@perspective-dev/client 4.5.1 → 5.0.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/dist/cdn/perspective-server.worker.js +1 -1
- package/dist/cdn/perspective-server.worker.js.map +3 -3
- package/dist/cdn/perspective.js +2 -2
- package/dist/cdn/perspective.js.map +4 -4
- package/dist/esm/perspective.browser.d.ts +50 -1
- package/dist/esm/perspective.inline.js +2 -2
- package/dist/esm/perspective.inline.js.map +4 -4
- package/dist/esm/perspective.js +2 -2
- package/dist/esm/perspective.js.map +4 -4
- package/dist/esm/perspective.node.d.ts +3 -0
- package/dist/esm/perspective.node.js +328 -25
- package/dist/esm/perspective.node.js.map +4 -4
- package/dist/esm/ts-rs/TableInitOptions.d.ts +6 -0
- package/dist/esm/virtual_servers/clickhouse.js +1 -1
- package/dist/esm/virtual_servers/clickhouse.js.map +2 -2
- package/dist/esm/virtual_servers/duckdb.js +1 -1
- package/dist/esm/virtual_servers/duckdb.js.map +2 -2
- package/dist/esm/wasm/emscripten_api.d.ts +14 -1
- package/dist/esm/wasm/engine.d.ts +11 -1
- package/dist/esm/wasm/features.d.ts +4 -0
- package/dist/wasm/perspective-js.d.ts +5 -5
- package/dist/wasm/perspective-js.js +9 -9
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +5 -5
- package/package.json +1 -1
- package/src/rust/typed_array.rs +88 -54
- package/src/ts/perspective.browser.ts +176 -20
- package/src/ts/perspective.cdn.ts +11 -5
- package/src/ts/perspective.node.ts +157 -5
- package/src/ts/ts-rs/TableInitOptions.ts +7 -1
- package/src/ts/virtual_servers/clickhouse.ts +1 -0
- package/src/ts/virtual_servers/duckdb.ts +3 -1
- package/src/ts/wasm/cdn.ts +32 -0
- package/src/ts/wasm/emscripten_api.ts +25 -0
- package/src/ts/wasm/engine.ts +59 -12
- package/src/ts/wasm/features.ts +31 -0
- package/src/ts/wasm/perspective-server.poly.ts +173 -3
|
@@ -3,7 +3,9 @@ export type * from "./virtual_server.ts";
|
|
|
3
3
|
import { WebSocketServer as HttpWebSocketServer } from "ws";
|
|
4
4
|
import http from "node:http";
|
|
5
5
|
import * as perspective_client from "../../dist/wasm/perspective-js.js";
|
|
6
|
+
import { host_supports_memory64 } from "./wasm/features.ts";
|
|
6
7
|
import * as engine from "./wasm/engine.ts";
|
|
8
|
+
export { host_supports_memory64 } from "./wasm/features.ts";
|
|
7
9
|
import * as virtual_server from "./virtual_server.ts";
|
|
8
10
|
export { GenericSQLVirtualServerModel, VirtualDataSlice, VirtualServer, } from "../../dist/wasm/perspective-js.js";
|
|
9
11
|
export declare class PerspectiveServer extends engine.PerspectiveServer {
|
|
@@ -83,6 +85,7 @@ declare const _default: {
|
|
|
83
85
|
join: typeof join;
|
|
84
86
|
websocket: typeof websocket;
|
|
85
87
|
worker: typeof worker;
|
|
88
|
+
host_supports_memory64: typeof host_supports_memory64;
|
|
86
89
|
get_hosted_table_names: typeof get_hosted_table_names;
|
|
87
90
|
on_hosted_tables_update: typeof on_hosted_tables_update;
|
|
88
91
|
remove_hosted_tables_update: typeof remove_hosted_tables_update;
|
|
@@ -8,6 +8,16 @@ var __export = (target, all) => {
|
|
|
8
8
|
import WebSocket, { WebSocketServer as HttpWebSocketServer } from "ws";
|
|
9
9
|
import stoppable from "stoppable";
|
|
10
10
|
import { promises as fs } from "node:fs";
|
|
11
|
+
import {
|
|
12
|
+
openSync,
|
|
13
|
+
readSync,
|
|
14
|
+
writeSync,
|
|
15
|
+
closeSync,
|
|
16
|
+
mkdirSync,
|
|
17
|
+
unlinkSync,
|
|
18
|
+
rmSync
|
|
19
|
+
} from "node:fs";
|
|
20
|
+
import os from "node:os";
|
|
11
21
|
import http from "node:http";
|
|
12
22
|
import path from "node:path";
|
|
13
23
|
import { webcrypto } from "node:crypto";
|
|
@@ -2025,7 +2035,7 @@ function __wbg_get_imports() {
|
|
|
2025
2035
|
const a = state0.a;
|
|
2026
2036
|
state0.a = 0;
|
|
2027
2037
|
try {
|
|
2028
|
-
return
|
|
2038
|
+
return __wasm_bindgen_func_elem_11001(a, state0.b, arg02, arg12);
|
|
2029
2039
|
} finally {
|
|
2030
2040
|
state0.a = a;
|
|
2031
2041
|
}
|
|
@@ -2189,11 +2199,11 @@ function __wbg_get_imports() {
|
|
|
2189
2199
|
console.warn(getObject(arg0));
|
|
2190
2200
|
},
|
|
2191
2201
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
2192
|
-
const ret = makeClosure(arg0, arg1, wasm.
|
|
2202
|
+
const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1082, __wasm_bindgen_func_elem_1766);
|
|
2193
2203
|
return addHeapObject(ret);
|
|
2194
2204
|
},
|
|
2195
2205
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
2196
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
2206
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4003, __wasm_bindgen_func_elem_4020);
|
|
2197
2207
|
return addHeapObject(ret);
|
|
2198
2208
|
},
|
|
2199
2209
|
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
@@ -2258,15 +2268,15 @@ function __wbg_get_imports() {
|
|
|
2258
2268
|
"./perspective-js.wasm_bg.js": import0
|
|
2259
2269
|
};
|
|
2260
2270
|
}
|
|
2261
|
-
function
|
|
2262
|
-
const ret = wasm.
|
|
2271
|
+
function __wasm_bindgen_func_elem_1766(arg0, arg1) {
|
|
2272
|
+
const ret = wasm.__wasm_bindgen_func_elem_1766(arg0, arg1);
|
|
2263
2273
|
return takeObject(ret);
|
|
2264
2274
|
}
|
|
2265
|
-
function
|
|
2266
|
-
wasm.
|
|
2275
|
+
function __wasm_bindgen_func_elem_4020(arg0, arg1, arg2) {
|
|
2276
|
+
wasm.__wasm_bindgen_func_elem_4020(arg0, arg1, addHeapObject(arg2));
|
|
2267
2277
|
}
|
|
2268
|
-
function
|
|
2269
|
-
wasm.
|
|
2278
|
+
function __wasm_bindgen_func_elem_11001(arg0, arg1, arg2, arg3) {
|
|
2279
|
+
wasm.__wasm_bindgen_func_elem_11001(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
2270
2280
|
}
|
|
2271
2281
|
var ClientFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
|
|
2272
2282
|
}, unregister: () => {
|
|
@@ -2665,16 +2675,59 @@ async function load_wasm_stage_0(wasm2) {
|
|
|
2665
2675
|
}
|
|
2666
2676
|
}
|
|
2667
2677
|
|
|
2678
|
+
// src/ts/wasm/features.ts
|
|
2679
|
+
var MEMORY64_PROBE = new Uint8Array([
|
|
2680
|
+
0,
|
|
2681
|
+
97,
|
|
2682
|
+
115,
|
|
2683
|
+
109,
|
|
2684
|
+
1,
|
|
2685
|
+
0,
|
|
2686
|
+
0,
|
|
2687
|
+
0,
|
|
2688
|
+
5,
|
|
2689
|
+
3,
|
|
2690
|
+
1,
|
|
2691
|
+
4,
|
|
2692
|
+
1
|
|
2693
|
+
]);
|
|
2694
|
+
var MEMORY64_SUPPORTED;
|
|
2695
|
+
function host_supports_memory64() {
|
|
2696
|
+
if (MEMORY64_SUPPORTED === void 0) {
|
|
2697
|
+
MEMORY64_SUPPORTED = WebAssembly.validate(MEMORY64_PROBE);
|
|
2698
|
+
}
|
|
2699
|
+
return MEMORY64_SUPPORTED;
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2668
2702
|
// src/ts/wasm/engine.ts
|
|
2703
|
+
var AsyncLock = class {
|
|
2704
|
+
tail = Promise.resolve();
|
|
2705
|
+
run(fn) {
|
|
2706
|
+
const result = this.tail.then(fn, fn);
|
|
2707
|
+
this.tail = result.then(
|
|
2708
|
+
() => void 0,
|
|
2709
|
+
() => void 0
|
|
2710
|
+
);
|
|
2711
|
+
return result;
|
|
2712
|
+
}
|
|
2713
|
+
};
|
|
2714
|
+
async function residency_safepoint(mod, lock, server) {
|
|
2715
|
+
const safepoint = mod.psp_residency_safepoint;
|
|
2716
|
+
if (safepoint) {
|
|
2717
|
+
await lock.run(() => safepoint(server));
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2669
2720
|
var PerspectiveServer = class {
|
|
2670
2721
|
clients;
|
|
2671
2722
|
server;
|
|
2672
2723
|
module;
|
|
2673
2724
|
on_poll_request;
|
|
2725
|
+
lock;
|
|
2674
2726
|
constructor(module, options) {
|
|
2675
2727
|
this.clients = /* @__PURE__ */ new Map();
|
|
2676
2728
|
this.module = module;
|
|
2677
2729
|
this.on_poll_request = options?.on_poll_request;
|
|
2730
|
+
this.lock = new AsyncLock();
|
|
2678
2731
|
this.server = module._psp_new_server(
|
|
2679
2732
|
!!options?.on_poll_request ? 1 : 0
|
|
2680
2733
|
);
|
|
@@ -2690,11 +2743,14 @@ var PerspectiveServer = class {
|
|
|
2690
2743
|
this.server,
|
|
2691
2744
|
client_id,
|
|
2692
2745
|
this.clients,
|
|
2746
|
+
this.lock,
|
|
2693
2747
|
this.on_poll_request && (() => this.on_poll_request(this))
|
|
2694
2748
|
);
|
|
2695
2749
|
}
|
|
2696
2750
|
async poll() {
|
|
2697
|
-
const polled = this.
|
|
2751
|
+
const polled = await this.lock.run(
|
|
2752
|
+
() => this.module._psp_poll(this.server)
|
|
2753
|
+
);
|
|
2698
2754
|
await decode_api_responses(
|
|
2699
2755
|
this.module,
|
|
2700
2756
|
polled,
|
|
@@ -2702,17 +2758,19 @@ var PerspectiveServer = class {
|
|
|
2702
2758
|
await this.clients.get(msg.client_id)(msg.data);
|
|
2703
2759
|
}
|
|
2704
2760
|
);
|
|
2761
|
+
await residency_safepoint(this.module, this.lock, this.server);
|
|
2705
2762
|
}
|
|
2706
2763
|
delete() {
|
|
2707
2764
|
this.module._psp_delete_server(this.server);
|
|
2708
2765
|
}
|
|
2709
2766
|
};
|
|
2710
2767
|
var PerspectiveSession = class {
|
|
2711
|
-
constructor(mod, server, client_id, client_map, on_poll_request) {
|
|
2768
|
+
constructor(mod, server, client_id, client_map, lock, on_poll_request) {
|
|
2712
2769
|
this.mod = mod;
|
|
2713
2770
|
this.server = server;
|
|
2714
2771
|
this.client_id = client_id;
|
|
2715
2772
|
this.client_map = client_map;
|
|
2773
|
+
this.lock = lock;
|
|
2716
2774
|
this.on_poll_request = on_poll_request;
|
|
2717
2775
|
}
|
|
2718
2776
|
async handle_request(view) {
|
|
@@ -2720,11 +2778,14 @@ var PerspectiveSession = class {
|
|
|
2720
2778
|
this.mod,
|
|
2721
2779
|
view,
|
|
2722
2780
|
async (viewPtr) => {
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
this.
|
|
2726
|
-
|
|
2727
|
-
|
|
2781
|
+
const len = this.mod._psp_is_memory64() ? BigInt(view.byteLength) : view.byteLength;
|
|
2782
|
+
return this.lock.run(
|
|
2783
|
+
() => this.mod._psp_handle_request(
|
|
2784
|
+
this.server,
|
|
2785
|
+
this.client_id,
|
|
2786
|
+
viewPtr,
|
|
2787
|
+
len
|
|
2788
|
+
)
|
|
2728
2789
|
);
|
|
2729
2790
|
}
|
|
2730
2791
|
);
|
|
@@ -2736,9 +2797,12 @@ var PerspectiveSession = class {
|
|
|
2736
2797
|
} else {
|
|
2737
2798
|
await this.poll();
|
|
2738
2799
|
}
|
|
2800
|
+
await residency_safepoint(this.mod, this.lock, this.server);
|
|
2739
2801
|
}
|
|
2740
2802
|
async poll() {
|
|
2741
|
-
const polled = this.
|
|
2803
|
+
const polled = await this.lock.run(
|
|
2804
|
+
() => this.mod._psp_poll(this.server)
|
|
2805
|
+
);
|
|
2742
2806
|
await decode_api_responses(
|
|
2743
2807
|
this.mod,
|
|
2744
2808
|
polled,
|
|
@@ -2756,10 +2820,12 @@ var PerspectiveSession = class {
|
|
|
2756
2820
|
}
|
|
2757
2821
|
};
|
|
2758
2822
|
async function convert_typed_array_to_pointer(core, array, callback) {
|
|
2823
|
+
const is_64 = core._psp_is_memory64();
|
|
2759
2824
|
const ptr = core._psp_alloc(
|
|
2760
|
-
|
|
2825
|
+
is_64 ? BigInt(array.byteLength) : array.byteLength
|
|
2761
2826
|
);
|
|
2762
|
-
|
|
2827
|
+
const addr = is_64 ? Number(ptr) : Number(ptr) >>> 0;
|
|
2828
|
+
core.HEAPU8.set(array, addr);
|
|
2763
2829
|
const msg = await callback(ptr);
|
|
2764
2830
|
core._psp_free(ptr);
|
|
2765
2831
|
return msg;
|
|
@@ -2768,7 +2834,7 @@ async function decode_api_responses(core, ptr, callback) {
|
|
|
2768
2834
|
const is_64 = core._psp_is_memory64();
|
|
2769
2835
|
const response = new DataView(
|
|
2770
2836
|
core.HEAPU8.buffer,
|
|
2771
|
-
Number(ptr),
|
|
2837
|
+
is_64 ? Number(ptr) : Number(ptr) >>> 0,
|
|
2772
2838
|
is_64 ? 12 : 8
|
|
2773
2839
|
);
|
|
2774
2840
|
const num_msgs = response.getUint32(0, true);
|
|
@@ -2837,6 +2903,105 @@ async function perspective_server_poly_default(obj) {
|
|
|
2837
2903
|
let psp_module;
|
|
2838
2904
|
let is_memory64 = false;
|
|
2839
2905
|
let wasm_memory;
|
|
2906
|
+
const heap2 = () => new Uint8Array(wasm_memory.buffer);
|
|
2907
|
+
const toAddr = (p) => is_memory64 ? Number(p) : p >>> 0;
|
|
2908
|
+
function readCString(p) {
|
|
2909
|
+
const addr = toAddr(p);
|
|
2910
|
+
const h = heap2();
|
|
2911
|
+
let end = addr;
|
|
2912
|
+
while (h[end]) ++end;
|
|
2913
|
+
return UTF8Decoder.decode(h.subarray(addr, end));
|
|
2914
|
+
}
|
|
2915
|
+
const disk_helpers = { heap: heap2, toAddr, readCString };
|
|
2916
|
+
function makeOpfsBridge() {
|
|
2917
|
+
async function opfsOpenFile(name, create) {
|
|
2918
|
+
const parts = name.split("/").filter((s) => s.length > 0);
|
|
2919
|
+
let dir = await navigator.storage.getDirectory();
|
|
2920
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
2921
|
+
dir = await dir.getDirectoryHandle(parts[i], { create });
|
|
2922
|
+
}
|
|
2923
|
+
return await dir.getFileHandle(parts[parts.length - 1], { create });
|
|
2924
|
+
}
|
|
2925
|
+
const handles = /* @__PURE__ */ new Map();
|
|
2926
|
+
return {
|
|
2927
|
+
async ensureOpen(name) {
|
|
2928
|
+
if (handles.has(name)) {
|
|
2929
|
+
return;
|
|
2930
|
+
}
|
|
2931
|
+
const fh = await opfsOpenFile(name, true);
|
|
2932
|
+
const ah = await fh.createSyncAccessHandle();
|
|
2933
|
+
handles.set(name, ah);
|
|
2934
|
+
},
|
|
2935
|
+
store(namePtr, dataPtr, len) {
|
|
2936
|
+
try {
|
|
2937
|
+
const ah = handles.get(readCString(namePtr));
|
|
2938
|
+
if (!ah) {
|
|
2939
|
+
return -1;
|
|
2940
|
+
}
|
|
2941
|
+
ah.truncate(len);
|
|
2942
|
+
if (len > 0) {
|
|
2943
|
+
const addr = toAddr(dataPtr);
|
|
2944
|
+
ah.write(heap2().subarray(addr, addr + len), { at: 0 });
|
|
2945
|
+
}
|
|
2946
|
+
ah.flush();
|
|
2947
|
+
return len;
|
|
2948
|
+
} catch (e) {
|
|
2949
|
+
err("psp_opfs_store failed", e);
|
|
2950
|
+
return -1;
|
|
2951
|
+
}
|
|
2952
|
+
},
|
|
2953
|
+
load(namePtr, dataPtr, len) {
|
|
2954
|
+
try {
|
|
2955
|
+
if (len <= 0) {
|
|
2956
|
+
return 0;
|
|
2957
|
+
}
|
|
2958
|
+
const ah = handles.get(readCString(namePtr));
|
|
2959
|
+
if (!ah) {
|
|
2960
|
+
return 0;
|
|
2961
|
+
}
|
|
2962
|
+
const addr = toAddr(dataPtr);
|
|
2963
|
+
return ah.read(heap2().subarray(addr, addr + len), {
|
|
2964
|
+
at: 0
|
|
2965
|
+
});
|
|
2966
|
+
} catch (e) {
|
|
2967
|
+
return 0;
|
|
2968
|
+
}
|
|
2969
|
+
},
|
|
2970
|
+
remove(namePtr) {
|
|
2971
|
+
try {
|
|
2972
|
+
const name = readCString(namePtr);
|
|
2973
|
+
const ah = handles.get(name);
|
|
2974
|
+
if (ah) {
|
|
2975
|
+
try {
|
|
2976
|
+
ah.close();
|
|
2977
|
+
} catch (e) {
|
|
2978
|
+
}
|
|
2979
|
+
handles.delete(name);
|
|
2980
|
+
}
|
|
2981
|
+
void (async () => {
|
|
2982
|
+
try {
|
|
2983
|
+
const parts = name.split("/").filter((s) => s.length > 0);
|
|
2984
|
+
let dir = await navigator.storage.getDirectory();
|
|
2985
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
2986
|
+
dir = await dir.getDirectoryHandle(parts[i], {
|
|
2987
|
+
create: false
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
await dir.removeEntry(parts[parts.length - 1]);
|
|
2991
|
+
} catch (e) {
|
|
2992
|
+
}
|
|
2993
|
+
})();
|
|
2994
|
+
} catch (e) {
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
const disk = obj.make_disk_bridge ? obj.make_disk_bridge(disk_helpers) : makeOpfsBridge();
|
|
3000
|
+
const opfs_imports = {
|
|
3001
|
+
psp_opfs_store: disk.store,
|
|
3002
|
+
psp_opfs_load: disk.load,
|
|
3003
|
+
psp_opfs_remove: disk.remove
|
|
3004
|
+
};
|
|
2840
3005
|
const module = {
|
|
2841
3006
|
HaveOffsetConverter() {
|
|
2842
3007
|
console.error("HaveOffsetConverter");
|
|
@@ -2972,7 +3137,8 @@ async function perspective_server_poly_default(obj) {
|
|
|
2972
3137
|
proc_exit(e) {
|
|
2973
3138
|
console.error("proc_exit", e);
|
|
2974
3139
|
return 0;
|
|
2975
|
-
}
|
|
3140
|
+
},
|
|
3141
|
+
...opfs_imports
|
|
2976
3142
|
};
|
|
2977
3143
|
const x = await obj.instantiateWasm(
|
|
2978
3144
|
{ env: module, wasi_snapshot_preview1: module },
|
|
@@ -2987,9 +3153,26 @@ async function perspective_server_poly_default(obj) {
|
|
|
2987
3153
|
for (const [name, func] of Object.entries(x)) {
|
|
2988
3154
|
extensions[`_${name}`] = func;
|
|
2989
3155
|
}
|
|
3156
|
+
const psp_residency_safepoint = async (server) => {
|
|
3157
|
+
const mod = psp_module;
|
|
3158
|
+
if (!mod.psp_residency_prepare) {
|
|
3159
|
+
return;
|
|
3160
|
+
}
|
|
3161
|
+
const n = Number(mod.psp_residency_prepare(server));
|
|
3162
|
+
for (let i = 0; i < n; i++) {
|
|
3163
|
+
const fname = readCString(
|
|
3164
|
+
mod.psp_residency_victim_fname(server, i)
|
|
3165
|
+
);
|
|
3166
|
+
if (fname) {
|
|
3167
|
+
await disk.ensureOpen(fname);
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
mod.psp_residency_commit(server);
|
|
3171
|
+
};
|
|
2990
3172
|
return {
|
|
2991
3173
|
...x,
|
|
2992
3174
|
...extensions,
|
|
3175
|
+
psp_residency_safepoint,
|
|
2993
3176
|
get HEAPU8() {
|
|
2994
3177
|
return new Uint8Array(wasm_memory.buffer);
|
|
2995
3178
|
}
|
|
@@ -2997,11 +3180,12 @@ async function perspective_server_poly_default(obj) {
|
|
|
2997
3180
|
}
|
|
2998
3181
|
|
|
2999
3182
|
// src/ts/wasm/emscripten_api.ts
|
|
3000
|
-
async function compile_perspective(wasmBinary) {
|
|
3183
|
+
async function compile_perspective(wasmBinary, opts) {
|
|
3001
3184
|
const module = await perspective_server_poly_default({
|
|
3002
3185
|
locateFile(x) {
|
|
3003
3186
|
return x;
|
|
3004
3187
|
},
|
|
3188
|
+
make_disk_bridge: opts?.make_disk_bridge,
|
|
3005
3189
|
instantiateWasm: async (imports, receive) => {
|
|
3006
3190
|
imports["env"] = {
|
|
3007
3191
|
...imports["env"],
|
|
@@ -3132,9 +3316,126 @@ if (!globalThis.crypto) {
|
|
|
3132
3316
|
}
|
|
3133
3317
|
var uncompressed_client_wasm = await fs.readFile(path.join(__dirname, "../../dist/wasm/perspective-js.wasm")).then((buffer) => load_wasm_stage_0(buffer.buffer));
|
|
3134
3318
|
await __wbg_init({ module_or_path: uncompressed_client_wasm });
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3319
|
+
function make_node_disk_bridge({
|
|
3320
|
+
heap: heap2,
|
|
3321
|
+
toAddr,
|
|
3322
|
+
readCString
|
|
3323
|
+
}) {
|
|
3324
|
+
const root = path.join(os.tmpdir(), `perspective-${process.pid}`);
|
|
3325
|
+
const resolve_path = (name) => {
|
|
3326
|
+
const p = path.join(root, name);
|
|
3327
|
+
if (!p.startsWith(root)) {
|
|
3328
|
+
throw new Error(`refusing disk path outside root: ${name}`);
|
|
3329
|
+
}
|
|
3330
|
+
return p;
|
|
3331
|
+
};
|
|
3332
|
+
let cleaned = false;
|
|
3333
|
+
const cleanup = () => {
|
|
3334
|
+
if (cleaned) return;
|
|
3335
|
+
cleaned = true;
|
|
3336
|
+
try {
|
|
3337
|
+
rmSync(root, { recursive: true, force: true });
|
|
3338
|
+
} catch (e) {
|
|
3339
|
+
}
|
|
3340
|
+
};
|
|
3341
|
+
process.on("exit", cleanup);
|
|
3342
|
+
process.on("SIGINT", () => {
|
|
3343
|
+
cleanup();
|
|
3344
|
+
process.exit(130);
|
|
3345
|
+
});
|
|
3346
|
+
return {
|
|
3347
|
+
// node:fs is synchronous — nothing to pre-open between safepoint phases.
|
|
3348
|
+
async ensureOpen(_name) {
|
|
3349
|
+
},
|
|
3350
|
+
store(namePtr, dataPtr, len) {
|
|
3351
|
+
try {
|
|
3352
|
+
const p = resolve_path(readCString(namePtr));
|
|
3353
|
+
mkdirSync(path.dirname(p), { recursive: true });
|
|
3354
|
+
const fd = openSync(p, "w");
|
|
3355
|
+
try {
|
|
3356
|
+
if (len > 0) {
|
|
3357
|
+
const addr = toAddr(dataPtr);
|
|
3358
|
+
const view = heap2().subarray(addr, addr + len);
|
|
3359
|
+
let off = 0;
|
|
3360
|
+
while (off < len) {
|
|
3361
|
+
off += writeSync(fd, view, off, len - off, off);
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
} finally {
|
|
3365
|
+
closeSync(fd);
|
|
3366
|
+
}
|
|
3367
|
+
return len;
|
|
3368
|
+
} catch (e) {
|
|
3369
|
+
console.error("node disk store failed", e);
|
|
3370
|
+
return -1;
|
|
3371
|
+
}
|
|
3372
|
+
},
|
|
3373
|
+
load(namePtr, dataPtr, len) {
|
|
3374
|
+
try {
|
|
3375
|
+
if (len <= 0) return 0;
|
|
3376
|
+
let fd;
|
|
3377
|
+
try {
|
|
3378
|
+
fd = openSync(resolve_path(readCString(namePtr)), "r");
|
|
3379
|
+
} catch (e) {
|
|
3380
|
+
return 0;
|
|
3381
|
+
}
|
|
3382
|
+
try {
|
|
3383
|
+
const addr = toAddr(dataPtr);
|
|
3384
|
+
const view = heap2().subarray(addr, addr + len);
|
|
3385
|
+
let off = 0;
|
|
3386
|
+
let n;
|
|
3387
|
+
while (off < len && (n = readSync(fd, view, off, len - off, off)) > 0) {
|
|
3388
|
+
off += n;
|
|
3389
|
+
}
|
|
3390
|
+
return off;
|
|
3391
|
+
} finally {
|
|
3392
|
+
closeSync(fd);
|
|
3393
|
+
}
|
|
3394
|
+
} catch (e) {
|
|
3395
|
+
return 0;
|
|
3396
|
+
}
|
|
3397
|
+
},
|
|
3398
|
+
remove(namePtr) {
|
|
3399
|
+
try {
|
|
3400
|
+
unlinkSync(resolve_path(readCString(namePtr)));
|
|
3401
|
+
} catch (e) {
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
};
|
|
3405
|
+
}
|
|
3406
|
+
async function compile_server_module(wasm_path) {
|
|
3407
|
+
const buffer = await fs.readFile(wasm_path);
|
|
3408
|
+
const bytes = await load_wasm_stage_0(buffer.buffer);
|
|
3409
|
+
return await compile_perspective(bytes.buffer, {
|
|
3410
|
+
make_disk_bridge: make_node_disk_bridge
|
|
3411
|
+
});
|
|
3412
|
+
}
|
|
3413
|
+
async function load_server_module() {
|
|
3414
|
+
if (host_supports_memory64()) {
|
|
3415
|
+
let wasm_path;
|
|
3416
|
+
try {
|
|
3417
|
+
wasm_path = resolve(
|
|
3418
|
+
"@perspective-dev/server/dist/wasm/perspective-server.memory64.wasm"
|
|
3419
|
+
);
|
|
3420
|
+
} catch (e) {
|
|
3421
|
+
wasm_path = void 0;
|
|
3422
|
+
}
|
|
3423
|
+
if (wasm_path !== void 0) {
|
|
3424
|
+
try {
|
|
3425
|
+
return await compile_server_module(wasm_path);
|
|
3426
|
+
} catch (e) {
|
|
3427
|
+
console.warn(
|
|
3428
|
+
"Memory64 perspective server wasm failed to load, falling back to wasm32",
|
|
3429
|
+
e
|
|
3430
|
+
);
|
|
3431
|
+
}
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
return await compile_server_module(
|
|
3435
|
+
resolve("@perspective-dev/server/dist/wasm/perspective-server.wasm")
|
|
3436
|
+
);
|
|
3437
|
+
}
|
|
3438
|
+
var SYNC_MODULE = await load_server_module();
|
|
3138
3439
|
var SYNC_CLIENT;
|
|
3139
3440
|
var SYNC_SERVER = new PerspectiveServer(SYNC_MODULE);
|
|
3140
3441
|
var SYNC_SESSION = SYNC_SERVER.make_session(
|
|
@@ -3335,6 +3636,7 @@ var perspective_node_default = {
|
|
|
3335
3636
|
join,
|
|
3336
3637
|
websocket: websocket2,
|
|
3337
3638
|
worker,
|
|
3639
|
+
host_supports_memory64,
|
|
3338
3640
|
get_hosted_table_names,
|
|
3339
3641
|
on_hosted_tables_update,
|
|
3340
3642
|
remove_hosted_tables_update,
|
|
@@ -3355,6 +3657,7 @@ export {
|
|
|
3355
3657
|
cwd_static_file_handler,
|
|
3356
3658
|
perspective_node_default as default,
|
|
3357
3659
|
get_hosted_table_names,
|
|
3660
|
+
host_supports_memory64,
|
|
3358
3661
|
join,
|
|
3359
3662
|
make_client,
|
|
3360
3663
|
make_session,
|