@perspective-dev/client 5.8.0 → 5.9.1

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.
@@ -4,12 +4,26 @@ import http from "node:http";
4
4
  import * as perspective_client from "../../dist/wasm/perspective-js.js";
5
5
  import { host_supports_memory64 } from "./wasm/features.ts";
6
6
  import * as engine from "./wasm/engine.ts";
7
- import type { MigrateKind, MigrateResult } from "./wasm/migrate.ts";
7
+ import type { MigrateKind, MigrateResult, Validator } from "./wasm/migrate.ts";
8
8
  export { host_supports_memory64 } from "./wasm/features.ts";
9
9
  export type { InitOptions, WasmBinary, WasmRegistration, WasmSource, } from "./wasm/registry.ts";
10
- export type { MigrateKind, MigrateNotice, MigrateResult, } from "./wasm/migrate.ts";
10
+ export type { MigrateKind, MigrateNotice, MigrateResult, Validator, } from "./wasm/migrate.ts";
11
11
  import * as virtual_server from "./virtual_server.ts";
12
12
  export { GenericSQLVirtualServerModel, VirtualDataSlice, VirtualServer, } from "../../dist/wasm/perspective-js.js";
13
+ /**
14
+ * Load the `perspective-migrate` binary and return synchronous `migrate()`
15
+ * and `validate()` over it; the process shares one instance.
16
+ *
17
+ * # Examples
18
+ *
19
+ * ```javascript
20
+ * const validator = await perspective.create_validator();
21
+ * for (const token of tokens) {
22
+ * validator.validate("viewer", token, { strict: true });
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function create_validator(): Promise<Validator>;
13
27
  /**
14
28
  * Upgrade a persisted config written by any Perspective release since 2.0.0
15
29
  * to the current schema.
@@ -17,13 +31,27 @@ export { GenericSQLVirtualServerModel, VirtualDataSlice, VirtualServer, } from "
17
31
  * # Arguments
18
32
  *
19
33
  * - `kind` - `"view"` for a `ViewConfig`, `"viewer"` for a
20
- * `<perspective-viewer>` `save()` token, or `"workspace"` for a
21
- * `saveWorkspace()` token.
34
+ * `<perspective-viewer>` `save()` token, `"panel"` for one workspace
35
+ * panel, or `"workspace"` for a `saveWorkspace()` token.
22
36
  * - `config` - The config to upgrade.
23
37
  * - `from_version` - The release which wrote `config`, used only when it has
24
38
  * no `version` field.
25
39
  */
26
40
  export declare function migrate<T = Record<string, unknown>>(kind: MigrateKind, config: unknown, from_version?: string): Promise<MigrateResult<T>>;
41
+ /**
42
+ * Check that a config is valid for this release without migrating it,
43
+ * rejecting with the offending JSON pointer and reason otherwise.
44
+ *
45
+ * # Arguments
46
+ *
47
+ * - `kind` - `"view"`, `"viewer"`, `"panel"` or `"workspace"`.
48
+ * - `config` - The config to check.
49
+ * - `options.strict` - Require the complete `save()` form rather than the
50
+ * field-wise `restore()` update form.
51
+ */
52
+ export declare function validate(kind: MigrateKind, config: unknown, options?: {
53
+ strict?: boolean;
54
+ }): Promise<void>;
27
55
  export declare class PerspectiveServer extends engine.PerspectiveServer {
28
56
  constructor(options?: engine.PerspectiveServerOptions);
29
57
  }
@@ -101,7 +129,9 @@ declare const _default: {
101
129
  join: typeof join;
102
130
  websocket: typeof websocket;
103
131
  worker: typeof worker;
132
+ create_validator: typeof create_validator;
104
133
  migrate: typeof migrate;
134
+ validate: typeof validate;
105
135
  host_supports_memory64: typeof host_supports_memory64;
106
136
  get_hosted_table_names: typeof get_hosted_table_names;
107
137
  on_hosted_tables_update: typeof on_hosted_tables_update;
@@ -1219,7 +1219,7 @@ var Table = class _Table {
1219
1219
  * [`Table::on_delete`] resolves when the subscription message is sent, not
1220
1220
  * when the _delete_ event occurs.
1221
1221
  * @param {Function} on_delete
1222
- * @returns {Promise<any>}
1222
+ * @returns {Promise<number>}
1223
1223
  */
1224
1224
  on_delete(on_delete) {
1225
1225
  const ret = wasm.table_on_delete(this.__wbg_ptr, addHeapObject(on_delete));
@@ -1253,7 +1253,7 @@ var Table = class _Table {
1253
1253
  * Removes a listener with a given ID, as returned by a previous call to
1254
1254
  * [`Table::on_delete`].
1255
1255
  * @param {number} callback_id
1256
- * @returns {Promise<any>}
1256
+ * @returns {Promise<void>}
1257
1257
  */
1258
1258
  remove_delete(callback_id) {
1259
1259
  const ret = wasm.table_remove_delete(this.__wbg_ptr, callback_id);
@@ -1341,7 +1341,7 @@ var Table = class _Table {
1341
1341
  * ```
1342
1342
  * @param {string | ArrayBuffer | Record<string, unknown[]> | Record<string, unknown>[] | Record<string, ColumnType>} input
1343
1343
  * @param {UpdateOptions | null} [options]
1344
- * @returns {Promise<any>}
1344
+ * @returns {Promise<void>}
1345
1345
  */
1346
1346
  update(input, options) {
1347
1347
  const ret = wasm.table_update(this.__wbg_ptr, addHeapObject(input), isLikeNone(options) ? 0 : addHeapObject(options));
@@ -1569,31 +1569,36 @@ var View = class _View {
1569
1569
  * Register a callback with this [`View`]. Whenever the [`View`] is
1570
1570
  * deleted, this callback will be invoked.
1571
1571
  * @param {Function} on_delete
1572
- * @returns {Promise<any>}
1572
+ * @returns {Promise<number>}
1573
1573
  */
1574
1574
  on_delete(on_delete) {
1575
1575
  const ret = wasm.view_on_delete(this.__wbg_ptr, addHeapObject(on_delete));
1576
1576
  return takeObject(ret);
1577
1577
  }
1578
1578
  /**
1579
- * Register a callback which is invoked whenever rows are removed from
1580
- * this [`View`]'s [`Table`] by [`Table::remove`], with an object
1581
- * containing `port_id` and `indices`, the removed `index` column
1582
- * values as an Arrow of one column named after the index.
1579
+ * Register a callback which is invoked whenever rows leave this
1580
+ * [`View`], with an object containing `port_id`, `indices` (their keys
1581
+ * as an Arrow of one column per key column named after it) and `cause`,
1582
+ * one of `"key"`, `"filter"` or `"group"`.
1583
1583
  *
1584
- * [`Table::replace`] reports the keys it does not re-supply and
1585
- * [`Table::clear`] reports every key. `on_remove` never fires for a
1586
- * [`Table`] without an `index`.
1584
+ * For a [`View`] without `group_by` the keys are the `index` columns of
1585
+ * the [`Table`], which must have one: `"key"` when [`Table::remove`]
1586
+ * removed them ([`Table::replace`] reports the keys it does not
1587
+ * re-supply and [`Table::clear`] every key) and `"filter"` when
1588
+ * [`Table::update`] moved them outside the [`View`]'s `filter`. For a
1589
+ * [`View`] with `group_by` the keys are the `group_by` columns of each
1590
+ * group which no longer has any rows, `"group"`, `null` below the
1591
+ * group's depth. It fires once per cause per update step.
1587
1592
  *
1588
1593
  * # JavaScript Examples
1589
1594
  *
1590
1595
  * ```javascript
1591
- * const id = await view.on_remove(({ indices, port_id }) => {
1596
+ * const id = await view.on_remove(({ indices, port_id, cause }) => {
1592
1597
  * replica.remove(indices);
1593
1598
  * });
1594
1599
  * ```
1595
1600
  * @param {(data: OnRemoveData) => void} on_remove_js
1596
- * @returns {Promise<any>}
1601
+ * @returns {Promise<number>}
1597
1602
  */
1598
1603
  on_remove(on_remove_js) {
1599
1604
  const ret = wasm.view_on_remove(this.__wbg_ptr, addHeapObject(on_remove_js));
@@ -1626,7 +1631,7 @@ var View = class _View {
1626
1631
  * ```
1627
1632
  * @param {(data: OnUpdateData) => void} on_update_js
1628
1633
  * @param {OnUpdateOptions | null} [options]
1629
- * @returns {Promise<any>}
1634
+ * @returns {Promise<number>}
1630
1635
  */
1631
1636
  on_update(on_update_js, options) {
1632
1637
  const ret = wasm.view_on_update(this.__wbg_ptr, addHeapObject(on_update_js), isLikeNone(options) ? 0 : addHeapObject(options));
@@ -1635,7 +1640,7 @@ var View = class _View {
1635
1640
  /**
1636
1641
  * Unregister a previously registered [`View::on_delete`] callback.
1637
1642
  * @param {number} callback_id
1638
- * @returns {Promise<any>}
1643
+ * @returns {Promise<void>}
1639
1644
  */
1640
1645
  remove_delete(callback_id) {
1641
1646
  const ret = wasm.view_remove_delete(this.__wbg_ptr, callback_id);
@@ -1983,7 +1988,7 @@ var VirtualServer = class {
1983
1988
  }
1984
1989
  /**
1985
1990
  * @param {Uint8Array} bytes
1986
- * @returns {Promise<any>}
1991
+ * @returns {Promise<Uint8Array>}
1987
1992
  */
1988
1993
  handleRequest(bytes) {
1989
1994
  const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
@@ -2377,7 +2382,7 @@ function __wbg_get_imports() {
2377
2382
  const a = state0.a;
2378
2383
  state0.a = 0;
2379
2384
  try {
2380
- return __wasm_bindgen_func_elem_13337(a, state0.b, arg02, arg12);
2385
+ return __wasm_bindgen_func_elem_13335(a, state0.b, arg02, arg12);
2381
2386
  } finally {
2382
2387
  state0.a = a;
2383
2388
  }
@@ -2456,7 +2461,7 @@ function __wbg_get_imports() {
2456
2461
  const ret = Promise.resolve(getObject(arg0));
2457
2462
  return addHeapObject(ret);
2458
2463
  },
2459
- __wbg_run_9572f64bdbcca74b: function() {
2464
+ __wbg_run_748b6920eb34b566: function() {
2460
2465
  return handleError(function(arg0, arg1) {
2461
2466
  const ret = getObject(arg0).run(getObject(arg1));
2462
2467
  return addHeapObject(ret);
@@ -2553,15 +2558,15 @@ function __wbg_get_imports() {
2553
2558
  console.warn(getObject(arg0));
2554
2559
  },
2555
2560
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
2556
- const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1738, __wasm_bindgen_func_elem_2108);
2561
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1727, __wasm_bindgen_func_elem_2093);
2557
2562
  return addHeapObject(ret);
2558
2563
  },
2559
2564
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
2560
- const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1738, __wasm_bindgen_func_elem_2109);
2565
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1727, __wasm_bindgen_func_elem_2094);
2561
2566
  return addHeapObject(ret);
2562
2567
  },
2563
2568
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
2564
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4802, __wasm_bindgen_func_elem_4804);
2569
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4768, __wasm_bindgen_func_elem_4770);
2565
2570
  return addHeapObject(ret);
2566
2571
  },
2567
2572
  __wbindgen_cast_0000000000000004: function(arg0) {
@@ -2626,18 +2631,18 @@ function __wbg_get_imports() {
2626
2631
  "./perspective-js.wasm_bg.js": import0
2627
2632
  };
2628
2633
  }
2629
- function __wasm_bindgen_func_elem_2109(arg0, arg1) {
2630
- wasm.__wasm_bindgen_func_elem_2109(arg0, arg1);
2634
+ function __wasm_bindgen_func_elem_2094(arg0, arg1) {
2635
+ wasm.__wasm_bindgen_func_elem_2094(arg0, arg1);
2631
2636
  }
2632
- function __wasm_bindgen_func_elem_2108(arg0, arg1) {
2633
- const ret = wasm.__wasm_bindgen_func_elem_2108(arg0, arg1);
2637
+ function __wasm_bindgen_func_elem_2093(arg0, arg1) {
2638
+ const ret = wasm.__wasm_bindgen_func_elem_2093(arg0, arg1);
2634
2639
  return takeObject(ret);
2635
2640
  }
2636
- function __wasm_bindgen_func_elem_4804(arg0, arg1, arg2) {
2637
- wasm.__wasm_bindgen_func_elem_4804(arg0, arg1, addHeapObject(arg2));
2641
+ function __wasm_bindgen_func_elem_4770(arg0, arg1, arg2) {
2642
+ wasm.__wasm_bindgen_func_elem_4770(arg0, arg1, addHeapObject(arg2));
2638
2643
  }
2639
- function __wasm_bindgen_func_elem_13337(arg0, arg1, arg2, arg3) {
2640
- wasm.__wasm_bindgen_func_elem_13337(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2644
+ function __wasm_bindgen_func_elem_13335(arg0, arg1, arg2, arg3) {
2645
+ wasm.__wasm_bindgen_func_elem_13335(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2641
2646
  }
2642
2647
  var ClientFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
2643
2648
  }, unregister: () => {
@@ -3278,12 +3283,6 @@ async function decode_api_responses(core, ptr, callback) {
3278
3283
  }
3279
3284
 
3280
3285
  // dist/wasm/perspective-migrate.js
3281
- var perspective_migrate_exports = {};
3282
- __export(perspective_migrate_exports, {
3283
- default: () => __wbg_init2,
3284
- initSync: () => initSync2,
3285
- migrate: () => migrate
3286
- });
3287
3286
  function migrate(kind, from, value) {
3288
3287
  try {
3289
3288
  const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
@@ -3303,6 +3302,21 @@ function migrate(kind, from, value) {
3303
3302
  wasm2.__wbindgen_add_to_stack_pointer(16);
3304
3303
  }
3305
3304
  }
3305
+ function validate_config(kind, value, strict) {
3306
+ try {
3307
+ const retptr = wasm2.__wbindgen_add_to_stack_pointer(-16);
3308
+ const ptr0 = passStringToWasm02(kind, wasm2.__wbindgen_export, wasm2.__wbindgen_export2);
3309
+ const len0 = WASM_VECTOR_LEN2;
3310
+ wasm2.validate_config(retptr, ptr0, len0, addHeapObject2(value), isLikeNone2(strict) ? 16777215 : strict ? 1 : 0);
3311
+ var r0 = getDataViewMemory02().getInt32(retptr + 4 * 0, true);
3312
+ var r1 = getDataViewMemory02().getInt32(retptr + 4 * 1, true);
3313
+ if (r1) {
3314
+ throw takeObject2(r0);
3315
+ }
3316
+ } finally {
3317
+ wasm2.__wbindgen_add_to_stack_pointer(16);
3318
+ }
3319
+ }
3306
3320
  function __wbg_get_imports2() {
3307
3321
  const import0 = {
3308
3322
  __proto__: null,
@@ -3722,22 +3736,6 @@ async function __wbg_load2(module, imports) {
3722
3736
  return false;
3723
3737
  }
3724
3738
  }
3725
- function initSync2(module) {
3726
- if (wasm2 !== void 0) return wasm2;
3727
- if (module !== void 0) {
3728
- if (Object.getPrototypeOf(module) === Object.prototype) {
3729
- ({ module } = module);
3730
- } else {
3731
- console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
3732
- }
3733
- }
3734
- const imports = __wbg_get_imports2();
3735
- if (!(module instanceof WebAssembly.Module)) {
3736
- module = new WebAssembly.Module(module);
3737
- }
3738
- const instance = new WebAssembly.Instance(module, imports);
3739
- return __wbg_finalize_init2(instance, module);
3740
- }
3741
3739
  async function __wbg_init2(module_or_path) {
3742
3740
  if (wasm2 !== void 0) return wasm2;
3743
3741
  if (module_or_path !== void 0) {
@@ -3756,34 +3754,21 @@ async function __wbg_init2(module_or_path) {
3756
3754
  }
3757
3755
 
3758
3756
  // src/ts/wasm/migrate.ts
3759
- var MigrateLoader = class {
3760
- source;
3761
- module;
3762
- register(source) {
3763
- this.source = source;
3764
- this.module = void 0;
3765
- }
3766
- async migrate(kind, config, from_version) {
3767
- if (this.module === void 0) {
3768
- if (this.source === void 0) {
3769
- throw new Error("Missing perspective-migrate.wasm");
3770
- }
3771
- const source = this.source;
3772
- const module = source().then(async (module_or_path) => {
3773
- await __wbg_init2({ module_or_path });
3774
- return perspective_migrate_exports;
3775
- });
3776
- this.module = module;
3777
- module.catch(() => {
3778
- if (this.module === module) {
3779
- this.module = void 0;
3780
- }
3781
- });
3757
+ async function load_validator(binary) {
3758
+ await __wbg_init2({ module_or_path: binary });
3759
+ return {
3760
+ migrate(kind, config, from_version) {
3761
+ return migrate(
3762
+ kind,
3763
+ from_version,
3764
+ config
3765
+ );
3766
+ },
3767
+ validate(kind, config, options) {
3768
+ validate_config(kind, config, options?.strict);
3782
3769
  }
3783
- const wasm3 = await this.module;
3784
- return wasm3.migrate(kind, from_version, config);
3785
- }
3786
- };
3770
+ };
3771
+ }
3787
3772
 
3788
3773
  // src/ts/wasm/perspective-server.poly.ts
3789
3774
  var out = console.log.bind(console);
@@ -4262,15 +4247,18 @@ if (!globalThis.crypto) {
4262
4247
  }
4263
4248
  var uncompressed_client_wasm = await fs.readFile(path.join(__dirname, "../../dist/wasm/perspective-js.wasm")).then((buffer) => load_wasm_stage_0(buffer.buffer));
4264
4249
  await __wbg_init({ module_or_path: uncompressed_client_wasm });
4265
- var MIGRATE = new MigrateLoader();
4266
- MIGRATE.register(async () => {
4267
- const buffer = await fs.readFile(
4250
+ var VALIDATOR;
4251
+ async function create_validator() {
4252
+ VALIDATOR ??= fs.readFile(
4268
4253
  path.join(__dirname, "../../dist/wasm/perspective-migrate.wasm")
4269
- );
4270
- return await load_wasm_stage_0(buffer.buffer);
4271
- });
4254
+ ).then((buffer) => load_wasm_stage_0(buffer.buffer)).then(load_validator);
4255
+ return await VALIDATOR;
4256
+ }
4272
4257
  async function migrate2(kind, config, from_version) {
4273
- return await MIGRATE.migrate(kind, config, from_version);
4258
+ return (await create_validator()).migrate(kind, config, from_version);
4259
+ }
4260
+ async function validate(kind, config, options) {
4261
+ (await create_validator()).validate(kind, config, options);
4274
4262
  }
4275
4263
  function make_node_disk_bridge({
4276
4264
  heap: heap3,
@@ -4593,7 +4581,9 @@ var perspective_node_default = {
4593
4581
  join,
4594
4582
  websocket: websocket2,
4595
4583
  worker,
4584
+ create_validator,
4596
4585
  migrate: migrate2,
4586
+ validate,
4597
4587
  host_supports_memory64,
4598
4588
  get_hosted_table_names,
4599
4589
  on_hosted_tables_update,
@@ -4612,6 +4602,7 @@ export {
4612
4602
  VirtualServer,
4613
4603
  WebSocketServer,
4614
4604
  createMessageHandler2 as createMessageHandler,
4605
+ create_validator,
4615
4606
  cwd_static_file_handler,
4616
4607
  perspective_node_default as default,
4617
4608
  get_hosted_table_names,
@@ -4625,6 +4616,7 @@ export {
4625
4616
  remove_hosted_tables_update,
4626
4617
  system_info,
4627
4618
  table,
4619
+ validate,
4628
4620
  perspective_js_exports as wasmModule,
4629
4621
  websocket2 as websocket,
4630
4622
  worker