@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.
@@ -4277,6 +4277,7 @@ function createRecordsClient(given) {
4277
4277
  }
4278
4278
  return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
4279
4279
  }
4280
+ const readsInFlight = /* @__PURE__ */ new Map();
4280
4281
  async function callDoor(door, args, where) {
4281
4282
  const primed = primedFor(door, args);
4282
4283
  if (primed) return ok(primed.data);
@@ -4287,7 +4288,19 @@ function createRecordsClient(given) {
4287
4288
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });
4288
4289
  return err(refusal3);
4289
4290
  }
4290
- const response = await config.dataSource.rpc(`${door}`, args, { schema });
4291
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
4292
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
4293
+ const response = await (flying ?? (() => {
4294
+ const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
4295
+ if (flightKey) {
4296
+ readsInFlight.set(flightKey, call);
4297
+ const forget = () => {
4298
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
4299
+ };
4300
+ call.then(forget, forget);
4301
+ }
4302
+ return call;
4303
+ })());
4291
4304
  if (response.error) {
4292
4305
  const refusal3 = mapPgError(response.error, where);
4293
4306
  scream({ code: refusal3.code, message: refusal3.message, ...refusal3.hint ? { hint: refusal3.hint } : {}, where });