Skip to content

Commit

Permalink
add TypeScript typings ; slight refactor ; improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Enet4 committed Feb 16, 2016
1 parent 910f269 commit 921df3c
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ gulp.task('main', ['lint'], function () {
gulp.task('bundle', ['lint', 'main'], function () {
// set up the browserify instance on a task basis
var b = browserify({
entries: './lib/dicoogle-client.js',
entries: './lib/index.js',
debug: false,
transform: [
['envify', {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"api"
],
"version": "3.2.0",
"main": "./lib/dicoogle-client",
"main": "./lib/index",
"typings": "./typings/dicoogle-client.d.ts",
"browserify": {
"transforms": [
"envify"
Expand Down
31 changes: 21 additions & 10 deletions src/dicoogle-client.js → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ DicoogleAccess.prototype.IndexerSettings = IndexerSettings;
callback = options;
options = {};
}
const endpoint = options.dim ? Endpoints.SEARCH_DIM : Endpoints.SEARCH;
let endpoint = Endpoints.SEARCH;
if (options.dim) {
endpoint = Endpoints.SEARCH_DIM;
if (process.end.NODE_ENV !== 'production') {
/*eslint-disable no-console */
console.error("Warning: 'dim' flag in method search is deprecated! Please use searchDIM instead.");
/*eslint-enable no-console */
}
}
let provider = options.provider || options.providers;
let keyword = typeof options.keyword === 'boolean' ? options.keyword : !!query.match(/[^\s\\]:\S/);
serviceRequest('GET', [url_, endpoint], {
Expand Down Expand Up @@ -138,7 +146,7 @@ DicoogleAccess.prototype.IndexerSettings = IndexerSettings;
/**
* Retrieve a list of provider plugins
* @param {string} [type] the type of provider ("query", "index", ...) - defaults to "query"
* @param {function(error:any, result:string)} callback the callback function
* @param {function(error:any, result:string[])} callback the callback function
*/
DicoogleAccess.prototype.getProviders = function Dicoogle_getProviders(type, callback) {
if (typeof type === 'function' && !callback) {
Expand Down Expand Up @@ -185,7 +193,7 @@ DicoogleAccess.prototype.IndexerSettings = IndexerSettings;
};

/**
* Obtain information about the DICOM Query Retrieve service.
* Obtain information about the DICOM Query/Retrieve service.
* @param {function(error:any, {running:boolean, autostart:boolean, port:number})} callback the callback function
*/
DicoogleAccess.prototype.getQueryRetrieveServiceStatus = function Dicoogle_getQueryRetrieveServiceStatus(callback) {
Expand Down Expand Up @@ -289,7 +297,6 @@ DicoogleAccess.prototype.IndexerSettings = IndexerSettings;
};

/** Retrieve the running Dicoogle version.
* Indices will not be updated, hence the files should be unindexed manually if so is intended.
* @param {function(error:any, {version:string})} callback the callback function
*/
DicoogleAccess.prototype.getVersion = function Dicoogle_getVersion(callback) {
Expand Down Expand Up @@ -319,7 +326,7 @@ DicoogleAccess.prototype.IndexerSettings = IndexerSettings;
/**
* Check whether the user is authenticated to the server. Authenticated clients will hold an
* authentication token.
* @returns {boolean} whether the user is authenticated to not.
* @returns {boolean} whether the user is authenticated or not.
*/
DicoogleAccess.prototype.isAuthenticated = function Dicoogle_isAuthenticated() {
return token_ !== null;
Expand Down Expand Up @@ -371,21 +378,21 @@ DicoogleAccess.prototype.IndexerSettings = IndexerSettings;

/**
* Log out from the server.
* @param {function(error:any)} callback the callback function
* @param {function(error:any)} [callback] the callback function
*/
DicoogleAccess.prototype.logout = function Dicoogle_logout(callback) {
serviceRequest('POST', [url_, Endpoints.LOGOUT], {}, function(error) {
if (error) {
if (error.status === 405) {
Dicoogle_logout_fallback(callback);
} else {
callback(error);
if (callback) callback(error);
}
} else {
username_ = null;
token_ = null;
roles_ = null;
callback(null);
if (callback) callback(null);
}
}, token_);
};
Expand All @@ -402,7 +409,7 @@ DicoogleAccess.prototype.IndexerSettings = IndexerSettings;
token_ = null;
roles_ = null;
}
callback(error);
if (callback) callback(error);
}, token_);
}

Expand Down Expand Up @@ -440,7 +447,11 @@ DicoogleAccess.prototype.IndexerSettings = IndexerSettings;
callback(err);
return;
}
callback(null, res.text);
let out = res.text;
if (field === 'effort' || field === 'thumbnailSize') {
out = +out;
}
callback(null, out);
});
return;
}
Expand Down
4 changes: 2 additions & 2 deletions test/mock/service-auth-mock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env node */
var DicoogleClient = require('../..');
var dicoogleClient = require('../..');
var nock = require('nock');
var nockDone = false;
var qs = require('querystring');
Expand Down Expand Up @@ -54,5 +54,5 @@ module.exports = function createDicoogleMock() {
nockDone = true;
}

return DicoogleClient(BASE_URL);
return dicoogleClient(BASE_URL);
};
5 changes: 2 additions & 3 deletions test/mock/service-mock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-env node */
var DicoogleClient = require('../..');
var dicoogleClient = require('../..');
var nock = require('nock');

var nockDone = false;

/** Use nock to intercept Dicoogle client requests.
Expand Down Expand Up @@ -248,5 +247,5 @@ module.exports = function createDicoogleMock() {
nockDone = true;
}

return DicoogleClient(BASE_URL);
return dicoogleClient(BASE_URL);
};
3 changes: 1 addition & 2 deletions test/test-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function assertDicomUUID(uid) {
assert(uid.match(/(\d+\.?)*/), "'" + uid + "' must be a valid DICOM UUID");
}


describe('Dicoogle Node.js Client', function() {
describe('Dicoogle Client (under Node.js)', function() {
var Dicoogle;
function initBaseURL() {
Dicoogle = createMockedDicoogle();
Expand Down
Loading

0 comments on commit 921df3c

Please sign in to comment.