@velajs/vela 1.0.0 → 1.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +36 -2
  3. package/dist/cache/cache.decorators.d.ts +2 -2
  4. package/dist/cache/cache.module.d.ts +1 -1
  5. package/dist/cache/cache.module.js +1 -1
  6. package/dist/constants.d.ts +8 -8
  7. package/dist/constants.js +8 -8
  8. package/dist/container/container.js +2 -2
  9. package/dist/container/decorators.js +8 -11
  10. package/dist/container/types.d.ts +1 -0
  11. package/dist/errors/http-exception.d.ts +21 -20
  12. package/dist/errors/http-exception.js +6 -6
  13. package/dist/event-emitter/event-emitter.decorators.js +2 -3
  14. package/dist/event-emitter/event-emitter.subscriber.js +2 -1
  15. package/dist/factory.d.ts +0 -1
  16. package/dist/factory.js +2 -32
  17. package/dist/fetch/fetch.module.d.ts +2 -2
  18. package/dist/fetch/fetch.module.js +2 -2
  19. package/dist/health/health.service.js +6 -2
  20. package/dist/http/decorators.d.ts +6 -5
  21. package/dist/http/decorators.js +28 -76
  22. package/dist/http/execution-context.d.ts +4 -0
  23. package/dist/http/execution-context.js +15 -0
  24. package/dist/http/index.d.ts +2 -2
  25. package/dist/http/index.js +1 -1
  26. package/dist/http/route.manager.d.ts +1 -2
  27. package/dist/http/route.manager.js +19 -25
  28. package/dist/http/types.d.ts +0 -1
  29. package/dist/index.d.ts +2 -8
  30. package/dist/index.js +6 -11
  31. package/dist/internal.d.ts +11 -0
  32. package/dist/internal.js +13 -0
  33. package/dist/metadata.js +6 -15
  34. package/dist/module/decorators.d.ts +1 -3
  35. package/dist/module/decorators.js +8 -20
  36. package/dist/module/graph.d.ts +10 -0
  37. package/dist/module/graph.js +35 -0
  38. package/dist/module/index.d.ts +2 -0
  39. package/dist/module/index.js +1 -0
  40. package/dist/{http/middleware-consumer.d.ts → module/middleware.d.ts} +4 -14
  41. package/dist/{http/middleware-consumer.js → module/middleware.js} +0 -12
  42. package/dist/module/module-loader.d.ts +1 -1
  43. package/dist/module/module-loader.js +17 -13
  44. package/dist/module/types.d.ts +1 -29
  45. package/dist/openapi/decorators.js +15 -10
  46. package/dist/openapi/document.js +7 -42
  47. package/dist/pipeline/app-providers.d.ts +10 -0
  48. package/dist/pipeline/app-providers.js +43 -0
  49. package/dist/pipeline/decorators.d.ts +5 -5
  50. package/dist/pipeline/decorators.js +1 -9
  51. package/dist/pipeline/reflector.d.ts +8 -24
  52. package/dist/pipeline/reflector.js +10 -55
  53. package/dist/registry/index.d.ts +1 -1
  54. package/dist/registry/metadata.registry.d.ts +18 -13
  55. package/dist/registry/metadata.registry.js +133 -159
  56. package/dist/registry/paths.d.ts +3 -0
  57. package/dist/registry/paths.js +15 -0
  58. package/dist/registry/types.d.ts +24 -14
  59. package/dist/registry/types.js +0 -1
  60. package/dist/registry/util.d.ts +3 -0
  61. package/dist/registry/util.js +8 -0
  62. package/dist/schedule/schedule.decorators.js +3 -6
  63. package/dist/schedule/schedule.registry.js +3 -2
  64. package/dist/schedule-node/index.d.ts +1 -0
  65. package/dist/schedule-node/index.js +1 -0
  66. package/dist/throttler/throttler.decorators.d.ts +2 -2
  67. package/package.json +5 -9
  68. package/dist/testing/index.d.ts +0 -2
  69. package/dist/testing/index.js +0 -2
  70. package/dist/testing/testing.builder.d.ts +0 -29
  71. package/dist/testing/testing.builder.js +0 -148
  72. package/dist/testing/testing.module.d.ts +0 -9
  73. 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
- }
@@ -1,15 +0,0 @@
1
- export class TestingModule {
2
- app;
3
- constructor(app){
4
- this.app = app;
5
- }
6
- get(token) {
7
- return this.app.get(token);
8
- }
9
- async close(signal) {
10
- await this.app.close(signal);
11
- }
12
- createNestApplication() {
13
- return this.app;
14
- }
15
- }