@lix-js/sdk 0.15.1 → 0.16.1

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.
@@ -9,6 +9,8 @@ export const __wbg_wasmremotelixtransaction_free: (a: number, b: number) => void
9
9
  export const __wbg_wasmremoteobserveevents_free: (a: number, b: number) => void;
10
10
  export const __wbg_wasmsnapshotexport_free: (a: number, b: number) => void;
11
11
  export const __wbg_wasmsnapshotrestore_free: (a: number, b: number) => void;
12
+ export const createHosted: (a: number) => number;
13
+ export const deleteHosted: (a: number) => number;
12
14
  export const openJsStorage: (a: number, b: number, c: number, d: number, e: number) => number;
13
15
  export const openJsStorageFromSnapshot: (a: number, b: number, c: number, d: number) => number;
14
16
  export const openMemory: (a: number, b: number, c: number, d: number) => number;
@@ -19,8 +21,10 @@ export const wasmlix_activeBranchId: (a: number) => number;
19
21
  export const wasmlix_beginTransaction: (a: number) => number;
20
22
  export const wasmlix_close: (a: number) => number;
21
23
  export const wasmlix_createBranch: (a: number, b: number) => number;
24
+ export const wasmlix_createHosted: (a: number, b: number) => number;
22
25
  export const wasmlix_execute: (a: number, b: number, c: number, d: number, e: number) => number;
23
26
  export const wasmlix_executeBatch: (a: number, b: number, c: number) => number;
27
+ export const wasmlix_exportReplicaRecovery: (a: number, b: number, c: number) => number;
24
28
  export const wasmlix_exportSnapshot: (a: number) => number;
25
29
  export const wasmlix_importFilesystemPaths: (a: number, b: number) => number;
26
30
  export const wasmlix_mergeBranch: (a: number, b: number) => number;
@@ -28,7 +32,9 @@ export const wasmlix_mergeBranchPreview: (a: number, b: number) => number;
28
32
  export const wasmlix_observe: (a: number, b: number, c: number, d: number) => number;
29
33
  export const wasmlix_openAnotherSession: (a: number, b: number) => number;
30
34
  export const wasmlix_openReport: (a: number, b: number) => void;
35
+ export const wasmlix_recoverReplica: (a: number, b: number, c: number) => number;
31
36
  export const wasmlix_redo: (a: number) => number;
37
+ export const wasmlix_replicaRecoverySources: (a: number) => number;
32
38
  export const wasmlix_setTelemetryParent: (a: number, b: number, c: number) => void;
33
39
  export const wasmlix_switchBranch: (a: number, b: number) => number;
34
40
  export const wasmlix_syncDiskToLix: (a: number) => number;
@@ -46,13 +52,16 @@ export const wasmremotelix_close: (a: number) => number;
46
52
  export const wasmremotelix_createBranch: (a: number, b: number) => number;
47
53
  export const wasmremotelix_execute: (a: number, b: number, c: number, d: number, e: number) => number;
48
54
  export const wasmremotelix_executeBatch: (a: number, b: number, c: number) => number;
55
+ export const wasmremotelix_exportReplicaRecovery: (a: number, b: number, c: number) => number;
49
56
  export const wasmremotelix_exportSnapshot: (a: number) => number;
50
57
  export const wasmremotelix_importFilesystemPaths: (a: number, b: number) => number;
51
58
  export const wasmremotelix_mergeBranch: (a: number, b: number) => number;
52
59
  export const wasmremotelix_mergeBranchPreview: (a: number, b: number) => number;
53
60
  export const wasmremotelix_observe: (a: number, b: number, c: number, d: number) => number;
54
61
  export const wasmremotelix_openAnotherSession: (a: number, b: number) => number;
62
+ export const wasmremotelix_recoverReplica: (a: number, b: number, c: number) => number;
55
63
  export const wasmremotelix_redo: (a: number) => number;
64
+ export const wasmremotelix_replicaRecoverySources: (a: number) => number;
56
65
  export const wasmremotelix_setTelemetryParent: (a: number, b: number) => void;
57
66
  export const wasmremotelix_switchBranch: (a: number, b: number) => number;
58
67
  export const wasmremotelix_syncDiskToLix: (a: number) => number;
@@ -69,9 +78,10 @@ export const wasmsnapshotrestore_cancel: (a: number) => number;
69
78
  export const wasmsnapshotrestore_finish: (a: number) => number;
70
79
  export const wasmsnapshotrestore_isComplete: (a: number) => number;
71
80
  export const wasmsnapshotrestore_write: (a: number, b: number, c: number) => number;
72
- export const __wasm_bindgen_func_elem_92636: (a: number, b: number, c: number, d: number) => void;
73
- export const __wasm_bindgen_func_elem_92638: (a: number, b: number, c: number, d: number) => void;
74
- export const __wasm_bindgen_func_elem_16813: (a: number, b: number) => void;
81
+ export const __wasm_bindgen_func_elem_95812: (a: number, b: number, c: number, d: number) => void;
82
+ export const __wasm_bindgen_func_elem_95814: (a: number, b: number, c: number, d: number) => void;
83
+ export const __wasm_bindgen_func_elem_17860: (a: number, b: number, c: number) => number;
84
+ export const __wasm_bindgen_func_elem_17859: (a: number, b: number) => void;
75
85
  export const __wbindgen_export: (a: number, b: number) => number;
76
86
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
77
87
  export const __wbindgen_export3: (a: number) => void;
@@ -1,7 +1,7 @@
1
1
  import type { LixBinding, LixStorageConfig } from "../binding-types.js";
2
- import type { LixTelemetryOptions, LixOpenProgress, LixOpenReport, SyncLixServerOptions } from "../types.js";
2
+ import type { LixTelemetryOptions, LixOpenProgress, LixOpenReport, LixServerOptions } from "../types.js";
3
3
  import { type WorkerConnection, type WorkerNotification, type WorkerOperation } from "./protocol.js";
4
- type SyncServerRuntimeOptions = Omit<SyncLixServerOptions, "mode">;
4
+ type SyncServerRuntimeOptions = LixServerOptions;
5
5
  export declare function openLixWorker(storage: LixStorageConfig, onDisposed?: () => void, telemetry?: LixTelemetryOptions, server?: SyncServerRuntimeOptions, onProgress?: (progress: LixOpenProgress) => void, snapshot?: ReadableStream<Uint8Array>): Promise<LixWorkerClient>;
6
6
  export declare function pumpSnapshotToWorker(client: LixWorkerClient, reader: ReadableStreamDefaultReader<Uint8Array>, snapshotId: number, open: Promise<unknown>): Promise<void>;
7
7
  /** Opens the local worker transport behind the semantic Lix binding. */
@@ -48,4 +48,7 @@ export declare class LixWorkerClient {
48
48
  private handleFatal;
49
49
  private rejectPending;
50
50
  }
51
+ export declare function hostedLixWorkerOperation<T>(operation: Extract<WorkerOperation, {
52
+ kind: "hosted.create" | "hosted.delete";
53
+ }>): Promise<T>;
51
54
  export {};
@@ -274,6 +274,9 @@ export function workerBinding(client, lease, sessionId) {
274
274
  });
275
275
  return workerTransactionBinding(request, transactionId);
276
276
  },
277
+ replicaRecoverySources: () => request({ kind: "replicaRecoverySources" }),
278
+ exportReplicaRecovery: (id) => request({ kind: "exportReplicaRecovery", id }),
279
+ recoverReplica: (id) => request({ kind: "recoverReplica", id }),
277
280
  activeBranchId: () => request({ kind: "activeBranchId" }),
278
281
  activeAccountId: () => request({ kind: "activeAccountId" }),
279
282
  createBranch: (options) => request({ kind: "createBranch", options }),
@@ -284,6 +287,7 @@ export function workerBinding(client, lease, sessionId) {
284
287
  mergeBranchPreview: (options) => request({ kind: "mergeBranchPreview", options }),
285
288
  mergeBranch: (options) => request({ kind: "mergeBranch", options }),
286
289
  syncDiskToLix: () => request({ kind: "syncDiskToLix" }),
290
+ createHosted: (server) => request({ kind: "hosted.createFrom", server }),
287
291
  exportSnapshot: () => {
288
292
  const exportId = request({ kind: "exportSnapshot" });
289
293
  let canceled = false;
@@ -757,3 +761,13 @@ async function resolveDirectSyncServer(server) {
757
761
  fetch: server.fetch,
758
762
  };
759
763
  }
764
+ export async function hostedLixWorkerOperation(operation) {
765
+ const client = new LixWorkerClient();
766
+ client.beginLease();
767
+ try {
768
+ return await client.request(operation, 0);
769
+ }
770
+ finally {
771
+ await client.terminate();
772
+ }
773
+ }
@@ -1,4 +1,4 @@
1
- import { openLixBinding } from "#binding";
1
+ import { openLixBinding, createHostedBinding, deleteHostedBinding, } from "#binding";
2
2
  import { deserializeWorkerError, serializeWorkerError, } from "./protocol.js";
3
3
  export function startWorkerHost(endpoint, openBinding = openLixBinding) {
4
4
  const sessions = new Map();
@@ -51,8 +51,8 @@ export function startWorkerHost(endpoint, openBinding = openLixBinding) {
51
51
  if (message.operation.kind === "observe") {
52
52
  const operation = message.operation;
53
53
  // Observation setup is metadata-only. Keeping it behind the global
54
- // finite-operation queue lets an authority mutation that is waiting for
55
- // local publication block a newly mounted server-first History query.
54
+ // finite-operation queue lets a long-running operation block a newly
55
+ // mounted query, including one that needs lazy history hydration.
56
56
  // The live `next()` lane is already independent for the same reason.
57
57
  void respond(message, () => handleObserveRegistration(message.sessionId, operation.sql, operation.params));
58
58
  return;
@@ -60,7 +60,9 @@ export function startWorkerHost(endpoint, openBinding = openLixBinding) {
60
60
  finiteQueue = finiteQueue.then(async () => {
61
61
  try {
62
62
  await respond(message, async () => {
63
- if (message.operation.kind !== "open") {
63
+ if (message.operation.kind !== "open" &&
64
+ message.operation.kind !== "hosted.create" &&
65
+ message.operation.kind !== "hosted.delete") {
64
66
  requiredLix(message.sessionId).setTelemetryParent(message.telemetryParent);
65
67
  }
66
68
  return handleFiniteOperation(message.sessionId, message.operation, message.telemetryParent);
@@ -163,6 +165,16 @@ export function startWorkerHost(endpoint, openBinding = openLixBinding) {
163
165
  }
164
166
  async function handleFiniteOperation(sessionId, operation, telemetryParent) {
165
167
  switch (operation.kind) {
168
+ case "hosted.create":
169
+ return createHostedBinding(operation.server);
170
+ case "hosted.delete":
171
+ return deleteHostedBinding(operation.server);
172
+ case "hosted.createFrom": {
173
+ const binding = requiredLix(sessionId);
174
+ if (!binding.createHosted)
175
+ throw new TypeError("createLix() from requires a local Lix");
176
+ return binding.createHosted(operation.server);
177
+ }
166
178
  case "open":
167
179
  if (sessions.size > 0)
168
180
  throw workerStateError("Lix worker is already open");
@@ -218,6 +230,12 @@ export function startWorkerHost(endpoint, openBinding = openLixBinding) {
218
230
  await transaction.rollback();
219
231
  return undefined;
220
232
  }
233
+ case "replicaRecoverySources":
234
+ return requiredLix(sessionId).replicaRecoverySources();
235
+ case "exportReplicaRecovery":
236
+ return requiredLix(sessionId).exportReplicaRecovery(operation.id);
237
+ case "recoverReplica":
238
+ return requiredLix(sessionId).recoverReplica(operation.id);
221
239
  case "activeBranchId":
222
240
  return requiredLix(sessionId).activeBranchId();
223
241
  case "activeAccountId":
@@ -238,18 +256,17 @@ export function startWorkerHost(endpoint, openBinding = openLixBinding) {
238
256
  return requiredLix(sessionId).importFilesystemPaths(operation.paths);
239
257
  case "syncDiskToLix":
240
258
  return requiredLix(sessionId).syncDiskToLix();
241
- case "exportSnapshot":
242
- {
243
- const binding = requiredLix(sessionId);
244
- const exportSnapshot = binding.exportSnapshot;
245
- if (!exportSnapshot) {
246
- throw workerStateError("this Lix binding cannot export snapshots");
247
- }
248
- const snapshot = exportSnapshot.call(binding);
249
- const exportId = nextSnapshotExportId++;
250
- snapshotExports.set(exportId, snapshot);
251
- return exportId;
259
+ case "exportSnapshot": {
260
+ const binding = requiredLix(sessionId);
261
+ const exportSnapshot = binding.exportSnapshot;
262
+ if (!exportSnapshot) {
263
+ throw workerStateError("this Lix binding cannot export snapshots");
252
264
  }
265
+ const snapshot = exportSnapshot.call(binding);
266
+ const exportId = nextSnapshotExportId++;
267
+ snapshotExports.set(exportId, snapshot);
268
+ return exportId;
269
+ }
253
270
  case "exportSnapshot.next":
254
271
  throw workerStateError("snapshot pulls bypass the finite operation queue");
255
272
  case "exportSnapshot.cancel":
@@ -36,6 +36,15 @@ export type WorkerRequest = {
36
36
  operation: WorkerOperation;
37
37
  };
38
38
  export type WorkerOperation = {
39
+ kind: "hosted.create";
40
+ server: import("../binding-types.js").HostedServerBindingOptions;
41
+ } | {
42
+ kind: "hosted.delete";
43
+ server: import("../binding-types.js").HostedServerBindingOptions;
44
+ } | {
45
+ kind: "hosted.createFrom";
46
+ server: import("../binding-types.js").HostedServerBindingOptions;
47
+ } | {
39
48
  kind: "open";
40
49
  storage: LixStorageConfig;
41
50
  telemetryEnabled: boolean;
@@ -75,6 +84,14 @@ export type WorkerOperation = {
75
84
  } | {
76
85
  kind: "transaction.rollback";
77
86
  transactionId: number;
87
+ } | {
88
+ kind: "replicaRecoverySources";
89
+ } | {
90
+ kind: "exportReplicaRecovery";
91
+ id: string;
92
+ } | {
93
+ kind: "recoverReplica";
94
+ id: string;
78
95
  } | {
79
96
  kind: "activeBranchId";
80
97
  } | {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lix-js/sdk",
3
3
  "type": "module",
4
- "version": "0.15.1",
4
+ "version": "0.16.1",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -11,10 +11,6 @@
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
13
  "default": "./dist/index.js"
14
- },
15
- "./server-protocol": {
16
- "types": "./dist/remote/server-protocol.d.ts",
17
- "default": "./dist/remote/server-protocol.js"
18
14
  }
19
15
  },
20
16
  "imports": {
@@ -49,10 +45,10 @@
49
45
  "typecheck": "tsc -p tsconfig.test.json --noEmit"
50
46
  },
51
47
  "optionalDependencies": {
52
- "@lix-js/sdk-darwin-arm64": "0.15.1",
53
- "@lix-js/sdk-linux-arm64": "0.15.1",
54
- "@lix-js/sdk-linux-x64": "0.15.1",
55
- "@lix-js/sdk-win32-x64": "0.15.1"
48
+ "@lix-js/sdk-darwin-arm64": "0.16.1",
49
+ "@lix-js/sdk-linux-arm64": "0.16.1",
50
+ "@lix-js/sdk-linux-x64": "0.16.1",
51
+ "@lix-js/sdk-win32-x64": "0.16.1"
56
52
  },
57
53
  "devDependencies": {
58
54
  "@vitest/browser-playwright": "4.1.10",
@@ -1,185 +0,0 @@
1
- import type { BindingExecuteResult, BindingObserveEvent } from "../binding-types.js";
2
- import type { NativeLixValue } from "../value.js";
3
- export declare const SERVER_PROTOCOL_VERSION = 6;
4
- export type WireValue = {
5
- kind: "null";
6
- value: null;
7
- } | {
8
- kind: "bool";
9
- value: boolean;
10
- } | {
11
- kind: "int";
12
- value: number;
13
- } | {
14
- kind: "float";
15
- value: number;
16
- } | {
17
- kind: "text";
18
- value: string;
19
- } | {
20
- kind: "jsonb";
21
- value: unknown;
22
- } | {
23
- kind: "row_ref";
24
- value: string;
25
- } | {
26
- kind: "timestamptz";
27
- value: string;
28
- } | {
29
- kind: "blob";
30
- base64: string;
31
- };
32
- export type WireRequestBlobSplice = {
33
- kind: "blob-splice";
34
- baseSha256: string;
35
- resultSha256: string;
36
- prefixBytes: number;
37
- suffixBytes: number;
38
- insertBase64: string;
39
- };
40
- export type WireRequestValue = WireValue | WireRequestBlobSplice;
41
- export type ServerProtocolHandshake = {
42
- protocolVersion: number;
43
- activeBranchId: string;
44
- activeAccountId: string;
45
- sessionId: string;
46
- };
47
- export type ServerProtocolHandshakeRequest = {
48
- activeBranchId?: string;
49
- };
50
- export type ServerProtocolExecuteRequest = {
51
- sql: string;
52
- params: WireRequestValue[];
53
- options?: {
54
- originKey?: string;
55
- };
56
- cacheBlobs?: true;
57
- };
58
- export type ServerProtocolExecuteBatchRequest = {
59
- statements: Array<{
60
- sql: string;
61
- params: WireRequestValue[];
62
- label?: string;
63
- }>;
64
- options?: {
65
- originKey?: string;
66
- };
67
- cacheBlobs?: true;
68
- };
69
- export type ServerProtocolExecuteResponse = {
70
- columns: BindingExecuteResult["columns"];
71
- rows: WireValue[][];
72
- rowsAffected: number;
73
- notices: Array<{
74
- code: string;
75
- message: string;
76
- hint?: string;
77
- }>;
78
- };
79
- export type ServerProtocolExecuteBatchResponse = ServerProtocolExecuteResponse & {
80
- statementIndex: number;
81
- label?: string;
82
- };
83
- export type ServerProtocolObserveRequest = {
84
- sql: string;
85
- params: WireValue[];
86
- };
87
- export type ServerProtocolObserveSubscription = ServerProtocolObserveRequest & {
88
- id: string;
89
- };
90
- export type ServerProtocolMultiplexObserveRequest = {
91
- subscriptions: ServerProtocolObserveSubscription[];
92
- };
93
- type ServerProtocolObserveEventBase = {
94
- sequence: number;
95
- mutationSequence: number;
96
- };
97
- export type ServerProtocolObserveBlobDelta = {
98
- kind: "single-blob-splice";
99
- baseSequence: number;
100
- prefixBytes: number;
101
- suffixBytes: number;
102
- insertBase64: string;
103
- };
104
- type ServerProtocolObserveRowSplice = {
105
- kind: "row-splice";
106
- baseSequence: number;
107
- prefixRows: number;
108
- deleteRows: number;
109
- insertRows: WireValue[][];
110
- };
111
- type ServerProtocolObserveDelta = ServerProtocolObserveBlobDelta | ServerProtocolObserveRowSplice;
112
- export type ServerProtocolObserveEvent = ServerProtocolObserveEventBase & ({
113
- result: ServerProtocolExecuteResponse;
114
- delta?: never;
115
- } | {
116
- result?: never;
117
- delta: ServerProtocolObserveDelta;
118
- });
119
- export type ServerProtocolMultiplexObserveEvent = ServerProtocolObserveEvent & {
120
- subscriptionId: string;
121
- };
122
- export type ServerProtocolCreateBranchRequest = {
123
- id?: string;
124
- name: string;
125
- fromCommitId?: string;
126
- };
127
- export type ServerProtocolCreateBranchResponse = {
128
- id: string;
129
- name: string;
130
- hidden: boolean;
131
- commitId: string;
132
- };
133
- export type ServerProtocolUndoResponse = {
134
- branchId: string;
135
- targetCommitId: string;
136
- inverseCommitId: string;
137
- };
138
- export type ServerProtocolRedoResponse = {
139
- branchId: string;
140
- targetCommitId: string;
141
- replayCommitId: string;
142
- };
143
- export type ServerProtocolSwitchBranchRequest = {
144
- branchId: string;
145
- };
146
- export type ServerProtocolSwitchBranchResponse = {
147
- branchId: string;
148
- };
149
- export type ServerProtocolErrorBody = {
150
- error: {
151
- code?: string;
152
- message?: string;
153
- hint?: string;
154
- details?: unknown;
155
- };
156
- };
157
- export type ServerProtocolObserveErrorEvent = ServerProtocolErrorBody & {
158
- retryable?: boolean;
159
- };
160
- export type ServerProtocolMultiplexObserveErrorEvent = ServerProtocolObserveErrorEvent & {
161
- subscriptionId?: string;
162
- };
163
- export declare function encodeWireValue(value: NativeLixValue): WireValue;
164
- export declare function decodeExecuteResult(value: unknown): BindingExecuteResult;
165
- export declare function decodeExecuteBatchResult(value: unknown): BindingExecuteResult;
166
- export declare function decodeHandshake(value: unknown): ServerProtocolHandshake;
167
- export declare function decodeObserveEvent(value: unknown, base?: BindingObserveEvent): BindingObserveEvent;
168
- export declare function remoteError(code: string, message: string, options?: {
169
- hint?: string;
170
- details?: unknown;
171
- status?: number;
172
- }): Error & {
173
- code: string;
174
- hint?: string;
175
- details?: unknown;
176
- status?: number;
177
- };
178
- export declare function protocolError(message: string): Error & {
179
- code: string;
180
- };
181
- export declare function errorFromResponseBody(value: unknown, status?: number): Error & {
182
- code: string;
183
- };
184
- export declare function record(value: unknown, description: string): Record<string, unknown>;
185
- export {};