@farm.js/core 0.1.41 → 0.1.43

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 (237) hide show
  1. package/dist/{agent-mcp-BOqIxJLI.d.mts → agent-mcp-3KDz4hr9.d.mts} +1 -1
  2. package/dist/{agent-mcp-D0eZKfci.d.ts → agent-mcp-6yRebHk7.d.ts} +1 -1
  3. package/dist/agent-runtime.d.mts +1 -1
  4. package/dist/agent-runtime.d.ts +1 -1
  5. package/dist/api/route-manager.d.mts +3 -3
  6. package/dist/api/route-manager.d.ts +3 -3
  7. package/dist/api/runtime.d.mts +2 -2
  8. package/dist/api/runtime.d.ts +2 -2
  9. package/dist/api.cjs +2 -2
  10. package/dist/api.d.mts +8 -3
  11. package/dist/api.d.ts +8 -3
  12. package/dist/api.mjs +1 -1
  13. package/dist/{app-DM8e1z3G.d.ts → app-8Db1zR-2.d.ts} +8 -4
  14. package/dist/{app-CzTSMJaf.d.mts → app-DlTWv4cn.d.mts} +8 -4
  15. package/dist/app-manifest-TRzS7ZZ9.d.mts +120 -0
  16. package/dist/app-manifest-cO2jkG1F.d.ts +120 -0
  17. package/dist/app-markdown.d.mts +2 -2
  18. package/dist/app-markdown.d.ts +2 -2
  19. package/dist/{chunk-ECKF2BAM.cjs → chunk-2GVF3C2F.cjs} +255 -42
  20. package/dist/chunk-2NXO5SBY.mjs +57 -0
  21. package/dist/chunk-3BROEWFY.cjs +39 -0
  22. package/dist/{chunk-ENOBPDKZ.mjs → chunk-4MRQ5OKQ.mjs} +14 -9
  23. package/dist/{chunk-R65GCA6A.mjs → chunk-4OCEMK72.mjs} +260 -49
  24. package/dist/{chunk-6PKXK4TY.mjs → chunk-53ZV6K65.mjs} +1 -1
  25. package/dist/{chunk-LYIZHJTK.cjs → chunk-5LPHJZSI.cjs} +14 -14
  26. package/dist/chunk-5NIWBWDD.mjs +97 -0
  27. package/dist/{chunk-NRDBW4MP.mjs → chunk-7IQQIPRZ.mjs} +10 -0
  28. package/dist/{chunk-FJGIVDA5.mjs → chunk-7SCCY6SI.mjs} +80 -177
  29. package/dist/chunk-APDGOKKE.cjs +148 -0
  30. package/dist/chunk-AZBSVLRM.cjs +132 -0
  31. package/dist/{chunk-PN676AZF.cjs → chunk-BKPXWRTT.cjs} +6 -6
  32. package/dist/chunk-CEDPEDNW.cjs +98 -0
  33. package/dist/chunk-D5RFPV2H.mjs +148 -0
  34. package/dist/{chunk-BYQVROIP.mjs → chunk-DMRPN25V.mjs} +69 -0
  35. package/dist/{chunk-724JLMS4.mjs → chunk-F646BZ4Y.mjs} +4 -2
  36. package/dist/{chunk-C5KVWHIH.cjs → chunk-G2Z5DGMS.cjs} +5 -3
  37. package/dist/{chunk-L6HYACBE.cjs → chunk-GVNCWSQV.cjs} +145 -127
  38. package/dist/{chunk-24SP5TGU.mjs → chunk-H4LXPWI2.mjs} +2 -2
  39. package/dist/chunk-H7BLEEAE.cjs +57 -0
  40. package/dist/{chunk-JOTUZIM4.cjs → chunk-HUMEHX24.cjs} +2 -2
  41. package/dist/{chunk-BD3D7EZV.cjs → chunk-IXFOBGLQ.cjs} +9 -3
  42. package/dist/{chunk-3TB5QGUW.cjs → chunk-JAXDRRRC.cjs} +70 -1
  43. package/dist/{chunk-32TZ3QTP.cjs → chunk-JDJAPCR2.cjs} +421 -210
  44. package/dist/{chunk-MHN4UR5U.cjs → chunk-KFZZFZ7J.cjs} +7 -7
  45. package/dist/chunk-LRJRXXQZ.cjs +109 -0
  46. package/dist/{chunk-EX4MKHXN.cjs → chunk-LVABUXLA.cjs} +22 -17
  47. package/dist/{chunk-HCSVR4YZ.mjs → chunk-M3BXTWJM.mjs} +18 -0
  48. package/dist/{chunk-PYHPXPSW.mjs → chunk-NXO75WY4.mjs} +1 -1
  49. package/dist/{chunk-BGGWKZ2V.mjs → chunk-OYSGGV6O.mjs} +137 -167
  50. package/dist/{chunk-JR4QCLJY.cjs → chunk-PDU4P2IC.cjs} +19 -1
  51. package/dist/chunk-PJEHUSHA.mjs +229 -0
  52. package/dist/chunk-QGH2RQVF.mjs +132 -0
  53. package/dist/{chunk-YWMZUGIS.mjs → chunk-R3ZFQJEF.mjs} +247 -34
  54. package/dist/{chunk-ROQ4C4LJ.cjs → chunk-RACQTC7K.cjs} +274 -371
  55. package/dist/{chunk-WSOBCAYO.cjs → chunk-RQYTOFQM.cjs} +23 -23
  56. package/dist/chunk-S34OBRMZ.mjs +109 -0
  57. package/dist/{chunk-TS4JHGUJ.mjs → chunk-S3ZEMCE6.mjs} +9 -3
  58. package/dist/{chunk-WWFTAUFG.cjs → chunk-SBH2JLLF.cjs} +12 -2
  59. package/dist/{chunk-YSLWRWWP.cjs → chunk-SKK6UF5P.cjs} +200 -46
  60. package/dist/chunk-T7J7E63D.cjs +144 -0
  61. package/dist/{chunk-SVPGWJZF.mjs → chunk-TESO7EFU.mjs} +125 -107
  62. package/dist/{chunk-OQ4YXWH4.cjs → chunk-VIVQERJ5.cjs} +320 -351
  63. package/dist/{chunk-JIYYX7WU.mjs → chunk-VLXNGUKO.mjs} +1 -1
  64. package/dist/{chunk-OFZUJMCU.mjs → chunk-WPJQN64R.mjs} +195 -41
  65. package/dist/chunk-XARSG2TG.mjs +144 -0
  66. package/dist/chunk-XUGFRFD2.mjs +39 -0
  67. package/dist/{chunk-EH3464KF.cjs → chunk-YBDSTNMH.cjs} +1 -1
  68. package/dist/{chunk-VLPII2JJ.mjs → chunk-YGZH4T2X.mjs} +1 -1
  69. package/dist/chunk-YKUEJ3MG.cjs +229 -0
  70. package/dist/{chunk-4C7KTKX7.mjs → chunk-ZYWJIPKQ.mjs} +1 -1
  71. package/dist/{client-plugins-CkYwvDJ0.d.mts → client-plugins-Cv0OJtnM.d.mts} +98 -7
  72. package/dist/{client-plugins-DfeKd0sD.d.ts → client-plugins-kwQuZcWq.d.ts} +98 -7
  73. package/dist/client-plugins.d.mts +1 -1
  74. package/dist/client-plugins.d.ts +1 -1
  75. package/dist/client.cjs +4 -3
  76. package/dist/client.d.mts +5 -5
  77. package/dist/client.d.ts +5 -5
  78. package/dist/client.mjs +3 -2
  79. package/dist/config.d.mts +1 -1
  80. package/dist/config.d.ts +1 -1
  81. package/dist/{devtools-N3QLRIQU.mjs → devtools-M22FEFPK.mjs} +4 -4
  82. package/dist/{devtools-2YHAJYH6.cjs → devtools-MLB3JJMC.cjs} +5 -5
  83. package/dist/docs.cjs +6 -6
  84. package/dist/docs.d.mts +2 -2
  85. package/dist/docs.d.ts +2 -2
  86. package/dist/docs.mjs +5 -5
  87. package/dist/index-CQOp8EmB.d.mts +48 -0
  88. package/dist/index-DAl0QTZS.d.ts +48 -0
  89. package/dist/index.cjs +41 -24
  90. package/dist/index.d.mts +15 -14
  91. package/dist/index.d.ts +15 -14
  92. package/dist/index.mjs +46 -29
  93. package/dist/integrations.d.mts +1 -1
  94. package/dist/integrations.d.ts +1 -1
  95. package/dist/internal/app-markdown-runtime.d.mts +2 -2
  96. package/dist/internal/app-markdown-runtime.d.ts +2 -2
  97. package/dist/internal/build-runtime.cjs +29 -15
  98. package/dist/internal/build-runtime.d.mts +12 -16
  99. package/dist/internal/build-runtime.d.ts +12 -16
  100. package/dist/internal/build-runtime.mjs +28 -14
  101. package/dist/internal/cli-runtime.cjs +23 -11
  102. package/dist/internal/cli-runtime.mjs +23 -11
  103. package/dist/internal/client-error-overlay.cjs +4 -4
  104. package/dist/internal/client-error-overlay.mjs +1 -1
  105. package/dist/internal/client-runtime.cjs +5 -1
  106. package/dist/internal/client-runtime.d.mts +1 -0
  107. package/dist/internal/client-runtime.d.ts +1 -0
  108. package/dist/internal/client-runtime.mjs +4 -0
  109. package/dist/internal/compression-runtime.d.mts +1 -1
  110. package/dist/internal/compression-runtime.d.ts +1 -1
  111. package/dist/internal/config-runtime.cjs +5 -5
  112. package/dist/internal/config-runtime.d.mts +2 -2
  113. package/dist/internal/config-runtime.d.ts +2 -2
  114. package/dist/internal/config-runtime.mjs +4 -4
  115. package/dist/internal/form-actions-client.cjs +18 -0
  116. package/dist/internal/form-actions-client.d.mts +5 -0
  117. package/dist/internal/form-actions-client.d.ts +5 -0
  118. package/dist/internal/form-actions-client.mjs +18 -0
  119. package/dist/internal/form-actions.cjs +18 -0
  120. package/dist/internal/form-actions.d.mts +14 -0
  121. package/dist/internal/form-actions.d.ts +14 -0
  122. package/dist/internal/form-actions.mjs +18 -0
  123. package/dist/internal/island-codec.cjs +22 -0
  124. package/dist/internal/island-codec.d.mts +29 -0
  125. package/dist/internal/island-codec.d.ts +29 -0
  126. package/dist/internal/island-codec.mjs +22 -0
  127. package/dist/internal/island-value-store.cjs +13 -0
  128. package/dist/internal/island-value-store.d.mts +6 -0
  129. package/dist/internal/island-value-store.d.ts +6 -0
  130. package/dist/internal/island-value-store.mjs +13 -0
  131. package/dist/internal/islands-runtime.cjs +77 -0
  132. package/dist/internal/islands-runtime.d.mts +57 -0
  133. package/dist/internal/islands-runtime.d.ts +57 -0
  134. package/dist/internal/islands-runtime.mjs +77 -0
  135. package/dist/internal/islands-server.cjs +19 -0
  136. package/dist/internal/islands-server.d.mts +3 -0
  137. package/dist/internal/islands-server.d.ts +3 -0
  138. package/dist/internal/islands-server.mjs +19 -0
  139. package/dist/internal/islx-client.cjs +5 -0
  140. package/dist/internal/islx-client.d.mts +2 -0
  141. package/dist/internal/islx-client.d.ts +2 -0
  142. package/dist/internal/islx-client.mjs +3 -0
  143. package/dist/internal/islx-react.cjs +4 -0
  144. package/dist/internal/islx-react.d.mts +1 -0
  145. package/dist/internal/islx-react.d.ts +1 -0
  146. package/dist/internal/islx-react.mjs +2 -0
  147. package/dist/internal/islx-server.cjs +5 -0
  148. package/dist/internal/islx-server.d.mts +2 -0
  149. package/dist/internal/islx-server.d.ts +2 -0
  150. package/dist/internal/islx-server.mjs +3 -0
  151. package/dist/internal/isolated-boundary.cjs +4 -3
  152. package/dist/internal/isolated-boundary.d.mts +13 -1
  153. package/dist/internal/isolated-boundary.d.ts +13 -1
  154. package/dist/internal/isolated-boundary.mjs +3 -2
  155. package/dist/internal/product-telemetry-runtime.cjs +2 -2
  156. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  157. package/dist/internal/production-runtime.cjs +24 -7
  158. package/dist/internal/production-runtime.d.mts +20 -127
  159. package/dist/internal/production-runtime.d.ts +20 -127
  160. package/dist/internal/production-runtime.mjs +24 -7
  161. package/dist/internal/server-tree.cjs +6 -3
  162. package/dist/internal/server-tree.d.mts +25 -2
  163. package/dist/internal/server-tree.d.ts +25 -2
  164. package/dist/internal/server-tree.mjs +7 -4
  165. package/dist/island-value-protocol-BRayRghM.d.mts +12 -0
  166. package/dist/island-value-protocol-BRayRghM.d.ts +12 -0
  167. package/dist/markdown.d.mts +1 -1
  168. package/dist/markdown.d.ts +1 -1
  169. package/dist/middleware.d.mts +3 -3
  170. package/dist/middleware.d.ts +3 -3
  171. package/dist/navigation.cjs +5 -4
  172. package/dist/navigation.d.mts +4 -4
  173. package/dist/navigation.d.ts +4 -4
  174. package/dist/navigation.mjs +4 -3
  175. package/dist/og.d.mts +5 -0
  176. package/dist/og.d.ts +5 -0
  177. package/dist/plugin.cjs +18 -12
  178. package/dist/plugin.d.mts +3 -3
  179. package/dist/plugin.d.ts +3 -3
  180. package/dist/plugin.mjs +17 -11
  181. package/dist/{production-runtime-DFC7pgbp.d.ts → production-runtime-5nArjFpn.d.ts} +1 -1
  182. package/dist/{production-runtime-BTkXQdYy.d.mts → production-runtime-BzsF2z5F.d.mts} +1 -1
  183. package/dist/query/client.cjs +6 -5
  184. package/dist/query/client.mjs +2 -1
  185. package/dist/{render-plan-5rFeWmk7.d.mts → render-plan-B9yQorV4.d.mts} +4 -2
  186. package/dist/{render-plan-BoAK9xFC.d.ts → render-plan-fg6E_HvL.d.ts} +4 -2
  187. package/dist/renderer/react/server.cjs +7 -6
  188. package/dist/renderer/react/server.d.mts +3 -1
  189. package/dist/renderer/react/server.d.ts +3 -1
  190. package/dist/renderer/react/server.mjs +5 -4
  191. package/dist/renderer-client.cjs +5 -4
  192. package/dist/renderer-client.d.mts +3 -3
  193. package/dist/renderer-client.d.ts +3 -3
  194. package/dist/renderer-client.mjs +2 -1
  195. package/dist/renderer.d.mts +3 -1
  196. package/dist/renderer.d.ts +3 -1
  197. package/dist/{request-BxBWigtl.d.mts → request-C4j_g-BH.d.mts} +1 -1
  198. package/dist/{request-fciwmd3n.d.ts → request-gz8vFK0n.d.ts} +1 -1
  199. package/dist/request.d.mts +2 -2
  200. package/dist/request.d.ts +2 -2
  201. package/dist/{route-rendering-BLZT0IP0.d.ts → route-rendering-DamyKVi3.d.ts} +1 -1
  202. package/dist/{route-rendering-BCM1QzEf.d.mts → route-rendering-iTTOwz1f.d.mts} +1 -1
  203. package/dist/{router-DyZJWc1_.d.mts → router-EoSzHlos.d.mts} +1 -1
  204. package/dist/{router-CkheNX3-.d.ts → router-OVjDqVo8.d.ts} +1 -1
  205. package/dist/routes.d.mts +1 -1
  206. package/dist/routes.d.ts +1 -1
  207. package/dist/rsc-pipeline-LK4K5JFK.mjs +77 -0
  208. package/dist/rsc-pipeline-YCDRJME4.cjs +77 -0
  209. package/dist/{runtime-DfU4sKa5.d.ts → runtime-CwiuozLd.d.ts} +1 -1
  210. package/dist/{runtime-wexvUN5J.d.mts → runtime-DDH4tiuF.d.mts} +1 -1
  211. package/dist/{schema-dev-notice-5JPE67AI.cjs → schema-dev-notice-77ZL23PL.cjs} +4 -4
  212. package/dist/{schema-dev-notice-WLPZ6WKU.mjs → schema-dev-notice-BLXOS6U2.mjs} +2 -2
  213. package/dist/server-plugins.d.mts +2 -2
  214. package/dist/server-plugins.d.ts +2 -2
  215. package/dist/server.cjs +56 -38
  216. package/dist/server.d.mts +15 -10
  217. package/dist/server.d.ts +15 -10
  218. package/dist/server.mjs +36 -18
  219. package/dist/{spa-router-DgsMXqfX.d.mts → spa-router-Br4qFCWf.d.mts} +8 -3
  220. package/dist/{spa-router-CcejECnG.d.ts → spa-router-BsWUKH73.d.ts} +8 -3
  221. package/dist/{ssg-1FGaFISl.d.ts → ssg-Csy2vwpi.d.ts} +2 -2
  222. package/dist/{ssg-Bg4bMMhM.d.mts → ssg-Donyfcxy.d.mts} +2 -2
  223. package/dist/testing.d.mts +1 -1
  224. package/dist/testing.d.ts +1 -1
  225. package/dist/{utils-Dxbh6Hgj.d.ts → utils-Luk72LXC.d.ts} +1 -1
  226. package/dist/{utils-8wtTYiH4.d.mts → utils-d_k1ZZw0.d.mts} +1 -1
  227. package/dist/version.cjs +2 -2
  228. package/dist/version.mjs +1 -1
  229. package/dist/vite.cjs +18 -12
  230. package/dist/vite.d.mts +6 -4
  231. package/dist/vite.d.ts +6 -4
  232. package/dist/vite.mjs +17 -11
  233. package/package.json +53 -1
  234. package/dist/{chunk-35WS7P2V.mjs → chunk-26CXZR6L.mjs} +3 -3
  235. package/dist/{chunk-QEILRWVV.cjs → chunk-3XEMGDBF.cjs} +2 -2
  236. package/dist/{chunk-BPOTSHDO.cjs → chunk-IOAUK4OI.cjs} +2 -2
  237. package/dist/{chunk-BYR3RQPB.mjs → chunk-T76H22WI.mjs} +4 -4
@@ -17,7 +17,7 @@ import {
17
17
  planSchemaMigration,
18
18
  readSchemaState,
19
19
  withoutRenameTargets
20
- } from "./chunk-BYR3RQPB.mjs";
20
+ } from "./chunk-T76H22WI.mjs";
21
21
  import {
22
22
  collectSchemaExtensions,
23
23
  describeSchemaExtensionApproval,
@@ -1,7 +1,14 @@
1
1
  import {
2
+ getFarmActionId,
2
3
  getFarmClientReference,
3
4
  subscribeFarmServerTreeUpdates
4
- } from "./chunk-NRDBW4MP.mjs";
5
+ } from "./chunk-7IQQIPRZ.mjs";
6
+ import {
7
+ FARM_REFERENCE_TAG,
8
+ FARM_TAG,
9
+ FARM_VALUE_SCRIPT_TYPE,
10
+ getFarmIslandValuesServer
11
+ } from "./chunk-2NXO5SBY.mjs";
5
12
  import {
6
13
  __name
7
14
  } from "./chunk-LPEX4YW6.mjs";
@@ -9,10 +16,12 @@ import {
9
16
  // src/client/server-tree.ts
10
17
  var MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo");
11
18
  var FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref");
12
- var SERVER_HTML_TAG = "farm-server-html";
13
- var FARM_SERVER_TREE_ATTRIBUTE = "data-farm-server-tree";
14
- var SERVER_TREE_CHUNK_ATTRIBUTE = "data-farm-server-tree-chunk";
15
- var SERVER_HTML_ATTRIBUTE = "data-farm-server-html";
19
+ var SERVER_HTML_TAG = "f-html";
20
+ var FARM_SERVER_TREE_SCRIPT_TYPE = "f/tree";
21
+ var FARM_NOT_A_MARKER = /* @__PURE__ */ Symbol.for("farm.codec.not-a-marker");
22
+ var SERVER_TREE_CHUNK_SCRIPT_TYPE = "f/chunk";
23
+ var FARM_SERVER_TREE_PAYLOAD_ONLY_ATTRIBUTE = "partial";
24
+ var SERVER_HTML_ATTRIBUTE = "name";
16
25
  var PARSER_SENSITIVE_TAGS = /* @__PURE__ */ new Set([
17
26
  "caption",
18
27
  "colgroup",
@@ -105,7 +114,7 @@ __name(serverHtmlNode, "serverHtmlNode");
105
114
  async function resolveProps(state, props, context, host) {
106
115
  const entries = await Promise.all(
107
116
  Object.entries(props).map(async ([name, value]) => {
108
- if (value === void 0) return null;
117
+ if (value === void 0 && (host || !state.codec)) return null;
109
118
  if (name === "ref") {
110
119
  if (value === null) return null;
111
120
  throw new UnsupportedNode("receives a ref");
@@ -120,11 +129,21 @@ async function resolveProps(state, props, context, host) {
120
129
  }
121
130
  __name(resolveProps, "resolveProps");
122
131
  async function resolveValue(state, value, context, seen) {
132
+ const codec = state.codec;
133
+ const leaf = codec?.encodeLeaf(value);
134
+ if (leaf) return leaf;
123
135
  if (value === null || value === void 0) return null;
124
136
  if (typeof value === "string" || typeof value === "boolean") return value;
125
137
  if (typeof value === "number") {
126
138
  return Number.isFinite(value) ? value : { $: "n", v: String(value) };
127
139
  }
140
+ if (typeof value === "function") {
141
+ const actionId = getFarmActionId(value);
142
+ if (actionId) {
143
+ state.actions.set(actionId, value);
144
+ return { $: "a", v: actionId };
145
+ }
146
+ }
128
147
  if (typeof value !== "object") throw new UnsupportedNode(`passes a ${typeof value} value`);
129
148
  if (state.ReactRuntime.isValidElement(value)) {
130
149
  return resolveElement(state, value, context);
@@ -143,12 +162,18 @@ async function resolveValue(state, value, context, seen) {
143
162
  if (Array.isArray(value)) {
144
163
  return await Promise.all(value.map((entry) => resolveValue(state, entry, context, seen)));
145
164
  }
165
+ if (codec && value instanceof Map) {
166
+ return { $: "M", v: await resolveValue(state, Array.from(value), context, seen) };
167
+ }
168
+ if (codec && value instanceof Set) {
169
+ return { $: "S", v: await resolveValue(state, Array.from(value), context, seen) };
170
+ }
146
171
  const prototype = Object.getPrototypeOf(value);
147
172
  if (prototype !== Object.prototype && prototype !== null) {
148
173
  throw new UnsupportedNode("passes a class instance");
149
174
  }
150
175
  const entries = await Promise.all(
151
- Object.entries(value).filter(([, entry]) => entry !== void 0).map(
176
+ Object.entries(value).filter(([, entry]) => entry !== void 0 || codec).map(
152
177
  async ([name, entry]) => [
153
178
  name,
154
179
  await resolveValue(state, entry, context, seen)
@@ -212,7 +237,7 @@ async function resolveElement(state, element, context) {
212
237
  encoded.catch(() => {
213
238
  });
214
239
  state.chunks.set(id, { encoded });
215
- return withKey({ $: "s", f: fallback, i: id });
240
+ return withKey({ $: "p", f: fallback, i: id });
216
241
  }
217
242
  const clientReference = getFarmClientReference(type);
218
243
  if (clientReference) {
@@ -276,9 +301,13 @@ async function resolveElement(state, element, context) {
276
301
  }
277
302
  __name(resolveElement, "resolveElement");
278
303
  function serializeTreePayload(value) {
279
- return JSON.stringify(value).replace(/&/g, "\\u0026").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
304
+ return escapeTreeJson(JSON.stringify(value));
280
305
  }
281
306
  __name(serializeTreePayload, "serializeTreePayload");
307
+ function escapeTreeJson(json) {
308
+ return json.replace(/&/g, "\\u0026").replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
309
+ }
310
+ __name(escapeTreeJson, "escapeTreeJson");
282
311
  var chunkComponents = /* @__PURE__ */ new WeakMap();
283
312
  function getChunkComponent(ReactRuntime) {
284
313
  const existing = chunkComponents.get(ReactRuntime.createElement);
@@ -351,7 +380,7 @@ function createTreeValue(ReactRuntime, value, resolver) {
351
380
  typeof value.k === "string" ? { key: value.k } : null,
352
381
  ...createTreeChildren(ReactRuntime, value.c, resolver)
353
382
  );
354
- case "s":
383
+ case "p":
355
384
  return ReactRuntime.createElement(
356
385
  ReactRuntime.Suspense,
357
386
  {
@@ -370,6 +399,8 @@ function createTreeValue(ReactRuntime, value, resolver) {
370
399
  return resolver.serverHtml(value.i, typeof value.k === "string" ? value.k : null);
371
400
  case "n":
372
401
  return Number(value.v);
402
+ case "a":
403
+ return resolver.action(value.v);
373
404
  case "P":
374
405
  return fulfilledThenable(createTreeValue(ReactRuntime, value.v, resolver));
375
406
  case "o": {
@@ -381,42 +412,134 @@ function createTreeValue(ReactRuntime, value, resolver) {
381
412
  ])
382
413
  );
383
414
  }
384
- default:
415
+ default: {
416
+ if (value.$ !== void 0) {
417
+ if (!resolver.decode) throw new Error("typed props need islands mode");
418
+ const decoded = resolver.decode(
419
+ value,
420
+ (child) => createTreeValue(ReactRuntime, child, resolver)
421
+ );
422
+ if (decoded !== FARM_NOT_A_MARKER) return decoded;
423
+ }
385
424
  return Object.fromEntries(
386
425
  Object.entries(value).map(([name, entry]) => [
387
426
  name,
388
427
  createTreeValue(ReactRuntime, entry, resolver)
389
428
  ])
390
429
  );
430
+ }
391
431
  }
392
432
  }
393
433
  __name(createTreeValue, "createTreeValue");
394
- function createTreeScript(ReactRuntime, attribute, value, json) {
395
- return ReactRuntime.createElement("script", {
396
- type: "application/json",
397
- [attribute]: value,
434
+ function createTreeScript(ReactRuntime, type, name, json, values = [], attributes = {}) {
435
+ const script = ReactRuntime.createElement("script", {
436
+ type,
437
+ ...name ? { name } : {},
438
+ ...attributes,
398
439
  dangerouslySetInnerHTML: { __html: json }
399
440
  });
441
+ if (values.length === 0) return script;
442
+ return ReactRuntime.createElement(
443
+ ReactRuntime.Fragment,
444
+ null,
445
+ ...values.map(
446
+ ([valueKey, valueJson]) => ReactRuntime.createElement("script", {
447
+ key: valueKey,
448
+ type: FARM_VALUE_SCRIPT_TYPE,
449
+ name: valueKey,
450
+ dangerouslySetInnerHTML: { __html: valueJson }
451
+ })
452
+ ),
453
+ script
454
+ );
400
455
  }
401
456
  __name(createTreeScript, "createTreeScript");
402
- function createTreePage(ReactRuntime, tree, json, resolver, key) {
457
+ function createTreePage(ReactRuntime, tree, json, resolver, key, values = []) {
403
458
  return ReactRuntime.createElement(
404
459
  ReactRuntime.Fragment,
405
460
  key === void 0 ? null : { key },
406
461
  createTreeValue(ReactRuntime, tree, resolver),
407
- createTreeScript(ReactRuntime, FARM_SERVER_TREE_ATTRIBUTE, "", json)
462
+ createTreeScript(ReactRuntime, FARM_SERVER_TREE_SCRIPT_TYPE, "", json, values)
408
463
  );
409
464
  }
410
465
  __name(createTreePage, "createTreePage");
466
+ function readTreeValueScripts(script) {
467
+ const values = [];
468
+ for (let node = script.previousElementSibling; node?.tagName === "SCRIPT" && node.getAttribute("type") === FARM_VALUE_SCRIPT_TYPE; node = node.previousElementSibling) {
469
+ values.unshift([node.getAttribute("name") ?? "", node.textContent ?? ""]);
470
+ }
471
+ return values;
472
+ }
473
+ __name(readTreeValueScripts, "readTreeValueScripts");
474
+ async function createPayloadOnlyPage(state, payload, encode, resolver) {
475
+ const { ReactRuntime } = state;
476
+ const chunks = /* @__PURE__ */ new Map();
477
+ for (let pending = [...state.chunks.keys()]; pending.length > 0; ) {
478
+ const settled = await Promise.allSettled(
479
+ pending.map(async (id) => [id, await state.chunks.get(id).encoded])
480
+ );
481
+ for (const result of settled) {
482
+ if (result.status === "rejected") return null;
483
+ chunks.set(result.value[0], result.value[1]);
484
+ }
485
+ pending = [...state.chunks.keys()].filter((id) => !chunks.has(id));
486
+ }
487
+ return ReactRuntime.createElement(
488
+ ReactRuntime.Fragment,
489
+ null,
490
+ ...Array.from(state.serverHtml.keys(), (id) => resolver.serverHtml(id, `h${id}`)),
491
+ ReactRuntime.createElement(
492
+ ReactRuntime.Fragment,
493
+ { key: "payload" },
494
+ createTreeScript(
495
+ ReactRuntime,
496
+ FARM_SERVER_TREE_SCRIPT_TYPE,
497
+ "",
498
+ payload.json,
499
+ payload.values,
500
+ {
501
+ [FARM_SERVER_TREE_PAYLOAD_ONLY_ATTRIBUTE]: ""
502
+ }
503
+ )
504
+ ),
505
+ ...Array.from(chunks, ([id, encoded]) => {
506
+ const chunk = encode({ t: encoded });
507
+ return ReactRuntime.createElement(
508
+ ReactRuntime.Fragment,
509
+ { key: `c${id}` },
510
+ createTreeScript(
511
+ ReactRuntime,
512
+ SERVER_TREE_CHUNK_SCRIPT_TYPE,
513
+ String(id),
514
+ chunk.json,
515
+ chunk.values
516
+ )
517
+ );
518
+ })
519
+ );
520
+ }
521
+ __name(createPayloadOnlyPage, "createPayloadOnlyPage");
411
522
  async function renderFarmServerTreePage(ReactRuntime, element, options) {
412
523
  const state = {
413
524
  ReactRuntime,
414
525
  nextId: 0,
415
526
  components: /* @__PURE__ */ new Map(),
416
527
  serverHtml: /* @__PURE__ */ new Map(),
417
- chunks: /* @__PURE__ */ new Map()
528
+ chunks: /* @__PURE__ */ new Map(),
529
+ actions: /* @__PURE__ */ new Map(),
530
+ codec: options.values ? getFarmIslandValuesServer() : void 0
418
531
  };
419
532
  const tree = await resolveValue(state, element, { parserSensitive: false }, /* @__PURE__ */ new Set());
533
+ const values = options.values ? getFarmIslandValuesServer() : void 0;
534
+ const held = values ? values.held() : null;
535
+ const encode = /* @__PURE__ */ __name((payload2) => {
536
+ if (!values) return { json: serializeTreePayload(payload2), values: [] };
537
+ const addressed = values.address(payload2);
538
+ return {
539
+ json: escapeTreeJson(addressed.json),
540
+ values: values.select(addressed, held).map((value) => [value.key, escapeTreeJson(value.json)])
541
+ };
542
+ }, "encode");
420
543
  const resolver = {
421
544
  component(reference, exportName) {
422
545
  const Component = state.components.get(`${reference}#${exportName}`);
@@ -435,12 +558,16 @@ async function renderFarmServerTreePage(ReactRuntime, element, options) {
435
558
  ReactRuntime.Fragment,
436
559
  null,
437
560
  createTreeValue(ReactRuntime, encoded, resolver),
438
- createTreeScript(
439
- ReactRuntime,
440
- SERVER_TREE_CHUNK_ATTRIBUTE,
441
- String(id),
442
- serializeTreePayload({ t: encoded })
443
- )
561
+ (() => {
562
+ const payload2 = encode({ t: encoded });
563
+ return createTreeScript(
564
+ ReactRuntime,
565
+ SERVER_TREE_CHUNK_SCRIPT_TYPE,
566
+ String(id),
567
+ payload2.json,
568
+ payload2.values
569
+ );
570
+ })()
444
571
  );
445
572
  chunk.status = "fulfilled";
446
573
  return chunk.value;
@@ -467,14 +594,14 @@ async function renderFarmServerTreePage(ReactRuntime, element, options) {
467
594
  },
468
595
  options.isolate(state.serverHtml.get(id))
469
596
  );
470
- }
597
+ },
598
+ action(id) {
599
+ return state.actions.get(id);
600
+ },
601
+ decode: state.codec ? (object, decodeChild) => getFarmIslandValuesServer().decode(object, decodeChild) : void 0
471
602
  };
472
- const page = createTreePage(
473
- ReactRuntime,
474
- tree,
475
- serializeTreePayload({ v: 1, t: tree }),
476
- resolver
477
- );
603
+ const payload = encode({ v: 1, t: tree });
604
+ const page = options.payloadOnly && await createPayloadOnlyPage(state, payload, encode, resolver) || createTreePage(ReactRuntime, tree, payload.json, resolver, void 0, payload.values);
478
605
  return ReactRuntime.createElement(/* @__PURE__ */ __name(function FarmServerTreePage() {
479
606
  return page;
480
607
  }, "FarmServerTreePage"));
@@ -506,19 +633,34 @@ function originalExport(module, exportName) {
506
633
  __name(originalExport, "originalExport");
507
634
  async function createFarmServerTreeElement(ReactRuntime, source, options) {
508
635
  const root = typeof source === "string" ? parseHtml(source) : source;
509
- const script = root.querySelector(`script[${FARM_SERVER_TREE_ATTRIBUTE}]`);
636
+ const script = root.querySelector(
637
+ `script[type="${FARM_SERVER_TREE_SCRIPT_TYPE}"]`
638
+ );
510
639
  if (!script) return null;
511
640
  const json = script.textContent ?? "";
512
- const payload = JSON.parse(json);
641
+ let ingested = false;
642
+ const parsePayload = /* @__PURE__ */ __name((text) => {
643
+ const parsed = JSON.parse(text);
644
+ if (!text.includes(`"${FARM_TAG}":"${FARM_REFERENCE_TAG}"`)) return parsed;
645
+ if (!options.values) throw new Error("island values need islands mode");
646
+ if (!ingested) {
647
+ options.values.ingest(root);
648
+ ingested = true;
649
+ }
650
+ return options.values.resolve(parsed);
651
+ }, "parsePayload");
652
+ const payload = parsePayload(json);
513
653
  if (payload.v !== 1) throw new Error("unsupported server tree payload version");
654
+ const values = readTreeValueScripts(script);
514
655
  const chunks = /* @__PURE__ */ new Map();
515
656
  for (const chunkScript of root.querySelectorAll(
516
- `script[${SERVER_TREE_CHUNK_ATTRIBUTE}]`
657
+ `script[type="${SERVER_TREE_CHUNK_SCRIPT_TYPE}"]`
517
658
  )) {
518
659
  const chunkJson = chunkScript.textContent ?? "";
519
- chunks.set(Number(chunkScript.getAttribute(SERVER_TREE_CHUNK_ATTRIBUTE)), {
520
- tree: JSON.parse(chunkJson).t,
521
- json: chunkJson
660
+ chunks.set(Number(chunkScript.getAttribute("name")), {
661
+ tree: parsePayload(chunkJson).t,
662
+ json: chunkJson,
663
+ values: readTreeValueScripts(chunkScript)
522
664
  });
523
665
  }
524
666
  const references = /* @__PURE__ */ new Set();
@@ -549,7 +691,13 @@ async function createFarmServerTreeElement(ReactRuntime, source, options) {
549
691
  ReactRuntime.Fragment,
550
692
  null,
551
693
  createTreeValue(ReactRuntime, chunk.tree, resolver),
552
- createTreeScript(ReactRuntime, SERVER_TREE_CHUNK_ATTRIBUTE, String(id), chunk.json)
694
+ createTreeScript(
695
+ ReactRuntime,
696
+ SERVER_TREE_CHUNK_SCRIPT_TYPE,
697
+ String(id),
698
+ chunk.json,
699
+ chunk.values
700
+ )
553
701
  );
554
702
  return { status: "fulfilled", value, promise: Promise.resolve(value) };
555
703
  },
@@ -564,9 +712,14 @@ async function createFarmServerTreeElement(ReactRuntime, source, options) {
564
712
  suppressHydrationWarning: true,
565
713
  dangerouslySetInnerHTML: { __html: html }
566
714
  });
567
- }
715
+ },
716
+ action(id) {
717
+ if (!options.actions) throw new Error("server action props need islands mode");
718
+ return options.actions(id);
719
+ },
720
+ decode: options.decode ? (object, decodeChild) => options.decode(object, decodeChild) : void 0
568
721
  };
569
- const build = /* @__PURE__ */ __name(() => createTreePage(ReactRuntime, payload.t, json, resolver), "build");
722
+ const build = /* @__PURE__ */ __name(() => createTreePage(ReactRuntime, payload.t, json, resolver, void 0, values), "build");
570
723
  build();
571
724
  function FarmServerTreePage() {
572
725
  const [, setVersion] = ReactRuntime.useState(0);
@@ -595,7 +748,8 @@ async function createFarmServerTreeElement(ReactRuntime, source, options) {
595
748
  __name(createFarmServerTreeElement, "createFarmServerTreeElement");
596
749
 
597
750
  export {
598
- FARM_SERVER_TREE_ATTRIBUTE,
751
+ FARM_SERVER_TREE_SCRIPT_TYPE,
752
+ FARM_SERVER_TREE_PAYLOAD_ONLY_ATTRIBUTE,
599
753
  renderFarmServerTreePage,
600
754
  createFarmServerTreeElement
601
755
  };
@@ -0,0 +1,144 @@
1
+ import {
2
+ FARM_RSC_INSTALL_HINT,
3
+ findFarmAppPackageDir
4
+ } from "./chunk-QGH2RQVF.mjs";
5
+ import {
6
+ resolveDeployOutputPath
7
+ } from "./chunk-4MRQ5OKQ.mjs";
8
+ import {
9
+ loadFarmReactPlugin
10
+ } from "./chunk-5NIWBWDD.mjs";
11
+ import {
12
+ loadTailwindVitePlugin
13
+ } from "./chunk-S34OBRMZ.mjs";
14
+ import {
15
+ __name
16
+ } from "./chunk-LPEX4YW6.mjs";
17
+
18
+ // src/rsc-pipeline.ts
19
+ import { readFileSync } from "fs";
20
+ import path from "path";
21
+ import { pathToFileURL } from "url";
22
+ var FARM_RSC_ENTRIES = {
23
+ rsc: "./.farm/rsc-entries/entry.rsc.tsx",
24
+ ssr: "./.farm/rsc-entries/entry.ssr.tsx",
25
+ client: "./.farm/rsc-entries/entry.browser.tsx"
26
+ };
27
+ var FARM_RSC_CONFIG_KEYS = [
28
+ "srcDir",
29
+ "extends",
30
+ "basePath",
31
+ "api",
32
+ "server",
33
+ "middleware",
34
+ "images",
35
+ "serverActions",
36
+ "deploymentId",
37
+ "generateBuildId",
38
+ "md",
39
+ "agent",
40
+ "mcp"
41
+ ];
42
+ var FARM_RSC_PASSTHROUGH_KEYS = ["i18n", "cache"];
43
+ function pickImportTarget(entry) {
44
+ if (typeof entry === "string") return entry;
45
+ if (!entry || typeof entry !== "object") return void 0;
46
+ for (const condition of ["import", "node", "default"]) {
47
+ const target = pickImportTarget(entry[condition]);
48
+ if (target) return target;
49
+ }
50
+ return void 0;
51
+ }
52
+ __name(pickImportTarget, "pickImportTarget");
53
+ async function importFromApp(root, packageName, subpath = ".") {
54
+ const packageDir = findFarmAppPackageDir(root, packageName);
55
+ if (!packageDir) return void 0;
56
+ const manifest = JSON.parse(readFileSync(path.join(packageDir, "package.json"), "utf8"));
57
+ const exportsMap = manifest.exports;
58
+ const entry = exportsMap && typeof exportsMap === "object" && !Array.isArray(exportsMap) && subpath in exportsMap ? exportsMap[subpath] : subpath === "." ? exportsMap ?? manifest.module ?? manifest.main ?? "index.js" : void 0;
59
+ const target = pickImportTarget(entry);
60
+ if (!target) return void 0;
61
+ return import(pathToFileURL(path.join(packageDir, target)).href);
62
+ }
63
+ __name(importFromApp, "importFromApp");
64
+ function hasPluginNamed(plugins, prefix) {
65
+ if (Array.isArray(plugins)) return plugins.some((plugin) => hasPluginNamed(plugin, prefix));
66
+ const name = plugins?.name;
67
+ return typeof name === "string" && name.startsWith(prefix);
68
+ }
69
+ __name(hasPluginNamed, "hasPluginNamed");
70
+ async function createFarmRscViteConfig(userConfig, options) {
71
+ const root = path.resolve(options.root);
72
+ const renderer = userConfig.renderer;
73
+ if (renderer && typeof renderer === "object" && renderer.name && renderer.name !== "react") {
74
+ throw new Error(
75
+ `[Farm.js] experimental.serverComponents needs the React renderer; this app uses "${renderer.name}".`
76
+ );
77
+ }
78
+ const [pluginRsc, viteRsc, viteReact] = await Promise.all([
79
+ importFromApp(root, "@farm.js/plugin", "./rsc"),
80
+ importFromApp(root, "@vitejs/plugin-rsc"),
81
+ importFromApp(root, "@vitejs/plugin-react")
82
+ ]);
83
+ if (!pluginRsc || !viteRsc || !findFarmAppPackageDir(root, "react-server-dom-webpack")) {
84
+ throw new Error(
85
+ `[Farm.js] experimental.serverComponents runs on @farm.js/plugin and the official @vitejs/plugin-rsc. Install them: ${FARM_RSC_INSTALL_HINT}`
86
+ );
87
+ }
88
+ const { plugins: vitePlugins = [], ...viteOptions } = userConfig.vite ?? {};
89
+ const rscConfig = {};
90
+ for (const key of FARM_RSC_CONFIG_KEYS) {
91
+ if (userConfig[key] !== void 0) rscConfig[key] = userConfig[key];
92
+ }
93
+ const createReactPlugin = hasPluginNamed(vitePlugins, "vite:react") ? void 0 : viteReact?.default ?? (options.command === "serve" ? (await loadFarmReactPlugin()).default : void 0);
94
+ const tailwind = hasPluginNamed(vitePlugins, "@tailwindcss/vite") ? void 0 : await loadTailwindVitePlugin();
95
+ const farmConfig = pluginRsc.defineConfig({
96
+ ...rscConfig,
97
+ experimental: { ...userConfig.experimental, serverComponents: true },
98
+ port: options.port ?? userConfig.server?.port,
99
+ plugins: [
100
+ ...tailwind ? [tailwind] : [],
101
+ ...vitePlugins,
102
+ viteRsc.default({ serverHandler: false, entries: FARM_RSC_ENTRIES }),
103
+ ...typeof createReactPlugin === "function" ? [createReactPlugin()] : [],
104
+ pluginRsc.nitro({
105
+ server: { environmentName: "rsc" },
106
+ config: {
107
+ preset: options.preset,
108
+ outputDir: options.outputDir && resolveDeployOutputPath(root, options.outputDir)
109
+ }
110
+ })
111
+ ]
112
+ });
113
+ for (const key of FARM_RSC_PASSTHROUGH_KEYS) {
114
+ if (userConfig[key] !== void 0) farmConfig[key] = userConfig[key];
115
+ }
116
+ const { mergeConfig } = await import("vite");
117
+ return {
118
+ ...mergeConfig(farmConfig, viteOptions),
119
+ root,
120
+ // The Farm config is the app's config; a stray vite.config must not add a second pipeline.
121
+ configFile: false,
122
+ mode: options.command === "build" ? "production" : "development"
123
+ };
124
+ }
125
+ __name(createFarmRscViteConfig, "createFarmRscViteConfig");
126
+ async function createFarmRscDevServer(userConfig, options) {
127
+ const { createServer } = await import("vite");
128
+ return createServer(await createFarmRscViteConfig(userConfig, { ...options, command: "serve" }));
129
+ }
130
+ __name(createFarmRscDevServer, "createFarmRscDevServer");
131
+ async function buildFarmRsc(userConfig, options) {
132
+ const { createBuilder } = await import("vite");
133
+ const builder = await createBuilder(
134
+ await createFarmRscViteConfig(userConfig, { ...options, command: "build" })
135
+ );
136
+ await builder.buildApp();
137
+ }
138
+ __name(buildFarmRsc, "buildFarmRsc");
139
+
140
+ export {
141
+ createFarmRscViteConfig,
142
+ createFarmRscDevServer,
143
+ buildFarmRsc
144
+ };
@@ -0,0 +1,39 @@
1
+ import {
2
+ runWithServerActionRequest
3
+ } from "./chunk-WMHG64DA.mjs";
4
+ import {
5
+ getFarmRedirectError,
6
+ isFarmNotFoundError
7
+ } from "./chunk-CBBLJMR5.mjs";
8
+ import {
9
+ __name
10
+ } from "./chunk-LPEX4YW6.mjs";
11
+
12
+ // src/form-actions.ts
13
+ import { handleAction, registerServerReference } from "@farm.js/islx/server";
14
+ var FARM_FORM_ACTION_HEADER = "F-Action";
15
+ function registerFarmFormAction(action, id) {
16
+ return registerServerReference(action, id);
17
+ }
18
+ __name(registerFarmFormAction, "registerFarmFormAction");
19
+ function handleFarmFormActionRequest(request, config) {
20
+ return handleAction(request, {
21
+ allowedOrigins: config.allowedOrigins,
22
+ bodySizeLimit: config.bodySizeLimit,
23
+ run: /* @__PURE__ */ __name((actionRequest, action) => runWithServerActionRequest(actionRequest, action), "run"),
24
+ mapError(error) {
25
+ const redirect = getFarmRedirectError(error);
26
+ if (redirect) return { redirect: redirect.url };
27
+ if (isFarmNotFoundError(error)) return { status: 404 };
28
+ return void 0;
29
+ },
30
+ onError: /* @__PURE__ */ __name((error) => console.error("[Farm.js] Server action failed:", error), "onError")
31
+ });
32
+ }
33
+ __name(handleFarmFormActionRequest, "handleFarmFormActionRequest");
34
+
35
+ export {
36
+ FARM_FORM_ACTION_HEADER,
37
+ registerFarmFormAction,
38
+ handleFarmFormActionRequest
39
+ };
@@ -1,5 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// package.json
2
- var version = "0.1.41";
2
+ var version = "0.1.43";
3
3
 
4
4
  // src/version.ts
5
5
  var FARM_VERSION = version;
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.1.41";
2
+ var version = "0.1.43";
3
3
 
4
4
  // src/version.ts
5
5
  var FARM_VERSION = version;