kuzzle 2.16.1 → 2.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,7 +47,11 @@ class ServerController extends NativeController {
47
47
  'publicApi',
48
48
  'openapi',
49
49
  ]);
50
- this._docOpenapi = generateOpenApi();
50
+
51
+ this._openApiDefinition = {
52
+ json: null,
53
+ yaml: null,
54
+ };
51
55
  }
52
56
 
53
57
  /**
@@ -55,7 +59,7 @@ class ServerController extends NativeController {
55
59
  *
56
60
  * @param {Request} request
57
61
  * @returns {Promise<Object>}
58
- *
62
+ *
59
63
  * @deprecated
60
64
  */
61
65
  getStats (request) {
@@ -66,7 +70,7 @@ class ServerController extends NativeController {
66
70
  * Returns the last statistics frame
67
71
  *
68
72
  * @returns {Promise<Object>}
69
- *
73
+ *
70
74
  * @deprecated
71
75
  */
72
76
  getLastStats () {
@@ -77,7 +81,7 @@ class ServerController extends NativeController {
77
81
  * Returns all stored statistics frames
78
82
  *
79
83
  * @returns {Promise<Object>}
80
- *
84
+ *
81
85
  * @deprecated
82
86
  */
83
87
  getAllStats () {
@@ -242,25 +246,34 @@ class ServerController extends NativeController {
242
246
  }
243
247
 
244
248
  async openapi (request) {
245
- const format = request.input.args.format
246
- ? request.input.args.format
247
- : 'json';
248
- const contentType = format === 'yaml'
249
- ? 'application/yaml'
250
- : 'application/json';
251
- const specifications = format === 'yaml'
252
- ? jsonToYaml.stringify(this._docOpenapi)
253
- : this._docOpenapi;
249
+ const format = request.getString('format', 'json');
250
+ const specifications = this.getOpenApiDefinition(format);
254
251
 
255
252
  request.response.configure({
256
253
  format: 'raw',
257
- headers: { 'Content-Type': contentType },
254
+ headers: { 'Content-Type': `application/${format}` },
258
255
  status: 200,
259
256
  });
260
257
 
261
258
  return specifications;
262
259
  }
263
260
 
261
+ /**
262
+ * Lazy loading of OpenAPI definition.
263
+ *
264
+ * Mainly because we need to wait all plugin to be loaded
265
+ * to generate the definition.
266
+ */
267
+ getOpenApiDefinition (format) {
268
+ if (! this._openApiDefinition[format]) {
269
+ this._openApiDefinition[format] = format === 'json'
270
+ ? generateOpenApi()
271
+ : jsonToYaml.stringify(generateOpenApi());
272
+ }
273
+
274
+ return this._openApiDefinition[format];
275
+ }
276
+
264
277
  /**
265
278
  * Fetches and returns Kuzzle core metrics
266
279
  * @returns {Promise<Object>}
@@ -1,6 +1,7 @@
1
+ import { JSONObject } from '../../index';
1
2
  /**
2
3
  * Generates JSON OpenApi object
3
4
  *
4
5
  * @returns {object} openApi object
5
6
  */
6
- export declare function generateOpenApi(): any;
7
+ export declare function generateOpenApi(): JSONObject;
@@ -1,9 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateOpenApi = void 0;
7
2
  /*
8
3
  * Kuzzle, a backend software, self-hostable and ready to use
9
4
  * to power modern apps
@@ -24,13 +19,18 @@ exports.generateOpenApi = void 0;
24
19
  * See the License for the specific language governing permissions and
25
20
  * limitations under the License.
26
21
  */
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.generateOpenApi = void 0;
27
27
  const lodash_1 = __importDefault(require("lodash"));
28
- const package_json_1 = require("./../../package.json");
29
- const document_1 = require("./openapi/document");
30
- const inflector_1 = require("./../util/inflector");
28
+ const package_json_1 = require("../../package.json");
29
+ const openapi_1 = require("./openapi");
30
+ const inflector_1 = require("../util/inflector");
31
31
  const routeUrlMatch = /:([^/]*)/g;
32
32
  /**
33
- * Genrate basic openApi Controller
33
+ * Generate basic openApi Controller
34
34
  */
35
35
  function generateController(route, response) {
36
36
  if (route.controller !== undefined) {
@@ -47,7 +47,7 @@ function generateController(route, response) {
47
47
  }
48
48
  }
49
49
  /**
50
- * Genrate basic openApi Summary
50
+ * Generate basic openApi Summary
51
51
  */
52
52
  function generateSummary(route) {
53
53
  if (route.openapi.description === undefined) {
@@ -58,7 +58,7 @@ function generateSummary(route) {
58
58
  }
59
59
  }
60
60
  /**
61
- * Genrate basic openApi Parameters
61
+ * Generate basic openApi Parameters
62
62
  */
63
63
  function generateParameters(route) {
64
64
  if (route.openapi.parameters === undefined) {
@@ -80,7 +80,7 @@ function generateParameters(route) {
80
80
  }
81
81
  }
82
82
  /**
83
- * Genrate basic openApi Response
83
+ * Generate basic openApi Response
84
84
  */
85
85
  function generateResponse(route) {
86
86
  if (route.openapi.responses === undefined) {
@@ -96,22 +96,20 @@ function generateResponse(route) {
96
96
  *
97
97
  * @returns {object} openApi object
98
98
  */
99
- /* eslint-disable @typescript-eslint/no-unused-vars */
100
99
  function generateOpenApi() {
101
- /* eslint-enable @typescript-eslint/no-unused-vars */
102
100
  const routes = [];
103
- global.kuzzle.config.http.routes.forEach(_route => routes.push({ ..._route }));
104
- global.kuzzle.pluginsManager.routes.forEach(_route => routes.push({ ..._route }));
101
+ global.kuzzle.config.http.routes.forEach(route => routes.push({ ...route }));
102
+ global.kuzzle.pluginsManager.routes.forEach(route => routes.push({ ...route }));
105
103
  /* eslint-disable sort-keys */
106
104
  const response = {
107
105
  swagger: '2.0',
108
106
  info: {
109
107
  title: 'Kuzzle API',
110
- description: 'The Kuzzle HTTP API',
108
+ description: 'Kuzzle HTTP API definition',
111
109
  contact: {
112
110
  name: 'Kuzzle team',
113
- url: 'http://kuzzle.io',
114
- email: 'hello@kuzzle.io',
111
+ url: 'https://kuzzle.io',
112
+ email: 'support@kuzzle.io',
115
113
  discord: 'http://join.discord.kuzzle.io'
116
114
  },
117
115
  license: {
@@ -150,18 +148,18 @@ function generateOpenApi() {
150
148
  ],
151
149
  paths: {},
152
150
  components: {
153
- ...document_1.DefinitionsDocument,
151
+ ...openapi_1.OpenApiPayloadsDefinitions,
154
152
  schemas: {
155
- ...document_1.OpenApiDocumentCountComponent,
156
- ...document_1.OpenApiDocumentDeleteByQueryComponent,
157
- ...document_1.OpenApiDocumentDeleteComponent,
158
- ...document_1.OpenApiDocumentScrollComponent,
159
- ...document_1.OpenApiDocumentExistsComponent,
160
- ...document_1.OpenApiDocumentUpdateComponent,
161
- ...document_1.OpenApiDocumentReplaceComponent,
162
- ...document_1.OpenApiDocumentGetComponent,
163
- ...document_1.OpenApiDocumentCreateOrReplaceComponent,
164
- ...document_1.OpenApiDocumentCreateComponent,
153
+ ...openapi_1.OpenApiDocumentCountComponent,
154
+ ...openapi_1.OpenApiDocumentDeleteByQueryComponent,
155
+ ...openapi_1.OpenApiDocumentDeleteComponent,
156
+ ...openapi_1.OpenApiDocumentScrollComponent,
157
+ ...openapi_1.OpenApiDocumentExistsComponent,
158
+ ...openapi_1.OpenApiDocumentUpdateComponent,
159
+ ...openapi_1.OpenApiDocumentReplaceComponent,
160
+ ...openapi_1.OpenApiDocumentGetComponent,
161
+ ...openapi_1.OpenApiDocumentCreateOrReplaceComponent,
162
+ ...openapi_1.OpenApiDocumentCreateComponent,
165
163
  }
166
164
  }
167
165
  };
@@ -18,4 +18,3 @@ export declare const OpenApiDocumentDelete: any;
18
18
  export declare const OpenApiDocumentDeleteComponent: any;
19
19
  export declare const OpenApiDocumentDeleteByQuery: any;
20
20
  export declare const OpenApiDocumentDeleteByQueryComponent: any;
21
- export declare const DefinitionsDocument: any;
@@ -1,57 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefinitionsDocument = exports.OpenApiDocumentDeleteByQueryComponent = exports.OpenApiDocumentDeleteByQuery = exports.OpenApiDocumentDeleteComponent = exports.OpenApiDocumentDelete = exports.OpenApiDocumentScrollComponent = exports.OpenApiDocumentScroll = exports.OpenApiDocumentUpdateComponent = exports.OpenApiDocumentUpdate = exports.OpenApiDocumentExistsComponent = exports.OpenApiDocumentExists = exports.OpenApiDocumentReplaceComponent = exports.OpenApiDocumentReplace = exports.OpenApiDocumentGetComponent = exports.OpenApiDocumentGet = exports.OpenApiDocumentCreateOrReplaceComponent = exports.OpenApiDocumentCreateOrReplace = exports.OpenApiDocumentCreateComponent = exports.OpenApiDocumentCreate = exports.OpenApiDocumentCountComponent = exports.OpenApiDocumentCount = void 0;
3
+ exports.OpenApiDocumentDeleteByQueryComponent = exports.OpenApiDocumentDeleteByQuery = exports.OpenApiDocumentDeleteComponent = exports.OpenApiDocumentDelete = exports.OpenApiDocumentScrollComponent = exports.OpenApiDocumentScroll = exports.OpenApiDocumentUpdateComponent = exports.OpenApiDocumentUpdate = exports.OpenApiDocumentExistsComponent = exports.OpenApiDocumentExists = exports.OpenApiDocumentReplaceComponent = exports.OpenApiDocumentReplace = exports.OpenApiDocumentGetComponent = exports.OpenApiDocumentGet = exports.OpenApiDocumentCreateOrReplaceComponent = exports.OpenApiDocumentCreateOrReplace = exports.OpenApiDocumentCreateComponent = exports.OpenApiDocumentCreate = exports.OpenApiDocumentCountComponent = exports.OpenApiDocumentCount = void 0;
4
4
  const readYamlFile_1 = require("../../../util/readYamlFile");
5
5
  // reading the description of the Count action in the controller document.
6
6
  // The yaml objects are then stored in the variables below
7
- const countObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/count.yaml');
7
+ const countObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/count.yaml');
8
8
  exports.OpenApiDocumentCount = countObject.DocumentCount;
9
9
  exports.OpenApiDocumentCountComponent = countObject.components.schemas;
10
10
  // reading the description of the Create action in the controller document.
11
11
  // The yaml objects are then stored in the variables below
12
- const createObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/create.yaml');
12
+ const createObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/create.yaml');
13
13
  exports.OpenApiDocumentCreate = createObject.DocumentCreate;
14
14
  exports.OpenApiDocumentCreateComponent = createObject.components.schemas;
15
15
  // reading the description of the CreateOrReplace action in the controller document.
16
16
  // The yaml objects are then stored in the variables below
17
- const createOrReplaceObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/createOrReplace.yaml');
17
+ const createOrReplaceObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/createOrReplace.yaml');
18
18
  exports.OpenApiDocumentCreateOrReplace = createOrReplaceObject.DocumentCreateOrReplace;
19
19
  exports.OpenApiDocumentCreateOrReplaceComponent = createOrReplaceObject.components.schemas;
20
20
  // reading the description of the Get action in the controller document.
21
21
  // The yaml objects are then stored in the variables below
22
- const getObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/get.yaml');
22
+ const getObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/get.yaml');
23
23
  exports.OpenApiDocumentGet = getObject.DocumentGet;
24
24
  exports.OpenApiDocumentGetComponent = getObject.components.schemas;
25
25
  // reading the description of the Replace action in the controller document.
26
26
  // The yaml objects are then stored in the variables below
27
- const replaceObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/replace.yaml');
27
+ const replaceObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/replace.yaml');
28
28
  exports.OpenApiDocumentReplace = replaceObject.DocumentReplace;
29
29
  exports.OpenApiDocumentReplaceComponent = replaceObject.components.schemas;
30
30
  // reading the description of the Exists action in the controller document.
31
31
  // The yaml objects are then stored in the variables below
32
- const existsObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/exists.yaml');
32
+ const existsObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/exists.yaml');
33
33
  exports.OpenApiDocumentExists = existsObject.DocumentExists;
34
34
  exports.OpenApiDocumentExistsComponent = existsObject.components.schemas;
35
35
  // reading the description of the Update action in the controller document.
36
36
  // The yaml objects are then stored in the variables below
37
- const updateObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/update.yaml');
37
+ const updateObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/update.yaml');
38
38
  exports.OpenApiDocumentUpdate = updateObject.DocumentUpdate;
39
39
  exports.OpenApiDocumentUpdateComponent = updateObject.components.schemas;
40
40
  // reading the description of the Scroll action in the controller document.
41
41
  // The yaml objects are then stored in the variables below
42
- const scrollObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/scroll.yaml');
42
+ const scrollObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/scroll.yaml');
43
43
  exports.OpenApiDocumentScroll = scrollObject.DocumentScroll;
44
44
  exports.OpenApiDocumentScrollComponent = scrollObject.components.schemas;
45
45
  // reading the description of the Delete action in the controller document.
46
46
  // The yaml objects are then stored in the variables below
47
- const deleteObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/delete.yaml');
47
+ const deleteObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/delete.yaml');
48
48
  exports.OpenApiDocumentDelete = deleteObject.DocumentDelete;
49
49
  exports.OpenApiDocumentDeleteComponent = deleteObject.components.schemas;
50
50
  // reading the description of the DeleteByQuery action in the controller document.
51
51
  // The yaml objects are then stored in the variables below
52
- const deleteByQueryObject = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/document/deleteByQuery.yaml');
52
+ const deleteByQueryObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/deleteByQuery.yaml');
53
53
  exports.OpenApiDocumentDeleteByQuery = deleteByQueryObject.DocumentDeleteByQuery;
54
54
  exports.OpenApiDocumentDeleteByQueryComponent = deleteByQueryObject.components.schemas;
55
- // Document definitions (reusable object for KuzzleRequest and KuzzleResponse)
56
- exports.DefinitionsDocument = (0, readYamlFile_1.readYamlFile)('./lib/api/openapi/payloads.yaml').definitions;
57
55
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export * from './document';
2
+ export declare const OpenApiPayloadsDefinitions: any;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.OpenApiPayloadsDefinitions = void 0;
14
+ const readYamlFile_1 = require("../../util/readYamlFile");
15
+ __exportStar(require("./document"), exports);
16
+ // Document definitions (reusable object for KuzzleRequest and KuzzleResponse)
17
+ exports.OpenApiPayloadsDefinitions = (0, readYamlFile_1.readYamlFile)(__dirname + '/payloads.yaml').definitions;
18
+ //# sourceMappingURL=index.js.map
@@ -1,5 +1,6 @@
1
1
  import { JSONObject } from 'kuzzle-sdk';
2
2
  import { RequestInput } from './requestInput';
3
+ import { RequestResponse } from './requestResponse';
3
4
  import { RequestContext } from './requestContext';
4
5
  import { KuzzleError } from '../../kerror/errors';
5
6
  import { Deprecation, User } from '../../types';
@@ -12,46 +13,47 @@ import { Deprecation, User } from '../../types';
12
13
  */
13
14
  export declare class KuzzleRequest {
14
15
  /**
15
- * Deprecation warnings for the API action
16
+ * Request external ID (specified by "requestId" or random uuid)
16
17
  */
17
- deprecations: Deprecation[] | undefined;
18
+ id: string;
19
+ constructor(data: any, options: any);
18
20
  /**
19
- * Request timestamp (in Epoch-Micro)
20
- */
21
- timestamp: number;
21
+ * Request internal ID
22
+ */
23
+ get internalId(): string;
22
24
  /**
23
- * Request HTTP status
24
- */
25
- status: any;
25
+ * Deprecation warnings for the API action
26
+ */
27
+ get deprecations(): Deprecation[] | void;
26
28
  /**
27
- * Request input
28
- */
29
- input: RequestInput;
29
+ * Request timestamp (in Epoch-micro)
30
+ */
31
+ get timestamp(): number;
30
32
  /**
31
- * Request context
32
- */
33
- context: RequestContext;
33
+ * Request HTTP status
34
+ */
35
+ get status(): number;
36
+ set status(i: number);
34
37
  /**
35
- * Request error
36
- */
37
- error: KuzzleError;
38
+ * Request input
39
+ */
40
+ get input(): RequestInput;
38
41
  /**
39
- * Request result
40
- */
41
- result: any;
42
+ * Request context
43
+ */
44
+ get context(): RequestContext;
42
45
  /**
43
- * Request response
44
- */
45
- response: any;
46
+ * Request error
47
+ */
48
+ get error(): KuzzleError | null;
46
49
  /**
47
- * Request internal ID
48
- */
49
- internalId: any;
50
+ * Request result
51
+ */
52
+ get result(): any | null;
50
53
  /**
51
- * Request external ID (specified by "requestId" or random uuid)
52
- */
53
- id: string;
54
- constructor(data: any, options: any);
54
+ * Request response
55
+ */
56
+ get response(): RequestResponse;
55
57
  /**
56
58
  * Adds an error to the request, and sets the request's status to the error one.
57
59
  */
@@ -101,6 +103,38 @@ export declare class KuzzleRequest {
101
103
  data: JSONObject;
102
104
  options: JSONObject;
103
105
  };
106
+ /**
107
+ * Return a POJO representing the request.
108
+ *
109
+ * This can be used to match Koncorde filter rather than the Request object
110
+ * because it has properties defined with invisible unicode characters.
111
+ */
112
+ pojo(): {
113
+ context: {
114
+ connection: import("./requestContext").Connection;
115
+ token: import("../../types").Token;
116
+ user: User;
117
+ };
118
+ deprecations: void | Deprecation[];
119
+ error: KuzzleError;
120
+ id: string;
121
+ input: {
122
+ action: string;
123
+ args: JSONObject;
124
+ body: JSONObject;
125
+ controller: string;
126
+ jwt: string;
127
+ volatile: JSONObject;
128
+ };
129
+ internalId: string;
130
+ response: {
131
+ headers: JSONObject;
132
+ raw: boolean;
133
+ };
134
+ result: any;
135
+ status: number;
136
+ timestamp: number;
137
+ };
104
138
  /**
105
139
  * Returns the `lang` param of the request.
106
140
  *
@@ -53,6 +53,17 @@ const kerror_1 = __importDefault(require("../../kerror"));
53
53
  const assert = __importStar(require("../../util/assertType"));
54
54
  const safeObject_1 = require("../../util/safeObject");
55
55
  const assertionError = kerror_1.default.wrap('api', 'assert');
56
+ // private properties
57
+ // \u200b is a zero width space, used to masquerade console.log output
58
+ const _internalId = 'internalId\u200b';
59
+ const _status = 'status\u200b';
60
+ const _input = 'input\u200b';
61
+ const _error = 'error\u200b';
62
+ const _result = 'result\u200b';
63
+ const _context = 'context\u200b';
64
+ const _timestamp = 'timestamp\u200b';
65
+ const _response = 'response\u200b';
66
+ const _deprecations = 'deprecations\u200b';
56
67
  /**
57
68
  * The `KuzzleRequest` class represents a request being processed by Kuzzle.
58
69
  *
@@ -62,21 +73,21 @@ const assertionError = kerror_1.default.wrap('api', 'assert');
62
73
  */
63
74
  class KuzzleRequest {
64
75
  constructor(data, options) {
65
- this.internalId = (0, nanoid_1.nanoid)();
66
- this.status = 102;
67
- this.input = new requestInput_1.RequestInput(data);
68
- this.context = new requestContext_1.RequestContext(options);
69
- this.error = null;
70
- this.result = null;
71
- this.response = new requestResponse_1.RequestResponse(this);
72
- this.deprecations = undefined;
76
+ this[_internalId] = (0, nanoid_1.nanoid)();
77
+ this[_status] = 102;
78
+ this[_input] = new requestInput_1.RequestInput(data);
79
+ this[_context] = new requestContext_1.RequestContext(options);
80
+ this[_error] = null;
81
+ this[_result] = null;
82
+ this[_response] = null;
83
+ this[_deprecations] = undefined;
73
84
  // @deprecated - Backward compatibility with the RequestInput.headers
74
85
  // property
75
- this.input.headers = this.context.connection.misc.headers;
86
+ this[_input].headers = this[_context].connection.misc.headers;
76
87
  this.id = data.requestId
77
88
  ? assert.assertString('requestId', data.requestId)
78
89
  : (0, nanoid_1.nanoid)();
79
- this.timestamp = data.timestamp || Date.now();
90
+ this[_timestamp] = data.timestamp || Date.now();
80
91
  // handling provided options
81
92
  if (options !== undefined && options !== null) {
82
93
  if (typeof options !== 'object' || Array.isArray(options)) {
@@ -111,6 +122,67 @@ class KuzzleRequest {
111
122
  this.status = options.status;
112
123
  }
113
124
  }
125
+ Object.seal(this);
126
+ }
127
+ /**
128
+ * Request internal ID
129
+ */
130
+ get internalId() {
131
+ return this[_internalId];
132
+ }
133
+ /**
134
+ * Deprecation warnings for the API action
135
+ */
136
+ get deprecations() {
137
+ return this[_deprecations];
138
+ }
139
+ /**
140
+ * Request timestamp (in Epoch-micro)
141
+ */
142
+ get timestamp() {
143
+ return this[_timestamp];
144
+ }
145
+ /**
146
+ * Request HTTP status
147
+ */
148
+ get status() {
149
+ return this[_status];
150
+ }
151
+ set status(i) {
152
+ this[_status] = assert.assertInteger('status', i);
153
+ }
154
+ /**
155
+ * Request input
156
+ */
157
+ get input() {
158
+ return this[_input];
159
+ }
160
+ /**
161
+ * Request context
162
+ */
163
+ get context() {
164
+ return this[_context];
165
+ }
166
+ /**
167
+ * Request error
168
+ */
169
+ get error() {
170
+ return this[_error];
171
+ }
172
+ /**
173
+ * Request result
174
+ */
175
+ get result() {
176
+ return this[_result];
177
+ }
178
+ /**
179
+ * Request response
180
+ */
181
+ get response() {
182
+ if (this[_response] === null) {
183
+ this[_response] = new requestResponse_1.RequestResponse(this);
184
+ }
185
+ return this[_response];
114
186
  }
115
187
  /**
116
188
  * Adds an error to the request, and sets the request's status to the error one.
@@ -119,14 +191,14 @@ class KuzzleRequest {
119
191
  if (!error || !(error instanceof Error)) {
120
192
  throw new errors_1.InternalError('Cannot set non-error object as a request\'s error');
121
193
  }
122
- this.error = error instanceof errors_1.KuzzleError ? error : new errors_1.InternalError(error);
123
- this.status = this.error.status;
194
+ this[_error] = error instanceof errors_1.KuzzleError ? error : new errors_1.InternalError(error);
195
+ this.status = this[_error].status;
124
196
  }
125
197
  /**
126
198
  * Sets the request error to null and status to 200
127
199
  */
128
200
  clearError() {
129
- this.error = null;
201
+ this[_error] = null;
130
202
  this.status = 200;
131
203
  }
132
204
  /**
@@ -151,7 +223,7 @@ class KuzzleRequest {
151
223
  if (options.raw !== undefined) {
152
224
  this.response.raw = options.raw;
153
225
  }
154
- this.result = result;
226
+ this[_result] = result;
155
227
  }
156
228
  /**
157
229
  * Add a deprecation for a used component, this can be action/controller/parameters...
@@ -168,7 +240,7 @@ class KuzzleRequest {
168
240
  version,
169
241
  };
170
242
  if (!this.deprecations) {
171
- this.deprecations = [deprecation];
243
+ this[_deprecations] = [deprecation];
172
244
  }
173
245
  else {
174
246
  this.deprecations.push(deprecation);
@@ -182,28 +254,62 @@ class KuzzleRequest {
182
254
  serialize() {
183
255
  const serialized = {
184
256
  data: {
185
- _id: this.input.args._id,
257
+ _id: this[_input].args._id,
258
+ action: this[_input].action,
259
+ body: this[_input].body,
260
+ collection: this[_input].args.collection,
261
+ controller: this[_input].controller,
262
+ index: this[_input].args.index,
263
+ jwt: this[_input].jwt,
264
+ requestId: this.id,
265
+ timestamp: this[_timestamp],
266
+ volatile: this[_input].volatile,
267
+ },
268
+ // @deprecated - duplicate of options.connection.misc.headers
269
+ headers: this[_input].headers,
270
+ options: {
271
+ error: this[_error],
272
+ result: this[_result],
273
+ status: this[_status],
274
+ },
275
+ };
276
+ Object.assign(serialized.data, this[_input].args);
277
+ Object.assign(serialized.options, this[_context].toJSON());
278
+ return serialized;
279
+ }
280
+ /**
281
+ * Return a POJO representing the request.
282
+ *
283
+ * This can be used to match Koncorde filter rather than the Request object
284
+ * because it has properties defined with invisible unicode characters.
285
+ */
286
+ pojo() {
287
+ return {
288
+ context: {
289
+ connection: this.context.connection,
290
+ token: this.context.token,
291
+ user: this.context.user,
292
+ },
293
+ deprecations: this.deprecations,
294
+ error: this.error,
295
+ id: this.id,
296
+ input: {
186
297
  action: this.input.action,
298
+ args: this.input.args,
187
299
  body: this.input.body,
188
- collection: this.input.args.collection,
189
300
  controller: this.input.controller,
190
- index: this.input.args.index,
191
301
  jwt: this.input.jwt,
192
- requestId: this.id,
193
- timestamp: this.timestamp,
194
302
  volatile: this.input.volatile,
195
303
  },
196
- // @deprecated - duplicate of options.connection.misc.headers
197
- headers: this.input.headers,
198
- options: {
199
- error: this.error,
200
- result: this.result,
201
- status: this.status,
304
+ internalId: this.internalId,
305
+ response: {
306
+ headers: this.response.headers,
307
+ raw: this.response.raw,
202
308
  },
309
+ result: this.result,
310
+ status: this.status,
311
+ timestamp: this.timestamp,
203
312
  };
204
- Object.assign(serialized.data, this.input.args);
205
- Object.assign(serialized.options, this.context.toJSON());
206
- return serialized;
207
313
  }
208
314
  /**
209
315
  * Returns the `lang` param of the request.