@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
package/src/registry.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import { z } from 'zod'
|
|
1
|
+
import type { z, ZodObject } from 'zod/v4'
|
|
4
2
|
|
|
5
3
|
import type { FactoryContext } from './factory-context.mjs'
|
|
6
4
|
import type { InjectionToken } from './injection-token.mjs'
|
|
@@ -17,7 +15,7 @@ export type FactoryRecord<Instance = any, Schema = any> = {
|
|
|
17
15
|
originalToken: InjectionToken<Instance, Schema>
|
|
18
16
|
factory: InjectionFactory<
|
|
19
17
|
Instance,
|
|
20
|
-
Schema extends
|
|
18
|
+
Schema extends ZodObject<any> ? z.input<Schema> : unknown
|
|
21
19
|
>
|
|
22
20
|
}
|
|
23
21
|
|
package/src/service-locator.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
3
|
-
import type {
|
|
3
|
+
import type { z, ZodObject, ZodOptional } from 'zod/v4'
|
|
4
4
|
|
|
5
5
|
import type { FactoryContext } from './factory-context.mjs'
|
|
6
6
|
import type {
|
|
@@ -62,7 +62,7 @@ export class ServiceLocator {
|
|
|
62
62
|
): void
|
|
63
63
|
public storeInstance<
|
|
64
64
|
Instance,
|
|
65
|
-
Schema extends
|
|
65
|
+
Schema extends ZodObject<any> | ZodOptional<ZodObject<any>>,
|
|
66
66
|
>(
|
|
67
67
|
instance: Instance,
|
|
68
68
|
token: InjectionToken<Instance, Schema>,
|
|
@@ -292,9 +292,9 @@ export class ServiceLocator {
|
|
|
292
292
|
Schema extends InjectionTokenSchemaType | undefined,
|
|
293
293
|
>(
|
|
294
294
|
token: InjectionToken<Instance, Schema>,
|
|
295
|
-
args: Schema extends
|
|
295
|
+
args: Schema extends ZodObject<any>
|
|
296
296
|
? z.input<Schema>
|
|
297
|
-
: Schema extends ZodOptional<
|
|
297
|
+
: Schema extends ZodOptional<ZodObject<any>>
|
|
298
298
|
? z.input<Schema> | undefined
|
|
299
299
|
: undefined,
|
|
300
300
|
): Promise<Instance> {
|
|
@@ -321,9 +321,9 @@ export class ServiceLocator {
|
|
|
321
321
|
>(
|
|
322
322
|
instanceName: string,
|
|
323
323
|
token: InjectionToken<Instance, Schema>,
|
|
324
|
-
args: Schema extends
|
|
324
|
+
args: Schema extends ZodObject<any>
|
|
325
325
|
? z.input<Schema>
|
|
326
|
-
: Schema extends ZodOptional<
|
|
326
|
+
: Schema extends ZodOptional<ZodObject<any>>
|
|
327
327
|
? z.input<Schema> | undefined
|
|
328
328
|
: undefined,
|
|
329
329
|
): Promise<[undefined, Instance] | [FactoryNotFound | UnknownError]> {
|
|
@@ -481,9 +481,9 @@ export class ServiceLocator {
|
|
|
481
481
|
Schema extends InjectionTokenSchemaType | undefined,
|
|
482
482
|
>(
|
|
483
483
|
token: InjectionToken<Instance, Schema>,
|
|
484
|
-
args: Schema extends
|
|
484
|
+
args: Schema extends ZodObject<any>
|
|
485
485
|
? z.input<Schema>
|
|
486
|
-
: Schema extends ZodOptional<
|
|
486
|
+
: Schema extends ZodOptional<ZodObject<any>>
|
|
487
487
|
? z.input<Schema> | undefined
|
|
488
488
|
: undefined,
|
|
489
489
|
): Instance | null {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { z, ZodObject, ZodType } from 'zod/v4'
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
BoundInjectionToken,
|
|
@@ -150,8 +150,8 @@ export function getInjectors({ baseLocator }: CreateInjectorsOptions) {
|
|
|
150
150
|
| InjectionToken<T>
|
|
151
151
|
| BoundInjectionToken<T, any>
|
|
152
152
|
| FactoryInjectionToken<T, any>,
|
|
153
|
-
S extends
|
|
154
|
-
>(token: Token, args?: S extends
|
|
153
|
+
S extends ZodObject<any> | unknown = Token['schema'],
|
|
154
|
+
>(token: Token, args?: S extends ZodObject<any> ? z.input<S> : never): T {
|
|
155
155
|
// @ts-expect-error In case we have a class
|
|
156
156
|
const realToken = token[InjectableTokenMeta] ?? token
|
|
157
157
|
|