@kayjs/kay 1.104.2 → 1.105.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 (1152) hide show
  1. package/README.md +2 -7
  2. package/dist/eslint.js +5483 -2607
  3. package/editors/vscode/syntaxes/kay.tmLanguage.json +1 -1
  4. package/editors/zed/extension.toml +2 -2
  5. package/llms/action-protection.md +10 -10
  6. package/llms/actions-from-islands.md +26 -29
  7. package/llms/actions-refused-fields.md +18 -4
  8. package/llms/actions.md +36 -27
  9. package/llms/analytics.md +1 -1
  10. package/llms/api-from-islands.md +14 -15
  11. package/llms/api-routes.md +10 -8
  12. package/llms/browser-only.md +12 -10
  13. package/llms/cdn-caching.md +7 -6
  14. package/llms/check-and-tools.md +11 -9
  15. package/llms/checks.md +1 -1
  16. package/llms/code-lints.md +7 -6
  17. package/llms/commands.md +42 -0
  18. package/llms/component-libraries.md +1 -1
  19. package/llms/component-library-conventions.md +11 -5
  20. package/llms/components.md +15 -15
  21. package/llms/content-markdown-to-caching.md +2 -2
  22. package/llms/deprecated-lints-1-105-libraries.md +30 -0
  23. package/llms/deprecated-lints-1-105.md +58 -0
  24. package/llms/deprecated-lints.md +7 -5
  25. package/llms/dev-tool.md +1 -1
  26. package/llms/eco-design.md +3 -3
  27. package/llms/editor-and-agent-commands.md +1 -1
  28. package/llms/effects.md +7 -7
  29. package/llms/environment.md +6 -5
  30. package/llms/errors-runtime.md +4 -4
  31. package/llms/errors.md +12 -8
  32. package/llms/events.md +15 -12
  33. package/llms/files.md +6 -4
  34. package/llms/guards.md +18 -15
  35. package/llms/head.md +38 -6
  36. package/llms/hooks.md +27 -25
  37. package/llms/images-runtime-and-remote.md +12 -12
  38. package/llms/images.md +29 -29
  39. package/llms/island-and-form-lints.md +8 -8
  40. package/llms/island-sources.md +31 -24
  41. package/llms/islands-state-to-ids.md +8 -10
  42. package/llms/islands.md +16 -14
  43. package/llms/lints.md +1 -1
  44. package/llms/live-values.md +12 -9
  45. package/llms/local-collections.md +11 -11
  46. package/llms/locales-texts.md +1 -1
  47. package/llms/locales.md +12 -11
  48. package/llms/mcp.md +8 -8
  49. package/llms/metrics.md +24 -0
  50. package/llms/navigation-from-code.md +16 -15
  51. package/llms/navigation.md +5 -3
  52. package/llms/prerendering.md +4 -4
  53. package/llms/privacy.md +4 -4
  54. package/llms/production.md +28 -38
  55. package/llms/project-new-and-add.md +7 -7
  56. package/llms/project.md +18 -42
  57. package/llms/proxy-and-security.md +5 -5
  58. package/llms/queues.md +19 -24
  59. package/llms/rate-limits.md +21 -10
  60. package/llms/recipes.md +7 -6
  61. package/llms/rendering.md +8 -7
  62. package/llms/request-values.md +2 -2
  63. package/llms/rooms.md +9 -9
  64. package/llms/routing-endpoints-and-base.md +3 -3
  65. package/llms/routing-special-pages.md +4 -4
  66. package/llms/routing.md +16 -18
  67. package/llms/security-and-i18n-lints.md +1 -1
  68. package/llms/seo-lints.md +1 -1
  69. package/llms/server-islands.md +12 -7
  70. package/llms/server.md +33 -18
  71. package/llms/site.md +12 -10
  72. package/llms/sitemap-search-fonts.md +50 -44
  73. package/llms/stores.md +7 -5
  74. package/llms/styles-and-assets.md +9 -9
  75. package/llms/templates-elements-slots-snippets.md +5 -9
  76. package/llms/templates.md +4 -4
  77. package/llms/testing-browser.md +2 -0
  78. package/llms/testing-requests-jobs-sockets.md +27 -4
  79. package/llms/testing.md +7 -7
  80. package/llms/tracing.md +9 -7
  81. package/llms/upgrading-1-105-config.md +71 -0
  82. package/llms/upgrading-archive.md +74 -114
  83. package/llms/upgrading.md +41 -127
  84. package/llms/whats-new-archive.md +68 -50
  85. package/llms/whats-new.md +32 -51
  86. package/llms/workers.md +2 -2
  87. package/llms.txt +18 -13
  88. package/package.json +11 -9
  89. package/src/add.ts +3 -1
  90. package/src/build/await-alert.ts +34 -0
  91. package/src/build/class-rules.ts +8 -0
  92. package/src/build/client.ts +21 -16
  93. package/src/build/compile.ts +9 -6
  94. package/src/build/pipeline.ts +19 -16
  95. package/src/build/recipe-classes.ts +11 -1
  96. package/src/build/recipe-utilities.ts +183 -0
  97. package/src/build/server-record.ts +2 -1
  98. package/src/build/signals.ts +113 -14
  99. package/src/build/sourcemap.ts +1 -1
  100. package/src/build/static.ts +10 -8
  101. package/src/build/style-uses.ts +7 -6
  102. package/src/build/styles.ts +7 -1
  103. package/src/build/supports.ts +4 -4
  104. package/src/build/transform.ts +3 -2
  105. package/src/build/verify.ts +8 -5
  106. package/src/check/action-readers.ts +115 -0
  107. package/src/check/action-type.ts +44 -0
  108. package/src/check/ai-language.ts +56 -0
  109. package/src/check/app-hooks.ts +90 -0
  110. package/src/check/auth-methods.ts +85 -0
  111. package/src/check/auth-rate-limits.ts +99 -0
  112. package/src/check/boot.ts +9 -8
  113. package/src/check/browser-global-reads.ts +4 -4
  114. package/src/check/client-keys.ts +10 -0
  115. package/src/check/cms-options.ts +81 -0
  116. package/src/check/config-groups.ts +22 -0
  117. package/src/check/config-objects.ts +83 -0
  118. package/src/check/config-switches.ts +38 -0
  119. package/src/check/context-import.ts +51 -0
  120. package/src/check/diagnose.ts +16 -6
  121. package/src/check/env-files.ts +31 -0
  122. package/src/check/env-types.ts +10 -8
  123. package/src/check/format-duration.ts +75 -0
  124. package/src/check/generated.ts +23 -4
  125. package/src/check/guard-options.ts +58 -0
  126. package/src/check/guards.ts +4 -4
  127. package/src/check/hook-context.ts +94 -0
  128. package/src/check/hook-names.ts +104 -0
  129. package/src/check/i18n-keys.ts +50 -0
  130. package/src/check/images-keys.ts +54 -0
  131. package/src/check/index.ts +38 -22
  132. package/src/check/job-shapes.ts +273 -0
  133. package/src/check/layout-facts.ts +1 -1
  134. package/src/check/live-api.ts +137 -0
  135. package/src/check/mail-api.ts +67 -0
  136. package/src/check/messages.ts +7 -7
  137. package/src/check/moved-keys.ts +49 -0
  138. package/src/check/one-state-api.ts +357 -0
  139. package/src/check/open-settings.ts +1 -1
  140. package/src/check/output-schema.ts +3 -1
  141. package/src/check/page-heads.ts +31 -5
  142. package/src/check/pages-options.ts +35 -0
  143. package/src/check/project.ts +5 -1
  144. package/src/check/rate-enforce.ts +53 -0
  145. package/src/check/refusal-calls.ts +185 -0
  146. package/src/check/regroup.ts +92 -0
  147. package/src/check/removed-ui-tokens.ts +2 -2
  148. package/src/check/renamed-packages.ts +32 -0
  149. package/src/check/retired-lints.ts +49 -0
  150. package/src/check/route-keys.ts +166 -0
  151. package/src/check/route-shadow.ts +174 -0
  152. package/src/check/secret-keys.ts +70 -0
  153. package/src/check/seo.ts +3 -3
  154. package/src/check/shadow-types.ts +112 -4
  155. package/src/check/shadow.ts +4 -1
  156. package/src/check/socket-frames.ts +102 -0
  157. package/src/check/source-readers.ts +257 -0
  158. package/src/check/store-ms.ts +72 -0
  159. package/src/check/store-names.ts +88 -0
  160. package/src/check/template-hints.ts +70 -6
  161. package/src/check/test-helpers.ts +98 -0
  162. package/src/check/text-size-colour.ts +57 -0
  163. package/src/check/ttl-names.ts +142 -0
  164. package/src/check/unmounted-jobs.ts +2 -2
  165. package/src/commands/a11y.ts +1 -1
  166. package/src/commands/check.ts +4 -2
  167. package/src/commands/env-compare.ts +2 -2
  168. package/src/commands/env-declare.ts +1 -1
  169. package/src/commands/env.ts +19 -16
  170. package/src/commands/explain-island.ts +27 -1
  171. package/src/commands/i18n.ts +2 -2
  172. package/src/commands/new.ts +17 -7
  173. package/src/commands/routes.ts +23 -17
  174. package/src/commands/upgrade-majors.ts +26 -0
  175. package/src/commands/upgrade-manifest.ts +23 -0
  176. package/src/commands/upgrade-messages.ts +16 -0
  177. package/src/commands/upgrade-peers.ts +89 -0
  178. package/src/commands/upgrade.ts +68 -36
  179. package/src/compiler/a11y.ts +56 -41
  180. package/src/compiler/aria.ts +1 -1
  181. package/src/compiler/ast.ts +54 -136
  182. package/src/compiler/bound-props.ts +75 -0
  183. package/src/compiler/browser.ts +12 -11
  184. package/src/compiler/button-forms.ts +33 -0
  185. package/src/compiler/codegen.ts +52 -138
  186. package/src/compiler/deprecated-ai-labels.ts +97 -0
  187. package/src/compiler/deprecated-ai-links.ts +63 -0
  188. package/src/compiler/deprecated-allow.ts +50 -0
  189. package/src/compiler/deprecated-auth-lints.ts +14 -0
  190. package/src/compiler/deprecated-auth-signed.ts +29 -0
  191. package/src/compiler/deprecated-children.ts +66 -0
  192. package/src/compiler/deprecated-image.ts +116 -0
  193. package/src/compiler/deprecated-island.ts +155 -0
  194. package/src/compiler/deprecated-library.ts +20 -0
  195. package/src/compiler/deprecated-lints.ts +523 -22
  196. package/src/compiler/deprecated-page.ts +125 -0
  197. package/src/compiler/deprecated-parts.ts +22 -0
  198. package/src/compiler/deprecated-ui-callbacks.ts +66 -0
  199. package/src/compiler/deprecated-ui-input.ts +97 -0
  200. package/src/compiler/deprecated-ui-items.ts +47 -0
  201. package/src/compiler/deprecated-ui-props.ts +3 -3
  202. package/src/compiler/dom-fields.ts +67 -0
  203. package/src/compiler/dom.ts +40 -27
  204. package/src/compiler/errors.ts +37 -27
  205. package/src/compiler/event-modifiers.ts +2 -2
  206. package/src/compiler/fence-checks.ts +29 -69
  207. package/src/compiler/form-action.ts +18 -0
  208. package/src/compiler/form-info.ts +154 -0
  209. package/src/compiler/head-shorthand.ts +118 -0
  210. package/src/compiler/head-tags.ts +64 -0
  211. package/src/compiler/helper-imports.ts +33 -0
  212. package/src/compiler/html-initial.ts +68 -0
  213. package/src/compiler/html-parts.ts +40 -0
  214. package/src/compiler/html.ts +41 -91
  215. package/src/compiler/if-alias.ts +2 -47
  216. package/src/compiler/image-attributes.ts +69 -0
  217. package/src/compiler/index.ts +63 -24
  218. package/src/compiler/island-arguments.ts +38 -10
  219. package/src/compiler/island-cause.ts +9 -6
  220. package/src/compiler/island-declaration.ts +181 -0
  221. package/src/compiler/island-marker.ts +10 -15
  222. package/src/compiler/items.ts +5 -0
  223. package/src/compiler/jsx-class.ts +25 -1
  224. package/src/compiler/jsx-field.ts +58 -0
  225. package/src/compiler/jsx.ts +24 -29
  226. package/src/compiler/kay-exports.ts +2 -0
  227. package/src/compiler/link-flags.ts +106 -0
  228. package/src/compiler/lints.ts +27 -60
  229. package/src/compiler/live-reads.ts +160 -0
  230. package/src/compiler/loop-lints.ts +6 -5
  231. package/src/compiler/markup-fields.ts +34 -0
  232. package/src/compiler/markup.ts +75 -77
  233. package/src/compiler/module-signals.ts +112 -9
  234. package/src/compiler/names.ts +7 -1
  235. package/src/compiler/nesting.ts +7 -0
  236. package/src/compiler/old-parts.ts +84 -0
  237. package/src/compiler/page-settings.ts +2 -0
  238. package/src/compiler/parser.ts +7 -8
  239. package/src/compiler/plan.ts +13 -1
  240. package/src/compiler/rewrite-reads.ts +30 -1
  241. package/src/compiler/rewrite-types.ts +2 -0
  242. package/src/compiler/rewrite.ts +35 -33
  243. package/src/compiler/route-lints.ts +12 -2
  244. package/src/compiler/script-props.ts +52 -6
  245. package/src/compiler/script-server.ts +26 -3
  246. package/src/compiler/script-shared.ts +9 -0
  247. package/src/compiler/script.ts +7 -0
  248. package/src/compiler/server-imports.ts +52 -0
  249. package/src/compiler/slot-types.ts +46 -0
  250. package/src/compiler/style-arguments.ts +20 -0
  251. package/src/compiler/template-walk.ts +72 -0
  252. package/src/compiler/type-parameters.ts +45 -0
  253. package/src/compiler/validate-fields.ts +68 -0
  254. package/src/compiler/validate.ts +51 -45
  255. package/src/config-extensions.ts +53 -6
  256. package/src/config-loader.ts +31 -16
  257. package/src/config-resolve.ts +194 -0
  258. package/src/config-shape.ts +81 -38
  259. package/src/config-switch.ts +14 -0
  260. package/src/config.ts +287 -102
  261. package/src/content/problems.ts +1 -1
  262. package/src/eslint/index.ts +19 -2
  263. package/src/features.ts +2 -2
  264. package/src/generate-resource.ts +5 -4
  265. package/src/generate.ts +2 -2
  266. package/src/lsp/code-actions.ts +1 -1
  267. package/src/lsp/completions.ts +2 -2
  268. package/src/lsp/diagnostics.ts +4 -2
  269. package/src/lsp/document-links.ts +1 -1
  270. package/src/lsp/navigation.ts +1 -1
  271. package/src/lsp/route-documents.ts +21 -0
  272. package/src/lsp/semantic-tokens.ts +2 -2
  273. package/src/lsp/server.ts +60 -8
  274. package/src/lsp/template-completion.ts +4 -4
  275. package/src/lsp/ui-completion.ts +1 -1
  276. package/src/migrate/astro.ts +1 -1
  277. package/src/migrate/project.ts +3 -3
  278. package/src/new.ts +6 -4
  279. package/src/project.ts +20 -11
  280. package/src/runtime/action-call.ts +179 -41
  281. package/src/runtime/action-encode.ts +2 -1
  282. package/src/runtime/action-error.ts +2 -1
  283. package/src/runtime/action-form.ts +159 -17
  284. package/src/runtime/action-navigate.ts +19 -0
  285. package/src/runtime/action-owner.ts +2 -0
  286. package/src/runtime/action-post.ts +22 -4
  287. package/src/runtime/action-protection.ts +4 -3
  288. package/src/runtime/action-shared.ts +86 -28
  289. package/src/runtime/action-stream.ts +43 -9
  290. package/src/runtime/action.ts +8 -7
  291. package/src/runtime/api-error-class.ts +1 -1
  292. package/src/runtime/api-url.ts +5 -4
  293. package/src/runtime/await-failed.ts +9 -0
  294. package/src/runtime/await.server.ts +14 -4
  295. package/src/runtime/await.ts +3 -3
  296. package/src/runtime/button-form.ts +5 -0
  297. package/src/runtime/cache-hooks.ts +54 -0
  298. package/src/runtime/cache-live-id.ts +3 -0
  299. package/src/runtime/cache.ts +12 -36
  300. package/src/runtime/call-result.ts +86 -21
  301. package/src/runtime/checks.ts +27 -17
  302. package/src/runtime/consent.ts +3 -2
  303. package/src/runtime/core.ts +99 -27
  304. package/src/runtime/dispatch.ts +11 -0
  305. package/src/runtime/dom-await.ts +39 -9
  306. package/src/runtime/dom-image.ts +2 -2
  307. package/src/runtime/dom.ts +11 -12
  308. package/src/runtime/duration-words.ts +2 -1
  309. package/src/runtime/duration.ts +5 -3
  310. package/src/runtime/edit.ts +3 -2
  311. package/src/runtime/env.ts +2 -1
  312. package/src/runtime/forms.ts +15 -5
  313. package/src/runtime/head.ts +3 -1
  314. package/src/runtime/html.ts +10 -6
  315. package/src/runtime/i18n.client.ts +12 -6
  316. package/src/runtime/i18n.server.ts +12 -6
  317. package/src/runtime/i18n.ts +28 -8
  318. package/src/runtime/image.ts +16 -18
  319. package/src/runtime/index.ts +9 -8
  320. package/src/runtime/internal.ts +2 -1
  321. package/src/runtime/invalidated-keys.ts +11 -0
  322. package/src/runtime/island.server.ts +18 -10
  323. package/src/runtime/jsx.ts +6 -1
  324. package/src/runtime/kay-error.ts +29 -0
  325. package/src/runtime/leave.ts +1 -0
  326. package/src/runtime/live-cache.ts +8 -1
  327. package/src/runtime/live-resource.server.ts +1 -0
  328. package/src/runtime/live-revalidate.ts +53 -0
  329. package/src/runtime/live-value.client.ts +36 -3
  330. package/src/runtime/live-value.server.ts +10 -6
  331. package/src/runtime/live-value.shared.ts +50 -10
  332. package/src/runtime/live-value.ts +16 -4
  333. package/src/runtime/live.ts +92 -137
  334. package/src/runtime/local-types.ts +106 -0
  335. package/src/runtime/local.ts +31 -109
  336. package/src/runtime/log.ts +3 -1
  337. package/src/runtime/mount.compat.ts +8 -0
  338. package/src/runtime/navigate-api.ts +17 -8
  339. package/src/runtime/navigation-state.ts +50 -13
  340. package/src/runtime/navigation.ts +3 -3
  341. package/src/runtime/optimistic.ts +1 -1
  342. package/src/runtime/page-swap.ts +11 -6
  343. package/src/runtime/persist.ts +2 -1
  344. package/src/runtime/persisted.ts +43 -38
  345. package/src/runtime/presence.ts +15 -9
  346. package/src/runtime/queue-jobs.ts +2 -1
  347. package/src/runtime/reactive.ts +4 -5
  348. package/src/runtime/refuse.ts +23 -6
  349. package/src/runtime/resource-tags.ts +35 -0
  350. package/src/runtime/route.ts +3 -2
  351. package/src/runtime/sanitize.ts +4 -3
  352. package/src/runtime/schema.client.ts +2 -1
  353. package/src/runtime/schema.ts +2 -1
  354. package/src/runtime/send.ts +2 -1
  355. package/src/runtime/shortcut.ts +10 -3
  356. package/src/runtime/socket-message.ts +26 -0
  357. package/src/runtime/store-base.ts +22 -0
  358. package/src/runtime/swap-fetch.ts +2 -1
  359. package/src/runtime/swap.ts +4 -0
  360. package/src/runtime/template-context.ts +4 -2
  361. package/src/runtime/values.ts +28 -10
  362. package/src/runtime/wire.ts +13 -3
  363. package/src/runtime/with-query.ts +3 -2
  364. package/src/runtime/work.ts +4 -2
  365. package/src/server/action-hooks.ts +15 -8
  366. package/src/server/action-iterable.ts +18 -3
  367. package/src/server/actions.ts +31 -18
  368. package/src/server/address.ts +1 -1
  369. package/src/server/analytics-server.ts +2 -1
  370. package/src/server/api-modules.ts +38 -26
  371. package/src/server/api.ts +17 -96
  372. package/src/server/app-database.ts +11 -0
  373. package/src/server/app-hooks.ts +25 -6
  374. package/src/server/app-stages.ts +91 -60
  375. package/src/server/app.ts +25 -13
  376. package/src/server/auth-mails.ts +2 -0
  377. package/src/server/basic-auth.ts +27 -7
  378. package/src/server/bundle.ts +2 -0
  379. package/src/server/button-form-rule.ts +20 -0
  380. package/src/server/card.ts +2 -2
  381. package/src/server/ceiling.ts +1 -1
  382. package/src/server/client.ts +2 -2
  383. package/src/server/config-error.ts +2 -2
  384. package/src/server/config-limits.ts +37 -17
  385. package/src/server/context-values.ts +4 -3
  386. package/src/server/cookies.ts +4 -2
  387. package/src/server/endpoints.ts +5 -2
  388. package/src/server/entry-drafts.ts +1 -1
  389. package/src/server/errors.ts +4 -3
  390. package/src/server/event-stream.ts +7 -4
  391. package/src/server/favicon.ts +59 -10
  392. package/src/server/fetch-public.ts +4 -3
  393. package/src/server/file-answer.ts +89 -0
  394. package/src/server/forms.ts +1 -1
  395. package/src/server/guard-requirement.ts +7 -0
  396. package/src/server/guards.ts +74 -2
  397. package/src/server/hooks.ts +10 -10
  398. package/src/server/i18n.ts +8 -9
  399. package/src/server/image-limits.ts +4 -3
  400. package/src/server/image.ts +17 -15
  401. package/src/server/index.ts +15 -9
  402. package/src/server/job-context.ts +35 -0
  403. package/src/server/jobs-page.ts +14 -8
  404. package/src/server/jobs.ts +48 -13
  405. package/src/server/kept-exports.ts +3 -1
  406. package/src/server/kv.ts +34 -18
  407. package/src/server/lazy-guard.ts +4 -1
  408. package/src/server/library.ts +5 -2
  409. package/src/server/lifecycle.ts +5 -5
  410. package/src/server/link-schemes.ts +5 -5
  411. package/src/server/live.ts +79 -7
  412. package/src/server/load-budget.ts +2 -2
  413. package/src/server/loader.ts +4 -2
  414. package/src/server/log.ts +18 -3
  415. package/src/server/maintenance.ts +1 -1
  416. package/src/server/mcp-key.ts +27 -24
  417. package/src/server/mcp.ts +21 -8
  418. package/src/server/message-drafts.ts +2 -2
  419. package/src/server/metrics.ts +42 -14
  420. package/src/server/moved-exports.ts +17 -0
  421. package/src/server/not-found-config.ts +4 -3
  422. package/src/server/notifications.ts +2 -2
  423. package/src/server/openapi.ts +9 -13
  424. package/src/server/over-limit.ts +29 -0
  425. package/src/server/page-limits.ts +1 -1
  426. package/src/server/page-routes.ts +2 -2
  427. package/src/server/page-seo.ts +29 -0
  428. package/src/server/page-settings.ts +69 -8
  429. package/src/server/pg-data.ts +3 -2
  430. package/src/server/pg-jobs.ts +3 -2
  431. package/src/server/pg-limit.ts +4 -3
  432. package/src/server/pg-live.ts +3 -1
  433. package/src/server/pg-not-found.ts +2 -1
  434. package/src/server/pg-poll.ts +3 -3
  435. package/src/server/pg-redirects.ts +3 -2
  436. package/src/server/pg-stores.ts +9 -7
  437. package/src/server/prerender.ts +21 -10
  438. package/src/server/preview.ts +3 -1
  439. package/src/server/protection.ts +20 -44
  440. package/src/server/proxy-key.ts +17 -39
  441. package/src/server/pure-page.ts +2 -29
  442. package/src/server/push-crypto.ts +3 -2
  443. package/src/server/push-server.ts +2 -1
  444. package/src/server/push.ts +6 -6
  445. package/src/server/queue-scheduler.ts +5 -0
  446. package/src/server/queue.ts +21 -29
  447. package/src/server/rate-limit.ts +21 -13
  448. package/src/server/rate-windows.ts +14 -0
  449. package/src/server/redirects.ts +29 -2
  450. package/src/server/remote.ts +5 -4
  451. package/src/server/render-document.ts +32 -11
  452. package/src/server/render.ts +6 -6
  453. package/src/server/report.ts +5 -5
  454. package/src/server/request-record.ts +2 -0
  455. package/src/server/resources.ts +2 -1
  456. package/src/server/rooms.ts +177 -23
  457. package/src/server/route-settings.ts +236 -0
  458. package/src/server/routes.ts +25 -195
  459. package/src/server/save-data.ts +1 -1
  460. package/src/server/scope.ts +1 -1
  461. package/src/server/secret.ts +76 -0
  462. package/src/server/security.ts +15 -10
  463. package/src/server/seo.ts +19 -7
  464. package/src/server/served-paths.ts +2 -1
  465. package/src/server/session.ts +39 -18
  466. package/src/server/setup.ts +17 -10
  467. package/src/server/signals.ts +23 -3
  468. package/src/server/signed.ts +7 -4
  469. package/src/server/sitemap.ts +6 -4
  470. package/src/server/socket.ts +371 -0
  471. package/src/server/source.ts +13 -7
  472. package/src/server/sqlite-live.ts +3 -1
  473. package/src/server/storage.ts +21 -48
  474. package/src/server/stream.ts +23 -14
  475. package/src/server/translations.ts +2 -2
  476. package/src/server/uncaught.ts +2 -2
  477. package/src/server/violations.ts +4 -3
  478. package/src/server/vitals-routes/_guard.ts +1 -1
  479. package/src/server/vitals-server.ts +2 -1
  480. package/src/server/vitals.ts +5 -2
  481. package/src/server/words.ts +4 -0
  482. package/src/server/work-scope.ts +4 -2
  483. package/src/server/work.ts +4 -3
  484. package/src/server/workers.ts +2 -1
  485. package/src/server/workflow.ts +19 -11
  486. package/src/server/ws-limits.ts +51 -69
  487. package/src/template-config.ts +11 -4
  488. package/src/template-docker.ts +2 -2
  489. package/src/template-shared.ts +4 -1
  490. package/src/template-starter.ts +26 -5
  491. package/src/template-styles.ts +55 -43
  492. package/src/template-ws.ts +1 -1
  493. package/src/templates.ts +2 -4
  494. package/src/test/a11y.ts +55 -0
  495. package/src/test/browser.ts +7 -53
  496. package/src/test/index.ts +31 -39
  497. package/src/test/mount.ts +5 -4
  498. package/src/test/outgoing.ts +138 -0
  499. package/src/test/page-types.ts +3 -0
  500. package/src/test/screenshot-match.ts +69 -0
  501. package/src/test/service.ts +11 -5
  502. package/src/test/site-actions.ts +22 -19
  503. package/src/test/site-keys.ts +49 -0
  504. package/src/test/site-socket.ts +42 -38
  505. package/src/test/site-types.ts +41 -12
  506. package/src/test/site-world.ts +86 -0
  507. package/src/test/text-match.ts +44 -0
  508. package/types/add.d.ts.map +1 -1
  509. package/types/build/await-alert.d.ts +4 -0
  510. package/types/build/await-alert.d.ts.map +1 -0
  511. package/types/build/class-rules.d.ts +1 -0
  512. package/types/build/class-rules.d.ts.map +1 -1
  513. package/types/build/client.d.ts.map +1 -1
  514. package/types/build/compile.d.ts +1 -0
  515. package/types/build/compile.d.ts.map +1 -1
  516. package/types/build/recipe-classes.d.ts +2 -0
  517. package/types/build/recipe-classes.d.ts.map +1 -1
  518. package/types/build/recipe-utilities.d.ts +4 -0
  519. package/types/build/recipe-utilities.d.ts.map +1 -0
  520. package/types/build/server-record.d.ts.map +1 -1
  521. package/types/build/signals.d.ts.map +1 -1
  522. package/types/build/static.d.ts.map +1 -1
  523. package/types/build/style-uses.d.ts +1 -0
  524. package/types/build/style-uses.d.ts.map +1 -1
  525. package/types/build/styles.d.ts.map +1 -1
  526. package/types/build/supports.d.ts +1 -1
  527. package/types/build/supports.d.ts.map +1 -1
  528. package/types/build/transform.d.ts.map +1 -1
  529. package/types/build/verify.d.ts +3 -2
  530. package/types/build/verify.d.ts.map +1 -1
  531. package/types/check/action-readers.d.ts +3 -0
  532. package/types/check/action-readers.d.ts.map +1 -0
  533. package/types/check/action-type.d.ts +3 -0
  534. package/types/check/action-type.d.ts.map +1 -0
  535. package/types/check/ai-language.d.ts +3 -0
  536. package/types/check/ai-language.d.ts.map +1 -0
  537. package/types/check/app-hooks.d.ts +3 -0
  538. package/types/check/app-hooks.d.ts.map +1 -0
  539. package/types/check/auth-methods.d.ts +3 -0
  540. package/types/check/auth-methods.d.ts.map +1 -0
  541. package/types/check/auth-rate-limits.d.ts +3 -0
  542. package/types/check/auth-rate-limits.d.ts.map +1 -0
  543. package/types/check/boot.d.ts.map +1 -1
  544. package/types/check/client-keys.d.ts +3 -0
  545. package/types/check/client-keys.d.ts.map +1 -0
  546. package/types/check/cms-options.d.ts +3 -0
  547. package/types/check/cms-options.d.ts.map +1 -0
  548. package/types/check/config-groups.d.ts +3 -0
  549. package/types/check/config-groups.d.ts.map +1 -0
  550. package/types/check/config-objects.d.ts +16 -0
  551. package/types/check/config-objects.d.ts.map +1 -0
  552. package/types/check/config-switches.d.ts +3 -0
  553. package/types/check/config-switches.d.ts.map +1 -0
  554. package/types/check/context-import.d.ts +3 -0
  555. package/types/check/context-import.d.ts.map +1 -0
  556. package/types/check/diagnose.d.ts +1 -1
  557. package/types/check/diagnose.d.ts.map +1 -1
  558. package/types/check/env-files.d.ts +3 -0
  559. package/types/check/env-files.d.ts.map +1 -0
  560. package/types/check/env-types.d.ts.map +1 -1
  561. package/types/check/format-duration.d.ts +5 -0
  562. package/types/check/format-duration.d.ts.map +1 -0
  563. package/types/check/generated.d.ts +2 -0
  564. package/types/check/generated.d.ts.map +1 -1
  565. package/types/check/guard-options.d.ts +3 -0
  566. package/types/check/guard-options.d.ts.map +1 -0
  567. package/types/check/hook-context.d.ts +3 -0
  568. package/types/check/hook-context.d.ts.map +1 -0
  569. package/types/check/hook-names.d.ts +3 -0
  570. package/types/check/hook-names.d.ts.map +1 -0
  571. package/types/check/i18n-keys.d.ts +3 -0
  572. package/types/check/i18n-keys.d.ts.map +1 -0
  573. package/types/check/images-keys.d.ts +3 -0
  574. package/types/check/images-keys.d.ts.map +1 -0
  575. package/types/check/index.d.ts +7 -4
  576. package/types/check/index.d.ts.map +1 -1
  577. package/types/check/job-shapes.d.ts +6 -0
  578. package/types/check/job-shapes.d.ts.map +1 -0
  579. package/types/check/live-api.d.ts +3 -0
  580. package/types/check/live-api.d.ts.map +1 -0
  581. package/types/check/mail-api.d.ts +3 -0
  582. package/types/check/mail-api.d.ts.map +1 -0
  583. package/types/check/moved-keys.d.ts +10 -0
  584. package/types/check/moved-keys.d.ts.map +1 -0
  585. package/types/check/one-state-api.d.ts +9 -0
  586. package/types/check/one-state-api.d.ts.map +1 -0
  587. package/types/check/output-schema.d.ts +1 -1
  588. package/types/check/output-schema.d.ts.map +1 -1
  589. package/types/check/page-heads.d.ts.map +1 -1
  590. package/types/check/pages-options.d.ts +3 -0
  591. package/types/check/pages-options.d.ts.map +1 -0
  592. package/types/check/project.d.ts.map +1 -1
  593. package/types/check/rate-enforce.d.ts +3 -0
  594. package/types/check/rate-enforce.d.ts.map +1 -0
  595. package/types/check/refusal-calls.d.ts +3 -0
  596. package/types/check/refusal-calls.d.ts.map +1 -0
  597. package/types/check/regroup.d.ts +8 -0
  598. package/types/check/regroup.d.ts.map +1 -0
  599. package/types/check/removed-ui-tokens.d.ts +2 -0
  600. package/types/check/removed-ui-tokens.d.ts.map +1 -1
  601. package/types/check/renamed-packages.d.ts.map +1 -1
  602. package/types/check/retired-lints.d.ts +3 -0
  603. package/types/check/retired-lints.d.ts.map +1 -0
  604. package/types/check/route-keys.d.ts +3 -0
  605. package/types/check/route-keys.d.ts.map +1 -0
  606. package/types/check/route-shadow.d.ts +12 -0
  607. package/types/check/route-shadow.d.ts.map +1 -0
  608. package/types/check/secret-keys.d.ts +3 -0
  609. package/types/check/secret-keys.d.ts.map +1 -0
  610. package/types/check/seo.d.ts +3 -1
  611. package/types/check/seo.d.ts.map +1 -1
  612. package/types/check/shadow-types.d.ts +1 -0
  613. package/types/check/shadow-types.d.ts.map +1 -1
  614. package/types/check/shadow.d.ts +1 -0
  615. package/types/check/shadow.d.ts.map +1 -1
  616. package/types/check/socket-frames.d.ts +3 -0
  617. package/types/check/socket-frames.d.ts.map +1 -0
  618. package/types/check/source-readers.d.ts +3 -0
  619. package/types/check/source-readers.d.ts.map +1 -0
  620. package/types/check/store-ms.d.ts +3 -0
  621. package/types/check/store-ms.d.ts.map +1 -0
  622. package/types/check/store-names.d.ts +3 -0
  623. package/types/check/store-names.d.ts.map +1 -0
  624. package/types/check/template-hints.d.ts +2 -0
  625. package/types/check/template-hints.d.ts.map +1 -1
  626. package/types/check/test-helpers.d.ts +3 -0
  627. package/types/check/test-helpers.d.ts.map +1 -0
  628. package/types/check/text-size-colour.d.ts +3 -0
  629. package/types/check/text-size-colour.d.ts.map +1 -0
  630. package/types/check/ttl-names.d.ts +3 -0
  631. package/types/check/ttl-names.d.ts.map +1 -0
  632. package/types/commands/check.d.ts.map +1 -1
  633. package/types/commands/env.d.ts.map +1 -1
  634. package/types/commands/explain-island.d.ts.map +1 -1
  635. package/types/commands/new.d.ts.map +1 -1
  636. package/types/commands/routes.d.ts.map +1 -1
  637. package/types/commands/upgrade-majors.d.ts +7 -0
  638. package/types/commands/upgrade-majors.d.ts.map +1 -0
  639. package/types/commands/upgrade-manifest.d.ts +6 -0
  640. package/types/commands/upgrade-manifest.d.ts.map +1 -0
  641. package/types/commands/upgrade-messages.d.ts +4 -0
  642. package/types/commands/upgrade-messages.d.ts.map +1 -0
  643. package/types/commands/upgrade-peers.d.ts +23 -0
  644. package/types/commands/upgrade-peers.d.ts.map +1 -0
  645. package/types/commands/upgrade.d.ts +7 -0
  646. package/types/commands/upgrade.d.ts.map +1 -1
  647. package/types/compiler/a11y.d.ts.map +1 -1
  648. package/types/compiler/aria.d.ts +1 -0
  649. package/types/compiler/aria.d.ts.map +1 -1
  650. package/types/compiler/ast.d.ts +13 -16
  651. package/types/compiler/ast.d.ts.map +1 -1
  652. package/types/compiler/bound-props.d.ts +16 -0
  653. package/types/compiler/bound-props.d.ts.map +1 -0
  654. package/types/compiler/browser.d.ts.map +1 -1
  655. package/types/compiler/button-forms.d.ts +3 -0
  656. package/types/compiler/button-forms.d.ts.map +1 -0
  657. package/types/compiler/codegen.d.ts +2 -1
  658. package/types/compiler/codegen.d.ts.map +1 -1
  659. package/types/compiler/deprecated-ai-labels.d.ts +5 -0
  660. package/types/compiler/deprecated-ai-labels.d.ts.map +1 -0
  661. package/types/compiler/deprecated-ai-links.d.ts +5 -0
  662. package/types/compiler/deprecated-ai-links.d.ts.map +1 -0
  663. package/types/compiler/deprecated-allow.d.ts +5 -0
  664. package/types/compiler/deprecated-allow.d.ts.map +1 -0
  665. package/types/compiler/deprecated-auth-lints.d.ts +12 -0
  666. package/types/compiler/deprecated-auth-lints.d.ts.map +1 -0
  667. package/types/compiler/deprecated-auth-signed.d.ts +5 -0
  668. package/types/compiler/deprecated-auth-signed.d.ts.map +1 -0
  669. package/types/compiler/deprecated-children.d.ts +4 -0
  670. package/types/compiler/deprecated-children.d.ts.map +1 -0
  671. package/types/compiler/deprecated-image.d.ts +5 -0
  672. package/types/compiler/deprecated-image.d.ts.map +1 -0
  673. package/types/compiler/deprecated-island.d.ts +9 -0
  674. package/types/compiler/deprecated-island.d.ts.map +1 -0
  675. package/types/compiler/deprecated-library.d.ts +4 -0
  676. package/types/compiler/deprecated-library.d.ts.map +1 -0
  677. package/types/compiler/deprecated-lints.d.ts +527 -20
  678. package/types/compiler/deprecated-lints.d.ts.map +1 -1
  679. package/types/compiler/deprecated-page.d.ts +4 -0
  680. package/types/compiler/deprecated-page.d.ts.map +1 -0
  681. package/types/compiler/deprecated-parts.d.ts +3 -0
  682. package/types/compiler/deprecated-parts.d.ts.map +1 -0
  683. package/types/compiler/deprecated-ui-callbacks.d.ts +5 -0
  684. package/types/compiler/deprecated-ui-callbacks.d.ts.map +1 -0
  685. package/types/compiler/deprecated-ui-input.d.ts +5 -0
  686. package/types/compiler/deprecated-ui-input.d.ts.map +1 -0
  687. package/types/compiler/deprecated-ui-items.d.ts +5 -0
  688. package/types/compiler/deprecated-ui-items.d.ts.map +1 -0
  689. package/types/compiler/deprecated-ui-props.d.ts.map +1 -1
  690. package/types/compiler/dom-fields.d.ts +7 -0
  691. package/types/compiler/dom-fields.d.ts.map +1 -0
  692. package/types/compiler/dom.d.ts +5 -2
  693. package/types/compiler/dom.d.ts.map +1 -1
  694. package/types/compiler/errors.d.ts +43 -18
  695. package/types/compiler/errors.d.ts.map +1 -1
  696. package/types/compiler/fence-checks.d.ts.map +1 -1
  697. package/types/compiler/form-action.d.ts +8 -0
  698. package/types/compiler/form-action.d.ts.map +1 -0
  699. package/types/compiler/form-info.d.ts +29 -0
  700. package/types/compiler/form-info.d.ts.map +1 -0
  701. package/types/compiler/head-shorthand.d.ts +16 -0
  702. package/types/compiler/head-shorthand.d.ts.map +1 -0
  703. package/types/compiler/head-tags.d.ts +7 -0
  704. package/types/compiler/head-tags.d.ts.map +1 -0
  705. package/types/compiler/helper-imports.d.ts +5 -0
  706. package/types/compiler/helper-imports.d.ts.map +1 -0
  707. package/types/compiler/html-initial.d.ts +16 -0
  708. package/types/compiler/html-initial.d.ts.map +1 -0
  709. package/types/compiler/html-parts.d.ts +13 -0
  710. package/types/compiler/html-parts.d.ts.map +1 -0
  711. package/types/compiler/html.d.ts +3 -2
  712. package/types/compiler/html.d.ts.map +1 -1
  713. package/types/compiler/if-alias.d.ts.map +1 -1
  714. package/types/compiler/image-attributes.d.ts +22 -0
  715. package/types/compiler/image-attributes.d.ts.map +1 -0
  716. package/types/compiler/index.d.ts +2 -0
  717. package/types/compiler/index.d.ts.map +1 -1
  718. package/types/compiler/island-arguments.d.ts +6 -1
  719. package/types/compiler/island-arguments.d.ts.map +1 -1
  720. package/types/compiler/island-cause.d.ts +2 -2
  721. package/types/compiler/island-cause.d.ts.map +1 -1
  722. package/types/compiler/island-declaration.d.ts +30 -0
  723. package/types/compiler/island-declaration.d.ts.map +1 -0
  724. package/types/compiler/island-marker.d.ts.map +1 -1
  725. package/types/compiler/items.d.ts +3 -0
  726. package/types/compiler/items.d.ts.map +1 -1
  727. package/types/compiler/jsx-class.d.ts +2 -1
  728. package/types/compiler/jsx-class.d.ts.map +1 -1
  729. package/types/compiler/jsx-field.d.ts +13 -0
  730. package/types/compiler/jsx-field.d.ts.map +1 -0
  731. package/types/compiler/jsx.d.ts +1 -0
  732. package/types/compiler/jsx.d.ts.map +1 -1
  733. package/types/compiler/kay-exports.d.ts.map +1 -1
  734. package/types/compiler/link-flags.d.ts +12 -0
  735. package/types/compiler/link-flags.d.ts.map +1 -0
  736. package/types/compiler/lints.d.ts +570 -54
  737. package/types/compiler/lints.d.ts.map +1 -1
  738. package/types/compiler/live-reads.d.ts +13 -0
  739. package/types/compiler/live-reads.d.ts.map +1 -0
  740. package/types/compiler/loop-lints.d.ts +4 -4
  741. package/types/compiler/loop-lints.d.ts.map +1 -1
  742. package/types/compiler/markup-fields.d.ts +8 -0
  743. package/types/compiler/markup-fields.d.ts.map +1 -0
  744. package/types/compiler/markup.d.ts +9 -5
  745. package/types/compiler/markup.d.ts.map +1 -1
  746. package/types/compiler/module-signals.d.ts +14 -1
  747. package/types/compiler/module-signals.d.ts.map +1 -1
  748. package/types/compiler/names.d.ts +4 -0
  749. package/types/compiler/names.d.ts.map +1 -1
  750. package/types/compiler/old-parts.d.ts +9 -0
  751. package/types/compiler/old-parts.d.ts.map +1 -0
  752. package/types/compiler/page-settings.d.ts +1 -0
  753. package/types/compiler/page-settings.d.ts.map +1 -1
  754. package/types/compiler/parser.d.ts.map +1 -1
  755. package/types/compiler/plan.d.ts +1 -0
  756. package/types/compiler/plan.d.ts.map +1 -1
  757. package/types/compiler/rewrite-reads.d.ts +8 -0
  758. package/types/compiler/rewrite-reads.d.ts.map +1 -1
  759. package/types/compiler/rewrite-types.d.ts +1 -0
  760. package/types/compiler/rewrite-types.d.ts.map +1 -1
  761. package/types/compiler/rewrite.d.ts.map +1 -1
  762. package/types/compiler/route-lints.d.ts +21 -6
  763. package/types/compiler/route-lints.d.ts.map +1 -1
  764. package/types/compiler/script-props.d.ts.map +1 -1
  765. package/types/compiler/script-server.d.ts.map +1 -1
  766. package/types/compiler/script-shared.d.ts +9 -0
  767. package/types/compiler/script-shared.d.ts.map +1 -1
  768. package/types/compiler/script.d.ts.map +1 -1
  769. package/types/compiler/server-imports.d.ts +4 -0
  770. package/types/compiler/server-imports.d.ts.map +1 -0
  771. package/types/compiler/slot-types.d.ts +13 -0
  772. package/types/compiler/slot-types.d.ts.map +1 -0
  773. package/types/compiler/style-arguments.d.ts +6 -0
  774. package/types/compiler/style-arguments.d.ts.map +1 -0
  775. package/types/compiler/template-walk.d.ts +7 -0
  776. package/types/compiler/template-walk.d.ts.map +1 -0
  777. package/types/compiler/type-parameters.d.ts +3 -0
  778. package/types/compiler/type-parameters.d.ts.map +1 -0
  779. package/types/compiler/validate-fields.d.ts +10 -0
  780. package/types/compiler/validate-fields.d.ts.map +1 -0
  781. package/types/compiler/validate.d.ts.map +1 -1
  782. package/types/config-extensions.d.ts +3 -1
  783. package/types/config-extensions.d.ts.map +1 -1
  784. package/types/config-loader.d.ts +2 -2
  785. package/types/config-loader.d.ts.map +1 -1
  786. package/types/config-resolve.d.ts +3 -0
  787. package/types/config-resolve.d.ts.map +1 -0
  788. package/types/config-shape.d.ts +2 -1
  789. package/types/config-shape.d.ts.map +1 -1
  790. package/types/config-switch.d.ts +10 -0
  791. package/types/config-switch.d.ts.map +1 -0
  792. package/types/config.d.ts +228 -67
  793. package/types/config.d.ts.map +1 -1
  794. package/types/generate-resource.d.ts.map +1 -1
  795. package/types/lsp/diagnostics.d.ts.map +1 -1
  796. package/types/lsp/route-documents.d.ts +4 -0
  797. package/types/lsp/route-documents.d.ts.map +1 -0
  798. package/types/lsp/server.d.ts +3 -0
  799. package/types/lsp/server.d.ts.map +1 -1
  800. package/types/new.d.ts.map +1 -1
  801. package/types/project.d.ts +7 -4
  802. package/types/project.d.ts.map +1 -1
  803. package/types/runtime/action-call.d.ts +11 -3
  804. package/types/runtime/action-call.d.ts.map +1 -1
  805. package/types/runtime/action-encode.d.ts.map +1 -1
  806. package/types/runtime/action-error.d.ts.map +1 -1
  807. package/types/runtime/action-form.d.ts +10 -3
  808. package/types/runtime/action-form.d.ts.map +1 -1
  809. package/types/runtime/action-navigate.d.ts +1 -0
  810. package/types/runtime/action-navigate.d.ts.map +1 -1
  811. package/types/runtime/action-owner.d.ts +1 -0
  812. package/types/runtime/action-owner.d.ts.map +1 -1
  813. package/types/runtime/action-post.d.ts.map +1 -1
  814. package/types/runtime/action-protection.d.ts.map +1 -1
  815. package/types/runtime/action-shared.d.ts +76 -15
  816. package/types/runtime/action-shared.d.ts.map +1 -1
  817. package/types/runtime/action-stream.d.ts +1 -1
  818. package/types/runtime/action-stream.d.ts.map +1 -1
  819. package/types/runtime/action.d.ts +5 -5
  820. package/types/runtime/action.d.ts.map +1 -1
  821. package/types/runtime/api-url.d.ts.map +1 -1
  822. package/types/runtime/await-failed.d.ts +8 -0
  823. package/types/runtime/await-failed.d.ts.map +1 -0
  824. package/types/runtime/await.d.ts +2 -2
  825. package/types/runtime/await.d.ts.map +1 -1
  826. package/types/runtime/await.server.d.ts +6 -3
  827. package/types/runtime/await.server.d.ts.map +1 -1
  828. package/types/runtime/button-form.d.ts +3 -0
  829. package/types/runtime/button-form.d.ts.map +1 -0
  830. package/types/runtime/cache-hooks.d.ts +10 -0
  831. package/types/runtime/cache-hooks.d.ts.map +1 -0
  832. package/types/runtime/cache-live-id.d.ts +3 -0
  833. package/types/runtime/cache-live-id.d.ts.map +1 -1
  834. package/types/runtime/cache.d.ts +1 -5
  835. package/types/runtime/cache.d.ts.map +1 -1
  836. package/types/runtime/call-result.d.ts +18 -9
  837. package/types/runtime/call-result.d.ts.map +1 -1
  838. package/types/runtime/checks.d.ts +13 -10
  839. package/types/runtime/checks.d.ts.map +1 -1
  840. package/types/runtime/consent.d.ts.map +1 -1
  841. package/types/runtime/core.d.ts +48 -9
  842. package/types/runtime/core.d.ts.map +1 -1
  843. package/types/runtime/dispatch.d.ts +8 -0
  844. package/types/runtime/dispatch.d.ts.map +1 -0
  845. package/types/runtime/dom-await.d.ts +1 -1
  846. package/types/runtime/dom-await.d.ts.map +1 -1
  847. package/types/runtime/dom-image.d.ts +1 -1
  848. package/types/runtime/dom-image.d.ts.map +1 -1
  849. package/types/runtime/dom.d.ts +1 -0
  850. package/types/runtime/dom.d.ts.map +1 -1
  851. package/types/runtime/duration-words.d.ts.map +1 -1
  852. package/types/runtime/duration.d.ts.map +1 -1
  853. package/types/runtime/edit.d.ts.map +1 -1
  854. package/types/runtime/env.d.ts.map +1 -1
  855. package/types/runtime/forms.d.ts.map +1 -1
  856. package/types/runtime/head.d.ts.map +1 -1
  857. package/types/runtime/html.d.ts +3 -2
  858. package/types/runtime/html.d.ts.map +1 -1
  859. package/types/runtime/i18n.client.d.ts +4 -1
  860. package/types/runtime/i18n.client.d.ts.map +1 -1
  861. package/types/runtime/i18n.d.ts +22 -7
  862. package/types/runtime/i18n.d.ts.map +1 -1
  863. package/types/runtime/i18n.server.d.ts +4 -1
  864. package/types/runtime/i18n.server.d.ts.map +1 -1
  865. package/types/runtime/image.d.ts +1 -1
  866. package/types/runtime/image.d.ts.map +1 -1
  867. package/types/runtime/index.d.ts +9 -8
  868. package/types/runtime/index.d.ts.map +1 -1
  869. package/types/runtime/internal.d.ts +2 -1
  870. package/types/runtime/internal.d.ts.map +1 -1
  871. package/types/runtime/invalidated-keys.d.ts +2 -0
  872. package/types/runtime/invalidated-keys.d.ts.map +1 -0
  873. package/types/runtime/island.server.d.ts.map +1 -1
  874. package/types/runtime/jsx.d.ts +7 -0
  875. package/types/runtime/jsx.d.ts.map +1 -1
  876. package/types/runtime/kay-error.d.ts +14 -0
  877. package/types/runtime/kay-error.d.ts.map +1 -0
  878. package/types/runtime/leave.d.ts.map +1 -1
  879. package/types/runtime/live-cache.d.ts +1 -0
  880. package/types/runtime/live-cache.d.ts.map +1 -1
  881. package/types/runtime/live-resource.server.d.ts.map +1 -1
  882. package/types/runtime/live-revalidate.d.ts +9 -0
  883. package/types/runtime/live-revalidate.d.ts.map +1 -0
  884. package/types/runtime/live-value.client.d.ts.map +1 -1
  885. package/types/runtime/live-value.d.ts +3 -0
  886. package/types/runtime/live-value.d.ts.map +1 -1
  887. package/types/runtime/live-value.server.d.ts.map +1 -1
  888. package/types/runtime/live-value.shared.d.ts +38 -6
  889. package/types/runtime/live-value.shared.d.ts.map +1 -1
  890. package/types/runtime/live.d.ts +41 -42
  891. package/types/runtime/live.d.ts.map +1 -1
  892. package/types/runtime/local-types.d.ts +86 -0
  893. package/types/runtime/local-types.d.ts.map +1 -0
  894. package/types/runtime/local.d.ts +1 -70
  895. package/types/runtime/local.d.ts.map +1 -1
  896. package/types/runtime/log.d.ts.map +1 -1
  897. package/types/runtime/mount.compat.d.ts +7 -0
  898. package/types/runtime/mount.compat.d.ts.map +1 -0
  899. package/types/runtime/navigate-api.d.ts +10 -4
  900. package/types/runtime/navigate-api.d.ts.map +1 -1
  901. package/types/runtime/navigation-state.d.ts +19 -0
  902. package/types/runtime/navigation-state.d.ts.map +1 -1
  903. package/types/runtime/page-swap.d.ts.map +1 -1
  904. package/types/runtime/persist.d.ts.map +1 -1
  905. package/types/runtime/persisted.d.ts +25 -29
  906. package/types/runtime/persisted.d.ts.map +1 -1
  907. package/types/runtime/presence.d.ts +6 -3
  908. package/types/runtime/presence.d.ts.map +1 -1
  909. package/types/runtime/queue-jobs.d.ts.map +1 -1
  910. package/types/runtime/reactive.d.ts.map +1 -1
  911. package/types/runtime/refuse.d.ts +8 -1
  912. package/types/runtime/refuse.d.ts.map +1 -1
  913. package/types/runtime/resource-tags.d.ts +4 -0
  914. package/types/runtime/resource-tags.d.ts.map +1 -0
  915. package/types/runtime/route.d.ts.map +1 -1
  916. package/types/runtime/sanitize.d.ts.map +1 -1
  917. package/types/runtime/schema.client.d.ts.map +1 -1
  918. package/types/runtime/schema.d.ts.map +1 -1
  919. package/types/runtime/send.d.ts.map +1 -1
  920. package/types/runtime/shortcut.d.ts +1 -0
  921. package/types/runtime/shortcut.d.ts.map +1 -1
  922. package/types/runtime/socket-message.d.ts +7 -0
  923. package/types/runtime/socket-message.d.ts.map +1 -0
  924. package/types/runtime/store-base.d.ts +4 -0
  925. package/types/runtime/store-base.d.ts.map +1 -1
  926. package/types/runtime/swap-fetch.d.ts.map +1 -1
  927. package/types/runtime/swap.d.ts +2 -0
  928. package/types/runtime/swap.d.ts.map +1 -1
  929. package/types/runtime/template-context.d.ts.map +1 -1
  930. package/types/runtime/values.d.ts.map +1 -1
  931. package/types/runtime/wire.d.ts +1 -0
  932. package/types/runtime/wire.d.ts.map +1 -1
  933. package/types/runtime/with-query.d.ts.map +1 -1
  934. package/types/runtime/work.d.ts.map +1 -1
  935. package/types/server/action-hooks.d.ts +4 -4
  936. package/types/server/action-hooks.d.ts.map +1 -1
  937. package/types/server/action-iterable.d.ts +2 -1
  938. package/types/server/action-iterable.d.ts.map +1 -1
  939. package/types/server/actions.d.ts +3 -2
  940. package/types/server/actions.d.ts.map +1 -1
  941. package/types/server/analytics-server.d.ts.map +1 -1
  942. package/types/server/api-modules.d.ts +16 -13
  943. package/types/server/api-modules.d.ts.map +1 -1
  944. package/types/server/api.d.ts +6 -3
  945. package/types/server/api.d.ts.map +1 -1
  946. package/types/server/app-database.d.ts +2 -0
  947. package/types/server/app-database.d.ts.map +1 -1
  948. package/types/server/app-hooks.d.ts +10 -2
  949. package/types/server/app-hooks.d.ts.map +1 -1
  950. package/types/server/app-stages.d.ts +21 -26
  951. package/types/server/app-stages.d.ts.map +1 -1
  952. package/types/server/app.d.ts +21 -24
  953. package/types/server/app.d.ts.map +1 -1
  954. package/types/server/auth-mails.d.ts +5 -0
  955. package/types/server/auth-mails.d.ts.map +1 -1
  956. package/types/server/basic-auth.d.ts +2 -5
  957. package/types/server/basic-auth.d.ts.map +1 -1
  958. package/types/server/bundle.d.ts +1 -0
  959. package/types/server/bundle.d.ts.map +1 -1
  960. package/types/server/button-form-rule.d.ts +4 -0
  961. package/types/server/button-form-rule.d.ts.map +1 -0
  962. package/types/server/card.d.ts +1 -1
  963. package/types/server/card.d.ts.map +1 -1
  964. package/types/server/config-limits.d.ts +5 -5
  965. package/types/server/config-limits.d.ts.map +1 -1
  966. package/types/server/context-values.d.ts.map +1 -1
  967. package/types/server/cookies.d.ts +2 -2
  968. package/types/server/cookies.d.ts.map +1 -1
  969. package/types/server/endpoints.d.ts.map +1 -1
  970. package/types/server/errors.d.ts +2 -2
  971. package/types/server/errors.d.ts.map +1 -1
  972. package/types/server/event-stream.d.ts +1 -1
  973. package/types/server/event-stream.d.ts.map +1 -1
  974. package/types/server/favicon.d.ts +7 -3
  975. package/types/server/favicon.d.ts.map +1 -1
  976. package/types/server/fetch-public.d.ts.map +1 -1
  977. package/types/server/file-answer.d.ts +17 -0
  978. package/types/server/file-answer.d.ts.map +1 -0
  979. package/types/server/forms.d.ts +1 -1
  980. package/types/server/forms.d.ts.map +1 -1
  981. package/types/server/guard-requirement.d.ts +6 -0
  982. package/types/server/guard-requirement.d.ts.map +1 -1
  983. package/types/server/guards.d.ts +11 -0
  984. package/types/server/guards.d.ts.map +1 -1
  985. package/types/server/hooks.d.ts +8 -8
  986. package/types/server/hooks.d.ts.map +1 -1
  987. package/types/server/i18n.d.ts.map +1 -1
  988. package/types/server/image-limits.d.ts.map +1 -1
  989. package/types/server/image.d.ts +8 -13
  990. package/types/server/image.d.ts.map +1 -1
  991. package/types/server/index.d.ts +12 -8
  992. package/types/server/index.d.ts.map +1 -1
  993. package/types/server/job-context.d.ts +16 -0
  994. package/types/server/job-context.d.ts.map +1 -0
  995. package/types/server/jobs-page.d.ts +1 -1
  996. package/types/server/jobs-page.d.ts.map +1 -1
  997. package/types/server/jobs.d.ts +22 -4
  998. package/types/server/jobs.d.ts.map +1 -1
  999. package/types/server/kept-exports.d.ts.map +1 -1
  1000. package/types/server/kv.d.ts +5 -4
  1001. package/types/server/kv.d.ts.map +1 -1
  1002. package/types/server/lazy-guard.d.ts +2 -1
  1003. package/types/server/lazy-guard.d.ts.map +1 -1
  1004. package/types/server/library.d.ts +5 -2
  1005. package/types/server/library.d.ts.map +1 -1
  1006. package/types/server/lifecycle.d.ts +2 -2
  1007. package/types/server/lifecycle.d.ts.map +1 -1
  1008. package/types/server/link-schemes.d.ts +1 -1
  1009. package/types/server/link-schemes.d.ts.map +1 -1
  1010. package/types/server/live.d.ts +5 -0
  1011. package/types/server/live.d.ts.map +1 -1
  1012. package/types/server/loader.d.ts.map +1 -1
  1013. package/types/server/log.d.ts +7 -1
  1014. package/types/server/log.d.ts.map +1 -1
  1015. package/types/server/mcp-key.d.ts +2 -3
  1016. package/types/server/mcp-key.d.ts.map +1 -1
  1017. package/types/server/mcp.d.ts +1 -0
  1018. package/types/server/mcp.d.ts.map +1 -1
  1019. package/types/server/metrics.d.ts +9 -2
  1020. package/types/server/metrics.d.ts.map +1 -1
  1021. package/types/server/moved-exports.d.ts +12 -0
  1022. package/types/server/moved-exports.d.ts.map +1 -0
  1023. package/types/server/not-found-config.d.ts.map +1 -1
  1024. package/types/server/openapi.d.ts +5 -5
  1025. package/types/server/openapi.d.ts.map +1 -1
  1026. package/types/server/over-limit.d.ts +9 -0
  1027. package/types/server/over-limit.d.ts.map +1 -0
  1028. package/types/server/page-seo.d.ts +3 -0
  1029. package/types/server/page-seo.d.ts.map +1 -0
  1030. package/types/server/page-settings.d.ts +5 -1
  1031. package/types/server/page-settings.d.ts.map +1 -1
  1032. package/types/server/pg-data.d.ts.map +1 -1
  1033. package/types/server/pg-jobs.d.ts.map +1 -1
  1034. package/types/server/pg-limit.d.ts.map +1 -1
  1035. package/types/server/pg-live.d.ts.map +1 -1
  1036. package/types/server/pg-not-found.d.ts.map +1 -1
  1037. package/types/server/pg-poll.d.ts +2 -2
  1038. package/types/server/pg-poll.d.ts.map +1 -1
  1039. package/types/server/pg-redirects.d.ts.map +1 -1
  1040. package/types/server/pg-stores.d.ts.map +1 -1
  1041. package/types/server/prerender.d.ts.map +1 -1
  1042. package/types/server/preview.d.ts +1 -1
  1043. package/types/server/preview.d.ts.map +1 -1
  1044. package/types/server/protection.d.ts +1 -2
  1045. package/types/server/protection.d.ts.map +1 -1
  1046. package/types/server/proxy-key.d.ts +3 -3
  1047. package/types/server/proxy-key.d.ts.map +1 -1
  1048. package/types/server/pure-page.d.ts.map +1 -1
  1049. package/types/server/push-crypto.d.ts.map +1 -1
  1050. package/types/server/push-server.d.ts.map +1 -1
  1051. package/types/server/queue-scheduler.d.ts +1 -0
  1052. package/types/server/queue-scheduler.d.ts.map +1 -1
  1053. package/types/server/queue.d.ts +6 -7
  1054. package/types/server/queue.d.ts.map +1 -1
  1055. package/types/server/rate-limit.d.ts +6 -1
  1056. package/types/server/rate-limit.d.ts.map +1 -1
  1057. package/types/server/rate-windows.d.ts +3 -0
  1058. package/types/server/rate-windows.d.ts.map +1 -0
  1059. package/types/server/redirects.d.ts.map +1 -1
  1060. package/types/server/remote.d.ts.map +1 -1
  1061. package/types/server/render-document.d.ts +1 -0
  1062. package/types/server/render-document.d.ts.map +1 -1
  1063. package/types/server/report.d.ts +3 -3
  1064. package/types/server/report.d.ts.map +1 -1
  1065. package/types/server/request-record.d.ts +1 -0
  1066. package/types/server/request-record.d.ts.map +1 -1
  1067. package/types/server/resources.d.ts.map +1 -1
  1068. package/types/server/rooms.d.ts +34 -4
  1069. package/types/server/rooms.d.ts.map +1 -1
  1070. package/types/server/route-settings.d.ts +9 -0
  1071. package/types/server/route-settings.d.ts.map +1 -0
  1072. package/types/server/routes.d.ts +1 -6
  1073. package/types/server/routes.d.ts.map +1 -1
  1074. package/types/server/secret.d.ts +12 -0
  1075. package/types/server/secret.d.ts.map +1 -0
  1076. package/types/server/security.d.ts +4 -5
  1077. package/types/server/security.d.ts.map +1 -1
  1078. package/types/server/seo.d.ts.map +1 -1
  1079. package/types/server/served-paths.d.ts.map +1 -1
  1080. package/types/server/session.d.ts +8 -2
  1081. package/types/server/session.d.ts.map +1 -1
  1082. package/types/server/setup.d.ts.map +1 -1
  1083. package/types/server/signals.d.ts +3 -1
  1084. package/types/server/signals.d.ts.map +1 -1
  1085. package/types/server/signed.d.ts +2 -0
  1086. package/types/server/signed.d.ts.map +1 -1
  1087. package/types/server/sitemap.d.ts +4 -3
  1088. package/types/server/sitemap.d.ts.map +1 -1
  1089. package/types/server/socket.d.ts +51 -0
  1090. package/types/server/socket.d.ts.map +1 -0
  1091. package/types/server/source.d.ts +4 -3
  1092. package/types/server/source.d.ts.map +1 -1
  1093. package/types/server/sqlite-live.d.ts.map +1 -1
  1094. package/types/server/storage.d.ts +10 -2
  1095. package/types/server/storage.d.ts.map +1 -1
  1096. package/types/server/stream.d.ts +3 -3
  1097. package/types/server/stream.d.ts.map +1 -1
  1098. package/types/server/uncaught.d.ts +2 -2
  1099. package/types/server/uncaught.d.ts.map +1 -1
  1100. package/types/server/violations.d.ts +2 -2
  1101. package/types/server/violations.d.ts.map +1 -1
  1102. package/types/server/vitals-server.d.ts.map +1 -1
  1103. package/types/server/vitals.d.ts +1 -0
  1104. package/types/server/vitals.d.ts.map +1 -1
  1105. package/types/server/words.d.ts +3 -0
  1106. package/types/server/words.d.ts.map +1 -1
  1107. package/types/server/work-scope.d.ts +2 -0
  1108. package/types/server/work-scope.d.ts.map +1 -1
  1109. package/types/server/work.d.ts +2 -2
  1110. package/types/server/work.d.ts.map +1 -1
  1111. package/types/server/workers.d.ts.map +1 -1
  1112. package/types/server/workflow.d.ts +4 -5
  1113. package/types/server/workflow.d.ts.map +1 -1
  1114. package/types/server/ws-limits.d.ts +15 -6
  1115. package/types/server/ws-limits.d.ts.map +1 -1
  1116. package/types/template-config.d.ts.map +1 -1
  1117. package/types/template-shared.d.ts +1 -1
  1118. package/types/template-shared.d.ts.map +1 -1
  1119. package/types/template-starter.d.ts.map +1 -1
  1120. package/types/template-styles.d.ts.map +1 -1
  1121. package/types/templates.d.ts.map +1 -1
  1122. package/types/test/a11y.d.ts +3 -0
  1123. package/types/test/a11y.d.ts.map +1 -0
  1124. package/types/test/browser.d.ts.map +1 -1
  1125. package/types/test/index.d.ts +8 -2
  1126. package/types/test/index.d.ts.map +1 -1
  1127. package/types/test/mount.d.ts.map +1 -1
  1128. package/types/test/outgoing.d.ts +12 -0
  1129. package/types/test/outgoing.d.ts.map +1 -0
  1130. package/types/test/page-types.d.ts +2 -0
  1131. package/types/test/page-types.d.ts.map +1 -1
  1132. package/types/test/screenshot-match.d.ts +7 -0
  1133. package/types/test/screenshot-match.d.ts.map +1 -0
  1134. package/types/test/service.d.ts +2 -0
  1135. package/types/test/service.d.ts.map +1 -1
  1136. package/types/test/site-actions.d.ts +2 -2
  1137. package/types/test/site-actions.d.ts.map +1 -1
  1138. package/types/test/site-keys.d.ts +10 -0
  1139. package/types/test/site-keys.d.ts.map +1 -0
  1140. package/types/test/site-socket.d.ts.map +1 -1
  1141. package/types/test/site-types.d.ts +32 -9
  1142. package/types/test/site-types.d.ts.map +1 -1
  1143. package/types/test/site-world.d.ts +11 -0
  1144. package/types/test/site-world.d.ts.map +1 -0
  1145. package/types/test/text-match.d.ts +13 -0
  1146. package/types/test/text-match.d.ts.map +1 -0
  1147. package/src/check/local-state.ts +0 -132
  1148. package/src/check/persisted-storage.ts +0 -87
  1149. package/types/check/local-state.d.ts +0 -3
  1150. package/types/check/local-state.d.ts.map +0 -1
  1151. package/types/check/persisted-storage.d.ts +0 -3
  1152. package/types/check/persisted-storage.d.ts.map +0 -1
@@ -1,16 +1,16 @@
1
1
  import type { TSchema } from 'elysia'
2
2
  import type { ActionsConfig } from '../config'
3
- import type { ActionDone, ActionFailed, ActionHooks, ActionRun, ServerAction } from '../runtime/action'
3
+ import type { ActionDone, ActionFailed, ActionHookContext, ActionHooks, ActionRun, ServerAction } from '../runtime/action'
4
4
  import type { ErrorShape } from '../runtime/api-error'
5
5
  import type { BeforeHook, Hook } from './hooks'
6
6
  import { resolveProtection } from '../runtime/action-protection'
7
- import { decide, dispatch } from './hooks'
7
+ import { decide, dispatch, hookContext } from './hooks'
8
8
 
9
9
  // The hooks of one action in the order they run: the app's, then the action's own.
10
10
  export interface ActionHookLists {
11
- before: BeforeHook<ActionRun, never>[]
12
- success: Hook<ActionDone>[]
13
- error: Hook<ActionFailed>[]
11
+ before: BeforeHook<ActionRun, never, ActionHookContext>[]
12
+ success: Hook<ActionDone, ActionHookContext>[]
13
+ error: Hook<ActionFailed, ActionHookContext>[]
14
14
  }
15
15
 
16
16
  const NONE: ActionHookLists = { before: [], success: [], error: [] }
@@ -30,24 +30,31 @@ export function hasHooks(lists: ActionHookLists): boolean {
30
30
  return lists.before.length + lists.success.length + lists.error.length > 0
31
31
  }
32
32
 
33
+ // The `context` of an action's hooks: the action's own, read through it as it is lazy, with who asks.
34
+ async function contextOf({ ctx }: ActionRun): Promise<ActionHookContext> {
35
+ const { ip, userAgent, userId } = await hookContext()
36
+
37
+ return Object.create(ctx, { ip: { value: ip, enumerable: true }, userAgent: { value: userAgent, enumerable: true }, userId: { value: userId, enumerable: true } }) as ActionHookContext
38
+ }
39
+
33
40
  // The `beforeRun` hooks of a run: the refusal when one stops it.
34
41
  export async function refusedBeforeRun(lists: ActionHookLists, event: ActionRun): Promise<(ErrorShape & { retryAfter?: number | undefined }) | undefined> {
35
42
  if (lists.before.length === 0)
36
43
  return undefined
37
44
 
38
- const answer = await decide('actions.beforeRun', lists.before, event)
45
+ const answer = await decide('actions.beforeRun', lists.before, event, await contextOf(event))
39
46
 
40
47
  return 'refused' in answer ? answer.refused : undefined
41
48
  }
42
49
 
43
50
  export async function tellSuccess(lists: ActionHookLists, event: ActionRun, result: unknown): Promise<void> {
44
51
  if (lists.success.length > 0)
45
- await dispatch('actions.onSuccess', lists.success, { ...event, result })
52
+ await dispatch('actions.onSuccess', lists.success, { ...event, result }, { context: await contextOf(event) })
46
53
  }
47
54
 
48
55
  export async function tellError(lists: ActionHookLists, event: ActionRun, failure: Pick<ActionFailed, 'status' | 'message' | 'errors' | 'data' | 'error'>): Promise<void> {
49
56
  if (lists.error.length > 0)
50
- await dispatch('actions.onError', lists.error, { ...event, ...failure })
57
+ await dispatch('actions.onError', lists.error, { ...event, ...failure }, { context: await contextOf(event) })
51
58
  }
52
59
 
53
60
  // The action as one app serves it, with the app's `actions` defaults laid under its own options key by key: a check the action names replaces the app's, `messages` merge one level, and `protect: false` keeps the app's checks out (its `maxSize` and `messages` still apply). The action itself is left as declared, so two apps in one process (a test site after another) each read their own defaults.
@@ -1,6 +1,7 @@
1
1
  import type { ActionOptions } from './actions'
2
2
  import type { CookieJar } from './cookies'
3
3
  import { eventBody } from './event-stream'
4
+ import { gatheringInvalidated, invalidatedText } from './live'
4
5
  import { reportServerError } from './report'
5
6
 
6
7
  export function isAsyncIterable(value: unknown): value is AsyncIterable<unknown> {
@@ -65,11 +66,25 @@ export async function started(source: AsyncIterable<unknown>, signal: AbortSigna
65
66
  }
66
67
  }
67
68
 
68
- // A call to a handler returning an async iterable gets its values as server-sent events, `readActionResponse` reading them as a stream; a throw past the first value ends it as failed.
69
- export function streamed(request: Request, jar: CookieJar, headers: Headers, source: AsyncIterable<unknown>, status: number, { onError }: ActionOptions): Response {
69
+ // The iterable, each step of it run as the handler's own, so the keys it invalidates while it streams reach `keys`.
70
+ export function gathering(source: AsyncIterable<unknown>, keys: Set<string>, asked: ReadonlySet<string>): AsyncIterable<unknown> {
71
+ return {
72
+ [Symbol.asyncIterator]: () => {
73
+ const iterator = source[Symbol.asyncIterator]()
74
+
75
+ return {
76
+ next: async () => gatheringInvalidated(keys, async () => iterator.next(), asked),
77
+ return: async (value?: unknown) => gatheringInvalidated(keys, async () => await iterator.return?.(value) ?? { done: true, value }, asked),
78
+ }
79
+ },
80
+ }
81
+ }
82
+
83
+ // A call to a handler returning an async iterable gets its values as server-sent events, `readActionResponse` reading them as a stream; a throw past the first value ends it as failed. The end event names the followed keys the handler invalidated, as an answer's header does, which the page then leaves to its live connection.
84
+ export function streamed(request: Request, jar: CookieJar, headers: Headers, source: AsyncIterable<unknown>, status: number, { onError }: ActionOptions, invalidated: ReadonlySet<string>): Response {
70
85
  jar.writeTo(headers)
71
86
  headers.set('content-type', 'text/event-stream; charset=utf-8')
72
87
  headers.set('cache-control', 'no-cache')
73
88
 
74
- return new Response(eventBody(source, error => reportServerError(error, request, onError)), { status, headers })
89
+ return new Response(eventBody(source, error => reportServerError(error, request, onError), undefined, () => invalidatedText(invalidated)), { status, headers })
75
90
  }
@@ -1,12 +1,13 @@
1
1
  import type { CookieMap } from 'bun'
2
2
  import type { Elysia, TSchema, ValidationError } from 'elysia'
3
3
  import type { Server } from 'elysia/universal'
4
- import type { ActionsConfig, ObserveConfig } from '../config'
4
+ import type { ActionsConfig } from '../config'
5
5
  import type { GuardContext, Locals, RouteParams } from '../runtime'
6
6
  import type { ActionContext, ActionRun, FieldErrors, RateKeyContext, ServerAction } from '../runtime/action'
7
7
  import type { Locale } from '../runtime/i18n'
8
8
  import type { LocaleState } from '../runtime/locale-state'
9
9
  import type { ActionHookLists } from './action-hooks'
10
+ import type { ErrorHook } from './app-hooks'
10
11
  import type { BodyLimit } from './body'
11
12
  import type { CookieJar } from './cookies'
12
13
  import type { CorsOptions } from './cors'
@@ -19,7 +20,7 @@ import type { Unmatched } from './page-routes'
19
20
  import type { ToolOutputs } from './tool-outputs'
20
21
  import { relative } from 'node:path'
21
22
  import { KayError } from '../compiler/errors'
22
- import { decodeCall, failure, FORM_CALL, isAction, isFailure, protectionFields } from '../runtime/action'
23
+ import { decodeCall, failure, FORM_CALL, FORM_FIELD, isAction, isFailure, protectionFields } from '../runtime/action'
23
24
  import { joinBase } from '../runtime/base'
24
25
  import { escapeAttribute } from '../runtime/escape'
25
26
  import { formInput } from '../runtime/form'
@@ -33,7 +34,7 @@ import { pageLocale } from '../runtime/words.server'
33
34
  import { actionClash } from './action-clash'
34
35
  import { hooksOf, refusedBeforeRun, tellError, tellSuccess, withActionDefaults } from './action-hooks'
35
36
  import { withFixedFields, withoutEmptyFiles } from './action-input'
36
- import { isAsyncIterable, lastOf, started, streamed } from './action-iterable'
37
+ import { gathering, isAsyncIterable, lastOf, started, streamed } from './action-iterable'
37
38
  import { routerPath } from './base'
38
39
  import { importModule } from './bundle'
39
40
  import { timeoutMs } from './config-limits'
@@ -45,6 +46,7 @@ import { handOver, submittedValues, writeSuccess } from './flash'
45
46
  import { requiredGuards, runGuards, unguarded } from './guards'
46
47
  import { handlerTiming } from './handler-timing'
47
48
  import { requestLocale, stateFor } from './i18n'
49
+ import { askedKeys, gatheringInvalidated, invalidatedHeader } from './live'
48
50
  import { answeringRequest } from './log'
49
51
  import { countSucceeded, isAgentCall, markChallenge, PRETEND, protectionRefusal, requestId } from './protection'
50
52
  import { sharedContext } from './render'
@@ -56,7 +58,7 @@ import { overHttps, requestUrl } from './request-url'
56
58
  import { guardUrl } from './routes'
57
59
  import { readPersonally } from './scope'
58
60
  import { carryContext } from './security'
59
- import { Denied, NotFound, Redirect, stoppers } from './signals'
61
+ import { actionStoppers, Denied, NotFound, Redirect, stoppers } from './signals'
60
62
  import { toolSettings } from './tool-settings'
61
63
  import { answered, replyTrace, SERVER_SPAN, traced } from './trace'
62
64
  import { visitAs } from './visit'
@@ -98,7 +100,7 @@ const BODY_PREFIX = /^body\./
98
100
  export interface ActionOptions {
99
101
  // Shows a failed action's message instead of a generic one.
100
102
  dev?: boolean | undefined
101
- onError?: ObserveConfig['onError'] | undefined
103
+ onError?: ErrorHook | undefined
102
104
  // An action runs in the locale of the page it was sent from, or the site's one language without `i18n`; an endpoint, which has no locale prefix, in the default one.
103
105
  i18n: I18n
104
106
  // Where the site is mounted, which the page a refused form post came from is served under.
@@ -227,6 +229,11 @@ export async function registerActionRoutes(app: Elysia, routes: ServedRoute[], m
227
229
  if (refusal)
228
230
  throw new Refusal(failed(context.request, new Headers(refusal.headers), cookieJar(context.request).cookies, { action: value.url, status: refusal.status, values: call ? {} : submittedValues(context.body), errors: { [refusal.field]: refusal.message } }, context.server, back))
229
231
 
232
+ const form = (context.body as Record<string, unknown> | null | undefined)?.[FORM_FIELD]
233
+
234
+ if (typeof form === 'string')
235
+ requestRecord(context.request).postedForm = form
236
+
230
237
  context.body = asForm ? formInput(value.schema, withFixedFields(withoutEmptyFiles(context.body), context.request)) : callInput(context.body)
231
238
  },
232
239
  // After validation, the one stage where the app's `resolve` values are there for `ctx.locals`.
@@ -598,7 +605,7 @@ async function runAction(action: ServerAction<TSchema, unknown>, context: { body
598
605
  status: (code) => {
599
606
  status = code
600
607
  },
601
- ...stoppers(request),
608
+ ...actionStoppers(request),
602
609
  fail: <Data>(code: number, data?: Data, errors?: FieldErrors) => failure(code, data as Data, errors),
603
610
  }
604
611
 
@@ -617,7 +624,8 @@ async function runAction(action: ServerAction<TSchema, unknown>, context: { body
617
624
 
618
625
  // An async iterable is taken as it is, as awaiting one that is also a thenable, a model's reply, would read it to its end before it could stream.
619
626
  const handlerStart = options.serverTiming === true ? performance.now() : undefined
620
- const returned = action.handler(context.body, ctx)
627
+ const invalidated = new Set<string>()
628
+ const returned = gatheringInvalidated(invalidated, () => action.handler(context.body, ctx), askedKeys(request))
621
629
  const result = isAsyncIterable(returned) ? returned : await returned
622
630
 
623
631
  if (handlerStart !== undefined)
@@ -635,12 +643,15 @@ async function runAction(action: ServerAction<TSchema, unknown>, context: { body
635
643
 
636
644
  // A call reads a stream as it comes; a plain form post or an agent gets its last value, as a handler returning it would.
637
645
  const streams = isAsyncIterable(result) && isCall(request) && !isAgentCall(request)
638
- const answer = isAsyncIterable(result) ? await (streams ? started(result, requestSignal(request)) : lastOf(result, requestSignal(request))) : result
646
+ const answer = isAsyncIterable(result) ? await (streams ? started : lastOf)(gathering(result, invalidated, askedKeys(request)), requestSignal(request)) : result
639
647
 
640
648
  await countGoneThrough(action, request, context.server, options)
641
649
  await tellSuccess(lists, run, answer)
642
650
 
643
- return streams ? streamed(request, jar, headers, answer as AsyncIterable<unknown>, status, options) : succeeded(action, request, jar, headers, answer, status, options.base)
651
+ // A stream names its keys on its end event, as the handler goes on invalidating until then.
652
+ invalidatedHeader(invalidated, headers, isCall(request) && !streams)
653
+
654
+ return streams ? streamed(request, jar, headers, answer as AsyncIterable<unknown>, status, options, invalidated) : succeeded(action, request, jar, headers, answer, status, options.base)
644
655
  }
645
656
  catch (error) {
646
657
  forgetOnces(request)
@@ -670,7 +681,7 @@ async function runAction(action: ServerAction<TSchema, unknown>, context: { body
670
681
  if (refused.retryAfter !== undefined)
671
682
  headers.set('retry-after', String(refused.retryAfter))
672
683
 
673
- return failed(request, headers, jar.cookies, { action: action.url, status: refused.status, values: submittedValues(context.body), errors: { '': refusalMessage(action, refused), ...refused.errors }, data: refused.data }, context.server, back)
684
+ return failed(request, headers, jar.cookies, { action: action.url, status: refused.status, values: submittedValues(context.body), errors: { ...refusalMessage(action, refused) !== '' && { '': refusalMessage(action, refused) }, ...refused.errors }, data: refused.data }, context.server, back)
674
685
  }
675
686
 
676
687
  // A mistake, or a service the handler relies on gone down: logged as any server error, and told the visitor beside the form they keep, as a refusal is.
@@ -738,8 +749,6 @@ function pretended(action: ServerAction<TSchema, unknown>, request: Request, bas
738
749
 
739
750
  // A redirect or a denial goes out with the cookies set so far; anything else was a mistake, answered with a generic 500 since Elysia would send its message.
740
751
  export function stopped(error: unknown, request: Request, { jar, headers }: GuardedRequest, options: ActionOptions): Response {
741
- const { dev, onError } = options
742
-
743
752
  if (error instanceof Redirect) {
744
753
  headers.set(redirectHeader(request), options.redirectSpelling?.(error.location) ?? error.location)
745
754
  jar.writeTo(headers)
@@ -754,9 +763,9 @@ export function stopped(error: unknown, request: Request, { jar, headers }: Guar
754
763
  return error instanceof Denied ? new Response(error.message, { status: error.status, headers }) : new Response('Not Found', { status: 404, headers })
755
764
  }
756
765
 
757
- reportServerError(error, request, onError)
766
+ reportServerError(error, request, options.onError)
758
767
 
759
- return new Response(dev && error instanceof Error ? error.message : 'Internal Server Error', { status: 500, headers: { 'content-type': TEXT } })
768
+ return new Response(options.dev && error instanceof Error ? error.message : 'Internal Server Error', { status: 500, headers: { 'content-type': TEXT } })
760
769
  }
761
770
 
762
771
  // A result holding a function or a class instance is a mistake in the handler, logged with what it returned.
@@ -783,8 +792,12 @@ async function failed(request: Request, headers: Headers, cookies: CookieMap, fl
783
792
  for (const cookie of cookies.toSetCookieHeaders())
784
793
  headers.append('set-cookie', cookie)
785
794
 
786
- if (!isCall(request))
787
- return back(request, headers, flash, server)
795
+ if (!isCall(request)) {
796
+ const form = requestRecord(request).postedForm
797
+
798
+ // The refusal tells the form that posted from the others sharing its action; one that read no field has nothing to tell.
799
+ return back(request, headers, form !== undefined && Object.keys(flash.values).length > 0 ? { ...flash, values: { ...flash.values, [FORM_FIELD]: form } } : flash, server)
800
+ }
788
801
 
789
802
  headers.set('content-type', 'application/json')
790
803
  headers.set(FAILURE_HEADER, '1')
@@ -792,7 +805,7 @@ async function failed(request: Request, headers: Headers, cookies: CookieMap, fl
792
805
  return new Response(encodeOrExplain({ errors: flash.errors, data: flash.data }, `what ${flash.action} passed to ctx.fail`), { status: flash.status, headers })
793
806
  }
794
807
 
795
- // The page renders as for a visit, through the app, its guards and hooks included, and the failure reaches `failed()` in memory, so all the visitor typed comes back whatever its length.
808
+ // The page renders as for a visit, through the app, its guards and hooks included, and the failure reaches `form.failed()` in memory, so all the visitor typed comes back whatever its length.
796
809
  // It answers the post itself, with the failure's status: a reload posts again, as after any form a server answers in place, and without the page swap a `base` keeps relative links pointing where they did on the page.
797
810
  async function renderBack(app: Elysia, base: string, request: Request, headers: Headers, flash: Flash, server: Server | null): Promise<Response> {
798
811
  const from = new URL(backTo(request, base), request.url)
@@ -803,7 +816,7 @@ async function renderBack(app: Elysia, base: string, request: Request, headers:
803
816
  let page: Response
804
817
  let html: string | undefined
805
818
 
806
- // Read through before the failure is forgotten: an `await` block streamed after the shell may read `failed()` too.
819
+ // Read through before the failure is forgotten: an `await` block streamed after the shell may read `form.failed()` too.
807
820
  try {
808
821
  page = await visitAs(request, new Request(new URL(`${path}${from.search}`, request.url), { headers: sent }), server, async visit => app.handle(visit))
809
822
 
@@ -154,7 +154,7 @@ export function pinnedLookup(resolve: Resolver, allowPrivate: boolean) {
154
154
  const answers = await resolve(host)
155
155
 
156
156
  if (answers.length === 0)
157
- throw new Error(`${host} resolves to no address`)
157
+ throw new KayError('helper-failed', `${host} resolves to no address`)
158
158
 
159
159
  if (!allowPrivate && !answers.every(({ address }) => isPublicAddress(address)))
160
160
  throw new PrivateAddressError(`${host} resolves to an address that is not public`)
@@ -12,7 +12,8 @@ import { BASE_PATH, routerPath } from './base'
12
12
  import { declined } from './consent-cookie'
13
13
  import { isCrossSite } from './cross-site'
14
14
  import { readCapped } from './errors'
15
- import { clientAddress, overLimit } from './protection'
15
+ import { overLimit } from './over-limit'
16
+ import { clientAddress } from './protection'
16
17
  import { askedPath } from './rewrite'
17
18
 
18
19
  // A visit is a URL, a title and a few short words: past this it is no visit.
@@ -3,6 +3,7 @@ import type { KayConfig } from '../config'
3
3
  import type { RateLimit } from '../runtime/action'
4
4
  import type { RateWindowMs } from './config-limits'
5
5
  import type { RouteMount } from './routes'
6
+ import type { Secret } from './secret'
6
7
  import { existsSync, realpathSync } from 'node:fs'
7
8
  import { basename, dirname, join, relative, sep } from 'node:path'
8
9
  import { TS_FILE } from '../build/files'
@@ -10,7 +11,8 @@ import { KayError } from '../compiler/errors'
10
11
  import { projectPaths } from '../project'
11
12
  import { TRAILING_SLASH } from '../runtime/base'
12
13
  import { rateLimitOf } from './config-limits'
13
- import { apiMounts, directoriesUp, falseKeys, fileAt } from './routes'
14
+ import { falseKeys, ownGuards } from './route-settings'
15
+ import { apiMounts, directoriesUp, fileAt } from './routes'
14
16
 
15
17
  // The API modules of a project and where they are served, apart from `./api` so `kay check` and the editor, which only list them, load no Elysia.
16
18
  // A module under the API directory or an extension's, as `pages()` mounts it.
@@ -30,6 +32,8 @@ export interface ApiGuard {
30
32
  file: string
31
33
  // Where it sits as the API directory and the extensions' laid over it read, whatever machine built the server: `admin/_guard.ts`.
32
34
  path: string
35
+ // The `guards` the module lists in its `api()` options, `file` being the module itself.
36
+ own?: true | undefined
33
37
  }
34
38
 
35
39
  export const API_PREFIX = '/api'
@@ -38,23 +42,22 @@ export const KAY_PREFIX = '/_kay/'
38
42
  export const OPENAPI_PATH = `${API_PREFIX}/openapi.json`
39
43
  export const REFERENCE_PATH = `${API_PREFIX}/reference`
40
44
 
41
- // The path the API modules, the OpenAPI document and its reference page are served under: `/api` by default, `serve.apiPrefix` in kay.config.ts otherwise.
45
+ // The path the API modules, the OpenAPI document and its reference page are served under: `/api` by default, `endpoints.api` in kay.config.ts otherwise.
42
46
  export function apiPathOf(value: string | undefined): string {
43
- return value === undefined ? API_PREFIX : servedPath(value, 'serve.apiPrefix')
47
+ return value === undefined ? API_PREFIX : servedPath(value, 'endpoints.api')
44
48
  }
45
- // Where `mcp` serves the app's tools.
46
- export const MCP_PATH = '/mcp'
49
+ // Where `mcp` serves the app's tools, and where it did before 1.105, which redirects there until 1.108.
50
+ export const MCP_PATH = '/_kay/mcp'
51
+ export const FORMER_MCP_PATH = '/mcp'
47
52
  // Where an MCP client finds how to sign in, which the endpoint's 401 points to.
48
53
  export const RESOURCE_METADATA = '/.well-known/oauth-protected-resource'
49
54
  const SERVED_PATH = /^\/[\w.~-]+(?:\/[\w.~-]+)*$/
50
55
 
51
56
  export interface McpConfig {
52
- // Where the endpoint is served, `/mcp` by default.
53
- path?: string | undefined
54
57
  // The most requests one client may send the endpoint in a window, `{ max: 120, window: '1m' }` by default, or `false` for no limit; a tool call also meets the limits of the action or route it calls.
55
- rateLimit?: Pick<RateLimit, 'max' | 'window'> | false | undefined
56
- // Requires this key as a bearer token (`Authorization: Bearer <key>`) on the endpoint and so on every tool call, compared in constant time, for an agent that holds a static key instead of signing in: `true` reads `KAY_MCP_KEY`, else the file `KAY_MCP_KEY_FILE` names; a string is the key; `{ file }` reads the environment, else that file, made with a random key on first use. At least 16 characters, read once at boot. A production server with `true` and no key does not boot; elsewhere every request is refused. With the key set the endpoint is open to `proxy.key`'s check, as the bearer is its credential.
57
- key?: boolean | string | { file: string } | undefined
58
+ rateLimit?: Omit<RateLimit, 'key'> | boolean | undefined
59
+ // Requires this token as a bearer token (`Authorization: Bearer <token>`) on the endpoint and so on every tool call, compared in constant time, for an agent that holds a static key instead of signing in: `true` reads `KAY_MCP_KEY`, else the file `KAY_MCP_KEY_FILE` names; a string is the token; `{ env }` names the variable that holds it; `{ file }` the file, made with a random token on first use. At least 16 characters, read once at boot. A production server with a token it cannot read does not boot; elsewhere every request is refused. With a token set the endpoint is open to `proxy.key`'s check, as the bearer is its credential.
60
+ token?: true | Secret | undefined
58
61
  // What the server tells a model about itself on `initialize`, as the MCP spec's `instructions`: guidance spanning tools, such as which to call first, that no single tool's description carries.
59
62
  instructions?: string | undefined
60
63
  }
@@ -68,11 +71,11 @@ export function mcpRateLimit(value: boolean | McpConfig | undefined): RateWindow
68
71
  }
69
72
 
70
73
  // The path an MCP endpoint is served at, or undefined while `mcp` is off.
71
- export function mcpPath(value: boolean | McpConfig | undefined): string | undefined {
74
+ export function mcpPath(value: boolean | McpConfig | undefined, at?: string): string | undefined {
72
75
  if (value === undefined || value === false)
73
76
  return undefined
74
77
 
75
- return value === true || value.path === undefined ? MCP_PATH : servedPath(value.path, 'mcp({ path })')
78
+ return at === undefined ? MCP_PATH : servedPath(at, 'endpoints.mcp')
76
79
  }
77
80
 
78
81
  // The server instructions `initialize` answers with, or undefined for none.
@@ -86,16 +89,22 @@ export function mcpInstructions(value: boolean | McpConfig | undefined): string
86
89
  }
87
90
 
88
91
  // The paths the OpenAPI document and its reference page are served at.
89
- export function openApiPaths(config: { path?: string | undefined, referencePath?: string | undefined, reference?: boolean | undefined } | undefined, apiPath = API_PREFIX): { document: string, reference: string } {
90
- const document = config?.path === undefined ? `${apiPath}/openapi.json` : servedPath(config.path, 'openapi.path')
91
- const reference = config?.referencePath === undefined ? `${apiPath}/reference` : servedPath(config.referencePath, 'openapi.referencePath')
92
+ export function openApiPaths(config: { reference?: boolean | { path?: string | undefined } | undefined } | undefined, apiPath = API_PREFIX, at?: string): { document: string, reference: string } {
93
+ const document = at === undefined ? `${apiPath}/openapi.json` : servedPath(at, 'endpoints.openapi')
94
+ const given = typeof config?.reference === 'object' ? config.reference.path : undefined
95
+ const reference = given === undefined ? `${apiPath}/reference` : servedPath(given, 'openapi.reference.path')
92
96
 
93
- if (config?.reference === true && document === reference)
94
- throw new KayError('config-invalid', `kay: openapi.path and openapi.referencePath are both ${document}; give the reference page a path of its own`)
97
+ if (referenced(config) && document === reference)
98
+ throw new KayError('config-invalid', `kay: endpoints.openapi and openapi.reference.path are both ${document}; give the reference page a path of its own`)
95
99
 
96
100
  return { document, reference }
97
101
  }
98
102
 
103
+ // Whether the reference page is served: `reference: true`, or `reference: { path }`.
104
+ export function referenced(config: { reference?: boolean | object | undefined } | undefined): boolean {
105
+ return config?.reference === true || (typeof config?.reference === 'object' && config.reference !== null)
106
+ }
107
+
99
108
  // A path kay serves a route at: absolute, one segment at least, with nothing the router reads as a parameter and nothing under kay's own `/_kay`.
100
109
  function servedPath(value: unknown, what: string): string {
101
110
  if (typeof value !== 'string' || !SERVED_PATH.test(value) || value.includes('//') || value.split('/').includes('..') || value.split('/').includes('.'))
@@ -121,15 +130,15 @@ const ROUTER_SYNTAX = /[:*']/
121
130
  const REGEX_SYNTAX = /[.*+?^${}()|[\]\\]/g
122
131
 
123
132
  // The app's API modules and its extensions', as `pages()` serves them.
124
- export async function projectApi(root: string, config: Pick<KayConfig, 'dirs' | 'extensions' | 'serve'>): Promise<ApiModule[]> {
133
+ export async function projectApi(root: string, config: Pick<KayConfig, 'dirs' | 'extensions' | 'endpoints'>): Promise<ApiModule[]> {
125
134
  const [app, ...mounts] = apiTrees(root, config)
126
135
 
127
- return scanApi(app!.dir, mounts, apiPathOf(config.serve?.apiPrefix))
136
+ return scanApi(app!.dir, mounts, apiPathOf(config.endpoints?.api))
128
137
  }
129
138
 
130
139
  // The app's API directory at the root of the API tree, then each extension's under its prefix.
131
- export function apiTrees(root: string, config: Pick<KayConfig, 'dirs' | 'extensions' | 'serve'>): RouteMount[] {
132
- const apiPath = apiPathOf(config.serve?.apiPrefix)
140
+ export function apiTrees(root: string, config: Pick<KayConfig, 'dirs' | 'extensions' | 'endpoints'>): RouteMount[] {
141
+ const apiPath = apiPathOf(config.endpoints?.api)
133
142
 
134
143
  return [{ dir: projectPaths(root, config).api, prefix: '' }, ...apiMounts(root, config.extensions)].map(tree => ({ ...tree, apiPath }))
135
144
  }
@@ -162,9 +171,11 @@ export async function scanApi(apiDir: string, mounts: RouteMount[] = [], apiPath
162
171
  continue
163
172
 
164
173
  const file = join(dir, path)
165
- const open = falseKeys(await Bun.file(file).text(), API_OPTIONS).has('guards')
174
+ const source = await Bun.file(file).text()
175
+ const open = falseKeys(source, API_OPTIONS).has('guards')
176
+ const own: ApiGuard[] = ownGuards(source, API_OPTIONS) ? [{ file, path: '', own: true }] : []
166
177
 
167
- modules.push({ file, mount, guards: open ? [] : guardsAt(trees, at), ...(open || index > 0) && { open: true }, ...extension !== undefined && { extension } })
178
+ modules.push({ file, mount, guards: [...open ? [] : guardsAt(trees, at), ...own], ...(open || index > 0) && { open: true }, ...extension !== undefined && { extension } })
168
179
  }
169
180
  }
170
181
 
@@ -174,11 +185,12 @@ export async function scanApi(apiDir: string, mounts: RouteMount[] = [], apiPath
174
185
 
175
186
  // The guards every module runs, the API directory's own first; with none of its own, those of a directory holding every module. A module setting `guards: false` runs none and leaves them as they are.
176
187
  export function sharedGuards(modules: ApiModule[]): string[] {
177
- const [first, ...rest] = modules.filter(module => module.open !== true || module.guards.length > 0)
188
+ const files = (module: ApiModule) => module.guards.filter(guard => guard.own !== true)
189
+ const [first, ...rest] = modules.filter(module => module.open !== true || files(module).length > 0)
178
190
  const shared: string[] = []
179
191
 
180
- for (const [index, guard] of first?.guards.entries() ?? []) {
181
- if (!rest.every(module => module.guards[index]?.file === guard.file))
192
+ for (const [index, guard] of first === undefined ? [] : files(first).entries()) {
193
+ if (!rest.every(module => files(module)[index]?.file === guard.file))
182
194
  break
183
195
 
184
196
  shared.push(guard.file)
package/src/server/api.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Server } from 'bun'
2
2
  import type { Context, TSchema, ValidationError } from 'elysia'
3
3
  import type { ExtensionApp } from '../config'
4
- import type { Locals } from '../runtime'
4
+ import type { Guard, Locals } from '../runtime'
5
5
  import type { ActionTool, RateLimit } from '../runtime/action'
6
6
  import type { ByteSize } from '../runtime/byte-size'
7
7
  import type { Once } from '../runtime/core'
@@ -10,17 +10,16 @@ import type { ActionOptions } from './actions'
10
10
  import type { ApiModule } from './api-modules'
11
11
  import type { BodyLimit, RouteBodyLimit } from './body'
12
12
  import type { CorsOptions, CorsRule } from './cors'
13
- import type { LoadedGuard } from './guards'
13
+ import type { GuardOption, LoadedGuard, OwnGuardValues } from './guards'
14
14
  import type { MountedApi } from './openapi'
15
15
  import type { KayPlugin } from './plugin'
16
+ import type { SocketOptions } from './socket'
16
17
  import type { SocketLimits } from './ws-limits'
17
- import { Cookie, Elysia, ElysiaCustomStatusResponse, ElysiaFile, getSchemaValidator, StatusMap } from 'elysia'
18
- import { underKayDev } from '../build/assets'
18
+ import { Cookie, Elysia, ElysiaCustomStatusResponse, ElysiaFile, StatusMap } from 'elysia'
19
19
  import { KayError } from '../compiler/errors'
20
20
  import { TRAILING_SLASH } from '../runtime/base'
21
21
  import { API_MOUNT } from '../runtime/live'
22
22
  import { runInLocale } from '../runtime/locale-state'
23
- import { kayLog } from '../runtime/log'
24
23
  import { withDefaultBounds } from '../runtime/schema-bounds'
25
24
  import { contextLocale, guardsFirst, passGuards, requestState } from './actions'
26
25
  import { withDecodedParams } from './api-params'
@@ -31,7 +30,7 @@ import { corsAdmits, corsResponse, corsRule, dropOwnGrant, grantedByKay, preflig
31
30
  import { admitCrossSite, crossSiteRefused, crossSiteResponse } from './cross-site'
32
31
  import { streamReporters } from './event-stream'
33
32
  import { refusedFields, validated } from './field-errors'
34
- import { loadGuard, requiredGuards } from './guards'
33
+ import { keepOwnGuards, loadApiGuards, requiredGuards } from './guards'
35
34
  import { handlerTiming } from './handler-timing'
36
35
  import { inRouteReads, LIVE_HEADER, routeProof } from './live'
37
36
  import { answeringRequest, statusOf } from './log'
@@ -48,6 +47,7 @@ import { mismatchOf } from './response-mismatch'
48
47
  import { apiRoutePath, withoutSlash } from './routes'
49
48
  import { markPrivate, wasReadPersonally } from './scope'
50
49
  import { carriedNames, carryContext } from './security'
50
+ import { holdToLimits, socketOptions } from './socket'
51
51
  import { answered, failed, replyTrace, SERVER_SPAN, startSpan, tracedUnder, tracing } from './trace'
52
52
  import { kayWord } from './words'
53
53
  import { socketLimits } from './ws-limits'
@@ -157,13 +157,13 @@ export async function serveApi(app: Elysia, modules: ApiModule[], options: Actio
157
157
 
158
158
  // Whichever way the module chains its `.ws()` (in a group, a guard or a used plugin), every websocket route is held to its limits.
159
159
  if (hooks && route.method === 'WS')
160
- hooks.beforeHandle = [socketLimits(route.path, hooks.detail?.messages, app), ...[hooks.beforeHandle ?? []].flat()]
160
+ hooks.beforeHandle = [socketLimits(route.path, hooks.detail?.messages, app, (request, run) => inApiLocale(request, options, run)), holdToLimits(app), ...[hooks.beforeHandle ?? []].flat()]
161
161
 
162
162
  if (hooks?.error !== undefined)
163
163
  hooks.error = [hooks.error].flat().map(hook => localizedHook(hook, options))
164
164
  }
165
165
 
166
- const guards = requiredGuards(await Promise.all(module.guards.map(async ({ file }) => loadGuard({ file, special: {} }))), module, {}, options.requireGuards)
166
+ const guards = requiredGuards(await loadApiGuards(module, instance), module, {}, options.requireGuards)
167
167
  const methods = [...new Set(instance.routes.map(route => route.method.toUpperCase()).filter(method => method !== 'OPTIONS' && method !== 'WS'))]
168
168
 
169
169
  app.group(module.mount, (group) => {
@@ -802,16 +802,16 @@ export interface ApiOptions {
802
802
  cors?: CorsOptions | false | undefined
803
803
  // At most `max` requests to any route of the module from one client, or from whatever `key` names, every `window`; past that they answer 429 with `Retry-After`. Counted after the module's guards.
804
804
  rateLimit?: RateLimit | RateLimit[] | undefined
805
- // Runs none of the guards above the module, as a page's `guards: false` does; read from the `api({ guards: false })` call as written.
806
- guards?: false | undefined
805
+ // `false` runs none of the guards above the module, as a page's `guards: false` does, read from the call as written; a guard, a list of them or `{ load }` returning one runs after the `_guard.ts` files above it.
806
+ guards?: GuardOption | boolean | undefined
807
807
  }
808
808
 
809
809
  // What a route of an `api()` module reads besides the app's locals: the values the `_guard.ts` files above it handed on, and `ctx.once`.
810
810
  type ApiRequest<Guarded extends object> = ApiLocals & { guard: Guarded, once: Once }
811
811
 
812
812
  // An Elysia instance for a module under `src/api` whose handlers read what the app's `derive` and `resolve` add, typed through `Register` as `ctx.locals` is, and `ctx.guard` and `ctx.once` as a page does.
813
- // `Guarded` names what the guards above the module return, `api<{ org: Org }>()`; it is an assertion kay does not check, as a library guard's locals are.
814
- export function api<Guarded extends object = object>(options: ApiOptions = {}): KayPlugin<ApiRequest<Guarded>> {
813
+ // What the module's own `guards` return is typed from the option; `Guarded` names what the guards above the module return, `api<{ org: Org }>()`, which the editor needs and `kay check` types from the file tree when it is left out.
814
+ export function api<Guarded extends object = object, const Own extends GuardOption | readonly Guard[] | boolean | undefined = GuardOption | boolean | undefined>(options: Omit<ApiOptions, 'guards'> & { guards?: Own } = {}): KayPlugin<ApiRequest<Guarded & OwnGuardValues<Own>>> {
815
815
  const instance = new Elysia()
816
816
 
817
817
  // `guard` is empty until the module's guards run, which set it, so a `derive` or `resolve` of the module's own reads none; only `request` is read, so Elysia parses nothing more for it.
@@ -831,92 +831,13 @@ export function api<Guarded extends object = object>(options: ApiOptions = {}):
831
831
  if (options.rateLimit !== undefined)
832
832
  Object.defineProperty(instance, RATE_LIMIT, { value: options.rateLimit })
833
833
 
834
+ keepOwnGuards(instance, options.guards)
835
+
834
836
  const socketRoute = instance.ws.bind(instance) as (path: string, options: SocketOptions) => unknown
837
+ const named = (path: string) => () => withoutSlash(apiRoutePath((instance as { [API_MOUNT]?: string })[API_MOUNT] ?? '', path))
835
838
 
836
839
  // `.ws()` returns the instance, so the chain goes on as it was written.
837
- instance.ws = ((path: string, socketOptions: SocketOptions) => socketRoute(path, decoded(instance, path, socketOptions))) as typeof instance.ws
838
-
839
- return kayPlugin(instance) as unknown as KayPlugin<ApiRequest<Guarded>>
840
- }
841
-
842
- // The first thing a schema finds wrong with a value, as text.
843
- function firstRefusal(validator: object, value: unknown): string {
844
- try {
845
- const errors = (validator as { Errors?: (value: unknown) => Iterable<{ path?: string, message?: string }> }).Errors?.(value)
846
- const first: { path?: string, message?: string } | undefined = errors?.[Symbol.iterator]().next().value as { path?: string, message?: string } | undefined
847
-
848
- return first === undefined ? 'it does not match' : `${first.path ?? ''} ${first.message ?? ''}`.trim()
849
- }
850
- catch {
851
- return 'it does not match'
852
- }
853
- }
854
-
855
- interface SocketOptions {
856
- beforeHandle?: unknown
857
- detail?: unknown
858
- body?: unknown
859
- message?: (ws: unknown, message: unknown) => unknown
860
- }
861
-
862
- interface Definitions {
863
- definitions: { typebox: never, type: never }
864
- }
865
-
866
- // A websocket route's `body` as an HTTP route's: a message arrives cleaned and decoded, `at: '1'` as `1` for an integer, and one the schema refuses is dropped, where Elysia would send the sender a validation frame carrying the schema, which an island applying every server message reads as one of its own.
867
- // Elysia's validation is left out of the route and done here, with the validator Elysia would have built.
868
- function decoded(app: Elysia, path: string, options: SocketOptions): SocketOptions {
869
- if (options.body === undefined || options.message === undefined)
870
- return options
871
-
872
- const { definitions } = app as unknown as Definitions
873
- const validator = getSchemaValidator(options.body as never, { modules: definitions.typebox, models: definitions.type, normalize: app.config.normalize })
874
-
875
- if (validator === undefined || validator.provider === 'standard')
876
- return options
840
+ instance.ws = ((path: string, routeOptions: SocketOptions) => socketRoute(path, socketOptions(instance, routeOptions, named(path)))) as typeof instance.ws
877
841
 
878
- const { message } = options
879
- let loggedAt = 0
880
-
881
- // Under `kay dev` only, and at most once a second per route: the sender is told nothing, so the developer is, in quotes as what a client sent may hold control codes.
882
- const drop = (value: unknown): undefined => {
883
- if (underKayDev() && performance.now() - loggedAt >= 1000) {
884
- loggedAt = performance.now()
885
- kayLog('warn', `the websocket route ${JSON.stringify(withoutSlash(apiRoutePath((app as { [API_MOUNT]?: string })[API_MOUNT] ?? '', path)))} dropped a message its body refused: ${JSON.stringify(firstRefusal(validator, value))}`)
886
- }
887
-
888
- return undefined
889
- }
890
-
891
- return {
892
- ...options,
893
- body: undefined,
894
- message(ws, raw) {
895
- let cleaned: unknown
896
-
897
- // A structure the cleaner cannot walk is refused as a failed check is, never passed on unstripped.
898
- try {
899
- cleaned = validator.Clean?.(raw) ?? raw
900
- }
901
- catch {
902
- return drop(raw)
903
- }
904
-
905
- if (validator.Check(cleaned) === false)
906
- return drop(cleaned)
907
-
908
- let value = cleaned
909
-
910
- try {
911
- if (validator.hasTransform)
912
- value = validator.Decode(cleaned)
913
- }
914
- catch {
915
- // A transform that refuses the value is a refused message too.
916
- return undefined
917
- }
918
-
919
- return message(ws, value)
920
- },
921
- }
842
+ return kayPlugin(instance) as unknown as KayPlugin<ApiRequest<Guarded & OwnGuardValues<Own>>>
922
843
  }