@reddb-io/client 1.22.0 → 1.23.0-rc.302

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 CHANGED
@@ -58,6 +58,14 @@ const kv = db.kv('settings')
58
58
  await kv.put('characters:hansel', 'crumbs')
59
59
  console.log(await kv.get('characters:hansel'))
60
60
 
61
+ await db.queues.create('jobs')
62
+ await db.queues.push('jobs', { task: 'email', orderId: 42 }, { dedup: 'outbox:email:42' })
63
+ await db.queues.push(
64
+ 'jobs',
65
+ { task: 'rebuild_account', accountId: 'acct_123' },
66
+ { key: 'acct_123' },
67
+ )
68
+
61
69
  await db.close()
62
70
  ```
63
71
 
@@ -183,7 +183,7 @@ export class QueueClient {
183
183
  push(
184
184
  queue: string,
185
185
  value: unknown,
186
- options?: { priority?: number },
186
+ options?: { priority?: number; key?: string; dedup?: string; delay?: string; at?: number },
187
187
  ): Promise<QueryResult>
188
188
  pop(queue: string, count?: number): Promise<unknown[]>
189
189
  peek(queue: string, count?: number): Promise<unknown[]>
package/index.d.ts CHANGED
@@ -179,7 +179,7 @@ export class QueueClient {
179
179
  push(
180
180
  queue: string,
181
181
  value: unknown,
182
- options?: { priority?: number },
182
+ options?: { priority?: number; key?: string; dedup?: string; delay?: string; at?: number },
183
183
  ): Promise<QueryResult>
184
184
  pop(queue: string, count?: number): Promise<unknown[]>
185
185
  peek(queue: string, count?: number): Promise<unknown[]>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reddb-io/client",
3
- "version": "1.22.0",
3
+ "version": "1.23.0-rc.302",
4
4
  "description": "Thin remote-only RedDB driver. Downloads the `red_client` binary on install. 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/queue.js CHANGED
@@ -6,9 +6,9 @@ export class QueueClient {
6
6
  }
7
7
 
8
8
  push(queue, value, options = {}) {
9
- const priority = options.priority != null ? ` PRIORITY ${queuePriority(options.priority)}` : ''
9
+ const suffix = queuePushOptions(options)
10
10
  return this.client.call('query', {
11
- sql: `QUEUE PUSH ${queueIdentifier(queue)} ${queueValueLiteral(value)}${priority}`,
11
+ sql: `QUEUE PUSH ${queueIdentifier(queue)} ${queueValueLiteral(value)}${suffix}`,
12
12
  })
13
13
  }
14
14
 
@@ -90,13 +90,33 @@ function queuePriority(priority) {
90
90
  return String(priority)
91
91
  }
92
92
 
93
+ function queuePushOptions(options) {
94
+ if (options.key != null && (options.delay != null || options.at != null)) {
95
+ throw new RedDBError(
96
+ 'INVALID_ARGUMENT',
97
+ 'QUEUE PUSH KEY cannot be combined with DELAY / AVAILABLE AT',
98
+ )
99
+ }
100
+ let suffix = ''
101
+ if (options.priority != null) suffix += ` PRIORITY ${queuePriority(options.priority)}`
102
+ if (options.key != null) suffix += ` KEY ${queueStringLiteral(options.key)}`
103
+ if (options.dedup != null) suffix += ` DEDUP ${queueStringLiteral(options.dedup)}`
104
+ if (options.delay != null) suffix += ` DELAY ${options.delay}`
105
+ if (options.at != null) suffix += ` AVAILABLE AT ${options.at}`
106
+ return suffix
107
+ }
108
+
93
109
  function queueValueLiteral(value) {
94
110
  if (typeof value === 'number' || typeof value === 'boolean') return String(value)
95
111
  if (value == null) return 'NULL'
96
- if (typeof value === 'string') return `'${value.replace(/'/g, "''")}'`
112
+ if (typeof value === 'string') return queueStringLiteral(value)
97
113
  return JSON.stringify(value)
98
114
  }
99
115
 
116
+ function queueStringLiteral(value) {
117
+ return `'${String(value).replace(/'/g, "''")}'`
118
+ }
119
+
100
120
  function queuePayloads(result) {
101
121
  return Array.isArray(result?.rows) ? result.rows.map((row) => row.payload) : []
102
122
  }