@@ -961,6 +961,40 @@ Kuzzle.prototype.whoAmI = function (callback) {
961
961
return self ;
962
962
} ;
963
963
964
+
965
+ /**
966
+ * Update current user in Kuzzle.
967
+ *
968
+ * @param {object } content - a plain javascript object representing the user's modification
969
+ * @param {object } [options] - (optional) arguments
970
+ * @param {responseCallback } [cb] - (optional) Handles the query response
971
+ */
972
+ Kuzzle . prototype . updateSelf = function ( content , options , cb ) {
973
+ var
974
+ self = this ,
975
+ data = { } ,
976
+ queryArgs = { controller : 'auth' , action : 'updateSelf' } ;
977
+
978
+ if ( ! cb && typeof options === 'function' ) {
979
+ cb = options ;
980
+ options = null ;
981
+ }
982
+
983
+ data . body = content ;
984
+
985
+ if ( cb ) {
986
+ self . query ( queryArgs , data , options , function ( err , res ) {
987
+ if ( err ) {
988
+ return cb ( err ) ;
989
+ }
990
+
991
+ cb ( null , res . result ) ;
992
+ } ) ;
993
+ } else {
994
+ self . query ( queryArgs , data , options ) ;
995
+ }
996
+ } ;
997
+
964
998
/**
965
999
* Clean up the queue, ensuring the queryTTL and queryMaxSize properties are respected
966
1000
*/
@@ -1873,27 +1907,6 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,
1873
1907
return this ;
1874
1908
} ;
1875
1909
1876
- /**
1877
- * Delete this data collection and all documents in it.
1878
- *
1879
- * @param {object } [options] - Optional parameters
1880
- * @param {responseCallback } [cb] - returns Kuzzle's response
1881
- * @returns {* } this
1882
- */
1883
- KuzzleDataCollection . prototype . delete = function ( options , cb ) {
1884
- var data = { } ;
1885
-
1886
- if ( ! cb && typeof options === 'function' ) {
1887
- cb = options ;
1888
- options = null ;
1889
- }
1890
-
1891
- data = this . kuzzle . addHeaders ( data , this . headers ) ;
1892
- this . kuzzle . query ( this . buildQueryArgs ( 'admin' , 'deleteCollection' ) , data , options , cb ) ;
1893
-
1894
- return this ;
1895
- } ;
1896
-
1897
1910
/**
1898
1911
* Delete persistent documents.
1899
1912
*
@@ -2730,6 +2743,36 @@ KuzzleDocument.prototype.setHeaders = function (content, replace) {
2730
2743
module . exports = KuzzleDocument ;
2731
2744
2732
2745
} , { } ] , 7 :[ function ( require , module , exports ) {
2746
+ /**
2747
+ * This is a global callback pattern, called by all asynchronous functions of the Kuzzle object.
2748
+ *
2749
+ * @callback responseCallback
2750
+ * @param {Object } err - Error object, NULL if the query is successful
2751
+ * @param {Object } data - The content of the query response
2752
+ */
2753
+
2754
+
2755
+ /**
2756
+ * Kuzzle's memory storage is a separate data store from the database layer.
2757
+ * It is internaly based on Redis. You can access most of Redis functions (all
2758
+ * lowercased), excepting:
2759
+ * * all cluster based functions
2760
+ * * all script based functions
2761
+ * * all cursors functions
2762
+ *
2763
+ * For instance:
2764
+ * kuzzle.memoryStorage
2765
+ * .set('myKey', 'myValue')
2766
+ * .get('myKey', function (err, response) {
2767
+ * console.log(response.result);
2768
+ *
2769
+ * // { _id: 'foo', body: { value: 'myValue' }}
2770
+ * });
2771
+ *
2772
+ *
2773
+ * @param {object } kuzzle - Kuzzle instance to inherit from
2774
+ * @constructor
2775
+ */
2733
2776
function KuzzleMemoryStorage ( kuzzle ) {
2734
2777
Object . defineProperties ( this , {
2735
2778
// read-only properties
@@ -2762,6 +2805,9 @@ function KuzzleMemoryStorage(kuzzle) {
2762
2805
}
2763
2806
2764
2807
2808
+ /**
2809
+ * constructs the memoryStorage functions.
2810
+ */
2765
2811
( function ( ) {
2766
2812
2767
2813
var
@@ -3064,7 +3110,7 @@ KuzzleRoom.prototype.count = function (cb) {
3064
3110
3065
3111
data = this . kuzzle . addHeaders ( { body : { roomId : this . roomId } } , this . headers ) ;
3066
3112
3067
- if ( this . subscribing ) {
3113
+ if ( ! isReady . call ( this ) ) {
3068
3114
this . queue . push ( { action : 'count' , args : [ cb ] } ) ;
3069
3115
return this ;
3070
3116
}
@@ -3185,7 +3231,7 @@ KuzzleRoom.prototype.unsubscribe = function () {
3185
3231
room = self . roomId ,
3186
3232
interval ;
3187
3233
3188
- if ( self . subscribing ) {
3234
+ if ( ! isReady . call ( this ) ) {
3189
3235
self . queue . push ( { action : 'unsubscribe' , args : [ ] } ) ;
3190
3236
return self ;
3191
3237
}
@@ -3273,6 +3319,13 @@ function dequeue () {
3273
3319
}
3274
3320
}
3275
3321
3322
+ function isReady ( ) {
3323
+ if ( this . kuzzle . state !== 'connected' || this . subscribing ) {
3324
+ return false ;
3325
+ }
3326
+ return true ;
3327
+ }
3328
+
3276
3329
module . exports = KuzzleRoom ;
3277
3330
3278
3331
} , { "node-uuid" :2 } ] , 9 :[ function ( require , module , exports ) {
@@ -4218,10 +4271,10 @@ KuzzleSecurity.prototype.updateUser = function (id, content, options, cb) {
4218
4271
return cb ( err ) ;
4219
4272
}
4220
4273
4221
- cb ( null , res . result . _id ) ;
4274
+ cb ( null , new KuzzleUser ( self , res . result . _id , res . result . _source ) ) ;
4222
4275
} ) ;
4223
4276
} else {
4224
- self . kuzzle . query ( this . buildQueryArgs ( action ) , data ) ;
4277
+ self . kuzzle . query ( this . buildQueryArgs ( action ) , data , options ) ;
4225
4278
}
4226
4279
} ;
4227
4280
0 commit comments