@lix-js/sdk 0.8.1 → 0.8.3

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";
Binary file
@@ -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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lix-js/sdk",
3
3
  "type": "module",
4
- "version": "0.8.1",
4
+ "version": "0.8.3",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -53,10 +53,10 @@
53
53
  "typecheck": "tsc -p tsconfig.test.json --noEmit"
54
54
  },
55
55
  "optionalDependencies": {
56
- "@lix-js/sdk-darwin-arm64": "0.8.1",
57
- "@lix-js/sdk-linux-arm64": "0.8.1",
58
- "@lix-js/sdk-linux-x64": "0.8.1",
59
- "@lix-js/sdk-win32-x64": "0.8.1"
56
+ "@lix-js/sdk-darwin-arm64": "0.8.3",
57
+ "@lix-js/sdk-linux-arm64": "0.8.3",
58
+ "@lix-js/sdk-linux-x64": "0.8.3",
59
+ "@lix-js/sdk-win32-x64": "0.8.3"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@vitest/browser-playwright": "4.0.18",