@velajs/vela 0.6.1 → 0.7.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/dist/cache/cache.module.js +14 -32
- package/dist/config/config.module.js +11 -32
- package/dist/container/container.js +8 -1
- package/dist/cors/cors.module.js +4 -15
- package/dist/factory.d.ts +1 -0
- package/dist/factory.js +1 -0
- package/dist/fetch/fetch.module.js +12 -30
- package/dist/http/middleware-consumer.d.ts +3 -0
- package/dist/http/middleware-consumer.js +10 -1
- package/dist/http/route.manager.d.ts +1 -0
- package/dist/http/route.manager.js +45 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -2
- package/dist/module/decorators.d.ts +2 -0
- package/dist/module/decorators.js +8 -0
- package/dist/module/index.d.ts +1 -1
- package/dist/module/index.js +1 -1
- package/dist/module/module-loader.js +12 -2
- package/dist/schedule/schedule.module.js +6 -24
- package/dist/throttler/throttler.module.js +13 -31
- package/dist/validation/create-zod-dto.d.ts +8 -3
- package/dist/validation/create-zod-dto.js +12 -1
- package/dist/validation/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,33 +1,12 @@
|
|
|
1
|
-
import { METADATA_KEYS } from "../constants.js";
|
|
2
|
-
import { defineMetadata } from "../metadata.js";
|
|
3
|
-
import { MetadataRegistry } from "../registry/metadata.registry.js";
|
|
4
1
|
import { APP_INTERCEPTOR } from "../pipeline/tokens.js";
|
|
5
2
|
import { CacheInterceptor } from "./cache.interceptor.js";
|
|
6
3
|
import { CacheService } from "./cache.service.js";
|
|
7
4
|
import { MemoryCacheStore } from "./cache.store.js";
|
|
8
5
|
import { CACHE_MANAGER, CACHE_MODULE_OPTIONS } from "./cache.tokens.js";
|
|
9
|
-
function makeCacheModuleClass(name) {
|
|
10
|
-
const moduleClass = class {
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
13
|
-
value: name
|
|
14
|
-
});
|
|
15
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
16
|
-
return moduleClass;
|
|
17
|
-
}
|
|
18
6
|
export class CacheModule {
|
|
19
7
|
static forRoot(options = {}) {
|
|
20
8
|
const { ttl = 5, max = 100, isGlobal = false } = options;
|
|
21
9
|
const store = new MemoryCacheStore(ttl, max);
|
|
22
|
-
const moduleClass = makeCacheModuleClass('CacheModule');
|
|
23
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
24
|
-
exports: [
|
|
25
|
-
CACHE_MANAGER,
|
|
26
|
-
CACHE_MODULE_OPTIONS,
|
|
27
|
-
CacheService,
|
|
28
|
-
CacheInterceptor
|
|
29
|
-
]
|
|
30
|
-
});
|
|
31
10
|
const providers = [
|
|
32
11
|
{
|
|
33
12
|
provide: CACHE_MANAGER,
|
|
@@ -47,21 +26,17 @@ export class CacheModule {
|
|
|
47
26
|
});
|
|
48
27
|
}
|
|
49
28
|
return {
|
|
50
|
-
module:
|
|
51
|
-
providers
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
static registerAsync(options) {
|
|
55
|
-
const moduleClass = makeCacheModuleClass('CacheModule');
|
|
56
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
57
|
-
imports: options.imports ?? [],
|
|
29
|
+
module: CacheModule,
|
|
30
|
+
providers,
|
|
58
31
|
exports: [
|
|
59
32
|
CACHE_MANAGER,
|
|
60
33
|
CACHE_MODULE_OPTIONS,
|
|
61
34
|
CacheService,
|
|
62
35
|
CacheInterceptor
|
|
63
36
|
]
|
|
64
|
-
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
static registerAsync(options) {
|
|
65
40
|
const providers = [
|
|
66
41
|
{
|
|
67
42
|
provide: CACHE_MODULE_OPTIONS,
|
|
@@ -85,8 +60,15 @@ export class CacheModule {
|
|
|
85
60
|
});
|
|
86
61
|
}
|
|
87
62
|
return {
|
|
88
|
-
module:
|
|
89
|
-
|
|
63
|
+
module: CacheModule,
|
|
64
|
+
imports: options.imports ?? [],
|
|
65
|
+
providers,
|
|
66
|
+
exports: [
|
|
67
|
+
CACHE_MANAGER,
|
|
68
|
+
CACHE_MODULE_OPTIONS,
|
|
69
|
+
CacheService,
|
|
70
|
+
CacheInterceptor
|
|
71
|
+
]
|
|
90
72
|
};
|
|
91
73
|
}
|
|
92
74
|
}
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
import { METADATA_KEYS } from "../constants.js";
|
|
2
|
-
import { defineMetadata } from "../metadata.js";
|
|
3
|
-
import { MetadataRegistry } from "../registry/metadata.registry.js";
|
|
4
1
|
import { ConfigService } from "./config.service.js";
|
|
5
2
|
import { CONFIG_OPTIONS } from "./config.tokens.js";
|
|
6
3
|
export class ConfigModule {
|
|
7
4
|
static forRoot(options) {
|
|
8
5
|
const config = options.validate ? options.validate(options.config) : options.config;
|
|
9
|
-
const moduleClass = class ConfigDynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: 'ConfigModule'
|
|
13
|
-
});
|
|
14
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
15
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
16
|
-
exports: [
|
|
17
|
-
ConfigService,
|
|
18
|
-
CONFIG_OPTIONS
|
|
19
|
-
],
|
|
20
|
-
isGlobal: options.isGlobal
|
|
21
|
-
});
|
|
22
6
|
return {
|
|
23
|
-
module:
|
|
7
|
+
module: ConfigModule,
|
|
24
8
|
providers: [
|
|
25
9
|
{
|
|
26
10
|
provide: CONFIG_OPTIONS,
|
|
@@ -28,28 +12,19 @@ export class ConfigModule {
|
|
|
28
12
|
},
|
|
29
13
|
ConfigService
|
|
30
14
|
],
|
|
15
|
+
exports: [
|
|
16
|
+
ConfigService,
|
|
17
|
+
CONFIG_OPTIONS
|
|
18
|
+
],
|
|
31
19
|
...options.isGlobal ? {
|
|
32
20
|
global: true
|
|
33
21
|
} : {}
|
|
34
22
|
};
|
|
35
23
|
}
|
|
36
24
|
static forRootAsync(options) {
|
|
37
|
-
const moduleClass = class ConfigAsyncDynamicModule {
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
40
|
-
value: 'ConfigModule'
|
|
41
|
-
});
|
|
42
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
43
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
44
|
-
imports: options.imports ?? [],
|
|
45
|
-
exports: [
|
|
46
|
-
ConfigService,
|
|
47
|
-
CONFIG_OPTIONS
|
|
48
|
-
],
|
|
49
|
-
isGlobal: options.isGlobal
|
|
50
|
-
});
|
|
51
25
|
return {
|
|
52
|
-
module:
|
|
26
|
+
module: ConfigModule,
|
|
27
|
+
imports: options.imports ?? [],
|
|
53
28
|
providers: [
|
|
54
29
|
{
|
|
55
30
|
provide: CONFIG_OPTIONS,
|
|
@@ -61,6 +36,10 @@ export class ConfigModule {
|
|
|
61
36
|
},
|
|
62
37
|
ConfigService
|
|
63
38
|
],
|
|
39
|
+
exports: [
|
|
40
|
+
ConfigService,
|
|
41
|
+
CONFIG_OPTIONS
|
|
42
|
+
],
|
|
64
43
|
...options.isGlobal ? {
|
|
65
44
|
global: true
|
|
66
45
|
} : {}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Scope } from "../constants.js";
|
|
2
2
|
import { getConstructorDependencies, getInjectMetadata, getScope, isInjectable } from "./decorators.js";
|
|
3
3
|
import { ForwardRef, InjectionToken } from "./types.js";
|
|
4
|
+
const IMPORT_TYPE_HINT = 'Did you use `import type { X }`? TypeScript strips type-only imports at ' + 'runtime and `design:paramtypes` emits `Object`/`undefined` for their ' + 'positions. Use a runtime `import { X }` for DI tokens.';
|
|
4
5
|
export class Container {
|
|
5
6
|
providers = new Map();
|
|
6
7
|
resolutionStack = new Set();
|
|
@@ -52,6 +53,12 @@ export class Container {
|
|
|
52
53
|
resolve(token) {
|
|
53
54
|
const registration = this.providers.get(token);
|
|
54
55
|
if (!registration) {
|
|
56
|
+
// `Object`/undefined at a token position is the fingerprint of a
|
|
57
|
+
// type-only import that TypeScript stripped — emit the hint BEFORE
|
|
58
|
+
// auto-registering Object as a provider (which would silently "succeed").
|
|
59
|
+
if (token === Object || token == null) {
|
|
60
|
+
throw new Error(`No provider found for token: ${this.tokenToString(token)}. ` + IMPORT_TYPE_HINT);
|
|
61
|
+
}
|
|
55
62
|
if (typeof token === 'function') {
|
|
56
63
|
this.register(token);
|
|
57
64
|
return this.resolve(token);
|
|
@@ -155,7 +162,7 @@ export class Container {
|
|
|
155
162
|
const token = isForwardRef ? rawToken.factory() : rawToken ?? paramType;
|
|
156
163
|
if (!token || token === Object) {
|
|
157
164
|
if (meta?.optional) return undefined;
|
|
158
|
-
throw new Error(`Cannot resolve dependency at index ${index} for ${target.name}. ` + `Parameter type is undefined or Object. ` + `
|
|
165
|
+
throw new Error(`Cannot resolve dependency at index ${index} for ${target.name}. ` + `Parameter type is undefined or Object. ` + IMPORT_TYPE_HINT + ` Alternatively, use \`@Inject()\` to specify the token explicitly.`);
|
|
159
166
|
}
|
|
160
167
|
if (meta?.optional && !this.has(token)) {
|
|
161
168
|
return undefined;
|
package/dist/cors/cors.module.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { cors } from "hono/cors";
|
|
2
|
-
import { METADATA_KEYS } from "../constants.js";
|
|
3
|
-
import { defineMetadata } from "../metadata.js";
|
|
4
|
-
import { MetadataRegistry } from "../registry/metadata.registry.js";
|
|
5
2
|
import { APP_MIDDLEWARE } from "../pipeline/tokens.js";
|
|
6
3
|
import { CORS_OPTIONS } from "./cors.tokens.js";
|
|
7
4
|
export class CorsModule {
|
|
@@ -17,19 +14,8 @@ export class CorsModule {
|
|
|
17
14
|
const middleware = {
|
|
18
15
|
use: (c, next)=>corsMiddleware(c, next)
|
|
19
16
|
};
|
|
20
|
-
const moduleClass = class CorsDynamicModule {
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
23
|
-
value: 'CorsModule'
|
|
24
|
-
});
|
|
25
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
26
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
27
|
-
exports: [
|
|
28
|
-
CORS_OPTIONS
|
|
29
|
-
]
|
|
30
|
-
});
|
|
31
17
|
return {
|
|
32
|
-
module:
|
|
18
|
+
module: CorsModule,
|
|
33
19
|
providers: [
|
|
34
20
|
{
|
|
35
21
|
provide: CORS_OPTIONS,
|
|
@@ -39,6 +25,9 @@ export class CorsModule {
|
|
|
39
25
|
provide: APP_MIDDLEWARE,
|
|
40
26
|
useValue: middleware
|
|
41
27
|
}
|
|
28
|
+
],
|
|
29
|
+
exports: [
|
|
30
|
+
CORS_OPTIONS
|
|
42
31
|
]
|
|
43
32
|
};
|
|
44
33
|
}
|
package/dist/factory.d.ts
CHANGED
package/dist/factory.js
CHANGED
|
@@ -4,52 +4,30 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
4
4
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
}
|
|
7
|
-
import {
|
|
8
|
-
import { defineMetadata } from "../metadata.js";
|
|
9
|
-
import { MetadataRegistry } from "../registry/metadata.registry.js";
|
|
7
|
+
import { createModuleRef } from "../module/decorators.js";
|
|
10
8
|
import { Module } from "../module/decorators.js";
|
|
11
9
|
import { HttpService, HTTP_MODULE_OPTIONS } from "./fetch.service.js";
|
|
12
10
|
export class HttpModule {
|
|
13
11
|
static register(options = {}) {
|
|
14
|
-
const moduleClass = class HttpDynamicModule {
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
17
|
-
value: 'HttpModule'
|
|
18
|
-
});
|
|
19
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
20
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
21
|
-
exports: [
|
|
22
|
-
HttpService,
|
|
23
|
-
HTTP_MODULE_OPTIONS
|
|
24
|
-
]
|
|
25
|
-
});
|
|
26
12
|
return {
|
|
27
|
-
module:
|
|
13
|
+
module: createModuleRef('HttpModule'),
|
|
28
14
|
providers: [
|
|
29
15
|
{
|
|
30
16
|
provide: HTTP_MODULE_OPTIONS,
|
|
31
17
|
useValue: options
|
|
32
18
|
},
|
|
33
19
|
HttpService
|
|
34
|
-
]
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
static registerAsync(options) {
|
|
38
|
-
const moduleClass = class HttpAsyncDynamicModule {
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
41
|
-
value: 'HttpModule'
|
|
42
|
-
});
|
|
43
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
44
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
45
|
-
imports: options.imports ?? [],
|
|
20
|
+
],
|
|
46
21
|
exports: [
|
|
47
22
|
HttpService,
|
|
48
23
|
HTTP_MODULE_OPTIONS
|
|
49
24
|
]
|
|
50
|
-
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static registerAsync(options) {
|
|
51
28
|
return {
|
|
52
|
-
module:
|
|
29
|
+
module: createModuleRef('HttpModule'),
|
|
30
|
+
imports: options.imports ?? [],
|
|
53
31
|
providers: [
|
|
54
32
|
{
|
|
55
33
|
provide: HTTP_MODULE_OPTIONS,
|
|
@@ -57,6 +35,10 @@ export class HttpModule {
|
|
|
57
35
|
inject: options.inject ?? []
|
|
58
36
|
},
|
|
59
37
|
HttpService
|
|
38
|
+
],
|
|
39
|
+
exports: [
|
|
40
|
+
HttpService,
|
|
41
|
+
HTTP_MODULE_OPTIONS
|
|
60
42
|
]
|
|
61
43
|
};
|
|
62
44
|
}
|
|
@@ -18,9 +18,12 @@ export interface MiddlewareRouteDefinition {
|
|
|
18
18
|
middleware: Array<Type<NestMiddleware> | NestMiddleware>;
|
|
19
19
|
routes: RouteInfo[];
|
|
20
20
|
excludes: RouteInfo[];
|
|
21
|
+
/** Stable-sort key; lower runs first. Default 0. */
|
|
22
|
+
priority?: number;
|
|
21
23
|
}
|
|
22
24
|
export interface MiddlewareConfigProxy {
|
|
23
25
|
exclude(...routes: Array<string | RouteInfo>): MiddlewareConfigProxy;
|
|
26
|
+
withPriority(priority: number): MiddlewareConfigProxy;
|
|
24
27
|
forRoutes(...routes: Array<string | Function | RouteInfo>): MiddlewareConsumer;
|
|
25
28
|
}
|
|
26
29
|
export interface MiddlewareConsumer {
|
|
@@ -17,11 +17,16 @@ export class MiddlewareBuilder {
|
|
|
17
17
|
...middleware
|
|
18
18
|
];
|
|
19
19
|
let currentExcludes = [];
|
|
20
|
+
let currentPriority;
|
|
20
21
|
const proxy = {
|
|
21
22
|
exclude: (...routes)=>{
|
|
22
23
|
currentExcludes = routes.map(normalizeRouteArg);
|
|
23
24
|
return proxy;
|
|
24
25
|
},
|
|
26
|
+
withPriority: (priority)=>{
|
|
27
|
+
currentPriority = priority;
|
|
28
|
+
return proxy;
|
|
29
|
+
},
|
|
25
30
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
26
31
|
forRoutes: (...routes)=>{
|
|
27
32
|
this.definitions.push({
|
|
@@ -29,9 +34,13 @@ export class MiddlewareBuilder {
|
|
|
29
34
|
routes: routes.flatMap(resolveRouteArg),
|
|
30
35
|
excludes: [
|
|
31
36
|
...currentExcludes
|
|
32
|
-
]
|
|
37
|
+
],
|
|
38
|
+
...currentPriority !== undefined ? {
|
|
39
|
+
priority: currentPriority
|
|
40
|
+
} : {}
|
|
33
41
|
});
|
|
34
42
|
currentExcludes = [];
|
|
43
|
+
currentPriority = undefined;
|
|
35
44
|
return this;
|
|
36
45
|
}
|
|
37
46
|
};
|
|
@@ -38,6 +38,7 @@ export declare class RouteManager {
|
|
|
38
38
|
useGlobalFilterTokens(...filterTokens: Array<Token<ExceptionFilter>>): this;
|
|
39
39
|
private instantiate;
|
|
40
40
|
private instantiateMany;
|
|
41
|
+
private getMiddlewarePriority;
|
|
41
42
|
private getRequestContainer;
|
|
42
43
|
registerController(controller: Type): this;
|
|
43
44
|
build(): Promise<Hono>;
|
|
@@ -175,6 +175,35 @@ export class RouteManager {
|
|
|
175
175
|
instantiateMany(items, container) {
|
|
176
176
|
return items.map((item)=>this.instantiate(item, container));
|
|
177
177
|
}
|
|
178
|
+
// Resolve middleware priority at build time. Supports three sources:
|
|
179
|
+
// 1. static priority on the class constructor
|
|
180
|
+
// 2. priority property on the instance
|
|
181
|
+
// 3. for container tokens, resolve and inspect the instance (+ its ctor)
|
|
182
|
+
// Falls back to 0 on any error or when no priority is set.
|
|
183
|
+
getMiddlewarePriority(entry) {
|
|
184
|
+
if (entry == null) return 0;
|
|
185
|
+
if (typeof entry === 'function') {
|
|
186
|
+
const p = entry.priority;
|
|
187
|
+
if (typeof p === 'number') return p;
|
|
188
|
+
}
|
|
189
|
+
if (typeof entry === 'object') {
|
|
190
|
+
const inst = entry;
|
|
191
|
+
if (typeof inst.priority === 'number') return inst.priority;
|
|
192
|
+
if (typeof inst.constructor?.priority === 'number') return inst.constructor.priority;
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
const resolved = this.instantiate(entry, this.container);
|
|
196
|
+
if (resolved && typeof resolved === 'object') {
|
|
197
|
+
const p = resolved.priority;
|
|
198
|
+
if (typeof p === 'number') return p;
|
|
199
|
+
const cp = resolved.constructor?.priority;
|
|
200
|
+
if (typeof cp === 'number') return cp;
|
|
201
|
+
}
|
|
202
|
+
} catch {
|
|
203
|
+
// Unresolvable at build time (e.g. request-scoped) — default 0
|
|
204
|
+
}
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
178
207
|
getRequestContainer(c) {
|
|
179
208
|
const existing = c.get('container');
|
|
180
209
|
if (existing) {
|
|
@@ -203,16 +232,29 @@ export class RouteManager {
|
|
|
203
232
|
}
|
|
204
233
|
async build() {
|
|
205
234
|
const app = new Hono();
|
|
235
|
+
// Sort global middleware by priority (lower runs first) with insertion
|
|
236
|
+
// index as tiebreaker so equal priorities preserve registration order.
|
|
237
|
+
const sortedGlobal = this.globalMiddleware.map((entry, index)=>({
|
|
238
|
+
entry,
|
|
239
|
+
index,
|
|
240
|
+
priority: this.getMiddlewarePriority(entry)
|
|
241
|
+
})).sort((a, b)=>a.priority - b.priority || a.index - b.index);
|
|
206
242
|
// Register global middleware on the Hono app
|
|
207
|
-
for (const
|
|
243
|
+
for (const { entry } of sortedGlobal){
|
|
208
244
|
app.use('*', (c, next)=>{
|
|
209
245
|
const requestContainer = this.getRequestContainer(c);
|
|
210
|
-
const resolved = this.instantiate(
|
|
246
|
+
const resolved = this.instantiate(entry, requestContainer);
|
|
211
247
|
return resolved.use(c, next);
|
|
212
248
|
});
|
|
213
249
|
}
|
|
250
|
+
// Sort consumer middleware with the same stable-by-index rule.
|
|
251
|
+
const sortedConsumer = this.consumerMiddlewareDefinitions.map((def, index)=>({
|
|
252
|
+
def,
|
|
253
|
+
index,
|
|
254
|
+
priority: def.priority ?? 0
|
|
255
|
+
})).sort((a, b)=>a.priority - b.priority || a.index - b.index);
|
|
214
256
|
// Register MiddlewareConsumer-configured middleware
|
|
215
|
-
for (const def of
|
|
257
|
+
for (const { def } of sortedConsumer){
|
|
216
258
|
const matchRoute = this.compileRouteMatcher(def.routes);
|
|
217
259
|
const matchExclude = this.compileRouteMatcher(def.excludes);
|
|
218
260
|
app.use('*', (c, next)=>{
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './metadata';
|
|
2
2
|
export { defineMetadata, getMetadata } from './metadata';
|
|
3
|
-
export { VelaFactory } from './factory';
|
|
3
|
+
export { VelaFactory, createApplication } from './factory';
|
|
4
4
|
export { VelaApplication } from './application';
|
|
5
5
|
export { Container, Injectable, Inject, Optional, InjectionToken, ForwardRef, forwardRef, ModuleRef, mixin } from './container/index';
|
|
6
6
|
export type { Type, Token, InjectableOptions, ProviderOptions, } from './container/index';
|
|
@@ -24,7 +24,7 @@ export { HealthModule, HealthCheckService, HealthIndicatorService, HttpHealthInd
|
|
|
24
24
|
export type { HealthCheckResult, HealthCheckStatus, HealthIndicatorResult, HealthIndicatorFunction, ResponseCheckCallback, HttpPingOptions, } from './health/index';
|
|
25
25
|
export { ThrottlerModule, ThrottlerGuard, ThrottlerStorage, Throttle, SkipThrottle, THROTTLER_OPTIONS, THROTTLER_STORAGE, THROTTLE_METADATA, SKIP_THROTTLE_METADATA, } from './throttler/index';
|
|
26
26
|
export type { ThrottlerModuleOptions, ThrottleConfig, ThrottlerStore, ThrottlerStorageRecord, RateLimitInfo, } from './throttler/index';
|
|
27
|
-
export { Global, Module } from './module/index';
|
|
27
|
+
export { Global, Module, createModuleRef } from './module/index';
|
|
28
28
|
export type { ModuleOptions, DynamicModule, AsyncModuleOptions, ModuleImport } from './module/index';
|
|
29
29
|
export { RequestMethod } from './http/index';
|
|
30
30
|
export type { MiddlewareConsumer, NestModule, RouteInfo } from './http/index';
|
|
@@ -41,6 +41,7 @@ export type { RouteManagerOptions } from './http/index';
|
|
|
41
41
|
export { ModuleLoader } from './module/index';
|
|
42
42
|
export { ComponentManager } from './pipeline/index';
|
|
43
43
|
export { createZodDto, ValidationPipe } from './validation/index';
|
|
44
|
+
export type { CreateZodDtoOptions } from './validation/index';
|
|
44
45
|
export { Serialize, SerializerInterceptor, SERIALIZE_METADATA } from './serialization/index';
|
|
45
46
|
export { Test, TestingModule, TestingModuleBuilder } from './testing/index';
|
|
46
47
|
export { getRuntimeKey, env } from 'hono/adapter';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./metadata.js";
|
|
2
2
|
export { defineMetadata, getMetadata } from "./metadata.js";
|
|
3
3
|
// Factory & Application
|
|
4
|
-
export { VelaFactory } from "./factory.js";
|
|
4
|
+
export { VelaFactory, createApplication } from "./factory.js";
|
|
5
5
|
export { VelaApplication } from "./application.js";
|
|
6
6
|
// DI Container
|
|
7
7
|
export { Container, Injectable, Inject, Optional, InjectionToken, ForwardRef, forwardRef, ModuleRef, mixin } from "./container/index.js";
|
|
@@ -28,7 +28,7 @@ export { HealthModule, HealthCheckService, HealthIndicatorService, HttpHealthInd
|
|
|
28
28
|
// Throttler
|
|
29
29
|
export { ThrottlerModule, ThrottlerGuard, ThrottlerStorage, Throttle, SkipThrottle, THROTTLER_OPTIONS, THROTTLER_STORAGE, THROTTLE_METADATA, SKIP_THROTTLE_METADATA } from "./throttler/index.js";
|
|
30
30
|
// Module
|
|
31
|
-
export { Global, Module } from "./module/index.js";
|
|
31
|
+
export { Global, Module, createModuleRef } from "./module/index.js";
|
|
32
32
|
export { RequestMethod } from "./http/index.js";
|
|
33
33
|
// Pipeline Decorators
|
|
34
34
|
export { UseMiddleware, UseGuards, UsePipes, UseInterceptors, UseFilters, Catch, SetMetadata, Reflector, APP_GUARD, APP_PIPE, APP_INTERCEPTOR, APP_FILTER, APP_MIDDLEWARE } from "./pipeline/index.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Constructor } from '../registry/types';
|
|
2
|
+
import type { Type } from '../container/types';
|
|
2
3
|
import type { ModuleMetadata, ModuleOptions } from './types';
|
|
3
4
|
export declare function Global(): ClassDecorator;
|
|
4
5
|
export declare function Module(options?: ModuleOptions): ClassDecorator;
|
|
5
6
|
export declare function isModule(target: Constructor): boolean;
|
|
7
|
+
export declare function createModuleRef(name: string): Type;
|
|
6
8
|
export declare function getModuleMetadata(target: Constructor): ModuleMetadata | undefined;
|
|
@@ -30,6 +30,14 @@ export function Module(options = {}) {
|
|
|
30
30
|
export function isModule(target) {
|
|
31
31
|
return MetadataRegistry.getModuleOptions(target) !== undefined || getMetadata(METADATA_KEYS.MODULE, target) === true || getMetadata(METADATA_KEYS.MODULE_OPTIONS, target) !== undefined;
|
|
32
32
|
}
|
|
33
|
+
export function createModuleRef(name) {
|
|
34
|
+
const moduleClass = class {
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(moduleClass, 'name', {
|
|
37
|
+
value: name
|
|
38
|
+
});
|
|
39
|
+
return moduleClass;
|
|
40
|
+
}
|
|
33
41
|
export function getModuleMetadata(target) {
|
|
34
42
|
if (!isModule(target)) {
|
|
35
43
|
return undefined;
|
package/dist/module/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Global, Module, isModule, getModuleMetadata } from './decorators';
|
|
1
|
+
export { Global, Module, isModule, getModuleMetadata, createModuleRef } from './decorators';
|
|
2
2
|
export { ModuleLoader } from './module-loader';
|
|
3
3
|
export type { ModuleOptions, ModuleMetadata, DynamicModule, AsyncModuleOptions, ModuleImport } from './types';
|
package/dist/module/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Global, Module, isModule, getModuleMetadata } from "./decorators.js";
|
|
1
|
+
export { Global, Module, isModule, getModuleMetadata, createModuleRef } from "./decorators.js";
|
|
2
2
|
export { ModuleLoader } from "./module-loader.js";
|
|
@@ -63,11 +63,13 @@ export class ModuleLoader {
|
|
|
63
63
|
let extraImports = [];
|
|
64
64
|
let extraControllers = [];
|
|
65
65
|
let extraProviders = [];
|
|
66
|
+
let extraExports = [];
|
|
66
67
|
if (isDynamicModule(moduleClassOrDynamic)) {
|
|
67
68
|
moduleClass = moduleClassOrDynamic.module;
|
|
68
69
|
extraImports = moduleClassOrDynamic.imports ?? [];
|
|
69
70
|
extraControllers = moduleClassOrDynamic.controllers ?? [];
|
|
70
71
|
extraProviders = moduleClassOrDynamic.providers ?? [];
|
|
72
|
+
extraExports = moduleClassOrDynamic.exports ?? [];
|
|
71
73
|
} else {
|
|
72
74
|
moduleClass = moduleClassOrDynamic;
|
|
73
75
|
}
|
|
@@ -86,7 +88,11 @@ export class ModuleLoader {
|
|
|
86
88
|
throw new Error(`Circular module dependency detected: ${chain}`);
|
|
87
89
|
}
|
|
88
90
|
if (!isModule(moduleClass)) {
|
|
89
|
-
|
|
91
|
+
if (isDynamicModule(moduleClassOrDynamic)) {
|
|
92
|
+
MetadataRegistry.setModuleOptions(moduleClass, {});
|
|
93
|
+
} else {
|
|
94
|
+
throw new Error(`${moduleClass.name} is not a module. Add @Module() decorator to the class.`);
|
|
95
|
+
}
|
|
90
96
|
}
|
|
91
97
|
const metadata = getModuleMetadata(moduleClass);
|
|
92
98
|
if (!metadata) {
|
|
@@ -134,7 +140,11 @@ export class ModuleLoader {
|
|
|
134
140
|
MetadataRegistry.propagateControllerComponents(moduleClass, controller);
|
|
135
141
|
}
|
|
136
142
|
this.processedModules.add(moduleClass);
|
|
137
|
-
const
|
|
143
|
+
const allExports = [
|
|
144
|
+
...metadata.exports,
|
|
145
|
+
...extraExports
|
|
146
|
+
];
|
|
147
|
+
const exports = this.buildExportSet(allExports, allProviders, importedProviders);
|
|
138
148
|
this.moduleExportsCache.set(moduleClass, exports);
|
|
139
149
|
const isGlobal = metadata.isGlobal || isDynamicModule(moduleClassOrDynamic) && moduleClassOrDynamic.global === true;
|
|
140
150
|
if (isGlobal) {
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import { METADATA_KEYS } from "../constants.js";
|
|
2
|
-
import { defineMetadata } from "../metadata.js";
|
|
3
|
-
import { MetadataRegistry } from "../registry/metadata.registry.js";
|
|
4
1
|
import { ScheduleExecutor } from "./schedule.executor.js";
|
|
5
2
|
import { ScheduleRegistry } from "./schedule.registry.js";
|
|
6
3
|
import { SCHEDULE_MODULE_OPTIONS } from "./schedule.tokens.js";
|
|
7
|
-
function makeScheduleModuleClass() {
|
|
8
|
-
const moduleClass = class ScheduleDynamicModule {
|
|
9
|
-
};
|
|
10
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
11
|
-
value: 'ScheduleModule'
|
|
12
|
-
});
|
|
13
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
14
|
-
return moduleClass;
|
|
15
|
-
}
|
|
16
4
|
export class ScheduleModule {
|
|
17
5
|
static forRoot(options = {}) {
|
|
18
6
|
const { enableTimers = false } = options;
|
|
19
|
-
const moduleClass = makeScheduleModuleClass();
|
|
20
7
|
const providers = [
|
|
21
8
|
{
|
|
22
9
|
provide: SCHEDULE_MODULE_OPTIONS,
|
|
@@ -32,17 +19,14 @@ export class ScheduleModule {
|
|
|
32
19
|
providers.push(ScheduleExecutor);
|
|
33
20
|
exports.push(ScheduleExecutor);
|
|
34
21
|
}
|
|
35
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
36
|
-
exports
|
|
37
|
-
});
|
|
38
22
|
return {
|
|
39
|
-
module:
|
|
40
|
-
providers
|
|
23
|
+
module: ScheduleModule,
|
|
24
|
+
providers,
|
|
25
|
+
exports
|
|
41
26
|
};
|
|
42
27
|
}
|
|
43
28
|
static forRootAsync(options) {
|
|
44
29
|
const { enableTimers = false } = options;
|
|
45
|
-
const moduleClass = makeScheduleModuleClass();
|
|
46
30
|
const providers = [
|
|
47
31
|
{
|
|
48
32
|
provide: SCHEDULE_MODULE_OPTIONS,
|
|
@@ -59,13 +43,11 @@ export class ScheduleModule {
|
|
|
59
43
|
providers.push(ScheduleExecutor);
|
|
60
44
|
exports.push(ScheduleExecutor);
|
|
61
45
|
}
|
|
62
|
-
|
|
46
|
+
return {
|
|
47
|
+
module: ScheduleModule,
|
|
63
48
|
imports: options.imports ?? [],
|
|
49
|
+
providers,
|
|
64
50
|
exports
|
|
65
|
-
});
|
|
66
|
-
return {
|
|
67
|
-
module: moduleClass,
|
|
68
|
-
providers
|
|
69
51
|
};
|
|
70
52
|
}
|
|
71
53
|
}
|
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
import { METADATA_KEYS } from "../constants.js";
|
|
2
|
-
import { defineMetadata } from "../metadata.js";
|
|
3
|
-
import { MetadataRegistry } from "../registry/metadata.registry.js";
|
|
4
1
|
import { APP_GUARD } from "../pipeline/tokens.js";
|
|
5
2
|
import { ThrottlerGuard } from "./throttler.guard.js";
|
|
6
3
|
import { ThrottlerStorage } from "./throttler.storage.js";
|
|
7
4
|
import { THROTTLER_OPTIONS, THROTTLER_STORAGE } from "./throttler.tokens.js";
|
|
8
|
-
function makeThrottlerModuleClass() {
|
|
9
|
-
const moduleClass = class ThrottlerDynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: 'ThrottlerModule'
|
|
13
|
-
});
|
|
14
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
15
|
-
return moduleClass;
|
|
16
|
-
}
|
|
17
5
|
export class ThrottlerModule {
|
|
18
6
|
static forRoot(options) {
|
|
19
|
-
const moduleClass = makeThrottlerModuleClass();
|
|
20
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
21
|
-
exports: [
|
|
22
|
-
THROTTLER_OPTIONS,
|
|
23
|
-
THROTTLER_STORAGE,
|
|
24
|
-
ThrottlerGuard
|
|
25
|
-
]
|
|
26
|
-
});
|
|
27
7
|
const providers = [
|
|
28
8
|
{
|
|
29
9
|
provide: THROTTLER_OPTIONS,
|
|
@@ -40,20 +20,16 @@ export class ThrottlerModule {
|
|
|
40
20
|
}
|
|
41
21
|
];
|
|
42
22
|
return {
|
|
43
|
-
module:
|
|
44
|
-
providers
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
static forRootAsync(options) {
|
|
48
|
-
const moduleClass = makeThrottlerModuleClass();
|
|
49
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
50
|
-
imports: options.imports ?? [],
|
|
23
|
+
module: ThrottlerModule,
|
|
24
|
+
providers,
|
|
51
25
|
exports: [
|
|
52
26
|
THROTTLER_OPTIONS,
|
|
53
27
|
THROTTLER_STORAGE,
|
|
54
28
|
ThrottlerGuard
|
|
55
29
|
]
|
|
56
|
-
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
static forRootAsync(options) {
|
|
57
33
|
const providers = [
|
|
58
34
|
{
|
|
59
35
|
provide: THROTTLER_OPTIONS,
|
|
@@ -74,8 +50,14 @@ export class ThrottlerModule {
|
|
|
74
50
|
}
|
|
75
51
|
];
|
|
76
52
|
return {
|
|
77
|
-
module:
|
|
78
|
-
|
|
53
|
+
module: ThrottlerModule,
|
|
54
|
+
imports: options.imports ?? [],
|
|
55
|
+
providers,
|
|
56
|
+
exports: [
|
|
57
|
+
THROTTLER_OPTIONS,
|
|
58
|
+
THROTTLER_STORAGE,
|
|
59
|
+
ThrottlerGuard
|
|
60
|
+
]
|
|
79
61
|
};
|
|
80
62
|
}
|
|
81
63
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface ZodLikeSchema {
|
|
2
2
|
parse(data: unknown): unknown;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type InferOutput<T extends ZodLikeSchema> = ReturnType<T['parse']>;
|
|
5
|
+
export interface CreateZodDtoOptions {
|
|
6
|
+
/** Override the generated class name (useful for debugging and OpenAPI). */
|
|
7
|
+
name?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function createZodDto<T extends ZodLikeSchema>(schema: T, options?: CreateZodDtoOptions): {
|
|
10
|
+
new (initial?: InferOutput<T>): InferOutput<T>;
|
|
6
11
|
schema: T;
|
|
7
12
|
};
|
|
8
13
|
export {};
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
export function createZodDto(schema) {
|
|
1
|
+
export function createZodDto(schema, options = {}) {
|
|
2
2
|
let ZodDto = class ZodDto {
|
|
3
3
|
static schema = schema;
|
|
4
|
+
constructor(initial){
|
|
5
|
+
if (initial && typeof initial === 'object') {
|
|
6
|
+
Object.assign(this, initial);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
4
9
|
};
|
|
10
|
+
if (options.name) {
|
|
11
|
+
Object.defineProperty(ZodDto, 'name', {
|
|
12
|
+
value: options.name,
|
|
13
|
+
configurable: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
5
16
|
return ZodDto;
|
|
6
17
|
}
|