@kayjs/kay 1.106.0 → 1.107.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/eslint.js +428 -176
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +1 -1
- package/llms/actions-refused-fields.md +22 -0
- package/llms/actions.md +2 -22
- package/llms/browser-only.md +1 -1
- package/llms/compiler-api.md +1 -1
- package/llms/components.md +1 -1
- package/llms/deprecated-lints.md +2 -3
- package/llms/island-and-form-lints.md +1 -0
- package/llms/islands.md +10 -1
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +2 -2
- package/llms/schemas.md +6 -4
- package/llms/upgrading.md +19 -1
- package/llms/whats-new.md +14 -1
- package/package.json +15 -6
- package/src/build/client.ts +20 -24
- package/src/build/entry-files.ts +19 -0
- package/src/build/lazy-components.ts +130 -0
- package/src/build/lazy-manifest.ts +56 -0
- package/src/build/lazy-stubs.ts +31 -0
- package/src/build/plugin.ts +3 -1
- package/src/build/runtime-chunk.ts +1 -1
- package/src/build/transform.ts +17 -7
- package/src/build/variants.ts +7 -4
- package/src/check/action-options.ts +56 -0
- package/src/check/schema-json.ts +226 -0
- package/src/check/shadow-types.ts +11 -9
- package/src/compiler/codegen.ts +7 -17
- package/src/compiler/deprecated-lints-1-105.ts +41 -0
- package/src/compiler/deprecated-lints-1-106.ts +1 -1
- package/src/compiler/deprecated-lints-1-107.ts +14 -0
- package/src/compiler/deprecated-lints.ts +7 -55
- package/src/compiler/import-edits.ts +15 -0
- package/src/compiler/index.ts +8 -3
- package/src/compiler/island-declaration.ts +15 -0
- package/src/compiler/kay-exports.ts +1 -0
- package/src/compiler/lazy-imports.ts +357 -0
- package/src/compiler/parser.ts +2 -2
- package/src/compiler/route-lints.ts +2 -0
- package/src/compiler/schema-lints.ts +13 -0
- package/src/compiler/script-server.ts +6 -3
- package/src/content/validate.ts +1 -1
- package/src/new.ts +6 -2
- package/src/runtime/action.ts +47 -4
- package/src/runtime/client.ts +10 -0
- package/src/runtime/dom-lazy.ts +276 -0
- package/src/runtime/field-errors.ts +58 -0
- package/src/runtime/field-refusal.ts +179 -0
- package/src/runtime/form.ts +3 -2
- package/src/runtime/html.ts +6 -1
- package/src/runtime/index.ts +2 -0
- package/src/runtime/island.server.ts +36 -2
- package/src/runtime/schema-record.ts +2 -1
- package/src/runtime/schema.client.ts +104 -14
- package/src/runtime/schema.ts +9 -2
- package/src/runtime/standard-schema.ts +32 -0
- package/src/runtime/validate-run.client.ts +179 -0
- package/src/runtime/validate.client.ts +11 -0
- package/src/runtime/validate.ts +4 -137
- package/src/server/actions.ts +48 -43
- package/src/server/answer.ts +102 -0
- package/src/server/api-input.ts +166 -0
- package/src/server/api.ts +12 -44
- package/src/server/app-stages.ts +15 -8
- package/src/server/app.ts +5 -2
- package/src/server/client.ts +2 -0
- package/src/server/dev.ts +7 -9
- package/src/server/file-limit.ts +7 -1
- package/src/server/forms.ts +1 -1
- package/src/server/host-allowlist.ts +7 -7
- package/src/server/index.ts +2 -0
- package/src/server/kay-routes.ts +221 -0
- package/src/server/kay-server.ts +228 -0
- package/src/server/kept-exports.ts +1 -0
- package/src/server/library.ts +0 -2
- package/src/server/mcp.ts +1 -1
- package/src/server/openapi.ts +12 -3
- package/src/server/phases.ts +249 -0
- package/src/server/protection.ts +6 -6
- package/src/server/proxy-key.ts +8 -8
- package/src/server/query.ts +4 -25
- package/src/server/receive.ts +43 -0
- package/src/server/render-document.ts +13 -3
- package/src/server/request-context.ts +137 -0
- package/src/server/schema-check.ts +1 -1
- package/src/server/socket.ts +19 -47
- package/src/server/stream.ts +1 -1
- package/src/server/validate.ts +346 -0
- package/src/test/mount.ts +6 -2
- package/types/build/client.d.ts +3 -2
- package/types/build/client.d.ts.map +1 -1
- package/types/build/entry-files.d.ts +4 -0
- package/types/build/entry-files.d.ts.map +1 -0
- package/types/build/lazy-components.d.ts +6 -0
- package/types/build/lazy-components.d.ts.map +1 -0
- package/types/build/lazy-manifest.d.ts +19 -0
- package/types/build/lazy-manifest.d.ts.map +1 -0
- package/types/build/lazy-stubs.d.ts +5 -0
- package/types/build/lazy-stubs.d.ts.map +1 -0
- package/types/build/plugin.d.ts +1 -0
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/transform.d.ts +3 -1
- package/types/build/transform.d.ts.map +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/action-options.d.ts +3 -0
- package/types/check/action-options.d.ts.map +1 -0
- package/types/check/schema-json.d.ts +3 -0
- package/types/check/schema-json.d.ts.map +1 -0
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/compiler/codegen.d.ts +2 -0
- package/types/compiler/codegen.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-105.d.ts +39 -0
- package/types/compiler/deprecated-lints-1-105.d.ts.map +1 -0
- package/types/compiler/deprecated-lints-1-106.d.ts +1 -1
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-107.d.ts +12 -0
- package/types/compiler/deprecated-lints-1-107.d.ts.map +1 -0
- package/types/compiler/deprecated-lints.d.ts +36 -44
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/import-edits.d.ts +1 -0
- package/types/compiler/import-edits.d.ts.map +1 -1
- package/types/compiler/index.d.ts +2 -0
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-declaration.d.ts +5 -0
- package/types/compiler/island-declaration.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/lazy-imports.d.ts +33 -0
- package/types/compiler/lazy-imports.d.ts.map +1 -0
- package/types/compiler/lints.d.ts +44 -44
- package/types/compiler/route-lints.d.ts +8 -0
- package/types/compiler/route-lints.d.ts.map +1 -1
- package/types/compiler/schema-lints.d.ts +11 -0
- package/types/compiler/schema-lints.d.ts.map +1 -0
- package/types/compiler/script-server.d.ts.map +1 -1
- package/types/new.d.ts +1 -0
- package/types/new.d.ts.map +1 -1
- package/types/runtime/action.d.ts +26 -1
- package/types/runtime/action.d.ts.map +1 -1
- package/types/runtime/client.d.ts.map +1 -1
- package/types/runtime/dom-lazy.d.ts +6 -0
- package/types/runtime/dom-lazy.d.ts.map +1 -0
- package/types/runtime/field-errors.d.ts +4 -0
- package/types/runtime/field-errors.d.ts.map +1 -0
- package/types/runtime/field-refusal.d.ts +37 -0
- package/types/runtime/field-refusal.d.ts.map +1 -0
- package/types/runtime/form.d.ts +1 -1
- package/types/runtime/form.d.ts.map +1 -1
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -0
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +2 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/schema-record.d.ts.map +1 -1
- package/types/runtime/schema.client.d.ts.map +1 -1
- package/types/runtime/schema.d.ts +6 -1
- package/types/runtime/schema.d.ts.map +1 -1
- package/types/runtime/standard-schema.d.ts +37 -0
- package/types/runtime/standard-schema.d.ts.map +1 -0
- package/types/runtime/validate-run.client.d.ts +4 -0
- package/types/runtime/validate-run.client.d.ts.map +1 -0
- package/types/runtime/validate.client.d.ts +4 -0
- package/types/runtime/validate.client.d.ts.map +1 -0
- package/types/runtime/validate.d.ts +1 -21
- package/types/runtime/validate.d.ts.map +1 -1
- package/types/server/actions.d.ts.map +1 -1
- package/types/server/answer.d.ts +6 -0
- package/types/server/answer.d.ts.map +1 -0
- package/types/server/api-input.d.ts +19 -0
- package/types/server/api-input.d.ts.map +1 -0
- package/types/server/api.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +4 -1
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +2 -0
- package/types/server/app.d.ts.map +1 -1
- package/types/server/client.d.ts +1 -0
- package/types/server/client.d.ts.map +1 -1
- package/types/server/dev.d.ts +1 -1
- package/types/server/dev.d.ts.map +1 -1
- package/types/server/file-limit.d.ts.map +1 -1
- package/types/server/host-allowlist.d.ts +3 -3
- package/types/server/host-allowlist.d.ts.map +1 -1
- package/types/server/index.d.ts +2 -0
- package/types/server/index.d.ts.map +1 -1
- package/types/server/kay-routes.d.ts +47 -0
- package/types/server/kay-routes.d.ts.map +1 -0
- package/types/server/kay-server.d.ts +25 -0
- package/types/server/kay-server.d.ts.map +1 -0
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/library.d.ts +0 -1
- package/types/server/library.d.ts.map +1 -1
- package/types/server/openapi.d.ts.map +1 -1
- package/types/server/phases.d.ts +36 -0
- package/types/server/phases.d.ts.map +1 -0
- package/types/server/protection.d.ts +3 -2
- package/types/server/protection.d.ts.map +1 -1
- package/types/server/proxy-key.d.ts +3 -3
- package/types/server/proxy-key.d.ts.map +1 -1
- package/types/server/query.d.ts.map +1 -1
- package/types/server/receive.d.ts +9 -0
- package/types/server/receive.d.ts.map +1 -0
- package/types/server/render-document.d.ts.map +1 -1
- package/types/server/request-context.d.ts +29 -0
- package/types/server/request-context.d.ts.map +1 -0
- package/types/server/schema-check.d.ts +1 -0
- package/types/server/schema-check.d.ts.map +1 -1
- package/types/server/socket.d.ts +3 -5
- package/types/server/socket.d.ts.map +1 -1
- package/types/server/validate.d.ts +26 -0
- package/types/server/validate.d.ts.map +1 -0
- package/types/test/mount.d.ts.map +1 -1
- package/src/check/schema-type.ts +0 -9
- package/src/compiler/deprecated-script-fence.ts +0 -26
- package/src/server/field-errors.ts +0 -136
- package/types/check/schema-type.d.ts +0 -3
- package/types/check/schema-type.d.ts.map +0 -1
- package/types/compiler/deprecated-script-fence.d.ts +0 -3
- package/types/compiler/deprecated-script-fence.d.ts.map +0 -1
- package/types/server/field-errors.d.ts +0 -6
- package/types/server/field-errors.d.ts.map +0 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { CheckDiagnostic, CheckOptions } from '.'
|
|
2
|
+
import type { Node, Program } from '../compiler/estree'
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { dirname, resolve } from 'node:path'
|
|
5
|
+
import { parseProgram } from '../compiler/estree'
|
|
6
|
+
import { apiScope, fromApi, isPlain, keyName } from './api-scope'
|
|
7
|
+
import { importedName, importsOf, walk } from './ast'
|
|
8
|
+
import { scan } from './renamed-exports'
|
|
9
|
+
|
|
10
|
+
const KAY = /^kay(?:\/|$)/
|
|
11
|
+
const NEEDLE = /\baction\b|\bapi\b/
|
|
12
|
+
const VALIBOT = /^valibot(?:\/|$)/
|
|
13
|
+
const SOURCE = /\.tsx?$/
|
|
14
|
+
const ROUTE_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'all'])
|
|
15
|
+
const ROUTE_SCHEMAS = new Set(['body', 'query', 'params', 'headers', 'cookie'])
|
|
16
|
+
const ACTION_SCHEMAS = new Set(['input'])
|
|
17
|
+
const RELATIVE = /^\.\.?\//
|
|
18
|
+
const EXTENSIONS = ['', '.ts', '.tsx', '/index.ts']
|
|
19
|
+
const WRAPPERS = new Set(['TSAsExpression', 'TSSatisfiesExpression', 'TSNonNullExpression', 'ParenthesizedExpression'])
|
|
20
|
+
const MAX_HOPS = 4
|
|
21
|
+
|
|
22
|
+
// A module of the project: its program and where it is, so a name it imports from a neighbour is read there.
|
|
23
|
+
interface Module {
|
|
24
|
+
ast: Program
|
|
25
|
+
file: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function readModule(from: string, specifier: string): Module | undefined {
|
|
29
|
+
for (const extension of EXTENSIONS) {
|
|
30
|
+
const file = resolve(dirname(from), specifier + extension)
|
|
31
|
+
|
|
32
|
+
if (!SOURCE.test(file) || !existsSync(file))
|
|
33
|
+
continue
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
return { ast: parseProgram(readFileSync(file, 'utf8'), { lang: file.endsWith('.tsx') ? 'tsx' : 'ts', recover: true }).program, file }
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return undefined
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The initializer of the top-level `const name`, exported or not.
|
|
47
|
+
function declared(ast: Program, name: string): Node | undefined {
|
|
48
|
+
for (const statement of ast.body) {
|
|
49
|
+
const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement
|
|
50
|
+
|
|
51
|
+
if (declaration?.type !== 'VariableDeclaration')
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
for (const declarator of declaration.declarations) {
|
|
55
|
+
if (declarator.id.type === 'Identifier' && declarator.id.name === name && declarator.init)
|
|
56
|
+
return declarator.init
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The module and the name a relative import binds `local` to; `default` for a default import.
|
|
64
|
+
function importedFrom({ ast, file }: Module, local: string): { module: Module, name: string } | undefined {
|
|
65
|
+
for (const statement of ast.body) {
|
|
66
|
+
if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type' || !RELATIVE.test(statement.source.value))
|
|
67
|
+
continue
|
|
68
|
+
|
|
69
|
+
for (const specifier of statement.specifiers) {
|
|
70
|
+
if (specifier.type === 'ImportNamespaceSpecifier' || specifier.local.name !== local)
|
|
71
|
+
continue
|
|
72
|
+
|
|
73
|
+
const module = readModule(file, statement.source.value)
|
|
74
|
+
const name = specifier.type === 'ImportDefaultSpecifier' ? 'default' : importedName(specifier)
|
|
75
|
+
|
|
76
|
+
return module && { module, name }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return undefined
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// What a module exports under `name`: a `const`, `export default <expression>`, or one `export { name } from './other'` hop.
|
|
84
|
+
function exported(module: Module, name: string, hops = 0): { init: Node, module: Module } | undefined {
|
|
85
|
+
for (const statement of module.ast.body) {
|
|
86
|
+
if (name === 'default' && statement.type === 'ExportDefaultDeclaration' && !statement.declaration.type.endsWith('Declaration'))
|
|
87
|
+
return { init: statement.declaration as unknown as Node, module }
|
|
88
|
+
|
|
89
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.source === null || hops > 0)
|
|
90
|
+
continue
|
|
91
|
+
|
|
92
|
+
for (const specifier of statement.specifiers) {
|
|
93
|
+
if ((specifier.exported.type === 'Identifier' ? specifier.exported.name : specifier.exported.value) !== name)
|
|
94
|
+
continue
|
|
95
|
+
|
|
96
|
+
const next = readModule(module.file, statement.source.value)
|
|
97
|
+
|
|
98
|
+
return next && exported(next, specifier.local.type === 'Identifier' ? specifier.local.name : specifier.local.value, hops + 1)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const init = declared(module.ast, name)
|
|
103
|
+
|
|
104
|
+
return init && { init, module }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function paramName(param: { type: string, left?: unknown, name?: string }): string | undefined {
|
|
108
|
+
if (param.type === 'AssignmentPattern')
|
|
109
|
+
return paramName(param.left as { type: string })
|
|
110
|
+
|
|
111
|
+
return param.type === 'Identifier' ? param.name : undefined
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Whether the file binds `name` anywhere but its import, as a parameter or a declaration, so a use of it may be that binding.
|
|
115
|
+
function rebound(ast: Program, name: string): boolean {
|
|
116
|
+
let found = false
|
|
117
|
+
|
|
118
|
+
walk(ast, (node) => {
|
|
119
|
+
if (node.type === 'VariableDeclarator' && node.id.type === 'Identifier' && node.id.name === name)
|
|
120
|
+
found = true
|
|
121
|
+
else if ((node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') && node.params.some(param => paramName(param) === name))
|
|
122
|
+
found = true
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
return found
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function fromValibot({ ast }: Module, name: string): boolean {
|
|
129
|
+
return ast.body.some(statement => statement.type === 'ImportDeclaration' && statement.importKind !== 'type' && VALIBOT.test(statement.source.value) && statement.specifiers.some(specifier => specifier.local.name === name)) && !rebound(ast, name)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Whether the expression names `toStandardJsonSchema` anywhere, which gives a valibot schema what it lacks.
|
|
133
|
+
function wrapsJsonSchema(node: Node): boolean {
|
|
134
|
+
let found = false
|
|
135
|
+
|
|
136
|
+
walk(node, (inner) => {
|
|
137
|
+
if (inner.type === 'Identifier' && inner.name === 'toStandardJsonSchema')
|
|
138
|
+
found = true
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
return found
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Whether an object literal holds `~standard` with no `jsonSchema` in it; one with a spread, or a `~standard` that is no literal, is taken to have it.
|
|
145
|
+
function handWritten(object: Extract<Node, { type: 'ObjectExpression' }>): boolean {
|
|
146
|
+
const standard = object.properties.find(property => isPlain(property) && keyName(property) === '~standard')
|
|
147
|
+
|
|
148
|
+
if (standard === undefined || !isPlain(standard) || standard.value.type !== 'ObjectExpression')
|
|
149
|
+
return false
|
|
150
|
+
|
|
151
|
+
return standard.value.properties.every(property => isPlain(property) && keyName(property) !== 'jsonSchema')
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Whether the expression is a Standard Schema validator known to lack `~standard.jsonSchema`: an object literal written by hand, or what valibot builds, which carries none until `toStandardJsonSchema` wraps it.
|
|
155
|
+
// A name is followed to its `const`, here or in a module imported by a relative path; anything else, a call of the app's own or a library other than valibot, is taken to have it.
|
|
156
|
+
function lacksJsonSchema(node: Node, module: Module, hops = 0): boolean {
|
|
157
|
+
if (wrapsJsonSchema(node))
|
|
158
|
+
return false
|
|
159
|
+
|
|
160
|
+
let current = node
|
|
161
|
+
|
|
162
|
+
for (;;) {
|
|
163
|
+
if (WRAPPERS.has(current.type))
|
|
164
|
+
current = (current as unknown as { expression: Node }).expression
|
|
165
|
+
else if (current.type === 'CallExpression')
|
|
166
|
+
current = current.callee
|
|
167
|
+
else if (current.type === 'MemberExpression')
|
|
168
|
+
current = current.object
|
|
169
|
+
else
|
|
170
|
+
break
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (current.type === 'ObjectExpression')
|
|
174
|
+
return handWritten(current)
|
|
175
|
+
|
|
176
|
+
if (current.type !== 'Identifier' || hops > MAX_HOPS)
|
|
177
|
+
return false
|
|
178
|
+
|
|
179
|
+
if (fromValibot(module, current.name))
|
|
180
|
+
return true
|
|
181
|
+
|
|
182
|
+
const init = declared(module.ast, current.name)
|
|
183
|
+
|
|
184
|
+
if (init)
|
|
185
|
+
return lacksJsonSchema(init, module, hops + 1)
|
|
186
|
+
|
|
187
|
+
const imported = importedFrom(module, current.name)
|
|
188
|
+
const remote = imported && exported(imported.module, imported.name)
|
|
189
|
+
|
|
190
|
+
return remote !== undefined && lacksJsonSchema(remote.init, remote.module, hops + 1)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// The values of the options object's members named `names`.
|
|
194
|
+
function positions(options: Node | undefined, names: Set<string>): Node[] {
|
|
195
|
+
if (options?.type !== 'ObjectExpression')
|
|
196
|
+
return []
|
|
197
|
+
|
|
198
|
+
return options.properties.flatMap(property => isPlain(property) && names.has(keyName(property) ?? '') ? [property.value] : [])
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// A Standard Schema validator with no `~standard.jsonSchema` where an action's `input` or an API route's `body`, `query`, `params`, `headers` or `cookie` takes a schema: it still validates, but a form shows no constraints, a form or a query is not read as numbers and booleans, and OpenAPI and MCP show an open schema.
|
|
202
|
+
// Read in the TypeScript files and the fences of `.kay` files alike, from what the source shows: an object literal with `~standard`, and valibot's builders, followed through a `const` and a relative import.
|
|
203
|
+
export async function schemaJson(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
204
|
+
return scan(root, options, 'schema-without-json-schema', NEEDLE, ({ file, parsed, report }) => {
|
|
205
|
+
for (const { ast, base } of parsed) {
|
|
206
|
+
const { locals: actions, namespaces } = importsOf(ast, source => KAY.test(source), 'action')
|
|
207
|
+
const scope = apiScope(ast)
|
|
208
|
+
const module: Module = { ast, file }
|
|
209
|
+
|
|
210
|
+
walk(ast, (node) => {
|
|
211
|
+
if (node.type !== 'CallExpression')
|
|
212
|
+
return
|
|
213
|
+
|
|
214
|
+
let schemas: Node[] = []
|
|
215
|
+
|
|
216
|
+
if ((node.callee.type === 'Identifier' && actions.has(node.callee.name)) || (node.callee.type === 'MemberExpression' && !node.callee.computed && node.callee.object.type === 'Identifier' && namespaces.has(node.callee.object.name) && node.callee.property.type === 'Identifier' && node.callee.property.name === 'action'))
|
|
217
|
+
schemas = positions(node.arguments[0], ACTION_SCHEMAS)
|
|
218
|
+
else if (node.callee.type === 'MemberExpression' && !node.callee.computed && node.callee.property.type === 'Identifier' && ROUTE_METHODS.has(node.callee.property.name) && fromApi(node.callee.object, scope))
|
|
219
|
+
schemas = positions(node.arguments[2], ROUTE_SCHEMAS)
|
|
220
|
+
|
|
221
|
+
for (const schema of schemas.filter(candidate => lacksJsonSchema(candidate, module)))
|
|
222
|
+
report(base + schema.start, base + schema.end, 'this Standard Schema validator has no `~standard.jsonSchema`: it still validates, but a form shows no constraints, a form or a query is not read as numbers and booleans, and OpenAPI and MCP show an open schema', 'give it `~standard.jsonSchema` (Zod 4.2+ and ArkType 2.1.28+ carry it, valibot through `toStandardJsonSchema` from `@valibot/to-json-schema`) or build the schema with `s`', null)
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
}
|
|
@@ -33,6 +33,7 @@ import { redirectProblems } from '../server/redirects'
|
|
|
33
33
|
import { extensionEditor, patternShapes, routeMounts, scanEndpoints, scanRoutes, servedPaths } from '../server/routes'
|
|
34
34
|
import { readRuntimeRedirects } from '../server/runtime-redirects'
|
|
35
35
|
|
|
36
|
+
import { actionOptions } from './action-options'
|
|
36
37
|
import { actionReaders } from './action-readers'
|
|
37
38
|
import { actionType } from './action-type'
|
|
38
39
|
import { aiLanguage } from './ai-language'
|
|
@@ -44,31 +45,31 @@ import { cmsOptions } from './cms-options'
|
|
|
44
45
|
import { configGroups } from './config-groups'
|
|
45
46
|
import { configSwitches } from './config-switches'
|
|
46
47
|
import { contextImport } from './context-import'
|
|
47
|
-
import { ownFile } from './diagnose'
|
|
48
48
|
|
|
49
|
+
import { ownFile } from './diagnose'
|
|
49
50
|
import { endpointExports } from './endpoint-exports'
|
|
50
|
-
import { envFiles } from './env-files'
|
|
51
51
|
|
|
52
|
+
import { envFiles } from './env-files'
|
|
52
53
|
import { ASSET_TYPES, environmentTypes, kayPaths, packageTypes } from './env-types'
|
|
53
|
-
import { formatDurationNumbers } from './format-duration'
|
|
54
54
|
|
|
55
|
+
import { formatDurationNumbers } from './format-duration'
|
|
55
56
|
import { CONTENT_CHECK, EXPORTS_CHECK, exportsCheck, SETTINGS_CHECK, settingsCheck } from './generated'
|
|
56
|
-
import { guardOptions } from './guard-options'
|
|
57
57
|
|
|
58
|
+
import { guardOptions } from './guard-options'
|
|
58
59
|
import { unguardedRoutes, unguardedTools } from './guards'
|
|
59
60
|
import { hookContext } from './hook-context'
|
|
60
61
|
import { hookNames } from './hook-names'
|
|
61
62
|
import { i18nKeys } from './i18n-keys'
|
|
62
|
-
import { imagesKeys } from './images-keys'
|
|
63
63
|
|
|
64
|
+
import { imagesKeys } from './images-keys'
|
|
64
65
|
import { islandOnlyComponents } from './island-only'
|
|
66
|
+
|
|
65
67
|
import { diskFilesCalls, jobHandlers, jobOptions, scheduleCalls } from './job-shapes'
|
|
66
68
|
|
|
67
69
|
import { largePublicImages } from './large-images'
|
|
68
|
-
|
|
69
70
|
import { liveApi } from './live-api'
|
|
70
|
-
import { mailApi } from './mail-api'
|
|
71
71
|
|
|
72
|
+
import { mailApi } from './mail-api'
|
|
72
73
|
import { mcpRoutes } from './mcp-routes'
|
|
73
74
|
import { islandEvents, listenTarget, movedImports, navigateQuery, navigationHooks, persistedCall, persistedQuery } from './one-state-api'
|
|
74
75
|
import { unreadOpenSettings } from './open-settings'
|
|
@@ -81,7 +82,7 @@ import { retiredLintLevels } from './retired-lints'
|
|
|
81
82
|
import { routeKeys } from './route-keys'
|
|
82
83
|
import { routeShadow, routeShadowPath } from './route-shadow'
|
|
83
84
|
import { schemaBuilders } from './schema-builders'
|
|
84
|
-
import {
|
|
85
|
+
import { schemaJson } from './schema-json'
|
|
85
86
|
import { secretKeys } from './secret-keys'
|
|
86
87
|
import { compileShadow, guardTypes, layoutQueries, matcherSource, outerSlots, pageRoute, serializeShadowSettings, SHADOW_SETTINGS, shadowOptionsFor, shadowPath } from './shadow'
|
|
87
88
|
import { socketFrames } from './socket-frames'
|
|
@@ -208,8 +209,9 @@ const PROJECT_CHECKS: ((input: ProjectCheckInput) => CheckDiagnostic[] | Promise
|
|
|
208
209
|
async ({ root, options }) => listenTarget(root, options),
|
|
209
210
|
async ({ root, options }) => movedImports(root, options),
|
|
210
211
|
|
|
211
|
-
async ({ root, options }) => schemaType(root, options),
|
|
212
212
|
async ({ root, options }) => schemaBuilders(root, options),
|
|
213
|
+
async ({ root, options }) => schemaJson(root, options),
|
|
214
|
+
async ({ root, options }) => actionOptions(root, options),
|
|
213
215
|
async ({ root, options }) => aiLanguage(root, options),
|
|
214
216
|
async ({ root, options }) => hookNames(root, options),
|
|
215
217
|
async ({ root, options }) => mailApi(root, options),
|
package/src/compiler/codegen.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ClassTable } from '../runtime/class-table'
|
|
|
2
2
|
import type { UiEntry } from '../runtime/ui'
|
|
3
3
|
import type { ConstNode, ElementNode, ErrorMessages, KayFile, Node, SlotNode, Span, TemplateFacts, TemplateHelper } from './ast'
|
|
4
4
|
import type { IslandCause } from './island-cause'
|
|
5
|
+
import type { LazyImport } from './lazy-imports'
|
|
5
6
|
import type { LoadPlan } from './load-plan'
|
|
6
7
|
import type { Rewrite } from './mapping'
|
|
7
8
|
import type { AwaitAlert, WRITE_HELPERS } from './names'
|
|
@@ -15,10 +16,12 @@ import { domHelperImport, DomTemplate } from './dom'
|
|
|
15
16
|
import { addIslandShorthandTitle, addShorthandChecks, addShorthandGroup, hasShorthandTitle } from './head-shorthand'
|
|
16
17
|
import { emitHeadTag, emitHeadText } from './head-tags'
|
|
17
18
|
import { awaitAlertTail, htmlHelperImport, HtmlTemplate } from './html'
|
|
19
|
+
import { withoutComma } from './import-edits'
|
|
18
20
|
import { sourceLocator } from './inspect'
|
|
19
21
|
import { asksOf, exportsIslandOptions, islandMessages, withAlertKeys } from './island-arguments'
|
|
20
22
|
import { ambientHelpers, constDeclaration } from './items'
|
|
21
23
|
import { JsxTemplate } from './jsx'
|
|
24
|
+
import { lazyDomImport, lazyEdits, lazyNoteImport } from './lazy-imports'
|
|
22
25
|
import { planLoads } from './load-plan'
|
|
23
26
|
import { CodeBuilder, DYNAMIC_TAG } from './mapping'
|
|
24
27
|
import { helperName } from './markup'
|
|
@@ -104,6 +107,7 @@ export interface GenerateOptions {
|
|
|
104
107
|
ui?: UiEntry | undefined
|
|
105
108
|
// Type checking's counterpart of `ui`: the variants and values `src/ui.ts` adds to the component's props.
|
|
106
109
|
uiAdded?: UiEntry | undefined
|
|
110
|
+
lazy?: ReadonlyMap<string, LazyImport> | undefined
|
|
107
111
|
// 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
112
|
writtenProps?: ReadonlySet<string> | undefined
|
|
109
113
|
// Final pass: rewrites from the analysis pass are applied and the props destructuring disappears.
|
|
@@ -119,8 +123,6 @@ export interface Generated {
|
|
|
119
123
|
|
|
120
124
|
const CTX_REFERENCE = /\bctx\b/
|
|
121
125
|
const IDENTIFIER = /[\p{ID_Start}$_][\p{ID_Continue}$]*/gu
|
|
122
|
-
const IMPORT_COMMA_AFTER = /^\s*,\s*/
|
|
123
|
-
const IMPORT_COMMA_BEFORE = /,\s*$/
|
|
124
126
|
// The specifier of an import that did not parse, quoted and closed or not.
|
|
125
127
|
const BROKEN_SPECIFIER = /^((?:\s*(?:\/\/.*\n|\/\*(?:[^*]|\*(?!\/))*\*\/))*\s*import\b(?:[^'"]*[^\w$'"]from)?\s*)((['"])[^'";\s]*\3?)/
|
|
126
128
|
// `kay build` renders the page once when it is `true`.
|
|
@@ -382,13 +384,13 @@ class ModuleShell {
|
|
|
382
384
|
b.add(this.slotTypes().imports)
|
|
383
385
|
|
|
384
386
|
if (mode === 'html')
|
|
385
|
-
b.add(htmlHelperImport(this.options.awaitAlert, facts.await))
|
|
387
|
+
b.add(htmlHelperImport(this.options.awaitAlert, facts.await) + lazyNoteImport(this.options.lazy, mode))
|
|
386
388
|
|
|
387
389
|
if (this.loadPlan)
|
|
388
390
|
b.add(`import { loadScope as ${helperName('loadScope')} } from 'kay/html'\n`)
|
|
389
391
|
|
|
390
392
|
if (mode === 'dom')
|
|
391
|
-
b.add(domHelperImport(this.options.awaitAlert, facts.await))
|
|
393
|
+
b.add(domHelperImport(this.options.awaitAlert, facts.await) + lazyDomImport(this.options.lazy))
|
|
392
394
|
|
|
393
395
|
// Apart from the DOM helpers, which the entry shares with every page, so only a site using it ships its code.
|
|
394
396
|
if (mode === 'dom' && this.kind === 'island' && titled)
|
|
@@ -695,7 +697,7 @@ class ModuleShell {
|
|
|
695
697
|
if (left.length > 0 && left.length === imports.filter(inside).length)
|
|
696
698
|
return
|
|
697
699
|
|
|
698
|
-
const edits: { start: number, end: number, text?: string }[] = left.map(binding => this.
|
|
700
|
+
const edits: { start: number, end: number, text?: string }[] = [...left.map(binding => withoutComma(this.src, binding.span, binding.declaration)), ...lazyEdits(imports, span, this.options.lazy, this.mode, this.options.moduleId)]
|
|
699
701
|
|
|
700
702
|
for (const specifier of specifiers) {
|
|
701
703
|
const quoted = this.src.slice(specifier.start, specifier.end)
|
|
@@ -730,18 +732,6 @@ class ModuleShell {
|
|
|
730
732
|
return start === 0 || this.src[start - 1] === '\n' ? start : offset
|
|
731
733
|
}
|
|
732
734
|
|
|
733
|
-
// An import specifier with the comma that separates it from its neighbour.
|
|
734
|
-
private withoutComma(specifier: Span, declaration: Span): Span {
|
|
735
|
-
const after = IMPORT_COMMA_AFTER.exec(this.src.slice(specifier.end, declaration.end))
|
|
736
|
-
|
|
737
|
-
if (after)
|
|
738
|
-
return { start: specifier.start, end: specifier.end + after[0].length }
|
|
739
|
-
|
|
740
|
-
const before = IMPORT_COMMA_BEFORE.exec(this.src.slice(declaration.start, specifier.start))
|
|
741
|
-
|
|
742
|
-
return { start: specifier.start - (before?.[0].length ?? 0), end: specifier.end }
|
|
743
|
-
}
|
|
744
|
-
|
|
745
735
|
// Server exports stay at module level; the rest of the fence becomes `load(ctx)`, returning every name it declares.
|
|
746
736
|
private emitLoad(server: ServerAnalysis) {
|
|
747
737
|
const { b } = this
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Lint } from './lints'
|
|
2
|
+
|
|
3
|
+
// The lints of the `deprecated` group for how an island read its sources and actions before 1.105, with the others in `DEPRECATED_LINTS`.
|
|
4
|
+
export const SOURCE_READERS = {
|
|
5
|
+
'deprecated-source-readers': {
|
|
6
|
+
level: 'warn',
|
|
7
|
+
group: 'deprecated',
|
|
8
|
+
since: '1.105',
|
|
9
|
+
site: true,
|
|
10
|
+
summary: 'The readers and hooks of an island\'s sources before 1.105, which every source reads alike since: `data()` in place of `value()` (a `resource`), `last()` (a `stream` or `socket`) and `rows()` (a `local` collection), `onData` in place of `onSuccess` (a `track()` handle) and `onSync` (a collection), whose event hands `value` where they handed `data` and `rows`, an action\'s `data()` and `status()` in place of `succeeded()`, and a collection\'s `sync.queued()` and `sync.status()` in place of `unsynced()` and `syncStatus()`. The old names work until 1.108. Found in the TypeScript files and `.kay` files of the project, templates included, on a name bound once to a call of `resource`, `stream`, `socket` or `local` from `kay` or to a `.track()` call, as `kay check` reads no types: a source reached through a property, a prop or another file is not found; `succeeded()` is found on any receiver. The fix renames the member, and the `data` or `rows` of a hook\'s inline handler to `value`; `succeeded()?.data` becomes `data()` and `succeeded() !== undefined` becomes `status() === \'ready\'`. A `succeeded()` read in any other way, a handler that is no inline function and a shorthand hook are reported with no fix.',
|
|
11
|
+
wrong: '---\nimport { local, resource } from \'kay\'\nimport notesApi from \'../api/notes\'\nimport { save } from \'./notes\'\n\nconst list = resource(notesApi, \'/\')\nconst notes = local({ key: \'id\', read: () => [], put: save })\n---\np {list.value()?.length} on the server, {notes.rows().length} here, {notes.unsynced()} waiting',
|
|
12
|
+
right: '---\nimport { local, resource } from \'kay\'\nimport notesApi from \'../api/notes\'\nimport { save } from \'./notes\'\n\nconst list = resource(notesApi, \'/\')\nconst notes = local({ key: \'id\', read: () => [], put: save })\n---\np {list.data()?.length} on the server, {notes.data().length} here, {notes.sync.queued()} waiting',
|
|
13
|
+
},
|
|
14
|
+
'deprecated-live-api': {
|
|
15
|
+
level: 'warn',
|
|
16
|
+
group: 'deprecated',
|
|
17
|
+
since: '1.105',
|
|
18
|
+
site: true,
|
|
19
|
+
summary: 'The forms of `set` and `presence` before 1.105, which write every live value and every room alike since: `set(next, { key })` of a value per key and `set(next, { user })` of a value per user in place of `set(key, next)` and `set(user, next)`, and `presence({ room, member })` in place of `presence(room, member)`. The old forms work until 1.108. Found in the TypeScript files and `.kay` files of the project, on a name bound once to a `live()` call from `kay`, or imported under the name of a declaration every file of the project agrees on (a value per key is one declared with a function of the key or `key: true`, per user with `user: true`), as `kay check` reads no types: a value reached through a namespace import or a property is not found. `presence` is the one imported from `kay`. The fix reorders the arguments of `set`, and writes the arguments of `presence` as one object, its options object spread into it; a `presence` given options that are no object written there is reported with no fix.',
|
|
20
|
+
wrong: '// src/live.ts\nimport { live } from \'kay\'\n\nexport const room = live((id: string) => ({ id, users: 0 }))\n\nroom.set(\'lobby\', { id: \'lobby\', users: 3 })',
|
|
21
|
+
right: '// src/live.ts\nimport { live } from \'kay\'\n\nexport const room = live((id: string) => ({ id, users: 0 }))\n\nroom.set({ id: \'lobby\', users: 3 }, { key: \'lobby\' })',
|
|
22
|
+
},
|
|
23
|
+
'deprecated-action-type': {
|
|
24
|
+
level: 'warn',
|
|
25
|
+
group: 'deprecated',
|
|
26
|
+
since: '1.105',
|
|
27
|
+
site: true,
|
|
28
|
+
summary: '`Action<never, unknown>` before 1.105, the type a prop takes to accept any action: `Action` since, whose two parameters default to it. `Action<{ name: string }, string>` keeps its input and output types, and a `.with()` action crosses into an island as any other does. The old form works until 1.108. Found on the `Action` a file imports from `kay`, under any local name, in the TypeScript files and the fences of `.kay` files. The fix drops the type arguments.',
|
|
29
|
+
wrong: '---\nimport type { Action } from \'kay\'\n\nconst { run } = props<{ run: Action<never, unknown> }>()\n---\nform(action={run})\n button Go',
|
|
30
|
+
right: '---\nimport type { Action } from \'kay\'\n\nconst { run } = props<{ run: Action }>()\n---\nform(action={run})\n button Go',
|
|
31
|
+
},
|
|
32
|
+
'deprecated-action-readers': {
|
|
33
|
+
level: 'warn',
|
|
34
|
+
group: 'deprecated',
|
|
35
|
+
since: '1.105',
|
|
36
|
+
site: true,
|
|
37
|
+
summary: 'An action\'s `failed()`, `error(field)` and `validate(form, field)` before 1.105, which a form shows and now reads from `form`: `form.failed()`, `form.error(field)` and `form.validate(form, field)`, the call state (`pending()`, `status()`, `data()`) staying on the action. The old names work until 1.108. Found in the TypeScript files and `.kay` files of the project, templates included, on a name bound once to a call of `action` from `kay`, to the `.with()` of one, or imported in lowercase from a `.kay` file, as `kay check` reads no types: an action reached through a property or a prop is not found. The fix writes `form.` before the name.',
|
|
38
|
+
wrong: '---\nimport { add } from \'./notes.kay\'\n---\nform(action={add})\n input(name="title" aria-invalid={add.error(\'title\') ? \'true\' : undefined})\n if add.failed()\n p Not saved',
|
|
39
|
+
right: '---\nimport { add } from \'./notes.kay\'\n---\nform(action={add})\n input(name="title" aria-invalid={add.form.error(\'title\') ? \'true\' : undefined})\n if add.form.failed()\n p Not saved',
|
|
40
|
+
},
|
|
41
|
+
} as const satisfies Record<string, Lint>
|
|
@@ -7,7 +7,7 @@ export const SCHEMA_BUILDERS = {
|
|
|
7
7
|
group: 'deprecated',
|
|
8
8
|
since: '1.106',
|
|
9
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 (
|
|
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 (an action\'s input, an API route\'s body, `defineEnv`, collection frontmatter), 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
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
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
13
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Lint } from './lints'
|
|
2
|
+
|
|
3
|
+
// The lints of the `deprecated` group that came in 1.107, with the others in `DEPRECATED_LINTS`.
|
|
4
|
+
export const ACTION_OPTIONS = {
|
|
5
|
+
'deprecated-action-options': {
|
|
6
|
+
level: 'warn',
|
|
7
|
+
group: 'deprecated',
|
|
8
|
+
since: '1.107',
|
|
9
|
+
site: true,
|
|
10
|
+
summary: 'The arguments of `action` before 1.107, `action(schema, handler, options)` and `action(handler, options)`: the options come first, with the input in them, as an API route\'s do, `action({ input: schema, ...options }, handler)` and `action(options, handler)`. `input` is a plain record of fields or any schema. The old forms work until 2.0. Found on the `action` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files; the fix moves the arguments and keeps their text.',
|
|
11
|
+
wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ title: s.string() }, ({ title }) => title, { maxSize: \'1mb\' })\n---\np x',
|
|
12
|
+
right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ input: { title: s.string() }, maxSize: \'1mb\' }, ({ title }) => title)\n---\np x',
|
|
13
|
+
},
|
|
14
|
+
} as const satisfies Record<string, Lint>
|
|
@@ -1,47 +1,15 @@
|
|
|
1
1
|
import type { Lint } from './lints'
|
|
2
2
|
import { AUTH_LINTS } from './deprecated-auth-lints'
|
|
3
|
+
import { SOURCE_READERS } from './deprecated-lints-1-105'
|
|
3
4
|
import { SCHEMA_BUILDERS } from './deprecated-lints-1-106'
|
|
5
|
+
import { ACTION_OPTIONS } from './deprecated-lints-1-107'
|
|
4
6
|
import { TYPED_DEPRECATIONS } from './deprecated-typed-lints'
|
|
5
7
|
|
|
6
8
|
// The lints of the `deprecated` group, with the other lints in `LINTS`; each stays three minors from its `since`.
|
|
7
9
|
export const DEPRECATED_LINTS = {
|
|
8
10
|
...SCHEMA_BUILDERS,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
group: 'deprecated',
|
|
12
|
-
since: '1.105',
|
|
13
|
-
site: true,
|
|
14
|
-
summary: 'The readers and hooks of an island\'s sources before 1.105, which every source reads alike since: `data()` in place of `value()` (a `resource`), `last()` (a `stream` or `socket`) and `rows()` (a `local` collection), `onData` in place of `onSuccess` (a `track()` handle) and `onSync` (a collection), whose event hands `value` where they handed `data` and `rows`, an action\'s `data()` and `status()` in place of `succeeded()`, and a collection\'s `sync.queued()` and `sync.status()` in place of `unsynced()` and `syncStatus()`. The old names work until 1.108. Found in the TypeScript files and `.kay` files of the project, templates included, on a name bound once to a call of `resource`, `stream`, `socket` or `local` from `kay` or to a `.track()` call, as `kay check` reads no types: a source reached through a property, a prop or another file is not found; `succeeded()` is found on any receiver. The fix renames the member, and the `data` or `rows` of a hook\'s inline handler to `value`; `succeeded()?.data` becomes `data()` and `succeeded() !== undefined` becomes `status() === \'ready\'`. A `succeeded()` read in any other way, a handler that is no inline function and a shorthand hook are reported with no fix.',
|
|
15
|
-
wrong: '---\nimport { local, resource } from \'kay\'\nimport notesApi from \'../api/notes\'\nimport { save } from \'./notes\'\n\nconst list = resource(notesApi, \'/\')\nconst notes = local({ key: \'id\', read: () => [], put: save })\n---\np {list.value()?.length} on the server, {notes.rows().length} here, {notes.unsynced()} waiting',
|
|
16
|
-
right: '---\nimport { local, resource } from \'kay\'\nimport notesApi from \'../api/notes\'\nimport { save } from \'./notes\'\n\nconst list = resource(notesApi, \'/\')\nconst notes = local({ key: \'id\', read: () => [], put: save })\n---\np {list.data()?.length} on the server, {notes.data().length} here, {notes.sync.queued()} waiting',
|
|
17
|
-
},
|
|
18
|
-
'deprecated-live-api': {
|
|
19
|
-
level: 'warn',
|
|
20
|
-
group: 'deprecated',
|
|
21
|
-
since: '1.105',
|
|
22
|
-
site: true,
|
|
23
|
-
summary: 'The forms of `set` and `presence` before 1.105, which write every live value and every room alike since: `set(next, { key })` of a value per key and `set(next, { user })` of a value per user in place of `set(key, next)` and `set(user, next)`, and `presence({ room, member })` in place of `presence(room, member)`. The old forms work until 1.108. Found in the TypeScript files and `.kay` files of the project, on a name bound once to a `live()` call from `kay`, or imported under the name of a declaration every file of the project agrees on (a value per key is one declared with a function of the key or `key: true`, per user with `user: true`), as `kay check` reads no types: a value reached through a namespace import or a property is not found. `presence` is the one imported from `kay`. The fix reorders the arguments of `set`, and writes the arguments of `presence` as one object, its options object spread into it; a `presence` given options that are no object written there is reported with no fix.',
|
|
24
|
-
wrong: '// src/live.ts\nimport { live } from \'kay\'\n\nexport const room = live((id: string) => ({ id, users: 0 }))\n\nroom.set(\'lobby\', { id: \'lobby\', users: 3 })',
|
|
25
|
-
right: '// src/live.ts\nimport { live } from \'kay\'\n\nexport const room = live((id: string) => ({ id, users: 0 }))\n\nroom.set({ id: \'lobby\', users: 3 }, { key: \'lobby\' })',
|
|
26
|
-
},
|
|
27
|
-
'deprecated-action-type': {
|
|
28
|
-
level: 'warn',
|
|
29
|
-
group: 'deprecated',
|
|
30
|
-
since: '1.105',
|
|
31
|
-
site: true,
|
|
32
|
-
summary: '`Action<never, unknown>` before 1.105, the type a prop takes to accept any action: `Action` since, whose two parameters default to it. `Action<{ name: string }, string>` keeps its input and output types, and a `.with()` action crosses into an island as any other does. The old form works until 1.108. Found on the `Action` a file imports from `kay`, under any local name, in the TypeScript files and the fences of `.kay` files. The fix drops the type arguments.',
|
|
33
|
-
wrong: '---\nimport type { Action } from \'kay\'\n\nconst { run } = props<{ run: Action<never, unknown> }>()\n---\nform(action={run})\n button Go',
|
|
34
|
-
right: '---\nimport type { Action } from \'kay\'\n\nconst { run } = props<{ run: Action }>()\n---\nform(action={run})\n button Go',
|
|
35
|
-
},
|
|
36
|
-
'deprecated-action-readers': {
|
|
37
|
-
level: 'warn',
|
|
38
|
-
group: 'deprecated',
|
|
39
|
-
since: '1.105',
|
|
40
|
-
site: true,
|
|
41
|
-
summary: 'An action\'s `failed()`, `error(field)` and `validate(form, field)` before 1.105, which a form shows and now reads from `form`: `form.failed()`, `form.error(field)` and `form.validate(form, field)`, the call state (`pending()`, `status()`, `data()`) staying on the action. The old names work until 1.108. Found in the TypeScript files and `.kay` files of the project, templates included, on a name bound once to a call of `action` from `kay`, to the `.with()` of one, or imported in lowercase from a `.kay` file, as `kay check` reads no types: an action reached through a property or a prop is not found. The fix writes `form.` before the name.',
|
|
42
|
-
wrong: '---\nimport { add } from \'./notes.kay\'\n---\nform(action={add})\n input(name="title" aria-invalid={add.error(\'title\') ? \'true\' : undefined})\n if add.failed()\n p Not saved',
|
|
43
|
-
right: '---\nimport { add } from \'./notes.kay\'\n---\nform(action={add})\n input(name="title" aria-invalid={add.form.error(\'title\') ? \'true\' : undefined})\n if add.form.failed()\n p Not saved',
|
|
44
|
-
},
|
|
11
|
+
...ACTION_OPTIONS,
|
|
12
|
+
...SOURCE_READERS,
|
|
45
13
|
'deprecated-ui-props': {
|
|
46
14
|
level: 'warn',
|
|
47
15
|
group: 'deprecated',
|
|
@@ -66,23 +34,6 @@ export const DEPRECATED_LINTS = {
|
|
|
66
34
|
wrong: '---\nimport Card from \'./card.kay\'\n---\nCard(class={{ head: \'p-6\' }})',
|
|
67
35
|
right: '---\nimport Card from \'./card.kay\'\n---\nCard(parts={{ head: \'p-6\' }})',
|
|
68
36
|
},
|
|
69
|
-
'deprecated-script-fence': {
|
|
70
|
-
level: 'warn',
|
|
71
|
-
group: 'deprecated',
|
|
72
|
-
since: '1.102',
|
|
73
|
-
summary: '`--- script` as the first fence of a file, `---` since 1.102: the bare line opens the component script wherever no named fence comes before it, so one fence had two spellings. `--- script` stays for a script that follows a `--- server`, `--- module` or `--- style` fence, where a bare `---` would close that fence instead, and `--- client` still replaces `---` rather than modifying it. The old form still works. The fix drops the word, keeping the type parameters of `--- script <T>` as `--- <T>`.',
|
|
74
|
-
wrong: '--- script\nconst { title } = props<{ title: string }>()\n---\nh1 {title}',
|
|
75
|
-
right: '---\nconst { title } = props<{ title: string }>()\n---\nh1 {title}',
|
|
76
|
-
},
|
|
77
|
-
'deprecated-schema-type': {
|
|
78
|
-
level: 'warn',
|
|
79
|
-
group: 'deprecated',
|
|
80
|
-
since: '1.103',
|
|
81
|
-
site: true,
|
|
82
|
-
summary: '`TSchema` imported from `kay/library`, `Schema` since 1.103: kay\'s own name for what `s` builds and every schema option takes, so a signature of the app does not name TypeBox, whose type follows the Elysia kay is built on. The old name works until 1.106. Found on an import from `kay/library` in the TypeScript files and `.kay` files of the project. The fix renames the import and each use of it; a file that already has a `Schema` of its own is reported with no fix, and one that imports it aliased with only the import renamed.',
|
|
83
|
-
wrong: '---\nimport type { TSchema } from \'kay/library\'\n\nexport function check<Fields extends TSchema>(fields: Fields) {\n return fields\n}\n---\np x',
|
|
84
|
-
right: '---\nimport type { Schema } from \'kay/library\'\n\nexport function check<Fields extends Schema>(fields: Fields) {\n return fields\n}\n---\np x',
|
|
85
|
-
},
|
|
86
37
|
'deprecated-package-names': {
|
|
87
38
|
level: 'warn',
|
|
88
39
|
group: 'deprecated',
|
|
@@ -595,9 +546,10 @@ export const DEPRECATION_MINORS: readonly { since: string, removedIn?: string }[
|
|
|
595
546
|
{ since: '1.99', removedIn: '1.103' },
|
|
596
547
|
{ since: '1.100', removedIn: '1.104' },
|
|
597
548
|
{ since: '1.101', removedIn: '1.105' },
|
|
598
|
-
{ since: '1.102' },
|
|
599
|
-
{ since: '1.103' },
|
|
549
|
+
{ since: '1.102', removedIn: '1.107' },
|
|
550
|
+
{ since: '1.103', removedIn: '1.107' },
|
|
600
551
|
{ since: '1.104' },
|
|
601
552
|
{ since: '1.105' },
|
|
602
553
|
{ since: '1.106' },
|
|
554
|
+
{ since: '1.107' },
|
|
603
555
|
]
|
|
@@ -45,3 +45,18 @@ export function importEdits(file: KayFile, fence: Span | undefined, imports: rea
|
|
|
45
45
|
|
|
46
46
|
return edits
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
const COMMA_AFTER = /^\s*,\s*/
|
|
50
|
+
const COMMA_BEFORE = /,\s*$/
|
|
51
|
+
|
|
52
|
+
// An import specifier with the comma that separates it from its neighbour.
|
|
53
|
+
export function withoutComma(src: string, specifier: Span, declaration: Span): Span {
|
|
54
|
+
const after = COMMA_AFTER.exec(src.slice(specifier.end, declaration.end))
|
|
55
|
+
|
|
56
|
+
if (after)
|
|
57
|
+
return { start: specifier.start, end: specifier.end + after[0].length }
|
|
58
|
+
|
|
59
|
+
const before = COMMA_BEFORE.exec(src.slice(declaration.start, specifier.start))
|
|
60
|
+
|
|
61
|
+
return { start: specifier.start - (before?.[0].length ?? 0), end: specifier.end }
|
|
62
|
+
}
|
package/src/compiler/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { UiEntry } from '../runtime/ui'
|
|
|
3
3
|
import type { Attribute, Diagnostic, KayFile, Node, Span } from './ast'
|
|
4
4
|
import type { ErrorName } from './errors'
|
|
5
5
|
import type { IslandCause } from './island-cause'
|
|
6
|
+
import type { ImportedComponents } from './lazy-imports'
|
|
6
7
|
import type { LintLevels } from './lints'
|
|
7
8
|
import type { Expansion } from './markdown-block'
|
|
8
9
|
import type { ImportedSignals, SignalKind } from './module-signals'
|
|
@@ -19,13 +20,13 @@ import { deprecatedChildrenProp } from './deprecated-children'
|
|
|
19
20
|
import { deprecatedIslandAttributes, deprecatedIslandForms, islandProblems } from './deprecated-island'
|
|
20
21
|
import { deprecatedPageSettings } from './deprecated-page'
|
|
21
22
|
import { deprecatedPartsClass } from './deprecated-parts'
|
|
22
|
-
import { spelledOutScriptFence } from './deprecated-script-fence'
|
|
23
23
|
import { asyncReplies, cssImportsWithoutText, missingCaptchas, onceReadProps, separatePageSettings, serverOnlyImports, unboundedFields, unreturnedFails } from './fence-checks'
|
|
24
24
|
import { openRedirects } from './fence-redirects'
|
|
25
25
|
import { cwd, scopeStorage } from './host'
|
|
26
26
|
import { ignoredIslandExport, interactiveProps, islandMessages, malformedInteractive, withAlertKeys } from './island-arguments'
|
|
27
27
|
import { describeCause } from './island-cause'
|
|
28
28
|
import { markerMismatch } from './island-marker'
|
|
29
|
+
import { lazyImportsOf } from './lazy-imports'
|
|
29
30
|
import { linkFlags } from './link-flags'
|
|
30
31
|
import { applyLints, templateLints } from './lints'
|
|
31
32
|
import { SourceMap } from './mapping'
|
|
@@ -96,6 +97,8 @@ export interface CompileOptions {
|
|
|
96
97
|
insideIsland?: boolean | undefined
|
|
97
98
|
// The signals and memos of the modules the component imports, which it writes by assigning and the check reports read uncalled: `importedSignals` from kay's build finds them.
|
|
98
99
|
importedSignals?: ImportedSignals | undefined
|
|
100
|
+
// The `.kay` modules the component imports that a template draws only where a branch may not render, which then load on their own the first time they draw: found by kay's build, which names the chunk of each.
|
|
101
|
+
components?: ImportedComponents | undefined
|
|
99
102
|
// The browser's build only: the classes a later Tailwind class overrides, with which literal classes written together resolve while compiling.
|
|
100
103
|
classTable?: ClassTable | undefined
|
|
101
104
|
// The server's build of an app with Tailwind: a shorthand beside a static `class` merges while rendering.
|
|
@@ -325,9 +328,11 @@ export function compileKay(original: string, filename: string, options: CompileO
|
|
|
325
328
|
const hydratableServer = options.output === 'html' && options.hydratable === true
|
|
326
329
|
const twin = hydratableServer && !options.twinBuild && island === undefined && !routeFile ? `./${basename(filename)}${ISLAND_TWIN}` : undefined
|
|
327
330
|
const pin = file.pin
|
|
331
|
+
const hydrated = hydratableServer && (island !== undefined || options.twinBuild === true)
|
|
332
|
+
const lazy = lazyImportsOf(file, script.imports, options, hydrated, routeFile, client)
|
|
328
333
|
const rawCause = island === undefined ? undefined : islandCause(file, script) ?? browserCause(file, script, live)
|
|
329
334
|
const cause = withInteractive(realCause(rawCause, expansion, original), script)
|
|
330
|
-
const generateOptions = { cause: options.inspect === true && cause !== undefined ? describeCause(cause) : undefined, classTable: options.classTable, classMerge: options.classMerge, awaitAlert: options.awaitAlert, island, client, lives: island === undefined ? undefined : liveBindings(script, options.importedSignals).map(binding => binding.local), twin, writtenProps: options.writtenProps, output: options.output, failedCode, hydratable:
|
|
335
|
+
const generateOptions = { cause: options.inspect === true && cause !== undefined ? describeCause(cause) : undefined, classTable: options.classTable, classMerge: options.classMerge, awaitAlert: options.awaitAlert, island, client, lives: island === undefined ? undefined : liveBindings(script, options.importedSignals).map(binding => binding.local), twin, writtenProps: options.writtenProps, output: options.output, failedCode, hydratable: hydrated, moduleId: islandId(filename, options.root), includeServer: options.includeServer, params: options.params, paramTypes: options.paramTypes, outerQueries: options.outerQueries, outerGuards: options.outerGuards, outerSlots: options.outerSlots, layoutFile: basename(filename) === LAYOUT, component: options.page === false && !routeFile, check: options.check, route: options.check === true && pageFile, pageFile, namedRefresh: options.namedRefresh, insideIsland: options.insideIsland, inspect: options.inspect, inspectSource: expansion ? { text: original, real: (offset: number) => expansion.real(offset) } : undefined, relocateImport: options.relocateImport, lazy, contextModule: options.check === true ? options.contextModule : undefined, ui: options.output === undefined ? undefined : options.ui, uiAdded: options.output === undefined ? options.ui : undefined, errorPage: isErrorPage(basename(filename)), cardPage: basename(filename) === CARD_PAGE, special: basename(filename).startsWith('_') && basename(filename) !== LAYOUT }
|
|
331
336
|
// The analysis pass names the component so no read resolves to it, then the name is chosen free of what the code reads.
|
|
332
337
|
const analysis = generate(file, script, server, { ...generateOptions, name: SELF })
|
|
333
338
|
const imported = new Map<string, SignalKind>([...script.imports, ...server?.imports ?? []].flatMap((binding) => {
|
|
@@ -379,7 +384,7 @@ export function compileKay(original: string, filename: string, options: CompileO
|
|
|
379
384
|
const browserScript = (island !== undefined || options.insideIsland === true) && !routeFile ? scriptFences(script) : []
|
|
380
385
|
const unusedLints = broken ? [] : [...unreadNames(source, file.template, script, server, found.findings), ...constantSignals(source, [file.script, file.module], found.findings)]
|
|
381
386
|
|
|
382
|
-
diagnostics.push(...unboundedFields(server), ...fenceLints, ...serialAwaits(server), ...browserScript.flatMap(fence => serverOnlyImports(fence)), ...browserScript.includes(script.fence!) ? onceReadProps(script.fence!, script.props, templateWords(file)) : [], ...unusedLints, ...templateLints(file), ...
|
|
387
|
+
diagnostics.push(...unboundedFields(server), ...fenceLints, ...serialAwaits(server), ...browserScript.flatMap(fence => serverOnlyImports(fence)), ...browserScript.includes(script.fence!) ? onceReadProps(script.fence!, script.props, templateWords(file)) : [], ...unusedLints, ...templateLints(file), ...retiredAllowComments(source), ...deprecatedIslandForms(file, script), ...deprecatedIslandAttributes(file), ...deprecatedChildrenProp(file, script), ...linkFlags(file), ...deprecatedPartsClass(file), ...deprecatedPageSettings(source, server), ...ignoredIslandExport(script, island !== undefined), ...malformedInteractive(script))
|
|
383
388
|
}
|
|
384
389
|
|
|
385
390
|
if (checked && pin !== undefined)
|