@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
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type { CheckDiagnostic, CheckOptions } from '.'
|
|
2
|
+
import type { Node } from '../compiler/estree'
|
|
3
|
+
import type { Edit } from './renamed-exports'
|
|
4
|
+
import { lintLevel } from '../compiler/lints'
|
|
5
|
+
import { importsOf, walk } from './ast'
|
|
6
|
+
import { scan } from './renamed-exports'
|
|
7
|
+
|
|
8
|
+
// Each PascalCase builder with the lowercase one that replaces it, the position of its options and the option names that changed.
|
|
9
|
+
const BUILDERS: Record<string, { name: string, options: number, keys?: Record<string, string> }> = {
|
|
10
|
+
String: { name: 'string', options: 0, keys: { minLength: 'min', maxLength: 'max' } },
|
|
11
|
+
Secret: { name: 'secret', options: 0, keys: { minLength: 'min', maxLength: 'max' } },
|
|
12
|
+
Number: { name: 'number', options: 0, keys: { minimum: 'min', maximum: 'max' } },
|
|
13
|
+
Numeric: { name: 'number', options: 0, keys: { minimum: 'min', maximum: 'max' } },
|
|
14
|
+
Integer: { name: 'int', options: 0, keys: { minimum: 'min', maximum: 'max' } },
|
|
15
|
+
Boolean: { name: 'boolean', options: 0 },
|
|
16
|
+
BooleanString: { name: 'boolean', options: 0 },
|
|
17
|
+
Date: { name: 'date', options: 0 },
|
|
18
|
+
File: { name: 'file', options: 0 },
|
|
19
|
+
Files: { name: 'files', options: 0, keys: { minItems: 'min', maxItems: 'max' } },
|
|
20
|
+
Literal: { name: 'literal', options: 1 },
|
|
21
|
+
Union: { name: 'union', options: 1 },
|
|
22
|
+
Array: { name: 'list', options: 1, keys: { minItems: 'min', maxItems: 'max' } },
|
|
23
|
+
Object: { name: 'object', options: 1 },
|
|
24
|
+
UnionEnum: { name: 'enum', options: 1 },
|
|
25
|
+
UnionKeys: { name: 'enum', options: 1 },
|
|
26
|
+
Public: { name: 'public', options: 1 },
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const FILES = new Set(['File', 'Files', 'file', 'files'])
|
|
30
|
+
const OLD_SIZE = /^\d+(?:\.\d+)?[kmg]$/i
|
|
31
|
+
const KAY = /^kay(?:\/|$)/
|
|
32
|
+
const NEEDLE = /\.(?:String|Secret|Number|Numeric|Integer|Boolean|BooleanString|Date|File|Files|Literal|Union|Array|Object|UnionEnum|UnionKeys|Public|Optional)\(|\.(?:file|files)\(/
|
|
33
|
+
|
|
34
|
+
interface Call {
|
|
35
|
+
node: Node & { type: 'CallExpression' }
|
|
36
|
+
name: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function builderCall(node: Node, receivers: Set<string>): Call | undefined {
|
|
40
|
+
if (node.type !== 'CallExpression' || node.callee.type !== 'MemberExpression' || node.callee.computed || node.callee.object.type !== 'Identifier' || node.callee.property.type !== 'Identifier')
|
|
41
|
+
return undefined
|
|
42
|
+
|
|
43
|
+
return receivers.has(node.callee.object.name) ? { node, name: node.callee.property.name } : undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function keyName(property: Node): string | undefined {
|
|
47
|
+
if (property.type !== 'Property' || property.computed)
|
|
48
|
+
return undefined
|
|
49
|
+
|
|
50
|
+
if (property.key.type === 'Identifier')
|
|
51
|
+
return property.key.name
|
|
52
|
+
|
|
53
|
+
return property.key.type === 'Literal' && typeof property.key.value === 'string' ? property.key.value : undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function renamedOption(name: string, keys: Record<string, string> | undefined): string | undefined {
|
|
57
|
+
return name === 'title' ? 'label' : keys?.[name]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The edits renaming a builder and the options it was given under old names: `s.String({ minLength: 3 })` is `s.string({ min: 3 })`.
|
|
61
|
+
function renames(call: Call, base: number): Edit[] {
|
|
62
|
+
const builder = BUILDERS[call.name]!
|
|
63
|
+
const { property } = call.node.callee as { property: Node }
|
|
64
|
+
const edits: Edit[] = [{ start: base + property.start, end: base + property.end, text: builder.name }]
|
|
65
|
+
const options = call.node.arguments[builder.options]
|
|
66
|
+
|
|
67
|
+
if (options?.type === 'ObjectExpression') {
|
|
68
|
+
for (const entry of options.properties) {
|
|
69
|
+
const name = keyName(entry)
|
|
70
|
+
const renamed = name === undefined ? undefined : renamedOption(name, builder.keys)
|
|
71
|
+
|
|
72
|
+
if (renamed === undefined || entry.type !== 'Property')
|
|
73
|
+
continue
|
|
74
|
+
|
|
75
|
+
edits.push({ start: base + entry.key.start, end: base + entry.key.end, text: entry.shorthand ? `${renamed}: ${name}` : renamed })
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return edits
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Where `optional: true` goes in a builder's call: into its options object, or after its last argument. Undefined for options that are not an object literal, which the fix leaves to the app.
|
|
83
|
+
function optionalEdit(call: Call, base: number): Edit | undefined {
|
|
84
|
+
const index = BUILDERS[call.name]!.options
|
|
85
|
+
const options = call.node.arguments[index]
|
|
86
|
+
|
|
87
|
+
if (options === undefined) {
|
|
88
|
+
if (call.node.arguments.length < index)
|
|
89
|
+
return undefined
|
|
90
|
+
|
|
91
|
+
const close = base + call.node.end - 1
|
|
92
|
+
|
|
93
|
+
return { start: close, end: close, text: call.node.arguments.length === 0 ? '{ optional: true }' : ', { optional: true }' }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (options.type !== 'ObjectExpression')
|
|
97
|
+
return undefined
|
|
98
|
+
|
|
99
|
+
const open = base + options.start
|
|
100
|
+
|
|
101
|
+
return { start: open, end: open + 1, text: options.properties.length === 0 ? '{ optional: true ' : '{ optional: true,' }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
type Program = Parameters<typeof importsOf>[0]
|
|
105
|
+
type Report = (start: number, end: number, message: string, help: string, edits: Edit[] | null) => void
|
|
106
|
+
|
|
107
|
+
// The `s` an app imported and no longer reads once a fix has taken `dropped` of its uses away: its import goes too, or the file would fail its own unused-name check.
|
|
108
|
+
function dropUnreadImport(ast: Program, receivers: Set<string>, dropped: number, span: { base: number, text: string }, report: Report): void {
|
|
109
|
+
for (const statement of ast.body) {
|
|
110
|
+
if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type' || !KAY.test(statement.source.value))
|
|
111
|
+
continue
|
|
112
|
+
|
|
113
|
+
const index = statement.specifiers.findIndex(specifier => specifier.type === 'ImportSpecifier' && specifier.importKind !== 'type' && (specifier.imported as { name?: string }).name === 's' && receivers.has(specifier.local.name))
|
|
114
|
+
|
|
115
|
+
if (index < 0)
|
|
116
|
+
continue
|
|
117
|
+
|
|
118
|
+
const specifier = statement.specifiers[index]!
|
|
119
|
+
let references = 0
|
|
120
|
+
|
|
121
|
+
walk(ast, (node) => {
|
|
122
|
+
if (node.type === 'Identifier' && receivers.has(node.name) && (node.start < specifier.start || node.end > specifier.end))
|
|
123
|
+
references++
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (references > dropped)
|
|
127
|
+
return
|
|
128
|
+
|
|
129
|
+
const only = statement.specifiers.length === 1
|
|
130
|
+
const next = statement.specifiers[index + 1]
|
|
131
|
+
const previous = statement.specifiers[index - 1]
|
|
132
|
+
const lineEnd = span.text[statement.end] === '\n' ? statement.end + 1 : statement.end
|
|
133
|
+
// The whole line when it is the only name, else the name and the comma beside it.
|
|
134
|
+
let [from, to] = [previous?.end ?? specifier.start, specifier.end]
|
|
135
|
+
|
|
136
|
+
if (only)
|
|
137
|
+
[from, to] = [statement.start, lineEnd]
|
|
138
|
+
else if (next)
|
|
139
|
+
[from, to] = [specifier.start, next.start]
|
|
140
|
+
|
|
141
|
+
const edit = { start: span.base + from, end: span.base + to, text: '' }
|
|
142
|
+
|
|
143
|
+
report(span.base + specifier.start, span.base + specifier.end, '`s` is no longer read once its builders are written as a record, so its import goes', 'drop the import of `s`', [edit])
|
|
144
|
+
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The PascalCase builders of `s`, which kay 1.106 replaces with its own lowercase ones, and the `'2m'` sizes of a file field, which are `'2mb'` as every size is.
|
|
150
|
+
// Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. `s.Optional(x)` of one of these builders is `optional: true` in its options; an `s.Object({ ... })` that is the schema of an `action` or a `defineEnv` is the record alone.
|
|
151
|
+
export async function schemaBuilders(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
152
|
+
if (lintLevel('deprecated-schema-builders', options.lints) === 'allow')
|
|
153
|
+
return []
|
|
154
|
+
|
|
155
|
+
return scan(root, options, 'deprecated-schema-builders', NEEDLE, ({ parsed, report }) => {
|
|
156
|
+
for (const { ast, base, text } of parsed) {
|
|
157
|
+
const receivers = importsOf(ast, source => KAY.test(source), 's').locals
|
|
158
|
+
const records = new Set([...importsOf(ast, source => KAY.test(source), 'action').locals, ...importsOf(ast, source => KAY.test(source), 'defineEnv').locals])
|
|
159
|
+
|
|
160
|
+
if (receivers.size === 0)
|
|
161
|
+
continue
|
|
162
|
+
|
|
163
|
+
// What an `s.Optional(...)` or a record has taken over, so the call inside is not reported on its own.
|
|
164
|
+
const taken = new Set<Node>()
|
|
165
|
+
// The uses of `s` a fix takes away: an `s.Optional(` and the `s.Object(` of a record.
|
|
166
|
+
let dropped = 0
|
|
167
|
+
|
|
168
|
+
walk(ast, (node) => {
|
|
169
|
+
const call = builderCall(node, receivers)
|
|
170
|
+
|
|
171
|
+
if (call === undefined) {
|
|
172
|
+
// `action(s.Object({ ... }), ...)`
|
|
173
|
+
if (node.type === 'CallExpression' && node.callee.type === 'Identifier' && records.has(node.callee.name)) {
|
|
174
|
+
const [schema] = node.arguments
|
|
175
|
+
const inner = schema === undefined ? undefined : builderCall(schema, receivers)
|
|
176
|
+
|
|
177
|
+
if (schema && inner?.name === 'Object' && inner.node.arguments.length === 1 && inner.node.arguments[0]!.type === 'ObjectExpression') {
|
|
178
|
+
const shape = inner.node.arguments[0]
|
|
179
|
+
|
|
180
|
+
taken.add(schema)
|
|
181
|
+
dropped++
|
|
182
|
+
report(base + schema.start, base + schema.end, 'a plain record of fields is the object schema of an action or a defineEnv since 1.106, `s.Object` being the PascalCase builder it replaces; the old form works until 2.0', 'write the record of fields', [{ start: base + schema.start, end: base + shape.start, text: '' }, { start: base + shape.end, end: base + schema.end, text: '' }])
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (call.name === 'Optional') {
|
|
190
|
+
const [inner, ...others] = call.node.arguments
|
|
191
|
+
const wrapped = inner === undefined ? undefined : builderCall(inner, receivers)
|
|
192
|
+
const known = wrapped && wrapped.name !== 'Public' && BUILDERS[wrapped.name] && !taken.has(inner!)
|
|
193
|
+
const edit = known ? optionalEdit(wrapped, base) : undefined
|
|
194
|
+
|
|
195
|
+
// Anything but a builder of `s`, such as the `imageField()` of kay/content, has no `optional` option to write yet.
|
|
196
|
+
if (!known)
|
|
197
|
+
return
|
|
198
|
+
|
|
199
|
+
if (others.length > 0 || !edit) {
|
|
200
|
+
report(base + node.start, base + node.end, '`s.Optional(field)` is `optional: true` in the options of the field since 1.106, the same option on every builder; the old form works until 2.0', 'write `optional: true` in the field\'s options', null)
|
|
201
|
+
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
taken.add(inner!)
|
|
206
|
+
dropped++
|
|
207
|
+
report(base + node.start, base + node.end, '`s.Optional(field)` is `optional: true` in the options of the field since 1.106, the same option on every builder; the old form works until 2.0', 'write `optional: true` in the field\'s options', [
|
|
208
|
+
{ start: base + node.start, end: base + inner!.start, text: '' },
|
|
209
|
+
...renames(wrapped, base),
|
|
210
|
+
edit,
|
|
211
|
+
{ start: base + node.end - 1, end: base + node.end, text: '' },
|
|
212
|
+
])
|
|
213
|
+
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const builder = BUILDERS[call.name]
|
|
218
|
+
|
|
219
|
+
if (builder && !taken.has(node)) {
|
|
220
|
+
const object = call.name === 'Object' ? 'unknown keys are refused by `s.object` where kay reads the schema itself, where `s.Object` let them by; write `extra: \'strip\'` to keep the old way' : ''
|
|
221
|
+
const message = call.name === 'UnionKeys' || call.name === 'UnionEnum'
|
|
222
|
+
? '`s.enum()` takes the values, or a record whose keys are the values, since 1.106, in place of `s.UnionEnum` and `s.UnionKeys`; the old forms work until 2.0'
|
|
223
|
+
: `\`s.${call.name}\` is \`s.${builder.name}\` since 1.106, kay's own lowercase builders with short options (\`min\`, \`max\`, \`optional\`) replacing the PascalCase ones of TypeBox${object ? `; ${object}` : ''}; the old form works until 2.0`
|
|
224
|
+
|
|
225
|
+
report(base + node.start, base + node.end, message, `write \`s.${builder.name}\``, renames(call, base))
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
walk(ast, (node) => {
|
|
230
|
+
const call = builderCall(node, receivers)
|
|
231
|
+
|
|
232
|
+
if (call === undefined || !FILES.has(call.name))
|
|
233
|
+
return
|
|
234
|
+
|
|
235
|
+
const options = call.node.arguments[0]
|
|
236
|
+
|
|
237
|
+
if (options?.type !== 'ObjectExpression')
|
|
238
|
+
return
|
|
239
|
+
|
|
240
|
+
for (const entry of options.properties) {
|
|
241
|
+
const name = keyName(entry)
|
|
242
|
+
|
|
243
|
+
if ((name !== 'maxSize' && name !== 'minSize') || entry.type !== 'Property' || entry.value.type !== 'Literal' || typeof entry.value.value !== 'string' || !OLD_SIZE.test(entry.value.value))
|
|
244
|
+
continue
|
|
245
|
+
|
|
246
|
+
const end = base + entry.value.end - 1
|
|
247
|
+
|
|
248
|
+
report(base + entry.value.start, base + entry.value.end, `a size is written \`'${entry.value.value}b'\`, with its unit, as every size of kay is`, 'write the size with its `b`', [{ start: end, end, text: 'b' }])
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
if (dropped > 0)
|
|
253
|
+
dropUnreadImport(ast, receivers, dropped, { base, text }, report)
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
}
|
package/src/check/secret-keys.ts
CHANGED
|
@@ -3,13 +3,14 @@ import type { Property } from './regroup'
|
|
|
3
3
|
import type { Edit } from './renamed-exports'
|
|
4
4
|
import { lintLevel } from '../compiler/lints'
|
|
5
5
|
import { configObjects, propertiesOf } from './config-objects'
|
|
6
|
+
import { regrouped } from './regroup'
|
|
6
7
|
import { scan } from './renamed-exports'
|
|
7
8
|
|
|
8
9
|
const NEEDLE = /\b(?:key|mcpKey|proxyKey)\b/
|
|
9
10
|
const TEST_KEYS = { mcpKey: 'mcp: { token }', proxyKey: 'proxy: { key: { header, secret } }' }
|
|
10
11
|
|
|
11
12
|
// The `key` of `mcp`, which is `token` since 1.105, and the string `key` of `proxy`, which names its header as `{ header }`, in the config; and the `mcpKey` and `proxyKey` options of `testSite()`, which are `config: { mcp: { token } }` and `config: { proxy: { key: { header, secret } } }`.
|
|
12
|
-
// The fix renames `mcp.key`, except for `false`, which has no token, and wraps the header of `proxy.key`, where the object is written in place; the options of `testSite()`
|
|
13
|
+
// The fix renames `mcp.key`, except for `false`, which has no token, and wraps the header of `proxy.key`, where the object is written in place; the options of `testSite()` move into a `config`, `proxyKey` only where the app's config names the header it travels in, and a `config` already written is left as it is.
|
|
13
14
|
export async function secretKeys(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
14
15
|
if (lintLevel('deprecated-secret-keys', options.lints) === 'allow')
|
|
15
16
|
return []
|
|
@@ -18,9 +19,13 @@ export async function secretKeys(root: string, options: CheckOptions): Promise<C
|
|
|
18
19
|
for (const { ast, base, text } of parsed) {
|
|
19
20
|
for (const { object, call } of configObjects(file, ast)) {
|
|
20
21
|
if (call === 'testSite') {
|
|
22
|
+
const header = options.proxyHeader
|
|
23
|
+
const shaped = (name: string, value: string) => name === 'mcpKey' ? `{ token: ${value} }` : `{ key: { header: '${header}', secret: ${value} } }`
|
|
24
|
+
const moves = regrouped(object, text, name => testGroup(name, header), false, shaped)
|
|
25
|
+
|
|
21
26
|
for (const [name, written] of Object.entries(TEST_KEYS)) {
|
|
22
27
|
for (const property of propertiesOf(object, name))
|
|
23
|
-
report(base + property.start, base + property.end, `\`${name}\` of \`testSite()\` is \`${written}\` in \`config\` since 1.105`, `write \`config: { ${written} }\``, null)
|
|
28
|
+
report(base + property.start, base + property.end, `\`${name}\` of \`testSite()\` is \`${written}\` in \`config\` since 1.105`, `write \`config: { ${written} }\``, name === 'mcpKey' || header !== undefined ? moves ?? null : null)
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
|
|
@@ -55,6 +60,14 @@ export async function secretKeys(root: string, options: CheckOptions): Promise<C
|
|
|
55
60
|
})
|
|
56
61
|
}
|
|
57
62
|
|
|
63
|
+
// Where a `testSite()` option moves to in its `config`, `proxyKey` only once the header it travels in is known.
|
|
64
|
+
function testGroup(name: string, header: string | undefined): [string, string] | undefined {
|
|
65
|
+
if (name === 'mcpKey')
|
|
66
|
+
return ['config', 'mcp']
|
|
67
|
+
|
|
68
|
+
return name === 'proxyKey' && header !== undefined ? ['config', 'proxy'] : undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
58
71
|
function fixOf(group: 'mcp' | 'proxy', property: Property, text: string, base: number, spread: boolean, off: boolean, taken: boolean): Edit[] | null {
|
|
59
72
|
if (spread || property.kind !== 'init' || property.method)
|
|
60
73
|
return null
|
|
@@ -80,6 +80,7 @@ import { removedUiTokens } from './removed-ui-tokens'
|
|
|
80
80
|
import { retiredLintLevels } from './retired-lints'
|
|
81
81
|
import { routeKeys } from './route-keys'
|
|
82
82
|
import { routeShadow, routeShadowPath } from './route-shadow'
|
|
83
|
+
import { schemaBuilders } from './schema-builders'
|
|
83
84
|
import { schemaType } from './schema-type'
|
|
84
85
|
import { secretKeys } from './secret-keys'
|
|
85
86
|
import { compileShadow, guardTypes, layoutQueries, matcherSource, outerSlots, pageRoute, serializeShadowSettings, SHADOW_SETTINGS, shadowOptionsFor, shadowPath } from './shadow'
|
|
@@ -208,6 +209,7 @@ const PROJECT_CHECKS: ((input: ProjectCheckInput) => CheckDiagnostic[] | Promise
|
|
|
208
209
|
async ({ root, options }) => movedImports(root, options),
|
|
209
210
|
|
|
210
211
|
async ({ root, options }) => schemaType(root, options),
|
|
212
|
+
async ({ root, options }) => schemaBuilders(root, options),
|
|
211
213
|
async ({ root, options }) => aiLanguage(root, options),
|
|
212
214
|
async ({ root, options }) => hookNames(root, options),
|
|
213
215
|
async ({ root, options }) => mailApi(root, options),
|
|
@@ -178,7 +178,7 @@ function attributeList(source: string, span: Span): Span {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
// `name={...}` or `name="..."` inside the attributes, as the span of the whole attribute.
|
|
181
|
-
function attributeNamed(source: string, list: Span, name: string): Span | undefined {
|
|
181
|
+
export function attributeNamed(source: string, list: Span, name: string): Span | undefined {
|
|
182
182
|
let start = source.indexOf(`${name}=`, list.start)
|
|
183
183
|
|
|
184
184
|
while (start !== -1 && start < list.end && NAME_CHAR.test(source[start - 1] ?? ' '))
|
package/src/check/tool-labels.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { snakeCase } from '../server/snake-case'
|
|
|
11
11
|
const SOURCE_FILE = /\.(?:kay|[cm]?ts|tsx)$/
|
|
12
12
|
const DECLARATION_FILE = /\.d\.[cm]?ts$/
|
|
13
13
|
const EXPORTED = /\bexport\s+(?:const|let|var|function|async\s+function)\s+([A-Za-z_$][\w$]*)/g
|
|
14
|
+
// The props of a Chat keyed by tool name.
|
|
15
|
+
const PROPS = new Set(['toolLabels', 'toolIcons'])
|
|
14
16
|
const QUOTED = /(['"`])([A-Z][\w-]*)\1/gi
|
|
15
17
|
// A name a second tool of the same name got: `add_note_2`.
|
|
16
18
|
const NUMBERED = /^(.+)_\d+$/
|
|
@@ -18,13 +20,13 @@ const NUMBERED = /^(.+)_\d+$/
|
|
|
18
20
|
interface Labelled {
|
|
19
21
|
file: string
|
|
20
22
|
source: string
|
|
21
|
-
keys: { name: string, at: number, end: number }[]
|
|
22
|
-
// The source with the keys of the `toolLabels` blanked, which is where tool names are searched, so a key never vouches for itself.
|
|
23
|
+
keys: { prop: string, name: string, at: number, end: number }[]
|
|
24
|
+
// The source with the keys of the `toolLabels` and `toolIcons` blanked, which is where tool names are searched, so a key never vouches for itself.
|
|
23
25
|
rest: string
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
// A key of a Chat's `toolLabels` that names no tool of the project: an action is a tool named by its export (`homeState` is `home_state`) or by its `tool.name`, and a function tool by its `name`, so a key matching none of them, nor any string the project writes, is a tool that was renamed or never was.
|
|
27
|
-
// Only a `toolLabels` written as an object literal is read, and only what the project's own modules write is searched.
|
|
28
|
+
// A key of a Chat's `toolLabels` or `toolIcons` that names no tool of the project: an action is a tool named by its export (`homeState` is `home_state`) or by its `tool.name`, and a function tool by its `name`, so a key matching none of them, nor any string the project writes, is a tool that was renamed or never was.
|
|
29
|
+
// Only a `toolLabels` or `toolIcons` written as an object literal is read, and only what the project's own modules write is searched.
|
|
28
30
|
export async function unknownToolLabels(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
29
31
|
if (lintLevel('unknown-tool-label', options.lints) === 'allow')
|
|
30
32
|
return []
|
|
@@ -32,12 +34,12 @@ export async function unknownToolLabels(root: string, options: CheckOptions): Pr
|
|
|
32
34
|
const files = (await findProjectFiles(root, SOURCE_FILE, { project: true, ownKayOnly: true })).filter(file => !DECLARATION_FILE.test(file))
|
|
33
35
|
const read = async (paths: string[]) => Promise.all(paths.map(async file => ({ file, source: await Bun.file(file).text() })))
|
|
34
36
|
const written = await read(files.filter(file => file.endsWith('.kay')))
|
|
35
|
-
const labelled = written.flatMap(({ file, source }) => source.includes('toolLabels') ? labelsIn(file, source) : [])
|
|
37
|
+
const labelled = written.flatMap(({ file, source }) => source.includes('toolLabels') || source.includes('toolIcons') ? labelsIn(file, source) : [])
|
|
36
38
|
|
|
37
39
|
if (labelled.length === 0)
|
|
38
40
|
return []
|
|
39
41
|
|
|
40
|
-
// The other modules are read once
|
|
42
|
+
// The other modules are read once one is found, as only they say which tools exist.
|
|
41
43
|
const texts = [...written, ...await read(files.filter(file => !file.endsWith('.kay')))]
|
|
42
44
|
const known = new Set<string>()
|
|
43
45
|
const labelledFiles = new Map(labelled.map(item => [item.file, item.rest]))
|
|
@@ -63,7 +65,7 @@ export async function unknownToolLabels(root: string, options: CheckOptions): Pr
|
|
|
63
65
|
if (level === 'allow' || known.has(key.name) || known.has(NUMBERED.exec(key.name)?.[1] ?? ''))
|
|
64
66
|
continue
|
|
65
67
|
|
|
66
|
-
found.push({ file, ...positionAt(source, key.at), end: key.end, message:
|
|
68
|
+
found.push({ file, ...positionAt(source, key.at), end: key.end, message: `\`${key.prop}\` names \`${key.name}\`, which no tool of this project is called`, help: 'name the tool as the model calls it: its export in snake case (`homeState` is `home_state`), its `tool.name` or the `name` of its `tool()`; or drop the key and give the action `tool: { label }`', code: 'unknown-tool-label', severity: level === 'warn' ? 'warning' : 'error' })
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -76,7 +78,7 @@ function labelsIn(file: string, source: string): Labelled[] {
|
|
|
76
78
|
|
|
77
79
|
for (const element of elementsIn(parseKay(source).template)) {
|
|
78
80
|
for (const attribute of element.attributes) {
|
|
79
|
-
if (attribute.kind !== 'expression' || source.slice(attribute.name.start, attribute.name.end)
|
|
81
|
+
if (attribute.kind !== 'expression' || !PROPS.has(source.slice(attribute.name.start, attribute.name.end)))
|
|
80
82
|
continue
|
|
81
83
|
|
|
82
84
|
const expression = parseObject(source.slice(attribute.expression.start, attribute.expression.end))
|
|
@@ -93,7 +95,7 @@ function labelsIn(file: string, source: string): Labelled[] {
|
|
|
93
95
|
const name = keyName(property.key)
|
|
94
96
|
|
|
95
97
|
if (name !== undefined)
|
|
96
|
-
keys.push({ name, at: attribute.expression.start + property.key.start, end: attribute.expression.start + property.key.end })
|
|
98
|
+
keys.push({ prop: source.slice(attribute.name.start, attribute.name.end), name, at: attribute.expression.start + property.key.start, end: attribute.expression.start + property.key.end })
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
}
|
package/src/check/ui-types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KayLibrary } from '../build/libraries'
|
|
2
2
|
import { realpathSync } from 'node:fs'
|
|
3
|
-
import { dirname, relative, sep } from 'node:path'
|
|
4
|
-
import { componentsNamed, forgetNames, uiOf } from '../build/ui'
|
|
3
|
+
import { dirname, join, relative, sep } from 'node:path'
|
|
4
|
+
import { componentsNamed, forgetNames, UI_FILE, uiLayerPathsOf, uiOf } from '../build/ui'
|
|
5
5
|
import { componentName } from '../compiler'
|
|
6
6
|
import { offered } from './ui'
|
|
7
7
|
|
|
@@ -29,7 +29,8 @@ function realOf(file: string): string {
|
|
|
29
29
|
|
|
30
30
|
// The `UiComponents` of `kay`, declared from the components `src/ui.ts` can restyle: each by the name a template calls it and by its specifier, with its part names and the values of its variants, so `defineUi` completes and checks an entry in the editor. An app with no `src/ui.ts` declares none.
|
|
31
31
|
export function uiTypes(root: string, libraries: KayLibrary[], own: string[]): string {
|
|
32
|
-
|
|
32
|
+
// An app with no `src/ui.ts` still takes the entries of its extensions' `ui` files, which a template's props are checked against.
|
|
33
|
+
const ui = uiOf(root) ?? (uiLayerPathsOf(root).length === 0 ? undefined : { file: join(root, UI_FILE), source: '', components: [], problems: [] })
|
|
33
34
|
|
|
34
35
|
if (ui === undefined)
|
|
35
36
|
return 'export {}\n'
|
package/src/check/ui.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { CheckDiagnostic } from '.'
|
|
|
2
2
|
import type { UiComponent, UiSource } from '../build/ui'
|
|
3
3
|
import type { Diagnostic, Span } from '../compiler/ast'
|
|
4
4
|
import { readFileSync, realpathSync } from 'node:fs'
|
|
5
|
-
import { basename,
|
|
6
|
-
import { componentFile, componentMatches, forgetNames, isComponentName, KAY_EXTENSION, uiOf } from '../build/ui'
|
|
5
|
+
import { basename, relative, sep } from 'node:path'
|
|
6
|
+
import { baseOf, componentFile, componentMatches, forgetNames, isComponentName, KAY_EXTENSION, uiLayersOf, uiOf } from '../build/ui'
|
|
7
7
|
import { ROUTE_FILES } from '../compiler'
|
|
8
8
|
import { templateFacts } from '../compiler/ast'
|
|
9
9
|
import { parseKay } from '../compiler/parser'
|
|
@@ -30,7 +30,7 @@ export function offered(file: string): { parts: Set<string>, variants: Record<st
|
|
|
30
30
|
|
|
31
31
|
// The specifier `src/ui.ts` writes a component by: a path from it for the app's own, the package's for a library's.
|
|
32
32
|
function specifierOf(ui: UiSource, file: string): string {
|
|
33
|
-
const from = realpathSync(
|
|
33
|
+
const from = realpathSync(baseOf(ui))
|
|
34
34
|
|
|
35
35
|
return file.startsWith(from + sep) ? `./${relative(from, file).split(sep).join('/')}` : `@kayjs/ui/${basename(file)}`
|
|
36
36
|
}
|
|
@@ -75,13 +75,8 @@ function componentProblems(ui: UiSource, component: UiComponent, report: (span:
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
// What `
|
|
79
|
-
|
|
80
|
-
const ui = uiOf(root)
|
|
81
|
-
|
|
82
|
-
if (ui === undefined)
|
|
83
|
-
return []
|
|
84
|
-
|
|
78
|
+
// What one `defineUi` file sets that the components it names do not have: an unknown or ambiguous component, an unknown part, and a file the compiler cannot read as written. An extension's file may name components this app lacks, so it is not told of those, only of a name two components bear.
|
|
79
|
+
function sourceProblems(ui: UiSource, own: boolean): CheckDiagnostic[] {
|
|
85
80
|
forgetNames(ui)
|
|
86
81
|
|
|
87
82
|
const found: Diagnostic[] = [...ui.problems]
|
|
@@ -98,8 +93,16 @@ export function uiProblems(root: string): CheckDiagnostic[] {
|
|
|
98
93
|
else if (file !== undefined)
|
|
99
94
|
named.set(file, component)
|
|
100
95
|
|
|
101
|
-
|
|
96
|
+
if (own || file !== undefined || (isComponentName(component.specifier) && componentMatches(ui, component).length > 1))
|
|
97
|
+
componentProblems(ui, component, report)
|
|
102
98
|
}
|
|
103
99
|
|
|
104
100
|
return found.map(diagnostic => fromCompile(ui.file, ui.source, diagnostic))
|
|
105
101
|
}
|
|
102
|
+
|
|
103
|
+
// What `src/ui.ts` and the extensions' `ui` files set that the components they name do not have.
|
|
104
|
+
export function uiProblems(root: string): CheckDiagnostic[] {
|
|
105
|
+
const ui = uiOf(root)
|
|
106
|
+
|
|
107
|
+
return [...uiLayersOf(root).flatMap(layer => sourceProblems(layer, false)), ...ui === undefined ? [] : sourceProblems(ui, true)]
|
|
108
|
+
}
|
|
@@ -17,12 +17,13 @@ interface Candidate {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const DEFINE_ENV = /\bdefineEnv\s*\(/
|
|
20
|
-
const SCHEMA = /export const env = defineEnv\(\s*(s|t)\.Object\(
|
|
20
|
+
const SCHEMA = /export const env = defineEnv\(\s*(?:(s|t)\.Object\()?\{(?=\r?\n|\})/
|
|
21
21
|
const FALLBACK = /^\s*\?\?\s*(?:'([^'\\\n]*)'|"([^"'\\\n]*)")(?=\s*(?:[;,)\]}]|\/\/|$))/
|
|
22
22
|
const ASSIGNED = /^\s*(?:\?\?|\|\||&&|\*\*|<<|>>>|>>|[-+*/%&|^])?=(?![=>])/
|
|
23
23
|
const DELETED = /\bdelete\s+$/
|
|
24
24
|
const ENV_NAME = /(?<![.\w$])env(?![\w$])/
|
|
25
25
|
const RAW_START = /^(?:process\.env|Bun\.env)/
|
|
26
|
+
const S_IMPORT = /import\s*\{[^}]*\bs\b[^}]*\}\s*from\s*['"]kay(?:\/server)?['"]/
|
|
26
27
|
const SCHEMA_PATH = /\.[mc]?ts$/
|
|
27
28
|
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/
|
|
28
29
|
const EXTENSION = /\.[mc]?[jt]s$/
|
|
@@ -140,7 +141,7 @@ function regexLiteralEnd(text: string, start: number): number | undefined {
|
|
|
140
141
|
return undefined
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
// The schema file a variable is added to: the project's `export const env = defineEnv(s.Object({` when it has one, `src/env.ts` when it has no `defineEnv` at all, nothing when it declares them in another shape.
|
|
144
|
+
// The schema file a variable is added to: the project's `export const env = defineEnv({` (or `defineEnv(s.Object({`) when it has one, `src/env.ts` when it has no `defineEnv` at all, nothing when it declares them in another shape.
|
|
144
145
|
async function schemaFile(root: string): Promise<{ file: string, existing: { prefix: string, at: number } | undefined } | undefined> {
|
|
145
146
|
const files = [...new Bun.Glob('src/**/*.{ts,tsx,js,mjs,mts,kay}').scanSync({ cwd: root })].sort().filter(file => !TEST_FILE.test(file))
|
|
146
147
|
const holders: { file: string, text: string }[] = []
|
|
@@ -158,11 +159,20 @@ async function schemaFile(root: string): Promise<{ file: string, existing: { pre
|
|
|
158
159
|
const [only, ...others] = holders
|
|
159
160
|
const found = others.length === 0 ? SCHEMA.exec(only!.text) : null
|
|
160
161
|
|
|
161
|
-
return found === null || !SCHEMA_PATH.test(only!.file) ? undefined : { file: only!.file, existing: { prefix: found[1]
|
|
162
|
+
return found === null || !SCHEMA_PATH.test(only!.file) ? undefined : { file: only!.file, existing: { prefix: found[1] ?? 's', at: found.index + found[0].length } }
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
function field(prefix: string, name: string, fallback: string | undefined): string {
|
|
165
|
-
|
|
166
|
+
// `t` is Elysia's, which the project's schema was written with; `s` is kay's.
|
|
167
|
+
if (prefix === 't')
|
|
168
|
+
return `${name}: ${fallback === undefined ? 't.Optional(t.String())' : `t.String({ default: '${fallback}' })`}`
|
|
169
|
+
|
|
170
|
+
return `${name}: ${fallback === undefined ? 's.string({ optional: true })' : `s.string({ default: '${fallback}' })`}`
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// A record of fields needs no `s` of its own until a variable is declared with it.
|
|
174
|
+
function withS(text: string, prefix: string): string {
|
|
175
|
+
return prefix !== 's' || S_IMPORT.test(text) ? text : insertImport(text, 'import { s } from \'kay\'')
|
|
166
176
|
}
|
|
167
177
|
|
|
168
178
|
// Declares the variables `process.env.X` is read for with no schema, in the schema file of the project, and rewrites their reads to `env.X`, a `?? 'default'` becoming the variable's default. `files` are the only files it may change: a variable with a read outside them is left alone, as is one whose read is assigned or deleted, destructured, in a `.kay` file or a file with an `env` of its own, inside a string, a template or a comment, or in the schema file itself. Answers the variables declared and the reads rewritten.
|
|
@@ -234,7 +244,7 @@ export async function declareRawEnv(root: string, undeclared: ReadonlySet<string
|
|
|
234
244
|
|
|
235
245
|
// The schema goes first, so a failed write leaves no file importing what is not there.
|
|
236
246
|
if (schema.existing === undefined) {
|
|
237
|
-
await writeFile(schema.file, `import { s } from 'kay'\nimport { defineEnv } from 'kay/server'\n\nexport const env = defineEnv(
|
|
247
|
+
await writeFile(schema.file, `import { s } from 'kay'\nimport { defineEnv } from 'kay/server'\n\nexport const env = defineEnv({\n${fields.map(line => ` ${line},\n`).join('')}})\n`)
|
|
238
248
|
}
|
|
239
249
|
else {
|
|
240
250
|
const text = await readFile(schema.file, 'utf8')
|
|
@@ -242,7 +252,9 @@ export async function declareRawEnv(root: string, undeclared: ReadonlySet<string
|
|
|
242
252
|
const eol = text.includes('\r\n') ? '\r\n' : '\n'
|
|
243
253
|
const indent = INDENT.exec(text.slice(at))?.[1] ?? ' '
|
|
244
254
|
|
|
245
|
-
|
|
255
|
+
const added = `${text.slice(0, at)}${fields.map(line => `${eol}${indent}${line},`).join('')}${text[at] === '}' ? eol : ''}${text.slice(at)}`
|
|
256
|
+
|
|
257
|
+
await writeFile(schema.file, withS(added, schema.existing.prefix))
|
|
246
258
|
}
|
|
247
259
|
|
|
248
260
|
for (const [file, list] of edits) {
|
package/src/commands/routes.ts
CHANGED
|
@@ -163,7 +163,7 @@ async function apiRoutes(root: string, config: KayConfig, modules: ApiModule[],
|
|
|
163
163
|
const instance = typeof exported === 'function' && extension !== undefined ? await (exported as (app: ExtensionApp) => unknown)(await appOf(extension)) : exported
|
|
164
164
|
|
|
165
165
|
if (!(instance instanceof Elysia))
|
|
166
|
-
throw new
|
|
166
|
+
throw new TypeError('it exports no Elysia instance by default')
|
|
167
167
|
|
|
168
168
|
for (const route of instance.routes.filter(route => ROUTE_METHODS.test(route.method)))
|
|
169
169
|
listed.push({ methods: route.method.toUpperCase(), path: apiRoutePath(module.mount, route.path), kind: 'api', by: shown(module.file), file: shown(module.file), notes, guards })
|
package/src/compiler/a11y.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Reader } from './a11y-markup'
|
|
2
2
|
import type { Diagnostic, ElementNode, KayFile, NamedAttribute, Node, SnippetNode } from './ast'
|
|
3
|
+
import { autocompleteByName } from '../runtime/form-types'
|
|
3
4
|
import { elementHasContent, markupLints, reader } from './a11y-markup'
|
|
4
5
|
import { ABSTRACT_ROLES, ARIA_ATTRIBUTES, ARIA_STATE_VALUES, closest, REQUIRED_STATES, ROLES, validAutocomplete } from './aria'
|
|
5
6
|
import { childBlocks, nodeExpressions, sectionOf, visitNodes } from './ast'
|
|
@@ -11,6 +12,12 @@ const UNLABELLED_TYPES = new Set(['hidden', 'submit', 'reset', 'button', 'image'
|
|
|
11
12
|
// What names an element besides its content.
|
|
12
13
|
const NAMING = ['aria-label', 'aria-labelledby', 'title']
|
|
13
14
|
const HEADING = /^h([1-6])$/
|
|
15
|
+
|
|
16
|
+
// Whether an input has an `autocomplete`: written, or given by the schema at render, `email` for an email field and what the name of a password asks for.
|
|
17
|
+
function givesAutocomplete(written: boolean, field: string | undefined, type: string): boolean {
|
|
18
|
+
return written || (field !== undefined && (type === 'email' || autocompleteByName(field) !== undefined))
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
const UI_IMPORT = /^import\b[^\n]*['"]@kayjs\/ui\/[^'"\n]*['"];?[ \t]*$/gm
|
|
15
22
|
const TOOLTIP_IMPORT = /^import\s+Tooltip\s+from\s+['"]@kayjs\/ui\/tooltip\.kay['"]/m
|
|
16
23
|
const WHITESPACE_CHAR = /\s/
|
|
@@ -556,7 +563,7 @@ function elementLints(file: KayFile): Diagnostic[] {
|
|
|
556
563
|
lint(pointer.name, 'mouse-only-event', `\`${text(pointer.name)}\` has no keyboard counterpart on this \`${element.name}\``, { note: 'what the pointer reveals or hides is never reached by a keyboard user, whom only focus tells', help: `handle \`${wanted}\` the same way, on an element the keyboard reaches` })
|
|
557
564
|
}
|
|
558
565
|
|
|
559
|
-
if (element.name === 'input' && type !== undefined && FILLED_TYPES.has(type) && !has(element, 'autocomplete'))
|
|
566
|
+
if (element.name === 'input' && type !== undefined && FILLED_TYPES.has(type) && !givesAutocomplete(has(element, 'autocomplete'), staticValue(element, 'field'), type))
|
|
560
567
|
lint(element, 'missing-autocomplete', `This \`${type}\` input has no \`autocomplete\``, { note: 'a browser or a password manager fills a field from it, which people with motor or memory difficulties rely on', help: type === 'email' ? 'write `autocomplete="email"`, or `username`' : 'write `autocomplete="current-password"` or `new-password`' })
|
|
561
568
|
|
|
562
569
|
const autocomplete = staticValue(element, 'autocomplete')
|
package/src/compiler/ast.ts
CHANGED
|
@@ -354,7 +354,7 @@ export function formFieldOf(element: ElementNode, source: string, inherited?: st
|
|
|
354
354
|
field.fill = 'content'
|
|
355
355
|
else if (element.name === 'select')
|
|
356
356
|
field.fill = attributes.has('multiple') ? undefined : 'selected'
|
|
357
|
-
else if (inputType === 'checkbox' || inputType === 'radio')
|
|
357
|
+
else if (inputType === 'checkbox' || inputType === 'radio' || (type === undefined && attributes.has('checked')))
|
|
358
358
|
field.fill = 'checked'
|
|
359
359
|
else if (!UNFILLED_TYPES.has(inputType))
|
|
360
360
|
field.fill = 'value'
|
|
@@ -6,7 +6,7 @@ type ExpressionAttribute = Extract<NamedAttribute, { kind: 'expression' }>
|
|
|
6
6
|
const BOUND_NAME = /^\s*[A-Z_$][\w$]*(?:\s*\.\s*[A-Z_$][\w$]*)*\s*$/i
|
|
7
7
|
|
|
8
8
|
// The callback a bound prop reports its changes through: `open` and `onOpenChange`.
|
|
9
|
-
function changeName(prop: string): string {
|
|
9
|
+
export function changeName(prop: string): string {
|
|
10
10
|
return `on${prop[0]!.toUpperCase()}${prop.slice(1)}Change`
|
|
11
11
|
}
|
|
12
12
|
|