layercache 2.1.0 → 3.0.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/README.md +22 -6
- package/dist/{chunk-IVX6ABFX.js → chunk-5CIBABDH.js} +62 -19
- package/dist/{chunk-6X7NV5BG.js → chunk-NBMG7DHT.js} +85 -13
- package/dist/cli.cjs +153 -25
- package/dist/cli.js +69 -13
- package/dist/{edge-BCU8D-Yd.d.cts → edge-BDyuPmIq.d.cts} +5 -0
- package/dist/{edge-BCU8D-Yd.d.ts → edge-BDyuPmIq.d.ts} +5 -0
- package/dist/edge.cjs +61 -19
- package/dist/edge.d.cts +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +1 -1
- package/dist/index.cjs +312 -82
- package/dist/index.d.cts +47 -3
- package/dist/index.d.ts +47 -3
- package/dist/index.js +163 -47
- package/package.json +1 -1
package/dist/edge.cjs
CHANGED
|
@@ -515,6 +515,9 @@ var TagIndex = class {
|
|
|
515
515
|
}
|
|
516
516
|
insertKnownKey(key) {
|
|
517
517
|
const isNew = !this.knownKeys.has(key);
|
|
518
|
+
if (!isNew) {
|
|
519
|
+
this.knownKeys.delete(key);
|
|
520
|
+
}
|
|
518
521
|
this.knownKeys.set(key, Date.now());
|
|
519
522
|
if (!isNew) {
|
|
520
523
|
return;
|
|
@@ -613,13 +616,13 @@ var TagIndex = class {
|
|
|
613
616
|
if (this.maxKnownKeys === void 0 || this.knownKeys.size <= this.maxKnownKeys) {
|
|
614
617
|
return;
|
|
615
618
|
}
|
|
616
|
-
const sorted = [...this.knownKeys.entries()].sort((a, b) => a[1] - b[1]);
|
|
617
619
|
const toRemove = Math.ceil(this.maxKnownKeys * 0.1);
|
|
618
|
-
for (let i = 0; i < toRemove
|
|
619
|
-
const
|
|
620
|
-
if (
|
|
621
|
-
|
|
620
|
+
for (let i = 0; i < toRemove; i += 1) {
|
|
621
|
+
const oldestKey = this.knownKeys.keys().next().value;
|
|
622
|
+
if (oldestKey === void 0) {
|
|
623
|
+
break;
|
|
622
624
|
}
|
|
625
|
+
this.removeKnownKey(oldestKey);
|
|
623
626
|
}
|
|
624
627
|
}
|
|
625
628
|
removeKey(key) {
|
|
@@ -670,6 +673,41 @@ var TagIndex = class {
|
|
|
670
673
|
}
|
|
671
674
|
};
|
|
672
675
|
|
|
676
|
+
// src/integrations/httpCacheKeys.ts
|
|
677
|
+
var SENSITIVE_QUERY_PARAMETERS = /* @__PURE__ */ new Set([
|
|
678
|
+
"access_token",
|
|
679
|
+
"api_key",
|
|
680
|
+
"apikey",
|
|
681
|
+
"auth",
|
|
682
|
+
"authorization",
|
|
683
|
+
"code",
|
|
684
|
+
"credentials",
|
|
685
|
+
"id_token",
|
|
686
|
+
"jwt",
|
|
687
|
+
"password",
|
|
688
|
+
"private_key",
|
|
689
|
+
"refresh_token",
|
|
690
|
+
"secret",
|
|
691
|
+
"session",
|
|
692
|
+
"sessionid",
|
|
693
|
+
"session_id",
|
|
694
|
+
"token"
|
|
695
|
+
]);
|
|
696
|
+
function normalizeHttpCacheUrl(url) {
|
|
697
|
+
try {
|
|
698
|
+
const parsed = new URL(url, "http://localhost");
|
|
699
|
+
for (const name of [...parsed.searchParams.keys()]) {
|
|
700
|
+
if (SENSITIVE_QUERY_PARAMETERS.has(name.toLowerCase())) {
|
|
701
|
+
parsed.searchParams.delete(name);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
parsed.searchParams.sort();
|
|
705
|
+
return parsed.pathname + parsed.search;
|
|
706
|
+
} catch {
|
|
707
|
+
return url;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
673
711
|
// src/integrations/hono.ts
|
|
674
712
|
function createHonoCacheMiddleware(cache, options = {}) {
|
|
675
713
|
const allowedMethods = new Set((options.methods ?? ["GET"]).map((method) => method.toUpperCase()));
|
|
@@ -684,35 +722,39 @@ function createHonoCacheMiddleware(cache, options = {}) {
|
|
|
684
722
|
return;
|
|
685
723
|
}
|
|
686
724
|
const rawPath = context.req.path ?? context.req.url ?? "/";
|
|
687
|
-
const key = options.keyResolver ? options.keyResolver(context.req) : `${method}:${
|
|
725
|
+
const key = options.keyResolver ? options.keyResolver(context.req) : `${method}:${normalizeHttpCacheUrl(rawPath)}`;
|
|
688
726
|
const cached = await cache.get(key, void 0, options);
|
|
689
727
|
if (cached !== null) {
|
|
690
728
|
context.header?.("x-cache", "HIT");
|
|
691
729
|
context.header?.("content-type", "application/json; charset=utf-8");
|
|
692
730
|
return context.json(cached);
|
|
693
731
|
}
|
|
732
|
+
let currentStatus;
|
|
733
|
+
const originalStatus = context.status?.bind(context);
|
|
734
|
+
if (originalStatus) {
|
|
735
|
+
context.status = (status) => {
|
|
736
|
+
currentStatus = status;
|
|
737
|
+
return originalStatus(status);
|
|
738
|
+
};
|
|
739
|
+
}
|
|
694
740
|
const originalJson = context.json.bind(context);
|
|
695
741
|
context.json = (body, status) => {
|
|
696
742
|
context.header?.("x-cache", "MISS");
|
|
697
|
-
|
|
698
|
-
cache.
|
|
699
|
-
|
|
700
|
-
|
|
743
|
+
if (isSuccessfulStatus(status ?? currentStatus)) {
|
|
744
|
+
cache.set(key, body, options).catch((err) => {
|
|
745
|
+
cache.emit("error", {
|
|
746
|
+
operation: "set",
|
|
747
|
+
error: err instanceof Error ? err.message : String(err)
|
|
748
|
+
});
|
|
701
749
|
});
|
|
702
|
-
}
|
|
750
|
+
}
|
|
703
751
|
return originalJson(body, status);
|
|
704
752
|
};
|
|
705
753
|
await next();
|
|
706
754
|
};
|
|
707
755
|
}
|
|
708
|
-
function
|
|
709
|
-
|
|
710
|
-
const parsed = new URL(url, "http://localhost");
|
|
711
|
-
parsed.searchParams.sort();
|
|
712
|
-
return parsed.pathname + parsed.search;
|
|
713
|
-
} catch {
|
|
714
|
-
return url;
|
|
715
|
-
}
|
|
756
|
+
function isSuccessfulStatus(statusCode) {
|
|
757
|
+
return statusCode === void 0 || statusCode >= 200 && statusCode < 300;
|
|
716
758
|
}
|
|
717
759
|
// Annotate the CommonJS export names for ESM import in node:
|
|
718
760
|
0 && (module.exports = {
|
package/dist/edge.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as CacheContextOptionsContext, o as CacheEntryWriteKind, p as CacheEntryWriteOptions, e as CacheGetOptions, f as CacheLayer, h as CacheLayerSetManyEntry, y as CacheMetricsSnapshot, B as CacheRateLimitOptions, H as CacheTtlPolicy, J as CacheTtlPolicyContext, O as CacheWriteOptions, P as EvictionPolicy, R as MemoryLayer, S as MemoryLayerOptions, T as MemoryLayerSnapshotEntry, U as PatternMatcher, V as TagIndex, W as createHonoCacheMiddleware } from './edge-
|
|
1
|
+
export { m as CacheContextOptionsContext, o as CacheEntryWriteKind, p as CacheEntryWriteOptions, e as CacheGetOptions, f as CacheLayer, h as CacheLayerSetManyEntry, y as CacheMetricsSnapshot, B as CacheRateLimitOptions, H as CacheTtlPolicy, J as CacheTtlPolicyContext, O as CacheWriteOptions, P as EvictionPolicy, R as MemoryLayer, S as MemoryLayerOptions, T as MemoryLayerSnapshotEntry, U as PatternMatcher, V as TagIndex, W as createHonoCacheMiddleware } from './edge-BDyuPmIq.cjs';
|
|
2
2
|
import 'node:events';
|
package/dist/edge.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as CacheContextOptionsContext, o as CacheEntryWriteKind, p as CacheEntryWriteOptions, e as CacheGetOptions, f as CacheLayer, h as CacheLayerSetManyEntry, y as CacheMetricsSnapshot, B as CacheRateLimitOptions, H as CacheTtlPolicy, J as CacheTtlPolicyContext, O as CacheWriteOptions, P as EvictionPolicy, R as MemoryLayer, S as MemoryLayerOptions, T as MemoryLayerSnapshotEntry, U as PatternMatcher, V as TagIndex, W as createHonoCacheMiddleware } from './edge-
|
|
1
|
+
export { m as CacheContextOptionsContext, o as CacheEntryWriteKind, p as CacheEntryWriteOptions, e as CacheGetOptions, f as CacheLayer, h as CacheLayerSetManyEntry, y as CacheMetricsSnapshot, B as CacheRateLimitOptions, H as CacheTtlPolicy, J as CacheTtlPolicyContext, O as CacheWriteOptions, P as EvictionPolicy, R as MemoryLayer, S as MemoryLayerOptions, T as MemoryLayerSnapshotEntry, U as PatternMatcher, V as TagIndex, W as createHonoCacheMiddleware } from './edge-BDyuPmIq.js';
|
|
2
2
|
import 'node:events';
|