@ai-matrx/records 0.84.2 → 0.84.4

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.
@@ -339,9 +339,20 @@ function takePrimedDoorAnswer(key) {
339
339
  registry2.delete(key);
340
340
  return null;
341
341
  }
342
- function dropPrimedDoorAnswers() {
343
- doorRegistry().clear();
342
+ function dropPrimedDoorAnswers(doors) {
343
+ const registry2 = doorRegistry();
344
+ if (!doors) {
345
+ registry2.clear();
346
+ return;
347
+ }
348
+ for (const key of [...registry2.keys()]) if (doors.some((door) => key.startsWith(`${door}|`))) registry2.delete(key);
344
349
  }
350
+ var LOOK_WRITES = {
351
+ view_declare: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
352
+ view_designate: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
353
+ view_look_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
354
+ view_record_order_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"]
355
+ };
345
356
  function isWritingDoor(door) {
346
357
  return /(_declare|_set(_|$)|_update|_write|_delete|_restore|_archive|_upsert|_reparent|_change|_duplicate|_move|_decide|_run$|_submit|_publish|_import_|_start$|_complete|_sign$|_add$|_retire|_propose|_promote|_land$|_pin$|_mute|_snooze|_unsnooze|_clear|_unclear|_revoke|_issue|_bind|_unbind|_apply|_backfill|_sync$|_decorate|_designate|_ensure|^migrate_|^home_add|^capture_|^claim_|^record_stage|^anon_|^io_import_|^io_comment_resolve|^enrich_(declare|land|pin)|^field_(declare|duplicate|propose|restore|retire|update)|^table_(declare|ensure|from_example|move|sync)|^value_restore|^relation_own)/.test(door);
347
358
  }
@@ -4543,12 +4554,18 @@ function createRecordsClient(given) {
4543
4554
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
4544
4555
  }
4545
4556
  function primedFor(door, args) {
4557
+ const look = LOOK_WRITES[door];
4558
+ if (look) {
4559
+ dropPrimedDoorAnswers(look);
4560
+ return null;
4561
+ }
4546
4562
  if (isWritingDoor(door)) {
4547
4563
  dropPrimedDoorAnswers();
4548
4564
  return null;
4549
4565
  }
4550
4566
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
4551
4567
  }
4568
+ const readsInFlight = /* @__PURE__ */ new Map();
4552
4569
  async function callDoor(door, args, where) {
4553
4570
  const primed = primedFor(door, args);
4554
4571
  if (primed) return ok(primed.data);
@@ -4559,7 +4576,19 @@ function createRecordsClient(given) {
4559
4576
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });
4560
4577
  return err(refusal3);
4561
4578
  }
4562
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
4579
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
4580
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
4581
+ const response = await (flying ?? (() => {
4582
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
4583
+ if (flightKey) {
4584
+ readsInFlight.set(flightKey, call);
4585
+ const forget = () => {
4586
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
4587
+ };
4588
+ call.then(forget, forget);
4589
+ }
4590
+ return call;
4591
+ })());
4563
4592
  if (response.error) {
4564
4593
  const refusal3 = mapPgError(response.error, where);
4565
4594
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });