@@ -529,7 +529,7 @@ module.exports = Kuzzle = function (url, options, cb) {
529
529
return this . bluebird . promisifyAll ( this , {
530
530
suffix : 'Promise' ,
531
531
filter : function ( name , func , target , passes ) {
532
- var whitelist = [ 'getAllStatistics' , 'getStatistics' , 'listCollections' , 'now' , 'query' ] ;
532
+ var whitelist = [ 'getAllStatistics' , 'getServerInfo' , ' getStatistics', 'listCollections' , 'listIndexes ', 'now' , 'query' ] ;
533
533
534
534
return passes && whitelist . indexOf ( name ) !== - 1 ;
535
535
}
@@ -961,16 +961,39 @@ Kuzzle.prototype.flushQueue = function () {
961
961
/**
962
962
* Returns the list of known persisted data collections.
963
963
*
964
+ * @param {string } [index] - Index containing collections to be listed
964
965
* @param {object } [options] - Optional parameters
965
966
* @param {responseCallback } cb - Handles the query response
966
967
* @returns {object } this
967
968
*/
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
+ } ) ;
970
990
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 ;
974
997
}
975
998
976
999
this . callbackRequired ( 'Kuzzle.listCollections' , cb ) ;
@@ -979,7 +1002,7 @@ Kuzzle.prototype.listCollections = function (options, cb) {
979
1002
collectionType = options . type ;
980
1003
}
981
1004
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 ) {
983
1006
if ( err ) {
984
1007
return cb ( err ) ;
985
1008
}
@@ -990,6 +1013,32 @@ Kuzzle.prototype.listCollections = function (options, cb) {
990
1013
return this ;
991
1014
} ;
992
1015
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
+
993
1042
/**
994
1043
* Disconnects from Kuzzle and invalidate this instance.
995
1044
*/
@@ -1009,6 +1058,32 @@ Kuzzle.prototype.disconnect = function () {
1009
1058
}
1010
1059
} ;
1011
1060
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
+
1012
1087
/**
1013
1088
* Return the current Kuzzle's UTC Epoch time, in milliseconds
1014
1089
* @param {object } [options] - Optional parameters
@@ -1182,7 +1257,6 @@ Kuzzle.prototype.replayQueue = function () {
1182
1257
return this ;
1183
1258
} ;
1184
1259
1185
-
1186
1260
/**
1187
1261
* Sets the default Kuzzle index
1188
1262
*
0 commit comments