@kayjs/kay 1.105.0 → 1.106.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 +435 -120
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +1 -1
- package/llms/actions-from-islands.md +2 -2
- package/llms/actions.md +22 -19
- package/llms/analytics.md +1 -1
- package/llms/api-from-islands.md +1 -1
- package/llms/api-routes.md +6 -6
- 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/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 +3 -2
- package/llms/dev-tool.md +2 -2
- package/llms/environment.md +22 -22
- package/llms/files.md +5 -5
- package/llms/islands-state-to-ids.md +2 -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.md +1 -1
- 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 +10 -5
- 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 +18 -3
- package/llms/whats-new-archive.md +35 -66
- package/llms/whats-new.md +34 -28
- package/llms.txt +1 -1
- package/package.json +15 -11
- package/src/add.ts +1 -1
- package/src/build/class-table.ts +2 -2
- package/src/build/client.ts +7 -6
- package/src/build/plugin.ts +14 -11
- package/src/build/styles.ts +3 -3
- package/src/build/transform.ts +3 -1
- package/src/build/ui-layers.ts +30 -0
- package/src/build/ui.ts +108 -11
- package/src/build/variants.ts +119 -43
- package/src/build/worker-bundle.ts +6 -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/secret-keys.ts +15 -2
- package/src/check/shadow-types.ts +2 -0
- 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 +6 -6
- package/src/compiler/deprecated-lints-1-106.ts +14 -0
- package/src/compiler/deprecated-lints.ts +10 -5
- 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/index.ts +3 -1
- package/src/compiler/items.ts +5 -5
- package/src/compiler/link-flags.ts +6 -5
- package/src/compiler/lints.ts +12 -12
- package/src/compiler/rest-omits.ts +15 -0
- 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/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/runtime/action-shared.ts +2 -2
- package/src/runtime/action.ts +6 -2
- package/src/runtime/form-types.ts +99 -0
- package/src/runtime/form.ts +22 -7
- package/src/runtime/html.ts +36 -5
- 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 +31 -0
- package/src/runtime/schema.client.ts +1 -4
- package/src/runtime/schema.ts +321 -26
- package/src/runtime/swap-focus.ts +59 -11
- package/src/server/action-module.ts +16 -0
- package/src/server/actions.ts +6 -14
- package/src/server/api-modules.ts +1 -1
- package/src/server/api.ts +13 -1
- package/src/server/app-stages.ts +23 -18
- package/src/server/dev-ui.ts +2 -2
- 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/image-metadata-bmff.ts +1 -1
- package/src/server/kept-pages.ts +3 -3
- package/src/server/library.ts +2 -0
- package/src/server/mcp.ts +13 -12
- package/src/server/notifications.ts +4 -2
- package/src/server/offline.ts +24 -7
- package/src/server/push-settings.ts +16 -2
- package/src/server/push.ts +12 -4
- package/src/server/query.ts +13 -6
- package/src/server/render.ts +1 -1
- package/src/server/scope.ts +20 -13
- package/src/server/signals.ts +4 -4
- 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 +8 -1
- 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.map +1 -1
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/transform.d.ts +1 -0
- 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/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/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 +1 -0
- package/types/compiler/codegen.d.ts.map +1 -1
- 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.d.ts +32 -5
- 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/index.d.ts +1 -0
- package/types/compiler/index.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/link-flags.d.ts +6 -0
- package/types/compiler/link-flags.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +44 -17
- 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/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/runtime/action-shared.d.ts +1 -1
- package/types/runtime/action-shared.d.ts.map +1 -1
- package/types/runtime/action.d.ts +3 -0
- package/types/runtime/action.d.ts.map +1 -1
- 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 +3 -1
- 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/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 +94 -10
- package/types/runtime/schema.d.ts.map +1 -1
- package/types/runtime/swap-focus.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/api.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +3 -2
- package/types/server/app-stages.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/kept-pages.d.ts +1 -1
- package/types/server/kept-pages.d.ts.map +1 -1
- package/types/server/library.d.ts +2 -0
- 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/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/scope.d.ts +1 -1
- package/types/server/scope.d.ts.map +1 -1
- 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/compiler/codegen.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { helperName } from './markup'
|
|
|
25
25
|
import { defaultName, LOAD, LOAD_KEY, LOAD_RUN, LOAD_TABLE, PROPS, VALUES } from './names'
|
|
26
26
|
import { ownMarkupOf } from './own-markup'
|
|
27
27
|
import { PAGE, PAGE_SETTINGS } from './page-settings'
|
|
28
|
+
import { restOmits } from './rest-omits'
|
|
28
29
|
import { reactiveValue } from './script'
|
|
29
30
|
import { kayCtxImport } from './script-shared'
|
|
30
31
|
import { slotTypes } from './slot-types'
|
|
@@ -103,6 +104,8 @@ export interface GenerateOptions {
|
|
|
103
104
|
ui?: UiEntry | undefined
|
|
104
105
|
// Type checking's counterpart of `ui`: the variants and values `src/ui.ts` adds to the component's props.
|
|
105
106
|
uiAdded?: UiEntry | undefined
|
|
107
|
+
// Browser variant builds: the props the project's call sites write, so the rest list omits only those (the others cannot arrive); absent, every declared prop is omitted.
|
|
108
|
+
writtenProps?: ReadonlySet<string> | undefined
|
|
106
109
|
// Final pass: rewrites from the analysis pass are applied and the props destructuring disappears.
|
|
107
110
|
rewrites?: ReadonlyMap<number, Rewrite & { end: number }> | undefined
|
|
108
111
|
// Type checking's final pass: the value of each signal the template reads, declared under `VALUES`.
|
|
@@ -293,7 +296,7 @@ class ModuleShell {
|
|
|
293
296
|
else if (head && this.kind === 'island')
|
|
294
297
|
this.emitIslandTitle(head)
|
|
295
298
|
|
|
296
|
-
this.b.add('\
|
|
299
|
+
this.b.add(`\n${this.mode === 'dom' && this.facts.ambientForm ? `const KayHere = ${helperName('formHere')}()\n` : ''}return `)
|
|
297
300
|
this.template(template, errors)
|
|
298
301
|
this.exports()
|
|
299
302
|
|
|
@@ -329,7 +332,7 @@ class ModuleShell {
|
|
|
329
332
|
if (server)
|
|
330
333
|
b.add(`import type { ${this.pageContextType()} as KayPageContext, PageData as KayPageData${this.guardValues() !== undefined ? ', GuardValues as KayGuardValues' : ''}${this.declaresQuery() !== undefined ? ', QueryOf as KayQueryOf' : ''}${this.settingType(PRERENDER) !== undefined ? ', PrerenderedContext as KayPrerenderedContext' : ''}${mode === 'check' && server.page ? ', PageSettings as KayPageSettings' : ''}${this.actionsTyped ? ', ActionFor as KayActionFor' : ''} } from 'kay'\n`)
|
|
331
334
|
|
|
332
|
-
const kayHelpers: KayHelper[] = [...facts.actionForm ? ['formAction' as const] : [], ...ambientHelpers(facts)]
|
|
335
|
+
const kayHelpers: KayHelper[] = [...facts.actionForm ? ['formAction' as const] : [], ...ambientHelpers(facts, mode)]
|
|
333
336
|
|
|
334
337
|
if (this.rootBlocks().length > 0)
|
|
335
338
|
kayHelpers.push('fill')
|
|
@@ -885,10 +888,7 @@ class ModuleShell {
|
|
|
885
888
|
}
|
|
886
889
|
|
|
887
890
|
if (props.rest) {
|
|
888
|
-
const
|
|
889
|
-
const keys = [...props.bindings.map(binding => JSON.stringify(binding.key)), ...owned ? ['"class"', '"parts"'] : [], ...owned && this.facts.recipe !== undefined ? [`...${this.facts.recipe}.variants`] : [], ...owned ? Object.keys(this.facts.ui?.variants ?? {}).map(name => JSON.stringify(name)) : []]
|
|
890
|
-
|
|
891
|
-
b.add('const ').addSource(props.rest).add(` = ${helperName('omit')}(${PROPS}, ${keys.join(', ')});\n`)
|
|
891
|
+
b.add('const ').addSource(props.rest).add(` = ${helperName('omit')}(${PROPS}, ${restOmits(props, this.options.writtenProps, this.facts).join(', ')});\n`)
|
|
892
892
|
}
|
|
893
893
|
|
|
894
894
|
// The analysis pass declares the destructured names so scope analysis can find every read of them; the final pass rewrites those reads instead.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Lint } from './lints'
|
|
2
|
+
|
|
3
|
+
// The lints of the `deprecated` group that came in 1.106, with the others in `DEPRECATED_LINTS`.
|
|
4
|
+
export const SCHEMA_BUILDERS = {
|
|
5
|
+
'deprecated-schema-builders': {
|
|
6
|
+
level: 'warn',
|
|
7
|
+
group: 'deprecated',
|
|
8
|
+
since: '1.106',
|
|
9
|
+
site: true,
|
|
10
|
+
summary: 'The PascalCase builders of `s` before 1.106, which kay\'s own lowercase builders replace, each taking the same field options (`optional`, `default`, `error`, `label`, `description`, `example`) and short names for the rest: `s.String` is `s.string` (`min`, `max`), `s.Integer` `s.int`, `s.Number` and `s.Numeric` `s.number`, `s.Boolean` and `s.BooleanString` `s.boolean`, `s.Array` `s.list`, `s.UnionEnum` and `s.UnionKeys` `s.enum`, and `s.Date`, `s.Literal`, `s.Union`, `s.Object`, `s.File`, `s.Files`, `s.Secret` and `s.Public` their lowercase names; `s.Optional(field)` is `optional: true` in the options of the field; an `s.Object({ ... })` that is the schema of an `action` or a `defineEnv` is the record of fields alone; and a file size written `\'2m\'` is `\'2mb\'`. The old names work until 2.0. Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. The fix renames the builder and the options that changed; an `s.Optional` around anything but one of these builders, such as a helper of `kay/content`, is left as it is. A lowercase `s.object` refuses a key its shape lacks where kay reads the schema itself (collection frontmatter, `defineEnv`), where `s.Object` let it by: write `{ extra: \'strip\' }` where the old way is wanted. A query, the headers and the cookies of a request carry keys no schema names, so their unknown keys are dropped whatever the schema says.',
|
|
11
|
+
wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.Object({ title: s.String({ maxLength: 200 }), note: s.Optional(s.String()) }), ({ title }) => title)\n---\np x',
|
|
12
|
+
right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ title: s.string({ max: 200 }), note: s.string({ optional: true }) }, ({ title }) => title)\n---\np x',
|
|
13
|
+
},
|
|
14
|
+
} as const satisfies Record<string, Lint>
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Lint } from './lints'
|
|
2
2
|
import { AUTH_LINTS } from './deprecated-auth-lints'
|
|
3
|
+
import { SCHEMA_BUILDERS } from './deprecated-lints-1-106'
|
|
4
|
+
import { TYPED_DEPRECATIONS } from './deprecated-typed-lints'
|
|
3
5
|
|
|
4
6
|
// The lints of the `deprecated` group, with the other lints in `LINTS`; each stays three minors from its `since`.
|
|
5
7
|
export const DEPRECATED_LINTS = {
|
|
8
|
+
...SCHEMA_BUILDERS,
|
|
6
9
|
'deprecated-source-readers': {
|
|
7
10
|
level: 'warn',
|
|
8
11
|
group: 'deprecated',
|
|
@@ -85,7 +88,7 @@ export const DEPRECATED_LINTS = {
|
|
|
85
88
|
group: 'deprecated',
|
|
86
89
|
since: '1.104',
|
|
87
90
|
site: true,
|
|
88
|
-
summary: 'A package of kay under the `@kaynooo` scope, `@kayjs` since 1.104: `@kaynooo/kayjs` is `@kayjs/kay`, and `@kaynooo/kayjs-ui`, `-auth`, `-mail`, `-cms` and `-ai` are `@kayjs/ui`, `@kayjs/auth`, `@kayjs/mail`, `@kayjs/cms` and `@kayjs/ai`. The old names stop at 1.103, which stays installable, so an app on them installs and checks as before until it moves; this lint goes in 1.107. Found
|
|
91
|
+
summary: 'A package of kay under the `@kaynooo` scope, `@kayjs` since 1.104: `@kaynooo/kayjs` is `@kayjs/kay`, and `@kaynooo/kayjs-ui`, `-auth`, `-mail`, `-cms` and `-ai` are `@kayjs/ui`, `@kayjs/auth`, `@kayjs/mail`, `@kayjs/cms` and `@kayjs/ai`. The old names stop at 1.103, which stays installable, so an app on them installs and checks as before until it moves; this lint goes in 1.107. Found where a name is an `import` or `export ... from` specifier, a `require()`, `import()` or `mock.module()` argument or a config key (a quoted name keyed to anything but a package name or a version, as `librarySettings`) of the project\'s TypeScript and `.kay` files, in the `@import` and `@plugin` paths of its CSS, and in its package.json and tsconfig files; a name in a comment or any other string, as data a tool reads or a table of renames, is left alone. The fix writes the new name; a package.json that lists the new name already is reported with a fix that is not safe, and `kay upgrade` does the whole move, package.json and install included.',
|
|
89
92
|
wrong: '---\nimport Button from \'@kaynooo/kayjs-ui/button.kay\'\n---\nButton Save',
|
|
90
93
|
right: '---\nimport Button from \'@kayjs/ui/button.kay\'\n---\nButton Save',
|
|
91
94
|
},
|
|
@@ -126,7 +129,7 @@ export const DEPRECATED_LINTS = {
|
|
|
126
129
|
level: 'warn',
|
|
127
130
|
group: 'deprecated',
|
|
128
131
|
since: '1.105',
|
|
129
|
-
summary: '`data-keep-scroll`, `data-no-transition` and `data-no-prefetch`, named as the options of `navigate()` since 1.105: `data-scroll="keep"` (`"top"` for a plain scroll), `data-transition="false"` and `data-prefetch="false"`, typed on every element. The old names work until 1.108. Found on any element and on a component call that forwards them to its link. The fix writes the new attribute, a static `data-keep-scroll="false"` becoming `data-scroll="top"` and a dynamic `data-keep-scroll` being renamed with its value; a dynamic `data-no-transition` or `data-no-prefetch` is reported with no fix, as the old name was set by being present.',
|
|
132
|
+
summary: '`data-keep-scroll`, `data-no-transition` and `data-no-prefetch`, named as the options of `navigate()` since 1.105: `data-scroll="keep"` (`"top"` for a plain scroll), `data-transition="false"` and `data-prefetch="false"`, typed on every element. The old names work until 1.108. Found on any element and on a component call that forwards them to its link. The fix writes the new attribute, a static `data-keep-scroll="false"` becoming `data-scroll="top"` and a dynamic `data-keep-scroll` being renamed with its value; a dynamic `data-no-transition` or `data-no-prefetch` is reported with no fix, as the old name was set by being present. The app\'s test files (`*.test.*`, `*.spec.*`) are checked too: a selector `[data-keep-scroll]` is written `[data-scroll=keep]` by the fix, an attribute read by name (`getAttribute(\'data-keep-scroll\')`) has a fix that is not safe, a read of `dataset.keepScroll` (and `noTransition`, `noPrefetch`) has one too, and a write of it and any other string naming an old flag have none.',
|
|
130
133
|
wrong: 'nav(data-keep-scroll)\n a(href="/tabs/a" data-no-prefetch) A',
|
|
131
134
|
right: 'nav(data-scroll="keep")\n a(href="/tabs/a" data-prefetch="false") A',
|
|
132
135
|
},
|
|
@@ -181,6 +184,7 @@ export const DEPRECATED_LINTS = {
|
|
|
181
184
|
right: '---\nimport SignedIn from \'@kayjs/auth/components/signed-in.kay\'\n---\nSignedIn(require="admin")\n a(href="/admin") Admin',
|
|
182
185
|
},
|
|
183
186
|
...AUTH_LINTS,
|
|
187
|
+
...TYPED_DEPRECATIONS,
|
|
184
188
|
'deprecated-ui-callbacks': {
|
|
185
189
|
level: 'warn',
|
|
186
190
|
group: 'deprecated',
|
|
@@ -405,7 +409,7 @@ export const DEPRECATED_LINTS = {
|
|
|
405
409
|
group: 'deprecated',
|
|
406
410
|
since: '1.105',
|
|
407
411
|
site: true,
|
|
408
|
-
summary: 'The keys `images`, `fonts`, `favicon`, `manifest` and `publicCache` of kay.config.ts, written in `assets` since 1.105, and `observe`, `health`, `metrics` and `jobs`, written in `ops`: `assets: { images, fonts, favicon, manifest, publicCache }`, `ops: { observe, health, metrics, jobs }`. They work until 1.108. Found in the object kay.config.ts exports
|
|
412
|
+
summary: 'The keys `images`, `fonts`, `favicon`, `manifest` and `publicCache` of kay.config.ts, written in `assets` since 1.105, and `observe`, `health`, `metrics` and `jobs`, written in `ops`: `assets: { images, fonts, favicon, manifest, publicCache }`, `ops: { observe, health, metrics, jobs }`. They work until 1.108. Found in the object kay.config.ts exports, in the `config` of `pages()` and `testSite()` and in the `config` of an extension a file types `KayExtension`, which takes the same keys. The fix moves the keys into their group as written, unless the object spreads, holds a computed key or has the group already.',
|
|
409
413
|
wrong: '// kay.config.ts\nexport default { images: { widths: [640] }, health: false }',
|
|
410
414
|
right: '// kay.config.ts\nexport default { assets: { images: { widths: [640] } }, ops: { health: false } }',
|
|
411
415
|
},
|
|
@@ -432,7 +436,7 @@ export const DEPRECATED_LINTS = {
|
|
|
432
436
|
group: 'deprecated',
|
|
433
437
|
since: '1.105',
|
|
434
438
|
site: true,
|
|
435
|
-
summary: 'The secrets of kay.config.ts in one shape since 1.105, each `string | { env } | { file }`: `mcp.key` is `mcp.token`, and `proxy.key`, a header name, is `{ header, secret? }`, so `proxy: { key: { header: \'x-upstream-key\' } }`; the `mcpKey` and `proxyKey` options of `testSite()` are the `token` and the `secret` of its `config`. They work until 1.108. Found in the object kay.config.ts exports and in the `config` of `pages()` and `testSite()`. The fix renames `mcp.key` (a `key: false` and an `mcp` that spreads or has a `token` are reported with no fix) and wraps the header of `proxy.key`; the options of `testSite()` are reported with no fix.',
|
|
439
|
+
summary: 'The secrets of kay.config.ts in one shape since 1.105, each `string | { env } | { file }`: `mcp.key` is `mcp.token`, and `proxy.key`, a header name, is `{ header, secret? }`, so `proxy: { key: { header: \'x-upstream-key\' } }`; the `mcpKey` and `proxyKey` options of `testSite()` are the `token` and the `secret` of its `config`. They work until 1.108. Found in the object kay.config.ts exports and in the `config` of `pages()` and `testSite()`. The fix renames `mcp.key` (a `key: false` and an `mcp` that spreads or has a `token` are reported with no fix) and wraps the header of `proxy.key`; the options of `testSite()` move into its `config`, `mcpKey` always and `proxyKey` where the app\'s config names the header, and are reported with no fix beside a `config` already written.',
|
|
436
440
|
wrong: '// kay.config.ts\nexport default { mcp: { key: true }, proxy: { key: \'x-upstream-key\' } }',
|
|
437
441
|
right: '// kay.config.ts\nexport default { mcp: { token: true }, proxy: { key: { header: \'x-upstream-key\' } } }',
|
|
438
442
|
},
|
|
@@ -504,7 +508,7 @@ export const DEPRECATED_LINTS = {
|
|
|
504
508
|
group: 'deprecated',
|
|
505
509
|
since: '1.105',
|
|
506
510
|
site: true,
|
|
507
|
-
summary: '`deny(status, \'message\', data)` of a guard, a page, an action and an endpoint, `deny(status, { message, errors, data })` since 1.105: a refusal takes one object in every place, as `refuse(status, { message, errors, data })` does, so `errors` puts a message on a field and the text is no longer an argument beside the data. An action answers `deny(status, { data, errors })` as `ctx.fail
|
|
511
|
+
summary: '`deny(status, \'message\', data)` of a guard, a page, an action and an endpoint, `deny(status, { message, errors, data })` since 1.105: a refusal takes one object in every place, as `refuse(status, { message, errors, data })` does, so `errors` puts a message on a field and the text is no longer an argument beside the data. An action answers `deny(status, { message, data, errors })` as `ctx.fail` did, the page again or an `ActionError`, so its text form, which stopped with plain text, becomes the form\'s message after the fix. The text form works until 1.108. Found on a call of `deny`, bare or read off a name, with a literal status from 400 to 599 and a text second argument, in the TypeScript files and `.kay` files of the project. The fix writes the object, unless a comment sits between the arguments or a `data` is given, which an action answers as a failure, not plain text.',
|
|
508
512
|
wrong: '// src/routes/_guard.ts\nimport { guard } from \'kay\'\n\nexport default guard(({ deny }) => {\n deny(403, \'Members only\')\n})',
|
|
509
513
|
right: '// src/routes/_guard.ts\nimport { guard } from \'kay\'\n\nexport default guard(({ deny }) => {\n deny(403, { message: \'Members only\' })\n})',
|
|
510
514
|
},
|
|
@@ -595,4 +599,5 @@ export const DEPRECATION_MINORS: readonly { since: string, removedIn?: string }[
|
|
|
595
599
|
{ since: '1.103' },
|
|
596
600
|
{ since: '1.104' },
|
|
597
601
|
{ since: '1.105' },
|
|
602
|
+
{ since: '1.106' },
|
|
598
603
|
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Lint } from './lints'
|
|
2
|
+
|
|
3
|
+
// The deprecated lints the type check finds, apart from the others: an old form the types of 1.105 refuse, which `kay check` names with the fix instead of leaving its type error.
|
|
4
|
+
export const TYPED_DEPRECATIONS = {
|
|
5
|
+
'deprecated-callback-handler': {
|
|
6
|
+
level: 'deny',
|
|
7
|
+
group: 'deprecated',
|
|
8
|
+
since: '1.105',
|
|
9
|
+
typed: true,
|
|
10
|
+
summary: 'A function written for the arguments a kayjs-ui, kayjs-ai or kayjs-cms callback took before 1.105, given to a callback that takes one event object since: `onValueChange={query.set}`, `onCheckedChange={toggle}` with `toggle(on: boolean)` or `onFiles={upload}` with `upload(files: File[])`. Found where the type check refuses the function and the component comes from a `@kayjs` library; the fix writes `event => query.set(event.value)`, passing the fields the handler took, first ones first, and is applied where its parameter is no object (a parameter typed as an object may be written for the event already, so that fix is offered). A handler that is not a plain name, such as an arrow function, is reported with no fix. The old form fails the type check, and would receive the event where it took the value, so the level is `deny` until it is rewritten.',
|
|
11
|
+
wrong: '---\nimport { signal } from \'kay\'\nimport Checkbox from \'@kayjs/ui/checkbox.kay\'\n\nconst on = signal(false)\n\nfunction toggle(next: boolean) {\n on.set(next)\n}\n---\nCheckbox(label="Notify" checked={on()} onChange={toggle})',
|
|
12
|
+
right: '---\nimport { signal } from \'kay\'\nimport Checkbox from \'@kayjs/ui/checkbox.kay\'\n\nconst on = signal(false)\n\nfunction toggle(next: boolean) {\n on.set(next)\n}\n---\nCheckbox(label="Notify" checked={on()} onChange={event => toggle(event.checked)})',
|
|
13
|
+
},
|
|
14
|
+
'deprecated-call-result': {
|
|
15
|
+
level: 'deny',
|
|
16
|
+
group: 'deprecated',
|
|
17
|
+
since: '1.105',
|
|
18
|
+
typed: true,
|
|
19
|
+
summary: 'An island\'s call read as its data, `const list = await call(notes, \'/\')` then `list.items`, or `await add(input)` then `.id`, which resolved with the data before 1.105 and answers a `CallResult`, `{ ok: true, data }` or `{ ok: false, error }`, since. Found where the type check refuses a field of a `CallResult`, in a `.kay` script or a module. The fix writes `.orThrow()` after the call, which resolves with the data and throws a refusal as the call did; it is applied where the call is written on an imported name and nothing reads `ok`, `data` or `error` of the answer, and offered otherwise. The old form fails the type check, so the level is `deny`.',
|
|
20
|
+
wrong: '---\nimport { call, signal } from \'kay\'\nimport notes from \'../api/notes\'\n\nconst names = signal(\'\')\n\nasync function load() {\n const list = await call(notes, \'/\')\n\n names = list.items.join(\', \')\n}\n---\nbutton(onClick={load}) Load\np {names()}',
|
|
21
|
+
right: '---\nimport { call, signal } from \'kay\'\nimport notes from \'../api/notes\'\n\nconst names = signal(\'\')\n\nasync function load() {\n const list = await call(notes, \'/\').orThrow()\n\n names = list.items.join(\', \')\n}\n---\nbutton(onClick={load}) Load\np {names()}',
|
|
22
|
+
},
|
|
23
|
+
} as const satisfies Record<string, Lint>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Node, SnippetNode, Span } from './ast'
|
|
2
|
+
import type { CodeBuilder } from './mapping'
|
|
3
|
+
import { someNode } from './ast'
|
|
4
|
+
import { helperName } from './markup'
|
|
5
|
+
|
|
6
|
+
const CALLED = /[a-z_$][\w$]*(?=\s*\()/gi
|
|
7
|
+
|
|
8
|
+
// The form each function of a template was called in, for the `error` and `pending` lines outside every form of their file: the template's own function and each block of content holding such a line (a snippet, the children a component is given) capture it once as it is called, as a line may be created again long after the render that knew the form.
|
|
9
|
+
export class FormHere {
|
|
10
|
+
private readonly names = ['KayHere']
|
|
11
|
+
private readonly snippets = new Set<string>()
|
|
12
|
+
private count = 0
|
|
13
|
+
|
|
14
|
+
// The name holding the form of the function being written.
|
|
15
|
+
get current(): string {
|
|
16
|
+
return this.names.at(-1)!
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Names a snippet, so a call of it inside a form is built in the form's scope.
|
|
20
|
+
declared(snippet: SnippetNode, src: string): SnippetNode {
|
|
21
|
+
this.snippets.add(src.slice(snippet.name.start, snippet.name.end))
|
|
22
|
+
|
|
23
|
+
return snippet
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The action a line follows: the form around it in the file, else the one its function was called in.
|
|
27
|
+
target(b: CodeBuilder, form: Span | undefined): void {
|
|
28
|
+
if (form)
|
|
29
|
+
b.add('(').addSource(form).add(')')
|
|
30
|
+
else
|
|
31
|
+
b.add(this.current)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Opens the scope a component's script runs in, the action of the form around it in the file; false when it has none.
|
|
35
|
+
scope(b: CodeBuilder, form: Span | undefined): boolean {
|
|
36
|
+
if (!form)
|
|
37
|
+
return false
|
|
38
|
+
|
|
39
|
+
b.add(`${helperName('issueScope')}(`)
|
|
40
|
+
this.target(b, form)
|
|
41
|
+
b.add(', () => ')
|
|
42
|
+
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// An expression inserted: one calling a snippet in a form is built inside the form's scope, as the component called there is, for its `error` and `pending` lines to follow it.
|
|
47
|
+
expression(b: CodeBuilder, expression: Span, src: string, form: Span | undefined): void {
|
|
48
|
+
const scoped = form !== undefined && src.slice(expression.start, expression.end).match(CALLED)?.some(name => this.snippets.has(name)) === true
|
|
49
|
+
|
|
50
|
+
if (scoped)
|
|
51
|
+
this.scope(b, form)
|
|
52
|
+
|
|
53
|
+
b.add('(').addSource(expression).add(scoped ? '))' : ')')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Writes a block of content, taking the form it is called in when it holds a line following one, falling back to the one of the function around it for a call made after the render.
|
|
57
|
+
within(b: CodeBuilder, nodes: Node[], forms: ReadonlyMap<Node, Span>, children: () => void): void {
|
|
58
|
+
if (!someNode(nodes, line => (line.kind === 'error' || line.kind === 'pending') && !forms.has(line))) {
|
|
59
|
+
children()
|
|
60
|
+
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const own = `KayHere${++this.count}`
|
|
65
|
+
|
|
66
|
+
b.add(`(() => { const ${own} = ${helperName('formHere')}() ?? ${this.current}; return `)
|
|
67
|
+
this.names.push(own)
|
|
68
|
+
children()
|
|
69
|
+
this.names.pop()
|
|
70
|
+
b.add('; })()')
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/compiler/dom.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { BindingPlan, LinkPlan } from './plan'
|
|
|
6
6
|
import { mayLeaveSite } from '../runtime/outside'
|
|
7
7
|
import { marksServerIsland, modifiersOf } from './ast'
|
|
8
8
|
import { fieldBindings } from './dom-fields'
|
|
9
|
+
import { FormHere } from './dom-here'
|
|
9
10
|
import { addHandler, listenerOptions } from './event-modifiers'
|
|
10
11
|
import { decodeEntities, isFunctionAt } from './expression'
|
|
11
12
|
import { addKeyParameters, addRowItem, childItems, constDeclaration, contentOf, errorParagraphArguments, isDeclaration, rowKeying, slotValue, soleDynamic } from './items'
|
|
@@ -44,6 +45,7 @@ export class DomTemplate extends TemplateWriter {
|
|
|
44
45
|
private readonly catches: string[] = []
|
|
45
46
|
// Whether the code may write a link's `href`, which an app with locales localizes through `kay/i18n-links`: only a module doing so imports it.
|
|
46
47
|
private writesLinks = false
|
|
48
|
+
private readonly here = new FormHere()
|
|
47
49
|
|
|
48
50
|
// `errors`: what a refused form's fields are described by.
|
|
49
51
|
// `located`, in development: the source position each element carries for `kay dev`'s inspector.
|
|
@@ -120,7 +122,9 @@ export class DomTemplate extends TemplateWriter {
|
|
|
120
122
|
|
|
121
123
|
switch (item.kind) {
|
|
122
124
|
case 'expression':
|
|
123
|
-
b.add(`KayInsert(${at}, () =>
|
|
125
|
+
b.add(`KayInsert(${at}, () => `)
|
|
126
|
+
this.here.expression(b, item.node.expression, this.src, this.formOf(item.line))
|
|
127
|
+
b.add(');')
|
|
124
128
|
|
|
125
129
|
break
|
|
126
130
|
case 'component':
|
|
@@ -187,27 +191,25 @@ export class DomTemplate extends TemplateWriter {
|
|
|
187
191
|
|
|
188
192
|
break
|
|
189
193
|
case 'error':
|
|
190
|
-
|
|
191
|
-
|
|
194
|
+
// With no form around it in the file, the message is read again when the action answers, outside any render, from the form the function was called in.
|
|
195
|
+
b.wrap(item.node, () => {
|
|
196
|
+
const target = this.formOf(item.node)
|
|
192
197
|
|
|
193
|
-
b.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// The form it renders in, taken now: the message is read again when the action answers, outside any render.
|
|
199
|
-
b.add(`{ const KayHere = ${helperName('formHere')}(); KayInsert(${at}, () => ${helperName('errorParagraph')}(${helperName('formError')}(KayHere, ${JSON.stringify(item.node.name)}), ${errorParagraphArguments(item.node, this.src, undefined)})); }`)
|
|
200
|
-
}
|
|
198
|
+
b.add(`KayInsert(${at}, () => ${helperName('errorParagraph')}(${helperName('formError')}(`)
|
|
199
|
+
|
|
200
|
+
this.here.target(b, target)
|
|
201
|
+
b.add(`, ${JSON.stringify(item.node.name)}), ${errorParagraphArguments(item.node, this.src, target ? this.errors?.lines.get(item.node) : undefined)}));`)
|
|
202
|
+
})
|
|
201
203
|
|
|
202
204
|
break
|
|
203
205
|
}
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
private declaration(item: Declaration): void {
|
|
207
|
-
if (item.kind === '
|
|
208
|
-
this.snippetDeclaration(item.node)
|
|
209
|
-
else
|
|
209
|
+
if (item.kind === 'const')
|
|
210
210
|
this.b.wrap(item.node, () => constDeclaration(this.b, item.node, this.src, helperName('memo')))
|
|
211
|
+
else
|
|
212
|
+
this.snippetDeclaration(this.here.declared(item.node, this.src))
|
|
211
213
|
}
|
|
212
214
|
|
|
213
215
|
private if(node: IfNode, at: string): void {
|
|
@@ -432,15 +434,14 @@ export class DomTemplate extends TemplateWriter {
|
|
|
432
434
|
return property === 'innerHTML' && !raw && checksMarkup(this.src, expression, this.ownMarkup) ? helperName('checkedMarkup') : ''
|
|
433
435
|
}
|
|
434
436
|
|
|
435
|
-
// An island's `pending` block shows while a call of its form's action is in flight, however the handler made it; with no form around it in the file, the action of the form
|
|
437
|
+
// An island's `pending` block shows while a call of its form's action is in flight, however the handler made it; with no form around it in the file, the action of the form the function was called in.
|
|
436
438
|
private followCalls(pending: PendingNode, node: TemplateNode): Binding {
|
|
437
439
|
const followed = this.formOf(pending)
|
|
438
440
|
|
|
439
441
|
return (variable) => {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
this.b.add(`{ const KayHere = ${helperName('formHere')}(); KayEffect(() => ${helperName('pendingCall')}(${variable(node)}, KayHere)); }`)
|
|
442
|
+
this.b.add(`KayEffect(() => ${helperName('pendingCall')}(${variable(node)}, `)
|
|
443
|
+
this.here.target(this.b, followed)
|
|
444
|
+
this.b.add('));')
|
|
444
445
|
}
|
|
445
446
|
}
|
|
446
447
|
|
|
@@ -767,20 +768,19 @@ export class DomTemplate extends TemplateWriter {
|
|
|
767
768
|
b.add(`(${helperName('holdSubmits')}(), `)
|
|
768
769
|
|
|
769
770
|
// The component's script runs inside the form's scope, so the fields it draws show the form's action's messages with no prop.
|
|
770
|
-
|
|
771
|
-
b.add(`${helperName(this.scoping)}((`).addSource(form).add('), () => ')
|
|
771
|
+
const scoped = this.here.scope(b, form)
|
|
772
772
|
|
|
773
773
|
b.add(dynamic ? 'KayDynamic(' : 'KayComponent(').addSource(element.tag).add(', ')
|
|
774
774
|
|
|
775
775
|
this.componentProps(element, true)
|
|
776
776
|
b.add(holds ? '))' : ')')
|
|
777
777
|
|
|
778
|
-
if (
|
|
778
|
+
if (scoped)
|
|
779
779
|
b.add(')')
|
|
780
780
|
}
|
|
781
781
|
|
|
782
782
|
protected rendered(nodes: Node[]): void {
|
|
783
|
-
this.block(nodes)
|
|
783
|
+
this.here.within(this.b, nodes, this.facts.forms, () => this.block(nodes))
|
|
784
784
|
}
|
|
785
785
|
|
|
786
786
|
// Inside an island a server island is a component as any other.
|
|
@@ -98,14 +98,14 @@ function lineEnd(source: string, end: number): number {
|
|
|
98
98
|
const SUGGESTED_MAX_LENGTH = 200
|
|
99
99
|
|
|
100
100
|
// Where and what to insert to bound a string field: a new options object, the first property of an empty one, or a property before the others.
|
|
101
|
-
function maxLengthEdit(call: NodeOfType<'CallExpression'>, options: NodeOfType<'CallExpression'>['arguments'][number] | undefined): { at: number, text: string } {
|
|
101
|
+
function maxLengthEdit(call: NodeOfType<'CallExpression'>, options: NodeOfType<'CallExpression'>['arguments'][number] | undefined, key: string): { at: number, text: string } {
|
|
102
102
|
if (options === undefined)
|
|
103
|
-
return { at: call.end - 1, text: `{
|
|
103
|
+
return { at: call.end - 1, text: `{ ${key}: ${SUGGESTED_MAX_LENGTH} }` }
|
|
104
104
|
|
|
105
105
|
if (options.type === 'ObjectExpression' && options.properties.length === 0)
|
|
106
|
-
return { at: options.start + 1, text: `
|
|
106
|
+
return { at: options.start + 1, text: ` ${key}: ${SUGGESTED_MAX_LENGTH} ` }
|
|
107
107
|
|
|
108
|
-
return { at: (options as NodeOfType<'ObjectExpression'>).properties[0]!.start, text:
|
|
108
|
+
return { at: (options as NodeOfType<'ObjectExpression'>).properties[0]!.start, text: `${key}: ${SUGGESTED_MAX_LENGTH}, ` }
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
const UNBOUNDED_QUANTIFIER = /^\{\d+,\}/
|
|
@@ -169,7 +169,7 @@ function isShortField(field: string): boolean {
|
|
|
169
169
|
export function unboundedFields(server: ServerAnalysis | undefined): Diagnostic[] {
|
|
170
170
|
const fence = server?.fence
|
|
171
171
|
|
|
172
|
-
if (!fence?.code.includes('String'))
|
|
172
|
+
if (!fence?.code.includes('String') && !fence?.code.includes('string'))
|
|
173
173
|
return []
|
|
174
174
|
|
|
175
175
|
const diagnostics: Diagnostic[] = []
|
|
@@ -184,19 +184,20 @@ export function unboundedFields(server: ServerAnalysis | undefined): Diagnostic[
|
|
|
184
184
|
const options = call.arguments[0]
|
|
185
185
|
const known = options === undefined || (options.type === 'ObjectExpression' && options.properties.every(property => property.type !== 'SpreadElement'))
|
|
186
186
|
|
|
187
|
-
if (!known || (options?.type === 'ObjectExpression' && options.properties.some(property => property.type !== 'SpreadElement' && (propertyKey(property) === 'maxLength' || isBoundedByValue(property)))) || field === undefined || isSecret(field) || !isShortField(field))
|
|
187
|
+
if (!known || (options?.type === 'ObjectExpression' && options.properties.some(property => property.type !== 'SpreadElement' && (propertyKey(property) === 'maxLength' || propertyKey(property) === 'max' || isBoundedByValue(property)))) || field === undefined || isSecret(field) || !isShortField(field))
|
|
188
188
|
return
|
|
189
189
|
|
|
190
|
-
const
|
|
190
|
+
const lowercase = call.callee.type === 'MemberExpression' && call.callee.property.type === 'Identifier' && call.callee.property.name === 'string'
|
|
191
|
+
const edit = maxLengthEdit(call, options, lowercase ? 'max' : 'maxLength')
|
|
191
192
|
const at = fence.offset + edit.at
|
|
192
193
|
|
|
193
194
|
diagnostics.push({
|
|
194
195
|
...fence.shift(call.callee),
|
|
195
196
|
code: 'unbounded-string',
|
|
196
|
-
message: `The string field ${field} has no maxLength of its own`,
|
|
197
|
+
message: `The string field ${field} has no ${lowercase ? 'max' : 'maxLength'} of its own`,
|
|
197
198
|
note: 'it takes the default bound of 10,000 characters, which is a lot for a value of its kind',
|
|
198
199
|
help: 'give it a tighter one',
|
|
199
|
-
fixes: [{ title: `Give it a maxLength of ${SUGGESTED_MAX_LENGTH}`, edits: [{ start: at, end: at, text: edit.text }] }],
|
|
200
|
+
fixes: [{ title: `Give it a ${lowercase ? 'max' : 'maxLength'} of ${SUGGESTED_MAX_LENGTH}`, edits: [{ start: at, end: at, text: edit.text }] }],
|
|
200
201
|
checkOnly: true,
|
|
201
202
|
})
|
|
202
203
|
})
|
|
@@ -336,14 +337,14 @@ export function cssImportsWithoutText(fence: ParsedFence): Diagnostic[] {
|
|
|
336
337
|
})
|
|
337
338
|
}
|
|
338
339
|
|
|
339
|
-
// Every `s.String(...)` call in a schema, with the name of the field it types, the nearest property holding it.
|
|
340
|
+
// Every `s.string(...)` (or old `s.String(...)`) call in a schema, with the name of the field it types, the nearest property holding it.
|
|
340
341
|
function schemaStrings(node: Node | null | undefined, field: string | undefined, found: (call: NodeOfType<'CallExpression'>, field: string | undefined) => void): void {
|
|
341
342
|
const optional = optionalParts()
|
|
342
343
|
|
|
343
344
|
eachNode(node, (inner, parent) => {
|
|
344
345
|
if (isPlainProperty(inner))
|
|
345
346
|
schemaStrings(inner.value, propertyKey(inner) ?? field, found)
|
|
346
|
-
else if (!optional(inner, parent) && inner.type === 'CallExpression' && inner.callee.type === 'MemberExpression' && inner.callee.property.type === 'Identifier' && inner.callee.property.name === 'String')
|
|
347
|
+
else if (!optional(inner, parent) && inner.type === 'CallExpression' && inner.callee.type === 'MemberExpression' && inner.callee.property.type === 'Identifier' && (inner.callee.property.name === 'String' || inner.callee.property.name === 'string'))
|
|
347
348
|
found(inner, field)
|
|
348
349
|
|
|
349
350
|
// A property's value is walked above, under the property's own name.
|
|
@@ -5,9 +5,9 @@ import { helperName } from './markup'
|
|
|
5
5
|
|
|
6
6
|
// The call giving a field the ids and requirement a component around it hands it, beside its own `own` ids.
|
|
7
7
|
// A field written with its own `aria-required` or `required`, or of a type whose role takes none, is left as it is whatever a component around it asks; an expression for either is read a second time, as the type's is, and counts once it gives a value.
|
|
8
|
-
export function addFieldDescribed(b: CodeBuilder, own: (() => void) | undefined, type: PlannedAttribute | undefined, aria: FieldAria | undefined, refusing?: () => void): void {
|
|
8
|
+
export function addFieldDescribed(b: CodeBuilder, own: (() => void) | undefined, type: PlannedAttribute | undefined, aria: FieldAria | undefined, refusing?: () => void, schemaType?: () => void): void {
|
|
9
9
|
const expression = (attribute: PlannedAttribute | undefined) => attribute?.kind === 'value' ? () => b.add('(').addSource(attribute.expression).add(')') : undefined
|
|
10
|
-
const typed = type?.kind === 'text' ? () => b.add(JSON.stringify(type.text)) : expression(type)
|
|
10
|
+
const typed = type?.kind === 'text' ? () => b.add(JSON.stringify(type.text)) : expression(type) ?? schemaType
|
|
11
11
|
const written = expression(aria?.required) ?? (aria?.required || aria?.unrequirable ? () => b.add('true') : undefined)
|
|
12
12
|
const native = expression(aria?.native) ?? (aria?.native ? () => b.add('true') : undefined)
|
|
13
13
|
// A field the template marks itself while its form refuses it, `refusing` writing the arguments of that check, counts as written then.
|
|
@@ -2,7 +2,7 @@ import type { AwaitAlert } from './names'
|
|
|
2
2
|
import { helperName } from './markup'
|
|
3
3
|
|
|
4
4
|
// The `kay/html` helpers static server output calls, each imported under a `Kay` name.
|
|
5
|
-
const HTML_HELPERS = ['attempt', 'attribute', 'checkedMarkup', 'child', 'className', 'component', 'componentClass', 'currentPage', 'dynamic', 'element', 'errorParagraph', 'fieldDescribed', 'formConstraints', 'formKey', 'head', 'html', 'imageAttributes', 'innerMarkup', 'leadingNewline', 'linkHref', 'localHref', 'loop', 'memo', 'merge', 'nonEmptyAttribute', 'omit', 'outsideLink', 'partClass', 'partHanded', 'partsClass', 'raw', 'rawData', 'rawTyped', 'refillOptions', 'selectOptions', 'serverIsland', 'show', 'spreadAttributes', 'spreadWith', 'style', 'untrack']
|
|
5
|
+
const HTML_HELPERS = ['attempt', 'attribute', 'checkedMarkup', 'child', 'className', 'component', 'componentClass', 'currentPage', 'dynamic', 'element', 'errorParagraph', 'fieldDescribed', 'formConstraints', 'formKey', 'formOptions', 'formType', 'head', 'html', 'imageAttributes', 'innerMarkup', 'leadingNewline', 'linkHref', 'localHref', 'loop', 'memo', 'merge', 'nonEmptyAttribute', 'omit', 'outsideLink', 'partClass', 'partHanded', 'partsClass', 'raw', 'rawData', 'rawTyped', 'refillOptions', 'schemaFill', 'selectOptions', 'serverIsland', 'show', 'spreadAttributes', 'spreadWith', 'style', 'untrack']
|
|
6
6
|
|
|
7
7
|
// The `kay/dom` helpers browser output calls, each imported under a `Kay` name.
|
|
8
8
|
const DOM_HELPERS = ['append', 'attribute', 'branches', 'checkedMarkup', 'choose', 'close', 'component', 'componentClass', 'effect', 'errorParagraph', 'fragment', 'holdSubmits', 'insert', 'listen', 'listenSubmit', 'listenSubmitWith', 'listenWith', 'markers', 'memo', 'merge', 'omit', 'outside', 'part', 'partClass', 'partHanded', 'partsClass', 'property', 'ref', 'setClass', 'setStyle', 'spreadAttributes', 'spreadWith', 'template', 'text', 'transition', 'untrack']
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ElementNode, FormField, Node, Span } from './ast'
|
|
2
|
+
import type { Markup } from './html-parts'
|
|
3
|
+
import type { CodeBuilder } from './mapping'
|
|
4
|
+
import type { ElementPlan } from './markup'
|
|
5
|
+
import { addFilled } from './html-initial'
|
|
6
|
+
import { escapeStaticAttribute, helperName } from './markup'
|
|
7
|
+
|
|
8
|
+
// The `class` of an element: written as it is when static, else built as it renders.
|
|
9
|
+
export function addClassAttribute(b: CodeBuilder, markup: Markup, classes: ElementPlan['classes'], classList: (classes: NonNullable<ElementPlan['classes']>) => void): void {
|
|
10
|
+
if (classes?.parts) {
|
|
11
|
+
const parts = classes
|
|
12
|
+
|
|
13
|
+
markup.dynamic(() => {
|
|
14
|
+
b.add(`${helperName('nonEmptyAttribute')}("class", ${helperName('className')}(`)
|
|
15
|
+
classList(parts)
|
|
16
|
+
b.add('))')
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
else if (classes?.expression) {
|
|
20
|
+
const { text, expression } = classes
|
|
21
|
+
|
|
22
|
+
markup.text(' class="')
|
|
23
|
+
markup.dynamic(() => b.add(`${helperName('className')}([${JSON.stringify(text)}, (`).addSource(expression).add(')])'))
|
|
24
|
+
markup.text('"')
|
|
25
|
+
}
|
|
26
|
+
else if (classes?.pieces) {
|
|
27
|
+
const { pieces } = classes
|
|
28
|
+
|
|
29
|
+
markup.text(' class="')
|
|
30
|
+
markup.dynamic(() => b.add(`${helperName('className')}(${JSON.stringify(pieces)})`))
|
|
31
|
+
markup.text('"')
|
|
32
|
+
}
|
|
33
|
+
else if (classes) {
|
|
34
|
+
markup.text(` class="${escapeStaticAttribute(classes.text)}"`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Fill {
|
|
39
|
+
filled: 'value' | 'checked'
|
|
40
|
+
fieldArguments: () => void
|
|
41
|
+
own: (() => void) | undefined
|
|
42
|
+
box: (() => void) | undefined
|
|
43
|
+
values: Span | undefined
|
|
44
|
+
name: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// A field's `value`, or `checked` for a boolean. An input that writes no `type` takes the one its schema gives it, so which of the two it is is only known as it renders.
|
|
48
|
+
export function addFieldFill(b: CodeBuilder, src: string, element: ElementNode, markup: Markup, fill: Fill, field: FormField, typed: boolean): void {
|
|
49
|
+
const one = (filled: 'value' | 'checked', box = fill.box, schemaType = true) => addFilled(b, src, element, { ...fill, filled, box, own: filled === fill.filled ? fill.own : undefined, schemaType })
|
|
50
|
+
|
|
51
|
+
if (!(typed && field.marked && fill.filled === 'value')) {
|
|
52
|
+
markup.dynamic(() => one(fill.filled, fill.box, false))
|
|
53
|
+
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
markup.dynamic(() => {
|
|
58
|
+
b.add(helperName('schemaFill'))
|
|
59
|
+
fill.fieldArguments()
|
|
60
|
+
b.add(', (KaySchemaType) => ')
|
|
61
|
+
one('value')
|
|
62
|
+
b.add(', () => ')
|
|
63
|
+
one('checked', fill.own)
|
|
64
|
+
|
|
65
|
+
// The `value` a box posts when ticked, which the template wrote.
|
|
66
|
+
if (fill.own) {
|
|
67
|
+
b.add(` + ${helperName('attribute')}("value", `)
|
|
68
|
+
fill.own()
|
|
69
|
+
b.add(')')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
b.add(')')
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// The call reading the `type` the schema gives an input that writes none, for a component requiring the field to know what it is.
|
|
77
|
+
export function schemaTypeCall(b: CodeBuilder, element: string, type: unknown, field: FormField | undefined, target: Span | undefined): (() => void) | undefined {
|
|
78
|
+
if (element !== 'input' || type !== undefined || !field?.marked || !target)
|
|
79
|
+
return undefined
|
|
80
|
+
|
|
81
|
+
return () => void b.add(`${helperName('formType')}((`).addSource(target).add(`), ${JSON.stringify(field.name)})`)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Whether a `select(field=...)` writes no options, which its schema's enum gives it.
|
|
85
|
+
export function listsFromSchema(element: string, children: Node[], field: FormField | undefined): boolean {
|
|
86
|
+
return element === 'select' && children.length === 0 && field?.marked === true
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The options of such a `select`, written as the helper that reads them off the schema of the action.
|
|
90
|
+
export function addSchemaOptions(b: CodeBuilder, target: Span, name: string): void {
|
|
91
|
+
b.add(`${helperName('formOptions')}((`).addSource(target).add(`), ${JSON.stringify(name)})`)
|
|
92
|
+
}
|
|
@@ -18,7 +18,7 @@ export function dateTypeOf(element: ElementNode, src: string): string | undefine
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// What the record a form fills its fields from holds for a field, after the `separator` that makes it the last fallback: its text, or whether the box a `value` stands for is ticked. Writes nothing for a form with no record.
|
|
21
|
-
export function addInitial(b: CodeBuilder, src: string, element: ElementNode, values: Span | undefined, name: string, box?: InitialBox, separator = ' ?? '): void {
|
|
21
|
+
export function addInitial(b: CodeBuilder, src: string, element: ElementNode, values: Span | undefined, name: string, box?: InitialBox, separator = ' ?? ', typeVariable?: string): void {
|
|
22
22
|
if (!values)
|
|
23
23
|
return
|
|
24
24
|
|
|
@@ -33,13 +33,15 @@ export function addInitial(b: CodeBuilder, src: string, element: ElementNode, va
|
|
|
33
33
|
|
|
34
34
|
if (type !== undefined)
|
|
35
35
|
b.add(`, ${JSON.stringify(type)}`)
|
|
36
|
+
else if (typeVariable !== undefined)
|
|
37
|
+
b.add(`, ${typeVariable}`)
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
b.add(')')
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
// What a field with a `value` or a `checked` is written as on the server: a refused post's, else the template's own, else the record's.
|
|
42
|
-
export function addFilled(b: CodeBuilder, src: string, element: ElementNode, { filled, fieldArguments, own, box, values, name }: { filled: 'value' | 'checked', fieldArguments: () => void, own: (() => void) | undefined, box: (() => void) | undefined, values: Span | undefined, name: string }): void {
|
|
44
|
+
export function addFilled(b: CodeBuilder, src: string, element: ElementNode, { filled, fieldArguments, own, box, values, name, schemaType }: { filled: 'value' | 'checked', fieldArguments: () => void, own: (() => void) | undefined, box: (() => void) | undefined, values: Span | undefined, name: string, schemaType?: boolean }): void {
|
|
43
45
|
b.add(`${helperName('attribute')}(${JSON.stringify(filled)}, ${filled === 'value' ? 'KayFormValue' : 'KayFormChecked'}`)
|
|
44
46
|
fieldArguments()
|
|
45
47
|
|
|
@@ -56,7 +58,7 @@ export function addFilled(b: CodeBuilder, src: string, element: ElementNode, { f
|
|
|
56
58
|
own()
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
addInitial(b, src, element, values, name, filled === 'checked' ? { value: box } : undefined)
|
|
61
|
+
addInitial(b, src, element, values, name, filled === 'checked' ? { value: box } : undefined, ' ?? ', schemaType ? 'KaySchemaType' : undefined)
|
|
60
62
|
b.add(')')
|
|
61
63
|
}
|
|
62
64
|
|