@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.
@@ -4565,6 +4565,7 @@ function createRecordsClient(given) {
4565
4565
  }
4566
4566
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
4567
4567
  }
4568
+ const readsInFlight = /* @__PURE__ */ new Map();
4568
4569
  async function callDoor(door, args, where) {
4569
4570
  const primed = primedFor(door, args);
4570
4571
  if (primed) return ok(primed.data);
@@ -4575,7 +4576,19 @@ function createRecordsClient(given) {
4575
4576
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });
4576
4577
  return err(refusal3);
4577
4578
  }
4578
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
4579
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
4580
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
4581
+ const response = await (flying ?? (() => {
4582
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
4583
+ if (flightKey) {
4584
+ readsInFlight.set(flightKey, call);
4585
+ const forget = () => {
4586
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
4587
+ };
4588
+ call.then(forget, forget);
4589
+ }
4590
+ return call;
4591
+ })());
4579
4592
  if (response.error) {
4580
4593
  const refusal3 = mapPgError(response.error, where);
4581
4594
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });