@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,357 @@
1
+ import type { ElementNode, KayFile, Node, Span } from './ast'
2
+ import type { ImportBinding } from './script-shared'
3
+ import { serverIslandOf, visitNodes } from './ast'
4
+ import { helperName } from './markup'
5
+
6
+ // What the build knows of a `.kay` module a component imports: the key its chunk is named by, and the props it draws only inside a branch that may not render, as a closed dialog does its children.
7
+ export interface ImportedComponent {
8
+ key: string
9
+ // `children` for the lines between its tags, else the name of a `@block`.
10
+ deferred: readonly string[]
11
+ // The size of its source, as a component under `LAZY_FLOOR` costs more as a chunk than it weighs.
12
+ size: number
13
+ // The keys of the components loaded with it: its own, and those its imports draw outside any branch that may not render, which a module importing it already holds.
14
+ reach: readonly string[]
15
+ }
16
+
17
+ // The imported components of a file, by the specifier it imports them with.
18
+ export type ImportedComponents = Readonly<Record<string, ImportedComponent>>
19
+
20
+ // A component loaded the first time it draws, with the key that names its chunk.
21
+ export interface LazyImport {
22
+ key: string
23
+ specifier: string
24
+ declaration: { start: number, end: number }
25
+ }
26
+
27
+ // The smallest source a component loads lazily: below it the request and the stub cost more than the code saves.
28
+ export const LAZY_FLOOR = 2000
29
+ const CHILDREN = 'children'
30
+ const LINE_COMMENT = /^[ \t]*\/\/.*$/
31
+ const PLAIN_STRING = /'(?:[^'\\\n$`]|\\.)*'|"(?:[^"\\\n$`]|\\.)*"/g
32
+ // A line where a quote may open something other than a string: a template literal, or a regular expression, which starts where a value is expected.
33
+ const UNSURE_LINE = /`|[(,=:?!&|{;[]\s*\/(?![/*])/
34
+ // An import of a component's default export on a line of its own, the one form a lazy import can replace.
35
+ const PLAIN_IMPORT = /^import\s+[\w$]+\s+from\s*(['"])[^'"]+\1\s*;?$/
36
+
37
+ // How often a name is written as a word of the text, as `codeOf` leaves it: a count the tag uses do not account for is another reference to it.
38
+ function occurrences(text: string, name: string): number {
39
+ return text.match(new RegExp(`(?<![\\w$.])${name.replaceAll('$', '\\$')}(?![\\w$])`, 'g'))?.length ?? 0
40
+ }
41
+
42
+ // Whether the script names a prop other than as a string or a type's optional member, as `Omit<Props, 'children'>` or `children?: Snippet` do: any other mention may read it.
43
+ function reads(code: string, name: string): boolean {
44
+ return new RegExp(`(?<![\\w$'"])${name}(?![\\w$'"])(?!\\?:)`).test(code)
45
+ }
46
+
47
+ // Walks a template noting where each component call and each `slot` stands: in a branch that may not render (an `if` or `match` branch, a `catch`) or in a block a component draws only inside such a branch, which is `deferred`. The lines of a `snippet` stay where they are written, as it is drawn where it is called.
48
+ class Positions {
49
+ // How many repeated blocks, a loop body or a block of a function of a row, enclose the node being walked: a branch inside one is drawn by most pages, so it is no reason to split a component off.
50
+ private repeating = 0
51
+
52
+ constructor(private readonly source: string, private readonly deferring: (element: ElementNode) => readonly string[], private visit: { use?: (element: ElementNode, deferred: boolean) => void, outlet?: (element: ElementNode, deferred: boolean) => void }) {}
53
+
54
+ // An `if` with an `else` or a `match` with a default always draws one of its branches: a name written in each of them is drawn at first paint, one missing from some may not be.
55
+ private exhaustive(branches: readonly (readonly Node[])[], deferred: boolean): void {
56
+ const real = this.visit
57
+ const calls = branches.map((children) => {
58
+ const seen: { name: string, element: ElementNode, deferred: boolean, outlet: boolean }[] = []
59
+
60
+ this.visit = {
61
+ use: (element, inner) => seen.push({ name: element.name, element, deferred: inner, outlet: false }),
62
+ outlet: (element, inner) => seen.push({ name: element.outlet ? this.source.slice(element.outlet.name.start, element.outlet.name.end) : CHILDREN, element, deferred: inner, outlet: true }),
63
+ }
64
+ this.walk(children, deferred)
65
+
66
+ return seen
67
+ })
68
+
69
+ this.visit = real
70
+
71
+ const keyOf = (call: { name: string, outlet: boolean }) => `${call.outlet}:${call.name}`
72
+ const everywhere = calls.map(seen => new Set(seen.map(keyOf)))
73
+
74
+ for (const call of calls.flat()) {
75
+ const always = everywhere.every(names => names.has(keyOf(call)))
76
+
77
+ if (call.outlet)
78
+ real.outlet?.(call.element, call.deferred || (!always && this.repeating === 0))
79
+ else
80
+ real.use?.(call.element, call.deferred || (!always && this.repeating === 0))
81
+ }
82
+ }
83
+
84
+ walk(nodes: readonly Node[], deferred: boolean): void {
85
+ for (const node of nodes) {
86
+ switch (node.kind) {
87
+ case 'element':
88
+ this.element(node, deferred)
89
+
90
+ break
91
+ case 'if':
92
+ if (node.fallback) {
93
+ this.exhaustive([...node.branches.map(branch => branch.children), node.fallback.children], deferred)
94
+
95
+ break
96
+ }
97
+
98
+ for (const branch of node.branches)
99
+ this.walk(branch.children, deferred || this.repeating === 0)
100
+
101
+ break
102
+ case 'match':
103
+ if (node.fallback) {
104
+ this.exhaustive([...node.cases.map(branch => branch.children), node.fallback.children], deferred)
105
+
106
+ break
107
+ }
108
+
109
+ for (const branch of node.cases)
110
+ this.walk(branch.children, deferred || this.repeating === 0)
111
+
112
+ break
113
+ case 'for':
114
+ this.repeating++
115
+ this.walk(node.children, deferred)
116
+ this.repeating--
117
+ this.walk(node.fallback ?? [], deferred)
118
+
119
+ break
120
+ case 'await':
121
+ this.walk(node.pending, deferred)
122
+ this.walk(node.resolved?.children ?? [], deferred)
123
+ this.walk(node.rejected?.children ?? [], true)
124
+
125
+ break
126
+ case 'try':
127
+ this.walk(node.children, deferred)
128
+ this.walk(node.rejected?.children ?? [], true)
129
+
130
+ break
131
+ case 'text':
132
+ this.walk(node.parts.filter(part => part.kind === 'element'), deferred)
133
+
134
+ break
135
+ case 'slot':
136
+ case 'snippet':
137
+ case 'pending':
138
+ this.walk(node.children, deferred)
139
+
140
+ break
141
+ case 'const':
142
+ case 'error':
143
+ break
144
+ }
145
+ }
146
+ }
147
+
148
+ private element(element: ElementNode, deferred: boolean): void {
149
+ if (element.component)
150
+ this.visit.use?.(element, deferred)
151
+ else if (element.name === 'slot')
152
+ this.visit.outlet?.(element, deferred)
153
+
154
+ const props = element.component ? this.deferring(element) : []
155
+
156
+ for (const child of element.children) {
157
+ const own = child.kind === 'slot' ? this.source.slice(child.name.start, child.name.end) : CHILDREN
158
+
159
+ const repeated = child.kind === 'slot' && child.params !== undefined
160
+
161
+ this.repeating += repeated ? 1 : 0
162
+ this.walk(child.kind === 'slot' ? child.children : [child], deferred || props.includes(own))
163
+ this.repeating -= repeated ? 1 : 0
164
+ }
165
+ }
166
+ }
167
+
168
+ // The file with the text and the quoted attribute values of its template blanked, so what is left is code: a word naming a component is no reference when it is only written in a sentence.
169
+ function codeOf(file: KayFile): string {
170
+ const blanks: Span[] = []
171
+
172
+ visitNodes(file.template, (node) => {
173
+ if (node.kind === 'text')
174
+ blanks.push(...node.parts.filter(part => part.kind === 'chunk'))
175
+ else if (node.kind === 'element')
176
+ blanks.push(...node.attributes.flatMap(attribute => attribute.kind === 'static' ? [attribute.value] : []))
177
+ })
178
+
179
+ let code = file.source
180
+
181
+ for (const { start, end } of blanks)
182
+ code = `${code.slice(0, start)}${' '.repeat(end - start)}${code.slice(end)}`
183
+
184
+ return blankLiterals(code)
185
+ }
186
+
187
+ // The whole-line comments and the one-line strings that hold no `${`, blanked: a word in them, as the `Select all` of a label, is text no code reads, so it is no reference to a component of that name. A line that may hold a template literal or a regular expression is left as it is, since a quote there may pair with another that is no string's, and a word hidden by mistake would load a component lazily that code reads.
188
+ function blankLiterals(code: string): string {
189
+ const blank = (text: string) => ' '.repeat(text.length)
190
+
191
+ return code.split('\n').map((line) => {
192
+ if (LINE_COMMENT.test(line))
193
+ return blank(line)
194
+
195
+ return UNSURE_LINE.test(line) ? line : line.replace(PLAIN_STRING, blank)
196
+ }).join('\n')
197
+ }
198
+
199
+ // The text before a file's template, which is all of its script.
200
+ function fences(file: KayFile): string {
201
+ return file.source.slice(0, file.templateStart)
202
+ }
203
+
204
+ // The props of a component it draws only where some of its own branches may not render, so what a use hands it for them is not drawn when they do not.
205
+ // A name its script mentions is left out, as it may read the prop itself.
206
+ export function deferredProps(file: KayFile, imports: readonly ImportBinding[], known: (specifier: string) => ImportedComponent | undefined): string[] {
207
+ const specifiers = new Map(imports.filter(binding => binding.imported === 'default' && !binding.typeOnly).map(binding => [binding.local, binding.source]))
208
+ const drawn = new Map<string, boolean>()
209
+ const code = fences(file)
210
+
211
+ new Positions(file.source, (element) => {
212
+ const specifier = specifiers.get(element.name)
213
+
214
+ return specifier === undefined ? [] : known(specifier)?.deferred ?? []
215
+ }, {
216
+ outlet(element, deferred) {
217
+ const name = element.outlet ? file.source.slice(element.outlet.name.start, element.outlet.name.end) : CHILDREN
218
+
219
+ drawn.set(name, (drawn.get(name) ?? true) && deferred)
220
+ },
221
+ }).walk(file.template, false)
222
+
223
+ return [...drawn].filter(([name, deferred]) => deferred && !reads(code, name)).map(([name]) => name)
224
+ }
225
+
226
+ // The default imports of a component's script that draw only in branches that may not render, so their code loads when one does.
227
+ // An import is left alone when anything but a tag names it, as its value is then read at once, and when a call of it is a server island or a dynamic tag.
228
+ export function lazyImports(file: KayFile, imports: readonly ImportBinding[], known: ImportedComponents): Map<string, LazyImport> {
229
+ const found = positionsLazy(file, imports, known)
230
+
231
+ // A component another import of the file brings along as it loads is no chunk worth a request: dropping one adds what it brings, so the check goes on until nothing changes.
232
+ for (let changed = found.size > 0; changed;) {
233
+ const held = new Set(eagerReach(imports, known, found))
234
+
235
+ changed = false
236
+
237
+ for (const [local, lazy] of found) {
238
+ if (held.has(lazy.key)) {
239
+ found.delete(local)
240
+ changed = true
241
+ }
242
+ }
243
+ }
244
+
245
+ return found
246
+ }
247
+
248
+ // The keys the file loads as it loads: those of the components it imports other than lazily, and what each of them brings.
249
+ export function eagerReach(imports: readonly ImportBinding[], known: ImportedComponents, lazy: ReadonlyMap<string, LazyImport>): string[] {
250
+ const reach = new Set<string>()
251
+
252
+ for (const binding of imports) {
253
+ const component = binding.imported === 'default' && !binding.typeOnly ? known[binding.source] : undefined
254
+
255
+ if (component && !lazy.has(binding.local)) {
256
+ reach.add(component.key)
257
+
258
+ for (const key of component.reach)
259
+ reach.add(key)
260
+ }
261
+ }
262
+
263
+ return [...reach]
264
+ }
265
+
266
+ function positionsLazy(file: KayFile, imports: readonly ImportBinding[], known: ImportedComponents): Map<string, LazyImport> {
267
+ const candidates = new Map<string, { binding: ImportBinding, uses: boolean[] }>()
268
+ const specifiers = new Map<string, string>()
269
+
270
+ for (const binding of imports) {
271
+ if (binding.imported !== 'default' || binding.typeOnly)
272
+ continue
273
+
274
+ specifiers.set(binding.local, binding.source)
275
+
276
+ const declared = file.source.slice(binding.declaration.start, binding.declaration.end)
277
+
278
+ if ((known[binding.source]?.size ?? 0) >= LAZY_FLOOR && PLAIN_IMPORT.test(declared))
279
+ candidates.set(binding.local, { binding, uses: [] })
280
+ }
281
+
282
+ if (candidates.size === 0)
283
+ return new Map()
284
+
285
+ const refused = new Set<string>()
286
+
287
+ new Positions(file.source, (element) => {
288
+ const specifier = specifiers.get(element.name)
289
+
290
+ return specifier === undefined ? [] : known[specifier]?.deferred ?? []
291
+ }, {
292
+ use(element, deferred) {
293
+ const candidate = candidates.get(element.name)
294
+
295
+ if (!candidate)
296
+ return
297
+
298
+ candidate.uses.push(deferred)
299
+
300
+ if (serverIslandOf(element, file.source) !== undefined)
301
+ refused.add(element.name)
302
+ },
303
+ }).walk(file.template, false)
304
+
305
+ const code = codeOf(file)
306
+ const found = new Map<string, LazyImport>()
307
+
308
+ for (const [local, { binding, uses }] of candidates) {
309
+ const written = occurrences(code, local) - 1
310
+
311
+ if (uses.length === 0 || !uses.every(Boolean) || refused.has(local) || written !== uses.length)
312
+ continue
313
+
314
+ found.set(local, { key: known[binding.source]!.key, specifier: binding.source, declaration: binding.declaration })
315
+ }
316
+
317
+ return found
318
+ }
319
+
320
+ // Whether the file's output holds lazy imports: the browser's, and the server's render of an island or of a twin, which tells the island what it drew.
321
+ export function lazyImportsOf(file: KayFile, imports: readonly ImportBinding[], options: { components?: ImportedComponents | undefined, output?: string | undefined }, hydrated: boolean, routeFile: boolean, clientOnly: boolean): ReadonlyMap<string, LazyImport> | undefined {
322
+ return options.components !== undefined && !(routeFile || clientOnly) && (options.output === 'dom' || hydrated) ? lazyImports(file, imports, options.components) : undefined
323
+ }
324
+
325
+ // The import the server's output adds for a lazy import: what tells the island its code is wanted.
326
+ export function lazyNoteImport(lazy: ReadonlyMap<string, LazyImport> | undefined, mode: string): string {
327
+ return mode === 'html' && (lazy?.size ?? 0) > 0 ? `import { lazyNote as ${helperName('lazyNote')} } from 'kay/island'\n` : ''
328
+ }
329
+
330
+ // The import of the lazy runtime, only in a module that has lazy imports: a module naming it without using it still joins the chunks of every module that does, whatever the bundle drops after.
331
+ export function lazyDomImport(lazy: ReadonlyMap<string, LazyImport> | undefined): string {
332
+ return (lazy?.size ?? 0) > 0 ? `import { lazy as ${helperName('lazy')}, ready as ${helperName('ready')} } from 'kay/dom-lazy'\n` : ''
333
+ }
334
+
335
+ // The edits rewriting the lazy imports among a hoisted statement's `imports`: the browser's code asks for the module when the component first draws, the server's draws it as it always did and notes its key.
336
+ export function lazyEdits(imports: readonly ImportBinding[], span: Span, lazy: ReadonlyMap<string, LazyImport> | undefined, mode: string, moduleId: string | undefined): { start: number, end: number, text: string }[] {
337
+ if (mode !== 'dom' && mode !== 'html')
338
+ return []
339
+
340
+ const last = Math.max(-1, ...[...lazy?.values() ?? []].map(other => other.declaration.start))
341
+
342
+ return imports.flatMap((binding) => {
343
+ const found = lazy?.get(binding.local)
344
+
345
+ if (!found || binding.declaration.start < span.start || binding.declaration.end > span.end)
346
+ return []
347
+
348
+ const key = JSON.stringify(found.key)
349
+ const specifier = JSON.stringify(found.specifier)
350
+ const eager = `${helperName('lazy')}_${binding.local}`
351
+
352
+ // The module says which keys it imports lazily, once, after the last, so every key is registered by then.
353
+ const ready = found.declaration.start === last ? `\n${helperName('ready')}(${JSON.stringify(moduleId)}, ${JSON.stringify([...lazy?.values() ?? []].map(other => other.key))})` : ''
354
+
355
+ return [{ ...found.declaration, text: mode === 'dom' ? `const ${binding.local} = ${helperName('lazy')}(${key}, () => import(${specifier}))${ready}` : `import ${eager} from ${specifier}\nconst ${binding.local} = ${helperName('lazyNote')}(${key}, () => ${eager})` }]
356
+ })
357
+ }
@@ -3,7 +3,7 @@ import type { Lint } from './lints'
3
3
  import { editDistance } from './aria'
4
4
  import { elementsIn } from './ast'
5
5
 
6
- interface Renamed {
6
+ export interface Renamed {
7
7
  name: string
8
8
  value: string
9
9
  // What a `false` value of the old name becomes, for a flag that was off by that word.
@@ -23,13 +23,14 @@ export const LINK_LINTS = {
23
23
 
24
24
  // The attributes a link, or an element around links, takes to say how the swap follows it, named as the options of `navigate()` are: `scroll`, `transition`, `prefetch`, and `reload` for a full load.
25
25
  const FLAGS = new Set(['data-scroll', 'data-transition', 'data-prefetch', 'data-reload'])
26
+
26
27
  // The names before 1.105 and what each became: `data-keep-scroll` is `data-scroll="keep"`, `data-no-transition` is `data-transition="false"`, `data-no-prefetch` is `data-prefetch="false"`.
27
- const OLD: Record<string, Renamed> = {
28
+ export const OLD_LINK_FLAGS: Record<string, Renamed> = {
28
29
  'data-keep-scroll': { name: 'data-scroll', value: 'keep', off: 'top' },
29
30
  'data-no-transition': { name: 'data-transition', value: 'false' },
30
31
  'data-no-prefetch': { name: 'data-prefetch', value: 'false' },
31
32
  }
32
- const NEARBY = [...FLAGS, ...Object.keys(OLD)]
33
+ const NEARBY = [...FLAGS, ...Object.keys(OLD_LINK_FLAGS)]
33
34
 
34
35
  // The name an attribute is written with, none for a spread or a `{name}` shorthand.
35
36
  function nameOf(attribute: Attribute): Span | undefined {
@@ -66,7 +67,7 @@ export function linkFlags(file: KayFile): Diagnostic[] {
66
67
  continue
67
68
 
68
69
  const name = file.source.slice(at.start, at.end)
69
- const old = OLD[name]
70
+ const old = OLD_LINK_FLAGS[name]
70
71
 
71
72
  if (old !== undefined) {
72
73
  found.push(oldFlag(file.source, attribute, at, name, old))
@@ -79,7 +80,7 @@ export function linkFlags(file: KayFile): Diagnostic[] {
79
80
  if (meant === undefined)
80
81
  continue
81
82
 
82
- const renamed = OLD[meant]
83
+ const renamed = OLD_LINK_FLAGS[meant]
83
84
  const to = renamed === undefined ? meant : `${renamed.name}="${renamed.value}"`
84
85
  // An old name written with a value keeps that value after the name, so writing `name="value"` there would leave two: that case gets the help alone.
85
86
  const fixes = renamed !== undefined && attribute.kind !== 'boolean' ? [] : [{ title: `Write \`${to}\``, safe: false, edits: [{ ...at, text: to }] }]
@@ -295,8 +295,8 @@ export const LINTS = {
295
295
  level: 'warn',
296
296
  group: 'forms',
297
297
  summary: 'A string field of an action\'s schema named like a short value (`name`, `email`, `title`, `subject`, `slug`, `phone`, `code`...) with no `maxLength` of its own: every string field is refused past 10,000 characters by default, which is far too long for these. Any other field keeps the default, and a secret such as a password is left alone.',
298
- wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.Object({ title: s.String() }), async ({ title }) => create(title))\n---\nform(action={add})\n input(name="title")',
299
- right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.Object({ title: s.String({ maxLength: 200 }) }), async ({ title }) => create(title))\n---\nform(action={add})\n input(name="title")',
298
+ wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.object({ title: s.string() }), async ({ title }) => create(title))\n---\nform(action={add})\n input(name="title")',
299
+ right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.object({ title: s.string({ max: 200 }) }), async ({ title }) => create(title))\n---\nform(action={add})\n input(name="title")',
300
300
  },
301
301
  'css-import-without-text': {
302
302
  level: 'deny',
@@ -309,22 +309,22 @@ export const LINTS = {
309
309
  level: 'warn',
310
310
  group: 'code',
311
311
  summary: 'An `async` function returning `ask()` from kayjs-ai: the reply is a thenable, so the function awaits it and the action, API route or `await` block reading it gets the whole text at once, with no streaming. The fix removes `async` (not from a function with a return type); a function that awaits something first returns `ask(...).stream()` instead, and `return await ask(...)` says the whole text is meant, which this lint leaves alone. Found in `.kay` fences and `.ts` modules alike.',
312
- wrong: '--- server\nimport { ask } from \'@kayjs/ai\'\nimport { action, s } from \'kay\'\n\nexport const reply = action(s.Object({ messages: s.Array(s.Any()) }), async ({ messages }) => ask(messages))\n---\np x',
313
- right: '--- server\nimport { ask } from \'@kayjs/ai\'\nimport { action, s } from \'kay\'\n\nexport const reply = action(s.Object({ messages: s.Array(s.Any()) }), ({ messages }) => ask(messages))\n---\np x',
312
+ wrong: '--- server\nimport { ask } from \'@kayjs/ai\'\nimport { action, s } from \'kay\'\n\nexport const reply = action(s.object({ messages: s.list(s.string()) }), async ({ messages }) => ask(messages))\n---\np x',
313
+ right: '--- server\nimport { ask } from \'@kayjs/ai\'\nimport { action, s } from \'kay\'\n\nexport const reply = action(s.object({ messages: s.list(s.string()) }), ({ messages }) => ask(messages))\n---\np x',
314
314
  },
315
315
  'unreturned-fail': {
316
316
  level: 'deny',
317
317
  group: 'code',
318
318
  summary: 'A `ctx.fail(...)` statement in an action\'s handler (or `fail(...)` destructured from the context) that is not returned: `fail` returns the failure the action answers with, where `deny`, `notFound` and `redirect` throw, so the statement does nothing and the handler carries on. An arrow function with an expression body already returns, and a nested function is left alone. The fix prepends `return`. Found in `.kay` fences and `.ts` modules alike.',
319
- wrong: '--- server\nexport const rename = action(s.Object({ name: s.String() }), ({ name }, ctx) => {\n if (name === \'admin\')\n ctx.fail(409, \'That name is taken\')\n\n return name\n})\n---\np x',
320
- right: '--- server\nexport const rename = action(s.Object({ name: s.String() }), ({ name }, ctx) => {\n if (name === \'admin\')\n return ctx.fail(409, \'That name is taken\')\n\n return name\n})\n---\np x',
319
+ wrong: '--- server\nexport const rename = action(s.object({ name: s.string() }), ({ name }, ctx) => {\n if (name === \'admin\')\n ctx.fail(409, \'That name is taken\')\n\n return name\n})\n---\np x',
320
+ right: '--- server\nexport const rename = action(s.object({ name: s.string() }), ({ name }, ctx) => {\n if (name === \'admin\')\n return ctx.fail(409, \'That name is taken\')\n\n return name\n})\n---\np x',
321
321
  },
322
322
  'missing-captcha': {
323
323
  level: 'warn',
324
324
  group: 'forms',
325
325
  summary: 'A call to `password.register`, `password.requestReset`, `magicLink.request` or `password.signIn` on an auth (a receiver named `auth`, or ending in `auth`), with no `captcha` option, while no `captcha: false` is written in the same file or in an `authCore` (`createAuth` before 1.91) call of the project (`kay check` reads every module): kayjs-auth asks a proof of work by default, so such a call answers `{ ok: false, error: \'captcha\' }` until the form carries the challenge. Put `input(type="hidden" name="captcha" data-kay-work={await auth.captcha.challenge(\'register\')})` in the form (action `\'reset\'`, `\'magic-link\'` or `\'sign-in\'` for the others), read the field in the action and pass it as `{ captcha: input.captcha }`. Found in `.kay` fences and `.ts` modules alike.',
326
- wrong: '--- server\nexport const reset = action(s.Object({ email: s.String() }), ({ email }, ctx) => ctx.locals.auth.password.requestReset(email))\n---\np x',
327
- right: '--- server\nexport const reset = action(s.Object({ email: s.String(), captcha: s.String() }), ({ email, captcha }, ctx) => ctx.locals.auth.password.requestReset(email, { captcha }))\n---\np x',
326
+ wrong: '--- server\nexport const reset = action(s.object({ email: s.string() }), ({ email }, ctx) => ctx.locals.auth.password.requestReset(email))\n---\np x',
327
+ right: '--- server\nexport const reset = action(s.object({ email: s.string(), captcha: s.string() }), ({ email, captcha }, ctx) => ctx.locals.auth.password.requestReset(email, { captcha }))\n---\np x',
328
328
  },
329
329
  'positional-key': {
330
330
  level: 'deny',
@@ -411,8 +411,8 @@ export const LINTS = {
411
411
  group: 'security',
412
412
  site: true,
413
413
  summary: 'With `mcp`, an action that sets `tool` and a `honeypot`, `minTime` or `proofOfWork`, with no `_guard.ts` covering it: an agent calls it without the form those protections ask of a person, so anonymous callers can spam it. A guard, or a `rateLimit` with `tool` alone, keeps it in hand.',
414
- wrong: '// kay.config.ts sets mcp: true\nexport const subscribe = action(s.Object({ email: s.String() }), save, { tool: true, protect: { honeypot: \'website\' } })',
415
- right: '// src/routes/_guard.ts covers it, or the action keeps tool and drops the honeypot\nexport const subscribe = action(s.Object({ email: s.String() }), save, { tool: true, protect: { rateLimit: { max: 5, window: \'1m\' } } })',
414
+ wrong: '// kay.config.ts sets mcp: true\nexport const subscribe = action(s.object({ email: s.string() }), save, { tool: true, protect: { honeypot: \'website\' } })',
415
+ right: '// src/routes/_guard.ts covers it, or the action keeps tool and drops the honeypot\nexport const subscribe = action(s.object({ email: s.string() }), save, { tool: true, protect: { rateLimit: { max: 5, window: \'1m\' } } })',
416
416
  },
417
417
  'external-redirect': {
418
418
  level: 'warn',
@@ -489,8 +489,8 @@ export const LINTS = {
489
489
  group: 'code',
490
490
  site: true,
491
491
  summary: 'An API route `.ws()` with a `body` and no `response`, written with an object literal of options and no spread: an island\'s `socket()` receives its messages as `unknown`, so `last()` and `on()` need a cast. Add `response: chats.response` when it sends through `rooms()`, or a `response` schema; a route only other clients read can allow the lint.',
492
- wrong: 'export default api().ws(\'/\', { body: s.Object({ text: s.String() }), message(ws, { text }) { chats.publish(\'main\', { text }) } })',
493
- right: 'export default api().ws(\'/\', { body: s.Object({ text: s.String() }), response: chats.response, message(ws, { text }) { chats.publish(\'main\', { text }) } })',
492
+ wrong: 'export default api().ws(\'/\', { body: s.object({ text: s.string() }), message(ws, { text }) { chats.publish(\'main\', { text }) } })',
493
+ right: 'export default api().ws(\'/\', { body: s.object({ text: s.string() }), response: chats.response, message(ws, { text }) { chats.publish(\'main\', { text }) } })',
494
494
  },
495
495
  'unsized-image': {
496
496
  level: 'warn',
@@ -2,7 +2,7 @@ import type { Attribute, AwaitBranch, AwaitNode, ConstNode, Details, Diagnostic,
2
2
  import { scanClassName } from './class-name'
3
3
  import { strayElse } from './else-problem'
4
4
  import { ifAlias } from './if-alias'
5
- import { rolesOf } from './island-declaration'
5
+ import { rolesOf, spelledOutFirstFence } from './island-declaration'
6
6
  import { Scanner } from './scanner'
7
7
 
8
8
  // `--- server`, `--- client`, `--- island`, `--- static`, `--- script`, `--- module`, or `--- <T extends Row>` making the component generic, its type parameters in the third or fourth group: `--- client <T>` takes both.
@@ -170,7 +170,7 @@ export function parseKay(source: string): KayFile {
170
170
  if (bareClosing)
171
171
  explainSecondFence(source, bareClosing, diagnostics)
172
172
 
173
- return { source, script: fences.script, server: fences.server, serverFence, module: fences.module, style: fences.style, typeParameters, client, pin, island, scriptLine, templateStart, template, diagnostics, unclosedServer }
173
+ return { source, script: fences.script, server: fences.server, serverFence, module: fences.module, style: fences.style, typeParameters, client, pin, island, scriptLine, templateStart, template, diagnostics: [...diagnostics, ...spelledOutFirstFence(source, scriptLine, fenceWord)], unclosedServer }
174
174
  }
175
175
 
176
176
  // A bare `---` in the template after a named fence closed by a bare `---`: the first bare line closed that fence, so the author meant the second fence as the script, which takes `--- script` once a named fence is there.
@@ -0,0 +1,15 @@
1
+ import type { TemplateFacts } from './ast'
2
+ import type { PropsDeclaration } from './script'
3
+
4
+ // The keys `omit` takes out of the props to make the rest object: the declared props that can arrive (all of them, or the ones `written` names), then what a component that merges parts owns (`class`, `parts`, its recipe's variants and the app's).
5
+ export function restOmits(props: PropsDeclaration, written: ReadonlySet<string> | undefined, facts: TemplateFacts): string[] {
6
+ const owned = facts.parts?.merges === true
7
+ const declared = props.bindings.filter(binding => written?.has(binding.key) ?? true)
8
+
9
+ return [
10
+ ...declared.map(binding => JSON.stringify(binding.key)),
11
+ ...owned ? ['"class"', '"parts"'] : [],
12
+ ...owned && facts.recipe !== undefined ? [`...${facts.recipe}.variants`] : [],
13
+ ...owned ? Object.keys(facts.ui?.variants ?? {}).map(name => JSON.stringify(name)) : [],
14
+ ]
15
+ }
@@ -1,6 +1,7 @@
1
1
  import type { Lint } from './lints'
2
2
  import { LINK_LINTS } from './link-flags'
3
3
  import { LOOP_LINTS } from './loop-lints'
4
+ import { SCHEMA_LINTS } from './schema-lints'
4
5
  import { SERIAL_AWAITS_LINTS } from './serial-awaits'
5
6
 
6
7
  // The lints of the files under `src/routes`, of the content entries and of a page's server fence, with the other lints in `LINTS`.
@@ -8,6 +9,7 @@ export const ROUTE_LINTS = {
8
9
  ...SERIAL_AWAITS_LINTS,
9
10
  ...LOOP_LINTS,
10
11
  ...LINK_LINTS,
12
+ ...SCHEMA_LINTS,
11
13
  'text-size-colour': {
12
14
  level: 'warn',
13
15
  group: 'code',
@@ -0,0 +1,13 @@
1
+ import type { Lint } from './lints'
2
+
3
+ // The lints about the schemas an app hands the server, with the others in `LINTS`.
4
+ export const SCHEMA_LINTS = {
5
+ 'schema-without-json-schema': {
6
+ level: 'warn',
7
+ group: 'forms',
8
+ site: true,
9
+ summary: 'A Standard Schema validator with no `~standard.jsonSchema` where an action\'s `input` or an API route\'s `body`, `query`, `params`, `headers` or `cookie` takes a schema: it still validates, but a form shows no constraints, a form or a query is not read as numbers and booleans, and OpenAPI and MCP show an open schema. Read from the source, in `.ts` modules and `.kay` fences: a hand-written object with `~standard` and no `jsonSchema`, and what valibot builds (valibot carries none until `toStandardJsonSchema` from `@valibot/to-json-schema` wraps it), followed through a `const` and a relative import. Zod 4.2+ and ArkType 2.1.28+ carry it.',
10
+ wrong: '--- server\nimport { action } from \'kay\'\nimport * as v from \'valibot\'\n\nexport const add = action({ input: v.object({ title: v.string() }) }, ({ title }) => title)\n---\np x',
11
+ right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ input: { title: s.string({ max: 200 }) } }, ({ title }) => title)\n---\np x',
12
+ },
13
+ } as const satisfies Record<string, Lint>
@@ -272,11 +272,14 @@ const BOT_PROTECTIONS = new Set(['honeypot', 'minTime', 'proofOfWork'])
272
272
 
273
273
  // What an `action(...)` call's options say, when one of its arguments is an object literal setting `tool`. Options it cannot read, a variable or an object spreading the `tool`, may make a tool: `output` is then false, so the type of its handler is probed, and `botProtected` false.
274
274
  function toolOptions(args: NodeOfType<'CallExpression'>['arguments']): { botProtected: boolean, output: boolean } | undefined {
275
- // The options follow the handler, which is the first argument of an action with no schema.
276
- const options = args[0]?.type === 'ArrowFunctionExpression' || args[0]?.type === 'FunctionExpression' ? args[1] : args[2]
275
+ const isHandler = (arg: Node | undefined): boolean => arg?.type === 'ArrowFunctionExpression' || arg?.type === 'FunctionExpression'
276
+ // The options come first when a handler follows them (`action({ input, ...options }, handler)`), else follow the handler, which is the first argument of an action with no schema.
277
+ const optionsFirst = args[0]?.type === 'ObjectExpression' && isHandler(args[1])
278
+ const afterHandler = isHandler(args[0]) ? args[1] : args[2]
279
+ const options = optionsFirst ? args[0] : afterHandler
277
280
  let unreadable = options !== undefined && options.type !== 'ObjectExpression'
278
281
 
279
- for (const arg of args.slice(1)) {
282
+ for (const arg of args.slice(options === args[0] ? 0 : 1)) {
280
283
  if (arg.type !== 'ObjectExpression')
281
284
  continue
282
285
 
@@ -4,6 +4,7 @@ import { existsSync, realpathSync } from 'node:fs'
4
4
  import { dirname, join, resolve } from 'node:path'
5
5
  import process from 'node:process'
6
6
  import { APP_DEPENDENCIES, dependencyNames, libraryMessageExtensions, readManifest } from './build/manifests'
7
+ import { setUiLayers } from './build/ui-layers'
7
8
  import { KayError } from './compiler/errors'
8
9
  import { APP_CONTEXT, CONFIG_FILE } from './config'
9
10
  import { resolveConfig } from './config-resolve'
@@ -14,7 +15,14 @@ import { publicEnvFiles } from './server/env-state'
14
15
 
15
16
  // `fresh` reads the file again as it is now, as `kay dev` does once it changed, rather than the module this process imported first.
16
17
  export async function loadConfig(root: string, fresh = false): Promise<LoadedConfig> {
17
- return withTailwind(root, withSiteUrl(withPublicFields(root, withExtensions(withAppContext(root, withLibraryMessages(root, await importConfig(root, fresh)))))))
18
+ return withUiLayers(root, await withTailwind(root, withSiteUrl(withPublicFields(root, withExtensions(withAppContext(root, withLibraryMessages(root, await importConfig(root, fresh))))))))
19
+ }
20
+
21
+ // The config, once the `ui` files of its extensions are known to the build of the project.
22
+ function withUiLayers<Config extends KayConfig>(root: string, config: Config): Config {
23
+ setUiLayers(root, config.extensions)
24
+
25
+ return config
18
26
  }
19
27
 
20
28
  const CONFIG_TIMEOUT = 30_000
@@ -332,7 +340,7 @@ export async function withConfig<Options extends ConfigInput>(root: string, opti
332
340
  // The options are resolved as the file is, so a code call may pass a list's function or an old key as `kay.config.ts` may.
333
341
  const given = await resolveConfig(options) as KayConfig & Omit<Options, keyof ConfigInput>
334
342
 
335
- return withTailwind(root, withPublicFields(root, withAppContext(root, mergeConfig(withLibraryMessages(root, await importConfig(root)), given))))
343
+ return withUiLayers(root, await withTailwind(root, withPublicFields(root, withAppContext(root, mergeConfig(withLibraryMessages(root, await importConfig(root)), given)))))
336
344
  }
337
345
 
338
346
  // `config` is as `kay.config.ts` writes it, so the extensions the options name lie under it rather than the file's.
@@ -173,13 +173,15 @@ export async function resolveConfig(config: ConfigInput): Promise<KayConfig> {
173
173
  ])
174
174
  const cors = config.cors === undefined ? undefined : await loadKeys(config.cors, ['origins'])
175
175
  const { onStart, ...kept } = config
176
+ // An extension's config is written as `kay.config.ts` is, so its keys of before 1.105 move as the app's do.
177
+ const extensions = config.extensions === undefined ? undefined : await Promise.all(config.extensions.map(async extension => extension.config === undefined ? extension : { ...extension, config: await resolveConfig(extension.config) }))
176
178
 
177
179
  for (const key of MOVED_KEYS)
178
180
  delete kept[key]
179
181
 
180
182
  const { ops, onError, paths } = resolveOps(config)
181
183
  const routes = resolveEndpoints(config, paths, resolveMcp(config.mcp))
182
- const resolved: Record<string, unknown> = { ...kept, security, proxy: resolveProxy(proxy), ...routes, robots, i18n, redirects, assets, ops, cors, client: resolveClient(config), onListen: config.onListen ?? onStart, onError: config.onError ?? onError }
184
+ const resolved: Record<string, unknown> = { ...kept, ...extensions !== undefined && { extensions }, security, proxy: resolveProxy(proxy), ...routes, robots, i18n, redirects, assets, ops, cors, client: resolveClient(config), onListen: config.onListen ?? onStart, onError: config.onError ?? onError }
183
185
 
184
186
  for (const key of Object.keys(resolved)) {
185
187
  if (resolved[key] === undefined)
@@ -1,5 +1,5 @@
1
1
  import type { BudgetConfig } from './build/budget'
2
- import type { ActionsConfig, AssetsConfig, CardConfig, ClientConfig, ConfigInput, CookieDefaults, DeprecatedMcp, DeprecatedOpenApi, DeprecatedPath, DeprecatedServe, DirsConfig, EndpointsConfig, FaviconConfig, HealthConfig, I18nInput, ImageFormats, ImageLimits, ImagesInput, JobsConfig, LimitsConfig, LiveConfig, LogConfig, ManifestConfig, MarkdownConfig, MetricsConfig, ObserveInput, OfflineConfig, OpsConfig, PreviewConfig, ProxyConfig, RemoteImages, RobotsConfig, SecurityConfig, SeoConfig, ServeConfig, SitemapConfig } from './config'
2
+ import type { ActionsConfig, AssetsConfig, CardConfig, ClientConfig, ConfigInput, CookieDefaults, DeprecatedMcp, DeprecatedOpenApi, DeprecatedPath, DeprecatedServe, DirsConfig, EndpointsConfig, FaviconConfig, HealthConfig, I18nInput, ImageFormats, ImageLimits, ImagesInput, JobsConfig, LimitsConfig, LiveConfig, LogConfig, ManifestConfig, ManifestShareTarget, MarkdownConfig, MetricsConfig, ObserveInput, OfflineConfig, OpsConfig, PreviewConfig, ProxyConfig, RemoteImages, RobotsConfig, SecurityConfig, SeoConfig, ServeConfig, SitemapConfig } from './config'
3
3
  import type { Rule } from './config-rules'
4
4
  import type { McpConfig } from './server/api-modules'
5
5
  import type { OpenApiConfig } from './server/openapi'
@@ -45,7 +45,7 @@ const JOBS: Record<keyof (JobsConfig & DeprecatedPath), Rule> = { guards: guardO
45
45
  const METRICS: Record<keyof (MetricsConfig & DeprecatedPath), Rule> = { path: str, token: either(lit(true), SECRET) }
46
46
  const BUDGET: Record<keyof BudgetConfig, Rule> = { js: bytes, css: bytes, weight: bytes, grade: oneOf('A', 'B', 'C', 'D', 'E', 'F', 'G') }
47
47
  const FAVICON: Record<keyof FaviconConfig, Rule> = { image: str, svg: str }
48
- const MANIFEST: Record<keyof ManifestConfig, Rule> = { shortName: str, themeColor: either(str, bag({ light: str, dark: str })), backgroundColor: str, display: oneOf('fullscreen', 'standalone', 'minimal-ui', 'browser'), orientation: oneOf('any', 'natural', 'landscape', 'landscape-primary', 'landscape-secondary', 'portrait', 'portrait-primary', 'portrait-secondary'), startUrl: str, scope: str, maskable: str, shortcuts: list(obj) }
48
+ const MANIFEST: Record<keyof ManifestConfig, Rule> = { shortName: str, themeColor: either(str, bag({ light: str, dark: str })), backgroundColor: str, display: oneOf('fullscreen', 'standalone', 'minimal-ui', 'browser'), orientation: oneOf('any', 'natural', 'landscape', 'landscape-primary', 'landscape-secondary', 'portrait', 'portrait-primary', 'portrait-secondary'), startUrl: str, scope: str, maskable: str, shortcuts: list(obj), shareTarget: bag({ action: str, files: list(str), params: bag({ title: str, text: str, url: str, files: str }) } satisfies Record<keyof ManifestShareTarget, Rule>) }
49
49
  const MARKDOWN: Record<keyof MarkdownConfig, Rule> = { highlight: fn, transform: fn, preprocess: fn, containers: bool, footnotes: bool, headingLinks: bool, readingSpeed: num, imageSizes: str }
50
50
  const CARD: Record<keyof CardConfig, Rule> = { font: bag({ family: str, weight: num }), background: str, color: str, logo: str }
51
51
  const AVIF = either(bool, bag({ quality: num }))