@navios/di 0.1.13 → 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 +17 -17
- package/lib/_tsup-dts-rollup.d.ts +17 -17
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +4 -0
- package/lib/index.mjs.map +1 -1
- package/package.json +3 -3
- 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 +3 -3
- package/src/decorators/injectable.decorator.mts +1 -1
- 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 }
|
|
@@ -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 }
|
|
@@ -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;
|