@gravito/stream 1.0.0-alpha.6 → 1.0.0-beta.2

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 (150) hide show
  1. package/README.md +94 -5
  2. package/dist/index.cjs +2265 -31639
  3. package/dist/index.d.cts +1814 -0
  4. package/dist/index.d.ts +1805 -36
  5. package/dist/index.js +2700 -0
  6. package/package.json +11 -7
  7. package/dist/Consumer.d.ts +0 -67
  8. package/dist/Consumer.d.ts.map +0 -1
  9. package/dist/Job.d.ts +0 -76
  10. package/dist/Job.d.ts.map +0 -1
  11. package/dist/OrbitQueue.d.ts +0 -74
  12. package/dist/OrbitQueue.d.ts.map +0 -1
  13. package/dist/QueueManager.d.ts +0 -86
  14. package/dist/QueueManager.d.ts.map +0 -1
  15. package/dist/Queueable.d.ts +0 -63
  16. package/dist/Queueable.d.ts.map +0 -1
  17. package/dist/Worker.d.ts +0 -48
  18. package/dist/Worker.d.ts.map +0 -1
  19. package/dist/core/src/ConfigManager.d.ts +0 -26
  20. package/dist/core/src/ConfigManager.d.ts.map +0 -1
  21. package/dist/core/src/Container.d.ts +0 -39
  22. package/dist/core/src/Container.d.ts.map +0 -1
  23. package/dist/core/src/Event.d.ts +0 -6
  24. package/dist/core/src/Event.d.ts.map +0 -1
  25. package/dist/core/src/EventManager.d.ts +0 -124
  26. package/dist/core/src/EventManager.d.ts.map +0 -1
  27. package/dist/core/src/GlobalErrorHandlers.d.ts +0 -32
  28. package/dist/core/src/GlobalErrorHandlers.d.ts.map +0 -1
  29. package/dist/core/src/HookManager.d.ts +0 -29
  30. package/dist/core/src/HookManager.d.ts.map +0 -1
  31. package/dist/core/src/Listener.d.ts +0 -5
  32. package/dist/core/src/Listener.d.ts.map +0 -1
  33. package/dist/core/src/Logger.d.ts +0 -21
  34. package/dist/core/src/Logger.d.ts.map +0 -1
  35. package/dist/core/src/PlanetCore.d.ts +0 -116
  36. package/dist/core/src/PlanetCore.d.ts.map +0 -1
  37. package/dist/core/src/Route.d.ts +0 -13
  38. package/dist/core/src/Route.d.ts.map +0 -1
  39. package/dist/core/src/Router.d.ts +0 -168
  40. package/dist/core/src/Router.d.ts.map +0 -1
  41. package/dist/core/src/ServiceProvider.d.ts +0 -17
  42. package/dist/core/src/ServiceProvider.d.ts.map +0 -1
  43. package/dist/core/src/exceptions/AuthenticationException.d.ts +0 -5
  44. package/dist/core/src/exceptions/AuthenticationException.d.ts.map +0 -1
  45. package/dist/core/src/exceptions/AuthorizationException.d.ts +0 -5
  46. package/dist/core/src/exceptions/AuthorizationException.d.ts.map +0 -1
  47. package/dist/core/src/exceptions/GravitoException.d.ts +0 -15
  48. package/dist/core/src/exceptions/GravitoException.d.ts.map +0 -1
  49. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +0 -7
  50. package/dist/core/src/exceptions/ModelNotFoundException.d.ts.map +0 -1
  51. package/dist/core/src/exceptions/ValidationException.d.ts +0 -15
  52. package/dist/core/src/exceptions/ValidationException.d.ts.map +0 -1
  53. package/dist/core/src/exceptions/index.d.ts +0 -6
  54. package/dist/core/src/exceptions/index.d.ts.map +0 -1
  55. package/dist/core/src/helpers/Arr.d.ts +0 -15
  56. package/dist/core/src/helpers/Arr.d.ts.map +0 -1
  57. package/dist/core/src/helpers/Str.d.ts +0 -19
  58. package/dist/core/src/helpers/Str.d.ts.map +0 -1
  59. package/dist/core/src/helpers/data.d.ts +0 -6
  60. package/dist/core/src/helpers/data.d.ts.map +0 -1
  61. package/dist/core/src/helpers/errors.d.ts +0 -13
  62. package/dist/core/src/helpers/errors.d.ts.map +0 -1
  63. package/dist/core/src/helpers/response.d.ts +0 -19
  64. package/dist/core/src/helpers/response.d.ts.map +0 -1
  65. package/dist/core/src/helpers.d.ts +0 -39
  66. package/dist/core/src/helpers.d.ts.map +0 -1
  67. package/dist/core/src/http/CookieJar.d.ts +0 -34
  68. package/dist/core/src/http/CookieJar.d.ts.map +0 -1
  69. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -13
  70. package/dist/core/src/http/middleware/ThrottleRequests.d.ts.map +0 -1
  71. package/dist/core/src/index.d.ts +0 -32
  72. package/dist/core/src/index.d.ts.map +0 -1
  73. package/dist/core/src/security/Encrypter.d.ts +0 -25
  74. package/dist/core/src/security/Encrypter.d.ts.map +0 -1
  75. package/dist/core/src/security/Hasher.d.ts +0 -30
  76. package/dist/core/src/security/Hasher.d.ts.map +0 -1
  77. package/dist/core/src/types/events.d.ts +0 -95
  78. package/dist/core/src/types/events.d.ts.map +0 -1
  79. package/dist/drivers/DatabaseDriver.d.ts +0 -60
  80. package/dist/drivers/DatabaseDriver.d.ts.map +0 -1
  81. package/dist/drivers/KafkaDriver.d.ts +0 -134
  82. package/dist/drivers/KafkaDriver.d.ts.map +0 -1
  83. package/dist/drivers/MemoryDriver.d.ts +0 -45
  84. package/dist/drivers/MemoryDriver.d.ts.map +0 -1
  85. package/dist/drivers/QueueDriver.d.ts +0 -89
  86. package/dist/drivers/QueueDriver.d.ts.map +0 -1
  87. package/dist/drivers/RedisDriver.d.ts +0 -79
  88. package/dist/drivers/RedisDriver.d.ts.map +0 -1
  89. package/dist/drivers/SQSDriver.d.ts +0 -100
  90. package/dist/drivers/SQSDriver.d.ts.map +0 -1
  91. package/dist/index.cjs.map +0 -422
  92. package/dist/index.d.ts.map +0 -1
  93. package/dist/index.mjs +0 -32096
  94. package/dist/index.mjs.map +0 -422
  95. package/dist/orbit-db/src/DBService.d.ts +0 -270
  96. package/dist/orbit-db/src/DBService.d.ts.map +0 -1
  97. package/dist/orbit-db/src/EventBus.d.ts +0 -53
  98. package/dist/orbit-db/src/EventBus.d.ts.map +0 -1
  99. package/dist/orbit-db/src/MigrationDriver.d.ts +0 -55
  100. package/dist/orbit-db/src/MigrationDriver.d.ts.map +0 -1
  101. package/dist/orbit-db/src/Model.d.ts +0 -564
  102. package/dist/orbit-db/src/Model.d.ts.map +0 -1
  103. package/dist/orbit-db/src/ModelCollection.d.ts +0 -35
  104. package/dist/orbit-db/src/ModelCollection.d.ts.map +0 -1
  105. package/dist/orbit-db/src/index.d.ts +0 -34
  106. package/dist/orbit-db/src/index.d.ts.map +0 -1
  107. package/dist/orbit-db/src/types.d.ts +0 -146
  108. package/dist/orbit-db/src/types.d.ts.map +0 -1
  109. package/dist/orbit-queue/src/Consumer.d.ts +0 -67
  110. package/dist/orbit-queue/src/Consumer.d.ts.map +0 -1
  111. package/dist/orbit-queue/src/Job.d.ts +0 -76
  112. package/dist/orbit-queue/src/Job.d.ts.map +0 -1
  113. package/dist/orbit-queue/src/OrbitQueue.d.ts +0 -74
  114. package/dist/orbit-queue/src/OrbitQueue.d.ts.map +0 -1
  115. package/dist/orbit-queue/src/QueueManager.d.ts +0 -86
  116. package/dist/orbit-queue/src/QueueManager.d.ts.map +0 -1
  117. package/dist/orbit-queue/src/Queueable.d.ts +0 -63
  118. package/dist/orbit-queue/src/Queueable.d.ts.map +0 -1
  119. package/dist/orbit-queue/src/Worker.d.ts +0 -48
  120. package/dist/orbit-queue/src/Worker.d.ts.map +0 -1
  121. package/dist/orbit-queue/src/drivers/DatabaseDriver.d.ts +0 -60
  122. package/dist/orbit-queue/src/drivers/DatabaseDriver.d.ts.map +0 -1
  123. package/dist/orbit-queue/src/drivers/KafkaDriver.d.ts +0 -134
  124. package/dist/orbit-queue/src/drivers/KafkaDriver.d.ts.map +0 -1
  125. package/dist/orbit-queue/src/drivers/MemoryDriver.d.ts +0 -45
  126. package/dist/orbit-queue/src/drivers/MemoryDriver.d.ts.map +0 -1
  127. package/dist/orbit-queue/src/drivers/QueueDriver.d.ts +0 -89
  128. package/dist/orbit-queue/src/drivers/QueueDriver.d.ts.map +0 -1
  129. package/dist/orbit-queue/src/drivers/RedisDriver.d.ts +0 -79
  130. package/dist/orbit-queue/src/drivers/RedisDriver.d.ts.map +0 -1
  131. package/dist/orbit-queue/src/drivers/SQSDriver.d.ts +0 -100
  132. package/dist/orbit-queue/src/drivers/SQSDriver.d.ts.map +0 -1
  133. package/dist/orbit-queue/src/index.d.ts +0 -45
  134. package/dist/orbit-queue/src/index.d.ts.map +0 -1
  135. package/dist/orbit-queue/src/serializers/ClassNameSerializer.d.ts +0 -46
  136. package/dist/orbit-queue/src/serializers/ClassNameSerializer.d.ts.map +0 -1
  137. package/dist/orbit-queue/src/serializers/JobSerializer.d.ts +0 -36
  138. package/dist/orbit-queue/src/serializers/JobSerializer.d.ts.map +0 -1
  139. package/dist/orbit-queue/src/serializers/JsonSerializer.d.ts +0 -32
  140. package/dist/orbit-queue/src/serializers/JsonSerializer.d.ts.map +0 -1
  141. package/dist/orbit-queue/src/types.d.ts +0 -85
  142. package/dist/orbit-queue/src/types.d.ts.map +0 -1
  143. package/dist/serializers/ClassNameSerializer.d.ts +0 -46
  144. package/dist/serializers/ClassNameSerializer.d.ts.map +0 -1
  145. package/dist/serializers/JobSerializer.d.ts +0 -36
  146. package/dist/serializers/JobSerializer.d.ts.map +0 -1
  147. package/dist/serializers/JsonSerializer.d.ts +0 -32
  148. package/dist/serializers/JsonSerializer.d.ts.map +0 -1
  149. package/dist/types.d.ts +0 -85
  150. package/dist/types.d.ts.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,45 +1,1814 @@
1
+ import { GravitoOrbit, PlanetCore } from '@gravito/core';
2
+
1
3
  /**
2
- * @gravito/orbit-queue
4
+ * Serialized job payload.
5
+ */
6
+ interface SerializedJob {
7
+ /**
8
+ * Unique job identifier.
9
+ */
10
+ id: string;
11
+ /**
12
+ * Serializer type: `'json'` or `'class'`.
13
+ */
14
+ type: 'json' | 'class';
15
+ /**
16
+ * Serialized data.
17
+ */
18
+ data: string;
19
+ /**
20
+ * Class name (only for `type === 'class'`).
21
+ */
22
+ className?: string;
23
+ /**
24
+ * Created timestamp.
25
+ */
26
+ createdAt: number;
27
+ /**
28
+ * Delay before execution (seconds).
29
+ */
30
+ delaySeconds?: number;
31
+ /**
32
+ * Current attempt number.
33
+ */
34
+ attempts?: number;
35
+ /**
36
+ * Maximum attempts.
37
+ */
38
+ maxAttempts?: number;
39
+ /**
40
+ * Group ID for FIFO ordering.
41
+ */
42
+ groupId?: string;
43
+ /**
44
+ * Initial retry delay (seconds).
45
+ */
46
+ retryAfterSeconds?: number;
47
+ /**
48
+ * Retry delay multiplier.
49
+ */
50
+ retryMultiplier?: number;
51
+ /**
52
+ * Last error message.
53
+ */
54
+ error?: string;
55
+ /**
56
+ * Timestamp when the job failed permanently.
57
+ */
58
+ failedAt?: number;
59
+ /**
60
+ * Job priority.
61
+ */
62
+ priority?: string | number;
63
+ }
64
+ /**
65
+ * Topic options (for Kafka, etc.).
66
+ */
67
+ interface TopicOptions {
68
+ /**
69
+ * Number of partitions.
70
+ */
71
+ partitions?: number;
72
+ /**
73
+ * Replication factor.
74
+ */
75
+ replicationFactor?: number;
76
+ /**
77
+ * Additional config.
78
+ */
79
+ config?: Record<string, string>;
80
+ }
81
+ /**
82
+ * Queue connection config.
83
+ */
84
+ interface QueueConnectionConfig {
85
+ /**
86
+ * Driver type.
87
+ */
88
+ driver: 'memory' | 'database' | 'redis' | 'kafka' | 'sqs' | 'rabbitmq' | 'nats';
89
+ /**
90
+ * Driver-specific config.
91
+ */
92
+ [key: string]: unknown;
93
+ }
94
+ /**
95
+ * Queue manager config.
96
+ */
97
+ interface QueueConfig {
98
+ /**
99
+ * Default connection name.
100
+ */
101
+ default?: string;
102
+ /**
103
+ * Connection configs.
104
+ */
105
+ connections?: Record<string, QueueConnectionConfig>;
106
+ /**
107
+ * Default serializer type.
108
+ */
109
+ defaultSerializer?: 'json' | 'class';
110
+ /**
111
+ * Persistence configuration (SQL Archive).
112
+ */
113
+ persistence?: {
114
+ /**
115
+ * Persistence adapter instance or config.
116
+ */
117
+ adapter: PersistenceAdapter;
118
+ /**
119
+ * Whether to automatically archive completed jobs.
120
+ */
121
+ archiveCompleted?: boolean;
122
+ /**
123
+ * Whether to automatically archive failed jobs.
124
+ */
125
+ archiveFailed?: boolean;
126
+ /**
127
+ * Whether to archive jobs immediately upon enqueue (Audit Mode).
128
+ * @default false
129
+ */
130
+ archiveEnqueued?: boolean;
131
+ };
132
+ }
133
+ /**
134
+ * Persistence Adapter Interface
135
+ * Used for long-term archiving of jobs in a SQL database.
136
+ */
137
+ interface PersistenceAdapter {
138
+ /**
139
+ * Archive a job.
140
+ */
141
+ archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
142
+ /**
143
+ * Find a job in the archive.
144
+ */
145
+ find(queue: string, id: string): Promise<SerializedJob | null>;
146
+ /**
147
+ * List jobs from the archive.
148
+ */
149
+ /**
150
+ * List jobs from the archive.
151
+ */
152
+ list(queue: string, options?: {
153
+ limit?: number;
154
+ offset?: number;
155
+ status?: 'completed' | 'failed' | 'waiting' | string;
156
+ jobId?: string;
157
+ startTime?: Date;
158
+ endTime?: Date;
159
+ }): Promise<SerializedJob[]>;
160
+ /**
161
+ * Remove old data from the archive.
162
+ */
163
+ cleanup(days: number): Promise<number>;
164
+ /**
165
+ * Count jobs in the archive.
166
+ */
167
+ count(queue: string, options?: {
168
+ status?: 'completed' | 'failed' | 'waiting' | string;
169
+ jobId?: string;
170
+ startTime?: Date;
171
+ endTime?: Date;
172
+ }): Promise<number>;
173
+ /**
174
+ * Archive a system log message.
175
+ */
176
+ archiveLog(log: {
177
+ level: string;
178
+ message: string;
179
+ workerId: string;
180
+ queue?: string;
181
+ timestamp: Date;
182
+ }): Promise<void>;
183
+ /**
184
+ * List system logs from the archive.
185
+ */
186
+ listLogs(options?: {
187
+ limit?: number;
188
+ offset?: number;
189
+ level?: string;
190
+ workerId?: string;
191
+ queue?: string;
192
+ search?: string;
193
+ startTime?: Date;
194
+ endTime?: Date;
195
+ }): Promise<any[]>;
196
+ /**
197
+ * Count system logs in the archive.
198
+ */
199
+ countLogs(options?: {
200
+ level?: string;
201
+ workerId?: string;
202
+ queue?: string;
203
+ search?: string;
204
+ startTime?: Date;
205
+ endTime?: Date;
206
+ }): Promise<number>;
207
+ }
208
+ /**
209
+ * Options when pushing a job.
210
+ */
211
+ interface JobPushOptions {
212
+ /**
213
+ * Group ID for FIFO ordering (e.g. userId).
214
+ * If set, jobs with the same groupId will be processed strictly sequentially.
215
+ */
216
+ groupId?: string;
217
+ /**
218
+ * Job priority.
219
+ * Higher priority jobs are processed first (if supported by driver).
220
+ * Example: 'high', 'low', 'critical'
221
+ */
222
+ priority?: string | number;
223
+ }
224
+
225
+ /**
226
+ * Queue driver interface.
227
+ *
228
+ * All queue drivers must implement this interface.
229
+ * Defines basic queue operations plus optional enterprise-grade capabilities.
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * class MyDriver implements QueueDriver {
234
+ * async push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void> {
235
+ * // push a job
236
+ * }
237
+ *
238
+ * async pop(queue: string): Promise<SerializedJob | null> {
239
+ * // pop a job
240
+ * }
241
+ *
242
+ * async complete(queue: string, job: SerializedJob): Promise<void> {
243
+ * // job completed (for FIFO handling)
244
+ * }
245
+ *
246
+ * async size(queue: string): Promise<number> {
247
+ * // queue size
248
+ * }
249
+ *
250
+ * async clear(queue: string): Promise<void> {
251
+ * // clear queue
252
+ * }
253
+ * }
254
+ * ```
255
+ */
256
+ interface QueueDriver {
257
+ /**
258
+ * Push a job to a queue.
259
+ * @param queue - Queue name
260
+ * @param job - Serialized job
261
+ * @param options - Push options (e.g. groupId)
262
+ */
263
+ push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void>;
264
+ /**
265
+ * Pop a job from a queue (non-blocking).
266
+ * @param queue - Queue name
267
+ * @returns Serialized job, or `null` if the queue is empty
268
+ */
269
+ pop(queue: string): Promise<SerializedJob | null>;
270
+ /**
271
+ * Mark a job as completed (used for FIFO/Group handling).
272
+ * @param queue - Queue name
273
+ * @param job - Serialized job
274
+ */
275
+ complete?(queue: string, job: SerializedJob): Promise<void>;
276
+ /**
277
+ * Get queue size.
278
+ * @param queue - Queue name
279
+ * @returns Number of jobs in the queue
280
+ */
281
+ size(queue: string): Promise<number>;
282
+ /**
283
+ * Clear a queue.
284
+ * @param queue - Queue name
285
+ */
286
+ clear(queue: string): Promise<void>;
287
+ /**
288
+ * Mark a job as permanently failed (move to DLQ).
289
+ * @param queue - Queue name
290
+ * @param job - Serialized job with error info
291
+ */
292
+ fail?(queue: string, job: SerializedJob): Promise<void>;
293
+ /**
294
+ * Push multiple jobs (optional, higher throughput).
295
+ * @param queue - Queue name
296
+ * @param jobs - Serialized job array
297
+ */
298
+ pushMany?(queue: string, jobs: SerializedJob[]): Promise<void>;
299
+ /**
300
+ * Pop multiple jobs (optional, higher throughput).
301
+ * @param queue - Queue name
302
+ * @param count - Max number of jobs to pop
303
+ * @returns Serialized job array
304
+ */
305
+ popMany?(queue: string, count: number): Promise<SerializedJob[]>;
306
+ /**
307
+ * Acknowledge a message (enterprise capability, e.g. Kafka/SQS).
308
+ * @param messageId - Message ID
309
+ */
310
+ acknowledge?(messageId: string): Promise<void>;
311
+ /**
312
+ * Subscribe to a queue (push-based model, e.g. Kafka/SQS).
313
+ * @param queue - Queue name
314
+ * @param callback - Callback to process jobs
315
+ */
316
+ subscribe?(queue: string, callback: (job: SerializedJob) => Promise<void>): Promise<void>;
317
+ /**
318
+ * Create a topic (Kafka, etc.).
319
+ * @param topic - Topic name
320
+ * @param options - Topic options
321
+ */
322
+ createTopic?(topic: string, options?: TopicOptions): Promise<void>;
323
+ /**
324
+ * Delete a topic (Kafka, etc.).
325
+ * @param topic - Topic name
326
+ */
327
+ deleteTopic?(topic: string): Promise<void>;
328
+ /**
329
+ * Report worker heartbeat for monitoring.
330
+ * @param workerInfo - Worker information
331
+ * @param prefix - Optional prefix for monitoring keys
332
+ */
333
+ reportHeartbeat?(workerInfo: any, prefix?: string): Promise<void>;
334
+ /**
335
+ * Publish a log message for monitoring.
336
+ * @param logPayload - Log payload
337
+ * @param prefix - Optional prefix for monitoring channels/keys
338
+ */
339
+ publishLog?(logPayload: any, prefix?: string): Promise<void>;
340
+ /**
341
+ * Check if a queue is rate limited.
342
+ * @param queue - Queue name
343
+ * @param config - Rate limit configuration
344
+ * @returns true if allowed, false if limited
345
+ */
346
+ checkRateLimit?(queue: string, config: {
347
+ max: number;
348
+ duration: number;
349
+ }): Promise<boolean>;
350
+ /**
351
+ * Retry failed jobs from DLQ.
352
+ * @param queue - Queue name
353
+ * @param count - Optional count (default: all)
354
+ * @returns Number of jobs retried
355
+ */
356
+ retryFailed?(queue: string, count?: number): Promise<number>;
357
+ /**
358
+ * Get failed jobs from DLQ.
359
+ * @param queue - Queue name
360
+ * @param start - Start index
361
+ * @param end - End index
362
+ * @returns Array of failed jobs
363
+ */
364
+ getFailed?(queue: string, start?: number, end?: number): Promise<SerializedJob[]>;
365
+ /**
366
+ * Clear failed jobs from DLQ.
367
+ * @param queue - Queue name
368
+ */
369
+ clearFailed?(queue: string): Promise<void>;
370
+ }
371
+
372
+ /**
373
+ * Queueable interface.
374
+ *
375
+ * Classes implementing this interface can be pushed to a queue for execution.
376
+ * Provides a fluent API for queue/connection/delay configuration.
377
+ *
378
+ * @example
379
+ * ```typescript
380
+ * class MyJob implements Queueable {
381
+ * queueName?: string
382
+ * connectionName?: string
383
+ * delaySeconds?: number
384
+ *
385
+ * onQueue(queue: string): this {
386
+ * this.queueName = queue
387
+ * return this
388
+ * }
389
+ *
390
+ * onConnection(connection: string): this {
391
+ * this.connectionName = connection
392
+ * return this
393
+ * }
394
+ *
395
+ * delay(seconds: number): this {
396
+ * this.delaySeconds = seconds
397
+ * return this
398
+ * }
399
+ * }
400
+ * ```
401
+ */
402
+ interface Queueable {
403
+ /**
404
+ * Queue name where the job should be pushed.
405
+ */
406
+ queueName?: string;
407
+ /**
408
+ * Connection name the job should use.
409
+ */
410
+ connectionName?: string;
411
+ /**
412
+ * Delay before execution (seconds).
413
+ */
414
+ delaySeconds?: number;
415
+ /**
416
+ * Job priority.
417
+ */
418
+ priority?: string | number;
419
+ /**
420
+ * Set target queue.
421
+ * @param queue - Queue name
422
+ * @returns Self for fluent chaining
423
+ */
424
+ onQueue(queue: string): this;
425
+ /**
426
+ * Set target connection.
427
+ * @param connection - Connection name
428
+ * @returns Self for fluent chaining
429
+ */
430
+ onConnection(connection: string): this;
431
+ /**
432
+ * Set job priority.
433
+ * @param priority - Priority level
434
+ * @returns Self for fluent chaining
435
+ */
436
+ withPriority(priority: string | number): this;
437
+ /**
438
+ * Set delay (seconds).
439
+ * @param delay - Delay seconds
440
+ * @returns Self for fluent chaining
441
+ */
442
+ delay(delay: number): this;
443
+ }
444
+
445
+ /**
446
+ * Base Job.
447
+ *
448
+ * All tasks that should be pushed to a queue should extend this class.
449
+ * Implements the `Queueable` interface, providing a fluent API for queue/connection/delay.
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ * class SendWelcomeEmail extends Job {
454
+ * constructor(private userId: string) {
455
+ * super()
456
+ * }
3
457
  *
4
- * Lightweight, high-performance queue system inspired by Laravel while keeping Gravito's core values.
5
- * Supports multiple storage drivers, embedded/standalone consumer modes, and multiple job serialization strategies.
458
+ * async handle(): Promise<void> {
459
+ * const user = await User.find(this.userId)
460
+ * await mail.send(new WelcomeEmail(user))
461
+ * }
462
+ * }
463
+ *
464
+ * // Usage
465
+ * await queue.push(new SendWelcomeEmail('123'))
466
+ * .onQueue('emails')
467
+ * .delay(60)
468
+ * ```
469
+ */
470
+ declare abstract class Job implements Queueable {
471
+ /**
472
+ * Unique job identifier.
473
+ */
474
+ id?: string;
475
+ /**
476
+ * Queue name.
477
+ */
478
+ queueName?: string;
479
+ /**
480
+ * Connection name.
481
+ */
482
+ connectionName?: string;
483
+ /**
484
+ * Delay before execution (seconds).
485
+ */
486
+ delaySeconds?: number;
487
+ /**
488
+ * Current attempt number.
489
+ */
490
+ attempts?: number;
491
+ /**
492
+ * Maximum attempts.
493
+ */
494
+ maxAttempts?: number;
495
+ /**
496
+ * Group ID for FIFO.
497
+ */
498
+ groupId?: string;
499
+ /**
500
+ * Job priority.
501
+ */
502
+ priority?: string | number;
503
+ /**
504
+ * Initial retry delay (seconds).
505
+ */
506
+ retryAfterSeconds?: number;
507
+ /**
508
+ * Retry delay multiplier.
509
+ */
510
+ retryMultiplier?: number;
511
+ /**
512
+ * Set target queue.
513
+ */
514
+ onQueue(queue: string): this;
515
+ /**
516
+ * Set target connection.
517
+ */
518
+ onConnection(connection: string): this;
519
+ /**
520
+ * Set job priority.
521
+ * @param priority - 'high', 'low', or number
522
+ */
523
+ withPriority(priority: string | number): this;
524
+ /**
525
+ * Set delay (seconds).
526
+ */
527
+ delay(delay: number): this;
528
+ /**
529
+ * Set retry backoff strategy.
530
+ * @param seconds - Initial delay in seconds
531
+ * @param multiplier - Multiplier for each subsequent attempt (default: 2)
532
+ */
533
+ backoff(seconds: number, multiplier?: number): this;
534
+ /**
535
+ * Calculate retry delay for the next attempt.
536
+ * @param attempt - Current attempt number (1-based)
537
+ * @returns Delay in milliseconds
538
+ */
539
+ getRetryDelay(attempt: number): number;
540
+ /**
541
+ * Job handler logic.
542
+ *
543
+ * Subclasses must implement this method.
544
+ */
545
+ abstract handle(): Promise<void>;
546
+ /**
547
+ * Failure handler (optional).
548
+ *
549
+ * Called when the job fails and reaches the maximum number of attempts.
550
+ * Subclasses can override to implement custom failure handling.
551
+ *
552
+ * @param error - Error instance
553
+ */
554
+ failed(_error: Error): Promise<void>;
555
+ }
556
+
557
+ /**
558
+ * Job serializer interface.
559
+ *
560
+ * Responsible for serializing and deserializing jobs.
561
+ * Supports multiple strategies (JSON, class-name, etc.).
6
562
  *
7
563
  * @example
8
564
  * ```typescript
9
- * import { OrbitQueue, Job } from '@gravito/orbit-queue'
565
+ * class MySerializer implements JobSerializer {
566
+ * serialize(job: Job): SerializedJob {
567
+ * // serialization logic
568
+ * }
10
569
  *
11
- * // Create a Job
12
- * class SendEmail extends Job {
13
- * async handle() {
14
- * // handle logic
570
+ * deserialize(serialized: SerializedJob): Job {
571
+ * // deserialization logic
15
572
  * }
16
573
  * }
574
+ * ```
575
+ */
576
+ interface JobSerializer {
577
+ /**
578
+ * Serialize a job.
579
+ * @param job - Job instance
580
+ * @returns Serialized job payload
581
+ */
582
+ serialize(job: Job): SerializedJob;
583
+ /**
584
+ * Deserialize a job.
585
+ * @param serialized - Serialized job payload
586
+ * @returns Job instance
587
+ */
588
+ deserialize(serialized: SerializedJob): Job;
589
+ }
590
+
591
+ /**
592
+ * Queue Manager
593
+ *
594
+ * Manages multiple queue connections and drivers, exposing a unified API for pushing and consuming jobs.
595
+ * Supports lazy-loading drivers to keep the core lightweight.
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * const manager = new QueueManager({
600
+ * default: 'database',
601
+ * connections: {
602
+ * database: { driver: 'database', table: 'jobs' },
603
+ * redis: { driver: 'redis', url: 'redis://...' }
604
+ * }
605
+ * })
606
+ *
607
+ * await manager.push(new SendEmail('user@example.com'))
608
+ * ```
609
+ */
610
+ declare class QueueManager {
611
+ private drivers;
612
+ private serializers;
613
+ private defaultConnection;
614
+ private defaultSerializer;
615
+ private persistence?;
616
+ private scheduler?;
617
+ constructor(config?: QueueConfig);
618
+ /**
619
+ * Register a connection.
620
+ * @param name - Connection name
621
+ * @param config - Connection config
622
+ */
623
+ registerConnection(name: string, config: unknown): void;
624
+ /**
625
+ * Get a driver for a connection.
626
+ * @param connection - Connection name
627
+ * @returns Driver instance
628
+ */
629
+ getDriver(connection: string): QueueDriver;
630
+ /**
631
+ * Get the default connection name.
632
+ * @returns Default connection name
633
+ */
634
+ getDefaultConnection(): string;
635
+ /**
636
+ * Get a serializer.
637
+ * @param type - Serializer type
638
+ * @returns Serializer instance
639
+ */
640
+ getSerializer(type?: string): JobSerializer;
641
+ /**
642
+ * Register Job classes (used by ClassNameSerializer).
643
+ * @param jobClasses - Job class array
644
+ */
645
+ registerJobClasses(jobClasses: Array<new (...args: unknown[]) => Job>): void;
646
+ /**
647
+ * Push a Job to the queue.
648
+ *
649
+ * @template T - The type of the job.
650
+ * @param job - Job instance to push.
651
+ * @param options - Push options.
652
+ * @returns The same job instance (for fluent chaining).
653
+ *
654
+ * @example
655
+ * ```typescript
656
+ * await manager.push(new SendEmailJob('user@example.com'));
657
+ * ```
658
+ */
659
+ push<T extends Job & Queueable>(job: T, options?: JobPushOptions): Promise<T>;
660
+ /**
661
+ * Push multiple jobs to the queue.
662
+ *
663
+ * @template T - The type of the jobs.
664
+ * @param jobs - Array of job instances.
665
+ *
666
+ * @example
667
+ * ```typescript
668
+ * await manager.pushMany([new JobA(), new JobB()]);
669
+ * ```
670
+ */
671
+ pushMany<T extends Job & Queueable>(jobs: T[]): Promise<void>;
672
+ /**
673
+ * Pop a job from the queue.
674
+ *
675
+ * @param queue - Queue name (default: 'default').
676
+ * @param connection - Connection name (optional).
677
+ * @returns Job instance or null if queue is empty.
678
+ *
679
+ * @example
680
+ * ```typescript
681
+ * const job = await manager.pop('emails');
682
+ * if (job) await job.handle();
683
+ * ```
684
+ */
685
+ pop(queue?: string, connection?: string): Promise<Job | null>;
686
+ /**
687
+ * Get queue size.
688
+ *
689
+ * @param queue - Queue name (default: 'default').
690
+ * @param connection - Connection name (optional).
691
+ * @returns Number of jobs in the queue.
692
+ */
693
+ size(queue?: string, connection?: string): Promise<number>;
694
+ /**
695
+ * Clear all jobs from a queue.
696
+ *
697
+ * @param queue - Queue name (default: 'default').
698
+ * @param connection - Connection name (optional).
699
+ */
700
+ clear(queue?: string, connection?: string): Promise<void>;
701
+ /**
702
+ * Mark a job as completed.
703
+ * @param job - Job instance
704
+ */
705
+ complete<T extends Job & Queueable>(job: T): Promise<void>;
706
+ /**
707
+ * Mark a job as permanently failed.
708
+ * @param job - Job instance
709
+ * @param error - Error object
710
+ */
711
+ fail<T extends Job & Queueable>(job: T, error: Error): Promise<void>;
712
+ /**
713
+ * Get the persistence adapter if configured.
714
+ */
715
+ getPersistence(): any;
716
+ /**
717
+ * Get the scheduler if configured.
718
+ */
719
+ getScheduler(): any;
720
+ /**
721
+ * Get failed jobs from DLQ (if driver supports it).
722
+ */
723
+ getFailed(queue: string, start?: number, end?: number, connection?: string): Promise<SerializedJob[]>;
724
+ /**
725
+ * Retry failed jobs from DLQ (if driver supports it).
726
+ */
727
+ retryFailed(queue: string, count?: number, connection?: string): Promise<number>;
728
+ /**
729
+ * Clear failed jobs from DLQ (if driver supports it).
730
+ */
731
+ clearFailed(queue: string, connection?: string): Promise<void>;
732
+ }
733
+
734
+ /**
735
+ * Worker options.
736
+ */
737
+ interface WorkerOptions {
738
+ /**
739
+ * Maximum retry attempts.
740
+ */
741
+ maxAttempts?: number;
742
+ /**
743
+ * Job timeout (seconds).
744
+ */
745
+ timeout?: number;
746
+ /**
747
+ * Failure callback.
748
+ */
749
+ onFailed?: (job: Job, error: Error) => Promise<void>;
750
+ }
751
+ /**
752
+ * Base Worker.
753
+ *
754
+ * Responsible for executing `Job` instances.
755
+ * Provides error handling, retry logic, and timeout support.
756
+ *
757
+ * @example
758
+ * ```typescript
759
+ * const worker = new Worker({
760
+ * maxAttempts: 3,
761
+ * timeout: 60
762
+ * })
763
+ *
764
+ * await worker.process(job)
765
+ * ```
766
+ */
767
+ declare class Worker {
768
+ private options;
769
+ constructor(options?: WorkerOptions);
770
+ /**
771
+ * Process a Job.
772
+ * @param job - Job instance
773
+ */
774
+ process(job: Job): Promise<void>;
775
+ /**
776
+ * Handle failure.
777
+ */
778
+ private handleFailure;
779
+ }
780
+
781
+ /**
782
+ * Consumer options.
783
+ */
784
+ interface ConsumerOptions {
785
+ /**
786
+ * Queues to listen on.
787
+ */
788
+ queues: string[];
789
+ /**
790
+ * Connection name.
791
+ */
792
+ connection?: string;
793
+ /**
794
+ * Worker options.
795
+ */
796
+ workerOptions?: WorkerOptions;
797
+ /**
798
+ * Polling interval (milliseconds).
799
+ */
800
+ pollInterval?: number;
801
+ /**
802
+ * Whether to keep polling when queues are empty.
803
+ */
804
+ keepAlive?: boolean;
805
+ /**
806
+ * Monitoring options.
807
+ */
808
+ monitor?: boolean | {
809
+ /**
810
+ * Heartbeat interval (milliseconds). Default: 5000.
811
+ */
812
+ interval?: number;
813
+ /**
814
+ * Extra info to report with heartbeat.
815
+ */
816
+ extraInfo?: Record<string, any>;
817
+ /**
818
+ * Prefix for monitoring keys/channels.
819
+ */
820
+ prefix?: string;
821
+ };
822
+ /**
823
+ * Rate limits per queue.
824
+ * Example: { 'emails': { max: 10, duration: 1000 } }
825
+ */
826
+ rateLimits?: Record<string, {
827
+ max: number;
828
+ duration: number;
829
+ }>;
830
+ }
831
+ /**
832
+ * Consumer
833
+ *
834
+ * Consumes and executes jobs from queues.
835
+ * Supports embedded mode (inside the main app) and standalone mode (as a worker service).
836
+ *
837
+ * @example
838
+ * ```typescript
839
+ * // Embedded mode
840
+ * const consumer = new Consumer(queueManager, {
841
+ * queues: ['default', 'emails'],
842
+ * pollInterval: 1000
843
+ * })
17
844
  *
18
- * // Push a Job
19
- * await queue.push(new SendEmail())
20
- * ```
21
- */
22
- export type { ConsumerOptions } from './Consumer';
23
- export { Consumer } from './Consumer';
24
- export type { DatabaseDriverConfig } from './drivers/DatabaseDriver';
25
- export { DatabaseDriver } from './drivers/DatabaseDriver';
26
- export type { KafkaDriverConfig } from './drivers/KafkaDriver';
27
- export { KafkaDriver } from './drivers/KafkaDriver';
28
- export { MemoryDriver } from './drivers/MemoryDriver';
29
- export type { QueueDriver } from './drivers/QueueDriver';
30
- export type { RedisDriverConfig } from './drivers/RedisDriver';
31
- export { RedisDriver } from './drivers/RedisDriver';
32
- export type { SQSDriverConfig } from './drivers/SQSDriver';
33
- export { SQSDriver } from './drivers/SQSDriver';
34
- export { Job } from './Job';
35
- export type { OrbitQueueOptions } from './OrbitQueue';
36
- export { OrbitQueue } from './OrbitQueue';
37
- export type { Queueable } from './Queueable';
38
- export { QueueManager } from './QueueManager';
39
- export { ClassNameSerializer } from './serializers/ClassNameSerializer';
40
- export type { JobSerializer } from './serializers/JobSerializer';
41
- export { JsonSerializer } from './serializers/JsonSerializer';
42
- export type { QueueConfig, QueueConnectionConfig, SerializedJob, TopicOptions, } from './types';
43
- export type { WorkerOptions } from './Worker';
44
- export { Worker } from './Worker';
45
- //# sourceMappingURL=index.d.ts.map
845
+ * consumer.start()
846
+ *
847
+ * // Standalone mode (CLI)
848
+ * // Start via CLI tooling with graceful shutdown
849
+ * ```
850
+ */
851
+ declare class Consumer {
852
+ private queueManager;
853
+ private options;
854
+ private running;
855
+ private stopRequested;
856
+ private workerId;
857
+ private heartbeatTimer;
858
+ constructor(queueManager: QueueManager, options: ConsumerOptions);
859
+ private get connectionName();
860
+ /**
861
+ * Start the consumer loop.
862
+ */
863
+ start(): Promise<void>;
864
+ private startHeartbeat;
865
+ private stopHeartbeat;
866
+ private publishLog;
867
+ /**
868
+ * Stop the consumer loop (graceful shutdown).
869
+ */
870
+ stop(): Promise<void>;
871
+ /**
872
+ * Check whether the consumer is running.
873
+ */
874
+ isRunning(): boolean;
875
+ }
876
+
877
+ /**
878
+ * Generic database service interface.
879
+ * Users should implement this interface with their preferred ORM/database client.
880
+ */
881
+ interface DatabaseService {
882
+ /**
883
+ * Execute a raw SQL query.
884
+ * @param sql - The SQL query string with placeholders ($1, $2, etc.)
885
+ * @param bindings - The values to bind to placeholders
886
+ */
887
+ execute<T = unknown>(sql: string, bindings?: unknown[]): Promise<T[] | T>;
888
+ /**
889
+ * Execute multiple queries within a transaction.
890
+ * @param callback - The callback to execute within the transaction
891
+ */
892
+ transaction<T>(callback: (tx: DatabaseService) => Promise<T>): Promise<T>;
893
+ }
894
+ /**
895
+ * Database driver configuration.
896
+ */
897
+ interface DatabaseDriverConfig {
898
+ /**
899
+ * Table name (default: `jobs`).
900
+ */
901
+ table?: string;
902
+ /**
903
+ * Database service instance that implements DatabaseService interface.
904
+ */
905
+ dbService?: DatabaseService;
906
+ }
907
+ /**
908
+ * Database Driver
909
+ *
910
+ * Uses a database as the queue backend.
911
+ * Works with any database service that implements the DatabaseService interface.
912
+ *
913
+ * @example
914
+ * ```typescript
915
+ * // Create a database service adapter
916
+ * const dbService = {
917
+ * execute: async (sql, bindings) => yourDbClient.query(sql, bindings),
918
+ * transaction: async (callback) => yourDbClient.transaction(callback),
919
+ * }
920
+ *
921
+ * const driver = new DatabaseDriver({ dbService, table: 'jobs' })
922
+ * await driver.push('default', serializedJob)
923
+ * ```
924
+ */
925
+ declare class DatabaseDriver implements QueueDriver {
926
+ private tableName;
927
+ private dbService;
928
+ constructor(config: DatabaseDriverConfig);
929
+ /**
930
+ * Push a job to a queue.
931
+ */
932
+ push(queue: string, job: SerializedJob): Promise<void>;
933
+ /**
934
+ * Pop a job from the queue (FIFO, with delay support).
935
+ */
936
+ pop(queue: string): Promise<SerializedJob | null>;
937
+ /**
938
+ * Get queue size.
939
+ */
940
+ size(queue: string): Promise<number>;
941
+ /**
942
+ * Clear a queue.
943
+ */
944
+ clear(queue: string): Promise<void>;
945
+ /**
946
+ * Push multiple jobs.
947
+ */
948
+ pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
949
+ /**
950
+ * Mark a job as failed (DLQ).
951
+ */
952
+ fail(queue: string, job: SerializedJob): Promise<void>;
953
+ /**
954
+ * Acknowledge/Complete a job.
955
+ */
956
+ complete(_queue: string, job: SerializedJob): Promise<void>;
957
+ }
958
+
959
+ /**
960
+ * Kafka driver configuration.
961
+ */
962
+ interface KafkaDriverConfig {
963
+ /**
964
+ * Kafka client instance (kafkajs).
965
+ */
966
+ client: {
967
+ producer: () => {
968
+ connect: () => Promise<void>;
969
+ send: (args: {
970
+ topic: string;
971
+ messages: Array<{
972
+ key?: string;
973
+ value: string;
974
+ }>;
975
+ }) => Promise<void>;
976
+ disconnect: () => Promise<void>;
977
+ };
978
+ admin: () => {
979
+ connect: () => Promise<void>;
980
+ createTopics: (args: {
981
+ topics: Array<{
982
+ topic: string;
983
+ numPartitions?: number;
984
+ replicationFactor?: number;
985
+ }>;
986
+ }) => Promise<void>;
987
+ deleteTopics: (args: {
988
+ topics: string[];
989
+ }) => Promise<void>;
990
+ disconnect: () => Promise<void>;
991
+ };
992
+ consumer: (args: {
993
+ groupId: string;
994
+ }) => {
995
+ connect: () => Promise<void>;
996
+ subscribe: (args: {
997
+ topics: string[];
998
+ }) => Promise<void>;
999
+ run: (args: {
1000
+ eachMessage: (args: {
1001
+ topic: string;
1002
+ partition: number;
1003
+ message: {
1004
+ key?: Buffer;
1005
+ value: Buffer;
1006
+ offset: string;
1007
+ };
1008
+ }) => Promise<void>;
1009
+ }) => Promise<void>;
1010
+ disconnect: () => Promise<void>;
1011
+ };
1012
+ };
1013
+ /**
1014
+ * Consumer group ID (for consuming messages).
1015
+ */
1016
+ consumerGroupId?: string;
1017
+ }
1018
+ /**
1019
+ * Kafka Driver
1020
+ *
1021
+ * Uses Apache Kafka as the queue backend.
1022
+ * Supports topic management, consumer groups, and batch operations.
1023
+ *
1024
+ * Requires `kafkajs`.
1025
+ *
1026
+ * @example
1027
+ * ```typescript
1028
+ * import { Kafka } from 'kafkajs'
1029
+ *
1030
+ * const kafka = new Kafka({
1031
+ * brokers: ['localhost:9092'],
1032
+ * clientId: 'gravito-app'
1033
+ * })
1034
+ *
1035
+ * const driver = new KafkaDriver({ client: kafka, consumerGroupId: 'workers' })
1036
+ * await driver.push('default', serializedJob)
1037
+ * ```
1038
+ */
1039
+ declare class KafkaDriver implements QueueDriver {
1040
+ private client;
1041
+ private consumerGroupId;
1042
+ private producer?;
1043
+ private admin?;
1044
+ constructor(config: KafkaDriverConfig);
1045
+ /**
1046
+ * Ensure the producer is connected.
1047
+ */
1048
+ private ensureProducer;
1049
+ /**
1050
+ * Ensure the admin client is connected.
1051
+ */
1052
+ private ensureAdmin;
1053
+ /**
1054
+ * Push a job to a topic.
1055
+ */
1056
+ push(queue: string, job: SerializedJob): Promise<void>;
1057
+ /**
1058
+ * Pop is not supported for Kafka.
1059
+ *
1060
+ * Note: Kafka uses a push-based model, so you should use `subscribe()`.
1061
+ */
1062
+ pop(_queue: string): Promise<SerializedJob | null>;
1063
+ /**
1064
+ * Kafka does not provide a direct queue size.
1065
+ *
1066
+ * Returns 0; use Kafka tooling/metrics for lag/size insights.
1067
+ */
1068
+ size(_queue: string): Promise<number>;
1069
+ /**
1070
+ * Clear a queue by deleting the topic.
1071
+ */
1072
+ clear(queue: string): Promise<void>;
1073
+ /**
1074
+ * Push multiple jobs.
1075
+ */
1076
+ pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
1077
+ /**
1078
+ * Create a topic.
1079
+ */
1080
+ createTopic(topic: string, options?: TopicOptions): Promise<void>;
1081
+ /**
1082
+ * Delete a topic.
1083
+ */
1084
+ deleteTopic(topic: string): Promise<void>;
1085
+ /**
1086
+ * Subscribe to a topic (push-based model).
1087
+ */
1088
+ subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>): Promise<void>;
1089
+ }
1090
+
1091
+ /**
1092
+ * Memory Driver
1093
+ *
1094
+ * In-memory driver for development and testing.
1095
+ * All data is stored in memory and will be lost when the process restarts.
1096
+ *
1097
+ * Zero-config: works out of the box.
1098
+ *
1099
+ * @example
1100
+ * ```typescript
1101
+ * const driver = new MemoryDriver()
1102
+ * await driver.push('default', serializedJob)
1103
+ * const job = await driver.pop('default')
1104
+ * ```
1105
+ */
1106
+ declare class MemoryDriver implements QueueDriver {
1107
+ private queues;
1108
+ /**
1109
+ * Push a job to a queue.
1110
+ */
1111
+ push(queue: string, job: SerializedJob): Promise<void>;
1112
+ /**
1113
+ * Pop a job from a queue (FIFO).
1114
+ */
1115
+ pop(queue: string): Promise<SerializedJob | null>;
1116
+ /**
1117
+ * Get queue size.
1118
+ */
1119
+ size(queue: string): Promise<number>;
1120
+ /**
1121
+ * Clear a queue.
1122
+ */
1123
+ clear(queue: string): Promise<void>;
1124
+ /**
1125
+ * Push multiple jobs.
1126
+ */
1127
+ pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
1128
+ /**
1129
+ * Pop multiple jobs.
1130
+ */
1131
+ popMany(queue: string, count: number): Promise<SerializedJob[]>;
1132
+ }
1133
+
1134
+ /**
1135
+ * RabbitMQ driver configuration.
1136
+ */
1137
+ interface RabbitMQDriverConfig {
1138
+ /**
1139
+ * RabbitMQ client (amqplib) Connection or Channel.
1140
+ * If a Connection is provided, the driver will create and manage a Channel.
1141
+ */
1142
+ client: any;
1143
+ /**
1144
+ * Exchange name (optional).
1145
+ */
1146
+ exchange?: string;
1147
+ /**
1148
+ * Exchange type (default: 'fanout').
1149
+ */
1150
+ exchangeType?: 'direct' | 'topic' | 'headers' | 'fanout' | 'match';
1151
+ }
1152
+ /**
1153
+ * RabbitMQ Driver
1154
+ *
1155
+ * Uses RabbitMQ as the queue backend.
1156
+ * Implements FIFO via RabbitMQ Queues.
1157
+ *
1158
+ * Requires `amqplib`.
1159
+ *
1160
+ * @example
1161
+ * ```typescript
1162
+ * import amqp from 'amqplib'
1163
+ *
1164
+ * const connection = await amqp.connect('amqp://localhost')
1165
+ * const driver = new RabbitMQDriver({ client: connection })
1166
+ *
1167
+ * await driver.push('default', serializedJob)
1168
+ * ```
1169
+ */
1170
+ declare class RabbitMQDriver implements QueueDriver {
1171
+ private connection;
1172
+ private channel;
1173
+ private exchange?;
1174
+ private exchangeType;
1175
+ constructor(config: RabbitMQDriverConfig);
1176
+ /**
1177
+ * Ensure channel is created.
1178
+ */
1179
+ ensureChannel(): Promise<any>;
1180
+ /**
1181
+ * Get the underlying connection.
1182
+ */
1183
+ getRawConnection(): any;
1184
+ /**
1185
+ * Push a job (sendToQueue / publish).
1186
+ */
1187
+ push(queue: string, job: SerializedJob): Promise<void>;
1188
+ /**
1189
+ * Pop a job (get).
1190
+ */
1191
+ pop(queue: string): Promise<SerializedJob | null>;
1192
+ /**
1193
+ * Acknowledge a message.
1194
+ */
1195
+ acknowledge(messageId: string): Promise<void>;
1196
+ /**
1197
+ * Negative acknowledge a message.
1198
+ */
1199
+ nack(message: any, requeue?: boolean): Promise<void>;
1200
+ /**
1201
+ * Reject a message.
1202
+ */
1203
+ reject(message: any, requeue?: boolean): Promise<void>;
1204
+ /**
1205
+ * Subscribe to a queue.
1206
+ */
1207
+ subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>, options?: {
1208
+ autoAck?: boolean;
1209
+ }): Promise<void>;
1210
+ /**
1211
+ * Get queue size.
1212
+ */
1213
+ size(queue: string): Promise<number>;
1214
+ /**
1215
+ * Clear a queue.
1216
+ */
1217
+ clear(queue: string): Promise<void>;
1218
+ }
1219
+
1220
+ /**
1221
+ * Redis driver configuration.
1222
+ */
1223
+ interface RedisDriverConfig {
1224
+ /**
1225
+ * Redis client instance (ioredis or node-redis).
1226
+ */
1227
+ client: {
1228
+ lpush: (key: string, ...values: string[]) => Promise<number>;
1229
+ rpop: (key: string) => Promise<string | null>;
1230
+ llen: (key: string) => Promise<number>;
1231
+ del: (key: string) => Promise<number>;
1232
+ lpushx?: (key: string, ...values: string[]) => Promise<number>;
1233
+ rpoplpush?: (src: string, dst: string) => Promise<string | null>;
1234
+ [key: string]: unknown;
1235
+ };
1236
+ /**
1237
+ * Key prefix (default: `queue:`).
1238
+ */
1239
+ prefix?: string;
1240
+ }
1241
+ /**
1242
+ * Redis Driver
1243
+ *
1244
+ * Uses Redis as the queue backend.
1245
+ * Implements FIFO via Redis Lists (LPUSH/RPOP).
1246
+ *
1247
+ * Requires `ioredis` or `redis`.
1248
+ *
1249
+ * @example
1250
+ * ```typescript
1251
+ * import Redis from 'ioredis'
1252
+ *
1253
+ * const redis = new Redis('redis://localhost:6379')
1254
+ * const redis = new Redis('ioredis://localhost:6379')
1255
+ * const driver = new RedisDriver({ client: redis })
1256
+ *
1257
+ * await driver.push('default', serializedJob)
1258
+ * ```
1259
+ */
1260
+ declare class RedisDriver implements QueueDriver {
1261
+ private prefix;
1262
+ private client;
1263
+ private static PUSH_SCRIPT;
1264
+ private static COMPLETE_SCRIPT;
1265
+ constructor(config: RedisDriverConfig);
1266
+ /**
1267
+ * Get full Redis key for a queue.
1268
+ */
1269
+ private getKey;
1270
+ /**
1271
+ * Push a job (LPUSH).
1272
+ */
1273
+ push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void>;
1274
+ /**
1275
+ * Complete a job (handle Group FIFO).
1276
+ */
1277
+ complete(queue: string, job: SerializedJob): Promise<void>;
1278
+ /**
1279
+ * Pop a job (RPOP, FIFO).
1280
+ * Supports implicit priority polling (critical -> high -> default -> low).
1281
+ */
1282
+ pop(queue: string): Promise<SerializedJob | null>;
1283
+ /**
1284
+ * Parse Redis payload.
1285
+ */
1286
+ private parsePayload;
1287
+ /**
1288
+ * Get queue size.
1289
+ */
1290
+ size(queue: string): Promise<number>;
1291
+ /**
1292
+ * Mark a job as permanently failed (DLQ).
1293
+ */
1294
+ fail(queue: string, job: SerializedJob): Promise<void>;
1295
+ /**
1296
+ * Clear a queue.
1297
+ */
1298
+ clear(queue: string): Promise<void>;
1299
+ /**
1300
+ * Push multiple jobs.
1301
+ */
1302
+ pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
1303
+ /**
1304
+ * Pop multiple jobs.
1305
+ */
1306
+ popMany(queue: string, count: number): Promise<SerializedJob[]>;
1307
+ /**
1308
+ * Report worker heartbeat for monitoring.
1309
+ */
1310
+ reportHeartbeat(workerInfo: any, prefix?: string): Promise<void>;
1311
+ /**
1312
+ * Publish a log message for monitoring.
1313
+ */
1314
+ publishLog(logPayload: any, prefix?: string): Promise<void>;
1315
+ /**
1316
+ * Check if a queue is rate limited.
1317
+ * Uses a fixed window counter.
1318
+ */
1319
+ checkRateLimit(queue: string, config: {
1320
+ max: number;
1321
+ duration: number;
1322
+ }): Promise<boolean>;
1323
+ /**
1324
+ * Get failed jobs from DLQ.
1325
+ */
1326
+ getFailed(queue: string, start?: number, end?: number): Promise<SerializedJob[]>;
1327
+ /**
1328
+ * Retry failed jobs from DLQ.
1329
+ * Moves jobs from failed list back to the main queue.
1330
+ */
1331
+ retryFailed(queue: string, count?: number): Promise<number>;
1332
+ /**
1333
+ * Clear failed jobs from DLQ.
1334
+ */
1335
+ clearFailed(queue: string): Promise<void>;
1336
+ }
1337
+
1338
+ /**
1339
+ * SQS driver configuration.
1340
+ */
1341
+ interface SQSDriverConfig {
1342
+ /**
1343
+ * SQS client instance (`@aws-sdk/client-sqs`).
1344
+ */
1345
+ client: {
1346
+ send: (command: unknown) => Promise<{
1347
+ MessageId?: string;
1348
+ Messages?: Array<{
1349
+ MessageId?: string;
1350
+ ReceiptHandle?: string;
1351
+ Body?: string;
1352
+ }>;
1353
+ }>;
1354
+ };
1355
+ /**
1356
+ * Queue URL prefix (used to build full queue URLs).
1357
+ */
1358
+ queueUrlPrefix?: string;
1359
+ /**
1360
+ * Visibility timeout (seconds, default: 30).
1361
+ */
1362
+ visibilityTimeout?: number;
1363
+ /**
1364
+ * Long-polling duration (seconds, default: 20).
1365
+ */
1366
+ waitTimeSeconds?: number;
1367
+ }
1368
+ /**
1369
+ * SQS Driver
1370
+ *
1371
+ * Uses AWS SQS as the queue backend.
1372
+ * Supports standard/FIFO queues, long polling, DLQ setups, etc.
1373
+ *
1374
+ * Requires `@aws-sdk/client-sqs`.
1375
+ *
1376
+ * @example
1377
+ * ```typescript
1378
+ * import { SQSClient } from '@aws-sdk/client-sqs'
1379
+ *
1380
+ * const sqs = new SQSClient({
1381
+ * region: 'us-east-1',
1382
+ * credentials: {
1383
+ * accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
1384
+ * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
1385
+ * }
1386
+ * })
1387
+ *
1388
+ * const driver = new SQSDriver({ client: sqs })
1389
+ * await driver.push('default', serializedJob)
1390
+ * ```
1391
+ */
1392
+ declare class SQSDriver implements QueueDriver {
1393
+ private client;
1394
+ private queueUrlPrefix;
1395
+ private visibilityTimeout;
1396
+ private waitTimeSeconds;
1397
+ private queueUrls;
1398
+ constructor(config: SQSDriverConfig);
1399
+ /**
1400
+ * Resolve the full queue URL.
1401
+ */
1402
+ private getQueueUrl;
1403
+ /**
1404
+ * Push a job to SQS.
1405
+ */
1406
+ push(queue: string, job: SerializedJob): Promise<void>;
1407
+ /**
1408
+ * Pop a job (long polling).
1409
+ */
1410
+ pop(queue: string): Promise<SerializedJob | null>;
1411
+ /**
1412
+ * Get queue size (approximate).
1413
+ */
1414
+ size(queue: string): Promise<number>;
1415
+ /**
1416
+ * Clear a queue by receiving and deleting messages.
1417
+ *
1418
+ * Note: SQS does not provide a direct "purge" API via this wrapper. This method will
1419
+ * keep receiving and deleting messages until the queue is empty.
1420
+ */
1421
+ clear(queue: string): Promise<void>;
1422
+ /**
1423
+ * Push multiple jobs.
1424
+ */
1425
+ pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
1426
+ /**
1427
+ * Acknowledge is not supported via messageId.
1428
+ */
1429
+ acknowledge(_messageId: string): Promise<void>;
1430
+ /**
1431
+ * Delete a message (acknowledge processing completion).
1432
+ */
1433
+ deleteMessage(queue: string, receiptHandle: string): Promise<void>;
1434
+ }
1435
+
1436
+ /**
1437
+ * Orbit Queue configuration options.
1438
+ */
1439
+ interface OrbitStreamOptions extends QueueConfig {
1440
+ /**
1441
+ * Whether to auto-start an embedded worker in development.
1442
+ */
1443
+ autoStartWorker?: boolean;
1444
+ /**
1445
+ * Embedded worker options.
1446
+ */
1447
+ workerOptions?: ConsumerOptions;
1448
+ }
1449
+ /**
1450
+ * Orbit Queue
1451
+ *
1452
+ * Gravito Orbit implementation providing queue functionality.
1453
+ * Integrates with PlanetCore and injects a `queue` service into the Photon Context.
1454
+ *
1455
+ * @example
1456
+ * ```typescript
1457
+ * const core = await PlanetCore.boot({
1458
+ * orbits: [
1459
+ * OrbitStream.configure({
1460
+ * default: 'database',
1461
+ * connections: {
1462
+ * database: { driver: 'database', table: 'jobs' }
1463
+ * }
1464
+ * })
1465
+ * ]
1466
+ * })
1467
+ *
1468
+ * // Use in a controller/handler
1469
+ * const queue = c.get('queue')
1470
+ * await queue.push(new SendEmail('user@example.com'))
1471
+ * ```
1472
+ */
1473
+ declare class OrbitStream implements GravitoOrbit {
1474
+ private options;
1475
+ private queueManager?;
1476
+ private consumer?;
1477
+ constructor(options?: OrbitStreamOptions);
1478
+ /**
1479
+ * Static configuration helper.
1480
+ */
1481
+ static configure(options: OrbitStreamOptions): OrbitStream;
1482
+ /**
1483
+ * Install into PlanetCore.
1484
+ */
1485
+ install(core: PlanetCore): void;
1486
+ /**
1487
+ * Start embedded worker.
1488
+ */
1489
+ startWorker(options: ConsumerOptions): void;
1490
+ /**
1491
+ * Stop embedded worker.
1492
+ */
1493
+ stopWorker(): Promise<void>;
1494
+ /**
1495
+ * Get QueueManager instance.
1496
+ */
1497
+ getQueueManager(): QueueManager | undefined;
1498
+ }
1499
+ declare module '@gravito/core' {
1500
+ interface GravitoVariables {
1501
+ /** Queue manager for job processing */
1502
+ queue?: QueueManager;
1503
+ /** Database service (from orbit-db) */
1504
+ db?: unknown;
1505
+ }
1506
+ }
1507
+
1508
+ /**
1509
+ * MySQL Persistence Adapter.
1510
+ * Archives jobs into a MySQL table for long-term auditing.
1511
+ */
1512
+ declare class MySQLPersistence implements PersistenceAdapter {
1513
+ private db;
1514
+ private table;
1515
+ private logsTable;
1516
+ /**
1517
+ * @param db - An Atlas DB instance or compatible QueryBuilder.
1518
+ * @param table - The name of the table to store archived jobs.
1519
+ */
1520
+ constructor(db: any, table?: string, logsTable?: string);
1521
+ /**
1522
+ * Archive a job.
1523
+ */
1524
+ archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
1525
+ /**
1526
+ * Find a specific job in the archive.
1527
+ */
1528
+ find(queue: string, id: string): Promise<SerializedJob | null>;
1529
+ /**
1530
+ * List jobs from the archive.
1531
+ */
1532
+ list(queue: string, options?: {
1533
+ limit?: number;
1534
+ offset?: number;
1535
+ status?: 'completed' | 'failed' | 'waiting' | string;
1536
+ jobId?: string;
1537
+ startTime?: Date;
1538
+ endTime?: Date;
1539
+ }): Promise<SerializedJob[]>;
1540
+ /**
1541
+ * Search jobs from the archive.
1542
+ */
1543
+ search(query: string, options?: {
1544
+ limit?: number;
1545
+ offset?: number;
1546
+ queue?: string;
1547
+ }): Promise<SerializedJob[]>;
1548
+ /**
1549
+ * Archive a system log message.
1550
+ */
1551
+ archiveLog(log: {
1552
+ level: string;
1553
+ message: string;
1554
+ workerId: string;
1555
+ queue?: string;
1556
+ timestamp: Date;
1557
+ }): Promise<void>;
1558
+ /**
1559
+ * List system logs from the archive.
1560
+ */
1561
+ listLogs(options?: {
1562
+ limit?: number;
1563
+ offset?: number;
1564
+ level?: string;
1565
+ workerId?: string;
1566
+ queue?: string;
1567
+ search?: string;
1568
+ startTime?: Date;
1569
+ endTime?: Date;
1570
+ }): Promise<any[]>;
1571
+ /**
1572
+ * Count system logs in the archive.
1573
+ */
1574
+ countLogs(options?: {
1575
+ level?: string;
1576
+ workerId?: string;
1577
+ queue?: string;
1578
+ search?: string;
1579
+ startTime?: Date;
1580
+ endTime?: Date;
1581
+ }): Promise<number>;
1582
+ /**
1583
+ * Remove old records from the archive.
1584
+ */
1585
+ cleanup(days: number): Promise<number>;
1586
+ /**
1587
+ * Count jobs in the archive.
1588
+ */
1589
+ count(queue: string, options?: {
1590
+ status?: 'completed' | 'failed' | 'waiting' | string;
1591
+ jobId?: string;
1592
+ startTime?: Date;
1593
+ endTime?: Date;
1594
+ }): Promise<number>;
1595
+ /**
1596
+ * Help script to create the necessary table.
1597
+ */
1598
+ setupTable(): Promise<void>;
1599
+ private setupJobsTable;
1600
+ private setupLogsTable;
1601
+ }
1602
+
1603
+ /**
1604
+ * SQLite Persistence Adapter.
1605
+ * Archives jobs into a local SQLite database for zero-config persistence.
1606
+ */
1607
+ declare class SQLitePersistence implements PersistenceAdapter {
1608
+ private db;
1609
+ private table;
1610
+ private logsTable;
1611
+ /**
1612
+ * @param db - An Atlas DB instance (SQLite driver).
1613
+ * @param table - The name of the table to store archived jobs.
1614
+ */
1615
+ constructor(db: any, table?: string, logsTable?: string);
1616
+ /**
1617
+ * Archive a job.
1618
+ */
1619
+ archive(queue: string, job: SerializedJob, status: 'completed' | 'failed' | 'waiting' | string): Promise<void>;
1620
+ /**
1621
+ * Find a specific job in the archive.
1622
+ */
1623
+ find(queue: string, id: string): Promise<SerializedJob | null>;
1624
+ /**
1625
+ * List jobs from the archive.
1626
+ */
1627
+ list(queue: string, options?: {
1628
+ limit?: number;
1629
+ offset?: number;
1630
+ status?: 'completed' | 'failed' | 'waiting' | string;
1631
+ jobId?: string;
1632
+ startTime?: Date;
1633
+ endTime?: Date;
1634
+ }): Promise<SerializedJob[]>;
1635
+ /**
1636
+ * Search jobs from the archive.
1637
+ */
1638
+ search(query: string, options?: {
1639
+ limit?: number;
1640
+ offset?: number;
1641
+ queue?: string;
1642
+ }): Promise<SerializedJob[]>;
1643
+ /**
1644
+ * Archive a system log message.
1645
+ */
1646
+ archiveLog(log: {
1647
+ level: string;
1648
+ message: string;
1649
+ workerId: string;
1650
+ queue?: string;
1651
+ timestamp: Date;
1652
+ }): Promise<void>;
1653
+ /**
1654
+ * List system logs from the archive.
1655
+ */
1656
+ listLogs(options?: {
1657
+ limit?: number;
1658
+ offset?: number;
1659
+ level?: string;
1660
+ workerId?: string;
1661
+ queue?: string;
1662
+ search?: string;
1663
+ startTime?: Date;
1664
+ endTime?: Date;
1665
+ }): Promise<any[]>;
1666
+ /**
1667
+ * Count system logs in the archive.
1668
+ */
1669
+ countLogs(options?: {
1670
+ level?: string;
1671
+ workerId?: string;
1672
+ queue?: string;
1673
+ search?: string;
1674
+ startTime?: Date;
1675
+ endTime?: Date;
1676
+ }): Promise<number>;
1677
+ /**
1678
+ * Remove old records from the archive.
1679
+ */
1680
+ cleanup(days: number): Promise<number>;
1681
+ /**
1682
+ * Count jobs in the archive.
1683
+ */
1684
+ count(queue: string, options?: {
1685
+ status?: 'completed' | 'failed' | 'waiting' | string;
1686
+ jobId?: string;
1687
+ startTime?: Date;
1688
+ endTime?: Date;
1689
+ }): Promise<number>;
1690
+ /**
1691
+ * Setup table for SQLite.
1692
+ */
1693
+ setupTable(): Promise<void>;
1694
+ private setupJobsTable;
1695
+ private setupLogsTable;
1696
+ }
1697
+
1698
+ interface ScheduledJobConfig {
1699
+ id: string;
1700
+ cron: string;
1701
+ queue: string;
1702
+ job: SerializedJob;
1703
+ lastRun?: number;
1704
+ nextRun?: number;
1705
+ enabled: boolean;
1706
+ }
1707
+ /**
1708
+ * Scheduler
1709
+ *
1710
+ * Manages recurring (cron) jobs.
1711
+ */
1712
+ declare class Scheduler {
1713
+ private manager;
1714
+ private prefix;
1715
+ constructor(manager: QueueManager, options?: {
1716
+ prefix?: string;
1717
+ });
1718
+ private get client();
1719
+ /**
1720
+ * Register a scheduled job.
1721
+ */
1722
+ register(config: Omit<ScheduledJobConfig, 'nextRun' | 'enabled'>): Promise<void>;
1723
+ /**
1724
+ * Remove a scheduled job.
1725
+ */
1726
+ remove(id: string): Promise<void>;
1727
+ /**
1728
+ * List all scheduled jobs.
1729
+ */
1730
+ list(): Promise<ScheduledJobConfig[]>;
1731
+ /**
1732
+ * Run a scheduled job immediately (out of schedule).
1733
+ */
1734
+ runNow(id: string): Promise<void>;
1735
+ /**
1736
+ * Process due tasks (TICK).
1737
+ * This should be called periodically (e.g. every minute).
1738
+ */
1739
+ tick(): Promise<number>;
1740
+ }
1741
+
1742
+ /**
1743
+ * Class name serializer (Laravel-style).
1744
+ *
1745
+ * Stores the class name and properties, then recreates an instance at runtime.
1746
+ * This is the recommended serializer because it can restore class instances correctly.
1747
+ *
1748
+ * Requirement: Job classes must be dynamically loadable (by class name).
1749
+ *
1750
+ * @example
1751
+ * ```typescript
1752
+ * const serializer = new ClassNameSerializer()
1753
+ * const serialized = serializer.serialize(new SendEmail('user@example.com'))
1754
+ * // serialized.data contains class name and properties
1755
+ *
1756
+ * const job = serializer.deserialize(serialized)
1757
+ * // job is an instance of SendEmail
1758
+ * ```
1759
+ */
1760
+ declare class ClassNameSerializer implements JobSerializer {
1761
+ /**
1762
+ * Job class registry (for resolving classes by name).
1763
+ */
1764
+ private jobClasses;
1765
+ /**
1766
+ * Register a Job class.
1767
+ * @param jobClass - Job class
1768
+ */
1769
+ register(jobClass: new (...args: unknown[]) => Job): void;
1770
+ /**
1771
+ * Register multiple Job classes.
1772
+ * @param jobClasses - Job class array
1773
+ */
1774
+ registerMany(jobClasses: Array<new (...args: unknown[]) => Job>): void;
1775
+ /**
1776
+ * Serialize a Job.
1777
+ */
1778
+ serialize(job: Job): SerializedJob;
1779
+ /**
1780
+ * Deserialize a Job.
1781
+ */
1782
+ deserialize(serialized: SerializedJob): Job;
1783
+ }
1784
+
1785
+ /**
1786
+ * JSON Serializer
1787
+ *
1788
+ * Serializes jobs using JSON.
1789
+ * Suitable for simple scenarios where you only need to persist plain properties.
1790
+ *
1791
+ * Limitation: cannot restore class instances, functions, or complex objects.
1792
+ *
1793
+ * @example
1794
+ * ```typescript
1795
+ * const serializer = new JsonSerializer()
1796
+ * const serialized = serializer.serialize(job)
1797
+ * const job = serializer.deserialize(serialized)
1798
+ * ```
1799
+ */
1800
+ declare class JsonSerializer implements JobSerializer {
1801
+ /**
1802
+ * Serialize a job.
1803
+ */
1804
+ serialize(job: Job): SerializedJob;
1805
+ /**
1806
+ * Deserialize a job.
1807
+ *
1808
+ * Note: this implementation only restores properties and does not recreate class instances.
1809
+ * For class instances, use `ClassNameSerializer`.
1810
+ */
1811
+ deserialize(serialized: SerializedJob): Job;
1812
+ }
1813
+
1814
+ export { ClassNameSerializer, Consumer, type ConsumerOptions, DatabaseDriver, type DatabaseDriverConfig, Job, type JobSerializer, JsonSerializer, KafkaDriver, type KafkaDriverConfig, MemoryDriver, MySQLPersistence, OrbitStream, type OrbitStreamOptions, type PersistenceAdapter, type QueueConfig, type QueueConnectionConfig, type QueueDriver, QueueManager, type Queueable, RabbitMQDriver, type RabbitMQDriverConfig, RedisDriver, type RedisDriverConfig, SQLitePersistence, SQSDriver, type SQSDriverConfig, Scheduler, type SerializedJob, type TopicOptions, Worker, type WorkerOptions };