@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
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Platform = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
|
-
const
|
|
7
|
-
const PlatformControllerBuilder_1 = require("../builder/PlatformControllerBuilder");
|
|
8
|
-
const PlatformRouteDetails_1 = require("../domain/PlatformRouteDetails");
|
|
6
|
+
const platform_router_1 = require("@tsed/platform-router");
|
|
9
7
|
const PlatformApplication_1 = require("./PlatformApplication");
|
|
8
|
+
const PlatformHandler_1 = require("./PlatformHandler");
|
|
10
9
|
const PlatformMiddlewaresChain_1 = require("./PlatformMiddlewaresChain");
|
|
11
10
|
/**
|
|
12
11
|
* `Platform` is used to provide all routes collected by annotation `@Controller`.
|
|
@@ -16,115 +15,72 @@ const PlatformMiddlewaresChain_1 = require("./PlatformMiddlewaresChain");
|
|
|
16
15
|
let Platform = class Platform {
|
|
17
16
|
injector;
|
|
18
17
|
platformApplication;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
platformRouters;
|
|
19
|
+
platformHandler;
|
|
20
|
+
platformMiddlewaresChain;
|
|
21
|
+
#controllers = new Map();
|
|
22
|
+
constructor(injector, platformApplication, platformRouters, platformHandler, platformMiddlewaresChain) {
|
|
22
23
|
this.injector = injector;
|
|
23
24
|
this.platformApplication = platformApplication;
|
|
24
|
-
this.
|
|
25
|
+
this.platformRouters = platformRouters;
|
|
26
|
+
this.platformHandler = platformHandler;
|
|
27
|
+
this.platformMiddlewaresChain = platformMiddlewaresChain;
|
|
28
|
+
// configure the router module
|
|
29
|
+
platformRouters.hooks
|
|
30
|
+
.on("alterEndpointHandlers", platformMiddlewaresChain.get.bind(platformMiddlewaresChain))
|
|
31
|
+
.on("alterHandler", (handler, handlerMetadata) => {
|
|
32
|
+
handler = handlerMetadata.isRawMiddleware() ? handler : this.platformHandler.createHandler(handler, handlerMetadata);
|
|
33
|
+
return platformApplication.adapter.mapHandler(handler, handlerMetadata);
|
|
34
|
+
});
|
|
35
|
+
platformRouters.prebuild();
|
|
25
36
|
}
|
|
26
37
|
get app() {
|
|
27
38
|
return this.platformApplication;
|
|
28
39
|
}
|
|
29
|
-
get routes() {
|
|
30
|
-
return this._routes;
|
|
31
|
-
}
|
|
32
40
|
addRoutes(routes) {
|
|
33
41
|
routes.forEach((routeSettings) => {
|
|
34
42
|
this.addRoute(routeSettings.route, routeSettings.token);
|
|
35
43
|
});
|
|
36
44
|
}
|
|
37
|
-
addRoute(
|
|
38
|
-
const
|
|
39
|
-
const provider = injector.getProvider(token);
|
|
45
|
+
addRoute(route, token) {
|
|
46
|
+
const provider = this.injector.getProvider(token);
|
|
40
47
|
if (!provider || provider.hasParent()) {
|
|
41
|
-
return;
|
|
48
|
+
return this;
|
|
42
49
|
}
|
|
43
|
-
this.
|
|
44
|
-
|
|
45
|
-
this.app.use(ctrlPath, ...[].concat((0, PlatformControllerBuilder_1.getRouter)(injector, provider).callback()));
|
|
46
|
-
this._routes = (0, schema_1.getOperationsRoutes)(provider.token, {
|
|
47
|
-
withChildren: true,
|
|
48
|
-
basePath
|
|
49
|
-
}).reduce((routes, operationRoute) => {
|
|
50
|
-
if (injector.hasProvider(token)) {
|
|
51
|
-
const provider = injector.getProvider(operationRoute.token);
|
|
52
|
-
const route = new PlatformRouteDetails_1.PlatformRouteDetails({
|
|
53
|
-
...operationRoute,
|
|
54
|
-
provider
|
|
55
|
-
});
|
|
56
|
-
routes = routes.concat(route);
|
|
57
|
-
}
|
|
58
|
-
return routes;
|
|
59
|
-
}, this._routes);
|
|
50
|
+
const router = this.platformRouters.from(provider.token);
|
|
51
|
+
this.app.use(route, router);
|
|
60
52
|
return this;
|
|
61
53
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
getLayers() {
|
|
55
|
+
this.#controllers = new Map();
|
|
56
|
+
return this.platformRouters.getLayers(this.app).map((layer) => {
|
|
57
|
+
if (layer.isProvider()) {
|
|
58
|
+
this.#controllers.set(layer.provider.token, {
|
|
59
|
+
route: String(layer.path).split(layer.provider.path)[0],
|
|
60
|
+
provider: layer.provider
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return layer;
|
|
64
|
+
});
|
|
68
65
|
}
|
|
69
66
|
/**
|
|
70
67
|
* Get all controllers mounted on the application.
|
|
71
68
|
* @returns {RouteController[]}
|
|
72
69
|
*/
|
|
73
70
|
getMountedControllers() {
|
|
74
|
-
return this.
|
|
75
|
-
}
|
|
76
|
-
$onInit() {
|
|
77
|
-
this.buildControllers();
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Create routers from the collected controllers.
|
|
81
|
-
* @private
|
|
82
|
-
*/
|
|
83
|
-
createRouters() {
|
|
84
|
-
const { injector } = this;
|
|
85
|
-
injector.getProviders(di_1.ProviderType.CONTROLLER).map((provider) => {
|
|
86
|
-
(0, PlatformControllerBuilder_1.createRouter)(injector, provider);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Get all router controllers from the controller token.
|
|
91
|
-
* @private
|
|
92
|
-
*/
|
|
93
|
-
getAllControllers(basePath, token) {
|
|
94
|
-
const store = token.isStore ? token : (0, schema_1.getJsonEntityStore)(token);
|
|
95
|
-
const ctrlPath = (0, schema_1.concatPath)(basePath, schema_1.JsonEntityStore.from(token).path);
|
|
96
|
-
const children = store.get("childrenControllers", []);
|
|
97
|
-
return children
|
|
98
|
-
.reduce((controllers, token) => {
|
|
99
|
-
const childBasePath = (0, schema_1.concatPath)(basePath, store.path);
|
|
100
|
-
return controllers.concat(this.getAllControllers(childBasePath, token));
|
|
101
|
-
}, [])
|
|
102
|
-
.concat([
|
|
103
|
-
{
|
|
104
|
-
route: ctrlPath,
|
|
105
|
-
provider: this.injector.getProvider(token)
|
|
106
|
-
}
|
|
107
|
-
]);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Create controllers from DI
|
|
111
|
-
* @private
|
|
112
|
-
*/
|
|
113
|
-
buildControllers() {
|
|
114
|
-
const { injector } = this;
|
|
115
|
-
injector.getProviders(di_1.ProviderType.CONTROLLER).map((provider) => {
|
|
116
|
-
if (!provider.hasParent()) {
|
|
117
|
-
return (0, PlatformControllerBuilder_1.buildRouter)(injector, provider);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
71
|
+
return [...this.#controllers.values()];
|
|
120
72
|
}
|
|
121
73
|
};
|
|
122
74
|
Platform = tslib_1.__decorate([
|
|
123
75
|
(0, di_1.Injectable)({
|
|
124
76
|
scope: di_1.ProviderScope.SINGLETON,
|
|
125
|
-
imports: [
|
|
77
|
+
imports: []
|
|
126
78
|
}),
|
|
127
|
-
tslib_1.__metadata("design:paramtypes", [di_1.InjectorService,
|
|
79
|
+
tslib_1.__metadata("design:paramtypes", [di_1.InjectorService,
|
|
80
|
+
PlatformApplication_1.PlatformApplication,
|
|
81
|
+
platform_router_1.PlatformRouters,
|
|
82
|
+
PlatformHandler_1.PlatformHandler,
|
|
83
|
+
PlatformMiddlewaresChain_1.PlatformMiddlewaresChain])
|
|
128
84
|
], Platform);
|
|
129
85
|
exports.Platform = Platform;
|
|
130
86
|
//# 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":"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","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,iCAAyE;
|
|
1
|
+
{"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":";;;AACA,iCAAyE;AAKzE,+CAA0C;AAE1C,MAAsB,eAAe;IACnC;;OAEG;IACH,SAAS,CAAiB;IAC1B;;OAEG;IACH,MAAM,CAAa;IACnB,gBAAgB,CAAsB;IACtC,eAAe,CAAsB;CAsCtC;AAhDD,0CAgDC;AAMD,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,oBAAe,CAAC;IACvB,QAAQ,EAAE,yBAAW;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"]}
|
|
@@ -3,32 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PlatformApplication = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
|
-
const
|
|
7
|
-
const PlatformRouter_1 = require("./PlatformRouter");
|
|
6
|
+
const platform_router_1 = require("@tsed/platform-router");
|
|
8
7
|
const PlatformAdapter_1 = require("./PlatformAdapter");
|
|
9
8
|
/**
|
|
10
9
|
* `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.
|
|
11
10
|
*
|
|
12
11
|
* @platform
|
|
13
12
|
*/
|
|
14
|
-
let PlatformApplication = class PlatformApplication extends
|
|
15
|
-
|
|
13
|
+
let PlatformApplication = class PlatformApplication extends platform_router_1.PlatformRouter {
|
|
14
|
+
adapter;
|
|
15
|
+
injector;
|
|
16
16
|
rawApp;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
rawCallback;
|
|
18
|
+
constructor(adapter, injector) {
|
|
19
|
+
super(injector);
|
|
20
|
+
this.adapter = adapter;
|
|
21
|
+
this.injector = injector;
|
|
19
22
|
const { app, callback } = adapter.app();
|
|
20
|
-
this.rawApp =
|
|
21
|
-
this.
|
|
23
|
+
this.rawApp = app;
|
|
24
|
+
this.rawCallback = callback;
|
|
22
25
|
}
|
|
23
26
|
getApp() {
|
|
24
|
-
return this.
|
|
27
|
+
return this.rawApp;
|
|
28
|
+
}
|
|
29
|
+
multer(options) {
|
|
30
|
+
return this.adapter.multipart(options);
|
|
31
|
+
}
|
|
32
|
+
callback(req, res) {
|
|
33
|
+
if (req && res) {
|
|
34
|
+
return this.callback()(req, res);
|
|
35
|
+
}
|
|
36
|
+
return this.rawCallback();
|
|
25
37
|
}
|
|
26
38
|
};
|
|
27
39
|
PlatformApplication = tslib_1.__decorate([
|
|
28
40
|
(0, di_1.Injectable)({
|
|
29
41
|
scope: di_1.ProviderScope.SINGLETON
|
|
30
42
|
}),
|
|
31
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
43
|
+
tslib_1.__metadata("design:paramtypes", [PlatformAdapter_1.PlatformAdapter, di_1.InjectorService])
|
|
32
44
|
], PlatformApplication);
|
|
33
45
|
exports.PlatformApplication = PlatformApplication;
|
|
34
46
|
//# sourceMappingURL=PlatformApplication.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";;;;AAAA,iCAAoE;AACpE,2DAAqD;AAGrD,uDAAkD;AASlD;;;;GAIG;AAIH,IAAa,mBAAmB,GAAhC,MAAa,mBAA4C,SAAQ,gCAAc;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,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;KAC/B,CAAC;6CAK4B,iCAAe,EAAwB,oBAAe;GAJvE,mBAAmB,CA6B/B;AA7BY,kDAAmB","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"]}
|
|
@@ -7,232 +7,156 @@ const di_1 = require("@tsed/di");
|
|
|
7
7
|
const logger_1 = require("@tsed/logger");
|
|
8
8
|
const platform_params_1 = require("@tsed/platform-params");
|
|
9
9
|
const platform_response_filter_1 = require("@tsed/platform-response-filter");
|
|
10
|
+
const platform_router_1 = require("@tsed/platform-router");
|
|
11
|
+
const util_1 = require("util");
|
|
10
12
|
const AnyToPromiseWithCtx_1 = require("../domain/AnyToPromiseWithCtx");
|
|
11
|
-
const HandlerMetadata_1 = require("../domain/HandlerMetadata");
|
|
12
|
-
const HandlerType_1 = require("../interfaces/HandlerType");
|
|
13
|
-
const createHandlerMetadata_1 = require("../utils/createHandlerMetadata");
|
|
14
13
|
const setResponseHeaders_1 = require("../utils/setResponseHeaders");
|
|
15
14
|
/**
|
|
16
15
|
* Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
|
|
17
16
|
* @platform
|
|
18
17
|
*/
|
|
19
18
|
let PlatformHandler = class PlatformHandler {
|
|
20
|
-
injector;
|
|
21
|
-
params;
|
|
22
19
|
responseFilter;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
createHandler(input, options = {}) {
|
|
33
|
-
return this.createRawHandler((0, createHandlerMetadata_1.createHandlerMetadata)(this.injector, input, options));
|
|
20
|
+
platformRouters;
|
|
21
|
+
platformParams;
|
|
22
|
+
createHandler(handler, handlerMetadata) {
|
|
23
|
+
return async ($ctx) => {
|
|
24
|
+
$ctx.handlerMetadata = handlerMetadata;
|
|
25
|
+
const error = await (0, core_1.catchAsyncError)(() => this.onRequest(handler, $ctx));
|
|
26
|
+
return this.next(error, $ctx.next, $ctx);
|
|
27
|
+
};
|
|
34
28
|
}
|
|
35
29
|
/**
|
|
36
|
-
* Create injectable handler from the given provider
|
|
37
30
|
* @param provider
|
|
38
31
|
* @param propertyKey
|
|
39
32
|
*/
|
|
40
33
|
createCustomHandler(provider, propertyKey) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type: HandlerType_1.HandlerType.CUSTOM,
|
|
45
|
-
scope: provider.scope,
|
|
34
|
+
const metadata = new platform_router_1.PlatformHandlerMetadata({
|
|
35
|
+
provider,
|
|
36
|
+
type: platform_router_1.PlatformHandlerType.CUSTOM,
|
|
46
37
|
propertyKey
|
|
47
|
-
}));
|
|
48
|
-
return async ($ctx, next) => handler({
|
|
49
|
-
$ctx,
|
|
50
|
-
next
|
|
51
38
|
});
|
|
39
|
+
const handler = this.platformParams.compileHandler(metadata.store);
|
|
40
|
+
return async ($ctx) => {
|
|
41
|
+
$ctx.set(platform_router_1.PlatformHandlerMetadata, metadata);
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
return this.onRequest(handler, $ctx);
|
|
44
|
+
};
|
|
52
45
|
}
|
|
53
46
|
/**
|
|
54
47
|
* Send the response to the consumer.
|
|
55
|
-
* @param data
|
|
56
|
-
* @param ctx
|
|
57
48
|
* @protected
|
|
49
|
+
* @param $ctx
|
|
58
50
|
*/
|
|
59
|
-
async flush(
|
|
60
|
-
const { response } = ctx;
|
|
51
|
+
async flush($ctx) {
|
|
52
|
+
const { response } = $ctx;
|
|
61
53
|
if (!response.isDone()) {
|
|
62
|
-
data = await this.responseFilter.serialize(data, ctx);
|
|
63
|
-
data = await this.responseFilter.transform(data, ctx);
|
|
54
|
+
let data = await this.responseFilter.serialize($ctx.data, $ctx);
|
|
55
|
+
data = await this.responseFilter.transform(data, $ctx);
|
|
64
56
|
response.body(data);
|
|
65
57
|
}
|
|
58
|
+
return response;
|
|
66
59
|
}
|
|
67
|
-
|
|
68
|
-
if (
|
|
69
|
-
return
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
return this.onCtxRequest({
|
|
72
|
-
...scope,
|
|
73
|
-
handler: () => metadata.handler(scope.$ctx),
|
|
74
|
-
metadata
|
|
75
|
-
});
|
|
76
|
-
};
|
|
60
|
+
setResponseHeaders($ctx) {
|
|
61
|
+
if (!$ctx.response.isDone()) {
|
|
62
|
+
return (0, setResponseHeaders_1.setResponseHeaders)($ctx);
|
|
77
63
|
}
|
|
78
|
-
const promise = this.params.compileHandler({
|
|
79
|
-
token: metadata.token,
|
|
80
|
-
propertyKey: metadata.propertyKey,
|
|
81
|
-
getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)
|
|
82
|
-
});
|
|
83
|
-
return async (scope) => {
|
|
84
|
-
const handler = await promise;
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
return this.onRequest({
|
|
87
|
-
...scope,
|
|
88
|
-
handler,
|
|
89
|
-
metadata
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
64
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
65
|
+
/**
|
|
66
|
+
* @param error
|
|
67
|
+
* @param next
|
|
68
|
+
* @param $ctx
|
|
69
|
+
*/
|
|
70
|
+
next(error, next, $ctx) {
|
|
71
|
+
if ((0, core_1.isStream)($ctx.data) || $ctx.isDone()) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return error ? next(error) : next();
|
|
96
75
|
}
|
|
97
76
|
/**
|
|
98
77
|
* Call handler when a request his handle
|
|
99
|
-
* @param requestOptions
|
|
100
78
|
*/
|
|
101
|
-
async onRequest(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!$ctx || $ctx.isDone()) {
|
|
79
|
+
async onRequest(handler, $ctx) {
|
|
80
|
+
// istanbul ignore next$
|
|
81
|
+
if ($ctx.isDone()) {
|
|
105
82
|
logger_1.$log.error({
|
|
106
83
|
name: "HEADERS_SENT",
|
|
107
|
-
message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${
|
|
84
|
+
message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${$ctx.handlerMetadata.toString()}`
|
|
108
85
|
});
|
|
109
86
|
return;
|
|
110
87
|
}
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (state === core_1.AnyToPromiseStatus.RESOLVED) {
|
|
116
|
-
if (status) {
|
|
117
|
-
$ctx.response.status(status);
|
|
118
|
-
}
|
|
119
|
-
if (headers) {
|
|
120
|
-
$ctx.response.setHeaders(headers);
|
|
121
|
-
}
|
|
122
|
-
if (data !== undefined) {
|
|
123
|
-
$ctx.data = data;
|
|
124
|
-
}
|
|
125
|
-
// Can be canceled by the handler itself
|
|
126
|
-
return await this.onSuccess($ctx.data, requestOptions);
|
|
127
|
-
}
|
|
88
|
+
try {
|
|
89
|
+
const { handlerMetadata } = $ctx;
|
|
90
|
+
if (handlerMetadata.type === platform_router_1.PlatformHandlerType.CTX_FN) {
|
|
91
|
+
return await handler({ $ctx });
|
|
128
92
|
}
|
|
129
|
-
|
|
130
|
-
|
|
93
|
+
const resolver = new AnyToPromiseWithCtx_1.AnyToPromiseWithCtx($ctx);
|
|
94
|
+
const { state, data, status, headers } = await resolver.call(handler);
|
|
95
|
+
// Note: restore previous handler metadata (for OIDC)
|
|
96
|
+
$ctx.handlerMetadata = handlerMetadata;
|
|
97
|
+
if (state === core_1.AnyToPromiseStatus.RESOLVED) {
|
|
98
|
+
if (status) {
|
|
99
|
+
$ctx.response.status(status);
|
|
100
|
+
}
|
|
101
|
+
if (headers) {
|
|
102
|
+
$ctx.response.setHeaders(headers);
|
|
103
|
+
}
|
|
104
|
+
if (data !== undefined) {
|
|
105
|
+
$ctx.data = data;
|
|
106
|
+
}
|
|
107
|
+
// Can be canceled by the handler itself
|
|
108
|
+
return await this.onSuccess($ctx);
|
|
131
109
|
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
async onError(er, requestOptions) {
|
|
135
|
-
const { next, $ctx, metadata } = requestOptions;
|
|
136
|
-
if ($ctx) {
|
|
137
|
-
$ctx.data = er;
|
|
138
110
|
}
|
|
139
|
-
|
|
140
|
-
|
|
111
|
+
catch (error) {
|
|
112
|
+
return this.onError(error, $ctx);
|
|
141
113
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,
|
|
147
|
-
stack: er.stack,
|
|
148
|
-
origin: er,
|
|
149
|
-
request_id: $ctx?.id
|
|
150
|
-
});
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
return next(er);
|
|
114
|
+
}
|
|
115
|
+
async onError(error, $ctx) {
|
|
116
|
+
$ctx.error = error;
|
|
117
|
+
throw error;
|
|
154
118
|
}
|
|
155
119
|
/**
|
|
156
120
|
* Manage success scenario
|
|
157
|
-
* @param
|
|
158
|
-
* @param requestOptions
|
|
121
|
+
* @param $ctx
|
|
159
122
|
* @protected
|
|
160
123
|
*/
|
|
161
|
-
async onSuccess(
|
|
162
|
-
const { metadata, $ctx, next } = requestOptions;
|
|
124
|
+
async onSuccess($ctx) {
|
|
163
125
|
// istanbul ignore next
|
|
164
|
-
if ($ctx
|
|
126
|
+
if ($ctx.isDone()) {
|
|
165
127
|
return;
|
|
166
128
|
}
|
|
129
|
+
$ctx.error = null;
|
|
130
|
+
const metadata = $ctx.handlerMetadata;
|
|
167
131
|
// set headers each times that an endpoint is called
|
|
168
|
-
if (metadata.
|
|
169
|
-
this.
|
|
132
|
+
if (metadata.isEndpoint()) {
|
|
133
|
+
this.setResponseHeaders($ctx);
|
|
170
134
|
}
|
|
171
135
|
// call returned middleware
|
|
172
|
-
if ((0, core_1.isFunction)(data) && !(0, core_1.isStream)(data)) {
|
|
173
|
-
return
|
|
136
|
+
if ((0, core_1.isFunction)($ctx.data) && !(0, core_1.isStream)($ctx.data)) {
|
|
137
|
+
return (0, util_1.promisify)($ctx.data)($ctx.getRequest(), $ctx.getResponse());
|
|
174
138
|
}
|
|
175
139
|
if (metadata.isFinal()) {
|
|
176
|
-
return this.flush(
|
|
177
|
-
}
|
|
178
|
-
return this.next(requestOptions);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Call the returned middleware by the handler.
|
|
182
|
-
* @param middleware
|
|
183
|
-
* @param ctx
|
|
184
|
-
* @param next
|
|
185
|
-
* @protected
|
|
186
|
-
*/
|
|
187
|
-
callReturnedMiddleware(middleware, ctx, next) {
|
|
188
|
-
return middleware(ctx.getRequest(), ctx.getResponse(), next);
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* create Raw handler
|
|
192
|
-
* @param metadata
|
|
193
|
-
*/
|
|
194
|
-
createRawHandler(metadata) {
|
|
195
|
-
if ([HandlerType_1.HandlerType.RAW_ERR_FN, HandlerType_1.HandlerType.RAW_FN].includes(metadata.type)) {
|
|
196
|
-
return metadata.handler;
|
|
140
|
+
return this.flush($ctx);
|
|
197
141
|
}
|
|
198
|
-
const handler = this.compileHandler(metadata);
|
|
199
|
-
return async (request, response, next) => {
|
|
200
|
-
return handler({
|
|
201
|
-
next,
|
|
202
|
-
$ctx: request.$ctx
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Set response headers
|
|
208
|
-
* @param ctx
|
|
209
|
-
* @protected
|
|
210
|
-
*/
|
|
211
|
-
setHeaders(ctx) {
|
|
212
|
-
return (0, setResponseHeaders_1.setResponseHeaders)(ctx);
|
|
213
|
-
}
|
|
214
|
-
next(requestOptions) {
|
|
215
|
-
const { $ctx, next } = requestOptions;
|
|
216
|
-
return !$ctx.response.isDone() && next && next();
|
|
217
|
-
}
|
|
218
|
-
getDefaultArgs(metadata) {
|
|
219
|
-
return async (scope) => [
|
|
220
|
-
metadata.hasErrorParam && scope.err,
|
|
221
|
-
scope.$ctx.request.request,
|
|
222
|
-
scope.$ctx.response.response,
|
|
223
|
-
metadata.hasNextFunction && scope.next
|
|
224
|
-
].filter(Boolean);
|
|
225
142
|
}
|
|
226
143
|
};
|
|
227
144
|
tslib_1.__decorate([
|
|
228
145
|
(0, di_1.Inject)(),
|
|
229
146
|
tslib_1.__metadata("design:type", platform_response_filter_1.PlatformResponseFilter)
|
|
230
147
|
], PlatformHandler.prototype, "responseFilter", void 0);
|
|
148
|
+
tslib_1.__decorate([
|
|
149
|
+
(0, di_1.Inject)(),
|
|
150
|
+
tslib_1.__metadata("design:type", platform_router_1.PlatformRouters)
|
|
151
|
+
], PlatformHandler.prototype, "platformRouters", void 0);
|
|
152
|
+
tslib_1.__decorate([
|
|
153
|
+
(0, di_1.Inject)(),
|
|
154
|
+
tslib_1.__metadata("design:type", platform_params_1.PlatformParams)
|
|
155
|
+
], PlatformHandler.prototype, "platformParams", void 0);
|
|
231
156
|
PlatformHandler = tslib_1.__decorate([
|
|
232
157
|
(0, di_1.Injectable)({
|
|
233
158
|
scope: di_1.ProviderScope.SINGLETON
|
|
234
|
-
})
|
|
235
|
-
tslib_1.__metadata("design:paramtypes", [di_1.InjectorService, platform_params_1.PlatformParams])
|
|
159
|
+
})
|
|
236
160
|
], PlatformHandler);
|
|
237
161
|
exports.PlatformHandler = PlatformHandler;
|
|
238
162
|
//# sourceMappingURL=PlatformHandler.js.map
|