@tsed/common 6.126.1 → 6.128.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.
- package/coverage.json +6 -0
- package/jest.config.js +1 -6
- package/lib/cjs/builder/PlatformBuilder.js +5 -2
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/domain/PlatformContext.js +11 -21
- package/lib/cjs/domain/PlatformContext.js.map +1 -1
- package/lib/cjs/services/PlatformHandler.js +20 -22
- package/lib/cjs/services/PlatformHandler.js.map +1 -1
- package/lib/cjs/services/PlatformRequest.js +0 -1
- package/lib/cjs/services/PlatformRequest.js.map +1 -1
- package/lib/cjs/services/PlatformResponse.js +5 -12
- package/lib/cjs/services/PlatformResponse.js.map +1 -1
- package/lib/cjs/services/PlatformRouter.js +1 -1
- package/lib/cjs/services/PlatformRouter.js.map +1 -1
- package/lib/cjs/utils/createContext.js +5 -8
- package/lib/cjs/utils/createContext.js.map +1 -1
- package/lib/cjs/utils/setResponseHeaders.js +1 -1
- package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +6 -3
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/domain/PlatformContext.js +11 -21
- package/lib/esm/domain/PlatformContext.js.map +1 -1
- package/lib/esm/services/PlatformHandler.js +20 -22
- package/lib/esm/services/PlatformHandler.js.map +1 -1
- package/lib/esm/services/PlatformRequest.js +0 -1
- package/lib/esm/services/PlatformRequest.js.map +1 -1
- package/lib/esm/services/PlatformResponse.js +5 -12
- package/lib/esm/services/PlatformResponse.js.map +1 -1
- package/lib/esm/services/PlatformRouter.js +2 -2
- package/lib/esm/services/PlatformRouter.js.map +1 -1
- package/lib/esm/utils/createContext.js +5 -8
- package/lib/esm/utils/createContext.js.map +1 -1
- package/lib/esm/utils/setResponseHeaders.js +1 -1
- package/lib/esm/utils/setResponseHeaders.js.map +1 -1
- package/lib/types/domain/PlatformContext.d.ts +5 -3
- package/lib/types/services/PlatformRequest.d.ts +0 -1
- package/lib/types/services/PlatformResponse.d.ts +2 -4
- package/package.json +15 -15
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setContext } from "@tsed/di";
|
|
1
2
|
import { v4 } from "uuid";
|
|
2
3
|
import { PlatformContext } from "../domain/PlatformContext.js";
|
|
3
4
|
import { PlatformRequest } from "../services/PlatformRequest.js";
|
|
@@ -32,18 +33,14 @@ export function createContext(injector) {
|
|
|
32
33
|
};
|
|
33
34
|
const ignoreLog = buildIgnoreLog(loggerOptions.ignoreUrlPatterns);
|
|
34
35
|
return async function invokeContext(event) {
|
|
35
|
-
const ctx = new PlatformContext({
|
|
36
|
+
const $ctx = new PlatformContext({
|
|
36
37
|
...opts,
|
|
37
38
|
event,
|
|
38
39
|
id: reqIdBuilder(event.request)
|
|
39
40
|
});
|
|
40
|
-
|
|
41
|
-
ctx.
|
|
42
|
-
|
|
43
|
-
await ctx.destroy();
|
|
44
|
-
});
|
|
45
|
-
await ctx.emit("$onRequest", ctx);
|
|
46
|
-
return ctx;
|
|
41
|
+
setContext($ctx);
|
|
42
|
+
ignoreLog && $ctx.logger.alterIgnoreLog((ignore, data) => ignoreLog(ignore, data, $ctx.url));
|
|
43
|
+
return $ctx;
|
|
47
44
|
};
|
|
48
45
|
}
|
|
49
46
|
//# sourceMappingURL=createContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../../src/utils/createContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../../src/utils/createContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,UAAU,EAAC,MAAM,UAAU,CAAC;AACrD,OAAO,EAAC,EAAE,EAAC,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CA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ACb,YAAY;KACb,CAAC;IAEF,MAAM,SAAS,GAAG,cAAc,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAElE,OAAO,KAAK,UAAU,aAAa,CAAC,KAAoB;QACtD,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC;YAC/B,GAAG,IAAI;YACP,KAAK;YACL,EAAE,EAAE,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC;SAChC,CAAC,CAAC;QAEH,UAAU,CAAC,IAAI,CAAC,CAAC;QAEjB,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAE7F,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {InjectorService, setContext} from \"@tsed/di\";\nimport {v4} from \"uuid\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\n\nfunction defaultReqIdBuilder(req: any) {\n return req.get(\"x-request-id\") || v4().split(\"-\").join(\"\");\n}\n\nfunction mapIgnoreUrlPatterns(ignoreUrlPatterns: any[]) {\n return ignoreUrlPatterns.map((pattern: string | RegExp) => (typeof pattern === \"string\" ? new RegExp(pattern, \"gi\") : pattern));\n}\n\nexport function buildIgnoreLog(ignoreUrlPatterns: any[] | undefined) {\n if (ignoreUrlPatterns) {\n ignoreUrlPatterns = mapIgnoreUrlPatterns(ignoreUrlPatterns);\n return (ignore: boolean, data: any, url: string) => ignoreUrlPatterns?.find((reg) => !!url.match(reg));\n }\n}\n\n/**\n * Create the TsED context to wrap request, response, injector, etc...\n * @param injector\n * @ignore\n */\nexport function createContext(injector: InjectorService) {\n const ResponseKlass = injector.getProvider(PlatformResponse)?.useClass;\n const RequestKlass = injector.getProvider(PlatformRequest)?.useClass;\n const {reqIdBuilder = defaultReqIdBuilder, ...loggerOptions} = injector.settings.logger;\n\n const opts = {\n ...loggerOptions,\n logger: injector.logger,\n injector,\n ResponseKlass,\n RequestKlass\n };\n\n const ignoreLog = buildIgnoreLog(loggerOptions.ignoreUrlPatterns);\n\n return async function invokeContext(event: IncomingEvent) {\n const $ctx = new PlatformContext({\n ...opts,\n event,\n id: reqIdBuilder(event.request)\n });\n\n setContext($ctx);\n\n ignoreLog && $ctx.logger.alterIgnoreLog((ignore, data) => ignoreLog(ignore, data, $ctx.url));\n\n return $ctx;\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setResponseHeaders.js","sourceRoot":"","sources":["../../../src/utils/setResponseHeaders.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAoB;IACrD,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAC,GAAG,GAAG,CAAC;IACjC,MAAM,EAAC,SAAS,EAAC,GAAG,QAAQ,CAAC;IAE7B,IAAI,
|
|
1
|
+
{"version":3,"file":"setResponseHeaders.js","sourceRoot":"","sources":["../../../src/utils/setResponseHeaders.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAoB;IACrD,MAAM,EAAC,QAAQ,EAAE,QAAQ,EAAC,GAAG,GAAG,CAAC;IACjC,MAAM,EAAC,SAAS,EAAC,GAAG,QAAQ,CAAC;IAE7B,IAAI,GAAG,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO;KACR;IAED,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;QACzB,kDAAkD;QAClD,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;KACxC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACvC,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAEnD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;QAC9C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACtB,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;SAC/C;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE;QACvC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;KACzD;AACH,CAAC","sourcesContent":["import {PlatformContext} from \"../domain/PlatformContext\";\n\n/**\n * @ignore\n */\nexport function setResponseHeaders(ctx: PlatformContext) {\n const {response, endpoint} = ctx;\n const {operation} = endpoint;\n\n if (ctx.isDone()) {\n return;\n }\n\n if (!response.hasStatus()) {\n // apply status only if the isn't already modified\n response.status(operation.getStatus());\n }\n\n const statusCode = response.statusCode;\n const headers = operation.getHeadersOf(statusCode);\n\n Object.entries(headers).forEach(([key, item]) => {\n if (!response.get(key)) {\n response.setHeader(key, String(item.example));\n }\n });\n\n if (operation.isRedirection(statusCode)) {\n response.redirect(statusCode, response.get(\"location\"));\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { DIContext, DIContextOptions } from "@tsed/di";
|
|
3
3
|
import { EndpointMetadata } from "@tsed/schema";
|
|
4
4
|
import { IncomingMessage, ServerResponse } from "http";
|
|
5
5
|
import { IncomingEvent } from "../interfaces/IncomingEvent";
|
|
@@ -17,7 +17,7 @@ export interface PlatformContextOptions extends DIContextOptions {
|
|
|
17
17
|
ignoreUrlPatterns?: any[];
|
|
18
18
|
endpoint?: EndpointMetadata;
|
|
19
19
|
}
|
|
20
|
-
export declare class PlatformContext<PReq extends PlatformRequest = PlatformRequest, PRes extends PlatformResponse = PlatformResponse> extends DIContext
|
|
20
|
+
export declare class PlatformContext<PReq extends PlatformRequest = PlatformRequest, PRes extends PlatformResponse = PlatformResponse> extends DIContext {
|
|
21
21
|
#private;
|
|
22
22
|
event: IncomingEvent;
|
|
23
23
|
/**
|
|
@@ -43,7 +43,9 @@ export declare class PlatformContext<PReq extends PlatformRequest = PlatformRequ
|
|
|
43
43
|
constructor(options: PlatformContextOptions);
|
|
44
44
|
get url(): string;
|
|
45
45
|
get app(): PlatformApplication<TsED.Application, TsED.Router>;
|
|
46
|
-
|
|
46
|
+
start(): Promise<void>;
|
|
47
|
+
finish(): Promise<void>;
|
|
48
|
+
isFinished(): boolean;
|
|
47
49
|
isDone(): any;
|
|
48
50
|
/**
|
|
49
51
|
* Return the framework request instance (Express, Koa, etc...)
|
|
@@ -103,7 +103,6 @@ export declare class PlatformRequest<Req extends {
|
|
|
103
103
|
accepts(mime: string): string | false;
|
|
104
104
|
accepts(mime: string[]): string[] | false;
|
|
105
105
|
isAborted(): any;
|
|
106
|
-
destroy(): void;
|
|
107
106
|
/**
|
|
108
107
|
* Return the Framework response object (express, koa, etc...)
|
|
109
108
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { OutgoingHttpHeaders, ServerResponse } from "http";
|
|
3
|
-
import type { PlatformRequest } from "./PlatformRequest";
|
|
4
3
|
import type { PlatformContext } from "../domain/PlatformContext";
|
|
4
|
+
import type { PlatformRequest } from "./PlatformRequest";
|
|
5
5
|
declare global {
|
|
6
6
|
namespace TsED {
|
|
7
7
|
interface Response {
|
|
@@ -40,7 +40,6 @@ export declare class PlatformResponse<Res extends Record<string, any> = any> {
|
|
|
40
40
|
* Return the original response node.js instance
|
|
41
41
|
*/
|
|
42
42
|
get res(): ServerResponse;
|
|
43
|
-
static onFinished(res: any, cb: (er: Error | null, message: string) => void): void;
|
|
44
43
|
/**
|
|
45
44
|
* Returns the HTTP response header specified by field. The match is case-insensitive.
|
|
46
45
|
*
|
|
@@ -153,8 +152,7 @@ export declare class PlatformResponse<Res extends Record<string, any> = any> {
|
|
|
153
152
|
* Add a listener to handler the end of the request/response.
|
|
154
153
|
* @param cb
|
|
155
154
|
*/
|
|
156
|
-
onEnd(cb: (
|
|
155
|
+
onEnd(cb: () => Promise<void> | void): this;
|
|
157
156
|
isDone(): boolean;
|
|
158
|
-
destroy(): void;
|
|
159
157
|
isHeadersSent(): boolean;
|
|
160
158
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.128.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.
|
|
66
|
-
"@tsed/core": "6.
|
|
67
|
-
"@tsed/di": "6.
|
|
68
|
-
"@tsed/exceptions": "6.
|
|
69
|
-
"@tsed/json-mapper": "6.
|
|
65
|
+
"@tsed/components-scan": "6.128.1",
|
|
66
|
+
"@tsed/core": "6.128.1",
|
|
67
|
+
"@tsed/di": "6.128.1",
|
|
68
|
+
"@tsed/exceptions": "6.128.1",
|
|
69
|
+
"@tsed/json-mapper": "6.128.1",
|
|
70
70
|
"@tsed/logger": ">=6.2.0",
|
|
71
71
|
"@tsed/logger-file": ">=6.2.0",
|
|
72
|
-
"@tsed/perf": "6.
|
|
73
|
-
"@tsed/platform-cache": "6.
|
|
74
|
-
"@tsed/platform-exceptions": "6.
|
|
75
|
-
"@tsed/platform-log-middleware": "6.
|
|
76
|
-
"@tsed/platform-middlewares": "6.
|
|
77
|
-
"@tsed/platform-params": "6.
|
|
78
|
-
"@tsed/platform-response-filter": "6.
|
|
79
|
-
"@tsed/platform-views": "6.
|
|
80
|
-
"@tsed/schema": "6.
|
|
72
|
+
"@tsed/perf": "6.128.1",
|
|
73
|
+
"@tsed/platform-cache": "6.128.1",
|
|
74
|
+
"@tsed/platform-exceptions": "6.128.1",
|
|
75
|
+
"@tsed/platform-log-middleware": "6.128.1",
|
|
76
|
+
"@tsed/platform-middlewares": "6.128.1",
|
|
77
|
+
"@tsed/platform-params": "6.128.1",
|
|
78
|
+
"@tsed/platform-response-filter": "6.128.1",
|
|
79
|
+
"@tsed/platform-views": "6.128.1",
|
|
80
|
+
"@tsed/schema": "6.128.1",
|
|
81
81
|
"@types/json-schema": "7.0.11",
|
|
82
82
|
"@types/on-finished": "2.3.1",
|
|
83
83
|
"on-finished": "2.4.1",
|