@loradb/lora-wasm 0.5.6 → 0.8.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/README.md +76 -34
- package/dist/decode.d.ts +29 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/decode.js +338 -0
- package/dist/decode.js.map +1 -0
- package/dist/index.d.ts +21 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -37
- package/dist/index.js.map +1 -1
- package/dist/loader-node.d.ts +1 -1
- package/dist/snapshot.d.ts +49 -16
- package/dist/snapshot.d.ts.map +1 -1
- package/dist/snapshot.js +36 -54
- package/dist/snapshot.js.map +1 -1
- package/dist/types.d.ts +81 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -2
- package/dist/types.js.map +1 -1
- package/dist/worker-client.d.ts +20 -20
- package/dist/worker-client.d.ts.map +1 -1
- package/dist/worker-client.js +32 -22
- package/dist/worker-client.js.map +1 -1
- package/dist/worker-protocol.d.ts +5 -2
- package/dist/worker-protocol.d.ts.map +1 -1
- package/dist/worker.js +18 -10
- package/dist/worker.js.map +1 -1
- package/package.json +5 -5
- package/pkg-bundler/README.md +76 -34
- package/pkg-bundler/lora_wasm.d.ts +37 -10
- package/pkg-bundler/lora_wasm_bg.js +173 -26
- package/pkg-bundler/lora_wasm_bg.wasm +0 -0
- package/pkg-bundler/lora_wasm_bg.wasm.d.ts +5 -2
- package/pkg-bundler/package.json +1 -1
- package/pkg-node/README.md +76 -34
- package/pkg-node/lora_wasm.d.ts +37 -10
- package/pkg-node/lora_wasm.js +173 -26
- package/pkg-node/lora_wasm_bg.wasm +0 -0
- package/pkg-node/lora_wasm_bg.wasm.d.ts +5 -2
- package/pkg-node/package.json +1 -1
- package/pkg-web/README.md +76 -34
- package/pkg-web/lora_wasm.d.ts +42 -12
- package/pkg-web/lora_wasm.js +156 -26
- package/pkg-web/lora_wasm_bg.wasm +0 -0
- package/pkg-web/lora_wasm_bg.wasm.d.ts +5 -2
- package/pkg-web/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# lora-wasm
|
|
2
2
|
|
|
3
|
-
WebAssembly bindings for the [Lora](
|
|
3
|
+
WebAssembly bindings for the [Lora](../../../README.md) in-memory graph
|
|
4
4
|
database. The package is designed for browsers and Node.js and exposes a
|
|
5
5
|
**strongly typed, async-facing API** that keeps the main thread responsive:
|
|
6
6
|
heavy query work can run inside a Web Worker while your UI code simply awaits
|
|
7
7
|
the result.
|
|
8
8
|
|
|
9
|
-
> **
|
|
9
|
+
> **Package:** `@loradb/lora-wasm`.
|
|
10
10
|
|
|
11
11
|
## Build
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
cd crates/lora-wasm
|
|
14
|
+
cd crates/bindings/lora-wasm
|
|
15
15
|
npm install
|
|
16
16
|
npm run build # wasm-pack (node + bundler) + tsc
|
|
17
17
|
npm test # vitest
|
|
@@ -52,7 +52,7 @@ fails during startup, the package emits one `console.warn` and falls back to
|
|
|
52
52
|
the in-process WASM engine so the app can still run.
|
|
53
53
|
|
|
54
54
|
```ts
|
|
55
|
-
import { createDatabase, isNode } from "lora-wasm";
|
|
55
|
+
import { createDatabase, isNode } from "@loradb/lora-wasm";
|
|
56
56
|
|
|
57
57
|
const db = await createDatabase(); // Worker-backed in browsers when possible
|
|
58
58
|
await db.execute("CREATE (:Person {name: $n})", { n: "Alice" });
|
|
@@ -63,6 +63,37 @@ for (const row of r.rows) {
|
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
### Explain & Profile
|
|
67
|
+
|
|
68
|
+
`db.explain()` and `db.profile()` are first-class methods alongside
|
|
69
|
+
`db.execute()`. They are intentionally *separate calls*, not a flag
|
|
70
|
+
on `execute()`, so plan inspection and runtime metrics must be
|
|
71
|
+
requested explicitly.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const plan = await db.explain(
|
|
75
|
+
"MATCH (p:Person) WHERE p.name = $name RETURN p",
|
|
76
|
+
{ name: "Alice" },
|
|
77
|
+
);
|
|
78
|
+
console.log(plan.shape); // "readOnly"
|
|
79
|
+
console.log(plan.tree.operator);
|
|
80
|
+
|
|
81
|
+
const profile = await db.profile(
|
|
82
|
+
"MATCH (p:Person) WHERE p.name = $name RETURN p",
|
|
83
|
+
{ name: "Alice" },
|
|
84
|
+
);
|
|
85
|
+
console.log(profile.metrics.totalElapsedNs);
|
|
86
|
+
console.log(profile.metrics.perOperator); // per-step inclusive timing
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`explain()` never invokes the executor — calling it on a mutating
|
|
90
|
+
query (`CREATE`, `MERGE`, `SET`, `DELETE`, `REMOVE`) leaves the graph
|
|
91
|
+
untouched.
|
|
92
|
+
|
|
93
|
+
> **`profile()` executes the query for real.** Mutating queries
|
|
94
|
+
> produce the same side effects as `execute()`. Use `explain()` to
|
|
95
|
+
> inspect a mutating plan without running it.
|
|
96
|
+
|
|
66
97
|
To force the in-process engine:
|
|
67
98
|
|
|
68
99
|
```ts
|
|
@@ -84,7 +115,7 @@ const db = await createDatabase({ warnOnFallback: false });
|
|
|
84
115
|
### 2. Explicit main-thread WASM
|
|
85
116
|
|
|
86
117
|
```ts
|
|
87
|
-
import { createMainThreadDatabase } from "lora-wasm";
|
|
118
|
+
import { createMainThreadDatabase } from "@loradb/lora-wasm";
|
|
88
119
|
|
|
89
120
|
const db = await createMainThreadDatabase();
|
|
90
121
|
```
|
|
@@ -116,35 +147,36 @@ useful for tests and for swapping execution backends behind the same API.
|
|
|
116
147
|
|
|
117
148
|
## Snapshots
|
|
118
149
|
|
|
119
|
-
WASM has no filesystem access, so
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
`
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
150
|
+
WASM has no filesystem access, so snapshots never accept string paths.
|
|
151
|
+
`saveSnapshot()` defaults to `Uint8Array`, and can also return `ArrayBuffer`,
|
|
152
|
+
`Blob`, `Response`, `ReadableStream`, or an object `URL`. `loadSnapshot`
|
|
153
|
+
accepts `URL`, `Uint8Array`, `ArrayBuffer`, `Blob`, `Response`, and web
|
|
154
|
+
`ReadableStream<Uint8Array | ArrayBuffer>`. The bytes use the database
|
|
155
|
+
snapshot codec (`LORACOL1`) and can be loaded by native LoraDB. Older store
|
|
156
|
+
snapshots use the current `LORACOL1` columnar format.
|
|
157
|
+
Snapshot bytes are uncompressed by default; pass `{ compression: "gzip" }` or
|
|
158
|
+
`{ compression: { format: "gzip", level: 1 } }` to save smaller
|
|
159
|
+
WASM-portable snapshots. Gzip levels `0..9` are supported; level `1` is the
|
|
160
|
+
fast default.
|
|
127
161
|
|
|
128
162
|
```ts
|
|
129
|
-
import { createDatabase } from "lora-wasm";
|
|
163
|
+
import { createDatabase } from "@loradb/lora-wasm";
|
|
130
164
|
|
|
131
165
|
const db = await createDatabase();
|
|
132
166
|
await db.execute("CREATE (:Person {name: 'Alice'})");
|
|
133
167
|
|
|
134
|
-
const bytes = await db.
|
|
135
|
-
const
|
|
136
|
-
const blob = await db.saveSnapshot({ format: "blob" });
|
|
137
|
-
await db.saveSnapshot({ format: "
|
|
168
|
+
const bytes = await db.saveSnapshot();
|
|
169
|
+
const compressed = await db.saveSnapshot({ compression: "gzip" });
|
|
170
|
+
const blob = await db.saveSnapshot({ format: "blob", compression: "gzip" });
|
|
171
|
+
const response = await db.saveSnapshot({ format: "response" });
|
|
138
172
|
|
|
139
173
|
await db.loadSnapshot(bytes);
|
|
174
|
+
await db.loadSnapshot(compressed);
|
|
140
175
|
await db.loadSnapshot(blob);
|
|
141
|
-
await db.loadSnapshot(
|
|
176
|
+
await db.loadSnapshot(response);
|
|
142
177
|
await db.loadSnapshot(new URL("/graph.lorasnap", location.href));
|
|
143
178
|
```
|
|
144
179
|
|
|
145
|
-
`loadSnapshotFromBytes(bytes)` remains available for the narrow
|
|
146
|
-
`Uint8Array`-only path.
|
|
147
|
-
|
|
148
180
|
## Typed value model
|
|
149
181
|
|
|
150
182
|
| TS type | Runtime shape |
|
|
@@ -171,31 +203,42 @@ Helper constructors: `date`, `time`, `datetime`, `localtime`, `localdatetime`,
|
|
|
171
203
|
`isNode`, `isRelationship`, `isPath`, `isPoint`, `isTemporal`.
|
|
172
204
|
|
|
173
205
|
> `distance()` on WGS-84-3D points ignores `height`. See
|
|
174
|
-
> [functions reference](
|
|
206
|
+
> [functions reference](../../../apps/loradb.com/docs/functions/overview.md) for the spatial
|
|
175
207
|
> reference and out-of-scope operations.
|
|
176
208
|
|
|
177
209
|
## Errors
|
|
178
210
|
|
|
179
|
-
`db.execute(...)` and the worker client throw `LoraError` with a
|
|
180
|
-
`code
|
|
211
|
+
`db.execute(...)` and the worker client throw `LoraError` with a
|
|
212
|
+
narrowed `code` from the `LoraErrorCode` union — these mirror
|
|
213
|
+
`lora_database::LoraErrorCode` 1:1, plus `WORKER_ERROR` and `UNKNOWN`.
|
|
181
214
|
|
|
182
|
-
|
|
183
|
-
|
|
215
|
+
Common ones:
|
|
216
|
+
|
|
217
|
+
- `LORA_PARSE` — Cypher syntax could not be parsed
|
|
218
|
+
- `LORA_SEMANTIC` — analysis failure (unknown variable, label, type mismatch, …)
|
|
219
|
+
- `LORA_INVALID_PARAMS` — a parameter value could not be coerced to a `LoraValue`
|
|
220
|
+
- `LORA_INVALID_VECTOR` — vector value failed dimension / coordinate-type validation
|
|
221
|
+
- `LORA_TIMEOUT` — query exceeded its cooperative deadline
|
|
222
|
+
- `LORA_IO`, `LORA_SNAPSHOT_CODEC`, `LORA_SNAPSHOT_CRYPTO` — storage / snapshot failures
|
|
223
|
+
- `LORA_INTERNAL` — last-resort fallback when the engine cannot classify the failure
|
|
184
224
|
- `WORKER_ERROR` — worker transport / lifecycle failure (worker client only)
|
|
185
225
|
|
|
226
|
+
See `ts/types.ts` (`LoraErrorCode`) for the full list.
|
|
227
|
+
|
|
186
228
|
## Shared type contract
|
|
187
229
|
|
|
188
230
|
The public TypeScript value model (`LoraValue`, `LoraNode`, …,
|
|
189
231
|
`QueryResult`, `LoraError`) lives in a single canonical file at
|
|
190
|
-
`crates/shared-ts/types.ts` and is copied into each consumer package by
|
|
232
|
+
`crates/bindings/shared-ts/types.ts` and is copied into each consumer package by
|
|
191
233
|
its `sync:types` npm script. CI runs `verify:types` to fail on drift.
|
|
192
234
|
That keeps `lora-node` and `lora-wasm` locked to one identical
|
|
193
235
|
public surface — consumers can swap backends without rewriting types.
|
|
194
236
|
|
|
195
237
|
## Known limitations
|
|
196
238
|
|
|
197
|
-
- The wasm module
|
|
198
|
-
|
|
239
|
+
- The wasm module runs inside one JavaScript runtime. Auto-commit reads can
|
|
240
|
+
overlap on engine snapshots; write commits serialize. Use more Workers for
|
|
241
|
+
separate graphs or stronger UI isolation.
|
|
199
242
|
- I64 values are delivered as JS `number` and lose precision above 2^53.
|
|
200
243
|
Applications that need bigint precision should use the native
|
|
201
244
|
`lora-node` binding instead.
|
|
@@ -227,7 +270,7 @@ public surface — consumers can swap backends without rewriting types.
|
|
|
227
270
|
forms, parameter validation errors, and concurrent queries across the
|
|
228
271
|
worker message protocol.
|
|
229
272
|
- The TypeScript public contract is shared verbatim with `lora-node`
|
|
230
|
-
via `crates/shared-ts/types.ts`, enforced by `verify:types` in CI.
|
|
273
|
+
via `crates/bindings/shared-ts/types.ts`, enforced by `verify:types` in CI.
|
|
231
274
|
- `npm pack --dry-run` produces a 45-file, 6.6 MB tarball containing
|
|
232
275
|
all three wasm bundles plus the compiled TS wrapper. No `file:` deps,
|
|
233
276
|
no postinstall scripts.
|
|
@@ -244,9 +287,8 @@ public surface — consumers can swap backends without rewriting types.
|
|
|
244
287
|
- I64 precision is capped at `Number.MAX_SAFE_INTEGER`. For larger
|
|
245
288
|
integer properties we need a `bigint`-aware serializer on the wasm
|
|
246
289
|
boundary.
|
|
247
|
-
- The engine is synchronous inside wasm
|
|
248
|
-
|
|
249
|
-
possible), or an engine-level cooperative scheduler.
|
|
290
|
+
- The engine is synchronous inside wasm once a call enters the module. A slow
|
|
291
|
+
query blocks that Worker until completion.
|
|
250
292
|
- No query cancellation or progress streaming crosses the Worker
|
|
251
293
|
boundary; a slow query blocks that Worker until completion.
|
|
252
294
|
|
package/dist/decode.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decoder for the binary result format produced by the native side.
|
|
3
|
+
*
|
|
4
|
+
* The native `execute()` ships a single `Uint8Array` whose layout is
|
|
5
|
+
* defined by `crates/bindings/lora-binding-buffer/src/lib.rs`. This
|
|
6
|
+
* file is the sole reader; it must stay byte-compatible with the
|
|
7
|
+
* encoder there.
|
|
8
|
+
*
|
|
9
|
+
* Why this exists: each FFI syscall costs ~150 ns; for a 10 000-row
|
|
10
|
+
* scan, the per-cell loop takes thousands of crossings and dominates
|
|
11
|
+
* wall-clock time. Transferring the whole result as one buffer and
|
|
12
|
+
* decoding it in JIT'd JavaScript is materially faster — V8 walks
|
|
13
|
+
* contiguous bytes far more cheaply than the FFI layer can hand
|
|
14
|
+
* values across one at a time.
|
|
15
|
+
*
|
|
16
|
+
* Shared between the `lora-node` and `lora-wasm` bindings; the source
|
|
17
|
+
* of truth lives in `crates/bindings/shared-ts/decode.ts` and is
|
|
18
|
+
* synced into each binding's `ts/` by their `npm run sync:types`
|
|
19
|
+
* script (mirrors how `types.ts` is shared).
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Decode the wire format produced by `encode_rows` in the native crate
|
|
23
|
+
* into the public `{ columns, rows }` shape.
|
|
24
|
+
*/
|
|
25
|
+
export declare function decodeResult(buf: Uint8Array): {
|
|
26
|
+
columns: string[];
|
|
27
|
+
rows: Array<Record<string, any>>;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../ts/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAsTH;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,UAAU,GACd;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;CAAE,CA4BzD"}
|
package/dist/decode.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decoder for the binary result format produced by the native side.
|
|
3
|
+
*
|
|
4
|
+
* The native `execute()` ships a single `Uint8Array` whose layout is
|
|
5
|
+
* defined by `crates/bindings/lora-binding-buffer/src/lib.rs`. This
|
|
6
|
+
* file is the sole reader; it must stay byte-compatible with the
|
|
7
|
+
* encoder there.
|
|
8
|
+
*
|
|
9
|
+
* Why this exists: each FFI syscall costs ~150 ns; for a 10 000-row
|
|
10
|
+
* scan, the per-cell loop takes thousands of crossings and dominates
|
|
11
|
+
* wall-clock time. Transferring the whole result as one buffer and
|
|
12
|
+
* decoding it in JIT'd JavaScript is materially faster — V8 walks
|
|
13
|
+
* contiguous bytes far more cheaply than the FFI layer can hand
|
|
14
|
+
* values across one at a time.
|
|
15
|
+
*
|
|
16
|
+
* Shared between the `lora-node` and `lora-wasm` bindings; the source
|
|
17
|
+
* of truth lives in `crates/bindings/shared-ts/decode.ts` and is
|
|
18
|
+
* synced into each binding's `ts/` by their `npm run sync:types`
|
|
19
|
+
* script (mirrors how `types.ts` is shared).
|
|
20
|
+
*/
|
|
21
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
22
|
+
const MAGIC_0 = 0x4c; // L
|
|
23
|
+
const MAGIC_1 = 0x52; // R
|
|
24
|
+
const MAGIC_2 = 0x31; // 1
|
|
25
|
+
const MAGIC_3 = 0x00;
|
|
26
|
+
// Cell tags — keep in sync with `tag::` constants in encode.rs.
|
|
27
|
+
const TAG_NULL = 0x00;
|
|
28
|
+
const TAG_FALSE = 0x01;
|
|
29
|
+
const TAG_TRUE = 0x02;
|
|
30
|
+
const TAG_I32 = 0x03;
|
|
31
|
+
const TAG_I64 = 0x04;
|
|
32
|
+
const TAG_F64 = 0x05;
|
|
33
|
+
const TAG_STRING = 0x06;
|
|
34
|
+
const TAG_LIST = 0x07;
|
|
35
|
+
const TAG_MAP = 0x08;
|
|
36
|
+
const TAG_NODE = 0x09;
|
|
37
|
+
const TAG_RELATIONSHIP = 0x0a;
|
|
38
|
+
const TAG_PATH = 0x0b;
|
|
39
|
+
const TAG_DATE = 0x0c;
|
|
40
|
+
const TAG_TIME = 0x0d;
|
|
41
|
+
const TAG_LOCAL_TIME = 0x0e;
|
|
42
|
+
const TAG_DATETIME = 0x0f;
|
|
43
|
+
const TAG_LOCAL_DATETIME = 0x10;
|
|
44
|
+
const TAG_DURATION = 0x11;
|
|
45
|
+
const TAG_POINT = 0x12;
|
|
46
|
+
const TAG_VECTOR = 0x13;
|
|
47
|
+
const TAG_BINARY = 0x14;
|
|
48
|
+
const VECTOR_FLOAT64 = 0;
|
|
49
|
+
const VECTOR_FLOAT32 = 1;
|
|
50
|
+
const VECTOR_INT64 = 2;
|
|
51
|
+
const VECTOR_INT32 = 3;
|
|
52
|
+
const VECTOR_INT16 = 4;
|
|
53
|
+
const VECTOR_INT8 = 5;
|
|
54
|
+
const SRID_CARTESIAN_2D = 7203;
|
|
55
|
+
const SRID_CARTESIAN_3D = 9157;
|
|
56
|
+
const SRID_WGS84_2D = 4326;
|
|
57
|
+
const SRID_WGS84_3D = 4979;
|
|
58
|
+
function sridToCrs(srid) {
|
|
59
|
+
switch (srid) {
|
|
60
|
+
case SRID_CARTESIAN_2D:
|
|
61
|
+
return "cartesian";
|
|
62
|
+
case SRID_CARTESIAN_3D:
|
|
63
|
+
return "cartesian-3D";
|
|
64
|
+
case SRID_WGS84_2D:
|
|
65
|
+
return "WGS-84-2D";
|
|
66
|
+
case SRID_WGS84_3D:
|
|
67
|
+
return "WGS-84-3D";
|
|
68
|
+
default:
|
|
69
|
+
return "cartesian";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const utf8 = new TextDecoder("utf-8");
|
|
73
|
+
class Reader {
|
|
74
|
+
view;
|
|
75
|
+
bytes;
|
|
76
|
+
off = 0;
|
|
77
|
+
constructor(buf) {
|
|
78
|
+
this.bytes = buf;
|
|
79
|
+
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
80
|
+
}
|
|
81
|
+
u8() {
|
|
82
|
+
// `noUncheckedIndexedAccess` says this might be undefined; we
|
|
83
|
+
// never read past the buffer because the encoder writes a
|
|
84
|
+
// bounded layout. The hot path can't afford a check.
|
|
85
|
+
return this.bytes[this.off++];
|
|
86
|
+
}
|
|
87
|
+
u32() {
|
|
88
|
+
const v = this.view.getUint32(this.off, true);
|
|
89
|
+
this.off += 4;
|
|
90
|
+
return v;
|
|
91
|
+
}
|
|
92
|
+
i32() {
|
|
93
|
+
const v = this.view.getInt32(this.off, true);
|
|
94
|
+
this.off += 4;
|
|
95
|
+
return v;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Reads an i64 LE and returns it as a JS Number. Values outside the
|
|
99
|
+
* `Number.MAX_SAFE_INTEGER` range silently lose precision — same
|
|
100
|
+
* behaviour the binding has always had on the read path. Callers that
|
|
101
|
+
* need exact representation of large ints should use a separate
|
|
102
|
+
* binding-side path; this is a hot loop.
|
|
103
|
+
*/
|
|
104
|
+
i64AsNumber() {
|
|
105
|
+
// Two getInt32 calls beat getBigInt64 + Number(BigInt) by ~3× in V8.
|
|
106
|
+
// Manual reconstruction is exact for the |x| < 2^53 range.
|
|
107
|
+
const lo = this.view.getUint32(this.off, true);
|
|
108
|
+
const hi = this.view.getInt32(this.off + 4, true);
|
|
109
|
+
this.off += 8;
|
|
110
|
+
return hi * 0x1_0000_0000 + lo;
|
|
111
|
+
}
|
|
112
|
+
f64() {
|
|
113
|
+
const v = this.view.getFloat64(this.off, true);
|
|
114
|
+
this.off += 8;
|
|
115
|
+
return v;
|
|
116
|
+
}
|
|
117
|
+
str() {
|
|
118
|
+
const len = this.u32();
|
|
119
|
+
const start = this.off;
|
|
120
|
+
this.off += len;
|
|
121
|
+
if (len === 0)
|
|
122
|
+
return "";
|
|
123
|
+
// TextDecoder is a fused C++ path in V8; faster than Buffer.toString
|
|
124
|
+
// for short-to-medium strings and avoids hitting Buffer's own
|
|
125
|
+
// string-cache layer.
|
|
126
|
+
return utf8.decode(this.bytes.subarray(start, this.off));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function readValue(r) {
|
|
130
|
+
const tag = r.u8();
|
|
131
|
+
switch (tag) {
|
|
132
|
+
case TAG_NULL:
|
|
133
|
+
return null;
|
|
134
|
+
case TAG_FALSE:
|
|
135
|
+
return false;
|
|
136
|
+
case TAG_TRUE:
|
|
137
|
+
return true;
|
|
138
|
+
case TAG_I32:
|
|
139
|
+
return r.i32();
|
|
140
|
+
case TAG_I64:
|
|
141
|
+
return r.i64AsNumber();
|
|
142
|
+
case TAG_F64:
|
|
143
|
+
return r.f64();
|
|
144
|
+
case TAG_STRING:
|
|
145
|
+
return r.str();
|
|
146
|
+
case TAG_LIST: {
|
|
147
|
+
const n = r.u32();
|
|
148
|
+
const arr = new Array(n);
|
|
149
|
+
for (let i = 0; i < n; i++)
|
|
150
|
+
arr[i] = readValue(r);
|
|
151
|
+
return arr;
|
|
152
|
+
}
|
|
153
|
+
case TAG_MAP: {
|
|
154
|
+
const n = r.u32();
|
|
155
|
+
const obj = {};
|
|
156
|
+
for (let i = 0; i < n; i++) {
|
|
157
|
+
const k = r.str();
|
|
158
|
+
obj[k] = readValue(r);
|
|
159
|
+
}
|
|
160
|
+
return obj;
|
|
161
|
+
}
|
|
162
|
+
case TAG_NODE:
|
|
163
|
+
return {
|
|
164
|
+
kind: "node",
|
|
165
|
+
id: r.i64AsNumber(),
|
|
166
|
+
labels: [],
|
|
167
|
+
properties: {},
|
|
168
|
+
};
|
|
169
|
+
case TAG_RELATIONSHIP:
|
|
170
|
+
return { kind: "relationship", id: r.i64AsNumber() };
|
|
171
|
+
case TAG_PATH: {
|
|
172
|
+
const nN = r.u32();
|
|
173
|
+
const nodes = new Array(nN);
|
|
174
|
+
for (let i = 0; i < nN; i++)
|
|
175
|
+
nodes[i] = r.i64AsNumber();
|
|
176
|
+
const nR = r.u32();
|
|
177
|
+
const rels = new Array(nR);
|
|
178
|
+
for (let i = 0; i < nR; i++)
|
|
179
|
+
rels[i] = r.i64AsNumber();
|
|
180
|
+
return { kind: "path", nodes, rels };
|
|
181
|
+
}
|
|
182
|
+
case TAG_DATE:
|
|
183
|
+
return { kind: "date", iso: r.str() };
|
|
184
|
+
case TAG_TIME:
|
|
185
|
+
return { kind: "time", iso: r.str() };
|
|
186
|
+
case TAG_LOCAL_TIME:
|
|
187
|
+
return { kind: "localtime", iso: r.str() };
|
|
188
|
+
case TAG_DATETIME:
|
|
189
|
+
return { kind: "datetime", iso: r.str() };
|
|
190
|
+
case TAG_LOCAL_DATETIME:
|
|
191
|
+
return { kind: "localdatetime", iso: r.str() };
|
|
192
|
+
case TAG_DURATION:
|
|
193
|
+
return { kind: "duration", iso: r.str() };
|
|
194
|
+
case TAG_POINT: {
|
|
195
|
+
const hasZ = r.u8();
|
|
196
|
+
const srid = r.u32();
|
|
197
|
+
const x = r.f64();
|
|
198
|
+
const y = r.f64();
|
|
199
|
+
const point = {
|
|
200
|
+
kind: "point",
|
|
201
|
+
srid,
|
|
202
|
+
crs: sridToCrs(srid),
|
|
203
|
+
x,
|
|
204
|
+
y,
|
|
205
|
+
};
|
|
206
|
+
if (hasZ)
|
|
207
|
+
point.z = r.f64();
|
|
208
|
+
if (srid === SRID_WGS84_2D || srid === SRID_WGS84_3D) {
|
|
209
|
+
point.longitude = x;
|
|
210
|
+
point.latitude = y;
|
|
211
|
+
if (hasZ)
|
|
212
|
+
point.height = point.z;
|
|
213
|
+
}
|
|
214
|
+
return point;
|
|
215
|
+
}
|
|
216
|
+
case TAG_VECTOR:
|
|
217
|
+
return readVector(r);
|
|
218
|
+
case TAG_BINARY:
|
|
219
|
+
return readBinary(r);
|
|
220
|
+
default:
|
|
221
|
+
throw new Error(`unknown LoraValue tag: 0x${tag.toString(16)}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function readVector(r) {
|
|
225
|
+
const coordTag = r.u8();
|
|
226
|
+
const dim = r.u32();
|
|
227
|
+
const values = new Array(dim);
|
|
228
|
+
let coordinateType;
|
|
229
|
+
switch (coordTag) {
|
|
230
|
+
case VECTOR_FLOAT64:
|
|
231
|
+
coordinateType = "FLOAT64";
|
|
232
|
+
for (let i = 0; i < dim; i++)
|
|
233
|
+
values[i] = r.f64();
|
|
234
|
+
break;
|
|
235
|
+
case VECTOR_FLOAT32:
|
|
236
|
+
coordinateType = "FLOAT32";
|
|
237
|
+
for (let i = 0; i < dim; i++) {
|
|
238
|
+
values[i] = r.view.getFloat32(r.off, true);
|
|
239
|
+
r.off += 4;
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
242
|
+
case VECTOR_INT64:
|
|
243
|
+
coordinateType = "INTEGER";
|
|
244
|
+
for (let i = 0; i < dim; i++)
|
|
245
|
+
values[i] = r.i64AsNumber();
|
|
246
|
+
break;
|
|
247
|
+
case VECTOR_INT32:
|
|
248
|
+
coordinateType = "INTEGER32";
|
|
249
|
+
for (let i = 0; i < dim; i++)
|
|
250
|
+
values[i] = r.i32();
|
|
251
|
+
break;
|
|
252
|
+
case VECTOR_INT16:
|
|
253
|
+
coordinateType = "INTEGER16";
|
|
254
|
+
for (let i = 0; i < dim; i++) {
|
|
255
|
+
values[i] = r.view.getInt16(r.off, true);
|
|
256
|
+
r.off += 2;
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
case VECTOR_INT8:
|
|
260
|
+
coordinateType = "INTEGER8";
|
|
261
|
+
for (let i = 0; i < dim; i++) {
|
|
262
|
+
values[i] = r.view.getInt8(r.off);
|
|
263
|
+
r.off += 1;
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
default:
|
|
267
|
+
throw new Error(`unknown vector coord type: ${coordTag}`);
|
|
268
|
+
}
|
|
269
|
+
return { kind: "vector", dimension: dim, coordinateType, values };
|
|
270
|
+
}
|
|
271
|
+
function readBinary(r) {
|
|
272
|
+
const segCount = r.u32();
|
|
273
|
+
const segments = new Array(segCount);
|
|
274
|
+
let total = 0;
|
|
275
|
+
for (let i = 0; i < segCount; i++) {
|
|
276
|
+
const len = r.u32();
|
|
277
|
+
const seg = new Array(len);
|
|
278
|
+
for (let j = 0; j < len; j++)
|
|
279
|
+
seg[j] = r.bytes[r.off + j];
|
|
280
|
+
r.off += len;
|
|
281
|
+
segments[i] = seg;
|
|
282
|
+
total += len;
|
|
283
|
+
}
|
|
284
|
+
return { kind: "binary", length: total, segments };
|
|
285
|
+
}
|
|
286
|
+
const factoryCache = new Map();
|
|
287
|
+
function rowFactory(columns) {
|
|
288
|
+
const key = columns.join("\x1f");
|
|
289
|
+
let factory = factoryCache.get(key);
|
|
290
|
+
if (factory)
|
|
291
|
+
return factory;
|
|
292
|
+
// Build:
|
|
293
|
+
// function (read, r) {
|
|
294
|
+
// const row = {};
|
|
295
|
+
// row[colA] = read(r);
|
|
296
|
+
// row[colB] = read(r);
|
|
297
|
+
// return row;
|
|
298
|
+
// }
|
|
299
|
+
const lines = ["const row = {};"];
|
|
300
|
+
for (const col of columns) {
|
|
301
|
+
lines.push(`row[${JSON.stringify(col)}] = read(r);`);
|
|
302
|
+
}
|
|
303
|
+
lines.push("return row;");
|
|
304
|
+
factory = new Function("read", "r", lines.join("\n"));
|
|
305
|
+
factoryCache.set(key, factory);
|
|
306
|
+
return factory;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Decode the wire format produced by `encode_rows` in the native crate
|
|
310
|
+
* into the public `{ columns, rows }` shape.
|
|
311
|
+
*/
|
|
312
|
+
export function decodeResult(buf) {
|
|
313
|
+
const r = new Reader(buf);
|
|
314
|
+
if (r.bytes[0] !== MAGIC_0 ||
|
|
315
|
+
r.bytes[1] !== MAGIC_1 ||
|
|
316
|
+
r.bytes[2] !== MAGIC_2 ||
|
|
317
|
+
r.bytes[3] !== MAGIC_3) {
|
|
318
|
+
throw new Error("lora-node: invalid result buffer magic");
|
|
319
|
+
}
|
|
320
|
+
r.off = 4;
|
|
321
|
+
const colCount = r.u32();
|
|
322
|
+
const columns = new Array(colCount);
|
|
323
|
+
for (let i = 0; i < colCount; i++)
|
|
324
|
+
columns[i] = r.str();
|
|
325
|
+
const rowCount = r.u32();
|
|
326
|
+
const rows = new Array(rowCount);
|
|
327
|
+
if (colCount === 0) {
|
|
328
|
+
for (let i = 0; i < rowCount; i++)
|
|
329
|
+
rows[i] = {};
|
|
330
|
+
return { columns, rows };
|
|
331
|
+
}
|
|
332
|
+
const factory = rowFactory(columns);
|
|
333
|
+
for (let i = 0; i < rowCount; i++) {
|
|
334
|
+
rows[i] = factory(readValue, r);
|
|
335
|
+
}
|
|
336
|
+
return { columns, rows };
|
|
337
|
+
}
|
|
338
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../ts/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,uDAAuD;AAEvD,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,IAAI;AAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,IAAI;AAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,IAAI;AAC1B,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB,gEAAgE;AAChE,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,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AAE,CAAC;IAExD,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,IAAI,GAAG,IAAI,KAAK,CAAsB,QAAQ,CAAC,CAAC;IACtD,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE;YAAE,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IACD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,15 +18,14 @@
|
|
|
18
18
|
import type { LoraParams, LoraValue, QueryResult } from "./types.js";
|
|
19
19
|
import { WasmDatabase } from "./loader-node.js";
|
|
20
20
|
import type { WorkerDatabase } from "./worker-client.js";
|
|
21
|
-
import type { WasmSnapshotSource } from "./snapshot.js";
|
|
21
|
+
import type { WasmSnapshotByteOptions, WasmSnapshotLoadOptions, WasmSnapshotSource } from "./snapshot.js";
|
|
22
22
|
export * from "./types.js";
|
|
23
23
|
export { createWorkerDatabase, type WorkerDatabase, type WorkerLike, } from "./worker-client.js";
|
|
24
|
-
export type { WasmSnapshotSaveFormat, WasmSnapshotSaveOptions, WasmSnapshotSource, } from "./snapshot.js";
|
|
24
|
+
export type { WasmSnapshotByteOptions, WasmSnapshotCompression, WasmSnapshotEncryption, WasmSnapshotLoadOptions, WasmSnapshotPasswordParams, WasmSnapshotSaveFormat, WasmSnapshotSaveOptions, WasmSnapshotSource, } from "./snapshot.js";
|
|
25
25
|
/**
|
|
26
|
-
* Metadata returned by `
|
|
27
|
-
* Mirrors the Rust `SnapshotMeta` struct
|
|
28
|
-
*
|
|
29
|
-
* WAL/checkpoint hybrid and is `null` for pure snapshots.
|
|
26
|
+
* Metadata returned by `loadSnapshot`.
|
|
27
|
+
* Mirrors the Rust `SnapshotMeta` struct. WASM saves the database snapshot
|
|
28
|
+
* codec and accepts legacy store snapshots on load for compatibility.
|
|
30
29
|
*/
|
|
31
30
|
export interface SnapshotMeta {
|
|
32
31
|
formatVersion: number;
|
|
@@ -80,39 +79,30 @@ declare class DatabaseImpl {
|
|
|
80
79
|
clear(): Promise<void>;
|
|
81
80
|
nodeCount(): Promise<number>;
|
|
82
81
|
relationshipCount(): Promise<number>;
|
|
83
|
-
/**
|
|
84
|
-
* Serialize the current graph to a `Uint8Array`. WASM has no filesystem
|
|
85
|
-
* access — the caller is responsible for persisting the bytes (IndexedDB,
|
|
86
|
-
* localStorage, fetch POST, `fs.writeFileSync` in Node, etc.) and passing
|
|
87
|
-
* them back to `loadSnapshotFromBytes` on a future database instance.
|
|
88
|
-
*/
|
|
89
|
-
saveSnapshotToBytes(): Promise<Uint8Array>;
|
|
90
82
|
saveSnapshot(): Promise<Uint8Array>;
|
|
91
|
-
saveSnapshot(
|
|
92
|
-
saveSnapshot(format: "base64"): Promise<string>;
|
|
93
|
-
saveSnapshot(format: "blob"): Promise<Blob>;
|
|
94
|
-
saveSnapshot(format: "download"): Promise<void>;
|
|
83
|
+
saveSnapshot(options: WasmSnapshotByteOptions): Promise<Uint8Array>;
|
|
95
84
|
saveSnapshot(options: {
|
|
96
|
-
format
|
|
97
|
-
}): Promise<Uint8Array>;
|
|
85
|
+
format?: "bytes";
|
|
86
|
+
} & WasmSnapshotByteOptions): Promise<Uint8Array>;
|
|
98
87
|
saveSnapshot(options: {
|
|
99
|
-
format: "
|
|
100
|
-
}): Promise<
|
|
88
|
+
format: "arrayBuffer";
|
|
89
|
+
} & WasmSnapshotByteOptions): Promise<ArrayBuffer>;
|
|
101
90
|
saveSnapshot(options: {
|
|
102
91
|
format: "blob";
|
|
103
92
|
mimeType?: string;
|
|
104
|
-
}): Promise<Blob>;
|
|
93
|
+
} & WasmSnapshotByteOptions): Promise<Blob>;
|
|
105
94
|
saveSnapshot(options: {
|
|
106
|
-
format: "
|
|
107
|
-
filename?: string;
|
|
95
|
+
format: "response";
|
|
108
96
|
mimeType?: string;
|
|
109
|
-
}): Promise<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
97
|
+
} & WasmSnapshotByteOptions): Promise<Response>;
|
|
98
|
+
saveSnapshot(options: {
|
|
99
|
+
format: "stream";
|
|
100
|
+
} & WasmSnapshotByteOptions): Promise<ReadableStream<Uint8Array>>;
|
|
101
|
+
saveSnapshot(options: {
|
|
102
|
+
format: "url";
|
|
103
|
+
mimeType?: string;
|
|
104
|
+
} & WasmSnapshotByteOptions): Promise<URL>;
|
|
105
|
+
loadSnapshot(source: WasmSnapshotSource, options?: WasmSnapshotLoadOptions): Promise<SnapshotMeta>;
|
|
116
106
|
/** Release the underlying wasm handle. Subsequent calls will throw. */
|
|
117
107
|
dispose(): void;
|
|
118
108
|
}
|