@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,130 @@
|
|
|
1
|
+
import type { CheckDiagnostic } from '.'
|
|
2
|
+
import type { Fix } from '../compiler/ast'
|
|
3
|
+
import type { Node } from '../compiler/estree'
|
|
4
|
+
import type { LintLevels } from '../compiler/lints'
|
|
5
|
+
import { findProjectFiles } from '../build/files'
|
|
6
|
+
import { parseProgram } from '../compiler/estree'
|
|
7
|
+
import { OLD_LINK_FLAGS } from '../compiler/link-flags'
|
|
8
|
+
import { lintLevel } from '../compiler/lints'
|
|
9
|
+
import { childrenOf } from './ast'
|
|
10
|
+
|
|
11
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/
|
|
12
|
+
const OLD_FLAG = new RegExp(`(?<![\\w-])(${Object.keys(OLD_LINK_FLAGS).join('|')})(?![\\w-])`, 'g')
|
|
13
|
+
const DATASET_END = /dataset$/
|
|
14
|
+
const ATTRIBUTE_CALL = /\.(?:get|has|set|remove|toggle)Attribute\(\s*$/
|
|
15
|
+
|
|
16
|
+
// The `dataset` property of each old flag: `data-keep-scroll` is `keepScroll`.
|
|
17
|
+
const DATASET_NAMES = new Map(Object.keys(OLD_LINK_FLAGS).map(name => [name.slice(5).replace(/-(\w)/g, (_, letter: string) => letter.toUpperCase()), name]))
|
|
18
|
+
|
|
19
|
+
interface Scanned {
|
|
20
|
+
// The content of each string literal and template chunk, as `[start, end]` offsets.
|
|
21
|
+
strings: [number, number][]
|
|
22
|
+
// The `x.dataset.<flag>` member expressions, and whether each is assigned, updated or deleted.
|
|
23
|
+
datasets: { node: Node, written: boolean, direct: boolean }[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const WRAPPERS = new Set(['ChainExpression', 'TSNonNullExpression', 'ParenthesizedExpression'])
|
|
27
|
+
|
|
28
|
+
// The expression under any wrappers.
|
|
29
|
+
function unwrapped(node: Node): Node {
|
|
30
|
+
let inner = node
|
|
31
|
+
|
|
32
|
+
while (inner.type === 'ChainExpression' || inner.type === 'TSNonNullExpression' || inner.type === 'ParenthesizedExpression')
|
|
33
|
+
inner = inner.expression
|
|
34
|
+
|
|
35
|
+
return inner
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isDataset(node: Node): boolean {
|
|
39
|
+
const inner = unwrapped(node)
|
|
40
|
+
|
|
41
|
+
return inner.type === 'MemberExpression' && !inner.computed && inner.property.type === 'Identifier' && inner.property.name === 'dataset'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// What the parsed program holds that names a flag, so a regex literal or a comment cannot shift what is a string.
|
|
45
|
+
function scan(source: string): Scanned {
|
|
46
|
+
const found: Scanned = { strings: [], datasets: [] }
|
|
47
|
+
const visit = (node: Node, ancestors: Node[]) => {
|
|
48
|
+
if (node.type === 'Literal' && typeof node.value === 'string') {
|
|
49
|
+
found.strings.push([node.start + 1, node.end - 1])
|
|
50
|
+
}
|
|
51
|
+
else if (node.type === 'TemplateElement') {
|
|
52
|
+
// The span holds its delimiters: a backtick or `}` before, a backtick or `${` after.
|
|
53
|
+
found.strings.push([node.start + 1, node.end - (source[node.end - 1] === '`' ? 1 : 2)])
|
|
54
|
+
}
|
|
55
|
+
else if (node.type === 'MemberExpression' && !node.computed && node.property.type === 'Identifier' && DATASET_NAMES.has(node.property.name) && isDataset(node.object)) {
|
|
56
|
+
// Through `?.`, `!` and parentheses: `delete el?.dataset.keepScroll` and `el.dataset!.keepScroll = 1` write it.
|
|
57
|
+
let at = ancestors.length - 1
|
|
58
|
+
let target: Node = node
|
|
59
|
+
|
|
60
|
+
while (at >= 0 && WRAPPERS.has(ancestors[at]!.type))
|
|
61
|
+
target = ancestors[at--]!
|
|
62
|
+
|
|
63
|
+
const parent = ancestors[at]
|
|
64
|
+
const assigned = parent?.type === 'AssignmentExpression' && parent.left === target
|
|
65
|
+
|
|
66
|
+
found.datasets.push({ node, written: assigned || parent?.type === 'UpdateExpression' || (parent?.type === 'UnaryExpression' && parent.operator === 'delete'), direct: unwrapped(node.object) === node.object })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (const child of childrenOf(node))
|
|
70
|
+
visit(child, [...ancestors, node])
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
visit(parseProgram(source, { lang: 'ts', recover: true }).program, [])
|
|
74
|
+
|
|
75
|
+
return found
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// The selectors, attribute reads and `dataset` reads of an app's test files that name a link flag by its name before 1.105, which `deprecated-link-flags` rewrites in the templates: `[data-keep-scroll]` is written `[data-scroll=keep]`, as the template's attribute was.
|
|
79
|
+
// An attribute read by name (`getAttribute('data-keep-scroll')`) and a read of `dataset.keepScroll` get a fix that is not safe, as the new name holds a word where the old one was there or not; any other string naming the flag (a selector with a value, one built in a template) and a write of `dataset` are reported with no fix.
|
|
80
|
+
export async function linkFlagTests(root: string, levels: LintLevels | undefined): Promise<CheckDiagnostic[]> {
|
|
81
|
+
const level = lintLevel('deprecated-link-flags', levels)
|
|
82
|
+
|
|
83
|
+
if (level === 'allow')
|
|
84
|
+
return []
|
|
85
|
+
|
|
86
|
+
const found: CheckDiagnostic[] = []
|
|
87
|
+
|
|
88
|
+
for (const file of (await findProjectFiles(root, TEST_FILE, { project: true, ownKayOnly: true })).sort()) {
|
|
89
|
+
const source = await Bun.file(file).text()
|
|
90
|
+
const { strings, datasets } = scan(source)
|
|
91
|
+
const report = (start: number, end: number, message: string, help: string, fixes: Fix[] | undefined) => {
|
|
92
|
+
const before = source.slice(0, start).split('\n')
|
|
93
|
+
|
|
94
|
+
found.push({ file, line: before.length, column: before.at(-1)!.length + 1, end, severity: level === 'warn' ? 'warning' : 'error', code: 'deprecated-link-flags', message, help, ...fixes === undefined ? {} : { fixes } })
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
for (const match of source.matchAll(OLD_FLAG)) {
|
|
98
|
+
const name = match[1]!
|
|
99
|
+
const end = match.index + name.length
|
|
100
|
+
const string = strings.find(([from, to]) => match.index >= from && end <= to)
|
|
101
|
+
|
|
102
|
+
if (string === undefined)
|
|
103
|
+
continue
|
|
104
|
+
|
|
105
|
+
const next = OLD_LINK_FLAGS[name]!
|
|
106
|
+
const written = `${next.name}=${next.value}`
|
|
107
|
+
const selector = source[match.index - 1] === '[' && source[end] === ']'
|
|
108
|
+
const read = !selector && string[1] - string[0] === name.length && ATTRIBUTE_CALL.test(source.slice(Math.max(0, string[0] - 201), string[0] - 1))
|
|
109
|
+
let fixes: Fix[] | undefined
|
|
110
|
+
|
|
111
|
+
if (selector)
|
|
112
|
+
fixes = [{ title: `write [${written}]`, safe: true, edits: [{ start: match.index - 1, end: end + 1, text: `[${written}]` }] }]
|
|
113
|
+
else if (read)
|
|
114
|
+
fixes = [{ title: `write ${next.name}`, safe: false, edits: [{ start: match.index, end, text: next.name }] }]
|
|
115
|
+
|
|
116
|
+
report(match.index, end, `\`${name}\` is \`${written}\`, deprecated since 1.105: a template written with the new attribute no longer matches this`, `select \`[${written}]\`; an attribute read follows the new name, whose value is \`${next.value}\` where the old one was present`, fixes)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
for (const { node, written, direct } of datasets) {
|
|
120
|
+
const member = node as Node & { object: Node, property: Node & { name: string } }
|
|
121
|
+
const old = OLD_LINK_FLAGS[DATASET_NAMES.get(member.property.name)!]!
|
|
122
|
+
const to = `dataset.${old.name.slice(5)} === '${old.value}'`
|
|
123
|
+
const fixes: Fix[] | undefined = written || !direct ? undefined : [{ title: `write ${to}`, safe: false, edits: [{ start: node.start, end: node.end, text: `(${source.slice(member.object.start, member.object.end).replace(DATASET_END, '')}${to})` }] }]
|
|
124
|
+
|
|
125
|
+
report(node.start, node.end, `\`dataset.${member.property.name}\` is \`${to}\`, deprecated since 1.105: the template's attribute is \`${old.name}\``, `read \`${to}\`; a write is set on \`${old.name}\` by hand`, fixes)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return found.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column)
|
|
130
|
+
}
|
package/src/check/project.ts
CHANGED
|
@@ -32,6 +32,7 @@ import { dockerfileProblems } from './dockerfile'
|
|
|
32
32
|
import { CONTENT_CHECK, contentPropsCheck } from './generated'
|
|
33
33
|
import { browserModules, islandEdges } from './island-modules'
|
|
34
34
|
import { componentImporters, islandOnlyComponents, renderedInIslands } from './island-only'
|
|
35
|
+
import { linkFlagTests } from './link-flag-tests'
|
|
35
36
|
import { FILES_MARKER, stampOf } from './loaded'
|
|
36
37
|
import { renamedPackages } from './renamed-packages'
|
|
37
38
|
import { configSeoLints } from './seo'
|
|
@@ -105,13 +106,13 @@ export function configProblems(root: string, options: CheckOptions, types: Shado
|
|
|
105
106
|
// The collections may still be read, which only the feeds and their own problems wait for.
|
|
106
107
|
export async function projectProblems(root: string, options: CheckOptions, collections: ContentChecks | Promise<ContentChecks>, memory?: ProbeMemory, scanned?: ServedProject): Promise<CheckDiagnostic[]> {
|
|
107
108
|
return inWalkScope(async () => {
|
|
108
|
-
const [content, messages, boot, modules, packages] = await Promise.all([collections, checkMessages(root, options, memory), (async () => {
|
|
109
|
+
const [content, messages, boot, modules, packages, linkTests] = await Promise.all([collections, checkMessages(root, options, memory), (async () => {
|
|
109
110
|
const read = await collections
|
|
110
111
|
|
|
111
112
|
return bootProblems(resolve(root), options, read.feeds, scanned, read.routes)
|
|
112
|
-
})(), moduleLints(root, options), renamedPackages(root, options.lints)])
|
|
113
|
+
})(), moduleLints(root, options), renamedPackages(root, options.lints), linkFlagTests(root, options.lints)])
|
|
113
114
|
|
|
114
|
-
return [...content.problems, ...messages, ...boot, ...modules, ...packages, ...uiProblems(root), ...contextModuleProblems(root)]
|
|
115
|
+
return [...content.problems, ...messages, ...boot, ...modules, ...packages, ...linkTests, ...uiProblems(root), ...contextModuleProblems(root)]
|
|
115
116
|
})
|
|
116
117
|
}
|
|
117
118
|
|
|
@@ -71,7 +71,7 @@ function isErrorStatus(node: Node | undefined): boolean {
|
|
|
71
71
|
return node?.type === 'Literal' && typeof node.value === 'number' && node.value >= 400 && node.value <= 599
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
// `return ctx.fail(status, data, errors)`, `return ctx.deny(status, { data, errors })` since 1.105: an action refuses as a guard and a page do. A text `data` is the form's message
|
|
74
|
+
// `return ctx.fail(status, data, errors)`, `return ctx.deny(status, { data, errors })` since 1.105: an action refuses as a guard and a page do. A text `data` is the form's message and is written as the `message`, and a call with neither data nor errors is left, as `deny(status)` stops with plain text.
|
|
75
75
|
// Found on `ctx.fail` of a handler's `ctx`; the fix is made where the call is returned, as `deny` throws and `fail` did not.
|
|
76
76
|
function failCalls({ parsed, report }: Found): void {
|
|
77
77
|
for (const { ast, base, text } of parsed) {
|
|
@@ -83,7 +83,7 @@ function failCalls({ parsed, report }: Found): void {
|
|
|
83
83
|
const parts: Part[] = []
|
|
84
84
|
|
|
85
85
|
if (data !== undefined && !isUndefined(data))
|
|
86
|
-
parts.push(['data', text.slice(data.start, data.end)])
|
|
86
|
+
parts.push([isText(data) ? 'message' : 'data', text.slice(data.start, data.end)])
|
|
87
87
|
|
|
88
88
|
if (errors !== undefined && !isUndefined(errors))
|
|
89
89
|
parts.push(['errors', text.slice(errors.start, errors.end)])
|
package/src/check/regroup.ts
CHANGED
|
@@ -12,8 +12,8 @@ export function nameOf(property: Node): string {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
// The edits that group the old keys, leaving every other property, its comments and the object's layout as written: the first old property of a feature becomes `feature: { part: value }` holding all of its parts, the others are removed. Undefined where that cannot be done without reading what a value is: a spread, a computed or shorthand key, a part named twice, a feature written both ways, or a comment that a removal would take.
|
|
15
|
-
// With `whole`, a part is the property as written (a shorthand or a method included) rather than `part: value`, for a group that takes the keys under their own names.
|
|
16
|
-
export function regrouped(object: NodeOfType<'ObjectExpression'>, text: string, movedTo: (name: string, property: Property) => [string, string] | undefined, whole = false): Edit[] | undefined {
|
|
15
|
+
// With `whole`, a part is the property as written (a shorthand or a method included) rather than `part: value`, for a group that takes the keys under their own names. `shaped` writes the value a part takes from the old key's name and value text, for a part that wraps it.
|
|
16
|
+
export function regrouped(object: NodeOfType<'ObjectExpression'>, text: string, movedTo: (name: string, property: Property) => [string, string] | undefined, whole = false, shaped?: (name: string, value: string) => string): Edit[] | undefined {
|
|
17
17
|
const properties: Property[] = []
|
|
18
18
|
|
|
19
19
|
for (const property of object.properties) {
|
|
@@ -43,7 +43,9 @@ export function regrouped(object: NodeOfType<'ObjectExpression'>, text: string,
|
|
|
43
43
|
if ((property.shorthand && !whole) || held.parts.has(part))
|
|
44
44
|
return undefined
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
const value = text.slice(property.value.start, property.value.end)
|
|
47
|
+
|
|
48
|
+
held.parts.set(part, whole ? text.slice(property.start, property.end) : shaped?.(name, value) ?? value)
|
|
47
49
|
features.set(feature, held)
|
|
48
50
|
moved.add(index)
|
|
49
51
|
}
|
|
@@ -4,7 +4,7 @@ import { writeFile } from 'node:fs/promises'
|
|
|
4
4
|
import { basename } from 'node:path'
|
|
5
5
|
import { findProjectFiles } from '../build/files'
|
|
6
6
|
import { lintLevel } from '../compiler/lints'
|
|
7
|
-
import { OLD_PACKAGE_NAME, RENAMED_IN, RENAMED_PACKAGES
|
|
7
|
+
import { OLD_PACKAGE_NAME, RENAMED_IN, RENAMED_PACKAGES } from '../package-names'
|
|
8
8
|
|
|
9
9
|
// The files that name a package: the scripts, components and stylesheets of the project, and its manifest and tsconfigs.
|
|
10
10
|
const NAMING_FILE = /^(?:package\.json|tsconfig[\w.-]*\.json)$|\.(?:[cm]?[jt]sx?|kay|css)$/
|
|
@@ -37,8 +37,18 @@ const BEFORE_NAME_IN_STRING = /^(?:npm:|[\w./-]*node_modules\/)?$/
|
|
|
37
37
|
const LINE_COMMENT = /(?:^|[^:])\/\//
|
|
38
38
|
const KEY_END = /^"\s*:/
|
|
39
39
|
|
|
40
|
-
//
|
|
41
|
-
|
|
40
|
+
// A tsconfig names a package anywhere a string does: `extends`, `types`, `paths`.
|
|
41
|
+
type Kind = 'manifest' | 'tsconfig' | 'stylesheet' | 'script'
|
|
42
|
+
|
|
43
|
+
// What opens the string of a module specifier in a script or a component: `from`, `import 'x'`, `import(`, `require(`, `require.resolve(`, `import.meta.resolve(`, `declare module` and a test's `mock.module(`.
|
|
44
|
+
const SPECIFIER_BEFORE = /(?:\b(?:from|import|module)|\b(?:require|require\.resolve|import\.meta\.resolve|import|mock\.module)\s*\()\s*$/
|
|
45
|
+
// A config key: a quoted name keyed to anything but a string that names a package or a version, which is data (a table of renames, a fixture of versions): `librarySettings: { '@kayjs/ui': './ui.ts' }` or a component path keyed to its options.
|
|
46
|
+
const CONFIG_KEY_END = /^[\w./*-]*["'`]\s*:\s*(?!\s|["'`](?:@kay|[~^]?\d))/
|
|
47
|
+
// What opens the path of a stylesheet that names a package.
|
|
48
|
+
const STYLESHEET_BEFORE = /@(?:import|plugin|source|config|reference)\b[^;'"`]*$/
|
|
49
|
+
|
|
50
|
+
// Whether the name at `index` is what the project depends on, not a word of a comment, a sentence or a string of data: in a stylesheet the path of an `@import`, `@plugin` or `@source`, in a script the specifier of an import, a `require` or `import()` or a config key, in a manifest a key or an alias, in a tsconfig any string.
|
|
51
|
+
function namesAPackage(source: string, index: number, end: number, kind: Kind, comments: [number, number][]): boolean {
|
|
42
52
|
if (comments.some(([from, to]) => index >= from && index < to))
|
|
43
53
|
return false
|
|
44
54
|
|
|
@@ -52,7 +62,36 @@ function namesAPackage(source: string, index: number, end: number, manifest: boo
|
|
|
52
62
|
if (LINE_COMMENT.test(before.slice(0, quote)))
|
|
53
63
|
return false
|
|
54
64
|
|
|
55
|
-
|
|
65
|
+
if (kind === 'manifest')
|
|
66
|
+
return before.endsWith('npm:') || KEY_END.test(source.slice(end))
|
|
67
|
+
|
|
68
|
+
if (kind === 'tsconfig')
|
|
69
|
+
return true
|
|
70
|
+
|
|
71
|
+
const opening = source.slice(Math.max(0, lineStart + quote - 200), lineStart + quote)
|
|
72
|
+
|
|
73
|
+
if (kind === 'stylesheet')
|
|
74
|
+
return STYLESHEET_BEFORE.test(opening)
|
|
75
|
+
|
|
76
|
+
return SPECIFIER_BEFORE.test(opening) || (before.slice(quote + 1) === '' && CONFIG_KEY_END.test(source.slice(end)))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function kindOf(file: string): Kind {
|
|
80
|
+
if (basename(file) === 'package.json')
|
|
81
|
+
return 'manifest'
|
|
82
|
+
|
|
83
|
+
if (file.endsWith('.json'))
|
|
84
|
+
return 'tsconfig'
|
|
85
|
+
|
|
86
|
+
return file.endsWith('.css') ? 'stylesheet' : 'script'
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The position of each old package name a file depends on, as the lint and `kay upgrade` rewrite them.
|
|
90
|
+
export function oldNamesIn(file: string, source: string): RegExpExecArray[] {
|
|
91
|
+
const kind = kindOf(file)
|
|
92
|
+
const comments = kind === 'manifest' || kind === 'tsconfig' ? [] : [...source.matchAll(BLOCK_COMMENT)].map((c): [number, number] => [c.index, c.index + c[0].length])
|
|
93
|
+
|
|
94
|
+
return [...source.matchAll(OLD_PACKAGE_NAME)].filter(match => namesAPackage(source, match.index, match.index + match[0].length, kind, comments))
|
|
56
95
|
}
|
|
57
96
|
|
|
58
97
|
// Every file of the project that names a package, but its manifest, written with the new names: what `kay upgrade` does before it runs the kay it installed, which loads the project's config and so cannot meet an old name.
|
|
@@ -62,14 +101,24 @@ export async function renameProjectFiles(root: string): Promise<void> {
|
|
|
62
101
|
continue
|
|
63
102
|
|
|
64
103
|
const source = await Bun.file(file).text()
|
|
65
|
-
const
|
|
104
|
+
const names = oldNamesIn(file, source)
|
|
105
|
+
|
|
106
|
+
if (names.length === 0)
|
|
107
|
+
continue
|
|
66
108
|
|
|
67
|
-
|
|
68
|
-
|
|
109
|
+
let renamed = ''
|
|
110
|
+
let from = 0
|
|
111
|
+
|
|
112
|
+
for (const match of names) {
|
|
113
|
+
renamed += source.slice(from, match.index) + RENAMED_PACKAGES[match[0]]!
|
|
114
|
+
from = match.index + match[0].length
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
await writeFile(file, renamed + source.slice(from))
|
|
69
118
|
}
|
|
70
119
|
}
|
|
71
120
|
|
|
72
|
-
// kay and its libraries under the `@kaynooo` scope, named
|
|
121
|
+
// kay and its libraries under the `@kaynooo` scope, named as an import, `require` or `import()` specifier, a config key, a stylesheet's `@import` or `@plugin` path or a package.json entry, which are `@kayjs/*` since 1.104: each name found gets a safe fix writing the new one.
|
|
73
122
|
// A package.json that lists the new name already would get the entry twice, so its names are reported with a fix that is not safe; one that does not has the range raised to the first version under the new name.
|
|
74
123
|
export async function renamedPackages(root: string, levels: LintLevels | undefined): Promise<CheckDiagnostic[]> {
|
|
75
124
|
const level = lintLevel('deprecated-package-names', levels)
|
|
@@ -83,14 +132,9 @@ export async function renamedPackages(root: string, levels: LintLevels | undefin
|
|
|
83
132
|
const source = await Bun.file(file).text()
|
|
84
133
|
const manifest = basename(file) === 'package.json'
|
|
85
134
|
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
for (const match of source.matchAll(OLD_PACKAGE_NAME)) {
|
|
135
|
+
for (const match of oldNamesIn(file, source)) {
|
|
89
136
|
const name = match[0]
|
|
90
137
|
|
|
91
|
-
if (!namesAPackage(source, match.index, match.index + name.length, manifest, comments))
|
|
92
|
-
continue
|
|
93
|
-
|
|
94
138
|
const next = RENAMED_PACKAGES[name]!
|
|
95
139
|
const before = source.slice(0, match.index).split('\n')
|
|
96
140
|
const raised = manifest ? raisedRange(source, match.index + name.length) : undefined
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type { CheckDiagnostic, CheckOptions } from '.'
|
|
2
|
+
import type { Node } from '../compiler/estree'
|
|
3
|
+
import type { Edit } from './renamed-exports'
|
|
4
|
+
import { lintLevel } from '../compiler/lints'
|
|
5
|
+
import { importsOf, walk } from './ast'
|
|
6
|
+
import { scan } from './renamed-exports'
|
|
7
|
+
|
|
8
|
+
// Each PascalCase builder with the lowercase one that replaces it, the position of its options and the option names that changed.
|
|
9
|
+
const BUILDERS: Record<string, { name: string, options: number, keys?: Record<string, string> }> = {
|
|
10
|
+
String: { name: 'string', options: 0, keys: { minLength: 'min', maxLength: 'max' } },
|
|
11
|
+
Secret: { name: 'secret', options: 0, keys: { minLength: 'min', maxLength: 'max' } },
|
|
12
|
+
Number: { name: 'number', options: 0, keys: { minimum: 'min', maximum: 'max' } },
|
|
13
|
+
Numeric: { name: 'number', options: 0, keys: { minimum: 'min', maximum: 'max' } },
|
|
14
|
+
Integer: { name: 'int', options: 0, keys: { minimum: 'min', maximum: 'max' } },
|
|
15
|
+
Boolean: { name: 'boolean', options: 0 },
|
|
16
|
+
BooleanString: { name: 'boolean', options: 0 },
|
|
17
|
+
Date: { name: 'date', options: 0 },
|
|
18
|
+
File: { name: 'file', options: 0 },
|
|
19
|
+
Files: { name: 'files', options: 0, keys: { minItems: 'min', maxItems: 'max' } },
|
|
20
|
+
Literal: { name: 'literal', options: 1 },
|
|
21
|
+
Union: { name: 'union', options: 1 },
|
|
22
|
+
Array: { name: 'list', options: 1, keys: { minItems: 'min', maxItems: 'max' } },
|
|
23
|
+
Object: { name: 'object', options: 1 },
|
|
24
|
+
UnionEnum: { name: 'enum', options: 1 },
|
|
25
|
+
UnionKeys: { name: 'enum', options: 1 },
|
|
26
|
+
Public: { name: 'public', options: 1 },
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const FILES = new Set(['File', 'Files', 'file', 'files'])
|
|
30
|
+
const OLD_SIZE = /^\d+(?:\.\d+)?[kmg]$/i
|
|
31
|
+
const KAY = /^kay(?:\/|$)/
|
|
32
|
+
const NEEDLE = /\.(?:String|Secret|Number|Numeric|Integer|Boolean|BooleanString|Date|File|Files|Literal|Union|Array|Object|UnionEnum|UnionKeys|Public|Optional)\(|\.(?:file|files)\(/
|
|
33
|
+
|
|
34
|
+
interface Call {
|
|
35
|
+
node: Node & { type: 'CallExpression' }
|
|
36
|
+
name: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function builderCall(node: Node, receivers: Set<string>): Call | undefined {
|
|
40
|
+
if (node.type !== 'CallExpression' || node.callee.type !== 'MemberExpression' || node.callee.computed || node.callee.object.type !== 'Identifier' || node.callee.property.type !== 'Identifier')
|
|
41
|
+
return undefined
|
|
42
|
+
|
|
43
|
+
return receivers.has(node.callee.object.name) ? { node, name: node.callee.property.name } : undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function keyName(property: Node): string | undefined {
|
|
47
|
+
if (property.type !== 'Property' || property.computed)
|
|
48
|
+
return undefined
|
|
49
|
+
|
|
50
|
+
if (property.key.type === 'Identifier')
|
|
51
|
+
return property.key.name
|
|
52
|
+
|
|
53
|
+
return property.key.type === 'Literal' && typeof property.key.value === 'string' ? property.key.value : undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function renamedOption(name: string, keys: Record<string, string> | undefined): string | undefined {
|
|
57
|
+
return name === 'title' ? 'label' : keys?.[name]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The edits renaming a builder and the options it was given under old names: `s.String({ minLength: 3 })` is `s.string({ min: 3 })`.
|
|
61
|
+
function renames(call: Call, base: number): Edit[] {
|
|
62
|
+
const builder = BUILDERS[call.name]!
|
|
63
|
+
const { property } = call.node.callee as { property: Node }
|
|
64
|
+
const edits: Edit[] = [{ start: base + property.start, end: base + property.end, text: builder.name }]
|
|
65
|
+
const options = call.node.arguments[builder.options]
|
|
66
|
+
|
|
67
|
+
if (options?.type === 'ObjectExpression') {
|
|
68
|
+
for (const entry of options.properties) {
|
|
69
|
+
const name = keyName(entry)
|
|
70
|
+
const renamed = name === undefined ? undefined : renamedOption(name, builder.keys)
|
|
71
|
+
|
|
72
|
+
if (renamed === undefined || entry.type !== 'Property')
|
|
73
|
+
continue
|
|
74
|
+
|
|
75
|
+
edits.push({ start: base + entry.key.start, end: base + entry.key.end, text: entry.shorthand ? `${renamed}: ${name}` : renamed })
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return edits
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Where `optional: true` goes in a builder's call: into its options object, or after its last argument. Undefined for options that are not an object literal, which the fix leaves to the app.
|
|
83
|
+
function optionalEdit(call: Call, base: number): Edit | undefined {
|
|
84
|
+
const index = BUILDERS[call.name]!.options
|
|
85
|
+
const options = call.node.arguments[index]
|
|
86
|
+
|
|
87
|
+
if (options === undefined) {
|
|
88
|
+
if (call.node.arguments.length < index)
|
|
89
|
+
return undefined
|
|
90
|
+
|
|
91
|
+
const close = base + call.node.end - 1
|
|
92
|
+
|
|
93
|
+
return { start: close, end: close, text: call.node.arguments.length === 0 ? '{ optional: true }' : ', { optional: true }' }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (options.type !== 'ObjectExpression')
|
|
97
|
+
return undefined
|
|
98
|
+
|
|
99
|
+
const open = base + options.start
|
|
100
|
+
|
|
101
|
+
return { start: open, end: open + 1, text: options.properties.length === 0 ? '{ optional: true ' : '{ optional: true,' }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
type Program = Parameters<typeof importsOf>[0]
|
|
105
|
+
type Report = (start: number, end: number, message: string, help: string, edits: Edit[] | null) => void
|
|
106
|
+
|
|
107
|
+
// The `s` an app imported and no longer reads once a fix has taken `dropped` of its uses away: its import goes too, or the file would fail its own unused-name check.
|
|
108
|
+
function dropUnreadImport(ast: Program, receivers: Set<string>, dropped: number, span: { base: number, text: string }, report: Report): void {
|
|
109
|
+
for (const statement of ast.body) {
|
|
110
|
+
if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type' || !KAY.test(statement.source.value))
|
|
111
|
+
continue
|
|
112
|
+
|
|
113
|
+
const index = statement.specifiers.findIndex(specifier => specifier.type === 'ImportSpecifier' && specifier.importKind !== 'type' && (specifier.imported as { name?: string }).name === 's' && receivers.has(specifier.local.name))
|
|
114
|
+
|
|
115
|
+
if (index < 0)
|
|
116
|
+
continue
|
|
117
|
+
|
|
118
|
+
const specifier = statement.specifiers[index]!
|
|
119
|
+
let references = 0
|
|
120
|
+
|
|
121
|
+
walk(ast, (node) => {
|
|
122
|
+
if (node.type === 'Identifier' && receivers.has(node.name) && (node.start < specifier.start || node.end > specifier.end))
|
|
123
|
+
references++
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (references > dropped)
|
|
127
|
+
return
|
|
128
|
+
|
|
129
|
+
const only = statement.specifiers.length === 1
|
|
130
|
+
const next = statement.specifiers[index + 1]
|
|
131
|
+
const previous = statement.specifiers[index - 1]
|
|
132
|
+
const lineEnd = span.text[statement.end] === '\n' ? statement.end + 1 : statement.end
|
|
133
|
+
// The whole line when it is the only name, else the name and the comma beside it.
|
|
134
|
+
let [from, to] = [previous?.end ?? specifier.start, specifier.end]
|
|
135
|
+
|
|
136
|
+
if (only)
|
|
137
|
+
[from, to] = [statement.start, lineEnd]
|
|
138
|
+
else if (next)
|
|
139
|
+
[from, to] = [specifier.start, next.start]
|
|
140
|
+
|
|
141
|
+
const edit = { start: span.base + from, end: span.base + to, text: '' }
|
|
142
|
+
|
|
143
|
+
report(span.base + specifier.start, span.base + specifier.end, '`s` is no longer read once its builders are written as a record, so its import goes', 'drop the import of `s`', [edit])
|
|
144
|
+
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The PascalCase builders of `s`, which kay 1.106 replaces with its own lowercase ones, and the `'2m'` sizes of a file field, which are `'2mb'` as every size is.
|
|
150
|
+
// Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. `s.Optional(x)` of one of these builders is `optional: true` in its options; an `s.Object({ ... })` that is the schema of an `action` or a `defineEnv` is the record alone.
|
|
151
|
+
export async function schemaBuilders(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
152
|
+
if (lintLevel('deprecated-schema-builders', options.lints) === 'allow')
|
|
153
|
+
return []
|
|
154
|
+
|
|
155
|
+
return scan(root, options, 'deprecated-schema-builders', NEEDLE, ({ parsed, report }) => {
|
|
156
|
+
for (const { ast, base, text } of parsed) {
|
|
157
|
+
const receivers = importsOf(ast, source => KAY.test(source), 's').locals
|
|
158
|
+
const records = new Set([...importsOf(ast, source => KAY.test(source), 'action').locals, ...importsOf(ast, source => KAY.test(source), 'defineEnv').locals])
|
|
159
|
+
|
|
160
|
+
if (receivers.size === 0)
|
|
161
|
+
continue
|
|
162
|
+
|
|
163
|
+
// What an `s.Optional(...)` or a record has taken over, so the call inside is not reported on its own.
|
|
164
|
+
const taken = new Set<Node>()
|
|
165
|
+
// The uses of `s` a fix takes away: an `s.Optional(` and the `s.Object(` of a record.
|
|
166
|
+
let dropped = 0
|
|
167
|
+
|
|
168
|
+
walk(ast, (node) => {
|
|
169
|
+
const call = builderCall(node, receivers)
|
|
170
|
+
|
|
171
|
+
if (call === undefined) {
|
|
172
|
+
// `action(s.Object({ ... }), ...)`
|
|
173
|
+
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && records.has(node.callee.name)) {
|
|
174
|
+
const [schema] = node.arguments
|
|
175
|
+
const inner = schema === undefined ? undefined : builderCall(schema, receivers)
|
|
176
|
+
|
|
177
|
+
if (schema && inner?.name === 'Object' && inner.node.arguments.length === 1 && inner.node.arguments[0]!.type === 'ObjectExpression') {
|
|
178
|
+
const shape = inner.node.arguments[0]
|
|
179
|
+
|
|
180
|
+
taken.add(schema)
|
|
181
|
+
dropped++
|
|
182
|
+
report(base + schema.start, base + schema.end, 'a plain record of fields is the object schema of an action or a defineEnv since 1.106, `s.Object` being the PascalCase builder it replaces; the old form works until 2.0', 'write the record of fields', [{ start: base + schema.start, end: base + shape.start, text: '' }, { start: base + shape.end, end: base + schema.end, text: '' }])
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (call.name === 'Optional') {
|
|
190
|
+
const [inner, ...others] = call.node.arguments
|
|
191
|
+
const wrapped = inner === undefined ? undefined : builderCall(inner, receivers)
|
|
192
|
+
const known = wrapped && wrapped.name !== 'Public' && BUILDERS[wrapped.name] && !taken.has(inner!)
|
|
193
|
+
const edit = known ? optionalEdit(wrapped, base) : undefined
|
|
194
|
+
|
|
195
|
+
// Anything but a builder of `s`, such as the `imageField()` of kay/content, has no `optional` option to write yet.
|
|
196
|
+
if (!known)
|
|
197
|
+
return
|
|
198
|
+
|
|
199
|
+
if (others.length > 0 || !edit) {
|
|
200
|
+
report(base + node.start, base + node.end, '`s.Optional(field)` is `optional: true` in the options of the field since 1.106, the same option on every builder; the old form works until 2.0', 'write `optional: true` in the field\'s options', null)
|
|
201
|
+
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
taken.add(inner!)
|
|
206
|
+
dropped++
|
|
207
|
+
report(base + node.start, base + node.end, '`s.Optional(field)` is `optional: true` in the options of the field since 1.106, the same option on every builder; the old form works until 2.0', 'write `optional: true` in the field\'s options', [
|
|
208
|
+
{ start: base + node.start, end: base + inner!.start, text: '' },
|
|
209
|
+
...renames(wrapped, base),
|
|
210
|
+
edit,
|
|
211
|
+
{ start: base + node.end - 1, end: base + node.end, text: '' },
|
|
212
|
+
])
|
|
213
|
+
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const builder = BUILDERS[call.name]
|
|
218
|
+
|
|
219
|
+
if (builder && !taken.has(node)) {
|
|
220
|
+
const object = call.name === 'Object' ? 'unknown keys are refused by `s.object` where kay reads the schema itself, where `s.Object` let them by; write `extra: \'strip\'` to keep the old way' : ''
|
|
221
|
+
const message = call.name === 'UnionKeys' || call.name === 'UnionEnum'
|
|
222
|
+
? '`s.enum()` takes the values, or a record whose keys are the values, since 1.106, in place of `s.UnionEnum` and `s.UnionKeys`; the old forms work until 2.0'
|
|
223
|
+
: `\`s.${call.name}\` is \`s.${builder.name}\` since 1.106, kay's own lowercase builders with short options (\`min\`, \`max\`, \`optional\`) replacing the PascalCase ones of TypeBox${object ? `; ${object}` : ''}; the old form works until 2.0`
|
|
224
|
+
|
|
225
|
+
report(base + node.start, base + node.end, message, `write \`s.${builder.name}\``, renames(call, base))
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
walk(ast, (node) => {
|
|
230
|
+
const call = builderCall(node, receivers)
|
|
231
|
+
|
|
232
|
+
if (call === undefined || !FILES.has(call.name))
|
|
233
|
+
return
|
|
234
|
+
|
|
235
|
+
const options = call.node.arguments[0]
|
|
236
|
+
|
|
237
|
+
if (options?.type !== 'ObjectExpression')
|
|
238
|
+
return
|
|
239
|
+
|
|
240
|
+
for (const entry of options.properties) {
|
|
241
|
+
const name = keyName(entry)
|
|
242
|
+
|
|
243
|
+
if ((name !== 'maxSize' && name !== 'minSize') || entry.type !== 'Property' || entry.value.type !== 'Literal' || typeof entry.value.value !== 'string' || !OLD_SIZE.test(entry.value.value))
|
|
244
|
+
continue
|
|
245
|
+
|
|
246
|
+
const end = base + entry.value.end - 1
|
|
247
|
+
|
|
248
|
+
report(base + entry.value.start, base + entry.value.end, `a size is written \`'${entry.value.value}b'\`, with its unit, as every size of kay is`, 'write the size with its `b`', [{ start: end, end, text: 'b' }])
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
if (dropped > 0)
|
|
253
|
+
dropUnreadImport(ast, receivers, dropped, { base, text }, report)
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
}
|