awilixify 3.3.0 → 3.4.0

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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.js +1 -0
  4. package/dist/lib/decorators/decorator-state.types.d.ts +1 -1
  5. package/dist/lib/di/common.types.d.ts +0 -1
  6. package/dist/lib/di/contexts/container-context-base.d.ts +4 -0
  7. package/dist/lib/di/contexts/container-context-base.js +30 -18
  8. package/dist/lib/di/contexts/di-context-async.js +4 -31
  9. package/dist/lib/di/contexts/di-context-base.js +5 -5
  10. package/dist/lib/di/contexts/di-context.d.ts +5 -0
  11. package/dist/lib/di/contexts/di-context.js +54 -0
  12. package/dist/lib/di/errors.d.ts +18 -0
  13. package/dist/lib/di/errors.js +36 -0
  14. package/dist/lib/di/modules/configure-module.d.ts +21 -0
  15. package/dist/lib/di/modules/configure-module.js +11 -0
  16. package/dist/lib/di/modules/module-def.types.d.ts +1 -1
  17. package/dist/lib/di/processors/controller-processor.d.ts +4 -1
  18. package/dist/lib/di/processors/controller-processor.js +57 -52
  19. package/dist/lib/di/processors/handler-processor.d.ts +3 -1
  20. package/dist/lib/di/processors/handler-processor.js +5 -3
  21. package/dist/lib/di/processors/initializer-processor.d.ts +3 -1
  22. package/dist/lib/di/processors/initializer-processor.js +25 -21
  23. package/dist/lib/di/processors/interceptor-processor.d.ts +4 -1
  24. package/dist/lib/di/processors/interceptor-processor.js +22 -16
  25. package/dist/lib/di/processors/keyed-feature-registrar.d.ts +4 -1
  26. package/dist/lib/di/processors/keyed-feature-registrar.js +58 -61
  27. package/dist/lib/di/providers/inquirer-resolver-factory.d.ts +10 -0
  28. package/dist/lib/di/providers/inquirer-resolver-factory.js +61 -0
  29. package/dist/lib/di/providers/provider-resolver.d.ts +5 -2
  30. package/dist/lib/di/providers/provider-resolver.js +43 -30
  31. package/dist/lib/di/providers/types/controller.types.d.ts +2 -1
  32. package/dist/lib/di/providers/types/handler.types.d.ts +0 -5
  33. package/dist/lib/di/providers/types/initializer.types.d.ts +2 -1
  34. package/dist/lib/di/providers/types/interceptor.types.d.ts +3 -2
  35. package/dist/lib/di/providers/types/middleware.types.d.ts +1 -4
  36. package/dist/lib/di/providers/types/provider.types.d.ts +4 -2
  37. package/dist/lib/di/type-guards.d.ts +1 -0
  38. package/dist/lib/extension-api/index.d.ts +1 -0
  39. package/dist/lib/extension-api/index.js +1 -0
  40. package/dist/tsconfig.build.tsbuildinfo +1 -1
  41. package/package.json +16 -7
@@ -2,6 +2,7 @@ import type * as Awilix from "awilix";
2
2
  import type { DevtoolsProcessorRef } from "../../devtools/devtools.types.js";
3
3
  import type { RegisteredModuleScope } from "../contexts/container-context-base.js";
4
4
  import type { InternalModuleLike as M } from "../modules/runtime-module.types.js";
5
+ import type { InquirerResolverFactory } from "../providers/inquirer-resolver-factory.js";
5
6
  import type { ConstructorController } from "../providers/provider.types.js";
6
7
  import type { ModuleInitOptions } from "./lifecycle-processor.js";
7
8
  export type ControllerRuntimeEntry = {
@@ -13,8 +14,9 @@ export declare class InitializerProcessor {
13
14
  private readonly devtoolsProcessorRef;
14
15
  private readonly keyedFeatureRegistrar;
15
16
  private readonly resolversByModule;
16
- constructor(devtoolsProcessorRef: DevtoolsProcessorRef);
17
+ constructor(inquirerResolverFactory: InquirerResolverFactory, devtoolsProcessorRef: DevtoolsProcessorRef);
17
18
  collectInitializers(m: M, scope: Awilix.AwilixContainer, importedModulesWithScope: RegisteredModuleScope[], controllers: ControllerRuntimeEntry[]): InitializerTask | null;
19
+ private initializeControllerMethod;
18
20
  private ensureNoMultiInvokableInitializersPerMethod;
19
21
  private filterActiveInitializers;
20
22
  }
@@ -5,10 +5,11 @@ import { runInRequestScopeContext } from "../request-scope-context.js";
5
5
  import { KeyedFeatureRegistrar } from "./keyed-feature-registrar.js";
6
6
  export class InitializerProcessor {
7
7
  devtoolsProcessorRef;
8
- keyedFeatureRegistrar = new KeyedFeatureRegistrar({});
8
+ keyedFeatureRegistrar;
9
9
  resolversByModule = new WeakMap();
10
- constructor(devtoolsProcessorRef) {
10
+ constructor(inquirerResolverFactory, devtoolsProcessorRef) {
11
11
  this.devtoolsProcessorRef = devtoolsProcessorRef;
12
+ this.keyedFeatureRegistrar = new KeyedFeatureRegistrar({}, inquirerResolverFactory);
12
13
  }
13
14
  collectInitializers(m, scope, importedModulesWithScope, controllers) {
14
15
  this.resolversByModule.set(m, this.keyedFeatureRegistrar.register({
@@ -34,29 +35,32 @@ export class InitializerProcessor {
34
35
  return;
35
36
  for (const controller of controllers) {
36
37
  for (const methodName of getControllerMethodNames(controller.controllerClass)) {
37
- const invoke = (...args) => runInRequestScopeContext(() => controller.resolve()[methodName](...args));
38
- this.ensureNoMultiInvokableInitializersPerMethod(m.name, methodName, controller, activeInitializers);
39
- for (const [, resolveInitializer] of activeInitializers) {
40
- const initializer = resolveInitializer();
41
- const decoratorState = resolveDecoratorState(controller.controllerClass, initializer.token);
42
- if (decoratorState === null)
43
- continue;
44
- const metadata = decoratorState.methods.get(methodName);
45
- if (metadata === undefined)
46
- continue;
47
- await initializer.initialize({
48
- moduleName: m.name,
49
- target: controller.controllerClass,
50
- methodName,
51
- metadata,
52
- decoratorState,
53
- ...(initializer.usesInvoke ? { invoke } : {}),
54
- });
55
- }
38
+ await this.initializeControllerMethod(m.name, controller, methodName, activeInitializers);
56
39
  }
57
40
  }
58
41
  };
59
42
  }
43
+ async initializeControllerMethod(moduleName, controller, methodName, initializers) {
44
+ const invoke = (...args) => runInRequestScopeContext(() => controller.resolve()[methodName](...args));
45
+ this.ensureNoMultiInvokableInitializersPerMethod(moduleName, methodName, controller, initializers);
46
+ for (const [, resolveInitializer] of initializers) {
47
+ const initializer = resolveInitializer();
48
+ const decoratorState = resolveDecoratorState(controller.controllerClass, initializer.token);
49
+ if (decoratorState === null)
50
+ continue;
51
+ const metadata = decoratorState.methods.get(methodName);
52
+ if (metadata === undefined)
53
+ continue;
54
+ await initializer.initialize({
55
+ moduleName,
56
+ target: controller.controllerClass,
57
+ methodName,
58
+ metadata,
59
+ decoratorState,
60
+ ...(initializer.usesInvoke ? { invoke } : {}),
61
+ });
62
+ }
63
+ }
60
64
  ensureNoMultiInvokableInitializersPerMethod(moduleName, methodName, controller, initializers) {
61
65
  const invokableInitializers = initializers
62
66
  .map(([, resolver]) => resolver())
@@ -3,11 +3,13 @@ import type { DevtoolsProcessorRef } from "../../devtools/devtools.types.js";
3
3
  import type { RegisteredModuleScope } from "../contexts/container-context-base.js";
4
4
  import type { DiContextOptions } from "../contexts/di-context-base.js";
5
5
  import type { InternalModuleLike as M } from "../modules/runtime-module.types.js";
6
+ import type { InquirerResolverFactory } from "../providers/inquirer-resolver-factory.js";
6
7
  export declare class InterceptorProcessor {
8
+ private readonly inquirerResolverFactory;
7
9
  private readonly devtoolsProcessorRef;
8
10
  private readonly keyedFeatureRegistrar;
9
11
  private readonly resolversByModule;
10
- constructor(providerOptions: DiContextOptions["providerOptions"], devtoolsProcessorRef: DevtoolsProcessorRef);
12
+ constructor(providerOptions: DiContextOptions["providerOptions"], inquirerResolverFactory: InquirerResolverFactory, devtoolsProcessorRef: DevtoolsProcessorRef);
11
13
  processInterceptors(m: M, scope: Awilix.AwilixContainer, importedModulesWithScope: RegisteredModuleScope[]): void;
12
14
  createInterceptedProviderResolver({ module, useClass, options, resolver, }: {
13
15
  module: M;
@@ -16,6 +18,7 @@ export declare class InterceptorProcessor {
16
18
  resolver?: Awilix.Resolver<any>;
17
19
  }): Awilix.Resolver<any>;
18
20
  private createInterceptedProviderInstance;
21
+ private collectInterceptorMetadata;
19
22
  private callWithInterceptorChain;
20
23
  private get devtoolsTracer();
21
24
  }
@@ -3,12 +3,14 @@ import { hasDecoratorMethodMetadata, resolveDecoratorState, } from "../../decora
3
3
  import { isPromiseLike } from "../type-guards.js";
4
4
  import { KeyedFeatureRegistrar } from "./keyed-feature-registrar.js";
5
5
  export class InterceptorProcessor {
6
+ inquirerResolverFactory;
6
7
  devtoolsProcessorRef;
7
8
  keyedFeatureRegistrar;
8
9
  resolversByModule = new WeakMap();
9
- constructor(providerOptions, devtoolsProcessorRef) {
10
+ constructor(providerOptions, inquirerResolverFactory, devtoolsProcessorRef) {
11
+ this.inquirerResolverFactory = inquirerResolverFactory;
10
12
  this.devtoolsProcessorRef = devtoolsProcessorRef;
11
- this.keyedFeatureRegistrar = new KeyedFeatureRegistrar(providerOptions ?? {});
13
+ this.keyedFeatureRegistrar = new KeyedFeatureRegistrar(providerOptions ?? {}, inquirerResolverFactory);
12
14
  }
13
15
  processInterceptors(m, scope, importedModulesWithScope) {
14
16
  const resolverMap = this.keyedFeatureRegistrar.register({
@@ -20,7 +22,7 @@ export class InterceptorProcessor {
20
22
  this.resolversByModule.set(m, resolverMap);
21
23
  }
22
24
  createInterceptedProviderResolver({ module, useClass, options, resolver, }) {
23
- const baseResolver = resolver || Awilix.asClass(useClass, options);
25
+ const baseResolver = resolver || this.inquirerResolverFactory.create(useClass, options);
24
26
  const interceptors = [
25
27
  ...(this.resolversByModule.get(module)?.values() ?? []),
26
28
  ];
@@ -53,19 +55,7 @@ export class InterceptorProcessor {
53
55
  return existing;
54
56
  const wrapped = (...args) => {
55
57
  const interceptors = resolveInterceptors.map((resolve) => resolve());
56
- const metadataByToken = new Map();
57
- for (const interceptor of interceptors) {
58
- const state = resolveDecoratorState(metadataTarget, interceptor.token);
59
- if (state === null)
60
- continue;
61
- const method = state.methods.get(propertyKey);
62
- if (method !== undefined) {
63
- metadataByToken.set(interceptor.token.stateSymbol, {
64
- state,
65
- method,
66
- });
67
- }
68
- }
58
+ const metadataByToken = self.collectInterceptorMetadata(metadataTarget, propertyKey, interceptors);
69
59
  const receiver = !self.devtoolsTracer || targetBoundMethods.has(propertyKey)
70
60
  ? target
71
61
  : proxyReceiver;
@@ -104,6 +94,22 @@ export class InterceptorProcessor {
104
94
  },
105
95
  });
106
96
  }
97
+ collectInterceptorMetadata(metadataTarget, propertyKey, interceptors) {
98
+ const metadataByToken = new Map();
99
+ for (const interceptor of interceptors) {
100
+ const state = resolveDecoratorState(metadataTarget, interceptor.token);
101
+ if (state === null)
102
+ continue;
103
+ const method = state.methods.get(propertyKey);
104
+ if (method !== undefined) {
105
+ metadataByToken.set(interceptor.token.stateSymbol, {
106
+ state,
107
+ method,
108
+ });
109
+ }
110
+ }
111
+ return metadataByToken;
112
+ }
107
113
  callWithInterceptorChain({ target, methodName, moduleName, args, metadataByToken, interceptors, proceed, }) {
108
114
  const invoke = (index, next) => {
109
115
  if (index >= interceptors.length)
@@ -2,6 +2,7 @@ import * as Awilix from "awilix";
2
2
  import type { DevtoolsProcessorRef } from "../../devtools/devtools.types.js";
3
3
  import type { RegisteredModuleScope } from "../contexts/container-context-base.js";
4
4
  import type { InternalModuleLike as M } from "../modules/runtime-module.types.js";
5
+ import type { InquirerResolverFactory } from "../providers/inquirer-resolver-factory.js";
5
6
  type KeyedFeatureKind = "queryPreHandlers" | "commandPreHandlers" | "interceptors" | "initializers";
6
7
  type RegisterKeyedFeatureParams = {
7
8
  featureKind: KeyedFeatureKind;
@@ -11,10 +12,12 @@ type RegisterKeyedFeatureParams = {
11
12
  };
12
13
  export declare class KeyedFeatureRegistrar {
13
14
  private readonly providerOptions;
15
+ private readonly inquirerResolverFactory;
14
16
  private readonly devtoolsProcessorRef;
15
- constructor(providerOptions: Partial<Awilix.BuildResolverOptions<any>>, devtoolsProcessorRef?: DevtoolsProcessorRef);
17
+ constructor(providerOptions: Partial<Awilix.BuildResolverOptions<any>>, inquirerResolverFactory: InquirerResolverFactory, devtoolsProcessorRef?: DevtoolsProcessorRef);
16
18
  private readonly featureConfig;
17
19
  register<T>({ featureKind, module, scope, importedModulesWithScope, }: RegisterKeyedFeatureParams): Map<string, () => T>;
20
+ private registerFeature;
18
21
  private createFeatureResolver;
19
22
  private get devtoolsTracer();
20
23
  private getProviderOptions;
@@ -5,9 +5,11 @@ import { getOrCreateRequestScope, resolveFromRequestScope, } from "../request-sc
5
5
  import { hasUseClass } from "../type-guards.js";
6
6
  export class KeyedFeatureRegistrar {
7
7
  providerOptions;
8
+ inquirerResolverFactory;
8
9
  devtoolsProcessorRef;
9
- constructor(providerOptions, devtoolsProcessorRef = {}) {
10
+ constructor(providerOptions, inquirerResolverFactory, devtoolsProcessorRef = {}) {
10
11
  this.providerOptions = providerOptions;
12
+ this.inquirerResolverFactory = inquirerResolverFactory;
11
13
  this.devtoolsProcessorRef = devtoolsProcessorRef;
12
14
  }
13
15
  featureConfig = {
@@ -29,77 +31,72 @@ export class KeyedFeatureRegistrar {
29
31
  },
30
32
  };
31
33
  register({ featureKind, module, scope, importedModulesWithScope, }) {
32
- const ownerByKey = new Map();
33
- const resolverMap = new Map();
34
- const ownerByInitializerToken = new Map();
35
- const config = this.featureConfig[featureKind];
36
- const providerResolver = new ProviderResolver(undefined, this.getProviderOptions(featureKind), {}, getOrCreateRequestScope);
34
+ const context = {
35
+ config: this.featureConfig[featureKind],
36
+ featureKind,
37
+ module,
38
+ scope,
39
+ providerResolver: new ProviderResolver(undefined, this.getProviderOptions(featureKind), getOrCreateRequestScope, this.inquirerResolverFactory),
40
+ ownerByKey: new Map(),
41
+ resolverMap: new Map(),
42
+ ownerByInitializerToken: new Map(),
43
+ };
37
44
  for (const { module: importedModule, moduleScope: importedModuleScope, } of importedModulesWithScope) {
38
- for (const key of importedModule[config.exportKey] ?? []) {
45
+ for (const key of importedModule[context.config.exportKey] ?? []) {
39
46
  const feature = importedModule[featureKind]?.[key];
40
47
  if (!feature) {
41
48
  throw new ERRORS.InvalidProviderDefinitionError(importedModule.name, key);
42
49
  }
43
- if (ownerByKey.has(key)) {
44
- throw new ERRORS.FeatureNameConflictError(module.name, config.featureName, key, ownerByKey.get(key) ?? importedModule.name);
45
- }
46
- const symbol = Symbol(`${featureKind}_export_${importedModule.name}_${key}`);
47
- scope.register({
48
- [symbol]: this.createFeatureResolver({
49
- feature,
50
- featureKind,
51
- key,
52
- module: importedModule,
53
- providerResolver,
54
- resolutionScope: importedModuleScope.scope,
55
- wrapForExport: true,
56
- }),
50
+ this.registerFeature(context, {
51
+ key,
52
+ feature,
53
+ ownerModule: importedModule,
54
+ resolutionScope: importedModuleScope.scope,
55
+ wrapForExport: true,
57
56
  });
58
- if (featureKind === "initializers") {
59
- this.ensureInitializerTokenUniqueness({
60
- scope,
61
- symbol,
62
- ownerByInitializerToken,
63
- moduleName: module.name,
64
- featureName: feature.name || key,
65
- });
66
- }
67
- resolverMap.set(key, featureKind === "initializers"
68
- ? () => scope.resolve(symbol)
69
- : () => resolveFromRequestScope(scope, symbol));
70
- ownerByKey.set(key, importedModule.name);
71
57
  }
72
58
  }
73
59
  for (const [key, feature] of Object.entries(module[featureKind] ?? {})) {
74
- if (ownerByKey.has(key)) {
75
- throw new ERRORS.FeatureNameConflictError(module.name, config.featureName, key, ownerByKey.get(key) ?? module.name);
76
- }
77
- const symbol = Symbol(`${featureKind}_${module.name}_${key}`);
78
- scope.register({
79
- [symbol]: this.createFeatureResolver({
80
- feature,
81
- featureKind,
82
- key,
83
- module,
84
- providerResolver,
85
- resolutionScope: scope,
86
- }),
60
+ this.registerFeature(context, {
61
+ key,
62
+ feature,
63
+ ownerModule: module,
64
+ resolutionScope: scope,
65
+ });
66
+ }
67
+ return context.resolverMap;
68
+ }
69
+ registerFeature(context, params) {
70
+ if (context.ownerByKey.has(params.key)) {
71
+ throw new ERRORS.FeatureNameConflictError(context.module.name, context.config.featureName, params.key, context.ownerByKey.get(params.key) ?? params.ownerModule.name);
72
+ }
73
+ const symbol = Symbol(params.wrapForExport
74
+ ? `${context.featureKind}_export_${params.ownerModule.name}_${params.key}`
75
+ : `${context.featureKind}_${params.ownerModule.name}_${params.key}`);
76
+ context.scope.register({
77
+ [symbol]: this.createFeatureResolver({
78
+ feature: params.feature,
79
+ featureKind: context.featureKind,
80
+ key: params.key,
81
+ module: params.ownerModule,
82
+ providerResolver: context.providerResolver,
83
+ resolutionScope: params.resolutionScope,
84
+ wrapForExport: params.wrapForExport,
85
+ }),
86
+ });
87
+ if (context.featureKind === "initializers") {
88
+ this.ensureInitializerTokenUniqueness({
89
+ scope: context.scope,
90
+ symbol,
91
+ ownerByInitializerToken: context.ownerByInitializerToken,
92
+ moduleName: context.module.name,
93
+ featureName: params.feature.name || params.key,
87
94
  });
88
- if (featureKind === "initializers") {
89
- this.ensureInitializerTokenUniqueness({
90
- scope,
91
- symbol,
92
- ownerByInitializerToken,
93
- moduleName: module.name,
94
- featureName: feature.name || key,
95
- });
96
- }
97
- resolverMap.set(key, featureKind === "initializers"
98
- ? () => scope.resolve(symbol)
99
- : () => resolveFromRequestScope(scope, symbol));
100
- ownerByKey.set(key, module.name);
101
95
  }
102
- return resolverMap;
96
+ context.resolverMap.set(params.key, context.featureKind === "initializers"
97
+ ? () => context.scope.resolve(symbol)
98
+ : () => resolveFromRequestScope(context.scope, symbol));
99
+ context.ownerByKey.set(params.key, params.ownerModule.name);
103
100
  }
104
101
  createFeatureResolver({ feature, featureKind, key, module, providerResolver, resolutionScope, wrapForExport = false, }) {
105
102
  const resolver = providerResolver.resolveClassProvider({
@@ -0,0 +1,10 @@
1
+ import * as Awilix from "awilix";
2
+ export declare class InquirerResolverFactory {
3
+ private currentFrame;
4
+ private enabled;
5
+ enableTracking(): void;
6
+ private withConsumer;
7
+ create<T extends object>(useClass: Awilix.Constructor<T>, options: Awilix.BuildResolverOptions<T> & {
8
+ injectInquirer?: boolean;
9
+ }): Awilix.Resolver<T>;
10
+ }
@@ -0,0 +1,61 @@
1
+ import * as Awilix from "awilix";
2
+ import { InquirerRequiresTransientLifetimeError } from "../errors.js";
3
+ export class InquirerResolverFactory {
4
+ currentFrame;
5
+ enabled = false;
6
+ enableTracking() {
7
+ this.enabled = true;
8
+ }
9
+ withConsumer(consumer, resolve) {
10
+ const previous = this.currentFrame;
11
+ this.currentFrame = { consumer, parent: previous?.consumer };
12
+ try {
13
+ return resolve();
14
+ }
15
+ finally {
16
+ this.currentFrame = previous;
17
+ }
18
+ }
19
+ create(useClass, options) {
20
+ const { injectInquirer, ...resolverOptions } = options;
21
+ if (injectInquirer && options.lifetime !== Awilix.Lifetime.TRANSIENT) {
22
+ throw new InquirerRequiresTransientLifetimeError(useClass.name);
23
+ }
24
+ const baseResolver = Awilix.asClass(useClass, {
25
+ ...resolverOptions,
26
+ ...(injectInquirer && {
27
+ isLeakSafe: resolverOptions.isLeakSafe ?? true,
28
+ injector: (container) => ({
29
+ ...resolverOptions.injector?.(container),
30
+ inquirer: this.currentFrame?.parent,
31
+ }),
32
+ }),
33
+ });
34
+ return {
35
+ ...baseResolver,
36
+ resolve: (container) => {
37
+ if (!this.enabled)
38
+ return baseResolver.resolve(container);
39
+ const consumer = useClass.prototype;
40
+ if ((resolverOptions.injectionMode ?? container.options.injectionMode) ===
41
+ Awilix.InjectionMode.CLASSIC) {
42
+ return this.withConsumer(consumer, () => baseResolver.resolve(container));
43
+ }
44
+ const cradle = new Proxy(container.cradle, {
45
+ get: (target, key) => this.withConsumer(consumer, () => Reflect.get(target, key)),
46
+ });
47
+ const contextualContainer = new Proxy(container, {
48
+ get: (target, key) => {
49
+ if (key === "cradle")
50
+ return cradle;
51
+ if (key === "resolve") {
52
+ return (...args) => this.withConsumer(consumer, () => container.resolve(...args));
53
+ }
54
+ return Reflect.get(target, key);
55
+ },
56
+ });
57
+ return this.withConsumer(consumer, () => baseResolver.resolve(contextualContainer));
58
+ },
59
+ };
60
+ }
61
+ }
@@ -2,6 +2,7 @@ import * as Awilix from "awilix";
2
2
  import type { DevtoolsProcessorRef } from "../../devtools/devtools.types.js";
3
3
  import type { InternalModuleLike as M } from "../modules/runtime-module.types.js";
4
4
  import type { InterceptorProcessor } from "../processors/interceptor-processor.js";
5
+ import type { InquirerResolverFactory } from "./inquirer-resolver-factory.js";
5
6
  import type { AnyProvider } from "./provider.types.js";
6
7
  export type RequestScopeResolver = (scope: Awilix.AwilixContainer) => Awilix.AwilixContainer;
7
8
  type ResolveProviderParams = {
@@ -21,13 +22,15 @@ type ResolveClassProviderParams = {
21
22
  export declare class ProviderResolver {
22
23
  private readonly interceptorProcessor;
23
24
  private readonly providerOptions;
25
+ private readonly requestScopeResolver;
26
+ private readonly inquirerResolverFactory;
24
27
  private readonly devtoolsProcessorRef;
25
- private readonly requestScopeResolver?;
26
- constructor(interceptorProcessor: InterceptorProcessor | undefined, providerOptions: Partial<Awilix.BuildResolverOptions<any>>, devtoolsProcessorRef: DevtoolsProcessorRef, requestScopeResolver?: RequestScopeResolver | undefined);
28
+ constructor(interceptorProcessor: InterceptorProcessor | undefined, providerOptions: Partial<Awilix.BuildResolverOptions<any>>, requestScopeResolver: RequestScopeResolver | undefined, inquirerResolverFactory: InquirerResolverFactory, devtoolsProcessorRef?: DevtoolsProcessorRef);
27
29
  static mergeResolverOptions(module: M, providerOptions: Partial<Awilix.BuildResolverOptions<any>>, options?: Partial<Awilix.BuildResolverOptions<any>>): Awilix.BuildResolverOptions<any>;
28
30
  resolveClassProvider({ provider, resolutionScope, module, wrapForExport, }: ResolveClassProviderParams): Awilix.Resolver<any>;
29
31
  resolveProvider({ key, moduleId, provider, resolutionScope, module, }: ResolveProviderParams): Awilix.Resolver<any>;
30
32
  resolveProviderAsync({ key, moduleId, provider, resolutionScope, module, }: ResolveProviderParams): Promise<Awilix.Resolver<any>>;
33
+ private resolveFactoryProvider;
31
34
  private extractResolverOptions;
32
35
  private createProxyResolver;
33
36
  private get devtoolsTracer();
@@ -4,13 +4,15 @@ import * as GUARGS from "../type-guards.js";
4
4
  export class ProviderResolver {
5
5
  interceptorProcessor;
6
6
  providerOptions;
7
- devtoolsProcessorRef;
8
7
  requestScopeResolver;
9
- constructor(interceptorProcessor, providerOptions, devtoolsProcessorRef, requestScopeResolver) {
8
+ inquirerResolverFactory;
9
+ devtoolsProcessorRef;
10
+ constructor(interceptorProcessor, providerOptions, requestScopeResolver, inquirerResolverFactory, devtoolsProcessorRef = {}) {
10
11
  this.interceptorProcessor = interceptorProcessor;
11
12
  this.providerOptions = providerOptions;
12
- this.devtoolsProcessorRef = devtoolsProcessorRef;
13
13
  this.requestScopeResolver = requestScopeResolver;
14
+ this.inquirerResolverFactory = inquirerResolverFactory;
15
+ this.devtoolsProcessorRef = devtoolsProcessorRef;
14
16
  }
15
17
  static mergeResolverOptions(module, providerOptions, options) {
16
18
  return {
@@ -28,7 +30,7 @@ export class ProviderResolver {
28
30
  ...module.providerOptions,
29
31
  ...featureOptions,
30
32
  };
31
- const resolver = Awilix.asClass(useClass, resolverOptions);
33
+ const resolver = this.inquirerResolverFactory.create(useClass, resolverOptions);
32
34
  if (!wrapForExport)
33
35
  return resolver;
34
36
  return Awilix.asFunction(() => resolver.resolve(resolverOptions.lifetime === Awilix.Lifetime.SINGLETON
@@ -53,7 +55,7 @@ export class ProviderResolver {
53
55
  }
54
56
  const resolverOptions = this.extractResolverOptions(module, provider);
55
57
  if (GUARGS.isCostructorProvider(provider)) {
56
- const baseResolver = Awilix.asClass(provider, resolverOptions);
58
+ const baseResolver = this.inquirerResolverFactory.create(provider, resolverOptions);
57
59
  const tracedResolver = !this.devtoolsTracer
58
60
  ? baseResolver
59
61
  : this.devtoolsTracer.wrapResolver({
@@ -75,30 +77,9 @@ export class ProviderResolver {
75
77
  });
76
78
  }
77
79
  if (GUARGS.isFactoryProvider(provider)) {
78
- if (GUARGS.isAsyncFactoryProvider(provider)) {
79
- if (GUARGS.isEagerProvider(provider)) {
80
- return Awilix.asFunction(() => {
81
- throw new ERRORS.AsyncEagerFactoryRequiresInitError(module.name, key ?? "unknown");
82
- }, resolverOptions);
83
- }
84
- throw new ERRORS.AsyncFactoryRequiresAsyncCreateError(module.name, key ?? "unknown");
85
- }
86
- const factoryDeps = (provider.inject || []).map((k) => resolutionScope.registrations[k].resolve(resolutionScope));
87
- const resolver = Awilix.asFunction(() => provider.useFactory(...factoryDeps), resolverOptions);
88
- if (!this.devtoolsTracer)
89
- return resolver;
90
- return this.devtoolsTracer.wrapResolver({
91
- kind: "provider",
92
- module,
93
- moduleId,
94
- options: resolverOptions,
95
- className: key,
96
- registrationKey: key,
97
- isFactory: true,
98
- resolver,
99
- });
80
+ return this.resolveFactoryProvider({ key, moduleId, provider, resolutionScope, module }, resolverOptions);
100
81
  }
101
- const baseResolver = Awilix.asClass(provider.useClass, resolverOptions);
82
+ const baseResolver = this.inquirerResolverFactory.create(provider.useClass, resolverOptions);
102
83
  const classResolver = provider.allowCircular
103
84
  ? this.createProxyResolver(baseResolver, resolverOptions)
104
85
  : baseResolver;
@@ -140,10 +121,42 @@ export class ProviderResolver {
140
121
  const factoryDeps = (provider.inject || []).map((k) => resolutionScope.registrations[k].resolve(resolutionScope));
141
122
  return Awilix.asValue(await provider.useFactory(...factoryDeps));
142
123
  }
124
+ resolveFactoryProvider(params, resolverOptions) {
125
+ const { provider, module, key, resolutionScope, moduleId } = params;
126
+ if (GUARGS.isAsyncFactoryProvider(provider)) {
127
+ if (GUARGS.isEagerProvider(provider)) {
128
+ return Awilix.asFunction(() => {
129
+ throw new ERRORS.AsyncEagerFactoryRequiresInitError(module.name, key ?? "unknown");
130
+ }, resolverOptions);
131
+ }
132
+ throw new ERRORS.AsyncFactoryRequiresAsyncCreateError(module.name, key ?? "unknown");
133
+ }
134
+ const factoryDeps = (provider.inject || []).map((k) => resolutionScope.registrations[k].resolve(resolutionScope));
135
+ const resolver = Awilix.asFunction(() => provider.useFactory(...factoryDeps), resolverOptions);
136
+ if (!this.devtoolsTracer)
137
+ return resolver;
138
+ return this.devtoolsTracer.wrapResolver({
139
+ kind: "provider",
140
+ module,
141
+ moduleId,
142
+ options: resolverOptions,
143
+ className: key,
144
+ registrationKey: key,
145
+ isFactory: true,
146
+ resolver,
147
+ });
148
+ }
143
149
  extractResolverOptions(module, provider) {
144
150
  if (GUARGS.hasUseClass(provider)) {
145
- const { useClass, allowCircular, eager, initAfter, ...options } = provider;
146
- return ProviderResolver.mergeResolverOptions(module, this.providerOptions, options);
151
+ const { useClass, allowCircular, eager, initAfter, injectInquirer, ...options } = provider;
152
+ const mergedOptions = ProviderResolver.mergeResolverOptions(module, this.providerOptions, options);
153
+ return {
154
+ ...mergedOptions,
155
+ ...(injectInquirer && {
156
+ injectInquirer,
157
+ isLeakSafe: mergedOptions.isLeakSafe ?? true,
158
+ }),
159
+ };
147
160
  }
148
161
  if (GUARGS.isFactoryProvider(provider)) {
149
162
  const { eager, initAfter, inject, useFactory, ...options } = provider;
@@ -1,9 +1,10 @@
1
1
  import type { BuildResolverOptions, Constructor } from "awilix";
2
2
  export type ConstructorController = Constructor<Controller>;
3
- export type ClassController = {
3
+ type ClassController = {
4
4
  useClass: ConstructorController | Constructor<any>;
5
5
  } & BuildResolverOptions<any>;
6
6
  export type AnyController = ConstructorController | ClassController | Constructor<any>;
7
7
  export interface Controller {
8
8
  registerRoutes: () => void;
9
9
  }
10
+ export {};
@@ -1,9 +1,4 @@
1
1
  import type { BuildResolverOptions, Constructor } from "awilix";
2
- import type { AnyContract } from "lib/mediator/contract.types.js";
3
- import type { Handler } from "lib/mediator/handler.types.js";
4
- export interface ConstructorHandler<C extends AnyContract = AnyContract> {
5
- new (...args: any[]): Handler<C>;
6
- }
7
2
  export type ClassHandler<H extends Constructor<any> = Constructor<any>> = {
8
3
  useClass: H;
9
4
  } & BuildResolverOptions<any>;
@@ -1,7 +1,7 @@
1
1
  import type { Constructor } from "awilix";
2
2
  import type { AnyDecoratorToken, DecoratorExecutionContext } from "./decorator-context.types.js";
3
3
  export type DefInitializerMap = Record<string, ConstructorInitializer>;
4
- export interface ConstructorInitializer {
4
+ interface ConstructorInitializer {
5
5
  new (...args: any[]): Initializer<any, boolean>;
6
6
  }
7
7
  export type MetadataInitializerContext<TToken extends AnyDecoratorToken = AnyDecoratorToken> = DecoratorExecutionContext<TToken, Constructor<any>>;
@@ -14,3 +14,4 @@ export declare abstract class Initializer<TToken extends AnyDecoratorToken = Any
14
14
  abstract initialize(context: TUsesInvoke extends true ? InitializerContext<TToken> : MetadataInitializerContext<TToken>): void | Promise<void>;
15
15
  }
16
16
  export type AnyInitializer = ConstructorInitializer;
17
+ export {};
@@ -1,10 +1,10 @@
1
1
  import type { BuildResolverOptions, Constructor } from "awilix";
2
2
  import type { AnyDecoratorToken, DecoratorExecutionContext } from "./decorator-context.types.js";
3
3
  export type DefInterceptorMap = Record<string, object>;
4
- export interface ConstructorInterceptor {
4
+ interface ConstructorInterceptor {
5
5
  new (...args: any[]): Interceptor;
6
6
  }
7
- export type ClassInterceptor<I extends Constructor<any> = Constructor<any>> = {
7
+ type ClassInterceptor<I extends Constructor<any> = Constructor<any>> = {
8
8
  useClass: I;
9
9
  } & BuildResolverOptions<any>;
10
10
  export type AnyInterceptor = ClassInterceptor | ConstructorInterceptor;
@@ -16,3 +16,4 @@ export interface Interceptor<TToken extends AnyDecoratorToken = AnyDecoratorToke
16
16
  token: TToken;
17
17
  intercept(context: InterceptContext<TToken>): unknown | Promise<unknown>;
18
18
  }
19
+ export {};
@@ -1,9 +1,6 @@
1
1
  import type { BuildResolverOptions, Constructor } from "awilix";
2
- import type { AnyMiddlewareContract, Middleware } from "lib/mediator/middleware.types.js";
2
+ import type { Middleware } from "lib/mediator/middleware.types.js";
3
3
  export type DefPreHandlerMap = Record<string, object>;
4
- export interface ConstructorMiddleware<C extends AnyMiddlewareContract = AnyMiddlewareContract> {
5
- new (...args: any[]): Middleware<C>;
6
- }
7
4
  export type ClassMiddleware<M extends Constructor<any> = Constructor<any>> = {
8
5
  useClass: M;
9
6
  } & BuildResolverOptions<any>;
@@ -1,7 +1,8 @@
1
1
  import type { BuildResolverOptions, Constructor } from "awilix";
2
2
  import { InitHook, ShutdownHook } from "../../lifecycle-hooks.js";
3
+ export type InquirerContext = object | undefined;
3
4
  export type DefProviderMap = Record<string, object | string | boolean | number>;
4
- export type ConstructorProvider<T extends object = object> = Constructor<T>;
5
+ type ConstructorProvider<T extends object = object> = Constructor<T>;
5
6
  export type PrimitiveProvider = string | number | boolean | symbol | bigint;
6
7
  export type FunctionProvider = (...args: any[]) => any;
7
8
  export type FactoryProvider<T extends object, DepsMap extends Record<string, unknown>, Keys extends readonly Extract<keyof DepsMap, string>[], Strict extends boolean = true, ResolverOptions extends object = BuildResolverOptions<T>> = {
@@ -10,8 +11,9 @@ export type FactoryProvider<T extends object, DepsMap extends Record<string, unk
10
11
  eager?: boolean;
11
12
  useFactory: Strict extends true ? (...args: MapKeysToValues<DepsMap, Keys>) => T | Promise<T> : (...args: any[]) => T | Promise<T>;
12
13
  } & ResolverOptions;
13
- export type ClassProvider<T extends object, DepsMap extends Record<string, unknown> = Record<string, unknown>, ResolverOptions extends object = BuildResolverOptions<T>> = {
14
+ type ClassProvider<T extends object, DepsMap extends Record<string, unknown> = Record<string, unknown>, ResolverOptions extends object = BuildResolverOptions<T>> = {
14
15
  useClass: Constructor<T>;
16
+ injectInquirer?: boolean;
15
17
  allowCircular?: boolean;
16
18
  eager?: boolean;
17
19
  initAfter?: readonly Extract<keyof DepsMap, string>[];