@webda/core 2.1.1 → 2.1.2

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.
Files changed (65) hide show
  1. package/lib/application.spec.js.map +1 -1
  2. package/lib/core.d.ts +27 -2
  3. package/lib/core.js +21 -0
  4. package/lib/core.js.map +1 -1
  5. package/lib/core.spec.js.map +1 -1
  6. package/lib/models/aclmodel.d.ts +7 -7
  7. package/lib/models/aclmodel.js +1 -1
  8. package/lib/models/aclmodel.js.map +1 -1
  9. package/lib/models/aclmodel.spec.js.map +1 -1
  10. package/lib/models/coremodel.d.ts +2 -2
  11. package/lib/models/coremodel.js +6 -1
  12. package/lib/models/coremodel.js.map +1 -1
  13. package/lib/models/coremodel.spec.js.map +1 -1
  14. package/lib/models/ownermodel.spec.js.map +1 -1
  15. package/lib/models/rolemodel.spec.js.map +1 -1
  16. package/lib/queues/filequeue.spec.js.map +1 -1
  17. package/lib/queues/memoryqueue.spec.js.map +1 -1
  18. package/lib/router.spec.js.map +1 -1
  19. package/lib/services/asyncevents.spec.js.map +1 -1
  20. package/lib/services/authentication.js.map +1 -1
  21. package/lib/services/authentication.spec.js.map +1 -1
  22. package/lib/services/binary.spec.js.map +1 -1
  23. package/lib/services/cloudbinary.spec.js.map +1 -1
  24. package/lib/services/configuration.spec.js.map +1 -1
  25. package/lib/services/cryptoservice.js.map +1 -1
  26. package/lib/services/cryptoservice.spec.js.map +1 -1
  27. package/lib/services/debugmailer.spec.js.map +1 -1
  28. package/lib/services/echo.spec.js.map +1 -1
  29. package/lib/services/filebinary.spec.js.map +1 -1
  30. package/lib/services/fileconfiguration.spec.js.map +1 -1
  31. package/lib/services/invitationservice.spec.js.map +1 -1
  32. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  33. package/lib/services/mailer.spec.js.map +1 -1
  34. package/lib/services/notificationservice.spec.js.map +1 -1
  35. package/lib/services/oauth.spec.js.map +1 -1
  36. package/lib/services/proxy.js.map +1 -1
  37. package/lib/services/proxy.spec.js.map +1 -1
  38. package/lib/services/resource.spec.js.map +1 -1
  39. package/lib/services/service.d.ts +16 -1
  40. package/lib/services/service.js +47 -0
  41. package/lib/services/service.js.map +1 -1
  42. package/lib/services/service.spec.js +28 -1
  43. package/lib/services/service.spec.js.map +1 -1
  44. package/lib/services/version.spec.js.map +1 -1
  45. package/lib/stores/file.spec.js.map +1 -1
  46. package/lib/stores/mapper.spec.js.map +1 -1
  47. package/lib/stores/memory.js +1 -2
  48. package/lib/stores/memory.js.map +1 -1
  49. package/lib/stores/memory.spec.js.map +1 -1
  50. package/lib/stores/store.d.ts +1 -0
  51. package/lib/stores/store.js +11 -0
  52. package/lib/stores/store.js.map +1 -1
  53. package/lib/stores/store.spec.js +5 -0
  54. package/lib/stores/store.spec.js.map +1 -1
  55. package/lib/test.js.map +1 -1
  56. package/lib/utils/context.d.ts +177 -79
  57. package/lib/utils/context.js +263 -133
  58. package/lib/utils/context.js.map +1 -1
  59. package/lib/utils/context.spec.js +20 -2
  60. package/lib/utils/context.spec.js.map +1 -1
  61. package/lib/utils/cookie.spec.js.map +1 -1
  62. package/lib/utils/httpcontext.spec.js.map +1 -1
  63. package/lib/utils/session.spec.js.map +1 -1
  64. package/lib/utils/waiter.spec.js.map +1 -1
  65. package/package.json +4 -4
@@ -1,10 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ /// <reference types="node" />
4
6
  import { WorkerLogLevel } from "@webda/workout";
5
7
  import { EventEmitter } from "events";
6
8
  import * as http from "http";
7
- import { Writable } from "stream";
9
+ import { Readable, Writable } from "stream";
8
10
  import { Core } from "../core.js";
9
11
  import { User } from "../models/user.js";
10
12
  import { Service } from "../services/service.js";
@@ -19,102 +21,214 @@ declare class Cookie {
19
21
  options: any;
20
22
  }
21
23
  /**
22
- * @category CoreFeatures
23
- * @WebdaModel
24
+ * OperationContext is used when call to an operation
24
25
  */
25
- export declare class Context<T = any, U = any> extends EventEmitter {
26
- protected _body: any;
27
- /**
28
- * Contains the response headers
29
- */
30
- protected _outputHeaders: Map<string, string>;
26
+ export declare class OperationContext<T = any, U = any> extends EventEmitter {
27
+ protected static __globalContext: OperationContext;
28
+ private global;
31
29
  /**
32
30
  * Contain emitting Core
33
31
  */
34
32
  protected _webda: Core;
35
33
  /**
36
- * Current status code
34
+ * Session
37
35
  */
38
- statusCode: number;
39
- _cookie: Map<string, Cookie>;
36
+ protected session: Session;
40
37
  /**
41
- *
38
+ * Allow extensions
42
39
  */
43
- headers: Map<string, string>;
44
- _route: any;
40
+ protected extensions: {
41
+ [key: string]: any;
42
+ };
45
43
  /**
46
- * Session
44
+ * Contain the sanitized request body if computed
47
45
  */
48
- protected session: Session;
49
- _ended: Promise<any>;
50
- _stream: Writable;
46
+ protected _sanitized: any;
47
+ /**
48
+ * Output
49
+ */
50
+ protected _body: string;
51
+ /**
52
+ * Loaded user if exist
53
+ */
54
+ private user;
51
55
  /**
52
56
  * Contain all registered promises to this context
53
57
  */
54
58
  _promises: Promise<any>[];
55
- _executor: Service<any>;
56
59
  /**
57
- * If headers were flushed
60
+ * @ignore
61
+ * Used by Webda framework to set the body, session and output stream if known
58
62
  */
59
- protected headersFlushed: boolean;
63
+ constructor(webda: Core, stream?: Writable);
60
64
  /**
61
- * Contain the sanitized request body if computed
65
+ * Output stream
62
66
  */
63
- protected _sanitized: any;
64
- protected parameters: any;
65
- protected _pathParams: any;
66
- protected _serviceParams: any;
67
- protected static __globalContext: Context;
68
- private global;
67
+ _stream: Writable;
69
68
  /**
70
- * Allow extensions
69
+ * Get an extension of the context
70
+ * @param name of the extension
71
+ * @returns extension object
71
72
  */
72
- protected extensions: {
73
- [key: string]: any;
74
- };
73
+ getExtension<K = any>(name: string): K;
75
74
  /**
76
- * Loaded user if exist
75
+ *
76
+ * @param name to add
77
+ * @param extension object to store
77
78
  */
78
- private user;
79
+ setExtension(name: string, extension: any): void;
80
+ /**
81
+ * Return the webda
82
+ */
83
+ getWebda(): Core<import("../core").CoreEvents>;
84
+ /**
85
+ * Register a promise with the context
86
+ * @param promise
87
+ */
88
+ addAsyncRequest(promise: any): void;
89
+ /**
90
+ * Get output as string, if a OutputStream is provided it will returned null
91
+ * @returns
92
+ */
93
+ getOutput(): string;
94
+ /**
95
+ * Ensure the whole execution is finished
96
+ */
97
+ end(): Promise<void>;
98
+ getInput(sanitizedOptions?: any): Promise<T>;
99
+ /**
100
+ * By default empty
101
+ * @returns
102
+ */
103
+ getRawInputAsString(_limit?: number, _timeout?: number, _encoding?: string): Promise<string>;
104
+ /**
105
+ * @override
106
+ */
107
+ getRawInput(limit?: number, timeout?: number): Promise<Buffer>;
108
+ /**
109
+ * @override
110
+ */
111
+ getRawStream(): Readable;
112
+ /**
113
+ * Get the HTTP stream to output raw data
114
+ * @returns {*}
115
+ */
116
+ getOutputStream(): Writable;
117
+ /**
118
+ * Get linked session
119
+ * @returns
120
+ */
121
+ getSession<K = Session>(): K;
122
+ /**
123
+ * Remove samitized body
124
+ */
125
+ reinit(): void;
126
+ /**
127
+ * Create a buffer stream
128
+ */
129
+ createStream(): void;
130
+ /**
131
+ * Proxy for simplification
132
+ * @param level
133
+ * @param args
134
+ */
135
+ log(level: WorkerLogLevel, ...args: any[]): void;
136
+ /**
137
+ * Create a new session
138
+ * @returns
139
+ */
140
+ newSession(): Session;
141
+ /**
142
+ * Remove everything that was about to be sent
143
+ */
144
+ resetResponse(): void;
145
+ /**
146
+ * Write data to the client
147
+ *
148
+ * @param output If it is an object it will be serializeb with toPublicJSON, if it is a String it will be appended to the result, if it is a buffer it will replace the result
149
+ * @param ...args any arguments to pass to the toPublicJSON method
150
+ */
151
+ write(output: U, _encoding?: string, _cb?: (error: Error) => void): boolean;
79
152
  /**
80
153
  * Get Global Context
81
154
  */
82
- static getGlobalContext(): Context<any, any>;
155
+ static getGlobalContext(): OperationContext<any, any>;
83
156
  /**
84
157
  * Set the Global Context
85
158
  *
86
159
  * @param ctx to set as Global
87
160
  */
88
- static setGlobalContext(ctx: Context): void;
161
+ static setGlobalContext(ctx: OperationContext): void;
89
162
  /**
90
163
  * Return if context is global
91
164
  */
92
165
  isGlobal(): boolean;
166
+ init(): Promise<this>;
167
+ /**
168
+ * Get the current user from session
169
+ */
170
+ getCurrentUser<K extends User>(refresh?: boolean): Promise<K>;
171
+ /**
172
+ * Get the current user id from session
173
+ */
174
+ getCurrentUserId(): any;
175
+ }
176
+ /**
177
+ * This represent in fact a WebContext
178
+ * In 3.0 an abstract version of Context will replace this (closer to OperationContext)
179
+ * @category CoreFeatures
180
+ * @WebdaModel
181
+ *
182
+ * @deprecated use WebContext instead - will be removed in 3.0
183
+ */
184
+ export declare class Context<T = any, U = any> extends OperationContext<T, U> {
185
+ /**
186
+ * Contains the response headers
187
+ */
188
+ protected _outputHeaders: Map<string, string>;
189
+ /**
190
+ * Current status code
191
+ */
192
+ statusCode: number;
193
+ /**
194
+ * Cookies to send back
195
+ */
196
+ _cookie: Map<string, Cookie>;
197
+ /**
198
+ *
199
+ */
200
+ headers: Map<string, string>;
201
+ _route: any;
202
+ _ended: Promise<any>;
203
+ _executor: Service<any>;
204
+ /**
205
+ * If headers were flushed
206
+ */
207
+ protected headersFlushed: boolean;
208
+ protected parameters: any;
209
+ protected _pathParams: any;
210
+ protected _serviceParams: any;
93
211
  /**
94
212
  * Set current http context
95
213
  * @param httpContext current http context
96
214
  */
97
215
  setHttpContext(httpContext: HttpContext): void;
98
- /**
99
- * Remove samitized body
100
- */
101
- reinit(): void;
102
216
  /**
103
217
  * Get current http context
104
218
  */
105
219
  getHttpContext(): HttpContext;
106
220
  /**
107
- * Get an extension of the context
108
- * @param name of the extension
109
- * @returns extension object
221
+ * @override
110
222
  */
111
- getExtension<K = any>(name: string): K;
223
+ getRawInputAsString(limit?: number, timeout?: number, encoding?: string): Promise<string>;
112
224
  /**
113
- *
114
- * @param name to add
115
- * @param extension object to store
225
+ * @override
116
226
  */
117
- setExtension(name: string, extension: any): void;
227
+ getRawInput(limit?: number, timeout?: number): Promise<Buffer>;
228
+ /**
229
+ * @override
230
+ */
231
+ getRawStream(): Readable;
118
232
  /**
119
233
  * Get output headers
120
234
  */
@@ -123,11 +237,6 @@ export declare class Context<T = any, U = any> extends EventEmitter {
123
237
  parameter(name: string): any;
124
238
  getParameters(): any;
125
239
  private processParameters;
126
- /**
127
- * Get linked session
128
- * @returns
129
- */
130
- getSession<K = Session>(): K;
131
240
  getServiceParameters(): any;
132
241
  getPathParameters(): any;
133
242
  setServiceParameters(params: any): void;
@@ -142,7 +251,7 @@ export declare class Context<T = any, U = any> extends EventEmitter {
142
251
  * @param output If it is an object it will be serializeb with toPublicJSON, if it is a String it will be appended to the result, if it is a buffer it will replace the result
143
252
  * @param ...args any arguments to pass to the toPublicJSON method
144
253
  */
145
- write(output: U, _encoding?: string, _cb?: (error: Error) => void): boolean;
254
+ write(output: U, encoding?: string, cb?: (error: Error) => void): boolean;
146
255
  /**
147
256
  * Set a header value
148
257
  *
@@ -168,7 +277,6 @@ export declare class Context<T = any, U = any> extends EventEmitter {
168
277
  */
169
278
  cookie(param: any, value: any, options?: any): void;
170
279
  getResponseCookies(): Map<string, Cookie>;
171
- addAsyncRequest(promise: any): void;
172
280
  isEnded(): Promise<any>;
173
281
  /******************************
174
282
  *
@@ -176,12 +284,12 @@ export declare class Context<T = any, U = any> extends EventEmitter {
176
284
  *
177
285
  ******************************/
178
286
  /**
179
- * Express response allow statusCode to be defined this was
287
+ * Express response allow statusCode to be defined this way
180
288
  * @param code to return
181
289
  */
182
290
  status(code: number): this;
183
291
  /**
184
- * Express response allow answer to be sent this w
292
+ * Express response allow answer to be sent this way
185
293
  * @param code to return
186
294
  */
187
295
  json(obj: any): this;
@@ -192,12 +300,17 @@ export declare class Context<T = any, U = any> extends EventEmitter {
192
300
  * @throws Error if the request was already ended
193
301
  */
194
302
  end(): Promise<any>;
303
+ /**
304
+ * Alias to keep compatibility with WebContext
305
+ * @param sanitizedOptions
306
+ * @returns
307
+ */
195
308
  getRequestBody(sanitizedOptions?: any): Promise<T>;
196
309
  /**
197
310
  * Get request body
198
311
  * @returns
199
312
  */
200
- getResponseBody(): any;
313
+ getResponseBody(): string | false | Buffer;
201
314
  /**
202
315
  * Retrieve a http.IncomingMessage valid from Context
203
316
  *
@@ -217,10 +330,6 @@ export declare class Context<T = any, U = any> extends EventEmitter {
217
330
  * @returns {*}
218
331
  */
219
332
  getStream(): Writable;
220
- /**
221
- * Get the current user from session
222
- */
223
- getCurrentUser<K extends User>(refresh?: boolean): Promise<K>;
224
333
  /**
225
334
  * Get the current user id from session
226
335
  */
@@ -233,10 +342,6 @@ export declare class Context<T = any, U = any> extends EventEmitter {
233
342
  * Execute the target route
234
343
  */
235
344
  execute(): Promise<any>;
236
- /**
237
- * Return the webda
238
- */
239
- getWebda(): Core<import("../core").CoreEvents>;
240
345
  /**
241
346
  * Get the request locale if found
242
347
  */
@@ -256,12 +361,6 @@ export declare class Context<T = any, U = any> extends EventEmitter {
256
361
  * Used for compatibility with express module
257
362
  */
258
363
  logIn(): void;
259
- /**
260
- * Proxy for simplification
261
- * @param level
262
- * @param args
263
- */
264
- log(level: WorkerLogLevel, ...args: any[]): void;
265
364
  /**
266
365
  * Return true if Headers got flushed already
267
366
  * @returns
@@ -277,13 +376,12 @@ export declare class Context<T = any, U = any> extends EventEmitter {
277
376
  * Used by Webda framework to set the body, session and output stream if known
278
377
  */
279
378
  constructor(webda: Core, httpContext: HttpContext, stream?: Writable);
280
- createStream(): void;
281
- /**
282
- * Create a new session
283
- * @returns
284
- */
285
- newSession(): Session;
286
379
  init(): Promise<this>;
287
380
  emitError(err: any): void;
288
381
  }
382
+ /**
383
+ * Replacement for Context
384
+ */
385
+ export declare class WebContext<T = any, U = any> extends Context<T, U> {
386
+ }
289
387
  export {};