@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,226 @@
|
|
|
1
|
+
import type { CheckDiagnostic, CheckOptions } from '.'
|
|
2
|
+
import type { Node, Program } from '../compiler/estree'
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { dirname, resolve } from 'node:path'
|
|
5
|
+
import { parseProgram } from '../compiler/estree'
|
|
6
|
+
import { apiScope, fromApi, isPlain, keyName } from './api-scope'
|
|
7
|
+
import { importedName, importsOf, walk } from './ast'
|
|
8
|
+
import { scan } from './renamed-exports'
|
|
9
|
+
|
|
10
|
+
const KAY = /^kay(?:\/|$)/
|
|
11
|
+
const NEEDLE = /\baction\b|\bapi\b/
|
|
12
|
+
const VALIBOT = /^valibot(?:\/|$)/
|
|
13
|
+
const SOURCE = /\.tsx?$/
|
|
14
|
+
const ROUTE_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'all'])
|
|
15
|
+
const ROUTE_SCHEMAS = new Set(['body', 'query', 'params', 'headers', 'cookie'])
|
|
16
|
+
const ACTION_SCHEMAS = new Set(['input'])
|
|
17
|
+
const RELATIVE = /^\.\.?\//
|
|
18
|
+
const EXTENSIONS = ['', '.ts', '.tsx', '/index.ts']
|
|
19
|
+
const WRAPPERS = new Set(['TSAsExpression', 'TSSatisfiesExpression', 'TSNonNullExpression', 'ParenthesizedExpression'])
|
|
20
|
+
const MAX_HOPS = 4
|
|
21
|
+
|
|
22
|
+
// A module of the project: its program and where it is, so a name it imports from a neighbour is read there.
|
|
23
|
+
interface Module {
|
|
24
|
+
ast: Program
|
|
25
|
+
file: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function readModule(from: string, specifier: string): Module | undefined {
|
|
29
|
+
for (const extension of EXTENSIONS) {
|
|
30
|
+
const file = resolve(dirname(from), specifier + extension)
|
|
31
|
+
|
|
32
|
+
if (!SOURCE.test(file) || !existsSync(file))
|
|
33
|
+
continue
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
return { ast: parseProgram(readFileSync(file, 'utf8'), { lang: file.endsWith('.tsx') ? 'tsx' : 'ts', recover: true }).program, file }
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The initializer of the top-level `const name`, exported or not.
|
|
47
|
+
function declared(ast: Program, name: string): Node | undefined {
|
|
48
|
+
for (const statement of ast.body) {
|
|
49
|
+
const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement
|
|
50
|
+
|
|
51
|
+
if (declaration?.type !== 'VariableDeclaration')
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
for (const declarator of declaration.declarations) {
|
|
55
|
+
if (declarator.id.type === 'Identifier' && declarator.id.name === name && declarator.init)
|
|
56
|
+
return declarator.init
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The module and the name a relative import binds `local` to; `default` for a default import.
|
|
64
|
+
function importedFrom({ ast, file }: Module, local: string): { module: Module, name: string } | undefined {
|
|
65
|
+
for (const statement of ast.body) {
|
|
66
|
+
if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type' || !RELATIVE.test(statement.source.value))
|
|
67
|
+
continue
|
|
68
|
+
|
|
69
|
+
for (const specifier of statement.specifiers) {
|
|
70
|
+
if (specifier.type === 'ImportNamespaceSpecifier' || specifier.local.name !== local)
|
|
71
|
+
continue
|
|
72
|
+
|
|
73
|
+
const module = readModule(file, statement.source.value)
|
|
74
|
+
const name = specifier.type === 'ImportDefaultSpecifier' ? 'default' : importedName(specifier)
|
|
75
|
+
|
|
76
|
+
return module && { module, name }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return undefined
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// What a module exports under `name`: a `const`, `export default <expression>`, or one `export { name } from './other'` hop.
|
|
84
|
+
function exported(module: Module, name: string, hops = 0): { init: Node, module: Module } | undefined {
|
|
85
|
+
for (const statement of module.ast.body) {
|
|
86
|
+
if (name === 'default' && statement.type === 'ExportDefaultDeclaration' && !statement.declaration.type.endsWith('Declaration'))
|
|
87
|
+
return { init: statement.declaration as unknown as Node, module }
|
|
88
|
+
|
|
89
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.source === null || hops > 0)
|
|
90
|
+
continue
|
|
91
|
+
|
|
92
|
+
for (const specifier of statement.specifiers) {
|
|
93
|
+
if ((specifier.exported.type === 'Identifier' ? specifier.exported.name : specifier.exported.value) !== name)
|
|
94
|
+
continue
|
|
95
|
+
|
|
96
|
+
const next = readModule(module.file, statement.source.value)
|
|
97
|
+
|
|
98
|
+
return next && exported(next, specifier.local.type === 'Identifier' ? specifier.local.name : specifier.local.value, hops + 1)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const init = declared(module.ast, name)
|
|
103
|
+
|
|
104
|
+
return init && { init, module }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function paramName(param: { type: string, left?: unknown, name?: string }): string | undefined {
|
|
108
|
+
if (param.type === 'AssignmentPattern')
|
|
109
|
+
return paramName(param.left as { type: string })
|
|
110
|
+
|
|
111
|
+
return param.type === 'Identifier' ? param.name : undefined
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Whether the file binds `name` anywhere but its import, as a parameter or a declaration, so a use of it may be that binding.
|
|
115
|
+
function rebound(ast: Program, name: string): boolean {
|
|
116
|
+
let found = false
|
|
117
|
+
|
|
118
|
+
walk(ast, (node) => {
|
|
119
|
+
if (node.type === 'VariableDeclarator' && node.id.type === 'Identifier' && node.id.name === name)
|
|
120
|
+
found = true
|
|
121
|
+
else if ((node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') && node.params.some(param => paramName(param) === name))
|
|
122
|
+
found = true
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
return found
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function fromValibot({ ast }: Module, name: string): boolean {
|
|
129
|
+
return ast.body.some(statement => statement.type === 'ImportDeclaration' && statement.importKind !== 'type' && VALIBOT.test(statement.source.value) && statement.specifiers.some(specifier => specifier.local.name === name)) && !rebound(ast, name)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Whether the expression names `toStandardJsonSchema` anywhere, which gives a valibot schema what it lacks.
|
|
133
|
+
function wrapsJsonSchema(node: Node): boolean {
|
|
134
|
+
let found = false
|
|
135
|
+
|
|
136
|
+
walk(node, (inner) => {
|
|
137
|
+
if (inner.type === 'Identifier' && inner.name === 'toStandardJsonSchema')
|
|
138
|
+
found = true
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
return found
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Whether an object literal holds `~standard` with no `jsonSchema` in it; one with a spread, or a `~standard` that is no literal, is taken to have it.
|
|
145
|
+
function handWritten(object: Extract<Node, { type: 'ObjectExpression' }>): boolean {
|
|
146
|
+
const standard = object.properties.find(property => isPlain(property) && keyName(property) === '~standard')
|
|
147
|
+
|
|
148
|
+
if (standard === undefined || !isPlain(standard) || standard.value.type !== 'ObjectExpression')
|
|
149
|
+
return false
|
|
150
|
+
|
|
151
|
+
return standard.value.properties.every(property => isPlain(property) && keyName(property) !== 'jsonSchema')
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Whether the expression is a Standard Schema validator known to lack `~standard.jsonSchema`: an object literal written by hand, or what valibot builds, which carries none until `toStandardJsonSchema` wraps it.
|
|
155
|
+
// A name is followed to its `const`, here or in a module imported by a relative path; anything else, a call of the app's own or a library other than valibot, is taken to have it.
|
|
156
|
+
function lacksJsonSchema(node: Node, module: Module, hops = 0): boolean {
|
|
157
|
+
if (wrapsJsonSchema(node))
|
|
158
|
+
return false
|
|
159
|
+
|
|
160
|
+
let current = node
|
|
161
|
+
|
|
162
|
+
for (;;) {
|
|
163
|
+
if (WRAPPERS.has(current.type))
|
|
164
|
+
current = (current as unknown as { expression: Node }).expression
|
|
165
|
+
else if (current.type === 'CallExpression')
|
|
166
|
+
current = current.callee
|
|
167
|
+
else if (current.type === 'MemberExpression')
|
|
168
|
+
current = current.object
|
|
169
|
+
else
|
|
170
|
+
break
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (current.type === 'ObjectExpression')
|
|
174
|
+
return handWritten(current)
|
|
175
|
+
|
|
176
|
+
if (current.type !== 'Identifier' || hops > MAX_HOPS)
|
|
177
|
+
return false
|
|
178
|
+
|
|
179
|
+
if (fromValibot(module, current.name))
|
|
180
|
+
return true
|
|
181
|
+
|
|
182
|
+
const init = declared(module.ast, current.name)
|
|
183
|
+
|
|
184
|
+
if (init)
|
|
185
|
+
return lacksJsonSchema(init, module, hops + 1)
|
|
186
|
+
|
|
187
|
+
const imported = importedFrom(module, current.name)
|
|
188
|
+
const remote = imported && exported(imported.module, imported.name)
|
|
189
|
+
|
|
190
|
+
return remote !== undefined && lacksJsonSchema(remote.init, remote.module, hops + 1)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// The values of the options object's members named `names`.
|
|
194
|
+
function positions(options: Node | undefined, names: Set<string>): Node[] {
|
|
195
|
+
if (options?.type !== 'ObjectExpression')
|
|
196
|
+
return []
|
|
197
|
+
|
|
198
|
+
return options.properties.flatMap(property => isPlain(property) && names.has(keyName(property) ?? '') ? [property.value] : [])
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// A Standard Schema validator with no `~standard.jsonSchema` where an action's `input` or an API route's `body`, `query`, `params`, `headers` or `cookie` takes a schema: it still validates, but a form shows no constraints, a form or a query is not read as numbers and booleans, and OpenAPI and MCP show an open schema.
|
|
202
|
+
// Read in the TypeScript files and the fences of `.kay` files alike, from what the source shows: an object literal with `~standard`, and valibot's builders, followed through a `const` and a relative import.
|
|
203
|
+
export async function schemaJson(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
204
|
+
return scan(root, options, 'schema-without-json-schema', NEEDLE, ({ file, parsed, report }) => {
|
|
205
|
+
for (const { ast, base } of parsed) {
|
|
206
|
+
const { locals: actions, namespaces } = importsOf(ast, source => KAY.test(source), 'action')
|
|
207
|
+
const scope = apiScope(ast)
|
|
208
|
+
const module: Module = { ast, file }
|
|
209
|
+
|
|
210
|
+
walk(ast, (node) => {
|
|
211
|
+
if (node.type !== 'CallExpression')
|
|
212
|
+
return
|
|
213
|
+
|
|
214
|
+
let schemas: Node[] = []
|
|
215
|
+
|
|
216
|
+
if ((node.callee.type === 'Identifier' && actions.has(node.callee.name)) || (node.callee.type === 'MemberExpression' && !node.callee.computed && node.callee.object.type === 'Identifier' && namespaces.has(node.callee.object.name) && node.callee.property.type === 'Identifier' && node.callee.property.name === 'action'))
|
|
217
|
+
schemas = positions(node.arguments[0], ACTION_SCHEMAS)
|
|
218
|
+
else if (node.callee.type === 'MemberExpression' && !node.callee.computed && node.callee.property.type === 'Identifier' && ROUTE_METHODS.has(node.callee.property.name) && fromApi(node.callee.object, scope))
|
|
219
|
+
schemas = positions(node.arguments[2], ROUTE_SCHEMAS)
|
|
220
|
+
|
|
221
|
+
for (const schema of schemas.filter(candidate => lacksJsonSchema(candidate, module)))
|
|
222
|
+
report(base + schema.start, base + schema.end, 'this Standard Schema validator has no `~standard.jsonSchema`: it still validates, but a form shows no constraints, a form or a query is not read as numbers and booleans, and OpenAPI and MCP show an open schema', 'give it `~standard.jsonSchema` (Zod 4.2+ and ArkType 2.1.28+ carry it, valibot through `toStandardJsonSchema` from `@valibot/to-json-schema`) or build the schema with `s`', null)
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
}
|
package/src/check/secret-keys.ts
CHANGED
|
@@ -3,13 +3,14 @@ import type { Property } from './regroup'
|
|
|
3
3
|
import type { Edit } from './renamed-exports'
|
|
4
4
|
import { lintLevel } from '../compiler/lints'
|
|
5
5
|
import { configObjects, propertiesOf } from './config-objects'
|
|
6
|
+
import { regrouped } from './regroup'
|
|
6
7
|
import { scan } from './renamed-exports'
|
|
7
8
|
|
|
8
9
|
const NEEDLE = /\b(?:key|mcpKey|proxyKey)\b/
|
|
9
10
|
const TEST_KEYS = { mcpKey: 'mcp: { token }', proxyKey: 'proxy: { key: { header, secret } }' }
|
|
10
11
|
|
|
11
12
|
// The `key` of `mcp`, which is `token` since 1.105, and the string `key` of `proxy`, which names its header as `{ header }`, in the config; and the `mcpKey` and `proxyKey` options of `testSite()`, which are `config: { mcp: { token } }` and `config: { proxy: { key: { header, secret } } }`.
|
|
12
|
-
// The fix renames `mcp.key`, except for `false`, which has no token, and wraps the header of `proxy.key`, where the object is written in place; the options of `testSite()`
|
|
13
|
+
// The fix renames `mcp.key`, except for `false`, which has no token, and wraps the header of `proxy.key`, where the object is written in place; the options of `testSite()` move into a `config`, `proxyKey` only where the app's config names the header it travels in, and a `config` already written is left as it is.
|
|
13
14
|
export async function secretKeys(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
14
15
|
if (lintLevel('deprecated-secret-keys', options.lints) === 'allow')
|
|
15
16
|
return []
|
|
@@ -18,9 +19,13 @@ export async function secretKeys(root: string, options: CheckOptions): Promise<C
|
|
|
18
19
|
for (const { ast, base, text } of parsed) {
|
|
19
20
|
for (const { object, call } of configObjects(file, ast)) {
|
|
20
21
|
if (call === 'testSite') {
|
|
22
|
+
const header = options.proxyHeader
|
|
23
|
+
const shaped = (name: string, value: string) => name === 'mcpKey' ? `{ token: ${value} }` : `{ key: { header: '${header}', secret: ${value} } }`
|
|
24
|
+
const moves = regrouped(object, text, name => testGroup(name, header), false, shaped)
|
|
25
|
+
|
|
21
26
|
for (const [name, written] of Object.entries(TEST_KEYS)) {
|
|
22
27
|
for (const property of propertiesOf(object, name))
|
|
23
|
-
report(base + property.start, base + property.end, `\`${name}\` of \`testSite()\` is \`${written}\` in \`config\` since 1.105`, `write \`config: { ${written} }\``, null)
|
|
28
|
+
report(base + property.start, base + property.end, `\`${name}\` of \`testSite()\` is \`${written}\` in \`config\` since 1.105`, `write \`config: { ${written} }\``, name === 'mcpKey' || header !== undefined ? moves ?? null : null)
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
|
|
@@ -55,6 +60,14 @@ export async function secretKeys(root: string, options: CheckOptions): Promise<C
|
|
|
55
60
|
})
|
|
56
61
|
}
|
|
57
62
|
|
|
63
|
+
// Where a `testSite()` option moves to in its `config`, `proxyKey` only once the header it travels in is known.
|
|
64
|
+
function testGroup(name: string, header: string | undefined): [string, string] | undefined {
|
|
65
|
+
if (name === 'mcpKey')
|
|
66
|
+
return ['config', 'mcp']
|
|
67
|
+
|
|
68
|
+
return name === 'proxyKey' && header !== undefined ? ['config', 'proxy'] : undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
58
71
|
function fixOf(group: 'mcp' | 'proxy', property: Property, text: string, base: number, spread: boolean, off: boolean, taken: boolean): Edit[] | null {
|
|
59
72
|
if (spread || property.kind !== 'init' || property.method)
|
|
60
73
|
return null
|
|
@@ -33,6 +33,7 @@ import { redirectProblems } from '../server/redirects'
|
|
|
33
33
|
import { extensionEditor, patternShapes, routeMounts, scanEndpoints, scanRoutes, servedPaths } from '../server/routes'
|
|
34
34
|
import { readRuntimeRedirects } from '../server/runtime-redirects'
|
|
35
35
|
|
|
36
|
+
import { actionOptions } from './action-options'
|
|
36
37
|
import { actionReaders } from './action-readers'
|
|
37
38
|
import { actionType } from './action-type'
|
|
38
39
|
import { aiLanguage } from './ai-language'
|
|
@@ -44,31 +45,31 @@ import { cmsOptions } from './cms-options'
|
|
|
44
45
|
import { configGroups } from './config-groups'
|
|
45
46
|
import { configSwitches } from './config-switches'
|
|
46
47
|
import { contextImport } from './context-import'
|
|
47
|
-
import { ownFile } from './diagnose'
|
|
48
48
|
|
|
49
|
+
import { ownFile } from './diagnose'
|
|
49
50
|
import { endpointExports } from './endpoint-exports'
|
|
50
|
-
import { envFiles } from './env-files'
|
|
51
51
|
|
|
52
|
+
import { envFiles } from './env-files'
|
|
52
53
|
import { ASSET_TYPES, environmentTypes, kayPaths, packageTypes } from './env-types'
|
|
53
|
-
import { formatDurationNumbers } from './format-duration'
|
|
54
54
|
|
|
55
|
+
import { formatDurationNumbers } from './format-duration'
|
|
55
56
|
import { CONTENT_CHECK, EXPORTS_CHECK, exportsCheck, SETTINGS_CHECK, settingsCheck } from './generated'
|
|
56
|
-
import { guardOptions } from './guard-options'
|
|
57
57
|
|
|
58
|
+
import { guardOptions } from './guard-options'
|
|
58
59
|
import { unguardedRoutes, unguardedTools } from './guards'
|
|
59
60
|
import { hookContext } from './hook-context'
|
|
60
61
|
import { hookNames } from './hook-names'
|
|
61
62
|
import { i18nKeys } from './i18n-keys'
|
|
62
|
-
import { imagesKeys } from './images-keys'
|
|
63
63
|
|
|
64
|
+
import { imagesKeys } from './images-keys'
|
|
64
65
|
import { islandOnlyComponents } from './island-only'
|
|
66
|
+
|
|
65
67
|
import { diskFilesCalls, jobHandlers, jobOptions, scheduleCalls } from './job-shapes'
|
|
66
68
|
|
|
67
69
|
import { largePublicImages } from './large-images'
|
|
68
|
-
|
|
69
70
|
import { liveApi } from './live-api'
|
|
70
|
-
import { mailApi } from './mail-api'
|
|
71
71
|
|
|
72
|
+
import { mailApi } from './mail-api'
|
|
72
73
|
import { mcpRoutes } from './mcp-routes'
|
|
73
74
|
import { islandEvents, listenTarget, movedImports, navigateQuery, navigationHooks, persistedCall, persistedQuery } from './one-state-api'
|
|
74
75
|
import { unreadOpenSettings } from './open-settings'
|
|
@@ -80,7 +81,8 @@ import { removedUiTokens } from './removed-ui-tokens'
|
|
|
80
81
|
import { retiredLintLevels } from './retired-lints'
|
|
81
82
|
import { routeKeys } from './route-keys'
|
|
82
83
|
import { routeShadow, routeShadowPath } from './route-shadow'
|
|
83
|
-
import {
|
|
84
|
+
import { schemaBuilders } from './schema-builders'
|
|
85
|
+
import { schemaJson } from './schema-json'
|
|
84
86
|
import { secretKeys } from './secret-keys'
|
|
85
87
|
import { compileShadow, guardTypes, layoutQueries, matcherSource, outerSlots, pageRoute, serializeShadowSettings, SHADOW_SETTINGS, shadowOptionsFor, shadowPath } from './shadow'
|
|
86
88
|
import { socketFrames } from './socket-frames'
|
|
@@ -207,7 +209,9 @@ const PROJECT_CHECKS: ((input: ProjectCheckInput) => CheckDiagnostic[] | Promise
|
|
|
207
209
|
async ({ root, options }) => listenTarget(root, options),
|
|
208
210
|
async ({ root, options }) => movedImports(root, options),
|
|
209
211
|
|
|
210
|
-
async ({ root, options }) =>
|
|
212
|
+
async ({ root, options }) => schemaBuilders(root, options),
|
|
213
|
+
async ({ root, options }) => schemaJson(root, options),
|
|
214
|
+
async ({ root, options }) => actionOptions(root, options),
|
|
211
215
|
async ({ root, options }) => aiLanguage(root, options),
|
|
212
216
|
async ({ root, options }) => hookNames(root, options),
|
|
213
217
|
async ({ root, options }) => mailApi(root, options),
|
|
@@ -178,7 +178,7 @@ function attributeList(source: string, span: Span): Span {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
// `name={...}` or `name="..."` inside the attributes, as the span of the whole attribute.
|
|
181
|
-
function attributeNamed(source: string, list: Span, name: string): Span | undefined {
|
|
181
|
+
export function attributeNamed(source: string, list: Span, name: string): Span | undefined {
|
|
182
182
|
let start = source.indexOf(`${name}=`, list.start)
|
|
183
183
|
|
|
184
184
|
while (start !== -1 && start < list.end && NAME_CHAR.test(source[start - 1] ?? ' '))
|
package/src/check/tool-labels.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { snakeCase } from '../server/snake-case'
|
|
|
11
11
|
const SOURCE_FILE = /\.(?:kay|[cm]?ts|tsx)$/
|
|
12
12
|
const DECLARATION_FILE = /\.d\.[cm]?ts$/
|
|
13
13
|
const EXPORTED = /\bexport\s+(?:const|let|var|function|async\s+function)\s+([A-Za-z_$][\w$]*)/g
|
|
14
|
+
// The props of a Chat keyed by tool name.
|
|
15
|
+
const PROPS = new Set(['toolLabels', 'toolIcons'])
|
|
14
16
|
const QUOTED = /(['"`])([A-Z][\w-]*)\1/gi
|
|
15
17
|
// A name a second tool of the same name got: `add_note_2`.
|
|
16
18
|
const NUMBERED = /^(.+)_\d+$/
|
|
@@ -18,13 +20,13 @@ const NUMBERED = /^(.+)_\d+$/
|
|
|
18
20
|
interface Labelled {
|
|
19
21
|
file: string
|
|
20
22
|
source: string
|
|
21
|
-
keys: { name: string, at: number, end: number }[]
|
|
22
|
-
// The source with the keys of the `toolLabels` blanked, which is where tool names are searched, so a key never vouches for itself.
|
|
23
|
+
keys: { prop: string, name: string, at: number, end: number }[]
|
|
24
|
+
// The source with the keys of the `toolLabels` and `toolIcons` blanked, which is where tool names are searched, so a key never vouches for itself.
|
|
23
25
|
rest: string
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
// A key of a Chat's `toolLabels` that names no tool of the project: an action is a tool named by its export (`homeState` is `home_state`) or by its `tool.name`, and a function tool by its `name`, so a key matching none of them, nor any string the project writes, is a tool that was renamed or never was.
|
|
27
|
-
// Only a `toolLabels` written as an object literal is read, and only what the project's own modules write is searched.
|
|
28
|
+
// A key of a Chat's `toolLabels` or `toolIcons` that names no tool of the project: an action is a tool named by its export (`homeState` is `home_state`) or by its `tool.name`, and a function tool by its `name`, so a key matching none of them, nor any string the project writes, is a tool that was renamed or never was.
|
|
29
|
+
// Only a `toolLabels` or `toolIcons` written as an object literal is read, and only what the project's own modules write is searched.
|
|
28
30
|
export async function unknownToolLabels(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
29
31
|
if (lintLevel('unknown-tool-label', options.lints) === 'allow')
|
|
30
32
|
return []
|
|
@@ -32,12 +34,12 @@ export async function unknownToolLabels(root: string, options: CheckOptions): Pr
|
|
|
32
34
|
const files = (await findProjectFiles(root, SOURCE_FILE, { project: true, ownKayOnly: true })).filter(file => !DECLARATION_FILE.test(file))
|
|
33
35
|
const read = async (paths: string[]) => Promise.all(paths.map(async file => ({ file, source: await Bun.file(file).text() })))
|
|
34
36
|
const written = await read(files.filter(file => file.endsWith('.kay')))
|
|
35
|
-
const labelled = written.flatMap(({ file, source }) => source.includes('toolLabels') ? labelsIn(file, source) : [])
|
|
37
|
+
const labelled = written.flatMap(({ file, source }) => source.includes('toolLabels') || source.includes('toolIcons') ? labelsIn(file, source) : [])
|
|
36
38
|
|
|
37
39
|
if (labelled.length === 0)
|
|
38
40
|
return []
|
|
39
41
|
|
|
40
|
-
// The other modules are read once
|
|
42
|
+
// The other modules are read once one is found, as only they say which tools exist.
|
|
41
43
|
const texts = [...written, ...await read(files.filter(file => !file.endsWith('.kay')))]
|
|
42
44
|
const known = new Set<string>()
|
|
43
45
|
const labelledFiles = new Map(labelled.map(item => [item.file, item.rest]))
|
|
@@ -63,7 +65,7 @@ export async function unknownToolLabels(root: string, options: CheckOptions): Pr
|
|
|
63
65
|
if (level === 'allow' || known.has(key.name) || known.has(NUMBERED.exec(key.name)?.[1] ?? ''))
|
|
64
66
|
continue
|
|
65
67
|
|
|
66
|
-
found.push({ file, ...positionAt(source, key.at), end: key.end, message:
|
|
68
|
+
found.push({ file, ...positionAt(source, key.at), end: key.end, message: `\`${key.prop}\` names \`${key.name}\`, which no tool of this project is called`, help: 'name the tool as the model calls it: its export in snake case (`homeState` is `home_state`), its `tool.name` or the `name` of its `tool()`; or drop the key and give the action `tool: { label }`', code: 'unknown-tool-label', severity: level === 'warn' ? 'warning' : 'error' })
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -76,7 +78,7 @@ function labelsIn(file: string, source: string): Labelled[] {
|
|
|
76
78
|
|
|
77
79
|
for (const element of elementsIn(parseKay(source).template)) {
|
|
78
80
|
for (const attribute of element.attributes) {
|
|
79
|
-
if (attribute.kind !== 'expression' || source.slice(attribute.name.start, attribute.name.end)
|
|
81
|
+
if (attribute.kind !== 'expression' || !PROPS.has(source.slice(attribute.name.start, attribute.name.end)))
|
|
80
82
|
continue
|
|
81
83
|
|
|
82
84
|
const expression = parseObject(source.slice(attribute.expression.start, attribute.expression.end))
|
|
@@ -93,7 +95,7 @@ function labelsIn(file: string, source: string): Labelled[] {
|
|
|
93
95
|
const name = keyName(property.key)
|
|
94
96
|
|
|
95
97
|
if (name !== undefined)
|
|
96
|
-
keys.push({ name, at: attribute.expression.start + property.key.start, end: attribute.expression.start + property.key.end })
|
|
98
|
+
keys.push({ prop: source.slice(attribute.name.start, attribute.name.end), name, at: attribute.expression.start + property.key.start, end: attribute.expression.start + property.key.end })
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
}
|
package/src/check/ui-types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KayLibrary } from '../build/libraries'
|
|
2
2
|
import { realpathSync } from 'node:fs'
|
|
3
|
-
import { dirname, relative, sep } from 'node:path'
|
|
4
|
-
import { componentsNamed, forgetNames, uiOf } from '../build/ui'
|
|
3
|
+
import { dirname, join, relative, sep } from 'node:path'
|
|
4
|
+
import { componentsNamed, forgetNames, UI_FILE, uiLayerPathsOf, uiOf } from '../build/ui'
|
|
5
5
|
import { componentName } from '../compiler'
|
|
6
6
|
import { offered } from './ui'
|
|
7
7
|
|
|
@@ -29,7 +29,8 @@ function realOf(file: string): string {
|
|
|
29
29
|
|
|
30
30
|
// The `UiComponents` of `kay`, declared from the components `src/ui.ts` can restyle: each by the name a template calls it and by its specifier, with its part names and the values of its variants, so `defineUi` completes and checks an entry in the editor. An app with no `src/ui.ts` declares none.
|
|
31
31
|
export function uiTypes(root: string, libraries: KayLibrary[], own: string[]): string {
|
|
32
|
-
|
|
32
|
+
// An app with no `src/ui.ts` still takes the entries of its extensions' `ui` files, which a template's props are checked against.
|
|
33
|
+
const ui = uiOf(root) ?? (uiLayerPathsOf(root).length === 0 ? undefined : { file: join(root, UI_FILE), source: '', components: [], problems: [] })
|
|
33
34
|
|
|
34
35
|
if (ui === undefined)
|
|
35
36
|
return 'export {}\n'
|
package/src/check/ui.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { CheckDiagnostic } from '.'
|
|
|
2
2
|
import type { UiComponent, UiSource } from '../build/ui'
|
|
3
3
|
import type { Diagnostic, Span } from '../compiler/ast'
|
|
4
4
|
import { readFileSync, realpathSync } from 'node:fs'
|
|
5
|
-
import { basename,
|
|
6
|
-
import { componentFile, componentMatches, forgetNames, isComponentName, KAY_EXTENSION, uiOf } from '../build/ui'
|
|
5
|
+
import { basename, relative, sep } from 'node:path'
|
|
6
|
+
import { baseOf, componentFile, componentMatches, forgetNames, isComponentName, KAY_EXTENSION, uiLayersOf, uiOf } from '../build/ui'
|
|
7
7
|
import { ROUTE_FILES } from '../compiler'
|
|
8
8
|
import { templateFacts } from '../compiler/ast'
|
|
9
9
|
import { parseKay } from '../compiler/parser'
|
|
@@ -30,7 +30,7 @@ export function offered(file: string): { parts: Set<string>, variants: Record<st
|
|
|
30
30
|
|
|
31
31
|
// The specifier `src/ui.ts` writes a component by: a path from it for the app's own, the package's for a library's.
|
|
32
32
|
function specifierOf(ui: UiSource, file: string): string {
|
|
33
|
-
const from = realpathSync(
|
|
33
|
+
const from = realpathSync(baseOf(ui))
|
|
34
34
|
|
|
35
35
|
return file.startsWith(from + sep) ? `./${relative(from, file).split(sep).join('/')}` : `@kayjs/ui/${basename(file)}`
|
|
36
36
|
}
|
|
@@ -75,13 +75,8 @@ function componentProblems(ui: UiSource, component: UiComponent, report: (span:
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
// What `
|
|
79
|
-
|
|
80
|
-
const ui = uiOf(root)
|
|
81
|
-
|
|
82
|
-
if (ui === undefined)
|
|
83
|
-
return []
|
|
84
|
-
|
|
78
|
+
// What one `defineUi` file sets that the components it names do not have: an unknown or ambiguous component, an unknown part, and a file the compiler cannot read as written. An extension's file may name components this app lacks, so it is not told of those, only of a name two components bear.
|
|
79
|
+
function sourceProblems(ui: UiSource, own: boolean): CheckDiagnostic[] {
|
|
85
80
|
forgetNames(ui)
|
|
86
81
|
|
|
87
82
|
const found: Diagnostic[] = [...ui.problems]
|
|
@@ -98,8 +93,16 @@ export function uiProblems(root: string): CheckDiagnostic[] {
|
|
|
98
93
|
else if (file !== undefined)
|
|
99
94
|
named.set(file, component)
|
|
100
95
|
|
|
101
|
-
|
|
96
|
+
if (own || file !== undefined || (isComponentName(component.specifier) && componentMatches(ui, component).length > 1))
|
|
97
|
+
componentProblems(ui, component, report)
|
|
102
98
|
}
|
|
103
99
|
|
|
104
100
|
return found.map(diagnostic => fromCompile(ui.file, ui.source, diagnostic))
|
|
105
101
|
}
|
|
102
|
+
|
|
103
|
+
// What `src/ui.ts` and the extensions' `ui` files set that the components they name do not have.
|
|
104
|
+
export function uiProblems(root: string): CheckDiagnostic[] {
|
|
105
|
+
const ui = uiOf(root)
|
|
106
|
+
|
|
107
|
+
return [...uiLayersOf(root).flatMap(layer => sourceProblems(layer, false)), ...ui === undefined ? [] : sourceProblems(ui, true)]
|
|
108
|
+
}
|
|
@@ -17,12 +17,13 @@ interface Candidate {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const DEFINE_ENV = /\bdefineEnv\s*\(/
|
|
20
|
-
const SCHEMA = /export const env = defineEnv\(\s*(s|t)\.Object\(
|
|
20
|
+
const SCHEMA = /export const env = defineEnv\(\s*(?:(s|t)\.Object\()?\{(?=\r?\n|\})/
|
|
21
21
|
const FALLBACK = /^\s*\?\?\s*(?:'([^'\\\n]*)'|"([^"'\\\n]*)")(?=\s*(?:[;,)\]}]|\/\/|$))/
|
|
22
22
|
const ASSIGNED = /^\s*(?:\?\?|\|\||&&|\*\*|<<|>>>|>>|[-+*/%&|^])?=(?![=>])/
|
|
23
23
|
const DELETED = /\bdelete\s+$/
|
|
24
24
|
const ENV_NAME = /(?<![.\w$])env(?![\w$])/
|
|
25
25
|
const RAW_START = /^(?:process\.env|Bun\.env)/
|
|
26
|
+
const S_IMPORT = /import\s*\{[^}]*\bs\b[^}]*\}\s*from\s*['"]kay(?:\/server)?['"]/
|
|
26
27
|
const SCHEMA_PATH = /\.[mc]?ts$/
|
|
27
28
|
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/
|
|
28
29
|
const EXTENSION = /\.[mc]?[jt]s$/
|
|
@@ -140,7 +141,7 @@ function regexLiteralEnd(text: string, start: number): number | undefined {
|
|
|
140
141
|
return undefined
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
// The schema file a variable is added to: the project's `export const env = defineEnv(s.Object({` when it has one, `src/env.ts` when it has no `defineEnv` at all, nothing when it declares them in another shape.
|
|
144
|
+
// The schema file a variable is added to: the project's `export const env = defineEnv({` (or `defineEnv(s.Object({`) when it has one, `src/env.ts` when it has no `defineEnv` at all, nothing when it declares them in another shape.
|
|
144
145
|
async function schemaFile(root: string): Promise<{ file: string, existing: { prefix: string, at: number } | undefined } | undefined> {
|
|
145
146
|
const files = [...new Bun.Glob('src/**/*.{ts,tsx,js,mjs,mts,kay}').scanSync({ cwd: root })].sort().filter(file => !TEST_FILE.test(file))
|
|
146
147
|
const holders: { file: string, text: string }[] = []
|
|
@@ -158,11 +159,20 @@ async function schemaFile(root: string): Promise<{ file: string, existing: { pre
|
|
|
158
159
|
const [only, ...others] = holders
|
|
159
160
|
const found = others.length === 0 ? SCHEMA.exec(only!.text) : null
|
|
160
161
|
|
|
161
|
-
return found === null || !SCHEMA_PATH.test(only!.file) ? undefined : { file: only!.file, existing: { prefix: found[1]
|
|
162
|
+
return found === null || !SCHEMA_PATH.test(only!.file) ? undefined : { file: only!.file, existing: { prefix: found[1] ?? 's', at: found.index + found[0].length } }
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
function field(prefix: string, name: string, fallback: string | undefined): string {
|
|
165
|
-
|
|
166
|
+
// `t` is Elysia's, which the project's schema was written with; `s` is kay's.
|
|
167
|
+
if (prefix === 't')
|
|
168
|
+
return `${name}: ${fallback === undefined ? 't.Optional(t.String())' : `t.String({ default: '${fallback}' })`}`
|
|
169
|
+
|
|
170
|
+
return `${name}: ${fallback === undefined ? 's.string({ optional: true })' : `s.string({ default: '${fallback}' })`}`
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// A record of fields needs no `s` of its own until a variable is declared with it.
|
|
174
|
+
function withS(text: string, prefix: string): string {
|
|
175
|
+
return prefix !== 's' || S_IMPORT.test(text) ? text : insertImport(text, 'import { s } from \'kay\'')
|
|
166
176
|
}
|
|
167
177
|
|
|
168
178
|
// Declares the variables `process.env.X` is read for with no schema, in the schema file of the project, and rewrites their reads to `env.X`, a `?? 'default'` becoming the variable's default. `files` are the only files it may change: a variable with a read outside them is left alone, as is one whose read is assigned or deleted, destructured, in a `.kay` file or a file with an `env` of its own, inside a string, a template or a comment, or in the schema file itself. Answers the variables declared and the reads rewritten.
|
|
@@ -234,7 +244,7 @@ export async function declareRawEnv(root: string, undeclared: ReadonlySet<string
|
|
|
234
244
|
|
|
235
245
|
// The schema goes first, so a failed write leaves no file importing what is not there.
|
|
236
246
|
if (schema.existing === undefined) {
|
|
237
|
-
await writeFile(schema.file, `import { s } from 'kay'\nimport { defineEnv } from 'kay/server'\n\nexport const env = defineEnv(
|
|
247
|
+
await writeFile(schema.file, `import { s } from 'kay'\nimport { defineEnv } from 'kay/server'\n\nexport const env = defineEnv({\n${fields.map(line => ` ${line},\n`).join('')}})\n`)
|
|
238
248
|
}
|
|
239
249
|
else {
|
|
240
250
|
const text = await readFile(schema.file, 'utf8')
|
|
@@ -242,7 +252,9 @@ export async function declareRawEnv(root: string, undeclared: ReadonlySet<string
|
|
|
242
252
|
const eol = text.includes('\r\n') ? '\r\n' : '\n'
|
|
243
253
|
const indent = INDENT.exec(text.slice(at))?.[1] ?? ' '
|
|
244
254
|
|
|
245
|
-
|
|
255
|
+
const added = `${text.slice(0, at)}${fields.map(line => `${eol}${indent}${line},`).join('')}${text[at] === '}' ? eol : ''}${text.slice(at)}`
|
|
256
|
+
|
|
257
|
+
await writeFile(schema.file, withS(added, schema.existing.prefix))
|
|
246
258
|
}
|
|
247
259
|
|
|
248
260
|
for (const [file, list] of edits) {
|
package/src/commands/routes.ts
CHANGED
|
@@ -163,7 +163,7 @@ async function apiRoutes(root: string, config: KayConfig, modules: ApiModule[],
|
|
|
163
163
|
const instance = typeof exported === 'function' && extension !== undefined ? await (exported as (app: ExtensionApp) => unknown)(await appOf(extension)) : exported
|
|
164
164
|
|
|
165
165
|
if (!(instance instanceof Elysia))
|
|
166
|
-
throw new
|
|
166
|
+
throw new TypeError('it exports no Elysia instance by default')
|
|
167
167
|
|
|
168
168
|
for (const route of instance.routes.filter(route => ROUTE_METHODS.test(route.method)))
|
|
169
169
|
listed.push({ methods: route.method.toUpperCase(), path: apiRoutePath(module.mount, route.path), kind: 'api', by: shown(module.file), file: shown(module.file), notes, guards })
|
package/src/compiler/a11y.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Reader } from './a11y-markup'
|
|
2
2
|
import type { Diagnostic, ElementNode, KayFile, NamedAttribute, Node, SnippetNode } from './ast'
|
|
3
|
+
import { autocompleteByName } from '../runtime/form-types'
|
|
3
4
|
import { elementHasContent, markupLints, reader } from './a11y-markup'
|
|
4
5
|
import { ABSTRACT_ROLES, ARIA_ATTRIBUTES, ARIA_STATE_VALUES, closest, REQUIRED_STATES, ROLES, validAutocomplete } from './aria'
|
|
5
6
|
import { childBlocks, nodeExpressions, sectionOf, visitNodes } from './ast'
|
|
@@ -11,6 +12,12 @@ const UNLABELLED_TYPES = new Set(['hidden', 'submit', 'reset', 'button', 'image'
|
|
|
11
12
|
// What names an element besides its content.
|
|
12
13
|
const NAMING = ['aria-label', 'aria-labelledby', 'title']
|
|
13
14
|
const HEADING = /^h([1-6])$/
|
|
15
|
+
|
|
16
|
+
// Whether an input has an `autocomplete`: written, or given by the schema at render, `email` for an email field and what the name of a password asks for.
|
|
17
|
+
function givesAutocomplete(written: boolean, field: string | undefined, type: string): boolean {
|
|
18
|
+
return written || (field !== undefined && (type === 'email' || autocompleteByName(field) !== undefined))
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
const UI_IMPORT = /^import\b[^\n]*['"]@kayjs\/ui\/[^'"\n]*['"];?[ \t]*$/gm
|
|
15
22
|
const TOOLTIP_IMPORT = /^import\s+Tooltip\s+from\s+['"]@kayjs\/ui\/tooltip\.kay['"]/m
|
|
16
23
|
const WHITESPACE_CHAR = /\s/
|
|
@@ -556,7 +563,7 @@ function elementLints(file: KayFile): Diagnostic[] {
|
|
|
556
563
|
lint(pointer.name, 'mouse-only-event', `\`${text(pointer.name)}\` has no keyboard counterpart on this \`${element.name}\``, { note: 'what the pointer reveals or hides is never reached by a keyboard user, whom only focus tells', help: `handle \`${wanted}\` the same way, on an element the keyboard reaches` })
|
|
557
564
|
}
|
|
558
565
|
|
|
559
|
-
if (element.name === 'input' && type !== undefined && FILLED_TYPES.has(type) && !has(element, 'autocomplete'))
|
|
566
|
+
if (element.name === 'input' && type !== undefined && FILLED_TYPES.has(type) && !givesAutocomplete(has(element, 'autocomplete'), staticValue(element, 'field'), type))
|
|
560
567
|
lint(element, 'missing-autocomplete', `This \`${type}\` input has no \`autocomplete\``, { note: 'a browser or a password manager fills a field from it, which people with motor or memory difficulties rely on', help: type === 'email' ? 'write `autocomplete="email"`, or `username`' : 'write `autocomplete="current-password"` or `new-password`' })
|
|
561
568
|
|
|
562
569
|
const autocomplete = staticValue(element, 'autocomplete')
|
package/src/compiler/ast.ts
CHANGED
|
@@ -354,7 +354,7 @@ export function formFieldOf(element: ElementNode, source: string, inherited?: st
|
|
|
354
354
|
field.fill = 'content'
|
|
355
355
|
else if (element.name === 'select')
|
|
356
356
|
field.fill = attributes.has('multiple') ? undefined : 'selected'
|
|
357
|
-
else if (inputType === 'checkbox' || inputType === 'radio')
|
|
357
|
+
else if (inputType === 'checkbox' || inputType === 'radio' || (type === undefined && attributes.has('checked')))
|
|
358
358
|
field.fill = 'checked'
|
|
359
359
|
else if (!UNFILLED_TYPES.has(inputType))
|
|
360
360
|
field.fill = 'value'
|
|
@@ -6,7 +6,7 @@ type ExpressionAttribute = Extract<NamedAttribute, { kind: 'expression' }>
|
|
|
6
6
|
const BOUND_NAME = /^\s*[A-Z_$][\w$]*(?:\s*\.\s*[A-Z_$][\w$]*)*\s*$/i
|
|
7
7
|
|
|
8
8
|
// The callback a bound prop reports its changes through: `open` and `onOpenChange`.
|
|
9
|
-
function changeName(prop: string): string {
|
|
9
|
+
export function changeName(prop: string): string {
|
|
10
10
|
return `on${prop[0]!.toUpperCase()}${prop.slice(1)}Change`
|
|
11
11
|
}
|
|
12
12
|
|