@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.
@@ -210,9 +210,20 @@ function takePrimedDoorAnswer(key) {
210
210
  registry2.delete(key);
211
211
  return null;
212
212
  }
213
- function dropPrimedDoorAnswers() {
214
- doorRegistry().clear();
213
+ function dropPrimedDoorAnswers(doors) {
214
+ const registry2 = doorRegistry();
215
+ if (!doors) {
216
+ registry2.clear();
217
+ return;
218
+ }
219
+ for (const key of [...registry2.keys()]) if (doors.some((door) => key.startsWith(`${door}|`))) registry2.delete(key);
215
220
  }
221
+ var LOOK_WRITES = {
222
+ view_declare: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
223
+ view_designate: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
224
+ view_look_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
225
+ view_record_order_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"]
226
+ };
216
227
  function isWritingDoor(door) {
217
228
  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);
218
229
  }
@@ -2713,12 +2724,18 @@ function createRecordsClient(given) {
2713
2724
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
2714
2725
  }
2715
2726
  function primedFor(door, args) {
2727
+ const look = LOOK_WRITES[door];
2728
+ if (look) {
2729
+ dropPrimedDoorAnswers(look);
2730
+ return null;
2731
+ }
2716
2732
  if (isWritingDoor(door)) {
2717
2733
  dropPrimedDoorAnswers();
2718
2734
  return null;
2719
2735
  }
2720
2736
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
2721
2737
  }
2738
+ const readsInFlight = /* @__PURE__ */ new Map();
2722
2739
  async function callDoor(door, args, where) {
2723
2740
  const primed = primedFor(door, args);
2724
2741
  if (primed) return ok(primed.data);
@@ -2729,7 +2746,19 @@ function createRecordsClient(given) {
2729
2746
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
2730
2747
  return err(refusal2);
2731
2748
  }
2732
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
2749
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
2750
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
2751
+ const response = await (flying ?? (() => {
2752
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
2753
+ if (flightKey) {
2754
+ readsInFlight.set(flightKey, call);
2755
+ const forget = () => {
2756
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
2757
+ };
2758
+ call.then(forget, forget);
2759
+ }
2760
+ return call;
2761
+ })());
2733
2762
  if (response.error) {
2734
2763
  const refusal2 = mapPgError(response.error, where);
2735
2764
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });