@tsed/common 7.0.0-beta.8 → 7.0.0-rc.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.
- package/coverage.json +6 -0
- package/jest.config.js +9 -0
- package/lib/cjs/builder/PlatformBuilder.js +86 -68
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/cjs/config/services/PlatformConfiguration.js +0 -64
- package/lib/cjs/config/services/PlatformConfiguration.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 +4 -5
- package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/cjs/domain/PlatformContext.js +46 -38
- package/lib/cjs/domain/PlatformContext.js.map +1 -1
- package/lib/cjs/domain/PlatformRouteDetails.js +0 -21
- package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/cjs/exports.js +1 -1
- package/lib/cjs/exports.js.map +1 -1
- package/lib/cjs/index.js +1 -9
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -1
- package/lib/cjs/interfaces/Route.js.map +1 -1
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js +2 -0
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/cjs/services/FakeAdapter.js +6 -12
- package/lib/cjs/services/FakeAdapter.js.map +1 -1
- package/lib/cjs/services/Platform.js +30 -86
- package/lib/cjs/services/Platform.js.map +1 -1
- package/lib/cjs/services/PlatformAdapter.js +10 -0
- package/lib/cjs/services/PlatformAdapter.js.map +1 -1
- package/lib/cjs/services/PlatformApplication.js +23 -9
- package/lib/cjs/services/PlatformApplication.js.map +1 -1
- package/lib/cjs/services/PlatformHandler.js +112 -171
- package/lib/cjs/services/PlatformHandler.js.map +1 -1
- package/lib/cjs/services/PlatformMiddlewaresChain.js +5 -19
- package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/cjs/services/PlatformRequest.js +16 -12
- package/lib/cjs/services/PlatformRequest.js.map +1 -1
- package/lib/cjs/services/PlatformResponse.js +19 -22
- package/lib/cjs/services/PlatformResponse.js.map +1 -1
- package/lib/cjs/services/PlatformTest.js +29 -9
- package/lib/cjs/services/PlatformTest.js.map +1 -1
- package/lib/cjs/utils/createContext.js +32 -21
- package/lib/cjs/utils/createContext.js.map +1 -1
- package/lib/cjs/utils/createHttpServer.js +3 -3
- package/lib/cjs/utils/createHttpServer.js.map +1 -1
- package/lib/cjs/utils/createHttpsServer.js +3 -3
- package/lib/cjs/utils/createHttpsServer.js.map +1 -1
- package/lib/cjs/utils/createInjector.js +6 -8
- 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/getConfiguration.js +6 -12
- package/lib/cjs/utils/getConfiguration.js.map +1 -1
- package/lib/cjs/utils/printRoutes.js +10 -8
- package/lib/cjs/utils/printRoutes.js.map +1 -1
- package/lib/cjs/utils/setResponseHeaders.js +8 -14
- package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +63 -68
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/esm/config/services/PlatformConfiguration.js +0 -64
- package/lib/esm/config/services/PlatformConfiguration.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 +4 -5
- package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/esm/domain/PlatformContext.js +46 -38
- package/lib/esm/domain/PlatformContext.js.map +1 -1
- package/lib/esm/domain/PlatformRouteDetails.js +1 -19
- package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/esm/exports.js +1 -1
- package/lib/esm/exports.js.map +1 -1
- package/lib/esm/index.js +1 -9
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -1
- package/lib/esm/interfaces/Route.js.map +1 -1
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
- package/lib/esm/middlewares/PlatformMulterMiddleware.js +2 -0
- package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/esm/services/FakeAdapter.js +6 -12
- package/lib/esm/services/FakeAdapter.js.map +1 -1
- package/lib/esm/services/Platform.js +31 -87
- package/lib/esm/services/Platform.js.map +1 -1
- package/lib/esm/services/PlatformAdapter.js +10 -0
- package/lib/esm/services/PlatformAdapter.js.map +1 -1
- package/lib/esm/services/PlatformApplication.js +23 -9
- package/lib/esm/services/PlatformApplication.js.map +1 -1
- package/lib/esm/services/PlatformHandler.js +114 -173
- package/lib/esm/services/PlatformHandler.js.map +1 -1
- package/lib/esm/services/PlatformMiddlewaresChain.js +5 -19
- package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/esm/services/PlatformRequest.js +16 -12
- package/lib/esm/services/PlatformRequest.js.map +1 -1
- package/lib/esm/services/PlatformResponse.js +19 -22
- package/lib/esm/services/PlatformResponse.js.map +1 -1
- package/lib/esm/services/PlatformTest.js +29 -9
- package/lib/esm/services/PlatformTest.js.map +1 -1
- package/lib/esm/utils/createContext.js +30 -20
- package/lib/esm/utils/createContext.js.map +1 -1
- package/lib/esm/utils/createHttpServer.js +3 -3
- package/lib/esm/utils/createHttpServer.js.map +1 -1
- package/lib/esm/utils/createHttpsServer.js +3 -3
- package/lib/esm/utils/createHttpsServer.js.map +1 -1
- package/lib/esm/utils/createInjector.js +7 -9
- 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/getConfiguration.js +8 -14
- package/lib/esm/utils/getConfiguration.js.map +1 -1
- package/lib/esm/utils/printRoutes.js +10 -8
- package/lib/esm/utils/printRoutes.js.map +1 -1
- package/lib/esm/utils/setResponseHeaders.js +8 -14
- package/lib/esm/utils/setResponseHeaders.js.map +1 -1
- package/lib/types/builder/PlatformBuilder.d.ts +17 -16
- package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +2 -43
- package/lib/types/config/services/PlatformConfiguration.d.ts +6 -22
- package/lib/types/domain/AnyToPromiseWithCtx.d.ts +1 -9
- package/lib/types/domain/PlatformContext.d.ts +32 -18
- package/lib/types/domain/PlatformRouteDetails.d.ts +4 -19
- package/lib/types/exports.d.ts +1 -1
- package/lib/types/index.d.ts +1 -9
- package/lib/types/interfaces/PlatformRouteOptions.d.ts +0 -1
- 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 +7 -28
- package/lib/types/services/PlatformAdapter.d.ts +22 -11
- package/lib/types/services/PlatformApplication.d.ts +14 -6
- package/lib/types/services/PlatformHandler.d.ts +21 -59
- package/lib/types/services/PlatformMiddlewaresChain.d.ts +1 -2
- package/lib/types/services/PlatformRequest.d.ts +8 -10
- package/lib/types/services/PlatformResponse.d.ts +11 -15
- package/lib/types/services/PlatformTest.d.ts +4 -3
- package/lib/types/utils/createContext.d.ts +4 -1
- package/lib/types/utils/createHttpsServer.d.ts +1 -0
- package/lib/types/utils/createInjector.d.ts +2 -2
- package/lib/types/utils/ensureContext.d.ts +2 -0
- package/lib/types/utils/listenServer.d.ts +2 -0
- package/package.json +27 -25
- package/readme.md +2 -1
- package/lib/cjs/builder/PlatformControllerBuilder.js +0 -82
- package/lib/cjs/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js +0 -3
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js.map +0 -1
- package/lib/cjs/domain/ControllerProvider.js +0 -51
- package/lib/cjs/domain/ControllerProvider.js.map +0 -1
- package/lib/cjs/domain/HandlerMetadata.js +0 -57
- package/lib/cjs/domain/HandlerMetadata.js.map +0 -1
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js +0 -12
- package/lib/cjs/middlewares/__mock__/FakeCtrl.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 -108
- package/lib/cjs/services/PlatformRouter.js.map +0 -1
- package/lib/cjs/utils/__mock__/Test1.js +0 -8
- package/lib/cjs/utils/__mock__/Test1.js.map +0 -1
- package/lib/cjs/utils/__mock__/Test2.js +0 -8
- package/lib/cjs/utils/__mock__/Test2.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/importProviders.js +0 -29
- package/lib/cjs/utils/importProviders.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/config/interfaces/EndpointDirectoriesSettings.js +0 -2
- package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js.map +0 -1
- package/lib/esm/domain/ControllerProvider.js +0 -47
- package/lib/esm/domain/ControllerProvider.js.map +0 -1
- package/lib/esm/domain/HandlerMetadata.js +0 -53
- package/lib/esm/domain/HandlerMetadata.js.map +0 -1
- package/lib/esm/middlewares/__mock__/FakeCtrl.js +0 -9
- package/lib/esm/middlewares/__mock__/FakeCtrl.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 -105
- package/lib/esm/services/PlatformRouter.js.map +0 -1
- package/lib/esm/utils/__mock__/Test1.js +0 -4
- package/lib/esm/utils/__mock__/Test1.js.map +0 -1
- package/lib/esm/utils/__mock__/Test2.js +0 -4
- package/lib/esm/utils/__mock__/Test2.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/importProviders.js +0 -25
- package/lib/esm/utils/importProviders.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/config/interfaces/EndpointDirectoriesSettings.d.ts +0 -3
- package/lib/types/domain/ControllerProvider.d.ts +0 -24
- package/lib/types/domain/HandlerMetadata.d.ts +0 -32
- package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +0 -2
- package/lib/types/middlewares/bindEndpointMiddleware.d.ts +0 -6
- package/lib/types/services/PlatformRouter.d.ts +0 -51
- package/lib/types/utils/__mock__/Test1.d.ts +0 -3
- package/lib/types/utils/__mock__/Test2.d.ts +0 -3
- package/lib/types/utils/createHandlerMetadata.d.ts +0 -8
- package/lib/types/utils/importProviders.d.ts +0 -10
- package/lib/types/utils/useCtxHandler.d.ts +0 -13
package/coverage.json
ADDED
package/jest.config.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
+
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require("@tsed/jest-config")(__dirname, "common"),
|
|
6
|
+
coverageThreshold: {
|
|
7
|
+
global: require("./coverage.json")
|
|
8
|
+
}
|
|
9
|
+
};
|
|
@@ -1,55 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
3
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
26
|
exports.PlatformBuilder = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
27
|
const core_1 = require("@tsed/core");
|
|
7
28
|
const di_1 = require("@tsed/di");
|
|
8
29
|
const platform_middlewares_1 = require("@tsed/platform-middlewares");
|
|
9
30
|
const Platform_1 = require("../services/Platform");
|
|
10
|
-
const PlatformApplication_1 = require("../services/PlatformApplication");
|
|
11
|
-
const getStaticsOptions_1 = require("../utils/getStaticsOptions");
|
|
12
|
-
const getConfiguration_1 = require("../utils/getConfiguration");
|
|
13
31
|
const PlatformAdapter_1 = require("../services/PlatformAdapter");
|
|
14
|
-
const
|
|
15
|
-
const createInjector_1 = require("../utils/createInjector");
|
|
16
|
-
const printRoutes_1 = require("../utils/printRoutes");
|
|
32
|
+
const PlatformApplication_1 = require("../services/PlatformApplication");
|
|
17
33
|
const createHttpServer_1 = require("../utils/createHttpServer");
|
|
18
34
|
const createHttpsServer_1 = require("../utils/createHttpsServer");
|
|
35
|
+
const createInjector_1 = require("../utils/createInjector");
|
|
36
|
+
const getConfiguration_1 = require("../utils/getConfiguration");
|
|
37
|
+
const getStaticsOptions_1 = require("../utils/getStaticsOptions");
|
|
38
|
+
const printRoutes_1 = require("../utils/printRoutes");
|
|
19
39
|
/**
|
|
20
40
|
* @platform
|
|
21
41
|
*/
|
|
22
42
|
class PlatformBuilder {
|
|
43
|
+
static adapter;
|
|
44
|
+
name = "";
|
|
45
|
+
startedAt = new Date();
|
|
46
|
+
current = new Date();
|
|
47
|
+
#injector;
|
|
48
|
+
#rootModule;
|
|
49
|
+
#adapter;
|
|
50
|
+
#promise;
|
|
51
|
+
#servers;
|
|
52
|
+
#listeners = [];
|
|
23
53
|
constructor(adapter, module, settings) {
|
|
24
|
-
this
|
|
25
|
-
|
|
26
|
-
this.current = new Date();
|
|
27
|
-
_PlatformBuilder_injector.set(this, void 0);
|
|
28
|
-
_PlatformBuilder_rootModule.set(this, void 0);
|
|
29
|
-
_PlatformBuilder_adapter.set(this, void 0);
|
|
30
|
-
_PlatformBuilder_promise.set(this, void 0);
|
|
31
|
-
_PlatformBuilder_servers.set(this, void 0);
|
|
32
|
-
_PlatformBuilder_listeners.set(this, []);
|
|
33
|
-
tslib_1.__classPrivateFieldSet(this, _PlatformBuilder_rootModule, module, "f");
|
|
54
|
+
this.#rootModule = module;
|
|
55
|
+
const configuration = (0, getConfiguration_1.getConfiguration)(settings, module);
|
|
34
56
|
const adapterKlass = adapter || PlatformBuilder.adapter;
|
|
35
57
|
const name = (0, core_1.nameOf)(adapterKlass).replace("Platform", "").toLowerCase();
|
|
36
|
-
const configuration = (0, getConfiguration_1.getConfiguration)(settings, module);
|
|
37
58
|
configuration.PLATFORM_NAME = name;
|
|
38
59
|
this.name = name;
|
|
39
|
-
|
|
60
|
+
this.#injector = (0, createInjector_1.createInjector)({
|
|
40
61
|
adapter: adapterKlass,
|
|
41
62
|
settings: configuration
|
|
42
|
-
})
|
|
43
|
-
|
|
63
|
+
});
|
|
64
|
+
this.#adapter = this.#injector.get(PlatformAdapter_1.PlatformAdapter);
|
|
44
65
|
this.createHttpServers();
|
|
45
|
-
|
|
66
|
+
this.#adapter.onInit && this.#adapter.onInit();
|
|
46
67
|
this.log("Injector created...");
|
|
47
68
|
}
|
|
48
69
|
get injector() {
|
|
49
|
-
return
|
|
70
|
+
return this.#injector;
|
|
50
71
|
}
|
|
51
72
|
get rootModule() {
|
|
52
|
-
return
|
|
73
|
+
return this.#injector.get(this.#rootModule);
|
|
53
74
|
}
|
|
54
75
|
get app() {
|
|
55
76
|
return this.injector.get(PlatformApplication_1.PlatformApplication);
|
|
@@ -58,7 +79,7 @@ class PlatformBuilder {
|
|
|
58
79
|
return this.injector.get(Platform_1.Platform);
|
|
59
80
|
}
|
|
60
81
|
get adapter() {
|
|
61
|
-
return
|
|
82
|
+
return this.#adapter;
|
|
62
83
|
}
|
|
63
84
|
/**
|
|
64
85
|
* Return the settings configured by the decorator @@Configuration@@.
|
|
@@ -88,15 +109,13 @@ class PlatformBuilder {
|
|
|
88
109
|
return this.injector.logger;
|
|
89
110
|
}
|
|
90
111
|
get disableBootstrapLog() {
|
|
91
|
-
|
|
92
|
-
return (_a = this.settings.logger) === null || _a === void 0 ? void 0 : _a.disableBootstrapLog;
|
|
112
|
+
return this.settings.get("logger.disableBootstrapLog");
|
|
93
113
|
}
|
|
94
114
|
static create(module, settings) {
|
|
95
115
|
return this.build(module, {
|
|
96
116
|
httpsPort: false,
|
|
97
117
|
httpPort: false,
|
|
98
|
-
...settings
|
|
99
|
-
disableComponentsScan: true
|
|
118
|
+
...settings
|
|
100
119
|
});
|
|
101
120
|
}
|
|
102
121
|
static build(module, { adapter, ...settings }) {
|
|
@@ -112,7 +131,7 @@ class PlatformBuilder {
|
|
|
112
131
|
}
|
|
113
132
|
callback(req, res) {
|
|
114
133
|
if (req && res) {
|
|
115
|
-
return this.
|
|
134
|
+
return this.callback()(req, res);
|
|
116
135
|
}
|
|
117
136
|
return this.app.callback();
|
|
118
137
|
}
|
|
@@ -124,7 +143,7 @@ class PlatformBuilder {
|
|
|
124
143
|
* @param classes
|
|
125
144
|
*/
|
|
126
145
|
addComponents(classes) {
|
|
127
|
-
this.settings.
|
|
146
|
+
this.settings.set("imports", this.settings.get("imports", []).concat(classes));
|
|
128
147
|
return this;
|
|
129
148
|
}
|
|
130
149
|
/**
|
|
@@ -148,32 +167,26 @@ class PlatformBuilder {
|
|
|
148
167
|
* @param {any[]} controllers
|
|
149
168
|
*/
|
|
150
169
|
addControllers(endpoint, controllers) {
|
|
151
|
-
|
|
170
|
+
[].concat(controllers).forEach((token) => {
|
|
171
|
+
this.settings.routes.push({ token, route: endpoint });
|
|
172
|
+
});
|
|
152
173
|
}
|
|
153
174
|
async runLifecycle() {
|
|
154
|
-
(0, di_1.
|
|
155
|
-
await this.importProviders();
|
|
175
|
+
(0, di_1.setLoggerConfiguration)(this.injector);
|
|
156
176
|
await this.loadInjector();
|
|
157
|
-
|
|
158
|
-
tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").useRouter && tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").useRouter();
|
|
177
|
+
this.#adapter.useContext();
|
|
159
178
|
await this.loadRoutes();
|
|
160
|
-
await this.logRoutes();
|
|
161
179
|
return this;
|
|
162
180
|
}
|
|
163
181
|
async loadInjector() {
|
|
164
182
|
const { injector } = this;
|
|
165
183
|
this.log("Build providers");
|
|
166
|
-
|
|
167
|
-
container.addProvider(tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_rootModule, "f"), {
|
|
168
|
-
type: "server:module",
|
|
169
|
-
scope: di_1.ProviderScope.SINGLETON
|
|
170
|
-
});
|
|
171
|
-
await injector.load(container);
|
|
184
|
+
await injector.loadModule(this.#rootModule);
|
|
172
185
|
this.log("Settings and injector loaded...");
|
|
173
186
|
await this.callHook("$afterInit");
|
|
174
187
|
}
|
|
175
188
|
async listen(network = true) {
|
|
176
|
-
if (!
|
|
189
|
+
if (!this.#promise) {
|
|
177
190
|
await this.bootstrap();
|
|
178
191
|
}
|
|
179
192
|
await this.callHook("$beforeListen");
|
|
@@ -186,7 +199,7 @@ class PlatformBuilder {
|
|
|
186
199
|
async stop() {
|
|
187
200
|
await this.callHook("$onDestroy");
|
|
188
201
|
await this.injector.destroy();
|
|
189
|
-
|
|
202
|
+
this.#listeners.map((server) => {
|
|
190
203
|
return new Promise((resolve) => server.close(() => resolve(undefined)));
|
|
191
204
|
});
|
|
192
205
|
}
|
|
@@ -219,15 +232,14 @@ class PlatformBuilder {
|
|
|
219
232
|
return this;
|
|
220
233
|
}
|
|
221
234
|
async bootstrap() {
|
|
222
|
-
|
|
223
|
-
return
|
|
235
|
+
this.#promise = this.#promise || this.runLifecycle();
|
|
236
|
+
return this.#promise;
|
|
224
237
|
}
|
|
225
238
|
async loadRoutes() {
|
|
226
|
-
|
|
227
|
-
tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes && (await tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes());
|
|
239
|
+
this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());
|
|
228
240
|
// istanbul ignore next
|
|
229
|
-
if (
|
|
230
|
-
const { PlatformLogMiddleware } = await Promise.resolve().then(() =>
|
|
241
|
+
if (this.settings.get("logger.level") !== "off") {
|
|
242
|
+
const { PlatformLogMiddleware } = await Promise.resolve().then(() => __importStar(require("@tsed/platform-log-middleware")));
|
|
231
243
|
this.app.use(PlatformLogMiddleware);
|
|
232
244
|
}
|
|
233
245
|
this.log("Load routes");
|
|
@@ -242,20 +254,19 @@ class PlatformBuilder {
|
|
|
242
254
|
await this.callHook("$onRoutesInit");
|
|
243
255
|
await this.loadStatics("$afterRoutesInit");
|
|
244
256
|
await this.callHook("$afterRoutesInit");
|
|
245
|
-
|
|
257
|
+
this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());
|
|
258
|
+
await this.mapRouters();
|
|
259
|
+
}
|
|
260
|
+
async mapRouters() {
|
|
261
|
+
const layers = this.platform.getLayers();
|
|
262
|
+
this.#adapter.mapLayers(layers);
|
|
263
|
+
return this.logRoutes(layers.filter((layer) => layer.isProvider()));
|
|
246
264
|
}
|
|
247
265
|
diff() {
|
|
248
266
|
const ms = di_1.colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);
|
|
249
267
|
this.current = new Date();
|
|
250
268
|
return ms;
|
|
251
269
|
}
|
|
252
|
-
async importProviders() {
|
|
253
|
-
this.injector.logger.debug("Scan components");
|
|
254
|
-
const providers = await (0, importProviders_1.importProviders)(this.injector.settings, ["imports", "mount", "componentsScan"]);
|
|
255
|
-
const routes = providers.filter((provider) => !!provider.route).map(({ route, token }) => ({ route, token }));
|
|
256
|
-
this.settings.set("routes", routes);
|
|
257
|
-
this.log("Providers loaded...");
|
|
258
|
-
}
|
|
259
270
|
/**
|
|
260
271
|
* Load middlewares from configuration for the given hook
|
|
261
272
|
* @param hook
|
|
@@ -267,20 +278,27 @@ class PlatformBuilder {
|
|
|
267
278
|
});
|
|
268
279
|
}
|
|
269
280
|
createHttpServers() {
|
|
270
|
-
|
|
281
|
+
this.#servers = [(0, createHttpServer_1.createHttpServer)(this.#injector, this.callback()), (0, createHttpsServer_1.createHttpsServer)(this.#injector, this.callback())].filter(Boolean);
|
|
271
282
|
}
|
|
272
283
|
async listenServers() {
|
|
273
|
-
|
|
284
|
+
this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));
|
|
274
285
|
}
|
|
275
|
-
async logRoutes() {
|
|
276
|
-
|
|
277
|
-
const { logger, platform } = this;
|
|
286
|
+
async logRoutes(layers) {
|
|
287
|
+
const { logger } = this;
|
|
278
288
|
this.log("Routes mounted...");
|
|
279
|
-
if (!
|
|
280
|
-
|
|
289
|
+
if (!this.settings.get("logger.disableRoutesSummary") && !this.disableBootstrapLog) {
|
|
290
|
+
const routes = layers.map((layer) => {
|
|
291
|
+
return {
|
|
292
|
+
url: layer.path,
|
|
293
|
+
method: layer.method,
|
|
294
|
+
name: layer.opts.name || `${layer.provider.className}.constructor()`,
|
|
295
|
+
className: layer.opts.className || layer.provider.className,
|
|
296
|
+
methodClassName: layer.opts.methodClassName || ""
|
|
297
|
+
};
|
|
298
|
+
});
|
|
299
|
+
logger.info((0, printRoutes_1.printRoutes)(await this.injector.alterAsync("$logRoutes", routes)));
|
|
281
300
|
}
|
|
282
301
|
}
|
|
283
302
|
}
|
|
284
303
|
exports.PlatformBuilder = PlatformBuilder;
|
|
285
|
-
_PlatformBuilder_injector = new WeakMap(), _PlatformBuilder_rootModule = new WeakMap(), _PlatformBuilder_adapter = new WeakMap(), _PlatformBuilder_promise = new WeakMap(), _PlatformBuilder_servers = new WeakMap(), _PlatformBuilder_listeners = new WeakMap();
|
|
286
304
|
//# sourceMappingURL=PlatformBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":";;;;;AAAA,qCAAwC;AACxC,iCAA+G;AAC/G,qEAAiE;AACjE,mDAA8C;AAC9C,yEAAoE;AAEpE,kEAA6D;AAE7D,gEAA2D;AAE3D,iEAAqF;AACrF,8DAAyD;AACzD,4DAAuD;AACvD,sDAAiD;AACjD,gEAA2D;AAC3D,kEAA6D;AAG7D;;GAEG;AACH,MAAa,eAAe;I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C,GAAG,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;IAES,iBAAiB;QACzB,+BAAA,IAAI,4BAAY,CAAC,IAAA,mCAAgB,EAAC,+BAAA,IAAI,iCAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAA,qCAAiB,EAAC,+BAAA,IAAI,iCAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAC5H,OAAO,CACC,MAAA,CAAC;IACb,CAAC;IAES,KAAK,CAAC,aAAa;QAC3B,+BAAA,IAAI,8BAAc,MAAM,OAAO,CAAC,GAAG,CAAC,+BAAA,IAAI,gCAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,MAAA,CAAC;IAC7E,CAAC;IAES,KAAK,CAAC,SAAS;;QACvB,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC;QAEhC,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAE9B,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,0CAAE,oBAAoB,CAAA,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC5E,MAAM,CAAC,IAAI,CAAC,IAAA,yBAAW,EAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9F;IACH,CAAC;CACF;AAvVD,0CAuVC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, createContainer, InjectorService, ProviderOpts, ProviderScope, setLoggerLevel} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {Route} from \"../interfaces/Route\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {importProviders} from \"../utils/importProviders\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {printRoutes} from \"../utils/printRoutes\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport type Https from \"https\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {\n public static adapter: Type<PlatformAdapter<any, any>>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n readonly #injector: InjectorService;\n readonly #rootModule: Type<any>;\n readonly #adapter: PlatformAdapter<App, Router>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n const adapterKlass: Type<PlatformAdapter<App, Router>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n const configuration = getConfiguration(settings, module);\n configuration.PLATFORM_NAME = name;\n this.name = name;\n\n this.#injector = createInjector({\n adapter: adapterKlass,\n settings: configuration\n });\n\n this.#adapter = this.#injector.get<PlatformAdapter<App, Router>>(PlatformAdapter)!;\n\n this.createHttpServers();\n\n this.#adapter.onInit && this.#adapter.onInit();\n\n this.log(\"Injector created...\");\n }\n\n get injector(): InjectorService {\n return this.#injector;\n }\n\n get rootModule(): any {\n return this.#injector.get(this.#rootModule);\n }\n\n get app(): PlatformApplication<App, Router> {\n return this.injector.get<PlatformApplication<App, Router>>(PlatformApplication)!;\n }\n\n get platform() {\n return this.injector.get<Platform>(Platform)!;\n }\n\n get adapter() {\n return this.#adapter;\n }\n\n /**\n * Return the settings configured by the decorator @@Configuration@@.\n *\n * ```typescript\n * @Configuration({\n * rootDir: Path.resolve(__dirname),\n * port: 8000,\n * httpsPort: 8080,\n * mount: {\n * \"/rest\": \"${rootDir}/controllers/**\\/*.js\"\n * }\n * })\n * export class Server {\n * $onInit(){\n * console.log(this.settings); // {rootDir, port, httpsPort,...}\n * }\n * }\n * ```\n *\n * @returns {PlatformConfiguration}\n */\n get settings() {\n return this.injector.settings;\n }\n\n get logger() {\n return this.injector.logger;\n }\n\n get disableBootstrapLog() {\n return this.settings.logger?.disableBootstrapLog;\n }\n\n static create<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings,\n disableComponentsScan: true\n });\n }\n\n static build<App = TsED.Application, Router = TsED.Router>(\n module: Type<any>,\n {adapter, ...settings}: PlatformBuilderSettings<App, Router>\n ) {\n return new PlatformBuilder(adapter, module, settings);\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n return this.build<App, Router>(module, settings).bootstrap();\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => void;\n callback(req: IncomingMessage, res: ServerResponse): void;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.app.callback()(req, res);\n }\n\n return this.app.callback();\n }\n\n log(...data: any[]) {\n return !this.disableBootstrapLog && this.logger.info(...data, this.diff());\n }\n\n /**\n * Add classes to the components list\n * @param classes\n */\n public addComponents(classes: any | any[]) {\n this.settings.componentsScan = this.settings.componentsScan.concat(classes);\n\n return this;\n }\n\n /**\n * Add classes decorated by @@Controller@@ to components container.\n *\n * ### Example\n *\n * ```typescript\n * @Controller('/ctrl')\n * class MyController{\n * }\n *\n * platform.addControllers('/rest', [MyController])\n * ```\n *\n * ::: tip\n * If the MyController class isn't decorated, the class will be ignored.\n * :::\n *\n * @param {string} endpoint\n * @param {any[]} controllers\n */\n public addControllers(endpoint: string, controllers: any | string | (any | string)[]) {\n this.settings.mount[endpoint] = (this.settings.mount[endpoint] || []).concat(controllers);\n }\n\n public async runLifecycle() {\n setLoggerLevel(this.injector);\n\n await this.importProviders();\n await this.loadInjector();\n\n this.#adapter.useContext && this.#adapter.useContext();\n this.#adapter.useRouter && this.#adapter.useRouter();\n\n await this.loadRoutes();\n await this.logRoutes();\n\n return this;\n }\n\n async loadInjector() {\n const {injector} = this;\n this.log(\"Build providers\");\n\n const container = createContainer();\n\n container.addProvider(this.#rootModule, {\n type: \"server:module\",\n scope: ProviderScope.SINGLETON\n });\n\n await injector.load(container);\n\n this.log(\"Settings and injector loaded...\");\n\n await this.callHook(\"$afterInit\");\n }\n\n async listen(network = true) {\n if (!this.#promise) {\n await this.bootstrap();\n }\n\n await this.callHook(\"$beforeListen\");\n\n if (network) {\n await this.listenServers();\n }\n\n await this.callHook(\"$afterListen\");\n\n await this.ready();\n }\n\n async stop() {\n await this.callHook(\"$onDestroy\");\n await this.injector.destroy();\n\n this.#listeners.map((server) => {\n return new Promise((resolve) => server.close(() => resolve(undefined)));\n });\n }\n\n public async ready() {\n const {startedAt} = this;\n\n await this.callHook(\"$onReady\");\n await this.injector.emit(\"$onServerReady\");\n\n this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);\n }\n\n async callHook(hook: string, ...args: any[]) {\n const {injector} = this;\n\n if (!this.disableBootstrapLog) {\n injector.logger.debug(`\\x1B[1mCall hook ${hook}\\x1B[22m`);\n }\n\n // Load middlewares for the given hook\n this.loadMiddlewaresFor(hook);\n\n // call hooks added by providers\n await injector.emit(hook, ...args);\n }\n\n async loadStatics(hook: string): Promise<void> {\n const statics = this.settings.get<PlatformStaticsSettings>(\"statics\");\n\n getStaticsOptions(statics).forEach(({path, options}) => {\n if (options.hook === hook) {\n this.platform.app.statics(path, options);\n }\n });\n }\n\n useProvider(token: Type<any>, settings?: Partial<ProviderOpts>) {\n this.injector.addProvider(token, settings);\n\n return this;\n }\n\n async bootstrap() {\n this.#promise = this.#promise || this.runLifecycle();\n\n return this.#promise;\n }\n\n protected async loadRoutes() {\n this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());\n\n // istanbul ignore next\n if (this.settings.logger?.level !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\n }\n\n this.log(\"Load routes\");\n\n if (this.rootModule.$beforeRoutesInit) {\n await this.rootModule.$beforeRoutesInit();\n this.rootModule.$beforeRoutesInit = () => {};\n }\n\n await this.loadStatics(\"$beforeRoutesInit\");\n await this.callHook(\"$beforeRoutesInit\");\n\n const routes = this.injector.settings.get<Route[]>(\"routes\");\n\n this.platform.addRoutes(routes);\n\n await this.callHook(\"$onRoutesInit\");\n\n await this.loadStatics(\"$afterRoutesInit\");\n\n await this.callHook(\"$afterRoutesInit\");\n\n this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());\n }\n\n protected diff() {\n const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);\n this.current = new Date();\n return ms;\n }\n\n protected async importProviders() {\n this.injector.logger.debug(\"Scan components\");\n\n const providers = await importProviders(this.injector.settings, [\"imports\", \"mount\", \"componentsScan\"]);\n const routes = providers.filter((provider) => !!provider.route).map(({route, token}) => ({route, token}));\n\n this.settings.set(\"routes\", routes);\n this.log(\"Providers loaded...\");\n }\n\n /**\n * Load middlewares from configuration for the given hook\n * @param hook\n * @protected\n */\n protected loadMiddlewaresFor(hook: string): void {\n return getMiddlewaresForHook(hook, this.settings, \"$beforeRoutesInit\").forEach(({use}) => {\n this.app.use(use);\n });\n }\n\n protected createHttpServers() {\n this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(\n Boolean\n ) as any[];\n }\n\n protected async listenServers(): Promise<void> {\n this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));\n }\n\n protected async logRoutes() {\n const {logger, platform} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.logger?.disableRoutesSummary && !this.disableBootstrapLog) {\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", platform.getRoutes())));\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAwC;AACxC,iCAAoH;AACpH,qEAAiE;AAOjE,mDAA8C;AAC9C,iEAAqF;AACrF,yEAAoE;AACpE,gEAA2D;AAC3D,kEAA6D;AAC7D,4DAAuD;AACvD,gEAA2D;AAC3D,kEAA6D;AAC7D,sDAAiD;AAEjD;;GAEG;AACH,MAAa,eAAe;IACnB,MAAM,CAAC,OAAO,CAA6B;IAEzC,IAAI,GAAW,EAAE,CAAC;IACjB,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;IACtB,SAAS,CAAkB;IAC3B,WAAW,CAAY;IACvB,QAAQ,CAAuB;IACxC,QAAQ,CAAgB;IACxB,QAAQ,CAA2C;IACnD,UAAU,GAA8B,EAAE,CAAC;IAE3C,YAAsB,OAA+C,EAAE,MAAY,EAAE,QAAqC;QACxH,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAE1B,MAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzD,MAAM,YAAY,GAA+B,OAAO,IAAK,eAAe,CAAC,OAAe,CAAC;QAC7F,MAAM,IAAI,GAAG,IAAA,aAAM,EAAC,YAAY,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAExE,aAAa,CAAC,aAAa,GAAG,I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AI,CAAC,IAAA,yBAAW,EAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;SAChF;IACH,CAAC;CACF;AAtVD,0CAsVC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, runInContext, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport {PlatformLayer} from \"@tsed/platform-router\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport type Https from \"https\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {PlatformRouteDetails} from \"../domain/PlatformRouteDetails\";\nimport {Route} from \"../interfaces/Route\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {printRoutes} from \"../utils/printRoutes\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application> {\n public static adapter: Type<PlatformAdapter<any>>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n readonly #injector: InjectorService;\n readonly #rootModule: Type<any>;\n readonly #adapter: PlatformAdapter<App>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n\n const configuration = getConfiguration(settings, module);\n const adapterKlass: Type<PlatformAdapter<App>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n configuration.PLATFORM_NAME = name;\n this.name = name;\n\n this.#injector = createInjector({\n adapter: adapterKlass,\n settings: configuration\n });\n\n this.#adapter = this.#injector.get<PlatformAdapter<App>>(PlatformAdapter)!;\n\n this.createHttpServers();\n\n this.#adapter.onInit && this.#adapter.onInit();\n\n this.log(\"Injector created...\");\n }\n\n get injector(): InjectorService {\n return this.#injector;\n }\n\n get rootModule(): any {\n return this.#injector.get(this.#rootModule);\n }\n\n get app(): PlatformApplication<App> {\n return this.injector.get<PlatformApplication<App>>(PlatformApplication)!;\n }\n\n get platform() {\n return this.injector.get<Platform>(Platform)!;\n }\n\n get adapter() {\n return this.#adapter;\n }\n\n /**\n * Return the settings configured by the decorator @@Configuration@@.\n *\n * ```typescript\n * @Configuration({\n * rootDir: Path.resolve(__dirname),\n * port: 8000,\n * httpsPort: 8080,\n * mount: {\n * \"/rest\": \"${rootDir}/controllers/**\\/*.js\"\n * }\n * })\n * export class Server {\n * $onInit(){\n * console.log(this.settings); // {rootDir, port, httpsPort,...}\n * }\n * }\n * ```\n *\n * @returns {PlatformConfiguration}\n */\n get settings() {\n return this.injector.settings;\n }\n\n get logger() {\n return this.injector.logger;\n }\n\n get disableBootstrapLog() {\n return this.settings.get(\"logger.disableBootstrapLog\");\n }\n\n static create<App = TsED.Application>(module: Type<any>, settings: PlatformBuilderSettings<App>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings\n });\n }\n\n static build<App = TsED.Application>(module: Type<any>, {adapter, ...settings}: PlatformBuilderSettings<App>) {\n return new PlatformBuilder(adapter, module, settings);\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap<App = TsED.Application>(module: Type<any>, settings: PlatformBuilderSettings<App>) {\n return this.build<App>(module, settings).bootstrap();\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => void;\n callback(req: IncomingMessage, res: ServerResponse): void;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.callback()(req, res);\n }\n\n return this.app.callback();\n }\n\n log(...data: any[]) {\n return !this.disableBootstrapLog && this.logger.info(...data, this.diff());\n }\n\n /**\n * Add classes to the components list\n * @param classes\n */\n public addComponents(classes: Type | Type[]) {\n this.settings.set(\"imports\", this.settings.get<any[]>(\"imports\", []).concat(classes));\n\n return this;\n }\n\n /**\n * Add classes decorated by @@Controller@@ to components container.\n *\n * ### Example\n *\n * ```typescript\n * @Controller('/ctrl')\n * class MyController{\n * }\n *\n * platform.addControllers('/rest', [MyController])\n * ```\n *\n * ::: tip\n * If the MyController class isn't decorated, the class will be ignored.\n * :::\n *\n * @param {string} endpoint\n * @param {any[]} controllers\n */\n public addControllers(endpoint: string, controllers: TokenProvider | TokenProvider[]) {\n [].concat(controllers).forEach((token) => {\n this.settings.routes.push({token, route: endpoint});\n });\n }\n\n public async runLifecycle() {\n setLoggerConfiguration(this.injector);\n\n await this.loadInjector();\n\n this.#adapter.useContext();\n\n await this.loadRoutes();\n\n return this;\n }\n\n async loadInjector() {\n const {injector} = this;\n this.log(\"Build providers\");\n\n await injector.loadModule(this.#rootModule);\n\n this.log(\"Settings and injector loaded...\");\n\n await this.callHook(\"$afterInit\");\n }\n\n async listen(network = true) {\n if (!this.#promise) {\n await this.bootstrap();\n }\n\n await this.callHook(\"$beforeListen\");\n\n if (network) {\n await this.listenServers();\n }\n\n await this.callHook(\"$afterListen\");\n\n await this.ready();\n }\n\n async stop() {\n await this.callHook(\"$onDestroy\");\n await this.injector.destroy();\n\n this.#listeners.map((server) => {\n return new Promise((resolve) => server.close(() => resolve(undefined)));\n });\n }\n\n public async ready() {\n const {startedAt} = this;\n\n await this.callHook(\"$onReady\");\n await this.injector.emit(\"$onServerReady\");\n\n this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);\n }\n\n async callHook(hook: string, ...args: any[]) {\n const {injector} = this;\n\n if (!this.disableBootstrapLog) {\n injector.logger.debug(`\\x1B[1mCall hook ${hook}\\x1B[22m`);\n }\n\n // Load middlewares for the given hook\n this.loadMiddlewaresFor(hook);\n\n // call hooks added by providers\n await injector.emit(hook, ...args);\n }\n\n async loadStatics(hook: string): Promise<void> {\n const statics = this.settings.get<PlatformStaticsSettings>(\"statics\");\n\n getStaticsOptions(statics).forEach(({path, options}) => {\n if (options.hook === hook) {\n this.platform.app.statics(path, options);\n }\n });\n }\n\n useProvider(token: Type<any>, settings?: Partial<ProviderOpts>) {\n this.injector.addProvider(token, settings);\n\n return this;\n }\n\n async bootstrap() {\n this.#promise = this.#promise || this.runLifecycle();\n\n return this.#promise;\n }\n\n protected async loadRoutes() {\n this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());\n\n // istanbul ignore next\n if (this.settings.get(\"logger.level\") !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\n }\n\n this.log(\"Load routes\");\n\n if (this.rootModule.$beforeRoutesInit) {\n await this.rootModule.$beforeRoutesInit();\n this.rootModule.$beforeRoutesInit = () => {};\n }\n\n await this.loadStatics(\"$beforeRoutesInit\");\n await this.callHook(\"$beforeRoutesInit\");\n\n const routes = this.injector.settings.get<Route[]>(\"routes\");\n\n this.platform.addRoutes(routes);\n\n await this.callHook(\"$onRoutesInit\");\n\n await this.loadStatics(\"$afterRoutesInit\");\n\n await this.callHook(\"$afterRoutesInit\");\n\n this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());\n\n await this.mapRouters();\n }\n\n protected async mapRouters() {\n const layers = this.platform.getLayers();\n\n this.#adapter.mapLayers(layers);\n\n return this.logRoutes(layers.filter((layer) => layer.isProvider()));\n }\n\n protected diff() {\n const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);\n this.current = new Date();\n return ms;\n }\n\n /**\n * Load middlewares from configuration for the given hook\n * @param hook\n * @protected\n */\n protected loadMiddlewaresFor(hook: string): void {\n return getMiddlewaresForHook(hook, this.settings, \"$beforeRoutesInit\").forEach(({use}) => {\n this.app.use(use);\n });\n }\n\n protected createHttpServers() {\n this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(\n Boolean\n ) as any[];\n }\n\n protected async listenServers(): Promise<void> {\n this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));\n }\n\n protected async logRoutes(layers: PlatformLayer[]) {\n const {logger} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.get(\"logger.disableRoutesSummary\") && !this.disableBootstrapLog) {\n const routes: PlatformRouteDetails[] = layers.map((layer) => {\n return {\n url: layer.path,\n method: layer.method,\n name: layer.opts.name || `${layer.provider.className}.constructor()`,\n className: layer.opts.className || layer.provider.className,\n methodClassName: layer.opts.methodClassName || \"\"\n } as PlatformRouteDetails;\n });\n\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", routes)));\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformLoggerSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformLoggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"PlatformLoggerSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformLoggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {DILoggerOptions} from \"@tsed/di\";\n\nexport interface PlatformLoggerSettings extends DILoggerOptions {}\n"]}
|
|
@@ -4,7 +4,6 @@ exports.PlatformConfiguration = 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 rootDir = process.cwd();
|
|
9
8
|
/**
|
|
10
9
|
* `PlatformConfiguration` contains all information about your Server configuration.
|
|
@@ -13,18 +12,6 @@ let PlatformConfiguration = class PlatformConfiguration extends di_1.DIConfigura
|
|
|
13
12
|
constructor() {
|
|
14
13
|
super({ rootDir });
|
|
15
14
|
}
|
|
16
|
-
get version() {
|
|
17
|
-
return this.getRaw("version");
|
|
18
|
-
}
|
|
19
|
-
set version(v) {
|
|
20
|
-
this.setRaw("version", v);
|
|
21
|
-
}
|
|
22
|
-
get rootDir() {
|
|
23
|
-
return this.getRaw("rootDir");
|
|
24
|
-
}
|
|
25
|
-
set rootDir(value) {
|
|
26
|
-
this.setRaw("rootDir", value);
|
|
27
|
-
}
|
|
28
15
|
get port() {
|
|
29
16
|
return this.httpPort;
|
|
30
17
|
}
|
|
@@ -49,24 +36,12 @@ let PlatformConfiguration = class PlatformConfiguration extends di_1.DIConfigura
|
|
|
49
36
|
set httpsPort(value) {
|
|
50
37
|
this.setRaw("httpsPort", value);
|
|
51
38
|
}
|
|
52
|
-
get env() {
|
|
53
|
-
return this.getRaw("env");
|
|
54
|
-
}
|
|
55
|
-
set env(value) {
|
|
56
|
-
this.setRaw("env", value);
|
|
57
|
-
}
|
|
58
39
|
get mount() {
|
|
59
40
|
return this.get("mount");
|
|
60
41
|
}
|
|
61
42
|
set mount(value) {
|
|
62
43
|
this.setRaw("mount", value);
|
|
63
44
|
}
|
|
64
|
-
get componentsScan() {
|
|
65
|
-
return this.resolve(this.getRaw("componentsScan"));
|
|
66
|
-
}
|
|
67
|
-
set componentsScan(value) {
|
|
68
|
-
this.setRaw("componentsScan", value);
|
|
69
|
-
}
|
|
70
45
|
get statics() {
|
|
71
46
|
return this.getRaw("statics") || this.getRaw("serveStatic") || {};
|
|
72
47
|
}
|
|
@@ -79,51 +54,12 @@ let PlatformConfiguration = class PlatformConfiguration extends di_1.DIConfigura
|
|
|
79
54
|
set acceptMimes(value) {
|
|
80
55
|
this.setRaw("acceptMimes", value || []);
|
|
81
56
|
}
|
|
82
|
-
get debug() {
|
|
83
|
-
return this.logger.level === "debug";
|
|
84
|
-
}
|
|
85
|
-
set debug(debug) {
|
|
86
|
-
this.logger = { ...this.logger, level: debug ? "debug" : "info" };
|
|
87
|
-
}
|
|
88
57
|
get converter() {
|
|
89
58
|
return this.get("converter") || {};
|
|
90
59
|
}
|
|
91
60
|
set converter(options) {
|
|
92
61
|
this.setRaw("converter", options);
|
|
93
62
|
}
|
|
94
|
-
get logger() {
|
|
95
|
-
return this.get("logger");
|
|
96
|
-
}
|
|
97
|
-
set logger(value) {
|
|
98
|
-
const logger = { ...this.logger, ...value };
|
|
99
|
-
logger.debug = logger.level === "debug";
|
|
100
|
-
this.setRaw("logger", logger);
|
|
101
|
-
this.setRaw("debug", logger.debug);
|
|
102
|
-
if (logger.format) {
|
|
103
|
-
logger_1.$log.appenders.set("stdout", {
|
|
104
|
-
type: "stdout",
|
|
105
|
-
levels: ["info", "debug"],
|
|
106
|
-
layout: {
|
|
107
|
-
type: "pattern",
|
|
108
|
-
pattern: logger.format
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
logger_1.$log.appenders.set("stderr", {
|
|
112
|
-
levels: ["trace", "fatal", "error", "warn"],
|
|
113
|
-
type: "stderr",
|
|
114
|
-
layout: {
|
|
115
|
-
type: "pattern",
|
|
116
|
-
pattern: logger.format
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
get exclude() {
|
|
122
|
-
return this.get("exclude");
|
|
123
|
-
}
|
|
124
|
-
set exclude(exclude) {
|
|
125
|
-
this.setRaw("exclude", exclude);
|
|
126
|
-
}
|
|
127
63
|
get additionalProperties() {
|
|
128
64
|
return this.get("converter.additionalProperties") === "accept";
|
|
129
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformConfiguration.js","sourceRoot":"","sources":["../../../../src/config/services/PlatformConfiguration.ts"],"names":[],"mappings":";;;;AAAA,qCAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"PlatformConfiguration.js","sourceRoot":"","sources":["../../../../src/config/services/PlatformConfiguration.ts"],"names":[],"mappings":";;;;AAAA,qCAAoD;AAC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,IAAI,CAAC;QAEnC,IAAI,SAAS,EAAE;YACb,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;SAC5B;QAED,IAAI,QAAQ,EAAE;YACZ,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;SAC3B;QAED,OAAO;YACL,QAAQ;gBACN,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA1HY,qBAAqB;IAJjC,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,MAAM,EAAE,IAAI;KACb,CAAC;;GACW,qBAAqB,CA0HjC;AA1HY,sDAAqB","sourcesContent":["import {Env, getHostInfoFromPort} from \"@tsed/core\";\nimport {DIConfiguration, Injectable, ProviderScope, TokenProvider} from \"@tsed/di\";\nimport Https from \"https\";\nimport {ConverterSettings} from \"../interfaces/ConverterSettings\";\n\nconst rootDir = process.cwd();\n\n/**\n * `PlatformConfiguration` contains all information about your Server configuration.\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n global: true\n})\nexport class PlatformConfiguration extends DIConfiguration {\n constructor() {\n super({rootDir});\n }\n\n get port(): string | number | false {\n return this.httpPort;\n }\n\n set port(value: string | number | false) {\n this.httpPort = value;\n }\n\n get httpsOptions(): Https.ServerOptions {\n return this.getRaw(\"httpsOptions\");\n }\n\n set httpsOptions(value: Https.ServerOptions) {\n this.setRaw(\"httpsOptions\", value);\n }\n\n get httpPort(): string | number | false {\n return this.getRaw(\"httpPort\");\n }\n\n set httpPort(value: string | number | false) {\n this.setRaw(\"httpPort\", value);\n }\n\n get httpsPort(): string | number | false {\n return this.getRaw(\"httpsPort\");\n }\n\n set httpsPort(value: string | number | false) {\n this.setRaw(\"httpsPort\", value);\n }\n\n get mount(): Record<string, TokenProvider[]> {\n return this.get(\"mount\");\n }\n\n set mount(value: Record<string, TokenProvider[]>) {\n this.setRaw(\"mount\", value);\n }\n\n get statics(): Record<string, (any | string)[]> {\n return this.getRaw(\"statics\") || this.getRaw(\"serveStatic\") || {};\n }\n\n set statics(value: Record<string, (any | string)[]>) {\n this.setRaw(\"statics\", value);\n }\n\n get acceptMimes(): string[] {\n return this.getRaw(\"acceptMimes\");\n }\n\n set acceptMimes(value: string[]) {\n this.setRaw(\"acceptMimes\", value || []);\n }\n\n get converter(): Partial<ConverterSettings> {\n return this.get(\"converter\") || {};\n }\n\n set converter(options: Partial<ConverterSettings>) {\n this.setRaw(\"converter\", options);\n }\n\n get additionalProperties() {\n return this.get(\"converter.additionalProperties\") === \"accept\";\n }\n\n /**\n *\n * @returns {string|number}\n */\n getHttpPort(): ReturnType<typeof getHostInfoFromPort> {\n return getHostInfoFromPort(\"http\", this.getRaw(\"httpPort\"));\n }\n\n /**\n *\n * @param settings\n */\n setHttpPort(settings: {address: string; port: number}) {\n this.setRaw(\"httpPort\", `${settings.address}:${settings.port}`);\n }\n\n /**\n *\n * @returns {string|number}\n */\n getHttpsPort() {\n return getHostInfoFromPort(\"https\", this.getRaw(\"httpsPort\"));\n }\n\n /**\n *\n * @param settings\n */\n setHttpsPort(settings: {address: string; port: number}) {\n this.setRaw(\"httpsPort\", `${settings.address}:${settings.port}`);\n }\n\n getBestHost() {\n const {httpsPort, httpPort} = this;\n\n if (httpsPort) {\n return this.getHttpsPort();\n }\n\n if (httpPort) {\n return this.getHttpPort();\n }\n\n return {\n toString() {\n return \"/\";\n }\n };\n }\n}\n"]}
|
|
@@ -11,7 +11,7 @@ const platform_params_1 = require("@tsed/platform-params");
|
|
|
11
11
|
function Err() {
|
|
12
12
|
return (0, platform_params_1.UseParam)({
|
|
13
13
|
paramType: platform_params_1.ParamTypes.ERR,
|
|
14
|
-
dataPath: "
|
|
14
|
+
dataPath: "$ctx.error",
|
|
15
15
|
useValidation: false,
|
|
16
16
|
useConverter: false
|
|
17
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../src/decorators/params/error.ts"],"names":[],"mappings":";;;AAAA,2DAA2D;AAE3D;;;;;GAKG;AACH,SAAgB,GAAG;IACjB,OAAO,IAAA,0BAAQ,EAAC;QACd,SAAS,EAAE,4BAAU,CAAC,GAAG;QACzB,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../src/decorators/params/error.ts"],"names":[],"mappings":";;;AAAA,2DAA2D;AAE3D;;;;;GAKG;AACH,SAAgB,GAAG;IACjB,OAAO,IAAA,0BAAQ,EAAC;QACd,SAAS,EAAE,4BAAU,CAAC,GAAG;QACzB,QAAQ,EAAE,YAAY;QACtB,aAAa,EAAE,KAAK;QACpB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;AACL,CAAC;AAPD,kBAOC","sourcesContent":["import {ParamTypes, UseParam} from \"@tsed/platform-params\";\n\n/**\n * @returns {Function}\n * @decorator\n * @operation\n * @input\n */\nexport function Err(): Function {\n return UseParam({\n paramType: ParamTypes.ERR,\n dataPath: \"$ctx.error\",\n useValidation: false,\n useConverter: false\n });\n}\n"]}
|
|
@@ -3,21 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AnyToPromiseWithCtx = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
class AnyToPromiseWithCtx extends core_1.AnyToPromise {
|
|
6
|
-
|
|
6
|
+
$ctx;
|
|
7
|
+
constructor($ctx) {
|
|
7
8
|
super();
|
|
8
9
|
this.$ctx = $ctx;
|
|
9
|
-
this.err = err;
|
|
10
10
|
}
|
|
11
11
|
isDone() {
|
|
12
12
|
const { $ctx } = this;
|
|
13
|
-
return
|
|
13
|
+
return $ctx?.isDone() || super.isDone();
|
|
14
14
|
}
|
|
15
15
|
async call(cb) {
|
|
16
16
|
return super.call(() => cb(this));
|
|
17
17
|
}
|
|
18
18
|
destroy() {
|
|
19
|
-
|
|
20
|
-
delete this.$ctx;
|
|
19
|
+
this.$ctx = null;
|
|
21
20
|
}
|
|
22
21
|
isCanceledResponse(process) {
|
|
23
22
|
return process === this.$ctx.getResponse();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnyToPromiseWithCtx.js","sourceRoot":"","sources":["../../../src/domain/AnyToPromiseWithCtx.ts"],"names":[],"mappings":";;;AAAA,qCAA0D;
|
|
1
|
+
{"version":3,"file":"AnyToPromiseWithCtx.js","sourceRoot":"","sources":["../../../src/domain/AnyToPromiseWithCtx.ts"],"names":[],"mappings":";;;AAAA,qCAA0D;AAG1D,MAAa,mBAAoB,SAAQ,mBAAY;IAC5C,IAAI,CAAkB;IAE7B,YAAY,IAAqB;QAC/B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,MAAM;QACJ,MAAM,EAAC,IAAI,EAAC,GAAG,IAAI,CAAC;QAEpB,OAAO,IAAI,EAAE,MAAM,EAAE,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAY;QACrB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACJ,IAAI,CAAC,IAAY,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,kBAAkB,CAAC,OAAY;QAC7B,OAAO,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IAC7C,CAAC;CACF;AAzBD,kDAyBC","sourcesContent":["import {AnyPromiseResult, AnyToPromise} from \"@tsed/core\";\nimport {PlatformContext} from \"./PlatformContext\";\n\nexport class AnyToPromiseWithCtx extends AnyToPromise {\n public $ctx: PlatformContext;\n\n constructor($ctx: PlatformContext) {\n super();\n this.$ctx = $ctx;\n }\n\n isDone(): boolean {\n const {$ctx} = this;\n\n return $ctx?.isDone() || super.isDone();\n }\n\n async call(cb: Function): Promise<AnyPromiseResult<any>> {\n return super.call(() => cb(this));\n }\n\n destroy() {\n (this.$ctx as any) = null;\n }\n\n isCanceledResponse(process: any) {\n return process === this.$ctx.getResponse();\n }\n}\n"]}
|