@perspective-dev/client 5.1.0 → 5.3.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 (41) 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 +36 -22
  8. package/dist/esm/perspective.node.js.map +2 -2
  9. package/dist/esm/ts-rs/Features.d.ts +10 -3
  10. package/dist/esm/ts-rs/ListFlatten.d.ts +1 -0
  11. package/dist/esm/ts-rs/SplitRollupMode.d.ts +9 -0
  12. package/dist/esm/ts-rs/TableInitOptions.d.ts +9 -0
  13. package/dist/esm/ts-rs/ViewConfig.d.ts +2 -0
  14. package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +15 -0
  15. package/dist/esm/ts-rs/WindowAggSpec.d.ts +25 -0
  16. package/dist/esm/ts-rs/WindowSpec.d.ts +3 -2
  17. package/dist/esm/virtual_servers/clickhouse.js +1 -1
  18. package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
  19. package/dist/esm/virtual_servers/duckdb.js +1 -1
  20. package/dist/esm/virtual_servers/duckdb.js.map +3 -3
  21. package/dist/wasm/perspective-js.d.ts +9 -8
  22. package/dist/wasm/perspective-js.js +38 -24
  23. package/dist/wasm/perspective-js.wasm +0 -0
  24. package/dist/wasm/perspective-js.wasm.d.ts +7 -6
  25. package/package.json +1 -1
  26. package/src/rust/generic_sql_model.rs +8 -1
  27. package/src/rust/lib.rs +1 -1
  28. package/src/rust/typed_array.rs +22 -3
  29. package/src/rust/utils/futures.rs +95 -8
  30. package/src/ts/ts-rs/Features.ts +10 -3
  31. package/src/ts/ts-rs/ListFlatten.ts +3 -0
  32. package/src/ts/ts-rs/SplitRollupMode.ts +11 -0
  33. package/src/ts/ts-rs/TableInitOptions.ts +10 -1
  34. package/src/ts/ts-rs/ViewConfig.ts +2 -1
  35. package/src/ts/ts-rs/ViewConfigUpdate.ts +15 -1
  36. package/src/ts/ts-rs/WindowAggSpec.ts +25 -0
  37. package/src/ts/ts-rs/WindowSpec.ts +3 -2
  38. package/src/ts/virtual_servers/clickhouse.ts +67 -24
  39. package/src/ts/virtual_servers/duckdb.ts +135 -50
  40. package/dist/esm/ts-rs/WindowAggregate.d.ts +0 -1
  41. package/src/ts/ts-rs/WindowAggregate.ts +0 -3
@@ -449,16 +449,17 @@ export class GenericSQLVirtualServerModel {
449
449
  * @param {string} table_id
450
450
  * @param {string} view_id
451
451
  * @param {any} config
452
+ * @param {any} schema
452
453
  * @returns {string}
453
454
  */
454
- tableMakeView(table_id, view_id, config) {
455
+ tableMakeView(table_id, view_id, config, schema) {
455
456
  try {
456
457
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
457
458
  const ptr0 = passStringToWasm0(table_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
458
459
  const len0 = WASM_VECTOR_LEN;
459
460
  const ptr1 = passStringToWasm0(view_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
460
461
  const len1 = WASM_VECTOR_LEN;
461
- wasm.genericsqlvirtualservermodel_tableMakeView(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(config));
462
+ wasm.genericsqlvirtualservermodel_tableMakeView(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(config), addHeapObject(schema));
462
463
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
463
464
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
464
465
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -2016,7 +2017,7 @@ function __wbg_get_imports() {
2016
2017
  const a = state0.a;
2017
2018
  state0.a = 0;
2018
2019
  try {
2019
- return __wasm_bindgen_func_elem_11388(a, state0.b, arg0, arg1);
2020
+ return __wasm_bindgen_func_elem_12453(a, state0.b, arg0, arg1);
2020
2021
  } finally {
2021
2022
  state0.a = a;
2022
2023
  }
@@ -2091,6 +2092,10 @@ function __wbg_get_imports() {
2091
2092
  const ret = Promise.resolve(getObject(arg0));
2092
2093
  return addHeapObject(ret);
2093
2094
  },
2095
+ __wbg_run_6b188d9db01ef98f: function() { return handleError(function (arg0, arg1) {
2096
+ const ret = getObject(arg0).run(getObject(arg1));
2097
+ return addHeapObject(ret);
2098
+ }, arguments); },
2094
2099
  __wbg_set_1eb0999cf5d27fc8: function(arg0, arg1, arg2) {
2095
2100
  const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
2096
2101
  return addHeapObject(ret);
@@ -2174,69 +2179,74 @@ function __wbg_get_imports() {
2174
2179
  console.warn(getObject(arg0));
2175
2180
  },
2176
2181
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
2177
- // Cast intrinsic for `Closure(Closure { dtor_idx: 12, function: Function { arguments: [], shim_idx: 31, ret: NamedExternref("Promise<any>"), inner_ret: Some(NamedExternref("Promise<any>")) }, mutable: false }) -> Externref`.
2178
- const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1125, __wasm_bindgen_func_elem_1843);
2182
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 12, function: Function { arguments: [], shim_idx: 32, ret: NamedExternref("Promise<any>"), inner_ret: Some(NamedExternref("Promise<any>")) }, mutable: false }) -> Externref`.
2183
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1164, __wasm_bindgen_func_elem_1899);
2179
2184
  return addHeapObject(ret);
2180
2185
  },
2181
2186
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
2182
- // Cast intrinsic for `Closure(Closure { dtor_idx: 575, function: Function { arguments: [Externref], shim_idx: 576, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2183
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4193, __wasm_bindgen_func_elem_4210);
2187
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 12, function: Function { arguments: [], shim_idx: 33, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
2188
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1164, __wasm_bindgen_func_elem_1900);
2184
2189
  return addHeapObject(ret);
2185
2190
  },
2186
- __wbindgen_cast_0000000000000003: function(arg0) {
2191
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
2192
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 591, function: Function { arguments: [Externref], shim_idx: 592, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2193
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4285, __wasm_bindgen_func_elem_4302);
2194
+ return addHeapObject(ret);
2195
+ },
2196
+ __wbindgen_cast_0000000000000004: function(arg0) {
2187
2197
  // Cast intrinsic for `F64 -> Externref`.
2188
2198
  const ret = arg0;
2189
2199
  return addHeapObject(ret);
2190
2200
  },
2191
- __wbindgen_cast_0000000000000004: function(arg0) {
2201
+ __wbindgen_cast_0000000000000005: function(arg0) {
2192
2202
  // Cast intrinsic for `I64 -> Externref`.
2193
2203
  const ret = arg0;
2194
2204
  return addHeapObject(ret);
2195
2205
  },
2196
- __wbindgen_cast_0000000000000005: function(arg0, arg1) {
2206
+ __wbindgen_cast_0000000000000006: function(arg0, arg1) {
2197
2207
  var v0 = getCachedStringFromWasm0(arg0, arg1);
2198
2208
  // Cast intrinsic for `Ref(CachedString) -> Externref`.
2199
2209
  const ret = v0;
2200
2210
  return addHeapObject(ret);
2201
2211
  },
2202
- __wbindgen_cast_0000000000000006: function(arg0, arg1) {
2212
+ __wbindgen_cast_0000000000000007: function(arg0, arg1) {
2203
2213
  // Cast intrinsic for `Ref(Slice(F32)) -> NamedExternref("Float32Array")`.
2204
2214
  const ret = getArrayF32FromWasm0(arg0, arg1);
2205
2215
  return addHeapObject(ret);
2206
2216
  },
2207
- __wbindgen_cast_0000000000000007: function(arg0, arg1) {
2217
+ __wbindgen_cast_0000000000000008: function(arg0, arg1) {
2208
2218
  // Cast intrinsic for `Ref(Slice(F64)) -> NamedExternref("Float64Array")`.
2209
2219
  const ret = getArrayF64FromWasm0(arg0, arg1);
2210
2220
  return addHeapObject(ret);
2211
2221
  },
2212
- __wbindgen_cast_0000000000000008: function(arg0, arg1) {
2222
+ __wbindgen_cast_0000000000000009: function(arg0, arg1) {
2213
2223
  // Cast intrinsic for `Ref(Slice(I32)) -> NamedExternref("Int32Array")`.
2214
2224
  const ret = getArrayI32FromWasm0(arg0, arg1);
2215
2225
  return addHeapObject(ret);
2216
2226
  },
2217
- __wbindgen_cast_0000000000000009: function(arg0, arg1) {
2227
+ __wbindgen_cast_000000000000000a: function(arg0, arg1) {
2218
2228
  // Cast intrinsic for `Ref(Slice(U32)) -> NamedExternref("Uint32Array")`.
2219
2229
  const ret = getArrayU32FromWasm0(arg0, arg1);
2220
2230
  return addHeapObject(ret);
2221
2231
  },
2222
- __wbindgen_cast_000000000000000a: function(arg0, arg1) {
2232
+ __wbindgen_cast_000000000000000b: function(arg0, arg1) {
2223
2233
  // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
2224
2234
  const ret = getArrayU8FromWasm0(arg0, arg1);
2225
2235
  return addHeapObject(ret);
2226
2236
  },
2227
- __wbindgen_cast_000000000000000b: function(arg0) {
2237
+ __wbindgen_cast_000000000000000c: function(arg0) {
2228
2238
  // Cast intrinsic for `U64 -> Externref`.
2229
2239
  const ret = BigInt.asUintN(64, arg0);
2230
2240
  return addHeapObject(ret);
2231
2241
  },
2232
- __wbindgen_cast_000000000000000c: function(arg0, arg1) {
2242
+ __wbindgen_cast_000000000000000d: function(arg0, arg1) {
2233
2243
  var v0 = getArrayJsValueFromWasm0(arg0, arg1).slice();
2234
2244
  wasm.__wbindgen_export4(arg0, arg1 * 4, 4);
2235
2245
  // Cast intrinsic for `Vector(NamedExternref("string")) -> Externref`.
2236
2246
  const ret = v0;
2237
2247
  return addHeapObject(ret);
2238
2248
  },
2239
- __wbindgen_cast_000000000000000d: function(arg0, arg1) {
2249
+ __wbindgen_cast_000000000000000e: function(arg0, arg1) {
2240
2250
  var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
2241
2251
  wasm.__wbindgen_export4(arg0, arg1 * 1, 1);
2242
2252
  // Cast intrinsic for `Vector(U8) -> Externref`.
@@ -2257,17 +2267,21 @@ function __wbg_get_imports() {
2257
2267
  };
2258
2268
  }
2259
2269
 
2260
- function __wasm_bindgen_func_elem_1843(arg0, arg1) {
2261
- const ret = wasm.__wasm_bindgen_func_elem_1843(arg0, arg1);
2270
+ function __wasm_bindgen_func_elem_1900(arg0, arg1) {
2271
+ wasm.__wasm_bindgen_func_elem_1900(arg0, arg1);
2272
+ }
2273
+
2274
+ function __wasm_bindgen_func_elem_1899(arg0, arg1) {
2275
+ const ret = wasm.__wasm_bindgen_func_elem_1899(arg0, arg1);
2262
2276
  return takeObject(ret);
2263
2277
  }
2264
2278
 
2265
- function __wasm_bindgen_func_elem_4210(arg0, arg1, arg2) {
2266
- wasm.__wasm_bindgen_func_elem_4210(arg0, arg1, addHeapObject(arg2));
2279
+ function __wasm_bindgen_func_elem_4302(arg0, arg1, arg2) {
2280
+ wasm.__wasm_bindgen_func_elem_4302(arg0, arg1, addHeapObject(arg2));
2267
2281
  }
2268
2282
 
2269
- function __wasm_bindgen_func_elem_11388(arg0, arg1, arg2, arg3) {
2270
- wasm.__wasm_bindgen_func_elem_11388(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2283
+ function __wasm_bindgen_func_elem_12453(arg0, arg1, arg2, arg3) {
2284
+ wasm.__wasm_bindgen_func_elem_12453(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2271
2285
  }
2272
2286
 
2273
2287
  const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -25,7 +25,7 @@ export const client_table: (a: number, b: number, c: number) => number;
25
25
  export const client_terminate: (a: number, b: number) => void;
26
26
  export const genericsqlvirtualservermodel_getHostedTables: (a: number, b: number) => void;
27
27
  export const genericsqlvirtualservermodel_new: (a: number, b: number) => void;
28
- export const genericsqlvirtualservermodel_tableMakeView: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
28
+ export const genericsqlvirtualservermodel_tableMakeView: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
29
29
  export const genericsqlvirtualservermodel_tableSchema: (a: number, b: number, c: number, d: number) => void;
30
30
  export const genericsqlvirtualservermodel_tableSize: (a: number, b: number, c: number, d: number) => void;
31
31
  export const genericsqlvirtualservermodel_tableValidateExpression: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
@@ -93,11 +93,12 @@ export const virtualdataslice_setIntegerCol: (a: number, b: number, c: number, d
93
93
  export const virtualdataslice_setStringCol: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
94
94
  export const virtualserver_handleRequest: (a: number, b: number, c: number) => number;
95
95
  export const virtualserver_new: (a: number, b: number) => void;
96
- export const __wasm_bindgen_func_elem_1125: (a: number, b: number) => void;
97
- export const __wasm_bindgen_func_elem_4193: (a: number, b: number) => void;
98
- export const __wasm_bindgen_func_elem_11388: (a: number, b: number, c: number, d: number) => void;
99
- export const __wasm_bindgen_func_elem_4210: (a: number, b: number, c: number) => void;
100
- export const __wasm_bindgen_func_elem_1843: (a: number, b: number) => number;
96
+ export const __wasm_bindgen_func_elem_1164: (a: number, b: number) => void;
97
+ export const __wasm_bindgen_func_elem_4285: (a: number, b: number) => void;
98
+ export const __wasm_bindgen_func_elem_12453: (a: number, b: number, c: number, d: number) => void;
99
+ export const __wasm_bindgen_func_elem_4302: (a: number, b: number, c: number) => void;
100
+ export const __wasm_bindgen_func_elem_1899: (a: number, b: number) => number;
101
+ export const __wasm_bindgen_func_elem_1900: (a: number, b: number) => void;
101
102
  export const __wbindgen_export: (a: number, b: number) => number;
102
103
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
103
104
  export const __wbindgen_export3: (a: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perspective-dev/client",
3
- "version": "5.1.0",
3
+ "version": "5.3.0",
4
4
  "description": "Client for Perspective, a high-performance WASM engine with reactive Tables, Views, and joins.",
5
5
  "keywords": [
6
6
  "perspective",
@@ -111,12 +111,19 @@ impl GenericSQLVirtualServerModel {
111
111
  table_id: &str,
112
112
  view_id: &str,
113
113
  config: JsValue,
114
+ schema: JsValue,
114
115
  ) -> Result<String, JsValue> {
115
116
  let config: ViewConfig = serde_wasm_bindgen::from_value(config)
116
117
  .map_err(|e| JsValue::from_str(&e.to_string()))?;
117
118
 
119
+ let schema = if schema.is_undefined() || schema.is_null() {
120
+ IndexMap::new()
121
+ } else {
122
+ self.parse_schema(schema)?
123
+ };
124
+
118
125
  self.inner
119
- .table_make_view(table_id, view_id, &config)
126
+ .table_make_view(table_id, view_id, &config, &schema)
120
127
  .map_err(|e| JsValue::from_str(&e.to_string()))
121
128
  }
122
129
 
package/src/rust/lib.rs CHANGED
@@ -66,7 +66,7 @@ export type * from "../../src/ts/ts-rs/JoinType.ts";
66
66
  export type * from "../../src/ts/ts-rs/TypedArrayWindow.ts";
67
67
  export type * from "../../src/ts/ts-rs/Features.ts";
68
68
  export type * from "../../src/ts/ts-rs/AggSpec.ts";
69
- export type * from "../../src/ts/ts-rs/WindowAggregate.ts";
69
+ export type * from "../../src/ts/ts-rs/WindowAggSpec.ts";
70
70
 
71
71
  import type {ColumnWindow} from "../../src/ts/ts-rs/ColumnWindow.d.ts";
72
72
  import type {ColumnType} from "../../src/ts/ts-rs/ColumnType.d.ts";
@@ -14,7 +14,7 @@ use std::io::Cursor;
14
14
 
15
15
  use arrow_array::cast::AsArray;
16
16
  use arrow_array::types::*;
17
- use arrow_array::{Array as _, ArrowPrimitiveType, PrimitiveArray};
17
+ use arrow_array::{Array as _, ArrowPrimitiveType, DictionaryArray, PrimitiveArray, StringArray};
18
18
  use arrow_ipc::reader::StreamReader;
19
19
  use arrow_schema::{DataType, TimeUnit};
20
20
  use js_sys::{Array, Function, JsString, Uint8Array};
@@ -219,13 +219,32 @@ pub(crate) async fn decode_and_call(
219
219
  js_dicts.set(col_idx as u32, JsValue::NULL);
220
220
  },
221
221
  DataType::Dictionary(..) => {
222
- let dict = col.as_dictionary::<Int32Type>();
222
+ let dict = col
223
+ .as_any()
224
+ .downcast_ref::<DictionaryArray<Int32Type>>()
225
+ .ok_or_else(|| {
226
+ JsValue::from_str(&format!(
227
+ "Unsupported dictionary key type for typed array: {}",
228
+ col.data_type()
229
+ ))
230
+ })?;
231
+
223
232
  let keys = dict.keys();
224
233
  zero_invalid_slots(keys);
225
234
  let arr = unsafe { js_sys::Int32Array::view(keys.values().as_ref()) };
226
235
  js_values.set(col_idx as u32, arr.into());
227
236
 
228
- let values = dict.values().as_string::<i32>();
237
+ let values = dict
238
+ .values()
239
+ .as_any()
240
+ .downcast_ref::<StringArray>()
241
+ .ok_or_else(|| {
242
+ JsValue::from_str(&format!(
243
+ "Unsupported dictionary value type for typed array: {}",
244
+ dict.values().data_type()
245
+ ))
246
+ })?;
247
+
229
248
  let js_dict = Array::new_with_length(values.len() as u32);
230
249
  for i in 0..values.len() {
231
250
  js_dict.set(i as u32, JsValue::from_str(values.value(i)));
@@ -10,6 +10,7 @@
10
10
  // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
11
  // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
12
 
13
+ use std::cell::RefCell;
13
14
  use std::future::Future;
14
15
  use std::pin::Pin;
15
16
 
@@ -25,13 +26,64 @@ use wasm_bindgen_futures::{JsFuture, future_to_promise};
25
26
 
26
27
  use super::errors::*;
27
28
 
29
+ #[wasm_bindgen]
30
+ extern "C" {
31
+ /// A DevTools task handle from `console.createTask` — Chrome's Async
32
+ /// Stack Tagging API. Bound manually, as `js_sys` does not expose it.
33
+ type JsConsoleTask;
34
+
35
+ #[wasm_bindgen(method, catch)]
36
+ fn run(this: &JsConsoleTask, f: &js_sys::Function) -> Result<JsValue, JsValue>;
37
+ }
38
+
39
+ #[wasm_bindgen]
40
+ extern "C" {
41
+ #[wasm_bindgen(variadic, js_namespace = console , js_name = createTask, catch)]
42
+ pub fn createTask(name: JsValue) -> Result<JsValue, JsValue>;
43
+ }
44
+
45
+ /// Create a DevTools task, or `None` where the API is unavailable (it is
46
+ /// Chrome-only).
47
+ fn create_task(name: &str) -> Option<JsConsoleTask> {
48
+ thread_local! {
49
+ static CREATE_TASK: Option<(JsValue, js_sys::Function)> = (|| {
50
+ let global = js_sys::global();
51
+ let console = js_sys::Reflect::get(&global, &"console".into()).ok()?;
52
+ let create = js_sys::Reflect::get(&console, &"createTask".into()).ok()?;
53
+ Some((console, create.dyn_into().ok()?))
54
+ })();
55
+ }
56
+
57
+ CREATE_TASK.with(|x| {
58
+ let (console, create) = x.as_ref()?;
59
+ Some(create.call1(console, &name.into()).ok()?.unchecked_into())
60
+ })
61
+ }
62
+
63
+ thread_local! {
64
+ /// Scoped poll thunks for [`TRAMPOLINE`], a stack because tagged polls
65
+ /// nest (an `ApiFuture` awaiting another `ApiFuture`).
66
+ static POLL_STACK: RefCell<Vec<*mut (dyn FnMut() + 'static)>> = RefCell::new(Vec::new());
67
+
68
+ /// The single reusable JS closure handed to [`JsConsoleTask::run`].
69
+ static TRAMPOLINE: Closure<dyn Fn()> = Closure::new(|| {
70
+ let thunk = POLL_STACK.with(|x| x.borrow().last().copied());
71
+ if let Some(thunk) = thunk {
72
+ unsafe { (*thunk)() }
73
+ }
74
+ });
75
+ }
76
+
28
77
  /// A newtype wrapper for a `Future` trait object which supports being
29
78
  /// marshalled to a `JsPromise`.
30
79
  ///
31
80
  /// This avoids implementing an API which requires type casting to
32
81
  /// and from `JsValue` and the associated loss of type safety.
33
82
  #[must_use]
34
- pub struct ApiFuture<T>(Pin<Box<dyn Future<Output = ApiResult<T>>>>)
83
+ pub struct ApiFuture<T>(
84
+ Pin<Box<dyn Future<Output = ApiResult<T>>>>,
85
+ Option<JsConsoleTask>,
86
+ )
35
87
  where
36
88
  Result<T, JsValue>: IntoJsResult + 'static;
37
89
 
@@ -44,13 +96,17 @@ where
44
96
  /// `Promise`, either explicitly or implcitly (when exposed via
45
97
  /// `wasm_bindgen`).
46
98
  pub fn new<U: Future<Output = ApiResult<T>> + 'static>(x: U) -> Self {
47
- Self(Box::pin(x))
99
+ Self::new_named("perspective", x)
100
+ }
101
+
102
+ /// [`Self::new`] with an explicit DevTools task label, shown at the async
103
+ /// gap in tagged stack traces.
104
+ pub fn new_named<U: Future<Output = ApiResult<T>> + 'static>(name: &str, x: U) -> Self {
105
+ Self(Box::pin(x), create_task(name))
48
106
  }
49
107
 
50
108
  pub fn new_throttled<U: Future<Output = ApiResult<T>> + 'static>(x: U) -> ApiFuture<()> {
51
- ApiFuture::<()>(Box::pin(
52
- async move { x.await.ignore_view_delete().map(|_| ()) },
53
- ))
109
+ ApiFuture::<()>::new(async move { x.await.ignore_view_delete().map(|_| ()) })
54
110
  }
55
111
  }
56
112
 
@@ -65,6 +121,11 @@ where
65
121
  drop(js_sys::Promise::from(Self::new(x)))
66
122
  }
67
123
 
124
+ /// [`Self::spawn`] with an explicit DevTools task label.
125
+ pub fn spawn_named<U: Future<Output = ApiResult<T>> + 'static>(name: &str, x: U) {
126
+ drop(js_sys::Promise::from(Self::new_named(name, x)))
127
+ }
128
+
68
129
  pub fn spawn_throttled<U: Future<Output = ApiResult<T>> + 'static>(x: U) {
69
130
  drop(js_sys::Promise::from(Self::new_throttled(x)))
70
131
  }
@@ -94,7 +155,8 @@ where
94
155
  Result<T, JsValue>: IntoJsResult + 'static,
95
156
  {
96
157
  fn from(fut: ApiFuture<T>) -> Self {
97
- future_to_promise(async move { Ok(fut.0.await?).into_js_result() })
158
+ // Await `fut` NOT `fut.0` or the stack frame is lost in Chrome.
159
+ future_to_promise(async move { Ok(fut.await?).into_js_result() })
98
160
  }
99
161
  }
100
162
 
@@ -145,8 +207,33 @@ where
145
207
  self: Pin<&mut Self>,
146
208
  cx: &mut std::task::Context<'_>,
147
209
  ) -> std::task::Poll<Self::Output> {
148
- let mut fut = unsafe { self.map_unchecked_mut(|s| &mut s.0) };
149
- fut.as_mut().poll(cx)
210
+ // SAFETY: structural projection only — neither field is moved, and
211
+ // the inner future stays behind its own `Pin<Box<_>>`.
212
+ let Self(inner, task) = unsafe { self.get_unchecked_mut() };
213
+ let Some(task) = task else {
214
+ return inner.as_mut().poll(cx);
215
+ };
216
+
217
+ let mut result = None;
218
+ let mut thunk = || result = Some(inner.as_mut().poll(cx));
219
+
220
+ // SAFETY: the lifetime is erased for storage only. The entry is
221
+ // pushed and popped within this scope, and `run` invokes the
222
+ // trampoline synchronously, so the pointer never outlives `thunk`.
223
+ let short: *mut (dyn FnMut() + '_) = &mut thunk;
224
+ let long: *mut (dyn FnMut() + 'static) = unsafe { std::mem::transmute(short) };
225
+ POLL_STACK.with(|x| x.borrow_mut().push(long));
226
+ let _ = TRAMPOLINE.with(|x| task.run(x.as_ref().unchecked_ref()));
227
+ POLL_STACK.with(|x| x.borrow_mut().pop());
228
+
229
+ #[allow(clippy::drop_non_drop)]
230
+ drop(thunk);
231
+
232
+ match result {
233
+ Some(result) => result,
234
+ // `run` threw without invoking the trampoline.
235
+ None => inner.as_mut().poll(cx),
236
+ }
150
237
  }
151
238
  }
152
239
 
@@ -2,7 +2,8 @@
2
2
  import type { AggSpec } from "./AggSpec.js";
3
3
  import type { ColumnType } from "./ColumnType.js";
4
4
  import type { GroupRollupMode } from "./GroupRollupMode.js";
5
- import type { WindowAggregate } from "./WindowAggregate.js";
5
+ import type { SplitRollupMode } from "./SplitRollupMode.js";
6
+ import type { WindowAggSpec } from "./WindowAggSpec.js";
6
7
 
7
8
  /**
8
9
  * Describes the capabilities supported by a virtual server handler.
@@ -24,6 +25,12 @@ group_rollup_mode?: Array<GroupRollupMode>,
24
25
  * Whether split-by (pivot) operations are supported.
25
26
  */
26
27
  split_by?: boolean,
28
+ /**
29
+ * Which `split_rollup_mode` options are supported. Empty (the default)
30
+ * means `["flat"]` - a server must opt in to `"rollup"` explicitly, as
31
+ * it requires emitting subtotal and grand-total column groups.
32
+ */
33
+ split_rollup_mode?: Array<SplitRollupMode>,
27
34
  /**
28
35
  * Available filter operators per column type.
29
36
  */
@@ -41,9 +48,9 @@ sort?: boolean,
41
48
  */
42
49
  expressions?: boolean,
43
50
  /**
44
- * Available window aggregates.
51
+ * Available window aggregates per column type.
45
52
  */
46
- window_aggregates?: { [key in ColumnType]?: Array<WindowAggregate> },
53
+ window_aggregates?: { [key in ColumnType]?: Array<WindowAggSpec> },
47
54
  /**
48
55
  * Whether update callbacks are supported.
49
56
  */
@@ -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 ListFlatten = "zip" | "cartesian" | "stringify";
@@ -0,0 +1,11 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+
3
+ /**
4
+ * The `split_by` corollary to [`GroupRollupMode`]. `Flat` (the default,
5
+ * matching this crate's historical behavior) emits only full-depth split
6
+ * combinations as columns; `Rollup` additionally emits grand-total and
7
+ * subtotal column groups in "totals before" order. There is no `Total`
8
+ * variant - an empty `split_by` already expresses a single grand-total
9
+ * column group.
10
+ */
11
+ export type SplitRollupMode = "flat" | "rollup";
@@ -1,4 +1,5 @@
1
1
  // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { ListFlatten } from "./ListFlatten.js";
2
3
  import type { TableReadFormat } from "./TableReadFormat.js";
3
4
 
4
5
  /**
@@ -24,4 +25,12 @@ limit?: number,
24
25
  * instead of memory. On native targets this is a memory-mapped file; on
25
26
  * WASM it is OPFS (Worker only). Defaults to in-memory.
26
27
  */
27
- page_to_disk?: boolean, };
28
+ page_to_disk?: boolean,
29
+ /**
30
+ * How Arrow `LIST` and JSON `Array` columns are ingested. `zip` (the
31
+ * default) and `cartesian` expand a row into one row per list element,
32
+ * and are incompatible with `index`, as the rows of an expansion
33
+ * repeat their index. `stringify` encodes each list as a JSON array in
34
+ * a single string column instead.
35
+ */
36
+ list_flatten?: ListFlatten, };
@@ -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 { SplitRollupMode } from "./SplitRollupMode.js";
8
9
  import type { Windows } from "./Windows.js";
9
10
 
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, };
11
+ export type ViewConfig = { group_by: Array<string>, split_by: Array<string>, sort: Array<Sort>, filter: Array<Filter>, group_rollup_mode: GroupRollupMode, split_rollup_mode: SplitRollupMode, 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 { SplitRollupMode } from "./SplitRollupMode.js";
8
9
  import type { Windows } from "./Windows.js";
9
10
 
10
11
  export type ViewConfigUpdate = {
@@ -63,6 +64,12 @@ filter?: Array<Filter>,
63
64
  * name and a string sort direction. When `column-pivots` are applied,
64
65
  * the additional sort directions `"col asc"` and `"col desc"` will
65
66
  * determine the order of pivot columns groups.
67
+ *
68
+ * `sort` is the ONLY thing that orders a `View`'s rows — without it
69
+ * they keep the `Table`'s natural (insertion) order, which any
70
+ * consumer reading rows sequentially will reflect. Not to be
71
+ * confused with a window column's `order_by`, which orders rows
72
+ * WITHIN a window frame and does not reorder the `View`.
66
73
  */
67
74
  sort?: Array<Sort>,
68
75
  /**
@@ -93,5 +100,12 @@ windows?: Windows,
93
100
  * Perspective provides a selection of aggregate functions that can be
94
101
  * applied to columns in the `View` constructor using a dictionary of
95
102
  * column name to aggregate function name.
103
+ *
104
+ * An aggregate also determines the column's RESULT TYPE, which need
105
+ * not match the input: `"count"` yields an `integer` whatever it
106
+ * counts, so a `date` column left on the default `"count"` is an
107
+ * `integer` in the resulting `View` — no longer a date. Set an
108
+ * aggregate that preserves the type (e.g. `"any"`, `"last"`) when
109
+ * the original type matters, such as a date used as a chart axis.
96
110
  */
97
- aggregates?: { [key in string]?: Aggregate }, group_by_depth?: number, filter_op?: FilterReducer, group_rollup_mode?: GroupRollupMode, };
111
+ aggregates?: { [key in string]?: Aggregate }, group_by_depth?: number, filter_op?: FilterReducer, group_rollup_mode?: GroupRollupMode, split_rollup_mode?: SplitRollupMode, };
@@ -0,0 +1,25 @@
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 a window aggregate.
6
+ */
7
+ export type WindowAggSpec = { name: string,
8
+ /**
9
+ * Frame kinds this aggregate accepts (`rows`, `range`, `cumulative`).
10
+ * Empty means it takes no frame at all.
11
+ */
12
+ frames?: Array<string>,
13
+ /**
14
+ * Takes a row offset, as `lag` / `lead` / `diff` do.
15
+ */
16
+ offset?: boolean,
17
+ /**
18
+ * Takes a smoothing factor, as `ema` does.
19
+ */
20
+ alpha?: boolean,
21
+ /**
22
+ * The output column type. `None` means the source column's type, which
23
+ * is what `min` / `max` / `lag` do.
24
+ */
25
+ result_type?: ColumnType, };
@@ -1,5 +1,4 @@
1
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
2
  import type { WindowSort } from "./WindowSort.js";
4
3
 
5
4
  /**
@@ -10,7 +9,7 @@ export type WindowSpec = {
10
9
  * The input column - either a real `Table` column or an expression
11
10
  * alias from the same `ViewConfig`.
12
11
  */
13
- column: string, aggregate: WindowAggregate,
12
+ column: string, aggregate: string,
14
13
  /**
15
14
  * Columns whose distinct value tuples partition the rows; empty
16
15
  * partitions the whole `Table` as one group.
@@ -18,6 +17,8 @@ column: string, aggregate: WindowAggregate,
18
17
  partition_by?: Array<string>,
19
18
  /**
20
19
  * The `Table` column which orders each partition, and the direction.
20
+ * This orders rows WITHIN the window frame only — it does not
21
+ * reorder the `View`, which is what the view-level `sort` does.
21
22
  */
22
23
  order_by?: WindowSort | null,
23
24
  /**