@tsed/common 7.63.0 → 7.63.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.
|
@@ -4,12 +4,10 @@ exports.PlatformHandler = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@tsed/core");
|
|
6
6
|
const di_1 = require("@tsed/di");
|
|
7
|
-
const logger_1 = require("@tsed/logger");
|
|
8
7
|
const platform_exceptions_1 = require("@tsed/platform-exceptions");
|
|
9
8
|
const platform_params_1 = require("@tsed/platform-params");
|
|
10
9
|
const platform_response_filter_1 = require("@tsed/platform-response-filter");
|
|
11
10
|
const platform_router_1 = require("@tsed/platform-router");
|
|
12
|
-
const util_1 = require("util");
|
|
13
11
|
const AnyToPromiseWithCtx_1 = require("../domain/AnyToPromiseWithCtx");
|
|
14
12
|
const setResponseHeaders_1 = require("../utils/setResponseHeaders");
|
|
15
13
|
const PlatformApplication_1 = require("./PlatformApplication");
|
|
@@ -31,23 +29,20 @@ let PlatformHandler = class PlatformHandler {
|
|
|
31
29
|
platformRouters.hooks
|
|
32
30
|
.on("alterEndpointHandlers", (handlers, operationRoute) => {
|
|
33
31
|
handlers = this.platformMiddlewaresChain.get(handlers, operationRoute);
|
|
34
|
-
handlers.after.push((0, platform_router_1.useResponseHandler)(this.
|
|
32
|
+
handlers.after.push((0, platform_router_1.useResponseHandler)(this.flush.bind(this)));
|
|
35
33
|
return handlers;
|
|
36
34
|
})
|
|
37
35
|
.on("alterHandler", (handlerMetadata) => {
|
|
38
|
-
|
|
36
|
+
const handler = handlerMetadata.isInjectable() ? this.createHandler(handlerMetadata) : handlerMetadata.handler;
|
|
37
|
+
return this.platformApplication.adapter.mapHandler(handler, handlerMetadata);
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
40
|
createHandler(handlerMetadata) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return this.next($ctx);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return handlerMetadata.handler;
|
|
41
|
+
const handler = this.platformParams.compileHandler(handlerMetadata);
|
|
42
|
+
return ($ctx) => {
|
|
43
|
+
$ctx.handlerMetadata = handlerMetadata;
|
|
44
|
+
return this.onRequest(handler, $ctx);
|
|
45
|
+
};
|
|
51
46
|
}
|
|
52
47
|
/**
|
|
53
48
|
* @param provider
|
|
@@ -59,93 +54,60 @@ let PlatformHandler = class PlatformHandler {
|
|
|
59
54
|
type: platform_router_1.PlatformHandlerType.CUSTOM,
|
|
60
55
|
propertyKey
|
|
61
56
|
});
|
|
62
|
-
|
|
63
|
-
return ($ctx) => {
|
|
64
|
-
$ctx.handlerMetadata = metadata;
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
return this.onRequest(handler, $ctx);
|
|
67
|
-
};
|
|
57
|
+
return this.createHandler(metadata);
|
|
68
58
|
}
|
|
69
59
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @protected
|
|
72
|
-
* @param $ctx
|
|
60
|
+
* Call handler when a request his handle
|
|
73
61
|
*/
|
|
74
|
-
async
|
|
75
|
-
const {
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
62
|
+
async onRequest(handler, $ctx) {
|
|
63
|
+
const { handlerMetadata } = $ctx;
|
|
64
|
+
if (handlerMetadata.type === platform_router_1.PlatformHandlerType.CTX_FN) {
|
|
65
|
+
return handler({ $ctx });
|
|
66
|
+
}
|
|
67
|
+
const resolver = new AnyToPromiseWithCtx_1.AnyToPromiseWithCtx($ctx);
|
|
68
|
+
const response = await resolver.call(handler);
|
|
69
|
+
// Note: restore previous handler metadata (for OIDC)
|
|
70
|
+
$ctx.handlerMetadata = handlerMetadata;
|
|
71
|
+
if (response.state === core_1.AnyToPromiseStatus.RESOLVED && !$ctx.isDone()) {
|
|
72
|
+
return this.onResponse(response, $ctx);
|
|
80
73
|
}
|
|
81
74
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
75
|
+
onResponse({ status, data, headers }, $ctx) {
|
|
76
|
+
if (status) {
|
|
77
|
+
$ctx.response.status(status);
|
|
78
|
+
}
|
|
79
|
+
if (headers) {
|
|
80
|
+
$ctx.response.setHeaders(headers);
|
|
81
|
+
}
|
|
82
|
+
if (data !== undefined) {
|
|
83
|
+
$ctx.data = data;
|
|
84
|
+
}
|
|
85
|
+
$ctx.error = null;
|
|
86
|
+
// set headers each times that an endpoint is called
|
|
87
|
+
if ($ctx.handlerMetadata.isEndpoint()) {
|
|
88
|
+
(0, setResponseHeaders_1.setResponseHeaders)($ctx);
|
|
88
89
|
}
|
|
89
|
-
return $ctx.error ? $ctx.next($ctx.error) : $ctx.next();
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
92
|
+
* Send the response to the consumer.
|
|
93
|
+
* @protected
|
|
94
|
+
* @param $ctx
|
|
93
95
|
*/
|
|
94
|
-
async
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${$ctx.handlerMetadata.toString()}`
|
|
99
|
-
});
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) || ($ctx.handlerMetadata.hasErrorParam && !$ctx.error)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
try {
|
|
106
|
-
const { handlerMetadata } = $ctx;
|
|
107
|
-
if (handlerMetadata.type === platform_router_1.PlatformHandlerType.CTX_FN) {
|
|
108
|
-
return await handler({ $ctx });
|
|
109
|
-
}
|
|
110
|
-
const resolver = new AnyToPromiseWithCtx_1.AnyToPromiseWithCtx($ctx);
|
|
111
|
-
const { state, type, data, status, headers } = await resolver.call(handler);
|
|
112
|
-
// Note: restore previous handler metadata (for OIDC)
|
|
113
|
-
$ctx.handlerMetadata = handlerMetadata;
|
|
114
|
-
if (state === core_1.AnyToPromiseStatus.RESOLVED) {
|
|
115
|
-
if (status) {
|
|
116
|
-
$ctx.response.status(status);
|
|
117
|
-
}
|
|
118
|
-
if (headers) {
|
|
119
|
-
$ctx.response.setHeaders(headers);
|
|
120
|
-
}
|
|
121
|
-
if (data !== undefined) {
|
|
122
|
-
$ctx.data = data;
|
|
123
|
-
}
|
|
96
|
+
async flush($ctx) {
|
|
97
|
+
if (!$ctx.error) {
|
|
98
|
+
$ctx.error = await (0, core_1.catchAsyncError)(async () => {
|
|
99
|
+
const { response } = $ctx;
|
|
124
100
|
if (!$ctx.isDone()) {
|
|
125
|
-
$ctx.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
(0, setResponseHeaders_1.setResponseHeaders)($ctx);
|
|
129
|
-
}
|
|
130
|
-
// call returned middleware
|
|
131
|
-
if ((0, core_1.isFunction)($ctx.data) && !(0, core_1.isStream)($ctx.data)) {
|
|
132
|
-
return (0, util_1.promisify)($ctx.data)($ctx.getRequest(), $ctx.getResponse());
|
|
133
|
-
}
|
|
134
|
-
if (type === core_1.AnyToPromiseResponseTypes.STREAM) {
|
|
135
|
-
return this.flush($ctx);
|
|
136
|
-
}
|
|
101
|
+
let data = await this.responseFilter.serialize($ctx.data, $ctx);
|
|
102
|
+
data = await this.responseFilter.transform(data, $ctx);
|
|
103
|
+
response.body(data);
|
|
137
104
|
}
|
|
138
|
-
}
|
|
105
|
+
});
|
|
139
106
|
}
|
|
140
|
-
|
|
141
|
-
$ctx.error
|
|
142
|
-
throw error;
|
|
107
|
+
if ($ctx.error) {
|
|
108
|
+
this.platformExceptions.catch($ctx.error, $ctx);
|
|
143
109
|
}
|
|
144
110
|
}
|
|
145
|
-
async onFinish($ctx) {
|
|
146
|
-
$ctx.error = await (0, core_1.catchAsyncError)(() => this.flush($ctx));
|
|
147
|
-
return $ctx.error && this.platformExceptions.catch($ctx.error, $ctx);
|
|
148
|
-
}
|
|
149
111
|
};
|
|
150
112
|
tslib_1.__decorate([
|
|
151
113
|
(0, di_1.Inject)(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";;;;AAAA,qCAAiF;AACjF,iCAAqE;AACrE,mEAA6D;AAC7D,2DAA6E;AAC7E,6EAAsE;AACtE,2DAM+B;AAE/B,uEAAkE;AAElE,oEAA+D;AAC/D,+DAA0D;AAC1D,yEAAoE;AAEpE;;;GAGG;AAII,IAAM,eAAe,GAArB,MAAM,eAAe;IAgBJ;IAdZ,cAAc,CAAyB;IAGvC,cAAc,CAAiB;IAG/B,kBAAkB,CAAqB;IAGvC,mBAAmB,CAAsB;IAGzC,wBAAwB,CAA2B;IAE7D,YAAsB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;QACpD,8BAA8B;QAC9B,eAAe,CAAC,KAAK;aAClB,EAAE,CAAC,uBAAuB,EAAE,CAAC,QAAkC,EAAE,cAAkC,EAAE,EAAE;YACtG,QAAQ,GAAG,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;YAEvE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAA,oCAAkB,EAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAE/D,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC;aACD,EAAE,CAAC,cAAc,EAAE,CAAC,eAAwC,EAAE,EAAE;YAC/D,MAAM,OAAO,GAAG,eAAe,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC;YAE/G,OAAO,IAAI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CAAA;AAxHC;IAAC,IAAA,WAAM,GAAE;sCACiB,iDAAsB;uDAAC;AAEjD;IAAC,IAAA,WAAM,GAAE;sCACiB,gCAAc;uDAAC;AAEzC;IAAC,IAAA,WAAM,GAAE;sCACqB,wCAAkB;2DAAC;AAEjD;IAAC,IAAA,WAAM,GAAE;sCACsB,yCAAmB;4DAAC;AAEnD;IAAC,IAAA,WAAM,GAAE;sCAC2B,mDAAwB;iEAAC;AAdlD,eAAe;IAH3B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;KAC/B,CAAC;6CAiBuC,iCAAe;GAhB3C,eAAe,CAyH3B;AAzHY,0CAAe"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { AnyToPromiseStatus, catchAsyncError } from "@tsed/core";
|
|
3
3
|
import { Inject, Injectable, ProviderScope } from "@tsed/di";
|
|
4
|
-
import { $log } from "@tsed/logger";
|
|
5
4
|
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
6
5
|
import { PlatformParams } from "@tsed/platform-params";
|
|
7
6
|
import { PlatformResponseFilter } from "@tsed/platform-response-filter";
|
|
8
7
|
import { PlatformHandlerMetadata, PlatformHandlerType, PlatformRouters, useResponseHandler } from "@tsed/platform-router";
|
|
9
|
-
import { promisify } from "util";
|
|
10
8
|
import { AnyToPromiseWithCtx } from "../domain/AnyToPromiseWithCtx.js";
|
|
11
9
|
import { setResponseHeaders } from "../utils/setResponseHeaders.js";
|
|
12
10
|
import { PlatformApplication } from "./PlatformApplication.js";
|
|
@@ -28,23 +26,20 @@ let PlatformHandler = class PlatformHandler {
|
|
|
28
26
|
platformRouters.hooks
|
|
29
27
|
.on("alterEndpointHandlers", (handlers, operationRoute) => {
|
|
30
28
|
handlers = this.platformMiddlewaresChain.get(handlers, operationRoute);
|
|
31
|
-
handlers.after.push(useResponseHandler(this.
|
|
29
|
+
handlers.after.push(useResponseHandler(this.flush.bind(this)));
|
|
32
30
|
return handlers;
|
|
33
31
|
})
|
|
34
32
|
.on("alterHandler", (handlerMetadata) => {
|
|
35
|
-
|
|
33
|
+
const handler = handlerMetadata.isInjectable() ? this.createHandler(handlerMetadata) : handlerMetadata.handler;
|
|
34
|
+
return this.platformApplication.adapter.mapHandler(handler, handlerMetadata);
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
37
|
createHandler(handlerMetadata) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return this.next($ctx);
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return handlerMetadata.handler;
|
|
38
|
+
const handler = this.platformParams.compileHandler(handlerMetadata);
|
|
39
|
+
return ($ctx) => {
|
|
40
|
+
$ctx.handlerMetadata = handlerMetadata;
|
|
41
|
+
return this.onRequest(handler, $ctx);
|
|
42
|
+
};
|
|
48
43
|
}
|
|
49
44
|
/**
|
|
50
45
|
* @param provider
|
|
@@ -56,93 +51,60 @@ let PlatformHandler = class PlatformHandler {
|
|
|
56
51
|
type: PlatformHandlerType.CUSTOM,
|
|
57
52
|
propertyKey
|
|
58
53
|
});
|
|
59
|
-
|
|
60
|
-
return ($ctx) => {
|
|
61
|
-
$ctx.handlerMetadata = metadata;
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
return this.onRequest(handler, $ctx);
|
|
64
|
-
};
|
|
54
|
+
return this.createHandler(metadata);
|
|
65
55
|
}
|
|
66
56
|
/**
|
|
67
|
-
*
|
|
68
|
-
* @protected
|
|
69
|
-
* @param $ctx
|
|
57
|
+
* Call handler when a request his handle
|
|
70
58
|
*/
|
|
71
|
-
async
|
|
72
|
-
const {
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
async onRequest(handler, $ctx) {
|
|
60
|
+
const { handlerMetadata } = $ctx;
|
|
61
|
+
if (handlerMetadata.type === PlatformHandlerType.CTX_FN) {
|
|
62
|
+
return handler({ $ctx });
|
|
63
|
+
}
|
|
64
|
+
const resolver = new AnyToPromiseWithCtx($ctx);
|
|
65
|
+
const response = await resolver.call(handler);
|
|
66
|
+
// Note: restore previous handler metadata (for OIDC)
|
|
67
|
+
$ctx.handlerMetadata = handlerMetadata;
|
|
68
|
+
if (response.state === AnyToPromiseStatus.RESOLVED && !$ctx.isDone()) {
|
|
69
|
+
return this.onResponse(response, $ctx);
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
72
|
+
onResponse({ status, data, headers }, $ctx) {
|
|
73
|
+
if (status) {
|
|
74
|
+
$ctx.response.status(status);
|
|
75
|
+
}
|
|
76
|
+
if (headers) {
|
|
77
|
+
$ctx.response.setHeaders(headers);
|
|
78
|
+
}
|
|
79
|
+
if (data !== undefined) {
|
|
80
|
+
$ctx.data = data;
|
|
81
|
+
}
|
|
82
|
+
$ctx.error = null;
|
|
83
|
+
// set headers each times that an endpoint is called
|
|
84
|
+
if ($ctx.handlerMetadata.isEndpoint()) {
|
|
85
|
+
setResponseHeaders($ctx);
|
|
85
86
|
}
|
|
86
|
-
return $ctx.error ? $ctx.next($ctx.error) : $ctx.next();
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
89
|
+
* Send the response to the consumer.
|
|
90
|
+
* @protected
|
|
91
|
+
* @param $ctx
|
|
90
92
|
*/
|
|
91
|
-
async
|
|
92
|
-
if (
|
|
93
|
-
$
|
|
94
|
-
|
|
95
|
-
message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${$ctx.handlerMetadata.toString()}`
|
|
96
|
-
});
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) || ($ctx.handlerMetadata.hasErrorParam && !$ctx.error)) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
try {
|
|
103
|
-
const { handlerMetadata } = $ctx;
|
|
104
|
-
if (handlerMetadata.type === PlatformHandlerType.CTX_FN) {
|
|
105
|
-
return await handler({ $ctx });
|
|
106
|
-
}
|
|
107
|
-
const resolver = new AnyToPromiseWithCtx($ctx);
|
|
108
|
-
const { state, type, data, status, headers } = await resolver.call(handler);
|
|
109
|
-
// Note: restore previous handler metadata (for OIDC)
|
|
110
|
-
$ctx.handlerMetadata = handlerMetadata;
|
|
111
|
-
if (state === AnyToPromiseStatus.RESOLVED) {
|
|
112
|
-
if (status) {
|
|
113
|
-
$ctx.response.status(status);
|
|
114
|
-
}
|
|
115
|
-
if (headers) {
|
|
116
|
-
$ctx.response.setHeaders(headers);
|
|
117
|
-
}
|
|
118
|
-
if (data !== undefined) {
|
|
119
|
-
$ctx.data = data;
|
|
120
|
-
}
|
|
93
|
+
async flush($ctx) {
|
|
94
|
+
if (!$ctx.error) {
|
|
95
|
+
$ctx.error = await catchAsyncError(async () => {
|
|
96
|
+
const { response } = $ctx;
|
|
121
97
|
if (!$ctx.isDone()) {
|
|
122
|
-
$ctx.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
setResponseHeaders($ctx);
|
|
126
|
-
}
|
|
127
|
-
// call returned middleware
|
|
128
|
-
if (isFunction($ctx.data) && !isStream($ctx.data)) {
|
|
129
|
-
return promisify($ctx.data)($ctx.getRequest(), $ctx.getResponse());
|
|
130
|
-
}
|
|
131
|
-
if (type === AnyToPromiseResponseTypes.STREAM) {
|
|
132
|
-
return this.flush($ctx);
|
|
133
|
-
}
|
|
98
|
+
let data = await this.responseFilter.serialize($ctx.data, $ctx);
|
|
99
|
+
data = await this.responseFilter.transform(data, $ctx);
|
|
100
|
+
response.body(data);
|
|
134
101
|
}
|
|
135
|
-
}
|
|
102
|
+
});
|
|
136
103
|
}
|
|
137
|
-
|
|
138
|
-
$ctx.error
|
|
139
|
-
throw error;
|
|
104
|
+
if ($ctx.error) {
|
|
105
|
+
this.platformExceptions.catch($ctx.error, $ctx);
|
|
140
106
|
}
|
|
141
107
|
}
|
|
142
|
-
async onFinish($ctx) {
|
|
143
|
-
$ctx.error = await catchAsyncError(() => this.flush($ctx));
|
|
144
|
-
return $ctx.error && this.platformExceptions.catch($ctx.error, $ctx);
|
|
145
|
-
}
|
|
146
108
|
};
|
|
147
109
|
__decorate([
|
|
148
110
|
Inject(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAmB,kBAAkB,EAAE,eAAe,EAAC,MAAM,YAAY,CAAC;AACjF,OAAO,EAAC,MAAM,EAAE,UAAU,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACrE,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAC,cAAc,EAAyB,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAEL,uBAAuB,EACvB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AAEpE;;;GAGG;AAII,IAAM,eAAe,GAArB,MAAM,eAAe;IAgBJ;IAdZ,cAAc,CAAyB;IAGvC,cAAc,CAAiB;IAG/B,kBAAkB,CAAqB;IAGvC,mBAAmB,CAAsB;IAGzC,wBAAwB,CAA2B;IAE7D,YAA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AI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,KAAK,GAAG,MAAM,eAAe,CAAC,KAAK,IAAI,EAAE;gBAC5C,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;gBAExB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;oBAClB,IAAI,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC;oBACvE,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,EAAE,IAAW,CAAC,CAAC;oBAC9D,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACrB;YACH,CAAC,CAAC,CAAC;SACJ;QAED,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACjD;IACH,CAAC;CACF,CAAA;AAxHC;IAAC,MAAM,EAAE;8BACiB,sBAAsB;uDAAC;AAEjD;IAAC,MAAM,EAAE;8BACiB,cAAc;uDAAC;AAEzC;IAAC,MAAM,EAAE;8BACqB,kBAAkB;2DAAC;AAEjD;IAAC,MAAM,EAAE;8BACsB,mBAAmB;4DAAC;AAEnD;IAAC,MAAM,EAAE;8BAC2B,wBAAwB;iEAAC;AAdlD,eAAe;IAH3B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAiBuC,eAAe;GAhB3C,eAAe,CAyH3B;SAzHY,eAAe"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AnyPromiseResult } from "@tsed/core";
|
|
1
2
|
import { Provider } from "@tsed/di";
|
|
2
3
|
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
3
4
|
import { PlatformParams, PlatformParamsCallback } from "@tsed/platform-params";
|
|
@@ -23,20 +24,16 @@ export declare class PlatformHandler {
|
|
|
23
24
|
* @param provider
|
|
24
25
|
* @param propertyKey
|
|
25
26
|
*/
|
|
26
|
-
createCustomHandler(provider: Provider, propertyKey: string):
|
|
27
|
+
createCustomHandler(provider: Provider, propertyKey: string): any;
|
|
28
|
+
/**
|
|
29
|
+
* Call handler when a request his handle
|
|
30
|
+
*/
|
|
31
|
+
onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any>;
|
|
32
|
+
onResponse({ status, data, headers }: AnyPromiseResult, $ctx: PlatformContext): void;
|
|
27
33
|
/**
|
|
28
34
|
* Send the response to the consumer.
|
|
29
35
|
* @protected
|
|
30
36
|
* @param $ctx
|
|
31
37
|
*/
|
|
32
38
|
flush($ctx: PlatformContext): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* @param $ctx
|
|
35
|
-
*/
|
|
36
|
-
next($ctx: PlatformContext): any;
|
|
37
|
-
/**
|
|
38
|
-
* Call handler when a request his handle
|
|
39
|
-
*/
|
|
40
|
-
onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext): Promise<any>;
|
|
41
|
-
onFinish($ctx: PlatformContext): Promise<unknown>;
|
|
42
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/common",
|
|
3
|
-
"version": "7.63.
|
|
3
|
+
"version": "7.63.2",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -60,28 +60,28 @@
|
|
|
60
60
|
}
|
|
61
61
|
],
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@tsed/core": "7.63.
|
|
64
|
-
"@tsed/di": "7.63.
|
|
65
|
-
"@tsed/exceptions": "7.63.
|
|
66
|
-
"@tsed/json-mapper": "7.63.
|
|
63
|
+
"@tsed/core": "7.63.2",
|
|
64
|
+
"@tsed/di": "7.63.2",
|
|
65
|
+
"@tsed/exceptions": "7.63.2",
|
|
66
|
+
"@tsed/json-mapper": "7.63.2",
|
|
67
67
|
"@tsed/logger": ">=6.2.2",
|
|
68
68
|
"@tsed/logger-file": ">=6.2.2",
|
|
69
|
-
"@tsed/platform-exceptions": "7.63.
|
|
70
|
-
"@tsed/platform-log-middleware": "7.63.
|
|
71
|
-
"@tsed/platform-middlewares": "7.63.
|
|
72
|
-
"@tsed/platform-params": "7.63.
|
|
73
|
-
"@tsed/platform-response-filter": "7.63.
|
|
74
|
-
"@tsed/platform-router": "7.63.
|
|
75
|
-
"@tsed/platform-views": "7.63.
|
|
76
|
-
"@tsed/schema": "7.63.
|
|
69
|
+
"@tsed/platform-exceptions": "7.63.2",
|
|
70
|
+
"@tsed/platform-log-middleware": "7.63.2",
|
|
71
|
+
"@tsed/platform-middlewares": "7.63.2",
|
|
72
|
+
"@tsed/platform-params": "7.63.2",
|
|
73
|
+
"@tsed/platform-response-filter": "7.63.2",
|
|
74
|
+
"@tsed/platform-router": "7.63.2",
|
|
75
|
+
"@tsed/platform-views": "7.63.2",
|
|
76
|
+
"@tsed/schema": "7.63.2",
|
|
77
77
|
"@types/json-schema": "7.0.11",
|
|
78
78
|
"accepts": "^1.3.8",
|
|
79
79
|
"tslib": "2.6.1",
|
|
80
80
|
"uuid": "8.3.2"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@tsed/components-scan": "7.63.
|
|
84
|
-
"@tsed/typescript": "7.63.
|
|
83
|
+
"@tsed/components-scan": "7.63.2",
|
|
84
|
+
"@tsed/typescript": "7.63.2",
|
|
85
85
|
"barrelsby": "^2.8.1",
|
|
86
86
|
"cross-env": "7.0.3",
|
|
87
87
|
"eslint": "^8.12.0",
|