awilixify 3.2.2 → 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.
- package/README.md +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/lib/decorators/decorator-state.types.d.ts +1 -1
- package/dist/lib/di/common.types.d.ts +0 -1
- package/dist/lib/di/contexts/container-context-base.d.ts +4 -0
- package/dist/lib/di/contexts/container-context-base.js +40 -19
- package/dist/lib/di/contexts/di-context-async.js +4 -23
- package/dist/lib/di/contexts/di-context-base.js +5 -5
- package/dist/lib/di/contexts/di-context.d.ts +5 -0
- package/dist/lib/di/contexts/di-context.js +54 -0
- package/dist/lib/di/contexts/module-graph-ensurer.d.ts +9 -0
- package/dist/lib/di/contexts/module-graph-ensurer.js +27 -0
- package/dist/lib/di/errors.d.ts +21 -0
- package/dist/lib/di/errors.js +43 -0
- package/dist/lib/di/lifecycle-hooks.d.ts +10 -0
- package/dist/lib/di/lifecycle-hooks.js +8 -0
- package/dist/lib/di/modules/configure-module.d.ts +21 -0
- package/dist/lib/di/modules/configure-module.js +11 -0
- package/dist/lib/di/modules/module-def.types.d.ts +1 -1
- package/dist/lib/di/processors/controller-processor.d.ts +4 -1
- package/dist/lib/di/processors/controller-processor.js +57 -52
- package/dist/lib/di/processors/handler-processor.d.ts +3 -1
- package/dist/lib/di/processors/handler-processor.js +5 -3
- package/dist/lib/di/processors/initializer-processor.d.ts +3 -1
- package/dist/lib/di/processors/initializer-processor.js +25 -21
- package/dist/lib/di/processors/interceptor-processor.d.ts +4 -1
- package/dist/lib/di/processors/interceptor-processor.js +22 -16
- package/dist/lib/di/processors/keyed-feature-registrar.d.ts +4 -1
- package/dist/lib/di/processors/keyed-feature-registrar.js +58 -61
- package/dist/lib/di/processors/lifecycle-processor.d.ts +9 -9
- package/dist/lib/di/processors/lifecycle-processor.js +67 -29
- package/dist/lib/di/providers/inquirer-resolver-factory.d.ts +10 -0
- package/dist/lib/di/providers/inquirer-resolver-factory.js +61 -0
- package/dist/lib/di/providers/provider-resolver.d.ts +5 -2
- package/dist/lib/di/providers/provider-resolver.js +43 -30
- package/dist/lib/di/providers/types/controller.types.d.ts +2 -1
- package/dist/lib/di/providers/types/handler.types.d.ts +0 -5
- package/dist/lib/di/providers/types/initializer.types.d.ts +2 -1
- package/dist/lib/di/providers/types/interceptor.types.d.ts +3 -2
- package/dist/lib/di/providers/types/middleware.types.d.ts +1 -4
- package/dist/lib/di/providers/types/provider.types.d.ts +16 -4
- package/dist/lib/di/providers/types/provider.types.js +1 -1
- package/dist/lib/di/type-guards.d.ts +7 -4
- package/dist/lib/di/type-guards.js +13 -6
- package/dist/lib/extension-api/index.d.ts +1 -0
- package/dist/lib/extension-api/index.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +19 -10
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -6,12 +6,14 @@ export class ControllerProcessor {
|
|
|
6
6
|
interceptorProcessor;
|
|
7
7
|
providerOptions;
|
|
8
8
|
skipRegisterRoutes;
|
|
9
|
+
inquirerResolverFactory;
|
|
9
10
|
devtoolsProcessorRef;
|
|
10
11
|
registeredControllers = new WeakMap();
|
|
11
|
-
constructor(interceptorProcessor, providerOptions, skipRegisterRoutes, devtoolsProcessorRef) {
|
|
12
|
+
constructor(interceptorProcessor, providerOptions, skipRegisterRoutes, inquirerResolverFactory, devtoolsProcessorRef) {
|
|
12
13
|
this.interceptorProcessor = interceptorProcessor;
|
|
13
14
|
this.providerOptions = providerOptions;
|
|
14
15
|
this.skipRegisterRoutes = skipRegisterRoutes;
|
|
16
|
+
this.inquirerResolverFactory = inquirerResolverFactory;
|
|
15
17
|
this.devtoolsProcessorRef = devtoolsProcessorRef;
|
|
16
18
|
}
|
|
17
19
|
processControllers(m, diScope) {
|
|
@@ -29,57 +31,7 @@ export class ControllerProcessor {
|
|
|
29
31
|
: { useClass: c };
|
|
30
32
|
const existingModule = this.registeredControllers.get(useClass);
|
|
31
33
|
if (!existingModule) {
|
|
32
|
-
this.
|
|
33
|
-
const controllerSymbol = Symbol(`controller_${useClass.name}`);
|
|
34
|
-
const options = {
|
|
35
|
-
...this.providerOptions,
|
|
36
|
-
...m.providerOptions,
|
|
37
|
-
...awilixOptions,
|
|
38
|
-
};
|
|
39
|
-
const isWithNewScope = options.lifetime !== Awilix.Lifetime.SINGLETON;
|
|
40
|
-
const baseResolver = Awilix.asClass(useClass, {
|
|
41
|
-
...options,
|
|
42
|
-
...(isWithNewScope && {
|
|
43
|
-
injector: () => ({
|
|
44
|
-
resolveSelf: () => this.resolveBySymbol(controllerSymbol, diScope, isWithNewScope),
|
|
45
|
-
}),
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
|
-
const tracedResolver = this.devtoolsTracer
|
|
49
|
-
? this.createTracedControllerResolver({
|
|
50
|
-
module: m,
|
|
51
|
-
options,
|
|
52
|
-
className: useClass.name,
|
|
53
|
-
registrationKey: useClass.name,
|
|
54
|
-
resolver: baseResolver,
|
|
55
|
-
})
|
|
56
|
-
: baseResolver;
|
|
57
|
-
const interceptedResolver = this.interceptorProcessor.createInterceptedProviderResolver({
|
|
58
|
-
module: m,
|
|
59
|
-
useClass,
|
|
60
|
-
options,
|
|
61
|
-
resolver: tracedResolver,
|
|
62
|
-
});
|
|
63
|
-
const traceStarterResolver = this.devtoolsTracer
|
|
64
|
-
? this.createTraceStarterResolver({
|
|
65
|
-
module: m,
|
|
66
|
-
options,
|
|
67
|
-
className: useClass.name,
|
|
68
|
-
registrationKey: useClass.name,
|
|
69
|
-
resolver: interceptedResolver,
|
|
70
|
-
})
|
|
71
|
-
: interceptedResolver;
|
|
72
|
-
diScope.register({
|
|
73
|
-
[controllerSymbol]: traceStarterResolver,
|
|
74
|
-
});
|
|
75
|
-
if (!this.skipRegisterRoutes &&
|
|
76
|
-
typeof useClass.prototype.registerRoutes === "function") {
|
|
77
|
-
baseResolver.resolve(diScope).registerRoutes();
|
|
78
|
-
}
|
|
79
|
-
runtimeEntries.push({
|
|
80
|
-
controllerClass: useClass,
|
|
81
|
-
resolve: () => this.resolveBySymbol(controllerSymbol, diScope, isWithNewScope),
|
|
82
|
-
});
|
|
34
|
+
runtimeEntries.push(this.registerController(m, diScope, useClass, awilixOptions));
|
|
83
35
|
continue;
|
|
84
36
|
}
|
|
85
37
|
if (existingModule === m) {
|
|
@@ -89,6 +41,59 @@ export class ControllerProcessor {
|
|
|
89
41
|
}
|
|
90
42
|
return runtimeEntries;
|
|
91
43
|
}
|
|
44
|
+
registerController(m, diScope, useClass, awilixOptions) {
|
|
45
|
+
this.registeredControllers.set(useClass, m);
|
|
46
|
+
const controllerSymbol = Symbol(`controller_${useClass.name}`);
|
|
47
|
+
const options = {
|
|
48
|
+
...this.providerOptions,
|
|
49
|
+
...m.providerOptions,
|
|
50
|
+
...awilixOptions,
|
|
51
|
+
};
|
|
52
|
+
const isWithNewScope = options.lifetime !== Awilix.Lifetime.SINGLETON;
|
|
53
|
+
const baseResolver = this.inquirerResolverFactory.create(useClass, {
|
|
54
|
+
...options,
|
|
55
|
+
...(isWithNewScope && {
|
|
56
|
+
injector: () => ({
|
|
57
|
+
resolveSelf: () => this.resolveBySymbol(controllerSymbol, diScope, isWithNewScope),
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
const tracedResolver = this.devtoolsTracer
|
|
62
|
+
? this.createTracedControllerResolver({
|
|
63
|
+
module: m,
|
|
64
|
+
options,
|
|
65
|
+
className: useClass.name,
|
|
66
|
+
registrationKey: useClass.name,
|
|
67
|
+
resolver: baseResolver,
|
|
68
|
+
})
|
|
69
|
+
: baseResolver;
|
|
70
|
+
const interceptedResolver = this.interceptorProcessor.createInterceptedProviderResolver({
|
|
71
|
+
module: m,
|
|
72
|
+
useClass,
|
|
73
|
+
options,
|
|
74
|
+
resolver: tracedResolver,
|
|
75
|
+
});
|
|
76
|
+
const traceStarterResolver = this.devtoolsTracer
|
|
77
|
+
? this.createTraceStarterResolver({
|
|
78
|
+
module: m,
|
|
79
|
+
options,
|
|
80
|
+
className: useClass.name,
|
|
81
|
+
registrationKey: useClass.name,
|
|
82
|
+
resolver: interceptedResolver,
|
|
83
|
+
})
|
|
84
|
+
: interceptedResolver;
|
|
85
|
+
diScope.register({
|
|
86
|
+
[controllerSymbol]: traceStarterResolver,
|
|
87
|
+
});
|
|
88
|
+
if (!this.skipRegisterRoutes &&
|
|
89
|
+
typeof useClass.prototype.registerRoutes === "function") {
|
|
90
|
+
baseResolver.resolve(diScope).registerRoutes();
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
controllerClass: useClass,
|
|
94
|
+
resolve: () => this.resolveBySymbol(controllerSymbol, diScope, isWithNewScope),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
92
97
|
resolveBySymbol(symbol, scope, withNewScope) {
|
|
93
98
|
if (withNewScope)
|
|
94
99
|
return resolveFromRequestScope(scope, symbol);
|
|
@@ -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
|
export declare const HandlerType: {
|
|
6
7
|
readonly Query: "query";
|
|
7
8
|
readonly Command: "command";
|
|
@@ -9,10 +10,11 @@ export declare const HandlerType: {
|
|
|
9
10
|
export type HandlerType = (typeof HandlerType)[keyof typeof HandlerType];
|
|
10
11
|
export declare class HandlerProcessor {
|
|
11
12
|
private readonly providerOptions;
|
|
13
|
+
private readonly inquirerResolverFactory;
|
|
12
14
|
private readonly devtoolsProcessorRef;
|
|
13
15
|
private readonly keyedFeatureRegistrar;
|
|
14
16
|
private static readonly handlerConfig;
|
|
15
|
-
constructor(providerOptions: Partial<Awilix.BuildResolverOptions<any>>, devtoolsProcessorRef: DevtoolsProcessorRef);
|
|
17
|
+
constructor(providerOptions: Partial<Awilix.BuildResolverOptions<any>>, inquirerResolverFactory: InquirerResolverFactory, devtoolsProcessorRef: DevtoolsProcessorRef);
|
|
16
18
|
processHandlers(m: M, scope: Awilix.AwilixContainer, importedModulesWithScope: RegisteredModuleScope[], handlerType: HandlerType): void;
|
|
17
19
|
private createTracedHandlerResolver;
|
|
18
20
|
private get devtoolsTracer();
|
|
@@ -11,6 +11,7 @@ export const HandlerType = {
|
|
|
11
11
|
};
|
|
12
12
|
export class HandlerProcessor {
|
|
13
13
|
providerOptions;
|
|
14
|
+
inquirerResolverFactory;
|
|
14
15
|
devtoolsProcessorRef;
|
|
15
16
|
keyedFeatureRegistrar;
|
|
16
17
|
static handlerConfig = {
|
|
@@ -25,10 +26,11 @@ export class HandlerProcessor {
|
|
|
25
26
|
mediatorKey: "commandMediator",
|
|
26
27
|
},
|
|
27
28
|
};
|
|
28
|
-
constructor(providerOptions, devtoolsProcessorRef) {
|
|
29
|
+
constructor(providerOptions, inquirerResolverFactory, devtoolsProcessorRef) {
|
|
29
30
|
this.providerOptions = providerOptions;
|
|
31
|
+
this.inquirerResolverFactory = inquirerResolverFactory;
|
|
30
32
|
this.devtoolsProcessorRef = devtoolsProcessorRef;
|
|
31
|
-
this.keyedFeatureRegistrar = new KeyedFeatureRegistrar(providerOptions, devtoolsProcessorRef);
|
|
33
|
+
this.keyedFeatureRegistrar = new KeyedFeatureRegistrar(providerOptions, inquirerResolverFactory, devtoolsProcessorRef);
|
|
32
34
|
}
|
|
33
35
|
processHandlers(m, scope, importedModulesWithScope, handlerType) {
|
|
34
36
|
const { handlersKey, mediatorKey, preHandlersKey } = HandlerProcessor.handlerConfig[handlerType];
|
|
@@ -52,7 +54,7 @@ export class HandlerProcessor {
|
|
|
52
54
|
}
|
|
53
55
|
const options = ProviderResolver.mergeResolverOptions(m, this.providerOptions, handlerOptions);
|
|
54
56
|
const handlerSymbol = Symbol(`${handlerKey}_${HandlerClass.name}`);
|
|
55
|
-
const handlerResolver =
|
|
57
|
+
const handlerResolver = this.inquirerResolverFactory.create(HandlerClass, options);
|
|
56
58
|
scope.register({
|
|
57
59
|
[handlerSymbol]: this.createTracedHandlerResolver({
|
|
58
60
|
handlerClassName: HandlerClass.name,
|
|
@@ -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
|
|
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
|
-
|
|
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 ||
|
|
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 =
|
|
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
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
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({
|
|
@@ -3,11 +3,12 @@ import type { InternalModuleLike as M } from "../modules/runtime-module.types.js
|
|
|
3
3
|
import type { InitializerTask } from "./initializer-processor.js";
|
|
4
4
|
export interface ModuleInitOptions {
|
|
5
5
|
excludeInitializers?: true | readonly string[];
|
|
6
|
-
|
|
6
|
+
excludeAfterInit?: true | readonly string[];
|
|
7
7
|
}
|
|
8
8
|
export interface LifecycleMethods {
|
|
9
9
|
init(options?: ModuleInitOptions): Promise<void>;
|
|
10
|
-
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
enableShutdownHooks(): void;
|
|
11
12
|
}
|
|
12
13
|
export declare class LifecycleProcessor {
|
|
13
14
|
private readonly providerOptions;
|
|
@@ -15,21 +16,20 @@ export declare class LifecycleProcessor {
|
|
|
15
16
|
private readonly initializerTasks;
|
|
16
17
|
private readonly createdScopes;
|
|
17
18
|
private initPromise?;
|
|
18
|
-
private
|
|
19
|
+
private closePromise?;
|
|
20
|
+
private readonly shutdownListeners;
|
|
19
21
|
constructor(providerOptions: Partial<Awilix.BuildResolverOptions<any>>);
|
|
20
22
|
collectEagerProviders(m: M, scope: Awilix.AwilixContainer): void;
|
|
21
23
|
trackScope(scope: Awilix.AwilixContainer): void;
|
|
22
24
|
addInitializerTask(task: InitializerTask | null): void;
|
|
23
25
|
init(options?: ModuleInitOptions): Promise<void>;
|
|
24
|
-
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
enableShutdownHooks(): void;
|
|
25
28
|
private executeInit;
|
|
26
|
-
private
|
|
27
|
-
private
|
|
29
|
+
private executeClose;
|
|
30
|
+
private shouldSkipProviderAfterInit;
|
|
28
31
|
private getEagerProviderKeys;
|
|
29
|
-
private ensureEagerProviderUsesSingletonLifetime;
|
|
30
32
|
private resolveEagerProvider;
|
|
31
|
-
private callProviderInitAsync;
|
|
32
|
-
private callProviderPostInitAsync;
|
|
33
33
|
private sortEagerProviderRefs;
|
|
34
34
|
private getProviderInitAfter;
|
|
35
35
|
private sortEagerProviderIds;
|