flashq 0.2.1 → 0.3.1

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 (119) hide show
  1. package/dist/client/connection.d.ts +27 -69
  2. package/dist/client/connection.d.ts.map +1 -1
  3. package/dist/client/connection.js +291 -272
  4. package/dist/client/connection.js.map +1 -1
  5. package/dist/client/http/request.d.ts +24 -0
  6. package/dist/client/http/request.d.ts.map +1 -0
  7. package/dist/client/http/request.js +289 -0
  8. package/dist/client/http/request.js.map +1 -0
  9. package/dist/client/http/response.d.ts +9 -0
  10. package/dist/client/http/response.d.ts.map +1 -0
  11. package/dist/client/http/response.js +80 -0
  12. package/dist/client/http/response.js.map +1 -0
  13. package/dist/client/index.d.ts +68 -562
  14. package/dist/client/index.d.ts.map +1 -1
  15. package/dist/client/index.js +186 -638
  16. package/dist/client/index.js.map +1 -1
  17. package/dist/client/{advanced.d.ts → methods/advanced.d.ts} +1 -1
  18. package/dist/client/methods/advanced.d.ts.map +1 -0
  19. package/dist/client/methods/advanced.js.map +1 -0
  20. package/dist/client/{core.d.ts → methods/core.d.ts} +25 -2
  21. package/dist/client/methods/core.d.ts.map +1 -0
  22. package/dist/client/{core.js → methods/core.js} +106 -1
  23. package/dist/client/methods/core.js.map +1 -0
  24. package/dist/client/{cron.d.ts → methods/cron.d.ts} +1 -1
  25. package/dist/client/methods/cron.d.ts.map +1 -0
  26. package/dist/client/methods/cron.js.map +1 -0
  27. package/dist/client/{dlq.d.ts → methods/dlq.d.ts} +1 -1
  28. package/dist/client/methods/dlq.d.ts.map +1 -0
  29. package/dist/client/methods/dlq.js.map +1 -0
  30. package/dist/client/{flows.d.ts → methods/flows.d.ts} +1 -1
  31. package/dist/client/methods/flows.d.ts.map +1 -0
  32. package/dist/client/methods/flows.js.map +1 -0
  33. package/dist/client/{jobs.d.ts → methods/jobs.d.ts} +2 -16
  34. package/dist/client/methods/jobs.d.ts.map +1 -0
  35. package/dist/client/{jobs.js → methods/jobs.js} +1 -15
  36. package/dist/client/methods/jobs.js.map +1 -0
  37. package/dist/client/{metrics.d.ts → methods/metrics.d.ts} +1 -1
  38. package/dist/client/methods/metrics.d.ts.map +1 -0
  39. package/dist/client/methods/metrics.js.map +1 -0
  40. package/dist/client/{queue.d.ts → methods/queue.d.ts} +1 -1
  41. package/dist/client/methods/queue.d.ts.map +1 -0
  42. package/dist/client/methods/queue.js.map +1 -0
  43. package/dist/client/types.d.ts +10 -3
  44. package/dist/client/types.d.ts.map +1 -1
  45. package/dist/errors.d.ts +105 -0
  46. package/dist/errors.d.ts.map +1 -0
  47. package/dist/errors.js +223 -0
  48. package/dist/errors.js.map +1 -0
  49. package/dist/events/index.d.ts +24 -0
  50. package/dist/events/index.d.ts.map +1 -0
  51. package/dist/events/index.js +53 -0
  52. package/dist/events/index.js.map +1 -0
  53. package/dist/events/subscriber.d.ts +30 -0
  54. package/dist/events/subscriber.d.ts.map +1 -0
  55. package/dist/{events.js → events/subscriber.js} +51 -148
  56. package/dist/events/subscriber.js.map +1 -0
  57. package/dist/events/types.d.ts +38 -0
  58. package/dist/events/types.d.ts.map +1 -0
  59. package/dist/events/types.js +6 -0
  60. package/dist/events/types.js.map +1 -0
  61. package/dist/hooks.d.ts +166 -0
  62. package/dist/hooks.d.ts.map +1 -0
  63. package/dist/hooks.js +73 -0
  64. package/dist/hooks.js.map +1 -0
  65. package/dist/index.d.ts +9 -2
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +36 -2
  68. package/dist/index.js.map +1 -1
  69. package/dist/queue.d.ts.map +1 -1
  70. package/dist/queue.js +9 -5
  71. package/dist/queue.js.map +1 -1
  72. package/dist/types.d.ts +53 -2
  73. package/dist/types.d.ts.map +1 -1
  74. package/dist/utils/logger.d.ts +53 -0
  75. package/dist/utils/logger.d.ts.map +1 -0
  76. package/dist/utils/logger.js +150 -0
  77. package/dist/utils/logger.js.map +1 -0
  78. package/dist/utils/retry.d.ts +70 -0
  79. package/dist/utils/retry.d.ts.map +1 -0
  80. package/dist/utils/retry.js +149 -0
  81. package/dist/utils/retry.js.map +1 -0
  82. package/dist/worker.d.ts +26 -5
  83. package/dist/worker.d.ts.map +1 -1
  84. package/dist/worker.js +157 -86
  85. package/dist/worker.js.map +1 -1
  86. package/package.json +11 -1
  87. package/dist/client/advanced.d.ts.map +0 -1
  88. package/dist/client/advanced.js.map +0 -1
  89. package/dist/client/core.d.ts.map +0 -1
  90. package/dist/client/core.js.map +0 -1
  91. package/dist/client/cron.d.ts.map +0 -1
  92. package/dist/client/cron.js.map +0 -1
  93. package/dist/client/dlq.d.ts.map +0 -1
  94. package/dist/client/dlq.js.map +0 -1
  95. package/dist/client/flows.d.ts.map +0 -1
  96. package/dist/client/flows.js.map +0 -1
  97. package/dist/client/jobs.d.ts.map +0 -1
  98. package/dist/client/jobs.js.map +0 -1
  99. package/dist/client/kv.d.ts +0 -63
  100. package/dist/client/kv.d.ts.map +0 -1
  101. package/dist/client/kv.js +0 -131
  102. package/dist/client/kv.js.map +0 -1
  103. package/dist/client/metrics.d.ts.map +0 -1
  104. package/dist/client/metrics.js.map +0 -1
  105. package/dist/client/pubsub.d.ts +0 -42
  106. package/dist/client/pubsub.d.ts.map +0 -1
  107. package/dist/client/pubsub.js +0 -92
  108. package/dist/client/pubsub.js.map +0 -1
  109. package/dist/client/queue.d.ts.map +0 -1
  110. package/dist/client/queue.js.map +0 -1
  111. package/dist/events.d.ts +0 -184
  112. package/dist/events.d.ts.map +0 -1
  113. package/dist/events.js.map +0 -1
  114. /package/dist/client/{advanced.js → methods/advanced.js} +0 -0
  115. /package/dist/client/{cron.js → methods/cron.js} +0 -0
  116. /package/dist/client/{dlq.js → methods/dlq.js} +0 -0
  117. /package/dist/client/{flows.js → methods/flows.js} +0 -0
  118. /package/dist/client/{metrics.js → methods/metrics.js} +0 -0
  119. /package/dist/client/{queue.js → methods/queue.js} +0 -0
@@ -1,341 +1,111 @@
1
1
  /**
2
- * FlashQ Client - High-performance job queue client
2
+ * FlashQ Client - High-performance job queue client.
3
3
  *
4
- * @example
5
- * ```typescript
6
- * import { FlashQ } from 'flashq';
7
- *
8
- * const client = new FlashQ();
9
- *
10
- * // Add a job (auto-connects!)
11
- * const job = await client.add('emails', { to: 'user@example.com' });
12
- *
13
- * // That's it! No connect() needed.
14
- * ```
15
- *
16
- * @example
17
- * ```typescript
18
- * // With options
19
- * const client = new FlashQ({
20
- * host: 'localhost',
21
- * port: 6789,
22
- * token: 'secret'
23
- * });
24
- *
25
- * // Add with job options
26
- * await client.add('emails', { to: 'user@example.com' }, {
27
- * priority: 10,
28
- * delay: 5000,
29
- * max_attempts: 3
30
- * });
31
- * ```
4
+ * This is the main facade that exposes all operations.
5
+ * Methods are organized into logical modules under ./methods/
32
6
  */
33
7
  import { FlashQConnection } from './connection';
34
- import * as kv from './kv';
35
- import type { Job, JobState, JobWithState, PushOptions, QueueInfo, QueueStats, Metrics, CronJob, CronOptions, JobLogEntry, FlowChild, FlowResult, FlowOptions } from './types';
36
- /**
37
- * FlashQ Client - High-performance job queue client with auto-connect.
38
- */
8
+ import { type ClientHooks } from '../hooks';
9
+ import type { Job, JobState, JobWithState, PushOptions, QueueInfo, QueueStats, Metrics, CronJob, CronOptions, JobLogEntry, FlowChild, FlowResult, FlowOptions, BatchPushResult } from './types';
10
+ export type { BatchPushResult } from './types';
11
+ /** FlashQ Client - High-performance job queue client with auto-connect. */
39
12
  export declare class FlashQ extends FlashQConnection {
40
- /**
41
- * Push a job to a queue.
42
- *
43
- * @param queue - Queue name
44
- * @param data - Job data payload
45
- * @param options - Push options (priority, delay, ttl, etc.)
46
- * @returns Created job
47
- *
48
- * @example
49
- * ```typescript
50
- * const job = await client.push('emails', { to: 'user@example.com' });
51
- * ```
52
- */
53
- push<T = unknown>(queueName: string, data: T, options?: PushOptions): Promise<Job>;
54
- /**
55
- * Add a job to a queue (alias for push).
56
- *
57
- * @param queue - Queue name
58
- * @param data - Job data payload
59
- * @param options - Push options
60
- * @returns Created job
61
- */
62
- add<T = unknown>(queueName: string, data: T, options?: PushOptions): Promise<Job>;
63
- /**
64
- * Push multiple jobs to a queue in a single batch.
65
- *
66
- * @param queue - Queue name
67
- * @param jobs - Array of jobs with data and options
68
- * @returns Array of created job IDs
69
- */
13
+ /** Hooks for observability */
14
+ get hooks(): ClientHooks | undefined;
15
+ /** Push a job to a queue */
16
+ push<T = unknown>(queueName: string, data: T, opts?: PushOptions): Promise<Job>;
17
+ /** Add a job to a queue (alias for push) */
18
+ add<T = unknown>(queueName: string, data: T, opts?: PushOptions): Promise<Job>;
19
+ /** Push multiple jobs in a single batch */
70
20
  pushBatch<T = unknown>(queueName: string, jobList: Array<{
71
21
  data: T;
72
22
  } & PushOptions>): Promise<number[]>;
73
- /**
74
- * Add multiple jobs to a queue (alias for pushBatch).
75
- */
23
+ /** Add multiple jobs (alias for pushBatch) */
76
24
  addBulk<T = unknown>(queueName: string, jobList: Array<{
77
25
  data: T;
78
26
  } & PushOptions>): Promise<number[]>;
79
- /**
80
- * Pull a job from a queue (blocking with server-side timeout).
81
- *
82
- * @param queue - Queue name
83
- * @param timeout - Server-side timeout in ms (default: 60s)
84
- * @returns Job or null if timeout
85
- */
27
+ /** Push multiple jobs with partial failure handling */
28
+ pushBatchSafe<T = unknown>(queueName: string, jobList: Array<{
29
+ data: T;
30
+ } & PushOptions>): Promise<BatchPushResult>;
31
+ /** Pull a job from a queue (blocking with timeout) */
86
32
  pull<T = unknown>(queueName: string, timeout?: number): Promise<(Job & {
87
33
  data: T;
88
34
  }) | null>;
89
- /**
90
- * Pull multiple jobs from a queue.
91
- *
92
- * @param queue - Queue name
93
- * @param count - Number of jobs to pull
94
- * @param timeout - Server-side timeout in ms (default: 60s)
95
- * @returns Array of jobs
96
- */
35
+ /** Pull multiple jobs from a queue */
97
36
  pullBatch<T = unknown>(queueName: string, count: number, timeout?: number): Promise<Array<Job & {
98
37
  data: T;
99
38
  }>>;
100
- /**
101
- * Acknowledge a job as completed.
102
- *
103
- * @param jobId - Job ID
104
- * @param result - Optional result data
105
- */
39
+ /** Acknowledge a job as completed */
106
40
  ack(jobId: number, result?: unknown): Promise<void>;
107
- /**
108
- * Acknowledge multiple jobs at once.
109
- *
110
- * @param jobIds - Array of job IDs
111
- * @returns Number of jobs acknowledged
112
- */
41
+ /** Acknowledge multiple jobs at once */
113
42
  ackBatch(jobIds: number[]): Promise<number>;
114
- /**
115
- * Fail a job (will retry or move to DLQ).
116
- *
117
- * @param jobId - Job ID
118
- * @param error - Optional error message
119
- */
43
+ /** Fail a job (will retry or move to DLQ) */
120
44
  fail(jobId: number, error?: string): Promise<void>;
121
- /**
122
- * Get a job with its current state.
123
- *
124
- * @param jobId - Job ID
125
- * @returns Job with state, or null if not found
126
- */
45
+ /** Get a job with its current state */
127
46
  getJob(jobId: number): Promise<JobWithState | null>;
128
- /**
129
- * Get job state only.
130
- *
131
- * @param jobId - Job ID
132
- * @returns Job state or null if not found
133
- */
47
+ /** Get job state only */
134
48
  getState(jobId: number): Promise<JobState | null>;
135
- /**
136
- * Get job result.
137
- *
138
- * @param jobId - Job ID
139
- * @returns Job result or null
140
- */
49
+ /** Get job result */
141
50
  getResult<T = unknown>(jobId: number): Promise<T | null>;
142
- /**
143
- * Wait for a job to complete and return its result.
144
- *
145
- * @param jobId - Job ID
146
- * @param timeout - Timeout in ms (default: 30000)
147
- * @returns Job result or null
148
- * @throws Error if job fails or times out
149
- */
51
+ /** Wait for a job to complete (finished() promise pattern) */
150
52
  finished<T = unknown>(jobId: number, timeout?: number): Promise<T | null>;
151
- /**
152
- * Get a job by its custom ID.
153
- *
154
- * @param customId - Custom job ID
155
- * @returns Job with state or null
156
- */
53
+ /** Get a job by its custom ID */
157
54
  getJobByCustomId(customId: string): Promise<JobWithState | null>;
158
- /**
159
- * Get multiple jobs by their IDs in a single call.
160
- *
161
- * @param jobIds - Array of job IDs
162
- * @returns Array of jobs with states
163
- */
55
+ /** Get multiple jobs by their IDs */
164
56
  getJobsBatch(jobIds: number[]): Promise<JobWithState[]>;
165
- /**
166
- * Cancel a pending job.
167
- *
168
- * @param jobId - Job ID
169
- */
57
+ /** Cancel a pending job */
170
58
  cancel(jobId: number): Promise<void>;
171
- /**
172
- * Update job progress.
173
- *
174
- * @param jobId - Job ID
175
- * @param progress - Progress value (0-100)
176
- * @param message - Optional progress message
177
- */
178
- progress(jobId: number, progressValue: number, message?: string): Promise<void>;
179
- /**
180
- * Get job progress.
181
- *
182
- * @param jobId - Job ID
183
- * @returns Progress value and message
184
- */
59
+ /** Update job progress */
60
+ progress(jobId: number, value: number, message?: string): Promise<void>;
61
+ /** Get job progress */
185
62
  getProgress(jobId: number): Promise<{
186
63
  progress: number;
187
64
  message?: string;
188
65
  }>;
189
- /**
190
- * Add a log entry to a job.
191
- *
192
- * @param jobId - Job ID
193
- * @param message - Log message
194
- * @param level - Log level (info, warn, error)
195
- */
66
+ /** Add a log entry to a job */
196
67
  log(jobId: number, message: string, level?: 'info' | 'warn' | 'error'): Promise<void>;
197
- /**
198
- * Get log entries for a job.
199
- *
200
- * @param jobId - Job ID
201
- * @returns Array of log entries
202
- */
68
+ /** Get log entries for a job */
203
69
  getLogs(jobId: number): Promise<JobLogEntry[]>;
204
- /**
205
- * Send a heartbeat for a long-running job.
206
- *
207
- * @param jobId - Job ID
208
- */
70
+ /** Send a heartbeat for a long-running job */
209
71
  heartbeat(jobId: number): Promise<void>;
210
- /**
211
- * Pause a queue.
212
- *
213
- * @param queue - Queue name
214
- */
72
+ /** Pause a queue */
215
73
  pause(queueName: string): Promise<void>;
216
- /**
217
- * Resume a paused queue.
218
- *
219
- * @param queue - Queue name
220
- */
74
+ /** Resume a paused queue */
221
75
  resume(queueName: string): Promise<void>;
222
- /**
223
- * Check if a queue is paused.
224
- *
225
- * @param queue - Queue name
226
- * @returns true if paused
227
- */
76
+ /** Check if a queue is paused */
228
77
  isPaused(queueName: string): Promise<boolean>;
229
- /**
230
- * Set rate limit for a queue (jobs per second).
231
- *
232
- * @param queue - Queue name
233
- * @param limit - Jobs per second
234
- */
78
+ /** Set rate limit for a queue (jobs per second) */
235
79
  setRateLimit(queueName: string, limit: number): Promise<void>;
236
- /**
237
- * Clear rate limit for a queue.
238
- *
239
- * @param queue - Queue name
240
- */
80
+ /** Clear rate limit for a queue */
241
81
  clearRateLimit(queueName: string): Promise<void>;
242
- /**
243
- * Set concurrency limit for a queue.
244
- *
245
- * @param queue - Queue name
246
- * @param limit - Max concurrent jobs
247
- */
82
+ /** Set concurrency limit for a queue */
248
83
  setConcurrency(queueName: string, limit: number): Promise<void>;
249
- /**
250
- * Clear concurrency limit for a queue.
251
- *
252
- * @param queue - Queue name
253
- */
84
+ /** Clear concurrency limit for a queue */
254
85
  clearConcurrency(queueName: string): Promise<void>;
255
- /**
256
- * List all queues.
257
- *
258
- * @returns Array of queue info
259
- */
86
+ /** List all queues */
260
87
  listQueues(): Promise<QueueInfo[]>;
261
- /**
262
- * Get jobs from the dead letter queue.
263
- *
264
- * @param queue - Queue name
265
- * @param count - Max jobs to return (default: 100)
266
- * @returns Array of failed jobs
267
- */
88
+ /** Get jobs from the dead letter queue */
268
89
  getDlq(queueName: string, count?: number): Promise<Job[]>;
269
- /**
270
- * Retry jobs from the dead letter queue.
271
- *
272
- * @param queue - Queue name
273
- * @param jobId - Optional specific job ID to retry
274
- * @returns Number of jobs retried
275
- */
90
+ /** Retry jobs from the dead letter queue */
276
91
  retryDlq(queueName: string, jobId?: number): Promise<number>;
277
- /**
278
- * Purge all jobs from the dead letter queue.
279
- *
280
- * @param queue - Queue name
281
- * @returns Number of jobs purged
282
- */
92
+ /** Purge all jobs from the dead letter queue */
283
93
  purgeDlq(queueName: string): Promise<number>;
284
- /**
285
- * Add a cron job for scheduled recurring tasks.
286
- *
287
- * @param name - Unique cron job name
288
- * @param options - Cron options
289
- */
94
+ /** Add a cron job for scheduled recurring tasks */
290
95
  addCron(name: string, options: CronOptions): Promise<void>;
291
- /**
292
- * Delete a cron job.
293
- *
294
- * @param name - Cron job name
295
- * @returns true if deleted
296
- */
96
+ /** Delete a cron job */
297
97
  deleteCron(name: string): Promise<boolean>;
298
- /**
299
- * List all cron jobs.
300
- *
301
- * @returns Array of cron jobs
302
- */
98
+ /** List all cron jobs */
303
99
  listCrons(): Promise<CronJob[]>;
304
- /**
305
- * Get queue statistics.
306
- *
307
- * @returns Queue stats
308
- */
100
+ /** Get queue statistics */
309
101
  stats(): Promise<QueueStats>;
310
- /**
311
- * Get detailed metrics.
312
- *
313
- * @returns Detailed metrics object
314
- */
102
+ /** Get detailed metrics */
315
103
  metrics(): Promise<Metrics>;
316
- /**
317
- * Push a flow (parent job with children).
318
- *
319
- * @param queue - Parent queue name
320
- * @param parentData - Parent job data
321
- * @param children - Array of child jobs
322
- * @param options - Flow options
323
- * @returns Parent and children IDs
324
- */
104
+ /** Push a flow (parent job with children) */
325
105
  pushFlow<T = unknown>(queueName: string, parentData: T, children: FlowChild[], options?: FlowOptions): Promise<FlowResult>;
326
- /**
327
- * Get children job IDs for a parent job in a flow.
328
- *
329
- * @param jobId - Parent job ID
330
- * @returns Array of children job IDs
331
- */
106
+ /** Get children job IDs for a parent job */
332
107
  getChildren(jobId: number): Promise<number[]>;
333
- /**
334
- * Get jobs filtered by queue and/or state with pagination.
335
- *
336
- * @param options - Filter options
337
- * @returns Jobs and total count
338
- */
108
+ /** Get jobs filtered by queue and/or state with pagination */
339
109
  getJobs(options?: {
340
110
  queue?: string;
341
111
  state?: JobState;
@@ -345,12 +115,7 @@ export declare class FlashQ extends FlashQConnection {
345
115
  jobs: JobWithState[];
346
116
  total: number;
347
117
  }>;
348
- /**
349
- * Get job counts by state for a queue.
350
- *
351
- * @param queue - Queue name
352
- * @returns Counts by state
353
- */
118
+ /** Get job counts by state for a queue */
354
119
  getJobCounts(queueName: string): Promise<{
355
120
  waiting: number;
356
121
  active: number;
@@ -358,287 +123,28 @@ export declare class FlashQ extends FlashQConnection {
358
123
  completed: number;
359
124
  failed: number;
360
125
  }>;
361
- /**
362
- * Get total count of jobs in a queue (waiting + delayed).
363
- *
364
- * @param queue - Queue name
365
- * @returns Total job count
366
- */
126
+ /** Get total count of jobs in a queue (waiting + delayed) */
367
127
  count(queueName: string): Promise<number>;
368
- /**
369
- * Clean jobs older than grace period by state.
370
- *
371
- * @param queue - Queue name
372
- * @param grace - Grace period in ms
373
- * @param state - Job state to clean
374
- * @param limit - Optional max jobs to clean
375
- * @returns Number of jobs cleaned
376
- */
128
+ /** Clean jobs older than grace period by state */
377
129
  clean(queueName: string, grace: number, state: 'waiting' | 'delayed' | 'completed' | 'failed', limit?: number): Promise<number>;
378
- /**
379
- * Drain all waiting jobs from a queue.
380
- *
381
- * @param queue - Queue name
382
- * @returns Number of jobs drained
383
- */
130
+ /** Drain all waiting jobs from a queue */
384
131
  drain(queueName: string): Promise<number>;
385
- /**
386
- * Remove ALL data for a queue.
387
- *
388
- * @param queue - Queue name
389
- * @returns Total items removed
390
- */
132
+ /** Remove ALL data for a queue */
391
133
  obliterate(queueName: string): Promise<number>;
392
- /**
393
- * Change job priority.
394
- *
395
- * @param jobId - Job ID
396
- * @param priority - New priority
397
- */
134
+ /** Change job priority */
398
135
  changePriority(jobId: number, priority: number): Promise<void>;
399
- /**
400
- * Move job from processing back to delayed.
401
- *
402
- * @param jobId - Job ID
403
- * @param delay - Delay in ms
404
- */
136
+ /** Move job from processing back to delayed */
405
137
  moveToDelayed(jobId: number, delay: number): Promise<void>;
406
- /**
407
- * Promote delayed job to waiting immediately.
408
- *
409
- * @param jobId - Job ID
410
- */
138
+ /** Promote delayed job to waiting immediately */
411
139
  promote(jobId: number): Promise<void>;
412
- /**
413
- * Update job data.
414
- *
415
- * @param jobId - Job ID
416
- * @param data - New data payload
417
- */
140
+ /** Update job data */
418
141
  update<T = unknown>(jobId: number, data: T): Promise<void>;
419
- /**
420
- * Discard job - move directly to DLQ.
421
- *
422
- * @param jobId - Job ID
423
- */
142
+ /** Discard job - move directly to DLQ */
424
143
  discard(jobId: number): Promise<void>;
425
- /**
426
- * Subscribe to real-time events via SSE.
427
- *
428
- * @param queue - Optional queue to filter events
429
- * @returns EventSubscriber instance
430
- *
431
- * @example
432
- * ```typescript
433
- * const events = client.subscribe();
434
- * events.on('completed', (e) => console.log(`Job ${e.jobId} completed`));
435
- * await events.connect();
436
- * ```
437
- */
144
+ /** Subscribe to real-time events via SSE */
438
145
  subscribe(queueName?: string): import('../events').EventSubscriber;
439
- /**
440
- * Subscribe to real-time events via WebSocket.
441
- *
442
- * @param queue - Optional queue to filter events
443
- * @returns EventSubscriber instance
444
- */
146
+ /** Subscribe to real-time events via WebSocket */
445
147
  subscribeWs(queueName?: string): import('../events').EventSubscriber;
446
- /**
447
- * Set a key-value pair.
448
- *
449
- * @param key - Key name
450
- * @param value - Value (any JSON-serializable data)
451
- * @param options - Optional TTL settings
452
- *
453
- * @example
454
- * ```typescript
455
- * await client.kvSet('user:123', { name: 'John' });
456
- * await client.kvSet('session:abc', { token: 'xyz' }, { ttl: 3600000 }); // 1 hour TTL
457
- * ```
458
- */
459
- kvSet(key: string, value: unknown, options?: kv.KvSetOptions): Promise<void>;
460
- /**
461
- * Get a value by key.
462
- *
463
- * @param key - Key name
464
- * @returns Value or null if not found/expired
465
- *
466
- * @example
467
- * ```typescript
468
- * const user = await client.kvGet<User>('user:123');
469
- * ```
470
- */
471
- kvGet<T = unknown>(key: string): Promise<T | null>;
472
- /**
473
- * Delete a key.
474
- *
475
- * @param key - Key name
476
- * @returns true if key existed
477
- */
478
- kvDel(key: string): Promise<boolean>;
479
- /**
480
- * Check if a key exists.
481
- *
482
- * @param key - Key name
483
- * @returns true if key exists and not expired
484
- */
485
- kvExists(key: string): Promise<boolean>;
486
- /**
487
- * Set TTL on an existing key.
488
- *
489
- * @param key - Key name
490
- * @param ttl - Time-to-live in milliseconds
491
- * @returns true if key existed
492
- */
493
- kvExpire(key: string, ttl: number): Promise<boolean>;
494
- /**
495
- * Get remaining TTL for a key.
496
- *
497
- * @param key - Key name
498
- * @returns ms remaining, -1 if no TTL, -2 if key doesn't exist
499
- */
500
- kvTtl(key: string): Promise<number>;
501
- /**
502
- * Get multiple values by keys (batch operation).
503
- *
504
- * @param keys - Array of keys
505
- * @returns Array of values (null for missing keys)
506
- *
507
- * @example
508
- * ```typescript
509
- * const [user1, user2, user3] = await client.kvMget<User>(['user:1', 'user:2', 'user:3']);
510
- * ```
511
- */
512
- kvMget<T = unknown>(keys: string[]): Promise<(T | null)[]>;
513
- /**
514
- * Set multiple key-value pairs (batch operation).
515
- *
516
- * @param entries - Array of {key, value, ttl?}
517
- * @returns Number of keys set
518
- *
519
- * @example
520
- * ```typescript
521
- * await client.kvMset([
522
- * { key: 'user:1', value: { name: 'Alice' } },
523
- * { key: 'user:2', value: { name: 'Bob' }, ttl: 60000 },
524
- * ]);
525
- * ```
526
- */
527
- kvMset(entries: kv.KvEntry[]): Promise<number>;
528
- /**
529
- * List keys matching a pattern.
530
- *
531
- * @param pattern - Glob pattern (* = any, ? = one char)
532
- * @returns Array of matching keys
533
- *
534
- * @example
535
- * ```typescript
536
- * const userKeys = await client.kvKeys('user:*');
537
- * const sessionKeys = await client.kvKeys('session:???');
538
- * ```
539
- */
540
- kvKeys(pattern?: string): Promise<string[]>;
541
- /**
542
- * Increment a numeric value atomically.
543
- *
544
- * @param key - Key name
545
- * @param by - Amount to increment (default: 1)
546
- * @returns New value
547
- *
548
- * @example
549
- * ```typescript
550
- * const views = await client.kvIncr('page:views');
551
- * const score = await client.kvIncr('user:123:score', 10);
552
- * ```
553
- */
554
- kvIncr(key: string, by?: number): Promise<number>;
555
- /**
556
- * Decrement a numeric value atomically.
557
- *
558
- * @param key - Key name
559
- * @param by - Amount to decrement (default: 1)
560
- * @returns New value
561
- */
562
- kvDecr(key: string, by?: number): Promise<number>;
563
- /**
564
- * Publish a message to a channel.
565
- *
566
- * @param channel - Channel name
567
- * @param message - Message data (any JSON-serializable data)
568
- * @returns Number of subscribers that received the message
569
- *
570
- * @example
571
- * ```typescript
572
- * const receivers = await client.publish('notifications', { type: 'alert', text: 'Hello!' });
573
- * console.log(`Message sent to ${receivers} subscribers`);
574
- * ```
575
- */
576
- publish(channel: string, message: unknown): Promise<number>;
577
- /**
578
- * Subscribe to channels.
579
- * Note: For real-time message delivery, use WebSocket/SSE connections.
580
- *
581
- * @param channels - Array of channel names
582
- * @returns List of subscribed channels
583
- *
584
- * @example
585
- * ```typescript
586
- * await client.pubsubSubscribe(['notifications', 'alerts']);
587
- * ```
588
- */
589
- pubsubSubscribe(channels: string[]): Promise<string[]>;
590
- /**
591
- * Subscribe to channels matching patterns (e.g., "events:*").
592
- *
593
- * @param patterns - Array of glob patterns
594
- * @returns List of subscribed patterns
595
- *
596
- * @example
597
- * ```typescript
598
- * await client.pubsubPsubscribe(['events:*', 'logs:*']);
599
- * ```
600
- */
601
- pubsubPsubscribe(patterns: string[]): Promise<string[]>;
602
- /**
603
- * Unsubscribe from channels.
604
- *
605
- * @param channels - Array of channel names
606
- * @returns List of unsubscribed channels
607
- */
608
- pubsubUnsubscribe(channels: string[]): Promise<string[]>;
609
- /**
610
- * Unsubscribe from patterns.
611
- *
612
- * @param patterns - Array of patterns
613
- * @returns List of unsubscribed patterns
614
- */
615
- pubsubPunsubscribe(patterns: string[]): Promise<string[]>;
616
- /**
617
- * List active channels (optionally matching a pattern).
618
- *
619
- * @param pattern - Optional glob pattern
620
- * @returns Array of active channel names
621
- *
622
- * @example
623
- * ```typescript
624
- * const allChannels = await client.pubsubChannels();
625
- * const eventChannels = await client.pubsubChannels('events:*');
626
- * ```
627
- */
628
- pubsubChannels(pattern?: string): Promise<string[]>;
629
- /**
630
- * Get subscriber counts for channels.
631
- *
632
- * @param channels - Array of channel names
633
- * @returns Array of [channel, count] tuples
634
- *
635
- * @example
636
- * ```typescript
637
- * const counts = await client.pubsubNumsub(['notifications', 'alerts']);
638
- * // [['notifications', 5], ['alerts', 2]]
639
- * ```
640
- */
641
- pubsubNumsub(channels: string[]): Promise<Array<[string, number]>>;
642
148
  }
643
149
  export default FlashQ;
644
150
  //# sourceMappingURL=index.d.ts.map