@velajs/vela 1.8.1 → 1.8.2
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/dist/container/index.d.ts +1 -1
- package/dist/container/types.d.ts +24 -2
- package/dist/index.d.ts +1 -1
- package/dist/registry/types.d.ts +25 -5
- package/package.json +1 -1
|
@@ -3,4 +3,4 @@ export { Injectable, Inject, Optional, isInjectable, getScope } from './decorato
|
|
|
3
3
|
export { InjectionToken, ForwardRef, forwardRef, ModuleVisibilityError, MultipleProvidersFoundError, ROOT_MODULE_ID, } from './types';
|
|
4
4
|
export { ModuleRef } from './module-ref';
|
|
5
5
|
export { mixin } from './mixin';
|
|
6
|
-
export type { Type, Token, InjectableOptions, InjectMetadata, ProviderOptions, ProviderRegistration, InjectionTokenOptions, ModuleScope, ContainerOptions, Diagnostics, } from './types';
|
|
6
|
+
export type { Type, Token, InferToken, InferTokens, InjectableOptions, InjectMetadata, ProviderOptions, ProviderRegistration, InjectionTokenOptions, ModuleScope, ContainerOptions, Diagnostics, } from './types';
|
|
@@ -16,6 +16,28 @@ export declare class ForwardRef<T = unknown> {
|
|
|
16
16
|
}
|
|
17
17
|
export declare function forwardRef<T>(factory: () => Token<T>): ForwardRef<T>;
|
|
18
18
|
export type Token<T = any> = Type<T> | InjectionToken<T> | string | symbol;
|
|
19
|
+
/**
|
|
20
|
+
* Maps a single DI `Token<T>` to its resolved value type at the type level:
|
|
21
|
+
* - `InjectionToken<T>` → `T`
|
|
22
|
+
* - `Type<T>` / `Constructor<T>` → `T` (the instance type)
|
|
23
|
+
* - `ForwardRef<T>` → `T`
|
|
24
|
+
* - `string` / `symbol` → `unknown` (runtime-only tokens carry no
|
|
25
|
+
* static type info; the consumer asserts).
|
|
26
|
+
*
|
|
27
|
+
* Used by `AsyncModuleOptions` to give `useFactory` parameters their real
|
|
28
|
+
* types based on the literal `inject` tuple — without `as const` at the call
|
|
29
|
+
* site (relies on the `const` type parameter on the consuming generic).
|
|
30
|
+
*/
|
|
31
|
+
export type InferToken<T> = T extends InjectionToken<infer U> ? U : T extends ForwardRef<infer U> ? U : T extends abstract new (...args: any[]) => infer U ? U : unknown;
|
|
32
|
+
/**
|
|
33
|
+
* Map every position of a `Token[]` tuple to its resolved value type.
|
|
34
|
+
* Pairs with `const Inject extends readonly Token<unknown>[]` generics to
|
|
35
|
+
* give `useFactory(...deps)` parameter types inferred from the literal
|
|
36
|
+
* `inject` array.
|
|
37
|
+
*/
|
|
38
|
+
export type InferTokens<T extends readonly unknown[]> = {
|
|
39
|
+
[K in keyof T]: InferToken<T[K]>;
|
|
40
|
+
};
|
|
19
41
|
export interface InjectableOptions {
|
|
20
42
|
scope?: Scope;
|
|
21
43
|
}
|
|
@@ -30,7 +52,7 @@ export interface ProviderOptions<T = unknown> {
|
|
|
30
52
|
useValue?: T;
|
|
31
53
|
useFactory?: (...args: any[]) => T | Promise<T>;
|
|
32
54
|
useClass?: Type<T>;
|
|
33
|
-
inject?: Token[];
|
|
55
|
+
inject?: readonly Token[];
|
|
34
56
|
useExisting?: Token<T>;
|
|
35
57
|
}
|
|
36
58
|
export interface ProviderRegistration<T = unknown> {
|
|
@@ -46,7 +68,7 @@ export interface ProviderRegistration<T = unknown> {
|
|
|
46
68
|
useValue?: T;
|
|
47
69
|
useFactory?: (...args: any[]) => T | Promise<T>;
|
|
48
70
|
useClass?: Type<T>;
|
|
49
|
-
inject?: Token[];
|
|
71
|
+
inject?: readonly Token[];
|
|
50
72
|
useExisting?: Token<T>;
|
|
51
73
|
}
|
|
52
74
|
export interface ModuleScope {
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type { BootstrapOptions, BootstrapResult } from './factory/bootstrap';
|
|
|
7
7
|
export { createOpenApiDocument, ApiDoc, ApiTags, ApiResponse, zodToJsonSchema, } from './openapi/index';
|
|
8
8
|
export type { OpenApiDocument, OpenApiInfo, OpenApiOperation, OpenApiParameter, OpenApiPathItem, OpenApiRequestBody, OpenApiResponse, ApiDocMetadata, ApiResponseEntry, ApiResponseOptions, CreateOpenApiDocumentOptions, HttpVerb, JsonSchema, } from './openapi/index';
|
|
9
9
|
export { Container, Injectable, Inject, Optional, InjectionToken, ForwardRef, forwardRef, ModuleRef, ModuleVisibilityError, MultipleProvidersFoundError, ROOT_MODULE_ID, mixin, } from './container/index';
|
|
10
|
-
export type { Type, Token, InjectableOptions, ProviderOptions, ModuleScope, ContainerOptions, Diagnostics, } from './container/index';
|
|
10
|
+
export type { Type, Token, InferToken, InferTokens, InjectableOptions, ProviderOptions, ModuleScope, ContainerOptions, Diagnostics, } from './container/index';
|
|
11
11
|
export { METADATA_KEYS, HttpMethod, ParamType, Scope } from './constants';
|
|
12
12
|
export { Controller, Version, Get, Post, Put, Patch, Delete, Options, Head, All, Sse, Param, Query, Body, Headers, Req, Res, Ip, Cookie, Cookies, RawBody, HttpCode, Header, Redirect, createParamDecorator, createLazyParamDecorator, applyDecorators, } from './http/index';
|
|
13
13
|
export { REQUEST_CONTEXT } from './http/request-context';
|
package/dist/registry/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Context } from 'hono';
|
|
2
2
|
import type { CanActivate, ExceptionFilter, NestInterceptor, NestMiddleware, PipeTransform } from '../pipeline/types';
|
|
3
|
-
import type { Constructor, ForwardRef, InjectionToken, ProviderOptions, Token, Type } from '../container/types';
|
|
4
|
-
export type { Constructor, ForwardRef, InjectionToken, ProviderOptions, Token, Type };
|
|
3
|
+
import type { Constructor, ForwardRef, InferToken, InferTokens, InjectionToken, ProviderOptions, Token, Type } from '../container/types';
|
|
4
|
+
export type { Constructor, ForwardRef, InferToken, InferTokens, InjectionToken, ProviderOptions, Token, Type };
|
|
5
5
|
export type ComponentType = 'middleware' | 'guard' | 'pipe' | 'interceptor' | 'filter';
|
|
6
6
|
export type MiddlewareType = Type<NestMiddleware> | NestMiddleware;
|
|
7
7
|
export type GuardType = Type<CanActivate> | CanActivate;
|
|
@@ -38,10 +38,30 @@ export interface HttpHandlerMeta {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
export type ModuleImport = Type | DynamicModule | ForwardRef;
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Async module options with **type-inferred `useFactory` parameters**.
|
|
43
|
+
*
|
|
44
|
+
* The `Inject` generic captures the literal `inject` tuple via `const` type
|
|
45
|
+
* parameter inference at the call site (TS 5.0+ — vela already requires it).
|
|
46
|
+
* `useFactory`'s parameter types are computed from that tuple via
|
|
47
|
+
* `InferTokens<Inject>`, so:
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* SomeModule.forRootAsync({
|
|
51
|
+
* inject: [D1Service, ConfigService], // captured as readonly [typeof D1Service, typeof ConfigService]
|
|
52
|
+
* useFactory: (d1, config) => { ... }, // d1: D1Service, config: ConfigService — inferred
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* Backwards compatible: when `inject` isn't a literal tuple (or is omitted),
|
|
57
|
+
* `Inject` falls back to `readonly Token<unknown>[]`, `InferTokens` resolves
|
|
58
|
+
* to `unknown[]`, and `useFactory` accepts variadic `unknown[]` — the prior
|
|
59
|
+
* loose-typing behavior. Existing callers don't break.
|
|
60
|
+
*/
|
|
61
|
+
export interface AsyncModuleOptions<T = unknown, Inject extends readonly Token<unknown>[] = readonly Token<unknown>[]> {
|
|
42
62
|
imports?: ModuleImport[];
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
inject?: Inject;
|
|
64
|
+
useFactory: (...args: InferTokens<Inject>) => T | Promise<T>;
|
|
45
65
|
}
|
|
46
66
|
export interface DynamicModule {
|
|
47
67
|
module: Type;
|