@velajs/vela 1.0.0 → 1.1.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/CHANGELOG.md +80 -0
- package/README.md +36 -2
- package/dist/cache/cache.decorators.d.ts +2 -2
- package/dist/cache/cache.module.d.ts +1 -1
- package/dist/cache/cache.module.js +1 -1
- package/dist/constants.d.ts +8 -8
- package/dist/constants.js +8 -8
- package/dist/container/container.js +2 -2
- package/dist/container/decorators.js +8 -11
- package/dist/container/types.d.ts +1 -0
- package/dist/errors/http-exception.d.ts +21 -20
- package/dist/errors/http-exception.js +6 -6
- package/dist/event-emitter/event-emitter.decorators.js +2 -3
- package/dist/event-emitter/event-emitter.subscriber.js +2 -1
- package/dist/factory.d.ts +0 -1
- package/dist/factory.js +2 -32
- package/dist/fetch/fetch.module.d.ts +2 -2
- package/dist/fetch/fetch.module.js +2 -2
- package/dist/health/health.service.js +6 -2
- package/dist/http/decorators.d.ts +6 -5
- package/dist/http/decorators.js +28 -76
- package/dist/http/execution-context.d.ts +4 -0
- package/dist/http/execution-context.js +15 -0
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +1 -1
- package/dist/http/route.manager.d.ts +1 -2
- package/dist/http/route.manager.js +19 -25
- package/dist/http/types.d.ts +0 -1
- package/dist/index.d.ts +2 -8
- package/dist/index.js +6 -11
- package/dist/internal.d.ts +11 -0
- package/dist/internal.js +13 -0
- package/dist/metadata.js +6 -15
- package/dist/module/decorators.d.ts +1 -3
- package/dist/module/decorators.js +8 -20
- package/dist/module/graph.d.ts +10 -0
- package/dist/module/graph.js +35 -0
- package/dist/module/index.d.ts +2 -0
- package/dist/module/index.js +1 -0
- package/dist/{http/middleware-consumer.d.ts → module/middleware.d.ts} +4 -14
- package/dist/{http/middleware-consumer.js → module/middleware.js} +0 -12
- package/dist/module/module-loader.d.ts +1 -1
- package/dist/module/module-loader.js +17 -13
- package/dist/module/types.d.ts +1 -29
- package/dist/openapi/decorators.js +15 -10
- package/dist/openapi/document.js +7 -42
- package/dist/pipeline/app-providers.d.ts +10 -0
- package/dist/pipeline/app-providers.js +43 -0
- package/dist/pipeline/decorators.d.ts +5 -5
- package/dist/pipeline/decorators.js +1 -9
- package/dist/pipeline/reflector.d.ts +8 -24
- package/dist/pipeline/reflector.js +10 -55
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/metadata.registry.d.ts +18 -13
- package/dist/registry/metadata.registry.js +133 -159
- package/dist/registry/paths.d.ts +3 -0
- package/dist/registry/paths.js +15 -0
- package/dist/registry/types.d.ts +24 -14
- package/dist/registry/types.js +0 -1
- package/dist/registry/util.d.ts +3 -0
- package/dist/registry/util.js +8 -0
- package/dist/schedule/schedule.decorators.js +3 -6
- package/dist/schedule/schedule.registry.js +3 -2
- package/dist/throttler/throttler.decorators.d.ts +2 -2
- package/package.json +5 -9
- package/dist/testing/index.d.ts +0 -2
- package/dist/testing/index.js +0 -2
- package/dist/testing/testing.builder.d.ts +0 -29
- package/dist/testing/testing.builder.js +0 -148
- package/dist/testing/testing.module.d.ts +0 -9
- package/dist/testing/testing.module.js +0 -15
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { VelaApplication } from "../application.js";
|
|
2
|
-
import { METADATA_KEYS } from "../constants.js";
|
|
3
|
-
import { Container } from "../container/container.js";
|
|
4
|
-
import { RouteManager } from "../http/route.manager.js";
|
|
5
|
-
import { defineMetadata } from "../metadata.js";
|
|
6
|
-
import { ModuleLoader } from "../module/module-loader.js";
|
|
7
|
-
import { ComponentManager } from "../pipeline/component.manager.js";
|
|
8
|
-
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_MIDDLEWARE, APP_PIPE } from "../pipeline/tokens.js";
|
|
9
|
-
import { MetadataRegistry } from "../registry/metadata.registry.js";
|
|
10
|
-
import { TestingModule } from "./testing.module.js";
|
|
11
|
-
export class OverrideBy {
|
|
12
|
-
builder;
|
|
13
|
-
token;
|
|
14
|
-
constructor(builder, token){
|
|
15
|
-
this.builder = builder;
|
|
16
|
-
this.token = token;
|
|
17
|
-
}
|
|
18
|
-
useValue(value) {
|
|
19
|
-
this.builder['addOverride']({
|
|
20
|
-
token: this.token,
|
|
21
|
-
provider: {
|
|
22
|
-
provide: this.token,
|
|
23
|
-
useValue: value
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return this.builder;
|
|
27
|
-
}
|
|
28
|
-
useClass(cls) {
|
|
29
|
-
this.builder['addOverride']({
|
|
30
|
-
token: this.token,
|
|
31
|
-
provider: {
|
|
32
|
-
provide: this.token,
|
|
33
|
-
useClass: cls
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return this.builder;
|
|
37
|
-
}
|
|
38
|
-
useFactory(options) {
|
|
39
|
-
this.builder['addOverride']({
|
|
40
|
-
token: this.token,
|
|
41
|
-
provider: {
|
|
42
|
-
provide: this.token,
|
|
43
|
-
useFactory: options.factory,
|
|
44
|
-
inject: options.inject
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return this.builder;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export class TestingModuleBuilder {
|
|
51
|
-
metadata;
|
|
52
|
-
overrides = [];
|
|
53
|
-
constructor(metadata){
|
|
54
|
-
this.metadata = metadata;
|
|
55
|
-
}
|
|
56
|
-
overrideProvider(token) {
|
|
57
|
-
return new OverrideBy(this, token);
|
|
58
|
-
}
|
|
59
|
-
overrideGuard(guard) {
|
|
60
|
-
return new OverrideBy(this, guard);
|
|
61
|
-
}
|
|
62
|
-
overridePipe(pipe) {
|
|
63
|
-
return new OverrideBy(this, pipe);
|
|
64
|
-
}
|
|
65
|
-
overrideInterceptor(interceptor) {
|
|
66
|
-
return new OverrideBy(this, interceptor);
|
|
67
|
-
}
|
|
68
|
-
overrideFilter(filter) {
|
|
69
|
-
return new OverrideBy(this, filter);
|
|
70
|
-
}
|
|
71
|
-
addOverride(entry) {
|
|
72
|
-
// Replace existing override for same token if any
|
|
73
|
-
const idx = this.overrides.findIndex((o)=>o.token === entry.token);
|
|
74
|
-
if (idx !== -1) {
|
|
75
|
-
this.overrides[idx] = entry;
|
|
76
|
-
} else {
|
|
77
|
-
this.overrides.push(entry);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async compile() {
|
|
81
|
-
// Create a temporary module class with the provided metadata
|
|
82
|
-
let TestRootModule = class TestRootModule {
|
|
83
|
-
};
|
|
84
|
-
MetadataRegistry.setModuleOptions(TestRootModule, {
|
|
85
|
-
imports: this.metadata.imports,
|
|
86
|
-
providers: this.metadata.providers,
|
|
87
|
-
controllers: this.metadata.controllers,
|
|
88
|
-
exports: this.metadata.exports
|
|
89
|
-
});
|
|
90
|
-
defineMetadata(METADATA_KEYS.MODULE, true, TestRootModule);
|
|
91
|
-
// Bootstrap (mirrors VelaFactory.create)
|
|
92
|
-
const container = new Container();
|
|
93
|
-
container.register({
|
|
94
|
-
provide: Container,
|
|
95
|
-
useValue: container
|
|
96
|
-
});
|
|
97
|
-
// Register overrides BEFORE module loading so ModuleLoader skips originals
|
|
98
|
-
for (const override of this.overrides){
|
|
99
|
-
container.register(override.provider);
|
|
100
|
-
}
|
|
101
|
-
const routeManager = new RouteManager(container);
|
|
102
|
-
ComponentManager.init(container);
|
|
103
|
-
const loader = new ModuleLoader(container, routeManager);
|
|
104
|
-
loader.load(TestRootModule);
|
|
105
|
-
const appGuards = loader.getAppProviderTokens(APP_GUARD);
|
|
106
|
-
if (appGuards.length > 0) {
|
|
107
|
-
routeManager.useGlobalGuardTokens(...appGuards);
|
|
108
|
-
} else if (container.has(APP_GUARD)) {
|
|
109
|
-
routeManager.useGlobalGuardTokens(APP_GUARD);
|
|
110
|
-
}
|
|
111
|
-
const appPipes = loader.getAppProviderTokens(APP_PIPE);
|
|
112
|
-
if (appPipes.length > 0) {
|
|
113
|
-
routeManager.useGlobalPipeTokens(...appPipes);
|
|
114
|
-
} else if (container.has(APP_PIPE)) {
|
|
115
|
-
routeManager.useGlobalPipeTokens(APP_PIPE);
|
|
116
|
-
}
|
|
117
|
-
const appInterceptors = loader.getAppProviderTokens(APP_INTERCEPTOR);
|
|
118
|
-
if (appInterceptors.length > 0) {
|
|
119
|
-
routeManager.useGlobalInterceptorTokens(...appInterceptors);
|
|
120
|
-
} else if (container.has(APP_INTERCEPTOR)) {
|
|
121
|
-
routeManager.useGlobalInterceptorTokens(APP_INTERCEPTOR);
|
|
122
|
-
}
|
|
123
|
-
const appFilters = loader.getAppProviderTokens(APP_FILTER);
|
|
124
|
-
if (appFilters.length > 0) {
|
|
125
|
-
routeManager.useGlobalFilterTokens(...appFilters);
|
|
126
|
-
} else if (container.has(APP_FILTER)) {
|
|
127
|
-
routeManager.useGlobalFilterTokens(APP_FILTER);
|
|
128
|
-
}
|
|
129
|
-
const appMiddleware = loader.getAppProviderTokens(APP_MIDDLEWARE);
|
|
130
|
-
if (appMiddleware.length > 0) {
|
|
131
|
-
routeManager.useGlobalMiddlewareTokens(...appMiddleware);
|
|
132
|
-
} else if (container.has(APP_MIDDLEWARE)) {
|
|
133
|
-
routeManager.useGlobalMiddlewareTokens(APP_MIDDLEWARE);
|
|
134
|
-
}
|
|
135
|
-
const app = new VelaApplication(container, routeManager);
|
|
136
|
-
const instances = await loader.resolveAllInstances();
|
|
137
|
-
app.setInstances(instances);
|
|
138
|
-
await app.callOnModuleInit();
|
|
139
|
-
await app.callOnApplicationBootstrap();
|
|
140
|
-
await app.initRoutes();
|
|
141
|
-
return new TestingModule(app);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
export class Test {
|
|
145
|
-
static createTestingModule(metadata) {
|
|
146
|
-
return new TestingModuleBuilder(metadata);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { VelaApplication } from '../application';
|
|
2
|
-
import type { Token } from '../container/types';
|
|
3
|
-
export declare class TestingModule {
|
|
4
|
-
private readonly app;
|
|
5
|
-
constructor(app: VelaApplication);
|
|
6
|
-
get<T>(token: Token<T>): T;
|
|
7
|
-
close(signal?: string): Promise<void>;
|
|
8
|
-
createNestApplication(): VelaApplication;
|
|
9
|
-
}
|