@tsed/common 7.3.0 → 7.4.0
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/lib/cjs/builder/PlatformBuilder.js +41 -0
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/services/PlatformMiddlewaresChain.js +2 -9
- package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/cjs/services/PlatformTest.js +1 -1
- package/lib/cjs/services/PlatformTest.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +42 -1
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/services/PlatformMiddlewaresChain.js +2 -9
- package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/esm/services/PlatformTest.js +1 -1
- package/lib/esm/services/PlatformTest.js.map +1 -1
- package/lib/types/builder/PlatformBuilder.d.ts +1 -0
- package/lib/types/services/PlatformTest.d.ts +2 -2
- package/package.json +14 -14
- package/readme.md +17 -7
|
@@ -173,6 +173,7 @@ class PlatformBuilder {
|
|
|
173
173
|
}
|
|
174
174
|
async runLifecycle() {
|
|
175
175
|
(0, di_1.setLoggerConfiguration)(this.injector);
|
|
176
|
+
await this.mapTokenMiddlewares();
|
|
176
177
|
await this.loadInjector();
|
|
177
178
|
this.#adapter.useContext();
|
|
178
179
|
await this.loadRoutes();
|
|
@@ -260,6 +261,11 @@ class PlatformBuilder {
|
|
|
260
261
|
async mapRouters() {
|
|
261
262
|
const layers = this.platform.getLayers();
|
|
262
263
|
this.#adapter.mapLayers(layers);
|
|
264
|
+
const rawBody = this.settings.get("rawBody") ||
|
|
265
|
+
layers.some(({ handlers }) => {
|
|
266
|
+
return handlers.some((handler) => handler.opts?.paramsTypes?.RAW_BODY);
|
|
267
|
+
});
|
|
268
|
+
this.settings.set("rawBody", rawBody);
|
|
263
269
|
return this.logRoutes(layers.filter((layer) => layer.isProvider()));
|
|
264
270
|
}
|
|
265
271
|
diff() {
|
|
@@ -299,6 +305,41 @@ class PlatformBuilder {
|
|
|
299
305
|
logger.info((0, printRoutes_1.printRoutes)(await this.injector.alterAsync("$logRoutes", routes)));
|
|
300
306
|
}
|
|
301
307
|
}
|
|
308
|
+
async mapTokenMiddlewares() {
|
|
309
|
+
let middlewares = this.injector.settings.get("middlewares", []);
|
|
310
|
+
const { env } = this.injector.settings;
|
|
311
|
+
const defaultHook = "$beforeRoutesInit";
|
|
312
|
+
const promises = middlewares.map(async (middleware) => {
|
|
313
|
+
if ((0, core_1.isFunction)(middleware)) {
|
|
314
|
+
return {
|
|
315
|
+
env,
|
|
316
|
+
hook: defaultHook,
|
|
317
|
+
use: middleware
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
if ((0, core_1.isString)(middleware)) {
|
|
321
|
+
middleware = { env, use: middleware, hook: defaultHook };
|
|
322
|
+
}
|
|
323
|
+
let { use, options } = middleware;
|
|
324
|
+
if ((0, core_1.isString)(use)) {
|
|
325
|
+
if (["text-parser", "raw-parser", "json-parser", "urlencoded-parser"].includes(use)) {
|
|
326
|
+
use = this.adapter.bodyParser(use.replace("-parser", ""), options);
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
const mod = await Promise.resolve().then(() => __importStar(require(use)));
|
|
330
|
+
use = (mod.default || mod)(options);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
env,
|
|
335
|
+
hook: defaultHook,
|
|
336
|
+
...middleware,
|
|
337
|
+
use
|
|
338
|
+
};
|
|
339
|
+
});
|
|
340
|
+
middlewares = await Promise.all(promises);
|
|
341
|
+
this.injector.settings.set("middlewares", middlewares);
|
|
342
|
+
}
|
|
302
343
|
}
|
|
303
344
|
exports.PlatformBuilder = PlatformBuilder;
|
|
304
345
|
//# sourceMappingURL=PlatformBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformB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AES,KAAK,CAAC,aAAa;QAC3B,IAAI,CAAC,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC;IAES,KAAK,CAAC,SAAS,CAAC,MAAuB;QAC/C,MAAM,EAAC,MAAM,EAAC,GAAG,IAAI,CAAC;QAEtB,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAE9B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAClF,MAAM,MAAM,GAA2B,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC1D,OAAO;oBACL,GAAG,EAAE,KAAK,CAAC,IAAI;oBACf,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,SAAS,gBAAgB;oBACpE,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS;oBAC3D,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE;iBAC1B,CAAC;YAC5B,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,IAAI,CAAC,IAAA,yBAAW,EAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;SAChF;IACH,CAAC;CACF;AAtVD,0CAsVC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, runInContext, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport {PlatformLayer} from \"@tsed/platform-router\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport type Https from \"https\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {PlatformRouteDetails} from \"../domain/PlatformRouteDetails\";\nimport {Route} from \"../interfaces/Route\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {printRoutes} from \"../utils/printRoutes\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application> {\n public static adapter: Type<PlatformAdapter<any>>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n readonly #injector: InjectorService;\n readonly #rootModule: Type<any>;\n readonly #adapter: PlatformAdapter<App>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n\n const configuration = getConfiguration(settings, module);\n const adapterKlass: Type<PlatformAdapter<App>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n configuration.PLATFORM_NAME = name;\n this.name = name;\n\n this.#injector = createInjector({\n adapter: adapterKlass,\n settings: configuration\n });\n\n this.#adapter = this.#injector.get<PlatformAdapter<App>>(PlatformAdapter)!;\n\n this.createHttpServers();\n\n this.#adapter.onInit && this.#adapter.onInit();\n\n this.log(\"Injector created...\");\n }\n\n get injector(): InjectorService {\n return this.#injector;\n }\n\n get rootModule(): any {\n return this.#injector.get(this.#rootModule);\n }\n\n get app(): PlatformApplication<App> {\n return this.injector.get<PlatformApplication<App>>(PlatformApplication)!;\n }\n\n get platform() {\n return this.injector.get<Platform>(Platform)!;\n }\n\n get adapter() {\n return this.#adapter;\n }\n\n /**\n * Return the settings configured by the decorator @@Configuration@@.\n *\n * ```typescript\n * @Configuration({\n * rootDir: Path.resolve(__dirname),\n * port: 8000,\n * httpsPort: 8080,\n * mount: {\n * \"/rest\": \"${rootDir}/controllers/**\\/*.js\"\n * }\n * })\n * export class Server {\n * $onInit(){\n * console.log(this.settings); // {rootDir, port, httpsPort,...}\n * }\n * }\n * ```\n *\n * @returns {PlatformConfiguration}\n */\n get settings() {\n return this.injector.settings;\n }\n\n get logger() {\n return this.injector.logger;\n }\n\n get disableBootstrapLog() {\n return this.settings.get(\"logger.disableBootstrapLog\");\n }\n\n static create<App = TsED.Application>(module: Type<any>, settings: PlatformBuilderSettings<App>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings\n });\n }\n\n static build<App = TsED.Application>(module: Type<any>, {adapter, ...settings}: PlatformBuilderSettings<App>) {\n return new PlatformBuilder(adapter, module, settings);\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap<App = TsED.Application>(module: Type<any>, settings: PlatformBuilderSettings<App>) {\n return this.build<App>(module, settings).bootstrap();\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => void;\n callback(req: IncomingMessage, res: ServerResponse): void;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.callback()(req, res);\n }\n\n return this.app.callback();\n }\n\n log(...data: any[]) {\n return !this.disableBootstrapLog && this.logger.info(...data, this.diff());\n }\n\n /**\n * Add classes to the components list\n * @param classes\n */\n public addComponents(classes: Type | Type[]) {\n this.settings.set(\"imports\", this.settings.get<any[]>(\"imports\", []).concat(classes));\n\n return this;\n }\n\n /**\n * Add classes decorated by @@Controller@@ to components container.\n *\n * ### Example\n *\n * ```typescript\n * @Controller('/ctrl')\n * class MyController{\n * }\n *\n * platform.addControllers('/rest', [MyController])\n * ```\n *\n * ::: tip\n * If the MyController class isn't decorated, the class will be ignored.\n * :::\n *\n * @param {string} endpoint\n * @param {any[]} controllers\n */\n public addControllers(endpoint: string, controllers: TokenProvider | TokenProvider[]) {\n [].concat(controllers).forEach((token) => {\n this.settings.routes.push({token, route: endpoint});\n });\n }\n\n public async runLifecycle() {\n setLoggerConfiguration(this.injector);\n\n await this.loadInjector();\n\n this.#adapter.useContext();\n\n await this.loadRoutes();\n\n return this;\n }\n\n async loadInjector() {\n const {injector} = this;\n this.log(\"Build providers\");\n\n await injector.loadModule(this.#rootModule);\n\n this.log(\"Settings and injector loaded...\");\n\n await this.callHook(\"$afterInit\");\n }\n\n async listen(network = true) {\n if (!this.#promise) {\n await this.bootstrap();\n }\n\n await this.callHook(\"$beforeListen\");\n\n if (network) {\n await this.listenServers();\n }\n\n await this.callHook(\"$afterListen\");\n\n await this.ready();\n }\n\n async stop() {\n await this.callHook(\"$onDestroy\");\n await this.injector.destroy();\n\n this.#listeners.map((server) => {\n return new Promise((resolve) => server.close(() => resolve(undefined)));\n });\n }\n\n public async ready() {\n const {startedAt} = this;\n\n await this.callHook(\"$onReady\");\n await this.injector.emit(\"$onServerReady\");\n\n this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);\n }\n\n async callHook(hook: string, ...args: any[]) {\n const {injector} = this;\n\n if (!this.disableBootstrapLog) {\n injector.logger.debug(`\\x1B[1mCall hook ${hook}\\x1B[22m`);\n }\n\n // Load middlewares for the given hook\n this.loadMiddlewaresFor(hook);\n\n // call hooks added by providers\n await injector.emit(hook, ...args);\n }\n\n async loadStatics(hook: string): Promise<void> {\n const statics = this.settings.get<PlatformStaticsSettings>(\"statics\");\n\n getStaticsOptions(statics).forEach(({path, options}) => {\n if (options.hook === hook) {\n this.platform.app.statics(path, options);\n }\n });\n }\n\n useProvider(token: Type<any>, settings?: Partial<ProviderOpts>) {\n this.injector.addProvider(token, settings);\n\n return this;\n }\n\n async bootstrap() {\n this.#promise = this.#promise || this.runLifecycle();\n\n return this.#promise;\n }\n\n protected async loadRoutes() {\n this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());\n\n // istanbul ignore next\n if (this.settings.get(\"logger.level\") !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\n }\n\n this.log(\"Load routes\");\n\n if (this.rootModule.$beforeRoutesInit) {\n await this.rootModule.$beforeRoutesInit();\n this.rootModule.$beforeRoutesInit = () => {};\n }\n\n await this.loadStatics(\"$beforeRoutesInit\");\n await this.callHook(\"$beforeRoutesInit\");\n\n const routes = this.injector.settings.get<Route[]>(\"routes\");\n\n this.platform.addRoutes(routes);\n\n await this.callHook(\"$onRoutesInit\");\n\n await this.loadStatics(\"$afterRoutesInit\");\n\n await this.callHook(\"$afterRoutesInit\");\n\n this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());\n\n await this.mapRouters();\n }\n\n protected async mapRouters() {\n const layers = this.platform.getLayers();\n\n this.#adapter.mapLayers(layers);\n\n return this.logRoutes(layers.filter((layer) => layer.isProvider()));\n }\n\n protected diff() {\n const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);\n this.current = new Date();\n return ms;\n }\n\n /**\n * Load middlewares from configuration for the given hook\n * @param hook\n * @protected\n */\n protected loadMiddlewaresFor(hook: string): void {\n return getMiddlewaresForHook(hook, this.settings, \"$beforeRoutesInit\").forEach(({use}) => {\n this.app.use(use);\n });\n }\n\n protected createHttpServers() {\n this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(\n Boolean\n ) as any[];\n }\n\n protected async listenServers(): Promise<void> {\n this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));\n }\n\n protected async logRoutes(layers: PlatformLayer[]) {\n const {logger} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.get(\"logger.disableRoutesSummary\") && !this.disableBootstrapLog) {\n const routes: PlatformRouteDetails[] = layers.map((layer) => {\n return {\n url: layer.path,\n method: layer.method,\n name: layer.opts.name || `${layer.provider.className}.constructor()`,\n className: layer.opts.className || layer.provider.className,\n methodClassName: layer.opts.methodClassName || \"\"\n } as PlatformRouteDetails;\n });\n\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", routes)));\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAA8D;AAC9D,iCAAsG;AACtG,qEAAmG;AAOnG,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;QAEx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AU,CAAC;YAEhC,IAAI,IAAA,eAAQ,EAAC,GAAG,CAAC,EAAE;gBACjB,IAAI,CAAC,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,mBAAmB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;oBACnF,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;iBACpE;qBAAM;oBACL,MAAM,GAAG,GAAG,wDAAa,GAAG,GAAC,CAAC;oBAC9B,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;iBACrC;aACF;YAED,OAAO;gBACL,GAAG;gBACH,IAAI,EAAE,WAAW;gBACjB,GAAG,UAAU;gBACb,GAAG;aACJ,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE1C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IACzD,CAAC;CACF;AA1YD,0CA0YC","sourcesContent":["import {isFunction, isString, nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook, PlatformMiddlewareLoadingOptions} 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.mapTokenMiddlewares();\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 const rawBody =\n this.settings.get(\"rawBody\") ||\n layers.some(({handlers}) => {\n return handlers.some((handler) => handler.opts?.paramsTypes?.RAW_BODY);\n });\n\n this.settings.set(\"rawBody\", rawBody);\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 protected async mapTokenMiddlewares() {\n let middlewares = this.injector.settings.get<PlatformMiddlewareLoadingOptions[]>(\"middlewares\", []);\n const {env} = this.injector.settings;\n const defaultHook = \"$beforeRoutesInit\";\n\n const promises = middlewares.map(async (middleware: PlatformMiddlewareLoadingOptions): Promise<PlatformMiddlewareLoadingOptions> => {\n if (isFunction(middleware)) {\n return {\n env,\n hook: defaultHook,\n use: middleware\n };\n }\n\n if (isString(middleware)) {\n middleware = {env, use: middleware, hook: defaultHook};\n }\n\n let {use, options} = middleware;\n\n if (isString(use)) {\n if ([\"text-parser\", \"raw-parser\", \"json-parser\", \"urlencoded-parser\"].includes(use)) {\n use = this.adapter.bodyParser(use.replace(\"-parser\", \"\"), options);\n } else {\n const mod = await import(use);\n use = (mod.default || mod)(options);\n }\n }\n\n return {\n env,\n hook: defaultHook,\n ...middleware,\n use\n };\n });\n\n middlewares = await Promise.all(promises);\n\n this.injector.settings.set(\"middlewares\", middlewares);\n }\n}\n"]}
|
|
@@ -13,15 +13,8 @@ let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
|
|
|
13
13
|
acceptMimes;
|
|
14
14
|
adapter;
|
|
15
15
|
get(allMiddlewares, operationRoute) {
|
|
16
|
-
const { ACCEPT_MIMES, FILE
|
|
17
|
-
return [
|
|
18
|
-
ACCEPT_MIMES && PlatformAcceptMimesMiddleware_1.PlatformAcceptMimesMiddleware,
|
|
19
|
-
FILE && PlatformMulterMiddleware_1.PlatformMulterMiddleware,
|
|
20
|
-
!FILE && RAW_BODY && this.adapter.bodyParser("raw"),
|
|
21
|
-
!FILE && !RAW_BODY && BODY && this.adapter.bodyParser("json"),
|
|
22
|
-
!FILE && !RAW_BODY && BODY && this.adapter.bodyParser("urlencoded"),
|
|
23
|
-
...allMiddlewares
|
|
24
|
-
].filter(Boolean);
|
|
16
|
+
const { ACCEPT_MIMES, FILE } = this.getParamTypes(allMiddlewares, operationRoute);
|
|
17
|
+
return [ACCEPT_MIMES && PlatformAcceptMimesMiddleware_1.PlatformAcceptMimesMiddleware, FILE && PlatformMulterMiddleware_1.PlatformMulterMiddleware, ...allMiddlewares].filter(Boolean);
|
|
25
18
|
}
|
|
26
19
|
hasAcceptMimes(operationRoute) {
|
|
27
20
|
return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";;;;AAAA,qCAAmC;AACnC,iCAAsD;AACtD,2DAAiD;AACjD,yCAAiE;AACjE,gGAA2F;AAC3F,sFAAiF;AACjF,iEAA4D;AAG5D,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IAEzB,WAAW,CAAW;IAGtB,OAAO,CAAkB;IAEnC,GAAG,CAAC,cAAqB,EAAE,cAAkC;QAC3D,MAAM,EAAC,YAAY,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";;;;AAAA,qCAAmC;AACnC,iCAAsD;AACtD,2DAAiD;AACjD,yCAAiE;AACjE,gGAA2F;AAC3F,sFAAiF;AACjF,iEAA4D;AAG5D,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IAEzB,WAAW,CAAW;IAGtB,OAAO,CAAkB;IAEnC,GAAG,CAAC,cAAqB,EAAE,cAAkC;QAC3D,MAAM,EAAC,YAAY,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QAEhF,OAAO,CAAC,YAAY,IAAI,6DAA6B,EAAE,IAAI,IAAI,mDAAwB,EAAE,GAAG,cAAc,CAAC,CAAC,MAAM,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AAC;;6DACI;AAGhC;IADC,IAAA,WAAM,GAAE;sCACU,iCAAe;yDAAC;AALxB,wBAAwB;IADpC,IAAA,eAAU,GAAE;GACA,wBAAwB,CAyCpC;AAzCY,4DAAwB","sourcesContent":["import {isClass} from \"@tsed/core\";\nimport {Constant, Inject, Injectable} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonEntityStore, JsonOperationRoute} from \"@tsed/schema\";\nimport {PlatformAcceptMimesMiddleware} from \"../middlewares/PlatformAcceptMimesMiddleware\";\nimport {PlatformMulterMiddleware} from \"../middlewares/PlatformMulterMiddleware\";\nimport {PlatformAdapter} from \"../services/PlatformAdapter\";\n\n@Injectable()\nexport class PlatformMiddlewaresChain {\n @Constant(\"acceptMimes\", [])\n protected acceptMimes: string[];\n\n @Inject()\n protected adapter: PlatformAdapter;\n\n get(allMiddlewares: any[], operationRoute: JsonOperationRoute) {\n const {ACCEPT_MIMES, FILE} = this.getParamTypes(allMiddlewares, operationRoute);\n\n return [ACCEPT_MIMES && PlatformAcceptMimesMiddleware, FILE && PlatformMulterMiddleware, ...allMiddlewares].filter(Boolean);\n }\n\n protected hasAcceptMimes(operationRoute: JsonOperationRoute) {\n return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;\n }\n\n protected getParamTypes(middlewares: any[], operationRoute: JsonOperationRoute) {\n return middlewares.filter(isClass).reduce(\n (paramTypes, token) => {\n if (token !== operationRoute.endpoint) {\n const entity = JsonEntityStore.fromMethod(token, \"use\");\n\n if (entity.decoratorType === \"method\") {\n const {FILE, RAW_BODY, BODY} = entity.getParamTypes();\n paramTypes.FILE = paramTypes.FILE || FILE;\n paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;\n paramTypes.BODY = paramTypes.BODY || BODY;\n }\n }\n\n return paramTypes;\n },\n {\n ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),\n FILE: operationRoute.has(ParamTypes.FILES),\n RAW_BODY: operationRoute.has(ParamTypes.RAW_BODY),\n BODY: operationRoute.has(ParamTypes.BODY) || operationRoute.method === \"ALL\"\n }\n );\n }\n}\n"]}
|
|
@@ -16,7 +16,7 @@ class PlatformTest extends di_1.DITest {
|
|
|
16
16
|
static adapter;
|
|
17
17
|
static async create(settings = {}) {
|
|
18
18
|
di_1.DITest.injector = PlatformTest.createInjector((0, getConfiguration_1.getConfiguration)(settings));
|
|
19
|
-
await di_1.DITest.createContainer(
|
|
19
|
+
await di_1.DITest.createContainer();
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Create a new injector with the right default services
|
|
@@ -1 +1 @@
|
|
|
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,mCAAgB,EAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,MAAM,WAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,WAAgB,EAAE;QACtC,OAAO,IAAA,+BAAc,EAAC;YACpB,QAAQ,EAAE,WAAM,CAAC,SAAS,CAAC,EAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAC,CAAC;SAC7E,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,GAAQ,EAAE,EAAC,MAAM,EAAE,GAAG,QAAQ,KAA0D,EAAE;QACzG,OAA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,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
|
+
{"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":";;;;AACA,iCAAiD;AACjD,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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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: Partial<TsED.Configuration> = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n await DITest.createContainer();\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,4 +1,4 @@
|
|
|
1
|
-
import { nameOf } from "@tsed/core";
|
|
1
|
+
import { isFunction, isString, nameOf } from "@tsed/core";
|
|
2
2
|
import { colors, setLoggerConfiguration } from "@tsed/di";
|
|
3
3
|
import { getMiddlewaresForHook } from "@tsed/platform-middlewares";
|
|
4
4
|
import { Platform } from "../services/Platform.js";
|
|
@@ -147,6 +147,7 @@ export class PlatformBuilder {
|
|
|
147
147
|
}
|
|
148
148
|
async runLifecycle() {
|
|
149
149
|
setLoggerConfiguration(this.injector);
|
|
150
|
+
await this.mapTokenMiddlewares();
|
|
150
151
|
await this.loadInjector();
|
|
151
152
|
this.#adapter.useContext();
|
|
152
153
|
await this.loadRoutes();
|
|
@@ -234,6 +235,11 @@ export class PlatformBuilder {
|
|
|
234
235
|
async mapRouters() {
|
|
235
236
|
const layers = this.platform.getLayers();
|
|
236
237
|
this.#adapter.mapLayers(layers);
|
|
238
|
+
const rawBody = this.settings.get("rawBody") ||
|
|
239
|
+
layers.some(({ handlers }) => {
|
|
240
|
+
return handlers.some((handler) => handler.opts?.paramsTypes?.RAW_BODY);
|
|
241
|
+
});
|
|
242
|
+
this.settings.set("rawBody", rawBody);
|
|
237
243
|
return this.logRoutes(layers.filter((layer) => layer.isProvider()));
|
|
238
244
|
}
|
|
239
245
|
diff() {
|
|
@@ -273,5 +279,40 @@ export class PlatformBuilder {
|
|
|
273
279
|
logger.info(printRoutes(await this.injector.alterAsync("$logRoutes", routes)));
|
|
274
280
|
}
|
|
275
281
|
}
|
|
282
|
+
async mapTokenMiddlewares() {
|
|
283
|
+
let middlewares = this.injector.settings.get("middlewares", []);
|
|
284
|
+
const { env } = this.injector.settings;
|
|
285
|
+
const defaultHook = "$beforeRoutesInit";
|
|
286
|
+
const promises = middlewares.map(async (middleware) => {
|
|
287
|
+
if (isFunction(middleware)) {
|
|
288
|
+
return {
|
|
289
|
+
env,
|
|
290
|
+
hook: defaultHook,
|
|
291
|
+
use: middleware
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (isString(middleware)) {
|
|
295
|
+
middleware = { env, use: middleware, hook: defaultHook };
|
|
296
|
+
}
|
|
297
|
+
let { use, options } = middleware;
|
|
298
|
+
if (isString(use)) {
|
|
299
|
+
if (["text-parser", "raw-parser", "json-parser", "urlencoded-parser"].includes(use)) {
|
|
300
|
+
use = this.adapter.bodyParser(use.replace("-parser", ""), options);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
const mod = await import(use);
|
|
304
|
+
use = (mod.default || mod)(options);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
env,
|
|
309
|
+
hook: defaultHook,
|
|
310
|
+
...middleware,
|
|
311
|
+
use
|
|
312
|
+
};
|
|
313
|
+
});
|
|
314
|
+
middlewares = await Promise.all(promises);
|
|
315
|
+
this.injector.settings.set("middlewares", middlewares);
|
|
316
|
+
}
|
|
276
317
|
}
|
|
277
318
|
//# sourceMappingURL=PlatformBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAO,MAAM,YAAY,CAAC;AACxC,OAAO,EAAC,MAAM,EAA+C,sBAAsB,EAAgB,MAAM,UAAU,CAAC;AACpH,OAAO,EAAC,qBAAqB,EAAC,MAAM,4BAA4B,CAAC;AAOjE,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9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/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
|
+
{"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAC,MAAM,EAAiC,sBAAsB,EAAgB,MAAM,UAAU,CAAC;AACtG,OAAO,EAAC,qBAAqB,EAAmC,MAAM,4BAA4B,CAAC;AAOnG,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,eAAe,EAA0B,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,eAAe;IACnB,MAAM,CAAC,OAAO,CAA6B;IAEzC,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aAAa,EAAE,WAAW,CAAC,CAAC;IACzD,CAAC;CACF","sourcesContent":["import {isFunction, isString, nameOf, Type} from \"@tsed/core\";\nimport {colors, InjectorService, ProviderOpts, setLoggerConfiguration, TokenProvider} from \"@tsed/di\";\nimport {getMiddlewaresForHook, PlatformMiddlewareLoadingOptions} 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.mapTokenMiddlewares();\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 const rawBody =\n this.settings.get(\"rawBody\") ||\n layers.some(({handlers}) => {\n return handlers.some((handler) => handler.opts?.paramsTypes?.RAW_BODY);\n });\n\n this.settings.set(\"rawBody\", rawBody);\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 protected async mapTokenMiddlewares() {\n let middlewares = this.injector.settings.get<PlatformMiddlewareLoadingOptions[]>(\"middlewares\", []);\n const {env} = this.injector.settings;\n const defaultHook = \"$beforeRoutesInit\";\n\n const promises = middlewares.map(async (middleware: PlatformMiddlewareLoadingOptions): Promise<PlatformMiddlewareLoadingOptions> => {\n if (isFunction(middleware)) {\n return {\n env,\n hook: defaultHook,\n use: middleware\n };\n }\n\n if (isString(middleware)) {\n middleware = {env, use: middleware, hook: defaultHook};\n }\n\n let {use, options} = middleware;\n\n if (isString(use)) {\n if ([\"text-parser\", \"raw-parser\", \"json-parser\", \"urlencoded-parser\"].includes(use)) {\n use = this.adapter.bodyParser(use.replace(\"-parser\", \"\"), options);\n } else {\n const mod = await import(use);\n use = (mod.default || mod)(options);\n }\n }\n\n return {\n env,\n hook: defaultHook,\n ...middleware,\n use\n };\n });\n\n middlewares = await Promise.all(promises);\n\n this.injector.settings.set(\"middlewares\", middlewares);\n }\n}\n"]}
|
|
@@ -10,15 +10,8 @@ let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
|
|
|
10
10
|
acceptMimes;
|
|
11
11
|
adapter;
|
|
12
12
|
get(allMiddlewares, operationRoute) {
|
|
13
|
-
const { ACCEPT_MIMES, FILE
|
|
14
|
-
return [
|
|
15
|
-
ACCEPT_MIMES && PlatformAcceptMimesMiddleware,
|
|
16
|
-
FILE && PlatformMulterMiddleware,
|
|
17
|
-
!FILE && RAW_BODY && this.adapter.bodyParser("raw"),
|
|
18
|
-
!FILE && !RAW_BODY && BODY && this.adapter.bodyParser("json"),
|
|
19
|
-
!FILE && !RAW_BODY && BODY && this.adapter.bodyParser("urlencoded"),
|
|
20
|
-
...allMiddlewares
|
|
21
|
-
].filter(Boolean);
|
|
13
|
+
const { ACCEPT_MIMES, FILE } = this.getParamTypes(allMiddlewares, operationRoute);
|
|
14
|
+
return [ACCEPT_MIMES && PlatformAcceptMimesMiddleware, FILE && PlatformMulterMiddleware, ...allMiddlewares].filter(Boolean);
|
|
22
15
|
}
|
|
23
16
|
hasAcceptMimes(operationRoute) {
|
|
24
17
|
return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAC,eAAe,EAAqB,MAAM,cAAc,CAAC;AACjE,OAAO,EAAC,6BAA6B,EAAC,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAC,wBAAwB,EAAC,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAC,eAAe,EAAC,MAAM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AAO,CAAC,CAAC,MAAM,CACvC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE;YACpB,IAAI,KAAK,KAAK,cAAc,CAAC,QAAQ,EAAE;gBACrC,MAAM,MAAM,GAAG,eAAe,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAExD,IAAI,MAAM,CAAC,aAAa,KAAK,QAAQ,EAAE;oBACrC,MAAM,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;oBACtD,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC;oBAC1C,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,IAAI,QAAQ,CAAC;oBACtD,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC;iBAC3C;aACF;YAED,OAAO,UAAU,CAAC;QACpB,CAAC,EACD;YACE,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC;YACjD,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;YAC1C,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC;YACjD,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,MAAM,KAAK,KAAK;SAC7E,CACF,CAAC;IACJ,CAAC;CACF,CAAA;AAvCC;IADC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;;6DACI;AAGhC;IADC,MAAM,EAAE;8BACU,eAAe;yDAAC;AALxB,wBAAwB;IADpC,UAAU,EAAE;GACA,wBAAwB,CAyCpC;SAzCY,wBAAwB","sourcesContent":["import {isClass} from \"@tsed/core\";\nimport {Constant, Inject, Injectable} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonEntityStore, JsonOperationRoute} from \"@tsed/schema\";\nimport {PlatformAcceptMimesMiddleware} from \"../middlewares/PlatformAcceptMimesMiddleware\";\nimport {PlatformMulterMiddleware} from \"../middlewares/PlatformMulterMiddleware\";\nimport {PlatformAdapter} from \"../services/PlatformAdapter\";\n\n@Injectable()\nexport class PlatformMiddlewaresChain {\n @Constant(\"acceptMimes\", [])\n protected acceptMimes: string[];\n\n @Inject()\n protected adapter: PlatformAdapter;\n\n get(allMiddlewares: any[], operationRoute: JsonOperationRoute) {\n const {ACCEPT_MIMES, FILE} = this.getParamTypes(allMiddlewares, operationRoute);\n\n return [ACCEPT_MIMES && PlatformAcceptMimesMiddleware, FILE && PlatformMulterMiddleware, ...allMiddlewares].filter(Boolean);\n }\n\n protected hasAcceptMimes(operationRoute: JsonOperationRoute) {\n return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;\n }\n\n protected getParamTypes(middlewares: any[], operationRoute: JsonOperationRoute) {\n return middlewares.filter(isClass).reduce(\n (paramTypes, token) => {\n if (token !== operationRoute.endpoint) {\n const entity = JsonEntityStore.fromMethod(token, \"use\");\n\n if (entity.decoratorType === \"method\") {\n const {FILE, RAW_BODY, BODY} = entity.getParamTypes();\n paramTypes.FILE = paramTypes.FILE || FILE;\n paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;\n paramTypes.BODY = paramTypes.BODY || BODY;\n }\n }\n\n return paramTypes;\n },\n {\n ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),\n FILE: operationRoute.has(ParamTypes.FILES),\n RAW_BODY: operationRoute.has(ParamTypes.RAW_BODY),\n BODY: operationRoute.has(ParamTypes.BODY) || operationRoute.method === \"ALL\"\n }\n );\n }\n}\n"]}
|
|
@@ -12,7 +12,7 @@ export class PlatformTest extends DITest {
|
|
|
12
12
|
static adapter;
|
|
13
13
|
static async create(settings = {}) {
|
|
14
14
|
DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
|
|
15
|
-
await DITest.createContainer(
|
|
15
|
+
await DITest.createContainer();
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Create a new injector with the right default services
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAiC,MAAM,UAAU,CAAC;AAChE,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAyB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,MAAM;IAC/B,MAAM,CAAC,OAAO,CAAwB;IAE7C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAA0B,EAAE;QAC9C,MAAM,CAAC,QAAQ,GAAG,YAAY,CAAC,cAAc,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,MAAM,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,WAAgB,EAAE;QACtC,OAAO,cAAc,CAAC;YACpB,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,EAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAC,CAAC;SAC7E,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,GAAQ,EAAE,EAAC,MAAM,EAAE,GAAG,QAAQ,KAA0D,EAAE;QACzG,OAAO,KAAK,UAAU,MAAM;YAC1B,IAAI,QAAyB,CAAC;YAC9B,MAAM,OAAO,GAA0B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AI,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,eAAe,CAAC;YAC/B,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,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","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
|
+
{"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAkB,MAAM,UAAU,CAAC;AACjD,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAyB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CA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QAAQ,CAAC;SAClC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {DITest, 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: Partial<TsED.Configuration> = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n await DITest.createContainer();\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"]}
|
|
@@ -103,4 +103,5 @@ export declare class PlatformBuilder<App = TsED.Application> {
|
|
|
103
103
|
protected createHttpServers(): void;
|
|
104
104
|
protected listenServers(): Promise<void>;
|
|
105
105
|
protected logRoutes(layers: PlatformLayer[]): Promise<void>;
|
|
106
|
+
protected mapTokenMiddlewares(): Promise<void>;
|
|
106
107
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Type } from "@tsed/core";
|
|
3
|
-
import { DITest,
|
|
3
|
+
import { DITest, InjectorService } from "@tsed/di";
|
|
4
4
|
import { PlatformContext, PlatformContextOptions } from "../domain/PlatformContext";
|
|
5
5
|
import { PlatformAdapter, PlatformBuilderSettings } from "./PlatformAdapter";
|
|
6
6
|
/**
|
|
@@ -8,7 +8,7 @@ import { PlatformAdapter, PlatformBuilderSettings } from "./PlatformAdapter";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class PlatformTest extends DITest {
|
|
10
10
|
static adapter: Type<PlatformAdapter>;
|
|
11
|
-
static create(settings?:
|
|
11
|
+
static create(settings?: Partial<TsED.Configuration>): Promise<void>;
|
|
12
12
|
/**
|
|
13
13
|
* Create a new injector with the right default services
|
|
14
14
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/common",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -62,21 +62,21 @@
|
|
|
62
62
|
}
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@tsed/core": "7.
|
|
66
|
-
"@tsed/di": "7.
|
|
67
|
-
"@tsed/exceptions": "7.
|
|
68
|
-
"@tsed/json-mapper": "7.
|
|
65
|
+
"@tsed/core": "7.4.0",
|
|
66
|
+
"@tsed/di": "7.4.0",
|
|
67
|
+
"@tsed/exceptions": "7.4.0",
|
|
68
|
+
"@tsed/json-mapper": "7.4.0",
|
|
69
69
|
"@tsed/logger": ">=6.2.2",
|
|
70
70
|
"@tsed/logger-file": ">=6.2.2",
|
|
71
|
-
"@tsed/perf": "7.
|
|
72
|
-
"@tsed/platform-exceptions": "7.
|
|
73
|
-
"@tsed/platform-log-middleware": "7.
|
|
74
|
-
"@tsed/platform-middlewares": "7.
|
|
75
|
-
"@tsed/platform-params": "7.
|
|
76
|
-
"@tsed/platform-response-filter": "7.
|
|
77
|
-
"@tsed/platform-router": "7.
|
|
78
|
-
"@tsed/platform-views": "7.
|
|
79
|
-
"@tsed/schema": "7.
|
|
71
|
+
"@tsed/perf": "7.4.0",
|
|
72
|
+
"@tsed/platform-exceptions": "7.4.0",
|
|
73
|
+
"@tsed/platform-log-middleware": "7.4.0",
|
|
74
|
+
"@tsed/platform-middlewares": "7.4.0",
|
|
75
|
+
"@tsed/platform-params": "7.4.0",
|
|
76
|
+
"@tsed/platform-response-filter": "7.4.0",
|
|
77
|
+
"@tsed/platform-router": "7.4.0",
|
|
78
|
+
"@tsed/platform-views": "7.4.0",
|
|
79
|
+
"@tsed/schema": "7.4.0",
|
|
80
80
|
"@types/json-schema": "7.0.11",
|
|
81
81
|
"tslib": "2.4.0",
|
|
82
82
|
"uuid": "8.3.2"
|
package/readme.md
CHANGED
|
@@ -28,11 +28,13 @@
|
|
|
28
28
|
|
|
29
29
|
<hr />
|
|
30
30
|
|
|
31
|
-
> A Node.js and TypeScript Framework on top of Express. It provides a lot of decorators and guidelines to write your
|
|
31
|
+
> A Node.js and TypeScript Framework on top of Express. It provides a lot of decorators and guidelines to write your
|
|
32
|
+
> code.
|
|
32
33
|
|
|
33
34
|
## What it is
|
|
34
35
|
|
|
35
|
-
Ts.ED is a framework on top of Express that helps you to write your application in TypeScript (or in ES6). It provides a
|
|
36
|
+
Ts.ED is a framework on top of Express that helps you to write your application in TypeScript (or in ES6). It provides a
|
|
37
|
+
lot of decorators
|
|
36
38
|
to make your code more readable and less error-prone.
|
|
37
39
|
|
|
38
40
|
## Features
|
|
@@ -83,7 +85,7 @@ import methodOverride from "method-override";
|
|
|
83
85
|
|
|
84
86
|
@Configuration({
|
|
85
87
|
port: 3000,
|
|
86
|
-
middlewares: [
|
|
88
|
+
middlewares: ["cookie-parser", "compression", "method-override", "json-parser", "urlencoded-parser"]
|
|
87
89
|
})
|
|
88
90
|
export class Server {}
|
|
89
91
|
```
|
|
@@ -200,7 +202,8 @@ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com
|
|
|
200
202
|
|
|
201
203
|
## Sponsors
|
|
202
204
|
|
|
203
|
-
Support this project by becoming a sponsor. Your logo will show up here with a link to your
|
|
205
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your
|
|
206
|
+
website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
204
207
|
|
|
205
208
|
## License
|
|
206
209
|
|
|
@@ -208,10 +211,17 @@ The MIT License (MIT)
|
|
|
208
211
|
|
|
209
212
|
Copyright (c) 2016 - 2020 Romain Lenzotti
|
|
210
213
|
|
|
211
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
214
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
215
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
216
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
217
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
212
218
|
|
|
213
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
219
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
220
|
+
Software.
|
|
214
221
|
|
|
215
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
222
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
223
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
224
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
225
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
216
226
|
|
|
217
227
|
[travis]: https://travis-ci.org/
|