@kayjs/kay 1.105.0 → 1.107.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/eslint.js +777 -210
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +2 -2
- package/llms/actions-from-islands.md +2 -2
- package/llms/actions-refused-fields.md +22 -0
- package/llms/actions.md +24 -41
- package/llms/analytics.md +1 -1
- package/llms/api-from-islands.md +1 -1
- package/llms/api-routes.md +6 -6
- package/llms/browser-only.md +1 -1
- package/llms/check-and-tools.md +1 -1
- package/llms/code-lints.md +2 -2
- package/llms/compiler-api.md +1 -1
- package/llms/component-libraries.md +1 -0
- package/llms/components.md +1 -1
- package/llms/content-cms.md +1 -1
- package/llms/content-markdown-to-caching.md +1 -1
- package/llms/content-preview.md +2 -2
- package/llms/content.md +21 -21
- package/llms/deprecated-lints-1-105-libraries.md +2 -0
- package/llms/deprecated-lints-1-105.md +3 -3
- package/llms/deprecated-lints.md +4 -4
- package/llms/dev-tool.md +2 -2
- package/llms/environment.md +22 -22
- package/llms/files.md +5 -5
- package/llms/island-and-form-lints.md +1 -0
- package/llms/islands-state-to-ids.md +2 -1
- package/llms/islands.md +10 -1
- package/llms/local-collections.md +2 -2
- package/llms/mcp.md +2 -1
- package/llms/navigation-from-code.md +1 -1
- package/llms/notifications.md +4 -2
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +3 -3
- package/llms/rate-limits.md +1 -1
- package/llms/recipes.md +16 -16
- package/llms/rooms.md +4 -4
- package/llms/routing-endpoints-and-base.md +1 -1
- package/llms/routing.md +5 -5
- package/llms/schemas.md +14 -7
- package/llms/server.md +7 -7
- package/llms/site.md +9 -9
- package/llms/sitemap-search-fonts.md +2 -0
- package/llms/styles-and-assets.md +2 -1
- package/llms/templates-elements-slots-snippets.md +2 -2
- package/llms/testing-browser.md +20 -0
- package/llms/testing.md +1 -1
- package/llms/upgrading-1-105-config.md +2 -2
- package/llms/upgrading.md +37 -4
- package/llms/whats-new-archive.md +35 -66
- package/llms/whats-new.md +47 -28
- package/llms.txt +1 -1
- package/package.json +24 -11
- package/src/add.ts +1 -1
- package/src/build/class-table.ts +2 -2
- package/src/build/client.ts +27 -30
- package/src/build/entry-files.ts +19 -0
- package/src/build/lazy-components.ts +130 -0
- package/src/build/lazy-manifest.ts +56 -0
- package/src/build/lazy-stubs.ts +31 -0
- package/src/build/plugin.ts +16 -11
- package/src/build/runtime-chunk.ts +1 -1
- package/src/build/styles.ts +3 -3
- package/src/build/transform.ts +19 -7
- package/src/build/ui-layers.ts +30 -0
- package/src/build/ui.ts +108 -11
- package/src/build/variants.ts +125 -46
- package/src/build/worker-bundle.ts +6 -0
- package/src/check/action-options.ts +56 -0
- package/src/check/boot.ts +22 -1
- package/src/check/call-result.ts +242 -0
- package/src/check/config-objects.ts +17 -2
- package/src/check/diagnose.ts +22 -0
- package/src/check/handler-events.ts +149 -0
- package/src/check/index.ts +6 -2
- package/src/check/link-flag-tests.ts +130 -0
- package/src/check/project.ts +4 -3
- package/src/check/refusal-calls.ts +2 -2
- package/src/check/regroup.ts +5 -3
- package/src/check/renamed-packages.ts +58 -14
- package/src/check/schema-builders.ts +256 -0
- package/src/check/schema-json.ts +226 -0
- package/src/check/secret-keys.ts +15 -2
- package/src/check/shadow-types.ts +13 -9
- package/src/check/template-hints.ts +1 -1
- package/src/check/tool-labels.ts +11 -9
- package/src/check/ui-types.ts +4 -3
- package/src/check/ui.ts +14 -11
- package/src/commands/env-declare.ts +18 -6
- package/src/commands/routes.ts +1 -1
- package/src/compiler/a11y.ts +8 -1
- package/src/compiler/ast.ts +1 -1
- package/src/compiler/bound-props.ts +1 -1
- package/src/compiler/codegen.ts +13 -23
- package/src/compiler/deprecated-lints-1-105.ts +41 -0
- package/src/compiler/deprecated-lints-1-106.ts +14 -0
- package/src/compiler/deprecated-lints-1-107.ts +14 -0
- package/src/compiler/deprecated-lints.ts +17 -60
- package/src/compiler/deprecated-typed-lints.ts +23 -0
- package/src/compiler/dom-here.ts +72 -0
- package/src/compiler/dom.ts +23 -23
- package/src/compiler/fence-checks.ts +12 -11
- package/src/compiler/field-described.ts +2 -2
- package/src/compiler/helper-imports.ts +1 -1
- package/src/compiler/html-fields.ts +92 -0
- package/src/compiler/html-initial.ts +5 -3
- package/src/compiler/html.ts +14 -31
- package/src/compiler/import-edits.ts +15 -0
- package/src/compiler/index.ts +10 -3
- package/src/compiler/island-declaration.ts +15 -0
- package/src/compiler/items.ts +5 -5
- package/src/compiler/kay-exports.ts +1 -0
- package/src/compiler/lazy-imports.ts +357 -0
- package/src/compiler/link-flags.ts +6 -5
- package/src/compiler/lints.ts +12 -12
- package/src/compiler/parser.ts +2 -2
- package/src/compiler/rest-omits.ts +15 -0
- package/src/compiler/route-lints.ts +2 -0
- package/src/compiler/schema-lints.ts +13 -0
- package/src/compiler/script-server.ts +6 -3
- package/src/config-loader.ts +10 -2
- package/src/config-resolve.ts +3 -1
- package/src/config-shape.ts +2 -2
- package/src/config.ts +20 -4
- package/src/content/markdown.ts +2 -3
- package/src/content/validate.ts +1 -1
- package/src/generate-resource.ts +9 -9
- package/src/generate.ts +1 -1
- package/src/mcp/guards.ts +1 -1
- package/src/mcp/tools.ts +1 -1
- package/src/migrate/content.ts +61 -55
- package/src/new.ts +6 -2
- package/src/runtime/action-shared.ts +2 -2
- package/src/runtime/action.ts +51 -4
- package/src/runtime/client.ts +10 -0
- package/src/runtime/dom-lazy.ts +276 -0
- package/src/runtime/field-errors.ts +58 -0
- package/src/runtime/field-refusal.ts +179 -0
- package/src/runtime/form-types.ts +99 -0
- package/src/runtime/form.ts +25 -9
- package/src/runtime/html.ts +42 -6
- package/src/runtime/index.ts +2 -0
- package/src/runtime/island.server.ts +36 -2
- package/src/runtime/markdown-autolink.ts +69 -0
- package/src/runtime/markdown-render.client.ts +39 -3
- package/src/runtime/markdown.client.ts +6 -3
- package/src/runtime/markdown.server.ts +6 -3
- package/src/runtime/markdown.ts +125 -1
- package/src/runtime/navigate-api.ts +10 -5
- package/src/runtime/persist.ts +7 -7
- package/src/runtime/query-param.ts +1 -1
- package/src/runtime/reactive.ts +14 -0
- package/src/runtime/sanitize.ts +3 -1
- package/src/runtime/schema-record.ts +32 -0
- package/src/runtime/schema.client.ts +101 -14
- package/src/runtime/schema.ts +328 -26
- package/src/runtime/standard-schema.ts +32 -0
- package/src/runtime/swap-focus.ts +59 -11
- package/src/runtime/validate-run.client.ts +179 -0
- package/src/runtime/validate.client.ts +11 -0
- package/src/runtime/validate.ts +4 -137
- package/src/server/action-module.ts +16 -0
- package/src/server/actions.ts +54 -57
- package/src/server/answer.ts +102 -0
- package/src/server/api-input.ts +166 -0
- package/src/server/api-modules.ts +1 -1
- package/src/server/api.ts +12 -32
- package/src/server/app-stages.ts +38 -26
- package/src/server/app.ts +5 -2
- package/src/server/client.ts +2 -0
- package/src/server/dev-ui.ts +2 -2
- package/src/server/dev.ts +7 -9
- package/src/server/env-state.ts +1 -1
- package/src/server/env.ts +11 -3
- package/src/server/favicon.ts +47 -1
- package/src/server/file-limit.ts +7 -1
- package/src/server/forms.ts +1 -1
- package/src/server/host-allowlist.ts +7 -7
- package/src/server/image-metadata-bmff.ts +1 -1
- package/src/server/index.ts +2 -0
- package/src/server/kay-routes.ts +221 -0
- package/src/server/kay-server.ts +228 -0
- package/src/server/kept-exports.ts +1 -0
- package/src/server/kept-pages.ts +3 -3
- package/src/server/library.ts +2 -2
- package/src/server/mcp.ts +14 -13
- package/src/server/notifications.ts +4 -2
- package/src/server/offline.ts +24 -7
- package/src/server/openapi.ts +12 -3
- package/src/server/phases.ts +249 -0
- package/src/server/protection.ts +6 -6
- package/src/server/proxy-key.ts +8 -8
- package/src/server/push-settings.ts +16 -2
- package/src/server/push.ts +12 -4
- package/src/server/query.ts +17 -31
- package/src/server/receive.ts +43 -0
- package/src/server/render-document.ts +13 -3
- package/src/server/render.ts +1 -1
- package/src/server/request-context.ts +137 -0
- package/src/server/schema-check.ts +1 -1
- package/src/server/scope.ts +20 -13
- package/src/server/signals.ts +4 -4
- package/src/server/socket.ts +19 -47
- package/src/server/stream.ts +1 -1
- package/src/server/validate.ts +346 -0
- package/src/template-ws.ts +1 -1
- package/src/test/a11y-dom.ts +70 -0
- package/src/test/html-snapshot.ts +103 -0
- package/src/test/index.ts +2 -1
- package/src/test/mount.ts +14 -3
- package/src/test/page-checks.ts +12 -0
- package/src/test/screenshot-match.ts +2 -2
- package/src/test/shared-modules.ts +27 -5
- package/src/test/site-types.ts +5 -1
- package/types/build/class-table.d.ts +1 -1
- package/types/build/class-table.d.ts.map +1 -1
- package/types/build/client.d.ts +3 -2
- package/types/build/client.d.ts.map +1 -1
- package/types/build/entry-files.d.ts +4 -0
- package/types/build/entry-files.d.ts.map +1 -0
- package/types/build/lazy-components.d.ts +6 -0
- package/types/build/lazy-components.d.ts.map +1 -0
- package/types/build/lazy-manifest.d.ts +19 -0
- package/types/build/lazy-manifest.d.ts.map +1 -0
- package/types/build/lazy-stubs.d.ts +5 -0
- package/types/build/lazy-stubs.d.ts.map +1 -0
- package/types/build/plugin.d.ts +1 -0
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/transform.d.ts +4 -1
- package/types/build/transform.d.ts.map +1 -1
- package/types/build/ui-layers.d.ts +5 -0
- package/types/build/ui-layers.d.ts.map +1 -0
- package/types/build/ui.d.ts +7 -0
- package/types/build/ui.d.ts.map +1 -1
- package/types/build/variants.d.ts +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/build/worker-bundle.d.ts +1 -0
- package/types/build/worker-bundle.d.ts.map +1 -1
- package/types/check/action-options.d.ts +3 -0
- package/types/check/action-options.d.ts.map +1 -0
- package/types/check/boot.d.ts.map +1 -1
- package/types/check/call-result.d.ts +7 -0
- package/types/check/call-result.d.ts.map +1 -0
- package/types/check/config-objects.d.ts.map +1 -1
- package/types/check/diagnose.d.ts.map +1 -1
- package/types/check/handler-events.d.ts +9 -0
- package/types/check/handler-events.d.ts.map +1 -0
- package/types/check/index.d.ts +1 -0
- package/types/check/index.d.ts.map +1 -1
- package/types/check/link-flag-tests.d.ts +4 -0
- package/types/check/link-flag-tests.d.ts.map +1 -0
- package/types/check/project.d.ts.map +1 -1
- package/types/check/regroup.d.ts +1 -1
- package/types/check/regroup.d.ts.map +1 -1
- package/types/check/renamed-packages.d.ts +1 -0
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/schema-builders.d.ts +3 -0
- package/types/check/schema-builders.d.ts.map +1 -0
- package/types/check/schema-json.d.ts +3 -0
- package/types/check/schema-json.d.ts.map +1 -0
- package/types/check/secret-keys.d.ts.map +1 -1
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/check/template-hints.d.ts +1 -0
- package/types/check/template-hints.d.ts.map +1 -1
- package/types/check/tool-labels.d.ts.map +1 -1
- package/types/check/ui-types.d.ts.map +1 -1
- package/types/check/ui.d.ts.map +1 -1
- package/types/commands/env-declare.d.ts.map +1 -1
- package/types/compiler/a11y.d.ts.map +1 -1
- package/types/compiler/bound-props.d.ts +1 -0
- package/types/compiler/bound-props.d.ts.map +1 -1
- package/types/compiler/codegen.d.ts +3 -0
- package/types/compiler/codegen.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-105.d.ts +39 -0
- package/types/compiler/deprecated-lints-1-105.d.ts.map +1 -0
- package/types/compiler/deprecated-lints-1-106.d.ts +12 -0
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -0
- package/types/compiler/deprecated-lints-1-107.d.ts +12 -0
- package/types/compiler/deprecated-lints-1-107.d.ts.map +1 -0
- package/types/compiler/deprecated-lints.d.ts +41 -22
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/deprecated-typed-lints.d.ts +21 -0
- package/types/compiler/deprecated-typed-lints.d.ts.map +1 -0
- package/types/compiler/dom-here.d.ts +14 -0
- package/types/compiler/dom-here.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/fence-checks.d.ts.map +1 -1
- package/types/compiler/field-described.d.ts +1 -1
- package/types/compiler/field-described.d.ts.map +1 -1
- package/types/compiler/html-fields.d.ts +19 -0
- package/types/compiler/html-fields.d.ts.map +1 -0
- package/types/compiler/html-initial.d.ts +3 -2
- package/types/compiler/html-initial.d.ts.map +1 -1
- package/types/compiler/html.d.ts.map +1 -1
- package/types/compiler/import-edits.d.ts +1 -0
- package/types/compiler/import-edits.d.ts.map +1 -1
- package/types/compiler/index.d.ts +3 -0
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-declaration.d.ts +5 -0
- package/types/compiler/island-declaration.d.ts.map +1 -1
- package/types/compiler/items.d.ts +4 -1
- package/types/compiler/items.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/lazy-imports.d.ts +33 -0
- package/types/compiler/lazy-imports.d.ts.map +1 -0
- package/types/compiler/link-flags.d.ts +6 -0
- package/types/compiler/link-flags.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +61 -34
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/rest-omits.d.ts +4 -0
- package/types/compiler/rest-omits.d.ts.map +1 -0
- package/types/compiler/route-lints.d.ts +8 -0
- package/types/compiler/route-lints.d.ts.map +1 -1
- package/types/compiler/schema-lints.d.ts +11 -0
- package/types/compiler/schema-lints.d.ts.map +1 -0
- package/types/compiler/script-server.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.d.ts +15 -2
- package/types/config.d.ts.map +1 -1
- package/types/content/markdown.d.ts.map +1 -1
- package/types/migrate/content.d.ts.map +1 -1
- package/types/new.d.ts +1 -0
- package/types/new.d.ts.map +1 -1
- package/types/runtime/action-shared.d.ts +1 -1
- package/types/runtime/action-shared.d.ts.map +1 -1
- package/types/runtime/action.d.ts +29 -1
- package/types/runtime/action.d.ts.map +1 -1
- package/types/runtime/client.d.ts.map +1 -1
- package/types/runtime/dom-lazy.d.ts +6 -0
- package/types/runtime/dom-lazy.d.ts.map +1 -0
- package/types/runtime/field-errors.d.ts +4 -0
- package/types/runtime/field-errors.d.ts.map +1 -0
- package/types/runtime/field-refusal.d.ts +37 -0
- package/types/runtime/field-refusal.d.ts.map +1 -0
- package/types/runtime/form-types.d.ts +6 -0
- package/types/runtime/form-types.d.ts.map +1 -0
- package/types/runtime/form.d.ts +4 -2
- package/types/runtime/form.d.ts.map +1 -1
- package/types/runtime/html.d.ts +3 -0
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -0
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +2 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/markdown-autolink.d.ts +11 -0
- package/types/runtime/markdown-autolink.d.ts.map +1 -0
- package/types/runtime/markdown-render.client.d.ts +2 -1
- package/types/runtime/markdown-render.client.d.ts.map +1 -1
- package/types/runtime/markdown.client.d.ts +3 -1
- package/types/runtime/markdown.client.d.ts.map +1 -1
- package/types/runtime/markdown.d.ts +11 -0
- package/types/runtime/markdown.d.ts.map +1 -1
- package/types/runtime/markdown.server.d.ts +3 -1
- package/types/runtime/markdown.server.d.ts.map +1 -1
- package/types/runtime/navigate-api.d.ts +1 -1
- package/types/runtime/navigate-api.d.ts.map +1 -1
- package/types/runtime/persist.d.ts +2 -2
- package/types/runtime/persist.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +3 -0
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/sanitize.d.ts.map +1 -1
- package/types/runtime/schema-record.d.ts +9 -0
- package/types/runtime/schema-record.d.ts.map +1 -0
- package/types/runtime/schema.client.d.ts.map +1 -1
- package/types/runtime/schema.d.ts +99 -10
- package/types/runtime/schema.d.ts.map +1 -1
- package/types/runtime/standard-schema.d.ts +37 -0
- package/types/runtime/standard-schema.d.ts.map +1 -0
- package/types/runtime/swap-focus.d.ts.map +1 -1
- package/types/runtime/validate-run.client.d.ts +4 -0
- package/types/runtime/validate-run.client.d.ts.map +1 -0
- package/types/runtime/validate.client.d.ts +4 -0
- package/types/runtime/validate.client.d.ts.map +1 -0
- package/types/runtime/validate.d.ts +1 -21
- package/types/runtime/validate.d.ts.map +1 -1
- package/types/server/action-module.d.ts +2 -0
- package/types/server/action-module.d.ts.map +1 -0
- package/types/server/actions.d.ts +1 -0
- package/types/server/actions.d.ts.map +1 -1
- package/types/server/answer.d.ts +6 -0
- package/types/server/answer.d.ts.map +1 -0
- package/types/server/api-input.d.ts +19 -0
- package/types/server/api-input.d.ts.map +1 -0
- package/types/server/api.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +7 -3
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +2 -0
- package/types/server/app.d.ts.map +1 -1
- package/types/server/client.d.ts +1 -0
- package/types/server/client.d.ts.map +1 -1
- package/types/server/dev.d.ts +1 -1
- package/types/server/dev.d.ts.map +1 -1
- package/types/server/env-state.d.ts.map +1 -1
- package/types/server/env.d.ts +5 -1
- package/types/server/env.d.ts.map +1 -1
- package/types/server/favicon.d.ts +3 -1
- package/types/server/favicon.d.ts.map +1 -1
- package/types/server/file-limit.d.ts.map +1 -1
- package/types/server/host-allowlist.d.ts +3 -3
- package/types/server/host-allowlist.d.ts.map +1 -1
- package/types/server/index.d.ts +2 -0
- package/types/server/index.d.ts.map +1 -1
- package/types/server/kay-routes.d.ts +47 -0
- package/types/server/kay-routes.d.ts.map +1 -0
- package/types/server/kay-server.d.ts +25 -0
- package/types/server/kay-server.d.ts.map +1 -0
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/kept-pages.d.ts +1 -1
- package/types/server/kept-pages.d.ts.map +1 -1
- package/types/server/library.d.ts +2 -1
- package/types/server/library.d.ts.map +1 -1
- package/types/server/mcp.d.ts +1 -1
- package/types/server/mcp.d.ts.map +1 -1
- package/types/server/notifications.d.ts +2 -1
- package/types/server/notifications.d.ts.map +1 -1
- package/types/server/offline.d.ts.map +1 -1
- package/types/server/openapi.d.ts.map +1 -1
- package/types/server/phases.d.ts +36 -0
- package/types/server/phases.d.ts.map +1 -0
- package/types/server/protection.d.ts +3 -2
- package/types/server/protection.d.ts.map +1 -1
- package/types/server/proxy-key.d.ts +3 -3
- package/types/server/proxy-key.d.ts.map +1 -1
- package/types/server/push-settings.d.ts +1 -1
- package/types/server/push-settings.d.ts.map +1 -1
- package/types/server/push.d.ts +1 -0
- package/types/server/push.d.ts.map +1 -1
- package/types/server/query.d.ts.map +1 -1
- package/types/server/receive.d.ts +9 -0
- package/types/server/receive.d.ts.map +1 -0
- package/types/server/render-document.d.ts.map +1 -1
- package/types/server/request-context.d.ts +29 -0
- package/types/server/request-context.d.ts.map +1 -0
- package/types/server/schema-check.d.ts +1 -0
- package/types/server/schema-check.d.ts.map +1 -1
- package/types/server/scope.d.ts +1 -1
- package/types/server/scope.d.ts.map +1 -1
- package/types/server/socket.d.ts +3 -5
- package/types/server/socket.d.ts.map +1 -1
- package/types/server/validate.d.ts +26 -0
- package/types/server/validate.d.ts.map +1 -0
- package/types/test/a11y-dom.d.ts +20 -0
- package/types/test/a11y-dom.d.ts.map +1 -0
- package/types/test/html-snapshot.d.ts +4 -0
- package/types/test/html-snapshot.d.ts.map +1 -0
- package/types/test/index.d.ts.map +1 -1
- package/types/test/mount.d.ts +3 -0
- package/types/test/mount.d.ts.map +1 -1
- package/types/test/page-checks.d.ts +6 -0
- package/types/test/page-checks.d.ts.map +1 -0
- package/types/test/screenshot-match.d.ts +1 -1
- package/types/test/screenshot-match.d.ts.map +1 -1
- package/types/test/shared-modules.d.ts.map +1 -1
- package/types/test/site-types.d.ts +3 -1
- package/types/test/site-types.d.ts.map +1 -1
- package/src/check/schema-type.ts +0 -9
- package/src/compiler/deprecated-script-fence.ts +0 -26
- package/src/server/field-errors.ts +0 -136
- package/types/check/schema-type.d.ts +0 -3
- package/types/check/schema-type.d.ts.map +0 -1
- package/types/compiler/deprecated-script-fence.d.ts +0 -3
- package/types/compiler/deprecated-script-fence.d.ts.map +0 -1
- package/types/server/field-errors.d.ts +0 -6
- package/types/server/field-errors.d.ts.map +0 -1
package/src/runtime/schema.ts
CHANGED
|
@@ -1,30 +1,177 @@
|
|
|
1
1
|
import type { TSchema, Static as TypeBoxStatic } from 'elysia'
|
|
2
2
|
import type { ByteSize } from './byte-size'
|
|
3
|
+
import type { StandardOutput, StandardSchema } from './standard-schema'
|
|
3
4
|
import { t as schema } from 'elysia'
|
|
4
5
|
import { FormatRegistry } from 'elysia/type-system'
|
|
5
6
|
import { byteSize } from './byte-size'
|
|
6
7
|
import { isEmail } from './email'
|
|
7
8
|
import { KayError } from './kay-error'
|
|
9
|
+
import { DEFAULT_MAX_LENGTH } from './schema-bounds'
|
|
8
10
|
|
|
9
11
|
type Builder = typeof schema
|
|
10
12
|
|
|
11
|
-
// What `s` builds and every API taking a schema accepts: an action's input, an env, a collection, an API route's `query`. In kay 1.x it is
|
|
13
|
+
// What `s` builds and every API taking a schema accepts: an action's input, an env, a collection, an API route's `query`. In kay 1.x it is a TypeBox schema, so a `t.Object(...)` of Elysia is one too; neither is part of kay's stable API.
|
|
12
14
|
export interface Schema extends TSchema {}
|
|
13
15
|
|
|
14
|
-
// The value a schema describes.
|
|
16
|
+
// The value a schema describes. Kept as `Static`, the name an app already reads it by, since a second name would only duplicate it.
|
|
15
17
|
export type Static<Type extends Schema, Params extends unknown[] = []> = TypeBoxStatic<Type, Params>
|
|
16
18
|
|
|
19
|
+
// A Standard Schema validator (Zod, ArkType, Valibot) typed as a schema whose value is the validator's output, which is what `Static` reads of one.
|
|
20
|
+
export type StandardAs<Validator extends StandardSchema> = Schema & { static: StandardOutput<Validator> }
|
|
21
|
+
|
|
17
22
|
// The `email` format is kay's own check, the one the browser, auth and mail share, in place of Elysia's.
|
|
18
23
|
FormatRegistry.Set('email', isEmail)
|
|
24
|
+
FormatRegistry.Set('url', isUrl)
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
const HTTP_URL = /^https?:/i
|
|
27
|
+
|
|
28
|
+
// `new URL` in a try, as URL.canParse is past the browsers kay supports (Safari 17).
|
|
29
|
+
function isUrl(value: string): boolean {
|
|
30
|
+
if (!HTTP_URL.test(value))
|
|
31
|
+
return false
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
void new URL(value)
|
|
35
|
+
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
23
41
|
}
|
|
24
42
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
43
|
+
// The most items a list takes when its builder is given no `max`.
|
|
44
|
+
export const DEFAULT_MAX_ITEMS = 1000
|
|
45
|
+
|
|
46
|
+
const SLUG = '^[a-z0-9]+(?:-[a-z0-9]+)*$'
|
|
47
|
+
|
|
48
|
+
// The words of a refusal: a text, a function called in the request's locale, or a record by the rule that failed (`min`, `max`, `pattern`, `format`, `required`, `type`), with a `default` for the others.
|
|
49
|
+
export type ErrorText = string | (() => string) | Record<string, string | (() => string) | undefined>
|
|
50
|
+
|
|
51
|
+
// What every builder takes beside its own options: the field is `optional`, takes a `default` when the value is left out, words its refusal with `error` (a text or a function called in the request's locale), and carries a `label`, a `description` and an `example` for the form, OpenAPI and MCP.
|
|
52
|
+
export interface FieldBase<Value = unknown> {
|
|
53
|
+
optional?: boolean | undefined
|
|
54
|
+
default?: Value | undefined
|
|
55
|
+
error?: ErrorText | undefined
|
|
56
|
+
label?: string | undefined
|
|
57
|
+
description?: string | undefined
|
|
58
|
+
example?: Value | undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Any other JSON Schema keyword, `format` or `x-privacy`, goes through to the schema as it is.
|
|
62
|
+
export type FieldOptions<Value = unknown> = FieldBase<Value> & Record<string, unknown>
|
|
63
|
+
|
|
64
|
+
interface Flagged { optional?: boolean | undefined }
|
|
65
|
+
|
|
66
|
+
// A field is optional in the shape that holds it when its options say `optional: true`.
|
|
67
|
+
const optionalOf = <Field extends TSchema>(field: Field) => schema.Optional(field)
|
|
68
|
+
|
|
69
|
+
type Wrapped<Field extends Schema, Options> = Options extends { optional: true } ? ReturnType<typeof optionalOf<Field>> : Field
|
|
70
|
+
|
|
71
|
+
// The TypeBox keywords a field option stands for, left alone when it is not given.
|
|
72
|
+
function keywords(options: FieldOptions): Record<string, unknown> {
|
|
73
|
+
const { default: fallback, error, label, description, example } = options
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
...fallback !== undefined && { default: fallback },
|
|
77
|
+
...error !== undefined && { error },
|
|
78
|
+
...label !== undefined && { title: label },
|
|
79
|
+
...description !== undefined && { description },
|
|
80
|
+
...example !== undefined && { examples: [example] },
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function wrapped<Field extends Schema, Options extends Flagged>(field: Field, options: Options | undefined): Wrapped<Field, Options> {
|
|
85
|
+
return (options?.optional === true ? optionalOf(field) : field) as Wrapped<Field, Options>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// The options of a builder without the field options, which `keywords` has turned into TypeBox's.
|
|
89
|
+
function rest<Options extends object>(options: Options | undefined, own: readonly string[]): Record<string, unknown> {
|
|
90
|
+
return Object.fromEntries(Object.entries(options ?? {}).filter(([key]) => !own.includes(key)))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const FIELD_KEYS = ['optional', 'default', 'error', 'label', 'description', 'example'] as const
|
|
94
|
+
|
|
95
|
+
// What `s.email()`, `s.url()` and `s.slug()` take: their own format is theirs, so no pattern, no format and no other keyword.
|
|
96
|
+
export interface FormatOptions extends FieldBase<string> {
|
|
97
|
+
min?: number | undefined
|
|
98
|
+
max?: number | undefined
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface StringOptions extends FieldOptions<string> {
|
|
102
|
+
min?: number | undefined
|
|
103
|
+
max?: number | undefined
|
|
104
|
+
pattern?: RegExp | string | undefined
|
|
105
|
+
// A format TypeBox knows, such as `'uuid'`; `s.email()`, `s.url()` and `s.slug()` set theirs.
|
|
106
|
+
format?: string | undefined
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function stringOf(options: StringOptions | undefined, extra: Record<string, unknown> = {}): ReturnType<Builder['String']> {
|
|
110
|
+
const pattern = options?.pattern instanceof RegExp ? options.pattern.source : options?.pattern
|
|
111
|
+
|
|
112
|
+
return schema.String({
|
|
113
|
+
...rest(options, [...FIELD_KEYS, 'min', 'max', 'pattern']),
|
|
114
|
+
...keywords(options ?? {}),
|
|
115
|
+
...extra,
|
|
116
|
+
...options?.min !== undefined && { minLength: options.min },
|
|
117
|
+
maxLength: options?.max ?? (typeof options?.maxLength === 'number' ? options.maxLength : DEFAULT_MAX_LENGTH),
|
|
118
|
+
...pattern !== undefined && { pattern },
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type Built<Field extends Schema, Options> = Wrapped<Field, Options>
|
|
123
|
+
|
|
124
|
+
// A text, at most `max` characters long (10,000 when not given), `min` at least, matching `pattern`.
|
|
125
|
+
function string<const Options extends StringOptions>(options?: Options): Built<ReturnType<Builder['String']>, Options> {
|
|
126
|
+
return wrapped(stringOf(options), options)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// An address `isEmail` accepts, the check the browser, auth and mail share, at most 254 characters long.
|
|
130
|
+
function email<const Options extends FormatOptions>(options?: Options): Built<ReturnType<Builder['String']>, Options> {
|
|
131
|
+
return wrapped(stringOf({ max: 254, ...options }, { format: 'email' }), options)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// An `http:` or `https:` address.
|
|
135
|
+
function url<const Options extends FormatOptions>(options?: Options): Built<ReturnType<Builder['String']>, Options> {
|
|
136
|
+
return wrapped(stringOf({ max: 2048, ...options }, { format: 'url' }), options)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Lowercase words and digits joined by single hyphens.
|
|
140
|
+
function slug<const Options extends FormatOptions>(options?: Options): Built<ReturnType<Builder['String']>, Options> {
|
|
141
|
+
return wrapped(stringOf({ max: 200, ...options, pattern: SLUG }), options)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface NumberOptions extends FieldOptions<number> {
|
|
145
|
+
min?: number | undefined
|
|
146
|
+
max?: number | undefined
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function bounds(options: NumberOptions | undefined): Record<string, unknown> {
|
|
150
|
+
return {
|
|
151
|
+
...rest(options, [...FIELD_KEYS, 'min', 'max']),
|
|
152
|
+
...keywords(options ?? {}),
|
|
153
|
+
...options?.min !== undefined && { minimum: options.min },
|
|
154
|
+
...options?.max !== undefined && { maximum: options.max },
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// A whole number. A form, a query, a param or an env value arrives as text, which the text types of Elysia read as the number it spells.
|
|
159
|
+
function int<const Options extends NumberOptions>(options?: Options): Built<ReturnType<Builder['Integer']>, Options> {
|
|
160
|
+
return wrapped(schema.Integer(bounds(options)), options)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// A finite number.
|
|
164
|
+
function number<const Options extends NumberOptions>(options?: Options): Built<ReturnType<Builder['Numeric']>, Options> {
|
|
165
|
+
return wrapped(schema.Numeric(bounds(options)), options)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function boolean<const Options extends FieldOptions<boolean>>(options?: Options): Built<ReturnType<Builder['BooleanString']>, Options> {
|
|
169
|
+
return wrapped(schema.BooleanString({ ...rest(options, FIELD_KEYS), ...keywords(options ?? {}) }), options)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// A `Date`, read from the text or the number of one as Elysia's `Date` does, until `validate()` reads dates alone.
|
|
173
|
+
function date<const Options extends FieldOptions<Date>>(options?: Options): Built<ReturnType<Builder['Date']>, Options> {
|
|
174
|
+
return wrapped(schema.Date({ ...rest(options, FIELD_KEYS), ...keywords(options ?? {}) }), options)
|
|
28
175
|
}
|
|
29
176
|
|
|
30
177
|
// Elysia's `UnionEnum` fills the first value in as `default`, so an optional field read as that value when left out and a required one was never refused; kay leaves `default` out unless the options give one.
|
|
@@ -37,36 +184,191 @@ const UnionEnum: Builder['UnionEnum'] = (values, options) => {
|
|
|
37
184
|
return field
|
|
38
185
|
}
|
|
39
186
|
|
|
40
|
-
|
|
41
|
-
function UnionKeys<const Keyed extends object>(record: Keyed, options?: Parameters<Builder['UnionEnum']>[1]): ReturnType<typeof schema.UnionEnum<[keyof Keyed & string, ...(keyof Keyed & string)[]]>> {
|
|
42
|
-
const keys = Object.keys(record)
|
|
187
|
+
type EnumValue = string | number
|
|
43
188
|
|
|
44
|
-
|
|
45
|
-
throw new KayError('argument-invalid', 'kay: s.UnionKeys() takes a record with at least one key')
|
|
189
|
+
type EnumValues = readonly [EnumValue, ...EnumValue[]]
|
|
46
190
|
|
|
47
|
-
|
|
191
|
+
// One of the values, or of a record's keys, as `select` draws its options from a record of labels.
|
|
192
|
+
function enumeration<const Values extends EnumValues, const Options extends FieldOptions<Values[number]> = FieldOptions<Values[number]>>(values: Values, options?: Options): Built<ReturnType<typeof schema.UnionEnum<Values>>, Options>
|
|
193
|
+
function enumeration<const Keyed extends object, const Options extends FieldOptions<keyof Keyed & string> = FieldOptions<keyof Keyed & string>>(record: Keyed, options?: Options): Built<ReturnType<typeof schema.UnionEnum<[keyof Keyed & string, ...(keyof Keyed & string)[]]>>, Options>
|
|
194
|
+
|
|
195
|
+
function enumeration(source: EnumValues | object, options?: FieldOptions): Schema {
|
|
196
|
+
const values = Array.isArray(source) ? source as unknown as EnumValues : Object.keys(source)
|
|
197
|
+
|
|
198
|
+
if (values.length === 0)
|
|
199
|
+
throw new KayError('argument-invalid', 'kay: s.enum() takes at least one value, or a record with at least one key')
|
|
200
|
+
|
|
201
|
+
// The texts of a record word the options of a `select(field=...)`.
|
|
202
|
+
const texts = Array.isArray(source) ? [] : Object.entries(source).filter(([, text]) => typeof text === 'string')
|
|
203
|
+
const labels = texts.length === 0 ? {} : { 'x-labels': Object.fromEntries(texts) }
|
|
204
|
+
|
|
205
|
+
return wrapped(UnionEnum(values as unknown as EnumValues, { ...rest(options, FIELD_KEYS), ...keywords(options ?? {}), ...labels }), options)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function literal<const Value extends string | number | boolean, const Options extends FieldOptions<Value>>(value: Value, options?: Options): Built<ReturnType<typeof schema.Literal<Value>>, Options> {
|
|
209
|
+
return wrapped(schema.Literal(value, { ...rest(options, FIELD_KEYS), ...keywords(options ?? {}) }), options)
|
|
48
210
|
}
|
|
49
211
|
|
|
50
|
-
|
|
51
|
-
|
|
212
|
+
function union<const Members extends readonly [Schema, Schema, ...Schema[]], const Options extends FieldOptions>(members: Members, options?: Options): Built<ReturnType<typeof schema.Union<[...Members]>>, Options> {
|
|
213
|
+
return wrapped(schema.Union([...members], { ...rest(options, FIELD_KEYS), ...keywords(options ?? {}) }), options) as never
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface ObjectOptions extends FieldOptions {
|
|
217
|
+
// What an object does with a key its shape lacks: `'refuse'` (the default) answers 422, `'strip'` drops it.
|
|
218
|
+
extra?: 'refuse' | 'strip' | undefined
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// The fields of an object, `shape` a record of schemas, which is refused with a 422 when it carries a key the shape lacks; `{ extra: 'strip' }` drops it instead. Anywhere kay takes a schema, a plain record is this object, so `s.object()` is rarely written.
|
|
222
|
+
function object<Shape extends Record<string, Schema>, const Options extends ObjectOptions>(shape: Shape, options?: Options): Built<ReturnType<typeof schema.Object<Shape>>, Options> {
|
|
223
|
+
return wrapped(schema.Object(shape, { ...options?.extra === 'strip' ? { 'x-kay-extra': 'strip' } : { additionalProperties: false }, ...rest(options, [...FIELD_KEYS, 'extra']), ...keywords(options ?? {}) }), options)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// An object of any keys, each holding `value`.
|
|
227
|
+
function record<Value extends Schema, const Options extends FieldOptions>(value: Value, options?: Options): Built<ReturnType<typeof schema.Record<ReturnType<Builder['String']>, Value>>, Options> {
|
|
228
|
+
return wrapped(schema.Record(schema.String({ maxLength: 200 }), value, { ...rest(options, FIELD_KEYS), ...keywords(options ?? {}) }), options)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface ListOptions extends FieldOptions<unknown[]> {
|
|
232
|
+
min?: number | undefined
|
|
233
|
+
max?: number | undefined
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// A list of files is bounded by `max` alone, as the body limit of an upload reads it, so a list of any other item is the one capped at 1,000.
|
|
237
|
+
function maxItemsOf(item: Schema, options: ListOptions | undefined): Record<string, unknown> {
|
|
238
|
+
const max = options?.max ?? (typeof options?.maxItems === 'number' ? options.maxItems : undefined)
|
|
239
|
+
|
|
240
|
+
if (max !== undefined)
|
|
241
|
+
return { maxItems: max }
|
|
242
|
+
|
|
243
|
+
return (item as { format?: unknown }).format === 'binary' ? {} : { maxItems: DEFAULT_MAX_ITEMS }
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// A list of `item`, at most `max` long (1,000 when not given).
|
|
247
|
+
function list<Item extends Schema, const Options extends ListOptions>(item: Item, options?: Options): Built<ReturnType<typeof schema.Array<Item>>, Options> {
|
|
248
|
+
return wrapped(schema.Array(item, {
|
|
249
|
+
...rest(options, [...FIELD_KEYS, 'min', 'max']),
|
|
250
|
+
...keywords(options ?? {}),
|
|
251
|
+
...options?.min !== undefined && { minItems: options.min },
|
|
252
|
+
...maxItemsOf(item, options),
|
|
253
|
+
}), options)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface FileOptions extends FieldOptions<never> {
|
|
257
|
+
// The media type the file must have, `'application/pdf'`, or a family such as `'image/*'`, or a list of them.
|
|
258
|
+
type?: string | string[] | undefined
|
|
259
|
+
minSize?: ByteSize | undefined
|
|
260
|
+
maxSize?: ByteSize | undefined
|
|
261
|
+
}
|
|
52
262
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
263
|
+
export interface FilesOptions extends FileOptions {
|
|
264
|
+
min?: number | undefined
|
|
265
|
+
max?: number | undefined
|
|
266
|
+
}
|
|
57
267
|
|
|
58
|
-
|
|
268
|
+
// The sizes of a file field are read as the action's `maxSize` is: `'2mb'`, `'600kb'` or bytes, handed to Elysia as bytes.
|
|
269
|
+
function sized(options: FileOptions | undefined, name: string): Record<string, unknown> {
|
|
270
|
+
const { minSize, maxSize } = options ?? {}
|
|
59
271
|
|
|
60
272
|
return {
|
|
61
|
-
...rest,
|
|
273
|
+
...rest(options, [...FIELD_KEYS, 'minSize', 'maxSize']),
|
|
274
|
+
...keywords(options ?? {}),
|
|
62
275
|
...minSize !== undefined && { minSize: byteSize(minSize, `${name}({ minSize })`) },
|
|
63
276
|
...maxSize !== undefined && { maxSize: byteSize(maxSize, `${name}({ maxSize })`) },
|
|
64
277
|
}
|
|
65
278
|
}
|
|
66
279
|
|
|
67
|
-
const
|
|
68
|
-
|
|
280
|
+
function file<const Options extends FileOptions>(options?: Options): Built<ReturnType<Builder['File']>, Options> {
|
|
281
|
+
return wrapped(schema.File(sized(options, 's.file') as never), options)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function files<const Options extends FilesOptions>(options?: Options): Built<ReturnType<Builder['Files']>, Options> {
|
|
285
|
+
const { min, max } = options ?? {}
|
|
286
|
+
|
|
287
|
+
return wrapped(schema.Files({ ...sized(options, 's.files'), ...min !== undefined && { minItems: min }, ...max !== undefined && { maxItems: max } }), options)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// A string of at least 32 characters that production must set, and development and tests derive from the project path, so a secret needs no placeholder in the app: read it with `defineEnv`.
|
|
291
|
+
function secret<const Options extends StringOptions>(options?: Options): Built<ReturnType<Builder['String']>, Options> {
|
|
292
|
+
return wrapped(stringOf({ ...options, min: Math.max(32, options?.min ?? 0) }, { requiredInProduction: true, secret: true }), options)
|
|
293
|
+
}
|
|
69
294
|
|
|
70
|
-
//
|
|
295
|
+
// A field of `defineEnv` an island may read, as `publicEnv` from `kay`, such as a map key or an analytics id; a name such as `STRIPE_SECRET` or `DATABASE_URL` is refused at boot, since every visitor reads it.
|
|
296
|
+
function publicField<Field extends Schema>(field: Field): Field & { public: true } {
|
|
297
|
+
return { ...field, public: true }
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// A `UnionEnum` of a record's keys, typed as their union, for a `select` whose options come from a record of labels.
|
|
301
|
+
function UnionKeys<const Keyed extends object>(record: Keyed, options?: Parameters<Builder['UnionEnum']>[1]): ReturnType<typeof schema.UnionEnum<[keyof Keyed & string, ...(keyof Keyed & string)[]]>> {
|
|
302
|
+
const keys = Object.keys(record)
|
|
303
|
+
|
|
304
|
+
if (keys.length === 0)
|
|
305
|
+
throw new KayError('argument-invalid', 'kay: s.UnionKeys() takes a record with at least one key')
|
|
306
|
+
|
|
307
|
+
return UnionEnum(keys as [keyof Keyed & string, ...(keyof Keyed & string)[]], options)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function Secret(options: Parameters<Builder['String']>[0] = {}): ReturnType<Builder['String']> {
|
|
311
|
+
return schema.String({ ...options, minLength: Math.max(32, (options as { minLength?: number }).minLength ?? 0), requiredInProduction: true, secret: true })
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
type OldFileOptions = Omit<NonNullable<Parameters<Builder['File']>[0]>, 'minSize' | 'maxSize'> & { minSize?: ByteSize | undefined, maxSize?: ByteSize | undefined }
|
|
315
|
+
type OldFilesOptions = Omit<NonNullable<Parameters<Builder['Files']>[0]>, 'minSize' | 'maxSize'> & { minSize?: ByteSize | undefined, maxSize?: ByteSize | undefined }
|
|
316
|
+
|
|
317
|
+
const File = (options?: OldFileOptions): ReturnType<Builder['File']> => schema.File(sized(options, 's.File'))
|
|
318
|
+
const Files = (options?: OldFilesOptions): ReturnType<Builder['Files']> => schema.Files(sized(options, 's.Files'))
|
|
319
|
+
|
|
320
|
+
// kay's schema builders, so an action's schema needs no import of its own, over TypeBox, so a schema stays JSON Schema data for OpenAPI, MCP and the form rules.
|
|
321
|
+
// The PascalCase builders, `s.Object`, `s.Optional`, `s.UnionKeys`, `s.Numeric` and the rest, are Elysia's under their old names and stay until 2.0: the `deprecated-schema-builders` lint rewrites the ones kay has a builder for.
|
|
71
322
|
// kept: free
|
|
72
|
-
export const s: Omit<Builder, 'File' | 'Files'
|
|
323
|
+
export const s: Omit<Builder, 'File' | 'Files' | 'UnionEnum' | 'Secret'> & {
|
|
324
|
+
UnionEnum: typeof UnionEnum
|
|
325
|
+
UnionKeys: typeof UnionKeys
|
|
326
|
+
File: typeof File
|
|
327
|
+
Files: typeof Files
|
|
328
|
+
Secret: typeof Secret
|
|
329
|
+
Public: typeof publicField
|
|
330
|
+
string: typeof string
|
|
331
|
+
email: typeof email
|
|
332
|
+
url: typeof url
|
|
333
|
+
slug: typeof slug
|
|
334
|
+
int: typeof int
|
|
335
|
+
number: typeof number
|
|
336
|
+
boolean: typeof boolean
|
|
337
|
+
date: typeof date
|
|
338
|
+
enum: typeof enumeration
|
|
339
|
+
literal: typeof literal
|
|
340
|
+
union: typeof union
|
|
341
|
+
object: typeof object
|
|
342
|
+
record: typeof record
|
|
343
|
+
list: typeof list
|
|
344
|
+
file: typeof file
|
|
345
|
+
files: typeof files
|
|
346
|
+
secret: typeof secret
|
|
347
|
+
public: typeof publicField
|
|
348
|
+
} = {
|
|
349
|
+
...schema,
|
|
350
|
+
UnionEnum,
|
|
351
|
+
UnionKeys,
|
|
352
|
+
File,
|
|
353
|
+
Files,
|
|
354
|
+
Secret,
|
|
355
|
+
Public: publicField,
|
|
356
|
+
string,
|
|
357
|
+
email,
|
|
358
|
+
url,
|
|
359
|
+
slug,
|
|
360
|
+
int,
|
|
361
|
+
number,
|
|
362
|
+
boolean,
|
|
363
|
+
date,
|
|
364
|
+
enum: enumeration,
|
|
365
|
+
literal,
|
|
366
|
+
union,
|
|
367
|
+
object,
|
|
368
|
+
record,
|
|
369
|
+
list,
|
|
370
|
+
file,
|
|
371
|
+
files,
|
|
372
|
+
secret,
|
|
373
|
+
public: publicField,
|
|
374
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// The shape every Standard Schema validator (Zod 4.2+, ArkType 2.1.28+, Valibot) has, https://standardschema.dev: written here so kay needs no dependency to accept one.
|
|
2
|
+
export interface StandardSchema<Input = unknown, Output = Input> {
|
|
3
|
+
readonly '~standard': {
|
|
4
|
+
readonly version: 1
|
|
5
|
+
readonly vendor: string
|
|
6
|
+
readonly validate: (value: unknown) => StandardResult<Output> | Promise<StandardResult<Output>>
|
|
7
|
+
readonly types?: { readonly input: Input, readonly output: Output } | undefined
|
|
8
|
+
// The JSON Schema extension: what a form's constraints, OpenAPI and MCP are read from.
|
|
9
|
+
readonly jsonSchema?: { readonly input: (options: { target: string }) => Record<string, unknown> } | undefined
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type StandardResult<Output> = { readonly value: Output, readonly issues?: undefined } | { readonly issues: readonly { readonly message: string, readonly path?: readonly (PropertyKey | { readonly key: PropertyKey })[] | undefined }[] }
|
|
14
|
+
|
|
15
|
+
export type StandardOutput<Type> = Type extends { '~standard': { types?: infer Types } } ? NonNullable<Types> extends { output: infer Output } ? Output : unknown : never
|
|
16
|
+
|
|
17
|
+
export function isStandardSchema(value: unknown): value is StandardSchema {
|
|
18
|
+
return typeof value === 'object' && value !== null && '~standard' in value && typeof (value as StandardSchema)['~standard'].validate === 'function'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The JSON Schema a Standard Schema validator describes its input with, as draft 2020-12; undefined for one without the extension, which validates but gives a form no constraints, nor OpenAPI and MCP a description.
|
|
22
|
+
export function jsonSchemaOf(schema: object): Record<string, unknown> | undefined {
|
|
23
|
+
if (!isStandardSchema(schema))
|
|
24
|
+
return schema as Record<string, unknown>
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
return schema['~standard'].jsonSchema?.input({ target: 'draft-2020-12' })
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -4,6 +4,17 @@ import { announce } from './announce'
|
|
|
4
4
|
import { HYDRATED, ISLAND } from './markers'
|
|
5
5
|
import { hashTarget } from './navigation'
|
|
6
6
|
|
|
7
|
+
const WATCH_BOUND_MS = 30_000
|
|
8
|
+
// What ends each pending replay of kept keys, and the fields whose island was told them, so it hears them once.
|
|
9
|
+
const replaying = new Set<() => void>()
|
|
10
|
+
const told = new WeakSet<Element>()
|
|
11
|
+
|
|
12
|
+
type Island = HTMLElement & { _$k?: boolean }
|
|
13
|
+
type Field = HTMLInputElement | HTMLTextAreaElement
|
|
14
|
+
interface Typed { value: string, start: number | null, end: number | null, direction: 'forward' | 'backward' | 'none', replay?: boolean }
|
|
15
|
+
|
|
16
|
+
const noteOf = (field: Field): Typed => ({ value: field.value, start: field.selectionStart, end: field.selectionEnd, direction: field.selectionDirection ?? 'none' })
|
|
17
|
+
|
|
7
18
|
function byName(element: Element | null): Element | null {
|
|
8
19
|
const name = element?.getAttribute('name') ?? ''
|
|
9
20
|
|
|
@@ -12,6 +23,10 @@ function byName(element: Element | null): Element | null {
|
|
|
12
23
|
|
|
13
24
|
// The element focused before, found again on a refreshed page or on Back and Forward between entries of one path; on a new page, the element its hash points at, else its autofocus field, its heading or its main, so a screen reader starts there, the title announced. Back and Forward skip the autofocus field, which the visitor left already, and a position an entry saved leaves the hash alone, as it does the scroll.
|
|
14
25
|
export async function moveFocus(swap: Swap, policy: Policy, hash: string): Promise<void> {
|
|
26
|
+
// The replays of an older swap's keys end here, as this swap's own are registered after.
|
|
27
|
+
for (const end of replaying)
|
|
28
|
+
end()
|
|
29
|
+
|
|
15
30
|
if (policy.focus === 'refused' && swap.refused && await showRefusal(document.forms[swap.refused.form], swap.refused.control))
|
|
16
31
|
return
|
|
17
32
|
|
|
@@ -55,16 +70,55 @@ function carryCaret(from: Element | null, to: HTMLElement, held: string | undefi
|
|
|
55
70
|
if (!(from instanceof HTMLInputElement || from instanceof HTMLTextAreaElement) || !(to instanceof HTMLInputElement || to instanceof HTMLTextAreaElement))
|
|
56
71
|
return
|
|
57
72
|
|
|
58
|
-
const {
|
|
73
|
+
const { value } = from
|
|
59
74
|
|
|
60
|
-
// Keys typed while the page was fetched are kept, and the island is told so it asks for them next.
|
|
75
|
+
// Keys typed while the page was fetched are kept, and the island is told so it asks for them next, once it has hydrated: its own write of the value it was given (kayjs-ui's TextInput) would otherwise land over them.
|
|
61
76
|
const typed = held !== undefined && value !== held && value !== to.value
|
|
62
77
|
|
|
78
|
+
const island = typed ? to.closest<Island>(ISLAND) : null
|
|
79
|
+
const waits = island !== null && !island._$k
|
|
80
|
+
|
|
63
81
|
if (typed) {
|
|
64
82
|
to.value = value
|
|
65
|
-
|
|
83
|
+
|
|
84
|
+
if (!waits)
|
|
85
|
+
to.dispatchEvent(new InputEvent('input', { bubbles: true }))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
placeCaret(from, to)
|
|
89
|
+
|
|
90
|
+
if (waits)
|
|
91
|
+
replayOnHydrate(to, island)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// The island hears the kept keys once it has hydrated, by this field's own listener so that no path of the swap can drop them: the text is put back if hydration wrote the server's over it, and `input` fires either way. The latest text typed meanwhile is the one kept, and the bound of 30 s ends the wait for an island that never hydrates.
|
|
95
|
+
function replayOnHydrate(field: Field, island: Island): void {
|
|
96
|
+
let typed = noteOf(field)
|
|
97
|
+
const heard = new AbortController()
|
|
98
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
99
|
+
const end = () => {
|
|
100
|
+
clearTimeout(timer)
|
|
101
|
+
heard.abort()
|
|
102
|
+
replaying.delete(end)
|
|
66
103
|
}
|
|
67
104
|
|
|
105
|
+
timer = setTimeout(end, WATCH_BOUND_MS)
|
|
106
|
+
replaying.add(end)
|
|
107
|
+
island.addEventListener('input', (event) => {
|
|
108
|
+
if (event.target === field)
|
|
109
|
+
typed = noteOf(field)
|
|
110
|
+
}, { signal: heard.signal, capture: true })
|
|
111
|
+
island.addEventListener(HYDRATED, () => {
|
|
112
|
+
end()
|
|
113
|
+
|
|
114
|
+
if (island.isConnected)
|
|
115
|
+
putBack(found(field), { ...typed, replay: true })
|
|
116
|
+
}, { signal: heard.signal, once: true })
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function placeCaret(from: Field, to: Field): void {
|
|
120
|
+
const { selectionStart, selectionEnd, selectionDirection, value } = from
|
|
121
|
+
|
|
68
122
|
// A number or email field has no selection, so no caret.
|
|
69
123
|
if (selectionStart === null || selectionEnd === null || to.selectionStart === null)
|
|
70
124
|
return
|
|
@@ -101,21 +155,15 @@ async function showRefusal(form: HTMLFormElement | undefined, control: number):
|
|
|
101
155
|
return refusal.showRefusal(form, control, announce)
|
|
102
156
|
}
|
|
103
157
|
|
|
104
|
-
const WATCH_BOUND_MS = 30_000
|
|
105
158
|
// What ends each watch, so a newer swap leaves the ones before it restoring nothing.
|
|
106
159
|
const watching = new Set<() => void>()
|
|
107
160
|
|
|
108
|
-
type Island = HTMLElement & { _$k?: boolean }
|
|
109
|
-
type Field = HTMLInputElement | HTMLTextAreaElement
|
|
110
|
-
interface Typed { value: string, start: number | null, end: number | null, direction: 'forward' | 'backward' | 'none' }
|
|
111
|
-
|
|
112
|
-
const noteOf = (field: Field): Typed => ({ value: field.value, start: field.selectionStart, end: field.selectionEnd, direction: field.selectionDirection ?? 'none' })
|
|
113
|
-
|
|
114
161
|
// Hydration kept what was typed when the field already holds it, and the island heard it through the events queued for it. A number or email field has no selection, so no caret.
|
|
115
162
|
function putBack(now: Element | null, typed: Typed | undefined): void {
|
|
116
|
-
if (!typed || !(now instanceof HTMLInputElement || now instanceof HTMLTextAreaElement) || now.value === typed.value)
|
|
163
|
+
if (!typed || !(now instanceof HTMLInputElement || now instanceof HTMLTextAreaElement) || (now.value === typed.value && !(typed.replay && !told.has(now))))
|
|
117
164
|
return
|
|
118
165
|
|
|
166
|
+
told.add(now)
|
|
119
167
|
now.value = typed.value
|
|
120
168
|
now.dispatchEvent(new InputEvent('input', { bubbles: true }))
|
|
121
169
|
|