@lix-js/sdk 0.12.3 → 0.14.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.
Files changed (50) hide show
  1. package/README.md +40 -10
  2. package/dist/binding-types.d.ts +37 -9
  3. package/dist/binding.browser.d.ts +2 -2
  4. package/dist/binding.browser.js +25 -10
  5. package/dist/binding.node-wasm.d.ts +2 -2
  6. package/dist/binding.node-wasm.js +8 -4
  7. package/dist/binding.node.d.ts +3 -3
  8. package/dist/binding.node.js +70 -13
  9. package/dist/browser-wasm-init.d.ts +14 -0
  10. package/dist/browser-wasm-init.js +16 -0
  11. package/dist/bundled-plugins/plugin_csv.lixplugin +0 -0
  12. package/dist/bundled-plugins/plugin_markdown.lixplugin +0 -0
  13. package/dist/index.d.ts +4 -4
  14. package/dist/index.js +2 -2
  15. package/dist/lix.d.ts +27 -5
  16. package/dist/lix.js +132 -6
  17. package/dist/open-lix.d.ts +4 -5
  18. package/dist/open-lix.js +173 -33
  19. package/dist/remote/client.d.ts +1 -2
  20. package/dist/remote/client.js +58 -1151
  21. package/dist/remote/server-protocol.d.ts +5 -6
  22. package/dist/remote/server-protocol.js +40 -6
  23. package/dist/result.d.ts +6 -13
  24. package/dist/result.js +9 -35
  25. package/dist/snapshot-restore.d.ts +6 -0
  26. package/dist/snapshot-restore.js +101 -0
  27. package/dist/storage-adapter.d.ts +175 -19
  28. package/dist/storage-adapter.js +21 -0
  29. package/dist/types.d.ts +101 -31
  30. package/dist/value.d.ts +1 -0
  31. package/dist/value.js +8 -0
  32. package/dist/wasm/lix_js_sdk.d.ts +119 -24
  33. package/dist/wasm/lix_js_sdk.js +599 -78
  34. package/dist/wasm/lix_js_sdk_bg.wasm +0 -0
  35. package/dist/wasm/lix_js_sdk_bg.wasm.d.ts +47 -6
  36. package/dist/worker/client.d.ts +27 -5
  37. package/dist/worker/client.js +458 -45
  38. package/dist/worker/factory.browser.d.ts +2 -2
  39. package/dist/worker/factory.node.d.ts +2 -2
  40. package/dist/worker/factory.node.js +3 -10
  41. package/dist/worker/host.d.ts +2 -1
  42. package/dist/worker/host.js +283 -37
  43. package/dist/worker/protocol.d.ts +80 -3
  44. package/package.json +6 -10
  45. package/dist/indexeddb-backend.d.ts +0 -19
  46. package/dist/indexeddb-backend.js +0 -121
  47. package/dist/remote/sse.d.ts +0 -12
  48. package/dist/remote/sse.js +0 -87
  49. package/dist/workerd.d.ts +0 -25
  50. package/dist/workerd.js +0 -35
@@ -1,121 +0,0 @@
1
- const DATABASE_VERSION = 1;
2
- const ENTRY_STORE = "entries";
3
- /** Internal worker-local bridge used by the WASM IndexedDB storage adapter. */
4
- export class IndexedDbBackend {
5
- #database;
6
- #releaseLock;
7
- #closed = false;
8
- constructor(database, releaseLock) {
9
- this.#database = database;
10
- this.#releaseLock = releaseLock;
11
- }
12
- static async open(name) {
13
- const releaseLock = await acquireDatabaseLock(name);
14
- try {
15
- const request = indexedDB.open(name, DATABASE_VERSION);
16
- request.onupgradeneeded = () => {
17
- if (!request.result.objectStoreNames.contains(ENTRY_STORE)) {
18
- request.result.createObjectStore(ENTRY_STORE);
19
- }
20
- };
21
- return new IndexedDbBackend(await openDatabase(request), releaseLock);
22
- }
23
- catch (error) {
24
- releaseLock();
25
- throw error;
26
- }
27
- }
28
- async loadEntries() {
29
- const transaction = this.#database.transaction(ENTRY_STORE, "readonly");
30
- const store = transaction.objectStore(ENTRY_STORE);
31
- const entries = [];
32
- await new Promise((resolve, reject) => {
33
- const request = store.openCursor();
34
- request.onerror = () => reject(request.error ?? transaction.error);
35
- request.onsuccess = () => {
36
- const cursor = request.result;
37
- if (!cursor) {
38
- resolve();
39
- return;
40
- }
41
- try {
42
- entries.push({
43
- key: copyBytes(cursor.key, "IndexedDB entry key"),
44
- value: copyBytes(cursor.value, "IndexedDB entry value"),
45
- });
46
- }
47
- catch (error) {
48
- transaction.abort();
49
- reject(error);
50
- return;
51
- }
52
- cursor.continue();
53
- };
54
- });
55
- await transactionDone(transaction);
56
- return entries;
57
- }
58
- async applyChanges(changes) {
59
- const transaction = this.#database.transaction(ENTRY_STORE, "readwrite", {
60
- durability: changes.strictDurability ? "strict" : "default",
61
- });
62
- const store = transaction.objectStore(ENTRY_STORE);
63
- for (const key of changes.deletes)
64
- store.delete(binaryKey(key));
65
- for (const entry of changes.puts) {
66
- store.put(entry.value, binaryKey(entry.key));
67
- }
68
- await transactionDone(transaction);
69
- }
70
- async close() {
71
- if (this.#closed)
72
- return;
73
- this.#closed = true;
74
- this.#database.close();
75
- this.#releaseLock();
76
- }
77
- }
78
- function acquireDatabaseLock(name) {
79
- let release;
80
- const released = new Promise((resolve) => {
81
- release = resolve;
82
- });
83
- return new Promise((resolve, reject) => {
84
- void navigator.locks
85
- .request(`lix:indexeddb:${name}`, { mode: "exclusive", ifAvailable: true }, async (lock) => {
86
- if (!lock) {
87
- reject(new Error(`IndexedDB storage '${name}' is already open`));
88
- return;
89
- }
90
- resolve(release);
91
- await released;
92
- })
93
- .catch(reject);
94
- });
95
- }
96
- function openDatabase(request) {
97
- return new Promise((resolve, reject) => {
98
- request.onsuccess = () => resolve(request.result);
99
- request.onerror = () => reject(request.error);
100
- request.onblocked = () => reject(new Error("IndexedDB database open was blocked"));
101
- });
102
- }
103
- function binaryKey(value) {
104
- return value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
105
- }
106
- function transactionDone(transaction) {
107
- return new Promise((resolve, reject) => {
108
- transaction.oncomplete = () => resolve();
109
- transaction.onabort = () => reject(transaction.error);
110
- transaction.onerror = () => reject(transaction.error);
111
- });
112
- }
113
- function copyBytes(value, label) {
114
- if (value instanceof ArrayBuffer) {
115
- return new Uint8Array(value.slice(0));
116
- }
117
- if (ArrayBuffer.isView(value)) {
118
- return new Uint8Array(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength));
119
- }
120
- throw new Error(`${label} is not binary data`);
121
- }
@@ -1,12 +0,0 @@
1
- export type SseEvent = {
2
- event: string;
3
- data: string;
4
- retry?: number;
5
- };
6
- /**
7
- * Parses a fetch response body as a stream of server-sent events.
8
- *
9
- * The caller remains responsible for validating the response status and
10
- * content type before passing its body here.
11
- */
12
- export declare function readSseEvents(stream: ReadableStream<Uint8Array>): AsyncGenerator<SseEvent, void, void>;
@@ -1,87 +0,0 @@
1
- /**
2
- * Parses a fetch response body as a stream of server-sent events.
3
- *
4
- * The caller remains responsible for validating the response status and
5
- * content type before passing its body here.
6
- */
7
- export async function* readSseEvents(stream) {
8
- const decoder = new TextDecoder();
9
- const reader = stream.getReader();
10
- let bufferedText = "";
11
- let eventName = "";
12
- let retry;
13
- let dataLines = [];
14
- function processLine(line) {
15
- if (line.length === 0) {
16
- return dispatchEvent();
17
- }
18
- if (line.startsWith(":")) {
19
- return undefined;
20
- }
21
- const colonIndex = line.indexOf(":");
22
- const field = colonIndex === -1 ? line : line.slice(0, colonIndex);
23
- let value = colonIndex === -1 ? "" : line.slice(colonIndex + 1);
24
- if (value.startsWith(" "))
25
- value = value.slice(1);
26
- switch (field) {
27
- case "event":
28
- eventName = value;
29
- break;
30
- case "data":
31
- dataLines.push(value);
32
- break;
33
- case "retry": {
34
- if (/^\d+$/.test(value)) {
35
- const parsed = Number(value);
36
- if (Number.isSafeInteger(parsed))
37
- retry = parsed;
38
- }
39
- break;
40
- }
41
- // Event IDs and extension fields are intentionally ignored. Remote Lix
42
- // observations use their payload sequence for resumption instead.
43
- default:
44
- break;
45
- }
46
- return undefined;
47
- }
48
- function dispatchEvent() {
49
- const hasData = dataLines.length !== 0;
50
- const event = hasData
51
- ? {
52
- event: eventName.length === 0 ? "message" : eventName,
53
- data: dataLines.join("\n"),
54
- ...(retry === undefined ? {} : { retry }),
55
- }
56
- : undefined;
57
- eventName = "";
58
- retry = undefined;
59
- dataLines = [];
60
- return event;
61
- }
62
- try {
63
- while (true) {
64
- const { done, value } = await reader.read();
65
- if (done)
66
- break;
67
- bufferedText += decoder.decode(value, { stream: true });
68
- let newlineIndex = bufferedText.indexOf("\n");
69
- while (newlineIndex !== -1) {
70
- let line = bufferedText.slice(0, newlineIndex);
71
- bufferedText = bufferedText.slice(newlineIndex + 1);
72
- if (line.endsWith("\r"))
73
- line = line.slice(0, -1);
74
- const event = processLine(line);
75
- if (event !== undefined)
76
- yield event;
77
- newlineIndex = bufferedText.indexOf("\n");
78
- }
79
- }
80
- decoder.decode();
81
- // SSE dispatches only at a blank line. An incomplete final frame indicates
82
- // a truncated connection and is deliberately left for the caller to retry.
83
- }
84
- finally {
85
- reader.releaseLock();
86
- }
87
- }
package/dist/workerd.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import type { LixBinding } from "./binding-types.js";
2
- export type SqlScriptPlan = {
3
- statements: SqlScriptStatement[];
4
- };
5
- export type SqlScriptStatement = {
6
- sql: string;
7
- paramStart: number;
8
- paramEnd: number;
9
- };
10
- export interface OpenMemoryLixOptions {
11
- snapshot?: Uint8Array;
12
- }
13
- export interface WorkerdLixBinding extends LixBinding {
14
- exportSnapshot(): Promise<Uint8Array>;
15
- }
16
- /** Parses SQL using the same DataFusion dialect and transaction policy as Lix. */
17
- export declare function parseSqlScript(sql: string, providedParamCount: number): SqlScriptPlan;
18
- /**
19
- * Opens an in-memory Lix binding directly in a Cloudflare Worker isolate.
20
- *
21
- * The browser SDK intentionally uses Web Workers. Workerd does not implement
22
- * that API, so this entry point initializes the precompiled module directly.
23
- * Plugin execution is deliberately unavailable in this environment.
24
- */
25
- export declare function openMemoryLix(options?: OpenMemoryLixOptions): Promise<WorkerdLixBinding>;
package/dist/workerd.js DELETED
@@ -1,35 +0,0 @@
1
- // Generated before TypeScript compilation and emitted beside this module.
2
- // @ts-expect-error Generated by build:wasm.
3
- import wasmModule from "./wasm/lix_js_sdk_bg.wasm";
4
- // @ts-expect-error Generated by build:wasm.
5
- import { initSync, openMemoryFromSnapshot, parseSqlScript as parseSqlScriptBinding } from "./wasm/lix_js_sdk.js";
6
- let initialized = false;
7
- function initializeWasm() {
8
- if (initialized)
9
- return;
10
- initSync({ module: wasmModule });
11
- initialized = true;
12
- }
13
- /** Parses SQL using the same DataFusion dialect and transaction policy as Lix. */
14
- export function parseSqlScript(sql, providedParamCount) {
15
- initializeWasm();
16
- return parseSqlScriptBinding(sql, providedParamCount);
17
- }
18
- /**
19
- * Opens an in-memory Lix binding directly in a Cloudflare Worker isolate.
20
- *
21
- * The browser SDK intentionally uses Web Workers. Workerd does not implement
22
- * that API, so this entry point initializes the precompiled module directly.
23
- * Plugin execution is deliberately unavailable in this environment.
24
- */
25
- export async function openMemoryLix(options = {}) {
26
- if (!options || typeof options !== "object" || Array.isArray(options)) {
27
- throw new TypeError("openMemoryLix() options must be an object");
28
- }
29
- if (options.snapshot !== undefined &&
30
- !(options.snapshot instanceof Uint8Array)) {
31
- throw new TypeError("openMemoryLix() snapshot must be a Uint8Array");
32
- }
33
- initializeWasm();
34
- return openMemoryFromSnapshot(undefined, options.snapshot);
35
- }