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/client-entry.cjs +33 -9
- package/dist/client-entry.cjs.map +1 -1
- package/dist/client-entry.js +33 -9
- package/dist/client-entry.js.map +1 -1
- package/dist/index.cjs +25 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/client-entry.js
CHANGED
|
@@ -1979,11 +1979,35 @@ async function runWithLadder(ctx, request, send) {
|
|
|
1979
1979
|
throw error;
|
|
1980
1980
|
}
|
|
1981
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
|
+
}
|
|
1982
1992
|
function execute(ctx, request) {
|
|
1983
|
-
|
|
1993
|
+
const run = () => runWithLadder(ctx, request, async (idempotencyKey) => {
|
|
1984
1994
|
const { data, meta, facets } = await sendOnce(ctx, request, idempotencyKey);
|
|
1985
1995
|
return attachMeta(data, meta, facets);
|
|
1986
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;
|
|
1987
2011
|
}
|
|
1988
2012
|
function executeBinary(ctx, request) {
|
|
1989
2013
|
return runWithLadder(
|
|
@@ -3144,15 +3168,15 @@ function createReadCacheStore(options) {
|
|
|
3144
3168
|
await options.storage.set(key, JSON.stringify(shape));
|
|
3145
3169
|
}
|
|
3146
3170
|
return {
|
|
3147
|
-
get(
|
|
3148
|
-
return reads.get(
|
|
3171
|
+
get(readKey2) {
|
|
3172
|
+
return reads.get(readKey2);
|
|
3149
3173
|
},
|
|
3150
|
-
async set(
|
|
3151
|
-
reads.set(
|
|
3174
|
+
async set(readKey2, value, serverTime) {
|
|
3175
|
+
reads.set(readKey2, { value, syncedAt: serverTime });
|
|
3152
3176
|
await persist();
|
|
3153
3177
|
},
|
|
3154
|
-
async purge(
|
|
3155
|
-
if (!reads.delete(
|
|
3178
|
+
async purge(readKey2) {
|
|
3179
|
+
if (!reads.delete(readKey2)) {
|
|
3156
3180
|
return;
|
|
3157
3181
|
}
|
|
3158
3182
|
await persist();
|
|
@@ -3169,9 +3193,9 @@ function createReadCacheStore(options) {
|
|
|
3169
3193
|
} catch {
|
|
3170
3194
|
return;
|
|
3171
3195
|
}
|
|
3172
|
-
for (const [
|
|
3196
|
+
for (const [readKey2, entry] of Object.entries(parsed.reads ?? {})) {
|
|
3173
3197
|
if (entry !== null && typeof entry === "object" && typeof entry.syncedAt === "string") {
|
|
3174
|
-
reads.set(
|
|
3198
|
+
reads.set(readKey2, entry);
|
|
3175
3199
|
}
|
|
3176
3200
|
}
|
|
3177
3201
|
}
|