@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.
- package/dist/eslint.js +1875 -3815
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +1 -1
- package/llms/actions-from-islands.md +5 -5
- package/llms/actions-refused-fields.md +4 -4
- package/llms/api-from-islands.md +6 -6
- package/llms/browser-only.md +2 -2
- package/llms/cdn-caching.md +1 -1
- package/llms/checks.md +1 -1
- package/llms/code-lints.md +1 -2
- package/llms/component-libraries.md +1 -1
- package/llms/component-library-conventions.md +1 -1
- package/llms/components.md +4 -4
- package/llms/deprecated-lints.md +1 -7
- package/llms/effects.md +1 -1
- package/llms/errors.md +2 -2
- package/llms/events.md +1 -1
- package/llms/guards.md +1 -1
- package/llms/head.md +1 -1
- package/llms/hooks.md +2 -2
- package/llms/images.md +1 -1
- package/llms/island-and-form-lints.md +2 -1
- package/llms/island-sources.md +1 -1
- package/llms/islands-state-to-ids.md +2 -2
- package/llms/islands.md +5 -3
- package/llms/lints.md +1 -1
- package/llms/live-values.md +3 -3
- package/llms/local-collections.md +1 -1
- package/llms/locales.md +1 -1
- package/llms/mcp.md +2 -2
- package/llms/metrics.md +1 -1
- package/llms/navigation-from-code.md +6 -6
- package/llms/prerendering.md +1 -0
- package/llms/production.md +2 -2
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +4 -4
- package/llms/proxy-and-security.md +1 -1
- package/llms/queues.md +1 -1
- package/llms/rate-limits.md +4 -4
- package/llms/rendering.md +1 -1
- package/llms/server-islands.md +2 -2
- package/llms/server.md +1 -1
- package/llms/stores.md +1 -1
- package/llms/styles-and-assets.md +1 -1
- package/llms/testing-mount.md +49 -0
- package/llms/testing.md +4 -45
- package/llms/upgrading-1-105-config.md +13 -13
- package/llms/upgrading-archive.md +42 -82
- package/llms/upgrading.md +92 -58
- package/llms/whats-new-archive.md +36 -1
- package/llms/whats-new.md +18 -39
- package/llms.txt +6 -7
- package/package.json +6 -10
- package/src/build/client.ts +7 -6
- package/src/build/icon-slots.ts +140 -0
- package/src/build/libraries.ts +24 -2
- package/src/build/plugin.ts +10 -0
- package/src/build/route-sizes.ts +2 -3
- package/src/build/runtime-chunk.ts +2 -2
- package/src/build/source-files.ts +8 -3
- package/src/build/variants.ts +90 -1
- package/src/check/browser-global-reads.ts +2 -2
- package/src/check/config-objects.ts +1 -1
- package/src/check/diagnose.ts +0 -22
- package/src/check/export-homes.ts +1 -1
- package/src/check/guards.ts +3 -3
- package/src/check/index.ts +2 -7
- package/src/check/moved-keys.ts +1 -1
- package/src/check/project.ts +4 -9
- package/src/check/renamed-packages.ts +3 -63
- package/src/check/shadow-types.ts +4 -104
- package/src/commands/check.ts +2 -2
- package/src/commands/env.ts +25 -3
- package/src/compiler/ast.ts +18 -16
- package/src/compiler/browser.ts +2 -14
- package/src/compiler/class-items.ts +16 -0
- package/src/compiler/codegen.ts +8 -8
- package/src/compiler/dead-code.ts +22 -0
- package/src/compiler/deprecated-library.ts +0 -12
- package/src/compiler/deprecated-lints.ts +4 -505
- package/src/compiler/deprecated-ui-props.ts +5 -5
- package/src/compiler/dom-property.ts +23 -0
- package/src/compiler/dom.ts +15 -15
- package/src/compiler/errors.ts +2 -2
- package/src/compiler/fence-checks.ts +2 -121
- package/src/compiler/hand-parts.ts +55 -0
- package/src/compiler/helper-imports.ts +2 -2
- package/src/compiler/image-attributes.ts +1 -3
- package/src/compiler/index.ts +20 -21
- package/src/compiler/island-arguments.ts +8 -95
- package/src/compiler/island-cause.ts +7 -7
- package/src/compiler/island-declaration.ts +2 -8
- package/src/compiler/island-lints.ts +12 -0
- package/src/compiler/island-marker.ts +3 -3
- package/src/compiler/island-problems.ts +25 -0
- package/src/compiler/jsx-class.ts +1 -25
- package/src/compiler/jsx.ts +2 -2
- package/src/compiler/kay-exports.ts +0 -2
- package/src/compiler/link-flags.ts +9 -38
- package/src/compiler/lints.ts +7 -14
- package/src/compiler/markup.ts +23 -26
- package/src/compiler/module-signals.ts +2 -2
- package/src/compiler/names.ts +1 -1
- package/src/compiler/page-settings.ts +11 -0
- package/src/compiler/parser.ts +6 -8
- package/src/compiler/plan.ts +1 -3
- package/src/compiler/rewrite.ts +3 -18
- package/src/compiler/script-server.ts +8 -3
- package/src/compiler/validate.ts +3 -8
- package/src/config-loader.ts +14 -4
- package/src/config-resolve.ts +18 -142
- package/src/config-shape.ts +44 -34
- package/src/config.ts +10 -114
- package/src/dev/preload.ts +4 -1
- package/src/lsp/server.ts +4 -0
- package/src/migrate/markup.ts +4 -1
- package/src/package-names.ts +1 -1
- package/src/runtime/action-call.ts +39 -335
- package/src/runtime/action-encode.ts +26 -0
- package/src/runtime/action-error.ts +3 -11
- package/src/runtime/action-protection.ts +2 -2
- package/src/runtime/action-run.ts +332 -0
- package/src/runtime/action-shared.ts +14 -37
- package/src/runtime/action-stream.ts +0 -1
- package/src/runtime/action.ts +1 -1
- package/src/runtime/call-result.ts +2 -10
- package/src/runtime/checks.ts +11 -11
- package/src/runtime/client.ts +2 -2
- package/src/runtime/core.ts +5 -23
- package/src/runtime/dom.ts +1 -1
- package/src/runtime/html.ts +1 -1
- package/src/runtime/i18n.client.ts +1 -4
- package/src/runtime/i18n.server.ts +1 -4
- package/src/runtime/i18n.ts +3 -3
- package/src/runtime/index.ts +2 -2
- package/src/runtime/island.server.ts +18 -5
- package/src/runtime/live-resource.server.ts +0 -1
- package/src/runtime/live-value.server.ts +2 -2
- package/src/runtime/live-value.shared.ts +7 -20
- package/src/runtime/live.ts +1 -12
- package/src/runtime/local-types.ts +1 -11
- package/src/runtime/local.ts +4 -14
- package/src/runtime/navigate-api.ts +2 -5
- package/src/runtime/navigation-state.ts +0 -12
- package/src/runtime/page-swap.ts +6 -6
- package/src/runtime/persist.ts +11 -3
- package/src/runtime/persisted.ts +4 -30
- package/src/runtime/presence.ts +6 -7
- package/src/runtime/query-param.ts +20 -12
- package/src/runtime/reactive.ts +3 -1
- package/src/runtime/refuse.ts +3 -17
- package/src/runtime/store-base.ts +4 -6
- package/src/runtime/swap-fetch.ts +1 -1
- package/src/runtime/values.ts +40 -23
- package/src/runtime/with-query.ts +9 -0
- package/src/server/action-hooks.ts +8 -8
- package/src/server/actions.ts +13 -14
- package/src/server/api-modules.ts +2 -3
- package/src/server/app-stages.ts +15 -33
- package/src/server/app.ts +10 -5
- package/src/server/auth-mails.ts +0 -2
- package/src/server/env-state.ts +40 -10
- package/src/server/flash.ts +1 -1
- package/src/server/guard-requirement.ts +4 -4
- package/src/server/image.ts +2 -2
- package/src/server/index.ts +0 -2
- package/src/server/job-context.ts +3 -3
- package/src/server/jobs-page.ts +1 -1
- package/src/server/jobs.ts +5 -9
- package/src/server/kept-exports.ts +0 -2
- package/src/server/kv.ts +11 -14
- package/src/server/library.ts +1 -3
- package/src/server/live.ts +2 -2
- package/src/server/mcp.ts +3 -9
- package/src/server/metrics.ts +2 -4
- package/src/server/page-settings.ts +10 -19
- package/src/server/prerender.ts +19 -2
- package/src/server/protection.ts +15 -18
- package/src/server/queue.ts +3 -6
- package/src/server/rate-limit.ts +0 -3
- package/src/server/render-document.ts +1 -1
- package/src/server/routes.ts +7 -3
- package/src/server/scope.ts +3 -2
- package/src/server/session.ts +5 -6
- package/src/server/setup.ts +1 -1
- package/src/server/signals.ts +17 -7
- package/src/server/signed.ts +1 -3
- package/src/server/source.ts +20 -4
- package/src/server/speculation.ts +1 -1
- package/src/server/storage.ts +3 -8
- package/src/server/validate.ts +1 -1
- package/src/server/vitals.ts +1 -3
- package/src/server/work-scope.ts +2 -4
- package/src/server/work.ts +1 -1
- package/src/server/workflow.ts +1 -1
- package/src/test/index.ts +2 -1
- package/src/test/site-actions.ts +16 -6
- package/src/test/site-keys.ts +10 -15
- package/src/test/site-socket.ts +1 -2
- package/src/test/site-types.ts +0 -8
- package/types/build/client.d.ts +1 -1
- package/types/build/client.d.ts.map +1 -1
- package/types/build/icon-slots.d.ts +7 -0
- package/types/build/icon-slots.d.ts.map +1 -0
- package/types/build/libraries.d.ts +2 -0
- package/types/build/libraries.d.ts.map +1 -1
- package/types/build/plugin.d.ts +1 -0
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/route-sizes.d.ts.map +1 -1
- package/types/build/source-files.d.ts.map +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/diagnose.d.ts.map +1 -1
- package/types/check/index.d.ts +1 -2
- package/types/check/index.d.ts.map +1 -1
- package/types/check/project.d.ts.map +1 -1
- package/types/check/renamed-packages.d.ts +0 -3
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/commands/env.d.ts.map +1 -1
- package/types/compiler/ast.d.ts +1 -2
- package/types/compiler/ast.d.ts.map +1 -1
- package/types/compiler/browser.d.ts.map +1 -1
- package/types/compiler/class-items.d.ts +7 -0
- package/types/compiler/class-items.d.ts.map +1 -0
- package/types/compiler/dead-code.d.ts +9 -0
- package/types/compiler/dead-code.d.ts.map +1 -0
- package/types/compiler/deprecated-library.d.ts.map +1 -1
- package/types/compiler/deprecated-lints.d.ts +0 -560
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/deprecated-ui-props.d.ts +1 -8
- package/types/compiler/deprecated-ui-props.d.ts.map +1 -1
- package/types/compiler/dom-property.d.ts +9 -0
- package/types/compiler/dom-property.d.ts.map +1 -0
- package/types/compiler/dom.d.ts +1 -0
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/errors.d.ts +2 -2
- package/types/compiler/errors.d.ts.map +1 -1
- package/types/compiler/fence-checks.d.ts +0 -1
- package/types/compiler/fence-checks.d.ts.map +1 -1
- package/types/compiler/hand-parts.d.ts +7 -0
- package/types/compiler/hand-parts.d.ts.map +1 -0
- package/types/compiler/image-attributes.d.ts +0 -1
- package/types/compiler/image-attributes.d.ts.map +1 -1
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-arguments.d.ts +2 -11
- package/types/compiler/island-arguments.d.ts.map +1 -1
- package/types/compiler/island-cause.d.ts +1 -1
- package/types/compiler/island-cause.d.ts.map +1 -1
- package/types/compiler/island-declaration.d.ts +1 -3
- package/types/compiler/island-declaration.d.ts.map +1 -1
- package/types/compiler/island-lints.d.ts +10 -0
- package/types/compiler/island-lints.d.ts.map +1 -0
- package/types/compiler/island-problems.d.ts +7 -0
- package/types/compiler/island-problems.d.ts.map +1 -0
- package/types/compiler/jsx-class.d.ts +1 -2
- package/types/compiler/jsx-class.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/link-flags.d.ts +0 -6
- package/types/compiler/link-flags.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +11 -572
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/markup.d.ts +1 -1
- package/types/compiler/markup.d.ts.map +1 -1
- package/types/compiler/module-signals.d.ts.map +1 -1
- package/types/compiler/names.d.ts.map +1 -1
- package/types/compiler/page-settings.d.ts +4 -0
- package/types/compiler/page-settings.d.ts.map +1 -1
- package/types/compiler/parser.d.ts.map +1 -1
- package/types/compiler/plan.d.ts.map +1 -1
- package/types/compiler/script-server.d.ts.map +1 -1
- package/types/compiler/validate.d.ts.map +1 -1
- package/types/config-loader.d.ts.map +1 -1
- package/types/config-resolve.d.ts.map +1 -1
- package/types/config-shape.d.ts +1 -1
- package/types/config-shape.d.ts.map +1 -1
- package/types/config.d.ts +5 -105
- package/types/config.d.ts.map +1 -1
- package/types/dev/preload.d.ts.map +1 -1
- package/types/lsp/server.d.ts.map +1 -1
- package/types/migrate/markup.d.ts.map +1 -1
- package/types/runtime/action-call.d.ts.map +1 -1
- package/types/runtime/action-encode.d.ts +1 -0
- package/types/runtime/action-encode.d.ts.map +1 -1
- package/types/runtime/action-error.d.ts +1 -2
- package/types/runtime/action-error.d.ts.map +1 -1
- package/types/runtime/action-run.d.ts +23 -0
- package/types/runtime/action-run.d.ts.map +1 -0
- package/types/runtime/action-shared.d.ts +1 -27
- package/types/runtime/action-shared.d.ts.map +1 -1
- package/types/runtime/action-stream.d.ts.map +1 -1
- package/types/runtime/action.d.ts +1 -1
- package/types/runtime/action.d.ts.map +1 -1
- package/types/runtime/call-result.d.ts +0 -10
- package/types/runtime/call-result.d.ts.map +1 -1
- package/types/runtime/checks.d.ts +6 -9
- package/types/runtime/checks.d.ts.map +1 -1
- package/types/runtime/core.d.ts +2 -20
- package/types/runtime/core.d.ts.map +1 -1
- package/types/runtime/dom.d.ts +1 -1
- package/types/runtime/dom.d.ts.map +1 -1
- package/types/runtime/html.d.ts +1 -1
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/i18n.client.d.ts +0 -1
- package/types/runtime/i18n.client.d.ts.map +1 -1
- package/types/runtime/i18n.d.ts +1 -1
- package/types/runtime/i18n.d.ts.map +1 -1
- package/types/runtime/i18n.server.d.ts +0 -1
- package/types/runtime/i18n.server.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -2
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +1 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/live-resource.server.d.ts.map +1 -1
- package/types/runtime/live-value.shared.d.ts +7 -15
- package/types/runtime/live-value.shared.d.ts.map +1 -1
- package/types/runtime/live.d.ts +0 -11
- package/types/runtime/live.d.ts.map +1 -1
- package/types/runtime/local-types.d.ts +0 -14
- package/types/runtime/local-types.d.ts.map +1 -1
- package/types/runtime/navigate-api.d.ts +0 -4
- package/types/runtime/navigate-api.d.ts.map +1 -1
- package/types/runtime/navigation-state.d.ts +0 -4
- package/types/runtime/navigation-state.d.ts.map +1 -1
- package/types/runtime/page-swap.d.ts.map +1 -1
- package/types/runtime/persist.d.ts +1 -0
- package/types/runtime/persist.d.ts.map +1 -1
- package/types/runtime/persisted.d.ts +0 -15
- package/types/runtime/persisted.d.ts.map +1 -1
- package/types/runtime/presence.d.ts +0 -2
- package/types/runtime/presence.d.ts.map +1 -1
- package/types/runtime/query-param.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +2 -1
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/refuse.d.ts +0 -7
- package/types/runtime/refuse.d.ts.map +1 -1
- package/types/runtime/store-base.d.ts +1 -2
- package/types/runtime/store-base.d.ts.map +1 -1
- package/types/runtime/values.d.ts +2 -1
- package/types/runtime/values.d.ts.map +1 -1
- package/types/runtime/with-query.d.ts +2 -0
- package/types/runtime/with-query.d.ts.map +1 -1
- package/types/server/action-hooks.d.ts +4 -4
- package/types/server/action-hooks.d.ts.map +1 -1
- package/types/server/actions.d.ts.map +1 -1
- package/types/server/api-modules.d.ts +0 -1
- package/types/server/api-modules.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +5 -13
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +3 -8
- package/types/server/app.d.ts.map +1 -1
- package/types/server/auth-mails.d.ts +0 -5
- package/types/server/auth-mails.d.ts.map +1 -1
- package/types/server/env-state.d.ts +1 -0
- package/types/server/env-state.d.ts.map +1 -1
- package/types/server/guard-requirement.d.ts +0 -1
- package/types/server/guard-requirement.d.ts.map +1 -1
- package/types/server/image.d.ts +0 -1
- package/types/server/image.d.ts.map +1 -1
- package/types/server/index.d.ts +0 -2
- package/types/server/index.d.ts.map +1 -1
- package/types/server/job-context.d.ts +1 -1
- package/types/server/job-context.d.ts.map +1 -1
- package/types/server/jobs.d.ts +0 -4
- package/types/server/jobs.d.ts.map +1 -1
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/kv.d.ts +4 -4
- package/types/server/kv.d.ts.map +1 -1
- package/types/server/library.d.ts +1 -3
- package/types/server/library.d.ts.map +1 -1
- package/types/server/mcp.d.ts +0 -1
- package/types/server/mcp.d.ts.map +1 -1
- package/types/server/metrics.d.ts +0 -5
- package/types/server/metrics.d.ts.map +1 -1
- package/types/server/page-settings.d.ts +3 -3
- package/types/server/page-settings.d.ts.map +1 -1
- package/types/server/prerender.d.ts.map +1 -1
- package/types/server/protection.d.ts +6 -6
- package/types/server/protection.d.ts.map +1 -1
- package/types/server/queue.d.ts +1 -3
- package/types/server/queue.d.ts.map +1 -1
- package/types/server/rate-limit.d.ts +0 -2
- package/types/server/rate-limit.d.ts.map +1 -1
- package/types/server/routes.d.ts +1 -1
- package/types/server/routes.d.ts.map +1 -1
- package/types/server/scope.d.ts.map +1 -1
- package/types/server/session.d.ts +1 -1
- package/types/server/session.d.ts.map +1 -1
- package/types/server/signals.d.ts.map +1 -1
- package/types/server/signed.d.ts +0 -2
- package/types/server/signed.d.ts.map +1 -1
- package/types/server/source.d.ts +1 -1
- package/types/server/source.d.ts.map +1 -1
- package/types/server/storage.d.ts +0 -4
- package/types/server/storage.d.ts.map +1 -1
- package/types/server/vitals.d.ts +0 -1
- package/types/server/vitals.d.ts.map +1 -1
- package/types/server/work-scope.d.ts +0 -2
- package/types/server/work-scope.d.ts.map +1 -1
- package/types/server/workflow.d.ts +1 -1
- package/types/server/workflow.d.ts.map +1 -1
- package/types/test/index.d.ts.map +1 -1
- package/types/test/site-actions.d.ts +1 -1
- package/types/test/site-actions.d.ts.map +1 -1
- package/types/test/site-keys.d.ts +1 -1
- package/types/test/site-keys.d.ts.map +1 -1
- package/types/test/site-socket.d.ts +1 -1
- package/types/test/site-socket.d.ts.map +1 -1
- package/types/test/site-types.d.ts +0 -8
- package/types/test/site-types.d.ts.map +1 -1
- package/llms/deprecated-lints-1-105-libraries.md +0 -32
- package/llms/deprecated-lints-1-105.md +0 -58
- package/src/check/action-readers.ts +0 -115
- package/src/check/action-type.ts +0 -44
- package/src/check/ai-language.ts +0 -56
- package/src/check/app-hooks.ts +0 -90
- package/src/check/auth-methods.ts +0 -85
- package/src/check/auth-rate-limits.ts +0 -99
- package/src/check/call-result.ts +0 -242
- package/src/check/client-keys.ts +0 -10
- package/src/check/cms-options.ts +0 -81
- package/src/check/config-groups.ts +0 -22
- package/src/check/config-switches.ts +0 -38
- package/src/check/context-import.ts +0 -51
- package/src/check/env-files.ts +0 -31
- package/src/check/format-duration.ts +0 -75
- package/src/check/guard-options.ts +0 -58
- package/src/check/handler-events.ts +0 -149
- package/src/check/hook-context.ts +0 -94
- package/src/check/hook-names.ts +0 -104
- package/src/check/i18n-keys.ts +0 -50
- package/src/check/images-keys.ts +0 -54
- package/src/check/job-shapes.ts +0 -273
- package/src/check/link-flag-tests.ts +0 -130
- package/src/check/live-api.ts +0 -137
- package/src/check/mail-api.ts +0 -67
- package/src/check/one-state-api.ts +0 -357
- package/src/check/pages-options.ts +0 -35
- package/src/check/rate-enforce.ts +0 -53
- package/src/check/refusal-calls.ts +0 -185
- package/src/check/retired-lints.ts +0 -49
- package/src/check/route-keys.ts +0 -166
- package/src/check/secret-keys.ts +0 -83
- package/src/check/socket-frames.ts +0 -102
- package/src/check/source-readers.ts +0 -257
- package/src/check/store-ms.ts +0 -72
- package/src/check/store-names.ts +0 -88
- package/src/check/test-helpers.ts +0 -98
- package/src/check/ttl-names.ts +0 -142
- package/src/compiler/deprecated-ai-labels.ts +0 -97
- package/src/compiler/deprecated-ai-links.ts +0 -63
- package/src/compiler/deprecated-allow.ts +0 -50
- package/src/compiler/deprecated-auth-lints.ts +0 -14
- package/src/compiler/deprecated-auth-signed.ts +0 -29
- package/src/compiler/deprecated-children.ts +0 -66
- package/src/compiler/deprecated-image.ts +0 -116
- package/src/compiler/deprecated-island.ts +0 -155
- package/src/compiler/deprecated-lints-1-105.ts +0 -41
- package/src/compiler/deprecated-page.ts +0 -125
- package/src/compiler/deprecated-parts.ts +0 -22
- package/src/compiler/deprecated-typed-lints.ts +0 -23
- package/src/compiler/deprecated-ui-callbacks.ts +0 -66
- package/src/compiler/deprecated-ui-input.ts +0 -97
- package/src/compiler/deprecated-ui-items.ts +0 -47
- package/src/compiler/old-parts.ts +0 -84
- package/src/runtime/mount.compat.ts +0 -8
- package/src/server/moved-exports.ts +0 -17
- package/types/check/action-readers.d.ts +0 -3
- package/types/check/action-readers.d.ts.map +0 -1
- package/types/check/action-type.d.ts +0 -3
- package/types/check/action-type.d.ts.map +0 -1
- package/types/check/ai-language.d.ts +0 -3
- package/types/check/ai-language.d.ts.map +0 -1
- package/types/check/app-hooks.d.ts +0 -3
- package/types/check/app-hooks.d.ts.map +0 -1
- package/types/check/auth-methods.d.ts +0 -3
- package/types/check/auth-methods.d.ts.map +0 -1
- package/types/check/auth-rate-limits.d.ts +0 -3
- package/types/check/auth-rate-limits.d.ts.map +0 -1
- package/types/check/call-result.d.ts +0 -7
- package/types/check/call-result.d.ts.map +0 -1
- package/types/check/client-keys.d.ts +0 -3
- package/types/check/client-keys.d.ts.map +0 -1
- package/types/check/cms-options.d.ts +0 -3
- package/types/check/cms-options.d.ts.map +0 -1
- package/types/check/config-groups.d.ts +0 -3
- package/types/check/config-groups.d.ts.map +0 -1
- package/types/check/config-switches.d.ts +0 -3
- package/types/check/config-switches.d.ts.map +0 -1
- package/types/check/context-import.d.ts +0 -3
- package/types/check/context-import.d.ts.map +0 -1
- package/types/check/env-files.d.ts +0 -3
- package/types/check/env-files.d.ts.map +0 -1
- package/types/check/format-duration.d.ts +0 -5
- package/types/check/format-duration.d.ts.map +0 -1
- package/types/check/guard-options.d.ts +0 -3
- package/types/check/guard-options.d.ts.map +0 -1
- package/types/check/handler-events.d.ts +0 -9
- package/types/check/handler-events.d.ts.map +0 -1
- package/types/check/hook-context.d.ts +0 -3
- package/types/check/hook-context.d.ts.map +0 -1
- package/types/check/hook-names.d.ts +0 -3
- package/types/check/hook-names.d.ts.map +0 -1
- package/types/check/i18n-keys.d.ts +0 -3
- package/types/check/i18n-keys.d.ts.map +0 -1
- package/types/check/images-keys.d.ts +0 -3
- package/types/check/images-keys.d.ts.map +0 -1
- package/types/check/job-shapes.d.ts +0 -6
- package/types/check/job-shapes.d.ts.map +0 -1
- package/types/check/link-flag-tests.d.ts +0 -4
- package/types/check/link-flag-tests.d.ts.map +0 -1
- package/types/check/live-api.d.ts +0 -3
- package/types/check/live-api.d.ts.map +0 -1
- package/types/check/mail-api.d.ts +0 -3
- package/types/check/mail-api.d.ts.map +0 -1
- package/types/check/one-state-api.d.ts +0 -9
- package/types/check/one-state-api.d.ts.map +0 -1
- package/types/check/pages-options.d.ts +0 -3
- package/types/check/pages-options.d.ts.map +0 -1
- package/types/check/rate-enforce.d.ts +0 -3
- package/types/check/rate-enforce.d.ts.map +0 -1
- package/types/check/refusal-calls.d.ts +0 -3
- package/types/check/refusal-calls.d.ts.map +0 -1
- package/types/check/retired-lints.d.ts +0 -3
- package/types/check/retired-lints.d.ts.map +0 -1
- package/types/check/route-keys.d.ts +0 -3
- package/types/check/route-keys.d.ts.map +0 -1
- package/types/check/secret-keys.d.ts +0 -3
- package/types/check/secret-keys.d.ts.map +0 -1
- package/types/check/socket-frames.d.ts +0 -3
- package/types/check/socket-frames.d.ts.map +0 -1
- package/types/check/source-readers.d.ts +0 -3
- package/types/check/source-readers.d.ts.map +0 -1
- package/types/check/store-ms.d.ts +0 -3
- package/types/check/store-ms.d.ts.map +0 -1
- package/types/check/store-names.d.ts +0 -3
- package/types/check/store-names.d.ts.map +0 -1
- package/types/check/test-helpers.d.ts +0 -3
- package/types/check/test-helpers.d.ts.map +0 -1
- package/types/check/ttl-names.d.ts +0 -3
- package/types/check/ttl-names.d.ts.map +0 -1
- package/types/compiler/deprecated-ai-labels.d.ts +0 -5
- package/types/compiler/deprecated-ai-labels.d.ts.map +0 -1
- package/types/compiler/deprecated-ai-links.d.ts +0 -5
- package/types/compiler/deprecated-ai-links.d.ts.map +0 -1
- package/types/compiler/deprecated-allow.d.ts +0 -5
- package/types/compiler/deprecated-allow.d.ts.map +0 -1
- package/types/compiler/deprecated-auth-lints.d.ts +0 -12
- package/types/compiler/deprecated-auth-lints.d.ts.map +0 -1
- package/types/compiler/deprecated-auth-signed.d.ts +0 -5
- package/types/compiler/deprecated-auth-signed.d.ts.map +0 -1
- package/types/compiler/deprecated-children.d.ts +0 -4
- package/types/compiler/deprecated-children.d.ts.map +0 -1
- package/types/compiler/deprecated-image.d.ts +0 -5
- package/types/compiler/deprecated-image.d.ts.map +0 -1
- package/types/compiler/deprecated-island.d.ts +0 -9
- package/types/compiler/deprecated-island.d.ts.map +0 -1
- package/types/compiler/deprecated-lints-1-105.d.ts +0 -39
- package/types/compiler/deprecated-lints-1-105.d.ts.map +0 -1
- package/types/compiler/deprecated-page.d.ts +0 -4
- package/types/compiler/deprecated-page.d.ts.map +0 -1
- package/types/compiler/deprecated-parts.d.ts +0 -3
- package/types/compiler/deprecated-parts.d.ts.map +0 -1
- package/types/compiler/deprecated-typed-lints.d.ts +0 -21
- package/types/compiler/deprecated-typed-lints.d.ts.map +0 -1
- package/types/compiler/deprecated-ui-callbacks.d.ts +0 -5
- package/types/compiler/deprecated-ui-callbacks.d.ts.map +0 -1
- package/types/compiler/deprecated-ui-input.d.ts +0 -5
- package/types/compiler/deprecated-ui-input.d.ts.map +0 -1
- package/types/compiler/deprecated-ui-items.d.ts +0 -5
- package/types/compiler/deprecated-ui-items.d.ts.map +0 -1
- package/types/compiler/old-parts.d.ts +0 -9
- package/types/compiler/old-parts.d.ts.map +0 -1
- package/types/runtime/mount.compat.d.ts +0 -7
- package/types/runtime/mount.compat.d.ts.map +0 -1
- package/types/server/moved-exports.d.ts +0 -12
- package/types/server/moved-exports.d.ts.map +0 -1
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
import type {
|
|
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 {
|
|
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 {
|
|
11
|
-
import { onStreamEnd, SETTLED } from './action-owner'
|
|
9
|
+
import { onStreamEnd } from './action-owner'
|
|
12
10
|
import { ACTION } from './action-shared'
|
|
13
|
-
import { actionFailed,
|
|
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
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
//
|
|
84
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
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
|
-
|
|
338
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
176
|
+
if (start.undo) {
|
|
177
|
+
start.undo()
|
|
178
|
+
released(start.undo)
|
|
179
|
+
}
|
|
448
180
|
|
|
449
|
-
|
|
450
|
-
called(page, { action: url(), status: error.status, values: {}, errors: error.errors, data: error.data }, turn)
|
|
181
|
+
shift(-1)
|
|
451
182
|
|
|
452
|
-
if (
|
|
453
|
-
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
623
|
-
|
|
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
|
|
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
|
|
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.
|
|
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
|
-
|
|
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 ??
|
|
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 ??
|
|
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 {
|