@perspective-dev/client 5.5.1 → 5.6.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 (38) hide show
  1. package/README.md +66 -2
  2. package/dist/cdn/perspective-server.worker.js +1 -1
  3. package/dist/cdn/perspective-server.worker.js.map +3 -3
  4. package/dist/cdn/perspective.js +2 -2
  5. package/dist/cdn/perspective.js.map +4 -4
  6. package/dist/esm/perspective.js +2 -2
  7. package/dist/esm/perspective.js.map +4 -4
  8. package/dist/esm/perspective.node.js +200 -66
  9. package/dist/esm/perspective.node.js.map +2 -2
  10. package/dist/esm/ts-rs/Features.d.ts +5 -0
  11. package/dist/esm/ts-rs/TableInitOptions.d.ts +8 -0
  12. package/dist/esm/ts-rs/TypedArrayWindow.d.ts +5 -4
  13. package/dist/esm/ts-rs/ViewWindow.d.ts +5 -4
  14. package/dist/esm/virtual_servers/clickhouse.js +1 -1
  15. package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
  16. package/dist/esm/virtual_servers/duckdb.d.ts +7 -1
  17. package/dist/esm/virtual_servers/duckdb.js +1 -1
  18. package/dist/esm/virtual_servers/duckdb.js.map +3 -3
  19. package/dist/wasm/perspective-js.d.ts +97 -19
  20. package/dist/wasm/perspective-js.js +172 -45
  21. package/dist/wasm/perspective-js.wasm +0 -0
  22. package/dist/wasm/perspective-js.wasm.d.ts +11 -7
  23. package/package.json +20 -15
  24. package/src/rust/client.rs +2 -1
  25. package/src/rust/generic_sql_model.rs +70 -6
  26. package/src/rust/table.rs +33 -1
  27. package/src/rust/view.rs +14 -5
  28. package/src/rust/virtual_server.rs +101 -23
  29. package/src/ts/ts-rs/Features.ts +6 -1
  30. package/src/ts/ts-rs/TableInitOptions.ts +7 -1
  31. package/src/ts/ts-rs/TypedArrayWindow.ts +5 -4
  32. package/src/ts/ts-rs/ViewWindow.ts +5 -4
  33. package/src/ts/virtual_servers/clickhouse.ts +99 -4
  34. package/src/ts/virtual_servers/duckdb.ts +116 -6
  35. package/src/ts/wasm/engine.ts +26 -35
  36. package/dist/esm/perspective.inline.js +0 -3
  37. package/dist/esm/perspective.inline.js.map +0 -7
  38. package/src/ts/perspective.inline.ts +0 -27
@@ -395,6 +395,67 @@ var GenericSQLVirtualServerModel = class {
395
395
  const ptr = this.__destroy_into_raw();
396
396
  wasm.__wbg_genericsqlvirtualservermodel_free(ptr, 0);
397
397
  }
398
+ /**
399
+ * Returns the SQL query that plans ONE expression against a table - for
400
+ * attributing a failed `expressionsDescribe` to the expressions at fault.
401
+ * @param {string} table_id
402
+ * @param {string} expression
403
+ * @returns {string}
404
+ */
405
+ expressionDescribe(table_id, expression) {
406
+ try {
407
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
408
+ const ptr0 = passStringToWasm0(table_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
409
+ const len0 = WASM_VECTOR_LEN;
410
+ const ptr1 = passStringToWasm0(expression, wasm.__wbindgen_export, wasm.__wbindgen_export2);
411
+ const len1 = WASM_VECTOR_LEN;
412
+ wasm.genericsqlvirtualservermodel_expressionDescribe(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
413
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
414
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
415
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
416
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
417
+ if (r3) {
418
+ throw takeObject(r2);
419
+ }
420
+ var v3 = getCachedStringFromWasm0(r0, r1);
421
+ if (r0 !== 0) {
422
+ wasm.__wbindgen_export4(r0, r1, 1);
423
+ }
424
+ return v3;
425
+ } finally {
426
+ wasm.__wbindgen_add_to_stack_pointer(16);
427
+ }
428
+ }
429
+ /**
430
+ * Returns the SQL query that plans every expression of `config` at once
431
+ * against a table, one result column per expression alias, or `undefined`
432
+ * when the config has no expressions.
433
+ * @param {string} table_id
434
+ * @param {any} config
435
+ * @returns {string}
436
+ */
437
+ expressionsDescribe(table_id, config) {
438
+ try {
439
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
440
+ const ptr0 = passStringToWasm0(table_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
441
+ const len0 = WASM_VECTOR_LEN;
442
+ wasm.genericsqlvirtualservermodel_expressionsDescribe(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(config));
443
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
444
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
445
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
446
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
447
+ if (r3) {
448
+ throw takeObject(r2);
449
+ }
450
+ var v2 = getCachedStringFromWasm0(r0, r1);
451
+ if (r0 !== 0) {
452
+ wasm.__wbindgen_export4(r0, r1, 1);
453
+ }
454
+ return v2;
455
+ } finally {
456
+ wasm.__wbindgen_add_to_stack_pointer(16);
457
+ }
458
+ }
398
459
  /**
399
460
  * Returns the SQL query to list all hosted tables.
400
461
  * @returns {string}
@@ -441,22 +502,21 @@ var GenericSQLVirtualServerModel = class {
441
502
  }
442
503
  }
443
504
  /**
444
- * Returns the SQL query to create a view from a table with the given
445
- * configuration.
505
+ * Returns the SQL query that plans the view `config` would build and
506
+ * reports its result columns without materializing it (`split_by` folded
507
+ * into `group_by`, no `PIVOT`), or `undefined` when the config selects no
508
+ * columns.
446
509
  * @param {string} table_id
447
- * @param {string} view_id
448
510
  * @param {any} config
449
511
  * @param {any} schema
450
512
  * @returns {string}
451
513
  */
452
- tableMakeView(table_id, view_id, config, schema) {
514
+ tableDescribe(table_id, config, schema) {
453
515
  try {
454
516
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
455
517
  const ptr0 = passStringToWasm0(table_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
456
518
  const len0 = WASM_VECTOR_LEN;
457
- const ptr1 = passStringToWasm0(view_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
458
- const len1 = WASM_VECTOR_LEN;
459
- wasm.genericsqlvirtualservermodel_tableMakeView(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(config), addHeapObject(schema));
519
+ wasm.genericsqlvirtualservermodel_tableDescribe(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(config), addHeapObject(schema));
460
520
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
461
521
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
462
522
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -464,26 +524,32 @@ var GenericSQLVirtualServerModel = class {
464
524
  if (r3) {
465
525
  throw takeObject(r2);
466
526
  }
467
- var v3 = getCachedStringFromWasm0(r0, r1);
527
+ var v2 = getCachedStringFromWasm0(r0, r1);
468
528
  if (r0 !== 0) {
469
529
  wasm.__wbindgen_export4(r0, r1, 1);
470
530
  }
471
- return v3;
531
+ return v2;
472
532
  } finally {
473
533
  wasm.__wbindgen_add_to_stack_pointer(16);
474
534
  }
475
535
  }
476
536
  /**
477
- * Returns the SQL query to describe a table's schema.
537
+ * Returns the SQL query to create a view from a table with the given
538
+ * configuration.
478
539
  * @param {string} table_id
540
+ * @param {string} view_id
541
+ * @param {any} config
542
+ * @param {any} schema
479
543
  * @returns {string}
480
544
  */
481
- tableSchema(table_id) {
545
+ tableMakeView(table_id, view_id, config, schema) {
482
546
  try {
483
547
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
484
548
  const ptr0 = passStringToWasm0(table_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
485
549
  const len0 = WASM_VECTOR_LEN;
486
- wasm.genericsqlvirtualservermodel_tableSchema(retptr, this.__wbg_ptr, ptr0, len0);
550
+ const ptr1 = passStringToWasm0(view_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
551
+ const len1 = WASM_VECTOR_LEN;
552
+ wasm.genericsqlvirtualservermodel_tableMakeView(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(config), addHeapObject(schema));
487
553
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
488
554
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
489
555
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -491,26 +557,26 @@ var GenericSQLVirtualServerModel = class {
491
557
  if (r3) {
492
558
  throw takeObject(r2);
493
559
  }
494
- var v2 = getCachedStringFromWasm0(r0, r1);
560
+ var v3 = getCachedStringFromWasm0(r0, r1);
495
561
  if (r0 !== 0) {
496
562
  wasm.__wbindgen_export4(r0, r1, 1);
497
563
  }
498
- return v2;
564
+ return v3;
499
565
  } finally {
500
566
  wasm.__wbindgen_add_to_stack_pointer(16);
501
567
  }
502
568
  }
503
569
  /**
504
- * Returns the SQL query to get the row count of a table.
570
+ * Returns the SQL query to describe a table's schema.
505
571
  * @param {string} table_id
506
572
  * @returns {string}
507
573
  */
508
- tableSize(table_id) {
574
+ tableSchema(table_id) {
509
575
  try {
510
576
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
511
577
  const ptr0 = passStringToWasm0(table_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
512
578
  const len0 = WASM_VECTOR_LEN;
513
- wasm.genericsqlvirtualservermodel_tableSize(retptr, this.__wbg_ptr, ptr0, len0);
579
+ wasm.genericsqlvirtualservermodel_tableSchema(retptr, this.__wbg_ptr, ptr0, len0);
514
580
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
515
581
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
516
582
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -528,19 +594,16 @@ var GenericSQLVirtualServerModel = class {
528
594
  }
529
595
  }
530
596
  /**
531
- * Returns the SQL query to validate an expression against a table.
597
+ * Returns the SQL query to get the row count of a table.
532
598
  * @param {string} table_id
533
- * @param {string} expression
534
599
  * @returns {string}
535
600
  */
536
- tableValidateExpression(table_id, expression) {
601
+ tableSize(table_id) {
537
602
  try {
538
603
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
539
604
  const ptr0 = passStringToWasm0(table_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
540
605
  const len0 = WASM_VECTOR_LEN;
541
- const ptr1 = passStringToWasm0(expression, wasm.__wbindgen_export, wasm.__wbindgen_export2);
542
- const len1 = WASM_VECTOR_LEN;
543
- wasm.genericsqlvirtualservermodel_tableValidateExpression(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
606
+ wasm.genericsqlvirtualservermodel_tableSize(retptr, this.__wbg_ptr, ptr0, len0);
544
607
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
545
608
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
546
609
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -548,11 +611,11 @@ var GenericSQLVirtualServerModel = class {
548
611
  if (r3) {
549
612
  throw takeObject(r2);
550
613
  }
551
- var v3 = getCachedStringFromWasm0(r0, r1);
614
+ var v2 = getCachedStringFromWasm0(r0, r1);
552
615
  if (r0 !== 0) {
553
616
  wasm.__wbindgen_export4(r0, r1, 1);
554
617
  }
555
- return v3;
618
+ return v2;
556
619
  } finally {
557
620
  wasm.__wbindgen_add_to_stack_pointer(16);
558
621
  }
@@ -672,6 +735,39 @@ var GenericSQLVirtualServerModel = class {
672
735
  wasm.__wbindgen_add_to_stack_pointer(16);
673
736
  }
674
737
  }
738
+ /**
739
+ * Returns the SQL query to create a table from a view.
740
+ * @param {string} view_id
741
+ * @param {string} table_id
742
+ * @param {any} config
743
+ * @param {any} view_schema
744
+ * @param {any} schema
745
+ * @returns {string}
746
+ */
747
+ viewMakeTable(view_id, table_id, config, view_schema, schema) {
748
+ try {
749
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
750
+ const ptr0 = passStringToWasm0(view_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
751
+ const len0 = WASM_VECTOR_LEN;
752
+ const ptr1 = passStringToWasm0(table_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
753
+ const len1 = WASM_VECTOR_LEN;
754
+ wasm.genericsqlvirtualservermodel_viewMakeTable(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(config), addHeapObject(view_schema), addHeapObject(schema));
755
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
756
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
757
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
758
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
759
+ if (r3) {
760
+ throw takeObject(r2);
761
+ }
762
+ var v3 = getCachedStringFromWasm0(r0, r1);
763
+ if (r0 !== 0) {
764
+ wasm.__wbindgen_export4(r0, r1, 1);
765
+ }
766
+ return v3;
767
+ } finally {
768
+ wasm.__wbindgen_add_to_stack_pointer(16);
769
+ }
770
+ }
675
771
  /**
676
772
  * Returns the SQL query to describe a view's schema.
677
773
  * @param {string} view_id
@@ -878,6 +974,30 @@ var Table = class _Table {
878
974
  const ret = wasm.table_delete(ptr, isLikeNone(options) ? 0 : addHeapObject(options));
879
975
  return takeObject(ret);
880
976
  }
977
+ /**
978
+ * Validate a complete view config against this table and report the
979
+ * schema a [`View`] built from it would have, WITHOUT creating one.
980
+ *
981
+ * # JavaScript Examples
982
+ *
983
+ * ```javascript
984
+ * const verdict = await table.describe({
985
+ * columns: ["Sales", "margin"],
986
+ * group_by: ["Region"],
987
+ * expressions: { margin: '"Profit" / "Sales"' },
988
+ * });
989
+ *
990
+ * if ("view_schema" in verdict) {
991
+ * const view = await table.view(config);
992
+ * }
993
+ * ```
994
+ * @param {ViewConfigUpdate | null} [config]
995
+ * @returns {Promise<any>}
996
+ */
997
+ describe(config) {
998
+ const ret = wasm.table_describe(this.__wbg_ptr, isLikeNone(config) ? 0 : addHeapObject(config));
999
+ return takeObject(ret);
1000
+ }
881
1001
  /**
882
1002
  * Get a copy of the [`Client`] this [`Table`] came from.
883
1003
  * @returns {Promise<Client>}
@@ -1154,13 +1274,22 @@ var View = class _View {
1154
1274
  return takeObject(ret);
1155
1275
  }
1156
1276
  /**
1157
- * Returns an array of strings containing the column paths of the [`View`]
1158
- * without any of the source columns.
1277
+ * Returns this [`View`]'s column header area for `window`, transposed as
1278
+ * `area[level][column]`.
1159
1279
  *
1160
1280
  * A column path shows the columns that a given cell belongs to after
1161
- * pivots are applied.
1281
+ * pivots are applied. The area is rectangular with one level per
1282
+ * `split_by` plus one: a column's split values occupy the leading levels
1283
+ * and its name always occupies the last, so a subtotal or grand total
1284
+ * under `split_rollup_mode: "rollup"` reads `null` at the levels it does
1285
+ * not pivot on. Values keep their column's type - a `datetime` split value
1286
+ * is epoch milliseconds, not text - so formatting them is the caller's
1287
+ * choice.
1288
+ *
1289
+ * `window` slices the *column* axis; the number of levels does not depend
1290
+ * on it.
1162
1291
  * @param {ColumnWindow | null} [window]
1163
- * @returns {Promise<any>}
1292
+ * @returns {(string | number | boolean | null)[][]}
1164
1293
  */
1165
1294
  column_paths(window2) {
1166
1295
  const ret = wasm.view_column_paths(this.__wbg_ptr, isLikeNone(window2) ? 0 : addHeapObject(window2));
@@ -2082,7 +2211,7 @@ function __wbg_get_imports() {
2082
2211
  const a = state0.a;
2083
2212
  state0.a = 0;
2084
2213
  try {
2085
- return __wasm_bindgen_func_elem_12577(a, state0.b, arg02, arg12);
2214
+ return __wasm_bindgen_func_elem_13017(a, state0.b, arg02, arg12);
2086
2215
  } finally {
2087
2216
  state0.a = a;
2088
2217
  }
@@ -2161,7 +2290,7 @@ function __wbg_get_imports() {
2161
2290
  const ret = Promise.resolve(getObject(arg0));
2162
2291
  return addHeapObject(ret);
2163
2292
  },
2164
- __wbg_run_556972011e45ec00: function() {
2293
+ __wbg_run_56500aec144102b2: function() {
2165
2294
  return handleError(function(arg0, arg1) {
2166
2295
  const ret = getObject(arg0).run(getObject(arg1));
2167
2296
  return addHeapObject(ret);
@@ -2174,6 +2303,12 @@ function __wbg_get_imports() {
2174
2303
  __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
2175
2304
  getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
2176
2305
  },
2306
+ __wbg_set_6cb8631f80447a67: function() {
2307
+ return handleError(function(arg0, arg1, arg2) {
2308
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
2309
+ return ret;
2310
+ }, arguments);
2311
+ },
2177
2312
  __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
2178
2313
  getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
2179
2314
  },
@@ -2252,15 +2387,15 @@ function __wbg_get_imports() {
2252
2387
  console.warn(getObject(arg0));
2253
2388
  },
2254
2389
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
2255
- const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1222, __wasm_bindgen_func_elem_1955);
2390
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1688, __wasm_bindgen_func_elem_2057);
2256
2391
  return addHeapObject(ret);
2257
2392
  },
2258
2393
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
2259
- const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1222, __wasm_bindgen_func_elem_1956);
2394
+ const ret = makeClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_1688, __wasm_bindgen_func_elem_2058);
2260
2395
  return addHeapObject(ret);
2261
2396
  },
2262
2397
  __wbindgen_cast_0000000000000003: function(arg0, arg1) {
2263
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4376, __wasm_bindgen_func_elem_4393);
2398
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_4639, __wasm_bindgen_func_elem_4641);
2264
2399
  return addHeapObject(ret);
2265
2400
  },
2266
2401
  __wbindgen_cast_0000000000000004: function(arg0) {
@@ -2325,18 +2460,18 @@ function __wbg_get_imports() {
2325
2460
  "./perspective-js.wasm_bg.js": import0
2326
2461
  };
2327
2462
  }
2328
- function __wasm_bindgen_func_elem_1956(arg0, arg1) {
2329
- wasm.__wasm_bindgen_func_elem_1956(arg0, arg1);
2463
+ function __wasm_bindgen_func_elem_2058(arg0, arg1) {
2464
+ wasm.__wasm_bindgen_func_elem_2058(arg0, arg1);
2330
2465
  }
2331
- function __wasm_bindgen_func_elem_1955(arg0, arg1) {
2332
- const ret = wasm.__wasm_bindgen_func_elem_1955(arg0, arg1);
2466
+ function __wasm_bindgen_func_elem_2057(arg0, arg1) {
2467
+ const ret = wasm.__wasm_bindgen_func_elem_2057(arg0, arg1);
2333
2468
  return takeObject(ret);
2334
2469
  }
2335
- function __wasm_bindgen_func_elem_4393(arg0, arg1, arg2) {
2336
- wasm.__wasm_bindgen_func_elem_4393(arg0, arg1, addHeapObject(arg2));
2470
+ function __wasm_bindgen_func_elem_4641(arg0, arg1, arg2) {
2471
+ wasm.__wasm_bindgen_func_elem_4641(arg0, arg1, addHeapObject(arg2));
2337
2472
  }
2338
- function __wasm_bindgen_func_elem_12577(arg0, arg1, arg2, arg3) {
2339
- wasm.__wasm_bindgen_func_elem_12577(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2473
+ function __wasm_bindgen_func_elem_13017(arg0, arg1, arg2, arg3) {
2474
+ wasm.__wasm_bindgen_func_elem_13017(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2340
2475
  }
2341
2476
  var ClientFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
2342
2477
  }, unregister: () => {
@@ -2892,48 +3027,47 @@ async function convert_typed_array_to_pointer(core, array, callback) {
2892
3027
  }
2893
3028
  async function decode_api_responses(core, ptr, callback) {
2894
3029
  const is_64 = core._psp_is_memory64();
3030
+ const response_ptr = is_64 ? Number(ptr) : Number(ptr) >>> 0;
2895
3031
  const response = new DataView(
2896
3032
  core.HEAPU8.buffer,
2897
- is_64 ? Number(ptr) : Number(ptr) >>> 0,
3033
+ response_ptr,
2898
3034
  is_64 ? 12 : 8
2899
3035
  );
2900
3036
  const num_msgs = response.getUint32(0, true);
2901
- const msgs_ptr = is_64 ? response.getBigInt64(4, true) : response.getUint32(4, true);
3037
+ const msgs_ptr = Number(
3038
+ is_64 ? response.getBigInt64(4, true) : response.getUint32(4, true)
3039
+ );
2902
3040
  const messages = new DataView(
2903
3041
  core.HEAPU8.buffer,
2904
- Number(msgs_ptr),
3042
+ msgs_ptr,
2905
3043
  num_msgs * (is_64 ? 16 : 12)
2906
3044
  );
2907
- try {
2908
- for (let i = 0; i < num_msgs; i++) {
2909
- const [data_ptr, data_len, client_id] = is_64 ? [
2910
- messages.getBigInt64(i * 16, true),
3045
+ const free = (x) => core._psp_free(is_64 ? BigInt(x) : x);
3046
+ const descriptors = [];
3047
+ for (let i = 0; i < num_msgs; i++) {
3048
+ descriptors.push(
3049
+ is_64 ? [
3050
+ Number(messages.getBigInt64(i * 16, true)),
2911
3051
  messages.getInt32(i * 16 + 8, true),
2912
3052
  messages.getInt32(i * 16 + 12, true)
2913
3053
  ] : [
2914
3054
  messages.getUint32(i * 12, true),
2915
3055
  messages.getUint32(i * 12 + 4, true),
2916
3056
  messages.getInt32(i * 12 + 8, true)
2917
- ];
2918
- const data = new Uint8Array(
2919
- core.HEAPU8.buffer,
2920
- Number(data_ptr),
2921
- data_len
2922
- );
2923
- const resp = { client_id, data };
2924
- await callback(resp);
3057
+ ]
3058
+ );
3059
+ }
3060
+ try {
3061
+ for (const [data_ptr, data_len, client_id] of descriptors) {
3062
+ const data = new Uint8Array(core.HEAPU8.buffer, data_ptr, data_len);
3063
+ await callback({ client_id, data });
2925
3064
  }
2926
3065
  } finally {
2927
- for (let i = 0; i < num_msgs; i++) {
2928
- const data_ptr = is_64 ? messages.getBigInt64(i * 16, true) : messages.getInt32(i * 12, true);
2929
- core._psp_free(data_ptr);
3066
+ for (const [data_ptr] of descriptors) {
3067
+ free(data_ptr);
2930
3068
  }
2931
- core._psp_free(
2932
- is_64 ? BigInt(messages.byteOffset) : messages.byteOffset
2933
- );
2934
- core._psp_free(
2935
- is_64 ? BigInt(response.byteOffset) : response.byteOffset
2936
- );
3069
+ free(msgs_ptr);
3070
+ free(response_ptr);
2937
3071
  }
2938
3072
  }
2939
3073