@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
@@ -1,1853 +1,44 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
20
2
 
21
- // src/server-fn.ts
22
- var server_fn_exports = {};
23
- __export(server_fn_exports, {
24
- FARM_SERVER_FN_FAILURE_SYMBOL: () => FARM_SERVER_FN_FAILURE_SYMBOL,
25
- FARM_SERVER_FN_SYMBOL: () => FARM_SERVER_FN_SYMBOL,
26
- ServerActionError: () => ServerActionError,
27
- ServerFnFailure: () => ServerFnFailure,
28
- _attachServerFunctionDescriptor: () => _attachServerFunctionDescriptor,
29
- _describeServerFunction: () => _describeServerFunction,
30
- _invokeServerFunction: () => _invokeServerFunction,
31
- _parseServerFnSchema: () => _parseServerFnSchema,
32
- _runServerFunctionForCaller: () => _runServerFunctionForCaller,
33
- createServerFn: () => createServerFn,
34
- createServerFnTransportError: () => createServerFnTransportError,
35
- createServerFunctionDescriptor: () => createServerFunctionDescriptor,
36
- createServerMiddleware: () => createServerMiddleware,
37
- isServerFnFailure: () => isServerFnFailure
38
- });
39
- module.exports = __toCommonJS(server_fn_exports);
40
3
 
41
- // src/server-action-security.ts
42
- var import_node_async_hooks = require("async_hooks");
43
4
 
44
- // src/cache-invalidation.ts
45
- var FARM_CACHE_INVALIDATION_STATE = /* @__PURE__ */ Symbol.for("farm.cacheInvalidationState");
46
- var globalState = globalThis;
47
- function getFarmCacheInvalidationState() {
48
- return globalState[FARM_CACHE_INVALIDATION_STATE] ?? (globalState[FARM_CACHE_INVALIDATION_STATE] = {
49
- listeners: /* @__PURE__ */ new Set(),
50
- taskListeners: /* @__PURE__ */ new Set()
51
- });
52
- }
53
- __name(getFarmCacheInvalidationState, "getFarmCacheInvalidationState");
54
- function warnFarmCacheListenerError(scope, error) {
55
- const detail = error instanceof Error ? error.stack ?? error.message : String(error);
56
- console.warn(`[farm:cache] ${scope} listener failed: ${detail}`);
57
- }
58
- __name(warnFarmCacheListenerError, "warnFarmCacheListenerError");
59
- function notifyFarmCacheInvalidation(key, source = "local") {
60
- if (typeof key !== "string" || key.length === 0) return;
61
- for (const listener of getFarmCacheInvalidationState().listeners) {
62
- try {
63
- listener(key, source);
64
- } catch (error) {
65
- warnFarmCacheListenerError("invalidation", error);
66
- }
67
- }
68
- }
69
- __name(notifyFarmCacheInvalidation, "notifyFarmCacheInvalidation");
70
- function notifyFarmCacheTask(task) {
71
- for (const listener of getFarmCacheInvalidationState().taskListeners) {
72
- try {
73
- listener(task);
74
- } catch (error) {
75
- warnFarmCacheListenerError("task", error);
76
- }
77
- }
78
- }
79
- __name(notifyFarmCacheTask, "notifyFarmCacheTask");
80
- function subscribeFarmCacheInvalidation(listener) {
81
- const state = getFarmCacheInvalidationState();
82
- state.listeners.add(listener);
83
- return () => state.listeners.delete(listener);
84
- }
85
- __name(subscribeFarmCacheInvalidation, "subscribeFarmCacheInvalidation");
86
- function subscribeFarmCacheTask(listener) {
87
- const state = getFarmCacheInvalidationState();
88
- state.taskListeners.add(listener);
89
- return () => state.taskListeners.delete(listener);
90
- }
91
- __name(subscribeFarmCacheTask, "subscribeFarmCacheTask");
92
5
 
93
- // src/server-fn-error.ts
94
- var FARM_SERVER_FN_FAILURE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-fn.failure");
95
- var _ServerFnFailure = class _ServerFnFailure extends Error {
96
- constructor(code, data, options) {
97
- super(options.message);
98
- this.name = "ServerFnFailure";
99
- this.code = code;
100
- this.data = data;
101
- this.status = options.status;
102
- Object.defineProperty(this, FARM_SERVER_FN_FAILURE_SYMBOL, {
103
- value: true,
104
- enumerable: false
105
- });
106
- }
107
- };
108
- __name(_ServerFnFailure, "ServerFnFailure");
109
- var ServerFnFailure = _ServerFnFailure;
110
- var _ServerActionError = class _ServerActionError extends Error {
111
- constructor(message = "Server function failed") {
112
- super(message);
113
- this.name = "ServerActionError";
114
- }
115
- };
116
- __name(_ServerActionError, "ServerActionError");
117
- var ServerActionError = _ServerActionError;
118
- function isServerFnFailure(value) {
119
- if (!value || typeof value !== "object") return false;
120
- const candidate = value;
121
- return candidate[FARM_SERVER_FN_FAILURE_SYMBOL] === true && candidate.name === "ServerFnFailure" && typeof candidate.code === "string" && Number.isInteger(candidate.status) && (candidate.status ?? 0) >= 400 && (candidate.status ?? 0) <= 599;
122
- }
123
- __name(isServerFnFailure, "isServerFnFailure");
124
- function createServerFnTransportError(value) {
125
- if (isSerializedServerFnFailure(value)) {
126
- return new ServerFnFailure(value.code, value.data, {
127
- status: value.status,
128
- message: value.message
129
- });
130
- }
131
- const message = value && typeof value === "object" && "message" in value && typeof value.message === "string" ? value.message : "Server function failed";
132
- return new ServerActionError(message);
133
- }
134
- __name(createServerFnTransportError, "createServerFnTransportError");
135
- function isSerializedServerFnFailure(value) {
136
- if (!value || typeof value !== "object") return false;
137
- const candidate = value;
138
- return candidate.name === "ServerFnFailure" && typeof candidate.message === "string" && typeof candidate.code === "string" && Number.isInteger(candidate.status) && (candidate.status ?? 0) >= 400 && (candidate.status ?? 0) <= 599 && "data" in candidate;
139
- }
140
- __name(isSerializedServerFnFailure, "isSerializedServerFnFailure");
141
6
 
142
- // src/server-action-security.ts
143
- var SERVER_ACTION_STORAGE_KEY = /* @__PURE__ */ Symbol.for("farm.serverActionStorage");
144
- var FALLBACK_ABORT_CONTROLLER_KEY = /* @__PURE__ */ Symbol.for("farm.serverActionFallbackAbortController");
145
- async function runWithServerActionRequest(request, callback) {
146
- throwIfAborted(request.signal);
147
- const context2 = {
148
- request,
149
- signal: request.signal,
150
- invalidations: /* @__PURE__ */ new Set(),
151
- cacheTasks: /* @__PURE__ */ new Set()
152
- };
153
- return getServerActionStorage().run(context2, async () => {
154
- try {
155
- const result = await callback();
156
- await Promise.all(context2.cacheTasks);
157
- return result;
158
- } catch (error) {
159
- await Promise.allSettled(context2.cacheTasks);
160
- throw error;
161
- }
162
- });
163
- }
164
- __name(runWithServerActionRequest, "runWithServerActionRequest");
165
- function getServerActionExecutionContext() {
166
- return getServerActionStorage().getStore();
167
- }
168
- __name(getServerActionExecutionContext, "getServerActionExecutionContext");
169
- function getServerActionSignal() {
170
- return getServerActionExecutionContext()?.signal ?? getFallbackAbortController().signal;
171
- }
172
- __name(getServerActionSignal, "getServerActionSignal");
173
- subscribeFarmCacheInvalidation((key) => {
174
- getServerActionExecutionContext()?.invalidations.add(key);
175
- });
176
- subscribeFarmCacheTask((task) => {
177
- getServerActionExecutionContext()?.cacheTasks.add(task);
178
- });
179
- function getServerActionStorage() {
180
- const globalState2 = globalThis;
181
- if (!globalState2[SERVER_ACTION_STORAGE_KEY]) {
182
- globalState2[SERVER_ACTION_STORAGE_KEY] = new import_node_async_hooks.AsyncLocalStorage();
183
- }
184
- return globalState2[SERVER_ACTION_STORAGE_KEY];
185
- }
186
- __name(getServerActionStorage, "getServerActionStorage");
187
- function getFallbackAbortController() {
188
- const globalState2 = globalThis;
189
- if (!globalState2[FALLBACK_ABORT_CONTROLLER_KEY]) {
190
- globalState2[FALLBACK_ABORT_CONTROLLER_KEY] = new AbortController();
191
- }
192
- return globalState2[FALLBACK_ABORT_CONTROLLER_KEY];
193
- }
194
- __name(getFallbackAbortController, "getFallbackAbortController");
195
- function throwIfAborted(signal) {
196
- if (!signal.aborted) return;
197
- if (signal.reason !== void 0) throw signal.reason;
198
- throw new DOMException("The operation was aborted", "AbortError");
199
- }
200
- __name(throwIfAborted, "throwIfAborted");
201
7
 
202
- // src/server/request-bridge.ts
203
- var CURRENT_REQUEST_RESOLVER_KEY = /* @__PURE__ */ Symbol.for("farm.currentRequestResolver");
204
- function getGlobalState() {
205
- return globalThis;
206
- }
207
- __name(getGlobalState, "getGlobalState");
208
- function _resolveCurrentRequest() {
209
- return getGlobalState()[CURRENT_REQUEST_RESOLVER_KEY]?.();
210
- }
211
- __name(_resolveCurrentRequest, "_resolveCurrentRequest");
212
8
 
213
- // src/tracing.ts
214
- var import_api = require("@opentelemetry/api");
215
- var FARM_TRACER_NAME = "@farm.js/core";
216
- var ALL_SPAN_KINDS = [
217
- "request",
218
- "render",
219
- "middleware",
220
- "api",
221
- "integration",
222
- "storage",
223
- "ppr",
224
- "build",
225
- "plugin"
226
- ];
227
- var DEFAULT_IGNORED_PATHS = [
228
- "/@vite/",
229
- "/@fs/",
230
- "/@id/",
231
- "/@react-refresh",
232
- "/node_modules/",
233
- "/__vite",
234
- "/.well-known/appspecific/"
235
- ];
236
- var FARM_REQUEST_METHOD_CONTEXT_KEY = (0, import_api.createContextKey)("@farm.js/core/request-method");
237
- var TRACING_RUNTIME = /* @__PURE__ */ Symbol.for("@farm.js/core/tracing-runtime/v1");
238
- var runtime = globalThis;
239
- var tracingState = runtime[TRACING_RUNTIME] ?? (runtime[TRACING_RUNTIME] = normalizeFarmTracingConfig(false));
240
- function normalizeFarmTracingConfig(config) {
241
- if (!config) {
242
- return {
243
- enabled: false,
244
- spans: new Set(ALL_SPAN_KINDS),
245
- recordEvents: true,
246
- attributes: {},
247
- ignorePaths: DEFAULT_IGNORED_PATHS
248
- };
249
- }
250
- if (config === true) {
251
- return {
252
- enabled: true,
253
- spans: new Set(ALL_SPAN_KINDS),
254
- recordEvents: true,
255
- attributes: {},
256
- ignorePaths: DEFAULT_IGNORED_PATHS
257
- };
258
- }
259
- return {
260
- enabled: config.enabled ?? true,
261
- spans: new Set(config.spans ?? ALL_SPAN_KINDS),
262
- recordEvents: config.recordEvents ?? true,
263
- attributes: { ...config.attributes },
264
- ignorePaths: [...DEFAULT_IGNORED_PATHS, ...config.ignorePaths ?? []]
265
- };
266
- }
267
- __name(normalizeFarmTracingConfig, "normalizeFarmTracingConfig");
268
- function recordFarmEventTrace(event) {
269
- if (!tracingState.enabled) return void 0;
270
- const activeContext = import_api.context.active();
271
- const activeSpan = import_api.trace.getSpan(activeContext);
272
- const traceContext = getSpanTraceContext(activeSpan);
273
- if (activeSpan && traceContext) {
274
- if (event.type === "route.matched") {
275
- const method = activeContext.getValue(FARM_REQUEST_METHOD_CONTEXT_KEY) ?? "HTTP";
276
- activeSpan.updateName(`${method} ${event.route}`);
277
- activeSpan.setAttribute("http.route", event.route);
278
- activeSpan.setAttribute("farm.route", event.route);
279
- }
280
- if (tracingState.recordEvents) {
281
- activeSpan.addEvent(event.type, toEventAttributes(event), event.timestamp);
282
- }
283
- const error = event.type === "request.error" ? void 0 : getEventError(event);
284
- if (error !== void 0) {
285
- if (event.type === "render.error") {
286
- recordSpanException(activeSpan, error);
287
- } else {
288
- recordSpanError(activeSpan, error);
289
- }
290
- }
291
- }
292
- const completedTraceContext = recordCompletedEventSpan(event, activeContext);
293
- return traceContext ?? completedTraceContext;
294
- }
295
- __name(recordFarmEventTrace, "recordFarmEventTrace");
296
- function recordCompletedEventSpan(event, parentContext) {
297
- const descriptor = getCompletedSpanDescriptor(event);
298
- if (!descriptor || !tracingState.spans.has(descriptor.kind)) return void 0;
299
- const tracer = import_api.trace.getTracer(FARM_TRACER_NAME);
300
- const span = tracer.startSpan(
301
- descriptor.name,
302
- {
303
- kind: import_api.SpanKind.INTERNAL,
304
- startTime: event.timestamp - descriptor.durationMs,
305
- attributes: {
306
- ...tracingState.attributes,
307
- ...toEventAttributes(event),
308
- "farm.event.type": event.type
309
- }
310
- },
311
- parentContext
312
- );
313
- const status = "status" in event && typeof event.status === "number" ? event.status : void 0;
314
- if (status !== void 0) setResponseStatus(span, status);
315
- const error = getEventError(event);
316
- if (error !== void 0) recordSpanError(span, error);
317
- const traceContext = getSpanTraceContext(span);
318
- span.end(event.timestamp);
319
- return traceContext;
320
- }
321
- __name(recordCompletedEventSpan, "recordCompletedEventSpan");
322
- function getCompletedSpanDescriptor(event) {
323
- if (!("durationMs" in event) || typeof event.durationMs !== "number") return void 0;
324
- switch (event.type) {
325
- case "render.complete":
326
- return { kind: "render", name: `farm.render ${event.route}`, durationMs: event.durationMs };
327
- case "render.stream.shellReady":
328
- return {
329
- kind: "render",
330
- name: `farm.render.shell ${event.route}`,
331
- durationMs: event.durationMs
332
- };
333
- case "render.stream.complete":
334
- return {
335
- kind: "render",
336
- name: `farm.render.stream ${event.route}`,
337
- durationMs: event.durationMs
338
- };
339
- case "middleware.complete":
340
- return {
341
- kind: "middleware",
342
- name: `farm.middleware ${event.name ?? event.route ?? "anonymous"}`,
343
- durationMs: event.durationMs
344
- };
345
- case "api.request.complete":
346
- case "api.error":
347
- return {
348
- kind: "api",
349
- name: `farm.api ${event.method} ${event.route}`,
350
- durationMs: event.durationMs
351
- };
352
- case "integration.api.call.complete":
353
- return {
354
- kind: "integration",
355
- name: `farm.integration ${event.integration}.${event.operation}`,
356
- durationMs: event.durationMs
357
- };
358
- case "storage.query.complete":
359
- return {
360
- kind: "storage",
361
- name: `farm.storage ${event.operation}`,
362
- durationMs: event.durationMs
363
- };
364
- case "ppr.refresh.complete":
365
- return {
366
- kind: "ppr",
367
- name: `farm.ppr.refresh ${event.route}`,
368
- durationMs: event.durationMs
369
- };
370
- case "build.complete":
371
- return {
372
- kind: "build",
373
- name: `farm.build${event.target ? ` ${event.target}` : ""}`,
374
- durationMs: event.durationMs
375
- };
376
- case "plugin.hook.complete":
377
- return {
378
- kind: "plugin",
379
- name: `farm.plugin ${event.plugin}.${event.hook}`,
380
- durationMs: event.durationMs
381
- };
382
- default:
383
- return void 0;
384
- }
385
- }
386
- __name(getCompletedSpanDescriptor, "getCompletedSpanDescriptor");
387
- function hashFarmCacheKey(value) {
388
- let hash = 2166136261;
389
- for (let index = 0; index < value.length; index++) {
390
- hash ^= value.charCodeAt(index);
391
- hash = Math.imul(hash, 16777619);
392
- }
393
- return (hash >>> 0).toString(16).padStart(8, "0");
394
- }
395
- __name(hashFarmCacheKey, "hashFarmCacheKey");
396
- function toEventAttributes(event) {
397
- const attributes = {};
398
- const redactKey = typeof event.type === "string" && event.type.startsWith("cache.");
399
- for (const [key, value] of Object.entries(event)) {
400
- if (key === "timestamp" || key === "level" || key === "error" || key === "traceId" || key === "spanId" || key === "traceSampled" || value === void 0) {
401
- continue;
402
- }
403
- if (redactKey && key === "key" && typeof value === "string") {
404
- attributes["farm.key_hash"] = hashFarmCacheKey(value);
405
- continue;
406
- }
407
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
408
- attributes[`farm.${key}`] = value;
409
- } else if (Array.isArray(value)) {
410
- if (value.every((entry) => typeof entry === "string")) {
411
- attributes[`farm.${key}`] = value;
412
- } else if (value.every((entry) => typeof entry === "number")) {
413
- attributes[`farm.${key}`] = value;
414
- } else if (value.every((entry) => typeof entry === "boolean")) {
415
- attributes[`farm.${key}`] = value;
416
- }
417
- }
418
- }
419
- return attributes;
420
- }
421
- __name(toEventAttributes, "toEventAttributes");
422
- function getEventError(event) {
423
- return "error" in event ? event.error : void 0;
424
- }
425
- __name(getEventError, "getEventError");
426
- function recordSpanException(span, error) {
427
- const normalized = error instanceof Error ? error : new Error(String(error));
428
- span.recordException(normalized);
429
- return normalized;
430
- }
431
- __name(recordSpanException, "recordSpanException");
432
- function recordSpanError(span, error) {
433
- const normalized = recordSpanException(span, error);
434
- span.setStatus({ code: import_api.SpanStatusCode.ERROR, message: normalized.message });
435
- }
436
- __name(recordSpanError, "recordSpanError");
437
- function setResponseStatus(span, status) {
438
- span.setAttribute("http.response.status_code", status);
439
- if (status >= 500) {
440
- span.setStatus({ code: import_api.SpanStatusCode.ERROR });
441
- }
442
- }
443
- __name(setResponseStatus, "setResponseStatus");
444
- function getSpanTraceContext(span) {
445
- if (!span) return void 0;
446
- const spanContext = span.spanContext();
447
- if (!(0, import_api.isSpanContextValid)(spanContext)) return void 0;
448
- return {
449
- traceId: spanContext.traceId,
450
- spanId: spanContext.spanId,
451
- traceSampled: (spanContext.traceFlags & 1) === 1
452
- };
453
- }
454
- __name(getSpanTraceContext, "getSpanTraceContext");
455
9
 
456
- // src/observability.ts
457
- var OBSERVABILITY_RUNTIME = /* @__PURE__ */ Symbol.for("@farm.js/core/observability-runtime/v1");
458
- var runtime2 = globalThis;
459
- var shared = runtime2[OBSERVABILITY_RUNTIME] ?? (runtime2[OBSERVABILITY_RUNTIME] = {
460
- handlers: /* @__PURE__ */ new Set(),
461
- unfilteredHandlers: /* @__PURE__ */ new Set(),
462
- config: { logs: false, handlers: [], tracing: normalizeFarmTracingConfig(false) }
463
- });
464
- var runtimeHandlers = shared.handlers;
465
- var unfilteredRuntimeHandlers = shared.unfilteredHandlers;
466
- var observabilityState = shared.config;
467
- function emitFarmEvent(input) {
468
- const event = {
469
- timestamp: Date.now(),
470
- level: inferFarmEventLevel(input.type),
471
- ...input
472
- };
473
- const traceContext = recordFarmEventTrace(event);
474
- if (traceContext) {
475
- event.traceId = traceContext.traceId;
476
- event.spanId = traceContext.spanId;
477
- event.traceSampled = traceContext.traceSampled;
478
- }
479
- notifyFarmEventHandlers(event, unfilteredRuntimeHandlers);
480
- if (!shouldEmitFarmEvent(event)) return event;
481
- if (observabilityState.logs) {
482
- logFarmEvent(event);
483
- }
484
- notifyFarmEventHandlers(event, [...observabilityState.handlers, ...runtimeHandlers]);
485
- return event;
486
- }
487
- __name(emitFarmEvent, "emitFarmEvent");
488
- function notifyFarmEventHandlers(event, handlers) {
489
- for (const handler of handlers) {
490
- try {
491
- Promise.resolve(handler(event)).catch((error) => {
492
- console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
493
- });
494
- } catch (error) {
495
- console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
496
- }
497
- }
498
- }
499
- __name(notifyFarmEventHandlers, "notifyFarmEventHandlers");
500
- function shouldEmitFarmEvent(event) {
501
- if (!observabilityState.logs && observabilityState.handlers.length === 0 && runtimeHandlers.size === 0) {
502
- return false;
503
- }
504
- if (observabilityState.events && !observabilityState.events.has(event.type)) {
505
- return false;
506
- }
507
- return true;
508
- }
509
- __name(shouldEmitFarmEvent, "shouldEmitFarmEvent");
510
- function inferFarmEventLevel(type) {
511
- if (type === "error" || type.endsWith(".error") || type.endsWith(".failed")) {
512
- return "error";
513
- }
514
- if (type.endsWith(".bypass") || type.endsWith(".invalidated") || type.endsWith(".stale") || type.endsWith(".notFound")) {
515
- return "warn";
516
- }
517
- if (type.endsWith(".hit") || type.endsWith(".miss") || type.endsWith(".start") || type.endsWith(".shellReady")) {
518
- return "debug";
519
- }
520
- return "info";
521
- }
522
- __name(inferFarmEventLevel, "inferFarmEventLevel");
523
- function logFarmEvent(event) {
524
- const message = `[farm:${event.level}] ${event.type}${formatFarmEventDetails(event)}`;
525
- switch (event.level) {
526
- case "error":
527
- console.error(message);
528
- break;
529
- case "warn":
530
- console.warn(message);
531
- break;
532
- default:
533
- console.log(message);
534
- break;
535
- }
536
- }
537
- __name(logFarmEvent, "logFarmEvent");
538
- function formatFarmEventDetails(event) {
539
- const details = [];
540
- const record = event;
541
- for (const key of [
542
- "route",
543
- "pathname",
544
- "method",
545
- "status",
546
- "key",
547
- "tag",
548
- "path",
549
- "reason",
550
- "durationMs",
551
- "integration",
552
- "server",
553
- "tool",
554
- "outcome",
555
- "operation",
556
- "plugin",
557
- "hook",
558
- "target",
559
- "count"
560
- ]) {
561
- const value = record[key];
562
- if (value !== void 0) {
563
- details.push(`${key}=${formatDetailValue(value)}`);
564
- }
565
- }
566
- return details.length > 0 ? ` ${details.join(" ")}` : "";
567
- }
568
- __name(formatFarmEventDetails, "formatFarmEventDetails");
569
- function formatDetailValue(value) {
570
- if (typeof value === "string") {
571
- return value;
572
- }
573
- if (typeof value === "number" || typeof value === "boolean") {
574
- return String(value);
575
- }
576
- try {
577
- return JSON.stringify(value);
578
- } catch {
579
- return String(value);
580
- }
581
- }
582
- __name(formatDetailValue, "formatDetailValue");
583
- function formatError(error) {
584
- return error instanceof Error ? error.message : String(error);
585
- }
586
- __name(formatError, "formatError");
587
10
 
588
- // src/cache-invalidation-stream.ts
589
- var MAX_BUFFERED_BYTES = 64 * 1024;
590
- var textEncoder = new TextEncoder();
11
+ var _chunkG3HRIVEYcjs = require('./chunk-G3HRIVEY.cjs');
591
12
 
592
- // src/cache.ts
593
- var _FarmDataCache = class _FarmDataCache {
594
- constructor(config = {}) {
595
- this.entries = /* @__PURE__ */ new Map();
596
- this.inflight = /* @__PURE__ */ new Map();
597
- /** Local entries by tag, so tag counts and pruning never scan unrelated entries. */
598
- this.entriesByTag = /* @__PURE__ */ new Map();
599
- this.invalidatedTagVersions = /* @__PURE__ */ new Map();
600
- this.activeGenerations = /* @__PURE__ */ new Set();
601
- this.version = 0;
602
- this.generation = 0;
603
- this.namespace = "farm";
604
- this.local = true;
605
- this.maxEntries = 1024;
606
- this.lease = {
607
- enabled: true,
608
- ttlMs: 1e4,
609
- waitTimeoutMs: 1e4,
610
- pollIntervalMs: 25
611
- };
612
- this.configure(config);
613
- }
614
- configure(config = {}) {
615
- this.generation++;
616
- this.entries.clear();
617
- this.entriesByTag.clear();
618
- this.inflight.clear();
619
- this.invalidatedTagVersions.clear();
620
- this.activeGenerations.clear();
621
- this.version = 0;
622
- this.adapter = config.adapter;
623
- this.namespace = normalizeCacheNamespace(config.namespace || "farm");
624
- this.local = !config.adapter;
625
- this.maxEntries = normalizePositiveInteger(config.maxEntries, 1024, "cache.maxEntries");
626
- this.lease = config.lease === false ? { ...this.lease, enabled: false } : {
627
- enabled: true,
628
- ttlMs: normalizePositiveDuration(config.lease?.ttlMs, 1e4, "cache.lease.ttlMs"),
629
- waitTimeoutMs: normalizePositiveDuration(
630
- config.lease?.waitTimeoutMs,
631
- 1e4,
632
- "cache.lease.waitTimeoutMs"
633
- ),
634
- pollIntervalMs: normalizePositiveDuration(
635
- config.lease?.pollIntervalMs,
636
- 25,
637
- "cache.lease.pollIntervalMs"
638
- )
639
- };
640
- }
641
- get adapterName() {
642
- return this.adapter?.name || (this.adapter ? "custom" : "memory");
643
- }
644
- get hasAdapter() {
645
- return this.adapter !== void 0;
646
- }
647
- get size() {
648
- return this.entries.size;
649
- }
650
- get(key, options = {}) {
651
- return this.getEntry(key, options)?.value;
652
- }
653
- getEntry(key, options = {}) {
654
- const entry = this.entries.get(key);
655
- if (!entry) {
656
- emitFarmEvent({ type: "cache.miss", key });
657
- return void 0;
658
- }
659
- const stale = this.isStale(entry, options.now);
660
- if (stale) {
661
- emitFarmEvent({
662
- type: "cache.stale",
663
- key,
664
- tags: Array.from(entry.tags),
665
- revalidate: entry.revalidate
666
- });
667
- }
668
- if (!options.allowStale && stale) {
669
- emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
670
- return void 0;
671
- }
672
- this.touchEntry(key, entry);
673
- emitFarmEvent({
674
- type: "cache.hit",
675
- key,
676
- tags: Array.from(entry.tags),
677
- revalidate: entry.revalidate,
678
- stale
679
- });
680
- return this.toPublicEntry(entry);
681
- }
682
- async getEntryAsync(key, options = {}) {
683
- if (this.local) {
684
- const localEntry = this.getEntry(key, options);
685
- if (localEntry) return localEntry;
686
- }
687
- if (!this.adapter) {
688
- return this.local ? void 0 : this.getEntry(key, options);
689
- }
690
- const generation = this.generation;
691
- const adapter = this.adapter;
692
- const namespace = this.namespace;
693
- const entry = await adapter.get(`${namespace}:entry:${key}`);
694
- if (generation !== this.generation) return void 0;
695
- if (!entry) {
696
- emitFarmEvent({ type: "cache.miss", key });
697
- return void 0;
698
- }
699
- assertFarmCacheEntry(entry, key);
700
- const stale = await this.isAdapterEntryStale(entry, options.now, adapter, namespace);
701
- if (generation !== this.generation) return void 0;
702
- if (stale) {
703
- emitFarmEvent({
704
- type: "cache.stale",
705
- key,
706
- tags: [...entry.tags],
707
- revalidate: entry.revalidate
708
- });
709
- if (!options.allowStale) {
710
- emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
711
- return void 0;
712
- }
713
- }
714
- emitFarmEvent({
715
- type: "cache.hit",
716
- key,
717
- tags: [...entry.tags],
718
- revalidate: entry.revalidate,
719
- stale
720
- });
721
- if (this.local && !stale) {
722
- this.hydrateLocalEntry(entry);
723
- }
724
- return { ...entry, key };
725
- }
726
- set(key, value, options = {}) {
727
- const revalidate = normalizeRevalidate(options.revalidate);
728
- const tags = /* @__PURE__ */ new Set();
729
- for (const tag of options.tags ?? []) {
730
- tags.add(normalizeCacheTag(tag));
731
- }
732
- for (const routePath of options.paths ?? []) {
733
- tags.add(createPathCacheTag(routePath));
734
- }
735
- const entry = {
736
- key,
737
- value,
738
- tags,
739
- tagVersions: void 0,
740
- createdAt: options.createdAt ?? Date.now(),
741
- createdVersion: ++this.version,
742
- revalidate
743
- };
744
- this.storeLocalEntry(entry);
745
- emitFarmEvent({
746
- type: "cache.set",
747
- key,
748
- tags: Array.from(tags),
749
- revalidate: entry.revalidate
750
- });
751
- return this.toPublicEntry(entry);
752
- }
753
- async setAsync(key, value, options = {}, tagVersions) {
754
- return this.writeAsync(key, value, options, tagVersions);
755
- }
756
- async writeAsync(key, value, options, tagVersions, createdVersion) {
757
- const revalidate = normalizeRevalidate(options.revalidate);
758
- const tags = normalizeCacheOptionsTags(options);
759
- const capturedVersions = tagVersions ?? await this.getAdapterTagVersions(Array.from(tags.values()));
760
- const entry = {
761
- key,
762
- value,
763
- tags: Array.from(tags),
764
- tagVersions: capturedVersions,
765
- createdAt: options.createdAt ?? Date.now(),
766
- createdVersion: createdVersion ?? ++this.version,
767
- revalidate
768
- };
769
- if (this.local) {
770
- this.hydrateLocalEntry(entry);
771
- }
772
- if (this.adapter) {
773
- await this.adapter.set(this.createAdapterKey(key), entry);
774
- }
775
- emitFarmEvent({
776
- type: "cache.set",
777
- key,
778
- tags: [...entry.tags],
779
- revalidate: entry.revalidate
780
- });
781
- return entry;
782
- }
783
- delete(key) {
784
- const deleted = this.deleteLocalEntry(key);
785
- emitFarmEvent({ type: "cache.delete", key, deleted });
786
- return deleted;
787
- }
788
- async deleteAsync(key) {
789
- const deleted = this.deleteLocalEntry(key);
790
- if (this.adapter) {
791
- await this.adapter.delete(this.createAdapterKey(key));
792
- }
793
- emitFarmEvent({ type: "cache.delete", key, deleted: this.adapter ? true : deleted });
794
- return this.adapter ? true : deleted;
795
- }
796
- clear() {
797
- const count = this.entries.size;
798
- this.generation++;
799
- this.entries.clear();
800
- this.entriesByTag.clear();
801
- this.inflight.clear();
802
- this.invalidatedTagVersions.clear();
803
- this.activeGenerations.clear();
804
- this.version = 0;
805
- emitFarmEvent({ type: "cache.clear", count });
806
- }
807
- async clearAsync() {
808
- this.clear();
809
- await this.adapter?.clear?.();
810
- }
811
- isStale(entry, now = Date.now()) {
812
- if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
813
- return true;
814
- }
815
- for (const tag of entry.tags) {
816
- const invalidatedVersion = this.invalidatedTagVersions.get(normalizeCacheTag(tag));
817
- if (typeof invalidatedVersion === "number" && typeof entry.createdVersion === "number" && invalidatedVersion > entry.createdVersion) {
818
- return true;
819
- }
820
- }
821
- return false;
822
- }
823
- async isStaleAsync(entry, now = Date.now()) {
824
- if (this.adapter) {
825
- return this.isAdapterEntryStale(entry, now);
826
- }
827
- return this.isStale(entry, now);
828
- }
829
- revalidateTag(tag, options = {}) {
830
- const normalized = normalizeCacheTag(tag);
831
- const count = this.invalidateTag(normalized);
832
- emitFarmEvent(
833
- options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
834
- );
835
- return count;
836
- }
837
- async revalidateTagAsync(tag, options = {}) {
838
- const normalized = normalizeCacheTag(tag);
839
- const count = this.invalidateTag(normalized);
840
- await this.adapter?.invalidateTags?.([this.createAdapterTag(normalized)]);
841
- emitFarmEvent(
842
- options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
843
- );
844
- return count;
845
- }
846
- revalidatePath(routePath) {
847
- const normalizedPath = normalizeRevalidatePath(routePath);
848
- const pathTag = createPathCacheTag(normalizedPath);
849
- const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
850
- const count = this.invalidateTag(pathTag);
851
- emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
852
- if (pprCount > 0) {
853
- emitFarmEvent({
854
- type: "ppr.shell.invalidated",
855
- route: normalizedPath,
856
- reason: "revalidatePath",
857
- count: pprCount
858
- });
859
- }
860
- return count;
861
- }
862
- async revalidatePathAsync(routePath) {
863
- const normalizedPath = normalizeRevalidatePath(routePath);
864
- const pathTag = createPathCacheTag(normalizedPath);
865
- const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
866
- const count = this.invalidateTag(pathTag);
867
- await this.adapter?.invalidateTags?.([this.createAdapterTag(pathTag)]);
868
- emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
869
- if (pprCount > 0) {
870
- emitFarmEvent({
871
- type: "ppr.shell.invalidated",
872
- route: normalizedPath,
873
- reason: "revalidatePath",
874
- count: pprCount
875
- });
876
- }
877
- return count;
878
- }
879
- async getOrSet(key, producer, options = {}) {
880
- normalizeRevalidate(options.revalidate);
881
- const cached = await this.getEntryAsync(key);
882
- if (cached) {
883
- return cached.value;
884
- }
885
- const inflight = this.inflight.get(key);
886
- if (inflight && !this.wasInvalidatedSince(inflight.tags, inflight.startVersion)) {
887
- emitFarmEvent({ type: "cache.dedupe", key });
888
- return inflight.promise;
889
- }
890
- const tags = Array.from(normalizeCacheOptionsTags(options));
891
- const generation = this.generation;
892
- const startVersion = this.version;
893
- const promise = this.fillCacheEntry(key, producer, options, tags, generation).catch((error) => {
894
- emitFarmEvent({ type: "cache.error", key, operation: "set", error });
895
- throw error;
896
- }).finally(() => {
897
- if (this.inflight.get(key)?.promise === promise) {
898
- this.inflight.delete(key);
899
- }
900
- });
901
- this.inflight.set(key, { promise, tags, startVersion });
902
- return promise;
903
- }
904
- /** A fill that started before one of its tags was invalidated cannot satisfy later readers. */
905
- wasInvalidatedSince(tags, version) {
906
- for (const tag of tags) {
907
- const invalidatedVersion = this.invalidatedTagVersions.get(tag);
908
- if (invalidatedVersion !== void 0 && invalidatedVersion > version) return true;
909
- }
910
- return false;
911
- }
912
- async fillCacheEntry(key, producer, options, tags, generation) {
913
- const adapter = this.adapter;
914
- const namespace = this.namespace;
915
- const lease = { ...this.lease };
916
- const leaseKey = `${namespace}:lease:${key}`;
917
- let leaseToken;
918
- if (adapter?.acquireLease && adapter.releaseLease && lease.enabled) {
919
- leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
920
- if (!leaseToken) {
921
- const shared2 = await this.waitForAdapterEntry(
922
- key,
923
- adapter,
924
- namespace,
925
- lease,
926
- generation
927
- );
928
- if (shared2) {
929
- emitFarmEvent({ type: "cache.dedupe", key });
930
- return shared2.value;
931
- }
932
- if (generation === this.generation) {
933
- leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
934
- }
935
- }
936
- }
937
- const initialCreatedVersion = this.version;
938
- const activeGeneration = {
939
- tags: new Set(tags),
940
- createdVersion: initialCreatedVersion
941
- };
942
- this.activeGenerations.add(activeGeneration);
943
- try {
944
- const initialTagVersions = await this.getAdapterTagVersions(tags, adapter, namespace);
945
- const value = await producer();
946
- if (generation === this.generation) {
947
- await this.writeAsync(key, value, options, initialTagVersions, initialCreatedVersion);
948
- }
949
- return value;
950
- } finally {
951
- this.activeGenerations.delete(activeGeneration);
952
- this.pruneInvalidatedTagVersions(activeGeneration.tags);
953
- if (leaseToken && adapter?.releaseLease) {
954
- try {
955
- await adapter.releaseLease(leaseKey, leaseToken);
956
- } catch (error) {
957
- emitFarmEvent({ type: "cache.error", key, operation: "set", error });
958
- }
959
- }
960
- }
961
- }
962
- async waitForAdapterEntry(key, adapter, namespace, lease, generation) {
963
- const deadline = Date.now() + lease.waitTimeoutMs;
964
- while (Date.now() < deadline) {
965
- await delay(lease.pollIntervalMs);
966
- if (generation !== this.generation) return void 0;
967
- const entry = await adapter.get(`${namespace}:entry:${key}`);
968
- if (generation !== this.generation) return void 0;
969
- if (!entry) {
970
- emitFarmEvent({ type: "cache.miss", key });
971
- continue;
972
- }
973
- assertFarmCacheEntry(entry, key);
974
- const stale = await this.isAdapterEntryStale(entry, Date.now(), adapter, namespace);
975
- if (generation !== this.generation) return void 0;
976
- if (stale) {
977
- emitFarmEvent({
978
- type: "cache.stale",
979
- key,
980
- tags: [...entry.tags],
981
- revalidate: entry.revalidate
982
- });
983
- emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
984
- } else {
985
- emitFarmEvent({
986
- type: "cache.hit",
987
- key,
988
- tags: [...entry.tags],
989
- revalidate: entry.revalidate,
990
- stale: false
991
- });
992
- return { ...entry, key };
993
- }
994
- }
995
- return void 0;
996
- }
997
- countEntriesForTags(tags) {
998
- let count = 0;
999
- for (const entry of this.entriesByTag.get(tags[0]) ?? []) {
1000
- if (tags.every((tag) => entry.tags.has(tag))) {
1001
- count++;
1002
- }
1003
- }
1004
- return count;
1005
- }
1006
- invalidateTag(normalizedTag) {
1007
- const count = this.entriesByTag.get(normalizedTag)?.size ?? 0;
1008
- this.invalidatedTagVersions.delete(normalizedTag);
1009
- this.invalidatedTagVersions.set(normalizedTag, ++this.version);
1010
- this.pruneInvalidatedTagVersions([normalizedTag]);
1011
- return count;
1012
- }
1013
- toPublicEntry(entry) {
1014
- return {
1015
- key: entry.key,
1016
- value: entry.value,
1017
- tags: Array.from(entry.tags),
1018
- tagVersions: entry.tagVersions,
1019
- createdAt: entry.createdAt,
1020
- createdVersion: entry.createdVersion,
1021
- revalidate: entry.revalidate
1022
- };
1023
- }
1024
- hydrateLocalEntry(entry) {
1025
- this.storeLocalEntry({
1026
- key: entry.key,
1027
- value: entry.value,
1028
- tags: new Set(entry.tags.map(normalizeCacheTag)),
1029
- tagVersions: entry.tagVersions,
1030
- createdAt: entry.createdAt,
1031
- createdVersion: entry.createdVersion ?? ++this.version,
1032
- revalidate: normalizeRevalidate(entry.revalidate)
1033
- });
1034
- }
1035
- touchEntry(key, entry) {
1036
- this.entries.delete(key);
1037
- this.entries.set(key, entry);
1038
- }
1039
- storeLocalEntry(entry) {
1040
- const removed = [];
1041
- const replaced = this.detachLocalEntry(entry.key);
1042
- if (replaced) removed.push(replaced);
1043
- this.entries.set(entry.key, entry);
1044
- for (const tag of entry.tags) {
1045
- let tagged = this.entriesByTag.get(tag);
1046
- if (!tagged) this.entriesByTag.set(tag, tagged = /* @__PURE__ */ new Set());
1047
- tagged.add(entry);
1048
- }
1049
- while (this.entries.size > this.maxEntries) {
1050
- const oldestKey = this.entries.keys().next().value;
1051
- if (oldestKey === void 0) break;
1052
- removed.push(this.detachLocalEntry(oldestKey));
1053
- }
1054
- for (const removedEntry of removed) this.pruneInvalidatedTagVersions(removedEntry.tags);
1055
- }
1056
- deleteLocalEntry(key) {
1057
- const entry = this.detachLocalEntry(key);
1058
- if (!entry) return false;
1059
- this.pruneInvalidatedTagVersions(entry.tags);
1060
- return true;
1061
- }
1062
- detachLocalEntry(key) {
1063
- const entry = this.entries.get(key);
1064
- if (!entry) return void 0;
1065
- this.entries.delete(key);
1066
- for (const tag of entry.tags) {
1067
- const tagged = this.entriesByTag.get(tag);
1068
- if (!tagged) continue;
1069
- tagged.delete(entry);
1070
- if (tagged.size === 0) this.entriesByTag.delete(tag);
1071
- }
1072
- return entry;
1073
- }
1074
- /**
1075
- * Drop invalidation versions that no local entry or active fill can be stale against.
1076
- * Callers pass only the tags whose dependents just changed, so the cost is bounded by
1077
- * the entries sharing those tags rather than by the whole cache.
1078
- */
1079
- pruneInvalidatedTagVersions(tags) {
1080
- tags: for (const tag of tags) {
1081
- const invalidatedVersion = this.invalidatedTagVersions.get(tag);
1082
- if (invalidatedVersion === void 0) continue;
1083
- for (const entry of this.entriesByTag.get(tag) ?? []) {
1084
- if (entry.createdVersion < invalidatedVersion) continue tags;
1085
- }
1086
- for (const generation of this.activeGenerations) {
1087
- if (generation.tags.has(tag) && generation.createdVersion < invalidatedVersion)
1088
- continue tags;
1089
- }
1090
- this.invalidatedTagVersions.delete(tag);
1091
- }
1092
- }
1093
- createAdapterKey(key) {
1094
- return `${this.namespace}:entry:${key}`;
1095
- }
1096
- createAdapterTag(tag) {
1097
- return `${this.namespace}:tag:${tag}`;
1098
- }
1099
- async getAdapterTagVersions(tags, adapter = this.adapter, namespace = this.namespace) {
1100
- if (!adapter?.getTagVersions || tags.length === 0) return {};
1101
- const normalized = tags.map(normalizeCacheTag);
1102
- const physicalTags = normalized.map((tag) => `${namespace}:tag:${tag}`);
1103
- const versions = await adapter.getTagVersions(physicalTags);
1104
- return Object.fromEntries(
1105
- normalized.map((tag, index) => [
1106
- tag,
1107
- normalizeAdapterVersion(versions[physicalTags[index]])
1108
- ])
1109
- );
1110
- }
1111
- async isAdapterEntryStale(entry, now = Date.now(), adapter = this.adapter, namespace = this.namespace) {
1112
- if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
1113
- return true;
1114
- }
1115
- const currentVersions = await this.getAdapterTagVersions(entry.tags, adapter, namespace);
1116
- for (const tag of entry.tags) {
1117
- if (normalizeAdapterVersion(currentVersions[tag]) > normalizeAdapterVersion(entry.tagVersions?.[tag])) {
1118
- return true;
1119
- }
1120
- }
1121
- return false;
1122
- }
1123
- };
1124
- __name(_FarmDataCache, "FarmDataCache");
1125
- var FarmDataCache = _FarmDataCache;
1126
- var FARM_DATA_CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.dataCache");
1127
- var farmDataCacheGlobal = globalThis;
1128
- var sharedFarmDataCache = farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] ?? (farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] = new FarmDataCache());
1129
- function getFarmDataCache() {
1130
- return sharedFarmDataCache;
1131
- }
1132
- __name(getFarmDataCache, "getFarmDataCache");
1133
- function updateTag(tag) {
1134
- const cache = getFarmDataCache();
1135
- if (cache.hasAdapter) {
1136
- const task = cache.revalidateTagAsync(tag, { source: "updateTag" }).then(() => void 0);
1137
- notifyFarmCacheTask(task);
1138
- return task;
1139
- }
1140
- cache.revalidateTag(tag, { source: "updateTag" });
1141
- }
1142
- __name(updateTag, "updateTag");
1143
- function revalidatePath(routePath) {
1144
- const cache = getFarmDataCache();
1145
- if (cache.hasAdapter) {
1146
- const task = cache.revalidatePathAsync(routePath).then(() => void 0);
1147
- notifyFarmCacheTask(task);
1148
- return task;
1149
- }
1150
- cache.revalidatePath(routePath);
1151
- }
1152
- __name(revalidatePath, "revalidatePath");
1153
- function invalidate(key) {
1154
- const clientKey = createRouteDataCacheKey(key);
1155
- const task = updateTag(createRouteDataCacheTag(key));
1156
- notifyFarmCacheInvalidation(clientKey);
1157
- return task;
1158
- }
1159
- __name(invalidate, "invalidate");
1160
- async function applyFarmCacheInvalidationTargets(targets) {
1161
- if (!Array.isArray(targets)) {
1162
- throw new TypeError("Cache invalidations must resolve to an array of targets.");
1163
- }
1164
- const clientKeys = [];
1165
- for (const target of targets) {
1166
- assertFarmCacheInvalidationTarget(target);
1167
- if ("key" in target) {
1168
- await invalidate(target.key);
1169
- clientKeys.push(createRouteDataCacheKey(target.key));
1170
- } else if ("path" in target) {
1171
- await revalidatePath(target.path);
1172
- } else {
1173
- await updateTag(target.tag);
1174
- }
1175
- }
1176
- return Array.from(new Set(clientKeys));
1177
- }
1178
- __name(applyFarmCacheInvalidationTargets, "applyFarmCacheInvalidationTargets");
1179
- function createPathCacheTag(routePath) {
1180
- return `path:${normalizeRevalidatePath(routePath)}`;
1181
- }
1182
- __name(createPathCacheTag, "createPathCacheTag");
1183
- function createRouteDataCacheTag(key) {
1184
- return `route-data:${createRouteDataCacheKey(key)}`;
1185
- }
1186
- __name(createRouteDataCacheTag, "createRouteDataCacheTag");
1187
- function createRouteDataCacheKey(key) {
1188
- return createFarmCacheKey(Array.isArray(key) ? key : [key]);
1189
- }
1190
- __name(createRouteDataCacheKey, "createRouteDataCacheKey");
1191
- function normalizeRevalidatePath(routePath) {
1192
- if (typeof routePath !== "string") {
1193
- throw new TypeError("revalidatePath expects a path string.");
1194
- }
1195
- let normalized = routePath.trim();
1196
- if (!normalized) {
1197
- throw new Error("revalidatePath expects a non-empty path.");
1198
- }
1199
- try {
1200
- if (/^https?:\/\//i.test(normalized)) {
1201
- normalized = new URL(normalized).pathname;
1202
- }
1203
- } catch {
1204
- }
1205
- normalized = normalized.split(/[?#]/, 1)[0] ?? normalized;
1206
- normalized = normalized.startsWith("/") ? normalized : `/${normalized}`;
1207
- normalized = normalized.replace(/\/{2,}/g, "/");
1208
- normalized = new URL(normalized, "http://farm.invalid").pathname;
1209
- if (normalized.length > 1) {
1210
- normalized = normalized.replace(/\/+$/, "");
1211
- }
1212
- return normalized || "/";
1213
- }
1214
- __name(normalizeRevalidatePath, "normalizeRevalidatePath");
1215
- function createFarmCacheKey(parts) {
1216
- return stableSerialize(parts);
1217
- }
1218
- __name(createFarmCacheKey, "createFarmCacheKey");
1219
- function normalizeRevalidate(revalidate) {
1220
- if (revalidate === false || revalidate === void 0) {
1221
- return revalidate;
1222
- }
1223
- if (!Number.isFinite(revalidate) || revalidate < 0) {
1224
- throw new TypeError("Cache revalidate must be false or a finite, non-negative number.");
1225
- }
1226
- return revalidate;
1227
- }
1228
- __name(normalizeRevalidate, "normalizeRevalidate");
1229
- function normalizeCacheTag(tag) {
1230
- if (typeof tag !== "string") {
1231
- throw new TypeError("Cache tags must be strings.");
1232
- }
1233
- const normalized = tag.trim();
1234
- if (!normalized) {
1235
- throw new Error("Cache tags cannot be empty.");
1236
- }
1237
- return normalized;
1238
- }
1239
- __name(normalizeCacheTag, "normalizeCacheTag");
1240
- function normalizeCacheNamespace(namespace) {
1241
- if (typeof namespace !== "string") {
1242
- throw new TypeError("Cache namespace must be a string.");
1243
- }
1244
- const normalized = namespace.trim().replace(/:+$/g, "");
1245
- if (!normalized) {
1246
- throw new Error("Cache namespace cannot be empty.");
1247
- }
1248
- return normalized;
1249
- }
1250
- __name(normalizeCacheNamespace, "normalizeCacheNamespace");
1251
- function normalizeAdapterVersion(value) {
1252
- return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
1253
- }
1254
- __name(normalizeAdapterVersion, "normalizeAdapterVersion");
1255
- function normalizePositiveDuration(value, fallback, name) {
1256
- if (value === void 0) return fallback;
1257
- if (!Number.isFinite(value) || value <= 0) {
1258
- throw new TypeError(`${name} must be a positive number of milliseconds.`);
1259
- }
1260
- return Math.floor(value);
1261
- }
1262
- __name(normalizePositiveDuration, "normalizePositiveDuration");
1263
- function normalizePositiveInteger(value, fallback, name) {
1264
- if (value === void 0) return fallback;
1265
- if (!Number.isSafeInteger(value) || value <= 0) {
1266
- throw new TypeError(`${name} must be a positive integer.`);
1267
- }
1268
- return value;
1269
- }
1270
- __name(normalizePositiveInteger, "normalizePositiveInteger");
1271
- function delay(ms) {
1272
- return new Promise((resolve) => setTimeout(resolve, ms));
1273
- }
1274
- __name(delay, "delay");
1275
- function normalizeCacheOptionsTags(options) {
1276
- const tags = /* @__PURE__ */ new Set();
1277
- for (const tag of options.tags ?? []) {
1278
- tags.add(normalizeCacheTag(tag));
1279
- }
1280
- for (const routePath of options.paths ?? []) {
1281
- tags.add(createPathCacheTag(routePath));
1282
- }
1283
- return tags;
1284
- }
1285
- __name(normalizeCacheOptionsTags, "normalizeCacheOptionsTags");
1286
- function assertFarmCacheEntry(entry, expectedKey) {
1287
- if (!entry || typeof entry !== "object" || entry.key !== expectedKey || !Array.isArray(entry.tags) || typeof entry.createdAt !== "number") {
1288
- throw new TypeError(
1289
- `Cache adapter returned an invalid entry for ${JSON.stringify(expectedKey)}.`
1290
- );
1291
- }
1292
- }
1293
- __name(assertFarmCacheEntry, "assertFarmCacheEntry");
1294
- function assertFarmCacheInvalidationTarget(target) {
1295
- if (!target || typeof target !== "object") {
1296
- throw new TypeError("Cache invalidation targets must be { key }, { path }, or { tag }.");
1297
- }
1298
- if ("key" in target) {
1299
- const key = target.key;
1300
- if (typeof key === "string" || Array.isArray(key)) return;
1301
- } else if ("path" in target && typeof target.path === "string") {
1302
- return;
1303
- } else if ("tag" in target && typeof target.tag === "string") {
1304
- return;
1305
- }
1306
- throw new TypeError("Cache invalidation targets must contain a string/array key, path, or tag.");
1307
- }
1308
- __name(assertFarmCacheInvalidationTarget, "assertFarmCacheInvalidationTarget");
1309
- function getFunctionCacheIdentity(fn) {
1310
- const name = fn.name || "anonymous";
1311
- return `${name}:${hashFunctionSource(String(fn))}`;
1312
- }
1313
- __name(getFunctionCacheIdentity, "getFunctionCacheIdentity");
1314
- function hashFunctionSource(source) {
1315
- let hash = 2166136261;
1316
- for (let index = 0; index < source.length; index++) {
1317
- hash ^= source.charCodeAt(index);
1318
- hash = Math.imul(hash, 16777619);
1319
- }
1320
- return (hash >>> 0).toString(36);
1321
- }
1322
- __name(hashFunctionSource, "hashFunctionSource");
1323
- function compareCodepoint(a, b) {
1324
- return a < b ? -1 : a > b ? 1 : 0;
1325
- }
1326
- __name(compareCodepoint, "compareCodepoint");
1327
- function serializeBinaryBytes(bytes) {
1328
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
1329
- }
1330
- __name(serializeBinaryBytes, "serializeBinaryBytes");
1331
- function serializeCanonicalStringEntries(entries, seen) {
1332
- const valuesByKey = /* @__PURE__ */ new Map();
1333
- for (const [key, item] of entries) {
1334
- const values = valuesByKey.get(key);
1335
- if (values) values.push(item);
1336
- else valuesByKey.set(key, [item]);
1337
- }
1338
- return Array.from(valuesByKey.keys()).sort(compareCodepoint).flatMap(
1339
- (key) => valuesByKey.get(key).map((item) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`)
1340
- ).join(",");
1341
- }
1342
- __name(serializeCanonicalStringEntries, "serializeCanonicalStringEntries");
1343
- function isPlainCacheKeyObject(value) {
1344
- const prototype = Object.getPrototypeOf(value);
1345
- if (prototype === null) return true;
1346
- const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
1347
- return Object.getPrototypeOf(prototype) === null && typeof constructor === "function" && constructor.name === "Object";
1348
- }
1349
- __name(isPlainCacheKeyObject, "isPlainCacheKeyObject");
1350
- function getCacheKeyValueType(value) {
1351
- const prototype = Object.getPrototypeOf(value);
1352
- const constructor = prototype ? Object.getOwnPropertyDescriptor(prototype, "constructor")?.value : void 0;
1353
- if (typeof constructor === "function" && constructor.name) {
1354
- return constructor.name;
1355
- }
1356
- return Object.prototype.toString.call(value).slice(8, -1) || "object";
1357
- }
1358
- __name(getCacheKeyValueType, "getCacheKeyValueType");
1359
- function stableSerialize(value, seen = /* @__PURE__ */ new WeakSet()) {
1360
- if (value === null) return "null";
1361
- if (value === void 0) return "undefined";
1362
- const valueType = typeof value;
1363
- if (valueType === "string") return JSON.stringify(value);
1364
- if (valueType === "number" || valueType === "boolean" || valueType === "bigint") {
1365
- return `${valueType}:${String(value)}`;
1366
- }
1367
- if (valueType === "symbol") {
1368
- return `symbol:${String(value)}`;
1369
- }
1370
- if (valueType === "function") {
1371
- return `function:${getFunctionCacheIdentity(value)}`;
1372
- }
1373
- if (value instanceof Date) {
1374
- return Number.isNaN(value.getTime()) ? "date:invalid" : `date:${value.toISOString()}`;
1375
- }
1376
- if (value instanceof URL) {
1377
- return `url:${value.toString()}`;
1378
- }
1379
- if (value instanceof RegExp) {
1380
- return `regexp:${value.toString()}`;
1381
- }
1382
- if (value instanceof ArrayBuffer) {
1383
- return `arraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
1384
- }
1385
- if (typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer) {
1386
- return `sharedarraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
1387
- }
1388
- if (ArrayBuffer.isView(value)) {
1389
- const viewType = Object.prototype.toString.call(value).slice(8, -1);
1390
- const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
1391
- return `binary:${viewType}:${serializeBinaryBytes(bytes)}`;
1392
- }
1393
- if (value && typeof value === "object") {
1394
- if (seen.has(value)) {
1395
- return "[Circular]";
1396
- }
1397
- seen.add(value);
1398
- if (Array.isArray(value)) {
1399
- const items = [];
1400
- for (let index = 0; index < value.length; index++) {
1401
- items.push(
1402
- Object.prototype.hasOwnProperty.call(value, index) ? stableSerialize(value[index], seen) : "[Hole]"
1403
- );
1404
- }
1405
- seen.delete(value);
1406
- return `[${items.join(",")}]`;
1407
- }
1408
- if (value instanceof Set) {
1409
- const items = Array.from(value, (item) => stableSerialize(item, seen)).sort(compareCodepoint);
1410
- seen.delete(value);
1411
- return `set:[${items.join(",")}]`;
1412
- }
1413
- if (value instanceof Map) {
1414
- const items = Array.from(
1415
- value,
1416
- ([key, item]) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`
1417
- ).sort(compareCodepoint);
1418
- seen.delete(value);
1419
- return `map:[${items.join(",")}]`;
1420
- }
1421
- if (value instanceof URLSearchParams) {
1422
- const serialized2 = serializeCanonicalStringEntries(value, seen);
1423
- seen.delete(value);
1424
- return `urlsearchparams:[${serialized2}]`;
1425
- }
1426
- if (value instanceof Headers) {
1427
- const serialized2 = serializeCanonicalStringEntries(value, seen);
1428
- seen.delete(value);
1429
- return `headers:[${serialized2}]`;
1430
- }
1431
- if (!isPlainCacheKeyObject(value)) {
1432
- throw new TypeError(
1433
- `Cache keys do not support ${getCacheKeyValueType(value)} values. Convert the value to an explicit stable string or structured key before caching.`
1434
- );
1435
- }
1436
- const entries = Object.entries(value).sort(
1437
- ([a], [b]) => compareCodepoint(a, b)
1438
- );
1439
- const serialized = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item, seen)}`).join(",");
1440
- seen.delete(value);
1441
- return `{${serialized}}`;
1442
- }
1443
- return String(value);
1444
- }
1445
- __name(stableSerialize, "stableSerialize");
1446
13
 
1447
- // src/navigation-errors.ts
1448
- var REDIRECT_ERROR_CODE = "FARM_REDIRECT";
1449
- var REDIRECT_ERROR_SYMBOL = /* @__PURE__ */ Symbol.for("farm.navigation.redirect");
1450
- function getFarmRedirectError(error) {
1451
- if (!error || typeof error !== "object") return null;
1452
- const candidate = error;
1453
- if (candidate[REDIRECT_ERROR_SYMBOL]) {
1454
- return candidate[REDIRECT_ERROR_SYMBOL];
1455
- }
1456
- if (typeof candidate.digest === "string" && candidate.digest.startsWith(`${REDIRECT_ERROR_CODE};`)) {
1457
- const [, status, ...urlParts] = candidate.digest.split(";");
1458
- const parsedStatus = Number(status);
1459
- if (isFarmRedirectStatus(parsedStatus)) {
1460
- return {
1461
- status: parsedStatus,
1462
- url: urlParts.join(";")
1463
- };
1464
- }
1465
- }
1466
- return null;
1467
- }
1468
- __name(getFarmRedirectError, "getFarmRedirectError");
1469
- function isFarmRedirectStatus(status) {
1470
- return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
1471
- }
1472
- __name(isFarmRedirectStatus, "isFarmRedirectStatus");
1473
14
 
1474
- // src/server-fn.ts
1475
- var FARM_SERVER_FN_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-fn");
1476
- var FARM_SERVER_FUNCTION_DESCRIPTOR = /* @__PURE__ */ Symbol.for("farm.server-function.descriptor");
1477
- var _ServerFnInputError = class _ServerFnInputError extends Error {
1478
- constructor(cause) {
1479
- super("Server function input is invalid");
1480
- this.cause = cause;
1481
- }
1482
- };
1483
- __name(_ServerFnInputError, "ServerFnInputError");
1484
- var ServerFnInputError = _ServerFnInputError;
1485
- function createServerFunctionDescriptor(kind, options, run) {
1486
- return Object.freeze({
1487
- kind,
1488
- input: options.input,
1489
- output: options.output,
1490
- mcp: options.mcp === void 0 ? void 0 : Object.freeze({ ...options.mcp }),
1491
- run
1492
- });
1493
- }
1494
- __name(createServerFunctionDescriptor, "createServerFunctionDescriptor");
1495
- function _attachServerFunctionDescriptor(target, descriptor) {
1496
- Object.defineProperty(target, FARM_SERVER_FUNCTION_DESCRIPTOR, {
1497
- value: descriptor,
1498
- enumerable: false
1499
- });
1500
- }
1501
- __name(_attachServerFunctionDescriptor, "_attachServerFunctionDescriptor");
1502
- function getServerFunctionRunner(value) {
1503
- if (typeof value !== "function") return void 0;
1504
- return value[FARM_SERVER_FUNCTION_DESCRIPTOR];
1505
- }
1506
- __name(getServerFunctionRunner, "getServerFunctionRunner");
1507
- function _runServerFunctionForCaller(value, input) {
1508
- const runner = getServerFunctionRunner(value);
1509
- if (!runner) throw new TypeError("Expected a function created with createServerFn");
1510
- return runner.run(input);
1511
- }
1512
- __name(_runServerFunctionForCaller, "_runServerFunctionForCaller");
1513
- function _describeServerFunction(value) {
1514
- const runner = getServerFunctionRunner(value);
1515
- if (!runner) return void 0;
1516
- const { kind, input, output, mcp } = runner;
1517
- return Object.freeze({ kind, input, output, mcp });
1518
- }
1519
- __name(_describeServerFunction, "_describeServerFunction");
1520
- async function _invokeServerFunction(value, input, request) {
1521
- const runner = getServerFunctionRunner(value);
1522
- if (!runner) {
1523
- throw new TypeError("Expected a function created with createServerFn or createServerQuery");
1524
- }
1525
- try {
1526
- const data = await runWithServerActionRequest(request, () => runner.run(input));
1527
- return { ok: true, data };
1528
- } catch (error) {
1529
- if (error instanceof ServerFnInputError) {
1530
- return { ok: false, reason: "input", error: error.cause };
1531
- }
1532
- if (isServerFnFailure(error)) return { ok: false, reason: "failure", failure: error };
1533
- const redirect = getFarmRedirectError(error);
1534
- if (redirect) {
1535
- return { ok: false, reason: "redirect", url: redirect.url, status: redirect.status };
1536
- }
1537
- return { ok: false, reason: "error", error };
1538
- }
1539
- }
1540
- __name(_invokeServerFunction, "_invokeServerFunction");
1541
- var UNSAFE_FORM_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
1542
- function createServerMiddleware(options) {
1543
- if (!options || typeof options.handler !== "function") {
1544
- throw new TypeError("createServerMiddleware requires a handler function");
1545
- }
1546
- const middleware = Object.freeze([...options.middleware ?? []]);
1547
- for (const entry of middleware) {
1548
- assertServerFnMiddleware(entry);
1549
- }
1550
- return Object.freeze({
1551
- __farmServerFnMiddleware: true,
1552
- middleware,
1553
- handler: options.handler
1554
- });
1555
- }
1556
- __name(createServerMiddleware, "createServerMiddleware");
1557
- function createServerFn(options) {
1558
- if (!options || typeof options.handler !== "function") {
1559
- throw new TypeError("createServerFn requires a handler function");
1560
- }
1561
- const middleware = resolveServerFnMiddleware(options.middleware);
1562
- const errors = normalizeServerFnErrors(options.errors);
1563
- const error = createServerFnErrorHandler(errors);
1564
- const run = /* @__PURE__ */ __name(async (value, labelInputErrors) => {
1565
- const formData = isFormData(value) ? value : void 0;
1566
- const rawInput = formData ? formDataToObject(formData) : value;
1567
- let input;
1568
- try {
1569
- input = await _parseServerFnSchema(options.input, rawInput, "input");
1570
- } catch (cause) {
1571
- throw labelInputErrors && isSchemaValidationFailure(cause) ? new ServerFnInputError(cause) : cause;
1572
- }
1573
- const executionContext = getServerActionExecutionContext();
1574
- const request = executionContext?.request ?? _resolveCurrentRequest();
1575
- const signal = executionContext?.signal ?? request?.signal ?? getServerActionSignal();
1576
- const handlerContext = {
1577
- input,
1578
- rawInput,
1579
- formData,
1580
- request,
1581
- signal
1582
- };
1583
- let resolvedContext = Object.freeze(/* @__PURE__ */ Object.create(null));
1584
- const result = await runServerFnMiddleware(middleware, handlerContext, async (context2) => {
1585
- resolvedContext = context2.context;
1586
- return options.handler({ ...context2, error });
1587
- });
1588
- const parsedResult = await _parseServerFnSchema(options.output, result, "output");
1589
- if (options.invalidates) {
1590
- const declaration = typeof options.invalidates === "function" ? await options.invalidates({
1591
- ...handlerContext,
1592
- context: resolvedContext,
1593
- result: parsedResult
1594
- }) : options.invalidates;
1595
- await applyFarmCacheInvalidationTargets(declaration);
1596
- }
1597
- return parsedResult;
1598
- }, "run");
1599
- const serverFn = /* @__PURE__ */ __name((value) => run(value, false), "serverFn");
1600
- Object.defineProperties(serverFn, {
1601
- [FARM_SERVER_FN_SYMBOL]: {
1602
- value: true,
1603
- enumerable: false
1604
- },
1605
- __farmServerFn: {
1606
- value: true,
1607
- enumerable: false
1608
- },
1609
- __farmServerFnInput: {
1610
- value: options.input,
1611
- enumerable: false
1612
- },
1613
- __farmServerFnOutput: {
1614
- value: options.output,
1615
- enumerable: false
1616
- },
1617
- __farmServerFnError: {
1618
- value: void 0,
1619
- enumerable: false
1620
- },
1621
- __farmServerFnMiddleware: {
1622
- value: middleware,
1623
- enumerable: false
1624
- },
1625
- __farmServerFnInvalidates: {
1626
- value: options.invalidates,
1627
- enumerable: false
1628
- }
1629
- });
1630
- _attachServerFunctionDescriptor(
1631
- serverFn,
1632
- createServerFunctionDescriptor("action", options, (value) => run(value, true))
1633
- );
1634
- return serverFn;
1635
- }
1636
- __name(createServerFn, "createServerFn");
1637
- async function runServerFnMiddleware(middleware, handlerContext, handler) {
1638
- const dispatch = /* @__PURE__ */ __name(async (index, context2) => {
1639
- const current = middleware[index];
1640
- if (!current) {
1641
- return handler({ ...handlerContext, context: context2 });
1642
- }
1643
- let nextCalled = false;
1644
- const result = await current.handler({
1645
- ...handlerContext,
1646
- context: context2,
1647
- next: /* @__PURE__ */ __name(async (nextOptions) => {
1648
- if (nextCalled) {
1649
- throw new Error("Server function middleware next() can only be called once");
1650
- }
1651
- nextCalled = true;
1652
- return dispatch(index + 1, mergeServerFnContext(context2, nextOptions?.context));
1653
- }, "next")
1654
- });
1655
- if (!nextCalled) {
1656
- throw new Error("Server function middleware must call next()");
1657
- }
1658
- return result;
1659
- }, "dispatch");
1660
- return dispatch(0, Object.freeze(/* @__PURE__ */ Object.create(null)));
1661
- }
1662
- __name(runServerFnMiddleware, "runServerFnMiddleware");
1663
- function normalizeServerFnErrors(definitions) {
1664
- if (definitions === void 0) return Object.freeze({});
1665
- if (!isPlainServerFnObject(definitions)) {
1666
- throw new TypeError("createServerFn errors must be an object");
1667
- }
1668
- const normalized = /* @__PURE__ */ Object.create(null);
1669
- for (const [code, definition] of Object.entries(definitions)) {
1670
- if (!code.trim()) {
1671
- throw new TypeError("Server function error codes cannot be empty");
1672
- }
1673
- if (!definition || typeof definition !== "object") {
1674
- throw new TypeError(`Server function error "${code}" must be an object`);
1675
- }
1676
- if (!Number.isInteger(definition.status) || definition.status < 400 || definition.status > 599) {
1677
- throw new TypeError(
1678
- `Server function error "${code}" status must be an integer between 400 and 599`
1679
- );
1680
- }
1681
- if (!definition.data || typeof definition.data.parse !== "function" && typeof definition.data.safeParse !== "function") {
1682
- throw new TypeError(
1683
- `Server function error "${code}" data must provide synchronous parse() or safeParse()`
1684
- );
1685
- }
1686
- if (definition.message !== void 0 && typeof definition.message !== "string") {
1687
- throw new TypeError(`Server function error "${code}" message must be a string`);
1688
- }
1689
- normalized[code] = Object.freeze({ ...definition });
1690
- }
1691
- return Object.freeze(normalized);
1692
- }
1693
- __name(normalizeServerFnErrors, "normalizeServerFnErrors");
1694
- function createServerFnErrorHandler(definitions) {
1695
- return ((code, data) => {
1696
- const definition = definitions[code];
1697
- if (!definition) {
1698
- throw new TypeError(`Server function error "${code}" is not declared`);
1699
- }
1700
- const parsed = parseServerFnFailureData(code, definition.data, data);
1701
- throw new ServerFnFailure(code, parsed, {
1702
- status: definition.status,
1703
- message: definition.message ?? "Server function failed"
1704
- });
1705
- });
1706
- }
1707
- __name(createServerFnErrorHandler, "createServerFnErrorHandler");
1708
- function parseServerFnFailureData(code, schema, value) {
1709
- if (typeof schema.safeParse === "function") {
1710
- const result2 = schema.safeParse(value);
1711
- if (isPromiseLike(result2)) {
1712
- throw new TypeError(`Server function error "${code}" data schema must parse synchronously`);
1713
- }
1714
- return unwrapSafeParseResult(result2);
1715
- }
1716
- const result = schema.parse(value);
1717
- if (isPromiseLike(result)) {
1718
- throw new TypeError(`Server function error "${code}" data schema must parse synchronously`);
1719
- }
1720
- return result;
1721
- }
1722
- __name(parseServerFnFailureData, "parseServerFnFailureData");
1723
- function isPlainServerFnObject(value) {
1724
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1725
- const prototype = Object.getPrototypeOf(value);
1726
- return prototype === Object.prototype || prototype === null;
1727
- }
1728
- __name(isPlainServerFnObject, "isPlainServerFnObject");
1729
- function isPromiseLike(value) {
1730
- return Boolean(
1731
- value && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function"
1732
- );
1733
- }
1734
- __name(isPromiseLike, "isPromiseLike");
1735
- function resolveServerFnMiddleware(middleware) {
1736
- const resolved = [];
1737
- const seen = /* @__PURE__ */ new Set();
1738
- const visiting = /* @__PURE__ */ new Set();
1739
- const visit = /* @__PURE__ */ __name((entry) => {
1740
- assertServerFnMiddleware(entry);
1741
- if (seen.has(entry)) return;
1742
- if (visiting.has(entry)) {
1743
- throw new Error("Server function middleware dependencies cannot contain a cycle");
1744
- }
1745
- visiting.add(entry);
1746
- for (const dependency of entry.middleware) {
1747
- visit(dependency);
1748
- }
1749
- visiting.delete(entry);
1750
- seen.add(entry);
1751
- resolved.push(entry);
1752
- }, "visit");
1753
- for (const entry of middleware ?? []) {
1754
- visit(entry);
1755
- }
1756
- return Object.freeze(resolved);
1757
- }
1758
- __name(resolveServerFnMiddleware, "resolveServerFnMiddleware");
1759
- function assertServerFnMiddleware(value) {
1760
- if (!value || typeof value !== "object" || value.__farmServerFnMiddleware !== true || typeof value.handler !== "function" || !Array.isArray(value.middleware)) {
1761
- throw new TypeError("createServerFn middleware must be created with createServerMiddleware");
1762
- }
1763
- }
1764
- __name(assertServerFnMiddleware, "assertServerFnMiddleware");
1765
- function mergeServerFnContext(current, added) {
1766
- if (added !== void 0 && (added === null || typeof added !== "object" || Array.isArray(added))) {
1767
- throw new TypeError("Server function middleware context must be an object");
1768
- }
1769
- return Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), current, added));
1770
- }
1771
- __name(mergeServerFnContext, "mergeServerFnContext");
1772
- async function _parseServerFnSchema(schema, value, contract, owner = "createServerFn") {
1773
- if (!schema) return value;
1774
- if (typeof schema.safeParseAsync === "function") {
1775
- const result = await schema.safeParseAsync(value);
1776
- return unwrapSafeParseResult(result);
1777
- }
1778
- if (typeof schema.safeParse === "function") {
1779
- const result = schema.safeParse(value);
1780
- return unwrapSafeParseResult(await result);
1781
- }
1782
- if (typeof schema.parseAsync === "function") {
1783
- return schema.parseAsync(value);
1784
- }
1785
- if (typeof schema.parse === "function") {
1786
- return schema.parse(value);
1787
- }
1788
- throw new TypeError(`${owner} ${contract} must provide parse, parseAsync, or safeParse`);
1789
- }
1790
- __name(_parseServerFnSchema, "_parseServerFnSchema");
1791
- var schemaValidationFailures = /* @__PURE__ */ new WeakSet();
1792
- function isSchemaValidationFailure(error) {
1793
- if (!error || typeof error !== "object") return false;
1794
- return schemaValidationFailures.has(error) || Array.isArray(error.issues);
1795
- }
1796
- __name(isSchemaValidationFailure, "isSchemaValidationFailure");
1797
- function unwrapSafeParseResult(result) {
1798
- if (result && typeof result === "object" && "success" in result && result.success === false) {
1799
- const error = result.error;
1800
- if (error && typeof error === "object") schemaValidationFailures.add(error);
1801
- throw error;
1802
- }
1803
- if (result && typeof result === "object" && "success" in result && result.success === true) {
1804
- return result.data;
1805
- }
1806
- return result;
1807
- }
1808
- __name(unwrapSafeParseResult, "unwrapSafeParseResult");
1809
- function formDataToObject(formData) {
1810
- const output = /* @__PURE__ */ Object.create(null);
1811
- for (const [key, value] of formData.entries()) {
1812
- if (!isSafeFormKey(key)) continue;
1813
- const existing = output[key];
1814
- if (existing === void 0) {
1815
- output[key] = value;
1816
- } else if (Array.isArray(existing)) {
1817
- existing.push(value);
1818
- } else {
1819
- output[key] = [existing, value];
1820
- }
1821
- }
1822
- return output;
1823
- }
1824
- __name(formDataToObject, "formDataToObject");
1825
- function isSafeFormKey(key) {
1826
- return !key.startsWith("$ACTION_") && !UNSAFE_FORM_KEYS.has(key);
1827
- }
1828
- __name(isSafeFormKey, "isSafeFormKey");
1829
- function isFormData(value) {
1830
- if (!value || typeof value !== "object") return false;
1831
- if (typeof FormData !== "undefined" && value instanceof FormData) {
1832
- return true;
1833
- }
1834
- return Object.prototype.toString.call(value) === "[object FormData]" && typeof value.entries === "function";
1835
- }
1836
- __name(isFormData, "isFormData");
1837
- // Annotate the CommonJS export names for ESM import in node:
1838
- 0 && (module.exports = {
1839
- FARM_SERVER_FN_FAILURE_SYMBOL,
1840
- FARM_SERVER_FN_SYMBOL,
1841
- ServerActionError,
1842
- ServerFnFailure,
1843
- _attachServerFunctionDescriptor,
1844
- _describeServerFunction,
1845
- _invokeServerFunction,
1846
- _parseServerFnSchema,
1847
- _runServerFunctionForCaller,
1848
- createServerFn,
1849
- createServerFnTransportError,
1850
- createServerFunctionDescriptor,
1851
- createServerMiddleware,
1852
- isServerFnFailure
1853
- });
15
+
16
+
17
+
18
+ var _chunkT5CERMEHcjs = require('./chunk-T5CERMEH.cjs');
19
+ require('./chunk-SVRTJOUF.cjs');
20
+ require('./chunk-EM6SBQKM.cjs');
21
+ require('./chunk-H6G5INWM.cjs');
22
+ require('./chunk-ZEG3OPIB.cjs');
23
+ require('./chunk-LIUGYUX3.cjs');
24
+ require('./chunk-E3UK5IIB.cjs');
25
+ require('./chunk-OX6O6WVA.cjs');
26
+ require('./chunk-U4KT7QP3.cjs');
27
+ require('./chunk-NO3WWW3N.cjs');
28
+ require('./chunk-S3JO3N4H.cjs');
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ exports.FARM_SERVER_FN_FAILURE_SYMBOL = _chunkT5CERMEHcjs.FARM_SERVER_FN_FAILURE_SYMBOL; exports.FARM_SERVER_FN_SYMBOL = _chunkG3HRIVEYcjs.FARM_SERVER_FN_SYMBOL; exports.ServerActionError = _chunkT5CERMEHcjs.ServerActionError; exports.ServerFnFailure = _chunkT5CERMEHcjs.ServerFnFailure; exports._attachServerFunctionDescriptor = _chunkG3HRIVEYcjs._attachServerFunctionDescriptor; exports._describeServerFunction = _chunkG3HRIVEYcjs._describeServerFunction; exports._invokeServerFunction = _chunkG3HRIVEYcjs._invokeServerFunction; exports._parseServerFnSchema = _chunkG3HRIVEYcjs._parseServerFnSchema; exports._runServerFunctionForCaller = _chunkG3HRIVEYcjs._runServerFunctionForCaller; exports.createServerFn = _chunkG3HRIVEYcjs.createServerFn; exports.createServerFnTransportError = _chunkT5CERMEHcjs.createServerFnTransportError; exports.createServerFunctionDescriptor = _chunkG3HRIVEYcjs.createServerFunctionDescriptor; exports.createServerMiddleware = _chunkG3HRIVEYcjs.createServerMiddleware; exports.isServerFnFailure = _chunkT5CERMEHcjs.isServerFnFailure;