@farm.js/core 0.1.75 → 0.1.76

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 (213) hide show
  1. package/dist/{agent-mcp.d-Djvao5eV.d.ts → agent-mcp.d-Cftp2kFv.d.ts} +1 -1
  2. package/dist/{agent-mcp.d-wA13pwmS.d.mts → agent-mcp.d-D0FMmqi0.d.mts} +1 -1
  3. package/dist/agent-runtime.cjs +2 -2
  4. package/dist/agent-runtime.d.mts +7 -5
  5. package/dist/agent-runtime.d.ts +7 -5
  6. package/dist/agent-runtime.mjs +1 -1
  7. package/dist/analyzer-KFJGYJS7.cjs +16 -0
  8. package/dist/{analyzer-LJHMFCDW.mjs → analyzer-NLQKPN74.mjs} +2 -2
  9. package/dist/api/node.d.mts +9 -7
  10. package/dist/api/node.d.ts +9 -7
  11. package/dist/api/route-manager.d.mts +9 -7
  12. package/dist/api/route-manager.d.ts +9 -7
  13. package/dist/api/runtime.d.mts +8 -6
  14. package/dist/api/runtime.d.ts +8 -6
  15. package/dist/api.d.mts +10 -8
  16. package/dist/api.d.ts +10 -8
  17. package/dist/{app-manifest.d-BukcP_EV.d.ts → app-manifest.d-7PmA_9hm.d.ts} +1 -1
  18. package/dist/{app-manifest.d-DIuqSi9k.d.mts → app-manifest.d-cpOw_sV5.d.mts} +1 -1
  19. package/dist/app-markdown.d.mts +8 -6
  20. package/dist/app-markdown.d.ts +8 -6
  21. package/dist/{app.d-YVuFb10p.d.mts → app.d-DUZvwnFF.d.mts} +5 -4
  22. package/dist/{app.d-BQqmM6Gy.d.ts → app.d-wOkxXre8.d.ts} +5 -4
  23. package/dist/{chunk-A5F55ZFA.mjs → chunk-2GZZVIXY.mjs} +1 -1
  24. package/dist/{chunk-4BS3HSY7.cjs → chunk-2JEXQAIR.cjs} +2 -2
  25. package/dist/{chunk-OZARLCYQ.cjs → chunk-2WKGQCAV.cjs} +162 -162
  26. package/dist/{chunk-B4CWYGCG.mjs → chunk-3OYFMOBY.mjs} +1 -1
  27. package/dist/{chunk-GNY7BO7R.mjs → chunk-5EEQNZLU.mjs} +2 -2
  28. package/dist/{chunk-XGDI4OUB.cjs → chunk-6ZFGWB75.cjs} +13 -1
  29. package/dist/{chunk-6MATGOEF.mjs → chunk-A2VFKOQL.mjs} +1 -1
  30. package/dist/{chunk-YL7BKHYE.cjs → chunk-BBRSPKFI.cjs} +277 -265
  31. package/dist/{chunk-BNTRXJL4.cjs → chunk-BYJPBJ4E.cjs} +3 -3
  32. package/dist/{chunk-4ZSZI6XL.cjs → chunk-CCQZDOQR.cjs} +8 -8
  33. package/dist/{chunk-OFIFRB62.mjs → chunk-CKBBKRBO.mjs} +34 -18
  34. package/dist/{chunk-IK33N2AN.cjs → chunk-DTNWLRRF.cjs} +144 -128
  35. package/dist/{chunk-BUC3FDYC.cjs → chunk-DVW6SKHA.cjs} +2 -2
  36. package/dist/{chunk-MFU7SXAB.mjs → chunk-E77ZKNPN.mjs} +1 -1
  37. package/dist/{chunk-YCNKS6SD.mjs → chunk-GP5BWTO7.mjs} +2 -2
  38. package/dist/{chunk-HT2SZKXG.mjs → chunk-H76C5AOU.mjs} +12 -0
  39. package/dist/{chunk-ZV76IQG7.cjs → chunk-HKGU2X4I.cjs} +2 -2
  40. package/dist/{chunk-4T2RB4JA.mjs → chunk-JL6XHQZF.mjs} +3 -3
  41. package/dist/{chunk-HV2WZFUW.mjs → chunk-MOS2N377.mjs} +1 -1
  42. package/dist/{chunk-IDOUCM2X.mjs → chunk-O225GNEU.mjs} +53 -41
  43. package/dist/{chunk-NPGXX7HN.cjs → chunk-PSNYVBWC.cjs} +3 -3
  44. package/dist/{chunk-WHCNJVYU.cjs → chunk-PXXG5BID.cjs} +3 -3
  45. package/dist/{chunk-TJVUTGED.mjs → chunk-Q4X3MX4J.mjs} +201 -3
  46. package/dist/{chunk-TFEODQLG.mjs → chunk-Q7JMHO5U.mjs} +2 -2
  47. package/dist/{chunk-JNZDTE75.cjs → chunk-QP4GYVRR.cjs} +6 -6
  48. package/dist/{chunk-HVJ7IACB.cjs → chunk-QTDIOZV6.cjs} +2 -2
  49. package/dist/{chunk-YSTKSZD2.mjs → chunk-SGQXJVFX.mjs} +1 -1
  50. package/dist/{chunk-KPYQ32BA.cjs → chunk-TMVVBK5S.cjs} +2 -2
  51. package/dist/{chunk-JMYXO572.cjs → chunk-UBXNTZCY.cjs} +205 -7
  52. package/dist/{chunk-2NQ3S2SJ.mjs → chunk-VDJ3CLBR.mjs} +1 -1
  53. package/dist/{chunk-WJ5CCQBM.cjs → chunk-WILPJVQE.cjs} +4 -4
  54. package/dist/{chunk-PBQGIA27.cjs → chunk-WJDMH3E7.cjs} +4 -4
  55. package/dist/{chunk-ZPCZWEU3.cjs → chunk-WMJQNVKX.cjs} +2 -2
  56. package/dist/{chunk-H7QY7ZE4.mjs → chunk-X3HUT4JU.mjs} +1 -1
  57. package/dist/{chunk-IVBDRAOR.cjs → chunk-XLOORES5.cjs} +1 -1
  58. package/dist/{chunk-QGYHE6VJ.mjs → chunk-YHE7HH2I.mjs} +19 -19
  59. package/dist/{chunk-4MU4QCX4.mjs → chunk-YONTMPZ6.mjs} +1 -1
  60. package/dist/{chunk-GLF44JKY.mjs → chunk-YQXJY7E7.mjs} +1 -1
  61. package/dist/cli-runtime.d-D84CwyPI.d.ts +535 -0
  62. package/dist/cli-runtime.d-OQY2pgwK.d.mts +535 -0
  63. package/dist/client/lifecycle.d.mts +1 -1
  64. package/dist/client/lifecycle.d.ts +1 -1
  65. package/dist/{client-component.d-CZ1NpHAY.d.ts → client-component.d-Bf8jZqW7.d.ts} +2 -137
  66. package/dist/{client-component.d-BeqVuqy2.d.mts → client-component.d-Bh6CfC5z.d.mts} +2 -137
  67. package/dist/{client-plugins.d-D9kWC0QB.d.ts → client-plugins.d-DuujrC8d.d.ts} +4 -4
  68. package/dist/{client-plugins.d-ChceYO9t.d.mts → client-plugins.d-r3K2oQ6w.d.mts} +4 -4
  69. package/dist/client-plugins.d.mts +7 -5
  70. package/dist/client-plugins.d.ts +7 -5
  71. package/dist/client.d.mts +12 -10
  72. package/dist/client.d.ts +12 -10
  73. package/dist/config.d.mts +7 -5
  74. package/dist/config.d.ts +7 -5
  75. package/dist/desktop.d.mts +8 -6
  76. package/dist/desktop.d.ts +8 -6
  77. package/dist/{devtools-T5I2WHRX.cjs → devtools-3WZIZ7KK.cjs} +3 -3
  78. package/dist/{devtools-B3W3DLPG.mjs → devtools-MBZPUH3U.mjs} +2 -2
  79. package/dist/docs.cjs +4 -4
  80. package/dist/docs.d.mts +10 -65
  81. package/dist/docs.d.ts +10 -65
  82. package/dist/docs.mjs +3 -3
  83. package/dist/environment/vite.cjs +3 -3
  84. package/dist/environment/vite.mjs +2 -2
  85. package/dist/handler.d-Bd5lRSvb.d.ts +62 -0
  86. package/dist/handler.d-SRH-AKzf.d.mts +62 -0
  87. package/dist/{headers.d-BawakaPv.d.mts → headers.d-CHHvyaIG.d.mts} +1 -1
  88. package/dist/{headers.d-Aux4JVnm.d.ts → headers.d-D-OvGikv.d.ts} +1 -1
  89. package/dist/index.cjs +22 -20
  90. package/dist/index.d-BOPsgMlI.d.mts +16 -0
  91. package/dist/index.d-BiUtYJUG.d.ts +16 -0
  92. package/dist/index.d.mts +39 -556
  93. package/dist/index.d.ts +39 -556
  94. package/dist/index.mjs +21 -19
  95. package/dist/integrations/orm.cjs +3 -3
  96. package/dist/integrations/orm.d.mts +6 -4
  97. package/dist/integrations/orm.d.ts +6 -4
  98. package/dist/integrations/orm.mjs +2 -2
  99. package/dist/integrations.cjs +2 -2
  100. package/dist/integrations.d.mts +7 -5
  101. package/dist/integrations.d.ts +7 -5
  102. package/dist/integrations.mjs +1 -1
  103. package/dist/internal/app-markdown-runtime.d.mts +8 -6
  104. package/dist/internal/app-markdown-runtime.d.ts +8 -6
  105. package/dist/internal/build-runtime.cjs +19 -19
  106. package/dist/internal/build-runtime.d.mts +10 -7
  107. package/dist/internal/build-runtime.d.ts +10 -7
  108. package/dist/internal/build-runtime.mjs +18 -18
  109. package/dist/internal/cli-runtime.cjs +11 -6
  110. package/dist/internal/cli-runtime.d.mts +45 -0
  111. package/dist/internal/cli-runtime.d.ts +45 -0
  112. package/dist/internal/cli-runtime.mjs +10 -5
  113. package/dist/internal/client-error-overlay.cjs +4 -4
  114. package/dist/internal/client-error-overlay.mjs +1 -1
  115. package/dist/internal/client-runtime.d.mts +11 -9
  116. package/dist/internal/client-runtime.d.ts +11 -9
  117. package/dist/internal/compression-runtime.d.mts +7 -5
  118. package/dist/internal/compression-runtime.d.ts +7 -5
  119. package/dist/internal/config-runtime.cjs +4 -4
  120. package/dist/internal/config-runtime.d.mts +9 -7
  121. package/dist/internal/config-runtime.d.ts +9 -7
  122. package/dist/internal/config-runtime.mjs +3 -3
  123. package/dist/internal/infra-analytics-runtime.cjs +6 -6
  124. package/dist/internal/infra-analytics-runtime.mjs +4 -4
  125. package/dist/internal/native-server-fns.cjs +4 -4
  126. package/dist/internal/native-server-fns.mjs +3 -3
  127. package/dist/internal/product-telemetry-runtime.cjs +3 -3
  128. package/dist/internal/product-telemetry-runtime.mjs +2 -2
  129. package/dist/internal/production-runtime.cjs +7 -7
  130. package/dist/internal/production-runtime.d.mts +16 -14
  131. package/dist/internal/production-runtime.d.ts +16 -14
  132. package/dist/internal/production-runtime.mjs +6 -6
  133. package/dist/internal/start-manifest.d.mts +7 -5
  134. package/dist/internal/start-manifest.d.ts +7 -5
  135. package/dist/{lifecycle.d-OtGWAvJT.d.mts → lifecycle.d-VzcXyEyn.d.mts} +1 -1
  136. package/dist/{lifecycle.d-OtGWAvJT.d.ts → lifecycle.d-VzcXyEyn.d.ts} +1 -1
  137. package/dist/markdown.d.mts +7 -5
  138. package/dist/markdown.d.ts +7 -5
  139. package/dist/middleware.d.mts +7 -5
  140. package/dist/middleware.d.ts +7 -5
  141. package/dist/{mount.d-Ca8eb9GB.d.ts → mount.d-C2yq0Zzz.d.ts} +1 -1
  142. package/dist/{mount.d-BomEt2kV.d.mts → mount.d-vq1HTq5u.d.mts} +1 -1
  143. package/dist/{navigation-delegate.d-DJCC2jXF.d.ts → navigation-delegate.d-D7xIin3i.d.ts} +1 -1
  144. package/dist/{navigation-delegate.d-B1ujRkYo.d.mts → navigation-delegate.d-DS2Sqm7E.d.mts} +1 -1
  145. package/dist/navigation.d.mts +10 -8
  146. package/dist/navigation.d.ts +10 -8
  147. package/dist/{plugin-FD4S2QEJ.mjs → plugin-6CHZBFJD.mjs} +1 -1
  148. package/dist/{plugin-5BNPYCER.cjs → plugin-YXPIS3XX.cjs} +2 -2
  149. package/dist/plugin.cjs +12 -12
  150. package/dist/plugin.d.mts +11 -8
  151. package/dist/plugin.d.ts +11 -8
  152. package/dist/plugin.mjs +11 -11
  153. package/dist/{render-plan.d-BxRbaxYA.d.ts → render-plan.d-BCq0nfdw.d.ts} +1 -1
  154. package/dist/{render-plan.d-CFod_Zf-.d.mts → render-plan.d-X6KqerAM.d.mts} +1 -1
  155. package/dist/renderer-client.d.mts +10 -8
  156. package/dist/renderer-client.d.ts +10 -8
  157. package/dist/{request.d-DG4TeXMM.d.mts → request.d-Be9rWboC.d.mts} +1 -1
  158. package/dist/{request.d-DRQgaXGG.d.ts → request.d-CPdq2_kC.d.ts} +1 -1
  159. package/dist/request.d.mts +8 -6
  160. package/dist/request.d.ts +8 -6
  161. package/dist/{route-rendering.d-BXtZKgqu.d.mts → route-rendering.d-CIPli7Ve.d.mts} +1 -1
  162. package/dist/{route-rendering.d-Db07UNVG.d.ts → route-rendering.d-CKB5GhQr.d.ts} +1 -1
  163. package/dist/{router.d-BC3hyjf0.d.ts → router.d-CvrbOXzF.d.ts} +1 -1
  164. package/dist/{router.d-B61kXqxJ.d.mts → router.d-VxTgLGxN.d.mts} +1 -1
  165. package/dist/routes.d.mts +7 -5
  166. package/dist/routes.d.ts +7 -5
  167. package/dist/{rsc-pipeline-LJ7YCGY6.mjs → rsc-pipeline-FPE4OL57.mjs} +4 -4
  168. package/dist/{rsc-pipeline-VENBFYXW.cjs → rsc-pipeline-TPHK74VE.cjs} +5 -5
  169. package/dist/{runtime-4DWUXZHS.mjs → runtime-45BD33OJ.mjs} +3 -3
  170. package/dist/{runtime-UNDTYGQS.cjs → runtime-UBG657UC.cjs} +5 -5
  171. package/dist/{runtime.d-Cl6EBGmC.d.mts → runtime.d-Cn1jiDNI.d.mts} +1 -1
  172. package/dist/{runtime.d-SC95yDzr.d.ts → runtime.d-Ps54JWpo.d.ts} +1 -1
  173. package/dist/{schema.d-Dny9pnrm.d.mts → schema.d-BM-uVGpx.d.mts} +1 -1
  174. package/dist/{schema.d-Dny9pnrm.d.ts → schema.d-BM-uVGpx.d.ts} +1 -1
  175. package/dist/schema.d.mts +1 -1
  176. package/dist/schema.d.ts +1 -1
  177. package/dist/{index.d-r1MLpgeE.d.ts → server-components-status.d-Dhtbs5lC.d.ts} +2 -15
  178. package/dist/{index.d-Ccq42CPU.d.mts → server-components-status.d-DnmipSb3.d.mts} +2 -15
  179. package/dist/server-plugins.d.mts +9 -7
  180. package/dist/server-plugins.d.ts +9 -7
  181. package/dist/server.cjs +37 -35
  182. package/dist/server.d.mts +17 -14
  183. package/dist/server.d.ts +17 -14
  184. package/dist/server.mjs +16 -14
  185. package/dist/session-ACVUJ5XV.cjs +23 -0
  186. package/dist/{session-QZXZOPR2.mjs → session-ASQTJNBK.mjs} +2 -2
  187. package/dist/{spa-router.d-DrlXgDqY.d.mts → spa-router.d-DXm5J9rM.d.mts} +4 -4
  188. package/dist/{spa-router.d-DwM02Mwd.d.ts → spa-router.d-cppVufl2.d.ts} +4 -4
  189. package/dist/ssg.d-CI5OFl8H.d.ts +138 -0
  190. package/dist/ssg.d-Duzy1wQc.d.mts +138 -0
  191. package/dist/storage.cjs +4 -2
  192. package/dist/storage.d.mts +14 -4
  193. package/dist/storage.d.ts +14 -4
  194. package/dist/storage.mjs +3 -1
  195. package/dist/testing.d.mts +7 -5
  196. package/dist/testing.d.ts +7 -5
  197. package/dist/{types.d-BnIqOn9w.d.mts → types.d-D5cY6XjK.d.mts} +43 -2
  198. package/dist/{types.d-BnIqOn9w.d.ts → types.d-D5cY6XjK.d.ts} +43 -2
  199. package/dist/{utils.d-CHzxAshz.d.mts → utils.d-CNI-I8ZV.d.mts} +1 -1
  200. package/dist/{utils.d-C6KXz3uB.d.ts → utils.d-D3dfy8zh.d.ts} +1 -1
  201. package/dist/version.cjs +2 -2
  202. package/dist/version.mjs +1 -1
  203. package/dist/vite.cjs +12 -12
  204. package/dist/vite.d.mts +12 -9
  205. package/dist/vite.d.ts +12 -9
  206. package/dist/vite.mjs +11 -11
  207. package/package.json +10 -3
  208. package/dist/analyzer-23GCBYFI.cjs +0 -16
  209. package/dist/session-2Q72D4QV.cjs +0 -23
  210. /package/dist/{chunk-PMU4U2W2.cjs → chunk-22T75EML.cjs} +0 -0
  211. /package/dist/{chunk-5O3SK3ZC.mjs → chunk-6MNDFNZW.mjs} +0 -0
  212. /package/dist/{chunk-Z5ZZAGIH.mjs → chunk-LSHUCNIF.mjs} +0 -0
  213. /package/dist/{chunk-6DBBMQWT.cjs → chunk-OWO7KDZ3.cjs} +0 -0
@@ -8,7 +8,7 @@ var _chunkSHD265HWcjs = require('./chunk-SHD265HW.cjs');
8
8
  var _chunkGBMWLDCCcjs = require('./chunk-GBMWLDCC.cjs');
9
9
 
10
10
 
11
- var _chunkJMYXO572cjs = require('./chunk-JMYXO572.cjs');
11
+ var _chunkUBXNTZCYcjs = require('./chunk-UBXNTZCY.cjs');
12
12
 
13
13
  // src/integration-orm.ts
14
14
  async function createIntegrationOrm(options) {
@@ -31,7 +31,7 @@ async function resolveIntegrationOrmRuntimeClient(options) {
31
31
  if (options.client !== void 0) {
32
32
  return typeof options.client === "function" ? await options.client() : options.client;
33
33
  }
34
- return _chunkJMYXO572cjs.resolveStorageRuntimeClient.call(void 0, _nullishCoalesce(options.storage, () => ( _optionalChain([options, 'access', _ => _.config, 'optionalAccess', _2 => _2.storage]))));
34
+ return _chunkUBXNTZCYcjs.resolveStorageRuntimeClient.call(void 0, _nullishCoalesce(options.storage, () => ( _optionalChain([options, 'access', _ => _.config, 'optionalAccess', _2 => _2.storage]))));
35
35
  }
36
36
  async function farmIntegrationSchemaToOrmSchema(schema) {
37
37
  for (const [modelKey, modelSchema] of Object.entries(schema.models)) {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-SMUW7UST.mjs";
4
4
  import {
5
5
  getFarmIntegrationPluginServerRuntime
6
- } from "./chunk-5O3SK3ZC.mjs";
6
+ } from "./chunk-6MNDFNZW.mjs";
7
7
  import {
8
8
  formatOptionalPeerInstallHint,
9
9
  isMissingPackageError
@@ -76,7 +76,7 @@ import {
76
76
  } from "./chunk-YWPNIYUP.mjs";
77
77
  import {
78
78
  resolveIntegrationPlugins
79
- } from "./chunk-5O3SK3ZC.mjs";
79
+ } from "./chunk-6MNDFNZW.mjs";
80
80
  import {
81
81
  compileMiddlewareConfig
82
82
  } from "./chunk-EDPENAVO.mjs";
@@ -1120,7 +1120,7 @@ async function resolveConfig(userConfig, mode) {
1120
1120
  userConfig.deploymentId || process.env.FARM_DEPLOYMENT_ID || process.env.VERCEL_GIT_COMMIT_SHA || process.env.CF_PAGES_COMMIT_SHA || (mode === "production" ? await generateBuildId() : "development")
1121
1121
  );
1122
1122
  const basePath = normalizeFarmConfigBasePath(userConfig.basePath);
1123
- const mobileSessionPlugin = userConfig.mobile !== void 0 && userConfig.mobile !== null ? (await import("./session-QZXZOPR2.mjs")).createFarmMobileSessionPlugin({
1123
+ const mobileSessionPlugin = userConfig.mobile !== void 0 && userConfig.mobile !== null ? (await import("./session-ASQTJNBK.mjs")).createFarmMobileSessionPlugin({
1124
1124
  basePath,
1125
1125
  integrations: () => integrations
1126
1126
  }) : null;
@@ -212,6 +212,17 @@ function peelDocumentPrefix(markup) {
212
212
  }
213
213
  return { inner, hoisted, layoutPatterns };
214
214
  }
215
+ function takeFarmNavigationOutlet(markup, tag) {
216
+ const open = `<${tag}>`;
217
+ const close = `</${tag}>`;
218
+ const start = markup.indexOf(open);
219
+ if (start === -1) return markup;
220
+ const end = markup.indexOf(close, start + open.length);
221
+ if (end === -1 || markup.includes(open, end + close.length)) {
222
+ return markup.split(open).join("").split(close).join("");
223
+ }
224
+ return peelDocumentPrefix(markup).hoisted + markup.slice(start + open.length, end);
225
+ }
215
226
  function markFarmDocumentLayouts(markup) {
216
227
  const { inner, layoutPatterns } = peelDocumentPrefix(markup);
217
228
  if (layoutPatterns.length === 0) return markup;
@@ -978,6 +989,7 @@ export {
978
989
  parseFarmLayoutChainHeader,
979
990
  getSharedLayoutPrefixLength,
980
991
  HOISTED_HEAD_ELEMENT,
992
+ takeFarmNavigationOutlet,
981
993
  markFarmDocumentLayouts,
982
994
  extractFarmFullDocument,
983
995
  classifyFarmDocumentPrefix,
@@ -15,14 +15,14 @@ var _chunkWBTHHTBOcjs = require('./chunk-WBTHHTBO.cjs');
15
15
  var _chunkCCAUIBIScjs = require('./chunk-CCAUIBIS.cjs');
16
16
 
17
17
 
18
- var _chunkIVBDRAORcjs = require('./chunk-IVBDRAOR.cjs');
18
+ var _chunkXLOORES5cjs = require('./chunk-XLOORES5.cjs');
19
19
 
20
20
  // src/mobile/analyzer.ts
21
21
  var _crypto = require('crypto');
22
22
  var _fs = require('fs');
23
23
  var _promises = require('fs/promises');
24
24
  var _path = require('path'); var path = _interopRequireWildcard(_path);
25
- var ANALYZER_VERSION = `7:${_chunkIVBDRAORcjs.FARM_VERSION}`;
25
+ var ANALYZER_VERSION = `7:${_chunkXLOORES5cjs.FARM_VERSION}`;
26
26
  var INTRINSIC_KINDS = {};
27
27
  for (const tag of "div section main article header footer nav aside figure hr li".split(" ")) {
28
28
  INTRINSIC_KINDS[tag] = "View";
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-IG2JE6WJ.mjs";
11
11
  import {
12
12
  resolveDeployOutputPath
13
- } from "./chunk-YCNKS6SD.mjs";
13
+ } from "./chunk-GP5BWTO7.mjs";
14
14
  import {
15
15
  farmDesktopDevGuardPlugin,
16
16
  loadFarmReactPlugin
@@ -19,7 +19,7 @@ import {
19
19
  generateFarmClientPluginEntryCode,
20
20
  hasFarmServerRuntimePlugins,
21
21
  loadTailwindVitePlugin
22
- } from "./chunk-MFU7SXAB.mjs";
22
+ } from "./chunk-E77ZKNPN.mjs";
23
23
  import {
24
24
  resolveFarmPlatform
25
25
  } from "./chunk-SMUW7UST.mjs";
@@ -210,7 +210,7 @@ async function resolveFarmRscServerPlugins(userConfig, config, root) {
210
210
  }
211
211
  async function configureFarmRscPlugins(config, command) {
212
212
  if (config.plugins.length === 0) return config;
213
- const { PluginManager } = await import("./plugin-FD4S2QEJ.mjs");
213
+ const { PluginManager } = await import("./plugin-6CHZBFJD.mjs");
214
214
  const manager = new PluginManager({
215
215
  config,
216
216
  isDev: command === "serve",
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readAliases,
3
3
  resolveFile
4
- } from "./chunk-6MATGOEF.mjs";
4
+ } from "./chunk-A2VFKOQL.mjs";
5
5
  import {
6
6
  transformFarmServerFns
7
7
  } from "./chunk-GNZIAJGB.mjs";
@@ -40,15 +40,15 @@ import {
40
40
  resolveFarmImageProviderForRuntime,
41
41
  resolveFarmRouteRootStrategy,
42
42
  toBakedMarkdownSourcePath
43
- } from "./chunk-OFIFRB62.mjs";
43
+ } from "./chunk-CKBBKRBO.mjs";
44
44
  import {
45
45
  generateFarmClientPluginEntryCode,
46
46
  hasFarmServerRuntimePlugins,
47
47
  loadTailwindVitePlugin
48
- } from "./chunk-MFU7SXAB.mjs";
48
+ } from "./chunk-E77ZKNPN.mjs";
49
49
  import {
50
50
  FARM_NODE_RESPONSE_END_PENDING
51
- } from "./chunk-Z5ZZAGIH.mjs";
51
+ } from "./chunk-LSHUCNIF.mjs";
52
52
  import {
53
53
  resolveFarmPlatform
54
54
  } from "./chunk-SMUW7UST.mjs";
@@ -64,7 +64,7 @@ import {
64
64
  getSharedLayoutPrefixLength,
65
65
  parseFarmLayoutChainHeader,
66
66
  renderFarmLocaleAlternateLinks
67
- } from "./chunk-HT2SZKXG.mjs";
67
+ } from "./chunk-H76C5AOU.mjs";
68
68
  import {
69
69
  FARM_NATIVE_TREE_CONTENT_TYPE
70
70
  } from "./chunk-LLZSYFOM.mjs";
@@ -82,13 +82,13 @@ import {
82
82
  resolveFarmMCPRouteLabel,
83
83
  resolveFarmMarkdownRouteLabel,
84
84
  setFarmRouteLabel
85
- } from "./chunk-GNY7BO7R.mjs";
85
+ } from "./chunk-5EEQNZLU.mjs";
86
86
  import {
87
87
  FARM_DEFAULT_MCP_PATH
88
88
  } from "./chunk-JA6RML7C.mjs";
89
89
  import {
90
90
  isFarmPreviewDeploymentEnvironment
91
- } from "./chunk-YSTKSZD2.mjs";
91
+ } from "./chunk-SGQXJVFX.mjs";
92
92
  import {
93
93
  createFarmServerFnBoundaryModule,
94
94
  isFarmServerFnBoundaryId,
@@ -139,7 +139,7 @@ import {
139
139
  usePackageScanCacheFile,
140
140
  withFarmSourceSnapshotOf,
141
141
  wrapFarmIslandContainers
142
- } from "./chunk-A5F55ZFA.mjs";
142
+ } from "./chunk-2GZZVIXY.mjs";
143
143
  import {
144
144
  generateFarmDocsAdapterClientRuntime,
145
145
  getFarmDocsAdapterConfigModule
@@ -215,7 +215,7 @@ import {
215
215
  getIntegrationDocumentNavigationMatchers,
216
216
  getIntegrationProviders,
217
217
  matchIntegrationRoute
218
- } from "./chunk-5O3SK3ZC.mjs";
218
+ } from "./chunk-6MNDFNZW.mjs";
219
219
  import {
220
220
  resolveFarmRouteContext,
221
221
  withFarmRouteContext
@@ -301,7 +301,7 @@ import {
301
301
  } from "./chunk-2DA7CLY7.mjs";
302
302
  import {
303
303
  FARM_VERSION
304
- } from "./chunk-H7QY7ZE4.mjs";
304
+ } from "./chunk-X3HUT4JU.mjs";
305
305
  import {
306
306
  DEFAULT_FARM_API_BASE_PATH
307
307
  } from "./chunk-W6QLRQ3V.mjs";
@@ -1273,7 +1273,7 @@ function loadFarmWorkflowsDevRuntime() {
1273
1273
  return import("./workflows.mjs");
1274
1274
  }
1275
1275
  function loadFarmDevtoolsSnapshotRuntime() {
1276
- return import("./devtools-B3W3DLPG.mjs");
1276
+ return import("./devtools-MBZPUH3U.mjs");
1277
1277
  }
1278
1278
  function loadFarmDevtoolsUIRuntime() {
1279
1279
  return import("./devtools-ui-CYBVFLPH.mjs");
@@ -2324,6 +2324,7 @@ function farmPlugin(options = {}, initialPluginManager, deferredSetup) {
2324
2324
  let openAPIManager = null;
2325
2325
  let middlewareManager;
2326
2326
  let refreshRouteDiscovery = null;
2327
+ const pendingRouteReloads = /* @__PURE__ */ new Set();
2327
2328
  let workflowHandler = null;
2328
2329
  let isBuild = false;
2329
2330
  let farmOwnsDevCors = false;
@@ -2590,8 +2591,7 @@ function farmPlugin(options = {}, initialPluginManager, deferredSetup) {
2590
2591
  let typeArtifactGenScheduled = null;
2591
2592
  let pendingTypeArtifacts = createEmptyTypeArtifactSelection();
2592
2593
  let pendingTypeArtifactReason = "";
2593
- let routeRefreshScheduled = null;
2594
- let pendingRouteRefreshIncludesMiddleware = false;
2594
+ let queuedRouteFiles;
2595
2595
  const scheduleTypeArtifactGen = (file, event, selection) => {
2596
2596
  const normalizedFile = toPosixPath(file);
2597
2597
  for (const [artifact, enabled] of Object.entries(selection)) {
@@ -2634,20 +2634,29 @@ function farmPlugin(options = {}, initialPluginManager, deferredSetup) {
2634
2634
  }
2635
2635
  const isRouteRefreshEvent = (ev !== "change" || isStaticMetadataImageFile(file)) && (isAppRuntimeFile(file) || isProgrammaticRouteFile(file) || isProgrammaticRouteSourceFile(file) && (ev === "unlink" || fileContainsProgrammaticPageRoute(file)));
2636
2636
  if (isRouteRefreshEvent) {
2637
- if (file.includes("middleware.")) {
2638
- pendingRouteRefreshIncludesMiddleware = true;
2639
- }
2640
- if (!routeRefreshScheduled) {
2641
- routeRefreshScheduled = setTimeout(() => {
2642
- routeRefreshScheduled = null;
2643
- const reloadsMiddleware = pendingRouteRefreshIncludesMiddleware;
2644
- pendingRouteRefreshIncludesMiddleware = false;
2645
- Promise.all([
2646
- refreshRouteDiscovery?.(`${ev} ${file}`),
2647
- reloadsMiddleware ? middlewareManager?.reload() : void 0
2648
- ]).then(() => server.ws.send({ type: "full-reload", path: "*" })).catch((error) => logger.warn(`Route refresh failed: ${error.message}`));
2637
+ if (!queuedRouteFiles) {
2638
+ const files = /* @__PURE__ */ new Set();
2639
+ queuedRouteFiles = files;
2640
+ pendingRouteReloads.add(files);
2641
+ setTimeout(async () => {
2642
+ queuedRouteFiles = void 0;
2643
+ try {
2644
+ await Promise.all([
2645
+ refreshRouteDiscovery?.(`${ev} ${file}`),
2646
+ [...files].some((path7) => path7.includes("middleware.")) ? middlewareManager?.reload() : void 0
2647
+ ]);
2648
+ if (pendingRouteReloads.size === 1)
2649
+ server.ws.send({ type: "full-reload", path: "*" });
2650
+ } catch (error) {
2651
+ logger.warn(
2652
+ `Route refresh failed: ${error instanceof Error ? error.message : String(error)}`
2653
+ );
2654
+ } finally {
2655
+ pendingRouteReloads.delete(files);
2656
+ }
2649
2657
  }, 50);
2650
2658
  }
2659
+ queuedRouteFiles.add(normalizedFile);
2651
2660
  }
2652
2661
  });
2653
2662
  });
@@ -4274,7 +4283,12 @@ function farmPlugin(options = {}, initialPluginManager, deferredSetup) {
4274
4283
  layouts.map((layout) => routeManager3.loadLayoutModule(layout.modulePath))
4275
4284
  );
4276
4285
  const layoutHydrationMetadata = layouts.map(
4277
- (layout) => navigationManifest.layouts.find((entry) => entry.pattern === layout.pattern) ?? getClientModuleMetadata(layout.modulePath, server.config.root)
4286
+ (layout) => navigationManifest.layouts.find(
4287
+ (entry) => entry.pattern === layout.pattern
4288
+ ) ?? {
4289
+ ...getClientModuleMetadata(layout.modulePath, server.config.root),
4290
+ serverTree: false
4291
+ }
4278
4292
  );
4279
4293
  const shouldHydrateLayout = layoutHydrationMetadata.some(
4280
4294
  (metadata) => metadata.shouldHydrate
@@ -4422,7 +4436,8 @@ function farmPlugin(options = {}, initialPluginManager, deferredSetup) {
4422
4436
  params,
4423
4437
  layouts: layouts.map((layout, index) => ({
4424
4438
  pattern: layout.pattern,
4425
- module: layoutModules[index]
4439
+ module: layoutModules[index],
4440
+ serverTree: layoutHydrationMetadata[index]?.serverTree
4426
4441
  })),
4427
4442
  layoutStartIndex,
4428
4443
  slots: routeSlots.map((slot) => ({
@@ -5262,6 +5277,12 @@ if (import.meta.hot) {
5262
5277
  }
5263
5278
  const currentFarmConfig = farmApp?.getConfig();
5264
5279
  const normalizedFile = file.replace(/\\/g, "/");
5280
+ const reloadAfterEdit = () => {
5281
+ for (const files of pendingRouteReloads) {
5282
+ if (files.has(normalizedFile)) return;
5283
+ }
5284
+ server2.ws.send({ type: "full-reload", path: "*" });
5285
+ };
5265
5286
  if (normalizedFile.includes(FARM_CLIENT_REFERENCE_DIRECTORY) && normalizedFile.startsWith(
5266
5287
  path6.posix.join(
5267
5288
  toPosixPath(currentFarmConfig?.root || options.root || server2.config.root),
@@ -5274,7 +5295,7 @@ if (import.meta.hot) {
5274
5295
  )) {
5275
5296
  for (const mod of modules) server2.moduleGraph.invalidateModule(mod);
5276
5297
  await refreshRouteDiscovery?.(`updated ${file}`);
5277
- server2.ws.send({ type: "full-reload", path: "*" });
5298
+ reloadAfterEdit();
5278
5299
  return [];
5279
5300
  }
5280
5301
  const currentSrcRoot = currentFarmConfig ? getFarmSourceRoots(currentFarmConfig).map((source) => path6.join(source.root, source.srcDir).replace(/\\/g, "/")).find((sourceRoot) => normalizedFile.startsWith(`${sourceRoot}/`)) || null : null;
@@ -5284,10 +5305,7 @@ if (import.meta.hot) {
5284
5305
  server2.moduleGraph.invalidateModule(mod);
5285
5306
  }
5286
5307
  await refreshRouteDiscovery?.(`updated ${file}`);
5287
- server2.ws.send({
5288
- type: "full-reload",
5289
- path: "*"
5290
- });
5308
+ reloadAfterEdit();
5291
5309
  return [];
5292
5310
  }
5293
5311
  if (currentSrcRoot && isPotentialProgrammaticRouteSourceFile(normalizedFile, currentSrcRoot) && fileContainsProgrammaticPageRoute(file)) {
@@ -5297,10 +5315,7 @@ if (import.meta.hot) {
5297
5315
  server2.moduleGraph.invalidateModule(mod);
5298
5316
  }
5299
5317
  await refreshRouteDiscovery?.(`updated ${file}`);
5300
- server2.ws.send({
5301
- type: "full-reload",
5302
- path: "*"
5303
- });
5318
+ reloadAfterEdit();
5304
5319
  return [];
5305
5320
  }
5306
5321
  if (apiRouteManager && invalidateFarmDevDependents(server2, file, apiRouteManager.getSourceFiles()).length > 0) {
@@ -5345,7 +5360,7 @@ if (import.meta.hot) {
5345
5360
  const clientModule = server2.moduleGraph.getModuleById(clientId);
5346
5361
  if (clientModule) server2.moduleGraph.invalidateModule(clientModule);
5347
5362
  }
5348
- server2.ws.send({ type: "full-reload", path: "*" });
5363
+ reloadAfterEdit();
5349
5364
  return [];
5350
5365
  }
5351
5366
  clientPlanCurrent = true;
@@ -5385,16 +5400,13 @@ if (import.meta.hot) {
5385
5400
  for (const mod of modules) {
5386
5401
  server2.moduleGraph.invalidateModule(mod);
5387
5402
  }
5388
- server2.ws.send({
5389
- type: "full-reload",
5390
- path: "*"
5391
- });
5403
+ reloadAfterEdit();
5392
5404
  return [];
5393
5405
  }
5394
5406
  }
5395
5407
  if (/\.[cm]?[jt]sx?$/.test(normalizedFile) && !server2.environments.client?.moduleGraph.getModulesByFile(normalizedFile)?.size && invalidateFarmDevDependents(server2, file, getFarmRenderedServerModules()).length > 0) {
5396
5408
  logUpdate("PAGE", `updated ${path6.basename(file)}`);
5397
- server2.ws.send({ type: "full-reload", path: "*" });
5409
+ reloadAfterEdit();
5398
5410
  return [];
5399
5411
  }
5400
5412
  return modules;
@@ -76,7 +76,7 @@ var _chunkQUEYL2WMcjs = require('./chunk-QUEYL2WM.cjs');
76
76
  var _chunkWT6RAN2Icjs = require('./chunk-WT6RAN2I.cjs');
77
77
 
78
78
 
79
- var _chunk6DBBMQWTcjs = require('./chunk-6DBBMQWT.cjs');
79
+ var _chunkOWO7KDZ3cjs = require('./chunk-OWO7KDZ3.cjs');
80
80
 
81
81
 
82
82
  var _chunk5DX3O6TTcjs = require('./chunk-5DX3O6TT.cjs');
@@ -1123,7 +1123,7 @@ async function resolveConfig(userConfig, mode) {
1123
1123
  userConfig.deploymentId || process.env.FARM_DEPLOYMENT_ID || process.env.VERCEL_GIT_COMMIT_SHA || process.env.CF_PAGES_COMMIT_SHA || (mode === "production" ? await generateBuildId() : "development")
1124
1124
  );
1125
1125
  const basePath = _chunkD22BUQKWcjs.normalizeFarmConfigBasePath.call(void 0, userConfig.basePath);
1126
- const mobileSessionPlugin = userConfig.mobile !== void 0 && userConfig.mobile !== null ? (await import("./session-2Q72D4QV.cjs")).createFarmMobileSessionPlugin({
1126
+ const mobileSessionPlugin = userConfig.mobile !== void 0 && userConfig.mobile !== null ? (await import("./session-ACVUJ5XV.cjs")).createFarmMobileSessionPlugin({
1127
1127
  basePath,
1128
1128
  integrations: () => integrations
1129
1129
  }) : null;
@@ -1190,7 +1190,7 @@ async function resolveConfig(userConfig, mode) {
1190
1190
  plugins: [
1191
1191
  ...mobileSessionPlugin ? [mobileSessionPlugin] : [],
1192
1192
  ...nativeServerFnPlugin ? [nativeServerFnPlugin] : [],
1193
- ..._chunk6DBBMQWTcjs.resolveIntegrationPlugins.call(void 0, integrations),
1193
+ ..._chunkOWO7KDZ3cjs.resolveIntegrationPlugins.call(void 0, integrations),
1194
1194
  ...nativeMCPPlugin ? [nativeMCPPlugin] : [],
1195
1195
  ...userConfig.plugins || []
1196
1196
  ],
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkWJ5CCQBMcjs = require('./chunk-WJ5CCQBM.cjs');
3
+ var _chunkWILPJVQEcjs = require('./chunk-WILPJVQE.cjs');
4
4
 
5
5
 
6
6
 
@@ -329,7 +329,7 @@ function requestEvent(metadata, method, status, durationMs) {
329
329
  id: uuid(),
330
330
  requestId: metadata.id,
331
331
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
332
- route: routeTemplate(_chunkWJ5CCQBMcjs.getFarmRouteLabel.call(void 0, metadata.route)),
332
+ route: routeTemplate(_chunkWILPJVQEcjs.getFarmRouteLabel.call(void 0, metadata.route)),
333
333
  ...metadata.path ? { path: metadata.path } : {},
334
334
  agent: metadata.agent,
335
335
  kind: "request",
@@ -343,7 +343,7 @@ function toolEvent(metadata, event) {
343
343
  id: uuid(),
344
344
  requestId: metadata.id,
345
345
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
346
- route: routeTemplate(_chunkWJ5CCQBMcjs.getFarmRouteLabel.call(void 0, metadata.route)),
346
+ route: routeTemplate(_chunkWILPJVQEcjs.getFarmRouteLabel.call(void 0, metadata.route)),
347
347
  ...metadata.path ? { path: metadata.path } : {},
348
348
  agent: metadata.agent,
349
349
  kind: "mcp.tool",
@@ -1,3 +1,172 @@
1
+ // src/storage/managed-sqlite.ts
2
+ function managedSqliteName(mount, managed) {
3
+ const name = managed === true ? mount : managed && typeof managed === "object" && "name" in managed ? managed.name : void 0;
4
+ if (typeof name !== "string" || !/^[a-z][a-z0-9-]{0,62}$/.test(name))
5
+ throw new TypeError(
6
+ "Use a managed SQLite name of 1\u201363 lowercase letters, digits, or hyphens starting with a letter."
7
+ );
8
+ return name;
9
+ }
10
+ function secureUrl(value) {
11
+ const url = new URL(value);
12
+ const local = url.hostname === "localhost" || url.hostname.endsWith(".localhost") || url.hostname === "127.0.0.1" || url.hostname === "[::1]";
13
+ if (!(url.protocol === "https:" || local && url.protocol === "http:") || url.username || url.password || url.search || url.hash)
14
+ throw new Error("Use HTTPS or a loopback URL for Farm managed SQLite.");
15
+ return url;
16
+ }
17
+ async function requestSqliteResource(name, operation) {
18
+ const key = process.env.FARMJS_API_KEY;
19
+ if (!key) throw new Error("Set FARMJS_API_KEY on the server to access managed SQLite.");
20
+ const base = secureUrl(process.env.FARMJS_API_URL || "https://app.farmjs.dev");
21
+ const headers = new Headers({
22
+ authorization: "Bearer " + key,
23
+ "content-type": "application/json"
24
+ });
25
+ if (process.env.FARMJS_PROJECT_ID) headers.set("x-farm-project", process.env.FARMJS_PROJECT_ID);
26
+ const environment = process.env.FARMJS_ENVIRONMENT;
27
+ if (environment)
28
+ headers.set("x-farm-environment", environment === "preview" ? "staging" : environment);
29
+ const response = await fetch(new URL("/api/storage/sqlite/" + operation, base), {
30
+ method: operation === "token" ? "POST" : "PUT",
31
+ headers,
32
+ body: JSON.stringify({ name }),
33
+ redirect: "error",
34
+ signal: AbortSignal.timeout(15e3)
35
+ });
36
+ const result = await response.json();
37
+ if (!response.ok)
38
+ throw new Error(
39
+ typeof result?.message === "string" ? result.message : "Farm SQLite request failed (HTTP " + response.status + ")."
40
+ );
41
+ return result;
42
+ }
43
+ async function credential(name) {
44
+ const result = await requestSqliteResource(name, "token");
45
+ if (!result || typeof result.url !== "string" || typeof result.token !== "string" || !result.token || !Number.isFinite(Date.parse(result.expiresAt)) || Date.parse(result.expiresAt) <= Date.now())
46
+ throw new Error("Farm returned an invalid SQLite credential. Check the Infra service.");
47
+ return {
48
+ url: secureUrl(result.url).href,
49
+ token: result.token,
50
+ expires: Date.parse(result.expiresAt)
51
+ };
52
+ }
53
+ async function connect(name, loadClient) {
54
+ const [{ createClient }, initial] = await Promise.all([loadClient(), credential(name)]);
55
+ let current = initial;
56
+ let refreshing;
57
+ return createClient({
58
+ url: current.url,
59
+ fetch: async (request) => {
60
+ if (new URL(request.url).origin !== new URL(initial.url).origin)
61
+ throw new Error("The database endpoint changed. Reconnect the managed SQLite mount.");
62
+ if (current.expires - Date.now() < 3e4) {
63
+ refreshing ?? (refreshing = credential(name).finally(() => {
64
+ refreshing = void 0;
65
+ }));
66
+ const renewed = await refreshing;
67
+ if (renewed.url !== initial.url)
68
+ throw new Error("The SQLite resource changed. Reconnect the mount.");
69
+ current = renewed;
70
+ }
71
+ const headers = new Headers(request.headers);
72
+ headers.set("authorization", "Bearer " + current.token);
73
+ return fetch(request, { headers, redirect: "error" });
74
+ }
75
+ });
76
+ }
77
+ var databaseAccessor = /* @__PURE__ */ Symbol.for("farmjs.storage.managedDatabase");
78
+ function managedSqliteDriver(name, loadClient) {
79
+ let pending;
80
+ let initialized;
81
+ let closed = false;
82
+ function client() {
83
+ if (closed) throw new Error("The managed SQLite mount has been disposed.");
84
+ return pending ?? (pending = connect(name, loadClient).catch((error) => {
85
+ pending = void 0;
86
+ throw error;
87
+ }));
88
+ }
89
+ function kv() {
90
+ return initialized ?? (initialized = client().then(async (db) => {
91
+ await db.execute(
92
+ "CREATE TABLE IF NOT EXISTS _farm_kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)"
93
+ );
94
+ return db;
95
+ }).catch((error) => {
96
+ initialized = void 0;
97
+ throw error;
98
+ }));
99
+ }
100
+ return {
101
+ name: "farm-managed-sqlite",
102
+ [databaseAccessor]: client,
103
+ async hasItem(key) {
104
+ return (await (await kv()).execute({ sql: "SELECT 1 FROM _farm_kv WHERE key=?", args: [key] })).rows.length > 0;
105
+ },
106
+ async getItem(key) {
107
+ const { rows } = await (await kv()).execute({ sql: "SELECT value FROM _farm_kv WHERE key=?", args: [key] });
108
+ return rows[0]?.value ?? null;
109
+ },
110
+ async getKeys(base = "") {
111
+ const { rows } = await (await kv()).execute({
112
+ sql: "SELECT key FROM _farm_kv WHERE instr(key,?)=1 ORDER BY key",
113
+ args: [base]
114
+ });
115
+ return rows.map((row) => String(row.key));
116
+ },
117
+ async setItem(key, value) {
118
+ await (await kv()).execute({
119
+ sql: "INSERT INTO _farm_kv(key,value) VALUES (?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value",
120
+ args: [key, value]
121
+ });
122
+ },
123
+ async removeItem(key) {
124
+ await (await kv()).execute({ sql: "DELETE FROM _farm_kv WHERE key=?", args: [key] });
125
+ },
126
+ async clear(base = "") {
127
+ await (await kv()).execute({ sql: "DELETE FROM _farm_kv WHERE instr(key,?)=1", args: [base] });
128
+ },
129
+ async dispose() {
130
+ closed = true;
131
+ (await pending)?.close();
132
+ }
133
+ };
134
+ }
135
+ function sqlAdapter(client, tx) {
136
+ return {
137
+ dialect: "sqlite",
138
+ async query(sql, params) {
139
+ const result = await (tx ?? client).execute({ sql, args: params });
140
+ return {
141
+ rows: result.rows,
142
+ affectedRows: result.rowsAffected,
143
+ insertId: result.lastInsertRowid
144
+ };
145
+ },
146
+ async transaction(run) {
147
+ if (tx) throw new Error("Nested managed SQLite transactions are unsupported.");
148
+ const transaction = await client.transaction("write");
149
+ try {
150
+ const value = await run(sqlAdapter(client, transaction));
151
+ await transaction.commit();
152
+ return value;
153
+ } catch (error) {
154
+ if (!transaction.closed) await transaction.rollback();
155
+ throw error;
156
+ } finally {
157
+ transaction.close();
158
+ }
159
+ }
160
+ };
161
+ }
162
+ async function managedOrm(client, schema) {
163
+ const [{ createOrm }, { createSqlDriverFromAdapter }] = await Promise.all([
164
+ import("@farming-labs/orm"),
165
+ import("@farming-labs/orm-sql")
166
+ ]);
167
+ return createOrm({ schema, driver: createSqlDriverFromAdapter(sqlAdapter(client)) });
168
+ }
169
+
1
170
  // src/storage/index.ts
2
171
  import { createStorage, prefixStorage, builtinDrivers } from "unstorage";
3
172
  import memoryDriver from "unstorage/drivers/memory";
@@ -159,10 +328,17 @@ async function loadDatabaseDriver(config) {
159
328
  }
160
329
  };
161
330
  }
162
- async function resolveDriver(config) {
331
+ async function resolveDriver(config, mount) {
163
332
  if (config && isStorageClient(config)) {
164
333
  return config.resolveDriver();
165
334
  }
335
+ if (config?.driver === "farm-managed-sqlite") {
336
+ if (!mount) throw new TypeError("Register managed SQLite in storage.mounts.");
337
+ return managedSqliteDriver(
338
+ managedSqliteName(mount, config.managed),
339
+ () => loadModule("@libsql/client/http")
340
+ );
341
+ }
166
342
  const driverInput = config?.driver ?? "memory";
167
343
  if (typeof driverInput === "function") {
168
344
  return await driverInput();
@@ -274,6 +450,12 @@ function localStorage(options = {}) {
274
450
  });
275
451
  }
276
452
  function sqliteStorage(options) {
453
+ if ("managed" in options) {
454
+ if (Object.keys(options).some((key) => key !== "managed"))
455
+ throw new TypeError("Supply only managed when Farm provisions SQLite.");
456
+ if (options.managed !== true) managedSqliteName("", options.managed);
457
+ return { driver: "farm-managed-sqlite", managed: options.managed };
458
+ }
277
459
  return createStorageClient({
278
460
  driver: "sqlite",
279
461
  ...options
@@ -368,7 +550,9 @@ function collectDriverModules(config, modules) {
368
550
  const source = config;
369
551
  const driver = source.driver;
370
552
  if (typeof driver === "string") {
371
- if (isDatabaseDriverName(driver)) {
553
+ if (driver === "farm-managed-sqlite") {
554
+ modules.add("@libsql/client/http");
555
+ } else if (isDatabaseDriverName(driver)) {
372
556
  modules.add("db0");
373
557
  modules.add(DATABASE_CONNECTORS[driver].module);
374
558
  modules.add("unstorage/drivers/db0");
@@ -392,7 +576,7 @@ async function mountNamespaces(storage, mounts) {
392
576
  return;
393
577
  }
394
578
  for (const [base, config] of Object.entries(mounts)) {
395
- storage.mount(normalizeMountKey(base), await resolveDriver(config));
579
+ storage.mount(normalizeMountKey(base), await resolveDriver(config, base));
396
580
  }
397
581
  }
398
582
  async function createFarmStorage(config = {}) {
@@ -436,6 +620,17 @@ async function initStorage(config = {}) {
436
620
  }
437
621
  return globalStorage;
438
622
  }
623
+ async function getDatabase(name, options) {
624
+ const key = normalizeMountKey(name);
625
+ const mount = getActiveGlobalStorage().getMount(key);
626
+ const driver = mount.driver;
627
+ if (!key || normalizeMountKey(mount.base) !== key || !driver[databaseAccessor])
628
+ throw new TypeError(
629
+ "Configure a managed SQLite mount named " + JSON.stringify(name) + " before calling getDatabase()."
630
+ );
631
+ const client = await driver[databaseAccessor]();
632
+ return options ? managedOrm(client, options.schema) : client;
633
+ }
439
634
  function getStorage(namespace) {
440
635
  globalStorage = getActiveGlobalStorage();
441
636
  const base = normalizeMountKey(namespace);
@@ -500,6 +695,8 @@ async function disposeStorage() {
500
695
  }
501
696
 
502
697
  export {
698
+ managedSqliteName,
699
+ requestSqliteResource,
503
700
  _registerFarmStorageModules,
504
701
  defineStorageClient,
505
702
  createStorageClient,
@@ -526,6 +723,7 @@ export {
526
723
  createFarmStorage,
527
724
  resolveStorageRuntimeClient,
528
725
  initStorage,
726
+ getDatabase,
529
727
  getStorage,
530
728
  disposeStorage
531
729
  };