@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
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { RequestContext } from './request-context'
|
|
2
|
+
import { eventStream } from './event-stream'
|
|
3
|
+
import { fileAnswer } from './file-answer'
|
|
4
|
+
|
|
5
|
+
// What a handler returned that has no answer: named by its route, so the fix is where it is written.
|
|
6
|
+
export class UnsupportedAnswerError extends Error {
|
|
7
|
+
override readonly name = 'UnsupportedAnswerError'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// A bigint is written as its digits, which JSON has no value for: the replacer swaps it for a marker string only this process knows, and the marker and its quotes are dropped from the text, so a string an app holds can never read as one.
|
|
11
|
+
const MARK = `__kay_bigint_${crypto.randomUUID()}_`
|
|
12
|
+
const MARKED = new RegExp(`"${MARK}(-?\\d+)"`, 'g')
|
|
13
|
+
|
|
14
|
+
function jsonText(value: unknown): string | undefined {
|
|
15
|
+
let marked = false
|
|
16
|
+
|
|
17
|
+
const text = JSON.stringify(value, (_key, held: unknown) => {
|
|
18
|
+
if (typeof held !== 'bigint')
|
|
19
|
+
return held
|
|
20
|
+
|
|
21
|
+
marked = true
|
|
22
|
+
|
|
23
|
+
return `${MARK}${held}`
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
return marked && text !== undefined ? text.replace(MARKED, '$1') : text
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isPlain(value: object): boolean {
|
|
30
|
+
const prototype: unknown = Object.getPrototypeOf(value)
|
|
31
|
+
|
|
32
|
+
return prototype === Object.prototype || prototype === null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isEventSource(value: object): boolean {
|
|
36
|
+
return Symbol.asyncIterator in value || Object.prototype.toString.call(value) === '[object Generator]'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// A response init whose status is only there when a handler set one.
|
|
40
|
+
function init(status: number | undefined, type: string): ResponseInit {
|
|
41
|
+
return status === undefined ? { headers: { 'content-type': type } } : { status, headers: { 'content-type': type } }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function json(text: string, status: number | undefined): Response {
|
|
45
|
+
return new Response(text, init(status, 'application/json'))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function named(context: RequestContext): string {
|
|
49
|
+
const { route } = context
|
|
50
|
+
|
|
51
|
+
return route === undefined ? `${context.method} ${context.url.pathname}` : `${route.method} ${route.path}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The Response a handler's value stands for, made once whatever the route kind:
|
|
55
|
+
// a Response as it is, text, JSON for an object, an array, a number, a boolean, null and a bigint, a Blob or a file with `Range` and `HEAD` answered, a stream, an event stream for an async generator, bytes, and 204 for nothing.
|
|
56
|
+
// A class instance, a Map or a function has no answer and fails the route, which says so by name.
|
|
57
|
+
// The status a handler set goes on a value that is not a Response.
|
|
58
|
+
export function answer(value: unknown, context: RequestContext): Response {
|
|
59
|
+
if (value instanceof Response)
|
|
60
|
+
return value
|
|
61
|
+
|
|
62
|
+
const status = context.written?.status
|
|
63
|
+
|
|
64
|
+
if (value === undefined)
|
|
65
|
+
return new Response(null, { status: status ?? 204 })
|
|
66
|
+
|
|
67
|
+
if (typeof value === 'string')
|
|
68
|
+
return new Response(value, init(status, 'text/plain; charset=utf-8'))
|
|
69
|
+
|
|
70
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint' || value === null)
|
|
71
|
+
return json(jsonText(value)!, status)
|
|
72
|
+
|
|
73
|
+
if (typeof value === 'object') {
|
|
74
|
+
if (value instanceof Blob)
|
|
75
|
+
return withStatus(fileAnswer(value, context.request), status)
|
|
76
|
+
|
|
77
|
+
if (value instanceof ReadableStream)
|
|
78
|
+
return new Response(value, init(status, 'application/octet-stream'))
|
|
79
|
+
|
|
80
|
+
if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer)
|
|
81
|
+
return new Response(value as BodyInit, init(status, 'application/octet-stream'))
|
|
82
|
+
|
|
83
|
+
if (isEventSource(value))
|
|
84
|
+
return withStatus(eventStream(value as AsyncIterable<unknown>), status)
|
|
85
|
+
|
|
86
|
+
if (Array.isArray(value) || isPlain(value)) {
|
|
87
|
+
const text = jsonText(value)
|
|
88
|
+
|
|
89
|
+
if (text !== undefined)
|
|
90
|
+
return json(text, status)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const kind = typeof value === 'object' ? (value.constructor as { name?: string } | undefined)?.name ?? 'an object with no class' : typeof value
|
|
95
|
+
|
|
96
|
+
throw new UnsupportedAnswerError(`kay: ${named(context)} returned ${kind}, which has no response; return a Response, text, a plain object or array, a file, a stream or an async generator`)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// A response with the status a handler set, when that is not the one it has.
|
|
100
|
+
function withStatus(response: Response, status: number | undefined): Response {
|
|
101
|
+
return status === undefined || status === response.status ? response : new Response(response.body, { status, headers: response.headers })
|
|
102
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { Issue, Source } from './validate'
|
|
2
|
+
import { isStandardSchema } from '../runtime/standard-schema'
|
|
3
|
+
import { isRefusal, validate } from './validate'
|
|
4
|
+
|
|
5
|
+
// What a route's `body`, `query`, `params`, `headers` and `cookie` schemas were declared as, kept where OpenAPI reads them since Elysia is left none to validate with.
|
|
6
|
+
const DECLARED = Symbol.for('kay.apiInputs')
|
|
7
|
+
|
|
8
|
+
const INPUTS = ['body', 'query', 'params', 'headers', 'cookie'] as const
|
|
9
|
+
|
|
10
|
+
type Input = typeof INPUTS[number]
|
|
11
|
+
|
|
12
|
+
type Hooks = Partial<Record<Input, unknown>> & { transform?: unknown, standaloneValidator?: Partial<Record<Input, unknown>>[], [DECLARED]?: Partial<Record<Input, object>> }
|
|
13
|
+
|
|
14
|
+
// Input a route's schema refused. It carries Elysia's `VALIDATION` code and the shape of its error, so an `onError` hook that answers refused input still reads it as it did.
|
|
15
|
+
export class InputRefusedError extends Error {
|
|
16
|
+
readonly code = 'VALIDATION'
|
|
17
|
+
readonly status = 422
|
|
18
|
+
|
|
19
|
+
constructor(readonly type: Input, readonly errors: Issue[]) {
|
|
20
|
+
super(`Invalid ${type}: ${errors.map(issue => issue.message).join('; ')}`)
|
|
21
|
+
this.name = 'InputRefusedError'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get all(): { path: string, message: string, summary: string }[] {
|
|
25
|
+
return this.errors.map(issue => ({ path: `/${issue.path.replaceAll('.', '/')}`, message: issue.message, summary: issue.message }))
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The input schemas of a route as it was declared.
|
|
30
|
+
export function declaredInputs(hooks: unknown): Partial<Record<Input, object>> {
|
|
31
|
+
return (hooks as Hooks | undefined)?.[DECLARED] ?? {}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A query, the headers and the cookies of a request carry what the schema does not name, which is dropped, not refused; so does a body or params with several schemas, a guard's beside the route's, each naming fields the others lack.
|
|
35
|
+
function lenient(schema: object): object {
|
|
36
|
+
if (isStandardSchema(schema))
|
|
37
|
+
return schema
|
|
38
|
+
|
|
39
|
+
const copy: Record<PropertyKey, unknown> = { ...schema, 'x-kay-extra': 'strip' }
|
|
40
|
+
|
|
41
|
+
delete copy.additionalProperties
|
|
42
|
+
|
|
43
|
+
return copy
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const FORM_BODY = /^(?:multipart\/form-data|application\/x-www-form-urlencoded)\b/i
|
|
47
|
+
|
|
48
|
+
function sourceOf(input: Input, request: Request): Source {
|
|
49
|
+
if (input === 'body')
|
|
50
|
+
return FORM_BODY.test(request.headers.get('content-type') ?? '') ? 'form' : 'json'
|
|
51
|
+
|
|
52
|
+
return input === 'query' ? 'query' : 'params'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface InputContext {
|
|
56
|
+
request: Request
|
|
57
|
+
body?: unknown
|
|
58
|
+
query?: unknown
|
|
59
|
+
params?: unknown
|
|
60
|
+
headers?: unknown
|
|
61
|
+
cookie?: unknown
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The value of each cookie, as Elysia hands the jar over as objects holding it.
|
|
65
|
+
function cookieValues(jar: unknown): unknown {
|
|
66
|
+
if (typeof jar !== 'object' || jar === null)
|
|
67
|
+
return jar
|
|
68
|
+
|
|
69
|
+
return Object.fromEntries(Object.entries(jar).map(([name, cookie]) => [name, (cookie as { value?: unknown } | undefined)?.value]))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Takes the route's input schemas out of Elysia's validation, which would call their `error` functions outside the request's locale, and checks them in a hook of its own, the value read being the one the handler gets. Reading each by its property tells Elysia the route needs it parsed.
|
|
73
|
+
// A key the query repeats is a list of its values: Elysia reads it so only for a schema it holds itself, which it is left none of.
|
|
74
|
+
function withRepeats(request: Request, parsed: unknown): unknown {
|
|
75
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
76
|
+
return parsed
|
|
77
|
+
|
|
78
|
+
const { searchParams } = new URL(request.url)
|
|
79
|
+
const repeated = Object.fromEntries([...new Set(searchParams.keys())].map(key => [key, searchParams.getAll(key)] as const).filter(([, values]) => values.length > 1))
|
|
80
|
+
|
|
81
|
+
return Object.keys(repeated).length === 0 ? parsed : { ...parsed, ...repeated }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function validatingInputs(hooks: unknown, inLocale: <T>(request: Request, run: () => T) => T): void {
|
|
85
|
+
const route = hooks as Hooks | undefined
|
|
86
|
+
const declared: Partial<Record<Input, object>> = {}
|
|
87
|
+
// Every schema an input has: the route's own, and one for each guard around it, which Elysia keeps apart and checks one by one.
|
|
88
|
+
const all: Partial<Record<Input, object[]>> = {}
|
|
89
|
+
|
|
90
|
+
if (route === undefined)
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
for (const input of INPUTS) {
|
|
94
|
+
for (const holder of [route, ...route.standaloneValidator ?? []]) {
|
|
95
|
+
const schema = holder[input]
|
|
96
|
+
|
|
97
|
+
if (typeof schema === 'object' && schema !== null) {
|
|
98
|
+
(all[input] ??= []).push(schema)
|
|
99
|
+
declared[input] ??= schema
|
|
100
|
+
holder[input] = undefined
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (Object.keys(declared).length === 0)
|
|
106
|
+
return
|
|
107
|
+
|
|
108
|
+
const checked: Partial<Record<Input, object[]>> = Object.fromEntries(Object.entries(all).map(([input, schemas]) => [input, (input === 'body' || input === 'params') && schemas.length === 1 ? schemas : schemas.map(lenient)]))
|
|
109
|
+
|
|
110
|
+
route[DECLARED] = declared
|
|
111
|
+
|
|
112
|
+
// What an input reads as, or the refusal thrown: the schemas it has, the route's own and its guards', checked one after the other.
|
|
113
|
+
const settle = async (input: Input, request: Request, given: unknown): Promise<unknown> => {
|
|
114
|
+
const schemas = checked[input]
|
|
115
|
+
|
|
116
|
+
if (schemas === undefined)
|
|
117
|
+
return given
|
|
118
|
+
|
|
119
|
+
// Each schema reads what was sent, not what another dropped from it: a form post loses the fields a schema does not name, and a guard's schema names others than the route's.
|
|
120
|
+
const outputs: unknown[] = []
|
|
121
|
+
const refused = new Map<string, Issue>()
|
|
122
|
+
|
|
123
|
+
for (const schema of schemas) {
|
|
124
|
+
const result = await inLocale(request, async () => validate(schema, given, { source: sourceOf(input, request), trim: false }))
|
|
125
|
+
|
|
126
|
+
if (!isRefusal(result)) {
|
|
127
|
+
outputs.push(result.value)
|
|
128
|
+
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for (const issue of result.errors) {
|
|
133
|
+
if (!refused.has(issue.path))
|
|
134
|
+
refused.set(issue.path, issue)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (refused.size > 0)
|
|
139
|
+
throw new InputRefusedError(input, [...refused.values()])
|
|
140
|
+
|
|
141
|
+
const plain = outputs.every(output => typeof output === 'object' && output !== null && !Array.isArray(output))
|
|
142
|
+
|
|
143
|
+
return plain ? Object.assign({}, ...outputs) as unknown : outputs.at(-1)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// One hook per input, each naming its own property and never passing the context on: Elysia reads a hook's source to know what to parse, so a route declaring only a `query` leaves its body to the handler.
|
|
147
|
+
const readers: Record<Input, (context: InputContext) => Promise<void>> = {
|
|
148
|
+
body: async (context) => {
|
|
149
|
+
context.body = await settle('body', context.request, context.body)
|
|
150
|
+
},
|
|
151
|
+
query: async (context) => {
|
|
152
|
+
context.query = await settle('query', context.request, withRepeats(context.request, context.query))
|
|
153
|
+
},
|
|
154
|
+
params: async (context) => {
|
|
155
|
+
context.params = await settle('params', context.request, context.params)
|
|
156
|
+
},
|
|
157
|
+
headers: async (context) => {
|
|
158
|
+
context.headers = await settle('headers', context.request, context.headers)
|
|
159
|
+
},
|
|
160
|
+
cookie: async (context) => {
|
|
161
|
+
await settle('cookie', context.request, cookieValues(context.cookie))
|
|
162
|
+
},
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
route.transform = [...[route.transform ?? []].flat() as unknown[], ...INPUTS.filter(input => declared[input] !== undefined).map(input => readers[input])]
|
|
166
|
+
}
|
|
@@ -46,7 +46,7 @@ export const REFERENCE_PATH = `${API_PREFIX}/reference`
|
|
|
46
46
|
export function apiPathOf(value: string | undefined): string {
|
|
47
47
|
return value === undefined ? API_PREFIX : servedPath(value, 'endpoints.api')
|
|
48
48
|
}
|
|
49
|
-
// Where `mcp` serves the app's tools, and where it did before 1.105, which
|
|
49
|
+
// Where `mcp` serves the app's tools, and where it did before 1.105, which is answered in place until 2.0.
|
|
50
50
|
export const MCP_PATH = '/_kay/mcp'
|
|
51
51
|
export const FORMER_MCP_PATH = '/mcp'
|
|
52
52
|
// Where an MCP client finds how to sign in, which the endpoint's 401 points to.
|
package/src/server/api.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Server } from 'bun'
|
|
2
|
-
import type { Context, TSchema
|
|
2
|
+
import type { Context, TSchema } from 'elysia'
|
|
3
3
|
import type { ExtensionApp } from '../config'
|
|
4
4
|
import type { Guard, Locals } from '../runtime'
|
|
5
5
|
import type { ActionTool, RateLimit } from '../runtime/action'
|
|
@@ -22,6 +22,7 @@ import { API_MOUNT } from '../runtime/live'
|
|
|
22
22
|
import { runInLocale } from '../runtime/locale-state'
|
|
23
23
|
import { withDefaultBounds } from '../runtime/schema-bounds'
|
|
24
24
|
import { contextLocale, guardsFirst, passGuards, requestState } from './actions'
|
|
25
|
+
import { InputRefusedError, validatingInputs } from './api-input'
|
|
25
26
|
import { withDecodedParams } from './api-params'
|
|
26
27
|
import { importModule } from './bundle'
|
|
27
28
|
import { timeoutMs } from './config-limits'
|
|
@@ -29,7 +30,6 @@ import { cookieJar } from './cookies'
|
|
|
29
30
|
import { corsAdmits, corsResponse, corsRule, dropOwnGrant, grantedByKay, preflight, varyByOrigin, withCors, withoutOwnGrant } from './cors'
|
|
30
31
|
import { admitCrossSite, crossSiteRefused, crossSiteResponse } from './cross-site'
|
|
31
32
|
import { streamReporters } from './event-stream'
|
|
32
|
-
import { refusedFields, validated } from './field-errors'
|
|
33
33
|
import { keepOwnGuards, loadApiGuards, requiredGuards } from './guards'
|
|
34
34
|
import { handlerTiming } from './handler-timing'
|
|
35
35
|
import { inRouteReads, LIVE_HEADER, routeProof } from './live'
|
|
@@ -49,7 +49,7 @@ import { markPrivate, wasReadPersonally } from './scope'
|
|
|
49
49
|
import { carriedNames, carryContext } from './security'
|
|
50
50
|
import { holdToLimits, socketOptions } from './socket'
|
|
51
51
|
import { answered, failed, replyTrace, SERVER_SPAN, startSpan, tracedUnder, tracing } from './trace'
|
|
52
|
-
import {
|
|
52
|
+
import { messagesOf } from './validate'
|
|
53
53
|
import { socketLimits } from './ws-limits'
|
|
54
54
|
|
|
55
55
|
// What a body Elysia streams, awaits or asks for its response has: a generator, a thenable, an object with `toResponse()`.
|
|
@@ -63,10 +63,6 @@ const CORS = Symbol.for('kay.cors')
|
|
|
63
63
|
const RATE_LIMIT = Symbol.for('kay.rateLimit')
|
|
64
64
|
// Where `api({ timeout })` keeps the module's timeout.
|
|
65
65
|
const TIMEOUT = Symbol.for('kay.timeout')
|
|
66
|
-
// The inputs of a route Elysia validates, whose schemas are read for their `error` in the request's locale.
|
|
67
|
-
const INPUTS = ['body', 'query', 'params', 'headers', 'cookie']
|
|
68
|
-
const BODY_PREFIX = /^body\./
|
|
69
|
-
|
|
70
66
|
// The requests the guards of their module let through, whose later errors are no refused input.
|
|
71
67
|
const admitted = new WeakSet<Request>()
|
|
72
68
|
|
|
@@ -147,13 +143,9 @@ export async function serveApi(app: Elysia, modules: ApiModule[], options: Actio
|
|
|
147
143
|
if (hooks && route.method !== 'WS' && typeof hooks.body === 'object' && hooks.body !== null && !('~standard' in hooks.body))
|
|
148
144
|
hooks.body = withDefaultBounds(hooks.body as TSchema)
|
|
149
145
|
|
|
150
|
-
// The
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (route.method !== 'WS' && typeof schema === 'object' && schema !== null && !('~standard' in schema))
|
|
155
|
-
(hooks as Record<string, unknown>)[input] = validated(schema as TSchema)
|
|
156
|
-
}
|
|
146
|
+
// The route's input schemas are checked by kay, in the request's locale, not by Elysia.
|
|
147
|
+
if (route.method !== 'WS')
|
|
148
|
+
validatingInputs(hooks, (request, run) => inApiLocale(request, options, run))
|
|
157
149
|
|
|
158
150
|
// Whichever way the module chains its `.ws()` (in a group, a guard or a used plugin), every websocket route is held to its limits.
|
|
159
151
|
if (hooks && route.method === 'WS')
|
|
@@ -259,7 +251,7 @@ export async function serveApi(app: Elysia, modules: ApiModule[], options: Actio
|
|
|
259
251
|
// Before the module's own `onError`, so no custom answer to refused input reaches a caller the guards refuse.
|
|
260
252
|
.onError(async (context) => {
|
|
261
253
|
// Past the guards, a failing response schema or a handler's own throw is no input to keep from a refused caller.
|
|
262
|
-
if ((context.
|
|
254
|
+
if (!(context.error instanceof InputRefusedError) || guards.length === 0 || admitted.has(context.request))
|
|
263
255
|
return undefined
|
|
264
256
|
|
|
265
257
|
const refusal = await answeringRequest(context.request, async () => inApiLocale(context.request, options, async () => guardsFirst(guards, sharedContext(context.request, () => ({ ...context })), (context as { params?: Record<string, unknown> }).params ?? {}, undefined, options)))
|
|
@@ -299,7 +291,7 @@ export async function serveApi(app: Elysia, modules: ApiModule[], options: Actio
|
|
|
299
291
|
.onError(({ request, error, code, set }) => {
|
|
300
292
|
const refused = { request, error, code, set }
|
|
301
293
|
|
|
302
|
-
return refusedInput(refused
|
|
294
|
+
return refusedInput(refused) ?? reportThrown(refused, options)
|
|
303
295
|
})
|
|
304
296
|
|
|
305
297
|
letGoOfParent(instance, app)
|
|
@@ -558,27 +550,15 @@ function carriedOver(set: { status?: number | string, headers: Record<string, un
|
|
|
558
550
|
return Object.keys(set.headers).length > 0 && response === given ? undefined : response
|
|
559
551
|
}
|
|
560
552
|
|
|
561
|
-
// Input the route's `body`, `query`, `params` or `
|
|
553
|
+
// Input the route's `body`, `query`, `params`, `headers` or `cookie` refused, answered as an action answers it: `{ errors, status }`, a message per field in the request's locale.
|
|
562
554
|
// A mismatch of the route's own response is the route's bug and is left to the caller.
|
|
563
|
-
function refusedInput({
|
|
564
|
-
if (
|
|
565
|
-
const field = (error as { property: string }).property.replace(BODY_PREFIX, '')
|
|
566
|
-
|
|
567
|
-
set.status = 422
|
|
568
|
-
|
|
569
|
-
return { errors: inApiLocale(request, options, () => ({ [field]: kayWord('kay.action.invalidFile') })), status: 422 }
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
if (code !== 'VALIDATION' || isResponseMismatch(error, code))
|
|
555
|
+
function refusedInput({ error, set }: { request: Request, error: unknown, code: unknown, set: { status?: number | string } }): { errors: Record<string, string>, status: 422 } | undefined {
|
|
556
|
+
if (!(error instanceof InputRefusedError))
|
|
573
557
|
return undefined
|
|
574
558
|
|
|
575
|
-
const { validator } = error as ValidationError
|
|
576
|
-
const schema = (validator as { schema?: unknown }).schema ?? validator
|
|
577
|
-
const errors = inApiLocale(request, options, () => refusedFields(schema, error as ValidationError))
|
|
578
|
-
|
|
579
559
|
set.status = 422
|
|
580
560
|
|
|
581
|
-
return { errors, status: 422 }
|
|
561
|
+
return { errors: messagesOf(error.errors), status: 422 }
|
|
582
562
|
}
|
|
583
563
|
|
|
584
564
|
// Elysia answers a response that fails its schema as validation (422), a client error for what is the route's own bug.
|
package/src/server/app-stages.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { OwnRoutes } from './dev'
|
|
|
9
9
|
import type { GuardRequirement } from './guard-requirement'
|
|
10
10
|
import type { ServedRoute } from './guards'
|
|
11
11
|
import type { ImageRouteOptions } from './image'
|
|
12
|
+
import type { KayServer } from './kay-server'
|
|
12
13
|
import type { Writes } from './kept-pages'
|
|
13
14
|
import type { MountedApi } from './openapi'
|
|
14
15
|
import type { Unmatched } from './page-routes'
|
|
@@ -19,7 +20,7 @@ import type { ServedPage } from './render'
|
|
|
19
20
|
import type { RouteTable } from './route-table'
|
|
20
21
|
import type { Claim, ServedPaths } from './served-paths'
|
|
21
22
|
import type { PageSetup } from './setup'
|
|
22
|
-
import { join, resolve } from 'node:path'
|
|
23
|
+
import { join, relative, resolve } from 'node:path'
|
|
23
24
|
import process from 'node:process'
|
|
24
25
|
import { MAPS_DIR } from '../build/assets'
|
|
25
26
|
import { pageHooks, servedPageHooks } from '../config-extensions'
|
|
@@ -52,7 +53,7 @@ import { entryUrls } from './entry-urls'
|
|
|
52
53
|
import { servePublicEnv } from './env'
|
|
53
54
|
import { browserStackMapper, devStackMapper } from './error-maps'
|
|
54
55
|
import { serveErrorReports } from './errors'
|
|
55
|
-
import { FAVICON_DIR, faviconSource, faviconVersion, serveFavicons } from './favicon'
|
|
56
|
+
import { checkShareAction, FAVICON_DIR, faviconSource, faviconVersion, serveFavicons } from './favicon'
|
|
56
57
|
import { loadGuard, requiredGuards } from './guards'
|
|
57
58
|
import { refuseUnknownHosts } from './host-allowlist'
|
|
58
59
|
|
|
@@ -64,7 +65,7 @@ import { HEALTH_PATH, serveHealth, stopOnSignal } from './lifecycle'
|
|
|
64
65
|
import { liveConnections, serveLive } from './live'
|
|
65
66
|
import { warnOfLocalFiles } from './local-files'
|
|
66
67
|
import { announceStart, loggerOf, logRequests, pathOf, requestRefusalLogger, useLogger } from './log'
|
|
67
|
-
import { mcpBodyLimit, receiveDispatched,
|
|
68
|
+
import { mcpBodyLimit, receiveDispatched, serveMcp, serveToolCallsThrough } from './mcp'
|
|
68
69
|
import { FORMER_METRICS_PATH, METRICS_PATH, metricsOf, serveMetrics } from './metrics'
|
|
69
70
|
import { newTabStyles } from './new-tab'
|
|
70
71
|
import { countMissing, knowRedirects } from './not-found'
|
|
@@ -79,6 +80,7 @@ import { checkProxy, requestId, requestIdHeader, setRequestIdHeader, trustProxy
|
|
|
79
80
|
import { requireProxyKey } from './proxy-key'
|
|
80
81
|
import { publicCacheRules, servePublic } from './public'
|
|
81
82
|
import { NOT_PUBLISHING, watchPublishing } from './publishing'
|
|
83
|
+
import { bridgeReceive } from './receive'
|
|
82
84
|
import { redirectSpelling } from './redirect-spelling'
|
|
83
85
|
import { redirectStatus, redirectTarget, serveRedirects } from './redirects'
|
|
84
86
|
import { remoteImages, remotePatterns } from './remote'
|
|
@@ -165,6 +167,8 @@ export type LateApp = ReturnType<typeof lateApp>
|
|
|
165
167
|
|
|
166
168
|
interface BootInput {
|
|
167
169
|
app: App
|
|
170
|
+
// The route table and the phases, with `app` as the fallback that serves what the table does not.
|
|
171
|
+
kay: KayServer
|
|
168
172
|
env: ServerEnv
|
|
169
173
|
project: Project<ServedOptions>
|
|
170
174
|
setup: PageSetup
|
|
@@ -195,8 +199,9 @@ export function bootOf(input: BootInput) {
|
|
|
195
199
|
// Offered, so an app file at the path keeps it; only a running server counts, as `kay dev` restarts on every change and an export serves nothing.
|
|
196
200
|
const metricsConfig = env.serving ? metricsOf(options.ops?.metrics) : undefined
|
|
197
201
|
const metrics: Claim | undefined = metricsConfig && { path: options.endpoints?.metrics ?? METRICS_PATH, owner: 'the metrics route', kind: 'kay' }
|
|
198
|
-
// Where the
|
|
202
|
+
// Where the MCP endpoint was served before 1.105, answered in place until 2.0 by an app that did not move it, unless an app file serves something there.
|
|
199
203
|
const formerMcp: Claim | undefined = input.mcpAt !== undefined && options.endpoints?.mcp === undefined ? { path: FORMER_MCP_PATH, owner: '`mcp`', kind: 'kay', method: 'ALL' } : undefined
|
|
204
|
+
// Where the metrics were served before 1.105, answered as well until 1.108 by an app that did not move them, unless an app file serves something there.
|
|
200
205
|
const formerMetrics: Claim | undefined = metrics && options.endpoints?.metrics === undefined ? { path: FORMER_METRICS_PATH, owner: 'the metrics route', kind: 'kay' } : undefined
|
|
201
206
|
// Offered, so an app file at the path keeps it; the check is served once every claim is in, and only where it still holds the path.
|
|
202
207
|
const health: Claim | undefined = options.ops?.health === false ? undefined : { path: options.endpoints?.health ?? HEALTH_PATH, owner: 'the health check', kind: 'kay' }
|
|
@@ -218,7 +223,7 @@ export function bootOf(input: BootInput) {
|
|
|
218
223
|
hasPreview: options.preview !== undefined && options.preview !== false,
|
|
219
224
|
metrics,
|
|
220
225
|
formerMetrics,
|
|
221
|
-
// Where the MCP endpoint was served before 1.105,
|
|
226
|
+
// Where the MCP endpoint was served before 1.105, answered as the endpoint is until 2.0 by an app that did not move it, unless an app file serves something there.
|
|
222
227
|
formerMcp,
|
|
223
228
|
health,
|
|
224
229
|
registered,
|
|
@@ -265,8 +270,11 @@ export function knowPages({ app, env, options, setup: { matchers }, routes, tabl
|
|
|
265
270
|
}
|
|
266
271
|
|
|
267
272
|
// Only a kept page reads the count, so a build keeping none registers no hook for it.
|
|
268
|
-
export function keptPageWrites({ app, setup: { client }, mcpAt }: Boot): Writes {
|
|
269
|
-
|
|
273
|
+
export function keptPageWrites({ app, setup: { client }, mcpAt, formerMcp, served }: Boot): Writes {
|
|
274
|
+
// The former path is exempt only where kay serves it: a route of the app at `/mcp` keeps counting.
|
|
275
|
+
const own = () => [...mcpAt === undefined ? [] : [mcpAt], ...formerMcp !== undefined && served.holds(formerMcp) ? [formerMcp.path] : []]
|
|
276
|
+
|
|
277
|
+
return [...client.pages.values()].some(page => page.kept === true) ? countWrites(app, own) : NO_WRITES
|
|
270
278
|
}
|
|
271
279
|
|
|
272
280
|
// The routes under `/_kay/files/` carry the security headers themselves, as the build's files and the image route do.
|
|
@@ -300,22 +308,25 @@ function hostsToAnswer(setting: SecurityConfig | boolean | undefined, site: stri
|
|
|
300
308
|
return hosts === false ? undefined : hosts ?? (env.production && site !== undefined ? true : undefined)
|
|
301
309
|
}
|
|
302
310
|
|
|
303
|
-
// Who the request is from and whether it may come
|
|
304
|
-
|
|
311
|
+
// Who the request is from and whether it may come, as the steps of `receive`: the proxy it came through, the server's own mark, the proxy key, the dev hosts, the hosts; then the security headers on every answer.
|
|
312
|
+
// The steps run in kay's pipeline, which Elysia's first `onRequest` hook hands every request to while the routes are not on kay's table.
|
|
313
|
+
export function trustRequests({ app, kay, env, options, project, served, security, filePaths, setup, mcpAt, mcpKey, metrics, formerMetrics, formerMcp, log, health }: Boot): void {
|
|
314
|
+
const { receive } = kay.pipeline.phases
|
|
315
|
+
|
|
305
316
|
setRequestIdHeader(options.ops?.observe?.requestIdHeader)
|
|
306
|
-
trustProxy(
|
|
317
|
+
receive.push(trustProxy(options.proxy))
|
|
307
318
|
defaultCookies(app, cookieDefaults(options.security, env.base))
|
|
308
319
|
// Before the key check reads the mark, and dropped from the request there, so no handler reads it.
|
|
309
|
-
|
|
320
|
+
receive.push((request) => {
|
|
310
321
|
receiveInternal(request)
|
|
311
322
|
})
|
|
312
|
-
requireProxyKey(app, checkProxy(options.proxy), { root: setup.source.runtimeRoot(project.root), dev: env.dev, exported: env.exported, base: env.base, health: health?.path, endpoint: mcpKey === undefined ? undefined : () => mcpEndpoints(mcpAt, formerMcp, served), metrics: () => [metrics, formerMetrics].flatMap(claim => claim !== undefined && served.holds(claim) ? [claim.path] : []), logRefused: requestRefusalLogger(log), security })
|
|
313
|
-
refuseForeignHosts(app, setup.site, security)
|
|
314
323
|
|
|
324
|
+
const key = requireProxyKey(checkProxy(options.proxy), { root: setup.source.runtimeRoot(project.root), dev: env.dev, exported: env.exported, base: env.base, health: health?.path, endpoint: mcpKey === undefined ? undefined : () => mcpEndpoints(mcpAt, formerMcp, served), metrics: () => [metrics, formerMetrics].flatMap(claim => claim !== undefined && served.holds(claim) ? [claim.path] : []), logRefused: requestRefusalLogger(log), security })
|
|
325
|
+
const foreign = refuseForeignHosts(setup.site, security)
|
|
315
326
|
const hosts = hostsToAnswer(options.security, setup.site, env)
|
|
316
327
|
|
|
317
|
-
|
|
318
|
-
|
|
328
|
+
receive.push(...[key, foreign, hosts === undefined ? undefined : refuseUnknownHosts({ site: setup.site, hosts, localeHosts: Object.values(setup.i18n?.settings.hosts ?? {}), security, health: health && [health.path, `${env.base}${health.path}`] })].filter(step => step !== undefined))
|
|
329
|
+
bridgeReceive(app, (request, server) => kay.pipeline.receive(request, server))
|
|
319
330
|
|
|
320
331
|
if (security)
|
|
321
332
|
sendSecurityHeaders(app, security, filePaths)
|
|
@@ -557,10 +568,13 @@ export function hookLifecycleOf({ app, options }: Boot): void {
|
|
|
557
568
|
// The actions, the API modules and the endpoints, then the jobs page, after the extensions whose derived values the guards read through `ctx.locals`.
|
|
558
569
|
export async function appRoutes(boot: Boot, actionOptions: ActionOptions, jobsPage: ReturnType<typeof kayEndpoints>, apiMountsServed: string[]) {
|
|
559
570
|
const { app, routes, table, setup } = boot
|
|
560
|
-
const [{ limits: actionLimits, tools: toolActions }, apiModules] = await Promise.all([registerActionRoutes(app, routes, routeMatch(table, setup.matchers, boot.env.trailingSlash), actionOptions), setup.api])
|
|
571
|
+
const [{ limits: actionLimits, tools: toolActions, broken }, apiModules] = await Promise.all([registerActionRoutes(app, routes, routeMatch(table, setup.matchers, boot.env.trailingSlash), actionOptions), setup.api])
|
|
561
572
|
const api = await serveApi(app, apiModules, actionOptions, setup.extensionApp)
|
|
562
573
|
|
|
563
574
|
apiMountsServed.push(...apiModules.map(module => module.mount))
|
|
575
|
+
const rooted = (file: string) => relative(boot.project.root, file).replaceAll('\\', '/')
|
|
576
|
+
|
|
577
|
+
checkShareAction(boot.options.assets?.manifest?.shareTarget, new Set(actionLimits.keys()), new Set(routes.flatMap(route => [...route.layouts, ...route.actionModules ?? [], route.file]).map(rooted)), new Map([...broken].map(([file, message]) => [rooted(file), message])))
|
|
564
578
|
boot.registered.actions = actionLimits.size > 0
|
|
565
579
|
boot.registered.api = api.mounted
|
|
566
580
|
|
|
@@ -577,7 +591,7 @@ type Served = Awaited<ReturnType<typeof appRoutes>>
|
|
|
577
591
|
// The rules a redirect added while the site runs is checked against, the API's claims and the body limits of every route. Returns where the OpenAPI document and the MCP metadata go.
|
|
578
592
|
// Not async, as the closures the runtime redirects keep past the app would hold an async function's parameters, the app among them.
|
|
579
593
|
export function limitBodiesAndClaimApi(boot: Boot, { actionLimits, api, endpointLimits }: Served, servers: unknown[]) {
|
|
580
|
-
const { app, env, options, served, setup: { client }, table, hasPreview, mcpAt } = boot
|
|
594
|
+
const { app, env, options, served, setup: { client }, table, hasPreview, mcpAt, formerMcp } = boot
|
|
581
595
|
// Claimed before kay's own files, which give way to them.
|
|
582
596
|
const openapi = openApiSettings(options.openapi)
|
|
583
597
|
const apiAt = apiPathOf(options.endpoints?.api)
|
|
@@ -604,14 +618,16 @@ export function limitBodiesAndClaimApi(boot: Boot, { actionLimits, api, endpoint
|
|
|
604
618
|
}
|
|
605
619
|
}
|
|
606
620
|
|
|
607
|
-
|
|
621
|
+
const formerAt = formerMcp && served.offer(formerMcp) ? formerMcp.path : undefined
|
|
622
|
+
|
|
623
|
+
limitBodies(app, options.limits?.body ?? DEFAULT_BODY_LIMIT, new Map([...actionLimits, ...hasPreview ? [[DRAFT_ROUTE, DRAFT_BODY_LIMIT] as const] : [], ...mcpAt === undefined ? [] : [[mcpAt, mcpBodyLimit] as const], ...formerAt === undefined ? [] : [[formerAt, mcpBodyLimit] as const]]), mountLimits(api.limits, options.extensions, options.limits?.byPath, servers), [...api.routeLimits, ...endpointLimits])
|
|
608
624
|
|
|
609
|
-
return { openapi, apiAt, servesOpenApi, metadataPaths }
|
|
625
|
+
return { openapi, apiAt, servesOpenApi, metadataPaths, formerAt }
|
|
610
626
|
}
|
|
611
627
|
|
|
612
628
|
// The OpenAPI document and the MCP endpoint, registered last before the pages.
|
|
613
|
-
export async function apiDocuments(boot: Boot, { toolActions, apiModules, api }: Served, actionOptions: ActionOptions, { openapi, apiAt, servesOpenApi, metadataPaths }: ReturnType<typeof limitBodiesAndClaimApi>): Promise<void> {
|
|
614
|
-
const { app, env, options, required,
|
|
629
|
+
export async function apiDocuments(boot: Boot, { toolActions, apiModules, api }: Served, actionOptions: ActionOptions, { openapi, apiAt, servesOpenApi, metadataPaths, formerAt }: ReturnType<typeof limitBodiesAndClaimApi>): Promise<void> {
|
|
630
|
+
const { app, env, options, required, setup: { locales }, project: { paths }, mcpAt, mcpKey } = boot
|
|
615
631
|
|
|
616
632
|
// The actions that opted in to being tools are in the document beside the routes, and the MCP endpoint reads its tools from it.
|
|
617
633
|
const document = servesOpenApi || mcpAt !== undefined
|
|
@@ -626,11 +642,7 @@ export async function apiDocuments(boot: Boot, { toolActions, apiModules, api }:
|
|
|
626
642
|
serveOpenApi(app, document, openapi, await covering(false), actionOptions, apiAt, options.endpoints?.openapi)
|
|
627
643
|
|
|
628
644
|
if (mcpAt !== undefined && document) {
|
|
629
|
-
serveMcp(app, document, { title: (document.info as { title: string }).title, version: (document.info as { version: string }).version, base: env.base, guards: await covering(true), actions: actionOptions, metadataPaths, path: mcpAt, rateLimit: mcpRateLimit(options.mcp), instructions: mcpInstructions(options.mcp), key: mcpKey, dev: env.dev, outputs: actionOptions.toolOutputs })
|
|
630
|
-
|
|
631
|
-
// Where the endpoint was served before 1.105, sent to the new path with a 308 until 1.108 by an app that did not move it, unless the app serves something there.
|
|
632
|
-
if (formerMcp && served.offer(formerMcp))
|
|
633
|
-
redirectFormerMcp(app, mcpAt)
|
|
645
|
+
serveMcp(app, document, { title: (document.info as { title: string }).title, version: (document.info as { version: string }).version, base: env.base, guards: await covering(true), actions: actionOptions, metadataPaths, path: mcpAt, former: formerAt, rateLimit: mcpRateLimit(options.mcp), instructions: mcpInstructions(options.mcp), key: mcpKey, dev: env.dev, outputs: actionOptions.toolOutputs })
|
|
634
646
|
}
|
|
635
647
|
}
|
|
636
648
|
|
package/src/server/app.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { faviconSource, MANIFEST, manifestJson } from './favicon'
|
|
|
25
25
|
import { guardRequirement, requiredBy } from './guard-requirement'
|
|
26
26
|
import { loadGuards } from './guards'
|
|
27
27
|
import { refuseLocaleClashes } from './i18n'
|
|
28
|
+
import { KayServer, serveThrough } from './kay-server'
|
|
28
29
|
import { dropExitListenerOnStop } from './lifecycle'
|
|
29
30
|
import { mcpKeySetting, resolveMcpKey } from './mcp-key'
|
|
30
31
|
import { checkPageLimits } from './page-limits'
|
|
@@ -185,10 +186,12 @@ export async function pagesApp(project: Project<ServedOptions>, loadClient: () =
|
|
|
185
186
|
const required = guardRequirement(requiredBy(options), setup.routes, setup.endpoints, await setup.api)
|
|
186
187
|
const routes = await servedRoutes(setup.routes, setup.claimed.routes, required)
|
|
187
188
|
const app = new Elysia({ name: 'kay/pages', seed: root })
|
|
189
|
+
const kay = new KayServer({ env: { base: setup.base, trailingSlash: options.trailingSlash ?? 'never' }, dev: running.dev })
|
|
188
190
|
|
|
189
191
|
dropExitListenerOnStop(app)
|
|
192
|
+
serveThrough(app, kay)
|
|
190
193
|
|
|
191
|
-
const boot = bootOf({ app, env: { ...running, base: setup.base, trailingSlash: options.trailingSlash }, project, setup, served, routes, table, late, mcpAt, mcpKey, required })
|
|
194
|
+
const boot = bootOf({ app, kay, env: { ...running, base: setup.base, trailingSlash: options.trailingSlash }, project, setup, served, routes, table, late, mcpAt, mcpKey, required })
|
|
192
195
|
const earlier = knowPages(boot)
|
|
193
196
|
const writes = keptPageWrites(boot)
|
|
194
197
|
|
|
@@ -226,5 +229,5 @@ export async function pagesApp(project: Project<ServedOptions>, loadClient: () =
|
|
|
226
229
|
|
|
227
230
|
await pageRoutes(boot, { redirects, publicServed, redirector, prerendered, writes })
|
|
228
231
|
|
|
229
|
-
return { app, served, locale: setup.locales.settings.defaultLocale, securityOptions: boot.securityOptions, routes }
|
|
232
|
+
return { app, kay, served, locale: setup.locales.settings.defaultLocale, securityOptions: boot.securityOptions, routes }
|
|
230
233
|
}
|
package/src/server/client.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface ClientManifest {
|
|
|
33
33
|
hydrateWhen?: string[]
|
|
34
34
|
// Each island's chunk and every chunk it imports statically, by island id.
|
|
35
35
|
islands: Record<string, string[]>
|
|
36
|
+
// Each component an island loads when it first draws it, by its key (its path from the root): its chunk and every chunk that imports statically.
|
|
37
|
+
lazies?: Record<string, string[]>
|
|
36
38
|
// The islands whose code holds `installPrompt`, which a page rendering one carries the small script keeping the browser's install offer from the first moment.
|
|
37
39
|
installs?: string[]
|
|
38
40
|
// The stylesheet of each page, layout and special page that imports any, by path relative to the root.
|
package/src/server/dev-ui.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { existsSync, realpathSync } from 'node:fs'
|
|
|
6
6
|
import { mkdir } from 'node:fs/promises'
|
|
7
7
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
8
8
|
import { findKayLibraries } from '../build/libraries'
|
|
9
|
-
import { classesOf, componentFile, componentsNamed, exported, forgetNames, isComponentName, keyOf, UI_FILE, uiOf } from '../build/ui'
|
|
9
|
+
import { classesOf, componentFile, componentsNamed, exported, forgetNames, isComponentName, keyOf, UI_FILE, uiEntryOf, uiOf } from '../build/ui'
|
|
10
10
|
import { appSpecifier, styleInfo, themeTokens, tokensNamedBy } from '../build/ui-info'
|
|
11
11
|
import { parseProgram } from '../compiler/estree'
|
|
12
12
|
import { unwrapped } from '../compiler/object-literal'
|
|
@@ -221,7 +221,7 @@ export async function devUi(root: string, request: Request): Promise<Response> {
|
|
|
221
221
|
|
|
222
222
|
const { info, libraries } = found
|
|
223
223
|
const ui = uiOf(root)
|
|
224
|
-
const set =
|
|
224
|
+
const set = uiEntryOf(root, info.file)
|
|
225
225
|
const own = (part: string): string | undefined => {
|
|
226
226
|
if (typeof set?.parts === 'string')
|
|
227
227
|
return part === 'root' ? set.parts : undefined
|