@tsed/di 8.14.2-rc.2 → 8.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/common/decorators/autoInjectable.js +1 -6
- package/lib/esm/common/index.js +0 -7
- package/lib/esm/{common → node}/domain/DIContext.js +1 -1
- package/lib/esm/node/fn/context.js +1 -1
- package/lib/esm/node/index.js +7 -0
- package/lib/esm/node/services/DITest.js +2 -2
- package/lib/esm/node/utils/asyncHookContext.js +0 -3
- package/lib/esm/{common → node}/utils/attachLogger.js +1 -1
- package/lib/esm/{common → node}/utils/setLoggerFormat.js +2 -2
- package/lib/esm/{common → node}/utils/setLoggerLevel.js +1 -1
- package/lib/types/common/decorators/controller.d.ts +1 -1
- package/lib/types/common/decorators/inject.d.ts +1 -1
- package/lib/types/common/decorators/intercept.d.ts +1 -1
- package/lib/types/common/decorators/overrideProvider.d.ts +1 -1
- package/lib/types/common/domain/Provider.d.ts +1 -1
- package/lib/types/common/index.d.ts +0 -7
- package/lib/types/common/interfaces/RegistrySettings.d.ts +1 -1
- package/lib/types/common/registries/GlobalProviders.d.ts +1 -1
- package/lib/types/common/utils/createContainer.d.ts +1 -1
- package/lib/types/common/utils/discoverHooks.d.ts +1 -1
- package/lib/types/common/utils/getConfiguration.d.ts +1 -1
- package/lib/types/common/utils/providerBuilder.d.ts +1 -1
- package/lib/types/node/decorators/injectContext.d.ts +1 -1
- package/lib/types/{common → node}/domain/DIContext.d.ts +1 -1
- package/lib/types/node/fn/context.d.ts +1 -1
- package/lib/types/node/fn/contextLogger.d.ts +1 -1
- package/lib/types/node/index.d.ts +7 -0
- package/lib/types/node/services/DITest.d.ts +1 -1
- package/lib/types/node/utils/asyncHookContext.d.ts +1 -4
- package/lib/types/{common → node}/utils/attachLogger.d.ts +1 -1
- package/package.json +10 -13
- package/lib/esm/browser/decorators/injectContext.js +0 -26
- package/lib/esm/browser/fn/context.js +0 -20
- package/lib/esm/browser/fn/contextLogger.js +0 -8
- package/lib/esm/browser/index.js +0 -5
- package/lib/esm/browser/utils/asyncHookContext.js +0 -67
- package/lib/types/browser/decorators/injectContext.d.ts +0 -16
- package/lib/types/browser/fn/context.d.ts +0 -9
- package/lib/types/browser/fn/contextLogger.d.ts +0 -5
- package/lib/types/browser/index.d.ts +0 -5
- package/lib/types/browser/utils/asyncHookContext.d.ts +0 -22
- /package/lib/esm/{common → node}/domain/ContextLogger.js +0 -0
- /package/lib/esm/{common → node}/interfaces/AlterRunInContext.js +0 -0
- /package/lib/esm/{common → node}/utils/setLoggerConfiguration.js +0 -0
- /package/lib/types/{common → node}/domain/ContextLogger.d.ts +0 -0
- /package/lib/types/{common → node}/interfaces/AlterRunInContext.d.ts +0 -0
- /package/lib/types/{common → node}/utils/setLoggerConfiguration.d.ts +0 -0
- /package/lib/types/{common → node}/utils/setLoggerFormat.d.ts +0 -0
- /package/lib/types/{common → node}/utils/setLoggerLevel.d.ts +0 -0
|
@@ -14,12 +14,7 @@ function resolveAutoInjectableArgs(token, args) {
|
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
16
|
const value = deps[i];
|
|
17
|
-
const instance = isArray(value)
|
|
18
|
-
? inj.getMany(value[0], { locals, parent: token })
|
|
19
|
-
: inj.invoke(value, {
|
|
20
|
-
locals,
|
|
21
|
-
parent: token
|
|
22
|
-
});
|
|
17
|
+
const instance = isArray(value) ? inj.getMany(value[0], { locals, parent: token }) : inj.invoke(value, { locals, parent: token });
|
|
23
18
|
list.push(instance);
|
|
24
19
|
}
|
|
25
20
|
}
|
package/lib/esm/common/index.js
CHANGED
|
@@ -19,9 +19,7 @@ export * from "./decorators/service.js";
|
|
|
19
19
|
export * from "./decorators/useOpts.js";
|
|
20
20
|
export * from "./decorators/value.js";
|
|
21
21
|
export * from "./domain/Container.js";
|
|
22
|
-
export * from "./domain/ContextLogger.js";
|
|
23
22
|
export * from "./domain/ControllerProvider.js";
|
|
24
|
-
export * from "./domain/DIContext.js";
|
|
25
23
|
export * from "./domain/InjectablePropertyType.js";
|
|
26
24
|
export * from "./domain/LocalsContainer.js";
|
|
27
25
|
export * from "./domain/Provider.js";
|
|
@@ -39,7 +37,6 @@ export * from "./fn/lazyInject.js";
|
|
|
39
37
|
export * from "./fn/localsContainer.js";
|
|
40
38
|
export * from "./fn/logger.js";
|
|
41
39
|
export * from "./fn/refValue.js";
|
|
42
|
-
export * from "./interfaces/AlterRunInContext.js";
|
|
43
40
|
export * from "./interfaces/DIConfigurationOptions.js";
|
|
44
41
|
export * from "./interfaces/DILogger.js";
|
|
45
42
|
export * from "./interfaces/DILoggerOptions.js";
|
|
@@ -59,13 +56,9 @@ export * from "./registries/ProviderRegistry.js";
|
|
|
59
56
|
export * from "./services/DIConfiguration.js";
|
|
60
57
|
export * from "./services/DILogger.js";
|
|
61
58
|
export * from "./services/InjectorService.js";
|
|
62
|
-
export * from "./utils/attachLogger.js";
|
|
63
59
|
export * from "./utils/colors.js";
|
|
64
60
|
export * from "./utils/createContainer.js";
|
|
65
61
|
export * from "./utils/discoverHooks.js";
|
|
66
62
|
export * from "./utils/getConfiguration.js";
|
|
67
63
|
export * from "./utils/getConstructorDependencies.js";
|
|
68
64
|
export * from "./utils/providerBuilder.js";
|
|
69
|
-
export * from "./utils/setLoggerConfiguration.js";
|
|
70
|
-
export * from "./utils/setLoggerFormat.js";
|
|
71
|
-
export * from "./utils/setLoggerLevel.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v4 } from "uuid";
|
|
2
|
-
import { DIContext } from "../../common/domain/DIContext.js";
|
|
3
2
|
import { injector } from "../../common/index.js";
|
|
3
|
+
import { DIContext } from "../domain/DIContext.js";
|
|
4
4
|
import { getContext } from "../utils/asyncHookContext.js";
|
|
5
5
|
/**
|
|
6
6
|
* Get the current DIContext instance using async hook node.js api.
|
package/lib/esm/node/index.js
CHANGED
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
* @file Automatically generated by @tsed/barrels.
|
|
3
3
|
*/
|
|
4
4
|
export * from "./decorators/injectContext.js";
|
|
5
|
+
export * from "./domain/ContextLogger.js";
|
|
6
|
+
export * from "./domain/DIContext.js";
|
|
5
7
|
export * from "./fn/context.js";
|
|
6
8
|
export * from "./fn/contextLogger.js";
|
|
9
|
+
export * from "./interfaces/AlterRunInContext.js";
|
|
7
10
|
export * from "./services/DILogger.js";
|
|
8
11
|
export * from "./services/DITest.js";
|
|
9
12
|
export * from "./utils/asyncHookContext.js";
|
|
13
|
+
export * from "./utils/attachLogger.js";
|
|
14
|
+
export * from "./utils/setLoggerConfiguration.js";
|
|
15
|
+
export * from "./utils/setLoggerFormat.js";
|
|
16
|
+
export * from "./utils/setLoggerLevel.js";
|
|
@@ -3,11 +3,11 @@ import { getValue } from "@tsed/core/utils/getValue.js";
|
|
|
3
3
|
import { isClass } from "@tsed/core/utils/isClass.js";
|
|
4
4
|
import { isObject } from "@tsed/core/utils/isObject.js";
|
|
5
5
|
import { $log } from "@tsed/logger";
|
|
6
|
-
import { DIContext } from "../../common/domain/DIContext.js";
|
|
7
6
|
import { cleanAllLocalsContainer, detachLocalsContainer, localsContainer } from "../../common/fn/localsContainer.js";
|
|
8
7
|
import { logger } from "../../common/fn/logger.js";
|
|
9
8
|
import { createContainer, destroyInjector, DI_INJECTABLE_PROPS, inject, injector } from "../../common/index.js";
|
|
10
|
-
import {
|
|
9
|
+
import { DIContext } from "../domain/DIContext.js";
|
|
10
|
+
import { setLoggerConfiguration } from "../utils/setLoggerConfiguration.js";
|
|
11
11
|
/**
|
|
12
12
|
* Tool to run test with lightweight DI sandbox.
|
|
13
13
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Type } from "@tsed/core/types/Type.js";
|
|
2
2
|
import type { ControllerMiddlewares } from "../domain/ControllerProvider.js";
|
|
3
3
|
import { ProviderOpts } from "../interfaces/ProviderOpts.js";
|
|
4
4
|
export type PathType = string | RegExp | (string | RegExp)[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Type } from "@tsed/core/types/Type.js";
|
|
2
2
|
import { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
3
3
|
export type TransformInjectedProviderCB<T, Klass = any> = (instance: T, { target, propertyKey }: {
|
|
4
4
|
self: Klass;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Type } from "@tsed/core/types/Type.js";
|
|
2
2
|
import type { InterceptorMethods } from "../interfaces/InterceptorMethods.js";
|
|
3
3
|
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
4
4
|
export declare function getInterceptorOptions<T>(target: Type<any>, propertyKey: string | symbol): T;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Store } from "@tsed/core/types/Store.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type AbstractType, Type } from "@tsed/core/types/Type.js";
|
|
3
3
|
import type { ProviderOpts } from "../interfaces/ProviderOpts.js";
|
|
4
4
|
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
5
5
|
import { ProviderScope } from "./ProviderScope.js";
|
|
@@ -19,9 +19,7 @@ export * from "./decorators/service.js";
|
|
|
19
19
|
export * from "./decorators/useOpts.js";
|
|
20
20
|
export * from "./decorators/value.js";
|
|
21
21
|
export * from "./domain/Container.js";
|
|
22
|
-
export * from "./domain/ContextLogger.js";
|
|
23
22
|
export * from "./domain/ControllerProvider.js";
|
|
24
|
-
export * from "./domain/DIContext.js";
|
|
25
23
|
export * from "./domain/InjectablePropertyType.js";
|
|
26
24
|
export * from "./domain/LocalsContainer.js";
|
|
27
25
|
export * from "./domain/Provider.js";
|
|
@@ -39,7 +37,6 @@ export * from "./fn/lazyInject.js";
|
|
|
39
37
|
export * from "./fn/localsContainer.js";
|
|
40
38
|
export * from "./fn/logger.js";
|
|
41
39
|
export * from "./fn/refValue.js";
|
|
42
|
-
export * from "./interfaces/AlterRunInContext.js";
|
|
43
40
|
export * from "./interfaces/DIConfigurationOptions.js";
|
|
44
41
|
export * from "./interfaces/DILogger.js";
|
|
45
42
|
export * from "./interfaces/DILoggerOptions.js";
|
|
@@ -59,13 +56,9 @@ export * from "./registries/ProviderRegistry.js";
|
|
|
59
56
|
export * from "./services/DIConfiguration.js";
|
|
60
57
|
export * from "./services/DILogger.js";
|
|
61
58
|
export * from "./services/InjectorService.js";
|
|
62
|
-
export * from "./utils/attachLogger.js";
|
|
63
59
|
export * from "./utils/colors.js";
|
|
64
60
|
export * from "./utils/createContainer.js";
|
|
65
61
|
export * from "./utils/discoverHooks.js";
|
|
66
62
|
export * from "./utils/getConfiguration.js";
|
|
67
63
|
export * from "./utils/getConstructorDependencies.js";
|
|
68
64
|
export * from "./utils/providerBuilder.js";
|
|
69
|
-
export * from "./utils/setLoggerConfiguration.js";
|
|
70
|
-
export * from "./utils/setLoggerFormat.js";
|
|
71
|
-
export * from "./utils/setLoggerLevel.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Type } from "@tsed/core/types/Type.js";
|
|
2
2
|
import { Provider } from "../domain/Provider.js";
|
|
3
3
|
import { ProviderOpts } from "../interfaces/ProviderOpts.js";
|
|
4
4
|
import { RegistrySettings } from "../interfaces/RegistrySettings.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AbstractType, type Type } from "@tsed/core/types/Type.js";
|
|
2
2
|
export declare function discoverHooks(token: Type | AbstractType<any>): any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../registries/ProviderRegistry.js";
|
|
2
2
|
import { Store } from "@tsed/core/types/Store.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type Type } from "@tsed/core/types/Type.js";
|
|
4
4
|
import type { ProviderOpts } from "../interfaces/ProviderOpts.js";
|
|
5
5
|
import type { FactoryTokenProvider, TokenProvider } from "../interfaces/TokenProvider.js";
|
|
6
6
|
type BaseMethodsProvider<TypeOf, BaseProvider, T extends object> = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InjectorService, LocalsContainer } from "
|
|
1
|
+
import { InjectorService, LocalsContainer } from "../../common/index.js";
|
|
2
2
|
import { ContextLogger, ContextLoggerOptions } from "./ContextLogger.js";
|
|
3
3
|
export interface DIContextOptions extends Omit<ContextLoggerOptions, "dateStart"> {
|
|
4
4
|
id: string;
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Get the current logger instance. If the logger() function is invoked in Request context, it will return the logger instance attached to the request context.
|
|
3
3
|
* Otherwise, it will return the logger instance attached to the DI context.
|
|
4
4
|
*/
|
|
5
|
-
export declare function contextLogger(): import("
|
|
5
|
+
export declare function contextLogger(): import("../index.js").ContextLogger;
|
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
* @file Automatically generated by @tsed/barrels.
|
|
3
3
|
*/
|
|
4
4
|
export * from "./decorators/injectContext.js";
|
|
5
|
+
export * from "./domain/ContextLogger.js";
|
|
6
|
+
export * from "./domain/DIContext.js";
|
|
5
7
|
export * from "./fn/context.js";
|
|
6
8
|
export * from "./fn/contextLogger.js";
|
|
9
|
+
export * from "./interfaces/AlterRunInContext.js";
|
|
7
10
|
export * from "./services/DILogger.js";
|
|
8
11
|
export * from "./services/DITest.js";
|
|
9
12
|
export * from "./utils/asyncHookContext.js";
|
|
13
|
+
export * from "./utils/attachLogger.js";
|
|
14
|
+
export * from "./utils/setLoggerConfiguration.js";
|
|
15
|
+
export * from "./utils/setLoggerFormat.js";
|
|
16
|
+
export * from "./utils/setLoggerLevel.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DIContext } from "../../common/domain/DIContext.js";
|
|
2
1
|
import { InjectorService, TokenProvider, type UseImportTokenProviderOpts } from "../../common/index.js";
|
|
2
|
+
import { DIContext } from "../domain/DIContext.js";
|
|
3
3
|
/**
|
|
4
4
|
* Tool to run test with lightweight DI sandbox.
|
|
5
5
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
-
import type { DIContext } from "../../common/domain/DIContext.js";
|
|
4
3
|
import { InjectorService } from "../../common/index.js";
|
|
4
|
+
import type { DIContext } from "../domain/DIContext.js";
|
|
5
5
|
export declare function getAsyncStore(): AsyncLocalStorage<{
|
|
6
6
|
current: DIContext | undefined;
|
|
7
7
|
}>;
|
|
@@ -11,7 +11,4 @@ export declare function useContextRef(): {
|
|
|
11
11
|
export declare function getContext<Context = DIContext>(initialValue?: DIContext): Context | undefined;
|
|
12
12
|
export declare function runInContext<Result = unknown>(ctx: DIContext | undefined, cb: (...args: unknown[]) => Result, injector?: InjectorService): Promise<Result>;
|
|
13
13
|
export declare function setContext(ctx: DIContext): void;
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated
|
|
16
|
-
*/
|
|
17
14
|
export declare function bindContext(cb: any): any;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DILogger } from "
|
|
1
|
+
import { DILogger } from "../../common/index.js";
|
|
2
2
|
export declare function attachLogger($log: DILogger): void;
|
package/package.json
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
"name": "@tsed/di",
|
|
3
3
|
"description": "DI module for Ts.ED Framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.15.1",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
9
9
|
"typings": "./lib/types/index.d.ts",
|
|
10
|
-
"browser": "./lib/esm/
|
|
10
|
+
"browser": "./lib/esm/common/index.js",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"tsed-source": "./src/index.ts",
|
|
14
14
|
"types": "./lib/types/index.d.ts",
|
|
15
|
-
"browser": "./lib/esm/
|
|
15
|
+
"browser": "./lib/esm/common/index.js",
|
|
16
16
|
"import": "./lib/esm/index.js",
|
|
17
17
|
"default": "./lib/esm/index.js"
|
|
18
18
|
}
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"uuid": "^10.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsed/barrels": "8.
|
|
33
|
-
"@tsed/core": "8.
|
|
34
|
-
"@tsed/hooks": "8.
|
|
35
|
-
"@tsed/logger": "^
|
|
36
|
-
"@tsed/typescript": "8.
|
|
32
|
+
"@tsed/barrels": "8.15.1",
|
|
33
|
+
"@tsed/core": "8.15.1",
|
|
34
|
+
"@tsed/hooks": "8.15.1",
|
|
35
|
+
"@tsed/logger": "^7.0.1",
|
|
36
|
+
"@tsed/typescript": "8.15.1",
|
|
37
37
|
"cross-env": "7.0.3",
|
|
38
38
|
"eslint": "9.12.0",
|
|
39
39
|
"typescript": "5.4.5",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@tsed/core": ">=8.0.0",
|
|
45
45
|
"@tsed/hooks": ">=8.0.0",
|
|
46
|
-
"@tsed/logger": ">=
|
|
46
|
+
"@tsed/logger": ">=7.0.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"@tsed/core": {
|
|
@@ -62,8 +62,5 @@
|
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/di",
|
|
64
64
|
"author": "Romain Lenzotti",
|
|
65
|
-
"license": "MIT"
|
|
66
|
-
"publishConfig": {
|
|
67
|
-
"tag": "rc"
|
|
68
|
-
}
|
|
65
|
+
"license": "MIT"
|
|
69
66
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { catchError } from "@tsed/core/utils/catchError.js";
|
|
2
|
-
import { context } from "../fn/context.js";
|
|
3
|
-
/**
|
|
4
|
-
* Inject a context like PlatformContext or any BaseContext.
|
|
5
|
-
*
|
|
6
|
-
* ```typescript
|
|
7
|
-
* @Injectable()
|
|
8
|
-
* export class MyService {
|
|
9
|
-
* @InjectContext()
|
|
10
|
-
* ctx?: Context;
|
|
11
|
-
* }
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @returns {Function}
|
|
15
|
-
* @decorator
|
|
16
|
-
*/
|
|
17
|
-
export function InjectContext(transform = (o) => o) {
|
|
18
|
-
return (target, propertyKey) => {
|
|
19
|
-
catchError(() => Reflect.deleteProperty(target, propertyKey));
|
|
20
|
-
Reflect.defineProperty(target, propertyKey, {
|
|
21
|
-
get() {
|
|
22
|
-
return transform(context());
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { v4 } from "uuid";
|
|
2
|
-
import { DIContext } from "../../common/domain/DIContext.js";
|
|
3
|
-
import { injector } from "../../common/index.js";
|
|
4
|
-
import { getContext } from "../utils/asyncHookContext.js";
|
|
5
|
-
/**
|
|
6
|
-
* Get the current DIContext instance using async hook node.js api.
|
|
7
|
-
*
|
|
8
|
-
* ::: warning
|
|
9
|
-
* This function isn't available in the browser context.
|
|
10
|
-
* :::
|
|
11
|
-
*/
|
|
12
|
-
export function context() {
|
|
13
|
-
return (getContext() ||
|
|
14
|
-
new DIContext({
|
|
15
|
-
id: v4(),
|
|
16
|
-
logger: injector().logger,
|
|
17
|
-
injector: injector(),
|
|
18
|
-
maxStackSize: 0
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { context } from "./context.js";
|
|
2
|
-
/**
|
|
3
|
-
* Get the current logger instance. If the logger() function is invoked in Request context, it will return the logger instance attached to the request context.
|
|
4
|
-
* Otherwise, it will return the logger instance attached to the DI context.
|
|
5
|
-
*/
|
|
6
|
-
export function contextLogger() {
|
|
7
|
-
return context().logger;
|
|
8
|
-
}
|
package/lib/esm/browser/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
class AsyncContextStorage {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.stack = [];
|
|
4
|
-
}
|
|
5
|
-
run(store, cb) {
|
|
6
|
-
this.stack.push(store);
|
|
7
|
-
this.store = store;
|
|
8
|
-
try {
|
|
9
|
-
return cb();
|
|
10
|
-
}
|
|
11
|
-
finally {
|
|
12
|
-
this.stack.pop();
|
|
13
|
-
this.store = this.stack[this.stack.length - 1];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
getStore() {
|
|
17
|
-
return this.store;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const storage = new AsyncContextStorage();
|
|
21
|
-
export function getAsyncStore() {
|
|
22
|
-
return storage;
|
|
23
|
-
}
|
|
24
|
-
export function useContextRef() {
|
|
25
|
-
return getAsyncStore().getStore();
|
|
26
|
-
}
|
|
27
|
-
export function getContext(initialValue) {
|
|
28
|
-
return initialValue || useContextRef()?.current;
|
|
29
|
-
}
|
|
30
|
-
export async function runInContext(ctx, cb, injector) {
|
|
31
|
-
const ref = useContextRef();
|
|
32
|
-
if (ref) {
|
|
33
|
-
ctx && setContext(ctx);
|
|
34
|
-
return cb();
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
injector = ctx?.injector || injector;
|
|
38
|
-
cb = (injector && (await injector.alterAsync?.("$alterRunInContext", cb))) || cb;
|
|
39
|
-
return await Promise.resolve(storage.run({ current: ctx }, cb));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export function setContext(ctx) {
|
|
43
|
-
const ref = useContextRef();
|
|
44
|
-
if (ref && !ref.current) {
|
|
45
|
-
ref.current = ctx;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @deprecated
|
|
50
|
-
*/
|
|
51
|
-
export function bindContext(cb) {
|
|
52
|
-
return cb;
|
|
53
|
-
}
|
|
54
|
-
if (typeof window !== "undefined") {
|
|
55
|
-
// Patch Promise.then pour propager le contexte
|
|
56
|
-
const origThen = Promise.prototype.then;
|
|
57
|
-
Promise.prototype.then = function (onFulfilled, onRejected) {
|
|
58
|
-
const ctx = useContextRef();
|
|
59
|
-
return origThen.call(this, onFulfilled && ((v) => storage.run({ current: ctx?.current }, () => onFulfilled(v))), onRejected && ((e) => storage.run({ current: ctx?.current }, () => onRejected(e))));
|
|
60
|
-
};
|
|
61
|
-
// Patch setTimeout pour propager le contexte
|
|
62
|
-
const origSetTimeout = window.setTimeout;
|
|
63
|
-
window.setTimeout = function (fn, ...args) {
|
|
64
|
-
const ctx = useContextRef();
|
|
65
|
-
return origSetTimeout(() => storage.run({ current: ctx?.current }, fn), ...args);
|
|
66
|
-
};
|
|
67
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { DIContext } from "../../common/domain/DIContext.js";
|
|
2
|
-
/**
|
|
3
|
-
* Inject a context like PlatformContext or any BaseContext.
|
|
4
|
-
*
|
|
5
|
-
* ```typescript
|
|
6
|
-
* @Injectable()
|
|
7
|
-
* export class MyService {
|
|
8
|
-
* @InjectContext()
|
|
9
|
-
* ctx?: Context;
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* @returns {Function}
|
|
14
|
-
* @decorator
|
|
15
|
-
*/
|
|
16
|
-
export declare function InjectContext(transform?: ($ctx: DIContext) => unknown): PropertyDecorator;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DIContext } from "../../common/domain/DIContext.js";
|
|
2
|
-
/**
|
|
3
|
-
* Get the current DIContext instance using async hook node.js api.
|
|
4
|
-
*
|
|
5
|
-
* ::: warning
|
|
6
|
-
* This function isn't available in the browser context.
|
|
7
|
-
* :::
|
|
8
|
-
*/
|
|
9
|
-
export declare function context<Ctx = DIContext>(): Ctx;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the current logger instance. If the logger() function is invoked in Request context, it will return the logger instance attached to the request context.
|
|
3
|
-
* Otherwise, it will return the logger instance attached to the DI context.
|
|
4
|
-
*/
|
|
5
|
-
export declare function contextLogger(): import("../index.js").ContextLogger;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DIContext } from "../../common/index.js";
|
|
2
|
-
interface AsyncStore {
|
|
3
|
-
current: DIContext | undefined;
|
|
4
|
-
}
|
|
5
|
-
declare class AsyncContextStorage {
|
|
6
|
-
private store?;
|
|
7
|
-
private stack;
|
|
8
|
-
run(store: AsyncStore, cb: (...args: any[]) => any): any;
|
|
9
|
-
getStore(): AsyncStore | undefined;
|
|
10
|
-
}
|
|
11
|
-
export declare function getAsyncStore(): AsyncContextStorage;
|
|
12
|
-
export declare function useContextRef(): AsyncStore | undefined;
|
|
13
|
-
export declare function getContext<Context = DIContext>(initialValue?: DIContext): Context | undefined;
|
|
14
|
-
export declare function runInContext<Result = unknown>(ctx: DIContext | undefined, cb: (...args: unknown[]) => Result, injector?: {
|
|
15
|
-
alterAsync?: (name: string, cb: any) => Promise<any>;
|
|
16
|
-
}): Promise<Result>;
|
|
17
|
-
export declare function setContext(ctx: DIContext): void;
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated
|
|
20
|
-
*/
|
|
21
|
-
export declare function bindContext(cb: any): any;
|
|
22
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|