@perspective-dev/client 4.5.2 → 5.1.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 (54) hide show
  1. package/dist/cdn/perspective-server.worker.js +1 -1
  2. package/dist/cdn/perspective-server.worker.js.map +3 -3
  3. package/dist/cdn/perspective.js +2 -2
  4. package/dist/cdn/perspective.js.map +4 -4
  5. package/dist/esm/perspective.browser.d.ts +50 -1
  6. package/dist/esm/perspective.inline.js +2 -2
  7. package/dist/esm/perspective.inline.js.map +4 -4
  8. package/dist/esm/perspective.js +2 -2
  9. package/dist/esm/perspective.js.map +4 -4
  10. package/dist/esm/perspective.node.d.ts +3 -0
  11. package/dist/esm/perspective.node.js +75 -21
  12. package/dist/esm/perspective.node.js.map +3 -3
  13. package/dist/esm/ts-rs/AggSpec.d.ts +8 -0
  14. package/dist/esm/ts-rs/Features.d.ts +59 -0
  15. package/dist/esm/ts-rs/ViewConfig.d.ts +2 -0
  16. package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +9 -0
  17. package/dist/esm/ts-rs/WindowAggregate.d.ts +1 -0
  18. package/dist/esm/ts-rs/WindowSort.d.ts +7 -0
  19. package/dist/esm/ts-rs/WindowSortDir.d.ts +6 -0
  20. package/dist/esm/ts-rs/WindowSpec.d.ts +46 -0
  21. package/dist/esm/ts-rs/Windows.d.ts +10 -0
  22. package/dist/esm/virtual_server.d.ts +8 -34
  23. package/dist/esm/virtual_servers/clickhouse.js +1 -1
  24. package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
  25. package/dist/esm/virtual_servers/duckdb.d.ts +6 -26
  26. package/dist/esm/virtual_servers/duckdb.js +1 -1
  27. package/dist/esm/virtual_servers/duckdb.js.map +3 -3
  28. package/dist/esm/wasm/features.d.ts +4 -0
  29. package/dist/wasm/perspective-js.d.ts +96 -6
  30. package/dist/wasm/perspective-js.js +11 -11
  31. package/dist/wasm/perspective-js.wasm +0 -0
  32. package/dist/wasm/perspective-js.wasm.d.ts +5 -5
  33. package/package.json +1 -1
  34. package/src/rust/lib.rs +6 -0
  35. package/src/rust/typed_array.rs +88 -54
  36. package/src/rust/virtual_server.rs +98 -2
  37. package/src/ts/perspective.browser.ts +176 -20
  38. package/src/ts/perspective.cdn.ts +11 -5
  39. package/src/ts/perspective.node.ts +39 -8
  40. package/src/ts/ts-rs/AggSpec.ts +10 -0
  41. package/src/ts/ts-rs/Features.ts +54 -0
  42. package/src/ts/ts-rs/ViewConfig.ts +2 -1
  43. package/src/ts/ts-rs/ViewConfigUpdate.ts +9 -0
  44. package/src/ts/ts-rs/WindowAggregate.ts +3 -0
  45. package/src/ts/ts-rs/WindowSort.ts +9 -0
  46. package/src/ts/ts-rs/WindowSortDir.ts +8 -0
  47. package/src/ts/ts-rs/WindowSpec.ts +46 -0
  48. package/src/ts/ts-rs/Windows.ts +10 -0
  49. package/src/ts/virtual_server.ts +17 -55
  50. package/src/ts/virtual_servers/clickhouse.ts +45 -2
  51. package/src/ts/virtual_servers/duckdb.ts +46 -4
  52. package/src/ts/wasm/cdn.ts +32 -0
  53. package/src/ts/wasm/engine.ts +7 -5
  54. package/src/ts/wasm/features.ts +31 -0
@@ -17,6 +17,8 @@ import * as psp_virtual from "./virtual_server.ts";
17
17
  import * as wasm_module from "../../dist/wasm/perspective-js.js";
18
18
  import * as api from "./wasm/browser.ts";
19
19
  import { load_wasm_stage_0 } from "./wasm/decompress.ts";
20
+ import { host_supports_memory64 } from "./wasm/features.ts";
21
+ export { host_supports_memory64 } from "./wasm/features.ts";
20
22
 
21
23
  export {
22
24
  GenericSQLVirtualServerModel,
@@ -30,7 +32,40 @@ import {
30
32
  VirtualServer,
31
33
  } from "../../dist/wasm/perspective-js.js";
32
34
 
33
- let GLOBAL_SERVER_WASM: Promise<ArrayBuffer | WebAssembly.Module>;
35
+ /**
36
+ * A single Perspective engine binary, in any form `init_server` accepts.
37
+ * Thunk sources are only invoked if selected — register both bitnesses as
38
+ * `() => fetch(...)` and only the winning binary is ever downloaded.
39
+ */
40
+ export type ServerWasmSource =
41
+ | Uint8Array
42
+ | ArrayBuffer
43
+ | Response
44
+ | WebAssembly.Module
45
+ | Promise<ArrayBuffer | Response | WebAssembly.Module>
46
+ | (() => Promise<ArrayBuffer | Response | WebAssembly.Module>);
47
+
48
+ /**
49
+ * Engine binaries by bitness. Registering `wasm64` is the opt-in for the
50
+ * Memory64 engine (4GB heap ceiling raised to 16GB, at some engine
51
+ * performance cost) — it is selected whenever the host supports Memory64.
52
+ */
53
+ export interface ServerWasmRegistration {
54
+ wasm32?: ServerWasmSource;
55
+ wasm64?: ServerWasmSource;
56
+ }
57
+
58
+ export interface InitServerOptions {
59
+ disable_stage_0?: boolean;
60
+ }
61
+
62
+ interface ServerWasmRegistry extends ServerWasmRegistration {
63
+ sole?: ServerWasmSource;
64
+ disable_stage_0: boolean;
65
+ }
66
+
67
+ let SERVER_REGISTRY: ServerWasmRegistry | undefined;
68
+ let GLOBAL_SERVER_WASM: Promise<ArrayBuffer | WebAssembly.Module> | undefined;
34
69
 
35
70
  export async function createMessageHandler(
36
71
  handler: psp_virtual.VirtualServerHandler,
@@ -38,28 +73,144 @@ export async function createMessageHandler(
38
73
  return psp_virtual.createMessageHandler(await get_client(), handler);
39
74
  }
40
75
 
76
+ function is_wasm_source(
77
+ wasm: ServerWasmSource | ServerWasmRegistration,
78
+ ): wasm is ServerWasmSource {
79
+ return (
80
+ wasm instanceof Uint8Array ||
81
+ wasm instanceof ArrayBuffer ||
82
+ (typeof Response !== "undefined" && wasm instanceof Response) ||
83
+ wasm instanceof Promise ||
84
+ wasm instanceof WebAssembly.Module ||
85
+ typeof wasm === "function"
86
+ );
87
+ }
88
+
89
+ async function materialize_server_wasm(
90
+ source: ServerWasmSource,
91
+ disable_stage_0: boolean,
92
+ ): Promise<ArrayBuffer | WebAssembly.Module> {
93
+ let wasm = typeof source === "function" ? await source() : await source;
94
+ if (wasm instanceof Uint8Array) {
95
+ wasm = wasm.buffer as ArrayBuffer;
96
+ }
97
+
98
+ if (typeof Response !== "undefined" && wasm instanceof Response) {
99
+ if (!wasm.ok) {
100
+ throw new Error(
101
+ `Failed to fetch perspective server wasm (HTTP ${wasm.status} "${wasm.url}")`,
102
+ );
103
+ }
104
+
105
+ if (disable_stage_0) {
106
+ return await wasm.arrayBuffer();
107
+ }
108
+ }
109
+
110
+ if (disable_stage_0) {
111
+ return wasm as ArrayBuffer | WebAssembly.Module;
112
+ }
113
+
114
+ const bytes = await load_wasm_stage_0(wasm);
115
+ return bytes.buffer as ArrayBuffer;
116
+ }
117
+
118
+ async function select_server_wasm(
119
+ registry: ServerWasmRegistry,
120
+ ): Promise<ArrayBuffer | WebAssembly.Module> {
121
+ if (registry.sole !== undefined) {
122
+ return await materialize_server_wasm(
123
+ registry.sole,
124
+ registry.disable_stage_0,
125
+ );
126
+ }
127
+
128
+ // A lone `wasm64` registration is an explicit opt-in and is used as-is
129
+ // regardless of the probe (an unsupporting host fails at instantiation,
130
+ // which is the correct error).
131
+ if (
132
+ registry.wasm64 !== undefined &&
133
+ (registry.wasm32 === undefined || host_supports_memory64())
134
+ ) {
135
+ try {
136
+ return await materialize_server_wasm(
137
+ registry.wasm64,
138
+ registry.disable_stage_0,
139
+ );
140
+ } catch (e) {
141
+ if (registry.wasm32 === undefined) {
142
+ throw e;
143
+ }
144
+
145
+ console.warn(
146
+ "Memory64 perspective server wasm failed to load, falling back to wasm32",
147
+ e,
148
+ );
149
+ }
150
+ }
151
+
152
+ return await materialize_server_wasm(
153
+ registry.wasm32!,
154
+ registry.disable_stage_0,
155
+ );
156
+ }
157
+
158
+ /**
159
+ * Register the Perspective engine ("server") WebAssembly binary that backs
160
+ * `worker()`.
161
+ *
162
+ * The single-argument form registers one binary of either bitness. The
163
+ * object form registers a wasm32 and/or wasm64 (Memory64) binary; the wasm64
164
+ * binary is preferred whenever the host supports Memory64, raising the
165
+ * engine's heap ceiling from 4GB to 16GB (at some engine performance cost —
166
+ * register only `wasm32` to opt out). Sources registered as thunks are only
167
+ * invoked if selected, so the losing binary is never downloaded; if the
168
+ * selected wasm64 source fails to load and a wasm32 source is also
169
+ * registered, selection falls back to wasm32 with a console warning.
170
+ *
171
+ * Selection and download are deferred to the first `worker()` call.
172
+ *
173
+ * # Examples
174
+ *
175
+ * ```javascript
176
+ * perspective.init_server(
177
+ * fetch("perspective-server.wasm"),
178
+ * );
179
+ *
180
+ * perspective.init_server({
181
+ * wasm32: () => fetch("perspective-server.wasm"),
182
+ * wasm64: () => fetch("perspective-server.memory64.wasm"),
183
+ * });
184
+ * ```
185
+ */
41
186
  export function init_server(
42
- wasm:
43
- | Uint8Array
44
- | Promise<ArrayBuffer | Response | WebAssembly.Module>
45
- | ArrayBuffer
46
- | Response
47
- | WebAssembly.Module,
48
- disable_stage_0: boolean = false,
187
+ wasm: ServerWasmSource | ServerWasmRegistration,
188
+ options: boolean | InitServerOptions = false,
49
189
  ) {
50
- if (wasm instanceof Uint8Array) {
51
- GLOBAL_SERVER_WASM = Promise.resolve(wasm.buffer);
52
- } else if (wasm instanceof Response) {
53
- GLOBAL_SERVER_WASM = Promise.resolve(wasm);
54
- } else if (wasm instanceof Promise) {
55
- GLOBAL_SERVER_WASM = wasm;
56
- } else {
57
- GLOBAL_SERVER_WASM = Promise.resolve(wasm);
190
+ const disable_stage_0 =
191
+ typeof options === "boolean" ? options : !!options.disable_stage_0;
192
+
193
+ GLOBAL_SERVER_WASM = undefined;
194
+ if (is_wasm_source(wasm)) {
195
+ SERVER_REGISTRY = { sole: wasm, disable_stage_0 };
196
+ return;
58
197
  }
59
198
 
60
- if (!disable_stage_0) {
61
- GLOBAL_SERVER_WASM = GLOBAL_SERVER_WASM.then((x) =>
62
- load_wasm_stage_0(x).then((x) => x.buffer as ArrayBuffer),
199
+ // `WebAssembly.Module`'s lib type is structurally empty, so TypeScript
200
+ // can't negatively narrow this branch itself.
201
+ const registration = wasm as ServerWasmRegistration;
202
+ if (
203
+ registration.wasm32 !== undefined ||
204
+ registration.wasm64 !== undefined
205
+ ) {
206
+ SERVER_REGISTRY = {
207
+ wasm32: registration.wasm32,
208
+ wasm64: registration.wasm64,
209
+ disable_stage_0,
210
+ };
211
+ } else {
212
+ throw new Error(
213
+ "init_server requires a wasm source or a {wasm32, wasm64} registration",
63
214
  );
64
215
  }
65
216
  }
@@ -175,10 +326,14 @@ export async function getCompiledClientWasm(): Promise<WebAssembly.Module> {
175
326
  }
176
327
 
177
328
  function get_server() {
178
- if (GLOBAL_SERVER_WASM === undefined) {
329
+ if (SERVER_REGISTRY === undefined) {
179
330
  throw new Error("Missing perspective-server.wasm");
180
331
  }
181
332
 
333
+ if (GLOBAL_SERVER_WASM === undefined) {
334
+ GLOBAL_SERVER_WASM = select_server_wasm(SERVER_REGISTRY);
335
+ }
336
+
182
337
  return GLOBAL_SERVER_WASM.then((x) =>
183
338
  x instanceof WebAssembly.Module ? x : x.slice(0),
184
339
  );
@@ -234,6 +389,7 @@ export default {
234
389
  worker,
235
390
  init_client,
236
391
  init_server,
392
+ host_supports_memory64,
237
393
  createMessageHandler,
238
394
  getCompiledClientWasm,
239
395
  GenericSQLVirtualServerModel,
@@ -12,11 +12,17 @@
12
12
 
13
13
  import perspective from "./perspective.browser.ts";
14
14
  export * from "./perspective.browser.ts";
15
+ import { resolve_server_wasm_url } from "./wasm/cdn.ts";
15
16
 
16
- const url = new URL(
17
- "../../../server/dist/wasm/perspective-server.wasm",
18
- import.meta.url,
19
- );
17
+ perspective.init_server({
18
+ wasm32: () => fetch(resolve_server_wasm_url(import.meta.url)),
19
+ wasm64: () =>
20
+ fetch(
21
+ resolve_server_wasm_url(
22
+ import.meta.url,
23
+ "perspective-server.memory64.wasm",
24
+ ),
25
+ ),
26
+ });
20
27
 
21
- perspective.init_server(fetch(url));
22
28
  export default perspective;
@@ -35,7 +35,10 @@ import { createRequire } from "node:module";
35
35
 
36
36
  import * as perspective_client from "../../dist/wasm/perspective-js.js";
37
37
  import { load_wasm_stage_0 } from "./wasm/decompress.js";
38
+ import { host_supports_memory64 } from "./wasm/features.ts";
38
39
  import * as engine from "./wasm/engine.ts";
40
+
41
+ export { host_supports_memory64 } from "./wasm/features.ts";
39
42
  import { compile_perspective } from "./wasm/emscripten_api.ts";
40
43
  import * as psp_websocket from "./websocket.ts";
41
44
  import * as api from "./wasm/browser.ts";
@@ -173,16 +176,43 @@ function make_node_disk_bridge({
173
176
  };
174
177
  }
175
178
 
176
- const SYNC_MODULE = await fs
177
- .readFile(
179
+ async function compile_server_module(wasm_path: string) {
180
+ const buffer = await fs.readFile(wasm_path);
181
+ const bytes = await load_wasm_stage_0(buffer.buffer as ArrayBuffer);
182
+ return await compile_perspective(bytes.buffer as ArrayBuffer, {
183
+ make_disk_bridge: make_node_disk_bridge,
184
+ });
185
+ }
186
+
187
+ async function load_server_module() {
188
+ if (host_supports_memory64()) {
189
+ let wasm_path;
190
+ try {
191
+ wasm_path = resolve(
192
+ "@perspective-dev/server/dist/wasm/perspective-server.memory64.wasm",
193
+ );
194
+ } catch (e) {
195
+ wasm_path = undefined;
196
+ }
197
+
198
+ if (wasm_path !== undefined) {
199
+ try {
200
+ return await compile_server_module(wasm_path);
201
+ } catch (e) {
202
+ console.warn(
203
+ "Memory64 perspective server wasm failed to load, falling back to wasm32",
204
+ e,
205
+ );
206
+ }
207
+ }
208
+ }
209
+
210
+ return await compile_server_module(
178
211
  resolve("@perspective-dev/server/dist/wasm/perspective-server.wasm"),
179
- )
180
- .then((buffer) => load_wasm_stage_0(buffer.buffer as ArrayBuffer))
181
- .then((buffer) =>
182
- compile_perspective(buffer.buffer as ArrayBuffer, {
183
- make_disk_bridge: make_node_disk_bridge,
184
- }),
185
212
  );
213
+ }
214
+
215
+ const SYNC_MODULE = await load_server_module();
186
216
 
187
217
  let SYNC_CLIENT: perspective_client.Client;
188
218
 
@@ -512,6 +542,7 @@ export default {
512
542
  join,
513
543
  websocket,
514
544
  worker,
545
+ host_supports_memory64,
515
546
  get_hosted_table_names,
516
547
  on_hosted_tables_update,
517
548
  remove_hosted_tables_update,
@@ -0,0 +1,10 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { ColumnType } from "./ColumnType.js";
3
+
4
+ /**
5
+ * Specification for an aggregate function.
6
+ *
7
+ * Aggregates can either take no additional arguments ([`AggSpec::Single`])
8
+ * or require column type arguments ([`AggSpec::Multiple`]).
9
+ */
10
+ export type AggSpec = string | [string, Array<ColumnType>];
@@ -0,0 +1,54 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { AggSpec } from "./AggSpec.js";
3
+ import type { ColumnType } from "./ColumnType.js";
4
+ import type { GroupRollupMode } from "./GroupRollupMode.js";
5
+ import type { WindowAggregate } from "./WindowAggregate.js";
6
+
7
+ /**
8
+ * Describes the capabilities supported by a virtual server handler.
9
+ *
10
+ * This struct is returned by
11
+ * [`VirtualServerHandler::get_features`](super::VirtualServerHandler::get_features)
12
+ * to inform clients about which operations are available.
13
+ */
14
+ export type Features = {
15
+ /**
16
+ * Whether group-by aggregation is supported.
17
+ */
18
+ group_by?: boolean,
19
+ /**
20
+ * Which `group_by_rollup_mode` options are supported
21
+ */
22
+ group_rollup_mode?: Array<GroupRollupMode>,
23
+ /**
24
+ * Whether split-by (pivot) operations are supported.
25
+ */
26
+ split_by?: boolean,
27
+ /**
28
+ * Available filter operators per column type.
29
+ */
30
+ filter_ops?: { [key in ColumnType]?: Array<string> },
31
+ /**
32
+ * Available aggregate functions per column type.
33
+ */
34
+ aggregates?: { [key in ColumnType]?: Array<AggSpec> },
35
+ /**
36
+ * Whether sorting is supported.
37
+ */
38
+ sort?: boolean,
39
+ /**
40
+ * Whether computed expressions are supported.
41
+ */
42
+ expressions?: boolean,
43
+ /**
44
+ * Available window aggregates.
45
+ */
46
+ window_aggregates?: { [key in ColumnType]?: Array<WindowAggregate> },
47
+ /**
48
+ * Whether update callbacks are supported.
49
+ */
50
+ on_update?: boolean,
51
+ /**
52
+ * The data store has no reliable natural row order
53
+ */
54
+ unordered?: boolean, };
@@ -5,5 +5,6 @@ import type { Filter } from "./Filter.js";
5
5
  import type { FilterReducer } from "./FilterReducer.js";
6
6
  import type { GroupRollupMode } from "./GroupRollupMode.js";
7
7
  import type { Sort } from "./Sort.js";
8
+ import type { Windows } from "./Windows.js";
8
9
 
9
- export type ViewConfig = { group_by: Array<string>, split_by: Array<string>, sort: Array<Sort>, filter: Array<Filter>, group_rollup_mode: GroupRollupMode, filter_op?: FilterReducer, expressions: Expressions, columns: Array<string | null>, aggregates: { [key in string]?: Aggregate }, group_by_depth?: number | null, };
10
+ export type ViewConfig = { group_by: Array<string>, split_by: Array<string>, sort: Array<Sort>, filter: Array<Filter>, group_rollup_mode: GroupRollupMode, filter_op?: FilterReducer, expressions: Expressions, windows?: Windows, columns: Array<string | null>, aggregates: { [key in string]?: Aggregate }, group_by_depth?: number | null, };
@@ -5,6 +5,7 @@ import type { Filter } from "./Filter.js";
5
5
  import type { FilterReducer } from "./FilterReducer.js";
6
6
  import type { GroupRollupMode } from "./GroupRollupMode.js";
7
7
  import type { Sort } from "./Sort.js";
8
+ import type { Windows } from "./Windows.js";
8
9
 
9
10
  export type ViewConfigUpdate = {
10
11
  /**
@@ -72,6 +73,14 @@ sort?: Array<Sort>,
72
73
  * panel.
73
74
  */
74
75
  expressions?: Expressions,
76
+ /**
77
+ * The `windows` property declares ordered, partitioned rolling
78
+ * computations (moving aggregates, cumulative sums) as _new_ columns
79
+ * keyed by output alias (`{"name": {...spec}}`, symmetric with
80
+ * `expressions`), analogous to SQL window functions. See
81
+ * [`crate::config::WindowSpec`].
82
+ */
83
+ windows?: Windows,
75
84
  /**
76
85
  * Aggregates perform a calculation over an entire column, and are
77
86
  * displayed when one or more [Group By](#group-by) are applied to the
@@ -0,0 +1,3 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+
3
+ export type WindowAggregate = "sum" | "avg" | "count" | "min" | "max" | "stddev" | "var" | "first" | "last" | "lag" | "lead" | "diff" | "rate" | "ema";
@@ -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
+ import type { WindowSortDir } from "./WindowSortDir.js";
3
+
4
+ /**
5
+ * The `Table` column which orders each partition, with its direction -
6
+ * serialized as a two-element array (`["ts", "desc"]`), symmetric with the
7
+ * `ViewConfig`'s `sort` field.
8
+ */
9
+ export type WindowSort = [string, WindowSortDir];
@@ -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
+
3
+ /**
4
+ * A window's order direction. A dedicated two-variant enum rather than
5
+ * [`crate::config::SortDir`] - the column-sort extras (`col asc`, `abs`,
6
+ * `none`) are meaningless inside a window frame and unrepresentable here.
7
+ */
8
+ export type WindowSortDir = "asc" | "desc";
@@ -0,0 +1,46 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { WindowAggregate } from "./WindowAggregate.js";
3
+ import type { WindowSort } from "./WindowSort.js";
4
+
5
+ /**
6
+ * The serialized form of [`WindowSpec`].
7
+ */
8
+ export type WindowSpec = {
9
+ /**
10
+ * The input column - either a real `Table` column or an expression
11
+ * alias from the same `ViewConfig`.
12
+ */
13
+ column: string, aggregate: WindowAggregate,
14
+ /**
15
+ * Columns whose distinct value tuples partition the rows; empty
16
+ * partitions the whole `Table` as one group.
17
+ */
18
+ partition_by?: Array<string>,
19
+ /**
20
+ * The `Table` column which orders each partition, and the direction.
21
+ */
22
+ order_by?: WindowSort | null,
23
+ /**
24
+ * A frame of the `rows` preceding each row, plus the row itself.
25
+ * Mutually exclusive with `range` and `cumulative`.
26
+ */
27
+ rows?: number | null,
28
+ /**
29
+ * A frame of the rows whose `order_by` value lies within `range` of
30
+ * each row's, requiring a numeric or temporal `order_by`. Mutually
31
+ * exclusive with `rows` and `cumulative`.
32
+ */
33
+ range?: number | null,
34
+ /**
35
+ * `true` frames all rows from the partition start through each row.
36
+ * Default can be omitted.
37
+ */
38
+ cumulative?: boolean | null,
39
+ /**
40
+ * Row offset for `lag`/`lead` (default 1).
41
+ */
42
+ offset?: number | null,
43
+ /**
44
+ * Smoothing factor in `(0, 1]` for `ema`.
45
+ */
46
+ alpha?: number | null, };
@@ -0,0 +1,10 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { WindowSpec } from "./WindowSpec.js";
3
+
4
+ /**
5
+ * The window columns of a `ViewConfig`, keyed by output column alias -
6
+ * symmetric with `expressions` (`{"name": {...spec}}`). An alias must not
7
+ * collide with a `Table` column, expression alias, or another window's
8
+ * key.
9
+ */
10
+ export type Windows = { [key in string]?: WindowSpec };
@@ -10,10 +10,6 @@
10
10
  // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
11
  // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
12
 
13
- import { ColumnType } from "./ts-rs/ColumnType.ts";
14
- import { ViewConfig } from "./ts-rs/ViewConfig.ts";
15
- import { ViewWindow } from "./ts-rs/ViewWindow.ts";
16
-
17
13
  import type * as perspective from "../../dist/wasm/perspective-js.js";
18
14
 
19
15
  /**
@@ -26,63 +22,29 @@ import type * as perspective from "../../dist/wasm/perspective-js.js";
26
22
  * - Implementing custom aggregation or transformation logic
27
23
  * - Creating data adapters without copying data into Perspective tables
28
24
  *
25
+ * The `VirtualServerHandler` interface and `Features` struct are declared
26
+ * in Rust alongside the bridge that invokes them (`perspective-js`'s
27
+ * `virtual_server.rs` and `perspective-client`'s `features.rs`
28
+ * respectively) and re-exported here. `ServerFeatures` is a legacy alias
29
+ * for `Features`.
30
+ *
29
31
  * @module virtual_server
30
32
  */
31
33
 
32
- export interface ServerFeatures {
33
- expressions?: boolean;
34
- }
35
-
36
- /**
37
- * Handler interface that you implement to provide custom data sources.
38
- *
39
- * All methods will be called by the VirtualServer when handling protocol
40
- * messages from Perspective clients. Methods can return values directly or
41
- * return Promises for asynchronous operations (e.g., database queries).
42
- */
43
- export interface VirtualServerHandler {
44
- getHostedTables(): string[] | Promise<string[]>;
45
- tableSchema(
46
- tableId: string,
47
- ): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
48
- tableSize(tableId: string): number | Promise<number>;
49
- tableMakeView(
50
- tableId: string,
51
- viewId: string,
52
- config: ViewConfig,
53
- ): void | Promise<void>;
54
- viewDelete(viewId: string): void | Promise<void>;
55
- viewGetData(
56
- viewId: string,
57
- config: ViewConfig,
58
- schema: Record<string, ColumnType>,
59
- viewport: ViewWindow,
60
- dataSlice: perspective.VirtualDataSlice,
61
- ): void | Promise<void>;
62
- viewSchema?(
63
- viewId: string,
64
- config?: ViewConfig,
65
- ): Record<string, ColumnType> | Promise<Record<string, ColumnType>>;
66
- viewSize?(viewId: string): number | Promise<number>;
67
- tableValidateExpression?(
68
- tableId: string,
69
- expression: string,
70
- ): ColumnType | Promise<ColumnType>;
71
- viewGetMinMax?(
72
- viewId: string,
73
- columnName: string,
74
- config: ViewConfig,
75
- ): { min: any; max: any } | Promise<{ min: any; max: any }>;
76
- getFeatures?(): ServerFeatures | Promise<ServerFeatures>;
77
- makeTable?(
78
- tableId: string,
79
- data: string | Uint8Array,
80
- ): void | Promise<void>;
81
- }
34
+ // `Features` must re-export from the wasm `.d.ts` (NOT "./ts-rs/Features.ts")
35
+ // - `perspective.browser.ts` star-exports both this module and the wasm
36
+ // `.d.ts`, and star exports of the same name only merge when they resolve to
37
+ // the same declaration.
38
+ export type {
39
+ VirtualServerHandler,
40
+ VirtualHostedTable,
41
+ Features,
42
+ Features as ServerFeatures,
43
+ } from "../../dist/wasm/perspective-js.js";
82
44
 
83
45
  export function createMessageHandler(
84
46
  mod: typeof perspective,
85
- handler: VirtualServerHandler,
47
+ handler: perspective.VirtualServerHandler,
86
48
  ) {
87
49
  let virtualServer: perspective.VirtualServer;
88
50
  async function postMessage(port: MessagePort, msg: MessageEvent) {