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