@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.
@@ -6293,6 +6293,7 @@ function createRecordsClient(given) {
6293
6293
  }
6294
6294
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
6295
6295
  }
6296
+ const readsInFlight = /* @__PURE__ */ new Map();
6296
6297
  async function callDoor(door, args, where) {
6297
6298
  const primed = primedFor(door, args);
6298
6299
  if (primed) return ok(primed.data);
@@ -6303,7 +6304,19 @@ function createRecordsClient(given) {
6303
6304
  scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
6304
6305
  return err(refusal);
6305
6306
  }
6306
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
6307
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
6308
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
6309
+ const response = await (flying ?? (() => {
6310
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
6311
+ if (flightKey) {
6312
+ readsInFlight.set(flightKey, call);
6313
+ const forget = () => {
6314
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
6315
+ };
6316
+ call.then(forget, forget);
6317
+ }
6318
+ return call;
6319
+ })());
6307
6320
  if (response.error) {
6308
6321
  const refusal = mapPgError(response.error, where);
6309
6322
  scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });