@kayjs/kay 1.107.0 → 1.109.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 (576) hide show
  1. package/dist/eslint.js +1875 -3815
  2. package/editors/zed/extension.toml +2 -2
  3. package/llms/action-protection.md +1 -1
  4. package/llms/actions-from-islands.md +5 -5
  5. package/llms/actions-refused-fields.md +4 -4
  6. package/llms/api-from-islands.md +6 -6
  7. package/llms/browser-only.md +2 -2
  8. package/llms/cdn-caching.md +1 -1
  9. package/llms/checks.md +1 -1
  10. package/llms/code-lints.md +1 -2
  11. package/llms/component-libraries.md +1 -1
  12. package/llms/component-library-conventions.md +1 -1
  13. package/llms/components.md +4 -4
  14. package/llms/deprecated-lints.md +1 -7
  15. package/llms/effects.md +1 -1
  16. package/llms/errors.md +2 -2
  17. package/llms/events.md +1 -1
  18. package/llms/guards.md +1 -1
  19. package/llms/head.md +1 -1
  20. package/llms/hooks.md +2 -2
  21. package/llms/images.md +1 -1
  22. package/llms/island-and-form-lints.md +2 -1
  23. package/llms/island-sources.md +1 -1
  24. package/llms/islands-state-to-ids.md +2 -2
  25. package/llms/islands.md +5 -3
  26. package/llms/lints.md +1 -1
  27. package/llms/live-values.md +3 -3
  28. package/llms/local-collections.md +1 -1
  29. package/llms/locales.md +1 -1
  30. package/llms/mcp.md +2 -2
  31. package/llms/metrics.md +1 -1
  32. package/llms/navigation-from-code.md +6 -6
  33. package/llms/prerendering.md +1 -0
  34. package/llms/production.md +2 -2
  35. package/llms/project-new-and-add.md +1 -1
  36. package/llms/project.md +4 -4
  37. package/llms/proxy-and-security.md +1 -1
  38. package/llms/queues.md +1 -1
  39. package/llms/rate-limits.md +4 -4
  40. package/llms/rendering.md +1 -1
  41. package/llms/server-islands.md +2 -2
  42. package/llms/server.md +1 -1
  43. package/llms/stores.md +1 -1
  44. package/llms/styles-and-assets.md +1 -1
  45. package/llms/testing-mount.md +49 -0
  46. package/llms/testing.md +4 -45
  47. package/llms/upgrading-1-105-config.md +13 -13
  48. package/llms/upgrading-archive.md +42 -82
  49. package/llms/upgrading.md +92 -58
  50. package/llms/whats-new-archive.md +36 -1
  51. package/llms/whats-new.md +18 -39
  52. package/llms.txt +6 -7
  53. package/package.json +6 -10
  54. package/src/build/client.ts +7 -6
  55. package/src/build/icon-slots.ts +140 -0
  56. package/src/build/libraries.ts +24 -2
  57. package/src/build/plugin.ts +10 -0
  58. package/src/build/route-sizes.ts +2 -3
  59. package/src/build/runtime-chunk.ts +2 -2
  60. package/src/build/source-files.ts +8 -3
  61. package/src/build/variants.ts +90 -1
  62. package/src/check/browser-global-reads.ts +2 -2
  63. package/src/check/config-objects.ts +1 -1
  64. package/src/check/diagnose.ts +0 -22
  65. package/src/check/export-homes.ts +1 -1
  66. package/src/check/guards.ts +3 -3
  67. package/src/check/index.ts +2 -7
  68. package/src/check/moved-keys.ts +1 -1
  69. package/src/check/project.ts +4 -9
  70. package/src/check/renamed-packages.ts +3 -63
  71. package/src/check/shadow-types.ts +4 -104
  72. package/src/commands/check.ts +2 -2
  73. package/src/commands/env.ts +25 -3
  74. package/src/compiler/ast.ts +18 -16
  75. package/src/compiler/browser.ts +2 -14
  76. package/src/compiler/class-items.ts +16 -0
  77. package/src/compiler/codegen.ts +8 -8
  78. package/src/compiler/dead-code.ts +22 -0
  79. package/src/compiler/deprecated-library.ts +0 -12
  80. package/src/compiler/deprecated-lints.ts +4 -505
  81. package/src/compiler/deprecated-ui-props.ts +5 -5
  82. package/src/compiler/dom-property.ts +23 -0
  83. package/src/compiler/dom.ts +15 -15
  84. package/src/compiler/errors.ts +2 -2
  85. package/src/compiler/fence-checks.ts +2 -121
  86. package/src/compiler/hand-parts.ts +55 -0
  87. package/src/compiler/helper-imports.ts +2 -2
  88. package/src/compiler/image-attributes.ts +1 -3
  89. package/src/compiler/index.ts +20 -21
  90. package/src/compiler/island-arguments.ts +8 -95
  91. package/src/compiler/island-cause.ts +7 -7
  92. package/src/compiler/island-declaration.ts +2 -8
  93. package/src/compiler/island-lints.ts +12 -0
  94. package/src/compiler/island-marker.ts +3 -3
  95. package/src/compiler/island-problems.ts +25 -0
  96. package/src/compiler/jsx-class.ts +1 -25
  97. package/src/compiler/jsx.ts +2 -2
  98. package/src/compiler/kay-exports.ts +0 -2
  99. package/src/compiler/link-flags.ts +9 -38
  100. package/src/compiler/lints.ts +7 -14
  101. package/src/compiler/markup.ts +23 -26
  102. package/src/compiler/module-signals.ts +2 -2
  103. package/src/compiler/names.ts +1 -1
  104. package/src/compiler/page-settings.ts +11 -0
  105. package/src/compiler/parser.ts +6 -8
  106. package/src/compiler/plan.ts +1 -3
  107. package/src/compiler/rewrite.ts +3 -18
  108. package/src/compiler/script-server.ts +8 -3
  109. package/src/compiler/validate.ts +3 -8
  110. package/src/config-loader.ts +14 -4
  111. package/src/config-resolve.ts +18 -142
  112. package/src/config-shape.ts +44 -34
  113. package/src/config.ts +10 -114
  114. package/src/dev/preload.ts +4 -1
  115. package/src/lsp/server.ts +4 -0
  116. package/src/migrate/markup.ts +4 -1
  117. package/src/package-names.ts +1 -1
  118. package/src/runtime/action-call.ts +39 -335
  119. package/src/runtime/action-encode.ts +26 -0
  120. package/src/runtime/action-error.ts +3 -11
  121. package/src/runtime/action-protection.ts +2 -2
  122. package/src/runtime/action-run.ts +332 -0
  123. package/src/runtime/action-shared.ts +14 -37
  124. package/src/runtime/action-stream.ts +0 -1
  125. package/src/runtime/action.ts +1 -1
  126. package/src/runtime/call-result.ts +2 -10
  127. package/src/runtime/checks.ts +11 -11
  128. package/src/runtime/client.ts +2 -2
  129. package/src/runtime/core.ts +5 -23
  130. package/src/runtime/dom.ts +1 -1
  131. package/src/runtime/html.ts +1 -1
  132. package/src/runtime/i18n.client.ts +1 -4
  133. package/src/runtime/i18n.server.ts +1 -4
  134. package/src/runtime/i18n.ts +3 -3
  135. package/src/runtime/index.ts +2 -2
  136. package/src/runtime/island.server.ts +18 -5
  137. package/src/runtime/live-resource.server.ts +0 -1
  138. package/src/runtime/live-value.server.ts +2 -2
  139. package/src/runtime/live-value.shared.ts +7 -20
  140. package/src/runtime/live.ts +1 -12
  141. package/src/runtime/local-types.ts +1 -11
  142. package/src/runtime/local.ts +4 -14
  143. package/src/runtime/navigate-api.ts +2 -5
  144. package/src/runtime/navigation-state.ts +0 -12
  145. package/src/runtime/page-swap.ts +6 -6
  146. package/src/runtime/persist.ts +11 -3
  147. package/src/runtime/persisted.ts +4 -30
  148. package/src/runtime/presence.ts +6 -7
  149. package/src/runtime/query-param.ts +20 -12
  150. package/src/runtime/reactive.ts +3 -1
  151. package/src/runtime/refuse.ts +3 -17
  152. package/src/runtime/store-base.ts +4 -6
  153. package/src/runtime/swap-fetch.ts +1 -1
  154. package/src/runtime/values.ts +40 -23
  155. package/src/runtime/with-query.ts +9 -0
  156. package/src/server/action-hooks.ts +8 -8
  157. package/src/server/actions.ts +13 -14
  158. package/src/server/api-modules.ts +2 -3
  159. package/src/server/app-stages.ts +15 -33
  160. package/src/server/app.ts +10 -5
  161. package/src/server/auth-mails.ts +0 -2
  162. package/src/server/env-state.ts +40 -10
  163. package/src/server/flash.ts +1 -1
  164. package/src/server/guard-requirement.ts +4 -4
  165. package/src/server/image.ts +2 -2
  166. package/src/server/index.ts +0 -2
  167. package/src/server/job-context.ts +3 -3
  168. package/src/server/jobs-page.ts +1 -1
  169. package/src/server/jobs.ts +5 -9
  170. package/src/server/kept-exports.ts +0 -2
  171. package/src/server/kv.ts +11 -14
  172. package/src/server/library.ts +1 -3
  173. package/src/server/live.ts +2 -2
  174. package/src/server/mcp.ts +3 -9
  175. package/src/server/metrics.ts +2 -4
  176. package/src/server/page-settings.ts +10 -19
  177. package/src/server/prerender.ts +19 -2
  178. package/src/server/protection.ts +15 -18
  179. package/src/server/queue.ts +3 -6
  180. package/src/server/rate-limit.ts +0 -3
  181. package/src/server/render-document.ts +1 -1
  182. package/src/server/routes.ts +7 -3
  183. package/src/server/scope.ts +3 -2
  184. package/src/server/session.ts +5 -6
  185. package/src/server/setup.ts +1 -1
  186. package/src/server/signals.ts +17 -7
  187. package/src/server/signed.ts +1 -3
  188. package/src/server/source.ts +20 -4
  189. package/src/server/speculation.ts +1 -1
  190. package/src/server/storage.ts +3 -8
  191. package/src/server/validate.ts +1 -1
  192. package/src/server/vitals.ts +1 -3
  193. package/src/server/work-scope.ts +2 -4
  194. package/src/server/work.ts +1 -1
  195. package/src/server/workflow.ts +1 -1
  196. package/src/test/index.ts +2 -1
  197. package/src/test/site-actions.ts +16 -6
  198. package/src/test/site-keys.ts +10 -15
  199. package/src/test/site-socket.ts +1 -2
  200. package/src/test/site-types.ts +0 -8
  201. package/types/build/client.d.ts +1 -1
  202. package/types/build/client.d.ts.map +1 -1
  203. package/types/build/icon-slots.d.ts +7 -0
  204. package/types/build/icon-slots.d.ts.map +1 -0
  205. package/types/build/libraries.d.ts +2 -0
  206. package/types/build/libraries.d.ts.map +1 -1
  207. package/types/build/plugin.d.ts +1 -0
  208. package/types/build/plugin.d.ts.map +1 -1
  209. package/types/build/route-sizes.d.ts.map +1 -1
  210. package/types/build/source-files.d.ts.map +1 -1
  211. package/types/build/variants.d.ts.map +1 -1
  212. package/types/check/diagnose.d.ts.map +1 -1
  213. package/types/check/index.d.ts +1 -2
  214. package/types/check/index.d.ts.map +1 -1
  215. package/types/check/project.d.ts.map +1 -1
  216. package/types/check/renamed-packages.d.ts +0 -3
  217. package/types/check/renamed-packages.d.ts.map +1 -1
  218. package/types/check/shadow-types.d.ts.map +1 -1
  219. package/types/commands/env.d.ts.map +1 -1
  220. package/types/compiler/ast.d.ts +1 -2
  221. package/types/compiler/ast.d.ts.map +1 -1
  222. package/types/compiler/browser.d.ts.map +1 -1
  223. package/types/compiler/class-items.d.ts +7 -0
  224. package/types/compiler/class-items.d.ts.map +1 -0
  225. package/types/compiler/dead-code.d.ts +9 -0
  226. package/types/compiler/dead-code.d.ts.map +1 -0
  227. package/types/compiler/deprecated-library.d.ts.map +1 -1
  228. package/types/compiler/deprecated-lints.d.ts +0 -560
  229. package/types/compiler/deprecated-lints.d.ts.map +1 -1
  230. package/types/compiler/deprecated-ui-props.d.ts +1 -8
  231. package/types/compiler/deprecated-ui-props.d.ts.map +1 -1
  232. package/types/compiler/dom-property.d.ts +9 -0
  233. package/types/compiler/dom-property.d.ts.map +1 -0
  234. package/types/compiler/dom.d.ts +1 -0
  235. package/types/compiler/dom.d.ts.map +1 -1
  236. package/types/compiler/errors.d.ts +2 -2
  237. package/types/compiler/errors.d.ts.map +1 -1
  238. package/types/compiler/fence-checks.d.ts +0 -1
  239. package/types/compiler/fence-checks.d.ts.map +1 -1
  240. package/types/compiler/hand-parts.d.ts +7 -0
  241. package/types/compiler/hand-parts.d.ts.map +1 -0
  242. package/types/compiler/image-attributes.d.ts +0 -1
  243. package/types/compiler/image-attributes.d.ts.map +1 -1
  244. package/types/compiler/index.d.ts.map +1 -1
  245. package/types/compiler/island-arguments.d.ts +2 -11
  246. package/types/compiler/island-arguments.d.ts.map +1 -1
  247. package/types/compiler/island-cause.d.ts +1 -1
  248. package/types/compiler/island-cause.d.ts.map +1 -1
  249. package/types/compiler/island-declaration.d.ts +1 -3
  250. package/types/compiler/island-declaration.d.ts.map +1 -1
  251. package/types/compiler/island-lints.d.ts +10 -0
  252. package/types/compiler/island-lints.d.ts.map +1 -0
  253. package/types/compiler/island-problems.d.ts +7 -0
  254. package/types/compiler/island-problems.d.ts.map +1 -0
  255. package/types/compiler/jsx-class.d.ts +1 -2
  256. package/types/compiler/jsx-class.d.ts.map +1 -1
  257. package/types/compiler/kay-exports.d.ts.map +1 -1
  258. package/types/compiler/link-flags.d.ts +0 -6
  259. package/types/compiler/link-flags.d.ts.map +1 -1
  260. package/types/compiler/lints.d.ts +11 -572
  261. package/types/compiler/lints.d.ts.map +1 -1
  262. package/types/compiler/markup.d.ts +1 -1
  263. package/types/compiler/markup.d.ts.map +1 -1
  264. package/types/compiler/module-signals.d.ts.map +1 -1
  265. package/types/compiler/names.d.ts.map +1 -1
  266. package/types/compiler/page-settings.d.ts +4 -0
  267. package/types/compiler/page-settings.d.ts.map +1 -1
  268. package/types/compiler/parser.d.ts.map +1 -1
  269. package/types/compiler/plan.d.ts.map +1 -1
  270. package/types/compiler/script-server.d.ts.map +1 -1
  271. package/types/compiler/validate.d.ts.map +1 -1
  272. package/types/config-loader.d.ts.map +1 -1
  273. package/types/config-resolve.d.ts.map +1 -1
  274. package/types/config-shape.d.ts +1 -1
  275. package/types/config-shape.d.ts.map +1 -1
  276. package/types/config.d.ts +5 -105
  277. package/types/config.d.ts.map +1 -1
  278. package/types/dev/preload.d.ts.map +1 -1
  279. package/types/lsp/server.d.ts.map +1 -1
  280. package/types/migrate/markup.d.ts.map +1 -1
  281. package/types/runtime/action-call.d.ts.map +1 -1
  282. package/types/runtime/action-encode.d.ts +1 -0
  283. package/types/runtime/action-encode.d.ts.map +1 -1
  284. package/types/runtime/action-error.d.ts +1 -2
  285. package/types/runtime/action-error.d.ts.map +1 -1
  286. package/types/runtime/action-run.d.ts +23 -0
  287. package/types/runtime/action-run.d.ts.map +1 -0
  288. package/types/runtime/action-shared.d.ts +1 -27
  289. package/types/runtime/action-shared.d.ts.map +1 -1
  290. package/types/runtime/action-stream.d.ts.map +1 -1
  291. package/types/runtime/action.d.ts +1 -1
  292. package/types/runtime/action.d.ts.map +1 -1
  293. package/types/runtime/call-result.d.ts +0 -10
  294. package/types/runtime/call-result.d.ts.map +1 -1
  295. package/types/runtime/checks.d.ts +6 -9
  296. package/types/runtime/checks.d.ts.map +1 -1
  297. package/types/runtime/core.d.ts +2 -20
  298. package/types/runtime/core.d.ts.map +1 -1
  299. package/types/runtime/dom.d.ts +1 -1
  300. package/types/runtime/dom.d.ts.map +1 -1
  301. package/types/runtime/html.d.ts +1 -1
  302. package/types/runtime/html.d.ts.map +1 -1
  303. package/types/runtime/i18n.client.d.ts +0 -1
  304. package/types/runtime/i18n.client.d.ts.map +1 -1
  305. package/types/runtime/i18n.d.ts +1 -1
  306. package/types/runtime/i18n.d.ts.map +1 -1
  307. package/types/runtime/i18n.server.d.ts +0 -1
  308. package/types/runtime/i18n.server.d.ts.map +1 -1
  309. package/types/runtime/index.d.ts +2 -2
  310. package/types/runtime/index.d.ts.map +1 -1
  311. package/types/runtime/island.server.d.ts +1 -0
  312. package/types/runtime/island.server.d.ts.map +1 -1
  313. package/types/runtime/live-resource.server.d.ts.map +1 -1
  314. package/types/runtime/live-value.shared.d.ts +7 -15
  315. package/types/runtime/live-value.shared.d.ts.map +1 -1
  316. package/types/runtime/live.d.ts +0 -11
  317. package/types/runtime/live.d.ts.map +1 -1
  318. package/types/runtime/local-types.d.ts +0 -14
  319. package/types/runtime/local-types.d.ts.map +1 -1
  320. package/types/runtime/navigate-api.d.ts +0 -4
  321. package/types/runtime/navigate-api.d.ts.map +1 -1
  322. package/types/runtime/navigation-state.d.ts +0 -4
  323. package/types/runtime/navigation-state.d.ts.map +1 -1
  324. package/types/runtime/page-swap.d.ts.map +1 -1
  325. package/types/runtime/persist.d.ts +1 -0
  326. package/types/runtime/persist.d.ts.map +1 -1
  327. package/types/runtime/persisted.d.ts +0 -15
  328. package/types/runtime/persisted.d.ts.map +1 -1
  329. package/types/runtime/presence.d.ts +0 -2
  330. package/types/runtime/presence.d.ts.map +1 -1
  331. package/types/runtime/query-param.d.ts.map +1 -1
  332. package/types/runtime/reactive.d.ts +2 -1
  333. package/types/runtime/reactive.d.ts.map +1 -1
  334. package/types/runtime/refuse.d.ts +0 -7
  335. package/types/runtime/refuse.d.ts.map +1 -1
  336. package/types/runtime/store-base.d.ts +1 -2
  337. package/types/runtime/store-base.d.ts.map +1 -1
  338. package/types/runtime/values.d.ts +2 -1
  339. package/types/runtime/values.d.ts.map +1 -1
  340. package/types/runtime/with-query.d.ts +2 -0
  341. package/types/runtime/with-query.d.ts.map +1 -1
  342. package/types/server/action-hooks.d.ts +4 -4
  343. package/types/server/action-hooks.d.ts.map +1 -1
  344. package/types/server/actions.d.ts.map +1 -1
  345. package/types/server/api-modules.d.ts +0 -1
  346. package/types/server/api-modules.d.ts.map +1 -1
  347. package/types/server/app-stages.d.ts +5 -13
  348. package/types/server/app-stages.d.ts.map +1 -1
  349. package/types/server/app.d.ts +3 -8
  350. package/types/server/app.d.ts.map +1 -1
  351. package/types/server/auth-mails.d.ts +0 -5
  352. package/types/server/auth-mails.d.ts.map +1 -1
  353. package/types/server/env-state.d.ts +1 -0
  354. package/types/server/env-state.d.ts.map +1 -1
  355. package/types/server/guard-requirement.d.ts +0 -1
  356. package/types/server/guard-requirement.d.ts.map +1 -1
  357. package/types/server/image.d.ts +0 -1
  358. package/types/server/image.d.ts.map +1 -1
  359. package/types/server/index.d.ts +0 -2
  360. package/types/server/index.d.ts.map +1 -1
  361. package/types/server/job-context.d.ts +1 -1
  362. package/types/server/job-context.d.ts.map +1 -1
  363. package/types/server/jobs.d.ts +0 -4
  364. package/types/server/jobs.d.ts.map +1 -1
  365. package/types/server/kept-exports.d.ts.map +1 -1
  366. package/types/server/kv.d.ts +4 -4
  367. package/types/server/kv.d.ts.map +1 -1
  368. package/types/server/library.d.ts +1 -3
  369. package/types/server/library.d.ts.map +1 -1
  370. package/types/server/mcp.d.ts +0 -1
  371. package/types/server/mcp.d.ts.map +1 -1
  372. package/types/server/metrics.d.ts +0 -5
  373. package/types/server/metrics.d.ts.map +1 -1
  374. package/types/server/page-settings.d.ts +3 -3
  375. package/types/server/page-settings.d.ts.map +1 -1
  376. package/types/server/prerender.d.ts.map +1 -1
  377. package/types/server/protection.d.ts +6 -6
  378. package/types/server/protection.d.ts.map +1 -1
  379. package/types/server/queue.d.ts +1 -3
  380. package/types/server/queue.d.ts.map +1 -1
  381. package/types/server/rate-limit.d.ts +0 -2
  382. package/types/server/rate-limit.d.ts.map +1 -1
  383. package/types/server/routes.d.ts +1 -1
  384. package/types/server/routes.d.ts.map +1 -1
  385. package/types/server/scope.d.ts.map +1 -1
  386. package/types/server/session.d.ts +1 -1
  387. package/types/server/session.d.ts.map +1 -1
  388. package/types/server/signals.d.ts.map +1 -1
  389. package/types/server/signed.d.ts +0 -2
  390. package/types/server/signed.d.ts.map +1 -1
  391. package/types/server/source.d.ts +1 -1
  392. package/types/server/source.d.ts.map +1 -1
  393. package/types/server/storage.d.ts +0 -4
  394. package/types/server/storage.d.ts.map +1 -1
  395. package/types/server/vitals.d.ts +0 -1
  396. package/types/server/vitals.d.ts.map +1 -1
  397. package/types/server/work-scope.d.ts +0 -2
  398. package/types/server/work-scope.d.ts.map +1 -1
  399. package/types/server/workflow.d.ts +1 -1
  400. package/types/server/workflow.d.ts.map +1 -1
  401. package/types/test/index.d.ts.map +1 -1
  402. package/types/test/site-actions.d.ts +1 -1
  403. package/types/test/site-actions.d.ts.map +1 -1
  404. package/types/test/site-keys.d.ts +1 -1
  405. package/types/test/site-keys.d.ts.map +1 -1
  406. package/types/test/site-socket.d.ts +1 -1
  407. package/types/test/site-socket.d.ts.map +1 -1
  408. package/types/test/site-types.d.ts +0 -8
  409. package/types/test/site-types.d.ts.map +1 -1
  410. package/llms/deprecated-lints-1-105-libraries.md +0 -32
  411. package/llms/deprecated-lints-1-105.md +0 -58
  412. package/src/check/action-readers.ts +0 -115
  413. package/src/check/action-type.ts +0 -44
  414. package/src/check/ai-language.ts +0 -56
  415. package/src/check/app-hooks.ts +0 -90
  416. package/src/check/auth-methods.ts +0 -85
  417. package/src/check/auth-rate-limits.ts +0 -99
  418. package/src/check/call-result.ts +0 -242
  419. package/src/check/client-keys.ts +0 -10
  420. package/src/check/cms-options.ts +0 -81
  421. package/src/check/config-groups.ts +0 -22
  422. package/src/check/config-switches.ts +0 -38
  423. package/src/check/context-import.ts +0 -51
  424. package/src/check/env-files.ts +0 -31
  425. package/src/check/format-duration.ts +0 -75
  426. package/src/check/guard-options.ts +0 -58
  427. package/src/check/handler-events.ts +0 -149
  428. package/src/check/hook-context.ts +0 -94
  429. package/src/check/hook-names.ts +0 -104
  430. package/src/check/i18n-keys.ts +0 -50
  431. package/src/check/images-keys.ts +0 -54
  432. package/src/check/job-shapes.ts +0 -273
  433. package/src/check/link-flag-tests.ts +0 -130
  434. package/src/check/live-api.ts +0 -137
  435. package/src/check/mail-api.ts +0 -67
  436. package/src/check/one-state-api.ts +0 -357
  437. package/src/check/pages-options.ts +0 -35
  438. package/src/check/rate-enforce.ts +0 -53
  439. package/src/check/refusal-calls.ts +0 -185
  440. package/src/check/retired-lints.ts +0 -49
  441. package/src/check/route-keys.ts +0 -166
  442. package/src/check/secret-keys.ts +0 -83
  443. package/src/check/socket-frames.ts +0 -102
  444. package/src/check/source-readers.ts +0 -257
  445. package/src/check/store-ms.ts +0 -72
  446. package/src/check/store-names.ts +0 -88
  447. package/src/check/test-helpers.ts +0 -98
  448. package/src/check/ttl-names.ts +0 -142
  449. package/src/compiler/deprecated-ai-labels.ts +0 -97
  450. package/src/compiler/deprecated-ai-links.ts +0 -63
  451. package/src/compiler/deprecated-allow.ts +0 -50
  452. package/src/compiler/deprecated-auth-lints.ts +0 -14
  453. package/src/compiler/deprecated-auth-signed.ts +0 -29
  454. package/src/compiler/deprecated-children.ts +0 -66
  455. package/src/compiler/deprecated-image.ts +0 -116
  456. package/src/compiler/deprecated-island.ts +0 -155
  457. package/src/compiler/deprecated-lints-1-105.ts +0 -41
  458. package/src/compiler/deprecated-page.ts +0 -125
  459. package/src/compiler/deprecated-parts.ts +0 -22
  460. package/src/compiler/deprecated-typed-lints.ts +0 -23
  461. package/src/compiler/deprecated-ui-callbacks.ts +0 -66
  462. package/src/compiler/deprecated-ui-input.ts +0 -97
  463. package/src/compiler/deprecated-ui-items.ts +0 -47
  464. package/src/compiler/old-parts.ts +0 -84
  465. package/src/runtime/mount.compat.ts +0 -8
  466. package/src/server/moved-exports.ts +0 -17
  467. package/types/check/action-readers.d.ts +0 -3
  468. package/types/check/action-readers.d.ts.map +0 -1
  469. package/types/check/action-type.d.ts +0 -3
  470. package/types/check/action-type.d.ts.map +0 -1
  471. package/types/check/ai-language.d.ts +0 -3
  472. package/types/check/ai-language.d.ts.map +0 -1
  473. package/types/check/app-hooks.d.ts +0 -3
  474. package/types/check/app-hooks.d.ts.map +0 -1
  475. package/types/check/auth-methods.d.ts +0 -3
  476. package/types/check/auth-methods.d.ts.map +0 -1
  477. package/types/check/auth-rate-limits.d.ts +0 -3
  478. package/types/check/auth-rate-limits.d.ts.map +0 -1
  479. package/types/check/call-result.d.ts +0 -7
  480. package/types/check/call-result.d.ts.map +0 -1
  481. package/types/check/client-keys.d.ts +0 -3
  482. package/types/check/client-keys.d.ts.map +0 -1
  483. package/types/check/cms-options.d.ts +0 -3
  484. package/types/check/cms-options.d.ts.map +0 -1
  485. package/types/check/config-groups.d.ts +0 -3
  486. package/types/check/config-groups.d.ts.map +0 -1
  487. package/types/check/config-switches.d.ts +0 -3
  488. package/types/check/config-switches.d.ts.map +0 -1
  489. package/types/check/context-import.d.ts +0 -3
  490. package/types/check/context-import.d.ts.map +0 -1
  491. package/types/check/env-files.d.ts +0 -3
  492. package/types/check/env-files.d.ts.map +0 -1
  493. package/types/check/format-duration.d.ts +0 -5
  494. package/types/check/format-duration.d.ts.map +0 -1
  495. package/types/check/guard-options.d.ts +0 -3
  496. package/types/check/guard-options.d.ts.map +0 -1
  497. package/types/check/handler-events.d.ts +0 -9
  498. package/types/check/handler-events.d.ts.map +0 -1
  499. package/types/check/hook-context.d.ts +0 -3
  500. package/types/check/hook-context.d.ts.map +0 -1
  501. package/types/check/hook-names.d.ts +0 -3
  502. package/types/check/hook-names.d.ts.map +0 -1
  503. package/types/check/i18n-keys.d.ts +0 -3
  504. package/types/check/i18n-keys.d.ts.map +0 -1
  505. package/types/check/images-keys.d.ts +0 -3
  506. package/types/check/images-keys.d.ts.map +0 -1
  507. package/types/check/job-shapes.d.ts +0 -6
  508. package/types/check/job-shapes.d.ts.map +0 -1
  509. package/types/check/link-flag-tests.d.ts +0 -4
  510. package/types/check/link-flag-tests.d.ts.map +0 -1
  511. package/types/check/live-api.d.ts +0 -3
  512. package/types/check/live-api.d.ts.map +0 -1
  513. package/types/check/mail-api.d.ts +0 -3
  514. package/types/check/mail-api.d.ts.map +0 -1
  515. package/types/check/one-state-api.d.ts +0 -9
  516. package/types/check/one-state-api.d.ts.map +0 -1
  517. package/types/check/pages-options.d.ts +0 -3
  518. package/types/check/pages-options.d.ts.map +0 -1
  519. package/types/check/rate-enforce.d.ts +0 -3
  520. package/types/check/rate-enforce.d.ts.map +0 -1
  521. package/types/check/refusal-calls.d.ts +0 -3
  522. package/types/check/refusal-calls.d.ts.map +0 -1
  523. package/types/check/retired-lints.d.ts +0 -3
  524. package/types/check/retired-lints.d.ts.map +0 -1
  525. package/types/check/route-keys.d.ts +0 -3
  526. package/types/check/route-keys.d.ts.map +0 -1
  527. package/types/check/secret-keys.d.ts +0 -3
  528. package/types/check/secret-keys.d.ts.map +0 -1
  529. package/types/check/socket-frames.d.ts +0 -3
  530. package/types/check/socket-frames.d.ts.map +0 -1
  531. package/types/check/source-readers.d.ts +0 -3
  532. package/types/check/source-readers.d.ts.map +0 -1
  533. package/types/check/store-ms.d.ts +0 -3
  534. package/types/check/store-ms.d.ts.map +0 -1
  535. package/types/check/store-names.d.ts +0 -3
  536. package/types/check/store-names.d.ts.map +0 -1
  537. package/types/check/test-helpers.d.ts +0 -3
  538. package/types/check/test-helpers.d.ts.map +0 -1
  539. package/types/check/ttl-names.d.ts +0 -3
  540. package/types/check/ttl-names.d.ts.map +0 -1
  541. package/types/compiler/deprecated-ai-labels.d.ts +0 -5
  542. package/types/compiler/deprecated-ai-labels.d.ts.map +0 -1
  543. package/types/compiler/deprecated-ai-links.d.ts +0 -5
  544. package/types/compiler/deprecated-ai-links.d.ts.map +0 -1
  545. package/types/compiler/deprecated-allow.d.ts +0 -5
  546. package/types/compiler/deprecated-allow.d.ts.map +0 -1
  547. package/types/compiler/deprecated-auth-lints.d.ts +0 -12
  548. package/types/compiler/deprecated-auth-lints.d.ts.map +0 -1
  549. package/types/compiler/deprecated-auth-signed.d.ts +0 -5
  550. package/types/compiler/deprecated-auth-signed.d.ts.map +0 -1
  551. package/types/compiler/deprecated-children.d.ts +0 -4
  552. package/types/compiler/deprecated-children.d.ts.map +0 -1
  553. package/types/compiler/deprecated-image.d.ts +0 -5
  554. package/types/compiler/deprecated-image.d.ts.map +0 -1
  555. package/types/compiler/deprecated-island.d.ts +0 -9
  556. package/types/compiler/deprecated-island.d.ts.map +0 -1
  557. package/types/compiler/deprecated-lints-1-105.d.ts +0 -39
  558. package/types/compiler/deprecated-lints-1-105.d.ts.map +0 -1
  559. package/types/compiler/deprecated-page.d.ts +0 -4
  560. package/types/compiler/deprecated-page.d.ts.map +0 -1
  561. package/types/compiler/deprecated-parts.d.ts +0 -3
  562. package/types/compiler/deprecated-parts.d.ts.map +0 -1
  563. package/types/compiler/deprecated-typed-lints.d.ts +0 -21
  564. package/types/compiler/deprecated-typed-lints.d.ts.map +0 -1
  565. package/types/compiler/deprecated-ui-callbacks.d.ts +0 -5
  566. package/types/compiler/deprecated-ui-callbacks.d.ts.map +0 -1
  567. package/types/compiler/deprecated-ui-input.d.ts +0 -5
  568. package/types/compiler/deprecated-ui-input.d.ts.map +0 -1
  569. package/types/compiler/deprecated-ui-items.d.ts +0 -5
  570. package/types/compiler/deprecated-ui-items.d.ts.map +0 -1
  571. package/types/compiler/old-parts.d.ts +0 -9
  572. package/types/compiler/old-parts.d.ts.map +0 -1
  573. package/types/runtime/mount.compat.d.ts +0 -7
  574. package/types/runtime/mount.compat.d.ts.map +0 -1
  575. package/types/server/moved-exports.d.ts +0 -12
  576. package/types/server/moved-exports.d.ts.map +0 -1
@@ -1,24 +1,20 @@
1
- import type { Caller } from './action-owner'
1
+ import type { Lane, Start } from './action-run'
2
2
  import type { Action, ActionErrorDetail, ActionStartDetail, ActionStream, ActionSuccessDetail, CallOptions, CallQueue, Outcome, TrackedCall } from './action-shared'
3
3
  import type { ApiError } from './api-error'
4
4
  import type { CallPromise, CallResult, TrackHooks } from './call-result'
5
- import type { Duration } from './duration'
6
- import type { ConnectionStatus, LoadStatus } from './live'
5
+ import type { LoadStatus } from './live'
7
6
  import { ActionError, ActionRedirectError } from './action-error'
8
7
  import { PAYLOAD_PARAM, payloadQuery, withFields } from './action-form'
9
8
  import { networkFailures, refusedAt, superseding } from './action-marks'
10
- import { refreshed, refreshedIn, refreshedUnlessFollowed } from './action-navigate'
11
- import { onStreamEnd, SETTLED } from './action-owner'
9
+ import { onStreamEnd } from './action-owner'
12
10
  import { ACTION } from './action-shared'
13
- import { actionFailed, apiErrorOf, failed, messageOf, unreachable } from './api-error'
11
+ import { actionFailed, failed, messageOf, unreachable } from './api-error'
14
12
  import { withoutBase } from './base'
15
13
  import { skew } from './build'
16
14
  import { settling, signalAborted, trackCalls, whenIdle } from './call-result'
17
- import { durationSeconds, isZeroDuration } from './duration'
18
15
  import { navigation } from './navigation'
19
16
  import { released, undoable } from './optimistic'
20
17
  import { pageData } from './page-data'
21
- import { randomId } from './random-id'
22
18
  import { getOwner, liveOwner, onCleanup, ownSignal, untrack } from './reactive'
23
19
  import { OUTCOME_SCRIPT } from './swap'
24
20
  import { ACTION_PREFIX, ACTION_TYPE, decodeServerValue, FIXED_FIELDS, malformed, serverWritten } from './wire'
@@ -30,122 +26,14 @@ export { OUTCOME_SCRIPT }
30
26
 
31
27
  const QUERY = /\?.*/
32
28
 
33
- // A property of the handle an action builds, readable and listed.
34
- const read = (value: unknown) => ({ value, enumerable: true })
35
-
36
- const RETRY_DELAY_MS = 500
37
29
  const CODE_RETRIES = 2
38
- // Once loaded, a call is posted in the same task, as one made from `pagehide` must be: a dynamic import resolves a task later, when the page may be gone.
39
- let posting: typeof import('./action-post') | undefined
40
-
41
- function idempotencyKey(): string {
42
- return randomId()
43
- }
44
-
45
- // The calls of an action, or of one `track()` handle, that `queue` orders: `tail` settles when the last `serial` call is done, `latest` is the call in flight a newer one aborts.
46
- interface Lane {
47
- tail: Promise<unknown>
48
- queue?: CallQueue | undefined
49
- latest?: AbortController | undefined
50
- }
51
-
52
- // One signal for several, aborting with the reason of the first to abort. A lone one is returned as it is, so a browser that has no `AbortSignal.any` still runs the call; `stop` lets go of the listeners, and `always` makes a signal of its own whose sources can be let go of before the call ends.
53
- function join(sources: (AbortSignal | undefined)[], always = false): { signal: AbortSignal | undefined, stop: (only?: AbortSignal) => void } {
54
- const list = sources.filter(source => source !== undefined)
55
-
56
- if (list.length < 2 && !always)
57
- return { signal: list[0], stop: () => undefined }
58
-
59
- const controller = new AbortController()
60
- const forwards = list.map(source => [source, () => controller.abort(source.reason)] as const)
61
-
62
- for (const [source, forward] of forwards) {
63
- if (source.aborted) {
64
- controller.abort(source.reason)
65
-
66
- break
67
- }
68
-
69
- source.addEventListener('abort', forward, { once: true })
70
- }
71
-
72
- return {
73
- signal: controller.signal,
74
- stop: (only) => {
75
- for (const [source, forward] of forwards) {
76
- if (only === undefined || only === source)
77
- source.removeEventListener('abort', forward)
78
- }
79
- },
80
- }
81
- }
30
+ // Once loaded, a call is made in the same task, as one made from `pagehide` must be: a dynamic import resolves a task later, when the page may be gone.
31
+ let running: typeof import('./action-run') | undefined
32
+ // The load the calls made before it ends share, so they go on in the order they were made.
33
+ let loading: Promise<typeof import('./action-run')> | undefined
82
34
 
83
- // Waits for `ms`, or for the calls ahead when given a promise, giving up at once when the signal aborts meanwhile.
84
- async function waitFor(wait: number | Promise<unknown>, signal: AbortSignal | undefined): Promise<void> {
85
- signal?.throwIfAborted()
86
-
87
- let stop = () => undefined as void
88
-
89
- try {
90
- await new Promise<unknown>((resolve, reject) => {
91
- const abort = () => reject(signal!.reason)
92
- const id = typeof wait === 'number' ? setTimeout(resolve, wait) : undefined
93
-
94
- if (typeof wait !== 'number') {
95
- void (async () => {
96
- try {
97
- resolve(await wait)
98
- }
99
- catch (error) {
100
- reject(error)
101
- }
102
- })()
103
- }
104
-
105
- signal?.addEventListener('abort', abort, { once: true })
106
- stop = () => {
107
- clearTimeout(id)
108
- signal?.removeEventListener('abort', abort)
109
- }
110
- })
111
- }
112
- finally {
113
- stop()
114
- }
115
- }
116
-
117
- // How long a wait of the call's lasts: nothing for a zero, a clear error for text that is no duration.
118
- function waitOf(value: Duration | undefined, what: string): number | undefined {
119
- return value === undefined || isZeroDuration(value) ? undefined : durationSeconds(value, what) * 1000
120
- }
121
-
122
- // Whether a failure is one a retry may repeat: the server's answer or the network's failure, never a redirect, an abort or something thrown before the post was sent. Unless `when` says otherwise, a 503 (the server turned the call away) and a failure before the post was sent are, and nothing else, as a post that reached the server may have run.
123
- function retryOf(retry: CallOptions['retry']): { times: number, delay: number, again: (error: unknown, sent: boolean) => boolean } {
124
- const options = typeof retry === 'number' ? { times: retry } : retry
125
-
126
- return {
127
- times: options?.times ?? 0,
128
- delay: waitOf(options?.delay, 'retry.delay') ?? RETRY_DELAY_MS,
129
- again: (error, sent) => {
130
- if (error instanceof ActionRedirectError || !(error instanceof ActionError || networkFailures.has(error as object) || (error as { name?: unknown } | null)?.name === 'TimeoutError'))
131
- return false
132
-
133
- const failure = apiErrorOf(error)
134
-
135
- return options?.when ? options.when(failure) : failure.status === 503 || (!sent && (failure.status === 0 || failure.status === 502))
136
- },
137
- }
138
- }
139
-
140
- // A hook never fails the call it observes: a throw, or a rejection, is logged.
141
- async function hooked<Event>(hook: ((event: Event) => unknown) | undefined, event: Event): Promise<void> {
142
- try {
143
- await hook?.(event)
144
- }
145
- catch (error) {
146
- console.error(error)
147
- }
148
- }
35
+ // A property of the handle an action builds, readable and listed.
36
+ const read = (value: unknown) => ({ value, enumerable: true })
149
37
 
150
38
  // On the server, the form post the request being answered carries: null for none, undefined outside a request.
151
39
  let requestOutcome: (() => Outcome | null | undefined) | undefined
@@ -191,10 +79,6 @@ export function reviveActions(): void {
191
79
  }
192
80
  }
193
81
 
194
- function succeededOf(found: Outcome | undefined): { data: unknown } | undefined {
195
- return found?.succeeded ? { data: found.data } : undefined
196
- }
197
-
198
82
  function statusOf(inFlight: number, found: Outcome | undefined, failed: object | undefined): LoadStatus {
199
83
  if (inFlight > 0)
200
84
  return 'loading'
@@ -221,32 +105,6 @@ function lazySignal<T>(value: T): [read: () => T, write: (next: T) => void, peek
221
105
  }, () => current]
222
106
  }
223
107
 
224
- // A call of an action `with()` fixed fields of is made with them, over the ones it is given, as a form posting to its URL does: a field fixed to `null` or `undefined` is left out there, so the given one stays.
225
- function withFixed(input: unknown, fixed: Record<string, unknown> | undefined): unknown {
226
- if (fixed === undefined)
227
- return input
228
-
229
- const set = Object.entries(fixed).filter(([name, value]) => name !== '__proto__' && value !== undefined && value !== null)
230
-
231
- if (!(input instanceof FormData))
232
- return { ...input as object | undefined, ...Object.fromEntries(set) }
233
-
234
- const names = new Set(set.map(([name]) => name))
235
- const copy = new FormData()
236
-
237
- for (const [name, value] of input) {
238
- if (!names.has(name))
239
- copy.append(name, value)
240
- }
241
-
242
- for (const [name, value] of set) {
243
- for (const item of Array.isArray(value) ? value : [value])
244
- copy.append(name, item instanceof Date ? item.toISOString() : String(item))
245
- }
246
-
247
- return copy
248
- }
249
-
250
108
  // Checks a form against the action's schema in the browser, as the server would, and hands `show` the messages to read as a refusal's, undefined for none; one field checked replaces that field's message and leaves the others.
251
109
  function validator(url: () => string, failed: () => { errors: Record<string, string> } | undefined, show: (errors: Record<string, string> | undefined) => unknown): (form: HTMLFormElement, field?: string) => Promise<boolean> {
252
110
  return async (form, field) => {
@@ -264,7 +122,7 @@ function validator(url: () => string, failed: () => { errors: Record<string, str
264
122
  }
265
123
  }
266
124
 
267
- // Posts a call, counting the ones in flight; a call that redirects rejects with `ActionRedirectError` once the browser is on its way, so the action stops being pending.
125
+ // Makes the call of an action, counting the ones in flight; a call that redirects rejects with `ActionRedirectError` once the browser is on its way, so the action stops being pending.
268
126
  // How a post went is the request's on the server; in the browser the last call's once the page shown made one, else the post the page answers.
269
127
  export function callable(url: () => string): { call: (input: never, options?: CallOptions) => CallPromise<CallResult<unknown, unknown>>, reads: PropertyDescriptorMap, bound: Bound } {
270
128
  const [inFlight, setInFlight, flying] = lazySignal(0)
@@ -294,187 +152,41 @@ export function callable(url: () => string): { call: (input: never, options?: Ca
294
152
  }
295
153
  const error = (field = '') => failed()?.errors[field]
296
154
  const validate = validator(url, failed, errors => called(navigation.page, errors === undefined ? null : { action: url(), status: 422, values: {}, errors, data: undefined }))
155
+ const host = { url, shift, called, progress: setProgress, latest: (turn: number) => turn === started }
297
156
 
298
- const run = async (lane: Lane, input: unknown, options?: CallOptions) => {
299
- // The page the call was made on, whose outcome it is even once the visitor went elsewhere.
300
- const page = navigation.page
301
- const visits = navigation.visits
302
- const left = () => navigation.visits !== visits
303
- // The island calling, from its setup or a handler, whose end ends a stream the call answers with; else the page, as long as no other path is shown.
304
- const caller: Caller = { owner: liveOwner(getOwner()), arrivals: navigation.arrivals }
305
- const mode = options?.queue ?? lane.queue ?? 'parallel'
306
-
307
- const turn = ++started
157
+ // The state a call changes is the action's own and is read from the first paint, so a call counts itself in flight at once and hands the rest to the code that runs it, which loads with the first call.
158
+ const run = async (lane: Lane, input: unknown, fixed: Record<string, unknown> | undefined, options?: CallOptions) => {
159
+ const start: Start = { page: navigation.page, visits: navigation.visits, caller: { owner: liveOwner(getOwner()), arrivals: navigation.arrivals }, turn: ++started }
308
160
 
309
161
  shift(1)
310
- called(page, null)
311
- void hooked(options?.onStart, { input })
312
-
313
- let undo: (() => void) | undefined
314
- let posted = false
315
- let sent = false
316
- let timedOut = false
317
- // A stream keeps the call in flight until it ends.
318
- let streaming = false
319
- let answer: unknown
320
- let failure: unknown
321
- let release: (() => void) | undefined
322
- // Started before the caller goes on, so a navigation it starts next supersedes the refresh rather than the other way round; a site with `navigation: false` shows a call's effects itself.
323
- const refreshPage = () => {
324
- const scope = options?.refresh
325
-
326
- if (scope === false || left())
327
- return
328
-
329
- if (scope === undefined || scope === true) {
330
- if (navigation.hooks)
331
- void (scope === true ? refreshed() : refreshedUnlessFollowed(caller.invalidated))
332
- }
333
- else {
334
- const asked = [scope].flat()
335
- const names = asked.filter(source => typeof source === 'string')
162
+ called(start.page, null)
336
163
 
337
- if (names.length > 0 && navigation.hooks)
338
- void refreshed(names)
339
-
340
- void refreshedIn(asked.filter(source => typeof source !== 'string'))
341
- }
342
- }
343
- const later = mode === 'latest' ? new AbortController() : undefined
344
- // What aborts the call as a whole: its own signal, and a later call of a `latest` queue, which stops mattering once the post is answered.
345
- const whole = join([options?.signal, later?.signal], later !== undefined)
346
- const timeoutOption = options?.timeout
347
- const timeout = waitOf(timeoutOption, 'timeout')
164
+ let code: typeof import('./action-run')
165
+ let attempt: typeof loading
348
166
 
349
167
  try {
350
- undo = options?.optimistic ? undoable(options.optimistic) : undefined
351
-
352
- if (later) {
353
- const reason = new DOMException('Superseded by a later call', 'AbortError')
354
-
355
- superseding.add(reason)
356
- lane.latest?.abort(reason)
357
- lane.latest = later
358
- }
359
-
360
- if (mode === 'serial') {
361
- const before = lane.tail
362
-
363
- lane.tail = Promise.all([before, new Promise<void>((resolve) => {
364
- release = resolve
365
- })])
366
- await waitFor(before, whole.signal)
367
- }
368
-
369
- const attempts = retryOf(options?.retry)
370
- // One key for every try of the call, which a handler reads from `ctx.request` to tell a repeat from a new call.
371
- const key = attempts.times > 0 ? idempotencyKey() : undefined
372
-
373
- for (let attempt = 0; ; attempt++) {
374
- // The wait for the answer counts from the moment the post is sent, and each try has its own.
375
- const limit = timeout === undefined ? undefined : new AbortController()
376
- const attemptSignal = join([whole.signal, limit?.signal])
377
- let timer: ReturnType<typeof setTimeout> | undefined
378
- let sentNow = false
379
-
380
- try {
381
- answer = await (await postingCode()).post(url(), input, setProgress, attemptSignal.signal, () => {
382
- sent = sentNow = true
383
- clearTimeout(timer)
384
- timer = limit && setTimeout(() => {
385
- timedOut = true
386
- limit.abort(new DOMException(`The action call timeout of ${String(timeoutOption)} passed before the server answered`, 'TimeoutError'))
387
- }, timeout)
388
- }, left, caller, { key, options })
389
-
390
- break
391
- }
392
- catch (error) {
393
- // Only the upload path says `sent: false`, as `fetch` gives no such signal and `onSent` has run before it: the default retry of an unsent post covers an upload alone.
394
- if (attempt >= attempts.times || whole.signal?.aborted === true || !attempts.again(error, sentNow && (error as { sent?: unknown } | null)?.sent !== false))
395
- throw error
396
-
397
- await waitFor(attempts.delay * 2 ** attempt, whole.signal)
398
- }
399
- finally {
400
- clearTimeout(timer)
401
- attemptSignal.stop()
402
- }
403
- }
404
-
405
- posted = true
406
- whole.stop(later?.signal)
407
- release?.()
408
- release = undefined
409
-
410
- const streamEnded = (status: ConnectionStatus) => {
411
- if (status === 'done') {
412
- called(page, { action: url(), succeeded: true, data: untrack((answer as ActionStream<unknown>).last) }, turn)
413
- refreshPage()
414
- }
415
-
416
- shift(-1)
417
- }
418
-
419
- streaming = onStreamEnd(answer, streamEnded)
420
-
421
- if (streaming) {
422
- // A retry of the stream is the call running again.
423
- caller.retried = (again) => {
424
- shift(1)
425
- again[SETTLED](streamEnded)
426
- }
427
- }
428
-
429
- if (!streaming) {
430
- called(page, { action: url(), succeeded: true, data: answer }, turn)
431
- refreshPage()
432
- }
433
-
434
- void hooked(options?.onSuccess, { data: answer })
435
-
436
- return answer
168
+ // An optimistic change shows at once, as the call is pending at once.
169
+ start.undo = options?.optimistic ? undoable(options.optimistic) : undefined
170
+ code = running ?? await (attempt = loading ??= runCode())
437
171
  }
438
172
  catch (error) {
439
- failure = error
440
-
441
- // A redirect leaves the page as it is until the next one shows.
442
- if (!posted && !(error instanceof ActionRedirectError))
443
- undo?.()
173
+ if (loading === attempt)
174
+ loading = undefined
444
175
 
445
- // The server may have run a call aborted or timed out once it was sent, which the page then shows as it stands.
446
- if (sent && (options?.signal?.aborted === true || timedOut))
447
- refreshPage()
176
+ if (start.undo) {
177
+ start.undo()
178
+ released(start.undo)
179
+ }
448
180
 
449
- if (error instanceof ActionError && !(error instanceof ActionRedirectError))
450
- called(page, { action: url(), status: error.status, values: {}, errors: error.errors, data: error.data }, turn)
181
+ shift(-1)
451
182
 
452
- if (!(error instanceof ActionRedirectError) && whole.signal?.aborted !== true)
453
- void hooked(options?.onError, { error: apiErrorOf(error) })
183
+ if (host.latest(start.turn))
184
+ setProgress(undefined)
454
185
 
455
186
  throw error
456
187
  }
457
- finally {
458
- // A stream is aborted by the call's own signal until it ends.
459
- if (!streaming)
460
- whole.stop()
461
-
462
- release?.()
463
188
 
464
- if (undo)
465
- released(undo)
466
-
467
- if (!streaming)
468
- shift(-1)
469
-
470
- if (turn === started)
471
- setProgress(undefined)
472
-
473
- if (lane.latest === later)
474
- lane.latest = undefined
475
-
476
- void hooked(options?.onSettled, failure === undefined ? { data: answer } : { error: apiErrorOf(failure) })
477
- }
189
+ return code.run(host, start, lane, input, fixed, options)
478
190
  }
479
191
 
480
192
  const bound = binder(run, url)
@@ -489,12 +201,8 @@ export function callable(url: () => string): { call: (input: never, options?: Ca
489
201
  ...formHooks(url),
490
202
  progress: read(progress),
491
203
  form: read({ failed, error, validate }),
492
- failed: read(failed),
493
- succeeded: read(() => succeededOf(outcome())),
494
204
  data: read(() => outcome()?.succeeded ? outcome()?.data : undefined),
495
205
  status: read(() => statusOf(inFlight(), outcome(), failed())),
496
- error: read(error),
497
- validate: read(validate),
498
206
  refused: read((error: unknown) => error instanceof ActionError && refusedAt.get(error) === url()),
499
207
  track: read(track),
500
208
  with: read((fields: Record<string, unknown>) => withFields(call, fields)),
@@ -542,16 +250,16 @@ function formHook<Detail extends { action: string }, Told>(url: () => string, st
542
250
  }
543
251
 
544
252
  // A call and `track()` carrying the fields given, over one action's state: a `with` of the action follows the same calls.
545
- function binder(run: (lane: Lane, input: unknown, options?: CallOptions) => Promise<unknown>, url: () => string): Bound {
253
+ function binder(run: (lane: Lane, input: unknown, fixed: Record<string, unknown> | undefined, options?: CallOptions) => Promise<unknown>, url: () => string): Bound {
546
254
  const actionLane: Lane = { tail: Promise.resolve() }
547
255
 
548
256
  return fields => ({
549
257
  // eslint-disable-next-line ts/promise-function-async -- an async function would wrap the call's promise, which carries `orThrow()`
550
- call: (input: unknown, options?: CallOptions) => settling(run(actionLane, withFixed(input, fields), options), error => signalAborted(options) ? undefined : refusalOf(url)(error)),
258
+ call: (input: unknown, options?: CallOptions) => settling(run(actionLane, input, fields, options), error => signalAborted(options) ? undefined : refusalOf(url)(error)),
551
259
  track: (handle) => {
552
260
  const lane: Lane = { tail: Promise.resolve(), queue: handle?.queue }
553
261
 
554
- return tracked(async (input, options) => run(lane, withFixed(input, fields), options), url, handle)
262
+ return tracked(async (input, options) => run(lane, input, fields, options), url, handle)
555
263
  },
556
264
  })
557
265
  }
@@ -599,7 +307,7 @@ function tracked(call: (input: never, options?: CallOptions) => Promise<unknown>
599
307
 
600
308
  let warming = false
601
309
 
602
- // An island holding an action caller loads the posting code once the browser is idle, so a call made as the page goes away (`pagehide`, which cannot wait for a chunk) finds it in; it stays out of the first load. A failure is left for the call itself to retry and report, so an idle load never reloads the page.
310
+ // An island holding an action caller loads the code running a call once the browser is idle, so a call made as the page goes away (`pagehide`, which cannot wait for a chunk) finds it in; it stays out of the first load. A failure is left for the call itself to retry and report, so an idle load never reloads the page.
603
311
  function warmCode(): void {
604
312
  if (warming || typeof window === 'undefined')
605
313
  return
@@ -608,7 +316,7 @@ function warmCode(): void {
608
316
 
609
317
  const load = async () => {
610
318
  try {
611
- posting = await import('./action-post')
319
+ running = await import('./action-run')
612
320
  }
613
321
  catch {}
614
322
  }
@@ -619,15 +327,11 @@ function warmCode(): void {
619
327
  setTimeout(() => void load(), 200)
620
328
  }
621
329
 
622
- function postingCode(): typeof import('./action-post') | Promise<typeof import('./action-post')> {
623
- return posting ?? postCode()
624
- }
625
-
626
- // A flaky connection gets the chunk retried after 1 s and 3 s, as a lazy component's is. The code that posts a call, loaded by the first call; a chunk a deploy removed asks the server whether the build changed, which reloads the page, and the call fails as any call that could not be sent.
627
- async function postCode(): Promise<typeof import('./action-post')> {
330
+ // A flaky connection gets the chunk retried after 1 s and 3 s, as a lazy component's is. The code that runs a call, loaded by the first call; a chunk a deploy removed asks the server whether the build changed, which reloads the page, and the call fails as any call that could not be sent.
331
+ async function runCode(): Promise<typeof import('./action-run')> {
628
332
  for (let attempt = 0; ; attempt++) {
629
333
  try {
630
- return posting = await import('./action-post')
334
+ return running = await import('./action-run')
631
335
  }
632
336
  catch (error) {
633
337
  if (attempt >= CODE_RETRIES) {
@@ -15,6 +15,32 @@ export interface EncodedCall {
15
15
  body: string | FormData
16
16
  }
17
17
 
18
+ // A call of an action `with()` fixed fields of is made with them, over the ones it is given, as a form posting to its URL does: a field fixed to `null` or `undefined` is left out there, so the given one stays.
19
+ export function withFixed(input: unknown, fixed: Record<string, unknown> | undefined): unknown {
20
+ if (fixed === undefined)
21
+ return input
22
+
23
+ const set = Object.entries(fixed).filter(([name, value]) => name !== '__proto__' && value !== undefined && value !== null)
24
+
25
+ if (!(input instanceof FormData))
26
+ return { ...input as object | undefined, ...Object.fromEntries(set) }
27
+
28
+ const names = new Set(set.map(([name]) => name))
29
+ const copy = new FormData()
30
+
31
+ for (const [name, value] of input) {
32
+ if (!names.has(name))
33
+ copy.append(name, value)
34
+ }
35
+
36
+ for (const [name, value] of set) {
37
+ for (const item of Array.isArray(value) ? value : [value])
38
+ copy.append(name, item instanceof Date ? item.toISOString() : String(item))
39
+ }
40
+
41
+ return copy
42
+ }
43
+
18
44
  // The encoding keeps numbers, booleans and Dates typed, which form fields would turn into strings; only a call carrying files needs multipart, whose boundary fetch writes.
19
45
  export function encodeCall(input: unknown): EncodedCall {
20
46
  // Sent as the form it is, for the server to read as a form post and answer as a call.
@@ -1,6 +1,5 @@
1
- import type { Failure, FieldErrors } from './action-shared'
1
+ import type { Failure } from './action-shared'
2
2
  import { actionFailed, ApiError, messageOf } from './api-error'
3
- import { KayError } from './kay-error'
4
3
 
5
4
  export const FAILURE = Symbol.for('kay.failure')
6
5
 
@@ -8,7 +7,7 @@ export const FAILURE = Symbol.for('kay.failure')
8
7
  export class ActionError<Data = unknown> extends ApiError<Data> {
9
8
  override name = 'ActionError'
10
9
 
11
- // `errors` holds a message per field the schema refused, `data` what the handler passed to `ctx.fail`, undefined when the call was refused before it ran; `message` reads them, else the status and body.
10
+ // `errors` holds a message per field the schema refused, `data` what the handler passed to `ctx.deny`, undefined when the call was refused before it ran; `message` reads them, else the status and body.
12
11
  constructor(status: number, readonly body: string, errors: Record<string, string> = {}, data?: Data, message = messageOf({ status, errors, data }, actionFailed(status))) {
13
12
  super(status, message, data, errors)
14
13
  }
@@ -24,14 +23,7 @@ export class ActionRedirectError extends ActionError {
24
23
  }
25
24
  }
26
25
 
27
- export function failure<Data>(status: number, data: Data, errors?: FieldErrors): Failure<Data> {
28
- // A call reads a success status as the handler's result, so a failure must not carry one.
29
- if (!Number.isInteger(status) || status < 400 || status > 599)
30
- throw new KayError('argument-invalid', `kay: ctx.deny takes an error status, from 400 to 599, not ${status}`)
31
-
32
- return { [FAILURE]: true, status, data, errors }
33
- }
34
-
26
+ // What a library's failed result is to an action: kayjs-auth's carries the mark, a status and its kind as `data`, so returning it refuses the call.
35
27
  export function isFailure(value: unknown): value is Failure<unknown> {
36
28
  return typeof value === 'object' && value !== null && FAILURE in value
37
29
  }
@@ -28,7 +28,7 @@ export function workOf(protection: ResolvedProtection): { difficulty: number, ma
28
28
  if (!Number.isInteger(difficulty) || difficulty < 1 || difficulty > 1e9)
29
29
  throw new KayError('config-invalid', `kay: proofOfWork's difficulty is ${difficulty}; it takes a whole number from 1 to 1,000,000,000`)
30
30
 
31
- return { difficulty, maxAge: durationSeconds(options.ttl ?? options.maxAge ?? DAY, 'proofOfWork.ttl') * 1000, pretend: options.pretend === true, store: options.store }
31
+ return { difficulty, maxAge: durationSeconds(options.ttl ?? DAY, 'proofOfWork.ttl') * 1000, pretend: options.pretend === true, store: options.store }
32
32
  }
33
33
 
34
34
  // `minTime` in milliseconds, read once it is set.
@@ -40,7 +40,7 @@ export function minTimeOf(protection: ResolvedProtection): { after: number, maxA
40
40
 
41
41
  const options = typeof minTime === 'object' ? minTime : { after: minTime }
42
42
 
43
- return { after: durationSeconds(options.after, 'minTime') * 1000, maxAge: durationSeconds(options.ttl ?? options.maxAge ?? DAY, 'minTime.ttl') * 1000, pretend: options.pretend === true }
43
+ return { after: durationSeconds(options.after, 'minTime') * 1000, maxAge: durationSeconds(options.ttl ?? DAY, 'minTime.ttl') * 1000, pretend: options.pretend === true }
44
44
  }
45
45
 
46
46
  export function honeypotField(protection: ResolvedProtection | undefined): string | undefined {