@tsed/common 6.119.0 → 6.119.1

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 (31) hide show
  1. package/jest.config.js +3 -3
  2. package/lib/cjs/domain/PlatformContext.js +41 -29
  3. package/lib/cjs/domain/PlatformContext.js.map +1 -1
  4. package/lib/cjs/domain/PlatformRouteDetails.js +2 -0
  5. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
  6. package/lib/cjs/services/PlatformRequest.js +11 -19
  7. package/lib/cjs/services/PlatformRequest.js.map +1 -1
  8. package/lib/cjs/services/PlatformResponse.js +10 -13
  9. package/lib/cjs/services/PlatformResponse.js.map +1 -1
  10. package/lib/cjs/services/PlatformTest.js +16 -3
  11. package/lib/cjs/services/PlatformTest.js.map +1 -1
  12. package/lib/cjs/utils/createContext.js +25 -9
  13. package/lib/cjs/utils/createContext.js.map +1 -1
  14. package/lib/esm/domain/PlatformContext.js +41 -29
  15. package/lib/esm/domain/PlatformContext.js.map +1 -1
  16. package/lib/esm/domain/PlatformRouteDetails.js +2 -0
  17. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
  18. package/lib/esm/services/PlatformRequest.js +11 -19
  19. package/lib/esm/services/PlatformRequest.js.map +1 -1
  20. package/lib/esm/services/PlatformResponse.js +10 -13
  21. package/lib/esm/services/PlatformResponse.js.map +1 -1
  22. package/lib/esm/services/PlatformTest.js +16 -3
  23. package/lib/esm/services/PlatformTest.js.map +1 -1
  24. package/lib/esm/utils/createContext.js +23 -8
  25. package/lib/esm/utils/createContext.js.map +1 -1
  26. package/lib/types/domain/PlatformContext.d.ts +19 -13
  27. package/lib/types/services/PlatformRequest.d.ts +10 -8
  28. package/lib/types/services/PlatformResponse.d.ts +8 -9
  29. package/lib/types/services/PlatformTest.d.ts +2 -2
  30. package/lib/types/utils/createContext.d.ts +4 -1
  31. package/package.json +15 -15
@@ -2,6 +2,7 @@
2
2
  import { ContextMethods, DIContext, DIContextOptions } from "@tsed/di";
3
3
  import { EndpointMetadata } from "@tsed/schema";
4
4
  import { IncomingMessage, ServerResponse } from "http";
5
+ import { IncomingEvent } from "../interfaces/IncomingEvent";
5
6
  import { PlatformApplication } from "../services/PlatformApplication";
6
7
  import { PlatformRequest } from "../services/PlatformRequest";
7
8
  import { PlatformResponse } from "../services/PlatformResponse";
@@ -12,36 +13,40 @@ declare global {
12
13
  }
13
14
  }
14
15
  export interface PlatformContextOptions extends DIContextOptions {
15
- event: {
16
- response?: ServerResponse;
17
- request?: IncomingMessage;
18
- };
16
+ event: IncomingEvent;
19
17
  ignoreUrlPatterns?: any[];
20
18
  endpoint?: EndpointMetadata;
21
19
  }
22
- export declare class PlatformContext extends DIContext implements ContextMethods {
23
- /**
24
- * The current @@EndpointMetadata@@ resolved by Ts.ED during the request.
25
- */
26
- endpoint: EndpointMetadata;
20
+ export declare class PlatformContext<PReq extends PlatformRequest = PlatformRequest, PRes extends PlatformResponse = PlatformResponse> extends DIContext implements ContextMethods {
21
+ #private;
22
+ event: IncomingEvent;
27
23
  /**
28
24
  * The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty.
29
25
  */
30
26
  data: any;
27
+ /**
28
+ * The error caught by the current handler
29
+ */
30
+ error?: unknown;
31
31
  /**
32
32
  * The current @@PlatformResponse@@.
33
33
  */
34
- readonly response: PlatformResponse;
34
+ readonly response: PRes;
35
35
  /**
36
36
  * The current @@PlatformRequest@@.
37
37
  */
38
- readonly request: PlatformRequest;
38
+ readonly request: PReq;
39
39
  private ignoreUrlPatterns;
40
- constructor({ event, endpoint, ignoreUrlPatterns, ResponseKlass, RequestKlass, ...options }: PlatformContextOptions);
40
+ constructor(options: PlatformContextOptions);
41
+ /**
42
+ * The current @@EndpointMetadata@@ resolved by Ts.ED during the request.
43
+ */
44
+ get endpoint(): EndpointMetadata;
45
+ set endpoint(endpoint: EndpointMetadata);
41
46
  get url(): string;
42
47
  get app(): PlatformApplication<TsED.Application, TsED.Router>;
43
48
  destroy(): Promise<void>;
44
- isDone(): boolean;
49
+ isDone(): any;
45
50
  /**
46
51
  * Return the framework request instance (Express, Koa, etc...)
47
52
  */
@@ -62,4 +67,5 @@ export declare class PlatformContext extends DIContext implements ContextMethods
62
67
  * Return the original application instance.
63
68
  */
64
69
  getApp<T = any>(): T;
70
+ upgrade(event: IncomingEvent): void;
65
71
  }
@@ -1,12 +1,14 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingHttpHeaders, IncomingMessage } from "http";
3
3
  import type { PlatformContext } from "../domain/PlatformContext";
4
- import { IncomingEvent } from "../interfaces/IncomingEvent";
5
4
  import type { PlatformResponse } from "./PlatformResponse";
6
5
  declare global {
7
6
  namespace TsED {
8
7
  interface Request {
9
8
  id: string;
9
+ /**
10
+ * @deprecated
11
+ */
10
12
  $ctx: PlatformContext;
11
13
  }
12
14
  }
@@ -15,16 +17,16 @@ declare global {
15
17
  * Platform Request abstraction layer.
16
18
  * @platform
17
19
  */
18
- export declare class PlatformRequest<T extends {
20
+ export declare class PlatformRequest<Req extends {
19
21
  [key: string]: any;
20
22
  } = any> {
21
- protected $ctx: PlatformContext;
22
- raw: T;
23
+ readonly $ctx: PlatformContext;
24
+ constructor($ctx: PlatformContext);
23
25
  /**
24
26
  * The current @@PlatformResponse@@.
25
27
  */
26
- response: PlatformResponse;
27
- constructor({ request }: IncomingEvent, $ctx: PlatformContext);
28
+ get response(): PlatformResponse;
29
+ get raw(): Req;
28
30
  get secure(): boolean;
29
31
  get host(): string;
30
32
  get protocol(): string;
@@ -76,7 +78,7 @@ export declare class PlatformRequest<T extends {
76
78
  /**
77
79
  * Return the original request framework instance
78
80
  */
79
- get request(): T;
81
+ get request(): Req;
80
82
  /**
81
83
  * Return the original request node.js instance
82
84
  */
@@ -105,7 +107,7 @@ export declare class PlatformRequest<T extends {
105
107
  /**
106
108
  * Return the Framework response object (express, koa, etc...)
107
109
  */
108
- getRequest<Req = T>(): Req;
110
+ getRequest<R = Req>(): R;
109
111
  /**
110
112
  * Return the Node.js response object
111
113
  */
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import { OutgoingHttpHeaders, ServerResponse } from "http";
3
- import { IncomingEvent } from "../interfaces/IncomingEvent";
4
3
  import type { PlatformRequest } from "./PlatformRequest";
5
4
  import type { PlatformContext } from "../domain/PlatformContext";
6
5
  declare global {
@@ -14,15 +13,15 @@ export declare type HeaderValue = Array<boolean | number | string> | boolean | n
14
13
  * Platform Response abstraction layer.
15
14
  * @platform
16
15
  */
17
- export declare class PlatformResponse<T extends Record<string, any> = any> {
18
- protected $ctx: PlatformContext;
16
+ export declare class PlatformResponse<Res extends Record<string, any> = any> {
17
+ readonly $ctx: PlatformContext;
18
+ data: any;
19
+ constructor($ctx: PlatformContext);
19
20
  /**
20
21
  * The current @@PlatformRequest@@.
21
22
  */
22
- request: PlatformRequest;
23
- data: any;
24
- raw: T;
25
- constructor({ response }: IncomingEvent, $ctx: PlatformContext);
23
+ get request(): PlatformRequest;
24
+ get raw(): Res;
26
25
  /**
27
26
  * Get the current statusCode
28
27
  */
@@ -36,7 +35,7 @@ export declare class PlatformResponse<T extends Record<string, any> = any> {
36
35
  /**
37
36
  * Return the original response framework instance
38
37
  */
39
- get response(): T;
38
+ get response(): Res;
40
39
  /**
41
40
  * Return the original response node.js instance
42
41
  */
@@ -56,7 +55,7 @@ export declare class PlatformResponse<T extends Record<string, any> = any> {
56
55
  /**
57
56
  * Return the Framework response object (express, koa, etc...)
58
57
  */
59
- getResponse<Res = T>(): Res;
58
+ getResponse<R = Res>(): R;
60
59
  /**
61
60
  * Return the Node.js response object
62
61
  */
@@ -1,5 +1,5 @@
1
- import { DITest, DITestOptions, InjectorService } from "@tsed/di";
2
1
  import { Type } from "@tsed/core";
2
+ import { DITest, DITestOptions, InjectorService } from "@tsed/di";
3
3
  import { PlatformContext, PlatformContextOptions } from "../domain/PlatformContext";
4
4
  import { PlatformAdapter, PlatformBuilderSettings } from "./PlatformAdapter";
5
5
  /**
@@ -54,5 +54,5 @@ export declare class PlatformTest extends DITest {
54
54
  static callback(): any;
55
55
  static createRequest(options?: any): any;
56
56
  static createResponse(options?: any): any;
57
- static createRequestContext(options?: Partial<PlatformContextOptions & any>): PlatformContext;
57
+ static createRequestContext(options?: Partial<PlatformContextOptions & any>): PlatformContext<import("./PlatformRequest").PlatformRequest<any>, import("./PlatformResponse").PlatformResponse<any>>;
58
58
  }
@@ -1,9 +1,12 @@
1
1
  import { InjectorService } from "@tsed/di";
2
2
  import { PlatformContext } from "../domain/PlatformContext";
3
+ import { PlatformRequest } from "../services/PlatformRequest";
4
+ import { PlatformResponse } from "../services/PlatformResponse";
3
5
  import { IncomingEvent } from "../interfaces/IncomingEvent";
6
+ export declare function ignoreLog(ignoreUrlPatterns: any[] | undefined): ((ignore: boolean, data: any, url: string) => any) | undefined;
4
7
  /**
5
8
  * Create the TsED context to wrap request, response, injector, etc...
6
9
  * @param injector
7
10
  * @ignore
8
11
  */
9
- export declare function createContext(injector: InjectorService): (event: IncomingEvent) => Promise<PlatformContext>;
12
+ export declare function createContext(injector: InjectorService): (event: IncomingEvent) => Promise<PlatformContext<PlatformRequest<any>, PlatformResponse<any>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/common",
3
- "version": "6.119.0",
3
+ "version": "6.119.1",
4
4
  "description": "A TypeScript Framework on top of Express",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -62,22 +62,22 @@
62
62
  }
63
63
  ],
64
64
  "dependencies": {
65
- "@tsed/components-scan": "6.119.0",
66
- "@tsed/core": "6.119.0",
67
- "@tsed/di": "6.119.0",
68
- "@tsed/exceptions": "6.119.0",
69
- "@tsed/json-mapper": "6.119.0",
65
+ "@tsed/components-scan": "6.119.1",
66
+ "@tsed/core": "6.119.1",
67
+ "@tsed/di": "6.119.1",
68
+ "@tsed/exceptions": "6.119.1",
69
+ "@tsed/json-mapper": "6.119.1",
70
70
  "@tsed/logger": ">=6.2.0",
71
71
  "@tsed/logger-file": ">=6.2.0",
72
- "@tsed/perf": "6.119.0",
73
- "@tsed/platform-cache": "6.119.0",
74
- "@tsed/platform-exceptions": "6.119.0",
75
- "@tsed/platform-log-middleware": "6.119.0",
76
- "@tsed/platform-middlewares": "6.119.0",
77
- "@tsed/platform-params": "6.119.0",
78
- "@tsed/platform-response-filter": "6.119.0",
79
- "@tsed/platform-views": "6.119.0",
80
- "@tsed/schema": "6.119.0",
72
+ "@tsed/perf": "6.119.1",
73
+ "@tsed/platform-cache": "6.119.1",
74
+ "@tsed/platform-exceptions": "6.119.1",
75
+ "@tsed/platform-log-middleware": "6.119.1",
76
+ "@tsed/platform-middlewares": "6.119.1",
77
+ "@tsed/platform-params": "6.119.1",
78
+ "@tsed/platform-response-filter": "6.119.1",
79
+ "@tsed/platform-views": "6.119.1",
80
+ "@tsed/schema": "6.119.1",
81
81
  "@types/json-schema": "7.0.11",
82
82
  "@types/on-finished": "2.3.1",
83
83
  "on-finished": "2.4.1",