@navios/di 0.2.0 → 0.3.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 +301 -39
- package/docs/README.md +122 -49
- package/docs/api-reference.md +763 -0
- package/docs/container.md +274 -0
- package/docs/examples/basic-usage.mts +97 -0
- package/docs/examples/factory-pattern.mts +318 -0
- package/docs/examples/injection-tokens.mts +225 -0
- package/docs/examples/request-scope-example.mts +254 -0
- package/docs/examples/service-lifecycle.mts +359 -0
- package/docs/factory.md +584 -0
- package/docs/getting-started.md +308 -0
- package/docs/injectable.md +496 -0
- package/docs/injection-tokens.md +400 -0
- package/docs/lifecycle.md +539 -0
- package/docs/scopes.md +749 -0
- package/lib/_tsup-dts-rollup.d.mts +495 -150
- package/lib/_tsup-dts-rollup.d.ts +495 -150
- package/lib/index.d.mts +26 -12
- package/lib/index.d.ts +26 -12
- package/lib/index.js +993 -462
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +983 -453
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
- package/project.json +10 -2
- package/src/__tests__/container.spec.mts +1301 -0
- package/src/__tests__/factory.spec.mts +137 -0
- package/src/__tests__/injectable.spec.mts +32 -88
- package/src/__tests__/injection-token.spec.mts +333 -17
- package/src/__tests__/request-scope.spec.mts +263 -0
- package/src/__type-tests__/factory.spec-d.mts +65 -0
- package/src/__type-tests__/inject.spec-d.mts +27 -28
- package/src/__type-tests__/injectable.spec-d.mts +42 -206
- package/src/container.mts +167 -0
- package/src/decorators/factory.decorator.mts +79 -0
- package/src/decorators/index.mts +1 -0
- package/src/decorators/injectable.decorator.mts +6 -56
- package/src/enums/injectable-scope.enum.mts +5 -1
- package/src/event-emitter.mts +18 -20
- package/src/factory-context.mts +2 -10
- package/src/index.mts +3 -2
- package/src/injection-token.mts +24 -9
- package/src/injector.mts +8 -20
- package/src/interfaces/factory.interface.mts +3 -3
- package/src/interfaces/index.mts +2 -0
- package/src/interfaces/on-service-destroy.interface.mts +3 -0
- package/src/interfaces/on-service-init.interface.mts +3 -0
- package/src/registry.mts +7 -16
- package/src/request-context-holder.mts +145 -0
- package/src/service-instantiator.mts +158 -0
- package/src/service-locator-event-bus.mts +0 -28
- package/src/service-locator-instance-holder.mts +27 -16
- package/src/service-locator-manager.mts +84 -0
- package/src/service-locator.mts +550 -395
- package/src/utils/defer.mts +73 -0
- package/src/utils/get-injectors.mts +93 -80
- package/src/utils/index.mts +2 -0
- package/src/utils/types.mts +52 -0
- package/docs/concepts/injectable.md +0 -182
- package/docs/concepts/injection-token.md +0 -145
- package/src/proxy-service-locator.mts +0 -83
- package/src/resolve-service.mts +0 -41
|
@@ -4,7 +4,15 @@ import type { ZodOptional } from 'zod/v4';
|
|
|
4
4
|
import type { ZodRecord } from 'zod/v4';
|
|
5
5
|
import type { ZodType } from 'zod/v4';
|
|
6
6
|
|
|
7
|
-
declare type
|
|
7
|
+
declare type AnyInjectableType = ClassType | InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
8
|
+
export { AnyInjectableType }
|
|
9
|
+
export { AnyInjectableType as AnyInjectableType_alias_1 }
|
|
10
|
+
|
|
11
|
+
declare const asyncInject: Injectors['asyncInject'];
|
|
12
|
+
export { asyncInject }
|
|
13
|
+
export { asyncInject as asyncInject_alias_1 }
|
|
14
|
+
|
|
15
|
+
declare type BaseInjectionTokenSchemaType = ZodObject | ZodRecord;
|
|
8
16
|
export { BaseInjectionTokenSchemaType }
|
|
9
17
|
export { BaseInjectionTokenSchemaType as BaseInjectionTokenSchemaType_alias_1 }
|
|
10
18
|
|
|
@@ -50,12 +58,144 @@ declare type ClassTypeWithOptionalArgument<Arg> = new (arg?: Arg) => any;
|
|
|
50
58
|
export { ClassTypeWithOptionalArgument }
|
|
51
59
|
export { ClassTypeWithOptionalArgument as ClassTypeWithOptionalArgument_alias_1 }
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Container class that provides a simplified public API for dependency injection.
|
|
63
|
+
* It wraps a ServiceLocator instance and provides convenient methods for getting instances.
|
|
64
|
+
*/
|
|
65
|
+
declare class Container {
|
|
66
|
+
private readonly serviceLocator;
|
|
67
|
+
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
68
|
+
private registerSelf;
|
|
69
|
+
/**
|
|
70
|
+
* Gets an instance from the container.
|
|
71
|
+
* This method has the same type signature as the inject method from get-injectors.mts
|
|
72
|
+
*/
|
|
73
|
+
get<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
74
|
+
get<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
75
|
+
get<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? Promise<T> : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
76
|
+
get<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
77
|
+
get<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
78
|
+
get<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the underlying ServiceLocator instance for advanced usage
|
|
81
|
+
*/
|
|
82
|
+
getServiceLocator(): ServiceLocator;
|
|
83
|
+
/**
|
|
84
|
+
* Invalidates a service and its dependencies
|
|
85
|
+
*/
|
|
86
|
+
invalidate(service: unknown): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Waits for all pending operations to complete
|
|
89
|
+
*/
|
|
90
|
+
ready(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Begins a new request context with the given parameters.
|
|
93
|
+
* @param requestId Unique identifier for this request
|
|
94
|
+
* @param metadata Optional metadata for the request
|
|
95
|
+
* @param priority Priority for resolution (higher = more priority)
|
|
96
|
+
* @returns The created request context holder
|
|
97
|
+
*/
|
|
98
|
+
beginRequest(requestId: string, metadata?: Record<string, any>, priority?: number): RequestContextHolder;
|
|
99
|
+
/**
|
|
100
|
+
* Ends a request context and cleans up all associated instances.
|
|
101
|
+
* @param requestId The request ID to end
|
|
102
|
+
*/
|
|
103
|
+
endRequest(requestId: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Gets the current request context.
|
|
106
|
+
* @returns The current request context holder or null
|
|
107
|
+
*/
|
|
108
|
+
getCurrentRequestContext(): RequestContextHolder | null;
|
|
109
|
+
/**
|
|
110
|
+
* Sets the current request context.
|
|
111
|
+
* @param requestId The request ID to set as current
|
|
112
|
+
*/
|
|
113
|
+
setCurrentRequestContext(requestId: string): void;
|
|
114
|
+
}
|
|
115
|
+
export { Container }
|
|
116
|
+
export { Container as Container_alias_1 }
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates a new deferred promise.
|
|
120
|
+
* @returns A new Deferred instance
|
|
121
|
+
*/
|
|
122
|
+
declare function createDeferred<T>(): Deferred<T>;
|
|
123
|
+
export { createDeferred }
|
|
124
|
+
export { createDeferred as createDeferred_alias_1 }
|
|
125
|
+
export { createDeferred as createDeferred_alias_2 }
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new request context holder with the given parameters.
|
|
129
|
+
*/
|
|
130
|
+
declare function createRequestContextHolder(requestId: string, priority?: number, initialMetadata?: Record<string, any>): RequestContextHolder;
|
|
131
|
+
export { createRequestContextHolder }
|
|
132
|
+
export { createRequestContextHolder as createRequestContextHolder_alias_1 }
|
|
133
|
+
|
|
134
|
+
declare const defaultInjectors: Injectors;
|
|
135
|
+
export { defaultInjectors }
|
|
136
|
+
export { defaultInjectors as defaultInjectors_alias_1 }
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Default implementation of RequestContextHolder.
|
|
140
|
+
*/
|
|
141
|
+
declare class DefaultRequestContextHolder implements RequestContextHolder {
|
|
142
|
+
readonly requestId: string;
|
|
143
|
+
readonly priority: number;
|
|
144
|
+
readonly instances: Map<string, any>;
|
|
145
|
+
readonly holders: Map<string, ServiceLocatorInstanceHolder>;
|
|
146
|
+
readonly metadata: Map<string, any>;
|
|
147
|
+
readonly createdAt: number;
|
|
148
|
+
constructor(requestId: string, priority?: number, initialMetadata?: Record<string, any>);
|
|
149
|
+
addInstance(instanceName: string, instance: any, holder: ServiceLocatorInstanceHolder): void;
|
|
150
|
+
getInstance(instanceName: string): any | undefined;
|
|
151
|
+
getHolder(instanceName: string): ServiceLocatorInstanceHolder | undefined;
|
|
152
|
+
hasInstance(instanceName: string): boolean;
|
|
153
|
+
clear(): void;
|
|
154
|
+
getMetadata(key: string): any | undefined;
|
|
155
|
+
setMetadata(key: string, value: any): void;
|
|
55
156
|
}
|
|
56
|
-
export {
|
|
57
|
-
export {
|
|
58
|
-
|
|
157
|
+
export { DefaultRequestContextHolder }
|
|
158
|
+
export { DefaultRequestContextHolder as DefaultRequestContextHolder_alias_1 }
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Creates a deferred promise that can be resolved or rejected externally.
|
|
162
|
+
* This is useful for creating stub holders that can be fulfilled later.
|
|
163
|
+
*/
|
|
164
|
+
declare class Deferred<T> {
|
|
165
|
+
readonly promise: Promise<T>;
|
|
166
|
+
private _resolve;
|
|
167
|
+
private _reject;
|
|
168
|
+
private _isResolved;
|
|
169
|
+
private _isRejected;
|
|
170
|
+
constructor();
|
|
171
|
+
/**
|
|
172
|
+
* Resolves the deferred promise with the given value.
|
|
173
|
+
* @param value The value to resolve with
|
|
174
|
+
* @throws Error if the promise has already been resolved or rejected
|
|
175
|
+
*/
|
|
176
|
+
resolve(value: T): void;
|
|
177
|
+
/**
|
|
178
|
+
* Rejects the deferred promise with the given reason.
|
|
179
|
+
* @param reason The reason for rejection
|
|
180
|
+
* @throws Error if the promise has already been resolved or rejected
|
|
181
|
+
*/
|
|
182
|
+
reject(reason?: any): void;
|
|
183
|
+
/**
|
|
184
|
+
* Returns true if the promise has been resolved.
|
|
185
|
+
*/
|
|
186
|
+
get isResolved(): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Returns true if the promise has been rejected.
|
|
189
|
+
*/
|
|
190
|
+
get isRejected(): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Returns true if the promise has been settled (resolved or rejected).
|
|
193
|
+
*/
|
|
194
|
+
get isSettled(): boolean;
|
|
195
|
+
}
|
|
196
|
+
export { Deferred }
|
|
197
|
+
export { Deferred as Deferred_alias_1 }
|
|
198
|
+
export { Deferred as Deferred_alias_2 }
|
|
59
199
|
|
|
60
200
|
declare enum ErrorsEnum {
|
|
61
201
|
InstanceExpired = "InstanceExpired",
|
|
@@ -75,7 +215,6 @@ declare class EventEmitter<Events extends EventsConfig = {}> implements EventEmi
|
|
|
75
215
|
off<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): void;
|
|
76
216
|
once<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): () => void;
|
|
77
217
|
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): Promise<any>;
|
|
78
|
-
addChannel<E extends EventsNames<Events>, Ns extends string, Emitter extends ChannelEmitter<Events, Ns, E>>(ns: Ns, event: E, target: Emitter): () => void;
|
|
79
218
|
}
|
|
80
219
|
export { EventEmitter }
|
|
81
220
|
export { EventEmitter as EventEmitter_alias_1 }
|
|
@@ -83,7 +222,6 @@ export { EventEmitter as EventEmitter_alias_1 }
|
|
|
83
222
|
declare interface EventEmitterInterface<Events extends EventsConfig> {
|
|
84
223
|
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): () => void;
|
|
85
224
|
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): void;
|
|
86
|
-
addChannel<E extends EventsNames<Events>, Ns extends string, Emmiter extends ChannelEmitter<Events, Ns, E>>(ns: Ns, event: E, target: Emmiter): () => void;
|
|
87
225
|
}
|
|
88
226
|
export { EventEmitterInterface }
|
|
89
227
|
export { EventEmitterInterface as EventEmitterInterface_alias_1 }
|
|
@@ -102,37 +240,54 @@ declare type EventsNames<Events extends EventsConfig> = Exclude<keyof Events, sy
|
|
|
102
240
|
export { EventsNames }
|
|
103
241
|
export { EventsNames as EventsNames_alias_1 }
|
|
104
242
|
|
|
105
|
-
declare interface
|
|
243
|
+
declare interface Factorable<T> {
|
|
106
244
|
create(ctx?: FactoryContext): Promise<T> | T;
|
|
107
245
|
}
|
|
246
|
+
export { Factorable }
|
|
247
|
+
export { Factorable as Factorable_alias_1 }
|
|
248
|
+
export { Factorable as Factorable_alias_2 }
|
|
249
|
+
|
|
250
|
+
declare interface FactorableWithArgs<T, A extends InjectionTokenSchemaType> {
|
|
251
|
+
create(ctx?: FactoryContext, ...args: [z.output<A>]): Promise<T> | T;
|
|
252
|
+
}
|
|
253
|
+
export { FactorableWithArgs }
|
|
254
|
+
export { FactorableWithArgs as FactorableWithArgs_alias_1 }
|
|
255
|
+
export { FactorableWithArgs as FactorableWithArgs_alias_2 }
|
|
256
|
+
|
|
257
|
+
declare function Factory<R>(options?: {
|
|
258
|
+
scope?: InjectableScope;
|
|
259
|
+
registry?: Registry;
|
|
260
|
+
}): <T extends ClassTypeWithInstance<Factorable<R>>>(target: T, context?: ClassDecoratorContext) => T;
|
|
261
|
+
|
|
262
|
+
declare function Factory<R, S>(options: {
|
|
263
|
+
scope?: InjectableScope;
|
|
264
|
+
token: InjectionToken<R, S>;
|
|
265
|
+
registry?: Registry;
|
|
266
|
+
}): R extends undefined ? never : S extends InjectionTokenSchemaType ? <T extends ClassTypeWithInstance<FactorableWithArgs<R, S>>>(// #2.2.1 Token have a schema
|
|
267
|
+
target: T, context?: ClassDecoratorContext) => T : S extends undefined ? <T extends ClassTypeWithInstance<Factorable<R>>>(// #2.3.1 Token without a schema
|
|
268
|
+
target: T, context?: ClassDecoratorContext) => T : never;
|
|
108
269
|
export { Factory }
|
|
109
270
|
export { Factory as Factory_alias_1 }
|
|
110
271
|
export { Factory as Factory_alias_2 }
|
|
111
272
|
|
|
112
273
|
declare interface FactoryContext {
|
|
113
|
-
inject: Injectors['
|
|
114
|
-
on: ServiceLocatorEventBus['on'];
|
|
115
|
-
getDependencies: () => string[];
|
|
116
|
-
invalidate: () => void;
|
|
117
|
-
addEffect: (listener: () => void) => void;
|
|
118
|
-
getDestroyListeners: () => (() => void)[];
|
|
119
|
-
setTtl: (ttl: number) => void;
|
|
120
|
-
getTtl: () => number;
|
|
274
|
+
inject: Injectors['asyncInject'];
|
|
121
275
|
locator: ServiceLocator;
|
|
276
|
+
addDestroyListener: (listener: () => void) => void;
|
|
122
277
|
}
|
|
123
278
|
export { FactoryContext }
|
|
124
279
|
export { FactoryContext as FactoryContext_alias_1 }
|
|
125
280
|
|
|
126
281
|
declare class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
127
282
|
readonly token: InjectionToken<T, S>;
|
|
128
|
-
readonly factory: () => Promise<z.input<S>>;
|
|
283
|
+
readonly factory: (ctx: FactoryContext) => Promise<z.input<S>>;
|
|
129
284
|
value?: z.input<S>;
|
|
130
285
|
resolved: boolean;
|
|
131
286
|
id: string;
|
|
132
287
|
name: string | symbol | ClassType;
|
|
133
288
|
schema: InjectionTokenSchemaType;
|
|
134
|
-
constructor(token: InjectionToken<T, S>, factory: () => Promise<z.input<S>>);
|
|
135
|
-
resolve(): Promise<z.input<S>>;
|
|
289
|
+
constructor(token: InjectionToken<T, S>, factory: (ctx: FactoryContext) => Promise<z.input<S>>);
|
|
290
|
+
resolve(ctx: FactoryContext): Promise<z.input<S>>;
|
|
136
291
|
toString(): string;
|
|
137
292
|
}
|
|
138
293
|
export { FactoryInjectionToken }
|
|
@@ -147,10 +302,20 @@ export { FactoryNotFound }
|
|
|
147
302
|
export { FactoryNotFound as FactoryNotFound_alias_1 }
|
|
148
303
|
export { FactoryNotFound as FactoryNotFound_alias_2 }
|
|
149
304
|
|
|
305
|
+
declare interface FactoryOptions {
|
|
306
|
+
scope?: InjectableScope;
|
|
307
|
+
token?: InjectionToken<any, any>;
|
|
308
|
+
registry?: Registry;
|
|
309
|
+
}
|
|
310
|
+
export { FactoryOptions }
|
|
311
|
+
export { FactoryOptions as FactoryOptions_alias_1 }
|
|
312
|
+
export { FactoryOptions as FactoryOptions_alias_2 }
|
|
313
|
+
|
|
150
314
|
declare type FactoryRecord<Instance = any, Schema = any> = {
|
|
151
315
|
scope: InjectableScope;
|
|
152
316
|
originalToken: InjectionToken<Instance, Schema>;
|
|
153
|
-
|
|
317
|
+
target: ClassType;
|
|
318
|
+
type: InjectableType;
|
|
154
319
|
};
|
|
155
320
|
export { FactoryRecord }
|
|
156
321
|
export { FactoryRecord as FactoryRecord_alias_1 }
|
|
@@ -163,17 +328,6 @@ export { FactoryTokenNotResolved }
|
|
|
163
328
|
export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_1 }
|
|
164
329
|
export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_2 }
|
|
165
330
|
|
|
166
|
-
declare interface FactoryWithArgs<T, A extends InjectionTokenSchemaType> {
|
|
167
|
-
create(...args: [FactoryContext, z.output<A>]): Promise<T> | T;
|
|
168
|
-
}
|
|
169
|
-
export { FactoryWithArgs }
|
|
170
|
-
export { FactoryWithArgs as FactoryWithArgs_alias_1 }
|
|
171
|
-
export { FactoryWithArgs as FactoryWithArgs_alias_2 }
|
|
172
|
-
|
|
173
|
-
declare function getGlobalServiceLocator(): ServiceLocator;
|
|
174
|
-
export { getGlobalServiceLocator }
|
|
175
|
-
export { getGlobalServiceLocator as getGlobalServiceLocator_alias_1 }
|
|
176
|
-
|
|
177
331
|
declare function getInjectableToken<R>(target: ClassType): R extends {
|
|
178
332
|
create(...args: any[]): infer V;
|
|
179
333
|
} ? InjectionToken<V> : InjectionToken<R>;
|
|
@@ -181,7 +335,7 @@ export { getInjectableToken }
|
|
|
181
335
|
export { getInjectableToken as getInjectableToken_alias_1 }
|
|
182
336
|
export { getInjectableToken as getInjectableToken_alias_2 }
|
|
183
337
|
|
|
184
|
-
declare function getInjectors(
|
|
338
|
+
declare function getInjectors(): Injectors;
|
|
185
339
|
export { getInjectors }
|
|
186
340
|
export { getInjectors as getInjectors_alias_1 }
|
|
187
341
|
export { getInjectors as getInjectors_alias_2 }
|
|
@@ -197,18 +351,16 @@ export { inject as inject_alias_1 }
|
|
|
197
351
|
declare function Injectable(): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
|
|
198
352
|
|
|
199
353
|
declare function Injectable(options: {
|
|
354
|
+
scope?: InjectableScope;
|
|
200
355
|
registry: Registry;
|
|
201
356
|
}): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
|
|
202
357
|
|
|
203
|
-
declare function Injectable
|
|
204
|
-
scope
|
|
205
|
-
|
|
206
|
-
registry?: Registry;
|
|
207
|
-
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context?: ClassDecoratorContext) => T;
|
|
358
|
+
declare function Injectable(options: {
|
|
359
|
+
scope: InjectableScope;
|
|
360
|
+
}): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
|
|
208
361
|
|
|
209
362
|
declare function Injectable<Type, Schema>(options: {
|
|
210
363
|
scope?: InjectableScope;
|
|
211
|
-
type?: InjectableType.Class;
|
|
212
364
|
token: InjectionToken<Type, Schema>;
|
|
213
365
|
registry?: Registry;
|
|
214
366
|
}): Schema extends BaseInjectionTokenSchemaType ? Type extends undefined ? <T extends ClassTypeWithArgument<z.output<Schema>>>(// #3.1.1 Typeless token
|
|
@@ -216,22 +368,12 @@ target: T, context?: ClassDecoratorContext) => T : <T extends ClassTypeWithInsta
|
|
|
216
368
|
target: T, context?: ClassDecoratorContext) => T : Schema extends OptionalInjectionTokenSchemaType ? Type extends undefined ? <T extends ClassTypeWithOptionalArgument<z.output<Schema>>>(// #3.2.1 Typeless token
|
|
217
369
|
target: T, context?: ClassDecoratorContext) => T : <T extends ClassTypeWithInstanceAndOptionalArgument<Type, z.output<Schema>>>(target: T, context?: ClassDecoratorContext) => T : Schema extends undefined ? <R extends ClassTypeWithInstance<Type>>(// #3.3.1 Token must have a type
|
|
218
370
|
target: R, context?: ClassDecoratorContext) => R : never;
|
|
219
|
-
|
|
220
|
-
declare function Injectable<R, S>(options: {
|
|
221
|
-
scope?: InjectableScope;
|
|
222
|
-
type: InjectableType.Factory;
|
|
223
|
-
token: InjectionToken<R, S>;
|
|
224
|
-
registry?: Registry;
|
|
225
|
-
}): R extends undefined ? never : S extends InjectionTokenSchemaType ? <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(// #4.2.1 Token have a schema
|
|
226
|
-
target: T, context?: ClassDecoratorContext) => T : S extends undefined ? <T extends ClassTypeWithInstance<Factory<R>>>(// #4.3.1 Token without a schema
|
|
227
|
-
target: T, context?: ClassDecoratorContext) => T : never;
|
|
228
371
|
export { Injectable }
|
|
229
372
|
export { Injectable as Injectable_alias_1 }
|
|
230
373
|
export { Injectable as Injectable_alias_2 }
|
|
231
374
|
|
|
232
375
|
declare interface InjectableOptions {
|
|
233
376
|
scope?: InjectableScope;
|
|
234
|
-
type?: InjectableType;
|
|
235
377
|
token?: InjectionToken<any, any>;
|
|
236
378
|
registry?: Registry;
|
|
237
379
|
}
|
|
@@ -247,7 +389,11 @@ declare enum InjectableScope {
|
|
|
247
389
|
/**
|
|
248
390
|
* Instance scope: A new instance is created for each injection.
|
|
249
391
|
*/
|
|
250
|
-
|
|
392
|
+
Transient = "Transient",
|
|
393
|
+
/**
|
|
394
|
+
* Request scope: The instance is created once per request and shared within that request context.
|
|
395
|
+
*/
|
|
396
|
+
Request = "Request"
|
|
251
397
|
}
|
|
252
398
|
export { InjectableScope }
|
|
253
399
|
export { InjectableScope as InjectableScope_alias_1 }
|
|
@@ -266,22 +412,18 @@ export { InjectableType }
|
|
|
266
412
|
export { InjectableType as InjectableType_alias_1 }
|
|
267
413
|
export { InjectableType as InjectableType_alias_2 }
|
|
268
414
|
|
|
269
|
-
declare
|
|
270
|
-
export { InjectionFactory }
|
|
271
|
-
export { InjectionFactory as InjectionFactory_alias_1 }
|
|
272
|
-
|
|
273
|
-
declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown, Required extends boolean = S extends ZodOptional<ZodObject<any>> ? false : S extends ZodOptional<ZodRecord> ? false : S extends ZodObject<any> ? true : S extends ZodRecord ? true : false> {
|
|
415
|
+
declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown, Required extends boolean = S extends ZodOptional<ZodObject> ? false : S extends ZodOptional<ZodRecord> ? false : S extends ZodObject ? true : S extends ZodRecord ? true : false> {
|
|
274
416
|
readonly name: string | symbol | ClassType;
|
|
275
|
-
readonly schema: ZodObject
|
|
417
|
+
readonly schema: ZodObject | undefined;
|
|
276
418
|
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
277
419
|
private formattedName;
|
|
278
|
-
constructor(name: string | symbol | ClassType, schema: ZodObject
|
|
420
|
+
constructor(name: string | symbol | ClassType, schema: ZodObject | undefined);
|
|
279
421
|
static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
|
|
280
422
|
static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): Schema['_def']['type'] extends 'ZodOptional' ? InjectionToken<InstanceType<T>, Schema, false> : InjectionToken<InstanceType<T>, Schema, true>;
|
|
281
423
|
static create<T>(name: string | symbol): InjectionToken<T, undefined>;
|
|
282
424
|
static create<T, Schema extends InjectionTokenSchemaType>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
|
|
283
425
|
static bound<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
|
|
284
|
-
static factory<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, factory: () => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
|
|
426
|
+
static factory<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, factory: (ctx: FactoryContext) => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
|
|
285
427
|
static refineType<T>(token: BoundInjectionToken<any, any>): BoundInjectionToken<T, any>;
|
|
286
428
|
toString(): string;
|
|
287
429
|
}
|
|
@@ -292,30 +434,41 @@ declare type InjectionTokenSchemaType = BaseInjectionTokenSchemaType | OptionalI
|
|
|
292
434
|
export { InjectionTokenSchemaType }
|
|
293
435
|
export { InjectionTokenSchemaType as InjectionTokenSchemaType_alias_1 }
|
|
294
436
|
|
|
437
|
+
declare type InjectionTokenType = InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
438
|
+
export { InjectionTokenType }
|
|
439
|
+
export { InjectionTokenType as InjectionTokenType_alias_1 }
|
|
440
|
+
|
|
295
441
|
declare interface Injectors {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
wrapSyncInit(cb: () => any): () => [any, Promise<any>[]];
|
|
309
|
-
|
|
442
|
+
asyncInject<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
443
|
+
asyncInject<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
444
|
+
asyncInject<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? Promise<T> : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
445
|
+
asyncInject<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
446
|
+
asyncInject<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
447
|
+
asyncInject<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
448
|
+
inject<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>;
|
|
449
|
+
inject<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T;
|
|
450
|
+
inject<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? T : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
|
|
451
|
+
inject<T>(token: InjectionToken<T, undefined>): T;
|
|
452
|
+
inject<T>(token: BoundInjectionToken<T, any>): T;
|
|
453
|
+
inject<T>(token: FactoryInjectionToken<T, any>): T;
|
|
454
|
+
wrapSyncInit(cb: () => any): (injectState?: InjectState) => [any, Promise<any>[], InjectState];
|
|
455
|
+
provideFactoryContext(context: FactoryContext | null): FactoryContext | null;
|
|
310
456
|
}
|
|
311
457
|
export { Injectors }
|
|
312
458
|
export { Injectors as Injectors_alias_1 }
|
|
313
459
|
export { Injectors as Injectors_alias_2 }
|
|
314
460
|
|
|
315
|
-
declare
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
461
|
+
declare interface InjectState {
|
|
462
|
+
currentIndex: number;
|
|
463
|
+
isFrozen: boolean;
|
|
464
|
+
requests: {
|
|
465
|
+
token: InjectionToken<any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any> | ClassType;
|
|
466
|
+
promise: Promise<any>;
|
|
467
|
+
}[];
|
|
468
|
+
}
|
|
469
|
+
export { InjectState }
|
|
470
|
+
export { InjectState as InjectState_alias_1 }
|
|
471
|
+
export { InjectState as InjectState_alias_2 }
|
|
319
472
|
|
|
320
473
|
declare class InstanceDestroying extends Error {
|
|
321
474
|
name: string;
|
|
@@ -345,37 +498,41 @@ export { InstanceNotFound as InstanceNotFound_alias_1 }
|
|
|
345
498
|
export { InstanceNotFound as InstanceNotFound_alias_2 }
|
|
346
499
|
|
|
347
500
|
declare type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
501
|
+
export { IsUnion }
|
|
502
|
+
export { IsUnion as IsUnion_alias_1 }
|
|
503
|
+
export { IsUnion as IsUnion_alias_2 }
|
|
348
504
|
|
|
349
505
|
declare type Join<TElements, TSeparator extends string> = TElements extends Readonly<[infer First, ...infer Rest]> ? Rest extends ReadonlyArray<string> ? First extends string ? `${First}${Rest extends [] ? '' : TSeparator}${Join<Rest, TSeparator>}` : never : never : '';
|
|
506
|
+
export { Join }
|
|
507
|
+
export { Join as Join_alias_1 }
|
|
508
|
+
export { Join as Join_alias_2 }
|
|
350
509
|
|
|
351
|
-
declare
|
|
352
|
-
|
|
353
|
-
|
|
510
|
+
declare interface OnServiceDestroy {
|
|
511
|
+
onServiceDestroy(): Promise<void> | void;
|
|
512
|
+
}
|
|
513
|
+
export { OnServiceDestroy }
|
|
514
|
+
export { OnServiceDestroy as OnServiceDestroy_alias_1 }
|
|
515
|
+
export { OnServiceDestroy as OnServiceDestroy_alias_2 }
|
|
516
|
+
|
|
517
|
+
declare interface OnServiceInit {
|
|
518
|
+
onServiceInit(): Promise<void> | void;
|
|
519
|
+
}
|
|
520
|
+
export { OnServiceInit }
|
|
521
|
+
export { OnServiceInit as OnServiceInit_alias_1 }
|
|
522
|
+
export { OnServiceInit as OnServiceInit_alias_2 }
|
|
354
523
|
|
|
355
|
-
declare type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject
|
|
524
|
+
declare type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject> | ZodOptional<ZodRecord>;
|
|
356
525
|
export { OptionalInjectionTokenSchemaType }
|
|
357
526
|
export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
|
|
358
527
|
|
|
359
528
|
declare type PopUnion<U> = UnionToOvlds<U> extends (a: infer A) => void ? A : never;
|
|
529
|
+
export { PopUnion }
|
|
530
|
+
export { PopUnion as PopUnion_alias_1 }
|
|
531
|
+
export { PopUnion as PopUnion_alias_2 }
|
|
360
532
|
|
|
361
|
-
declare const
|
|
362
|
-
export {
|
|
363
|
-
export {
|
|
364
|
-
|
|
365
|
-
declare class ProxyServiceLocator implements ServiceLocator {
|
|
366
|
-
private readonly serviceLocator;
|
|
367
|
-
private readonly ctx;
|
|
368
|
-
constructor(serviceLocator: ServiceLocator, ctx: FactoryContext);
|
|
369
|
-
getEventBus(): ServiceLocatorEventBus;
|
|
370
|
-
getInstance(token: InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args?: any): Promise<any[]>;
|
|
371
|
-
getOrThrowInstance<Instance, Schema extends ZodObject<any> | ZodOptional<ZodObject<any>> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject<any> ? z.input<Schema> : Schema extends ZodOptional<ZodObject<any>> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
|
|
372
|
-
getSyncInstance<Instance, Schema extends ZodObject<any> | ZodOptional<ZodObject<any>> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject<any> ? z.input<Schema> : Schema extends ZodOptional<ZodObject<any>> ? z.input<Schema> | undefined : undefined): Instance | null;
|
|
373
|
-
invalidate(service: string, round?: number): Promise<any>;
|
|
374
|
-
ready(): Promise<null>;
|
|
375
|
-
makeInstanceName(token: InjectionToken<any, any>, args: any): string;
|
|
376
|
-
}
|
|
377
|
-
export { ProxyServiceLocator }
|
|
378
|
-
export { ProxyServiceLocator as ProxyServiceLocator_alias_1 }
|
|
533
|
+
declare const provideFactoryContext: Injectors['provideFactoryContext'];
|
|
534
|
+
export { provideFactoryContext }
|
|
535
|
+
export { provideFactoryContext as provideFactoryContext_alias_1 }
|
|
379
536
|
|
|
380
537
|
declare class Registry {
|
|
381
538
|
private readonly parent?;
|
|
@@ -383,52 +540,188 @@ declare class Registry {
|
|
|
383
540
|
constructor(parent?: Registry | undefined);
|
|
384
541
|
has(token: InjectionToken<any, any>): boolean;
|
|
385
542
|
get<Instance, Schema>(token: InjectionToken<Instance, Schema>): FactoryRecord<Instance, Schema>;
|
|
386
|
-
set<Instance, Schema>(token: InjectionToken<Instance, Schema>,
|
|
543
|
+
set<Instance, Schema>(token: InjectionToken<Instance, Schema>, scope: InjectableScope, target: ClassType, type: InjectableType): void;
|
|
387
544
|
delete(token: InjectionToken<any, any>): void;
|
|
388
545
|
}
|
|
389
546
|
export { Registry }
|
|
390
547
|
export { Registry as Registry_alias_1 }
|
|
391
548
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
549
|
+
/**
|
|
550
|
+
* Request context holder that manages pre-prepared instances for a specific request.
|
|
551
|
+
* This allows for efficient instantiation of request-scoped services.
|
|
552
|
+
*/
|
|
553
|
+
declare interface RequestContextHolder {
|
|
554
|
+
/**
|
|
555
|
+
* Unique identifier for this request context.
|
|
556
|
+
*/
|
|
557
|
+
readonly requestId: string;
|
|
558
|
+
/**
|
|
559
|
+
* Pre-prepared instances for this request, keyed by instance name.
|
|
560
|
+
*/
|
|
561
|
+
readonly instances: Map<string, any>;
|
|
562
|
+
/**
|
|
563
|
+
* Instance holders for request-scoped services.
|
|
564
|
+
*/
|
|
565
|
+
readonly holders: Map<string, ServiceLocatorInstanceHolder>;
|
|
566
|
+
/**
|
|
567
|
+
* Priority for resolution in FactoryContext.inject method.
|
|
568
|
+
* Higher values take precedence.
|
|
569
|
+
*/
|
|
570
|
+
readonly priority: number;
|
|
571
|
+
/**
|
|
572
|
+
* Request-specific metadata that can be used during instantiation.
|
|
573
|
+
*/
|
|
574
|
+
readonly metadata: Map<string, any>;
|
|
575
|
+
/**
|
|
576
|
+
* Timestamp when this context was created.
|
|
577
|
+
*/
|
|
578
|
+
readonly createdAt: number;
|
|
579
|
+
/**
|
|
580
|
+
* Adds a pre-prepared instance to this context.
|
|
581
|
+
*/
|
|
582
|
+
addInstance(instanceName: string, instance: any, holder: ServiceLocatorInstanceHolder): void;
|
|
583
|
+
/**
|
|
584
|
+
* Gets a pre-prepared instance from this context.
|
|
585
|
+
*/
|
|
586
|
+
getInstance(instanceName: string): any | undefined;
|
|
587
|
+
/**
|
|
588
|
+
* Gets an instance holder from this context.
|
|
589
|
+
*/
|
|
590
|
+
getHolder(instanceName: string): ServiceLocatorInstanceHolder | undefined;
|
|
591
|
+
/**
|
|
592
|
+
* Checks if this context has a pre-prepared instance.
|
|
593
|
+
*/
|
|
594
|
+
hasInstance(instanceName: string): boolean;
|
|
595
|
+
/**
|
|
596
|
+
* Clears all instances and holders from this context.
|
|
597
|
+
*/
|
|
598
|
+
clear(): void;
|
|
599
|
+
/**
|
|
600
|
+
* Gets metadata value by key.
|
|
601
|
+
*/
|
|
602
|
+
getMetadata(key: string): any | undefined;
|
|
603
|
+
/**
|
|
604
|
+
* Sets metadata value by key.
|
|
605
|
+
*/
|
|
606
|
+
setMetadata(key: string, value: any): void;
|
|
607
|
+
}
|
|
608
|
+
export { RequestContextHolder }
|
|
609
|
+
export { RequestContextHolder as RequestContextHolder_alias_1 }
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* ServiceInstantiator handles the instantiation of services based on registry records.
|
|
613
|
+
* It replaces the hard-coded logic in Injectable and Factory decorators.
|
|
614
|
+
*/
|
|
615
|
+
declare class ServiceInstantiator {
|
|
616
|
+
private readonly injectors;
|
|
617
|
+
constructor(injectors: Injectors);
|
|
618
|
+
/**
|
|
619
|
+
* Instantiates a service based on its registry record.
|
|
620
|
+
* @param ctx The factory context for dependency injection
|
|
621
|
+
* @param record The factory record from the registry
|
|
622
|
+
* @param args Optional arguments for the service
|
|
623
|
+
* @returns Promise resolving to [undefined, instance] or [error]
|
|
624
|
+
*/
|
|
625
|
+
instantiateService<T>(ctx: FactoryContext, record: FactoryRecord<T, any>, args?: any): Promise<[undefined, T] | [Error]>;
|
|
626
|
+
/**
|
|
627
|
+
* Instantiates a class-based service (Injectable decorator).
|
|
628
|
+
* @param ctx The factory context for dependency injection
|
|
629
|
+
* @param record The factory record from the registry
|
|
630
|
+
* @param args Optional arguments for the service constructor
|
|
631
|
+
* @returns Promise resolving to [undefined, instance] or [error]
|
|
632
|
+
*/
|
|
633
|
+
private instantiateClass;
|
|
634
|
+
/**
|
|
635
|
+
* Instantiates a factory-based service (Factory decorator).
|
|
636
|
+
* @param ctx The factory context for dependency injection
|
|
637
|
+
* @param record The factory record from the registry
|
|
638
|
+
* @param args Optional arguments for the factory
|
|
639
|
+
* @returns Promise resolving to [undefined, instance] or [error]
|
|
640
|
+
*/
|
|
641
|
+
private instantiateFactory;
|
|
642
|
+
}
|
|
643
|
+
export { ServiceInstantiator }
|
|
644
|
+
export { ServiceInstantiator as ServiceInstantiator_alias_1 }
|
|
395
645
|
|
|
396
646
|
declare class ServiceLocator {
|
|
397
647
|
private readonly registry;
|
|
398
648
|
private readonly logger;
|
|
649
|
+
private readonly injectors;
|
|
399
650
|
private readonly eventBus;
|
|
400
651
|
private readonly manager;
|
|
401
|
-
|
|
652
|
+
private readonly serviceInstantiator;
|
|
653
|
+
private readonly requestContexts;
|
|
654
|
+
private currentRequestContext;
|
|
655
|
+
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
402
656
|
getEventBus(): ServiceLocatorEventBus;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
private resolveTokenArgs;
|
|
413
|
-
getInstanceIdentifier<Instance, Schema extends BaseInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): string;
|
|
414
|
-
getInstanceIdentifier<Instance, Schema extends OptionalInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): string;
|
|
415
|
-
getInstanceIdentifier<Instance>(token: InjectionToken<Instance, undefined>): string;
|
|
416
|
-
getInstanceIdentifier<Instance>(token: BoundInjectionToken<Instance, any>): string;
|
|
417
|
-
getInstanceIdentifier<Instance>(token: FactoryInjectionToken<Instance, any>): string;
|
|
418
|
-
getInstance<Instance, Schema extends BaseInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
419
|
-
getInstance<Instance, Schema extends OptionalInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
420
|
-
getInstance<Instance>(token: InjectionToken<Instance, undefined>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
421
|
-
getInstance<Instance>(token: BoundInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
422
|
-
getInstance<Instance>(token: FactoryInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
423
|
-
getOrThrowInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject<any> ? z.input<Schema> : Schema extends ZodOptional<ZodObject<any>> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
|
|
424
|
-
private notifyListeners;
|
|
425
|
-
private createInstance;
|
|
426
|
-
private resolveInstance;
|
|
427
|
-
private createFactoryContext;
|
|
428
|
-
getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject<any> ? z.input<Schema> : Schema extends ZodOptional<ZodObject<any>> ? z.input<Schema> | undefined : undefined): Instance | null;
|
|
657
|
+
getManager(): ServiceLocatorManager;
|
|
658
|
+
getInstanceIdentifier(token: AnyInjectableType, args?: any): string;
|
|
659
|
+
getInstance(token: AnyInjectableType, args?: any, onPrepare?: (data: {
|
|
660
|
+
instanceName: string;
|
|
661
|
+
actualToken: InjectionTokenType;
|
|
662
|
+
validatedArgs?: any;
|
|
663
|
+
}) => void): Promise<any[]>;
|
|
664
|
+
getOrThrowInstance<Instance>(token: AnyInjectableType, args: any): Promise<Instance>;
|
|
665
|
+
getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: AnyInjectableType, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? z.input<Schema> | undefined : undefined): Instance | null;
|
|
429
666
|
invalidate(service: string, round?: number): Promise<any>;
|
|
430
667
|
ready(): Promise<null>;
|
|
431
|
-
|
|
668
|
+
/**
|
|
669
|
+
* Begins a new request context with the given parameters.
|
|
670
|
+
* @param requestId Unique identifier for this request
|
|
671
|
+
* @param metadata Optional metadata for the request
|
|
672
|
+
* @param priority Priority for resolution (higher = more priority)
|
|
673
|
+
* @returns The created request context holder
|
|
674
|
+
*/
|
|
675
|
+
beginRequest(requestId: string, metadata?: Record<string, any>, priority?: number): RequestContextHolder;
|
|
676
|
+
/**
|
|
677
|
+
* Ends a request context and cleans up all associated instances.
|
|
678
|
+
* @param requestId The request ID to end
|
|
679
|
+
*/
|
|
680
|
+
endRequest(requestId: string): Promise<void>;
|
|
681
|
+
/**
|
|
682
|
+
* Gets the current request context.
|
|
683
|
+
* @returns The current request context holder or null
|
|
684
|
+
*/
|
|
685
|
+
getCurrentRequestContext(): RequestContextHolder | null;
|
|
686
|
+
/**
|
|
687
|
+
* Sets the current request context.
|
|
688
|
+
* @param requestId The request ID to set as current
|
|
689
|
+
*/
|
|
690
|
+
setCurrentRequestContext(requestId: string): void;
|
|
691
|
+
/**
|
|
692
|
+
* Validates and resolves token arguments, handling factory token resolution and validation.
|
|
693
|
+
*/
|
|
694
|
+
private validateAndResolveTokenArgs;
|
|
695
|
+
/**
|
|
696
|
+
* Internal method to resolve token args and create instance name.
|
|
697
|
+
* Handles factory token resolution and validation.
|
|
698
|
+
*/
|
|
699
|
+
private resolveTokenAndPrepareInstanceName;
|
|
700
|
+
/**
|
|
701
|
+
* Gets an instance by its instance name, handling all the logic after instance name creation.
|
|
702
|
+
*/
|
|
703
|
+
private retrieveOrCreateInstanceByInstanceName;
|
|
704
|
+
/**
|
|
705
|
+
* Emits events to listeners for instance lifecycle events.
|
|
706
|
+
*/
|
|
707
|
+
private emitInstanceEvent;
|
|
708
|
+
/**
|
|
709
|
+
* Creates a new instance for the given token and arguments.
|
|
710
|
+
*/
|
|
711
|
+
private createNewInstance;
|
|
712
|
+
/**
|
|
713
|
+
* Instantiates a service from the registry using the service instantiator.
|
|
714
|
+
*/
|
|
715
|
+
private instantiateServiceFromRegistry;
|
|
716
|
+
/**
|
|
717
|
+
* Creates a factory context for dependency injection during service instantiation.
|
|
718
|
+
* @param contextHolder Optional request context holder for priority-based resolution
|
|
719
|
+
*/
|
|
720
|
+
private createFactoryContext;
|
|
721
|
+
/**
|
|
722
|
+
* Generates a unique instance name based on token and arguments.
|
|
723
|
+
*/
|
|
724
|
+
private generateInstanceName;
|
|
432
725
|
}
|
|
433
726
|
export { ServiceLocator }
|
|
434
727
|
export { ServiceLocator as ServiceLocator_alias_1 }
|
|
@@ -451,7 +744,7 @@ declare type ServiceLocatorInstanceEffect = () => void;
|
|
|
451
744
|
export { ServiceLocatorInstanceEffect }
|
|
452
745
|
export { ServiceLocatorInstanceEffect as ServiceLocatorInstanceEffect_alias_1 }
|
|
453
746
|
|
|
454
|
-
declare type ServiceLocatorInstanceHolder<Instance = unknown> = ServiceLocatorInstanceHolderCreating<Instance> | ServiceLocatorInstanceHolderCreated<Instance> | ServiceLocatorInstanceHolderDestroying<Instance
|
|
747
|
+
declare type ServiceLocatorInstanceHolder<Instance = unknown> = ServiceLocatorInstanceHolderCreating<Instance> | ServiceLocatorInstanceHolderCreated<Instance> | ServiceLocatorInstanceHolderDestroying<Instance> | ServiceLocatorInstanceHolderError;
|
|
455
748
|
export { ServiceLocatorInstanceHolder }
|
|
456
749
|
export { ServiceLocatorInstanceHolder as ServiceLocatorInstanceHolder_alias_1 }
|
|
457
750
|
|
|
@@ -461,9 +754,9 @@ declare interface ServiceLocatorInstanceHolderCreated<Instance> {
|
|
|
461
754
|
instance: Instance;
|
|
462
755
|
creationPromise: null;
|
|
463
756
|
destroyPromise: null;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
deps: string
|
|
757
|
+
type: InjectableType;
|
|
758
|
+
scope: InjectableScope;
|
|
759
|
+
deps: Set<string>;
|
|
467
760
|
destroyListeners: ServiceLocatorInstanceDestroyListener[];
|
|
468
761
|
createdAt: number;
|
|
469
762
|
ttl: number;
|
|
@@ -477,9 +770,9 @@ declare interface ServiceLocatorInstanceHolderCreating<Instance> {
|
|
|
477
770
|
instance: null;
|
|
478
771
|
creationPromise: Promise<[undefined, Instance]> | null;
|
|
479
772
|
destroyPromise: null;
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
deps: string
|
|
773
|
+
type: InjectableType;
|
|
774
|
+
scope: InjectableScope;
|
|
775
|
+
deps: Set<string>;
|
|
483
776
|
destroyListeners: ServiceLocatorInstanceDestroyListener[];
|
|
484
777
|
createdAt: number;
|
|
485
778
|
ttl: number;
|
|
@@ -493,9 +786,9 @@ declare interface ServiceLocatorInstanceHolderDestroying<Instance> {
|
|
|
493
786
|
instance: Instance | null;
|
|
494
787
|
creationPromise: null;
|
|
495
788
|
destroyPromise: Promise<void>;
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
deps: string
|
|
789
|
+
type: InjectableType;
|
|
790
|
+
scope: InjectableScope;
|
|
791
|
+
deps: Set<string>;
|
|
499
792
|
destroyListeners: ServiceLocatorInstanceDestroyListener[];
|
|
500
793
|
createdAt: number;
|
|
501
794
|
ttl: number;
|
|
@@ -503,18 +796,27 @@ declare interface ServiceLocatorInstanceHolderDestroying<Instance> {
|
|
|
503
796
|
export { ServiceLocatorInstanceHolderDestroying }
|
|
504
797
|
export { ServiceLocatorInstanceHolderDestroying as ServiceLocatorInstanceHolderDestroying_alias_1 }
|
|
505
798
|
|
|
506
|
-
declare
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
799
|
+
declare interface ServiceLocatorInstanceHolderError {
|
|
800
|
+
status: ServiceLocatorInstanceHolderStatus.Error;
|
|
801
|
+
name: string;
|
|
802
|
+
instance: Error;
|
|
803
|
+
creationPromise: null;
|
|
804
|
+
destroyPromise: null;
|
|
805
|
+
type: InjectableType;
|
|
806
|
+
scope: InjectableScope;
|
|
807
|
+
deps: Set<string>;
|
|
808
|
+
destroyListeners: ServiceLocatorInstanceDestroyListener[];
|
|
809
|
+
createdAt: number;
|
|
810
|
+
ttl: number;
|
|
510
811
|
}
|
|
511
|
-
export {
|
|
512
|
-
export {
|
|
812
|
+
export { ServiceLocatorInstanceHolderError }
|
|
813
|
+
export { ServiceLocatorInstanceHolderError as ServiceLocatorInstanceHolderError_alias_1 }
|
|
513
814
|
|
|
514
815
|
declare enum ServiceLocatorInstanceHolderStatus {
|
|
515
816
|
Created = "created",
|
|
516
817
|
Creating = "creating",
|
|
517
|
-
Destroying = "destroying"
|
|
818
|
+
Destroying = "destroying",
|
|
819
|
+
Error = "error"
|
|
518
820
|
}
|
|
519
821
|
export { ServiceLocatorInstanceHolderStatus }
|
|
520
822
|
export { ServiceLocatorInstanceHolderStatus as ServiceLocatorInstanceHolderStatus_alias_1 }
|
|
@@ -528,19 +830,62 @@ declare class ServiceLocatorManager {
|
|
|
528
830
|
has(name: string): [InstanceExpired | InstanceDestroying] | [undefined, boolean];
|
|
529
831
|
delete(name: string): boolean;
|
|
530
832
|
filter(predicate: (value: ServiceLocatorInstanceHolder<any>, key: string) => boolean): Map<string, ServiceLocatorInstanceHolder>;
|
|
833
|
+
/**
|
|
834
|
+
* Creates a new holder with Creating status and a deferred creation promise.
|
|
835
|
+
* This is useful for creating placeholder holders that can be fulfilled later.
|
|
836
|
+
* @param name The name of the instance
|
|
837
|
+
* @param type The injectable type
|
|
838
|
+
* @param scope The injectable scope
|
|
839
|
+
* @param deps Optional set of dependencies
|
|
840
|
+
* @param ttl Optional time-to-live in milliseconds (defaults to Infinity)
|
|
841
|
+
* @returns A tuple containing the deferred promise and the holder
|
|
842
|
+
*/
|
|
843
|
+
createCreatingHolder<Instance>(name: string, type: InjectableType, scope: InjectableScope, deps?: Set<string>, ttl?: number): [
|
|
844
|
+
ReturnType<typeof createDeferred<[undefined, Instance]>>,
|
|
845
|
+
ServiceLocatorInstanceHolder<Instance>
|
|
846
|
+
];
|
|
847
|
+
/**
|
|
848
|
+
* Creates a new holder with Created status and an actual instance.
|
|
849
|
+
* This is useful for creating holders that already have their instance ready.
|
|
850
|
+
* @param name The name of the instance
|
|
851
|
+
* @param instance The actual instance to store
|
|
852
|
+
* @param type The injectable type
|
|
853
|
+
* @param scope The injectable scope
|
|
854
|
+
* @param deps Optional set of dependencies
|
|
855
|
+
* @param ttl Optional time-to-live in milliseconds (defaults to Infinity)
|
|
856
|
+
* @returns The created holder
|
|
857
|
+
*/
|
|
858
|
+
storeCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>, ttl?: number): ServiceLocatorInstanceHolder<Instance>;
|
|
531
859
|
}
|
|
532
860
|
export { ServiceLocatorManager }
|
|
533
861
|
export { ServiceLocatorManager as ServiceLocatorManager_alias_1 }
|
|
534
862
|
|
|
535
|
-
declare const
|
|
536
|
-
|
|
537
|
-
export
|
|
863
|
+
export declare const test1: string;
|
|
864
|
+
|
|
865
|
+
export declare const test2: number;
|
|
866
|
+
|
|
867
|
+
export declare const test3: boolean;
|
|
868
|
+
|
|
869
|
+
export declare const test4: {
|
|
870
|
+
name: string;
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
export declare const test5: object;
|
|
538
874
|
|
|
539
875
|
declare type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true ? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]> : [T, ...A];
|
|
876
|
+
export { UnionToArray }
|
|
877
|
+
export { UnionToArray as UnionToArray_alias_1 }
|
|
878
|
+
export { UnionToArray as UnionToArray_alias_2 }
|
|
540
879
|
|
|
541
880
|
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
881
|
+
export { UnionToIntersection }
|
|
882
|
+
export { UnionToIntersection as UnionToIntersection_alias_1 }
|
|
883
|
+
export { UnionToIntersection as UnionToIntersection_alias_2 }
|
|
542
884
|
|
|
543
885
|
declare type UnionToOvlds<U> = UnionToIntersection<U extends any ? (f: U) => void : never>;
|
|
886
|
+
export { UnionToOvlds }
|
|
887
|
+
export { UnionToOvlds as UnionToOvlds_alias_1 }
|
|
888
|
+
export { UnionToOvlds as UnionToOvlds_alias_2 }
|
|
544
889
|
|
|
545
890
|
declare class UnknownError extends Error {
|
|
546
891
|
code: ErrorsEnum;
|