Skip to content

Commit c21faed

Browse files
authored
Merge a8c2511 into 1bf128c
2 parents 1bf128c + a8c2511 commit c21faed

File tree

9 files changed

+135
-21
lines changed

9 files changed

+135
-21
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
code: true
3+
type: page
4+
title: serialize
5+
description: Profile serialize method
6+
---
7+
8+
# serialize
9+
10+
<SinceBadge version="7.6.2" />
11+
12+
Serialize the profile into a JSONObject.
13+
14+
## Arguments
15+
16+
```js
17+
serialize();
18+
```
19+
20+
## Resolve
21+
22+
Serialized profile with the following properties:
23+
- `_id`: Profile ID
24+
- `rateLimit`: Profile rate limits
25+
- `policies`: Profile policies
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
code: true
3+
type: page
4+
title: serialize
5+
description: Role serialize method
6+
---
7+
8+
# serialize
9+
10+
<SinceBadge version="7.6.2" />
11+
12+
Serialize the profile into a JSONObject.
13+
14+
## Arguments
15+
16+
```js
17+
serialize();
18+
```
19+
20+
## Resolve
21+
22+
Serialized role with the following properties:
23+
- `_id`: Role ID
24+
- `controllers`: Controllers definition
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
code: true
3+
type: page
4+
title: serialize
5+
description: User serialize method
6+
---
7+
8+
# serialize
9+
10+
<SinceBadge version="7.6.2" />
11+
12+
Serialize the user into a JSONObject.
13+
14+
## Arguments
15+
16+
```js
17+
serialize();
18+
```
19+
20+
## Resolve
21+
22+
Serialized user with the following properties:
23+
- `_id`: User ID
24+
- `_source`: User content

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

src/controllers/Document.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export class DocumentController extends BaseController {
263263
* - `queuable` If true, queues the request during downtime, until connected to Kuzzle again
264264
* - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed
265265
* - `silent` If true, then Kuzzle will not generate notifications
266+
* - `strict` If true, an error will occur if a document was not created
266267
*
267268
* @returns An object containing 2 arrays: "successes" and "errors"
268269
*/
@@ -279,7 +280,7 @@ export class DocumentController extends BaseController {
279280
*/
280281
body: JSONObject;
281282
}>,
282-
options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean } = {}
283+
options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, strict?: boolean } = {}
283284
): Promise<{
284285
/**
285286
* Array of successfully created documents
@@ -327,6 +328,7 @@ export class DocumentController extends BaseController {
327328
* - `queuable` If true, queues the request during downtime, until connected to Kuzzle again
328329
* - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed
329330
* - `silent` If true, then Kuzzle will not generate notifications
331+
* - `strict` If true, an error will occur if a document was not created
330332
*
331333
* @returns An object containing 2 arrays: "successes" and "errors"
332334
*/
@@ -343,7 +345,7 @@ export class DocumentController extends BaseController {
343345
*/
344346
body: JSONObject;
345347
}>,
346-
options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean } = {}
348+
options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, strict?: boolean } = {}
347349
): Promise<{
348350
/**
349351
* Array of successfully created documents
@@ -391,14 +393,15 @@ export class DocumentController extends BaseController {
391393
* - `queuable` If true, queues the request during downtime, until connected to Kuzzle again
392394
* - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed
393395
* - `silent` If true, then Kuzzle will not generate notifications
396+
* - `strict` If true, an error will occur if a document was not deleted
394397
*
395398
* @returns An object containing 2 arrays: "successes" and "errors"
396399
*/
397400
mDelete (
398401
index: string,
399402
collection: string,
400403
ids: Array<string>,
401-
options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean } = {}
404+
options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, strict?: boolean } = {}
402405
): Promise<{
403406
/**
404407
* Array of successfully deleted documents IDS
@@ -482,6 +485,7 @@ export class DocumentController extends BaseController {
482485
* - `queuable` If true, queues the request during downtime, until connected to Kuzzle again
483486
* - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed
484487
* - `silent` If true, then Kuzzle will not generate notifications
488+
* - `strict` If true, an error will occur if a document was not replaced
485489
*
486490
* @returns An object containing 2 arrays: "successes" and "errors"
487491
*/
@@ -498,7 +502,7 @@ export class DocumentController extends BaseController {
498502
*/
499503
body: JSONObject;
500504
}>,
501-
options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean } = {}
505+
options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, strict?: boolean } = {}
502506
): Promise<{
503507
/**
504508
* Array of successfully replaced documents
@@ -550,6 +554,7 @@ export class DocumentController extends BaseController {
550554
* - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed
551555
* - `silent` If true, then Kuzzle will not generate notifications
552556
* - `retryOnConflict` Number of times the database layer should retry in case of version conflict
557+
* - `strict` If true, an error will occur if a document was not updated
553558
*
554559
* @returns An object containing 2 arrays: "successes" and "errors"
555560
*/
@@ -570,7 +575,8 @@ export class DocumentController extends BaseController {
570575
queuable?: boolean,
571576
refresh?: 'wait_for',
572577
silent?: boolean,
573-
retryOnConflict?: number
578+
retryOnConflict?: number,
579+
strict?: boolean,
574580
} = {}
575581
): Promise<{
576582
/**

src/core/security/Profile.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { Role } from './Role';
2-
import { ProfilePolicy } from '../../types';
2+
import { JSONObject, ProfilePolicy } from '../../types';
33

44
export class Profile {
55
/**
66
* Profile unique ID
77
*/
8-
public _id: string;
8+
_id: string;
99

1010
/**
1111
* Maximum number of requests per second and per node with this profile
1212
*/
13-
public rateLimit: number;
13+
rateLimit: number;
1414

1515
/**
1616
* Array of policies
1717
*/
18-
public policies: Array<ProfilePolicy>;
19-
18+
policies: Array<ProfilePolicy>;
2019

2120
private _kuzzle: any;
2221

@@ -51,4 +50,15 @@ export class Profile {
5150
this.policies.map(policy => policy.roleId),
5251
options);
5352
}
53+
54+
/**
55+
* Serialize the instance
56+
*/
57+
serialize (): JSONObject {
58+
return {
59+
_id: this._id,
60+
rateLimit: this.rateLimit,
61+
policies: this.policies,
62+
};
63+
}
5464
}

src/core/security/Role.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { RoleRightsDefinition } from '../../types';
1+
import { JSONObject, RoleRightsDefinition } from '../../types';
22

33
export class Role {
44
/**
55
* Role unique ID
66
*/
7-
public _id: string;
7+
_id: string;
8+
89
/**
910
* List of rights on controllers/actions
1011
*/
11-
public controllers: RoleRightsDefinition;
12+
controllers: RoleRightsDefinition;
1213

1314
private _kuzzle: any;
1415

@@ -28,6 +29,16 @@ export class Role {
2829
protected get kuzzle () {
2930
return this._kuzzle;
3031
}
32+
33+
/**
34+
* Serialize the instance
35+
*/
36+
serialize (): JSONObject {
37+
return {
38+
_id: this._id,
39+
controllers: this.controllers,
40+
};
41+
}
3142
}
3243

3344
module.exports = { Role };

src/core/security/User.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@ export class User {
55
/**
66
* Kuid (Kuzzle unique ID)
77
*/
8-
public _id: string;
8+
_id: string;
99

1010
/**
1111
* User content
1212
*/
13-
public _source: JSONObject;
13+
_source: JSONObject;
1414

1515
/**
1616
* User content
1717
*
18-
* @deprecated
18+
* @deprecated Use User._source instead
1919
*/
20-
get content (): JSONObject {
21-
return this._source;
22-
}
20+
content: JSONObject
2321

2422
private _kuzzle: any;
2523

@@ -33,6 +31,13 @@ export class User {
3331
value: kuzzle
3432
});
3533

34+
Reflect.defineProperty(this, 'content', {
35+
enumerable: true,
36+
get () {
37+
return this._source;
38+
}
39+
});
40+
3641
this._id = _id;
3742
this._source = content;
3843
}
@@ -59,6 +64,15 @@ export class User {
5964
return this.kuzzle.security.mGetProfiles(this.profileIds);
6065
}
6166

67+
/**
68+
* Serialize the instance
69+
*/
70+
serialize (): JSONObject {
71+
return {
72+
_id: this._id,
73+
_source: this._source,
74+
};
75+
}
6276
}
6377

6478
module.exports = { User };

0 commit comments

Comments
 (0)