@perspective-dev/client 5.3.0 → 5.4.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.
@@ -0,0 +1,6 @@
1
+ import type { ViewOnRemoveResp } from "./ViewOnRemoveResp.js";
2
+ /**
3
+ * Removed index values and port ID corresponding to a remove batch, provided
4
+ * to the callback argument to [`View::on_remove`].
5
+ */
6
+ export type OnRemoveData = ViewOnRemoveResp;
@@ -0,0 +1,6 @@
1
+ import type { ViewOnUpdateResp } from "./ViewOnUpdateResp.js";
2
+ /**
3
+ * Rows updated and port ID corresponding to an update batch, provided to the
4
+ * callback argument to [`View::on_update`] with the "rows" mode.
5
+ */
6
+ export type OnUpdateData = ViewOnUpdateResp;
@@ -0,0 +1,4 @@
1
+ export type ViewOnRemoveResp = {
2
+ indices: Uint8Array;
3
+ port_id: number;
4
+ };
@@ -1,4 +1,4 @@
1
1
  export type ViewOnUpdateResp = {
2
- delta: Array<number>;
2
+ delta: Uint8Array | undefined;
3
3
  port_id: number;
4
4
  };
@@ -91,6 +91,9 @@ export type * from "../../src/ts/ts-rs/ColumnWindow.d.ts";
91
91
  export type * from "../../src/ts/ts-rs/TableInitOptions.d.ts";
92
92
  export type * from "../../src/ts/ts-rs/ViewConfigUpdate.d.ts";
93
93
  export type * from "../../src/ts/ts-rs/ViewOnUpdateResp.d.ts";
94
+ export type * from "../../src/ts/ts-rs/ViewOnRemoveResp.d.ts";
95
+ export type * from "../../src/ts/ts-rs/OnRemoveData.d.ts";
96
+ export type * from "../../src/ts/ts-rs/OnUpdateData.d.ts";
94
97
  export type * from "../../src/ts/ts-rs/OnUpdateOptions.d.ts";
95
98
  export type * from "../../src/ts/ts-rs/UpdateOptions.d.ts";
96
99
  export type * from "../../src/ts/ts-rs/DeleteOptions.d.ts";
@@ -115,6 +118,8 @@ import type {JoinOptions} from "../../src/ts/ts-rs/JoinOptions.ts";
115
118
  import type {JoinType} from "../../src/ts/ts-rs/JoinType.ts";
116
119
  import type {ViewConfigUpdate} from "../../src/ts/ts-rs/ViewConfigUpdate.d.ts";
117
120
  import type * as on_update_args from "../../src/ts/ts-rs/ViewOnUpdateResp.d.ts";
121
+ import type {OnRemoveData} from "../../src/ts/ts-rs/OnRemoveData.d.ts";
122
+ import type {OnUpdateData} from "../../src/ts/ts-rs/OnUpdateData.d.ts";
118
123
  import type {OnUpdateOptions} from "../../src/ts/ts-rs/OnUpdateOptions.d.ts";
119
124
  import type {UpdateOptions} from "../../src/ts/ts-rs/UpdateOptions.d.ts";
120
125
  import type {DeleteOptions} from "../../src/ts/ts-rs/DeleteOptions.d.ts";
@@ -737,12 +742,31 @@ export class View {
737
742
  * deleted, this callback will be invoked.
738
743
  */
739
744
  on_delete(on_delete: Function): Promise<any>;
745
+ /**
746
+ * Register a callback which is invoked whenever rows are removed from
747
+ * this [`View`]'s [`Table`] by [`Table::remove`], with an object
748
+ * containing `port_id` and `indices`, the removed `index` column
749
+ * values as an Arrow of one column named after the index.
750
+ *
751
+ * [`Table::replace`] reports the keys it does not re-supply and
752
+ * [`Table::clear`] reports every key. `on_remove` never fires for a
753
+ * [`Table`] without an `index`.
754
+ *
755
+ * # JavaScript Examples
756
+ *
757
+ * ```javascript
758
+ * const id = await view.on_remove(({ indices, port_id }) => {
759
+ * replica.remove(indices);
760
+ * });
761
+ * ```
762
+ */
763
+ on_remove(on_remove_js: (data: OnRemoveData) => void): Promise<any>;
740
764
  /**
741
765
  * Register a callback with this [`View`]. Whenever the view's underlying
742
766
  * table emits an update, this callback will be invoked with an object
743
767
  * containing `port_id`, indicating which port the update fired on, and
744
768
  * optionally `delta`, which is the new data that was updated for each
745
- * cell or each row.
769
+ * cell or each row (as an Arrow).
746
770
  *
747
771
  * # Arguments
748
772
  *
@@ -750,27 +774,33 @@ export class View {
750
774
  * object with two keys: `port_id`, indicating which port the update was
751
775
  * triggered on, and `delta`, whose value is dependent on the mode
752
776
  * parameter.
753
- * - `options` - If this is provided as `OnUpdateOptions { mode:
754
- * Some(OnUpdateMode::Row) }`, then `delta` is an Arrow of the updated
755
- * rows. Otherwise `delta` will be [`Option::None`].
777
+ * - `options` - If this is provided as `{mode: "row"}`, then `delta` is an
778
+ * Arrow of the updated rows. Otherwise `delta` will be `null`.
756
779
  *
757
780
  * # JavaScript Examples
758
781
  *
759
782
  * ```javascript
760
- * // Attach an `on_update` callback
761
783
  * view.on_update((updated) => console.log(updated.port_id));
762
784
  * ```
763
785
  *
764
786
  * ```javascript
765
- * // `on_update` with row deltas
766
787
  * view.on_update((updated) => console.log(updated.delta), { mode: "row" });
767
788
  * ```
768
789
  */
769
- on_update(on_update_js: Function, options?: OnUpdateOptions | null): Promise<any>;
790
+ on_update(on_update_js: (data: OnUpdateData) => void, options?: OnUpdateOptions | null): Promise<any>;
770
791
  /**
771
792
  * Unregister a previously registered [`View::on_delete`] callback.
772
793
  */
773
794
  remove_delete(callback_id: number): Promise<any>;
795
+ /**
796
+ * Unregister a previously registered [`View::on_remove`] callback.
797
+ *
798
+ * # Arguments
799
+ *
800
+ * - `id` - A callback `id` as returned by a reciprocal call to
801
+ * [`View::on_remove`].
802
+ */
803
+ remove_remove(callback_id: number): Promise<void>;
774
804
  /**
775
805
  * Unregister a previously registered update callback with this [`View`].
776
806
  *
@@ -941,8 +971,10 @@ export interface InitOutput {
941
971
  readonly view_num_columns: (a: number) => number;
942
972
  readonly view_num_rows: (a: number) => number;
943
973
  readonly view_on_delete: (a: number, b: number) => number;
974
+ readonly view_on_remove: (a: number, b: number) => number;
944
975
  readonly view_on_update: (a: number, b: number, c: number) => number;
945
976
  readonly view_remove_delete: (a: number, b: number) => number;
977
+ readonly view_remove_remove: (a: number, b: number) => number;
946
978
  readonly view_remove_update: (a: number, b: number) => number;
947
979
  readonly view_schema: (a: number) => number;
948
980
  readonly view_set_depth: (a: number, b: number) => number;
@@ -964,12 +996,12 @@ export interface InitOutput {
964
996
  readonly virtualdataslice_setStringCol: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
965
997
  readonly virtualserver_handleRequest: (a: number, b: number, c: number) => number;
966
998
  readonly virtualserver_new: (a: number, b: number) => void;
967
- readonly __wasm_bindgen_func_elem_1164: (a: number, b: number) => void;
968
- readonly __wasm_bindgen_func_elem_4285: (a: number, b: number) => void;
969
- readonly __wasm_bindgen_func_elem_12453: (a: number, b: number, c: number, d: number) => void;
970
- readonly __wasm_bindgen_func_elem_4302: (a: number, b: number, c: number) => void;
971
- readonly __wasm_bindgen_func_elem_1899: (a: number, b: number) => number;
972
- readonly __wasm_bindgen_func_elem_1900: (a: number, b: number) => void;
999
+ readonly __wasm_bindgen_func_elem_1222: (a: number, b: number) => void;
1000
+ readonly __wasm_bindgen_func_elem_4376: (a: number, b: number) => void;
1001
+ readonly __wasm_bindgen_func_elem_12577: (a: number, b: number, c: number, d: number) => void;
1002
+ readonly __wasm_bindgen_func_elem_4393: (a: number, b: number, c: number) => void;
1003
+ readonly __wasm_bindgen_func_elem_1955: (a: number, b: number) => number;
1004
+ readonly __wasm_bindgen_func_elem_1956: (a: number, b: number) => void;
973
1005
  readonly __wbindgen_export: (a: number, b: number) => number;
974
1006
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
975
1007
  readonly __wbindgen_export3: (a: number) => void;
@@ -1277,12 +1277,36 @@ export class View {
1277
1277
  const ret = wasm.view_on_delete(this.__wbg_ptr, addHeapObject(on_delete));
1278
1278
  return takeObject(ret);
1279
1279
  }
1280
+ /**
1281
+ * Register a callback which is invoked whenever rows are removed from
1282
+ * this [`View`]'s [`Table`] by [`Table::remove`], with an object
1283
+ * containing `port_id` and `indices`, the removed `index` column
1284
+ * values as an Arrow of one column named after the index.
1285
+ *
1286
+ * [`Table::replace`] reports the keys it does not re-supply and
1287
+ * [`Table::clear`] reports every key. `on_remove` never fires for a
1288
+ * [`Table`] without an `index`.
1289
+ *
1290
+ * # JavaScript Examples
1291
+ *
1292
+ * ```javascript
1293
+ * const id = await view.on_remove(({ indices, port_id }) => {
1294
+ * replica.remove(indices);
1295
+ * });
1296
+ * ```
1297
+ * @param {(data: OnRemoveData) => void} on_remove_js
1298
+ * @returns {Promise<any>}
1299
+ */
1300
+ on_remove(on_remove_js) {
1301
+ const ret = wasm.view_on_remove(this.__wbg_ptr, addHeapObject(on_remove_js));
1302
+ return takeObject(ret);
1303
+ }
1280
1304
  /**
1281
1305
  * Register a callback with this [`View`]. Whenever the view's underlying
1282
1306
  * table emits an update, this callback will be invoked with an object
1283
1307
  * containing `port_id`, indicating which port the update fired on, and
1284
1308
  * optionally `delta`, which is the new data that was updated for each
1285
- * cell or each row.
1309
+ * cell or each row (as an Arrow).
1286
1310
  *
1287
1311
  * # Arguments
1288
1312
  *
@@ -1290,22 +1314,19 @@ export class View {
1290
1314
  * object with two keys: `port_id`, indicating which port the update was
1291
1315
  * triggered on, and `delta`, whose value is dependent on the mode
1292
1316
  * parameter.
1293
- * - `options` - If this is provided as `OnUpdateOptions { mode:
1294
- * Some(OnUpdateMode::Row) }`, then `delta` is an Arrow of the updated
1295
- * rows. Otherwise `delta` will be [`Option::None`].
1317
+ * - `options` - If this is provided as `{mode: "row"}`, then `delta` is an
1318
+ * Arrow of the updated rows. Otherwise `delta` will be `null`.
1296
1319
  *
1297
1320
  * # JavaScript Examples
1298
1321
  *
1299
1322
  * ```javascript
1300
- * // Attach an `on_update` callback
1301
1323
  * view.on_update((updated) => console.log(updated.port_id));
1302
1324
  * ```
1303
1325
  *
1304
1326
  * ```javascript
1305
- * // `on_update` with row deltas
1306
1327
  * view.on_update((updated) => console.log(updated.delta), { mode: "row" });
1307
1328
  * ```
1308
- * @param {Function} on_update_js
1329
+ * @param {(data: OnUpdateData) => void} on_update_js
1309
1330
  * @param {OnUpdateOptions | null} [options]
1310
1331
  * @returns {Promise<any>}
1311
1332
  */
@@ -1322,6 +1343,20 @@ export class View {
1322
1343
  const ret = wasm.view_remove_delete(this.__wbg_ptr, callback_id);
1323
1344
  return takeObject(ret);
1324
1345
  }
1346
+ /**
1347
+ * Unregister a previously registered [`View::on_remove`] callback.
1348
+ *
1349
+ * # Arguments
1350
+ *
1351
+ * - `id` - A callback `id` as returned by a reciprocal call to
1352
+ * [`View::on_remove`].
1353
+ * @param {number} callback_id
1354
+ * @returns {Promise<void>}
1355
+ */
1356
+ remove_remove(callback_id) {
1357
+ const ret = wasm.view_remove_remove(this.__wbg_ptr, callback_id);
1358
+ return takeObject(ret);
1359
+ }
1325
1360
  /**
1326
1361
  * Unregister a previously registered update callback with this [`View`].
1327
1362
  *
@@ -2017,7 +2052,7 @@ function __wbg_get_imports() {
2017
2052
  const a = state0.a;
2018
2053
  state0.a = 0;
2019
2054
  try {
2020
- return __wasm_bindgen_func_elem_12453(a, state0.b, arg0, arg1);
2055
+ return __wasm_bindgen_func_elem_12577(a, state0.b, arg0, arg1);
2021
2056
  } finally {
2022
2057
  state0.a = a;
2023
2058
  }
@@ -2092,7 +2127,7 @@ function __wbg_get_imports() {
2092
2127
  const ret = Promise.resolve(getObject(arg0));
2093
2128
  return addHeapObject(ret);
2094
2129
  },
2095
- __wbg_run_6b188d9db01ef98f: function() { return handleError(function (arg0, arg1) {
2130
+ __wbg_run_a7d22113de2ff7d8: function() { return handleError(function (arg0, arg1) {
2096
2131
  const ret = getObject(arg0).run(getObject(arg1));
2097
2132
  return addHeapObject(ret);
2098
2133
  }, arguments); },
@@ -2180,17 +2215,17 @@ function __wbg_get_imports() {
2180
2215
  },
2181
2216
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
2182
2217
  // 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);
2218
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1222, __wasm_bindgen_func_elem_1955);
2184
2219
  return addHeapObject(ret);
2185
2220
  },
2186
2221
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
2187
2222
  // 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);
2223
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1222, __wasm_bindgen_func_elem_1956);
2189
2224
  return addHeapObject(ret);
2190
2225
  },
2191
2226
  __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);
2227
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 609, function: Function { arguments: [Externref], shim_idx: 610, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
2228
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4376, __wasm_bindgen_func_elem_4393);
2194
2229
  return addHeapObject(ret);
2195
2230
  },
2196
2231
  __wbindgen_cast_0000000000000004: function(arg0) {
@@ -2267,21 +2302,21 @@ function __wbg_get_imports() {
2267
2302
  };
2268
2303
  }
2269
2304
 
2270
- function __wasm_bindgen_func_elem_1900(arg0, arg1) {
2271
- wasm.__wasm_bindgen_func_elem_1900(arg0, arg1);
2305
+ function __wasm_bindgen_func_elem_1956(arg0, arg1) {
2306
+ wasm.__wasm_bindgen_func_elem_1956(arg0, arg1);
2272
2307
  }
2273
2308
 
2274
- function __wasm_bindgen_func_elem_1899(arg0, arg1) {
2275
- const ret = wasm.__wasm_bindgen_func_elem_1899(arg0, arg1);
2309
+ function __wasm_bindgen_func_elem_1955(arg0, arg1) {
2310
+ const ret = wasm.__wasm_bindgen_func_elem_1955(arg0, arg1);
2276
2311
  return takeObject(ret);
2277
2312
  }
2278
2313
 
2279
- function __wasm_bindgen_func_elem_4302(arg0, arg1, arg2) {
2280
- wasm.__wasm_bindgen_func_elem_4302(arg0, arg1, addHeapObject(arg2));
2314
+ function __wasm_bindgen_func_elem_4393(arg0, arg1, arg2) {
2315
+ wasm.__wasm_bindgen_func_elem_4393(arg0, arg1, addHeapObject(arg2));
2281
2316
  }
2282
2317
 
2283
- function __wasm_bindgen_func_elem_12453(arg0, arg1, arg2, arg3) {
2284
- wasm.__wasm_bindgen_func_elem_12453(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2318
+ function __wasm_bindgen_func_elem_12577(arg0, arg1, arg2, arg3) {
2319
+ wasm.__wasm_bindgen_func_elem_12577(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2285
2320
  }
2286
2321
 
2287
2322
  const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -70,8 +70,10 @@ export const view_get_min_max: (a: number, b: number, c: number) => number;
70
70
  export const view_num_columns: (a: number) => number;
71
71
  export const view_num_rows: (a: number) => number;
72
72
  export const view_on_delete: (a: number, b: number) => number;
73
+ export const view_on_remove: (a: number, b: number) => number;
73
74
  export const view_on_update: (a: number, b: number, c: number) => number;
74
75
  export const view_remove_delete: (a: number, b: number) => number;
76
+ export const view_remove_remove: (a: number, b: number) => number;
75
77
  export const view_remove_update: (a: number, b: number) => number;
76
78
  export const view_schema: (a: number) => number;
77
79
  export const view_set_depth: (a: number, b: number) => number;
@@ -93,12 +95,12 @@ export const virtualdataslice_setIntegerCol: (a: number, b: number, c: number, d
93
95
  export const virtualdataslice_setStringCol: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
94
96
  export const virtualserver_handleRequest: (a: number, b: number, c: number) => number;
95
97
  export const virtualserver_new: (a: number, b: number) => void;
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;
98
+ export const __wasm_bindgen_func_elem_1222: (a: number, b: number) => void;
99
+ export const __wasm_bindgen_func_elem_4376: (a: number, b: number) => void;
100
+ export const __wasm_bindgen_func_elem_12577: (a: number, b: number, c: number, d: number) => void;
101
+ export const __wasm_bindgen_func_elem_4393: (a: number, b: number, c: number) => void;
102
+ export const __wasm_bindgen_func_elem_1955: (a: number, b: number) => number;
103
+ export const __wasm_bindgen_func_elem_1956: (a: number, b: number) => void;
102
104
  export const __wbindgen_export: (a: number, b: number) => number;
103
105
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
104
106
  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.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "Client for Perspective, a high-performance WASM engine with reactive Tables, Views, and joins.",
5
5
  "keywords": [
6
6
  "perspective",
@@ -63,15 +63,12 @@
63
63
  "access": "public"
64
64
  },
65
65
  "dependencies": {
66
- "@perspective-dev/server": "",
67
66
  "pro_self_extracting_wasm": "0.0.9",
68
67
  "stoppable": "=1.1.0",
69
- "ws": "^8.17.0"
68
+ "ws": "^8.17.0",
69
+ "@perspective-dev/server": "^5.4.0"
70
70
  },
71
71
  "devDependencies": {
72
- "@perspective-dev/esbuild-plugin": "",
73
- "@perspective-dev/metadata": "",
74
- "@perspective-dev/test": "",
75
72
  "@clickhouse/client-web": "^1.12.0",
76
73
  "@duckdb/duckdb-wasm": "1.33.1-dev18.0",
77
74
  "@playwright/experimental-ct-react": "=1.58.0",
@@ -86,7 +83,10 @@
86
83
  "typedoc": "^0.28.7",
87
84
  "typescript": ">=5 <6",
88
85
  "web-worker": "1.4.1",
89
- "zx": ">=8 <9"
86
+ "zx": ">=8 <9",
87
+ "@perspective-dev/esbuild-plugin": "^5.4.0",
88
+ "@perspective-dev/test": "^5.4.0",
89
+ "@perspective-dev/metadata": "^5.4.0"
90
90
  },
91
91
  "scripts": {
92
92
  "build": "node ./build.mjs",
package/src/rust/lib.rs CHANGED
@@ -53,6 +53,9 @@ export type * from "../../src/ts/ts-rs/ColumnWindow.d.ts";
53
53
  export type * from "../../src/ts/ts-rs/TableInitOptions.d.ts";
54
54
  export type * from "../../src/ts/ts-rs/ViewConfigUpdate.d.ts";
55
55
  export type * from "../../src/ts/ts-rs/ViewOnUpdateResp.d.ts";
56
+ export type * from "../../src/ts/ts-rs/ViewOnRemoveResp.d.ts";
57
+ export type * from "../../src/ts/ts-rs/OnRemoveData.d.ts";
58
+ export type * from "../../src/ts/ts-rs/OnUpdateData.d.ts";
56
59
  export type * from "../../src/ts/ts-rs/OnUpdateOptions.d.ts";
57
60
  export type * from "../../src/ts/ts-rs/UpdateOptions.d.ts";
58
61
  export type * from "../../src/ts/ts-rs/DeleteOptions.d.ts";
@@ -77,6 +80,8 @@ import type {JoinOptions} from "../../src/ts/ts-rs/JoinOptions.ts";
77
80
  import type {JoinType} from "../../src/ts/ts-rs/JoinType.ts";
78
81
  import type {ViewConfigUpdate} from "../../src/ts/ts-rs/ViewConfigUpdate.d.ts";
79
82
  import type * as on_update_args from "../../src/ts/ts-rs/ViewOnUpdateResp.d.ts";
83
+ import type {OnRemoveData} from "../../src/ts/ts-rs/OnRemoveData.d.ts";
84
+ import type {OnUpdateData} from "../../src/ts/ts-rs/OnUpdateData.d.ts";
80
85
  import type {OnUpdateOptions} from "../../src/ts/ts-rs/OnUpdateOptions.d.ts";
81
86
  import type {UpdateOptions} from "../../src/ts/ts-rs/UpdateOptions.d.ts";
82
87
  import type {DeleteOptions} from "../../src/ts/ts-rs/DeleteOptions.d.ts";
@@ -14,7 +14,9 @@ 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, DictionaryArray, PrimitiveArray, StringArray};
17
+ use arrow_array::{
18
+ Array as _, ArrayRef, ArrowPrimitiveType, DictionaryArray, PrimitiveArray, StringArray,
19
+ };
18
20
  use arrow_ipc::reader::StreamReader;
19
21
  use arrow_schema::{DataType, TimeUnit};
20
22
  use js_sys::{Array, Function, JsString, Uint8Array};
@@ -74,6 +76,33 @@ fn zero_invalid_slots<T: ArrowPrimitiveType>(arr: &PrimitiveArray<T>) {
74
76
  }
75
77
  }
76
78
 
79
+ /// Emit a sub-32-bit integer column as an `Int32Array`. Every Arrow
80
+ /// integer width the engine emits below 32 bits (`i8`/`u8`/`i16`/`u16`)
81
+ /// widens losslessly, so consumers see ONE integer representation
82
+ /// regardless of the column's storage width — and, like `Int32`, one
83
+ /// the `float32` flag never narrows. Needs a copy; `Box<[i32]>` gives
84
+ /// the stable data pointer the zero-copy `view` requires, exactly as
85
+ /// the `f32`/`f64` conversion buffers do.
86
+ fn set_widened_i32<T>(
87
+ col: &ArrayRef,
88
+ col_idx: usize,
89
+ js_values: &Array,
90
+ js_dicts: &Array,
91
+ storage: &mut Vec<Box<[i32]>>,
92
+ ) where
93
+ T: ArrowPrimitiveType,
94
+ T::Native: Into<i32>,
95
+ {
96
+ let typed = col.as_primitive::<T>();
97
+ zero_invalid_slots(typed);
98
+ let vals: Box<[i32]> = typed.values().iter().map(|&v| v.into()).collect();
99
+
100
+ let arr = unsafe { js_sys::Int32Array::view(&vals) };
101
+ storage.push(vals);
102
+ js_values.set(col_idx as u32, arr.into());
103
+ js_dicts.set(col_idx as u32, JsValue::NULL);
104
+ }
105
+
77
106
  /// Decode an Arrow IPC batch and call `callback` once with all columns.
78
107
  ///
79
108
  /// Callback signature:
@@ -108,12 +137,14 @@ pub(crate) async fn decode_and_call(
108
137
  let js_validities = Array::new_with_length(num_cols as u32);
109
138
  let js_dicts = Array::new_with_length(num_cols as u32);
110
139
 
111
- // Storage for type-conversion buffers (Int64/Date32/Timestamp and
112
- // `float32` narrowing). These MUST outlive the callback because
113
- // `js_sys::*Array::view()` creates zero-copy views into their heap
114
- // memory. Using `Box<[T]>` (rather than `Vec<T>`) yields a stable
115
- // data pointer that won't move when the outer Vec grows, so a view
116
- // created before the push stays valid.
140
+ // Storage for type-conversion buffers (narrow-int/bool widening,
141
+ // Int64/UInt64/Date32/Timestamp and `float32` narrowing). These
142
+ // MUST outlive the callback because `js_sys::*Array::view()`
143
+ // creates zero-copy views into their heap memory. Using `Box<[T]>`
144
+ // (rather than `Vec<T>`) yields a stable data pointer that won't
145
+ // move when the outer Vec grows, so a view created before the push
146
+ // stays valid.
147
+ let mut i32_storage: Vec<Box<[i32]>> = Vec::new();
117
148
  let mut f32_storage: Vec<Box<[f32]>> = Vec::new();
118
149
  let mut f64_storage: Vec<Box<[f64]>> = Vec::new();
119
150
 
@@ -133,6 +164,24 @@ pub(crate) async fn decode_and_call(
133
164
  js_names.set(col_idx as u32, JsString::from(field.name().as_str()).into());
134
165
 
135
166
  match col.data_type() {
167
+ DataType::Int8 => {
168
+ set_widened_i32::<Int8Type>(col, col_idx, &js_values, &js_dicts, &mut i32_storage);
169
+ },
170
+ DataType::UInt8 => {
171
+ set_widened_i32::<UInt8Type>(col, col_idx, &js_values, &js_dicts, &mut i32_storage);
172
+ },
173
+ DataType::Int16 => {
174
+ set_widened_i32::<Int16Type>(col, col_idx, &js_values, &js_dicts, &mut i32_storage);
175
+ },
176
+ DataType::UInt16 => {
177
+ set_widened_i32::<UInt16Type>(
178
+ col,
179
+ col_idx,
180
+ &js_values,
181
+ &js_dicts,
182
+ &mut i32_storage,
183
+ );
184
+ },
136
185
  DataType::UInt32 => {
137
186
  let typed = col.as_primitive::<UInt32Type>();
138
187
  zero_invalid_slots(typed);
@@ -218,6 +267,46 @@ pub(crate) async fn decode_and_call(
218
267
 
219
268
  js_dicts.set(col_idx as u32, JsValue::NULL);
220
269
  },
270
+ // Neither `u64` nor `i64` fits `Int32Array`, so both widen
271
+ // to float (narrowed by `float32` like the other float
272
+ // columns) and lose exactness past 2^53. `UInt64` is not an
273
+ // exotic case: `get_simple_accumulator_type` promotes EVERY
274
+ // unsigned width to `DTYPE_UINT64`, so the `sum` of any
275
+ // unsigned column in a `group_by` view lands here.
276
+ DataType::UInt64 => {
277
+ let typed = col.as_primitive::<UInt64Type>();
278
+ zero_invalid_slots(typed);
279
+ if float32 {
280
+ let vals: Box<[f32]> = typed.values().iter().map(|&v| v as f32).collect();
281
+
282
+ let arr = unsafe { js_sys::Float32Array::view(&vals) };
283
+ f32_storage.push(vals);
284
+ js_values.set(col_idx as u32, arr.into());
285
+ } else {
286
+ let vals: Box<[f64]> = typed.values().iter().map(|&v| v as f64).collect();
287
+
288
+ let arr = unsafe { js_sys::Float64Array::view(&vals) };
289
+ f64_storage.push(vals);
290
+ js_values.set(col_idx as u32, arr.into());
291
+ }
292
+
293
+ js_dicts.set(col_idx as u32, JsValue::NULL);
294
+ },
295
+ DataType::Boolean => {
296
+ // Bit-packed, so `zero_invalid_slots` (a `PrimitiveArray`
297
+ // memory rewrite) cannot apply — the `is_valid` test
298
+ // below enforces the same "invalid slots read 0"
299
+ // contract while materializing.
300
+ let typed = col.as_boolean();
301
+ let vals: Box<[i32]> = (0..typed.len())
302
+ .map(|i| i32::from(typed.is_valid(i) && typed.value(i)))
303
+ .collect();
304
+
305
+ let arr = unsafe { js_sys::Int32Array::view(&vals) };
306
+ i32_storage.push(vals);
307
+ js_values.set(col_idx as u32, arr.into());
308
+ js_dicts.set(col_idx as u32, JsValue::NULL);
309
+ },
221
310
  DataType::Dictionary(..) => {
222
311
  let dict = col
223
312
  .as_any()
@@ -279,9 +368,9 @@ pub(crate) async fn decode_and_call(
279
368
  )?;
280
369
 
281
370
  // If the callback returned a Promise, await it before releasing the
282
- // batch — zero-copy TypedArray views into `batch`/`f32_storage`/
283
- // `f64_storage` must remain valid for the full lifetime of the
284
- // awaited work.
371
+ // batch — zero-copy TypedArray views into `batch` and the
372
+ // `i32`/`f32`/`f64` conversion buffers must remain valid for the
373
+ // full lifetime of the awaited work.
285
374
  if ret.is_instance_of::<js_sys::Promise>() {
286
375
  let promise: js_sys::Promise = ret.unchecked_into();
287
376
  wasm_bindgen_futures::JsFuture::from(promise).await?;
@@ -289,6 +378,7 @@ pub(crate) async fn decode_and_call(
289
378
 
290
379
  // Keep storage alive until after the callback (and its awaited
291
380
  // promise, if any) returns.
381
+ drop(i32_storage);
292
382
  drop(f32_storage);
293
383
  drop(f64_storage);
294
384
 
package/src/rust/view.rs CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  use js_sys::{Array, ArrayBuffer, Function, Object};
14
14
  use perspective_client::{
15
- ColumnWindow, OnUpdateData, OnUpdateOptions, ViewWindow, assert_view_api,
15
+ ColumnWindow, OnRemoveData, OnUpdateData, OnUpdateOptions, ViewWindow, assert_view_api,
16
16
  };
17
17
  use wasm_bindgen::prelude::*;
18
18
  use wasm_bindgen_futures::spawn_local;
@@ -289,7 +289,7 @@ impl View {
289
289
  /// table emits an update, this callback will be invoked with an object
290
290
  /// containing `port_id`, indicating which port the update fired on, and
291
291
  /// optionally `delta`, which is the new data that was updated for each
292
- /// cell or each row.
292
+ /// cell or each row (as an Arrow).
293
293
  ///
294
294
  /// # Arguments
295
295
  ///
@@ -297,24 +297,22 @@ impl View {
297
297
  /// object with two keys: `port_id`, indicating which port the update was
298
298
  /// triggered on, and `delta`, whose value is dependent on the mode
299
299
  /// parameter.
300
- /// - `options` - If this is provided as `OnUpdateOptions { mode:
301
- /// Some(OnUpdateMode::Row) }`, then `delta` is an Arrow of the updated
302
- /// rows. Otherwise `delta` will be [`Option::None`].
300
+ /// - `options` - If this is provided as `{mode: "row"}`, then `delta` is an
301
+ /// Arrow of the updated rows. Otherwise `delta` will be `null`.
303
302
  ///
304
303
  /// # JavaScript Examples
305
304
  ///
306
305
  /// ```javascript
307
- /// // Attach an `on_update` callback
308
306
  /// view.on_update((updated) => console.log(updated.port_id));
309
307
  /// ```
310
308
  ///
311
309
  /// ```javascript
312
- /// // `on_update` with row deltas
313
310
  /// view.on_update((updated) => console.log(updated.delta), { mode: "row" });
314
311
  /// ```
315
312
  #[wasm_bindgen]
316
313
  pub fn on_update(
317
314
  &self,
315
+ #[wasm_bindgen(unchecked_param_type = "(data: OnUpdateData) => void")]
318
316
  on_update_js: Function,
319
317
  options: Option<JsOnUpdateOptions>,
320
318
  ) -> ApiFuture<u32> {
@@ -346,6 +344,49 @@ impl View {
346
344
  Ok(self.0.remove_update(callback_id).await?)
347
345
  }
348
346
 
347
+ /// Register a callback which is invoked whenever rows are removed from
348
+ /// this [`View`]'s [`Table`] by [`Table::remove`], with an object
349
+ /// containing `port_id` and `indices`, the removed `index` column
350
+ /// values as an Arrow of one column named after the index.
351
+ ///
352
+ /// [`Table::replace`] reports the keys it does not re-supply and
353
+ /// [`Table::clear`] reports every key. `on_remove` never fires for a
354
+ /// [`Table`] without an `index`.
355
+ ///
356
+ /// # JavaScript Examples
357
+ ///
358
+ /// ```javascript
359
+ /// const id = await view.on_remove(({ indices, port_id }) => {
360
+ /// replica.remove(indices);
361
+ /// });
362
+ /// ```
363
+ #[wasm_bindgen]
364
+ pub fn on_remove(
365
+ &self,
366
+ #[wasm_bindgen(unchecked_param_type = "(data: OnRemoveData) => void")]
367
+ on_remove_js: Function,
368
+ ) -> ApiFuture<u32> {
369
+ let poll_loop = LocalPollLoop::new(move |args: OnRemoveData| {
370
+ let js_obj = JsValue::from_serde_ext(&*args)?;
371
+ on_remove_js.call1(&JsValue::UNDEFINED, &js_obj)
372
+ });
373
+
374
+ let on_remove = Box::new(move |msg| poll_loop.poll(msg));
375
+ let view = self.0.clone();
376
+ ApiFuture::new(async move { Ok(view.on_remove(on_remove).await?) })
377
+ }
378
+
379
+ /// Unregister a previously registered [`View::on_remove`] callback.
380
+ ///
381
+ /// # Arguments
382
+ ///
383
+ /// - `id` - A callback `id` as returned by a reciprocal call to
384
+ /// [`View::on_remove`].
385
+ #[wasm_bindgen]
386
+ pub async fn remove_remove(&self, callback_id: u32) -> ApiResult<()> {
387
+ Ok(self.0.remove_remove(callback_id).await?)
388
+ }
389
+
349
390
  /// Register a callback with this [`View`]. Whenever the [`View`] is
350
391
  /// deleted, this callback will be invoked.
351
392
  #[wasm_bindgen]
@@ -0,0 +1,8 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { ViewOnRemoveResp } from "./ViewOnRemoveResp.js";
3
+
4
+ /**
5
+ * Removed index values and port ID corresponding to a remove batch, provided
6
+ * to the callback argument to [`View::on_remove`].
7
+ */
8
+ export type OnRemoveData = ViewOnRemoveResp;