@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.
@@ -5993,6 +5993,7 @@ function createRecordsClient(given) {
5993
5993
  }
5994
5994
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
5995
5995
  }
5996
+ const readsInFlight = /* @__PURE__ */ new Map();
5996
5997
  async function callDoor(door, args, where) {
5997
5998
  const primed = primedFor(door, args);
5998
5999
  if (primed) return ok(primed.data);
@@ -6003,7 +6004,19 @@ function createRecordsClient(given) {
6003
6004
  scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
6004
6005
  return err(refusal);
6005
6006
  }
6006
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
6007
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
6008
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
6009
+ const response = await (flying ?? (() => {
6010
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
6011
+ if (flightKey) {
6012
+ readsInFlight.set(flightKey, call);
6013
+ const forget = () => {
6014
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
6015
+ };
6016
+ call.then(forget, forget);
6017
+ }
6018
+ return call;
6019
+ })());
6007
6020
  if (response.error) {
6008
6021
  const refusal = mapPgError(response.error, where);
6009
6022
  scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });