@loradb/lora-wasm 0.2.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -18,6 +18,18 @@ import type { LoraParams, LoraValue, QueryResult } from "./types.js";
18
18
  import { WasmDatabase } from "./loader-node.js";
19
19
  export * from "./types.js";
20
20
  export { createWorkerDatabase, type WorkerDatabase } from "./worker-client.js";
21
+ /**
22
+ * Metadata returned by `saveSnapshotToBytes` / `loadSnapshotFromBytes`.
23
+ * Mirrors the Rust `SnapshotMeta` struct and matches the shape used by
24
+ * every other binding — `walLsn` is reserved for the future
25
+ * WAL/checkpoint hybrid and is `null` for pure snapshots.
26
+ */
27
+ export interface SnapshotMeta {
28
+ formatVersion: number;
29
+ nodeCount: number;
30
+ relationshipCount: number;
31
+ walLsn: number | null;
32
+ }
21
33
  /**
22
34
  * In-memory Lora graph database running on the WASM engine.
23
35
  *
@@ -33,6 +45,18 @@ declare class DatabaseImpl {
33
45
  clear(): Promise<void>;
34
46
  nodeCount(): Promise<number>;
35
47
  relationshipCount(): Promise<number>;
48
+ /**
49
+ * Serialize the current graph to a `Uint8Array`. WASM has no filesystem
50
+ * access — the caller is responsible for persisting the bytes (IndexedDB,
51
+ * localStorage, fetch POST, `fs.writeFileSync` in Node, etc.) and passing
52
+ * them back to `loadSnapshotFromBytes` on a future database instance.
53
+ */
54
+ saveSnapshotToBytes(): Promise<Uint8Array>;
55
+ /**
56
+ * Replace the current graph state with a snapshot decoded from `bytes`.
57
+ * Returns metadata describing the restored snapshot.
58
+ */
59
+ loadSnapshotFromBytes(bytes: Uint8Array): Promise<SnapshotMeta>;
36
60
  /** Release the underlying wasm handle. Subsequent calls will throw. */
37
61
  dispose(): void;
38
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,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;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AASD;;;;;;;GAOG;AACH,cAAM,YAAY;;gBAGJ,KAAK,EAAE,YAAY,CAAC,OAAO,YAAY,CAAC;IAI9C,OAAO,CACX,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/D,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IASxD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI1C;;;;;OAKG;IACG,mBAAmB,IAAI,OAAO,CAAC,UAAU,CAAC;IAQhD;;;OAGG;IACG,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAQrE,uEAAuE;IACvE,OAAO,IAAI,IAAI;CAGhB;AAED;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,YAAY,CAAC;AAEpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,QAAQ,CAAC,CAGxD"}
package/dist/index.js CHANGED
@@ -56,6 +56,32 @@ class DatabaseImpl {
56
56
  async relationshipCount() {
57
57
  return this.#inner.relationshipCount();
58
58
  }
59
+ /**
60
+ * Serialize the current graph to a `Uint8Array`. WASM has no filesystem
61
+ * access — the caller is responsible for persisting the bytes (IndexedDB,
62
+ * localStorage, fetch POST, `fs.writeFileSync` in Node, etc.) and passing
63
+ * them back to `loadSnapshotFromBytes` on a future database instance.
64
+ */
65
+ async saveSnapshotToBytes() {
66
+ try {
67
+ return this.#inner.saveSnapshotToBytes();
68
+ }
69
+ catch (err) {
70
+ throw wrapError(err);
71
+ }
72
+ }
73
+ /**
74
+ * Replace the current graph state with a snapshot decoded from `bytes`.
75
+ * Returns metadata describing the restored snapshot.
76
+ */
77
+ async loadSnapshotFromBytes(bytes) {
78
+ try {
79
+ return this.#inner.loadSnapshotFromBytes(bytes);
80
+ }
81
+ catch (err) {
82
+ throw wrapError(err);
83
+ }
84
+ }
59
85
  /** Release the underlying wasm handle. Subsequent calls will throw. */
60
86
  dispose() {
61
87
  this.#inner.free();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAElE,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAuB,MAAM,oBAAoB,CAAC;AAE/E,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,SAAS,kBAAkB;IACzB,IAAI,YAAY;QAAE,OAAO;IACzB,QAAQ,EAAE,CAAC;IACX,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,YAAY;IACP,MAAM,CAAoC;IAEnD,YAAY,KAAwC;QAClD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,OAAO,CAEX,KAAa,EAAE,MAAmB;QAClC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,IAAI,IAAI,CAAY,CAAC,CAAC;YACpE,OAAO,GAAqB,CAAC;QAC/B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC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ase;
8
8
  init: () => void;
9
9
  }
10
+ /**
11
+ * Shape of the snapshot metadata emitted by `loadSnapshotFromBytes`. The
12
+ * native Rust layer returns this as a plain JS object via `serde-wasm-bindgen`.
13
+ */
14
+ export interface NativeSnapshotMeta {
15
+ formatVersion: number;
16
+ nodeCount: number;
17
+ relationshipCount: number;
18
+ walLsn: number | null;
19
+ }
10
20
  export declare const WasmDatabase: new () => NativeWasmDatabase;
11
21
  export declare const init: () => void;
12
22
  //# sourceMappingURL=loader-node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader-node.d.ts","sourceRoot":"","sources":["../ts/loader-node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnF,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,UAAU,kBAAkB,CAAC;IAC3C,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAOD,eAAO,MAAM,YAAY,YATC,kBASkB,CAAC;AAC7C,eAAO,MAAM,IAAI,QATH,IASc,CAAC"}
1
+ {"version":3,"file":"loader-node.d.ts","sourceRoot":"","sources":["../ts/loader-node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,IAAI,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnF,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,UAAU,kBAAkB,CAAC;IAC3C,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAOD,eAAO,MAAM,YAAY,YApBC,kBAoBkB,CAAC;AAC7C,eAAO,MAAM,IAAI,QApBH,IAoBc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"loader-node.js","sourceRoot":"","sources":["../ts/loader-node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQ5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,2EAA2E;AAC3E,wCAAwC;AACxC,MAAM,GAAG,GAAG,OAAO,CAAC,0BAA0B,CAAiB,CAAC;AAEhE,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC;AAC7C,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC"}
1
+ {"version":3,"file":"loader-node.js","sourceRoot":"","sources":["../ts/loader-node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAmB5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,2EAA2E;AAC3E,wCAAwC;AACxC,MAAM,GAAG,GAAG,OAAO,CAAC,0BAA0B,CAAiB,CAAC;AAEhE,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC;AAC7C,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loradb/lora-wasm",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "WebAssembly bindings for the Lora in-memory graph database",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "LoraDB, Inc.",
@@ -12,6 +12,22 @@ export class WasmDatabase {
12
12
  free(): void;
13
13
  nodeCount(): number;
14
14
  relationshipCount(): number;
15
+ /**
16
+ * Serialize the graph into a byte buffer. The caller is responsible for
17
+ * writing it to disk, IndexedDB, localStorage, or wherever — WASM does
18
+ * not have direct filesystem access. The returned bytes can later be
19
+ * passed to `loadSnapshotFromBytes` on any `WasmDatabase` instance.
20
+ *
21
+ * Returns the serialized bytes as a `Uint8Array`.
22
+ */
23
+ saveSnapshotToBytes(): Uint8Array;
24
+ /**
25
+ * Replace the graph state with a snapshot decoded from `bytes`.
26
+ *
27
+ * Returns a plain object matching the shape of `SnapshotMeta`:
28
+ * `{ formatVersion, nodeCount, relationshipCount, walLsn }`.
29
+ */
30
+ loadSnapshotFromBytes(bytes: Uint8Array): any;
15
31
  constructor();
16
32
  clear(): void;
17
33
  /**
@@ -180,6 +180,18 @@ function takeFromExternrefTable0(idx) {
180
180
  wasm.__externref_table_dealloc(idx);
181
181
  return value;
182
182
  }
183
+
184
+ function getArrayU8FromWasm0(ptr, len) {
185
+ ptr = ptr >>> 0;
186
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
187
+ }
188
+
189
+ function passArray8ToWasm0(arg, malloc) {
190
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
191
+ getUint8ArrayMemory0().set(arg, ptr / 1);
192
+ WASM_VECTOR_LEN = arg.length;
193
+ return ptr;
194
+ }
183
195
  /**
184
196
  * Call once at module start to install a panic hook that routes Rust
185
197
  * panics to `console.error`. No-op if compiled without the default feature.
@@ -221,6 +233,41 @@ export class WasmDatabase {
221
233
  const ret = wasm.wasmdatabase_relationshipCount(this.__wbg_ptr);
222
234
  return ret >>> 0;
223
235
  }
236
+ /**
237
+ * Serialize the graph into a byte buffer. The caller is responsible for
238
+ * writing it to disk, IndexedDB, localStorage, or wherever — WASM does
239
+ * not have direct filesystem access. The returned bytes can later be
240
+ * passed to `loadSnapshotFromBytes` on any `WasmDatabase` instance.
241
+ *
242
+ * Returns the serialized bytes as a `Uint8Array`.
243
+ * @returns {Uint8Array}
244
+ */
245
+ saveSnapshotToBytes() {
246
+ const ret = wasm.wasmdatabase_saveSnapshotToBytes(this.__wbg_ptr);
247
+ if (ret[3]) {
248
+ throw takeFromExternrefTable0(ret[2]);
249
+ }
250
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
251
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
252
+ return v1;
253
+ }
254
+ /**
255
+ * Replace the graph state with a snapshot decoded from `bytes`.
256
+ *
257
+ * Returns a plain object matching the shape of `SnapshotMeta`:
258
+ * `{ formatVersion, nodeCount, relationshipCount, walLsn }`.
259
+ * @param {Uint8Array} bytes
260
+ * @returns {any}
261
+ */
262
+ loadSnapshotFromBytes(bytes) {
263
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
264
+ const len0 = WASM_VECTOR_LEN;
265
+ const ret = wasm.wasmdatabase_loadSnapshotFromBytes(this.__wbg_ptr, ptr0, len0);
266
+ if (ret[2]) {
267
+ throw takeFromExternrefTable0(ret[1]);
268
+ }
269
+ return takeFromExternrefTable0(ret[0]);
270
+ }
224
271
  constructor() {
225
272
  const ret = wasm.wasmdatabase_new();
226
273
  this.__wbg_ptr = ret >>> 0;
Binary file
@@ -4,9 +4,11 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_wasmdatabase_free: (a: number, b: number) => void;
5
5
  export const wasmdatabase_clear: (a: number) => void;
6
6
  export const wasmdatabase_execute: (a: number, b: number, c: number, d: any) => [number, number, number];
7
+ export const wasmdatabase_loadSnapshotFromBytes: (a: number, b: number, c: number) => [number, number, number];
7
8
  export const wasmdatabase_new: () => number;
8
9
  export const wasmdatabase_nodeCount: (a: number) => number;
9
10
  export const wasmdatabase_relationshipCount: (a: number) => number;
11
+ export const wasmdatabase_saveSnapshotToBytes: (a: number) => [number, number, number, number];
10
12
  export const init: () => void;
11
13
  export const __wbindgen_malloc: (a: number, b: number) => number;
12
14
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -5,7 +5,7 @@
5
5
  "LoraDB, Inc."
6
6
  ],
7
7
  "description": "WebAssembly bindings for the Lora in-memory graph database",
8
- "version": "0.2.0",
8
+ "version": "0.4.0",
9
9
  "license": "BUSL-1.1",
10
10
  "files": [
11
11
  "lora_wasm_bg.wasm",
@@ -12,6 +12,22 @@ export class WasmDatabase {
12
12
  free(): void;
13
13
  nodeCount(): number;
14
14
  relationshipCount(): number;
15
+ /**
16
+ * Serialize the graph into a byte buffer. The caller is responsible for
17
+ * writing it to disk, IndexedDB, localStorage, or wherever — WASM does
18
+ * not have direct filesystem access. The returned bytes can later be
19
+ * passed to `loadSnapshotFromBytes` on any `WasmDatabase` instance.
20
+ *
21
+ * Returns the serialized bytes as a `Uint8Array`.
22
+ */
23
+ saveSnapshotToBytes(): Uint8Array;
24
+ /**
25
+ * Replace the graph state with a snapshot decoded from `bytes`.
26
+ *
27
+ * Returns a plain object matching the shape of `SnapshotMeta`:
28
+ * `{ formatVersion, nodeCount, relationshipCount, walLsn }`.
29
+ */
30
+ loadSnapshotFromBytes(bytes: Uint8Array): any;
15
31
  constructor();
16
32
  clear(): void;
17
33
  /**
@@ -176,6 +176,18 @@ function takeFromExternrefTable0(idx) {
176
176
  wasm.__externref_table_dealloc(idx);
177
177
  return value;
178
178
  }
179
+
180
+ function getArrayU8FromWasm0(ptr, len) {
181
+ ptr = ptr >>> 0;
182
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
183
+ }
184
+
185
+ function passArray8ToWasm0(arg, malloc) {
186
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
187
+ getUint8ArrayMemory0().set(arg, ptr / 1);
188
+ WASM_VECTOR_LEN = arg.length;
189
+ return ptr;
190
+ }
179
191
  /**
180
192
  * Call once at module start to install a panic hook that routes Rust
181
193
  * panics to `console.error`. No-op if compiled without the default feature.
@@ -217,6 +229,41 @@ class WasmDatabase {
217
229
  const ret = wasm.wasmdatabase_relationshipCount(this.__wbg_ptr);
218
230
  return ret >>> 0;
219
231
  }
232
+ /**
233
+ * Serialize the graph into a byte buffer. The caller is responsible for
234
+ * writing it to disk, IndexedDB, localStorage, or wherever — WASM does
235
+ * not have direct filesystem access. The returned bytes can later be
236
+ * passed to `loadSnapshotFromBytes` on any `WasmDatabase` instance.
237
+ *
238
+ * Returns the serialized bytes as a `Uint8Array`.
239
+ * @returns {Uint8Array}
240
+ */
241
+ saveSnapshotToBytes() {
242
+ const ret = wasm.wasmdatabase_saveSnapshotToBytes(this.__wbg_ptr);
243
+ if (ret[3]) {
244
+ throw takeFromExternrefTable0(ret[2]);
245
+ }
246
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
247
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
248
+ return v1;
249
+ }
250
+ /**
251
+ * Replace the graph state with a snapshot decoded from `bytes`.
252
+ *
253
+ * Returns a plain object matching the shape of `SnapshotMeta`:
254
+ * `{ formatVersion, nodeCount, relationshipCount, walLsn }`.
255
+ * @param {Uint8Array} bytes
256
+ * @returns {any}
257
+ */
258
+ loadSnapshotFromBytes(bytes) {
259
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
260
+ const len0 = WASM_VECTOR_LEN;
261
+ const ret = wasm.wasmdatabase_loadSnapshotFromBytes(this.__wbg_ptr, ptr0, len0);
262
+ if (ret[2]) {
263
+ throw takeFromExternrefTable0(ret[1]);
264
+ }
265
+ return takeFromExternrefTable0(ret[0]);
266
+ }
220
267
  constructor() {
221
268
  const ret = wasm.wasmdatabase_new();
222
269
  this.__wbg_ptr = ret >>> 0;
Binary file
@@ -4,9 +4,11 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_wasmdatabase_free: (a: number, b: number) => void;
5
5
  export const wasmdatabase_clear: (a: number) => void;
6
6
  export const wasmdatabase_execute: (a: number, b: number, c: number, d: any) => [number, number, number];
7
+ export const wasmdatabase_loadSnapshotFromBytes: (a: number, b: number, c: number) => [number, number, number];
7
8
  export const wasmdatabase_new: () => number;
8
9
  export const wasmdatabase_nodeCount: (a: number) => number;
9
10
  export const wasmdatabase_relationshipCount: (a: number) => number;
11
+ export const wasmdatabase_saveSnapshotToBytes: (a: number) => [number, number, number, number];
10
12
  export const init: () => void;
11
13
  export const __wbindgen_malloc: (a: number, b: number) => number;
12
14
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -4,7 +4,7 @@
4
4
  "LoraDB, Inc."
5
5
  ],
6
6
  "description": "WebAssembly bindings for the Lora in-memory graph database",
7
- "version": "0.2.0",
7
+ "version": "0.4.0",
8
8
  "license": "BUSL-1.1",
9
9
  "files": [
10
10
  "lora_wasm_bg.wasm",
@@ -12,6 +12,22 @@ export class WasmDatabase {
12
12
  free(): void;
13
13
  nodeCount(): number;
14
14
  relationshipCount(): number;
15
+ /**
16
+ * Serialize the graph into a byte buffer. The caller is responsible for
17
+ * writing it to disk, IndexedDB, localStorage, or wherever — WASM does
18
+ * not have direct filesystem access. The returned bytes can later be
19
+ * passed to `loadSnapshotFromBytes` on any `WasmDatabase` instance.
20
+ *
21
+ * Returns the serialized bytes as a `Uint8Array`.
22
+ */
23
+ saveSnapshotToBytes(): Uint8Array;
24
+ /**
25
+ * Replace the graph state with a snapshot decoded from `bytes`.
26
+ *
27
+ * Returns a plain object matching the shape of `SnapshotMeta`:
28
+ * `{ formatVersion, nodeCount, relationshipCount, walLsn }`.
29
+ */
30
+ loadSnapshotFromBytes(bytes: Uint8Array): any;
15
31
  constructor();
16
32
  clear(): void;
17
33
  /**
@@ -31,9 +47,11 @@ export interface InitOutput {
31
47
  readonly __wbg_wasmdatabase_free: (a: number, b: number) => void;
32
48
  readonly wasmdatabase_clear: (a: number) => void;
33
49
  readonly wasmdatabase_execute: (a: number, b: number, c: number, d: any) => [number, number, number];
50
+ readonly wasmdatabase_loadSnapshotFromBytes: (a: number, b: number, c: number) => [number, number, number];
34
51
  readonly wasmdatabase_new: () => number;
35
52
  readonly wasmdatabase_nodeCount: (a: number) => number;
36
53
  readonly wasmdatabase_relationshipCount: (a: number) => number;
54
+ readonly wasmdatabase_saveSnapshotToBytes: (a: number) => [number, number, number, number];
37
55
  readonly init: () => void;
38
56
  readonly __wbindgen_malloc: (a: number, b: number) => number;
39
57
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -172,6 +172,18 @@ function takeFromExternrefTable0(idx) {
172
172
  wasm.__externref_table_dealloc(idx);
173
173
  return value;
174
174
  }
175
+
176
+ function getArrayU8FromWasm0(ptr, len) {
177
+ ptr = ptr >>> 0;
178
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
179
+ }
180
+
181
+ function passArray8ToWasm0(arg, malloc) {
182
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
183
+ getUint8ArrayMemory0().set(arg, ptr / 1);
184
+ WASM_VECTOR_LEN = arg.length;
185
+ return ptr;
186
+ }
175
187
  /**
176
188
  * Call once at module start to install a panic hook that routes Rust
177
189
  * panics to `console.error`. No-op if compiled without the default feature.
@@ -213,6 +225,41 @@ export class WasmDatabase {
213
225
  const ret = wasm.wasmdatabase_relationshipCount(this.__wbg_ptr);
214
226
  return ret >>> 0;
215
227
  }
228
+ /**
229
+ * Serialize the graph into a byte buffer. The caller is responsible for
230
+ * writing it to disk, IndexedDB, localStorage, or wherever — WASM does
231
+ * not have direct filesystem access. The returned bytes can later be
232
+ * passed to `loadSnapshotFromBytes` on any `WasmDatabase` instance.
233
+ *
234
+ * Returns the serialized bytes as a `Uint8Array`.
235
+ * @returns {Uint8Array}
236
+ */
237
+ saveSnapshotToBytes() {
238
+ const ret = wasm.wasmdatabase_saveSnapshotToBytes(this.__wbg_ptr);
239
+ if (ret[3]) {
240
+ throw takeFromExternrefTable0(ret[2]);
241
+ }
242
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
243
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
244
+ return v1;
245
+ }
246
+ /**
247
+ * Replace the graph state with a snapshot decoded from `bytes`.
248
+ *
249
+ * Returns a plain object matching the shape of `SnapshotMeta`:
250
+ * `{ formatVersion, nodeCount, relationshipCount, walLsn }`.
251
+ * @param {Uint8Array} bytes
252
+ * @returns {any}
253
+ */
254
+ loadSnapshotFromBytes(bytes) {
255
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
256
+ const len0 = WASM_VECTOR_LEN;
257
+ const ret = wasm.wasmdatabase_loadSnapshotFromBytes(this.__wbg_ptr, ptr0, len0);
258
+ if (ret[2]) {
259
+ throw takeFromExternrefTable0(ret[1]);
260
+ }
261
+ return takeFromExternrefTable0(ret[0]);
262
+ }
216
263
  constructor() {
217
264
  const ret = wasm.wasmdatabase_new();
218
265
  this.__wbg_ptr = ret >>> 0;
Binary file
@@ -4,9 +4,11 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_wasmdatabase_free: (a: number, b: number) => void;
5
5
  export const wasmdatabase_clear: (a: number) => void;
6
6
  export const wasmdatabase_execute: (a: number, b: number, c: number, d: any) => [number, number, number];
7
+ export const wasmdatabase_loadSnapshotFromBytes: (a: number, b: number, c: number) => [number, number, number];
7
8
  export const wasmdatabase_new: () => number;
8
9
  export const wasmdatabase_nodeCount: (a: number) => number;
9
10
  export const wasmdatabase_relationshipCount: (a: number) => number;
11
+ export const wasmdatabase_saveSnapshotToBytes: (a: number) => [number, number, number, number];
10
12
  export const init: () => void;
11
13
  export const __wbindgen_malloc: (a: number, b: number) => number;
12
14
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -5,7 +5,7 @@
5
5
  "LoraDB, Inc."
6
6
  ],
7
7
  "description": "WebAssembly bindings for the Lora in-memory graph database",
8
- "version": "0.2.0",
8
+ "version": "0.4.0",
9
9
  "license": "BUSL-1.1",
10
10
  "files": [
11
11
  "lora_wasm_bg.wasm",