@ai-matrx/records 0.84.3 → 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.
@@ -2779,6 +2779,7 @@ function createRecordsClient(given) {
2779
2779
  }
2780
2780
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
2781
2781
  }
2782
+ const readsInFlight = /* @__PURE__ */ new Map();
2782
2783
  async function callDoor(door, args, where) {
2783
2784
  const primed = primedFor(door, args);
2784
2785
  if (primed) return ok(primed.data);
@@ -2789,7 +2790,19 @@ function createRecordsClient(given) {
2789
2790
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
2790
2791
  return err(refusal2);
2791
2792
  }
2792
- 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
+ })());
2793
2806
  if (response.error) {
2794
2807
  const refusal2 = mapPgError(response.error, where);
2795
2808
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });