@farm.js/core 0.1.17 → 0.1.18

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.
Files changed (249) hide show
  1. package/dist/after.cjs +12 -225
  2. package/dist/agent-runtime.cjs +83 -2800
  3. package/dist/api/client.cjs +17 -4060
  4. package/dist/api/route-manager.cjs +34 -4354
  5. package/dist/api/runtime.cjs +29 -2696
  6. package/dist/api.cjs +88 -8434
  7. package/dist/app-markdown.cjs +39 -280
  8. package/dist/cache.cjs +38 -1560
  9. package/dist/chunk-22GUSVNJ.cjs +351 -0
  10. package/dist/chunk-2CQ74SP6.cjs +13 -0
  11. package/dist/chunk-2SJ4RQ6P.cjs +57 -0
  12. package/dist/chunk-3376ZTRC.cjs +1 -0
  13. package/dist/{chunk-YD4J4XCI.mjs → chunk-3XG26Z3J.mjs} +1 -1
  14. package/dist/chunk-4PNUXIVU.cjs +472 -0
  15. package/dist/chunk-4PPEPOZZ.cjs +21 -0
  16. package/dist/chunk-4ZFL5GFN.cjs +520 -0
  17. package/dist/chunk-5OVTOKGH.cjs +65 -0
  18. package/dist/chunk-5QIKR7RR.cjs +224 -0
  19. package/dist/chunk-5ZSWG4UX.cjs +127 -0
  20. package/dist/chunk-62YJ2IEB.cjs +238 -0
  21. package/dist/chunk-6EODJYCX.cjs +183 -0
  22. package/dist/chunk-6EXBPJ24.cjs +434 -0
  23. package/dist/chunk-6QQDAAAZ.cjs +38 -0
  24. package/dist/chunk-6V4TDWEC.cjs +455 -0
  25. package/dist/chunk-72ADZ6GQ.cjs +19 -0
  26. package/dist/chunk-75BRBIFP.cjs +172 -0
  27. package/dist/chunk-7W3CPVXS.cjs +24 -0
  28. package/dist/chunk-A6WIQH5Z.cjs +31 -0
  29. package/dist/chunk-AFOD3LYZ.cjs +377 -0
  30. package/dist/chunk-AMDMVWMI.cjs +39 -0
  31. package/dist/chunk-AORPIPNB.cjs +552 -0
  32. package/dist/chunk-ARJWXNQL.cjs +256 -0
  33. package/dist/chunk-AWRISO2H.cjs +2199 -0
  34. package/dist/chunk-AYJR42WX.cjs +711 -0
  35. package/dist/chunk-B4CH33IG.cjs +644 -0
  36. package/dist/chunk-BIDYX3SL.cjs +91 -0
  37. package/dist/chunk-BSTRERPP.cjs +40 -0
  38. package/dist/chunk-BYODCJD6.cjs +663 -0
  39. package/dist/chunk-C3VRMB6H.cjs +85 -0
  40. package/dist/chunk-C5GUTBZK.cjs +173 -0
  41. package/dist/chunk-CIAGU2X4.cjs +337 -0
  42. package/dist/chunk-CMGMGHUZ.cjs +27 -0
  43. package/dist/chunk-CXP5U3RW.cjs +54 -0
  44. package/dist/chunk-D2ULAULS.cjs +166 -0
  45. package/dist/chunk-D7JTOLFK.cjs +285 -0
  46. package/dist/chunk-DVM4FKZL.cjs +169 -0
  47. package/dist/chunk-DYEJQTDN.cjs +49 -0
  48. package/dist/chunk-E2BMSZ2W.cjs +151 -0
  49. package/dist/chunk-E3UK5IIB.cjs +593 -0
  50. package/dist/chunk-EM6SBQKM.cjs +470 -0
  51. package/dist/chunk-FJSWYIR7.cjs +482 -0
  52. package/dist/chunk-FK6GO24V.cjs +54 -0
  53. package/dist/chunk-FXUUWYAX.cjs +654 -0
  54. package/dist/chunk-G3HRIVEY.cjs +395 -0
  55. package/dist/chunk-G643DQCH.cjs +13 -0
  56. package/dist/chunk-G7HXGLEC.cjs +175 -0
  57. package/dist/chunk-GDSHDTJ4.cjs +152 -0
  58. package/dist/chunk-GNEO2XOF.cjs +2040 -0
  59. package/dist/{chunk-56DAX2BE.mjs → chunk-GYKJCFTS.mjs} +1 -1
  60. package/dist/chunk-H6G5INWM.cjs +1094 -0
  61. package/dist/chunk-HBTUGXHS.cjs +180 -0
  62. package/dist/chunk-HREOKQWT.cjs +45 -0
  63. package/dist/chunk-I4J452B7.cjs +435 -0
  64. package/dist/chunk-I57LW5VZ.cjs +94 -0
  65. package/dist/chunk-I7PUUDGY.cjs +389 -0
  66. package/dist/chunk-IAMRBF3Z.cjs +86 -0
  67. package/dist/chunk-IKNRN4VS.cjs +14214 -0
  68. package/dist/chunk-IQXFRNY2.cjs +169 -0
  69. package/dist/chunk-IXTFU4PL.cjs +2355 -0
  70. package/dist/chunk-J2OP5GG3.cjs +725 -0
  71. package/dist/chunk-J3LOGE4T.cjs +42 -0
  72. package/dist/chunk-J7FSKED3.cjs +93 -0
  73. package/dist/chunk-JDNHKPTD.cjs +22 -0
  74. package/dist/chunk-JSROZYYO.cjs +164 -0
  75. package/dist/chunk-K6FNHVDR.cjs +696 -0
  76. package/dist/chunk-KGZIORNL.cjs +43 -0
  77. package/dist/{chunk-MVIWBEJF.mjs → chunk-KPNVGRBL.mjs} +1 -1
  78. package/dist/chunk-KR6CKSXT.cjs +15 -0
  79. package/dist/chunk-KROWKCUH.cjs +185 -0
  80. package/dist/chunk-KVFPGF2M.cjs +46 -0
  81. package/dist/chunk-LCCBO7PJ.cjs +46 -0
  82. package/dist/chunk-LIUGYUX3.cjs +22 -0
  83. package/dist/chunk-LTNGXMQ6.cjs +55 -0
  84. package/dist/chunk-M2L4MYDQ.cjs +14 -0
  85. package/dist/chunk-MCJLA63J.cjs +1 -0
  86. package/dist/chunk-MKB2EGIR.cjs +148 -0
  87. package/dist/chunk-MQ3H6LT5.cjs +202 -0
  88. package/dist/chunk-MT763TDW.cjs +43 -0
  89. package/dist/chunk-MWSK6C4J.cjs +18 -0
  90. package/dist/chunk-MWWVKDW3.cjs +169 -0
  91. package/dist/chunk-NO3WWW3N.cjs +192 -0
  92. package/dist/chunk-NV3A5DXM.cjs +862 -0
  93. package/dist/chunk-NWOD6NIT.cjs +9 -0
  94. package/dist/chunk-NZKJGRB3.cjs +230 -0
  95. package/dist/chunk-OAVTUMJP.cjs +1496 -0
  96. package/dist/chunk-OHY2ZWUG.cjs +25 -0
  97. package/dist/chunk-OI6CMLWX.cjs +47 -0
  98. package/dist/chunk-OIEOCXKG.cjs +453 -0
  99. package/dist/chunk-OWOUTKIJ.cjs +558 -0
  100. package/dist/chunk-OX6O6WVA.cjs +74 -0
  101. package/dist/chunk-OXSIH4D6.cjs +476 -0
  102. package/dist/chunk-OYEUREB6.cjs +35 -0
  103. package/dist/chunk-PCOTGFSM.cjs +139 -0
  104. package/dist/chunk-PZYCPSCC.cjs +35 -0
  105. package/dist/chunk-QBK2AA4U.cjs +445 -0
  106. package/dist/chunk-QBPXNZGV.cjs +487 -0
  107. package/dist/chunk-QNPEUFHQ.cjs +27 -0
  108. package/dist/chunk-QZRVZSPN.cjs +236 -0
  109. package/dist/chunk-R5A5KNVX.cjs +20 -0
  110. package/dist/chunk-R5JIFR6B.cjs +42 -0
  111. package/dist/chunk-R6AIILII.cjs +193 -0
  112. package/dist/chunk-RG3ZOTG5.cjs +34 -0
  113. package/dist/chunk-ROUTX2E5.cjs +390 -0
  114. package/dist/chunk-RTHIVJ2G.cjs +54 -0
  115. package/dist/chunk-S3A45T7F.cjs +166 -0
  116. package/dist/chunk-S3JO3N4H.cjs +17 -0
  117. package/dist/chunk-SK35NQKK.cjs +27 -0
  118. package/dist/chunk-SU7MH53P.cjs +180 -0
  119. package/dist/chunk-SVRTJOUF.cjs +113 -0
  120. package/dist/chunk-SWN467MP.cjs +18 -0
  121. package/dist/chunk-SYQ3MOWW.cjs +73 -0
  122. package/dist/chunk-T5CERMEH.cjs +417 -0
  123. package/dist/chunk-TFAXUHWX.cjs +206 -0
  124. package/dist/chunk-TIWHTW3Q.cjs +24 -0
  125. package/dist/chunk-TKJZFIML.cjs +20 -0
  126. package/dist/chunk-TKNSDBBN.cjs +193 -0
  127. package/dist/chunk-TWGMSEHX.cjs +525 -0
  128. package/dist/chunk-TYQUSXUG.cjs +1357 -0
  129. package/dist/chunk-U4KT7QP3.cjs +23 -0
  130. package/dist/chunk-UJ2C4ICS.cjs +277 -0
  131. package/dist/chunk-UN5GHC5V.cjs +10244 -0
  132. package/dist/chunk-UQZ4AYTH.cjs +168 -0
  133. package/dist/chunk-US2QVW3E.cjs +36 -0
  134. package/dist/chunk-VB6UCX3V.cjs +421 -0
  135. package/dist/chunk-VEKFLAQM.cjs +300 -0
  136. package/dist/chunk-VQDBNVOO.cjs +14 -0
  137. package/dist/chunk-W4E7WMXE.cjs +71 -0
  138. package/dist/chunk-WJ3HK3LJ.cjs +1102 -0
  139. package/dist/chunk-WMAPPDMM.cjs +28 -0
  140. package/dist/chunk-WMOGFOUJ.cjs +223 -0
  141. package/dist/chunk-WPYFSQKK.cjs +37 -0
  142. package/dist/chunk-WZMNW2IW.cjs +1415 -0
  143. package/dist/chunk-XGC343EY.cjs +443 -0
  144. package/dist/chunk-XSKZORAS.cjs +727 -0
  145. package/dist/chunk-XWAWFQFS.cjs +82 -0
  146. package/dist/chunk-Y4YMF2NQ.cjs +460 -0
  147. package/dist/chunk-Y4YWHNKU.cjs +250 -0
  148. package/dist/chunk-Y53ZSFN6.cjs +504 -0
  149. package/dist/chunk-YA6LLTIJ.cjs +411 -0
  150. package/dist/chunk-YFPGHF5F.cjs +202 -0
  151. package/dist/chunk-YJRZR7VU.cjs +28 -0
  152. package/dist/chunk-YTAABQEV.cjs +1 -0
  153. package/dist/chunk-YX3DBN4M.cjs +18 -0
  154. package/dist/chunk-YZTASLPQ.cjs +64 -0
  155. package/dist/chunk-Z5HIWVDP.cjs +2173 -0
  156. package/dist/chunk-ZEG3OPIB.cjs +93 -0
  157. package/dist/chunk-ZMN3H73H.cjs +155 -0
  158. package/dist/client/lifecycle.cjs +6 -35
  159. package/dist/client-plugins.cjs +7 -448
  160. package/dist/client.cjs +171 -9808
  161. package/dist/config.cjs +8 -36
  162. package/dist/cron.cjs +24 -491
  163. package/dist/deferred.cjs +26 -475
  164. package/dist/deployment.cjs +39 -210
  165. package/dist/devtools-OUIPHVV6.cjs +388 -0
  166. package/dist/devtools-client-4WAPJY5L.cjs +254 -0
  167. package/dist/devtools-ui-5GBDIGMK.cjs +1296 -0
  168. package/dist/docs.cjs +46 -5657
  169. package/dist/env-types.cjs +5 -226
  170. package/dist/env.cjs +21 -338
  171. package/dist/environment/vite.cjs +8 -372
  172. package/dist/environment.cjs +12 -94
  173. package/dist/font.cjs +13 -63
  174. package/dist/headers.cjs +7 -123
  175. package/dist/i18n/client.cjs +55 -294
  176. package/dist/i18n/index.cjs +22 -209
  177. package/dist/i18n/server.cjs +22 -745
  178. package/dist/image/server.cjs +13 -729
  179. package/dist/image/sharp.cjs +33 -171
  180. package/dist/image.cjs +41 -85
  181. package/dist/index.cjs +1151 -68080
  182. package/dist/index.mjs +3 -3
  183. package/dist/instrumentation.cjs +12 -138
  184. package/dist/integration-orm-55F7CII5.cjs +13 -0
  185. package/dist/integrations.cjs +55 -4090
  186. package/dist/internal/app-markdown-runtime.cjs +27 -224
  187. package/dist/internal/build-runtime.cjs +120 -52259
  188. package/dist/internal/build-runtime.mjs +3 -3
  189. package/dist/internal/cli-runtime.cjs +67 -13811
  190. package/dist/internal/client-error-overlay.cjs +80 -733
  191. package/dist/internal/client-error-overlay.mjs +1 -1
  192. package/dist/internal/client-runtime.cjs +81 -913
  193. package/dist/internal/compression-runtime.cjs +8 -214
  194. package/dist/internal/config-runtime.cjs +42 -6547
  195. package/dist/internal/docs-precompiled-runtime.cjs +26 -46
  196. package/dist/internal/infra-analytics-runtime.cjs +10 -536
  197. package/dist/internal/isolated-boundary.cjs +14 -414
  198. package/dist/internal/metadata-image-runtime.cjs +7 -285
  199. package/dist/internal/product-telemetry-runtime.cjs +42 -97
  200. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  201. package/dist/internal/production-node-env.cjs +6 -63
  202. package/dist/internal/production-runtime.cjs +418 -7133
  203. package/dist/internal/request-cookies.cjs +6 -54
  204. package/dist/json-ld.cjs +24 -50
  205. package/dist/layers-E4WPJNY5.cjs +17 -0
  206. package/dist/manager-G4B2IPYE.cjs +14 -0
  207. package/dist/markdown.cjs +21 -547
  208. package/dist/middleware.cjs +36 -2995
  209. package/dist/navigation.cjs +22 -2588
  210. package/dist/nitro-4I2MYLY2.cjs +652 -0
  211. package/dist/observability.cjs +22 -614
  212. package/dist/og.cjs +5 -28
  213. package/dist/plugin.cjs +106 -37442
  214. package/dist/plugin.mjs +2 -2
  215. package/dist/query/client.cjs +113 -449
  216. package/dist/query/index.cjs +26 -288
  217. package/dist/query/parsers.cjs +23 -247
  218. package/dist/query/server.cjs +36 -298
  219. package/dist/renderer/react/client.cjs +9 -43
  220. package/dist/renderer/react/server.cjs +40 -103
  221. package/dist/renderer/react/vite.cjs +7 -29
  222. package/dist/renderer-client.cjs +126 -4295
  223. package/dist/renderer.cjs +31 -249
  224. package/dist/request.cjs +5 -68
  225. package/dist/router.cjs +11 -474
  226. package/dist/routes.cjs +42 -2461
  227. package/dist/schema-dev-notice-MXSZMVDG.cjs +56 -0
  228. package/dist/schema.cjs +6 -33
  229. package/dist/search-client-G3RICOFU.cjs +13 -0
  230. package/dist/server-action-security.cjs +25 -541
  231. package/dist/server-fn-client.cjs +6 -337
  232. package/dist/server-fn.cjs +32 -1841
  233. package/dist/server-plugins.cjs +15 -884
  234. package/dist/server-query-client.cjs +15 -1883
  235. package/dist/server-query.cjs +16 -1838
  236. package/dist/server.cjs +296 -44681
  237. package/dist/server.mjs +2 -2
  238. package/dist/storage.cjs +57 -576
  239. package/dist/testing.cjs +89 -3186
  240. package/dist/theme/client.cjs +13 -108
  241. package/dist/theme/index.cjs +6 -68
  242. package/dist/theme/runtime.cjs +13 -78
  243. package/dist/theme/server.cjs +10 -179
  244. package/dist/version.cjs +4 -32
  245. package/dist/version.mjs +1 -1
  246. package/dist/vite.cjs +119 -37773
  247. package/dist/vite.mjs +2 -2
  248. package/dist/workflows.cjs +19 -1040
  249. package/package.json +1 -1
@@ -0,0 +1,1094 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+ var _chunkZEG3OPIBcjs = require('./chunk-ZEG3OPIB.cjs');
7
+
8
+
9
+ var _chunkLIUGYUX3cjs = require('./chunk-LIUGYUX3.cjs');
10
+
11
+
12
+ var _chunkE3UK5IIBcjs = require('./chunk-E3UK5IIB.cjs');
13
+
14
+
15
+ var _chunkS3JO3N4Hcjs = require('./chunk-S3JO3N4H.cjs');
16
+
17
+ // src/cache-invalidation-stream.ts
18
+ var DEFAULT_HEARTBEAT_INTERVAL_MS = 15e3;
19
+ var DEFAULT_RETRY_MS = 3e3;
20
+ var MAX_BUFFERED_BYTES = 64 * 1024;
21
+ var MAX_PENDING_KEYS = 1024;
22
+ var textEncoder = new TextEncoder();
23
+ function positiveDuration(value, fallback) {
24
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
25
+ }
26
+ _chunkS3JO3N4Hcjs.__name.call(void 0, positiveDuration, "positiveDuration");
27
+ function createFarmCacheInvalidationStream(options = {}) {
28
+ const heartbeatIntervalMs = options.heartbeatIntervalMs === false ? false : positiveDuration(options.heartbeatIntervalMs, DEFAULT_HEARTBEAT_INTERVAL_MS);
29
+ const retryMs = positiveDuration(options.retryMs, DEFAULT_RETRY_MS);
30
+ let unsubscribe;
31
+ let heartbeat;
32
+ let controller;
33
+ let closed = false;
34
+ let flushScheduled = false;
35
+ const pending = /* @__PURE__ */ new Set();
36
+ let pendingBytes = 0;
37
+ const enqueue = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (value) => {
38
+ if (closed || !controller) return;
39
+ const chunk = textEncoder.encode(value);
40
+ if (chunk.byteLength > (_nullishCoalesce(controller.desiredSize, () => ( 0)))) {
41
+ overflow();
42
+ return;
43
+ }
44
+ controller.enqueue(chunk);
45
+ }, "enqueue");
46
+ const cleanup = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
47
+ _optionalChain([unsubscribe, 'optionalCall', _ => _()]);
48
+ unsubscribe = void 0;
49
+ if (heartbeat !== void 0) clearInterval(heartbeat);
50
+ heartbeat = void 0;
51
+ _optionalChain([options, 'access', _2 => _2.signal, 'optionalAccess', _3 => _3.removeEventListener, 'call', _4 => _4("abort", abort)]);
52
+ pending.clear();
53
+ pendingBytes = 0;
54
+ }, "cleanup");
55
+ const stop = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (closeController) => {
56
+ if (closed) return;
57
+ closed = true;
58
+ cleanup();
59
+ if (closeController) _optionalChain([controller, 'optionalAccess', _5 => _5.close, 'call', _6 => _6()]);
60
+ }, "stop");
61
+ const abort = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => stop(true), "abort");
62
+ const overflow = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
63
+ if (closed) return;
64
+ stop(false);
65
+ _optionalChain([controller, 'optionalAccess', _7 => _7.error, 'call', _8 => _8(new Error("Farm cache invalidation stream exceeded its buffer limit."))]);
66
+ }, "overflow");
67
+ const flush = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
68
+ flushScheduled = false;
69
+ if (closed || pending.size === 0) return;
70
+ const encoded = _chunkZEG3OPIBcjs.encodeFarmCacheInvalidations.call(void 0, [...pending]);
71
+ pending.clear();
72
+ pendingBytes = 0;
73
+ if (encoded !== null) enqueue(`data: ${encoded}
74
+
75
+ `);
76
+ }, "flush");
77
+ const stream = new ReadableStream(
78
+ {
79
+ start(nextController) {
80
+ controller = nextController;
81
+ if (_optionalChain([options, 'access', _9 => _9.signal, 'optionalAccess', _10 => _10.aborted])) {
82
+ stop(true);
83
+ return;
84
+ }
85
+ enqueue(`: connected
86
+ retry: ${retryMs}
87
+
88
+ `);
89
+ unsubscribe = _chunkZEG3OPIBcjs.subscribeFarmCacheInvalidation.call(void 0, (key) => {
90
+ if (closed || _optionalChain([options, 'access', _11 => _11.filter, 'optionalCall', _12 => _12(key)]) === false) return;
91
+ if (closed || pending.has(key)) return;
92
+ if (pending.size >= MAX_PENDING_KEYS || pendingBytes + key.length * 2 > MAX_BUFFERED_BYTES) {
93
+ overflow();
94
+ return;
95
+ }
96
+ pending.add(key);
97
+ pendingBytes += key.length * 2;
98
+ if (!flushScheduled) {
99
+ flushScheduled = true;
100
+ queueMicrotask(flush);
101
+ }
102
+ });
103
+ _optionalChain([options, 'access', _13 => _13.signal, 'optionalAccess', _14 => _14.addEventListener, 'call', _15 => _15("abort", abort, { once: true })]);
104
+ if (heartbeatIntervalMs !== false) {
105
+ heartbeat = setInterval(() => {
106
+ if (_optionalChain([controller, 'optionalAccess', _16 => _16.desiredSize]) === MAX_BUFFERED_BYTES) enqueue(": heartbeat\n\n");
107
+ }, heartbeatIntervalMs);
108
+ }
109
+ },
110
+ cancel() {
111
+ stop(false);
112
+ }
113
+ },
114
+ { highWaterMark: MAX_BUFFERED_BYTES, size: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (chunk) => chunk.byteLength, "size") }
115
+ );
116
+ return new Response(stream, {
117
+ headers: {
118
+ "Cache-Control": "no-cache, no-transform",
119
+ "Content-Type": "text/event-stream; charset=utf-8"
120
+ }
121
+ });
122
+ }
123
+ _chunkS3JO3N4Hcjs.__name.call(void 0, createFarmCacheInvalidationStream, "createFarmCacheInvalidationStream");
124
+
125
+ // src/cache.ts
126
+ function defineCacheKey() {
127
+ return (factory) => {
128
+ if (typeof factory !== "function") {
129
+ throw new TypeError("defineCacheKey expects a key factory function.");
130
+ }
131
+ return ((...args) => {
132
+ const key = factory(...args);
133
+ if (typeof key !== "string" && !Array.isArray(key)) {
134
+ throw new TypeError(
135
+ "A defined cache key factory must return a string or structured array."
136
+ );
137
+ }
138
+ return key;
139
+ });
140
+ };
141
+ }
142
+ _chunkS3JO3N4Hcjs.__name.call(void 0, defineCacheKey, "defineCacheKey");
143
+ function storageCacheAdapter(storage, options = {}) {
144
+ if (!storage || typeof storage.getItem !== "function" || typeof storage.setItem !== "function") {
145
+ throw new TypeError("storageCacheAdapter expects a compatible storage client.");
146
+ }
147
+ const base = normalizeCacheNamespace(options.base || "farm-cache");
148
+ const entryKey = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (key) => `${base}:entry:${key}`, "entryKey");
149
+ const tagKey = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (tag) => `${base}:tag:${tag}`, "tagKey");
150
+ return {
151
+ name: "storage",
152
+ get: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (key) => storage.getItem(entryKey(key)), "get"),
153
+ set: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, async (key, entry) => {
154
+ await storage.setItem(entryKey(key), entry);
155
+ }, "set"),
156
+ delete: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, async (key) => {
157
+ await storage.removeItem(entryKey(key));
158
+ }, "delete"),
159
+ clear: storage.clear ? async () => {
160
+ await storage.clear(base);
161
+ } : void 0,
162
+ getTagVersions: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, async (tags) => {
163
+ const versions = await Promise.all(
164
+ tags.map(async (tag) => {
165
+ const value = await storage.getItem(tagKey(tag));
166
+ return [tag, normalizeAdapterVersion(value)];
167
+ })
168
+ );
169
+ return Object.fromEntries(versions);
170
+ }, "getTagVersions"),
171
+ invalidateTags: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, async (tags) => {
172
+ await Promise.all(
173
+ tags.map(async (tag) => {
174
+ const key = tagKey(tag);
175
+ const current = normalizeAdapterVersion(await storage.getItem(key));
176
+ await storage.setItem(key, Math.max(Date.now(), current + 1));
177
+ })
178
+ );
179
+ }, "invalidateTags")
180
+ };
181
+ }
182
+ _chunkS3JO3N4Hcjs.__name.call(void 0, storageCacheAdapter, "storageCacheAdapter");
183
+ var _FarmDataCache = class _FarmDataCache {
184
+ constructor(config = {}) {
185
+ this.entries = /* @__PURE__ */ new Map();
186
+ this.inflight = /* @__PURE__ */ new Map();
187
+ /** Local entries by tag, so tag counts and pruning never scan unrelated entries. */
188
+ this.entriesByTag = /* @__PURE__ */ new Map();
189
+ this.invalidatedTagVersions = /* @__PURE__ */ new Map();
190
+ this.activeGenerations = /* @__PURE__ */ new Set();
191
+ this.version = 0;
192
+ this.generation = 0;
193
+ this.namespace = "farm";
194
+ this.local = true;
195
+ this.maxEntries = 1024;
196
+ this.lease = {
197
+ enabled: true,
198
+ ttlMs: 1e4,
199
+ waitTimeoutMs: 1e4,
200
+ pollIntervalMs: 25
201
+ };
202
+ this.configure(config);
203
+ }
204
+ configure(config = {}) {
205
+ this.generation++;
206
+ this.entries.clear();
207
+ this.entriesByTag.clear();
208
+ this.inflight.clear();
209
+ this.invalidatedTagVersions.clear();
210
+ this.activeGenerations.clear();
211
+ this.version = 0;
212
+ this.adapter = config.adapter;
213
+ this.namespace = normalizeCacheNamespace(config.namespace || "farm");
214
+ this.local = !config.adapter;
215
+ this.maxEntries = normalizePositiveInteger(config.maxEntries, 1024, "cache.maxEntries");
216
+ this.lease = config.lease === false ? { ...this.lease, enabled: false } : {
217
+ enabled: true,
218
+ ttlMs: normalizePositiveDuration(_optionalChain([config, 'access', _17 => _17.lease, 'optionalAccess', _18 => _18.ttlMs]), 1e4, "cache.lease.ttlMs"),
219
+ waitTimeoutMs: normalizePositiveDuration(
220
+ _optionalChain([config, 'access', _19 => _19.lease, 'optionalAccess', _20 => _20.waitTimeoutMs]),
221
+ 1e4,
222
+ "cache.lease.waitTimeoutMs"
223
+ ),
224
+ pollIntervalMs: normalizePositiveDuration(
225
+ _optionalChain([config, 'access', _21 => _21.lease, 'optionalAccess', _22 => _22.pollIntervalMs]),
226
+ 25,
227
+ "cache.lease.pollIntervalMs"
228
+ )
229
+ };
230
+ }
231
+ get adapterName() {
232
+ return _optionalChain([this, 'access', _23 => _23.adapter, 'optionalAccess', _24 => _24.name]) || (this.adapter ? "custom" : "memory");
233
+ }
234
+ get hasAdapter() {
235
+ return this.adapter !== void 0;
236
+ }
237
+ get size() {
238
+ return this.entries.size;
239
+ }
240
+ get(key, options = {}) {
241
+ return _optionalChain([this, 'access', _25 => _25.getEntry, 'call', _26 => _26(key, options), 'optionalAccess', _27 => _27.value]);
242
+ }
243
+ getEntry(key, options = {}) {
244
+ const entry = this.entries.get(key);
245
+ if (!entry) {
246
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.miss", key });
247
+ return void 0;
248
+ }
249
+ const stale = this.isStale(entry, options.now);
250
+ if (stale) {
251
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
252
+ type: "cache.stale",
253
+ key,
254
+ tags: Array.from(entry.tags),
255
+ revalidate: entry.revalidate
256
+ });
257
+ }
258
+ if (!options.allowStale && stale) {
259
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.miss", key, reason: "stale" });
260
+ return void 0;
261
+ }
262
+ this.touchEntry(key, entry);
263
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
264
+ type: "cache.hit",
265
+ key,
266
+ tags: Array.from(entry.tags),
267
+ revalidate: entry.revalidate,
268
+ stale
269
+ });
270
+ return this.toPublicEntry(entry);
271
+ }
272
+ async getEntryAsync(key, options = {}) {
273
+ if (this.local) {
274
+ const localEntry = this.getEntry(key, options);
275
+ if (localEntry) return localEntry;
276
+ }
277
+ if (!this.adapter) {
278
+ return this.local ? void 0 : this.getEntry(key, options);
279
+ }
280
+ const generation = this.generation;
281
+ const adapter = this.adapter;
282
+ const namespace = this.namespace;
283
+ const entry = await adapter.get(`${namespace}:entry:${key}`);
284
+ if (generation !== this.generation) return void 0;
285
+ if (!entry) {
286
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.miss", key });
287
+ return void 0;
288
+ }
289
+ assertFarmCacheEntry(entry, key);
290
+ const stale = await this.isAdapterEntryStale(entry, options.now, adapter, namespace);
291
+ if (generation !== this.generation) return void 0;
292
+ if (stale) {
293
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
294
+ type: "cache.stale",
295
+ key,
296
+ tags: [...entry.tags],
297
+ revalidate: entry.revalidate
298
+ });
299
+ if (!options.allowStale) {
300
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.miss", key, reason: "stale" });
301
+ return void 0;
302
+ }
303
+ }
304
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
305
+ type: "cache.hit",
306
+ key,
307
+ tags: [...entry.tags],
308
+ revalidate: entry.revalidate,
309
+ stale
310
+ });
311
+ if (this.local && !stale) {
312
+ this.hydrateLocalEntry(entry);
313
+ }
314
+ return { ...entry, key };
315
+ }
316
+ set(key, value, options = {}) {
317
+ const revalidate = normalizeRevalidate(options.revalidate);
318
+ const tags = /* @__PURE__ */ new Set();
319
+ for (const tag of _nullishCoalesce(options.tags, () => ( []))) {
320
+ tags.add(normalizeCacheTag(tag));
321
+ }
322
+ for (const routePath of _nullishCoalesce(options.paths, () => ( []))) {
323
+ tags.add(createPathCacheTag(routePath));
324
+ }
325
+ const entry = {
326
+ key,
327
+ value,
328
+ tags,
329
+ tagVersions: void 0,
330
+ createdAt: _nullishCoalesce(options.createdAt, () => ( Date.now())),
331
+ createdVersion: ++this.version,
332
+ revalidate
333
+ };
334
+ this.storeLocalEntry(entry);
335
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
336
+ type: "cache.set",
337
+ key,
338
+ tags: Array.from(tags),
339
+ revalidate: entry.revalidate
340
+ });
341
+ return this.toPublicEntry(entry);
342
+ }
343
+ async setAsync(key, value, options = {}, tagVersions) {
344
+ return this.writeAsync(key, value, options, tagVersions);
345
+ }
346
+ async writeAsync(key, value, options, tagVersions, createdVersion) {
347
+ const revalidate = normalizeRevalidate(options.revalidate);
348
+ const tags = normalizeCacheOptionsTags(options);
349
+ const capturedVersions = await _asyncNullishCoalesce(tagVersions, async () => ( await this.getAdapterTagVersions(Array.from(tags.values()))));
350
+ const entry = {
351
+ key,
352
+ value,
353
+ tags: Array.from(tags),
354
+ tagVersions: capturedVersions,
355
+ createdAt: _nullishCoalesce(options.createdAt, () => ( Date.now())),
356
+ createdVersion: _nullishCoalesce(createdVersion, () => ( ++this.version)),
357
+ revalidate
358
+ };
359
+ if (this.local) {
360
+ this.hydrateLocalEntry(entry);
361
+ }
362
+ if (this.adapter) {
363
+ await this.adapter.set(this.createAdapterKey(key), entry);
364
+ }
365
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
366
+ type: "cache.set",
367
+ key,
368
+ tags: [...entry.tags],
369
+ revalidate: entry.revalidate
370
+ });
371
+ return entry;
372
+ }
373
+ delete(key) {
374
+ const deleted = this.deleteLocalEntry(key);
375
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.delete", key, deleted });
376
+ return deleted;
377
+ }
378
+ async deleteAsync(key) {
379
+ const deleted = this.deleteLocalEntry(key);
380
+ if (this.adapter) {
381
+ await this.adapter.delete(this.createAdapterKey(key));
382
+ }
383
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.delete", key, deleted: this.adapter ? true : deleted });
384
+ return this.adapter ? true : deleted;
385
+ }
386
+ clear() {
387
+ const count = this.entries.size;
388
+ this.generation++;
389
+ this.entries.clear();
390
+ this.entriesByTag.clear();
391
+ this.inflight.clear();
392
+ this.invalidatedTagVersions.clear();
393
+ this.activeGenerations.clear();
394
+ this.version = 0;
395
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.clear", count });
396
+ }
397
+ async clearAsync() {
398
+ this.clear();
399
+ await _optionalChain([this, 'access', _28 => _28.adapter, 'optionalAccess', _29 => _29.clear, 'optionalCall', _30 => _30()]);
400
+ }
401
+ isStale(entry, now = Date.now()) {
402
+ if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
403
+ return true;
404
+ }
405
+ for (const tag of entry.tags) {
406
+ const invalidatedVersion = this.invalidatedTagVersions.get(normalizeCacheTag(tag));
407
+ if (typeof invalidatedVersion === "number" && typeof entry.createdVersion === "number" && invalidatedVersion > entry.createdVersion) {
408
+ return true;
409
+ }
410
+ }
411
+ return false;
412
+ }
413
+ async isStaleAsync(entry, now = Date.now()) {
414
+ if (this.adapter) {
415
+ return this.isAdapterEntryStale(entry, now);
416
+ }
417
+ return this.isStale(entry, now);
418
+ }
419
+ revalidateTag(tag, options = {}) {
420
+ const normalized = normalizeCacheTag(tag);
421
+ const count = this.invalidateTag(normalized);
422
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0,
423
+ options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
424
+ );
425
+ return count;
426
+ }
427
+ async revalidateTagAsync(tag, options = {}) {
428
+ const normalized = normalizeCacheTag(tag);
429
+ const count = this.invalidateTag(normalized);
430
+ await _optionalChain([this, 'access', _31 => _31.adapter, 'optionalAccess', _32 => _32.invalidateTags, 'optionalCall', _33 => _33([this.createAdapterTag(normalized)])]);
431
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0,
432
+ options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
433
+ );
434
+ return count;
435
+ }
436
+ revalidatePath(routePath) {
437
+ const normalizedPath = normalizeRevalidatePath(routePath);
438
+ const pathTag = createPathCacheTag(normalizedPath);
439
+ const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
440
+ const count = this.invalidateTag(pathTag);
441
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.revalidatePath", path: normalizedPath, count });
442
+ if (pprCount > 0) {
443
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
444
+ type: "ppr.shell.invalidated",
445
+ route: normalizedPath,
446
+ reason: "revalidatePath",
447
+ count: pprCount
448
+ });
449
+ }
450
+ return count;
451
+ }
452
+ async revalidatePathAsync(routePath) {
453
+ const normalizedPath = normalizeRevalidatePath(routePath);
454
+ const pathTag = createPathCacheTag(normalizedPath);
455
+ const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
456
+ const count = this.invalidateTag(pathTag);
457
+ await _optionalChain([this, 'access', _34 => _34.adapter, 'optionalAccess', _35 => _35.invalidateTags, 'optionalCall', _36 => _36([this.createAdapterTag(pathTag)])]);
458
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.revalidatePath", path: normalizedPath, count });
459
+ if (pprCount > 0) {
460
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
461
+ type: "ppr.shell.invalidated",
462
+ route: normalizedPath,
463
+ reason: "revalidatePath",
464
+ count: pprCount
465
+ });
466
+ }
467
+ return count;
468
+ }
469
+ async getOrSet(key, producer, options = {}) {
470
+ normalizeRevalidate(options.revalidate);
471
+ const cached = await this.getEntryAsync(key);
472
+ if (cached) {
473
+ return cached.value;
474
+ }
475
+ const inflight = this.inflight.get(key);
476
+ if (inflight && !this.wasInvalidatedSince(inflight.tags, inflight.startVersion)) {
477
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.dedupe", key });
478
+ return inflight.promise;
479
+ }
480
+ const tags = Array.from(normalizeCacheOptionsTags(options));
481
+ const generation = this.generation;
482
+ const startVersion = this.version;
483
+ const promise = this.fillCacheEntry(key, producer, options, tags, generation).catch((error) => {
484
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.error", key, operation: "set", error });
485
+ throw error;
486
+ }).finally(() => {
487
+ if (_optionalChain([this, 'access', _37 => _37.inflight, 'access', _38 => _38.get, 'call', _39 => _39(key), 'optionalAccess', _40 => _40.promise]) === promise) {
488
+ this.inflight.delete(key);
489
+ }
490
+ });
491
+ this.inflight.set(key, { promise, tags, startVersion });
492
+ return promise;
493
+ }
494
+ /** A fill that started before one of its tags was invalidated cannot satisfy later readers. */
495
+ wasInvalidatedSince(tags, version) {
496
+ for (const tag of tags) {
497
+ const invalidatedVersion = this.invalidatedTagVersions.get(tag);
498
+ if (invalidatedVersion !== void 0 && invalidatedVersion > version) return true;
499
+ }
500
+ return false;
501
+ }
502
+ async fillCacheEntry(key, producer, options, tags, generation) {
503
+ const adapter = this.adapter;
504
+ const namespace = this.namespace;
505
+ const lease = { ...this.lease };
506
+ const leaseKey = `${namespace}:lease:${key}`;
507
+ let leaseToken;
508
+ if (_optionalChain([adapter, 'optionalAccess', _41 => _41.acquireLease]) && adapter.releaseLease && lease.enabled) {
509
+ leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
510
+ if (!leaseToken) {
511
+ const shared = await this.waitForAdapterEntry(
512
+ key,
513
+ adapter,
514
+ namespace,
515
+ lease,
516
+ generation
517
+ );
518
+ if (shared) {
519
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.dedupe", key });
520
+ return shared.value;
521
+ }
522
+ if (generation === this.generation) {
523
+ leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
524
+ }
525
+ }
526
+ }
527
+ const initialCreatedVersion = this.version;
528
+ const activeGeneration = {
529
+ tags: new Set(tags),
530
+ createdVersion: initialCreatedVersion
531
+ };
532
+ this.activeGenerations.add(activeGeneration);
533
+ try {
534
+ const initialTagVersions = await this.getAdapterTagVersions(tags, adapter, namespace);
535
+ const value = await producer();
536
+ if (generation === this.generation) {
537
+ await this.writeAsync(key, value, options, initialTagVersions, initialCreatedVersion);
538
+ }
539
+ return value;
540
+ } finally {
541
+ this.activeGenerations.delete(activeGeneration);
542
+ this.pruneInvalidatedTagVersions(activeGeneration.tags);
543
+ if (leaseToken && _optionalChain([adapter, 'optionalAccess', _42 => _42.releaseLease])) {
544
+ try {
545
+ await adapter.releaseLease(leaseKey, leaseToken);
546
+ } catch (error) {
547
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.error", key, operation: "set", error });
548
+ }
549
+ }
550
+ }
551
+ }
552
+ async waitForAdapterEntry(key, adapter, namespace, lease, generation) {
553
+ const deadline = Date.now() + lease.waitTimeoutMs;
554
+ while (Date.now() < deadline) {
555
+ await delay(lease.pollIntervalMs);
556
+ if (generation !== this.generation) return void 0;
557
+ const entry = await adapter.get(`${namespace}:entry:${key}`);
558
+ if (generation !== this.generation) return void 0;
559
+ if (!entry) {
560
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.miss", key });
561
+ continue;
562
+ }
563
+ assertFarmCacheEntry(entry, key);
564
+ const stale = await this.isAdapterEntryStale(entry, Date.now(), adapter, namespace);
565
+ if (generation !== this.generation) return void 0;
566
+ if (stale) {
567
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
568
+ type: "cache.stale",
569
+ key,
570
+ tags: [...entry.tags],
571
+ revalidate: entry.revalidate
572
+ });
573
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, { type: "cache.miss", key, reason: "stale" });
574
+ } else {
575
+ _chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
576
+ type: "cache.hit",
577
+ key,
578
+ tags: [...entry.tags],
579
+ revalidate: entry.revalidate,
580
+ stale: false
581
+ });
582
+ return { ...entry, key };
583
+ }
584
+ }
585
+ return void 0;
586
+ }
587
+ countEntriesForTags(tags) {
588
+ let count = 0;
589
+ for (const entry of _nullishCoalesce(this.entriesByTag.get(tags[0]), () => ( []))) {
590
+ if (tags.every((tag) => entry.tags.has(tag))) {
591
+ count++;
592
+ }
593
+ }
594
+ return count;
595
+ }
596
+ invalidateTag(normalizedTag) {
597
+ const count = _nullishCoalesce(_optionalChain([this, 'access', _43 => _43.entriesByTag, 'access', _44 => _44.get, 'call', _45 => _45(normalizedTag), 'optionalAccess', _46 => _46.size]), () => ( 0));
598
+ this.invalidatedTagVersions.delete(normalizedTag);
599
+ this.invalidatedTagVersions.set(normalizedTag, ++this.version);
600
+ this.pruneInvalidatedTagVersions([normalizedTag]);
601
+ return count;
602
+ }
603
+ toPublicEntry(entry) {
604
+ return {
605
+ key: entry.key,
606
+ value: entry.value,
607
+ tags: Array.from(entry.tags),
608
+ tagVersions: entry.tagVersions,
609
+ createdAt: entry.createdAt,
610
+ createdVersion: entry.createdVersion,
611
+ revalidate: entry.revalidate
612
+ };
613
+ }
614
+ hydrateLocalEntry(entry) {
615
+ this.storeLocalEntry({
616
+ key: entry.key,
617
+ value: entry.value,
618
+ tags: new Set(entry.tags.map(normalizeCacheTag)),
619
+ tagVersions: entry.tagVersions,
620
+ createdAt: entry.createdAt,
621
+ createdVersion: _nullishCoalesce(entry.createdVersion, () => ( ++this.version)),
622
+ revalidate: normalizeRevalidate(entry.revalidate)
623
+ });
624
+ }
625
+ touchEntry(key, entry) {
626
+ this.entries.delete(key);
627
+ this.entries.set(key, entry);
628
+ }
629
+ storeLocalEntry(entry) {
630
+ const removed = [];
631
+ const replaced = this.detachLocalEntry(entry.key);
632
+ if (replaced) removed.push(replaced);
633
+ this.entries.set(entry.key, entry);
634
+ for (const tag of entry.tags) {
635
+ let tagged = this.entriesByTag.get(tag);
636
+ if (!tagged) this.entriesByTag.set(tag, tagged = /* @__PURE__ */ new Set());
637
+ tagged.add(entry);
638
+ }
639
+ while (this.entries.size > this.maxEntries) {
640
+ const oldestKey = this.entries.keys().next().value;
641
+ if (oldestKey === void 0) break;
642
+ removed.push(this.detachLocalEntry(oldestKey));
643
+ }
644
+ for (const removedEntry of removed) this.pruneInvalidatedTagVersions(removedEntry.tags);
645
+ }
646
+ deleteLocalEntry(key) {
647
+ const entry = this.detachLocalEntry(key);
648
+ if (!entry) return false;
649
+ this.pruneInvalidatedTagVersions(entry.tags);
650
+ return true;
651
+ }
652
+ detachLocalEntry(key) {
653
+ const entry = this.entries.get(key);
654
+ if (!entry) return void 0;
655
+ this.entries.delete(key);
656
+ for (const tag of entry.tags) {
657
+ const tagged = this.entriesByTag.get(tag);
658
+ if (!tagged) continue;
659
+ tagged.delete(entry);
660
+ if (tagged.size === 0) this.entriesByTag.delete(tag);
661
+ }
662
+ return entry;
663
+ }
664
+ /**
665
+ * Drop invalidation versions that no local entry or active fill can be stale against.
666
+ * Callers pass only the tags whose dependents just changed, so the cost is bounded by
667
+ * the entries sharing those tags rather than by the whole cache.
668
+ */
669
+ pruneInvalidatedTagVersions(tags) {
670
+ tags: for (const tag of tags) {
671
+ const invalidatedVersion = this.invalidatedTagVersions.get(tag);
672
+ if (invalidatedVersion === void 0) continue;
673
+ for (const entry of _nullishCoalesce(this.entriesByTag.get(tag), () => ( []))) {
674
+ if (entry.createdVersion < invalidatedVersion) continue tags;
675
+ }
676
+ for (const generation of this.activeGenerations) {
677
+ if (generation.tags.has(tag) && generation.createdVersion < invalidatedVersion)
678
+ continue tags;
679
+ }
680
+ this.invalidatedTagVersions.delete(tag);
681
+ }
682
+ }
683
+ createAdapterKey(key) {
684
+ return `${this.namespace}:entry:${key}`;
685
+ }
686
+ createAdapterTag(tag) {
687
+ return `${this.namespace}:tag:${tag}`;
688
+ }
689
+ async getAdapterTagVersions(tags, adapter = this.adapter, namespace = this.namespace) {
690
+ if (!_optionalChain([adapter, 'optionalAccess', _47 => _47.getTagVersions]) || tags.length === 0) return {};
691
+ const normalized = tags.map(normalizeCacheTag);
692
+ const physicalTags = normalized.map((tag) => `${namespace}:tag:${tag}`);
693
+ const versions = await adapter.getTagVersions(physicalTags);
694
+ return Object.fromEntries(
695
+ normalized.map((tag, index) => [
696
+ tag,
697
+ normalizeAdapterVersion(versions[physicalTags[index]])
698
+ ])
699
+ );
700
+ }
701
+ async isAdapterEntryStale(entry, now = Date.now(), adapter = this.adapter, namespace = this.namespace) {
702
+ if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
703
+ return true;
704
+ }
705
+ const currentVersions = await this.getAdapterTagVersions(entry.tags, adapter, namespace);
706
+ for (const tag of entry.tags) {
707
+ if (normalizeAdapterVersion(currentVersions[tag]) > normalizeAdapterVersion(_optionalChain([entry, 'access', _48 => _48.tagVersions, 'optionalAccess', _49 => _49[tag]]))) {
708
+ return true;
709
+ }
710
+ }
711
+ return false;
712
+ }
713
+ };
714
+ _chunkS3JO3N4Hcjs.__name.call(void 0, _FarmDataCache, "FarmDataCache");
715
+ var FarmDataCache = _FarmDataCache;
716
+ var FARM_DATA_CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.dataCache");
717
+ var farmDataCacheGlobal = globalThis;
718
+ var sharedFarmDataCache = _nullishCoalesce(farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL], () => ( (farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] = new FarmDataCache())));
719
+ function getFarmDataCache() {
720
+ return sharedFarmDataCache;
721
+ }
722
+ _chunkS3JO3N4Hcjs.__name.call(void 0, getFarmDataCache, "getFarmDataCache");
723
+ function configureFarmCache(config) {
724
+ sharedFarmDataCache.configure(config);
725
+ }
726
+ _chunkS3JO3N4Hcjs.__name.call(void 0, configureFarmCache, "configureFarmCache");
727
+ function unstable_cache(fn, keyParts = [], options = {}) {
728
+ return async (...args) => {
729
+ const locale = _optionalChain([_chunkLIUGYUX3cjs.getActiveFarmI18nSnapshot.call(void 0, ), 'optionalAccess', _50 => _50.locale]);
730
+ const key = createFarmCacheKey([
731
+ "unstable_cache",
732
+ getFunctionCacheIdentity(fn),
733
+ locale ? ["locale", locale] : null,
734
+ keyParts,
735
+ args
736
+ ]);
737
+ return getFarmDataCache().getOrSet(key, () => fn(...args), options);
738
+ };
739
+ }
740
+ _chunkS3JO3N4Hcjs.__name.call(void 0, unstable_cache, "unstable_cache");
741
+ function revalidateTag(_tag, _profile) {
742
+ const cache = getFarmDataCache();
743
+ if (cache.hasAdapter) {
744
+ const task = cache.revalidateTagAsync(_tag, {
745
+ source: "revalidateTag",
746
+ profile: _profile
747
+ }).then(() => void 0);
748
+ _chunkZEG3OPIBcjs.notifyFarmCacheTask.call(void 0, task);
749
+ return task;
750
+ }
751
+ cache.revalidateTag(_tag, {
752
+ source: "revalidateTag",
753
+ profile: _profile
754
+ });
755
+ }
756
+ _chunkS3JO3N4Hcjs.__name.call(void 0, revalidateTag, "revalidateTag");
757
+ function updateTag(tag) {
758
+ const cache = getFarmDataCache();
759
+ if (cache.hasAdapter) {
760
+ const task = cache.revalidateTagAsync(tag, { source: "updateTag" }).then(() => void 0);
761
+ _chunkZEG3OPIBcjs.notifyFarmCacheTask.call(void 0, task);
762
+ return task;
763
+ }
764
+ cache.revalidateTag(tag, { source: "updateTag" });
765
+ }
766
+ _chunkS3JO3N4Hcjs.__name.call(void 0, updateTag, "updateTag");
767
+ function revalidatePath(routePath) {
768
+ const cache = getFarmDataCache();
769
+ if (cache.hasAdapter) {
770
+ const task = cache.revalidatePathAsync(routePath).then(() => void 0);
771
+ _chunkZEG3OPIBcjs.notifyFarmCacheTask.call(void 0, task);
772
+ return task;
773
+ }
774
+ cache.revalidatePath(routePath);
775
+ }
776
+ _chunkS3JO3N4Hcjs.__name.call(void 0, revalidatePath, "revalidatePath");
777
+ function invalidate(key) {
778
+ const clientKey = createRouteDataCacheKey(key);
779
+ const task = updateTag(createRouteDataCacheTag(key));
780
+ _chunkZEG3OPIBcjs.notifyFarmCacheInvalidation.call(void 0, clientKey);
781
+ return task;
782
+ }
783
+ _chunkS3JO3N4Hcjs.__name.call(void 0, invalidate, "invalidate");
784
+ function invalidateRouteData(key) {
785
+ return invalidate(key);
786
+ }
787
+ _chunkS3JO3N4Hcjs.__name.call(void 0, invalidateRouteData, "invalidateRouteData");
788
+ async function applyFarmCacheInvalidationTargets(targets) {
789
+ if (!Array.isArray(targets)) {
790
+ throw new TypeError("Cache invalidations must resolve to an array of targets.");
791
+ }
792
+ const clientKeys = [];
793
+ for (const target of targets) {
794
+ assertFarmCacheInvalidationTarget(target);
795
+ if ("key" in target) {
796
+ await invalidate(target.key);
797
+ clientKeys.push(createRouteDataCacheKey(target.key));
798
+ } else if ("path" in target) {
799
+ await revalidatePath(target.path);
800
+ } else {
801
+ await updateTag(target.tag);
802
+ }
803
+ }
804
+ return Array.from(new Set(clientKeys));
805
+ }
806
+ _chunkS3JO3N4Hcjs.__name.call(void 0, applyFarmCacheInvalidationTargets, "applyFarmCacheInvalidationTargets");
807
+ function createPathCacheTag(routePath) {
808
+ return `path:${normalizeRevalidatePath(routePath)}`;
809
+ }
810
+ _chunkS3JO3N4Hcjs.__name.call(void 0, createPathCacheTag, "createPathCacheTag");
811
+ function createRouteDataCacheTag(key) {
812
+ return `route-data:${createRouteDataCacheKey(key)}`;
813
+ }
814
+ _chunkS3JO3N4Hcjs.__name.call(void 0, createRouteDataCacheTag, "createRouteDataCacheTag");
815
+ function createRouteDataCacheKey(key) {
816
+ return createFarmCacheKey(Array.isArray(key) ? key : [key]);
817
+ }
818
+ _chunkS3JO3N4Hcjs.__name.call(void 0, createRouteDataCacheKey, "createRouteDataCacheKey");
819
+ function normalizeRevalidatePath(routePath) {
820
+ if (typeof routePath !== "string") {
821
+ throw new TypeError("revalidatePath expects a path string.");
822
+ }
823
+ let normalized = routePath.trim();
824
+ if (!normalized) {
825
+ throw new Error("revalidatePath expects a non-empty path.");
826
+ }
827
+ try {
828
+ if (/^https?:\/\//i.test(normalized)) {
829
+ normalized = new URL(normalized).pathname;
830
+ }
831
+ } catch (e) {
832
+ }
833
+ normalized = _nullishCoalesce(normalized.split(/[?#]/, 1)[0], () => ( normalized));
834
+ normalized = normalized.startsWith("/") ? normalized : `/${normalized}`;
835
+ normalized = normalized.replace(/\/{2,}/g, "/");
836
+ normalized = new URL(normalized, "http://farm.invalid").pathname;
837
+ if (normalized.length > 1) {
838
+ normalized = normalized.replace(/\/+$/, "");
839
+ }
840
+ return normalized || "/";
841
+ }
842
+ _chunkS3JO3N4Hcjs.__name.call(void 0, normalizeRevalidatePath, "normalizeRevalidatePath");
843
+ function createFarmCacheKey(parts) {
844
+ return stableSerialize(parts);
845
+ }
846
+ _chunkS3JO3N4Hcjs.__name.call(void 0, createFarmCacheKey, "createFarmCacheKey");
847
+ function normalizeRevalidate(revalidate) {
848
+ if (revalidate === false || revalidate === void 0) {
849
+ return revalidate;
850
+ }
851
+ if (!Number.isFinite(revalidate) || revalidate < 0) {
852
+ throw new TypeError("Cache revalidate must be false or a finite, non-negative number.");
853
+ }
854
+ return revalidate;
855
+ }
856
+ _chunkS3JO3N4Hcjs.__name.call(void 0, normalizeRevalidate, "normalizeRevalidate");
857
+ function normalizeCacheTag(tag) {
858
+ if (typeof tag !== "string") {
859
+ throw new TypeError("Cache tags must be strings.");
860
+ }
861
+ const normalized = tag.trim();
862
+ if (!normalized) {
863
+ throw new Error("Cache tags cannot be empty.");
864
+ }
865
+ return normalized;
866
+ }
867
+ _chunkS3JO3N4Hcjs.__name.call(void 0, normalizeCacheTag, "normalizeCacheTag");
868
+ function normalizeCacheNamespace(namespace) {
869
+ if (typeof namespace !== "string") {
870
+ throw new TypeError("Cache namespace must be a string.");
871
+ }
872
+ const normalized = namespace.trim().replace(/:+$/g, "");
873
+ if (!normalized) {
874
+ throw new Error("Cache namespace cannot be empty.");
875
+ }
876
+ return normalized;
877
+ }
878
+ _chunkS3JO3N4Hcjs.__name.call(void 0, normalizeCacheNamespace, "normalizeCacheNamespace");
879
+ function normalizeAdapterVersion(value) {
880
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
881
+ }
882
+ _chunkS3JO3N4Hcjs.__name.call(void 0, normalizeAdapterVersion, "normalizeAdapterVersion");
883
+ function normalizePositiveDuration(value, fallback, name) {
884
+ if (value === void 0) return fallback;
885
+ if (!Number.isFinite(value) || value <= 0) {
886
+ throw new TypeError(`${name} must be a positive number of milliseconds.`);
887
+ }
888
+ return Math.floor(value);
889
+ }
890
+ _chunkS3JO3N4Hcjs.__name.call(void 0, normalizePositiveDuration, "normalizePositiveDuration");
891
+ function normalizePositiveInteger(value, fallback, name) {
892
+ if (value === void 0) return fallback;
893
+ if (!Number.isSafeInteger(value) || value <= 0) {
894
+ throw new TypeError(`${name} must be a positive integer.`);
895
+ }
896
+ return value;
897
+ }
898
+ _chunkS3JO3N4Hcjs.__name.call(void 0, normalizePositiveInteger, "normalizePositiveInteger");
899
+ function delay(ms) {
900
+ return new Promise((resolve) => setTimeout(resolve, ms));
901
+ }
902
+ _chunkS3JO3N4Hcjs.__name.call(void 0, delay, "delay");
903
+ function normalizeCacheOptionsTags(options) {
904
+ const tags = /* @__PURE__ */ new Set();
905
+ for (const tag of _nullishCoalesce(options.tags, () => ( []))) {
906
+ tags.add(normalizeCacheTag(tag));
907
+ }
908
+ for (const routePath of _nullishCoalesce(options.paths, () => ( []))) {
909
+ tags.add(createPathCacheTag(routePath));
910
+ }
911
+ return tags;
912
+ }
913
+ _chunkS3JO3N4Hcjs.__name.call(void 0, normalizeCacheOptionsTags, "normalizeCacheOptionsTags");
914
+ function assertFarmCacheEntry(entry, expectedKey) {
915
+ if (!entry || typeof entry !== "object" || entry.key !== expectedKey || !Array.isArray(entry.tags) || typeof entry.createdAt !== "number") {
916
+ throw new TypeError(
917
+ `Cache adapter returned an invalid entry for ${JSON.stringify(expectedKey)}.`
918
+ );
919
+ }
920
+ }
921
+ _chunkS3JO3N4Hcjs.__name.call(void 0, assertFarmCacheEntry, "assertFarmCacheEntry");
922
+ function assertFarmCacheInvalidationTarget(target) {
923
+ if (!target || typeof target !== "object") {
924
+ throw new TypeError("Cache invalidation targets must be { key }, { path }, or { tag }.");
925
+ }
926
+ if ("key" in target) {
927
+ const key = target.key;
928
+ if (typeof key === "string" || Array.isArray(key)) return;
929
+ } else if ("path" in target && typeof target.path === "string") {
930
+ return;
931
+ } else if ("tag" in target && typeof target.tag === "string") {
932
+ return;
933
+ }
934
+ throw new TypeError("Cache invalidation targets must contain a string/array key, path, or tag.");
935
+ }
936
+ _chunkS3JO3N4Hcjs.__name.call(void 0, assertFarmCacheInvalidationTarget, "assertFarmCacheInvalidationTarget");
937
+ function getFunctionCacheIdentity(fn) {
938
+ const name = fn.name || "anonymous";
939
+ return `${name}:${hashFunctionSource(String(fn))}`;
940
+ }
941
+ _chunkS3JO3N4Hcjs.__name.call(void 0, getFunctionCacheIdentity, "getFunctionCacheIdentity");
942
+ function hashFunctionSource(source) {
943
+ let hash = 2166136261;
944
+ for (let index = 0; index < source.length; index++) {
945
+ hash ^= source.charCodeAt(index);
946
+ hash = Math.imul(hash, 16777619);
947
+ }
948
+ return (hash >>> 0).toString(36);
949
+ }
950
+ _chunkS3JO3N4Hcjs.__name.call(void 0, hashFunctionSource, "hashFunctionSource");
951
+ function compareCodepoint(a, b) {
952
+ return a < b ? -1 : a > b ? 1 : 0;
953
+ }
954
+ _chunkS3JO3N4Hcjs.__name.call(void 0, compareCodepoint, "compareCodepoint");
955
+ function serializeBinaryBytes(bytes) {
956
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
957
+ }
958
+ _chunkS3JO3N4Hcjs.__name.call(void 0, serializeBinaryBytes, "serializeBinaryBytes");
959
+ function serializeCanonicalStringEntries(entries, seen) {
960
+ const valuesByKey = /* @__PURE__ */ new Map();
961
+ for (const [key, item] of entries) {
962
+ const values = valuesByKey.get(key);
963
+ if (values) values.push(item);
964
+ else valuesByKey.set(key, [item]);
965
+ }
966
+ return Array.from(valuesByKey.keys()).sort(compareCodepoint).flatMap(
967
+ (key) => valuesByKey.get(key).map((item) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`)
968
+ ).join(",");
969
+ }
970
+ _chunkS3JO3N4Hcjs.__name.call(void 0, serializeCanonicalStringEntries, "serializeCanonicalStringEntries");
971
+ function isPlainCacheKeyObject(value) {
972
+ const prototype = Object.getPrototypeOf(value);
973
+ if (prototype === null) return true;
974
+ const constructor = _optionalChain([Object, 'access', _51 => _51.getOwnPropertyDescriptor, 'call', _52 => _52(prototype, "constructor"), 'optionalAccess', _53 => _53.value]);
975
+ return Object.getPrototypeOf(prototype) === null && typeof constructor === "function" && constructor.name === "Object";
976
+ }
977
+ _chunkS3JO3N4Hcjs.__name.call(void 0, isPlainCacheKeyObject, "isPlainCacheKeyObject");
978
+ function getCacheKeyValueType(value) {
979
+ const prototype = Object.getPrototypeOf(value);
980
+ const constructor = prototype ? _optionalChain([Object, 'access', _54 => _54.getOwnPropertyDescriptor, 'call', _55 => _55(prototype, "constructor"), 'optionalAccess', _56 => _56.value]) : void 0;
981
+ if (typeof constructor === "function" && constructor.name) {
982
+ return constructor.name;
983
+ }
984
+ return Object.prototype.toString.call(value).slice(8, -1) || "object";
985
+ }
986
+ _chunkS3JO3N4Hcjs.__name.call(void 0, getCacheKeyValueType, "getCacheKeyValueType");
987
+ function stableSerialize(value, seen = /* @__PURE__ */ new WeakSet()) {
988
+ if (value === null) return "null";
989
+ if (value === void 0) return "undefined";
990
+ const valueType = typeof value;
991
+ if (valueType === "string") return JSON.stringify(value);
992
+ if (valueType === "number" || valueType === "boolean" || valueType === "bigint") {
993
+ return `${valueType}:${String(value)}`;
994
+ }
995
+ if (valueType === "symbol") {
996
+ return `symbol:${String(value)}`;
997
+ }
998
+ if (valueType === "function") {
999
+ return `function:${getFunctionCacheIdentity(value)}`;
1000
+ }
1001
+ if (value instanceof Date) {
1002
+ return Number.isNaN(value.getTime()) ? "date:invalid" : `date:${value.toISOString()}`;
1003
+ }
1004
+ if (value instanceof URL) {
1005
+ return `url:${value.toString()}`;
1006
+ }
1007
+ if (value instanceof RegExp) {
1008
+ return `regexp:${value.toString()}`;
1009
+ }
1010
+ if (value instanceof ArrayBuffer) {
1011
+ return `arraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
1012
+ }
1013
+ if (typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer) {
1014
+ return `sharedarraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
1015
+ }
1016
+ if (ArrayBuffer.isView(value)) {
1017
+ const viewType = Object.prototype.toString.call(value).slice(8, -1);
1018
+ const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
1019
+ return `binary:${viewType}:${serializeBinaryBytes(bytes)}`;
1020
+ }
1021
+ if (value && typeof value === "object") {
1022
+ if (seen.has(value)) {
1023
+ return "[Circular]";
1024
+ }
1025
+ seen.add(value);
1026
+ if (Array.isArray(value)) {
1027
+ const items = [];
1028
+ for (let index = 0; index < value.length; index++) {
1029
+ items.push(
1030
+ Object.prototype.hasOwnProperty.call(value, index) ? stableSerialize(value[index], seen) : "[Hole]"
1031
+ );
1032
+ }
1033
+ seen.delete(value);
1034
+ return `[${items.join(",")}]`;
1035
+ }
1036
+ if (value instanceof Set) {
1037
+ const items = Array.from(value, (item) => stableSerialize(item, seen)).sort(compareCodepoint);
1038
+ seen.delete(value);
1039
+ return `set:[${items.join(",")}]`;
1040
+ }
1041
+ if (value instanceof Map) {
1042
+ const items = Array.from(
1043
+ value,
1044
+ ([key, item]) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`
1045
+ ).sort(compareCodepoint);
1046
+ seen.delete(value);
1047
+ return `map:[${items.join(",")}]`;
1048
+ }
1049
+ if (value instanceof URLSearchParams) {
1050
+ const serialized2 = serializeCanonicalStringEntries(value, seen);
1051
+ seen.delete(value);
1052
+ return `urlsearchparams:[${serialized2}]`;
1053
+ }
1054
+ if (value instanceof Headers) {
1055
+ const serialized2 = serializeCanonicalStringEntries(value, seen);
1056
+ seen.delete(value);
1057
+ return `headers:[${serialized2}]`;
1058
+ }
1059
+ if (!isPlainCacheKeyObject(value)) {
1060
+ throw new TypeError(
1061
+ `Cache keys do not support ${getCacheKeyValueType(value)} values. Convert the value to an explicit stable string or structured key before caching.`
1062
+ );
1063
+ }
1064
+ const entries = Object.entries(value).sort(
1065
+ ([a], [b]) => compareCodepoint(a, b)
1066
+ );
1067
+ const serialized = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item, seen)}`).join(",");
1068
+ seen.delete(value);
1069
+ return `{${serialized}}`;
1070
+ }
1071
+ return String(value);
1072
+ }
1073
+ _chunkS3JO3N4Hcjs.__name.call(void 0, stableSerialize, "stableSerialize");
1074
+
1075
+
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+
1082
+
1083
+
1084
+
1085
+
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+ exports.createFarmCacheInvalidationStream = createFarmCacheInvalidationStream; exports.defineCacheKey = defineCacheKey; exports.storageCacheAdapter = storageCacheAdapter; exports.FarmDataCache = FarmDataCache; exports.getFarmDataCache = getFarmDataCache; exports.configureFarmCache = configureFarmCache; exports.unstable_cache = unstable_cache; exports.revalidateTag = revalidateTag; exports.updateTag = updateTag; exports.revalidatePath = revalidatePath; exports.invalidate = invalidate; exports.invalidateRouteData = invalidateRouteData; exports.applyFarmCacheInvalidationTargets = applyFarmCacheInvalidationTargets; exports.createPathCacheTag = createPathCacheTag; exports.createRouteDataCacheTag = createRouteDataCacheTag; exports.createRouteDataCacheKey = createRouteDataCacheKey; exports.normalizeRevalidatePath = normalizeRevalidatePath; exports.createFarmCacheKey = createFarmCacheKey;