@tsed/di 7.0.0-beta.9 → 7.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage.json +6 -0
- package/jest.config.js +9 -0
- package/lib/cjs/decorators/controller.js.map +1 -1
- package/lib/cjs/decorators/inject.js +2 -2
- package/lib/cjs/decorators/inject.js.map +1 -1
- package/lib/cjs/domain/Container.js +1 -2
- package/lib/cjs/domain/Container.js.map +1 -1
- package/lib/cjs/domain/ContextLogger.js +41 -30
- package/lib/cjs/domain/ContextLogger.js.map +1 -1
- package/lib/cjs/domain/ControllerProvider.js +37 -0
- package/lib/cjs/domain/ControllerProvider.js.map +1 -0
- package/lib/cjs/domain/DIContext.js +86 -30
- package/lib/cjs/domain/DIContext.js.map +1 -1
- package/lib/cjs/domain/LocalsContainer.js +3 -46
- package/lib/cjs/domain/LocalsContainer.js.map +1 -1
- package/lib/cjs/domain/Provider.js +20 -1
- package/lib/cjs/domain/Provider.js.map +1 -1
- package/lib/cjs/errors/InjectionError.js +3 -2
- package/lib/cjs/errors/InjectionError.js.map +1 -1
- package/lib/cjs/errors/UndefinedTokenError.js +1 -1
- package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
- package/lib/cjs/index.js +8 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
- package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
- package/lib/cjs/interfaces/DILoggerOptions.js +3 -0
- package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/cjs/interfaces/InjectableProperties.js.map +1 -1
- package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -1
- package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
- package/lib/cjs/interfaces/TokenRoute.js +3 -0
- package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
- package/lib/cjs/registries/GlobalProviders.js +7 -12
- package/lib/cjs/registries/GlobalProviders.js.map +1 -1
- package/lib/cjs/registries/ProviderRegistry.js +1 -1
- package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
- package/lib/cjs/services/DIConfiguration.js +56 -43
- package/lib/cjs/services/DIConfiguration.js.map +1 -1
- package/lib/cjs/services/DITest.js +5 -6
- package/lib/cjs/services/DITest.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +94 -92
- package/lib/cjs/services/InjectorService.js.map +1 -1
- package/lib/cjs/utils/asyncHookContext.js +42 -0
- package/lib/cjs/utils/asyncHookContext.js.map +1 -0
- package/lib/cjs/utils/getConfiguration.js +13 -10
- package/lib/cjs/utils/getConfiguration.js.map +1 -1
- package/lib/cjs/utils/resolveControllers.js +47 -0
- package/lib/cjs/utils/resolveControllers.js.map +1 -0
- package/lib/cjs/utils/setLoggerConfiguration.js +11 -0
- package/lib/cjs/utils/setLoggerConfiguration.js.map +1 -0
- package/lib/cjs/utils/setLoggerFormat.js +33 -0
- package/lib/cjs/utils/setLoggerFormat.js.map +1 -0
- package/lib/cjs/utils/setLoggerLevel.js +1 -2
- package/lib/cjs/utils/setLoggerLevel.js.map +1 -1
- package/lib/esm/decorators/controller.js.map +1 -1
- package/lib/esm/decorators/inject.js +1 -1
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/domain/Container.js +1 -2
- package/lib/esm/domain/Container.js.map +1 -1
- package/lib/esm/domain/ContextLogger.js +41 -30
- package/lib/esm/domain/ContextLogger.js.map +1 -1
- package/lib/esm/domain/ControllerProvider.js +33 -0
- package/lib/esm/domain/ControllerProvider.js.map +1 -0
- package/lib/esm/domain/DIContext.js +86 -30
- package/lib/esm/domain/DIContext.js.map +1 -1
- package/lib/esm/domain/LocalsContainer.js +3 -46
- package/lib/esm/domain/LocalsContainer.js.map +1 -1
- package/lib/esm/domain/Provider.js +21 -2
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/errors/InjectionError.js +3 -2
- package/lib/esm/errors/InjectionError.js.map +1 -1
- package/lib/esm/errors/UndefinedTokenError.js +1 -1
- package/lib/esm/errors/UndefinedTokenError.js.map +1 -1
- package/lib/esm/index.js +8 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/AlterRunInContext.js +2 -0
- package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
- package/lib/esm/interfaces/DILoggerOptions.js +2 -0
- package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/esm/interfaces/InjectableProperties.js.map +1 -1
- package/lib/esm/interfaces/InterceptorMethods.js.map +1 -1
- package/lib/esm/interfaces/TokenProvider.js.map +1 -1
- package/lib/esm/interfaces/TokenRoute.js +2 -0
- package/lib/esm/interfaces/TokenRoute.js.map +1 -0
- package/lib/esm/registries/GlobalProviders.js +7 -12
- package/lib/esm/registries/GlobalProviders.js.map +1 -1
- package/lib/esm/registries/ProviderRegistry.js +1 -1
- package/lib/esm/registries/ProviderRegistry.js.map +1 -1
- package/lib/esm/services/DIConfiguration.js +57 -44
- package/lib/esm/services/DIConfiguration.js.map +1 -1
- package/lib/esm/services/DITest.js +5 -6
- package/lib/esm/services/DITest.js.map +1 -1
- package/lib/esm/services/InjectorService.js +96 -94
- package/lib/esm/services/InjectorService.js.map +1 -1
- package/lib/esm/utils/asyncHookContext.js +33 -0
- package/lib/esm/utils/asyncHookContext.js.map +1 -0
- package/lib/esm/utils/getConfiguration.js +12 -10
- package/lib/esm/utils/getConfiguration.js.map +1 -1
- package/lib/esm/utils/resolveControllers.js +42 -0
- package/lib/esm/utils/resolveControllers.js.map +1 -0
- package/lib/esm/utils/setLoggerConfiguration.js +7 -0
- package/lib/esm/utils/setLoggerConfiguration.js.map +1 -0
- package/lib/esm/utils/setLoggerFormat.js +29 -0
- package/lib/esm/utils/setLoggerFormat.js.map +1 -0
- package/lib/esm/utils/setLoggerLevel.js +1 -2
- package/lib/esm/utils/setLoggerLevel.js.map +1 -1
- package/lib/types/decorators/controller.d.ts +0 -1
- package/lib/types/domain/ContextLogger.d.ts +13 -18
- package/lib/types/domain/ControllerProvider.d.ts +17 -0
- package/lib/types/domain/DIContext.d.ts +23 -29
- package/lib/types/domain/LocalsContainer.d.ts +3 -22
- package/lib/types/domain/Provider.d.ts +2 -1
- package/lib/types/index.d.ts +8 -1
- package/lib/types/interfaces/AlterRunInContext.d.ts +3 -0
- package/lib/types/interfaces/DIConfigurationOptions.d.ts +5 -2
- package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
- package/lib/types/interfaces/InjectableProperties.d.ts +2 -1
- package/lib/types/interfaces/InterceptorMethods.d.ts +1 -1
- package/lib/types/interfaces/TokenProvider.d.ts +1 -1
- package/lib/types/interfaces/TokenRoute.d.ts +5 -0
- package/lib/types/registries/GlobalProviders.d.ts +6 -5
- package/lib/types/registries/ProviderRegistry.d.ts +2 -1
- package/lib/types/services/DIConfiguration.d.ts +19 -11
- package/lib/types/services/InjectorService.d.ts +20 -28
- package/lib/types/utils/asyncHookContext.d.ts +14 -0
- package/lib/types/utils/getConfiguration.d.ts +1 -0
- package/lib/types/utils/resolveControllers.d.ts +12 -0
- package/lib/types/utils/setLoggerConfiguration.d.ts +2 -0
- package/lib/types/utils/setLoggerFormat.d.ts +6 -0
- package/lib/types/utils/setLoggerLevel.d.ts +1 -1
- package/package.json +15 -11
- package/readme.md +3 -2
- package/lib/cjs/utils/runInContext.js +0 -20
- package/lib/cjs/utils/runInContext.js.map +0 -1
- package/lib/esm/utils/runInContext.js +0 -14
- package/lib/esm/utils/runInContext.js.map +0 -1
- package/lib/types/utils/runInContext.d.ts +0 -6
|
@@ -4,10 +4,11 @@ exports.InjectionError = void 0;
|
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
const colors_1 = require("../utils/colors");
|
|
6
6
|
class InjectionError extends Error {
|
|
7
|
+
name = "INJECTION_ERROR";
|
|
8
|
+
tokens = [];
|
|
9
|
+
origin;
|
|
7
10
|
constructor(token, origin) {
|
|
8
11
|
super((0, core_1.isString)(origin) ? origin : "");
|
|
9
|
-
this.name = "INJECTION_ERROR";
|
|
10
|
-
this.tokens = [];
|
|
11
12
|
this.tokens = [token];
|
|
12
13
|
if (origin) {
|
|
13
14
|
if ((0, core_1.isString)(origin)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAE7E,4CAAuC;AAEvC,MAAa,cAAe,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAE7E,4CAAuC;AAEvC,MAAa,cAAe,SAAQ,KAAK;IACvC,IAAI,GAAG,iBAAiB,CAAC;IAElB,MAAM,GAAoB,EAAE,CAAC;IAC7B,MAAM,CAAM;IAEnB,YAAY,KAAoB,EAAE,MAAY;QAC5C,KAAK,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;QAEtB,IAAI,MAAM,EAAE;YACV,IAAI,IAAA,eAAQ,EAAC,MAAM,CAAC,EAAE;gBACpB,IAAI,CAAC,MAAM,GAAG;oBACZ,OAAO,EAAE,MAAM;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;iBAClB,CAAC;aACH;iBAAM;gBACL,IAAI,MAAM,CAAC,MAAM,EAAE;oBACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;iBAC7B;qBAAM;oBACL,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;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EAAE,CAAC;IAClD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,SAAS,GAAG,IAAA,aAAM,EAAC,KAAK,CAAC,GAAG,gBAAgB,GAAG,IAAI,GAAG,GAAG,CAAC;IAChE,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,eAAM,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhH,OAAO,+BAA+B,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACjI,CAAC","sourcesContent":["import {getConstructorArgNames, isClass, isString, nameOf} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {colors} from \"../utils/colors\";\n\nexport class InjectionError extends Error {\n name = \"INJECTION_ERROR\";\n\n public tokens: TokenProvider[] = [];\n public origin: any;\n\n constructor(token: TokenProvider, origin?: any) {\n super(isString(origin) ? origin : \"\");\n\n this.tokens = [token];\n\n if (origin) {\n if (isString(origin)) {\n this.origin = {\n message: origin,\n stack: this.stack\n };\n } else {\n if (origin.tokens) {\n this.tokens = this.tokens.concat(origin.tokens);\n this.origin = origin.origin;\n } else {\n this.origin = origin;\n this.stack = origin.stack;\n }\n }\n }\n\n const originMessage = this.origin ? \"\\nOrigin: \" + this.origin.message : \"\";\n const tokensMessage = this.tokens.map((token) => nameOf(token)).join(\" > \");\n\n this.message = `Injection failed on ${tokensMessage}${originMessage}`;\n }\n\n static throwInjectorError(token: any, currentDependency: any, error: any) {\n if (currentDependency && isClass(token)) {\n error.message = printDependencyInjectionError(token, {...currentDependency, message: error.message});\n }\n\n throw new InjectionError(token, error);\n }\n}\n\nfunction printDependencyInjectionError(token: any, options: {token: any; index: number; deps: any[]; message: string}) {\n let erroredArg = \"\";\n\n const args = getConstructorArgNames(token)\n .map((arg, index) => {\n if (options.index === index) {\n erroredArg = arg;\n arg = colors.red(arg);\n }\n\n return `${arg}: ${nameOf(options.deps[index])}`;\n })\n .join(\", \");\n\n const signature = nameOf(token) + \"->constructor(\" + args + \")\";\n const indexOf = signature.indexOf(erroredArg) - 5;\n const drawline = (indexOf: number) => \" \".repeat(indexOf) + colors.red(\"^\" + \"‾\".repeat(erroredArg.length - 1));\n\n return \"Unable to inject dependency. \" + options.message + \"\\n\\n\" + signature + \"\\n\" + (indexOf > -1 ? drawline(indexOf) : \"\");\n}\n"]}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UndefinedTokenError = void 0;
|
|
4
4
|
class UndefinedTokenError extends Error {
|
|
5
|
+
name = "UNDEFINED_TOKEN_ERROR";
|
|
5
6
|
constructor() {
|
|
6
7
|
super("Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?");
|
|
7
|
-
this.name = "UNDEFINED_TOKEN_ERROR";
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.UndefinedTokenError = UndefinedTokenError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,IAAI,GAAG,uBAAuB,CAAC;IAE/B;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;IACJ,CAAC;CACF;AARD,kDAQC","sourcesContent":["export class UndefinedTokenError extends Error {\n name = \"UNDEFINED_TOKEN_ERROR\";\n\n constructor() {\n super(\n \"Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?\"\n );\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -22,6 +22,7 @@ tslib_1.__exportStar(require("./decorators/useOpts"), exports);
|
|
|
22
22
|
tslib_1.__exportStar(require("./decorators/value"), exports);
|
|
23
23
|
tslib_1.__exportStar(require("./domain/Container"), exports);
|
|
24
24
|
tslib_1.__exportStar(require("./domain/ContextLogger"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./domain/ControllerProvider"), exports);
|
|
25
26
|
tslib_1.__exportStar(require("./domain/DIContext"), exports);
|
|
26
27
|
tslib_1.__exportStar(require("./domain/InjectablePropertyType"), exports);
|
|
27
28
|
tslib_1.__exportStar(require("./domain/LocalsContainer"), exports);
|
|
@@ -30,8 +31,10 @@ tslib_1.__exportStar(require("./domain/ProviderScope"), exports);
|
|
|
30
31
|
tslib_1.__exportStar(require("./domain/ProviderType"), exports);
|
|
31
32
|
tslib_1.__exportStar(require("./errors/InjectionError"), exports);
|
|
32
33
|
tslib_1.__exportStar(require("./errors/UndefinedTokenError"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./interfaces/AlterRunInContext"), exports);
|
|
33
35
|
tslib_1.__exportStar(require("./interfaces/DIConfigurationOptions"), exports);
|
|
34
36
|
tslib_1.__exportStar(require("./interfaces/DILogger"), exports);
|
|
37
|
+
tslib_1.__exportStar(require("./interfaces/DILoggerOptions"), exports);
|
|
35
38
|
tslib_1.__exportStar(require("./interfaces/DIResolver"), exports);
|
|
36
39
|
tslib_1.__exportStar(require("./interfaces/InjectableProperties"), exports);
|
|
37
40
|
tslib_1.__exportStar(require("./interfaces/InterceptorContext"), exports);
|
|
@@ -43,15 +46,19 @@ tslib_1.__exportStar(require("./interfaces/ProviderOpts"), exports);
|
|
|
43
46
|
tslib_1.__exportStar(require("./interfaces/RegistrySettings"), exports);
|
|
44
47
|
tslib_1.__exportStar(require("./interfaces/ResolvedInvokeOptions"), exports);
|
|
45
48
|
tslib_1.__exportStar(require("./interfaces/TokenProvider"), exports);
|
|
49
|
+
tslib_1.__exportStar(require("./interfaces/TokenRoute"), exports);
|
|
46
50
|
tslib_1.__exportStar(require("./registries/GlobalProviders"), exports);
|
|
47
51
|
tslib_1.__exportStar(require("./registries/ProviderRegistry"), exports);
|
|
48
52
|
tslib_1.__exportStar(require("./services/DIConfiguration"), exports);
|
|
49
53
|
tslib_1.__exportStar(require("./services/DILogger"), exports);
|
|
50
54
|
tslib_1.__exportStar(require("./services/DITest"), exports);
|
|
51
55
|
tslib_1.__exportStar(require("./services/InjectorService"), exports);
|
|
56
|
+
tslib_1.__exportStar(require("./utils/asyncHookContext"), exports);
|
|
52
57
|
tslib_1.__exportStar(require("./utils/colors"), exports);
|
|
53
58
|
tslib_1.__exportStar(require("./utils/createContainer"), exports);
|
|
54
59
|
tslib_1.__exportStar(require("./utils/getConfiguration"), exports);
|
|
55
|
-
tslib_1.__exportStar(require("./utils/
|
|
60
|
+
tslib_1.__exportStar(require("./utils/resolveControllers"), exports);
|
|
61
|
+
tslib_1.__exportStar(require("./utils/setLoggerConfiguration"), exports);
|
|
62
|
+
tslib_1.__exportStar(require("./utils/setLoggerFormat"), exports);
|
|
56
63
|
tslib_1.__exportStar(require("./utils/setLoggerLevel"), exports);
|
|
57
64
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,8EAAoD;AACpD,gEAAsC;AACtC,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,sEAA4C;AAC5C,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,yEAA+C;AAC/C,8EAAoD;AACpD,gEAAsC;AACtC,uEAA6C;AAC7C,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,kEAAwC;AACxC,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,mEAAyC;AACzC,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,qEAA2C;AAC3C,yEAA+C;AAC/C,kEAAwC;AACxC,iEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/ControllerProvider\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/AlterRunInContext\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/asyncHookContext\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlterRunInContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterRunInContext.ts"],"names":[],"mappings":"","sourcesContent":["export interface AlterRunInContext {\n $alterRunInContext(next: (...args: unknown[]) => unknown): () => unknown | Promise<() => unknown>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIConfigurationOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DIConfigurationOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\ndeclare global {\n namespace TsED {\n interface Context {}\n interface Configuration {\n scopes: {[key: string]: ProviderScope};\n /**\n * Define a list of resolvers (it can be an external DI).\n */\n resolvers: DIResolver[];\n /**\n * Define dependencies to build the provider\n */\n imports: TokenProvider[];\n\n
|
|
1
|
+
{"version":3,"file":"DIConfigurationOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DIConfigurationOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n interface Context {}\n interface Configuration extends Record<string, any> {\n scopes: {[key: string]: ProviderScope};\n /**\n * Define a list of resolvers (it can be an external DI).\n */\n resolvers: DIResolver[];\n /**\n * Define dependencies to build the provider\n */\n imports: TokenProvider[];\n /**\n * Mount controllers\n */\n mount: Record<string, TokenProvider[]>;\n }\n }\n}\n\nexport interface DIConfigurationOptions extends TsED.Configuration {}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DILoggerOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DILoggerOptions.ts"],"names":[],"mappings":"","sourcesContent":["export interface DILoggerOptions {\n /**\n * Enable debug mode. By default debug is false.\n */\n debug?: boolean;\n /**\n * Enable info mode. By default debug is false.\n */\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\";\n /**\n * Enable log performance tracker and disable log server.\n */\n perf?: boolean;\n /**\n * List of regexp to ignore log.\n */\n ignoreUrlPatterns?: (string | RegExp)[];\n /**\n * The number of space characters to use as white space in JSON output. Default is 2 (0 in production).\n */\n jsonIndentation?: number;\n /**\n * A function called for each incoming request to create a request id.\n * @returns {number}\n */\n reqIdBuilder?: (req: any) => string;\n /**\n * Disable routes table displayed in the logger. By default debug is `false`.\n */\n disableRoutesSummary?: boolean;\n /**\n * Disable bootstrap log displayed in the logger. By default debug is `false`.\n */\n disableBootstrapLog?: boolean;\n /**\n * Specify log format. Example: `%[%d{[yyyy-MM-dd hh:mm:ss,SSS}] %p%] %m`. See [@tsed/logger configuration](https://tsedio.github.io/logger/).\n */\n format?: string;\n /**\n * Specify the log stack size for the context.logger. When the stack.length is reach, the logger is flushed during the request.\n * Default size is set to 30.\n */\n maxStackSize?: number;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InjectableProperties.js","sourceRoot":"","sources":["../../../src/interfaces/InjectableProperties.ts"],"names":[],"mappings":"","sourcesContent":["import type {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {TokenProvider} from \"./TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {InvokeOptions} from \"./InvokeOptions\";\n\nexport interface InjectableProperty {\n propertyKey: string;\n}\n\nexport interface InjectablePropertyOptions extends InjectableProperty {\n bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;\n propertyType: string;\n useType?: TokenProvider;\n resolver: (injector: InjectorService, locals:
|
|
1
|
+
{"version":3,"file":"InjectableProperties.js","sourceRoot":"","sources":["../../../src/interfaces/InjectableProperties.ts"],"names":[],"mappings":"","sourcesContent":["import type {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {LocalsContainer} from \"../domain/LocalsContainer\";\nimport type {TokenProvider} from \"./TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {InvokeOptions} from \"./InvokeOptions\";\n\nexport interface InjectableProperty {\n propertyKey: string;\n}\n\nexport interface InjectablePropertyOptions extends InjectableProperty {\n bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;\n propertyType: string;\n useType?: TokenProvider;\n resolver: (injector: InjectorService, locals: LocalsContainer, options: Partial<InvokeOptions> & {options: any}) => () => any;\n options?: any;\n}\n\nexport interface InjectablePropertyValue extends InjectableProperty {\n bindingType: InjectablePropertyType.CONSTANT | InjectablePropertyType.VALUE;\n expression: string;\n defaultValue?: any;\n}\n\nexport interface InjectableProperties {\n [key: string]: InjectablePropertyOptions | InjectablePropertyValue;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InterceptorMethods.js","sourceRoot":"","sources":["../../../src/interfaces/InterceptorMethods.ts"],"names":[],"mappings":"","sourcesContent":["import type {InterceptorContext, InterceptorNext} from \"./InterceptorContext\";\n\nexport interface InterceptorMethods {\n intercept
|
|
1
|
+
{"version":3,"file":"InterceptorMethods.js","sourceRoot":"","sources":["../../../src/interfaces/InterceptorMethods.ts"],"names":[],"mappings":"","sourcesContent":["import type {InterceptorContext, InterceptorNext} from \"./InterceptorContext\";\n\nexport interface InterceptorMethods {\n intercept(context: InterceptorContext, next?: InterceptorNext): any;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenProvider.js","sourceRoot":"","sources":["../../../src/interfaces/TokenProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\n\nexport type TokenProvider = string | symbol | Type | Function | any;\n"]}
|
|
1
|
+
{"version":3,"file":"TokenProvider.js","sourceRoot":"","sources":["../../../src/interfaces/TokenProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\n\nexport type TokenProvider<T = any> = string | symbol | Type<T> | Function | any;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenRoute.js","sourceRoot":"","sources":["../../../src/interfaces/TokenRoute.ts"],"names":[],"mappings":"","sourcesContent":["import {TokenProvider} from \"./TokenProvider\";\n\nexport interface TokenRoute {\n token: TokenProvider;\n route: string;\n}\n"]}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _GlobalProviderRegistry_settings;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.GlobalProviders = exports.GlobalProviderRegistry = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
4
|
const core_1 = require("@tsed/core");
|
|
7
5
|
const Provider_1 = require("../domain/Provider");
|
|
8
6
|
const ProviderType_1 = require("../domain/ProviderType");
|
|
9
7
|
class GlobalProviderRegistry extends Map {
|
|
10
|
-
|
|
11
|
-
super(...arguments);
|
|
12
|
-
_GlobalProviderRegistry_settings.set(this, new Map());
|
|
13
|
-
}
|
|
8
|
+
#settings = new Map();
|
|
14
9
|
/**
|
|
15
10
|
* The get() method returns a specified element from a Map object.
|
|
16
11
|
* @param key Required. The key of the element to return from the Map object.
|
|
@@ -47,6 +42,7 @@ class GlobalProviderRegistry extends Map {
|
|
|
47
42
|
meta[key] = options[key];
|
|
48
43
|
});
|
|
49
44
|
this.set(target, meta);
|
|
45
|
+
return meta;
|
|
50
46
|
}
|
|
51
47
|
/**
|
|
52
48
|
* The delete() method removes the specified element from a Map object.
|
|
@@ -62,12 +58,12 @@ class GlobalProviderRegistry extends Map {
|
|
|
62
58
|
...options,
|
|
63
59
|
model
|
|
64
60
|
});
|
|
65
|
-
|
|
61
|
+
this.#settings.set(type, options);
|
|
66
62
|
return this;
|
|
67
63
|
}
|
|
68
64
|
onInvoke(provider, locals, options) {
|
|
69
|
-
const settings =
|
|
70
|
-
if (settings
|
|
65
|
+
const settings = this.#settings.get(provider.type);
|
|
66
|
+
if (settings?.onInvoke) {
|
|
71
67
|
settings.onInvoke(provider, locals, options);
|
|
72
68
|
}
|
|
73
69
|
}
|
|
@@ -82,7 +78,7 @@ class GlobalProviderRegistry extends Map {
|
|
|
82
78
|
type = provider.type;
|
|
83
79
|
}
|
|
84
80
|
}
|
|
85
|
-
return (
|
|
81
|
+
return (this.#settings.get(type) || {
|
|
86
82
|
model: Provider_1.Provider
|
|
87
83
|
});
|
|
88
84
|
}
|
|
@@ -106,7 +102,7 @@ class GlobalProviderRegistry extends Map {
|
|
|
106
102
|
createIfNotExists(key, options) {
|
|
107
103
|
const type = options.type || ProviderType_1.ProviderType.PROVIDER;
|
|
108
104
|
if (!this.has(key)) {
|
|
109
|
-
const { model = Provider_1.Provider } =
|
|
105
|
+
const { model = Provider_1.Provider } = this.#settings.get(type) || {};
|
|
110
106
|
const item = new model(key, options);
|
|
111
107
|
this.set(key, item);
|
|
112
108
|
}
|
|
@@ -114,7 +110,6 @@ class GlobalProviderRegistry extends Map {
|
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
112
|
exports.GlobalProviderRegistry = GlobalProviderRegistry;
|
|
117
|
-
_GlobalProviderRegistry_settings = new WeakMap();
|
|
118
113
|
/**
|
|
119
114
|
*
|
|
120
115
|
* @type {GlobalProviders}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":";;;AAAA,qCAAkD;AAElD,iDAA4C;AAC5C,yDAAoD;AAOpD,MAAa,sBAAuB,SAAQ,GAA4B;IACtE,SAAS,GAAkC,IAAI,GAAG,EAAE,CAAC;IAErD;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAA,uBAAgB,EAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAA,uBAAgB,EAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAkB,EAAE,QAAkB;QACxC,KAAK,CAAC,GAAG,CAAC,IAAA,uBAAgB,EAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;QAE3C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAqB,EAAE,OAA8B;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAErD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnC,IAAI,CAAC,GAAG,CAAC,GAAI,OAAe,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,IA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F,CAAC;IACJ,CAAC;IAED,gBAAgB,CAAC,IAAY;QAC3B,OAAO,CAAC,QAA4B,EAAE,QAAc,EAAQ,EAAE;YAC5D,uBAAuB;YACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;gBACrB,QAAQ,GAAG;oBACT,OAAO,EAAE,QAAQ;iBAClB,CAAC;aACH;YAED,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAC,QAAQ,EAAC,EAAE,QAAQ,EAAE,EAAC,IAAI,EAAC,CAAC,CAAC;YACvD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACO,iBAAiB,CAAC,GAAkB,EAAE,OAA8B;QAC5E,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,2BAAY,CAAC,QAAQ,CAAC;QAEnD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,MAAM,EAAC,KAAK,GAAG,mBAAQ,EAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAE1D,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;SACrB;QAED,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;IACxB,CAAC;CACF;AAlID,wDAkIC;AAED;;;GAGG;AACH,0CAA0C;AAC7B,QAAA,eAAe,GAAG,IAAI,sBAAsB,EAAE,CAAC","sourcesContent":["import {getClassOrSymbol, Type} from \"@tsed/core\";\nimport type {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {RegistrySettings} from \"../interfaces/RegistrySettings\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\n\nexport class GlobalProviderRegistry extends Map<TokenProvider, Provider> {\n #settings: Map<string, RegistrySettings> = new Map();\n\n /**\n * The get() method returns a specified element from a Map object.\n * @param key Required. The key of the element to return from the 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 */\n get(key: TokenProvider): Provider | undefined {\n return super.get(getClassOrSymbol(key));\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @param key\n * @returns {boolean}\n */\n has(key: TokenProvider): boolean {\n return super.has(getClassOrSymbol(key));\n }\n\n /**\n * The set() method adds or updates an element with a specified key and value to a Map object.\n * @param key Required. The key of the element to add to the Map object.\n * @param metadata Required. The value of the element to add to the Map object.\n */\n set(key: TokenProvider, metadata: Provider): this {\n super.set(getClassOrSymbol(key), metadata);\n\n return this;\n }\n\n /**\n *\n * @param target\n * @param options\n */\n merge(target: TokenProvider, options: Partial<ProviderOpts>) {\n const meta = this.createIfNotExists(target, options);\n\n Object.keys(options).forEach((key) => {\n meta[key] = (options as any)[key];\n });\n\n this.set(target, meta);\n\n return meta;\n }\n\n /**\n * The delete() method removes the specified element from a Map object.\n * @param key Required. The key of the element to remove from the Map object.\n * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\n */\n delete(key: TokenProvider): boolean {\n return super.delete(getClassOrSymbol(key));\n }\n\n createRegistry(type: string, model: Type<Provider>, options: Partial<RegistrySettings> = {}) {\n const defaultOptions = this.getRegistrySettings(type);\n\n options = Object.assign(defaultOptions, {\n ...options,\n model\n });\n\n this.#settings.set(type, options);\n\n return this;\n }\n\n onInvoke(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {injector: InjectorService}) {\n const settings = this.#settings.get(provider.type);\n\n if (settings?.onInvoke) {\n settings.onInvoke(provider, locals, options);\n }\n }\n\n getRegistrySettings(target: string | TokenProvider): RegistrySettings {\n let type: string = \"provider\";\n\n if (typeof target === \"string\") {\n type = target;\n } else {\n const provider = this.get(target);\n if (provider) {\n type = provider.type;\n }\n }\n\n return (\n this.#settings.get(type) || {\n model: Provider\n }\n );\n }\n\n createRegisterFn(type: string) {\n return (provider: any | ProviderOpts, instance?: any): void => {\n // istanbul ignore next\n if (!provider.provide) {\n provider = {\n provide: provider\n };\n }\n\n provider = Object.assign({instance}, provider, {type});\n this.merge(provider.provide, provider);\n };\n }\n\n /**\n *\n * @param key\n * @param options\n */\n protected createIfNotExists(key: TokenProvider, options: Partial<ProviderOpts>): Provider {\n const type = options.type || ProviderType.PROVIDER;\n\n if (!this.has(key)) {\n const {model = Provider} = this.#settings.get(type) || {};\n\n const item = new model(key, options);\n\n this.set(key, item);\n }\n\n return this.get(key)!;\n }\n}\n\n/**\n *\n * @type {GlobalProviders}\n */\n// tslint:disable-next-line: variable-name\nexport const GlobalProviders = new GlobalProviderRegistry();\n"]}
|
|
@@ -17,7 +17,7 @@ function registerProvider(provider) {
|
|
|
17
17
|
if (!provider.provide) {
|
|
18
18
|
throw new Error("Provider.provide is required");
|
|
19
19
|
}
|
|
20
|
-
GlobalProviders_1.GlobalProviders.merge(provider.provide, provider);
|
|
20
|
+
return GlobalProviders_1.GlobalProviders.merge(provider.provide, provider);
|
|
21
21
|
}
|
|
22
22
|
exports.registerProvider = registerProvider;
|
|
23
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderRegistry.js","sourceRoot":"","sources":["../../../src/registries/ProviderRegistry.ts"],"names":[],"mappings":";;;AAAA,iDAA4C;AAC5C,2DAAsD;AACtD,yDAAoD;AAEpD,uDAAkD;AAElD;;GAEG;AACH,iCAAe,CAAC,cAAc,CAAC,2BAAY,CAAC,UAAU,EAAE,mBAAQ,CAAC,CAAC;AAElE;;;GAGG;AACH,SAAgB,gBAAgB,CAAa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ACU,QAAA,kBAAkB,GAAG,iCAAe,CAAC,gBAAgB,CAAC,2BAAY,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import {Provider} from \"../domain/Provider\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport type {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {GlobalProviders} from \"./GlobalProviders\";\n\n/**\n *\n */\nGlobalProviders.createRegistry(ProviderType.CONTROLLER, Provider);\n\n/**\n * Register a provider configuration.\n * @param {ProviderOpts<any>} provider\n */\nexport function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>) {\n if (!provider.provide) {\n throw new Error(\"Provider.provide is required\");\n }\n\n return GlobalProviders.merge(provider.provide, provider);\n}\n\n/**\n * Add a new value in the `ProviderRegistry`.\n *\n * #### Example with symbol definition\n *\n *\n * ```typescript\n * import {registerValue, InjectorService} from \"@tsed/di\";\n *\n * const MyValue = Symbol.from(\"MyValue\")\n *\n * registerValue({token: MyValue, useValue: \"myValue\"});\n *\n * @Service()\n * export class OtherService {\n * constructor(@Inject(MyValue) myValue: string){\n * console.log(myValue); /// \"myValue\"\n * }\n * }\n * ```\n */\nexport const registerValue = (provider: any | ProviderOpts<any>, value?: any): void => {\n if (!provider.provide) {\n provider = {\n provide: provider\n };\n }\n\n provider = Object.assign(\n {\n scope: ProviderScope.SINGLETON,\n useValue: value\n },\n provider,\n {type: ProviderType.VALUE}\n );\n GlobalProviders.merge(provider.provide, provider);\n};\n\n/**\n * Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.\n *\n * #### Example\n *\n * ```typescript\n * import {registerController, InjectorService} from \"@tsed/di\";\n *\n * export default class MyController {\n * constructor(){}\n * transform() {\n * return \"test\";\n * }\n * }\n *\n * registerController({provide: MyController});\n * // or\n * registerController(MyController);\n *\n * const injector = new InjectorService();\n * injector.load();\n *\n * const myController = injector.get<MyController>(MyController);\n * myController.getFoo(); // test\n * ```\n *\n * @param provider Provider configuration.\n */\nexport const registerController = GlobalProviders.createRegisterFn(ProviderType.CONTROLLER);\n"]}
|
|
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DIConfiguration = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
class DIConfiguration {
|
|
6
|
+
default = new Map();
|
|
7
|
+
map = new Map();
|
|
6
8
|
constructor(initialProps = {}) {
|
|
7
|
-
this.default = new Map();
|
|
8
|
-
this.map = new Map();
|
|
9
9
|
Object.entries({
|
|
10
10
|
scopes: {},
|
|
11
11
|
resolvers: [],
|
|
12
12
|
imports: [],
|
|
13
|
+
routes: [],
|
|
14
|
+
logger: {},
|
|
13
15
|
...initialProps
|
|
14
16
|
}).forEach(([key, value]) => {
|
|
15
17
|
this.default.set(key, value);
|
|
@@ -20,23 +22,60 @@ class DIConfiguration {
|
|
|
20
22
|
}
|
|
21
23
|
});
|
|
22
24
|
}
|
|
25
|
+
get version() {
|
|
26
|
+
return this.get("version");
|
|
27
|
+
}
|
|
28
|
+
set version(v) {
|
|
29
|
+
this.map.set("version", v);
|
|
30
|
+
}
|
|
31
|
+
get rootDir() {
|
|
32
|
+
return this.get("rootDir");
|
|
33
|
+
}
|
|
34
|
+
set rootDir(value) {
|
|
35
|
+
this.map.set("rootDir", value);
|
|
36
|
+
}
|
|
37
|
+
get env() {
|
|
38
|
+
return this.map.get("env");
|
|
39
|
+
}
|
|
40
|
+
set env(value) {
|
|
41
|
+
this.map.set("env", value);
|
|
42
|
+
}
|
|
23
43
|
get scopes() {
|
|
24
|
-
return this.
|
|
44
|
+
return this.map.get("scopes");
|
|
25
45
|
}
|
|
26
46
|
set scopes(value) {
|
|
27
|
-
this.
|
|
47
|
+
this.map.set("scopes", value);
|
|
28
48
|
}
|
|
29
49
|
get resolvers() {
|
|
30
50
|
return this.getRaw("resolvers");
|
|
31
51
|
}
|
|
32
52
|
set resolvers(resolvers) {
|
|
33
|
-
this.
|
|
53
|
+
this.map.set("resolvers", resolvers);
|
|
34
54
|
}
|
|
35
55
|
get imports() {
|
|
36
|
-
return this.
|
|
56
|
+
return this.get("imports");
|
|
37
57
|
}
|
|
38
58
|
set imports(imports) {
|
|
39
|
-
this.
|
|
59
|
+
this.map.set("imports", imports);
|
|
60
|
+
}
|
|
61
|
+
get routes() {
|
|
62
|
+
return this.get("routes");
|
|
63
|
+
}
|
|
64
|
+
set routes(routes) {
|
|
65
|
+
this.map.set("routes", routes);
|
|
66
|
+
}
|
|
67
|
+
get logger() {
|
|
68
|
+
return this.get("logger");
|
|
69
|
+
}
|
|
70
|
+
set logger(value) {
|
|
71
|
+
const logger = { ...this.logger, ...value };
|
|
72
|
+
this.map.set("logger", logger);
|
|
73
|
+
}
|
|
74
|
+
get debug() {
|
|
75
|
+
return this.logger.level === "debug";
|
|
76
|
+
}
|
|
77
|
+
set debug(debug) {
|
|
78
|
+
this.logger = { ...this.logger, level: debug ? "debug" : "info" };
|
|
40
79
|
}
|
|
41
80
|
/**
|
|
42
81
|
*
|
|
@@ -55,11 +94,17 @@ class DIConfiguration {
|
|
|
55
94
|
*/
|
|
56
95
|
set(propertyKey, value) {
|
|
57
96
|
if (typeof propertyKey === "string") {
|
|
58
|
-
|
|
97
|
+
if (propertyKey in this) {
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
this[propertyKey] = value;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.setRaw(propertyKey, value);
|
|
103
|
+
}
|
|
59
104
|
}
|
|
60
105
|
else {
|
|
61
106
|
Object.entries(propertyKey).forEach(([key, value]) => {
|
|
62
|
-
this
|
|
107
|
+
this.set(key, value);
|
|
63
108
|
});
|
|
64
109
|
}
|
|
65
110
|
return this;
|
|
@@ -75,7 +120,7 @@ class DIConfiguration {
|
|
|
75
120
|
* @returns {undefined|any}
|
|
76
121
|
*/
|
|
77
122
|
get(propertyKey, defaultValue) {
|
|
78
|
-
return this.
|
|
123
|
+
return this.getRaw(propertyKey, defaultValue);
|
|
79
124
|
}
|
|
80
125
|
getRaw(propertyKey, defaultValue) {
|
|
81
126
|
const value = (0, core_1.getValue)(this.map, propertyKey);
|
|
@@ -84,45 +129,13 @@ class DIConfiguration {
|
|
|
84
129
|
}
|
|
85
130
|
return (0, core_1.getValue)(this.default, propertyKey, defaultValue);
|
|
86
131
|
}
|
|
87
|
-
merge(obj) {
|
|
88
|
-
Object.entries(obj).forEach(([key, value]) => {
|
|
89
|
-
const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);
|
|
90
|
-
const originalValue = this.get(key);
|
|
91
|
-
value = (0, core_1.deepMerge)(value, originalValue);
|
|
92
|
-
if (descriptor && !["default", "set", "map", "get"].includes(key)) {
|
|
93
|
-
this[key] = value;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
132
|
/**
|
|
98
133
|
*
|
|
99
134
|
* @param value
|
|
100
135
|
* @returns {any}
|
|
101
136
|
*/
|
|
102
137
|
resolve(value) {
|
|
103
|
-
|
|
104
|
-
if (![Array, Object].includes((0, core_1.classOf)(value))) {
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
return Object.entries(value).reduce((o, [k, v]) => {
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
o[k] = this.resolve(v);
|
|
110
|
-
return o;
|
|
111
|
-
}, Array.isArray(value) ? [] : {});
|
|
112
|
-
}
|
|
113
|
-
if (typeof value === "string") {
|
|
114
|
-
const replacer = (match, key) => (0, core_1.getValue)(this.map, key);
|
|
115
|
-
return value
|
|
116
|
-
.replace(/\${([\w.]+)}/gi, replacer)
|
|
117
|
-
.replace(/<([\w.]+)>/gi, replacer)
|
|
118
|
-
.replace(/{{([\w.]+)}}/gi, replacer);
|
|
119
|
-
}
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
build() {
|
|
123
|
-
this.forEach((value, key) => this.map.set(key, this.resolve(value)));
|
|
124
|
-
this.set = this.setRaw;
|
|
125
|
-
this.get = this.getRaw = (propertyKey, defaultValue) => (0, core_1.getValue)(this.map, propertyKey, defaultValue);
|
|
138
|
+
return value.replace("${rootDir}", this.rootDir);
|
|
126
139
|
}
|
|
127
140
|
}
|
|
128
141
|
exports.DIConfiguration = DIConfiguration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIConfiguration.js","sourceRoot":"","sources":["../../../src/services/DIConfiguration.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"DIConfiguration.js","sourceRoot":"","sources":["../../../src/services/DIConfiguration.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAO7E,MAAa,eAAe;IACjB,OAAO,GAAqB,IAAI,GAAG,EAAE,CAAC;IACrC,GAAG,GAAqB,IAAI,GAAG,EAAE,CAAC;IAE5C,YAAY,YAAY,GAAG,EAAE;QAC3B,MAAM,CAAC,OAAO,CAAC;YACb,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;YACV,GAAG,YAAY;SAChB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,IAAA,sBAAe,EAAkB,IAAI,EAAE;YAC5C,OAAO,CAAC,MAAM;gBACZ,OAAO,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1D,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,OAAO,CAAC,CAAS;QACnB,IAAI,CAAC,G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CAAC;aAC3B;iBAAM;gBACL,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;aACjC;SACF;aAAM;YACL,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBACnD,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,WAAmB,EAAE,KAAU;QACpC,IAAA,eAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;QAEvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAU,WAAmB,EAAE,YAAgB;QAChD,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAChD,CAAC;IAES,MAAM,CAAC,WAAmB,EAAE,YAAkB;QACtD,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAE9C,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAA,eAAQ,EAAC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAU;QAChB,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;CACF;AAnKD,0CAmKC","sourcesContent":["import {classOf, Env, getValue, proxyDelegation, setValue} from \"@tsed/core\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {DILoggerOptions} from \"../interfaces/DILoggerOptions\";\nimport type {DIResolver} from \"../interfaces/DIResolver\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\nimport type {TokenRoute} from \"../interfaces/TokenRoute\";\n\nexport class DIConfiguration {\n readonly default: Map<string, any> = new Map();\n protected map: Map<string, any> = new Map();\n\n constructor(initialProps = {}) {\n Object.entries({\n scopes: {},\n resolvers: [],\n imports: [],\n routes: [],\n logger: {},\n ...initialProps\n }).forEach(([key, value]) => {\n this.default.set(key, value);\n });\n\n return proxyDelegation<DIConfiguration>(this, {\n ownKeys(target) {\n return [...target.default.keys(), ...target.map.keys()];\n }\n });\n }\n\n get version() {\n return this.get(\"version\");\n }\n\n set version(v: string) {\n this.map.set(\"version\", v);\n }\n\n get rootDir() {\n return this.get(\"rootDir\");\n }\n\n set rootDir(value: string) {\n this.map.set(\"rootDir\", value);\n }\n\n get env(): Env {\n return this.map.get(\"env\");\n }\n\n set env(value: Env) {\n this.map.set(\"env\", value);\n }\n\n get scopes(): Record<string, ProviderScope> {\n return this.map.get(\"scopes\");\n }\n\n set scopes(value: Record<string, ProviderScope>) {\n this.map.set(\"scopes\", value);\n }\n\n get resolvers(): DIResolver[] {\n return this.getRaw(\"resolvers\");\n }\n\n set resolvers(resolvers: DIResolver[]) {\n this.map.set(\"resolvers\", resolvers);\n }\n\n get imports(): TokenProvider[] {\n return this.get(\"imports\");\n }\n\n set imports(imports: TokenProvider[]) {\n this.map.set(\"imports\", imports);\n }\n\n get routes(): TokenRoute[] {\n return this.get(\"routes\");\n }\n\n set routes(routes: TokenRoute[]) {\n this.map.set(\"routes\", routes);\n }\n\n get logger(): Partial<DILoggerOptions> {\n return this.get(\"logger\");\n }\n\n set logger(value: Partial<DILoggerOptions>) {\n const logger = {...this.logger, ...value};\n this.map.set(\"logger\", logger);\n }\n\n get debug(): boolean {\n return this.logger.level === \"debug\";\n }\n\n set debug(debug: boolean) {\n this.logger = {...this.logger, level: debug ? \"debug\" : \"info\"};\n }\n\n /**\n *\n * @param callbackfn\n * @param thisArg\n */\n forEach(callbackfn: (value: any, index: string, map: Map<string, any>) => void, thisArg?: any) {\n return new Set([...Array.from(this.default.keys()), ...Array.from(this.map.keys())]).forEach((key) => {\n callbackfn(this.getRaw(key), key, this.map);\n }, thisArg);\n }\n\n /**\n *\n * @param propertyKey\n * @param value\n */\n set(propertyKey: string | Partial<TsED.Configuration>, value?: any): this {\n if (typeof propertyKey === \"string\") {\n if (propertyKey in this) {\n // @ts-ignore\n this[propertyKey] = value;\n } else {\n this.setRaw(propertyKey, value);\n }\n } else {\n Object.entries(propertyKey).forEach(([key, value]) => {\n this.set(key, value);\n });\n }\n\n return this;\n }\n\n setRaw(propertyKey: string, value: any) {\n setValue(this.map, propertyKey, value);\n\n return this;\n }\n\n /**\n *\n * @param propertyKey\n * @param defaultValue\n * @returns {undefined|any}\n */\n get<T = any>(propertyKey: string, defaultValue?: T): T {\n return this.getRaw(propertyKey, defaultValue);\n }\n\n protected getRaw(propertyKey: string, defaultValue?: any): any {\n const value = getValue(this.map, propertyKey);\n\n if (value !== undefined) {\n return value;\n }\n\n return getValue(this.default, propertyKey, defaultValue);\n }\n\n /**\n *\n * @param value\n * @returns {any}\n */\n resolve(value: any) {\n return value.replace(\"${rootDir}\", this.rootDir);\n }\n}\n"]}
|
|
@@ -5,13 +5,14 @@ const core_1 = require("@tsed/core");
|
|
|
5
5
|
const logger_1 = require("@tsed/logger");
|
|
6
6
|
const createContainer_1 = require("../utils/createContainer");
|
|
7
7
|
const LocalsContainer_1 = require("../domain/LocalsContainer");
|
|
8
|
-
const
|
|
8
|
+
const setLoggerConfiguration_1 = require("../utils/setLoggerConfiguration");
|
|
9
9
|
const InjectorService_1 = require("./InjectorService");
|
|
10
10
|
const DIContext_1 = require("../domain/DIContext");
|
|
11
11
|
/**
|
|
12
12
|
* Tool to run test with lightweight DI sandbox.
|
|
13
13
|
*/
|
|
14
14
|
class DITest {
|
|
15
|
+
static _injector = null;
|
|
15
16
|
static get injector() {
|
|
16
17
|
if (DITest._injector) {
|
|
17
18
|
return DITest._injector;
|
|
@@ -32,12 +33,11 @@ class DITest {
|
|
|
32
33
|
}
|
|
33
34
|
static async create(settings = {}) {
|
|
34
35
|
DITest.injector = DITest.createInjector(settings);
|
|
35
|
-
await
|
|
36
|
+
await DITest.createContainer(settings);
|
|
36
37
|
}
|
|
37
38
|
static async createContainer(settings = {}) {
|
|
38
|
-
var _a;
|
|
39
39
|
const container = (0, createContainer_1.createContainer)();
|
|
40
|
-
|
|
40
|
+
settings.imports?.forEach(({ token, use }) => {
|
|
41
41
|
container.addProvider(token, {
|
|
42
42
|
useValue: use
|
|
43
43
|
});
|
|
@@ -52,7 +52,7 @@ class DITest {
|
|
|
52
52
|
injector.logger = logger_1.$log;
|
|
53
53
|
// @ts-ignore
|
|
54
54
|
injector.settings.set(DITest.configure(settings));
|
|
55
|
-
(0,
|
|
55
|
+
(0, setLoggerConfiguration_1.setLoggerConfiguration)(injector);
|
|
56
56
|
return injector;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
@@ -112,5 +112,4 @@ class DITest {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
exports.DITest = DITest;
|
|
115
|
-
DITest._injector = null;
|
|
116
115
|
//# sourceMappingURL=DITest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DITest.js","sourceRoot":"","sources":["../../../src/services/DITest.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,yCAAkC;AAClC,8DAAyD;AACzD,+DAA0D;AAG1D,
|
|
1
|
+
{"version":3,"file":"DITest.js","sourceRoot":"","sources":["../../../src/services/DITest.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,yCAAkC;AAClC,8DAAyD;AACzD,+DAA0D;AAG1D,4EAAuE;AAEvE,uDAAkD;AAClD,mDAA8C;AAW9C;;GAEG;AACH,MAAa,MAAM;IACP,MAAM,CAAC,SAAS,GAA2B,IAAI,CAAC;IAE1D,MAAM,KAAK,QAAQ;QACjB,IAAI,MAAM,CAAC,SAAS,EAAE;YACpB,OAAO,MAAM,CAAC,SAAU,C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;YACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;SAC/B,CAAC,CAAC;IACL,CAAC;IAES,MAAM,CAAC,SAAS,CAAC,WAAwC,EAAE;QACnE,OAAO;YACL,GAAG,QAAQ;YACX,GAAG,EAAE,IAAA,eAAQ,EAAC,QAAQ,EAAE,KAAK,EAAE,UAAG,CAAC,IAAI,CAAC;YACxC,MAAM,EAAE;gBACN,GAAG,IAAA,eAAQ,EAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC;gBACnC,KAAK,EAAE,IAAA,eAAQ,EAAC,QAAQ,EAAE,cAAc,EAAE,KAAK,CAAC;aACjD;SACF,CAAC;IACJ,CAAC;;AA1HH,wBA2HC","sourcesContent":["import {Env, getValue} from \"@tsed/core\";\nimport {$log} from \"@tsed/logger\";\nimport {createContainer} from \"../utils/createContainer\";\nimport {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {OnInit} from \"../interfaces/OnInit\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {setLoggerConfiguration} from \"../utils/setLoggerConfiguration\";\nimport {setLoggerLevel} from \"../utils/setLoggerLevel\";\nimport {InjectorService} from \"./InjectorService\";\nimport {DIContext} from \"../domain/DIContext\";\n\nexport interface DITestInvokeOptions {\n token?: TokenProvider;\n use: any;\n}\n\nexport interface DITestOptions extends Partial<TsED.Configuration> {\n imports?: DITestInvokeOptions[];\n}\n\n/**\n * Tool to run test with lightweight DI sandbox.\n */\nexport class DITest {\n protected static _injector: InjectorService | null = null;\n\n static get injector(): InjectorService {\n if (DITest._injector) {\n return DITest._injector!;\n }\n\n /* istanbul ignore next */\n throw new Error(\n \"PlatformTest.injector is not initialized. Use PlatformTest.create(): Promise before PlatformTest.invoke() or PlatformTest.injector.\\n\" +\n \"Example:\\n\" +\n \"before(async () => {\\n\" +\n \" await PlatformTest.create()\\n\" +\n \" await PlatformTest.invoke(MyService, [])\\n\" +\n \"})\"\n );\n }\n\n static set injector(injector: InjectorService) {\n DITest._injector = injector;\n }\n\n static hasInjector() {\n return !!DITest._injector;\n }\n\n static async create(settings: DITestOptions = {}) {\n DITest.injector = DITest.createInjector(settings);\n\n await DITest.createContainer(settings);\n }\n\n static async createContainer(settings: DITestOptions = {}) {\n const container = createContainer();\n\n settings.imports?.forEach(({token, use}) => {\n container.addProvider(token, {\n useValue: use\n });\n });\n\n await DITest.injector.load(container);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n const injector = new InjectorService();\n injector.logger = $log;\n\n // @ts-ignore\n injector.settings.set(DITest.configure(settings));\n\n setLoggerConfiguration(injector);\n\n return injector;\n }\n\n /**\n * Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.\n */\n static async reset() {\n if (DITest.hasInjector()) {\n await DITest.injector.destroy();\n DITest._injector = null;\n }\n }\n\n /**\n * Invoke a provider and return a fresh instance\n * @param target\n * @param providers\n */\n static invoke<T = any>(target: TokenProvider, providers: DITestInvokeOptions[] = []): T | Promise<T> {\n const locals = new LocalsContainer();\n providers.forEach((p) => {\n locals.set(p.token, p.use);\n });\n\n locals.set(InjectorService, DITest.injector);\n\n const instance: OnInit = DITest.injector.invoke(target, locals, {rebuild: true});\n\n if (instance && instance.$onInit) {\n // await instance.$onInit();\n const result = instance.$onInit();\n if (result instanceof Promise) {\n return result.then(() => instance as any);\n }\n }\n\n return instance as any;\n }\n\n /**\n * Return the instance from injector registry\n * @param target\n * @param options\n */\n static get<T = any>(target: TokenProvider, options: any = {}): T {\n return DITest.injector.get<T>(target, options)!;\n }\n\n static createDIContext() {\n return new DIContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger\n });\n }\n\n protected static configure(settings: Partial<TsED.Configuration> = {}): Partial<TsED.Configuration> {\n return {\n ...settings,\n env: getValue(settings, \"env\", Env.TEST),\n logger: {\n ...getValue(settings, \"logger\", {}),\n level: getValue(settings, \"logger.level\", \"off\")\n }\n };\n }\n}\n"]}
|