@lix-js/sdk 0.15.0 → 0.16.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 CHANGED
@@ -22,10 +22,51 @@ console.log(result.rows[0]?.message);
22
22
  await lix.close();
23
23
  ```
24
24
 
25
+ ## Hosted lifecycle
26
+
27
+ `openLix()` selects execution from the supplied locations:
28
+
29
+ | Options | Behavior |
30
+ | --- | --- |
31
+ | Neither | Fresh in-memory repository |
32
+ | `storage` | Local repository, initialized if empty |
33
+ | `server` | Execute against an existing hosted repository |
34
+ | `storage` and `server` | Synchronized local reads; mutations execute on the server |
35
+
36
+ Creation and deletion are explicit server operations:
37
+
38
+ ```ts
39
+ import { createLix, deleteLix, openLix } from "@lix-js/sdk";
40
+
41
+ const repository = await createLix({
42
+ server: { url: "https://example.com", headers: getAuthHeaders },
43
+ from: localLix, // Omit to create an empty repository.
44
+ });
45
+
46
+ const remote = await openLix({
47
+ server: { url: repository.url, headers: getAuthHeaders },
48
+ });
49
+ await remote.close();
50
+ await deleteLix({ server: { url: repository.url, headers: getAuthHeaders } });
51
+ ```
52
+
53
+ `from` captures a consistent repository snapshot, including history and untracked
54
+ rows. The source remains open. Creation returns `{ id, url }`, not a session.
55
+ Use the same optional `idempotencyKey` when retrying creation after an uncertain
56
+ response. Deletion removes the hosted repository and leaves local copies intact. Opening
57
+ or synchronizing never implicitly creates a missing hosted repository.
58
+
59
+ Browser creation from a local repository requires Fetch request streaming.
60
+ Browsers without that support return `LIX_UNSUPPORTED_OPERATION`; Lix does not
61
+ buffer the complete repository as a fallback. Browser Fetch may also require an
62
+ HTTP/2 or HTTP/3 connection for streaming uploads. Empty creation and remote
63
+ execution do not require streaming uploads.
64
+
25
65
  ## Synchronized local repositories
26
66
 
27
- Use sync mode when reads and writes should execute locally while Lix exchanges
28
- commits with a hosted repository in the background:
67
+ Combine storage with a server to keep a synchronized local read replica.
68
+ Certified current-state reads can execute locally; mutations execute on the
69
+ server:
29
70
 
30
71
  ```ts
31
72
  import { openLix } from "@lix-js/sdk";
@@ -34,7 +75,6 @@ import { OpfsStorage } from "@lix-js/storage-opfs";
34
75
  const lix = await openLix({
35
76
  storage: new OpfsStorage({ name: "acme" }),
36
77
  server: {
37
- mode: "sync",
38
78
  url: "https://example.com/lix/01936f4e-7b6c-7c3d-8f9a-123456789abc",
39
79
  headers: async () => ({
40
80
  Authorization: `Bearer ${await accessToken()}`,
@@ -43,9 +83,10 @@ const lix = await openLix({
43
83
  });
44
84
  ```
45
85
 
46
- `await lix.execute(...)` means that the local transaction committed. It does
47
- not mean that the server has received the commit. Current data and new commits
48
- synchronize automatically; older history and binary content load when needed.
86
+ A successful mutation confirms server acceptance. The local replica receives
87
+ the resulting certified state automatically; older history and binary content
88
+ load when needed. Connected mutations require the server, and cached reads may
89
+ also need fresh server certification.
49
90
  See [Collaboration and Sync](https://lix.dev/docs/collaboration-and-sync).
50
91
 
51
92
  ## Remote repositories
@@ -55,7 +96,6 @@ Use the same Lix client as a thin client against a hosted repository:
55
96
  ```ts
56
97
  const lix = await openLix({
57
98
  server: {
58
- mode: "remote",
59
99
  url: "https://example.com/lix/01936f4e-7b6c-7c3d-8f9a-123456789abc",
60
100
  headers: async () => ({
61
101
  Authorization: `Bearer ${await accessToken()}`,
@@ -161,6 +201,11 @@ const merge = await lix.mergeBranch({ sourceBranchId: draft.id });
161
201
 
162
202
  ## Transactions
163
203
 
204
+ `beginTransaction()` captures the current branch and account in an independent
205
+ transaction context. Use `tx.execute()` for transaction work; its reads see staged
206
+ writes. Ordinary reads and observers on `lix` continue to see committed data while
207
+ the transaction is open. Commit or roll back before closing `lix`.
208
+
164
209
  ```ts
165
210
  const tx = await lix.beginTransaction();
166
211
 
@@ -41,6 +41,7 @@ export type BindingBatchStatement = {
41
41
  label?: string;
42
42
  };
43
43
  export type LixBinding = {
44
+ createHosted?(server: HostedServerBindingOptions): Promise<import("./types.js").HostedLix>;
44
45
  openReport?(): LixOpenReport | undefined;
45
46
  setTelemetryParent(parent?: TelemetryParentContext): void;
46
47
  openAnotherSession(options: OpenAnotherSessionOptions): Promise<LixBinding>;
@@ -88,3 +89,8 @@ export type LixStorageConfig = {
88
89
  path: string;
89
90
  syncAllFiles: boolean;
90
91
  };
92
+ export type HostedServerBindingOptions = {
93
+ idempotencyKey?: string;
94
+ url: string;
95
+ headers: [string, string][];
96
+ };
@@ -1,2 +1,4 @@
1
1
  import type { LixStorageConfig, LixBinding, SyncServerBindingOptions, TelemetryDispatch, TelemetryParentContext, OpenProgressDispatch } from "./binding-types.js";
2
2
  export declare function openLixBinding(storage: LixStorageConfig, telemetry?: TelemetryDispatch, telemetryParent?: TelemetryParentContext, server?: SyncServerBindingOptions, openProgress?: OpenProgressDispatch, snapshot?: ReadableStream<Uint8Array>): Promise<LixBinding>;
3
+ export declare function createHostedBinding(server: import("./binding-types.js").HostedServerBindingOptions): Promise<import("./types.js").HostedLix>;
4
+ export declare function deleteHostedBinding(server: import("./binding-types.js").HostedServerBindingOptions): Promise<void>;
@@ -2,7 +2,9 @@ import { initializeWasm } from "./wasm-init.js";
2
2
  import { restoreSnapshot } from "./snapshot-restore.js";
3
3
  // Generated before TypeScript compilation and emitted beside this module.
4
4
  // @ts-ignore Generated by build:wasm and absent in source-only checks.
5
- import { openJsStorage, openJsStorageFromSnapshot, openMemory, openMemoryFromSnapshot, } from "./wasm/lix_js_sdk.js";
5
+ import { createHosted, deleteHosted, openJsStorage, openJsStorageFromSnapshot, openMemory, openMemoryFromSnapshot,
6
+ // @ts-ignore Generated by build:wasm and absent in source-only checks.
7
+ } from "./wasm/lix_js_sdk.js";
6
8
  export async function openLixBinding(storage, telemetry, telemetryParent, server, openProgress, snapshot) {
7
9
  await initializeWasm();
8
10
  switch (storage.kind) {
@@ -32,3 +34,11 @@ export async function openLixBinding(storage, telemetry, telemetryParent, server
32
34
  throw new Error("FilesystemStorage is only available in Node.js");
33
35
  }
34
36
  }
37
+ export async function createHostedBinding(server) {
38
+ await initializeWasm();
39
+ return createHosted(server);
40
+ }
41
+ export async function deleteHostedBinding(server) {
42
+ await initializeWasm();
43
+ await deleteHosted(server);
44
+ }
@@ -1,3 +1,5 @@
1
1
  import type { LixStorageConfig, LixBinding, SyncServerBindingOptions, TelemetryDispatch, TelemetryParentContext, OpenProgressDispatch } from "./binding-types.js";
2
2
  export declare function openLixBinding(storage: LixStorageConfig, telemetry?: TelemetryDispatch, telemetryParent?: TelemetryParentContext, server?: SyncServerBindingOptions, openProgress?: OpenProgressDispatch, snapshot?: ReadableStream<Uint8Array>): Promise<LixBinding>;
3
3
  export declare function openNativeLixBinding(storage: LixStorageConfig, telemetry?: TelemetryDispatch, telemetryParent?: TelemetryParentContext, server?: SyncServerBindingOptions, openProgress?: OpenProgressDispatch, snapshot?: ReadableStream<Uint8Array>): Promise<LixBinding>;
4
+ export declare function createHostedBinding(server: import("./binding-types.js").HostedServerBindingOptions): Promise<import("./types.js").HostedLix>;
5
+ export declare function deleteHostedBinding(server: import("./binding-types.js").HostedServerBindingOptions): Promise<void>;
@@ -62,7 +62,7 @@ class NativeAddonUnavailableError extends Error {
62
62
  this.name = "NativeAddonUnavailableError";
63
63
  }
64
64
  }
65
- function loadNativeAddon() {
65
+ function loadAddon() {
66
66
  if (addon)
67
67
  return addon;
68
68
  if (addonLoadError)
@@ -114,7 +114,7 @@ export async function openNativeLixBinding(storage, telemetry, telemetryParent,
114
114
  : undefined;
115
115
  switch (storage.kind) {
116
116
  case "memory": {
117
- const nativeAddon = loadNativeAddon();
117
+ const nativeAddon = loadAddon();
118
118
  const nativeTelemetry = telemetry
119
119
  ? (spanJson) => telemetry(JSON.parse(spanJson))
120
120
  : undefined;
@@ -130,7 +130,7 @@ export async function openNativeLixBinding(storage, telemetry, telemetryParent,
130
130
  case "jsStorage":
131
131
  throw new Error("JavaScript storage providers are only available in browsers");
132
132
  case "filesystem": {
133
- const nativeAddon = loadNativeAddon();
133
+ const nativeAddon = loadAddon();
134
134
  const nativeTelemetry = telemetry
135
135
  ? (spanJson) => telemetry(JSON.parse(spanJson))
136
136
  : undefined;
@@ -145,3 +145,9 @@ export async function openNativeLixBinding(storage, telemetry, telemetryParent,
145
145
  }
146
146
  }
147
147
  }
148
+ export async function createHostedBinding(server) {
149
+ return loadAddon().createHosted(server.url, server.headers, server.idempotencyKey);
150
+ }
151
+ export async function deleteHostedBinding(server) {
152
+ await loadAddon().deleteHosted(server.url, server.headers);
153
+ }
@@ -0,0 +1,5 @@
1
+ import type { CreateLixOptions, DeleteLixOptions, HostedLix } from "./types.js";
2
+ /** Creates a hosted repository, optionally from a consistent snapshot of a local Lix. */
3
+ export declare function createLix(options: CreateLixOptions): Promise<HostedLix>;
4
+ /** Deletes the hosted repository. Local replicas are not deleted. */
5
+ export declare function deleteLix(options: DeleteLixOptions): Promise<void>;
@@ -0,0 +1,36 @@
1
+ import { createHostedFromLix } from "./lix.js";
2
+ import { hostedLixWorkerOperation } from "./worker/client.js";
3
+ async function resolveServer(server) {
4
+ if (!server || typeof server !== "object")
5
+ throw new TypeError("A server is required");
6
+ if ("fetch" in server && server.fetch !== undefined)
7
+ throw new TypeError("hosted lifecycle does not accept a custom fetch");
8
+ if ("mode" in server)
9
+ throw new TypeError("server.mode was removed");
10
+ const url = new URL(server.url).toString();
11
+ const headers = new Headers(typeof server.headers === "function"
12
+ ? await server.headers()
13
+ : server.headers);
14
+ const entries = [];
15
+ headers.forEach((value, key) => entries.push([key, value]));
16
+ return { url, headers: entries };
17
+ }
18
+ /** Creates a hosted repository, optionally from a consistent snapshot of a local Lix. */
19
+ export async function createLix(options) {
20
+ if (options.from !== undefined) {
21
+ return createHostedFromLix(options.from, async () => ({
22
+ ...(await resolveServer(options.server)),
23
+ idempotencyKey: options.idempotencyKey,
24
+ }));
25
+ }
26
+ const server = await resolveServer(options.server);
27
+ return hostedLixWorkerOperation({
28
+ kind: "hosted.create",
29
+ server: { ...server, idempotencyKey: options.idempotencyKey },
30
+ });
31
+ }
32
+ /** Deletes the hosted repository. Local replicas are not deleted. */
33
+ export async function deleteLix(options) {
34
+ const server = await resolveServer(options.server);
35
+ await hostedLixWorkerOperation({ kind: "hosted.delete", server });
36
+ }
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export type { LixStorage, LixStorageBound, LixStorageChangeWatch, LixStorageComm
3
3
  export { LixStorageError } from "./storage-adapter.js";
4
4
  export { bundledPluginArchives, type BundledPluginArchive, } from "./bundled-plugins.js";
5
5
  export { Value } from "./value.js";
6
- export type { CreateBranchOptions, CreateBranchReceipt, RedoReceipt, ExecuteOptions, ExecuteResult, ExecuteBatchResult, LixBatchOptions, LixBatchStatement, JsonValue, LixValue, ResultArrayRow, ResultColumn, ResultColumnType, ResultObjectRow, ResultRow, MergeBranchOptions, MergeBranchOutcome, MergeBranchPreview, MergeBranchReceipt, MergeChangeStats, MergeConflict, MergeConflictSide, ObserveEvent, OpenLixOptions, OpenAnotherSessionOptions, LixTelemetryOptions, LixTelemetryParentContext, LixTelemetrySpan, LixTelemetrySpanLink, LixOpenMigrationReport, LixOpenPhase, LixOpenProgress, LixOpenProgressOptions, LixOpenReport, RemoteLixFetch, RemoteLixServerOptions, SyncLixServerOptions, UndoReceipt, SqlParam, SwitchBranchOptions, SwitchBranchReceipt, } from "./types.js";
6
+ export type { CreateBranchOptions, CreateBranchReceipt, RedoReceipt, ExecuteOptions, ExecuteResult, ExecuteBatchResult, LixBatchOptions, LixBatchStatement, JsonValue, LixValue, ResultArrayRow, ResultColumn, ResultColumnType, ResultObjectRow, ResultRow, MergeBranchOptions, MergeBranchOutcome, MergeBranchPreview, MergeBranchReceipt, MergeChangeStats, MergeConflict, MergeConflictSide, ObserveEvent, OpenLixOptions, OpenAnotherSessionOptions, LixTelemetryOptions, LixTelemetryParentContext, LixTelemetrySpan, LixTelemetrySpanLink, LixOpenMigrationReport, LixOpenPhase, LixOpenProgress, LixOpenProgressOptions, LixOpenReport, RemoteLixFetch, LixServerOptions, HostedLix, CreateLixOptions, DeleteLixOptions, UndoReceipt, SqlParam, SwitchBranchOptions, SwitchBranchReceipt, } from "./types.js";
7
+ export { createLix, deleteLix } from "./hosted-lix.js";
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export { Lix, LixTransaction, ObserveEvents, openLix } from "./open-lix.js";
2
2
  export { LixStorageError } from "./storage-adapter.js";
3
3
  export { bundledPluginArchives, } from "./bundled-plugins.js";
4
4
  export { Value } from "./value.js";
5
+ export { createLix, deleteLix } from "./hosted-lix.js";
package/dist/lix.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { LixBinding, LixTransactionBinding, ObserveEventsBinding } from "./binding-types.js";
2
2
  import type { CreateBranchOptions, CreateBranchReceipt, RedoReceipt, ExecuteOptions, ExecuteResult, ExecuteBatchResult, LixBatchOptions, LixBatchStatement, MergeBranchOptions, MergeBranchPreview, MergeBranchReceipt, ObserveEvent, OpenAnotherSessionOptions, LixOpenReport, SqlParam, ResultArrayRow, ResultObjectRow, ResultRow, SwitchBranchOptions, SwitchBranchReceipt, UndoReceipt } from "./types.js";
3
+ /** @internal Used by createLix without adding another method to Lix. */
4
+ export declare function createHostedFromLix(lix: Lix, server: () => Promise<import("./binding-types.js").HostedServerBindingOptions>): Promise<import("./types.js").HostedLix>;
3
5
  export declare class Lix {
4
6
  #private;
5
7
  private readonly binding;
package/dist/lix.js CHANGED
@@ -13,6 +13,14 @@ const observeFinalizer = new FinalizationRegistry(({ observe, onClose }) => {
13
13
  events?.close();
14
14
  });
15
15
  });
16
+ const hostedCreators = new WeakMap();
17
+ /** @internal Used by createLix without adding another method to Lix. */
18
+ export function createHostedFromLix(lix, server) {
19
+ const create = hostedCreators.get(lix);
20
+ if (!create)
21
+ throw new TypeError("createLix() from must be an open local Lix");
22
+ return create(server);
23
+ }
16
24
  export class Lix {
17
25
  binding;
18
26
  openReport;
@@ -27,6 +35,11 @@ export class Lix {
27
35
  #acceptingOperations = true;
28
36
  constructor(binding) {
29
37
  this.binding = binding;
38
+ hostedCreators.set(this, (server) => this.#runOperation(async () => {
39
+ if (!binding.createHosted)
40
+ throw new TypeError("createLix() from requires a local Lix");
41
+ return binding.createHosted(await server());
42
+ }));
30
43
  const report = binding.openReport?.();
31
44
  this.openReport = report
32
45
  ? Object.freeze({
package/dist/open-lix.js CHANGED
@@ -26,37 +26,34 @@ async function openLixInternal(options, snapshot) {
26
26
  throw new TypeError("openLix() onProgress must be a function");
27
27
  }
28
28
  if (options.server !== undefined) {
29
+ if ("mode" in options.server)
30
+ throw new TypeError("server.mode was removed; provide storage for synchronization or omit it for remote execution");
29
31
  if (snapshot) {
30
32
  throw new TypeError("openLix.fromSnapshot() does not accept server mode");
31
33
  }
32
- if (options.server.mode === "remote") {
34
+ if (options.storage === undefined) {
35
+ if (options.telemetry !== undefined || options.onProgress !== undefined)
36
+ throw new TypeError("remote execution does not accept local telemetry or onProgress");
33
37
  const { openRemoteLixBinding } = await import("./remote/client.js");
34
- if ("storage" in options && options.storage !== undefined) {
35
- throw new TypeError("openLix() remote mode does not accept storage");
36
- }
37
38
  return new Lix(await openRemoteLixBinding(options.server));
38
39
  }
39
40
  }
40
- const syncServer = options.server?.mode === "sync"
41
+ const syncServer = options.server !== undefined && options.storage !== undefined
41
42
  ? {
42
43
  url: new URL(options.server.url).toString(),
43
44
  headers: options.server.headers,
44
45
  fetch: options.server.fetch,
45
46
  }
46
47
  : undefined;
47
- if (syncServer?.fetch !== undefined && typeof syncServer.fetch !== "function") {
48
+ if (syncServer?.fetch !== undefined &&
49
+ typeof syncServer.fetch !== "function") {
48
50
  throw new TypeError("openLix() sync server fetch must be a function");
49
51
  }
50
- if (syncServer?.headers !== undefined && typeof syncServer.headers !== "function") {
52
+ if (syncServer?.headers !== undefined &&
53
+ typeof syncServer.headers !== "function") {
51
54
  // Validate static headers before opening a worker/native runtime.
52
55
  new Headers(syncServer.headers);
53
56
  }
54
- if (options.server !== undefined && syncServer === undefined) {
55
- throw new TypeError("openLix() server mode must be 'remote' or 'sync'");
56
- }
57
- if (syncServer !== undefined && options.storage === undefined) {
58
- throw new TypeError("openLix() sync mode requires a durability-capable storage adapter");
59
- }
60
57
  const { openLixWorkerBinding } = await import("./worker/client.js");
61
58
  if (options.storage === undefined) {
62
59
  const binding = await openLixWorkerBinding({ kind: "memory" }, undefined, options.telemetry, syncServer, options.onProgress, snapshot);
@@ -1,7 +1,7 @@
1
1
  import type { LixBinding } from "../binding-types.js";
2
- import type { RemoteLixServerOptions } from "../types.js";
2
+ import type { LixServerOptions } from "../types.js";
3
3
  type RemoteLixClientOptions = {
4
4
  initialActiveBranchId?: string;
5
5
  };
6
- export declare function openRemoteLixBinding(options: RemoteLixServerOptions, clientOptions?: RemoteLixClientOptions): Promise<LixBinding>;
6
+ export declare function openRemoteLixBinding(options: LixServerOptions, clientOptions?: RemoteLixClientOptions): Promise<LixBinding>;
7
7
  export {};
@@ -6,9 +6,6 @@ export async function openRemoteLixBinding(options, clientOptions = {}) {
6
6
  if (!options || typeof options !== "object") {
7
7
  throw new TypeError("openLix() remote server must be an object");
8
8
  }
9
- if (options.mode !== "remote") {
10
- throw new TypeError("openLix() remote server mode must be 'remote'");
11
- }
12
9
  const remoteFetch = options.fetch ?? globalThis.fetch?.bind(globalThis);
13
10
  if (typeof remoteFetch !== "function") {
14
11
  throw new TypeError("openLix() remote mode requires fetch");
@@ -1,6 +1,6 @@
1
1
  import type { BindingExecuteResult, BindingObserveEvent } from "../binding-types.js";
2
2
  import type { NativeLixValue } from "../value.js";
3
- export declare const SERVER_PROTOCOL_VERSION = 6;
3
+ export declare const SERVER_PROTOCOL_VERSION = 7;
4
4
  export type WireValue = {
5
5
  kind: "null";
6
6
  value: null;
@@ -1,4 +1,4 @@
1
- export const SERVER_PROTOCOL_VERSION = 6;
1
+ export const SERVER_PROTOCOL_VERSION = 7;
2
2
  export function encodeWireValue(value) {
3
3
  switch (value.kind) {
4
4
  case "null":
package/dist/types.d.ts CHANGED
@@ -1,24 +1,22 @@
1
1
  export type RemoteLixFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
2
- export type RemoteLixServerOptions = {
3
- mode: "remote";
4
- /** Stable HTTPS locator whose path is exactly `/lix/{uuid}`. HTTP is loopback-only. */
2
+ /** A Lix protocol endpoint. Host URL for creation; repository URL for opening/deletion. */
3
+ export type LixServerOptions = {
5
4
  url: string | URL;
6
5
  headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
7
6
  fetch?: RemoteLixFetch;
8
7
  };
9
- /**
10
- * Opens a local native replica that synchronizes with the server in the
11
- * background. Sync mode keeps the normal local storage/read path and works
12
- * with browser storage such as OPFS as well as native storage.
13
- */
14
- export type SyncLixServerOptions = {
15
- mode: "sync";
16
- /** Stable HTTPS locator whose path is exactly `/lix/{uuid}`. HTTP is loopback-only. */
17
- url: string | URL;
18
- /** Resolved for every browser sync request, including reconnect handshakes. */
19
- headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
20
- /** Browser fetch override. Functions cross the worker boundary through RPC. */
21
- fetch?: RemoteLixFetch;
8
+ export type HostedLix = {
9
+ id: string;
10
+ url: string;
11
+ };
12
+ export type CreateLixOptions = {
13
+ /** Reuse this key when retrying a creation whose outcome was uncertain. */
14
+ idempotencyKey?: string;
15
+ server: Pick<LixServerOptions, "url" | "headers">;
16
+ from?: import("./lix.js").Lix;
17
+ };
18
+ export type DeleteLixOptions = {
19
+ server: Pick<LixServerOptions, "url" | "headers">;
22
20
  };
23
21
  export type LixTelemetrySpanLink = {
24
22
  traceId: string;
@@ -81,20 +79,21 @@ export type LixOpenProgressOptions = {
81
79
  /** Observes local inspection, automatic migration, and opening. */
82
80
  onProgress?(progress: LixOpenProgress): void;
83
81
  };
84
- export type OpenLixOptions = {
82
+ /** No options: memory. Storage: local. Server: remote. Storage + server: sync. */
83
+ export type OpenLixOptions = ({
85
84
  storage?: import("./storage-adapter.js").LixStorage;
86
85
  server?: never;
87
86
  telemetry?: LixTelemetryOptions;
88
- } & LixOpenProgressOptions | {
87
+ } & LixOpenProgressOptions) | {
89
88
  storage?: never;
90
- server: RemoteLixServerOptions;
89
+ server: LixServerOptions;
91
90
  telemetry?: never;
92
91
  onProgress?: never;
93
- } | {
92
+ } | ({
94
93
  storage: import("./storage-adapter.js").LixStorage;
95
- server: SyncLixServerOptions;
94
+ server: LixServerOptions;
96
95
  telemetry?: LixTelemetryOptions;
97
- } & LixOpenProgressOptions;
96
+ } & LixOpenProgressOptions);
98
97
  /** Selects the initial context for an additional independent session. */
99
98
  export type OpenAnotherSessionOptions = {
100
99
  /** Defaults to the current branch of the session opening it. */
@@ -10,6 +10,7 @@ export class WasmLix {
10
10
  beginTransaction(): Promise<WasmLixTransaction>;
11
11
  close(): Promise<void>;
12
12
  createBranch(options: any): Promise<any>;
13
+ createHosted(server: any): Promise<any>;
13
14
  execute(sql: string, params: any, options?: any | null): Promise<any>;
14
15
  executeBatch(statements: any, options?: any | null): Promise<any>;
15
16
  exportSnapshot(): WasmSnapshotExport;
@@ -104,6 +105,10 @@ export class WasmSnapshotRestore {
104
105
  write(chunk: Uint8Array): Promise<void>;
105
106
  }
106
107
 
108
+ export function createHosted(server: any): Promise<any>;
109
+
110
+ export function deleteHosted(server: any): Promise<void>;
111
+
107
112
  export function openJsStorage(provider: any, telemetry_dispatch?: Function | null, telemetry_parent?: any | null, server?: any | null, open_progress_dispatch?: Function | null): Promise<WasmLix>;
108
113
 
109
114
  export function openJsStorageFromSnapshot(provider: any, telemetry_dispatch?: Function | null, telemetry_parent?: any | null, open_progress_dispatch?: Function | null): WasmSnapshotRestore;
@@ -126,6 +131,8 @@ export interface InitOutput {
126
131
  readonly __wbg_wasmremoteobserveevents_free: (a: number, b: number) => void;
127
132
  readonly __wbg_wasmsnapshotexport_free: (a: number, b: number) => void;
128
133
  readonly __wbg_wasmsnapshotrestore_free: (a: number, b: number) => void;
134
+ readonly createHosted: (a: number) => number;
135
+ readonly deleteHosted: (a: number) => number;
129
136
  readonly openJsStorage: (a: number, b: number, c: number, d: number, e: number) => number;
130
137
  readonly openJsStorageFromSnapshot: (a: number, b: number, c: number, d: number) => number;
131
138
  readonly openMemory: (a: number, b: number, c: number, d: number) => number;
@@ -136,6 +143,7 @@ export interface InitOutput {
136
143
  readonly wasmlix_beginTransaction: (a: number) => number;
137
144
  readonly wasmlix_close: (a: number) => number;
138
145
  readonly wasmlix_createBranch: (a: number, b: number) => number;
146
+ readonly wasmlix_createHosted: (a: number, b: number) => number;
139
147
  readonly wasmlix_execute: (a: number, b: number, c: number, d: number, e: number) => number;
140
148
  readonly wasmlix_executeBatch: (a: number, b: number, c: number) => number;
141
149
  readonly wasmlix_exportSnapshot: (a: number) => number;
@@ -186,9 +194,10 @@ export interface InitOutput {
186
194
  readonly wasmsnapshotrestore_finish: (a: number) => number;
187
195
  readonly wasmsnapshotrestore_isComplete: (a: number) => number;
188
196
  readonly wasmsnapshotrestore_write: (a: number, b: number, c: number) => number;
189
- readonly __wasm_bindgen_func_elem_92635: (a: number, b: number, c: number, d: number) => void;
190
- readonly __wasm_bindgen_func_elem_92637: (a: number, b: number, c: number, d: number) => void;
191
- readonly __wasm_bindgen_func_elem_16813: (a: number, b: number) => void;
197
+ readonly __wasm_bindgen_func_elem_95597: (a: number, b: number, c: number, d: number) => void;
198
+ readonly __wasm_bindgen_func_elem_95599: (a: number, b: number, c: number, d: number) => void;
199
+ readonly __wasm_bindgen_func_elem_17533: (a: number, b: number, c: number) => number;
200
+ readonly __wasm_bindgen_func_elem_17532: (a: number, b: number) => void;
192
201
  readonly __wbindgen_export: (a: number, b: number) => number;
193
202
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
194
203
  readonly __wbindgen_export3: (a: number) => void;
@@ -53,6 +53,14 @@ export class WasmLix {
53
53
  const ret = wasm.wasmlix_createBranch(this.__wbg_ptr, addHeapObject(options));
54
54
  return takeObject(ret);
55
55
  }
56
+ /**
57
+ * @param {any} server
58
+ * @returns {Promise<any>}
59
+ */
60
+ createHosted(server) {
61
+ const ret = wasm.wasmlix_createHosted(this.__wbg_ptr, addHeapObject(server));
62
+ return takeObject(ret);
63
+ }
56
64
  /**
57
65
  * @param {string} sql
58
66
  * @param {any} params
@@ -611,6 +619,24 @@ export class WasmSnapshotRestore {
611
619
  }
612
620
  if (Symbol.dispose) WasmSnapshotRestore.prototype[Symbol.dispose] = WasmSnapshotRestore.prototype.free;
613
621
 
622
+ /**
623
+ * @param {any} server
624
+ * @returns {Promise<any>}
625
+ */
626
+ export function createHosted(server) {
627
+ const ret = wasm.createHosted(addHeapObject(server));
628
+ return takeObject(ret);
629
+ }
630
+
631
+ /**
632
+ * @param {any} server
633
+ * @returns {Promise<void>}
634
+ */
635
+ export function deleteHosted(server) {
636
+ const ret = wasm.deleteHosted(addHeapObject(server));
637
+ return takeObject(ret);
638
+ }
639
+
614
640
  /**
615
641
  * @param {any} provider
616
642
  * @param {Function | null} [telemetry_dispatch]
@@ -767,19 +793,19 @@ function __wbg_get_imports() {
767
793
  __wbg__wbg_cb_unref_61db23ac97f16c31: function(arg0) {
768
794
  getObject(arg0)._wbg_cb_unref();
769
795
  },
770
- __wbg_acquireSession_57f1f2cd5f681c2d: function(arg0) {
796
+ __wbg_acquireSession_a8254a768d39837d: function(arg0) {
771
797
  const ret = getObject(arg0).acquireSession();
772
798
  return addHeapObject(ret);
773
799
  },
774
- __wbg_beginRead_1138c26c0b47afd3: function(arg0, arg1) {
800
+ __wbg_beginRead_60aa15a811be5c9e: function(arg0, arg1) {
775
801
  const ret = getObject(arg0).beginRead(takeObject(arg1));
776
802
  return addHeapObject(ret);
777
803
  },
778
- __wbg_beginScan_d935bfe04519622e: function(arg0, arg1, arg2, arg3) {
804
+ __wbg_beginScan_babac0f551e5944a: function(arg0, arg1, arg2, arg3) {
779
805
  const ret = getObject(arg0).beginScan(takeObject(arg1), takeObject(arg2), takeObject(arg3));
780
806
  return addHeapObject(ret);
781
807
  },
782
- __wbg_beginWrite_4d84cc1cbfc72fa9: function(arg0, arg1) {
808
+ __wbg_beginWrite_1c425bc25b4478a9: function(arg0, arg1) {
783
809
  const ret = getObject(arg0).beginWrite(takeObject(arg1));
784
810
  return addHeapObject(ret);
785
811
  },
@@ -795,18 +821,18 @@ function __wbg_get_imports() {
795
821
  const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
796
822
  return addHeapObject(ret);
797
823
  }, arguments); },
798
- __wbg_changed_8b3c117efdd37fbf: function(arg0) {
824
+ __wbg_changed_528baf87aed58eeb: function(arg0) {
799
825
  const ret = getObject(arg0).changed();
800
826
  return addHeapObject(ret);
801
827
  },
802
- __wbg_close_70069a5308f6a3d8: function(arg0) {
828
+ __wbg_close_f2aa9b20739360cc: function(arg0) {
829
+ getObject(arg0).close();
830
+ },
831
+ __wbg_close_f3e51c630f322069: function(arg0) {
803
832
  const ret = getObject(arg0).close();
804
833
  return addHeapObject(ret);
805
834
  },
806
- __wbg_close_eb44b04eda5115d4: function(arg0) {
807
- getObject(arg0).close();
808
- },
809
- __wbg_commit_9dc6a608a8f559f7: function(arg0) {
835
+ __wbg_commit_c3ce5649299748fc: function(arg0) {
810
836
  const ret = getObject(arg0).commit();
811
837
  return addHeapObject(ret);
812
838
  },
@@ -814,11 +840,11 @@ function __wbg_get_imports() {
814
840
  const ret = Reflect.construct(getObject(arg0), getObject(arg1));
815
841
  return addHeapObject(ret);
816
842
  }, arguments); },
817
- __wbg_deleteMany_15f48563982d361e: function(arg0, arg1, arg2) {
843
+ __wbg_deleteMany_6d3b448de0ed189f: function(arg0, arg1, arg2) {
818
844
  const ret = getObject(arg0).deleteMany(takeObject(arg1), takeObject(arg2));
819
845
  return addHeapObject(ret);
820
846
  },
821
- __wbg_deleteRange_29b8dd1d129b1f8c: function(arg0, arg1, arg2) {
847
+ __wbg_deleteRange_c657e89ac7d3019f: function(arg0, arg1, arg2) {
822
848
  const ret = getObject(arg0).deleteRange(takeObject(arg1), takeObject(arg2));
823
849
  return addHeapObject(ret);
824
850
  },
@@ -845,7 +871,7 @@ function __wbg_get_imports() {
845
871
  const ret = Array.from(getObject(arg0));
846
872
  return addHeapObject(ret);
847
873
  },
848
- __wbg_getMany_946bf213edc127f3: function(arg0, arg1) {
874
+ __wbg_getMany_9a7d0535b6c9d8a8: function(arg0, arg1) {
849
875
  const ret = getObject(arg0).getMany(takeObject(arg1));
850
876
  return addHeapObject(ret);
851
877
  },
@@ -970,7 +996,7 @@ function __wbg_get_imports() {
970
996
  const a = state0.a;
971
997
  state0.a = 0;
972
998
  try {
973
- return __wasm_bindgen_func_elem_92637(a, state0.b, arg0, arg1);
999
+ return __wasm_bindgen_func_elem_95599(a, state0.b, arg0, arg1);
974
1000
  } finally {
975
1001
  state0.a = a;
976
1002
  }
@@ -1000,7 +1026,7 @@ function __wbg_get_imports() {
1000
1026
  const a = state0.a;
1001
1027
  state0.a = 0;
1002
1028
  try {
1003
- return __wasm_bindgen_func_elem_92637(a, state0.b, arg0, arg1);
1029
+ return __wasm_bindgen_func_elem_95599(a, state0.b, arg0, arg1);
1004
1030
  } finally {
1005
1031
  state0.a = a;
1006
1032
  }
@@ -1011,7 +1037,7 @@ function __wbg_get_imports() {
1011
1037
  state0.a = 0;
1012
1038
  }
1013
1039
  },
1014
- __wbg_nextPage_6902443bcbff10d3: function(arg0, arg1) {
1040
+ __wbg_nextPage_fa7414622954e329: function(arg0, arg1) {
1015
1041
  const ret = getObject(arg0).nextPage(arg1 >>> 0);
1016
1042
  return addHeapObject(ret);
1017
1043
  },
@@ -1050,7 +1076,7 @@ function __wbg_get_imports() {
1050
1076
  const ret = getObject(arg0).push(getObject(arg1));
1051
1077
  return ret;
1052
1078
  },
1053
- __wbg_putMany_168141e3afba203c: function(arg0, arg1, arg2) {
1079
+ __wbg_putMany_23a2adb09a5dbeb0: function(arg0, arg1, arg2) {
1054
1080
  const ret = getObject(arg0).putMany(takeObject(arg1), takeObject(arg2));
1055
1081
  return addHeapObject(ret);
1056
1082
  },
@@ -1061,7 +1087,7 @@ function __wbg_get_imports() {
1061
1087
  const ret = getObject(arg0).queueMicrotask;
1062
1088
  return addHeapObject(ret);
1063
1089
  },
1064
- __wbg_replaceMany_b2dc402a4ff6b772: function(arg0, arg1, arg2) {
1090
+ __wbg_replaceMany_ec7b95ae5e240784: function(arg0, arg1, arg2) {
1065
1091
  const ret = getObject(arg0).replaceMany(takeObject(arg1), takeObject(arg2));
1066
1092
  return addHeapObject(ret);
1067
1093
  },
@@ -1069,7 +1095,7 @@ function __wbg_get_imports() {
1069
1095
  const ret = Promise.resolve(getObject(arg0));
1070
1096
  return addHeapObject(ret);
1071
1097
  },
1072
- __wbg_rollback_5632fb7c3f6f9b08: function(arg0) {
1098
+ __wbg_rollback_5fba8ed172c77521: function(arg0) {
1073
1099
  const ret = getObject(arg0).rollback();
1074
1100
  return addHeapObject(ret);
1075
1101
  },
@@ -1153,46 +1179,51 @@ function __wbg_get_imports() {
1153
1179
  const ret = WasmRemoteObserveEvents.__wrap(arg0);
1154
1180
  return addHeapObject(ret);
1155
1181
  },
1156
- __wbg_watchForChanges_465d4036436d28da: function(arg0) {
1182
+ __wbg_watchForChanges_c0eedd0a57ce54a9: function(arg0) {
1157
1183
  const ret = getObject(arg0).watchForChanges();
1158
1184
  return addHeapObject(ret);
1159
1185
  },
1160
1186
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1161
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 21338, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1162
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_92635);
1187
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1280, ret: NamedExternref("Promise<any>"), inner_ret: Some(NamedExternref("Promise<any>")) }, mutable: true }) -> Externref`.
1188
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_17533);
1163
1189
  return addHeapObject(ret);
1164
1190
  },
1165
1191
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
1166
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1647, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1167
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_16813);
1192
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 21180, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
1193
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_95597);
1194
+ return addHeapObject(ret);
1195
+ },
1196
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
1197
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1279, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1198
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_17532);
1168
1199
  return addHeapObject(ret);
1169
1200
  },
1170
- __wbindgen_cast_0000000000000003: function(arg0) {
1201
+ __wbindgen_cast_0000000000000004: function(arg0) {
1171
1202
  // Cast intrinsic for `F64 -> Externref`.
1172
1203
  const ret = arg0;
1173
1204
  return addHeapObject(ret);
1174
1205
  },
1175
- __wbindgen_cast_0000000000000004: function(arg0) {
1206
+ __wbindgen_cast_0000000000000005: function(arg0) {
1176
1207
  // Cast intrinsic for `I64 -> Externref`.
1177
1208
  const ret = arg0;
1178
1209
  return addHeapObject(ret);
1179
1210
  },
1180
- __wbindgen_cast_0000000000000005: function(arg0, arg1) {
1211
+ __wbindgen_cast_0000000000000006: function(arg0, arg1) {
1181
1212
  // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
1182
1213
  const ret = getArrayU8FromWasm0(arg0, arg1);
1183
1214
  return addHeapObject(ret);
1184
1215
  },
1185
- __wbindgen_cast_0000000000000006: function(arg0, arg1) {
1216
+ __wbindgen_cast_0000000000000007: function(arg0, arg1) {
1186
1217
  // Cast intrinsic for `Ref(String) -> Externref`.
1187
1218
  const ret = getStringFromWasm0(arg0, arg1);
1188
1219
  return addHeapObject(ret);
1189
1220
  },
1190
- __wbindgen_cast_0000000000000007: function(arg0) {
1221
+ __wbindgen_cast_0000000000000008: function(arg0) {
1191
1222
  // Cast intrinsic for `U64 -> Externref`.
1192
1223
  const ret = BigInt.asUintN(64, arg0);
1193
1224
  return addHeapObject(ret);
1194
1225
  },
1195
- __wbindgen_cast_0000000000000008: function(arg0, arg1) {
1226
+ __wbindgen_cast_0000000000000009: function(arg0, arg1) {
1196
1227
  var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
1197
1228
  wasm.__wbindgen_export4(arg0, arg1 * 1, 1);
1198
1229
  // Cast intrinsic for `Vector(U8) -> Externref`.
@@ -1213,14 +1244,19 @@ function __wbg_get_imports() {
1213
1244
  };
1214
1245
  }
1215
1246
 
1216
- function __wasm_bindgen_func_elem_16813(arg0, arg1) {
1217
- wasm.__wasm_bindgen_func_elem_16813(arg0, arg1);
1247
+ function __wasm_bindgen_func_elem_17532(arg0, arg1) {
1248
+ wasm.__wasm_bindgen_func_elem_17532(arg0, arg1);
1249
+ }
1250
+
1251
+ function __wasm_bindgen_func_elem_17533(arg0, arg1, arg2) {
1252
+ const ret = wasm.__wasm_bindgen_func_elem_17533(arg0, arg1, addHeapObject(arg2));
1253
+ return takeObject(ret);
1218
1254
  }
1219
1255
 
1220
- function __wasm_bindgen_func_elem_92635(arg0, arg1, arg2) {
1256
+ function __wasm_bindgen_func_elem_95597(arg0, arg1, arg2) {
1221
1257
  try {
1222
1258
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1223
- wasm.__wasm_bindgen_func_elem_92635(retptr, arg0, arg1, addHeapObject(arg2));
1259
+ wasm.__wasm_bindgen_func_elem_95597(retptr, arg0, arg1, addHeapObject(arg2));
1224
1260
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1225
1261
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1226
1262
  if (r1) {
@@ -1231,8 +1267,8 @@ function __wasm_bindgen_func_elem_92635(arg0, arg1, arg2) {
1231
1267
  }
1232
1268
  }
1233
1269
 
1234
- function __wasm_bindgen_func_elem_92637(arg0, arg1, arg2, arg3) {
1235
- wasm.__wasm_bindgen_func_elem_92637(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1270
+ function __wasm_bindgen_func_elem_95599(arg0, arg1, arg2, arg3) {
1271
+ wasm.__wasm_bindgen_func_elem_95599(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
1236
1272
  }
1237
1273
 
1238
1274
  const WasmLixFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -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,6 +21,7 @@ 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;
24
27
  export const wasmlix_exportSnapshot: (a: number) => number;
@@ -69,9 +72,10 @@ export const wasmsnapshotrestore_cancel: (a: number) => number;
69
72
  export const wasmsnapshotrestore_finish: (a: number) => number;
70
73
  export const wasmsnapshotrestore_isComplete: (a: number) => number;
71
74
  export const wasmsnapshotrestore_write: (a: number, b: number, c: number) => number;
72
- export const __wasm_bindgen_func_elem_92635: (a: number, b: number, c: number, d: number) => void;
73
- export const __wasm_bindgen_func_elem_92637: (a: number, b: number, c: number, d: number) => void;
74
- export const __wasm_bindgen_func_elem_16813: (a: number, b: number) => void;
75
+ export const __wasm_bindgen_func_elem_95597: (a: number, b: number, c: number, d: number) => void;
76
+ export const __wasm_bindgen_func_elem_95599: (a: number, b: number, c: number, d: number) => void;
77
+ export const __wasm_bindgen_func_elem_17533: (a: number, b: number, c: number) => number;
78
+ export const __wasm_bindgen_func_elem_17532: (a: number, b: number) => void;
75
79
  export const __wbindgen_export: (a: number, b: number) => number;
76
80
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
77
81
  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 {};
@@ -284,6 +284,7 @@ export function workerBinding(client, lease, sessionId) {
284
284
  mergeBranchPreview: (options) => request({ kind: "mergeBranchPreview", options }),
285
285
  mergeBranch: (options) => request({ kind: "mergeBranch", options }),
286
286
  syncDiskToLix: () => request({ kind: "syncDiskToLix" }),
287
+ createHosted: (server) => request({ kind: "hosted.createFrom", server }),
287
288
  exportSnapshot: () => {
288
289
  const exportId = request({ kind: "exportSnapshot" });
289
290
  let canceled = false;
@@ -757,3 +758,13 @@ async function resolveDirectSyncServer(server) {
757
758
  fetch: server.fetch,
758
759
  };
759
760
  }
761
+ export async function hostedLixWorkerOperation(operation) {
762
+ const client = new LixWorkerClient();
763
+ client.beginLease();
764
+ try {
765
+ return await client.request(operation, 0);
766
+ }
767
+ finally {
768
+ await client.terminate();
769
+ }
770
+ }
@@ -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");
@@ -238,18 +250,17 @@ export function startWorkerHost(endpoint, openBinding = openLixBinding) {
238
250
  return requiredLix(sessionId).importFilesystemPaths(operation.paths);
239
251
  case "syncDiskToLix":
240
252
  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;
253
+ case "exportSnapshot": {
254
+ const binding = requiredLix(sessionId);
255
+ const exportSnapshot = binding.exportSnapshot;
256
+ if (!exportSnapshot) {
257
+ throw workerStateError("this Lix binding cannot export snapshots");
252
258
  }
259
+ const snapshot = exportSnapshot.call(binding);
260
+ const exportId = nextSnapshotExportId++;
261
+ snapshotExports.set(exportId, snapshot);
262
+ return exportId;
263
+ }
253
264
  case "exportSnapshot.next":
254
265
  throw workerStateError("snapshot pulls bypass the finite operation queue");
255
266
  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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lix-js/sdk",
3
3
  "type": "module",
4
- "version": "0.15.0",
4
+ "version": "0.16.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -49,10 +49,10 @@
49
49
  "typecheck": "tsc -p tsconfig.test.json --noEmit"
50
50
  },
51
51
  "optionalDependencies": {
52
- "@lix-js/sdk-darwin-arm64": "0.15.0",
53
- "@lix-js/sdk-linux-arm64": "0.15.0",
54
- "@lix-js/sdk-linux-x64": "0.15.0",
55
- "@lix-js/sdk-win32-x64": "0.15.0"
52
+ "@lix-js/sdk-darwin-arm64": "0.16.0",
53
+ "@lix-js/sdk-linux-arm64": "0.16.0",
54
+ "@lix-js/sdk-linux-x64": "0.16.0",
55
+ "@lix-js/sdk-win32-x64": "0.16.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@vitest/browser-playwright": "4.1.10",