@navios/di 0.1.5 → 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.
@@ -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 class BoundInjectionToken<T, S extends AnyZodObject | ZodOptional<AnyZodObject>> {
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: AnyZodObject | ZodOptional<AnyZodObject>;
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 AnyZodObject | ZodOptional<AnyZodObject>> {
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: AnyZodObject | ZodOptional<AnyZodObject>;
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 AnyZodObject> {
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 }
@@ -180,55 +185,41 @@ declare const inject: Injectors['inject'];
180
185
  export { inject }
181
186
  export { inject as inject_alias_1 }
182
187
 
183
- declare function Injectable(): <T extends ClassType>(target: T, context: ClassDecoratorContext) => T & {
184
- [InjectableTokenMeta]: InjectionToken<InstanceType<T>, undefined>;
185
- };
188
+ declare function Injectable(): <T extends ClassType>(target: T, context: ClassDecoratorContext) => T;
186
189
 
187
190
  declare function Injectable<R>(options: {
188
191
  scope?: InjectableScope;
189
192
  type: InjectableType.Factory;
190
- }): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T & {
191
- [InjectableTokenMeta]: InjectionToken<R, undefined>;
192
- };
193
+ }): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T;
193
194
 
194
- declare function Injectable<S extends AnyZodObject>(options: {
195
+ declare function Injectable<S extends InjectionTokenSchemaType>(options: {
195
196
  scope?: InjectableScope;
196
197
  type?: InjectableType.Class;
197
198
  token: InjectionToken<undefined, S>;
198
- }): <T extends ClassTypeWithArgument<z.output<S>>>(target: T, context: ClassDecoratorContext) => T & {
199
- [InjectableTokenMeta]: InjectionToken<T, S>;
200
- };
199
+ }): <T extends ClassTypeWithArgument<z.output<S>>>(target: T, context: ClassDecoratorContext) => T;
201
200
 
202
- declare function Injectable<R, S extends AnyZodObject>(options: {
201
+ declare function Injectable<R, S extends InjectionTokenSchemaType>(options: {
203
202
  scope?: InjectableScope;
204
203
  type?: InjectableType.Class;
205
204
  token: InjectionToken<R, S>;
206
- }): <T extends ClassTypeWithInstanceAndArgument<R, z.output<S>>>(target: T, context: ClassDecoratorContext) => T & {
207
- [InjectableTokenMeta]: InjectionToken<R, S>;
208
- };
205
+ }): <T extends ClassTypeWithInstanceAndArgument<R, z.output<S>>>(target: T, context: ClassDecoratorContext) => T;
209
206
 
210
207
  declare function Injectable<T extends ClassType>(options: {
211
208
  scope?: InjectableScope;
212
209
  token: InjectionToken<T, undefined>;
213
- }): (target: T, context: ClassDecoratorContext) => T & {
214
- [InjectableTokenMeta]: InjectionToken<InstanceType<T>, undefined>;
215
- };
210
+ }): (target: T, context: ClassDecoratorContext) => T;
216
211
 
217
- declare function Injectable<R, S extends AnyZodObject>(options: {
212
+ declare function Injectable<R, S extends InjectionTokenSchemaType>(options: {
218
213
  scope?: InjectableScope;
219
214
  type: InjectableType.Factory;
220
215
  token: InjectionToken<R, S>;
221
- }): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(target: T, context: ClassDecoratorContext) => T & {
222
- [InjectableTokenMeta]: InjectionToken<R, S>;
223
- };
216
+ }): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(target: T, context: ClassDecoratorContext) => T;
224
217
 
225
218
  declare function Injectable<R>(options: {
226
219
  scope?: InjectableScope;
227
220
  type: InjectableType.Factory;
228
221
  token: InjectionToken<R, undefined>;
229
- }): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T & {
230
- [InjectableTokenMeta]: InjectionToken<R, undefined>;
231
- };
222
+ }): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T;
232
223
  export { Injectable }
233
224
  export { Injectable as Injectable_alias_1 }
234
225
  export { Injectable as Injectable_alias_2 }
@@ -274,34 +265,38 @@ declare type InjectionFactory<T = unknown, Args = unknown> = (ctx: FactoryContex
274
265
  export { InjectionFactory }
275
266
  export { InjectionFactory as InjectionFactory_alias_1 }
276
267
 
277
- declare class InjectionToken<T, S extends AnyZodObject | ZodOptional<AnyZodObject> | unknown = unknown> {
268
+ declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown> {
278
269
  readonly name: string | symbol | ClassType;
279
270
  readonly schema: AnyZodObject | undefined;
280
271
  id: `${string}-${string}-${string}-${string}-${string}`;
281
272
  private formattedName;
282
273
  constructor(name: string | symbol | ClassType, schema: AnyZodObject | undefined);
283
274
  static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
284
- static create<T extends ClassType, Schema extends AnyZodObject | ZodOptional<AnyZodObject>>(name: T, schema: Schema): InjectionToken<InstanceType<T>, Schema>;
275
+ static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): InjectionToken<InstanceType<T>, Schema>;
285
276
  static create<T>(name: string | symbol): InjectionToken<T, undefined>;
286
- static create<T, Schema extends AnyZodObject | ZodOptional<AnyZodObject>>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
287
- static bound<T, S extends AnyZodObject | ZodOptional<AnyZodObject>>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
288
- static factory<T, S extends AnyZodObject | ZodOptional<AnyZodObject>>(token: InjectionToken<T, S>, factory: () => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
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>;
289
280
  static refineType<T>(token: BoundInjectionToken<any, any>): BoundInjectionToken<T, any>;
290
281
  toString(): string;
291
282
  }
292
283
  export { InjectionToken }
293
284
  export { InjectionToken as InjectionToken_alias_1 }
294
285
 
286
+ declare type InjectionTokenSchemaType = BaseInjectionTokenSchemaType | OptionalInjectionTokenSchemaType;
287
+ export { InjectionTokenSchemaType }
288
+ export { InjectionTokenSchemaType as InjectionTokenSchemaType_alias_1 }
289
+
295
290
  declare interface Injectors {
296
291
  inject<T extends ClassType>(token: T): Promise<InstanceType<T>>;
297
- inject<T, S extends AnyZodObject>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
298
- inject<T, S extends ZodOptional<AnyZodObject>>(token: InjectionToken<T, S>, args?: z.input<S>): Promise<T>;
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>;
299
294
  inject<T>(token: InjectionToken<T, undefined>): Promise<T>;
300
295
  inject<T>(token: BoundInjectionToken<T, any>): Promise<T>;
301
296
  inject<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
302
297
  syncInject<T extends ClassType>(token: T): InstanceType<T>;
303
- syncInject<T, S extends AnyZodObject>(token: InjectionToken<T, S>, args: z.input<S>): T;
304
- syncInject<T, S extends ZodOptional<AnyZodObject>>(token: InjectionToken<T, S>, args?: z.input<S>): T;
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;
305
300
  syncInject<T>(token: InjectionToken<T, undefined>): T;
306
301
  syncInject<T>(token: BoundInjectionToken<T, any>): T;
307
302
  syncInject<T>(token: FactoryInjectionToken<T, any>): T;
@@ -348,6 +343,10 @@ declare function makeProxyServiceLocator(serviceLocator: ServiceLocator, ctx: Fa
348
343
  export { makeProxyServiceLocator }
349
344
  export { makeProxyServiceLocator as makeProxyServiceLocator_alias_1 }
350
345
 
346
+ declare type OptionalInjectionTokenSchemaType = ZodOptional<AnyZodObject> | ZodOptional<ZodRecord>;
347
+ export { OptionalInjectionTokenSchemaType }
348
+ export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
349
+
351
350
  declare const provideServiceLocator: Injectors['provideServiceLocator'];
352
351
  export { provideServiceLocator }
353
352
  export { provideServiceLocator as provideServiceLocator_alias_1 }
@@ -397,24 +396,25 @@ declare class ServiceLocator {
397
396
  removeInstance<Instance>(token: BoundInjectionToken<Instance, any>): void;
398
397
  removeInstance<Instance>(token: FactoryInjectionToken<Instance, any>): void;
399
398
  removeInstance<Instance>(token: InjectionToken<Instance, undefined>): void;
400
- removeInstance<Instance, Schema extends AnyZodObject | ZodOptional<AnyZodObject>>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): void;
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;
401
401
  private resolveTokenArgs;
402
- getInstanceIdentifier<Instance, Schema extends AnyZodObject>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): string;
403
- getInstanceIdentifier<Instance, Schema extends ZodOptional<AnyZodObject>>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): string;
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;
404
404
  getInstanceIdentifier<Instance>(token: InjectionToken<Instance, undefined>): string;
405
405
  getInstanceIdentifier<Instance>(token: BoundInjectionToken<Instance, any>): string;
406
406
  getInstanceIdentifier<Instance>(token: FactoryInjectionToken<Instance, any>): string;
407
- getInstance<Instance, Schema extends AnyZodObject>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
408
- getInstance<Instance, Schema extends ZodOptional<AnyZodObject>>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
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]>;
409
409
  getInstance<Instance>(token: InjectionToken<Instance, undefined>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
410
410
  getInstance<Instance>(token: BoundInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
411
411
  getInstance<Instance>(token: FactoryInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
412
- getOrThrowInstance<Instance, Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends AnyZodObject ? z.input<Schema> : Schema extends ZodOptional<AnyZodObject> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
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>;
413
413
  private notifyListeners;
414
414
  private createInstance;
415
415
  private resolveInstance;
416
416
  private createFactoryContext;
417
- getSyncInstance<Instance, Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends AnyZodObject ? z.input<Schema> : Schema extends ZodOptional<AnyZodObject> ? z.input<Schema> | undefined : undefined): Instance | null;
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;
418
418
  invalidate(service: string, round?: number): Promise<any>;
419
419
  ready(): Promise<null>;
420
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 class BoundInjectionToken<T, S extends AnyZodObject | ZodOptional<AnyZodObject>> {
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: AnyZodObject | ZodOptional<AnyZodObject>;
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 AnyZodObject | ZodOptional<AnyZodObject>> {
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: AnyZodObject | ZodOptional<AnyZodObject>;
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 AnyZodObject> {
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 }
@@ -180,55 +185,41 @@ declare const inject: Injectors['inject'];
180
185
  export { inject }
181
186
  export { inject as inject_alias_1 }
182
187
 
183
- declare function Injectable(): <T extends ClassType>(target: T, context: ClassDecoratorContext) => T & {
184
- [InjectableTokenMeta]: InjectionToken<InstanceType<T>, undefined>;
185
- };
188
+ declare function Injectable(): <T extends ClassType>(target: T, context: ClassDecoratorContext) => T;
186
189
 
187
190
  declare function Injectable<R>(options: {
188
191
  scope?: InjectableScope;
189
192
  type: InjectableType.Factory;
190
- }): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T & {
191
- [InjectableTokenMeta]: InjectionToken<R, undefined>;
192
- };
193
+ }): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T;
193
194
 
194
- declare function Injectable<S extends AnyZodObject>(options: {
195
+ declare function Injectable<S extends InjectionTokenSchemaType>(options: {
195
196
  scope?: InjectableScope;
196
197
  type?: InjectableType.Class;
197
198
  token: InjectionToken<undefined, S>;
198
- }): <T extends ClassTypeWithArgument<z.output<S>>>(target: T, context: ClassDecoratorContext) => T & {
199
- [InjectableTokenMeta]: InjectionToken<T, S>;
200
- };
199
+ }): <T extends ClassTypeWithArgument<z.output<S>>>(target: T, context: ClassDecoratorContext) => T;
201
200
 
202
- declare function Injectable<R, S extends AnyZodObject>(options: {
201
+ declare function Injectable<R, S extends InjectionTokenSchemaType>(options: {
203
202
  scope?: InjectableScope;
204
203
  type?: InjectableType.Class;
205
204
  token: InjectionToken<R, S>;
206
- }): <T extends ClassTypeWithInstanceAndArgument<R, z.output<S>>>(target: T, context: ClassDecoratorContext) => T & {
207
- [InjectableTokenMeta]: InjectionToken<R, S>;
208
- };
205
+ }): <T extends ClassTypeWithInstanceAndArgument<R, z.output<S>>>(target: T, context: ClassDecoratorContext) => T;
209
206
 
210
207
  declare function Injectable<T extends ClassType>(options: {
211
208
  scope?: InjectableScope;
212
209
  token: InjectionToken<T, undefined>;
213
- }): (target: T, context: ClassDecoratorContext) => T & {
214
- [InjectableTokenMeta]: InjectionToken<InstanceType<T>, undefined>;
215
- };
210
+ }): (target: T, context: ClassDecoratorContext) => T;
216
211
 
217
- declare function Injectable<R, S extends AnyZodObject>(options: {
212
+ declare function Injectable<R, S extends InjectionTokenSchemaType>(options: {
218
213
  scope?: InjectableScope;
219
214
  type: InjectableType.Factory;
220
215
  token: InjectionToken<R, S>;
221
- }): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(target: T, context: ClassDecoratorContext) => T & {
222
- [InjectableTokenMeta]: InjectionToken<R, S>;
223
- };
216
+ }): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(target: T, context: ClassDecoratorContext) => T;
224
217
 
225
218
  declare function Injectable<R>(options: {
226
219
  scope?: InjectableScope;
227
220
  type: InjectableType.Factory;
228
221
  token: InjectionToken<R, undefined>;
229
- }): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T & {
230
- [InjectableTokenMeta]: InjectionToken<R, undefined>;
231
- };
222
+ }): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context: ClassDecoratorContext) => T;
232
223
  export { Injectable }
233
224
  export { Injectable as Injectable_alias_1 }
234
225
  export { Injectable as Injectable_alias_2 }
@@ -274,34 +265,38 @@ declare type InjectionFactory<T = unknown, Args = unknown> = (ctx: FactoryContex
274
265
  export { InjectionFactory }
275
266
  export { InjectionFactory as InjectionFactory_alias_1 }
276
267
 
277
- declare class InjectionToken<T, S extends AnyZodObject | ZodOptional<AnyZodObject> | unknown = unknown> {
268
+ declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown> {
278
269
  readonly name: string | symbol | ClassType;
279
270
  readonly schema: AnyZodObject | undefined;
280
271
  id: `${string}-${string}-${string}-${string}-${string}`;
281
272
  private formattedName;
282
273
  constructor(name: string | symbol | ClassType, schema: AnyZodObject | undefined);
283
274
  static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
284
- static create<T extends ClassType, Schema extends AnyZodObject | ZodOptional<AnyZodObject>>(name: T, schema: Schema): InjectionToken<InstanceType<T>, Schema>;
275
+ static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): InjectionToken<InstanceType<T>, Schema>;
285
276
  static create<T>(name: string | symbol): InjectionToken<T, undefined>;
286
- static create<T, Schema extends AnyZodObject | ZodOptional<AnyZodObject>>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
287
- static bound<T, S extends AnyZodObject | ZodOptional<AnyZodObject>>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
288
- static factory<T, S extends AnyZodObject | ZodOptional<AnyZodObject>>(token: InjectionToken<T, S>, factory: () => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
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>;
289
280
  static refineType<T>(token: BoundInjectionToken<any, any>): BoundInjectionToken<T, any>;
290
281
  toString(): string;
291
282
  }
292
283
  export { InjectionToken }
293
284
  export { InjectionToken as InjectionToken_alias_1 }
294
285
 
286
+ declare type InjectionTokenSchemaType = BaseInjectionTokenSchemaType | OptionalInjectionTokenSchemaType;
287
+ export { InjectionTokenSchemaType }
288
+ export { InjectionTokenSchemaType as InjectionTokenSchemaType_alias_1 }
289
+
295
290
  declare interface Injectors {
296
291
  inject<T extends ClassType>(token: T): Promise<InstanceType<T>>;
297
- inject<T, S extends AnyZodObject>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
298
- inject<T, S extends ZodOptional<AnyZodObject>>(token: InjectionToken<T, S>, args?: z.input<S>): Promise<T>;
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>;
299
294
  inject<T>(token: InjectionToken<T, undefined>): Promise<T>;
300
295
  inject<T>(token: BoundInjectionToken<T, any>): Promise<T>;
301
296
  inject<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
302
297
  syncInject<T extends ClassType>(token: T): InstanceType<T>;
303
- syncInject<T, S extends AnyZodObject>(token: InjectionToken<T, S>, args: z.input<S>): T;
304
- syncInject<T, S extends ZodOptional<AnyZodObject>>(token: InjectionToken<T, S>, args?: z.input<S>): T;
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;
305
300
  syncInject<T>(token: InjectionToken<T, undefined>): T;
306
301
  syncInject<T>(token: BoundInjectionToken<T, any>): T;
307
302
  syncInject<T>(token: FactoryInjectionToken<T, any>): T;
@@ -348,6 +343,10 @@ declare function makeProxyServiceLocator(serviceLocator: ServiceLocator, ctx: Fa
348
343
  export { makeProxyServiceLocator }
349
344
  export { makeProxyServiceLocator as makeProxyServiceLocator_alias_1 }
350
345
 
346
+ declare type OptionalInjectionTokenSchemaType = ZodOptional<AnyZodObject> | ZodOptional<ZodRecord>;
347
+ export { OptionalInjectionTokenSchemaType }
348
+ export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
349
+
351
350
  declare const provideServiceLocator: Injectors['provideServiceLocator'];
352
351
  export { provideServiceLocator }
353
352
  export { provideServiceLocator as provideServiceLocator_alias_1 }
@@ -397,24 +396,25 @@ declare class ServiceLocator {
397
396
  removeInstance<Instance>(token: BoundInjectionToken<Instance, any>): void;
398
397
  removeInstance<Instance>(token: FactoryInjectionToken<Instance, any>): void;
399
398
  removeInstance<Instance>(token: InjectionToken<Instance, undefined>): void;
400
- removeInstance<Instance, Schema extends AnyZodObject | ZodOptional<AnyZodObject>>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): void;
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;
401
401
  private resolveTokenArgs;
402
- getInstanceIdentifier<Instance, Schema extends AnyZodObject>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): string;
403
- getInstanceIdentifier<Instance, Schema extends ZodOptional<AnyZodObject>>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): string;
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;
404
404
  getInstanceIdentifier<Instance>(token: InjectionToken<Instance, undefined>): string;
405
405
  getInstanceIdentifier<Instance>(token: BoundInjectionToken<Instance, any>): string;
406
406
  getInstanceIdentifier<Instance>(token: FactoryInjectionToken<Instance, any>): string;
407
- getInstance<Instance, Schema extends AnyZodObject>(token: InjectionToken<Instance, Schema>, args: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
408
- getInstance<Instance, Schema extends ZodOptional<AnyZodObject>>(token: InjectionToken<Instance, Schema>, args?: z.input<Schema>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
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]>;
409
409
  getInstance<Instance>(token: InjectionToken<Instance, undefined>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
410
410
  getInstance<Instance>(token: BoundInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
411
411
  getInstance<Instance>(token: FactoryInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
412
- getOrThrowInstance<Instance, Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends AnyZodObject ? z.input<Schema> : Schema extends ZodOptional<AnyZodObject> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
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>;
413
413
  private notifyListeners;
414
414
  private createInstance;
415
415
  private resolveInstance;
416
416
  private createFactoryContext;
417
- getSyncInstance<Instance, Schema extends AnyZodObject | ZodOptional<AnyZodObject> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends AnyZodObject ? z.input<Schema> : Schema extends ZodOptional<AnyZodObject> ? z.input<Schema> | undefined : undefined): Instance | null;
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;
418
418
  invalidate(service: string, round?: number): Promise<any>;
419
419
  ready(): Promise<null>;
420
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@navios/di",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "author": {
5
5
  "name": "Oleksandr Hanzha",
6
6
  "email": "alex@granted.name"
@@ -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'
@@ -29,48 +28,42 @@ export interface InjectableOptions {
29
28
  export function Injectable(): <T extends ClassType>(
30
29
  target: T,
31
30
  context: ClassDecoratorContext,
32
- ) => T & { [InjectableTokenMeta]: InjectionToken<InstanceType<T>, undefined> }
31
+ ) => T
33
32
  export function Injectable<R>(options: {
34
33
  scope?: InjectableScope
35
34
  type: InjectableType.Factory
36
35
  }): <T extends ClassTypeWithInstance<Factory<R>>>(
37
36
  target: T,
38
37
  context: ClassDecoratorContext,
39
- ) => T & { [InjectableTokenMeta]: InjectionToken<R, undefined> }
40
- export function Injectable<S extends AnyZodObject>(options: {
38
+ ) => T
39
+ export function Injectable<S extends InjectionTokenSchemaType>(options: {
41
40
  scope?: InjectableScope
42
41
  type?: InjectableType.Class
43
42
  token: InjectionToken<undefined, S>
44
43
  }): <T extends ClassTypeWithArgument<z.output<S>>>(
45
44
  target: T,
46
45
  context: ClassDecoratorContext,
47
- ) => T & { [InjectableTokenMeta]: InjectionToken<T, S> }
48
- export function Injectable<R, S extends AnyZodObject>(options: {
46
+ ) => T
47
+ export function Injectable<R, S extends InjectionTokenSchemaType>(options: {
49
48
  scope?: InjectableScope
50
49
  type?: InjectableType.Class
51
50
  token: InjectionToken<R, S>
52
51
  }): <T extends ClassTypeWithInstanceAndArgument<R, z.output<S>>>(
53
52
  target: T,
54
53
  context: ClassDecoratorContext,
55
- ) => T & { [InjectableTokenMeta]: InjectionToken<R, S> }
54
+ ) => T
56
55
  export function Injectable<T extends ClassType>(options: {
57
56
  scope?: InjectableScope
58
57
  token: InjectionToken<T, undefined>
59
- }): (
60
- target: T,
61
- context: ClassDecoratorContext,
62
- ) => T & {
63
- [InjectableTokenMeta]: InjectionToken<InstanceType<T>, undefined>
64
- }
65
-
66
- export function Injectable<R, S extends AnyZodObject>(options: {
58
+ }): (target: T, context: ClassDecoratorContext) => T
59
+ export function Injectable<R, S extends InjectionTokenSchemaType>(options: {
67
60
  scope?: InjectableScope
68
61
  type: InjectableType.Factory
69
62
  token: InjectionToken<R, S>
70
63
  }): <T extends ClassTypeWithInstance<FactoryWithArgs<R, S>>>(
71
64
  target: T,
72
65
  context: ClassDecoratorContext,
73
- ) => T & { [InjectableTokenMeta]: InjectionToken<R, S> }
66
+ ) => T
74
67
  export function Injectable<R>(options: {
75
68
  scope?: InjectableScope
76
69
  type: InjectableType.Factory
@@ -78,7 +71,7 @@ export function Injectable<R>(options: {
78
71
  }): <T extends ClassTypeWithInstance<Factory<R>>>(
79
72
  target: T,
80
73
  context: ClassDecoratorContext,
81
- ) => T & { [InjectableTokenMeta]: InjectionToken<R, undefined> }
74
+ ) => T
82
75
  export function Injectable({
83
76
  scope = InjectableScope.Singleton,
84
77
  type = InjectableType.Class,
@@ -88,9 +81,7 @@ export function Injectable({
88
81
  return <T extends ClassType>(
89
82
  target: T,
90
83
  context: ClassDecoratorContext,
91
- ): T & {
92
- [InjectableTokenMeta]: InjectionToken<any, any>
93
- } => {
84
+ ): T => {
94
85
  if (context.kind !== 'class') {
95
86
  throw new Error(
96
87
  '[ServiceLocator] @Injectable decorator can only be used on classes.',
@@ -123,8 +114,6 @@ export function Injectable({
123
114
  // @ts-expect-error
124
115
  target[InjectableTokenMeta] = injectableToken
125
116
 
126
- return target as T & {
127
- [InjectableTokenMeta]: InjectionToken<any, any>
128
- }
117
+ return target
129
118
  }
130
119
  }
@@ -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 AnyZodObject | ZodOptional<AnyZodObject> | unknown = unknown,
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 extends ClassType,
30
- Schema extends AnyZodObject | ZodOptional<AnyZodObject>,
31
- >(name: T, schema: Schema): InjectionToken<InstanceType<T>, Schema>
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 AnyZodObject | ZodOptional<AnyZodObject>>(
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 AnyZodObject | ZodOptional<AnyZodObject>>(
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 AnyZodObject | ZodOptional<AnyZodObject>>(
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: AnyZodObject | ZodOptional<AnyZodObject>
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 AnyZodObject | ZodOptional<AnyZodObject>
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: AnyZodObject | ZodOptional<AnyZodObject>
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 AnyZodObject | ZodOptional<AnyZodObject>
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 AnyZodObject> {
9
+ export interface FactoryWithArgs<T, A extends InjectionTokenSchemaType> {
10
10
  create(ctx: any, args: z.output<A>): Promise<T> | T
11
11
  }
@@ -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
- private resolveTokenArgs<Instance, Schema extends AnyZodObject>(
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<Instance, Schema extends ZodOptional<AnyZodObject>>(
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 AnyZodObject>(
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 AnyZodObject>(
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 ZodOptional<AnyZodObject>,
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 AnyZodObject>(
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 ZodOptional<AnyZodObject>>(
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 AnyZodObject | ZodOptional<AnyZodObject> | undefined,
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 AnyZodObject | ZodOptional<AnyZodObject> | undefined,
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 AnyZodObject | ZodOptional<AnyZodObject> | undefined,
332
- Args extends Schema extends AnyZodObject
345
+ Schema extends InjectionTokenSchemaType | undefined,
346
+ Args extends Schema extends BaseInjectionTokenSchemaType
333
347
  ? z.input<Schema>
334
- : Schema extends ZodOptional<AnyZodObject>
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 AnyZodObject | ZodOptional<AnyZodObject> | undefined,
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, ZodOptional } from 'zod'
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 AnyZodObject>(
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 ZodOptional<AnyZodObject>>(
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 AnyZodObject>(
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 ZodOptional<AnyZodObject>>(
38
+ syncInject<T, S extends OptionalInjectionTokenSchemaType>(
37
39
  token: InjectionToken<T, S>,
38
40
  args?: z.input<S>,
39
41
  ): T