@tsed/common 6.89.0 → 6.92.1

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.
Files changed (69) hide show
  1. package/lib/cjs/builder/PlatformBuilder.d.ts +15 -27
  2. package/lib/cjs/builder/PlatformBuilder.js +68 -41
  3. package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
  4. package/lib/cjs/config/interfaces/index.d.ts +10 -1
  5. package/lib/cjs/config/interfaces/index.js.map +1 -1
  6. package/lib/cjs/config/services/PlatformConfiguration.d.ts +9 -13
  7. package/lib/cjs/config/services/PlatformConfiguration.js +12 -29
  8. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
  9. package/lib/cjs/decorators/httpServer.d.ts +1 -0
  10. package/lib/cjs/decorators/httpServer.js +1 -0
  11. package/lib/cjs/decorators/httpServer.js.map +1 -1
  12. package/lib/cjs/decorators/httpsServer.d.ts +1 -0
  13. package/lib/cjs/decorators/httpsServer.js +1 -0
  14. package/lib/cjs/decorators/httpsServer.js.map +1 -1
  15. package/lib/cjs/interfaces/PlatformAdapter.d.ts +19 -0
  16. package/lib/cjs/interfaces/PlatformAdapter.js +3 -0
  17. package/lib/cjs/interfaces/PlatformAdapter.js.map +1 -0
  18. package/lib/cjs/interfaces/index.d.ts +1 -0
  19. package/lib/cjs/interfaces/index.js +1 -0
  20. package/lib/cjs/interfaces/index.js.map +1 -1
  21. package/lib/cjs/services/PlatformTest.d.ts +5 -4
  22. package/lib/cjs/services/PlatformTest.js +9 -14
  23. package/lib/cjs/services/PlatformTest.js.map +1 -1
  24. package/lib/cjs/utils/createHttpServer.d.ts +3 -2
  25. package/lib/cjs/utils/createHttpServer.js +23 -24
  26. package/lib/cjs/utils/createHttpServer.js.map +1 -1
  27. package/lib/cjs/utils/createHttpsServer.d.ts +3 -2
  28. package/lib/cjs/utils/createHttpsServer.js +23 -25
  29. package/lib/cjs/utils/createHttpsServer.js.map +1 -1
  30. package/lib/cjs/utils/createInjector.js +0 -4
  31. package/lib/cjs/utils/createInjector.js.map +1 -1
  32. package/lib/cjs/utils/listenServer.d.ts +6 -9
  33. package/lib/cjs/utils/listenServer.js +11 -7
  34. package/lib/cjs/utils/listenServer.js.map +1 -1
  35. package/lib/esm/builder/PlatformBuilder.js +69 -42
  36. package/lib/esm/builder/PlatformBuilder.js.map +1 -1
  37. package/lib/esm/config/interfaces/index.js.map +1 -1
  38. package/lib/esm/config/services/PlatformConfiguration.js +12 -29
  39. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -1
  40. package/lib/esm/decorators/httpServer.js +1 -0
  41. package/lib/esm/decorators/httpServer.js.map +1 -1
  42. package/lib/esm/decorators/httpsServer.js +1 -0
  43. package/lib/esm/decorators/httpsServer.js.map +1 -1
  44. package/lib/esm/interfaces/PlatformAdapter.js +2 -0
  45. package/lib/esm/interfaces/PlatformAdapter.js.map +1 -0
  46. package/lib/esm/interfaces/index.js +1 -0
  47. package/lib/esm/interfaces/index.js.map +1 -1
  48. package/lib/esm/services/PlatformTest.js +9 -14
  49. package/lib/esm/services/PlatformTest.js.map +1 -1
  50. package/lib/esm/utils/createHttpServer.js +22 -22
  51. package/lib/esm/utils/createHttpServer.js.map +1 -1
  52. package/lib/esm/utils/createHttpsServer.js +22 -23
  53. package/lib/esm/utils/createHttpsServer.js.map +1 -1
  54. package/lib/esm/utils/createInjector.js +0 -4
  55. package/lib/esm/utils/createInjector.js.map +1 -1
  56. package/lib/esm/utils/listenServer.js +11 -7
  57. package/lib/esm/utils/listenServer.js.map +1 -1
  58. package/lib/types/builder/PlatformBuilder.d.ts +15 -27
  59. package/lib/types/config/interfaces/index.d.ts +10 -1
  60. package/lib/types/config/services/PlatformConfiguration.d.ts +9 -13
  61. package/lib/types/decorators/httpServer.d.ts +1 -0
  62. package/lib/types/decorators/httpsServer.d.ts +1 -0
  63. package/lib/types/interfaces/PlatformAdapter.d.ts +19 -0
  64. package/lib/types/interfaces/index.d.ts +1 -0
  65. package/lib/types/services/PlatformTest.d.ts +5 -4
  66. package/lib/types/utils/createHttpServer.d.ts +3 -2
  67. package/lib/types/utils/createHttpsServer.d.ts +3 -2
  68. package/lib/types/utils/listenServer.d.ts +6 -9
  69. package/package.json +15 -16
@@ -23,6 +23,7 @@ const di_1 = require("@tsed/di");
23
23
  * @param {TypedPropertyDescriptor<Function> | number} descriptor
24
24
  * @returns {any}
25
25
  * @decorator
26
+ * @deprecated Use Https.Server from "https"
26
27
  */
27
28
  function HttpsServer(target, targetKey, descriptor) {
28
29
  return (0, di_1.Inject)(HttpsServer)(target, targetKey, descriptor);
@@ -1 +1 @@
1
- {"version":3,"file":"httpsServer.js","sourceRoot":"","sources":["../../../src/decorators/httpsServer.ts"],"names":[],"mappings":";;;AACA,iCAAgC;AAGhC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,WAAW,CAAC,MAAiB,EAAE,SAAiB,EAAE,UAAsD;IACtH,OAAO,IAAA,WAAM,EAAC,WAAW,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAC5D,CAAC;AAFD,kCAEC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Inject} from \"@tsed/di\";\nimport Https from \"https\";\n\n/**\n * Inject the Https.Server instance.\n *\n * ### Example\n *\n * ```typescript\n * import {HttpsServer, Service} from \"@tsed/common\";\n *\n * @Service()\n * export default class OtherService {\n * constructor(@HttpsServer httpServer: HttpServer) {}\n * }\n * ```\n *\n * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.\n *\n * @param {Type<any>} target\n * @param {string} targetKey\n * @param {TypedPropertyDescriptor<Function> | number} descriptor\n * @returns {any}\n * @decorator\n */\nexport function HttpsServer(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number) {\n return Inject(HttpsServer)(target, targetKey, descriptor);\n}\n\nexport type HttpsServer = Https.Server;\n"]}
1
+ {"version":3,"file":"httpsServer.js","sourceRoot":"","sources":["../../../src/decorators/httpsServer.ts"],"names":[],"mappings":";;;AACA,iCAAgC;AAGhC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,WAAW,CAAC,MAAiB,EAAE,SAAiB,EAAE,UAAsD;IACtH,OAAO,IAAA,WAAM,EAAC,WAAW,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAC5D,CAAC;AAFD,kCAEC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Inject} from \"@tsed/di\";\nimport Https from \"https\";\n\n/**\n * Inject the Https.Server instance.\n *\n * ### Example\n *\n * ```typescript\n * import {HttpsServer, Service} from \"@tsed/common\";\n *\n * @Service()\n * export default class OtherService {\n * constructor(@HttpsServer httpServer: HttpServer) {}\n * }\n * ```\n *\n * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.\n *\n * @param {Type<any>} target\n * @param {string} targetKey\n * @param {TypedPropertyDescriptor<Function> | number} descriptor\n * @returns {any}\n * @decorator\n * @deprecated Use Https.Server from \"https\"\n */\nexport function HttpsServer(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number) {\n return Inject(HttpsServer)(target, targetKey, descriptor);\n}\n\nexport type HttpsServer = Https.Server;\n"]}
@@ -0,0 +1,19 @@
1
+ import { Type } from "@tsed/core";
2
+ import { IProvider } from "@tsed/di";
3
+ export interface PlatformAdapter<App = TsED.Application, Router = TsED.Router> {
4
+ /**
5
+ * Load providers in top priority
6
+ */
7
+ readonly providers: IProvider[];
8
+ /**
9
+ * Called after the injector instantiation
10
+ */
11
+ onInit?: () => any;
12
+ beforeLoadRoutes?: () => Promise<any>;
13
+ afterLoadRoutes?: () => Promise<any>;
14
+ useRouter?: () => any;
15
+ useContext?: () => any;
16
+ }
17
+ export interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {
18
+ adapter?: Type<PlatformAdapter<App, Router>>;
19
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=PlatformAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformAdapter.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {IProvider} from \"@tsed/di\";\n\nexport interface PlatformAdapter<App = TsED.Application, Router = TsED.Router> {\n /**\n * Load providers in top priority\n */\n readonly providers: IProvider[];\n /**\n * Called after the injector instantiation\n */\n onInit?: () => any;\n beforeLoadRoutes?: () => Promise<any>;\n afterLoadRoutes?: () => Promise<any>;\n useRouter?: () => any;\n useContext?: () => any;\n}\n\nexport interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {\n adapter?: Type<PlatformAdapter<App, Router>>;\n}\n"]}
@@ -14,3 +14,4 @@ export * from "./OnRequest";
14
14
  export * from "./OnResponse";
15
15
  export * from "./Route";
16
16
  export * from "./IncomingEvent";
17
+ export * from "./PlatformAdapter";
@@ -17,4 +17,5 @@ const tslib_1 = require("tslib");
17
17
  (0, tslib_1.__exportStar)(require("./OnResponse"), exports);
18
18
  (0, tslib_1.__exportStar)(require("./Route"), exports);
19
19
  (0, tslib_1.__exportStar)(require("./IncomingEvent"), exports);
20
+ (0, tslib_1.__exportStar)(require("./PlatformAdapter"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,qEAAsC;AACtC,6DAA8B;AAC9B,sEAAuC;AACvC,4DAA6B;AAC7B,2DAA4B;AAC5B,iEAAkC;AAClC,8DAA+B;AAC/B,6DAA8B;AAC9B,kEAAmC;AACnC,iEAAkC;AAClC,8DAA+B;AAC/B,yDAA0B;AAC1B,2DAA4B;AAC5B,4DAA6B;AAC7B,uDAAwB;AACxB,+DAAgC","sourcesContent":["export * from \"./ResponseErrorObject\";\nexport * from \"./HandlerType\";\nexport * from \"./PlatformRouteOptions\";\nexport * from \"./BeforeInit\";\nexport * from \"./AfterInit\";\nexport * from \"./AfterRoutesInit\";\nexport * from \"./BeforeListen\";\nexport * from \"./AfterListen\";\nexport * from \"./BeforeRoutesInit\";\nexport * from \"./AfterRoutesInit\";\nexport * from \"./OnRoutesInit\";\nexport * from \"./OnReady\";\nexport * from \"./OnRequest\";\nexport * from \"./OnResponse\";\nexport * from \"./Route\";\nexport * from \"./IncomingEvent\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAAA,qEAAsC;AACtC,6DAA8B;AAC9B,sEAAuC;AACvC,4DAA6B;AAC7B,2DAA4B;AAC5B,iEAAkC;AAClC,8DAA+B;AAC/B,6DAA8B;AAC9B,kEAAmC;AACnC,iEAAkC;AAClC,8DAA+B;AAC/B,yDAA0B;AAC1B,2DAA4B;AAC5B,4DAA6B;AAC7B,uDAAwB;AACxB,+DAAgC;AAChC,iEAAkC","sourcesContent":["export * from \"./ResponseErrorObject\";\nexport * from \"./HandlerType\";\nexport * from \"./PlatformRouteOptions\";\nexport * from \"./BeforeInit\";\nexport * from \"./AfterInit\";\nexport * from \"./AfterRoutesInit\";\nexport * from \"./BeforeListen\";\nexport * from \"./AfterListen\";\nexport * from \"./BeforeRoutesInit\";\nexport * from \"./AfterRoutesInit\";\nexport * from \"./OnRoutesInit\";\nexport * from \"./OnReady\";\nexport * from \"./OnRequest\";\nexport * from \"./OnResponse\";\nexport * from \"./Route\";\nexport * from \"./IncomingEvent\";\nexport * from \"./PlatformAdapter\";\n"]}
@@ -1,12 +1,12 @@
1
- import { Type } from "@tsed/core";
2
1
  import { DITest, InjectorService } from "@tsed/di";
3
- import { PlatformBuilder } from "../builder/PlatformBuilder";
4
2
  import { PlatformContext, PlatformContextOptions } from "../domain/PlatformContext";
3
+ import { PlatformAdapter, PlatformBuilderSettings } from "../interfaces/PlatformAdapter";
4
+ import { Type } from "@tsed/core";
5
5
  /**
6
6
  * @platform
7
7
  */
8
8
  export declare class PlatformTest extends DITest {
9
- static platformBuilder: Type<PlatformBuilder<any, any>>;
9
+ static adapter: Type<PlatformAdapter>;
10
10
  static create(settings?: Partial<TsED.Configuration>): Promise<void>;
11
11
  /**
12
12
  * Create a new injector with the right default services
@@ -16,10 +16,11 @@ export declare class PlatformTest extends DITest {
16
16
  * Load the server silently without listening port and configure it on test profile.
17
17
  * @decorator
18
18
  * @param mod
19
+ * @param listen
19
20
  * @param settings
20
21
  * @returns {Promise<void>}
21
22
  */
22
- static bootstrap(mod: any, settings?: Partial<TsED.Configuration & {
23
+ static bootstrap(mod: any, { listen, ...settings }?: Partial<PlatformBuilderSettings & {
23
24
  listen: boolean;
24
25
  }>): () => Promise<void>;
25
26
  /**
@@ -22,35 +22,30 @@ class PlatformTest extends di_1.DITest {
22
22
  static createInjector(settings = {}) {
23
23
  return (0, createInjector_1.createInjector)({
24
24
  providers: [],
25
- settings: di_1.DITest.configure(settings)
25
+ settings: di_1.DITest.configure({ httpPort: false, httpsPort: false, ...settings })
26
26
  });
27
27
  }
28
28
  /**
29
29
  * Load the server silently without listening port and configure it on test profile.
30
30
  * @decorator
31
31
  * @param mod
32
+ * @param listen
32
33
  * @param settings
33
34
  * @returns {Promise<void>}
34
35
  */
35
- static bootstrap(mod, settings = {}) {
36
+ static bootstrap(mod, { listen, ...settings } = {}) {
36
37
  return async function before() {
37
38
  let instance;
38
- const platform = settings.platform || PlatformTest.platformBuilder;
39
+ const adapter = settings.platform || settings.adapter || PlatformTest.adapter;
39
40
  /* istanbul ignore next */
40
- if (!platform) {
41
- throw new Error("Platform type is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?");
41
+ if (!adapter) {
42
+ throw new Error("Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?");
42
43
  }
43
44
  // @ts-ignore
44
45
  settings = di_1.DITest.configure(settings);
45
- instance = await PlatformBuilder_1.PlatformBuilder.build(platform, mod, settings).bootstrap();
46
- if (!settings.listen) {
47
- await instance.callHook("$beforeListen");
48
- await instance.callHook("$afterListen");
49
- await instance.ready();
50
- }
51
- else {
52
- await instance.listen();
53
- }
46
+ settings.adapter = adapter;
47
+ instance = await PlatformBuilder_1.PlatformBuilder.build(mod, settings).bootstrap();
48
+ await instance.listen(!!listen);
54
49
  // used by inject method
55
50
  di_1.DITest.injector = instance.injector;
56
51
  };
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":";;;AACA,iCAAkE;AAClE,gEAAyE;AACzE,+DAAkF;AAClF,4DAAuD;AACvD,+DAA0D;AAC1D,gEAA2D;AAE3D;;GAEG;AACH,MAAa,YAAa,SAAQ,WAAM;IAGtC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAwC,EAAE;QAC5D,WAAM,CAAC,QAAQ,GAAG,YAAY,CAAC,cAAc,CAAC,IAAA,mCAAgB,EAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,MAAM,SAAS,GAAG,IAAA,oBAAe,GAAE,CAAC;QAEpC,MAAM,WAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,WAAgB,EAAE;QACtC,OAAO,IAAA,+BAAc,EAAC;YACpB,SAAS,EAAE,EAAE;YACb,QAAQ,EAAE,WAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;SACrC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,GAAQ,EAAE,WAA4D,EAAE;QACvF,OAAO,KAAK,UAAU,MAAM;YAC1B,IAAI,QAAa,CAAC;YAClB,MAAM,QAAQ,GAAiB,QAAQ,CA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AAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AA9KD,oCA8KC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {createContainer, DITest, InjectorService} from \"@tsed/di\";\nimport {PlatformBuilder, PlatformType} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static platformBuilder: Type<PlatformBuilder<any, any>>;\n\n static async create(settings: Partial<TsED.Configuration> = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n const container = createContainer();\n\n await DITest.injector.load(container);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n providers: [],\n settings: DITest.configure(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 settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, settings: Partial<TsED.Configuration & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: any;\n const platform: PlatformType = settings.platform || PlatformTest.platformBuilder;\n\n /* istanbul ignore next */\n if (!platform) {\n throw new Error(\n \"Platform type 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 instance = await PlatformBuilder.build(platform, mod, settings).bootstrap();\n\n if (!settings.listen) {\n await instance.callHook(\"$beforeListen\");\n await instance.callHook(\"$afterListen\");\n await instance.ready();\n } else {\n await instance.listen();\n }\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return require(\"accepts\")(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":";;;AAAA,iCAAkE;AAClE,gEAA2D;AAC3D,+DAAkF;AAClF,4DAAuD;AACvD,+DAA0D;AAC1D,gEAA2D;AAI3D;;GAEG;AACH,MAAa,YAAa,SAAQ,WAAM;IAGtC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAwC,EAAE;QAC5D,WAAM,CAAC,QAAQ,GAAG,YAAY,CAAC,cAAc,CAAC,IAAA,mCAAgB,EAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,MAAM,SAAS,GAAG,IAAA,oBAAe,GAAE,CAAC;QAEpC,MAAM,WAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,WAAgB,EAAE;QACtC,OAAO,IAAA,+BAAc,EAAC;YACpB,SAAS,EAAE,EAAE;YACb,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,OAAO,KAAK,UAAU,MAAM;YAC1B,IAAI,QAAyB,CAAC;YAC9B,MAAM,OAAO,GAA0B,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC;YAErG,0BAA0B;YAC1B,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,KAAK,CACb,gIAAgI,CACjI,CAAC;aACH;YAED,aAAa;YACb,QAAQ,GAAG,WAAM,CAAC,SA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,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,CAAC,IAAS;gBACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,IAAI,CAAC,IAAS;gBACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,UAAiD,EAAE;;QAC7E,MAAM,KAAK,GAAG;YACZ,OAAO,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,OAAO,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,OAAO,CAAA,IAAI,YAAY,CAAC,aAAa,EAAE;YAC7F,QAAQ,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,0CAAE,QAAQ,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,QAAQ,CAAA,IAAI,YAAY,CAAC,cAAc,EAAE;SACnG,CAAC;QAEF,OAAO,IAAI,iCAAe,CAAC;YACzB,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,WAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,WAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AA1KD,oCA0KC","sourcesContent":["import {createContainer, DITest, InjectorService} from \"@tsed/di\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../interfaces/PlatformAdapter\";\nimport {Type} from \"@tsed/core\";\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 const container = createContainer();\n\n await DITest.injector.load(container);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n providers: [],\n settings: DITest.configure({httpPort: false, httpsPort: false, ...settings})\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: PlatformBuilder;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n instance = await PlatformBuilder.build(mod, settings).bootstrap();\n await instance.listen(!!listen);\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return require(\"accepts\")(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { InjectorService } from "@tsed/di";
2
- export declare function createHttpServer(injector: InjectorService): void;
3
- export declare function listenHttpServer(injector: InjectorService): Promise<void>;
3
+ import Http from "http";
4
+ export declare function createHttpServer(injector: InjectorService, requestListener: Http.RequestListener): (() => Promise<void>) | undefined;
@@ -1,35 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listenHttpServer = exports.createHttpServer = void 0;
3
+ exports.createHttpServer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const di_1 = require("@tsed/di");
6
+ const core_1 = require("@tsed/core");
6
7
  const http_1 = (0, tslib_1.__importDefault)(require("http"));
7
- const PlatformApplication_1 = require("../services/PlatformApplication");
8
8
  const httpServer_1 = require("../decorators/httpServer");
9
9
  const listenServer_1 = require("./listenServer");
10
- function createHttpServer(injector) {
11
- injector.invoke(httpServer_1.HttpServer);
12
- }
13
- exports.createHttpServer = createHttpServer;
14
- (0, di_1.registerProvider)({
15
- provide: httpServer_1.HttpServer,
16
- deps: [PlatformApplication_1.PlatformApplication],
17
- scope: di_1.ProviderScope.SINGLETON,
18
- global: true,
19
- useFactory(platformApplication) {
20
- return http_1.default.createServer(platformApplication.callback());
21
- }
22
- });
23
- async function listenHttpServer(injector) {
10
+ function createHttpServer(injector, requestListener) {
24
11
  const { settings } = injector;
25
- const server = injector.get(httpServer_1.HttpServer);
26
- if (settings.httpPort !== false && server) {
27
- const { address, port } = settings.getHttpPort();
28
- injector.logger.debug(`Start server on http://${address}:${port}`);
29
- const options = await (0, listenServer_1.listenServer)(server, { address, port });
30
- settings.setHttpPort(options);
31
- injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
12
+ const httpPort = settings.getRaw("httpPort");
13
+ const httpOptions = settings.getRaw("httpOptions");
14
+ const server = httpPort !== false ? http_1.default.createServer(httpOptions, requestListener) : null;
15
+ injector.addProvider(httpServer_1.HttpServer, {
16
+ scope: di_1.ProviderScope.SINGLETON,
17
+ useValue: server
18
+ });
19
+ injector.addProvider(http_1.default.Server, {
20
+ scope: di_1.ProviderScope.SINGLETON,
21
+ useValue: server
22
+ });
23
+ injector.invoke(httpServer_1.HttpServer);
24
+ injector.invoke(http_1.default.Server);
25
+ if (httpPort !== false) {
26
+ const hostInfo = (0, core_1.getHostInfoFromPort)("http", httpPort);
27
+ return async () => {
28
+ const resolvedHostInfo = await (0, listenServer_1.listenServer)(injector, server, hostInfo);
29
+ settings.setRaw("httpPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
30
+ };
32
31
  }
33
32
  }
34
- exports.listenHttpServer = listenHttpServer;
33
+ exports.createHttpServer = createHttpServer;
35
34
  //# sourceMappingURL=createHttpServer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createHttpServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpServer.ts"],"names":[],"mappings":";;;;AAAA,iCAA0E;AAC1E,6DAAwB;AACxB,yEAAoE;AACpE,yDAAoD;AACpD,iDAA4C;AAE5C,SAAgB,gBAAgB,CAAC,QAAyB;IACxD,QAAQ,CAAC,MAAM,CAAC,uBAAU,CAAC,CAAC;AAC9B,CAAC;AAFD,4CAEC;AAED,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,uBAAU;IACnB,IAAI,EAAE,CAAC,yCAAmB,CAAC;IAC3B,KAAK,EAAE,kBAAa,CAAC,SAAS;IAC9B,MAAM,EAAE,IAAI;IACZ,UAAU,CAAC,mBAAwC;QACjD,OAAO,cAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF,CAAC,CAAC;AAEI,KAAK,UAAU,gBAAgB,CAAC,QAAyB;IAC9D,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAa,uBAAU,CAAC,CAAC;IAEpD,IAAI,QAAQ,CAAC,QAAQ,KAAK,KAAK,IAAI,MAAM,EAAE;QACzC,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC/C,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC;QAEnE,MAAM,OAAO,GAAG,MAAM,IAAA,2BAAY,EAAC,MAAM,EAAE,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;QAC5D,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAE9B,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACpF;AACH,CAAC;AAbD,4CAaC","sourcesContent":["import {InjectorService, ProviderScope, registerProvider} from \"@tsed/di\";\nimport Http from \"http\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {HttpServer} from \"../decorators/httpServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpServer(injector: InjectorService): void {\n injector.invoke(HttpServer);\n}\n\nregisterProvider({\n provide: HttpServer,\n deps: [PlatformApplication],\n scope: ProviderScope.SINGLETON,\n global: true,\n useFactory(platformApplication: PlatformApplication) {\n return Http.createServer(platformApplication.callback());\n }\n});\n\nexport async function listenHttpServer(injector: InjectorService) {\n const {settings} = injector;\n const server = injector.get<HttpServer>(HttpServer);\n\n if (settings.httpPort !== false && server) {\n const {address, port} = settings.getHttpPort();\n injector.logger.debug(`Start server on http://${address}:${port}`);\n\n const options = await listenServer(server, {address, port});\n settings.setHttpPort(options);\n\n injector.logger.info(`Listen server on http://${options.address}:${options.port}`);\n }\n}\n"]}
1
+ {"version":3,"file":"createHttpServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,6DAAwB;AACxB,yDAAoD;AACpD,iDAA4C;AAE5C,SAAgB,gBAAgB,CAAC,QAAyB,EAAE,eAAqC;IAC/F,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAEnD,MAAM,MAAM,GAAG,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,cAAI,CAAC,YAAY,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3F,QAAQ,CAAC,WAAW,CAAC,uBAAU,EAAE;QAC/B,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,WAAW,CAAC,cAAI,CAAC,MAAM,EAAE;QAChC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,uBAAU,CAAC,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,cAAI,CAAC,MAAM,CAAC,CAAC;IAE7B,IAAI,QAAQ,KAAK,KAAK,EAAE;QACtB,MAAM,QAAQ,GAAG,IAAA,0BAAmB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEvD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,IAAA,2BAAY,EAAC,QAAQ,EAAE,MAAqB,EAAE,QAAQ,CAAC,CAAC;YACvF,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;QACtF,CAAC,CAAC;KACH;AACH,CAAC;AA5BD,4CA4BC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Http from \"http\";\nimport {HttpServer} from \"../decorators/httpServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpServer(injector: InjectorService, requestListener: Http.RequestListener) {\n const {settings} = injector;\n const httpPort = settings.getRaw(\"httpPort\");\n const httpOptions = settings.getRaw(\"httpOptions\");\n\n const server = httpPort !== false ? Http.createServer(httpOptions, requestListener) : null;\n\n injector.addProvider(HttpServer, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.addProvider(Http.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(HttpServer);\n injector.invoke(Http.Server);\n\n if (httpPort !== false) {\n const hostInfo = getHostInfoFromPort(\"http\", httpPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Http.Server, hostInfo);\n settings.setRaw(\"httpPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n };\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { InjectorService } from "@tsed/di";
2
- export declare function createHttpsServer(injector: InjectorService): void;
3
- export declare function listenHttpsServer(injector: InjectorService): Promise<void>;
3
+ import Http from "http";
4
+ export declare function createHttpsServer(injector: InjectorService, requestListener?: Http.RequestListener): (() => Promise<void>) | undefined;
@@ -1,36 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listenHttpsServer = exports.createHttpsServer = void 0;
3
+ exports.createHttpsServer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const di_1 = require("@tsed/di");
6
+ const core_1 = require("@tsed/core");
6
7
  const https_1 = (0, tslib_1.__importDefault)(require("https"));
7
- const PlatformApplication_1 = require("../services/PlatformApplication");
8
8
  const httpsServer_1 = require("../decorators/httpsServer");
9
9
  const listenServer_1 = require("./listenServer");
10
- function createHttpsServer(injector) {
11
- injector.invoke(httpsServer_1.HttpsServer);
12
- }
13
- exports.createHttpsServer = createHttpsServer;
14
- (0, di_1.registerProvider)({
15
- provide: httpsServer_1.HttpsServer,
16
- deps: [PlatformApplication_1.PlatformApplication, di_1.Configuration],
17
- scope: di_1.ProviderScope.SINGLETON,
18
- global: true,
19
- useFactory(platformApplication, settings) {
20
- const options = settings.httpsOptions;
21
- return https_1.default.createServer(options, platformApplication.callback());
22
- }
23
- });
24
- async function listenHttpsServer(injector) {
10
+ function createHttpsServer(injector, requestListener) {
25
11
  const { settings } = injector;
26
- const server = injector.get(httpsServer_1.HttpsServer);
27
- if (settings.httpsPort !== false && server) {
28
- const { address, port } = settings.getHttpsPort();
29
- injector.logger.debug(`Start server on https://${address}:${port}`);
30
- const options = await (0, listenServer_1.listenServer)(server, { address, port });
31
- settings.setHttpsPort(options);
32
- injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
12
+ const httpsPort = settings.getRaw("httpsPort");
13
+ const httpsOptions = settings.getRaw("httpsOptions");
14
+ const server = httpsPort !== false ? https_1.default.createServer(httpsOptions, requestListener) : null;
15
+ injector.addProvider(httpsServer_1.HttpsServer, {
16
+ scope: di_1.ProviderScope.SINGLETON,
17
+ useValue: server
18
+ });
19
+ injector.addProvider(https_1.default.Server, {
20
+ scope: di_1.ProviderScope.SINGLETON,
21
+ useValue: server
22
+ });
23
+ injector.invoke(httpsServer_1.HttpsServer);
24
+ injector.invoke(https_1.default.Server);
25
+ if (httpsPort !== false) {
26
+ const hostInfo = (0, core_1.getHostInfoFromPort)("https", httpsPort);
27
+ return async () => {
28
+ const resolvedHostInfo = await (0, listenServer_1.listenServer)(injector, server, hostInfo);
29
+ settings.setRaw("httpsPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
30
+ };
33
31
  }
34
32
  }
35
- exports.listenHttpsServer = listenHttpsServer;
33
+ exports.createHttpsServer = createHttpsServer;
36
34
  //# sourceMappingURL=createHttpsServer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createHttpsServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpsServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAyF;AACzF,+DAA0B;AAC1B,yEAAoE;AACpE,2DAAsD;AACtD,iDAA4C;AAE5C,SAAgB,iBAAiB,CAAC,QAAyB;IACzD,QAAQ,CAAC,MAAM,CAAC,yBAAW,CAAC,CAAC;AAC/B,CAAC;AAFD,8CAEC;AAED,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,yBAAW;IACpB,IAAI,EAAE,CAAC,yCAAmB,EAAE,kBAAa,CAAC;IAC1C,KAAK,EAAE,kBAAa,CAAC,SAAS;IAC9B,MAAM,EAAE,IAAI;IACZ,UAAU,CAAC,mBAAwC,EAAE,QAAuB;QAC1E,MAAM,OAAO,GAAG,QAAQ,CAAC,YAAa,CAAC;QAEvC,OAAO,eAAK,CAAC,YAAY,CAAC,OAAO,EAAE,mBAAmB,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrE,CAAC;CACF,CAAC,CAAC;AAEI,KAAK,UAAU,iBAAiB,CAAC,QAAyB;IAC/D,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAc,yBAAW,CAAC,CAAC;IAEtD,IAAI,QAAQ,CAAC,SAAS,KAAK,KAAK,IAAI,MAAM,EAAE;QAC1C,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,QAAQ,CAAC,YAAY,EAAE,CAAC;QAChD,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC;QAEpE,MAAM,OAAO,GAAG,MAAM,IAAA,2BAAY,EAAC,MAAM,EAAE,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;QAC5D,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE/B,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACrF;AACH,CAAC;AAbD,8CAaC","sourcesContent":["import {Configuration, InjectorService, ProviderScope, registerProvider} from \"@tsed/di\";\nimport Https from \"https\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {HttpsServer} from \"../decorators/httpsServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpsServer(injector: InjectorService): void {\n injector.invoke(HttpsServer);\n}\n\nregisterProvider({\n provide: HttpsServer,\n deps: [PlatformApplication, Configuration],\n scope: ProviderScope.SINGLETON,\n global: true,\n useFactory(platformApplication: PlatformApplication, settings: Configuration) {\n const options = settings.httpsOptions!;\n\n return Https.createServer(options, platformApplication.callback());\n }\n});\n\nexport async function listenHttpsServer(injector: InjectorService) {\n const {settings} = injector;\n const server = injector.get<HttpsServer>(HttpsServer);\n\n if (settings.httpsPort !== false && server) {\n const {address, port} = settings.getHttpsPort();\n injector.logger.debug(`Start server on https://${address}:${port}`);\n\n const options = await listenServer(server, {address, port});\n settings.setHttpsPort(options);\n\n injector.logger.info(`Listen server on https://${options.address}:${options.port}`);\n }\n}\n"]}
1
+ {"version":3,"file":"createHttpsServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpsServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,+DAA0B;AAE1B,2DAAsD;AACtD,iDAA4C;AAE5C,SAAgB,iBAAiB,CAAC,QAAyB,EAAE,eAAsC;IACjG,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAErD,MAAM,MAAM,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,eAAK,CAAC,YAAY,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE9F,QAAQ,CAAC,WAAW,CAAC,yBAAW,EAAE;QAChC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,WAAW,CAAC,eAAK,CAAC,MAAM,EAAE;QACjC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,yBAAW,CAAC,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,eAAK,CAAC,MAAM,CAAC,CAAC;IAE9B,IAAI,SAAS,KAAK,KAAK,EAAE;QACvB,MAAM,QAAQ,GAAG,IAAA,0BAAmB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAEzD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,IAAA,2BAAY,EAAC,QAAQ,EAAE,MAAsB,EAAE,QAAQ,CAAC,CAAC;YACxF,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;QACvF,CAAC,CAAC;KACH;AACH,CAAC;AA5BD,8CA4BC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Https from \"https\";\nimport Http from \"http\";\nimport {HttpsServer} from \"../decorators/httpsServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpsServer(injector: InjectorService, requestListener?: Http.RequestListener) {\n const {settings} = injector;\n const httpsPort = settings.getRaw(\"httpsPort\");\n const httpsOptions = settings.getRaw(\"httpsOptions\");\n\n const server = httpsPort !== false ? Https.createServer(httpsOptions, requestListener) : null;\n\n injector.addProvider(HttpsServer, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.addProvider(Https.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(HttpsServer);\n injector.invoke(Https.Server);\n\n if (httpsPort !== false) {\n const hostInfo = getHostInfoFromPort(\"https\", httpsPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Https.Server, hostInfo);\n settings.setRaw(\"httpsPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n };\n }\n}\n"]}
@@ -11,8 +11,6 @@ const PlatformRouter_1 = require("../services/PlatformRouter");
11
11
  const PlatformApplication_1 = require("../services/PlatformApplication");
12
12
  const Platform_1 = require("../services/Platform");
13
13
  const PlatformRequest_1 = require("../services/PlatformRequest");
14
- const createHttpsServer_1 = require("./createHttpsServer");
15
- const createHttpServer_1 = require("./createHttpServer");
16
14
  logger_1.$log.name = "TSED";
17
15
  const DEFAULT_PROVIDERS = [
18
16
  { provide: PlatformHandler_1.PlatformHandler },
@@ -34,8 +32,6 @@ function createInjector({ providers = [], settings = {} }) {
34
32
  injector.addProvider(token, provider);
35
33
  });
36
34
  injector.invoke(PlatformApplication_1.PlatformApplication);
37
- (0, createHttpsServer_1.createHttpsServer)(injector);
38
- (0, createHttpServer_1.createHttpServer)(injector);
39
35
  return injector;
40
36
  }
41
37
  exports.createInjector = createInjector;
@@ -1 +1 @@
1
- {"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":";;;AAAA,iCAAoE;AACpE,yCAAkC;AAClC,qCAAuC;AACvC,oFAA+E;AAC/E,iEAA4D;AAC5D,mEAA8D;AAC9D,+DAA0D;AAC1D,yEAAoE;AACpE,mDAA8C;AAC9C,iEAA4D;AAC5D,2DAAsD;AACtD,yDAAoD;AAEpD,aAAI,CAAC,IAAI,GAAG,MAAM,CAAC;AAEnB,MAAM,iBAAiB,GAAG;IACxB,EAAC,OAAO,EAAE,iCAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,mCAAgB,EAAC;IAC3B,EAAC,OAAO,EAAE,iCAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,+BAAc,EAAC;IACzB,EAAC,OAAO,EAAE,yCAAmB,EAAC;IAC9B,EAAC,OAAO,EAAE,mBAAQ,EAAC;CACpB,CAAC;AAOF,SAAgB,cAAc,CAAC,EAAC,SAAS,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAwB;IACnF,MAAM,QAAQ,GAAG,IAAI,oBAAe,EAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,6CAAqB,CAAC,CAAC;IAE5C,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,6CAAqB,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,GAAG,aAAI,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEhC,IAAA,mBAAc,EAAC,QAAQ,CAAC,CAAC;IAEzB,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,SAAS,CAAC,CAAC;IAEjD,IAAA,YAAK,EAAiB,SAAS,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtE,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,yCAAmB,CAAC,CAAC;IACrC,IAAA,qCAAiB,EAAC,QAAQ,CAAC,CAAC;IAC5B,IAAA,mCAAgB,EAAC,QAAQ,CAAC,CAAC;IAE3B,OAAO,QAAQ,CAAC;AAClB,CAAC;AArBD,wCAqBC","sourcesContent":["import {InjectorService, IProvider, setLoggerLevel} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {toMap, Type} from \"@tsed/core\";\nimport {PlatformConfiguration} from \"../config/services/PlatformConfiguration\";\nimport {PlatformHandler} from \"../services/PlatformHandler\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\nimport {PlatformRouter} from \"../services/PlatformRouter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {createHttpsServer} from \"./createHttpsServer\";\nimport {createHttpServer} from \"./createHttpServer\";\n\n$log.name = \"TSED\";\n\nconst DEFAULT_PROVIDERS = [\n {provide: PlatformHandler},\n {provide: PlatformResponse},\n {provide: PlatformRequest},\n {provide: PlatformRouter},\n {provide: PlatformApplication},\n {provide: Platform}\n];\n\ninterface CreateInjectorOptions {\n providers?: IProvider[];\n settings?: Partial<TsED.Configuration>;\n}\n\nexport function createInjector({providers = [], settings = {}}: CreateInjectorOptions) {\n const injector = new InjectorService();\n injector.addProvider(PlatformConfiguration);\n\n injector.settings = injector.invoke(PlatformConfiguration);\n injector.logger = $log;\n injector.settings.set(settings);\n\n setLoggerLevel(injector);\n\n providers = [...DEFAULT_PROVIDERS, ...providers];\n\n toMap<any, IProvider>(providers, \"provide\").forEach((provider, token) => {\n injector.addProvider(token, provider);\n });\n\n injector.invoke(PlatformApplication);\n createHttpsServer(injector);\n createHttpServer(injector);\n\n return injector;\n}\n"]}
1
+ {"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":";;;AAAA,iCAAoE;AACpE,yCAAkC;AAClC,qCAAiC;AACjC,oFAA+E;AAC/E,iEAA4D;AAC5D,mEAA8D;AAC9D,+DAA0D;AAC1D,yEAAoE;AACpE,mDAA8C;AAC9C,iEAA4D;AAE5D,aAAI,CAAC,IAAI,GAAG,MAAM,CAAC;AAEnB,MAAM,iBAAiB,GAAG;IACxB,EAAC,OAAO,EAAE,iCAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,mCAAgB,EAAC;IAC3B,EAAC,OAAO,EAAE,iCAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,+BAAc,EAAC;IACzB,EAAC,OAAO,EAAE,yCAAmB,EAAC;IAC9B,EAAC,OAAO,EAAE,mBAAQ,EAAC;CACpB,CAAC;AAOF,SAAgB,cAAc,CAAC,EAAC,SAAS,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAwB;IACnF,MAAM,QAAQ,GAAG,IAAI,oBAAe,EAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,6CAAqB,CAAC,CAAC;IAE5C,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,6CAAqB,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,GAAG,aAAI,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEhC,IAAA,mBAAc,EAAC,QAAQ,CAAC,CAAC;IAEzB,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,SAAS,CAAC,CAAC;IAEjD,IAAA,YAAK,EAAiB,SAAS,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtE,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,yCAAmB,CAAC,CAAC;IAErC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAnBD,wCAmBC","sourcesContent":["import {InjectorService, IProvider, setLoggerLevel} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {toMap} from \"@tsed/core\";\nimport {PlatformConfiguration} from \"../config/services/PlatformConfiguration\";\nimport {PlatformHandler} from \"../services/PlatformHandler\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\nimport {PlatformRouter} from \"../services/PlatformRouter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\n\n$log.name = \"TSED\";\n\nconst DEFAULT_PROVIDERS = [\n {provide: PlatformHandler},\n {provide: PlatformResponse},\n {provide: PlatformRequest},\n {provide: PlatformRouter},\n {provide: PlatformApplication},\n {provide: Platform}\n];\n\ninterface CreateInjectorOptions {\n providers?: IProvider[];\n settings?: Partial<TsED.Configuration>;\n}\n\nexport function createInjector({providers = [], settings = {}}: CreateInjectorOptions) {\n const injector = new InjectorService();\n injector.addProvider(PlatformConfiguration);\n\n injector.settings = injector.invoke(PlatformConfiguration);\n injector.logger = $log;\n injector.settings.set(settings);\n\n setLoggerLevel(injector);\n\n providers = [...DEFAULT_PROVIDERS, ...providers];\n\n toMap<any, IProvider>(providers, \"provide\").forEach((provider, token) => {\n injector.addProvider(token, provider);\n });\n\n injector.invoke(PlatformApplication);\n\n return injector;\n}\n"]}
@@ -1,10 +1,7 @@
1
1
  /// <reference types="node" />
2
- import Http from "http";
3
- import Https from "https";
4
- export declare function listenServer(http: Http.Server | Https.Server, settings: {
5
- address: string | number;
6
- port: number;
7
- }): Promise<{
8
- address: string;
9
- port: number;
10
- }>;
2
+ import type Http from "http";
3
+ import type Https from "https";
4
+ import type Http2 from "http2";
5
+ import { InjectorService } from "@tsed/di";
6
+ import { getHostInfoFromPort } from "@tsed/core";
7
+ export declare function listenServer(injector: InjectorService, server: Http.Server | Https.Server | Http2.Http2Server, hostInfo: ReturnType<typeof getHostInfoFromPort>): Promise<ReturnType<typeof getHostInfoFromPort>>;
@@ -1,16 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listenServer = void 0;
4
- function listenServer(http, settings) {
5
- const { address, port } = settings;
4
+ function listenServer(injector, server, hostInfo) {
5
+ const { protocol, address, port } = hostInfo;
6
+ const url = `${protocol}://${address}:${port}`;
7
+ injector.logger.debug(`Start server on ${url}`);
6
8
  const promise = new Promise((resolve, reject) => {
7
- http.on("listening", resolve);
8
- http.on("error", reject);
9
+ server.on("listening", resolve);
10
+ server.on("error", reject);
9
11
  }).then(() => {
10
- const port = http.address().port;
11
- return { address: settings.address, port };
12
+ const port = server.address().port;
13
+ const info = { ...hostInfo, port };
14
+ injector.logger.info(`Listen server on ${info.toString()}`);
15
+ return info;
12
16
  });
13
- http.listen(port, address);
17
+ server.listen(port, address);
14
18
  return promise;
15
19
  }
16
20
  exports.listenServer = listenServer;
@@ -1 +1 @@
1
- {"version":3,"file":"listenServer.js","sourceRoot":"","sources":["../../../src/utils/listenServer.ts"],"names":[],"mappings":";;;AAGA,SAAgB,YAAY,CAC1B,IAAgC,EAChC,QAAkD;IAElD,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,QAAQ,CAAC;IAEjC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACX,MAAM,IAAI,GAAI,IAAI,CAAC,OAAO,EAAU,CAAC,IAAI,CAAC;QAE1C,OAAO,EAAC,OAAO,EAAE,QAAQ,CAAC,OAAiB,EAAE,IAAI,EAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAc,CAAC,CAAC;IAElC,OAAO,OAAO,CAAC;AACjB,CAAC;AAlBD,oCAkBC","sourcesContent":["import Http from \"http\";\nimport Https from \"https\";\n\nexport function listenServer(\n http: Http.Server | Https.Server,\n settings: {address: string | number; port: number}\n): Promise<{address: string; port: number}> {\n const {address, port} = settings;\n\n const promise = new Promise((resolve, reject) => {\n http.on(\"listening\", resolve);\n http.on(\"error\", reject);\n }).then(() => {\n const port = (http.address() as any).port;\n\n return {address: settings.address as string, port};\n });\n\n http.listen(port, address as any);\n\n return promise;\n}\n"]}
1
+ {"version":3,"file":"listenServer.js","sourceRoot":"","sources":["../../../src/utils/listenServer.ts"],"names":[],"mappings":";;;AAMA,SAAgB,YAAY,CAC1B,QAAyB,EACzB,MAAsD,EACtD,QAAgD;IAEhD,MAAM,EAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAC,GAAG,QAAQ,CAAC;IAC3C,MAAM,GAAG,GAAG,GAAG,QAAQ,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;IAC/C,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;IAEhD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC9C,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAChC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACX,MAAM,IAAI,GAAI,MAAM,CAAC,OAAO,EAAU,CAAC,IAAI,CAAC;QAC5C,MAAM,IAAI,GAAG,EAAC,GAAG,QAAQ,EAAE,IAAI,EAAC,CAAC;QAEjC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAE5D,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAc,CAAC,CAAC;IAEpC,OAAO,OAAO,CAAC;AACjB,CAAC;AAxBD,oCAwBC","sourcesContent":["import type Http from \"http\";\nimport type Https from \"https\";\nimport type Http2 from \"http2\";\nimport {InjectorService} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\n\nexport function listenServer(\n injector: InjectorService,\n server: Http.Server | Https.Server | Http2.Http2Server,\n hostInfo: ReturnType<typeof getHostInfoFromPort>\n): Promise<ReturnType<typeof getHostInfoFromPort>> {\n const {protocol, address, port} = hostInfo;\n const url = `${protocol}://${address}:${port}`;\n injector.logger.debug(`Start server on ${url}`);\n\n const promise = new Promise((resolve, reject) => {\n server.on(\"listening\", resolve);\n server.on(\"error\", reject);\n }).then(() => {\n const port = (server.address() as any).port;\n const info = {...hostInfo, port};\n\n injector.logger.info(`Listen server on ${info.toString()}`);\n\n return info;\n });\n\n server.listen(port, address as any);\n\n return promise;\n}\n"]}