@kayjs/kay 1.105.0 → 1.107.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 (467) hide show
  1. package/README.md +2 -2
  2. package/dist/eslint.js +777 -210
  3. package/editors/zed/extension.toml +2 -2
  4. package/llms/action-protection.md +2 -2
  5. package/llms/actions-from-islands.md +2 -2
  6. package/llms/actions-refused-fields.md +22 -0
  7. package/llms/actions.md +24 -41
  8. package/llms/analytics.md +1 -1
  9. package/llms/api-from-islands.md +1 -1
  10. package/llms/api-routes.md +6 -6
  11. package/llms/browser-only.md +1 -1
  12. package/llms/check-and-tools.md +1 -1
  13. package/llms/code-lints.md +2 -2
  14. package/llms/compiler-api.md +1 -1
  15. package/llms/component-libraries.md +1 -0
  16. package/llms/components.md +1 -1
  17. package/llms/content-cms.md +1 -1
  18. package/llms/content-markdown-to-caching.md +1 -1
  19. package/llms/content-preview.md +2 -2
  20. package/llms/content.md +21 -21
  21. package/llms/deprecated-lints-1-105-libraries.md +2 -0
  22. package/llms/deprecated-lints-1-105.md +3 -3
  23. package/llms/deprecated-lints.md +4 -4
  24. package/llms/dev-tool.md +2 -2
  25. package/llms/environment.md +22 -22
  26. package/llms/files.md +5 -5
  27. package/llms/island-and-form-lints.md +1 -0
  28. package/llms/islands-state-to-ids.md +2 -1
  29. package/llms/islands.md +10 -1
  30. package/llms/local-collections.md +2 -2
  31. package/llms/mcp.md +2 -1
  32. package/llms/navigation-from-code.md +1 -1
  33. package/llms/notifications.md +4 -2
  34. package/llms/project-new-and-add.md +1 -1
  35. package/llms/project.md +3 -3
  36. package/llms/rate-limits.md +1 -1
  37. package/llms/recipes.md +16 -16
  38. package/llms/rooms.md +4 -4
  39. package/llms/routing-endpoints-and-base.md +1 -1
  40. package/llms/routing.md +5 -5
  41. package/llms/schemas.md +14 -7
  42. package/llms/server.md +7 -7
  43. package/llms/site.md +9 -9
  44. package/llms/sitemap-search-fonts.md +2 -0
  45. package/llms/styles-and-assets.md +2 -1
  46. package/llms/templates-elements-slots-snippets.md +2 -2
  47. package/llms/testing-browser.md +20 -0
  48. package/llms/testing.md +1 -1
  49. package/llms/upgrading-1-105-config.md +2 -2
  50. package/llms/upgrading.md +37 -4
  51. package/llms/whats-new-archive.md +35 -66
  52. package/llms/whats-new.md +47 -28
  53. package/llms.txt +1 -1
  54. package/package.json +24 -11
  55. package/src/add.ts +1 -1
  56. package/src/build/class-table.ts +2 -2
  57. package/src/build/client.ts +27 -30
  58. package/src/build/entry-files.ts +19 -0
  59. package/src/build/lazy-components.ts +130 -0
  60. package/src/build/lazy-manifest.ts +56 -0
  61. package/src/build/lazy-stubs.ts +31 -0
  62. package/src/build/plugin.ts +16 -11
  63. package/src/build/runtime-chunk.ts +1 -1
  64. package/src/build/styles.ts +3 -3
  65. package/src/build/transform.ts +19 -7
  66. package/src/build/ui-layers.ts +30 -0
  67. package/src/build/ui.ts +108 -11
  68. package/src/build/variants.ts +125 -46
  69. package/src/build/worker-bundle.ts +6 -0
  70. package/src/check/action-options.ts +56 -0
  71. package/src/check/boot.ts +22 -1
  72. package/src/check/call-result.ts +242 -0
  73. package/src/check/config-objects.ts +17 -2
  74. package/src/check/diagnose.ts +22 -0
  75. package/src/check/handler-events.ts +149 -0
  76. package/src/check/index.ts +6 -2
  77. package/src/check/link-flag-tests.ts +130 -0
  78. package/src/check/project.ts +4 -3
  79. package/src/check/refusal-calls.ts +2 -2
  80. package/src/check/regroup.ts +5 -3
  81. package/src/check/renamed-packages.ts +58 -14
  82. package/src/check/schema-builders.ts +256 -0
  83. package/src/check/schema-json.ts +226 -0
  84. package/src/check/secret-keys.ts +15 -2
  85. package/src/check/shadow-types.ts +13 -9
  86. package/src/check/template-hints.ts +1 -1
  87. package/src/check/tool-labels.ts +11 -9
  88. package/src/check/ui-types.ts +4 -3
  89. package/src/check/ui.ts +14 -11
  90. package/src/commands/env-declare.ts +18 -6
  91. package/src/commands/routes.ts +1 -1
  92. package/src/compiler/a11y.ts +8 -1
  93. package/src/compiler/ast.ts +1 -1
  94. package/src/compiler/bound-props.ts +1 -1
  95. package/src/compiler/codegen.ts +13 -23
  96. package/src/compiler/deprecated-lints-1-105.ts +41 -0
  97. package/src/compiler/deprecated-lints-1-106.ts +14 -0
  98. package/src/compiler/deprecated-lints-1-107.ts +14 -0
  99. package/src/compiler/deprecated-lints.ts +17 -60
  100. package/src/compiler/deprecated-typed-lints.ts +23 -0
  101. package/src/compiler/dom-here.ts +72 -0
  102. package/src/compiler/dom.ts +23 -23
  103. package/src/compiler/fence-checks.ts +12 -11
  104. package/src/compiler/field-described.ts +2 -2
  105. package/src/compiler/helper-imports.ts +1 -1
  106. package/src/compiler/html-fields.ts +92 -0
  107. package/src/compiler/html-initial.ts +5 -3
  108. package/src/compiler/html.ts +14 -31
  109. package/src/compiler/import-edits.ts +15 -0
  110. package/src/compiler/index.ts +10 -3
  111. package/src/compiler/island-declaration.ts +15 -0
  112. package/src/compiler/items.ts +5 -5
  113. package/src/compiler/kay-exports.ts +1 -0
  114. package/src/compiler/lazy-imports.ts +357 -0
  115. package/src/compiler/link-flags.ts +6 -5
  116. package/src/compiler/lints.ts +12 -12
  117. package/src/compiler/parser.ts +2 -2
  118. package/src/compiler/rest-omits.ts +15 -0
  119. package/src/compiler/route-lints.ts +2 -0
  120. package/src/compiler/schema-lints.ts +13 -0
  121. package/src/compiler/script-server.ts +6 -3
  122. package/src/config-loader.ts +10 -2
  123. package/src/config-resolve.ts +3 -1
  124. package/src/config-shape.ts +2 -2
  125. package/src/config.ts +20 -4
  126. package/src/content/markdown.ts +2 -3
  127. package/src/content/validate.ts +1 -1
  128. package/src/generate-resource.ts +9 -9
  129. package/src/generate.ts +1 -1
  130. package/src/mcp/guards.ts +1 -1
  131. package/src/mcp/tools.ts +1 -1
  132. package/src/migrate/content.ts +61 -55
  133. package/src/new.ts +6 -2
  134. package/src/runtime/action-shared.ts +2 -2
  135. package/src/runtime/action.ts +51 -4
  136. package/src/runtime/client.ts +10 -0
  137. package/src/runtime/dom-lazy.ts +276 -0
  138. package/src/runtime/field-errors.ts +58 -0
  139. package/src/runtime/field-refusal.ts +179 -0
  140. package/src/runtime/form-types.ts +99 -0
  141. package/src/runtime/form.ts +25 -9
  142. package/src/runtime/html.ts +42 -6
  143. package/src/runtime/index.ts +2 -0
  144. package/src/runtime/island.server.ts +36 -2
  145. package/src/runtime/markdown-autolink.ts +69 -0
  146. package/src/runtime/markdown-render.client.ts +39 -3
  147. package/src/runtime/markdown.client.ts +6 -3
  148. package/src/runtime/markdown.server.ts +6 -3
  149. package/src/runtime/markdown.ts +125 -1
  150. package/src/runtime/navigate-api.ts +10 -5
  151. package/src/runtime/persist.ts +7 -7
  152. package/src/runtime/query-param.ts +1 -1
  153. package/src/runtime/reactive.ts +14 -0
  154. package/src/runtime/sanitize.ts +3 -1
  155. package/src/runtime/schema-record.ts +32 -0
  156. package/src/runtime/schema.client.ts +101 -14
  157. package/src/runtime/schema.ts +328 -26
  158. package/src/runtime/standard-schema.ts +32 -0
  159. package/src/runtime/swap-focus.ts +59 -11
  160. package/src/runtime/validate-run.client.ts +179 -0
  161. package/src/runtime/validate.client.ts +11 -0
  162. package/src/runtime/validate.ts +4 -137
  163. package/src/server/action-module.ts +16 -0
  164. package/src/server/actions.ts +54 -57
  165. package/src/server/answer.ts +102 -0
  166. package/src/server/api-input.ts +166 -0
  167. package/src/server/api-modules.ts +1 -1
  168. package/src/server/api.ts +12 -32
  169. package/src/server/app-stages.ts +38 -26
  170. package/src/server/app.ts +5 -2
  171. package/src/server/client.ts +2 -0
  172. package/src/server/dev-ui.ts +2 -2
  173. package/src/server/dev.ts +7 -9
  174. package/src/server/env-state.ts +1 -1
  175. package/src/server/env.ts +11 -3
  176. package/src/server/favicon.ts +47 -1
  177. package/src/server/file-limit.ts +7 -1
  178. package/src/server/forms.ts +1 -1
  179. package/src/server/host-allowlist.ts +7 -7
  180. package/src/server/image-metadata-bmff.ts +1 -1
  181. package/src/server/index.ts +2 -0
  182. package/src/server/kay-routes.ts +221 -0
  183. package/src/server/kay-server.ts +228 -0
  184. package/src/server/kept-exports.ts +1 -0
  185. package/src/server/kept-pages.ts +3 -3
  186. package/src/server/library.ts +2 -2
  187. package/src/server/mcp.ts +14 -13
  188. package/src/server/notifications.ts +4 -2
  189. package/src/server/offline.ts +24 -7
  190. package/src/server/openapi.ts +12 -3
  191. package/src/server/phases.ts +249 -0
  192. package/src/server/protection.ts +6 -6
  193. package/src/server/proxy-key.ts +8 -8
  194. package/src/server/push-settings.ts +16 -2
  195. package/src/server/push.ts +12 -4
  196. package/src/server/query.ts +17 -31
  197. package/src/server/receive.ts +43 -0
  198. package/src/server/render-document.ts +13 -3
  199. package/src/server/render.ts +1 -1
  200. package/src/server/request-context.ts +137 -0
  201. package/src/server/schema-check.ts +1 -1
  202. package/src/server/scope.ts +20 -13
  203. package/src/server/signals.ts +4 -4
  204. package/src/server/socket.ts +19 -47
  205. package/src/server/stream.ts +1 -1
  206. package/src/server/validate.ts +346 -0
  207. package/src/template-ws.ts +1 -1
  208. package/src/test/a11y-dom.ts +70 -0
  209. package/src/test/html-snapshot.ts +103 -0
  210. package/src/test/index.ts +2 -1
  211. package/src/test/mount.ts +14 -3
  212. package/src/test/page-checks.ts +12 -0
  213. package/src/test/screenshot-match.ts +2 -2
  214. package/src/test/shared-modules.ts +27 -5
  215. package/src/test/site-types.ts +5 -1
  216. package/types/build/class-table.d.ts +1 -1
  217. package/types/build/class-table.d.ts.map +1 -1
  218. package/types/build/client.d.ts +3 -2
  219. package/types/build/client.d.ts.map +1 -1
  220. package/types/build/entry-files.d.ts +4 -0
  221. package/types/build/entry-files.d.ts.map +1 -0
  222. package/types/build/lazy-components.d.ts +6 -0
  223. package/types/build/lazy-components.d.ts.map +1 -0
  224. package/types/build/lazy-manifest.d.ts +19 -0
  225. package/types/build/lazy-manifest.d.ts.map +1 -0
  226. package/types/build/lazy-stubs.d.ts +5 -0
  227. package/types/build/lazy-stubs.d.ts.map +1 -0
  228. package/types/build/plugin.d.ts +1 -0
  229. package/types/build/plugin.d.ts.map +1 -1
  230. package/types/build/transform.d.ts +4 -1
  231. package/types/build/transform.d.ts.map +1 -1
  232. package/types/build/ui-layers.d.ts +5 -0
  233. package/types/build/ui-layers.d.ts.map +1 -0
  234. package/types/build/ui.d.ts +7 -0
  235. package/types/build/ui.d.ts.map +1 -1
  236. package/types/build/variants.d.ts +1 -1
  237. package/types/build/variants.d.ts.map +1 -1
  238. package/types/build/worker-bundle.d.ts +1 -0
  239. package/types/build/worker-bundle.d.ts.map +1 -1
  240. package/types/check/action-options.d.ts +3 -0
  241. package/types/check/action-options.d.ts.map +1 -0
  242. package/types/check/boot.d.ts.map +1 -1
  243. package/types/check/call-result.d.ts +7 -0
  244. package/types/check/call-result.d.ts.map +1 -0
  245. package/types/check/config-objects.d.ts.map +1 -1
  246. package/types/check/diagnose.d.ts.map +1 -1
  247. package/types/check/handler-events.d.ts +9 -0
  248. package/types/check/handler-events.d.ts.map +1 -0
  249. package/types/check/index.d.ts +1 -0
  250. package/types/check/index.d.ts.map +1 -1
  251. package/types/check/link-flag-tests.d.ts +4 -0
  252. package/types/check/link-flag-tests.d.ts.map +1 -0
  253. package/types/check/project.d.ts.map +1 -1
  254. package/types/check/regroup.d.ts +1 -1
  255. package/types/check/regroup.d.ts.map +1 -1
  256. package/types/check/renamed-packages.d.ts +1 -0
  257. package/types/check/renamed-packages.d.ts.map +1 -1
  258. package/types/check/schema-builders.d.ts +3 -0
  259. package/types/check/schema-builders.d.ts.map +1 -0
  260. package/types/check/schema-json.d.ts +3 -0
  261. package/types/check/schema-json.d.ts.map +1 -0
  262. package/types/check/secret-keys.d.ts.map +1 -1
  263. package/types/check/shadow-types.d.ts.map +1 -1
  264. package/types/check/template-hints.d.ts +1 -0
  265. package/types/check/template-hints.d.ts.map +1 -1
  266. package/types/check/tool-labels.d.ts.map +1 -1
  267. package/types/check/ui-types.d.ts.map +1 -1
  268. package/types/check/ui.d.ts.map +1 -1
  269. package/types/commands/env-declare.d.ts.map +1 -1
  270. package/types/compiler/a11y.d.ts.map +1 -1
  271. package/types/compiler/bound-props.d.ts +1 -0
  272. package/types/compiler/bound-props.d.ts.map +1 -1
  273. package/types/compiler/codegen.d.ts +3 -0
  274. package/types/compiler/codegen.d.ts.map +1 -1
  275. package/types/compiler/deprecated-lints-1-105.d.ts +39 -0
  276. package/types/compiler/deprecated-lints-1-105.d.ts.map +1 -0
  277. package/types/compiler/deprecated-lints-1-106.d.ts +12 -0
  278. package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -0
  279. package/types/compiler/deprecated-lints-1-107.d.ts +12 -0
  280. package/types/compiler/deprecated-lints-1-107.d.ts.map +1 -0
  281. package/types/compiler/deprecated-lints.d.ts +41 -22
  282. package/types/compiler/deprecated-lints.d.ts.map +1 -1
  283. package/types/compiler/deprecated-typed-lints.d.ts +21 -0
  284. package/types/compiler/deprecated-typed-lints.d.ts.map +1 -0
  285. package/types/compiler/dom-here.d.ts +14 -0
  286. package/types/compiler/dom-here.d.ts.map +1 -0
  287. package/types/compiler/dom.d.ts +1 -0
  288. package/types/compiler/dom.d.ts.map +1 -1
  289. package/types/compiler/fence-checks.d.ts.map +1 -1
  290. package/types/compiler/field-described.d.ts +1 -1
  291. package/types/compiler/field-described.d.ts.map +1 -1
  292. package/types/compiler/html-fields.d.ts +19 -0
  293. package/types/compiler/html-fields.d.ts.map +1 -0
  294. package/types/compiler/html-initial.d.ts +3 -2
  295. package/types/compiler/html-initial.d.ts.map +1 -1
  296. package/types/compiler/html.d.ts.map +1 -1
  297. package/types/compiler/import-edits.d.ts +1 -0
  298. package/types/compiler/import-edits.d.ts.map +1 -1
  299. package/types/compiler/index.d.ts +3 -0
  300. package/types/compiler/index.d.ts.map +1 -1
  301. package/types/compiler/island-declaration.d.ts +5 -0
  302. package/types/compiler/island-declaration.d.ts.map +1 -1
  303. package/types/compiler/items.d.ts +4 -1
  304. package/types/compiler/items.d.ts.map +1 -1
  305. package/types/compiler/kay-exports.d.ts.map +1 -1
  306. package/types/compiler/lazy-imports.d.ts +33 -0
  307. package/types/compiler/lazy-imports.d.ts.map +1 -0
  308. package/types/compiler/link-flags.d.ts +6 -0
  309. package/types/compiler/link-flags.d.ts.map +1 -1
  310. package/types/compiler/lints.d.ts +61 -34
  311. package/types/compiler/lints.d.ts.map +1 -1
  312. package/types/compiler/rest-omits.d.ts +4 -0
  313. package/types/compiler/rest-omits.d.ts.map +1 -0
  314. package/types/compiler/route-lints.d.ts +8 -0
  315. package/types/compiler/route-lints.d.ts.map +1 -1
  316. package/types/compiler/schema-lints.d.ts +11 -0
  317. package/types/compiler/schema-lints.d.ts.map +1 -0
  318. package/types/compiler/script-server.d.ts.map +1 -1
  319. package/types/config-loader.d.ts.map +1 -1
  320. package/types/config-resolve.d.ts.map +1 -1
  321. package/types/config.d.ts +15 -2
  322. package/types/config.d.ts.map +1 -1
  323. package/types/content/markdown.d.ts.map +1 -1
  324. package/types/migrate/content.d.ts.map +1 -1
  325. package/types/new.d.ts +1 -0
  326. package/types/new.d.ts.map +1 -1
  327. package/types/runtime/action-shared.d.ts +1 -1
  328. package/types/runtime/action-shared.d.ts.map +1 -1
  329. package/types/runtime/action.d.ts +29 -1
  330. package/types/runtime/action.d.ts.map +1 -1
  331. package/types/runtime/client.d.ts.map +1 -1
  332. package/types/runtime/dom-lazy.d.ts +6 -0
  333. package/types/runtime/dom-lazy.d.ts.map +1 -0
  334. package/types/runtime/field-errors.d.ts +4 -0
  335. package/types/runtime/field-errors.d.ts.map +1 -0
  336. package/types/runtime/field-refusal.d.ts +37 -0
  337. package/types/runtime/field-refusal.d.ts.map +1 -0
  338. package/types/runtime/form-types.d.ts +6 -0
  339. package/types/runtime/form-types.d.ts.map +1 -0
  340. package/types/runtime/form.d.ts +4 -2
  341. package/types/runtime/form.d.ts.map +1 -1
  342. package/types/runtime/html.d.ts +3 -0
  343. package/types/runtime/html.d.ts.map +1 -1
  344. package/types/runtime/index.d.ts +2 -0
  345. package/types/runtime/index.d.ts.map +1 -1
  346. package/types/runtime/island.server.d.ts +2 -0
  347. package/types/runtime/island.server.d.ts.map +1 -1
  348. package/types/runtime/markdown-autolink.d.ts +11 -0
  349. package/types/runtime/markdown-autolink.d.ts.map +1 -0
  350. package/types/runtime/markdown-render.client.d.ts +2 -1
  351. package/types/runtime/markdown-render.client.d.ts.map +1 -1
  352. package/types/runtime/markdown.client.d.ts +3 -1
  353. package/types/runtime/markdown.client.d.ts.map +1 -1
  354. package/types/runtime/markdown.d.ts +11 -0
  355. package/types/runtime/markdown.d.ts.map +1 -1
  356. package/types/runtime/markdown.server.d.ts +3 -1
  357. package/types/runtime/markdown.server.d.ts.map +1 -1
  358. package/types/runtime/navigate-api.d.ts +1 -1
  359. package/types/runtime/navigate-api.d.ts.map +1 -1
  360. package/types/runtime/persist.d.ts +2 -2
  361. package/types/runtime/persist.d.ts.map +1 -1
  362. package/types/runtime/reactive.d.ts +3 -0
  363. package/types/runtime/reactive.d.ts.map +1 -1
  364. package/types/runtime/sanitize.d.ts.map +1 -1
  365. package/types/runtime/schema-record.d.ts +9 -0
  366. package/types/runtime/schema-record.d.ts.map +1 -0
  367. package/types/runtime/schema.client.d.ts.map +1 -1
  368. package/types/runtime/schema.d.ts +99 -10
  369. package/types/runtime/schema.d.ts.map +1 -1
  370. package/types/runtime/standard-schema.d.ts +37 -0
  371. package/types/runtime/standard-schema.d.ts.map +1 -0
  372. package/types/runtime/swap-focus.d.ts.map +1 -1
  373. package/types/runtime/validate-run.client.d.ts +4 -0
  374. package/types/runtime/validate-run.client.d.ts.map +1 -0
  375. package/types/runtime/validate.client.d.ts +4 -0
  376. package/types/runtime/validate.client.d.ts.map +1 -0
  377. package/types/runtime/validate.d.ts +1 -21
  378. package/types/runtime/validate.d.ts.map +1 -1
  379. package/types/server/action-module.d.ts +2 -0
  380. package/types/server/action-module.d.ts.map +1 -0
  381. package/types/server/actions.d.ts +1 -0
  382. package/types/server/actions.d.ts.map +1 -1
  383. package/types/server/answer.d.ts +6 -0
  384. package/types/server/answer.d.ts.map +1 -0
  385. package/types/server/api-input.d.ts +19 -0
  386. package/types/server/api-input.d.ts.map +1 -0
  387. package/types/server/api.d.ts.map +1 -1
  388. package/types/server/app-stages.d.ts +7 -3
  389. package/types/server/app-stages.d.ts.map +1 -1
  390. package/types/server/app.d.ts +2 -0
  391. package/types/server/app.d.ts.map +1 -1
  392. package/types/server/client.d.ts +1 -0
  393. package/types/server/client.d.ts.map +1 -1
  394. package/types/server/dev.d.ts +1 -1
  395. package/types/server/dev.d.ts.map +1 -1
  396. package/types/server/env-state.d.ts.map +1 -1
  397. package/types/server/env.d.ts +5 -1
  398. package/types/server/env.d.ts.map +1 -1
  399. package/types/server/favicon.d.ts +3 -1
  400. package/types/server/favicon.d.ts.map +1 -1
  401. package/types/server/file-limit.d.ts.map +1 -1
  402. package/types/server/host-allowlist.d.ts +3 -3
  403. package/types/server/host-allowlist.d.ts.map +1 -1
  404. package/types/server/index.d.ts +2 -0
  405. package/types/server/index.d.ts.map +1 -1
  406. package/types/server/kay-routes.d.ts +47 -0
  407. package/types/server/kay-routes.d.ts.map +1 -0
  408. package/types/server/kay-server.d.ts +25 -0
  409. package/types/server/kay-server.d.ts.map +1 -0
  410. package/types/server/kept-exports.d.ts.map +1 -1
  411. package/types/server/kept-pages.d.ts +1 -1
  412. package/types/server/kept-pages.d.ts.map +1 -1
  413. package/types/server/library.d.ts +2 -1
  414. package/types/server/library.d.ts.map +1 -1
  415. package/types/server/mcp.d.ts +1 -1
  416. package/types/server/mcp.d.ts.map +1 -1
  417. package/types/server/notifications.d.ts +2 -1
  418. package/types/server/notifications.d.ts.map +1 -1
  419. package/types/server/offline.d.ts.map +1 -1
  420. package/types/server/openapi.d.ts.map +1 -1
  421. package/types/server/phases.d.ts +36 -0
  422. package/types/server/phases.d.ts.map +1 -0
  423. package/types/server/protection.d.ts +3 -2
  424. package/types/server/protection.d.ts.map +1 -1
  425. package/types/server/proxy-key.d.ts +3 -3
  426. package/types/server/proxy-key.d.ts.map +1 -1
  427. package/types/server/push-settings.d.ts +1 -1
  428. package/types/server/push-settings.d.ts.map +1 -1
  429. package/types/server/push.d.ts +1 -0
  430. package/types/server/push.d.ts.map +1 -1
  431. package/types/server/query.d.ts.map +1 -1
  432. package/types/server/receive.d.ts +9 -0
  433. package/types/server/receive.d.ts.map +1 -0
  434. package/types/server/render-document.d.ts.map +1 -1
  435. package/types/server/request-context.d.ts +29 -0
  436. package/types/server/request-context.d.ts.map +1 -0
  437. package/types/server/schema-check.d.ts +1 -0
  438. package/types/server/schema-check.d.ts.map +1 -1
  439. package/types/server/scope.d.ts +1 -1
  440. package/types/server/scope.d.ts.map +1 -1
  441. package/types/server/socket.d.ts +3 -5
  442. package/types/server/socket.d.ts.map +1 -1
  443. package/types/server/validate.d.ts +26 -0
  444. package/types/server/validate.d.ts.map +1 -0
  445. package/types/test/a11y-dom.d.ts +20 -0
  446. package/types/test/a11y-dom.d.ts.map +1 -0
  447. package/types/test/html-snapshot.d.ts +4 -0
  448. package/types/test/html-snapshot.d.ts.map +1 -0
  449. package/types/test/index.d.ts.map +1 -1
  450. package/types/test/mount.d.ts +3 -0
  451. package/types/test/mount.d.ts.map +1 -1
  452. package/types/test/page-checks.d.ts +6 -0
  453. package/types/test/page-checks.d.ts.map +1 -0
  454. package/types/test/screenshot-match.d.ts +1 -1
  455. package/types/test/screenshot-match.d.ts.map +1 -1
  456. package/types/test/shared-modules.d.ts.map +1 -1
  457. package/types/test/site-types.d.ts +3 -1
  458. package/types/test/site-types.d.ts.map +1 -1
  459. package/src/check/schema-type.ts +0 -9
  460. package/src/compiler/deprecated-script-fence.ts +0 -26
  461. package/src/server/field-errors.ts +0 -136
  462. package/types/check/schema-type.d.ts +0 -3
  463. package/types/check/schema-type.d.ts.map +0 -1
  464. package/types/compiler/deprecated-script-fence.d.ts +0 -3
  465. package/types/compiler/deprecated-script-fence.d.ts.map +0 -1
  466. package/types/server/field-errors.d.ts +0 -6
  467. package/types/server/field-errors.d.ts.map +0 -1
@@ -0,0 +1,179 @@
1
+ import type { Issue, Refusal, Source, Validated, ValidateOptions } from '../server/validate'
2
+ import type { FieldRules } from './field-refusal'
3
+ import { errorText, ruleOf } from './field-errors'
4
+ import { issueOf } from './field-refusal'
5
+ import { formInput } from './form'
6
+ import { schemaOf } from './schema-record'
7
+ import { isStandardSchema, jsonSchemaOf } from './standard-schema'
8
+ import { wording } from './words.client'
9
+
10
+ export type { Issue, Refusal, Source, Validated, ValidateOptions }
11
+
12
+ type Node = Record<string, unknown> & FieldRules & { properties?: Record<string, Node>, required?: string[], additionalProperties?: unknown, items?: Node, default?: unknown }
13
+
14
+ const isNode = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value)
15
+
16
+ // A missing field takes its schema's `default`, a nested object's too.
17
+ function withDefaults(schema: Node, value: unknown): unknown {
18
+ if (!isNode(value) || schema.properties === undefined)
19
+ return value
20
+
21
+ const fields: Record<string, unknown> = { ...value }
22
+
23
+ for (const [name, field] of Object.entries(schema.properties)) {
24
+ if (fields[name] === undefined && field.default !== undefined && field.format !== 'binary')
25
+ fields[name] = structuredClone(field.default)
26
+ else if (fields[name] !== undefined)
27
+ fields[name] = withDefaults(field, fields[name])
28
+ }
29
+
30
+ return fields
31
+ }
32
+
33
+ // A form or a query posts text and a blank list is the empty one: the top-level fields are read as their schema expects, as the server reads them.
34
+ function readText(schema: Node, value: unknown, form: boolean, trim: boolean): unknown {
35
+ const input = isNode(value) ? { ...value } : {}
36
+
37
+ for (const [name, field] of Object.entries(schema.properties ?? {})) {
38
+ if (form && input[name] === '' && field.type === 'array')
39
+ input[name] = []
40
+ else if (form && input[name] === '' && field.default !== undefined && !schema.required?.includes(name))
41
+ delete input[name]
42
+ }
43
+
44
+ return formInput(schema as never, withDefaults(schema, input), form, form && trim)
45
+ }
46
+
47
+ const join = (path: string, step: string): string => path === '' ? step : `${path}.${step}`
48
+
49
+ function issue(path: string, key: Issue['key'], english: string, field: Node): Issue {
50
+ return { path, key, params: {}, message: errorText(field.error, ruleOf(key.slice('kay.invalid.'.length))) ?? wording(key, english) }
51
+ }
52
+
53
+ // Every place the value fails the schema, once each, down to the fields of nested objects and the items of lists.
54
+ function walk(field: Node, value: unknown, path: string, source: Source, issues: Issue[]): void {
55
+ if (value === undefined) {
56
+ issues.push(issue(path, 'kay.invalid.required', 'Expected required property', field))
57
+
58
+ return
59
+ }
60
+
61
+ // A file is read by its bytes on the server alone.
62
+ if (field.format === 'binary' || field.items?.format === 'binary')
63
+ return
64
+
65
+ if (field.anyOf?.some(member => member.type === 'object' || member.type === 'array')) {
66
+ const tries = field.anyOf.map((member) => {
67
+ const found: Issue[] = []
68
+
69
+ walk(member as Node, value, path, source, found)
70
+
71
+ return found
72
+ })
73
+
74
+ if (!tries.some(found => found.length === 0))
75
+ issues.push(issue(path, 'kay.invalid.type', 'Expected union value', field))
76
+
77
+ return
78
+ }
79
+
80
+ if (field.type === 'object' && field.anyOf === undefined) {
81
+ if (!isNode(value)) {
82
+ issues.push(issue(path, 'kay.invalid.type', 'Expected object', field))
83
+
84
+ return
85
+ }
86
+
87
+ const shape = field.properties ?? {}
88
+
89
+ for (const [name, member] of Object.entries(shape)) {
90
+ if (value[name] !== undefined)
91
+ walk(member, value[name], join(path, name), source, issues)
92
+ else if (field.required?.includes(name))
93
+ issues.push(issue(join(path, name), 'kay.invalid.required', 'Expected required property', member))
94
+ }
95
+
96
+ for (const [name, member] of Object.entries(value)) {
97
+ if (Object.hasOwn(shape, name))
98
+ continue
99
+
100
+ if (isNode(field.additionalProperties))
101
+ walk(field.additionalProperties, member, join(path, name), source, issues)
102
+ else if (field.additionalProperties === false)
103
+ issues.push(issue(join(path, name), 'kay.invalid.type', 'Unexpected property', field))
104
+ }
105
+
106
+ return
107
+ }
108
+
109
+ const found = issueOf(path, field, value)
110
+
111
+ if (found !== undefined) {
112
+ issues.push({ path, ...found })
113
+
114
+ return
115
+ }
116
+
117
+ if (field.type === 'array' && field.items !== undefined && Array.isArray(value)) {
118
+ for (const [index, item] of value.entries())
119
+ walk(field.items, item, join(path, String(index)), source, issues)
120
+ }
121
+ }
122
+
123
+ // What an object keeps of a value: a form's unknown top-level fields are dropped, as a browser posts controls the app does not own, and an object that opted into `extra: 'strip'` loses its unknown keys.
124
+ function stripped(schema: Node, value: unknown, dropUnknown = false): unknown {
125
+ if (Array.isArray(value))
126
+ return schema.items === undefined ? value : value.map(item => stripped(schema.items!, item))
127
+
128
+ if (!isNode(value) || schema.properties === undefined)
129
+ return value
130
+
131
+ const shape = schema.properties
132
+ const keep = schema['x-kay-extra'] !== 'strip' && !dropUnknown
133
+
134
+ return Object.fromEntries(Object.entries(value).filter(([name]) => keep || Object.hasOwn(shape, name)).map(([name, member]) => [name, Object.hasOwn(shape, name) ? stripped(shape[name]!, member) : member]))
135
+ }
136
+
137
+ const refused = (errors: Issue[]): Refusal => ({ errors, status: 422 })
138
+
139
+ interface StandardResult {
140
+ value?: unknown
141
+ issues?: readonly { message?: string, path?: unknown }[]
142
+ }
143
+
144
+ async function standard(schema: object, source: Source, value: unknown, trim: boolean): Promise<Validated> {
145
+ const rules = source === 'json' ? undefined : jsonSchemaOf(schema) as Node | undefined
146
+ const read = rules === undefined ? value : readText(rules, value, source !== 'env' && source !== 'params', trim)
147
+ const result = await (schema as { '~standard': { validate: (value: unknown) => StandardResult | Promise<StandardResult> } })['~standard'].validate(read)
148
+
149
+ if (result.issues === undefined)
150
+ return { value: result.value }
151
+
152
+ const seen = new Set<string>()
153
+ const errors: Issue[] = []
154
+
155
+ for (const found of result.issues) {
156
+ const path = Array.isArray(found.path) ? found.path.map(step => String(isNode(step) ? step.key : step)).join('.') : ''
157
+
158
+ if (!seen.has(path)) {
159
+ seen.add(path)
160
+ errors.push({ path, key: 'kay.invalid.type', params: {}, message: found.message ?? wording('kay.invalid.type', 'Invalid value') })
161
+ }
162
+ }
163
+
164
+ return refused(errors)
165
+ }
166
+
167
+ // The value a schema reads from `source`, or where and why it is refused: the server's `validate` in the browser, for a form before it posts or a row a local collection takes. A date stays its text, and a file is checked by the server alone, which reads its bytes; the messages are the page's locale.
168
+ export async function validate<Value = unknown>(schema: object, value: unknown, { source, trim = true }: ValidateOptions): Promise<Validated<Value>> {
169
+ if (isStandardSchema(schema))
170
+ return await standard(schema, source, value, trim) as Validated<Value>
171
+
172
+ const rules = schemaOf(schema as never) as unknown as Node
173
+ const read = stripped(rules, source === 'json' ? withDefaults(rules, value) : readText(rules, value, source !== 'env' && source !== 'params', trim), source === 'form')
174
+ const issues: Issue[] = []
175
+
176
+ walk(rules, read, '', source, issues)
177
+
178
+ return issues.length === 0 ? { value: read as Value } : refused(issues)
179
+ }
@@ -0,0 +1,11 @@
1
+ import type { Validated, ValidateOptions } from '../server/validate'
2
+
3
+ export type { Issue, Refusal, Source, Validated, ValidateOptions } from '../server/validate'
4
+
5
+ // The server's `validate` in the browser. The validator is a chunk of its own, loaded by the first call, so a page whose islands never call `validate` does not fetch it and one that does fetches it once.
6
+ // kept: free
7
+ export async function validate<Value = unknown>(schema: object, value: unknown, options: ValidateOptions): Promise<Validated<Value>> {
8
+ const { validate: run } = await import('./validate-run.client')
9
+
10
+ return run<Value>(schema, value, options)
11
+ }
@@ -1,47 +1,17 @@
1
1
  import type { TSchema } from 'elysia'
2
- import type { InvalidWord } from '../server/words'
3
- import { isEmail } from './email'
2
+ import type { FormRules } from './field-refusal'
3
+ import { fieldMessage } from './field-refusal'
4
4
  import { focusInvalid } from './focus'
5
- import { formInput, NUMERIC_FORMATS } from './form'
5
+ import { formInput } from './form'
6
6
  import { controlsOf } from './form-controls'
7
7
  import { markInvalid } from './invalid'
8
8
  import { ISLAND } from './markers'
9
9
  import { uid } from './uid'
10
- import { wording } from './words.client'
11
-
12
- // What the server sends of an action's schema, for the forms of a page to be checked before they post: the top-level fields, the keywords the browser checks, and their `error` messages.
13
- export interface FieldRules {
14
- type?: string | undefined
15
- format?: string | undefined
16
- pattern?: string | undefined
17
- minLength?: number | undefined
18
- maxLength?: number | undefined
19
- minimum?: number | undefined
20
- maximum?: number | undefined
21
- exclusiveMinimum?: number | undefined
22
- exclusiveMaximum?: number | undefined
23
- minItems?: number | undefined
24
- maxItems?: number | undefined
25
- const?: unknown | undefined
26
- items?: FieldRules | undefined
27
- anyOf?: FieldRules[] | undefined
28
- error?: string | undefined
29
- }
30
10
 
31
- export interface FormRules {
32
- properties: Record<string, FieldRules>
33
- required: string[]
34
- }
11
+ export type { FieldRules, FormRules } from './field-refusal'
35
12
 
36
13
  // The schemas of the actions a page's forms post to, by action path, in one JSON script of the page's head, and one more after each streamed block bringing forms the page lacked.
37
14
  export const FORMS_SCRIPT = 'script[data-kay-forms]'
38
- type Format = RegExp | ((value: string) => boolean)
39
-
40
- // The formats the browser checks too, as the server does (`email` is kay's own, the rest Elysia's); any other format is left to the server.
41
- const FORMATS: Record<string, Format> = {
42
- email: isEmail,
43
- uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,
44
- }
45
15
 
46
16
  // Checks a form against the schema of the action it posts to, as the server would, reporting each refused field with the message the server would give; true when it may post.
47
17
  export function checkForm(form: HTMLFormElement, action: string): boolean {
@@ -205,106 +175,3 @@ function controlOf(form: HTMLFormElement, name: string): HTMLInputElement | HTML
205
175
 
206
176
  return control instanceof HTMLInputElement || control instanceof HTMLSelectElement || control instanceof HTMLTextAreaElement ? control : undefined
207
177
  }
208
-
209
- function formatFails(format: Format | undefined, value: string): boolean {
210
- if (format === undefined)
211
- return false
212
-
213
- return typeof format === 'function' ? !format(value) : !format.test(value)
214
- }
215
-
216
- // The schema's own `error` for a refused field, else the `kay.invalid.*` text of the keyword it fails, which the server words the same way; a site without the key reads Elysia's English.
217
- function fieldMessage(name: string, field: FieldRules, value: unknown): string | undefined {
218
- const message = refusal(name, field, value)
219
-
220
- if (message !== undefined)
221
- return field.error ?? wording(message.kind, message.english, message.params)
222
-
223
- // An item is named by its index, as the server names it, and refused with its own `error`.
224
- return field.items && Array.isArray(value) ? value.map((item, index) => fieldMessage(`${name}.${index}`, field.items!, item)).find(found => found !== undefined) : undefined
225
- }
226
-
227
- // What a field's value fails: the `kay.invalid.*` key the server's refusal of it would use, the limit it names, and Elysia's own summary, which is its English.
228
- interface Refusal {
229
- kind: InvalidWord
230
- english: string
231
- params?: Record<string, string | number>
232
- }
233
-
234
- function typeRefusal(english: string): Refusal {
235
- return { kind: 'kay.invalid.type', english }
236
- }
237
-
238
- function refusal(name: string, field: FieldRules, value: unknown): Refusal | undefined {
239
- if (field.anyOf) {
240
- const bound = bounds(field, value)
241
-
242
- if (bound === undefined && field.anyOf.some(member => refusal(name, member, value) === undefined))
243
- return undefined
244
-
245
- // A union is summarized by its members, though a bound of its own gives the kind, as the server words it.
246
- return { kind: bound?.kind ?? 'kay.invalid.type', english: `Property '${name}' should be one of: ${field.anyOf.map(member => `'${member.format ?? member.type}'`).join(', ')}`, ...bound?.params && { params: bound.params } }
247
- }
248
-
249
- if (field.const !== undefined)
250
- return value === field.const ? undefined : typeRefusal(`Expected ${typeof field.const === 'string' ? `'${field.const}'` : String(field.const)}`)
251
-
252
- switch (field.type) {
253
- case 'string':
254
- if (typeof value !== 'string')
255
- return typeRefusal('Expected string')
256
-
257
- if (field.format !== undefined && NUMERIC_FORMATS.has(field.format))
258
- return typeRefusal('Expected string')
259
-
260
- if (field.minLength !== undefined && value.length < field.minLength)
261
- return { kind: value === '' && field.minLength === 1 ? 'kay.invalid.required' : 'kay.invalid.tooShort', english: `Expected string length greater or equal to ${field.minLength}`, params: { min: field.minLength } }
262
-
263
- if (field.maxLength !== undefined && value.length > field.maxLength)
264
- return { kind: 'kay.invalid.tooLong', english: `Expected string length less or equal to ${field.maxLength}`, params: { max: field.maxLength } }
265
-
266
- if (field.pattern !== undefined && !new RegExp(field.pattern).test(value))
267
- return { kind: 'kay.invalid.pattern', english: `Expected string to match '${field.pattern}'` }
268
-
269
- return field.format !== undefined && formatFails(FORMATS[field.format], value) ? { kind: 'kay.invalid.format', english: `Property '${name}' should be ${field.format}`, params: { format: field.format } } : undefined
270
- case 'number':
271
- case 'integer':
272
- if (typeof value !== 'number' || Number.isNaN(value))
273
- return typeRefusal(`Expected ${field.type}`)
274
-
275
- // A bound a number fails is worded before its type, as the server does.
276
- return bounds(field, value) ?? (field.type === 'integer' && !Number.isInteger(value) ? typeRefusal('Expected integer') : undefined)
277
- case 'boolean':
278
- return typeof value === 'boolean' ? undefined : typeRefusal('Expected boolean')
279
- case 'array':
280
- if (!Array.isArray(value))
281
- return typeRefusal('Expected array')
282
-
283
- if (field.minItems !== undefined && value.length < field.minItems)
284
- return { kind: 'kay.invalid.tooFewItems', english: `Expected array length to be greater or equal to ${field.minItems}`, params: { min: field.minItems } }
285
-
286
- return field.maxItems !== undefined && value.length > field.maxItems ? { kind: 'kay.invalid.tooManyItems', english: `Expected array length to be less or equal to ${field.maxItems}`, params: { max: field.maxItems } } : undefined
287
- case undefined:
288
- default:
289
- return undefined
290
- }
291
- }
292
-
293
- // An exclusive bound is worded as a type refusal, as the server does.
294
- function bounds(field: FieldRules, value: unknown): Refusal | undefined {
295
- if (typeof value !== 'number')
296
- return undefined
297
-
298
- const type = field.type ?? 'number'
299
-
300
- if (field.minimum !== undefined && value < field.minimum)
301
- return { kind: 'kay.invalid.tooSmall', english: `Expected ${type} to be greater or equal to ${field.minimum}`, params: { min: field.minimum } }
302
-
303
- if (field.maximum !== undefined && value > field.maximum)
304
- return { kind: 'kay.invalid.tooBig', english: `Expected ${type} to be less or equal to ${field.maximum}`, params: { max: field.maximum } }
305
-
306
- if (field.exclusiveMinimum !== undefined && value <= field.exclusiveMinimum)
307
- return typeRefusal(`Expected ${type} to be greater than ${field.exclusiveMinimum}`)
308
-
309
- return field.exclusiveMaximum !== undefined && value >= field.exclusiveMaximum ? typeRefusal(`Expected ${type} to be less than ${field.exclusiveMaximum}`) : undefined
310
- }
@@ -0,0 +1,16 @@
1
+ import { importModule } from './bundle'
2
+
3
+ // The exports of a page file. With `skipBroken`, a file that fails to compile has none, and its failure goes into `broken` for the checks naming one of its actions.
4
+ export async function actionModule(file: string, skipBroken: boolean | undefined, broken: Map<string, string>): Promise<Record<string, unknown>> {
5
+ try {
6
+ return await importModule<Record<string, unknown>>(file)
7
+ }
8
+ catch (error) {
9
+ if (skipBroken !== true || !(error instanceof Error) || error.name !== 'KayCompileError')
10
+ throw error
11
+
12
+ broken.set(file, error.message)
13
+
14
+ return {}
15
+ }
16
+ }
@@ -1,5 +1,5 @@
1
1
  import type { CookieMap } from 'bun'
2
- import type { Elysia, TSchema, ValidationError } from 'elysia'
2
+ import type { Elysia, TSchema } from 'elysia'
3
3
  import type { Server } from 'elysia/universal'
4
4
  import type { ActionsConfig } from '../config'
5
5
  import type { GuardContext, Locals, RouteParams } from '../runtime'
@@ -18,16 +18,17 @@ import type { I18n } from './i18n'
18
18
  import type { DocumentedAction } from './openapi'
19
19
  import type { Unmatched } from './page-routes'
20
20
  import type { ToolOutputs } from './tool-outputs'
21
+ import type { Source } from './validate'
21
22
  import { relative } from 'node:path'
22
23
  import { KayError } from '../compiler/errors'
23
- import { decodeCall, failure, FORM_CALL, FORM_FIELD, isAction, isFailure, protectionFields } from '../runtime/action'
24
+ import { decodeCall, failure, FORM_CALL, FORM_FIELD, honeypotField, isAction, isFailure, protectionFields, STAMP_FIELD } from '../runtime/action'
24
25
  import { joinBase } from '../runtime/base'
25
26
  import { escapeAttribute } from '../runtime/escape'
26
- import { formInput } from '../runtime/form'
27
27
  import { localeState, runInLocale } from '../runtime/locale-state'
28
28
  import { thrownRefusal } from '../runtime/refuse'
29
29
  import { withDefaultBounds } from '../runtime/schema-bounds'
30
30
  import { sizeText } from '../runtime/size-text'
31
+ import { isStandardSchema } from '../runtime/standard-schema'
31
32
  import { FAILURE_HEADER, NAVIGATE_HEADER, PAGE_HEADER, REDIRECT_HEADER } from '../runtime/swap'
32
33
  import { ACTION_PREFIX, encodeValue, FIELDS_PREFIX, unsendable } from '../runtime/wire'
33
34
  import { pageLocale } from '../runtime/words.server'
@@ -35,12 +36,11 @@ import { actionClash } from './action-clash'
35
36
  import { hooksOf, refusedBeforeRun, tellError, tellSuccess, withActionDefaults } from './action-hooks'
36
37
  import { withFixedFields, withoutEmptyFiles } from './action-input'
37
38
  import { gathering, isAsyncIterable, lastOf, started, streamed } from './action-iterable'
39
+ import { actionModule } from './action-module'
38
40
  import { routerPath } from './base'
39
- import { importModule } from './bundle'
40
41
  import { timeoutMs } from './config-limits'
41
42
  import { cookieJar } from './cookies'
42
43
  import { BACK_PARAMETER, crossSiteResponse, isCrossSite, postedFrom, TEXT } from './cross-site'
43
- import { fieldMessage, refusedFields, validated } from './field-errors'
44
44
  import { fileBodyLimit } from './file-limit'
45
45
  import { handOver, submittedValues, writeSuccess } from './flash'
46
46
  import { requiredGuards, runGuards, unguarded } from './guards'
@@ -61,6 +61,7 @@ import { carryContext } from './security'
61
61
  import { actionStoppers, Denied, NotFound, Redirect, stoppers } from './signals'
62
62
  import { toolSettings } from './tool-settings'
63
63
  import { answered, replyTrace, SERVER_SPAN, traced } from './trace'
64
+ import { isRefusal, messagesOf, validate } from './validate'
64
65
  import { visitAs } from './visit'
65
66
  import { kayWord } from './words'
66
67
  import { onceWritten } from './writes'
@@ -94,9 +95,6 @@ const HEAD_START = /<head\b[^>]*>/i
94
95
  // The `action` of a form posting to an action, the site's `base` before it if any.
95
96
  const FORM_ACTION = /(<form\b[^>]*?\saction=")([^"]*\/_kay\/action\/[^"#]*)/gi
96
97
 
97
- // Elysia names a file it refuses `body.<field>`.
98
- const BODY_PREFIX = /^body\./
99
-
100
98
  export interface ActionOptions {
101
99
  // Shows a failed action's message instead of a generic one.
102
100
  dev?: boolean | undefined
@@ -138,29 +136,22 @@ type Back = (request: Request, headers: Headers, flash: Flash, server: Server |
138
136
  const pageBound = new WeakMap<object, boolean>()
139
137
 
140
138
  // Registers every action the pages and layouts export as a POST route whose body Elysia validates against the action's schema, giving back the body limit of each by its path and the actions that opted in to being MCP tools.
141
- export async function registerActionRoutes(app: Elysia, routes: ServedRoute[], match: RouteMatch, options: ActionOptions): Promise<{ limits: Map<string, BodyLimit>, tools: DocumentedAction[] }> {
139
+ export async function registerActionRoutes(app: Elysia, routes: ServedRoute[], match: RouteMatch, options: ActionOptions): Promise<{ limits: Map<string, BodyLimit>, tools: DocumentedAction[], broken: Map<string, string> }> {
142
140
  const back: Back = async (request, headers, flash, server) => renderBack(app, options.base ?? '', request, headers, flash, server)
143
141
  const served = new Map<string, { file: string, action: ServerAction<TSchema, unknown> }>()
144
142
  const limits = new Map<string, BodyLimit>()
145
143
  const tools: DocumentedAction[] = []
144
+ // The files `skipBroken` passed over, with why.
145
+ const broken = new Map<string, string>()
146
146
 
147
147
  for (const [file, { guards, ...page }] of actionFiles(routes, options.requireGuards)) {
148
- let module: Record<string, unknown> = {}
149
-
150
- try {
151
- module = await importModule<Record<string, unknown>>(file)
152
- }
153
- catch (error) {
154
- if (options.skipBroken !== true || !(error instanceof Error) || error.name !== 'KayCompileError')
155
- throw error
156
- }
157
-
158
- for (const [name, exported] of Object.entries(module)) {
148
+ for (const [name, exported] of Object.entries(await actionModule(file, options.skipBroken, broken))) {
159
149
  if (!isAction(exported))
160
150
  continue
161
151
 
162
152
  // Every string field with no bound of its own takes the default, for the route's validation, the form's `maxlength` and the tool's schema alike.
163
- Object.assign(exported, { schema: withDefaultBounds(exported.schema) })
153
+ if (!isStandardSchema(exported.schema))
154
+ Object.assign(exported, { schema: withDefaultBounds(exported.schema) })
164
155
 
165
156
  const taken = served.get(exported.url)
166
157
 
@@ -208,7 +199,6 @@ export async function registerActionRoutes(app: Elysia, routes: ServedRoute[], m
208
199
 
209
200
  return carryContext(context.set, response)
210
201
  }, context.request), {
211
- body: validated(value.schema),
212
202
  transform: async (context) => {
213
203
  refuseCrossSite(context.request)
214
204
 
@@ -234,36 +224,37 @@ export async function registerActionRoutes(app: Elysia, routes: ServedRoute[], m
234
224
  if (typeof form === 'string')
235
225
  requestRecord(context.request).postedForm = form
236
226
 
237
- context.body = asForm ? formInput(value.schema, withFixedFields(withoutEmptyFiles(context.body), context.request)) : callInput(context.body)
227
+ context.body = asForm ? withFixedFields(withoutEmptyFiles(context.body), context.request) : callInput(context.body)
238
228
  },
239
- // After validation, the one stage where the app's `resolve` values are there for `ctx.locals`.
240
- ...(guards.length > 0 && {
241
- beforeHandle: async (context: { request: Request }) => {
242
- const { pageParams = {}, pageUrl } = requestRecord(context.request)
243
-
244
- return inLocale(context.request, options, async () => admit(guards, sharedContext(context.request, () => ({ ...context })), pageParams, pageUrl, options))
245
- },
246
- }),
247
- error: async (context) => {
248
- const { code, error, request, body, server, set } = context
229
+ // The guards first, so a caller they refuse learns nothing of the input, then the input against the schema: the handler reads the value it reads.
230
+ beforeHandle: async (context: { request: Request, body: unknown, server: Server | null }) => {
231
+ const { pageParams = {}, pageUrl } = requestRecord(context.request)
232
+ const { request } = context
233
+
234
+ return inLocale(request, options, async () => {
235
+ if (guards.length > 0) {
236
+ const refusal = await admit(guards, sharedContext(request, () => ({ ...context })), pageParams, pageUrl, options)
249
237
 
250
- if ((code === 'VALIDATION' || code === 'INVALID_FILE_TYPE') && guards.length > 0) {
251
- const { pageParams = {}, pageUrl } = requestRecord(request)
252
- const refusal = await inLocale(request, options, async () => guardsFirst(guards, sharedContext(request, () => ({ ...context })), pageParams, pageUrl, options))
238
+ if (refusal)
239
+ return refusal
240
+ }
253
241
 
254
- if (refusal)
255
- return refusal
256
- }
242
+ // A call with no input posts no body, which an object schema reads as no fields.
243
+ const posted = context.body === undefined && (value.schema as { type?: string }).type === 'object' ? {} : context.body
244
+ const result = await validate(value.schema, isCall(request) && !isFormCall(request) ? posted : withoutKayFields(posted, value), { source: sourceOfCall(request) })
257
245
 
258
- if (code === 'VALIDATION')
259
- return inLocale(request, options, async () => refused(value, error, request, server, back))
246
+ if (isRefusal(result))
247
+ return failed(request, new Headers(), cookieJar(request).cookies, { action: value.url, status: 422, values: isCall(request) ? {} : submittedValues(posted), errors: messagesOf(result.errors) }, context.server, back)
260
248
 
261
- // Elysia checks a top-level `s.File({ type })` against the file's bytes once the schema passed.
262
- if (code === 'INVALID_FILE_TYPE') {
263
- const field = error.property.replace(BODY_PREFIX, '')
249
+ // The copy the guards were handed is the one the handler is run with.
250
+ context.body = result.value
251
+ sharedContext(request, () => ({ ...context })).body = result.value
264
252
 
265
- return inLocale(request, options, async () => failed(request, new Headers(), cookieJar(request).cookies, { action: value.url, status: 422, values: submittedValues(body), errors: { [field]: fieldError(value, field) ?? kayWord('kay.action.invalidFile') } }, server, back))
266
- }
253
+ return undefined
254
+ })
255
+ },
256
+ error: async (context) => {
257
+ const { error, set } = context
267
258
 
268
259
  // Read as unknown: some apps' Elysia types narrow the error to an intersection holding `number`.
269
260
  const refusal: unknown = error
@@ -282,7 +273,7 @@ export async function registerActionRoutes(app: Elysia, routes: ServedRoute[], m
282
273
  }
283
274
  }
284
275
 
285
- return { limits, tools }
276
+ return { limits, tools, broken }
286
277
  }
287
278
 
288
279
  // Runs the action under its timeout; one that ran out is reported as a server error and answered as a failed post, 504.
@@ -444,9 +435,14 @@ function callInput(body: unknown): unknown {
444
435
  }
445
436
  }
446
437
 
447
- // The `error` option the schema gives a top-level field, read in the request's locale.
448
- function fieldError(action: ServerAction<TSchema, unknown>, field: string): string | undefined {
449
- return fieldMessage(action.schema, `/${field}`)
438
+ // The post without the fields kay adds to a form itself, which the schema never names: the form it came from, the stamp `minTime` reads and the honeypot.
439
+ function withoutKayFields(body: unknown, action: ServerAction<TSchema, unknown>): unknown {
440
+ if (typeof body !== 'object' || body === null || Array.isArray(body))
441
+ return body
442
+
443
+ const honeypot = honeypotField(action.protection)
444
+
445
+ return Object.fromEntries(Object.entries(body).filter(([name]) => name !== FORM_FIELD && name !== STAMP_FIELD && name !== honeypot))
450
446
  }
451
447
 
452
448
  // Browsers send `Origin` on every POST, so a form another site submits on the user's behalf is refused before anything else runs.
@@ -780,13 +776,6 @@ function encodeOrExplain(value: unknown, what: string): string {
780
776
  }
781
777
  }
782
778
 
783
- // Input the schema refused: a message per field, the schema's own `error` when it has one, a function `error` called in the request's locale.
784
- async function refused(action: ServerAction<TSchema, unknown>, error: Readonly<ValidationError>, request: Request, server: Server | null, back: Back): Promise<Response> {
785
- const errors = refusedFields(action.schema, error)
786
-
787
- return failed(request, new Headers(), cookieJar(request).cookies, { action: action.url, status: 422, values: submittedValues(error.value), errors }, server, back)
788
- }
789
-
790
779
  // A call gets the failure as JSON; a plain form post gets the page it came from, rendered with the failure.
791
780
  async function failed(request: Request, headers: Headers, cookies: CookieMap, flash: Flash, server: Server | null, back: Back): Promise<Response> {
792
781
  for (const cookie of cookies.toSetCookieHeaders())
@@ -885,3 +874,11 @@ function visitHeaders(request: Request): Headers {
885
874
  function redirectHeader(request: Request): string {
886
875
  return isCall(request) || request.headers.get(NAVIGATE_HEADER) === '1' ? REDIRECT_HEADER : 'location'
887
876
  }
877
+
878
+ // A call's JSON keeps its types, except one from an MCP client, whose arguments may be the text of a number or a boolean as a form's are.
879
+ function sourceOfCall(request: Request): Source {
880
+ if (!isCall(request) || isFormCall(request))
881
+ return 'form'
882
+
883
+ return request.headers.get('x-kay-tool') === '1' ? 'query' : 'json'
884
+ }