@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.
@@ -254,9 +254,20 @@ function takePrimedDoorAnswer(key) {
254
254
  registry2.delete(key);
255
255
  return null;
256
256
  }
257
- function dropPrimedDoorAnswers() {
258
- doorRegistry().clear();
257
+ function dropPrimedDoorAnswers(doors) {
258
+ const registry2 = doorRegistry();
259
+ if (!doors) {
260
+ registry2.clear();
261
+ return;
262
+ }
263
+ for (const key of [...registry2.keys()]) if (doors.some((door) => key.startsWith(`${door}|`))) registry2.delete(key);
259
264
  }
265
+ var LOOK_WRITES = {
266
+ view_declare: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
267
+ view_designate: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
268
+ view_look_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
269
+ view_record_order_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"]
270
+ };
260
271
  function isWritingDoor(door) {
261
272
  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);
262
273
  }
@@ -2757,12 +2768,18 @@ function createRecordsClient(given) {
2757
2768
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
2758
2769
  }
2759
2770
  function primedFor(door, args) {
2771
+ const look = LOOK_WRITES[door];
2772
+ if (look) {
2773
+ dropPrimedDoorAnswers(look);
2774
+ return null;
2775
+ }
2760
2776
  if (isWritingDoor(door)) {
2761
2777
  dropPrimedDoorAnswers();
2762
2778
  return null;
2763
2779
  }
2764
2780
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
2765
2781
  }
2782
+ const readsInFlight = /* @__PURE__ */ new Map();
2766
2783
  async function callDoor(door, args, where) {
2767
2784
  const primed = primedFor(door, args);
2768
2785
  if (primed) return ok(primed.data);
@@ -2773,7 +2790,19 @@ function createRecordsClient(given) {
2773
2790
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
2774
2791
  return err(refusal2);
2775
2792
  }
2776
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
2793
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
2794
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
2795
+ const response = await (flying ?? (() => {
2796
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
2797
+ if (flightKey) {
2798
+ readsInFlight.set(flightKey, call);
2799
+ const forget = () => {
2800
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
2801
+ };
2802
+ call.then(forget, forget);
2803
+ }
2804
+ return call;
2805
+ })());
2777
2806
  if (response.error) {
2778
2807
  const refusal2 = mapPgError(response.error, where);
2779
2808
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });