@vizamodo/edge-cache-core 0.3.35 → 0.3.36

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.
@@ -36,6 +36,12 @@ export async function getEdgeCache(key) {
36
36
  let parsed;
37
37
  try {
38
38
  parsed = JSON.parse(data);
39
+ // Normalize back: unwrap primitive values
40
+ if (parsed &&
41
+ typeof parsed === "object" &&
42
+ parsed.__primitive === true) {
43
+ parsed = parsed.value;
44
+ }
39
45
  }
40
46
  catch (err) {
41
47
  console.error("[edge-cache] JSON PARSE FAILED", { key, err, dataPreview: data.slice(0, 200) });
@@ -44,6 +50,9 @@ export async function getEdgeCache(key) {
44
50
  console.debug("[edge-cache] PARSED OK", {
45
51
  key,
46
52
  type: typeof parsed,
53
+ isPrimitiveWrapped: typeof parsed !== "object"
54
+ ? true
55
+ : parsed?.__primitive === true,
47
56
  });
48
57
  return parsed;
49
58
  }
@@ -66,7 +75,11 @@ export async function setEdgeCache(key, value, ttlSec) {
66
75
  const cache = caches.default;
67
76
  const req = new Request(CACHE_KEY_PREFIX + normalizeKey(key));
68
77
  console.debug("[edge-cache] SET", { key, url: req.url, ttlSec });
69
- const body = JSON.stringify(value);
78
+ // Normalize value: always store as object to ensure stable JSON shape
79
+ const normalizedValue = value !== null && typeof value === "object"
80
+ ? value
81
+ : { __primitive: true, value };
82
+ const body = JSON.stringify(normalizedValue);
70
83
  const res = new Response(body, {
71
84
  headers: {
72
85
  "Content-Type": "application/json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizamodo/edge-cache-core",
3
- "version": "0.3.35",
3
+ "version": "0.3.36",
4
4
  "description": "Edge cache primitives for Cloudflare Workers (L1 memory + L2 edge cache)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",