Skip to content

Commit 6d23b14

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop-implement-scroll
Conflicts: src/kuzzleDataCollection.js
2 parents 3bca87c + a7dfef1 commit 6d23b14

File tree

16 files changed

+102
-125
lines changed

16 files changed

+102
-125
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
@@ -560,15 +560,11 @@ Kuzzle.prototype.logout = function (cb) {
560560
};
561561

562562
this.query({controller: 'auth', action: 'logout'}, request, {queuable: false}, typeof cb !== 'function' ? null : function(error) {
563-
if (error === null) {
564-
self.unsetJwtToken();
565-
cb(null, self);
566-
}
567-
else {
568-
cb(error);
569-
}
563+
cb(error, self);
570564
});
571565

566+
self.unsetJwtToken();
567+
572568
return self;
573569
};
574570

@@ -884,7 +880,7 @@ Kuzzle.prototype.getAllStatistics = function (options, cb) {
884880

885881
this.callbackRequired('Kuzzle.getAllStatistics', cb);
886882

887-
this.query({controller:'admin', action: 'getAllStats'}, {}, options, function (err, res) {
883+
this.query({controller:'server', action: 'getAllStats'}, {}, options, function (err, res) {
888884
if (err) {
889885
return cb(err);
890886
}
@@ -934,7 +930,7 @@ Kuzzle.prototype.getStatistics = function (timestamp, options, cb) {
934930
this.callbackRequired('Kuzzle.getStatistics', cb);
935931

936932
body = timestamp ? {body: {startTime: timestamp}} : {};
937-
this.query({controller: 'admin', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
933+
this.query({controller: 'server', action: timestamp ? 'getStats' : 'getLastStats'}, body, options, queryCB);
938934
};
939935

940936
/**
@@ -1035,7 +1031,7 @@ Kuzzle.prototype.listCollections = function () {
10351031
query.body.size = options.size;
10361032
}
10371033

1038-
this.query({index: index, controller: 'read', action: 'listCollections'}, query, options, function (err, res) {
1034+
this.query({index: index, controller: 'collection', action: 'list'}, query, options, function (err, res) {
10391035
if (err) {
10401036
return cb(err);
10411037
}
@@ -1058,7 +1054,7 @@ Kuzzle.prototype.listIndexes = function (options, cb) {
10581054

10591055
this.callbackRequired('Kuzzle.listIndexes', cb);
10601056

1061-
this.query({controller: 'read', action: 'listIndexes'}, {}, options, function (err, res) {
1057+
this.query({controller: 'index', action: 'list'}, {}, options, function (err, res) {
10621058
cb(err, err ? undefined : res.result.indexes);
10631059
});
10641060
};
@@ -1094,7 +1090,7 @@ Kuzzle.prototype.getServerInfo = function (options, cb) {
10941090

10951091
this.callbackRequired('Kuzzle.getServerInfo', cb);
10961092

1097-
this.query({controller: 'read', action: 'serverInfo'}, {}, options, function (err, res) {
1093+
this.query({controller: 'server', action: 'info'}, {}, options, function (err, res) {
10981094
if (err) {
10991095
return cb(err);
11001096
}
@@ -1138,7 +1134,7 @@ Kuzzle.prototype.refreshIndex = function () {
11381134
index = this.defaultIndex;
11391135
}
11401136

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

11431139
return this;
11441140
};
@@ -1178,7 +1174,7 @@ Kuzzle.prototype.getAutoRefresh = function () {
11781174
}
11791175

11801176
this.callbackRequired('Kuzzle.getAutoRefresh', cb);
1181-
this.query({ index: index, controller: 'admin', action: 'getAutoRefresh'}, {}, options, cb);
1177+
this.query({ index: index, controller: 'index', action: 'getAutoRefresh'}, {}, options, cb);
11821178
};
11831179

11841180
/**
@@ -1225,7 +1221,7 @@ Kuzzle.prototype.setAutoRefresh = function () {
12251221
throw new Error('Kuzzle.setAutoRefresh: autoRefresh value is required');
12261222
}
12271223

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

12301226
return this;
12311227
};
@@ -1243,7 +1239,7 @@ Kuzzle.prototype.now = function (options, cb) {
12431239

12441240
this.callbackRequired('Kuzzle.now', cb);
12451241

1246-
this.query({controller: 'read', action: 'now'}, {}, options, function (err, res) {
1242+
this.query({controller: 'server', action: 'now'}, {}, options, function (err, res) {
12471243
cb(err, res && res.result.now);
12481244
});
12491245
};

src/kuzzleDataCollection.js

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

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

100-
this.kuzzle.query(this.buildQueryArgs('read', 'count'), query, options, function (error, result) {
100+
this.kuzzle.query(this.buildQueryArgs('document', 'count'), query, options, function (error, result) {
101101
cb(error, result && result.result.count);
102102
});
103103
};
@@ -120,7 +120,7 @@ KuzzleDataCollection.prototype.create = function (options, cb) {
120120
}
121121

122122
data = this.kuzzle.addHeaders(data, this.headers);
123-
this.kuzzle.query(this.buildQueryArgs('write', 'createCollection'), data, options, cb);
123+
this.kuzzle.query(this.buildQueryArgs('collection', 'create'), data, options, cb);
124124

125125
return this;
126126
};
@@ -175,7 +175,7 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,
175175

176176
data = self.kuzzle.addHeaders(data, self.headers);
177177

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

181181
if (err) {
@@ -226,7 +226,7 @@ KuzzleDataCollection.prototype.deleteDocument = function (arg, options, cb) {
226226

227227
data = this.kuzzle.addHeaders(data, this.headers);
228228

229-
this.kuzzle.query(this.buildQueryArgs('write', action), data, options, cb && function (err, res) {
229+
this.kuzzle.query(this.buildQueryArgs('document', action), data, options, cb && function (err, res) {
230230
if (err) {
231231
cb(err);
232232
}
@@ -258,7 +258,7 @@ KuzzleDataCollection.prototype.fetchDocument = function (documentId, options, cb
258258
self.kuzzle.callbackRequired('KuzzleDataCollection.fetch', cb);
259259
data = self.kuzzle.addHeaders(data, this.headers);
260260

261-
self.kuzzle.query(this.buildQueryArgs('read', 'get'), data, options, function (err, res) {
261+
self.kuzzle.query(this.buildQueryArgs('document', 'get'), data, options, function (err, res) {
262262
var document;
263263

264264
if (err) {
@@ -377,7 +377,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options, cb)
377377
}
378378

379379
data = this.kuzzle.addHeaders(data, this.headers);
380-
this.kuzzle.query(this.buildQueryArgs('write', 'publish'), data, options, cb);
380+
this.kuzzle.query(this.buildQueryArgs('realtime', 'publish'), data, options, cb);
381381

382382
return this;
383383
};
@@ -410,7 +410,7 @@ KuzzleDataCollection.prototype.replaceDocument = function (documentId, content,
410410

411411
data = self.kuzzle.addHeaders(data, this.headers);
412412

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

416416
if (err) {
@@ -452,7 +452,7 @@ KuzzleDataCollection.prototype.search = function (filters, options, cb) {
452452
query = self.kuzzle.addHeaders({body: filters}, this.headers);
453453

454454

455-
self.kuzzle.query(this.buildQueryArgs('read', 'search'), query, options, function (error, result) {
455+
self.kuzzle.query(this.buildQueryArgs('document', 'search'), query, options, function (error, result) {
456456
var documents = [];
457457

458458
if (error) {
@@ -467,8 +467,8 @@ KuzzleDataCollection.prototype.search = function (filters, options, cb) {
467467
documents.push(newDocument);
468468
});
469469

470-
if (result.result['_scroll_id']) {
471-
options.scrollId = result.result['_scroll_id'];
470+
if (result.result._scroll_id) {
471+
options.scrollId = result.result._scroll_id;
472472
}
473473

474474
cb(null, new KuzzleSearchResult(
@@ -531,8 +531,8 @@ KuzzleDataCollection.prototype.scroll = function (scrollId, options, filters, cb
531531
documents.push(newDocument);
532532
});
533533

534-
if (result.result['_scroll_id']) {
535-
filters.scrollId = result.result['_scroll_id'];
534+
if (result.result._scroll_id) {
535+
filters.scrollId = result.result._scroll_id;
536536
}
537537

538538
cb(null, new KuzzleSearchResult(
@@ -593,7 +593,7 @@ KuzzleDataCollection.prototype.truncate = function (options, cb) {
593593
}
594594

595595
data = this.kuzzle.addHeaders(data, this.headers);
596-
this.kuzzle.query(this.buildQueryArgs('admin', 'truncateCollection'), data, options, cb);
596+
this.kuzzle.query(this.buildQueryArgs('collection', 'truncate'), data, options, cb);
597597

598598
return this;
599599
};
@@ -627,7 +627,7 @@ KuzzleDataCollection.prototype.updateDocument = function (documentId, content, o
627627

628628
data = self.kuzzle.addHeaders(data, this.headers);
629629

630-
self.kuzzle.query(this.buildQueryArgs('write', 'update'), data, options, cb && function (err, res) {
630+
self.kuzzle.query(this.buildQueryArgs('document', 'update'), data, options, cb && function (err, res) {
631631
if (err) {
632632
return cb(err);
633633
}

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: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,23 +212,9 @@ describe('Kuzzle constructor', () => {
212212
});
213213

214214
it('should throw an error if no URL is provided', () => {
215-
try {
215+
should(() => {
216216
new Kuzzle();
217-
should.fail('success', 'failure', 'Constructor should fail with no URL provided', '');
218-
}
219-
catch (e) {
220-
// done
221-
}
222-
});
223-
224-
it('should throw an error if no index is provied', () => {
225-
try {
226-
new Kuzzle('foo');
227-
should.fail('success', 'failure', 'Constructor should fail with no Index provided', '');
228-
}
229-
catch (e) {
230-
// done
231-
}
217+
}).throw();
232218
});
233219

234220
describe('#connect', function () {
@@ -913,7 +899,7 @@ describe('Kuzzle constructor', () => {
913899
kuzzle.login('local', loginCredentials);
914900
});
915901

916-
it('should have a empty token in logout callback', function (done) {
902+
it('should have a empty token in logout callback', function () {
917903
var
918904
unsetJwtToken = false,
919905
kuzzle;
@@ -932,10 +918,8 @@ describe('Kuzzle constructor', () => {
932918
cb(null, {});
933919
};
934920

935-
kuzzle.logout(function() {
936-
should(unsetJwtToken).be.exactly(true);
937-
done();
938-
});
921+
kuzzle.logout(() => {});
922+
should(unsetJwtToken).be.exactly(true);
939923
});
940924

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

0 commit comments

Comments
 (0)