@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
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Queue System Types
|
|
3
|
+
*
|
|
4
|
+
* Common types and interfaces for all queue adapters (memory, redis, nats, jetstream).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Ack Modes
|
|
9
|
+
// ============================================================================
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Message acknowledgment mode
|
|
13
|
+
* - 'auto': Message is automatically acknowledged after successful handler execution
|
|
14
|
+
* - 'manual': Handler must call message.ack() or message.nack() explicitly
|
|
15
|
+
*/
|
|
16
|
+
export type AckMode = 'auto' | 'manual';
|
|
17
|
+
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Message Types
|
|
20
|
+
// ============================================================================
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Message metadata for inter-service communication, guards, and authorization
|
|
24
|
+
*/
|
|
25
|
+
export interface MessageMetadata {
|
|
26
|
+
/** Custom headers */
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
|
|
29
|
+
/** Authorization token (e.g., "Bearer xxx") */
|
|
30
|
+
authorization?: string;
|
|
31
|
+
|
|
32
|
+
/** ID of the calling service */
|
|
33
|
+
serviceId?: string;
|
|
34
|
+
|
|
35
|
+
/** Trace ID for distributed tracing (integration with @onebun/trace) */
|
|
36
|
+
traceId?: string;
|
|
37
|
+
|
|
38
|
+
/** Span ID for distributed tracing */
|
|
39
|
+
spanId?: string;
|
|
40
|
+
|
|
41
|
+
/** Parent span ID for distributed tracing */
|
|
42
|
+
parentSpanId?: string;
|
|
43
|
+
|
|
44
|
+
/** Additional data (for guards and custom logic) */
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Queue message interface
|
|
50
|
+
*/
|
|
51
|
+
export interface Message<T = unknown> {
|
|
52
|
+
/** Unique message ID */
|
|
53
|
+
id: string;
|
|
54
|
+
|
|
55
|
+
/** Message pattern/topic */
|
|
56
|
+
pattern: string;
|
|
57
|
+
|
|
58
|
+
/** Message payload */
|
|
59
|
+
data: T;
|
|
60
|
+
|
|
61
|
+
/** Message timestamp (ms since epoch) */
|
|
62
|
+
timestamp: number;
|
|
63
|
+
|
|
64
|
+
/** Whether this message was redelivered */
|
|
65
|
+
redelivered?: boolean;
|
|
66
|
+
|
|
67
|
+
/** Message metadata for inter-service communication */
|
|
68
|
+
metadata: MessageMetadata;
|
|
69
|
+
|
|
70
|
+
/** Current attempt number (for retries) */
|
|
71
|
+
attempt?: number;
|
|
72
|
+
|
|
73
|
+
/** Maximum attempts allowed */
|
|
74
|
+
maxAttempts?: number;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Acknowledge the message (for manual ack mode)
|
|
78
|
+
*/
|
|
79
|
+
ack(): Promise<void>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Negative acknowledge the message (for manual ack mode)
|
|
83
|
+
* @param requeue - Whether to requeue the message for reprocessing
|
|
84
|
+
*/
|
|
85
|
+
nack(requeue?: boolean): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// Publish Options
|
|
90
|
+
// ============================================================================
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Options for publishing messages
|
|
94
|
+
*/
|
|
95
|
+
export interface PublishOptions {
|
|
96
|
+
/** Delay before the message is delivered (ms) */
|
|
97
|
+
delay?: number;
|
|
98
|
+
|
|
99
|
+
/** Message priority (higher = more important) */
|
|
100
|
+
priority?: number;
|
|
101
|
+
|
|
102
|
+
/** Custom message ID */
|
|
103
|
+
messageId?: string;
|
|
104
|
+
|
|
105
|
+
/** Metadata for inter-service communication */
|
|
106
|
+
metadata?: Partial<MessageMetadata>;
|
|
107
|
+
|
|
108
|
+
/** Repeat options for scheduled jobs */
|
|
109
|
+
repeat?: {
|
|
110
|
+
/** Cron expression */
|
|
111
|
+
pattern?: string;
|
|
112
|
+
/** Interval in milliseconds */
|
|
113
|
+
every?: number;
|
|
114
|
+
/** Maximum number of repetitions */
|
|
115
|
+
limit?: number;
|
|
116
|
+
/** End date for repetitions */
|
|
117
|
+
endDate?: Date;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ============================================================================
|
|
122
|
+
// Subscribe Options
|
|
123
|
+
// ============================================================================
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Retry configuration
|
|
127
|
+
*/
|
|
128
|
+
export interface RetryOptions {
|
|
129
|
+
/** Maximum number of attempts */
|
|
130
|
+
attempts?: number;
|
|
131
|
+
/** Backoff strategy */
|
|
132
|
+
backoff?: 'fixed' | 'linear' | 'exponential';
|
|
133
|
+
/** Base delay in milliseconds */
|
|
134
|
+
delay?: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Dead Letter Queue configuration
|
|
139
|
+
*/
|
|
140
|
+
export interface DeadLetterOptions {
|
|
141
|
+
/** Queue name for dead letters */
|
|
142
|
+
queue: string;
|
|
143
|
+
/** Maximum retries before sending to DLQ */
|
|
144
|
+
maxRetries?: number;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Options for subscribing to messages
|
|
149
|
+
*/
|
|
150
|
+
export interface SubscribeOptions {
|
|
151
|
+
/** Acknowledgment mode ('auto' by default) */
|
|
152
|
+
ackMode?: AckMode;
|
|
153
|
+
|
|
154
|
+
/** Number of messages to process in parallel */
|
|
155
|
+
prefetch?: number;
|
|
156
|
+
|
|
157
|
+
/** Consumer group (for load balancing between instances) */
|
|
158
|
+
group?: string;
|
|
159
|
+
|
|
160
|
+
/** Retry settings (optional extension) */
|
|
161
|
+
retry?: RetryOptions;
|
|
162
|
+
|
|
163
|
+
/** Dead Letter Queue settings (optional extension) */
|
|
164
|
+
deadLetter?: DeadLetterOptions;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ============================================================================
|
|
168
|
+
// Lifecycle Events
|
|
169
|
+
// ============================================================================
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Queue lifecycle events
|
|
173
|
+
*/
|
|
174
|
+
export interface QueueEvents {
|
|
175
|
+
/** Called when the queue adapter is ready */
|
|
176
|
+
onReady?: () => void;
|
|
177
|
+
|
|
178
|
+
/** Called when an error occurs */
|
|
179
|
+
onError?: (error: Error) => void;
|
|
180
|
+
|
|
181
|
+
/** Called when a message is received */
|
|
182
|
+
onMessageReceived?: (message: Message) => void;
|
|
183
|
+
|
|
184
|
+
/** Called when a message is processed successfully */
|
|
185
|
+
onMessageProcessed?: (message: Message) => void;
|
|
186
|
+
|
|
187
|
+
/** Called when message processing fails */
|
|
188
|
+
onMessageFailed?: (message: Message, error: Error) => void;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ============================================================================
|
|
192
|
+
// Subscription
|
|
193
|
+
// ============================================================================
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Subscription handle returned by subscribe()
|
|
197
|
+
*/
|
|
198
|
+
export interface Subscription {
|
|
199
|
+
/** Unsubscribe from the pattern */
|
|
200
|
+
unsubscribe(): Promise<void>;
|
|
201
|
+
|
|
202
|
+
/** Pause receiving messages */
|
|
203
|
+
pause(): void;
|
|
204
|
+
|
|
205
|
+
/** Resume receiving messages */
|
|
206
|
+
resume(): void;
|
|
207
|
+
|
|
208
|
+
/** The pattern this subscription is for */
|
|
209
|
+
readonly pattern: string;
|
|
210
|
+
|
|
211
|
+
/** Whether the subscription is active */
|
|
212
|
+
readonly isActive: boolean;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ============================================================================
|
|
216
|
+
// Scheduled Jobs
|
|
217
|
+
// ============================================================================
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Overlap strategy for scheduled jobs
|
|
221
|
+
* - 'skip': Skip execution if previous job is still running
|
|
222
|
+
* - 'queue': Queue as a regular message even if previous is running
|
|
223
|
+
*/
|
|
224
|
+
export type OverlapStrategy = 'skip' | 'queue';
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Options for scheduled jobs
|
|
228
|
+
*/
|
|
229
|
+
export interface ScheduledJobOptions {
|
|
230
|
+
/** Pattern to publish to */
|
|
231
|
+
pattern: string;
|
|
232
|
+
|
|
233
|
+
/** Data to include in the message */
|
|
234
|
+
data?: unknown;
|
|
235
|
+
|
|
236
|
+
/** Schedule configuration */
|
|
237
|
+
schedule: {
|
|
238
|
+
/** Cron expression */
|
|
239
|
+
cron?: string;
|
|
240
|
+
/** Interval in milliseconds */
|
|
241
|
+
every?: number;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/** Metadata to include in messages */
|
|
245
|
+
metadata?: Partial<MessageMetadata>;
|
|
246
|
+
|
|
247
|
+
/** What to do if previous job is still running */
|
|
248
|
+
overlapStrategy?: OverlapStrategy;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Information about a scheduled job
|
|
253
|
+
*/
|
|
254
|
+
export interface ScheduledJobInfo {
|
|
255
|
+
/** Job name */
|
|
256
|
+
name: string;
|
|
257
|
+
|
|
258
|
+
/** Pattern to publish to */
|
|
259
|
+
pattern: string;
|
|
260
|
+
|
|
261
|
+
/** Schedule configuration */
|
|
262
|
+
schedule: {
|
|
263
|
+
cron?: string;
|
|
264
|
+
every?: number;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
/** Next scheduled run time */
|
|
268
|
+
nextRun?: Date;
|
|
269
|
+
|
|
270
|
+
/** Last run time */
|
|
271
|
+
lastRun?: Date;
|
|
272
|
+
|
|
273
|
+
/** Whether the job is currently running */
|
|
274
|
+
isRunning?: boolean;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ============================================================================
|
|
278
|
+
// Queue Features
|
|
279
|
+
// ============================================================================
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Features that queue adapters may support
|
|
283
|
+
*/
|
|
284
|
+
export type QueueFeature =
|
|
285
|
+
| 'delayed-messages'
|
|
286
|
+
| 'priority'
|
|
287
|
+
| 'dead-letter-queue'
|
|
288
|
+
| 'retry'
|
|
289
|
+
| 'scheduled-jobs'
|
|
290
|
+
| 'consumer-groups'
|
|
291
|
+
| 'pattern-subscriptions';
|
|
292
|
+
|
|
293
|
+
// ============================================================================
|
|
294
|
+
// Queue Adapter Interface
|
|
295
|
+
// ============================================================================
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Queue adapter type
|
|
299
|
+
*/
|
|
300
|
+
export type QueueAdapterType = 'memory' | 'redis' | 'nats' | 'jetstream';
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Message handler function
|
|
304
|
+
*/
|
|
305
|
+
export type MessageHandler<T = unknown> = (message: Message<T>) => Promise<void>;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Unified Queue Adapter interface
|
|
309
|
+
*
|
|
310
|
+
* All queue backends (memory, redis, nats, jetstream) implement this interface.
|
|
311
|
+
* Configuration differs, but the API remains the same.
|
|
312
|
+
*/
|
|
313
|
+
export interface QueueAdapter {
|
|
314
|
+
/** Adapter name */
|
|
315
|
+
readonly name: string;
|
|
316
|
+
|
|
317
|
+
/** Adapter type */
|
|
318
|
+
readonly type: QueueAdapterType;
|
|
319
|
+
|
|
320
|
+
// Lifecycle
|
|
321
|
+
/** Connect to the queue backend */
|
|
322
|
+
connect(): Promise<void>;
|
|
323
|
+
|
|
324
|
+
/** Disconnect from the queue backend */
|
|
325
|
+
disconnect(): Promise<void>;
|
|
326
|
+
|
|
327
|
+
/** Check if connected */
|
|
328
|
+
isConnected(): boolean;
|
|
329
|
+
|
|
330
|
+
// Publishing
|
|
331
|
+
/**
|
|
332
|
+
* Publish a message to a pattern
|
|
333
|
+
* @returns Message ID
|
|
334
|
+
*/
|
|
335
|
+
publish<T>(pattern: string, data: T, options?: PublishOptions): Promise<string>;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Publish multiple messages in a batch
|
|
339
|
+
* @returns Array of message IDs
|
|
340
|
+
*/
|
|
341
|
+
publishBatch<T>(
|
|
342
|
+
messages: Array<{ pattern: string; data: T; options?: PublishOptions }>
|
|
343
|
+
): Promise<string[]>;
|
|
344
|
+
|
|
345
|
+
// Subscribing
|
|
346
|
+
/**
|
|
347
|
+
* Subscribe to messages matching a pattern
|
|
348
|
+
* Supports wildcards: 'orders.*', 'events.user.#'
|
|
349
|
+
*/
|
|
350
|
+
subscribe<T>(
|
|
351
|
+
pattern: string,
|
|
352
|
+
handler: MessageHandler<T>,
|
|
353
|
+
options?: SubscribeOptions
|
|
354
|
+
): Promise<Subscription>;
|
|
355
|
+
|
|
356
|
+
// Scheduled Jobs
|
|
357
|
+
/** Add a scheduled job */
|
|
358
|
+
addScheduledJob(name: string, options: ScheduledJobOptions): Promise<void>;
|
|
359
|
+
|
|
360
|
+
/** Remove a scheduled job */
|
|
361
|
+
removeScheduledJob(name: string): Promise<boolean>;
|
|
362
|
+
|
|
363
|
+
/** Get all scheduled jobs */
|
|
364
|
+
getScheduledJobs(): Promise<ScheduledJobInfo[]>;
|
|
365
|
+
|
|
366
|
+
// Feature Support
|
|
367
|
+
/** Check if a feature is supported by this adapter */
|
|
368
|
+
supports(feature: QueueFeature): boolean;
|
|
369
|
+
|
|
370
|
+
// Events
|
|
371
|
+
/** Register an event handler */
|
|
372
|
+
on<E extends keyof QueueEvents>(event: E, handler: NonNullable<QueueEvents[E]>): void;
|
|
373
|
+
|
|
374
|
+
/** Unregister an event handler */
|
|
375
|
+
off<E extends keyof QueueEvents>(event: E, handler: NonNullable<QueueEvents[E]>): void;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ============================================================================
|
|
379
|
+
// Queue Configuration
|
|
380
|
+
// ============================================================================
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Built-in adapter types
|
|
384
|
+
*/
|
|
385
|
+
export type BuiltInAdapterType = 'memory' | 'redis';
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Queue adapter constructor
|
|
389
|
+
*/
|
|
390
|
+
export interface QueueAdapterConstructor {
|
|
391
|
+
new (options?: unknown): QueueAdapter;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Queue configuration options
|
|
396
|
+
*/
|
|
397
|
+
export interface QueueConfig {
|
|
398
|
+
/** Adapter type or custom adapter class */
|
|
399
|
+
adapter: BuiltInAdapterType | QueueAdapterConstructor;
|
|
400
|
+
|
|
401
|
+
/** Adapter-specific options */
|
|
402
|
+
options?: Record<string, unknown>;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ============================================================================
|
|
406
|
+
// Decorator Metadata Types
|
|
407
|
+
// ============================================================================
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Subscribe decorator options
|
|
411
|
+
*/
|
|
412
|
+
export interface SubscribeDecoratorOptions extends SubscribeOptions {
|
|
413
|
+
/** Pattern is required and comes from decorator argument */
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Cron decorator options
|
|
418
|
+
*/
|
|
419
|
+
export interface CronDecoratorOptions {
|
|
420
|
+
/** Pattern to publish to when cron triggers */
|
|
421
|
+
pattern: string;
|
|
422
|
+
|
|
423
|
+
/** Metadata to include in messages */
|
|
424
|
+
metadata?: Partial<MessageMetadata>;
|
|
425
|
+
|
|
426
|
+
/** Job name (defaults to method name) */
|
|
427
|
+
name?: string;
|
|
428
|
+
|
|
429
|
+
/** Overlap strategy */
|
|
430
|
+
overlapStrategy?: OverlapStrategy;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Interval decorator options
|
|
435
|
+
*/
|
|
436
|
+
export interface IntervalDecoratorOptions {
|
|
437
|
+
/** Pattern to publish to when interval triggers */
|
|
438
|
+
pattern: string;
|
|
439
|
+
|
|
440
|
+
/** Metadata to include in messages */
|
|
441
|
+
metadata?: Partial<MessageMetadata>;
|
|
442
|
+
|
|
443
|
+
/** Job name (defaults to method name) */
|
|
444
|
+
name?: string;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Timeout decorator options
|
|
449
|
+
*/
|
|
450
|
+
export interface TimeoutDecoratorOptions {
|
|
451
|
+
/** Pattern to publish to when timeout fires */
|
|
452
|
+
pattern: string;
|
|
453
|
+
|
|
454
|
+
/** Metadata to include in messages */
|
|
455
|
+
metadata?: Partial<MessageMetadata>;
|
|
456
|
+
|
|
457
|
+
/** Job name (defaults to method name) */
|
|
458
|
+
name?: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ============================================================================
|
|
462
|
+
// Guard Types
|
|
463
|
+
// ============================================================================
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Message execution context for guards
|
|
467
|
+
*/
|
|
468
|
+
export interface MessageExecutionContext {
|
|
469
|
+
/** Get the message */
|
|
470
|
+
getMessage<T>(): Message<T>;
|
|
471
|
+
|
|
472
|
+
/** Get message metadata */
|
|
473
|
+
getMetadata(): MessageMetadata;
|
|
474
|
+
|
|
475
|
+
/** Get the pattern */
|
|
476
|
+
getPattern(): string;
|
|
477
|
+
|
|
478
|
+
/** Get the handler function */
|
|
479
|
+
getHandler(): (...args: unknown[]) => unknown;
|
|
480
|
+
|
|
481
|
+
/** Get the class containing the handler */
|
|
482
|
+
getClass(): new (...args: unknown[]) => unknown;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** Handler function type alias */
|
|
486
|
+
export type HandlerFunction = (...args: unknown[]) => unknown;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Message guard interface
|
|
490
|
+
*/
|
|
491
|
+
export interface MessageGuard {
|
|
492
|
+
/**
|
|
493
|
+
* Determine if the message should be processed
|
|
494
|
+
* @returns true to allow processing, false to reject
|
|
495
|
+
*/
|
|
496
|
+
canActivate(context: MessageExecutionContext): boolean | Promise<boolean>;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Guard constructor type
|
|
501
|
+
*/
|
|
502
|
+
export type MessageGuardConstructor = new (...args: unknown[]) => MessageGuard;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Client Module
|
|
3
|
+
*
|
|
4
|
+
* Type-safe service definitions and clients for inter-service communication.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export * from './service-client.types';
|
|
8
|
+
export * from './service-definition';
|
|
9
|
+
export * from './service-client';
|
|
10
|
+
export * from './env-resolver';
|
|
@@ -15,10 +15,11 @@ import {
|
|
|
15
15
|
Post,
|
|
16
16
|
Body,
|
|
17
17
|
Query,
|
|
18
|
-
} from '
|
|
18
|
+
} from '../decorators/decorators';
|
|
19
|
+
import { HttpMethod } from '../types';
|
|
20
|
+
|
|
19
21
|
import { createServiceClient, getServiceUrl } from './service-client';
|
|
20
22
|
import { createServiceDefinition } from './service-definition';
|
|
21
|
-
import { HttpMethod } from './types';
|
|
22
23
|
|
|
23
24
|
// Test controller with various parameter types
|
|
24
25
|
@Controller('/users')
|
|
@@ -11,9 +11,10 @@ import {
|
|
|
11
11
|
Param,
|
|
12
12
|
Post,
|
|
13
13
|
Body,
|
|
14
|
-
} from '
|
|
14
|
+
} from '../decorators/decorators';
|
|
15
|
+
import { HttpMethod } from '../types';
|
|
16
|
+
|
|
15
17
|
import { createServiceDefinition } from './service-definition';
|
|
16
|
-
import { HttpMethod } from './types';
|
|
17
18
|
|
|
18
19
|
// Test controller
|
|
19
20
|
@Controller('/users')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getControllerMetadata, getModuleMetadata } from '
|
|
2
|
-
import { type HttpMethod, type ParamMetadata } from '
|
|
1
|
+
import { getControllerMetadata, getModuleMetadata } from '../decorators/decorators';
|
|
2
|
+
import { type HttpMethod, type ParamMetadata } from '../types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Metadata for a single endpoint
|
package/src/types.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Logger } from '@onebun/logger';
|
|
|
6
6
|
/**
|
|
7
7
|
* Base interface for all OneBun services
|
|
8
8
|
*/
|
|
9
|
-
export interface
|
|
9
|
+
export interface ServiceInterface {
|
|
10
10
|
readonly [key: string]: unknown;
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -17,7 +17,7 @@ export interface ModuleProviders {
|
|
|
17
17
|
/**
|
|
18
18
|
* Services to provide
|
|
19
19
|
*/
|
|
20
|
-
providers?:
|
|
20
|
+
providers?: ServiceInterface[];
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Controllers to include
|
|
@@ -27,7 +27,7 @@ export interface ModuleProviders {
|
|
|
27
27
|
/**
|
|
28
28
|
* Modules to import
|
|
29
29
|
*/
|
|
30
|
-
imports?:
|
|
30
|
+
imports?: ModuleInstance[];
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Services to export to parent modules
|
|
@@ -36,9 +36,9 @@ export interface ModuleProviders {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Module interface
|
|
39
|
+
* Module instance interface
|
|
40
40
|
*/
|
|
41
|
-
export interface
|
|
41
|
+
export interface ModuleInstance {
|
|
42
42
|
/**
|
|
43
43
|
* Setup the module
|
|
44
44
|
*/
|
|
@@ -272,6 +272,11 @@ export interface ApplicationOptions {
|
|
|
272
272
|
*/
|
|
273
273
|
websocket?: WebSocketApplicationOptions;
|
|
274
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Queue configuration
|
|
277
|
+
*/
|
|
278
|
+
queue?: QueueApplicationOptions;
|
|
279
|
+
|
|
275
280
|
/**
|
|
276
281
|
* Enable graceful shutdown on SIGTERM/SIGINT
|
|
277
282
|
* When enabled, the application will cleanly shutdown on process signals,
|
|
@@ -282,6 +287,30 @@ export interface ApplicationOptions {
|
|
|
282
287
|
gracefulShutdown?: boolean;
|
|
283
288
|
}
|
|
284
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Queue adapter type for application configuration
|
|
292
|
+
*/
|
|
293
|
+
export type QueueAdapterType = 'memory' | 'redis';
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Queue configuration for OneBunApplication
|
|
297
|
+
*/
|
|
298
|
+
export interface QueueApplicationOptions {
|
|
299
|
+
/** Enable/disable queue (default: auto - enabled if handlers exist) */
|
|
300
|
+
enabled?: boolean;
|
|
301
|
+
/** Adapter type or custom adapter instance */
|
|
302
|
+
adapter?: QueueAdapterType;
|
|
303
|
+
/** Redis-specific options (only used when adapter is 'redis') */
|
|
304
|
+
redis?: {
|
|
305
|
+
/** Use shared Redis provider instead of dedicated connection */
|
|
306
|
+
useSharedProvider?: boolean;
|
|
307
|
+
/** Redis connection URL (required if not using shared provider) */
|
|
308
|
+
url?: string;
|
|
309
|
+
/** Key prefix for Redis keys */
|
|
310
|
+
prefix?: string;
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
285
314
|
/**
|
|
286
315
|
* WebSocket storage type
|
|
287
316
|
*/
|