@perspective-dev/client 4.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/LICENSE.md +193 -0
- package/README.md +3 -0
- package/dist/cdn/perspective-server.worker.js +2 -0
- package/dist/cdn/perspective-server.worker.js.map +7 -0
- package/dist/cdn/perspective.js +3 -0
- package/dist/cdn/perspective.js.map +7 -0
- package/dist/esm/perspective-server.worker.d.ts +1 -0
- package/dist/esm/perspective.browser.d.ts +14 -0
- package/dist/esm/perspective.inline.js +3 -0
- package/dist/esm/perspective.inline.js.map +7 -0
- package/dist/esm/perspective.js +3 -0
- package/dist/esm/perspective.js.map +7 -0
- package/dist/esm/perspective.node.d.ts +60 -0
- package/dist/esm/perspective.node.js +2431 -0
- package/dist/esm/perspective.node.js.map +7 -0
- package/dist/esm/ts-rs/Aggregate.d.ts +1 -0
- package/dist/esm/ts-rs/ColumnWindow.d.ts +4 -0
- package/dist/esm/ts-rs/DeleteOptions.d.ts +6 -0
- package/dist/esm/ts-rs/Expressions.d.ts +3 -0
- package/dist/esm/ts-rs/Filter.d.ts +2 -0
- package/dist/esm/ts-rs/FilterReducer.d.ts +1 -0
- package/dist/esm/ts-rs/FilterTerm.d.ts +2 -0
- package/dist/esm/ts-rs/OnUpdateMode.d.ts +9 -0
- package/dist/esm/ts-rs/OnUpdateOptions.d.ts +7 -0
- package/dist/esm/ts-rs/Scalar.d.ts +5 -0
- package/dist/esm/ts-rs/Sort.d.ts +2 -0
- package/dist/esm/ts-rs/SortDir.d.ts +1 -0
- package/dist/esm/ts-rs/SystemInfo.d.ts +40 -0
- package/dist/esm/ts-rs/TableInitOptions.d.ts +22 -0
- package/dist/esm/ts-rs/TableReadFormat.d.ts +7 -0
- package/dist/esm/ts-rs/UpdateOptions.d.ts +8 -0
- package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +90 -0
- package/dist/esm/ts-rs/ViewOnUpdateResp.d.ts +4 -0
- package/dist/esm/ts-rs/ViewWindow.d.ts +23 -0
- package/dist/esm/wasm/browser.d.ts +21 -0
- package/dist/esm/wasm/decompress.d.ts +1 -0
- package/dist/esm/wasm/emscripten_api.d.ts +5 -0
- package/dist/esm/wasm/engine.d.ts +40 -0
- package/dist/esm/wasm/perspective-server.poly.d.ts +1 -0
- package/dist/esm/websocket.d.ts +4 -0
- package/dist/wasm/perspective-js.d.ts +712 -0
- package/dist/wasm/perspective-js.js +1934 -0
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +75 -0
- package/package.json +68 -0
- package/src/rust/client.rs +483 -0
- package/src/rust/lib.rs +70 -0
- package/src/rust/table.rs +364 -0
- package/src/rust/table_data.rs +159 -0
- package/src/rust/utils/browser.rs +39 -0
- package/src/rust/utils/console_logger.rs +236 -0
- package/src/rust/utils/errors.rs +288 -0
- package/src/rust/utils/futures.rs +174 -0
- package/src/rust/utils/json.rs +252 -0
- package/src/rust/utils/local_poll_loop.rs +63 -0
- package/src/rust/utils/mod.rs +32 -0
- package/src/rust/utils/serde.rs +46 -0
- package/src/rust/utils/trace_allocator.rs +98 -0
- package/src/rust/view.rs +355 -0
- package/src/ts/perspective-server.worker.ts +54 -0
- package/src/ts/perspective.browser.ts +132 -0
- package/src/ts/perspective.cdn.ts +22 -0
- package/src/ts/perspective.inline.ts +27 -0
- package/src/ts/perspective.node.ts +315 -0
- package/src/ts/ts-rs/Aggregate.ts +3 -0
- package/src/ts/ts-rs/ColumnWindow.ts +3 -0
- package/src/ts/ts-rs/DeleteOptions.ts +6 -0
- package/src/ts/ts-rs/Expressions.ts +3 -0
- package/src/ts/ts-rs/Filter.ts +4 -0
- package/src/ts/ts-rs/FilterReducer.ts +3 -0
- package/src/ts/ts-rs/FilterTerm.ts +4 -0
- package/src/ts/ts-rs/OnUpdateData.ts +8 -0
- package/src/ts/ts-rs/OnUpdateMode.ts +11 -0
- package/src/ts/ts-rs/OnUpdateOptions.ts +7 -0
- package/src/ts/ts-rs/Scalar.ts +7 -0
- package/src/ts/ts-rs/Sort.ts +4 -0
- package/src/ts/ts-rs/SortDir.ts +3 -0
- package/src/ts/ts-rs/SystemInfo.ts +41 -0
- package/src/ts/ts-rs/TableInitOptions.ts +21 -0
- package/src/ts/ts-rs/TableReadFormat.ts +9 -0
- package/src/ts/ts-rs/UpdateOptions.ts +7 -0
- package/src/ts/ts-rs/ViewConfigUpdate.ts +87 -0
- package/src/ts/ts-rs/ViewOnUpdateResp.ts +3 -0
- package/src/ts/ts-rs/ViewWindow.ts +17 -0
- package/src/ts/wasm/browser.ts +123 -0
- package/src/ts/wasm/decompress.ts +64 -0
- package/src/ts/wasm/emscripten_api.ts +63 -0
- package/src/ts/wasm/engine.ts +271 -0
- package/src/ts/wasm/perspective-server.poly.ts +244 -0
- package/src/ts/websocket.ts +95 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,315 @@
|
|
|
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
|
+
|
|
15
|
+
import WebSocket, { WebSocketServer as HttpWebSocketServer } from "ws";
|
|
16
|
+
import stoppable from "stoppable";
|
|
17
|
+
import { promises as fs } from "node:fs";
|
|
18
|
+
import http from "node:http";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import { webcrypto } from "node:crypto";
|
|
21
|
+
import type * as net from "node:net";
|
|
22
|
+
import * as url from "node:url";
|
|
23
|
+
import { createRequire } from "node:module";
|
|
24
|
+
|
|
25
|
+
import * as perspective_client from "../../dist/wasm/perspective-js.js";
|
|
26
|
+
import { load_wasm_stage_0 } from "./wasm/decompress.js";
|
|
27
|
+
import * as engine from "./wasm/engine.ts";
|
|
28
|
+
import { compile_perspective } from "./wasm/emscripten_api.ts";
|
|
29
|
+
import * as psp_websocket from "./websocket.ts";
|
|
30
|
+
|
|
31
|
+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
32
|
+
|
|
33
|
+
const { resolve } = createRequire(import.meta.url);
|
|
34
|
+
|
|
35
|
+
if (!globalThis.crypto) {
|
|
36
|
+
globalThis.crypto = webcrypto as Crypto;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const uncompressed_client_wasm = await fs
|
|
40
|
+
.readFile(path.join(__dirname, "../../dist/wasm/perspective-js.wasm"))
|
|
41
|
+
.then((buffer) => load_wasm_stage_0(buffer.buffer as ArrayBuffer));
|
|
42
|
+
|
|
43
|
+
await perspective_client.default({ module_or_path: uncompressed_client_wasm });
|
|
44
|
+
const SYNC_MODULE = await fs
|
|
45
|
+
.readFile(
|
|
46
|
+
resolve("@perspective-dev/server/dist/wasm/perspective-server.wasm"),
|
|
47
|
+
)
|
|
48
|
+
.then((buffer) => load_wasm_stage_0(buffer.buffer as ArrayBuffer))
|
|
49
|
+
.then((buffer) => compile_perspective(buffer.buffer as ArrayBuffer));
|
|
50
|
+
|
|
51
|
+
let SYNC_CLIENT: perspective_client.Client;
|
|
52
|
+
|
|
53
|
+
const SYNC_SERVER = new engine.PerspectiveServer(SYNC_MODULE);
|
|
54
|
+
|
|
55
|
+
// const SYNC_SERVER = new engine.PerspectiveServer(SYNC_MODULE, {
|
|
56
|
+
// on_poll_request: () => SYNC_POLL_HANDLE.on_poll_request(),
|
|
57
|
+
// });
|
|
58
|
+
|
|
59
|
+
// const SYNC_POLL_HANDLE: engine.PerspectivePollThread =
|
|
60
|
+
// new engine.PerspectivePollThread(SYNC_SERVER);
|
|
61
|
+
|
|
62
|
+
const SYNC_SESSION = SYNC_SERVER.make_session(
|
|
63
|
+
async (resp) => await SYNC_CLIENT.handle_response(resp),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
SYNC_CLIENT = new perspective_client.Client(async (req: Uint8Array) => {
|
|
67
|
+
await SYNC_SESSION.handle_request(req);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export class PerspectiveServer extends engine.PerspectiveServer {
|
|
71
|
+
constructor(options?: engine.PerspectiveServerOptions) {
|
|
72
|
+
super(SYNC_MODULE, options);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const make_session = async (
|
|
77
|
+
send_response: (buffer: Uint8Array) => Promise<void>,
|
|
78
|
+
) => SYNC_SERVER.make_session(send_response);
|
|
79
|
+
|
|
80
|
+
// Helper function to create client emitter/receiver pairs
|
|
81
|
+
export function make_client(
|
|
82
|
+
send_request: (buffer: Uint8Array) => Promise<void>,
|
|
83
|
+
close?: Function,
|
|
84
|
+
) {
|
|
85
|
+
return new perspective_client.Client(send_request, close);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const CONTENT_TYPES: Record<string, string> = {
|
|
89
|
+
".js": "text/javascript",
|
|
90
|
+
".mjs": "text/javascript",
|
|
91
|
+
".css": "text/css; charset=utf-8",
|
|
92
|
+
".json": "application/json",
|
|
93
|
+
".arrow": "arraybuffer",
|
|
94
|
+
".feather": "arraybuffer",
|
|
95
|
+
".wasm": "application/wasm",
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Host a Perspective server that hosts data, code files, etc.
|
|
100
|
+
* Strip version numbers from the URL so we can handle CDN-like requests
|
|
101
|
+
* of the form @[^~]major.minor.patch when testing local versions of
|
|
102
|
+
* Perspective against Voila.
|
|
103
|
+
*/
|
|
104
|
+
export async function cwd_static_file_handler(
|
|
105
|
+
request: http.IncomingMessage,
|
|
106
|
+
response: http.ServerResponse<http.IncomingMessage>,
|
|
107
|
+
assets = ["./"],
|
|
108
|
+
{ debug = true } = {},
|
|
109
|
+
) {
|
|
110
|
+
let url =
|
|
111
|
+
request.url
|
|
112
|
+
?.split(/[\?\#]/)[0]
|
|
113
|
+
.replace(/@[\^~]?\d+.[\d\*]*.[\d\*]*/, "") || "/";
|
|
114
|
+
|
|
115
|
+
if (url === "/") {
|
|
116
|
+
url = "/index.html";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let extname = path.extname(url);
|
|
120
|
+
let contentType = CONTENT_TYPES[extname] || "text/html";
|
|
121
|
+
try {
|
|
122
|
+
for (const root of assets) {
|
|
123
|
+
let filePath = root + url;
|
|
124
|
+
try {
|
|
125
|
+
let content = await fs.readFile(filePath);
|
|
126
|
+
if (typeof content !== "undefined") {
|
|
127
|
+
if (debug) {
|
|
128
|
+
console.log(`200 ${url}`);
|
|
129
|
+
}
|
|
130
|
+
response.writeHead(200, {
|
|
131
|
+
"Content-Type": contentType,
|
|
132
|
+
"Access-Control-Allow-Origin": "*",
|
|
133
|
+
});
|
|
134
|
+
if (extname === ".arrow" || extname === ".feather") {
|
|
135
|
+
response.end(content, "utf-8");
|
|
136
|
+
} else {
|
|
137
|
+
response.end(content);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
} catch (e) {}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (debug) {
|
|
146
|
+
console.error(`404 ${url}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
response.writeHead(404);
|
|
150
|
+
response.end("", "utf-8");
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (debug) {
|
|
153
|
+
console.error(`500 ${url} ${error}`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
response.writeHead(500);
|
|
157
|
+
response.end("", "utf-8");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function buffer_to_arraybuffer(
|
|
162
|
+
buffer: string | Buffer | ArrayBuffer | Buffer[] | Uint8Array,
|
|
163
|
+
): Uint8Array {
|
|
164
|
+
if (typeof buffer === "string") {
|
|
165
|
+
throw new Error("Unknown websocket message: " + buffer);
|
|
166
|
+
} else if (buffer instanceof ArrayBuffer) {
|
|
167
|
+
return new Uint8Array(buffer);
|
|
168
|
+
} else if (buffer instanceof Array) {
|
|
169
|
+
throw new Error("Unknown websocket message: " + buffer);
|
|
170
|
+
} else {
|
|
171
|
+
return new Uint8Array(
|
|
172
|
+
buffer.buffer.slice(
|
|
173
|
+
buffer.byteOffset,
|
|
174
|
+
buffer.byteOffset + buffer.length,
|
|
175
|
+
),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function invert_promise<T>(): [(t: T) => void, Promise<T>, (t: any) => void] {
|
|
181
|
+
let sender: ((t: T) => void) | undefined = undefined,
|
|
182
|
+
reject = undefined;
|
|
183
|
+
let receiver: Promise<T> = new Promise((x, u) => {
|
|
184
|
+
sender = x;
|
|
185
|
+
reject = u;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
return [sender!, receiver, reject!];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export class WebSocketServer {
|
|
192
|
+
_server: http.Server | any; // stoppable has no type ...
|
|
193
|
+
_wss: HttpWebSocketServer;
|
|
194
|
+
constructor({ port = 8080, assets = ["./"], server = undefined } = {}) {
|
|
195
|
+
const perspective_server =
|
|
196
|
+
typeof server === "undefined" ? SYNC_SERVER : server;
|
|
197
|
+
|
|
198
|
+
port = typeof port === "undefined" ? 8080 : port;
|
|
199
|
+
this._server = stoppable(
|
|
200
|
+
http.createServer((x, y) => cwd_static_file_handler(x, y, assets)),
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
this._wss = new HttpWebSocketServer({
|
|
204
|
+
noServer: true,
|
|
205
|
+
perMessageDeflate: true,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
this._wss.on("connection", (ws) => {
|
|
209
|
+
console.log("... Connecting websocket");
|
|
210
|
+
const session = perspective_server.make_session(
|
|
211
|
+
async (proto: Uint8Array) => {
|
|
212
|
+
ws.send(buffer_to_arraybuffer(proto));
|
|
213
|
+
},
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
ws.on("message", (proto) => {
|
|
217
|
+
session.handle_request(buffer_to_arraybuffer(proto));
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
ws.on("close", () => {
|
|
221
|
+
session.close();
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
this._server.on(
|
|
226
|
+
"upgrade",
|
|
227
|
+
(
|
|
228
|
+
request: http.IncomingMessage,
|
|
229
|
+
socket: net.Socket,
|
|
230
|
+
head: Buffer,
|
|
231
|
+
) => {
|
|
232
|
+
console.log("200 Websocket upgrade");
|
|
233
|
+
this._wss.handleUpgrade(
|
|
234
|
+
request,
|
|
235
|
+
socket as net.Socket,
|
|
236
|
+
head,
|
|
237
|
+
(sock) => this._wss.emit("connection", sock, request),
|
|
238
|
+
);
|
|
239
|
+
},
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
this._server.listen(port, () => {
|
|
243
|
+
console.log(`Listening on ${this._server.address().port}`);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async close() {
|
|
248
|
+
await new Promise((x) => this._server.stop(x));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function get_hosted_table_names() {
|
|
253
|
+
return SYNC_CLIENT.get_hosted_table_names();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function on_hosted_tables_update(cb: () => void) {
|
|
257
|
+
return SYNC_CLIENT.on_hosted_tables_update(cb);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function remove_hosted_tables_update(id: number) {
|
|
261
|
+
return SYNC_CLIENT.remove_hosted_tables_update(id);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function system_info() {
|
|
265
|
+
return SYNC_CLIENT.system_info();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function on_error(callback: Function) {
|
|
269
|
+
return SYNC_CLIENT.on_error(callback);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Create a table from the global Perspective instance.
|
|
274
|
+
* @param init_data
|
|
275
|
+
* @param options
|
|
276
|
+
* @returns
|
|
277
|
+
*/
|
|
278
|
+
export function table(
|
|
279
|
+
init_data:
|
|
280
|
+
| string
|
|
281
|
+
| ArrayBuffer
|
|
282
|
+
| Record<string, any>
|
|
283
|
+
| Record<string, unknown>[],
|
|
284
|
+
options?: perspective_client.TableInitOptions,
|
|
285
|
+
) {
|
|
286
|
+
return SYNC_CLIENT.table(init_data, options);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Create a new client connected via WebSocket to a server implemnting the
|
|
291
|
+
* Perspective Protocol.
|
|
292
|
+
* @param module
|
|
293
|
+
* @param url
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
export async function websocket(
|
|
297
|
+
url: string,
|
|
298
|
+
): Promise<perspective_client.Client> {
|
|
299
|
+
return await psp_websocket.websocket(
|
|
300
|
+
WebSocket as unknown as typeof window.WebSocket,
|
|
301
|
+
perspective_client.Client,
|
|
302
|
+
url,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export default {
|
|
307
|
+
table,
|
|
308
|
+
websocket,
|
|
309
|
+
get_hosted_table_names,
|
|
310
|
+
on_hosted_tables_update,
|
|
311
|
+
remove_hosted_tables_update,
|
|
312
|
+
on_error,
|
|
313
|
+
system_info,
|
|
314
|
+
WebSocketServer,
|
|
315
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { ViewOnUpdateResp } from "./ViewOnUpdateResp.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Rows updated and port ID corresponding to an update batch, provided to the
|
|
6
|
+
* callback argument to [`View::on_update`] with the "rows" mode.
|
|
7
|
+
*/
|
|
8
|
+
export type OnUpdateData = ViewOnUpdateResp;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The update mode for [`View::on_update`].
|
|
5
|
+
*
|
|
6
|
+
* `Row` mode calculates and provides the update batch new rows/columns as an
|
|
7
|
+
* Apache Arrow to the callback provided to [`View::on_update`]. This allows
|
|
8
|
+
* incremental updates if your callbakc can read this format, but should be
|
|
9
|
+
* disabled otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export type OnUpdateMode = "row";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { OnUpdateMode } from "./OnUpdateMode.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for [`View::on_update`].
|
|
6
|
+
*/
|
|
7
|
+
export type OnUpdateOptions = { mode: OnUpdateMode | null, };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Metadata about the engine runtime (such as total heap utilization).
|
|
5
|
+
*/
|
|
6
|
+
export type SystemInfo<T = bigint> = {
|
|
7
|
+
/**
|
|
8
|
+
* Total available bytes for allocation on the [`Server`].
|
|
9
|
+
*/
|
|
10
|
+
heap_size: T,
|
|
11
|
+
/**
|
|
12
|
+
* Bytes allocated for use on the [`Server`].
|
|
13
|
+
*/
|
|
14
|
+
used_size: T,
|
|
15
|
+
/**
|
|
16
|
+
* Wall-clock time spent processing requests on the [`Server`], in
|
|
17
|
+
* milliseconds (estimated). This does not properly account for the
|
|
18
|
+
* internal thread pool (which enables column-parallel processing of
|
|
19
|
+
* individual requests).
|
|
20
|
+
*/
|
|
21
|
+
cpu_time: number,
|
|
22
|
+
/**
|
|
23
|
+
* Milliseconds since internal CPU time accumulator was reset.
|
|
24
|
+
*/
|
|
25
|
+
cpu_time_epoch: number,
|
|
26
|
+
/**
|
|
27
|
+
* Timestamp (POSIX) this request was made. This field may be omitted
|
|
28
|
+
* for wasm due to `perspective-client` lacking a dependency on
|
|
29
|
+
* `wasm_bindgen`.
|
|
30
|
+
*/
|
|
31
|
+
timestamp: T | null,
|
|
32
|
+
/**
|
|
33
|
+
* Total available bytes for allocation on the [`Client`]. This is only
|
|
34
|
+
* available if `trace-allocator` is enabled.
|
|
35
|
+
*/
|
|
36
|
+
client_heap: T | null,
|
|
37
|
+
/**
|
|
38
|
+
* Bytes allocated for use on the [`Client`]. This is only
|
|
39
|
+
* available if `trace-allocator` is enabled.
|
|
40
|
+
*/
|
|
41
|
+
client_used: T | null, };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { TableReadFormat } from "./TableReadFormat.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options which impact the behavior of [`Client::table`], as well as
|
|
6
|
+
* subsequent calls to [`Table::update`].
|
|
7
|
+
*/
|
|
8
|
+
export type TableInitOptions = { name?: string, format?: TableReadFormat,
|
|
9
|
+
/**
|
|
10
|
+
* This [`Table`] should use the column named by the `index` parameter as
|
|
11
|
+
* the `index`, which causes [`Table::update`] and [`Client::table`] input
|
|
12
|
+
* to either insert or update existing rows based on `index` column
|
|
13
|
+
* value equality.
|
|
14
|
+
*/
|
|
15
|
+
index?: string,
|
|
16
|
+
/**
|
|
17
|
+
* This [`Table`] should be limited to `limit` rows, after which the
|
|
18
|
+
* _earliest_ rows will be overwritten (where _earliest_ is defined as
|
|
19
|
+
* relative to insertion order).
|
|
20
|
+
*/
|
|
21
|
+
limit?: number, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The format to interpret data preovided to [`Client::table`].
|
|
5
|
+
*
|
|
6
|
+
* When serialized, these values are `"csv"`, `"json"`, `"columns"`, `"arrow"`
|
|
7
|
+
* and `"ndjson"`.
|
|
8
|
+
*/
|
|
9
|
+
export type TableReadFormat = "csv" | "json" | "columns" | "arrow" | "ndjson";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { TableReadFormat } from "./TableReadFormat.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for [`Table::update`].
|
|
6
|
+
*/
|
|
7
|
+
export type UpdateOptions = { port_id: number | null, format: TableReadFormat | null, };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { Aggregate } from "./Aggregate.js";
|
|
3
|
+
import type { Expressions } from "./Expressions.js";
|
|
4
|
+
import type { Filter } from "./Filter.js";
|
|
5
|
+
import type { FilterReducer } from "./FilterReducer.js";
|
|
6
|
+
import type { Sort } from "./Sort.js";
|
|
7
|
+
|
|
8
|
+
export type ViewConfigUpdate = {
|
|
9
|
+
/**
|
|
10
|
+
* A group by _groups_ the dataset by the unique values of each column used
|
|
11
|
+
* as a group by - a close analogue in SQL to the `GROUP BY` statement.
|
|
12
|
+
* The underlying dataset is aggregated to show the values belonging to
|
|
13
|
+
* each group, and a total row is calculated for each group, showing
|
|
14
|
+
* the currently selected aggregated value (e.g. `sum`) of the column.
|
|
15
|
+
* Group by are useful for hierarchies, categorizing data and
|
|
16
|
+
* attributing values, i.e. showing the number of units sold based on
|
|
17
|
+
* State and City. In Perspective, group by are represented as an array
|
|
18
|
+
* of string column names to pivot, are applied in the order provided;
|
|
19
|
+
* For example, a group by of `["State", "City", "Postal Code"]` shows
|
|
20
|
+
* the values for each Postal Code, which are grouped by City,
|
|
21
|
+
* which are in turn grouped by State.
|
|
22
|
+
*/
|
|
23
|
+
group_by?: Array<string>,
|
|
24
|
+
/**
|
|
25
|
+
* A split by _splits_ the dataset by the unique values of each column used
|
|
26
|
+
* as a split by. The underlying dataset is not aggregated, and a new
|
|
27
|
+
* column is created for each unique value of the split by. Each newly
|
|
28
|
+
* created column contains the parts of the dataset that correspond to
|
|
29
|
+
* the column header, i.e. a `View` that has `["State"]` as its split
|
|
30
|
+
* by will have a new column for each state. In Perspective, Split By
|
|
31
|
+
* are represented as an array of string column names to pivot.
|
|
32
|
+
*/
|
|
33
|
+
split_by?: Array<string>,
|
|
34
|
+
/**
|
|
35
|
+
* The `columns` property specifies which columns should be included in the
|
|
36
|
+
* [`crate::View`]'s output. This allows users to show or hide a specific
|
|
37
|
+
* subset of columns, as well as control the order in which columns
|
|
38
|
+
* appear to the user. This is represented in Perspective as an array
|
|
39
|
+
* of string column names.
|
|
40
|
+
*/
|
|
41
|
+
columns?: Array<string | null>,
|
|
42
|
+
/**
|
|
43
|
+
* The `filter` property specifies columns on which the query can be
|
|
44
|
+
* filtered, returning rows that pass the specified filter condition.
|
|
45
|
+
* This is analogous to the `WHERE` clause in SQL. There is no limit on
|
|
46
|
+
* the number of columns where `filter` is applied, but the resulting
|
|
47
|
+
* dataset is one that passes all the filter conditions, i.e. the
|
|
48
|
+
* filters are joined with an `AND` condition.
|
|
49
|
+
*
|
|
50
|
+
* Perspective represents `filter` as an array of arrays, with the values
|
|
51
|
+
* of each inner array being a string column name, a string filter
|
|
52
|
+
* operator, and a filter operand in the type of the column.
|
|
53
|
+
*/
|
|
54
|
+
filter?: Array<Filter>,
|
|
55
|
+
/**
|
|
56
|
+
* The `sort` property specifies columns on which the query should be
|
|
57
|
+
* sorted, analogous to `ORDER BY` in SQL. A column can be sorted
|
|
58
|
+
* regardless of its data type, and sorts can be applied in ascending
|
|
59
|
+
* or descending order. Perspective represents `sort` as an array of
|
|
60
|
+
* arrays, with the values of each inner array being a string column
|
|
61
|
+
* name and a string sort direction. When `column-pivots` are applied,
|
|
62
|
+
* the additional sort directions `"col asc"` and `"col desc"` will
|
|
63
|
+
* determine the order of pivot columns groups.
|
|
64
|
+
*/
|
|
65
|
+
sort?: Array<Sort>,
|
|
66
|
+
/**
|
|
67
|
+
* The `expressions` property specifies _new_ columns in Perspective that
|
|
68
|
+
* are created using existing column values or arbitary scalar values
|
|
69
|
+
* defined within the expression. In `<perspective-viewer>`,
|
|
70
|
+
* expressions are added using the "New Column" button in the side
|
|
71
|
+
* panel.
|
|
72
|
+
*/
|
|
73
|
+
expressions?: Expressions,
|
|
74
|
+
/**
|
|
75
|
+
* Aggregates perform a calculation over an entire column, and are
|
|
76
|
+
* displayed when one or more [Group By](#group-by) are applied to the
|
|
77
|
+
* `View`. Aggregates can be specified by the user, or Perspective will
|
|
78
|
+
* use the following sensible default aggregates based on column type:
|
|
79
|
+
*
|
|
80
|
+
* - "sum" for `integer` and `float` columns
|
|
81
|
+
* - "count" for all other columns
|
|
82
|
+
*
|
|
83
|
+
* Perspective provides a selection of aggregate functions that can be
|
|
84
|
+
* applied to columns in the `View` constructor using a dictionary of
|
|
85
|
+
* column name to aggregate function name.
|
|
86
|
+
*/
|
|
87
|
+
aggregates?: { [key in string]?: Aggregate }, group_by_depth?: number, filter_op?: FilterReducer, };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for serializing a window of data from a [`View`].
|
|
5
|
+
*
|
|
6
|
+
* Some fields of [`ViewWindow`] are only applicable to specific methods of
|
|
7
|
+
* [`View`].
|
|
8
|
+
*/
|
|
9
|
+
export type ViewWindow = { start_row: number | null, start_col: number | null, end_row: number | null, end_col: number | null, id: boolean | null, index: boolean | null, leaves_only: boolean | null,
|
|
10
|
+
/**
|
|
11
|
+
* Only impacts [`View::to_csv`]
|
|
12
|
+
*/
|
|
13
|
+
formatted: boolean | null,
|
|
14
|
+
/**
|
|
15
|
+
* Only impacts [`View::to_arrow`]
|
|
16
|
+
*/
|
|
17
|
+
compression: string | null, };
|