@navios/di 0.1.12 → 0.2.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/lib/_tsup-dts-rollup.d.mts +26 -26
- package/lib/_tsup-dts-rollup.d.ts +26 -26
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +5 -1
- package/lib/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/injectable.spec.mts +1 -1
- package/src/__tests__/injection-token.spec.mts +1 -1
- package/src/__type-tests__/inject.spec-d.mts +4 -4
- package/src/__type-tests__/injectable.spec-d.mts +258 -3
- package/src/decorators/injectable.decorator.mts +16 -13
- package/src/injection-token.mts +7 -9
- package/src/interfaces/factory.interface.mts +1 -1
- package/src/proxy-service-locator.mts +8 -8
- package/src/registry.mts +2 -4
- package/src/service-locator.mts +8 -8
- package/src/utils/get-injectors.mts +3 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { ZodOptional } from 'zod';
|
|
4
|
-
import { ZodRecord } from 'zod';
|
|
5
|
-
import type { ZodType } from 'zod';
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import type { ZodObject } from 'zod/v4';
|
|
3
|
+
import type { ZodOptional } from 'zod/v4';
|
|
4
|
+
import type { ZodRecord } from 'zod/v4';
|
|
5
|
+
import type { ZodType } from 'zod/v4';
|
|
6
6
|
|
|
7
|
-
declare type BaseInjectionTokenSchemaType =
|
|
7
|
+
declare type BaseInjectionTokenSchemaType = ZodObject<any> | ZodRecord;
|
|
8
8
|
export { BaseInjectionTokenSchemaType }
|
|
9
9
|
export { BaseInjectionTokenSchemaType as BaseInjectionTokenSchemaType_alias_1 }
|
|
10
10
|
|
|
@@ -150,7 +150,7 @@ export { FactoryNotFound as FactoryNotFound_alias_2 }
|
|
|
150
150
|
declare type FactoryRecord<Instance = any, Schema = any> = {
|
|
151
151
|
scope: InjectableScope;
|
|
152
152
|
originalToken: InjectionToken<Instance, Schema>;
|
|
153
|
-
factory: InjectionFactory<Instance, Schema extends
|
|
153
|
+
factory: InjectionFactory<Instance, Schema extends ZodObject<any> ? z.input<Schema> : unknown>;
|
|
154
154
|
};
|
|
155
155
|
export { FactoryRecord }
|
|
156
156
|
export { FactoryRecord as FactoryRecord_alias_1 }
|
|
@@ -194,17 +194,17 @@ declare const inject: Injectors['inject'];
|
|
|
194
194
|
export { inject }
|
|
195
195
|
export { inject as inject_alias_1 }
|
|
196
196
|
|
|
197
|
-
declare function Injectable(): <T extends ClassType>(target: T, context
|
|
197
|
+
declare function Injectable(): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
|
|
198
198
|
|
|
199
199
|
declare function Injectable(options: {
|
|
200
200
|
registry: Registry;
|
|
201
|
-
}): <T extends ClassType>(target: T, context
|
|
201
|
+
}): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
|
|
202
202
|
|
|
203
203
|
declare function Injectable<R>(options: {
|
|
204
204
|
scope?: InjectableScope;
|
|
205
205
|
type: InjectableType.Factory;
|
|
206
206
|
registry?: Registry;
|
|
207
|
-
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context
|
|
207
|
+
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context?: ClassDecoratorContext) => T;
|
|
208
208
|
|
|
209
209
|
declare function Injectable<Type, Schema>(options: {
|
|
210
210
|
scope?: InjectableScope;
|
|
@@ -212,10 +212,10 @@ declare function Injectable<Type, Schema>(options: {
|
|
|
212
212
|
token: InjectionToken<Type, Schema>;
|
|
213
213
|
registry?: Registry;
|
|
214
214
|
}): Schema extends BaseInjectionTokenSchemaType ? Type extends undefined ? <T extends ClassTypeWithArgument<z.output<Schema>>>(// #3.1.1 Typeless token
|
|
215
|
-
target: T, context
|
|
216
|
-
target: T, context
|
|
217
|
-
target: T, context
|
|
218
|
-
target: R, context
|
|
215
|
+
target: T, context?: ClassDecoratorContext) => T : <T extends ClassTypeWithInstanceAndArgument<Type, z.output<Schema>>>(// #3.1.2 Typed token
|
|
216
|
+
target: T, context?: ClassDecoratorContext) => T : Schema extends OptionalInjectionTokenSchemaType ? Type extends undefined ? <T extends ClassTypeWithOptionalArgument<z.output<Schema>>>(// #3.2.1 Typeless token
|
|
217
|
+
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
|
+
target: R, context?: ClassDecoratorContext) => R : never;
|
|
219
219
|
|
|
220
220
|
declare function Injectable<R, S>(options: {
|
|
221
221
|
scope?: InjectableScope;
|
|
@@ -223,8 +223,8 @@ declare function Injectable<R, S>(options: {
|
|
|
223
223
|
token: InjectionToken<R, S>;
|
|
224
224
|
registry?: Registry;
|
|
225
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
|
|
227
|
-
target: T, context
|
|
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
228
|
export { Injectable }
|
|
229
229
|
export { Injectable as Injectable_alias_1 }
|
|
230
230
|
export { Injectable as Injectable_alias_2 }
|
|
@@ -270,14 +270,14 @@ declare type InjectionFactory<T = unknown, Args = unknown> = (ctx: FactoryContex
|
|
|
270
270
|
export { InjectionFactory }
|
|
271
271
|
export { InjectionFactory as InjectionFactory_alias_1 }
|
|
272
272
|
|
|
273
|
-
declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown, Required extends boolean = S extends ZodOptional<
|
|
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> {
|
|
274
274
|
readonly name: string | symbol | ClassType;
|
|
275
|
-
readonly schema:
|
|
275
|
+
readonly schema: ZodObject<any> | undefined;
|
|
276
276
|
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
277
277
|
private formattedName;
|
|
278
|
-
constructor(name: string | symbol | ClassType, schema:
|
|
278
|
+
constructor(name: string | symbol | ClassType, schema: ZodObject<any> | undefined);
|
|
279
279
|
static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
|
|
280
|
-
static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): Schema['_def']['
|
|
280
|
+
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
281
|
static create<T>(name: string | symbol): InjectionToken<T, undefined>;
|
|
282
282
|
static create<T, Schema extends InjectionTokenSchemaType>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
|
|
283
283
|
static bound<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
|
|
@@ -352,7 +352,7 @@ declare function makeProxyServiceLocator(serviceLocator: ServiceLocator, ctx: Fa
|
|
|
352
352
|
export { makeProxyServiceLocator }
|
|
353
353
|
export { makeProxyServiceLocator as makeProxyServiceLocator_alias_1 }
|
|
354
354
|
|
|
355
|
-
declare type OptionalInjectionTokenSchemaType = ZodOptional<
|
|
355
|
+
declare type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject<any>> | ZodOptional<ZodRecord>;
|
|
356
356
|
export { OptionalInjectionTokenSchemaType }
|
|
357
357
|
export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
|
|
358
358
|
|
|
@@ -368,8 +368,8 @@ declare class ProxyServiceLocator implements ServiceLocator {
|
|
|
368
368
|
constructor(serviceLocator: ServiceLocator, ctx: FactoryContext);
|
|
369
369
|
getEventBus(): ServiceLocatorEventBus;
|
|
370
370
|
getInstance(token: InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args?: any): Promise<any[]>;
|
|
371
|
-
getOrThrowInstance<Instance, Schema extends
|
|
372
|
-
getSyncInstance<Instance, Schema extends
|
|
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
373
|
invalidate(service: string, round?: number): Promise<any>;
|
|
374
374
|
ready(): Promise<null>;
|
|
375
375
|
makeInstanceName(token: InjectionToken<any, any>, args: any): string;
|
|
@@ -403,7 +403,7 @@ declare class ServiceLocator {
|
|
|
403
403
|
storeInstance<Instance>(instance: Instance, token: BoundInjectionToken<Instance, any>): void;
|
|
404
404
|
storeInstance<Instance>(instance: Instance, token: FactoryInjectionToken<Instance, any>): void;
|
|
405
405
|
storeInstance<Instance>(instance: Instance, token: InjectionToken<Instance, undefined>): void;
|
|
406
|
-
storeInstance<Instance, Schema extends
|
|
406
|
+
storeInstance<Instance, Schema extends ZodObject<any> | ZodOptional<ZodObject<any>>>(instance: Instance, token: InjectionToken<Instance, Schema>, args: z.input<Schema>): void;
|
|
407
407
|
removeInstance<Instance>(token: BoundInjectionToken<Instance, any>): void;
|
|
408
408
|
removeInstance<Instance>(token: FactoryInjectionToken<Instance, any>): void;
|
|
409
409
|
removeInstance<Instance>(token: InjectionToken<Instance, undefined>): void;
|
|
@@ -420,12 +420,12 @@ declare class ServiceLocator {
|
|
|
420
420
|
getInstance<Instance>(token: InjectionToken<Instance, undefined>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
421
421
|
getInstance<Instance>(token: BoundInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
422
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
|
|
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
424
|
private notifyListeners;
|
|
425
425
|
private createInstance;
|
|
426
426
|
private resolveInstance;
|
|
427
427
|
private createFactoryContext;
|
|
428
|
-
getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends
|
|
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;
|
|
429
429
|
invalidate(service: string, round?: number): Promise<any>;
|
|
430
430
|
ready(): Promise<null>;
|
|
431
431
|
makeInstanceName(token: InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args: any): string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { ZodOptional } from 'zod';
|
|
4
|
-
import { ZodRecord } from 'zod';
|
|
5
|
-
import type { ZodType } from 'zod';
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import type { ZodObject } from 'zod/v4';
|
|
3
|
+
import type { ZodOptional } from 'zod/v4';
|
|
4
|
+
import type { ZodRecord } from 'zod/v4';
|
|
5
|
+
import type { ZodType } from 'zod/v4';
|
|
6
6
|
|
|
7
|
-
declare type BaseInjectionTokenSchemaType =
|
|
7
|
+
declare type BaseInjectionTokenSchemaType = ZodObject<any> | ZodRecord;
|
|
8
8
|
export { BaseInjectionTokenSchemaType }
|
|
9
9
|
export { BaseInjectionTokenSchemaType as BaseInjectionTokenSchemaType_alias_1 }
|
|
10
10
|
|
|
@@ -150,7 +150,7 @@ export { FactoryNotFound as FactoryNotFound_alias_2 }
|
|
|
150
150
|
declare type FactoryRecord<Instance = any, Schema = any> = {
|
|
151
151
|
scope: InjectableScope;
|
|
152
152
|
originalToken: InjectionToken<Instance, Schema>;
|
|
153
|
-
factory: InjectionFactory<Instance, Schema extends
|
|
153
|
+
factory: InjectionFactory<Instance, Schema extends ZodObject<any> ? z.input<Schema> : unknown>;
|
|
154
154
|
};
|
|
155
155
|
export { FactoryRecord }
|
|
156
156
|
export { FactoryRecord as FactoryRecord_alias_1 }
|
|
@@ -194,17 +194,17 @@ declare const inject: Injectors['inject'];
|
|
|
194
194
|
export { inject }
|
|
195
195
|
export { inject as inject_alias_1 }
|
|
196
196
|
|
|
197
|
-
declare function Injectable(): <T extends ClassType>(target: T, context
|
|
197
|
+
declare function Injectable(): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
|
|
198
198
|
|
|
199
199
|
declare function Injectable(options: {
|
|
200
200
|
registry: Registry;
|
|
201
|
-
}): <T extends ClassType>(target: T, context
|
|
201
|
+
}): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
|
|
202
202
|
|
|
203
203
|
declare function Injectable<R>(options: {
|
|
204
204
|
scope?: InjectableScope;
|
|
205
205
|
type: InjectableType.Factory;
|
|
206
206
|
registry?: Registry;
|
|
207
|
-
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context
|
|
207
|
+
}): <T extends ClassTypeWithInstance<Factory<R>>>(target: T, context?: ClassDecoratorContext) => T;
|
|
208
208
|
|
|
209
209
|
declare function Injectable<Type, Schema>(options: {
|
|
210
210
|
scope?: InjectableScope;
|
|
@@ -212,10 +212,10 @@ declare function Injectable<Type, Schema>(options: {
|
|
|
212
212
|
token: InjectionToken<Type, Schema>;
|
|
213
213
|
registry?: Registry;
|
|
214
214
|
}): Schema extends BaseInjectionTokenSchemaType ? Type extends undefined ? <T extends ClassTypeWithArgument<z.output<Schema>>>(// #3.1.1 Typeless token
|
|
215
|
-
target: T, context
|
|
216
|
-
target: T, context
|
|
217
|
-
target: T, context
|
|
218
|
-
target: R, context
|
|
215
|
+
target: T, context?: ClassDecoratorContext) => T : <T extends ClassTypeWithInstanceAndArgument<Type, z.output<Schema>>>(// #3.1.2 Typed token
|
|
216
|
+
target: T, context?: ClassDecoratorContext) => T : Schema extends OptionalInjectionTokenSchemaType ? Type extends undefined ? <T extends ClassTypeWithOptionalArgument<z.output<Schema>>>(// #3.2.1 Typeless token
|
|
217
|
+
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
|
+
target: R, context?: ClassDecoratorContext) => R : never;
|
|
219
219
|
|
|
220
220
|
declare function Injectable<R, S>(options: {
|
|
221
221
|
scope?: InjectableScope;
|
|
@@ -223,8 +223,8 @@ declare function Injectable<R, S>(options: {
|
|
|
223
223
|
token: InjectionToken<R, S>;
|
|
224
224
|
registry?: Registry;
|
|
225
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
|
|
227
|
-
target: T, context
|
|
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
228
|
export { Injectable }
|
|
229
229
|
export { Injectable as Injectable_alias_1 }
|
|
230
230
|
export { Injectable as Injectable_alias_2 }
|
|
@@ -270,14 +270,14 @@ declare type InjectionFactory<T = unknown, Args = unknown> = (ctx: FactoryContex
|
|
|
270
270
|
export { InjectionFactory }
|
|
271
271
|
export { InjectionFactory as InjectionFactory_alias_1 }
|
|
272
272
|
|
|
273
|
-
declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown, Required extends boolean = S extends ZodOptional<
|
|
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> {
|
|
274
274
|
readonly name: string | symbol | ClassType;
|
|
275
|
-
readonly schema:
|
|
275
|
+
readonly schema: ZodObject<any> | undefined;
|
|
276
276
|
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
277
277
|
private formattedName;
|
|
278
|
-
constructor(name: string | symbol | ClassType, schema:
|
|
278
|
+
constructor(name: string | symbol | ClassType, schema: ZodObject<any> | undefined);
|
|
279
279
|
static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
|
|
280
|
-
static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): Schema['_def']['
|
|
280
|
+
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
281
|
static create<T>(name: string | symbol): InjectionToken<T, undefined>;
|
|
282
282
|
static create<T, Schema extends InjectionTokenSchemaType>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
|
|
283
283
|
static bound<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
|
|
@@ -352,7 +352,7 @@ declare function makeProxyServiceLocator(serviceLocator: ServiceLocator, ctx: Fa
|
|
|
352
352
|
export { makeProxyServiceLocator }
|
|
353
353
|
export { makeProxyServiceLocator as makeProxyServiceLocator_alias_1 }
|
|
354
354
|
|
|
355
|
-
declare type OptionalInjectionTokenSchemaType = ZodOptional<
|
|
355
|
+
declare type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject<any>> | ZodOptional<ZodRecord>;
|
|
356
356
|
export { OptionalInjectionTokenSchemaType }
|
|
357
357
|
export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
|
|
358
358
|
|
|
@@ -368,8 +368,8 @@ declare class ProxyServiceLocator implements ServiceLocator {
|
|
|
368
368
|
constructor(serviceLocator: ServiceLocator, ctx: FactoryContext);
|
|
369
369
|
getEventBus(): ServiceLocatorEventBus;
|
|
370
370
|
getInstance(token: InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args?: any): Promise<any[]>;
|
|
371
|
-
getOrThrowInstance<Instance, Schema extends
|
|
372
|
-
getSyncInstance<Instance, Schema extends
|
|
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
373
|
invalidate(service: string, round?: number): Promise<any>;
|
|
374
374
|
ready(): Promise<null>;
|
|
375
375
|
makeInstanceName(token: InjectionToken<any, any>, args: any): string;
|
|
@@ -403,7 +403,7 @@ declare class ServiceLocator {
|
|
|
403
403
|
storeInstance<Instance>(instance: Instance, token: BoundInjectionToken<Instance, any>): void;
|
|
404
404
|
storeInstance<Instance>(instance: Instance, token: FactoryInjectionToken<Instance, any>): void;
|
|
405
405
|
storeInstance<Instance>(instance: Instance, token: InjectionToken<Instance, undefined>): void;
|
|
406
|
-
storeInstance<Instance, Schema extends
|
|
406
|
+
storeInstance<Instance, Schema extends ZodObject<any> | ZodOptional<ZodObject<any>>>(instance: Instance, token: InjectionToken<Instance, Schema>, args: z.input<Schema>): void;
|
|
407
407
|
removeInstance<Instance>(token: BoundInjectionToken<Instance, any>): void;
|
|
408
408
|
removeInstance<Instance>(token: FactoryInjectionToken<Instance, any>): void;
|
|
409
409
|
removeInstance<Instance>(token: InjectionToken<Instance, undefined>): void;
|
|
@@ -420,12 +420,12 @@ declare class ServiceLocator {
|
|
|
420
420
|
getInstance<Instance>(token: InjectionToken<Instance, undefined>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
421
421
|
getInstance<Instance>(token: BoundInjectionToken<Instance, any>): Promise<[undefined, Instance] | [UnknownError | FactoryNotFound]>;
|
|
422
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
|
|
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
424
|
private notifyListeners;
|
|
425
425
|
private createInstance;
|
|
426
426
|
private resolveInstance;
|
|
427
427
|
private createFactoryContext;
|
|
428
|
-
getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends
|
|
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;
|
|
429
429
|
invalidate(service: string, round?: number): Promise<any>;
|
|
430
430
|
ready(): Promise<null>;
|
|
431
431
|
makeInstanceName(token: InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args: any): string;
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var InjectableType = /* @__PURE__ */ ((InjectableType2) => {
|
|
|
15
15
|
InjectableType2["Factory"] = "Factory";
|
|
16
16
|
return InjectableType2;
|
|
17
17
|
})(InjectableType || {});
|
|
18
|
+
|
|
19
|
+
// src/injection-token.mts
|
|
18
20
|
var InjectionToken = class _InjectionToken {
|
|
19
21
|
constructor(name, schema) {
|
|
20
22
|
this.name = name;
|
|
@@ -89,6 +91,8 @@ var FactoryInjectionToken = class {
|
|
|
89
91
|
return this.token.toString();
|
|
90
92
|
}
|
|
91
93
|
};
|
|
94
|
+
|
|
95
|
+
// src/registry.mts
|
|
92
96
|
var Registry = class {
|
|
93
97
|
constructor(parent) {
|
|
94
98
|
this.parent = parent;
|
|
@@ -286,7 +290,7 @@ function Injectable({
|
|
|
286
290
|
registry = globalRegistry
|
|
287
291
|
} = {}) {
|
|
288
292
|
return (target, context) => {
|
|
289
|
-
if (context.kind !== "class") {
|
|
293
|
+
if (context && context.kind !== "class" || target instanceof Function && !context) {
|
|
290
294
|
throw new Error(
|
|
291
295
|
"[ServiceLocator] @Injectable decorator can only be used on classes."
|
|
292
296
|
);
|