@tsed/di 7.0.0-beta.8 → 7.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/coverage.json +6 -0
  2. package/jest.config.js +9 -0
  3. package/lib/cjs/decorators/controller.js.map +1 -1
  4. package/lib/cjs/decorators/inject.js +7 -3
  5. package/lib/cjs/decorators/inject.js.map +1 -1
  6. package/lib/cjs/domain/Container.js +1 -2
  7. package/lib/cjs/domain/Container.js.map +1 -1
  8. package/lib/cjs/domain/ContextLogger.js +41 -30
  9. package/lib/cjs/domain/ContextLogger.js.map +1 -1
  10. package/lib/cjs/domain/ControllerProvider.js +37 -0
  11. package/lib/cjs/domain/ControllerProvider.js.map +1 -0
  12. package/lib/cjs/domain/DIContext.js +86 -30
  13. package/lib/cjs/domain/DIContext.js.map +1 -1
  14. package/lib/cjs/domain/LocalsContainer.js +3 -46
  15. package/lib/cjs/domain/LocalsContainer.js.map +1 -1
  16. package/lib/cjs/domain/Provider.js +20 -1
  17. package/lib/cjs/domain/Provider.js.map +1 -1
  18. package/lib/cjs/errors/InjectionError.js +3 -2
  19. package/lib/cjs/errors/InjectionError.js.map +1 -1
  20. package/lib/cjs/errors/InvalidPropertyTokenError.js +12 -0
  21. package/lib/cjs/errors/InvalidPropertyTokenError.js.map +1 -0
  22. package/lib/cjs/errors/UndefinedTokenError.js +1 -1
  23. package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
  24. package/lib/cjs/index.js +9 -1
  25. package/lib/cjs/index.js.map +1 -1
  26. package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
  27. package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
  28. package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
  29. package/lib/cjs/interfaces/DILoggerOptions.js +3 -0
  30. package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
  31. package/lib/cjs/interfaces/InjectableProperties.js.map +1 -1
  32. package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -1
  33. package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
  34. package/lib/cjs/interfaces/TokenRoute.js +3 -0
  35. package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
  36. package/lib/cjs/registries/GlobalProviders.js +7 -12
  37. package/lib/cjs/registries/GlobalProviders.js.map +1 -1
  38. package/lib/cjs/registries/ProviderRegistry.js +1 -1
  39. package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
  40. package/lib/cjs/services/DIConfiguration.js +56 -43
  41. package/lib/cjs/services/DIConfiguration.js.map +1 -1
  42. package/lib/cjs/services/DITest.js +5 -6
  43. package/lib/cjs/services/DITest.js.map +1 -1
  44. package/lib/cjs/services/InjectorService.js +94 -92
  45. package/lib/cjs/services/InjectorService.js.map +1 -1
  46. package/lib/cjs/utils/asyncHookContext.js +42 -0
  47. package/lib/cjs/utils/asyncHookContext.js.map +1 -0
  48. package/lib/cjs/utils/getConfiguration.js +13 -10
  49. package/lib/cjs/utils/getConfiguration.js.map +1 -1
  50. package/lib/cjs/utils/resolveControllers.js +47 -0
  51. package/lib/cjs/utils/resolveControllers.js.map +1 -0
  52. package/lib/cjs/utils/setLoggerConfiguration.js +11 -0
  53. package/lib/cjs/utils/setLoggerConfiguration.js.map +1 -0
  54. package/lib/cjs/utils/setLoggerFormat.js +33 -0
  55. package/lib/cjs/utils/setLoggerFormat.js.map +1 -0
  56. package/lib/cjs/utils/setLoggerLevel.js +1 -2
  57. package/lib/cjs/utils/setLoggerLevel.js.map +1 -1
  58. package/lib/esm/decorators/controller.js.map +1 -1
  59. package/lib/esm/decorators/inject.js +6 -2
  60. package/lib/esm/decorators/inject.js.map +1 -1
  61. package/lib/esm/domain/Container.js +1 -2
  62. package/lib/esm/domain/Container.js.map +1 -1
  63. package/lib/esm/domain/ContextLogger.js +41 -30
  64. package/lib/esm/domain/ContextLogger.js.map +1 -1
  65. package/lib/esm/domain/ControllerProvider.js +33 -0
  66. package/lib/esm/domain/ControllerProvider.js.map +1 -0
  67. package/lib/esm/domain/DIContext.js +86 -30
  68. package/lib/esm/domain/DIContext.js.map +1 -1
  69. package/lib/esm/domain/LocalsContainer.js +3 -46
  70. package/lib/esm/domain/LocalsContainer.js.map +1 -1
  71. package/lib/esm/domain/Provider.js +21 -2
  72. package/lib/esm/domain/Provider.js.map +1 -1
  73. package/lib/esm/errors/InjectionError.js +3 -2
  74. package/lib/esm/errors/InjectionError.js.map +1 -1
  75. package/lib/esm/errors/InvalidPropertyTokenError.js +8 -0
  76. package/lib/esm/errors/InvalidPropertyTokenError.js.map +1 -0
  77. package/lib/esm/errors/UndefinedTokenError.js +1 -1
  78. package/lib/esm/errors/UndefinedTokenError.js.map +1 -1
  79. package/lib/esm/index.js +9 -1
  80. package/lib/esm/index.js.map +1 -1
  81. package/lib/esm/interfaces/AlterRunInContext.js +2 -0
  82. package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
  83. package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
  84. package/lib/esm/interfaces/DILoggerOptions.js +2 -0
  85. package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
  86. package/lib/esm/interfaces/InjectableProperties.js.map +1 -1
  87. package/lib/esm/interfaces/InterceptorMethods.js.map +1 -1
  88. package/lib/esm/interfaces/TokenProvider.js.map +1 -1
  89. package/lib/esm/interfaces/TokenRoute.js +2 -0
  90. package/lib/esm/interfaces/TokenRoute.js.map +1 -0
  91. package/lib/esm/registries/GlobalProviders.js +7 -12
  92. package/lib/esm/registries/GlobalProviders.js.map +1 -1
  93. package/lib/esm/registries/ProviderRegistry.js +1 -1
  94. package/lib/esm/registries/ProviderRegistry.js.map +1 -1
  95. package/lib/esm/services/DIConfiguration.js +57 -44
  96. package/lib/esm/services/DIConfiguration.js.map +1 -1
  97. package/lib/esm/services/DITest.js +5 -6
  98. package/lib/esm/services/DITest.js.map +1 -1
  99. package/lib/esm/services/InjectorService.js +96 -94
  100. package/lib/esm/services/InjectorService.js.map +1 -1
  101. package/lib/esm/utils/asyncHookContext.js +33 -0
  102. package/lib/esm/utils/asyncHookContext.js.map +1 -0
  103. package/lib/esm/utils/getConfiguration.js +12 -10
  104. package/lib/esm/utils/getConfiguration.js.map +1 -1
  105. package/lib/esm/utils/resolveControllers.js +42 -0
  106. package/lib/esm/utils/resolveControllers.js.map +1 -0
  107. package/lib/esm/utils/setLoggerConfiguration.js +7 -0
  108. package/lib/esm/utils/setLoggerConfiguration.js.map +1 -0
  109. package/lib/esm/utils/setLoggerFormat.js +29 -0
  110. package/lib/esm/utils/setLoggerFormat.js.map +1 -0
  111. package/lib/esm/utils/setLoggerLevel.js +1 -2
  112. package/lib/esm/utils/setLoggerLevel.js.map +1 -1
  113. package/lib/types/decorators/controller.d.ts +0 -1
  114. package/lib/types/domain/ContextLogger.d.ts +13 -18
  115. package/lib/types/domain/ControllerProvider.d.ts +17 -0
  116. package/lib/types/domain/DIContext.d.ts +23 -29
  117. package/lib/types/domain/LocalsContainer.d.ts +3 -22
  118. package/lib/types/domain/Provider.d.ts +2 -1
  119. package/lib/types/errors/InvalidPropertyTokenError.d.ts +4 -0
  120. package/lib/types/index.d.ts +9 -1
  121. package/lib/types/interfaces/AlterRunInContext.d.ts +3 -0
  122. package/lib/types/interfaces/DIConfigurationOptions.d.ts +5 -2
  123. package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
  124. package/lib/types/interfaces/InjectableProperties.d.ts +2 -1
  125. package/lib/types/interfaces/InterceptorMethods.d.ts +1 -1
  126. package/lib/types/interfaces/TokenProvider.d.ts +1 -1
  127. package/lib/types/interfaces/TokenRoute.d.ts +5 -0
  128. package/lib/types/registries/GlobalProviders.d.ts +6 -5
  129. package/lib/types/registries/ProviderRegistry.d.ts +2 -1
  130. package/lib/types/services/DIConfiguration.d.ts +19 -11
  131. package/lib/types/services/InjectorService.d.ts +20 -28
  132. package/lib/types/utils/asyncHookContext.d.ts +14 -0
  133. package/lib/types/utils/getConfiguration.d.ts +1 -0
  134. package/lib/types/utils/resolveControllers.d.ts +12 -0
  135. package/lib/types/utils/setLoggerConfiguration.d.ts +2 -0
  136. package/lib/types/utils/setLoggerFormat.d.ts +6 -0
  137. package/lib/types/utils/setLoggerLevel.d.ts +1 -1
  138. package/package.json +15 -11
  139. package/readme.md +3 -2
  140. package/lib/cjs/utils/runInContext.js +0 -20
  141. package/lib/cjs/utils/runInContext.js.map +0 -1
  142. package/lib/esm/utils/runInContext.js +0 -14
  143. package/lib/esm/utils/runInContext.js.map +0 -1
  144. package/lib/types/utils/runInContext.d.ts +0 -6
@@ -0,0 +1,42 @@
1
+ import { isArray, isClass } from "@tsed/core";
2
+ import { GlobalProviders } from "../registries/GlobalProviders.js";
3
+ import { ProviderType } from "../domain/ProviderType.js";
4
+ const lookupProperties = ["mount", "imports"];
5
+ export function getTokens(config) {
6
+ if (!config) {
7
+ return [];
8
+ }
9
+ if (isArray(config)) {
10
+ return config.filter(isClass).map((value) => {
11
+ return { token: value };
12
+ });
13
+ }
14
+ return Object.keys(config).reduce((list, route) => {
15
+ return [
16
+ ...list,
17
+ ...[]
18
+ .concat(config[route])
19
+ .filter(isClass)
20
+ .map((token) => ({
21
+ route,
22
+ token
23
+ }))
24
+ ];
25
+ }, []);
26
+ }
27
+ function resolveRecursively(providers) {
28
+ return providers
29
+ .map(({ token }) => GlobalProviders.get(token))
30
+ .filter((provider) => provider?.type === ProviderType.MODULE && provider.configuration)
31
+ .flatMap((provider) => resolveControllers(provider.configuration));
32
+ }
33
+ /**
34
+ * Return controllers and is base route according to his configuration in module configuration.
35
+ *
36
+ * @param settings
37
+ */
38
+ export function resolveControllers(settings) {
39
+ const providers = lookupProperties.flatMap((property) => getTokens(settings[property]));
40
+ return [...resolveRecursively(providers), ...providers].filter((provider) => !!provider.route);
41
+ }
42
+ //# sourceMappingURL=resolveControllers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveControllers.js","sourceRoot":"","sources":["../../../src/utils/resolveControllers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAIpD,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAE9C,MAAM,UAAU,SAAS,CAAC,MAAW;IACnC,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE;QACnB,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE;YAC/C,OAAO,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC;QACxB,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,IAAW,EAAE,KAAa,EAAE,EAAE;QAC/D,OAAO;YACL,GAAG,IAAI;YACP,GAAG,EAAE;iBACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBACrB,MAAM,CAAC,OAAO,CAAC;iBACf,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACf,KAAK;gBACL,KAAK;aACN,CAAC,CAAC;SACN,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,SAAS,kBAAkB,CAAC,SAAmD;IAC7E,OAAO,SAAS;SACb,GAAG,CAAC,CAAC,EAAC,KAAK,EAAC,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC5C,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,IAAI,KAAK,YAAY,CAAC,MAAM,IAAI,QAAQ,CAAC,aAAa,CAAC;SACtF,OAAO,CAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;AACjF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAqC;IACtE,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,GAAG,kBAAkB,CAAC,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAU,CAAC;AAC1G,CAAC","sourcesContent":["import {isArray, isClass} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {Provider} from \"../domain/Provider\";\nimport {TokenRoute} from \"../interfaces/TokenRoute\";\n\nconst lookupProperties = [\"mount\", \"imports\"];\n\nexport function getTokens(config: any): {route?: string; token: TokenProvider}[] {\n if (!config) {\n return [];\n }\n\n if (isArray(config)) {\n return config.filter(isClass).map((value: any) => {\n return {token: value};\n });\n }\n\n return Object.keys(config).reduce((list: any[], route: string) => {\n return [\n ...list,\n ...[]\n .concat(config[route])\n .filter(isClass)\n .map((token) => ({\n route,\n token\n }))\n ];\n }, []);\n}\n\nfunction resolveRecursively(providers: {token: TokenProvider; route?: string}[]) {\n return providers\n .map(({token}) => GlobalProviders.get(token))\n .filter((provider) => provider?.type === ProviderType.MODULE && provider.configuration)\n .flatMap((provider: Provider) => resolveControllers(provider.configuration));\n}\n\n/**\n * Return controllers and is base route according to his configuration in module configuration.\n *\n * @param settings\n */\nexport function resolveControllers(settings: Partial<TsED.Configuration>): TokenRoute[] {\n const providers = lookupProperties.flatMap((property) => getTokens(settings[property]));\n\n return [...resolveRecursively(providers), ...providers].filter((provider) => !!provider.route) as any[];\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import { setLoggerFormat } from "./setLoggerFormat.js";
2
+ import { setLoggerLevel } from "./setLoggerLevel.js";
3
+ export function setLoggerConfiguration(injector) {
4
+ setLoggerLevel(injector);
5
+ setLoggerFormat(injector);
6
+ }
7
+ //# sourceMappingURL=setLoggerConfiguration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setLoggerConfiguration.js","sourceRoot":"","sources":["../../../src/utils/setLoggerConfiguration.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,MAAM,UAAU,sBAAsB,CAAC,QAAyB;IAC9D,cAAc,CAAC,QAAQ,CAAC,CAAC;IACzB,eAAe,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type {InjectorService} from \"../services/InjectorService\";\nimport {setLoggerFormat} from \"./setLoggerFormat\";\nimport {setLoggerLevel} from \"./setLoggerLevel\";\n\nexport function setLoggerConfiguration(injector: InjectorService) {\n setLoggerLevel(injector);\n setLoggerFormat(injector);\n}\n"]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @ignore
3
+ * @param injector
4
+ */
5
+ export function setLoggerFormat(injector) {
6
+ const { level, format } = injector.settings.logger;
7
+ if (level) {
8
+ injector.logger.level = level;
9
+ }
10
+ if (format && injector.logger.appenders) {
11
+ injector.logger.appenders.set("stdout", {
12
+ type: "stdout",
13
+ levels: ["info", "debug"],
14
+ layout: {
15
+ type: "pattern",
16
+ pattern: format
17
+ }
18
+ });
19
+ injector.logger.appenders.set("stderr", {
20
+ levels: ["trace", "fatal", "error", "warn"],
21
+ type: "stderr",
22
+ layout: {
23
+ type: "pattern",
24
+ pattern: format
25
+ }
26
+ });
27
+ }
28
+ }
29
+ //# sourceMappingURL=setLoggerFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setLoggerFormat.js","sourceRoot":"","sources":["../../../src/utils/setLoggerFormat.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,QAAyB;IACvD,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;IAEjD,IAAI,KAAK,EAAE;QACT,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/B;IAED,IAAI,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE;QACvC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YACzB,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,MAAM;aAChB;SACF,CAAC,CAAC;QAEH,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE;YACtC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC;YAC3C,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,MAAM;aAChB;SACF,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["import type {InjectorService} from \"../services/InjectorService\";\n\n/**\n * @ignore\n * @param injector\n */\nexport function setLoggerFormat(injector: InjectorService) {\n const {level, format} = injector.settings.logger;\n\n if (level) {\n injector.logger.level = level;\n }\n\n if (format && injector.logger.appenders) {\n injector.logger.appenders.set(\"stdout\", {\n type: \"stdout\",\n levels: [\"info\", \"debug\"],\n layout: {\n type: \"pattern\",\n pattern: format\n }\n });\n\n injector.logger.appenders.set(\"stderr\", {\n levels: [\"trace\", \"fatal\", \"error\", \"warn\"],\n type: \"stderr\",\n layout: {\n type: \"pattern\",\n pattern: format\n }\n });\n }\n}\n"]}
@@ -3,8 +3,7 @@
3
3
  * @param injector
4
4
  */
5
5
  export function setLoggerLevel(injector) {
6
- var _a;
7
- const level = (_a = injector.settings.logger) === null || _a === void 0 ? void 0 : _a.level;
6
+ const { level } = injector.settings.logger;
8
7
  if (level) {
9
8
  injector.logger.level = level;
10
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setLoggerLevel.js","sourceRoot":"","sources":["../../../src/utils/setLoggerLevel.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAyB;;IACtD,MAAM,KAAK,GAAG,MAAA,QAAQ,CAAC,QAAQ,CAAC,MAAM,0CAAE,KAAK,CAAC;IAE9C,IAAI,KAAK,EAAE;QACT,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/B;AACH,CAAC","sourcesContent":["import {InjectorService} from \"../services/InjectorService\";\n\n/**\n * @ignore\n * @param injector\n */\nexport function setLoggerLevel(injector: InjectorService) {\n const level = injector.settings.logger?.level;\n\n if (level) {\n injector.logger.level = level;\n }\n}\n"]}
1
+ {"version":3,"file":"setLoggerLevel.js","sourceRoot":"","sources":["../../../src/utils/setLoggerLevel.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAyB;IACtD,MAAM,EAAC,KAAK,EAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;IAEzC,IAAI,KAAK,EAAE;QACT,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/B;AACH,CAAC","sourcesContent":["import type {InjectorService} from \"../services/InjectorService\";\n\n/**\n * @ignore\n * @param injector\n */\nexport function setLoggerLevel(injector: InjectorService) {\n const {level} = injector.settings.logger;\n\n if (level) {\n injector.logger.level = level;\n }\n}\n"]}
@@ -9,7 +9,6 @@ export interface ControllerMiddlewares {
9
9
  export interface ControllerOptions extends Partial<ProviderOpts<any>> {
10
10
  path?: PathType;
11
11
  children?: Type<any>[];
12
- routerOptions?: any;
13
12
  middlewares?: Partial<ControllerMiddlewares>;
14
13
  }
15
14
  /**
@@ -1,28 +1,24 @@
1
+ import { Hooks } from "@tsed/core";
1
2
  import { LogLevel } from "@tsed/logger";
3
+ import { DILogger } from "../interfaces/DILogger";
2
4
  export interface ContextLoggerOptions extends Record<string, any> {
3
5
  id: string;
4
- url?: string;
5
- dateStart?: Date;
6
+ logger?: DILogger;
6
7
  level?: "debug" | "info" | "warn" | "error" | "off" | "all";
7
8
  maxStackSize?: number;
8
- minimalRequestPicker?: (o: any) => any;
9
- completeRequestPicker?: (o: any) => any;
10
- ignoreLog?: (data: any) => boolean;
11
9
  additionalProps?: Record<any, any>;
12
10
  }
13
11
  export declare class ContextLogger {
14
- private logger;
15
- id: string;
16
- url: string;
17
- minimalRequestPicker: Function;
18
- completeRequestPicker: Function;
12
+ #private;
13
+ readonly dateStart: Date;
14
+ readonly id: string;
19
15
  maxStackSize: number;
20
- private readonly additionalProps;
21
- private readonly dateStart;
22
- private readonly ignoreLog;
23
- private stack;
24
- private level;
25
- constructor(logger: any, { id, url, dateStart, ignoreUrlPatterns, minimalRequestPicker, completeRequestPicker, level, maxStackSize, ignoreLog, additionalProps }: ContextLoggerOptions);
16
+ level: LogLevel;
17
+ constructor({ id, logger, dateStart, level, maxStackSize, additionalProps }: ContextLoggerOptions);
18
+ get hooks(): Hooks;
19
+ private get stack();
20
+ alterLog(cb: (data: any, level: "debug" | "info" | "warn" | "error" | "off" | "all", withRequest: boolean) => any): Hooks;
21
+ alterIgnoreLog(cb: (ignore: boolean, data: any) => boolean): Hooks;
26
22
  info(obj: any): this;
27
23
  debug(obj: any, withRequest?: boolean): this;
28
24
  warn(obj: any): this;
@@ -30,12 +26,11 @@ export declare class ContextLogger {
30
26
  trace(obj: any): this;
31
27
  flush(): void;
32
28
  isLevelEnabled(otherLevel: string | LogLevel): boolean;
33
- destroy(): void;
34
29
  /**
35
30
  * Return the duration between the time when LogIncomingRequest has handle the request and now.
36
31
  * @returns {number}
37
32
  */
38
33
  protected getDuration(): number;
39
34
  protected getData(obj: any): any;
40
- protected run(level: LogLevel, obj: any, mapper: (data: any) => any): void;
35
+ protected run(level: LogLevel, obj: any, withRequest?: boolean): void;
41
36
  }
@@ -0,0 +1,17 @@
1
+ import { ControllerMiddlewares } from "../decorators/controller";
2
+ import { TokenProvider } from "../interfaces/TokenProvider";
3
+ import { Provider } from "./Provider";
4
+ export declare class ControllerProvider<T = any> extends Provider<T> {
5
+ tokenRouter: string;
6
+ constructor(provide: TokenProvider, options?: Partial<Provider>);
7
+ /**
8
+ *
9
+ * @returns {any[]}
10
+ */
11
+ get middlewares(): ControllerMiddlewares;
12
+ /**
13
+ *
14
+ * @param middlewares
15
+ */
16
+ set middlewares(middlewares: ControllerMiddlewares);
17
+ }
@@ -1,22 +1,20 @@
1
- import type { Env } from "@tsed/core";
2
1
  import { InjectorService } from "../services/InjectorService";
3
2
  import { ContextLogger, ContextLoggerOptions } from "./ContextLogger";
4
3
  import { LocalsContainer } from "./LocalsContainer";
5
- export interface ContextMethods extends Map<any, any> {
6
- readonly id: string;
7
- readonly logger: ContextLogger;
8
- readonly injector: InjectorService;
9
- readonly container: LocalsContainer;
10
- readonly env: Env;
11
- destroy(): any;
12
- }
13
4
  export interface DIContextOptions extends Omit<ContextLoggerOptions, "dateStart"> {
14
5
  id: string;
6
+ injector: InjectorService;
15
7
  logger: any;
16
- injector?: InjectorService;
17
8
  }
18
- export declare class DIContext extends Map<any, any> implements ContextMethods {
9
+ export declare class DIContext {
10
+ #private;
11
+ opts: DIContextOptions;
19
12
  [x: string]: any;
13
+ constructor(opts: DIContextOptions);
14
+ /**
15
+ * Logger attached to the context request.
16
+ */
17
+ get logger(): ContextLogger;
20
18
  /**
21
19
  * Request id generated by @@contextMiddleware@@.
22
20
  *
@@ -41,26 +39,22 @@ export declare class DIContext extends Map<any, any> implements ContextMethods {
41
39
  * :::
42
40
  *
43
41
  */
44
- readonly id: string;
45
- /**
46
- * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.
47
- */
48
- readonly dateStart: Date;
49
- /**
50
- * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
51
- */
52
- container: LocalsContainer<any>;
53
- /**
54
- * Logger attached to the context request.
55
- */
56
- logger: ContextLogger;
42
+ get id(): string;
43
+ get dateStart(): Date;
44
+ get injector(): InjectorService;
45
+ get env(): any;
57
46
  /**
58
- *
47
+ * The request container used by the Ts.ED DI. It contains all services annotated with `@Scope(ProviderScope.REQUEST)`
59
48
  */
60
- injector: InjectorService;
61
- constructor({ id, injector, logger, ignoreLog, ...options }: DIContextOptions);
62
- get env(): any;
63
- destroy(): Promise<void>;
49
+ get container(): LocalsContainer;
50
+ destroy(): Promise<any>;
64
51
  emit(eventName: string, ...args: any[]): Promise<void>;
52
+ runInContext(next: Function): Promise<any>;
53
+ cache<Value = any>(key: string, cb: () => Value): Value;
54
+ cacheAsync<Value = any>(key: string, cb: () => Promise<Value>): Promise<Value>;
55
+ delete(key: any): boolean;
56
+ get<T = any>(key: any): T;
57
+ has(key: any): boolean;
58
+ set(key: any, value: any): this;
65
59
  }
66
60
  export declare type BaseContext = DIContext & TsED.Context;
@@ -1,25 +1,6 @@
1
+ import { Hooks } from "@tsed/core";
1
2
  import type { TokenProvider } from "../interfaces/TokenProvider";
2
- export declare class LocalsContainer<V = any> extends Map<TokenProvider, V> {
3
- /**
4
- * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
5
- * @param eventName The event name to emit at all services.
6
- * @param args List of the parameters to give to each services.
7
- * @returns {Promise<any[]>} A list of promises.
8
- */
9
- emit(eventName: string, ...args: any[]): Promise<void>;
10
- /**
11
- * @param eventName
12
- * @param value
13
- * @param args
14
- */
15
- alter<T = any>(eventName: string, value: any, ...args: any[]): T;
16
- /**
17
- * @param eventName
18
- * @param value
19
- * @param args
20
- */
21
- alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T>;
22
- toArray(): V[];
3
+ export declare class LocalsContainer extends Map<TokenProvider, any> {
4
+ readonly hooks: Hooks;
23
5
  destroy(): Promise<void>;
24
- protected getListeners(event: string): any[];
25
6
  }
@@ -3,6 +3,7 @@ import { ProviderOpts } from "../interfaces/ProviderOpts";
3
3
  import { TokenProvider } from "../interfaces/TokenProvider";
4
4
  import { ProviderScope } from "./ProviderScope";
5
5
  import { ProviderType } from "./ProviderType";
6
+ export declare type ProviderHookCallback<T = any> = (instance: T, ...args: any[]) => Promise<void> | void;
6
7
  export declare class Provider<T = any> implements ProviderOpts<T> {
7
8
  type: ProviderType | any;
8
9
  deps: TokenProvider[];
@@ -10,7 +11,7 @@ export declare class Provider<T = any> implements ProviderOpts<T> {
10
11
  useFactory: Function;
11
12
  useAsyncFactory: Function;
12
13
  useValue: any;
13
- hooks?: Record<string, (instance: T, ...args: any[]) => Promise<void> | void>;
14
+ hooks?: Record<string, ProviderHookCallback<T>>;
14
15
  private _useClass;
15
16
  private _provide;
16
17
  private _store;
@@ -0,0 +1,4 @@
1
+ export declare class InvalidPropertyTokenError extends Error {
2
+ name: string;
3
+ constructor(target: any, propertyKey: string);
4
+ }
@@ -19,6 +19,7 @@ export * from "./decorators/useOpts";
19
19
  export * from "./decorators/value";
20
20
  export * from "./domain/Container";
21
21
  export * from "./domain/ContextLogger";
22
+ export * from "./domain/ControllerProvider";
22
23
  export * from "./domain/DIContext";
23
24
  export * from "./domain/InjectablePropertyType";
24
25
  export * from "./domain/LocalsContainer";
@@ -26,9 +27,12 @@ export * from "./domain/Provider";
26
27
  export * from "./domain/ProviderScope";
27
28
  export * from "./domain/ProviderType";
28
29
  export * from "./errors/InjectionError";
30
+ export * from "./errors/InvalidPropertyTokenError";
29
31
  export * from "./errors/UndefinedTokenError";
32
+ export * from "./interfaces/AlterRunInContext";
30
33
  export * from "./interfaces/DIConfigurationOptions";
31
34
  export * from "./interfaces/DILogger";
35
+ export * from "./interfaces/DILoggerOptions";
32
36
  export * from "./interfaces/DIResolver";
33
37
  export * from "./interfaces/InjectableProperties";
34
38
  export * from "./interfaces/InterceptorContext";
@@ -40,14 +44,18 @@ export * from "./interfaces/ProviderOpts";
40
44
  export * from "./interfaces/RegistrySettings";
41
45
  export * from "./interfaces/ResolvedInvokeOptions";
42
46
  export * from "./interfaces/TokenProvider";
47
+ export * from "./interfaces/TokenRoute";
43
48
  export * from "./registries/GlobalProviders";
44
49
  export * from "./registries/ProviderRegistry";
45
50
  export * from "./services/DIConfiguration";
46
51
  export * from "./services/DILogger";
47
52
  export * from "./services/DITest";
48
53
  export * from "./services/InjectorService";
54
+ export * from "./utils/asyncHookContext";
49
55
  export * from "./utils/colors";
50
56
  export * from "./utils/createContainer";
51
57
  export * from "./utils/getConfiguration";
52
- export * from "./utils/runInContext";
58
+ export * from "./utils/resolveControllers";
59
+ export * from "./utils/setLoggerConfiguration";
60
+ export * from "./utils/setLoggerFormat";
53
61
  export * from "./utils/setLoggerLevel";
@@ -0,0 +1,3 @@
1
+ export interface AlterRunInContext {
2
+ $alterRunInContext(next: (...args: unknown[]) => unknown): () => unknown | Promise<() => unknown>;
3
+ }
@@ -5,7 +5,7 @@ declare global {
5
5
  namespace TsED {
6
6
  interface Context {
7
7
  }
8
- interface Configuration {
8
+ interface Configuration extends Record<string, any> {
9
9
  scopes: {
10
10
  [key: string]: ProviderScope;
11
11
  };
@@ -17,7 +17,10 @@ declare global {
17
17
  * Define dependencies to build the provider
18
18
  */
19
19
  imports: TokenProvider[];
20
- [key: string]: any;
20
+ /**
21
+ * Mount controllers
22
+ */
23
+ mount: Record<string, TokenProvider[]>;
21
24
  }
22
25
  }
23
26
  }
@@ -0,0 +1,44 @@
1
+ export interface DILoggerOptions {
2
+ /**
3
+ * Enable debug mode. By default debug is false.
4
+ */
5
+ debug?: boolean;
6
+ /**
7
+ * Enable info mode. By default debug is false.
8
+ */
9
+ level?: "debug" | "info" | "warn" | "error" | "off";
10
+ /**
11
+ * Enable log performance tracker and disable log server.
12
+ */
13
+ perf?: boolean;
14
+ /**
15
+ * List of regexp to ignore log.
16
+ */
17
+ ignoreUrlPatterns?: (string | RegExp)[];
18
+ /**
19
+ * The number of space characters to use as white space in JSON output. Default is 2 (0 in production).
20
+ */
21
+ jsonIndentation?: number;
22
+ /**
23
+ * A function called for each incoming request to create a request id.
24
+ * @returns {number}
25
+ */
26
+ reqIdBuilder?: (req: any) => string;
27
+ /**
28
+ * Disable routes table displayed in the logger. By default debug is `false`.
29
+ */
30
+ disableRoutesSummary?: boolean;
31
+ /**
32
+ * Disable bootstrap log displayed in the logger. By default debug is `false`.
33
+ */
34
+ disableBootstrapLog?: boolean;
35
+ /**
36
+ * Specify log format. Example: `%[%d{[yyyy-MM-dd hh:mm:ss,SSS}] %p%] %m`. See [@tsed/logger configuration](https://tsedio.github.io/logger/).
37
+ */
38
+ format?: string;
39
+ /**
40
+ * Specify the log stack size for the context.logger. When the stack.length is reach, the logger is flushed during the request.
41
+ * Default size is set to 30.
42
+ */
43
+ maxStackSize?: number;
44
+ }
@@ -1,4 +1,5 @@
1
1
  import type { InjectablePropertyType } from "../domain/InjectablePropertyType";
2
+ import type { LocalsContainer } from "../domain/LocalsContainer";
2
3
  import type { TokenProvider } from "./TokenProvider";
3
4
  import type { InjectorService } from "../services/InjectorService";
4
5
  import type { InvokeOptions } from "./InvokeOptions";
@@ -9,7 +10,7 @@ export interface InjectablePropertyOptions extends InjectableProperty {
9
10
  bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;
10
11
  propertyType: string;
11
12
  useType?: TokenProvider;
12
- resolver: (injector: InjectorService, locals: Map<TokenProvider, any>, options: Partial<InvokeOptions> & {
13
+ resolver: (injector: InjectorService, locals: LocalsContainer, options: Partial<InvokeOptions> & {
13
14
  options: any;
14
15
  }) => () => any;
15
16
  options?: any;
@@ -1,4 +1,4 @@
1
1
  import type { InterceptorContext, InterceptorNext } from "./InterceptorContext";
2
2
  export interface InterceptorMethods {
3
- intercept?(context: InterceptorContext, next?: InterceptorNext): any;
3
+ intercept(context: InterceptorContext, next?: InterceptorNext): any;
4
4
  }
@@ -1,2 +1,2 @@
1
1
  import type { Type } from "@tsed/core";
2
- export declare type TokenProvider = string | symbol | Type | Function | any;
2
+ export declare type TokenProvider<T = any> = string | symbol | Type<T> | Function | any;
@@ -0,0 +1,5 @@
1
+ import { TokenProvider } from "./TokenProvider";
2
+ export interface TokenRoute {
3
+ token: TokenProvider;
4
+ route: string;
5
+ }
@@ -1,10 +1,11 @@
1
1
  import { Type } from "@tsed/core";
2
+ import type { LocalsContainer } from "../domain/LocalsContainer";
2
3
  import { Provider } from "../domain/Provider";
3
- import type { InjectorService } from "../services/InjectorService";
4
+ import { ProviderOpts } from "../interfaces/ProviderOpts";
5
+ import { RegistrySettings } from "../interfaces/RegistrySettings";
4
6
  import { ResolvedInvokeOptions } from "../interfaces/ResolvedInvokeOptions";
5
7
  import { TokenProvider } from "../interfaces/TokenProvider";
6
- import { RegistrySettings } from "../interfaces/RegistrySettings";
7
- import { ProviderOpts } from "../interfaces/ProviderOpts";
8
+ import type { InjectorService } from "../services/InjectorService";
8
9
  export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider> {
9
10
  #private;
10
11
  /**
@@ -30,7 +31,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
30
31
  * @param target
31
32
  * @param options
32
33
  */
33
- merge(target: TokenProvider, options: Partial<ProviderOpts>): void;
34
+ merge(target: TokenProvider, options: Partial<ProviderOpts>): Provider<any>;
34
35
  /**
35
36
  * The delete() method removes the specified element from a Map object.
36
37
  * @param key Required. The key of the element to remove from the Map object.
@@ -38,7 +39,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
38
39
  */
39
40
  delete(key: TokenProvider): boolean;
40
41
  createRegistry(type: string, model: Type<Provider>, options?: Partial<RegistrySettings>): this;
41
- onInvoke(provider: Provider, locals: Map<TokenProvider, any>, options: ResolvedInvokeOptions & {
42
+ onInvoke(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {
42
43
  injector: InjectorService;
43
44
  }): void;
44
45
  getRegistrySettings(target: string | TokenProvider): RegistrySettings;
@@ -1,9 +1,10 @@
1
+ import { Provider } from "../domain/Provider";
1
2
  import type { ProviderOpts } from "../interfaces/ProviderOpts";
2
3
  /**
3
4
  * Register a provider configuration.
4
5
  * @param {ProviderOpts<any>} provider
5
6
  */
6
- export declare function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>): void;
7
+ export declare function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>): Provider<any>;
7
8
  /**
8
9
  * Add a new value in the `ProviderRegistry`.
9
10
  *
@@ -1,21 +1,31 @@
1
- import { ProviderScope } from "../domain/ProviderScope";
1
+ import { Env } from "@tsed/core";
2
+ import type { ProviderScope } from "../domain/ProviderScope";
3
+ import type { DILoggerOptions } from "../interfaces/DILoggerOptions";
2
4
  import type { DIResolver } from "../interfaces/DIResolver";
3
5
  import type { TokenProvider } from "../interfaces/TokenProvider";
6
+ import type { TokenRoute } from "../interfaces/TokenRoute";
4
7
  export declare class DIConfiguration {
5
8
  readonly default: Map<string, any>;
6
9
  protected map: Map<string, any>;
7
- [key: string]: any;
8
10
  constructor(initialProps?: {});
9
- get scopes(): {
10
- [key: string]: ProviderScope;
11
- };
12
- set scopes(value: {
13
- [key: string]: ProviderScope;
14
- });
11
+ get version(): string;
12
+ set version(v: string);
13
+ get rootDir(): string;
14
+ set rootDir(value: string);
15
+ get env(): Env;
16
+ set env(value: Env);
17
+ get scopes(): Record<string, ProviderScope>;
18
+ set scopes(value: Record<string, ProviderScope>);
15
19
  get resolvers(): DIResolver[];
16
20
  set resolvers(resolvers: DIResolver[]);
17
21
  get imports(): TokenProvider[];
18
22
  set imports(imports: TokenProvider[]);
23
+ get routes(): TokenRoute[];
24
+ set routes(routes: TokenRoute[]);
25
+ get logger(): Partial<DILoggerOptions>;
26
+ set logger(value: Partial<DILoggerOptions>);
27
+ get debug(): boolean;
28
+ set debug(debug: boolean);
19
29
  /**
20
30
  *
21
31
  * @param callbackfn
@@ -36,13 +46,11 @@ export declare class DIConfiguration {
36
46
  * @returns {undefined|any}
37
47
  */
38
48
  get<T = any>(propertyKey: string, defaultValue?: T): T;
39
- getRaw(propertyKey: string, defaultValue?: any): any;
40
- merge(obj: Partial<TsED.Configuration>): void;
49
+ protected getRaw(propertyKey: string, defaultValue?: any): any;
41
50
  /**
42
51
  *
43
52
  * @param value
44
53
  * @returns {any}
45
54
  */
46
55
  resolve(value: any): any;
47
- build(): void;
48
56
  }