@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,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DI_PARAM_OPTIONS =
|
|
4
|
-
exports.INJECTABLE_PROP = "DI:INJECTABLE_PROP";
|
|
5
|
-
exports.DI_PARAMS = "DI:PARAMS";
|
|
3
|
+
exports.DI_PARAM_OPTIONS = void 0;
|
|
6
4
|
exports.DI_PARAM_OPTIONS = "DI:PARAM:OPTIONS";
|
|
7
5
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,
|
|
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"]}
|
|
@@ -2,8 +2,6 @@
|
|
|
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");
|
|
7
5
|
/**
|
|
8
6
|
* Return value from Configuration.
|
|
9
7
|
*
|
|
@@ -41,13 +39,14 @@ const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
|
41
39
|
*/
|
|
42
40
|
function Constant(expression, defaultValue) {
|
|
43
41
|
return (target, propertyKey) => {
|
|
44
|
-
core_1.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
Object.defineProperty((0, core_1.prototypeOf)(target), propertyKey, {
|
|
43
|
+
get() {
|
|
44
|
+
const injector = this.$$injector;
|
|
45
|
+
const value = injector.settings.get(expression, defaultValue);
|
|
46
|
+
return Object.freeze((0, core_1.deepClone)(value));
|
|
47
|
+
},
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true
|
|
51
50
|
});
|
|
52
51
|
};
|
|
53
52
|
}
|
|
@@ -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,qCAAkD;AAGlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,QAAQ,CAAC,UAAkB,EAAE,YAAkB;IAC7D,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,CAAC,cAAc,CAAC,IAAA,kBAAW,EAAC,MAAM,CAAC,EAAE,WAAW,EAAE;YACtD,GAAG;gBACD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAA6B,CAAC;gBACpD,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;gBAE9D,OAAO,MAAM,CAAC,MAAM,CAAC,IAAA,gBAAS,EAAC,KAAK,CAAC,CAAC,CAAC;YACzC,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAbD,4BAaC","sourcesContent":["import {deepClone, prototypeOf} from \"@tsed/core\";\nimport type {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 {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 Object.defineProperty(prototypeOf(target), propertyKey, {\n get() {\n const injector = this.$$injector as InjectorService;\n const value = injector.settings.get(expression, defaultValue);\n\n return Object.freeze(deepClone(value));\n },\n enumerable: true,\n configurable: true\n });\n };\n}\n"]}
|
|
@@ -4,12 +4,23 @@ 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
|
-
core_1.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
function injectProperty(target, propertyKey, resolver) {
|
|
8
|
+
Object.defineProperty((0, core_1.prototypeOf)(target), propertyKey, {
|
|
9
|
+
enumerable: false,
|
|
10
|
+
configurable: true,
|
|
11
|
+
get() {
|
|
12
|
+
const key = `$$getter_${propertyKey}`;
|
|
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]();
|
|
13
24
|
}
|
|
14
25
|
});
|
|
15
26
|
}
|
|
@@ -45,32 +56,23 @@ function Inject(symbol, onGet = (bean) => bean) {
|
|
|
45
56
|
}
|
|
46
57
|
break;
|
|
47
58
|
case core_1.DecoratorTypes.PROP:
|
|
48
|
-
injectProperty(target, propertyKey, {
|
|
49
|
-
|
|
59
|
+
injectProperty(target, propertyKey, (injector, locals, invokeOptions) => {
|
|
60
|
+
const useType = symbol || core_1.Metadata.getType(target, propertyKey);
|
|
61
|
+
let bean;
|
|
62
|
+
if (!bean) {
|
|
63
|
+
const options = core_1.Store.from(target, propertyKey).get(constants_1.DI_PARAM_OPTIONS);
|
|
50
64
|
locals.set(constants_1.DI_PARAM_OPTIONS, { ...options });
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
}
|
|
65
|
+
bean = injector.invoke(useType, locals, invokeOptions);
|
|
66
|
+
locals.delete(constants_1.DI_PARAM_OPTIONS);
|
|
57
67
|
if ((0, core_1.isPromise)(bean)) {
|
|
58
68
|
bean.then((result) => {
|
|
59
69
|
bean = result;
|
|
60
70
|
});
|
|
61
71
|
}
|
|
62
|
-
return () => onGet(bean);
|
|
63
72
|
}
|
|
73
|
+
return () => onGet(bean);
|
|
64
74
|
});
|
|
65
75
|
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;
|
|
74
76
|
default:
|
|
75
77
|
throw new core_1.UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);
|
|
76
78
|
}
|
|
@@ -93,11 +95,7 @@ exports.Inject = Inject;
|
|
|
93
95
|
*/
|
|
94
96
|
function InjectContext() {
|
|
95
97
|
return (target, propertyKey) => {
|
|
96
|
-
injectProperty(target, propertyKey,
|
|
97
|
-
resolver() {
|
|
98
|
-
return () => (0, runInContext_1.getContext)();
|
|
99
|
-
}
|
|
100
|
-
});
|
|
98
|
+
injectProperty(target, propertyKey, () => () => (0, runInContext_1.getContext)());
|
|
101
99
|
};
|
|
102
100
|
}
|
|
103
101
|
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":";;;AAAA,qCAA8H;AAC9H,sDAAwD;AAIxD,wDAAiD;AAQjD,SAAgB,cAAc,CAAC,MAAW,EAAE,WAAmB,EAAE,QAAgC;IAC/F,MAAM,CAAC,cAAc,CAAC,IAAA,kBAAW,EAAC,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;AArBD,wCAqB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BAEhC,IAAI,IAAA,gBAAS,EAAC,IAAI,CAAC,EAAE;4BACnB,IAAI,CAAC,IAAI,CAAC,CAAC,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,+BAAwB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;SACjF;IACH,CAAC,CAAC;AACJ,CAAC;AA5CD,wBA4CC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,aAAa;IAC3B,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAA,yBAAU,GAAE,CAAC,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC;AAJD,sCAIC","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"]}
|
|
@@ -2,8 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Intercept = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
function bindMethod(target, propertyKey, descriptor, { options, useType }) {
|
|
6
|
+
const originalMethod = descriptor.value;
|
|
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
|
+
}
|
|
7
32
|
/**
|
|
8
33
|
* Attaches interceptor to method call and executes the before and after methods
|
|
9
34
|
*
|
|
@@ -20,15 +45,10 @@ function Intercept(interceptor, options) {
|
|
|
20
45
|
(0, core_1.decorateMethodsOf)(target, Intercept(interceptor, options));
|
|
21
46
|
break;
|
|
22
47
|
case core_1.DecoratorTypes.METHOD:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
propertyKey,
|
|
27
|
-
useType: interceptor,
|
|
28
|
-
bindingType: InjectablePropertyType_1.InjectablePropertyType.INTERCEPTOR
|
|
29
|
-
}
|
|
48
|
+
return bindMethod(target, propertyKey, descriptor, {
|
|
49
|
+
options,
|
|
50
|
+
useType: interceptor
|
|
30
51
|
});
|
|
31
|
-
return descriptor;
|
|
32
52
|
}
|
|
33
53
|
};
|
|
34
54
|
}
|
|
@@ -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,qCAAyG;AAKzG,SAAS,UAAU,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAC,OAAO,EAAE,OAAO,EAAM;IAC3G,MAAM,cAAc,GAAI,UAAiC,CAAC,KAAK,CAAC;IAEhE,OAAO;QACL,GAAG,UAAU;QACb,KAAK,CAAC,GAAG,IAAW;YAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,UAA6B,CAAC;YACpD,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,EAAE;gBAC3B,IAAI,CAAC,GAAG,EAAE;oBACR,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;iBACzC;gBAED,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC;YAEF,MAAM,OAAO,GAA4B;gBACvC,MAAM;gBACN,WAAW;gBACX,IAAI;gBACJ,OAAO;gBACP,IAAI;aACL,CAAC;YAEF,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAqB,OAAO,CAAE,CAAC;YAE/D,OAAO,WAAW,CAAC,SAAU,CAC3B;gBACE,GAAG,OAAO;gBACV,OAAO;aACR,EACD,IAAI,CACL,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;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,OAAO,UAAU,CAAC,MAAM,EAAE,WAAqB,EAAE,UAAgC,EAAE;oBACjF,OAAO;oBACP,OAAO,EAAE,WAAW;iBACrB,CAAC,CAAC;SACN;IACH,CAAC,CAAC;AACJ,CAAC;AAfD,8BAeC","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"]}
|
|
@@ -25,23 +25,22 @@ 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
|
|
29
|
-
(0, inject_1.injectProperty)(target, propertyKey, {
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
let token;
|
|
29
|
+
(0, inject_1.injectProperty)(target, propertyKey, (injector) => {
|
|
30
|
+
let bean;
|
|
31
|
+
return async () => {
|
|
32
|
+
if (!token) {
|
|
33
|
+
const exports = await (0, core_1.importPackage)(packageName, resolver, optional);
|
|
34
|
+
token = exports[key];
|
|
32
35
|
if (!token) {
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
}
|
|
36
|
+
if (!optional) {
|
|
37
|
+
throw new Error(`Unable to lazy load the "${key}". The token isn\'t a valid token provider.`);
|
|
39
38
|
}
|
|
40
|
-
bean = token ? await injector.lazyInvoke(token) : {};
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
40
|
+
bean = token ? await injector.lazyInvoke(token) : {};
|
|
41
|
+
}
|
|
42
|
+
return bean;
|
|
43
|
+
};
|
|
45
44
|
});
|
|
46
45
|
};
|
|
47
46
|
}
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"lazyInject.js","sourceRoot":"","sources":["../../../src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";\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"]}
|
|
@@ -50,11 +50,7 @@ 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).merge(constants_1.
|
|
54
|
-
[propertyKey]: {
|
|
55
|
-
options
|
|
56
|
-
}
|
|
57
|
-
});
|
|
53
|
+
core_1.Store.from(target, propertyKey).merge(constants_1.DI_PARAM_OPTIONS, options);
|
|
58
54
|
break;
|
|
59
55
|
default:
|
|
60
56
|
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,sDAAwD;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC,4BAAgB,EAAE,OAAO,CAAC,CAAC;gBACjE,MAAM;YAER;gBACE,MAAM,IAAI,+BAAwB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;SAC7E;IACH,CAAC,CAAC;AACJ,CAAC;AAjBD,0BAiBC","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"]}
|
|
@@ -2,8 +2,6 @@
|
|
|
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");
|
|
7
5
|
/**
|
|
8
6
|
* Return value from Configuration.
|
|
9
7
|
*
|
|
@@ -41,13 +39,15 @@ const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
|
41
39
|
*/
|
|
42
40
|
function Value(expression, defaultValue) {
|
|
43
41
|
return (target, propertyKey) => {
|
|
44
|
-
core_1.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
42
|
+
Object.defineProperty((0, core_1.prototypeOf)(target), propertyKey, {
|
|
43
|
+
get() {
|
|
44
|
+
return this.$$injector.settings.get(expression, defaultValue);
|
|
45
|
+
},
|
|
46
|
+
set(value) {
|
|
47
|
+
this.$$injector.settings.set(expression, value);
|
|
48
|
+
},
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true
|
|
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,qCAAuC;AAGvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,KAAK,CAAC,UAAe,EAAE,YAAkB;IACvD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,CAAC,cAAc,CAAC,IAAA,kBAAW,EAAC,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;AAbD,sBAaC","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,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,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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/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);
|
|
35
36
|
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,5 +55,7 @@ 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);
|
|
58
60
|
tslib_1.__exportStar(require("./utils/setLoggerLevel"), exports);
|
|
59
61
|
//# 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,
|
|
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,uEAA6C;AAC7C,kEAAwC;AACxC,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,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/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"]}
|
|
@@ -11,6 +11,7 @@ class DIConfiguration {
|
|
|
11
11
|
resolvers: [],
|
|
12
12
|
imports: [],
|
|
13
13
|
routes: [],
|
|
14
|
+
logger: {},
|
|
14
15
|
...initialProps
|
|
15
16
|
}).forEach(([key, value]) => {
|
|
16
17
|
this.default.set(key, value);
|
|
@@ -21,29 +22,60 @@ class DIConfiguration {
|
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
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
|
+
}
|
|
24
43
|
get scopes() {
|
|
25
|
-
return this.
|
|
44
|
+
return this.map.get("scopes");
|
|
26
45
|
}
|
|
27
46
|
set scopes(value) {
|
|
28
|
-
this.
|
|
47
|
+
this.map.set("scopes", value);
|
|
29
48
|
}
|
|
30
49
|
get resolvers() {
|
|
31
50
|
return this.getRaw("resolvers");
|
|
32
51
|
}
|
|
33
52
|
set resolvers(resolvers) {
|
|
34
|
-
this.
|
|
53
|
+
this.map.set("resolvers", resolvers);
|
|
35
54
|
}
|
|
36
55
|
get imports() {
|
|
37
|
-
return this.
|
|
56
|
+
return this.get("imports");
|
|
38
57
|
}
|
|
39
58
|
set imports(imports) {
|
|
40
|
-
this.
|
|
59
|
+
this.map.set("imports", imports);
|
|
41
60
|
}
|
|
42
61
|
get routes() {
|
|
43
|
-
return this.
|
|
62
|
+
return this.get("routes");
|
|
44
63
|
}
|
|
45
64
|
set routes(routes) {
|
|
46
|
-
this.
|
|
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" };
|
|
47
79
|
}
|
|
48
80
|
/**
|
|
49
81
|
*
|
|
@@ -62,11 +94,17 @@ class DIConfiguration {
|
|
|
62
94
|
*/
|
|
63
95
|
set(propertyKey, value) {
|
|
64
96
|
if (typeof propertyKey === "string") {
|
|
65
|
-
|
|
97
|
+
if (propertyKey in this) {
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
this[propertyKey] = value;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.setRaw(propertyKey, value);
|
|
103
|
+
}
|
|
66
104
|
}
|
|
67
105
|
else {
|
|
68
106
|
Object.entries(propertyKey).forEach(([key, value]) => {
|
|
69
|
-
this
|
|
107
|
+
this.set(key, value);
|
|
70
108
|
});
|
|
71
109
|
}
|
|
72
110
|
return this;
|
|
@@ -82,7 +120,7 @@ class DIConfiguration {
|
|
|
82
120
|
* @returns {undefined|any}
|
|
83
121
|
*/
|
|
84
122
|
get(propertyKey, defaultValue) {
|
|
85
|
-
return this.
|
|
123
|
+
return this.getRaw(propertyKey, defaultValue);
|
|
86
124
|
}
|
|
87
125
|
getRaw(propertyKey, defaultValue) {
|
|
88
126
|
const value = (0, core_1.getValue)(this.map, propertyKey);
|
|
@@ -91,45 +129,13 @@ class DIConfiguration {
|
|
|
91
129
|
}
|
|
92
130
|
return (0, core_1.getValue)(this.default, propertyKey, defaultValue);
|
|
93
131
|
}
|
|
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
|
-
}
|
|
104
132
|
/**
|
|
105
133
|
*
|
|
106
134
|
* @param value
|
|
107
135
|
* @returns {any}
|
|
108
136
|
*/
|
|
109
137
|
resolve(value) {
|
|
110
|
-
|
|
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);
|
|
138
|
+
return value.replace("${rootDir}", this.rootDir);
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
141
|
exports.DIConfiguration = DIConfiguration;
|