@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.
Files changed (91) hide show
  1. package/LICENSE.md +193 -0
  2. package/README.md +3 -0
  3. package/dist/cdn/perspective-server.worker.js +2 -0
  4. package/dist/cdn/perspective-server.worker.js.map +7 -0
  5. package/dist/cdn/perspective.js +3 -0
  6. package/dist/cdn/perspective.js.map +7 -0
  7. package/dist/esm/perspective-server.worker.d.ts +1 -0
  8. package/dist/esm/perspective.browser.d.ts +14 -0
  9. package/dist/esm/perspective.inline.js +3 -0
  10. package/dist/esm/perspective.inline.js.map +7 -0
  11. package/dist/esm/perspective.js +3 -0
  12. package/dist/esm/perspective.js.map +7 -0
  13. package/dist/esm/perspective.node.d.ts +60 -0
  14. package/dist/esm/perspective.node.js +2431 -0
  15. package/dist/esm/perspective.node.js.map +7 -0
  16. package/dist/esm/ts-rs/Aggregate.d.ts +1 -0
  17. package/dist/esm/ts-rs/ColumnWindow.d.ts +4 -0
  18. package/dist/esm/ts-rs/DeleteOptions.d.ts +6 -0
  19. package/dist/esm/ts-rs/Expressions.d.ts +3 -0
  20. package/dist/esm/ts-rs/Filter.d.ts +2 -0
  21. package/dist/esm/ts-rs/FilterReducer.d.ts +1 -0
  22. package/dist/esm/ts-rs/FilterTerm.d.ts +2 -0
  23. package/dist/esm/ts-rs/OnUpdateMode.d.ts +9 -0
  24. package/dist/esm/ts-rs/OnUpdateOptions.d.ts +7 -0
  25. package/dist/esm/ts-rs/Scalar.d.ts +5 -0
  26. package/dist/esm/ts-rs/Sort.d.ts +2 -0
  27. package/dist/esm/ts-rs/SortDir.d.ts +1 -0
  28. package/dist/esm/ts-rs/SystemInfo.d.ts +40 -0
  29. package/dist/esm/ts-rs/TableInitOptions.d.ts +22 -0
  30. package/dist/esm/ts-rs/TableReadFormat.d.ts +7 -0
  31. package/dist/esm/ts-rs/UpdateOptions.d.ts +8 -0
  32. package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +90 -0
  33. package/dist/esm/ts-rs/ViewOnUpdateResp.d.ts +4 -0
  34. package/dist/esm/ts-rs/ViewWindow.d.ts +23 -0
  35. package/dist/esm/wasm/browser.d.ts +21 -0
  36. package/dist/esm/wasm/decompress.d.ts +1 -0
  37. package/dist/esm/wasm/emscripten_api.d.ts +5 -0
  38. package/dist/esm/wasm/engine.d.ts +40 -0
  39. package/dist/esm/wasm/perspective-server.poly.d.ts +1 -0
  40. package/dist/esm/websocket.d.ts +4 -0
  41. package/dist/wasm/perspective-js.d.ts +712 -0
  42. package/dist/wasm/perspective-js.js +1934 -0
  43. package/dist/wasm/perspective-js.wasm +0 -0
  44. package/dist/wasm/perspective-js.wasm.d.ts +75 -0
  45. package/package.json +68 -0
  46. package/src/rust/client.rs +483 -0
  47. package/src/rust/lib.rs +70 -0
  48. package/src/rust/table.rs +364 -0
  49. package/src/rust/table_data.rs +159 -0
  50. package/src/rust/utils/browser.rs +39 -0
  51. package/src/rust/utils/console_logger.rs +236 -0
  52. package/src/rust/utils/errors.rs +288 -0
  53. package/src/rust/utils/futures.rs +174 -0
  54. package/src/rust/utils/json.rs +252 -0
  55. package/src/rust/utils/local_poll_loop.rs +63 -0
  56. package/src/rust/utils/mod.rs +32 -0
  57. package/src/rust/utils/serde.rs +46 -0
  58. package/src/rust/utils/trace_allocator.rs +98 -0
  59. package/src/rust/view.rs +355 -0
  60. package/src/ts/perspective-server.worker.ts +54 -0
  61. package/src/ts/perspective.browser.ts +132 -0
  62. package/src/ts/perspective.cdn.ts +22 -0
  63. package/src/ts/perspective.inline.ts +27 -0
  64. package/src/ts/perspective.node.ts +315 -0
  65. package/src/ts/ts-rs/Aggregate.ts +3 -0
  66. package/src/ts/ts-rs/ColumnWindow.ts +3 -0
  67. package/src/ts/ts-rs/DeleteOptions.ts +6 -0
  68. package/src/ts/ts-rs/Expressions.ts +3 -0
  69. package/src/ts/ts-rs/Filter.ts +4 -0
  70. package/src/ts/ts-rs/FilterReducer.ts +3 -0
  71. package/src/ts/ts-rs/FilterTerm.ts +4 -0
  72. package/src/ts/ts-rs/OnUpdateData.ts +8 -0
  73. package/src/ts/ts-rs/OnUpdateMode.ts +11 -0
  74. package/src/ts/ts-rs/OnUpdateOptions.ts +7 -0
  75. package/src/ts/ts-rs/Scalar.ts +7 -0
  76. package/src/ts/ts-rs/Sort.ts +4 -0
  77. package/src/ts/ts-rs/SortDir.ts +3 -0
  78. package/src/ts/ts-rs/SystemInfo.ts +41 -0
  79. package/src/ts/ts-rs/TableInitOptions.ts +21 -0
  80. package/src/ts/ts-rs/TableReadFormat.ts +9 -0
  81. package/src/ts/ts-rs/UpdateOptions.ts +7 -0
  82. package/src/ts/ts-rs/ViewConfigUpdate.ts +87 -0
  83. package/src/ts/ts-rs/ViewOnUpdateResp.ts +3 -0
  84. package/src/ts/ts-rs/ViewWindow.ts +17 -0
  85. package/src/ts/wasm/browser.ts +123 -0
  86. package/src/ts/wasm/decompress.ts +64 -0
  87. package/src/ts/wasm/emscripten_api.ts +63 -0
  88. package/src/ts/wasm/engine.ts +271 -0
  89. package/src/ts/wasm/perspective-server.poly.ts +244 -0
  90. package/src/ts/websocket.ts +95 -0
  91. package/tsconfig.json +20 -0
@@ -0,0 +1,2431 @@
1
+ // src/ts/perspective.node.ts
2
+ import WebSocket, { WebSocketServer as HttpWebSocketServer } from "ws";
3
+ import stoppable from "stoppable";
4
+ import { promises as fs } from "node:fs";
5
+ import http from "node:http";
6
+ import path from "node:path";
7
+ import { webcrypto } from "node:crypto";
8
+ import * as url from "node:url";
9
+ import { createRequire } from "node:module";
10
+
11
+ // dist/wasm/perspective-js.js
12
+ var wasm;
13
+ var heap = new Array(128).fill(void 0);
14
+ heap.push(void 0, null, true, false);
15
+ function getObject(idx) {
16
+ return heap[idx];
17
+ }
18
+ var WASM_VECTOR_LEN = 0;
19
+ var cachedUint8ArrayMemory0 = null;
20
+ function getUint8ArrayMemory0() {
21
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
22
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
23
+ }
24
+ return cachedUint8ArrayMemory0;
25
+ }
26
+ var cachedTextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder("utf-8") : { encode: () => {
27
+ throw Error("TextEncoder not available");
28
+ } };
29
+ var encodeString = function(arg, view) {
30
+ return cachedTextEncoder.encodeInto(arg, view);
31
+ };
32
+ function passStringToWasm0(arg, malloc, realloc) {
33
+ if (realloc === void 0) {
34
+ const buf = cachedTextEncoder.encode(arg);
35
+ const ptr2 = malloc(buf.length, 1) >>> 0;
36
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
37
+ WASM_VECTOR_LEN = buf.length;
38
+ return ptr2;
39
+ }
40
+ let len = arg.length;
41
+ let ptr = malloc(len, 1) >>> 0;
42
+ const mem = getUint8ArrayMemory0();
43
+ let offset = 0;
44
+ for (; offset < len; offset++) {
45
+ const code = arg.charCodeAt(offset);
46
+ if (code > 127) break;
47
+ mem[ptr + offset] = code;
48
+ }
49
+ if (offset !== len) {
50
+ if (offset !== 0) {
51
+ arg = arg.slice(offset);
52
+ }
53
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
54
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
55
+ const ret = encodeString(arg, view);
56
+ offset += ret.written;
57
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
58
+ }
59
+ WASM_VECTOR_LEN = offset;
60
+ return ptr;
61
+ }
62
+ var cachedDataViewMemory0 = null;
63
+ function getDataViewMemory0() {
64
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
65
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
66
+ }
67
+ return cachedDataViewMemory0;
68
+ }
69
+ var heap_next = heap.length;
70
+ function addHeapObject(obj) {
71
+ if (heap_next === heap.length) heap.push(heap.length + 1);
72
+ const idx = heap_next;
73
+ heap_next = heap[idx];
74
+ heap[idx] = obj;
75
+ return idx;
76
+ }
77
+ function handleError(f, args) {
78
+ try {
79
+ return f.apply(this, args);
80
+ } catch (e) {
81
+ wasm.__wbindgen_export_2(addHeapObject(e));
82
+ }
83
+ }
84
+ var cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) : { decode: () => {
85
+ throw Error("TextDecoder not available");
86
+ } };
87
+ if (typeof TextDecoder !== "undefined") {
88
+ cachedTextDecoder.decode();
89
+ }
90
+ function getStringFromWasm0(ptr, len) {
91
+ ptr = ptr >>> 0;
92
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
93
+ }
94
+ function getArrayU8FromWasm0(ptr, len) {
95
+ ptr = ptr >>> 0;
96
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
97
+ }
98
+ function isLikeNone(x) {
99
+ return x === void 0 || x === null;
100
+ }
101
+ function dropObject(idx) {
102
+ if (idx < 132) return;
103
+ heap[idx] = heap_next;
104
+ heap_next = idx;
105
+ }
106
+ function takeObject(idx) {
107
+ const ret = getObject(idx);
108
+ dropObject(idx);
109
+ return ret;
110
+ }
111
+ var CLOSURE_DTORS = typeof FinalizationRegistry === "undefined" ? { register: () => {
112
+ }, unregister: () => {
113
+ } } : new FinalizationRegistry((state) => {
114
+ wasm.__wbindgen_export_4.get(state.dtor)(state.a, state.b);
115
+ });
116
+ function makeMutClosure(arg0, arg1, dtor, f) {
117
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
118
+ const real = (...args) => {
119
+ state.cnt++;
120
+ const a = state.a;
121
+ state.a = 0;
122
+ try {
123
+ return f(a, state.b, ...args);
124
+ } finally {
125
+ if (--state.cnt === 0) {
126
+ wasm.__wbindgen_export_4.get(state.dtor)(a, state.b);
127
+ CLOSURE_DTORS.unregister(state);
128
+ } else {
129
+ state.a = a;
130
+ }
131
+ }
132
+ };
133
+ real.original = state;
134
+ CLOSURE_DTORS.register(real, state, state);
135
+ return real;
136
+ }
137
+ function makeClosure(arg0, arg1, dtor, f) {
138
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
139
+ const real = (...args) => {
140
+ state.cnt++;
141
+ try {
142
+ return f(state.a, state.b, ...args);
143
+ } finally {
144
+ if (--state.cnt === 0) {
145
+ wasm.__wbindgen_export_4.get(state.dtor)(state.a, state.b);
146
+ state.a = 0;
147
+ CLOSURE_DTORS.unregister(state);
148
+ }
149
+ }
150
+ };
151
+ real.original = state;
152
+ CLOSURE_DTORS.register(real, state, state);
153
+ return real;
154
+ }
155
+ function debugString(val) {
156
+ const type = typeof val;
157
+ if (type == "number" || type == "boolean" || val == null) {
158
+ return `${val}`;
159
+ }
160
+ if (type == "string") {
161
+ return `"${val}"`;
162
+ }
163
+ if (type == "symbol") {
164
+ const description = val.description;
165
+ if (description == null) {
166
+ return "Symbol";
167
+ } else {
168
+ return `Symbol(${description})`;
169
+ }
170
+ }
171
+ if (type == "function") {
172
+ const name = val.name;
173
+ if (typeof name == "string" && name.length > 0) {
174
+ return `Function(${name})`;
175
+ } else {
176
+ return "Function";
177
+ }
178
+ }
179
+ if (Array.isArray(val)) {
180
+ const length = val.length;
181
+ let debug = "[";
182
+ if (length > 0) {
183
+ debug += debugString(val[0]);
184
+ }
185
+ for (let i = 1; i < length; i++) {
186
+ debug += ", " + debugString(val[i]);
187
+ }
188
+ debug += "]";
189
+ return debug;
190
+ }
191
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
192
+ let className;
193
+ if (builtInMatches && builtInMatches.length > 1) {
194
+ className = builtInMatches[1];
195
+ } else {
196
+ return toString.call(val);
197
+ }
198
+ if (className == "Object") {
199
+ try {
200
+ return "Object(" + JSON.stringify(val) + ")";
201
+ } catch (_) {
202
+ return "Object";
203
+ }
204
+ }
205
+ if (val instanceof Error) {
206
+ return `${val.name}: ${val.message}
207
+ ${val.stack}`;
208
+ }
209
+ return className;
210
+ }
211
+ function _assertClass(instance, klass) {
212
+ if (!(instance instanceof klass)) {
213
+ throw new Error(`expected instance of ${klass.name}`);
214
+ }
215
+ }
216
+ var stack_pointer = 128;
217
+ function addBorrowedObject(obj) {
218
+ if (stack_pointer == 1) throw new Error("out of js stack");
219
+ heap[--stack_pointer] = obj;
220
+ return stack_pointer;
221
+ }
222
+ function __wbg_adapter_50(arg0, arg1) {
223
+ const ret = wasm.__wbindgen_export_5(arg0, arg1);
224
+ return takeObject(ret);
225
+ }
226
+ function __wbg_adapter_53(arg0, arg1, arg2) {
227
+ wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2));
228
+ }
229
+ function __wbg_adapter_251(arg0, arg1, arg2, arg3) {
230
+ wasm.__wbindgen_export_7(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
231
+ }
232
+ var ClientFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
233
+ }, unregister: () => {
234
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_client_free(ptr >>> 0, 1));
235
+ var Client = class _Client {
236
+ static __wrap(ptr) {
237
+ ptr = ptr >>> 0;
238
+ const obj = Object.create(_Client.prototype);
239
+ obj.__wbg_ptr = ptr;
240
+ ClientFinalization.register(obj, obj.__wbg_ptr, obj);
241
+ return obj;
242
+ }
243
+ __destroy_into_raw() {
244
+ const ptr = this.__wbg_ptr;
245
+ this.__wbg_ptr = 0;
246
+ ClientFinalization.unregister(this);
247
+ return ptr;
248
+ }
249
+ free() {
250
+ const ptr = this.__destroy_into_raw();
251
+ wasm.__wbg_client_free(ptr, 0);
252
+ }
253
+ /**
254
+ * @returns {string}
255
+ */
256
+ __getClassname() {
257
+ let deferred1_0;
258
+ let deferred1_1;
259
+ try {
260
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
261
+ wasm.client___getClassname(retptr, this.__wbg_ptr);
262
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
263
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
264
+ deferred1_0 = r0;
265
+ deferred1_1 = r1;
266
+ return getStringFromWasm0(r0, r1);
267
+ } finally {
268
+ wasm.__wbindgen_add_to_stack_pointer(16);
269
+ wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
270
+ }
271
+ }
272
+ /**
273
+ * @param {Function} send_request
274
+ * @param {Function | null} [close]
275
+ */
276
+ constructor(send_request, close) {
277
+ try {
278
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
279
+ wasm.client_new(retptr, addHeapObject(send_request), isLikeNone(close) ? 0 : addHeapObject(close));
280
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
281
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
282
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
283
+ if (r2) {
284
+ throw takeObject(r1);
285
+ }
286
+ this.__wbg_ptr = r0 >>> 0;
287
+ ClientFinalization.register(this, this.__wbg_ptr, this);
288
+ return this;
289
+ } finally {
290
+ wasm.__wbindgen_add_to_stack_pointer(16);
291
+ }
292
+ }
293
+ /**
294
+ * @param {Function} on_response
295
+ * @returns {ProxySession}
296
+ */
297
+ new_proxy_session(on_response) {
298
+ try {
299
+ const ret = wasm.client_new_proxy_session(this.__wbg_ptr, addBorrowedObject(on_response));
300
+ return ProxySession.__wrap(ret);
301
+ } finally {
302
+ heap[stack_pointer++] = void 0;
303
+ }
304
+ }
305
+ /**
306
+ * @param {any} value
307
+ * @returns {Promise<void>}
308
+ */
309
+ handle_response(value) {
310
+ const ret = wasm.client_handle_response(this.__wbg_ptr, addHeapObject(value));
311
+ return takeObject(ret);
312
+ }
313
+ /**
314
+ * @param {string} error
315
+ * @param {Function | null} [reconnect]
316
+ * @returns {Promise<void>}
317
+ */
318
+ handle_error(error, reconnect) {
319
+ const ptr0 = passStringToWasm0(error, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
320
+ const len0 = WASM_VECTOR_LEN;
321
+ const ret = wasm.client_handle_error(this.__wbg_ptr, ptr0, len0, isLikeNone(reconnect) ? 0 : addHeapObject(reconnect));
322
+ return takeObject(ret);
323
+ }
324
+ /**
325
+ * @param {Function} callback
326
+ * @returns {Promise<number>}
327
+ */
328
+ on_error(callback) {
329
+ const ret = wasm.client_on_error(this.__wbg_ptr, addHeapObject(callback));
330
+ return takeObject(ret);
331
+ }
332
+ /**
333
+ * Creates a new [`Table`] from either a _schema_ or _data_.
334
+ *
335
+ * The [`Client::table`] factory function can be initialized with either a
336
+ * _schema_ (see [`Table::schema`]), or data in one of these formats:
337
+ *
338
+ * - Apache Arrow
339
+ * - CSV
340
+ * - JSON row-oriented
341
+ * - JSON column-oriented
342
+ * - NDJSON
343
+ *
344
+ * When instantiated with _data_, the schema is inferred from this data.
345
+ * While this is convenient, inferrence is sometimes imperfect e.g.
346
+ * when the input is empty, null or ambiguous. For these cases,
347
+ * [`Client::table`] can first be instantiated with a explicit schema.
348
+ *
349
+ * When instantiated with a _schema_, the resulting [`Table`] is empty but
350
+ * with known column names and column types. When subsqeuently
351
+ * populated with [`Table::update`], these columns will be _coerced_ to
352
+ * the schema's type. This behavior can be useful when
353
+ * [`Client::table`]'s column type inferences doesn't work.
354
+ *
355
+ * The resulting [`Table`] is _virtual_, and invoking its methods
356
+ * dispatches events to the `perspective_server::Server` this
357
+ * [`Client`] connects to, where the data is stored and all calculation
358
+ * occurs.
359
+ *
360
+ * # Arguments
361
+ *
362
+ * - `arg` - Either _schema_ or initialization _data_.
363
+ * - `options` - Optional configuration which provides one of:
364
+ * - `limit` - The max number of rows the resulting [`Table`] can
365
+ * store.
366
+ * - `index` - The column name to use as an _index_ column. If this
367
+ * `Table` is being instantiated by _data_, this column name must be
368
+ * present in the data.
369
+ * - `name` - The name of the table. This will be generated if it is
370
+ * not provided.
371
+ * - `format` - The explicit format of the input data, can be one of
372
+ * `"json"`, `"columns"`, `"csv"` or `"arrow"`. This overrides
373
+ * language-specific type dispatch behavior, which allows stringified
374
+ * and byte array alternative inputs.
375
+ *
376
+ * # JavaScript Examples
377
+ *
378
+ * Load a CSV from a `string`:
379
+ *
380
+ * ```javascript
381
+ * const table = await client.table("x,y\n1,2\n3,4");
382
+ * ```
383
+ *
384
+ * Load an Arrow from an `ArrayBuffer`:
385
+ *
386
+ * ```javascript
387
+ * import * as fs from "node:fs/promises";
388
+ * const table2 = await client.table(await fs.readFile("superstore.arrow"));
389
+ * ```
390
+ *
391
+ * Load a CSV from a `UInt8Array` (the default for this type is Arrow)
392
+ * using a format override:
393
+ *
394
+ * ```javascript
395
+ * const enc = new TextEncoder();
396
+ * const table = await client.table(enc.encode("x,y\n1,2\n3,4"), {
397
+ * format: "csv",
398
+ * });
399
+ * ```
400
+ *
401
+ * Create a table with an `index`:
402
+ *
403
+ * ```javascript
404
+ * const table = await client.table(data, { index: "Row ID" });
405
+ * ```
406
+ * @param {string | ArrayBuffer | Record<string, unknown[]> | Record<string, unknown>[]} value
407
+ * @param {TableInitOptions | null} [options]
408
+ * @returns {Promise<Table>}
409
+ */
410
+ table(value, options) {
411
+ const ret = wasm.client_table(this.__wbg_ptr, addHeapObject(value), isLikeNone(options) ? 0 : addHeapObject(options));
412
+ return takeObject(ret);
413
+ }
414
+ /**
415
+ * Terminates this [`Client`], cleaning up any [`crate::View`] handles the
416
+ * [`Client`] has open as well as its callbacks.
417
+ * @returns {any}
418
+ */
419
+ terminate() {
420
+ try {
421
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
422
+ wasm.client_terminate(retptr, this.__wbg_ptr);
423
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
424
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
425
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
426
+ if (r2) {
427
+ throw takeObject(r1);
428
+ }
429
+ return takeObject(r0);
430
+ } finally {
431
+ wasm.__wbindgen_add_to_stack_pointer(16);
432
+ }
433
+ }
434
+ /**
435
+ * Opens a [`Table`] that is hosted on the `perspective_server::Server`
436
+ * that is connected to this [`Client`].
437
+ *
438
+ * The `name` property of [`TableInitOptions`] is used to identify each
439
+ * [`Table`]. [`Table`] `name`s can be looked up for each [`Client`]
440
+ * via [`Client::get_hosted_table_names`].
441
+ *
442
+ * # JavaScript Examples
443
+ *
444
+ * Get a virtual [`Table`] named "table_one" from this [`Client`]
445
+ *
446
+ * ```javascript
447
+ * const tables = await client.open_table("table_one");
448
+ * ```
449
+ * @param {string} entity_id
450
+ * @returns {Promise<Table>}
451
+ */
452
+ open_table(entity_id) {
453
+ const ptr0 = passStringToWasm0(entity_id, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
454
+ const len0 = WASM_VECTOR_LEN;
455
+ const ret = wasm.client_open_table(this.__wbg_ptr, ptr0, len0);
456
+ return takeObject(ret);
457
+ }
458
+ /**
459
+ * Retrieves the names of all tables that this client has access to.
460
+ *
461
+ * `name` is a string identifier unique to the [`Table`] (per [`Client`]),
462
+ * which can be used in conjunction with [`Client::open_table`] to get
463
+ * a [`Table`] instance without the use of [`Client::table`]
464
+ * constructor directly (e.g., one created by another [`Client`]).
465
+ *
466
+ * # JavaScript Examples
467
+ *
468
+ * ```javascript
469
+ * const tables = await client.get_hosted_table_names();
470
+ * ```
471
+ * @returns {Promise<any>}
472
+ */
473
+ get_hosted_table_names() {
474
+ const ret = wasm.client_get_hosted_table_names(this.__wbg_ptr);
475
+ return takeObject(ret);
476
+ }
477
+ /**
478
+ * Register a callback which is invoked whenever [`Client::table`] (on this
479
+ * [`Client`]) or [`Table::delete`] (on a [`Table`] belinging to this
480
+ * [`Client`]) are called.
481
+ * @param {Function} on_update_js
482
+ * @returns {Promise<number>}
483
+ */
484
+ on_hosted_tables_update(on_update_js) {
485
+ const ret = wasm.client_on_hosted_tables_update(this.__wbg_ptr, addHeapObject(on_update_js));
486
+ return takeObject(ret);
487
+ }
488
+ /**
489
+ * Remove a callback previously registered via
490
+ * `Client::on_hosted_tables_update`.
491
+ * @param {number} update_id
492
+ * @returns {Promise<void>}
493
+ */
494
+ remove_hosted_tables_update(update_id) {
495
+ const ret = wasm.client_remove_hosted_tables_update(this.__wbg_ptr, update_id);
496
+ return takeObject(ret);
497
+ }
498
+ /**
499
+ * Provides the [`SystemInfo`] struct, implementation-specific metadata
500
+ * about the [`perspective_server::Server`] runtime such as Memory and
501
+ * CPU usage.
502
+ *
503
+ * For WebAssembly servers, this method includes the WebAssembly heap size.
504
+ *
505
+ * # JavaScript Examples
506
+ *
507
+ * ```javascript
508
+ * const info = await client.system_info();
509
+ * ```
510
+ * @returns {Promise<SystemInfo>}
511
+ */
512
+ system_info() {
513
+ const ret = wasm.client_system_info(this.__wbg_ptr);
514
+ return takeObject(ret);
515
+ }
516
+ };
517
+ var ProxySessionFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
518
+ }, unregister: () => {
519
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_proxysession_free(ptr >>> 0, 1));
520
+ var ProxySession = class _ProxySession {
521
+ static __wrap(ptr) {
522
+ ptr = ptr >>> 0;
523
+ const obj = Object.create(_ProxySession.prototype);
524
+ obj.__wbg_ptr = ptr;
525
+ ProxySessionFinalization.register(obj, obj.__wbg_ptr, obj);
526
+ return obj;
527
+ }
528
+ __destroy_into_raw() {
529
+ const ptr = this.__wbg_ptr;
530
+ this.__wbg_ptr = 0;
531
+ ProxySessionFinalization.unregister(this);
532
+ return ptr;
533
+ }
534
+ free() {
535
+ const ptr = this.__destroy_into_raw();
536
+ wasm.__wbg_proxysession_free(ptr, 0);
537
+ }
538
+ /**
539
+ * @param {Client} client
540
+ * @param {Function} on_response
541
+ */
542
+ constructor(client, on_response) {
543
+ try {
544
+ _assertClass(client, Client);
545
+ const ret = wasm.client_new_proxy_session(client.__wbg_ptr, addBorrowedObject(on_response));
546
+ this.__wbg_ptr = ret >>> 0;
547
+ ProxySessionFinalization.register(this, this.__wbg_ptr, this);
548
+ return this;
549
+ } finally {
550
+ heap[stack_pointer++] = void 0;
551
+ }
552
+ }
553
+ /**
554
+ * @param {any} value
555
+ * @returns {Promise<void>}
556
+ */
557
+ handle_request(value) {
558
+ const ret = wasm.proxysession_handle_request(this.__wbg_ptr, addHeapObject(value));
559
+ return takeObject(ret);
560
+ }
561
+ /**
562
+ * @returns {Promise<void>}
563
+ */
564
+ close() {
565
+ const ptr = this.__destroy_into_raw();
566
+ const ret = wasm.proxysession_close(ptr);
567
+ return takeObject(ret);
568
+ }
569
+ };
570
+ var TableFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
571
+ }, unregister: () => {
572
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_table_free(ptr >>> 0, 1));
573
+ var Table = class _Table {
574
+ static __wrap(ptr) {
575
+ ptr = ptr >>> 0;
576
+ const obj = Object.create(_Table.prototype);
577
+ obj.__wbg_ptr = ptr;
578
+ TableFinalization.register(obj, obj.__wbg_ptr, obj);
579
+ return obj;
580
+ }
581
+ __destroy_into_raw() {
582
+ const ptr = this.__wbg_ptr;
583
+ this.__wbg_ptr = 0;
584
+ TableFinalization.unregister(this);
585
+ return ptr;
586
+ }
587
+ free() {
588
+ const ptr = this.__destroy_into_raw();
589
+ wasm.__wbg_table_free(ptr, 0);
590
+ }
591
+ /**
592
+ * @returns {string}
593
+ */
594
+ __getClassname() {
595
+ let deferred1_0;
596
+ let deferred1_1;
597
+ try {
598
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
599
+ wasm.table___getClassname(retptr, this.__wbg_ptr);
600
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
601
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
602
+ deferred1_0 = r0;
603
+ deferred1_1 = r1;
604
+ return getStringFromWasm0(r0, r1);
605
+ } finally {
606
+ wasm.__wbindgen_add_to_stack_pointer(16);
607
+ wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
608
+ }
609
+ }
610
+ /**
611
+ * Returns the name of the index column for the table.
612
+ *
613
+ * # JavaScript Examples
614
+ *
615
+ * ```javascript
616
+ * const table = await client.table("x,y\n1,2\n3,4", { index: "x" });
617
+ * const index = table.get_index(); // "x"
618
+ * ```
619
+ * @returns {Promise<string | undefined>}
620
+ */
621
+ get_index() {
622
+ const ret = wasm.table_get_index(this.__wbg_ptr);
623
+ return takeObject(ret);
624
+ }
625
+ /**
626
+ * Get a copy of the [`Client`] this [`Table`] came from.
627
+ * @returns {Promise<Client>}
628
+ */
629
+ get_client() {
630
+ const ret = wasm.table_get_client(this.__wbg_ptr);
631
+ return takeObject(ret);
632
+ }
633
+ /**
634
+ * Returns the user-specified name for this table, or the auto-generated
635
+ * name if a name was not specified when the table was created.
636
+ * @returns {Promise<string>}
637
+ */
638
+ get_name() {
639
+ const ret = wasm.table_get_name(this.__wbg_ptr);
640
+ return takeObject(ret);
641
+ }
642
+ /**
643
+ * Returns the user-specified row limit for this table.
644
+ * @returns {Promise<number | undefined>}
645
+ */
646
+ get_limit() {
647
+ const ret = wasm.table_get_limit(this.__wbg_ptr);
648
+ return takeObject(ret);
649
+ }
650
+ /**
651
+ * Removes all the rows in the [`Table`], but preserves everything else
652
+ * including the schema, index, and any callbacks or registered
653
+ * [`View`] instances.
654
+ *
655
+ * Calling [`Table::clear`], like [`Table::update`] and [`Table::remove`],
656
+ * will trigger an update event to any registered listeners via
657
+ * [`View::on_update`].
658
+ * @returns {Promise<void>}
659
+ */
660
+ clear() {
661
+ const ret = wasm.table_clear(this.__wbg_ptr);
662
+ return takeObject(ret);
663
+ }
664
+ /**
665
+ * Delete this [`Table`] and cleans up associated resources.
666
+ *
667
+ * [`Table`]s do not stop consuming resources or processing updates when
668
+ * they are garbage collected in their host language - you must call
669
+ * this method to reclaim these.
670
+ *
671
+ * # Arguments
672
+ *
673
+ * - `options` An options dictionary.
674
+ * - `lazy` Whether to delete this [`Table`] _lazily_. When false (the
675
+ * default), the delete will occur immediately, assuming it has no
676
+ * [`View`] instances registered to it (which must be deleted first,
677
+ * otherwise this method will throw an error). When true, the
678
+ * [`Table`] will only be marked for deltion once its [`View`]
679
+ * dependency count reaches 0.
680
+ *
681
+ * # JavaScript Examples
682
+ *
683
+ * ```javascript
684
+ * const table = await client.table("x,y\n1,2\n3,4");
685
+ *
686
+ * // ...
687
+ *
688
+ * await table.delete({ lazy: true });
689
+ * ```
690
+ * @param {DeleteOptions | null} [options]
691
+ * @returns {Promise<void>}
692
+ */
693
+ delete(options) {
694
+ const ptr = this.__destroy_into_raw();
695
+ const ret = wasm.table_delete(ptr, isLikeNone(options) ? 0 : addHeapObject(options));
696
+ return takeObject(ret);
697
+ }
698
+ /**
699
+ * Returns the number of rows in a [`Table`].
700
+ * @returns {Promise<number>}
701
+ */
702
+ size() {
703
+ const ret = wasm.table_size(this.__wbg_ptr);
704
+ return takeObject(ret);
705
+ }
706
+ /**
707
+ * Returns a table's [`Schema`], a mapping of column names to column types.
708
+ *
709
+ * The mapping of a [`Table`]'s column names to data types is referred to
710
+ * as a [`Schema`]. Each column has a unique name and a data type, one
711
+ * of:
712
+ *
713
+ * - `"boolean"` - A boolean type
714
+ * - `"date"` - A timesonze-agnostic date type (month/day/year)
715
+ * - `"datetime"` - A millisecond-precision datetime type in the UTC
716
+ * timezone
717
+ * - `"float"` - A 64 bit float
718
+ * - `"integer"` - A signed 32 bit integer (the integer type supported by
719
+ * JavaScript)
720
+ * - `"string"` - A [`String`] data type (encoded internally as a
721
+ * _dictionary_)
722
+ *
723
+ * Note that all [`Table`] columns are _nullable_, regardless of the data
724
+ * type.
725
+ * @returns {Promise<any>}
726
+ */
727
+ schema() {
728
+ const ret = wasm.table_schema(this.__wbg_ptr);
729
+ return takeObject(ret);
730
+ }
731
+ /**
732
+ * Returns the column names of this [`Table`] in "natural" order (the
733
+ * ordering implied by the input format).
734
+ *
735
+ * # JavaScript Examples
736
+ *
737
+ * ```javascript
738
+ * const columns = await table.columns();
739
+ * ```
740
+ * @returns {Promise<any>}
741
+ */
742
+ columns() {
743
+ const ret = wasm.table_columns(this.__wbg_ptr);
744
+ return takeObject(ret);
745
+ }
746
+ /**
747
+ * Create a unique channel ID on this [`Table`], which allows
748
+ * `View::on_update` callback calls to be associated with the
749
+ * `Table::update` which caused them.
750
+ * @returns {Promise<number>}
751
+ */
752
+ make_port() {
753
+ const ret = wasm.table_make_port(this.__wbg_ptr);
754
+ return takeObject(ret);
755
+ }
756
+ /**
757
+ * Register a callback which is called exactly once, when this [`Table`] is
758
+ * deleted with the [`Table::delete`] method.
759
+ *
760
+ * [`Table::on_delete`] resolves when the subscription message is sent, not
761
+ * when the _delete_ event occurs.
762
+ * @param {Function} on_delete
763
+ * @returns {Promise<any>}
764
+ */
765
+ on_delete(on_delete) {
766
+ const ret = wasm.table_on_delete(this.__wbg_ptr, addHeapObject(on_delete));
767
+ return takeObject(ret);
768
+ }
769
+ /**
770
+ * Removes a listener with a given ID, as returned by a previous call to
771
+ * [`Table::on_delete`].
772
+ * @param {number} callback_id
773
+ * @returns {Promise<any>}
774
+ */
775
+ remove_delete(callback_id) {
776
+ const ret = wasm.table_remove_delete(this.__wbg_ptr, callback_id);
777
+ return takeObject(ret);
778
+ }
779
+ /**
780
+ * Removes rows from this [`Table`] with the `index` column values
781
+ * supplied.
782
+ *
783
+ * # Arguments
784
+ *
785
+ * - `indices` - A list of `index` column values for rows that should be
786
+ * removed.
787
+ *
788
+ * # JavaScript Examples
789
+ *
790
+ * ```javascript
791
+ * await table.remove([1, 2, 3]);
792
+ * ```
793
+ * @param {any} value
794
+ * @param {UpdateOptions | null} [options]
795
+ * @returns {Promise<void>}
796
+ */
797
+ remove(value, options) {
798
+ const ret = wasm.table_remove(this.__wbg_ptr, addHeapObject(value), isLikeNone(options) ? 0 : addHeapObject(options));
799
+ return takeObject(ret);
800
+ }
801
+ /**
802
+ * Replace all rows in this [`Table`] with the input data, coerced to this
803
+ * [`Table`]'s existing [`perspective_client::Schema`], notifying any
804
+ * derived [`View`] and [`View::on_update`] callbacks.
805
+ *
806
+ * Calling [`Table::replace`] is an easy way to replace _all_ the data in a
807
+ * [`Table`] without losing any derived [`View`] instances or
808
+ * [`View::on_update`] callbacks. [`Table::replace`] does _not_ infer
809
+ * data types like [`Client::table`] does, rather it _coerces_ input
810
+ * data to the `Schema` like [`Table::update`]. If you need a [`Table`]
811
+ * with a different `Schema`, you must create a new one.
812
+ *
813
+ * # JavaScript Examples
814
+ *
815
+ * ```javascript
816
+ * await table.replace("x,y\n1,2");
817
+ * ```
818
+ * @param {any} input
819
+ * @param {UpdateOptions | null} [options]
820
+ * @returns {Promise<void>}
821
+ */
822
+ replace(input, options) {
823
+ const ret = wasm.table_replace(this.__wbg_ptr, addHeapObject(input), isLikeNone(options) ? 0 : addHeapObject(options));
824
+ return takeObject(ret);
825
+ }
826
+ /**
827
+ * Updates the rows of this table and any derived [`View`] instances.
828
+ *
829
+ * Calling [`Table::update`] will trigger the [`View::on_update`] callbacks
830
+ * register to derived [`View`], and the call itself will not resolve until
831
+ * _all_ derived [`View`]'s are notified.
832
+ *
833
+ * When updating a [`Table`] with an `index`, [`Table::update`] supports
834
+ * partial updates, by omitting columns from the update data.
835
+ *
836
+ * # Arguments
837
+ *
838
+ * - `input` - The input data for this [`Table`]. The schema of a [`Table`]
839
+ * is immutable after creation, so this method cannot be called with a
840
+ * schema.
841
+ * - `options` - Options for this update step - see [`UpdateOptions`].
842
+ *
843
+ * # JavaScript Examples
844
+ *
845
+ * ```javascript
846
+ * await table.update("x,y\n1,2");
847
+ * ```
848
+ * @param {string | ArrayBuffer | Record<string, unknown[]> | Record<string, unknown>[]} input
849
+ * @param {UpdateOptions | null} [options]
850
+ * @returns {Promise<any>}
851
+ */
852
+ update(input, options) {
853
+ const ret = wasm.table_update(this.__wbg_ptr, addHeapObject(input), isLikeNone(options) ? 0 : addHeapObject(options));
854
+ return takeObject(ret);
855
+ }
856
+ /**
857
+ * Create a new [`View`] from this table with a specified
858
+ * [`ViewConfigUpdate`].
859
+ *
860
+ * See [`View`] struct.
861
+ *
862
+ * # JavaScript Examples
863
+ *
864
+ * ```javascript
865
+ * const view = await table.view({
866
+ * columns: ["Sales"],
867
+ * aggregates: { Sales: "sum" },
868
+ * group_by: ["Region", "Country"],
869
+ * filter: [["Category", "in", ["Furniture", "Technology"]]],
870
+ * });
871
+ * ```
872
+ * @param {ViewConfigUpdate | null} [config]
873
+ * @returns {Promise<View>}
874
+ */
875
+ view(config) {
876
+ const ret = wasm.table_view(this.__wbg_ptr, isLikeNone(config) ? 0 : addHeapObject(config));
877
+ return takeObject(ret);
878
+ }
879
+ /**
880
+ * Validates the given expressions.
881
+ * @param {any} exprs
882
+ * @returns {Promise<any>}
883
+ */
884
+ validate_expressions(exprs) {
885
+ const ret = wasm.table_validate_expressions(this.__wbg_ptr, addHeapObject(exprs));
886
+ return takeObject(ret);
887
+ }
888
+ };
889
+ var ViewFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
890
+ }, unregister: () => {
891
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_view_free(ptr >>> 0, 1));
892
+ var View = class _View {
893
+ static __wrap(ptr) {
894
+ ptr = ptr >>> 0;
895
+ const obj = Object.create(_View.prototype);
896
+ obj.__wbg_ptr = ptr;
897
+ ViewFinalization.register(obj, obj.__wbg_ptr, obj);
898
+ return obj;
899
+ }
900
+ static __unwrap(jsValue) {
901
+ if (!(jsValue instanceof _View)) {
902
+ return 0;
903
+ }
904
+ return jsValue.__destroy_into_raw();
905
+ }
906
+ __destroy_into_raw() {
907
+ const ptr = this.__wbg_ptr;
908
+ this.__wbg_ptr = 0;
909
+ ViewFinalization.unregister(this);
910
+ return ptr;
911
+ }
912
+ free() {
913
+ const ptr = this.__destroy_into_raw();
914
+ wasm.__wbg_view_free(ptr, 0);
915
+ }
916
+ /**
917
+ * @returns {View}
918
+ */
919
+ __get_model() {
920
+ const ret = wasm.view___get_model(this.__wbg_ptr);
921
+ return _View.__wrap(ret);
922
+ }
923
+ /**
924
+ * Returns an array of strings containing the column paths of the [`View`]
925
+ * without any of the source columns.
926
+ *
927
+ * A column path shows the columns that a given cell belongs to after
928
+ * pivots are applied.
929
+ * @param {ColumnWindow | null} [window]
930
+ * @returns {Promise<any>}
931
+ */
932
+ column_paths(window2) {
933
+ const ret = wasm.view_column_paths(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
934
+ return takeObject(ret);
935
+ }
936
+ /**
937
+ * Delete this [`View`] and clean up all resources associated with it.
938
+ * [`View`] objects do not stop consuming resources or processing
939
+ * updates when they are garbage collected - you must call this method
940
+ * to reclaim these.
941
+ * @returns {Promise<void>}
942
+ */
943
+ delete() {
944
+ const ptr = this.__destroy_into_raw();
945
+ const ret = wasm.view_delete(ptr);
946
+ return takeObject(ret);
947
+ }
948
+ /**
949
+ * Returns this [`View`]'s _dimensions_, row and column count, as well as
950
+ * those of the [`crate::Table`] from which it was derived.
951
+ *
952
+ * - `num_table_rows` - The number of rows in the underlying
953
+ * [`crate::Table`].
954
+ * - `num_table_columns` - The number of columns in the underlying
955
+ * [`crate::Table`] (including the `index` column if this
956
+ * [`crate::Table`] was constructed with one).
957
+ * - `num_view_rows` - The number of rows in this [`View`]. If this
958
+ * [`View`] has a `group_by` clause, `num_view_rows` will also include
959
+ * aggregated rows.
960
+ * - `num_view_columns` - The number of columns in this [`View`]. If this
961
+ * [`View`] has a `split_by` clause, `num_view_columns` will include all
962
+ * _column paths_, e.g. the number of `columns` clause times the number
963
+ * of `split_by` groups.
964
+ * @returns {Promise<any>}
965
+ */
966
+ dimensions() {
967
+ const ret = wasm.view_dimensions(this.__wbg_ptr);
968
+ return takeObject(ret);
969
+ }
970
+ /**
971
+ * The expression schema of this [`View`], which contains only the
972
+ * expressions created on this [`View`]. See [`View::schema`] for
973
+ * details.
974
+ * @returns {Promise<any>}
975
+ */
976
+ expression_schema() {
977
+ const ret = wasm.view_expression_schema(this.__wbg_ptr);
978
+ return takeObject(ret);
979
+ }
980
+ /**
981
+ * A copy of the config object passed to the [`Table::view`] method which
982
+ * created this [`View`].
983
+ * @returns {Promise<any>}
984
+ */
985
+ get_config() {
986
+ const ret = wasm.view_get_config(this.__wbg_ptr);
987
+ return takeObject(ret);
988
+ }
989
+ /**
990
+ * Calculates the [min, max] of the leaf nodes of a column `column_name`.
991
+ *
992
+ * # Returns
993
+ *
994
+ * A tuple of [min, max], whose types are column and aggregate dependent.
995
+ * @param {string} name
996
+ * @returns {Promise<Array<any>>}
997
+ */
998
+ get_min_max(name) {
999
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
1000
+ const len0 = WASM_VECTOR_LEN;
1001
+ const ret = wasm.view_get_min_max(this.__wbg_ptr, ptr0, len0);
1002
+ return takeObject(ret);
1003
+ }
1004
+ /**
1005
+ * The number of aggregated rows in this [`View`]. This is affected by the
1006
+ * "group_by" configuration parameter supplied to this view's contructor.
1007
+ *
1008
+ * # Returns
1009
+ *
1010
+ * The number of aggregated rows.
1011
+ * @returns {Promise<number>}
1012
+ */
1013
+ num_rows() {
1014
+ const ret = wasm.view_num_rows(this.__wbg_ptr);
1015
+ return takeObject(ret);
1016
+ }
1017
+ /**
1018
+ * The schema of this [`View`].
1019
+ *
1020
+ * The [`View`] schema differs from the `schema` returned by
1021
+ * [`Table::schema`]; it may have different column names due to
1022
+ * `expressions` or `columns` configs, or it maye have _different
1023
+ * column types_ due to the application og `group_by` and `aggregates`
1024
+ * config. You can think of [`Table::schema`] as the _input_ schema and
1025
+ * [`View::schema`] as the _output_ schema of a Perspective pipeline.
1026
+ * @returns {Promise<any>}
1027
+ */
1028
+ schema() {
1029
+ const ret = wasm.view_schema(this.__wbg_ptr);
1030
+ return takeObject(ret);
1031
+ }
1032
+ /**
1033
+ * Serializes a [`View`] to the Apache Arrow data format.
1034
+ * @param {ViewWindow | null} [window]
1035
+ * @returns {Promise<ArrayBuffer>}
1036
+ */
1037
+ to_arrow(window2) {
1038
+ const ret = wasm.view_to_arrow(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
1039
+ return takeObject(ret);
1040
+ }
1041
+ /**
1042
+ * Serializes this [`View`] to a string of JSON data. Useful if you want to
1043
+ * save additional round trip serialize/deserialize cycles.
1044
+ * @param {ViewWindow | null} [window]
1045
+ * @returns {Promise<string>}
1046
+ */
1047
+ to_columns_string(window2) {
1048
+ const ret = wasm.view_to_columns_string(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
1049
+ return takeObject(ret);
1050
+ }
1051
+ /**
1052
+ * Serializes this [`View`] to JavaScript objects in a column-oriented
1053
+ * format.
1054
+ * @param {ViewWindow | null} [window]
1055
+ * @returns {Promise<object>}
1056
+ */
1057
+ to_columns(window2) {
1058
+ const ret = wasm.view_to_columns(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
1059
+ return takeObject(ret);
1060
+ }
1061
+ /**
1062
+ * Render this `View` as a JSON string.
1063
+ * @param {ViewWindow | null} [window]
1064
+ * @returns {Promise<string>}
1065
+ */
1066
+ to_json_string(window2) {
1067
+ const ret = wasm.view_to_json_string(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
1068
+ return takeObject(ret);
1069
+ }
1070
+ /**
1071
+ * Serializes this [`View`] to JavaScript objects in a row-oriented
1072
+ * format.
1073
+ * @param {ViewWindow | null} [window]
1074
+ * @returns {Promise<Array<any>>}
1075
+ */
1076
+ to_json(window2) {
1077
+ const ret = wasm.view_to_json(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
1078
+ return takeObject(ret);
1079
+ }
1080
+ /**
1081
+ * Renders this [`View`] as an [NDJSON](https://github.com/ndjson/ndjson-spec)
1082
+ * formatted [`String`].
1083
+ * @param {ViewWindow | null} [window]
1084
+ * @returns {Promise<string>}
1085
+ */
1086
+ to_ndjson(window2) {
1087
+ const ret = wasm.view_to_ndjson(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
1088
+ return takeObject(ret);
1089
+ }
1090
+ /**
1091
+ * Serializes this [`View`] to CSV data in a standard format.
1092
+ * @param {ViewWindow | null} [window]
1093
+ * @returns {Promise<string>}
1094
+ */
1095
+ to_csv(window2) {
1096
+ const ret = wasm.view_to_csv(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
1097
+ return takeObject(ret);
1098
+ }
1099
+ /**
1100
+ * Register a callback with this [`View`]. Whenever the view's underlying
1101
+ * table emits an update, this callback will be invoked with an object
1102
+ * containing `port_id`, indicating which port the update fired on, and
1103
+ * optionally `delta`, which is the new data that was updated for each
1104
+ * cell or each row.
1105
+ *
1106
+ * # Arguments
1107
+ *
1108
+ * - `on_update` - A callback function invoked on update, which receives an
1109
+ * object with two keys: `port_id`, indicating which port the update was
1110
+ * triggered on, and `delta`, whose value is dependent on the mode
1111
+ * parameter.
1112
+ * - `options` - If this is provided as `OnUpdateOptions { mode:
1113
+ * Some(OnUpdateMode::Row) }`, then `delta` is an Arrow of the updated
1114
+ * rows. Otherwise `delta` will be [`Option::None`].
1115
+ *
1116
+ * # JavaScript Examples
1117
+ *
1118
+ * ```javascript
1119
+ * // Attach an `on_update` callback
1120
+ * view.on_update((updated) => console.log(updated.port_id));
1121
+ * ```
1122
+ *
1123
+ * ```javascript
1124
+ * // `on_update` with row deltas
1125
+ * view.on_update((updated) => console.log(updated.delta), { mode: "row" });
1126
+ * ```
1127
+ * @param {Function} on_update_js
1128
+ * @param {OnUpdateOptions | null} [options]
1129
+ * @returns {Promise<any>}
1130
+ */
1131
+ on_update(on_update_js, options) {
1132
+ const ret = wasm.view_on_update(this.__wbg_ptr, addHeapObject(on_update_js), isLikeNone(options) ? 0 : addHeapObject(options));
1133
+ return takeObject(ret);
1134
+ }
1135
+ /**
1136
+ * Unregister a previously registered update callback with this [`View`].
1137
+ *
1138
+ * # Arguments
1139
+ *
1140
+ * - `id` - A callback `id` as returned by a recipricol call to
1141
+ * [`View::on_update`].
1142
+ * @param {number} callback_id
1143
+ * @returns {Promise<void>}
1144
+ */
1145
+ remove_update(callback_id) {
1146
+ const ret = wasm.view_remove_update(this.__wbg_ptr, callback_id);
1147
+ return takeObject(ret);
1148
+ }
1149
+ /**
1150
+ * Register a callback with this [`View`]. Whenever the [`View`] is
1151
+ * deleted, this callback will be invoked.
1152
+ * @param {Function} on_delete
1153
+ * @returns {Promise<any>}
1154
+ */
1155
+ on_delete(on_delete) {
1156
+ const ret = wasm.view_on_delete(this.__wbg_ptr, addHeapObject(on_delete));
1157
+ return takeObject(ret);
1158
+ }
1159
+ /**
1160
+ * The number of aggregated columns in this [`View`]. This is affected by
1161
+ * the "split_by" configuration parameter supplied to this view's
1162
+ * contructor.
1163
+ *
1164
+ * # Returns
1165
+ *
1166
+ * The number of aggregated columns.
1167
+ * @returns {Promise<number>}
1168
+ */
1169
+ num_columns() {
1170
+ const ret = wasm.view_num_columns(this.__wbg_ptr);
1171
+ return takeObject(ret);
1172
+ }
1173
+ /**
1174
+ * Unregister a previously registered [`View::on_delete`] callback.
1175
+ * @param {number} callback_id
1176
+ * @returns {Promise<any>}
1177
+ */
1178
+ remove_delete(callback_id) {
1179
+ const ret = wasm.view_remove_delete(this.__wbg_ptr, callback_id);
1180
+ return takeObject(ret);
1181
+ }
1182
+ /**
1183
+ * Collapses the `group_by` row at `row_index`.
1184
+ * @param {number} row_index
1185
+ * @returns {Promise<number>}
1186
+ */
1187
+ collapse(row_index) {
1188
+ const ret = wasm.view_collapse(this.__wbg_ptr, row_index);
1189
+ return takeObject(ret);
1190
+ }
1191
+ /**
1192
+ * Expand the `group_by` row at `row_index`.
1193
+ * @param {number} row_index
1194
+ * @returns {Promise<number>}
1195
+ */
1196
+ expand(row_index) {
1197
+ const ret = wasm.view_expand(this.__wbg_ptr, row_index);
1198
+ return takeObject(ret);
1199
+ }
1200
+ /**
1201
+ * Set expansion `depth` of the `group_by` tree.
1202
+ * @param {number} depth
1203
+ * @returns {Promise<void>}
1204
+ */
1205
+ set_depth(depth) {
1206
+ const ret = wasm.view_set_depth(this.__wbg_ptr, depth);
1207
+ return takeObject(ret);
1208
+ }
1209
+ };
1210
+ async function __wbg_load(module, imports) {
1211
+ if (typeof Response === "function" && module instanceof Response) {
1212
+ if (typeof WebAssembly.instantiateStreaming === "function") {
1213
+ try {
1214
+ return await WebAssembly.instantiateStreaming(module, imports);
1215
+ } catch (e) {
1216
+ if (module.headers.get("Content-Type") != "application/wasm") {
1217
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
1218
+ } else {
1219
+ throw e;
1220
+ }
1221
+ }
1222
+ }
1223
+ const bytes = await module.arrayBuffer();
1224
+ return await WebAssembly.instantiate(bytes, imports);
1225
+ } else {
1226
+ const instance = await WebAssembly.instantiate(module, imports);
1227
+ if (instance instanceof WebAssembly.Instance) {
1228
+ return { instance, module };
1229
+ } else {
1230
+ return instance;
1231
+ }
1232
+ }
1233
+ }
1234
+ function __wbg_get_imports() {
1235
+ const imports = {};
1236
+ imports.wbg = {};
1237
+ imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
1238
+ const ret = String(getObject(arg1));
1239
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
1240
+ const len1 = WASM_VECTOR_LEN;
1241
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1242
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1243
+ };
1244
+ imports.wbg.__wbg_at_7d852dd9f194d43e = function(arg0, arg1) {
1245
+ const ret = getObject(arg0).at(arg1);
1246
+ return addHeapObject(ret);
1247
+ };
1248
+ imports.wbg.__wbg_buffer_09165b52af8c5237 = function(arg0) {
1249
+ const ret = getObject(arg0).buffer;
1250
+ return addHeapObject(ret);
1251
+ };
1252
+ imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
1253
+ const ret = getObject(arg0).buffer;
1254
+ return addHeapObject(ret);
1255
+ };
1256
+ imports.wbg.__wbg_call_672a4d21634d4a24 = function() {
1257
+ return handleError(function(arg0, arg1) {
1258
+ const ret = getObject(arg0).call(getObject(arg1));
1259
+ return addHeapObject(ret);
1260
+ }, arguments);
1261
+ };
1262
+ imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() {
1263
+ return handleError(function(arg0, arg1, arg2) {
1264
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
1265
+ return addHeapObject(ret);
1266
+ }, arguments);
1267
+ };
1268
+ imports.wbg.__wbg_call_833bed5770ea2041 = function() {
1269
+ return handleError(function(arg0, arg1, arg2, arg3) {
1270
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3));
1271
+ return addHeapObject(ret);
1272
+ }, arguments);
1273
+ };
1274
+ imports.wbg.__wbg_client_new = function(arg0) {
1275
+ const ret = Client.__wrap(arg0);
1276
+ return addHeapObject(ret);
1277
+ };
1278
+ imports.wbg.__wbg_debug_3cb59063b29f58c1 = function(arg0) {
1279
+ console.debug(getObject(arg0));
1280
+ };
1281
+ imports.wbg.__wbg_debug_e17b51583ca6a632 = function(arg0, arg1, arg2, arg3) {
1282
+ console.debug(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
1283
+ };
1284
+ imports.wbg.__wbg_done_769e5ede4b31c67b = function(arg0) {
1285
+ const ret = getObject(arg0).done;
1286
+ return ret;
1287
+ };
1288
+ imports.wbg.__wbg_entries_3265d4158b33e5dc = function(arg0) {
1289
+ const ret = Object.entries(getObject(arg0));
1290
+ return addHeapObject(ret);
1291
+ };
1292
+ imports.wbg.__wbg_error_1004b8c64097413f = function(arg0, arg1) {
1293
+ console.error(getObject(arg0), getObject(arg1));
1294
+ };
1295
+ imports.wbg.__wbg_error_524f506f44df1645 = function(arg0) {
1296
+ console.error(getObject(arg0));
1297
+ };
1298
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
1299
+ let deferred0_0;
1300
+ let deferred0_1;
1301
+ try {
1302
+ deferred0_0 = arg0;
1303
+ deferred0_1 = arg1;
1304
+ console.error(getStringFromWasm0(arg0, arg1));
1305
+ } finally {
1306
+ wasm.__wbindgen_export_3(deferred0_0, deferred0_1, 1);
1307
+ }
1308
+ };
1309
+ imports.wbg.__wbg_error_80de38b3f7cc3c3c = function(arg0, arg1, arg2, arg3) {
1310
+ console.error(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
1311
+ };
1312
+ imports.wbg.__wbg_from_2a5d3e218e67aa85 = function(arg0) {
1313
+ const ret = Array.from(getObject(arg0));
1314
+ return addHeapObject(ret);
1315
+ };
1316
+ imports.wbg.__wbg_getEntriesByName_2a5a14d4b09f36a4 = function(arg0, arg1, arg2, arg3, arg4) {
1317
+ const ret = getObject(arg0).getEntriesByName(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
1318
+ return addHeapObject(ret);
1319
+ };
1320
+ imports.wbg.__wbg_getRandomValues_21a0191e74d0e1d3 = function() {
1321
+ return handleError(function(arg0, arg1) {
1322
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
1323
+ }, arguments);
1324
+ };
1325
+ imports.wbg.__wbg_get_67b2ba62fc30de12 = function() {
1326
+ return handleError(function(arg0, arg1) {
1327
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
1328
+ return addHeapObject(ret);
1329
+ }, arguments);
1330
+ };
1331
+ imports.wbg.__wbg_get_74b8744f6a23f4fa = function(arg0, arg1, arg2) {
1332
+ const ret = getObject(arg0)[getStringFromWasm0(arg1, arg2)];
1333
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1334
+ };
1335
+ imports.wbg.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
1336
+ const ret = getObject(arg0)[arg1 >>> 0];
1337
+ return addHeapObject(ret);
1338
+ };
1339
+ imports.wbg.__wbg_getwithrefkey_1dc361bd10053bfe = function(arg0, arg1) {
1340
+ const ret = getObject(arg0)[getObject(arg1)];
1341
+ return addHeapObject(ret);
1342
+ };
1343
+ imports.wbg.__wbg_has_a5ea9117f258a0ec = function() {
1344
+ return handleError(function(arg0, arg1) {
1345
+ const ret = Reflect.has(getObject(arg0), getObject(arg1));
1346
+ return ret;
1347
+ }, arguments);
1348
+ };
1349
+ imports.wbg.__wbg_info_033d8b8a0838f1d3 = function(arg0, arg1, arg2, arg3) {
1350
+ console.info(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
1351
+ };
1352
+ imports.wbg.__wbg_info_3daf2e093e091b66 = function(arg0) {
1353
+ console.info(getObject(arg0));
1354
+ };
1355
+ imports.wbg.__wbg_instanceof_ArrayBuffer_e14585432e3737fc = function(arg0) {
1356
+ let result;
1357
+ try {
1358
+ result = getObject(arg0) instanceof ArrayBuffer;
1359
+ } catch (_) {
1360
+ result = false;
1361
+ }
1362
+ const ret = result;
1363
+ return ret;
1364
+ };
1365
+ imports.wbg.__wbg_instanceof_Array_6ac07133d621675a = function(arg0) {
1366
+ let result;
1367
+ try {
1368
+ result = getObject(arg0) instanceof Array;
1369
+ } catch (_) {
1370
+ result = false;
1371
+ }
1372
+ const ret = result;
1373
+ return ret;
1374
+ };
1375
+ imports.wbg.__wbg_instanceof_Error_4d54113b22d20306 = function(arg0) {
1376
+ let result;
1377
+ try {
1378
+ result = getObject(arg0) instanceof Error;
1379
+ } catch (_) {
1380
+ result = false;
1381
+ }
1382
+ const ret = result;
1383
+ return ret;
1384
+ };
1385
+ imports.wbg.__wbg_instanceof_Map_f3469ce2244d2430 = function(arg0) {
1386
+ let result;
1387
+ try {
1388
+ result = getObject(arg0) instanceof Map;
1389
+ } catch (_) {
1390
+ result = false;
1391
+ }
1392
+ const ret = result;
1393
+ return ret;
1394
+ };
1395
+ imports.wbg.__wbg_instanceof_Object_7f2dcef8f78644a4 = function(arg0) {
1396
+ let result;
1397
+ try {
1398
+ result = getObject(arg0) instanceof Object;
1399
+ } catch (_) {
1400
+ result = false;
1401
+ }
1402
+ const ret = result;
1403
+ return ret;
1404
+ };
1405
+ imports.wbg.__wbg_instanceof_Uint8Array_17156bcf118086a9 = function(arg0) {
1406
+ let result;
1407
+ try {
1408
+ result = getObject(arg0) instanceof Uint8Array;
1409
+ } catch (_) {
1410
+ result = false;
1411
+ }
1412
+ const ret = result;
1413
+ return ret;
1414
+ };
1415
+ imports.wbg.__wbg_instanceof_Window_def73ea0955fc569 = function(arg0) {
1416
+ let result;
1417
+ try {
1418
+ result = getObject(arg0) instanceof Window;
1419
+ } catch (_) {
1420
+ result = false;
1421
+ }
1422
+ const ret = result;
1423
+ return ret;
1424
+ };
1425
+ imports.wbg.__wbg_isArray_a1eab7e0d067391b = function(arg0) {
1426
+ const ret = Array.isArray(getObject(arg0));
1427
+ return ret;
1428
+ };
1429
+ imports.wbg.__wbg_isSafeInteger_343e2beeeece1bb0 = function(arg0) {
1430
+ const ret = Number.isSafeInteger(getObject(arg0));
1431
+ return ret;
1432
+ };
1433
+ imports.wbg.__wbg_iterator_9a24c88df860dc65 = function() {
1434
+ const ret = Symbol.iterator;
1435
+ return addHeapObject(ret);
1436
+ };
1437
+ imports.wbg.__wbg_keys_5c77a08ddc2fb8a6 = function(arg0) {
1438
+ const ret = Object.keys(getObject(arg0));
1439
+ return addHeapObject(ret);
1440
+ };
1441
+ imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) {
1442
+ const ret = getObject(arg0).length;
1443
+ return ret;
1444
+ };
1445
+ imports.wbg.__wbg_length_e2d2a49132c1b256 = function(arg0) {
1446
+ const ret = getObject(arg0).length;
1447
+ return ret;
1448
+ };
1449
+ imports.wbg.__wbg_mark_001da84b098c950f = function() {
1450
+ return handleError(function(arg0, arg1, arg2) {
1451
+ getObject(arg0).mark(getStringFromWasm0(arg1, arg2));
1452
+ }, arguments);
1453
+ };
1454
+ imports.wbg.__wbg_measure_65e49f8bc0e203a8 = function() {
1455
+ return handleError(function(arg0, arg1, arg2, arg3, arg4) {
1456
+ getObject(arg0).measure(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
1457
+ }, arguments);
1458
+ };
1459
+ imports.wbg.__wbg_message_97a2af9b89d693a3 = function(arg0) {
1460
+ const ret = getObject(arg0).message;
1461
+ return addHeapObject(ret);
1462
+ };
1463
+ imports.wbg.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
1464
+ try {
1465
+ var state0 = { a: arg0, b: arg1 };
1466
+ var cb0 = (arg02, arg12) => {
1467
+ const a = state0.a;
1468
+ state0.a = 0;
1469
+ try {
1470
+ return __wbg_adapter_251(a, state0.b, arg02, arg12);
1471
+ } finally {
1472
+ state0.a = a;
1473
+ }
1474
+ };
1475
+ const ret = new Promise(cb0);
1476
+ return addHeapObject(ret);
1477
+ } finally {
1478
+ state0.a = state0.b = 0;
1479
+ }
1480
+ };
1481
+ imports.wbg.__wbg_new_405e22f390576ce2 = function() {
1482
+ const ret = new Object();
1483
+ return addHeapObject(ret);
1484
+ };
1485
+ imports.wbg.__wbg_new_5e0be73521bc8c17 = function() {
1486
+ const ret = /* @__PURE__ */ new Map();
1487
+ return addHeapObject(ret);
1488
+ };
1489
+ imports.wbg.__wbg_new_78feb108b6472713 = function() {
1490
+ const ret = new Array();
1491
+ return addHeapObject(ret);
1492
+ };
1493
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
1494
+ const ret = new Error();
1495
+ return addHeapObject(ret);
1496
+ };
1497
+ imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) {
1498
+ const ret = new Uint8Array(getObject(arg0));
1499
+ return addHeapObject(ret);
1500
+ };
1501
+ imports.wbg.__wbg_new_c68d7209be747379 = function(arg0, arg1) {
1502
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
1503
+ return addHeapObject(ret);
1504
+ };
1505
+ imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
1506
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
1507
+ return addHeapObject(ret);
1508
+ };
1509
+ imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
1510
+ const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
1511
+ return addHeapObject(ret);
1512
+ };
1513
+ imports.wbg.__wbg_next_25feadfc0913fea9 = function(arg0) {
1514
+ const ret = getObject(arg0).next;
1515
+ return addHeapObject(ret);
1516
+ };
1517
+ imports.wbg.__wbg_next_6574e1a8a62d1055 = function() {
1518
+ return handleError(function(arg0) {
1519
+ const ret = getObject(arg0).next();
1520
+ return addHeapObject(ret);
1521
+ }, arguments);
1522
+ };
1523
+ imports.wbg.__wbg_now_d18023d54d4e5500 = function(arg0) {
1524
+ const ret = getObject(arg0).now();
1525
+ return ret;
1526
+ };
1527
+ imports.wbg.__wbg_parse_def2e24ef1252aff = function() {
1528
+ return handleError(function(arg0, arg1) {
1529
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
1530
+ return addHeapObject(ret);
1531
+ }, arguments);
1532
+ };
1533
+ imports.wbg.__wbg_performance_c185c0cdc2766575 = function(arg0) {
1534
+ const ret = getObject(arg0).performance;
1535
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1536
+ };
1537
+ imports.wbg.__wbg_push_737cfc8c1432c2c6 = function(arg0, arg1) {
1538
+ const ret = getObject(arg0).push(getObject(arg1));
1539
+ return ret;
1540
+ };
1541
+ imports.wbg.__wbg_queueMicrotask_6808622725a52272 = function(arg0) {
1542
+ const ret = getObject(arg0).queueMicrotask;
1543
+ return addHeapObject(ret);
1544
+ };
1545
+ imports.wbg.__wbg_queueMicrotask_ef0e86b0263a71ee = function(arg0) {
1546
+ queueMicrotask(getObject(arg0));
1547
+ };
1548
+ imports.wbg.__wbg_reject_b3fcf99063186ff7 = function(arg0) {
1549
+ const ret = Promise.reject(getObject(arg0));
1550
+ return addHeapObject(ret);
1551
+ };
1552
+ imports.wbg.__wbg_resolve_4851785c9c5f573d = function(arg0) {
1553
+ const ret = Promise.resolve(getObject(arg0));
1554
+ return addHeapObject(ret);
1555
+ };
1556
+ imports.wbg.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
1557
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
1558
+ };
1559
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
1560
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
1561
+ };
1562
+ imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
1563
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
1564
+ };
1565
+ imports.wbg.__wbg_set_8fc6bf8a5b1071d1 = function(arg0, arg1, arg2) {
1566
+ const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
1567
+ return addHeapObject(ret);
1568
+ };
1569
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
1570
+ const ret = getObject(arg1).stack;
1571
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
1572
+ const len1 = WASM_VECTOR_LEN;
1573
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1574
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1575
+ };
1576
+ imports.wbg.__wbg_startTime_c051731d0a31602f = function(arg0) {
1577
+ const ret = getObject(arg0).startTime;
1578
+ return ret;
1579
+ };
1580
+ imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
1581
+ const ret = typeof global === "undefined" ? null : global;
1582
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1583
+ };
1584
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
1585
+ const ret = typeof globalThis === "undefined" ? null : globalThis;
1586
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1587
+ };
1588
+ imports.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
1589
+ const ret = typeof self === "undefined" ? null : self;
1590
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1591
+ };
1592
+ imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
1593
+ const ret = typeof window === "undefined" ? null : window;
1594
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
1595
+ };
1596
+ imports.wbg.__wbg_stringify_f7ed6987935b4a24 = function() {
1597
+ return handleError(function(arg0) {
1598
+ const ret = JSON.stringify(getObject(arg0));
1599
+ return addHeapObject(ret);
1600
+ }, arguments);
1601
+ };
1602
+ imports.wbg.__wbg_table_new = function(arg0) {
1603
+ const ret = Table.__wrap(arg0);
1604
+ return addHeapObject(ret);
1605
+ };
1606
+ imports.wbg.__wbg_then_44b73946d2fb3e7d = function(arg0, arg1) {
1607
+ const ret = getObject(arg0).then(getObject(arg1));
1608
+ return addHeapObject(ret);
1609
+ };
1610
+ imports.wbg.__wbg_then_48b406749878a531 = function(arg0, arg1, arg2) {
1611
+ const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
1612
+ return addHeapObject(ret);
1613
+ };
1614
+ imports.wbg.__wbg_toString_5285597960676b7b = function(arg0) {
1615
+ const ret = getObject(arg0).toString();
1616
+ return addHeapObject(ret);
1617
+ };
1618
+ imports.wbg.__wbg_trace_d12a9ac890a2cbb8 = function(arg0, arg1, arg2, arg3) {
1619
+ console.trace(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
1620
+ };
1621
+ imports.wbg.__wbg_trace_e758b839df8d34f1 = function(arg0) {
1622
+ console.trace(getObject(arg0));
1623
+ };
1624
+ imports.wbg.__wbg_value_cd1ffa7b1ab794f1 = function(arg0) {
1625
+ const ret = getObject(arg0).value;
1626
+ return addHeapObject(ret);
1627
+ };
1628
+ imports.wbg.__wbg_values_fcb8ba8c0aad8b58 = function(arg0) {
1629
+ const ret = Object.values(getObject(arg0));
1630
+ return addHeapObject(ret);
1631
+ };
1632
+ imports.wbg.__wbg_view_new = function(arg0) {
1633
+ const ret = View.__wrap(arg0);
1634
+ return addHeapObject(ret);
1635
+ };
1636
+ imports.wbg.__wbg_view_unwrap = function(arg0) {
1637
+ const ret = View.__unwrap(takeObject(arg0));
1638
+ return ret;
1639
+ };
1640
+ imports.wbg.__wbg_warn_4ca3906c248c47c4 = function(arg0) {
1641
+ console.warn(getObject(arg0));
1642
+ };
1643
+ imports.wbg.__wbg_warn_aaf1f4664a035bd6 = function(arg0, arg1, arg2, arg3) {
1644
+ console.warn(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
1645
+ };
1646
+ imports.wbg.__wbindgen_as_number = function(arg0) {
1647
+ const ret = +getObject(arg0);
1648
+ return ret;
1649
+ };
1650
+ imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
1651
+ const ret = arg0;
1652
+ return addHeapObject(ret);
1653
+ };
1654
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
1655
+ const ret = BigInt.asUintN(64, arg0);
1656
+ return addHeapObject(ret);
1657
+ };
1658
+ imports.wbg.__wbindgen_bigint_get_as_i64 = function(arg0, arg1) {
1659
+ const v = getObject(arg1);
1660
+ const ret = typeof v === "bigint" ? v : void 0;
1661
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
1662
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1663
+ };
1664
+ imports.wbg.__wbindgen_boolean_get = function(arg0) {
1665
+ const v = getObject(arg0);
1666
+ const ret = typeof v === "boolean" ? v ? 1 : 0 : 2;
1667
+ return ret;
1668
+ };
1669
+ imports.wbg.__wbindgen_cb_drop = function(arg0) {
1670
+ const obj = takeObject(arg0).original;
1671
+ if (obj.cnt-- == 1) {
1672
+ obj.a = 0;
1673
+ return true;
1674
+ }
1675
+ const ret = false;
1676
+ return ret;
1677
+ };
1678
+ imports.wbg.__wbindgen_closure_wrapper3224 = function(arg0, arg1, arg2) {
1679
+ const ret = makeMutClosure(arg0, arg1, 468, __wbg_adapter_53);
1680
+ return addHeapObject(ret);
1681
+ };
1682
+ imports.wbg.__wbindgen_closure_wrapper367 = function(arg0, arg1, arg2) {
1683
+ const ret = makeClosure(arg0, arg1, 7, __wbg_adapter_50);
1684
+ return addHeapObject(ret);
1685
+ };
1686
+ imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
1687
+ const ret = debugString(getObject(arg1));
1688
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
1689
+ const len1 = WASM_VECTOR_LEN;
1690
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1691
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1692
+ };
1693
+ imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
1694
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
1695
+ return addHeapObject(ret);
1696
+ };
1697
+ imports.wbg.__wbindgen_in = function(arg0, arg1) {
1698
+ const ret = getObject(arg0) in getObject(arg1);
1699
+ return ret;
1700
+ };
1701
+ imports.wbg.__wbindgen_is_bigint = function(arg0) {
1702
+ const ret = typeof getObject(arg0) === "bigint";
1703
+ return ret;
1704
+ };
1705
+ imports.wbg.__wbindgen_is_function = function(arg0) {
1706
+ const ret = typeof getObject(arg0) === "function";
1707
+ return ret;
1708
+ };
1709
+ imports.wbg.__wbindgen_is_object = function(arg0) {
1710
+ const val = getObject(arg0);
1711
+ const ret = typeof val === "object" && val !== null;
1712
+ return ret;
1713
+ };
1714
+ imports.wbg.__wbindgen_is_string = function(arg0) {
1715
+ const ret = typeof getObject(arg0) === "string";
1716
+ return ret;
1717
+ };
1718
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
1719
+ const ret = getObject(arg0) === void 0;
1720
+ return ret;
1721
+ };
1722
+ imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
1723
+ const ret = getObject(arg0) === getObject(arg1);
1724
+ return ret;
1725
+ };
1726
+ imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
1727
+ const ret = getObject(arg0) == getObject(arg1);
1728
+ return ret;
1729
+ };
1730
+ imports.wbg.__wbindgen_memory = function() {
1731
+ const ret = wasm.memory;
1732
+ return addHeapObject(ret);
1733
+ };
1734
+ imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
1735
+ const obj = getObject(arg1);
1736
+ const ret = typeof obj === "number" ? obj : void 0;
1737
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1738
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1739
+ };
1740
+ imports.wbg.__wbindgen_number_new = function(arg0) {
1741
+ const ret = arg0;
1742
+ return addHeapObject(ret);
1743
+ };
1744
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
1745
+ const ret = getObject(arg0);
1746
+ return addHeapObject(ret);
1747
+ };
1748
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
1749
+ takeObject(arg0);
1750
+ };
1751
+ imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
1752
+ const obj = getObject(arg1);
1753
+ const ret = typeof obj === "string" ? obj : void 0;
1754
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
1755
+ var len1 = WASM_VECTOR_LEN;
1756
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1757
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1758
+ };
1759
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
1760
+ const ret = getStringFromWasm0(arg0, arg1);
1761
+ return addHeapObject(ret);
1762
+ };
1763
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
1764
+ throw new Error(getStringFromWasm0(arg0, arg1));
1765
+ };
1766
+ return imports;
1767
+ }
1768
+ function __wbg_init_memory(imports, memory) {
1769
+ }
1770
+ function __wbg_finalize_init(instance, module) {
1771
+ wasm = instance.exports;
1772
+ __wbg_init.__wbindgen_wasm_module = module;
1773
+ cachedDataViewMemory0 = null;
1774
+ cachedUint8ArrayMemory0 = null;
1775
+ return wasm;
1776
+ }
1777
+ async function __wbg_init(module_or_path) {
1778
+ if (wasm !== void 0) return wasm;
1779
+ if (typeof module_or_path !== "undefined") {
1780
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1781
+ ({ module_or_path } = module_or_path);
1782
+ } else {
1783
+ console.warn("using deprecated parameters for the initialization function; pass a single object instead");
1784
+ }
1785
+ }
1786
+ const imports = __wbg_get_imports();
1787
+ if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
1788
+ module_or_path = fetch(module_or_path);
1789
+ }
1790
+ __wbg_init_memory(imports);
1791
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1792
+ return __wbg_finalize_init(instance, module);
1793
+ }
1794
+ var perspective_js_default = __wbg_init;
1795
+
1796
+ // src/ts/wasm/decompress.ts
1797
+ import { extract } from "pro_self_extracting_wasm";
1798
+ if (typeof WebAssembly === "undefined") {
1799
+ throw new Error("WebAssembly not supported.");
1800
+ }
1801
+ async function load_wasm_stage_0(wasm2) {
1802
+ if (wasm2 instanceof Function) {
1803
+ wasm2 = await wasm2();
1804
+ }
1805
+ try {
1806
+ return await extract(wasm2);
1807
+ } catch (e) {
1808
+ console.warn("Stage 0 wasm loading failed, skipping");
1809
+ return new Uint8Array(wasm2);
1810
+ }
1811
+ }
1812
+
1813
+ // src/ts/wasm/engine.ts
1814
+ var PerspectiveServer = class {
1815
+ clients;
1816
+ server;
1817
+ module;
1818
+ on_poll_request;
1819
+ constructor(module, options) {
1820
+ this.clients = /* @__PURE__ */ new Map();
1821
+ this.module = module;
1822
+ this.on_poll_request = options?.on_poll_request;
1823
+ this.server = module._psp_new_server(
1824
+ !!options?.on_poll_request ? 1 : 0
1825
+ );
1826
+ }
1827
+ /**
1828
+ * Helper function to create server emitter/receiver pairs
1829
+ */
1830
+ make_session(callback) {
1831
+ const client_id = this.module._psp_new_session(this.server);
1832
+ this.clients.set(client_id, callback);
1833
+ return new PerspectiveSession(
1834
+ this.module,
1835
+ this.server,
1836
+ client_id,
1837
+ this.clients,
1838
+ this.on_poll_request && (() => this.on_poll_request(this))
1839
+ );
1840
+ }
1841
+ async poll() {
1842
+ const polled = this.module._psp_poll(this.server);
1843
+ await decode_api_responses(
1844
+ this.module,
1845
+ polled,
1846
+ async (msg) => {
1847
+ await this.clients.get(msg.client_id)(msg.data);
1848
+ }
1849
+ );
1850
+ }
1851
+ delete() {
1852
+ this.module._psp_delete_server(this.server);
1853
+ }
1854
+ };
1855
+ var PerspectiveSession = class {
1856
+ constructor(mod, server, client_id, client_map, on_poll_request) {
1857
+ this.mod = mod;
1858
+ this.server = server;
1859
+ this.client_id = client_id;
1860
+ this.client_map = client_map;
1861
+ this.on_poll_request = on_poll_request;
1862
+ }
1863
+ async handle_request(view) {
1864
+ const ptr = await convert_typed_array_to_pointer(
1865
+ this.mod,
1866
+ view,
1867
+ async (viewPtr) => {
1868
+ return this.mod._psp_handle_request(
1869
+ this.server,
1870
+ this.client_id,
1871
+ viewPtr,
1872
+ this.mod._psp_is_memory64() ? BigInt(view.byteLength) : view.byteLength
1873
+ );
1874
+ }
1875
+ );
1876
+ await decode_api_responses(this.mod, ptr, async (msg) => {
1877
+ await this.client_map.get(msg.client_id)(msg.data);
1878
+ });
1879
+ if (this.on_poll_request) {
1880
+ await this.on_poll_request();
1881
+ } else {
1882
+ await this.poll();
1883
+ }
1884
+ }
1885
+ async poll() {
1886
+ const polled = this.mod._psp_poll(this.server);
1887
+ await decode_api_responses(
1888
+ this.mod,
1889
+ polled,
1890
+ async (msg) => {
1891
+ if (msg.client_id === 0) {
1892
+ await this.client_map.get(this.client_id)(msg.data);
1893
+ } else {
1894
+ await this.client_map.get(msg.client_id)(msg.data);
1895
+ }
1896
+ }
1897
+ );
1898
+ }
1899
+ close() {
1900
+ this.mod._psp_close_session(this.server, this.client_id);
1901
+ }
1902
+ };
1903
+ async function convert_typed_array_to_pointer(core, array, callback) {
1904
+ const ptr = core._psp_alloc(
1905
+ core._psp_is_memory64() ? BigInt(array.byteLength) : array.byteLength
1906
+ );
1907
+ core.HEAPU8.set(array, Number(ptr));
1908
+ const msg = await callback(ptr);
1909
+ core._psp_free(ptr);
1910
+ return msg;
1911
+ }
1912
+ async function decode_api_responses(core, ptr, callback) {
1913
+ const is_64 = core._psp_is_memory64();
1914
+ const response = new DataView(
1915
+ core.HEAPU8.buffer,
1916
+ Number(ptr),
1917
+ is_64 ? 12 : 8
1918
+ );
1919
+ const num_msgs = response.getUint32(0, true);
1920
+ const msgs_ptr = is_64 ? response.getBigInt64(4, true) : response.getUint32(4, true);
1921
+ const messages = new DataView(
1922
+ core.HEAPU8.buffer,
1923
+ Number(msgs_ptr),
1924
+ num_msgs * (is_64 ? 16 : 12)
1925
+ );
1926
+ try {
1927
+ for (let i = 0; i < num_msgs; i++) {
1928
+ const [data_ptr, data_len, client_id] = is_64 ? [
1929
+ messages.getBigInt64(i * 16, true),
1930
+ messages.getInt32(i * 16 + 8, true),
1931
+ messages.getInt32(i * 16 + 12, true)
1932
+ ] : [
1933
+ messages.getInt32(i * 12, true),
1934
+ messages.getInt32(i * 12 + 4, true),
1935
+ messages.getInt32(i * 12 + 8, true)
1936
+ ];
1937
+ const data = new Uint8Array(
1938
+ core.HEAPU8.buffer,
1939
+ Number(data_ptr),
1940
+ data_len
1941
+ );
1942
+ const resp = { client_id, data };
1943
+ await callback(resp);
1944
+ }
1945
+ } finally {
1946
+ for (let i = 0; i < num_msgs; i++) {
1947
+ const data_ptr = is_64 ? messages.getBigInt64(i * 16, true) : messages.getInt32(i * 12, true);
1948
+ core._psp_free(data_ptr);
1949
+ }
1950
+ core._psp_free(
1951
+ is_64 ? BigInt(messages.byteOffset) : messages.byteOffset
1952
+ );
1953
+ core._psp_free(
1954
+ is_64 ? BigInt(response.byteOffset) : response.byteOffset
1955
+ );
1956
+ }
1957
+ }
1958
+
1959
+ // src/ts/wasm/perspective-server.poly.ts
1960
+ var out = console.log.bind(console);
1961
+ var err = console.error.bind(console);
1962
+ var UTF8Decoder = new TextDecoder("utf8");
1963
+ var printCharBuffers = [null, [], []];
1964
+ function UTF8ArrayToString(heapOrArray, idx = 0, maxBytesToRead = NaN) {
1965
+ var endIdx = idx + maxBytesToRead;
1966
+ var endPtr = idx;
1967
+ while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
1968
+ return UTF8Decoder.decode(
1969
+ heapOrArray instanceof Uint8Array ? heapOrArray.subarray(idx, endPtr) : new Uint8Array(heapOrArray.slice(idx, endPtr))
1970
+ );
1971
+ }
1972
+ function printChar(stream, curr) {
1973
+ var buffer = printCharBuffers[stream];
1974
+ if (curr === 0 || curr === 10) {
1975
+ (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
1976
+ buffer.length = 0;
1977
+ } else {
1978
+ buffer.push(curr);
1979
+ }
1980
+ }
1981
+ async function perspective_server_poly_default(obj) {
1982
+ let psp_module;
1983
+ let is_memory64 = false;
1984
+ let wasm_memory;
1985
+ const module = {
1986
+ HaveOffsetConverter() {
1987
+ console.error("HaveOffsetConverter");
1988
+ },
1989
+ __syscall_ftruncate64(...args) {
1990
+ console.error("__syscall_frtuncate64", args);
1991
+ },
1992
+ __syscall_getdents64(...args) {
1993
+ console.error("__syscall_frtuncate64", args);
1994
+ },
1995
+ __syscall_unlinkat(...args) {
1996
+ console.error("__syscall_frtuncate64", args);
1997
+ },
1998
+ __throw_exception_with_stack_trace(ex) {
1999
+ const e = new WebAssembly.Exception(
2000
+ psp_module.__cpp_exception,
2001
+ [ex],
2002
+ {
2003
+ traceStack: true
2004
+ }
2005
+ );
2006
+ e.message = "Unexpected internal error";
2007
+ throw e;
2008
+ },
2009
+ clock_time_get(clk_id, ignored_precision, ptime) {
2010
+ if (is_memory64) {
2011
+ ptime = ptime;
2012
+ ptime = Number(ptime);
2013
+ if (!(clk_id == 0 || clk_id == 1 || clk_id == 2 || clk_id == 3)) {
2014
+ return 28;
2015
+ }
2016
+ var now;
2017
+ if (clk_id === 0) {
2018
+ now = Date.now();
2019
+ } else {
2020
+ now = performance.now();
2021
+ }
2022
+ const nsec2 = Math.round(now * 1e3 * 1e3);
2023
+ const HEAP64 = new BigInt64Array(wasm_memory.buffer);
2024
+ HEAP64[ptime / 8] = BigInt(nsec2);
2025
+ return 0;
2026
+ } else {
2027
+ ptime = ptime;
2028
+ ptime >>>= 0;
2029
+ if (!(clk_id == 0 || clk_id == 1 || clk_id == 2 || clk_id == 3)) {
2030
+ return 28;
2031
+ }
2032
+ var now;
2033
+ if (clk_id === 0) {
2034
+ now = Date.now();
2035
+ } else {
2036
+ now = performance.now();
2037
+ }
2038
+ var nsec = Math.round(now * 1e6);
2039
+ const HEAP64 = new BigInt64Array(wasm_memory.buffer);
2040
+ HEAP64[ptime >>> 3] = BigInt(nsec);
2041
+ return 0;
2042
+ }
2043
+ },
2044
+ emscripten_asm_const_int(...args) {
2045
+ return 0;
2046
+ },
2047
+ emscripten_notify_memory_growth(memoryIndex) {
2048
+ if (is_memory64) {
2049
+ memoryIndex = Number(memoryIndex);
2050
+ } else {
2051
+ memoryIndex = memoryIndex;
2052
+ memoryIndex >>>= 0;
2053
+ }
2054
+ if (memoryIndex != 0) {
2055
+ console.error("abort");
2056
+ }
2057
+ },
2058
+ environ_get(...args) {
2059
+ return 0;
2060
+ },
2061
+ environ_sizes_get(...args) {
2062
+ return 0;
2063
+ },
2064
+ fd_close(...args) {
2065
+ console.error("fd_close", args);
2066
+ return 0;
2067
+ },
2068
+ fd_read(...args) {
2069
+ console.error("fd_read", args);
2070
+ return 0;
2071
+ },
2072
+ fd_seek(...args) {
2073
+ console.error("fs_seek", args);
2074
+ return 0;
2075
+ },
2076
+ fd_write(fd, iov, iovcnt, pnum) {
2077
+ const HEAPU8 = new Uint8Array(wasm_memory.buffer);
2078
+ if (!is_memory64) {
2079
+ iov = iov;
2080
+ iovcnt = iovcnt;
2081
+ pnum = pnum;
2082
+ iov >>>= 0;
2083
+ iovcnt >>>= 0;
2084
+ pnum >>>= 0;
2085
+ let num = 0;
2086
+ const HEAPU32 = new Uint32Array(wasm_memory.buffer);
2087
+ for (let i = 0; i < iovcnt; i++) {
2088
+ let ptr = HEAPU32[iov >>> 2 >>> 0];
2089
+ let len = HEAPU32[iov + 4 >>> 2 >>> 0];
2090
+ iov += 8;
2091
+ for (let j = 0; j < len; j++) {
2092
+ printChar(fd, HEAPU8[ptr + j >>> 0]);
2093
+ }
2094
+ num += len;
2095
+ }
2096
+ HEAPU32[pnum >>> 2 >>> 0] = num;
2097
+ return 0;
2098
+ } else {
2099
+ iov = Number(iov);
2100
+ iovcnt = Number(iovcnt);
2101
+ pnum = Number(pnum);
2102
+ let num = 0;
2103
+ const HEAPU64 = new BigUint64Array(wasm_memory.buffer);
2104
+ for (let i = 0; i < iovcnt; i++) {
2105
+ let ptr = Number(HEAPU64[iov / 8]);
2106
+ let len = Number(HEAPU64[(iov + 8) / 8]);
2107
+ iov += 16;
2108
+ for (let j = 0; j < len; j++) {
2109
+ printChar(fd, HEAPU8[ptr + j]);
2110
+ }
2111
+ num += len;
2112
+ }
2113
+ HEAPU64[pnum / 8] = BigInt(num);
2114
+ return 0;
2115
+ }
2116
+ },
2117
+ proc_exit(e) {
2118
+ console.error("proc_exit", e);
2119
+ return 0;
2120
+ }
2121
+ };
2122
+ const x = await obj.instantiateWasm(
2123
+ { env: module, wasi_snapshot_preview1: module },
2124
+ (instance) => {
2125
+ psp_module = instance.exports;
2126
+ is_memory64 = !!psp_module.psp_is_memory64();
2127
+ wasm_memory = instance.exports.memory;
2128
+ psp_module._initialize();
2129
+ }
2130
+ );
2131
+ const extensions = {};
2132
+ for (const [name, func] of Object.entries(x)) {
2133
+ extensions[`_${name}`] = func;
2134
+ }
2135
+ return {
2136
+ ...x,
2137
+ ...extensions,
2138
+ get HEAPU8() {
2139
+ return new Uint8Array(wasm_memory.buffer);
2140
+ }
2141
+ };
2142
+ }
2143
+
2144
+ // src/ts/wasm/emscripten_api.ts
2145
+ async function compile_perspective(wasmBinary) {
2146
+ const module = await perspective_server_poly_default({
2147
+ locateFile(x) {
2148
+ return x;
2149
+ },
2150
+ instantiateWasm: async (imports, receive) => {
2151
+ imports["env"] = {
2152
+ ...imports["env"],
2153
+ psp_stack_trace() {
2154
+ const str = Error().stack || "";
2155
+ const textEncoder = new TextEncoder();
2156
+ const bytes = textEncoder.encode(str);
2157
+ const ptr = module._psp_alloc(
2158
+ module._psp_is_memory64() ? BigInt(bytes.byteLength + 1) : bytes.byteLength + 1
2159
+ );
2160
+ module.HEAPU8.set(bytes, Number(ptr));
2161
+ module.HEAPU8[Number(ptr) + bytes.byteLength] = 0;
2162
+ return ptr;
2163
+ },
2164
+ psp_heap_size() {
2165
+ if (module._psp_is_memory64()) {
2166
+ return BigInt(module.HEAPU8.buffer.byteLength);
2167
+ } else {
2168
+ return module.HEAPU8.buffer.byteLength;
2169
+ }
2170
+ }
2171
+ };
2172
+ const webasm = await WebAssembly.instantiate(wasmBinary, imports);
2173
+ receive(webasm.instance);
2174
+ return webasm.instance.exports;
2175
+ }
2176
+ });
2177
+ return module;
2178
+ }
2179
+
2180
+ // src/ts/websocket.ts
2181
+ function invert_promise() {
2182
+ let sender = void 0, reject = void 0;
2183
+ let receiver = new Promise((x, u) => {
2184
+ sender = x;
2185
+ reject = u;
2186
+ });
2187
+ return [sender, receiver, reject];
2188
+ }
2189
+ async function websocket(WebSocket2, Client2, url2, options) {
2190
+ let client, ws;
2191
+ async function connect() {
2192
+ if (ws?.readyState === WebSocket2.CONNECTING || ws?.readyState === WebSocket2.OPEN) {
2193
+ console.warn(`Already connected ${ws.readyState}`);
2194
+ return;
2195
+ }
2196
+ let [sender, receiver, reject] = invert_promise();
2197
+ ws = new WebSocket2(url2, options);
2198
+ ws.onopen = sender;
2199
+ ws.binaryType = "arraybuffer";
2200
+ ws.onerror = (event) => {
2201
+ const msg = event.message || "Generic Websocket Error";
2202
+ client.handle_error(msg, connect);
2203
+ reject(msg);
2204
+ };
2205
+ ws.onclose = (event) => {
2206
+ const msg = `WebSocket closed ${event.code}`;
2207
+ client.handle_error(msg, connect);
2208
+ reject(msg);
2209
+ };
2210
+ ws.onmessage = (event) => {
2211
+ client.handle_response(event.data);
2212
+ };
2213
+ await receiver;
2214
+ }
2215
+ async function send_message(proto) {
2216
+ if (ws.readyState === WebSocket2.CLOSING || ws.readyState === WebSocket2.CLOSED) {
2217
+ const msg = `WebSocket transport error (${ws.readyState})`;
2218
+ client.handle_error(msg, connect);
2219
+ throw new Error(msg);
2220
+ } else if (ws.readyState === WebSocket2.CONNECTING) {
2221
+ const msg = `WebSocket message dropped (${ws.readyState})`;
2222
+ throw new Error(msg);
2223
+ } else {
2224
+ const buffer = proto.slice().buffer;
2225
+ ws.send(buffer);
2226
+ }
2227
+ }
2228
+ async function on_close() {
2229
+ console.debug("Closing WebSocket");
2230
+ ws.close();
2231
+ }
2232
+ client = new Client2(send_message, on_close);
2233
+ await connect();
2234
+ return client;
2235
+ }
2236
+
2237
+ // src/ts/perspective.node.ts
2238
+ var __dirname = path.dirname(url.fileURLToPath(import.meta.url));
2239
+ var { resolve } = createRequire(import.meta.url);
2240
+ if (!globalThis.crypto) {
2241
+ globalThis.crypto = webcrypto;
2242
+ }
2243
+ var uncompressed_client_wasm = await fs.readFile(path.join(__dirname, "../../dist/wasm/perspective-js.wasm")).then((buffer) => load_wasm_stage_0(buffer.buffer));
2244
+ await perspective_js_default({ module_or_path: uncompressed_client_wasm });
2245
+ var SYNC_MODULE = await fs.readFile(
2246
+ resolve("@perspective-dev/server/dist/wasm/perspective-server.wasm")
2247
+ ).then((buffer) => load_wasm_stage_0(buffer.buffer)).then((buffer) => compile_perspective(buffer.buffer));
2248
+ var SYNC_CLIENT;
2249
+ var SYNC_SERVER = new PerspectiveServer(SYNC_MODULE);
2250
+ var SYNC_SESSION = SYNC_SERVER.make_session(
2251
+ async (resp) => await SYNC_CLIENT.handle_response(resp)
2252
+ );
2253
+ SYNC_CLIENT = new Client(async (req) => {
2254
+ await SYNC_SESSION.handle_request(req);
2255
+ });
2256
+ var PerspectiveServer2 = class extends PerspectiveServer {
2257
+ constructor(options) {
2258
+ super(SYNC_MODULE, options);
2259
+ }
2260
+ };
2261
+ var make_session = async (send_response) => SYNC_SERVER.make_session(send_response);
2262
+ function make_client(send_request, close) {
2263
+ return new Client(send_request, close);
2264
+ }
2265
+ var CONTENT_TYPES = {
2266
+ ".js": "text/javascript",
2267
+ ".mjs": "text/javascript",
2268
+ ".css": "text/css; charset=utf-8",
2269
+ ".json": "application/json",
2270
+ ".arrow": "arraybuffer",
2271
+ ".feather": "arraybuffer",
2272
+ ".wasm": "application/wasm"
2273
+ };
2274
+ async function cwd_static_file_handler(request, response, assets = ["./"], { debug = true } = {}) {
2275
+ let url2 = request.url?.split(/[\?\#]/)[0].replace(/@[\^~]?\d+.[\d\*]*.[\d\*]*/, "") || "/";
2276
+ if (url2 === "/") {
2277
+ url2 = "/index.html";
2278
+ }
2279
+ let extname = path.extname(url2);
2280
+ let contentType = CONTENT_TYPES[extname] || "text/html";
2281
+ try {
2282
+ for (const root of assets) {
2283
+ let filePath = root + url2;
2284
+ try {
2285
+ let content = await fs.readFile(filePath);
2286
+ if (typeof content !== "undefined") {
2287
+ if (debug) {
2288
+ console.log(`200 ${url2}`);
2289
+ }
2290
+ response.writeHead(200, {
2291
+ "Content-Type": contentType,
2292
+ "Access-Control-Allow-Origin": "*"
2293
+ });
2294
+ if (extname === ".arrow" || extname === ".feather") {
2295
+ response.end(content, "utf-8");
2296
+ } else {
2297
+ response.end(content);
2298
+ }
2299
+ return;
2300
+ }
2301
+ } catch (e) {
2302
+ }
2303
+ }
2304
+ if (debug) {
2305
+ console.error(`404 ${url2}`);
2306
+ }
2307
+ response.writeHead(404);
2308
+ response.end("", "utf-8");
2309
+ } catch (error) {
2310
+ if (debug) {
2311
+ console.error(`500 ${url2} ${error}`);
2312
+ }
2313
+ response.writeHead(500);
2314
+ response.end("", "utf-8");
2315
+ }
2316
+ }
2317
+ function buffer_to_arraybuffer(buffer) {
2318
+ if (typeof buffer === "string") {
2319
+ throw new Error("Unknown websocket message: " + buffer);
2320
+ } else if (buffer instanceof ArrayBuffer) {
2321
+ return new Uint8Array(buffer);
2322
+ } else if (buffer instanceof Array) {
2323
+ throw new Error("Unknown websocket message: " + buffer);
2324
+ } else {
2325
+ return new Uint8Array(
2326
+ buffer.buffer.slice(
2327
+ buffer.byteOffset,
2328
+ buffer.byteOffset + buffer.length
2329
+ )
2330
+ );
2331
+ }
2332
+ }
2333
+ var WebSocketServer = class {
2334
+ _server;
2335
+ // stoppable has no type ...
2336
+ _wss;
2337
+ constructor({ port = 8080, assets = ["./"], server = void 0 } = {}) {
2338
+ const perspective_server = typeof server === "undefined" ? SYNC_SERVER : server;
2339
+ port = typeof port === "undefined" ? 8080 : port;
2340
+ this._server = stoppable(
2341
+ http.createServer((x, y) => cwd_static_file_handler(x, y, assets))
2342
+ );
2343
+ this._wss = new HttpWebSocketServer({
2344
+ noServer: true,
2345
+ perMessageDeflate: true
2346
+ });
2347
+ this._wss.on("connection", (ws) => {
2348
+ console.log("... Connecting websocket");
2349
+ const session = perspective_server.make_session(
2350
+ async (proto) => {
2351
+ ws.send(buffer_to_arraybuffer(proto));
2352
+ }
2353
+ );
2354
+ ws.on("message", (proto) => {
2355
+ session.handle_request(buffer_to_arraybuffer(proto));
2356
+ });
2357
+ ws.on("close", () => {
2358
+ session.close();
2359
+ });
2360
+ });
2361
+ this._server.on(
2362
+ "upgrade",
2363
+ (request, socket, head) => {
2364
+ console.log("200 Websocket upgrade");
2365
+ this._wss.handleUpgrade(
2366
+ request,
2367
+ socket,
2368
+ head,
2369
+ (sock) => this._wss.emit("connection", sock, request)
2370
+ );
2371
+ }
2372
+ );
2373
+ this._server.listen(port, () => {
2374
+ console.log(`Listening on ${this._server.address().port}`);
2375
+ });
2376
+ }
2377
+ async close() {
2378
+ await new Promise((x) => this._server.stop(x));
2379
+ }
2380
+ };
2381
+ function get_hosted_table_names() {
2382
+ return SYNC_CLIENT.get_hosted_table_names();
2383
+ }
2384
+ function on_hosted_tables_update(cb) {
2385
+ return SYNC_CLIENT.on_hosted_tables_update(cb);
2386
+ }
2387
+ function remove_hosted_tables_update(id) {
2388
+ return SYNC_CLIENT.remove_hosted_tables_update(id);
2389
+ }
2390
+ function system_info() {
2391
+ return SYNC_CLIENT.system_info();
2392
+ }
2393
+ function on_error(callback) {
2394
+ return SYNC_CLIENT.on_error(callback);
2395
+ }
2396
+ function table(init_data, options) {
2397
+ return SYNC_CLIENT.table(init_data, options);
2398
+ }
2399
+ async function websocket2(url2) {
2400
+ return await websocket(
2401
+ WebSocket,
2402
+ Client,
2403
+ url2
2404
+ );
2405
+ }
2406
+ var perspective_node_default = {
2407
+ table,
2408
+ websocket: websocket2,
2409
+ get_hosted_table_names,
2410
+ on_hosted_tables_update,
2411
+ remove_hosted_tables_update,
2412
+ on_error,
2413
+ system_info,
2414
+ WebSocketServer
2415
+ };
2416
+ export {
2417
+ PerspectiveServer2 as PerspectiveServer,
2418
+ WebSocketServer,
2419
+ cwd_static_file_handler,
2420
+ perspective_node_default as default,
2421
+ get_hosted_table_names,
2422
+ make_client,
2423
+ make_session,
2424
+ on_error,
2425
+ on_hosted_tables_update,
2426
+ remove_hosted_tables_update,
2427
+ system_info,
2428
+ table,
2429
+ websocket2 as websocket
2430
+ };
2431
+ //# sourceMappingURL=perspective.node.js.map