@kayjs/kay 1.105.0 → 1.107.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (467) hide show
  1. package/README.md +2 -2
  2. package/dist/eslint.js +777 -210
  3. package/editors/zed/extension.toml +2 -2
  4. package/llms/action-protection.md +2 -2
  5. package/llms/actions-from-islands.md +2 -2
  6. package/llms/actions-refused-fields.md +22 -0
  7. package/llms/actions.md +24 -41
  8. package/llms/analytics.md +1 -1
  9. package/llms/api-from-islands.md +1 -1
  10. package/llms/api-routes.md +6 -6
  11. package/llms/browser-only.md +1 -1
  12. package/llms/check-and-tools.md +1 -1
  13. package/llms/code-lints.md +2 -2
  14. package/llms/compiler-api.md +1 -1
  15. package/llms/component-libraries.md +1 -0
  16. package/llms/components.md +1 -1
  17. package/llms/content-cms.md +1 -1
  18. package/llms/content-markdown-to-caching.md +1 -1
  19. package/llms/content-preview.md +2 -2
  20. package/llms/content.md +21 -21
  21. package/llms/deprecated-lints-1-105-libraries.md +2 -0
  22. package/llms/deprecated-lints-1-105.md +3 -3
  23. package/llms/deprecated-lints.md +4 -4
  24. package/llms/dev-tool.md +2 -2
  25. package/llms/environment.md +22 -22
  26. package/llms/files.md +5 -5
  27. package/llms/island-and-form-lints.md +1 -0
  28. package/llms/islands-state-to-ids.md +2 -1
  29. package/llms/islands.md +10 -1
  30. package/llms/local-collections.md +2 -2
  31. package/llms/mcp.md +2 -1
  32. package/llms/navigation-from-code.md +1 -1
  33. package/llms/notifications.md +4 -2
  34. package/llms/project-new-and-add.md +1 -1
  35. package/llms/project.md +3 -3
  36. package/llms/rate-limits.md +1 -1
  37. package/llms/recipes.md +16 -16
  38. package/llms/rooms.md +4 -4
  39. package/llms/routing-endpoints-and-base.md +1 -1
  40. package/llms/routing.md +5 -5
  41. package/llms/schemas.md +14 -7
  42. package/llms/server.md +7 -7
  43. package/llms/site.md +9 -9
  44. package/llms/sitemap-search-fonts.md +2 -0
  45. package/llms/styles-and-assets.md +2 -1
  46. package/llms/templates-elements-slots-snippets.md +2 -2
  47. package/llms/testing-browser.md +20 -0
  48. package/llms/testing.md +1 -1
  49. package/llms/upgrading-1-105-config.md +2 -2
  50. package/llms/upgrading.md +37 -4
  51. package/llms/whats-new-archive.md +35 -66
  52. package/llms/whats-new.md +47 -28
  53. package/llms.txt +1 -1
  54. package/package.json +24 -11
  55. package/src/add.ts +1 -1
  56. package/src/build/class-table.ts +2 -2
  57. package/src/build/client.ts +27 -30
  58. package/src/build/entry-files.ts +19 -0
  59. package/src/build/lazy-components.ts +130 -0
  60. package/src/build/lazy-manifest.ts +56 -0
  61. package/src/build/lazy-stubs.ts +31 -0
  62. package/src/build/plugin.ts +16 -11
  63. package/src/build/runtime-chunk.ts +1 -1
  64. package/src/build/styles.ts +3 -3
  65. package/src/build/transform.ts +19 -7
  66. package/src/build/ui-layers.ts +30 -0
  67. package/src/build/ui.ts +108 -11
  68. package/src/build/variants.ts +125 -46
  69. package/src/build/worker-bundle.ts +6 -0
  70. package/src/check/action-options.ts +56 -0
  71. package/src/check/boot.ts +22 -1
  72. package/src/check/call-result.ts +242 -0
  73. package/src/check/config-objects.ts +17 -2
  74. package/src/check/diagnose.ts +22 -0
  75. package/src/check/handler-events.ts +149 -0
  76. package/src/check/index.ts +6 -2
  77. package/src/check/link-flag-tests.ts +130 -0
  78. package/src/check/project.ts +4 -3
  79. package/src/check/refusal-calls.ts +2 -2
  80. package/src/check/regroup.ts +5 -3
  81. package/src/check/renamed-packages.ts +58 -14
  82. package/src/check/schema-builders.ts +256 -0
  83. package/src/check/schema-json.ts +226 -0
  84. package/src/check/secret-keys.ts +15 -2
  85. package/src/check/shadow-types.ts +13 -9
  86. package/src/check/template-hints.ts +1 -1
  87. package/src/check/tool-labels.ts +11 -9
  88. package/src/check/ui-types.ts +4 -3
  89. package/src/check/ui.ts +14 -11
  90. package/src/commands/env-declare.ts +18 -6
  91. package/src/commands/routes.ts +1 -1
  92. package/src/compiler/a11y.ts +8 -1
  93. package/src/compiler/ast.ts +1 -1
  94. package/src/compiler/bound-props.ts +1 -1
  95. package/src/compiler/codegen.ts +13 -23
  96. package/src/compiler/deprecated-lints-1-105.ts +41 -0
  97. package/src/compiler/deprecated-lints-1-106.ts +14 -0
  98. package/src/compiler/deprecated-lints-1-107.ts +14 -0
  99. package/src/compiler/deprecated-lints.ts +17 -60
  100. package/src/compiler/deprecated-typed-lints.ts +23 -0
  101. package/src/compiler/dom-here.ts +72 -0
  102. package/src/compiler/dom.ts +23 -23
  103. package/src/compiler/fence-checks.ts +12 -11
  104. package/src/compiler/field-described.ts +2 -2
  105. package/src/compiler/helper-imports.ts +1 -1
  106. package/src/compiler/html-fields.ts +92 -0
  107. package/src/compiler/html-initial.ts +5 -3
  108. package/src/compiler/html.ts +14 -31
  109. package/src/compiler/import-edits.ts +15 -0
  110. package/src/compiler/index.ts +10 -3
  111. package/src/compiler/island-declaration.ts +15 -0
  112. package/src/compiler/items.ts +5 -5
  113. package/src/compiler/kay-exports.ts +1 -0
  114. package/src/compiler/lazy-imports.ts +357 -0
  115. package/src/compiler/link-flags.ts +6 -5
  116. package/src/compiler/lints.ts +12 -12
  117. package/src/compiler/parser.ts +2 -2
  118. package/src/compiler/rest-omits.ts +15 -0
  119. package/src/compiler/route-lints.ts +2 -0
  120. package/src/compiler/schema-lints.ts +13 -0
  121. package/src/compiler/script-server.ts +6 -3
  122. package/src/config-loader.ts +10 -2
  123. package/src/config-resolve.ts +3 -1
  124. package/src/config-shape.ts +2 -2
  125. package/src/config.ts +20 -4
  126. package/src/content/markdown.ts +2 -3
  127. package/src/content/validate.ts +1 -1
  128. package/src/generate-resource.ts +9 -9
  129. package/src/generate.ts +1 -1
  130. package/src/mcp/guards.ts +1 -1
  131. package/src/mcp/tools.ts +1 -1
  132. package/src/migrate/content.ts +61 -55
  133. package/src/new.ts +6 -2
  134. package/src/runtime/action-shared.ts +2 -2
  135. package/src/runtime/action.ts +51 -4
  136. package/src/runtime/client.ts +10 -0
  137. package/src/runtime/dom-lazy.ts +276 -0
  138. package/src/runtime/field-errors.ts +58 -0
  139. package/src/runtime/field-refusal.ts +179 -0
  140. package/src/runtime/form-types.ts +99 -0
  141. package/src/runtime/form.ts +25 -9
  142. package/src/runtime/html.ts +42 -6
  143. package/src/runtime/index.ts +2 -0
  144. package/src/runtime/island.server.ts +36 -2
  145. package/src/runtime/markdown-autolink.ts +69 -0
  146. package/src/runtime/markdown-render.client.ts +39 -3
  147. package/src/runtime/markdown.client.ts +6 -3
  148. package/src/runtime/markdown.server.ts +6 -3
  149. package/src/runtime/markdown.ts +125 -1
  150. package/src/runtime/navigate-api.ts +10 -5
  151. package/src/runtime/persist.ts +7 -7
  152. package/src/runtime/query-param.ts +1 -1
  153. package/src/runtime/reactive.ts +14 -0
  154. package/src/runtime/sanitize.ts +3 -1
  155. package/src/runtime/schema-record.ts +32 -0
  156. package/src/runtime/schema.client.ts +101 -14
  157. package/src/runtime/schema.ts +328 -26
  158. package/src/runtime/standard-schema.ts +32 -0
  159. package/src/runtime/swap-focus.ts +59 -11
  160. package/src/runtime/validate-run.client.ts +179 -0
  161. package/src/runtime/validate.client.ts +11 -0
  162. package/src/runtime/validate.ts +4 -137
  163. package/src/server/action-module.ts +16 -0
  164. package/src/server/actions.ts +54 -57
  165. package/src/server/answer.ts +102 -0
  166. package/src/server/api-input.ts +166 -0
  167. package/src/server/api-modules.ts +1 -1
  168. package/src/server/api.ts +12 -32
  169. package/src/server/app-stages.ts +38 -26
  170. package/src/server/app.ts +5 -2
  171. package/src/server/client.ts +2 -0
  172. package/src/server/dev-ui.ts +2 -2
  173. package/src/server/dev.ts +7 -9
  174. package/src/server/env-state.ts +1 -1
  175. package/src/server/env.ts +11 -3
  176. package/src/server/favicon.ts +47 -1
  177. package/src/server/file-limit.ts +7 -1
  178. package/src/server/forms.ts +1 -1
  179. package/src/server/host-allowlist.ts +7 -7
  180. package/src/server/image-metadata-bmff.ts +1 -1
  181. package/src/server/index.ts +2 -0
  182. package/src/server/kay-routes.ts +221 -0
  183. package/src/server/kay-server.ts +228 -0
  184. package/src/server/kept-exports.ts +1 -0
  185. package/src/server/kept-pages.ts +3 -3
  186. package/src/server/library.ts +2 -2
  187. package/src/server/mcp.ts +14 -13
  188. package/src/server/notifications.ts +4 -2
  189. package/src/server/offline.ts +24 -7
  190. package/src/server/openapi.ts +12 -3
  191. package/src/server/phases.ts +249 -0
  192. package/src/server/protection.ts +6 -6
  193. package/src/server/proxy-key.ts +8 -8
  194. package/src/server/push-settings.ts +16 -2
  195. package/src/server/push.ts +12 -4
  196. package/src/server/query.ts +17 -31
  197. package/src/server/receive.ts +43 -0
  198. package/src/server/render-document.ts +13 -3
  199. package/src/server/render.ts +1 -1
  200. package/src/server/request-context.ts +137 -0
  201. package/src/server/schema-check.ts +1 -1
  202. package/src/server/scope.ts +20 -13
  203. package/src/server/signals.ts +4 -4
  204. package/src/server/socket.ts +19 -47
  205. package/src/server/stream.ts +1 -1
  206. package/src/server/validate.ts +346 -0
  207. package/src/template-ws.ts +1 -1
  208. package/src/test/a11y-dom.ts +70 -0
  209. package/src/test/html-snapshot.ts +103 -0
  210. package/src/test/index.ts +2 -1
  211. package/src/test/mount.ts +14 -3
  212. package/src/test/page-checks.ts +12 -0
  213. package/src/test/screenshot-match.ts +2 -2
  214. package/src/test/shared-modules.ts +27 -5
  215. package/src/test/site-types.ts +5 -1
  216. package/types/build/class-table.d.ts +1 -1
  217. package/types/build/class-table.d.ts.map +1 -1
  218. package/types/build/client.d.ts +3 -2
  219. package/types/build/client.d.ts.map +1 -1
  220. package/types/build/entry-files.d.ts +4 -0
  221. package/types/build/entry-files.d.ts.map +1 -0
  222. package/types/build/lazy-components.d.ts +6 -0
  223. package/types/build/lazy-components.d.ts.map +1 -0
  224. package/types/build/lazy-manifest.d.ts +19 -0
  225. package/types/build/lazy-manifest.d.ts.map +1 -0
  226. package/types/build/lazy-stubs.d.ts +5 -0
  227. package/types/build/lazy-stubs.d.ts.map +1 -0
  228. package/types/build/plugin.d.ts +1 -0
  229. package/types/build/plugin.d.ts.map +1 -1
  230. package/types/build/transform.d.ts +4 -1
  231. package/types/build/transform.d.ts.map +1 -1
  232. package/types/build/ui-layers.d.ts +5 -0
  233. package/types/build/ui-layers.d.ts.map +1 -0
  234. package/types/build/ui.d.ts +7 -0
  235. package/types/build/ui.d.ts.map +1 -1
  236. package/types/build/variants.d.ts +1 -1
  237. package/types/build/variants.d.ts.map +1 -1
  238. package/types/build/worker-bundle.d.ts +1 -0
  239. package/types/build/worker-bundle.d.ts.map +1 -1
  240. package/types/check/action-options.d.ts +3 -0
  241. package/types/check/action-options.d.ts.map +1 -0
  242. package/types/check/boot.d.ts.map +1 -1
  243. package/types/check/call-result.d.ts +7 -0
  244. package/types/check/call-result.d.ts.map +1 -0
  245. package/types/check/config-objects.d.ts.map +1 -1
  246. package/types/check/diagnose.d.ts.map +1 -1
  247. package/types/check/handler-events.d.ts +9 -0
  248. package/types/check/handler-events.d.ts.map +1 -0
  249. package/types/check/index.d.ts +1 -0
  250. package/types/check/index.d.ts.map +1 -1
  251. package/types/check/link-flag-tests.d.ts +4 -0
  252. package/types/check/link-flag-tests.d.ts.map +1 -0
  253. package/types/check/project.d.ts.map +1 -1
  254. package/types/check/regroup.d.ts +1 -1
  255. package/types/check/regroup.d.ts.map +1 -1
  256. package/types/check/renamed-packages.d.ts +1 -0
  257. package/types/check/renamed-packages.d.ts.map +1 -1
  258. package/types/check/schema-builders.d.ts +3 -0
  259. package/types/check/schema-builders.d.ts.map +1 -0
  260. package/types/check/schema-json.d.ts +3 -0
  261. package/types/check/schema-json.d.ts.map +1 -0
  262. package/types/check/secret-keys.d.ts.map +1 -1
  263. package/types/check/shadow-types.d.ts.map +1 -1
  264. package/types/check/template-hints.d.ts +1 -0
  265. package/types/check/template-hints.d.ts.map +1 -1
  266. package/types/check/tool-labels.d.ts.map +1 -1
  267. package/types/check/ui-types.d.ts.map +1 -1
  268. package/types/check/ui.d.ts.map +1 -1
  269. package/types/commands/env-declare.d.ts.map +1 -1
  270. package/types/compiler/a11y.d.ts.map +1 -1
  271. package/types/compiler/bound-props.d.ts +1 -0
  272. package/types/compiler/bound-props.d.ts.map +1 -1
  273. package/types/compiler/codegen.d.ts +3 -0
  274. package/types/compiler/codegen.d.ts.map +1 -1
  275. package/types/compiler/deprecated-lints-1-105.d.ts +39 -0
  276. package/types/compiler/deprecated-lints-1-105.d.ts.map +1 -0
  277. package/types/compiler/deprecated-lints-1-106.d.ts +12 -0
  278. package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -0
  279. package/types/compiler/deprecated-lints-1-107.d.ts +12 -0
  280. package/types/compiler/deprecated-lints-1-107.d.ts.map +1 -0
  281. package/types/compiler/deprecated-lints.d.ts +41 -22
  282. package/types/compiler/deprecated-lints.d.ts.map +1 -1
  283. package/types/compiler/deprecated-typed-lints.d.ts +21 -0
  284. package/types/compiler/deprecated-typed-lints.d.ts.map +1 -0
  285. package/types/compiler/dom-here.d.ts +14 -0
  286. package/types/compiler/dom-here.d.ts.map +1 -0
  287. package/types/compiler/dom.d.ts +1 -0
  288. package/types/compiler/dom.d.ts.map +1 -1
  289. package/types/compiler/fence-checks.d.ts.map +1 -1
  290. package/types/compiler/field-described.d.ts +1 -1
  291. package/types/compiler/field-described.d.ts.map +1 -1
  292. package/types/compiler/html-fields.d.ts +19 -0
  293. package/types/compiler/html-fields.d.ts.map +1 -0
  294. package/types/compiler/html-initial.d.ts +3 -2
  295. package/types/compiler/html-initial.d.ts.map +1 -1
  296. package/types/compiler/html.d.ts.map +1 -1
  297. package/types/compiler/import-edits.d.ts +1 -0
  298. package/types/compiler/import-edits.d.ts.map +1 -1
  299. package/types/compiler/index.d.ts +3 -0
  300. package/types/compiler/index.d.ts.map +1 -1
  301. package/types/compiler/island-declaration.d.ts +5 -0
  302. package/types/compiler/island-declaration.d.ts.map +1 -1
  303. package/types/compiler/items.d.ts +4 -1
  304. package/types/compiler/items.d.ts.map +1 -1
  305. package/types/compiler/kay-exports.d.ts.map +1 -1
  306. package/types/compiler/lazy-imports.d.ts +33 -0
  307. package/types/compiler/lazy-imports.d.ts.map +1 -0
  308. package/types/compiler/link-flags.d.ts +6 -0
  309. package/types/compiler/link-flags.d.ts.map +1 -1
  310. package/types/compiler/lints.d.ts +61 -34
  311. package/types/compiler/lints.d.ts.map +1 -1
  312. package/types/compiler/rest-omits.d.ts +4 -0
  313. package/types/compiler/rest-omits.d.ts.map +1 -0
  314. package/types/compiler/route-lints.d.ts +8 -0
  315. package/types/compiler/route-lints.d.ts.map +1 -1
  316. package/types/compiler/schema-lints.d.ts +11 -0
  317. package/types/compiler/schema-lints.d.ts.map +1 -0
  318. package/types/compiler/script-server.d.ts.map +1 -1
  319. package/types/config-loader.d.ts.map +1 -1
  320. package/types/config-resolve.d.ts.map +1 -1
  321. package/types/config.d.ts +15 -2
  322. package/types/config.d.ts.map +1 -1
  323. package/types/content/markdown.d.ts.map +1 -1
  324. package/types/migrate/content.d.ts.map +1 -1
  325. package/types/new.d.ts +1 -0
  326. package/types/new.d.ts.map +1 -1
  327. package/types/runtime/action-shared.d.ts +1 -1
  328. package/types/runtime/action-shared.d.ts.map +1 -1
  329. package/types/runtime/action.d.ts +29 -1
  330. package/types/runtime/action.d.ts.map +1 -1
  331. package/types/runtime/client.d.ts.map +1 -1
  332. package/types/runtime/dom-lazy.d.ts +6 -0
  333. package/types/runtime/dom-lazy.d.ts.map +1 -0
  334. package/types/runtime/field-errors.d.ts +4 -0
  335. package/types/runtime/field-errors.d.ts.map +1 -0
  336. package/types/runtime/field-refusal.d.ts +37 -0
  337. package/types/runtime/field-refusal.d.ts.map +1 -0
  338. package/types/runtime/form-types.d.ts +6 -0
  339. package/types/runtime/form-types.d.ts.map +1 -0
  340. package/types/runtime/form.d.ts +4 -2
  341. package/types/runtime/form.d.ts.map +1 -1
  342. package/types/runtime/html.d.ts +3 -0
  343. package/types/runtime/html.d.ts.map +1 -1
  344. package/types/runtime/index.d.ts +2 -0
  345. package/types/runtime/index.d.ts.map +1 -1
  346. package/types/runtime/island.server.d.ts +2 -0
  347. package/types/runtime/island.server.d.ts.map +1 -1
  348. package/types/runtime/markdown-autolink.d.ts +11 -0
  349. package/types/runtime/markdown-autolink.d.ts.map +1 -0
  350. package/types/runtime/markdown-render.client.d.ts +2 -1
  351. package/types/runtime/markdown-render.client.d.ts.map +1 -1
  352. package/types/runtime/markdown.client.d.ts +3 -1
  353. package/types/runtime/markdown.client.d.ts.map +1 -1
  354. package/types/runtime/markdown.d.ts +11 -0
  355. package/types/runtime/markdown.d.ts.map +1 -1
  356. package/types/runtime/markdown.server.d.ts +3 -1
  357. package/types/runtime/markdown.server.d.ts.map +1 -1
  358. package/types/runtime/navigate-api.d.ts +1 -1
  359. package/types/runtime/navigate-api.d.ts.map +1 -1
  360. package/types/runtime/persist.d.ts +2 -2
  361. package/types/runtime/persist.d.ts.map +1 -1
  362. package/types/runtime/reactive.d.ts +3 -0
  363. package/types/runtime/reactive.d.ts.map +1 -1
  364. package/types/runtime/sanitize.d.ts.map +1 -1
  365. package/types/runtime/schema-record.d.ts +9 -0
  366. package/types/runtime/schema-record.d.ts.map +1 -0
  367. package/types/runtime/schema.client.d.ts.map +1 -1
  368. package/types/runtime/schema.d.ts +99 -10
  369. package/types/runtime/schema.d.ts.map +1 -1
  370. package/types/runtime/standard-schema.d.ts +37 -0
  371. package/types/runtime/standard-schema.d.ts.map +1 -0
  372. package/types/runtime/swap-focus.d.ts.map +1 -1
  373. package/types/runtime/validate-run.client.d.ts +4 -0
  374. package/types/runtime/validate-run.client.d.ts.map +1 -0
  375. package/types/runtime/validate.client.d.ts +4 -0
  376. package/types/runtime/validate.client.d.ts.map +1 -0
  377. package/types/runtime/validate.d.ts +1 -21
  378. package/types/runtime/validate.d.ts.map +1 -1
  379. package/types/server/action-module.d.ts +2 -0
  380. package/types/server/action-module.d.ts.map +1 -0
  381. package/types/server/actions.d.ts +1 -0
  382. package/types/server/actions.d.ts.map +1 -1
  383. package/types/server/answer.d.ts +6 -0
  384. package/types/server/answer.d.ts.map +1 -0
  385. package/types/server/api-input.d.ts +19 -0
  386. package/types/server/api-input.d.ts.map +1 -0
  387. package/types/server/api.d.ts.map +1 -1
  388. package/types/server/app-stages.d.ts +7 -3
  389. package/types/server/app-stages.d.ts.map +1 -1
  390. package/types/server/app.d.ts +2 -0
  391. package/types/server/app.d.ts.map +1 -1
  392. package/types/server/client.d.ts +1 -0
  393. package/types/server/client.d.ts.map +1 -1
  394. package/types/server/dev.d.ts +1 -1
  395. package/types/server/dev.d.ts.map +1 -1
  396. package/types/server/env-state.d.ts.map +1 -1
  397. package/types/server/env.d.ts +5 -1
  398. package/types/server/env.d.ts.map +1 -1
  399. package/types/server/favicon.d.ts +3 -1
  400. package/types/server/favicon.d.ts.map +1 -1
  401. package/types/server/file-limit.d.ts.map +1 -1
  402. package/types/server/host-allowlist.d.ts +3 -3
  403. package/types/server/host-allowlist.d.ts.map +1 -1
  404. package/types/server/index.d.ts +2 -0
  405. package/types/server/index.d.ts.map +1 -1
  406. package/types/server/kay-routes.d.ts +47 -0
  407. package/types/server/kay-routes.d.ts.map +1 -0
  408. package/types/server/kay-server.d.ts +25 -0
  409. package/types/server/kay-server.d.ts.map +1 -0
  410. package/types/server/kept-exports.d.ts.map +1 -1
  411. package/types/server/kept-pages.d.ts +1 -1
  412. package/types/server/kept-pages.d.ts.map +1 -1
  413. package/types/server/library.d.ts +2 -1
  414. package/types/server/library.d.ts.map +1 -1
  415. package/types/server/mcp.d.ts +1 -1
  416. package/types/server/mcp.d.ts.map +1 -1
  417. package/types/server/notifications.d.ts +2 -1
  418. package/types/server/notifications.d.ts.map +1 -1
  419. package/types/server/offline.d.ts.map +1 -1
  420. package/types/server/openapi.d.ts.map +1 -1
  421. package/types/server/phases.d.ts +36 -0
  422. package/types/server/phases.d.ts.map +1 -0
  423. package/types/server/protection.d.ts +3 -2
  424. package/types/server/protection.d.ts.map +1 -1
  425. package/types/server/proxy-key.d.ts +3 -3
  426. package/types/server/proxy-key.d.ts.map +1 -1
  427. package/types/server/push-settings.d.ts +1 -1
  428. package/types/server/push-settings.d.ts.map +1 -1
  429. package/types/server/push.d.ts +1 -0
  430. package/types/server/push.d.ts.map +1 -1
  431. package/types/server/query.d.ts.map +1 -1
  432. package/types/server/receive.d.ts +9 -0
  433. package/types/server/receive.d.ts.map +1 -0
  434. package/types/server/render-document.d.ts.map +1 -1
  435. package/types/server/request-context.d.ts +29 -0
  436. package/types/server/request-context.d.ts.map +1 -0
  437. package/types/server/schema-check.d.ts +1 -0
  438. package/types/server/schema-check.d.ts.map +1 -1
  439. package/types/server/scope.d.ts +1 -1
  440. package/types/server/scope.d.ts.map +1 -1
  441. package/types/server/socket.d.ts +3 -5
  442. package/types/server/socket.d.ts.map +1 -1
  443. package/types/server/validate.d.ts +26 -0
  444. package/types/server/validate.d.ts.map +1 -0
  445. package/types/test/a11y-dom.d.ts +20 -0
  446. package/types/test/a11y-dom.d.ts.map +1 -0
  447. package/types/test/html-snapshot.d.ts +4 -0
  448. package/types/test/html-snapshot.d.ts.map +1 -0
  449. package/types/test/index.d.ts.map +1 -1
  450. package/types/test/mount.d.ts +3 -0
  451. package/types/test/mount.d.ts.map +1 -1
  452. package/types/test/page-checks.d.ts +6 -0
  453. package/types/test/page-checks.d.ts.map +1 -0
  454. package/types/test/screenshot-match.d.ts +1 -1
  455. package/types/test/screenshot-match.d.ts.map +1 -1
  456. package/types/test/shared-modules.d.ts.map +1 -1
  457. package/types/test/site-types.d.ts +3 -1
  458. package/types/test/site-types.d.ts.map +1 -1
  459. package/src/check/schema-type.ts +0 -9
  460. package/src/compiler/deprecated-script-fence.ts +0 -26
  461. package/src/server/field-errors.ts +0 -136
  462. package/types/check/schema-type.d.ts +0 -3
  463. package/types/check/schema-type.d.ts.map +0 -1
  464. package/types/compiler/deprecated-script-fence.d.ts +0 -3
  465. package/types/compiler/deprecated-script-fence.d.ts.map +0 -1
  466. package/types/server/field-errors.d.ts +0 -6
  467. package/types/server/field-errors.d.ts.map +0 -1
@@ -0,0 +1,228 @@
1
+ import type { Server } from 'bun'
2
+ import type { Elysia } from 'elysia'
3
+ import type { Compiled, RouteEnv, RouteRecord } from './kay-routes'
4
+ import type { PipelineOptions } from './phases'
5
+ import type { ReceiveServer } from './receive'
6
+ import { compileRecord, extractParams, isDynamic, RouteIndex, slashed } from './kay-routes'
7
+ import { emptyPhases, Pipeline } from './phases'
8
+ import { requestUrl } from './request-url'
9
+
10
+ // What answers a request no record of the table serves: the Elysia app kay still routes the rest through.
11
+ export type Fallback = (request: Request, server: ReceiveServer) => Response | Promise<Response>
12
+
13
+ type Handler = (request: Request, server: ReceiveServer) => Promise<Response>
14
+ type BunRoutes = Record<string, Record<string, Handler | Response>>
15
+
16
+ export interface KayServerOptions extends PipelineOptions {
17
+ env: RouteEnv
18
+ fallback?: Fallback | undefined
19
+ }
20
+
21
+ const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD']
22
+
23
+ // The methods Bun is handed a record for: a GET record answers HEAD too, an ALL one every method.
24
+ function askedBy(method: string): string[] {
25
+ if (method === 'ALL')
26
+ return METHODS
27
+
28
+ return method === 'GET' ? ['GET', 'HEAD'] : [method]
29
+ }
30
+
31
+ // kay's own server: the route table compiled into the `routes` `Bun.serve` matches, and `fetch` for what that router leaves, with the fixed phases around both and the fallback app answering what no record serves.
32
+ export class KayServer {
33
+ readonly pipeline: Pipeline
34
+ readonly records: RouteRecord[] = []
35
+ fallback: Fallback | undefined
36
+ readonly #env: RouteEnv
37
+ #built: { routes: BunRoutes, index: RouteIndex } | undefined
38
+
39
+ constructor(options: KayServerOptions) {
40
+ this.pipeline = new Pipeline(emptyPhases(), options)
41
+ this.#env = options.env
42
+ this.fallback = options.fallback
43
+ }
44
+
45
+ // Adds a record to the table; the routes compile again from the next read.
46
+ add(...records: RouteRecord[]): void {
47
+ this.records.push(...records)
48
+ this.#built = undefined
49
+ }
50
+
51
+ // What to hand `Bun.serve({ routes })`.
52
+ get routes(): BunRoutes {
53
+ return this.#build().routes
54
+ }
55
+
56
+ // Answers a request the router did not send to a record: a rewritten one, a request with no server, or one whose path is the fallback's.
57
+ async fetch(request: Request, server?: ReceiveServer): Promise<Response> {
58
+ const received = await this.#receive(request, server)
59
+
60
+ if (received instanceof Response)
61
+ return received
62
+
63
+ const hit = this.#build().index.match(received.method, requestUrl(received).pathname)
64
+
65
+ return hit === undefined ? this.#fallback(received, server) : this.#answer(hit.compiled, hit.params, received)
66
+ }
67
+
68
+ #build(): { routes: BunRoutes, index: RouteIndex } {
69
+ if (this.#built !== undefined)
70
+ return this.#built
71
+
72
+ const compiled = this.records.flatMap(record => compileRecord(record, this.#env))
73
+ const routes: BunRoutes = {}
74
+
75
+ for (const entry of compiled) {
76
+ const methods = routes[entry.path] ??= {}
77
+ const asked = askedBy(entry.record.method)
78
+ const staticAnswer = !entry.redirect && this.pipeline.empty ? entry.record.static : undefined
79
+
80
+ for (const method of asked) {
81
+ // The first record of a path and method keeps it.
82
+ if (methods[method] === undefined)
83
+ methods[method] = staticAnswer !== undefined && method === 'GET' ? staticAnswer : async (request, server) => this.#serve(entry, request, server)
84
+ }
85
+ }
86
+
87
+ return this.#built = { routes, index: new RouteIndex(compiled) }
88
+ }
89
+
90
+ // `receive`, its answer or the failure of a step taken through the phases that follow it, as any failure is.
91
+ async #receive(request: Request, server: ReceiveServer): Promise<Request | Response> {
92
+ try {
93
+ const received = this.pipeline.receive(request, server)
94
+
95
+ return received instanceof Response ? await this.pipeline.settle(request, received) : received
96
+ }
97
+ catch (error) {
98
+ return this.pipeline.failed(request, error)
99
+ }
100
+ }
101
+
102
+ // A request Bun's router sent to a record: received first, and handed on to the table's own match when `receive` rewrote it.
103
+ async #serve(entry: Compiled, request: Request, server: ReceiveServer): Promise<Response> {
104
+ const received = await this.#receive(request, server)
105
+
106
+ if (received instanceof Response)
107
+ return received
108
+
109
+ if (received !== request)
110
+ return this.fetch(received, server)
111
+
112
+ const params = isDynamic(entry.path) ? extractParams(entry.segments, requestUrl(received).pathname) : {}
113
+
114
+ // A path the router took for the record, which its own reading of the params refuses, is the fallback's.
115
+ return params === null ? this.#fallback(received, server) : this.#answer(entry, params, received)
116
+ }
117
+
118
+ async #answer(entry: Compiled, params: Record<string, string> | undefined, request: Request): Promise<Response> {
119
+ if (entry.redirect) {
120
+ const { pathname, search } = requestUrl(request)
121
+
122
+ return this.pipeline.settle(request, new Response(null, { status: 308, headers: { location: slashed(pathname, search) } }))
123
+ }
124
+
125
+ return this.pipeline.serve(entry.record.static === undefined || entry.record.handle !== undefined ? entry.record : { ...entry.record, handle: () => entry.record.static!.clone() }, params, request)
126
+ }
127
+
128
+ async #fallback(request: Request, server: ReceiveServer): Promise<Response> {
129
+ if (this.fallback === undefined)
130
+ return this.pipeline.settle(request, new Response('Not Found\n', { status: 404, headers: { 'content-type': 'text/plain; charset=utf-8' } }))
131
+
132
+ return this.pipeline.settle(request, await this.fallback(request, server))
133
+ }
134
+ }
135
+
136
+ // The routes Elysia handed Bun with the table's laid over them, each method of a path the table serves taken from it and the others left to Elysia.
137
+ function withTable(elysia: Record<string, unknown> | undefined, table: BunRoutes): Record<string, unknown> {
138
+ const merged: Record<string, unknown> = { ...elysia }
139
+
140
+ for (const [path, methods] of Object.entries(table)) {
141
+ const held = merged[path]
142
+
143
+ merged[path] = typeof held === 'object' && held !== null && Object.getPrototypeOf(held) === Object.prototype ? { ...held, ...methods } : methods
144
+ }
145
+
146
+ return merged
147
+ }
148
+
149
+ const INSTALLED = Symbol.for('kay.server.installed')
150
+
151
+ type Reload = Server<unknown>['reload']
152
+
153
+ // What a server holds once kay is in front of it: the table it serves now, which a later run of the app (`kay dev` restarts it on the same server) takes over.
154
+ interface Front {
155
+ kay: KayServer
156
+ // What the app last handed the server, laid over again when a later run's table takes over.
157
+ options?: Parameters<Reload>[0]
158
+ }
159
+
160
+ interface Installable extends Server<unknown> {
161
+ [INSTALLED]?: Front
162
+ }
163
+
164
+ // The `reload` of the server is its prototype's, which the patch shadows: it is lifted for the call, then put back.
165
+ function lifted(server: Installable, options: Parameters<Reload>[0]): void {
166
+ delete (server as { reload?: Reload }).reload
167
+
168
+ try {
169
+ server.reload(options)
170
+ }
171
+ finally {
172
+ server.reload = patched as Reload
173
+ }
174
+ }
175
+
176
+ // Hands Bun what the app gave, with the table's routes laid over its own and a `fetch` that reads the table from the server at each request, so a reload of an earlier run never leaves a request to a table that has no fallback.
177
+ function lay(server: Installable, front: Front, options: Parameters<Reload>[0]): void {
178
+ const { fetch: elysia } = options as { fetch?: ((request: Request, server: ReceiveServer) => Response | Promise<Response>) | undefined }
179
+
180
+ front.kay.fallback = elysia && (async request => elysia(request, server))
181
+ lifted(server, { ...options, fetch: async (request: Request, bun: ReceiveServer) => server[INSTALLED]!.kay.fetch(request, bun ?? server), routes: withTable(options.routes, front.kay.routes) as never })
182
+ }
183
+
184
+ // What the server's `reload` is once kay is in front: the app's `fetch` becomes the fallback of the table's, and its routes are laid under the table's. It is a function of the module, not of one run of the app, so it keeps no run's app or table alive; a wrapper of the server (`kay dev` hands each run one) calls it on the server itself, so `this` is the server whatever object the app holds.
185
+ function patched(this: Installable, options: Parameters<Reload>[0]): void {
186
+ // Elysia also reloads a server with the server itself, which holds what it already serves.
187
+ if (typeof (options as { stop?: unknown }).stop === 'function')
188
+ return lifted(this, options)
189
+
190
+ const front = this[INSTALLED]!
191
+
192
+ front.options = options
193
+ lay(this, front, options)
194
+ }
195
+
196
+ // Puts kay's server in front of the Elysia app once it listens: Bun is handed `kay.fetch`, with the app's own `fetch` as its fallback, and the routes the table compiled to, beside the ones Elysia hands it.
197
+ // Elysia hands Bun its `fetch` and routes in a `reload` when it has loaded its modules, a microtask after it starts listening, and recompiles `app.fetch` by then, so the `reload` of the running server is where both are taken over.
198
+ // Elysia also hands Bun a handler for each of its routes, which Bun calls without `fetch`, so the answer would skip `respond` and `after`: once a step of either is set, Elysia's own router serves them through `fetch` instead. With none set, which is the case until the slices moving the response work onto the phases land, the app is served exactly as before.
199
+ export function serveThrough(app: Elysia, kay: KayServer): void {
200
+ app.onStart((root) => {
201
+ const server = root.server as Installable | null | undefined
202
+
203
+ if (server === null || server === undefined)
204
+ return
205
+
206
+ const { respond, after } = kay.pipeline.phases
207
+
208
+ if (respond.length > 0 || after.length > 0)
209
+ root.config.systemRouter = false
210
+
211
+ const held = server[INSTALLED]
212
+
213
+ if (held !== undefined) {
214
+ // The table of the new run takes the server over, its routes laid under Bun again, and no table of an earlier run keeps the app of a later one.
215
+ kay.fallback = held.kay.fallback
216
+ held.kay.fallback = undefined
217
+ held.kay = kay
218
+
219
+ if (held.options !== undefined)
220
+ lay(server, held, held.options)
221
+
222
+ return
223
+ }
224
+
225
+ server[INSTALLED] = { kay }
226
+ server.reload = patched as Reload
227
+ })
228
+ }
@@ -91,6 +91,7 @@ export const KAY_EXPORTS: Record<string, 'free' | 'request' | 'local'> = {
91
91
  trustHtml: 'free',
92
92
  uid: 'free',
93
93
  untrack: 'free',
94
+ validate: 'free',
94
95
  watch: 'free',
95
96
  webPush: 'free',
96
97
  withBase: 'free',
@@ -39,18 +39,18 @@ function withoutTrailingSlashes(path: string): string {
39
39
  // A request that is not a GET, a HEAD or an OPTIONS can change what a page renders, an action as much as a route of the app, once a route answers it: one to no route, and kay's own routes in `own` (the MCP endpoint among them, whose tool calls reach the app's actions and count there), write nothing, so no visitor can force a page to render again by sending them.
40
40
  // Counted when its route is matched and again as its response is made, so a visit between the two is checked once more, and the visit that follows the response sees the finished write; one a guard or the validation refuses (a 400, 401, 403, 405, 413, 415, 422 or 429) is counted by neither, so no visitor can make a page render again by sending those.
41
41
  // The end count is a `mapResponse` and an `afterResponse`, never an `afterHandle` or `onError`, which would change how an API module answers; called before any route is added, as a hook reaches only the routes added after it.
42
- export function countWrites(app: Elysia, own: string[] = []): Writes {
42
+ export function countWrites(app: Elysia, own: () => string[] = () => []): Writes {
43
43
  let done = 0
44
44
  let active = 0
45
45
  const writes: Writes = { get count() {
46
46
  // A write in flight counts half a step, so a visit during it is checked once more after it, and a refused one leaves the count where it was.
47
47
  return active > 0 ? done + 0.5 : done
48
48
  } }
49
- const kay = new Set([...KAY_ROUTES, ...own])
49
+ const kay = new Set(KAY_ROUTES)
50
50
  const started = new WeakSet<Request>()
51
51
 
52
52
  app.onTransform({ as: 'global' }, ({ request }) => {
53
- if (request.method !== 'GET' && request.method !== 'HEAD' && request.method !== 'OPTIONS' && !kay.has(withoutTrailingSlashes(pathOf(request.url)))) {
53
+ if (request.method !== 'GET' && request.method !== 'HEAD' && request.method !== 'OPTIONS' && !kay.has(withoutTrailingSlashes(pathOf(request.url))) && !own().includes(withoutTrailingSlashes(pathOf(request.url)))) {
54
54
  started.add(request)
55
55
  active++
56
56
  }
@@ -42,7 +42,9 @@ export type { DenyOptions, RefuseOptions } from '../runtime/refuse'
42
42
  export { refuse } from '../runtime/refuse'
43
43
  export { safeCode } from '../runtime/safe-code'
44
44
  export { isUrlAttribute, UNSAFE_ATTRIBUTE, UNSAFE_TAGS } from '../runtime/sanitize'
45
+ export { DEFAULT_MAX_ITEMS } from '../runtime/schema'
45
46
  export type { Schema, Static } from '../runtime/schema'
47
+ export { DEFAULT_MAX_LENGTH } from '../runtime/schema-bounds'
46
48
  export { configuredSite, setSite } from '../runtime/site'
47
49
  export { openSqlite } from '../runtime/sqlite.server'
48
50
  export { parseEvents } from '../runtime/sse'
@@ -105,8 +107,6 @@ export { sha256 } from './sha256'
105
107
  export { stoppers } from './signals'
106
108
  export { appSecrets, keyedDigest } from './stamp'
107
109
  export type { MissingTranslations } from './translations'
108
- // Deprecated since 1.103: `Schema`, kay's own name for it.
109
- export type { TSchema } from 'elysia'
110
110
 
111
111
  type Translations = typeof import('./translations')
112
112
  type Drafts = typeof import('./message-drafts')
package/src/server/mcp.ts CHANGED
@@ -16,7 +16,7 @@ import { configuredSite } from '../runtime/site'
16
16
  import { FAILURE_HEADER, PAGE_HEADER, REDIRECT_HEADER } from '../runtime/swap'
17
17
  import { decodeServerValue, encodeValue } from '../runtime/wire'
18
18
  import { boundToPage } from './actions'
19
- import { FORMER_MCP_PATH, RESOURCE_METADATA } from './api-modules'
19
+ import { RESOURCE_METADATA } from './api-modules'
20
20
  import { isCrossSite, postedFrom, unadmittedCrossSite } from './cross-site'
21
21
  import { answeredAsPage, currentRequest } from './log'
22
22
  import { bearsMcpKey } from './mcp-key'
@@ -176,7 +176,7 @@ function toolOf(path: string, method: string, operation: Operation, id: string,
176
176
  const init: RequestInit = { method: method.toUpperCase(), headers: { accept: 'application/json' } }
177
177
 
178
178
  if (action) {
179
- init.headers = { 'accept': 'application/json', 'content-type': 'application/json', 'x-kay-action': '1' }
179
+ init.headers = { 'accept': 'application/json', 'content-type': 'application/json', 'x-kay-action': '1', 'x-kay-tool': '1' }
180
180
  init.body = encodeValue(args)
181
181
  }
182
182
  else if (!NO_BODY.has(method) && operation.requestBody) {
@@ -403,6 +403,8 @@ export interface McpOptions {
403
403
  metadataPaths: string[]
404
404
  // Where the endpoint is served, `/mcp` by default.
405
405
  path: string
406
+ // The path before 1.105, answered as `path` is until 2.0, for an app that did not move the endpoint and serves nothing there.
407
+ former?: string | undefined
406
408
  // The requests a client may send it in a window, or undefined for no limit.
407
409
  rateLimit: RateWindowMs | undefined
408
410
  // Sent as `instructions` of `initialize`, from `mcp.instructions`.
@@ -566,7 +568,7 @@ function serveResourceMetadata(app: Elysia, name: string, paths: string[], endpo
566
568
  }
567
569
  }
568
570
 
569
- // Serves the tools of `document` at `/mcp` over Streamable HTTP: one JSON-RPC message per POST, answered with JSON.
571
+ // Serves the tools of `document` at its path over Streamable HTTP: one JSON-RPC message per POST, answered with JSON; `former`, where it was before 1.105, answers POST in place until 2.0.
570
572
  export function serveMcp(app: Elysia, document: Schema, options: McpOptions): void {
571
573
  const calls = new AsyncLocalStorage<CallContext>()
572
574
  const build = () => {
@@ -587,7 +589,7 @@ export function serveMcp(app: Elysia, document: Schema, options: McpOptions): vo
587
589
  }
588
590
  const notAllowed = () => new Response(null, { status: 405, headers: { allow: 'POST' } })
589
591
 
590
- app.post(options.path, async (served) => {
592
+ const answer = async (served: { request: Request, server: Server | null }) => {
591
593
  const { request, server } = served
592
594
 
593
595
  // A browser page of another site posting here would act with the visitor's cookies.
@@ -637,18 +639,17 @@ export function serveMcp(app: Elysia, document: Schema, options: McpOptions): vo
637
639
  status = 401
638
640
 
639
641
  return new Response(JSON.stringify(reply), { status, headers })
640
- }, { parse: 'none' })
642
+ }
643
+
644
+ app.post(options.path, answer, { parse: 'none' })
641
645
  app.get(options.path, notAllowed)
642
646
  app.delete(options.path, notAllowed)
643
- serveResourceMetadata(app, options.title, options.metadataPaths, options.path)
644
- }
645
647
 
646
- // Sends a request for `/mcp`, where the endpoint was served before 1.105, to its path now, with the method, the body and the query kept by a 308; removed in 1.108.
647
- export function redirectFormerMcp(app: Elysia, to: string): void {
648
- app.all(FORMER_MCP_PATH, ({ request }) => {
649
- // The base goes in front of the location as it does for every redirect.
650
- return new Response(null, { status: 308, headers: { 'location': `${to}${requestUrl(request).search}`, 'cache-control': 'no-store' } })
651
- })
648
+ // Only the POST is taken at the former path, so a catch-all or parameter route of the app keeps its GET and DELETE.
649
+ if (options.former !== undefined)
650
+ app.post(options.former, answer, { parse: 'none' })
651
+
652
+ serveResourceMetadata(app, options.title, options.metadataPaths, options.path)
652
653
  }
653
654
 
654
655
  // An action a library offers a model: what the model reads of it, and the call it makes.
@@ -63,6 +63,8 @@ export interface NotifyOptions {
63
63
  ttl?: Duration | undefined
64
64
  // `false` keeps the notification in the inbox alone, without the push a person who opted in would get with `push()` listed.
65
65
  push?: boolean | undefined
66
+ // `false` leaves the installed app's badge alone: the push otherwise carries the person's unread count, which the worker shows as the app badge.
67
+ badge?: boolean | undefined
66
68
  }
67
69
 
68
70
  export const MAX_TITLE = 200
@@ -278,7 +280,7 @@ function changed(user: string): void {
278
280
 
279
281
  // Puts a notification in a person's inbox, which the `Bell` of kayjs-ui shows with its unread count and updates in every open tab. `user` is the id kayjs-auth, or whatever names the request's user, gives.
280
282
  // The store is the app's `store.notifications`, which `sqliteData` and `pgData` fill; with none it is this process's memory. A notification is dropped after `ttl`, 90 days by default.
281
- export async function notify(user: string, { title, url, ttl, push }: NotifyOptions): Promise<Notification> {
283
+ export async function notify(user: string, { title, url, ttl, push, badge }: NotifyOptions): Promise<Notification> {
282
284
  const id = checkedUser(user)
283
285
  const text = typeof title === 'string' ? title.replaceAll('\0', '').trim() : ''
284
286
 
@@ -297,7 +299,7 @@ export async function notify(user: string, { title, url, ttl, push }: NotifyOpti
297
299
  changed(id)
298
300
 
299
301
  if (push !== false)
300
- pushAlongside(id, { title: text, url: link })
302
+ pushAlongside(id, { title: text, url: link }, badge === false ? undefined : async () => notificationStore().unread(id, Date.now()))
301
303
 
302
304
  return { id: note.id, title: note.title, ...link === undefined ? {} : { url: link }, createdAt: new Date(createdAt), read: false }
303
305
  }
@@ -30,7 +30,7 @@ const BACKSLASH = /\\/g
30
30
  // A rule of the fonts' stylesheet naming its file and the range of characters it holds.
31
31
  const FACE_RANGE = /url\("([^"]+)"\)[^}]*?unicode-range:([^;}]+)/g
32
32
  // Bumped whenever the worker's own code changes, so every site installs it again.
33
- const WORKER_VERSION = 8
33
+ const WORKER_VERSION = 9
34
34
  // Past this many pages kept by default, the boot says to list the ones worth it.
35
35
  const MANY_PAGES = 100
36
36
 
@@ -195,14 +195,31 @@ self.addEventListener('push', (event) => {
195
195
  }
196
196
  catch {}
197
197
 
198
- event.waitUntil(self.registration.showNotification(typeof data.title === 'string' && data.title !== '' ? data.title : location.hostname, {
199
- body: typeof data.body === 'string' ? data.body : undefined,
200
- tag: typeof data.tag === 'string' ? data.tag : undefined,
201
- icon: typeof data.icon === 'string' ? linkOf(data.icon) : undefined,
202
- data: { url: typeof data.url === 'string' ? linkOf(data.url) : linkOf('/') },
203
- }))
198
+ event.waitUntil(Promise.all([
199
+ self.registration.showNotification(typeof data.title === 'string' && data.title !== '' ? data.title : location.hostname, {
200
+ body: typeof data.body === 'string' ? data.body : undefined,
201
+ tag: typeof data.tag === 'string' ? data.tag : undefined,
202
+ icon: typeof data.icon === 'string' ? linkOf(data.icon) : undefined,
203
+ data: { url: typeof data.url === 'string' ? linkOf(data.url) : linkOf('/') },
204
+ }),
205
+ badge(data.badge),
206
+ ]))
204
207
  })
205
208
 
209
+ // The app badge a push carries the unread count of: a count sets it, 0 clears it, and a browser without the Badging API leaves it.
210
+ async function badge(count) {
211
+ if (!Number.isSafeInteger(count) || count < 0)
212
+ return
213
+
214
+ try {
215
+ if (count > 0 && self.navigator.setAppBadge)
216
+ await self.navigator.setAppBadge(count)
217
+ else if (count === 0 && self.navigator.clearAppBadge)
218
+ await self.navigator.clearAppBadge()
219
+ }
220
+ catch {}
221
+ }
222
+
206
223
  self.addEventListener('notificationclick', (event) => {
207
224
  event.notification.close()
208
225
 
@@ -7,7 +7,9 @@ import type { ServedPaths } from './served-paths'
7
7
  import { posix } from 'node:path'
8
8
  import { NON_ROOT_TRAILING_SLASH } from '../runtime/base'
9
9
  import { escape } from '../runtime/escape'
10
+ import { jsonSchemaOf } from '../runtime/standard-schema'
10
11
  import { inLocale, passGuards } from './actions'
12
+ import { declaredInputs } from './api-input'
11
13
  import { API_PREFIX, KAY_PREFIX, openApiPaths, referenced } from './api-modules'
12
14
  import { sharedContext } from './render'
13
15
  import { apiRoutePath } from './routes'
@@ -208,7 +210,7 @@ export function openApiDocument(modules: MountedApi[], options: { title: string,
208
210
  for (const module of modules) {
209
211
  for (const route of module.instance.routes) {
210
212
  const method = route.method.toUpperCase()
211
- const hooks = route.hooks as Record<string, unknown> & { detail?: { summary?: string, description?: string, tags?: string[], deprecated?: boolean, hide?: boolean, operationId?: string, tool?: boolean | string | ActionTool } }
213
+ const hooks = { ...route.hooks as object, ...Object.fromEntries(Object.entries(declaredInputs(route.hooks)).map(([input, schema]) => [input, described(schema)])) } as Record<string, unknown> & { detail?: { summary?: string, description?: string, tags?: string[], deprecated?: boolean, hide?: boolean, operationId?: string, tool?: boolean | string | ActionTool } }
212
214
 
213
215
  if ((!METHODS.has(method) && method !== 'ALL') || hooks.detail?.hide === true)
214
216
  continue
@@ -361,7 +363,7 @@ function withRefusal(answers: Record<string, Schema>, hooks: Record<string, unkn
361
363
 
362
364
  // A schema under the type it goes as: raw bytes as such, text as text, anything else as `fallback`.
363
365
  function content(schema: unknown, fallback: string): Record<string, { schema: unknown }> {
364
- const plain = schemaOf(schema) as Schema
366
+ const plain = schemaOf(described(schema)) as Schema
365
367
  let type = fallback
366
368
 
367
369
  if (plain.format === 'binary')
@@ -372,7 +374,14 @@ function content(schema: unknown, fallback: string): Record<string, { schema: un
372
374
  return { [type]: { schema: plain } }
373
375
  }
374
376
 
375
- function holdsFile(schema: unknown): boolean {
377
+ // What a schema describes as JSON Schema: itself, or what a Standard Schema validator says of its input, none for one that cannot.
378
+ function described(schema: unknown): unknown {
379
+ return typeof schema === 'object' && schema !== null ? jsonSchemaOf(schema) ?? {} : schema
380
+ }
381
+
382
+ function holdsFile(given: unknown): boolean {
383
+ const schema = described(given)
384
+
376
385
  if (typeof schema !== 'object' || schema === null)
377
386
  return false
378
387