@tsed/di 6.68.1 → 6.69.0-rc.3

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 (116) hide show
  1. package/lib/index.js +2537 -23
  2. package/lib/index.js.map +1 -1
  3. package/lib/index.modern.js +2474 -0
  4. package/lib/index.modern.js.map +1 -0
  5. package/lib/registries/GlobalProviders.d.ts +1 -1
  6. package/package.json +11 -8
  7. package/lib/constants/index.js +0 -7
  8. package/lib/constants/index.js.map +0 -1
  9. package/lib/decorators/configuration.js +0 -24
  10. package/lib/decorators/configuration.js.map +0 -1
  11. package/lib/decorators/constant.js +0 -55
  12. package/lib/decorators/constant.js.map +0 -1
  13. package/lib/decorators/index.js +0 -17
  14. package/lib/decorators/index.js.map +0 -1
  15. package/lib/decorators/inject.js +0 -60
  16. package/lib/decorators/inject.js.map +0 -1
  17. package/lib/decorators/injectable.js +0 -33
  18. package/lib/decorators/injectable.js.map +0 -1
  19. package/lib/decorators/intercept.js +0 -28
  20. package/lib/decorators/intercept.js.map +0 -1
  21. package/lib/decorators/interceptor.js +0 -21
  22. package/lib/decorators/interceptor.js.map +0 -1
  23. package/lib/decorators/module.js +0 -31
  24. package/lib/decorators/module.js.map +0 -1
  25. package/lib/decorators/opts.js +0 -54
  26. package/lib/decorators/opts.js.map +0 -1
  27. package/lib/decorators/overrideProvider.js +0 -17
  28. package/lib/decorators/overrideProvider.js.map +0 -1
  29. package/lib/decorators/scope.js +0 -16
  30. package/lib/decorators/scope.js.map +0 -1
  31. package/lib/decorators/service.js +0 -18
  32. package/lib/decorators/service.js.map +0 -1
  33. package/lib/decorators/useOpts.js +0 -65
  34. package/lib/decorators/useOpts.js.map +0 -1
  35. package/lib/decorators/value.js +0 -55
  36. package/lib/decorators/value.js.map +0 -1
  37. package/lib/domain/Container.js +0 -69
  38. package/lib/domain/Container.js.map +0 -1
  39. package/lib/domain/ContextLogger.js +0 -92
  40. package/lib/domain/ContextLogger.js.map +0 -1
  41. package/lib/domain/DIContext.js +0 -45
  42. package/lib/domain/DIContext.js.map +0 -1
  43. package/lib/domain/InjectablePropertyType.js +0 -12
  44. package/lib/domain/InjectablePropertyType.js.map +0 -1
  45. package/lib/domain/LocalsContainer.js +0 -55
  46. package/lib/domain/LocalsContainer.js.map +0 -1
  47. package/lib/domain/Provider.js +0 -173
  48. package/lib/domain/Provider.js.map +0 -1
  49. package/lib/domain/ProviderScope.js +0 -10
  50. package/lib/domain/ProviderScope.js.map +0 -1
  51. package/lib/domain/ProviderType.js +0 -15
  52. package/lib/domain/ProviderType.js.map +0 -1
  53. package/lib/domain/index.js +0 -12
  54. package/lib/domain/index.js.map +0 -1
  55. package/lib/errors/InjectionError.js +0 -59
  56. package/lib/errors/InjectionError.js.map +0 -1
  57. package/lib/errors/UndefinedTokenError.js +0 -11
  58. package/lib/errors/UndefinedTokenError.js.map +0 -1
  59. package/lib/interfaces/DIConfigurationOptions.js +0 -3
  60. package/lib/interfaces/DIConfigurationOptions.js.map +0 -1
  61. package/lib/interfaces/DILogger.js +0 -3
  62. package/lib/interfaces/DILogger.js.map +0 -1
  63. package/lib/interfaces/DIResolver.js +0 -3
  64. package/lib/interfaces/DIResolver.js.map +0 -1
  65. package/lib/interfaces/IProvider.js +0 -3
  66. package/lib/interfaces/IProvider.js.map +0 -1
  67. package/lib/interfaces/InjectableProperties.js +0 -3
  68. package/lib/interfaces/InjectableProperties.js.map +0 -1
  69. package/lib/interfaces/InterceptorContext.js +0 -3
  70. package/lib/interfaces/InterceptorContext.js.map +0 -1
  71. package/lib/interfaces/InterceptorMethods.js +0 -3
  72. package/lib/interfaces/InterceptorMethods.js.map +0 -1
  73. package/lib/interfaces/InvokeOptions.js +0 -3
  74. package/lib/interfaces/InvokeOptions.js.map +0 -1
  75. package/lib/interfaces/OnDestroy.js +0 -3
  76. package/lib/interfaces/OnDestroy.js.map +0 -1
  77. package/lib/interfaces/OnInit.js +0 -3
  78. package/lib/interfaces/OnInit.js.map +0 -1
  79. package/lib/interfaces/RegistrySettings.js +0 -3
  80. package/lib/interfaces/RegistrySettings.js.map +0 -1
  81. package/lib/interfaces/TokenProvider.js +0 -3
  82. package/lib/interfaces/TokenProvider.js.map +0 -1
  83. package/lib/interfaces/index.js +0 -17
  84. package/lib/interfaces/index.js.map +0 -1
  85. package/lib/registries/GlobalProviders.js +0 -124
  86. package/lib/registries/GlobalProviders.js.map +0 -1
  87. package/lib/registries/ProviderRegistry.js +0 -181
  88. package/lib/registries/ProviderRegistry.js.map +0 -1
  89. package/lib/services/DIConfiguration.js +0 -129
  90. package/lib/services/DIConfiguration.js.map +0 -1
  91. package/lib/services/DILogger.js +0 -13
  92. package/lib/services/DILogger.js.map +0 -1
  93. package/lib/services/DITest.js +0 -100
  94. package/lib/services/DITest.js.map +0 -1
  95. package/lib/services/InjectorService.js +0 -543
  96. package/lib/services/InjectorService.js.map +0 -1
  97. package/lib/utils/cleanGlobPatterns.js +0 -30
  98. package/lib/utils/cleanGlobPatterns.js.map +0 -1
  99. package/lib/utils/createContainer.js +0 -14
  100. package/lib/utils/createContainer.js.map +0 -1
  101. package/lib/utils/data/Test1.d.ts +0 -3
  102. package/lib/utils/data/Test1.js +0 -8
  103. package/lib/utils/data/Test1.js.map +0 -1
  104. package/lib/utils/data/Test2.d.ts +0 -3
  105. package/lib/utils/data/Test2.js +0 -8
  106. package/lib/utils/data/Test2.js.map +0 -1
  107. package/lib/utils/getConfiguration.js +0 -20
  108. package/lib/utils/getConfiguration.js.map +0 -1
  109. package/lib/utils/importComponents.js +0 -50
  110. package/lib/utils/importComponents.js.map +0 -1
  111. package/lib/utils/importFiles.js +0 -28
  112. package/lib/utils/importFiles.js.map +0 -1
  113. package/lib/utils/importProviders.js +0 -29
  114. package/lib/utils/importProviders.js.map +0 -1
  115. package/lib/utils/setLoggerLevel.js +0 -16
  116. package/lib/utils/setLoggerLevel.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"overrideProvider.js","sourceRoot":"","sources":["../../src/decorators/overrideProvider.ts"],"names":[],"mappings":";;;AACA,mEAA8D;AAE9D;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,gBAA2B;IAC1D,OAAO,CAAC,MAAiB,EAAQ,EAAE;QACjC,iCAAe,CAAC,GAAG,CAAC,gBAAgB,CAAE,CAAC,QAAQ,GAAG,MAAM,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC;AAJD,4CAIC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\n\n/**\n * Override a provider which is already registered in ProviderRegistry.\n * @returns {Function}\n * @decorators\n * @param originalProvider\n */\nexport function OverrideProvider(originalProvider: Type<any>): Function {\n return (target: Type<any>): void => {\n GlobalProviders.get(originalProvider)!.useClass = target;\n };\n}\n"]}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Scope = void 0;
4
- const core_1 = require("@tsed/core");
5
- const ProviderScope_1 = require("../domain/ProviderScope");
6
- /**
7
- *
8
- * @param {"request" | "singleton" | ProviderScope} scope
9
- * @returns {Function}
10
- * @constructor
11
- */
12
- function Scope(scope = ProviderScope_1.ProviderScope.REQUEST) {
13
- return core_1.StoreSet("scope", scope);
14
- }
15
- exports.Scope = Scope;
16
- //# sourceMappingURL=scope.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/decorators/scope.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AACpC,2DAAsD;AAEtD;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,QAAiD,6BAAa,CAAC,OAAO;IAC1F,OAAO,eAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC;AAFD,sBAEC","sourcesContent":["import {StoreSet} from \"@tsed/core\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\n\n/**\n *\n * @param {\"request\" | \"singleton\" | ProviderScope} scope\n * @returns {Function}\n * @constructor\n */\nexport function Scope(scope: \"request\" | \"singleton\" | ProviderScope = ProviderScope.REQUEST) {\n return StoreSet(\"scope\", scope);\n}\n"]}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Service = void 0;
4
- const injectable_1 = require("./injectable");
5
- /**
6
- * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.
7
- * All services annotated with `@Service()` are constructed one time.
8
- *
9
- * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.
10
- *
11
- * @returns {Function}
12
- * @decorator
13
- */
14
- function Service() {
15
- return injectable_1.Injectable();
16
- }
17
- exports.Service = Service;
18
- //# sourceMappingURL=service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/decorators/service.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AAExC;;;;;;;;GAQG;AACH,SAAgB,OAAO;IACrB,OAAO,uBAAU,EAAE,CAAC;AACtB,CAAC;AAFD,0BAEC","sourcesContent":["import {Injectable} from \"./injectable\";\n\n/**\n * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.\n * All services annotated with `@Service()` are constructed one time.\n *\n * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.\n *\n * @returns {Function}\n * @decorator\n */\nexport function Service(): Function {\n return Injectable();\n}\n"]}
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UseOpts = void 0;
4
- const core_1 = require("@tsed/core");
5
- const constants_1 = require("../constants");
6
- /**
7
- * Add options to invoke the Service.
8
- *
9
- * ```typescript
10
- * import {Injectable, Opts, UseOpts} from "@tsed/di";
11
- *
12
- * @Injectable()
13
- * class MyConfigurableService {
14
- * source: string;
15
- * constructor(@Opts options: any = {}) {
16
- * console.log("Hello ", options.source); // log: Hello Service1 then Hello Service2
17
- *
18
- * this.source = options.source;
19
- * }
20
- * }
21
- *
22
- * @Injectable()
23
- * class MyService1 {
24
- * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {
25
- * console.log(service.source) // log: Service1
26
- * }
27
- * }
28
- *
29
- * @Injectable()
30
- * class MyService2 {
31
- * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {
32
- * console.log(service.source) // log: Service2
33
- * }
34
- * }
35
- * ```
36
- *
37
- * ::: warning
38
- * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.
39
- * :::
40
- *
41
- * @returns {Function}
42
- * @decorator
43
- * @param options
44
- */
45
- function UseOpts(options) {
46
- return (target, propertyKey, index) => {
47
- const bindingType = core_1.decoratorTypeOf([target, propertyKey, index]);
48
- switch (bindingType) {
49
- case core_1.DecoratorTypes.PARAM_CTOR:
50
- core_1.Store.from(target).merge(`${constants_1.DI_PARAM_OPTIONS}:${index}`, options);
51
- break;
52
- case core_1.DecoratorTypes.PROP:
53
- core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
54
- [propertyKey]: {
55
- options
56
- }
57
- });
58
- break;
59
- default:
60
- throw new core_1.UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);
61
- }
62
- };
63
- }
64
- exports.UseOpts = UseOpts;
65
- //# sourceMappingURL=useOpts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../src/decorators/useOpts.ts"],"names":[],"mappings":";;;AAAA,qCAA4F;AAC5F,4CAA+D;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,SAAgB,OAAO,CAAC,OAA6B;IACnD,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,KAAc,EAAO,EAAE;QAC3E,MAAM,WAAW,GAAG,sBAAe,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;QAElE,QAAQ,WAAW,EAAE;YACnB,KAAK,qBAAc,CAAC,UAAU;gBAC5B,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,4BAAgB,IAAI,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;gBAClE,MAAM;YAER,KAAK,qBAAc,CAAC,IAAI;gBACtB,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;oBACxC,CAAC,WAAqB,CAAC,EAAE;wBACvB,OAAO;qBACR;iBACF,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,+BAAwB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;SAC7E;IACH,CAAC,CAAC;AACJ,CAAC;AArBD,0BAqBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants\";\n\n/**\n * Add options to invoke the Service.\n *\n * ```typescript\n * import {Injectable, Opts, UseOpts} from \"@tsed/di\";\n *\n * @Injectable()\n * class MyConfigurableService {\n * source: string;\n * constructor(@Opts options: any = {}) {\n * console.log(\"Hello \", options.source); // log: Hello Service1 then Hello Service2\n *\n * this.source = options.source;\n * }\n * }\n *\n * @Injectable()\n * class MyService1 {\n * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service1\n * }\n * }\n *\n * @Injectable()\n * class MyService2 {\n * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service2\n * }\n * }\n * ```\n *\n * ::: warning\n * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.\n * :::\n *\n * @returns {Function}\n * @decorator\n * @param options\n */\nexport function UseOpts(options: {[key: string]: any}): Function {\n return (target: Object, propertyKey: string | symbol, index?: number): any => {\n const bindingType = decoratorTypeOf([target, propertyKey, index]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM_CTOR:\n Store.from(target).merge(`${DI_PARAM_OPTIONS}:${index}`, options);\n break;\n\n case DecoratorTypes.PROP:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey as string]: {\n options\n }\n });\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);\n }\n };\n}\n"]}
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Value = void 0;
4
- const core_1 = require("@tsed/core");
5
- const constants_1 = require("../constants");
6
- const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
7
- /**
8
- * Return value from Configuration.
9
- *
10
- * ## Example
11
- *
12
- * ```typescript
13
- * import {Env} from "@tsed/core";
14
- * import {Constant, Value} from "@tsed/di";
15
- *
16
- * export class MyClass {
17
- *
18
- * @Constant("env")
19
- * env: Env;
20
- *
21
- * @Value("swagger.path")
22
- * swaggerPath: string;
23
- *
24
- * @Value("swagger.path", "defaultValue")
25
- * swaggerPath: string;
26
- *
27
- * constructor() {
28
- * console.log(this.swaggerPath) // undefined. Not available on constructor
29
- * }
30
- *
31
- * $onInit() {
32
- * console.log(this.swaggerPath) // something
33
- * }
34
- * }
35
- * ```
36
- *
37
- * @param expression
38
- * @param defaultValue
39
- * @returns {(targetClass: any, attributeName: string) => any}
40
- * @decorator
41
- */
42
- function Value(expression, defaultValue) {
43
- return (target, propertyKey) => {
44
- core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
45
- [propertyKey]: {
46
- bindingType: InjectablePropertyType_1.InjectablePropertyType.VALUE,
47
- propertyKey,
48
- expression,
49
- defaultValue
50
- }
51
- });
52
- };
53
- }
54
- exports.Value = Value;
55
- //# sourceMappingURL=value.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"value.js","sourceRoot":"","sources":["../../src/decorators/value.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,4CAA6C;AAE7C,6EAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,KAAK,CAAC,UAAe,EAAE,YAAkB;IACvD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;YACxC,CAAC,WAAW,CAAC,EAAE;gBACb,WAAW,EAAE,+CAAsB,CAAC,KAAK;gBACzC,WAAW;gBACX,UAAU;gBACV,YAAY;aACb;SACsB,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC;AAXD,sBAWC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\n\n/**\n * Return value from Configuration.\n *\n * ## Example\n *\n * ```typescript\n * import {Env} from \"@tsed/core\";\n * import {Constant, Value} from \"@tsed/di\";\n *\n * export class MyClass {\n *\n * @Constant(\"env\")\n * env: Env;\n *\n * @Value(\"swagger.path\")\n * swaggerPath: string;\n *\n * @Value(\"swagger.path\", \"defaultValue\")\n * swaggerPath: string;\n *\n * constructor() {\n * console.log(this.swaggerPath) // undefined. Not available on constructor\n * }\n *\n * $onInit() {\n * console.log(this.swaggerPath) // something\n * }\n * }\n * ```\n *\n * @param expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Value(expression: any, defaultValue?: any) {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.VALUE,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n"]}
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Container = void 0;
4
- const GlobalProviders_1 = require("../registries/GlobalProviders");
5
- const LocalsContainer_1 = require("./LocalsContainer");
6
- const Provider_1 = require("./Provider");
7
- class Container extends LocalsContainer_1.LocalsContainer {
8
- /**
9
- *
10
- * @param token
11
- * @param settings
12
- */
13
- add(token, settings = {}) {
14
- const provider = GlobalProviders_1.GlobalProviders.has(token) ? GlobalProviders_1.GlobalProviders.get(token).clone() : new Provider_1.Provider(token);
15
- Object.assign(provider, settings);
16
- return super.set(token, provider);
17
- }
18
- /**
19
- * Add a provider to the
20
- * @param token
21
- * @param settings
22
- */
23
- addProvider(token, settings = {}) {
24
- return this.add(token, settings);
25
- }
26
- /**
27
- *
28
- * @param token
29
- */
30
- hasProvider(token) {
31
- return super.has(token);
32
- }
33
- /**
34
- * Add a provider to the
35
- * @param token
36
- * @param provider
37
- */
38
- setProvider(token, provider) {
39
- return super.set(token, provider);
40
- }
41
- /**
42
- * The getProvider() method returns a specified element from a Map object.
43
- * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
44
- * @param token
45
- */
46
- getProvider(token) {
47
- return super.get(token);
48
- }
49
- /**
50
- * Get all providers registered in the injector container.
51
- *
52
- * @param {ProviderType} type Filter the list by the given ProviderType.
53
- * @returns {[TokenProvider , Provider<any>][]}
54
- */
55
- getProviders(type) {
56
- return Array.from(this)
57
- .filter(([_, provider]) => (type ? provider.type === type : true))
58
- .map(([_, provider]) => provider);
59
- }
60
- addProviders(container) {
61
- container.forEach((provider) => {
62
- if (!this.hasProvider(provider.provide)) {
63
- this.setProvider(provider.provide, provider.clone());
64
- }
65
- });
66
- }
67
- }
68
- exports.Container = Container;
69
- //# sourceMappingURL=Container.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Container.js","sourceRoot":"","sources":["../../src/domain/Container.ts"],"names":[],"mappings":";;;AAGA,mEAA8D;AAC9D,uDAAkD;AAClD,yCAAoC;AAEpC,MAAa,SAAU,SAAQ,iCAAyB;IACtD;;;;OAIG;IACI,GAAG,CAAC,KAAoB,EAAE,WAA+B,EAAE;QAChE,MAAM,QAAQ,GAAG,iCAAe,CAAC,GAAG,CAAC,KAAK,C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WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBACvC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;aACtD;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApED,8BAoEC","sourcesContent":["import {IProvider} from \"../interfaces/IProvider\";\nimport {ProviderType} from \"./ProviderType\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {LocalsContainer} from \"./LocalsContainer\";\nimport {Provider} from \"./Provider\";\n\nexport class Container extends LocalsContainer<Provider> {\n /**\n *\n * @param token\n * @param settings\n */\n public add(token: TokenProvider, settings: Partial<IProvider> = {}): this {\n const provider = GlobalProviders.has(token) ? GlobalProviders.get(token)!.clone() : new Provider(token);\n\n Object.assign(provider, settings);\n\n return super.set(token, provider);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param settings\n */\n public addProvider(token: TokenProvider, settings: Partial<IProvider> = {}): this {\n return this.add(token, settings);\n }\n\n /**\n *\n * @param token\n */\n public hasProvider(token: TokenProvider) {\n return super.has(token);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param provider\n */\n public setProvider(token: TokenProvider, provider: Provider) {\n return super.set(token, provider);\n }\n\n /**\n * The getProvider() method returns a specified element from a Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n * @param token\n */\n public getProvider(token: TokenProvider): Provider | undefined {\n return super.get(token);\n }\n\n /**\n * Get all providers registered in the injector container.\n *\n * @param {ProviderType} type Filter the list by the given ProviderType.\n * @returns {[TokenProvider , Provider<any>][]}\n */\n public getProviders(type?: ProviderType | string): Provider[] {\n return Array.from(this)\n .filter(([_, provider]) => (type ? provider.type === type : true))\n .map(([_, provider]) => provider);\n }\n\n public addProviders(container: Map<TokenProvider, Provider>) {\n container.forEach((provider) => {\n if (!this.hasProvider(provider.provide)) {\n this.setProvider(provider.provide, provider.clone());\n }\n });\n }\n}\n"]}
@@ -1,92 +0,0 @@
1
- "use strict";
2
- var _additionalProps, _dateStart, _ignoreLog, _stack, _level;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ContextLogger = void 0;
5
- const tslib_1 = require("tslib");
6
- const logger_1 = require("@tsed/logger");
7
- class ContextLogger {
8
- constructor(logger, { id, url = "", dateStart = new Date(), ignoreUrlPatterns = [], minimalRequestPicker, completeRequestPicker, level = "all", maxStackSize = 30, ignoreLog, additionalProps }) {
9
- this.logger = logger;
10
- _additionalProps.set(this, void 0);
11
- _dateStart.set(this, void 0);
12
- _ignoreLog.set(this, void 0);
13
- _stack.set(this, []);
14
- _level.set(this, void 0);
15
- this.id = id;
16
- this.url = url;
17
- tslib_1.__classPrivateFieldSet(this, _additionalProps, additionalProps || {});
18
- tslib_1.__classPrivateFieldSet(this, _dateStart, dateStart);
19
- tslib_1.__classPrivateFieldSet(this, _ignoreLog, ignoreLog || (() => false));
20
- this.minimalRequestPicker = minimalRequestPicker || ((l) => l);
21
- this.completeRequestPicker = completeRequestPicker || ((l) => l);
22
- // @ts-ignore
23
- tslib_1.__classPrivateFieldSet(this, _level, logger_1.levels()[level.toUpperCase()] || logger_1.levels().ALL);
24
- this.maxStackSize = maxStackSize;
25
- }
26
- info(obj) {
27
- this.run(logger_1.levels().INFO, obj, (obj) => this.minimalRequestPicker(this.getData(obj)));
28
- return this;
29
- }
30
- debug(obj, withRequest = true) {
31
- this.run(logger_1.levels().DEBUG, obj, (obj) => {
32
- obj = this.getData(obj);
33
- return withRequest ? this.completeRequestPicker(obj) : obj;
34
- });
35
- return this;
36
- }
37
- warn(obj) {
38
- this.run(logger_1.levels().WARN, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
39
- return this;
40
- }
41
- error(obj) {
42
- this.run(logger_1.levels().ERROR, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
43
- return this;
44
- }
45
- trace(obj) {
46
- this.run(logger_1.levels().TRACE, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
47
- return this;
48
- }
49
- flush() {
50
- if (tslib_1.__classPrivateFieldGet(this, _stack).length) {
51
- tslib_1.__classPrivateFieldGet(this, _stack).forEach(({ level, data }) => {
52
- this.logger[level](data);
53
- });
54
- tslib_1.__classPrivateFieldSet(this, _stack, []);
55
- }
56
- }
57
- isLevelEnabled(otherLevel) {
58
- return tslib_1.__classPrivateFieldGet(this, _level).isLessThanOrEqualTo(otherLevel);
59
- }
60
- destroy() {
61
- this.flush();
62
- this.logger = undefined;
63
- tslib_1.__classPrivateFieldSet(this, _stack, undefined);
64
- }
65
- /**
66
- * Return the duration between the time when LogIncomingRequest has handle the request and now.
67
- * @returns {number}
68
- */
69
- getDuration() {
70
- return new Date().getTime() - tslib_1.__classPrivateFieldGet(this, _dateStart).getTime();
71
- }
72
- getData(obj) {
73
- if (typeof obj === "string") {
74
- obj = { message: obj };
75
- }
76
- return { ...tslib_1.__classPrivateFieldGet(this, _additionalProps), reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj };
77
- }
78
- run(level, obj, mapper) {
79
- if (!this.isLevelEnabled(level)) {
80
- return;
81
- }
82
- if (!tslib_1.__classPrivateFieldGet(this, _ignoreLog).call(this, obj)) {
83
- tslib_1.__classPrivateFieldGet(this, _stack).push({ level: level.levelStr.toLowerCase(), data: mapper(obj) });
84
- }
85
- if (this.maxStackSize < tslib_1.__classPrivateFieldGet(this, _stack).length) {
86
- this.flush();
87
- }
88
- }
89
- }
90
- exports.ContextLogger = ContextLogger;
91
- _additionalProps = new WeakMap(), _dateStart = new WeakMap(), _ignoreLog = new WeakMap(), _stack = new WeakMap(), _level = new WeakMap();
92
- //# sourceMappingURL=ContextLogger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContextLogger.js","sourceRoot":"","sources":["../../src/domain/ContextLogger.ts"],"names":[],"mappings":";;;;;AAAA,yCAA8C;AAc9C,MAAa,aAAa;IAYxB,YACU,MAAW,EACnB,EACE,EAAE,E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Options extends Record<string, any> {\n id: string;\n url?: string;\n dateStart?: Date;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\" | \"all\";\n maxStackSize?: number;\n minimalRequestPicker?: (o: any) => any;\n completeRequestPicker?: (o: any) => any;\n ignoreLog?: (data: any) => boolean;\n additionalProps?: Record<any, any>;\n}\n\nexport class ContextLogger {\n id: string;\n url: string;\n minimalRequestPicker: Function;\n completeRequestPicker: Function;\n maxStackSize: number;\n readonly #additionalProps: Record<string, unknown>;\n readonly #dateStart: Date;\n readonly #ignoreLog: (data: any) => boolean;\n #stack: any = [];\n #level: LogLevel;\n\n constructor(\n private logger: any,\n {\n id,\n url = \"\",\n dateStart = new Date(),\n ignoreUrlPatterns = [],\n minimalRequestPicker,\n completeRequestPicker,\n level = \"all\",\n maxStackSize = 30,\n ignoreLog,\n additionalProps\n }: ContextLoggerOptions\n ) {\n this.id = id;\n this.url = url;\n this.#additionalProps = additionalProps || {};\n this.#dateStart = dateStart;\n this.#ignoreLog = ignoreLog || (() => false);\n this.minimalRequestPicker = minimalRequestPicker || ((l: any) => l);\n this.completeRequestPicker = completeRequestPicker || ((l: any) => l);\n // @ts-ignore\n this.#level = levels()[level.toUpperCase()] || levels().ALL;\n this.maxStackSize = maxStackSize;\n }\n\n info(obj: any) {\n this.run(levels().INFO, obj, (obj) => this.minimalRequestPicker(this.getData(obj)));\n return this;\n }\n\n debug(obj: any, withRequest: boolean = true) {\n this.run(levels().DEBUG, obj, (obj) => {\n obj = this.getData(obj);\n return withRequest ? this.completeRequestPicker(obj) : obj;\n });\n return this;\n }\n\n warn(obj: any) {\n this.run(levels().WARN, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n error(obj: any) {\n this.run(levels().ERROR, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n trace(obj: any) {\n this.run(levels().TRACE, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n public flush() {\n if (this.#stack.length) {\n this.#stack.forEach(({level, data}: any) => {\n this.logger[level](data);\n });\n\n this.#stack = [];\n }\n }\n\n public isLevelEnabled(otherLevel: string | LogLevel) {\n return this.#level.isLessThanOrEqualTo(otherLevel);\n }\n\n destroy() {\n this.flush();\n\n this.logger = undefined;\n this.#stack = undefined;\n }\n\n /**\n * Return the duration between the time when LogIncomingRequest has handle the request and now.\n * @returns {number}\n */\n protected getDuration(): number {\n return new Date().getTime() - this.#dateStart.getTime();\n }\n\n protected getData(obj: any) {\n if (typeof obj === \"string\") {\n obj = {message: obj};\n }\n\n return {...this.#additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj};\n }\n\n protected run(level: LogLevel, obj: any, mapper: (data: any) => any) {\n if (!this.isLevelEnabled(level)) {\n return;\n }\n\n if (!this.#ignoreLog(obj)) {\n this.#stack.push({level: level.levelStr.toLowerCase(), data: mapper(obj)});\n }\n\n if (this.maxStackSize < this.#stack.length) {\n this.flush();\n }\n }\n}\n"]}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DIContext = void 0;
4
- const ContextLogger_1 = require("./ContextLogger");
5
- const LocalsContainer_1 = require("./LocalsContainer");
6
- class DIContext extends Map {
7
- constructor({ id, injector, logger, ignoreLog, ...options }) {
8
- super();
9
- /**
10
- * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.
11
- */
12
- this.dateStart = new Date();
13
- /**
14
- * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
15
- */
16
- this.container = new LocalsContainer_1.LocalsContainer();
17
- this.id = id;
18
- injector && (this.injector = injector);
19
- this.logger = new ContextLogger_1.ContextLogger(logger, {
20
- ...options,
21
- dateStart: this.dateStart,
22
- id,
23
- ignoreLog
24
- });
25
- }
26
- get env() {
27
- return this.injector.settings.env;
28
- }
29
- async destroy() {
30
- await this.container.destroy();
31
- this.logger.destroy();
32
- // @ts-ignore
33
- delete this.container;
34
- // @ts-ignore
35
- delete this.logger;
36
- // @ts-ignore
37
- delete this.injector;
38
- }
39
- async emit(eventName, ...args) {
40
- var _a;
41
- return (_a = this.injector) === null || _a === void 0 ? void 0 : _a.emit(eventName, ...args);
42
- }
43
- }
44
- exports.DIContext = DIContext;
45
- //# sourceMappingURL=DIContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,mDAAoE;AACpE,uDAAkD;AAwBlD,MAAa,SAAU,SAAQ,GAAa;IA4C1C,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QAlBV;;WAEG;QACM,cAAS,GAAS,IAAI,IAAI,EAAE,CAAC;QACtC;;WAEG;QACI,cAAS,GAAG,IAAI,iCAAe,EAAO,CAAC;QAY5C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;QACtB,aAAa;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;QACnB,aAAa;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;;QAC1C,OAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACF;AA5ED,8BA4EC","sourcesContent":["import {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\ndeclare global {\n namespace TsED {\n interface Context {}\n }\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n public logger: ContextLogger;\n /**\n *\n */\n public injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.env;\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n // @ts-ignore\n delete this.container;\n // @ts-ignore\n delete this.logger;\n // @ts-ignore\n delete this.injector;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InjectablePropertyType = void 0;
4
- var InjectablePropertyType;
5
- (function (InjectablePropertyType) {
6
- InjectablePropertyType["METHOD"] = "method";
7
- InjectablePropertyType["PROPERTY"] = "property";
8
- InjectablePropertyType["CONSTANT"] = "constant";
9
- InjectablePropertyType["VALUE"] = "value";
10
- InjectablePropertyType["INTERCEPTOR"] = "interceptor";
11
- })(InjectablePropertyType = exports.InjectablePropertyType || (exports.InjectablePropertyType = {}));
12
- //# sourceMappingURL=InjectablePropertyType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InjectablePropertyType.js","sourceRoot":"","sources":["../../src/domain/InjectablePropertyType.ts"],"names":[],"mappings":";;;AAAA,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,2CAAiB,CAAA;IACjB,+CAAqB,CAAA;IACrB,+CAAqB,CAAA;IACrB,yCAAe,CAAA;IACf,qDAA2B,CAAA;AAC7B,CAAC,EANW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAMjC","sourcesContent":["export enum InjectablePropertyType {\n METHOD = \"method\",\n PROPERTY = \"property\",\n CONSTANT = \"constant\",\n VALUE = \"value\",\n INTERCEPTOR = \"interceptor\"\n}\n"]}
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalsContainer = void 0;
4
- class LocalsContainer extends Map {
5
- /**
6
- * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
7
- * @param eventName The event name to emit at all services.
8
- * @param args List of the parameters to give to each services.
9
- * @returns {Promise<any[]>} A list of promises.
10
- */
11
- async emit(eventName, ...args) {
12
- for (const handler of this.getListeners(eventName)) {
13
- await handler(...args);
14
- }
15
- }
16
- /**
17
- * @param eventName
18
- * @param value
19
- * @param args
20
- */
21
- alter(eventName, value, ...args) {
22
- for (const handler of this.getListeners(eventName)) {
23
- value = handler(value, ...args);
24
- }
25
- return value;
26
- }
27
- /**
28
- * @param eventName
29
- * @param value
30
- * @param args
31
- */
32
- async alterAsync(eventName, value, ...args) {
33
- for (const handler of this.getListeners(eventName)) {
34
- value = handler(value, ...args);
35
- }
36
- return value;
37
- }
38
- toArray() {
39
- return [...this.values()];
40
- }
41
- async destroy() {
42
- await this.emit("$onDestroy");
43
- this.clear();
44
- }
45
- getListeners(event) {
46
- return this.toArray().reduce((listeners, instance) => {
47
- if (typeof instance === "object" && instance && event in instance) {
48
- return listeners.concat(instance[event].bind(instance));
49
- }
50
- return listeners;
51
- }, []);
52
- }
53
- }
54
- exports.LocalsContainer = LocalsContainer;
55
- //# sourceMappingURL=LocalsContainer.js.map