@lix-js/sdk 0.8.0 → 0.8.2

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
@@ -11,7 +11,7 @@ npm install @lix-js/sdk
11
11
 
12
12
  ## Usage
13
13
 
14
- The default in-memory backend works in browsers and Node.js:
14
+ The default in-memory storage works in browsers and Node.js:
15
15
 
16
16
  ```ts
17
17
  import { openLix } from "@lix-js/sdk";
@@ -22,13 +22,13 @@ console.log(result.rows[0]?.get("message"));
22
22
  await lix.close();
23
23
  ```
24
24
 
25
- Filesystem and SQLite backends use native Node.js dependencies:
25
+ Filesystem sync and SQLite persistence use native Node.js dependencies:
26
26
 
27
27
  ```ts
28
- import { FsBackend, openLix } from "@lix-js/sdk";
28
+ import { LocalFilesystem, openLix } from "@lix-js/sdk";
29
29
 
30
30
  const lix = await openLix({
31
- backend: new FsBackend({
31
+ storage: new LocalFilesystem({
32
32
  path: "./workspace",
33
33
  syncAllFiles: true,
34
34
  }),
@@ -89,19 +89,19 @@ try {
89
89
 
90
90
  ## Notes
91
91
 
92
- - `openLix()` opens a fresh in-memory Lix. Pass `new FsBackend({ path, syncAllFiles: true })` for a filesystem workspace directory backed by `<path>/.lix/.internal/rocksdb`.
93
- - Pass `new FsBackend({ path, lixDir, syncAllFiles: true })` for filesystem sync with repository metadata in an external `.lix` directory and no workspace `.lix` directory.
94
- - Pass `syncAllFiles: false` to start filesystem sync with no regular workspace files, then call `backend.importPaths(["notes/today.md"])` on the `FsBackend` instance to sync selected files. Imported paths are exact workspace-relative file paths, not directories or globs.
95
- - Use `new SqliteBackend({ path })` when a single SQLite-backed `.lix` file is the application document itself, for example when defining a new file format and using Lix as the application's file format.
92
+ - `openLix()` opens a fresh in-memory Lix. Pass `new LocalFilesystem({ path, syncAllFiles: true })` for a filesystem workspace directory backed by `<path>/.lix/.internal/rocksdb`.
93
+ - Pass `new LocalFilesystem({ path, lixDir, syncAllFiles: true })` for filesystem sync with repository metadata in an external `.lix` directory and no workspace `.lix` directory.
94
+ - Pass `syncAllFiles: false` to start filesystem sync with no regular workspace files, then call `storage.importPaths(["notes/today.md"])` on the `LocalFilesystem` instance to sync selected files. Imported paths are exact workspace-relative file paths, not directories or globs.
95
+ - Use `new SQLite({ path })` when a single SQLite-backed `.lix` file is the application document itself, for example when defining a new file format and using Lix as the application's file format.
96
96
  - In browsers, `openLix()` loads the Rust engine as WebAssembly and uses the
97
- in-memory backend.
98
- - `FsBackend` and `SqliteBackend` are Node.js-only. Constructing them is safe in
97
+ in-memory storage.
98
+ - `LocalFilesystem` and `SQLite` are Node.js-only. Constructing them is safe in
99
99
  shared code, but passing one to `openLix()` in a browser throws an error.
100
100
  - The package is ESM-only.
101
101
  - The package uses conditional ESM imports internally: Node.js resolves the
102
102
  native N-API binding, while browsers and other runtimes resolve the portable
103
103
  WebAssembly binding. Vite follows this split without consumer configuration.
104
- - Every `openLix()` owns one dedicated worker. The engine, storage backend, and
104
+ - Every `openLix()` owns one dedicated worker. The engine, storage, and
105
105
  installed WASM plugin components all run in that worker in both Node.js and
106
106
  browsers, so database and plugin work does not block the page's main thread.
107
107
  - Installed WASM plugin components are transpiled with JCO and executed by the
@@ -39,13 +39,13 @@ export type ObserveEventsBinding = {
39
39
  close(): void;
40
40
  };
41
41
  export type PluginRuntimeDispatch = (request: unknown) => Promise<unknown>;
42
- export type LixBackendConfig = {
42
+ export type LixStorageConfig = {
43
43
  kind: "memory";
44
44
  } | {
45
45
  kind: "sqlite";
46
46
  path: string;
47
47
  } | {
48
- kind: "fs";
48
+ kind: "localFilesystem";
49
49
  path: string;
50
50
  lixDir?: string;
51
51
  syncAllFiles: boolean;
@@ -1,2 +1,2 @@
1
- import type { LixBackendConfig, LixBinding, PluginRuntimeDispatch } from "./binding-types.js";
2
- export declare function openLixBinding(backend: LixBackendConfig, dispatch: PluginRuntimeDispatch): Promise<LixBinding>;
1
+ import type { LixStorageConfig, LixBinding, PluginRuntimeDispatch } from "./binding-types.js";
2
+ export declare function openLixBinding(storage: LixStorageConfig, dispatch: PluginRuntimeDispatch): Promise<LixBinding>;
@@ -5,9 +5,9 @@ let wasmInitialized;
5
5
  function initializeWasm() {
6
6
  return (wasmInitialized ??= initWasm());
7
7
  }
8
- export async function openLixBinding(backend, dispatch) {
9
- if (backend.kind !== "memory") {
10
- throw new Error(`${backend.kind === "fs" ? "FsBackend" : "SqliteBackend"} is only available in Node.js`);
8
+ export async function openLixBinding(storage, dispatch) {
9
+ if (storage.kind !== "memory") {
10
+ throw new Error(`${storage.kind === "localFilesystem" ? "LocalFilesystem" : "SQLite"} is only available in Node.js`);
11
11
  }
12
12
  await initializeWasm();
13
13
  return openMemory(dispatch);
@@ -1,2 +1,2 @@
1
- import type { LixBackendConfig, LixBinding, PluginRuntimeDispatch } from "./binding-types.js";
2
- export declare function openLixBinding(backend: LixBackendConfig, dispatch: PluginRuntimeDispatch): Promise<LixBinding>;
1
+ import type { LixStorageConfig, LixBinding, PluginRuntimeDispatch } from "./binding-types.js";
2
+ export declare function openLixBinding(storage: LixStorageConfig, dispatch: PluginRuntimeDispatch): Promise<LixBinding>;
@@ -39,13 +39,13 @@ catch (cause) {
39
39
  error.cause = cause;
40
40
  throw error;
41
41
  }
42
- export function openLixBinding(backend, dispatch) {
43
- switch (backend.kind) {
42
+ export function openLixBinding(storage, dispatch) {
43
+ switch (storage.kind) {
44
44
  case "memory":
45
45
  return addon.Lix.openMemory(dispatch);
46
46
  case "sqlite":
47
- return addon.Lix.openSqlite(backend.path, dispatch);
48
- case "fs":
49
- return addon.Lix.openFs(backend.path, backend.lixDir, backend.syncAllFiles, dispatch);
47
+ return addon.Lix.openSQLite(storage.path, dispatch);
48
+ case "localFilesystem":
49
+ return addon.Lix.openLocalFilesystem(storage.path, storage.lixDir, storage.syncAllFiles, dispatch);
50
50
  }
51
51
  }
package/dist/errors.d.ts CHANGED
@@ -5,5 +5,5 @@ export type LixJsError = Error & {
5
5
  };
6
6
  export declare function invalidArgument(operation: string, argument: string, expected: string, actual: string, receiver?: string): LixJsError;
7
7
  export declare function invalidParam(index: number, message: string, actual: string): LixJsError;
8
- export declare function fsBackendNotOpen(operation: string): LixJsError;
9
- export declare function fsBackendAlreadyOpen(): LixJsError;
8
+ export declare function localFilesystemNotOpen(operation: string): LixJsError;
9
+ export declare function localFilesystemAlreadyOpen(): LixJsError;
package/dist/errors.js CHANGED
@@ -17,16 +17,16 @@ export function invalidParam(index, message, actual) {
17
17
  };
18
18
  return error;
19
19
  }
20
- export function fsBackendNotOpen(operation) {
21
- const error = new Error(`FsBackend.${operation}() requires the backend to be opened with openLix() first`);
20
+ export function localFilesystemNotOpen(operation) {
21
+ const error = new Error(`LocalFilesystem.${operation}() requires the storage to be opened with openLix() first`);
22
22
  error.name = "LixError";
23
- error.code = "LIX_FS_BACKEND_NOT_OPEN";
23
+ error.code = "LIX_LOCAL_FILESYSTEM_NOT_OPEN";
24
24
  error.details = { operation };
25
25
  return error;
26
26
  }
27
- export function fsBackendAlreadyOpen() {
28
- const error = new Error("openLix() FsBackend is already open; close the existing Lix or create a new FsBackend");
27
+ export function localFilesystemAlreadyOpen() {
28
+ const error = new Error("openLix() LocalFilesystem is already open; close the existing Lix or create a new LocalFilesystem");
29
29
  error.name = "LixError";
30
- error.code = "LIX_FS_BACKEND_IN_USE";
30
+ error.code = "LIX_LOCAL_FILESYSTEM_IN_USE";
31
31
  return error;
32
32
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { FsBackend, Lix, LixTransaction, ObserveEvents, openLix, SqliteBackend, } from "./open-lix.js";
1
+ export { LocalFilesystem, Lix, LixTransaction, ObserveEvents, openLix, SQLite, } from "./open-lix.js";
2
2
  export { bundledPluginArchives, type BundledPluginArchive, } from "./bundled-plugins.js";
3
3
  export { Row } from "./result.js";
4
4
  export { Value } from "./value.js";
5
- export type { CreateBranchOptions, CreateBranchReceipt, ExecuteOptions, ExecuteResult, FsBackendOptions, JsonValue, LixValue, MergeBranchOptions, MergeBranchOutcome, MergeBranchPreview, MergeBranchReceipt, MergeChangeStats, MergeConflict, MergeConflictSide, ObserveEvent, OpenLixOptions, SqlParam, SqliteBackendOptions, SwitchBranchOptions, SwitchBranchReceipt, } from "./types.js";
5
+ export type { CreateBranchOptions, CreateBranchReceipt, ExecuteOptions, ExecuteResult, LocalFilesystemOptions, JsonValue, LixValue, MergeBranchOptions, MergeBranchOutcome, MergeBranchPreview, MergeBranchReceipt, MergeChangeStats, MergeConflict, MergeConflictSide, ObserveEvent, OpenLixOptions, SqlParam, SQLiteOptions, SwitchBranchOptions, SwitchBranchReceipt, } from "./types.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { FsBackend, Lix, LixTransaction, ObserveEvents, openLix, SqliteBackend, } from "./open-lix.js";
1
+ export { LocalFilesystem, Lix, LixTransaction, ObserveEvents, openLix, SQLite, } from "./open-lix.js";
2
2
  export { bundledPluginArchives, } from "./bundled-plugins.js";
3
3
  export { Row } from "./result.js";
4
4
  export { Value } from "./value.js";
@@ -1,14 +1,14 @@
1
1
  import { LixWorkerClient } from "./worker/client.js";
2
- import type { CreateBranchOptions, CreateBranchReceipt, ExecuteOptions, ExecuteResult, FsBackendOptions, MergeBranchOptions, MergeBranchPreview, MergeBranchReceipt, ObserveEvent, OpenLixOptions, SqlParam, SqliteBackendOptions, SwitchBranchOptions, SwitchBranchReceipt } from "./types.js";
3
- export declare class SqliteBackend {
2
+ import type { CreateBranchOptions, CreateBranchReceipt, ExecuteOptions, ExecuteResult, LocalFilesystemOptions, MergeBranchOptions, MergeBranchPreview, MergeBranchReceipt, ObserveEvent, OpenLixOptions, SqlParam, SQLiteOptions, SwitchBranchOptions, SwitchBranchReceipt } from "./types.js";
3
+ export declare class SQLite {
4
4
  readonly path: string;
5
- constructor(options: SqliteBackendOptions);
5
+ constructor(options: SQLiteOptions);
6
6
  }
7
- export declare class FsBackend {
7
+ export declare class LocalFilesystem {
8
8
  readonly path: string;
9
9
  readonly lixDir: string | undefined;
10
10
  readonly syncAllFiles: boolean;
11
- constructor(options: FsBackendOptions);
11
+ constructor(options: LocalFilesystemOptions);
12
12
  importPaths(paths: readonly string[]): Promise<void>;
13
13
  syncDiskToLix(): Promise<void>;
14
14
  private client;
package/dist/open-lix.js CHANGED
@@ -1,4 +1,4 @@
1
- import { fsBackendAlreadyOpen, fsBackendNotOpen, invalidArgument, } from "./errors.js";
1
+ import { localFilesystemAlreadyOpen, localFilesystemNotOpen, invalidArgument, } from "./errors.js";
2
2
  import { normalizeOptionals, wrapExecuteResult } from "./result.js";
3
3
  import { normalizeParam, toNativeValue } from "./value.js";
4
4
  import { openLixWorker } from "./worker/client.js";
@@ -11,19 +11,19 @@ const observeFinalizer = new FinalizationRegistry(({ client, observeId }) => {
11
11
  client.notify({ kind: "observe.close", observeId: id });
12
12
  });
13
13
  });
14
- export class SqliteBackend {
14
+ export class SQLite {
15
15
  path;
16
16
  constructor(options) {
17
17
  if (!options ||
18
18
  typeof options.path !== "string" ||
19
19
  options.path.length === 0) {
20
- throw new TypeError("SqliteBackend requires a non-empty path");
20
+ throw new TypeError("SQLite requires a non-empty path");
21
21
  }
22
22
  this.path = options.path;
23
23
  }
24
24
  }
25
- const openFsBackends = new WeakMap();
26
- export class FsBackend {
25
+ const openLocalFilesystems = new WeakMap();
26
+ export class LocalFilesystem {
27
27
  path;
28
28
  lixDir;
29
29
  syncAllFiles;
@@ -31,14 +31,14 @@ export class FsBackend {
31
31
  if (!options ||
32
32
  typeof options.path !== "string" ||
33
33
  options.path.length === 0) {
34
- throw new TypeError("FsBackend requires a non-empty path");
34
+ throw new TypeError("LocalFilesystem requires a non-empty path");
35
35
  }
36
36
  if (options.lixDir !== undefined &&
37
37
  (typeof options.lixDir !== "string" || options.lixDir.length === 0)) {
38
- throw new TypeError("FsBackend lixDir must be a non-empty string");
38
+ throw new TypeError("LocalFilesystem lixDir must be a non-empty string");
39
39
  }
40
40
  if (typeof options.syncAllFiles !== "boolean") {
41
- throw new TypeError("FsBackend syncAllFiles must be a boolean");
41
+ throw new TypeError("LocalFilesystem syncAllFiles must be a boolean");
42
42
  }
43
43
  this.path = options.path;
44
44
  this.lixDir = options.lixDir;
@@ -65,9 +65,9 @@ export class FsBackend {
65
65
  return this.client("syncDiskToLix").request({ kind: "syncDiskToLix" });
66
66
  }
67
67
  client(operation) {
68
- const client = openFsBackends.get(this);
68
+ const client = openLocalFilesystems.get(this);
69
69
  if (!client) {
70
- throw fsBackendNotOpen(operation);
70
+ throw localFilesystemNotOpen(operation);
71
71
  }
72
72
  return client;
73
73
  }
@@ -76,34 +76,37 @@ export async function openLix(options = {}) {
76
76
  if (!options || typeof options !== "object") {
77
77
  throw new TypeError("openLix() options must be an object");
78
78
  }
79
- if (options.backend === undefined) {
79
+ if ("backend" in options) {
80
+ throw new TypeError("openLix() option 'backend' was removed; use 'storage' instead");
81
+ }
82
+ if (options.storage === undefined) {
80
83
  return new Lix(await openLixWorker({ kind: "memory" }));
81
84
  }
82
- if (options.backend instanceof SqliteBackend) {
83
- return new Lix(await openLixWorker({ kind: "sqlite", path: options.backend.path }));
85
+ if (options.storage instanceof SQLite) {
86
+ return new Lix(await openLixWorker({ kind: "sqlite", path: options.storage.path }));
84
87
  }
85
- if (options.backend instanceof FsBackend) {
86
- const backend = options.backend;
87
- if (openFsBackends.has(backend)) {
88
- throw fsBackendAlreadyOpen();
88
+ if (options.storage instanceof LocalFilesystem) {
89
+ const storage = options.storage;
90
+ if (openLocalFilesystems.has(storage)) {
91
+ throw localFilesystemAlreadyOpen();
89
92
  }
90
- openFsBackends.set(backend, null);
93
+ openLocalFilesystems.set(storage, null);
91
94
  try {
92
95
  const client = await openLixWorker({
93
- kind: "fs",
94
- path: backend.path,
95
- lixDir: backend.lixDir,
96
- syncAllFiles: backend.syncAllFiles,
97
- }, () => openFsBackends.delete(backend));
98
- openFsBackends.set(backend, client);
96
+ kind: "localFilesystem",
97
+ path: storage.path,
98
+ lixDir: storage.lixDir,
99
+ syncAllFiles: storage.syncAllFiles,
100
+ }, () => openLocalFilesystems.delete(storage));
101
+ openLocalFilesystems.set(storage, client);
99
102
  return new Lix(client);
100
103
  }
101
104
  catch (error) {
102
- openFsBackends.delete(backend);
105
+ openLocalFilesystems.delete(storage);
103
106
  throw error;
104
107
  }
105
108
  }
106
- throw new TypeError("openLix() requires backend to be SqliteBackend or FsBackend");
109
+ throw new TypeError("openLix() requires storage to be SQLite or LocalFilesystem");
107
110
  }
108
111
  export class Lix {
109
112
  client;
package/dist/types.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- export type SqliteBackendOptions = {
1
+ export type SQLiteOptions = {
2
2
  path: string;
3
3
  };
4
- export type FsBackendOptions = {
4
+ export type LocalFilesystemOptions = {
5
5
  path: string;
6
6
  lixDir?: string;
7
7
  syncAllFiles: boolean;
8
8
  };
9
9
  export type OpenLixOptions = {
10
- backend?: import("./open-lix.js").SqliteBackend | import("./open-lix.js").FsBackend;
10
+ storage?: import("./open-lix.js").SQLite | import("./open-lix.js").LocalFilesystem;
11
11
  };
12
12
  export type LixValue = {
13
13
  kind: "null";
@@ -10,6 +10,7 @@ export class WasmLix {
10
10
  close(): Promise<void>;
11
11
  createBranch(options: any): Promise<any>;
12
12
  execute(sql: string, params: any, options?: any | null): Promise<any>;
13
+ exportSnapshot(): Promise<Uint8Array>;
13
14
  mergeBranch(options: any): Promise<any>;
14
15
  mergeBranchPreview(options: any): Promise<any>;
15
16
  observe(sql: string, params: any): Promise<WasmObserveEvents>;
@@ -35,6 +36,8 @@ export class WasmObserveEvents {
35
36
 
36
37
  export function openMemory(plugin_runtime_dispatch: Function): Promise<WasmLix>;
37
38
 
39
+ export function openMemoryFromSnapshot(plugin_runtime_dispatch: Function, snapshot?: Uint8Array | null): Promise<WasmLix>;
40
+
38
41
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
39
42
 
40
43
  export interface InitOutput {
@@ -43,11 +46,13 @@ export interface InitOutput {
43
46
  readonly __wbg_wasmlixtransaction_free: (a: number, b: number) => void;
44
47
  readonly __wbg_wasmobserveevents_free: (a: number, b: number) => void;
45
48
  readonly openMemory: (a: number) => number;
49
+ readonly openMemoryFromSnapshot: (a: number, b: number, c: number) => number;
46
50
  readonly wasmlix_activeBranchId: (a: number) => number;
47
51
  readonly wasmlix_beginTransaction: (a: number) => number;
48
52
  readonly wasmlix_close: (a: number) => number;
49
53
  readonly wasmlix_createBranch: (a: number, b: number) => number;
50
54
  readonly wasmlix_execute: (a: number, b: number, c: number, d: number, e: number) => number;
55
+ readonly wasmlix_exportSnapshot: (a: number) => number;
51
56
  readonly wasmlix_mergeBranch: (a: number, b: number) => number;
52
57
  readonly wasmlix_mergeBranchPreview: (a: number, b: number) => number;
53
58
  readonly wasmlix_observe: (a: number, b: number, c: number, d: number) => number;
@@ -57,8 +62,8 @@ export interface InitOutput {
57
62
  readonly wasmlixtransaction_rollback: (a: number) => number;
58
63
  readonly wasmobserveevents_close: (a: number) => void;
59
64
  readonly wasmobserveevents_next: (a: number) => number;
60
- readonly __wasm_bindgen_func_elem_100752: (a: number, b: number, c: number, d: number) => void;
61
- readonly __wasm_bindgen_func_elem_100754: (a: number, b: number, c: number, d: number) => void;
65
+ readonly __wasm_bindgen_func_elem_101610: (a: number, b: number, c: number, d: number) => void;
66
+ readonly __wasm_bindgen_func_elem_101612: (a: number, b: number, c: number, d: number) => void;
62
67
  readonly __wbindgen_export: (a: number, b: number) => number;
63
68
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
64
69
  readonly __wbindgen_export3: (a: number) => void;
@@ -58,6 +58,13 @@ export class WasmLix {
58
58
  const ret = wasm.wasmlix_execute(this.__wbg_ptr, ptr0, len0, addHeapObject(params), isLikeNone(options) ? 0 : addHeapObject(options));
59
59
  return takeObject(ret);
60
60
  }
61
+ /**
62
+ * @returns {Promise<Uint8Array>}
63
+ */
64
+ exportSnapshot() {
65
+ const ret = wasm.wasmlix_exportSnapshot(this.__wbg_ptr);
66
+ return takeObject(ret);
67
+ }
61
68
  /**
62
69
  * @param {any} options
63
70
  * @returns {Promise<any>}
@@ -180,6 +187,18 @@ export function openMemory(plugin_runtime_dispatch) {
180
187
  const ret = wasm.openMemory(addHeapObject(plugin_runtime_dispatch));
181
188
  return takeObject(ret);
182
189
  }
190
+
191
+ /**
192
+ * @param {Function} plugin_runtime_dispatch
193
+ * @param {Uint8Array | null} [snapshot]
194
+ * @returns {Promise<WasmLix>}
195
+ */
196
+ export function openMemoryFromSnapshot(plugin_runtime_dispatch, snapshot) {
197
+ var ptr0 = isLikeNone(snapshot) ? 0 : passArray8ToWasm0(snapshot, wasm.__wbindgen_export);
198
+ var len0 = WASM_VECTOR_LEN;
199
+ const ret = wasm.openMemoryFromSnapshot(addHeapObject(plugin_runtime_dispatch), ptr0, len0);
200
+ return takeObject(ret);
201
+ }
183
202
  function __wbg_get_imports() {
184
203
  const import0 = {
185
204
  __proto__: null,
@@ -415,7 +434,7 @@ function __wbg_get_imports() {
415
434
  const a = state0.a;
416
435
  state0.a = 0;
417
436
  try {
418
- return __wasm_bindgen_func_elem_100754(a, state0.b, arg0, arg1);
437
+ return __wasm_bindgen_func_elem_101612(a, state0.b, arg0, arg1);
419
438
  } finally {
420
439
  state0.a = a;
421
440
  }
@@ -525,8 +544,8 @@ function __wbg_get_imports() {
525
544
  return addHeapObject(ret);
526
545
  },
527
546
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
528
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 29069, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
529
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_100752);
547
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 29086, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
548
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_101610);
530
549
  return addHeapObject(ret);
531
550
  },
532
551
  __wbindgen_cast_0000000000000002: function(arg0) {
@@ -554,6 +573,13 @@ function __wbg_get_imports() {
554
573
  const ret = BigInt.asUintN(64, arg0);
555
574
  return addHeapObject(ret);
556
575
  },
576
+ __wbindgen_cast_0000000000000007: function(arg0, arg1) {
577
+ var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
578
+ wasm.__wbindgen_export4(arg0, arg1 * 1, 1);
579
+ // Cast intrinsic for `Vector(U8) -> Externref`.
580
+ const ret = v0;
581
+ return addHeapObject(ret);
582
+ },
557
583
  __wbindgen_object_clone_ref: function(arg0) {
558
584
  const ret = getObject(arg0);
559
585
  return addHeapObject(ret);
@@ -568,10 +594,10 @@ function __wbg_get_imports() {
568
594
  };
569
595
  }
570
596
 
571
- function __wasm_bindgen_func_elem_100752(arg0, arg1, arg2) {
597
+ function __wasm_bindgen_func_elem_101610(arg0, arg1, arg2) {
572
598
  try {
573
599
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
574
- wasm.__wasm_bindgen_func_elem_100752(retptr, arg0, arg1, addHeapObject(arg2));
600
+ wasm.__wasm_bindgen_func_elem_101610(retptr, arg0, arg1, addHeapObject(arg2));
575
601
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
576
602
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
577
603
  if (r1) {
@@ -582,8 +608,8 @@ function __wasm_bindgen_func_elem_100752(arg0, arg1, arg2) {
582
608
  }
583
609
  }
584
610
 
585
- function __wasm_bindgen_func_elem_100754(arg0, arg1, arg2, arg3) {
586
- wasm.__wasm_bindgen_func_elem_100754(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
611
+ function __wasm_bindgen_func_elem_101612(arg0, arg1, arg2, arg3) {
612
+ wasm.__wasm_bindgen_func_elem_101612(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
587
613
  }
588
614
 
589
615
  const WasmLixFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -752,6 +778,13 @@ function makeMutClosure(arg0, arg1, f) {
752
778
  return real;
753
779
  }
754
780
 
781
+ function passArray8ToWasm0(arg, malloc) {
782
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
783
+ getUint8ArrayMemory0().set(arg, ptr / 1);
784
+ WASM_VECTOR_LEN = arg.length;
785
+ return ptr;
786
+ }
787
+
755
788
  function passStringToWasm0(arg, malloc, realloc) {
756
789
  if (realloc === undefined) {
757
790
  const buf = cachedTextEncoder.encode(arg);
Binary file
@@ -5,11 +5,13 @@ export const __wbg_wasmlix_free: (a: number, b: number) => void;
5
5
  export const __wbg_wasmlixtransaction_free: (a: number, b: number) => void;
6
6
  export const __wbg_wasmobserveevents_free: (a: number, b: number) => void;
7
7
  export const openMemory: (a: number) => number;
8
+ export const openMemoryFromSnapshot: (a: number, b: number, c: number) => number;
8
9
  export const wasmlix_activeBranchId: (a: number) => number;
9
10
  export const wasmlix_beginTransaction: (a: number) => number;
10
11
  export const wasmlix_close: (a: number) => number;
11
12
  export const wasmlix_createBranch: (a: number, b: number) => number;
12
13
  export const wasmlix_execute: (a: number, b: number, c: number, d: number, e: number) => number;
14
+ export const wasmlix_exportSnapshot: (a: number) => number;
13
15
  export const wasmlix_mergeBranch: (a: number, b: number) => number;
14
16
  export const wasmlix_mergeBranchPreview: (a: number, b: number) => number;
15
17
  export const wasmlix_observe: (a: number, b: number, c: number, d: number) => number;
@@ -19,8 +21,8 @@ export const wasmlixtransaction_execute: (a: number, b: number, c: number, d: nu
19
21
  export const wasmlixtransaction_rollback: (a: number) => number;
20
22
  export const wasmobserveevents_close: (a: number) => void;
21
23
  export const wasmobserveevents_next: (a: number) => number;
22
- export const __wasm_bindgen_func_elem_100752: (a: number, b: number, c: number, d: number) => void;
23
- export const __wasm_bindgen_func_elem_100754: (a: number, b: number, c: number, d: number) => void;
24
+ export const __wasm_bindgen_func_elem_101610: (a: number, b: number, c: number, d: number) => void;
25
+ export const __wasm_bindgen_func_elem_101612: (a: number, b: number, c: number, d: number) => void;
24
26
  export const __wbindgen_export: (a: number, b: number) => number;
25
27
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
26
28
  export const __wbindgen_export3: (a: number) => void;
@@ -1,6 +1,6 @@
1
- import type { LixBackendConfig } from "../binding-types.js";
1
+ import type { LixStorageConfig } from "../binding-types.js";
2
2
  import { type WorkerConnection, type WorkerNotification, type WorkerOperation } from "./protocol.js";
3
- export declare function openLixWorker(backend: LixBackendConfig, onDisposed?: () => void): Promise<LixWorkerClient>;
3
+ export declare function openLixWorker(storage: LixStorageConfig, onDisposed?: () => void): Promise<LixWorkerClient>;
4
4
  export declare class LixWorkerClient {
5
5
  private readonly onDisposed?;
6
6
  private readonly connection;
@@ -1,9 +1,9 @@
1
1
  import { createWorkerConnection } from "#worker-factory";
2
2
  import { deserializeWorkerError, } from "./protocol.js";
3
- export async function openLixWorker(backend, onDisposed) {
3
+ export async function openLixWorker(storage, onDisposed) {
4
4
  const client = new LixWorkerClient(onDisposed);
5
5
  try {
6
- await client.request({ kind: "open", backend });
6
+ await client.request({ kind: "open", storage });
7
7
  return client;
8
8
  }
9
9
  catch (error) {
@@ -58,7 +58,7 @@ export function startWorkerHost(endpoint) {
58
58
  case "open":
59
59
  if (lix)
60
60
  throw workerStateError("Lix worker is already open");
61
- lix = await openLixBinding(operation.backend, createPluginRuntimeDispatch());
61
+ lix = await openLixBinding(operation.storage, createPluginRuntimeDispatch());
62
62
  return undefined;
63
63
  case "execute":
64
64
  return requiredLix().execute(operation.sql, operation.params, operation.options);
@@ -1,4 +1,4 @@
1
- import type { BindingParam, LixBackendConfig } from "../binding-types.js";
1
+ import type { BindingParam, LixStorageConfig } from "../binding-types.js";
2
2
  import type { CreateBranchOptions, ExecuteOptions, MergeBranchOptions, SwitchBranchOptions } from "../types.js";
3
3
  export type WorkerRequest = {
4
4
  id: number;
@@ -6,7 +6,7 @@ export type WorkerRequest = {
6
6
  };
7
7
  export type WorkerOperation = {
8
8
  kind: "open";
9
- backend: LixBackendConfig;
9
+ storage: LixStorageConfig;
10
10
  } | {
11
11
  kind: "execute";
12
12
  sql: string;
@@ -0,0 +1,15 @@
1
+ import type { LixBinding } from "./binding-types.js";
2
+ export interface OpenMemoryLixOptions {
3
+ snapshot?: Uint8Array;
4
+ }
5
+ export interface WorkerdLixBinding extends LixBinding {
6
+ exportSnapshot(): Promise<Uint8Array>;
7
+ }
8
+ /**
9
+ * Opens an in-memory Lix binding directly in a Cloudflare Worker isolate.
10
+ *
11
+ * The browser SDK intentionally uses Web Workers. Workerd does not implement
12
+ * that API, so this entry point initializes the precompiled module directly.
13
+ * Plugin execution is deliberately unavailable in this environment.
14
+ */
15
+ export declare function openMemoryLix(options?: OpenMemoryLixOptions): Promise<WorkerdLixBinding>;
@@ -0,0 +1,32 @@
1
+ // Generated before TypeScript compilation and emitted beside this module.
2
+ // @ts-expect-error Generated by build:wasm.
3
+ import wasmModule from "./wasm/lix_js_sdk_bg.wasm";
4
+ // @ts-expect-error Generated by build:wasm.
5
+ import { initSync, openMemoryFromSnapshot } from "./wasm/lix_js_sdk.js";
6
+ let initialized = false;
7
+ function initializeWasm() {
8
+ if (initialized)
9
+ return;
10
+ initSync({ module: wasmModule });
11
+ initialized = true;
12
+ }
13
+ /**
14
+ * Opens an in-memory Lix binding directly in a Cloudflare Worker isolate.
15
+ *
16
+ * The browser SDK intentionally uses Web Workers. Workerd does not implement
17
+ * that API, so this entry point initializes the precompiled module directly.
18
+ * Plugin execution is deliberately unavailable in this environment.
19
+ */
20
+ export async function openMemoryLix(options = {}) {
21
+ if (!options || typeof options !== "object" || Array.isArray(options)) {
22
+ throw new TypeError("openMemoryLix() options must be an object");
23
+ }
24
+ if (options.snapshot !== undefined &&
25
+ !(options.snapshot instanceof Uint8Array)) {
26
+ throw new TypeError("openMemoryLix() snapshot must be a Uint8Array");
27
+ }
28
+ initializeWasm();
29
+ return openMemoryFromSnapshot(async () => {
30
+ throw new Error("Lix plugin execution is unavailable in Workerd");
31
+ }, options.snapshot);
32
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lix-js/sdk",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.8.2",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -11,6 +11,11 @@
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
13
  "default": "./dist/index.js"
14
+ },
15
+ "./workerd": {
16
+ "types": "./dist/workerd.d.ts",
17
+ "workerd": "./dist/workerd.js",
18
+ "default": "./dist/workerd.js"
14
19
  }
15
20
  },
16
21
  "imports": {
@@ -48,10 +53,10 @@
48
53
  "typecheck": "tsc -p tsconfig.test.json --noEmit"
49
54
  },
50
55
  "optionalDependencies": {
51
- "@lix-js/sdk-darwin-arm64": "0.8.0",
52
- "@lix-js/sdk-linux-arm64": "0.8.0",
53
- "@lix-js/sdk-linux-x64": "0.8.0",
54
- "@lix-js/sdk-win32-x64": "0.8.0"
56
+ "@lix-js/sdk-darwin-arm64": "0.8.2",
57
+ "@lix-js/sdk-linux-arm64": "0.8.2",
58
+ "@lix-js/sdk-linux-x64": "0.8.2",
59
+ "@lix-js/sdk-win32-x64": "0.8.2"
55
60
  },
56
61
  "devDependencies": {
57
62
  "@vitest/browser-playwright": "4.0.18",