Skip to content

Commit f1234f4

Browse files
committed
Adapt the SDK to PR kuzzleio/kuzzle#567
1 parent 9a713a9 commit f1234f4

File tree

11 files changed

+76
-76
lines changed

11 files changed

+76
-76
lines changed

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": "2.2.2",
3+
"version": "2.2.3",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <[email protected]>",
66
"repository": {

src/kuzzle.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ Kuzzle.prototype.getAllStatistics = function (options, cb) {
858858

859859
this.callbackRequired('Kuzzle.getAllStatistics', cb);
860860

861-
this.query({controller:'admin', action: 'getAllStats'}, {}, options, function (err, res) {
861+
this.query({controller:'server', action: 'getAllStats'}, {}, options, function (err, res) {
862862
if (err) {
863863
return cb(err);
864864
}
@@ -908,7 +908,7 @@ Kuzzle.prototype.getStatistics = function (timestamp, options, cb) {
908908
this.callbackRequired('Kuzzle.getStatistics', cb);
909909

910910
body = timestamp ? {body: {startTime: timestamp}} : {};
911-
this.query({controller: 'admin', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
911+
this.query({controller: 'server', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
912912
};
913913

914914
/**
@@ -1009,7 +1009,7 @@ Kuzzle.prototype.listCollections = function () {
10091009
query.body.size = options.size;
10101010
}
10111011

1012-
this.query({index: index, controller: 'read', action: 'listCollections'}, query, options, function (err, res) {
1012+
this.query({index: index, controller: 'collection', action: 'list'}, query, options, function (err, res) {
10131013
if (err) {
10141014
return cb(err);
10151015
}
@@ -1032,7 +1032,7 @@ Kuzzle.prototype.listIndexes = function (options, cb) {
10321032

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

1035-
this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
1035+
this.query({controller: 'index', action: 'list'}, {}, options, function (err, res) {
10361036
cb(err, err ? undefined : res.result.indexes);
10371037
});
10381038
};
@@ -1068,7 +1068,7 @@ Kuzzle.prototype.getServerInfo = function (options, cb) {
10681068

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

1071-
this.query({controller: 'read', action: 'serverInfo'}, {}, options, function (err, res) {
1071+
this.query({controller: 'server', action: 'info'}, {}, options, function (err, res) {
10721072
if (err) {
10731073
return cb(err);
10741074
}
@@ -1112,7 +1112,7 @@ Kuzzle.prototype.refreshIndex = function () {
11121112
index = this.defaultIndex;
11131113
}
11141114

1115-
this.query({ index: index, controller: 'admin', action: 'refreshIndex'}, {}, options, cb);
1115+
this.query({ index: index, controller: 'index', action: 'refresh'}, {}, options, cb);
11161116

11171117
return this;
11181118
};
@@ -1152,7 +1152,7 @@ Kuzzle.prototype.getAutoRefresh = function () {
11521152
}
11531153

11541154
this.callbackRequired('Kuzzle.getAutoRefresh', cb);
1155-
this.query({ index: index, controller: 'admin', action: 'getAutoRefresh'}, {}, options, cb);
1155+
this.query({ index: index, controller: 'index', action: 'getAutoRefresh'}, {}, options, cb);
11561156
};
11571157

11581158
/**
@@ -1199,7 +1199,7 @@ Kuzzle.prototype.setAutoRefresh = function () {
11991199
throw new Error('Kuzzle.setAutoRefresh: autoRefresh value is required');
12001200
}
12011201

1202-
this.query({ index: index, controller: 'admin', action: 'setAutoRefresh'}, { body: { autoRefresh: autoRefresh }}, options, cb);
1202+
this.query({ index: index, controller: 'index', action: 'setAutoRefresh'}, { body: { autoRefresh: autoRefresh }}, options, cb);
12031203

12041204
return this;
12051205
};
@@ -1217,7 +1217,7 @@ Kuzzle.prototype.now = function (options, cb) {
12171217

12181218
this.callbackRequired('Kuzzle.now', cb);
12191219

1220-
this.query({controller: 'read', action: 'now'}, {}, options, function (err, res) {
1220+
this.query({controller: 'server', action: 'now'}, {}, options, function (err, res) {
12211221
cb(err, res && res.result.now);
12221222
});
12231223
};

src/kuzzleDataCollection.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ KuzzleDataCollection.prototype.advancedSearch = function (filters, options, cb)
9797

9898
query = self.kuzzle.addHeaders({body: filters}, this.headers);
9999

100-
self.kuzzle.query(this.buildQueryArgs('read', 'search'), query, options, function (error, result) {
100+
self.kuzzle.query(this.buildQueryArgs('document', 'search'), query, options, function (error, result) {
101101
var
102102
response,
103103
documents = [];
@@ -151,7 +151,7 @@ KuzzleDataCollection.prototype.count = function (filters, options, cb) {
151151

152152
query = this.kuzzle.addHeaders({body: filters}, this.headers);
153153

154-
this.kuzzle.query(this.buildQueryArgs('read', 'count'), query, options, function (error, result) {
154+
this.kuzzle.query(this.buildQueryArgs('document', 'count'), query, options, function (error, result) {
155155
cb(error, result && result.result.count);
156156
});
157157
};
@@ -174,7 +174,7 @@ KuzzleDataCollection.prototype.create = function (options, cb) {
174174
}
175175

176176
data = this.kuzzle.addHeaders(data, this.headers);
177-
this.kuzzle.query(this.buildQueryArgs('write', 'createCollection'), data, options, cb);
177+
this.kuzzle.query(this.buildQueryArgs('collection', 'create'), data, options, cb);
178178

179179
return this;
180180
};
@@ -229,7 +229,7 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,
229229

230230
data = self.kuzzle.addHeaders(data, self.headers);
231231

232-
self.kuzzle.query(this.buildQueryArgs('write', action), data, options, cb && function (err, res) {
232+
self.kuzzle.query(this.buildQueryArgs('document', action), data, options, cb && function (err, res) {
233233
var doc;
234234

235235
if (err) {
@@ -280,7 +280,7 @@ KuzzleDataCollection.prototype.deleteDocument = function (arg, options, cb) {
280280

281281
data = this.kuzzle.addHeaders(data, this.headers);
282282

283-
this.kuzzle.query(this.buildQueryArgs('write', action), data, options, cb && function (err, res) {
283+
this.kuzzle.query(this.buildQueryArgs('document', action), data, options, cb && function (err, res) {
284284
if (err) {
285285
cb(err);
286286
}
@@ -312,7 +312,7 @@ KuzzleDataCollection.prototype.fetchDocument = function (documentId, options, cb
312312
self.kuzzle.callbackRequired('KuzzleDataCollection.fetch', cb);
313313
data = self.kuzzle.addHeaders(data, this.headers);
314314

315-
self.kuzzle.query(this.buildQueryArgs('read', 'get'), data, options, function (err, res) {
315+
self.kuzzle.query(this.buildQueryArgs('document', 'get'), data, options, function (err, res) {
316316
var document;
317317

318318
if (err) {
@@ -398,7 +398,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options, cb)
398398
}
399399

400400
data = this.kuzzle.addHeaders(data, this.headers);
401-
this.kuzzle.query(this.buildQueryArgs('write', 'publish'), data, options, cb);
401+
this.kuzzle.query(this.buildQueryArgs('realtime', 'publish'), data, options, cb);
402402

403403
return this;
404404
};
@@ -431,7 +431,7 @@ KuzzleDataCollection.prototype.replaceDocument = function (documentId, content,
431431

432432
data = self.kuzzle.addHeaders(data, this.headers);
433433

434-
self.kuzzle.query(this.buildQueryArgs('write', 'createOrReplace'), data, options, cb && function (err, res) {
434+
self.kuzzle.query(this.buildQueryArgs('document', 'createOrReplace'), data, options, cb && function (err, res) {
435435
var document;
436436

437437
if (err) {
@@ -492,7 +492,7 @@ KuzzleDataCollection.prototype.truncate = function (options, cb) {
492492
}
493493

494494
data = this.kuzzle.addHeaders(data, this.headers);
495-
this.kuzzle.query(this.buildQueryArgs('admin', 'truncateCollection'), data, options, cb);
495+
this.kuzzle.query(this.buildQueryArgs('collection', 'truncate'), data, options, cb);
496496

497497
return this;
498498
};
@@ -526,7 +526,7 @@ KuzzleDataCollection.prototype.updateDocument = function (documentId, content, o
526526

527527
data = self.kuzzle.addHeaders(data, this.headers);
528528

529-
self.kuzzle.query(this.buildQueryArgs('write', 'update'), data, options, cb && function (err, res) {
529+
self.kuzzle.query(this.buildQueryArgs('document', 'update'), data, options, cb && function (err, res) {
530530
if (err) {
531531
return cb(err);
532532
}

src/kuzzleDataMapping.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ KuzzleDataMapping.prototype.apply = function (options, cb) {
7373
options = null;
7474
}
7575

76-
self.kuzzle.query(this.collection.buildQueryArgs('admin', 'updateMapping'), data, options, function (err) {
76+
self.kuzzle.query(this.collection.buildQueryArgs('collection', 'updateMapping'), data, options, function (err) {
7777
if (err) {
7878
return cb && cb(err);
7979
}
@@ -103,7 +103,7 @@ KuzzleDataMapping.prototype.refresh = function (options, cb) {
103103
options = null;
104104
}
105105

106-
this.kuzzle.query(this.collection.buildQueryArgs('admin', 'getMapping'), data, options, function (err, res) {
106+
this.kuzzle.query(this.collection.buildQueryArgs('collection', 'getMapping'), data, options, function (err, res) {
107107
if (err) {
108108
return cb ? cb(err) : false;
109109
}

src/kuzzleDocument.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ KuzzleDocument.prototype.delete = function (options, cb) {
146146
throw new Error('KuzzleDocument.delete: cannot delete a document without a document ID');
147147
}
148148

149-
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options, cb && function (err) {
149+
this.kuzzle.query(this.dataCollection.buildQueryArgs('document', 'delete'), this.serialize(), options, cb && function (err) {
150150
cb(err, err ? undefined : self.id);
151151
});
152152
};
@@ -172,7 +172,7 @@ KuzzleDocument.prototype.refresh = function (options, cb) {
172172

173173
this.kuzzle.callbackRequired('KuzzleDocument.refresh', cb);
174174

175-
self.kuzzle.query(self.dataCollection.buildQueryArgs('read', 'get'), {_id: self.id}, options, function (error, res) {
175+
self.kuzzle.query(self.dataCollection.buildQueryArgs('document', 'get'), {_id: self.id}, options, function (error, res) {
176176
var newDocument;
177177

178178
if (error) {
@@ -211,7 +211,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
211211
options = null;
212212
}
213213

214-
self.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'createOrReplace'), data, options, function (error, res) {
214+
self.kuzzle.query(this.dataCollection.buildQueryArgs('document', 'createOrReplace'), data, options, function (error, res) {
215215
if (error) {
216216
return cb && cb(error);
217217
}
@@ -240,7 +240,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
240240
KuzzleDocument.prototype.publish = function (options) {
241241
var data = this.serialize();
242242

243-
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'publish'), data, options);
243+
this.kuzzle.query(this.dataCollection.buildQueryArgs('realtime', 'publish'), data, options);
244244

245245
return this;
246246
};

src/kuzzleRoom.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ KuzzleRoom.prototype.count = function (cb) {
142142
throw new Error('KuzzleRoom.count: cannot count subscriptions on an inactive room');
143143
}
144144

145-
this.kuzzle.query(this.collection.buildQueryArgs('subscribe', 'count'), data, function (err, res) {
145+
this.kuzzle.query(this.collection.buildQueryArgs('realtime', 'count'), data, function (err, res) {
146146
cb(err, res && res.result.count);
147147
});
148148
};
@@ -213,7 +213,7 @@ KuzzleRoom.prototype.renew = function (filters, notificationCB, cb) {
213213
subscribeQuery.body = self.filters;
214214
subscribeQuery = self.kuzzle.addHeaders(subscribeQuery, this.headers);
215215

216-
self.kuzzle.query(self.collection.buildQueryArgs('subscribe', 'on'), subscribeQuery, {metadata: self.metadata}, function (error, response) {
216+
self.kuzzle.query(self.collection.buildQueryArgs('realtime', 'subscribe'), subscribeQuery, {metadata: self.metadata}, function (error, response) {
217217
delete self.kuzzle.subscriptions.pending[self.id];
218218
self.subscribing = false;
219219

@@ -267,12 +267,12 @@ KuzzleRoom.prototype.unsubscribe = function () {
267267
delete self.kuzzle.subscriptions[room];
268268

269269
if (Object.keys(self.kuzzle.subscriptions.pending).length === 0) {
270-
self.kuzzle.query(self.collection.buildQueryArgs('subscribe', 'off'), {body: {roomId: room}});
270+
self.kuzzle.query(self.collection.buildQueryArgs('realtime', 'unsubscribe'), {body: {roomId: room}});
271271
} else {
272272
interval = setInterval(function () {
273273
if (Object.keys(self.kuzzle.subscriptions.pending).length === 0) {
274274
if (!self.kuzzle.subscriptions[room]) {
275-
self.kuzzle.query(self.collection.buildQueryArgs('subscribe', 'off'), {body: {roomId: room}});
275+
self.kuzzle.query(self.collection.buildQueryArgs('realtime', 'unsubscribe'), {body: {roomId: room}});
276276
}
277277
clearInterval(interval);
278278
}

test/kuzzle/methods.test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('Kuzzle methods', function () {
5454
error = null;
5555
result = {result: {hits: []}};
5656
expectedQuery = {
57-
controller: 'admin',
57+
controller: 'server',
5858
action: 'getAllStats'
5959
};
6060
});
@@ -96,7 +96,7 @@ describe('Kuzzle methods', function () {
9696
error = null;
9797
result = {result: {hits: []}};
9898
expectedQuery = {
99-
controller: 'admin',
99+
controller: 'server',
100100
action: 'getLastStats'
101101
};
102102
});
@@ -115,7 +115,7 @@ describe('Kuzzle methods', function () {
115115

116116
it('should return statistics frames starting from the given timestamp', function () {
117117
expectedQuery = {
118-
controller: 'admin',
118+
controller: 'server',
119119
action: 'getStats',
120120
body: { startTime: 123 }
121121
};
@@ -159,7 +159,7 @@ describe('Kuzzle methods', function () {
159159
// testing: getStatistics(timestamp, options callback);
160160
emitted = false;
161161
expectedQuery = {
162-
controller: 'admin',
162+
controller: 'server',
163163
action: 'getStats',
164164
body: { startTime: 123 }
165165
};
@@ -255,8 +255,8 @@ describe('Kuzzle methods', function () {
255255
}
256256
}}};
257257
expectedQuery = {
258-
controller: 'read',
259-
action: 'serverInfo'
258+
controller: 'server',
259+
action: 'info'
260260
};
261261
});
262262

@@ -297,8 +297,8 @@ describe('Kuzzle methods', function () {
297297
result = {result: {collections: {stored: [], realtime: []}}};
298298
expectedQuery = {
299299
index: 'foo',
300-
controller: 'read',
301-
action: 'listCollections',
300+
controller: 'collection',
301+
action: 'list',
302302
body: {type: 'all'}
303303
};
304304
});
@@ -374,8 +374,8 @@ describe('Kuzzle methods', function () {
374374
error = null;
375375
result = {result: {indexes: ['foo', 'bar']}};
376376
expectedQuery = {
377-
controller: 'read',
378-
action: 'listIndexes'
377+
controller: 'index',
378+
action: 'list'
379379
};
380380
});
381381

@@ -424,7 +424,7 @@ describe('Kuzzle methods', function () {
424424
error = null;
425425
result = {result: {now: Date.now()}};
426426
expectedQuery = {
427-
controller: 'read',
427+
controller: 'server',
428428
action: 'now'
429429
};
430430
});
@@ -855,8 +855,8 @@ describe('Kuzzle methods', function () {
855855
args = spy.firstCall.args;
856856

857857
should(args[0].index).be.exactly(index);
858-
should(args[0].controller).be.exactly('admin');
859-
should(args[0].action).be.exactly('refreshIndex');
858+
should(args[0].controller).be.exactly('index');
859+
should(args[0].action).be.exactly('refresh');
860860
should(args[2]).be.exactly(options);
861861
should(args[3]).be.exactly(cb);
862862
});
@@ -899,7 +899,7 @@ describe('Kuzzle methods', function () {
899899
kuzzle.getAutoRefresh(index, options, cb);
900900
should(spy.calledOnce).be.true();
901901
should(spy.calledWithExactly(
902-
{ index: index, controller: 'admin', action: 'getAutoRefresh' },
902+
{ index: index, controller: 'index', action: 'getAutoRefresh' },
903903
{},
904904
options,
905905
cb)
@@ -909,7 +909,7 @@ describe('Kuzzle methods', function () {
909909
kuzzle.getAutoRefresh(cb);
910910
should(spy.calledTwice).be.true();
911911
should(spy.secondCall.calledWithExactly(
912-
{ index: kuzzle.defaultIndex, controller: 'admin', action: 'getAutoRefresh' },
912+
{ index: kuzzle.defaultIndex, controller: 'index', action: 'getAutoRefresh' },
913913
{},
914914
undefined,
915915
cb)
@@ -937,7 +937,7 @@ describe('Kuzzle methods', function () {
937937
kuzzle.setAutoRefresh(true, cb);
938938
should(spy.calledOnce).be.true();
939939
should(spy.calledWith(
940-
{ index: kuzzle.defaultIndex, controller: 'admin', action: 'setAutoRefresh' },
940+
{ index: kuzzle.defaultIndex, controller: 'index', action: 'setAutoRefresh' },
941941
{ body: { autoRefresh: true } },
942942
undefined,
943943
cb
@@ -964,7 +964,7 @@ describe('Kuzzle methods', function () {
964964
kuzzle.setAutoRefresh(autoRefresh, options, cb);
965965
should(spy.calledOnce).be.true();
966966
should(spy.firstCall.calledWithExactly(
967-
{ index: kuzzle.defaultIndex, controller: 'admin', action: 'setAutoRefresh' },
967+
{ index: kuzzle.defaultIndex, controller: 'index', action: 'setAutoRefresh' },
968968
{ body: { autoRefresh: autoRefresh }},
969969
options,
970970
cb
@@ -973,7 +973,7 @@ describe('Kuzzle methods', function () {
973973
kuzzle.setAutoRefresh(index, autoRefresh);
974974
should(spy.calledTwice).be.true();
975975
should(spy.secondCall.calledWithExactly(
976-
{ index: index, controller: 'admin', action: 'setAutoRefresh' },
976+
{ index: index, controller: 'index', action: 'setAutoRefresh' },
977977
{ body: { autoRefresh: autoRefresh }},
978978
undefined,
979979
undefined

0 commit comments

Comments
 (0)