@onebun/core 0.1.2 → 0.1.3
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/package.json +1 -1
- package/src/{application.test.ts → application/application.test.ts} +6 -5
- package/src/{application.ts → application/application.ts} +131 -12
- package/src/application/index.ts +9 -0
- package/src/{multi-service-application.test.ts → application/multi-service-application.test.ts} +2 -1
- package/src/{multi-service-application.ts → application/multi-service-application.ts} +2 -1
- package/src/{multi-service.types.ts → application/multi-service.types.ts} +1 -1
- package/src/{decorators.test.ts → decorators/decorators.test.ts} +2 -1
- package/src/{decorators.ts → decorators/decorators.ts} +3 -2
- package/src/decorators/index.ts +15 -0
- package/src/index.ts +47 -134
- package/src/module/index.ts +12 -0
- package/src/{module.test.ts → module/module.test.ts} +3 -2
- package/src/{module.ts → module/module.ts} +6 -5
- package/src/queue/adapters/index.ts +8 -0
- package/src/queue/adapters/memory.adapter.test.ts +405 -0
- package/src/queue/adapters/memory.adapter.ts +509 -0
- package/src/queue/adapters/redis.adapter.ts +673 -0
- package/src/queue/cron-expression.test.ts +145 -0
- package/src/queue/cron-expression.ts +115 -0
- package/src/queue/cron-parser.test.ts +185 -0
- package/src/queue/cron-parser.ts +287 -0
- package/src/queue/decorators.test.ts +292 -0
- package/src/queue/decorators.ts +493 -0
- package/src/queue/docs-examples.test.ts +449 -0
- package/src/queue/guards.test.ts +309 -0
- package/src/queue/guards.ts +307 -0
- package/src/queue/index.ts +118 -0
- package/src/queue/pattern-matcher.test.ts +191 -0
- package/src/queue/pattern-matcher.ts +252 -0
- package/src/queue/queue.service.ts +421 -0
- package/src/queue/scheduler.test.ts +235 -0
- package/src/queue/scheduler.ts +379 -0
- package/src/queue/types.ts +502 -0
- package/src/redis/index.ts +8 -0
- package/src/{env-resolver.ts → service-client/env-resolver.ts} +1 -1
- package/src/service-client/index.ts +10 -0
- package/src/{service-client.test.ts → service-client/service-client.test.ts} +3 -2
- package/src/{service-client.ts → service-client/service-client.ts} +1 -1
- package/src/{service-definition.test.ts → service-client/service-definition.test.ts} +3 -2
- package/src/{service-definition.ts → service-client/service-definition.ts} +2 -2
- package/src/testing/index.ts +7 -0
- package/src/types.ts +34 -5
- package/src/websocket/index.ts +50 -0
- package/src/{ws-decorators.ts → websocket/ws-decorators.ts} +2 -1
- package/src/{ws-integration.test.ts → websocket/ws-integration.test.ts} +3 -2
- package/src/{ws-service-definition.ts → websocket/ws-service-definition.ts} +2 -1
- package/src/{ws-storage-redis.ts → websocket/ws-storage-redis.ts} +1 -1
- /package/src/{metadata.test.ts → decorators/metadata.test.ts} +0 -0
- /package/src/{metadata.ts → decorators/metadata.ts} +0 -0
- /package/src/{config.service.test.ts → module/config.service.test.ts} +0 -0
- /package/src/{config.service.ts → module/config.service.ts} +0 -0
- /package/src/{controller.test.ts → module/controller.test.ts} +0 -0
- /package/src/{controller.ts → module/controller.ts} +0 -0
- /package/src/{service.test.ts → module/service.test.ts} +0 -0
- /package/src/{service.ts → module/service.ts} +0 -0
- /package/src/{redis-client.ts → redis/redis-client.ts} +0 -0
- /package/src/{shared-redis.ts → redis/shared-redis.ts} +0 -0
- /package/src/{env-resolver.test.ts → service-client/env-resolver.test.ts} +0 -0
- /package/src/{service-client.types.ts → service-client/service-client.types.ts} +0 -0
- /package/src/{test-utils.test.ts → testing/test-utils.test.ts} +0 -0
- /package/src/{test-utils.ts → testing/test-utils.ts} +0 -0
- /package/src/{ws-base-gateway.test.ts → websocket/ws-base-gateway.test.ts} +0 -0
- /package/src/{ws-base-gateway.ts → websocket/ws-base-gateway.ts} +0 -0
- /package/src/{ws-client.test.ts → websocket/ws-client.test.ts} +0 -0
- /package/src/{ws-client.ts → websocket/ws-client.ts} +0 -0
- /package/src/{ws-client.types.ts → websocket/ws-client.types.ts} +0 -0
- /package/src/{ws-decorators.test.ts → websocket/ws-decorators.test.ts} +0 -0
- /package/src/{ws-guards.test.ts → websocket/ws-guards.test.ts} +0 -0
- /package/src/{ws-guards.ts → websocket/ws-guards.ts} +0 -0
- /package/src/{ws-handler.ts → websocket/ws-handler.ts} +0 -0
- /package/src/{ws-pattern-matcher.test.ts → websocket/ws-pattern-matcher.test.ts} +0 -0
- /package/src/{ws-pattern-matcher.ts → websocket/ws-pattern-matcher.ts} +0 -0
- /package/src/{ws-socketio-protocol.test.ts → websocket/ws-socketio-protocol.test.ts} +0 -0
- /package/src/{ws-socketio-protocol.ts → websocket/ws-socketio-protocol.ts} +0 -0
- /package/src/{ws-storage-memory.test.ts → websocket/ws-storage-memory.test.ts} +0 -0
- /package/src/{ws-storage-memory.ts → websocket/ws-storage-memory.ts} +0 -0
- /package/src/{ws-storage.ts → websocket/ws-storage.ts} +0 -0
- /package/src/{ws.types.ts → websocket/ws.types.ts} +0 -0
package/package.json
CHANGED
|
@@ -9,10 +9,8 @@ import {
|
|
|
9
9
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
10
10
|
import { register } from 'prom-client';
|
|
11
11
|
|
|
12
|
-
import type { ApplicationOptions } from '
|
|
12
|
+
import type { ApplicationOptions } from '../types';
|
|
13
13
|
|
|
14
|
-
import { OneBunApplication } from './application';
|
|
15
|
-
import { Controller as BaseController } from './controller';
|
|
16
14
|
import {
|
|
17
15
|
Module,
|
|
18
16
|
Controller,
|
|
@@ -21,8 +19,11 @@ import {
|
|
|
21
19
|
Param,
|
|
22
20
|
Query,
|
|
23
21
|
Body,
|
|
24
|
-
} from '
|
|
25
|
-
import {
|
|
22
|
+
} from '../decorators/decorators';
|
|
23
|
+
import { Controller as BaseController } from '../module/controller';
|
|
24
|
+
import { makeMockLoggerLayer } from '../testing/test-utils';
|
|
25
|
+
|
|
26
|
+
import { OneBunApplication } from './application';
|
|
26
27
|
|
|
27
28
|
// Helper function to create app with mock logger to suppress logs in tests
|
|
28
29
|
function createTestApp(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, type Layer } from 'effect';
|
|
2
2
|
|
|
3
|
-
import type { Controller } from '
|
|
4
|
-
import type { WsClientData } from '
|
|
3
|
+
import type { Controller } from '../module/controller';
|
|
4
|
+
import type { WsClientData } from '../websocket/ws.types';
|
|
5
5
|
|
|
6
6
|
import { TypedEnv } from '@onebun/envs';
|
|
7
7
|
import {
|
|
@@ -20,20 +20,24 @@ import {
|
|
|
20
20
|
} from '@onebun/requests';
|
|
21
21
|
import { makeTraceService, TraceService } from '@onebun/trace';
|
|
22
22
|
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import { OneBunModule } from '
|
|
26
|
-
import {
|
|
23
|
+
import { getControllerMetadata } from '../decorators/decorators';
|
|
24
|
+
import { ConfigServiceImpl } from '../module/config.service';
|
|
25
|
+
import { OneBunModule } from '../module/module';
|
|
26
|
+
import { QueueService, type QueueAdapter } from '../queue';
|
|
27
|
+
import { InMemoryQueueAdapter } from '../queue/adapters/memory.adapter';
|
|
28
|
+
import { RedisQueueAdapter } from '../queue/adapters/redis.adapter';
|
|
29
|
+
import { hasQueueDecorators } from '../queue/decorators';
|
|
30
|
+
import { SharedRedisProvider } from '../redis/shared-redis';
|
|
27
31
|
import {
|
|
28
32
|
type ApplicationOptions,
|
|
29
33
|
type HttpMethod,
|
|
30
|
-
type
|
|
34
|
+
type ModuleInstance,
|
|
31
35
|
type ParamMetadata,
|
|
32
36
|
ParamType,
|
|
33
37
|
type RouteMetadata,
|
|
34
|
-
} from '
|
|
35
|
-
import { validateOrThrow } from '
|
|
36
|
-
import { WsHandler, isWebSocketGateway } from '
|
|
38
|
+
} from '../types';
|
|
39
|
+
import { validateOrThrow } from '../validation';
|
|
40
|
+
import { WsHandler, isWebSocketGateway } from '../websocket/ws-handler';
|
|
37
41
|
|
|
38
42
|
// Conditionally import metrics
|
|
39
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -63,7 +67,7 @@ function clearGlobalTraceContext(): void {
|
|
|
63
67
|
* OneBun Application
|
|
64
68
|
*/
|
|
65
69
|
export class OneBunApplication {
|
|
66
|
-
private rootModule:
|
|
70
|
+
private rootModule: ModuleInstance;
|
|
67
71
|
private server: ReturnType<typeof Bun.serve> | null = null;
|
|
68
72
|
private options: ApplicationOptions = {
|
|
69
73
|
port: 3000,
|
|
@@ -79,6 +83,8 @@ export class OneBunApplication {
|
|
|
79
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
84
|
private traceService: any = null;
|
|
81
85
|
private wsHandler: WsHandler | null = null;
|
|
86
|
+
private queueService: QueueService | null = null;
|
|
87
|
+
private queueAdapter: QueueAdapter | null = null;
|
|
82
88
|
|
|
83
89
|
/**
|
|
84
90
|
* Create application instance
|
|
@@ -272,12 +278,15 @@ export class OneBunApplication {
|
|
|
272
278
|
if (isWebSocketGateway(controllerClass)) {
|
|
273
279
|
const instance = this.rootModule.getControllerInstance?.(controllerClass);
|
|
274
280
|
if (instance) {
|
|
275
|
-
this.wsHandler.registerGateway(controllerClass, instance as import('
|
|
281
|
+
this.wsHandler.registerGateway(controllerClass, instance as import('../websocket/ws-base-gateway').BaseWebSocketGateway);
|
|
276
282
|
this.logger.info(`Registered WebSocket gateway: ${controllerClass.name}`);
|
|
277
283
|
}
|
|
278
284
|
}
|
|
279
285
|
}
|
|
280
286
|
|
|
287
|
+
// Initialize Queue system if configured or handlers exist
|
|
288
|
+
await this.initializeQueue(controllers);
|
|
289
|
+
|
|
281
290
|
// Create a map of routes with metadata
|
|
282
291
|
const routes = new Map<
|
|
283
292
|
string,
|
|
@@ -987,6 +996,20 @@ export class OneBunApplication {
|
|
|
987
996
|
this.wsHandler = null;
|
|
988
997
|
}
|
|
989
998
|
|
|
999
|
+
// Stop queue service
|
|
1000
|
+
if (this.queueService) {
|
|
1001
|
+
this.logger.debug('Stopping queue service');
|
|
1002
|
+
await this.queueService.stop();
|
|
1003
|
+
this.queueService = null;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// Disconnect queue adapter
|
|
1007
|
+
if (this.queueAdapter) {
|
|
1008
|
+
this.logger.debug('Disconnecting queue adapter');
|
|
1009
|
+
await this.queueAdapter.disconnect();
|
|
1010
|
+
this.queueAdapter = null;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
990
1013
|
// Stop HTTP server
|
|
991
1014
|
if (this.server) {
|
|
992
1015
|
this.server.stop();
|
|
@@ -1003,6 +1026,102 @@ export class OneBunApplication {
|
|
|
1003
1026
|
this.logger.info('OneBun application stopped');
|
|
1004
1027
|
}
|
|
1005
1028
|
|
|
1029
|
+
/**
|
|
1030
|
+
* Initialize the queue system based on configuration and detected handlers
|
|
1031
|
+
*/
|
|
1032
|
+
private async initializeQueue(controllers: Function[]): Promise<void> {
|
|
1033
|
+
const queueOptions = this.options.queue;
|
|
1034
|
+
|
|
1035
|
+
// Check if any controller has queue-related decorators
|
|
1036
|
+
const hasQueueHandlers = controllers.some(controller => {
|
|
1037
|
+
const instance = this.rootModule.getControllerInstance?.(controller);
|
|
1038
|
+
if (!instance) {
|
|
1039
|
+
return false;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
return hasQueueDecorators(instance.constructor);
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
// Determine if queue should be enabled
|
|
1046
|
+
const shouldEnableQueue = queueOptions?.enabled ?? hasQueueHandlers;
|
|
1047
|
+
if (!shouldEnableQueue) {
|
|
1048
|
+
this.logger.debug('Queue system not enabled (no handlers detected or explicitly disabled)');
|
|
1049
|
+
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// Create the appropriate adapter
|
|
1054
|
+
const adapterType = queueOptions?.adapter ?? 'memory';
|
|
1055
|
+
|
|
1056
|
+
if (adapterType === 'memory') {
|
|
1057
|
+
this.queueAdapter = new InMemoryQueueAdapter();
|
|
1058
|
+
this.logger.info('Queue system initialized with in-memory adapter');
|
|
1059
|
+
} else if (adapterType === 'redis') {
|
|
1060
|
+
const redisOptions = queueOptions?.redis ?? {};
|
|
1061
|
+
if (redisOptions.useSharedProvider !== false) {
|
|
1062
|
+
// Use shared Redis provider
|
|
1063
|
+
this.queueAdapter = new RedisQueueAdapter({
|
|
1064
|
+
useSharedClient: true,
|
|
1065
|
+
keyPrefix: redisOptions.prefix ?? 'onebun:queue:',
|
|
1066
|
+
});
|
|
1067
|
+
this.logger.info('Queue system initialized with Redis adapter (shared provider)');
|
|
1068
|
+
} else if (redisOptions.url) {
|
|
1069
|
+
// Create dedicated Redis connection
|
|
1070
|
+
this.queueAdapter = new RedisQueueAdapter({
|
|
1071
|
+
useSharedClient: false,
|
|
1072
|
+
url: redisOptions.url,
|
|
1073
|
+
keyPrefix: redisOptions.prefix ?? 'onebun:queue:',
|
|
1074
|
+
});
|
|
1075
|
+
this.logger.info('Queue system initialized with Redis adapter (dedicated connection)');
|
|
1076
|
+
} else {
|
|
1077
|
+
throw new Error('Redis queue adapter requires either useSharedProvider: true or a url');
|
|
1078
|
+
}
|
|
1079
|
+
} else {
|
|
1080
|
+
throw new Error(`Unknown queue adapter type: ${adapterType}`);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// Connect the adapter
|
|
1084
|
+
await this.queueAdapter.connect();
|
|
1085
|
+
|
|
1086
|
+
// Create queue service with config
|
|
1087
|
+
this.queueService = new QueueService({
|
|
1088
|
+
adapter: adapterType,
|
|
1089
|
+
options: queueOptions?.redis,
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
// Initialize with the adapter
|
|
1093
|
+
await this.queueService.initialize(this.queueAdapter);
|
|
1094
|
+
|
|
1095
|
+
// Register handlers from controllers using registerService
|
|
1096
|
+
for (const controllerClass of controllers) {
|
|
1097
|
+
const instance = this.rootModule.getControllerInstance?.(controllerClass);
|
|
1098
|
+
if (!instance) {
|
|
1099
|
+
continue;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// Only register if the controller has queue decorators
|
|
1103
|
+
if (hasQueueDecorators(controllerClass)) {
|
|
1104
|
+
await this.queueService.registerService(
|
|
1105
|
+
instance,
|
|
1106
|
+
controllerClass as new (...args: unknown[]) => unknown,
|
|
1107
|
+
);
|
|
1108
|
+
this.logger.debug(`Registered queue handlers for controller: ${controllerClass.name}`);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// Start the queue service
|
|
1113
|
+
await this.queueService.start();
|
|
1114
|
+
this.logger.info('Queue service started');
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* Get the queue service instance
|
|
1119
|
+
* @returns The queue service or null if not enabled
|
|
1120
|
+
*/
|
|
1121
|
+
getQueueService(): QueueService | null {
|
|
1122
|
+
return this.queueService;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1006
1125
|
/**
|
|
1007
1126
|
* Register signal handlers for graceful shutdown
|
|
1008
1127
|
* Call this after start() to enable automatic shutdown on SIGTERM/SIGINT
|
|
@@ -15,8 +15,9 @@ import {
|
|
|
15
15
|
type SyncLogger,
|
|
16
16
|
} from '@onebun/logger';
|
|
17
17
|
|
|
18
|
+
import { resolveEnvOverrides } from '../service-client/env-resolver';
|
|
19
|
+
|
|
18
20
|
import { OneBunApplication } from './application';
|
|
19
|
-
import { resolveEnvOverrides } from './env-resolver';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* ENV schema for service filtering
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
beforeEach,
|
|
13
13
|
} from 'bun:test';
|
|
14
14
|
|
|
15
|
+
import { HttpMethod, ParamType } from '../types';
|
|
16
|
+
|
|
15
17
|
import {
|
|
16
18
|
injectable,
|
|
17
19
|
Controller,
|
|
@@ -39,7 +41,6 @@ import {
|
|
|
39
41
|
getModuleMetadata,
|
|
40
42
|
ApiResponse,
|
|
41
43
|
} from './decorators';
|
|
42
|
-
import { HttpMethod, ParamType } from './types';
|
|
43
44
|
|
|
44
45
|
describe('decorators', () => {
|
|
45
46
|
beforeEach(() => {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import './metadata'; // Import polyfill first
|
|
2
2
|
import type { Type } from 'arktype';
|
|
3
3
|
|
|
4
|
-
import { getConstructorParamTypes as getDesignParamTypes, Reflect } from './metadata';
|
|
5
4
|
import {
|
|
6
5
|
type ControllerMetadata,
|
|
7
6
|
HttpMethod,
|
|
8
7
|
type ParamMetadata,
|
|
9
8
|
ParamType,
|
|
10
|
-
} from '
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
import { getConstructorParamTypes as getDesignParamTypes, Reflect } from './metadata';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Metadata storage for controllers
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorators Module
|
|
3
|
+
*
|
|
4
|
+
* HTTP decorators and metadata utilities.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Export metadata utilities (excluding getConstructorParamTypes which is re-exported from decorators)
|
|
8
|
+
export {
|
|
9
|
+
defineMetadata,
|
|
10
|
+
getMetadata,
|
|
11
|
+
Reflect,
|
|
12
|
+
} from './metadata';
|
|
13
|
+
|
|
14
|
+
// Export all decorators (including getConstructorParamTypes)
|
|
15
|
+
export * from './decorators';
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
// export
|
|
2
|
-
// export * from './types';
|
|
3
|
-
// export * from './config.service';
|
|
4
|
-
// Re-export envs from @onebun/envs
|
|
1
|
+
// Re-export from external packages
|
|
5
2
|
export { Env, type EnvSchema, EnvValidationError } from '@onebun/envs';
|
|
6
3
|
export type { SyncLogger } from '@onebun/logger';
|
|
7
4
|
export {
|
|
@@ -15,147 +12,63 @@ export {
|
|
|
15
12
|
type SuccessResponse,
|
|
16
13
|
} from '@onebun/requests';
|
|
17
14
|
export { Span } from '@onebun/trace';
|
|
15
|
+
|
|
18
16
|
// Re-export Effect and Layer from effect
|
|
19
17
|
export { Effect, Layer } from 'effect';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export * from './decorators';
|
|
23
|
-
export { defineMetadata, getMetadata } from './metadata';
|
|
24
|
-
export { OneBunModule } from './module';
|
|
25
|
-
export { BaseService, getServiceTag, Service } from './service';
|
|
26
|
-
export {
|
|
27
|
-
FakeTimers,
|
|
28
|
-
fakeTimers,
|
|
29
|
-
useFakeTimers,
|
|
30
|
-
makeMockLoggerLayer,
|
|
31
|
-
} from './test-utils';
|
|
18
|
+
|
|
19
|
+
// Types (excluding WebSocket types that are re-exported from ./websocket)
|
|
32
20
|
export {
|
|
33
21
|
HttpMethod,
|
|
34
|
-
|
|
35
|
-
type
|
|
22
|
+
ParamType,
|
|
23
|
+
type ServiceInterface,
|
|
24
|
+
type ModuleProviders,
|
|
25
|
+
type ModuleInstance,
|
|
26
|
+
type TypedEnvSchema,
|
|
27
|
+
type ApplicationOptions,
|
|
36
28
|
type ParamMetadata,
|
|
37
29
|
type ResponseSchemaMetadata,
|
|
38
|
-
|
|
30
|
+
type RouteMetadata,
|
|
31
|
+
type ControllerMetadata,
|
|
32
|
+
// WebSocket types are exported from ./websocket
|
|
33
|
+
type WsStorageType,
|
|
34
|
+
type WsStorageOptions,
|
|
35
|
+
type WebSocketApplicationOptions,
|
|
39
36
|
} from './types';
|
|
40
|
-
export * from './validation';
|
|
41
37
|
|
|
42
|
-
//
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
// Decorators and Metadata (exports Controller decorator, Module decorator, etc.)
|
|
39
|
+
export * from './decorators';
|
|
40
|
+
|
|
41
|
+
// Module System - explicitly re-export to avoid Controller conflict
|
|
42
|
+
export {
|
|
43
|
+
OneBunModule,
|
|
44
|
+
Controller as BaseController,
|
|
45
|
+
BaseService,
|
|
46
|
+
Service,
|
|
47
|
+
getServiceMetadata,
|
|
48
|
+
getServiceTag,
|
|
49
|
+
createServiceLayer,
|
|
50
|
+
ConfigServiceImpl,
|
|
51
|
+
ConfigServiceTag,
|
|
52
|
+
ConfigService,
|
|
53
|
+
} from './module';
|
|
52
54
|
|
|
53
|
-
//
|
|
54
|
-
export
|
|
55
|
-
export type {
|
|
56
|
-
ServiceDefinition,
|
|
57
|
-
EndpointMetadata,
|
|
58
|
-
ControllerDefinition,
|
|
59
|
-
} from './service-definition';
|
|
55
|
+
// Application
|
|
56
|
+
export * from './application';
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
export
|
|
58
|
+
// Service Client
|
|
59
|
+
export * from './service-client';
|
|
63
60
|
|
|
64
|
-
//
|
|
65
|
-
export
|
|
61
|
+
// Redis
|
|
62
|
+
export * from './redis';
|
|
66
63
|
|
|
67
|
-
// WebSocket
|
|
68
|
-
export
|
|
69
|
-
export {
|
|
70
|
-
WebSocketGateway,
|
|
71
|
-
OnConnect,
|
|
72
|
-
OnDisconnect,
|
|
73
|
-
OnJoinRoom,
|
|
74
|
-
OnLeaveRoom,
|
|
75
|
-
OnMessage,
|
|
76
|
-
Client,
|
|
77
|
-
Socket,
|
|
78
|
-
MessageData,
|
|
79
|
-
RoomName,
|
|
80
|
-
PatternParams,
|
|
81
|
-
WsServer,
|
|
82
|
-
UseWsGuards,
|
|
83
|
-
getGatewayMetadata,
|
|
84
|
-
isWebSocketGateway,
|
|
85
|
-
} from './ws-decorators';
|
|
86
|
-
export {
|
|
87
|
-
WsAuthGuard,
|
|
88
|
-
WsPermissionGuard,
|
|
89
|
-
WsRoomGuard,
|
|
90
|
-
WsAnyPermissionGuard,
|
|
91
|
-
WsServiceGuard,
|
|
92
|
-
WsAllGuards,
|
|
93
|
-
WsAnyGuard,
|
|
94
|
-
WsExecutionContextImpl,
|
|
95
|
-
executeGuards,
|
|
96
|
-
createGuard,
|
|
97
|
-
} from './ws-guards';
|
|
98
|
-
export type {
|
|
99
|
-
WsClientData,
|
|
100
|
-
WsAuthData,
|
|
101
|
-
WsRoom,
|
|
102
|
-
WsHandlerType,
|
|
103
|
-
WsParamType,
|
|
104
|
-
GatewayMetadata,
|
|
105
|
-
WsHandlerMetadata,
|
|
106
|
-
WsParamMetadata,
|
|
107
|
-
WebSocketGatewayOptions,
|
|
108
|
-
WsStorageOptions,
|
|
109
|
-
WebSocketApplicationOptions,
|
|
110
|
-
WsMessage,
|
|
111
|
-
WsHandlerResponse,
|
|
112
|
-
PatternMatch,
|
|
113
|
-
WsExecutionContext,
|
|
114
|
-
WsGuard,
|
|
115
|
-
WsServer as WsServerType,
|
|
116
|
-
} from './ws.types';
|
|
117
|
-
export {
|
|
118
|
-
WsHandlerType as WsHandlerTypeEnum,
|
|
119
|
-
WsParamType as WsParamTypeEnum,
|
|
120
|
-
isWsMessage,
|
|
121
|
-
isWsHandlerResponse,
|
|
122
|
-
isWsClientData,
|
|
123
|
-
isWsRoom,
|
|
124
|
-
} from './ws.types';
|
|
125
|
-
export {
|
|
126
|
-
matchPattern,
|
|
127
|
-
isPatternMatch,
|
|
128
|
-
createPatternMatcher,
|
|
129
|
-
isPattern,
|
|
130
|
-
getPatternParams,
|
|
131
|
-
buildFromPattern,
|
|
132
|
-
} from './ws-pattern-matcher';
|
|
133
|
-
export type { WsStorageAdapter, WsPubSubStorageAdapter, WsStorageEventPayload } from './ws-storage';
|
|
134
|
-
export { WsStorageEvent, isPubSubAdapter } from './ws-storage';
|
|
135
|
-
export { InMemoryWsStorage, createInMemoryWsStorage } from './ws-storage-memory';
|
|
136
|
-
export { RedisWsStorage, createRedisWsStorage } from './ws-storage-redis';
|
|
64
|
+
// WebSocket
|
|
65
|
+
export * from './websocket';
|
|
137
66
|
|
|
138
|
-
//
|
|
139
|
-
export
|
|
140
|
-
export type { RedisClientOptions } from './redis-client';
|
|
141
|
-
export {
|
|
142
|
-
SharedRedisProvider, SharedRedisService, makeSharedRedisLayer, getSharedRedis,
|
|
143
|
-
} from './shared-redis';
|
|
144
|
-
export type { SharedRedisOptions } from './shared-redis';
|
|
67
|
+
// Queue System
|
|
68
|
+
export * from './queue';
|
|
145
69
|
|
|
146
|
-
//
|
|
147
|
-
export
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
export
|
|
151
|
-
export { createWsClient } from './ws-client';
|
|
152
|
-
export type {
|
|
153
|
-
WsClientOptions,
|
|
154
|
-
WsClient,
|
|
155
|
-
WsGatewayClient,
|
|
156
|
-
WsEventListener,
|
|
157
|
-
WsClientEvent,
|
|
158
|
-
WsClientEventListeners,
|
|
159
|
-
TypedWsClient,
|
|
160
|
-
} from './ws-client.types';
|
|
161
|
-
export { WsConnectionState } from './ws-client.types';
|
|
70
|
+
// Validation
|
|
71
|
+
export * from './validation';
|
|
72
|
+
|
|
73
|
+
// Testing Utilities
|
|
74
|
+
export * from './testing';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module System
|
|
3
|
+
*
|
|
4
|
+
* Core module, controller, and service abstractions.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export * from './module';
|
|
8
|
+
export * from './controller';
|
|
9
|
+
// Re-export Controller as BaseController for backward compatibility
|
|
10
|
+
export { Controller as BaseController } from './controller';
|
|
11
|
+
export * from './service';
|
|
12
|
+
export * from './config.service';
|
|
@@ -11,9 +11,10 @@ import {
|
|
|
11
11
|
} from 'bun:test';
|
|
12
12
|
import { Context } from 'effect';
|
|
13
13
|
|
|
14
|
-
import { makeDevLogger } from '
|
|
14
|
+
import { makeDevLogger } from '@onebun/logger';
|
|
15
|
+
|
|
16
|
+
import { Module } from '../decorators/decorators';
|
|
15
17
|
|
|
16
|
-
import { Module } from './decorators';
|
|
17
18
|
import { OneBunModule } from './module';
|
|
18
19
|
import { Service } from './service';
|
|
19
20
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from 'effect';
|
|
6
6
|
|
|
7
7
|
import type { Controller } from './controller';
|
|
8
|
-
import type {
|
|
8
|
+
import type { ModuleInstance } from '../types';
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
createSyncLogger,
|
|
@@ -21,14 +21,15 @@ import {
|
|
|
21
21
|
getConstructorParamTypes,
|
|
22
22
|
getModuleMetadata,
|
|
23
23
|
registerControllerDependencies,
|
|
24
|
-
} from '
|
|
24
|
+
} from '../decorators/decorators';
|
|
25
|
+
import { isWebSocketGateway } from '../websocket/ws-decorators';
|
|
26
|
+
|
|
25
27
|
import { getServiceMetadata, getServiceTag } from './service';
|
|
26
|
-
import { isWebSocketGateway } from './ws-decorators';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* OneBun Module implementation
|
|
30
31
|
*/
|
|
31
|
-
export class OneBunModule implements
|
|
32
|
+
export class OneBunModule implements ModuleInstance {
|
|
32
33
|
private rootLayer: Layer.Layer<never, never, unknown>;
|
|
33
34
|
private controllers: Function[] = [];
|
|
34
35
|
private controllerInstances: Map<Function, Controller> = new Map();
|
|
@@ -438,7 +439,7 @@ export class OneBunModule implements Module {
|
|
|
438
439
|
moduleClass: Function,
|
|
439
440
|
loggerLayer?: Layer.Layer<never, never, unknown>,
|
|
440
441
|
config?: unknown,
|
|
441
|
-
):
|
|
442
|
+
): ModuleInstance {
|
|
442
443
|
// Using console.log here because we don't have access to the logger instance yet
|
|
443
444
|
// The instance will create its own logger in the constructor
|
|
444
445
|
return new OneBunModule(moduleClass, loggerLayer, config);
|