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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Awilix from "awilix";
|
|
2
2
|
import * as ERRORS from "../errors.js";
|
|
3
|
+
import { InitHook, ShutdownHook } from "../lifecycle-hooks.js";
|
|
3
4
|
import * as GUARGS from "../type-guards.js";
|
|
4
5
|
export class LifecycleProcessor {
|
|
5
6
|
providerOptions;
|
|
@@ -7,7 +8,8 @@ export class LifecycleProcessor {
|
|
|
7
8
|
initializerTasks = [];
|
|
8
9
|
createdScopes = [];
|
|
9
10
|
initPromise;
|
|
10
|
-
|
|
11
|
+
closePromise;
|
|
12
|
+
shutdownListeners = new Map();
|
|
11
13
|
constructor(providerOptions) {
|
|
12
14
|
this.providerOptions = providerOptions;
|
|
13
15
|
}
|
|
@@ -32,54 +34,100 @@ export class LifecycleProcessor {
|
|
|
32
34
|
this.initPromise ??= this.executeInit(options);
|
|
33
35
|
return this.initPromise;
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
|
|
37
|
+
close() {
|
|
38
|
+
this.closePromise ??= this.executeClose().finally(() => {
|
|
39
|
+
for (const [signal, listener] of this.shutdownListeners) {
|
|
40
|
+
process.off(signal, listener);
|
|
41
|
+
}
|
|
42
|
+
this.shutdownListeners.clear();
|
|
43
|
+
});
|
|
44
|
+
return this.closePromise;
|
|
45
|
+
}
|
|
46
|
+
enableShutdownHooks() {
|
|
47
|
+
if (this.closePromise || this.shutdownListeners.size > 0)
|
|
48
|
+
return;
|
|
49
|
+
let shutdownSignalReceived = false;
|
|
50
|
+
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
51
|
+
const listener = async () => {
|
|
52
|
+
if (shutdownSignalReceived)
|
|
53
|
+
return;
|
|
54
|
+
shutdownSignalReceived = true;
|
|
55
|
+
try {
|
|
56
|
+
await this.close();
|
|
57
|
+
process.kill(process.pid, signal);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error("Application shutdown failed", error);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
this.shutdownListeners.set(signal, listener);
|
|
65
|
+
process.on(signal, listener);
|
|
66
|
+
}
|
|
38
67
|
}
|
|
39
68
|
async executeInit(options) {
|
|
40
69
|
const initializedProviders = [];
|
|
41
70
|
for (const { module, scope, key } of this.sortEagerProviderRefs()) {
|
|
42
|
-
this.ensureEagerProviderUsesSingletonLifetime(module, scope, key);
|
|
43
71
|
const instance = await this.resolveEagerProvider({
|
|
44
72
|
module,
|
|
45
73
|
scope,
|
|
46
74
|
key,
|
|
47
75
|
});
|
|
48
76
|
initializedProviders.push({ module, scope, key, instance });
|
|
49
|
-
|
|
77
|
+
if (!GUARGS.hasProviderOnInit(instance))
|
|
78
|
+
continue;
|
|
79
|
+
await instance[InitHook.OnInit]();
|
|
50
80
|
}
|
|
51
81
|
for (const initialize of this.initializerTasks) {
|
|
52
82
|
await initialize(options);
|
|
53
83
|
}
|
|
54
84
|
for (const { key, instance } of initializedProviders) {
|
|
55
|
-
if (this.
|
|
85
|
+
if (this.shouldSkipProviderAfterInit(key, options))
|
|
56
86
|
continue;
|
|
57
|
-
|
|
87
|
+
if (!GUARGS.hasProviderAfterInit(instance))
|
|
88
|
+
continue;
|
|
89
|
+
await instance[InitHook.AfterInit]();
|
|
58
90
|
}
|
|
59
91
|
}
|
|
60
|
-
async
|
|
92
|
+
async executeClose() {
|
|
93
|
+
await this.initPromise?.catch(() => { });
|
|
94
|
+
const errors = [];
|
|
95
|
+
const providers = [
|
|
96
|
+
...new Set(this.createdScopes.flatMap((scope) => [...scope.cache.values()]
|
|
97
|
+
.filter((el) => el.resolver.lifetime === Awilix.Lifetime.SINGLETON)
|
|
98
|
+
.map(({ value }) => value))),
|
|
99
|
+
];
|
|
100
|
+
for (const hook of Object.values(ShutdownHook)) {
|
|
101
|
+
const results = await Promise.allSettled(providers
|
|
102
|
+
.filter((instance) => GUARGS.hasProviderShutdownHook(instance, hook))
|
|
103
|
+
.map(async (instance) => instance[hook]()));
|
|
104
|
+
for (const result of results) {
|
|
105
|
+
if (result.status === "rejected")
|
|
106
|
+
errors.push(result.reason);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
61
109
|
const uniqueScopes = Array.from(new Set(this.createdScopes)).reverse();
|
|
62
110
|
for (const scope of uniqueScopes) {
|
|
63
|
-
await scope.dispose()
|
|
111
|
+
await scope.dispose().catch((error) => {
|
|
112
|
+
errors.push(error);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (errors.length > 0) {
|
|
116
|
+
throw new AggregateError(errors, "Application shutdown failed");
|
|
64
117
|
}
|
|
65
118
|
}
|
|
66
|
-
|
|
67
|
-
if (options?.
|
|
119
|
+
shouldSkipProviderAfterInit(key, options) {
|
|
120
|
+
if (options?.excludeAfterInit === true)
|
|
68
121
|
return true;
|
|
69
|
-
if (!Array.isArray(options?.
|
|
122
|
+
if (!Array.isArray(options?.excludeAfterInit))
|
|
70
123
|
return false;
|
|
71
|
-
return new Set(options.
|
|
124
|
+
return new Set(options.excludeAfterInit).has(key);
|
|
72
125
|
}
|
|
73
126
|
getEagerProviderKeys(m) {
|
|
74
127
|
return Object.entries(m.providers || {})
|
|
75
128
|
.filter(([, provider]) => GUARGS.isEagerProvider(provider))
|
|
76
129
|
.map(([key]) => key);
|
|
77
130
|
}
|
|
78
|
-
ensureEagerProviderUsesSingletonLifetime(m, scope, key) {
|
|
79
|
-
if (scope.registrations[key]?.lifetime !== Awilix.Lifetime.SINGLETON) {
|
|
80
|
-
throw new ERRORS.EagerProviderRequiresSingletonLifetimeError(m.name, key);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
131
|
async resolveEagerProvider({ module, scope, key, }) {
|
|
84
132
|
const provider = module.providers?.[key];
|
|
85
133
|
if (!provider ||
|
|
@@ -100,16 +148,6 @@ export class LifecycleProcessor {
|
|
|
100
148
|
});
|
|
101
149
|
return scope.resolve(key);
|
|
102
150
|
}
|
|
103
|
-
async callProviderInitAsync(instance) {
|
|
104
|
-
if (!GUARGS.hasProviderInit(instance))
|
|
105
|
-
return;
|
|
106
|
-
await instance.init();
|
|
107
|
-
}
|
|
108
|
-
async callProviderPostInitAsync(instance) {
|
|
109
|
-
if (!GUARGS.hasProviderPostInit(instance))
|
|
110
|
-
return;
|
|
111
|
-
await instance.postInit();
|
|
112
|
-
}
|
|
113
151
|
sortEagerProviderRefs() {
|
|
114
152
|
const nodes = this.eagerProviderRefs.map((ref) => ({
|
|
115
153
|
...ref,
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
4
|
+
interface ConstructorInterceptor {
|
|
5
5
|
new (...args: any[]): Interceptor;
|
|
6
6
|
}
|
|
7
|
-
|
|
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 {
|
|
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,6 +1,8 @@
|
|
|
1
1
|
import type { BuildResolverOptions, Constructor } from "awilix";
|
|
2
|
+
import { InitHook, ShutdownHook } from "../../lifecycle-hooks.js";
|
|
3
|
+
export type InquirerContext = object | undefined;
|
|
2
4
|
export type DefProviderMap = Record<string, object | string | boolean | number>;
|
|
3
|
-
|
|
5
|
+
type ConstructorProvider<T extends object = object> = Constructor<T>;
|
|
4
6
|
export type PrimitiveProvider = string | number | boolean | symbol | bigint;
|
|
5
7
|
export type FunctionProvider = (...args: any[]) => any;
|
|
6
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>> = {
|
|
@@ -9,14 +11,24 @@ export type FactoryProvider<T extends object, DepsMap extends Record<string, unk
|
|
|
9
11
|
eager?: boolean;
|
|
10
12
|
useFactory: Strict extends true ? (...args: MapKeysToValues<DepsMap, Keys>) => T | Promise<T> : (...args: any[]) => T | Promise<T>;
|
|
11
13
|
} & ResolverOptions;
|
|
12
|
-
|
|
14
|
+
type ClassProvider<T extends object, DepsMap extends Record<string, unknown> = Record<string, unknown>, ResolverOptions extends object = BuildResolverOptions<T>> = {
|
|
13
15
|
useClass: Constructor<T>;
|
|
16
|
+
injectInquirer?: boolean;
|
|
14
17
|
allowCircular?: boolean;
|
|
15
18
|
eager?: boolean;
|
|
16
19
|
initAfter?: readonly Extract<keyof DepsMap, string>[];
|
|
17
20
|
} & ResolverOptions;
|
|
18
|
-
export interface
|
|
19
|
-
|
|
21
|
+
export interface OnInit {
|
|
22
|
+
[InitHook.OnInit](): void | Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export interface AfterInit {
|
|
25
|
+
[InitHook.AfterInit](): void | Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export interface BeforeShutdown {
|
|
28
|
+
[ShutdownHook.BeforeShutdown](): void | Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export interface OnShutdown {
|
|
31
|
+
[ShutdownHook.OnShutdown](): void | Promise<void>;
|
|
20
32
|
}
|
|
21
33
|
export type Provider<T extends object, DepsMap extends Record<string, unknown> = Record<string, unknown>, ResolverOptions extends object = BuildResolverOptions<T>> = FactoryProvider<T, DepsMap, readonly Extract<keyof DepsMap, string>[], false> | ClassProvider<T, DepsMap, ResolverOptions> | ConstructorProvider<T>;
|
|
22
34
|
export type AnyProvider = FactoryProvider<any, any, readonly string[], false> | ClassProvider<any> | ConstructorProvider<any> | PrimitiveProvider | FunctionProvider | object;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import { InitHook, ShutdownHook } from "../../lifecycle-hooks.js";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { BuildResolverOptions, Constructor } from "awilix";
|
|
2
|
+
import { InitHook, type ShutdownHook } from "./lifecycle-hooks.js";
|
|
2
3
|
import type { ForwardRef } from "./modules/module-ref.types.js";
|
|
3
4
|
import type { FactoryProvider, FunctionProvider, PrimitiveProvider } from "./providers/provider.types.js";
|
|
4
5
|
export declare function hasUseClass<T extends object = object>(value: unknown): value is {
|
|
5
6
|
useClass: Constructor<T>;
|
|
7
|
+
injectInquirer?: boolean;
|
|
6
8
|
allowCircular?: boolean;
|
|
7
9
|
eager?: boolean;
|
|
8
10
|
initAfter?: readonly string[];
|
|
@@ -17,12 +19,13 @@ export declare function isPromiseLike<T = unknown>(value: unknown): value is Pro
|
|
|
17
19
|
export declare function isEagerProvider(provider: unknown): provider is {
|
|
18
20
|
eager: true;
|
|
19
21
|
};
|
|
20
|
-
export declare function
|
|
21
|
-
|
|
22
|
+
export declare function hasProviderOnInit(value: unknown): value is {
|
|
23
|
+
[InitHook.OnInit]: () => void | Promise<void>;
|
|
22
24
|
};
|
|
23
|
-
export declare function
|
|
24
|
-
|
|
25
|
+
export declare function hasProviderAfterInit(value: unknown): value is {
|
|
26
|
+
[InitHook.AfterInit]: () => void | Promise<void>;
|
|
25
27
|
};
|
|
28
|
+
export declare function hasProviderShutdownHook<K extends ShutdownHook>(value: unknown, hook: K): value is Record<K, () => void | Promise<void>>;
|
|
26
29
|
export declare function hasInitAfter(provider: unknown): provider is {
|
|
27
30
|
initAfter: readonly string[];
|
|
28
31
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InitHook } from "./lifecycle-hooks.js";
|
|
1
2
|
export function hasUseClass(value) {
|
|
2
3
|
return typeof value === "object" && value !== null && "useClass" in value;
|
|
3
4
|
}
|
|
@@ -56,17 +57,23 @@ export function isEagerProvider(provider) {
|
|
|
56
57
|
"eager" in provider &&
|
|
57
58
|
provider.eager === true);
|
|
58
59
|
}
|
|
59
|
-
export function
|
|
60
|
+
export function hasProviderOnInit(value) {
|
|
60
61
|
return (typeof value === "object" &&
|
|
61
62
|
value !== null &&
|
|
62
|
-
|
|
63
|
-
typeof value.
|
|
63
|
+
InitHook.OnInit in value &&
|
|
64
|
+
typeof value[InitHook.OnInit] === "function");
|
|
64
65
|
}
|
|
65
|
-
export function
|
|
66
|
+
export function hasProviderAfterInit(value) {
|
|
66
67
|
return (typeof value === "object" &&
|
|
67
68
|
value !== null &&
|
|
68
|
-
|
|
69
|
-
typeof value.
|
|
69
|
+
InitHook.AfterInit in value &&
|
|
70
|
+
typeof value[InitHook.AfterInit] === "function");
|
|
71
|
+
}
|
|
72
|
+
export function hasProviderShutdownHook(value, hook) {
|
|
73
|
+
return (typeof value === "object" &&
|
|
74
|
+
value !== null &&
|
|
75
|
+
hook in value &&
|
|
76
|
+
typeof value[hook] === "function");
|
|
70
77
|
}
|
|
71
78
|
export function hasInitAfter(provider) {
|
|
72
79
|
return (typeof provider === "object" &&
|
|
@@ -3,5 +3,6 @@ export { ContainerContextBase, type ContainerContextOptions, type ModuleScope, t
|
|
|
3
3
|
export type { ModuleImport } from "../di/modules/module.types.js";
|
|
4
4
|
export type { GlobalDependencies, NormalizeGlobalDependencies, } from "../di/modules/module-def.types.js";
|
|
5
5
|
export type { InternalModuleLike as RuntimeModuleLike } from "../di/modules/runtime-module.types.js";
|
|
6
|
+
export { InquirerResolverFactory } from "../di/providers/inquirer-resolver-factory.js";
|
|
6
7
|
export type { DefProviderMap, Provider, } from "../di/providers/provider.types.js";
|
|
7
8
|
export { ProviderResolver } from "../di/providers/provider-resolver.js";
|