@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.
@@ -2735,6 +2735,7 @@ function createRecordsClient(given) {
2735
2735
  }
2736
2736
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
2737
2737
  }
2738
+ const readsInFlight = /* @__PURE__ */ new Map();
2738
2739
  async function callDoor(door, args, where) {
2739
2740
  const primed = primedFor(door, args);
2740
2741
  if (primed) return ok(primed.data);
@@ -2745,7 +2746,19 @@ function createRecordsClient(given) {
2745
2746
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
2746
2747
  return err(refusal2);
2747
2748
  }
2748
- 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
+ })());
2749
2762
  if (response.error) {
2750
2763
  const refusal2 = mapPgError(response.error, where);
2751
2764
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });