@lix-js/sdk 0.8.4 → 0.10.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 +105 -22
- package/dist/binding-types.d.ts +21 -2
- package/dist/binding.browser.d.ts +2 -2
- package/dist/binding.browser.js +3 -3
- package/dist/binding.node.d.ts +2 -2
- package/dist/binding.node.js +18 -4
- package/dist/bundled-plugins/plugin_csv.lixplugin +0 -0
- package/dist/bundled-plugins/plugin_markdown.lixplugin +0 -0
- package/dist/bundled-plugins.js +2 -2
- package/dist/client-state.d.ts +53 -0
- package/dist/client-state.js +318 -0
- package/dist/index.d.ts +2 -1
- package/dist/lix.d.ts +47 -0
- package/dist/lix.js +378 -0
- package/dist/local-storage-adapter.d.ts +26 -0
- package/dist/local-storage-adapter.js +117 -0
- package/dist/open-lix.d.ts +3 -34
- package/dist/open-lix.js +99 -170
- package/dist/remote/client.d.ts +9 -0
- package/dist/remote/client.js +1150 -0
- package/dist/remote/protocol.d.ts +178 -0
- package/dist/remote/protocol.js +367 -0
- package/dist/remote/sse.d.ts +12 -0
- package/dist/remote/sse.js +87 -0
- package/dist/snapshot-persistence.d.ts +7 -0
- package/dist/snapshot-persistence.js +26 -0
- package/dist/types.d.ts +68 -1
- package/dist/wasm/lix_js_sdk.d.ts +22 -4
- package/dist/wasm/lix_js_sdk.js +96 -17
- package/dist/wasm/lix_js_sdk_bg.wasm +0 -0
- package/dist/wasm/lix_js_sdk_bg.wasm.d.ts +11 -2
- package/dist/worker/client.d.ts +23 -4
- package/dist/worker/client.js +329 -11
- package/dist/worker/factory.browser.d.ts +2 -0
- package/dist/worker/factory.browser.js +2 -0
- package/dist/worker/factory.node.d.ts +2 -0
- package/dist/worker/factory.node.js +5 -0
- package/dist/worker/host.js +36 -2
- package/dist/worker/protocol.d.ts +32 -2
- package/dist/workerd.js +1 -3
- package/package.json +19 -16
- package/dist/bundled-plugins/plugin_md_v2.lixplugin +0 -0
- package/dist/jco/js-component-bindgen-component.core.wasm +0 -0
- package/dist/jco/js-component-bindgen-component.core2.wasm +0 -0
- package/dist/jco/js-component-bindgen-component.js +0 -13662
- package/dist/jco-transpile.browser.d.ts +0 -14
- package/dist/jco-transpile.browser.js +0 -22
- package/dist/plugin-runtime.d.ts +0 -45
- package/dist/plugin-runtime.js +0 -124
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type TranspileOptions = {
|
|
2
|
-
name?: string;
|
|
3
|
-
emitTypescriptDeclarations?: boolean;
|
|
4
|
-
instantiation?: "async" | "sync";
|
|
5
|
-
nodejsCompat?: boolean;
|
|
6
|
-
base64Cutoff?: number;
|
|
7
|
-
};
|
|
8
|
-
type TranspileResult = {
|
|
9
|
-
files: Record<string, Uint8Array>;
|
|
10
|
-
imports: string[];
|
|
11
|
-
exports: [string, "function" | "instance"][];
|
|
12
|
-
};
|
|
13
|
-
export declare function transpileBytes(component: Uint8Array, options?: TranspileOptions): Promise<TranspileResult>;
|
|
14
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// This module is copied from the pinned JCO package by build:jco-browser. Using
|
|
2
|
-
// its browser-native generator avoids pulling JCO's CLI-only Node imports and
|
|
3
|
-
// optional minifier into application bundles.
|
|
4
|
-
// @ts-expect-error The generated module is copied into dist after tsc runs.
|
|
5
|
-
import { $init, generate } from "./jco/js-component-bindgen-component.js";
|
|
6
|
-
export async function transpileBytes(component, options = {}) {
|
|
7
|
-
await $init;
|
|
8
|
-
const generated = generate(component, {
|
|
9
|
-
name: options.name ?? "component",
|
|
10
|
-
noTypescript: options.emitTypescriptDeclarations === false,
|
|
11
|
-
instantiation: options.instantiation
|
|
12
|
-
? { tag: options.instantiation }
|
|
13
|
-
: undefined,
|
|
14
|
-
noNodejsCompat: options.nodejsCompat === false,
|
|
15
|
-
base64Cutoff: options.base64Cutoff ?? 5000,
|
|
16
|
-
});
|
|
17
|
-
return {
|
|
18
|
-
files: Object.fromEntries(generated.files),
|
|
19
|
-
imports: generated.imports,
|
|
20
|
-
exports: generated.exports,
|
|
21
|
-
};
|
|
22
|
-
}
|
package/dist/plugin-runtime.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
type PluginRuntimeOperation = "initComponent" | "detectChanges" | "render" | "closeComponent";
|
|
2
|
-
export type PluginRuntimeRequest = {
|
|
3
|
-
operation: PluginRuntimeOperation;
|
|
4
|
-
componentId?: number;
|
|
5
|
-
componentBytes?: Uint8Array;
|
|
6
|
-
maxMemoryBytes?: string;
|
|
7
|
-
maxFuel?: string;
|
|
8
|
-
timeoutMs?: string;
|
|
9
|
-
state?: PluginEntityState[];
|
|
10
|
-
file?: PluginFile;
|
|
11
|
-
};
|
|
12
|
-
export type PluginRuntimeResponse = {
|
|
13
|
-
componentId?: number;
|
|
14
|
-
changes?: PluginDetectedChange[];
|
|
15
|
-
bytes?: Uint8Array;
|
|
16
|
-
errorMessage?: string;
|
|
17
|
-
};
|
|
18
|
-
type PluginFile = {
|
|
19
|
-
filename?: string;
|
|
20
|
-
data: Uint8Array;
|
|
21
|
-
};
|
|
22
|
-
type PluginEntityState = {
|
|
23
|
-
entityPk: string[];
|
|
24
|
-
schemaKey: string;
|
|
25
|
-
snapshotContent: string;
|
|
26
|
-
metadata?: string;
|
|
27
|
-
};
|
|
28
|
-
type PluginDetectedChange = {
|
|
29
|
-
entityPk: string[];
|
|
30
|
-
schemaKey: string;
|
|
31
|
-
snapshotContent?: string;
|
|
32
|
-
metadata?: string;
|
|
33
|
-
};
|
|
34
|
-
declare class WasmPluginRuntime {
|
|
35
|
-
private nextComponentId;
|
|
36
|
-
private readonly components;
|
|
37
|
-
readonly dispatch: (request: PluginRuntimeRequest) => Promise<PluginRuntimeResponse>;
|
|
38
|
-
private initComponent;
|
|
39
|
-
private detectChanges;
|
|
40
|
-
private render;
|
|
41
|
-
private closeComponent;
|
|
42
|
-
private requiredComponent;
|
|
43
|
-
}
|
|
44
|
-
export declare function createPluginRuntimeDispatch(): WasmPluginRuntime["dispatch"];
|
|
45
|
-
export {};
|
package/dist/plugin-runtime.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { WASIShim } from "@bytecodealliance/preview2-shim/instantiation";
|
|
2
|
-
import { transpileBytes } from "#jco-transpile";
|
|
3
|
-
const webAssembly = globalThis.WebAssembly;
|
|
4
|
-
class WasmPluginRuntime {
|
|
5
|
-
nextComponentId = 1;
|
|
6
|
-
components = new Map();
|
|
7
|
-
dispatch = async (request) => {
|
|
8
|
-
try {
|
|
9
|
-
switch (request.operation) {
|
|
10
|
-
case "initComponent":
|
|
11
|
-
return await this.initComponent(request);
|
|
12
|
-
case "detectChanges":
|
|
13
|
-
return this.detectChanges(request);
|
|
14
|
-
case "render":
|
|
15
|
-
return this.render(request);
|
|
16
|
-
case "closeComponent":
|
|
17
|
-
return this.closeComponent(request);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch (cause) {
|
|
21
|
-
return {
|
|
22
|
-
errorMessage: `Lix plugin runtime ${request.operation} failed: ${errorMessage(cause)}`,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
async initComponent(request) {
|
|
27
|
-
if (!request.componentBytes) {
|
|
28
|
-
throw new TypeError("initComponent requires componentBytes");
|
|
29
|
-
}
|
|
30
|
-
const componentId = this.nextComponentId;
|
|
31
|
-
this.nextComponentId += 1;
|
|
32
|
-
const name = "lix_plugin";
|
|
33
|
-
const transpiled = await transpileBytes(request.componentBytes, {
|
|
34
|
-
name,
|
|
35
|
-
emitTypescriptDeclarations: false,
|
|
36
|
-
instantiation: "async",
|
|
37
|
-
nodejsCompat: false,
|
|
38
|
-
});
|
|
39
|
-
const files = new Map(Object.entries(transpiled.files));
|
|
40
|
-
const moduleSource = requiredFile(files, `${name}.js`);
|
|
41
|
-
const moduleUrl = `data:text/javascript;base64,${bytesToBase64(moduleSource)}`;
|
|
42
|
-
const generatedModule = (await import(
|
|
43
|
-
/* @vite-ignore */ moduleUrl));
|
|
44
|
-
const wasi = new WASIShim({
|
|
45
|
-
sandbox: {
|
|
46
|
-
preopens: {},
|
|
47
|
-
env: {},
|
|
48
|
-
args: ["lix-plugin"],
|
|
49
|
-
enableNetwork: false,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
const instance = await generatedModule.instantiate(async (path) => await webAssembly.compile(copyArrayBuffer(requiredFile(files, path))), wasi.getImportObject());
|
|
53
|
-
if (!instance.api) {
|
|
54
|
-
throw new Error("component does not export lix:plugin/api");
|
|
55
|
-
}
|
|
56
|
-
this.components.set(componentId, instance.api);
|
|
57
|
-
return { componentId };
|
|
58
|
-
}
|
|
59
|
-
detectChanges(request) {
|
|
60
|
-
const component = this.requiredComponent(request.componentId);
|
|
61
|
-
if (!request.file) {
|
|
62
|
-
throw new TypeError("detectChanges requires file");
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
changes: component.detectChanges(request.state ?? [], request.file),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
render(request) {
|
|
69
|
-
const component = this.requiredComponent(request.componentId);
|
|
70
|
-
return { bytes: component.render(request.state ?? []) };
|
|
71
|
-
}
|
|
72
|
-
closeComponent(request) {
|
|
73
|
-
if (request.componentId !== undefined) {
|
|
74
|
-
this.components.delete(request.componentId);
|
|
75
|
-
}
|
|
76
|
-
return {};
|
|
77
|
-
}
|
|
78
|
-
requiredComponent(componentId) {
|
|
79
|
-
if (componentId === undefined) {
|
|
80
|
-
throw new TypeError("plugin runtime operation requires componentId");
|
|
81
|
-
}
|
|
82
|
-
const component = this.components.get(componentId);
|
|
83
|
-
if (!component) {
|
|
84
|
-
throw new Error(`unknown plugin component ${componentId}`);
|
|
85
|
-
}
|
|
86
|
-
return component;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export function createPluginRuntimeDispatch() {
|
|
90
|
-
return new WasmPluginRuntime().dispatch;
|
|
91
|
-
}
|
|
92
|
-
function bytesToBase64(bytes) {
|
|
93
|
-
let binary = "";
|
|
94
|
-
const chunkSize = 0x8000;
|
|
95
|
-
for (let index = 0; index < bytes.length; index += chunkSize) {
|
|
96
|
-
binary += String.fromCharCode(...bytes.subarray(index, index + chunkSize));
|
|
97
|
-
}
|
|
98
|
-
return btoa(binary);
|
|
99
|
-
}
|
|
100
|
-
function requiredFile(files, path) {
|
|
101
|
-
const file = files.get(path);
|
|
102
|
-
if (!file) {
|
|
103
|
-
throw new Error(`JCO output is missing ${path}`);
|
|
104
|
-
}
|
|
105
|
-
return file;
|
|
106
|
-
}
|
|
107
|
-
function copyArrayBuffer(bytes) {
|
|
108
|
-
const copy = new Uint8Array(bytes.byteLength);
|
|
109
|
-
copy.set(bytes);
|
|
110
|
-
return copy.buffer;
|
|
111
|
-
}
|
|
112
|
-
function errorMessage(cause) {
|
|
113
|
-
if (cause instanceof Error) {
|
|
114
|
-
return cause.message;
|
|
115
|
-
}
|
|
116
|
-
if (cause && typeof cause === "object") {
|
|
117
|
-
const tag = "tag" in cause ? String(cause.tag) : undefined;
|
|
118
|
-
const value = "val" in cause ? String(cause.val) : undefined;
|
|
119
|
-
if (tag || value) {
|
|
120
|
-
return [tag, value].filter(Boolean).join(": ");
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return String(cause);
|
|
124
|
-
}
|