Skip to content

Commit a7dfef1

Browse files
author
David Bengsch
authored
Merge pull request #152 from kuzzleio/newControllerStructure
Adapt the SDK to the controller refactor
2 parents 88d5a55 + 9fab840 commit a7dfef1

File tree

15 files changed

+92
-93
lines changed

15 files changed

+92
-93
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ deploy:
2424
skip_cleanup: true
2525
2626
api_key:
27-
secure: DqPwRO+LYFFOgIdZ23Prhw14f1ycsOcOXZsl7tMi4kznwu1PTkWgW+rFyCMoTeV/BxexvzMjAneSqO0plvbZyKOMzNtNCGPUjD49zzdpgkMo4Gc+fwb9AgbqUj3rRROX+106KJsoSRuTzOeuK+Ar7NJNBH1xX+zKkNHd+FaJiPFGwKTcEOguf0ger04NyZUVpzs4YPJDlZdXjXQEdh9EhnvLSUkPXD6cbPuSCMKoOuuUZIWXA3rwOMdId6dLp63NAv0SxCqiCGO82BfRj1pbn3ocqgorGSTI2l4aSHF5IU9WPH/j1WnaLJVgqCbXyALWE7qXwiPc2/IEmQLe4JnkUjY5RLPNppJk1g5lGoM8Wd/21EsGb4jYuLJlTjHhe2qHY2Xki3r0WoZyLzGYlHMNAZaSBDckMssG3LjSWQSqCwKZM4DypdQ16ROALYQELKL/MSQQS+vD+/hgCf8JDIytnEZyHzllbwhBxctWp4UYbjcsS5dh/YJFbNl6Vgf8i9S+RnqxlV96pyHX881vz9ZskpHvMEwgENDNZqGRUzeyM058VlqspL9mq6VbbTiRNneupQAEyeyZ0oadNhy7dG0oOABVAcwpGGDBWXSd3OYGPcWrbTKpiGbH/NAlsC8sXLtA74mGvupkxXSFJRf75KC8bYZrpb6Q6eLGFHB480lomXw=
27+
secure: fyAUrBhmctUri2wPCcdufPME6EyFLpC4OS4wMAmUc7iNNSUl2C9On0HMkmz1JKD/+fMhlFCvQcpD6O8hNThneSqrv/PANAyz9YXblv35W9v1XbYrzm5IWQ4D30+Zg350SK6Wqn4Wr6jZkRXQKhBo8GQ5aLsDdhr7RgRBpw8p6GwDuda41K9cAOh8vbX2u6guOfeJW+jfwfXgwZUl/DEor8XkIJYcVwOF0989FT0urYf28afnxVgaj5XuIyNQMLC0R0KAsbYO0EPDy1O7a34SFUoNVBXPqP+5wYocML6mKNOFtLfvTAfIeErQc6Is3roJvZqMkcu8zzRH+OdbQfa+3+sUTPbxBAaNvcITO/z36QnYh/Swbnfxn0dD5ue2bAXseVpa55fWw0DPOQkcQ3VJ9hHQfMWTn+4EH6lqYEynSJ0KGbHqzm3Qm15fCj0s+vjvs4axGcYEpZlJaTu9o3oHYJTTDfbkk4b7nbKGQ/vDsYFTRL2yRprYlCQ8YoUnDMOB3YHxmRs7Jgxb9lbg8iD5ZMtP1+QIhUMJTI16ruxs88bRvCaTkfdTOGv0qVhgA9a00+G1XMLxCzpvI8wKgo7+GKRPUyvR2bRCQS6mHtbp6beCqPxgzyfGzg8XU09disST7spqH3E8ohWwVfgkjoBlS9+y62iaiwXRsTVXyeGJpac=
2828
on:
2929
repo: kuzzleio/sdk-javascript
3030
branch: master

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Official Kuzzle Javascript SDK
55
======
66

7-
This SDK version is compatible with Kuzzle 1.0.0-RC6 and higher
87

98
Please use SDK v1.x for earlier versions of Kuzzle.
109

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

src/kuzzle.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,11 @@ Kuzzle.prototype.logout = function (cb) {
534534
};
535535

536536
this.query({controller: 'auth', action: 'logout'}, request, {queuable: false}, typeof cb !== 'function' ? null : function(error) {
537-
if (error === null) {
538-
self.unsetJwtToken();
539-
cb(null, self);
540-
}
541-
else {
542-
cb(error);
543-
}
537+
cb(error, self);
544538
});
545539

540+
self.unsetJwtToken();
541+
546542
return self;
547543
};
548544

@@ -858,7 +854,7 @@ Kuzzle.prototype.getAllStatistics = function (options, cb) {
858854

859855
this.callbackRequired('Kuzzle.getAllStatistics', cb);
860856

861-
this.query({controller:'admin', action: 'getAllStats'}, {}, options, function (err, res) {
857+
this.query({controller:'server', action: 'getAllStats'}, {}, options, function (err, res) {
862858
if (err) {
863859
return cb(err);
864860
}
@@ -908,7 +904,7 @@ Kuzzle.prototype.getStatistics = function (timestamp, options, cb) {
908904
this.callbackRequired('Kuzzle.getStatistics', cb);
909905

910906
body = timestamp ? {body: {startTime: timestamp}} : {};
911-
this.query({controller: 'admin', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
907+
this.query({controller: 'server', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
912908
};
913909

914910
/**
@@ -1009,7 +1005,7 @@ Kuzzle.prototype.listCollections = function () {
10091005
query.body.size = options.size;
10101006
}
10111007

1012-
this.query({index: index, controller: 'read', action: 'listCollections'}, query, options, function (err, res) {
1008+
this.query({index: index, controller: 'collection', action: 'list'}, query, options, function (err, res) {
10131009
if (err) {
10141010
return cb(err);
10151011
}
@@ -1032,7 +1028,7 @@ Kuzzle.prototype.listIndexes = function (options, cb) {
10321028

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

1035-
this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
1031+
this.query({controller: 'index', action: 'list'}, {}, options, function (err, res) {
10361032
cb(err, err ? undefined : res.result.indexes);
10371033
});
10381034
};
@@ -1068,7 +1064,7 @@ Kuzzle.prototype.getServerInfo = function (options, cb) {
10681064

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

1071-
this.query({controller: 'read', action: 'serverInfo'}, {}, options, function (err, res) {
1067+
this.query({controller: 'server', action: 'info'}, {}, options, function (err, res) {
10721068
if (err) {
10731069
return cb(err);
10741070
}
@@ -1112,7 +1108,7 @@ Kuzzle.prototype.refreshIndex = function () {
11121108
index = this.defaultIndex;
11131109
}
11141110

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

11171113
return this;
11181114
};
@@ -1152,7 +1148,7 @@ Kuzzle.prototype.getAutoRefresh = function () {
11521148
}
11531149

11541150
this.callbackRequired('Kuzzle.getAutoRefresh', cb);
1155-
this.query({ index: index, controller: 'admin', action: 'getAutoRefresh'}, {}, options, cb);
1151+
this.query({ index: index, controller: 'index', action: 'getAutoRefresh'}, {}, options, cb);
11561152
};
11571153

11581154
/**
@@ -1199,7 +1195,7 @@ Kuzzle.prototype.setAutoRefresh = function () {
11991195
throw new Error('Kuzzle.setAutoRefresh: autoRefresh value is required');
12001196
}
12011197

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

12041200
return this;
12051201
};
@@ -1217,7 +1213,7 @@ Kuzzle.prototype.now = function (options, cb) {
12171213

12181214
this.callbackRequired('Kuzzle.now', cb);
12191215

1220-
this.query({controller: 'read', action: 'now'}, {}, options, function (err, res) {
1216+
this.query({controller: 'server', action: 'now'}, {}, options, function (err, res) {
12211217
cb(err, res && res.result.now);
12221218
});
12231219
};

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
}

src/networkWrapper/wrappers/websocket.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,17 @@ function WSNode(host, port, ssl) {
162162
* @param {function} callback
163163
*/
164164
this.off = function (roomId, callback) {
165-
var index;
165+
var index = -1;
166166

167167
if (this.listeners[roomId]) {
168-
index = this.listeners[roomId].findIndex(function (listener) {
169-
return listener.fn === callback;
168+
// Array.findIndex is not supported by internet explorer
169+
this.listeners[roomId].some(function (listener, i) {
170+
if (listener.fn === callback) {
171+
index = i;
172+
return true;
173+
}
174+
175+
return false;
170176
});
171177

172178
if (index !== -1) {

test/kuzzle/constructor.test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ describe('Kuzzle constructor', () => {
899899
kuzzle.login('local', loginCredentials);
900900
});
901901

902-
it('should have a empty token in logout callback', function (done) {
902+
it('should have a empty token in logout callback', function () {
903903
var
904904
unsetJwtToken = false,
905905
kuzzle;
@@ -918,10 +918,8 @@ describe('Kuzzle constructor', () => {
918918
cb(null, {});
919919
};
920920

921-
kuzzle.logout(function() {
922-
should(unsetJwtToken).be.exactly(true);
923-
done();
924-
});
921+
kuzzle.logout(() => {});
922+
should(unsetJwtToken).be.exactly(true);
925923
});
926924

927925
it('should give an error if login query fail to the logout callback if is set', function (done) {

0 commit comments

Comments
 (0)