@lix-js/sdk 0.10.0 → 0.12.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 +49 -78
- package/dist/binding-types.d.ts +9 -18
- package/dist/binding.browser.js +18 -5
- package/dist/binding.node.js +5 -11
- package/dist/bundled-plugins/plugin_csv.lixplugin +0 -0
- package/dist/bundled-plugins/plugin_markdown.lixplugin +0 -0
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +0 -13
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/indexeddb-backend.d.ts +19 -0
- package/dist/indexeddb-backend.js +121 -0
- package/dist/lix.d.ts +3 -6
- package/dist/lix.js +28 -54
- package/dist/open-lix.d.ts +4 -13
- package/dist/open-lix.js +45 -152
- package/dist/remote/client.d.ts +2 -3
- package/dist/remote/client.js +50 -23
- package/dist/remote/{protocol.d.ts → server-protocol.d.ts} +40 -32
- package/dist/remote/{protocol.js → server-protocol.js} +36 -17
- package/dist/result.d.ts +2 -1
- package/dist/result.js +12 -0
- package/dist/storage-adapter.d.ts +30 -0
- package/dist/storage-adapter.js +12 -0
- package/dist/types.d.ts +25 -27
- package/dist/value.d.ts +2 -1
- package/dist/value.js +23 -10
- package/dist/wasm/lix_js_sdk.d.ts +5 -10
- package/dist/wasm/lix_js_sdk.js +33 -45
- package/dist/wasm/lix_js_sdk_bg.wasm +0 -0
- package/dist/wasm/lix_js_sdk_bg.wasm.d.ts +3 -6
- package/dist/worker/client.d.ts +1 -12
- package/dist/worker/client.js +0 -161
- package/dist/worker/host.js +0 -23
- package/dist/worker/protocol.d.ts +1 -15
- package/package.json +8 -12
- package/dist/client-state.d.ts +0 -53
- package/dist/client-state.js +0 -318
- package/dist/local-storage-adapter.d.ts +0 -26
- package/dist/local-storage-adapter.js +0 -117
- package/dist/snapshot-persistence.d.ts +0 -7
- package/dist/snapshot-persistence.js +0 -26
package/dist/wasm/lix_js_sdk.js
CHANGED
|
@@ -38,44 +38,6 @@ export class WasmLix {
|
|
|
38
38
|
const ret = wasm.wasmlix_beginTransaction(this.__wbg_ptr);
|
|
39
39
|
return takeObject(ret);
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
* @param {string} key
|
|
43
|
-
* @returns {Promise<void>}
|
|
44
|
-
*/
|
|
45
|
-
clientStateDelete(key) {
|
|
46
|
-
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
47
|
-
const len0 = WASM_VECTOR_LEN;
|
|
48
|
-
const ret = wasm.wasmlix_clientStateDelete(this.__wbg_ptr, ptr0, len0);
|
|
49
|
-
return takeObject(ret);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @returns {Promise<any>}
|
|
53
|
-
*/
|
|
54
|
-
clientStateEntries() {
|
|
55
|
-
const ret = wasm.wasmlix_clientStateEntries(this.__wbg_ptr);
|
|
56
|
-
return takeObject(ret);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @param {string} key
|
|
60
|
-
* @returns {Promise<any>}
|
|
61
|
-
*/
|
|
62
|
-
clientStateGet(key) {
|
|
63
|
-
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
64
|
-
const len0 = WASM_VECTOR_LEN;
|
|
65
|
-
const ret = wasm.wasmlix_clientStateGet(this.__wbg_ptr, ptr0, len0);
|
|
66
|
-
return takeObject(ret);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @param {string} key
|
|
70
|
-
* @param {any} value
|
|
71
|
-
* @returns {Promise<void>}
|
|
72
|
-
*/
|
|
73
|
-
clientStateSet(key, value) {
|
|
74
|
-
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
75
|
-
const len0 = WASM_VECTOR_LEN;
|
|
76
|
-
const ret = wasm.wasmlix_clientStateSet(this.__wbg_ptr, ptr0, len0, addHeapObject(value));
|
|
77
|
-
return takeObject(ret);
|
|
78
|
-
}
|
|
79
41
|
/**
|
|
80
42
|
* @returns {Promise<void>}
|
|
81
43
|
*/
|
|
@@ -254,6 +216,16 @@ export class WasmObserveEvents {
|
|
|
254
216
|
}
|
|
255
217
|
if (Symbol.dispose) WasmObserveEvents.prototype[Symbol.dispose] = WasmObserveEvents.prototype.free;
|
|
256
218
|
|
|
219
|
+
/**
|
|
220
|
+
* @param {any} backend
|
|
221
|
+
* @param {Function | null} [telemetry_dispatch]
|
|
222
|
+
* @returns {Promise<WasmLix>}
|
|
223
|
+
*/
|
|
224
|
+
export function openIndexedDb(backend, telemetry_dispatch) {
|
|
225
|
+
const ret = wasm.openIndexedDb(addHeapObject(backend), isLikeNone(telemetry_dispatch) ? 0 : addHeapObject(telemetry_dispatch));
|
|
226
|
+
return takeObject(ret);
|
|
227
|
+
}
|
|
228
|
+
|
|
257
229
|
/**
|
|
258
230
|
* @param {Function | null} [telemetry_dispatch]
|
|
259
231
|
* @returns {Promise<WasmLix>}
|
|
@@ -390,6 +362,10 @@ function __wbg_get_imports() {
|
|
|
390
362
|
__wbg__wbg_cb_unref_61db23ac97f16c31: function(arg0) {
|
|
391
363
|
getObject(arg0)._wbg_cb_unref();
|
|
392
364
|
},
|
|
365
|
+
__wbg_applyChanges_641749f1dfe2d9cb: function(arg0, arg1) {
|
|
366
|
+
const ret = getObject(arg0).applyChanges(takeObject(arg1));
|
|
367
|
+
return addHeapObject(ret);
|
|
368
|
+
},
|
|
393
369
|
__wbg_call_8a89609d89f6608a: function() { return handleError(function (arg0, arg1) {
|
|
394
370
|
const ret = getObject(arg0).call(getObject(arg1));
|
|
395
371
|
return addHeapObject(ret);
|
|
@@ -398,6 +374,10 @@ function __wbg_get_imports() {
|
|
|
398
374
|
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
|
399
375
|
return addHeapObject(ret);
|
|
400
376
|
}, arguments); },
|
|
377
|
+
__wbg_close_7dfdae1bb5aa18be: function(arg0) {
|
|
378
|
+
const ret = getObject(arg0).close();
|
|
379
|
+
return addHeapObject(ret);
|
|
380
|
+
},
|
|
401
381
|
__wbg_done_60cf307fcc680536: function(arg0) {
|
|
402
382
|
const ret = getObject(arg0).done;
|
|
403
383
|
return ret;
|
|
@@ -501,6 +481,10 @@ function __wbg_get_imports() {
|
|
|
501
481
|
const ret = getObject(arg0).length;
|
|
502
482
|
return ret;
|
|
503
483
|
},
|
|
484
|
+
__wbg_loadEntries_ca66ce538b54b55e: function(arg0) {
|
|
485
|
+
const ret = getObject(arg0).loadEntries();
|
|
486
|
+
return addHeapObject(ret);
|
|
487
|
+
},
|
|
504
488
|
__wbg_new_0_445c13a750296eb6: function() {
|
|
505
489
|
const ret = new Date();
|
|
506
490
|
return addHeapObject(ret);
|
|
@@ -536,7 +520,7 @@ function __wbg_get_imports() {
|
|
|
536
520
|
const a = state0.a;
|
|
537
521
|
state0.a = 0;
|
|
538
522
|
try {
|
|
539
|
-
return
|
|
523
|
+
return __wasm_bindgen_func_elem_119241(a, state0.b, arg0, arg1);
|
|
540
524
|
} finally {
|
|
541
525
|
state0.a = a;
|
|
542
526
|
}
|
|
@@ -625,6 +609,10 @@ function __wbg_get_imports() {
|
|
|
625
609
|
const ret = typeof window === 'undefined' ? null : window;
|
|
626
610
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
627
611
|
},
|
|
612
|
+
__wbg_then_18f476d590e58992: function(arg0, arg1, arg2) {
|
|
613
|
+
const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
|
|
614
|
+
return addHeapObject(ret);
|
|
615
|
+
},
|
|
628
616
|
__wbg_then_ac7b025999b52837: function(arg0, arg1) {
|
|
629
617
|
const ret = getObject(arg0).then(getObject(arg1));
|
|
630
618
|
return addHeapObject(ret);
|
|
@@ -646,8 +634,8 @@ function __wbg_get_imports() {
|
|
|
646
634
|
return addHeapObject(ret);
|
|
647
635
|
},
|
|
648
636
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
649
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
650
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
637
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 28427, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
638
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_119239);
|
|
651
639
|
return addHeapObject(ret);
|
|
652
640
|
},
|
|
653
641
|
__wbindgen_cast_0000000000000002: function(arg0) {
|
|
@@ -696,10 +684,10 @@ function __wbg_get_imports() {
|
|
|
696
684
|
};
|
|
697
685
|
}
|
|
698
686
|
|
|
699
|
-
function
|
|
687
|
+
function __wasm_bindgen_func_elem_119239(arg0, arg1, arg2) {
|
|
700
688
|
try {
|
|
701
689
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
702
|
-
wasm.
|
|
690
|
+
wasm.__wasm_bindgen_func_elem_119239(retptr, arg0, arg1, addHeapObject(arg2));
|
|
703
691
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
704
692
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
705
693
|
if (r1) {
|
|
@@ -710,8 +698,8 @@ function __wasm_bindgen_func_elem_120695(arg0, arg1, arg2) {
|
|
|
710
698
|
}
|
|
711
699
|
}
|
|
712
700
|
|
|
713
|
-
function
|
|
714
|
-
wasm.
|
|
701
|
+
function __wasm_bindgen_func_elem_119241(arg0, arg1, arg2, arg3) {
|
|
702
|
+
wasm.__wasm_bindgen_func_elem_119241(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
715
703
|
}
|
|
716
704
|
|
|
717
705
|
const WasmLixFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
Binary file
|
|
@@ -4,16 +4,13 @@ export const memory: WebAssembly.Memory;
|
|
|
4
4
|
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
|
+
export const openIndexedDb: (a: number, b: number) => number;
|
|
7
8
|
export const openMemory: (a: number) => number;
|
|
8
9
|
export const openMemoryFromSnapshot: (a: number, b: number, c: number) => number;
|
|
9
10
|
export const parseSqlScript: (a: number, b: number, c: number, d: number) => void;
|
|
10
11
|
export const wasmlix_activeAccountId: (a: number) => number;
|
|
11
12
|
export const wasmlix_activeBranchId: (a: number) => number;
|
|
12
13
|
export const wasmlix_beginTransaction: (a: number) => number;
|
|
13
|
-
export const wasmlix_clientStateDelete: (a: number, b: number, c: number) => number;
|
|
14
|
-
export const wasmlix_clientStateEntries: (a: number) => number;
|
|
15
|
-
export const wasmlix_clientStateGet: (a: number, b: number, c: number) => number;
|
|
16
|
-
export const wasmlix_clientStateSet: (a: number, b: number, c: number, d: number) => number;
|
|
17
14
|
export const wasmlix_close: (a: number) => number;
|
|
18
15
|
export const wasmlix_createBranch: (a: number, b: number) => number;
|
|
19
16
|
export const wasmlix_createCheckpoint: (a: number) => number;
|
|
@@ -31,8 +28,8 @@ export const wasmlixtransaction_execute: (a: number, b: number, c: number, d: nu
|
|
|
31
28
|
export const wasmlixtransaction_rollback: (a: number) => number;
|
|
32
29
|
export const wasmobserveevents_close: (a: number) => void;
|
|
33
30
|
export const wasmobserveevents_next: (a: number) => number;
|
|
34
|
-
export const
|
|
35
|
-
export const
|
|
31
|
+
export const __wasm_bindgen_func_elem_119239: (a: number, b: number, c: number, d: number) => void;
|
|
32
|
+
export const __wasm_bindgen_func_elem_119241: (a: number, b: number, c: number, d: number) => void;
|
|
36
33
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
37
34
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
38
35
|
export const __wbindgen_export3: (a: number) => void;
|
package/dist/worker/client.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import type { LixBinding, LixStorageConfig } from "../binding-types.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { LixTelemetryOptions } from "../types.js";
|
|
3
3
|
import { type WorkerConnection, type WorkerNotification, type WorkerOperation } from "./protocol.js";
|
|
4
4
|
export declare function openLixWorker(storage: LixStorageConfig, onDisposed?: () => void, telemetry?: LixTelemetryOptions): Promise<LixWorkerClient>;
|
|
5
5
|
/** Opens the local worker transport behind the semantic Lix binding. */
|
|
6
6
|
export declare function openLixWorkerBinding(storage: LixStorageConfig, onDisposed?: () => void, telemetry?: LixTelemetryOptions): Promise<LixBinding>;
|
|
7
|
-
export type OpenPersistentLixWorkerBindingOptions = {
|
|
8
|
-
storage: LixSnapshotStorage;
|
|
9
|
-
namespace: string;
|
|
10
|
-
telemetry?: LixTelemetryOptions;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Opens a browser memory binding from an opaque snapshot and persists a fresh
|
|
14
|
-
* snapshot after every successful mutation. This is an internal composition
|
|
15
|
-
* seam for public storage adapters; it does not route workspace operations.
|
|
16
|
-
*/
|
|
17
|
-
export declare function openPersistentLixWorkerBinding(options: OpenPersistentLixWorkerBindingOptions): Promise<LixBinding>;
|
|
18
7
|
export declare class LixWorkerClient {
|
|
19
8
|
private readonly connection;
|
|
20
9
|
private nextRequestId;
|
package/dist/worker/client.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createWorkerConnection, openDirectLixBinding } from "#worker-factory";
|
|
2
|
-
import { snapshotPersistenceAfterCommitError } from "../snapshot-persistence.js";
|
|
3
2
|
import { deserializeWorkerError, } from "./protocol.js";
|
|
4
3
|
const MAX_IDLE_WORKERS = 1;
|
|
5
4
|
// The common serial reopen path retains one worker so its prepared plugin cache
|
|
@@ -64,43 +63,6 @@ export async function openLixWorkerBinding(storage, onDisposed, telemetry) {
|
|
|
64
63
|
const client = await openLixWorker(storage, onDisposed, telemetry);
|
|
65
64
|
return workerBinding(client);
|
|
66
65
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Opens a browser memory binding from an opaque snapshot and persists a fresh
|
|
69
|
-
* snapshot after every successful mutation. This is an internal composition
|
|
70
|
-
* seam for public storage adapters; it does not route workspace operations.
|
|
71
|
-
*/
|
|
72
|
-
export async function openPersistentLixWorkerBinding(options) {
|
|
73
|
-
if (!options || typeof options !== "object") {
|
|
74
|
-
throw new TypeError("openPersistentLixWorkerBinding() options must be an object");
|
|
75
|
-
}
|
|
76
|
-
if (!options.storage ||
|
|
77
|
-
typeof options.storage.load !== "function" ||
|
|
78
|
-
typeof options.storage.save !== "function") {
|
|
79
|
-
throw new TypeError("openPersistentLixWorkerBinding() storage must implement load() and save()");
|
|
80
|
-
}
|
|
81
|
-
if (typeof options.namespace !== "string" || options.namespace.length === 0) {
|
|
82
|
-
throw new TypeError("openPersistentLixWorkerBinding() namespace must be a non-empty string");
|
|
83
|
-
}
|
|
84
|
-
const snapshot = await options.storage.load(options.namespace);
|
|
85
|
-
if (snapshot !== undefined && !(snapshot instanceof Uint8Array)) {
|
|
86
|
-
throw new TypeError("Snapshot storage load() must return a Uint8Array");
|
|
87
|
-
}
|
|
88
|
-
const binding = await openLixWorkerBinding({
|
|
89
|
-
kind: "memory",
|
|
90
|
-
...(snapshot === undefined ? {} : { snapshot }),
|
|
91
|
-
}, undefined, options.telemetry);
|
|
92
|
-
const persistent = persistentSnapshotBinding(binding, options.storage, options.namespace);
|
|
93
|
-
if (snapshot === undefined) {
|
|
94
|
-
try {
|
|
95
|
-
await persistent.persist();
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
await binding.close().catch(() => undefined);
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return persistent.binding;
|
|
103
|
-
}
|
|
104
66
|
function workerBinding(client) {
|
|
105
67
|
let closed = false;
|
|
106
68
|
const request = (operation) => {
|
|
@@ -131,10 +93,6 @@ function workerBinding(client) {
|
|
|
131
93
|
},
|
|
132
94
|
activeBranchId: () => request({ kind: "activeBranchId" }),
|
|
133
95
|
activeAccountId: () => request({ kind: "activeAccountId" }),
|
|
134
|
-
clientStateEntries: () => request({ kind: "clientState.entries" }),
|
|
135
|
-
clientStateGet: (key) => request({ kind: "clientState.get", key }),
|
|
136
|
-
clientStateSet: (key, value) => request({ kind: "clientState.set", key, value }),
|
|
137
|
-
clientStateDelete: (key) => request({ kind: "clientState.delete", key }),
|
|
138
96
|
createBranch: (options) => request({ kind: "createBranch", options }),
|
|
139
97
|
createCheckpoint: () => request({ kind: "createCheckpoint" }),
|
|
140
98
|
undo: () => request({ kind: "undo" }),
|
|
@@ -144,7 +102,6 @@ function workerBinding(client) {
|
|
|
144
102
|
mergeBranchPreview: (options) => request({ kind: "mergeBranchPreview", options }),
|
|
145
103
|
mergeBranch: (options) => request({ kind: "mergeBranch", options }),
|
|
146
104
|
syncDiskToLix: () => request({ kind: "syncDiskToLix" }),
|
|
147
|
-
exportSnapshot: () => request({ kind: "exportSnapshot" }),
|
|
148
105
|
close: async () => {
|
|
149
106
|
if (closed)
|
|
150
107
|
return;
|
|
@@ -154,124 +111,6 @@ function workerBinding(client) {
|
|
|
154
111
|
},
|
|
155
112
|
};
|
|
156
113
|
}
|
|
157
|
-
function persistentSnapshotBinding(binding, storage, namespace) {
|
|
158
|
-
let persistenceTail = Promise.resolve();
|
|
159
|
-
let closePromise;
|
|
160
|
-
let bindingClosed = false;
|
|
161
|
-
const persist = () => {
|
|
162
|
-
const operation = persistenceTail.then(async () => {
|
|
163
|
-
const exportSnapshot = binding.exportSnapshot;
|
|
164
|
-
if (!exportSnapshot) {
|
|
165
|
-
throw new Error("The open Lix binding does not support snapshot export");
|
|
166
|
-
}
|
|
167
|
-
const snapshot = await exportSnapshot.call(binding);
|
|
168
|
-
await storage.save(namespace, snapshot);
|
|
169
|
-
});
|
|
170
|
-
persistenceTail = operation.catch(() => undefined);
|
|
171
|
-
return operation;
|
|
172
|
-
};
|
|
173
|
-
const afterMutation = async (operation) => {
|
|
174
|
-
const result = await operation;
|
|
175
|
-
try {
|
|
176
|
-
await persist();
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
// The Rust transaction is already committed. Preserve that fact so
|
|
180
|
-
// synchronous facades can reflect the live session value while still
|
|
181
|
-
// reporting that durability failed.
|
|
182
|
-
throw snapshotPersistenceAfterCommitError(error);
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
};
|
|
186
|
-
const persistentBinding = {
|
|
187
|
-
execute: (sql, params, executeOptions) => afterMutation(binding.execute(sql, params, executeOptions)),
|
|
188
|
-
executeBatch: (statements, batchOptions) => afterMutation(binding.executeBatch(statements, batchOptions)),
|
|
189
|
-
observe: (sql, params) => binding.observe(sql, params),
|
|
190
|
-
beginTransaction: async () => {
|
|
191
|
-
const transaction = await binding.beginTransaction();
|
|
192
|
-
return {
|
|
193
|
-
execute: (sql, params, executeOptions) => transaction.execute(sql, params, executeOptions),
|
|
194
|
-
commit: () => afterMutation(transaction.commit()),
|
|
195
|
-
rollback: () => transaction.rollback(),
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
activeBranchId: () => binding.activeBranchId(),
|
|
199
|
-
activeAccountId: () => binding.activeAccountId(),
|
|
200
|
-
clientStateEntries: () => {
|
|
201
|
-
const method = binding.clientStateEntries;
|
|
202
|
-
if (!method)
|
|
203
|
-
return Promise.reject(clientStateUnsupportedError());
|
|
204
|
-
return method.call(binding);
|
|
205
|
-
},
|
|
206
|
-
clientStateGet: (key) => {
|
|
207
|
-
const method = binding.clientStateGet;
|
|
208
|
-
if (!method)
|
|
209
|
-
return Promise.reject(clientStateUnsupportedError());
|
|
210
|
-
return method.call(binding, key);
|
|
211
|
-
},
|
|
212
|
-
clientStateSet: (key, value) => {
|
|
213
|
-
const method = binding.clientStateSet;
|
|
214
|
-
if (!method)
|
|
215
|
-
return Promise.reject(clientStateUnsupportedError());
|
|
216
|
-
return afterMutation(method.call(binding, key, value));
|
|
217
|
-
},
|
|
218
|
-
clientStateDelete: (key) => {
|
|
219
|
-
const method = binding.clientStateDelete;
|
|
220
|
-
if (!method)
|
|
221
|
-
return Promise.reject(clientStateUnsupportedError());
|
|
222
|
-
return afterMutation(method.call(binding, key));
|
|
223
|
-
},
|
|
224
|
-
createBranch: (branchOptions) => afterMutation(binding.createBranch(branchOptions)),
|
|
225
|
-
createCheckpoint: () => afterMutation(binding.createCheckpoint()),
|
|
226
|
-
undo: () => afterMutation(binding.undo()),
|
|
227
|
-
redo: () => afterMutation(binding.redo()),
|
|
228
|
-
switchBranch: (branchOptions) => afterMutation(binding.switchBranch(branchOptions)),
|
|
229
|
-
importFilesystemPaths: (paths) => afterMutation(binding.importFilesystemPaths(paths)),
|
|
230
|
-
mergeBranchPreview: (branchOptions) => binding.mergeBranchPreview(branchOptions),
|
|
231
|
-
mergeBranch: (branchOptions) => afterMutation(binding.mergeBranch(branchOptions)),
|
|
232
|
-
syncDiskToLix: () => afterMutation(binding.syncDiskToLix()),
|
|
233
|
-
exportSnapshot: () => {
|
|
234
|
-
const exportSnapshot = binding.exportSnapshot;
|
|
235
|
-
if (!exportSnapshot) {
|
|
236
|
-
return Promise.reject(new Error("The open Lix binding does not support snapshot export"));
|
|
237
|
-
}
|
|
238
|
-
return exportSnapshot.call(binding);
|
|
239
|
-
},
|
|
240
|
-
close: () => {
|
|
241
|
-
if (closePromise)
|
|
242
|
-
return closePromise;
|
|
243
|
-
closePromise = (async () => {
|
|
244
|
-
let persistenceError;
|
|
245
|
-
try {
|
|
246
|
-
await persist();
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
persistenceError = error;
|
|
250
|
-
}
|
|
251
|
-
await binding.close();
|
|
252
|
-
bindingClosed = true;
|
|
253
|
-
if (persistenceError !== undefined)
|
|
254
|
-
throw persistenceError;
|
|
255
|
-
})();
|
|
256
|
-
void closePromise.catch((error) => {
|
|
257
|
-
if (!bindingClosed && isActiveTransactionCloseError(error)) {
|
|
258
|
-
closePromise = undefined;
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
return closePromise;
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
return { binding: persistentBinding, persist };
|
|
265
|
-
}
|
|
266
|
-
function isActiveTransactionCloseError(error) {
|
|
267
|
-
return (typeof error === "object" &&
|
|
268
|
-
error !== null &&
|
|
269
|
-
"code" in error &&
|
|
270
|
-
error.code === "LIX_INVALID_TRANSACTION_STATE");
|
|
271
|
-
}
|
|
272
|
-
function clientStateUnsupportedError() {
|
|
273
|
-
return new Error("The open Lix binding does not support typed client state");
|
|
274
|
-
}
|
|
275
114
|
function workerTransactionBinding(request, transactionId) {
|
|
276
115
|
return {
|
|
277
116
|
execute: (sql, params, options) => request({
|
package/dist/worker/host.js
CHANGED
|
@@ -89,14 +89,6 @@ export function startWorkerHost(endpoint) {
|
|
|
89
89
|
return requiredLix().activeBranchId();
|
|
90
90
|
case "activeAccountId":
|
|
91
91
|
return requiredLix().activeAccountId();
|
|
92
|
-
case "clientState.entries":
|
|
93
|
-
return requiredClientStateMethod("clientStateEntries")();
|
|
94
|
-
case "clientState.get":
|
|
95
|
-
return requiredClientStateMethod("clientStateGet")(operation.key);
|
|
96
|
-
case "clientState.set":
|
|
97
|
-
return requiredClientStateMethod("clientStateSet")(operation.key, operation.value);
|
|
98
|
-
case "clientState.delete":
|
|
99
|
-
return requiredClientStateMethod("clientStateDelete")(operation.key);
|
|
100
92
|
case "createBranch":
|
|
101
93
|
return requiredLix().createBranch(operation.options);
|
|
102
94
|
case "createCheckpoint":
|
|
@@ -115,14 +107,6 @@ export function startWorkerHost(endpoint) {
|
|
|
115
107
|
return requiredLix().importFilesystemPaths(operation.paths);
|
|
116
108
|
case "syncDiskToLix":
|
|
117
109
|
return requiredLix().syncDiskToLix();
|
|
118
|
-
case "exportSnapshot": {
|
|
119
|
-
const lix = requiredLix();
|
|
120
|
-
const exportSnapshot = lix.exportSnapshot;
|
|
121
|
-
if (!exportSnapshot) {
|
|
122
|
-
throw workerStateError("The open Lix storage does not support snapshot export");
|
|
123
|
-
}
|
|
124
|
-
return exportSnapshot.call(lix);
|
|
125
|
-
}
|
|
126
110
|
case "observe": {
|
|
127
111
|
const events = await requiredLix().observe(operation.sql, operation.params);
|
|
128
112
|
const observeId = nextObserveId++;
|
|
@@ -154,13 +138,6 @@ export function startWorkerHost(endpoint) {
|
|
|
154
138
|
throw workerStateError("Lix worker is closed");
|
|
155
139
|
return lix;
|
|
156
140
|
}
|
|
157
|
-
function requiredClientStateMethod(key) {
|
|
158
|
-
const method = requiredLix()[key];
|
|
159
|
-
if (!method) {
|
|
160
|
-
throw workerStateError("The open Lix binding does not support typed client state");
|
|
161
|
-
}
|
|
162
|
-
return method.bind(requiredLix());
|
|
163
|
-
}
|
|
164
141
|
function requiredTransaction(transactionId) {
|
|
165
142
|
const transaction = transactions.get(transactionId);
|
|
166
143
|
if (!transaction) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BindingBatchStatement, BindingParam, LixStorageConfig } from "../binding-types.js";
|
|
2
|
-
import type { CreateBranchOptions, ExecuteOptions,
|
|
2
|
+
import type { CreateBranchOptions, ExecuteOptions, LixBatchOptions, MergeBranchOptions, SwitchBranchOptions, LixTelemetrySpan } from "../types.js";
|
|
3
3
|
export type WorkerRequest = {
|
|
4
4
|
id: number;
|
|
5
5
|
operation: WorkerOperation;
|
|
@@ -35,18 +35,6 @@ export type WorkerOperation = {
|
|
|
35
35
|
kind: "activeBranchId";
|
|
36
36
|
} | {
|
|
37
37
|
kind: "activeAccountId";
|
|
38
|
-
} | {
|
|
39
|
-
kind: "clientState.entries";
|
|
40
|
-
} | {
|
|
41
|
-
kind: "clientState.get";
|
|
42
|
-
key: string;
|
|
43
|
-
} | {
|
|
44
|
-
kind: "clientState.set";
|
|
45
|
-
key: string;
|
|
46
|
-
value: JsonValue;
|
|
47
|
-
} | {
|
|
48
|
-
kind: "clientState.delete";
|
|
49
|
-
key: string;
|
|
50
38
|
} | {
|
|
51
39
|
kind: "createBranch";
|
|
52
40
|
options: CreateBranchOptions;
|
|
@@ -70,8 +58,6 @@ export type WorkerOperation = {
|
|
|
70
58
|
paths: string[];
|
|
71
59
|
} | {
|
|
72
60
|
kind: "syncDiskToLix";
|
|
73
|
-
} | {
|
|
74
|
-
kind: "exportSnapshot";
|
|
75
61
|
} | {
|
|
76
62
|
kind: "observe";
|
|
77
63
|
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.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -17,13 +17,9 @@
|
|
|
17
17
|
"workerd": "./dist/workerd.js",
|
|
18
18
|
"default": "./dist/workerd.js"
|
|
19
19
|
},
|
|
20
|
-
"./
|
|
21
|
-
"types": "./dist/remote/protocol.d.ts",
|
|
22
|
-
"default": "./dist/remote/protocol.js"
|
|
23
|
-
},
|
|
24
|
-
"./local-storage-adapter": {
|
|
25
|
-
"types": "./dist/local-storage-adapter.d.ts",
|
|
26
|
-
"default": "./dist/local-storage-adapter.js"
|
|
20
|
+
"./server-protocol": {
|
|
21
|
+
"types": "./dist/remote/server-protocol.d.ts",
|
|
22
|
+
"default": "./dist/remote/server-protocol.js"
|
|
27
23
|
}
|
|
28
24
|
},
|
|
29
25
|
"imports": {
|
|
@@ -57,10 +53,10 @@
|
|
|
57
53
|
"typecheck": "tsc -p tsconfig.test.json --noEmit"
|
|
58
54
|
},
|
|
59
55
|
"optionalDependencies": {
|
|
60
|
-
"@lix-js/sdk-darwin-arm64": "0.
|
|
61
|
-
"@lix-js/sdk-linux-arm64": "0.
|
|
62
|
-
"@lix-js/sdk-linux-x64": "0.
|
|
63
|
-
"@lix-js/sdk-win32-x64": "0.
|
|
56
|
+
"@lix-js/sdk-darwin-arm64": "0.12.0",
|
|
57
|
+
"@lix-js/sdk-linux-arm64": "0.12.0",
|
|
58
|
+
"@lix-js/sdk-linux-x64": "0.12.0",
|
|
59
|
+
"@lix-js/sdk-win32-x64": "0.12.0"
|
|
64
60
|
},
|
|
65
61
|
"devDependencies": {
|
|
66
62
|
"@vitest/browser-playwright": "4.1.10",
|
package/dist/client-state.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { LixBinding } from "./binding-types.js";
|
|
2
|
-
import type { JsonValue, LixSnapshotStorage } from "./types.js";
|
|
3
|
-
export declare const ACTIVE_BRANCH_CLIENT_STATE_KEY = "lix_active_branch_id";
|
|
4
|
-
export declare const ACTIVE_ACCOUNT_CLIENT_STATE_KEY = "lix_active_account_id";
|
|
5
|
-
export type LixClientState = {
|
|
6
|
-
/** Returns the hydrated client-local value without a network round trip. */
|
|
7
|
-
get<T extends JsonValue = JsonValue>(key: string): T | undefined;
|
|
8
|
-
/** Persists a client-local value in the configured client storage. */
|
|
9
|
-
set(key: string, value: JsonValue): Promise<void>;
|
|
10
|
-
/** Deletes a client-local value from the configured client storage. */
|
|
11
|
-
delete(key: string): Promise<void>;
|
|
12
|
-
/** Subscribes to successful mutations made through this client-state handle. */
|
|
13
|
-
subscribe(listener: () => void): () => void;
|
|
14
|
-
};
|
|
15
|
-
export type ManagedClientState = LixClientState & {
|
|
16
|
-
close(): Promise<void>;
|
|
17
|
-
};
|
|
18
|
-
export declare function unavailableClientState(): LixClientState;
|
|
19
|
-
type ClientStateBinding = LixBinding & {
|
|
20
|
-
exportSnapshot?: () => Promise<Uint8Array>;
|
|
21
|
-
};
|
|
22
|
-
export type OpenClientStateOptions = {
|
|
23
|
-
readonly binding: ClientStateBinding;
|
|
24
|
-
readonly saveSnapshot?: (snapshot: Uint8Array) => Promise<void>;
|
|
25
|
-
readonly closeBinding?: boolean;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Opens the typed client-state facade over a private local Rust Lix.
|
|
29
|
-
*
|
|
30
|
-
* Values are ordinary global, untracked `lix_key_value` rows. The physical
|
|
31
|
-
* prefix is intentionally private so built-in Lix key/value rows never leak
|
|
32
|
-
* through this small API.
|
|
33
|
-
*/
|
|
34
|
-
export declare function openClientState(options: OpenClientStateOptions): Promise<ManagedLixClientState>;
|
|
35
|
-
export declare class ManagedLixClientState implements LixClientState {
|
|
36
|
-
#private;
|
|
37
|
-
constructor(options: OpenClientStateOptions, initial: Map<string, JsonValue>);
|
|
38
|
-
get<T extends JsonValue = JsonValue>(key: string): T | undefined;
|
|
39
|
-
set(key: string, value: JsonValue): Promise<void>;
|
|
40
|
-
delete(key: string): Promise<void>;
|
|
41
|
-
subscribe(listener: () => void): () => void;
|
|
42
|
-
close(): Promise<void>;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Opens client state directly over snapshot storage without starting a local
|
|
46
|
-
* Lix runtime. This is used by remote Lix connections, where the storage
|
|
47
|
-
* option persists client-local state rather than the remote workspace.
|
|
48
|
-
*/
|
|
49
|
-
export declare function openStoredClientState(options: {
|
|
50
|
-
readonly storage: LixSnapshotStorage;
|
|
51
|
-
readonly namespace: string;
|
|
52
|
-
}): Promise<ManagedClientState>;
|
|
53
|
-
export {};
|