@tsed/common 7.0.0-beta.13 → 7.0.0-beta.16
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/jest.config.js +4 -4
- package/lib/cjs/builder/PlatformBuilder.js +20 -10
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/decorators/params/error.js +1 -1
- package/lib/cjs/decorators/params/error.js.map +1 -1
- package/lib/cjs/domain/AnyToPromiseWithCtx.js +1 -3
- package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/cjs/domain/PlatformContext.js +28 -1
- package/lib/cjs/domain/PlatformContext.js.map +1 -1
- package/lib/cjs/domain/PlatformRouteDetails.js +0 -25
- package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/cjs/exports.js +1 -0
- package/lib/cjs/exports.js.map +1 -1
- package/lib/cjs/index.js +1 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/Route.js.map +1 -1
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/cjs/services/FakeAdapter.js +5 -9
- package/lib/cjs/services/FakeAdapter.js.map +1 -1
- package/lib/cjs/services/Platform.js +41 -85
- package/lib/cjs/services/Platform.js.map +1 -1
- package/lib/cjs/services/PlatformAdapter.js +0 -2
- package/lib/cjs/services/PlatformAdapter.js.map +1 -1
- package/lib/cjs/services/PlatformApplication.js +22 -10
- package/lib/cjs/services/PlatformApplication.js.map +1 -1
- package/lib/cjs/services/PlatformHandler.js +87 -163
- package/lib/cjs/services/PlatformHandler.js.map +1 -1
- package/lib/cjs/services/PlatformMiddlewaresChain.js +2 -18
- package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/cjs/services/PlatformRequest.js +2 -2
- package/lib/cjs/services/PlatformRequest.js.map +1 -1
- package/lib/cjs/services/PlatformResponse.js +5 -9
- package/lib/cjs/services/PlatformResponse.js.map +1 -1
- package/lib/cjs/services/PlatformTest.js +1 -0
- package/lib/cjs/services/PlatformTest.js.map +1 -1
- package/lib/cjs/utils/createContext.js +7 -11
- package/lib/cjs/utils/createContext.js.map +1 -1
- package/lib/cjs/utils/createInjector.js +0 -2
- package/lib/cjs/utils/createInjector.js.map +1 -1
- package/lib/cjs/utils/ensureContext.js +16 -0
- package/lib/cjs/utils/ensureContext.js.map +1 -0
- package/lib/cjs/utils/printRoutes.js +10 -8
- package/lib/cjs/utils/printRoutes.js.map +1 -1
- package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +20 -10
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/decorators/params/error.js +1 -1
- package/lib/esm/decorators/params/error.js.map +1 -1
- package/lib/esm/domain/AnyToPromiseWithCtx.js +1 -3
- package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/esm/domain/PlatformContext.js +28 -1
- package/lib/esm/domain/PlatformContext.js.map +1 -1
- package/lib/esm/domain/PlatformRouteDetails.js +1 -23
- package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/esm/exports.js +1 -0
- package/lib/esm/exports.js.map +1 -1
- package/lib/esm/index.js +1 -7
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/Route.js.map +1 -1
- package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/esm/services/FakeAdapter.js +5 -9
- package/lib/esm/services/FakeAdapter.js.map +1 -1
- package/lib/esm/services/Platform.js +42 -86
- package/lib/esm/services/Platform.js.map +1 -1
- package/lib/esm/services/PlatformAdapter.js +0 -2
- package/lib/esm/services/PlatformAdapter.js.map +1 -1
- package/lib/esm/services/PlatformApplication.js +22 -10
- package/lib/esm/services/PlatformApplication.js.map +1 -1
- package/lib/esm/services/PlatformHandler.js +89 -165
- package/lib/esm/services/PlatformHandler.js.map +1 -1
- package/lib/esm/services/PlatformMiddlewaresChain.js +2 -18
- package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/esm/services/PlatformRequest.js +2 -2
- package/lib/esm/services/PlatformRequest.js.map +1 -1
- package/lib/esm/services/PlatformResponse.js +5 -9
- package/lib/esm/services/PlatformResponse.js.map +1 -1
- package/lib/esm/services/PlatformTest.js +1 -0
- package/lib/esm/services/PlatformTest.js.map +1 -1
- package/lib/esm/utils/createContext.js +5 -9
- package/lib/esm/utils/createContext.js.map +1 -1
- package/lib/esm/utils/createInjector.js +0 -2
- package/lib/esm/utils/createInjector.js.map +1 -1
- package/lib/esm/utils/ensureContext.js +12 -0
- package/lib/esm/utils/ensureContext.js.map +1 -0
- package/lib/esm/utils/printRoutes.js +10 -8
- package/lib/esm/utils/printRoutes.js.map +1 -1
- package/lib/esm/utils/setResponseHeaders.js.map +1 -1
- package/lib/types/builder/PlatformBuilder.d.ts +13 -11
- package/lib/types/domain/AnyToPromiseWithCtx.d.ts +1 -9
- package/lib/types/domain/PlatformContext.d.ts +16 -1
- package/lib/types/domain/PlatformRouteDetails.d.ts +6 -15
- package/lib/types/exports.d.ts +1 -0
- package/lib/types/index.d.ts +1 -7
- package/lib/types/interfaces/Route.d.ts +2 -3
- package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +1 -1
- package/lib/types/services/FakeAdapter.d.ts +7 -6
- package/lib/types/services/Platform.d.ts +11 -28
- package/lib/types/services/PlatformAdapter.d.ts +19 -10
- package/lib/types/services/PlatformApplication.d.ts +14 -6
- package/lib/types/services/PlatformHandler.d.ts +19 -55
- package/lib/types/services/PlatformMiddlewaresChain.d.ts +1 -2
- package/lib/types/services/PlatformRequest.d.ts +1 -5
- package/lib/types/services/PlatformResponse.d.ts +2 -4
- package/lib/types/services/PlatformTest.d.ts +2 -1
- package/lib/types/utils/createContext.d.ts +2 -2
- package/lib/types/utils/createInjector.d.ts +1 -1
- package/lib/types/utils/ensureContext.d.ts +2 -0
- package/package.json +16 -15
- package/lib/cjs/builder/PlatformControllerBuilder.js +0 -82
- package/lib/cjs/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/cjs/domain/ControllerProvider.js +0 -52
- package/lib/cjs/domain/ControllerProvider.js.map +0 -1
- package/lib/cjs/domain/HandlerMetadata.js +0 -62
- package/lib/cjs/domain/HandlerMetadata.js.map +0 -1
- package/lib/cjs/middlewares/bindEndpointMiddleware.js +0 -13
- package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +0 -1
- package/lib/cjs/services/PlatformRouter.js +0 -114
- package/lib/cjs/services/PlatformRouter.js.map +0 -1
- package/lib/cjs/utils/createHandlerMetadata.js +0 -49
- package/lib/cjs/utils/createHandlerMetadata.js.map +0 -1
- package/lib/cjs/utils/useCtxHandler.js +0 -15
- package/lib/cjs/utils/useCtxHandler.js.map +0 -1
- package/lib/esm/builder/PlatformControllerBuilder.js +0 -76
- package/lib/esm/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/esm/domain/ControllerProvider.js +0 -48
- package/lib/esm/domain/ControllerProvider.js.map +0 -1
- package/lib/esm/domain/HandlerMetadata.js +0 -58
- package/lib/esm/domain/HandlerMetadata.js.map +0 -1
- package/lib/esm/middlewares/bindEndpointMiddleware.js +0 -9
- package/lib/esm/middlewares/bindEndpointMiddleware.js.map +0 -1
- package/lib/esm/services/PlatformRouter.js +0 -111
- package/lib/esm/services/PlatformRouter.js.map +0 -1
- package/lib/esm/utils/createHandlerMetadata.js +0 -45
- package/lib/esm/utils/createHandlerMetadata.js.map +0 -1
- package/lib/esm/utils/useCtxHandler.js +0 -11
- package/lib/esm/utils/useCtxHandler.js.map +0 -1
- package/lib/types/builder/PlatformControllerBuilder.d.ts +0 -18
- package/lib/types/domain/ControllerProvider.d.ts +0 -24
- package/lib/types/domain/HandlerMetadata.d.ts +0 -32
- package/lib/types/middlewares/bindEndpointMiddleware.d.ts +0 -6
- package/lib/types/services/PlatformRouter.d.ts +0 -51
- package/lib/types/utils/createHandlerMetadata.d.ts +0 -8
- package/lib/types/utils/useCtxHandler.d.ts +0 -13
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { Injectable, InjectorService, ProviderScope
|
|
3
|
-
import {
|
|
4
|
-
import { buildRouter, createRouter, getRouter } from "../builder/PlatformControllerBuilder.js";
|
|
5
|
-
import { PlatformRouteDetails } from "../domain/PlatformRouteDetails.js";
|
|
2
|
+
import { Injectable, InjectorService, ProviderScope } from "@tsed/di";
|
|
3
|
+
import { PlatformRouters } from "@tsed/platform-router";
|
|
6
4
|
import { PlatformApplication } from "./PlatformApplication.js";
|
|
5
|
+
import { PlatformHandler } from "./PlatformHandler.js";
|
|
7
6
|
import { PlatformMiddlewaresChain } from "./PlatformMiddlewaresChain.js";
|
|
8
7
|
/**
|
|
9
8
|
* `Platform` is used to provide all routes collected by annotation `@Controller`.
|
|
@@ -13,115 +12,72 @@ import { PlatformMiddlewaresChain } from "./PlatformMiddlewaresChain.js";
|
|
|
13
12
|
let Platform = class Platform {
|
|
14
13
|
injector;
|
|
15
14
|
platformApplication;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
platformRouters;
|
|
16
|
+
platformHandler;
|
|
17
|
+
platformMiddlewaresChain;
|
|
18
|
+
#controllers = new Map();
|
|
19
|
+
constructor(injector, platformApplication, platformRouters, platformHandler, platformMiddlewaresChain) {
|
|
19
20
|
this.injector = injector;
|
|
20
21
|
this.platformApplication = platformApplication;
|
|
21
|
-
this.
|
|
22
|
+
this.platformRouters = platformRouters;
|
|
23
|
+
this.platformHandler = platformHandler;
|
|
24
|
+
this.platformMiddlewaresChain = platformMiddlewaresChain;
|
|
25
|
+
// configure the router module
|
|
26
|
+
platformRouters.hooks
|
|
27
|
+
.on("alterEndpointHandlers", platformMiddlewaresChain.get.bind(platformMiddlewaresChain))
|
|
28
|
+
.on("alterHandler", (handler, handlerMetadata) => {
|
|
29
|
+
handler = handlerMetadata.isRawMiddleware() ? handler : this.platformHandler.createHandler(handler, handlerMetadata);
|
|
30
|
+
return platformApplication.adapter.mapHandler(handler, handlerMetadata);
|
|
31
|
+
});
|
|
32
|
+
platformRouters.prebuild();
|
|
22
33
|
}
|
|
23
34
|
get app() {
|
|
24
35
|
return this.platformApplication;
|
|
25
36
|
}
|
|
26
|
-
get routes() {
|
|
27
|
-
return this._routes;
|
|
28
|
-
}
|
|
29
37
|
addRoutes(routes) {
|
|
30
38
|
routes.forEach((routeSettings) => {
|
|
31
39
|
this.addRoute(routeSettings.route, routeSettings.token);
|
|
32
40
|
});
|
|
33
41
|
}
|
|
34
|
-
addRoute(
|
|
35
|
-
const
|
|
36
|
-
const provider = injector.getProvider(token);
|
|
42
|
+
addRoute(route, token) {
|
|
43
|
+
const provider = this.injector.getProvider(token);
|
|
37
44
|
if (!provider || provider.hasParent()) {
|
|
38
|
-
return;
|
|
45
|
+
return this;
|
|
39
46
|
}
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));
|
|
43
|
-
this._routes = getOperationsRoutes(provider.token, {
|
|
44
|
-
withChildren: true,
|
|
45
|
-
basePath
|
|
46
|
-
}).reduce((routes, operationRoute) => {
|
|
47
|
-
if (injector.hasProvider(token)) {
|
|
48
|
-
const provider = injector.getProvider(operationRoute.token);
|
|
49
|
-
const route = new PlatformRouteDetails({
|
|
50
|
-
...operationRoute,
|
|
51
|
-
provider
|
|
52
|
-
});
|
|
53
|
-
routes = routes.concat(route);
|
|
54
|
-
}
|
|
55
|
-
return routes;
|
|
56
|
-
}, this._routes);
|
|
47
|
+
const router = this.platformRouters.from(provider.token);
|
|
48
|
+
this.app.use(route, router);
|
|
57
49
|
return this;
|
|
58
50
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
getLayers() {
|
|
52
|
+
this.#controllers = new Map();
|
|
53
|
+
return this.platformRouters.getLayers(this.app).map((layer) => {
|
|
54
|
+
if (layer.isProvider()) {
|
|
55
|
+
this.#controllers.set(layer.provider.token, {
|
|
56
|
+
route: String(layer.path).split(layer.provider.path)[0],
|
|
57
|
+
provider: layer.provider
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return layer;
|
|
61
|
+
});
|
|
65
62
|
}
|
|
66
63
|
/**
|
|
67
64
|
* Get all controllers mounted on the application.
|
|
68
65
|
* @returns {RouteController[]}
|
|
69
66
|
*/
|
|
70
67
|
getMountedControllers() {
|
|
71
|
-
return this.
|
|
72
|
-
}
|
|
73
|
-
$onInit() {
|
|
74
|
-
this.buildControllers();
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Create routers from the collected controllers.
|
|
78
|
-
* @private
|
|
79
|
-
*/
|
|
80
|
-
createRouters() {
|
|
81
|
-
const { injector } = this;
|
|
82
|
-
injector.getProviders(ProviderType.CONTROLLER).map((provider) => {
|
|
83
|
-
createRouter(injector, provider);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Get all router controllers from the controller token.
|
|
88
|
-
* @private
|
|
89
|
-
*/
|
|
90
|
-
getAllControllers(basePath, token) {
|
|
91
|
-
const store = token.isStore ? token : getJsonEntityStore(token);
|
|
92
|
-
const ctrlPath = concatPath(basePath, JsonEntityStore.from(token).path);
|
|
93
|
-
const children = store.get("childrenControllers", []);
|
|
94
|
-
return children
|
|
95
|
-
.reduce((controllers, token) => {
|
|
96
|
-
const childBasePath = concatPath(basePath, store.path);
|
|
97
|
-
return controllers.concat(this.getAllControllers(childBasePath, token));
|
|
98
|
-
}, [])
|
|
99
|
-
.concat([
|
|
100
|
-
{
|
|
101
|
-
route: ctrlPath,
|
|
102
|
-
provider: this.injector.getProvider(token)
|
|
103
|
-
}
|
|
104
|
-
]);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Create controllers from DI
|
|
108
|
-
* @private
|
|
109
|
-
*/
|
|
110
|
-
buildControllers() {
|
|
111
|
-
const { injector } = this;
|
|
112
|
-
injector.getProviders(ProviderType.CONTROLLER).map((provider) => {
|
|
113
|
-
if (!provider.hasParent()) {
|
|
114
|
-
return buildRouter(injector, provider);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
68
|
+
return [...this.#controllers.values()];
|
|
117
69
|
}
|
|
118
70
|
};
|
|
119
71
|
Platform = __decorate([
|
|
120
72
|
Injectable({
|
|
121
73
|
scope: ProviderScope.SINGLETON,
|
|
122
|
-
imports: [
|
|
74
|
+
imports: []
|
|
123
75
|
}),
|
|
124
|
-
__metadata("design:paramtypes", [InjectorService,
|
|
76
|
+
__metadata("design:paramtypes", [InjectorService,
|
|
77
|
+
PlatformApplication,
|
|
78
|
+
PlatformRouters,
|
|
79
|
+
PlatformHandler,
|
|
80
|
+
PlatformMiddlewaresChain])
|
|
125
81
|
], Platform);
|
|
126
82
|
export { Platform };
|
|
127
83
|
//# sourceMappingURL=Platform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/services/Platform.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/services/Platform.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,eAAe,EAAE,aAAa,EAAgB,MAAM,UAAU,CAAC;AACnF,OAAO,EAA0B,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAG/E,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AAEpE;;;;GAIG;AAKH,IAAa,QAAQ,GAArB,MAAa,QAAQ;IAIR;IACA;IACA;IACA;IACA;IAPX,YAAY,GAAiC,IAAI,GAAG,EAAE,CAAC;IAEvD,YACW,QAAyB,EACzB,mBAAwC,EACxC,eAAgC,EAChC,eAAgC,EAChC,wBAAkD;QAJlD,aAAQ,GAAR,QAAQ,CAAiB;QACzB,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,oBAAe,GAAf,eAAe,CAAiB;QAChC,oBAAe,GAAf,eAAe,CAAiB;QAChC,6BAAwB,GAAxB,wBAAwB,CAA0B;QAE3D,8BAA8B;QAC9B,eAAe,CAAC,KAAK;aAClB,EAAE,CAAC,uBAAuB,EAAE,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;aACxF,EAAE,CAAC,cAAc,EAAE,CAAC,OAAiB,EAAE,eAAwC,EAAE,EAAE;YAClF,OAAO,GAAG,eAAe,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,OAAc,EAAE,eAAe,CAAC,CAAC;YAE5H,OAAO,mBAAmB,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;QAEL,eAAe,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAEM,SAAS,CAAC,MAAe;QAC9B,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;YAC/B,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,QAAQ,CAAC,KAAa,EAAE,KAAoB;QACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAuB,CAAC;QAExE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,EAAE,EAAE;YACrC,OAAO,IAAI,CAAC;SACb;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEzD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAE5B,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,SAAS;QACd,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAE9B,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC5D,IAAI,KAAK,CAAC,UAAU,EAAE,EAAE;gBACtB,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE;oBAC1C,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACvD,QAAQ,EAAE,KAAK,CAAC,QAAQ;iBACzB,CAAC,CAAC;aACJ;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACI,qBAAqB;QAC1B,OAAO,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;CACF,CAAA;AApEY,QAAQ;IAJpB,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,EAAE;KACZ,CAAC;qCAKqB,eAAe;QACJ,mBAAmB;QACvB,eAAe;QACf,eAAe;QACN,wBAAwB;GARlD,QAAQ,CAoEpB;SApEY,QAAQ","sourcesContent":["import {Injectable, InjectorService, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport {PlatformHandlerMetadata, PlatformRouters} from \"@tsed/platform-router\";\nimport {ControllerProvider} from \"@tsed/di\";\nimport {Route, RouteController} from \"../interfaces/Route\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformMiddlewaresChain} from \"./PlatformMiddlewaresChain\";\n\n/**\n * `Platform` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: []\n})\nexport class Platform {\n #controllers: Map<string, RouteController> = new Map();\n\n constructor(\n readonly injector: InjectorService,\n readonly platformApplication: PlatformApplication,\n readonly platformRouters: PlatformRouters,\n readonly platformHandler: PlatformHandler,\n readonly platformMiddlewaresChain: PlatformMiddlewaresChain\n ) {\n // configure the router module\n platformRouters.hooks\n .on(\"alterEndpointHandlers\", platformMiddlewaresChain.get.bind(platformMiddlewaresChain))\n .on(\"alterHandler\", (handler: Function, handlerMetadata: PlatformHandlerMetadata) => {\n handler = handlerMetadata.isRawMiddleware() ? handler : this.platformHandler.createHandler(handler as any, handlerMetadata);\n\n return platformApplication.adapter.mapHandler(handler, handlerMetadata);\n });\n\n platformRouters.prebuild();\n }\n\n get app() {\n return this.platformApplication;\n }\n\n public addRoutes(routes: Route[]) {\n routes.forEach((routeSettings) => {\n this.addRoute(routeSettings.route, routeSettings.token);\n });\n }\n\n public addRoute(route: string, token: TokenProvider) {\n const provider = this.injector.getProvider(token) as ControllerProvider;\n\n if (!provider || provider.hasParent()) {\n return this;\n }\n\n const router = this.platformRouters.from(provider.token);\n\n this.app.use(route, router);\n\n return this;\n }\n\n public getLayers() {\n this.#controllers = new Map();\n\n return this.platformRouters.getLayers(this.app).map((layer) => {\n if (layer.isProvider()) {\n this.#controllers.set(layer.provider.token, {\n route: String(layer.path).split(layer.provider.path)[0],\n provider: layer.provider\n });\n }\n\n return layer;\n });\n }\n\n /**\n * Get all controllers mounted on the application.\n * @returns {RouteController[]}\n */\n public getMountedControllers(): RouteController[] {\n return [...this.#controllers.values()];\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAgB,gBAAgB,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAgB,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAKzE,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,MAAM,OAAgB,eAAe;IACnC;;OAEG;IACH,SAAS,CAAiB;IAC1B;;OAEG;IACH,MAAM,CAAa;IACnB,gBAAgB,CAAsB;IACtC,eAAe,CAAsB;CAsCtC;AAMD,gBAAgB,CAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,eAAe,CAAC;IACvB,QAAQ,EAAE,WAAW;CACtB,CAAC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, registerProvider} from \"@tsed/di\";\nimport {PlatformContextHandler, PlatformHandlerMetadata, PlatformLayer} from \"@tsed/platform-router\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\nexport abstract class PlatformAdapter<App = TsED.Application> {\n /**\n * Load providers in top priority\n */\n providers: ProviderOpts[];\n /**\n * Called after the injector instantiation\n */\n onInit?: () => any;\n beforeLoadRoutes?: () => Promise<any>;\n afterLoadRoutes?: () => Promise<any>;\n /**\n * create initial context\n */\n abstract useContext: () => any;\n /**\n * Map router layer to the targeted framework\n */\n abstract mapLayers: (layer: PlatformLayer[]) => void;\n /**\n * Map handler to the targeted framework\n */\n abstract mapHandler: (handler: Function, layer: PlatformHandlerMetadata) => Function;\n\n /**\n * Return the app instance\n */\n abstract app(): {app: App; callback(): any};\n\n /**\n * Return the statics middlewares\n * @param endpoint\n * @param options\n */\n abstract statics(endpoint: string, options: PlatformStaticsOptions): any;\n\n /**\n * Return the multipart middleware\n * @param options\n */\n abstract multipart(options: PlatformMulterSettings): PlatformMulter;\n\n /**\n * Return the body parser for the given\n * @param type\n * @param opts\n */\n abstract bodyParser(type: string, opts?: Record<string, any>): any;\n}\n\nexport interface PlatformBuilderSettings<App = TsED.Application> extends Partial<TsED.Configuration> {\n adapter?: Type<PlatformAdapter<App>>;\n}\n\nregisterProvider({\n provide: PlatformAdapter,\n deps: [InjectorService],\n useClass: FakeAdapter\n});\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { Injectable, ProviderScope } from "@tsed/di";
|
|
3
|
-
import {
|
|
4
|
-
import { PlatformRouter } from "./PlatformRouter.js";
|
|
2
|
+
import { Injectable, InjectorService, ProviderScope } from "@tsed/di";
|
|
3
|
+
import { PlatformRouter } from "@tsed/platform-router";
|
|
5
4
|
import { PlatformAdapter } from "./PlatformAdapter.js";
|
|
6
5
|
/**
|
|
7
6
|
* `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.
|
|
@@ -9,23 +8,36 @@ import { PlatformAdapter } from "./PlatformAdapter.js";
|
|
|
9
8
|
* @platform
|
|
10
9
|
*/
|
|
11
10
|
let PlatformApplication = class PlatformApplication extends PlatformRouter {
|
|
12
|
-
|
|
11
|
+
adapter;
|
|
12
|
+
injector;
|
|
13
13
|
rawApp;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
rawCallback;
|
|
15
|
+
constructor(adapter, injector) {
|
|
16
|
+
super(injector);
|
|
17
|
+
this.adapter = adapter;
|
|
18
|
+
this.injector = injector;
|
|
16
19
|
const { app, callback } = adapter.app();
|
|
17
|
-
this.rawApp =
|
|
18
|
-
this.
|
|
20
|
+
this.rawApp = app;
|
|
21
|
+
this.rawCallback = callback;
|
|
19
22
|
}
|
|
20
23
|
getApp() {
|
|
21
|
-
return this.
|
|
24
|
+
return this.rawApp;
|
|
25
|
+
}
|
|
26
|
+
multer(options) {
|
|
27
|
+
return this.adapter.multipart(options);
|
|
28
|
+
}
|
|
29
|
+
callback(req, res) {
|
|
30
|
+
if (req && res) {
|
|
31
|
+
return this.callback()(req, res);
|
|
32
|
+
}
|
|
33
|
+
return this.rawCallback();
|
|
22
34
|
}
|
|
23
35
|
};
|
|
24
36
|
PlatformApplication = __decorate([
|
|
25
37
|
Injectable({
|
|
26
38
|
scope: ProviderScope.SINGLETON
|
|
27
39
|
}),
|
|
28
|
-
__metadata("design:paramtypes", [
|
|
40
|
+
__metadata("design:paramtypes", [PlatformAdapter, InjectorService])
|
|
29
41
|
], PlatformApplication);
|
|
30
42
|
export { PlatformApplication };
|
|
31
43
|
//# sourceMappingURL=PlatformApplication.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,eAAe,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAGrD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AASlD;;;;GAIG;AAIH,IAAa,mBAAmB,GAAhC,MAAa,mBAA4C,SAAQ,cAAc;IAI1D;IAAsC;IAHzD,MAAM,CAAM;IACZ,WAAW,CAAY;IAEvB,YAAmB,OAA6B,EAAS,QAAyB;QAChF,KAAK,CAAC,QAAQ,CAAC,CAAC;QADC,YAAO,GAAP,OAAO,CAAsB;QAAS,aAAQ,GAAR,QAAQ,CAAiB;QAEhF,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,OAA+B;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAID,QAAQ,CAAC,GAAqB,EAAE,GAAoB;QAClD,IAAI,GAAG,IAAI,GAAG,EAAE;YACd,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SAClC;QAED,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;CACF,CAAA;AA7BY,mBAAmB;IAH/B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAK4B,eAAe,EAAwB,eAAe;GAJvE,mBAAmB,CA6B/B;SA7BY,mBAAmB","sourcesContent":["import {Injectable, InjectorService, ProviderScope} from \"@tsed/di\";\nimport {PlatformRouter} from \"@tsed/platform-router\";\nimport {IncomingMessage, ServerResponse} from \"http\";\nimport {PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Application {}\n }\n}\n\n/**\n * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformApplication<App = TsED.Application> extends PlatformRouter {\n rawApp: App;\n rawCallback: () => any;\n\n constructor(public adapter: PlatformAdapter<App>, public injector: InjectorService) {\n super(injector);\n const {app, callback} = adapter.app();\n\n this.rawApp = app;\n this.rawCallback = callback;\n }\n\n getApp(): App {\n return this.rawApp;\n }\n\n multer(options: PlatformMulterSettings) {\n return this.adapter.multipart(options);\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => any;\n callback(req: IncomingMessage, res: ServerResponse): any;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.callback()(req, res);\n }\n\n return this.rawCallback();\n }\n}\n"]}
|
|
@@ -1,235 +1,159 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { AnyToPromiseStatus, isFunction, isStream } from "@tsed/core";
|
|
3
|
-
import { Inject, Injectable,
|
|
2
|
+
import { AnyToPromiseStatus, catchAsyncError, isFunction, isStream } from "@tsed/core";
|
|
3
|
+
import { Inject, Injectable, ProviderScope } from "@tsed/di";
|
|
4
4
|
import { $log } from "@tsed/logger";
|
|
5
5
|
import { PlatformParams } from "@tsed/platform-params";
|
|
6
6
|
import { PlatformResponseFilter } from "@tsed/platform-response-filter";
|
|
7
|
+
import { PlatformHandlerMetadata, PlatformHandlerType, PlatformRouters } from "@tsed/platform-router";
|
|
8
|
+
import { promisify } from "util";
|
|
7
9
|
import { AnyToPromiseWithCtx } from "../domain/AnyToPromiseWithCtx.js";
|
|
8
|
-
import { HandlerMetadata } from "../domain/HandlerMetadata.js";
|
|
9
|
-
import { HandlerType } from "../interfaces/HandlerType.js";
|
|
10
|
-
import { createHandlerMetadata } from "../utils/createHandlerMetadata.js";
|
|
11
10
|
import { setResponseHeaders } from "../utils/setResponseHeaders.js";
|
|
12
11
|
/**
|
|
13
12
|
* Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
|
|
14
13
|
* @platform
|
|
15
14
|
*/
|
|
16
15
|
let PlatformHandler = class PlatformHandler {
|
|
17
|
-
injector;
|
|
18
|
-
params;
|
|
19
16
|
responseFilter;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
createHandler(input, options = {}) {
|
|
30
|
-
return this.createRawHandler(createHandlerMetadata(this.injector, input, options));
|
|
17
|
+
platformRouters;
|
|
18
|
+
platformParams;
|
|
19
|
+
createHandler(handler, handlerMetadata) {
|
|
20
|
+
return async ($ctx) => {
|
|
21
|
+
$ctx.handlerMetadata = handlerMetadata;
|
|
22
|
+
const error = await catchAsyncError(() => this.onRequest(handler, $ctx));
|
|
23
|
+
return this.next(error, $ctx.next, $ctx);
|
|
24
|
+
};
|
|
31
25
|
}
|
|
32
26
|
/**
|
|
33
|
-
* Create injectable handler from the given provider
|
|
34
27
|
* @param provider
|
|
35
28
|
* @param propertyKey
|
|
36
29
|
*/
|
|
37
30
|
createCustomHandler(provider, propertyKey) {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
type: HandlerType.CUSTOM,
|
|
42
|
-
scope: provider.scope,
|
|
31
|
+
const metadata = new PlatformHandlerMetadata({
|
|
32
|
+
provider,
|
|
33
|
+
type: PlatformHandlerType.CUSTOM,
|
|
43
34
|
propertyKey
|
|
44
|
-
}));
|
|
45
|
-
return async ($ctx, next) => handler({
|
|
46
|
-
$ctx,
|
|
47
|
-
next
|
|
48
35
|
});
|
|
36
|
+
const handler = this.platformParams.compileHandler(metadata.store);
|
|
37
|
+
return async ($ctx) => {
|
|
38
|
+
$ctx.set(PlatformHandlerMetadata, metadata);
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
return this.onRequest(handler, $ctx);
|
|
41
|
+
};
|
|
49
42
|
}
|
|
50
43
|
/**
|
|
51
44
|
* Send the response to the consumer.
|
|
52
|
-
* @param data
|
|
53
|
-
* @param ctx
|
|
54
45
|
* @protected
|
|
46
|
+
* @param $ctx
|
|
55
47
|
*/
|
|
56
|
-
async flush(
|
|
57
|
-
const { response } = ctx;
|
|
48
|
+
async flush($ctx) {
|
|
49
|
+
const { response } = $ctx;
|
|
58
50
|
if (!response.isDone()) {
|
|
59
|
-
data = await this.responseFilter.serialize(data, ctx);
|
|
60
|
-
data = await this.responseFilter.transform(data, ctx);
|
|
51
|
+
let data = await this.responseFilter.serialize($ctx.data, $ctx);
|
|
52
|
+
data = await this.responseFilter.transform(data, $ctx);
|
|
61
53
|
response.body(data);
|
|
62
54
|
}
|
|
55
|
+
return response;
|
|
63
56
|
}
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
return this.onCtxRequest({
|
|
69
|
-
...scope,
|
|
70
|
-
handler: () => metadata.handler(scope.$ctx),
|
|
71
|
-
metadata
|
|
72
|
-
});
|
|
73
|
-
};
|
|
57
|
+
setResponseHeaders($ctx) {
|
|
58
|
+
if (!$ctx.response.isDone()) {
|
|
59
|
+
return setResponseHeaders($ctx);
|
|
74
60
|
}
|
|
75
|
-
const promise = this.params.compileHandler({
|
|
76
|
-
token: metadata.token,
|
|
77
|
-
propertyKey: metadata.propertyKey,
|
|
78
|
-
getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)
|
|
79
|
-
});
|
|
80
|
-
return async (scope) => {
|
|
81
|
-
const handler = await promise;
|
|
82
|
-
// @ts-ignore
|
|
83
|
-
return this.onRequest({
|
|
84
|
-
...scope,
|
|
85
|
-
handler,
|
|
86
|
-
metadata
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
61
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
62
|
+
/**
|
|
63
|
+
* @param error
|
|
64
|
+
* @param next
|
|
65
|
+
* @param $ctx
|
|
66
|
+
*/
|
|
67
|
+
next(error, next, $ctx) {
|
|
68
|
+
if (isStream($ctx.data) || $ctx.isDone()) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
return error ? next(error) : next();
|
|
93
72
|
}
|
|
94
73
|
/**
|
|
95
74
|
* Call handler when a request his handle
|
|
96
|
-
* @param requestOptions
|
|
97
75
|
*/
|
|
98
|
-
async onRequest(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!$ctx || $ctx.isDone()) {
|
|
76
|
+
async onRequest(handler, $ctx) {
|
|
77
|
+
// istanbul ignore next$
|
|
78
|
+
if ($ctx.isDone()) {
|
|
102
79
|
$log.error({
|
|
103
80
|
name: "HEADERS_SENT",
|
|
104
|
-
message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${
|
|
81
|
+
message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${$ctx.handlerMetadata.toString()}`
|
|
105
82
|
});
|
|
106
83
|
return;
|
|
107
84
|
}
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (state === AnyToPromiseStatus.RESOLVED) {
|
|
113
|
-
if (status) {
|
|
114
|
-
$ctx.response.status(status);
|
|
115
|
-
}
|
|
116
|
-
if (headers) {
|
|
117
|
-
$ctx.response.setHeaders(headers);
|
|
118
|
-
}
|
|
119
|
-
if (data !== undefined) {
|
|
120
|
-
$ctx.data = data;
|
|
121
|
-
}
|
|
122
|
-
// Can be canceled by the handler itself
|
|
123
|
-
return await this.onSuccess($ctx.data, requestOptions);
|
|
124
|
-
}
|
|
85
|
+
try {
|
|
86
|
+
const { handlerMetadata } = $ctx;
|
|
87
|
+
if (handlerMetadata.type === PlatformHandlerType.CTX_FN) {
|
|
88
|
+
return await handler({ $ctx });
|
|
125
89
|
}
|
|
126
|
-
|
|
127
|
-
|
|
90
|
+
const resolver = new AnyToPromiseWithCtx($ctx);
|
|
91
|
+
const { state, data, status, headers } = await resolver.call(handler);
|
|
92
|
+
// Note: restore previous handler metadata (for OIDC)
|
|
93
|
+
$ctx.handlerMetadata = handlerMetadata;
|
|
94
|
+
if (state === AnyToPromiseStatus.RESOLVED) {
|
|
95
|
+
if (status) {
|
|
96
|
+
$ctx.response.status(status);
|
|
97
|
+
}
|
|
98
|
+
if (headers) {
|
|
99
|
+
$ctx.response.setHeaders(headers);
|
|
100
|
+
}
|
|
101
|
+
if (data !== undefined) {
|
|
102
|
+
$ctx.data = data;
|
|
103
|
+
}
|
|
104
|
+
// Can be canceled by the handler itself
|
|
105
|
+
return await this.onSuccess($ctx);
|
|
128
106
|
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
async onError(er, requestOptions) {
|
|
132
|
-
const { next, $ctx, metadata } = requestOptions;
|
|
133
|
-
if ($ctx) {
|
|
134
|
-
$ctx.data = er;
|
|
135
107
|
}
|
|
136
|
-
|
|
137
|
-
|
|
108
|
+
catch (error) {
|
|
109
|
+
return this.onError(error, $ctx);
|
|
138
110
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,
|
|
144
|
-
stack: er.stack,
|
|
145
|
-
origin: er,
|
|
146
|
-
request_id: $ctx?.id
|
|
147
|
-
});
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
return next(er);
|
|
111
|
+
}
|
|
112
|
+
async onError(error, $ctx) {
|
|
113
|
+
$ctx.error = error;
|
|
114
|
+
throw error;
|
|
151
115
|
}
|
|
152
116
|
/**
|
|
153
117
|
* Manage success scenario
|
|
154
|
-
* @param
|
|
155
|
-
* @param requestOptions
|
|
118
|
+
* @param $ctx
|
|
156
119
|
* @protected
|
|
157
120
|
*/
|
|
158
|
-
async onSuccess(
|
|
159
|
-
const { metadata, $ctx, next } = requestOptions;
|
|
121
|
+
async onSuccess($ctx) {
|
|
160
122
|
// istanbul ignore next
|
|
161
|
-
if ($ctx
|
|
123
|
+
if ($ctx.isDone()) {
|
|
162
124
|
return;
|
|
163
125
|
}
|
|
126
|
+
$ctx.error = null;
|
|
127
|
+
const metadata = $ctx.handlerMetadata;
|
|
164
128
|
// set headers each times that an endpoint is called
|
|
165
|
-
if (metadata.
|
|
166
|
-
this.
|
|
129
|
+
if (metadata.isEndpoint()) {
|
|
130
|
+
this.setResponseHeaders($ctx);
|
|
167
131
|
}
|
|
168
132
|
// call returned middleware
|
|
169
|
-
if (isFunction(data) && !isStream(data)) {
|
|
170
|
-
return
|
|
133
|
+
if (isFunction($ctx.data) && !isStream($ctx.data)) {
|
|
134
|
+
return promisify($ctx.data)($ctx.getRequest(), $ctx.getResponse());
|
|
171
135
|
}
|
|
172
136
|
if (metadata.isFinal()) {
|
|
173
|
-
return this.flush(
|
|
174
|
-
}
|
|
175
|
-
return this.next(requestOptions);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Call the returned middleware by the handler.
|
|
179
|
-
* @param middleware
|
|
180
|
-
* @param ctx
|
|
181
|
-
* @param next
|
|
182
|
-
* @protected
|
|
183
|
-
*/
|
|
184
|
-
callReturnedMiddleware(middleware, ctx, next) {
|
|
185
|
-
return middleware(ctx.getRequest(), ctx.getResponse(), next);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* create Raw handler
|
|
189
|
-
* @param metadata
|
|
190
|
-
*/
|
|
191
|
-
createRawHandler(metadata) {
|
|
192
|
-
if ([HandlerType.RAW_ERR_FN, HandlerType.RAW_FN].includes(metadata.type)) {
|
|
193
|
-
return metadata.handler;
|
|
137
|
+
return this.flush($ctx);
|
|
194
138
|
}
|
|
195
|
-
const handler = this.compileHandler(metadata);
|
|
196
|
-
return async (request, response, next) => {
|
|
197
|
-
return handler({
|
|
198
|
-
next,
|
|
199
|
-
$ctx: request.$ctx
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Set response headers
|
|
205
|
-
* @param ctx
|
|
206
|
-
* @protected
|
|
207
|
-
*/
|
|
208
|
-
setHeaders(ctx) {
|
|
209
|
-
return setResponseHeaders(ctx);
|
|
210
|
-
}
|
|
211
|
-
next(requestOptions) {
|
|
212
|
-
const { $ctx, next } = requestOptions;
|
|
213
|
-
return !$ctx.response.isDone() && next && next();
|
|
214
|
-
}
|
|
215
|
-
getDefaultArgs(metadata) {
|
|
216
|
-
return async (scope) => [
|
|
217
|
-
metadata.hasErrorParam && scope.err,
|
|
218
|
-
scope.$ctx.request.request,
|
|
219
|
-
scope.$ctx.response.response,
|
|
220
|
-
metadata.hasNextFunction && scope.next
|
|
221
|
-
].filter(Boolean);
|
|
222
139
|
}
|
|
223
140
|
};
|
|
224
141
|
__decorate([
|
|
225
142
|
Inject(),
|
|
226
143
|
__metadata("design:type", PlatformResponseFilter)
|
|
227
144
|
], PlatformHandler.prototype, "responseFilter", void 0);
|
|
145
|
+
__decorate([
|
|
146
|
+
Inject(),
|
|
147
|
+
__metadata("design:type", PlatformRouters)
|
|
148
|
+
], PlatformHandler.prototype, "platformRouters", void 0);
|
|
149
|
+
__decorate([
|
|
150
|
+
Inject(),
|
|
151
|
+
__metadata("design:type", PlatformParams)
|
|
152
|
+
], PlatformHandler.prototype, "platformParams", void 0);
|
|
228
153
|
PlatformHandler = __decorate([
|
|
229
154
|
Injectable({
|
|
230
155
|
scope: ProviderScope.SINGLETON
|
|
231
|
-
})
|
|
232
|
-
__metadata("design:paramtypes", [InjectorService, PlatformParams])
|
|
156
|
+
})
|
|
233
157
|
], PlatformHandler);
|
|
234
158
|
export { PlatformHandler };
|
|
235
159
|
//# sourceMappingURL=PlatformHandler.js.map
|