@reddb-io/sdk 1.0.4 → 1.0.7

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 CHANGED
@@ -224,6 +224,7 @@ export class RedDB {
224
224
  readonly vault: (collection?: string) => VaultClient
225
225
 
226
226
  query(sql: string): Promise<QueryResult>
227
+ query(sql: string, params: Array<number | string | null>): Promise<QueryResult>
227
228
  insert(collection: string, payload: Record<string, unknown>): Promise<InsertResult>
228
229
  bulkInsert(
229
230
  collection: string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reddb-io/sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
4
4
  "description": "Official RedDB driver — talks the native RedWire TCP protocol (mTLS), HTTP, gRPC bridge, or embedded stdio JSON-RPC. Works in Node 18+, Bun and Deno.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/postinstall.js CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  import { createRequire } from 'node:module'
20
20
  import { fileURLToPath } from 'node:url'
21
- import { dirname, join } from 'node:path'
21
+ import { dirname, join, sep } from 'node:path'
22
22
  import { existsSync, mkdirSync, writeFileSync, chmodSync } from 'node:fs'
23
23
 
24
24
  import { fetchReleaseAsset } from './src/internal/asset-fetcher/index.js'
@@ -34,16 +34,66 @@ if (process.env.REDDB_SKIP_POSTINSTALL === '1') {
34
34
  process.exit(0)
35
35
  }
36
36
 
37
- main().catch((err) => {
38
- process.stderr.write(
39
- `reddb: postinstall could not download the binary (${err.message}).\n` +
40
- ` The package will still install. To use the driver you can:\n` +
41
- ` - set REDDB_BINARY_PATH=/path/to/red\n` +
42
- ` - or install the binary manually from https://github.com/${DEFAULT_REPO}/releases\n`,
37
+ // Workspace-local install detection. When this file's resolved path is not
38
+ // inside a `node_modules` tree we're running from a fresh checkout of the
39
+ // reddb monorepo (or a fork), where `package.json` may already carry a
40
+ // version whose GitHub Release has not been built yet and where the
41
+ // developer typically builds `red` with `cargo build` anyway. Skip the
42
+ // download with a clear pointer; release flows still work because the npm
43
+ // tarball, when installed, lives under `node_modules/`.
44
+ if (!HERE.includes(`${sep}node_modules${sep}`)) {
45
+ process.stdout.write(
46
+ 'reddb: skipping postinstall — running from a workspace checkout (no node_modules/).\n' +
47
+ ' If you need the binary, either:\n' +
48
+ ' - cargo build --release --bin red && export REDDB_BIN="$PWD/target/release/red"\n' +
49
+ ' - or: curl -fsSL https://raw.githubusercontent.com/reddb-io/reddb/main/install.sh | bash\n' +
50
+ ' Set REDDB_SKIP_POSTINSTALL=1 to silence this message.\n',
43
51
  )
44
52
  process.exit(0)
53
+ }
54
+
55
+ main().catch((err) => {
56
+ process.stderr.write(formatFailure(err))
57
+ process.exit(0)
45
58
  })
46
59
 
60
+ function formatFailure(err) {
61
+ const repo = process.env.REDDB_POSTINSTALL_REPO || DEFAULT_REPO
62
+ if (err && err.code === 'UNSUPPORTED_PLATFORM') {
63
+ return (
64
+ `reddb: no prebuilt red binary for ${process.platform}/${process.arch}.\n` +
65
+ ` Options:\n` +
66
+ ` - build from source: https://github.com/${repo}#build-from-source\n` +
67
+ ` - or set REDDB_BIN=/path/to/red to point at one you compiled.\n`
68
+ )
69
+ }
70
+ if (err && err.code === 'ASSET_NOT_FOUND') {
71
+ return (
72
+ `reddb: release asset not found at ${err.url}\n` +
73
+ ` Common cause: the GitHub Release for this SDK version has not\n` +
74
+ ` been published yet (or your platform's binary was not produced\n` +
75
+ ` for that release). To unblock without reinstalling:\n` +
76
+ ` 1. Install the latest stable red via the official installer\n` +
77
+ ` and point the SDK at it:\n` +
78
+ ` curl -fsSL https://raw.githubusercontent.com/${repo}/main/install.sh | bash\n` +
79
+ ` export REDDB_BIN="$(command -v red)"\n` +
80
+ ` 2. Or pull a specific tag explicitly and re-run postinstall:\n` +
81
+ ` REDDB_POSTINSTALL_VERSION=v1.0.5 npm rebuild @reddb-io/sdk\n` +
82
+ ` 3. Or skip the download entirely and provide the binary yourself:\n` +
83
+ ` REDDB_SKIP_POSTINSTALL=1 (re-install), then export REDDB_BIN=…\n` +
84
+ ` Releases: https://github.com/${repo}/releases\n`
85
+ )
86
+ }
87
+ return (
88
+ `reddb: postinstall could not download the binary (${err && err.message}).\n` +
89
+ ` The package itself still installs. To use the driver:\n` +
90
+ ` - run the installer: curl -fsSL https://raw.githubusercontent.com/${repo}/main/install.sh | bash\n` +
91
+ ` then: export REDDB_BIN="$(command -v red)"\n` +
92
+ ` - or download manually from https://github.com/${repo}/releases\n` +
93
+ ` - or set REDDB_BIN=/path/to/red.\n`
94
+ )
95
+ }
96
+
47
97
  async function main() {
48
98
  const repo = process.env.REDDB_POSTINSTALL_REPO || DEFAULT_REPO
49
99
  const tag = process.env.REDDB_POSTINSTALL_VERSION
package/src/index.js CHANGED
@@ -167,6 +167,17 @@ export async function connect(uri, options = {}) {
167
167
  )
168
168
  }
169
169
 
170
+ // Coerce a JS query parameter to a JSON-serializable shape the server
171
+ // understands. The tracer scope (#355) lifts vector params: `Float32Array`
172
+ // and `Float64Array` round-trip as plain JSON arrays of numbers, which
173
+ // the embedded stdio handler maps to `Value::Vector`.
174
+ function serializeParam(value) {
175
+ if (value instanceof Float32Array || value instanceof Float64Array) {
176
+ return Array.from(value)
177
+ }
178
+ return value
179
+ }
180
+
170
181
  function embeddedArgs(parsed) {
171
182
  if (parsed.path) return ['rpc', '--stdio', '--path', parsed.path]
172
183
  return ['rpc', '--stdio']
@@ -344,9 +355,27 @@ export class RedDB {
344
355
  this.vault = (collection = 'red.vault') => new VaultClient(client, collection)
345
356
  }
346
357
 
347
- /** Execute a SQL query. Returns `{ statement, affected, columns, rows }`. */
348
- query(sql) {
349
- return this.client.call('query', { sql })
358
+ /**
359
+ * Execute a SQL query.
360
+ *
361
+ * Two signatures:
362
+ * - `query(sql)` — legacy single-arg form.
363
+ * - `query(sql, params)` — positional `$N` bind values. `params` is
364
+ * an array (JS scalars: number | string | null map to engine
365
+ * int/float / text / null). Indices in the SQL are 1-based
366
+ * (`$1`, `$2`, ...), `params` is 0-based JS-style.
367
+ *
368
+ * Returns `{ statement, affected, columns, rows }`.
369
+ */
370
+ query(sql, params) {
371
+ if (params === undefined) {
372
+ return this.client.call('query', { sql })
373
+ }
374
+ if (!Array.isArray(params)) {
375
+ throw new TypeError('query: `params` must be an array')
376
+ }
377
+ const wireParams = params.map(serializeParam)
378
+ return this.client.call('query', { sql, params: wireParams })
350
379
  }
351
380
 
352
381
  /** Insert one row. Returns `{ affected, id? }`. */