Skip to content

Commit ff49bb5

Browse files
kuzzleAschen
authored andcommitted
Release 6.1.1 (#393)
# [6.1.1](https://github.com/kuzzleio/sdk-javascript/releases/tag/6.1.1) (2019-04-29) #### Bug fixes - [ [#384](#384) ] [fix] search API: "sort" and "search_after" must be in the requests body ([scottinet](https://github.com/scottinet)) #### Enhancements - [ [#388](#388) ] Use BaseController class for controllers ([Aschen](https://github.com/Aschen)) - [ [#385](#385) ] Add Realtime.createRestrictedUser method ([Aschen](https://github.com/Aschen)) #### Others - [ [#387](#387) ] SearchResult.next returns a new instance ([Aschen](https://github.com/Aschen)) ---
1 parent 11afe36 commit ff49bb5

25 files changed

+601
-580
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

src/Kuzzle.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ class Kuzzle extends KuzzleEventEmitter {
6262
this.volatile = typeof options.volatile === 'object' ? options.volatile : {};
6363

6464
// controllers
65-
this.auth = new AuthController(this);
66-
this.bulk = new BulkController(this);
67-
this.collection = new CollectionController(this);
68-
this.document = new DocumentController(this);
69-
this.index = new IndexController(this);
70-
this.ms = new MemoryStorageController(this);
71-
this.realtime = new RealtimeController(this);
72-
this.security = new SecurityController(this);
73-
this.server = new ServerController(this);
65+
this.useController(AuthController, 'auth');
66+
this.useController(BulkController, 'bulk');
67+
this.useController(CollectionController, 'collection');
68+
this.useController(DocumentController, 'document');
69+
this.useController(IndexController, 'index');
70+
this.useController(MemoryStorageController, 'ms');
71+
this.useController(RealtimeController, 'realtime');
72+
this.useController(SecurityController, 'security');
73+
this.useController(ServerController, 'server');
7474

7575
// offline queue
7676
this._autoQueue = typeof options.autoQueue === 'boolean' ? options.autoQueue : false;
@@ -443,28 +443,34 @@ Discarded request: ${JSON.stringify(request)}`));
443443
/**
444444
* Adds a new controller and make it available in the SDK.
445445
*
446-
* @param {BaseController} controller
446+
* @param {BaseController} ControllerClass
447+
* @param {string} accessor
447448
* @returns {Kuzzle}
448449
*/
449-
useController (controller) {
450-
if (!(controller instanceof BaseController)) {
450+
useController (ControllerClass, accessor) {
451+
if (!(ControllerClass.prototype instanceof BaseController)) {
451452
throw new Error('Controllers must inherits from the BaseController class.');
452453
}
453454

454-
if (!(controller.name && controller.name.length > 0)) {
455-
throw new Error('Controllers must have a name.');
455+
if (!(accessor && accessor.length > 0)) {
456+
throw new Error('You must provide a valid accessor.');
457+
}
458+
459+
if (this[accessor]) {
460+
throw new Error(`There is already a controller with the accessor '${accessor}'. Please use another one.`);
456461
}
457462

458-
if (!(controller.accessor && controller.accessor.length > 0)) {
459-
throw new Error('Controllers must have an accessor.');
463+
const controller = new ControllerClass(this);
464+
465+
if (!(controller.name && controller.name.length > 0)) {
466+
throw new Error('Controllers must have a name.');
460467
}
461468

462-
if (this[controller.accessor]) {
463-
throw new Error(`There is already a controller with the accessor '${controller.accessor}'. Please use another one.`);
469+
if (controller.kuzzle !== this) {
470+
throw new Error('You must pass the Kuzzle SDK instance to the parent constructor.');
464471
}
465472

466-
controller.kuzzle = this;
467-
this[controller.accessor] = controller;
473+
this[accessor] = controller;
468474

469475
return this;
470476
}

src/controllers/auth.js

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
const User = require('./security/user');
1+
const
2+
BaseController = require('./base'),
3+
User = require('./security/user');
24

35
/**
46
* Auth controller
57
*
68
* @param kuzzle
79
* @constructor
810
*/
9-
class AuthController {
11+
class AuthController extends BaseController {
1012

1113
/**
1214
* constructor
1315
* @param kuzzle
1416
*/
1517
constructor (kuzzle) {
16-
this._kuzzle = kuzzle;
17-
}
18-
19-
get kuzzle () {
20-
return this._kuzzle;
18+
super(kuzzle, 'auth');
2119
}
2220

2321
/**
@@ -27,8 +25,7 @@ class AuthController {
2725
* @return {Promise|*|PromiseLike<T>|Promise<T>}
2826
*/
2927
checkToken (token) {
30-
return this.kuzzle.query({
31-
controller: 'auth',
28+
return this.query({
3229
action: 'checkToken',
3330
body: {token}
3431
}, {queuable: false})
@@ -44,9 +41,8 @@ class AuthController {
4441
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
4542
*/
4643
createMyCredentials (strategy, credentials, options = {}) {
47-
return this.kuzzle.query({
44+
return this.query({
4845
strategy,
49-
controller: 'auth',
5046
action: 'createMyCredentials',
5147
body: credentials
5248
}, options)
@@ -60,9 +56,8 @@ class AuthController {
6056
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
6157
*/
6258
credentialsExist (strategy, options = {}) {
63-
return this.kuzzle.query({
59+
return this.query({
6460
strategy,
65-
controller: 'auth',
6661
action: 'credentialsExist'
6762
}, options)
6863
.then(response => response.result);
@@ -76,9 +71,8 @@ class AuthController {
7671
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
7772
*/
7873
deleteMyCredentials (strategy, options = {}) {
79-
return this.kuzzle.query({
74+
return this.query({
8075
strategy,
81-
controller: 'auth',
8276
action: 'deleteMyCredentials'
8377
}, options)
8478
.then(response => response.result.acknowledged);
@@ -90,8 +84,7 @@ class AuthController {
9084
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
9185
*/
9286
getCurrentUser (options = {}) {
93-
return this.kuzzle.query({
94-
controller: 'auth',
87+
return this.query({
9588
action: 'getCurrentUser'
9689
}, options)
9790
.then(response => new User(this.kuzzle, response.result._id, response.result._source, response.result._meta));
@@ -104,9 +97,8 @@ class AuthController {
10497
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
10598
*/
10699
getMyCredentials(strategy, options = {}) {
107-
return this.kuzzle.query({
100+
return this.query({
108101
strategy,
109-
controller: 'auth',
110102
action: 'getMyCredentials'
111103
}, options)
112104
.then(response => response.result);
@@ -119,8 +111,7 @@ class AuthController {
119111
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
120112
*/
121113
getMyRights (options = {}) {
122-
return this.kuzzle.query({
123-
controller: 'auth',
114+
return this.query({
124115
action: 'getMyRights'
125116
}, options)
126117
.then(response => response.result.hits);
@@ -133,8 +124,7 @@ class AuthController {
133124
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
134125
*/
135126
getStrategies (options = {}) {
136-
return this.kuzzle.query({
137-
controller: 'auth',
127+
return this.query({
138128
action: 'getStrategies'
139129
}, options)
140130
.then(response => response.result);
@@ -159,11 +149,10 @@ class AuthController {
159149
strategy,
160150
expiresIn,
161151
body: credentials,
162-
controller: 'auth',
163152
action: 'login'
164153
};
165154

166-
return this.kuzzle.query(request, {queuable: false})
155+
return this.query(request, {queuable: false})
167156
.then(response => {
168157
try {
169158
this.kuzzle.jwt = response.result.jwt;
@@ -186,8 +175,7 @@ class AuthController {
186175
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
187176
*/
188177
logout () {
189-
return this.kuzzle.query({
190-
controller: 'auth',
178+
return this.query({
191179
action: 'logout'
192180
}, {queuable: false})
193181
.then(() => {
@@ -204,10 +192,9 @@ class AuthController {
204192
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
205193
*/
206194
updateMyCredentials (strategy, credentials, options = {}) {
207-
return this.kuzzle.query({
195+
return this.query({
208196
strategy,
209197
body: credentials,
210-
controller: 'auth',
211198
action: 'updateMyCredentials'
212199
}, options)
213200
.then(response => response.result);
@@ -221,9 +208,8 @@ class AuthController {
221208
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
222209
*/
223210
updateSelf (body, options = {}) {
224-
return this.kuzzle.query({
211+
return this.query({
225212
body,
226-
controller: 'auth',
227213
action: 'updateSelf'
228214
}, options)
229215
.then(response => new User(this.kuzzle, response.result._id, response.result._source, response.result._meta));
@@ -238,10 +224,9 @@ class AuthController {
238224
* @returns {Promise|*|PromiseLike<T>|Promise<T>}
239225
*/
240226
validateMyCredentials (strategy, credentials, options = {}) {
241-
return this.kuzzle.query({
227+
return this.query({
242228
strategy,
243229
body: credentials,
244-
controller: 'auth',
245230
action: 'validateMyCredentials'
246231
}, options)
247232
.then(response => response.result);
@@ -255,12 +240,11 @@ class AuthController {
255240
*/
256241
refreshToken(options = {}) {
257242
const query = {
258-
controller: 'auth',
259243
action: 'refreshToken',
260244
expiresIn: options.expiresIn
261245
};
262246

263-
return this.kuzzle.query(query, options)
247+
return this.query(query, options)
264248
.then(response => {
265249
this.kuzzle.jwt = response.result.jwt;
266250

src/controllers/base.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
class BaseController {
22

33
/**
4+
* @param {Kuzzle} kuzzle - Kuzzle SDK object.
45
* @param {string} name - Controller full name for API request.
5-
* @param {string} accessor - Controller accessor name on Kuzzle object.
66
*/
7-
constructor (name, accessor) {
8-
this.name = name;
9-
this.accessor = accessor;
7+
constructor (kuzzle, name) {
8+
this._kuzzle = kuzzle;
9+
this._name = name;
1010
}
1111

1212
get kuzzle () {
1313
return this._kuzzle;
1414
}
1515

16-
set kuzzle (kuzzle) {
17-
this._kuzzle = kuzzle;
16+
get name () {
17+
return this._name;
1818
}
1919

2020
/**
@@ -25,7 +25,7 @@ class BaseController {
2525
query (request = {}, options = {}) {
2626
request.controller = request.controller || this.name;
2727

28-
return this.kuzzle.query(request, options);
28+
return this._kuzzle.query(request, options);
2929
}
3030
}
3131

src/controllers/bulk.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
class BulkController {
2-
constructor (kuzzle) {
3-
this._kuzzle = kuzzle;
4-
}
1+
const BaseController = require('./base');
52

6-
get kuzzle () {
7-
return this._kuzzle;
3+
class BulkController extends BaseController {
4+
constructor (kuzzle) {
5+
super(kuzzle, 'bulk');
86
}
97

108
import (data, options) {
11-
return this.kuzzle.query({
12-
controller: 'bulk',
9+
return this.query({
1310
action: 'import',
1411
body: {
1512
bulkData: data

0 commit comments

Comments
 (0)