@tsed/di 7.0.0-beta.16 → 7.0.0-beta.19
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 +1 -6
- package/lib/cjs/decorators/inject.js +2 -2
- package/lib/cjs/decorators/inject.js.map +1 -1
- package/lib/cjs/domain/ContextLogger.js +9 -22
- package/lib/cjs/domain/ContextLogger.js.map +1 -1
- package/lib/cjs/domain/DIContext.js +45 -21
- 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 +9 -0
- package/lib/cjs/domain/Provider.js.map +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -1
- package/lib/cjs/interfaces/InjectableProperties.js.map +1 -1
- package/lib/cjs/registries/GlobalProviders.js +1 -0
- 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/DITest.js +1 -1
- package/lib/cjs/services/DITest.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +24 -13
- 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/esm/decorators/inject.js +1 -1
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/domain/ContextLogger.js +9 -22
- package/lib/esm/domain/ContextLogger.js.map +1 -1
- package/lib/esm/domain/DIContext.js +44 -20
- 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 +10 -1
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/AlterRunInContext.js.map +1 -1
- package/lib/esm/interfaces/InjectableProperties.js.map +1 -1
- package/lib/esm/registries/GlobalProviders.js +1 -0
- 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/DITest.js +1 -1
- package/lib/esm/services/DITest.js.map +1 -1
- package/lib/esm/services/InjectorService.js +25 -14
- 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/types/domain/ContextLogger.d.ts +4 -6
- package/lib/types/domain/DIContext.d.ts +17 -20
- package/lib/types/domain/LocalsContainer.d.ts +3 -22
- package/lib/types/domain/Provider.d.ts +2 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/interfaces/AlterRunInContext.d.ts +1 -2
- package/lib/types/interfaces/InjectableProperties.d.ts +2 -1
- package/lib/types/registries/GlobalProviders.d.ts +6 -5
- package/lib/types/registries/ProviderRegistry.d.ts +2 -1
- package/lib/types/services/InjectorService.d.ts +6 -5
- package/lib/types/utils/asyncHookContext.d.ts +14 -0
- package/package.json +5 -5
- package/lib/cjs/utils/runInContext.js +0 -32
- package/lib/cjs/utils/runInContext.js.map +0 -1
- package/lib/esm/utils/runInContext.js +0 -25
- package/lib/esm/utils/runInContext.js.map +0 -1
- package/lib/types/utils/runInContext.d.ts +0 -7
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Hooks } from "@tsed/core";
|
|
2
2
|
import { LogLevel } from "@tsed/logger";
|
|
3
3
|
import { DILogger } from "../interfaces/DILogger";
|
|
4
|
-
import type { DIContext } from "./DIContext";
|
|
5
4
|
export interface ContextLoggerOptions extends Record<string, any> {
|
|
6
5
|
id: string;
|
|
7
6
|
logger?: DILogger;
|
|
@@ -11,11 +10,11 @@ export interface ContextLoggerOptions extends Record<string, any> {
|
|
|
11
10
|
}
|
|
12
11
|
export declare class ContextLogger {
|
|
13
12
|
#private;
|
|
14
|
-
protected readonly $ctx: DIContext;
|
|
15
13
|
readonly dateStart: Date;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
readonly id: string;
|
|
15
|
+
maxStackSize: number;
|
|
16
|
+
level: LogLevel;
|
|
17
|
+
constructor({ id, logger, dateStart, level, maxStackSize, additionalProps }: ContextLoggerOptions);
|
|
19
18
|
get hooks(): Hooks;
|
|
20
19
|
private get stack();
|
|
21
20
|
alterLog(cb: (data: any, level: "debug" | "info" | "warn" | "error" | "off" | "all", withRequest: boolean) => any): Hooks;
|
|
@@ -27,7 +26,6 @@ export declare class ContextLogger {
|
|
|
27
26
|
trace(obj: any): this;
|
|
28
27
|
flush(): void;
|
|
29
28
|
isLevelEnabled(otherLevel: string | LogLevel): boolean;
|
|
30
|
-
destroy(): void;
|
|
31
29
|
/**
|
|
32
30
|
* Return the duration between the time when LogIncomingRequest has handle the request and now.
|
|
33
31
|
* @returns {number}
|
|
@@ -1,33 +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
4
|
export interface DIContextOptions extends Omit<ContextLoggerOptions, "dateStart"> {
|
|
14
5
|
id: string;
|
|
15
6
|
injector: InjectorService;
|
|
16
7
|
logger: any;
|
|
17
8
|
}
|
|
18
|
-
export declare class DIContext
|
|
19
|
-
|
|
20
|
-
[x: string]: any;
|
|
9
|
+
export declare class DIContext {
|
|
10
|
+
#private;
|
|
21
11
|
opts: DIContextOptions;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
container: LocalsContainer<any>;
|
|
12
|
+
[x: string]: any;
|
|
13
|
+
constructor(opts: DIContextOptions);
|
|
26
14
|
/**
|
|
27
15
|
* Logger attached to the context request.
|
|
28
16
|
*/
|
|
29
|
-
|
|
30
|
-
constructor(options: DIContextOptions);
|
|
17
|
+
get logger(): ContextLogger;
|
|
31
18
|
/**
|
|
32
19
|
* Request id generated by @@contextMiddleware@@.
|
|
33
20
|
*
|
|
@@ -56,8 +43,18 @@ export declare class DIContext extends Map<any, any> implements ContextMethods {
|
|
|
56
43
|
get dateStart(): Date;
|
|
57
44
|
get injector(): InjectorService;
|
|
58
45
|
get env(): any;
|
|
59
|
-
|
|
46
|
+
/**
|
|
47
|
+
* The request container used by the Ts.ED DI. It contains all services annotated with `@Scope(ProviderScope.REQUEST)`
|
|
48
|
+
*/
|
|
49
|
+
get container(): LocalsContainer;
|
|
50
|
+
destroy(): Promise<any>;
|
|
60
51
|
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
61
|
-
runInContext(next: Function): Promise<
|
|
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;
|
|
62
59
|
}
|
|
63
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
|
}
|
|
@@ -3,6 +3,7 @@ import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
|
3
3
|
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
4
4
|
import { ProviderScope } from "./ProviderScope";
|
|
5
5
|
import { ProviderType } from "./ProviderType";
|
|
6
|
+
export declare type ProviderHookCallback<T = any> = (instance: T, ...args: any[]) => Promise<void> | void;
|
|
6
7
|
export declare class Provider<T = any> implements ProviderOpts<T> {
|
|
7
8
|
type: ProviderType | any;
|
|
8
9
|
deps: TokenProvider[];
|
|
@@ -10,7 +11,7 @@ export declare class Provider<T = any> implements ProviderOpts<T> {
|
|
|
10
11
|
useFactory: Function;
|
|
11
12
|
useAsyncFactory: Function;
|
|
12
13
|
useValue: any;
|
|
13
|
-
hooks?: Record<string,
|
|
14
|
+
hooks?: Record<string, ProviderHookCallback<T>>;
|
|
14
15
|
private _useClass;
|
|
15
16
|
private _provide;
|
|
16
17
|
private _store;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -50,11 +50,11 @@ export * from "./services/DIConfiguration";
|
|
|
50
50
|
export * from "./services/DILogger";
|
|
51
51
|
export * from "./services/DITest";
|
|
52
52
|
export * from "./services/InjectorService";
|
|
53
|
+
export * from "./utils/asyncHookContext";
|
|
53
54
|
export * from "./utils/colors";
|
|
54
55
|
export * from "./utils/createContainer";
|
|
55
56
|
export * from "./utils/getConfiguration";
|
|
56
57
|
export * from "./utils/resolveControllers";
|
|
57
|
-
export * from "./utils/runInContext";
|
|
58
58
|
export * from "./utils/setLoggerConfiguration";
|
|
59
59
|
export * from "./utils/setLoggerFormat";
|
|
60
60
|
export * from "./utils/setLoggerLevel";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DIContext } from "../domain/DIContext";
|
|
2
1
|
export interface AlterRunInContext {
|
|
3
|
-
$alterRunInContext(next: (...args: unknown[]) => unknown
|
|
2
|
+
$alterRunInContext(next: (...args: unknown[]) => unknown): () => unknown | Promise<() => unknown>;
|
|
4
3
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { InjectablePropertyType } from "../domain/InjectablePropertyType";
|
|
2
|
+
import type { LocalsContainer } from "../domain/LocalsContainer";
|
|
2
3
|
import type { TokenProvider } from "./TokenProvider";
|
|
3
4
|
import type { InjectorService } from "../services/InjectorService";
|
|
4
5
|
import type { InvokeOptions } from "./InvokeOptions";
|
|
@@ -9,7 +10,7 @@ export interface InjectablePropertyOptions extends InjectableProperty {
|
|
|
9
10
|
bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;
|
|
10
11
|
propertyType: string;
|
|
11
12
|
useType?: TokenProvider;
|
|
12
|
-
resolver: (injector: InjectorService, locals:
|
|
13
|
+
resolver: (injector: InjectorService, locals: LocalsContainer, options: Partial<InvokeOptions> & {
|
|
13
14
|
options: any;
|
|
14
15
|
}) => () => any;
|
|
15
16
|
options?: any;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
+
import type { LocalsContainer } from "../domain/LocalsContainer";
|
|
2
3
|
import { Provider } from "../domain/Provider";
|
|
3
|
-
import
|
|
4
|
+
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
5
|
+
import { RegistrySettings } from "../interfaces/RegistrySettings";
|
|
4
6
|
import { ResolvedInvokeOptions } from "../interfaces/ResolvedInvokeOptions";
|
|
5
7
|
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
6
|
-
import {
|
|
7
|
-
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
8
|
+
import type { InjectorService } from "../services/InjectorService";
|
|
8
9
|
export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider> {
|
|
9
10
|
#private;
|
|
10
11
|
/**
|
|
@@ -30,7 +31,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
30
31
|
* @param target
|
|
31
32
|
* @param options
|
|
32
33
|
*/
|
|
33
|
-
merge(target: TokenProvider, options: Partial<ProviderOpts>):
|
|
34
|
+
merge(target: TokenProvider, options: Partial<ProviderOpts>): Provider<any>;
|
|
34
35
|
/**
|
|
35
36
|
* The delete() method removes the specified element from a Map object.
|
|
36
37
|
* @param key Required. The key of the element to remove from the Map object.
|
|
@@ -38,7 +39,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
38
39
|
*/
|
|
39
40
|
delete(key: TokenProvider): boolean;
|
|
40
41
|
createRegistry(type: string, model: Type<Provider>, options?: Partial<RegistrySettings>): this;
|
|
41
|
-
onInvoke(provider: Provider, locals:
|
|
42
|
+
onInvoke(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {
|
|
42
43
|
injector: InjectorService;
|
|
43
44
|
}): void;
|
|
44
45
|
getRegistrySettings(target: string | TokenProvider): RegistrySettings;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Provider } from "../domain/Provider";
|
|
1
2
|
import type { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
2
3
|
/**
|
|
3
4
|
* Register a provider configuration.
|
|
4
5
|
* @param {ProviderOpts<any>} provider
|
|
5
6
|
*/
|
|
6
|
-
export declare function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>):
|
|
7
|
+
export declare function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>): Provider<any>;
|
|
7
8
|
/**
|
|
8
9
|
* Add a new value in the `ProviderRegistry`.
|
|
9
10
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Container } from "../domain/Container";
|
|
2
|
+
import { LocalsContainer } from "../domain/LocalsContainer";
|
|
2
3
|
import { Provider } from "../domain/Provider";
|
|
3
4
|
import { ProviderScope } from "../domain/ProviderScope";
|
|
4
5
|
import { DILogger } from "../interfaces/DILogger";
|
|
@@ -97,7 +98,7 @@ export declare class InjectorService extends Container {
|
|
|
97
98
|
* @param options
|
|
98
99
|
* @returns {T} The class constructed.
|
|
99
100
|
*/
|
|
100
|
-
invoke<T = any>(token: TokenProvider, locals?:
|
|
101
|
+
invoke<T = any>(token: TokenProvider, locals?: LocalsContainer, options?: Partial<InvokeOptions<T>>): T;
|
|
101
102
|
/**
|
|
102
103
|
* Build only providers which are asynchronous.
|
|
103
104
|
*/
|
|
@@ -130,9 +131,8 @@ export declare class InjectorService extends Container {
|
|
|
130
131
|
* @param locals
|
|
131
132
|
* @param options
|
|
132
133
|
*/
|
|
133
|
-
bindInjectableProperties(instance: any, locals:
|
|
134
|
+
bindInjectableProperties(instance: any, locals: LocalsContainer, options: Partial<InvokeOptions>): void;
|
|
134
135
|
/**
|
|
135
|
-
*
|
|
136
136
|
* @param instance
|
|
137
137
|
* @param {string} propertyKey
|
|
138
138
|
*/
|
|
@@ -148,7 +148,7 @@ export declare class InjectorService extends Container {
|
|
|
148
148
|
* @param locals
|
|
149
149
|
* @param invokeOptions
|
|
150
150
|
*/
|
|
151
|
-
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals:
|
|
151
|
+
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: LocalsContainer, invokeOptions: Partial<InvokeOptions>): void;
|
|
152
152
|
/**
|
|
153
153
|
*
|
|
154
154
|
* @param instance
|
|
@@ -175,7 +175,7 @@ export declare class InjectorService extends Container {
|
|
|
175
175
|
/**
|
|
176
176
|
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
177
177
|
* @param eventName The event name to emit at all services.
|
|
178
|
-
* @param args List of the parameters to give to each
|
|
178
|
+
* @param args List of the parameters to give to each service.
|
|
179
179
|
* @returns {Promise<any[]>} A list of promises.
|
|
180
180
|
*/
|
|
181
181
|
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
@@ -219,4 +219,5 @@ export declare class InjectorService extends Container {
|
|
|
219
219
|
* @param options
|
|
220
220
|
*/
|
|
221
221
|
private mapInvokeOptions;
|
|
222
|
+
private registerHooks;
|
|
222
223
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
import type { DIContext } from "../domain/DIContext";
|
|
4
|
+
import type { InjectorService } from "../services/InjectorService";
|
|
5
|
+
export declare function getAsyncStore(): AsyncLocalStorage<{
|
|
6
|
+
current: DIContext | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function useContextRef(): {
|
|
9
|
+
current: DIContext | undefined;
|
|
10
|
+
} | undefined;
|
|
11
|
+
export declare function getContext<Context = DIContext>(): Context | undefined;
|
|
12
|
+
export declare function runInContext(ctx: DIContext | undefined, cb: any, injector?: InjectorService): Promise<any>;
|
|
13
|
+
export declare function setContext(ctx: DIContext): void;
|
|
14
|
+
export declare function bindContext(cb: any): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/di",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.19",
|
|
4
4
|
"description": "DI module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"tslib": "2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/core": "7.0.0-beta.
|
|
27
|
+
"@tsed/core": "7.0.0-beta.19",
|
|
28
28
|
"@tsed/logger": ">=6.2.0",
|
|
29
|
-
"@tsed/schema": "7.0.0-beta.
|
|
29
|
+
"@tsed/schema": "7.0.0-beta.19"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tsed/core": "^7.0.0-beta.
|
|
32
|
+
"@tsed/core": "^7.0.0-beta.19",
|
|
33
33
|
"@tsed/logger": ">=6.2.0",
|
|
34
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
34
|
+
"@tsed/schema": "^7.0.0-beta.19"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@tsed/core": {
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bindContext = exports.runInContext = exports.getContext = exports.getAsyncStore = void 0;
|
|
4
|
-
const async_hooks_1 = require("async_hooks");
|
|
5
|
-
const storage = new async_hooks_1.AsyncLocalStorage();
|
|
6
|
-
function getAsyncStore() {
|
|
7
|
-
return storage;
|
|
8
|
-
}
|
|
9
|
-
exports.getAsyncStore = getAsyncStore;
|
|
10
|
-
function getContext() {
|
|
11
|
-
return getAsyncStore().getStore();
|
|
12
|
-
}
|
|
13
|
-
exports.getContext = getContext;
|
|
14
|
-
function runInContext(ctx, cb) {
|
|
15
|
-
return storage.run(ctx, cb);
|
|
16
|
-
}
|
|
17
|
-
exports.runInContext = runInContext;
|
|
18
|
-
function bindContext(cb) {
|
|
19
|
-
if (getContext()) {
|
|
20
|
-
let localArgs;
|
|
21
|
-
const newCB = async_hooks_1.AsyncResource.bind(() => cb(...localArgs));
|
|
22
|
-
// FIXME: remove this hack when the support of v14 will be removed
|
|
23
|
-
// see issue: https://github.com/nodejs/node/issues/36051
|
|
24
|
-
return (...args) => {
|
|
25
|
-
localArgs = args;
|
|
26
|
-
return newCB(...args);
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return cb;
|
|
30
|
-
}
|
|
31
|
-
exports.bindContext = bindContext;
|
|
32
|
-
//# sourceMappingURL=runInContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runInContext.js","sourceRoot":"","sources":["../../../src/utils/runInContext.ts"],"names":[],"mappings":";;;AAAA,6CAA6D;AAG7D,MAAM,OAAO,GAAiC,IAAI,+BAAiB,EAAE,CAAC;AAEtE,SAAgB,aAAa;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC;AAFD,sCAEC;AAED,SAAgB,UAAU;IACxB,OAAO,aAAa,EAAE,CAAC,QAAQ,EAAS,CAAC;AAC3C,CAAC;AAFD,gCAEC;AAED,SAAgB,YAAY,CAAC,GAAc,EAAE,EAAO;IAClD,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;AAFD,oCAEC;AAED,SAAgB,WAAW,CAAC,EAAO;IACjC,IAAI,UAAU,EAAE,EAAE;QAChB,IAAI,SAAc,CAAC;QACnB,MAAM,KAAK,GAAQ,2BAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;QAE9D,kEAAkE;QAClE,yDAAyD;QACzD,OAAO,CAAC,GAAG,IAAS,EAAE,EAAE;YACtB,SAAS,GAAG,IAAI,CAAC;YACjB,OAAO,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC;KACH;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAdD,kCAcC","sourcesContent":["import {AsyncLocalStorage, AsyncResource} from \"async_hooks\";\nimport {DIContext} from \"../domain/DIContext\";\n\nconst storage: AsyncLocalStorage<DIContext> = new AsyncLocalStorage();\n\nexport function getAsyncStore() {\n return storage;\n}\n\nexport function getContext<Context = DIContext>(): Context | undefined {\n return getAsyncStore().getStore() as any;\n}\n\nexport function runInContext(ctx: DIContext, cb: any) {\n return storage.run(ctx, cb);\n}\n\nexport function bindContext(cb: any) {\n if (getContext()) {\n let localArgs: any;\n const newCB: any = AsyncResource.bind(() => cb(...localArgs));\n\n // FIXME: remove this hack when the support of v14 will be removed\n // see issue: https://github.com/nodejs/node/issues/36051\n return (...args: any) => {\n localArgs = args;\n return newCB(...args);\n };\n }\n\n return cb;\n}\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage, AsyncResource } from "async_hooks";
|
|
2
|
-
const storage = new AsyncLocalStorage();
|
|
3
|
-
export function getAsyncStore() {
|
|
4
|
-
return storage;
|
|
5
|
-
}
|
|
6
|
-
export function getContext() {
|
|
7
|
-
return getAsyncStore().getStore();
|
|
8
|
-
}
|
|
9
|
-
export function runInContext(ctx, cb) {
|
|
10
|
-
return storage.run(ctx, cb);
|
|
11
|
-
}
|
|
12
|
-
export function bindContext(cb) {
|
|
13
|
-
if (getContext()) {
|
|
14
|
-
let localArgs;
|
|
15
|
-
const newCB = AsyncResource.bind(() => cb(...localArgs));
|
|
16
|
-
// FIXME: remove this hack when the support of v14 will be removed
|
|
17
|
-
// see issue: https://github.com/nodejs/node/issues/36051
|
|
18
|
-
return (...args) => {
|
|
19
|
-
localArgs = args;
|
|
20
|
-
return newCB(...args);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return cb;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=runInContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runInContext.js","sourceRoot":"","sources":["../../../src/utils/runInContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAG7D,MAAM,OAAO,GAAiC,IAAI,iBAAiB,EAAE,CAAC;AAEtE,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,aAAa,EAAE,CAAC,QAAQ,EAAS,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAc,EAAE,EAAO;IAClD,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAAO;IACjC,IAAI,UAAU,EAAE,EAAE;QAChB,IAAI,SAAc,CAAC;QACnB,MAAM,KAAK,GAAQ,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;QAE9D,kEAAkE;QAClE,yDAAyD;QACzD,OAAO,CAAC,GAAG,IAAS,EAAE,EAAE;YACtB,SAAS,GAAG,IAAI,CAAC;YACjB,OAAO,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC;KACH;IAED,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import {AsyncLocalStorage, AsyncResource} from \"async_hooks\";\nimport {DIContext} from \"../domain/DIContext\";\n\nconst storage: AsyncLocalStorage<DIContext> = new AsyncLocalStorage();\n\nexport function getAsyncStore() {\n return storage;\n}\n\nexport function getContext<Context = DIContext>(): Context | undefined {\n return getAsyncStore().getStore() as any;\n}\n\nexport function runInContext(ctx: DIContext, cb: any) {\n return storage.run(ctx, cb);\n}\n\nexport function bindContext(cb: any) {\n if (getContext()) {\n let localArgs: any;\n const newCB: any = AsyncResource.bind(() => cb(...localArgs));\n\n // FIXME: remove this hack when the support of v14 will be removed\n // see issue: https://github.com/nodejs/node/issues/36051\n return (...args: any) => {\n localArgs = args;\n return newCB(...args);\n };\n }\n\n return cb;\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
-
import { DIContext } from "../domain/DIContext";
|
|
4
|
-
export declare function getAsyncStore(): AsyncLocalStorage<DIContext>;
|
|
5
|
-
export declare function getContext<Context = DIContext>(): Context | undefined;
|
|
6
|
-
export declare function runInContext(ctx: DIContext, cb: any): unknown;
|
|
7
|
-
export declare function bindContext(cb: any): any;
|