@tsed/platform-http 8.46.2 → 8.46.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DIContext, injector } from "@tsed/di";
|
|
2
|
-
import { $asyncEmit } from "@tsed/hooks";
|
|
2
|
+
import { $asyncEmit, hooks } from "@tsed/hooks";
|
|
3
3
|
import { PlatformApplication } from "../services/PlatformApplication.js";
|
|
4
4
|
import { PlatformRequest } from "../services/PlatformRequest.js";
|
|
5
5
|
import { PlatformResponse } from "../services/PlatformResponse.js";
|
|
@@ -27,7 +27,7 @@ export class PlatformContext extends DIContext {
|
|
|
27
27
|
return $asyncEmit("$onRequest", [this]);
|
|
28
28
|
}
|
|
29
29
|
async finish() {
|
|
30
|
-
await Promise.all([$asyncEmit("$onResponse", [this]), this.destroy()]);
|
|
30
|
+
await (hooks.has("$onResponse") ? Promise.all([$asyncEmit("$onResponse", [this]), this.destroy()]) : this.destroy());
|
|
31
31
|
this.#isFinished = true;
|
|
32
32
|
}
|
|
33
33
|
isFinished() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PlatformHandlerMetadata, PlatformHandlerType, PlatformRouters, useResponseHandler } from "@tsed/platform-router";
|
|
2
|
-
import { AnyToPromiseStatus
|
|
2
|
+
import { AnyToPromiseStatus } from "@tsed/core";
|
|
3
3
|
import { PlatformParams } from "@tsed/platform-params";
|
|
4
4
|
import { ProviderScope, inject, injectable } from "@tsed/di";
|
|
5
5
|
import { $alter } from "@tsed/hooks";
|
|
@@ -88,14 +88,14 @@ export class PlatformHandler {
|
|
|
88
88
|
* @param $ctx
|
|
89
89
|
*/
|
|
90
90
|
async flush($ctx) {
|
|
91
|
-
if (!$ctx.error) {
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
91
|
+
if (!$ctx.error && !$ctx.isDone()) {
|
|
92
|
+
try {
|
|
93
|
+
const data = await this.responseFilter.transform($ctx.data, $ctx);
|
|
94
|
+
$ctx.response.body(data);
|
|
95
|
+
}
|
|
96
|
+
catch (er) {
|
|
97
|
+
$ctx.error = er;
|
|
98
|
+
}
|
|
99
99
|
}
|
|
100
100
|
if ($ctx.error) {
|
|
101
101
|
this.platformExceptions.catch($ctx.error, $ctx);
|
|
@@ -2,9 +2,22 @@ import { configuration, injector } from "@tsed/di";
|
|
|
2
2
|
import { PlatformContext } from "../domain/PlatformContext.js";
|
|
3
3
|
import { PlatformRequest } from "../services/PlatformRequest.js";
|
|
4
4
|
import { PlatformResponse } from "../services/PlatformResponse.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
/**
|
|
7
|
+
* Return a 32 hex chars id, a uuid v4 without its dashes.
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export function createRequestId() {
|
|
11
|
+
const id = randomUUID();
|
|
12
|
+
return id.slice(0, 8) + id.slice(9, 13) + id.slice(14, 18) + id.slice(19, 23) + id.slice(24);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reuse the incoming `x-request-id` header, or create a new id.
|
|
16
|
+
* Express and Koa requests expose `get()`, a Fastify request only exposes `headers`.
|
|
17
|
+
* @ignore
|
|
18
|
+
*/
|
|
19
|
+
export function defaultReqIdBuilder(req) {
|
|
20
|
+
return (req.get ? req.get("x-request-id") : req.headers?.["x-request-id"]) || createRequestId();
|
|
8
21
|
}
|
|
9
22
|
function mapIgnoreUrlPatterns(ignoreUrlPatterns) {
|
|
10
23
|
return ignoreUrlPatterns.map((pattern) => (typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern));
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { IncomingEvent } from "../interfaces/IncomingEvent.js";
|
|
2
2
|
import { PlatformContext } from "../domain/PlatformContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Return a 32 hex chars id, a uuid v4 without its dashes.
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export declare function createRequestId(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Reuse the incoming `x-request-id` header, or create a new id.
|
|
10
|
+
* Express and Koa requests expose `get()`, a Fastify request only exposes `headers`.
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
13
|
+
export declare function defaultReqIdBuilder(req: any): any;
|
|
3
14
|
export declare function buildIgnoreLog(ignoreUrlPatterns: any[] | undefined): ((ignore: boolean, data: any, url: string) => any) | undefined;
|
|
4
15
|
/**
|
|
5
16
|
* Create the TsED context to wrap request, response, injector, etc...
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-http",
|
|
3
|
-
"version": "8.46.
|
|
3
|
+
"version": "8.46.3",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Controller",
|
|
@@ -70,33 +70,32 @@
|
|
|
70
70
|
"test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@tsed/core": "8.46.
|
|
74
|
-
"@tsed/di": "8.46.
|
|
75
|
-
"@tsed/exceptions": "8.46.
|
|
76
|
-
"@tsed/hooks": "8.46.
|
|
77
|
-
"@tsed/json-mapper": "8.46.
|
|
73
|
+
"@tsed/core": "8.46.3",
|
|
74
|
+
"@tsed/di": "8.46.3",
|
|
75
|
+
"@tsed/exceptions": "8.46.3",
|
|
76
|
+
"@tsed/hooks": "8.46.3",
|
|
77
|
+
"@tsed/json-mapper": "8.46.3",
|
|
78
78
|
"@tsed/logger": "^8.0.0",
|
|
79
79
|
"@tsed/logger-std": "^8.0.0",
|
|
80
|
-
"@tsed/platform-accept-mimes": "8.46.
|
|
81
|
-
"@tsed/platform-exceptions": "8.46.
|
|
82
|
-
"@tsed/platform-middlewares": "8.46.
|
|
83
|
-
"@tsed/platform-multer": "8.46.
|
|
84
|
-
"@tsed/platform-params": "8.46.
|
|
85
|
-
"@tsed/platform-response-filter": "8.46.
|
|
86
|
-
"@tsed/platform-router": "8.46.
|
|
87
|
-
"@tsed/platform-views": "8.46.
|
|
88
|
-
"@tsed/schema": "8.46.
|
|
80
|
+
"@tsed/platform-accept-mimes": "8.46.3",
|
|
81
|
+
"@tsed/platform-exceptions": "8.46.3",
|
|
82
|
+
"@tsed/platform-middlewares": "8.46.3",
|
|
83
|
+
"@tsed/platform-multer": "8.46.3",
|
|
84
|
+
"@tsed/platform-params": "8.46.3",
|
|
85
|
+
"@tsed/platform-response-filter": "8.46.3",
|
|
86
|
+
"@tsed/platform-router": "8.46.3",
|
|
87
|
+
"@tsed/platform-views": "8.46.3",
|
|
88
|
+
"@tsed/schema": "8.46.3",
|
|
89
89
|
"@types/json-schema": "7.0.15",
|
|
90
90
|
"accepts": "^1.3.8",
|
|
91
91
|
"cookie": "^2.0.1",
|
|
92
92
|
"encodeurl": "^2.0.0",
|
|
93
|
-
"tslib": ">=2.7.0"
|
|
94
|
-
"uuid": "14.0.0"
|
|
93
|
+
"tslib": ">=2.7.0"
|
|
95
94
|
},
|
|
96
95
|
"devDependencies": {
|
|
97
|
-
"@tsed/barrels": "8.46.
|
|
98
|
-
"@tsed/engines": "8.46.
|
|
99
|
-
"@tsed/typescript": "8.46.
|
|
96
|
+
"@tsed/barrels": "8.46.3",
|
|
97
|
+
"@tsed/engines": "8.46.3",
|
|
98
|
+
"@tsed/typescript": "8.46.3",
|
|
100
99
|
"cross-env": "7.0.3",
|
|
101
100
|
"typescript": "6.0.2",
|
|
102
101
|
"vitest": "4.1.4"
|