diff --git a/doc/7/core-classes/profile/serialize/index.md b/doc/7/core-classes/profile/serialize/index.md new file mode 100644 index 000000000..17b48c090 --- /dev/null +++ b/doc/7/core-classes/profile/serialize/index.md @@ -0,0 +1,25 @@ +--- +code: true +type: page +title: serialize +description: Profile serialize method +--- + +# serialize + + + +Serialize the profile into a JSONObject. + +## Arguments + +```js +serialize(); +``` + +## Resolve + +Serialized profile with the following properties: + - `_id`: Profile ID + - `rateLimit`: Profile rate limits + - `policies`: Profile policies diff --git a/doc/7/core-classes/role/serialize/index.md b/doc/7/core-classes/role/serialize/index.md new file mode 100644 index 000000000..9be65f1bd --- /dev/null +++ b/doc/7/core-classes/role/serialize/index.md @@ -0,0 +1,24 @@ +--- +code: true +type: page +title: serialize +description: Role serialize method +--- + +# serialize + + + +Serialize the profile into a JSONObject. + +## Arguments + +```js +serialize(); +``` + +## Resolve + +Serialized role with the following properties: + - `_id`: Role ID + - `controllers`: Controllers definition diff --git a/doc/7/core-classes/user/serialize/index.md b/doc/7/core-classes/user/serialize/index.md new file mode 100644 index 000000000..c4c71656f --- /dev/null +++ b/doc/7/core-classes/user/serialize/index.md @@ -0,0 +1,24 @@ +--- +code: true +type: page +title: serialize +description: User serialize method +--- + +# serialize + + + +Serialize the user into a JSONObject. + +## Arguments + +```js +serialize(); +``` + +## Resolve + +Serialized user with the following properties: + - `_id`: User ID + - `_source`: User content diff --git a/package-lock.json b/package-lock.json index a62ec2f75..686077c7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "kuzzle-sdk", - "version": "7.6.1", + "version": "7.6.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 061b10951..7aae85fa0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kuzzle-sdk", - "version": "7.6.1", + "version": "7.6.2", "description": "Official Javascript SDK for Kuzzle", "author": "The Kuzzle Team ", "repository": { diff --git a/src/controllers/Document.ts b/src/controllers/Document.ts index 536fe95e6..c773aa6b6 100644 --- a/src/controllers/Document.ts +++ b/src/controllers/Document.ts @@ -263,6 +263,7 @@ export class DocumentController extends BaseController { * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications + * - `strict` If true, an error will occur if a document was not created * * @returns An object containing 2 arrays: "successes" and "errors" */ @@ -279,7 +280,7 @@ export class DocumentController extends BaseController { */ body: JSONObject; }>, - options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean } = {} + options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, strict?: boolean } = {} ): Promise<{ /** * Array of successfully created documents @@ -327,6 +328,7 @@ export class DocumentController extends BaseController { * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications + * - `strict` If true, an error will occur if a document was not created * * @returns An object containing 2 arrays: "successes" and "errors" */ @@ -343,7 +345,7 @@ export class DocumentController extends BaseController { */ body: JSONObject; }>, - options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean } = {} + options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, strict?: boolean } = {} ): Promise<{ /** * Array of successfully created documents @@ -391,6 +393,7 @@ export class DocumentController extends BaseController { * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications + * - `strict` If true, an error will occur if a document was not deleted * * @returns An object containing 2 arrays: "successes" and "errors" */ @@ -398,7 +401,7 @@ export class DocumentController extends BaseController { index: string, collection: string, ids: Array, - options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean } = {} + options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, strict?: boolean } = {} ): Promise<{ /** * Array of successfully deleted documents IDS @@ -482,6 +485,7 @@ export class DocumentController extends BaseController { * - `queuable` If true, queues the request during downtime, until connected to Kuzzle again * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications + * - `strict` If true, an error will occur if a document was not replaced * * @returns An object containing 2 arrays: "successes" and "errors" */ @@ -498,7 +502,7 @@ export class DocumentController extends BaseController { */ body: JSONObject; }>, - options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean } = {} + options: { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, strict?: boolean } = {} ): Promise<{ /** * Array of successfully replaced documents @@ -550,6 +554,7 @@ export class DocumentController extends BaseController { * - `refresh` If set to `wait_for`, Kuzzle will not respond until the API key is indexed * - `silent` If true, then Kuzzle will not generate notifications * - `retryOnConflict` Number of times the database layer should retry in case of version conflict + * - `strict` If true, an error will occur if a document was not updated * * @returns An object containing 2 arrays: "successes" and "errors" */ @@ -570,7 +575,8 @@ export class DocumentController extends BaseController { queuable?: boolean, refresh?: 'wait_for', silent?: boolean, - retryOnConflict?: number + retryOnConflict?: number, + strict?: boolean, } = {} ): Promise<{ /** diff --git a/src/core/security/Profile.ts b/src/core/security/Profile.ts index 7781b75b4..e52ded6f5 100644 --- a/src/core/security/Profile.ts +++ b/src/core/security/Profile.ts @@ -1,22 +1,21 @@ import { Role } from './Role'; -import { ProfilePolicy } from '../../types'; +import { JSONObject, ProfilePolicy } from '../../types'; export class Profile { /** * Profile unique ID */ - public _id: string; + _id: string; /** * Maximum number of requests per second and per node with this profile */ - public rateLimit: number; + rateLimit: number; /** * Array of policies */ - public policies: Array; - + policies: Array; private _kuzzle: any; @@ -51,4 +50,15 @@ export class Profile { this.policies.map(policy => policy.roleId), options); } + + /** + * Serialize the instance + */ + serialize (): JSONObject { + return { + _id: this._id, + rateLimit: this.rateLimit, + policies: this.policies, + }; + } } diff --git a/src/core/security/Role.ts b/src/core/security/Role.ts index 0f3d0592a..8dfddbe08 100644 --- a/src/core/security/Role.ts +++ b/src/core/security/Role.ts @@ -1,14 +1,15 @@ -import { RoleRightsDefinition } from '../../types'; +import { JSONObject, RoleRightsDefinition } from '../../types'; export class Role { /** * Role unique ID */ - public _id: string; + _id: string; + /** * List of rights on controllers/actions */ - public controllers: RoleRightsDefinition; + controllers: RoleRightsDefinition; private _kuzzle: any; @@ -28,6 +29,16 @@ export class Role { protected get kuzzle () { return this._kuzzle; } + + /** + * Serialize the instance + */ + serialize (): JSONObject { + return { + _id: this._id, + controllers: this.controllers, + }; + } } module.exports = { Role }; diff --git a/src/core/security/User.ts b/src/core/security/User.ts index f6ed3719c..735cc1acd 100644 --- a/src/core/security/User.ts +++ b/src/core/security/User.ts @@ -5,21 +5,19 @@ export class User { /** * Kuid (Kuzzle unique ID) */ - public _id: string; + _id: string; /** * User content */ - public _source: JSONObject; + _source: JSONObject; /** * User content * - * @deprecated + * @deprecated Use User._source instead */ - get content (): JSONObject { - return this._source; - } + content: JSONObject private _kuzzle: any; @@ -33,6 +31,13 @@ export class User { value: kuzzle }); + Reflect.defineProperty(this, 'content', { + enumerable: true, + get () { + return this._source; + } + }); + this._id = _id; this._source = content; } @@ -59,6 +64,15 @@ export class User { return this.kuzzle.security.mGetProfiles(this.profileIds); } + /** + * Serialize the instance + */ + serialize (): JSONObject { + return { + _id: this._id, + _source: this._source, + }; + } } module.exports = { User };