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.
@@ -1759,7 +1759,8 @@ function parseRetryAfterSeconds(headerValue) {
1759
1759
  return Number.isFinite(seconds) && seconds >= 0 ? seconds : void 0;
1760
1760
  }
1761
1761
  function attachMeta(data, meta, facets) {
1762
- const withMeta = Object.assign(data, { meta });
1762
+ const base = data === void 0 || data === null ? {} : data;
1763
+ const withMeta = Object.assign(base, { meta });
1763
1764
  return facets === void 0 ? withMeta : Object.assign(withMeta, { facets });
1764
1765
  }
1765
1766
  function describeCrossOriginSuspect(url) {
@@ -1978,11 +1979,35 @@ async function runWithLadder(ctx, request, send) {
1978
1979
  throw error;
1979
1980
  }
1980
1981
  }
1982
+ var inFlightReads = /* @__PURE__ */ new WeakMap();
1983
+ function readKey(request) {
1984
+ return [
1985
+ request.operationId,
1986
+ request.path,
1987
+ JSON.stringify(request.pathParams ?? {}),
1988
+ JSON.stringify(request.query ?? {}),
1989
+ JSON.stringify(request.headers ?? {})
1990
+ ].join("|");
1991
+ }
1981
1992
  function execute(ctx, request) {
1982
- return runWithLadder(ctx, request, async (idempotencyKey) => {
1993
+ const run = () => runWithLadder(ctx, request, async (idempotencyKey) => {
1983
1994
  const { data, meta, facets } = await sendOnce(ctx, request, idempotencyKey);
1984
1995
  return attachMeta(data, meta, facets);
1985
1996
  });
1997
+ if (request.method !== "GET" || request.signal !== void 0) return run();
1998
+ let perClient = inFlightReads.get(ctx);
1999
+ if (perClient === void 0) {
2000
+ perClient = /* @__PURE__ */ new Map();
2001
+ inFlightReads.set(ctx, perClient);
2002
+ }
2003
+ const key = readKey(request);
2004
+ const existing = perClient.get(key);
2005
+ if (existing !== void 0) return existing;
2006
+ const started = run().finally(() => {
2007
+ perClient.delete(key);
2008
+ });
2009
+ perClient.set(key, started);
2010
+ return started;
1986
2011
  }
1987
2012
  function executeBinary(ctx, request) {
1988
2013
  return runWithLadder(
@@ -3143,15 +3168,15 @@ function createReadCacheStore(options) {
3143
3168
  await options.storage.set(key, JSON.stringify(shape));
3144
3169
  }
3145
3170
  return {
3146
- get(readKey) {
3147
- return reads.get(readKey);
3171
+ get(readKey2) {
3172
+ return reads.get(readKey2);
3148
3173
  },
3149
- async set(readKey, value, serverTime) {
3150
- reads.set(readKey, { value, syncedAt: serverTime });
3174
+ async set(readKey2, value, serverTime) {
3175
+ reads.set(readKey2, { value, syncedAt: serverTime });
3151
3176
  await persist();
3152
3177
  },
3153
- async purge(readKey) {
3154
- if (!reads.delete(readKey)) {
3178
+ async purge(readKey2) {
3179
+ if (!reads.delete(readKey2)) {
3155
3180
  return;
3156
3181
  }
3157
3182
  await persist();
@@ -3168,9 +3193,9 @@ function createReadCacheStore(options) {
3168
3193
  } catch {
3169
3194
  return;
3170
3195
  }
3171
- for (const [readKey, entry] of Object.entries(parsed.reads ?? {})) {
3196
+ for (const [readKey2, entry] of Object.entries(parsed.reads ?? {})) {
3172
3197
  if (entry !== null && typeof entry === "object" && typeof entry.syncedAt === "string") {
3173
- reads.set(readKey, entry);
3198
+ reads.set(readKey2, entry);
3174
3199
  }
3175
3200
  }
3176
3201
  }