@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.
Files changed (222) hide show
  1. package/README.md +2 -2
  2. package/dist/eslint.js +428 -176
  3. package/editors/zed/extension.toml +2 -2
  4. package/llms/action-protection.md +1 -1
  5. package/llms/actions-refused-fields.md +22 -0
  6. package/llms/actions.md +2 -22
  7. package/llms/browser-only.md +1 -1
  8. package/llms/compiler-api.md +1 -1
  9. package/llms/components.md +1 -1
  10. package/llms/deprecated-lints.md +2 -3
  11. package/llms/island-and-form-lints.md +1 -0
  12. package/llms/islands.md +10 -1
  13. package/llms/project-new-and-add.md +1 -1
  14. package/llms/project.md +2 -2
  15. package/llms/schemas.md +6 -4
  16. package/llms/upgrading.md +19 -1
  17. package/llms/whats-new.md +14 -1
  18. package/package.json +15 -6
  19. package/src/build/client.ts +20 -24
  20. package/src/build/entry-files.ts +19 -0
  21. package/src/build/lazy-components.ts +130 -0
  22. package/src/build/lazy-manifest.ts +56 -0
  23. package/src/build/lazy-stubs.ts +31 -0
  24. package/src/build/plugin.ts +3 -1
  25. package/src/build/runtime-chunk.ts +1 -1
  26. package/src/build/transform.ts +17 -7
  27. package/src/build/variants.ts +7 -4
  28. package/src/check/action-options.ts +56 -0
  29. package/src/check/schema-json.ts +226 -0
  30. package/src/check/shadow-types.ts +11 -9
  31. package/src/compiler/codegen.ts +7 -17
  32. package/src/compiler/deprecated-lints-1-105.ts +41 -0
  33. package/src/compiler/deprecated-lints-1-106.ts +1 -1
  34. package/src/compiler/deprecated-lints-1-107.ts +14 -0
  35. package/src/compiler/deprecated-lints.ts +7 -55
  36. package/src/compiler/import-edits.ts +15 -0
  37. package/src/compiler/index.ts +8 -3
  38. package/src/compiler/island-declaration.ts +15 -0
  39. package/src/compiler/kay-exports.ts +1 -0
  40. package/src/compiler/lazy-imports.ts +357 -0
  41. package/src/compiler/parser.ts +2 -2
  42. package/src/compiler/route-lints.ts +2 -0
  43. package/src/compiler/schema-lints.ts +13 -0
  44. package/src/compiler/script-server.ts +6 -3
  45. package/src/content/validate.ts +1 -1
  46. package/src/new.ts +6 -2
  47. package/src/runtime/action.ts +47 -4
  48. package/src/runtime/client.ts +10 -0
  49. package/src/runtime/dom-lazy.ts +276 -0
  50. package/src/runtime/field-errors.ts +58 -0
  51. package/src/runtime/field-refusal.ts +179 -0
  52. package/src/runtime/form.ts +3 -2
  53. package/src/runtime/html.ts +6 -1
  54. package/src/runtime/index.ts +2 -0
  55. package/src/runtime/island.server.ts +36 -2
  56. package/src/runtime/schema-record.ts +2 -1
  57. package/src/runtime/schema.client.ts +104 -14
  58. package/src/runtime/schema.ts +9 -2
  59. package/src/runtime/standard-schema.ts +32 -0
  60. package/src/runtime/validate-run.client.ts +179 -0
  61. package/src/runtime/validate.client.ts +11 -0
  62. package/src/runtime/validate.ts +4 -137
  63. package/src/server/actions.ts +48 -43
  64. package/src/server/answer.ts +102 -0
  65. package/src/server/api-input.ts +166 -0
  66. package/src/server/api.ts +12 -44
  67. package/src/server/app-stages.ts +15 -8
  68. package/src/server/app.ts +5 -2
  69. package/src/server/client.ts +2 -0
  70. package/src/server/dev.ts +7 -9
  71. package/src/server/file-limit.ts +7 -1
  72. package/src/server/forms.ts +1 -1
  73. package/src/server/host-allowlist.ts +7 -7
  74. package/src/server/index.ts +2 -0
  75. package/src/server/kay-routes.ts +221 -0
  76. package/src/server/kay-server.ts +228 -0
  77. package/src/server/kept-exports.ts +1 -0
  78. package/src/server/library.ts +0 -2
  79. package/src/server/mcp.ts +1 -1
  80. package/src/server/openapi.ts +12 -3
  81. package/src/server/phases.ts +249 -0
  82. package/src/server/protection.ts +6 -6
  83. package/src/server/proxy-key.ts +8 -8
  84. package/src/server/query.ts +4 -25
  85. package/src/server/receive.ts +43 -0
  86. package/src/server/render-document.ts +13 -3
  87. package/src/server/request-context.ts +137 -0
  88. package/src/server/schema-check.ts +1 -1
  89. package/src/server/socket.ts +19 -47
  90. package/src/server/stream.ts +1 -1
  91. package/src/server/validate.ts +346 -0
  92. package/src/test/mount.ts +6 -2
  93. package/types/build/client.d.ts +3 -2
  94. package/types/build/client.d.ts.map +1 -1
  95. package/types/build/entry-files.d.ts +4 -0
  96. package/types/build/entry-files.d.ts.map +1 -0
  97. package/types/build/lazy-components.d.ts +6 -0
  98. package/types/build/lazy-components.d.ts.map +1 -0
  99. package/types/build/lazy-manifest.d.ts +19 -0
  100. package/types/build/lazy-manifest.d.ts.map +1 -0
  101. package/types/build/lazy-stubs.d.ts +5 -0
  102. package/types/build/lazy-stubs.d.ts.map +1 -0
  103. package/types/build/plugin.d.ts +1 -0
  104. package/types/build/plugin.d.ts.map +1 -1
  105. package/types/build/transform.d.ts +3 -1
  106. package/types/build/transform.d.ts.map +1 -1
  107. package/types/build/variants.d.ts.map +1 -1
  108. package/types/check/action-options.d.ts +3 -0
  109. package/types/check/action-options.d.ts.map +1 -0
  110. package/types/check/schema-json.d.ts +3 -0
  111. package/types/check/schema-json.d.ts.map +1 -0
  112. package/types/check/shadow-types.d.ts.map +1 -1
  113. package/types/compiler/codegen.d.ts +2 -0
  114. package/types/compiler/codegen.d.ts.map +1 -1
  115. package/types/compiler/deprecated-lints-1-105.d.ts +39 -0
  116. package/types/compiler/deprecated-lints-1-105.d.ts.map +1 -0
  117. package/types/compiler/deprecated-lints-1-106.d.ts +1 -1
  118. package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
  119. package/types/compiler/deprecated-lints-1-107.d.ts +12 -0
  120. package/types/compiler/deprecated-lints-1-107.d.ts.map +1 -0
  121. package/types/compiler/deprecated-lints.d.ts +36 -44
  122. package/types/compiler/deprecated-lints.d.ts.map +1 -1
  123. package/types/compiler/import-edits.d.ts +1 -0
  124. package/types/compiler/import-edits.d.ts.map +1 -1
  125. package/types/compiler/index.d.ts +2 -0
  126. package/types/compiler/index.d.ts.map +1 -1
  127. package/types/compiler/island-declaration.d.ts +5 -0
  128. package/types/compiler/island-declaration.d.ts.map +1 -1
  129. package/types/compiler/kay-exports.d.ts.map +1 -1
  130. package/types/compiler/lazy-imports.d.ts +33 -0
  131. package/types/compiler/lazy-imports.d.ts.map +1 -0
  132. package/types/compiler/lints.d.ts +44 -44
  133. package/types/compiler/route-lints.d.ts +8 -0
  134. package/types/compiler/route-lints.d.ts.map +1 -1
  135. package/types/compiler/schema-lints.d.ts +11 -0
  136. package/types/compiler/schema-lints.d.ts.map +1 -0
  137. package/types/compiler/script-server.d.ts.map +1 -1
  138. package/types/new.d.ts +1 -0
  139. package/types/new.d.ts.map +1 -1
  140. package/types/runtime/action.d.ts +26 -1
  141. package/types/runtime/action.d.ts.map +1 -1
  142. package/types/runtime/client.d.ts.map +1 -1
  143. package/types/runtime/dom-lazy.d.ts +6 -0
  144. package/types/runtime/dom-lazy.d.ts.map +1 -0
  145. package/types/runtime/field-errors.d.ts +4 -0
  146. package/types/runtime/field-errors.d.ts.map +1 -0
  147. package/types/runtime/field-refusal.d.ts +37 -0
  148. package/types/runtime/field-refusal.d.ts.map +1 -0
  149. package/types/runtime/form.d.ts +1 -1
  150. package/types/runtime/form.d.ts.map +1 -1
  151. package/types/runtime/html.d.ts.map +1 -1
  152. package/types/runtime/index.d.ts +2 -0
  153. package/types/runtime/index.d.ts.map +1 -1
  154. package/types/runtime/island.server.d.ts +2 -0
  155. package/types/runtime/island.server.d.ts.map +1 -1
  156. package/types/runtime/schema-record.d.ts.map +1 -1
  157. package/types/runtime/schema.client.d.ts.map +1 -1
  158. package/types/runtime/schema.d.ts +6 -1
  159. package/types/runtime/schema.d.ts.map +1 -1
  160. package/types/runtime/standard-schema.d.ts +37 -0
  161. package/types/runtime/standard-schema.d.ts.map +1 -0
  162. package/types/runtime/validate-run.client.d.ts +4 -0
  163. package/types/runtime/validate-run.client.d.ts.map +1 -0
  164. package/types/runtime/validate.client.d.ts +4 -0
  165. package/types/runtime/validate.client.d.ts.map +1 -0
  166. package/types/runtime/validate.d.ts +1 -21
  167. package/types/runtime/validate.d.ts.map +1 -1
  168. package/types/server/actions.d.ts.map +1 -1
  169. package/types/server/answer.d.ts +6 -0
  170. package/types/server/answer.d.ts.map +1 -0
  171. package/types/server/api-input.d.ts +19 -0
  172. package/types/server/api-input.d.ts.map +1 -0
  173. package/types/server/api.d.ts.map +1 -1
  174. package/types/server/app-stages.d.ts +4 -1
  175. package/types/server/app-stages.d.ts.map +1 -1
  176. package/types/server/app.d.ts +2 -0
  177. package/types/server/app.d.ts.map +1 -1
  178. package/types/server/client.d.ts +1 -0
  179. package/types/server/client.d.ts.map +1 -1
  180. package/types/server/dev.d.ts +1 -1
  181. package/types/server/dev.d.ts.map +1 -1
  182. package/types/server/file-limit.d.ts.map +1 -1
  183. package/types/server/host-allowlist.d.ts +3 -3
  184. package/types/server/host-allowlist.d.ts.map +1 -1
  185. package/types/server/index.d.ts +2 -0
  186. package/types/server/index.d.ts.map +1 -1
  187. package/types/server/kay-routes.d.ts +47 -0
  188. package/types/server/kay-routes.d.ts.map +1 -0
  189. package/types/server/kay-server.d.ts +25 -0
  190. package/types/server/kay-server.d.ts.map +1 -0
  191. package/types/server/kept-exports.d.ts.map +1 -1
  192. package/types/server/library.d.ts +0 -1
  193. package/types/server/library.d.ts.map +1 -1
  194. package/types/server/openapi.d.ts.map +1 -1
  195. package/types/server/phases.d.ts +36 -0
  196. package/types/server/phases.d.ts.map +1 -0
  197. package/types/server/protection.d.ts +3 -2
  198. package/types/server/protection.d.ts.map +1 -1
  199. package/types/server/proxy-key.d.ts +3 -3
  200. package/types/server/proxy-key.d.ts.map +1 -1
  201. package/types/server/query.d.ts.map +1 -1
  202. package/types/server/receive.d.ts +9 -0
  203. package/types/server/receive.d.ts.map +1 -0
  204. package/types/server/render-document.d.ts.map +1 -1
  205. package/types/server/request-context.d.ts +29 -0
  206. package/types/server/request-context.d.ts.map +1 -0
  207. package/types/server/schema-check.d.ts +1 -0
  208. package/types/server/schema-check.d.ts.map +1 -1
  209. package/types/server/socket.d.ts +3 -5
  210. package/types/server/socket.d.ts.map +1 -1
  211. package/types/server/validate.d.ts +26 -0
  212. package/types/server/validate.d.ts.map +1 -0
  213. package/types/test/mount.d.ts.map +1 -1
  214. package/src/check/schema-type.ts +0 -9
  215. package/src/compiler/deprecated-script-fence.ts +0 -26
  216. package/src/server/field-errors.ts +0 -136
  217. package/types/check/schema-type.d.ts +0 -3
  218. package/types/check/schema-type.d.ts.map +0 -1
  219. package/types/compiler/deprecated-script-fence.d.ts +0 -3
  220. package/types/compiler/deprecated-script-fence.d.ts.map +0 -1
  221. package/types/server/field-errors.d.ts +0 -6
  222. package/types/server/field-errors.d.ts.map +0 -1
@@ -179,3 +179,18 @@ export function rolesOf(source: string, script: Span | undefined, fence: Span &
179
179
 
180
180
  return island.render === 'client' ? { island, client: island.span, pin: undefined } : { island, client: undefined, pin: { kind: island.render, ...island.span } }
181
181
  }
182
+
183
+ // `--- script` opening a file: the bare `---` is the same fence, and only a script that follows a named fence needs the word, as there a bare line would close that one.
184
+ export function spelledOutFirstFence(source: string, line: Span | undefined, word: { start: number, end: number, word: string } | undefined): Diagnostic[] {
185
+ if (!line || word?.word !== 'script' || source.slice(0, line.start).trim() !== '')
186
+ return []
187
+
188
+ return [{
189
+ start: line.start,
190
+ end: word.end,
191
+ code: 'fence-invalid',
192
+ message: '`--- script` cannot open a file: the script is written `---`',
193
+ help: '`--- script` is only for a script that follows a `--- server`, `--- module` or `--- style` fence',
194
+ fixes: [{ title: 'Write `---`', safe: true, edits: [{ start: line.start + 3, end: word.end, text: '' }] }],
195
+ }]
196
+ }
@@ -91,6 +91,7 @@ export const KAY_ROLES: Readonly<Record<string, KayRole>> = {
91
91
  trustHtml: 'shared',
92
92
  uid: 'shared',
93
93
  untrack: 'browser',
94
+ validate: 'shared',
94
95
  watch: 'browser',
95
96
  webPush: 'browser',
96
97
  withBase: 'shared',
@@ -0,0 +1,357 @@
1
+ import type { ElementNode, KayFile, Node, Span } from './ast'
2
+ import type { ImportBinding } from './script-shared'
3
+ import { serverIslandOf, visitNodes } from './ast'
4
+ import { helperName } from './markup'
5
+
6
+ // What the build knows of a `.kay` module a component imports: the key its chunk is named by, and the props it draws only inside a branch that may not render, as a closed dialog does its children.
7
+ export interface ImportedComponent {
8
+ key: string
9
+ // `children` for the lines between its tags, else the name of a `@block`.
10
+ deferred: readonly string[]
11
+ // The size of its source, as a component under `LAZY_FLOOR` costs more as a chunk than it weighs.
12
+ size: number
13
+ // The keys of the components loaded with it: its own, and those its imports draw outside any branch that may not render, which a module importing it already holds.
14
+ reach: readonly string[]
15
+ }
16
+
17
+ // The imported components of a file, by the specifier it imports them with.
18
+ export type ImportedComponents = Readonly<Record<string, ImportedComponent>>
19
+
20
+ // A component loaded the first time it draws, with the key that names its chunk.
21
+ export interface LazyImport {
22
+ key: string
23
+ specifier: string
24
+ declaration: { start: number, end: number }
25
+ }
26
+
27
+ // The smallest source a component loads lazily: below it the request and the stub cost more than the code saves.
28
+ export const LAZY_FLOOR = 2000
29
+ const CHILDREN = 'children'
30
+ const LINE_COMMENT = /^[ \t]*\/\/.*$/
31
+ const PLAIN_STRING = /'(?:[^'\\\n$`]|\\.)*'|"(?:[^"\\\n$`]|\\.)*"/g
32
+ // A line where a quote may open something other than a string: a template literal, or a regular expression, which starts where a value is expected.
33
+ const UNSURE_LINE = /`|[(,=:?!&|{;[]\s*\/(?![/*])/
34
+ // An import of a component's default export on a line of its own, the one form a lazy import can replace.
35
+ const PLAIN_IMPORT = /^import\s+[\w$]+\s+from\s*(['"])[^'"]+\1\s*;?$/
36
+
37
+ // How often a name is written as a word of the text, as `codeOf` leaves it: a count the tag uses do not account for is another reference to it.
38
+ function occurrences(text: string, name: string): number {
39
+ return text.match(new RegExp(`(?<![\\w$.])${name.replaceAll('$', '\\$')}(?![\\w$])`, 'g'))?.length ?? 0
40
+ }
41
+
42
+ // Whether the script names a prop other than as a string or a type's optional member, as `Omit<Props, 'children'>` or `children?: Snippet` do: any other mention may read it.
43
+ function reads(code: string, name: string): boolean {
44
+ return new RegExp(`(?<![\\w$'"])${name}(?![\\w$'"])(?!\\?:)`).test(code)
45
+ }
46
+
47
+ // Walks a template noting where each component call and each `slot` stands: in a branch that may not render (an `if` or `match` branch, a `catch`) or in a block a component draws only inside such a branch, which is `deferred`. The lines of a `snippet` stay where they are written, as it is drawn where it is called.
48
+ class Positions {
49
+ // How many repeated blocks, a loop body or a block of a function of a row, enclose the node being walked: a branch inside one is drawn by most pages, so it is no reason to split a component off.
50
+ private repeating = 0
51
+
52
+ constructor(private readonly source: string, private readonly deferring: (element: ElementNode) => readonly string[], private visit: { use?: (element: ElementNode, deferred: boolean) => void, outlet?: (element: ElementNode, deferred: boolean) => void }) {}
53
+
54
+ // An `if` with an `else` or a `match` with a default always draws one of its branches: a name written in each of them is drawn at first paint, one missing from some may not be.
55
+ private exhaustive(branches: readonly (readonly Node[])[], deferred: boolean): void {
56
+ const real = this.visit
57
+ const calls = branches.map((children) => {
58
+ const seen: { name: string, element: ElementNode, deferred: boolean, outlet: boolean }[] = []
59
+
60
+ this.visit = {
61
+ use: (element, inner) => seen.push({ name: element.name, element, deferred: inner, outlet: false }),
62
+ outlet: (element, inner) => seen.push({ name: element.outlet ? this.source.slice(element.outlet.name.start, element.outlet.name.end) : CHILDREN, element, deferred: inner, outlet: true }),
63
+ }
64
+ this.walk(children, deferred)
65
+
66
+ return seen
67
+ })
68
+
69
+ this.visit = real
70
+
71
+ const keyOf = (call: { name: string, outlet: boolean }) => `${call.outlet}:${call.name}`
72
+ const everywhere = calls.map(seen => new Set(seen.map(keyOf)))
73
+
74
+ for (const call of calls.flat()) {
75
+ const always = everywhere.every(names => names.has(keyOf(call)))
76
+
77
+ if (call.outlet)
78
+ real.outlet?.(call.element, call.deferred || (!always && this.repeating === 0))
79
+ else
80
+ real.use?.(call.element, call.deferred || (!always && this.repeating === 0))
81
+ }
82
+ }
83
+
84
+ walk(nodes: readonly Node[], deferred: boolean): void {
85
+ for (const node of nodes) {
86
+ switch (node.kind) {
87
+ case 'element':
88
+ this.element(node, deferred)
89
+
90
+ break
91
+ case 'if':
92
+ if (node.fallback) {
93
+ this.exhaustive([...node.branches.map(branch => branch.children), node.fallback.children], deferred)
94
+
95
+ break
96
+ }
97
+
98
+ for (const branch of node.branches)
99
+ this.walk(branch.children, deferred || this.repeating === 0)
100
+
101
+ break
102
+ case 'match':
103
+ if (node.fallback) {
104
+ this.exhaustive([...node.cases.map(branch => branch.children), node.fallback.children], deferred)
105
+
106
+ break
107
+ }
108
+
109
+ for (const branch of node.cases)
110
+ this.walk(branch.children, deferred || this.repeating === 0)
111
+
112
+ break
113
+ case 'for':
114
+ this.repeating++
115
+ this.walk(node.children, deferred)
116
+ this.repeating--
117
+ this.walk(node.fallback ?? [], deferred)
118
+
119
+ break
120
+ case 'await':
121
+ this.walk(node.pending, deferred)
122
+ this.walk(node.resolved?.children ?? [], deferred)
123
+ this.walk(node.rejected?.children ?? [], true)
124
+
125
+ break
126
+ case 'try':
127
+ this.walk(node.children, deferred)
128
+ this.walk(node.rejected?.children ?? [], true)
129
+
130
+ break
131
+ case 'text':
132
+ this.walk(node.parts.filter(part => part.kind === 'element'), deferred)
133
+
134
+ break
135
+ case 'slot':
136
+ case 'snippet':
137
+ case 'pending':
138
+ this.walk(node.children, deferred)
139
+
140
+ break
141
+ case 'const':
142
+ case 'error':
143
+ break
144
+ }
145
+ }
146
+ }
147
+
148
+ private element(element: ElementNode, deferred: boolean): void {
149
+ if (element.component)
150
+ this.visit.use?.(element, deferred)
151
+ else if (element.name === 'slot')
152
+ this.visit.outlet?.(element, deferred)
153
+
154
+ const props = element.component ? this.deferring(element) : []
155
+
156
+ for (const child of element.children) {
157
+ const own = child.kind === 'slot' ? this.source.slice(child.name.start, child.name.end) : CHILDREN
158
+
159
+ const repeated = child.kind === 'slot' && child.params !== undefined
160
+
161
+ this.repeating += repeated ? 1 : 0
162
+ this.walk(child.kind === 'slot' ? child.children : [child], deferred || props.includes(own))
163
+ this.repeating -= repeated ? 1 : 0
164
+ }
165
+ }
166
+ }
167
+
168
+ // The file with the text and the quoted attribute values of its template blanked, so what is left is code: a word naming a component is no reference when it is only written in a sentence.
169
+ function codeOf(file: KayFile): string {
170
+ const blanks: Span[] = []
171
+
172
+ visitNodes(file.template, (node) => {
173
+ if (node.kind === 'text')
174
+ blanks.push(...node.parts.filter(part => part.kind === 'chunk'))
175
+ else if (node.kind === 'element')
176
+ blanks.push(...node.attributes.flatMap(attribute => attribute.kind === 'static' ? [attribute.value] : []))
177
+ })
178
+
179
+ let code = file.source
180
+
181
+ for (const { start, end } of blanks)
182
+ code = `${code.slice(0, start)}${' '.repeat(end - start)}${code.slice(end)}`
183
+
184
+ return blankLiterals(code)
185
+ }
186
+
187
+ // The whole-line comments and the one-line strings that hold no `${`, blanked: a word in them, as the `Select all` of a label, is text no code reads, so it is no reference to a component of that name. A line that may hold a template literal or a regular expression is left as it is, since a quote there may pair with another that is no string's, and a word hidden by mistake would load a component lazily that code reads.
188
+ function blankLiterals(code: string): string {
189
+ const blank = (text: string) => ' '.repeat(text.length)
190
+
191
+ return code.split('\n').map((line) => {
192
+ if (LINE_COMMENT.test(line))
193
+ return blank(line)
194
+
195
+ return UNSURE_LINE.test(line) ? line : line.replace(PLAIN_STRING, blank)
196
+ }).join('\n')
197
+ }
198
+
199
+ // The text before a file's template, which is all of its script.
200
+ function fences(file: KayFile): string {
201
+ return file.source.slice(0, file.templateStart)
202
+ }
203
+
204
+ // The props of a component it draws only where some of its own branches may not render, so what a use hands it for them is not drawn when they do not.
205
+ // A name its script mentions is left out, as it may read the prop itself.
206
+ export function deferredProps(file: KayFile, imports: readonly ImportBinding[], known: (specifier: string) => ImportedComponent | undefined): string[] {
207
+ const specifiers = new Map(imports.filter(binding => binding.imported === 'default' && !binding.typeOnly).map(binding => [binding.local, binding.source]))
208
+ const drawn = new Map<string, boolean>()
209
+ const code = fences(file)
210
+
211
+ new Positions(file.source, (element) => {
212
+ const specifier = specifiers.get(element.name)
213
+
214
+ return specifier === undefined ? [] : known(specifier)?.deferred ?? []
215
+ }, {
216
+ outlet(element, deferred) {
217
+ const name = element.outlet ? file.source.slice(element.outlet.name.start, element.outlet.name.end) : CHILDREN
218
+
219
+ drawn.set(name, (drawn.get(name) ?? true) && deferred)
220
+ },
221
+ }).walk(file.template, false)
222
+
223
+ return [...drawn].filter(([name, deferred]) => deferred && !reads(code, name)).map(([name]) => name)
224
+ }
225
+
226
+ // The default imports of a component's script that draw only in branches that may not render, so their code loads when one does.
227
+ // An import is left alone when anything but a tag names it, as its value is then read at once, and when a call of it is a server island or a dynamic tag.
228
+ export function lazyImports(file: KayFile, imports: readonly ImportBinding[], known: ImportedComponents): Map<string, LazyImport> {
229
+ const found = positionsLazy(file, imports, known)
230
+
231
+ // A component another import of the file brings along as it loads is no chunk worth a request: dropping one adds what it brings, so the check goes on until nothing changes.
232
+ for (let changed = found.size > 0; changed;) {
233
+ const held = new Set(eagerReach(imports, known, found))
234
+
235
+ changed = false
236
+
237
+ for (const [local, lazy] of found) {
238
+ if (held.has(lazy.key)) {
239
+ found.delete(local)
240
+ changed = true
241
+ }
242
+ }
243
+ }
244
+
245
+ return found
246
+ }
247
+
248
+ // The keys the file loads as it loads: those of the components it imports other than lazily, and what each of them brings.
249
+ export function eagerReach(imports: readonly ImportBinding[], known: ImportedComponents, lazy: ReadonlyMap<string, LazyImport>): string[] {
250
+ const reach = new Set<string>()
251
+
252
+ for (const binding of imports) {
253
+ const component = binding.imported === 'default' && !binding.typeOnly ? known[binding.source] : undefined
254
+
255
+ if (component && !lazy.has(binding.local)) {
256
+ reach.add(component.key)
257
+
258
+ for (const key of component.reach)
259
+ reach.add(key)
260
+ }
261
+ }
262
+
263
+ return [...reach]
264
+ }
265
+
266
+ function positionsLazy(file: KayFile, imports: readonly ImportBinding[], known: ImportedComponents): Map<string, LazyImport> {
267
+ const candidates = new Map<string, { binding: ImportBinding, uses: boolean[] }>()
268
+ const specifiers = new Map<string, string>()
269
+
270
+ for (const binding of imports) {
271
+ if (binding.imported !== 'default' || binding.typeOnly)
272
+ continue
273
+
274
+ specifiers.set(binding.local, binding.source)
275
+
276
+ const declared = file.source.slice(binding.declaration.start, binding.declaration.end)
277
+
278
+ if ((known[binding.source]?.size ?? 0) >= LAZY_FLOOR && PLAIN_IMPORT.test(declared))
279
+ candidates.set(binding.local, { binding, uses: [] })
280
+ }
281
+
282
+ if (candidates.size === 0)
283
+ return new Map()
284
+
285
+ const refused = new Set<string>()
286
+
287
+ new Positions(file.source, (element) => {
288
+ const specifier = specifiers.get(element.name)
289
+
290
+ return specifier === undefined ? [] : known[specifier]?.deferred ?? []
291
+ }, {
292
+ use(element, deferred) {
293
+ const candidate = candidates.get(element.name)
294
+
295
+ if (!candidate)
296
+ return
297
+
298
+ candidate.uses.push(deferred)
299
+
300
+ if (serverIslandOf(element, file.source) !== undefined)
301
+ refused.add(element.name)
302
+ },
303
+ }).walk(file.template, false)
304
+
305
+ const code = codeOf(file)
306
+ const found = new Map<string, LazyImport>()
307
+
308
+ for (const [local, { binding, uses }] of candidates) {
309
+ const written = occurrences(code, local) - 1
310
+
311
+ if (uses.length === 0 || !uses.every(Boolean) || refused.has(local) || written !== uses.length)
312
+ continue
313
+
314
+ found.set(local, { key: known[binding.source]!.key, specifier: binding.source, declaration: binding.declaration })
315
+ }
316
+
317
+ return found
318
+ }
319
+
320
+ // Whether the file's output holds lazy imports: the browser's, and the server's render of an island or of a twin, which tells the island what it drew.
321
+ export function lazyImportsOf(file: KayFile, imports: readonly ImportBinding[], options: { components?: ImportedComponents | undefined, output?: string | undefined }, hydrated: boolean, routeFile: boolean, clientOnly: boolean): ReadonlyMap<string, LazyImport> | undefined {
322
+ return options.components !== undefined && !(routeFile || clientOnly) && (options.output === 'dom' || hydrated) ? lazyImports(file, imports, options.components) : undefined
323
+ }
324
+
325
+ // The import the server's output adds for a lazy import: what tells the island its code is wanted.
326
+ export function lazyNoteImport(lazy: ReadonlyMap<string, LazyImport> | undefined, mode: string): string {
327
+ return mode === 'html' && (lazy?.size ?? 0) > 0 ? `import { lazyNote as ${helperName('lazyNote')} } from 'kay/island'\n` : ''
328
+ }
329
+
330
+ // The import of the lazy runtime, only in a module that has lazy imports: a module naming it without using it still joins the chunks of every module that does, whatever the bundle drops after.
331
+ export function lazyDomImport(lazy: ReadonlyMap<string, LazyImport> | undefined): string {
332
+ return (lazy?.size ?? 0) > 0 ? `import { lazy as ${helperName('lazy')}, ready as ${helperName('ready')} } from 'kay/dom-lazy'\n` : ''
333
+ }
334
+
335
+ // The edits rewriting the lazy imports among a hoisted statement's `imports`: the browser's code asks for the module when the component first draws, the server's draws it as it always did and notes its key.
336
+ export function lazyEdits(imports: readonly ImportBinding[], span: Span, lazy: ReadonlyMap<string, LazyImport> | undefined, mode: string, moduleId: string | undefined): { start: number, end: number, text: string }[] {
337
+ if (mode !== 'dom' && mode !== 'html')
338
+ return []
339
+
340
+ const last = Math.max(-1, ...[...lazy?.values() ?? []].map(other => other.declaration.start))
341
+
342
+ return imports.flatMap((binding) => {
343
+ const found = lazy?.get(binding.local)
344
+
345
+ if (!found || binding.declaration.start < span.start || binding.declaration.end > span.end)
346
+ return []
347
+
348
+ const key = JSON.stringify(found.key)
349
+ const specifier = JSON.stringify(found.specifier)
350
+ const eager = `${helperName('lazy')}_${binding.local}`
351
+
352
+ // The module says which keys it imports lazily, once, after the last, so every key is registered by then.
353
+ const ready = found.declaration.start === last ? `\n${helperName('ready')}(${JSON.stringify(moduleId)}, ${JSON.stringify([...lazy?.values() ?? []].map(other => other.key))})` : ''
354
+
355
+ return [{ ...found.declaration, text: mode === 'dom' ? `const ${binding.local} = ${helperName('lazy')}(${key}, () => import(${specifier}))${ready}` : `import ${eager} from ${specifier}\nconst ${binding.local} = ${helperName('lazyNote')}(${key}, () => ${eager})` }]
356
+ })
357
+ }
@@ -2,7 +2,7 @@ import type { Attribute, AwaitBranch, AwaitNode, ConstNode, Details, Diagnostic,
2
2
  import { scanClassName } from './class-name'
3
3
  import { strayElse } from './else-problem'
4
4
  import { ifAlias } from './if-alias'
5
- import { rolesOf } from './island-declaration'
5
+ import { rolesOf, spelledOutFirstFence } from './island-declaration'
6
6
  import { Scanner } from './scanner'
7
7
 
8
8
  // `--- server`, `--- client`, `--- island`, `--- static`, `--- script`, `--- module`, or `--- <T extends Row>` making the component generic, its type parameters in the third or fourth group: `--- client <T>` takes both.
@@ -170,7 +170,7 @@ export function parseKay(source: string): KayFile {
170
170
  if (bareClosing)
171
171
  explainSecondFence(source, bareClosing, diagnostics)
172
172
 
173
- return { source, script: fences.script, server: fences.server, serverFence, module: fences.module, style: fences.style, typeParameters, client, pin, island, scriptLine, templateStart, template, diagnostics, unclosedServer }
173
+ return { source, script: fences.script, server: fences.server, serverFence, module: fences.module, style: fences.style, typeParameters, client, pin, island, scriptLine, templateStart, template, diagnostics: [...diagnostics, ...spelledOutFirstFence(source, scriptLine, fenceWord)], unclosedServer }
174
174
  }
175
175
 
176
176
  // A bare `---` in the template after a named fence closed by a bare `---`: the first bare line closed that fence, so the author meant the second fence as the script, which takes `--- script` once a named fence is there.
@@ -1,6 +1,7 @@
1
1
  import type { Lint } from './lints'
2
2
  import { LINK_LINTS } from './link-flags'
3
3
  import { LOOP_LINTS } from './loop-lints'
4
+ import { SCHEMA_LINTS } from './schema-lints'
4
5
  import { SERIAL_AWAITS_LINTS } from './serial-awaits'
5
6
 
6
7
  // The lints of the files under `src/routes`, of the content entries and of a page's server fence, with the other lints in `LINTS`.
@@ -8,6 +9,7 @@ export const ROUTE_LINTS = {
8
9
  ...SERIAL_AWAITS_LINTS,
9
10
  ...LOOP_LINTS,
10
11
  ...LINK_LINTS,
12
+ ...SCHEMA_LINTS,
11
13
  'text-size-colour': {
12
14
  level: 'warn',
13
15
  group: 'code',
@@ -0,0 +1,13 @@
1
+ import type { Lint } from './lints'
2
+
3
+ // The lints about the schemas an app hands the server, with the others in `LINTS`.
4
+ export const SCHEMA_LINTS = {
5
+ 'schema-without-json-schema': {
6
+ level: 'warn',
7
+ group: 'forms',
8
+ site: true,
9
+ summary: '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. Read from the source, in `.ts` modules and `.kay` fences: a hand-written object with `~standard` and no `jsonSchema`, and what valibot builds (valibot carries none until `toStandardJsonSchema` from `@valibot/to-json-schema` wraps it), followed through a `const` and a relative import. Zod 4.2+ and ArkType 2.1.28+ carry it.',
10
+ wrong: '--- server\nimport { action } from \'kay\'\nimport * as v from \'valibot\'\n\nexport const add = action({ input: v.object({ title: v.string() }) }, ({ title }) => title)\n---\np x',
11
+ right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ input: { title: s.string({ max: 200 }) } }, ({ title }) => title)\n---\np x',
12
+ },
13
+ } as const satisfies Record<string, Lint>
@@ -272,11 +272,14 @@ const BOT_PROTECTIONS = new Set(['honeypot', 'minTime', 'proofOfWork'])
272
272
 
273
273
  // What an `action(...)` call's options say, when one of its arguments is an object literal setting `tool`. Options it cannot read, a variable or an object spreading the `tool`, may make a tool: `output` is then false, so the type of its handler is probed, and `botProtected` false.
274
274
  function toolOptions(args: NodeOfType<'CallExpression'>['arguments']): { botProtected: boolean, output: boolean } | undefined {
275
- // The options follow the handler, which is the first argument of an action with no schema.
276
- const options = args[0]?.type === 'ArrowFunctionExpression' || args[0]?.type === 'FunctionExpression' ? args[1] : args[2]
275
+ const isHandler = (arg: Node | undefined): boolean => arg?.type === 'ArrowFunctionExpression' || arg?.type === 'FunctionExpression'
276
+ // The options come first when a handler follows them (`action({ input, ...options }, handler)`), else follow the handler, which is the first argument of an action with no schema.
277
+ const optionsFirst = args[0]?.type === 'ObjectExpression' && isHandler(args[1])
278
+ const afterHandler = isHandler(args[0]) ? args[1] : args[2]
279
+ const options = optionsFirst ? args[0] : afterHandler
277
280
  let unreadable = options !== undefined && options.type !== 'ObjectExpression'
278
281
 
279
- for (const arg of args.slice(1)) {
282
+ for (const arg of args.slice(options === args[0] ? 0 : 1)) {
280
283
  if (arg.type !== 'ObjectExpression')
281
284
  continue
282
285
 
@@ -1,7 +1,7 @@
1
1
  import type { TSchema } from 'elysia'
2
2
  import type { RawEntry } from './load'
3
3
  import type { ComponentSegment, Segment } from './markdown'
4
- import { errorText } from '../server/field-errors'
4
+ import { errorText } from '../runtime/field-errors'
5
5
  import { compiledCheck, dottedPath, fieldOf, refusals, unescaped } from '../server/schema-check'
6
6
  import { entryRefusal, kayWord } from '../server/words'
7
7
  import { humanize } from './humanize'
package/src/new.ts CHANGED
@@ -227,13 +227,17 @@ async function librariesDryRun(files: Record<string, string>, libraries: readonl
227
227
  }
228
228
  }
229
229
 
230
+ // The range a new project pins kay to: a 1.x minor may break, so it takes patches only (`~`), and from 2.0.0 a breaking change is a major, so it takes minors too (`^`).
231
+ export function kayRange(version: string): string {
232
+ return Number.parseInt(version, 10) >= 2 ? `^${version}` : `~${version}`
233
+ }
234
+
230
235
  // Every file of a project with these features in `dir`, named after it; run from a checkout of kay, packs it into `dir/vendor` for the project to depend on.
231
236
  export async function projectFiles(dir: string, features: ReadonlySet<Feature>, kayDependency?: string | undefined, settings: ConfigSettings = {}, host?: Host, runner?: string): Promise<Record<string, string>> {
232
237
  const has = holds(features)
233
238
  const name = packageName(basename(resolve(dir)))
234
239
  const kay = await Bun.file(join(KAY_ROOT, 'package.json')).json() as { name: string, version: string, dependencies: Record<string, string>, devDependencies: Record<string, string>, peerDependencies: Record<string, string> }
235
- // A kay minor may break, so the project takes its patches only.
236
- const dependency = kayDependency ?? (existsSync(join(KAY_ROOT, '.git')) ? await packKay(join(dir, 'vendor')) : `npm:${kay.name}@~${kay.version}`)
240
+ const dependency = kayDependency ?? (existsSync(join(KAY_ROOT, '.git')) ? await packKay(join(dir, 'vendor')) : `npm:${kay.name}@${kayRange(kay.version)}`)
237
241
  const scripts = {
238
242
  'dev': 'kay dev',
239
243
  ...has('server') ? { build: 'kay build', compile: 'kay build --compile server', start: 'kay start' } : { build: 'kay build --static' },
@@ -1,14 +1,16 @@
1
1
  import type { t } from 'elysia'
2
2
  import type { ActionContext, ActionProtection, Answer, Called, CallOptions, OutputSchema, ServerAction, Settled, Success } from './action-shared'
3
3
  import type { RouteParams } from './checks'
4
- import type { Schema, Static } from './schema'
4
+ import type { Schema, StandardAs, Static } from './schema'
5
5
  import type { ObjectOf, SchemaShape } from './schema-record'
6
+ import type { StandardSchema } from './standard-schema'
6
7
  import { callable } from './action-call'
7
8
  import { minTimeOf, resolveProtection, workOf } from './action-protection'
8
9
  import { ACTION, isAction } from './action-shared'
9
10
  import { durationSeconds } from './duration'
10
11
  import { KayError } from './kay-error'
11
- import { schemaOf } from './schema-record'
12
+ import { isSchema, schemaOf } from './schema-record'
13
+ import { isStandardSchema } from './standard-schema'
12
14
  import { ACTION_PREFIX } from './wire'
13
15
 
14
16
  export { actionStub, OUTCOME_SCRIPT, setRequestOutcome } from './action-call'
@@ -44,14 +46,24 @@ const emptySchema = () => ({ [Symbol.for('TypeBox.Kind')]: 'Object', type: 'obje
44
46
 
45
47
  // `action` as `kay check` reads it in a page's server fence, whose `ctx.params` are those of the page's route: not something to write.
46
48
  export interface ActionFor<Params extends Readonly<Record<string, unknown>>, Guarded extends object = object> {
49
+ <const Honeypot extends string = never, Output = never, Shape extends OutputSchema = OutputSchema>(options: ActionProtection<Honeypot, Success<Settled<Output>>, Shape> & { input?: undefined }, handler: (ctx: ActionContext<Params, string, Guarded>, ctxAfterEmptyInput: ActionContext<Params, string, Guarded>) => Output | Promise<Output>): NoInputAction<Settled<Output>, Honeypot>
50
+ <Spec extends Schema, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(options: ActionProtection<Honeypot, Success<Settled<Output>>, Shape> & { input: Spec }, handler: (input: Static<Spec>, ctx: ActionContext<Params, Extract<keyof Static<Spec>, string>, Guarded>) => Output | Promise<Output>): ServerAction<Spec, Settled<Output>, Honeypot>
51
+ <Validator extends StandardSchema, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(options: ActionProtection<Honeypot, Success<Settled<Output>>, Shape> & { input: Validator }, handler: (input: Static<StandardAs<Validator>>, ctx: ActionContext<Params, Extract<keyof Static<StandardAs<Validator>>, string>, Guarded>) => Output | Promise<Output>): ServerAction<StandardAs<Validator>, Settled<Output>, Honeypot>
52
+ <const Fields extends SchemaShape, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(options: ActionProtection<Honeypot, Success<Settled<Output>>, Shape> & { input: Fields }, handler: (input: Static<ObjectOf<Fields>>, ctx: ActionContext<Params, Extract<keyof Static<ObjectOf<Fields>>, string>, Guarded>) => Output | Promise<Output>): ServerAction<ObjectOf<Fields>, Settled<Output>, Honeypot>
47
53
  <Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(handler: (ctx: ActionContext<Params, string, Guarded>) => Output | Promise<Output>, protection?: ActionProtection<Honeypot, Success<Settled<Output>>, Shape>): NoInputAction<Settled<Output>, Honeypot>
48
54
  <Spec extends Schema, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(schema: Spec, handler: (input: Static<Spec>, ctx: ActionContext<Params, Extract<keyof Static<Spec>, string>, Guarded>) => Output | Promise<Output>, protection?: ActionProtection<Honeypot, Success<Settled<Output>>, Shape>): ServerAction<Spec, Settled<Output>, Honeypot>
49
55
  <const Fields extends SchemaShape, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(fields: Fields, handler: (input: Static<ObjectOf<Fields>>, ctx: ActionContext<Params, Extract<keyof Static<ObjectOf<Fields>>, string>, Guarded>) => Output | Promise<Output>, protection?: ActionProtection<Honeypot, Success<Settled<Output>>, Shape>): ServerAction<ObjectOf<Fields>, Settled<Output>, Honeypot>
50
56
  }
51
57
 
52
- // Declares a server action in a page's `--- server` fence: Elysia validates the input against `schema` before `handler` runs, `schema` a plain record of fields as well as a schema.
53
- // Without a schema the action takes no input, as with an empty object schema, and its handler gets the context alone.
58
+ // Declares a server action in a page's `--- server` fence: the options come first, as an API route's do, `input` a plain record of fields or any schema that kay checks the post against before `handler` runs.
59
+ // Without an `input` the action takes no input, as with an empty object schema, and its handler gets the context alone.
60
+ // The form before 1.107, `action(schema, handler, options)`, works until 2.0: the `deprecated-action-options` lint rewrites it.
54
61
  // kept: free, it registers a route answering a POST, which the page's own render never runs, and a kept page is refreshed after the first request that can write.
62
+ // A handler of two parameters is the form before 1.107, `action({}, (input, ctx) => ...)`, handed the empty input first: its second is the context, as the first of one taking the context alone is.
63
+ export function action<const Honeypot extends string = never, Output = never, Shape extends OutputSchema = OutputSchema>(options: ActionProtection<Honeypot, Success<Settled<Output>>, Shape> & { input?: undefined }, handler: (ctx: ActionContext, ctxAfterEmptyInput: ActionContext) => Output | Promise<Output>): NoInputAction<Settled<Output>, Honeypot>
64
+ export function action<Spec extends Schema, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(options: ActionProtection<Honeypot, Success<Settled<Output>>, Shape> & { input: Spec }, handler: (input: Static<Spec>, ctx: ActionContext<RouteParams, Extract<keyof Static<Spec>, string>>) => Output | Promise<Output>): ServerAction<Spec, Settled<Output>, Honeypot>
65
+ export function action<Validator extends StandardSchema, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(options: ActionProtection<Honeypot, Success<Settled<Output>>, Shape> & { input: Validator }, handler: (input: Static<StandardAs<Validator>>, ctx: ActionContext<RouteParams, Extract<keyof Static<StandardAs<Validator>>, string>>) => Output | Promise<Output>): ServerAction<StandardAs<Validator>, Settled<Output>, Honeypot>
66
+ export function action<const Fields extends SchemaShape, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(options: ActionProtection<Honeypot, Success<Settled<Output>>, Shape> & { input: Fields }, handler: (input: Static<ObjectOf<Fields>>, ctx: ActionContext<RouteParams, Extract<keyof Static<ObjectOf<Fields>>, string>>) => Output | Promise<Output>): ServerAction<ObjectOf<Fields>, Settled<Output>, Honeypot>
55
67
  export function action<Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(handler: (ctx: ActionContext) => Output | Promise<Output>, protection?: ActionProtection<Honeypot, Success<Settled<Output>>, Shape>): NoInputAction<Settled<Output>, Honeypot>
56
68
  export function action<Spec extends Schema, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(schema: Spec, handler: (input: Static<Spec>, ctx: ActionContext<RouteParams, Extract<keyof Static<Spec>, string>>) => Output | Promise<Output>, protection?: ActionProtection<Honeypot, Success<Settled<Output>>, Shape>): ServerAction<Spec, Settled<Output>, Honeypot>
57
69
  export function action<const Fields extends SchemaShape, Output, const Honeypot extends string = never, Shape extends OutputSchema = OutputSchema>(fields: Fields, handler: (input: Static<ObjectOf<Fields>>, ctx: ActionContext<RouteParams, Extract<keyof Static<ObjectOf<Fields>>, string>>) => Output | Promise<Output>, protection?: ActionProtection<Honeypot, Success<Settled<Output>>, Shape>): ServerAction<ObjectOf<Fields>, Settled<Output>, Honeypot>
@@ -62,9 +74,40 @@ export function action(first: unknown, second?: unknown, third?: ActionProtectio
62
74
  return declare(emptySchema(), (_input, ctx) => handler(ctx), second as ActionProtection<string> | undefined)
63
75
  }
64
76
 
77
+ if (third === undefined && isOptions(first)) {
78
+ const { input, ...options } = first as { input?: Schema | SchemaShape }
79
+ const handler = second as (...args: unknown[]) => unknown
80
+
81
+ // Without an `input` the handler takes the context alone, though an empty record before 1.107 gave it `(input, ctx)`.
82
+ return declare(input === undefined ? emptySchema() : schemaOf(input), input === undefined && handler.length < 2 ? (_input, ctx) => handler(ctx) : handler, options)
83
+ }
84
+
65
85
  return declare(schemaOf(first as Schema | SchemaShape), second as (input: unknown, ctx: ActionContext) => unknown, third)
66
86
  }
67
87
 
88
+ // Whether the first argument is the options of the form since 1.107, not the schema or the record of fields of the form before: an object that names an `input` which is a record or an object schema, or names no field at all.
89
+ function isOptions(first: unknown): boolean {
90
+ if (typeof first !== 'object' || first === null || isSchema(first) || isStandardSchema(first))
91
+ return false
92
+
93
+ const entries = Object.entries(first)
94
+
95
+ if ('input' in first) {
96
+ const { input } = first
97
+
98
+ // An `input` that is a schema or a record is options; so is one left undefined. A legacy record holding a field called `input` has a schema beside it, which options never do.
99
+ if (input === undefined)
100
+ return true
101
+
102
+ if (typeof input !== 'object' || input === null)
103
+ return false
104
+
105
+ return !entries.some(([name, value]) => name !== 'input' && (isSchema(value) || isStandardSchema(value)))
106
+ }
107
+
108
+ return !entries.some(([, value]) => isSchema(value) || isStandardSchema(value))
109
+ }
110
+
68
111
  export function declare(schema: Schema, handler: (input: unknown, ctx: ActionContext) => unknown, options: ActionProtection<string> | undefined): ServerAction<Schema, unknown> {
69
112
  const protection = resolveProtection(options)
70
113
 
@@ -229,6 +229,12 @@ async function hydrateIsland(registry: IslandRegistry, element: HTMLElement): Pr
229
229
 
230
230
  try {
231
231
  loaded = await Promise.all([load(), staticSlots(registry, element), livePropsOf(element), reviveActionsIn(element.dataset.props)])
232
+
233
+ // What the server drew of its lazy components loads first, so the markup is claimed as it stands.
234
+ const drawn = (globalThis as { $kayLoadDrawn?: (island: HTMLElement) => Promise<void> }).$kayLoadDrawn
235
+
236
+ if (drawn !== undefined)
237
+ await drawn(element)
232
238
  }
233
239
  catch (error) {
234
240
  // A chunk that failed to load is dropped like a missing one.
@@ -355,6 +361,10 @@ async function hotSwap(registry: IslandRegistry, swap: HotSwap): Promise<boolean
355
361
  const chunk = withBase(chunks[0]!)
356
362
 
357
363
  if (!document.querySelector(`${ISLAND}[data-component="${CSS.escape(id)}"]`)) {
364
+ // An island's code an island loaded lazily is not in the page as an island of its own, and keeps the version it loaded: only a reload brings the new one.
365
+ if ((globalThis as { $kayLazyLoaded?: boolean }).$kayLazyLoaded === true)
366
+ return false
367
+
358
368
  // Not on this page: a later one rendering it loads the new chunk, unless that would bring code the page runs again.
359
369
  if (fits(chunks))
360
370
  registry[id] = async () => import(chunk) as ReturnType<IslandRegistry[string]>