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.
@@ -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
- * Unique identifier of the user connection
31
- */
32
- this.id = null;
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.id,
63
- ips: this.ips,
64
- protocol: this.protocol,
65
- ...this.misc
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
- * Authentication token
80
- */
81
- this.token = null;
82
- /**
83
- * Associated user
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.connection.toJSON(),
109
- token: this.token,
110
- user: this.user,
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.connection.id;
159
+ return this[_connection].id;
119
160
  }
120
161
  set connectionId(str) {
121
- this.connection.id = str;
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.connection.protocol;
168
+ return this[_connection].protocol;
128
169
  }
129
170
  set protocol(str) {
130
- this.connection.protocol = str;
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;
@@ -7,19 +7,16 @@ export declare class RequestResource {
7
7
  constructor(args: JSONObject);
8
8
  /**
9
9
  * Document ID
10
- * @deprecated
11
10
  */
12
11
  get _id(): string | null;
13
12
  set _id(str: string);
14
13
  /**
15
14
  * Index name
16
- * @deprecated
17
15
  */
18
16
  get index(): string | null;
19
17
  set index(str: string);
20
18
  /**
21
19
  * Collection name
22
- * @deprecated
23
20
  */
24
21
  get collection(): string | null;
25
22
  set collection(str: string);
@@ -55,7 +52,7 @@ export declare class RequestInput {
55
52
  /**
56
53
  * Common arguments that identify Kuzzle resources.
57
54
  * (e.g: "_id", "index", "collection")
58
- * @deprecated Use`request.getId()|getIndex()|getCollection()>` instead
55
+ * @deprecated Use directly`request.input.args.<_id|index|collection>` instead
59
56
  * @example
60
57
  * // original JSON request sent to Kuzzle
61
58
  * {
@@ -72,6 +69,15 @@ export declare class RequestInput {
72
69
  * }
73
70
  */
74
71
  resource: RequestResource;
72
+ /**
73
+ * Builds a Kuzzle normalized request input object
74
+ *
75
+ * The 'data' object accepts a request content using the same
76
+ * format as the one used, for instance, for the Websocket protocol
77
+ *
78
+ * Any undefined option is set to null
79
+ */
80
+ constructor(data: any);
75
81
  /**
76
82
  * Authentication token.
77
83
  * @example
@@ -89,7 +95,8 @@ export declare class RequestInput {
89
95
  * body
90
96
  * }
91
97
  */
92
- jwt: string | null;
98
+ get jwt(): string | null;
99
+ set jwt(str: string);
93
100
  /**
94
101
  * API controller name.
95
102
  * @example
@@ -107,7 +114,8 @@ export declare class RequestInput {
107
114
  * body
108
115
  * }
109
116
  */
110
- controller: string | null;
117
+ get controller(): string | null;
118
+ set controller(str: string);
111
119
  /**
112
120
  * API action name.
113
121
  * @example
@@ -125,7 +133,8 @@ export declare class RequestInput {
125
133
  * body
126
134
  * }
127
135
  */
128
- action: string | null;
136
+ get action(): string | null;
137
+ set action(str: string);
129
138
  /**
130
139
  * Request body.
131
140
  * In Http it's the request body parsed.
@@ -144,11 +153,15 @@ export declare class RequestInput {
144
153
  * body <== that
145
154
  * }
146
155
  */
147
- body: JSONObject | null;
156
+ get body(): JSONObject | null;
157
+ set body(obj: JSONObject);
148
158
  /**
149
159
  * Request headers (Http only).
160
+ *
161
+ * @deprecated Use RequestContext.connection.misc.headers instead
150
162
  */
151
- headers: JSONObject | null;
163
+ get headers(): JSONObject | null;
164
+ set headers(obj: JSONObject);
152
165
  /**
153
166
  * Volatile object.
154
167
  * @example
@@ -166,14 +179,6 @@ export declare class RequestInput {
166
179
  * body
167
180
  * }
168
181
  */
169
- volatile: JSONObject | null;
170
- /**
171
- * Builds a Kuzzle normalized request input object
172
- *
173
- * The 'data' object accepts a request content using the same
174
- * format as the one used, for instance, for the Websocket protocol
175
- *
176
- * Any undefined option is set to null
177
- */
178
- constructor(data: any);
182
+ get volatile(): JSONObject | null;
183
+ set volatile(obj: JSONObject);
179
184
  }