kaafil-js 0.6.1 → 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.js CHANGED
@@ -1811,7 +1811,8 @@ function parseRetryAfterSeconds(headerValue) {
1811
1811
  return Number.isFinite(seconds) && seconds >= 0 ? seconds : void 0;
1812
1812
  }
1813
1813
  function attachMeta(data, meta, facets) {
1814
- const withMeta = Object.assign(data, { meta });
1814
+ const base = data === void 0 || data === null ? {} : data;
1815
+ const withMeta = Object.assign(base, { meta });
1815
1816
  return facets === void 0 ? withMeta : Object.assign(withMeta, { facets });
1816
1817
  }
1817
1818
  function describeCrossOriginSuspect(url) {
@@ -1977,11 +1978,35 @@ async function runWithLadder(ctx, request, send) {
1977
1978
  throw error;
1978
1979
  }
1979
1980
  }
1981
+ var inFlightReads = /* @__PURE__ */ new WeakMap();
1982
+ function readKey(request) {
1983
+ return [
1984
+ request.operationId,
1985
+ request.path,
1986
+ JSON.stringify(request.pathParams ?? {}),
1987
+ JSON.stringify(request.query ?? {}),
1988
+ JSON.stringify(request.headers ?? {})
1989
+ ].join("|");
1990
+ }
1980
1991
  function execute(ctx, request) {
1981
- return runWithLadder(ctx, request, async (idempotencyKey) => {
1992
+ const run = () => runWithLadder(ctx, request, async (idempotencyKey) => {
1982
1993
  const { data, meta, facets } = await sendOnce(ctx, request, idempotencyKey);
1983
1994
  return attachMeta(data, meta, facets);
1984
1995
  });
1996
+ if (request.method !== "GET" || request.signal !== void 0) return run();
1997
+ let perClient = inFlightReads.get(ctx);
1998
+ if (perClient === void 0) {
1999
+ perClient = /* @__PURE__ */ new Map();
2000
+ inFlightReads.set(ctx, perClient);
2001
+ }
2002
+ const key = readKey(request);
2003
+ const existing = perClient.get(key);
2004
+ if (existing !== void 0) return existing;
2005
+ const started = run().finally(() => {
2006
+ perClient.delete(key);
2007
+ });
2008
+ perClient.set(key, started);
2009
+ return started;
1985
2010
  }
1986
2011
  function executeBinary(ctx, request) {
1987
2012
  return runWithLadder(