@velajs/vela 0.4.3 → 0.5.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.d.ts +4 -1
- package/dist/cache/cache.module.js +51 -9
- package/dist/config/config.module.d.ts +4 -1
- package/dist/config/config.module.js +40 -3
- package/dist/config/config.types.d.ts +1 -0
- package/dist/constants.d.ts +6 -1
- package/dist/constants.js +5 -0
- package/dist/container/container.d.ts +2 -0
- package/dist/container/container.js +47 -15
- package/dist/container/decorators.d.ts +3 -1
- package/dist/container/decorators.js +27 -6
- package/dist/container/index.d.ts +4 -2
- package/dist/container/index.js +4 -2
- package/dist/container/mixin.d.ts +24 -0
- package/dist/container/mixin.js +26 -0
- package/dist/container/module-ref.d.ts +21 -0
- package/dist/container/module-ref.js +48 -0
- package/dist/container/types.d.ts +9 -3
- package/dist/container/types.js +9 -0
- package/dist/cors/cors.module.js +2 -2
- package/dist/factory.js +11 -2
- package/dist/fetch/fetch.module.d.ts +6 -0
- package/dist/fetch/fetch.module.js +77 -0
- package/dist/fetch/fetch.service.d.ts +24 -0
- package/dist/fetch/fetch.service.js +145 -0
- package/dist/fetch/fetch.types.d.ts +24 -0
- package/dist/fetch/fetch.types.js +1 -0
- package/dist/fetch/index.d.ts +3 -0
- package/dist/fetch/index.js +2 -0
- package/dist/http/decorators.d.ts +64 -0
- package/dist/http/decorators.js +89 -1
- package/dist/http/index.d.ts +3 -1
- package/dist/http/index.js +2 -1
- package/dist/http/middleware-consumer.d.ts +36 -0
- package/dist/http/middleware-consumer.js +71 -0
- package/dist/http/route.manager.d.ts +4 -0
- package/dist/http/route.manager.js +75 -1
- package/dist/index.d.ts +11 -6
- package/dist/index.js +7 -4
- package/dist/metadata.d.ts +1 -1
- package/dist/module/decorators.d.ts +1 -0
- package/dist/module/decorators.js +24 -8
- package/dist/module/index.d.ts +2 -2
- package/dist/module/index.js +1 -1
- package/dist/module/module-loader.d.ts +5 -1
- package/dist/module/module-loader.js +54 -10
- package/dist/module/types.d.ts +13 -3
- package/dist/pipeline/index.d.ts +3 -2
- package/dist/pipeline/index.js +1 -1
- package/dist/pipeline/pipes.d.ts +22 -0
- package/dist/pipeline/pipes.js +50 -0
- package/dist/pipeline/tokens.d.ts +1 -1
- package/dist/pipeline/tokens.js +1 -1
- package/dist/pipeline/types.d.ts +16 -0
- package/dist/registry/metadata.registry.d.ts +7 -6
- package/dist/registry/metadata.registry.js +13 -0
- package/dist/registry/types.d.ts +1 -0
- package/dist/schedule/schedule.module.d.ts +4 -1
- package/dist/schedule/schedule.module.js +39 -7
- package/dist/testing/testing.builder.js +5 -5
- package/dist/throttler/throttler.module.d.ts +2 -1
- package/dist/throttler/throttler.module.js +47 -9
- package/package.json +1 -1
|
@@ -38,12 +38,12 @@ export declare class MetadataRegistry {
|
|
|
38
38
|
static getController<T extends ComponentType>(type: T, controller: Constructor): ComponentTypeMap[T][];
|
|
39
39
|
static registerHandler<T extends ComponentType>(type: T, handlerKey: string, component: ComponentTypeMap[T]): void;
|
|
40
40
|
static getHandler<T extends ComponentType>(type: T, handlerKey: string): ComponentTypeMap[T][];
|
|
41
|
-
static markInjectable(target:
|
|
42
|
-
static hasInjectable(target:
|
|
43
|
-
static setScope(target:
|
|
44
|
-
static getScope(target:
|
|
45
|
-
static setInjectTokens(target:
|
|
46
|
-
static getInjectTokens(target:
|
|
41
|
+
static markInjectable(target: object): void;
|
|
42
|
+
static hasInjectable(target: object): boolean;
|
|
43
|
+
static setScope(target: object, scope: Scope): void;
|
|
44
|
+
static getScope(target: object): Scope | undefined;
|
|
45
|
+
static setInjectTokens(target: object, tokens: InjectMetadata[]): void;
|
|
46
|
+
static getInjectTokens(target: object): InjectMetadata[] | undefined;
|
|
47
47
|
static setHandlerHttpMeta(controller: Constructor, method: string | symbol, meta: HttpHandlerMeta): void;
|
|
48
48
|
static getHandlerHttpMeta(controller: Constructor, method: string | symbol): HttpHandlerMeta | undefined;
|
|
49
49
|
static setCatchTypes(filter: Constructor, types: Type<Error>[]): void;
|
|
@@ -57,5 +57,6 @@ export declare class MetadataRegistry {
|
|
|
57
57
|
static setCustomHandlerMeta(target: Constructor, handler: string | symbol, key: string, value: unknown): void;
|
|
58
58
|
static getCustomHandlerMeta(target: Constructor, handler: string | symbol, key: string): unknown;
|
|
59
59
|
static getCustomHandlerMetaAll(target: Constructor, handler: string | symbol): Map<string, unknown> | undefined;
|
|
60
|
+
static propagateControllerComponents(from: Constructor, to: Constructor): void;
|
|
60
61
|
static clear(): void;
|
|
61
62
|
}
|
|
@@ -248,6 +248,19 @@ export class MetadataRegistry {
|
|
|
248
248
|
static getCustomHandlerMetaAll(target, handler) {
|
|
249
249
|
return this.customHandlerMeta.get(target)?.get(handler);
|
|
250
250
|
}
|
|
251
|
+
// Propagate all controller-level components from one class to another.
|
|
252
|
+
// Used by ModuleLoader to apply module-level decorators to every controller.
|
|
253
|
+
static propagateControllerComponents(from, to) {
|
|
254
|
+
for (const [, typeMap] of this.controller.entries()){
|
|
255
|
+
const components = typeMap.get(from);
|
|
256
|
+
if (components && components.length > 0) {
|
|
257
|
+
if (!typeMap.has(to)) {
|
|
258
|
+
typeMap.set(to, []);
|
|
259
|
+
}
|
|
260
|
+
typeMap.get(to).push(...components);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
251
264
|
// Clear all (for testing)
|
|
252
265
|
static clear() {
|
|
253
266
|
this.routes.clear();
|
package/dist/registry/types.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { DynamicModule } from '../module/types';
|
|
1
|
+
import type { AsyncModuleOptions, DynamicModule } from '../module/types';
|
|
2
2
|
import type { ScheduleModuleOptions } from './schedule.types';
|
|
3
3
|
export declare class ScheduleModule {
|
|
4
4
|
static forRoot(options?: ScheduleModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: AsyncModuleOptions<ScheduleModuleOptions> & {
|
|
6
|
+
enableTimers?: boolean;
|
|
7
|
+
}): DynamicModule;
|
|
5
8
|
}
|
|
@@ -4,18 +4,22 @@ import { MetadataRegistry } from "../registry/metadata.registry.js";
|
|
|
4
4
|
import { ScheduleExecutor } from "./schedule.executor.js";
|
|
5
5
|
import { ScheduleRegistry } from "./schedule.registry.js";
|
|
6
6
|
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
|
+
}
|
|
7
16
|
export class ScheduleModule {
|
|
8
17
|
static forRoot(options = {}) {
|
|
9
18
|
const { enableTimers = false } = options;
|
|
10
|
-
const moduleClass =
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
13
|
-
value: 'ScheduleModule'
|
|
14
|
-
});
|
|
15
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
19
|
+
const moduleClass = makeScheduleModuleClass();
|
|
16
20
|
const providers = [
|
|
17
21
|
{
|
|
18
|
-
|
|
22
|
+
provide: SCHEDULE_MODULE_OPTIONS,
|
|
19
23
|
useValue: options
|
|
20
24
|
},
|
|
21
25
|
ScheduleRegistry
|
|
@@ -36,4 +40,32 @@ export class ScheduleModule {
|
|
|
36
40
|
providers
|
|
37
41
|
};
|
|
38
42
|
}
|
|
43
|
+
static forRootAsync(options) {
|
|
44
|
+
const { enableTimers = false } = options;
|
|
45
|
+
const moduleClass = makeScheduleModuleClass();
|
|
46
|
+
const providers = [
|
|
47
|
+
{
|
|
48
|
+
provide: SCHEDULE_MODULE_OPTIONS,
|
|
49
|
+
useFactory: options.useFactory,
|
|
50
|
+
inject: options.inject ?? []
|
|
51
|
+
},
|
|
52
|
+
ScheduleRegistry
|
|
53
|
+
];
|
|
54
|
+
const exports = [
|
|
55
|
+
SCHEDULE_MODULE_OPTIONS,
|
|
56
|
+
ScheduleRegistry
|
|
57
|
+
];
|
|
58
|
+
if (enableTimers) {
|
|
59
|
+
providers.push(ScheduleExecutor);
|
|
60
|
+
exports.push(ScheduleExecutor);
|
|
61
|
+
}
|
|
62
|
+
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
63
|
+
imports: options.imports ?? [],
|
|
64
|
+
exports
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
module: moduleClass,
|
|
68
|
+
providers
|
|
69
|
+
};
|
|
70
|
+
}
|
|
39
71
|
}
|
|
@@ -19,7 +19,7 @@ export class OverrideBy {
|
|
|
19
19
|
this.builder['addOverride']({
|
|
20
20
|
token: this.token,
|
|
21
21
|
provider: {
|
|
22
|
-
|
|
22
|
+
provide: this.token,
|
|
23
23
|
useValue: value
|
|
24
24
|
}
|
|
25
25
|
});
|
|
@@ -29,7 +29,7 @@ export class OverrideBy {
|
|
|
29
29
|
this.builder['addOverride']({
|
|
30
30
|
token: this.token,
|
|
31
31
|
provider: {
|
|
32
|
-
|
|
32
|
+
provide: this.token,
|
|
33
33
|
useClass: cls
|
|
34
34
|
}
|
|
35
35
|
});
|
|
@@ -39,7 +39,7 @@ export class OverrideBy {
|
|
|
39
39
|
this.builder['addOverride']({
|
|
40
40
|
token: this.token,
|
|
41
41
|
provider: {
|
|
42
|
-
|
|
42
|
+
provide: this.token,
|
|
43
43
|
useFactory: options.factory,
|
|
44
44
|
inject: options.inject
|
|
45
45
|
}
|
|
@@ -91,7 +91,7 @@ export class TestingModuleBuilder {
|
|
|
91
91
|
// Bootstrap (mirrors VelaFactory.create)
|
|
92
92
|
const container = new Container();
|
|
93
93
|
container.register({
|
|
94
|
-
|
|
94
|
+
provide: Container,
|
|
95
95
|
useValue: container
|
|
96
96
|
});
|
|
97
97
|
// Register overrides BEFORE module loading so ModuleLoader skips originals
|
|
@@ -133,7 +133,7 @@ export class TestingModuleBuilder {
|
|
|
133
133
|
routeManager.useGlobalMiddlewareTokens(APP_MIDDLEWARE);
|
|
134
134
|
}
|
|
135
135
|
const app = new VelaApplication(container, routeManager);
|
|
136
|
-
const instances = loader.resolveAllInstances();
|
|
136
|
+
const instances = await loader.resolveAllInstances();
|
|
137
137
|
app.setInstances(instances);
|
|
138
138
|
await app.callOnModuleInit();
|
|
139
139
|
await app.callOnApplicationBootstrap();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { DynamicModule } from '../module/types';
|
|
1
|
+
import type { AsyncModuleOptions, DynamicModule } from '../module/types';
|
|
2
2
|
import type { ThrottlerModuleOptions } from './throttler.types';
|
|
3
3
|
export declare class ThrottlerModule {
|
|
4
4
|
static forRoot(options: ThrottlerModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: AsyncModuleOptions<ThrottlerModuleOptions>): DynamicModule;
|
|
5
6
|
}
|
|
@@ -5,14 +5,18 @@ import { APP_GUARD } from "../pipeline/tokens.js";
|
|
|
5
5
|
import { ThrottlerGuard } from "./throttler.guard.js";
|
|
6
6
|
import { ThrottlerStorage } from "./throttler.storage.js";
|
|
7
7
|
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
|
+
}
|
|
8
17
|
export class ThrottlerModule {
|
|
9
18
|
static forRoot(options) {
|
|
10
|
-
const moduleClass =
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
13
|
-
value: 'ThrottlerModule'
|
|
14
|
-
});
|
|
15
|
-
defineMetadata(METADATA_KEYS.MODULE, true, moduleClass);
|
|
19
|
+
const moduleClass = makeThrottlerModuleClass();
|
|
16
20
|
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
17
21
|
exports: [
|
|
18
22
|
THROTTLER_OPTIONS,
|
|
@@ -22,16 +26,50 @@ export class ThrottlerModule {
|
|
|
22
26
|
});
|
|
23
27
|
const providers = [
|
|
24
28
|
{
|
|
25
|
-
|
|
29
|
+
provide: THROTTLER_OPTIONS,
|
|
26
30
|
useValue: options
|
|
27
31
|
},
|
|
28
32
|
{
|
|
29
|
-
|
|
33
|
+
provide: THROTTLER_STORAGE,
|
|
30
34
|
useValue: options.storage ?? new ThrottlerStorage()
|
|
31
35
|
},
|
|
32
36
|
ThrottlerGuard,
|
|
33
37
|
{
|
|
34
|
-
|
|
38
|
+
provide: APP_GUARD,
|
|
39
|
+
useExisting: ThrottlerGuard
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
return {
|
|
43
|
+
module: moduleClass,
|
|
44
|
+
providers
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
static forRootAsync(options) {
|
|
48
|
+
const moduleClass = makeThrottlerModuleClass();
|
|
49
|
+
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
50
|
+
imports: options.imports ?? [],
|
|
51
|
+
exports: [
|
|
52
|
+
THROTTLER_OPTIONS,
|
|
53
|
+
THROTTLER_STORAGE,
|
|
54
|
+
ThrottlerGuard
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
const providers = [
|
|
58
|
+
{
|
|
59
|
+
provide: THROTTLER_OPTIONS,
|
|
60
|
+
useFactory: options.useFactory,
|
|
61
|
+
inject: options.inject ?? []
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
provide: THROTTLER_STORAGE,
|
|
65
|
+
useFactory: (opts)=>opts.storage ?? new ThrottlerStorage(),
|
|
66
|
+
inject: [
|
|
67
|
+
THROTTLER_OPTIONS
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
ThrottlerGuard,
|
|
71
|
+
{
|
|
72
|
+
provide: APP_GUARD,
|
|
35
73
|
useExisting: ThrottlerGuard
|
|
36
74
|
}
|
|
37
75
|
];
|