@perspective-dev/client 5.6.1 → 5.8.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 +734 -39
- 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 +41 -0
- package/dist/esm/virtual_servers/clickhouse.js +6 -1
- package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
- package/dist/esm/virtual_servers/duckdb.d.ts +19 -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/ViewOnUpdateResp.ts → dist/ts-rs/ViewOnUpdateResp.d.ts} +1 -1
- 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 +136 -58
- package/dist/wasm/perspective-js.js +190 -24
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +14 -8
- package/dist/wasm/perspective-migrate.d.ts +41 -0
- package/dist/wasm/perspective-migrate.js +524 -0
- package/dist/wasm/perspective-migrate.wasm +0 -0
- package/dist/wasm/perspective-migrate.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/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
|
@@ -1,556 +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
|
-
export type * from "../../dist/wasm/perspective-js.d.ts";
|
|
14
|
-
export type * from "./virtual_server.ts";
|
|
15
|
-
|
|
16
|
-
import WebSocket, { WebSocketServer as HttpWebSocketServer } from "ws";
|
|
17
|
-
import stoppable from "stoppable";
|
|
18
|
-
import { promises as fs } from "node:fs";
|
|
19
|
-
import {
|
|
20
|
-
openSync,
|
|
21
|
-
readSync,
|
|
22
|
-
writeSync,
|
|
23
|
-
closeSync,
|
|
24
|
-
mkdirSync,
|
|
25
|
-
unlinkSync,
|
|
26
|
-
rmSync,
|
|
27
|
-
} from "node:fs";
|
|
28
|
-
import os from "node:os";
|
|
29
|
-
import http from "node:http";
|
|
30
|
-
import path from "node:path";
|
|
31
|
-
import { webcrypto } from "node:crypto";
|
|
32
|
-
import type * as net from "node:net";
|
|
33
|
-
import * as url from "node:url";
|
|
34
|
-
import { createRequire } from "node:module";
|
|
35
|
-
|
|
36
|
-
import * as perspective_client from "../../dist/wasm/perspective-js.js";
|
|
37
|
-
import { load_wasm_stage_0 } from "./wasm/decompress.js";
|
|
38
|
-
import { host_supports_memory64 } from "./wasm/features.ts";
|
|
39
|
-
import * as engine from "./wasm/engine.ts";
|
|
40
|
-
|
|
41
|
-
export { host_supports_memory64 } from "./wasm/features.ts";
|
|
42
|
-
import { compile_perspective } from "./wasm/emscripten_api.ts";
|
|
43
|
-
import * as psp_websocket from "./websocket.ts";
|
|
44
|
-
import * as api from "./wasm/browser.ts";
|
|
45
|
-
import * as virtual_server from "./virtual_server.ts";
|
|
46
|
-
|
|
47
|
-
export {
|
|
48
|
-
GenericSQLVirtualServerModel,
|
|
49
|
-
VirtualDataSlice,
|
|
50
|
-
VirtualServer,
|
|
51
|
-
} from "../../dist/wasm/perspective-js.js";
|
|
52
|
-
|
|
53
|
-
import {
|
|
54
|
-
GenericSQLVirtualServerModel,
|
|
55
|
-
VirtualDataSlice,
|
|
56
|
-
VirtualServer,
|
|
57
|
-
} from "../../dist/wasm/perspective-js.js";
|
|
58
|
-
|
|
59
|
-
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
60
|
-
|
|
61
|
-
const { resolve } = createRequire(import.meta.url);
|
|
62
|
-
|
|
63
|
-
if (!globalThis.crypto) {
|
|
64
|
-
globalThis.crypto = webcrypto as Crypto;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const uncompressed_client_wasm = await fs
|
|
68
|
-
.readFile(path.join(__dirname, "../../dist/wasm/perspective-js.wasm"))
|
|
69
|
-
.then((buffer) => load_wasm_stage_0(buffer.buffer as ArrayBuffer));
|
|
70
|
-
|
|
71
|
-
await perspective_client.default({ module_or_path: uncompressed_client_wasm });
|
|
72
|
-
|
|
73
|
-
function make_node_disk_bridge({
|
|
74
|
-
heap,
|
|
75
|
-
toAddr,
|
|
76
|
-
readCString,
|
|
77
|
-
}: {
|
|
78
|
-
heap: () => Uint8Array;
|
|
79
|
-
toAddr: (p: number | bigint) => number;
|
|
80
|
-
readCString: (p: number | bigint) => string;
|
|
81
|
-
}) {
|
|
82
|
-
const root = path.join(os.tmpdir(), `perspective-${process.pid}`);
|
|
83
|
-
const resolve_path = (name: string) => {
|
|
84
|
-
const p = path.join(root, name);
|
|
85
|
-
if (!p.startsWith(root)) {
|
|
86
|
-
throw new Error(`refusing disk path outside root: ${name}`);
|
|
87
|
-
}
|
|
88
|
-
return p;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
let cleaned = false;
|
|
92
|
-
const cleanup = () => {
|
|
93
|
-
if (cleaned) return;
|
|
94
|
-
cleaned = true;
|
|
95
|
-
try {
|
|
96
|
-
rmSync(root, { recursive: true, force: true });
|
|
97
|
-
} catch (e) {
|
|
98
|
-
/* best effort */
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
process.on("exit", cleanup);
|
|
102
|
-
process.on("SIGINT", () => {
|
|
103
|
-
cleanup();
|
|
104
|
-
process.exit(130);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
// node:fs is synchronous — nothing to pre-open between safepoint phases.
|
|
109
|
-
async ensureOpen(_name: string) {},
|
|
110
|
-
store(
|
|
111
|
-
namePtr: number | bigint,
|
|
112
|
-
dataPtr: number | bigint,
|
|
113
|
-
len: number,
|
|
114
|
-
): number {
|
|
115
|
-
try {
|
|
116
|
-
const p = resolve_path(readCString(namePtr));
|
|
117
|
-
mkdirSync(path.dirname(p), { recursive: true });
|
|
118
|
-
const fd = openSync(p, "w");
|
|
119
|
-
try {
|
|
120
|
-
if (len > 0) {
|
|
121
|
-
const addr = toAddr(dataPtr);
|
|
122
|
-
const view = heap().subarray(addr, addr + len);
|
|
123
|
-
let off = 0;
|
|
124
|
-
while (off < len) {
|
|
125
|
-
off += writeSync(fd, view, off, len - off, off);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
} finally {
|
|
129
|
-
closeSync(fd);
|
|
130
|
-
}
|
|
131
|
-
return len;
|
|
132
|
-
} catch (e) {
|
|
133
|
-
console.error("node disk store failed", e);
|
|
134
|
-
return -1;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
load(
|
|
138
|
-
namePtr: number | bigint,
|
|
139
|
-
dataPtr: number | bigint,
|
|
140
|
-
len: number,
|
|
141
|
-
): number {
|
|
142
|
-
try {
|
|
143
|
-
if (len <= 0) return 0;
|
|
144
|
-
let fd: number;
|
|
145
|
-
try {
|
|
146
|
-
fd = openSync(resolve_path(readCString(namePtr)), "r");
|
|
147
|
-
} catch (e) {
|
|
148
|
-
return 0; // never-flushed file reads as zeros
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
const addr = toAddr(dataPtr);
|
|
152
|
-
const view = heap().subarray(addr, addr + len);
|
|
153
|
-
let off = 0;
|
|
154
|
-
let n: number;
|
|
155
|
-
while (
|
|
156
|
-
off < len &&
|
|
157
|
-
(n = readSync(fd, view, off, len - off, off)) > 0
|
|
158
|
-
) {
|
|
159
|
-
off += n;
|
|
160
|
-
}
|
|
161
|
-
return off;
|
|
162
|
-
} finally {
|
|
163
|
-
closeSync(fd);
|
|
164
|
-
}
|
|
165
|
-
} catch (e) {
|
|
166
|
-
return 0;
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
remove(namePtr: number | bigint) {
|
|
170
|
-
try {
|
|
171
|
-
unlinkSync(resolve_path(readCString(namePtr)));
|
|
172
|
-
} catch (e) {
|
|
173
|
-
/* already gone */
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async function compile_server_module(wasm_path: string) {
|
|
180
|
-
const buffer = await fs.readFile(wasm_path);
|
|
181
|
-
const bytes = await load_wasm_stage_0(buffer.buffer as ArrayBuffer);
|
|
182
|
-
return await compile_perspective(bytes.buffer as ArrayBuffer, {
|
|
183
|
-
make_disk_bridge: make_node_disk_bridge,
|
|
184
|
-
env: process.env,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async function load_server_module() {
|
|
189
|
-
if (host_supports_memory64()) {
|
|
190
|
-
let wasm_path;
|
|
191
|
-
try {
|
|
192
|
-
wasm_path = resolve(
|
|
193
|
-
"@perspective-dev/server/dist/wasm/perspective-server.memory64.wasm",
|
|
194
|
-
);
|
|
195
|
-
} catch (e) {
|
|
196
|
-
wasm_path = undefined;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (wasm_path !== undefined) {
|
|
200
|
-
try {
|
|
201
|
-
return await compile_server_module(wasm_path);
|
|
202
|
-
} catch (e) {
|
|
203
|
-
console.warn(
|
|
204
|
-
"Memory64 perspective server wasm failed to load, falling back to wasm32",
|
|
205
|
-
e,
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return await compile_server_module(
|
|
212
|
-
resolve("@perspective-dev/server/dist/wasm/perspective-server.wasm"),
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const SYNC_MODULE = await load_server_module();
|
|
217
|
-
|
|
218
|
-
let SYNC_CLIENT: perspective_client.Client;
|
|
219
|
-
|
|
220
|
-
const SYNC_SERVER = new engine.PerspectiveServer(SYNC_MODULE);
|
|
221
|
-
|
|
222
|
-
// const SYNC_SERVER = new engine.PerspectiveServer(SYNC_MODULE, {
|
|
223
|
-
// on_poll_request: () => SYNC_POLL_HANDLE.on_poll_request(),
|
|
224
|
-
// });
|
|
225
|
-
|
|
226
|
-
// const SYNC_POLL_HANDLE: engine.PerspectivePollThread =
|
|
227
|
-
// new engine.PerspectivePollThread(SYNC_SERVER);
|
|
228
|
-
|
|
229
|
-
const SYNC_SESSION = SYNC_SERVER.make_session(
|
|
230
|
-
async (resp) => await SYNC_CLIENT.handle_response(resp),
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
SYNC_CLIENT = new perspective_client.Client(async (req: Uint8Array) => {
|
|
234
|
-
await SYNC_SESSION.handle_request(req);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
export class PerspectiveServer extends engine.PerspectiveServer {
|
|
238
|
-
constructor(options?: engine.PerspectiveServerOptions) {
|
|
239
|
-
super(SYNC_MODULE, options);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export const make_session = async (
|
|
244
|
-
send_response: (buffer: Uint8Array) => Promise<void>,
|
|
245
|
-
) => SYNC_SERVER.make_session(send_response);
|
|
246
|
-
|
|
247
|
-
// Helper function to create client emitter/receiver pairs
|
|
248
|
-
export function make_client(
|
|
249
|
-
send_request: (buffer: Uint8Array) => Promise<void>,
|
|
250
|
-
close?: Function,
|
|
251
|
-
) {
|
|
252
|
-
return new perspective_client.Client(send_request, close);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const CONTENT_TYPES: Record<string, string> = {
|
|
256
|
-
".js": "text/javascript",
|
|
257
|
-
".mjs": "text/javascript",
|
|
258
|
-
".css": "text/css; charset=utf-8",
|
|
259
|
-
".json": "application/json",
|
|
260
|
-
".arrow": "arraybuffer",
|
|
261
|
-
".feather": "arraybuffer",
|
|
262
|
-
".wasm": "application/wasm",
|
|
263
|
-
".svg": "image/svg+xml",
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Host a Perspective server that hosts data, code files, etc.
|
|
268
|
-
* Strip version numbers from the URL so we can handle CDN-like requests
|
|
269
|
-
* of the form @[^~]major.minor.patch when testing local versions of
|
|
270
|
-
* Perspective against Voila.
|
|
271
|
-
*/
|
|
272
|
-
export async function cwd_static_file_handler(
|
|
273
|
-
request: http.IncomingMessage,
|
|
274
|
-
response: http.ServerResponse<http.IncomingMessage>,
|
|
275
|
-
assets = ["./"],
|
|
276
|
-
{ debug = false } = {},
|
|
277
|
-
) {
|
|
278
|
-
let url =
|
|
279
|
-
request.url
|
|
280
|
-
?.split(/[\?\#]/)[0]
|
|
281
|
-
.replace(/@[\^~]?\d+.[\d\*]*.[\d\*]*/, "") || "/";
|
|
282
|
-
|
|
283
|
-
if (url === "/") {
|
|
284
|
-
url = "/index.html";
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
let extname = path.extname(url);
|
|
288
|
-
let contentType = CONTENT_TYPES[extname] || "text/html";
|
|
289
|
-
try {
|
|
290
|
-
for (const root of assets) {
|
|
291
|
-
let filePath = root + url;
|
|
292
|
-
try {
|
|
293
|
-
let content = await fs.readFile(filePath);
|
|
294
|
-
if (typeof content !== "undefined") {
|
|
295
|
-
if (debug) {
|
|
296
|
-
console.log(`200 ${url}`);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
response.writeHead(200, {
|
|
300
|
-
"Content-Type": contentType,
|
|
301
|
-
"Access-Control-Allow-Origin": "*",
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
if (extname === ".arrow" || extname === ".feather") {
|
|
305
|
-
response.end(content, "utf8");
|
|
306
|
-
} else {
|
|
307
|
-
response.end(content, "utf8");
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
} catch (e) {}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (debug) {
|
|
316
|
-
console.error(`404 ${url}`);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
response.writeHead(404);
|
|
320
|
-
response.end("", "utf-8");
|
|
321
|
-
} catch (error) {
|
|
322
|
-
if (debug) {
|
|
323
|
-
console.error(`500 ${url} ${error}`);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
response.writeHead(500);
|
|
327
|
-
response.end("", "utf-8");
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function buffer_to_arraybuffer(
|
|
332
|
-
buffer: string | Buffer | ArrayBuffer | Buffer[] | Uint8Array,
|
|
333
|
-
): Uint8Array {
|
|
334
|
-
if (typeof buffer === "string") {
|
|
335
|
-
throw new Error("Unknown websocket message: " + buffer);
|
|
336
|
-
} else if (buffer instanceof ArrayBuffer) {
|
|
337
|
-
return new Uint8Array(buffer);
|
|
338
|
-
} else if (buffer instanceof Array) {
|
|
339
|
-
throw new Error("Unknown websocket message: " + buffer);
|
|
340
|
-
} else {
|
|
341
|
-
return new Uint8Array(
|
|
342
|
-
buffer.buffer.slice(
|
|
343
|
-
buffer.byteOffset,
|
|
344
|
-
buffer.byteOffset + buffer.length,
|
|
345
|
-
),
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* A simple Node `http`-based WebSocket adapter that exposes a
|
|
352
|
-
* `PerspectiveServer` over the wire.
|
|
353
|
-
*
|
|
354
|
-
* @remarks
|
|
355
|
-
*
|
|
356
|
-
* **Security.** `WebSocketServer` is a reference integration with no
|
|
357
|
-
* authentication, authorization, origin enforcement, or rate limiting, and
|
|
358
|
-
* is not safe to expose to untrusted networks — see
|
|
359
|
-
* [`SECURITY.md`](https://github.com/perspective-dev/perspective/blob/master/SECURITY.md)
|
|
360
|
-
* for the full threat model.
|
|
361
|
-
*/
|
|
362
|
-
export class WebSocketServer {
|
|
363
|
-
_server: http.Server | any; // stoppable has no type ...
|
|
364
|
-
_wss: HttpWebSocketServer;
|
|
365
|
-
constructor({ port = 8080, assets = ["./"], server = undefined } = {}) {
|
|
366
|
-
const perspective_server =
|
|
367
|
-
typeof server === "undefined" ? SYNC_SERVER : server;
|
|
368
|
-
|
|
369
|
-
port = typeof port === "undefined" ? 8080 : port;
|
|
370
|
-
this._server = stoppable(
|
|
371
|
-
http.createServer((x, y) => cwd_static_file_handler(x, y, assets)),
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
this._wss = new HttpWebSocketServer({
|
|
375
|
-
noServer: true,
|
|
376
|
-
perMessageDeflate: true,
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
this._wss.on("connection", (ws) => {
|
|
380
|
-
console.log("... Connecting websocket");
|
|
381
|
-
const session = perspective_server.make_session(
|
|
382
|
-
async (proto: Uint8Array) => {
|
|
383
|
-
ws.send(buffer_to_arraybuffer(proto));
|
|
384
|
-
},
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
ws.on("message", (proto) => {
|
|
388
|
-
session.handle_request(buffer_to_arraybuffer(proto));
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
ws.on("close", () => {
|
|
392
|
-
session.close();
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
this._server.on(
|
|
397
|
-
"upgrade",
|
|
398
|
-
(
|
|
399
|
-
request: http.IncomingMessage,
|
|
400
|
-
socket: net.Socket,
|
|
401
|
-
head: Buffer,
|
|
402
|
-
) => {
|
|
403
|
-
console.log("200 Websocket upgrade");
|
|
404
|
-
this._wss.handleUpgrade(
|
|
405
|
-
request,
|
|
406
|
-
socket as net.Socket,
|
|
407
|
-
head,
|
|
408
|
-
(sock) => this._wss.emit("connection", sock, request),
|
|
409
|
-
);
|
|
410
|
-
},
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
this._server.listen(port, () => {
|
|
414
|
-
console.log(`Listening on ${this._server.address().port}`);
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
async close() {
|
|
419
|
-
await new Promise((x) => this._server.stop(x));
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
export function get_hosted_table_names() {
|
|
424
|
-
return SYNC_CLIENT.get_hosted_table_names();
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export function on_hosted_tables_update(cb: () => void) {
|
|
428
|
-
return SYNC_CLIENT.on_hosted_tables_update(cb);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export function remove_hosted_tables_update(id: number) {
|
|
432
|
-
return SYNC_CLIENT.remove_hosted_tables_update(id);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
export function system_info() {
|
|
436
|
-
return SYNC_CLIENT.system_info();
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
export function on_error(callback: Function) {
|
|
440
|
-
return SYNC_CLIENT.on_error(callback);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Create a read-only table from a JOIN of two source tables.
|
|
445
|
-
* @param left - The left source table (a Table instance or a table name string).
|
|
446
|
-
* @param right - The right source table (a Table instance or a table name string).
|
|
447
|
-
* @param on
|
|
448
|
-
* @param options - Optional join configuration: { join_type?: "inner"|"left"|"outer", name?: string }
|
|
449
|
-
* @returns
|
|
450
|
-
*/
|
|
451
|
-
export function join(
|
|
452
|
-
left: perspective_client.Table | string,
|
|
453
|
-
right: perspective_client.Table | string,
|
|
454
|
-
on: string,
|
|
455
|
-
options?: perspective_client.JoinOptions,
|
|
456
|
-
) {
|
|
457
|
-
return SYNC_CLIENT.join(left as any, right as any, on, options);
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Create a table from the global Perspective instance.
|
|
462
|
-
* @param init_data
|
|
463
|
-
* @param options
|
|
464
|
-
* @returns
|
|
465
|
-
*/
|
|
466
|
-
export function table(
|
|
467
|
-
init_data:
|
|
468
|
-
| string
|
|
469
|
-
| ArrayBuffer
|
|
470
|
-
| Record<string, any>
|
|
471
|
-
| Record<string, unknown>[],
|
|
472
|
-
options?: perspective_client.TableInitOptions,
|
|
473
|
-
) {
|
|
474
|
-
return SYNC_CLIENT.table(init_data, options);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Create a new client connected via WebSocket to a server implemnting the
|
|
479
|
-
* Perspective Protocol.
|
|
480
|
-
* @param module
|
|
481
|
-
* @param url
|
|
482
|
-
* @returns
|
|
483
|
-
*/
|
|
484
|
-
export async function websocket(
|
|
485
|
-
url: string,
|
|
486
|
-
): Promise<perspective_client.Client> {
|
|
487
|
-
return await psp_websocket.websocket(
|
|
488
|
-
WebSocket as unknown as typeof window.WebSocket,
|
|
489
|
-
perspective_client.Client,
|
|
490
|
-
url,
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
export async function worker(worker: Promise<MessagePort>) {
|
|
495
|
-
const port = await worker;
|
|
496
|
-
const client = new perspective_client.Client(
|
|
497
|
-
async (proto: Uint8Array) => {
|
|
498
|
-
const f = proto.slice().buffer;
|
|
499
|
-
port.postMessage(f, { transfer: [f] });
|
|
500
|
-
},
|
|
501
|
-
async () => {
|
|
502
|
-
console.debug("Closing WebWorker");
|
|
503
|
-
port.close();
|
|
504
|
-
},
|
|
505
|
-
);
|
|
506
|
-
|
|
507
|
-
const { promise, resolve, reject } = Promise.withResolvers();
|
|
508
|
-
port.onmessage = function listener(resp) {
|
|
509
|
-
port.onmessage = null;
|
|
510
|
-
resolve(null);
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
port.onmessageerror = function (...args) {
|
|
514
|
-
port.onmessage = null;
|
|
515
|
-
console.error(...args);
|
|
516
|
-
reject(args);
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
port.postMessage({ cmd: "init", args: [] });
|
|
520
|
-
await promise;
|
|
521
|
-
port.addEventListener("message", (json: MessageEvent<Uint8Array>) => {
|
|
522
|
-
client.handle_response(json.data);
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
console.log(client);
|
|
526
|
-
return client;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
export function createMessageHandler(
|
|
530
|
-
handler: virtual_server.VirtualServerHandler,
|
|
531
|
-
) {
|
|
532
|
-
return virtual_server.createMessageHandler(perspective_client, handler);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* The initialized WASM module. Use this when you need to pass the module
|
|
537
|
-
* to components that require it, such as `DuckDBHandler`.
|
|
538
|
-
*/
|
|
539
|
-
export { perspective_client as wasmModule };
|
|
540
|
-
|
|
541
|
-
export default {
|
|
542
|
-
table,
|
|
543
|
-
join,
|
|
544
|
-
websocket,
|
|
545
|
-
worker,
|
|
546
|
-
host_supports_memory64,
|
|
547
|
-
get_hosted_table_names,
|
|
548
|
-
on_hosted_tables_update,
|
|
549
|
-
remove_hosted_tables_update,
|
|
550
|
-
on_error,
|
|
551
|
-
system_info,
|
|
552
|
-
WebSocketServer,
|
|
553
|
-
GenericSQLVirtualServerModel,
|
|
554
|
-
VirtualDataSlice,
|
|
555
|
-
VirtualServer,
|
|
556
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
-
import type { ColumnType } from "./ColumnType.js";
|
|
3
|
-
import type { ListFlatten } from "./ListFlatten.js";
|
|
4
|
-
import type { TableReadFormat } from "./TableReadFormat.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Options which impact the behavior of [`Client::table`], as well as
|
|
8
|
-
* subsequent calls to [`Table::update`].
|
|
9
|
-
*/
|
|
10
|
-
export type TableInitOptions = { name?: string, format?: TableReadFormat,
|
|
11
|
-
/**
|
|
12
|
-
* This [`Table`] should use the column named by the `index` parameter as
|
|
13
|
-
* the `index`, which causes [`Table::update`] and [`Client::table`] input
|
|
14
|
-
* to either insert or update existing rows based on `index` column
|
|
15
|
-
* value equality.
|
|
16
|
-
*/
|
|
17
|
-
index?: string,
|
|
18
|
-
/**
|
|
19
|
-
* This [`Table`] should be limited to `limit` rows, after which the
|
|
20
|
-
* _earliest_ rows will be overwritten (where _earliest_ is defined as
|
|
21
|
-
* relative to insertion order).
|
|
22
|
-
*/
|
|
23
|
-
limit?: number,
|
|
24
|
-
/**
|
|
25
|
-
* Back this [`Table`]'s canonical data with the on-disk storage backend
|
|
26
|
-
* instead of memory. On native targets this is a memory-mapped file; on
|
|
27
|
-
* WASM it is OPFS (Worker only). Defaults to in-memory.
|
|
28
|
-
*/
|
|
29
|
-
page_to_disk?: boolean,
|
|
30
|
-
/**
|
|
31
|
-
* How Arrow `LIST` and JSON `Array` columns are ingested. `zip` (the
|
|
32
|
-
* default) and `cartesian` expand a row into one row per list element,
|
|
33
|
-
* and are incompatible with `index`, as the rows of an expansion
|
|
34
|
-
* repeat their index. `stringify` encodes each list as a JSON array in
|
|
35
|
-
* a single string column instead.
|
|
36
|
-
*/
|
|
37
|
-
list_flatten?: ListFlatten,
|
|
38
|
-
/**
|
|
39
|
-
* The columns of a [`Table`] made from a [`View`], in place of the ones
|
|
40
|
-
* inferred from it.
|
|
41
|
-
*/
|
|
42
|
-
schema?: { [key in string]?: ColumnType }, };
|
package/src/ts/virtual_server.ts
DELETED
|
@@ -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
|
-
import type * as perspective from "../../dist/wasm/perspective-js.js";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* VirtualServer API for implementing custom data sources in JavaScript/WASM.
|
|
17
|
-
*
|
|
18
|
-
* The VirtualServer pattern allows you to create custom data sources that
|
|
19
|
-
* integrate with Perspective's protocol. This is useful for:
|
|
20
|
-
* - Connecting to external databases (DuckDB, PostgreSQL, etc.)
|
|
21
|
-
* - Streaming data from APIs or message queues
|
|
22
|
-
* - Implementing custom aggregation or transformation logic
|
|
23
|
-
* - Creating data adapters without copying data into Perspective tables
|
|
24
|
-
*
|
|
25
|
-
* The `VirtualServerHandler` interface and `Features` struct are declared
|
|
26
|
-
* in Rust alongside the bridge that invokes them (`perspective-js`'s
|
|
27
|
-
* `virtual_server.rs` and `perspective-client`'s `features.rs`
|
|
28
|
-
* respectively) and re-exported here. `ServerFeatures` is a legacy alias
|
|
29
|
-
* for `Features`.
|
|
30
|
-
*
|
|
31
|
-
* @module virtual_server
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
// `Features` must re-export from the wasm `.d.ts` (NOT "./ts-rs/Features.ts")
|
|
35
|
-
// - `perspective.browser.ts` star-exports both this module and the wasm
|
|
36
|
-
// `.d.ts`, and star exports of the same name only merge when they resolve to
|
|
37
|
-
// the same declaration.
|
|
38
|
-
export type {
|
|
39
|
-
VirtualServerHandler,
|
|
40
|
-
VirtualHostedTable,
|
|
41
|
-
Features,
|
|
42
|
-
Features as ServerFeatures,
|
|
43
|
-
} from "../../dist/wasm/perspective-js.js";
|
|
44
|
-
|
|
45
|
-
export function createMessageHandler(
|
|
46
|
-
mod: typeof perspective,
|
|
47
|
-
handler: perspective.VirtualServerHandler,
|
|
48
|
-
) {
|
|
49
|
-
let virtualServer: perspective.VirtualServer;
|
|
50
|
-
async function postMessage(port: MessagePort, msg: MessageEvent) {
|
|
51
|
-
if (msg.data.cmd === "init") {
|
|
52
|
-
try {
|
|
53
|
-
virtualServer = new mod.VirtualServer(handler);
|
|
54
|
-
if (msg.data.id !== undefined) {
|
|
55
|
-
port.postMessage({ id: msg.data.id });
|
|
56
|
-
} else {
|
|
57
|
-
port.postMessage(null);
|
|
58
|
-
}
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error("Error initializing worker:", error);
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
try {
|
|
65
|
-
const requestBytes = new Uint8Array(msg.data);
|
|
66
|
-
const responseBytes =
|
|
67
|
-
await virtualServer.handleRequest(requestBytes);
|
|
68
|
-
const buffer = responseBytes.slice().buffer;
|
|
69
|
-
port.postMessage(buffer, { transfer: [buffer] });
|
|
70
|
-
} catch (error) {
|
|
71
|
-
console.error("Error handling request in worker:", error);
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const channel = new MessageChannel();
|
|
78
|
-
channel.port1.onmessage = (message) => {
|
|
79
|
-
postMessage(channel.port1, message);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
return channel.port2;
|
|
83
|
-
}
|