@velajs/vela 0.4.2 → 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.
Files changed (65) hide show
  1. package/dist/cache/cache.module.d.ts +4 -1
  2. package/dist/cache/cache.module.js +51 -9
  3. package/dist/config/config.module.d.ts +4 -1
  4. package/dist/config/config.module.js +40 -3
  5. package/dist/config/config.types.d.ts +1 -0
  6. package/dist/constants.d.ts +6 -1
  7. package/dist/constants.js +5 -0
  8. package/dist/container/container.d.ts +4 -0
  9. package/dist/container/container.js +52 -15
  10. package/dist/container/decorators.d.ts +3 -1
  11. package/dist/container/decorators.js +27 -6
  12. package/dist/container/index.d.ts +4 -2
  13. package/dist/container/index.js +4 -2
  14. package/dist/container/mixin.d.ts +24 -0
  15. package/dist/container/mixin.js +26 -0
  16. package/dist/container/module-ref.d.ts +21 -0
  17. package/dist/container/module-ref.js +48 -0
  18. package/dist/container/types.d.ts +10 -3
  19. package/dist/container/types.js +9 -0
  20. package/dist/cors/cors.module.js +2 -2
  21. package/dist/factory.js +36 -13
  22. package/dist/fetch/fetch.module.d.ts +6 -0
  23. package/dist/fetch/fetch.module.js +77 -0
  24. package/dist/fetch/fetch.service.d.ts +24 -0
  25. package/dist/fetch/fetch.service.js +145 -0
  26. package/dist/fetch/fetch.types.d.ts +24 -0
  27. package/dist/fetch/fetch.types.js +1 -0
  28. package/dist/fetch/index.d.ts +3 -0
  29. package/dist/fetch/index.js +2 -0
  30. package/dist/http/decorators.d.ts +64 -0
  31. package/dist/http/decorators.js +89 -1
  32. package/dist/http/index.d.ts +3 -1
  33. package/dist/http/index.js +2 -1
  34. package/dist/http/middleware-consumer.d.ts +36 -0
  35. package/dist/http/middleware-consumer.js +71 -0
  36. package/dist/http/route.manager.d.ts +13 -1
  37. package/dist/http/route.manager.js +153 -53
  38. package/dist/index.d.ts +11 -6
  39. package/dist/index.js +7 -4
  40. package/dist/metadata.d.ts +1 -1
  41. package/dist/module/decorators.d.ts +1 -0
  42. package/dist/module/decorators.js +24 -8
  43. package/dist/module/index.d.ts +2 -2
  44. package/dist/module/index.js +1 -1
  45. package/dist/module/module-loader.d.ts +9 -1
  46. package/dist/module/module-loader.js +107 -11
  47. package/dist/module/types.d.ts +13 -3
  48. package/dist/pipeline/index.d.ts +3 -2
  49. package/dist/pipeline/index.js +1 -1
  50. package/dist/pipeline/pipes.d.ts +22 -0
  51. package/dist/pipeline/pipes.js +50 -0
  52. package/dist/pipeline/tokens.d.ts +1 -1
  53. package/dist/pipeline/tokens.js +1 -1
  54. package/dist/pipeline/types.d.ts +16 -0
  55. package/dist/registry/metadata.registry.d.ts +7 -6
  56. package/dist/registry/metadata.registry.js +13 -0
  57. package/dist/registry/types.d.ts +1 -0
  58. package/dist/schedule/schedule.executor.d.ts +11 -2
  59. package/dist/schedule/schedule.executor.js +134 -19
  60. package/dist/schedule/schedule.module.d.ts +4 -1
  61. package/dist/schedule/schedule.module.js +39 -7
  62. package/dist/testing/testing.builder.js +31 -17
  63. package/dist/throttler/throttler.module.d.ts +2 -1
  64. package/dist/throttler/throttler.module.js +47 -9
  65. package/package.json +1 -1
@@ -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 = class ScheduleDynamicModule {
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
- token: SCHEDULE_MODULE_OPTIONS,
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
- token: this.token,
22
+ provide: this.token,
23
23
  useValue: value
24
24
  }
25
25
  });
@@ -29,8 +29,8 @@ export class OverrideBy {
29
29
  this.builder['addOverride']({
30
30
  token: this.token,
31
31
  provider: {
32
- token: this.token,
33
- useFactory: ()=>new cls()
32
+ provide: this.token,
33
+ useClass: cls
34
34
  }
35
35
  });
36
36
  return this.builder;
@@ -39,7 +39,7 @@ export class OverrideBy {
39
39
  this.builder['addOverride']({
40
40
  token: this.token,
41
41
  provider: {
42
- token: this.token,
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
- token: Container,
94
+ provide: Container,
95
95
  useValue: container
96
96
  });
97
97
  // Register overrides BEFORE module loading so ModuleLoader skips originals
@@ -102,24 +102,38 @@ export class TestingModuleBuilder {
102
102
  ComponentManager.init(container);
103
103
  const loader = new ModuleLoader(container, routeManager);
104
104
  loader.load(TestRootModule);
105
- // Resolve APP_* tokens
106
- if (container.has(APP_GUARD)) {
107
- routeManager.useGlobalGuards(container.resolve(APP_GUARD));
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);
108
110
  }
109
- if (container.has(APP_PIPE)) {
110
- routeManager.useGlobalPipes(container.resolve(APP_PIPE));
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);
111
116
  }
112
- if (container.has(APP_INTERCEPTOR)) {
113
- routeManager.useGlobalInterceptors(container.resolve(APP_INTERCEPTOR));
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);
114
122
  }
115
- if (container.has(APP_FILTER)) {
116
- routeManager.useGlobalFilters(container.resolve(APP_FILTER));
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);
117
128
  }
118
- if (container.has(APP_MIDDLEWARE)) {
119
- routeManager.useGlobalMiddleware(container.resolve(APP_MIDDLEWARE));
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);
120
134
  }
121
135
  const app = new VelaApplication(container, routeManager);
122
- const instances = loader.resolveAllInstances();
136
+ const instances = await loader.resolveAllInstances();
123
137
  app.setInstances(instances);
124
138
  await app.callOnModuleInit();
125
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 = class ThrottlerDynamicModule {
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
- token: THROTTLER_OPTIONS,
29
+ provide: THROTTLER_OPTIONS,
26
30
  useValue: options
27
31
  },
28
32
  {
29
- token: THROTTLER_STORAGE,
33
+ provide: THROTTLER_STORAGE,
30
34
  useValue: options.storage ?? new ThrottlerStorage()
31
35
  },
32
36
  ThrottlerGuard,
33
37
  {
34
- token: APP_GUARD,
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
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velajs/vela",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "NestJS-compatible framework for edge runtimes, powered by Hono",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",