@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 +11 -11
- package/dist/binding-types.d.ts +2 -2
- package/dist/binding.browser.d.ts +2 -2
- package/dist/binding.browser.js +3 -3
- package/dist/binding.node.d.ts +2 -2
- package/dist/binding.node.js +5 -5
- package/dist/bundled-plugins/plugin_csv.lixplugin +0 -0
- package/dist/bundled-plugins/plugin_md_v2.lixplugin +0 -0
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +6 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/open-lix.d.ts +5 -5
- package/dist/open-lix.js +29 -26
- package/dist/types.d.ts +3 -3
- package/dist/wasm/lix_js_sdk_bg.wasm +0 -0
- package/dist/worker/client.d.ts +2 -2
- package/dist/worker/client.js +2 -2
- package/dist/worker/host.js +1 -1
- package/dist/worker/protocol.d.ts +2 -2
- package/package.json +5 -5
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
|
|
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
|
|
25
|
+
Filesystem sync and SQLite persistence use native Node.js dependencies:
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
-
import {
|
|
28
|
+
import { LocalFilesystem, openLix } from "@lix-js/sdk";
|
|
29
29
|
|
|
30
30
|
const lix = await openLix({
|
|
31
|
-
|
|
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
|
|
93
|
-
- Pass `new
|
|
94
|
-
- Pass `syncAllFiles: false` to start filesystem sync with no regular workspace files, then call `
|
|
95
|
-
- Use `new
|
|
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
|
|
98
|
-
- `
|
|
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
|
|
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
|
package/dist/binding-types.d.ts
CHANGED
|
@@ -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
|
|
42
|
+
export type LixStorageConfig = {
|
|
43
43
|
kind: "memory";
|
|
44
44
|
} | {
|
|
45
45
|
kind: "sqlite";
|
|
46
46
|
path: string;
|
|
47
47
|
} | {
|
|
48
|
-
kind: "
|
|
48
|
+
kind: "localFilesystem";
|
|
49
49
|
path: string;
|
|
50
50
|
lixDir?: string;
|
|
51
51
|
syncAllFiles: boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function openLixBinding(
|
|
1
|
+
import type { LixStorageConfig, LixBinding, PluginRuntimeDispatch } from "./binding-types.js";
|
|
2
|
+
export declare function openLixBinding(storage: LixStorageConfig, dispatch: PluginRuntimeDispatch): Promise<LixBinding>;
|
package/dist/binding.browser.js
CHANGED
|
@@ -5,9 +5,9 @@ let wasmInitialized;
|
|
|
5
5
|
function initializeWasm() {
|
|
6
6
|
return (wasmInitialized ??= initWasm());
|
|
7
7
|
}
|
|
8
|
-
export async function openLixBinding(
|
|
9
|
-
if (
|
|
10
|
-
throw new Error(`${
|
|
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);
|
package/dist/binding.node.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function openLixBinding(
|
|
1
|
+
import type { LixStorageConfig, LixBinding, PluginRuntimeDispatch } from "./binding-types.js";
|
|
2
|
+
export declare function openLixBinding(storage: LixStorageConfig, dispatch: PluginRuntimeDispatch): Promise<LixBinding>;
|
package/dist/binding.node.js
CHANGED
|
@@ -39,13 +39,13 @@ catch (cause) {
|
|
|
39
39
|
error.cause = cause;
|
|
40
40
|
throw error;
|
|
41
41
|
}
|
|
42
|
-
export function openLixBinding(
|
|
43
|
-
switch (
|
|
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.
|
|
48
|
-
case "
|
|
49
|
-
return addon.Lix.
|
|
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
|
}
|
|
Binary file
|
|
Binary file
|
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
|
|
9
|
-
export declare function
|
|
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
|
|
21
|
-
const error = new Error(`
|
|
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 = "
|
|
23
|
+
error.code = "LIX_LOCAL_FILESYSTEM_NOT_OPEN";
|
|
24
24
|
error.details = { operation };
|
|
25
25
|
return error;
|
|
26
26
|
}
|
|
27
|
-
export function
|
|
28
|
-
const error = new Error("openLix()
|
|
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 = "
|
|
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 {
|
|
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,
|
|
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 {
|
|
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";
|
package/dist/open-lix.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { LixWorkerClient } from "./worker/client.js";
|
|
2
|
-
import type { CreateBranchOptions, CreateBranchReceipt, ExecuteOptions, ExecuteResult,
|
|
3
|
-
export declare class
|
|
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:
|
|
5
|
+
constructor(options: SQLiteOptions);
|
|
6
6
|
}
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class LocalFilesystem {
|
|
8
8
|
readonly path: string;
|
|
9
9
|
readonly lixDir: string | undefined;
|
|
10
10
|
readonly syncAllFiles: boolean;
|
|
11
|
-
constructor(options:
|
|
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 {
|
|
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
|
|
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("
|
|
20
|
+
throw new TypeError("SQLite requires a non-empty path");
|
|
21
21
|
}
|
|
22
22
|
this.path = options.path;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
export class
|
|
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("
|
|
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("
|
|
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("
|
|
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 =
|
|
68
|
+
const client = openLocalFilesystems.get(this);
|
|
69
69
|
if (!client) {
|
|
70
|
-
throw
|
|
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 (
|
|
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.
|
|
83
|
-
return new Lix(await openLixWorker({ kind: "sqlite", path: options.
|
|
85
|
+
if (options.storage instanceof SQLite) {
|
|
86
|
+
return new Lix(await openLixWorker({ kind: "sqlite", path: options.storage.path }));
|
|
84
87
|
}
|
|
85
|
-
if (options.
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
88
|
-
throw
|
|
88
|
+
if (options.storage instanceof LocalFilesystem) {
|
|
89
|
+
const storage = options.storage;
|
|
90
|
+
if (openLocalFilesystems.has(storage)) {
|
|
91
|
+
throw localFilesystemAlreadyOpen();
|
|
89
92
|
}
|
|
90
|
-
|
|
93
|
+
openLocalFilesystems.set(storage, null);
|
|
91
94
|
try {
|
|
92
95
|
const client = await openLixWorker({
|
|
93
|
-
kind: "
|
|
94
|
-
path:
|
|
95
|
-
lixDir:
|
|
96
|
-
syncAllFiles:
|
|
97
|
-
}, () =>
|
|
98
|
-
|
|
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
|
-
|
|
105
|
+
openLocalFilesystems.delete(storage);
|
|
103
106
|
throw error;
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
|
-
throw new TypeError("openLix() requires
|
|
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
|
|
1
|
+
export type SQLiteOptions = {
|
|
2
2
|
path: string;
|
|
3
3
|
};
|
|
4
|
-
export type
|
|
4
|
+
export type LocalFilesystemOptions = {
|
|
5
5
|
path: string;
|
|
6
6
|
lixDir?: string;
|
|
7
7
|
syncAllFiles: boolean;
|
|
8
8
|
};
|
|
9
9
|
export type OpenLixOptions = {
|
|
10
|
-
|
|
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
|
package/dist/worker/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
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(
|
|
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;
|
package/dist/worker/client.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createWorkerConnection } from "#worker-factory";
|
|
2
2
|
import { deserializeWorkerError, } from "./protocol.js";
|
|
3
|
-
export async function openLixWorker(
|
|
3
|
+
export async function openLixWorker(storage, onDisposed) {
|
|
4
4
|
const client = new LixWorkerClient(onDisposed);
|
|
5
5
|
try {
|
|
6
|
-
await client.request({ kind: "open",
|
|
6
|
+
await client.request({ kind: "open", storage });
|
|
7
7
|
return client;
|
|
8
8
|
}
|
|
9
9
|
catch (error) {
|
package/dist/worker/host.js
CHANGED
|
@@ -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.
|
|
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,
|
|
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
|
-
|
|
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.
|
|
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.
|
|
57
|
-
"@lix-js/sdk-linux-arm64": "0.8.
|
|
58
|
-
"@lix-js/sdk-linux-x64": "0.8.
|
|
59
|
-
"@lix-js/sdk-win32-x64": "0.8.
|
|
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",
|