@reddb-io/sdk 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +12 -0
- package/package.json +1 -1
- package/src/queue.js +29 -0
package/index.d.ts
CHANGED
|
@@ -298,6 +298,18 @@ export class QueueClient {
|
|
|
298
298
|
peek(queue: string, count?: number): Promise<unknown[]>
|
|
299
299
|
len(queue: string): Promise<number>
|
|
300
300
|
purge(queue: string): Promise<QueryResult>
|
|
301
|
+
/**
|
|
302
|
+
* Live `QUEUE READ … WAIT <ms>` helper (PRD #718 / #725). Blocks
|
|
303
|
+
* until a message is available, the wait budget elapses, or the
|
|
304
|
+
* server cancels. Timeout returns an empty array — same shape as
|
|
305
|
+
* an empty pop, never throws. `waitMs` is required; there is no
|
|
306
|
+
* infinite-wait default.
|
|
307
|
+
*/
|
|
308
|
+
readWait(
|
|
309
|
+
queue: string,
|
|
310
|
+
consumer: string,
|
|
311
|
+
options: { waitMs: number; group?: string; count?: number },
|
|
312
|
+
): Promise<unknown[]>
|
|
301
313
|
}
|
|
302
314
|
|
|
303
315
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reddb-io/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Official embedded RedDB SDK — launches a local red binary over stdio JSON-RPC. Use @reddb-io/client for remote HTTP, gRPC, and RedWire.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/queue.js
CHANGED
|
@@ -46,6 +46,35 @@ export class QueueClient {
|
|
|
46
46
|
sql: `QUEUE PURGE ${queueIdentifier(queue)}`,
|
|
47
47
|
})
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
// Live `QUEUE READ … WAIT <ms>` helper (PRD #718 / #725). Blocks until
|
|
51
|
+
// a message is available for `consumer` on `queue` (optionally scoped
|
|
52
|
+
// to `group`), the wait budget elapses, or the server cancels.
|
|
53
|
+
//
|
|
54
|
+
// Timeout returns the same empty array as a non-waiting empty pop —
|
|
55
|
+
// never an exception. `waitMs` is required; there is no infinite-wait
|
|
56
|
+
// default. Server-side cancellation, transport cancellation, and cap
|
|
57
|
+
// rejection surface as RedDBErrors from the transport path.
|
|
58
|
+
async readWait(queue, consumer, options = {}) {
|
|
59
|
+
const sql = buildQueueReadWaitSql(queue, consumer, options)
|
|
60
|
+
const result = await this.client.call('query', { sql })
|
|
61
|
+
return queuePayloads(result)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function buildQueueReadWaitSql(queue, consumer, options) {
|
|
66
|
+
const { waitMs, group = null, count = null } = options ?? {}
|
|
67
|
+
if (!Number.isInteger(waitMs) || waitMs < 0) {
|
|
68
|
+
throw new RedDBError(
|
|
69
|
+
'INVALID_QUEUE_WAIT',
|
|
70
|
+
'queue readWait requires an explicit non-negative integer waitMs (no infinite wait)',
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
const q = queueIdentifier(queue)
|
|
74
|
+
const c = queueIdentifier(consumer)
|
|
75
|
+
const g = group != null ? ` GROUP ${queueIdentifier(group)}` : ''
|
|
76
|
+
const n = count != null ? queueCount(count) : ''
|
|
77
|
+
return `QUEUE READ ${q}${g} CONSUMER ${c}${n} WAIT ${waitMs}ms`
|
|
49
78
|
}
|
|
50
79
|
|
|
51
80
|
function queueIdentifier(value) {
|