@tsed/di 7.0.0-beta.17 → 7.0.0-beta.18

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.
Files changed (66) hide show
  1. package/coverage.json +4 -4
  2. package/lib/cjs/decorators/inject.js +2 -2
  3. package/lib/cjs/decorators/inject.js.map +1 -1
  4. package/lib/cjs/domain/ContextLogger.js +9 -22
  5. package/lib/cjs/domain/ContextLogger.js.map +1 -1
  6. package/lib/cjs/domain/DIContext.js +28 -19
  7. package/lib/cjs/domain/DIContext.js.map +1 -1
  8. package/lib/cjs/domain/LocalsContainer.js +3 -46
  9. package/lib/cjs/domain/LocalsContainer.js.map +1 -1
  10. package/lib/cjs/domain/Provider.js +9 -0
  11. package/lib/cjs/domain/Provider.js.map +1 -1
  12. package/lib/cjs/index.js +1 -1
  13. package/lib/cjs/index.js.map +1 -1
  14. package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -1
  15. package/lib/cjs/interfaces/InjectableProperties.js.map +1 -1
  16. package/lib/cjs/registries/GlobalProviders.js +1 -0
  17. package/lib/cjs/registries/GlobalProviders.js.map +1 -1
  18. package/lib/cjs/registries/ProviderRegistry.js +1 -1
  19. package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
  20. package/lib/cjs/services/DITest.js +1 -1
  21. package/lib/cjs/services/DITest.js.map +1 -1
  22. package/lib/cjs/services/InjectorService.js +24 -22
  23. package/lib/cjs/services/InjectorService.js.map +1 -1
  24. package/lib/cjs/utils/asyncHookContext.js +42 -0
  25. package/lib/cjs/utils/asyncHookContext.js.map +1 -0
  26. package/lib/esm/decorators/inject.js +1 -1
  27. package/lib/esm/decorators/inject.js.map +1 -1
  28. package/lib/esm/domain/ContextLogger.js +9 -22
  29. package/lib/esm/domain/ContextLogger.js.map +1 -1
  30. package/lib/esm/domain/DIContext.js +27 -18
  31. package/lib/esm/domain/DIContext.js.map +1 -1
  32. package/lib/esm/domain/LocalsContainer.js +3 -46
  33. package/lib/esm/domain/LocalsContainer.js.map +1 -1
  34. package/lib/esm/domain/Provider.js +10 -1
  35. package/lib/esm/domain/Provider.js.map +1 -1
  36. package/lib/esm/index.js +1 -1
  37. package/lib/esm/index.js.map +1 -1
  38. package/lib/esm/interfaces/AlterRunInContext.js.map +1 -1
  39. package/lib/esm/interfaces/InjectableProperties.js.map +1 -1
  40. package/lib/esm/registries/GlobalProviders.js +1 -0
  41. package/lib/esm/registries/GlobalProviders.js.map +1 -1
  42. package/lib/esm/registries/ProviderRegistry.js +1 -1
  43. package/lib/esm/registries/ProviderRegistry.js.map +1 -1
  44. package/lib/esm/services/DITest.js +1 -1
  45. package/lib/esm/services/DITest.js.map +1 -1
  46. package/lib/esm/services/InjectorService.js +25 -23
  47. package/lib/esm/services/InjectorService.js.map +1 -1
  48. package/lib/esm/utils/asyncHookContext.js +33 -0
  49. package/lib/esm/utils/asyncHookContext.js.map +1 -0
  50. package/lib/types/domain/ContextLogger.d.ts +4 -6
  51. package/lib/types/domain/DIContext.d.ts +12 -18
  52. package/lib/types/domain/LocalsContainer.d.ts +3 -22
  53. package/lib/types/domain/Provider.d.ts +2 -1
  54. package/lib/types/index.d.ts +1 -1
  55. package/lib/types/interfaces/AlterRunInContext.d.ts +1 -2
  56. package/lib/types/interfaces/InjectableProperties.d.ts +2 -1
  57. package/lib/types/registries/GlobalProviders.d.ts +6 -5
  58. package/lib/types/registries/ProviderRegistry.d.ts +2 -1
  59. package/lib/types/services/InjectorService.d.ts +6 -5
  60. package/lib/types/utils/asyncHookContext.d.ts +14 -0
  61. package/package.json +5 -5
  62. package/lib/cjs/utils/runInContext.js +0 -32
  63. package/lib/cjs/utils/runInContext.js.map +0 -1
  64. package/lib/esm/utils/runInContext.js +0 -25
  65. package/lib/esm/utils/runInContext.js.map +0 -1
  66. package/lib/types/utils/runInContext.d.ts +0 -7
@@ -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,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
- constructor($ctx: DIContext);
17
- get id(): string;
18
- set maxStackSize(maxStackSize: number);
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,30 +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 extends Map<any, any> implements ContextMethods {
9
+ export declare class DIContext {
19
10
  #private;
20
- readonly options: DIContextOptions;
21
- [x: string]: any;
22
11
  opts: DIContextOptions;
12
+ [x: string]: any;
13
+ constructor(opts: DIContextOptions);
23
14
  /**
24
15
  * Logger attached to the context request.
25
16
  */
26
- readonly logger: ContextLogger;
27
- constructor(options: DIContextOptions);
17
+ get logger(): ContextLogger;
28
18
  /**
29
19
  * Request id generated by @@contextMiddleware@@.
30
20
  *
@@ -54,13 +44,17 @@ export declare class DIContext extends Map<any, any> implements ContextMethods {
54
44
  get injector(): InjectorService;
55
45
  get env(): any;
56
46
  /**
57
- * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
47
+ * The request container used by the Ts.ED DI. It contains all services annotated with `@Scope(ProviderScope.REQUEST)`
58
48
  */
59
- get container(): LocalsContainer<any>;
60
- destroy(): Promise<void>;
49
+ get container(): LocalsContainer;
50
+ destroy(): Promise<any>;
61
51
  emit(eventName: string, ...args: any[]): Promise<void>;
62
- runInContext(next: Function): Promise<unknown>;
52
+ runInContext(next: Function): Promise<any>;
63
53
  cache<Value = any>(key: string, cb: () => Value): Value;
64
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;
65
59
  }
66
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<V = any> extends Map<TokenProvider, V> {
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, (instance: T, ...args: any[]) => Promise<void> | void>;
14
+ hooks?: Record<string, ProviderHookCallback<T>>;
14
15
  private _useClass;
15
16
  private _provide;
16
17
  private _store;
@@ -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, ctx: DIContext): () => unknown | Promise<() => 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: Map<TokenProvider, any>, options: Partial<InvokeOptions> & {
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 type { InjectorService } from "../services/InjectorService";
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 { RegistrySettings } from "../interfaces/RegistrySettings";
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>): void;
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: Map<TokenProvider, any>, options: ResolvedInvokeOptions & {
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>>): void;
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?: Map<TokenProvider, any>, options?: Partial<InvokeOptions<T>>): T;
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: Map<TokenProvider, any>, options: Partial<InvokeOptions>): void;
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: Map<TokenProvider, any>, invokeOptions: Partial<InvokeOptions>): void;
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 services.
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.17",
3
+ "version": "7.0.0-beta.18",
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.17",
27
+ "@tsed/core": "7.0.0-beta.18",
28
28
  "@tsed/logger": ">=6.2.0",
29
- "@tsed/schema": "7.0.0-beta.17"
29
+ "@tsed/schema": "7.0.0-beta.18"
30
30
  },
31
31
  "peerDependencies": {
32
- "@tsed/core": "^7.0.0-beta.17",
32
+ "@tsed/core": "^7.0.0-beta.18",
33
33
  "@tsed/logger": ">=6.2.0",
34
- "@tsed/schema": "^7.0.0-beta.17"
34
+ "@tsed/schema": "^7.0.0-beta.18"
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;