@tsed/di 7.0.0-beta.10 → 7.0.0-beta.13

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 (106) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/cjs/domain/Container.js +1 -2
  3. package/lib/cjs/domain/Container.js.map +1 -1
  4. package/lib/cjs/domain/ContextLogger.js +55 -30
  5. package/lib/cjs/domain/ContextLogger.js.map +1 -1
  6. package/lib/cjs/domain/DIContext.js +55 -26
  7. package/lib/cjs/domain/DIContext.js.map +1 -1
  8. package/lib/cjs/domain/Provider.js +11 -1
  9. package/lib/cjs/domain/Provider.js.map +1 -1
  10. package/lib/cjs/errors/InjectionError.js +3 -2
  11. package/lib/cjs/errors/InjectionError.js.map +1 -1
  12. package/lib/cjs/errors/UndefinedTokenError.js +1 -1
  13. package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
  14. package/lib/cjs/index.js +6 -0
  15. package/lib/cjs/index.js.map +1 -1
  16. package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
  17. package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
  18. package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
  19. package/lib/cjs/interfaces/DILoggerOptions.js +3 -0
  20. package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
  21. package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -1
  22. package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
  23. package/lib/cjs/interfaces/TokenRoute.js +3 -0
  24. package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
  25. package/lib/cjs/registries/GlobalProviders.js +6 -12
  26. package/lib/cjs/registries/GlobalProviders.js.map +1 -1
  27. package/lib/cjs/services/DIConfiguration.js +56 -43
  28. package/lib/cjs/services/DIConfiguration.js.map +1 -1
  29. package/lib/cjs/services/DITest.js +4 -5
  30. package/lib/cjs/services/DITest.js.map +1 -1
  31. package/lib/cjs/services/InjectorService.js +76 -76
  32. package/lib/cjs/services/InjectorService.js.map +1 -1
  33. package/lib/cjs/utils/getConfiguration.js +13 -10
  34. package/lib/cjs/utils/getConfiguration.js.map +1 -1
  35. package/lib/cjs/utils/resolveControllers.js +47 -0
  36. package/lib/cjs/utils/resolveControllers.js.map +1 -0
  37. package/lib/cjs/utils/runInContext.js +9 -6
  38. package/lib/cjs/utils/runInContext.js.map +1 -1
  39. package/lib/cjs/utils/setLoggerConfiguration.js +11 -0
  40. package/lib/cjs/utils/setLoggerConfiguration.js.map +1 -0
  41. package/lib/cjs/utils/setLoggerFormat.js +33 -0
  42. package/lib/cjs/utils/setLoggerFormat.js.map +1 -0
  43. package/lib/cjs/utils/setLoggerLevel.js +1 -2
  44. package/lib/cjs/utils/setLoggerLevel.js.map +1 -1
  45. package/lib/esm/domain/Container.js +1 -2
  46. package/lib/esm/domain/Container.js.map +1 -1
  47. package/lib/esm/domain/ContextLogger.js +55 -30
  48. package/lib/esm/domain/ContextLogger.js.map +1 -1
  49. package/lib/esm/domain/DIContext.js +55 -26
  50. package/lib/esm/domain/DIContext.js.map +1 -1
  51. package/lib/esm/domain/Provider.js +11 -1
  52. package/lib/esm/domain/Provider.js.map +1 -1
  53. package/lib/esm/errors/InjectionError.js +3 -2
  54. package/lib/esm/errors/InjectionError.js.map +1 -1
  55. package/lib/esm/errors/UndefinedTokenError.js +1 -1
  56. package/lib/esm/errors/UndefinedTokenError.js.map +1 -1
  57. package/lib/esm/index.js +6 -0
  58. package/lib/esm/index.js.map +1 -1
  59. package/lib/esm/interfaces/AlterRunInContext.js +2 -0
  60. package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
  61. package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
  62. package/lib/esm/interfaces/DILoggerOptions.js +2 -0
  63. package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
  64. package/lib/esm/interfaces/InterceptorMethods.js.map +1 -1
  65. package/lib/esm/interfaces/TokenProvider.js.map +1 -1
  66. package/lib/esm/interfaces/TokenRoute.js +2 -0
  67. package/lib/esm/interfaces/TokenRoute.js.map +1 -0
  68. package/lib/esm/registries/GlobalProviders.js +6 -12
  69. package/lib/esm/registries/GlobalProviders.js.map +1 -1
  70. package/lib/esm/services/DIConfiguration.js +57 -44
  71. package/lib/esm/services/DIConfiguration.js.map +1 -1
  72. package/lib/esm/services/DITest.js +4 -5
  73. package/lib/esm/services/DITest.js.map +1 -1
  74. package/lib/esm/services/InjectorService.js +77 -77
  75. package/lib/esm/services/InjectorService.js.map +1 -1
  76. package/lib/esm/utils/getConfiguration.js +12 -10
  77. package/lib/esm/utils/getConfiguration.js.map +1 -1
  78. package/lib/esm/utils/resolveControllers.js +42 -0
  79. package/lib/esm/utils/resolveControllers.js.map +1 -0
  80. package/lib/esm/utils/runInContext.js +8 -6
  81. package/lib/esm/utils/runInContext.js.map +1 -1
  82. package/lib/esm/utils/setLoggerConfiguration.js +7 -0
  83. package/lib/esm/utils/setLoggerConfiguration.js.map +1 -0
  84. package/lib/esm/utils/setLoggerFormat.js +29 -0
  85. package/lib/esm/utils/setLoggerFormat.js.map +1 -0
  86. package/lib/esm/utils/setLoggerLevel.js +1 -2
  87. package/lib/esm/utils/setLoggerLevel.js.map +1 -1
  88. package/lib/types/domain/ContextLogger.d.ts +15 -18
  89. package/lib/types/domain/DIContext.d.ts +15 -19
  90. package/lib/types/index.d.ts +6 -0
  91. package/lib/types/interfaces/AlterRunInContext.d.ts +4 -0
  92. package/lib/types/interfaces/DIConfigurationOptions.d.ts +5 -2
  93. package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
  94. package/lib/types/interfaces/InterceptorMethods.d.ts +1 -1
  95. package/lib/types/interfaces/TokenProvider.d.ts +1 -1
  96. package/lib/types/interfaces/TokenRoute.d.ts +5 -0
  97. package/lib/types/services/DIConfiguration.d.ts +19 -11
  98. package/lib/types/services/InjectorService.d.ts +16 -17
  99. package/lib/types/utils/getConfiguration.d.ts +1 -0
  100. package/lib/types/utils/resolveControllers.d.ts +12 -0
  101. package/lib/types/utils/runInContext.d.ts +2 -1
  102. package/lib/types/utils/setLoggerConfiguration.d.ts +2 -0
  103. package/lib/types/utils/setLoggerFormat.d.ts +6 -0
  104. package/lib/types/utils/setLoggerLevel.d.ts +1 -1
  105. package/package.json +14 -10
  106. package/readme.md +2 -1
@@ -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"]}
@@ -1,28 +1,25 @@
1
+ import { Hooks } from "@tsed/core";
1
2
  import { LogLevel } from "@tsed/logger";
3
+ import { DILogger } from "../interfaces/DILogger";
4
+ import type { DIContext } from "./DIContext";
2
5
  export interface ContextLoggerOptions extends Record<string, any> {
3
6
  id: string;
4
- url?: string;
5
- dateStart?: Date;
7
+ logger?: DILogger;
6
8
  level?: "debug" | "info" | "warn" | "error" | "off" | "all";
7
9
  maxStackSize?: number;
8
- minimalRequestPicker?: (o: any) => any;
9
- completeRequestPicker?: (o: any) => any;
10
- ignoreLog?: (data: any) => boolean;
11
10
  additionalProps?: Record<any, any>;
12
11
  }
13
12
  export declare class ContextLogger {
14
- private logger;
15
- id: string;
16
- url: string;
17
- minimalRequestPicker: Function;
18
- completeRequestPicker: Function;
19
- 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);
13
+ #private;
14
+ readonly $ctx: DIContext;
15
+ readonly dateStart: Date;
16
+ constructor($ctx: DIContext);
17
+ get id(): any;
18
+ set maxStackSize(maxStackSize: number);
19
+ get hooks(): Hooks;
20
+ private get stack();
21
+ alterLog(cb: (data: any, level: "debug" | "info" | "warn" | "error" | "off" | "all", withRequest: boolean) => any): Hooks;
22
+ alterIgnoreLog(cb: (ignore: boolean, data: any) => boolean): Hooks;
26
23
  info(obj: any): this;
27
24
  debug(obj: any, withRequest?: boolean): this;
28
25
  warn(obj: any): this;
@@ -37,5 +34,5 @@ export declare class ContextLogger {
37
34
  */
38
35
  protected getDuration(): number;
39
36
  protected getData(obj: any): any;
40
- protected run(level: LogLevel, obj: any, mapper: (data: any) => any): void;
37
+ protected run(level: LogLevel, obj: any, withRequest?: boolean): void;
41
38
  }
@@ -12,11 +12,21 @@ export interface ContextMethods extends Map<any, any> {
12
12
  }
13
13
  export interface DIContextOptions extends Omit<ContextLoggerOptions, "dateStart"> {
14
14
  id: string;
15
+ injector: InjectorService;
15
16
  logger: any;
16
- injector?: InjectorService;
17
17
  }
18
18
  export declare class DIContext extends Map<any, any> implements ContextMethods {
19
+ readonly options: DIContextOptions;
19
20
  [x: string]: any;
21
+ /**
22
+ * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
23
+ */
24
+ container: LocalsContainer<any>;
25
+ /**
26
+ * Logger attached to the context request.
27
+ */
28
+ readonly logger: ContextLogger;
29
+ constructor(options: DIContextOptions);
20
30
  /**
21
31
  * Request id generated by @@contextMiddleware@@.
22
32
  *
@@ -41,26 +51,12 @@ export declare class DIContext extends Map<any, any> implements ContextMethods {
41
51
  * :::
42
52
  *
43
53
  */
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;
57
- /**
58
- *
59
- */
60
- injector: InjectorService;
61
- constructor({ id, injector, logger, ignoreLog, ...options }: DIContextOptions);
54
+ get id(): any;
55
+ get dateStart(): Date;
56
+ get injector(): InjectorService;
62
57
  get env(): any;
63
58
  destroy(): Promise<void>;
64
59
  emit(eventName: string, ...args: any[]): Promise<void>;
60
+ runInContext(next: Function): Promise<unknown>;
65
61
  }
66
62
  export declare type BaseContext = DIContext & TsED.Context;
@@ -27,8 +27,10 @@ export * from "./domain/ProviderScope";
27
27
  export * from "./domain/ProviderType";
28
28
  export * from "./errors/InjectionError";
29
29
  export * from "./errors/UndefinedTokenError";
30
+ export * from "./interfaces/AlterRunInContext";
30
31
  export * from "./interfaces/DIConfigurationOptions";
31
32
  export * from "./interfaces/DILogger";
33
+ export * from "./interfaces/DILoggerOptions";
32
34
  export * from "./interfaces/DIResolver";
33
35
  export * from "./interfaces/InjectableProperties";
34
36
  export * from "./interfaces/InterceptorContext";
@@ -40,6 +42,7 @@ export * from "./interfaces/ProviderOpts";
40
42
  export * from "./interfaces/RegistrySettings";
41
43
  export * from "./interfaces/ResolvedInvokeOptions";
42
44
  export * from "./interfaces/TokenProvider";
45
+ export * from "./interfaces/TokenRoute";
43
46
  export * from "./registries/GlobalProviders";
44
47
  export * from "./registries/ProviderRegistry";
45
48
  export * from "./services/DIConfiguration";
@@ -49,5 +52,8 @@ export * from "./services/InjectorService";
49
52
  export * from "./utils/colors";
50
53
  export * from "./utils/createContainer";
51
54
  export * from "./utils/getConfiguration";
55
+ export * from "./utils/resolveControllers";
52
56
  export * from "./utils/runInContext";
57
+ export * from "./utils/setLoggerConfiguration";
58
+ export * from "./utils/setLoggerFormat";
53
59
  export * from "./utils/setLoggerLevel";
@@ -0,0 +1,4 @@
1
+ import { DIContext } from "../domain/DIContext";
2
+ export interface AlterRunInContext {
3
+ $alterRunInContext(next: (...args: unknown[]) => unknown, ctx: DIContext): () => unknown | Promise<() => unknown>;
4
+ }
@@ -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,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,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
  }
@@ -1,12 +1,11 @@
1
1
  import { Container } from "../domain/Container";
2
- import { LocalsContainer } from "../domain/LocalsContainer";
3
2
  import { Provider } from "../domain/Provider";
4
- import { DIConfiguration } from "./DIConfiguration";
5
3
  import { ProviderScope } from "../domain/ProviderScope";
6
4
  import { DILogger } from "../interfaces/DILogger";
7
- import { TokenProvider } from "../interfaces/TokenProvider";
8
- import { InvokeOptions } from "../interfaces/InvokeOptions";
9
5
  import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties";
6
+ import { InvokeOptions } from "../interfaces/InvokeOptions";
7
+ import { TokenProvider } from "../interfaces/TokenProvider";
8
+ import { DIConfiguration } from "./DIConfiguration";
10
9
  /**
11
10
  * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
12
11
  *
@@ -20,7 +19,7 @@ import { InjectablePropertyOptions, InjectablePropertyValue } from "../interface
20
19
  * import MyService2 from "./services/service2";
21
20
  * import MyService3 from "./services/service3";
22
21
  *
23
- * // When all services is imported you can load InjectorService.
22
+ * // When all services are imported, you can load InjectorService.
24
23
  * const injector = new InjectorService()
25
24
  *
26
25
  * await injector.load();
@@ -30,16 +29,12 @@ import { InjectablePropertyOptions, InjectablePropertyValue } from "../interface
30
29
  */
31
30
  export declare class InjectorService extends Container {
32
31
  #private;
33
- settings: TsED.Configuration & DIConfiguration;
32
+ settings: DIConfiguration;
34
33
  logger: DILogger;
35
34
  private resolvedConfiguration;
36
35
  constructor();
37
36
  get resolvers(): import("..").DIResolver[];
38
- get scopes(): {
39
- [key: string]: ProviderScope;
40
- } & {
41
- [key: string]: ProviderScope;
42
- };
37
+ get scopes(): Record<string, ProviderScope>;
43
38
  /**
44
39
  * Retrieve default scope for a given provider.
45
40
  * @param provider
@@ -69,7 +64,7 @@ export declare class InjectorService extends Container {
69
64
  * @param options
70
65
  * @returns {boolean}
71
66
  */
72
- get<T = any>(token: TokenProvider, options?: any): T | undefined;
67
+ get<T = any>(token: TokenProvider<T>, options?: any): T | undefined;
73
68
  /**
74
69
  * Return all instance of the same provider type
75
70
  * @param type
@@ -102,25 +97,29 @@ export declare class InjectorService extends Container {
102
97
  * @param options
103
98
  * @returns {T} The class constructed.
104
99
  */
105
- invoke<T>(token: TokenProvider, locals?: Map<TokenProvider, any>, options?: Partial<InvokeOptions<T>>): T;
100
+ invoke<T = any>(token: TokenProvider, locals?: Map<TokenProvider, any>, options?: Partial<InvokeOptions<T>>): T;
106
101
  /**
107
102
  * Build only providers which are asynchronous.
108
103
  */
109
- loadAsync(locals?: LocalsContainer): Promise<LocalsContainer<any>>;
110
- loadSync(locals?: LocalsContainer): LocalsContainer<any>;
104
+ loadAsync(): Promise<void>;
105
+ loadSync(): void;
111
106
  /**
112
107
  * Boostrap injector from container and resolve configuration.
113
108
  *
114
109
  * @param container
115
110
  */
116
111
  bootstrap(container?: Container): this;
112
+ /**
113
+ * Load injector from a given module
114
+ * @param rootModule
115
+ */
116
+ loadModule(rootModule: TokenProvider): Promise<void>;
117
117
  /**
118
118
  * Build all providers from given container (or GlobalProviders) and emit `$onInit` event.
119
119
  *
120
120
  * @param container
121
- * @param rootModule
122
121
  */
123
- load(container?: Container, rootModule?: TokenProvider): Promise<LocalsContainer<any>>;
122
+ load(container?: Container): Promise<void>;
124
123
  /**
125
124
  * Load all configurations registered on providers
126
125
  */
@@ -1,2 +1,3 @@
1
1
  import { Type } from "@tsed/core";
2
+ export declare function mergeMount(m1?: any, m2?: any): any;
2
3
  export declare function getConfiguration(module: Type<any>, configuration?: any): any;
@@ -0,0 +1,12 @@
1
+ import { TokenProvider } from "../interfaces/TokenProvider";
2
+ import { TokenRoute } from "../interfaces/TokenRoute";
3
+ export declare function getTokens(config: any): {
4
+ route?: string;
5
+ token: TokenProvider;
6
+ }[];
7
+ /**
8
+ * Return controllers and is base route according to his configuration in module configuration.
9
+ *
10
+ * @param settings
11
+ */
12
+ export declare function resolveControllers(settings: Partial<TsED.Configuration>): TokenRoute[];
@@ -2,5 +2,6 @@
2
2
  import { AsyncLocalStorage } from "async_hooks";
3
3
  import { DIContext } from "../domain/DIContext";
4
4
  export declare function getAsyncStore(): AsyncLocalStorage<DIContext>;
5
- export declare function getContext(): DIContext | undefined;
5
+ export declare function getContext<Context = DIContext>(): Context | undefined;
6
6
  export declare function runInContext(ctx: DIContext, cb: any): unknown;
7
+ export declare function bindContext(cb: any): any;
@@ -0,0 +1,2 @@
1
+ import type { InjectorService } from "../services/InjectorService";
2
+ export declare function setLoggerConfiguration(injector: InjectorService): void;
@@ -0,0 +1,6 @@
1
+ import type { InjectorService } from "../services/InjectorService";
2
+ /**
3
+ * @ignore
4
+ * @param injector
5
+ */
6
+ export declare function setLoggerFormat(injector: InjectorService): void;
@@ -1,4 +1,4 @@
1
- import { InjectorService } from "../services/InjectorService";
1
+ import type { InjectorService } from "../services/InjectorService";
2
2
  /**
3
3
  * @ignore
4
4
  * @param injector
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/di",
3
- "version": "7.0.0-beta.10",
3
+ "version": "7.0.0-beta.13",
4
4
  "description": "DI module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -17,20 +17,21 @@
17
17
  "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
18
18
  "build:cjs": "tsc --build tsconfig.compile.json",
19
19
  "build:esm": "tsc --build tsconfig.compile.esm.json",
20
- "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\""
20
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\"",
21
+ "test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
21
22
  },
22
23
  "dependencies": {
23
- "tslib": "2.3.1"
24
+ "tslib": "2.4.0"
24
25
  },
25
26
  "devDependencies": {
26
- "@tsed/core": "7.0.0-beta.10",
27
- "@tsed/logger": ">=6.1.1",
28
- "@tsed/schema": "7.0.0-beta.10"
27
+ "@tsed/core": "7.0.0-beta.13",
28
+ "@tsed/logger": ">=6.2.0",
29
+ "@tsed/schema": "7.0.0-beta.13"
29
30
  },
30
31
  "peerDependencies": {
31
- "@tsed/core": "^7.0.0-beta.10",
32
- "@tsed/logger": ">=6.1.1",
33
- "@tsed/schema": "^7.0.0-beta.10"
32
+ "@tsed/core": "^7.0.0-beta.13",
33
+ "@tsed/logger": ">=6.2.0",
34
+ "@tsed/schema": "^7.0.0-beta.13"
34
35
  },
35
36
  "peerDependenciesMeta": {
36
37
  "@tsed/core": {
@@ -49,5 +50,8 @@
49
50
  },
50
51
  "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/di",
51
52
  "author": "Romain Lenzotti",
52
- "license": "MIT"
53
+ "license": "MIT",
54
+ "publishConfig": {
55
+ "tag": "beta"
56
+ }
53
57
  }
package/readme.md CHANGED
@@ -11,7 +11,8 @@
11
11
  [![npm version](https://badge.fury.io/js/%40tsed%2Fcommon.svg)](https://badge.fury.io/js/%40tsed%2Fcommon)
12
12
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
13
13
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
14
- [![backers](https://opencollective.com/tsed/tiers/badge.svg)](https://opencollective.com/tsed)
14
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
15
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
15
16
 
16
17
  </div>
17
18