@navios/di 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,41 +13,42 @@ yarn add @navios/di
13
13
  ## Simple Usage example
14
14
 
15
15
  ```ts
16
- import { Injectable, inject, syncInject } from '@navios/di';
16
+ import { inject, Injectable, syncInject } from '@navios/di'
17
17
 
18
18
  @Injectable()
19
19
  class GreeterService {
20
20
  getFoo(user: string): string {
21
- return `Hello ${user}`;
21
+ return `Hello ${user}`
22
22
  }
23
23
  }
24
24
 
25
25
  @Injectable()
26
26
  class UserService {
27
- private readonly greeterService = syncInject(GreeterService);
28
-
27
+ private readonly greeterService = syncInject(GreeterService)
28
+
29
29
  greet(user: string): string {
30
- return this.greeterService.getFoo(user);
30
+ return this.greeterService.getFoo(user)
31
31
  }
32
32
  }
33
33
 
34
- const userService = await inject(UserService);
34
+ const userService = await inject(UserService)
35
35
 
36
- console.log(userService.greet('World')); // Hello World
36
+ console.log(userService.greet('World')) // Hello World
37
37
  ```
38
38
 
39
39
  ## Usage with Injection Token
40
40
 
41
41
  ```ts
42
- import { Injectable, inject, syncInject, InjectionToken } from '@navios/di';
43
- import { z } from 'zod';
42
+ import { inject, Injectable, InjectionToken, syncInject } from '@navios/di'
43
+
44
+ import { z } from 'zod/v4'
44
45
 
45
46
  const schema = z.object({
46
47
  user: z.string(),
47
48
  })
48
49
 
49
50
  interface GreeterInterface {
50
- getFoo(): string;
51
+ getFoo(): string
51
52
  }
52
53
 
53
54
  const token = new InjectionToken.create<GreeterInterface, typeof schema>(
@@ -62,19 +63,19 @@ class GreeterService {
62
63
  constructor(private readonly config: z.infer<typeof schema>) {}
63
64
 
64
65
  getFoo(): string {
65
- return `Hello ${this.config.user}`;
66
+ return `Hello ${this.config.user}`
66
67
  }
67
68
  }
68
69
 
69
70
  const greetWorld = await inject(token, {
70
- user: 'World'
71
+ user: 'World',
71
72
  })
72
73
  const BoundGreeterService = InjectionToken.bound(token, {
73
- user: 'Earth'
74
+ user: 'Earth',
74
75
  })
75
76
 
76
- const greetEarth = await inject(BoundGreeterService);
77
+ const greetEarth = await inject(BoundGreeterService)
77
78
 
78
- console.log(greetWorld.getFoo()); // Hello World
79
- console.log(greetEarth.getFoo()); // Hello Earth
79
+ console.log(greetWorld.getFoo()) // Hello World
80
+ console.log(greetEarth.getFoo()) // Hello Earth
80
81
  ```
package/docs/README.md CHANGED
@@ -13,41 +13,42 @@ yarn add @navios/di
13
13
  ## Simple Usage example
14
14
 
15
15
  ```ts
16
- import { Injectable, inject, syncInject } from '@navios/di';
16
+ import { inject, Injectable, syncInject } from '@navios/di'
17
17
 
18
18
  @Injectable()
19
19
  class GreeterService {
20
20
  getFoo(user: string): string {
21
- return `Hello ${user}`;
21
+ return `Hello ${user}`
22
22
  }
23
23
  }
24
24
 
25
25
  @Injectable()
26
26
  class UserService {
27
- private readonly greeterService = syncInject(GreeterService);
28
-
27
+ private readonly greeterService = syncInject(GreeterService)
28
+
29
29
  greet(user: string): string {
30
- return this.greeterService.getFoo(user);
30
+ return this.greeterService.getFoo(user)
31
31
  }
32
32
  }
33
33
 
34
- const userService = await inject(UserService);
34
+ const userService = await inject(UserService)
35
35
 
36
- console.log(userService.greet('World')); // Hello World
36
+ console.log(userService.greet('World')) // Hello World
37
37
  ```
38
38
 
39
39
  ## Usage with Injection Token
40
40
 
41
41
  ```ts
42
- import { Injectable, inject, syncInject, InjectionToken } from '@navios/di';
43
- import { z } from 'zod';
42
+ import { inject, Injectable, InjectionToken, syncInject } from '@navios/di'
43
+
44
+ import { z } from 'zod/v4'
44
45
 
45
46
  const schema = z.object({
46
47
  user: z.string(),
47
48
  })
48
49
 
49
50
  interface GreeterInterface {
50
- getFoo(): string;
51
+ getFoo(): string
51
52
  }
52
53
 
53
54
  const token = new InjectionToken<GreeterInterface, typeof schema>(
@@ -62,20 +63,19 @@ class GreeterService {
62
63
  constructor(private readonly config: z.infer<typeof schema>) {}
63
64
 
64
65
  getFoo(): string {
65
- return `Hello ${this.config.user}`;
66
+ return `Hello ${this.config.user}`
66
67
  }
67
68
  }
68
69
 
69
70
  const greetWorld = await inject(token, {
70
- user: 'World'
71
+ user: 'World',
71
72
  })
72
73
  const BoundGreeterService = InjectionToken.bound(token, {
73
- user: 'Earth'
74
+ user: 'Earth',
74
75
  })
75
76
 
76
- const greetEarth = await inject(BoundGreeterService);
77
-
78
- console.log(greetWorld.getFoo()); // Hello World
79
- console.log(greetEarth.getFoo()); // Hello Earth
77
+ const greetEarth = await inject(BoundGreeterService)
80
78
 
79
+ console.log(greetWorld.getFoo()) // Hello World
80
+ console.log(greetEarth.getFoo()) // Hello Earth
81
81
  ```
@@ -41,7 +41,7 @@ class UserService {
41
41
  You can add a parameter to the injection token to make it more specific.
42
42
 
43
43
  ```ts
44
- import { z } from 'zod'
44
+ import { z } from 'zod/v4'
45
45
 
46
46
  const GreeterServiceParams = z.object({
47
47
  context: z.string(),
@@ -4,7 +4,7 @@ import type { ZodOptional } from 'zod/v4';
4
4
  import type { ZodRecord } from 'zod/v4';
5
5
  import type { ZodType } from 'zod/v4';
6
6
 
7
- declare type BaseInjectionTokenSchemaType = ZodObject<any> | ZodRecord;
7
+ declare type BaseInjectionTokenSchemaType = ZodObject | 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 ZodObject<any> ? z.input<Schema> : unknown>;
153
+ factory: InjectionFactory<Instance, Schema extends ZodObject ? z.input<Schema> : unknown>;
154
154
  };
155
155
  export { FactoryRecord }
156
156
  export { FactoryRecord as FactoryRecord_alias_1 }
@@ -270,12 +270,12 @@ 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<ZodObject<any>> ? false : S extends ZodOptional<ZodRecord> ? false : S extends ZodObject<any> ? true : S extends ZodRecord ? true : false> {
273
+ declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown, Required extends boolean = S extends ZodOptional<ZodObject> ? false : S extends ZodOptional<ZodRecord> ? false : S extends ZodObject ? true : S extends ZodRecord ? true : false> {
274
274
  readonly name: string | symbol | ClassType;
275
- readonly schema: ZodObject<any> | undefined;
275
+ readonly schema: ZodObject | undefined;
276
276
  id: `${string}-${string}-${string}-${string}-${string}`;
277
277
  private formattedName;
278
- constructor(name: string | symbol | ClassType, schema: ZodObject<any> | undefined);
278
+ constructor(name: string | symbol | ClassType, schema: ZodObject | undefined);
279
279
  static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
280
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>;
@@ -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<ZodObject<any>> | ZodOptional<ZodRecord>;
355
+ declare type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject> | 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 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;
371
+ getOrThrowInstance<Instance, Schema extends ZodObject | ZodOptional<ZodObject> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
372
+ getSyncInstance<Instance, Schema extends ZodObject | ZodOptional<ZodObject> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? 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 ZodObject<any> | ZodOptional<ZodObject<any>>>(instance: Instance, token: InjectionToken<Instance, Schema>, args: z.input<Schema>): void;
406
+ storeInstance<Instance, Schema extends ZodObject | ZodOptional<ZodObject>>(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 ZodObject<any> ? z.input<Schema> : Schema extends ZodOptional<ZodObject<any>> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
423
+ getOrThrowInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? 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 ZodObject<any> ? z.input<Schema> : Schema extends ZodOptional<ZodObject<any>> ? z.input<Schema> | undefined : undefined): Instance | null;
428
+ getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? 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;
@@ -4,7 +4,7 @@ import type { ZodOptional } from 'zod/v4';
4
4
  import type { ZodRecord } from 'zod/v4';
5
5
  import type { ZodType } from 'zod/v4';
6
6
 
7
- declare type BaseInjectionTokenSchemaType = ZodObject<any> | ZodRecord;
7
+ declare type BaseInjectionTokenSchemaType = ZodObject | 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 ZodObject<any> ? z.input<Schema> : unknown>;
153
+ factory: InjectionFactory<Instance, Schema extends ZodObject ? z.input<Schema> : unknown>;
154
154
  };
155
155
  export { FactoryRecord }
156
156
  export { FactoryRecord as FactoryRecord_alias_1 }
@@ -270,12 +270,12 @@ 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<ZodObject<any>> ? false : S extends ZodOptional<ZodRecord> ? false : S extends ZodObject<any> ? true : S extends ZodRecord ? true : false> {
273
+ declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown, Required extends boolean = S extends ZodOptional<ZodObject> ? false : S extends ZodOptional<ZodRecord> ? false : S extends ZodObject ? true : S extends ZodRecord ? true : false> {
274
274
  readonly name: string | symbol | ClassType;
275
- readonly schema: ZodObject<any> | undefined;
275
+ readonly schema: ZodObject | undefined;
276
276
  id: `${string}-${string}-${string}-${string}-${string}`;
277
277
  private formattedName;
278
- constructor(name: string | symbol | ClassType, schema: ZodObject<any> | undefined);
278
+ constructor(name: string | symbol | ClassType, schema: ZodObject | undefined);
279
279
  static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
280
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>;
@@ -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<ZodObject<any>> | ZodOptional<ZodRecord>;
355
+ declare type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject> | 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 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;
371
+ getOrThrowInstance<Instance, Schema extends ZodObject | ZodOptional<ZodObject> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
372
+ getSyncInstance<Instance, Schema extends ZodObject | ZodOptional<ZodObject> | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? 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 ZodObject<any> | ZodOptional<ZodObject<any>>>(instance: Instance, token: InjectionToken<Instance, Schema>, args: z.input<Schema>): void;
406
+ storeInstance<Instance, Schema extends ZodObject | ZodOptional<ZodObject>>(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 ZodObject<any> ? z.input<Schema> : Schema extends ZodOptional<ZodObject<any>> ? z.input<Schema> | undefined : undefined): Promise<Instance>;
423
+ getOrThrowInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? 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 ZodObject<any> ? z.input<Schema> : Schema extends ZodOptional<ZodObject<any>> ? z.input<Schema> | undefined : undefined): Instance | null;
428
+ getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: InjectionToken<Instance, Schema>, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? 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;