@tsed/di 7.0.0-beta.2 → 7.0.0-beta.20
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/constants/{index.js → constants.js} +1 -1
- package/lib/cjs/constants/constants.js.map +1 -0
- package/lib/cjs/decorators/constant.js +1 -1
- package/lib/cjs/decorators/constant.js.map +1 -1
- package/lib/cjs/decorators/controller.js.map +1 -1
- package/lib/cjs/decorators/inject.js +27 -2
- package/lib/cjs/decorators/inject.js.map +1 -1
- package/lib/cjs/decorators/injectable.js +0 -2
- package/lib/cjs/decorators/injectable.js.map +1 -1
- package/lib/cjs/decorators/intercept.js +20 -12
- package/lib/cjs/decorators/intercept.js.map +1 -1
- package/lib/cjs/decorators/module.js +4 -3
- package/lib/cjs/decorators/module.js.map +1 -1
- package/lib/cjs/decorators/opts.js +1 -1
- package/lib/cjs/decorators/opts.js.map +1 -1
- package/lib/cjs/decorators/useOpts.js +1 -1
- package/lib/cjs/decorators/useOpts.js.map +1 -1
- package/lib/cjs/decorators/value.js +1 -1
- package/lib/cjs/decorators/value.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/UndefinedTokenError.js +1 -1
- package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
- package/lib/cjs/index.js +60 -17
- 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/ProviderOpts.js +3 -0
- package/lib/cjs/interfaces/ProviderOpts.js.map +1 -0
- package/lib/cjs/interfaces/RegistrySettings.js.map +1 -1
- package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
- package/lib/cjs/interfaces/{IProvider.js → TokenRoute.js} +1 -1
- package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/registries/GlobalProviders.js +7 -12
- package/lib/cjs/registries/GlobalProviders.js.map +1 -1
- package/lib/cjs/registries/ProviderRegistry.js +8 -7
- 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 +13 -6
- package/lib/cjs/services/DITest.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +115 -113
- 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/constants/{index.js → constants.js} +1 -1
- package/lib/esm/constants/constants.js.map +1 -0
- package/lib/esm/decorators/configuration.js +1 -1
- package/lib/esm/decorators/constant.js +2 -2
- package/lib/esm/decorators/constant.js.map +1 -1
- package/lib/esm/decorators/controller.js +1 -1
- package/lib/esm/decorators/controller.js.map +1 -1
- package/lib/esm/decorators/inject.js +25 -1
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/decorators/injectable.js +1 -3
- package/lib/esm/decorators/injectable.js.map +1 -1
- package/lib/esm/decorators/intercept.js +21 -13
- package/lib/esm/decorators/intercept.js.map +1 -1
- package/lib/esm/decorators/interceptor.js +2 -2
- package/lib/esm/decorators/lazyInject.js +1 -1
- package/lib/esm/decorators/module.js +4 -3
- package/lib/esm/decorators/module.js.map +1 -1
- package/lib/esm/decorators/opts.js +4 -4
- package/lib/esm/decorators/opts.js.map +1 -1
- package/lib/esm/decorators/overrideProvider.js +1 -1
- package/lib/esm/decorators/scope.js +1 -1
- package/lib/esm/decorators/service.js +1 -1
- package/lib/esm/decorators/useOpts.js +1 -1
- package/lib/esm/decorators/useOpts.js.map +1 -1
- package/lib/esm/decorators/value.js +2 -2
- package/lib/esm/decorators/value.js.map +1 -1
- package/lib/esm/domain/Container.js +3 -4
- 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 +88 -32
- 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 +23 -4
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/errors/InjectionError.js +4 -3
- 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 +60 -17
- 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/ProviderOpts.js +2 -0
- package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
- package/lib/esm/interfaces/RegistrySettings.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/package.json +3 -0
- package/lib/esm/registries/GlobalProviders.js +9 -14
- package/lib/esm/registries/GlobalProviders.js.map +1 -1
- package/lib/esm/registries/ProviderRegistry.js +6 -5
- 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/DILogger.js +2 -2
- package/lib/esm/services/DITest.js +16 -9
- package/lib/esm/services/DITest.js.map +1 -1
- package/lib/esm/services/InjectorService.js +116 -114
- 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/createContainer.js +2 -2
- 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/constants/{index.d.ts → constants.d.ts} +0 -0
- package/lib/types/decorators/controller.d.ts +2 -3
- package/lib/types/decorators/inject.d.ts +15 -0
- package/lib/types/decorators/injectable.d.ts +2 -4
- package/lib/types/decorators/intercept.d.ts +2 -2
- package/lib/types/decorators/module.d.ts +3 -2
- package/lib/types/domain/Container.d.ts +3 -3
- 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 -35
- package/lib/types/domain/LocalsContainer.d.ts +3 -22
- package/lib/types/domain/Provider.d.ts +5 -6
- package/lib/types/errors/InjectionError.d.ts +1 -1
- package/lib/types/index.d.ts +54 -11
- 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/{IProvider.d.ts → ProviderOpts.d.ts} +5 -4
- package/lib/types/interfaces/RegistrySettings.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 +9 -6
- package/lib/types/registries/ProviderRegistry.d.ts +5 -4
- package/lib/types/services/DIConfiguration.d.ts +21 -12
- package/lib/types/services/DITest.d.ts +2 -0
- package/lib/types/services/InjectorService.d.ts +28 -34
- 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 +29 -10
- package/readme.md +40 -43
- package/tsconfig.compile.esm.json +1 -0
- package/lib/cjs/constants/index.js.map +0 -1
- package/lib/cjs/decorators/index.js +0 -19
- package/lib/cjs/decorators/index.js.map +0 -1
- package/lib/cjs/domain/index.js +0 -12
- package/lib/cjs/domain/index.js.map +0 -1
- package/lib/cjs/interfaces/IProvider.js.map +0 -1
- package/lib/cjs/interfaces/index.js +0 -18
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/cjs/utils/data/Test1.js +0 -8
- package/lib/cjs/utils/data/Test1.js.map +0 -1
- package/lib/cjs/utils/data/Test2.js +0 -8
- package/lib/cjs/utils/data/Test2.js.map +0 -1
- package/lib/esm/constants/index.js.map +0 -1
- package/lib/esm/decorators/index.js +0 -16
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/esm/domain/index.js +0 -9
- package/lib/esm/domain/index.js.map +0 -1
- package/lib/esm/interfaces/IProvider.js +0 -2
- package/lib/esm/interfaces/IProvider.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -15
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/esm/utils/data/Test1.js +0 -4
- package/lib/esm/utils/data/Test1.js.map +0 -1
- package/lib/esm/utils/data/Test2.js +0 -4
- package/lib/esm/utils/data/Test2.js.map +0 -1
- package/lib/types/decorators/index.d.ts +0 -15
- package/lib/types/domain/index.d.ts +0 -8
- package/lib/types/interfaces/index.d.ts +0 -14
- package/lib/types/utils/data/Test1.d.ts +0 -3
- package/lib/types/utils/data/Test2.d.ts +0 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AsyncLocalStorage, AsyncResource } from "async_hooks";
|
|
2
|
+
const storage = new AsyncLocalStorage();
|
|
3
|
+
export function getAsyncStore() {
|
|
4
|
+
return storage;
|
|
5
|
+
}
|
|
6
|
+
export function useContextRef() {
|
|
7
|
+
return getAsyncStore().getStore();
|
|
8
|
+
}
|
|
9
|
+
export function getContext() {
|
|
10
|
+
return useContextRef()?.current;
|
|
11
|
+
}
|
|
12
|
+
export async function runInContext(ctx, cb, injector) {
|
|
13
|
+
const ref = useContextRef();
|
|
14
|
+
if (ref) {
|
|
15
|
+
ctx && setContext(ctx);
|
|
16
|
+
return cb();
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
injector = ctx?.injector || injector;
|
|
20
|
+
cb = (await injector?.alterAsync("$alterRunInContext", cb)) || cb;
|
|
21
|
+
return storage.run({ current: ctx }, cb);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function setContext(ctx) {
|
|
25
|
+
const ref = useContextRef();
|
|
26
|
+
if (ref && !ref.current) {
|
|
27
|
+
ref.current = ctx;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function bindContext(cb) {
|
|
31
|
+
return AsyncResource.bind(cb);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=asyncHookContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncHookContext.js","sourceRoot":"","sources":["../../../src/utils/asyncHookContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAI7D,MAAM,OAAO,GAAwD,IAAI,iBAAiB,EAAE,CAAC;AAE7F,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,aAAa,EAAE,CAAC,QAAQ,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,aAAa,EAAE,EAAE,OAAc,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAA0B,EAAE,EAAO,EAAE,QAA0B;IAChG,MAAM,GAAG,GAAG,aAAa,EAAE,CAAC;IAE5B,IAAI,GAAG,EAAE;QACP,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;QACvB,OAAO,EAAE,EAAE,CAAC;KACb;SAAM;QACL,QAAQ,GAAG,GAAG,EAAE,QAAQ,IAAI,QAAQ,CAAC;QACrC,EAAE,GAAG,CAAC,MAAM,QAAQ,EAAE,UAAU,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAElE,OAAO,OAAO,CAAC,GAAG,CAAC,EAAC,OAAO,EAAE,GAAG,EAAC,EAAE,EAAE,CAAC,CAAC;KACxC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAc;IACvC,MAAM,GAAG,GAAG,aAAa,EAAE,CAAC;IAE5B,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QACvB,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC;KACnB;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAO;IACjC,OAAO,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import {AsyncLocalStorage, AsyncResource} from \"async_hooks\";\nimport type {DIContext} from \"../domain/DIContext\";\nimport type {InjectorService} from \"../services/InjectorService\";\n\nconst storage: AsyncLocalStorage<{current: DIContext | undefined}> = new AsyncLocalStorage();\n\nexport function getAsyncStore() {\n return storage;\n}\n\nexport function useContextRef() {\n return getAsyncStore().getStore();\n}\n\nexport function getContext<Context = DIContext>(): Context | undefined {\n return useContextRef()?.current as any;\n}\n\nexport async function runInContext(ctx: DIContext | undefined, cb: any, injector?: InjectorService) {\n const ref = useContextRef();\n\n if (ref) {\n ctx && setContext(ctx);\n return cb();\n } else {\n injector = ctx?.injector || injector;\n cb = (await injector?.alterAsync(\"$alterRunInContext\", cb)) || cb;\n\n return storage.run({current: ctx}, cb);\n }\n}\n\nexport function setContext(ctx: DIContext) {\n const ref = useContextRef();\n\n if (ref && !ref.current) {\n ref.current = ctx;\n }\n}\n\nexport function bindContext(cb: any) {\n return AsyncResource.bind(cb);\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Container } from "../domain/Container";
|
|
2
|
-
import { GlobalProviders } from "../registries/GlobalProviders";
|
|
1
|
+
import { Container } from "../domain/Container.js";
|
|
2
|
+
import { GlobalProviders } from "../registries/GlobalProviders.js";
|
|
3
3
|
export function createContainer(rootModule) {
|
|
4
4
|
const container = new Container(GlobalProviders.entries());
|
|
5
5
|
if (rootModule) {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
export function mergeMount(m1 = {}, m2 = {}) {
|
|
3
|
+
return Object.entries(m2).reduce((mount, [key, controllers]) => {
|
|
4
|
+
return {
|
|
5
|
+
...mount,
|
|
6
|
+
[key]: (mount[key] || []).concat(controllers)
|
|
7
|
+
};
|
|
8
|
+
}, m1);
|
|
9
|
+
}
|
|
2
10
|
export function getConfiguration(module, configuration = {}) {
|
|
3
11
|
const store = Store.from(module).get("configuration") || {};
|
|
4
|
-
|
|
12
|
+
return {
|
|
5
13
|
...store,
|
|
6
|
-
...configuration
|
|
14
|
+
...configuration,
|
|
15
|
+
mount: mergeMount(store.mount, configuration.mount)
|
|
7
16
|
};
|
|
8
|
-
if (store.mount && configuration.mount) {
|
|
9
|
-
config.mount = deepMerge(store.mount, configuration.mount);
|
|
10
|
-
}
|
|
11
|
-
if (store.componentsScan && configuration.componentsScan) {
|
|
12
|
-
config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];
|
|
13
|
-
}
|
|
14
|
-
return config;
|
|
15
17
|
}
|
|
16
18
|
//# sourceMappingURL=getConfiguration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getConfiguration.js","sourceRoot":"","sources":["../../../src/utils/getConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"getConfiguration.js","sourceRoot":"","sources":["../../../src/utils/getConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAO,MAAM,YAAY,CAAC;AAEvC,MAAM,UAAU,UAAU,CAAC,KAAU,EAAE,EAAE,KAAU,EAAE;IACnD,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;QAC7D,OAAO;YACL,GAAG,KAAK;YACR,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;SAC9C,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAiB,EAAE,gBAAqB,EAAE;IACzE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAE5D,OAAO;QACL,GAAG,KAAK;QACR,GAAG,aAAa;QAChB,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC;KACpD,CAAC;AACJ,CAAC","sourcesContent":["import {Store, Type} from \"@tsed/core\";\n\nexport function mergeMount(m1: any = {}, m2: any = {}) {\n return Object.entries(m2).reduce((mount, [key, controllers]) => {\n return {\n ...mount,\n [key]: (mount[key] || []).concat(controllers)\n };\n }, m1);\n}\n\nexport function getConfiguration(module: Type<any>, configuration: any = {}) {\n const store = Store.from(module).get(\"configuration\") || {};\n\n return {\n ...store,\n ...configuration,\n mount: mergeMount(store.mount, configuration.mount)\n };\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isArray, isClass } from "@tsed/core";
|
|
2
|
+
import { GlobalProviders } from "../registries/GlobalProviders.js";
|
|
3
|
+
import { ProviderType } from "../domain/ProviderType.js";
|
|
4
|
+
const lookupProperties = ["mount", "imports"];
|
|
5
|
+
export function getTokens(config) {
|
|
6
|
+
if (!config) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
if (isArray(config)) {
|
|
10
|
+
return config.filter(isClass).map((value) => {
|
|
11
|
+
return { token: value };
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return Object.keys(config).reduce((list, route) => {
|
|
15
|
+
return [
|
|
16
|
+
...list,
|
|
17
|
+
...[]
|
|
18
|
+
.concat(config[route])
|
|
19
|
+
.filter(isClass)
|
|
20
|
+
.map((token) => ({
|
|
21
|
+
route,
|
|
22
|
+
token
|
|
23
|
+
}))
|
|
24
|
+
];
|
|
25
|
+
}, []);
|
|
26
|
+
}
|
|
27
|
+
function resolveRecursively(providers) {
|
|
28
|
+
return providers
|
|
29
|
+
.map(({ token }) => GlobalProviders.get(token))
|
|
30
|
+
.filter((provider) => provider?.type === ProviderType.MODULE && provider.configuration)
|
|
31
|
+
.flatMap((provider) => resolveControllers(provider.configuration));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Return controllers and is base route according to his configuration in module configuration.
|
|
35
|
+
*
|
|
36
|
+
* @param settings
|
|
37
|
+
*/
|
|
38
|
+
export function resolveControllers(settings) {
|
|
39
|
+
const providers = lookupProperties.flatMap((property) => getTokens(settings[property]));
|
|
40
|
+
return [...resolveRecursively(providers), ...providers].filter((provider) => !!provider.route);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=resolveControllers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveControllers.js","sourceRoot":"","sources":["../../../src/utils/resolveControllers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAIpD,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAE9C,MAAM,UAAU,SAAS,CAAC,MAAW;IACnC,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE;QACnB,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE;YAC/C,OAAO,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC;QACxB,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,IAAW,EAAE,KAAa,EAAE,EAAE;QAC/D,OAAO;YACL,GAAG,IAAI;YACP,GAAG,EAAE;iBACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBACrB,MAAM,CAAC,OAAO,CAAC;iBACf,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACf,KAAK;gBACL,KAAK;aACN,CAAC,CAAC;SACN,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED,SAAS,kBAAkB,CAAC,SAAmD;IAC7E,OAAO,SAAS;SACb,GAAG,CAAC,CAAC,EAAC,KAAK,EAAC,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC5C,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,IAAI,KAAK,YAAY,CAAC,MAAM,IAAI,QAAQ,CAAC,aAAa,CAAC;SACtF,OAAO,CAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;AACjF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAqC;IACtE,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,GAAG,kBAAkB,CAAC,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAU,CAAC;AAC1G,CAAC","sourcesContent":["import {isArray, isClass} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {Provider} from \"../domain/Provider\";\nimport {TokenRoute} from \"../interfaces/TokenRoute\";\n\nconst lookupProperties = [\"mount\", \"imports\"];\n\nexport function getTokens(config: any): {route?: string; token: TokenProvider}[] {\n if (!config) {\n return [];\n }\n\n if (isArray(config)) {\n return config.filter(isClass).map((value: any) => {\n return {token: value};\n });\n }\n\n return Object.keys(config).reduce((list: any[], route: string) => {\n return [\n ...list,\n ...[]\n .concat(config[route])\n .filter(isClass)\n .map((token) => ({\n route,\n token\n }))\n ];\n }, []);\n}\n\nfunction resolveRecursively(providers: {token: TokenProvider; route?: string}[]) {\n return providers\n .map(({token}) => GlobalProviders.get(token))\n .filter((provider) => provider?.type === ProviderType.MODULE && provider.configuration)\n .flatMap((provider: Provider) => resolveControllers(provider.configuration));\n}\n\n/**\n * Return controllers and is base route according to his configuration in module configuration.\n *\n * @param settings\n */\nexport function resolveControllers(settings: Partial<TsED.Configuration>): TokenRoute[] {\n const providers = lookupProperties.flatMap((property) => getTokens(settings[property]));\n\n return [...resolveRecursively(providers), ...providers].filter((provider) => !!provider.route) as any[];\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { setLoggerFormat } from "./setLoggerFormat.js";
|
|
2
|
+
import { setLoggerLevel } from "./setLoggerLevel.js";
|
|
3
|
+
export function setLoggerConfiguration(injector) {
|
|
4
|
+
setLoggerLevel(injector);
|
|
5
|
+
setLoggerFormat(injector);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=setLoggerConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setLoggerConfiguration.js","sourceRoot":"","sources":["../../../src/utils/setLoggerConfiguration.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,MAAM,UAAU,sBAAsB,CAAC,QAAyB;IAC9D,cAAc,CAAC,QAAQ,CAAC,CAAC;IACzB,eAAe,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import type {InjectorService} from \"../services/InjectorService\";\nimport {setLoggerFormat} from \"./setLoggerFormat\";\nimport {setLoggerLevel} from \"./setLoggerLevel\";\n\nexport function setLoggerConfiguration(injector: InjectorService) {\n setLoggerLevel(injector);\n setLoggerFormat(injector);\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
* @param injector
|
|
4
|
+
*/
|
|
5
|
+
export function setLoggerFormat(injector) {
|
|
6
|
+
const { level, format } = injector.settings.logger;
|
|
7
|
+
if (level) {
|
|
8
|
+
injector.logger.level = level;
|
|
9
|
+
}
|
|
10
|
+
if (format && injector.logger.appenders) {
|
|
11
|
+
injector.logger.appenders.set("stdout", {
|
|
12
|
+
type: "stdout",
|
|
13
|
+
levels: ["info", "debug"],
|
|
14
|
+
layout: {
|
|
15
|
+
type: "pattern",
|
|
16
|
+
pattern: format
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
injector.logger.appenders.set("stderr", {
|
|
20
|
+
levels: ["trace", "fatal", "error", "warn"],
|
|
21
|
+
type: "stderr",
|
|
22
|
+
layout: {
|
|
23
|
+
type: "pattern",
|
|
24
|
+
pattern: format
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=setLoggerFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setLoggerFormat.js","sourceRoot":"","sources":["../../../src/utils/setLoggerFormat.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,QAAyB;IACvD,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;IAEjD,IAAI,KAAK,EAAE;QACT,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/B;IAED,IAAI,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE;QACvC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YACzB,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,MAAM;aAChB;SACF,CAAC,CAAC;QAEH,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE;YACtC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC;YAC3C,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,MAAM;aAChB;SACF,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["import type {InjectorService} from \"../services/InjectorService\";\n\n/**\n * @ignore\n * @param injector\n */\nexport function setLoggerFormat(injector: InjectorService) {\n const {level, format} = injector.settings.logger;\n\n if (level) {\n injector.logger.level = level;\n }\n\n if (format && injector.logger.appenders) {\n injector.logger.appenders.set(\"stdout\", {\n type: \"stdout\",\n levels: [\"info\", \"debug\"],\n layout: {\n type: \"pattern\",\n pattern: format\n }\n });\n\n injector.logger.appenders.set(\"stderr\", {\n levels: [\"trace\", \"fatal\", \"error\", \"warn\"],\n type: \"stderr\",\n layout: {\n type: \"pattern\",\n pattern: format\n }\n });\n }\n}\n"]}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* @param injector
|
|
4
4
|
*/
|
|
5
5
|
export function setLoggerLevel(injector) {
|
|
6
|
-
|
|
7
|
-
const level = (_a = injector.settings.logger) === null || _a === void 0 ? void 0 : _a.level;
|
|
6
|
+
const { level } = injector.settings.logger;
|
|
8
7
|
if (level) {
|
|
9
8
|
injector.logger.level = level;
|
|
10
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setLoggerLevel.js","sourceRoot":"","sources":["../../../src/utils/setLoggerLevel.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAyB
|
|
1
|
+
{"version":3,"file":"setLoggerLevel.js","sourceRoot":"","sources":["../../../src/utils/setLoggerLevel.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAyB;IACtD,MAAM,EAAC,KAAK,EAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;IAEzC,IAAI,KAAK,EAAE;QACT,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/B;AACH,CAAC","sourcesContent":["import type {InjectorService} from \"../services/InjectorService\";\n\n/**\n * @ignore\n * @param injector\n */\nexport function setLoggerLevel(injector: InjectorService) {\n const {level} = injector.settings.logger;\n\n if (level) {\n injector.logger.level = level;\n }\n}\n"]}
|
|
File without changes
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
3
3
|
export declare type PathType = string | RegExp | (string | RegExp)[];
|
|
4
4
|
export interface ControllerMiddlewares {
|
|
5
5
|
useBefore: any[];
|
|
6
6
|
use: any[];
|
|
7
7
|
useAfter: any[];
|
|
8
8
|
}
|
|
9
|
-
export interface ControllerOptions extends Partial<
|
|
9
|
+
export interface ControllerOptions extends Partial<ProviderOpts<any>> {
|
|
10
10
|
path?: PathType;
|
|
11
11
|
children?: Type<any>[];
|
|
12
|
-
routerOptions?: any;
|
|
13
12
|
middlewares?: Partial<ControllerMiddlewares>;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
@@ -19,3 +19,18 @@ export declare function injectProperty(target: any, propertyKey: string, options
|
|
|
19
19
|
* @decorator
|
|
20
20
|
*/
|
|
21
21
|
export declare function Inject(symbol?: any, onGet?: (bean: any) => any): Function;
|
|
22
|
+
/**
|
|
23
|
+
* Inject a context like PlatformContext or any BaseContext.
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* @Injectable()
|
|
27
|
+
* export class MyService {
|
|
28
|
+
* @InjectContext()
|
|
29
|
+
* ctx?: Context;
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @returns {Function}
|
|
34
|
+
* @decorator
|
|
35
|
+
*/
|
|
36
|
+
export declare function InjectContext(): PropertyDecorator;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
2
2
|
/**
|
|
3
3
|
* The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.
|
|
4
4
|
* All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.
|
|
5
5
|
*
|
|
6
|
-
* <<< @/docs/snippets/providers/getting-started-injectable.ts
|
|
7
|
-
*
|
|
8
6
|
* ::: tip
|
|
9
7
|
* `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.
|
|
10
8
|
* :::
|
|
@@ -19,4 +17,4 @@ import type { IProvider } from "../interfaces";
|
|
|
19
17
|
* @returns {Function}
|
|
20
18
|
* @decorator
|
|
21
19
|
*/
|
|
22
|
-
export declare function Injectable(options?: Partial<
|
|
20
|
+
export declare function Injectable(options?: Partial<ProviderOpts>): ClassDecorator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
-
import type { InterceptorMethods } from "../interfaces";
|
|
2
|
+
import type { InterceptorMethods } from "../interfaces/InterceptorMethods";
|
|
3
3
|
/**
|
|
4
4
|
* Attaches interceptor to method call and executes the before and after methods
|
|
5
5
|
*
|
|
@@ -7,4 +7,4 @@ import type { InterceptorMethods } from "../interfaces";
|
|
|
7
7
|
* @param options
|
|
8
8
|
* @decorator
|
|
9
9
|
*/
|
|
10
|
-
export declare function Intercept<T extends InterceptorMethods>(interceptor: Type<T>, options?: any):
|
|
10
|
+
export declare function Intercept<T extends InterceptorMethods>(interceptor: Type<T>, options?: any): any;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ProviderScope } from "../domain";
|
|
2
|
-
import
|
|
1
|
+
import { ProviderScope } from "../domain/ProviderScope";
|
|
2
|
+
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
3
|
+
import { DIResolver } from "../interfaces/DIResolver";
|
|
3
4
|
export interface ModuleOptions extends Omit<TsED.Configuration, "scopes"> {
|
|
4
5
|
/**
|
|
5
6
|
* Provider scope
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
2
2
|
import type { ProviderType } from "./ProviderType";
|
|
3
3
|
import type { TokenProvider } from "../interfaces/TokenProvider";
|
|
4
4
|
import { Provider } from "./Provider";
|
|
@@ -8,13 +8,13 @@ export declare class Container extends Map<TokenProvider, Provider> {
|
|
|
8
8
|
* @param token
|
|
9
9
|
* @param settings
|
|
10
10
|
*/
|
|
11
|
-
add(token: TokenProvider, settings?: Partial<
|
|
11
|
+
add(token: TokenProvider, settings?: Partial<ProviderOpts>): this;
|
|
12
12
|
/**
|
|
13
13
|
* Add a provider to the
|
|
14
14
|
* @param token
|
|
15
15
|
* @param settings
|
|
16
16
|
*/
|
|
17
|
-
addProvider(token: TokenProvider, settings?: Partial<
|
|
17
|
+
addProvider(token: TokenProvider, settings?: Partial<ProviderOpts>): this;
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
20
20
|
* @param token
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
+
import { Hooks } from "@tsed/core";
|
|
1
2
|
import { LogLevel } from "@tsed/logger";
|
|
3
|
+
import { DILogger } from "../interfaces/DILogger";
|
|
2
4
|
export interface ContextLoggerOptions extends Record<string, any> {
|
|
3
5
|
id: string;
|
|
4
|
-
|
|
5
|
-
dateStart?: Date;
|
|
6
|
+
logger?: DILogger;
|
|
6
7
|
level?: "debug" | "info" | "warn" | "error" | "off" | "all";
|
|
7
8
|
maxStackSize?: number;
|
|
8
|
-
minimalRequestPicker?: (o: any) => any;
|
|
9
|
-
completeRequestPicker?: (o: any) => any;
|
|
10
|
-
ignoreLog?: (data: any) => boolean;
|
|
11
9
|
additionalProps?: Record<any, any>;
|
|
12
10
|
}
|
|
13
11
|
export declare class ContextLogger {
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
minimalRequestPicker: Function;
|
|
18
|
-
completeRequestPicker: Function;
|
|
12
|
+
#private;
|
|
13
|
+
readonly dateStart: Date;
|
|
14
|
+
readonly id: string;
|
|
19
15
|
maxStackSize: number;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
private stack;
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
level: LogLevel;
|
|
17
|
+
constructor({ id, logger, dateStart, level, maxStackSize, additionalProps }: ContextLoggerOptions);
|
|
18
|
+
get hooks(): Hooks;
|
|
19
|
+
private get stack();
|
|
20
|
+
alterLog(cb: (data: any, level: "debug" | "info" | "warn" | "error" | "off" | "all", withRequest: boolean) => any): Hooks;
|
|
21
|
+
alterIgnoreLog(cb: (ignore: boolean, data: any) => boolean): Hooks;
|
|
26
22
|
info(obj: any): this;
|
|
27
23
|
debug(obj: any, withRequest?: boolean): this;
|
|
28
24
|
warn(obj: any): this;
|
|
@@ -30,12 +26,11 @@ export declare class ContextLogger {
|
|
|
30
26
|
trace(obj: any): this;
|
|
31
27
|
flush(): void;
|
|
32
28
|
isLevelEnabled(otherLevel: string | LogLevel): boolean;
|
|
33
|
-
destroy(): void;
|
|
34
29
|
/**
|
|
35
30
|
* Return the duration between the time when LogIncomingRequest has handle the request and now.
|
|
36
31
|
* @returns {number}
|
|
37
32
|
*/
|
|
38
33
|
protected getDuration(): number;
|
|
39
34
|
protected getData(obj: any): any;
|
|
40
|
-
protected run(level: LogLevel, obj: any,
|
|
35
|
+
protected run(level: LogLevel, obj: any, withRequest?: boolean): void;
|
|
41
36
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ControllerMiddlewares } from "../decorators/controller";
|
|
2
|
+
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
3
|
+
import { Provider } from "./Provider";
|
|
4
|
+
export declare class ControllerProvider<T = any> extends Provider<T> {
|
|
5
|
+
tokenRouter: string;
|
|
6
|
+
constructor(provide: TokenProvider, options?: Partial<Provider>);
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @returns {any[]}
|
|
10
|
+
*/
|
|
11
|
+
get middlewares(): ControllerMiddlewares;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param middlewares
|
|
15
|
+
*/
|
|
16
|
+
set middlewares(middlewares: ControllerMiddlewares);
|
|
17
|
+
}
|
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
import type { Env } from "@tsed/core";
|
|
2
1
|
import { InjectorService } from "../services/InjectorService";
|
|
3
2
|
import { ContextLogger, ContextLoggerOptions } from "./ContextLogger";
|
|
4
3
|
import { LocalsContainer } from "./LocalsContainer";
|
|
5
|
-
export interface ContextMethods extends Map<any, any> {
|
|
6
|
-
readonly id: string;
|
|
7
|
-
readonly logger: ContextLogger;
|
|
8
|
-
readonly injector: InjectorService;
|
|
9
|
-
readonly container: LocalsContainer;
|
|
10
|
-
readonly env: Env;
|
|
11
|
-
destroy(): any;
|
|
12
|
-
}
|
|
13
|
-
declare global {
|
|
14
|
-
namespace TsED {
|
|
15
|
-
interface Context {
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
4
|
export interface DIContextOptions extends Omit<ContextLoggerOptions, "dateStart"> {
|
|
20
5
|
id: string;
|
|
6
|
+
injector: InjectorService;
|
|
21
7
|
logger: any;
|
|
22
|
-
injector?: InjectorService;
|
|
23
8
|
}
|
|
24
|
-
export declare class DIContext
|
|
9
|
+
export declare class DIContext {
|
|
10
|
+
#private;
|
|
11
|
+
opts: DIContextOptions;
|
|
25
12
|
[x: string]: any;
|
|
13
|
+
constructor(opts: DIContextOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Logger attached to the context request.
|
|
16
|
+
*/
|
|
17
|
+
get logger(): ContextLogger;
|
|
26
18
|
/**
|
|
27
19
|
* Request id generated by @@contextMiddleware@@.
|
|
28
20
|
*
|
|
@@ -47,26 +39,22 @@ export declare class DIContext extends Map<any, any> implements ContextMethods {
|
|
|
47
39
|
* :::
|
|
48
40
|
*
|
|
49
41
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
readonly dateStart: Date;
|
|
55
|
-
/**
|
|
56
|
-
* The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
|
|
57
|
-
*/
|
|
58
|
-
container: LocalsContainer<any>;
|
|
59
|
-
/**
|
|
60
|
-
* Logger attached to the context request.
|
|
61
|
-
*/
|
|
62
|
-
logger: ContextLogger;
|
|
42
|
+
get id(): string;
|
|
43
|
+
get dateStart(): Date;
|
|
44
|
+
get injector(): InjectorService;
|
|
45
|
+
get env(): any;
|
|
63
46
|
/**
|
|
64
|
-
*
|
|
47
|
+
* The request container used by the Ts.ED DI. It contains all services annotated with `@Scope(ProviderScope.REQUEST)`
|
|
65
48
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
get env(): any;
|
|
69
|
-
destroy(): Promise<void>;
|
|
49
|
+
get container(): LocalsContainer;
|
|
50
|
+
destroy(): Promise<any>;
|
|
70
51
|
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
52
|
+
runInContext(next: Function): Promise<any>;
|
|
53
|
+
cache<Value = any>(key: string, cb: () => Value): Value;
|
|
54
|
+
cacheAsync<Value = any>(key: string, cb: () => Promise<Value>): Promise<Value>;
|
|
55
|
+
delete(key: any): boolean;
|
|
56
|
+
get<T = any>(key: any): T;
|
|
57
|
+
has(key: any): boolean;
|
|
58
|
+
set(key: any, value: any): this;
|
|
71
59
|
}
|
|
72
60
|
export declare type BaseContext = DIContext & TsED.Context;
|
|
@@ -1,25 +1,6 @@
|
|
|
1
|
+
import { Hooks } from "@tsed/core";
|
|
1
2
|
import type { TokenProvider } from "../interfaces/TokenProvider";
|
|
2
|
-
export declare class LocalsContainer
|
|
3
|
-
|
|
4
|
-
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
5
|
-
* @param eventName The event name to emit at all services.
|
|
6
|
-
* @param args List of the parameters to give to each services.
|
|
7
|
-
* @returns {Promise<any[]>} A list of promises.
|
|
8
|
-
*/
|
|
9
|
-
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* @param eventName
|
|
12
|
-
* @param value
|
|
13
|
-
* @param args
|
|
14
|
-
*/
|
|
15
|
-
alter<T = any>(eventName: string, value: any, ...args: any[]): T;
|
|
16
|
-
/**
|
|
17
|
-
* @param eventName
|
|
18
|
-
* @param value
|
|
19
|
-
* @param args
|
|
20
|
-
*/
|
|
21
|
-
alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T>;
|
|
22
|
-
toArray(): V[];
|
|
3
|
+
export declare class LocalsContainer extends Map<TokenProvider, any> {
|
|
4
|
+
readonly hooks: Hooks;
|
|
23
5
|
destroy(): Promise<void>;
|
|
24
|
-
protected getListeners(event: string): any[];
|
|
25
6
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { Store, Type } from "@tsed/core";
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
3
|
+
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
3
4
|
import { ProviderScope } from "./ProviderScope";
|
|
4
5
|
import { ProviderType } from "./ProviderType";
|
|
5
|
-
export declare
|
|
6
|
+
export declare type ProviderHookCallback<T = any> = (instance: T, ...args: any[]) => Promise<void> | void;
|
|
7
|
+
export declare class Provider<T = any> implements ProviderOpts<T> {
|
|
6
8
|
type: ProviderType | any;
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Use injector.get(provider.token) instead.
|
|
9
|
-
*/
|
|
10
|
-
instance: T;
|
|
11
9
|
deps: TokenProvider[];
|
|
12
10
|
imports: any[];
|
|
13
11
|
useFactory: Function;
|
|
14
12
|
useAsyncFactory: Function;
|
|
15
13
|
useValue: any;
|
|
14
|
+
hooks?: Record<string, ProviderHookCallback<T>>;
|
|
16
15
|
private _useClass;
|
|
17
16
|
private _provide;
|
|
18
17
|
private _store;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,17 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./constants/constants";
|
|
5
|
+
export * from "./decorators/configuration";
|
|
6
|
+
export * from "./decorators/constant";
|
|
7
|
+
export * from "./decorators/controller";
|
|
8
|
+
export * from "./decorators/inject";
|
|
9
|
+
export * from "./decorators/injectable";
|
|
10
|
+
export * from "./decorators/intercept";
|
|
11
|
+
export * from "./decorators/interceptor";
|
|
12
|
+
export * from "./decorators/lazyInject";
|
|
13
|
+
export * from "./decorators/module";
|
|
14
|
+
export * from "./decorators/opts";
|
|
15
|
+
export * from "./decorators/overrideProvider";
|
|
16
|
+
export * from "./decorators/scope";
|
|
17
|
+
export * from "./decorators/service";
|
|
18
|
+
export * from "./decorators/useOpts";
|
|
19
|
+
export * from "./decorators/value";
|
|
20
|
+
export * from "./domain/Container";
|
|
21
|
+
export * from "./domain/ContextLogger";
|
|
22
|
+
export * from "./domain/ControllerProvider";
|
|
23
|
+
export * from "./domain/DIContext";
|
|
24
|
+
export * from "./domain/InjectablePropertyType";
|
|
25
|
+
export * from "./domain/LocalsContainer";
|
|
26
|
+
export * from "./domain/Provider";
|
|
27
|
+
export * from "./domain/ProviderScope";
|
|
28
|
+
export * from "./domain/ProviderType";
|
|
29
|
+
export * from "./errors/InjectionError";
|
|
30
|
+
export * from "./errors/UndefinedTokenError";
|
|
31
|
+
export * from "./interfaces/AlterRunInContext";
|
|
32
|
+
export * from "./interfaces/DIConfigurationOptions";
|
|
33
|
+
export * from "./interfaces/DILogger";
|
|
34
|
+
export * from "./interfaces/DILoggerOptions";
|
|
35
|
+
export * from "./interfaces/DIResolver";
|
|
36
|
+
export * from "./interfaces/InjectableProperties";
|
|
37
|
+
export * from "./interfaces/InterceptorContext";
|
|
38
|
+
export * from "./interfaces/InterceptorMethods";
|
|
39
|
+
export * from "./interfaces/InvokeOptions";
|
|
40
|
+
export * from "./interfaces/OnDestroy";
|
|
41
|
+
export * from "./interfaces/OnInit";
|
|
42
|
+
export * from "./interfaces/ProviderOpts";
|
|
43
|
+
export * from "./interfaces/RegistrySettings";
|
|
44
|
+
export * from "./interfaces/ResolvedInvokeOptions";
|
|
45
|
+
export * from "./interfaces/TokenProvider";
|
|
46
|
+
export * from "./interfaces/TokenRoute";
|
|
6
47
|
export * from "./registries/GlobalProviders";
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./services/DILogger";
|
|
48
|
+
export * from "./registries/ProviderRegistry";
|
|
9
49
|
export * from "./services/DIConfiguration";
|
|
50
|
+
export * from "./services/DILogger";
|
|
10
51
|
export * from "./services/DITest";
|
|
11
|
-
export * from "./
|
|
12
|
-
export * from "./
|
|
52
|
+
export * from "./services/InjectorService";
|
|
53
|
+
export * from "./utils/asyncHookContext";
|
|
54
|
+
export * from "./utils/colors";
|
|
13
55
|
export * from "./utils/createContainer";
|
|
14
56
|
export * from "./utils/getConfiguration";
|
|
15
|
-
export * from "./utils/
|
|
57
|
+
export * from "./utils/resolveControllers";
|
|
58
|
+
export * from "./utils/setLoggerConfiguration";
|
|
59
|
+
export * from "./utils/setLoggerFormat";
|
|
16
60
|
export * from "./utils/setLoggerLevel";
|
|
17
|
-
export * from "./utils/colors";
|
|
@@ -5,7 +5,7 @@ declare global {
|
|
|
5
5
|
namespace TsED {
|
|
6
6
|
interface Context {
|
|
7
7
|
}
|
|
8
|
-
interface Configuration {
|
|
8
|
+
interface Configuration extends Record<string, any> {
|
|
9
9
|
scopes: {
|
|
10
10
|
[key: string]: ProviderScope;
|
|
11
11
|
};
|
|
@@ -17,7 +17,10 @@ declare global {
|
|
|
17
17
|
* Define dependencies to build the provider
|
|
18
18
|
*/
|
|
19
19
|
imports: TokenProvider[];
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Mount controllers
|
|
22
|
+
*/
|
|
23
|
+
mount: Record<string, TokenProvider[]>;
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
}
|