@tsed/di 6.114.5-rc.1 → 6.114.5
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/lib/cjs/constants/constants.js +3 -1
- package/lib/cjs/constants/constants.js.map +1 -1
- package/lib/cjs/decorators/constant.js +9 -8
- package/lib/cjs/decorators/constant.js.map +1 -1
- package/lib/cjs/decorators/inject.js +28 -26
- package/lib/cjs/decorators/inject.js.map +1 -1
- package/lib/cjs/decorators/intercept.js +10 -30
- package/lib/cjs/decorators/intercept.js.map +1 -1
- package/lib/cjs/decorators/lazyInject.js +14 -13
- package/lib/cjs/decorators/lazyInject.js.map +1 -1
- package/lib/cjs/decorators/useOpts.js +5 -1
- package/lib/cjs/decorators/useOpts.js.map +1 -1
- package/lib/cjs/decorators/value.js +9 -9
- package/lib/cjs/decorators/value.js.map +1 -1
- package/lib/cjs/domain/DIContext.js +1 -1
- package/lib/cjs/domain/DIContext.js.map +1 -1
- package/lib/cjs/index.js +1 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/{DILoggerOptions.js → InjectableProperties.js} +1 -1
- package/lib/cjs/interfaces/InjectableProperties.js.map +1 -0
- package/lib/cjs/services/DIConfiguration.js +43 -49
- package/lib/cjs/services/DIConfiguration.js.map +1 -1
- package/lib/cjs/services/DITest.js +2 -2
- package/lib/cjs/services/DITest.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +133 -19
- package/lib/cjs/services/InjectorService.js.map +1 -1
- package/lib/cjs/utils/setLoggerLevel.js +2 -1
- package/lib/cjs/utils/setLoggerLevel.js.map +1 -1
- package/lib/esm/constants/constants.js +2 -0
- package/lib/esm/constants/constants.js.map +1 -1
- package/lib/esm/decorators/constant.js +10 -9
- package/lib/esm/decorators/constant.js.map +1 -1
- package/lib/esm/decorators/inject.js +30 -28
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/decorators/intercept.js +11 -31
- package/lib/esm/decorators/intercept.js.map +1 -1
- package/lib/esm/decorators/lazyInject.js +14 -13
- package/lib/esm/decorators/lazyInject.js.map +1 -1
- package/lib/esm/decorators/useOpts.js +6 -2
- package/lib/esm/decorators/useOpts.js.map +1 -1
- package/lib/esm/decorators/value.js +10 -10
- package/lib/esm/decorators/value.js.map +1 -1
- package/lib/esm/domain/DIContext.js +1 -1
- package/lib/esm/domain/DIContext.js.map +1 -1
- package/lib/esm/index.js +1 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/InjectableProperties.js +2 -0
- package/lib/esm/interfaces/InjectableProperties.js.map +1 -0
- package/lib/esm/services/DIConfiguration.js +44 -50
- package/lib/esm/services/DIConfiguration.js.map +1 -1
- package/lib/esm/services/DITest.js +2 -2
- package/lib/esm/services/DITest.js.map +1 -1
- package/lib/esm/services/InjectorService.js +135 -21
- package/lib/esm/services/InjectorService.js.map +1 -1
- package/lib/esm/utils/setLoggerLevel.js +2 -1
- package/lib/esm/utils/setLoggerLevel.js.map +1 -1
- package/lib/types/constants/constants.d.ts +2 -0
- package/lib/types/decorators/inject.d.ts +2 -5
- package/lib/types/index.d.ts +1 -3
- package/lib/types/interfaces/InjectableProperties.d.ts +24 -0
- package/lib/types/services/DIConfiguration.d.ts +12 -17
- package/lib/types/services/InjectorService.d.ts +50 -5
- package/lib/types/utils/setLoggerLevel.d.ts +1 -1
- package/package.json +6 -9
- package/lib/cjs/interfaces/DILoggerOptions.js.map +0 -1
- package/lib/cjs/utils/setLoggerConfiguration.js +0 -11
- package/lib/cjs/utils/setLoggerConfiguration.js.map +0 -1
- package/lib/cjs/utils/setLoggerFormat.js +0 -33
- package/lib/cjs/utils/setLoggerFormat.js.map +0 -1
- package/lib/esm/interfaces/DILoggerOptions.js +0 -2
- package/lib/esm/interfaces/DILoggerOptions.js.map +0 -1
- package/lib/esm/utils/setLoggerConfiguration.js +0 -7
- package/lib/esm/utils/setLoggerConfiguration.js.map +0 -1
- package/lib/esm/utils/setLoggerFormat.js +0 -29
- package/lib/esm/utils/setLoggerFormat.js.map +0 -1
- package/lib/types/interfaces/DILoggerOptions.d.ts +0 -44
- package/lib/types/utils/setLoggerConfiguration.d.ts +0 -2
- package/lib/types/utils/setLoggerFormat.d.ts +0 -6
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DI_PARAM_OPTIONS = void 0;
|
|
3
|
+
exports.DI_PARAM_OPTIONS = exports.DI_PARAMS = exports.INJECTABLE_PROP = void 0;
|
|
4
|
+
exports.INJECTABLE_PROP = "DI:INJECTABLE_PROP";
|
|
5
|
+
exports.DI_PARAMS = "DI:PARAMS";
|
|
4
6
|
exports.DI_PARAM_OPTIONS = "DI:PARAM:OPTIONS";
|
|
5
7
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,kBAAkB,CAAC","sourcesContent":["export const DI_PARAM_OPTIONS = \"DI:PARAM:OPTIONS\";\n"]}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,oBAAoB,CAAC;AACvC,QAAA,SAAS,GAAG,WAAW,CAAC;AACxB,QAAA,gBAAgB,GAAG,kBAAkB,CAAC","sourcesContent":["export const INJECTABLE_PROP = \"DI:INJECTABLE_PROP\";\nexport const DI_PARAMS = \"DI:PARAMS\";\nexport const DI_PARAM_OPTIONS = \"DI:PARAM:OPTIONS\";\n"]}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Constant = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
|
+
const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
5
7
|
/**
|
|
6
8
|
* Return value from Configuration.
|
|
7
9
|
*
|
|
@@ -39,14 +41,13 @@ const core_1 = require("@tsed/core");
|
|
|
39
41
|
*/
|
|
40
42
|
function Constant(expression, defaultValue) {
|
|
41
43
|
return (target, propertyKey) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
configurable: true
|
|
44
|
+
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
45
|
+
[propertyKey]: {
|
|
46
|
+
bindingType: InjectablePropertyType_1.InjectablePropertyType.CONSTANT,
|
|
47
|
+
propertyKey,
|
|
48
|
+
expression,
|
|
49
|
+
defaultValue
|
|
50
|
+
}
|
|
50
51
|
});
|
|
51
52
|
};
|
|
52
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/decorators/constant.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/decorators/constant.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,sDAAuD;AAEvD,6EAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,QAAQ,CAAC,UAAkB,EAAE,YAAkB;IAC7D,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,QAAQ;gBAC5C,WAAW;gBACX,UAAU;gBACV,YAAY;aACb;SACsB,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC;AAXD,4BAWC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/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 {string} expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Constant(expression: string, defaultValue?: any): any {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.CONSTANT,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n"]}
|
|
@@ -4,23 +4,12 @@ exports.InjectContext = exports.Inject = exports.injectProperty = void 0;
|
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
const constants_1 = require("../constants/constants");
|
|
6
6
|
const runInContext_1 = require("../utils/runInContext");
|
|
7
|
-
function injectProperty(target, propertyKey,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!this[key]) {
|
|
14
|
-
const fn = resolver(this.$$injector, this.$$locals, this.$$invokeOptions);
|
|
15
|
-
Object.defineProperty(this, key, {
|
|
16
|
-
configurable: true,
|
|
17
|
-
enumerable: false,
|
|
18
|
-
get() {
|
|
19
|
-
return fn;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return this[key]();
|
|
7
|
+
function injectProperty(target, propertyKey, options) {
|
|
8
|
+
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
9
|
+
[propertyKey]: {
|
|
10
|
+
bindingType: core_1.DecoratorTypes.PROP,
|
|
11
|
+
propertyKey,
|
|
12
|
+
...options
|
|
24
13
|
}
|
|
25
14
|
});
|
|
26
15
|
}
|
|
@@ -56,23 +45,32 @@ function Inject(symbol, onGet = (bean) => bean) {
|
|
|
56
45
|
}
|
|
57
46
|
break;
|
|
58
47
|
case core_1.DecoratorTypes.PROP:
|
|
59
|
-
injectProperty(target, propertyKey,
|
|
60
|
-
|
|
61
|
-
let bean;
|
|
62
|
-
if (!bean) {
|
|
63
|
-
const options = core_1.Store.from(target, propertyKey).get(constants_1.DI_PARAM_OPTIONS);
|
|
48
|
+
injectProperty(target, propertyKey, {
|
|
49
|
+
resolver(injector, locals, { options, ...invokeOptions }) {
|
|
64
50
|
locals.set(constants_1.DI_PARAM_OPTIONS, { ...options });
|
|
65
|
-
bean
|
|
66
|
-
|
|
51
|
+
let bean;
|
|
52
|
+
if (!bean) {
|
|
53
|
+
const useType = symbol || core_1.Metadata.getType(target, propertyKey);
|
|
54
|
+
bean = injector.invoke(useType, locals, invokeOptions);
|
|
55
|
+
locals.delete(constants_1.DI_PARAM_OPTIONS);
|
|
56
|
+
}
|
|
67
57
|
if ((0, core_1.isPromise)(bean)) {
|
|
68
58
|
bean.then((result) => {
|
|
69
59
|
bean = result;
|
|
70
60
|
});
|
|
71
61
|
}
|
|
62
|
+
return () => onGet(bean);
|
|
72
63
|
}
|
|
73
|
-
return () => onGet(bean);
|
|
74
64
|
});
|
|
75
65
|
break;
|
|
66
|
+
case core_1.DecoratorTypes.METHOD:
|
|
67
|
+
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
68
|
+
[propertyKey]: {
|
|
69
|
+
bindingType,
|
|
70
|
+
propertyKey
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return descriptor;
|
|
76
74
|
default:
|
|
77
75
|
throw new core_1.UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);
|
|
78
76
|
}
|
|
@@ -95,7 +93,11 @@ exports.Inject = Inject;
|
|
|
95
93
|
*/
|
|
96
94
|
function InjectContext() {
|
|
97
95
|
return (target, propertyKey) => {
|
|
98
|
-
injectProperty(target, propertyKey,
|
|
96
|
+
injectProperty(target, propertyKey, {
|
|
97
|
+
resolver() {
|
|
98
|
+
return () => (0, runInContext_1.getContext)();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
99
101
|
};
|
|
100
102
|
}
|
|
101
103
|
exports.InjectContext = InjectContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":"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","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport type {InjectablePropertyOptions} from \"../interfaces/InjectableProperties\";\nimport {getContext} from \"../utils/runInContext\";\n\nexport function injectProperty(target: any, propertyKey: string, options: Partial<InjectablePropertyOptions>) {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: DecoratorTypes.PROP,\n propertyKey,\n ...options\n }\n });\n}\n\n/**\n * Inject a provider to another provider.\n *\n * Use this decorator to inject a custom provider on constructor parameter or property.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @Inject(CONNECTION)\n * connection: CONNECTION;\n * }\n * ```\n *\n * @param symbol\n * @param onGet Use the given name method to inject\n * @returns {Function}\n * @decorator\n */\nexport function Inject(symbol?: any, onGet = (bean: any) => bean): Function {\n return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any | void => {\n const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM:\n case DecoratorTypes.PARAM_CTOR:\n if (symbol) {\n const paramTypes = Metadata.getParamTypes(target, propertyKey);\n\n paramTypes[descriptor as number] = symbol;\n Metadata.setParamTypes(target, propertyKey, paramTypes);\n }\n break;\n\n case DecoratorTypes.PROP:\n injectProperty(target, propertyKey, {\n resolver(injector, locals, {options, ...invokeOptions}) {\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n let bean: any;\n\n if (!bean) {\n const useType = symbol || Metadata.getType(target, propertyKey);\n bean = injector.invoke(useType, locals, invokeOptions);\n locals.delete(DI_PARAM_OPTIONS);\n }\n\n if (isPromise(bean)) {\n bean.then((result: any) => {\n bean = result;\n });\n }\n\n return () => onGet(bean);\n }\n });\n break;\n\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType,\n propertyKey\n }\n });\n\n return descriptor;\n\n default:\n throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);\n }\n };\n}\n\n/**\n * Inject a context like PlatformContext or any BaseContext.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @InjectContext()\n * ctx?: Context;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n */\nexport function InjectContext(): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n injectProperty(target, propertyKey, {\n resolver() {\n return () => getContext();\n }\n });\n };\n}\n"]}
|
|
@@ -2,33 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Intercept = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return {
|
|
8
|
-
...descriptor,
|
|
9
|
-
value(...args) {
|
|
10
|
-
const injector = this.$$injector;
|
|
11
|
-
const next = (err) => {
|
|
12
|
-
if (!err) {
|
|
13
|
-
return originalMethod.apply(this, args);
|
|
14
|
-
}
|
|
15
|
-
throw err;
|
|
16
|
-
};
|
|
17
|
-
const context = {
|
|
18
|
-
target,
|
|
19
|
-
propertyKey,
|
|
20
|
-
args,
|
|
21
|
-
options,
|
|
22
|
-
next
|
|
23
|
-
};
|
|
24
|
-
const interceptor = injector.get(useType);
|
|
25
|
-
return interceptor.intercept({
|
|
26
|
-
...context,
|
|
27
|
-
options
|
|
28
|
-
}, next);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
|
+
const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
32
7
|
/**
|
|
33
8
|
* Attaches interceptor to method call and executes the before and after methods
|
|
34
9
|
*
|
|
@@ -45,10 +20,15 @@ function Intercept(interceptor, options) {
|
|
|
45
20
|
(0, core_1.decorateMethodsOf)(target, Intercept(interceptor, options));
|
|
46
21
|
break;
|
|
47
22
|
case core_1.DecoratorTypes.METHOD:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
23
|
+
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
24
|
+
[propertyKey]: {
|
|
25
|
+
options,
|
|
26
|
+
propertyKey,
|
|
27
|
+
useType: interceptor,
|
|
28
|
+
bindingType: InjectablePropertyType_1.InjectablePropertyType.INTERCEPTOR
|
|
29
|
+
}
|
|
51
30
|
});
|
|
31
|
+
return descriptor;
|
|
52
32
|
}
|
|
53
33
|
};
|
|
54
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/decorators/intercept.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/decorators/intercept.ts"],"names":[],"mappings":";;;AAAA,qCAAgH;AAChH,sDAAuD;AACvD,6EAAwE;AAIxE;;;;;;GAMG;AACH,SAAgB,SAAS,CAA+B,WAAoB,EAAE,OAAa;IACzF,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,IAAI,CAAC;QAC/C,MAAM,IAAI,GAAG,IAAA,sBAAe,EAAC,IAAI,CAAC,CAAC;QACnC,QAAQ,IAAI,EAAE;YACZ,KAAK,qBAAc,CAAC,KAAK;gBACvB,IAAA,wBAAiB,EAAC,MAAM,EAAE,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;gBAC3D,MAAM;YACR,KAAK,qBAAc,CAAC,MAAM;gBACxB,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;oBACxC,CAAC,WAAW,CAAC,EAAE;wBACb,OAAO;wBACP,WAAW;wBACX,OAAO,EAAE,WAAW;wBACpB,WAAW,EAAE,+CAAsB,CAAC,WAAW;qBAChD;iBACsB,CAAC,CAAC;gBAE3B,OAAO,UAAU,CAAC;SACrB;IACH,CAAC,CAAC;AACJ,CAAC;AArBD,8BAqBC","sourcesContent":["import {decorateMethodsOf, DecoratorParameters, decoratorTypeOf, DecoratorTypes, Store, Type} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/constants\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\n\n/**\n * Attaches interceptor to method call and executes the before and after methods\n *\n * @param interceptor\n * @param options\n * @decorator\n */\nexport function Intercept<T extends InterceptorMethods>(interceptor: Type<T>, options?: any): any {\n return (...args: DecoratorParameters) => {\n const [target, propertyKey, descriptor] = args;\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.CLASS:\n decorateMethodsOf(target, Intercept(interceptor, options));\n break;\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n options,\n propertyKey,\n useType: interceptor,\n bindingType: InjectablePropertyType.INTERCEPTOR\n }\n } as InjectableProperties);\n\n return descriptor;\n }\n };\n}\n"]}
|
|
@@ -25,22 +25,23 @@ const inject_1 = require("./inject");
|
|
|
25
25
|
*/
|
|
26
26
|
function LazyInject(key, resolver, { optional = false, packageName = resolver.toString() } = {}) {
|
|
27
27
|
return (target, propertyKey) => {
|
|
28
|
-
let token;
|
|
29
|
-
(0, inject_1.injectProperty)(target, propertyKey,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!token) {
|
|
33
|
-
const exports = await (0, core_1.importPackage)(packageName, resolver, optional);
|
|
34
|
-
token = exports[key];
|
|
28
|
+
let bean, token;
|
|
29
|
+
(0, inject_1.injectProperty)(target, propertyKey, {
|
|
30
|
+
resolver(injector) {
|
|
31
|
+
return async () => {
|
|
35
32
|
if (!token) {
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const exports = await (0, core_1.importPackage)(packageName, resolver, optional);
|
|
34
|
+
token = exports[key];
|
|
35
|
+
if (!token) {
|
|
36
|
+
if (!optional) {
|
|
37
|
+
throw new Error(`Unable to lazy load the "${key}". The token isn\'t a valid token provider.`);
|
|
38
|
+
}
|
|
38
39
|
}
|
|
40
|
+
bean = token ? await injector.lazyInvoke(token) : {};
|
|
39
41
|
}
|
|
40
|
-
bean
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
};
|
|
42
|
+
return bean;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyInject.js","sourceRoot":"","sources":["../../../src/decorators/lazyInject.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,UAAU,CACxB,GAAW,EACX,QAAmB,EACnB,EAAC,QAAQ,GAAG,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC,QAAQ,EAAE,KAAgD,EAAE;IAEtG,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,IAAI,KAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"lazyInject.js","sourceRoot":"","sources":["../../../src/decorators/lazyInject.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,qCAAwC;AAExC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,UAAU,CACxB,GAAW,EACX,QAAmB,EACnB,EAAC,QAAQ,GAAG,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC,QAAQ,EAAE,KAAgD,EAAE;IAEtG,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,IAAI,IAAS,EAAE,KAAU,CAAC;QAC1B,IAAA,uBAAc,EAAC,MAAM,EAAE,WAAW,EAAE;YAClC,QAAQ,CAAC,QAAQ;gBACf,OAAO,KAAK,IAAI,EAAE;oBAChB,IAAI,CAAC,KAAK,EAAE;wBACV,MAAM,OAAO,GAAG,MAAM,IAAA,oBAAa,EAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;wBACrE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;wBAErB,IAAI,CAAC,KAAK,EAAE;4BACV,IAAI,CAAC,QAAQ,EAAE;gCACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,6CAA6C,CAAC,CAAC;6BAC/F;yBACF;wBAED,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;qBACtD;oBAED,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA5BD,gCA4BC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,kBAAkB,CAAC,GAAW,EAAE,QAAmB;IACjE,OAAQ,UAAkB,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC9D,CAAC;AAFD,gDAEC","sourcesContent":["import {importPackage} from \"@tsed/core\";\nimport {injectProperty} from \"./inject\";\n\n/**\n * Lazy load a provider from his package and invoke only when the provider is used\n *\n * ```typescript\n * import type {PlatformException} from \"@tsed/platform-exceptions\";\n *\n * @Injectable()\n * export class MyService {\n * @LazyInject(\"PlatformException\", () => import(\"@tsed/platform-exceptions\"))\n * exceptions: Promise<PlatformException>;\n * }\n * ```\n *\n * @param key\n * @param packageName\n * @param resolver\n * @param optional\n * @returns {Function}\n * @decorator\n */\nexport function LazyInject(\n key: string,\n resolver: () => any,\n {optional = false, packageName = resolver.toString()}: {optional?: boolean; packageName?: string} = {}\n): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n let bean: any, token: any;\n injectProperty(target, propertyKey, {\n resolver(injector) {\n return async () => {\n if (!token) {\n const exports = await importPackage(packageName, resolver, optional);\n token = exports[key];\n\n if (!token) {\n if (!optional) {\n throw new Error(`Unable to lazy load the \"${key}\". The token isn\\'t a valid token provider.`);\n }\n }\n\n bean = token ? await injector.lazyInvoke(token) : {};\n }\n\n return bean;\n };\n }\n });\n };\n}\n\n/**\n * Optionally Lazy load a provider from his package and invoke only when the provider is used\n *\n * ```typescript\n * import type {PlatformException} from \"@tsed/platform-exceptions\";\n *\n * @Injectable()\n * export class MyService {\n * @OptionalLazyInject(\"@tsed/platform-exceptions\")\n * exceptions: Promise<PlatformException>;\n * }\n * ```\n *\n * @param key\n * @param resolver\n * @returns {Function}\n * @decorator\n */\nexport function OptionalLazyInject(key: string, resolver: () => any): PropertyDecorator {\n return (LazyInject as any)(key, resolver, {optional: true});\n}\n"]}
|
|
@@ -50,7 +50,11 @@ function UseOpts(options) {
|
|
|
50
50
|
core_1.Store.from(target).merge(`${constants_1.DI_PARAM_OPTIONS}:${index}`, options);
|
|
51
51
|
break;
|
|
52
52
|
case core_1.DecoratorTypes.PROP:
|
|
53
|
-
core_1.Store.from(target
|
|
53
|
+
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
54
|
+
[propertyKey]: {
|
|
55
|
+
options
|
|
56
|
+
}
|
|
57
|
+
});
|
|
54
58
|
break;
|
|
55
59
|
default:
|
|
56
60
|
throw new core_1.UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../../src/decorators/useOpts.ts"],"names":[],"mappings":";;;AAAA,qCAA4F;AAC5F,
|
|
1
|
+
{"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../../src/decorators/useOpts.ts"],"names":[],"mappings":";;;AAAA,qCAA4F;AAC5F,sDAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,SAAgB,OAAO,CAAC,OAA6B;IACnD,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,KAAc,EAAO,EAAE;QAC3E,MAAM,WAAW,GAAG,IAAA,sBAAe,EAAC,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/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"]}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Value = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
|
+
const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
5
7
|
/**
|
|
6
8
|
* Return value from Configuration.
|
|
7
9
|
*
|
|
@@ -39,15 +41,13 @@ const core_1 = require("@tsed/core");
|
|
|
39
41
|
*/
|
|
40
42
|
function Value(expression, defaultValue) {
|
|
41
43
|
return (target, propertyKey) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true
|
|
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
51
|
});
|
|
52
52
|
};
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../src/decorators/value.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../src/decorators/value.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,sDAAuD;AAEvD,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/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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,mDAAoE;AACpE,uDAAkD;AAkBlD,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
|
|
1
|
+
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,mDAAoE;AACpE,uDAAkD;AAkBlD,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;QAEtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,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;AAzED,8BAyEC","sourcesContent":["import type {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\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 readonly logger: ContextLogger;\n /**\n *\n */\n readonly 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\n // @ts-ignore\n delete this.container;\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"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -32,8 +32,8 @@ tslib_1.__exportStar(require("./errors/InjectionError"), exports);
|
|
|
32
32
|
tslib_1.__exportStar(require("./errors/UndefinedTokenError"), exports);
|
|
33
33
|
tslib_1.__exportStar(require("./interfaces/DIConfigurationOptions"), exports);
|
|
34
34
|
tslib_1.__exportStar(require("./interfaces/DILogger"), exports);
|
|
35
|
-
tslib_1.__exportStar(require("./interfaces/DILoggerOptions"), exports);
|
|
36
35
|
tslib_1.__exportStar(require("./interfaces/DIResolver"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./interfaces/InjectableProperties"), exports);
|
|
37
37
|
tslib_1.__exportStar(require("./interfaces/InterceptorContext"), exports);
|
|
38
38
|
tslib_1.__exportStar(require("./interfaces/InterceptorMethods"), exports);
|
|
39
39
|
tslib_1.__exportStar(require("./interfaces/InvokeOptions"), exports);
|
|
@@ -55,7 +55,5 @@ tslib_1.__exportStar(require("./utils/createContainer"), exports);
|
|
|
55
55
|
tslib_1.__exportStar(require("./utils/getConfiguration"), exports);
|
|
56
56
|
tslib_1.__exportStar(require("./utils/resolveControllers"), exports);
|
|
57
57
|
tslib_1.__exportStar(require("./utils/runInContext"), exports);
|
|
58
|
-
tslib_1.__exportStar(require("./utils/setLoggerConfiguration"), exports);
|
|
59
|
-
tslib_1.__exportStar(require("./utils/setLoggerFormat"), exports);
|
|
60
58
|
tslib_1.__exportStar(require("./utils/setLoggerLevel"), exports);
|
|
61
59
|
//# 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,
|
|
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,kEAAwC;AACxC,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,qEAA2C;AAC3C,+DAAqC;AACrC,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/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/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\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/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
|
|
@@ -0,0 +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: Map<TokenProvider, any>, 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"]}
|
|
@@ -11,7 +11,6 @@ class DIConfiguration {
|
|
|
11
11
|
resolvers: [],
|
|
12
12
|
imports: [],
|
|
13
13
|
routes: [],
|
|
14
|
-
logger: {},
|
|
15
14
|
...initialProps
|
|
16
15
|
}).forEach(([key, value]) => {
|
|
17
16
|
this.default.set(key, value);
|
|
@@ -22,60 +21,29 @@ class DIConfiguration {
|
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
23
|
}
|
|
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
|
-
}
|
|
43
24
|
get scopes() {
|
|
44
|
-
return this.
|
|
25
|
+
return this.getRaw("scopes");
|
|
45
26
|
}
|
|
46
27
|
set scopes(value) {
|
|
47
|
-
this.
|
|
28
|
+
this.setRaw("scopes", value);
|
|
48
29
|
}
|
|
49
30
|
get resolvers() {
|
|
50
31
|
return this.getRaw("resolvers");
|
|
51
32
|
}
|
|
52
33
|
set resolvers(resolvers) {
|
|
53
|
-
this.
|
|
34
|
+
this.setRaw("resolvers", resolvers);
|
|
54
35
|
}
|
|
55
36
|
get imports() {
|
|
56
|
-
return this.
|
|
37
|
+
return this.getRaw("imports");
|
|
57
38
|
}
|
|
58
39
|
set imports(imports) {
|
|
59
|
-
this.
|
|
40
|
+
this.setRaw("imports", imports);
|
|
60
41
|
}
|
|
61
42
|
get routes() {
|
|
62
|
-
return this.
|
|
43
|
+
return this.getRaw("routes");
|
|
63
44
|
}
|
|
64
45
|
set routes(routes) {
|
|
65
|
-
this.
|
|
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" };
|
|
46
|
+
this.setRaw("routes", routes);
|
|
79
47
|
}
|
|
80
48
|
/**
|
|
81
49
|
*
|
|
@@ -94,17 +62,11 @@ class DIConfiguration {
|
|
|
94
62
|
*/
|
|
95
63
|
set(propertyKey, value) {
|
|
96
64
|
if (typeof propertyKey === "string") {
|
|
97
|
-
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
this[propertyKey] = value;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
this.setRaw(propertyKey, value);
|
|
103
|
-
}
|
|
65
|
+
this.setRaw(propertyKey, value);
|
|
104
66
|
}
|
|
105
67
|
else {
|
|
106
68
|
Object.entries(propertyKey).forEach(([key, value]) => {
|
|
107
|
-
this
|
|
69
|
+
this[key] = value;
|
|
108
70
|
});
|
|
109
71
|
}
|
|
110
72
|
return this;
|
|
@@ -120,7 +82,7 @@ class DIConfiguration {
|
|
|
120
82
|
* @returns {undefined|any}
|
|
121
83
|
*/
|
|
122
84
|
get(propertyKey, defaultValue) {
|
|
123
|
-
return this.getRaw(propertyKey, defaultValue);
|
|
85
|
+
return this.resolve(this.getRaw(propertyKey, defaultValue));
|
|
124
86
|
}
|
|
125
87
|
getRaw(propertyKey, defaultValue) {
|
|
126
88
|
const value = (0, core_1.getValue)(this.map, propertyKey);
|
|
@@ -129,13 +91,45 @@ class DIConfiguration {
|
|
|
129
91
|
}
|
|
130
92
|
return (0, core_1.getValue)(this.default, propertyKey, defaultValue);
|
|
131
93
|
}
|
|
94
|
+
merge(obj) {
|
|
95
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
96
|
+
const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);
|
|
97
|
+
const originalValue = this.get(key);
|
|
98
|
+
value = (0, core_1.deepMerge)(value, originalValue);
|
|
99
|
+
if (descriptor && !["default", "set", "map", "get"].includes(key)) {
|
|
100
|
+
this[key] = value;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
132
104
|
/**
|
|
133
105
|
*
|
|
134
106
|
* @param value
|
|
135
107
|
* @returns {any}
|
|
136
108
|
*/
|
|
137
109
|
resolve(value) {
|
|
138
|
-
|
|
110
|
+
if (typeof value === "object" && value !== null) {
|
|
111
|
+
if (![Array, Object].includes((0, core_1.classOf)(value))) {
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
return Object.entries(value).reduce((o, [k, v]) => {
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
o[k] = this.resolve(v);
|
|
117
|
+
return o;
|
|
118
|
+
}, Array.isArray(value) ? [] : {});
|
|
119
|
+
}
|
|
120
|
+
if (typeof value === "string") {
|
|
121
|
+
const replacer = (match, key) => (0, core_1.getValue)(this.map, key);
|
|
122
|
+
return value
|
|
123
|
+
.replace(/\${([\w.]+)}/gi, replacer)
|
|
124
|
+
.replace(/<([\w.]+)>/gi, replacer)
|
|
125
|
+
.replace(/{{([\w.]+)}}/gi, replacer);
|
|
126
|
+
}
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
build() {
|
|
130
|
+
this.forEach((value, key) => this.map.set(key, this.resolve(value)));
|
|
131
|
+
this.set = this.setRaw;
|
|
132
|
+
this.get = this.getRaw = (propertyKey, defaultValue) => (0, core_1.getValue)(this.map, propertyKey, defaultValue);
|
|
139
133
|
}
|
|
140
134
|
}
|
|
141
135
|
exports.DIConfiguration = DIConfiguration;
|