awilixify 3.3.0 → 3.5.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.js +6 -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 +30 -18
- package/dist/lib/di/contexts/di-context-async.js +4 -31
- 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/errors.d.ts +18 -0
- package/dist/lib/di/errors.js +36 -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 +5 -1
- package/dist/lib/di/processors/interceptor-processor.js +59 -69
- 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/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 +4 -2
- package/dist/lib/di/type-guards.d.ts +1 -0
- package/dist/lib/extension-api/index.d.ts +1 -0
- package/dist/lib/extension-api/index.js +1 -0
- package/dist/lib/http/exceptions.d.ts +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +18 -9
|
@@ -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 "../../../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
|
-
|
|
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
|
-
|
|
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>[];
|
|
@@ -4,6 +4,7 @@ import type { ForwardRef } from "./modules/module-ref.types.js";
|
|
|
4
4
|
import type { FactoryProvider, FunctionProvider, PrimitiveProvider } from "./providers/provider.types.js";
|
|
5
5
|
export declare function hasUseClass<T extends object = object>(value: unknown): value is {
|
|
6
6
|
useClass: Constructor<T>;
|
|
7
|
+
injectInquirer?: boolean;
|
|
7
8
|
allowCircular?: boolean;
|
|
8
9
|
eager?: boolean;
|
|
9
10
|
initAfter?: readonly string[];
|
|
@@ -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";
|
|
@@ -25,8 +25,8 @@ export declare enum HttpStatus {
|
|
|
25
25
|
export declare class HttpException<TMessage extends string, TStatus extends HttpStatus = HttpStatus> extends Error {
|
|
26
26
|
readonly message: TMessage;
|
|
27
27
|
readonly statusCode: TStatus;
|
|
28
|
-
readonly response?:
|
|
29
|
-
constructor(message: TMessage, statusCode: TStatus, response?:
|
|
28
|
+
readonly response?: Record<string, any> | null | undefined;
|
|
29
|
+
constructor(message: TMessage, statusCode: TStatus, response?: Record<string, any> | null | undefined);
|
|
30
30
|
getResponse(): {
|
|
31
31
|
message: TMessage;
|
|
32
32
|
statusCode: TStatus;
|