@reddb-io/sdk 1.22.0-rc.249 → 1.22.0-rc.251
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 -0
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/queue.js +23 -3
package/README.md
CHANGED
|
@@ -358,6 +358,12 @@ is the plural `db.queues`; `db.queue` remains as an alias.
|
|
|
358
358
|
```js
|
|
359
359
|
await db.queues.create('jobs') // CREATE QUEUE IF NOT EXISTS (idempotent)
|
|
360
360
|
await db.queues.push('jobs', { task: 'ship' })
|
|
361
|
+
await db.queues.push('jobs', { task: 'email', orderId: 42 }, { dedup: 'outbox:email:42' })
|
|
362
|
+
await db.queues.push(
|
|
363
|
+
'jobs',
|
|
364
|
+
{ task: 'rebuild_account', accountId: 'acct_123' },
|
|
365
|
+
{ key: 'acct_123' },
|
|
366
|
+
)
|
|
361
367
|
await db.queues.peek('jobs') // does NOT decrement length
|
|
362
368
|
await db.queues.pop('jobs') // empty queue → [] (never NOT_FOUND)
|
|
363
369
|
await db.queues.len('jobs')
|
package/index.d.ts
CHANGED
|
@@ -292,7 +292,7 @@ export class QueueClient {
|
|
|
292
292
|
push(
|
|
293
293
|
queue: string,
|
|
294
294
|
value: unknown,
|
|
295
|
-
options?: { priority?: number },
|
|
295
|
+
options?: { priority?: number; key?: string; dedup?: string; delay?: string; at?: number },
|
|
296
296
|
): Promise<QueryResult>
|
|
297
297
|
pop(queue: string, count?: number): Promise<unknown[]>
|
|
298
298
|
peek(queue: string, count?: number): Promise<unknown[]>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reddb-io/sdk",
|
|
3
|
-
"version": "1.22.0-rc.
|
|
3
|
+
"version": "1.22.0-rc.251",
|
|
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
|
@@ -14,9 +14,9 @@ export class QueueClient {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
push(queue, value, options = {}) {
|
|
17
|
-
const
|
|
17
|
+
const suffix = queuePushOptions(options)
|
|
18
18
|
return this.client.call('query', {
|
|
19
|
-
sql: `QUEUE PUSH ${queueIdentifier(queue)} ${queueValueLiteral(value)}${
|
|
19
|
+
sql: `QUEUE PUSH ${queueIdentifier(queue)} ${queueValueLiteral(value)}${suffix}`,
|
|
20
20
|
})
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -103,13 +103,33 @@ function queuePriority(priority) {
|
|
|
103
103
|
return String(priority)
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
function queuePushOptions(options) {
|
|
107
|
+
if (options.key != null && (options.delay != null || options.at != null)) {
|
|
108
|
+
throw new RedDBError(
|
|
109
|
+
'INVALID_ARGUMENT',
|
|
110
|
+
'QUEUE PUSH KEY cannot be combined with DELAY / AVAILABLE AT',
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
let suffix = ''
|
|
114
|
+
if (options.priority != null) suffix += ` PRIORITY ${queuePriority(options.priority)}`
|
|
115
|
+
if (options.key != null) suffix += ` KEY ${queueStringLiteral(options.key)}`
|
|
116
|
+
if (options.dedup != null) suffix += ` DEDUP ${queueStringLiteral(options.dedup)}`
|
|
117
|
+
if (options.delay != null) suffix += ` DELAY ${options.delay}`
|
|
118
|
+
if (options.at != null) suffix += ` AVAILABLE AT ${options.at}`
|
|
119
|
+
return suffix
|
|
120
|
+
}
|
|
121
|
+
|
|
106
122
|
function queueValueLiteral(value) {
|
|
107
123
|
if (typeof value === 'number' || typeof value === 'boolean') return String(value)
|
|
108
124
|
if (value == null) return 'NULL'
|
|
109
|
-
if (typeof value === 'string') return
|
|
125
|
+
if (typeof value === 'string') return queueStringLiteral(value)
|
|
110
126
|
return JSON.stringify(value)
|
|
111
127
|
}
|
|
112
128
|
|
|
129
|
+
function queueStringLiteral(value) {
|
|
130
|
+
return `'${String(value).replace(/'/g, "''")}'`
|
|
131
|
+
}
|
|
132
|
+
|
|
113
133
|
function queuePayloads(result) {
|
|
114
134
|
return Array.isArray(result?.rows) ? result.rows.map((row) => row.payload) : []
|
|
115
135
|
}
|