@tsed/di 7.0.0-beta.8 → 7.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage.json +6 -0
- package/jest.config.js +9 -0
- package/lib/cjs/decorators/controller.js.map +1 -1
- package/lib/cjs/decorators/inject.js +7 -3
- package/lib/cjs/decorators/inject.js.map +1 -1
- package/lib/cjs/domain/Container.js +1 -2
- package/lib/cjs/domain/Container.js.map +1 -1
- package/lib/cjs/domain/ContextLogger.js +41 -30
- package/lib/cjs/domain/ContextLogger.js.map +1 -1
- package/lib/cjs/domain/ControllerProvider.js +37 -0
- package/lib/cjs/domain/ControllerProvider.js.map +1 -0
- package/lib/cjs/domain/DIContext.js +86 -30
- package/lib/cjs/domain/DIContext.js.map +1 -1
- package/lib/cjs/domain/LocalsContainer.js +3 -46
- package/lib/cjs/domain/LocalsContainer.js.map +1 -1
- package/lib/cjs/domain/Provider.js +20 -1
- package/lib/cjs/domain/Provider.js.map +1 -1
- package/lib/cjs/errors/InjectionError.js +3 -2
- package/lib/cjs/errors/InjectionError.js.map +1 -1
- package/lib/cjs/errors/InvalidPropertyTokenError.js +12 -0
- package/lib/cjs/errors/InvalidPropertyTokenError.js.map +1 -0
- package/lib/cjs/errors/UndefinedTokenError.js +1 -1
- package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
- package/lib/cjs/index.js +9 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
- package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
- package/lib/cjs/interfaces/DILoggerOptions.js +3 -0
- package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/cjs/interfaces/InjectableProperties.js.map +1 -1
- package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -1
- package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
- package/lib/cjs/interfaces/TokenRoute.js +3 -0
- package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
- package/lib/cjs/registries/GlobalProviders.js +7 -12
- package/lib/cjs/registries/GlobalProviders.js.map +1 -1
- package/lib/cjs/registries/ProviderRegistry.js +1 -1
- package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
- package/lib/cjs/services/DIConfiguration.js +56 -43
- package/lib/cjs/services/DIConfiguration.js.map +1 -1
- package/lib/cjs/services/DITest.js +5 -6
- package/lib/cjs/services/DITest.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +94 -92
- package/lib/cjs/services/InjectorService.js.map +1 -1
- package/lib/cjs/utils/asyncHookContext.js +42 -0
- package/lib/cjs/utils/asyncHookContext.js.map +1 -0
- package/lib/cjs/utils/getConfiguration.js +13 -10
- package/lib/cjs/utils/getConfiguration.js.map +1 -1
- package/lib/cjs/utils/resolveControllers.js +47 -0
- package/lib/cjs/utils/resolveControllers.js.map +1 -0
- package/lib/cjs/utils/setLoggerConfiguration.js +11 -0
- package/lib/cjs/utils/setLoggerConfiguration.js.map +1 -0
- package/lib/cjs/utils/setLoggerFormat.js +33 -0
- package/lib/cjs/utils/setLoggerFormat.js.map +1 -0
- package/lib/cjs/utils/setLoggerLevel.js +1 -2
- package/lib/cjs/utils/setLoggerLevel.js.map +1 -1
- package/lib/esm/decorators/controller.js.map +1 -1
- package/lib/esm/decorators/inject.js +6 -2
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/domain/Container.js +1 -2
- package/lib/esm/domain/Container.js.map +1 -1
- package/lib/esm/domain/ContextLogger.js +41 -30
- package/lib/esm/domain/ContextLogger.js.map +1 -1
- package/lib/esm/domain/ControllerProvider.js +33 -0
- package/lib/esm/domain/ControllerProvider.js.map +1 -0
- package/lib/esm/domain/DIContext.js +86 -30
- package/lib/esm/domain/DIContext.js.map +1 -1
- package/lib/esm/domain/LocalsContainer.js +3 -46
- package/lib/esm/domain/LocalsContainer.js.map +1 -1
- package/lib/esm/domain/Provider.js +21 -2
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/errors/InjectionError.js +3 -2
- package/lib/esm/errors/InjectionError.js.map +1 -1
- package/lib/esm/errors/InvalidPropertyTokenError.js +8 -0
- package/lib/esm/errors/InvalidPropertyTokenError.js.map +1 -0
- package/lib/esm/errors/UndefinedTokenError.js +1 -1
- package/lib/esm/errors/UndefinedTokenError.js.map +1 -1
- package/lib/esm/index.js +9 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/AlterRunInContext.js +2 -0
- package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
- package/lib/esm/interfaces/DILoggerOptions.js +2 -0
- package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/esm/interfaces/InjectableProperties.js.map +1 -1
- package/lib/esm/interfaces/InterceptorMethods.js.map +1 -1
- package/lib/esm/interfaces/TokenProvider.js.map +1 -1
- package/lib/esm/interfaces/TokenRoute.js +2 -0
- package/lib/esm/interfaces/TokenRoute.js.map +1 -0
- package/lib/esm/registries/GlobalProviders.js +7 -12
- package/lib/esm/registries/GlobalProviders.js.map +1 -1
- package/lib/esm/registries/ProviderRegistry.js +1 -1
- package/lib/esm/registries/ProviderRegistry.js.map +1 -1
- package/lib/esm/services/DIConfiguration.js +57 -44
- package/lib/esm/services/DIConfiguration.js.map +1 -1
- package/lib/esm/services/DITest.js +5 -6
- package/lib/esm/services/DITest.js.map +1 -1
- package/lib/esm/services/InjectorService.js +96 -94
- package/lib/esm/services/InjectorService.js.map +1 -1
- package/lib/esm/utils/asyncHookContext.js +33 -0
- package/lib/esm/utils/asyncHookContext.js.map +1 -0
- package/lib/esm/utils/getConfiguration.js +12 -10
- package/lib/esm/utils/getConfiguration.js.map +1 -1
- package/lib/esm/utils/resolveControllers.js +42 -0
- package/lib/esm/utils/resolveControllers.js.map +1 -0
- package/lib/esm/utils/setLoggerConfiguration.js +7 -0
- package/lib/esm/utils/setLoggerConfiguration.js.map +1 -0
- package/lib/esm/utils/setLoggerFormat.js +29 -0
- package/lib/esm/utils/setLoggerFormat.js.map +1 -0
- package/lib/esm/utils/setLoggerLevel.js +1 -2
- package/lib/esm/utils/setLoggerLevel.js.map +1 -1
- package/lib/types/decorators/controller.d.ts +0 -1
- package/lib/types/domain/ContextLogger.d.ts +13 -18
- package/lib/types/domain/ControllerProvider.d.ts +17 -0
- package/lib/types/domain/DIContext.d.ts +23 -29
- package/lib/types/domain/LocalsContainer.d.ts +3 -22
- package/lib/types/domain/Provider.d.ts +2 -1
- package/lib/types/errors/InvalidPropertyTokenError.d.ts +4 -0
- package/lib/types/index.d.ts +9 -1
- package/lib/types/interfaces/AlterRunInContext.d.ts +3 -0
- package/lib/types/interfaces/DIConfigurationOptions.d.ts +5 -2
- package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
- package/lib/types/interfaces/InjectableProperties.d.ts +2 -1
- package/lib/types/interfaces/InterceptorMethods.d.ts +1 -1
- package/lib/types/interfaces/TokenProvider.d.ts +1 -1
- package/lib/types/interfaces/TokenRoute.d.ts +5 -0
- package/lib/types/registries/GlobalProviders.d.ts +6 -5
- package/lib/types/registries/ProviderRegistry.d.ts +2 -1
- package/lib/types/services/DIConfiguration.d.ts +19 -11
- package/lib/types/services/InjectorService.d.ts +20 -28
- package/lib/types/utils/asyncHookContext.d.ts +14 -0
- package/lib/types/utils/getConfiguration.d.ts +1 -0
- package/lib/types/utils/resolveControllers.d.ts +12 -0
- package/lib/types/utils/setLoggerConfiguration.d.ts +2 -0
- package/lib/types/utils/setLoggerFormat.d.ts +6 -0
- package/lib/types/utils/setLoggerLevel.d.ts +1 -1
- package/package.json +15 -11
- package/readme.md +3 -2
- package/lib/cjs/utils/runInContext.js +0 -20
- package/lib/cjs/utils/runInContext.js.map +0 -1
- package/lib/esm/utils/runInContext.js +0 -14
- package/lib/esm/utils/runInContext.js.map +0 -1
- package/lib/types/utils/runInContext.d.ts +0 -6
|
@@ -1,41 +1,97 @@
|
|
|
1
|
+
import { runInContext } from "../utils/asyncHookContext.js";
|
|
1
2
|
import { ContextLogger } from "./ContextLogger.js";
|
|
2
3
|
import { LocalsContainer } from "./LocalsContainer.js";
|
|
3
|
-
export class DIContext
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
export class DIContext {
|
|
5
|
+
opts;
|
|
6
|
+
#container;
|
|
7
|
+
#cache;
|
|
8
|
+
#logger;
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.opts = opts;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Logger attached to the context request.
|
|
14
|
+
*/
|
|
15
|
+
get logger() {
|
|
16
|
+
this.#logger = this.#logger || new ContextLogger(this.opts);
|
|
17
|
+
return this.#logger;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Request id generated by @@contextMiddleware@@.
|
|
21
|
+
*
|
|
22
|
+
* ::: tip
|
|
23
|
+
* By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, ""))`.
|
|
24
|
+
* Dash are removed to simplify tracking logs in Kibana
|
|
25
|
+
* :::
|
|
26
|
+
*
|
|
27
|
+
* ::: tip
|
|
28
|
+
* Request id can by customized by changing the server configuration.
|
|
29
|
+
*
|
|
30
|
+
* ```typescript
|
|
31
|
+
* @Configuration({
|
|
32
|
+
* logger: {
|
|
33
|
+
* reqIdBuilder: createUniqId // give your own id generator function
|
|
34
|
+
* }
|
|
35
|
+
* })
|
|
36
|
+
* class Server {
|
|
37
|
+
*
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
* :::
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
get id() {
|
|
44
|
+
return this.opts.id;
|
|
45
|
+
}
|
|
46
|
+
get dateStart() {
|
|
47
|
+
return this.logger.dateStart;
|
|
48
|
+
}
|
|
49
|
+
get injector() {
|
|
50
|
+
return this.opts.injector;
|
|
22
51
|
}
|
|
23
52
|
get env() {
|
|
24
|
-
return this.injector.settings.env;
|
|
53
|
+
return this.injector.settings.get("env");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The request container used by the Ts.ED DI. It contains all services annotated with `@Scope(ProviderScope.REQUEST)`
|
|
57
|
+
*/
|
|
58
|
+
get container() {
|
|
59
|
+
return (this.#container = this.#container || new LocalsContainer());
|
|
25
60
|
}
|
|
26
61
|
async destroy() {
|
|
27
|
-
|
|
28
|
-
this.logger.destroy();
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
delete this.container;
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
delete this.logger;
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
delete this.injector;
|
|
62
|
+
return Promise.all([this.#container?.destroy(), this.#logger?.flush()]);
|
|
35
63
|
}
|
|
36
64
|
async emit(eventName, ...args) {
|
|
37
|
-
|
|
38
|
-
|
|
65
|
+
return this.injector?.emit(eventName, ...args);
|
|
66
|
+
}
|
|
67
|
+
async runInContext(next) {
|
|
68
|
+
return runInContext(this, next);
|
|
69
|
+
}
|
|
70
|
+
cache(key, cb) {
|
|
71
|
+
if (!this.has(key)) {
|
|
72
|
+
this.set(key, cb());
|
|
73
|
+
}
|
|
74
|
+
return this.get(key);
|
|
75
|
+
}
|
|
76
|
+
async cacheAsync(key, cb) {
|
|
77
|
+
if (!this.has(key)) {
|
|
78
|
+
this.set(key, await cb());
|
|
79
|
+
}
|
|
80
|
+
return this.get(key);
|
|
81
|
+
}
|
|
82
|
+
delete(key) {
|
|
83
|
+
return !!this.#cache?.delete(key);
|
|
84
|
+
}
|
|
85
|
+
get(key) {
|
|
86
|
+
return this.#cache?.get(key);
|
|
87
|
+
}
|
|
88
|
+
has(key) {
|
|
89
|
+
return !!this.#cache?.has(key);
|
|
90
|
+
}
|
|
91
|
+
set(key, value) {
|
|
92
|
+
this.#cache = this.#cache || new Map();
|
|
93
|
+
this.#cache.set(key, value);
|
|
94
|
+
return this;
|
|
39
95
|
}
|
|
40
96
|
}
|
|
41
97
|
//# sourceMappingURL=DIContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAC,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAQlD,MAAM,OAAO,SAAS;IAOD;IAJnB,UAAU,CAAmB;IAC7B,MAAM,CAAiB;IACvB,OAAO,CAAiB;IAExB,YAAmB,IAAsB;QAAtB,SAAI,GAAJ,IAAI,CAAkB;IAAG,CAAC;IAE7C;;OAEG;IACH,IAAI,MAAM;QACR,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,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,CAA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;QACnB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,GAAG,CAAC,GAAQ;QACV,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,GAAG,CAAC,GAAQ,EAAE,KAAU;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,GAAG,EAAY,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {InjectorService} from \"../services/InjectorService\";\nimport {runInContext} from \"../utils/asyncHookContext\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n injector: InjectorService;\n logger: any;\n}\n\nexport class DIContext {\n [x: string]: any;\n\n #container?: LocalsContainer;\n #cache?: Map<any, any>;\n #logger?: ContextLogger;\n\n constructor(public opts: DIContextOptions) {}\n\n /**\n * Logger attached to the context request.\n */\n get logger() {\n this.#logger = this.#logger || new ContextLogger(this.opts);\n return this.#logger;\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 /**\n * The request container used by the Ts.ED DI. It contains all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n get container() {\n return (this.#container = this.#container || new LocalsContainer());\n }\n\n async destroy(): Promise<any> {\n return Promise.all([this.#container?.destroy(), this.#logger?.flush()]);\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n\n async runInContext(next: Function) {\n return runInContext(this, next);\n }\n\n cache<Value = any>(key: string, cb: () => Value): Value {\n if (!this.has(key)) {\n this.set(key, cb());\n }\n\n return this.get(key);\n }\n\n async cacheAsync<Value = any>(key: string, cb: () => Promise<Value>): Promise<Value> {\n if (!this.has(key)) {\n this.set(key, await cb());\n }\n\n return this.get(key);\n }\n\n delete(key: any): boolean {\n return !!this.#cache?.delete(key);\n }\n\n get<T = any>(key: any): T {\n return this.#cache?.get(key);\n }\n\n has(key: any): boolean {\n return !!this.#cache?.has(key);\n }\n\n set(key: any, value: any): this {\n this.#cache = this.#cache || new Map<any, any>();\n this.#cache.set(key, value);\n return this;\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
|
|
@@ -1,51 +1,8 @@
|
|
|
1
|
+
import { Hooks } from "@tsed/core";
|
|
1
2
|
export class LocalsContainer extends Map {
|
|
2
|
-
|
|
3
|
-
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
4
|
-
* @param eventName The event name to emit at all services.
|
|
5
|
-
* @param args List of the parameters to give to each services.
|
|
6
|
-
* @returns {Promise<any[]>} A list of promises.
|
|
7
|
-
*/
|
|
8
|
-
async emit(eventName, ...args) {
|
|
9
|
-
for (const handler of this.getListeners(eventName)) {
|
|
10
|
-
await handler(...args);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @param eventName
|
|
15
|
-
* @param value
|
|
16
|
-
* @param args
|
|
17
|
-
*/
|
|
18
|
-
alter(eventName, value, ...args) {
|
|
19
|
-
for (const handler of this.getListeners(eventName)) {
|
|
20
|
-
value = handler(value, ...args);
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @param eventName
|
|
26
|
-
* @param value
|
|
27
|
-
* @param args
|
|
28
|
-
*/
|
|
29
|
-
async alterAsync(eventName, value, ...args) {
|
|
30
|
-
for (const handler of this.getListeners(eventName)) {
|
|
31
|
-
value = handler(value, ...args);
|
|
32
|
-
}
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
toArray() {
|
|
36
|
-
return [...this.values()];
|
|
37
|
-
}
|
|
3
|
+
hooks = new Hooks();
|
|
38
4
|
async destroy() {
|
|
39
|
-
await this.
|
|
40
|
-
this.clear();
|
|
41
|
-
}
|
|
42
|
-
getListeners(event) {
|
|
43
|
-
return this.toArray().reduce((listeners, instance) => {
|
|
44
|
-
if (typeof instance === "object" && instance && event in instance) {
|
|
45
|
-
return listeners.concat(instance[event].bind(instance));
|
|
46
|
-
}
|
|
47
|
-
return listeners;
|
|
48
|
-
}, []);
|
|
5
|
+
await this.hooks.asyncEmit("$onDestroy");
|
|
49
6
|
}
|
|
50
7
|
}
|
|
51
8
|
//# sourceMappingURL=LocalsContainer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalsContainer.js","sourceRoot":"","sources":["../../../src/domain/LocalsContainer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LocalsContainer.js","sourceRoot":"","sources":["../../../src/domain/LocalsContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAGjC,MAAM,OAAO,eAAgB,SAAQ,GAAuB;IACjD,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;IAE7B,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import {Hooks} from \"@tsed/core\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\n\nexport class LocalsContainer extends Map<TokenProvider, any> {\n readonly hooks = new Hooks();\n\n async destroy() {\n await this.hooks.asyncEmit(\"$onDestroy\");\n }\n}\n"]}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { classOf, getClassOrSymbol, isClass, nameOf, Store } from "@tsed/core";
|
|
1
|
+
import { classOf, getClassOrSymbol, isClass, methodsOf, nameOf, Store } from "@tsed/core";
|
|
2
2
|
import { ProviderScope } from "./ProviderScope.js";
|
|
3
3
|
import { ProviderType } from "./ProviderType.js";
|
|
4
4
|
export class Provider {
|
|
5
|
+
type = ProviderType.PROVIDER;
|
|
6
|
+
deps;
|
|
7
|
+
imports;
|
|
8
|
+
useFactory;
|
|
9
|
+
useAsyncFactory;
|
|
10
|
+
useValue;
|
|
11
|
+
hooks;
|
|
12
|
+
_useClass;
|
|
13
|
+
_provide;
|
|
14
|
+
_store;
|
|
15
|
+
_tokenStore;
|
|
5
16
|
constructor(token, options = {}) {
|
|
6
|
-
this.type = ProviderType.PROVIDER;
|
|
7
17
|
this.provide = token;
|
|
8
18
|
this.useClass = token;
|
|
9
19
|
Object.assign(this, options);
|
|
@@ -31,6 +41,15 @@ export class Provider {
|
|
|
31
41
|
if (isClass(value)) {
|
|
32
42
|
this._useClass = classOf(value);
|
|
33
43
|
this._store = Store.from(value);
|
|
44
|
+
this.hooks = methodsOf(this._useClass).reduce((hooks, { propertyKey }) => {
|
|
45
|
+
if (String(propertyKey).startsWith("$")) {
|
|
46
|
+
return {
|
|
47
|
+
...hooks,
|
|
48
|
+
[propertyKey]: (instance, ...args) => instance[propertyKey](...args)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return hooks;
|
|
52
|
+
}, {});
|
|
34
53
|
}
|
|
35
54
|
}
|
|
36
55
|
get className() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/domain/Provider.ts"],"names":[],"m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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","sourcesContent":["import {classOf, getClassOrSymbol, isClass, methodsOf, 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 type ProviderHookCallback<T = any> = (instance: T, ...args: any[]) => Promise<void> | void;\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, ProviderHookCallback<T>>;\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 this.hooks = methodsOf(this._useClass).reduce((hooks, {propertyKey}) => {\n if (String(propertyKey).startsWith(\"$\")) {\n return {\n ...hooks,\n [propertyKey]: (instance: any, ...args: any[]) => instance[propertyKey](...args)\n };\n }\n return hooks;\n }, {} as any);\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"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getConstructorArgNames, isClass, isString, nameOf } from "@tsed/core";
|
|
2
2
|
import { colors } from "../utils/colors.js";
|
|
3
3
|
export class InjectionError extends Error {
|
|
4
|
+
name = "INJECTION_ERROR";
|
|
5
|
+
tokens = [];
|
|
6
|
+
origin;
|
|
4
7
|
constructor(token, origin) {
|
|
5
8
|
super(isString(origin) ? origin : "");
|
|
6
|
-
this.name = "INJECTION_ERROR";
|
|
7
|
-
this.tokens = [];
|
|
8
9
|
this.tokens = [token];
|
|
9
10
|
if (origin) {
|
|
10
11
|
if (isString(origin)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAE7E,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvC,MAAM,OAAO,cAAe,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAE7E,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvC,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,IAAI,GAAG,iBAAiB,CAAC;IAElB,MAAM,GAAoB,EAAE,CAAC;IAC7B,MAAM,CAAM;IAEnB,YAAY,KAAoB,EAAE,MAAY;QAC5C,KAAK,CAAC,QAAQ,CAAC,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,QAAQ,CAAC,MAAM,CAAC,EAAE;gBACpB,IAAI,CAAC,MAAM,GAAG;oBACZ,OAAO,EAAE,MAAM;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;iBAClB,CAAC;aACH;iBAAM;gBACL,IAAI,MAAM,CAAC,MAAM,EAAE;oBACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,M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,CAAC,GAAG,CAAC,CAAC;SACvB;QAED,OAAO,GAAG,GAAG,KAAK,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,SAAS,GAAG,MAAM,CAAC,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,MAAM,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"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { classOf, nameOf } from "@tsed/core";
|
|
2
|
+
export class InvalidPropertyTokenError extends Error {
|
|
3
|
+
name = "INVALID_TOKEN_ERROR";
|
|
4
|
+
constructor(target, propertyKey) {
|
|
5
|
+
super(`Object isn't a valid token. Please check the token set on ${nameOf(classOf(target))}.${propertyKey}.\n- Check that it is not a circular reference.\n- Check that the token (class or symbol) exists`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=InvalidPropertyTokenError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidPropertyTokenError.js","sourceRoot":"","sources":["../../../src/errors/InvalidPropertyTokenError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AAE3C,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,IAAI,GAAG,qBAAqB,CAAC;IAE7B,YAAY,MAAW,EAAE,WAAmB;QAC1C,KAAK,CACH,6DAA6D,MAAM,CACjE,OAAO,CAAC,MAAM,CAAC,CAChB,IAAI,WAAW,kGAAkG,CACnH,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {classOf, nameOf} from \"@tsed/core\";\n\nexport class InvalidPropertyTokenError extends Error {\n name = \"INVALID_TOKEN_ERROR\";\n\n constructor(target: any, propertyKey: string) {\n super(\n `Object isn't a valid token. Please check the token set on ${nameOf(\n classOf(target)\n )}.${propertyKey}.\\n- Check that it is not a circular reference.\\n- Check that the token (class or symbol) exists`\n );\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export class UndefinedTokenError extends Error {
|
|
2
|
+
name = "UNDEFINED_TOKEN_ERROR";
|
|
2
3
|
constructor() {
|
|
3
4
|
super("Given token is undefined. Have you enabled emitDecoratorMetadata in your tsconfig.json or decorated your class with @Injectable, @Service, ... decorator ?");
|
|
4
|
-
this.name = "UNDEFINED_TOKEN_ERROR";
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=UndefinedTokenError.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"UndefinedTokenError.js","sourceRoot":"","sources":["../../../src/errors/UndefinedTokenError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,IAAI,GAAG,uBAAuB,CAAC;IAE/B;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;IACJ,CAAC;CACF","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/esm/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export * from "./decorators/useOpts.js";
|
|
|
19
19
|
export * from "./decorators/value.js";
|
|
20
20
|
export * from "./domain/Container.js";
|
|
21
21
|
export * from "./domain/ContextLogger.js";
|
|
22
|
+
export * from "./domain/ControllerProvider.js";
|
|
22
23
|
export * from "./domain/DIContext.js";
|
|
23
24
|
export * from "./domain/InjectablePropertyType.js";
|
|
24
25
|
export * from "./domain/LocalsContainer.js";
|
|
@@ -26,9 +27,12 @@ export * from "./domain/Provider.js";
|
|
|
26
27
|
export * from "./domain/ProviderScope.js";
|
|
27
28
|
export * from "./domain/ProviderType.js";
|
|
28
29
|
export * from "./errors/InjectionError.js";
|
|
30
|
+
export * from "./errors/InvalidPropertyTokenError.js";
|
|
29
31
|
export * from "./errors/UndefinedTokenError.js";
|
|
32
|
+
export * from "./interfaces/AlterRunInContext.js";
|
|
30
33
|
export * from "./interfaces/DIConfigurationOptions.js";
|
|
31
34
|
export * from "./interfaces/DILogger.js";
|
|
35
|
+
export * from "./interfaces/DILoggerOptions.js";
|
|
32
36
|
export * from "./interfaces/DIResolver.js";
|
|
33
37
|
export * from "./interfaces/InjectableProperties.js";
|
|
34
38
|
export * from "./interfaces/InterceptorContext.js";
|
|
@@ -40,15 +44,19 @@ export * from "./interfaces/ProviderOpts.js";
|
|
|
40
44
|
export * from "./interfaces/RegistrySettings.js";
|
|
41
45
|
export * from "./interfaces/ResolvedInvokeOptions.js";
|
|
42
46
|
export * from "./interfaces/TokenProvider.js";
|
|
47
|
+
export * from "./interfaces/TokenRoute.js";
|
|
43
48
|
export * from "./registries/GlobalProviders.js";
|
|
44
49
|
export * from "./registries/ProviderRegistry.js";
|
|
45
50
|
export * from "./services/DIConfiguration.js";
|
|
46
51
|
export * from "./services/DILogger.js";
|
|
47
52
|
export * from "./services/DITest.js";
|
|
48
53
|
export * from "./services/InjectorService.js";
|
|
54
|
+
export * from "./utils/asyncHookContext.js";
|
|
49
55
|
export * from "./utils/colors.js";
|
|
50
56
|
export * from "./utils/createContainer.js";
|
|
51
57
|
export * from "./utils/getConfiguration.js";
|
|
52
|
-
export * from "./utils/
|
|
58
|
+
export * from "./utils/resolveControllers.js";
|
|
59
|
+
export * from "./utils/setLoggerConfiguration.js";
|
|
60
|
+
export * from "./utils/setLoggerFormat.js";
|
|
53
61
|
export * from "./utils/setLoggerLevel.js";
|
|
54
62
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAy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AClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/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/InvalidPropertyTokenError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/AlterRunInContext\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/asyncHookContext\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlterRunInContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterRunInContext.ts"],"names":[],"mappings":"","sourcesContent":["export interface AlterRunInContext {\n $alterRunInContext(next: (...args: unknown[]) => unknown): () => unknown | Promise<() => unknown>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIConfigurationOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DIConfigurationOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\ndeclare global {\n namespace TsED {\n interface Context {}\n interface Configuration {\n scopes: {[key: string]: ProviderScope};\n /**\n * Define a list of resolvers (it can be an external DI).\n */\n resolvers: DIResolver[];\n /**\n * Define dependencies to build the provider\n */\n imports: TokenProvider[];\n\n
|
|
1
|
+
{"version":3,"file":"DIConfigurationOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DIConfigurationOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n interface Context {}\n interface Configuration extends Record<string, any> {\n scopes: {[key: string]: ProviderScope};\n /**\n * Define a list of resolvers (it can be an external DI).\n */\n resolvers: DIResolver[];\n /**\n * Define dependencies to build the provider\n */\n imports: TokenProvider[];\n /**\n * Mount controllers\n */\n mount: Record<string, TokenProvider[]>;\n }\n }\n}\n\nexport interface DIConfigurationOptions extends TsED.Configuration {}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DILoggerOptions.js","sourceRoot":"","sources":["../../../src/interfaces/DILoggerOptions.ts"],"names":[],"mappings":"","sourcesContent":["export interface DILoggerOptions {\n /**\n * Enable debug mode. By default debug is false.\n */\n debug?: boolean;\n /**\n * Enable info mode. By default debug is false.\n */\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\";\n /**\n * Enable log performance tracker and disable log server.\n */\n perf?: boolean;\n /**\n * List of regexp to ignore log.\n */\n ignoreUrlPatterns?: (string | RegExp)[];\n /**\n * The number of space characters to use as white space in JSON output. Default is 2 (0 in production).\n */\n jsonIndentation?: number;\n /**\n * A function called for each incoming request to create a request id.\n * @returns {number}\n */\n reqIdBuilder?: (req: any) => string;\n /**\n * Disable routes table displayed in the logger. By default debug is `false`.\n */\n disableRoutesSummary?: boolean;\n /**\n * Disable bootstrap log displayed in the logger. By default debug is `false`.\n */\n disableBootstrapLog?: boolean;\n /**\n * Specify log format. Example: `%[%d{[yyyy-MM-dd hh:mm:ss,SSS}] %p%] %m`. See [@tsed/logger configuration](https://tsedio.github.io/logger/).\n */\n format?: string;\n /**\n * Specify the log stack size for the context.logger. When the stack.length is reach, the logger is flushed during the request.\n * Default size is set to 30.\n */\n maxStackSize?: number;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InjectableProperties.js","sourceRoot":"","sources":["../../../src/interfaces/InjectableProperties.ts"],"names":[],"mappings":"","sourcesContent":["import type {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {TokenProvider} from \"./TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {InvokeOptions} from \"./InvokeOptions\";\n\nexport interface InjectableProperty {\n propertyKey: string;\n}\n\nexport interface InjectablePropertyOptions extends InjectableProperty {\n bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;\n propertyType: string;\n useType?: TokenProvider;\n resolver: (injector: InjectorService, locals:
|
|
1
|
+
{"version":3,"file":"InjectableProperties.js","sourceRoot":"","sources":["../../../src/interfaces/InjectableProperties.ts"],"names":[],"mappings":"","sourcesContent":["import type {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {LocalsContainer} from \"../domain/LocalsContainer\";\nimport type {TokenProvider} from \"./TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {InvokeOptions} from \"./InvokeOptions\";\n\nexport interface InjectableProperty {\n propertyKey: string;\n}\n\nexport interface InjectablePropertyOptions extends InjectableProperty {\n bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;\n propertyType: string;\n useType?: TokenProvider;\n resolver: (injector: InjectorService, locals: LocalsContainer, options: Partial<InvokeOptions> & {options: any}) => () => any;\n options?: any;\n}\n\nexport interface InjectablePropertyValue extends InjectableProperty {\n bindingType: InjectablePropertyType.CONSTANT | InjectablePropertyType.VALUE;\n expression: string;\n defaultValue?: any;\n}\n\nexport interface InjectableProperties {\n [key: string]: InjectablePropertyOptions | InjectablePropertyValue;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InterceptorMethods.js","sourceRoot":"","sources":["../../../src/interfaces/InterceptorMethods.ts"],"names":[],"mappings":"","sourcesContent":["import type {InterceptorContext, InterceptorNext} from \"./InterceptorContext\";\n\nexport interface InterceptorMethods {\n intercept
|
|
1
|
+
{"version":3,"file":"InterceptorMethods.js","sourceRoot":"","sources":["../../../src/interfaces/InterceptorMethods.ts"],"names":[],"mappings":"","sourcesContent":["import type {InterceptorContext, InterceptorNext} from \"./InterceptorContext\";\n\nexport interface InterceptorMethods {\n intercept(context: InterceptorContext, next?: InterceptorNext): any;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenProvider.js","sourceRoot":"","sources":["../../../src/interfaces/TokenProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\n\nexport type TokenProvider = string | symbol | Type | Function | any;\n"]}
|
|
1
|
+
{"version":3,"file":"TokenProvider.js","sourceRoot":"","sources":["../../../src/interfaces/TokenProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\n\nexport type TokenProvider<T = any> = string | symbol | Type<T> | Function | any;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenRoute.js","sourceRoot":"","sources":["../../../src/interfaces/TokenRoute.ts"],"names":[],"mappings":"","sourcesContent":["import {TokenProvider} from \"./TokenProvider\";\n\nexport interface TokenRoute {\n token: TokenProvider;\n route: string;\n}\n"]}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
var _GlobalProviderRegistry_settings;
|
|
2
|
-
import { __classPrivateFieldGet } from "tslib";
|
|
3
1
|
import { getClassOrSymbol } from "@tsed/core";
|
|
4
2
|
import { Provider } from "../domain/Provider.js";
|
|
5
3
|
import { ProviderType } from "../domain/ProviderType.js";
|
|
6
4
|
export class GlobalProviderRegistry extends Map {
|
|
7
|
-
|
|
8
|
-
super(...arguments);
|
|
9
|
-
_GlobalProviderRegistry_settings.set(this, new Map());
|
|
10
|
-
}
|
|
5
|
+
#settings = new Map();
|
|
11
6
|
/**
|
|
12
7
|
* The get() method returns a specified element from a Map object.
|
|
13
8
|
* @param key Required. The key of the element to return from the Map object.
|
|
@@ -44,6 +39,7 @@ export class GlobalProviderRegistry extends Map {
|
|
|
44
39
|
meta[key] = options[key];
|
|
45
40
|
});
|
|
46
41
|
this.set(target, meta);
|
|
42
|
+
return meta;
|
|
47
43
|
}
|
|
48
44
|
/**
|
|
49
45
|
* The delete() method removes the specified element from a Map object.
|
|
@@ -59,12 +55,12 @@ export class GlobalProviderRegistry extends Map {
|
|
|
59
55
|
...options,
|
|
60
56
|
model
|
|
61
57
|
});
|
|
62
|
-
|
|
58
|
+
this.#settings.set(type, options);
|
|
63
59
|
return this;
|
|
64
60
|
}
|
|
65
61
|
onInvoke(provider, locals, options) {
|
|
66
|
-
const settings =
|
|
67
|
-
if (settings
|
|
62
|
+
const settings = this.#settings.get(provider.type);
|
|
63
|
+
if (settings?.onInvoke) {
|
|
68
64
|
settings.onInvoke(provider, locals, options);
|
|
69
65
|
}
|
|
70
66
|
}
|
|
@@ -79,7 +75,7 @@ export class GlobalProviderRegistry extends Map {
|
|
|
79
75
|
type = provider.type;
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
|
-
return (
|
|
78
|
+
return (this.#settings.get(type) || {
|
|
83
79
|
model: Provider
|
|
84
80
|
});
|
|
85
81
|
}
|
|
@@ -103,14 +99,13 @@ export class GlobalProviderRegistry extends Map {
|
|
|
103
99
|
createIfNotExists(key, options) {
|
|
104
100
|
const type = options.type || ProviderType.PROVIDER;
|
|
105
101
|
if (!this.has(key)) {
|
|
106
|
-
const { model = Provider } =
|
|
102
|
+
const { model = Provider } = this.#settings.get(type) || {};
|
|
107
103
|
const item = new model(key, options);
|
|
108
104
|
this.set(key, item);
|
|
109
105
|
}
|
|
110
106
|
return this.get(key);
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
|
-
_GlobalProviderRegistry_settings = new WeakMap();
|
|
114
109
|
/**
|
|
115
110
|
*
|
|
116
111
|
* @type {GlobalProviders}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAO,MAAM,YAAY,CAAC;AAElD,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAOpD,MAAM,OAAO,sBAAuB,SAAQ,GAA4B;IACtE,SAAS,GAAkC,IAAI,GAAG,EAAE,CAAC;IAErD;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,gBAAgB,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IAAI,CAAC,IAAI,EAAE,CAAC;YAE1D,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;SACrB;QAED,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;IACxB,CAAC;CACF;AAED;;;GAGG;AACH,0CAA0C;AAC1C,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,sBAAsB,EAAE,CAAC","sourcesContent":["import {getClassOrSymbol, Type} from \"@tsed/core\";\nimport type {LocalsContainer} from \"../domain/LocalsContainer\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {RegistrySettings} from \"../interfaces/RegistrySettings\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport type {InjectorService} from \"../services/InjectorService\";\n\nexport class GlobalProviderRegistry extends Map<TokenProvider, Provider> {\n #settings: Map<string, RegistrySettings> = new Map();\n\n /**\n * The get() method returns a specified element from a Map object.\n * @param key Required. The key of the element to return from the Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n */\n get(key: TokenProvider): Provider | undefined {\n return super.get(getClassOrSymbol(key));\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @param key\n * @returns {boolean}\n */\n has(key: TokenProvider): boolean {\n return super.has(getClassOrSymbol(key));\n }\n\n /**\n * The set() method adds or updates an element with a specified key and value to a Map object.\n * @param key Required. The key of the element to add to the Map object.\n * @param metadata Required. The value of the element to add to the Map object.\n */\n set(key: TokenProvider, metadata: Provider): this {\n super.set(getClassOrSymbol(key), metadata);\n\n return this;\n }\n\n /**\n *\n * @param target\n * @param options\n */\n merge(target: TokenProvider, options: Partial<ProviderOpts>) {\n const meta = this.createIfNotExists(target, options);\n\n Object.keys(options).forEach((key) => {\n meta[key] = (options as any)[key];\n });\n\n this.set(target, meta);\n\n return meta;\n }\n\n /**\n * The delete() method removes the specified element from a Map object.\n * @param key Required. The key of the element to remove from the Map object.\n * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\n */\n delete(key: TokenProvider): boolean {\n return super.delete(getClassOrSymbol(key));\n }\n\n createRegistry(type: string, model: Type<Provider>, options: Partial<RegistrySettings> = {}) {\n const defaultOptions = this.getRegistrySettings(type);\n\n options = Object.assign(defaultOptions, {\n ...options,\n model\n });\n\n this.#settings.set(type, options);\n\n return this;\n }\n\n onInvoke(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {injector: InjectorService}) {\n const settings = this.#settings.get(provider.type);\n\n if (settings?.onInvoke) {\n settings.onInvoke(provider, locals, options);\n }\n }\n\n getRegistrySettings(target: string | TokenProvider): RegistrySettings {\n let type: string = \"provider\";\n\n if (typeof target === \"string\") {\n type = target;\n } else {\n const provider = this.get(target);\n if (provider) {\n type = provider.type;\n }\n }\n\n return (\n this.#settings.get(type) || {\n model: Provider\n }\n );\n }\n\n createRegisterFn(type: string) {\n return (provider: any | ProviderOpts, instance?: any): void => {\n // istanbul ignore next\n if (!provider.provide) {\n provider = {\n provide: provider\n };\n }\n\n provider = Object.assign({instance}, provider, {type});\n this.merge(provider.provide, provider);\n };\n }\n\n /**\n *\n * @param key\n * @param options\n */\n protected createIfNotExists(key: TokenProvider, options: Partial<ProviderOpts>): Provider {\n const type = options.type || ProviderType.PROVIDER;\n\n if (!this.has(key)) {\n const {model = Provider} = this.#settings.get(type) || {};\n\n const item = new model(key, options);\n\n this.set(key, item);\n }\n\n return this.get(key)!;\n }\n}\n\n/**\n *\n * @type {GlobalProviders}\n */\n// tslint:disable-next-line: variable-name\nexport const GlobalProviders = new GlobalProviderRegistry();\n"]}
|
|
@@ -14,7 +14,7 @@ export function registerProvider(provider) {
|
|
|
14
14
|
if (!provider.provide) {
|
|
15
15
|
throw new Error("Provider.provide is required");
|
|
16
16
|
}
|
|
17
|
-
GlobalProviders.merge(provider.provide, provider);
|
|
17
|
+
return GlobalProviders.merge(provider.provide, provider);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Add a new value in the `ProviderRegistry`.
|