Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 82 additions & 8 deletions dist/kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ module.exports = Kuzzle = function (url, options, cb) {
return this.bluebird.promisifyAll(this, {
suffix: 'Promise',
filter: function (name, func, target, passes) {
var whitelist = ['getAllStatistics', 'getStatistics', 'listCollections', 'now', 'query'];
var whitelist = ['getAllStatistics', 'getServerInfo', 'getStatistics', 'listCollections', 'listIndexes', 'now', 'query'];

return passes && whitelist.indexOf(name) !== -1;
}
Expand Down Expand Up @@ -961,16 +961,39 @@ Kuzzle.prototype.flushQueue = function () {
/**
* Returns the list of known persisted data collections.
*
* @param {string} [index] - Index containing collections to be listed
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.listCollections = function (options, cb) {
var collectionType = 'all';
Kuzzle.prototype.listCollections = function () {
var
collectionType = 'all',
index,
options,
cb,
args = Array.prototype.slice.call(arguments);

args.forEach(function(arg) {
switch (typeof arg) {
case 'string':
index = arg;
break;
case 'object':
options = arg;
break;
case 'function':
cb = arg;
break;
}
});

if (!cb && typeof options === 'function') {
cb = options;
options = null;
if (!index) {
if (!this.defaultIndex) {
throw new Error('Kuzzle.listCollections: index required');
}

index = this.defaultIndex;
}

this.callbackRequired('Kuzzle.listCollections', cb);
Expand All @@ -979,7 +1002,7 @@ Kuzzle.prototype.listCollections = function (options, cb) {
collectionType = options.type;
}

this.query({controller: 'read', action: 'listCollections'}, {body: {type: collectionType}}, options, function (err, res) {
this.query({index: index, controller: 'read', action: 'listCollections'}, {body: {type: collectionType}}, options, function (err, res) {
if (err) {
return cb(err);
}
Expand All @@ -990,6 +1013,32 @@ Kuzzle.prototype.listCollections = function (options, cb) {
return this;
};

/**
* Returns the list of existing indexes in Kuzzle
*
* @param {object} [options] - Optional arguments
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.listIndexes = function (options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.callbackRequired('Kuzzle.listIndexes', cb);

this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}

return cb(null, res.result.indexes);
});

return this;
};

/**
* Disconnects from Kuzzle and invalidate this instance.
*/
Expand All @@ -1009,6 +1058,32 @@ Kuzzle.prototype.disconnect = function () {
}
};

/**
* Returns the server informations
*
* @param {object} [options] - Optional arguments
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.getServerInfo = function (options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.callbackRequired('Kuzzle.getServerInfo', cb);

this.query({controller: 'read', action: 'serverInfo'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}

cb(null, res.result.serverInfo);
});

return this;
};

/**
* Return the current Kuzzle's UTC Epoch time, in milliseconds
* @param {object} [options] - Optional parameters
Expand Down Expand Up @@ -1182,7 +1257,6 @@ Kuzzle.prototype.replayQueue = function () {
return this;
};


/**
* Sets the default Kuzzle index
*
Expand Down
4 changes: 2 additions & 2 deletions dist/kuzzle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kuzzle.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "1.3.1",
"version": "1.3.2",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <support@kuzzle.io>",
"repository": {
Expand Down
90 changes: 82 additions & 8 deletions src/kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ module.exports = Kuzzle = function (url, options, cb) {
return this.bluebird.promisifyAll(this, {
suffix: 'Promise',
filter: function (name, func, target, passes) {
var whitelist = ['getAllStatistics', 'getStatistics', 'listCollections', 'now', 'query'];
var whitelist = ['getAllStatistics', 'getServerInfo', 'getStatistics', 'listCollections', 'listIndexes', 'now', 'query'];

return passes && whitelist.indexOf(name) !== -1;
}
Expand Down Expand Up @@ -686,16 +686,39 @@ Kuzzle.prototype.flushQueue = function () {
/**
* Returns the list of known persisted data collections.
*
* @param {string} [index] - Index containing collections to be listed
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.listCollections = function (options, cb) {
var collectionType = 'all';
Kuzzle.prototype.listCollections = function () {
var
collectionType = 'all',
index,
options,
cb,
args = Array.prototype.slice.call(arguments);

args.forEach(function(arg) {
switch (typeof arg) {
case 'string':
index = arg;
break;
case 'object':
options = arg;
break;
case 'function':
cb = arg;
break;
}
});

if (!cb && typeof options === 'function') {
cb = options;
options = null;
if (!index) {
if (!this.defaultIndex) {
throw new Error('Kuzzle.listCollections: index required');
}

index = this.defaultIndex;
}

this.callbackRequired('Kuzzle.listCollections', cb);
Expand All @@ -704,7 +727,7 @@ Kuzzle.prototype.listCollections = function (options, cb) {
collectionType = options.type;
}

this.query({controller: 'read', action: 'listCollections'}, {body: {type: collectionType}}, options, function (err, res) {
this.query({index: index, controller: 'read', action: 'listCollections'}, {body: {type: collectionType}}, options, function (err, res) {
if (err) {
return cb(err);
}
Expand All @@ -715,6 +738,32 @@ Kuzzle.prototype.listCollections = function (options, cb) {
return this;
};

/**
* Returns the list of existing indexes in Kuzzle
*
* @param {object} [options] - Optional arguments
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.listIndexes = function (options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.callbackRequired('Kuzzle.listIndexes', cb);

this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}

return cb(null, res.result.indexes);
});

return this;
};

/**
* Disconnects from Kuzzle and invalidate this instance.
*/
Expand All @@ -734,6 +783,32 @@ Kuzzle.prototype.disconnect = function () {
}
};

/**
* Returns the server informations
*
* @param {object} [options] - Optional arguments
* @param {responseCallback} cb - Handles the query response
* @returns {object} this
*/
Kuzzle.prototype.getServerInfo = function (options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.callbackRequired('Kuzzle.getServerInfo', cb);

this.query({controller: 'read', action: 'serverInfo'}, {}, options, function (err, res) {
if (err) {
return cb(err);
}

cb(null, res.result.serverInfo);
});

return this;
};

/**
* Return the current Kuzzle's UTC Epoch time, in milliseconds
* @param {object} [options] - Optional parameters
Expand Down Expand Up @@ -907,7 +982,6 @@ Kuzzle.prototype.replayQueue = function () {
return this;
};


/**
* Sets the default Kuzzle index
*
Expand Down
2 changes: 2 additions & 0 deletions test/kuzzle/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ describe('Kuzzle constructor', () => {
should.not.exist(kuzzle.dataCollectionFactoryPromise);
should.not.exist(kuzzle.flushQueuePromise);
should.exist(kuzzle.getAllStatisticsPromise);
should.exist(kuzzle.getServerInfoPromise);
should.exist(kuzzle.getStatisticsPromise);
should.exist(kuzzle.listCollectionsPromise);
should.exist(kuzzle.listIndexesPromise);
should.not.exist(kuzzle.logoutPromise);
should.exist(kuzzle.nowPromise);
should.exist(kuzzle.queryPromise);
Expand Down
Loading