kaafil-js 0.6.2 → 0.7.0

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.
package/dist/index.cjs CHANGED
@@ -1980,11 +1980,35 @@ async function runWithLadder(ctx, request, send) {
1980
1980
  throw error;
1981
1981
  }
1982
1982
  }
1983
+ var inFlightReads = /* @__PURE__ */ new WeakMap();
1984
+ function readKey(request) {
1985
+ return [
1986
+ request.operationId,
1987
+ request.path,
1988
+ JSON.stringify(request.pathParams ?? {}),
1989
+ JSON.stringify(request.query ?? {}),
1990
+ JSON.stringify(request.headers ?? {})
1991
+ ].join("|");
1992
+ }
1983
1993
  function execute(ctx, request) {
1984
- return runWithLadder(ctx, request, async (idempotencyKey) => {
1994
+ const run = () => runWithLadder(ctx, request, async (idempotencyKey) => {
1985
1995
  const { data, meta, facets } = await sendOnce(ctx, request, idempotencyKey);
1986
1996
  return attachMeta(data, meta, facets);
1987
1997
  });
1998
+ if (request.method !== "GET" || request.signal !== void 0) return run();
1999
+ let perClient = inFlightReads.get(ctx);
2000
+ if (perClient === void 0) {
2001
+ perClient = /* @__PURE__ */ new Map();
2002
+ inFlightReads.set(ctx, perClient);
2003
+ }
2004
+ const key = readKey(request);
2005
+ const existing = perClient.get(key);
2006
+ if (existing !== void 0) return existing;
2007
+ const started = run().finally(() => {
2008
+ perClient.delete(key);
2009
+ });
2010
+ perClient.set(key, started);
2011
+ return started;
1988
2012
  }
1989
2013
  function executeBinary(ctx, request) {
1990
2014
  return runWithLadder(