Skip to content

Commit 3387d49

Browse files
committed
Merge pull request #40 from kuzzleio/serverInfo
New routes
2 parents 7ac8159 + 1a79928 commit 3387d49

File tree

7 files changed

+302
-27
lines changed

7 files changed

+302
-27
lines changed

dist/kuzzle.js

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ module.exports = Kuzzle = function (url, options, cb) {
529529
return this.bluebird.promisifyAll(this, {
530530
suffix: 'Promise',
531531
filter: function (name, func, target, passes) {
532-
var whitelist = ['getAllStatistics', 'getStatistics', 'listCollections', 'now', 'query'];
532+
var whitelist = ['getAllStatistics', 'getServerInfo', 'getStatistics', 'listCollections', 'listIndexes', 'now', 'query'];
533533

534534
return passes && whitelist.indexOf(name) !== -1;
535535
}
@@ -961,16 +961,39 @@ Kuzzle.prototype.flushQueue = function () {
961961
/**
962962
* Returns the list of known persisted data collections.
963963
*
964+
* @param {string} [index] - Index containing collections to be listed
964965
* @param {object} [options] - Optional parameters
965966
* @param {responseCallback} cb - Handles the query response
966967
* @returns {object} this
967968
*/
968-
Kuzzle.prototype.listCollections = function (options, cb) {
969-
var collectionType = 'all';
969+
Kuzzle.prototype.listCollections = function () {
970+
var
971+
collectionType = 'all',
972+
index,
973+
options,
974+
cb,
975+
args = Array.prototype.slice.call(arguments);
976+
977+
args.forEach(function(arg) {
978+
switch (typeof arg) {
979+
case 'string':
980+
index = arg;
981+
break;
982+
case 'object':
983+
options = arg;
984+
break;
985+
case 'function':
986+
cb = arg;
987+
break;
988+
}
989+
});
970990

971-
if (!cb && typeof options === 'function') {
972-
cb = options;
973-
options = null;
991+
if (!index) {
992+
if (!this.defaultIndex) {
993+
throw new Error('Kuzzle.listCollections: index required');
994+
}
995+
996+
index = this.defaultIndex;
974997
}
975998

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

982-
this.query({controller: 'read', action: 'listCollections'}, {body: {type: collectionType}}, options, function (err, res) {
1005+
this.query({index: index, controller: 'read', action: 'listCollections'}, {body: {type: collectionType}}, options, function (err, res) {
9831006
if (err) {
9841007
return cb(err);
9851008
}
@@ -990,6 +1013,32 @@ Kuzzle.prototype.listCollections = function (options, cb) {
9901013
return this;
9911014
};
9921015

1016+
/**
1017+
* Returns the list of existing indexes in Kuzzle
1018+
*
1019+
* @param {object} [options] - Optional arguments
1020+
* @param {responseCallback} cb - Handles the query response
1021+
* @returns {object} this
1022+
*/
1023+
Kuzzle.prototype.listIndexes = function (options, cb) {
1024+
if (!cb && typeof options === 'function') {
1025+
cb = options;
1026+
options = null;
1027+
}
1028+
1029+
this.callbackRequired('Kuzzle.listIndexes', cb);
1030+
1031+
this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
1032+
if (err) {
1033+
return cb(err);
1034+
}
1035+
1036+
return cb(null, res.result.indexes);
1037+
});
1038+
1039+
return this;
1040+
};
1041+
9931042
/**
9941043
* Disconnects from Kuzzle and invalidate this instance.
9951044
*/
@@ -1009,6 +1058,32 @@ Kuzzle.prototype.disconnect = function () {
10091058
}
10101059
};
10111060

1061+
/**
1062+
* Returns the server informations
1063+
*
1064+
* @param {object} [options] - Optional arguments
1065+
* @param {responseCallback} cb - Handles the query response
1066+
* @returns {object} this
1067+
*/
1068+
Kuzzle.prototype.getServerInfo = function (options, cb) {
1069+
if (!cb && typeof options === 'function') {
1070+
cb = options;
1071+
options = null;
1072+
}
1073+
1074+
this.callbackRequired('Kuzzle.getServerInfo', cb);
1075+
1076+
this.query({controller: 'read', action: 'serverInfo'}, {}, options, function (err, res) {
1077+
if (err) {
1078+
return cb(err);
1079+
}
1080+
1081+
cb(null, res.result.serverInfo);
1082+
});
1083+
1084+
return this;
1085+
};
1086+
10121087
/**
10131088
* Return the current Kuzzle's UTC Epoch time, in milliseconds
10141089
* @param {object} [options] - Optional parameters
@@ -1182,7 +1257,6 @@ Kuzzle.prototype.replayQueue = function () {
11821257
return this;
11831258
};
11841259

1185-
11861260
/**
11871261
* Sets the default Kuzzle index
11881262
*

dist/kuzzle.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/kuzzle.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <[email protected]>",
66
"repository": {

src/kuzzle.js

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ module.exports = Kuzzle = function (url, options, cb) {
254254
return this.bluebird.promisifyAll(this, {
255255
suffix: 'Promise',
256256
filter: function (name, func, target, passes) {
257-
var whitelist = ['getAllStatistics', 'getStatistics', 'listCollections', 'now', 'query'];
257+
var whitelist = ['getAllStatistics', 'getServerInfo', 'getStatistics', 'listCollections', 'listIndexes', 'now', 'query'];
258258

259259
return passes && whitelist.indexOf(name) !== -1;
260260
}
@@ -686,16 +686,39 @@ Kuzzle.prototype.flushQueue = function () {
686686
/**
687687
* Returns the list of known persisted data collections.
688688
*
689+
* @param {string} [index] - Index containing collections to be listed
689690
* @param {object} [options] - Optional parameters
690691
* @param {responseCallback} cb - Handles the query response
691692
* @returns {object} this
692693
*/
693-
Kuzzle.prototype.listCollections = function (options, cb) {
694-
var collectionType = 'all';
694+
Kuzzle.prototype.listCollections = function () {
695+
var
696+
collectionType = 'all',
697+
index,
698+
options,
699+
cb,
700+
args = Array.prototype.slice.call(arguments);
701+
702+
args.forEach(function(arg) {
703+
switch (typeof arg) {
704+
case 'string':
705+
index = arg;
706+
break;
707+
case 'object':
708+
options = arg;
709+
break;
710+
case 'function':
711+
cb = arg;
712+
break;
713+
}
714+
});
695715

696-
if (!cb && typeof options === 'function') {
697-
cb = options;
698-
options = null;
716+
if (!index) {
717+
if (!this.defaultIndex) {
718+
throw new Error('Kuzzle.listCollections: index required');
719+
}
720+
721+
index = this.defaultIndex;
699722
}
700723

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

707-
this.query({controller: 'read', action: 'listCollections'}, {body: {type: collectionType}}, options, function (err, res) {
730+
this.query({index: index, controller: 'read', action: 'listCollections'}, {body: {type: collectionType}}, options, function (err, res) {
708731
if (err) {
709732
return cb(err);
710733
}
@@ -715,6 +738,32 @@ Kuzzle.prototype.listCollections = function (options, cb) {
715738
return this;
716739
};
717740

741+
/**
742+
* Returns the list of existing indexes in Kuzzle
743+
*
744+
* @param {object} [options] - Optional arguments
745+
* @param {responseCallback} cb - Handles the query response
746+
* @returns {object} this
747+
*/
748+
Kuzzle.prototype.listIndexes = function (options, cb) {
749+
if (!cb && typeof options === 'function') {
750+
cb = options;
751+
options = null;
752+
}
753+
754+
this.callbackRequired('Kuzzle.listIndexes', cb);
755+
756+
this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
757+
if (err) {
758+
return cb(err);
759+
}
760+
761+
return cb(null, res.result.indexes);
762+
});
763+
764+
return this;
765+
};
766+
718767
/**
719768
* Disconnects from Kuzzle and invalidate this instance.
720769
*/
@@ -734,6 +783,32 @@ Kuzzle.prototype.disconnect = function () {
734783
}
735784
};
736785

786+
/**
787+
* Returns the server informations
788+
*
789+
* @param {object} [options] - Optional arguments
790+
* @param {responseCallback} cb - Handles the query response
791+
* @returns {object} this
792+
*/
793+
Kuzzle.prototype.getServerInfo = function (options, cb) {
794+
if (!cb && typeof options === 'function') {
795+
cb = options;
796+
options = null;
797+
}
798+
799+
this.callbackRequired('Kuzzle.getServerInfo', cb);
800+
801+
this.query({controller: 'read', action: 'serverInfo'}, {}, options, function (err, res) {
802+
if (err) {
803+
return cb(err);
804+
}
805+
806+
cb(null, res.result.serverInfo);
807+
});
808+
809+
return this;
810+
};
811+
737812
/**
738813
* Return the current Kuzzle's UTC Epoch time, in milliseconds
739814
* @param {object} [options] - Optional parameters
@@ -907,7 +982,6 @@ Kuzzle.prototype.replayQueue = function () {
907982
return this;
908983
};
909984

910-
911985
/**
912986
* Sets the default Kuzzle index
913987
*

test/kuzzle/constructor.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ describe('Kuzzle constructor', () => {
176176
should.not.exist(kuzzle.dataCollectionFactoryPromise);
177177
should.not.exist(kuzzle.flushQueuePromise);
178178
should.exist(kuzzle.getAllStatisticsPromise);
179+
should.exist(kuzzle.getServerInfoPromise);
179180
should.exist(kuzzle.getStatisticsPromise);
180181
should.exist(kuzzle.listCollectionsPromise);
182+
should.exist(kuzzle.listIndexesPromise);
181183
should.not.exist(kuzzle.logoutPromise);
182184
should.exist(kuzzle.nowPromise);
183185
should.exist(kuzzle.queryPromise);

0 commit comments

Comments
 (0)