@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.
@@ -390,9 +390,20 @@ function takePrimedDoorAnswer(key) {
390
390
  registry2.delete(key);
391
391
  return null;
392
392
  }
393
- function dropPrimedDoorAnswers() {
394
- doorRegistry().clear();
393
+ function dropPrimedDoorAnswers(doors) {
394
+ const registry2 = doorRegistry();
395
+ if (!doors) {
396
+ registry2.clear();
397
+ return;
398
+ }
399
+ for (const key of [...registry2.keys()]) if (doors.some((door) => key.startsWith(`${door}|`))) registry2.delete(key);
395
400
  }
401
+ var LOOK_WRITES = {
402
+ view_declare: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
403
+ view_designate: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
404
+ view_look_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"],
405
+ view_record_order_set: ["views", "view_look_read", "grid_layout", "table_page_bundle"]
406
+ };
396
407
  function isWritingDoor(door) {
397
408
  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);
398
409
  }
@@ -2869,12 +2880,18 @@ function createRecordsClient(given) {
2869
2880
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
2870
2881
  }
2871
2882
  function primedFor(door, args) {
2883
+ const look = LOOK_WRITES[door];
2884
+ if (look) {
2885
+ dropPrimedDoorAnswers(look);
2886
+ return null;
2887
+ }
2872
2888
  if (isWritingDoor(door)) {
2873
2889
  dropPrimedDoorAnswers();
2874
2890
  return null;
2875
2891
  }
2876
2892
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
2877
2893
  }
2894
+ const readsInFlight = /* @__PURE__ */ new Map();
2878
2895
  async function callDoor(door, args, where) {
2879
2896
  const primed = primedFor(door, args);
2880
2897
  if (primed) return ok(primed.data);
@@ -2885,7 +2902,19 @@ function createRecordsClient(given) {
2885
2902
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
2886
2903
  return err(refusal2);
2887
2904
  }
2888
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
2905
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
2906
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
2907
+ const response = await (flying ?? (() => {
2908
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
2909
+ if (flightKey) {
2910
+ readsInFlight.set(flightKey, call);
2911
+ const forget = () => {
2912
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
2913
+ };
2914
+ call.then(forget, forget);
2915
+ }
2916
+ return call;
2917
+ })());
2889
2918
  if (response.error) {
2890
2919
  const refusal2 = mapPgError(response.error, where);
2891
2920
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });