kuzzle 2.16.2 → 2.16.3
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.
- package/lib/api/request/kuzzleRequest.d.ts +64 -30
- package/lib/api/request/kuzzleRequest.js +135 -29
- package/lib/api/request/requestContext.d.ts +22 -17
- package/lib/api/request/requestContext.js +109 -44
- package/lib/api/request/requestInput.d.ts +24 -19
- package/lib/api/request/requestInput.js +175 -115
- package/lib/api/request/requestResponse.d.ts +8 -12
- package/lib/api/request/requestResponse.js +29 -35
- package/lib/core/plugin/pluginsManager.js +1 -3
- package/lib/kuzzle/kuzzle.js +5 -9
- package/package-lock.json +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
*
|
|
16
|
+
* Request external ID (specified by "requestId" or random uuid)
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
id: string;
|
|
19
|
+
constructor(data: any, options: any);
|
|
18
20
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
* Request internal ID
|
|
22
|
+
*/
|
|
23
|
+
get internalId(): string;
|
|
22
24
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
* Deprecation warnings for the API action
|
|
26
|
+
*/
|
|
27
|
+
get deprecations(): Deprecation[] | void;
|
|
26
28
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
* Request timestamp (in Epoch-micro)
|
|
30
|
+
*/
|
|
31
|
+
get timestamp(): number;
|
|
30
32
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
* Request HTTP status
|
|
34
|
+
*/
|
|
35
|
+
get status(): number;
|
|
36
|
+
set status(i: number);
|
|
34
37
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
* Request input
|
|
39
|
+
*/
|
|
40
|
+
get input(): RequestInput;
|
|
38
41
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
* Request context
|
|
43
|
+
*/
|
|
44
|
+
get context(): RequestContext;
|
|
42
45
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
* Request error
|
|
47
|
+
*/
|
|
48
|
+
get error(): KuzzleError | null;
|
|
46
49
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
* Request result
|
|
51
|
+
*/
|
|
52
|
+
get result(): any | null;
|
|
50
53
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
|
66
|
-
this
|
|
67
|
-
this
|
|
68
|
-
this
|
|
69
|
-
this
|
|
70
|
-
this
|
|
71
|
-
this
|
|
72
|
-
this
|
|
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.
|
|
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
|
|
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
|
|
123
|
-
this.status = this.
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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.
|
|
@@ -24,23 +24,26 @@ export declare type ContextMisc = {
|
|
|
24
24
|
* Information about the connection at the origin of the request.
|
|
25
25
|
*/
|
|
26
26
|
export declare class Connection {
|
|
27
|
+
constructor(connection: any);
|
|
27
28
|
/**
|
|
28
29
|
* Unique identifier of the user connection
|
|
29
30
|
*/
|
|
30
|
-
id: string;
|
|
31
|
+
set id(str: string);
|
|
32
|
+
get id(): string | null;
|
|
31
33
|
/**
|
|
32
34
|
* Network protocol name
|
|
33
35
|
*/
|
|
34
|
-
protocol: string;
|
|
36
|
+
set protocol(str: string);
|
|
37
|
+
get protocol(): string | null;
|
|
35
38
|
/**
|
|
36
39
|
* Chain of IP addresses, starting from the client
|
|
37
40
|
*/
|
|
38
|
-
ips: string[];
|
|
41
|
+
set ips(arr: string[]);
|
|
42
|
+
get ips(): string[];
|
|
39
43
|
/**
|
|
40
44
|
* Additional informations about the connection
|
|
41
45
|
*/
|
|
42
|
-
misc: ContextMisc;
|
|
43
|
-
constructor(connection: any);
|
|
46
|
+
get misc(): ContextMisc;
|
|
44
47
|
/**
|
|
45
48
|
* Serializes the Connection object
|
|
46
49
|
*/
|
|
@@ -53,18 +56,6 @@ export declare class Connection {
|
|
|
53
56
|
* and origin (connection, protocol).
|
|
54
57
|
*/
|
|
55
58
|
export declare class RequestContext {
|
|
56
|
-
/**
|
|
57
|
-
* Connection that initiated the request
|
|
58
|
-
*/
|
|
59
|
-
connection: Connection;
|
|
60
|
-
/**
|
|
61
|
-
* Authentication token
|
|
62
|
-
*/
|
|
63
|
-
token: Token | null;
|
|
64
|
-
/**
|
|
65
|
-
* Associated user
|
|
66
|
-
*/
|
|
67
|
-
user: User | null;
|
|
68
59
|
constructor(options?: any);
|
|
69
60
|
/**
|
|
70
61
|
* Serializes the RequestContext object
|
|
@@ -81,4 +72,18 @@ export declare class RequestContext {
|
|
|
81
72
|
*/
|
|
82
73
|
get protocol(): string | null;
|
|
83
74
|
set protocol(str: string);
|
|
75
|
+
/**
|
|
76
|
+
* Connection that initiated the request
|
|
77
|
+
*/
|
|
78
|
+
get connection(): Connection;
|
|
79
|
+
/**
|
|
80
|
+
* Authentication token
|
|
81
|
+
*/
|
|
82
|
+
get token(): Token | null;
|
|
83
|
+
set token(obj: Token | null);
|
|
84
|
+
/**
|
|
85
|
+
* Associated user
|
|
86
|
+
*/
|
|
87
|
+
get user(): User | null;
|
|
88
|
+
set user(obj: User | null);
|
|
84
89
|
}
|
|
@@ -19,29 +19,48 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
22
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
42
|
exports.RequestContext = exports.Connection = void 0;
|
|
43
|
+
const assert = __importStar(require("../../util/assertType"));
|
|
44
|
+
// private properties
|
|
45
|
+
// \u200b is a zero width space, used to masquerade console.log output
|
|
46
|
+
const _token = 'token\u200b';
|
|
47
|
+
const _user = 'user\u200b';
|
|
48
|
+
const _connection = 'connection\u200b';
|
|
49
|
+
// Connection class properties
|
|
50
|
+
const _c_id = 'id\u200b';
|
|
51
|
+
const _c_protocol = 'protocol\u200b';
|
|
52
|
+
const _c_ips = 'ips\u200b';
|
|
53
|
+
const _c_misc = 'misc\u200b';
|
|
24
54
|
/**
|
|
25
55
|
* Information about the connection at the origin of the request.
|
|
26
56
|
*/
|
|
27
57
|
class Connection {
|
|
28
58
|
constructor(connection) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this
|
|
33
|
-
|
|
34
|
-
* Network protocol name
|
|
35
|
-
*/
|
|
36
|
-
this.protocol = null;
|
|
37
|
-
/**
|
|
38
|
-
* Chain of IP addresses, starting from the client
|
|
39
|
-
*/
|
|
40
|
-
this.ips = [];
|
|
41
|
-
/**
|
|
42
|
-
* Additional informations about the connection
|
|
43
|
-
*/
|
|
44
|
-
this.misc = {};
|
|
59
|
+
this[_c_id] = null;
|
|
60
|
+
this[_c_protocol] = null;
|
|
61
|
+
this[_c_ips] = [];
|
|
62
|
+
this[_c_misc] = {};
|
|
63
|
+
Object.seal(this);
|
|
45
64
|
if (typeof connection !== 'object' || connection === null) {
|
|
46
65
|
return;
|
|
47
66
|
}
|
|
@@ -54,15 +73,48 @@ class Connection {
|
|
|
54
73
|
}
|
|
55
74
|
}
|
|
56
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Unique identifier of the user connection
|
|
78
|
+
*/
|
|
79
|
+
set id(str) {
|
|
80
|
+
this[_c_id] = assert.assertString('connection.id', str);
|
|
81
|
+
}
|
|
82
|
+
get id() {
|
|
83
|
+
return this[_c_id];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Network protocol name
|
|
87
|
+
*/
|
|
88
|
+
set protocol(str) {
|
|
89
|
+
this[_c_protocol] = assert.assertString('connection.protocol', str);
|
|
90
|
+
}
|
|
91
|
+
get protocol() {
|
|
92
|
+
return this[_c_protocol];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Chain of IP addresses, starting from the client
|
|
96
|
+
*/
|
|
97
|
+
set ips(arr) {
|
|
98
|
+
this[_c_ips] = assert.assertArray('connection.ips', arr, 'string');
|
|
99
|
+
}
|
|
100
|
+
get ips() {
|
|
101
|
+
return this[_c_ips];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Additional informations about the connection
|
|
105
|
+
*/
|
|
106
|
+
get misc() {
|
|
107
|
+
return this[_c_misc];
|
|
108
|
+
}
|
|
57
109
|
/**
|
|
58
110
|
* Serializes the Connection object
|
|
59
111
|
*/
|
|
60
112
|
toJSON() {
|
|
61
113
|
return {
|
|
62
|
-
id: this
|
|
63
|
-
ips: this
|
|
64
|
-
protocol: this
|
|
65
|
-
...this
|
|
114
|
+
id: this[_c_id],
|
|
115
|
+
ips: this[_c_ips],
|
|
116
|
+
protocol: this[_c_protocol],
|
|
117
|
+
...this[_c_misc]
|
|
66
118
|
};
|
|
67
119
|
}
|
|
68
120
|
}
|
|
@@ -75,23 +127,12 @@ exports.Connection = Connection;
|
|
|
75
127
|
*/
|
|
76
128
|
class RequestContext {
|
|
77
129
|
constructor(options = {}) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*/
|
|
85
|
-
this.user = null;
|
|
86
|
-
this.token = null;
|
|
87
|
-
this.user = null;
|
|
88
|
-
this.connection = new Connection(options.connection);
|
|
89
|
-
if (options.token) {
|
|
90
|
-
this.token = options.token;
|
|
91
|
-
}
|
|
92
|
-
if (options.user) {
|
|
93
|
-
this.user = options.user;
|
|
94
|
-
}
|
|
130
|
+
this[_token] = null;
|
|
131
|
+
this[_user] = null;
|
|
132
|
+
this[_connection] = new Connection(options.connection);
|
|
133
|
+
Object.seal(this);
|
|
134
|
+
this.token = options.token;
|
|
135
|
+
this.user = options.user;
|
|
95
136
|
// @deprecated - backward compatibility only
|
|
96
137
|
if (options.connectionId) {
|
|
97
138
|
this.connectionId = options.connectionId;
|
|
@@ -105,9 +146,9 @@ class RequestContext {
|
|
|
105
146
|
*/
|
|
106
147
|
toJSON() {
|
|
107
148
|
return {
|
|
108
|
-
connection: this.
|
|
109
|
-
token: this
|
|
110
|
-
user: this
|
|
149
|
+
connection: this[_connection].toJSON(),
|
|
150
|
+
token: this[_token],
|
|
151
|
+
user: this[_user],
|
|
111
152
|
};
|
|
112
153
|
}
|
|
113
154
|
/**
|
|
@@ -115,19 +156,43 @@ class RequestContext {
|
|
|
115
156
|
* Internal connection ID
|
|
116
157
|
*/
|
|
117
158
|
get connectionId() {
|
|
118
|
-
return this.
|
|
159
|
+
return this[_connection].id;
|
|
119
160
|
}
|
|
120
161
|
set connectionId(str) {
|
|
121
|
-
this.
|
|
162
|
+
this[_connection].id = assert.assertString('connectionId', str);
|
|
122
163
|
}
|
|
123
164
|
/**
|
|
124
165
|
* @deprecated use connection.protocol instead
|
|
125
166
|
*/
|
|
126
167
|
get protocol() {
|
|
127
|
-
return this.
|
|
168
|
+
return this[_connection].protocol;
|
|
128
169
|
}
|
|
129
170
|
set protocol(str) {
|
|
130
|
-
this.
|
|
171
|
+
this[_connection].protocol = assert.assertString('protocol', str);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Connection that initiated the request
|
|
175
|
+
*/
|
|
176
|
+
get connection() {
|
|
177
|
+
return this[_connection];
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Authentication token
|
|
181
|
+
*/
|
|
182
|
+
get token() {
|
|
183
|
+
return this[_token];
|
|
184
|
+
}
|
|
185
|
+
set token(obj) {
|
|
186
|
+
this[_token] = assert.assertObject('token', obj);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Associated user
|
|
190
|
+
*/
|
|
191
|
+
get user() {
|
|
192
|
+
return this[_user];
|
|
193
|
+
}
|
|
194
|
+
set user(obj) {
|
|
195
|
+
this[_user] = assert.assertObject('user', obj);
|
|
131
196
|
}
|
|
132
197
|
}
|
|
133
198
|
exports.RequestContext = RequestContext;
|