@navios/di 0.1.6 → 0.1.7
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/dist/_tsup-dts-rollup.d.mts +40 -30
- package/dist/_tsup-dts-rollup.d.ts +40 -30
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/decorators/injectable.decorator.mts +6 -8
- package/src/injection-token.mts +25 -21
- package/src/interfaces/factory.interface.mts +3 -3
- package/src/service-locator.mts +35 -21
- package/src/utils/get-injectors.mts +7 -5
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { AnyZodObject } from 'zod';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { ZodOptional } from 'zod';
|
|
4
|
+
import { ZodRecord } from 'zod';
|
|
4
5
|
|
|
5
|
-
declare
|
|
6
|
+
declare type BaseInjectionTokenSchemaType = AnyZodObject | ZodRecord;
|
|
7
|
+
export { BaseInjectionTokenSchemaType }
|
|
8
|
+
export { BaseInjectionTokenSchemaType as BaseInjectionTokenSchemaType_alias_1 }
|
|
9
|
+
|
|
10
|
+
declare class BoundInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
6
11
|
readonly token: InjectionToken<T, S>;
|
|
7
12
|
readonly value: z.input<S>;
|
|
8
13
|
id: string;
|
|
9
14
|
name: string | symbol | ClassType;
|
|
10
|
-
schema:
|
|
15
|
+
schema: InjectionTokenSchemaType;
|
|
11
16
|
constructor(token: InjectionToken<T, S>, value: z.input<S>);
|
|
12
17
|
toString(): string;
|
|
13
18
|
}
|
|
@@ -109,14 +114,14 @@ declare interface FactoryContext {
|
|
|
109
114
|
export { FactoryContext }
|
|
110
115
|
export { FactoryContext as FactoryContext_alias_1 }
|
|
111
116
|
|
|
112
|
-
declare class FactoryInjectionToken<T, S extends
|
|
117
|
+
declare class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
113
118
|
readonly token: InjectionToken<T, S>;
|
|
114
119
|
readonly factory: () => Promise<z.input<S>>;
|
|
115
120
|
value?: z.input<S>;
|
|
116
121
|
resolved: boolean;
|
|
117
122
|
id: string;
|
|
118
123
|
name: string | symbol | ClassType;
|
|
119
|
-
schema:
|
|
124
|
+
schema: InjectionTokenSchemaType;
|
|
120
125
|
constructor(token: InjectionToken<T, S>, factory: () => Promise<z.input<S>>);
|
|
121
126
|
resolve(): Promise<z.input<S>>;
|
|
122
127
|
toString(): string;
|
|
@@ -149,7 +154,7 @@ export { FactoryTokenNotResolved }
|
|
|
149
154
|
export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_1 }
|
|
150
155
|
export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_2 }
|
|
151
156
|
|
|
152
|
-
declare interface FactoryWithArgs<T, A extends
|
|
157
|
+
declare interface FactoryWithArgs<T, A extends InjectionTokenSchemaType> {
|
|
153
158
|
create(ctx: any, args: z.output<A>): Promise<T> | T;
|
|
154
159
|
}
|
|
155
160
|
export { FactoryWithArgs }
|
|
@@ -187,13 +192,13 @@ declare function Injectable<R>(options: {
|
|
|
187
192
|
type: InjectableType.Factory;
|
|
188
193
|
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T;
|
|
189
194
|
|
|
190
|
-
declare function Injectable<S extends
|
|
195
|
+
declare function Injectable<S extends InjectionTokenSchemaType>(options: {
|
|
191
196
|
scope?: InjectableScope;
|
|
192
197
|
type?: InjectableType.Class;
|
|
193
198
|
token: InjectionToken<undefined, S>;
|
|
194
199
|
}): <T extends ClassTypeWithArgument<z.output<S>>>(target: T, context: ClassDecoratorContext) => T;
|
|
195
200
|
|
|
196
|
-
declare function Injectable<R, S extends
|
|
201
|
+
declare function Injectable<R, S extends InjectionTokenSchemaType>(options: {
|
|
197
202
|
scope?: InjectableScope;
|
|
198
203
|
type?: InjectableType.Class;
|
|
199
204
|
token: InjectionToken<R, S>;
|
|
@@ -204,21 +209,17 @@ declare function Injectable<T extends ClassType>(options: {
|
|
|
204
209
|
token: InjectionToken<T, undefined>;
|
|
205
210
|
}): (target: T, context: ClassDecoratorContext) => T;
|
|
206
211
|
|
|
207
|
-
declare function Injectable<R, S extends
|
|
212
|
+
declare function Injectable<R, S extends InjectionTokenSchemaType>(options: {
|
|
208
213
|
scope?: InjectableScope;
|
|
209
214
|
type: InjectableType.Factory;
|
|
210
215
|
token: InjectionToken<R, S>;
|
|
211
|
-
}): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(target: T, context: ClassDecoratorContext) => T
|
|
212
|
-
[InjectableTokenMeta]: InjectionToken<R, S>;
|
|
213
|
-
};
|
|
216
|
+
}): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(target: T, context: ClassDecoratorContext) => T;
|
|
214
217
|
|
|
215
218
|
declare function Injectable<R>(options: {
|
|
216
219
|
scope?: InjectableScope;
|
|
217
220
|
type: InjectableType.Factory;
|
|
218
221
|
token: InjectionToken<R, undefined>;
|
|
219
|
-
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T
|
|
220
|
-
[InjectableTokenMeta]: InjectionToken<R, undefined>;
|
|
221
|
-
};
|
|
222
|
+
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T;
|
|
222
223
|
export { Injectable }
|
|
223
224
|
export { Injectable as Injectable_alias_1 }
|
|
224
225
|
export { Injectable as Injectable_alias_2 }
|
|
@@ -264,34 +265,38 @@ declare type InjectionFactory<T = unknown, Args = unknown> = (ctx: FactoryContex
|
|
|
264
265
|
export { InjectionFactory }
|
|
265
266
|
export { InjectionFactory as InjectionFactory_alias_1 }
|
|
266
267
|
|
|
267
|
-
declare class InjectionToken<T, S extends
|
|
268
|
+
declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown> {
|
|
268
269
|
readonly name: string | symbol | ClassType;
|
|
269
270
|
readonly schema: AnyZodObject | undefined;
|
|
270
271
|
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
271
272
|
private formattedName;
|
|
272
273
|
constructor(name: string | symbol | ClassType, schema: AnyZodObject | undefined);
|
|
273
274
|
static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
|
|
274
|
-
static create<T extends ClassType, Schema extends
|
|
275
|
+
static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): InjectionToken<InstanceType<T>, Schema>;
|
|
275
276
|
static create<T>(name: string | symbol): InjectionToken<T, undefined>;
|
|
276
|
-
static create<T, Schema extends
|
|
277
|
-
static bound<T, S extends
|
|
278
|
-
static factory<T, S extends
|
|
277
|
+
static create<T, Schema extends InjectionTokenSchemaType>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
|
|
278
|
+
static bound<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
|
|
279
|
+
static factory<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, factory: () => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
|
|
279
280
|
static refineType<T>(token: BoundInjectionToken<any, any>): BoundInjectionToken<T, any>;
|
|
280
281
|
toString(): string;
|
|
281
282
|
}
|
|
282
283
|
export { InjectionToken }
|
|
283
284
|
export { InjectionToken as InjectionToken_alias_1 }
|
|
284
285
|
|
|
286
|
+
declare type InjectionTokenSchemaType = BaseInjectionTokenSchemaType | OptionalInjectionTokenSchemaType;
|
|
287
|
+
export { InjectionTokenSchemaType }
|
|
288
|
+
export { InjectionTokenSchemaType as InjectionTokenSchemaType_alias_1 }
|
|
289
|
+
|
|
285
290
|
declare interface Injectors {
|
|
286
291
|
inject<T extends ClassType>(token: T): Promise<InstanceType<T>>;
|
|
287
|
-
inject<T, S extends
|
|
288
|
-
inject<T, S extends
|
|
292
|
+
inject<T, S extends BaseInjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
293
|
+
inject<T, S extends OptionalInjectionTokenSchemaType>(token: InjectionToken<T, S>, args?: z.input<S>): Promise<T>;
|
|
289
294
|
inject<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
290
295
|
inject<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
291
296
|
inject<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
292
297
|
syncInject<T extends ClassType>(token: T): InstanceType<T>;
|
|
293
|
-
syncInject<T, S extends
|
|
294
|
-
syncInject<T, S extends
|
|
298
|
+
syncInject<T, S extends BaseInjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T;
|
|
299
|
+
syncInject<T, S extends OptionalInjectionTokenSchemaType>(token: InjectionToken<T, S>, args?: z.input<S>): T;
|
|
295
300
|
syncInject<T>(token: InjectionToken<T, undefined>): T;
|
|
296
301
|
syncInject<T>(token: BoundInjectionToken<T, any>): T;
|
|
297
302
|
syncInject<T>(token: FactoryInjectionToken<T, any>): T;
|
|
@@ -338,6 +343,10 @@ declare function makeProxyServiceLocator(serviceLocator: ServiceLocator, ctx: Fa
|
|
|
338
343
|
export { makeProxyServiceLocator }
|
|
339
344
|
export { makeProxyServiceLocator as makeProxyServiceLocator_alias_1 }
|
|
340
345
|
|
|
346
|
+
declare type OptionalInjectionTokenSchemaType = ZodOptional<AnyZodObject> | ZodOptional<ZodRecord>;
|
|
347
|
+
export { OptionalInjectionTokenSchemaType }
|
|
348
|
+
export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
|
|
349
|
+
|
|
341
350
|
declare const provideServiceLocator: Injectors['provideServiceLocator'];
|
|
342
351
|
export { provideServiceLocator }
|
|
343
352
|
export { provideServiceLocator as provideServiceLocator_alias_1 }
|
|
@@ -387,24 +396,25 @@ declare class ServiceLocator {
|
|
|
387
396
|
removeInstance<Instance>(token: BoundInjectionToken<Instance, any>): void;
|
|
388
397
|
removeInstance<Instance>(token: FactoryInjectionToken<Instance, any>): void;
|
|
389
398
|
removeInstance<Instance>(token: InjectionToken<Instance, undefined>): void;
|
|
390
|
-
removeInstance<Instance, Schema extends
|
|
399
|
+
removeInstance<Instance, Schema extends BaseInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): void;
|
|
400
|
+
removeInstance<Instance, Schema extends OptionalInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): void;
|
|
391
401
|
private resolveTokenArgs;
|
|
392
|
-
getInstanceIdentifier<Instance, Schema extends
|
|
393
|
-
getInstanceIdentifier<Instance, Schema extends
|
|
402
|
+
getInstanceIdentifier<Instance, Schema extends BaseInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): string;
|
|
403
|
+
getInstanceIdentifier<Instance, Schema extends OptionalInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): string;
|
|
394
404
|
getInstanceIdentifier<Instance>(token: InjectionToken<Instance, undefined>): string;
|
|
395
405
|
getInstanceIdentifier<Instance>(token: BoundInjectionToken<Instance, any>): string;
|
|
396
406
|
getInstanceIdentifier<Instance>(token: FactoryInjectionToken<Instance, any>): string;
|
|
397
|
-
getInstance<Instance, Schema extends
|
|
398
|
-
getInstance<Instance, Schema extends
|
|
407
|
+
getInstance<Instance, Schema extends BaseInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
408
|
+
getInstance<Instance, Schema extends OptionalInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
399
409
|
getInstance<Instance>(token: InjectionToken<Instance, undefined>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
400
410
|
getInstance<Instance>(token: BoundInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
401
411
|
getInstance<Instance>(token: FactoryInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
402
|
-
getOrThrowInstance<Instance, Schema extends
|
|
412
|
+
getOrThrowInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends AnyZodObject ? z.input<Schema> : Schema extends ZodOptional<AnyZodObject> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
|
|
403
413
|
private notifyListeners;
|
|
404
414
|
private createInstance;
|
|
405
415
|
private resolveInstance;
|
|
406
416
|
private createFactoryContext;
|
|
407
|
-
getSyncInstance<Instance, Schema extends
|
|
417
|
+
getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends AnyZodObject ? z.input<Schema> : Schema extends ZodOptional<AnyZodObject> ? z.input<Schema> | undefined : undefined): Instance | null;
|
|
408
418
|
invalidate(service: string, round?: number): Promise<any>;
|
|
409
419
|
ready(): Promise<null>;
|
|
410
420
|
makeInstanceName(token: InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args: any): string;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { AnyZodObject } from 'zod';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { ZodOptional } from 'zod';
|
|
4
|
+
import { ZodRecord } from 'zod';
|
|
4
5
|
|
|
5
|
-
declare
|
|
6
|
+
declare type BaseInjectionTokenSchemaType = AnyZodObject | ZodRecord;
|
|
7
|
+
export { BaseInjectionTokenSchemaType }
|
|
8
|
+
export { BaseInjectionTokenSchemaType as BaseInjectionTokenSchemaType_alias_1 }
|
|
9
|
+
|
|
10
|
+
declare class BoundInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
6
11
|
readonly token: InjectionToken<T, S>;
|
|
7
12
|
readonly value: z.input<S>;
|
|
8
13
|
id: string;
|
|
9
14
|
name: string | symbol | ClassType;
|
|
10
|
-
schema:
|
|
15
|
+
schema: InjectionTokenSchemaType;
|
|
11
16
|
constructor(token: InjectionToken<T, S>, value: z.input<S>);
|
|
12
17
|
toString(): string;
|
|
13
18
|
}
|
|
@@ -109,14 +114,14 @@ declare interface FactoryContext {
|
|
|
109
114
|
export { FactoryContext }
|
|
110
115
|
export { FactoryContext as FactoryContext_alias_1 }
|
|
111
116
|
|
|
112
|
-
declare class FactoryInjectionToken<T, S extends
|
|
117
|
+
declare class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
113
118
|
readonly token: InjectionToken<T, S>;
|
|
114
119
|
readonly factory: () => Promise<z.input<S>>;
|
|
115
120
|
value?: z.input<S>;
|
|
116
121
|
resolved: boolean;
|
|
117
122
|
id: string;
|
|
118
123
|
name: string | symbol | ClassType;
|
|
119
|
-
schema:
|
|
124
|
+
schema: InjectionTokenSchemaType;
|
|
120
125
|
constructor(token: InjectionToken<T, S>, factory: () => Promise<z.input<S>>);
|
|
121
126
|
resolve(): Promise<z.input<S>>;
|
|
122
127
|
toString(): string;
|
|
@@ -149,7 +154,7 @@ export { FactoryTokenNotResolved }
|
|
|
149
154
|
export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_1 }
|
|
150
155
|
export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_2 }
|
|
151
156
|
|
|
152
|
-
declare interface FactoryWithArgs<T, A extends
|
|
157
|
+
declare interface FactoryWithArgs<T, A extends InjectionTokenSchemaType> {
|
|
153
158
|
create(ctx: any, args: z.output<A>): Promise<T> | T;
|
|
154
159
|
}
|
|
155
160
|
export { FactoryWithArgs }
|
|
@@ -187,13 +192,13 @@ declare function Injectable<R>(options: {
|
|
|
187
192
|
type: InjectableType.Factory;
|
|
188
193
|
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T;
|
|
189
194
|
|
|
190
|
-
declare function Injectable<S extends
|
|
195
|
+
declare function Injectable<S extends InjectionTokenSchemaType>(options: {
|
|
191
196
|
scope?: InjectableScope;
|
|
192
197
|
type?: InjectableType.Class;
|
|
193
198
|
token: InjectionToken<undefined, S>;
|
|
194
199
|
}): <T extends ClassTypeWithArgument<z.output<S>>>(target: T, context: ClassDecoratorContext) => T;
|
|
195
200
|
|
|
196
|
-
declare function Injectable<R, S extends
|
|
201
|
+
declare function Injectable<R, S extends InjectionTokenSchemaType>(options: {
|
|
197
202
|
scope?: InjectableScope;
|
|
198
203
|
type?: InjectableType.Class;
|
|
199
204
|
token: InjectionToken<R, S>;
|
|
@@ -204,21 +209,17 @@ declare function Injectable<T extends ClassType>(options: {
|
|
|
204
209
|
token: InjectionToken<T, undefined>;
|
|
205
210
|
}): (target: T, context: ClassDecoratorContext) => T;
|
|
206
211
|
|
|
207
|
-
declare function Injectable<R, S extends
|
|
212
|
+
declare function Injectable<R, S extends InjectionTokenSchemaType>(options: {
|
|
208
213
|
scope?: InjectableScope;
|
|
209
214
|
type: InjectableType.Factory;
|
|
210
215
|
token: InjectionToken<R, S>;
|
|
211
|
-
}): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(target: T, context: ClassDecoratorContext) => T
|
|
212
|
-
[InjectableTokenMeta]: InjectionToken<R, S>;
|
|
213
|
-
};
|
|
216
|
+
}): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(target: T, context: ClassDecoratorContext) => T;
|
|
214
217
|
|
|
215
218
|
declare function Injectable<R>(options: {
|
|
216
219
|
scope?: InjectableScope;
|
|
217
220
|
type: InjectableType.Factory;
|
|
218
221
|
token: InjectionToken<R, undefined>;
|
|
219
|
-
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T
|
|
220
|
-
[InjectableTokenMeta]: InjectionToken<R, undefined>;
|
|
221
|
-
};
|
|
222
|
+
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T;
|
|
222
223
|
export { Injectable }
|
|
223
224
|
export { Injectable as Injectable_alias_1 }
|
|
224
225
|
export { Injectable as Injectable_alias_2 }
|
|
@@ -264,34 +265,38 @@ declare type InjectionFactory<T = unknown, Args = unknown> = (ctx: FactoryContex
|
|
|
264
265
|
export { InjectionFactory }
|
|
265
266
|
export { InjectionFactory as InjectionFactory_alias_1 }
|
|
266
267
|
|
|
267
|
-
declare class InjectionToken<T, S extends
|
|
268
|
+
declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown> {
|
|
268
269
|
readonly name: string | symbol | ClassType;
|
|
269
270
|
readonly schema: AnyZodObject | undefined;
|
|
270
271
|
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
271
272
|
private formattedName;
|
|
272
273
|
constructor(name: string | symbol | ClassType, schema: AnyZodObject | undefined);
|
|
273
274
|
static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
|
|
274
|
-
static create<T extends ClassType, Schema extends
|
|
275
|
+
static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): InjectionToken<InstanceType<T>, Schema>;
|
|
275
276
|
static create<T>(name: string | symbol): InjectionToken<T, undefined>;
|
|
276
|
-
static create<T, Schema extends
|
|
277
|
-
static bound<T, S extends
|
|
278
|
-
static factory<T, S extends
|
|
277
|
+
static create<T, Schema extends InjectionTokenSchemaType>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
|
|
278
|
+
static bound<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
|
|
279
|
+
static factory<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, factory: () => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
|
|
279
280
|
static refineType<T>(token: BoundInjectionToken<any, any>): BoundInjectionToken<T, any>;
|
|
280
281
|
toString(): string;
|
|
281
282
|
}
|
|
282
283
|
export { InjectionToken }
|
|
283
284
|
export { InjectionToken as InjectionToken_alias_1 }
|
|
284
285
|
|
|
286
|
+
declare type InjectionTokenSchemaType = BaseInjectionTokenSchemaType | OptionalInjectionTokenSchemaType;
|
|
287
|
+
export { InjectionTokenSchemaType }
|
|
288
|
+
export { InjectionTokenSchemaType as InjectionTokenSchemaType_alias_1 }
|
|
289
|
+
|
|
285
290
|
declare interface Injectors {
|
|
286
291
|
inject<T extends ClassType>(token: T): Promise<InstanceType<T>>;
|
|
287
|
-
inject<T, S extends
|
|
288
|
-
inject<T, S extends
|
|
292
|
+
inject<T, S extends BaseInjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
293
|
+
inject<T, S extends OptionalInjectionTokenSchemaType>(token: InjectionToken<T, S>, args?: z.input<S>): Promise<T>;
|
|
289
294
|
inject<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
290
295
|
inject<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
291
296
|
inject<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
292
297
|
syncInject<T extends ClassType>(token: T): InstanceType<T>;
|
|
293
|
-
syncInject<T, S extends
|
|
294
|
-
syncInject<T, S extends
|
|
298
|
+
syncInject<T, S extends BaseInjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T;
|
|
299
|
+
syncInject<T, S extends OptionalInjectionTokenSchemaType>(token: InjectionToken<T, S>, args?: z.input<S>): T;
|
|
295
300
|
syncInject<T>(token: InjectionToken<T, undefined>): T;
|
|
296
301
|
syncInject<T>(token: BoundInjectionToken<T, any>): T;
|
|
297
302
|
syncInject<T>(token: FactoryInjectionToken<T, any>): T;
|
|
@@ -338,6 +343,10 @@ declare function makeProxyServiceLocator(serviceLocator: ServiceLocator, ctx: Fa
|
|
|
338
343
|
export { makeProxyServiceLocator }
|
|
339
344
|
export { makeProxyServiceLocator as makeProxyServiceLocator_alias_1 }
|
|
340
345
|
|
|
346
|
+
declare type OptionalInjectionTokenSchemaType = ZodOptional<AnyZodObject> | ZodOptional<ZodRecord>;
|
|
347
|
+
export { OptionalInjectionTokenSchemaType }
|
|
348
|
+
export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
|
|
349
|
+
|
|
341
350
|
declare const provideServiceLocator: Injectors['provideServiceLocator'];
|
|
342
351
|
export { provideServiceLocator }
|
|
343
352
|
export { provideServiceLocator as provideServiceLocator_alias_1 }
|
|
@@ -387,24 +396,25 @@ declare class ServiceLocator {
|
|
|
387
396
|
removeInstance<Instance>(token: BoundInjectionToken<Instance, any>): void;
|
|
388
397
|
removeInstance<Instance>(token: FactoryInjectionToken<Instance, any>): void;
|
|
389
398
|
removeInstance<Instance>(token: InjectionToken<Instance, undefined>): void;
|
|
390
|
-
removeInstance<Instance, Schema extends
|
|
399
|
+
removeInstance<Instance, Schema extends BaseInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): void;
|
|
400
|
+
removeInstance<Instance, Schema extends OptionalInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): void;
|
|
391
401
|
private resolveTokenArgs;
|
|
392
|
-
getInstanceIdentifier<Instance, Schema extends
|
|
393
|
-
getInstanceIdentifier<Instance, Schema extends
|
|
402
|
+
getInstanceIdentifier<Instance, Schema extends BaseInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): string;
|
|
403
|
+
getInstanceIdentifier<Instance, Schema extends OptionalInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): string;
|
|
394
404
|
getInstanceIdentifier<Instance>(token: InjectionToken<Instance, undefined>): string;
|
|
395
405
|
getInstanceIdentifier<Instance>(token: BoundInjectionToken<Instance, any>): string;
|
|
396
406
|
getInstanceIdentifier<Instance>(token: FactoryInjectionToken<Instance, any>): string;
|
|
397
|
-
getInstance<Instance, Schema extends
|
|
398
|
-
getInstance<Instance, Schema extends
|
|
407
|
+
getInstance<Instance, Schema extends BaseInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
408
|
+
getInstance<Instance, Schema extends OptionalInjectionTokenSchemaType>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
399
409
|
getInstance<Instance>(token: InjectionToken<Instance, undefined>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
400
410
|
getInstance<Instance>(token: BoundInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
401
411
|
getInstance<Instance>(token: FactoryInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
402
|
-
getOrThrowInstance<Instance, Schema extends
|
|
412
|
+
getOrThrowInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends AnyZodObject ? z.input<Schema> : Schema extends ZodOptional<AnyZodObject> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
|
|
403
413
|
private notifyListeners;
|
|
404
414
|
private createInstance;
|
|
405
415
|
private resolveInstance;
|
|
406
416
|
private createFactoryContext;
|
|
407
|
-
getSyncInstance<Instance, Schema extends
|
|
417
|
+
getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends AnyZodObject ? z.input<Schema> : Schema extends ZodOptional<AnyZodObject> ? z.input<Schema> | undefined : undefined): Instance | null;
|
|
408
418
|
invalidate(service: string, round?: number): Promise<any>;
|
|
409
419
|
ready(): Promise<null>;
|
|
410
420
|
makeInstanceName(token: InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args: any): string;
|
package/dist/index.d.mts
CHANGED
|
@@ -27,6 +27,9 @@ export { ClassType } from './_tsup-dts-rollup.mjs';
|
|
|
27
27
|
export { ClassTypeWithArgument } from './_tsup-dts-rollup.mjs';
|
|
28
28
|
export { ClassTypeWithInstance } from './_tsup-dts-rollup.mjs';
|
|
29
29
|
export { ClassTypeWithInstanceAndArgument } from './_tsup-dts-rollup.mjs';
|
|
30
|
+
export { BaseInjectionTokenSchemaType } from './_tsup-dts-rollup.mjs';
|
|
31
|
+
export { OptionalInjectionTokenSchemaType } from './_tsup-dts-rollup.mjs';
|
|
32
|
+
export { InjectionTokenSchemaType } from './_tsup-dts-rollup.mjs';
|
|
30
33
|
export { InjectionToken } from './_tsup-dts-rollup.mjs';
|
|
31
34
|
export { BoundInjectionToken } from './_tsup-dts-rollup.mjs';
|
|
32
35
|
export { FactoryInjectionToken } from './_tsup-dts-rollup.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export { ClassType } from './_tsup-dts-rollup.js';
|
|
|
27
27
|
export { ClassTypeWithArgument } from './_tsup-dts-rollup.js';
|
|
28
28
|
export { ClassTypeWithInstance } from './_tsup-dts-rollup.js';
|
|
29
29
|
export { ClassTypeWithInstanceAndArgument } from './_tsup-dts-rollup.js';
|
|
30
|
+
export { BaseInjectionTokenSchemaType } from './_tsup-dts-rollup.js';
|
|
31
|
+
export { OptionalInjectionTokenSchemaType } from './_tsup-dts-rollup.js';
|
|
32
|
+
export { InjectionTokenSchemaType } from './_tsup-dts-rollup.js';
|
|
30
33
|
export { InjectionToken } from './_tsup-dts-rollup.js';
|
|
31
34
|
export { BoundInjectionToken } from './_tsup-dts-rollup.js';
|
|
32
35
|
export { FactoryInjectionToken } from './_tsup-dts-rollup.js';
|
package/package.json
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { AnyZodObject } from 'zod'
|
|
2
|
-
|
|
3
1
|
import { NaviosException } from '@navios/common'
|
|
4
2
|
|
|
5
3
|
import { z } from 'zod'
|
|
@@ -9,6 +7,7 @@ import type {
|
|
|
9
7
|
ClassTypeWithArgument,
|
|
10
8
|
ClassTypeWithInstance,
|
|
11
9
|
ClassTypeWithInstanceAndArgument,
|
|
10
|
+
InjectionTokenSchemaType,
|
|
12
11
|
} from '../injection-token.mjs'
|
|
13
12
|
import type { Factory, FactoryWithArgs } from '../interfaces/index.mjs'
|
|
14
13
|
import type { Registry } from '../registry.mjs'
|
|
@@ -37,7 +36,7 @@ export function Injectable<R>(options: {
|
|
|
37
36
|
target: T,
|
|
38
37
|
context: ClassDecoratorContext,
|
|
39
38
|
) => T
|
|
40
|
-
export function Injectable<S extends
|
|
39
|
+
export function Injectable<S extends InjectionTokenSchemaType>(options: {
|
|
41
40
|
scope?: InjectableScope
|
|
42
41
|
type?: InjectableType.Class
|
|
43
42
|
token: InjectionToken<undefined, S>
|
|
@@ -45,7 +44,7 @@ export function Injectable<S extends AnyZodObject>(options: {
|
|
|
45
44
|
target: T,
|
|
46
45
|
context: ClassDecoratorContext,
|
|
47
46
|
) => T
|
|
48
|
-
export function Injectable<R, S extends
|
|
47
|
+
export function Injectable<R, S extends InjectionTokenSchemaType>(options: {
|
|
49
48
|
scope?: InjectableScope
|
|
50
49
|
type?: InjectableType.Class
|
|
51
50
|
token: InjectionToken<R, S>
|
|
@@ -57,15 +56,14 @@ export function Injectable<T extends ClassType>(options: {
|
|
|
57
56
|
scope?: InjectableScope
|
|
58
57
|
token: InjectionToken<T, undefined>
|
|
59
58
|
}): (target: T, context: ClassDecoratorContext) => T
|
|
60
|
-
|
|
61
|
-
export function Injectable<R, S extends AnyZodObject>(options: {
|
|
59
|
+
export function Injectable<R, S extends InjectionTokenSchemaType>(options: {
|
|
62
60
|
scope?: InjectableScope
|
|
63
61
|
type: InjectableType.Factory
|
|
64
62
|
token: InjectionToken<R, S>
|
|
65
63
|
}): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(
|
|
66
64
|
target: T,
|
|
67
65
|
context: ClassDecoratorContext,
|
|
68
|
-
) => T
|
|
66
|
+
) => T
|
|
69
67
|
export function Injectable<R>(options: {
|
|
70
68
|
scope?: InjectableScope
|
|
71
69
|
type: InjectableType.Factory
|
|
@@ -73,7 +71,7 @@ export function Injectable<R>(options: {
|
|
|
73
71
|
}): <T extends ClassTypeWithInstance<Factory<R>>>(
|
|
74
72
|
target: T,
|
|
75
73
|
context: ClassDecoratorContext,
|
|
76
|
-
) => T
|
|
74
|
+
) => T
|
|
77
75
|
export function Injectable({
|
|
78
76
|
scope = InjectableScope.Singleton,
|
|
79
77
|
type = InjectableType.Class,
|
package/src/injection-token.mts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AnyZodObject } from 'zod'
|
|
|
2
2
|
|
|
3
3
|
import { randomUUID } from 'crypto'
|
|
4
4
|
|
|
5
|
-
import { z, ZodOptional } from 'zod'
|
|
5
|
+
import { z, ZodOptional, ZodRecord } from 'zod'
|
|
6
6
|
|
|
7
7
|
export type ClassType = new (...args: any[]) => any
|
|
8
8
|
export type ClassTypeWithArgument<Arg> = new (arg: Arg) => any
|
|
@@ -10,9 +10,19 @@ export type ClassTypeWithArgument<Arg> = new (arg: Arg) => any
|
|
|
10
10
|
export type ClassTypeWithInstance<T> = new (...args: any[]) => T
|
|
11
11
|
export type ClassTypeWithInstanceAndArgument<T, Arg> = new (arg: Arg) => T
|
|
12
12
|
|
|
13
|
+
export type BaseInjectionTokenSchemaType = AnyZodObject | ZodRecord
|
|
14
|
+
|
|
15
|
+
export type OptionalInjectionTokenSchemaType =
|
|
16
|
+
| ZodOptional<AnyZodObject>
|
|
17
|
+
| ZodOptional<ZodRecord>
|
|
18
|
+
|
|
19
|
+
export type InjectionTokenSchemaType =
|
|
20
|
+
| BaseInjectionTokenSchemaType
|
|
21
|
+
| OptionalInjectionTokenSchemaType
|
|
22
|
+
|
|
13
23
|
export class InjectionToken<
|
|
14
24
|
T,
|
|
15
|
-
S extends
|
|
25
|
+
S extends InjectionTokenSchemaType | unknown = unknown,
|
|
16
26
|
> {
|
|
17
27
|
public id = randomUUID()
|
|
18
28
|
private formattedName: string | null = null
|
|
@@ -25,12 +35,12 @@ export class InjectionToken<
|
|
|
25
35
|
static create<T extends ClassType>(
|
|
26
36
|
name: T,
|
|
27
37
|
): InjectionToken<InstanceType<T>, undefined>
|
|
28
|
-
static create<
|
|
29
|
-
T
|
|
30
|
-
Schema
|
|
31
|
-
|
|
38
|
+
static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(
|
|
39
|
+
name: T,
|
|
40
|
+
schema: Schema,
|
|
41
|
+
): InjectionToken<InstanceType<T>, Schema>
|
|
32
42
|
static create<T>(name: string | symbol): InjectionToken<T, undefined>
|
|
33
|
-
static create<T, Schema extends
|
|
43
|
+
static create<T, Schema extends InjectionTokenSchemaType>(
|
|
34
44
|
name: string | any,
|
|
35
45
|
schema: Schema,
|
|
36
46
|
): InjectionToken<T, Schema>
|
|
@@ -39,14 +49,14 @@ export class InjectionToken<
|
|
|
39
49
|
return new InjectionToken(name, schema)
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
static bound<T, S extends
|
|
52
|
+
static bound<T, S extends InjectionTokenSchemaType>(
|
|
43
53
|
token: InjectionToken<T, S>,
|
|
44
54
|
value: z.input<S>,
|
|
45
55
|
): BoundInjectionToken<T, S> {
|
|
46
56
|
return new BoundInjectionToken(token, value)
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
static factory<T, S extends
|
|
59
|
+
static factory<T, S extends InjectionTokenSchemaType>(
|
|
50
60
|
token: InjectionToken<T, S>,
|
|
51
61
|
factory: () => Promise<z.input<S>>,
|
|
52
62
|
): FactoryInjectionToken<T, S> {
|
|
@@ -77,13 +87,10 @@ export class InjectionToken<
|
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
export class BoundInjectionToken<
|
|
81
|
-
T,
|
|
82
|
-
S extends AnyZodObject | ZodOptional<AnyZodObject>,
|
|
83
|
-
> {
|
|
90
|
+
export class BoundInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
84
91
|
public id: string
|
|
85
92
|
public name: string | symbol | ClassType
|
|
86
|
-
public schema:
|
|
93
|
+
public schema: InjectionTokenSchemaType
|
|
87
94
|
|
|
88
95
|
constructor(
|
|
89
96
|
public readonly token: InjectionToken<T, S>,
|
|
@@ -91,7 +98,7 @@ export class BoundInjectionToken<
|
|
|
91
98
|
) {
|
|
92
99
|
this.name = token.name
|
|
93
100
|
this.id = token.id
|
|
94
|
-
this.schema = token.schema as
|
|
101
|
+
this.schema = token.schema as InjectionTokenSchemaType
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
toString() {
|
|
@@ -99,15 +106,12 @@ export class BoundInjectionToken<
|
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
export class FactoryInjectionToken<
|
|
103
|
-
T,
|
|
104
|
-
S extends AnyZodObject | ZodOptional<AnyZodObject>,
|
|
105
|
-
> {
|
|
109
|
+
export class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
106
110
|
public value?: z.input<S>
|
|
107
111
|
public resolved = false
|
|
108
112
|
public id: string
|
|
109
113
|
public name: string | symbol | ClassType
|
|
110
|
-
public schema:
|
|
114
|
+
public schema: InjectionTokenSchemaType
|
|
111
115
|
|
|
112
116
|
constructor(
|
|
113
117
|
public readonly token: InjectionToken<T, S>,
|
|
@@ -115,7 +119,7 @@ export class FactoryInjectionToken<
|
|
|
115
119
|
) {
|
|
116
120
|
this.name = token.name
|
|
117
121
|
this.id = token.id
|
|
118
|
-
this.schema = token.schema as
|
|
122
|
+
this.schema = token.schema as InjectionTokenSchemaType
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
async resolve(): Promise<z.input<S>> {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { AnyZodObject } from 'zod'
|
|
2
|
-
|
|
3
1
|
import { z } from 'zod'
|
|
4
2
|
|
|
3
|
+
import type { InjectionTokenSchemaType } from '../injection-token.mjs'
|
|
4
|
+
|
|
5
5
|
export interface Factory<T> {
|
|
6
6
|
create(ctx?: any): Promise<T> | T
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export interface FactoryWithArgs<T, A extends
|
|
9
|
+
export interface FactoryWithArgs<T, A extends InjectionTokenSchemaType> {
|
|
10
10
|
create(ctx: any, args: z.output<A>): Promise<T> | T
|
|
11
11
|
}
|
package/src/service-locator.mts
CHANGED
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
import type { AnyZodObject, z, ZodOptional } from 'zod'
|
|
4
4
|
|
|
5
5
|
import type { FactoryContext } from './factory-context.mjs'
|
|
6
|
+
import type {
|
|
7
|
+
BaseInjectionTokenSchemaType,
|
|
8
|
+
InjectionTokenSchemaType,
|
|
9
|
+
OptionalInjectionTokenSchemaType,
|
|
10
|
+
} from './injection-token.mjs'
|
|
6
11
|
import type { Registry } from './registry.mjs'
|
|
7
12
|
import type { ServiceLocatorInstanceHolder } from './service-locator-instance-holder.mjs'
|
|
8
13
|
|
|
@@ -98,13 +103,15 @@ export class ServiceLocator {
|
|
|
98
103
|
public removeInstance<Instance>(
|
|
99
104
|
token: InjectionToken<Instance, undefined>,
|
|
100
105
|
): void
|
|
101
|
-
public removeInstance<
|
|
102
|
-
Instance,
|
|
103
|
-
Schema extends AnyZodObject | ZodOptional<AnyZodObject>,
|
|
104
|
-
>(
|
|
106
|
+
public removeInstance<Instance, Schema extends BaseInjectionTokenSchemaType>(
|
|
105
107
|
token: InjectionToken<Instance, Schema>,
|
|
106
108
|
args: z.input<Schema>,
|
|
107
109
|
): void
|
|
110
|
+
public removeInstance<
|
|
111
|
+
Instance,
|
|
112
|
+
Schema extends OptionalInjectionTokenSchemaType,
|
|
113
|
+
>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): void
|
|
114
|
+
|
|
108
115
|
public removeInstance(
|
|
109
116
|
token:
|
|
110
117
|
| InjectionToken<any, any>
|
|
@@ -116,18 +123,25 @@ export class ServiceLocator {
|
|
|
116
123
|
const instanceName = this.getInstanceIdentifier(token, args)
|
|
117
124
|
return this.invalidate(instanceName)
|
|
118
125
|
}
|
|
119
|
-
|
|
126
|
+
|
|
127
|
+
private resolveTokenArgs<
|
|
128
|
+
Instance,
|
|
129
|
+
Schema extends BaseInjectionTokenSchemaType,
|
|
130
|
+
>(
|
|
120
131
|
token: InjectionToken<Instance, Schema>,
|
|
121
132
|
args: z.input<Schema>,
|
|
122
133
|
): [undefined, z.output<Schema>] | [UnknownError]
|
|
123
|
-
private resolveTokenArgs<
|
|
134
|
+
private resolveTokenArgs<
|
|
135
|
+
Instance,
|
|
136
|
+
Schema extends OptionalInjectionTokenSchemaType,
|
|
137
|
+
>(
|
|
124
138
|
token: InjectionToken<Instance, Schema>,
|
|
125
139
|
args?: z.input<Schema>,
|
|
126
140
|
): [undefined, z.output<Schema>] | [UnknownError]
|
|
127
|
-
private resolveTokenArgs<Instance, Schema extends
|
|
141
|
+
private resolveTokenArgs<Instance, Schema extends InjectionTokenSchemaType>(
|
|
128
142
|
token: BoundInjectionToken<Instance, Schema>,
|
|
129
143
|
): [undefined, z.output<Schema>] | [UnknownError]
|
|
130
|
-
private resolveTokenArgs<Instance, Schema extends
|
|
144
|
+
private resolveTokenArgs<Instance, Schema extends InjectionTokenSchemaType>(
|
|
131
145
|
token: FactoryInjectionToken<Instance, Schema>,
|
|
132
146
|
): [undefined, z.output<Schema>] | [FactoryTokenNotResolved | UnknownError]
|
|
133
147
|
private resolveTokenArgs(
|
|
@@ -161,13 +175,13 @@ export class ServiceLocator {
|
|
|
161
175
|
return [undefined, validatedArgs?.data]
|
|
162
176
|
}
|
|
163
177
|
|
|
164
|
-
public getInstanceIdentifier<Instance, Schema extends AnyZodObject>(
|
|
165
|
-
token: InjectionToken<Instance, Schema>,
|
|
166
|
-
args: z.input<Schema>,
|
|
167
|
-
): string
|
|
168
178
|
public getInstanceIdentifier<
|
|
169
179
|
Instance,
|
|
170
|
-
Schema extends
|
|
180
|
+
Schema extends BaseInjectionTokenSchemaType,
|
|
181
|
+
>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): string
|
|
182
|
+
public getInstanceIdentifier<
|
|
183
|
+
Instance,
|
|
184
|
+
Schema extends OptionalInjectionTokenSchemaType,
|
|
171
185
|
>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): string
|
|
172
186
|
public getInstanceIdentifier<Instance>(
|
|
173
187
|
token: InjectionToken<Instance, undefined>,
|
|
@@ -195,11 +209,11 @@ export class ServiceLocator {
|
|
|
195
209
|
return this.makeInstanceName(token as InjectionToken<any>, realArgs)
|
|
196
210
|
}
|
|
197
211
|
|
|
198
|
-
public getInstance<Instance, Schema extends
|
|
212
|
+
public getInstance<Instance, Schema extends BaseInjectionTokenSchemaType>(
|
|
199
213
|
token: InjectionToken<Instance, Schema>,
|
|
200
214
|
args: z.input<Schema>,
|
|
201
215
|
): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>
|
|
202
|
-
public getInstance<Instance, Schema extends
|
|
216
|
+
public getInstance<Instance, Schema extends OptionalInjectionTokenSchemaType>(
|
|
203
217
|
token: InjectionToken<Instance, Schema>,
|
|
204
218
|
args?: z.input<Schema>,
|
|
205
219
|
): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>
|
|
@@ -273,7 +287,7 @@ export class ServiceLocator {
|
|
|
273
287
|
|
|
274
288
|
public async getOrThrowInstance<
|
|
275
289
|
Instance,
|
|
276
|
-
Schema extends
|
|
290
|
+
Schema extends InjectionTokenSchemaType | undefined,
|
|
277
291
|
>(
|
|
278
292
|
token: InjectionToken<Instance, Schema>,
|
|
279
293
|
args: Schema extends AnyZodObject
|
|
@@ -301,7 +315,7 @@ export class ServiceLocator {
|
|
|
301
315
|
|
|
302
316
|
private async createInstance<
|
|
303
317
|
Instance,
|
|
304
|
-
Schema extends
|
|
318
|
+
Schema extends InjectionTokenSchemaType | undefined,
|
|
305
319
|
>(
|
|
306
320
|
instanceName: string,
|
|
307
321
|
token: InjectionToken<Instance, Schema>,
|
|
@@ -328,10 +342,10 @@ export class ServiceLocator {
|
|
|
328
342
|
|
|
329
343
|
private async resolveInstance<
|
|
330
344
|
Instance,
|
|
331
|
-
Schema extends
|
|
332
|
-
Args extends Schema extends
|
|
345
|
+
Schema extends InjectionTokenSchemaType | undefined,
|
|
346
|
+
Args extends Schema extends BaseInjectionTokenSchemaType
|
|
333
347
|
? z.input<Schema>
|
|
334
|
-
: Schema extends
|
|
348
|
+
: Schema extends OptionalInjectionTokenSchemaType
|
|
335
349
|
? z.input<Schema> | undefined
|
|
336
350
|
: undefined,
|
|
337
351
|
>(
|
|
@@ -455,7 +469,7 @@ export class ServiceLocator {
|
|
|
455
469
|
|
|
456
470
|
public getSyncInstance<
|
|
457
471
|
Instance,
|
|
458
|
-
Schema extends
|
|
472
|
+
Schema extends InjectionTokenSchemaType | undefined,
|
|
459
473
|
>(
|
|
460
474
|
token: InjectionToken<Instance, Schema>,
|
|
461
475
|
args: Schema extends AnyZodObject
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { AnyZodObject, z
|
|
1
|
+
import type { AnyZodObject, z } from 'zod'
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
+
BaseInjectionTokenSchemaType,
|
|
4
5
|
BoundInjectionToken,
|
|
5
6
|
ClassType,
|
|
6
7
|
FactoryInjectionToken,
|
|
7
8
|
InjectionToken,
|
|
9
|
+
OptionalInjectionTokenSchemaType,
|
|
8
10
|
} from '../injection-token.mjs'
|
|
9
11
|
import type { ServiceLocator } from '../service-locator.mjs'
|
|
10
12
|
|
|
@@ -16,11 +18,11 @@ export interface CreateInjectorsOptions {
|
|
|
16
18
|
|
|
17
19
|
export interface Injectors {
|
|
18
20
|
inject<T extends ClassType>(token: T): Promise<InstanceType<T>>
|
|
19
|
-
inject<T, S extends
|
|
21
|
+
inject<T, S extends BaseInjectionTokenSchemaType>(
|
|
20
22
|
token: InjectionToken<T, S>,
|
|
21
23
|
args: z.input<S>,
|
|
22
24
|
): Promise<T>
|
|
23
|
-
inject<T, S extends
|
|
25
|
+
inject<T, S extends OptionalInjectionTokenSchemaType>(
|
|
24
26
|
token: InjectionToken<T, S>,
|
|
25
27
|
args?: z.input<S>,
|
|
26
28
|
): Promise<T>
|
|
@@ -29,11 +31,11 @@ export interface Injectors {
|
|
|
29
31
|
inject<T>(token: FactoryInjectionToken<T, any>): Promise<T>
|
|
30
32
|
|
|
31
33
|
syncInject<T extends ClassType>(token: T): InstanceType<T>
|
|
32
|
-
syncInject<T, S extends
|
|
34
|
+
syncInject<T, S extends BaseInjectionTokenSchemaType>(
|
|
33
35
|
token: InjectionToken<T, S>,
|
|
34
36
|
args: z.input<S>,
|
|
35
37
|
): T
|
|
36
|
-
syncInject<T, S extends
|
|
38
|
+
syncInject<T, S extends OptionalInjectionTokenSchemaType>(
|
|
37
39
|
token: InjectionToken<T, S>,
|
|
38
40
|
args?: z.input<S>,
|
|
39
41
|
): T
|