@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformRequest.ts"],"names":[],"mappings":";;;;AAAA,iCAA0D;
|
|
1
|
+
{"version":3,"file":"PlatformRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformRequest.ts"],"names":[],"mappings":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OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAc,CAAC;IACjC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAaD,OAAO,CAAC,IAAwB;QAC9B,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,GAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IACjC,CAAC;CACF,CAAA;AA5JY,eAAe;IAF3B,IAAA,eAAU,GAAE;IACZ,IAAA,UAAK,EAAC,kBAAa,CAAC,QAAQ,CAAC;;GACjB,eAAe,CA4J3B;AA5JY,0CAAe","sourcesContent":["import {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {IncomingHttpHeaders, IncomingMessage} from \"http\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\nimport type {PlatformResponse} from \"./PlatformResponse\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Request {\n id: string;\n }\n }\n}\n\n/**\n * Platform Request abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformRequest<Req extends {[key: string]: any} = any> {\n constructor(readonly $ctx: PlatformContext) {}\n\n /**\n * The current @@PlatformResponse@@.\n */\n get response(): PlatformResponse {\n return this.$ctx.response;\n }\n\n get raw(): Req {\n return this.$ctx.event.request as any;\n }\n\n get secure(): boolean {\n return this.raw.secure;\n }\n\n get host(): string {\n return this.get(\"host\");\n }\n\n get protocol(): string {\n return this.raw.protocol;\n }\n\n /**\n * Get the url of the request.\n *\n * Is equivalent of `express.response.originalUrl || express.response.url`.\n */\n get url(): string {\n return this.raw.originalUrl || this.raw.url;\n }\n\n get headers(): IncomingHttpHeaders {\n return this.raw.headers;\n }\n\n get method(): string {\n return this.raw.method;\n }\n\n /**\n * Contains key-value pairs of data submitted in the request body. By default, it is `undefined`, and is populated when you use\n * `body-parsing` middleware such as `express.json()` or `express.urlencoded()`.\n */\n get body(): any {\n return this.raw.body;\n }\n\n get rawBody(): any {\n return this.raw.rawBody || this.raw.body;\n }\n\n /**\n * When using `cookie-parser` middleware, this property is an object that contains cookies sent by the request.\n * If the request contains no cookies, it defaults to `{}`.\n */\n get cookies(): {[key: string]: any} {\n return this.raw.cookies;\n }\n\n /**\n * This property is an object containing properties mapped to the named route `parameters`.\n * For example, if you have the route `/user/:name`, then the `name` property is available as `req.params.name`.\n * This object defaults to `{}`.\n */\n get params(): {[key: string]: any} {\n return this.raw.params;\n }\n\n /**\n * This property is an object containing a property for each query string parameter in the route.\n * When query parser is set to disabled, it is an empty object `{}`, otherwise it is the result of the configured query parser.\n */\n get query(): {[key: string]: any} {\n return this.raw.query;\n }\n\n /**\n * This property is an object containing a property for each session attributes set by any code.\n * It require to install a middleware like express-session to work.\n */\n get session(): {[key: string]: any} {\n return this.raw.session as any;\n }\n\n get files() {\n return this.raw.files;\n }\n\n get route() {\n return this.$ctx.handlerMetadata?.path;\n }\n\n /**\n * Return the original request framework instance\n */\n get request() {\n return this.getRequest();\n }\n\n /**\n * Return the original request node.js instance\n */\n get req() {\n return this.getReq();\n }\n\n /**\n * Returns the HTTP request header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * request.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string) {\n return this.raw.get(name);\n }\n\n /**\n * Checks if the specified content types are acceptable, based on the request’s Accept HTTP header field. The method returns the best match, or if none of the specified content types is acceptable, returns false (in which case, the application should respond with 406 \"Not Acceptable\").\n *\n * The type value may be a single MIME type string (such as “application/json”), an extension name such as “json”, a comma-delimited list, or an array. For a list or array, the method returns the best match (if any).\n *\n * @param mime\n */\n accepts(mime: string): string | false;\n\n accepts(mime: string[]): string[] | false;\n\n accepts(mime?: string | string[]): string | string[] | false {\n // @ts-ignore\n return this.raw.accepts(mime);\n }\n\n isAborted() {\n return this.raw.aborted;\n }\n\n /**\n * Return the Framework response object (express, koa, etc...)\n */\n getRequest<R = Req>(): R {\n return this.raw as any;\n }\n\n /**\n * Return the Node.js response object\n */\n getReq(): IncomingMessage {\n return this.$ctx.event.request;\n }\n}\n"]}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var PlatformResponse_1;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.PlatformResponse = void 0;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
6
5
|
const core_1 = require("@tsed/core");
|
|
7
6
|
const di_1 = require("@tsed/di");
|
|
8
|
-
const on_finished_1 = tslib_1.__importDefault(require("on-finished"));
|
|
9
7
|
/**
|
|
10
8
|
* Platform Response abstraction layer.
|
|
11
9
|
* @platform
|
|
12
10
|
*/
|
|
13
|
-
let PlatformResponse =
|
|
14
|
-
|
|
11
|
+
let PlatformResponse = class PlatformResponse {
|
|
12
|
+
$ctx;
|
|
13
|
+
data;
|
|
14
|
+
constructor($ctx) {
|
|
15
15
|
this.$ctx = $ctx;
|
|
16
|
-
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The current @@PlatformRequest@@.
|
|
19
|
+
*/
|
|
20
|
+
get request() {
|
|
21
|
+
return this.$ctx.request;
|
|
22
|
+
}
|
|
23
|
+
get raw() {
|
|
24
|
+
return this.$ctx.event.response;
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
27
|
* Get the current statusCode
|
|
@@ -41,9 +49,6 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
41
49
|
get res() {
|
|
42
50
|
return this.getRes();
|
|
43
51
|
}
|
|
44
|
-
static onFinished(res, cb) {
|
|
45
|
-
(0, on_finished_1.default)(res, cb);
|
|
46
|
-
}
|
|
47
52
|
/**
|
|
48
53
|
* Returns the HTTP response header specified by field. The match is case-insensitive.
|
|
49
54
|
*
|
|
@@ -202,7 +207,7 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
202
207
|
* Send any data to your consumer.
|
|
203
208
|
*
|
|
204
209
|
* This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
|
|
205
|
-
* It
|
|
210
|
+
* It chooses the better way to send the data.
|
|
206
211
|
*
|
|
207
212
|
* @param data
|
|
208
213
|
*/
|
|
@@ -239,33 +244,25 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
|
239
244
|
* @param cb
|
|
240
245
|
*/
|
|
241
246
|
onEnd(cb) {
|
|
242
|
-
|
|
247
|
+
const res = this.getRes();
|
|
248
|
+
res.on("finish", cb);
|
|
243
249
|
return this;
|
|
244
250
|
}
|
|
245
251
|
isDone() {
|
|
246
|
-
if (
|
|
252
|
+
if (this.$ctx.isFinished()) {
|
|
247
253
|
return true;
|
|
248
254
|
}
|
|
249
255
|
const res = this.getRes();
|
|
250
256
|
return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);
|
|
251
257
|
}
|
|
252
|
-
destroy() {
|
|
253
|
-
// @ts-ignore
|
|
254
|
-
delete this.raw;
|
|
255
|
-
delete this.data;
|
|
256
|
-
// @ts-ignore
|
|
257
|
-
delete this.request;
|
|
258
|
-
// @ts-ignore
|
|
259
|
-
delete this.$ctx;
|
|
260
|
-
}
|
|
261
258
|
isHeadersSent() {
|
|
262
259
|
return this.getRes().headersSent;
|
|
263
260
|
}
|
|
264
261
|
};
|
|
265
|
-
PlatformResponse =
|
|
262
|
+
PlatformResponse = tslib_1.__decorate([
|
|
266
263
|
(0, di_1.Injectable)(),
|
|
267
264
|
(0, di_1.Scope)(di_1.ProviderScope.INSTANCE),
|
|
268
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
265
|
+
tslib_1.__metadata("design:paramtypes", [Function])
|
|
269
266
|
], PlatformResponse);
|
|
270
267
|
exports.PlatformResponse = PlatformResponse;
|
|
271
268
|
//# sourceMappingURL=PlatformResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformResponse.ts"],"names":[],"mappings":";;;;;AAAA,qCAAmE;AACnE,iCAA0D;AAE1D,sEAAqC;AAgBrC;;;GAGG;AAGH,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAU3B,YAAY,EAAC,QAAQ,EAAgB,EAAY,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QACpE,IAAI,CAAC,GAAG,GAAG,QAAe,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAI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,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,EAA+C;QACnD,kBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QAE/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YACb,OAAO,IAAI,CAAC;SACb;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAE1B,OAAO,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACpF,CAAC;IAED,OAAO;QACL,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC;QACjB,aAAa;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;QACpB,aAAa;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC;IACnC,CAAC;CACF,CAAA;AAtTY,gBAAgB;IAF5B,IAAA,eAAU,GAAE;IACZ,IAAA,UAAK,EAAC,kBAAa,CAAC,QAAQ,CAAC;;GACjB,gBAAgB,CAsT5B;AAtTY,4CAAgB","sourcesContent":["import {isBoolean, isNumber, isStream, isString} from \"@tsed/core\";\nimport {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {OutgoingHttpHeaders, ServerResponse} from \"http\";\nimport onFinished from \"on-finished\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport type {PlatformRequest} from \"./PlatformRequest\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Response {\n // req: any;\n }\n }\n}\n\nexport type HeaderValue = Array<boolean | number | string> | boolean | number | string;\n\n/**\n * Platform Response abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformResponse<T extends Record<string, any> = any> {\n /**\n * The current @@PlatformRequest@@.\n */\n public request: PlatformRequest;\n\n data: any;\n\n raw: T;\n\n constructor({response}: IncomingEvent, protected $ctx: PlatformContext) {\n this.raw = response as any;\n }\n\n /**\n * Get the current statusCode\n */\n get statusCode() {\n return this.raw.statusCode;\n }\n\n /**\n * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.\n *\n * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.\n */\n get locals() {\n return this.raw.locals;\n }\n\n /**\n * Return the original response framework instance\n */\n get response() {\n return this.getResponse();\n }\n\n /**\n * Return the original response node.js instance\n */\n get res() {\n return this.getRes();\n }\n\n static onFinished(res: any, cb: (er: Error | null, message: string) => void) {\n onFinished(res, cb);\n }\n\n /**\n * Returns the HTTP response header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * response.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string) {\n return this.raw.get(name);\n }\n\n getHeaders(): OutgoingHttpHeaders {\n return this.raw.getHeaders();\n }\n\n /**\n * Return the Framework response object (express, koa, etc...)\n */\n getResponse<Res = T>(): Res {\n return this.raw as any;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw as any;\n }\n\n hasStatus() {\n return this.statusCode !== 200;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.raw.status(status);\n\n return this;\n }\n\n /**\n * Set header `field` to `val`, or pass\n * an object of header fields.\n *\n * Examples:\n * ```typescript\n * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });\n * ```\n *\n * Aliased as `res.header()`.\n */\n setHeaders(headers: OutgoingHttpHeaders) {\n // apply headers\n Object.entries(headers).forEach(([key, item]) => {\n this.setHeader(key, item);\n });\n\n return this;\n }\n\n setHeader(key: string, item: any) {\n if (key.toLowerCase() === \"location\") {\n return this.location(String(item));\n }\n\n this.raw.set(key, item);\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.raw.contentType(contentType);\n\n return this;\n }\n\n contentLength(length: number) {\n this.setHeader(\"Content-Length\", length);\n return this;\n }\n\n getContentLength() {\n if (this.get(\"Content-Length\")) {\n return parseInt(this.get(\"Content-Length\"), 10) || 0;\n }\n }\n\n getContentType() {\n return (this.get(\"Content-Type\") || \"\").split(\";\")[0];\n }\n\n /**\n * Sets the HTTP response Content-Disposition header field to “attachment”.\n * If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter.\n *\n * ```typescript\n * res.attachment()\n * // Content-Disposition: attachment\n *\n * res.attachment('path/to/logo.png')\n * // Content-Disposition: attachment; filename=\"logo.png\"\n * // Content-Type: image/png\n * ```\n *\n * @param filename\n */\n attachment(filename: string) {\n this.raw.attachment(filename);\n return this;\n }\n\n /**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).\n * If not specified, status defaults to `302 Found`.\n *\n * @param status\n * @param url\n */\n redirect(status: number, url: string) {\n this.raw.redirect(status, url);\n\n return this;\n }\n\n /**\n * Sets the response Location HTTP header to the specified path parameter.\n *\n * @param location\n */\n location(location: string) {\n this.raw.location(location);\n\n return this;\n }\n\n /**\n * Stream the given data.\n *\n * @param data\n */\n stream(data: any) {\n data.pipe(this.raw);\n\n return this;\n }\n\n /**\n * Renders a view and sends the rendered HTML string to the client.\n *\n * @param path\n * @param options\n */\n async render(path: string, options: any = {}) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);\n\n return platformViews.render(path, {\n ...this.locals,\n ...options\n });\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It choose the better way to send the data.\n *\n * @param data\n */\n body(data: any) {\n this.data = data;\n\n if (data === undefined) {\n this.raw.send();\n\n return this;\n }\n\n if (isStream(data)) {\n this.stream(data);\n\n return this;\n }\n\n if (Buffer.isBuffer(data)) {\n if (!this.getContentType()) {\n this.contentType(\"application/octet-stream\");\n }\n\n this.contentLength(data.length);\n this.raw.send(data);\n\n return this;\n }\n\n if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {\n this.raw.send(data);\n\n return this;\n }\n\n this.raw.json(data);\n\n return this;\n }\n\n getBody() {\n return this.data;\n }\n\n /**\n * Add a listener to handler the end of the request/response.\n * @param cb\n */\n onEnd(cb: (er: Error | null, message: string) => void): this {\n PlatformResponse.onFinished(this.getRes(), cb);\n\n return this;\n }\n\n isDone(): boolean {\n if (!this.raw) {\n return true;\n }\n\n const res = this.getRes();\n\n return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);\n }\n\n destroy() {\n // @ts-ignore\n delete this.raw;\n delete this.data;\n // @ts-ignore\n delete this.request;\n // @ts-ignore\n delete this.$ctx;\n }\n\n isHeadersSent() {\n return this.getRes().headersSent;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PlatformResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformResponse.ts"],"names":[],"mappings":";;;;AAAA,qCAAmE;AACnE,iCAA0D;AAY1D;;;GAGG;AAGH,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAGN;IAFrB,IAAI,CAAM;IAEV,YAAqB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;I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core\";\nimport {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {OutgoingHttpHeaders, ServerResponse} from \"http\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\nimport type {PlatformRequest} from \"./PlatformRequest\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Response {}\n }\n}\n\n/**\n * Platform Response abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformResponse<Res extends Record<string, any> = any> {\n data: any;\n\n constructor(readonly $ctx: PlatformContext) {}\n\n /**\n * The current @@PlatformRequest@@.\n */\n get request(): PlatformRequest {\n return this.$ctx.request;\n }\n\n get raw(): Res {\n return this.$ctx.event.response as any;\n }\n\n /**\n * Get the current statusCode\n */\n get statusCode() {\n return this.raw.statusCode;\n }\n\n /**\n * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.\n *\n * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.\n */\n get locals() {\n return this.raw.locals;\n }\n\n /**\n * Return the original response framework instance\n */\n get response() {\n return this.getResponse();\n }\n\n /**\n * Return the original response node.js instance\n */\n get res() {\n return this.getRes();\n }\n\n /**\n * Returns the HTTP response header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * response.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string) {\n return this.raw.get(name);\n }\n\n getHeaders(): OutgoingHttpHeaders {\n return this.raw.getHeaders();\n }\n\n /**\n * Return the Framework response object (express, koa, etc...)\n */\n getResponse<R = Res>(): R {\n return this.raw as any;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw as any;\n }\n\n hasStatus() {\n return this.statusCode !== 200;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.raw.status(status);\n\n return this;\n }\n\n /**\n * Set header `field` to `val`, or pass\n * an object of header fields.\n *\n * Examples:\n * ```typescript\n * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });\n * ```\n *\n * Aliased as `res.header()`.\n */\n setHeaders(headers: OutgoingHttpHeaders) {\n // apply headers\n Object.entries(headers).forEach(([key, item]) => {\n this.setHeader(key, item);\n });\n\n return this;\n }\n\n setHeader(key: string, item: any) {\n if (key.toLowerCase() === \"location\") {\n return this.location(String(item));\n }\n\n this.raw.set(key, item);\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.raw.contentType(contentType);\n\n return this;\n }\n\n contentLength(length: number) {\n this.setHeader(\"Content-Length\", length);\n return this;\n }\n\n getContentLength() {\n if (this.get(\"Content-Length\")) {\n return parseInt(this.get(\"Content-Length\"), 10) || 0;\n }\n }\n\n getContentType() {\n return (this.get(\"Content-Type\") || \"\").split(\";\")[0];\n }\n\n /**\n * Sets the HTTP response Content-Disposition header field to “attachment”.\n * If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter.\n *\n * ```typescript\n * res.attachment()\n * // Content-Disposition: attachment\n *\n * res.attachment('path/to/logo.png')\n * // Content-Disposition: attachment; filename=\"logo.png\"\n * // Content-Type: image/png\n * ```\n *\n * @param filename\n */\n attachment(filename: string) {\n this.raw.attachment(filename);\n return this;\n }\n\n /**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).\n * If not specified, status defaults to `302 Found`.\n *\n * @param status\n * @param url\n */\n redirect(status: number, url: string) {\n this.raw.redirect(status, url);\n\n return this;\n }\n\n /**\n * Sets the response Location HTTP header to the specified path parameter.\n *\n * @param location\n */\n location(location: string) {\n this.raw.location(location);\n\n return this;\n }\n\n /**\n * Stream the given data.\n *\n * @param data\n */\n stream(data: any) {\n data.pipe(this.raw);\n\n return this;\n }\n\n /**\n * Renders a view and sends the rendered HTML string to the client.\n *\n * @param path\n * @param options\n */\n async render(path: string, options: any = {}) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);\n\n return platformViews.render(path, {\n ...this.locals,\n ...options\n });\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It chooses the better way to send the data.\n *\n * @param data\n */\n body(data: any) {\n this.data = data;\n\n if (data === undefined) {\n this.raw.send();\n\n return this;\n }\n\n if (isStream(data)) {\n this.stream(data);\n\n return this;\n }\n\n if (Buffer.isBuffer(data)) {\n if (!this.getContentType()) {\n this.contentType(\"application/octet-stream\");\n }\n\n this.contentLength(data.length);\n this.raw.send(data);\n\n return this;\n }\n\n if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {\n this.raw.send(data);\n\n return this;\n }\n\n this.raw.json(data);\n\n return this;\n }\n\n getBody() {\n return this.data;\n }\n\n /**\n * Add a listener to handler the end of the request/response.\n * @param cb\n */\n onEnd(cb: () => Promise<void> | void): this {\n const res: any = this.getRes();\n\n res.on(\"finish\", cb);\n\n return this;\n }\n\n isDone(): boolean {\n if (this.$ctx.isFinished()) {\n return true;\n }\n\n const res = this.getRes();\n\n return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);\n }\n\n isHeadersSent() {\n return this.getRes().headersSent;\n }\n}\n"]}
|
|
@@ -3,16 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PlatformTest = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
|
+
const accepts_1 = tslib_1.__importDefault(require("accepts"));
|
|
6
7
|
const PlatformBuilder_1 = require("../builder/PlatformBuilder");
|
|
7
8
|
const PlatformContext_1 = require("../domain/PlatformContext");
|
|
8
9
|
const createInjector_1 = require("../utils/createInjector");
|
|
9
|
-
const PlatformApplication_1 = require("./PlatformApplication");
|
|
10
10
|
const getConfiguration_1 = require("../utils/getConfiguration");
|
|
11
|
-
const
|
|
11
|
+
const PlatformApplication_1 = require("./PlatformApplication");
|
|
12
12
|
/**
|
|
13
13
|
* @platform
|
|
14
14
|
*/
|
|
15
15
|
class PlatformTest extends di_1.DITest {
|
|
16
|
+
static adapter;
|
|
16
17
|
static async create(settings = {}) {
|
|
17
18
|
di_1.DITest.injector = PlatformTest.createInjector((0, getConfiguration_1.getConfiguration)(settings));
|
|
18
19
|
await di_1.DITest.createContainer(settings);
|
|
@@ -44,7 +45,13 @@ class PlatformTest extends di_1.DITest {
|
|
|
44
45
|
// @ts-ignore
|
|
45
46
|
settings = di_1.DITest.configure(settings);
|
|
46
47
|
settings.adapter = adapter;
|
|
47
|
-
|
|
48
|
+
const configuration = (0, getConfiguration_1.getConfiguration)(settings, mod);
|
|
49
|
+
const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;
|
|
50
|
+
if (!disableComponentsScan) {
|
|
51
|
+
const { importProviders } = await Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/components-scan")));
|
|
52
|
+
await importProviders(configuration);
|
|
53
|
+
}
|
|
54
|
+
instance = await PlatformBuilder_1.PlatformBuilder.build(mod, configuration).bootstrap();
|
|
48
55
|
await instance.listen(!!listen);
|
|
49
56
|
// used by inject method
|
|
50
57
|
di_1.DITest.injector = instance.injector;
|
|
@@ -91,12 +98,14 @@ class PlatformTest extends di_1.DITest {
|
|
|
91
98
|
* ```
|
|
92
99
|
*/
|
|
93
100
|
static callback() {
|
|
94
|
-
|
|
95
|
-
return (_a = di_1.DITest.injector.get(PlatformApplication_1.PlatformApplication)) === null || _a === void 0 ? void 0 : _a.callback();
|
|
101
|
+
return di_1.DITest.injector.get(PlatformApplication_1.PlatformApplication)?.callback();
|
|
96
102
|
}
|
|
97
103
|
static createRequest(options = {}) {
|
|
98
104
|
return {
|
|
99
105
|
headers: {},
|
|
106
|
+
method: "GET",
|
|
107
|
+
url: "/",
|
|
108
|
+
query: {},
|
|
100
109
|
get(key) {
|
|
101
110
|
return this.headers[key.toLowerCase()];
|
|
102
111
|
},
|
|
@@ -138,22 +147,29 @@ class PlatformTest extends di_1.DITest {
|
|
|
138
147
|
this.headers[key.toLowerCase()] = value;
|
|
139
148
|
return this;
|
|
140
149
|
},
|
|
150
|
+
setHeader(key, value) {
|
|
151
|
+
this.headers[key.toLowerCase()] = value;
|
|
152
|
+
return this;
|
|
153
|
+
},
|
|
141
154
|
send(data) {
|
|
142
155
|
this.data = data;
|
|
143
156
|
},
|
|
144
157
|
json(data) {
|
|
145
158
|
this.data = data;
|
|
146
159
|
},
|
|
160
|
+
end(data) {
|
|
161
|
+
this.data = data;
|
|
162
|
+
},
|
|
147
163
|
...options
|
|
148
164
|
};
|
|
149
165
|
}
|
|
150
166
|
static createRequestContext(options = {}) {
|
|
151
|
-
var _a, _b, _c, _d;
|
|
152
167
|
const event = {
|
|
153
|
-
|
|
154
|
-
|
|
168
|
+
...options.event,
|
|
169
|
+
request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),
|
|
170
|
+
response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()
|
|
155
171
|
};
|
|
156
|
-
|
|
172
|
+
const $ctx = new PlatformContext_1.PlatformContext({
|
|
157
173
|
id: "id",
|
|
158
174
|
injector: di_1.DITest.injector,
|
|
159
175
|
logger: di_1.DITest.injector.logger,
|
|
@@ -161,6 +177,10 @@ class PlatformTest extends di_1.DITest {
|
|
|
161
177
|
...options,
|
|
162
178
|
event
|
|
163
179
|
});
|
|
180
|
+
if (options.endpoint) {
|
|
181
|
+
$ctx.endpoint = options.endpoint;
|
|
182
|
+
}
|
|
183
|
+
return $ctx;
|
|
164
184
|
}
|
|
165
185
|
}
|
|
166
186
|
exports.PlatformTest = PlatformTest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version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CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,UAAiD,EAAE;;QAC7E,MAAM,KAAK,GAAG;YACZ,OAAO,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,OAAO,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,OAAO,CAAA,IAAI,YAAY,CAAC,aAAa,EAAE;YAC7F,QAAQ,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,0CAAE,QAAQ,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,QAAQ,CAAA,IAAI,YAAY,CAAC,cAAc,EAAE;SACnG,CAAC;QAEF,OAAO,IAAI,iCAAe,CAAC;YACzB,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,WAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,WAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AAvKD,oCAuKC","sourcesContent":["import {DITest, DITestOptions, InjectorService} from \"@tsed/di\";\nimport {Type} from \"@tsed/core\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"./PlatformAdapter\";\nimport accepts from \"accepts\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static adapter: Type<PlatformAdapter>;\n\n static async create(settings: DITestOptions = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n await DITest.createContainer(settings);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n settings: DITest.configure({httpPort: false, httpsPort: false, ...settings})\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: PlatformBuilder;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n instance = await PlatformBuilder.build(mod, settings).bootstrap();\n await instance.listen(!!listen);\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return accepts(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":";;;;AACA,iCAAgE;AAChE,8DAA8B;AAC9B,gEAA2D;AAC3D,+DAAkF;AAClF,4DAAuD;AACvD,gEAA2D;AAE3D,+DAA0D;AAE1D;;GAEG;AACH,MAAa,YAAa,SAAQ,WAAM;IAC/B,MAAM,CAAC,OAAO,CAAwB;IAE7C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAA0B,EAAE;QAC9C,WAAM,CAAC,QAAQ,GAAG,YAAY,CAAC,cAAc,CAAC,IAAA,m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AAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;gBACxC,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,CAAC,IAAS;gBACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,IAAI,CAAC,IAAS;gBACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,GAAG,CAAC,IAAS;gBACX,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,UAAiD,EAAE;QAC7E,MAAM,KAAK,GAAG;YACZ,GAAG,OAAO,CAAC,KAAK;YAChB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,YAAY,CAAC,aAAa,EAAE;YAC7F,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,IAAI,OAAO,EAAE,KAAK,EAAE,QAAQ,IAAI,YAAY,CAAC,cAAc,EAAE;SACnG,CAAC;QAEF,MAAM,IAAI,GAAG,IAAI,iCAAe,CAAC;YAC/B,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,WAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,WAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;QAEH,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;SAClC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAhMD,oCAgMC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {DITest, DITestOptions, InjectorService} from \"@tsed/di\";\nimport accepts from \"accepts\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"./PlatformAdapter\";\nimport {PlatformApplication} from \"./PlatformApplication\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static adapter: Type<PlatformAdapter>;\n\n static async create(settings: DITestOptions = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n await DITest.createContainer(settings);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n settings: DITest.configure({httpPort: false, httpsPort: false, ...settings})\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: PlatformBuilder;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n const configuration = getConfiguration(settings, mod);\n const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;\n\n if (!disableComponentsScan) {\n const {importProviders} = await import(\"@tsed/components-scan\");\n await importProviders(configuration);\n }\n\n instance = await PlatformBuilder.build(mod, configuration).bootstrap();\n await instance.listen(!!listen);\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n method: \"GET\",\n url: \"/\",\n query: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return accepts(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n setHeader(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n end(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n ...options.event,\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n const $ctx = new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n\n if (options.endpoint) {\n $ctx.endpoint = options.endpoint;\n }\n\n return $ctx;\n }\n}\n"]}
|
|
@@ -1,37 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createContext = void 0;
|
|
3
|
+
exports.createContext = exports.buildIgnoreLog = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
4
5
|
const PlatformContext_1 = require("../domain/PlatformContext");
|
|
5
6
|
const PlatformRequest_1 = require("../services/PlatformRequest");
|
|
6
7
|
const PlatformResponse_1 = require("../services/PlatformResponse");
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
function defaultReqIdBuilder(req) {
|
|
9
|
+
return req.get("x-request-id") || (0, uuid_1.v4)().split("-").join("");
|
|
10
|
+
}
|
|
11
|
+
function mapIgnoreUrlPatterns(ignoreUrlPatterns) {
|
|
12
|
+
return ignoreUrlPatterns.map((pattern) => (typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern));
|
|
13
|
+
}
|
|
14
|
+
function buildIgnoreLog(ignoreUrlPatterns) {
|
|
15
|
+
if (ignoreUrlPatterns) {
|
|
16
|
+
ignoreUrlPatterns = mapIgnoreUrlPatterns(ignoreUrlPatterns);
|
|
17
|
+
return (ignore, data, url) => ignoreUrlPatterns?.find((reg) => !!url.match(reg));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.buildIgnoreLog = buildIgnoreLog;
|
|
9
21
|
/**
|
|
10
22
|
* Create the TsED context to wrap request, response, injector, etc...
|
|
11
23
|
* @param injector
|
|
12
24
|
* @ignore
|
|
13
25
|
*/
|
|
14
26
|
function createContext(injector) {
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
const ResponseKlass = injector.getProvider(PlatformResponse_1.PlatformResponse)?.useClass;
|
|
28
|
+
const RequestKlass = injector.getProvider(PlatformRequest_1.PlatformRequest)?.useClass;
|
|
29
|
+
const { reqIdBuilder = defaultReqIdBuilder, ...loggerOptions } = injector.settings.logger;
|
|
30
|
+
const opts = {
|
|
31
|
+
...loggerOptions,
|
|
32
|
+
logger: injector.logger,
|
|
33
|
+
injector,
|
|
34
|
+
ResponseKlass,
|
|
35
|
+
RequestKlass
|
|
36
|
+
};
|
|
37
|
+
const ignoreLog = buildIgnoreLog(loggerOptions.ignoreUrlPatterns);
|
|
38
|
+
return async function invokeContext(event) {
|
|
39
|
+
const $ctx = new PlatformContext_1.PlatformContext({
|
|
40
|
+
...opts,
|
|
21
41
|
event,
|
|
22
|
-
id: reqIdBuilder(event.request)
|
|
23
|
-
logger: injector.logger,
|
|
24
|
-
...loggerOptions,
|
|
25
|
-
injector,
|
|
26
|
-
ResponseKlass,
|
|
27
|
-
RequestKlass
|
|
28
|
-
});
|
|
29
|
-
ctx.response.onEnd(async () => {
|
|
30
|
-
await ctx.emit("$onResponse", ctx);
|
|
31
|
-
await ctx.destroy();
|
|
42
|
+
id: reqIdBuilder(event.request)
|
|
32
43
|
});
|
|
33
|
-
|
|
34
|
-
return ctx;
|
|
44
|
+
ignoreLog && $ctx.logger.alterIgnoreLog((ignore, data) => ignoreLog(ignore, data, $ctx.url));
|
|
45
|
+
return $ctx;
|
|
35
46
|
};
|
|
36
47
|
}
|
|
37
48
|
exports.createContext = createContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../../src/utils/createContext.ts"],"names":[],"mappings":";;;AACA,+DAA0D;
|
|
1
|
+
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../../src/utils/createContext.ts"],"names":[],"mappings":";;;AACA,+BAAwB;AACxB,+DAA0D;AAE1D,iEAA4D;AAC5D,mEAA8D;AAE9D,SAAS,m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CAAC,iBAAiB,CAAC,CAAC;IAElE,OAAO,KAAK,UAAU,aAAa,CAAC,KAAoB;QACtD,MAAM,IAAI,GAAG,IAAI,iCAAe,CAAC;YAC/B,GAAG,IAAI;YACP,KAAK;YACL,EAAE,EAAE,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC;SAChC,CAAC,CAAC;QAEH,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAE7F,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AA1BD,sCA0BC","sourcesContent":["import {InjectorService} from \"@tsed/di\";\nimport {v4} from \"uuid\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\n\nfunction defaultReqIdBuilder(req: any) {\n return req.get(\"x-request-id\") || v4().split(\"-\").join(\"\");\n}\n\nfunction mapIgnoreUrlPatterns(ignoreUrlPatterns: any[]) {\n return ignoreUrlPatterns.map((pattern: string | RegExp) => (typeof pattern === \"string\" ? new RegExp(pattern, \"gi\") : pattern));\n}\n\nexport function buildIgnoreLog(ignoreUrlPatterns: any[] | undefined) {\n if (ignoreUrlPatterns) {\n ignoreUrlPatterns = mapIgnoreUrlPatterns(ignoreUrlPatterns);\n return (ignore: boolean, data: any, url: string) => ignoreUrlPatterns?.find((reg) => !!url.match(reg));\n }\n}\n\n/**\n * Create the TsED context to wrap request, response, injector, etc...\n * @param injector\n * @ignore\n */\nexport function createContext(injector: InjectorService) {\n const ResponseKlass = injector.getProvider(PlatformResponse)?.useClass;\n const RequestKlass = injector.getProvider(PlatformRequest)?.useClass;\n const {reqIdBuilder = defaultReqIdBuilder, ...loggerOptions} = injector.settings.logger;\n\n const opts = {\n ...loggerOptions,\n logger: injector.logger,\n injector,\n ResponseKlass,\n RequestKlass\n };\n\n const ignoreLog = buildIgnoreLog(loggerOptions.ignoreUrlPatterns);\n\n return async function invokeContext(event: IncomingEvent) {\n const $ctx = new PlatformContext({\n ...opts,\n event,\n id: reqIdBuilder(event.request)\n });\n\n ignoreLog && $ctx.logger.alterIgnoreLog((ignore, data) => ignoreLog(ignore, data, $ctx.url));\n\n return $ctx;\n };\n}\n"]}
|
|
@@ -8,8 +8,8 @@ const http_1 = tslib_1.__importDefault(require("http"));
|
|
|
8
8
|
const listenServer_1 = require("./listenServer");
|
|
9
9
|
function createHttpServer(injector, requestListener) {
|
|
10
10
|
const { settings } = injector;
|
|
11
|
-
const httpPort = settings.
|
|
12
|
-
const httpOptions = settings.
|
|
11
|
+
const httpPort = settings.get("httpPort");
|
|
12
|
+
const httpOptions = settings.get("httpOptions");
|
|
13
13
|
const server = httpPort !== false ? http_1.default.createServer(httpOptions, requestListener) : null;
|
|
14
14
|
injector.addProvider(http_1.default.Server, {
|
|
15
15
|
scope: di_1.ProviderScope.SINGLETON,
|
|
@@ -20,7 +20,7 @@ function createHttpServer(injector, requestListener) {
|
|
|
20
20
|
const hostInfo = (0, core_1.getHostInfoFromPort)("http", httpPort);
|
|
21
21
|
return async () => {
|
|
22
22
|
const resolvedHostInfo = await (0, listenServer_1.listenServer)(injector, server, hostInfo);
|
|
23
|
-
settings.
|
|
23
|
+
settings.set("httpPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
|
|
24
24
|
return server;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHttpServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,wDAAwB;AACxB,iDAA4C;AAE5C,SAAgB,gBAAgB,CAAC,QAAyB,EAAE,eAAqC;IAC/F,MAAM,E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":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Http from \"http\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpServer(injector: InjectorService, requestListener: Http.RequestListener) {\n const {settings} = injector;\n const httpPort = settings.get(\"httpPort\");\n const httpOptions = settings.get(\"httpOptions\");\n\n const server = httpPort !== false ? Http.createServer(httpOptions, requestListener) : null;\n\n injector.addProvider(Http.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(Http.Server);\n\n if (server) {\n const hostInfo = getHostInfoFromPort(\"http\", httpPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Http.Server, hostInfo);\n settings.set(\"httpPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n return server;\n };\n }\n}\n"]}
|
|
@@ -8,8 +8,8 @@ const https_1 = tslib_1.__importDefault(require("https"));
|
|
|
8
8
|
const listenServer_1 = require("./listenServer");
|
|
9
9
|
function createHttpsServer(injector, requestListener) {
|
|
10
10
|
const { settings } = injector;
|
|
11
|
-
const httpsPort = settings.
|
|
12
|
-
const httpsOptions = settings.
|
|
11
|
+
const httpsPort = settings.get("httpsPort");
|
|
12
|
+
const httpsOptions = settings.get("httpsOptions");
|
|
13
13
|
const server = httpsPort !== false ? https_1.default.createServer(httpsOptions, requestListener) : null;
|
|
14
14
|
injector.addProvider(https_1.default.Server, {
|
|
15
15
|
scope: di_1.ProviderScope.SINGLETON,
|
|
@@ -20,7 +20,7 @@ function createHttpsServer(injector, requestListener) {
|
|
|
20
20
|
const hostInfo = (0, core_1.getHostInfoFromPort)("https", httpsPort);
|
|
21
21
|
return async () => {
|
|
22
22
|
const resolvedHostInfo = await (0, listenServer_1.listenServer)(injector, server, hostInfo);
|
|
23
|
-
settings.
|
|
23
|
+
settings.set("httpsPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
|
|
24
24
|
return server;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHttpsServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpsServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,0DAA0B;AAE1B,iDAA4C;AAE5C,SAAgB,iBAAiB,CAAC,QAAyB,EAAE,eAAsC;IACjG,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,SAAS,GAAG,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"createHttpsServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpsServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,0DAA0B;AAE1B,iDAA4C;AAE5C,SAAgB,iBAAiB,CAAC,QAAyB,EAAE,eAAsC;IACjG,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC5C,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAElD,MAAM,MAAM,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,eAAK,CAAC,YAAY,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE9F,QAAQ,CAAC,WAAW,CAAC,eAAK,CAAC,MAAM,EAAE;QACjC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,eAAK,CAAC,MAAM,CAAC,CAAC;IAE9B,IAAI,MAAM,EAAE;QACV,MAAM,QAAQ,GAAG,IAAA,0BAAmB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAEzD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,IAAA,2BAAY,EAAC,QAAQ,EAAE,MAAsB,EAAE,QAAQ,CAAC,CAAC;YACxF,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;YAClF,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;KACH;AACH,CAAC;AAvBD,8CAuBC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Https from \"https\";\nimport Http from \"http\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpsServer(injector: InjectorService, requestListener?: Http.RequestListener) {\n const {settings} = injector;\n const httpsPort = settings.get(\"httpsPort\");\n const httpsOptions = settings.get(\"httpsOptions\");\n\n const server = httpsPort !== false ? Https.createServer(httpsOptions, requestListener) : null;\n\n injector.addProvider(Https.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(Https.Server);\n\n if (server) {\n const hostInfo = getHostInfoFromPort(\"https\", httpsPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Https.Server, hostInfo);\n settings.set(\"httpsPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n return server;\n };\n }\n}\n"]}
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createInjector = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
4
5
|
const di_1 = require("@tsed/di");
|
|
5
6
|
const logger_1 = require("@tsed/logger");
|
|
6
|
-
const core_1 = require("@tsed/core");
|
|
7
7
|
const PlatformConfiguration_1 = require("../config/services/PlatformConfiguration");
|
|
8
|
-
const PlatformHandler_1 = require("../services/PlatformHandler");
|
|
9
|
-
const PlatformResponse_1 = require("../services/PlatformResponse");
|
|
10
|
-
const PlatformRouter_1 = require("../services/PlatformRouter");
|
|
11
|
-
const PlatformApplication_1 = require("../services/PlatformApplication");
|
|
12
8
|
const Platform_1 = require("../services/Platform");
|
|
13
|
-
const PlatformRequest_1 = require("../services/PlatformRequest");
|
|
14
9
|
const PlatformAdapter_1 = require("../services/PlatformAdapter");
|
|
10
|
+
const PlatformApplication_1 = require("../services/PlatformApplication");
|
|
11
|
+
const PlatformHandler_1 = require("../services/PlatformHandler");
|
|
12
|
+
const PlatformRequest_1 = require("../services/PlatformRequest");
|
|
13
|
+
const PlatformResponse_1 = require("../services/PlatformResponse");
|
|
15
14
|
logger_1.$log.name = "TSED";
|
|
16
15
|
const DEFAULT_PROVIDERS = [
|
|
17
16
|
{ provide: PlatformHandler_1.PlatformHandler },
|
|
18
17
|
{ provide: PlatformResponse_1.PlatformResponse },
|
|
19
18
|
{ provide: PlatformRequest_1.PlatformRequest },
|
|
20
|
-
{ provide: PlatformRouter_1.PlatformRouter },
|
|
21
19
|
{ provide: PlatformApplication_1.PlatformApplication },
|
|
22
20
|
{ provide: Platform_1.Platform }
|
|
23
21
|
];
|
|
@@ -33,7 +31,7 @@ function createInjector({ adapter, settings = {} }) {
|
|
|
33
31
|
});
|
|
34
32
|
}
|
|
35
33
|
injector.invoke(PlatformAdapter_1.PlatformAdapter);
|
|
36
|
-
(0, di_1.
|
|
34
|
+
(0, di_1.setLoggerConfiguration)(injector);
|
|
37
35
|
const instance = injector.get(PlatformAdapter_1.PlatformAdapter);
|
|
38
36
|
instance.providers = [...DEFAULT_PROVIDERS, ...instance.providers];
|
|
39
37
|
(0, core_1.toMap)(instance.providers, "provide").forEach((provider, token) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AACvC,iCAA+E;AAC/E,yCAAkC;AAClC,oFAA+E;AAC/E,mDAA8C;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AAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,yCAAmB,CAAC,CAAC;IAErC,OAAO,QAAQ,CAAC;AAClB,CAAC;AA7BD,wCA6BC","sourcesContent":["import {toMap, Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, setLoggerConfiguration} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {PlatformConfiguration} from \"../config/services/PlatformConfiguration\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformAdapter} from \"../services/PlatformAdapter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {PlatformHandler} from \"../services/PlatformHandler\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\n\n$log.name = \"TSED\";\n\nconst DEFAULT_PROVIDERS = [\n {provide: PlatformHandler},\n {provide: PlatformResponse},\n {provide: PlatformRequest},\n {provide: PlatformApplication},\n {provide: Platform}\n];\n\ninterface CreateInjectorOptions {\n adapter?: Type<PlatformAdapter<any>>;\n settings?: Partial<TsED.Configuration>;\n}\n\nexport function createInjector({adapter, settings = {}}: CreateInjectorOptions) {\n const injector = new InjectorService();\n injector.addProvider(PlatformConfiguration);\n\n injector.settings = injector.invoke(PlatformConfiguration);\n injector.logger = $log;\n injector.settings.set(settings);\n\n if (adapter) {\n injector.addProvider(PlatformAdapter, {\n useClass: adapter\n });\n }\n\n injector.invoke(PlatformAdapter);\n\n setLoggerConfiguration(injector);\n\n const instance = injector.get<PlatformAdapter>(PlatformAdapter)!;\n\n instance.providers = [...DEFAULT_PROVIDERS, ...instance.providers];\n\n toMap<any, ProviderOpts>(instance.providers, \"provide\").forEach((provider, token) => {\n injector.addProvider(token, provider);\n });\n\n injector.invoke(PlatformApplication);\n\n return injector;\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureContext = void 0;
|
|
4
|
+
const di_1 = require("@tsed/di");
|
|
5
|
+
function ensureContext(request, cb, fallback) {
|
|
6
|
+
const $ctx = (0, di_1.getContext)();
|
|
7
|
+
if ($ctx) {
|
|
8
|
+
return cb($ctx);
|
|
9
|
+
}
|
|
10
|
+
if (!request?.$ctx && fallback) {
|
|
11
|
+
return fallback();
|
|
12
|
+
}
|
|
13
|
+
return request.$ctx.runInContext(() => cb(request.$ctx));
|
|
14
|
+
}
|
|
15
|
+
exports.ensureContext = ensureContext;
|
|
16
|
+
//# sourceMappingURL=ensureContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureContext.js","sourceRoot":"","sources":["../../../src/utils/ensureContext.ts"],"names":[],"mappings":";;;AAAA,iCAAoC;AAGpC,SAAgB,aAAa,CAAC,OAAY,EAAE,EAAkC,EAAE,QAAqB;IACnG,MAAM,IAAI,GAAG,IAAA,eAAU,GAAmB,CAAC;IAE3C,IAAI,IAAI,EAAE;QACR,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;KACjB;IAED,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE;QAC9B,OAAO,QAAQ,EAAE,CAAC;KACnB;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC;AAZD,sCAYC","sourcesContent":["import {getContext} from \"@tsed/di\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\n\nexport function ensureContext(request: any, cb: ($ctx: PlatformContext) => any, fallback?: () => void) {\n const $ctx = getContext<PlatformContext>();\n\n if ($ctx) {\n return cb($ctx);\n }\n\n if (!request?.$ctx && fallback) {\n return fallback();\n }\n\n return request.$ctx.runInContext(() => cb(request.$ctx));\n}\n"]}
|
|
@@ -4,11 +4,13 @@ exports.getConfiguration = void 0;
|
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
6
|
function getConfiguration(configuration = {}, module = null) {
|
|
7
|
+
if (configuration.$$resolved) {
|
|
8
|
+
return configuration;
|
|
9
|
+
}
|
|
7
10
|
const store = module ? core_1.Store.from(module).get("configuration") || {} : {};
|
|
8
11
|
const env = configuration.env || store.env || process.env.NODE_ENV || core_1.Env.DEV;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
componentsScan: ["${rootDir}/mvc/**/*.ts", "${rootDir}/services/**/*.ts", "${rootDir}/middlewares/**/*.ts"],
|
|
12
|
+
return {
|
|
13
|
+
$$resolved: true,
|
|
12
14
|
env,
|
|
13
15
|
httpPort: 8080,
|
|
14
16
|
httpsPort: false,
|
|
@@ -19,11 +21,7 @@ function getConfiguration(configuration = {}, module = null) {
|
|
|
19
21
|
...store.scopes,
|
|
20
22
|
...configuration.scopes
|
|
21
23
|
},
|
|
22
|
-
mount: store.mount
|
|
23
|
-
? (0, core_1.deepMerge)(store.mount || {}, configuration.mount || {})
|
|
24
|
-
: {
|
|
25
|
-
"/rest": "${rootDir}/controllers/**/*.ts"
|
|
26
|
-
},
|
|
24
|
+
mount: (0, di_1.mergeMount)(store.mount, configuration.mount),
|
|
27
25
|
logger: {
|
|
28
26
|
debug: false,
|
|
29
27
|
level: env === core_1.Env.TEST ? "off" : "info",
|
|
@@ -33,10 +31,6 @@ function getConfiguration(configuration = {}, module = null) {
|
|
|
33
31
|
jsonIndentation: process.env.NODE_ENV === core_1.Env.PROD ? 0 : 2
|
|
34
32
|
}
|
|
35
33
|
};
|
|
36
|
-
if (!configuration.disableComponentsScan && store.componentsScan && configuration.componentsScan) {
|
|
37
|
-
config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];
|
|
38
|
-
}
|
|
39
|
-
return config;
|
|
40
34
|
}
|
|
41
35
|
exports.getConfiguration = getConfiguration;
|
|
42
36
|
//# sourceMappingURL=getConfiguration.js.map
|