@kayjs/kay 1.105.0 → 1.106.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 (310) hide show
  1. package/dist/eslint.js +435 -120
  2. package/editors/zed/extension.toml +2 -2
  3. package/llms/action-protection.md +1 -1
  4. package/llms/actions-from-islands.md +2 -2
  5. package/llms/actions.md +22 -19
  6. package/llms/analytics.md +1 -1
  7. package/llms/api-from-islands.md +1 -1
  8. package/llms/api-routes.md +6 -6
  9. package/llms/check-and-tools.md +1 -1
  10. package/llms/code-lints.md +2 -2
  11. package/llms/compiler-api.md +1 -1
  12. package/llms/component-libraries.md +1 -0
  13. package/llms/content-cms.md +1 -1
  14. package/llms/content-markdown-to-caching.md +1 -1
  15. package/llms/content-preview.md +2 -2
  16. package/llms/content.md +21 -21
  17. package/llms/deprecated-lints-1-105-libraries.md +2 -0
  18. package/llms/deprecated-lints-1-105.md +3 -3
  19. package/llms/deprecated-lints.md +3 -2
  20. package/llms/dev-tool.md +2 -2
  21. package/llms/environment.md +22 -22
  22. package/llms/files.md +5 -5
  23. package/llms/islands-state-to-ids.md +2 -1
  24. package/llms/local-collections.md +2 -2
  25. package/llms/mcp.md +2 -1
  26. package/llms/navigation-from-code.md +1 -1
  27. package/llms/notifications.md +4 -2
  28. package/llms/project.md +1 -1
  29. package/llms/rate-limits.md +1 -1
  30. package/llms/recipes.md +16 -16
  31. package/llms/rooms.md +4 -4
  32. package/llms/routing-endpoints-and-base.md +1 -1
  33. package/llms/routing.md +5 -5
  34. package/llms/schemas.md +10 -5
  35. package/llms/server.md +7 -7
  36. package/llms/site.md +9 -9
  37. package/llms/sitemap-search-fonts.md +2 -0
  38. package/llms/styles-and-assets.md +2 -1
  39. package/llms/templates-elements-slots-snippets.md +2 -2
  40. package/llms/testing-browser.md +20 -0
  41. package/llms/testing.md +1 -1
  42. package/llms/upgrading-1-105-config.md +2 -2
  43. package/llms/upgrading.md +18 -3
  44. package/llms/whats-new-archive.md +35 -66
  45. package/llms/whats-new.md +34 -28
  46. package/llms.txt +1 -1
  47. package/package.json +15 -11
  48. package/src/add.ts +1 -1
  49. package/src/build/class-table.ts +2 -2
  50. package/src/build/client.ts +7 -6
  51. package/src/build/plugin.ts +14 -11
  52. package/src/build/styles.ts +3 -3
  53. package/src/build/transform.ts +3 -1
  54. package/src/build/ui-layers.ts +30 -0
  55. package/src/build/ui.ts +108 -11
  56. package/src/build/variants.ts +119 -43
  57. package/src/build/worker-bundle.ts +6 -0
  58. package/src/check/boot.ts +22 -1
  59. package/src/check/call-result.ts +242 -0
  60. package/src/check/config-objects.ts +17 -2
  61. package/src/check/diagnose.ts +22 -0
  62. package/src/check/handler-events.ts +149 -0
  63. package/src/check/index.ts +6 -2
  64. package/src/check/link-flag-tests.ts +130 -0
  65. package/src/check/project.ts +4 -3
  66. package/src/check/refusal-calls.ts +2 -2
  67. package/src/check/regroup.ts +5 -3
  68. package/src/check/renamed-packages.ts +58 -14
  69. package/src/check/schema-builders.ts +256 -0
  70. package/src/check/secret-keys.ts +15 -2
  71. package/src/check/shadow-types.ts +2 -0
  72. package/src/check/template-hints.ts +1 -1
  73. package/src/check/tool-labels.ts +11 -9
  74. package/src/check/ui-types.ts +4 -3
  75. package/src/check/ui.ts +14 -11
  76. package/src/commands/env-declare.ts +18 -6
  77. package/src/commands/routes.ts +1 -1
  78. package/src/compiler/a11y.ts +8 -1
  79. package/src/compiler/ast.ts +1 -1
  80. package/src/compiler/bound-props.ts +1 -1
  81. package/src/compiler/codegen.ts +6 -6
  82. package/src/compiler/deprecated-lints-1-106.ts +14 -0
  83. package/src/compiler/deprecated-lints.ts +10 -5
  84. package/src/compiler/deprecated-typed-lints.ts +23 -0
  85. package/src/compiler/dom-here.ts +72 -0
  86. package/src/compiler/dom.ts +23 -23
  87. package/src/compiler/fence-checks.ts +12 -11
  88. package/src/compiler/field-described.ts +2 -2
  89. package/src/compiler/helper-imports.ts +1 -1
  90. package/src/compiler/html-fields.ts +92 -0
  91. package/src/compiler/html-initial.ts +5 -3
  92. package/src/compiler/html.ts +14 -31
  93. package/src/compiler/index.ts +3 -1
  94. package/src/compiler/items.ts +5 -5
  95. package/src/compiler/link-flags.ts +6 -5
  96. package/src/compiler/lints.ts +12 -12
  97. package/src/compiler/rest-omits.ts +15 -0
  98. package/src/config-loader.ts +10 -2
  99. package/src/config-resolve.ts +3 -1
  100. package/src/config-shape.ts +2 -2
  101. package/src/config.ts +20 -4
  102. package/src/content/markdown.ts +2 -3
  103. package/src/generate-resource.ts +9 -9
  104. package/src/generate.ts +1 -1
  105. package/src/mcp/guards.ts +1 -1
  106. package/src/mcp/tools.ts +1 -1
  107. package/src/migrate/content.ts +61 -55
  108. package/src/runtime/action-shared.ts +2 -2
  109. package/src/runtime/action.ts +6 -2
  110. package/src/runtime/form-types.ts +99 -0
  111. package/src/runtime/form.ts +22 -7
  112. package/src/runtime/html.ts +36 -5
  113. package/src/runtime/markdown-autolink.ts +69 -0
  114. package/src/runtime/markdown-render.client.ts +39 -3
  115. package/src/runtime/markdown.client.ts +6 -3
  116. package/src/runtime/markdown.server.ts +6 -3
  117. package/src/runtime/markdown.ts +125 -1
  118. package/src/runtime/navigate-api.ts +10 -5
  119. package/src/runtime/persist.ts +7 -7
  120. package/src/runtime/query-param.ts +1 -1
  121. package/src/runtime/reactive.ts +14 -0
  122. package/src/runtime/sanitize.ts +3 -1
  123. package/src/runtime/schema-record.ts +31 -0
  124. package/src/runtime/schema.client.ts +1 -4
  125. package/src/runtime/schema.ts +321 -26
  126. package/src/runtime/swap-focus.ts +59 -11
  127. package/src/server/action-module.ts +16 -0
  128. package/src/server/actions.ts +6 -14
  129. package/src/server/api-modules.ts +1 -1
  130. package/src/server/api.ts +13 -1
  131. package/src/server/app-stages.ts +23 -18
  132. package/src/server/dev-ui.ts +2 -2
  133. package/src/server/env-state.ts +1 -1
  134. package/src/server/env.ts +11 -3
  135. package/src/server/favicon.ts +47 -1
  136. package/src/server/image-metadata-bmff.ts +1 -1
  137. package/src/server/kept-pages.ts +3 -3
  138. package/src/server/library.ts +2 -0
  139. package/src/server/mcp.ts +13 -12
  140. package/src/server/notifications.ts +4 -2
  141. package/src/server/offline.ts +24 -7
  142. package/src/server/push-settings.ts +16 -2
  143. package/src/server/push.ts +12 -4
  144. package/src/server/query.ts +13 -6
  145. package/src/server/render.ts +1 -1
  146. package/src/server/scope.ts +20 -13
  147. package/src/server/signals.ts +4 -4
  148. package/src/template-ws.ts +1 -1
  149. package/src/test/a11y-dom.ts +70 -0
  150. package/src/test/html-snapshot.ts +103 -0
  151. package/src/test/index.ts +2 -1
  152. package/src/test/mount.ts +8 -1
  153. package/src/test/page-checks.ts +12 -0
  154. package/src/test/screenshot-match.ts +2 -2
  155. package/src/test/shared-modules.ts +27 -5
  156. package/src/test/site-types.ts +5 -1
  157. package/types/build/class-table.d.ts +1 -1
  158. package/types/build/class-table.d.ts.map +1 -1
  159. package/types/build/client.d.ts.map +1 -1
  160. package/types/build/plugin.d.ts.map +1 -1
  161. package/types/build/transform.d.ts +1 -0
  162. package/types/build/transform.d.ts.map +1 -1
  163. package/types/build/ui-layers.d.ts +5 -0
  164. package/types/build/ui-layers.d.ts.map +1 -0
  165. package/types/build/ui.d.ts +7 -0
  166. package/types/build/ui.d.ts.map +1 -1
  167. package/types/build/variants.d.ts +1 -1
  168. package/types/build/variants.d.ts.map +1 -1
  169. package/types/build/worker-bundle.d.ts +1 -0
  170. package/types/build/worker-bundle.d.ts.map +1 -1
  171. package/types/check/boot.d.ts.map +1 -1
  172. package/types/check/call-result.d.ts +7 -0
  173. package/types/check/call-result.d.ts.map +1 -0
  174. package/types/check/config-objects.d.ts.map +1 -1
  175. package/types/check/diagnose.d.ts.map +1 -1
  176. package/types/check/handler-events.d.ts +9 -0
  177. package/types/check/handler-events.d.ts.map +1 -0
  178. package/types/check/index.d.ts +1 -0
  179. package/types/check/index.d.ts.map +1 -1
  180. package/types/check/link-flag-tests.d.ts +4 -0
  181. package/types/check/link-flag-tests.d.ts.map +1 -0
  182. package/types/check/project.d.ts.map +1 -1
  183. package/types/check/regroup.d.ts +1 -1
  184. package/types/check/regroup.d.ts.map +1 -1
  185. package/types/check/renamed-packages.d.ts +1 -0
  186. package/types/check/renamed-packages.d.ts.map +1 -1
  187. package/types/check/schema-builders.d.ts +3 -0
  188. package/types/check/schema-builders.d.ts.map +1 -0
  189. package/types/check/secret-keys.d.ts.map +1 -1
  190. package/types/check/shadow-types.d.ts.map +1 -1
  191. package/types/check/template-hints.d.ts +1 -0
  192. package/types/check/template-hints.d.ts.map +1 -1
  193. package/types/check/tool-labels.d.ts.map +1 -1
  194. package/types/check/ui-types.d.ts.map +1 -1
  195. package/types/check/ui.d.ts.map +1 -1
  196. package/types/commands/env-declare.d.ts.map +1 -1
  197. package/types/compiler/a11y.d.ts.map +1 -1
  198. package/types/compiler/bound-props.d.ts +1 -0
  199. package/types/compiler/bound-props.d.ts.map +1 -1
  200. package/types/compiler/codegen.d.ts +1 -0
  201. package/types/compiler/codegen.d.ts.map +1 -1
  202. package/types/compiler/deprecated-lints-1-106.d.ts +12 -0
  203. package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -0
  204. package/types/compiler/deprecated-lints.d.ts +32 -5
  205. package/types/compiler/deprecated-lints.d.ts.map +1 -1
  206. package/types/compiler/deprecated-typed-lints.d.ts +21 -0
  207. package/types/compiler/deprecated-typed-lints.d.ts.map +1 -0
  208. package/types/compiler/dom-here.d.ts +14 -0
  209. package/types/compiler/dom-here.d.ts.map +1 -0
  210. package/types/compiler/dom.d.ts +1 -0
  211. package/types/compiler/dom.d.ts.map +1 -1
  212. package/types/compiler/fence-checks.d.ts.map +1 -1
  213. package/types/compiler/field-described.d.ts +1 -1
  214. package/types/compiler/field-described.d.ts.map +1 -1
  215. package/types/compiler/html-fields.d.ts +19 -0
  216. package/types/compiler/html-fields.d.ts.map +1 -0
  217. package/types/compiler/html-initial.d.ts +3 -2
  218. package/types/compiler/html-initial.d.ts.map +1 -1
  219. package/types/compiler/html.d.ts.map +1 -1
  220. package/types/compiler/index.d.ts +1 -0
  221. package/types/compiler/index.d.ts.map +1 -1
  222. package/types/compiler/items.d.ts +4 -1
  223. package/types/compiler/items.d.ts.map +1 -1
  224. package/types/compiler/link-flags.d.ts +6 -0
  225. package/types/compiler/link-flags.d.ts.map +1 -1
  226. package/types/compiler/lints.d.ts +44 -17
  227. package/types/compiler/lints.d.ts.map +1 -1
  228. package/types/compiler/rest-omits.d.ts +4 -0
  229. package/types/compiler/rest-omits.d.ts.map +1 -0
  230. package/types/config-loader.d.ts.map +1 -1
  231. package/types/config-resolve.d.ts.map +1 -1
  232. package/types/config.d.ts +15 -2
  233. package/types/config.d.ts.map +1 -1
  234. package/types/content/markdown.d.ts.map +1 -1
  235. package/types/migrate/content.d.ts.map +1 -1
  236. package/types/runtime/action-shared.d.ts +1 -1
  237. package/types/runtime/action-shared.d.ts.map +1 -1
  238. package/types/runtime/action.d.ts +3 -0
  239. package/types/runtime/action.d.ts.map +1 -1
  240. package/types/runtime/form-types.d.ts +6 -0
  241. package/types/runtime/form-types.d.ts.map +1 -0
  242. package/types/runtime/form.d.ts +3 -1
  243. package/types/runtime/form.d.ts.map +1 -1
  244. package/types/runtime/html.d.ts +3 -0
  245. package/types/runtime/html.d.ts.map +1 -1
  246. package/types/runtime/markdown-autolink.d.ts +11 -0
  247. package/types/runtime/markdown-autolink.d.ts.map +1 -0
  248. package/types/runtime/markdown-render.client.d.ts +2 -1
  249. package/types/runtime/markdown-render.client.d.ts.map +1 -1
  250. package/types/runtime/markdown.client.d.ts +3 -1
  251. package/types/runtime/markdown.client.d.ts.map +1 -1
  252. package/types/runtime/markdown.d.ts +11 -0
  253. package/types/runtime/markdown.d.ts.map +1 -1
  254. package/types/runtime/markdown.server.d.ts +3 -1
  255. package/types/runtime/markdown.server.d.ts.map +1 -1
  256. package/types/runtime/navigate-api.d.ts +1 -1
  257. package/types/runtime/navigate-api.d.ts.map +1 -1
  258. package/types/runtime/persist.d.ts +2 -2
  259. package/types/runtime/persist.d.ts.map +1 -1
  260. package/types/runtime/reactive.d.ts +3 -0
  261. package/types/runtime/reactive.d.ts.map +1 -1
  262. package/types/runtime/sanitize.d.ts.map +1 -1
  263. package/types/runtime/schema-record.d.ts +9 -0
  264. package/types/runtime/schema-record.d.ts.map +1 -0
  265. package/types/runtime/schema.client.d.ts.map +1 -1
  266. package/types/runtime/schema.d.ts +94 -10
  267. package/types/runtime/schema.d.ts.map +1 -1
  268. package/types/runtime/swap-focus.d.ts.map +1 -1
  269. package/types/server/action-module.d.ts +2 -0
  270. package/types/server/action-module.d.ts.map +1 -0
  271. package/types/server/actions.d.ts +1 -0
  272. package/types/server/actions.d.ts.map +1 -1
  273. package/types/server/api.d.ts.map +1 -1
  274. package/types/server/app-stages.d.ts +3 -2
  275. package/types/server/app-stages.d.ts.map +1 -1
  276. package/types/server/env-state.d.ts.map +1 -1
  277. package/types/server/env.d.ts +5 -1
  278. package/types/server/env.d.ts.map +1 -1
  279. package/types/server/favicon.d.ts +3 -1
  280. package/types/server/favicon.d.ts.map +1 -1
  281. package/types/server/kept-pages.d.ts +1 -1
  282. package/types/server/kept-pages.d.ts.map +1 -1
  283. package/types/server/library.d.ts +2 -0
  284. package/types/server/library.d.ts.map +1 -1
  285. package/types/server/mcp.d.ts +1 -1
  286. package/types/server/mcp.d.ts.map +1 -1
  287. package/types/server/notifications.d.ts +2 -1
  288. package/types/server/notifications.d.ts.map +1 -1
  289. package/types/server/offline.d.ts.map +1 -1
  290. package/types/server/push-settings.d.ts +1 -1
  291. package/types/server/push-settings.d.ts.map +1 -1
  292. package/types/server/push.d.ts +1 -0
  293. package/types/server/push.d.ts.map +1 -1
  294. package/types/server/query.d.ts.map +1 -1
  295. package/types/server/scope.d.ts +1 -1
  296. package/types/server/scope.d.ts.map +1 -1
  297. package/types/test/a11y-dom.d.ts +20 -0
  298. package/types/test/a11y-dom.d.ts.map +1 -0
  299. package/types/test/html-snapshot.d.ts +4 -0
  300. package/types/test/html-snapshot.d.ts.map +1 -0
  301. package/types/test/index.d.ts.map +1 -1
  302. package/types/test/mount.d.ts +3 -0
  303. package/types/test/mount.d.ts.map +1 -1
  304. package/types/test/page-checks.d.ts +6 -0
  305. package/types/test/page-checks.d.ts.map +1 -0
  306. package/types/test/screenshot-match.d.ts +1 -1
  307. package/types/test/screenshot-match.d.ts.map +1 -1
  308. package/types/test/shared-modules.d.ts.map +1 -1
  309. package/types/test/site-types.d.ts +3 -1
  310. package/types/test/site-types.d.ts.map +1 -1
package/llms/dev-tool.md CHANGED
@@ -26,8 +26,8 @@ The Request tab shows the route matched, the layouts, the params, the locale, th
26
26
  - When a page's loads together take longer than `ops.observe.loadBudget` (`'300ms'`, `false` for none), the Request tab counts one warning, says so under the server's time naming the slowest load, and the page's console and `kay dev`'s log carry the same message. A layout whose load outlasts the page's own loads and the budget adds a second warning naming the layout file and both times, with the fix: start it unawaited and stream it with an `await` block, or cache it.
27
27
  - Its Network tab lists what the page fetched, read off Resource Timing, by navigation, newest first: the load, then each page swap, the last 5 kept, each request with its kind (document, page for a swap or prefetch, action, server island, fetch, script, stylesheet, image, font), status, size or `from the cache`, time and start after the navigation, an error status counted on the tab for the page shown; the tool's own requests, the live reload's and `/_kay/dev/` are left out, a hover prefetch is listed under its page, and another site's answer shows no status or size without `Timing-Allow-Origin`;
28
28
  - Its Head tab shows the page's head as it is now: the search result it makes, its title and description with their length and the description's limit of 160 characters, the canonical link, hreflang alternates, the robots tag, whether the sitemap lists the page, the og and twitter tags with a preview of the social card image, and each JSON-LD block parsed or with its parse error; what `kay check` would flag in a built page's head shows as a problem, and with `seo` set but no origin it says there is no canonical link or sitemap; it reads again after each page swap;
29
- - Its Routes tab lists every page, endpoint and API route the server serves, each locale's copy of a page on its own line, filtered by path or file, a path no request fills in linking to itself, fetched again after each restart; a section of what kay serves itself lists the sitemap, robots.txt, feeds, manifest, favicons, service worker, health check and a library's dev pages such as kayjs-mail's `/_kay/mail`, only those the running server serves, so a path an app file took over shows as the app's, and with `seo` set but no origin it says why there is no sitemap or robots.txt; under it a "kay's plumbing" group lists kay's own endpoints the app serves, one line each with its purpose and a `docs` link (the build files, `/_kay/assets/*` and `/_kay/images/*` once the build has some, `/_kay/images`, `/_kay/card`, `/_kay/files/*`, `POST /_kay/action/<file>/<name>` and `GET /_kay/fields/<file>/<name>` once an action exists, `/_kay/live`, `/_kay/error`, `/_kay/csp` with `security.reports`, `/_kay/preview` and `/_kay/draft` with `preview`, `/_kay/env.js` with an `s.Public` field, `/_kay/search.json` and `/_kay/search/*` with a search index, the `analytics()` and `vitals()` routes, `/_kay/THIRD-PARTY-LICENSES.txt`), the filter box matching their path and purpose, a GET path with nothing to fill in linking to itself under `base`;
30
- - Its Env tab lists each public variable (`s.Public`) sent to the browser, read from `/_kay/env.js` with its value, flags one whose value looks like a secret (a URL with a password, a well-known token prefix, a hexadecimal or random string), only noting a name ending in `_KEY`, and says when the app sends no public env; the server's own env is never shown;
29
+ - Its Routes tab lists every page, endpoint and API route the server serves, each locale's copy of a page on its own line, filtered by path or file, a path no request fills in linking to itself, fetched again after each restart; a section of what kay serves itself lists the sitemap, robots.txt, feeds, manifest, favicons, service worker, health check and a library's dev pages such as kayjs-mail's `/_kay/mail`, only those the running server serves, so a path an app file took over shows as the app's, and with `seo` set but no origin it says why there is no sitemap or robots.txt; under it a "kay's plumbing" group lists kay's own endpoints the app serves, one line each with its purpose and a `docs` link (the build files, `/_kay/assets/*` and `/_kay/images/*` once the build has some, `/_kay/images`, `/_kay/card`, `/_kay/files/*`, `POST /_kay/action/<file>/<name>` and `GET /_kay/fields/<file>/<name>` once an action exists, `/_kay/live`, `/_kay/error`, `/_kay/csp` with `security.reports`, `/_kay/preview` and `/_kay/draft` with `preview`, `/_kay/env.js` with an `s.public` field, `/_kay/search.json` and `/_kay/search/*` with a search index, the `analytics()` and `vitals()` routes, `/_kay/THIRD-PARTY-LICENSES.txt`), the filter box matching their path and purpose, a GET path with nothing to fill in linking to itself under `base`;
30
+ - Its Env tab lists each public variable (`s.public`) sent to the browser, read from `/_kay/env.js` with its value, flags one whose value looks like a secret (a URL with a password, a well-known token prefix, a hexadecimal or random string), only noting a name ending in `_KEY`, and says when the app sends no public env; the server's own env is never shown;
31
31
  - Its Images tab lists each image of the page with the variant it got (a ladder width, a crop, the share card, or not resized by kay), the format and bytes the server answers with (a HEAD request, only for a loaded image of kay's image route or built variants, with a timeout; any other image is not asked), the size served against the size drawn (flagged past 4 times the pixels shown, never for an SVG, whose address ends in `.svg` or whose fetch answered `image/svg+xml`, as Resource Timing keeps it), the largest contentful paint, and an image without `width` and `height` or lazy-loaded while in view; copies of one image drawn alike share a row with their count, and hovering or focusing a row outlines each, and the list follows the page as images change;
32
32
  - Its Performance tab shows the page load's LCP (with its element), CLS and INP as the browser reports them while the page is used, each rated against its good limit (2.5 s, 0.1, 200 ms) and naming the page they were measured on once a swap moved away from it, and the page's footprint measured in the browser (the DOM elements without the tool's own, the requests of the load, the EcoIndex grade and score and the grams of CO2e per view, worked out by the server with the models `kay build` uses, [Build](build-and-start.md#build-and-start-commands)), then the HTML (the document the browser holds), CSS and JS gzipped and the images, fonts and other files as the browser says they came, measured again after a swap, with the entry, the islands' chunks and the other chunks apart (a page a swap fetched and an action are not counted, another site's file counts as a request of unknown weight); the sizes are dev sizes, not minified, larger than `kay build` makes them, and a "Last kay build" block gives the route's scripts and stylesheets from the report `.kay` keeps (its age, `~` for an estimate, nothing before a first build);
33
33
  - Its Not found tab lists the paths a production run recorded visitors found nothing at (the database of the app's `store`, SQLite or Postgres, else `data/not-found.sqlite`: the log `kay not-found` reads), most hit first, with the hosts they came from and the suggested target, those a `redirects` entry answers left out; a field holds the target (the suggestion, or one typed) and Add redirect writes it into `kay.config.ts` as `kay not-found --redirect` does, then `kay dev` restarts; `kay dev` records nothing itself, so the tab leaves the list while the file, or the Postgres table `kay_missing`, is absent (it creates none).
@@ -12,31 +12,31 @@ Reading the environment typed, and letting an island read a variable. Sessions,
12
12
  import { s } from 'kay'
13
13
  import { defineEnv } from 'kay/server'
14
14
 
15
- export const env = defineEnv(s.Object({
16
- DATABASE_URL: s.String(),
17
- PORT: s.Integer({ default: 3000 }),
18
- DEBUG: s.Optional(s.Boolean()),
19
- }))
15
+ export const env = defineEnv({
16
+ DATABASE_URL: s.string(),
17
+ PORT: s.int({ default: 3000 }),
18
+ DEBUG: s.boolean({ optional: true }),
19
+ })
20
20
  ```
21
21
 
22
22
  `defineEnv(schema, source)` reads `source` instead of `process.env`, for a module building its own env. A test gives a variable of `env` another value with `overrideEnv` from `kay/test` ([Testing](testing.md)).
23
23
 
24
24
  ### Let an island read a variable
25
25
 
26
- Mark a field of `defineEnv` `s.Public` to let an island read it, such as a map key or an analytics id; it needs no key in kay.config.ts:
26
+ Mark a field of `defineEnv` `s.public` to let an island read it, such as a map key or an analytics id; it needs no key in kay.config.ts:
27
27
 
28
28
  ```ts
29
29
  import { s } from 'kay'
30
30
  import { defineEnv } from 'kay/server'
31
31
 
32
- export const env = defineEnv(s.Object({
33
- DATABASE_URL: s.String(),
34
- MAP_KEY: s.Public(s.String()),
35
- ANALYTICS_ID: s.Public(s.Optional(s.String())),
36
- }))
32
+ export const env = defineEnv({
33
+ DATABASE_URL: s.string(),
34
+ MAP_KEY: s.public(s.string()),
35
+ ANALYTICS_ID: s.public(s.string({ optional: true })),
36
+ })
37
37
  ```
38
38
 
39
- A component reads it as `publicEnv` from `kay`, typed from the `s.Public` fields of the modules under `src` only (one outside it, such as `common/env.ts`, is not found: `kay check` reports it as `public-env-outside-src`):
39
+ A component reads it as `publicEnv` from `kay`, typed from the `s.public` fields of the modules under `src` only (one outside it, such as `common/env.ts`, is not found: `kay check` reports it as `public-env-outside-src`):
40
40
 
41
41
  ```kay
42
42
  ---
@@ -52,7 +52,7 @@ button(onClick={() => console.log(publicEnv.MAP_KEY)}) Log the map key
52
52
  - One secret, `KAY_SECRET` or `secret` in kay.config.ts (which wins), at least 32 random characters: `bun -e "console.log(crypto.randomUUID() + crypto.randomUUID())"`. An empty one counts as none; a short one stops the boot.
53
53
  - It serves everything kay seals or signs, each under a key derived for its use, so none passes for another: `session()`'s cookie (no `secret` option), kayjs-auth's keys (`deriveSecret`), form stamps (`minTime`), links to private files, the flash cookie, rate-limit keys and live proofs, and `preview`'s links and cookie (no `preview.secret`). An option giving its own secret keeps it apart.
54
54
  - Commas in `KAY_SECRET` (or a list in `secret`) rotate it: the first seals and signs, every one opens and verifies: sessions, kayjs-auth's sealed data, stamps, private-file links, the flash cookie and preview links, so a rotation breaks none of them. Keep the old secret in the list while data sealed with it exists, a session cookie or a second factor.
55
- - Development and tests (`NODE_ENV` `development` or `test`) derive one for the checkout, as `s.Secret()` does, so a fresh clone runs with nothing set. Production without any refuses `session()` and `preview`, naming `KAY_SECRET`, and refuses to start a server at all: it would sign with a key of the process, which a restart changes and other replicas do not share. `KAY_EPHEMERAL_SECRET=1` starts one anyway, for a single throwaway server, which warns once. A secret of fewer than 10 different characters warns in production.
55
+ - Development and tests (`NODE_ENV` `development` or `test`) derive one for the checkout, as `s.secret()` does, so a fresh clone runs with nothing set. Production without any refuses `session()` and `preview`, naming `KAY_SECRET`, and refuses to start a server at all: it would sign with a key of the process, which a restart changes and other replicas do not share. `KAY_EPHEMERAL_SECRET=1` starts one anyway, for a single throwaway server, which warns once. A secret of fewer than 10 different characters warns in production.
56
56
  - `session()` reads it on first use, or as the server starts, so a `session()` made as a module loads takes the config's `secret` and its rotation list as well as `KAY_SECRET`; one given `session({ secret })` keeps its own.
57
57
  - An app signs its own links and values with `signed` from `kay/server`, keyed on this secret, so no key file of its own: `signed.sign(use, value, { ttl })` gives `<expiry>.<signature>` (URL-safe, `ttl` a duration, `'1h'` when left out) and `signed.verify(use, value, token)` is `true` only for that `use`, that `value`, a token not expired and signed under any key of the list, `false` for anything else, a missing or malformed token too, and never throws. `use` keeps one feature's signatures from passing for another's, and for kay's own (private-file links, stamps). A script or job that started no server reads `KAY_SECRET` (the checkout's in development and tests); a production process with none signs under a key of its own, as stamps do. `value` and `use` are strings (anything else throws) and `ttl` is at most `'52w'.
58
58
 
@@ -61,23 +61,23 @@ button(onClick={() => console.log(publicEnv.MAP_KEY)}) Log the map key
61
61
  - `defineEnv` from `kay/server` reads `process.env` once against a schema, as the server boots, and gives it back typed.
62
62
  - Names follow one rule. kay's own start `KAY_` (`KAY_SECRET`, `KAY_PROXY_KEY`, `KAY_MCP_KEY`, `KAY_METRICS_TOKEN`) apart from the ones a host sets for the app, `PORT`, `HOST`, `SITE_URL` and `SITE_BASE`, and the web push keys `VAPID_PUBLIC_KEY` and `VAPID_PRIVATE_KEY` as the standard names them. Each library has one prefix: `AUTH_` (kayjs-auth), `MAIL_`, `AI_`, `CMS_`. A vendor's own name stays as the vendor spells it: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `<PROVIDER>_CLIENT_ID` and `<PROVIDER>_CLIENT_SECRET`. `MAIL_INSECURE` and `AI_INSECURE` both mean `true` lets a secret go over a connection a network you trust carries in clear. The renamed ones, `KAYJS_AUTH_DATABASE_URL` (now `AUTH_DATABASE_URL`) and `MAIL_INBOUND_SECRET` (now `MAIL_EVENTS_INBOUND`), are no longer read.
63
63
  - A number or boolean is read from its text as a form field is, a variable left out takes its `default`, and any missing or refused stops the boot with an error naming each one.
64
- - An empty variable, `PORT=` or `PORT=""` in a `.env` file, counts as left out: it takes the default, satisfies `s.Optional` and fails a required one, rather than an empty string reaching the schema.
65
- - So an empty string is not a value a variable can carry: a setting that means something when blank is `s.Optional`, read as `undefined`.
64
+ - An empty variable, `PORT=` or `PORT=""` in a `.env` file, counts as left out: it takes the default, satisfies `optional: true` and fails a required one, rather than an empty string reaching the schema.
65
+ - So an empty string is not a value a variable can carry: a setting that means something when blank is `optional: true`, read as `undefined`.
66
66
  - A value of spaces is kept as it is, since only quoting makes one.
67
67
  - `kay build` runs without the server's environment: there a missing or refused variable leaves the module declaring it alone, and reading it throws naming it, which fails only a prerendered page that reads it.
68
68
  - The object holds the declared names only.
69
- - A string field also reads `<NAME>_FILE`, the path of a file holding the value, as a compose or swarm secret hands it: `API_KEY_FILE=/run/secrets/api_key` fills `API_KEY: s.String()`. The file is read once at boot and trimmed (surrounding whitespace goes), and the value is checked against the schema as any other. Both `API_KEY` and `API_KEY_FILE` set stops the boot naming both, and so does a file that is missing, unreadable or empty, naming the variable and the path, never the content; an `s.Optional` field (not `requiredInProduction`) is left unset instead, with one warning naming the file, so its default applies. `s.Public` fields, numbers and booleans have no file form, and neither has a name whose `_FILE` variable the schema declares itself. `kay env` says so under its listing, and `kay env --compose` and `kay check` count `API_KEY_FILE` in a compose file or the example as setting `API_KEY`. A build without the server's environment leaves a file it cannot read as a missing variable.
70
- - `requiredInProduction: true` on a field makes it required under `NODE_ENV=production` only: there it is refused at boot when missing, its `default` dropped and `s.Optional` no longer applying; in development and tests it takes its `default`, stays `undefined` under `s.Optional`, or is `''` when a `s.String` has neither, so `DISCORD_CLIENT_ID: s.String({ requiredInProduction: true })` types as `string` and needs no placeholder in the app and no second list of production keys; `s.Optional(s.String({ requiredInProduction: true }))` keeps `string | undefined`.
71
- - `s.Secret()` is a string of at least 32 characters required in production, which development and tests read as a derived value, so sessions survive a restart and nothing is committed: `DOWNLOAD_KEY: s.Secret()`; a value set in the environment wins, and `kay env` lists it as a secret required in production (`secret: true` in JSON). `kay new` uses it. Only under `NODE_ENV` `development` or `test` (`kay dev` and `bun test` set them) is it derived, from the path, the name and a random seed kept in `.kay/dev-secret` (git-ignored, 0600, written on first use and again when empty or cut short, read once per process; under `test` the seed is only read, and one of the process stands in when there is none, exported as `KAY_DEV_SEED` so a subprocess spawned with the inherited environment derives the same secret, one given an environment of its own another; `bun test` writes nothing to `.kay` for a secret and needs no `KAY_SECRET`); under any other `NODE_ENV`, or none, a missing one refuses the boot as a plain `s.String({ minLength: 32 })` does, and a `.kay` that cannot be written is an error naming it and the variable to set; `testSite()` building islands into a `.kay` that cannot be written fails the same way, naming the folder and `islands: false`.
69
+ - A string field also reads `<NAME>_FILE`, the path of a file holding the value, as a compose or swarm secret hands it: `API_KEY_FILE=/run/secrets/api_key` fills `API_KEY: s.string()`. The file is read once at boot and trimmed (surrounding whitespace goes), and the value is checked against the schema as any other. Both `API_KEY` and `API_KEY_FILE` set stops the boot naming both, and so does a file that is missing, unreadable or empty, naming the variable and the path, never the content; an optional field (not `requiredInProduction`) is left unset instead, with one warning naming the file, so its default applies. `s.public` fields, numbers and booleans have no file form, and neither has a name whose `_FILE` variable the schema declares itself. `kay env` says so under its listing, and `kay env --compose` and `kay check` count `API_KEY_FILE` in a compose file or the example as setting `API_KEY`. A build without the server's environment leaves a file it cannot read as a missing variable.
70
+ - `requiredInProduction: true` on a field makes it required under `NODE_ENV=production` only: there it is refused at boot when missing, its `default` dropped and `optional` no longer applying; in development and tests it takes its `default`, stays `undefined` when optional, or is `''` when a `s.string` has neither, so `DISCORD_CLIENT_ID: s.string({ requiredInProduction: true })` types as `string` and needs no placeholder in the app and no second list of production keys; `s.string({ optional: true, requiredInProduction: true })` keeps `string | undefined`.
71
+ - `s.secret()` is a string of at least 32 characters required in production, which development and tests read as a derived value, so sessions survive a restart and nothing is committed: `DOWNLOAD_KEY: s.secret()`; a value set in the environment wins, and `kay env` lists it as a secret required in production (`secret: true` in JSON). `kay new` uses it. Only under `NODE_ENV` `development` or `test` (`kay dev` and `bun test` set them) is it derived, from the path, the name and a random seed kept in `.kay/dev-secret` (git-ignored, 0600, written on first use and again when empty or cut short, read once per process; under `test` the seed is only read, and one of the process stands in when there is none, exported as `KAY_DEV_SEED` so a subprocess spawned with the inherited environment derives the same secret, one given an environment of its own another; `bun test` writes nothing to `.kay` for a secret and needs no `KAY_SECRET`); under any other `NODE_ENV`, or none, a missing one refuses the boot as a plain `s.string({ minLength: 32 })` does, and a `.kay` that cannot be written is an error naming it and the variable to set; `testSite()` building islands into a `.kay` that cannot be written fails the same way, naming the folder and `islands: false`.
72
72
  - `NODE_ENV=production kay build` counts as production too: a prerendered page reading a flagged variable needs it set for the build, or reads it where the server runs.
73
- - `kay env [dir] [--compose <file>]... [--example <file>] [--write] [--format text|json]` lists every variable the project declares, without its environment and without running the server entry, whose own `defineEnv` calls it leaves out: the `defineEnv` schemas in the modules under `src` (imported, so their top-level code runs), the `s.Public` fields among them, the `env` schema of each extension in kay.config.ts (a library's, such as kayjs-mail's `MAIL_*` variables or kayjs-ai's provider keys and `AI_MODEL`, with no wiring), and kay's own `PORT`, `HOST`, `SITE_URL` and `KAY_SECRET`, and `KAY_PROXY_KEY` (required in production) and `KAY_PROXY_KEY_FILE` while `proxy.key` is set, and `KAY_MCP_KEY` (required in production) and `KAY_MCP_KEY_FILE` while `mcp.token` is `true`; a secret given as `{ env: 'NAME' }` lists that variable instead, and a value or a `{ file }` none. A schema built inside a function is not seen. A library's mailer built in one of those modules, such as `mailer()` from kayjs-mail, is listed once under that module, as its options set it up (`mailer({ optional: true })` does not make `MAIL_URL` required); the module under `src` an extension with an `env` names as its `serverModule` is imported too, whether or not it says `defineEnv`, and one that does not load leaves the extension's own list. Each has its `name`, `source`, `type`, `required` (`'always'`, `'production'` or `false`), its `default` and `description` when it has them; a module that fails to load is under `unread`.
73
+ - `kay env [dir] [--compose <file>]... [--example <file>] [--write] [--format text|json]` lists every variable the project declares, without its environment and without running the server entry, whose own `defineEnv` calls it leaves out: the `defineEnv` schemas in the modules under `src` (imported, so their top-level code runs), the `s.public` fields among them, the `env` schema of each extension in kay.config.ts (a library's, such as kayjs-mail's `MAIL_*` variables or kayjs-ai's provider keys and `AI_MODEL`, with no wiring), and kay's own `PORT`, `HOST`, `SITE_URL` and `KAY_SECRET`, and `KAY_PROXY_KEY` (required in production) and `KAY_PROXY_KEY_FILE` while `proxy.key` is set, and `KAY_MCP_KEY` (required in production) and `KAY_MCP_KEY_FILE` while `mcp.token` is `true`; a secret given as `{ env: 'NAME' }` lists that variable instead, and a value or a `{ file }` none. A schema built inside a function is not seen. A library's mailer built in one of those modules, such as `mailer()` from kayjs-mail, is listed once under that module, as its options set it up (`mailer({ optional: true })` does not make `MAIL_URL` required); the module under `src` an extension with an `env` names as its `serverModule` is imported too, whether or not it says `defineEnv`, and one that does not load leaves the extension's own list. Each has its `name`, `source`, `type`, `required` (`'always'`, `'production'` or `false`), its `default` and `description` when it has them; a module that fails to load is under `unread`.
74
74
  - `envFiles: { compose: 'compose.prod.yaml', example: '.env.example' }` in kay.config.ts (`compose` takes several files), or `kay env --compose <file>... --example <file>`, compares what the project declares with those files, and `kay check` runs it with no flag. With neither, both compare the project's root `compose*.yaml` and `docker-compose*.yaml` files (a name with `dev`, `development`, `test`, `local` or `override` in it is left out, as it holds the services around the app) and its `.env.example`, those that exist; `env: false` turns the comparison off. A line of `.env.example` no schema declares is an error unless compose uses it: a service sets it, a value interpolates it as `${HF_TOKEN}`, or a top-level secret or config reads it as `environment: HF_TOKEN`.
75
75
  - `kay env --write` appends every declared variable the example does not mention (kay's and the libraries' included, an optional one commented out beside its default), creating the file or keeping what it holds, and writes `--example`'s file, else the config's, else `.env.example`: a variable production needs (`required` not `false`) that no compose service sets, in `environment` (a map or a list, `${VAR:-x}` included) or an `env_file` (one the checkout leaves out, such as a gitignored `.env`, sets what the `.env.example` beside it lists, an empty line included, as the deploy fills that file from it), is an error, as is `KAY_PROXY_KEY` when `proxy.key` is set and no service sets it or `KAY_PROXY_KEY_FILE` (and `KAY_MCP_KEY` for `mcp: { token: true }`, with `KAY_MCP_KEY_FILE`); so is one the example does not list unless a compose service gives it a literal, and one the example lists that no schema declares, no service sets, no `${VAR}` of the compose file reads (`POSTGRES_PASSWORD`) and neither kay.config.ts nor a module it imports by relative path reads as `process.env.X` (`COMPOSE_*` and `DOCKER_*` apart, which Docker Compose reads). A `process.env.X` or `Bun.env.X` read in `src` outside tests (`NODE_ENV` apart) that nothing declares is a warning, which `kay check --fix` can declare for you ([Check](check-and-tools.md)). A file `bun build` names in a `package.json` script (a standalone binary's entry, in `src` or anywhere else, `--cwd` honoured) with the files it imports by relative path (`./x.js` for `x.ts` and a `.kay` file included), the content config (`src/content.config.ts`, or the config's `contentConfig`), and a file with a `// kay-env: raw` line are not checked, nor rewritten by `--fix`: they read the environment themselves, so a module the entry shares with the app is exempt for the whole app. `kay env` prints the findings and exits 1 on an error; `--format json` adds `findings`, as `kay check` prints its problems. A file named and missing, or a compose file that is not YAML, is an error; leave a key out to skip its half. `--compose` and `--example` resolve against the project root and, when given, replace the config's `env` wholesale. A module under `src` that does not load is an error and stops nothing being judged undeclared; an empty value (`FOO=`, `FOO: ''`) counts as unset, as `defineEnv` reads it. Raw reads are found in one-line `process.env.X`, `process.env['X']`, `Bun.env.X` and `const { X } = process.env`, not in a multi-line destructuring, a computed name or `import.meta.env`.
76
76
  - Server code imports it: a `.ts` module, a server fence, the server entry; an island never sees the server's environment.
77
- - A field wrapped in `s.Public(...)` is one an island may read, such as a map key or an analytics id, which a component reads as `publicEnv` from `kay`, typed from the `s.Public` fields of the `.ts` modules under `src` (found by reading them as text, so the field is written `s.Public(`); `kay env` lists it as `public`.
77
+ - A field wrapped in `s.public(...)` is one an island may read, such as a map key or an analytics id, which a component reads as `publicEnv` from `kay`, typed from the `s.public` fields of the `.ts` modules under `src` (found by reading them as text, so the field is written `s.public(`); `kay env` lists it as `public`.
78
78
  - It is read as `defineEnv` reads the rest, a missing or refused one stopping the boot, and reaches the browser as the module declaring it loads: an island reading `publicEnv` needs a module with `defineEnv` imported by the server.
79
- - The browser gets them from `/_kay/env.js`, which the server answers from its environment and the island entry imports before any island hydrates, so an executable, or a page prerendered at build time, carries the values of the environment it runs in (an executable embeds the `.ts` modules declaring `s.Public`, so it needs no `src` beside it); `kay build --static` writes that file with the build's.
79
+ - The browser gets them from `/_kay/env.js`, which the server answers from its environment and the island entry imports before any island hydrates, so an executable, or a page prerendered at build time, carries the values of the environment it runs in (an executable embeds the `.ts` modules declaring `s.public`, so it needs no `src` beside it); `kay build --static` writes that file with the build's.
80
80
  - The markup a prerendered page rendered holds the build's values, though: an island showing a variable that differs at runtime hydrates with a mismatch, so a page showing one renders per request.
81
- - The server refuses to boot, before any build starts, when an `s.Public` field has a name such as `STRIPE_SECRET`, `DB_PASSWORD`, `PRIVATE_KEY`, `ACCESS_TOKEN`, `API_KEY`, `SIGNING_KEY`, `SENTRY_DSN`, `JWT_SECRET`, `AWS_CREDENTIALS` or `DATABASE_URL`, or whose value is an address with a username and password in it (`postgres://user:pass@host/db`), which every visitor would read; keep those in `defineEnv` without `s.Public`. An `s.Public` field in a `.kay` file is refused too: declare it in a `.ts` module. The values served are those of the `.ts` modules of the app booting, not of another `pages()` app in the same process. A name ending in `_KEY` is refused too unless it says it is for the browser: `MAP_KEY`, `MAPBOX_KEY`, `PUBLISHABLE_KEY`, `PUBLIC_KEY`, `ANALYTICS_KEY`, `SITE_KEY`, `CAPTCHA_KEY`, `TURNSTILE_KEY` and `CLIENT_KEY` pass.
81
+ - The server refuses to boot, before any build starts, when an `s.public` field has a name such as `STRIPE_SECRET`, `DB_PASSWORD`, `PRIVATE_KEY`, `ACCESS_TOKEN`, `API_KEY`, `SIGNING_KEY`, `SENTRY_DSN`, `JWT_SECRET`, `AWS_CREDENTIALS` or `DATABASE_URL`, or whose value is an address with a username and password in it (`postgres://user:pass@host/db`), which every visitor would read; keep those in `defineEnv` without `s.public`. An `s.public` field in a `.kay` file is refused too: declare it in a `.ts` module. The values served are those of the `.ts` modules of the app booting, not of another `pages()` app in the same process. A name ending in `_KEY` is refused too unless it says it is for the browser: `MAP_KEY`, `MAPBOX_KEY`, `PUBLISHABLE_KEY`, `PUBLIC_KEY`, `ANALYTICS_KEY`, `SITE_KEY`, `CAPTCHA_KEY`, `TURNSTILE_KEY` and `CLIENT_KEY` pass.
82
82
  - Only the public variables leave the server, and nothing else of the environment reaches an island: a module reading `process.env` or `defineEnv`'s values fails the browser build.
83
83
  - Reading `publicEnv` when nothing is public throws; a name that is not public is a type error.
package/llms/files.md CHANGED
@@ -16,7 +16,7 @@ import { s, action } from 'kay'
16
16
  import { files } from 'kay/server'
17
17
  import { photos } from '../photos'
18
18
 
19
- export const upload = action(s.Object({ photo: s.File({ type: 'image/jpeg' }) }), async ({ photo }) => {
19
+ export const upload = action({ photo: s.file({ type: 'image/jpeg' }) }, async ({ photo }) => {
20
20
  photos.push(await files.put(photo, { folder: 'photos' }))
21
21
  }, { maxSize: '20mb' })
22
22
  ---
@@ -180,12 +180,12 @@ if upload.progress() !== undefined
180
180
 
181
181
  ### Files posted to an action
182
182
 
183
- - `s.File()` or `s.Files()` in the schema, `input(type="file" name="avatar")` in the form, and the handler gets a `File`, which `files.put` stores.
183
+ - `s.file()` or `s.files()` in the schema, `input(type="file" name="avatar")` in the form, and the handler gets a `File`, which `files.put` stores.
184
184
  - Forms posting to an action are sent as `multipart/form-data` unless they set `enctype`.
185
- - A file input left empty counts as no file, so `s.Optional(s.File())` works.
185
+ - A file input left empty counts as no file, so `s.file({ optional: true })` works.
186
186
  - An island passes a `File` or `Blob` anywhere in its input, nested ones included, and a `Blob` types as a field's `File`: `await upload({ avatar: input.files[0] })`.
187
- - On a top-level field, `s.File({ type: 'image/png' })` checks the file's bytes, not its name or declared type.
187
+ - On a top-level field, `s.file({ type: 'image/png' })` checks the file's bytes, not its name or declared type.
188
188
  - A file it refuses fails like any field, under its name in `errors` with the schema's `error` option when set.
189
189
  - A nested file is checked against the type it declares only.
190
190
  - A post sends 1 MB at most unless the action raises its `maxSize` (see [Protecting actions](action-protection.md)).
191
- - `s.File({ minSize, maxSize })` and `s.Files` take a size as an action's `maxSize` does, `'2mb'`, `'600kb'` or bytes. An action with no `maxSize` of its own takes as many bytes as its sized file fields add up to (a `Files` field counting its `maxItems` files, or ten) plus 64 KB for the other fields, never less than the app's, so the limit is written once on the field; an action's own `maxSize` wins.
191
+ - `s.file({ minSize, maxSize })` and `s.files` take a size as an action's `maxSize` does, `'2mb'`, `'600kb'` or bytes. An action with no `maxSize` of its own takes as many bytes as its sized file fields add up to (a `Files` field counting its `maxItems` files, or ten) plus 64 KB for the other fields, never less than the app's, so the limit is written once on the field; an action's own `maxSize` wins.
@@ -12,7 +12,8 @@
12
12
  - On the server a module outlives the request, so a value a page's, a layout's or an island's script writes to such a signal while the page renders, as `cart = items` seeding it from props, holds for that request only, and everything rendered after it reads it.
13
13
  - A module's `memo` is computed afresh on each read on the server.
14
14
  - `persisted.cookie('theme', 'light')` from `kay` is a signal that keeps its value across pages and visits in a cookie named `theme`, which the server reads too, so a page rendered for the request shows the kept value from the first paint, and answers with `Vary: Cookie`.
15
- - A page `kay build` prerendered renders a `persisted` signal's default, and the island corrects it as it hydrates.
15
+ - A page's `--- server` fence, which loads its data before the render, reads a `persisted.cookie()` signal by calling it: `open()` there is the request's value, decoded and checked against `values` as the render does, the default when the cookie is missing or refused, so the fence needs no `ctx.cookies` and no knowledge of the cookie's encoding. The page then answers with `Vary: Cookie`.
16
+ - A page `kay build` prerendered renders a `persisted` signal's default, in its server fence too, and the island corrects it as it hydrates.
16
17
  - The cookie is named as it is given, so it never reuses the name of a cookie the app sets itself.
17
18
  - `persisted` has one entry per storage, `persisted.cookie()`, `persisted.local()` and `persisted.session()`, each taking the options its storage can use, and a call always names its storage: a bare `persisted(name, value)`, which kept a cookie without saying so, works until 1.108 and `kay upgrade` writes `.cookie` for it (`deprecated-persisted-call`). The `storage` option is gone since 1.105.
18
19
  - A query param is not persisted but `queryParam`, below: `persisted.query(name, value, options)` is `queryParam(name, { default: value, ...options })`, works until 1.108 and `kay upgrade` rewrites it (`deprecated-persisted-query`).
@@ -13,12 +13,12 @@ Declare the actions as for any call, one that stores a row and one that removes
13
13
  import { action, s } from 'kay'
14
14
  import { removeTodo, saveTodo } from '../data'
15
15
 
16
- export const save = action(s.Object({ id: s.String({ maxLength: 40 }), title: s.String({ minLength: 1, maxLength: 200 }), rev: s.Number() }), async (todo, ctx) => {
16
+ export const save = action({ id: s.string({ max: 40 }), title: s.string({ min: 1, max: 200 }), rev: s.number() }, async (todo, ctx) => {
17
17
  const held = await saveTodo(todo)
18
18
 
19
19
  return held.conflict ? ctx.deny(409, { data: held.row }) : held.row
20
20
  })
21
- export const remove = action(s.Object({ id: s.String({ maxLength: 40 }) }), async ({ id }) => removeTodo(id))
21
+ export const remove = action({ id: s.string({ max: 40 }) }, async ({ id }) => removeTodo(id))
22
22
  ---
23
23
  Todos
24
24
  ```
package/llms/mcp.md CHANGED
@@ -39,7 +39,7 @@ expect(await site.mcp.call('add_note', { title: 'Milk' })).toMatchObject({ isErr
39
39
  - A route's `detail.tool` is `true`, a description, or `{ name, description }`, as an action's. Its tool is named by `tool.name` else its `operationId` (a route setting only `tool.name` takes it as its `operationId`), made a safe name (`users.list` is `users_list`, a clash `_2`), described by `tool`'s description else its `summary` and `description`, its input one JSON Schema of the path params, query and JSON body, merged by name.
40
40
  - Left out: `detail: { hide: true }` routes, `tool` or not (`hidden-tool` in `kay check`), websockets, a route whose body is files, text or bytes, an action holding a file, an action in a file whose pages have route params (a post from no page cannot name one), and `in: header` parameters. `tools/list` is served behind the API directory's `_guard.ts` as the document is, and with `guards: { default: 'closed' }` it is refused (403) unless the guards cover every module; `initialize` and `ping` stay open, and a call runs the guards of its own route.
41
41
  - A route answering every method, `.all()`, that sets `tool` is a tool per method; a `tool.name` takes the method as a suffix, `echo_get`.
42
- - An action is a tool only when its third argument sets `tool`: `true`, a description, or `{ name, description }`; its name is the export in snake case, `addNote` is `add_note`, a clash `add_note_2`, and its input schema is the action's as JSON: `s.Integer()` and `s.Numeric()` read as a number, not also as the text a form sends (which a call still takes), and a top-level body or query field with a `default` is left out of `required`, as a call omitting it gets the default.
42
+ - An action is a tool only when its third argument sets `tool`: `true`, a description, or `{ name, description }`; its name is the export in snake case, `addNote` is `add_note`, a clash `add_note_2`, and its input schema is the action's as JSON: `s.int()` and `s.number()` read as a number, not also as the text a form sends (which a call still takes), and a top-level body or query field with a `default` is left out of `required`, as a call omitting it gets the default.
43
43
  - A name is made of letters, digits and `_`, at most 64 characters.
44
44
  - A call is dispatched through the whole app as a fetch to the route's or action's URL would be, so its guards, `rateLimit`, body limit, schema validation and `ctx.locals` are the web path's; `ctx.params` and `ctx.url` of an action are read as for a script's post from no page.
45
45
  - It carries the caller's `Authorization` (not the endpoint's own `mcp.token` bearer), `Cookie`, `Accept-Language` and `User-Agent`, and rate limits count the caller's address as `proxy` reads it, not the server's.
@@ -50,6 +50,7 @@ expect(await site.mcp.call('add_note', { title: 'Milk' })).toMatchObject({ isErr
50
50
  - A refused call is a result with `isError`: the schema's field errors, the `ctx.fail` data and status as `{ status, errors, data }` JSON, a route's own refusal text, a redirect naming where it leads. The agent corrects and calls again.
51
51
  - A guard answering 401 makes the endpoint answer 401 with `WWW-Authenticate: Bearer resource_metadata="<site>/.well-known/oauth-protected-resource"`, how a client learns to sign in (kay serves that document when kayjs-auth's OAuth server is on: see its "OAuth server for MCP clients"); any other refusal, 403 included, is a result. Only a guard's 401 does: a route answering 401 itself is a result too. A refused `tools/list` answers the same way (a redirect counting as a 401), as a JSON-RPC error. It keeps the guard's response headers, `Retry-After` of a 429 among them. A `tools/call` of a name no tool has is refused the same way, so names cannot be probed; a call to a tool runs its own guards.
52
52
  - A result is JSON as text, and `structuredContent` when an object; any other type read as its size. A route's object `response` is the tool's `outputSchema`, with no `detail.tool.output` ([action protection](action-protection.md#offering-an-action-to-agents)).
53
+ - Until 2.0, an app that did not set `endpoints.mcp` is answered at `/mcp` as well, in place, under the same limits, key and checks, unless a page, endpoint or file serves `/mcp`, which keeps it. Only a POST is taken there, so a `[...rest]` or `[slug]` page still answers GET and DELETE; only an exact route at `/mcp` takes POST from kay.
53
54
  - `/_kay/mcp` (`endpoints.mcp`) is claimed like a route: a page, endpoint or file serving it stops the boot, and `kay check` reports it.
54
55
  - `unguarded-tool` warns, with `mcp`, of a tool action with a `honeypot`, `minTime` or `proofOfWork` that no guard covers: an agent calls it without the form those protections ask of a person. A `...spread` in the options counts as one of them, so it warns; options that are not an object literal, `action(schema, run, options)`, are not read, so the action is not taken for a tool.
55
56
  - `site.mcp.initialize()` resolves with `{ serverInfo, instructions }` of the `initialize` answer, `instructions` being `mcp: { instructions }` or undefined.
@@ -45,7 +45,7 @@ const dispose = mount(Panel, document.querySelector('#panel')!, { title: 'Ticket
45
45
  ### Navigating from code
46
46
 
47
47
  - `navigate('/todos/1')`, imported from `kay`, goes to a page as a link would (the mount point and the current locale's prefix put on as on any `href`, `/todos/1` on a French page going to `/fr/todos/1`, a path already prefixed or another site's URL left as written; a module that gets `navigate` through a dynamic `import('kay')` is not covered, so import it statically), `{ replace: true }` taking the current history entry's place, `{ scroll: 'keep' }` leaving the window scrolled where it is instead of going to the top, `{ transition: false }` swapping without a view transition; another site's page loads, so a `?next=` param goes through `localPath()` as a redirect's does, and a `javascript:` URL throws, as it would run in the page; `mailto:`, `tel:` and other schemes go to the browser as a link would. A link or `navigate()` that a redirect takes to another site loads that page fully rather than swapping it in.
48
- - `navigate.query({ sort: 'name', page: null })` goes to the current page with those params set and a null, undefined or empty one dropped, the others and the path kept and the hash left out, keeping the scroll and the focus as `refresh()` does: a filter or a sort picked in place. It takes the options of `navigate()` and resolves as it does. `navigate({ query })`, which did this under the name that goes to a page, works until 1.108, `kay upgrade` rewriting it (`deprecated-navigate-query`). A query that is state of the page, not a one-off change, is a `queryParam` signal ([state](islands-state-to-ids.md#shared-and-persisted-state)).
48
+ - `navigate.query({ sort: 'name', page: null })` goes to the current page with those params set (a list sets one param once per item, `{ tag: ['a', 'b'] }` giving `?tag=a&tag=b`) and a null, undefined or empty one dropped, the others and the path kept and the hash left out, keeping the scroll and the focus as `refresh()` does: a filter or a sort picked in place. It takes the options of `navigate()` and resolves as it does. `navigate({ query })`, which did this under the name that goes to a page, works until 1.108, `kay upgrade` rewriting it (`deprecated-navigate-query`). A query that is state of the page, not a one-off change, is a `queryParam` signal ([state](islands-state-to-ids.md#shared-and-persisted-state)).
49
49
  - `withQuery({ page: 2, sort: null })` from `kay`, in a server fence, a template or an island (where it follows the address, so the link is built again after each `navigate.query()`, swap, Back and `queryParam` write), returns the path of the current page with those params set by the rule of `navigate.query()`, the other params kept and the hash left out, to link to it with one filter changed: `a(href={withQuery({ page: 2 })}) Next`. The path is the site's own, so `base`, `trailingSlash` and the locale prefix are put on by the link as on any `href`; in a fence it reads the request, so it throws in a page rendered once at build time.
50
50
  - `refresh()` from `kay` runs the current page's loads again and shows what they return, keeping the scroll, the focus and every island whose props did not change, as a call to an action does by itself once it went through.
51
51
  - `refresh('cart')` or `refresh(['cart', 'user'])` sends and swaps only the elements of the page reading the loads of its fence that bind those names, and leaves the rest of the page as it is: [rendering](rendering.md#refreshing-some-loads).
@@ -66,7 +66,7 @@ await notifications.erase(userId)
66
66
 
67
67
  ### Push to a person's devices
68
68
 
69
- `push()` in the extensions turns on web push: kay keeps the subscriptions in the app's store, signs and encrypts each push, and adds the `push` and `notificationclick` handlers to its service worker, which it serves and registers on every page with or without `offline`. When the browser rotates a subscription the worker subscribes again with the served key and posts it to the subscribe route with the session cookie, so the person keeps their pushes without reopening the page (a person signed out by then is not re-subscribed; a worker that could not reach the server keeps the new subscription, and a page using `webPush` posts the one the browser holds on load when it differs from the last one the server accepted, kept in `localStorage`, naming that one so the server takes it only from the person who owns it, never from whoever signed in next; a signed-out visitor's 401 is not repeated in that tab, and `unsubscribe()` or `subscribe()` leaves no stale record); an app that turns `offline` off while listing `push()` has the earlier worker's caches deleted. A person who subscribed gets every `notify()` as a push too, with no second call; `push: false` in its options keeps one in the inbox alone:
69
+ `push()` in the extensions turns on web push: kay keeps the subscriptions in the app's store, signs and encrypts each push, and adds the `push` and `notificationclick` handlers to its service worker, which it serves and registers on every page with or without `offline`. When the browser rotates a subscription the worker subscribes again with the served key and posts it to the subscribe route with the session cookie, so the person keeps their pushes without reopening the page (a person signed out by then is not re-subscribed; a worker that could not reach the server keeps the new subscription, and a page using `webPush` posts the one the browser holds on load when it differs from the last one the server accepted, kept in `localStorage`, naming that one so the server takes it only from the person who owns it, never from whoever signed in next; a signed-out visitor's 401 is not repeated in that tab, and `unsubscribe()` or `subscribe()` leaves no stale record); an app that turns `offline` off while listing `push()` has the earlier worker's caches deleted. A person who subscribed gets every `notify()` as a push too, with no second call; `push: false` in its options keeps one in the inbox alone, and the push carries the person's unread count, which the worker shows as the installed app's badge (`badge: false` leaves the badge alone):
70
70
 
71
71
  ```ts
72
72
  // kay.config.ts
@@ -109,6 +109,8 @@ button(onClick={async () => { await webPush.enable() }}) Notify me
109
109
  - Live: the route reads the inbox as `cached(..., { live: true })` does, so every open tab updates within about a second of a `notify`, a read or an erase, in any process sharing a cache store; a hidden tab catches up when shown ([Following cached values](live-values.md#following-cached-values)). The inbox is cached in the process's memory only, never in the cache store.
110
110
  - `Bell` takes `label` (the `ui.bell.label` message, "Notifications") and `placement`. A page with a Bell is the signed-in visitor's own: `private, no-cache` and rendered per request, as one reading `ctx` is. Put the Bell in a layout or a page, not inside an island: it reads the visitor on the server. Notifications from another source go through `items` ([Bell](../../ui/llms/page-layout-palette-and-trees.md#bell)).
111
111
  - Erasing a person: call `notifications.erase(userId)`, which also deletes their push subscriptions, with the rest of the function in [Privacy](privacy.md#erase-a-person-on-request).
112
- - Push: `sendPush(userId, { title, body?, url?, tag?, icon? }, { ttl?, urgency?, topic? })` answers `{ sent, dropped, failed }`. Title is 1 to 200 characters, body up to 500, tag 64; `url` and `icon` are kept as `notify` keeps a link, and a path goes under `base` in the worker. The payload is RFC 8291 aes128gcm with a VAPID (RFC 8292) JWT, on Web Crypto with no dependency. A push service answering 404 or 410 deletes that subscription; any other refusal counts as `failed` and keeps it. A person keeps their newest 10 devices. A subscription no push has reached for `push({ keep: '180d' })` is purged by an hourly sweep, a push that gets through counting as reached (`createdAt` then answers that time, written at most once a day). Idleness counts from the later of that date and the first sweep a store ever ran, so a subscription stored before an upgrade is never purged for its age alone, and the first purge comes `keep` after the upgrade. `pushSubscriptions.list(userId)` and `.erase(userId)` read and delete them.
112
+ - App badge: the Bell sets `navigator.setAppBadge(unread)`, and `clearAppBadge()` at 0, each time its count changes once its list has loaded, wherever the browser has the Badging API (an installed app on desktop Chrome and Edge, Android and iOS 16.4+, nothing elsewhere); `appBadge={false}` on `Bell` or `BellInbox` leaves it alone, and it follows `unread` of a custom source. A push from `notify()` carries `badge` (the count after the new notification, `notify(..., { badge: false })` leaves it out) and the worker sets it while no page is open; `sendPush` takes `badge` (0 to 999999, 0 clears) for a count of your own.
113
+ - The badge follows the page: a sign-out leaves the last count on the icon until the next visit, "Mark all as read" on one device reaches another's badge at its next page load (a push needs a title, so it cannot update a badge silently), and two quick `notify` calls may arrive out of order and leave the lower count until then. A Bell on a custom `items` list owns the badge too, so a page with two Bells of different counts sets `appBadge={false}` on one.
114
+ - Push: `sendPush(userId, { title, body?, url?, tag?, icon?, badge? }, { ttl?, urgency?, topic? })` answers `{ sent, dropped, failed }`. Title is 1 to 200 characters, body up to 500, tag 64; `url` and `icon` are kept as `notify` keeps a link, and a path goes under `base` in the worker. The payload is RFC 8291 aes128gcm with a VAPID (RFC 8292) JWT, on Web Crypto with no dependency. A push service answering 404 or 410 deletes that subscription; any other refusal counts as `failed` and keeps it. A person keeps their newest 10 devices. A subscription no push has reached for `push({ keep: '180d' })` is purged by an hourly sweep, a push that gets through counting as reached (`createdAt` then answers that time, written at most once a day). Idleness counts from the later of that date and the first sweep a store ever ran, so a subscription stored before an upgrade is never purged for its age alone, and the first purge comes `keep` after the upgrade. `pushSubscriptions.list(userId)` and `.erase(userId)` read and delete them.
113
115
  - Push store: `store.push` of kay.config.ts, a `PushStore` (`add`, `list`, `delete`, `erase`, and optionally `touch(endpoint, at)` and `prune(before)` for the age purge, which kay runs only for a store that has both, `prune` counting idleness from its first call as above): `sqliteData` and `pgData` fill it (the `kay_push_subscriptions` table), memory otherwise.
114
116
  - Push routes: `GET /_kay/push/key`, `POST /_kay/push/subscribe` and `/unsubscribe` (which ends the `kay_push_device` cookie), whose user comes from the request (401 when nobody is signed in) and which refuse another site; a subscription's endpoint must be https at a public address in production.
package/llms/project.md CHANGED
@@ -98,7 +98,7 @@ export default defineConfig({
98
98
  - A feature key is `false` for off, `true` for its defaults or an object of options: `robots`, `sitemap`, `assets.favicon`, `security`, `ops.health`, `preview`, `client.offline`, `ops.metrics`, `openapi`, `mcp`, `proxy`, `assets.images.formats.avif` and the rate limits. `defineConfig` refuses a key it does not know in any option bag, as a type error.
99
99
  - A list that may come from a CMS or a database is the list, or a function returning it (or a promise of it): `cors.origins`, `security.hosts`, `assets.images.remote.hosts`, `proxy.trusted`, `redirects`, `robots.disallow`, `robots.allow` and `i18n.paths`. Kay calls it once as the config loads, `kay dev` again after a change to the file.
100
100
  - Keys are grouped by concern: `client` (what the browser is given: `links`, `offline`, `search`, ...), `assets` (`images`, `fonts`, `favicon`, `manifest`, `publicCache`), `ops` (`observe`, `health`, `metrics`, `jobs`), `endpoints` (where the app's API and each feature are served) and `i18n: { locales, default, mode }`, where `mode` is `'prefix'` (the default locale unprefixed), `'always'` or `{ domains }`. The old top-level keys work until 1.108 (`deprecated-client-keys`, `deprecated-config-groups`, `deprecated-i18n-keys` rewrite them).
101
- - `endpoints` holds every route the config moves, in one place: `{ api: '/api', openapi: '/api/openapi.json', mcp: '/_kay/mcp', health: '/_kay/health', metrics: '/_kay/metrics', jobs: '/_kay/jobs' }`, each an absolute path of plain segments with no trailing slash, and `api`, `openapi` and `mcp` none under `/_kay` when you set them. Every default is under `/_kay` but the app's API (and its OpenAPI document and reference page, which follow it). The reference page is `openapi: { reference: true }` or `{ reference: { path } }`. `serve.apiPrefix` and the `path` of `openapi`, `mcp`, `health`, `metrics` and `jobs`, and `openapi.referencePath`, work until 1.108 (`deprecated-route-keys` rewrites them). An app that did not move `mcp` or `metrics` keeps `/mcp` (a 308 to the new path) and `/metrics` (answered as well) until 1.108.
101
+ - `endpoints` holds every route the config moves, in one place: `{ api: '/api', openapi: '/api/openapi.json', mcp: '/_kay/mcp', health: '/_kay/health', metrics: '/_kay/metrics', jobs: '/_kay/jobs' }`, each an absolute path of plain segments with no trailing slash, and `api`, `openapi` and `mcp` none under `/_kay` when you set them. Every default is under `/_kay` but the app's API (and its OpenAPI document and reference page, which follow it). The reference page is `openapi: { reference: true }` or `{ reference: { path } }`. `serve.apiPrefix` and the `path` of `openapi`, `mcp`, `health`, `metrics` and `jobs`, and `openapi.referencePath`, work until 1.108 (`deprecated-route-keys` rewrites them). An app that did not move `mcp` or `metrics` keeps `/metrics` answering as well until 1.108, and `/mcp` answers the MCP endpoint in place (not redirected) until 2.0.
102
102
  - `assets.images` is `{ remote: { hosts, maxSize, timeout }, formats: { quality, webp, avif }, limits: { variants, queue }, rateLimit, ttl, widths, ... }`; `remote: [...]` is hosts alone.
103
103
  - A duration key is `ttl` for how long data lives, `timeout` for how long to wait and `maxAge` only for the HTTP or cookie attribute of that name.
104
104
  - `proxy: false` is none, `proxy: true` is one proxy in front, `proxy: { hops: 2 }` two, `{ header }` a header the proxy sets, `{ key: { header: 'x-upstream-key' }, open }` refuses requests without the shared key ([Production](proxy-and-security.md#behind-a-proxy)).
@@ -13,7 +13,7 @@ How many times a client may do something in a window, on actions, in guards and
13
13
  import { s, action } from 'kay'
14
14
 
15
15
  export const subscribe = action(
16
- s.Object({ email: s.String({ format: 'email' }) }),
16
+ { email: s.string({ format: 'email' }) },
17
17
  async ({ email }) => email.length,
18
18
  { protect: { rateLimit: { max: 5, window: '1m' } } },
19
19
  )
package/llms/recipes.md CHANGED
@@ -24,7 +24,7 @@ export const Todo = defineTable('todo', f => ({
24
24
  import { s } from 'kay'
25
25
  import { defineEnv } from 'kay/server'
26
26
 
27
- export const env = defineEnv(s.Object({ DATABASE_URL: s.String() }))
27
+ export const env = defineEnv({ DATABASE_URL: s.string() })
28
28
  ```
29
29
 
30
30
  ```ts
@@ -53,13 +53,13 @@ import { s, action } from 'kay'
53
53
  import { db } from '../db'
54
54
  import { Todo } from '../db/todo'
55
55
 
56
- export const create = action(s.Object({
57
- title: s.String({ pattern: '\\S', maxLength: 120, error: 'Write a title' }),
58
- }), async ({ title }) => {
56
+ export const create = action({
57
+ title: s.string({ pattern: '\\S', max: 120, error: 'Write a title' }),
58
+ }, async ({ title }) => {
59
59
  await db.repo(Todo).write.insertOne({ title: title.trim() })
60
60
  })
61
61
 
62
- export const remove = action(s.Object({ id: s.Integer() }), async ({ id }) => {
62
+ export const remove = action({ id: s.int() }, async ({ id }) => {
63
63
  await db.repo(Todo).write.deleteOne({ id })
64
64
  })
65
65
 
@@ -88,11 +88,11 @@ import { s, action } from 'kay'
88
88
  import { db } from '../../db'
89
89
  import { Todo } from '../../db/todo'
90
90
 
91
- export const save = action(s.Object({
92
- id: s.Integer(),
93
- title: s.String({ pattern: '\\S', maxLength: 120, error: 'Write a title' }),
94
- done: s.Boolean(),
95
- }), async ({ id, title, done }, ctx) => {
91
+ export const save = action({
92
+ id: s.int(),
93
+ title: s.string({ pattern: '\\S', max: 120, error: 'Write a title' }),
94
+ done: s.boolean(),
95
+ }, async ({ id, title, done }, ctx) => {
96
96
  await db.repo(Todo).write.updateOne({ title: title.trim(), done }, { id })
97
97
 
98
98
  return ctx.redirect('/todos')
@@ -201,7 +201,7 @@ An action is covered by the guards of its folder; one that lives elsewhere check
201
201
  // src/routes/dashboard/users/index.kay, in its server fence
202
202
  import { auth } from '../../../auth'
203
203
 
204
- export const ban = action(s.Object({ id: s.String() }), async ({ id }, ctx) => {
204
+ export const ban = action({ id: s.string() }, async ({ id }, ctx) => {
205
205
  const user = await ctx.locals.auth.requireUser()
206
206
 
207
207
  if (!auth.isGranted('admin', user))
@@ -243,11 +243,11 @@ import { s } from 'kay'
243
243
  import { collection } from 'kay/content'
244
244
 
245
245
  export const posts = collection('content/posts', {
246
- schema: s.Object({
247
- title: s.String(),
248
- date: s.Date(),
249
- tags: s.Array(s.String(), { default: [] }),
250
- draft: s.Optional(s.Boolean()),
246
+ schema: s.object({
247
+ title: s.string(),
248
+ date: s.date(),
249
+ tags: s.list(s.string(), { default: [] }),
250
+ draft: s.boolean({ optional: true }),
251
251
  }),
252
252
  route: '/blog/:slug',
253
253
  draft: post => post.data.draft === true,
package/llms/rooms.md CHANGED
@@ -14,7 +14,7 @@ const chats = rooms<{ from: string, text: string }, string>()
14
14
 
15
15
  export default api()
16
16
  .ws('/:room', {
17
- body: s.Object({ text: s.String() }),
17
+ body: s.object({ text: s.string() }),
18
18
  response: chats.response,
19
19
  open(ws) {
20
20
  chats.join(ws, ws.data.params.room, ws.data.user.name)
@@ -70,9 +70,9 @@ const sendBoard = games.coalesce(async room => ({
70
70
 
71
71
  export default api()
72
72
  .ws('/:room', {
73
- body: s.Union([
74
- s.Object({ type: s.Literal('say'), text: s.String() }),
75
- s.Object({ type: s.Literal('play'), cell: s.Integer() }),
73
+ body: s.union([
74
+ s.object({ type: s.literal('say'), text: s.string() }),
75
+ s.object({ type: s.literal('play'), cell: s.int() }),
76
76
  ]),
77
77
  response: games.response,
78
78
  open(ws) {
@@ -31,7 +31,7 @@ export function GET({ params }: EndpointContext) {
31
31
  import type { EndpointContext } from 'kay'
32
32
  import { s } from 'kay'
33
33
 
34
- export const page = { rateLimit: { max: 60, window: '1m' }, maxSize: '1mb', query: s.Object({ test: s.Optional(s.Boolean()) }) }
34
+ export const page = { rateLimit: { max: 60, window: '1m' }, maxSize: '1mb', query: s.object({ test: s.boolean({ optional: true }) }) }
35
35
 
36
36
  export async function POST({ request, query }: EndpointContext) {
37
37
  await handleEvent(await request.json(), query.test === true)
package/llms/routing.md CHANGED
@@ -25,7 +25,7 @@ The `query` key of `page` is the schema `ctx.query` is read against, so `ctx.que
25
25
  --- server
26
26
  import { s } from 'kay'
27
27
 
28
- export const page = { query: s.Object({ q: s.String(), page: s.Optional(s.Integer()) }) }
28
+ export const page = { query: s.object({ q: s.string(), page: s.int({ optional: true }) }) }
29
29
 
30
30
  const { q, page: current } = ctx.query
31
31
  ---
@@ -62,7 +62,7 @@ a(href={route('/blog/:page?', { page: 2 }, { query: { q: 'kay' }, hash: 'top' })
62
62
  --- server
63
63
  import { localPath, s } from 'kay'
64
64
 
65
- export const page = { query: s.Object({ next: s.Optional(s.String()) }) }
65
+ export const page = { query: s.object({ next: s.string({ optional: true }) }) }
66
66
 
67
67
  if (ctx.params.id === 'latest') ctx.redirect(localPath(ctx.query.next, '/todos/42'))
68
68
  if (ctx.params.id === 'secret') ctx.deny(403, { message: 'Members only' })
@@ -257,12 +257,12 @@ export default (value: string) =>
257
257
  The fence's `ctx`:
258
258
 
259
259
  - `ctx.params`, typed from the file name, `ctx.url`, `ctx.request`
260
- - `ctx.query`, the search params, read against the schema the page sets as the `query` key of `page`: `export const page = { query: s.Object({ q: s.String(), page: s.Optional(s.Integer()) }) }` types `ctx.query.page` as a `number | undefined`.
260
+ - `ctx.query`, the search params, read against the schema the page sets as the `query` key of `page`: `export const page = { query: s.object({ q: s.string(), page: s.int({ optional: true }) }) }` types `ctx.query.page` as a `number | undefined`.
261
261
  - Each is read as a form field is (a number from decimal text, a list from a repeated name, `true` from `on`), one left out takes its `default`, and a query the schema refuses renders `_error.kay` with status 400, once the guards let the request through.
262
- - A field with `lenient: true` in its options (`period: s.UnionEnum(['24h', '7d'], { default: '24h', lenient: true })`) reads a value its schema refuses, a stale link's, as its default, or leaves it out when it has none, and `ctx.query` is typed by the real schema (`'24h' | '7d'`); a field without it, or a refused one with no default and required, still answers 400, and an island's `queryParam` already reads a refused value as its default.
262
+ - A field with `lenient: true` in its options (`period: s.enum(['24h', '7d'], { default: '24h', lenient: true })`) reads a value its schema refuses, a stale link's, as its default, or leaves it out when it has none, and `ctx.query` is typed by the real schema (`'24h' | '7d'`); a field without it, or a refused one with no default and required, still answers 400, and an island's `queryParam` already reads a refused value as its default.
263
263
  - A layout declares the params it reads the same way, in its own `page`, and the pages under it do not repeat the schema: `ctx.query` is read once against every `query` of the route's layouts and its page merged, so a layout and its page see the same typed values.
264
264
  - A layout's `ctx.query` is typed by the layouts above it and its own, a page's by every layout above it and its own.
265
- - A name two of them declare is accepted when their schemas are the same, and refused when they differ: `kay check` reports it on the later file for schemas written inline as `s.Object({ ... })`, and the render fails for any other. The merged schema takes its object keywords, such as `additionalProperties`, from the innermost file.
265
+ - A name two of them declare is accepted when their schemas are the same, and refused when they differ: `kay check` reports it on the later file for schemas written inline as `s.object({ ... })`, and the render fails for any other. The merged schema takes its object keywords, such as `additionalProperties`, from the innermost file.
266
266
  - A page with `layouts: false` reads none of the dropped layouts' params. `query` on a special page is reported, "Only a page or a layout declares its query".
267
267
  - Without a schema each name reads as its text, a repeated one as a list, typed `unknown`; the raw text is `ctx.url.searchParams`.
268
268
  - An island reads and writes one param the same way with `queryParam` (see islands).
package/llms/schemas.md CHANGED
@@ -11,7 +11,7 @@ A shape the server validates and an island types is written once, as a schema in
11
11
  import type { Static } from 'kay'
12
12
  import { s } from 'kay'
13
13
 
14
- export const choice = s.Union([s.Literal('smash'), s.Literal('pass')])
14
+ export const choice = s.union([s.literal('smash'), s.literal('pass')])
15
15
  export type Choice = Static<typeof choice>
16
16
  ```
17
17
 
@@ -22,7 +22,7 @@ An API module, a server fence and an `_actions.kay` import the schema; an island
22
22
  import { action, s } from 'kay'
23
23
  import { choice } from '../schemas'
24
24
 
25
- export const castVerdict = action(s.Object({ choice }), input => input.choice)
25
+ export const castVerdict = action({ choice }, input => input.choice)
26
26
  ---
27
27
  ```
28
28
 
@@ -42,9 +42,14 @@ const { initial } = props<{ initial: Choice }>()
42
42
 
43
43
  ### Schemas
44
44
 
45
- - `s` from `kay` is Elysia's schema builder under a name that leaves `t` to translations, there to save an import in server fences and server modules, `defineEnv` and API modules included.
46
- - `Schema` from `kay` is the type of what `s` builds, and what `action`, `defineEnv`, `collection`, an API route's `query` and a library's schema option take: name it in a signature, never TypeBox's `TSchema`. `Static<typeof schema>` reads the TypeScript type. Elysia and TypeBox are implementation details of kay; `s.typebox` is the TypeBox builder itself for the rare case `s` lacks, and unstable, as a change of Elysia may change it.
47
- - The browser has no Elysia, which reads `Bun`: there `s.Object(...)` and the rest build an inert stand-in, so a module shared by the server and an island may build its schemas as it loads, with no validator in the island's chunk, only the calls and their literals.
45
+ - `s` from `kay` is kay's own schema builder, over TypeBox so a schema stays JSON Schema data for OpenAPI, MCP and the form rules, under a name that leaves `t` to translations: lowercase builders with short options, there to save an import in server fences and server modules, `defineEnv` and API modules included.
46
+ - The builders: `s.string({ min, max, pattern })`, `s.email()`, `s.url()`, `s.slug()`, `s.int({ min, max })`, `s.number({ min, max })`, `s.boolean()`, `s.date()` (read as a `Date`), `s.enum(values)` or `s.enum(record)` (a record gives its keys), `s.literal(value)`, `s.union([a, b])`, `s.object(shape)`, `s.record(value)`, `s.list(item, { min, max })`, `s.file({ type, minSize, maxSize })`, `s.files()`, `s.secret()` and `s.public(field)` (the last two for `defineEnv`).
47
+ - Every builder takes the same field options: `optional: true` (the field may be left out, typed `T | undefined`), `default`, `error` (a text, or a function called in the request's locale), `label`, `description` and `example`. Any other option is a JSON Schema keyword, kept as written.
48
+ - Strict by default: a string is at most 10,000 characters, a list at most 1,000 items and a file size is `'2mb'`, `'600kb'` or bytes, each unless the options give another; `s.object` marks its shape closed, and `s.object(shape, { extra: 'strip' })` leaves it open. What a closed shape does with a key it lacks depends on who reads it: kay refuses it where it reads the schema itself (collection frontmatter, `defineEnv`, a JSON Schema check by `ask`); a body, a response and a record of an action are read by Elysia, which drops it and answers 200 (refusing it is for a later minor); the search params of a page or an API route and a request's headers are dropped whatever the shape says, and an API route's `cookie` schema ignores the cookies it does not name, as a third party sets some.
49
+ - A plain record of schemas is the object schema wherever a schema is taken: `action({ title: s.string() }, handler)` and `defineEnv({ PORT: s.int({ default: 3000 }) })`, so `s.object()` is rarely written. A record is strict as `s.object` is, and kay's own form fields (the honeypot, the stamp) are not its keys.
50
+ - The PascalCase builders of 1.x, `s.String`, `s.Object`, `s.Optional(field)`, `s.UnionEnum`, `s.UnionKeys`, `s.Numeric` and the rest, are Elysia's under their old names and work until 2.0: `kay upgrade` rewrites them (`deprecated-schema-builders`). A schema built with Elysia's `t` is still a `Schema`.
51
+ - `Schema` from `kay` is the type of what `s` builds, and what `action`, `defineEnv`, `collection`, an API route's `query` and a library's schema option take: name it in a signature, never TypeBox's `TSchema`. `Static<typeof schema>` reads the TypeScript type. Elysia and TypeBox are implementation details of kay: `s` has no door to TypeBox's own builders, and a schema it builds is JSON Schema data.
52
+ - The browser has no Elysia, which reads `Bun`: there `s.object(...)` and the rest build an inert stand-in, so a module shared by the server and an island may build its schemas as it loads, with no validator in the island's chunk, only the calls and their literals.
48
53
  - The stand-in only passes into another builder: reading a key of one, or validating with it, throws in the browser. An island reads the type, `Static<typeof schema>`, and the server validates.
49
54
  - An island reads a schema's type, not its value: `import type { Choice } from '../schemas'`, or `import type { choice } from '../schemas'` for `Static<typeof choice>`, is erased from the browser build; a plain `import { choice }` works too, keeping the inert stand-in and the schema's literal in the chunk.
50
55
  - `Static<typeof schema>` and `InputOf<typeof action>` are types from `kay` and cost the browser nothing.
package/llms/server.md CHANGED
@@ -53,9 +53,9 @@ Mount it from `src/plugins/session.ts` (`export default sessions`, see above), o
53
53
  --- server
54
54
  import { s, action } from 'kay'
55
55
 
56
- const credentials = s.Object({
57
- email: s.String({ maxLength: 254 }),
58
- password: s.String(),
56
+ const credentials = s.object({
57
+ email: s.string({ max: 254 }),
58
+ password: s.string(),
59
59
  })
60
60
 
61
61
  export const signIn = action(credentials, async (input, ctx) => {
@@ -95,10 +95,10 @@ export const signOut = action(async ctx => {
95
95
  --- server
96
96
  import { s, action } from 'kay'
97
97
 
98
- const credentials = s.Object({
99
- email: s.String({ maxLength: 254 }),
100
- password: s.String(),
101
- remember: s.Optional(s.Boolean()),
98
+ const credentials = s.object({
99
+ email: s.string({ max: 254 }),
100
+ password: s.string(),
101
+ remember: s.boolean({ optional: true }),
102
102
  })
103
103
 
104
104
  export const signIn = action(credentials, async (input, ctx) => {
package/llms/site.md CHANGED
@@ -37,7 +37,7 @@ import { s } from 'kay'
37
37
  import { collection } from 'kay/content'
38
38
 
39
39
  export const posts = collection('content/posts', {
40
- schema: s.Object({ title: s.String(), date: s.Date() }),
40
+ schema: s.object({ title: s.string(), date: s.date() }),
41
41
  })
42
42
  ```
43
43
 
@@ -120,7 +120,7 @@ A page's server fence exports an action, and `form(action={comment})` posts to i
120
120
  import { s, action } from 'kay'
121
121
 
122
122
  export const comment = action(
123
- s.Object({ text: s.String({ minLength: 10, maxLength: 2000 }) }),
123
+ { text: s.string({ min: 10, max: 2000 }) },
124
124
  async ({ text }) => text.trim(),
125
125
  )
126
126
  ---
@@ -195,10 +195,10 @@ import { s } from 'kay'
195
195
  import { collection } from 'kay/content'
196
196
 
197
197
  export const posts = collection('content/posts', {
198
- schema: s.Object({
199
- title: s.String(),
200
- date: s.Date(),
201
- tags: s.Array(s.String(), { default: [] }),
198
+ schema: s.object({
199
+ title: s.string(),
200
+ date: s.date(),
201
+ tags: s.list(s.string(), { default: [] }),
202
202
  }),
203
203
  })
204
204
  ```
@@ -329,9 +329,9 @@ import { s, action } from 'kay'
329
329
  import { checkComment } from '../comment'
330
330
  import CommentForm from '../components/comment-form.kay'
331
331
 
332
- const newComment = s.Object({
333
- name: s.String({ maxLength: 100 }),
334
- text: s.String({ maxLength: 2000 }),
332
+ const newComment = s.object({
333
+ name: s.string({ max: 100 }),
334
+ text: s.string({ max: 2000 }),
335
335
  })
336
336
 
337
337
  export const comment = action(newComment, (input, ctx) => {
@@ -139,6 +139,7 @@ export default defineConfig({
139
139
  scope: '/',
140
140
  maskable: 'src/favicon-maskable.png',
141
141
  shortcuts: [{ name: 'New note', url: '/notes/new' }],
142
+ shareTarget: { action: 'src/routes/share.kay#receive', files: ['image/*'] },
142
143
  },
143
144
  },
144
145
  seo: { name: 'Example' },
@@ -151,6 +152,7 @@ export default defineConfig({
151
152
  - `startUrl` is the page the installed app opens, `scope` by default, else `/`, and `scope` the paths it keeps in its window.
152
153
  - `startUrl`, `scope` and each shortcut's `url` (`name`, `shortName`, `description`) are paths of the site, put under `base`.
153
154
  - One not starting with a single `/`, or a start page or shortcut outside `scope`, which browsers would ignore, stops the server as it boots.
155
+ - `shareTarget` lists the installed app in the share sheet of a device (Chromium browsers, as an installed app): the shared title, text, link and files are posted to `action`, written as the page file and the action's export name (`'src/routes/share.kay#receive'`), or a path of the site (`'/share'`) for a route of your own taking a POST. The action reads `title`, `text`, `url` and `files`, each optional, as any action reads a form: `s.Object({ title: s.Optional(s.String()), url: s.Optional(s.String()), files: s.Optional(s.Files({ maxSize: '5mb' })) })`, and answers with `ctx.redirect('/saved')` to show the person where the share went. `files` lists the kinds taken (`['image/*', '.pdf']`), which posts `multipart/form-data` and lists them in the manifest; without it only text and a link are shared, urlencoded. `params` renames the fields (`{ url: 'link' }`). The action sits under `base` and, like a shortcut, must lie inside `scope` when one is set, `/_kay/action/` included, or the server stops as it boots. A share arrives as a navigation the device starts, sent with no `Origin` and `Sec-Fetch-Site` `none` or `same-origin`, which an action's cross-site check lets through. Android apps often put the link in `text`, so read both. A page file that is no page or layout of the app, or an export that is no action of it, stops the server as it boots, naming the reference.
154
156
  - `maskable` names a square image whose subject sits inside the middle 80%, which a launcher may crop to a circle or a squircle.
155
157
  - kay serves `maskable` as `/icon-maskable-192.png` and `/icon-maskable-512.png`, listed in the manifest with `purpose: "maskable"`, as it serves the favicon.
156
158