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.cjs CHANGED
@@ -1813,7 +1813,8 @@ function parseRetryAfterSeconds(headerValue) {
1813
1813
  return Number.isFinite(seconds) && seconds >= 0 ? seconds : void 0;
1814
1814
  }
1815
1815
  function attachMeta(data, meta, facets) {
1816
- const withMeta = Object.assign(data, { meta });
1816
+ const base = data === void 0 || data === null ? {} : data;
1817
+ const withMeta = Object.assign(base, { meta });
1817
1818
  return facets === void 0 ? withMeta : Object.assign(withMeta, { facets });
1818
1819
  }
1819
1820
  function describeCrossOriginSuspect(url) {
@@ -1979,11 +1980,35 @@ async function runWithLadder(ctx, request, send) {
1979
1980
  throw error;
1980
1981
  }
1981
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
+ }
1982
1993
  function execute(ctx, request) {
1983
- return runWithLadder(ctx, request, async (idempotencyKey) => {
1994
+ const run = () => runWithLadder(ctx, request, async (idempotencyKey) => {
1984
1995
  const { data, meta, facets } = await sendOnce(ctx, request, idempotencyKey);
1985
1996
  return attachMeta(data, meta, facets);
1986
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;
1987
2012
  }
1988
2013
  function executeBinary(ctx, request) {
1989
2014
  return runWithLadder(