@tsed/common 7.0.0-beta.2 → 7.0.0-beta.20
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 +94 -65
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -1
- package/lib/cjs/config/services/PlatformConfiguration.js +2 -66
- package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
- package/lib/cjs/decorators/multer/multipartFile.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/EndpointMetadata.js +2 -66
- package/lib/cjs/domain/EndpointMetadata.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 +32 -0
- package/lib/cjs/exports.js.map +1 -0
- package/lib/cjs/index.js +58 -30
- 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 +10 -9
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js +27 -13
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/FakeAdapter.js +49 -0
- package/lib/cjs/services/FakeAdapter.js.map +1 -0
- package/lib/cjs/services/Platform.js +33 -68
- package/lib/cjs/services/Platform.js.map +1 -1
- package/lib/cjs/services/PlatformAdapter.js +24 -0
- package/lib/cjs/services/PlatformAdapter.js.map +1 -0
- package/lib/cjs/services/PlatformApplication.js +26 -14
- package/lib/cjs/services/PlatformApplication.js.map +1 -1
- package/lib/cjs/services/PlatformHandler.js +115 -172
- package/lib/cjs/services/PlatformHandler.js.map +1 -1
- package/lib/cjs/services/PlatformMiddlewaresChain.js +46 -19
- package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/cjs/services/PlatformRequest.js +17 -13
- package/lib/cjs/services/PlatformRequest.js.map +1 -1
- package/lib/cjs/services/PlatformResponse.js +20 -23
- package/lib/cjs/services/PlatformResponse.js.map +1 -1
- package/lib/cjs/services/PlatformTest.js +31 -10
- 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 +6 -11
- package/lib/cjs/utils/createHttpServer.js.map +1 -1
- package/lib/cjs/utils/createHttpsServer.js +6 -11
- package/lib/cjs/utils/createHttpsServer.js.map +1 -1
- package/lib/cjs/utils/createInjector.js +16 -10
- 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 +74 -68
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/esm/config/interfaces/PlatformMulterSettings.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/multer/multerFileSize.js +1 -1
- package/lib/esm/decorators/multer/multerOptions.js +1 -1
- package/lib/esm/decorators/multer/multipartFile.js +1 -1
- package/lib/esm/decorators/multer/multipartFile.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/EndpointMetadata.js +1 -66
- package/lib/esm/domain/EndpointMetadata.js.map +1 -1
- package/lib/esm/domain/PlatformContext.js +49 -41
- 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 +14 -0
- package/lib/esm/exports.js.map +1 -0
- package/lib/esm/index.js +58 -27
- 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 +18 -5
- package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/FakeAdapter.js +45 -0
- package/lib/esm/services/FakeAdapter.js.map +1 -0
- package/lib/esm/services/Platform.js +34 -69
- package/lib/esm/services/Platform.js.map +1 -1
- package/lib/esm/services/PlatformAdapter.js +20 -0
- package/lib/esm/services/PlatformAdapter.js.map +1 -0
- package/lib/esm/services/PlatformApplication.js +27 -15
- package/lib/esm/services/PlatformApplication.js.map +1 -1
- package/lib/esm/services/PlatformHandler.js +116 -173
- package/lib/esm/services/PlatformHandler.js.map +1 -1
- package/lib/esm/services/PlatformMiddlewaresChain.js +49 -22
- 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 +34 -14
- package/lib/esm/services/PlatformTest.js.map +1 -1
- package/lib/esm/utils/createContext.js +33 -23
- package/lib/esm/utils/createContext.js.map +1 -1
- package/lib/esm/utils/createHttpServer.js +6 -11
- package/lib/esm/utils/createHttpServer.js.map +1 -1
- package/lib/esm/utils/createHttpsServer.js +6 -11
- package/lib/esm/utils/createHttpsServer.js.map +1 -1
- package/lib/esm/utils/createInjector.js +20 -14
- 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 +19 -17
- package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +2 -43
- package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +6 -130
- package/lib/types/config/services/PlatformConfiguration.d.ts +6 -21
- package/lib/types/domain/AnyToPromiseWithCtx.d.ts +1 -9
- package/lib/types/domain/EndpointMetadata.d.ts +1 -50
- package/lib/types/domain/PlatformContext.d.ts +32 -18
- package/lib/types/domain/PlatformRouteDetails.d.ts +4 -20
- package/lib/types/exports.d.ts +13 -0
- package/lib/types/index.d.ts +56 -18
- package/lib/types/interfaces/PlatformRouteOptions.d.ts +1 -2
- package/lib/types/interfaces/Route.d.ts +2 -3
- package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +8 -3
- package/lib/types/services/FakeAdapter.d.ts +31 -0
- package/lib/types/services/Platform.d.ts +9 -21
- package/lib/types/services/PlatformAdapter.d.ts +58 -0
- package/lib/types/services/PlatformApplication.d.ts +15 -7
- package/lib/types/services/PlatformHandler.d.ts +21 -59
- package/lib/types/services/PlatformMiddlewaresChain.d.ts +6 -3
- package/lib/types/services/PlatformRequest.d.ts +8 -10
- package/lib/types/services/PlatformResponse.d.ts +15 -19
- package/lib/types/services/PlatformTest.d.ts +5 -4
- package/lib/types/utils/createContext.d.ts +4 -1
- package/lib/types/utils/createHttpServer.d.ts +1 -1
- package/lib/types/utils/createHttpsServer.d.ts +3 -1
- package/lib/types/utils/createInjector.d.ts +5 -3
- package/lib/types/utils/ensureContext.d.ts +2 -0
- package/lib/types/utils/listenServer.d.ts +2 -0
- package/package.json +43 -26
- package/readme.md +52 -58
- package/tsconfig.compile.esm.json +2 -12
- package/lib/cjs/builder/PlatformControllerBuilder.js +0 -85
- package/lib/cjs/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/cjs/config/index.js +0 -7
- package/lib/cjs/config/index.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/config/interfaces/index.js +0 -8
- package/lib/cjs/config/interfaces/index.js.map +0 -1
- package/lib/cjs/decorators/httpServer.js +0 -32
- package/lib/cjs/decorators/httpServer.js.map +0 -1
- package/lib/cjs/decorators/httpsServer.js +0 -32
- package/lib/cjs/decorators/httpsServer.js.map +0 -1
- package/lib/cjs/decorators/index.js +0 -21
- package/lib/cjs/decorators/index.js.map +0 -1
- package/lib/cjs/decorators/method/acceptMime.js +0 -28
- package/lib/cjs/decorators/method/acceptMime.js.map +0 -1
- package/lib/cjs/decorators/method/endpointFn.js +0 -15
- package/lib/cjs/decorators/method/endpointFn.js.map +0 -1
- package/lib/cjs/decorators/method/location.js +0 -6
- package/lib/cjs/decorators/method/location.js.map +0 -1
- package/lib/cjs/decorators/method/redirect.js +0 -6
- package/lib/cjs/decorators/method/redirect.js.map +0 -1
- package/lib/cjs/decorators/method/route.js +0 -13
- package/lib/cjs/decorators/method/route.js.map +0 -1
- package/lib/cjs/decorators/method/view.js +0 -34
- package/lib/cjs/decorators/method/view.js.map +0 -1
- package/lib/cjs/decorators/multer/index.js +0 -7
- package/lib/cjs/decorators/multer/index.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/domain/index.js +0 -10
- package/lib/cjs/domain/index.js.map +0 -1
- package/lib/cjs/interfaces/PathType.js +0 -3
- package/lib/cjs/interfaces/PathType.js.map +0 -1
- package/lib/cjs/interfaces/PlatformAdapter.js +0 -3
- package/lib/cjs/interfaces/PlatformAdapter.js.map +0 -1
- package/lib/cjs/interfaces/index.js +0 -21
- package/lib/cjs/interfaces/index.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/middlewares/index.js +0 -7
- package/lib/cjs/middlewares/index.js.map +0 -1
- package/lib/cjs/services/FakeRawDriver.js +0 -26
- package/lib/cjs/services/FakeRawDriver.js.map +0 -1
- package/lib/cjs/services/PlatformRouter.js +0 -126
- package/lib/cjs/services/PlatformRouter.js.map +0 -1
- package/lib/cjs/services/index.js +0 -12
- package/lib/cjs/services/index.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/index.js +0 -11
- package/lib/cjs/utils/index.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 -79
- package/lib/esm/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/esm/config/index.js +0 -4
- package/lib/esm/config/index.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/config/interfaces/index.js +0 -5
- package/lib/esm/config/interfaces/index.js.map +0 -1
- package/lib/esm/decorators/httpServer.js +0 -28
- package/lib/esm/decorators/httpServer.js.map +0 -1
- package/lib/esm/decorators/httpsServer.js +0 -28
- package/lib/esm/decorators/httpsServer.js.map +0 -1
- package/lib/esm/decorators/index.js +0 -18
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/esm/decorators/method/acceptMime.js +0 -24
- package/lib/esm/decorators/method/acceptMime.js.map +0 -1
- package/lib/esm/decorators/method/endpointFn.js +0 -11
- package/lib/esm/decorators/method/endpointFn.js.map +0 -1
- package/lib/esm/decorators/method/location.js +0 -2
- package/lib/esm/decorators/method/location.js.map +0 -1
- package/lib/esm/decorators/method/redirect.js +0 -2
- package/lib/esm/decorators/method/redirect.js.map +0 -1
- package/lib/esm/decorators/method/route.js +0 -2
- package/lib/esm/decorators/method/route.js.map +0 -1
- package/lib/esm/decorators/method/view.js +0 -30
- package/lib/esm/decorators/method/view.js.map +0 -1
- package/lib/esm/decorators/multer/index.js +0 -4
- package/lib/esm/decorators/multer/index.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/domain/index.js +0 -7
- package/lib/esm/domain/index.js.map +0 -1
- package/lib/esm/interfaces/PathType.js +0 -2
- package/lib/esm/interfaces/PathType.js.map +0 -1
- package/lib/esm/interfaces/PlatformAdapter.js +0 -2
- package/lib/esm/interfaces/PlatformAdapter.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -18
- package/lib/esm/interfaces/index.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/middlewares/index.js +0 -4
- package/lib/esm/middlewares/index.js.map +0 -1
- package/lib/esm/services/FakeRawDriver.js +0 -22
- package/lib/esm/services/FakeRawDriver.js.map +0 -1
- package/lib/esm/services/PlatformRouter.js +0 -123
- package/lib/esm/services/PlatformRouter.js.map +0 -1
- package/lib/esm/services/index.js +0 -9
- package/lib/esm/services/index.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/index.js +0 -8
- package/lib/esm/utils/index.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 -17
- package/lib/types/config/index.d.ts +0 -3
- package/lib/types/config/interfaces/EndpointDirectoriesSettings.d.ts +0 -3
- package/lib/types/config/interfaces/index.d.ts +0 -97
- package/lib/types/decorators/httpServer.d.ts +0 -28
- package/lib/types/decorators/httpsServer.d.ts +0 -28
- package/lib/types/decorators/index.d.ts +0 -14
- package/lib/types/decorators/method/acceptMime.d.ts +0 -19
- package/lib/types/decorators/method/endpointFn.d.ts +0 -9
- package/lib/types/decorators/method/location.d.ts +0 -1
- package/lib/types/decorators/method/redirect.d.ts +0 -1
- package/lib/types/decorators/method/route.d.ts +0 -1
- package/lib/types/decorators/method/view.d.ts +0 -25
- package/lib/types/decorators/multer/index.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/domain/index.d.ts +0 -6
- package/lib/types/interfaces/PathType.d.ts +0 -1
- package/lib/types/interfaces/PlatformAdapter.d.ts +0 -19
- package/lib/types/interfaces/index.d.ts +0 -17
- package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +0 -2
- package/lib/types/middlewares/bindEndpointMiddleware.d.ts +0 -5
- package/lib/types/middlewares/index.d.ts +0 -3
- package/lib/types/services/FakeRawDriver.d.ts +0 -15
- package/lib/types/services/PlatformRouter.d.ts +0 -48
- package/lib/types/services/index.d.ts +0 -8
- package/lib/types/utils/createHandlerMetadata.d.ts +0 -8
- package/lib/types/utils/index.d.ts +0 -7
- 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,50 +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
|
-
const components_scan_1 = require("@tsed/components-scan");
|
|
9
29
|
const platform_middlewares_1 = require("@tsed/platform-middlewares");
|
|
10
30
|
const Platform_1 = require("../services/Platform");
|
|
31
|
+
const PlatformAdapter_1 = require("../services/PlatformAdapter");
|
|
11
32
|
const PlatformApplication_1 = require("../services/PlatformApplication");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
33
|
+
const createHttpServer_1 = require("../utils/createHttpServer");
|
|
34
|
+
const createHttpsServer_1 = require("../utils/createHttpsServer");
|
|
35
|
+
const createInjector_1 = require("../utils/createInjector");
|
|
14
36
|
const getConfiguration_1 = require("../utils/getConfiguration");
|
|
37
|
+
const getStaticsOptions_1 = require("../utils/getStaticsOptions");
|
|
38
|
+
const printRoutes_1 = require("../utils/printRoutes");
|
|
15
39
|
/**
|
|
16
40
|
* @platform
|
|
17
41
|
*/
|
|
18
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 = [];
|
|
19
53
|
constructor(adapter, module, settings) {
|
|
20
|
-
this
|
|
21
|
-
|
|
22
|
-
this.current = new Date();
|
|
23
|
-
_PlatformBuilder_injector.set(this, void 0);
|
|
24
|
-
_PlatformBuilder_rootModule.set(this, void 0);
|
|
25
|
-
_PlatformBuilder_promise.set(this, void 0);
|
|
26
|
-
_PlatformBuilder_adapter.set(this, void 0);
|
|
27
|
-
_PlatformBuilder_servers.set(this, void 0);
|
|
28
|
-
(0, tslib_1.__classPrivateFieldSet)(this, _PlatformBuilder_rootModule, module, "f");
|
|
54
|
+
this.#rootModule = module;
|
|
55
|
+
const configuration = (0, getConfiguration_1.getConfiguration)(settings, module);
|
|
29
56
|
const adapterKlass = adapter || PlatformBuilder.adapter;
|
|
30
57
|
const name = (0, core_1.nameOf)(adapterKlass).replace("Platform", "").toLowerCase();
|
|
31
|
-
const configuration = (0, getConfiguration_1.getConfiguration)(settings, module);
|
|
32
58
|
configuration.PLATFORM_NAME = name;
|
|
33
59
|
this.name = name;
|
|
34
|
-
(0,
|
|
35
|
-
|
|
36
|
-
settings: configuration
|
|
37
|
-
|
|
38
|
-
|
|
60
|
+
this.#injector = (0, createInjector_1.createInjector)({
|
|
61
|
+
adapter: adapterKlass,
|
|
62
|
+
settings: configuration
|
|
63
|
+
});
|
|
64
|
+
this.#adapter = this.#injector.get(PlatformAdapter_1.PlatformAdapter);
|
|
39
65
|
this.createHttpServers();
|
|
40
|
-
|
|
66
|
+
this.#adapter.onInit && this.#adapter.onInit();
|
|
41
67
|
this.log("Injector created...");
|
|
42
68
|
}
|
|
43
69
|
get injector() {
|
|
44
|
-
return
|
|
70
|
+
return this.#injector;
|
|
45
71
|
}
|
|
46
72
|
get rootModule() {
|
|
47
|
-
return
|
|
73
|
+
return this.#injector.get(this.#rootModule);
|
|
48
74
|
}
|
|
49
75
|
get app() {
|
|
50
76
|
return this.injector.get(PlatformApplication_1.PlatformApplication);
|
|
@@ -52,6 +78,9 @@ class PlatformBuilder {
|
|
|
52
78
|
get platform() {
|
|
53
79
|
return this.injector.get(Platform_1.Platform);
|
|
54
80
|
}
|
|
81
|
+
get adapter() {
|
|
82
|
+
return this.#adapter;
|
|
83
|
+
}
|
|
55
84
|
/**
|
|
56
85
|
* Return the settings configured by the decorator @@Configuration@@.
|
|
57
86
|
*
|
|
@@ -80,15 +109,13 @@ class PlatformBuilder {
|
|
|
80
109
|
return this.injector.logger;
|
|
81
110
|
}
|
|
82
111
|
get disableBootstrapLog() {
|
|
83
|
-
|
|
84
|
-
return (_a = this.settings.logger) === null || _a === void 0 ? void 0 : _a.disableBootstrapLog;
|
|
112
|
+
return this.settings.get("logger.disableBootstrapLog");
|
|
85
113
|
}
|
|
86
114
|
static create(module, settings) {
|
|
87
115
|
return this.build(module, {
|
|
88
116
|
httpsPort: false,
|
|
89
117
|
httpPort: false,
|
|
90
|
-
...settings
|
|
91
|
-
disableComponentsScan: true
|
|
118
|
+
...settings
|
|
92
119
|
});
|
|
93
120
|
}
|
|
94
121
|
static build(module, { adapter, ...settings }) {
|
|
@@ -104,7 +131,7 @@ class PlatformBuilder {
|
|
|
104
131
|
}
|
|
105
132
|
callback(req, res) {
|
|
106
133
|
if (req && res) {
|
|
107
|
-
return this.
|
|
134
|
+
return this.callback()(req, res);
|
|
108
135
|
}
|
|
109
136
|
return this.app.callback();
|
|
110
137
|
}
|
|
@@ -116,7 +143,7 @@ class PlatformBuilder {
|
|
|
116
143
|
* @param classes
|
|
117
144
|
*/
|
|
118
145
|
addComponents(classes) {
|
|
119
|
-
this.settings.
|
|
146
|
+
this.settings.set("imports", this.settings.get("imports", []).concat(classes));
|
|
120
147
|
return this;
|
|
121
148
|
}
|
|
122
149
|
/**
|
|
@@ -140,32 +167,26 @@ class PlatformBuilder {
|
|
|
140
167
|
* @param {any[]} controllers
|
|
141
168
|
*/
|
|
142
169
|
addControllers(endpoint, controllers) {
|
|
143
|
-
|
|
170
|
+
[].concat(controllers).forEach((token) => {
|
|
171
|
+
this.settings.routes.push({ token, route: endpoint });
|
|
172
|
+
});
|
|
144
173
|
}
|
|
145
174
|
async runLifecycle() {
|
|
146
|
-
(0, di_1.
|
|
147
|
-
await this.importProviders();
|
|
175
|
+
(0, di_1.setLoggerConfiguration)(this.injector);
|
|
148
176
|
await this.loadInjector();
|
|
149
|
-
|
|
150
|
-
(0, tslib_1.__classPrivateFieldGet)(this, _PlatformBuilder_adapter, "f").useRouter && (0, tslib_1.__classPrivateFieldGet)(this, _PlatformBuilder_adapter, "f").useRouter();
|
|
177
|
+
this.#adapter.useContext();
|
|
151
178
|
await this.loadRoutes();
|
|
152
|
-
await this.logRoutes();
|
|
153
179
|
return this;
|
|
154
180
|
}
|
|
155
181
|
async loadInjector() {
|
|
156
182
|
const { injector } = this;
|
|
157
183
|
this.log("Build providers");
|
|
158
|
-
|
|
159
|
-
container.addProvider((0, tslib_1.__classPrivateFieldGet)(this, _PlatformBuilder_rootModule, "f"), {
|
|
160
|
-
type: "server:module",
|
|
161
|
-
scope: di_1.ProviderScope.SINGLETON
|
|
162
|
-
});
|
|
163
|
-
await injector.load(container);
|
|
184
|
+
await injector.loadModule(this.#rootModule);
|
|
164
185
|
this.log("Settings and injector loaded...");
|
|
165
186
|
await this.callHook("$afterInit");
|
|
166
187
|
}
|
|
167
188
|
async listen(network = true) {
|
|
168
|
-
if (!
|
|
189
|
+
if (!this.#promise) {
|
|
169
190
|
await this.bootstrap();
|
|
170
191
|
}
|
|
171
192
|
await this.callHook("$beforeListen");
|
|
@@ -177,7 +198,10 @@ class PlatformBuilder {
|
|
|
177
198
|
}
|
|
178
199
|
async stop() {
|
|
179
200
|
await this.callHook("$onDestroy");
|
|
180
|
-
|
|
201
|
+
await this.injector.destroy();
|
|
202
|
+
this.#listeners.map((server) => {
|
|
203
|
+
return new Promise((resolve) => server.close(() => resolve(undefined)));
|
|
204
|
+
});
|
|
181
205
|
}
|
|
182
206
|
async ready() {
|
|
183
207
|
const { startedAt } = this;
|
|
@@ -208,15 +232,14 @@ class PlatformBuilder {
|
|
|
208
232
|
return this;
|
|
209
233
|
}
|
|
210
234
|
async bootstrap() {
|
|
211
|
-
|
|
212
|
-
return
|
|
235
|
+
this.#promise = this.#promise || this.runLifecycle();
|
|
236
|
+
return this.#promise;
|
|
213
237
|
}
|
|
214
238
|
async loadRoutes() {
|
|
215
|
-
|
|
216
|
-
(0, tslib_1.__classPrivateFieldGet)(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes && (await (0, tslib_1.__classPrivateFieldGet)(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes());
|
|
239
|
+
this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());
|
|
217
240
|
// istanbul ignore next
|
|
218
|
-
if (
|
|
219
|
-
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")));
|
|
220
243
|
this.app.use(PlatformLogMiddleware);
|
|
221
244
|
}
|
|
222
245
|
this.log("Load routes");
|
|
@@ -231,20 +254,19 @@ class PlatformBuilder {
|
|
|
231
254
|
await this.callHook("$onRoutesInit");
|
|
232
255
|
await this.loadStatics("$afterRoutesInit");
|
|
233
256
|
await this.callHook("$afterRoutesInit");
|
|
234
|
-
|
|
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()));
|
|
235
264
|
}
|
|
236
265
|
diff() {
|
|
237
266
|
const ms = di_1.colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);
|
|
238
267
|
this.current = new Date();
|
|
239
268
|
return ms;
|
|
240
269
|
}
|
|
241
|
-
async importProviders() {
|
|
242
|
-
this.injector.logger.debug("Scan components");
|
|
243
|
-
const providers = await (0, components_scan_1.importProviders)(this.injector.settings, ["imports", "mount", "componentsScan"]);
|
|
244
|
-
const routes = providers.filter((provider) => !!provider.route).map(({ route, token }) => ({ route, token }));
|
|
245
|
-
this.settings.set("routes", routes);
|
|
246
|
-
this.log("Providers loaded...");
|
|
247
|
-
}
|
|
248
270
|
/**
|
|
249
271
|
* Load middlewares from configuration for the given hook
|
|
250
272
|
* @param hook
|
|
@@ -256,20 +278,27 @@ class PlatformBuilder {
|
|
|
256
278
|
});
|
|
257
279
|
}
|
|
258
280
|
createHttpServers() {
|
|
259
|
-
|
|
281
|
+
this.#servers = [(0, createHttpServer_1.createHttpServer)(this.#injector, this.callback()), (0, createHttpsServer_1.createHttpsServer)(this.#injector, this.callback())].filter(Boolean);
|
|
260
282
|
}
|
|
261
283
|
async listenServers() {
|
|
262
|
-
await Promise.all(
|
|
284
|
+
this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));
|
|
263
285
|
}
|
|
264
|
-
async logRoutes() {
|
|
265
|
-
|
|
266
|
-
const { logger, platform } = this;
|
|
286
|
+
async logRoutes(layers) {
|
|
287
|
+
const { logger } = this;
|
|
267
288
|
this.log("Routes mounted...");
|
|
268
|
-
if (!
|
|
269
|
-
|
|
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)));
|
|
270
300
|
}
|
|
271
301
|
}
|
|
272
302
|
}
|
|
273
303
|
exports.PlatformBuilder = PlatformBuilder;
|
|
274
|
-
_PlatformBuilder_injector = new WeakMap(), _PlatformBuilder_rootModule = new WeakMap(), _PlatformBuilder_promise = new WeakMap(), _PlatformBuilder_adapter = new WeakMap(), _PlatformBuilder_servers = new WeakMap();
|
|
275
304
|
//# sourceMappingURL=PlatformBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":";;;;;AAAA,qCAAwC;AACxC,iCAA4G;AAC5G,2DAAsD;AACtD,qEAAiE;AACjE,mDAA8C;AAC9C,yEAAoE;AACpE,oCAA0F;AAE1F,kEAA6D;AAE7D,gEAA2D;AAI3D;;GAEG;AACH,MAAa,eAAe;IAa1B,YAAsB,OAAuD,EAAE,MAAY,EAAE,QAAqC;QAVzH,SAAI,GAAW,EAAE,CAAC;QACjB,cAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,YAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QAE/B,4CAA2B;QAC3B,8CAAuB;QACvB,2CAAwB;QACxB,2CAAuC;QACvC,2CAAkC;QAGhC,oCAAA,IAAI,+BAAe,MAAM,MAAA,CAAC;QAC1B,MAAM,YAAY,GAAG,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC;QACxD,MAAM,IAAI,GAAG,IAAA,aAAM,EAAC,YAAY,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAExE,MAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzD,aAAa,CAAC,aAAa,GAAG,IAAI,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,C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C;CACF;AA9UD,0CA8UC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, createContainer, InjectorService, IProvider, ProviderScope, setLoggerLevel} from \"@tsed/di\";\nimport {importProviders} from \"@tsed/components-scan\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {createHttpServer, createHttpsServer, createInjector, printRoutes} from \"../utils\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {Route} from \"../interfaces/Route\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {IncomingMessage, ServerResponse} from \"http\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../interfaces/PlatformAdapter\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {\n public static adapter: Type<PlatformAdapter>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n\n #injector: InjectorService;\n #rootModule: Type<any>;\n #promise: Promise<this>;\n #adapter: PlatformAdapter<App, Router>;\n #servers: (() => Promise<void>)[];\n\n protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n const adapterKlass = adapter || PlatformBuilder.adapter;\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 this.#adapter = new adapterKlass(this);\n\n this.#injector = createInjector({\n settings: configuration,\n providers: this.#adapter.providers\n });\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 /**\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 return this.injector.destroy();\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<IProvider>) {\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 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,IAAI,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAA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C,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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformMulterSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformMulterSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"PlatformMulterSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformMulterSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {Express} from \"express\";\nimport type multer from \"multer\";\n\ndeclare global {\n namespace TsED {\n export type MulterFile = Express.Multer.File;\n export type MulterStorageEngine = multer.StorageEngine;\n export type MulterOptions = multer.Options;\n export type MulterField = multer.Field;\n export type Multer = multer.Multer;\n }\n}\n\nexport type PlatformMulter = TsED.Multer;\nexport type PlatformMulterSettings = TsED.MulterOptions;\nexport type PlatformMulterFile = TsED.MulterFile;\nexport type PlatformMulterField = TsED.MulterField;\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
|
}
|
|
@@ -170,12 +106,12 @@ let PlatformConfiguration = class PlatformConfiguration extends di_1.DIConfigura
|
|
|
170
106
|
};
|
|
171
107
|
}
|
|
172
108
|
};
|
|
173
|
-
PlatformConfiguration =
|
|
109
|
+
PlatformConfiguration = tslib_1.__decorate([
|
|
174
110
|
(0, di_1.Injectable)({
|
|
175
111
|
scope: di_1.ProviderScope.SINGLETON,
|
|
176
112
|
global: true
|
|
177
113
|
}),
|
|
178
|
-
|
|
114
|
+
tslib_1.__metadata("design:paramtypes", [])
|
|
179
115
|
], PlatformConfiguration);
|
|
180
116
|
exports.PlatformConfiguration = PlatformConfiguration;
|
|
181
117
|
//# sourceMappingURL=PlatformConfiguration.js.map
|
|
@@ -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;AACpD,iCAAmF;AAInF,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAE9B;;GAEG;AAKH,IAAa,qBAAqB,GAAlC,MAAa,qBAAsB,SAAQ,oBAAe;IACxD;QACE,KAAK,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,IAAI,CAAC,KAA8B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,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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipartFile.js","sourceRoot":"","sources":["../../../../src/decorators/multer/multipartFile.ts"],"names":[],"mappings":";;;AAAA,qCAAyG;AACzG,2DAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"multipartFile.js","sourceRoot":"","sources":["../../../../src/decorators/multer/multipartFile.ts"],"names":[],"mappings":";;;AAAA,qCAAyG;AACzG,2DAA2D;AAC3D,yCAAoC;AAEpC,yFAAwG;AAExG,SAAS,UAAU,CAAC,IAAY,EAAE,QAA4B;IAC5D,OAAO;QACL,MAAM,EAAE;YACN;gBACE,IAAI;gBACJ,QAAQ;aACT;SACF;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,SAAgB,aAAa,CAAC,IAAY,EAAE,QAAiB;IAC3D,OAAO,CAAC,GAAG,IAAyB,EAAQ,EAAE;QAC5C,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;QAC1C,MAAM,QAAQ,GAAG,eAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,KAAe,CAAC,KAAK,KAAK,CAAC;QAExF,IAAI,GAAG,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAE,CAAC;QAEtD,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,CAAC,QAAQ,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEtE,MAAM,UAAU,GAAG,IAAA,oBAAa,EAC9B,IAAA,eAAM,EAAC,IAAI,CAAC,EACZ,IAAA,0BAAmB,EAAC,IAAA,iBAAU,EAAC,mDAAwB,EAAE,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrF,IAAA,0BAAQ,EAAC;YACP,SAAS,EAAE,4BAAU,CAAC,KAAK;YAC3B,QAAQ,EAAE,oBAAoB;YAC9B,UAAU;YACV,aAAa,EAAE,IAAI;SACpB,CAAC,CACH,CAAC;QAEF,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC;AAtBD,sCAsBC","sourcesContent":["import {DecoratorParameters, Metadata, StoreMerge, useDecorators, useMethodDecorators} from \"@tsed/core\";\nimport {ParamTypes, UseParam} from \"@tsed/platform-params\";\nimport {InFile} from \"@tsed/schema\";\nimport {PlatformMulterFile} from \"../../config/interfaces/PlatformMulterSettings\";\nimport {MulterInputOptions, PlatformMulterMiddleware} from \"../../middlewares/PlatformMulterMiddleware\";\n\nfunction mapOptions(name: string, maxCount: number | undefined): MulterInputOptions {\n return {\n fields: [\n {\n name,\n maxCount\n }\n ]\n };\n}\n\n/**\n * Define a parameter as Multipart file.\n *\n * ```typescript\n * import {Controller, Post} from \"@tsed/common\";\n * import {MulterOptions, MultipartFile} from \"@tsed/common\";\n * import {Multer} from \"@types/multer\";\n *\n * type MulterFile = Express.Multer.File;\n *\n * @Controller('/')\n * class MyCtrl {\n * @Post('/file')\n * private uploadFile(@MultipartFile(\"file1\") file: MulterFile) {\n *\n * }\n *\n * @Post('/file')\n * @MulterOptions({dest: \"/other-dir\"})\n * private uploadFile(@MultipartFile(\"file1\") file: MulterFile) {\n *\n * }\n *\n * @Post('/file2')\n * @MulterOptions({dest: \"/other-dir\"})\n * private uploadFile(@MultipartFile(\"file1\") file: MulterFile, @MultipartFile(\"file2\") file2: MulterFile) {\n *\n * }\n *\n * @Post('/files')\n * private uploadFile(@MultipartFile(\"file1\") files: MulterFile[]) {\n *\n * }\n * }\n * ```\n *\n * > See the tutorial on the [multer configuration](/tutorials/multer.md).\n *\n * @param name\n * @param maxCount\n * @returns Function\n * @decorator\n * @input\n */\nexport function MultipartFile(name: string, maxCount?: number): ParameterDecorator {\n return (...args: DecoratorParameters): void => {\n const [target, propertyKey, index] = args;\n const multiple = Metadata.getParamTypes(target, propertyKey)[index as number] === Array;\n\n name = (typeof name === \"object\" ? undefined : name)!;\n\n const expression = [name, !multiple && \"0\"].filter(Boolean).join(\".\");\n\n const decorators = useDecorators(\n InFile(name),\n useMethodDecorators(StoreMerge(PlatformMulterMiddleware, mapOptions(name, maxCount))),\n UseParam({\n paramType: ParamTypes.FILES,\n dataPath: \"$ctx.request.files\",\n expression,\n useValidation: true\n })\n );\n\n decorators(...args);\n };\n}\n\nexport type MultipartFile = PlatformMulterFile;\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"]}
|