@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.
@@ -2891,6 +2891,7 @@ function createRecordsClient(given) {
2891
2891
  }
2892
2892
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
2893
2893
  }
2894
+ const readsInFlight = /* @__PURE__ */ new Map();
2894
2895
  async function callDoor(door, args, where) {
2895
2896
  const primed = primedFor(door, args);
2896
2897
  if (primed) return ok(primed.data);
@@ -2901,7 +2902,19 @@ function createRecordsClient(given) {
2901
2902
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
2902
2903
  return err(refusal2);
2903
2904
  }
2904
- 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
+ })());
2905
2918
  if (response.error) {
2906
2919
  const refusal2 = mapPgError(response.error, where);
2907
2920
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });