@tsed/di 7.0.0-beta.12 → 7.0.0-beta.15
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/jest.config.js +14 -0
- package/lib/cjs/decorators/controller.js.map +1 -1
- package/lib/cjs/domain/Container.js +1 -2
- package/lib/cjs/domain/Container.js.map +1 -1
- package/lib/cjs/domain/ContextLogger.js +54 -30
- package/lib/cjs/domain/ContextLogger.js.map +1 -1
- package/lib/cjs/domain/ControllerProvider.js +37 -0
- package/lib/cjs/domain/ControllerProvider.js.map +1 -0
- package/lib/cjs/domain/DIContext.js +58 -26
- package/lib/cjs/domain/DIContext.js.map +1 -1
- package/lib/cjs/domain/Provider.js +11 -1
- package/lib/cjs/domain/Provider.js.map +1 -1
- package/lib/cjs/errors/InjectionError.js +3 -2
- package/lib/cjs/errors/InjectionError.js.map +1 -1
- package/lib/cjs/errors/UndefinedTokenError.js +1 -1
- package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
- package/lib/cjs/index.js +5 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
- package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
- package/lib/cjs/interfaces/DILoggerOptions.js +3 -0
- package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -1
- package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
- package/lib/cjs/registries/GlobalProviders.js +6 -12
- package/lib/cjs/registries/GlobalProviders.js.map +1 -1
- package/lib/cjs/services/DIConfiguration.js +51 -45
- package/lib/cjs/services/DIConfiguration.js.map +1 -1
- package/lib/cjs/services/DITest.js +4 -5
- package/lib/cjs/services/DITest.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +56 -73
- package/lib/cjs/services/InjectorService.js.map +1 -1
- package/lib/cjs/utils/getConfiguration.js +3 -9
- package/lib/cjs/utils/getConfiguration.js.map +1 -1
- package/lib/cjs/utils/resolveControllers.js +1 -1
- package/lib/cjs/utils/resolveControllers.js.map +1 -1
- package/lib/cjs/utils/runInContext.js +19 -6
- package/lib/cjs/utils/runInContext.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/decorators/controller.js.map +1 -1
- package/lib/esm/domain/Container.js +1 -2
- package/lib/esm/domain/Container.js.map +1 -1
- package/lib/esm/domain/ContextLogger.js +54 -30
- package/lib/esm/domain/ContextLogger.js.map +1 -1
- package/lib/esm/domain/ControllerProvider.js +33 -0
- package/lib/esm/domain/ControllerProvider.js.map +1 -0
- package/lib/esm/domain/DIContext.js +58 -26
- package/lib/esm/domain/DIContext.js.map +1 -1
- package/lib/esm/domain/Provider.js +11 -1
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/errors/InjectionError.js +3 -2
- package/lib/esm/errors/InjectionError.js.map +1 -1
- package/lib/esm/errors/UndefinedTokenError.js +1 -1
- package/lib/esm/errors/UndefinedTokenError.js.map +1 -1
- package/lib/esm/index.js +5 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/AlterRunInContext.js +2 -0
- package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
- package/lib/esm/interfaces/DILoggerOptions.js +2 -0
- package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/esm/interfaces/InterceptorMethods.js.map +1 -1
- package/lib/esm/interfaces/TokenProvider.js.map +1 -1
- package/lib/esm/registries/GlobalProviders.js +6 -12
- package/lib/esm/registries/GlobalProviders.js.map +1 -1
- package/lib/esm/services/DIConfiguration.js +52 -46
- package/lib/esm/services/DIConfiguration.js.map +1 -1
- package/lib/esm/services/DITest.js +4 -5
- package/lib/esm/services/DITest.js.map +1 -1
- package/lib/esm/services/InjectorService.js +57 -74
- package/lib/esm/services/InjectorService.js.map +1 -1
- package/lib/esm/utils/getConfiguration.js +3 -9
- package/lib/esm/utils/getConfiguration.js.map +1 -1
- package/lib/esm/utils/resolveControllers.js +1 -1
- package/lib/esm/utils/resolveControllers.js.map +1 -1
- package/lib/esm/utils/runInContext.js +18 -6
- package/lib/esm/utils/runInContext.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/decorators/controller.d.ts +0 -1
- package/lib/types/domain/ContextLogger.d.ts +15 -18
- package/lib/types/domain/ControllerProvider.d.ts +17 -0
- package/lib/types/domain/DIContext.d.ts +16 -19
- package/lib/types/index.d.ts +5 -0
- package/lib/types/interfaces/AlterRunInContext.d.ts +4 -0
- package/lib/types/interfaces/DIConfigurationOptions.d.ts +1 -2
- package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
- package/lib/types/interfaces/InterceptorMethods.d.ts +1 -1
- package/lib/types/interfaces/TokenProvider.d.ts +1 -1
- package/lib/types/services/DIConfiguration.d.ts +17 -12
- package/lib/types/services/InjectorService.d.ts +11 -17
- package/lib/types/utils/runInContext.d.ts +2 -1
- 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 +10 -9
- package/readme.md +1 -1
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
+
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require("@tsed/jest-config")(__dirname, "di"),
|
|
6
|
+
coverageThreshold: {
|
|
7
|
+
global: {
|
|
8
|
+
statements: 99.1,
|
|
9
|
+
branches: 92.91,
|
|
10
|
+
functions: 99.23,
|
|
11
|
+
lines: 99.21
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/decorators/controller.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAA4C;AAE5C,qEAAkE;
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/decorators/controller.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAA4C;AAE5C,qEAAkE;AAgBlE,SAAS,UAAU,CAAC,OAAY;IAC9B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,MAAM,IAAI,IAAA,0BAAmB,EAAC,OAAO,CAAC,EAAE;QAC5F,OAAO;YACL,IAAI,EAAE,OAAO;SACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,UAAU,CAAC,OAAqC;IAC9D,MAAM,EAAC,QAAQ,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,EAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAE3D,OAAO,IAAA,oBAAa,EAClB,CAAC,MAAY,EAAE,EAAE;QACf,IAAA,qCAAkB,EAAC;YACjB,OAAO,EAAE,MAAM;YACf,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC,EACD,IAAI,IAAI,IAAA,aAAI,EAAC,IAAW,CAAC,EACzB,IAAA,iBAAQ,EAAC,GAAG,QAAQ,CAAC,CACtB,CAAC;AACJ,CAAC;AAbD,gCAaC","sourcesContent":["import {isArrayOrArrayClass, Type, useDecorators} from \"@tsed/core\";\nimport {Children, Path} from \"@tsed/schema\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {registerController} from \"../registries/ProviderRegistry\";\n\nexport type PathType = string | RegExp | (string | RegExp)[];\n\nexport interface ControllerMiddlewares {\n useBefore: any[];\n use: any[];\n useAfter: any[];\n}\n\nexport interface ControllerOptions extends Partial<ProviderOpts<any>> {\n path?: PathType;\n children?: Type<any>[];\n middlewares?: Partial<ControllerMiddlewares>;\n}\n\nfunction mapOptions(options: any): ControllerOptions {\n if (typeof options === \"string\" || options instanceof RegExp || isArrayOrArrayClass(options)) {\n return {\n path: options\n };\n }\n\n return options;\n}\n\n/**\n * Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.\n * This routing listing will be built with the `express.Router` object.\n *\n * ::: tip\n * See [Controllers](/docs/controllers.md) section for more details\n * :::\n *\n * ```typescript\n * @Controller(\"/calendars\")\n * export provide CalendarCtrl {\n *\n * @Get(\"/:id\")\n * public get(\n * @Req() request: Req,\n * @Res() response: Res,\n * @Next() next: Next\n * ): void {\n *\n * }\n * }\n * ```\n *\n * @param options\n * @controller\n * @decorator\n * @classDecorator\n */\nexport function Controller(options: PathType | ControllerOptions): ClassDecorator {\n const {children = [], path, ...opts} = mapOptions(options);\n\n return useDecorators(\n (target: Type) => {\n registerController({\n provide: target,\n ...opts\n });\n },\n path && Path(path as any),\n Children(...children)\n );\n}\n"]}
|
|
@@ -10,8 +10,7 @@ class Container extends Map {
|
|
|
10
10
|
* @param settings
|
|
11
11
|
*/
|
|
12
12
|
add(token, settings = {}) {
|
|
13
|
-
|
|
14
|
-
const provider = ((_a = GlobalProviders_1.GlobalProviders.get(token)) === null || _a === void 0 ? void 0 : _a.clone()) || new Provider_1.Provider(token);
|
|
13
|
+
const provider = GlobalProviders_1.GlobalProviders.get(token)?.clone() || new Provider_1.Provider(token);
|
|
15
14
|
Object.assign(provider, settings);
|
|
16
15
|
return super.set(token, provider);
|
|
17
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Container.js","sourceRoot":"","sources":["../../../src/domain/Container.ts"],"names":[],"mappings":";;;AAGA,mEAA8D;AAC9D,yCAAoC;AAEpC,MAAa,SAAU,SAAQ,GAA4B;IACzD;;;;OAIG;IACI,GAAG,CAAC,KAAoB,EAAE,WAAkC,EAAE
|
|
1
|
+
{"version":3,"file":"Container.js","sourceRoot":"","sources":["../../../src/domain/Container.ts"],"names":[],"mappings":";;;AAGA,mEAA8D;AAC9D,yCAAoC;AAEpC,MAAa,SAAU,SAAQ,GAA4B;IACzD;;;;OAIG;IACI,GAAG,CAAC,KAAoB,EAAE,WAAkC,EAAE;QACnE,MAAM,QAAQ,GAAG,iCAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,IAAI,mBAAQ,CAAC,KAAK,CAAC,CAAC;QAE5E,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAElC,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,KAAoB,EAAE,WAAkC,EAAE;QAC3E,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,WAAW,CAAC,KAAoB;QACrC,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,KAAoB,EAAE,QAAkB;QACzD,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAgC,KAAoB;QACpE,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAM,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACI,YAAY,CAAC,IAA4B;QAC9C,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE;YACnD,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE;gBACnC,OAAO,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC;aACjC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;IAEM,YAAY,CAAC,SAAuC;QACzD,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBACvC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;aACtD;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvED,8BAuEC","sourcesContent":["import type {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport type {ProviderType} from \"./ProviderType\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {Provider} from \"./Provider\";\n\nexport class Container extends Map<TokenProvider, Provider> {\n /**\n *\n * @param token\n * @param settings\n */\n public add(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n const provider = GlobalProviders.get(token)?.clone() || new Provider(token);\n\n Object.assign(provider, settings);\n\n return super.set(token, provider);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param settings\n */\n public addProvider(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n return this.add(token, settings);\n }\n\n /**\n *\n * @param token\n */\n public hasProvider(token: TokenProvider) {\n return super.has(token);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param provider\n */\n public setProvider(token: TokenProvider, provider: Provider) {\n return super.set(token, provider);\n }\n\n /**\n * The getProvider() method returns a specified element from a Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n * @param token\n */\n public getProvider<T extends Provider = Provider>(token: TokenProvider): T | undefined {\n return super.get(token) as T;\n }\n\n /**\n * Get all providers registered in the injector container.\n *\n * @param {ProviderType} type Filter the list by the given ProviderType.\n * @returns {[TokenProvider , Provider<any>][]}\n */\n public getProviders(type?: ProviderType | string): Provider[] {\n return [...this].reduce((providers, [_, provider]) => {\n if (provider.type === type || !type) {\n return [...providers, provider];\n }\n return providers;\n }, []);\n }\n\n public addProviders(container: Map<TokenProvider, Provider>) {\n container.forEach((provider) => {\n if (!this.hasProvider(provider.provide)) {\n this.setProvider(provider.provide, provider.clone());\n }\n });\n }\n}\n"]}
|
|
@@ -1,60 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ContextLogger = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
4
5
|
const logger_1 = require("@tsed/logger");
|
|
6
|
+
const LEVELS = (0, logger_1.levels)();
|
|
5
7
|
class ContextLogger {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
$ctx;
|
|
9
|
+
dateStart;
|
|
10
|
+
#additionalProps;
|
|
11
|
+
#hooks;
|
|
12
|
+
#maxStackSize;
|
|
13
|
+
#stack;
|
|
14
|
+
#level;
|
|
15
|
+
#logger;
|
|
16
|
+
constructor($ctx) {
|
|
17
|
+
this.$ctx = $ctx;
|
|
18
|
+
const { logger, dateStart = new Date(), level = "all", maxStackSize = 30, additionalProps } = $ctx.opts;
|
|
12
19
|
this.dateStart = dateStart;
|
|
13
|
-
this
|
|
14
|
-
this
|
|
15
|
-
this
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
this.#logger = logger;
|
|
21
|
+
this.#additionalProps = additionalProps;
|
|
22
|
+
this.#level = (LEVELS[level.toUpperCase()] || LEVELS.ALL);
|
|
23
|
+
this.#maxStackSize = maxStackSize;
|
|
24
|
+
}
|
|
25
|
+
get id() {
|
|
26
|
+
return this.$ctx.id;
|
|
27
|
+
}
|
|
28
|
+
set maxStackSize(maxStackSize) {
|
|
29
|
+
this.#maxStackSize = maxStackSize;
|
|
30
|
+
}
|
|
31
|
+
get hooks() {
|
|
32
|
+
return (this.#hooks = this.#hooks || new core_1.Hooks());
|
|
33
|
+
}
|
|
34
|
+
get stack() {
|
|
35
|
+
return (this.#stack = this.#stack || []);
|
|
36
|
+
}
|
|
37
|
+
alterLog(cb) {
|
|
38
|
+
return this.hooks.on("log", cb);
|
|
39
|
+
}
|
|
40
|
+
alterIgnoreLog(cb) {
|
|
41
|
+
return this.hooks.on("ignore", cb);
|
|
19
42
|
}
|
|
20
43
|
info(obj) {
|
|
21
|
-
this.run((0, logger_1.levels)().INFO, obj
|
|
44
|
+
this.run((0, logger_1.levels)().INFO, obj);
|
|
22
45
|
return this;
|
|
23
46
|
}
|
|
24
47
|
debug(obj, withRequest = true) {
|
|
25
|
-
this.run((0, logger_1.levels)().DEBUG, obj,
|
|
26
|
-
obj = this.getData(obj);
|
|
27
|
-
return withRequest ? this.completeRequestPicker(obj) : obj;
|
|
28
|
-
});
|
|
48
|
+
this.run((0, logger_1.levels)().DEBUG, obj, withRequest);
|
|
29
49
|
return this;
|
|
30
50
|
}
|
|
31
51
|
warn(obj) {
|
|
32
|
-
this.run((0, logger_1.levels)().WARN, obj
|
|
52
|
+
this.run((0, logger_1.levels)().WARN, obj);
|
|
33
53
|
return this;
|
|
34
54
|
}
|
|
35
55
|
error(obj) {
|
|
36
|
-
this.run((0, logger_1.levels)().ERROR, obj
|
|
56
|
+
this.run((0, logger_1.levels)().ERROR, obj);
|
|
37
57
|
return this;
|
|
38
58
|
}
|
|
39
59
|
trace(obj) {
|
|
40
|
-
this.run((0, logger_1.levels)().TRACE, obj
|
|
60
|
+
this.run((0, logger_1.levels)().TRACE, obj);
|
|
41
61
|
return this;
|
|
42
62
|
}
|
|
43
63
|
flush() {
|
|
44
64
|
if (this.stack.length) {
|
|
45
65
|
this.stack.forEach(({ level, data }) => {
|
|
46
|
-
this
|
|
66
|
+
this.#logger[level](data);
|
|
47
67
|
});
|
|
48
|
-
this
|
|
68
|
+
this.#stack = [];
|
|
49
69
|
}
|
|
50
70
|
}
|
|
51
71
|
isLevelEnabled(otherLevel) {
|
|
52
|
-
return this
|
|
72
|
+
return this.#level.isLessThanOrEqualTo(otherLevel);
|
|
53
73
|
}
|
|
54
74
|
destroy() {
|
|
55
75
|
this.flush();
|
|
56
|
-
this
|
|
57
|
-
this
|
|
76
|
+
this.#maxStackSize = 0;
|
|
77
|
+
this.#stack = [];
|
|
78
|
+
this.#logger = null;
|
|
58
79
|
}
|
|
59
80
|
/**
|
|
60
81
|
* Return the duration between the time when LogIncomingRequest has handle the request and now.
|
|
@@ -67,16 +88,19 @@ class ContextLogger {
|
|
|
67
88
|
if (typeof obj === "string") {
|
|
68
89
|
obj = { message: obj };
|
|
69
90
|
}
|
|
70
|
-
return { ...this
|
|
91
|
+
return { ...this.#additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj };
|
|
71
92
|
}
|
|
72
|
-
run(level, obj,
|
|
93
|
+
run(level, obj, withRequest) {
|
|
73
94
|
if (!this.isLevelEnabled(level)) {
|
|
74
95
|
return;
|
|
75
96
|
}
|
|
76
|
-
|
|
77
|
-
|
|
97
|
+
const ignore = this.#hooks?.alter("ignore", false, [obj]);
|
|
98
|
+
if (!ignore) {
|
|
99
|
+
const levelStr = level.levelStr.toLowerCase();
|
|
100
|
+
obj = this.hooks.alter("log", this.getData(obj), [levelStr, withRequest]);
|
|
101
|
+
this.stack.push({ level: levelStr, data: obj });
|
|
78
102
|
}
|
|
79
|
-
if (this
|
|
103
|
+
if (this.#maxStackSize < this.stack.length) {
|
|
80
104
|
this.flush();
|
|
81
105
|
}
|
|
82
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextLogger.js","sourceRoot":"","sources":["../../../src/domain/ContextLogger.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;
|
|
1
|
+
{"version":3,"file":"ContextLogger.js","sourceRoot":"","sources":["../../../src/domain/ContextLogger.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,yCAA8C;AAY9C,MAAM,MAAM,GAA6B,IAAA,eAAM,GAAE,CAAC;AAElD,MAAa,aAAa;IAUH;IATZ,SAAS,CAAO;IAChB,gBAAgB,CAA2B;IAEpD,MAAM,CAAS;IACf,aAAa,CAAS;IACtB,MAAM,CAAS;IACf,MAAM,CAAW;IACjB,OAAO,CAAM;IAEb,YAAqB,IAAe;QAAf,SAAI,GAAJ,IAAI,CAAW;QAClC,MAAM,EAAC,MAAM,EAAE,SAAS,GAAG,IAAI,IAAI,EAAE,EAAE,KAAK,GAAG,KAAK,EAAE,YAAY,GAAG,EAAE,EAAE,eAAe,EAAC,GAAG,IAAI,CAAC,IAAI,CAAC;QACtG,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAa,CAAC;QACtE,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IACtB,CAAC;IAED,IAAI,YAAY,CAAC,YAAoB;QACnC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAA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AE;YACX,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;YAE9C,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;YAE1E,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAC,CAAC,CAAC;SAC/C;QAED,IAAI,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YAC1C,IAAI,CAAC,KAAK,EAAE,CAAC;SACd;IACH,CAAC;CACF;AA5HD,sCA4HC","sourcesContent":["import {Hooks} from \"@tsed/core\";\nimport {levels, LogLevel} from \"@tsed/logger\";\nimport {DILogger} from \"../interfaces/DILogger\";\nimport type {DIContext} from \"./DIContext\";\n\nexport interface ContextLoggerOptions extends Record<string, any> {\n id: string;\n logger?: DILogger;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\" | \"all\";\n maxStackSize?: number;\n additionalProps?: Record<any, any>;\n}\n\nconst LEVELS: Record<string, LogLevel> = levels();\n\nexport class ContextLogger {\n readonly dateStart: Date;\n readonly #additionalProps?: Record<string, unknown>;\n\n #hooks?: Hooks;\n #maxStackSize: number;\n #stack?: any[];\n #level: LogLevel;\n #logger: any;\n\n constructor(readonly $ctx: DIContext) {\n const {logger, dateStart = new Date(), level = \"all\", maxStackSize = 30, additionalProps} = $ctx.opts;\n this.dateStart = dateStart;\n this.#logger = logger;\n this.#additionalProps = additionalProps;\n this.#level = (LEVELS[level.toUpperCase()] || LEVELS.ALL) as LogLevel;\n this.#maxStackSize = maxStackSize;\n }\n\n get id() {\n return this.$ctx.id;\n }\n\n set maxStackSize(maxStackSize: number) {\n this.#maxStackSize = maxStackSize;\n }\n\n get hooks() {\n return (this.#hooks = this.#hooks || new Hooks());\n }\n\n private get stack() {\n return (this.#stack = this.#stack || []);\n }\n\n alterLog(cb: (data: any, level: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\" | \"all\", withRequest: boolean) => any) {\n return this.hooks.on(\"log\", cb);\n }\n\n alterIgnoreLog(cb: (ignore: boolean, data: any) => boolean) {\n return this.hooks.on(\"ignore\", cb);\n }\n\n info(obj: any) {\n this.run(levels().INFO, obj);\n return this;\n }\n\n debug(obj: any, withRequest: boolean = true) {\n this.run(levels().DEBUG, obj, withRequest);\n return this;\n }\n\n warn(obj: any) {\n this.run(levels().WARN, obj);\n return this;\n }\n\n error(obj: any) {\n this.run(levels().ERROR, obj);\n return this;\n }\n\n trace(obj: any) {\n this.run(levels().TRACE, obj);\n return this;\n }\n\n public flush() {\n if (this.stack.length) {\n this.stack.forEach(({level, data}: any) => {\n this.#logger[level](data);\n });\n\n this.#stack = [];\n }\n }\n\n public isLevelEnabled(otherLevel: string | LogLevel) {\n return this.#level.isLessThanOrEqualTo(otherLevel);\n }\n\n destroy() {\n this.flush();\n this.#maxStackSize = 0;\n this.#stack = [];\n this.#logger = null;\n }\n\n /**\n * Return the duration between the time when LogIncomingRequest has handle the request and now.\n * @returns {number}\n */\n protected getDuration(): number {\n return new Date().getTime() - this.dateStart.getTime();\n }\n\n protected getData(obj: any) {\n if (typeof obj === \"string\") {\n obj = {message: obj};\n }\n\n return {...this.#additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj};\n }\n\n protected run(level: LogLevel, obj: any, withRequest?: boolean) {\n if (!this.isLevelEnabled(level)) {\n return;\n }\n\n const ignore = this.#hooks?.alter(\"ignore\", false, [obj]);\n\n if (!ignore) {\n const levelStr = level.levelStr.toLowerCase();\n\n obj = this.hooks.alter(\"log\", this.getData(obj), [levelStr, withRequest]);\n\n this.stack.push({level: levelStr, data: obj});\n }\n\n if (this.#maxStackSize < this.stack.length) {\n this.flush();\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ControllerProvider = void 0;
|
|
4
|
+
const Provider_1 = require("./Provider");
|
|
5
|
+
const ProviderType_1 = require("./ProviderType");
|
|
6
|
+
class ControllerProvider extends Provider_1.Provider {
|
|
7
|
+
tokenRouter;
|
|
8
|
+
constructor(provide, options = {}) {
|
|
9
|
+
super(provide, options);
|
|
10
|
+
this.type = ProviderType_1.ProviderType.CONTROLLER;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @returns {any[]}
|
|
15
|
+
*/
|
|
16
|
+
get middlewares() {
|
|
17
|
+
return Object.assign({
|
|
18
|
+
use: [],
|
|
19
|
+
useAfter: [],
|
|
20
|
+
useBefore: []
|
|
21
|
+
}, this.store.get("middlewares", {}));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param middlewares
|
|
26
|
+
*/
|
|
27
|
+
set middlewares(middlewares) {
|
|
28
|
+
const mdlwrs = this.middlewares;
|
|
29
|
+
const concat = (key, a, b) => (a[key] = a[key].concat(b[key]));
|
|
30
|
+
Object.keys(middlewares).forEach((key) => {
|
|
31
|
+
concat(key, mdlwrs, middlewares);
|
|
32
|
+
});
|
|
33
|
+
this.store.set("middlewares", mdlwrs);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ControllerProvider = ControllerProvider;
|
|
37
|
+
//# sourceMappingURL=ControllerProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControllerProvider.js","sourceRoot":"","sources":["../../../src/domain/ControllerProvider.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,iDAA4C;AAE5C,MAAa,kBAA4B,SAAQ,mBAAW;IACnD,WAAW,CAAS;IAE3B,YAAY,OAAsB,EAAE,UAA6B,EAAE;QACjE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,2BAAY,CAAC,UAAU,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW;QACb,OAAO,MAAM,CAAC,MAAM,CAClB;YACE,GAAG,EAAE,EAAE;YACP,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,EAAE;SACd,EACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW,CAAC,WAAkC;QAChD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;QAChC,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAEjF,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;YAC/C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;CACF;AArCD,gDAqCC","sourcesContent":["import {ControllerMiddlewares} from \"../decorators/controller\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {Provider} from \"./Provider\";\nimport {ProviderType} from \"./ProviderType\";\n\nexport class ControllerProvider<T = any> extends Provider<T> {\n public tokenRouter: string;\n\n constructor(provide: TokenProvider, options: Partial<Provider> = {}) {\n super(provide, options);\n this.type = ProviderType.CONTROLLER;\n }\n\n /**\n *\n * @returns {any[]}\n */\n get middlewares(): ControllerMiddlewares {\n return Object.assign(\n {\n use: [],\n useAfter: [],\n useBefore: []\n },\n this.store.get(\"middlewares\", {})\n );\n }\n\n /**\n *\n * @param middlewares\n */\n set middlewares(middlewares: ControllerMiddlewares) {\n const mdlwrs = this.middlewares;\n const concat = (key: string, a: any, b: any) => (a[key] = a[key].concat(b[key]));\n\n Object.keys(middlewares).forEach((key: string) => {\n concat(key, mdlwrs, middlewares);\n });\n\n this.store.set(\"middlewares\", mdlwrs);\n }\n}\n"]}
|
|
@@ -1,44 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DIContext = void 0;
|
|
4
|
+
const runInContext_1 = require("../utils/runInContext");
|
|
4
5
|
const ContextLogger_1 = require("./ContextLogger");
|
|
5
6
|
const LocalsContainer_1 = require("./LocalsContainer");
|
|
6
7
|
class DIContext extends Map {
|
|
7
|
-
|
|
8
|
+
options;
|
|
9
|
+
opts;
|
|
10
|
+
/**
|
|
11
|
+
* The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
|
|
12
|
+
*/
|
|
13
|
+
container = new LocalsContainer_1.LocalsContainer();
|
|
14
|
+
/**
|
|
15
|
+
* Logger attached to the context request.
|
|
16
|
+
*/
|
|
17
|
+
logger;
|
|
18
|
+
constructor(options) {
|
|
8
19
|
super();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.opts = options;
|
|
22
|
+
this.logger = new ContextLogger_1.ContextLogger(this);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Request id generated by @@contextMiddleware@@.
|
|
26
|
+
*
|
|
27
|
+
* ::: tip
|
|
28
|
+
* By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, ""))`.
|
|
29
|
+
* Dash are removed to simplify tracking logs in Kibana
|
|
30
|
+
* :::
|
|
31
|
+
*
|
|
32
|
+
* ::: tip
|
|
33
|
+
* Request id can by customized by changing the server configuration.
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* @Configuration({
|
|
37
|
+
* logger: {
|
|
38
|
+
* reqIdBuilder: createUniqId // give your own id generator function
|
|
39
|
+
* }
|
|
40
|
+
* })
|
|
41
|
+
* class Server {
|
|
42
|
+
*
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
* :::
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
get id() {
|
|
49
|
+
return this.opts.id;
|
|
50
|
+
}
|
|
51
|
+
get dateStart() {
|
|
52
|
+
return this.logger.dateStart;
|
|
53
|
+
}
|
|
54
|
+
get injector() {
|
|
55
|
+
return this.opts.injector;
|
|
25
56
|
}
|
|
26
57
|
get env() {
|
|
27
|
-
return this.injector.settings.env;
|
|
58
|
+
return this.injector.settings.get("env");
|
|
28
59
|
}
|
|
29
60
|
async destroy() {
|
|
30
61
|
await this.container.destroy();
|
|
31
62
|
this.logger.destroy();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
delete this.injector;
|
|
63
|
+
this.opts = {
|
|
64
|
+
id: this.opts.id
|
|
65
|
+
};
|
|
66
|
+
this.container = null;
|
|
38
67
|
}
|
|
39
68
|
async emit(eventName, ...args) {
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
return this.injector?.emit(eventName, ...args);
|
|
70
|
+
}
|
|
71
|
+
async runInContext(next) {
|
|
72
|
+
next = (await this.injector?.alterAsync("$alterRunInContext", next, this)) || next;
|
|
73
|
+
return (0, runInContext_1.runInContext)(this, next);
|
|
42
74
|
}
|
|
43
75
|
}
|
|
44
76
|
exports.DIContext = DIContext;
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,wDAAmD;AACnD,mDAAoE;AACpE,uDAAkD;AAkBlD,MAAa,SAAU,SAAQ,GAAa;IAcrB;IAXrB,IAAI,CAAmB;IAEvB;;OAEG;IACI,SAAS,GAAG,IAAI,iCAAe,EAAO,CAAC;IAC9C;;OAEG;IACM,MAAM,CAAgB;IAE/B,YAAqB,OAAyB;QAC5C,KAAK,EAAE,CAAC;QADW,YAAO,GAAP,OAAO,CAAkB;QAE5C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IACtB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,IAAI,CAAC,QAAS,CAAC;IAC7B,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;QACtB,IAAI,CAAC,IAAI,GAAG;YACV,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE;SACV,CAAC;QACT,IAAI,CAAC,SAAS,GAAG,IAAW,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;QAC1C,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,IAAc;QAC/B,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,oBAAoB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;QAEnF,OAAO,IAAA,2BAAY,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AA9ED,8BA8EC","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {runInContext} from \"../utils/runInContext\";\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 injector: InjectorService;\n logger: any;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n\n opts: DIContextOptions;\n\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 constructor(readonly options: DIContextOptions) {\n super();\n this.opts = options;\n this.logger = new ContextLogger(this);\n }\n\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 get id() {\n return this.opts.id;\n }\n\n get dateStart() {\n return this.logger.dateStart;\n }\n\n get injector(): InjectorService {\n return this.opts.injector!;\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 this.opts = {\n id: this.opts.id\n } as any;\n this.container = null as any;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n\n async runInContext(next: Function) {\n next = (await this.injector?.alterAsync(\"$alterRunInContext\", next, this)) || next;\n\n return runInContext(this, next);\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
|
|
@@ -5,8 +5,18 @@ const core_1 = require("@tsed/core");
|
|
|
5
5
|
const ProviderScope_1 = require("./ProviderScope");
|
|
6
6
|
const ProviderType_1 = require("./ProviderType");
|
|
7
7
|
class Provider {
|
|
8
|
+
type = ProviderType_1.ProviderType.PROVIDER;
|
|
9
|
+
deps;
|
|
10
|
+
imports;
|
|
11
|
+
useFactory;
|
|
12
|
+
useAsyncFactory;
|
|
13
|
+
useValue;
|
|
14
|
+
hooks;
|
|
15
|
+
_useClass;
|
|
16
|
+
_provide;
|
|
17
|
+
_store;
|
|
18
|
+
_tokenStore;
|
|
8
19
|
constructor(token, options = {}) {
|
|
9
|
-
this.type = ProviderType_1.ProviderType.PROVIDER;
|
|
10
20
|
this.provide = token;
|
|
11
21
|
this.useClass = token;
|
|
12
22
|
Object.assign(this, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/domain/Provider.ts"],"names":[],"mappings":";;;AAAA,qCAAmF;AAGnF,mDAA8C;AAC9C,iDAA4C;AAE5C,MAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/domain/Provider.ts"],"names":[],"mappings":";;;AAAA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KAAK;QACH,OAAO,IAAI,CAAC,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACI,WAAW;QAChB,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ;QACN,OAAO;YACL,OAAO;YACP,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,QAAQ,IAAI,IAAA,aAAM,EAAC,IAAI,CAAC,QAAQ,CAAC;YACtC,IAAI,CAAC,UAAU,IAAI,SAAS;YAC5B,IAAI,CAAC,QAAQ,IAAI,OAAO;YACxB,IAAI,CAAC,eAAe,IAAI,cAAc;SACvC;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AArJD,4BAqJC","sourcesContent":["import {classOf, getClassOrSymbol, isClass, nameOf, Store, Type} from \"@tsed/core\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {ProviderScope} from \"./ProviderScope\";\nimport {ProviderType} from \"./ProviderType\";\n\nexport class Provider<T = any> implements ProviderOpts<T> {\n public type: ProviderType | any = ProviderType.PROVIDER;\n public deps: TokenProvider[];\n public imports: any[];\n public useFactory: Function;\n public useAsyncFactory: Function;\n public useValue: any;\n public hooks?: Record<string, (instance: T, ...args: any[]) => Promise<void> | void>;\n private _useClass: Type<T>;\n private _provide: TokenProvider;\n private _store: Store;\n private _tokenStore: Store;\n\n [key: string]: any;\n\n constructor(token: TokenProvider, options: Partial<Provider> = {}) {\n this.provide = token;\n this.useClass = token;\n\n Object.assign(this, options);\n }\n\n get token() {\n return this._provide;\n }\n\n get provide(): TokenProvider {\n return this._provide;\n }\n\n set provide(value: TokenProvider) {\n if (value) {\n this._provide = getClassOrSymbol(value);\n this._tokenStore = this._store = Store.from(value);\n }\n }\n\n get useClass(): Type<T> {\n return this._useClass;\n }\n\n /**\n * Create a new store if the given value is a class. Otherwise the value is ignored.\n * @param value\n */\n set useClass(value: Type<T>) {\n if (isClass(value)) {\n this._useClass = classOf(value);\n this._store = Store.from(value);\n }\n }\n\n get className() {\n return this.name;\n }\n\n get name() {\n return nameOf(this.provide);\n }\n\n get store(): Store {\n return this._store;\n }\n\n get path() {\n return this.store.get(\"path\", \"/\");\n }\n\n set path(path: string) {\n this.store.set(\"path\", path);\n }\n\n /**\n * Get the scope of the provider.\n *\n * ::: tip Note\n * Async provider is always a SINGLETON\n * :::\n *\n * @returns {boolean}\n */\n get scope(): ProviderScope {\n if (this.isAsync()) {\n return ProviderScope.SINGLETON;\n }\n\n return this.get(\"scope\");\n }\n\n /**\n * Change the scope value of the provider.\n * @param scope\n */\n set scope(scope: ProviderScope) {\n this.store.set(\"scope\", scope);\n }\n\n get configuration(): Partial<TsED.Configuration> {\n return this.get(\"configuration\");\n }\n\n set configuration(configuration: Partial<TsED.Configuration>) {\n this.store.set(\"configuration\", configuration);\n }\n\n get children(): TokenProvider[] {\n return this.store.get(\"childrenControllers\", []);\n }\n\n get(key: string) {\n return this.store.get(key) || this._tokenStore.get(key);\n }\n\n isAsync(): boolean {\n return !!this.useAsyncFactory;\n }\n\n clone(): Provider {\n return new (classOf(this))(this._provide, this);\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasChildren(): boolean {\n return !!this.children.length;\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasParent(): boolean {\n return !!this.store.get(\"parentController\");\n }\n\n toString() {\n return [\n \"Token\",\n this.name,\n this.useClass && nameOf(this.useClass),\n this.useFactory && \"Factory\",\n this.useValue && \"Value\",\n this.useAsyncFactory && \"AsyncFactory\"\n ]\n .filter(Boolean)\n .join(\":\");\n }\n}\n"]}
|
|
@@ -4,10 +4,11 @@ exports.InjectionError = void 0;
|
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
5
|
const colors_1 = require("../utils/colors");
|
|
6
6
|
class InjectionError extends Error {
|
|
7
|
+
name = "INJECTION_ERROR";
|
|
8
|
+
tokens = [];
|
|
9
|
+
origin;
|
|
7
10
|
constructor(token, origin) {
|
|
8
11
|
super((0, core_1.isString)(origin) ? origin : "");
|
|
9
|
-
this.name = "INJECTION_ERROR";
|
|
10
|
-
this.tokens = [];
|
|
11
12
|
this.tokens = [token];
|
|
12
13
|
if (origin) {
|
|
13
14
|
if ((0, core_1.isString)(origin)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAE7E,4CAAuC;AAEvC,MAAa,cAAe,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAE7E,4CAAuC;AAEvC,MAAa,cAAe,SAAQ,KAAK;IACvC,IAAI,GAAG,iBAAiB,CAAC;IAElB,MAAM,GAAoB,EAAE,CAAC;IAC7B,MAAM,CAAM;IAEnB,YAAY,KAAoB,EAAE,MAAY;QAC5C,KAAK,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;QAEtB,IAAI,MAAM,EAAE;YACV,IAAI,IAAA,eAAQ,EAAC,MAAM,CAAC,EAAE;gBACpB,IAAI,CAAC,MAAM,GAAG;oBACZ,OAAO,EAAE,MAAM;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;iBAClB,CAAC;aACH;iBAAM;gBACL,IAAI,MAAM,CAAC,MAA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O,CAAC,KAAK,KAAK,KAAK,EAAE;YAC3B,UAAU,GAAG,GAAG,CAAC;YACjB,GAAG,GAAG,eAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SACvB;QAED,OAAO,GAAG,GAAG,KAAK,IAAA,aAAM,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,SAAS,GAAG,IAAA,aAAM,EAAC,KAAK,CAAC,GAAG,gBAAgB,GAAG,IAAI,GAAG,GAAG,CAAC;IAChE,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,eAAM,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhH,OAAO,+BAA+B,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACjI,CAAC","sourcesContent":["import {getConstructorArgNames, isClass, isString, nameOf} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {colors} from \"../utils/colors\";\n\nexport class InjectionError extends Error {\n name = \"INJECTION_ERROR\";\n\n public tokens: TokenProvider[] = [];\n public origin: any;\n\n constructor(token: TokenProvider, origin?: any) {\n super(isString(origin) ? origin : \"\");\n\n this.tokens = [token];\n\n if (origin) {\n if (isString(origin)) {\n this.origin = {\n message: origin,\n stack: this.stack\n };\n } else {\n if (origin.tokens) {\n this.tokens = this.tokens.concat(origin.tokens);\n this.origin = origin.origin;\n } else {\n this.origin = origin;\n this.stack = origin.stack;\n }\n }\n }\n\n const originMessage = this.origin ? \"\\nOrigin: \" + this.origin.message : \"\";\n const tokensMessage = this.tokens.map((token) => nameOf(token)).join(\" > \");\n\n this.message = `Injection failed on ${tokensMessage}${originMessage}`;\n }\n\n static throwInjectorError(token: any, currentDependency: any, error: any) {\n if (currentDependency && isClass(token)) {\n error.message = printDependencyInjectionError(token, {...currentDependency, message: error.message});\n }\n\n throw new InjectionError(token, error);\n }\n}\n\nfunction printDependencyInjectionError(token: any, options: {token: any; index: number; deps: any[]; message: string}) {\n let erroredArg = \"\";\n\n const args = getConstructorArgNames(token)\n .map((arg, index) => {\n if (options.index === index) {\n erroredArg = arg;\n arg = colors.red(arg);\n }\n\n return `${arg}: ${nameOf(options.deps[index])}`;\n })\n .join(\", \");\n\n const signature = nameOf(token) + \"->constructor(\" + args + \")\";\n const indexOf = signature.indexOf(erroredArg) - 5;\n const drawline = (indexOf: number) => \" \".repeat(indexOf) + colors.red(\"^\" + \"‾\".repeat(erroredArg.length - 1));\n\n return \"Unable to inject dependency. \" + options.message + \"\\n\\n\" + signature + \"\\n\" + (indexOf > -1 ? drawline(indexOf) : \"\");\n}\n"]}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UndefinedTokenError = void 0;
|
|
4
4
|
class UndefinedTokenError extends Error {
|
|
5
|
+
name = "UNDEFINED_TOKEN_ERROR";
|
|
5
6
|
constructor() {
|
|
6
7
|
super("Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?");
|
|
7
|
-
this.name = "UNDEFINED_TOKEN_ERROR";
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.UndefinedTokenError = UndefinedTokenError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,IAAI,GAAG,uBAAuB,CAAC;IAE/B;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;IACJ,CAAC;CACF;AARD,kDAQC","sourcesContent":["export class UndefinedTokenError extends Error {\n name = \"UNDEFINED_TOKEN_ERROR\";\n\n constructor() {\n super(\n \"Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?\"\n );\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -22,6 +22,7 @@ tslib_1.__exportStar(require("./decorators/useOpts"), exports);
|
|
|
22
22
|
tslib_1.__exportStar(require("./decorators/value"), exports);
|
|
23
23
|
tslib_1.__exportStar(require("./domain/Container"), exports);
|
|
24
24
|
tslib_1.__exportStar(require("./domain/ContextLogger"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./domain/ControllerProvider"), exports);
|
|
25
26
|
tslib_1.__exportStar(require("./domain/DIContext"), exports);
|
|
26
27
|
tslib_1.__exportStar(require("./domain/InjectablePropertyType"), exports);
|
|
27
28
|
tslib_1.__exportStar(require("./domain/LocalsContainer"), exports);
|
|
@@ -30,8 +31,10 @@ tslib_1.__exportStar(require("./domain/ProviderScope"), exports);
|
|
|
30
31
|
tslib_1.__exportStar(require("./domain/ProviderType"), exports);
|
|
31
32
|
tslib_1.__exportStar(require("./errors/InjectionError"), exports);
|
|
32
33
|
tslib_1.__exportStar(require("./errors/UndefinedTokenError"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./interfaces/AlterRunInContext"), exports);
|
|
33
35
|
tslib_1.__exportStar(require("./interfaces/DIConfigurationOptions"), exports);
|
|
34
36
|
tslib_1.__exportStar(require("./interfaces/DILogger"), exports);
|
|
37
|
+
tslib_1.__exportStar(require("./interfaces/DILoggerOptions"), exports);
|
|
35
38
|
tslib_1.__exportStar(require("./interfaces/DIResolver"), exports);
|
|
36
39
|
tslib_1.__exportStar(require("./interfaces/InjectableProperties"), exports);
|
|
37
40
|
tslib_1.__exportStar(require("./interfaces/InterceptorContext"), exports);
|
|
@@ -55,5 +58,7 @@ tslib_1.__exportStar(require("./utils/createContainer"), exports);
|
|
|
55
58
|
tslib_1.__exportStar(require("./utils/getConfiguration"), exports);
|
|
56
59
|
tslib_1.__exportStar(require("./utils/resolveControllers"), exports);
|
|
57
60
|
tslib_1.__exportStar(require("./utils/runInContext"), exports);
|
|
61
|
+
tslib_1.__exportStar(require("./utils/setLoggerConfiguration"), exports);
|
|
62
|
+
tslib_1.__exportStar(require("./utils/setLoggerFormat"), exports);
|
|
58
63
|
tslib_1.__exportStar(require("./utils/setLoggerLevel"), exports);
|
|
59
64
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,8EAAoD;AACpD,gEAAsC;AACtC,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,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"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,sEAA4C;AAC5C,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,yEAA+C;AAC/C,8EAAoD;AACpD,gEAAsC;AACtC,uEAA6C;AAC7C,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,kEAAwC;AACxC,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,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/ControllerProvider\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/AlterRunInContext\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/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":"AlterRunInContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterRunInContext.ts"],"names":[],"mappings":"","sourcesContent":["import {DIContext} from \"../domain/DIContext\";\n\nexport interface AlterRunInContext {\n $alterRunInContext(next: (...args: unknown[]) => unknown, ctx: DIContext): () => unknown | Promise<() => unknown>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIConfigurationOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DIConfigurationOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\ndeclare global {\n namespace TsED {\n interface Context {}\n interface Configuration {\n scopes: {[key: string]: ProviderScope};\n /**\n * Define a list of resolvers (it can be an external DI).\n */\n resolvers: DIResolver[];\n /**\n * Define dependencies to build the provider\n */\n imports: TokenProvider[];\n /**\n * Mount controllers\n */\n mount: Record<string, TokenProvider[]>;\n
|
|
1
|
+
{"version":3,"file":"DIConfigurationOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DIConfigurationOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n interface Context {}\n interface Configuration extends Record<string, any> {\n scopes: {[key: string]: ProviderScope};\n /**\n * Define a list of resolvers (it can be an external DI).\n */\n resolvers: DIResolver[];\n /**\n * Define dependencies to build the provider\n */\n imports: TokenProvider[];\n /**\n * Mount controllers\n */\n mount: Record<string, TokenProvider[]>;\n }\n }\n}\n\nexport interface DIConfigurationOptions extends TsED.Configuration {}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DILoggerOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DILoggerOptions.ts"],"names":[],"mappings":"","sourcesContent":["export interface DILoggerOptions {\n /**\n * Enable debug mode. By default debug is false.\n */\n debug?: boolean;\n /**\n * Enable info mode. By default debug is false.\n */\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\";\n /**\n * Enable log performance tracker and disable log server.\n */\n perf?: boolean;\n /**\n * List of regexp to ignore log.\n */\n ignoreUrlPatterns?: (string | RegExp)[];\n /**\n * The number of space characters to use as white space in JSON output. Default is 2 (0 in production).\n */\n jsonIndentation?: number;\n /**\n * A function called for each incoming request to create a request id.\n * @returns {number}\n */\n reqIdBuilder?: (req: any) => string;\n /**\n * Disable routes table displayed in the logger. By default debug is `false`.\n */\n disableRoutesSummary?: boolean;\n /**\n * Disable bootstrap log displayed in the logger. By default debug is `false`.\n */\n disableBootstrapLog?: boolean;\n /**\n * Specify log format. Example: `%[%d{[yyyy-MM-dd hh:mm:ss,SSS}] %p%] %m`. See [@tsed/logger configuration](https://tsedio.github.io/logger/).\n */\n format?: string;\n /**\n * Specify the log stack size for the context.logger. When the stack.length is reach, the logger is flushed during the request.\n * Default size is set to 30.\n */\n maxStackSize?: number;\n}\n"]}
|