@tsed/di 6.114.4 → 6.114.5-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/lib/cjs/constants/constants.js +1 -3
- package/lib/cjs/constants/constants.js.map +1 -1
- package/lib/cjs/decorators/constant.js +8 -9
- package/lib/cjs/decorators/constant.js.map +1 -1
- package/lib/cjs/decorators/inject.js +26 -28
- package/lib/cjs/decorators/inject.js.map +1 -1
- package/lib/cjs/decorators/intercept.js +30 -10
- package/lib/cjs/decorators/intercept.js.map +1 -1
- package/lib/cjs/decorators/lazyInject.js +13 -14
- package/lib/cjs/decorators/lazyInject.js.map +1 -1
- package/lib/cjs/decorators/useOpts.js +1 -5
- 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 +3 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/{InjectableProperties.js → DILoggerOptions.js} +1 -1
- package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/cjs/services/DIConfiguration.js +49 -43
- 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 +19 -133
- package/lib/cjs/services/InjectorService.js.map +1 -1
- 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/constants/constants.js +0 -2
- package/lib/esm/constants/constants.js.map +1 -1
- package/lib/esm/decorators/constant.js +9 -10
- package/lib/esm/decorators/constant.js.map +1 -1
- package/lib/esm/decorators/inject.js +28 -30
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/decorators/intercept.js +31 -11
- package/lib/esm/decorators/intercept.js.map +1 -1
- package/lib/esm/decorators/lazyInject.js +13 -14
- package/lib/esm/decorators/lazyInject.js.map +1 -1
- package/lib/esm/decorators/useOpts.js +2 -6
- 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 +3 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/DILoggerOptions.js +2 -0
- package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/esm/services/DIConfiguration.js +50 -44
- 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 +21 -135
- package/lib/esm/services/InjectorService.js.map +1 -1
- 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/constants/constants.d.ts +0 -2
- package/lib/types/decorators/inject.d.ts +5 -2
- package/lib/types/index.d.ts +3 -1
- package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
- package/lib/types/services/DIConfiguration.d.ts +17 -12
- package/lib/types/services/InjectorService.d.ts +5 -50
- 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 +9 -6
- package/lib/cjs/interfaces/InjectableProperties.js.map +0 -1
- package/lib/esm/interfaces/InjectableProperties.js +0 -2
- package/lib/esm/interfaces/InjectableProperties.js.map +0 -1
- package/lib/types/interfaces/InjectableProperties.d.ts +0 -24
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
-
import { DI_PARAM_OPTIONS
|
|
1
|
+
import { decoratorTypeOf, DecoratorTypes, isPromise, Metadata, prototypeOf, Store, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
+
import { DI_PARAM_OPTIONS } from "../constants/constants.js";
|
|
3
3
|
import { getContext } from "../utils/runInContext.js";
|
|
4
|
-
export function injectProperty(target, propertyKey,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export function injectProperty(target, propertyKey, resolver) {
|
|
5
|
+
Object.defineProperty(prototypeOf(target), propertyKey, {
|
|
6
|
+
enumerable: false,
|
|
7
|
+
configurable: true,
|
|
8
|
+
get() {
|
|
9
|
+
const key = `$$getter_${propertyKey}`;
|
|
10
|
+
if (!this[key]) {
|
|
11
|
+
const fn = resolver(this.$$injector, this.$$locals, this.$$invokeOptions);
|
|
12
|
+
Object.defineProperty(this, key, {
|
|
13
|
+
configurable: true,
|
|
14
|
+
enumerable: false,
|
|
15
|
+
get() {
|
|
16
|
+
return fn;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return this[key]();
|
|
10
21
|
}
|
|
11
22
|
});
|
|
12
23
|
}
|
|
@@ -41,32 +52,23 @@ export function Inject(symbol, onGet = (bean) => bean) {
|
|
|
41
52
|
}
|
|
42
53
|
break;
|
|
43
54
|
case DecoratorTypes.PROP:
|
|
44
|
-
injectProperty(target, propertyKey, {
|
|
45
|
-
|
|
55
|
+
injectProperty(target, propertyKey, (injector, locals, invokeOptions) => {
|
|
56
|
+
const useType = symbol || Metadata.getType(target, propertyKey);
|
|
57
|
+
let bean;
|
|
58
|
+
if (!bean) {
|
|
59
|
+
const options = Store.from(target, propertyKey).get(DI_PARAM_OPTIONS);
|
|
46
60
|
locals.set(DI_PARAM_OPTIONS, { ...options });
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const useType = symbol || Metadata.getType(target, propertyKey);
|
|
50
|
-
bean = injector.invoke(useType, locals, invokeOptions);
|
|
51
|
-
locals.delete(DI_PARAM_OPTIONS);
|
|
52
|
-
}
|
|
61
|
+
bean = injector.invoke(useType, locals, invokeOptions);
|
|
62
|
+
locals.delete(DI_PARAM_OPTIONS);
|
|
53
63
|
if (isPromise(bean)) {
|
|
54
64
|
bean.then((result) => {
|
|
55
65
|
bean = result;
|
|
56
66
|
});
|
|
57
67
|
}
|
|
58
|
-
return () => onGet(bean);
|
|
59
68
|
}
|
|
69
|
+
return () => onGet(bean);
|
|
60
70
|
});
|
|
61
71
|
break;
|
|
62
|
-
case DecoratorTypes.METHOD:
|
|
63
|
-
Store.from(target).merge(INJECTABLE_PROP, {
|
|
64
|
-
[propertyKey]: {
|
|
65
|
-
bindingType,
|
|
66
|
-
propertyKey
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return descriptor;
|
|
70
72
|
default:
|
|
71
73
|
throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);
|
|
72
74
|
}
|
|
@@ -88,11 +90,7 @@ export function Inject(symbol, onGet = (bean) => bean) {
|
|
|
88
90
|
*/
|
|
89
91
|
export function InjectContext() {
|
|
90
92
|
return (target, propertyKey) => {
|
|
91
|
-
injectProperty(target, propertyKey,
|
|
92
|
-
resolver() {
|
|
93
|
-
return () => getContext();
|
|
94
|
-
}
|
|
95
|
-
});
|
|
93
|
+
injectProperty(target, propertyKey, () => () => getContext());
|
|
96
94
|
};
|
|
97
95
|
}
|
|
98
96
|
//# sourceMappingURL=inject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AAC9H,OAAO,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AAIxD,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAQjD,MAAM,UAAU,cAAc,CAAC,MAAW,EAAE,WAAmB,EAAE,QAAgC;IAC/F,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE;QACtD,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;QAClB,GAAG;YACD,MAAM,GAAG,GAAG,YAAY,WAAW,EAAE,CAAC;YAEtC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBACd,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;gBAC1E,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE;oBAC/B,YAAY,EAAE,IAAI;oBAClB,UAAU,EAAE,KAAK;oBACjB,GAAG;wBACD,OAAO,EAAE,CAAC;oBACZ,CAAC;iBACF,CAAC,CAAC;aACJ;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACrB,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,MAAY,EAAE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,MAAW,EAAE,EAAE;gCACxB,IAAI,GAAG,MAAM,CAAC;4BAChB,CAAC,CAAC,CAAC;yBACJ;qBACF;oBAED,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC3B,CAAC,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;SACjF;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, prototypeOf, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS} from \"../constants/constants\";\nimport {InvokeOptions} from \"../interfaces/InvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {getContext} from \"../utils/runInContext\";\n\nexport type InjectPropertyResolver = (\n injector: InjectorService,\n locals: Map<TokenProvider, any>,\n options: Partial<InvokeOptions>\n) => () => any;\n\nexport function injectProperty(target: any, propertyKey: string, resolver: InjectPropertyResolver) {\n Object.defineProperty(prototypeOf(target), propertyKey, {\n enumerable: false,\n configurable: true,\n get() {\n const key = `$$getter_${propertyKey}`;\n\n if (!this[key]) {\n const fn = resolver(this.$$injector, this.$$locals, this.$$invokeOptions);\n Object.defineProperty(this, key, {\n configurable: true,\n enumerable: false,\n get() {\n return fn;\n }\n });\n }\n\n return this[key]();\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, (injector, locals, invokeOptions) => {\n const useType = symbol || Metadata.getType(target, propertyKey);\n\n let bean: any;\n\n if (!bean) {\n const options = Store.from(target, propertyKey).get(DI_PARAM_OPTIONS);\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n bean = injector.invoke(useType, locals, invokeOptions);\n\n locals.delete(DI_PARAM_OPTIONS);\n\n if (isPromise(bean)) {\n bean.then((result: any) => {\n bean = result;\n });\n }\n }\n\n return () => onGet(bean);\n });\n break;\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, () => () => getContext());\n };\n}\n"]}
|
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes } from "@tsed/core";
|
|
2
|
+
function bindMethod(target, propertyKey, descriptor, { options, useType }) {
|
|
3
|
+
const originalMethod = descriptor.value;
|
|
4
|
+
return {
|
|
5
|
+
...descriptor,
|
|
6
|
+
value(...args) {
|
|
7
|
+
const injector = this.$$injector;
|
|
8
|
+
const next = (err) => {
|
|
9
|
+
if (!err) {
|
|
10
|
+
return originalMethod.apply(this, args);
|
|
11
|
+
}
|
|
12
|
+
throw err;
|
|
13
|
+
};
|
|
14
|
+
const context = {
|
|
15
|
+
target,
|
|
16
|
+
propertyKey,
|
|
17
|
+
args,
|
|
18
|
+
options,
|
|
19
|
+
next
|
|
20
|
+
};
|
|
21
|
+
const interceptor = injector.get(useType);
|
|
22
|
+
return interceptor.intercept({
|
|
23
|
+
...context,
|
|
24
|
+
options
|
|
25
|
+
}, next);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
4
29
|
/**
|
|
5
30
|
* Attaches interceptor to method call and executes the before and after methods
|
|
6
31
|
*
|
|
@@ -17,15 +42,10 @@ export function Intercept(interceptor, options) {
|
|
|
17
42
|
decorateMethodsOf(target, Intercept(interceptor, options));
|
|
18
43
|
break;
|
|
19
44
|
case DecoratorTypes.METHOD:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
propertyKey,
|
|
24
|
-
useType: interceptor,
|
|
25
|
-
bindingType: InjectablePropertyType.INTERCEPTOR
|
|
26
|
-
}
|
|
45
|
+
return bindMethod(target, propertyKey, descriptor, {
|
|
46
|
+
options,
|
|
47
|
+
useType: interceptor
|
|
27
48
|
});
|
|
28
|
-
return descriptor;
|
|
29
49
|
}
|
|
30
50
|
};
|
|
31
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/decorators/intercept.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAuB,eAAe,EAAE,cAAc,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"intercept.js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AC,CAAC,CAAC;gBAC3D,MAAM;YACR,KAAK,cAAc,CAAC,MAAM;gBACxB,OAAO,UAAU,CAAC,MAAM,EAAE,WAAqB,EAAE,UAAgC,EAAE;oBACjF,OAAO;oBACP,OAAO,EAAE,WAAW;iBACrB,CAAC,CAAC;SACN;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decorateMethodsOf, DecoratorParameters, decoratorTypeOf, DecoratorTypes, Type} from \"@tsed/core\";\nimport {InterceptorContext} from \"../interfaces/InterceptorContext\";\nimport type {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport type {InjectorService} from \"../services/InjectorService\";\n\nfunction bindMethod(target: any, propertyKey: string, descriptor: PropertyDescriptor, {options, useType}: any) {\n const originalMethod = (descriptor as PropertyDescriptor).value;\n\n return {\n ...descriptor,\n value(...args: any[]) {\n const injector = this.$$injector as InjectorService;\n const next = (err?: Error) => {\n if (!err) {\n return originalMethod.apply(this, args);\n }\n\n throw err;\n };\n\n const context: InterceptorContext<any> = {\n target,\n propertyKey,\n args,\n options,\n next\n };\n\n const interceptor = injector.get<InterceptorMethods>(useType)!;\n\n return interceptor.intercept!(\n {\n ...context,\n options\n },\n next\n );\n }\n };\n}\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 return bindMethod(target, propertyKey as string, descriptor as PropertyDescriptor, {\n options,\n useType: interceptor\n });\n }\n };\n}\n"]}
|
|
@@ -22,23 +22,22 @@ import { injectProperty } from "./inject.js";
|
|
|
22
22
|
*/
|
|
23
23
|
export function LazyInject(key, resolver, { optional = false, packageName = resolver.toString() } = {}) {
|
|
24
24
|
return (target, propertyKey) => {
|
|
25
|
-
let
|
|
26
|
-
injectProperty(target, propertyKey, {
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
let token;
|
|
26
|
+
injectProperty(target, propertyKey, (injector) => {
|
|
27
|
+
let bean;
|
|
28
|
+
return async () => {
|
|
29
|
+
if (!token) {
|
|
30
|
+
const exports = await importPackage(packageName, resolver, optional);
|
|
31
|
+
token = exports[key];
|
|
29
32
|
if (!token) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!token) {
|
|
33
|
-
if (!optional) {
|
|
34
|
-
throw new Error(`Unable to lazy load the "${key}". The token isn\'t a valid token provider.`);
|
|
35
|
-
}
|
|
33
|
+
if (!optional) {
|
|
34
|
+
throw new Error(`Unable to lazy load the "${key}". The token isn\'t a valid token provider.`);
|
|
36
35
|
}
|
|
37
|
-
bean = token ? await injector.lazyInvoke(token) : {};
|
|
38
36
|
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
37
|
+
bean = token ? await injector.lazyInvoke(token) : {};
|
|
38
|
+
}
|
|
39
|
+
return bean;
|
|
40
|
+
};
|
|
42
41
|
});
|
|
43
42
|
};
|
|
44
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazyInject.js","sourceRoot":"","sources":["../../../src/decorators/lazyInject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,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,
|
|
1
|
+
{"version":3,"file":"lazyInject.js","sourceRoot":"","sources":["../../../src/decor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ed/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 token: any;\n\n injectProperty(target, propertyKey, (injector) => {\n let bean: any;\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 * 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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { decoratorTypeOf, DecoratorTypes, Store, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
-
import { DI_PARAM_OPTIONS
|
|
2
|
+
import { DI_PARAM_OPTIONS } from "../constants/constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* Add options to invoke the Service.
|
|
5
5
|
*
|
|
@@ -47,11 +47,7 @@ export function UseOpts(options) {
|
|
|
47
47
|
Store.from(target).merge(`${DI_PARAM_OPTIONS}:${index}`, options);
|
|
48
48
|
break;
|
|
49
49
|
case DecoratorTypes.PROP:
|
|
50
|
-
Store.from(target).merge(
|
|
51
|
-
[propertyKey]: {
|
|
52
|
-
options
|
|
53
|
-
}
|
|
54
|
-
});
|
|
50
|
+
Store.from(target, propertyKey).merge(DI_PARAM_OPTIONS, options);
|
|
55
51
|
break;
|
|
56
52
|
default:
|
|
57
53
|
throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../../src/decorators/useOpts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../../src/decorators/useOpts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,OAAO,CAAC,OAA6B;IACnD,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,KAAc,EAAO,EAAE;QAC3E,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;QAElE,QAAQ,WAAW,EAAE;YACnB,KAAK,cAAc,CAAC,UAAU;gBAC5B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,gBAAgB,IAAI,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;gBAClE,MAAM;YAER,KAAK,cAAc,CAAC,IAAI;gBACtB,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;gBACjE,MAAM;YAER;gBACE,MAAM,IAAI,wBAAwB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;SAC7E;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS} 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, propertyKey).merge(DI_PARAM_OPTIONS, options);\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);\n }\n };\n}\n"]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { INJECTABLE_PROP } from "../constants/constants.js";
|
|
3
|
-
import { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
|
|
1
|
+
import { prototypeOf } from "@tsed/core";
|
|
4
2
|
/**
|
|
5
3
|
* Return value from Configuration.
|
|
6
4
|
*
|
|
@@ -38,13 +36,15 @@ import { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
|
|
|
38
36
|
*/
|
|
39
37
|
export function Value(expression, defaultValue) {
|
|
40
38
|
return (target, propertyKey) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
39
|
+
Object.defineProperty(prototypeOf(target), propertyKey, {
|
|
40
|
+
get() {
|
|
41
|
+
return this.$$injector.settings.get(expression, defaultValue);
|
|
42
|
+
},
|
|
43
|
+
set(value) {
|
|
44
|
+
this.$$injector.settings.set(expression, value);
|
|
45
|
+
},
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true
|
|
48
48
|
});
|
|
49
49
|
};
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../src/decorators/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../src/decorators/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAGvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,KAAK,CAAC,UAAe,EAAE,YAAkB;IACvD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE;YACtD,GAAG;gBACD,OAAQ,IAAI,CAAC,UAA8B,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;YACrF,CAAC;YACD,GAAG,CAAC,KAAU;gBACX,IAAI,CAAC,UAA8B,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YACvE,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {prototypeOf} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\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 Object.defineProperty(prototypeOf(target), propertyKey, {\n get() {\n return (this.$$injector as InjectorService).settings.get(expression, defaultValue);\n },\n set(value: any) {\n (this.$$injector as InjectorService).settings.set(expression, value);\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAkBlD,MAAM,OAAO,SAAU,SAAQ,GAAa;IA4C1C,YAAY,EAAC,EAAE,EAAE,QAA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F,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,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","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.get(\"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/esm/index.js
CHANGED
|
@@ -29,8 +29,8 @@ export * from "./errors/InjectionError.js";
|
|
|
29
29
|
export * from "./errors/UndefinedTokenError.js";
|
|
30
30
|
export * from "./interfaces/DIConfigurationOptions.js";
|
|
31
31
|
export * from "./interfaces/DILogger.js";
|
|
32
|
+
export * from "./interfaces/DILoggerOptions.js";
|
|
32
33
|
export * from "./interfaces/DIResolver.js";
|
|
33
|
-
export * from "./interfaces/InjectableProperties.js";
|
|
34
34
|
export * from "./interfaces/InterceptorContext.js";
|
|
35
35
|
export * from "./interfaces/InterceptorMethods.js";
|
|
36
36
|
export * from "./interfaces/InvokeOptions.js";
|
|
@@ -52,5 +52,7 @@ export * from "./utils/createContainer.js";
|
|
|
52
52
|
export * from "./utils/getConfiguration.js";
|
|
53
53
|
export * from "./utils/resolveControllers.js";
|
|
54
54
|
export * from "./utils/runInContext.js";
|
|
55
|
+
export * from "./utils/setLoggerConfiguration.js";
|
|
56
|
+
export * from "./utils/setLoggerFormat.js";
|
|
55
57
|
export * from "./utils/setLoggerLevel.js";
|
|
56
58
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC","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/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\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/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\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[];\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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getValue, proxyDelegation, setValue } from "@tsed/core";
|
|
2
2
|
export class DIConfiguration {
|
|
3
3
|
constructor(initialProps = {}) {
|
|
4
4
|
this.default = new Map();
|
|
@@ -8,6 +8,7 @@ export class DIConfiguration {
|
|
|
8
8
|
resolvers: [],
|
|
9
9
|
imports: [],
|
|
10
10
|
routes: [],
|
|
11
|
+
logger: {},
|
|
11
12
|
...initialProps
|
|
12
13
|
}).forEach(([key, value]) => {
|
|
13
14
|
this.default.set(key, value);
|
|
@@ -18,29 +19,60 @@ export class DIConfiguration {
|
|
|
18
19
|
}
|
|
19
20
|
});
|
|
20
21
|
}
|
|
22
|
+
get version() {
|
|
23
|
+
return this.get("version");
|
|
24
|
+
}
|
|
25
|
+
set version(v) {
|
|
26
|
+
this.map.set("version", v);
|
|
27
|
+
}
|
|
28
|
+
get rootDir() {
|
|
29
|
+
return this.get("rootDir");
|
|
30
|
+
}
|
|
31
|
+
set rootDir(value) {
|
|
32
|
+
this.map.set("rootDir", value);
|
|
33
|
+
}
|
|
34
|
+
get env() {
|
|
35
|
+
return this.map.get("env");
|
|
36
|
+
}
|
|
37
|
+
set env(value) {
|
|
38
|
+
this.map.set("env", value);
|
|
39
|
+
}
|
|
21
40
|
get scopes() {
|
|
22
|
-
return this.
|
|
41
|
+
return this.map.get("scopes");
|
|
23
42
|
}
|
|
24
43
|
set scopes(value) {
|
|
25
|
-
this.
|
|
44
|
+
this.map.set("scopes", value);
|
|
26
45
|
}
|
|
27
46
|
get resolvers() {
|
|
28
47
|
return this.getRaw("resolvers");
|
|
29
48
|
}
|
|
30
49
|
set resolvers(resolvers) {
|
|
31
|
-
this.
|
|
50
|
+
this.map.set("resolvers", resolvers);
|
|
32
51
|
}
|
|
33
52
|
get imports() {
|
|
34
|
-
return this.
|
|
53
|
+
return this.get("imports");
|
|
35
54
|
}
|
|
36
55
|
set imports(imports) {
|
|
37
|
-
this.
|
|
56
|
+
this.map.set("imports", imports);
|
|
38
57
|
}
|
|
39
58
|
get routes() {
|
|
40
|
-
return this.
|
|
59
|
+
return this.get("routes");
|
|
41
60
|
}
|
|
42
61
|
set routes(routes) {
|
|
43
|
-
this.
|
|
62
|
+
this.map.set("routes", routes);
|
|
63
|
+
}
|
|
64
|
+
get logger() {
|
|
65
|
+
return this.get("logger");
|
|
66
|
+
}
|
|
67
|
+
set logger(value) {
|
|
68
|
+
const logger = { ...this.logger, ...value };
|
|
69
|
+
this.map.set("logger", logger);
|
|
70
|
+
}
|
|
71
|
+
get debug() {
|
|
72
|
+
return this.logger.level === "debug";
|
|
73
|
+
}
|
|
74
|
+
set debug(debug) {
|
|
75
|
+
this.logger = { ...this.logger, level: debug ? "debug" : "info" };
|
|
44
76
|
}
|
|
45
77
|
/**
|
|
46
78
|
*
|
|
@@ -59,11 +91,17 @@ export class DIConfiguration {
|
|
|
59
91
|
*/
|
|
60
92
|
set(propertyKey, value) {
|
|
61
93
|
if (typeof propertyKey === "string") {
|
|
62
|
-
|
|
94
|
+
if (propertyKey in this) {
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
this[propertyKey] = value;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.setRaw(propertyKey, value);
|
|
100
|
+
}
|
|
63
101
|
}
|
|
64
102
|
else {
|
|
65
103
|
Object.entries(propertyKey).forEach(([key, value]) => {
|
|
66
|
-
this
|
|
104
|
+
this.set(key, value);
|
|
67
105
|
});
|
|
68
106
|
}
|
|
69
107
|
return this;
|
|
@@ -79,7 +117,7 @@ export class DIConfiguration {
|
|
|
79
117
|
* @returns {undefined|any}
|
|
80
118
|
*/
|
|
81
119
|
get(propertyKey, defaultValue) {
|
|
82
|
-
return this.
|
|
120
|
+
return this.getRaw(propertyKey, defaultValue);
|
|
83
121
|
}
|
|
84
122
|
getRaw(propertyKey, defaultValue) {
|
|
85
123
|
const value = getValue(this.map, propertyKey);
|
|
@@ -88,45 +126,13 @@ export class DIConfiguration {
|
|
|
88
126
|
}
|
|
89
127
|
return getValue(this.default, propertyKey, defaultValue);
|
|
90
128
|
}
|
|
91
|
-
merge(obj) {
|
|
92
|
-
Object.entries(obj).forEach(([key, value]) => {
|
|
93
|
-
const descriptor = Object.getOwnPropertyDescriptor(DIConfiguration.prototype, key);
|
|
94
|
-
const originalValue = this.get(key);
|
|
95
|
-
value = deepMerge(value, originalValue);
|
|
96
|
-
if (descriptor && !["default", "set", "map", "get"].includes(key)) {
|
|
97
|
-
this[key] = value;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
129
|
/**
|
|
102
130
|
*
|
|
103
131
|
* @param value
|
|
104
132
|
* @returns {any}
|
|
105
133
|
*/
|
|
106
134
|
resolve(value) {
|
|
107
|
-
|
|
108
|
-
if (![Array, Object].includes(classOf(value))) {
|
|
109
|
-
return value;
|
|
110
|
-
}
|
|
111
|
-
return Object.entries(value).reduce((o, [k, v]) => {
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
o[k] = this.resolve(v);
|
|
114
|
-
return o;
|
|
115
|
-
}, Array.isArray(value) ? [] : {});
|
|
116
|
-
}
|
|
117
|
-
if (typeof value === "string") {
|
|
118
|
-
const replacer = (match, key) => getValue(this.map, key);
|
|
119
|
-
return value
|
|
120
|
-
.replace(/\${([\w.]+)}/gi, replacer)
|
|
121
|
-
.replace(/<([\w.]+)>/gi, replacer)
|
|
122
|
-
.replace(/{{([\w.]+)}}/gi, replacer);
|
|
123
|
-
}
|
|
124
|
-
return value;
|
|
125
|
-
}
|
|
126
|
-
build() {
|
|
127
|
-
this.forEach((value, key) => this.map.set(key, this.resolve(value)));
|
|
128
|
-
this.set = this.setRaw;
|
|
129
|
-
this.get = this.getRaw = (propertyKey, defaultValue) => getValue(this.map, propertyKey, defaultValue);
|
|
135
|
+
return value.replace("${rootDir}", this.rootDir);
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
//# sourceMappingURL=DIConfiguration.js.map
|