@perspective-dev/client 5.0.0 → 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 (42) hide show
  1. package/dist/cdn/perspective.js +2 -2
  2. package/dist/cdn/perspective.js.map +3 -3
  3. package/dist/esm/perspective.inline.js +2 -2
  4. package/dist/esm/perspective.inline.js.map +3 -3
  5. package/dist/esm/perspective.js +2 -2
  6. package/dist/esm/perspective.js.map +3 -3
  7. package/dist/esm/perspective.node.js +10 -10
  8. package/dist/esm/perspective.node.js.map +2 -2
  9. package/dist/esm/ts-rs/AggSpec.d.ts +8 -0
  10. package/dist/esm/ts-rs/Features.d.ts +59 -0
  11. package/dist/esm/ts-rs/ViewConfig.d.ts +2 -0
  12. package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +9 -0
  13. package/dist/esm/ts-rs/WindowAggregate.d.ts +1 -0
  14. package/dist/esm/ts-rs/WindowSort.d.ts +7 -0
  15. package/dist/esm/ts-rs/WindowSortDir.d.ts +6 -0
  16. package/dist/esm/ts-rs/WindowSpec.d.ts +46 -0
  17. package/dist/esm/ts-rs/Windows.d.ts +10 -0
  18. package/dist/esm/virtual_server.d.ts +8 -34
  19. package/dist/esm/virtual_servers/clickhouse.js +1 -1
  20. package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
  21. package/dist/esm/virtual_servers/duckdb.d.ts +6 -26
  22. package/dist/esm/virtual_servers/duckdb.js +1 -1
  23. package/dist/esm/virtual_servers/duckdb.js.map +3 -3
  24. package/dist/wasm/perspective-js.d.ts +96 -6
  25. package/dist/wasm/perspective-js.js +11 -11
  26. package/dist/wasm/perspective-js.wasm +0 -0
  27. package/dist/wasm/perspective-js.wasm.d.ts +5 -5
  28. package/package.json +1 -1
  29. package/src/rust/lib.rs +6 -0
  30. package/src/rust/virtual_server.rs +98 -2
  31. package/src/ts/ts-rs/AggSpec.ts +10 -0
  32. package/src/ts/ts-rs/Features.ts +54 -0
  33. package/src/ts/ts-rs/ViewConfig.ts +2 -1
  34. package/src/ts/ts-rs/ViewConfigUpdate.ts +9 -0
  35. package/src/ts/ts-rs/WindowAggregate.ts +3 -0
  36. package/src/ts/ts-rs/WindowSort.ts +9 -0
  37. package/src/ts/ts-rs/WindowSortDir.ts +8 -0
  38. package/src/ts/ts-rs/WindowSpec.ts +46 -0
  39. package/src/ts/ts-rs/Windows.ts +10 -0
  40. package/src/ts/virtual_server.ts +17 -55
  41. package/src/ts/virtual_servers/clickhouse.ts +44 -2
  42. package/src/ts/virtual_servers/duckdb.ts +43 -3
@@ -24,7 +24,9 @@
24
24
  import type * as perspective from "@perspective-dev/client";
25
25
  import type { ColumnType } from "@perspective-dev/client/dist/esm/ts-rs/ColumnType.d.ts";
26
26
  import type { ViewConfig } from "@perspective-dev/client/dist/esm/ts-rs/ViewConfig.d.ts";
27
+ import type { ViewConfigUpdate } from "@perspective-dev/client/dist/esm/ts-rs/ViewConfigUpdate.d.ts";
27
28
  import type { ViewWindow } from "@perspective-dev/client/dist/esm/ts-rs/ViewWindow.d.ts";
29
+ import type { WindowAggregate } from "@perspective-dev/client/dist/esm/ts-rs/WindowAggregate.d.ts";
28
30
  import type * as clickhouse from "@clickhouse/client-web";
29
31
 
30
32
  const NUMBER_AGGS = [
@@ -63,6 +65,30 @@ const STRING_AGGS = [
63
65
  "string_agg",
64
66
  ];
65
67
 
68
+ // The window aggregates the SQL translation supports, per source
69
+ // column type (`ema` is recursive - no SQL window equivalent).
70
+ const WINDOW_AGGREGATES: WindowAggregate[] = [
71
+ "sum",
72
+ "avg",
73
+ "count",
74
+ "min",
75
+ "max",
76
+ "stddev",
77
+ "var",
78
+ "lag",
79
+ "lead",
80
+ "diff",
81
+ "rate",
82
+ ];
83
+
84
+ const WINDOW_AGGREGATES_ANY: WindowAggregate[] = [
85
+ "count",
86
+ "min",
87
+ "max",
88
+ "lag",
89
+ "lead",
90
+ ];
91
+
66
92
  const FILTER_OPS = [
67
93
  "==",
68
94
  "!=",
@@ -218,12 +244,24 @@ export class ClickhouseHandler implements perspective.VirtualServerHandler {
218
244
  });
219
245
  }
220
246
 
221
- getFeatures() {
247
+ getFeatures(): perspective.Features {
222
248
  return {
223
249
  group_by: true,
224
250
  split_by: false,
225
251
  sort: true,
226
252
  expressions: true,
253
+ // ClickHouse has no stable `rowid`, so natural-order windows
254
+ // are unsupported.
255
+ unordered: true,
256
+ window_aggregates: {
257
+ // `ema` is recursive and has no SQL window translation.
258
+ integer: WINDOW_AGGREGATES,
259
+ float: WINDOW_AGGREGATES,
260
+ string: WINDOW_AGGREGATES_ANY,
261
+ date: WINDOW_AGGREGATES_ANY,
262
+ datetime: WINDOW_AGGREGATES_ANY,
263
+ boolean: WINDOW_AGGREGATES_ANY,
264
+ },
227
265
  group_rollup_mode: ["rollup", "flat", "total"],
228
266
  filter_ops: {
229
267
  integer: FILTER_OPS,
@@ -284,7 +322,11 @@ export class ClickhouseHandler implements perspective.VirtualServerHandler {
284
322
  return Number(results[0]["COUNT()"]);
285
323
  }
286
324
 
287
- async tableMakeView(tableId: string, viewId: string, config: ViewConfig) {
325
+ async tableMakeView(
326
+ tableId: string,
327
+ viewId: string,
328
+ config: ViewConfigUpdate,
329
+ ) {
288
330
  const query = this.sqlBuilder.tableMakeView(tableId, viewId, config);
289
331
  await runQuery(this.db, query, { execute: true });
290
332
  }
@@ -24,7 +24,10 @@
24
24
  import type * as perspective from "@perspective-dev/client";
25
25
  import type { ColumnType } from "@perspective-dev/client/dist/esm/ts-rs/ColumnType.d.ts";
26
26
  import type { ViewConfig } from "@perspective-dev/client/dist/esm/ts-rs/ViewConfig.d.ts";
27
+ import type { ViewConfigUpdate } from "@perspective-dev/client/dist/esm/ts-rs/ViewConfigUpdate.d.ts";
27
28
  import type { ViewWindow } from "@perspective-dev/client/dist/esm/ts-rs/ViewWindow.d.ts";
29
+ import type { WindowAggregate } from "@perspective-dev/client/dist/esm/ts-rs/WindowAggregate.d.ts";
30
+ import type { Scalar } from "@perspective-dev/client/dist/esm/ts-rs/Scalar.d.ts";
28
31
  import type * as duckdb from "@duckdb/duckdb-wasm";
29
32
 
30
33
  const NUMBER_AGGS = [
@@ -63,6 +66,30 @@ const STRING_AGGS = [
63
66
  "string_agg",
64
67
  ];
65
68
 
69
+ // The window aggregates the SQL translation supports, per source
70
+ // column type (`ema` is recursive - no SQL window equivalent).
71
+ const WINDOW_AGGREGATES: WindowAggregate[] = [
72
+ "sum",
73
+ "avg",
74
+ "count",
75
+ "min",
76
+ "max",
77
+ "stddev",
78
+ "var",
79
+ "lag",
80
+ "lead",
81
+ "diff",
82
+ "rate",
83
+ ];
84
+
85
+ const WINDOW_AGGREGATES_ANY: WindowAggregate[] = [
86
+ "count",
87
+ "min",
88
+ "max",
89
+ "lag",
90
+ "lead",
91
+ ];
92
+
66
93
  const FILTER_OPS = [
67
94
  "==",
68
95
  "!=",
@@ -189,12 +216,21 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
189
216
  });
190
217
  }
191
218
 
192
- getFeatures() {
219
+ getFeatures(): perspective.Features {
193
220
  return {
194
221
  group_by: true,
195
222
  split_by: true,
196
223
  sort: true,
197
224
  expressions: true,
225
+ window_aggregates: {
226
+ // `ema` is recursive and has no SQL window translation.
227
+ integer: WINDOW_AGGREGATES,
228
+ float: WINDOW_AGGREGATES,
229
+ string: WINDOW_AGGREGATES_ANY,
230
+ date: WINDOW_AGGREGATES_ANY,
231
+ datetime: WINDOW_AGGREGATES_ANY,
232
+ boolean: WINDOW_AGGREGATES_ANY,
233
+ },
198
234
  group_rollup_mode: ["rollup", "flat", "total"],
199
235
  filter_ops: {
200
236
  integer: FILTER_OPS,
@@ -256,7 +292,11 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
256
292
  return Number(results[0].toJSON()["count_star()"]);
257
293
  }
258
294
 
259
- async tableMakeView(tableId: string, viewId: string, config: ViewConfig) {
295
+ async tableMakeView(
296
+ tableId: string,
297
+ viewId: string,
298
+ config: ViewConfigUpdate,
299
+ ) {
260
300
  const query = this.sqlBuilder.tableMakeView(tableId, viewId, config);
261
301
  await runQuery(this.db, query);
262
302
  }
@@ -288,7 +328,7 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
288
328
  let [min, max] = Object.values(row);
289
329
  if (typeof min === "bigint") min = Number(min);
290
330
  if (typeof max === "bigint") max = Number(max);
291
- return { min: min ?? null, max: max ?? null };
331
+ return { min: (min ?? null) as Scalar, max: (max ?? null) as Scalar };
292
332
  }
293
333
 
294
334
  async viewGetData(