@kayjs/kay 1.107.0 → 1.109.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint.js +1875 -3815
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +1 -1
- package/llms/actions-from-islands.md +5 -5
- package/llms/actions-refused-fields.md +4 -4
- package/llms/api-from-islands.md +6 -6
- package/llms/browser-only.md +2 -2
- package/llms/cdn-caching.md +1 -1
- package/llms/checks.md +1 -1
- package/llms/code-lints.md +1 -2
- package/llms/component-libraries.md +1 -1
- package/llms/component-library-conventions.md +1 -1
- package/llms/components.md +4 -4
- package/llms/deprecated-lints.md +1 -7
- package/llms/effects.md +1 -1
- package/llms/errors.md +2 -2
- package/llms/events.md +1 -1
- package/llms/guards.md +1 -1
- package/llms/head.md +1 -1
- package/llms/hooks.md +2 -2
- package/llms/images.md +1 -1
- package/llms/island-and-form-lints.md +2 -1
- package/llms/island-sources.md +1 -1
- package/llms/islands-state-to-ids.md +2 -2
- package/llms/islands.md +5 -3
- package/llms/lints.md +1 -1
- package/llms/live-values.md +3 -3
- package/llms/local-collections.md +1 -1
- package/llms/locales.md +1 -1
- package/llms/mcp.md +2 -2
- package/llms/metrics.md +1 -1
- package/llms/navigation-from-code.md +6 -6
- package/llms/prerendering.md +1 -0
- package/llms/production.md +2 -2
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +4 -4
- package/llms/proxy-and-security.md +1 -1
- package/llms/queues.md +1 -1
- package/llms/rate-limits.md +4 -4
- package/llms/rendering.md +1 -1
- package/llms/server-islands.md +2 -2
- package/llms/server.md +1 -1
- package/llms/stores.md +1 -1
- package/llms/styles-and-assets.md +1 -1
- package/llms/testing-mount.md +49 -0
- package/llms/testing.md +4 -45
- package/llms/upgrading-1-105-config.md +13 -13
- package/llms/upgrading-archive.md +42 -82
- package/llms/upgrading.md +92 -58
- package/llms/whats-new-archive.md +36 -1
- package/llms/whats-new.md +18 -39
- package/llms.txt +6 -7
- package/package.json +6 -10
- package/src/build/client.ts +7 -6
- package/src/build/icon-slots.ts +140 -0
- package/src/build/libraries.ts +24 -2
- package/src/build/plugin.ts +10 -0
- package/src/build/route-sizes.ts +2 -3
- package/src/build/runtime-chunk.ts +2 -2
- package/src/build/source-files.ts +8 -3
- package/src/build/variants.ts +90 -1
- package/src/check/browser-global-reads.ts +2 -2
- package/src/check/config-objects.ts +1 -1
- package/src/check/diagnose.ts +0 -22
- package/src/check/export-homes.ts +1 -1
- package/src/check/guards.ts +3 -3
- package/src/check/index.ts +2 -7
- package/src/check/moved-keys.ts +1 -1
- package/src/check/project.ts +4 -9
- package/src/check/renamed-packages.ts +3 -63
- package/src/check/shadow-types.ts +4 -104
- package/src/commands/check.ts +2 -2
- package/src/commands/env.ts +25 -3
- package/src/compiler/ast.ts +18 -16
- package/src/compiler/browser.ts +2 -14
- package/src/compiler/class-items.ts +16 -0
- package/src/compiler/codegen.ts +8 -8
- package/src/compiler/dead-code.ts +22 -0
- package/src/compiler/deprecated-library.ts +0 -12
- package/src/compiler/deprecated-lints.ts +4 -505
- package/src/compiler/deprecated-ui-props.ts +5 -5
- package/src/compiler/dom-property.ts +23 -0
- package/src/compiler/dom.ts +15 -15
- package/src/compiler/errors.ts +2 -2
- package/src/compiler/fence-checks.ts +2 -121
- package/src/compiler/hand-parts.ts +55 -0
- package/src/compiler/helper-imports.ts +2 -2
- package/src/compiler/image-attributes.ts +1 -3
- package/src/compiler/index.ts +20 -21
- package/src/compiler/island-arguments.ts +8 -95
- package/src/compiler/island-cause.ts +7 -7
- package/src/compiler/island-declaration.ts +2 -8
- package/src/compiler/island-lints.ts +12 -0
- package/src/compiler/island-marker.ts +3 -3
- package/src/compiler/island-problems.ts +25 -0
- package/src/compiler/jsx-class.ts +1 -25
- package/src/compiler/jsx.ts +2 -2
- package/src/compiler/kay-exports.ts +0 -2
- package/src/compiler/link-flags.ts +9 -38
- package/src/compiler/lints.ts +7 -14
- package/src/compiler/markup.ts +23 -26
- package/src/compiler/module-signals.ts +2 -2
- package/src/compiler/names.ts +1 -1
- package/src/compiler/page-settings.ts +11 -0
- package/src/compiler/parser.ts +6 -8
- package/src/compiler/plan.ts +1 -3
- package/src/compiler/rewrite.ts +3 -18
- package/src/compiler/script-server.ts +8 -3
- package/src/compiler/validate.ts +3 -8
- package/src/config-loader.ts +14 -4
- package/src/config-resolve.ts +18 -142
- package/src/config-shape.ts +44 -34
- package/src/config.ts +10 -114
- package/src/dev/preload.ts +4 -1
- package/src/lsp/server.ts +4 -0
- package/src/migrate/markup.ts +4 -1
- package/src/package-names.ts +1 -1
- package/src/runtime/action-call.ts +39 -335
- package/src/runtime/action-encode.ts +26 -0
- package/src/runtime/action-error.ts +3 -11
- package/src/runtime/action-protection.ts +2 -2
- package/src/runtime/action-run.ts +332 -0
- package/src/runtime/action-shared.ts +14 -37
- package/src/runtime/action-stream.ts +0 -1
- package/src/runtime/action.ts +1 -1
- package/src/runtime/call-result.ts +2 -10
- package/src/runtime/checks.ts +11 -11
- package/src/runtime/client.ts +2 -2
- package/src/runtime/core.ts +5 -23
- package/src/runtime/dom.ts +1 -1
- package/src/runtime/html.ts +1 -1
- package/src/runtime/i18n.client.ts +1 -4
- package/src/runtime/i18n.server.ts +1 -4
- package/src/runtime/i18n.ts +3 -3
- package/src/runtime/index.ts +2 -2
- package/src/runtime/island.server.ts +18 -5
- package/src/runtime/live-resource.server.ts +0 -1
- package/src/runtime/live-value.server.ts +2 -2
- package/src/runtime/live-value.shared.ts +7 -20
- package/src/runtime/live.ts +1 -12
- package/src/runtime/local-types.ts +1 -11
- package/src/runtime/local.ts +4 -14
- package/src/runtime/navigate-api.ts +2 -5
- package/src/runtime/navigation-state.ts +0 -12
- package/src/runtime/page-swap.ts +6 -6
- package/src/runtime/persist.ts +11 -3
- package/src/runtime/persisted.ts +4 -30
- package/src/runtime/presence.ts +6 -7
- package/src/runtime/query-param.ts +20 -12
- package/src/runtime/reactive.ts +3 -1
- package/src/runtime/refuse.ts +3 -17
- package/src/runtime/store-base.ts +4 -6
- package/src/runtime/swap-fetch.ts +1 -1
- package/src/runtime/values.ts +40 -23
- package/src/runtime/with-query.ts +9 -0
- package/src/server/action-hooks.ts +8 -8
- package/src/server/actions.ts +13 -14
- package/src/server/api-modules.ts +2 -3
- package/src/server/app-stages.ts +15 -33
- package/src/server/app.ts +10 -5
- package/src/server/auth-mails.ts +0 -2
- package/src/server/env-state.ts +40 -10
- package/src/server/flash.ts +1 -1
- package/src/server/guard-requirement.ts +4 -4
- package/src/server/image.ts +2 -2
- package/src/server/index.ts +0 -2
- package/src/server/job-context.ts +3 -3
- package/src/server/jobs-page.ts +1 -1
- package/src/server/jobs.ts +5 -9
- package/src/server/kept-exports.ts +0 -2
- package/src/server/kv.ts +11 -14
- package/src/server/library.ts +1 -3
- package/src/server/live.ts +2 -2
- package/src/server/mcp.ts +3 -9
- package/src/server/metrics.ts +2 -4
- package/src/server/page-settings.ts +10 -19
- package/src/server/prerender.ts +19 -2
- package/src/server/protection.ts +15 -18
- package/src/server/queue.ts +3 -6
- package/src/server/rate-limit.ts +0 -3
- package/src/server/render-document.ts +1 -1
- package/src/server/routes.ts +7 -3
- package/src/server/scope.ts +3 -2
- package/src/server/session.ts +5 -6
- package/src/server/setup.ts +1 -1
- package/src/server/signals.ts +17 -7
- package/src/server/signed.ts +1 -3
- package/src/server/source.ts +20 -4
- package/src/server/speculation.ts +1 -1
- package/src/server/storage.ts +3 -8
- package/src/server/validate.ts +1 -1
- package/src/server/vitals.ts +1 -3
- package/src/server/work-scope.ts +2 -4
- package/src/server/work.ts +1 -1
- package/src/server/workflow.ts +1 -1
- package/src/test/index.ts +2 -1
- package/src/test/site-actions.ts +16 -6
- package/src/test/site-keys.ts +10 -15
- package/src/test/site-socket.ts +1 -2
- package/src/test/site-types.ts +0 -8
- package/types/build/client.d.ts +1 -1
- package/types/build/client.d.ts.map +1 -1
- package/types/build/icon-slots.d.ts +7 -0
- package/types/build/icon-slots.d.ts.map +1 -0
- package/types/build/libraries.d.ts +2 -0
- package/types/build/libraries.d.ts.map +1 -1
- package/types/build/plugin.d.ts +1 -0
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/route-sizes.d.ts.map +1 -1
- package/types/build/source-files.d.ts.map +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/diagnose.d.ts.map +1 -1
- package/types/check/index.d.ts +1 -2
- package/types/check/index.d.ts.map +1 -1
- package/types/check/project.d.ts.map +1 -1
- package/types/check/renamed-packages.d.ts +0 -3
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/commands/env.d.ts.map +1 -1
- package/types/compiler/ast.d.ts +1 -2
- package/types/compiler/ast.d.ts.map +1 -1
- package/types/compiler/browser.d.ts.map +1 -1
- package/types/compiler/class-items.d.ts +7 -0
- package/types/compiler/class-items.d.ts.map +1 -0
- package/types/compiler/dead-code.d.ts +9 -0
- package/types/compiler/dead-code.d.ts.map +1 -0
- package/types/compiler/deprecated-library.d.ts.map +1 -1
- package/types/compiler/deprecated-lints.d.ts +0 -560
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/deprecated-ui-props.d.ts +1 -8
- package/types/compiler/deprecated-ui-props.d.ts.map +1 -1
- package/types/compiler/dom-property.d.ts +9 -0
- package/types/compiler/dom-property.d.ts.map +1 -0
- package/types/compiler/dom.d.ts +1 -0
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/errors.d.ts +2 -2
- package/types/compiler/errors.d.ts.map +1 -1
- package/types/compiler/fence-checks.d.ts +0 -1
- package/types/compiler/fence-checks.d.ts.map +1 -1
- package/types/compiler/hand-parts.d.ts +7 -0
- package/types/compiler/hand-parts.d.ts.map +1 -0
- package/types/compiler/image-attributes.d.ts +0 -1
- package/types/compiler/image-attributes.d.ts.map +1 -1
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-arguments.d.ts +2 -11
- package/types/compiler/island-arguments.d.ts.map +1 -1
- package/types/compiler/island-cause.d.ts +1 -1
- package/types/compiler/island-cause.d.ts.map +1 -1
- package/types/compiler/island-declaration.d.ts +1 -3
- package/types/compiler/island-declaration.d.ts.map +1 -1
- package/types/compiler/island-lints.d.ts +10 -0
- package/types/compiler/island-lints.d.ts.map +1 -0
- package/types/compiler/island-problems.d.ts +7 -0
- package/types/compiler/island-problems.d.ts.map +1 -0
- package/types/compiler/jsx-class.d.ts +1 -2
- package/types/compiler/jsx-class.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/link-flags.d.ts +0 -6
- package/types/compiler/link-flags.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +11 -572
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/markup.d.ts +1 -1
- package/types/compiler/markup.d.ts.map +1 -1
- package/types/compiler/module-signals.d.ts.map +1 -1
- package/types/compiler/names.d.ts.map +1 -1
- package/types/compiler/page-settings.d.ts +4 -0
- package/types/compiler/page-settings.d.ts.map +1 -1
- package/types/compiler/parser.d.ts.map +1 -1
- package/types/compiler/plan.d.ts.map +1 -1
- package/types/compiler/script-server.d.ts.map +1 -1
- package/types/compiler/validate.d.ts.map +1 -1
- package/types/config-loader.d.ts.map +1 -1
- package/types/config-resolve.d.ts.map +1 -1
- package/types/config-shape.d.ts +1 -1
- package/types/config-shape.d.ts.map +1 -1
- package/types/config.d.ts +5 -105
- package/types/config.d.ts.map +1 -1
- package/types/dev/preload.d.ts.map +1 -1
- package/types/lsp/server.d.ts.map +1 -1
- package/types/migrate/markup.d.ts.map +1 -1
- package/types/runtime/action-call.d.ts.map +1 -1
- package/types/runtime/action-encode.d.ts +1 -0
- package/types/runtime/action-encode.d.ts.map +1 -1
- package/types/runtime/action-error.d.ts +1 -2
- package/types/runtime/action-error.d.ts.map +1 -1
- package/types/runtime/action-run.d.ts +23 -0
- package/types/runtime/action-run.d.ts.map +1 -0
- package/types/runtime/action-shared.d.ts +1 -27
- package/types/runtime/action-shared.d.ts.map +1 -1
- package/types/runtime/action-stream.d.ts.map +1 -1
- package/types/runtime/action.d.ts +1 -1
- package/types/runtime/action.d.ts.map +1 -1
- package/types/runtime/call-result.d.ts +0 -10
- package/types/runtime/call-result.d.ts.map +1 -1
- package/types/runtime/checks.d.ts +6 -9
- package/types/runtime/checks.d.ts.map +1 -1
- package/types/runtime/core.d.ts +2 -20
- package/types/runtime/core.d.ts.map +1 -1
- package/types/runtime/dom.d.ts +1 -1
- package/types/runtime/dom.d.ts.map +1 -1
- package/types/runtime/html.d.ts +1 -1
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/i18n.client.d.ts +0 -1
- package/types/runtime/i18n.client.d.ts.map +1 -1
- package/types/runtime/i18n.d.ts +1 -1
- package/types/runtime/i18n.d.ts.map +1 -1
- package/types/runtime/i18n.server.d.ts +0 -1
- package/types/runtime/i18n.server.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -2
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +1 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/live-resource.server.d.ts.map +1 -1
- package/types/runtime/live-value.shared.d.ts +7 -15
- package/types/runtime/live-value.shared.d.ts.map +1 -1
- package/types/runtime/live.d.ts +0 -11
- package/types/runtime/live.d.ts.map +1 -1
- package/types/runtime/local-types.d.ts +0 -14
- package/types/runtime/local-types.d.ts.map +1 -1
- package/types/runtime/navigate-api.d.ts +0 -4
- package/types/runtime/navigate-api.d.ts.map +1 -1
- package/types/runtime/navigation-state.d.ts +0 -4
- package/types/runtime/navigation-state.d.ts.map +1 -1
- package/types/runtime/page-swap.d.ts.map +1 -1
- package/types/runtime/persist.d.ts +1 -0
- package/types/runtime/persist.d.ts.map +1 -1
- package/types/runtime/persisted.d.ts +0 -15
- package/types/runtime/persisted.d.ts.map +1 -1
- package/types/runtime/presence.d.ts +0 -2
- package/types/runtime/presence.d.ts.map +1 -1
- package/types/runtime/query-param.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +2 -1
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/refuse.d.ts +0 -7
- package/types/runtime/refuse.d.ts.map +1 -1
- package/types/runtime/store-base.d.ts +1 -2
- package/types/runtime/store-base.d.ts.map +1 -1
- package/types/runtime/values.d.ts +2 -1
- package/types/runtime/values.d.ts.map +1 -1
- package/types/runtime/with-query.d.ts +2 -0
- package/types/runtime/with-query.d.ts.map +1 -1
- package/types/server/action-hooks.d.ts +4 -4
- package/types/server/action-hooks.d.ts.map +1 -1
- package/types/server/actions.d.ts.map +1 -1
- package/types/server/api-modules.d.ts +0 -1
- package/types/server/api-modules.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +5 -13
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +3 -8
- package/types/server/app.d.ts.map +1 -1
- package/types/server/auth-mails.d.ts +0 -5
- package/types/server/auth-mails.d.ts.map +1 -1
- package/types/server/env-state.d.ts +1 -0
- package/types/server/env-state.d.ts.map +1 -1
- package/types/server/guard-requirement.d.ts +0 -1
- package/types/server/guard-requirement.d.ts.map +1 -1
- package/types/server/image.d.ts +0 -1
- package/types/server/image.d.ts.map +1 -1
- package/types/server/index.d.ts +0 -2
- package/types/server/index.d.ts.map +1 -1
- package/types/server/job-context.d.ts +1 -1
- package/types/server/job-context.d.ts.map +1 -1
- package/types/server/jobs.d.ts +0 -4
- package/types/server/jobs.d.ts.map +1 -1
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/kv.d.ts +4 -4
- package/types/server/kv.d.ts.map +1 -1
- package/types/server/library.d.ts +1 -3
- package/types/server/library.d.ts.map +1 -1
- package/types/server/mcp.d.ts +0 -1
- package/types/server/mcp.d.ts.map +1 -1
- package/types/server/metrics.d.ts +0 -5
- package/types/server/metrics.d.ts.map +1 -1
- package/types/server/page-settings.d.ts +3 -3
- package/types/server/page-settings.d.ts.map +1 -1
- package/types/server/prerender.d.ts.map +1 -1
- package/types/server/protection.d.ts +6 -6
- package/types/server/protection.d.ts.map +1 -1
- package/types/server/queue.d.ts +1 -3
- package/types/server/queue.d.ts.map +1 -1
- package/types/server/rate-limit.d.ts +0 -2
- package/types/server/rate-limit.d.ts.map +1 -1
- package/types/server/routes.d.ts +1 -1
- package/types/server/routes.d.ts.map +1 -1
- package/types/server/scope.d.ts.map +1 -1
- package/types/server/session.d.ts +1 -1
- package/types/server/session.d.ts.map +1 -1
- package/types/server/signals.d.ts.map +1 -1
- package/types/server/signed.d.ts +0 -2
- package/types/server/signed.d.ts.map +1 -1
- package/types/server/source.d.ts +1 -1
- package/types/server/source.d.ts.map +1 -1
- package/types/server/storage.d.ts +0 -4
- package/types/server/storage.d.ts.map +1 -1
- package/types/server/vitals.d.ts +0 -1
- package/types/server/vitals.d.ts.map +1 -1
- package/types/server/work-scope.d.ts +0 -2
- package/types/server/work-scope.d.ts.map +1 -1
- package/types/server/workflow.d.ts +1 -1
- package/types/server/workflow.d.ts.map +1 -1
- package/types/test/index.d.ts.map +1 -1
- package/types/test/site-actions.d.ts +1 -1
- package/types/test/site-actions.d.ts.map +1 -1
- package/types/test/site-keys.d.ts +1 -1
- package/types/test/site-keys.d.ts.map +1 -1
- package/types/test/site-socket.d.ts +1 -1
- package/types/test/site-socket.d.ts.map +1 -1
- package/types/test/site-types.d.ts +0 -8
- package/types/test/site-types.d.ts.map +1 -1
- package/llms/deprecated-lints-1-105-libraries.md +0 -32
- package/llms/deprecated-lints-1-105.md +0 -58
- package/src/check/action-readers.ts +0 -115
- package/src/check/action-type.ts +0 -44
- package/src/check/ai-language.ts +0 -56
- package/src/check/app-hooks.ts +0 -90
- package/src/check/auth-methods.ts +0 -85
- package/src/check/auth-rate-limits.ts +0 -99
- package/src/check/call-result.ts +0 -242
- package/src/check/client-keys.ts +0 -10
- package/src/check/cms-options.ts +0 -81
- package/src/check/config-groups.ts +0 -22
- package/src/check/config-switches.ts +0 -38
- package/src/check/context-import.ts +0 -51
- package/src/check/env-files.ts +0 -31
- package/src/check/format-duration.ts +0 -75
- package/src/check/guard-options.ts +0 -58
- package/src/check/handler-events.ts +0 -149
- package/src/check/hook-context.ts +0 -94
- package/src/check/hook-names.ts +0 -104
- package/src/check/i18n-keys.ts +0 -50
- package/src/check/images-keys.ts +0 -54
- package/src/check/job-shapes.ts +0 -273
- package/src/check/link-flag-tests.ts +0 -130
- package/src/check/live-api.ts +0 -137
- package/src/check/mail-api.ts +0 -67
- package/src/check/one-state-api.ts +0 -357
- package/src/check/pages-options.ts +0 -35
- package/src/check/rate-enforce.ts +0 -53
- package/src/check/refusal-calls.ts +0 -185
- package/src/check/retired-lints.ts +0 -49
- package/src/check/route-keys.ts +0 -166
- package/src/check/secret-keys.ts +0 -83
- package/src/check/socket-frames.ts +0 -102
- package/src/check/source-readers.ts +0 -257
- package/src/check/store-ms.ts +0 -72
- package/src/check/store-names.ts +0 -88
- package/src/check/test-helpers.ts +0 -98
- package/src/check/ttl-names.ts +0 -142
- package/src/compiler/deprecated-ai-labels.ts +0 -97
- package/src/compiler/deprecated-ai-links.ts +0 -63
- package/src/compiler/deprecated-allow.ts +0 -50
- package/src/compiler/deprecated-auth-lints.ts +0 -14
- package/src/compiler/deprecated-auth-signed.ts +0 -29
- package/src/compiler/deprecated-children.ts +0 -66
- package/src/compiler/deprecated-image.ts +0 -116
- package/src/compiler/deprecated-island.ts +0 -155
- package/src/compiler/deprecated-lints-1-105.ts +0 -41
- package/src/compiler/deprecated-page.ts +0 -125
- package/src/compiler/deprecated-parts.ts +0 -22
- package/src/compiler/deprecated-typed-lints.ts +0 -23
- package/src/compiler/deprecated-ui-callbacks.ts +0 -66
- package/src/compiler/deprecated-ui-input.ts +0 -97
- package/src/compiler/deprecated-ui-items.ts +0 -47
- package/src/compiler/old-parts.ts +0 -84
- package/src/runtime/mount.compat.ts +0 -8
- package/src/server/moved-exports.ts +0 -17
- package/types/check/action-readers.d.ts +0 -3
- package/types/check/action-readers.d.ts.map +0 -1
- package/types/check/action-type.d.ts +0 -3
- package/types/check/action-type.d.ts.map +0 -1
- package/types/check/ai-language.d.ts +0 -3
- package/types/check/ai-language.d.ts.map +0 -1
- package/types/check/app-hooks.d.ts +0 -3
- package/types/check/app-hooks.d.ts.map +0 -1
- package/types/check/auth-methods.d.ts +0 -3
- package/types/check/auth-methods.d.ts.map +0 -1
- package/types/check/auth-rate-limits.d.ts +0 -3
- package/types/check/auth-rate-limits.d.ts.map +0 -1
- package/types/check/call-result.d.ts +0 -7
- package/types/check/call-result.d.ts.map +0 -1
- package/types/check/client-keys.d.ts +0 -3
- package/types/check/client-keys.d.ts.map +0 -1
- package/types/check/cms-options.d.ts +0 -3
- package/types/check/cms-options.d.ts.map +0 -1
- package/types/check/config-groups.d.ts +0 -3
- package/types/check/config-groups.d.ts.map +0 -1
- package/types/check/config-switches.d.ts +0 -3
- package/types/check/config-switches.d.ts.map +0 -1
- package/types/check/context-import.d.ts +0 -3
- package/types/check/context-import.d.ts.map +0 -1
- package/types/check/env-files.d.ts +0 -3
- package/types/check/env-files.d.ts.map +0 -1
- package/types/check/format-duration.d.ts +0 -5
- package/types/check/format-duration.d.ts.map +0 -1
- package/types/check/guard-options.d.ts +0 -3
- package/types/check/guard-options.d.ts.map +0 -1
- package/types/check/handler-events.d.ts +0 -9
- package/types/check/handler-events.d.ts.map +0 -1
- package/types/check/hook-context.d.ts +0 -3
- package/types/check/hook-context.d.ts.map +0 -1
- package/types/check/hook-names.d.ts +0 -3
- package/types/check/hook-names.d.ts.map +0 -1
- package/types/check/i18n-keys.d.ts +0 -3
- package/types/check/i18n-keys.d.ts.map +0 -1
- package/types/check/images-keys.d.ts +0 -3
- package/types/check/images-keys.d.ts.map +0 -1
- package/types/check/job-shapes.d.ts +0 -6
- package/types/check/job-shapes.d.ts.map +0 -1
- package/types/check/link-flag-tests.d.ts +0 -4
- package/types/check/link-flag-tests.d.ts.map +0 -1
- package/types/check/live-api.d.ts +0 -3
- package/types/check/live-api.d.ts.map +0 -1
- package/types/check/mail-api.d.ts +0 -3
- package/types/check/mail-api.d.ts.map +0 -1
- package/types/check/one-state-api.d.ts +0 -9
- package/types/check/one-state-api.d.ts.map +0 -1
- package/types/check/pages-options.d.ts +0 -3
- package/types/check/pages-options.d.ts.map +0 -1
- package/types/check/rate-enforce.d.ts +0 -3
- package/types/check/rate-enforce.d.ts.map +0 -1
- package/types/check/refusal-calls.d.ts +0 -3
- package/types/check/refusal-calls.d.ts.map +0 -1
- package/types/check/retired-lints.d.ts +0 -3
- package/types/check/retired-lints.d.ts.map +0 -1
- package/types/check/route-keys.d.ts +0 -3
- package/types/check/route-keys.d.ts.map +0 -1
- package/types/check/secret-keys.d.ts +0 -3
- package/types/check/secret-keys.d.ts.map +0 -1
- package/types/check/socket-frames.d.ts +0 -3
- package/types/check/socket-frames.d.ts.map +0 -1
- package/types/check/source-readers.d.ts +0 -3
- package/types/check/source-readers.d.ts.map +0 -1
- package/types/check/store-ms.d.ts +0 -3
- package/types/check/store-ms.d.ts.map +0 -1
- package/types/check/store-names.d.ts +0 -3
- package/types/check/store-names.d.ts.map +0 -1
- package/types/check/test-helpers.d.ts +0 -3
- package/types/check/test-helpers.d.ts.map +0 -1
- package/types/check/ttl-names.d.ts +0 -3
- package/types/check/ttl-names.d.ts.map +0 -1
- package/types/compiler/deprecated-ai-labels.d.ts +0 -5
- package/types/compiler/deprecated-ai-labels.d.ts.map +0 -1
- package/types/compiler/deprecated-ai-links.d.ts +0 -5
- package/types/compiler/deprecated-ai-links.d.ts.map +0 -1
- package/types/compiler/deprecated-allow.d.ts +0 -5
- package/types/compiler/deprecated-allow.d.ts.map +0 -1
- package/types/compiler/deprecated-auth-lints.d.ts +0 -12
- package/types/compiler/deprecated-auth-lints.d.ts.map +0 -1
- package/types/compiler/deprecated-auth-signed.d.ts +0 -5
- package/types/compiler/deprecated-auth-signed.d.ts.map +0 -1
- package/types/compiler/deprecated-children.d.ts +0 -4
- package/types/compiler/deprecated-children.d.ts.map +0 -1
- package/types/compiler/deprecated-image.d.ts +0 -5
- package/types/compiler/deprecated-image.d.ts.map +0 -1
- package/types/compiler/deprecated-island.d.ts +0 -9
- package/types/compiler/deprecated-island.d.ts.map +0 -1
- package/types/compiler/deprecated-lints-1-105.d.ts +0 -39
- package/types/compiler/deprecated-lints-1-105.d.ts.map +0 -1
- package/types/compiler/deprecated-page.d.ts +0 -4
- package/types/compiler/deprecated-page.d.ts.map +0 -1
- package/types/compiler/deprecated-parts.d.ts +0 -3
- package/types/compiler/deprecated-parts.d.ts.map +0 -1
- package/types/compiler/deprecated-typed-lints.d.ts +0 -21
- package/types/compiler/deprecated-typed-lints.d.ts.map +0 -1
- package/types/compiler/deprecated-ui-callbacks.d.ts +0 -5
- package/types/compiler/deprecated-ui-callbacks.d.ts.map +0 -1
- package/types/compiler/deprecated-ui-input.d.ts +0 -5
- package/types/compiler/deprecated-ui-input.d.ts.map +0 -1
- package/types/compiler/deprecated-ui-items.d.ts +0 -5
- package/types/compiler/deprecated-ui-items.d.ts.map +0 -1
- package/types/compiler/old-parts.d.ts +0 -9
- package/types/compiler/old-parts.d.ts.map +0 -1
- package/types/runtime/mount.compat.d.ts +0 -7
- package/types/runtime/mount.compat.d.ts.map +0 -1
- package/types/server/moved-exports.d.ts +0 -12
- package/types/server/moved-exports.d.ts.map +0 -1
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
import type { CheckDiagnostic, CheckOptions } from '.'
|
|
2
|
-
import type { Node, NodeOfType, Program } from '../compiler/estree'
|
|
3
|
-
import type { LintName } from '../compiler/lints'
|
|
4
|
-
import type { Edit, Found } from './renamed-exports'
|
|
5
|
-
import { lintLevel } from '../compiler/lints'
|
|
6
|
-
import { importedName, importsOf, walk } from './ast'
|
|
7
|
-
import { mentions, scan } from './renamed-exports'
|
|
8
|
-
|
|
9
|
-
const FROM_KAY = (source: string) => source === 'kay'
|
|
10
|
-
const COMMENT = /\/[*/]/
|
|
11
|
-
const PERSISTED = /\bpersisted\b/
|
|
12
|
-
const NAVIGATE = /\bnavigate\b/
|
|
13
|
-
const NAVIGATION_HOOK = /\bon(?:Before)?Navigate\b/
|
|
14
|
-
const LISTEN = /\blisten\b/
|
|
15
|
-
const MOVED_SOURCE = /kay\/(?:mount|server)/
|
|
16
|
-
const TRAILING_COMMA = /,$/
|
|
17
|
-
|
|
18
|
-
// What a rewritten `queryParam` call keeps of the old call's third argument: its members, or the whole value spread when it is not a plain object.
|
|
19
|
-
function keptSettings(source: string, base: number, settings: Node | undefined, inner: string | undefined): string {
|
|
20
|
-
if (settings === undefined)
|
|
21
|
-
return ''
|
|
22
|
-
|
|
23
|
-
if (inner === undefined)
|
|
24
|
-
return `, ...${source.slice(base + settings.start, base + settings.end)}`
|
|
25
|
-
|
|
26
|
-
return inner === '' ? '' : `, ${inner}`
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function keyName(key: Node): unknown {
|
|
30
|
-
if (key.type === 'Identifier')
|
|
31
|
-
return key.name
|
|
32
|
-
|
|
33
|
-
return key.type === 'Literal' ? key.value : undefined
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type Call = NodeOfType<'CallExpression'>
|
|
37
|
-
type ImportDeclaration = NodeOfType<'ImportDeclaration'>
|
|
38
|
-
|
|
39
|
-
// Whether `callee` is `name` imported from `kay` as written (`persisted`) or read off `import * as kay` (`kay.persisted`).
|
|
40
|
-
function calls(ast: Program, name: string): (callee: Node) => boolean {
|
|
41
|
-
const { locals, namespaces } = importsOf(ast, FROM_KAY, name)
|
|
42
|
-
|
|
43
|
-
return callee => callee.type === 'Identifier'
|
|
44
|
-
? locals.has(callee.name)
|
|
45
|
-
: callee.type === 'MemberExpression' && !callee.computed && callee.object.type === 'Identifier' && namespaces.has(callee.object.name) && callee.property.type === 'Identifier' && callee.property.name === name
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Whether `callee` is `<name>.<member>` of `name` imported from `kay`.
|
|
49
|
-
function entryCalls(ast: Program, name: string, member: string): (callee: Node) => boolean {
|
|
50
|
-
const { locals, namespaces } = importsOf(ast, FROM_KAY, name)
|
|
51
|
-
|
|
52
|
-
return callee => callee.type === 'MemberExpression' && !callee.computed && callee.property.type === 'Identifier' && callee.property.name === member
|
|
53
|
-
&& (callee.object.type === 'Identifier' ? locals.has(callee.object.name) : callee.object.type === 'MemberExpression' && !callee.object.computed && callee.object.object.type === 'Identifier' && namespaces.has(callee.object.object.name) && callee.object.property.type === 'Identifier' && callee.object.property.name === name)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Calls `visit` on each call whose callee `is` accepts.
|
|
57
|
-
function eachCall(ast: Program, is: (callee: Node) => boolean, visit: (call: Call) => void): void {
|
|
58
|
-
walk(ast, (node) => {
|
|
59
|
-
if (node.type === 'CallExpression' && is(node.callee))
|
|
60
|
-
visit(node)
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// How many identifiers named `name` the statements hold, imports left out: a rewrite of the calls alone would leave the others behind.
|
|
65
|
-
function reads(ast: Program, name: string): number {
|
|
66
|
-
let found = 0
|
|
67
|
-
|
|
68
|
-
for (const statement of ast.body) {
|
|
69
|
-
if (statement.type === 'ImportDeclaration')
|
|
70
|
-
continue
|
|
71
|
-
|
|
72
|
-
walk(statement, (node) => {
|
|
73
|
-
if (node.type === 'Identifier' && node.name === name)
|
|
74
|
-
found++
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return found
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// The import of `kay` that names `drops`, rebuilt without them and with `add`, which a file already importing it keeps as it is; a declaration of anything but plain named specifiers, an alias or a comment in the braces leaves it to the app (`null`).
|
|
82
|
-
function importEdits(ast: Program, base: number, source: string, drops: readonly string[], add: string): Edit[] | null {
|
|
83
|
-
const declaration = ast.body.find((statement): statement is ImportDeclaration => statement.type === 'ImportDeclaration' && FROM_KAY(statement.source.value) && statement.importKind !== 'type' && statement.specifiers.some(specifier => specifier.type === 'ImportSpecifier' && (drops.length === 0 || drops.includes(importedName(specifier)))))
|
|
84
|
-
|
|
85
|
-
if (!declaration || declaration.specifiers.some(specifier => specifier.type !== 'ImportSpecifier' || specifier.importKind === 'type' || specifier.local.name !== importedName(specifier)))
|
|
86
|
-
return null
|
|
87
|
-
|
|
88
|
-
const specifiers = declaration.specifiers as NodeOfType<'ImportSpecifier'>[]
|
|
89
|
-
const texts = specifiers.filter(specifier => !drops.includes(importedName(specifier))).map(specifier => source.slice(base + specifier.start, base + specifier.end))
|
|
90
|
-
const imported = ast.body.some(statement => statement.type === 'ImportDeclaration' && FROM_KAY(statement.source.value) && statement.importKind !== 'type' && statement.specifiers.some(specifier => specifier.type === 'ImportSpecifier' && importedName(specifier) === add))
|
|
91
|
-
const first = specifiers[0]!
|
|
92
|
-
const last = specifiers.at(-1)!
|
|
93
|
-
|
|
94
|
-
if (COMMENT.test(source.slice(base + first.start, base + last.end)))
|
|
95
|
-
return null
|
|
96
|
-
|
|
97
|
-
if (!imported)
|
|
98
|
-
texts.push(add)
|
|
99
|
-
|
|
100
|
-
if (texts.length === 0) {
|
|
101
|
-
const after = source[base + declaration.end] === '\n' ? 1 : 0
|
|
102
|
-
|
|
103
|
-
return [{ start: base + declaration.start, end: base + declaration.end + after, text: '' }]
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return [{ start: base + first.start, end: base + last.end, text: texts.join(', ') }]
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Runs `visit` over the parsed spans of the files whose text matches `needle`, when the lint is not allowed.
|
|
110
|
-
async function scanned(root: string, options: CheckOptions, lint: LintName, needle: RegExp, visit: (found: Found) => void): Promise<CheckDiagnostic[]> {
|
|
111
|
-
return lintLevel(lint, options.lints) === 'allow' ? [] : scan(root, options, lint, needle, visit)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// `persisted(name, value)`, a cookie since it began: `persisted.cookie(name, value)` names it, as `persisted.local()` and `persisted.session()` name theirs.
|
|
115
|
-
// A call with a `storage` option, which 1.105 no longer takes, is reported with no fix.
|
|
116
|
-
export async function persistedCall(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
117
|
-
return scanned(root, options, 'deprecated-persisted-call', PERSISTED, ({ parsed, report }) => {
|
|
118
|
-
for (const { ast, base } of parsed) {
|
|
119
|
-
eachCall(ast, calls(ast, 'persisted'), (call) => {
|
|
120
|
-
const settings = call.arguments[2]
|
|
121
|
-
const storage = settings?.type === 'ObjectExpression' && settings.properties.some(property => property.type === 'Property' && !property.computed && keyName(property.key) === 'storage')
|
|
122
|
-
|
|
123
|
-
report(base + call.callee.start, base + call.callee.end, storage ? '`storage` of `persisted()` is removed since 1.105: each storage has its own entry' : '`persisted()` keeps a cookie without saying so since 1.105: `persisted.cookie()` names it', storage ? 'call `persisted.local()`, `persisted.session()` or `queryParam()`, or `persisted.cookie()` for a cookie' : 'call `persisted.cookie()`', storage ? null : [{ start: base + call.callee.end, end: base + call.callee.end, text: '.cookie' }])
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const QUERY_MEMBER = /\.persisted\.query$/
|
|
130
|
-
|
|
131
|
-
// Whether `call` reads `persisted.query` off a namespace import (`kay.persisted.query`).
|
|
132
|
-
const spelled = (call: Call): boolean => call.callee.type === 'MemberExpression' && call.callee.object.type === 'MemberExpression'
|
|
133
|
-
|
|
134
|
-
// `persisted.query(name, value, options)`, the signal of a query param twice: `queryParam(name, { default: value, ...options })` is the one.
|
|
135
|
-
export async function persistedQuery(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
136
|
-
return scanned(root, options, 'deprecated-persisted-query', PERSISTED, ({ source, parsed, unparsed, report }) => {
|
|
137
|
-
for (const { ast, base } of parsed) {
|
|
138
|
-
const hits: Call[] = []
|
|
139
|
-
|
|
140
|
-
eachCall(ast, entryCalls(ast, 'persisted', 'query'), call => hits.push(call))
|
|
141
|
-
|
|
142
|
-
if (hits.length === 0)
|
|
143
|
-
continue
|
|
144
|
-
|
|
145
|
-
// `persisted` goes from the import when every use of it is such a call, and is kept otherwise.
|
|
146
|
-
const { locals } = importsOf(ast, FROM_KAY, 'persisted')
|
|
147
|
-
const others = [...locals].some(local => reads(ast, local) > hits.length || new RegExp(`\\b${local}\\b`).test(unparsed))
|
|
148
|
-
const named = hits.filter(call => !spelled(call))
|
|
149
|
-
const planned = hits.map(call => ({ call, own: queryEdits(source, base, call) }))
|
|
150
|
-
const everyFixable = planned.every(({ own }) => own !== null)
|
|
151
|
-
const imports = named.length === 0 ? [] : importEdits(ast, base, source, others || !everyFixable ? [] : ['persisted'], 'queryParam')
|
|
152
|
-
// Each diagnostic carries every call's rewrite and the import's, so the first fix applied does it all and the others overlap it.
|
|
153
|
-
const all = imports ? [...planned.flatMap(({ own }) => own ?? []), ...imports] : null
|
|
154
|
-
|
|
155
|
-
for (const { call, own } of planned)
|
|
156
|
-
report(base + call.callee.start, base + call.callee.end, '`persisted.query()` is deprecated since 1.105: `queryParam()` is the one signal of a query param', 'call `queryParam(name, { default })`', own && all ? all : null)
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// The edits that make `call`, a `persisted.query(name, value, options)`, a `queryParam(name, { default: value, ...options })`; `null` when the call cannot be rewritten without risk: a spread, a comment in it, or an `equals` option `queryParam` does not take.
|
|
162
|
-
function queryEdits(source: string, base: number, call: Call): Edit[] | null {
|
|
163
|
-
const [name, value, settings] = call.arguments
|
|
164
|
-
const plain = call.arguments.length >= 2 && call.arguments.length <= 3 && !call.arguments.some(argument => argument.type === 'SpreadElement')
|
|
165
|
-
const inner = settings?.type === 'ObjectExpression' && !settings.properties.some(property => property.type === 'SpreadElement') ? source.slice(base + settings.start + 1, base + settings.end - 1).trim().replace(TRAILING_COMMA, '') : undefined
|
|
166
|
-
const kept = keptSettings(source, base, settings, inner)
|
|
167
|
-
const text = plain ? `, { default: ${source.slice(base + value!.start, base + value!.end)}${kept} }` : undefined
|
|
168
|
-
const lost = plain && COMMENT.test(source.slice(base + name!.end, base + call.end))
|
|
169
|
-
const callee = spelled(call) ? `${source.slice(base + call.callee.start, base + call.callee.end).replace(QUERY_MEMBER, '')}.queryParam` : 'queryParam'
|
|
170
|
-
const equals = settings?.type === 'ObjectExpression' && settings.properties.some(property => property.type === 'Property' && keyName(property.key) === 'equals')
|
|
171
|
-
|
|
172
|
-
return plain && !lost && !equals ? [{ start: base + call.callee.start, end: base + call.callee.end, text: callee }, { start: base + name!.end, end: base + call.end - 1, text: text! }] : null
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// `navigate({ query })`, one name for two jobs: `navigate.query(changes)` changes the query of the current page, `navigate(href)` goes to another.
|
|
176
|
-
export async function navigateQuery(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
177
|
-
return scanned(root, options, 'deprecated-navigate-query', NAVIGATE, ({ source, parsed, report }) => {
|
|
178
|
-
for (const { ast, base } of parsed) {
|
|
179
|
-
eachCall(ast, calls(ast, 'navigate'), (call) => {
|
|
180
|
-
const [changes] = call.arguments
|
|
181
|
-
|
|
182
|
-
if (changes?.type !== 'ObjectExpression')
|
|
183
|
-
return
|
|
184
|
-
|
|
185
|
-
const [property] = changes.properties
|
|
186
|
-
const only = changes.properties.length === 1 && property?.type === 'Property' && !property.computed && !property.method && property.kind === 'init' && keyName(property.key) === 'query'
|
|
187
|
-
|
|
188
|
-
if (!only && !changes.properties.some(one => one.type === 'Property' && !one.computed && one.key.type === 'Identifier' && one.key.name === 'query'))
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
const text = only ? source.slice(base + property.value.start, base + property.value.end) : undefined
|
|
192
|
-
const lost = only && COMMENT.test(source.slice(base + changes.start, base + changes.end))
|
|
193
|
-
|
|
194
|
-
report(base + changes.start, base + changes.end, '`navigate({ query })` is deprecated since 1.105: `navigate.query()` changes the query, `navigate()` goes to a page', 'call `navigate.query(changes)`', only && !lost ? [{ start: base + call.callee.end, end: base + call.callee.end, text: '.query' }, { start: base + changes.start, end: base + changes.end, text: text! }] : null)
|
|
195
|
-
})
|
|
196
|
-
}
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const HOOKS = ['onBeforeNavigate', 'onNavigate'] as const
|
|
201
|
-
|
|
202
|
-
// `onNavigate(fn)` and `onBeforeNavigate(fn)`, hooks of the `navigation` source like the other sources' hooks: `navigation.onNavigate(fn)`.
|
|
203
|
-
// Moves the import too, unless a use of the name stays that is no call, or a `navigation` of the file's own stands in the way.
|
|
204
|
-
export async function navigationHooks(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
205
|
-
return scanned(root, options, 'deprecated-navigation-hooks', NAVIGATION_HOOK, ({ source, parsed, unparsed, report }) => {
|
|
206
|
-
for (const { ast, base } of parsed) {
|
|
207
|
-
const hits = HOOKS.flatMap(hook => [...importsOf(ast, FROM_KAY, hook).locals].map(local => ({ hook, local })))
|
|
208
|
-
|
|
209
|
-
if (hits.length === 0)
|
|
210
|
-
continue
|
|
211
|
-
|
|
212
|
-
const callees = new Set<Node>()
|
|
213
|
-
|
|
214
|
-
for (const { local } of hits)
|
|
215
|
-
eachCall(ast, callee => callee.type === 'Identifier' && callee.name === local, call => callees.add(call.callee))
|
|
216
|
-
|
|
217
|
-
const read = hits.reduce((total, { local }) => total + reads(ast, local), 0)
|
|
218
|
-
const text = parsed.map(one => one.ast)
|
|
219
|
-
const blocked = hits.some(({ hook, local }) => local !== hook) || read !== callees.size || hits.some(({ local }) => new RegExp(`\\b${local}\\b`).test(unparsed)) || (mentions(text, 'navigation') && !importsOf(ast, FROM_KAY, 'navigation').locals.has('navigation'))
|
|
220
|
-
const imports = blocked ? null : importEdits(ast, base, source, hits.map(({ hook }) => hook), 'navigation')
|
|
221
|
-
|
|
222
|
-
// Each diagnostic carries every call's rewrite and the import's, so the first fix applied does it all and the others overlap it.
|
|
223
|
-
const names = [...callees].filter(callee => callee.type === 'Identifier')
|
|
224
|
-
const all = imports ? [...names.map(callee => ({ start: base + callee.start, end: base + callee.end, text: `navigation.${callee.name}` })), ...imports] : null
|
|
225
|
-
|
|
226
|
-
for (const callee of names)
|
|
227
|
-
report(base + callee.start, base + callee.end, `\`${callee.name}()\` is deprecated since 1.105: the hooks of \`navigation\` are its methods`, `call \`navigation.${callee.name}()\``, all)
|
|
228
|
-
}
|
|
229
|
-
})
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Whether `node` is `window`, `document` or a member read off one: `document.body`, `window.visualViewport`.
|
|
233
|
-
function globalTarget(node: Node): boolean {
|
|
234
|
-
if (node.type === 'Identifier')
|
|
235
|
-
return node.name === 'window' || node.name === 'document'
|
|
236
|
-
|
|
237
|
-
return node.type === 'MemberExpression' && !node.computed && globalTarget(node.object)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// `listen(window, ...)`, a target read once: `listen(() => window, ...)` is the one form, which a `.ts` module runs on the server and a signal or a `ref` follows.
|
|
241
|
-
export async function listenTarget(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
242
|
-
return scanned(root, options, 'deprecated-listen-target', LISTEN, ({ parsed, report }) => {
|
|
243
|
-
for (const { ast, base } of parsed) {
|
|
244
|
-
eachCall(ast, calls(ast, 'listen'), (call) => {
|
|
245
|
-
const [target] = call.arguments
|
|
246
|
-
|
|
247
|
-
// Only a global read once is wrapped: any other identifier is a signal or a `ref` already, which `listen` follows as the function form, and a `.kay` file's compiler reads it for the target.
|
|
248
|
-
if (!target || !globalTarget(target))
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
report(base + target.start, base + target.end, '`listen()` with a target given as a value is deprecated since 1.105: a function returning it is the one form', 'write `() => target`', [{ start: base + target.start, end: base + target.start, text: '() => ' }])
|
|
252
|
-
})
|
|
253
|
-
}
|
|
254
|
-
})
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Where an export lives, when the entry an app imported it from is no longer its home: the name, the entry it left and the one it is imported from now.
|
|
258
|
-
const MOVED: Record<string, Record<string, string>> = {
|
|
259
|
-
'kay/mount': { mount: 'kay', Mounted: 'kay' },
|
|
260
|
-
'kay/server': { s: 'kay', RateLimit: 'kay', RateLimitRefusal: 'kay', sqliteCache: 'kay/cache' },
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// A name imported from the entry that no longer owns it: each name has one home, `s` and `mount` in `kay`, `sqliteCache` in `kay/cache`.
|
|
264
|
-
// The fix takes the name out of the import and writes it as an import of its home, after it, keeping a `type` import and a `type` specifier as they were; an aliased import is rewritten the same.
|
|
265
|
-
export async function movedImports(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
266
|
-
return scanned(root, options, 'deprecated-import-path', MOVED_SOURCE, ({ source, parsed, report }) => {
|
|
267
|
-
for (const { ast, base } of parsed) {
|
|
268
|
-
for (const statement of ast.body) {
|
|
269
|
-
if (statement.type !== 'ImportDeclaration' || !Object.hasOwn(MOVED, statement.source.value))
|
|
270
|
-
continue
|
|
271
|
-
|
|
272
|
-
const homes = MOVED[statement.source.value]!
|
|
273
|
-
const moved = statement.specifiers.filter((specifier): specifier is NodeOfType<'ImportSpecifier'> => specifier.type === 'ImportSpecifier' && Object.hasOwn(homes, importedName(specifier)))
|
|
274
|
-
|
|
275
|
-
if (moved.length === 0)
|
|
276
|
-
continue
|
|
277
|
-
|
|
278
|
-
const left = statement.specifiers.filter(specifier => !moved.includes(specifier as never))
|
|
279
|
-
const plain = left.every(specifier => specifier.type === 'ImportSpecifier')
|
|
280
|
-
const lost = COMMENT.test(source.slice(base + statement.start, base + statement.end))
|
|
281
|
-
const edits: Edit[] | null = !plain || lost ? null : []
|
|
282
|
-
|
|
283
|
-
if (edits) {
|
|
284
|
-
const kind = statement.importKind === 'type' ? 'import type' : 'import'
|
|
285
|
-
const byHome = Map.groupBy(moved, specifier => homes[importedName(specifier)]!)
|
|
286
|
-
const added = [...byHome].map(([home, specifiers]) => `${kind} { ${specifiers.map(specifier => source.slice(base + specifier.start, base + specifier.end)).join(', ')} } from '${home}'`).join('\n')
|
|
287
|
-
const every = statement.specifiers as Node[]
|
|
288
|
-
const rest = left.length === 0 ? '' : `${source.slice(base + statement.start, base + every[0]!.start)}${left.map(specifier => source.slice(base + specifier.start, base + specifier.end)).join(', ')}${source.slice(base + every.at(-1)!.end, base + statement.end)}`
|
|
289
|
-
|
|
290
|
-
edits.push({ start: base + statement.start, end: base + statement.end, text: rest === '' ? added : `${rest}\n${added}` })
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
for (const specifier of moved)
|
|
294
|
-
report(base + specifier.start, base + specifier.end, `\`${importedName(specifier)}\` is exported from \`${homes[importedName(specifier)]}\`, its one home, since 1.105`, `import it from \`${homes[importedName(specifier)]}\``, edits)
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
})
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// What tells an island, as a function, what each DOM event of kay tells a plain script: a method of `navigation` for the swap's events, which a rewrite reaches, and for the others a hook that needs the action or the signal the code names.
|
|
301
|
-
const EVENT_HOOKS: Record<string, { hook: string, method?: string }> = {
|
|
302
|
-
'kay:navigate': { hook: '`navigation.onNavigate(fn)`', method: 'onNavigate' },
|
|
303
|
-
'kay:navigate-start': { hook: '`navigation.onStart(fn)`', method: 'onStart' },
|
|
304
|
-
'kay:navigate-error': { hook: '`navigation.onError(fn)`', method: 'onError' },
|
|
305
|
-
'kay:navigate-stall': { hook: '`navigation.onStall(fn)`', method: 'onStall' },
|
|
306
|
-
'kay:action-start': { hook: '`action.onStart(fn)`' },
|
|
307
|
-
'kay:action-success': { hook: '`action.onData(fn)`' },
|
|
308
|
-
'kay:action-error': { hook: '`action.onError(fn)`' },
|
|
309
|
-
'kay:consent': { hook: 'the `consent` signal' },
|
|
310
|
-
'kay:install': { hook: '`installPrompt.available()`' },
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const KAY_EVENT = /kay:(?:navigate|action|consent|install)/
|
|
314
|
-
const NAVIGATION = /\bnavigation\b/
|
|
315
|
-
|
|
316
|
-
// `listen(() => document, 'kay:navigate', () => ...)`: a function written in place that takes no parameter, so nothing of the event the old form handed it is read.
|
|
317
|
-
function rewritable(call: Call, source: string, base: number): boolean {
|
|
318
|
-
const [target, , handler] = call.arguments
|
|
319
|
-
|
|
320
|
-
return call.arguments.length === 3 && (handler?.type === 'ArrowFunctionExpression' || handler?.type === 'FunctionExpression') && handler.params.length === 0
|
|
321
|
-
&& target?.type === 'ArrowFunctionExpression' && target.params.length === 0 && target.body.type === 'Identifier' && target.body.name === 'document'
|
|
322
|
-
&& !COMMENT.test(source.slice(base + call.start, base + call.end))
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// `listen(() => document, 'kay:navigate', fn)` in an island, where a function hook says the same: `navigation.onNavigate(fn)`, `action.onStart(fn)`, the `consent` signal. A plain script keeps its listener, as it has no island to hook into.
|
|
326
|
-
// The swap's events are rewritten when the handler takes no parameter, as the hook hands an object of its own where the event handed `detail`; any other listener is reported with the hook to write.
|
|
327
|
-
export async function islandEvents(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
328
|
-
return scanned(root, options, 'deprecated-island-events', KAY_EVENT, ({ source, parsed, unparsed, report }) => {
|
|
329
|
-
for (const { ast, base } of parsed) {
|
|
330
|
-
const hits: { call: Call, event: string }[] = []
|
|
331
|
-
|
|
332
|
-
eachCall(ast, calls(ast, 'listen'), (call) => {
|
|
333
|
-
const [, type] = call.arguments
|
|
334
|
-
|
|
335
|
-
if (type?.type === 'Literal' && typeof type.value === 'string' && Object.hasOwn(EVENT_HOOKS, type.value))
|
|
336
|
-
hits.push({ call, event: type.value })
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
if (hits.length === 0)
|
|
340
|
-
continue
|
|
341
|
-
|
|
342
|
-
const fixable = hits.filter(({ call, event }) => EVENT_HOOKS[event]!.method !== undefined && rewritable(call, source, base))
|
|
343
|
-
const own = (mentions(parsed.map(one => one.ast), 'navigation') || NAVIGATION.test(unparsed)) && !importsOf(ast, FROM_KAY, 'navigation').locals.has('navigation')
|
|
344
|
-
// `listen` leaves the import when every use of it, in the other spans and the template too, is a call rewritten here; a call inside another's handler overlaps its edit, so none is rewritten.
|
|
345
|
-
const nested = fixable.some(({ call }) => fixable.some(other => other.call !== call && other.call.start >= call.start && other.call.end <= call.end))
|
|
346
|
-
const dropped = !LISTEN.test(unparsed) && parsed.every(one => one.ast === ast || reads(one.ast, 'listen') === 0) && reads(ast, 'listen') === fixable.length
|
|
347
|
-
const imports = own || nested || fixable.length === 0 ? null : importEdits(ast, base, source, dropped ? ['listen'] : [], 'navigation')
|
|
348
|
-
const all = imports ? [...fixable.map(({ call, event }) => ({ start: base + call.start, end: base + call.end, text: `navigation.${EVENT_HOOKS[event]!.method}(${source.slice(base + call.arguments[2]!.start, base + call.arguments[2]!.end)})` })), ...imports] : null
|
|
349
|
-
|
|
350
|
-
for (const { call, event } of hits) {
|
|
351
|
-
const { hook } = EVENT_HOOKS[event]!
|
|
352
|
-
|
|
353
|
-
report(base + call.callee.start, base + call.callee.end, `an island listening to \`${event}\` is deprecated since 1.105: ${hook} is the function hook, the event being for a plain script`, `use ${hook}`, fixable.some(one => one.call === call) ? all : null)
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
})
|
|
357
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { CheckDiagnostic, CheckOptions } from '.'
|
|
2
|
-
import type { Property } from './regroup'
|
|
3
|
-
import { lintLevel } from '../compiler/lints'
|
|
4
|
-
import { CONFIG_KEYS } from '../config-shape'
|
|
5
|
-
import { configObjects, isProperty, propertyOf } from './config-objects'
|
|
6
|
-
import { nameOf, regrouped } from './regroup'
|
|
7
|
-
import { scan } from './renamed-exports'
|
|
8
|
-
|
|
9
|
-
const NEEDLE = /\b(?:pages|testSite)\b/
|
|
10
|
-
|
|
11
|
-
// The config keys written beside `root` in the options of `pages()` and `testSite()`, `config` since 1.105: the options are the project's own (`root`, `dev`, `prebuilt`, and a test site's `browser`, `headers` and the like) and the config they lay over `kay.config.ts` is one key, not a copy of the config's whole shape.
|
|
12
|
-
// The fix, from the first report of a call, moves the keys into a new `config` and offers none where the options spread, hold a computed key or have a `config` already.
|
|
13
|
-
export async function pagesOptions(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
14
|
-
if (lintLevel('deprecated-pages-options', options.lints) === 'allow')
|
|
15
|
-
return []
|
|
16
|
-
|
|
17
|
-
return scan(root, options, 'deprecated-pages-options', NEEDLE, ({ parsed, file, report }) => {
|
|
18
|
-
for (const { ast, base, text } of parsed) {
|
|
19
|
-
for (const { object, call, others } of configObjects(file, ast)) {
|
|
20
|
-
if (call === undefined)
|
|
21
|
-
continue
|
|
22
|
-
|
|
23
|
-
const old = object.properties.filter((property): property is Property => isProperty(property) && !property.computed && CONFIG_KEYS.has(nameOf(property)) && !others.includes(nameOf(property)))
|
|
24
|
-
|
|
25
|
-
if (old.length === 0)
|
|
26
|
-
continue
|
|
27
|
-
|
|
28
|
-
const fixed = propertyOf(object, 'config') === undefined ? regrouped(object, text, name => CONFIG_KEYS.has(name) && !others.includes(name) ? ['config', name] : undefined, true) : undefined
|
|
29
|
-
|
|
30
|
-
for (const [index, property] of old.entries())
|
|
31
|
-
report(base + property.start, base + property.end, `\`${nameOf(property)}\` beside the options of \`${call}()\` is deprecated since 1.105: the config is one key, \`config\``, `write \`config: { ${nameOf(property)} }\``, index === 0 && fixed !== undefined ? fixed.map(edit => ({ ...edit, start: base + edit.start, end: base + edit.end })) : null)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { CheckDiagnostic, CheckOptions } from '.'
|
|
2
|
-
import type { Node, Program } from '../compiler/estree'
|
|
3
|
-
import { lintLevel } from '../compiler/lints'
|
|
4
|
-
import { importsOf, walk } from './ast'
|
|
5
|
-
import { scan } from './renamed-exports'
|
|
6
|
-
|
|
7
|
-
const NEEDLE = /\.enforce\b/
|
|
8
|
-
const FROM_SERVER = (source: string) => source === 'kay/server'
|
|
9
|
-
const HELP = 'write `check`, which refuses with a 429 as `enforce` did'
|
|
10
|
-
|
|
11
|
-
// `limit.enforce(ctx)` on what `rateLimit()` returns, `limit.check(ctx)` since 1.105: `limiter().enforce(key)` counts under a key and refuses nothing, so the one name kept two meanings.
|
|
12
|
-
// Found in the TypeScript files and `.kay` files of the project, on a name bound once to a call of `rateLimit` imported from `kay/server`, as `kay check` reads no types; the fix renames the method.
|
|
13
|
-
export async function rateEnforce(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
14
|
-
if (lintLevel('deprecated-rate-enforce', options.lints) === 'allow')
|
|
15
|
-
return []
|
|
16
|
-
|
|
17
|
-
return scan(root, options, 'deprecated-rate-enforce', NEEDLE, ({ parsed, report }) => {
|
|
18
|
-
for (const { ast, base } of parsed) {
|
|
19
|
-
const { locals, namespaces } = importsOf(ast, FROM_SERVER, 'rateLimit')
|
|
20
|
-
|
|
21
|
-
if (locals.size === 0 && namespaces.size === 0)
|
|
22
|
-
continue
|
|
23
|
-
|
|
24
|
-
const limits = limitNames(ast, locals, namespaces)
|
|
25
|
-
|
|
26
|
-
walk(ast, (node) => {
|
|
27
|
-
if (node.type !== 'MemberExpression' || node.computed || node.object.type !== 'Identifier' || node.property.type !== 'Identifier' || node.property.name !== 'enforce' || !limits.has(node.object.name))
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
report(base + node.property.start, base + node.property.end, '`enforce` of a `rateLimit()` limit is `check` since 1.105', HELP, [{ start: base + node.property.start, end: base + node.property.end, text: 'check' }])
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// The names a file binds once to `rateLimit(...)`, or `server.rateLimit(...)` of a namespace import.
|
|
37
|
-
function limitNames(ast: Program, locals: Set<string>, namespaces: Set<string>): Set<string> {
|
|
38
|
-
const bound = new Map<string, number>()
|
|
39
|
-
const limits = new Set<string>()
|
|
40
|
-
const isLimit = (init: Node): boolean => init.type === 'CallExpression' && ((init.callee.type === 'Identifier' && locals.has(init.callee.name)) || (init.callee.type === 'MemberExpression' && !init.callee.computed && init.callee.object.type === 'Identifier' && namespaces.has(init.callee.object.name) && init.callee.property.type === 'Identifier' && init.callee.property.name === 'rateLimit'))
|
|
41
|
-
|
|
42
|
-
walk(ast, (node) => {
|
|
43
|
-
if (node.type !== 'VariableDeclarator' || node.id.type !== 'Identifier')
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
bound.set(node.id.name, (bound.get(node.id.name) ?? 0) + 1)
|
|
47
|
-
|
|
48
|
-
if (node.init && isLimit(node.init))
|
|
49
|
-
limits.add(node.id.name)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return new Set([...limits].filter(name => bound.get(name) === 1))
|
|
53
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import type { CheckDiagnostic, CheckOptions } from '.'
|
|
2
|
-
import type { Node, NodeOfType } from '../compiler/estree'
|
|
3
|
-
import type { LintName } from '../compiler/lints'
|
|
4
|
-
import type { Edit, Found } from './renamed-exports'
|
|
5
|
-
import { lintLevel } from '../compiler/lints'
|
|
6
|
-
import { importsOf, walk } from './ast'
|
|
7
|
-
import { scan } from './renamed-exports'
|
|
8
|
-
|
|
9
|
-
const FROM_KAY = (source: string) => source === 'kay' || source === 'kay/library' || source === '@kayjs/kay' || source === '@kayjs/kay/library'
|
|
10
|
-
const NEEDLE = /\b(?:deny|fail|refuse)\(/
|
|
11
|
-
const COMMENT = /\/[*/]/
|
|
12
|
-
const BEFORE_VALUE = /(?:\breturn|=>|\?)\s*$/
|
|
13
|
-
const BEFORE_COLON = /:\s*$/
|
|
14
|
-
const LAST_STATEMENT = /[^;{}\n]*$/
|
|
15
|
-
const CASE_LABEL = /^\s*(?:case\b|default\b)/
|
|
16
|
-
|
|
17
|
-
type Call = NodeOfType<'CallExpression'>
|
|
18
|
-
type Part = [key: string, text: string]
|
|
19
|
-
|
|
20
|
-
const isText = (node: Node | undefined): boolean => node?.type === 'TemplateLiteral' || (node?.type === 'Literal' && typeof node.value === 'string')
|
|
21
|
-
const isUndefined = (node: Node | undefined): boolean => node?.type === 'Identifier' && node.name === 'undefined'
|
|
22
|
-
|
|
23
|
-
// `{ message: 'x', data }`, a part written as its key when the text is that name.
|
|
24
|
-
function objectOf(parts: Part[]): string {
|
|
25
|
-
return `{ ${parts.map(([key, text]) => key === text ? key : `${key}: ${text}`).join(', ')} }`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// The edit swapping the arguments from `first` on for the object, or none when a comment sits between them, which the swap would drop.
|
|
29
|
-
function swapArguments(text: string, base: number, call: Call, first: number, parts: Part[]): Edit[] | null {
|
|
30
|
-
const from = call.arguments[first]!
|
|
31
|
-
|
|
32
|
-
if (COMMENT.test(text.slice(from.start, call.end)))
|
|
33
|
-
return null
|
|
34
|
-
|
|
35
|
-
return [{ start: base + from.start, end: base + call.end - 1, text: objectOf(parts) }]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// `ctx.deny(status, 'message', data)`, `ctx.deny(status, { message, data })` since 1.105: a refusal takes the one `{ message, errors, data }` everywhere, as `refuse(status, options)` does.
|
|
39
|
-
// Found on a call of `deny`, bare or read off a name, whose status is a literal from 400 to 599 and whose second argument is a text.
|
|
40
|
-
function denyCalls({ parsed, report }: Found): void {
|
|
41
|
-
for (const { ast, base, text } of parsed) {
|
|
42
|
-
walk(ast, (node) => {
|
|
43
|
-
if (node.type !== 'CallExpression' || !isDeny(node.callee) || node.arguments.length < 2 || node.arguments.length > 3 || !isErrorStatus(node.arguments[0]) || !isText(node.arguments[1]) || node.arguments.some(argument => argument.type === 'SpreadElement'))
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
const [, message, data] = node.arguments as [Node, Node, Node | undefined]
|
|
47
|
-
const parts: Part[] = [['message', text.slice(message.start, message.end)]]
|
|
48
|
-
|
|
49
|
-
if (data !== undefined && !isUndefined(data))
|
|
50
|
-
parts.push(['data', text.slice(data.start, data.end)])
|
|
51
|
-
|
|
52
|
-
// With `data`, an action fails the post as `ctx.fail` did instead of stopping with plain text, so that call is left to the app.
|
|
53
|
-
report(base + node.start, base + node.end, '`deny(status, message, data)` is `deny(status, { message, data })` since 1.105', 'write the message and the data in one object', data === undefined || isUndefined(data) ? swapArguments(text, base, node, 1, parts) : null)
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Whether a value is read from the call: after `return`, an arrow or a `?`, or a `:` closing a ternary, not a `case` or a label.
|
|
59
|
-
function isReturned(before: string): boolean {
|
|
60
|
-
if (BEFORE_VALUE.test(before))
|
|
61
|
-
return true
|
|
62
|
-
|
|
63
|
-
return BEFORE_COLON.test(before) && !CASE_LABEL.test(LAST_STATEMENT.exec(before)?.[0] ?? '') && (LAST_STATEMENT.exec(before)?.[0] ?? '').includes('?')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function isDeny(callee: Node): boolean {
|
|
67
|
-
return (callee.type === 'Identifier' && callee.name === 'deny') || (callee.type === 'MemberExpression' && !callee.computed && callee.property.type === 'Identifier' && callee.property.name === 'deny')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function isErrorStatus(node: Node | undefined): boolean {
|
|
71
|
-
return node?.type === 'Literal' && typeof node.value === 'number' && node.value >= 400 && node.value <= 599
|
|
72
|
-
}
|
|
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 and is written as the `message`, and a call with neither data nor errors is left, as `deny(status)` stops with plain text.
|
|
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
|
-
function failCalls({ parsed, report }: Found): void {
|
|
77
|
-
for (const { ast, base, text } of parsed) {
|
|
78
|
-
walk(ast, (node) => {
|
|
79
|
-
if (node.type !== 'CallExpression' || node.callee.type !== 'MemberExpression' || node.callee.computed || node.callee.object.type !== 'Identifier' || node.callee.object.name !== 'ctx' || node.callee.property.type !== 'Identifier' || node.callee.property.name !== 'fail' || node.arguments.length === 0)
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
const [status, data, errors] = node.arguments
|
|
83
|
-
const parts: Part[] = []
|
|
84
|
-
|
|
85
|
-
if (data !== undefined && !isUndefined(data))
|
|
86
|
-
parts.push([isText(data) ? 'message' : 'data', text.slice(data.start, data.end)])
|
|
87
|
-
|
|
88
|
-
if (errors !== undefined && !isUndefined(errors))
|
|
89
|
-
parts.push(['errors', text.slice(errors.start, errors.end)])
|
|
90
|
-
|
|
91
|
-
const returned = isReturned(text.slice(0, node.start))
|
|
92
|
-
const plain = node.arguments.length <= 3 && node.arguments.every(argument => argument.type !== 'SpreadElement') && status !== undefined && !COMMENT.test(text.slice(status.start, node.end))
|
|
93
|
-
const property = node.callee.property
|
|
94
|
-
const edits: Edit[] = [{ start: base + property.start, end: base + property.end, text: 'deny' }]
|
|
95
|
-
|
|
96
|
-
if (parts.length > 0)
|
|
97
|
-
edits.push({ start: base + status!.end, end: base + node.end - 1, text: `, ${objectOf(parts)}` })
|
|
98
|
-
|
|
99
|
-
report(base + node.start, base + node.end, '`ctx.fail(status, data, errors)` is `ctx.deny(status, { data, errors })` since 1.105', 'write `ctx.deny` with the data and the errors in one object', returned && plain && parts.length > 0 ? edits : null)
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// `refuse('message', { status, errors, data })`, `refuse(status, { message, errors, data })` since 1.105.
|
|
105
|
-
// Found on a call of `refuse` imported from `kay`, whose first argument is a text; the fix is made when the options are an object written in the call and the status is known.
|
|
106
|
-
function refuseCalls({ parsed, report }: Found): void {
|
|
107
|
-
for (const { ast, base, text } of parsed) {
|
|
108
|
-
const { locals, namespaces } = importsOf(ast, FROM_KAY, 'refuse')
|
|
109
|
-
|
|
110
|
-
if (locals.size === 0 && namespaces.size === 0)
|
|
111
|
-
continue
|
|
112
|
-
|
|
113
|
-
walk(ast, (node) => {
|
|
114
|
-
const named = node.type === 'CallExpression' && (node.callee.type === 'Identifier' ? locals.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 === 'refuse')
|
|
115
|
-
|
|
116
|
-
if (!named || node.type !== 'CallExpression' || !isText(node.arguments[0]) || node.arguments.length > 2)
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
report(base + node.start, base + node.end, '`refuse(message, { status, errors, data })` is `refuse(status, { message, errors, data })` since 1.105', 'write the status first and the message in the options', refuseEdits(text, base, node))
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function fieldsOf(errors: Node): 'none' | 'named' | 'unknown' {
|
|
125
|
-
if (errors.type !== 'ObjectExpression')
|
|
126
|
-
return 'unknown'
|
|
127
|
-
|
|
128
|
-
if (errors.properties.some(property => property.type === 'SpreadElement'))
|
|
129
|
-
return 'unknown'
|
|
130
|
-
|
|
131
|
-
return errors.properties.length > 0 ? 'named' : 'none'
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function refuseEdits(text: string, base: number, call: Call): Edit[] | null {
|
|
135
|
-
const [message, options] = call.arguments as [Node, Node | undefined]
|
|
136
|
-
const parts: Part[] = [['message', text.slice(message.start, message.end)]]
|
|
137
|
-
let status: string | undefined
|
|
138
|
-
// Without a status, `errors` naming fields is a 422, which only an object written in the call can be told to name some.
|
|
139
|
-
let fields: 'none' | 'named' | 'unknown' = 'none'
|
|
140
|
-
|
|
141
|
-
if (options !== undefined) {
|
|
142
|
-
if (options.type !== 'ObjectExpression' || COMMENT.test(text.slice(options.start, options.end)))
|
|
143
|
-
return null
|
|
144
|
-
|
|
145
|
-
for (const property of options.properties) {
|
|
146
|
-
if (property.type !== 'Property' || property.computed || property.kind !== 'init' || property.method || property.key.type !== 'Identifier')
|
|
147
|
-
return null
|
|
148
|
-
|
|
149
|
-
const { name } = property.key
|
|
150
|
-
const value = text.slice(property.value.start, property.value.end)
|
|
151
|
-
|
|
152
|
-
if (name === 'status') {
|
|
153
|
-
status = value
|
|
154
|
-
}
|
|
155
|
-
else if (name === 'data') {
|
|
156
|
-
parts.push([name, value])
|
|
157
|
-
}
|
|
158
|
-
else if (name === 'errors') {
|
|
159
|
-
parts.push([name, value])
|
|
160
|
-
fields = fieldsOf(property.value)
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
return null
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (status === undefined && fields === 'unknown')
|
|
169
|
-
return null
|
|
170
|
-
|
|
171
|
-
return [{ start: base + message.start, end: base + (options ?? message).end, text: `${status ?? (fields === 'named' ? '422' : '403')}, ${objectOf(parts)}` }]
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const SCANS: [LintName, (found: Found) => void][] = [
|
|
175
|
-
['deprecated-deny-call', denyCalls],
|
|
176
|
-
['deprecated-ctx-fail', failCalls],
|
|
177
|
-
['deprecated-refuse-call', refuseCalls],
|
|
178
|
-
]
|
|
179
|
-
|
|
180
|
-
// The three spellings of a refusal before 1.105, found in the TypeScript files and `.kay` files of the project as `kay check` reads no types: a call through a name it cannot follow is not found.
|
|
181
|
-
export async function refusalCalls(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
182
|
-
const found = await Promise.all(SCANS.filter(([lint]) => lintLevel(lint, options.lints) !== 'allow').map(async ([lint, visit]) => scan(root, options, lint, NEEDLE, visit)))
|
|
183
|
-
|
|
184
|
-
return found.flat()
|
|
185
|
-
}
|