@perspective-dev/client 5.6.1 → 5.7.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 +5 -1
- package/dist/cdn/perspective.js +3 -2
- package/dist/cdn/perspective.js.map +4 -4
- package/dist/esm/perspective.browser.d.ts +71 -17
- package/dist/esm/perspective.js +2 -2
- package/dist/esm/perspective.js.map +4 -4
- package/dist/esm/perspective.node.d.ts +20 -3
- package/dist/esm/perspective.node.js +664 -35
- package/dist/esm/perspective.node.js.map +4 -4
- package/dist/esm/public_types.d.ts +31 -0
- package/dist/esm/virtual_servers/clickhouse.d.ts +37 -0
- package/dist/esm/virtual_servers/clickhouse.js +1 -1
- package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
- package/dist/esm/virtual_servers/duckdb.d.ts +14 -9
- package/dist/esm/virtual_servers/duckdb.js +1 -1
- package/dist/esm/virtual_servers/duckdb.js.map +3 -3
- package/dist/esm/wasm/cdn.d.ts +12 -0
- package/dist/esm/wasm/migrate.d.ts +40 -0
- package/dist/esm/wasm/registry.d.ts +123 -0
- package/dist/esm/wasm/registry.js +3 -0
- package/dist/esm/wasm/registry.js.map +7 -0
- package/{src/ts/ts-rs/AggSpec.ts → dist/ts-rs/AggSpec.d.ts} +1 -1
- package/{src/ts/ts-rs/Features.ts → dist/ts-rs/Features.d.ts} +16 -6
- package/{src/ts/ts-rs/Filter.ts → dist/ts-rs/Filter.d.ts} +1 -1
- package/{src/ts/ts-rs/FilterTerm.ts → dist/ts-rs/FilterTerm.d.ts} +1 -1
- package/{src/ts/ts-rs/JoinOptions.ts → dist/ts-rs/JoinOptions.d.ts} +1 -1
- package/dist/ts-rs/ListFlatten.d.ts +3 -0
- package/dist/ts-rs/MapFlatten.d.ts +3 -0
- package/{src/ts/ts-rs/OnRemoveData.ts → dist/ts-rs/OnRemoveData.d.ts} +1 -1
- package/{src/ts/ts-rs/OnUpdateData.ts → dist/ts-rs/OnUpdateData.d.ts} +1 -1
- package/{src/ts/ts-rs/OnUpdateOptions.ts → dist/ts-rs/OnUpdateOptions.d.ts} +1 -1
- package/{src/ts/ts-rs/Sort.ts → dist/ts-rs/Sort.d.ts} +1 -1
- package/dist/ts-rs/StructFlatten.d.ts +3 -0
- package/dist/ts-rs/TableIndex.d.ts +9 -0
- package/dist/ts-rs/TableInitOptions.d.ts +65 -0
- package/{src/ts/ts-rs/UpdateOptions.ts → dist/ts-rs/UpdateOptions.d.ts} +1 -1
- package/{src/ts/ts-rs/ViewConfig.ts → dist/ts-rs/ViewConfig.d.ts} +8 -8
- package/{src/ts/ts-rs/ViewConfigUpdate.ts → dist/ts-rs/ViewConfigUpdate.d.ts} +8 -8
- package/{src/ts/ts-rs/WindowAggSpec.ts → dist/ts-rs/WindowAggSpec.d.ts} +1 -1
- package/{src/ts/ts-rs/WindowSort.ts → dist/ts-rs/WindowSort.d.ts} +1 -1
- package/{src/ts/ts-rs/WindowSpec.ts → dist/ts-rs/WindowSpec.d.ts} +1 -1
- package/{src/ts/ts-rs/Windows.ts → dist/ts-rs/Windows.d.ts} +1 -1
- package/dist/wasm/perspective-js.d.ts +121 -54
- package/dist/wasm/perspective-js.js +123 -20
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +10 -6
- package/dist/wasm/perspective-migrate-js.d.ts +41 -0
- package/dist/wasm/perspective-migrate-js.js +524 -0
- package/dist/wasm/perspective-migrate-js.wasm +0 -0
- package/dist/wasm/perspective-migrate-js.wasm.d.ts +8 -0
- package/package.json +30 -15
- package/dist/esm/ts-rs/AggSpec.d.ts +0 -8
- package/dist/esm/ts-rs/Aggregate.d.ts +0 -1
- package/dist/esm/ts-rs/ColumnType.d.ts +0 -4
- package/dist/esm/ts-rs/ColumnWindow.d.ts +0 -4
- package/dist/esm/ts-rs/DeleteOptions.d.ts +0 -6
- package/dist/esm/ts-rs/Expressions.d.ts +0 -3
- package/dist/esm/ts-rs/Features.d.ts +0 -71
- package/dist/esm/ts-rs/Filter.d.ts +0 -2
- package/dist/esm/ts-rs/FilterReducer.d.ts +0 -1
- package/dist/esm/ts-rs/FilterTerm.d.ts +0 -2
- package/dist/esm/ts-rs/GroupRollupMode.d.ts +0 -1
- package/dist/esm/ts-rs/JoinOptions.d.ts +0 -9
- package/dist/esm/ts-rs/JoinType.d.ts +0 -1
- package/dist/esm/ts-rs/ListFlatten.d.ts +0 -1
- package/dist/esm/ts-rs/OnRemoveData.d.ts +0 -6
- package/dist/esm/ts-rs/OnUpdateData.d.ts +0 -6
- package/dist/esm/ts-rs/OnUpdateMode.d.ts +0 -9
- package/dist/esm/ts-rs/OnUpdateOptions.d.ts +0 -7
- package/dist/esm/ts-rs/Scalar.d.ts +0 -5
- package/dist/esm/ts-rs/Sort.d.ts +0 -2
- package/dist/esm/ts-rs/SortDir.d.ts +0 -1
- package/dist/esm/ts-rs/SplitRollupMode.d.ts +0 -9
- package/dist/esm/ts-rs/SystemInfo.d.ts +0 -40
- package/dist/esm/ts-rs/TableInitOptions.d.ts +0 -45
- package/dist/esm/ts-rs/TableReadFormat.d.ts +0 -7
- package/dist/esm/ts-rs/TypedArrayWindow.d.ts +0 -33
- package/dist/esm/ts-rs/UpdateOptions.d.ts +0 -8
- package/dist/esm/ts-rs/ViewConfig.d.ts +0 -24
- package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +0 -116
- package/dist/esm/ts-rs/ViewOnRemoveResp.d.ts +0 -4
- package/dist/esm/ts-rs/ViewOnUpdateResp.d.ts +0 -4
- package/dist/esm/ts-rs/ViewWindow.d.ts +0 -30
- package/dist/esm/ts-rs/WindowAggSpec.d.ts +0 -25
- package/dist/esm/ts-rs/WindowSort.d.ts +0 -7
- package/dist/esm/ts-rs/WindowSortDir.d.ts +0 -6
- package/dist/esm/ts-rs/WindowSpec.d.ts +0 -47
- package/dist/esm/ts-rs/Windows.d.ts +0 -10
- package/src/rust/client.rs +0 -590
- package/src/rust/generic_sql_model.rs +0 -276
- package/src/rust/lib.rs +0 -99
- package/src/rust/table.rs +0 -397
- package/src/rust/table_data.rs +0 -164
- package/src/rust/typed_array.rs +0 -386
- package/src/rust/utils/browser.rs +0 -35
- package/src/rust/utils/console_logger.rs +0 -237
- package/src/rust/utils/errors.rs +0 -274
- package/src/rust/utils/futures.rs +0 -274
- package/src/rust/utils/json.rs +0 -252
- package/src/rust/utils/local_poll_loop.rs +0 -63
- package/src/rust/utils/mod.rs +0 -32
- package/src/rust/utils/serde.rs +0 -46
- package/src/rust/utils/trace_allocator.rs +0 -98
- package/src/rust/view.rs +0 -463
- package/src/rust/virtual_server.rs +0 -991
- package/src/ts/perspective-server.worker.ts +0 -74
- package/src/ts/perspective.browser.ts +0 -380
- package/src/ts/perspective.cdn.ts +0 -28
- package/src/ts/perspective.node.ts +0 -556
- package/src/ts/ts-rs/ListFlatten.ts +0 -3
- package/src/ts/ts-rs/TableInitOptions.ts +0 -42
- package/src/ts/virtual_server.ts +0 -83
- package/src/ts/virtual_servers/clickhouse.ts +0 -533
- package/src/ts/virtual_servers/duckdb.ts +0 -549
- package/src/ts/wasm/browser.ts +0 -134
- package/src/ts/wasm/cdn.ts +0 -32
- package/src/ts/wasm/decompress.ts +0 -83
- package/src/ts/wasm/emscripten_api.ts +0 -91
- package/src/ts/wasm/engine.ts +0 -309
- package/src/ts/wasm/features.ts +0 -31
- package/src/ts/wasm/perspective-server.poly.ts +0 -460
- package/src/ts/websocket.ts +0 -95
- package/tsconfig.json +0 -22
- /package/{src/ts/ts-rs/Aggregate.ts → dist/ts-rs/Aggregate.d.ts} +0 -0
- /package/{src/ts/ts-rs/ColumnType.ts → dist/ts-rs/ColumnType.d.ts} +0 -0
- /package/{src/ts/ts-rs/ColumnWindow.ts → dist/ts-rs/ColumnWindow.d.ts} +0 -0
- /package/{src/ts/ts-rs/DeleteOptions.ts → dist/ts-rs/DeleteOptions.d.ts} +0 -0
- /package/{src/ts/ts-rs/Expressions.ts → dist/ts-rs/Expressions.d.ts} +0 -0
- /package/{src/ts/ts-rs/FilterReducer.ts → dist/ts-rs/FilterReducer.d.ts} +0 -0
- /package/{src/ts/ts-rs/GroupRollupMode.ts → dist/ts-rs/GroupRollupMode.d.ts} +0 -0
- /package/{src/ts/ts-rs/JoinType.ts → dist/ts-rs/JoinType.d.ts} +0 -0
- /package/{src/ts/ts-rs/OnUpdateMode.ts → dist/ts-rs/OnUpdateMode.d.ts} +0 -0
- /package/{src/ts/ts-rs/Scalar.ts → dist/ts-rs/Scalar.d.ts} +0 -0
- /package/{src/ts/ts-rs/SortDir.ts → dist/ts-rs/SortDir.d.ts} +0 -0
- /package/{src/ts/ts-rs/SplitRollupMode.ts → dist/ts-rs/SplitRollupMode.d.ts} +0 -0
- /package/{src/ts/ts-rs/SystemInfo.ts → dist/ts-rs/SystemInfo.d.ts} +0 -0
- /package/{src/ts/ts-rs/TableReadFormat.ts → dist/ts-rs/TableReadFormat.d.ts} +0 -0
- /package/{src/ts/ts-rs/TypedArrayWindow.ts → dist/ts-rs/TypedArrayWindow.d.ts} +0 -0
- /package/{src/ts/ts-rs/ViewOnRemoveResp.ts → dist/ts-rs/ViewOnRemoveResp.d.ts} +0 -0
- /package/{src/ts/ts-rs/ViewOnUpdateResp.ts → dist/ts-rs/ViewOnUpdateResp.d.ts} +0 -0
- /package/{src/ts/ts-rs/ViewWindow.ts → dist/ts-rs/ViewWindow.d.ts} +0 -0
- /package/{src/ts/ts-rs/WindowSortDir.ts → dist/ts-rs/WindowSortDir.d.ts} +0 -0
package/src/ts/wasm/cdn.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
2
|
-
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
|
3
|
-
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
|
4
|
-
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
|
5
|
-
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
|
6
|
-
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
|
7
|
-
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
|
8
|
-
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
|
9
|
-
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
|
10
|
-
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
|
11
|
-
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Resolve the URL of one of `@perspective-dev/server`'s engine WASM binaries
|
|
15
|
-
* relative to the URL of the `@perspective-dev/client` CDN bundle which loads
|
|
16
|
-
* it.
|
|
17
|
-
*/
|
|
18
|
-
export function resolve_server_wasm_url(
|
|
19
|
-
client_url: string,
|
|
20
|
-
filename: string = "perspective-server.wasm",
|
|
21
|
-
): string {
|
|
22
|
-
const rewritten = client_url.replace(
|
|
23
|
-
/\/client(@[^/]+)?\/dist\/cdn\/[^/?#]*([?#].*)?$/,
|
|
24
|
-
(_, tag) => `/server${tag ?? ""}/dist/wasm/${filename}`,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
if (rewritten !== client_url) {
|
|
28
|
-
return rewritten;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return new URL(`../../../server/dist/wasm/${filename}`, client_url).href;
|
|
32
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
2
|
-
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
|
3
|
-
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
|
4
|
-
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
|
5
|
-
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
|
6
|
-
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
|
7
|
-
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
|
8
|
-
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
|
9
|
-
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
|
10
|
-
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
|
11
|
-
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
12
|
-
|
|
13
|
-
type ModType = {
|
|
14
|
-
resize: (x: number) => number;
|
|
15
|
-
memory: WebAssembly.Memory;
|
|
16
|
-
compile: (x: number, y: number) => number;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export async function extract(input: any) {
|
|
20
|
-
let bin: WebAssembly.WebAssemblyInstantiatedSource;
|
|
21
|
-
if (input instanceof Response) {
|
|
22
|
-
bin = await WebAssembly.instantiateStreaming(input);
|
|
23
|
-
} else if (typeof input === "string") {
|
|
24
|
-
bin = await WebAssembly.instantiateStreaming(fetch(input));
|
|
25
|
-
} else if (input instanceof ArrayBuffer) {
|
|
26
|
-
bin = await WebAssembly.instantiate(input);
|
|
27
|
-
} else {
|
|
28
|
-
bin = input;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const inst = bin.instance.exports as ModType;
|
|
32
|
-
const [payload] = WebAssembly.Module.customSections(
|
|
33
|
-
bin.module,
|
|
34
|
-
"psp-runtime",
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const [raw_length_view] = WebAssembly.Module.customSections(
|
|
38
|
-
bin.module,
|
|
39
|
-
"psp-len",
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const raw_length = new DataView(raw_length_view).getUint32(0, true);
|
|
43
|
-
const ptr = inst.resize(payload.byteLength);
|
|
44
|
-
new Uint8Array(inst.memory.buffer).set(new Uint8Array(payload), ptr);
|
|
45
|
-
const offset = inst.compile(payload.byteLength, raw_length);
|
|
46
|
-
return new Uint8Array(inst.memory.buffer).slice(
|
|
47
|
-
offset,
|
|
48
|
-
raw_length + offset,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (typeof WebAssembly === "undefined") {
|
|
53
|
-
throw new Error("WebAssembly not supported.");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
interface Module extends WebAssembly.Exports {
|
|
57
|
-
size(): number;
|
|
58
|
-
offset(): number;
|
|
59
|
-
memory: WebAssembly.Memory;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export async function load_wasm_stage_0(
|
|
63
|
-
wasm:
|
|
64
|
-
| ArrayBuffer
|
|
65
|
-
| Response
|
|
66
|
-
| WebAssembly.Module
|
|
67
|
-
| (() => Promise<ArrayBuffer>),
|
|
68
|
-
): Promise<Uint8Array> {
|
|
69
|
-
if (wasm instanceof Function) {
|
|
70
|
-
wasm = await wasm();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (wasm instanceof Promise) {
|
|
74
|
-
wasm = await wasm;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
return await extract(wasm as ArrayBuffer);
|
|
79
|
-
} catch (e) {
|
|
80
|
-
console.warn("Stage 0 wasm loading failed, skipping");
|
|
81
|
-
return new Uint8Array(wasm as ArrayBuffer);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
2
|
-
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
|
3
|
-
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
|
4
|
-
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
|
5
|
-
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
|
6
|
-
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
|
7
|
-
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
|
8
|
-
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
|
9
|
-
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
|
10
|
-
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
|
11
|
-
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
12
|
-
|
|
13
|
-
import * as perspective_server from "./perspective-server.poly.ts";
|
|
14
|
-
export type * from "../../../dist/wasm/perspective-js.js";
|
|
15
|
-
import type * as perspective_server_t from "@perspective-dev/server/dist/wasm/perspective-server.js";
|
|
16
|
-
|
|
17
|
-
export type PspPtr = BigInt | number;
|
|
18
|
-
export type EmscriptenServer = bigint | number;
|
|
19
|
-
|
|
20
|
-
export interface DiskBridgeHelpers {
|
|
21
|
-
heap: () => Uint8Array;
|
|
22
|
-
toAddr: (p: number | bigint) => number;
|
|
23
|
-
readCString: (p: number | bigint) => string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface CompileOptions {
|
|
27
|
-
env?: Record<string, string | undefined>;
|
|
28
|
-
|
|
29
|
-
make_disk_bridge?: (helpers: DiskBridgeHelpers) => {
|
|
30
|
-
store(
|
|
31
|
-
namePtr: number | bigint,
|
|
32
|
-
dataPtr: number | bigint,
|
|
33
|
-
len: number,
|
|
34
|
-
): number;
|
|
35
|
-
load(
|
|
36
|
-
namePtr: number | bigint,
|
|
37
|
-
dataPtr: number | bigint,
|
|
38
|
-
len: number,
|
|
39
|
-
): number;
|
|
40
|
-
remove(namePtr: number | bigint): void;
|
|
41
|
-
ensureOpen(name: string): Promise<void>;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function compile_perspective(
|
|
46
|
-
wasmBinary: ArrayBuffer,
|
|
47
|
-
opts?: CompileOptions,
|
|
48
|
-
): Promise<perspective_server_t.MainModule> {
|
|
49
|
-
const module = await perspective_server.default({
|
|
50
|
-
locateFile(x: any) {
|
|
51
|
-
return x;
|
|
52
|
-
},
|
|
53
|
-
make_disk_bridge: opts?.make_disk_bridge,
|
|
54
|
-
env: opts?.env,
|
|
55
|
-
instantiateWasm: async (
|
|
56
|
-
imports: any,
|
|
57
|
-
receive: (_: WebAssembly.Instance) => void,
|
|
58
|
-
) => {
|
|
59
|
-
imports["env"] = {
|
|
60
|
-
...imports["env"],
|
|
61
|
-
psp_stack_trace() {
|
|
62
|
-
const str = Error().stack || "";
|
|
63
|
-
const textEncoder = new TextEncoder();
|
|
64
|
-
const bytes = textEncoder.encode(str);
|
|
65
|
-
const ptr = module._psp_alloc(
|
|
66
|
-
module._psp_is_memory64()
|
|
67
|
-
? (BigInt(bytes.byteLength + 1) as any as number)
|
|
68
|
-
: bytes.byteLength + 1,
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
module.HEAPU8.set(bytes, Number(ptr));
|
|
72
|
-
module.HEAPU8[Number(ptr) + bytes.byteLength] = 0;
|
|
73
|
-
return ptr;
|
|
74
|
-
},
|
|
75
|
-
psp_heap_size() {
|
|
76
|
-
if (module._psp_is_memory64()) {
|
|
77
|
-
return BigInt(module.HEAPU8.buffer.byteLength);
|
|
78
|
-
} else {
|
|
79
|
-
return module.HEAPU8.buffer.byteLength;
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const webasm = await WebAssembly.instantiate(wasmBinary, imports);
|
|
85
|
-
receive(webasm.instance);
|
|
86
|
-
return webasm.instance.exports;
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
return module;
|
|
91
|
-
}
|
package/src/ts/wasm/engine.ts
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
2
|
-
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
|
3
|
-
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
|
4
|
-
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
|
5
|
-
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
|
6
|
-
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
|
7
|
-
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
|
8
|
-
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
|
9
|
-
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
|
10
|
-
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
|
11
|
-
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
12
|
-
|
|
13
|
-
import type { MainModule } from "@perspective-dev/server/dist/wasm/perspective-server.js";
|
|
14
|
-
import type { EmscriptenServer, PspPtr } from "./emscripten_api.ts";
|
|
15
|
-
|
|
16
|
-
export type ApiResponse = {
|
|
17
|
-
client_id: number;
|
|
18
|
-
data: Uint8Array;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export interface PerspectiveServerOptions {
|
|
22
|
-
on_poll_request?: (x: PerspectiveServer) => Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A server-wide FIFO async mutex.
|
|
27
|
-
*/
|
|
28
|
-
class AsyncLock {
|
|
29
|
-
private tail: Promise<unknown> = Promise.resolve();
|
|
30
|
-
run<T>(fn: () => Promise<T> | T): Promise<T> {
|
|
31
|
-
const result = this.tail.then(fn, fn);
|
|
32
|
-
this.tail = result.then(
|
|
33
|
-
() => undefined,
|
|
34
|
-
() => undefined,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function residency_safepoint(
|
|
42
|
-
mod: MainModule,
|
|
43
|
-
lock: AsyncLock,
|
|
44
|
-
server: EmscriptenServer,
|
|
45
|
-
) {
|
|
46
|
-
const safepoint = (mod as any).psp_residency_safepoint;
|
|
47
|
-
if (safepoint) {
|
|
48
|
-
await lock.run(() => safepoint(server));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class PerspectivePollThread {
|
|
53
|
-
private poll_handle?: Promise<void>;
|
|
54
|
-
private server: PerspectiveServer;
|
|
55
|
-
constructor(server: PerspectiveServer) {
|
|
56
|
-
this.server = server;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private set_poll_handle() {
|
|
60
|
-
this.poll_handle = new Promise((resolve, reject) =>
|
|
61
|
-
setTimeout(() =>
|
|
62
|
-
this.server
|
|
63
|
-
.poll()
|
|
64
|
-
.then(resolve)
|
|
65
|
-
.catch(reject)
|
|
66
|
-
.finally(() => {
|
|
67
|
-
this.poll_handle = undefined;
|
|
68
|
-
}),
|
|
69
|
-
),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
return this.poll_handle;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async on_poll_request() {
|
|
76
|
-
if (!this.poll_handle) {
|
|
77
|
-
await this.set_poll_handle();
|
|
78
|
-
} else {
|
|
79
|
-
await this.poll_handle.then(() => {
|
|
80
|
-
if (!this.poll_handle) {
|
|
81
|
-
return this.set_poll_handle();
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export class PerspectiveServer {
|
|
89
|
-
clients: Map<number, (buffer: Uint8Array) => Promise<void>>;
|
|
90
|
-
server: EmscriptenServer;
|
|
91
|
-
module: MainModule;
|
|
92
|
-
on_poll_request?: (x: PerspectiveServer) => Promise<void>;
|
|
93
|
-
lock: AsyncLock;
|
|
94
|
-
|
|
95
|
-
constructor(module: MainModule, options?: PerspectiveServerOptions) {
|
|
96
|
-
this.clients = new Map();
|
|
97
|
-
this.module = module;
|
|
98
|
-
this.on_poll_request = options?.on_poll_request;
|
|
99
|
-
this.lock = new AsyncLock();
|
|
100
|
-
this.server = module._psp_new_server(
|
|
101
|
-
!!options?.on_poll_request ? 1 : 0,
|
|
102
|
-
) as EmscriptenServer;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Helper function to create server emitter/receiver pairs
|
|
107
|
-
*/
|
|
108
|
-
make_session(
|
|
109
|
-
callback: (buffer: Uint8Array) => Promise<void>,
|
|
110
|
-
): PerspectiveSession {
|
|
111
|
-
const client_id = this.module._psp_new_session(this.server as any);
|
|
112
|
-
this.clients.set(client_id, callback);
|
|
113
|
-
return new PerspectiveSession(
|
|
114
|
-
this.module,
|
|
115
|
-
this.server,
|
|
116
|
-
client_id,
|
|
117
|
-
this.clients,
|
|
118
|
-
this.lock,
|
|
119
|
-
this.on_poll_request && (() => this.on_poll_request!(this)),
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async poll() {
|
|
124
|
-
const polled = await this.lock.run(() =>
|
|
125
|
-
this.module._psp_poll(this.server as any),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
await decode_api_responses(
|
|
129
|
-
this.module,
|
|
130
|
-
polled,
|
|
131
|
-
async (msg: ApiResponse) => {
|
|
132
|
-
await this.clients.get(msg.client_id)!(msg.data);
|
|
133
|
-
},
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
await residency_safepoint(this.module, this.lock, this.server);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
delete() {
|
|
140
|
-
this.module._psp_delete_server(this.server as any);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export class PerspectiveSession {
|
|
145
|
-
constructor(
|
|
146
|
-
private mod: MainModule,
|
|
147
|
-
private server: EmscriptenServer,
|
|
148
|
-
private client_id: number,
|
|
149
|
-
private client_map: Map<number, (buffer: Uint8Array) => Promise<void>>,
|
|
150
|
-
private lock: AsyncLock,
|
|
151
|
-
private on_poll_request?: () => Promise<void>,
|
|
152
|
-
) {}
|
|
153
|
-
|
|
154
|
-
async handle_request(view: Uint8Array) {
|
|
155
|
-
const ptr = await convert_typed_array_to_pointer(
|
|
156
|
-
this.mod,
|
|
157
|
-
view,
|
|
158
|
-
async (viewPtr) => {
|
|
159
|
-
const len = this.mod._psp_is_memory64()
|
|
160
|
-
? (BigInt(view.byteLength) as any as number)
|
|
161
|
-
: (view.byteLength as any);
|
|
162
|
-
|
|
163
|
-
return this.lock.run(() =>
|
|
164
|
-
this.mod._psp_handle_request(
|
|
165
|
-
this.server as any,
|
|
166
|
-
this.client_id,
|
|
167
|
-
viewPtr as any,
|
|
168
|
-
len,
|
|
169
|
-
),
|
|
170
|
-
);
|
|
171
|
-
},
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
await decode_api_responses(this.mod, ptr, async (msg: ApiResponse) => {
|
|
175
|
-
await this.client_map.get(msg.client_id)!(msg.data);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
if (this.on_poll_request) {
|
|
179
|
-
await this.on_poll_request();
|
|
180
|
-
} else {
|
|
181
|
-
await this.poll();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
await residency_safepoint(this.mod, this.lock, this.server);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
private async poll() {
|
|
188
|
-
const polled = await this.lock.run(() =>
|
|
189
|
-
this.mod._psp_poll(this.server as any),
|
|
190
|
-
);
|
|
191
|
-
await decode_api_responses(
|
|
192
|
-
this.mod,
|
|
193
|
-
polled,
|
|
194
|
-
async (msg: ApiResponse) => {
|
|
195
|
-
if (msg.client_id === 0) {
|
|
196
|
-
await this.client_map.get(this.client_id)!(msg.data);
|
|
197
|
-
} else {
|
|
198
|
-
await this.client_map.get(msg.client_id)!(msg.data);
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
close() {
|
|
205
|
-
this.mod._psp_close_session(this.server as any, this.client_id);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
async function convert_typed_array_to_pointer(
|
|
210
|
-
core: MainModule,
|
|
211
|
-
array: Uint8Array,
|
|
212
|
-
callback: (_: PspPtr) => Promise<PspPtr>,
|
|
213
|
-
): Promise<PspPtr> {
|
|
214
|
-
const is_64 = core._psp_is_memory64();
|
|
215
|
-
const ptr = core._psp_alloc(
|
|
216
|
-
is_64
|
|
217
|
-
? (BigInt(array.byteLength) as any as number)
|
|
218
|
-
: (array.byteLength as any),
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
const addr = is_64 ? Number(ptr) : Number(ptr) >>> 0;
|
|
222
|
-
core.HEAPU8.set(array, addr);
|
|
223
|
-
const msg = await callback(ptr);
|
|
224
|
-
core._psp_free(ptr);
|
|
225
|
-
return msg;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Convert a pointer to WASM memory into an `ApiResponse[]`, via a custom
|
|
230
|
-
* encoding.
|
|
231
|
-
*
|
|
232
|
-
* @param core The emscripten API
|
|
233
|
-
* @param ptr A pointer to a fixed-sized struct representing a set of
|
|
234
|
-
* `proto::Resp` payloads, encoded as a length-prefixed array of
|
|
235
|
-
* (char* data, u32_t len, u32_t client_id) tuples:
|
|
236
|
-
*
|
|
237
|
-
* ```text
|
|
238
|
-
* N data length client_id data length client_id
|
|
239
|
-
* +-------------------------------------------------------------+
|
|
240
|
-
* | 2 | 0xabc | 9 | 0 | 0xdef | 12 | 0 |
|
|
241
|
-
* +-------------------------------------------------------------+
|
|
242
|
-
* | |
|
|
243
|
-
* | +-------------+ | +----------------+
|
|
244
|
-
* +--| "Test Data" | +--| "Hello, World" |
|
|
245
|
-
* +-------------+ +----------------+
|
|
246
|
-
* ```
|
|
247
|
-
*
|
|
248
|
-
* @param callback A callback to which is passed the responses. THe responses
|
|
249
|
-
* must be fully processed or copied before the callback returns, as it
|
|
250
|
-
* references memory on the wasm stack, which a `callback` that allocates may
|
|
251
|
-
* also detach - hence the message descriptors are read before dispatching.
|
|
252
|
-
*/
|
|
253
|
-
async function decode_api_responses(
|
|
254
|
-
core: MainModule,
|
|
255
|
-
ptr: PspPtr,
|
|
256
|
-
callback: (_: ApiResponse) => Promise<void>,
|
|
257
|
-
) {
|
|
258
|
-
const is_64 = core._psp_is_memory64();
|
|
259
|
-
const response_ptr = is_64 ? Number(ptr) : Number(ptr) >>> 0;
|
|
260
|
-
const response = new DataView(
|
|
261
|
-
core.HEAPU8.buffer,
|
|
262
|
-
response_ptr,
|
|
263
|
-
is_64 ? 12 : 8,
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
const num_msgs = response.getUint32(0, true);
|
|
267
|
-
const msgs_ptr = Number(
|
|
268
|
-
is_64 ? response.getBigInt64(4, true) : response.getUint32(4, true),
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
const messages = new DataView(
|
|
272
|
-
core.HEAPU8.buffer,
|
|
273
|
-
msgs_ptr,
|
|
274
|
-
num_msgs * (is_64 ? 16 : 12),
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
const free = (x: number) => core._psp_free((is_64 ? BigInt(x) : x) as any);
|
|
278
|
-
|
|
279
|
-
const descriptors: [number, number, number][] = [];
|
|
280
|
-
for (let i = 0; i < num_msgs; i++) {
|
|
281
|
-
descriptors.push(
|
|
282
|
-
is_64
|
|
283
|
-
? [
|
|
284
|
-
Number(messages.getBigInt64(i * 16, true)),
|
|
285
|
-
messages.getInt32(i * 16 + 8, true),
|
|
286
|
-
messages.getInt32(i * 16 + 12, true),
|
|
287
|
-
]
|
|
288
|
-
: [
|
|
289
|
-
messages.getUint32(i * 12, true),
|
|
290
|
-
messages.getUint32(i * 12 + 4, true),
|
|
291
|
-
messages.getInt32(i * 12 + 8, true),
|
|
292
|
-
],
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
try {
|
|
297
|
-
for (const [data_ptr, data_len, client_id] of descriptors) {
|
|
298
|
-
const data = new Uint8Array(core.HEAPU8.buffer, data_ptr, data_len);
|
|
299
|
-
await callback({ client_id, data });
|
|
300
|
-
}
|
|
301
|
-
} finally {
|
|
302
|
-
for (const [data_ptr] of descriptors) {
|
|
303
|
-
free(data_ptr);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
free(msgs_ptr);
|
|
307
|
-
free(response_ptr);
|
|
308
|
-
}
|
|
309
|
-
}
|
package/src/ts/wasm/features.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
2
|
-
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
|
3
|
-
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
|
4
|
-
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
|
5
|
-
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
|
6
|
-
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
|
7
|
-
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
|
8
|
-
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
|
9
|
-
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
|
10
|
-
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
|
11
|
-
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
12
|
-
|
|
13
|
-
// The encoding of `(module (memory i64 1))` — validates only on hosts with
|
|
14
|
-
// WebAssembly Memory64 support (the same probe `wasm-feature-detect` uses).
|
|
15
|
-
const MEMORY64_PROBE = new Uint8Array([
|
|
16
|
-
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x05, 0x03, 0x01, 0x04,
|
|
17
|
-
0x01,
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
let MEMORY64_SUPPORTED: boolean | undefined;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Does this JavaScript host support WebAssembly Memory64 (wasm64)?
|
|
24
|
-
*/
|
|
25
|
-
export function host_supports_memory64(): boolean {
|
|
26
|
-
if (MEMORY64_SUPPORTED === undefined) {
|
|
27
|
-
MEMORY64_SUPPORTED = WebAssembly.validate(MEMORY64_PROBE);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return MEMORY64_SUPPORTED;
|
|
31
|
-
}
|