@reddb-io/client 1.36.10 → 1.36.11
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/README.md +6 -1
- package/index.browser.d.ts +14 -0
- package/index.d.ts +14 -0
- package/package.json +1 -1
- package/src/core/routing.js +1 -0
- package/src/queue.js +30 -9
- package/src/redwire-core.js +52 -0
package/README.md
CHANGED
|
@@ -149,7 +149,12 @@ The client follows the SDK Helper Spec for the shared JS/TS surface:
|
|
|
149
149
|
fields.
|
|
150
150
|
- `db.kv(collection?)` preserves exact keys, including namespaced keys such as
|
|
151
151
|
`characters:hansel`, and exposes `put/get/exists/delete/list`.
|
|
152
|
-
- `db.queue` exposes `push/pop/peek/len/purge`.
|
|
152
|
+
- `db.queue` exposes `push/pop/peek/len/purge/readWait/readWaitEntries`.
|
|
153
|
+
On RedWire, a single-message `readWait` uses the native async queue-wait
|
|
154
|
+
frame, so an idle consumer does not occupy an engine execution worker.
|
|
155
|
+
`readWaitEntries` preserves `message_id`, `consumer`, and `delivery_count`
|
|
156
|
+
for ACK/NACK handling. Multi-message waits retain the SQL compatibility
|
|
157
|
+
path until the wire protocol has an explicit terminal frame.
|
|
153
158
|
|
|
154
159
|
## Accepted URI schemes
|
|
155
160
|
|
package/index.browser.d.ts
CHANGED
|
@@ -231,6 +231,20 @@ export class QueueClient {
|
|
|
231
231
|
consumer: string,
|
|
232
232
|
options: { waitMs: number; group?: string; count?: number },
|
|
233
233
|
): Promise<unknown[]>
|
|
234
|
+
/** Like readWait(), but preserves message_id, consumer and delivery_count. */
|
|
235
|
+
readWaitEntries<T = unknown>(
|
|
236
|
+
queue: string,
|
|
237
|
+
consumer: string,
|
|
238
|
+
options: { waitMs: number; group?: string; count?: number },
|
|
239
|
+
): Promise<Array<QueueWaitEntry<T>>>
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface QueueWaitEntry<T = unknown> {
|
|
243
|
+
message_id: string | number
|
|
244
|
+
payload: T
|
|
245
|
+
consumer: string
|
|
246
|
+
delivery_count: number
|
|
247
|
+
[key: string]: unknown
|
|
234
248
|
}
|
|
235
249
|
|
|
236
250
|
/**
|
package/index.d.ts
CHANGED
|
@@ -233,6 +233,20 @@ export class QueueClient {
|
|
|
233
233
|
consumer: string,
|
|
234
234
|
options: { waitMs: number; group?: string; count?: number },
|
|
235
235
|
): Promise<unknown[]>
|
|
236
|
+
/** Like readWait(), but preserves message_id, consumer and delivery_count. */
|
|
237
|
+
readWaitEntries<T = unknown>(
|
|
238
|
+
queue: string,
|
|
239
|
+
consumer: string,
|
|
240
|
+
options: { waitMs: number; group?: string; count?: number },
|
|
241
|
+
): Promise<Array<QueueWaitEntry<T>>>
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface QueueWaitEntry<T = unknown> {
|
|
245
|
+
message_id: string | number
|
|
246
|
+
payload: T
|
|
247
|
+
consumer: string
|
|
248
|
+
delivery_count: number
|
|
249
|
+
[key: string]: unknown
|
|
236
250
|
}
|
|
237
251
|
|
|
238
252
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reddb-io/client",
|
|
3
|
-
"version": "1.36.
|
|
3
|
+
"version": "1.36.11",
|
|
4
4
|
"description": "Thin remote-only RedDB driver. Pure JavaScript — no install scripts, no native binary. Speaks RedWire/gRPC/HTTP. Embedded URIs (memory://, file://, red:///path) are rejected — use @reddb-io/sdk for those.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
package/src/core/routing.js
CHANGED
package/src/queue.js
CHANGED
|
@@ -39,17 +39,27 @@ export class QueueClient {
|
|
|
39
39
|
})
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
// Live `QUEUE READ … WAIT <ms>` helper (PRD #718 / #725). Same
|
|
43
|
-
// contract as drivers/js: required `waitMs`, timeout returns empty
|
|
44
|
-
// array, cancellation/cap rejection surface as transport errors.
|
|
45
42
|
async readWait(queue, consumer, options = {}) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
return queuePayloads({ rows: await this.readWaitEntries(queue, consumer, options) })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// RedWire's QueueWaitOpen parks on the async wait registry instead of
|
|
47
|
+
// occupying an engine execution slot for the wait duration. The v1 frame
|
|
48
|
+
// has no terminal marker after a multi-message delivery, so COUNT != 1
|
|
49
|
+
// deliberately stays on the SQL compatibility path.
|
|
50
|
+
async readWaitEntries(queue, consumer, options = {}) {
|
|
51
|
+
const request = buildQueueReadWaitRequest(queue, consumer, options)
|
|
52
|
+
if (this.client.nativeQueueWait === true && request.count === 1) {
|
|
53
|
+
const { sql: _, ...params } = request
|
|
54
|
+
const result = await this.client.call('queue_wait', params)
|
|
55
|
+
return queueRows(result)
|
|
56
|
+
}
|
|
57
|
+
const result = await this.client.call('query', { sql: request.sql })
|
|
58
|
+
return queueRows(result)
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
function
|
|
62
|
+
function buildQueueReadWaitRequest(queue, consumer, options) {
|
|
53
63
|
const { waitMs, group = null, count = null } = options ?? {}
|
|
54
64
|
if (!Number.isInteger(waitMs) || waitMs < 0) {
|
|
55
65
|
throw new RedDBError(
|
|
@@ -61,7 +71,14 @@ function buildQueueReadWaitSql(queue, consumer, options) {
|
|
|
61
71
|
const c = queueIdentifier(consumer)
|
|
62
72
|
const g = group != null ? ` GROUP ${queueIdentifier(group)}` : ''
|
|
63
73
|
const n = count != null ? queueCount(count) : ''
|
|
64
|
-
return
|
|
74
|
+
return {
|
|
75
|
+
queue: q,
|
|
76
|
+
group: group != null ? queueIdentifier(group) : null,
|
|
77
|
+
consumer: c,
|
|
78
|
+
count: count ?? 1,
|
|
79
|
+
waitMs,
|
|
80
|
+
sql: `QUEUE READ ${q}${g} CONSUMER ${c}${n} WAIT ${waitMs}ms`,
|
|
81
|
+
}
|
|
65
82
|
}
|
|
66
83
|
|
|
67
84
|
function queueIdentifier(value) {
|
|
@@ -118,5 +135,9 @@ function queueStringLiteral(value) {
|
|
|
118
135
|
}
|
|
119
136
|
|
|
120
137
|
function queuePayloads(result) {
|
|
121
|
-
return
|
|
138
|
+
return queueRows(result).map((row) => row.payload)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function queueRows(result) {
|
|
142
|
+
return Array.isArray(result?.rows) ? result.rows : []
|
|
122
143
|
}
|
package/src/redwire-core.js
CHANGED
|
@@ -59,6 +59,9 @@ export const MessageKind = Object.freeze({
|
|
|
59
59
|
StreamChunk: 0x2B,
|
|
60
60
|
StreamError: 0x2C,
|
|
61
61
|
StreamCancel: 0x2D,
|
|
62
|
+
QueueWaitOpen: 0x2E,
|
|
63
|
+
QueueEventPush: 0x2F,
|
|
64
|
+
QueueWaitTimeout: 0x30,
|
|
62
65
|
})
|
|
63
66
|
|
|
64
67
|
export const Features = Object.freeze({ PARAMS: 0x0000_0001, TOPOLOGY: 0x0000_0002 })
|
|
@@ -238,6 +241,7 @@ export class RedWireClient {
|
|
|
238
241
|
this.serverFeatures = serverFeatures >>> 0
|
|
239
242
|
// RedWire consumes typed views directly; JSON transports use envelopes.
|
|
240
243
|
this.binaryQueryParams = true
|
|
244
|
+
this.nativeQueueWait = true
|
|
241
245
|
this.nextCorr = 1n
|
|
242
246
|
this.nextStream = 1
|
|
243
247
|
this.closed = false
|
|
@@ -267,6 +271,7 @@ export class RedWireClient {
|
|
|
267
271
|
return decodeTopology(response.payload)
|
|
268
272
|
}
|
|
269
273
|
if (method === 'query') return this.#query(params.sql ?? '', params.params)
|
|
274
|
+
if (method === 'queue_wait') return this.#queueWait(params)
|
|
270
275
|
if (method === 'insert') return this.#insert({ collection: params.collection, payload: params.payload })
|
|
271
276
|
if (method === 'bulk_insert') return this.#insert({ collection: params.collection, payloads: params.payloads })
|
|
272
277
|
if (method === 'bulk_insert_binary') {
|
|
@@ -400,6 +405,53 @@ export class RedWireClient {
|
|
|
400
405
|
)
|
|
401
406
|
}
|
|
402
407
|
|
|
408
|
+
async #queueWait(params) {
|
|
409
|
+
if (params.count !== 1) {
|
|
410
|
+
throw new RedDBError(
|
|
411
|
+
'INVALID_QUEUE_WAIT_COUNT',
|
|
412
|
+
'native RedWire queue wait requires count=1',
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
const streamId = this.#stream()
|
|
416
|
+
const corr = this.#corr()
|
|
417
|
+
const payload = {
|
|
418
|
+
queue: params.queue,
|
|
419
|
+
consumer: params.consumer,
|
|
420
|
+
count: 1,
|
|
421
|
+
wait_ms: params.waitMs,
|
|
422
|
+
}
|
|
423
|
+
if (params.group != null) payload.group = params.group
|
|
424
|
+
await this.#writeStreamFrame(MessageKind.QueueWaitOpen, corr, jsonBytes(payload), streamId)
|
|
425
|
+
|
|
426
|
+
const response = await this.reader.next()
|
|
427
|
+
if (response.streamId !== streamId || response.correlationId !== corr) {
|
|
428
|
+
throw new RedDBError(
|
|
429
|
+
'QUEUE_WAIT_PROTOCOL',
|
|
430
|
+
`queue wait response did not match stream ${streamId} / correlation ${corr}`,
|
|
431
|
+
)
|
|
432
|
+
}
|
|
433
|
+
if (response.kind === MessageKind.QueueEventPush) {
|
|
434
|
+
const message = jsonOf(response.payload)
|
|
435
|
+
if (message == null || typeof message !== 'object' || Array.isArray(message)) {
|
|
436
|
+
throw new RedDBError('QUEUE_WAIT_PROTOCOL', 'QueueEventPush payload must be a JSON object')
|
|
437
|
+
}
|
|
438
|
+
return { rows: [message] }
|
|
439
|
+
}
|
|
440
|
+
if (response.kind === MessageKind.QueueWaitTimeout) return { rows: [] }
|
|
441
|
+
if (response.kind === MessageKind.StreamError || response.kind === MessageKind.Error) {
|
|
442
|
+
const error = jsonOf(response.payload) ?? {}
|
|
443
|
+
throw new RedDBError(
|
|
444
|
+
error.code || 'QUEUE_WAIT_ERROR',
|
|
445
|
+
error.message || new TextDecoder().decode(response.payload),
|
|
446
|
+
error,
|
|
447
|
+
)
|
|
448
|
+
}
|
|
449
|
+
throw new RedDBError(
|
|
450
|
+
'QUEUE_WAIT_PROTOCOL',
|
|
451
|
+
`expected QueueEventPush/QueueWaitTimeout/StreamError, got ${KIND_NAME[response.kind] ?? response.kind}`,
|
|
452
|
+
)
|
|
453
|
+
}
|
|
454
|
+
|
|
403
455
|
async #ping() {
|
|
404
456
|
const corr = this.#corr()
|
|
405
457
|
await writeFrame(this.socket, MessageKind.Ping, corr, new Uint8Array())
|