@teyik0/furin 0.7.0-alpha.3 → 0.8.0-alpha.0

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 (497) hide show
  1. package/README.md +1 -1
  2. package/dist/adapter/build.d.ts +9 -0
  3. package/dist/adapter/bun/server.d.ts +1 -0
  4. package/dist/adapter/bun.d.ts +7 -3
  5. package/dist/adapter/package.d.ts +1 -0
  6. package/dist/adapter/prerender.d.ts +21 -0
  7. package/dist/adapter/runtime-build.d.ts +24 -10
  8. package/dist/adapter/server-bundle.d.ts +20 -0
  9. package/dist/adapter/static.d.ts +2 -2
  10. package/dist/adapter/types.d.ts +81 -0
  11. package/dist/adapter/vercel/bootstrap.d.ts +5 -0
  12. package/dist/adapter/vercel/data.d.ts +23 -0
  13. package/dist/adapter/vercel/handler.d.ts +10 -0
  14. package/dist/adapter/vercel.d.ts +13 -3
  15. package/dist/adapter/vercel.js +516 -0
  16. package/dist/build/bun-build.d.ts +4 -0
  17. package/dist/build/compile-entry.ts +1 -0
  18. package/dist/build/discover-mounts-process.d.ts +1 -0
  19. package/dist/build/discover-mounts.d.ts +6 -0
  20. package/dist/build/elysia-aot-worker.d.ts +4 -0
  21. package/dist/build/elysia-aot.d.ts +7 -1
  22. package/dist/build/entry-template.d.ts +14 -7
  23. package/dist/build/entry-template.ts +33 -18
  24. package/dist/build/hydrate.d.ts +15 -2
  25. package/dist/build/index.d.ts +7 -3
  26. package/dist/build/index.js +8842 -15395
  27. package/dist/build/private-server-sourcemaps.d.ts +2 -0
  28. package/dist/build/route-types.d.ts +8 -2
  29. package/dist/build/server-app-entry.d.ts +2 -2
  30. package/dist/build/shared.d.ts +3 -5
  31. package/dist/build/types.d.ts +16 -16
  32. package/dist/cache.js +117 -32
  33. package/dist/cli/config.d.ts +2 -2
  34. package/dist/cli/index.js +8953 -15269
  35. package/dist/client/chunks/client-brdfd773.js +852 -0
  36. package/dist/client/chunks/client-k29262a4.js +59 -0
  37. package/dist/client/chunks/client-k88668k7.js +159 -0
  38. package/dist/client/chunks/client-xy6g38kx.js +317 -0
  39. package/dist/client/default-screens.d.ts +0 -11
  40. package/dist/client/define-route.d.ts +2 -1
  41. package/dist/client/hmr.d.ts +1 -1
  42. package/dist/client/internal/runtime-types.d.ts +7 -1
  43. package/dist/client/link.d.ts +1 -0
  44. package/dist/client/link.js +1790 -4190
  45. package/dist/client/mutation.d.ts +5 -0
  46. package/dist/client/query-store.d.ts +17 -7
  47. package/dist/client/query.d.ts +6 -8
  48. package/dist/client/request-id.d.ts +1 -0
  49. package/dist/client/route-api.d.ts +4 -4
  50. package/dist/client/route-element.d.ts +51 -0
  51. package/dist/client/router/boundary-tree.d.ts +1 -9
  52. package/dist/client/router/cache-generation.d.ts +15 -0
  53. package/dist/client/router/context.d.ts +13 -2
  54. package/dist/client/router/fetch-observers.d.ts +9 -0
  55. package/dist/client/router/hmr-refresh.d.ts +12 -0
  56. package/dist/client/router/index.d.ts +5 -7
  57. package/dist/client/router/link-utils.d.ts +0 -2
  58. package/dist/client/router/navigation-controller.d.ts +76 -0
  59. package/dist/client/router/navigation.d.ts +1 -0
  60. package/dist/client/router/page-fetch.d.ts +38 -0
  61. package/dist/client/router/provider.d.ts +2 -3
  62. package/dist/client/router/search/index.d.ts +11 -4
  63. package/dist/client/router/search/index.js +60 -0
  64. package/dist/client/router/spa-response.d.ts +9 -26
  65. package/dist/client/router/sync-catch-up.d.ts +3 -2
  66. package/dist/client/router/transport.d.ts +4 -0
  67. package/dist/client/router/types.d.ts +120 -46
  68. package/dist/client/router/use-fetch-interception.d.ts +12 -0
  69. package/dist/client/router/use-history-sync.d.ts +7 -0
  70. package/dist/client/router/use-hmr-refresh.d.ts +8 -0
  71. package/dist/client/router/use-sync-stream.d.ts +16 -0
  72. package/dist/client/server-error.d.ts +4 -7
  73. package/dist/client/sync.d.ts +43 -30
  74. package/dist/client.d.ts +2 -1
  75. package/dist/client.js +279 -829
  76. package/dist/config.d.ts +11 -12
  77. package/dist/config.js +0 -30
  78. package/dist/define-route.d.ts +262 -517
  79. package/dist/devtools/protocol.d.ts +4 -3
  80. package/dist/furin.d.ts +41 -31
  81. package/dist/furin.js +20560 -18970
  82. package/dist/plugin/binding-scope.d.ts +15 -2
  83. package/dist/plugin/client-plugin.d.ts +19 -0
  84. package/dist/plugin/dead-code-elimination.d.ts +14 -3
  85. package/dist/plugin/dev-routes.d.ts +22 -0
  86. package/dist/plugin/hmr-data-signature.d.ts +3 -0
  87. package/dist/plugin/hmr-hook-signature.d.ts +9 -0
  88. package/dist/plugin/index.d.ts +1 -6
  89. package/dist/plugin/index.js +1753 -1214
  90. package/dist/plugin/module-bindings.d.ts +11 -0
  91. package/dist/plugin/module-transform.d.ts +29 -0
  92. package/dist/plugin/preflight.d.ts +8 -0
  93. package/dist/plugin/route-chains.d.ts +35 -0
  94. package/dist/plugin/route-config.d.ts +28 -0
  95. package/dist/plugin/route-modules.d.ts +35 -0
  96. package/dist/plugin/route-registry.d.ts +12 -0
  97. package/dist/plugin/route-tree.d.ts +43 -0
  98. package/dist/plugin/strip-server-stages.d.ts +10 -0
  99. package/dist/plugin/strip-server.d.ts +10 -0
  100. package/dist/plugin/transform-client-module.d.ts +3 -0
  101. package/dist/plugin/transform-client.d.ts +0 -2
  102. package/dist/plugin/transform-isomorphic.d.ts +3 -2
  103. package/dist/routes.d.ts +15 -5
  104. package/dist/rsc/build/client-references.d.ts +8 -0
  105. package/dist/rsc/build/discover.d.ts +7 -0
  106. package/dist/rsc/build/flight-loader.d.ts +1 -0
  107. package/dist/rsc/build/index.d.ts +4 -1
  108. package/dist/rsc/build/paths.d.ts +2 -0
  109. package/dist/rsc/bundled-client-codec.d.ts +1 -0
  110. package/dist/rsc/client-codec.d.ts +3 -0
  111. package/dist/rsc/client-references.d.ts +22 -0
  112. package/dist/rsc/server-client-codec.d.ts +1 -0
  113. package/dist/rsc/server-codec.js +3889 -2
  114. package/dist/rsc/slot-proxy.d.ts +11 -0
  115. package/dist/rsc/transport-benchmark.d.ts +2 -1
  116. package/dist/rsc-client.js +16 -164
  117. package/dist/rsc-server.d.ts +1 -5
  118. package/dist/rsc.d.ts +1 -5
  119. package/dist/rsc.js +233 -73
  120. package/dist/server/assets/client-dir.d.ts +1 -0
  121. package/dist/server/auto-invalidate/index.d.ts +2 -2
  122. package/dist/server/auto-invalidate/plugin.d.ts +21 -15
  123. package/dist/server/auto-invalidate/types.d.ts +0 -2
  124. package/dist/server/bounded-body.d.ts +6 -0
  125. package/dist/server/browser-events/plugin.d.ts +4 -1
  126. package/dist/server/browser-events/shutdown.d.ts +1 -1
  127. package/dist/server/cache/dev-loader.d.ts +6 -1
  128. package/dist/server/cache/index.d.ts +4 -9
  129. package/dist/server/cache/invalidation.d.ts +7 -2
  130. package/dist/server/cache/isr-ssg.d.ts +6 -1
  131. package/dist/server/cache/page-cache.d.ts +5 -0
  132. package/dist/server/cache/purger.d.ts +14 -4
  133. package/dist/server/cache/redis/index.d.ts +1 -34
  134. package/dist/server/cache/redis/index.js +51 -25
  135. package/dist/server/cache/redis/scripts.d.ts +1 -1
  136. package/dist/server/cache/route-cache.d.ts +18 -2
  137. package/dist/server/cache/runtime-cache.d.ts +7 -0
  138. package/dist/server/context-logger.d.ts +6 -1
  139. package/dist/server/dev/graph.d.ts +4 -3
  140. package/dist/server/dev/runtime.d.ts +4 -0
  141. package/dist/server/dev/runtime.production.d.ts +1 -0
  142. package/dist/server/dev/stack-location.d.ts +9 -0
  143. package/dist/server/dev-page-imports.d.ts +42 -0
  144. package/dist/server/dev-page-plugin.d.ts +2 -49
  145. package/dist/server/devtools/instrumentation.d.ts +1 -3
  146. package/dist/server/devtools/instrumentation.production.d.ts +0 -2
  147. package/dist/server/devtools/request-context.d.ts +7 -0
  148. package/dist/server/evlog.d.ts +18 -6
  149. package/dist/server/instance.d.ts +52 -44
  150. package/dist/server/internal.d.ts +51 -14
  151. package/dist/server/internal.js +9749 -2095
  152. package/dist/server/lang-detect.d.ts +4 -4
  153. package/dist/server/logger.d.ts +6 -0
  154. package/dist/server/logging/ingest-plugin.d.ts +32 -0
  155. package/dist/server/mode.d.ts +17 -0
  156. package/dist/server/prerender.d.ts +32 -0
  157. package/dist/server/prod/runtime.d.ts +5 -0
  158. package/dist/server/production-server.js +992 -726
  159. package/dist/server/registrations.d.ts +14 -0
  160. package/dist/server/render/assemble.d.ts +0 -22
  161. package/dist/server/render/buffered-render.d.ts +20 -0
  162. package/dist/server/render/document-stream.d.ts +45 -0
  163. package/dist/server/render/document.d.ts +1 -1
  164. package/dist/server/render/element.d.ts +2 -5
  165. package/dist/server/render/index.d.ts +4 -5
  166. package/dist/server/render/index.ts +4 -21
  167. package/dist/server/render/isr-revalidation.d.ts +5 -0
  168. package/dist/server/render/isr-shared-cache.d.ts +23 -0
  169. package/dist/server/render/isr.d.ts +19 -1
  170. package/dist/server/render/loader-errors.d.ts +33 -0
  171. package/dist/server/render/loader-segments.d.ts +40 -0
  172. package/dist/server/render/loaders.d.ts +16 -32
  173. package/dist/server/render/mixed-cache.d.ts +2 -2
  174. package/dist/server/render/navigation-head.d.ts +13 -0
  175. package/dist/server/render/not-found-plugin.d.ts +18 -0
  176. package/dist/server/render/observe-loader.d.ts +1 -0
  177. package/dist/server/render/ppr-document.d.ts +1 -1
  178. package/dist/server/render/ppr-request.d.ts +0 -2
  179. package/dist/server/render/ppr-route.d.ts +13 -2
  180. package/dist/server/render/prepare-render.d.ts +57 -0
  181. package/dist/server/render/request-loaders.d.ts +19 -0
  182. package/dist/server/render/route-frame-transport.d.ts +7 -1
  183. package/dist/server/render/shell.d.ts +1 -1
  184. package/dist/server/render/shell.ts +1 -1
  185. package/dist/server/render/ssr-transport.d.ts +11 -0
  186. package/dist/server/render/ssr.d.ts +1 -116
  187. package/dist/server/render/static-params.d.ts +15 -0
  188. package/dist/server/router/discovery.d.ts +1 -0
  189. package/dist/server/router/dispatch.d.ts +96 -0
  190. package/dist/server/router/hmr.d.ts +14 -24
  191. package/dist/server/router/patterns.d.ts +15 -20
  192. package/dist/server/router/plugin.d.ts +26 -24
  193. package/dist/server/router/schemas.d.ts +6 -24
  194. package/dist/server/router/types.d.ts +0 -2
  195. package/dist/server/runtime-env.d.ts +6 -1
  196. package/dist/server/static-export.d.ts +38 -0
  197. package/dist/server/static-export.js +10667 -0
  198. package/dist/server/sync/adapter.d.ts +11 -0
  199. package/dist/server/sync/atomic.d.ts +0 -2
  200. package/dist/server/sync/config.d.ts +0 -1
  201. package/dist/server/sync/drizzle/index.js +112 -68
  202. package/dist/server/sync/fingerprint.d.ts +0 -1
  203. package/dist/server/sync/index.d.ts +2 -6
  204. package/dist/server/sync/index.js +1689 -1364
  205. package/dist/server/sync/invalidate-sync.d.ts +10 -0
  206. package/dist/server/sync/plugin.d.ts +18 -55
  207. package/dist/server/sync/postgres/execute.d.ts +2 -2
  208. package/dist/server/sync/postgres/index.d.ts +3 -1
  209. package/dist/server/sync/postgres/index.js +68 -37
  210. package/dist/server/sync/postgres/migration.sql +2 -0
  211. package/dist/server/sync/principal-journal.d.ts +11 -0
  212. package/dist/server/sync/prisma/index.js +74 -39
  213. package/dist/server/sync/queries.d.ts +57 -16
  214. package/dist/server/sync/redis/index.d.ts +2 -1
  215. package/dist/server/sync/redis/index.js +49 -5
  216. package/dist/server/sync/redis/scripts.d.ts +2 -1
  217. package/dist/server/sync/response.d.ts +3 -0
  218. package/dist/server/sync/runtime.d.ts +5 -1
  219. package/dist/server/sync/sqlite/index.d.ts +3 -1
  220. package/dist/server/sync/sqlite/index.js +58 -27
  221. package/dist/server/sync/stream.d.ts +32 -7
  222. package/dist/server/weak-registry.d.ts +9 -0
  223. package/dist/shared/await.d.ts +2 -1
  224. package/dist/shared/compact-json.d.ts +1 -0
  225. package/dist/shared/defer.d.ts +1 -1
  226. package/dist/shared/deferred-ndjson.d.ts +3 -2
  227. package/dist/shared/elysia-contract.d.ts +2 -0
  228. package/dist/shared/in-memory-apps.d.ts +7 -0
  229. package/dist/shared/invalidation-header.d.ts +13 -0
  230. package/dist/shared/navigation-data.d.ts +7 -0
  231. package/dist/shared/prefix.d.ts +11 -5
  232. package/dist/shared/route-frame.d.ts +3 -0
  233. package/dist/shared/route-map.d.ts +7 -0
  234. package/dist/shared/route-matches.d.ts +41 -0
  235. package/dist/shared/route-specificity.d.ts +2 -0
  236. package/dist/shared/search-params.d.ts +2 -3
  237. package/dist/shared/sync-query.d.ts +6 -13
  238. package/dist/shared/utils/ast-walk.d.ts +3 -11
  239. package/package.json +32 -21
  240. package/src/adapter/README.md +37 -16
  241. package/src/adapter/build.ts +269 -0
  242. package/src/adapter/bun/server.ts +14 -0
  243. package/src/adapter/bun.ts +89 -265
  244. package/src/adapter/furin-app.d.ts +14 -0
  245. package/src/adapter/package.ts +31 -27
  246. package/src/adapter/prerender.ts +97 -0
  247. package/src/adapter/runtime-build.ts +83 -93
  248. package/src/adapter/server-bundle.ts +110 -0
  249. package/src/adapter/static.ts +259 -247
  250. package/src/adapter/types.ts +89 -0
  251. package/src/adapter/vercel/bootstrap.ts +85 -0
  252. package/src/adapter/vercel/data.ts +21 -0
  253. package/src/adapter/vercel/handler.ts +132 -0
  254. package/src/adapter/vercel.ts +329 -659
  255. package/src/build/bun-build.ts +3 -0
  256. package/src/build/client.ts +22 -60
  257. package/src/build/compile-entry.ts +1 -0
  258. package/src/build/discover-mounts-process.ts +13 -0
  259. package/src/build/discover-mounts.ts +40 -0
  260. package/src/build/elysia-aot-worker.ts +84 -2
  261. package/src/build/elysia-aot.ts +61 -2
  262. package/src/build/entry-template.ts +33 -18
  263. package/src/build/hydrate.ts +122 -44
  264. package/src/build/index.ts +156 -108
  265. package/src/build/private-server-sourcemaps.ts +5 -0
  266. package/src/build/production-instrumentation.ts +22 -19
  267. package/src/build/route-types.ts +93 -11
  268. package/src/build/server-app-entry.ts +4 -21
  269. package/src/build/shared.ts +9 -41
  270. package/src/build/types.ts +14 -20
  271. package/src/build/virtual-entry.ts +2 -4
  272. package/src/cli/config.ts +133 -6
  273. package/src/cli/index.ts +59 -21
  274. package/src/cli/preview.ts +2 -1
  275. package/src/client/boundaries.tsx +5 -14
  276. package/src/client/default-screens.tsx +2 -2
  277. package/src/client/define-route.ts +3 -2
  278. package/src/client/hmr.ts +1 -1
  279. package/src/client/internal/runtime-types.ts +7 -1
  280. package/src/client/link.tsx +80 -43
  281. package/src/client/mutation.ts +98 -3
  282. package/src/client/query-store.ts +160 -29
  283. package/src/client/query.tsx +12 -29
  284. package/src/client/request-id.ts +10 -0
  285. package/src/client/route-api.tsx +6 -6
  286. package/src/client/route-element.tsx +155 -0
  287. package/src/client/router/boundary-tree.tsx +2 -93
  288. package/src/client/router/cache-generation.ts +37 -0
  289. package/src/client/router/context.ts +40 -4
  290. package/src/client/router/fetch-observers.ts +46 -0
  291. package/src/client/router/hmr-refresh.ts +50 -0
  292. package/src/client/router/index.ts +7 -29
  293. package/src/client/router/link-utils.ts +19 -31
  294. package/src/client/router/navigation-controller.ts +547 -0
  295. package/src/client/router/navigation.ts +3 -2
  296. package/src/client/router/optimistic.ts +2 -3
  297. package/src/client/router/page-fetch.ts +272 -0
  298. package/src/client/router/provider.tsx +223 -1079
  299. package/src/client/router/search/index.ts +38 -14
  300. package/src/client/router/spa-response.ts +19 -70
  301. package/src/client/router/sync-catch-up.ts +65 -7
  302. package/src/client/router/transport.ts +23 -0
  303. package/src/client/router/types.ts +203 -61
  304. package/src/client/router/use-fetch-interception.ts +52 -0
  305. package/src/client/router/use-history-sync.ts +56 -0
  306. package/src/client/router/use-hmr-refresh.ts +51 -0
  307. package/src/client/router/use-sync-stream.ts +129 -0
  308. package/src/client/server-error.ts +2 -40
  309. package/src/client/sync.ts +268 -378
  310. package/src/client.ts +2 -7
  311. package/src/config.ts +23 -45
  312. package/src/define-route.ts +487 -882
  313. package/src/devtools/devtools-element.js +10 -3
  314. package/src/devtools/protocol.ts +3 -3
  315. package/src/furin.ts +253 -1086
  316. package/src/plugin/binding-scope.ts +219 -94
  317. package/src/plugin/client-plugin.ts +145 -0
  318. package/src/plugin/dead-code-elimination.ts +390 -111
  319. package/src/plugin/dev-routes.ts +453 -0
  320. package/src/plugin/hmr-data-signature.ts +161 -0
  321. package/src/plugin/hmr-dependencies.ts +2 -4
  322. package/src/plugin/hmr-hook-signature.ts +252 -0
  323. package/src/plugin/index.ts +3 -96
  324. package/src/plugin/module-bindings.ts +216 -0
  325. package/src/plugin/module-transform.ts +63 -0
  326. package/src/plugin/preflight.ts +66 -0
  327. package/src/plugin/route-chains.ts +309 -0
  328. package/src/plugin/route-config.ts +451 -0
  329. package/src/plugin/route-modules.ts +209 -0
  330. package/src/plugin/route-registry.ts +316 -0
  331. package/src/plugin/route-tree.ts +248 -0
  332. package/src/plugin/strip-server-stages.ts +197 -0
  333. package/src/plugin/strip-server.ts +22 -0
  334. package/src/plugin/transform-client-module.ts +36 -31
  335. package/src/plugin/transform-client.ts +33 -1114
  336. package/src/plugin/transform-dev-page.ts +84 -92
  337. package/src/plugin/transform-isomorphic.ts +396 -185
  338. package/src/routes.ts +15 -5
  339. package/src/rsc/build/client-references.ts +267 -0
  340. package/src/rsc/build/discover.ts +226 -0
  341. package/src/rsc/build/flight-loader.ts +69 -0
  342. package/src/rsc/build/index.ts +53 -31
  343. package/src/rsc/build/paths.ts +7 -0
  344. package/src/rsc/bundled-client-codec.ts +4 -0
  345. package/src/rsc/client-codec.ts +12 -3
  346. package/src/rsc/client-references.ts +138 -0
  347. package/src/rsc/codec.ts +30 -21
  348. package/src/rsc/flight-drain.ts +6 -29
  349. package/src/rsc/react-server-dom-webpack.d.ts +1 -1
  350. package/src/rsc/server-client-codec.ts +14 -0
  351. package/src/rsc/server-codec.ts +5 -8
  352. package/src/rsc/slot-proxy.ts +34 -0
  353. package/src/rsc/transport-benchmark.ts +1 -1
  354. package/src/rsc-server.tsx +5 -23
  355. package/src/rsc.tsx +5 -29
  356. package/src/server/assets/client-dir.ts +110 -0
  357. package/src/server/assets/production.ts +1 -1
  358. package/src/server/auto-invalidate/index.ts +2 -7
  359. package/src/server/auto-invalidate/plugin.ts +43 -15
  360. package/src/server/auto-invalidate/registry.ts +6 -6
  361. package/src/server/auto-invalidate/runtime.ts +16 -98
  362. package/src/server/auto-invalidate/types.ts +0 -6
  363. package/src/server/bounded-body.ts +38 -0
  364. package/src/server/browser-events/plugin.ts +109 -22
  365. package/src/server/browser-events/shutdown.ts +28 -9
  366. package/src/server/cache/dev-loader.ts +30 -16
  367. package/src/server/cache/index.ts +2 -15
  368. package/src/server/cache/invalidation.ts +27 -46
  369. package/src/server/cache/isr-ssg.ts +6 -1
  370. package/src/server/cache/isr.ts +11 -11
  371. package/src/server/cache/page-cache-state.ts +2 -2
  372. package/src/server/cache/page-cache.ts +13 -9
  373. package/src/server/cache/purger.ts +64 -8
  374. package/src/server/cache/redis/index.ts +17 -27
  375. package/src/server/cache/redis/scripts.ts +21 -4
  376. package/src/server/cache/registry.ts +3 -3
  377. package/src/server/cache/route-cache.ts +47 -13
  378. package/src/server/cache/runtime-cache.ts +144 -24
  379. package/src/server/cache/ssg.ts +7 -5
  380. package/src/server/context-logger.ts +46 -8
  381. package/src/server/dev/diagnostics.ts +6 -56
  382. package/src/server/dev/error.ts +3 -34
  383. package/src/server/dev/graph.ts +35 -22
  384. package/src/server/dev/rewrite-module-specifiers.ts +15 -19
  385. package/src/server/dev/runtime.production.ts +4 -0
  386. package/src/server/dev/runtime.ts +404 -0
  387. package/src/server/dev/stack-location.ts +46 -0
  388. package/src/server/dev-page-imports.ts +183 -0
  389. package/src/server/dev-page-plugin.ts +39 -302
  390. package/src/server/devtools/hub.ts +3 -3
  391. package/src/server/devtools/instrumentation.production.ts +0 -8
  392. package/src/server/devtools/instrumentation.ts +6 -8
  393. package/src/server/devtools/plugin.ts +2 -1
  394. package/src/server/devtools/request-context.ts +67 -16
  395. package/src/server/evlog.ts +119 -55
  396. package/src/server/instance.ts +187 -138
  397. package/src/server/internal.ts +66 -62
  398. package/src/server/lang-detect.ts +31 -22
  399. package/src/server/logger.ts +20 -7
  400. package/src/server/logging/ingest-plugin.ts +123 -0
  401. package/src/server/mode.ts +19 -0
  402. package/src/server/prerender.ts +122 -0
  403. package/src/server/prod/runtime.ts +181 -0
  404. package/src/server/production-server.ts +43 -17
  405. package/src/server/registrations.ts +38 -0
  406. package/src/server/render/assemble.ts +5 -8
  407. package/src/server/render/buffered-render.ts +171 -0
  408. package/src/server/render/document-stream.ts +188 -0
  409. package/src/server/render/document.tsx +5 -3
  410. package/src/server/render/element.tsx +6 -73
  411. package/src/server/render/index.ts +4 -21
  412. package/src/server/render/isr-revalidation.ts +246 -0
  413. package/src/server/render/isr-shared-cache.ts +141 -0
  414. package/src/server/render/isr.ts +212 -516
  415. package/src/server/render/loader-errors.ts +183 -0
  416. package/src/server/render/loader-segments.ts +149 -0
  417. package/src/server/render/loaders.ts +126 -547
  418. package/src/server/render/mixed-cache.ts +28 -27
  419. package/src/server/render/navigation-head.ts +33 -0
  420. package/src/server/render/not-found-plugin.ts +31 -0
  421. package/src/server/render/not-found.ts +32 -8
  422. package/src/server/render/observe-loader.ts +46 -0
  423. package/src/server/render/ppr-document.ts +36 -14
  424. package/src/server/render/ppr-request.ts +2 -2
  425. package/src/server/render/ppr-route.ts +79 -18
  426. package/src/server/render/prepare-render.ts +251 -0
  427. package/src/server/render/request-loaders.ts +216 -0
  428. package/src/server/render/route-frame-transport.ts +41 -4
  429. package/src/server/render/shell.ts +1 -1
  430. package/src/server/render/ssg.ts +9 -20
  431. package/src/server/render/ssr-transport.ts +221 -0
  432. package/src/server/render/ssr.ts +95 -956
  433. package/src/server/render/static-params.ts +32 -0
  434. package/src/server/render/template.ts +7 -7
  435. package/src/server/router/discovery.ts +82 -159
  436. package/src/server/router/dispatch.ts +337 -0
  437. package/src/server/router/hmr.ts +177 -190
  438. package/src/server/router/patterns.ts +39 -65
  439. package/src/server/router/plugin.ts +234 -359
  440. package/src/server/router/schemas.ts +6 -39
  441. package/src/server/router/source-version.ts +5 -4
  442. package/src/server/router/types.ts +0 -2
  443. package/src/server/runtime-env.ts +6 -1
  444. package/src/server/static-export.ts +143 -0
  445. package/src/server/sync/adapter.ts +11 -0
  446. package/src/server/sync/atomic.ts +16 -36
  447. package/src/server/sync/config.ts +6 -14
  448. package/src/server/sync/drizzle/index.ts +12 -20
  449. package/src/server/sync/fingerprint.ts +1 -1
  450. package/src/server/sync/index.ts +2 -10
  451. package/src/server/sync/invalidate-sync.ts +31 -0
  452. package/src/server/sync/mutation-handler.ts +6 -0
  453. package/src/server/sync/plugin.ts +171 -129
  454. package/src/server/sync/postgres/execute.ts +9 -1
  455. package/src/server/sync/postgres/index.ts +71 -39
  456. package/src/server/sync/postgres/migration.sql +2 -0
  457. package/src/server/sync/principal-journal.ts +78 -0
  458. package/src/server/sync/prisma/index.ts +1 -0
  459. package/src/server/sync/queries.ts +133 -40
  460. package/src/server/sync/query-context.ts +38 -5
  461. package/src/server/sync/redis/index.ts +34 -6
  462. package/src/server/sync/redis/scripts.ts +10 -1
  463. package/src/server/sync/response.ts +47 -67
  464. package/src/server/sync/runtime.ts +24 -7
  465. package/src/server/sync/sqlite/index.ts +92 -61
  466. package/src/server/sync/sqlite/migration.sql +1 -0
  467. package/src/server/sync/stream.ts +47 -26
  468. package/src/server/sync/validation.ts +1 -1
  469. package/src/server/weak-registry.ts +37 -0
  470. package/src/shared/await.tsx +2 -1
  471. package/src/shared/compact-json.ts +1 -1
  472. package/src/shared/defer.ts +1 -1
  473. package/src/shared/deferred-ndjson.ts +142 -120
  474. package/src/shared/elysia-contract.ts +7 -0
  475. package/src/shared/error.ts +1 -4
  476. package/src/shared/in-memory-apps.ts +24 -0
  477. package/src/shared/invalidation-header.ts +38 -0
  478. package/src/shared/navigation-data.ts +29 -0
  479. package/src/shared/prefix.ts +42 -6
  480. package/src/shared/route-frame.ts +82 -26
  481. package/src/shared/route-map.ts +23 -39
  482. package/src/shared/route-matches.ts +59 -0
  483. package/src/shared/route-specificity.ts +28 -0
  484. package/src/shared/search-params.ts +6 -35
  485. package/src/shared/sync-query.ts +30 -23
  486. package/src/shared/utils/ast-walk.ts +9 -25
  487. package/src/shared/utils/index.ts +1 -1
  488. package/dist/build/scan-server.d.ts +0 -14
  489. package/dist/build/ssg-cache.d.ts +0 -18
  490. package/dist/plugin/route-config-autofix.d.ts +0 -31
  491. package/dist/plugin/routes.d.ts +0 -34
  492. package/dist/server/router/hmr.production.d.ts +0 -7
  493. package/src/build/scan-server.ts +0 -112
  494. package/src/build/ssg-cache.ts +0 -126
  495. package/src/plugin/route-config-autofix.ts +0 -1149
  496. package/src/plugin/routes.ts +0 -1140
  497. package/src/server/router/hmr.production.ts +0 -18
@@ -1,10 +1,9 @@
1
- import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
2
- import { join, relative } from "node:path";
1
+ import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
2
+ import { dirname, relative } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
- import type { BuildTarget } from "../config";
5
4
  import { resolveRouteRevalidate } from "../server/router/patterns.ts";
6
5
  import type { ResolvedRoute } from "../server/router/types.ts";
7
- import type { BuildRouteManifestEntry, TargetBuildManifest } from "./types";
6
+ import type { BuildRouteManifestEntry } from "./types";
8
7
 
9
8
  // import.meta.dir/path/url are inlined at bundle time to the OUTPUT file's
10
9
  // location — so relative paths break when bundled. import.meta.resolve() is a
@@ -12,7 +11,6 @@ import type { BuildRouteManifestEntry, TargetBuildManifest } from "./types";
12
11
  // exports. This is the Web-standard approach (Bun, Node 20.6+, browsers).
13
12
  export const CLIENT_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/client"));
14
13
  export const LINK_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/link"));
15
- export const SEARCH_MODULE_PATH = fileURLToPath(import.meta.resolve("@teyik0/furin/search"));
16
14
 
17
15
  export function ensureDir(path: string): void {
18
16
  if (!existsSync(path)) {
@@ -24,27 +22,16 @@ export function toPosixPath(path: string): string {
24
22
  return path.replace(/\\/g, "/");
25
23
  }
26
24
 
27
- export function collectFilesRecursive(dir: string): string[] {
28
- const files: string[] = [];
29
- const entries = readdirSync(dir, { withFileTypes: true });
30
-
31
- for (const entry of entries) {
32
- const absolutePath = join(dir, entry.name);
33
- if (entry.isDirectory()) {
34
- files.push(...collectFilesRecursive(absolutePath));
35
- continue;
36
- }
37
- if (entry.isFile()) {
38
- files.push(absolutePath);
39
- }
40
- }
41
-
42
- return files.sort();
25
+ /** Writes a Bun build metafile (`furin build --analyze`) and logs where it went. */
26
+ export function writeBuildMetafile(path: string, metafile: Bun.BuildMetafile, label: string): void {
27
+ ensureDir(dirname(path));
28
+ writeFileSync(path, `${JSON.stringify(metafile, null, 2)}\n`);
29
+ console.log(`[furin] ${label} metafile: ${toPosixPath(path)}`);
43
30
  }
44
31
 
45
32
  export function copyDirRecursive(sourceDir: string, targetDir: string): void {
46
33
  rmSync(targetDir, { force: true, recursive: true });
47
- cpSync(sourceDir, targetDir, { recursive: true });
34
+ cpSync(sourceDir, targetDir, { recursive: true, dereference: true });
48
35
  }
49
36
 
50
37
  export function toBuildRouteManifestEntry(
@@ -62,22 +49,3 @@ export function toBuildRouteManifestEntry(
62
49
  revalidate: resolveRouteRevalidate(route.page) ?? null,
63
50
  };
64
51
  }
65
-
66
- export function buildTargetManifest(
67
- rootDir: string,
68
- buildRoot: string,
69
- target: BuildTarget,
70
- serverEntry: string | null
71
- ): TargetBuildManifest {
72
- const targetDir = join(buildRoot, target);
73
-
74
- return {
75
- buildId: "", // populated by adapter after buildClient() completes
76
- generatedAt: new Date().toISOString(),
77
- targetDir: toPosixPath(relative(rootDir, targetDir)),
78
- clientDir: toPosixPath(relative(rootDir, join(targetDir, "client"))),
79
- templatePath: toPosixPath(relative(rootDir, join(targetDir, "client", "index.html"))),
80
- serverPath: null,
81
- serverEntry: serverEntry ? toPosixPath(relative(rootDir, serverEntry)) : null,
82
- };
83
- }
@@ -1,9 +1,7 @@
1
- import type {
2
- BuildTarget,
3
- StaticExportConfig,
4
- VercelDeploymentConfig,
5
- } from "../config";
1
+ import type { AdapterTargetManifest } from "../adapter/types.ts";
2
+ import type { FurinTarget, StaticExportConfig } from "../config";
6
3
  import type { ResolvedRoute } from "../server/router/types.ts";
4
+ import type { ClientBoundary } from "../rsc/build/discover.ts";
7
5
 
8
6
  export interface BuildClientOptions {
9
7
  /**
@@ -19,6 +17,8 @@ export interface BuildClientOptions {
19
17
  clientDirName?: string;
20
18
  /** Inject the evlog client logger into the hydrate entry. Off by default. */
21
19
  clientLogging: boolean;
20
+ /** Client boundaries found in the unstripped server graph. */
21
+ clientBoundaries?: readonly ClientBoundary[];
22
22
  /** Write Bun's complete build metafile to this path when provided. */
23
23
  metafilePath?: string;
24
24
  /** Package barrels Bun should parse on demand instead of loading in full. */
@@ -37,12 +37,6 @@ export interface BuildClientOptions {
37
37
  */
38
38
  publicPath: string;
39
39
  rootLayout: string;
40
- /**
41
- * Skip furin-env.d.ts generation. Set for non-root instances in
42
- * multi-instance dev — the file lives at the project root and only the root
43
- * app owns it.
44
- */
45
- skipRouteTypes?: boolean;
46
40
  }
47
41
 
48
42
  export interface BuildRouteManifestEntry {
@@ -59,7 +53,6 @@ export interface TargetBuildManifest {
59
53
  clientDir: string | null;
60
54
  generatedAt: string;
61
55
  rscManifestPath?: string;
62
- serverEntry: string | null;
63
56
  serverPath: string | null;
64
57
  targetDir: string;
65
58
  templatePath: string | null;
@@ -73,14 +66,15 @@ export interface PackageTargetBuildManifest {
73
66
  targetDir: string;
74
67
  }
75
68
 
76
- export type AnyTargetManifest =
69
+ type AnyTargetManifest =
70
+ | AdapterTargetManifest
77
71
  | TargetBuildManifest
78
72
  | StaticTargetBuildManifest
79
73
  | PackageTargetBuildManifest
80
74
  | VercelTargetBuildManifest;
81
75
 
82
76
  /** One mounted app in a multi-instance build. */
83
- export interface BuildAppSpec {
77
+ interface BuildAppSpec {
84
78
  pagesDir: string;
85
79
  /** Mount prefix (`""` or absent = root). */
86
80
  prefix?: string;
@@ -95,7 +89,8 @@ export interface BuildManifest {
95
89
  rootPath: string;
96
90
  routes: BuildRouteManifestEntry[];
97
91
  serverEntry: string | null;
98
- targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
92
+ /** Keyed by target name. */
93
+ targets: { [target: string]: AnyTargetManifest };
99
94
  version: 1;
100
95
  }
101
96
 
@@ -104,7 +99,7 @@ export interface BuildAppOptions {
104
99
  analyze?: boolean;
105
100
  /**
106
101
  * Explicit multi-app build (furin.config.ts `apps`). Overrides `pagesDir`
107
- * and server-entry auto-detection.
102
+ * and the mounts found by evaluating the server entry.
108
103
  */
109
104
  apps?: BuildAppSpec[];
110
105
  /** Inject the evlog client logger into the hydrate entry. Defaults to false. */
@@ -124,9 +119,8 @@ export interface BuildAppOptions {
124
119
  serverSourceMaps?: boolean;
125
120
  /** Configuration for the `static` build target. */
126
121
  staticConfig?: StaticExportConfig;
127
- target: BuildTarget | "all";
128
- /** Configuration for the Vercel build target. */
129
- vercelConfig?: VercelDeploymentConfig;
122
+ /** One target, several, or `"all"` deploy targets (bun, vercel, static). */
123
+ target: FurinTarget | FurinTarget[] | "all";
130
124
  }
131
125
 
132
126
  /** Build manifest entry produced by the `static` adapter. */
@@ -150,7 +144,7 @@ export interface VercelTargetBuildManifest {
150
144
 
151
145
  export interface BuildAppResult {
152
146
  manifest: BuildManifest;
153
- targets: Partial<Record<BuildTarget, AnyTargetManifest>>;
147
+ targets: BuildManifest["targets"];
154
148
  }
155
149
 
156
150
  export type BunBuildAliasConfig = Bun.BuildConfig & {
@@ -1,4 +1,4 @@
1
- const REGEX_SPECIAL_CHARACTERS_RE = /[.*+?^${}()|[\]\\]/g;
1
+ import { escapeRegExp } from "../server/router/patterns.ts";
2
2
 
3
3
  export interface VirtualBuildEntry {
4
4
  entrypoint: string;
@@ -12,9 +12,7 @@ export function createVirtualBuildEntry(
12
12
  loader: Bun.Loader
13
13
  ): VirtualBuildEntry {
14
14
  const normalizedEntrypoint = entrypoint.replaceAll("\\", "/");
15
- const entrypointFilter = new RegExp(
16
- `^${normalizedEntrypoint.replace(REGEX_SPECIAL_CHARACTERS_RE, "\\$&")}$`
17
- );
15
+ const entrypointFilter = new RegExp(`^${escapeRegExp(normalizedEntrypoint)}$`);
18
16
  return {
19
17
  entrypoint: normalizedEntrypoint,
20
18
  files: { [normalizedEntrypoint]: source },
package/src/cli/config.ts CHANGED
@@ -1,11 +1,115 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { resolve } from "node:path";
3
3
  import { pathToFileURL } from "node:url";
4
- import { Validator } from "elysia";
5
- import { configSchema, type FurinConfig } from "../config.ts";
4
+ import { t, Validator } from "elysia";
5
+ import type { TSchema } from "typebox";
6
+ import { BUILD_TARGETS, configSchema, type FurinConfig, type FurinTarget } from "../config.ts";
6
7
 
7
8
  const compiledConfigSchema = Validator.create(configSchema);
8
9
 
10
+ // `plugins` and `targets` are validated separately: TypeBox cannot describe functions.
11
+ const configKeysSchema = t.Object({
12
+ ...configSchema.properties,
13
+ plugins: t.Any(),
14
+ targets: t.Any(),
15
+ });
16
+ const MAX_SUGGESTION_DISTANCE = 2;
17
+
18
+ function editDistance(left: string, right: string): number {
19
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
20
+ for (const [leftIndex, leftChar] of [...left].entries()) {
21
+ const current = [leftIndex + 1];
22
+ for (const [rightIndex, rightChar] of [...right].entries()) {
23
+ current.push(
24
+ Math.min(
25
+ (previous[rightIndex + 1] ?? 0) + 1,
26
+ (current[rightIndex] ?? 0) + 1,
27
+ (previous[rightIndex] ?? 0) + (leftChar === rightChar ? 0 : 1)
28
+ )
29
+ );
30
+ }
31
+ previous = current;
32
+ }
33
+ return previous[right.length] ?? 0;
34
+ }
35
+
36
+ function closestKey(key: string, validKeys: string[]): string | undefined {
37
+ let best: { distance: number; key: string } | undefined;
38
+ for (const candidate of validKeys) {
39
+ const distance = editDistance(key.toLowerCase(), candidate.toLowerCase());
40
+ if (distance <= MAX_SUGGESTION_DISTANCE && (best === undefined || distance < best.distance)) {
41
+ best = { distance, key: candidate };
42
+ }
43
+ }
44
+ return best?.key;
45
+ }
46
+
47
+ /** Returns a message for the first key that the config schema does not declare. */
48
+ function findUnknownKey(value: unknown, schema: TSchema, path: string): string | undefined {
49
+ if (Array.isArray(value)) {
50
+ if (!t.IsArray(schema)) {
51
+ return;
52
+ }
53
+ for (const [index, item] of value.entries()) {
54
+ const message = findUnknownKey(item, schema.items, `${path}/${index}`);
55
+ if (message !== undefined) {
56
+ return message;
57
+ }
58
+ }
59
+ return;
60
+ }
61
+ if (!t.IsObject(schema) || typeof value !== "object" || value === null) {
62
+ return;
63
+ }
64
+ const { properties } = schema;
65
+ const validKeys = Object.keys(properties);
66
+ for (const [key, child] of Object.entries(value)) {
67
+ const childPath = `${path}/${key}`;
68
+ const childSchema = properties[key];
69
+ if (childSchema === undefined) {
70
+ const suggestion = closestKey(key, validKeys);
71
+ const hint =
72
+ suggestion === undefined
73
+ ? `Valid keys: ${validKeys.join(", ")}`
74
+ : `Did you mean "${suggestion}"?`;
75
+ return `unknown key "${key}" (path: ${childPath}). ${hint}`;
76
+ }
77
+ const message = findUnknownKey(child, childSchema, childPath);
78
+ if (message !== undefined) {
79
+ return message;
80
+ }
81
+ }
82
+ }
83
+
84
+ function isBunPlugin(value: unknown): value is Bun.BunPlugin {
85
+ return (
86
+ typeof value === "object" &&
87
+ value !== null &&
88
+ "name" in value &&
89
+ typeof value.name === "string" &&
90
+ "setup" in value &&
91
+ typeof value.setup === "function"
92
+ );
93
+ }
94
+
95
+ function isFurinTarget(value: unknown): value is FurinTarget {
96
+ if (typeof value === "string") {
97
+ return (BUILD_TARGETS as readonly string[]).includes(value);
98
+ }
99
+ return (
100
+ typeof value === "object" &&
101
+ value !== null &&
102
+ "name" in value &&
103
+ typeof value.name === "string" &&
104
+ "capabilities" in value &&
105
+ typeof value.capabilities === "object" &&
106
+ "runtimeModule" in value &&
107
+ typeof value.runtimeModule === "string" &&
108
+ "onBuildComplete" in value &&
109
+ typeof value.onBuildComplete === "function"
110
+ );
111
+ }
112
+
9
113
  const DEFAULT_CONFIG_FILENAMES = [
10
114
  "furin.config.ts",
11
115
  "furin.config.js",
@@ -16,8 +120,8 @@ interface ResolvedCliConfig extends FurinConfig {
16
120
  configPath: string | null;
17
121
  /**
18
122
  * Only set when the config file declares one — leaving it undefined lets
19
- * buildApp fall back to scanning server.ts for `furin({ pagesDir, prefix })`
20
- * calls (multi-instance detection).
123
+ * buildApp fall back to the `furin({ pagesDir, prefix })` calls made by
124
+ * evaluating the server entry (multi-instance detection).
21
125
  */
22
126
  pagesDir?: string;
23
127
  plugins?: Bun.BunPlugin[];
@@ -45,8 +149,8 @@ export async function loadCliConfig(
45
149
  const imported = await import(pathToFileURL(configPath).href);
46
150
  const rawConfig: FurinConfig = imported.default ?? imported;
47
151
 
48
- // Extract plugins before TypeBox validation: functions cannot be JSON-schema validated
49
- const { plugins, ...configToValidate } = rawConfig;
152
+ // Extract plugins and targets before TypeBox validation: functions cannot be JSON-schema validated
153
+ const { plugins, targets, ...configToValidate } = rawConfig;
50
154
 
51
155
  if (plugins !== undefined && !Array.isArray(plugins)) {
52
156
  throw new Error(
@@ -54,6 +158,28 @@ export async function loadCliConfig(
54
158
  );
55
159
  }
56
160
 
161
+ const unknownKey = findUnknownKey(rawConfig, configKeysSchema, "");
162
+ if (unknownKey !== undefined) {
163
+ throw new Error(`[furin] Invalid config at ${configPath}: ${unknownKey}`);
164
+ }
165
+
166
+ const invalidPluginIndex = (plugins ?? []).findIndex((plugin: unknown) => !isBunPlugin(plugin));
167
+ if (invalidPluginIndex !== -1) {
168
+ throw new Error(
169
+ `[furin] Invalid config at ${configPath}: plugins[${invalidPluginIndex}] must be a Bun plugin object: { name: string, setup(build) {} }`
170
+ );
171
+ }
172
+
173
+ if (targets !== undefined && !Array.isArray(targets)) {
174
+ throw new Error(`[furin] Invalid config at ${configPath}: "targets" must be an array`);
175
+ }
176
+ const invalidTargetIndex = (targets ?? []).findIndex((target: unknown) => !isFurinTarget(target));
177
+ if (invalidTargetIndex !== -1) {
178
+ throw new Error(
179
+ `[furin] Invalid config at ${configPath}: targets[${invalidTargetIndex}] must be one of ${BUILD_TARGETS.join(", ")}, or a deployment adapter object`
180
+ );
181
+ }
182
+
57
183
  if (!compiledConfigSchema.Check(configToValidate)) {
58
184
  const [firstError] = compiledConfigSchema.Errors(configToValidate);
59
185
  throw new Error(
@@ -70,5 +196,6 @@ export async function loadCliConfig(
70
196
  : undefined,
71
197
  plugins,
72
198
  rootDir: resolvedRootDir,
199
+ targets,
73
200
  };
74
201
  }
package/src/cli/index.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  import { existsSync } from "node:fs";
3
3
  import { resolve } from "node:path";
4
4
  import { parseArgs } from "node:util";
5
- import { buildApp } from "../build/index.ts";
6
- import { BUILD_TARGETS, type BuildTarget } from "../config.ts";
5
+ import { buildApp, generateRouteTypes } from "../build/index.ts";
6
+ import { BUILD_TARGETS, type FurinTarget } from "../config.ts";
7
7
  import { normalizePrefix } from "../server/instance.ts";
8
8
  import { loadCliConfig } from "./config.ts";
9
9
  import { normalizeStaticPreviewBasePath, startStaticPreview } from "./preview.ts";
@@ -138,28 +138,35 @@ if (command === "preview") {
138
138
  config?: string;
139
139
  };
140
140
 
141
- const target = values.target ?? "bun";
141
+ const config = await loadCliConfig(process.cwd(), values.config);
142
+ const configTargets = config.targets ?? ["bun"];
143
+ const targetName = (entry: FurinTarget): string =>
144
+ typeof entry === "string" ? entry : entry.name;
145
+ // --target names a configured target (so adapter options apply), else a built-in one.
146
+ const target: FurinTarget | FurinTarget[] | "all" =
147
+ values.target === undefined || values.target === "all"
148
+ ? (values.target ?? configTargets)
149
+ : (configTargets.find((entry) => targetName(entry) === values.target) ??
150
+ (values.target as FurinTarget));
142
151
 
143
- if (target !== "all" && !(BUILD_TARGETS as readonly string[]).includes(target)) {
152
+ if (
153
+ typeof target === "string" &&
154
+ target !== "all" &&
155
+ !(BUILD_TARGETS as readonly string[]).includes(target)
156
+ ) {
144
157
  bail(`Unsupported build target "${target}". Valid: ${BUILD_TARGETS.join(", ")}, all`);
145
158
  }
146
159
 
147
- const config = await loadCliConfig(process.cwd(), values.config);
148
-
149
- const isServerlessTarget = target === "static" || target === "package";
150
-
151
- const resolvedServerEntry = isServerlessTarget
152
- ? undefined
153
- : (() => {
154
- const entry = resolve(config.rootDir, config.serverEntry ?? "src/server.ts");
155
- if (!existsSync(entry)) {
156
- const expected = config.serverEntry ?? "src/server.ts";
157
- throw new Error(`[furin] Entrypoint ${expected} not found`);
158
- }
159
- return entry;
160
- })();
160
+ const resolvedServerEntry = config.serverEntry
161
+ ? resolve(config.rootDir, config.serverEntry)
162
+ : undefined;
163
+ if (resolvedServerEntry !== undefined && !existsSync(resolvedServerEntry)) {
164
+ throw new Error(`[furin] Entrypoint ${config.serverEntry} not found`);
165
+ }
166
+ const targets = Array.isArray(target) || target === "all" ? target : [target];
167
+ const targetLabel = targets === "all" ? targets : targets.map(targetName).join(", ");
161
168
 
162
- log(`Building Furin for ${target}…`);
169
+ log(`Building Furin for ${targetLabel}…`);
163
170
 
164
171
  const result = await buildApp({
165
172
  analyze: values.analyze,
@@ -187,12 +194,37 @@ if (command === "preview") {
187
194
  serverEntry: resolvedServerEntry,
188
195
  serverSourceMaps: config.serverSourceMaps,
189
196
  staticConfig: config.static,
190
- target: target as BuildTarget | "all",
191
- vercelConfig: config.vercel,
197
+ target,
192
198
  });
193
199
 
194
200
  const built = Object.keys(result.targets).join(", ") || "none";
195
201
  log(`Done: ${built} → .furin/build`);
202
+ } else if (command === "typegen") {
203
+ let rawValues: ReturnType<typeof parseArgs>["values"];
204
+ try {
205
+ rawValues = parseArgs({
206
+ args: argv.slice(1),
207
+ options: {
208
+ config: { type: "string" },
209
+ pagesDir: { type: "string" },
210
+ },
211
+ strict: true,
212
+ }).values;
213
+ } catch (error) {
214
+ bail(error instanceof Error ? error.message : String(error));
215
+ }
216
+
217
+ const values = rawValues as { config?: string; pagesDir?: string };
218
+ const config = await loadCliConfig(process.cwd(), values.config);
219
+ const pagesDir = values.pagesDir ?? config.pagesDir;
220
+ await generateRouteTypes({
221
+ apps: pagesDir ? [{ pagesDir, prefix: "" }] : config.apps,
222
+ pagesDir: undefined,
223
+ plugins: config.plugins,
224
+ rootDir: config.rootDir,
225
+ serverEntry: config.serverEntry,
226
+ });
227
+ log("Route types written to furin-env.d.ts");
196
228
  } else if (!command || command === "help") {
197
229
  console.log(
198
230
  `Furin CLI
@@ -200,6 +232,7 @@ if (command === "preview") {
200
232
  USAGE
201
233
  furin build [options]
202
234
  furin preview [options]
235
+ furin typegen [options]
203
236
 
204
237
  BUILD OPTIONS
205
238
  --target ${BUILD_TARGETS.join(" | ")} | all (default: bun)
@@ -210,6 +243,11 @@ BUILD OPTIONS
210
243
  --compile server | embed Compile to binary: "server" keeps client on disk, "embed" is self-contained
211
244
  --analyze Write complete bundle metafiles to .furin/build/analysis
212
245
 
246
+ TYPEGEN OPTIONS
247
+ Writes furin-env.d.ts for every mounted app (run it before tsc in CI)
248
+ --pagesDir Pages directory (default: config apps, server entry furin() mounts, then src/pages)
249
+ --config Config file path
250
+
213
251
  PREVIEW OPTIONS
214
252
  --dir Static export directory (default: static.outDir or dist)
215
253
  --basePath Static export base path (default: static.basePath or "")
@@ -1,5 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { isAbsolute, join, relative, resolve } from "node:path";
3
+ import { isWithinPrefix } from "../shared/prefix.ts";
3
4
 
4
5
  const LEADING_SLASHES_RE = /^\/+/;
5
6
  const TRAILING_SLASHES_RE = /\/+$/;
@@ -47,7 +48,7 @@ export function startStaticPreview({
47
48
  } catch {
48
49
  return notFound();
49
50
  }
50
- if (basePath && pathname !== basePath && !pathname.startsWith(`${basePath}/`)) {
51
+ if (!isWithinPrefix(pathname, basePath)) {
51
52
  return notFound();
52
53
  }
53
54
 
@@ -4,13 +4,10 @@ import { type ErrorComponent, getPublicErrorMessage } from "../shared/error.ts";
4
4
  import { isNotFoundError, type NotFoundComponent } from "../shared/not-found.ts";
5
5
  import { DefaultErrorFallback, DefaultNotFoundFallback } from "./default-screens.tsx";
6
6
  import { FurinDocumentFallback } from "./document.tsx";
7
- import { isFurinServerError } from "./server-error.ts";
8
7
 
9
8
  /**
10
- * Default HTTP status surfaced to error UIs when the caught error has no
11
- * intrinsic status (e.g. a thrown `Error`, a non-Error throw). The loader
12
- * pipeline produces a `FurinServerError` with the right status when a thrown
13
- * `Response` is the cause; everything else collapses to 500.
9
+ * HTTP status surfaced to error UIs for an error caught while rendering. Route
10
+ * failures with their own status are rendered from the route match instead.
14
11
  */
15
12
  const DEFAULT_ERROR_STATUS = 500;
16
13
 
@@ -19,9 +16,6 @@ const SERVER_RESET_NOOP = () => {
19
16
  };
20
17
 
21
18
  function getServerDigest(error: unknown): string | undefined {
22
- if (isFurinServerError(error)) {
23
- return error.digest;
24
- }
25
19
  if ((typeof error !== "object" && typeof error !== "function") || error === null) {
26
20
  return;
27
21
  }
@@ -108,7 +102,8 @@ export class FurinErrorBoundary extends Component<ErrorBoundaryProps, ErrorBound
108
102
  }
109
103
 
110
104
  override componentDidCatch(error: Error): void {
111
- if (import.meta.hot && typeof window !== "undefined") {
105
+ // Not `import.meta.hot`: Furin's own build would compile it out of `dist/`.
106
+ if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
112
107
  window.dispatchEvent(
113
108
  new CustomEvent("furin:client-error", {
114
109
  detail: { error, phase: "client-render" },
@@ -159,13 +154,9 @@ export class FurinErrorBoundary extends Component<ErrorBoundaryProps, ErrorBound
159
154
  const serverDigest = getServerDigest(error);
160
155
  const finalDigest = serverDigest ?? digest ?? this.props.digest ?? computeErrorDigest(error);
161
156
  const message = this.props.fallback ? error.message : getPublicErrorMessage(error);
162
- // Status precedence: FurinServerError carries the original Response.status
163
- // (or the loader's computed 500 for non-Response throws); everything else
164
- // collapses to the default 500.
165
- const status = isFurinServerError(error) ? error.status : DEFAULT_ERROR_STATUS;
166
157
  const fallback = (
167
158
  <Fallback
168
- error={{ digest: finalDigest, message, status }}
159
+ error={{ digest: finalDigest, message, status: DEFAULT_ERROR_STATUS }}
169
160
  reset={typeof window === "undefined" ? SERVER_RESET_NOOP : this.reset}
170
161
  />
171
162
  );
@@ -244,7 +244,7 @@ interface DefaultErrorScreenProps {
244
244
  reset: () => void;
245
245
  }
246
246
 
247
- export function DefaultErrorScreen({ message, digest, reset }: DefaultErrorScreenProps) {
247
+ function DefaultErrorScreen({ message, digest, reset }: DefaultErrorScreenProps) {
248
248
  return (
249
249
  // react-doctor-disable-next-line react-doctor/design-no-em-dash-in-jsx-text
250
250
  <ScreenFrame badge={<div style={BADGE_STYLE}>500 — ERROR</div>}>
@@ -274,7 +274,7 @@ interface DefaultNotFoundScreenProps {
274
274
  message: string | undefined;
275
275
  }
276
276
 
277
- export function DefaultNotFoundScreen({ message }: DefaultNotFoundScreenProps) {
277
+ function DefaultNotFoundScreen({ message }: DefaultNotFoundScreenProps) {
278
278
  return (
279
279
  // react-doctor-disable-next-line react-doctor/design-no-em-dash-in-jsx-text
280
280
  <ScreenFrame badge={<div style={BADGE_STYLE}>404 — NOT FOUND</div>}>
@@ -37,11 +37,12 @@ function createRouteBuilder(remountDeps: RemountDeps<never, never> | undefined)
37
37
  };
38
38
  }
39
39
 
40
- export function defineRoute() {
40
+ /** The file id of `defineRoute(id)` is type-only: the client ignores it. */
41
+ export function defineRoute(_id: string) {
41
42
  return createRouteBuilder(undefined);
42
43
  }
43
44
 
44
45
  /** Client stub for the root-layout builder — identical surface. */
45
46
  export function defineRootRoute() {
46
- return defineRoute();
47
+ return createRouteBuilder(undefined);
47
48
  }
package/src/client/hmr.ts CHANGED
@@ -4,7 +4,7 @@ import { jsx } from "react/jsx-runtime";
4
4
  type ClientComponent<Props> = (props: Props) => ReactNode;
5
5
  const HOT_COMPONENT_SIGNATURE = Symbol.for("furin.hmr.hook-signature");
6
6
 
7
- export interface HotComponentSlot {
7
+ interface HotComponentSlot {
8
8
  boundary: ClientComponent<never>;
9
9
  current: ClientComponent<never>;
10
10
  signature: string | undefined;
@@ -3,7 +3,13 @@ import type { HeadOptions, RenderingMode } from "../../client.ts";
3
3
  import type { RequestLoaderContext } from "../../define-route.ts";
4
4
  import type { RemountDeps } from "../../shared/page-key.ts";
5
5
 
6
- export type RuntimeData = Record<string, unknown>;
6
+ /**
7
+ * Loader data after type erasure: field name → value. Each route declares the
8
+ * real shape through `defineRoute`; the runtime only relies on string keys.
9
+ */
10
+ export interface RuntimeData {
11
+ [field: string]: unknown;
12
+ }
7
13
 
8
14
  type Awaitable<T> = Promise<T> | T;
9
15