@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
package/dist/eslint.js CHANGED
@@ -25,7 +25,7 @@ var __esm = (fn, res, err) => () => {
25
25
  };
26
26
 
27
27
  // package.json
28
- var version = "1.106.0", peerDependencies;
28
+ var version = "1.107.0", peerDependencies;
29
29
  var init_package = __esm(() => {
30
30
  peerDependencies = {
31
31
  "@happy-dom/global-registrator": "^20.14.6 || ^21.0.3",
@@ -1027,6 +1027,18 @@ function rolesOf(source, script, fence) {
1027
1027
  return { island, client: undefined, pin: undefined };
1028
1028
  return island.render === "client" ? { island, client: island.span, pin: undefined } : { island, client: undefined, pin: { kind: island.render, ...island.span } };
1029
1029
  }
1030
+ function spelledOutFirstFence(source, line, word) {
1031
+ if (!line || word?.word !== "script" || source.slice(0, line.start).trim() !== "")
1032
+ return [];
1033
+ return [{
1034
+ start: line.start,
1035
+ end: word.end,
1036
+ code: "fence-invalid",
1037
+ message: "`--- script` cannot open a file: the script is written `---`",
1038
+ help: "`--- script` is only for a script that follows a `--- server`, `--- module` or `--- style` fence",
1039
+ fixes: [{ title: "Write `---`", safe: true, edits: [{ start: line.start + 3, end: word.end, text: "" }] }]
1040
+ }];
1041
+ }
1030
1042
  var ISLAND_CALL, RENDERS, HYDRATE_TIMINGS, KEYS;
1031
1043
  var init_island_declaration = __esm(() => {
1032
1044
  init_estree();
@@ -1227,7 +1239,7 @@ function parseKay(source) {
1227
1239
  const template = parser.parseTemplate();
1228
1240
  if (bareClosing)
1229
1241
  explainSecondFence(source, bareClosing, diagnostics);
1230
- return { source, script: fences.script, server: fences.server, serverFence, module: fences.module, style: fences.style, typeParameters, client, pin, island, scriptLine, templateStart, template, diagnostics, unclosedServer };
1242
+ 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 };
1231
1243
  }
1232
1244
  function explainSecondFence(source, closing, diagnostics) {
1233
1245
  const stray = diagnostics.find((diagnostic) => diagnostic.code === undefined && diagnostic.start >= closing.end && BARE_LINE.test(source.slice(diagnostic.start, diagnostic.end)) && source[diagnostic.start - 1] === `
@@ -3993,11 +4005,20 @@ function importEdits(file, fence, imports, wanted) {
3993
4005
  }
3994
4006
  return edits;
3995
4007
  }
3996
- var STARTS_WITH_IMPORT, STARTS_BLANK, PROLOGUE_LINE;
4008
+ function withoutComma(src, specifier, declaration) {
4009
+ const after = COMMA_AFTER.exec(src.slice(specifier.end, declaration.end));
4010
+ if (after)
4011
+ return { start: specifier.start, end: specifier.end + after[0].length };
4012
+ const before = COMMA_BEFORE.exec(src.slice(declaration.start, specifier.start));
4013
+ return { start: specifier.start - (before?.[0].length ?? 0), end: specifier.end };
4014
+ }
4015
+ var STARTS_WITH_IMPORT, STARTS_BLANK, PROLOGUE_LINE, COMMA_AFTER, COMMA_BEFORE;
3997
4016
  var init_import_edits = __esm(() => {
3998
4017
  STARTS_WITH_IMPORT = /^\s*import\b/;
3999
4018
  STARTS_BLANK = /^[ \t]*\r?\n/;
4000
4019
  PROLOGUE_LINE = /^(?:#!.*|\/\/\/\s*<reference\b.*|[ \t]*(['"])use [\w -]+\1[ \t]*(?:;[ \t]*)?)(?:\r?\n|$)/;
4020
+ COMMA_AFTER = /^\s*,\s*/;
4021
+ COMMA_BEFORE = /,\s*$/;
4001
4022
  });
4002
4023
 
4003
4024
  // src/compiler/names.ts
@@ -4583,6 +4604,7 @@ var init_kay_exports = __esm(() => {
4583
4604
  trustHtml: "shared",
4584
4605
  uid: "shared",
4585
4606
  untrack: "browser",
4607
+ validate: "shared",
4586
4608
  watch: "browser",
4587
4609
  webPush: "browser",
4588
4610
  withBase: "shared",
@@ -5375,9 +5397,12 @@ function readsItself(ast, declaration) {
5375
5397
  return found;
5376
5398
  }
5377
5399
  function toolOptions(args) {
5378
- const options = args[0]?.type === "ArrowFunctionExpression" || args[0]?.type === "FunctionExpression" ? args[1] : args[2];
5400
+ const isHandler = (arg) => arg?.type === "ArrowFunctionExpression" || arg?.type === "FunctionExpression";
5401
+ const optionsFirst = args[0]?.type === "ObjectExpression" && isHandler(args[1]);
5402
+ const afterHandler = isHandler(args[0]) ? args[1] : args[2];
5403
+ const options = optionsFirst ? args[0] : afterHandler;
5379
5404
  let unreadable = options !== undefined && options.type !== "ObjectExpression";
5380
- for (const arg of args.slice(1)) {
5405
+ for (const arg of args.slice(options === args[0] ? 0 : 1)) {
5381
5406
  if (arg.type !== "ObjectExpression")
5382
5407
  continue;
5383
5408
  const keys = new Map(arg.properties.flatMap((property) => isPlainProperty(property) && !property.computed ? [[keyName(property.key), property.value]] : []));
@@ -7273,7 +7298,7 @@ class AttributeFixes {
7273
7298
  if (this.src[start - 1] === ",") {
7274
7299
  start--;
7275
7300
  } else {
7276
- const after = COMMA_AFTER.exec(this.src.slice(end));
7301
+ const after = COMMA_AFTER2.exec(this.src.slice(end));
7277
7302
  if (after)
7278
7303
  end += after[0].length;
7279
7304
  }
@@ -7301,13 +7326,13 @@ class AttributeFixes {
7301
7326
  return this.src.slice(span.start, span.end);
7302
7327
  }
7303
7328
  }
7304
- var PART = "[A-Z][\\w-]*", PART_NAME, PART_NAME_LIST, FIELD_NAME2, WHITESPACE_CHAR, COMMA_AFTER, PLAIN_TEXT, QUOTED;
7329
+ var PART = "[A-Z][\\w-]*", PART_NAME, PART_NAME_LIST, FIELD_NAME2, WHITESPACE_CHAR, COMMA_AFTER2, PLAIN_TEXT, QUOTED;
7305
7330
  var init_validate_fixes = __esm(() => {
7306
7331
  PART_NAME = new RegExp(`^${PART}$`, "i");
7307
7332
  PART_NAME_LIST = new RegExp(`^${PART}(?: ${PART})*$`, "i");
7308
7333
  FIELD_NAME2 = /^[\w.[\]-]+$/;
7309
7334
  WHITESPACE_CHAR = /\s/;
7310
- COMMA_AFTER = /^\s*,\s*/;
7335
+ COMMA_AFTER2 = /^\s*,\s*/;
7311
7336
  PLAIN_TEXT = /^[^"'`\\&\n{}<>]*$/;
7312
7337
  QUOTED = /^\s*(['"`])([^'"`\\${}\n]*)\1\s*$/;
7313
7338
  });
@@ -11211,6 +11236,233 @@ var init_jsx = __esm(() => {
11211
11236
  PLAIN_PARAMETER = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u;
11212
11237
  });
11213
11238
 
11239
+ // src/compiler/lazy-imports.ts
11240
+ function occurrences(text, name) {
11241
+ return text.match(new RegExp(`(?<![\\w$.])${name.replaceAll("$", "\\$")}(?![\\w$])`, "g"))?.length ?? 0;
11242
+ }
11243
+
11244
+ class Positions {
11245
+ source;
11246
+ deferring;
11247
+ visit;
11248
+ repeating = 0;
11249
+ constructor(source, deferring, visit) {
11250
+ this.source = source;
11251
+ this.deferring = deferring;
11252
+ this.visit = visit;
11253
+ }
11254
+ exhaustive(branches, deferred) {
11255
+ const real = this.visit;
11256
+ const calls = branches.map((children) => {
11257
+ const seen = [];
11258
+ this.visit = {
11259
+ use: (element, inner) => seen.push({ name: element.name, element, deferred: inner, outlet: false }),
11260
+ 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 })
11261
+ };
11262
+ this.walk(children, deferred);
11263
+ return seen;
11264
+ });
11265
+ this.visit = real;
11266
+ const keyOf = (call) => `${call.outlet}:${call.name}`;
11267
+ const everywhere = calls.map((seen) => new Set(seen.map(keyOf)));
11268
+ for (const call of calls.flat()) {
11269
+ const always = everywhere.every((names) => names.has(keyOf(call)));
11270
+ if (call.outlet)
11271
+ real.outlet?.(call.element, call.deferred || !always && this.repeating === 0);
11272
+ else
11273
+ real.use?.(call.element, call.deferred || !always && this.repeating === 0);
11274
+ }
11275
+ }
11276
+ walk(nodes, deferred) {
11277
+ for (const node of nodes) {
11278
+ switch (node.kind) {
11279
+ case "element":
11280
+ this.element(node, deferred);
11281
+ break;
11282
+ case "if":
11283
+ if (node.fallback) {
11284
+ this.exhaustive([...node.branches.map((branch) => branch.children), node.fallback.children], deferred);
11285
+ break;
11286
+ }
11287
+ for (const branch of node.branches)
11288
+ this.walk(branch.children, deferred || this.repeating === 0);
11289
+ break;
11290
+ case "match":
11291
+ if (node.fallback) {
11292
+ this.exhaustive([...node.cases.map((branch) => branch.children), node.fallback.children], deferred);
11293
+ break;
11294
+ }
11295
+ for (const branch of node.cases)
11296
+ this.walk(branch.children, deferred || this.repeating === 0);
11297
+ break;
11298
+ case "for":
11299
+ this.repeating++;
11300
+ this.walk(node.children, deferred);
11301
+ this.repeating--;
11302
+ this.walk(node.fallback ?? [], deferred);
11303
+ break;
11304
+ case "await":
11305
+ this.walk(node.pending, deferred);
11306
+ this.walk(node.resolved?.children ?? [], deferred);
11307
+ this.walk(node.rejected?.children ?? [], true);
11308
+ break;
11309
+ case "try":
11310
+ this.walk(node.children, deferred);
11311
+ this.walk(node.rejected?.children ?? [], true);
11312
+ break;
11313
+ case "text":
11314
+ this.walk(node.parts.filter((part) => part.kind === "element"), deferred);
11315
+ break;
11316
+ case "slot":
11317
+ case "snippet":
11318
+ case "pending":
11319
+ this.walk(node.children, deferred);
11320
+ break;
11321
+ case "const":
11322
+ case "error":
11323
+ break;
11324
+ }
11325
+ }
11326
+ }
11327
+ element(element, deferred) {
11328
+ if (element.component)
11329
+ this.visit.use?.(element, deferred);
11330
+ else if (element.name === "slot")
11331
+ this.visit.outlet?.(element, deferred);
11332
+ const props = element.component ? this.deferring(element) : [];
11333
+ for (const child of element.children) {
11334
+ const own = child.kind === "slot" ? this.source.slice(child.name.start, child.name.end) : CHILDREN;
11335
+ const repeated = child.kind === "slot" && child.params !== undefined;
11336
+ this.repeating += repeated ? 1 : 0;
11337
+ this.walk(child.kind === "slot" ? child.children : [child], deferred || props.includes(own));
11338
+ this.repeating -= repeated ? 1 : 0;
11339
+ }
11340
+ }
11341
+ }
11342
+ function codeOf2(file) {
11343
+ const blanks = [];
11344
+ visitNodes(file.template, (node) => {
11345
+ if (node.kind === "text")
11346
+ blanks.push(...node.parts.filter((part) => part.kind === "chunk"));
11347
+ else if (node.kind === "element")
11348
+ blanks.push(...node.attributes.flatMap((attribute) => attribute.kind === "static" ? [attribute.value] : []));
11349
+ });
11350
+ let code = file.source;
11351
+ for (const { start, end } of blanks)
11352
+ code = `${code.slice(0, start)}${" ".repeat(end - start)}${code.slice(end)}`;
11353
+ return blankLiterals(code);
11354
+ }
11355
+ function blankLiterals(code) {
11356
+ const blank = (text) => " ".repeat(text.length);
11357
+ return code.split(`
11358
+ `).map((line) => {
11359
+ if (LINE_COMMENT.test(line))
11360
+ return blank(line);
11361
+ return UNSURE_LINE.test(line) ? line : line.replace(PLAIN_STRING, blank);
11362
+ }).join(`
11363
+ `);
11364
+ }
11365
+ function lazyImports(file, imports, known) {
11366
+ const found = positionsLazy(file, imports, known);
11367
+ for (let changed = found.size > 0;changed; ) {
11368
+ const held = new Set(eagerReach(imports, known, found));
11369
+ changed = false;
11370
+ for (const [local, lazy] of found) {
11371
+ if (held.has(lazy.key)) {
11372
+ found.delete(local);
11373
+ changed = true;
11374
+ }
11375
+ }
11376
+ }
11377
+ return found;
11378
+ }
11379
+ function eagerReach(imports, known, lazy) {
11380
+ const reach = new Set;
11381
+ for (const binding of imports) {
11382
+ const component = binding.imported === "default" && !binding.typeOnly ? known[binding.source] : undefined;
11383
+ if (component && !lazy.has(binding.local)) {
11384
+ reach.add(component.key);
11385
+ for (const key of component.reach)
11386
+ reach.add(key);
11387
+ }
11388
+ }
11389
+ return [...reach];
11390
+ }
11391
+ function positionsLazy(file, imports, known) {
11392
+ const candidates = new Map;
11393
+ const specifiers = new Map;
11394
+ for (const binding of imports) {
11395
+ if (binding.imported !== "default" || binding.typeOnly)
11396
+ continue;
11397
+ specifiers.set(binding.local, binding.source);
11398
+ const declared = file.source.slice(binding.declaration.start, binding.declaration.end);
11399
+ if ((known[binding.source]?.size ?? 0) >= LAZY_FLOOR && PLAIN_IMPORT.test(declared))
11400
+ candidates.set(binding.local, { binding, uses: [] });
11401
+ }
11402
+ if (candidates.size === 0)
11403
+ return new Map;
11404
+ const refused = new Set;
11405
+ new Positions(file.source, (element) => {
11406
+ const specifier = specifiers.get(element.name);
11407
+ return specifier === undefined ? [] : known[specifier]?.deferred ?? [];
11408
+ }, {
11409
+ use(element, deferred) {
11410
+ const candidate = candidates.get(element.name);
11411
+ if (!candidate)
11412
+ return;
11413
+ candidate.uses.push(deferred);
11414
+ if (serverIslandOf(element, file.source) !== undefined)
11415
+ refused.add(element.name);
11416
+ }
11417
+ }).walk(file.template, false);
11418
+ const code = codeOf2(file);
11419
+ const found = new Map;
11420
+ for (const [local, { binding, uses }] of candidates) {
11421
+ const written = occurrences(code, local) - 1;
11422
+ if (uses.length === 0 || !uses.every(Boolean) || refused.has(local) || written !== uses.length)
11423
+ continue;
11424
+ found.set(local, { key: known[binding.source].key, specifier: binding.source, declaration: binding.declaration });
11425
+ }
11426
+ return found;
11427
+ }
11428
+ function lazyImportsOf(file, imports, options, hydrated, routeFile, clientOnly) {
11429
+ return options.components !== undefined && !(routeFile || clientOnly) && (options.output === "dom" || hydrated) ? lazyImports(file, imports, options.components) : undefined;
11430
+ }
11431
+ function lazyNoteImport(lazy, mode) {
11432
+ return mode === "html" && (lazy?.size ?? 0) > 0 ? `import { lazyNote as ${helperName("lazyNote")} } from 'kay/island'
11433
+ ` : "";
11434
+ }
11435
+ function lazyDomImport(lazy) {
11436
+ return (lazy?.size ?? 0) > 0 ? `import { lazy as ${helperName("lazy")}, ready as ${helperName("ready")} } from 'kay/dom-lazy'
11437
+ ` : "";
11438
+ }
11439
+ function lazyEdits(imports, span, lazy, mode, moduleId) {
11440
+ if (mode !== "dom" && mode !== "html")
11441
+ return [];
11442
+ const last = Math.max(-1, ...[...lazy?.values() ?? []].map((other) => other.declaration.start));
11443
+ return imports.flatMap((binding) => {
11444
+ const found = lazy?.get(binding.local);
11445
+ if (!found || binding.declaration.start < span.start || binding.declaration.end > span.end)
11446
+ return [];
11447
+ const key = JSON.stringify(found.key);
11448
+ const specifier = JSON.stringify(found.specifier);
11449
+ const eager = `${helperName("lazy")}_${binding.local}`;
11450
+ const ready = found.declaration.start === last ? `
11451
+ ${helperName("ready")}(${JSON.stringify(moduleId)}, ${JSON.stringify([...lazy?.values() ?? []].map((other) => other.key))})` : "";
11452
+ return [{ ...found.declaration, text: mode === "dom" ? `const ${binding.local} = ${helperName("lazy")}(${key}, () => import(${specifier}))${ready}` : `import ${eager} from ${specifier}
11453
+ const ${binding.local} = ${helperName("lazyNote")}(${key}, () => ${eager})` }];
11454
+ });
11455
+ }
11456
+ var LAZY_FLOOR = 2000, CHILDREN = "children", LINE_COMMENT, PLAIN_STRING, UNSURE_LINE, PLAIN_IMPORT;
11457
+ var init_lazy_imports = __esm(() => {
11458
+ init_ast();
11459
+ init_markup();
11460
+ LINE_COMMENT = /^[ \t]*\/\/.*$/;
11461
+ PLAIN_STRING = /'(?:[^'\\\n$`]|\\.)*'|"(?:[^"\\\n$`]|\\.)*"/g;
11462
+ UNSURE_LINE = /`|[(,=:?!&|{;[]\s*\/(?![/*])/;
11463
+ PLAIN_IMPORT = /^import\s+[\w$]+\s+from\s*(['"])[^'"]+\1\s*;?$/;
11464
+ });
11465
+
11214
11466
  // src/compiler/template-reads.ts
11215
11467
  function binders(node) {
11216
11468
  switch (node.kind) {
@@ -11862,12 +12114,12 @@ ${this.mode === "dom" && this.facts.ambientForm ? `const KayHere = ${helperName(
11862
12114
  }
11863
12115
  b.add(this.slotTypes().imports);
11864
12116
  if (mode === "html")
11865
- b.add(htmlHelperImport(this.options.awaitAlert, facts.await));
12117
+ b.add(htmlHelperImport(this.options.awaitAlert, facts.await) + lazyNoteImport(this.options.lazy, mode));
11866
12118
  if (this.loadPlan)
11867
12119
  b.add(`import { loadScope as ${helperName("loadScope")} } from 'kay/html'
11868
12120
  `);
11869
12121
  if (mode === "dom")
11870
- b.add(domHelperImport(this.options.awaitAlert, facts.await));
12122
+ b.add(domHelperImport(this.options.awaitAlert, facts.await) + lazyDomImport(this.options.lazy));
11871
12123
  if (mode === "dom" && this.kind === "island" && titled)
11872
12124
  b.add(`import { pageTitle as ${helperName("pageTitle")} } from 'kay/internal/title'
11873
12125
  `);
@@ -12106,7 +12358,7 @@ export default KayIsland(${JSON.stringify(this.options.island)}, ${name}${this.g
12106
12358
  const left = duplicates.filter(inside);
12107
12359
  if (left.length > 0 && left.length === imports.filter(inside).length)
12108
12360
  return;
12109
- const edits = left.map((binding) => this.withoutComma(binding.span, binding.declaration));
12361
+ const edits = [...left.map((binding) => withoutComma(this.src, binding.span, binding.declaration)), ...lazyEdits(imports, span, this.options.lazy, this.mode, this.options.moduleId)];
12110
12362
  for (const specifier of specifiers) {
12111
12363
  const quoted = this.src.slice(specifier.start, specifier.end);
12112
12364
  const target = specifier.start >= span.start && specifier.end <= span.end ? this.options.relocateImport?.(quoted.length > 1 && quoted.endsWith(quoted[0]) ? quoted.slice(1, -1) : quoted.slice(1)) : undefined;
@@ -12131,13 +12383,6 @@ export default KayIsland(${JSON.stringify(this.options.island)}, ${name}${this.g
12131
12383
  return start === 0 || this.src[start - 1] === `
12132
12384
  ` ? start : offset;
12133
12385
  }
12134
- withoutComma(specifier, declaration) {
12135
- const after = IMPORT_COMMA_AFTER.exec(this.src.slice(specifier.end, declaration.end));
12136
- if (after)
12137
- return { start: specifier.start, end: specifier.end + after[0].length };
12138
- const before = IMPORT_COMMA_BEFORE.exec(this.src.slice(declaration.start, specifier.start));
12139
- return { start: specifier.start - (before?.[0].length ?? 0), end: specifier.end };
12140
- }
12141
12386
  emitLoad(server) {
12142
12387
  const { b } = this;
12143
12388
  const query = this.declaresQuery();
@@ -12406,17 +12651,19 @@ function deferredData(facts, server) {
12406
12651
  function paramsType(options) {
12407
12652
  return options.params ? `{ ${options.params.map((name) => `${JSON.stringify(name)}: ${options.paramTypes?.[name] ?? "string"}`).join(", ")} }` : "Record<string, string>";
12408
12653
  }
12409
- var HORIZONTAL_SPACE, WRITE_NAMES, CTX_REFERENCE, IDENTIFIER6, IMPORT_COMMA_AFTER, IMPORT_COMMA_BEFORE, BROKEN_SPECIFIER, PRERENDER = "prerender", QUERY2 = "query", NOT_ACTIONS;
12654
+ var HORIZONTAL_SPACE, WRITE_NAMES, CTX_REFERENCE, IDENTIFIER6, BROKEN_SPECIFIER, PRERENDER = "prerender", QUERY2 = "query", NOT_ACTIONS;
12410
12655
  var init_codegen = __esm(() => {
12411
12656
  init_action();
12412
12657
  init_ast();
12413
12658
  init_dom();
12414
12659
  init_head_shorthand();
12415
12660
  init_html();
12661
+ init_import_edits();
12416
12662
  init_inspect();
12417
12663
  init_island_arguments();
12418
12664
  init_items();
12419
12665
  init_jsx();
12666
+ init_lazy_imports();
12420
12667
  init_load_plan();
12421
12668
  init_mapping();
12422
12669
  init_markup();
@@ -12433,8 +12680,6 @@ var init_codegen = __esm(() => {
12433
12680
  WRITE_NAMES = { to: "writeTo", update: "updateTo", back: "writeBack", updateBack: "updateBack" };
12434
12681
  CTX_REFERENCE = /\bctx\b/;
12435
12682
  IDENTIFIER6 = /[\p{ID_Start}$_][\p{ID_Continue}$]*/gu;
12436
- IMPORT_COMMA_AFTER = /^\s*,\s*/;
12437
- IMPORT_COMMA_BEFORE = /,\s*$/;
12438
12683
  BROKEN_SPECIFIER = /^((?:\s*(?:\/\/.*\n|\/\*(?:[^*]|\*(?!\/))*\*\/))*\s*import\b(?:[^'"]*[^\w$'"]from)?\s*)((['"])[^'";\s]*\3?)/;
12439
12684
  NOT_ACTIONS = new Set([PAGE, ...PAGE_SETTINGS]);
12440
12685
  });
@@ -12676,29 +12921,6 @@ var init_deprecated_parts = __esm(() => {
12676
12921
  init_old_parts();
12677
12922
  });
12678
12923
 
12679
- // src/compiler/deprecated-script-fence.ts
12680
- function spelledOutScriptFence(file) {
12681
- const line = file.scriptLine;
12682
- if (!line || file.source.slice(0, line.start).trim() !== "")
12683
- return [];
12684
- const spelled = SPELLED_OUT.exec(file.source.slice(line.start, line.end));
12685
- if (!spelled)
12686
- return [];
12687
- return [{
12688
- start: line.start,
12689
- end: line.start + spelled[0].length,
12690
- code: "deprecated-script-fence",
12691
- checkOnly: true,
12692
- message: "`--- script` is `---` spelled out, deprecated since 1.102",
12693
- help: "write `---`: the word is only needed for a script that follows a `--- server`, `--- module` or `--- style` fence",
12694
- fixes: [{ title: "Write `---`", safe: true, edits: [{ start: line.start + 3, end: line.start + spelled[0].length, text: "" }] }]
12695
- }];
12696
- }
12697
- var SPELLED_OUT;
12698
- var init_deprecated_script_fence = __esm(() => {
12699
- SPELLED_OUT = /^---[ \t]+script\b/;
12700
- });
12701
-
12702
12924
  // src/runtime/form-types.ts
12703
12925
  function autocompleteByName(name) {
12704
12926
  return NAMED_AUTOCOMPLETE.get(name.replace(NAME_SEPARATORS, "").toLowerCase());
@@ -13822,6 +14044,99 @@ export async function members(auth: Auth, org: string) {
13822
14044
  };
13823
14045
  });
13824
14046
 
14047
+ // src/compiler/deprecated-lints-1-105.ts
14048
+ var SOURCE_READERS;
14049
+ var init_deprecated_lints_1_105 = __esm(() => {
14050
+ SOURCE_READERS = {
14051
+ "deprecated-source-readers": {
14052
+ level: "warn",
14053
+ group: "deprecated",
14054
+ since: "1.105",
14055
+ site: true,
14056
+ 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.",
14057
+ wrong: `---
14058
+ import { local, resource } from 'kay'
14059
+ import notesApi from '../api/notes'
14060
+ import { save } from './notes'
14061
+
14062
+ const list = resource(notesApi, '/')
14063
+ const notes = local({ key: 'id', read: () => [], put: save })
14064
+ ---
14065
+ p {list.value()?.length} on the server, {notes.rows().length} here, {notes.unsynced()} waiting`,
14066
+ right: `---
14067
+ import { local, resource } from 'kay'
14068
+ import notesApi from '../api/notes'
14069
+ import { save } from './notes'
14070
+
14071
+ const list = resource(notesApi, '/')
14072
+ const notes = local({ key: 'id', read: () => [], put: save })
14073
+ ---
14074
+ p {list.data()?.length} on the server, {notes.data().length} here, {notes.sync.queued()} waiting`
14075
+ },
14076
+ "deprecated-live-api": {
14077
+ level: "warn",
14078
+ group: "deprecated",
14079
+ since: "1.105",
14080
+ site: true,
14081
+ 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.",
14082
+ wrong: `// src/live.ts
14083
+ import { live } from 'kay'
14084
+
14085
+ export const room = live((id: string) => ({ id, users: 0 }))
14086
+
14087
+ room.set('lobby', { id: 'lobby', users: 3 })`,
14088
+ right: `// src/live.ts
14089
+ import { live } from 'kay'
14090
+
14091
+ export const room = live((id: string) => ({ id, users: 0 }))
14092
+
14093
+ room.set({ id: 'lobby', users: 3 }, { key: 'lobby' })`
14094
+ },
14095
+ "deprecated-action-type": {
14096
+ level: "warn",
14097
+ group: "deprecated",
14098
+ since: "1.105",
14099
+ site: true,
14100
+ 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.",
14101
+ wrong: `---
14102
+ import type { Action } from 'kay'
14103
+
14104
+ const { run } = props<{ run: Action<never, unknown> }>()
14105
+ ---
14106
+ form(action={run})
14107
+ button Go`,
14108
+ right: `---
14109
+ import type { Action } from 'kay'
14110
+
14111
+ const { run } = props<{ run: Action }>()
14112
+ ---
14113
+ form(action={run})
14114
+ button Go`
14115
+ },
14116
+ "deprecated-action-readers": {
14117
+ level: "warn",
14118
+ group: "deprecated",
14119
+ since: "1.105",
14120
+ site: true,
14121
+ 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.",
14122
+ wrong: `---
14123
+ import { add } from './notes.kay'
14124
+ ---
14125
+ form(action={add})
14126
+ input(name="title" aria-invalid={add.error('title') ? 'true' : undefined})
14127
+ if add.failed()
14128
+ p Not saved`,
14129
+ right: `---
14130
+ import { add } from './notes.kay'
14131
+ ---
14132
+ form(action={add})
14133
+ input(name="title" aria-invalid={add.form.error('title') ? 'true' : undefined})
14134
+ if add.form.failed()
14135
+ p Not saved`
14136
+ }
14137
+ };
14138
+ });
14139
+
13825
14140
  // src/compiler/deprecated-lints-1-106.ts
13826
14141
  var SCHEMA_BUILDERS;
13827
14142
  var init_deprecated_lints_1_106 = __esm(() => {
@@ -13831,7 +14146,7 @@ var init_deprecated_lints_1_106 = __esm(() => {
13831
14146
  group: "deprecated",
13832
14147
  since: "1.106",
13833
14148
  site: true,
13834
- summary: "The PascalCase builders of `s` before 1.106, which kay's own lowercase builders replace, each taking the same field options (`optional`, `default`, `error`, `label`, `description`, `example`) and short names for the rest: `s.String` is `s.string` (`min`, `max`), `s.Integer` `s.int`, `s.Number` and `s.Numeric` `s.number`, `s.Boolean` and `s.BooleanString` `s.boolean`, `s.Array` `s.list`, `s.UnionEnum` and `s.UnionKeys` `s.enum`, and `s.Date`, `s.Literal`, `s.Union`, `s.Object`, `s.File`, `s.Files`, `s.Secret` and `s.Public` their lowercase names; `s.Optional(field)` is `optional: true` in the options of the field; an `s.Object({ ... })` that is the schema of an `action` or a `defineEnv` is the record of fields alone; and a file size written `'2m'` is `'2mb'`. The old names work until 2.0. Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. The fix renames the builder and the options that changed; an `s.Optional` around anything but one of these builders, such as a helper of `kay/content`, is left as it is. A lowercase `s.object` refuses a key its shape lacks where kay reads the schema itself (collection frontmatter, `defineEnv`), where `s.Object` let it by: write `{ extra: 'strip' }` where the old way is wanted. A query, the headers and the cookies of a request carry keys no schema names, so their unknown keys are dropped whatever the schema says.",
14149
+ 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.",
13835
14150
  wrong: `--- server
13836
14151
  import { action, s } from 'kay'
13837
14152
 
@@ -13848,6 +14163,32 @@ p x`
13848
14163
  };
13849
14164
  });
13850
14165
 
14166
+ // src/compiler/deprecated-lints-1-107.ts
14167
+ var ACTION_OPTIONS;
14168
+ var init_deprecated_lints_1_107 = __esm(() => {
14169
+ ACTION_OPTIONS = {
14170
+ "deprecated-action-options": {
14171
+ level: "warn",
14172
+ group: "deprecated",
14173
+ since: "1.107",
14174
+ site: true,
14175
+ 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.",
14176
+ wrong: `--- server
14177
+ import { action, s } from 'kay'
14178
+
14179
+ export const add = action({ title: s.string() }, ({ title }) => title, { maxSize: '1mb' })
14180
+ ---
14181
+ p x`,
14182
+ right: `--- server
14183
+ import { action, s } from 'kay'
14184
+
14185
+ export const add = action({ input: { title: s.string() }, maxSize: '1mb' }, ({ title }) => title)
14186
+ ---
14187
+ p x`
14188
+ }
14189
+ };
14190
+ });
14191
+
13851
14192
  // src/compiler/deprecated-typed-lints.ts
13852
14193
  var TYPED_DEPRECATIONS;
13853
14194
  var init_deprecated_typed_lints = __esm(() => {
@@ -13923,96 +14264,14 @@ p {names()}`
13923
14264
  var DEPRECATED_LINTS;
13924
14265
  var init_deprecated_lints = __esm(() => {
13925
14266
  init_deprecated_auth_lints();
14267
+ init_deprecated_lints_1_105();
13926
14268
  init_deprecated_lints_1_106();
14269
+ init_deprecated_lints_1_107();
13927
14270
  init_deprecated_typed_lints();
13928
14271
  DEPRECATED_LINTS = {
13929
14272
  ...SCHEMA_BUILDERS,
13930
- "deprecated-source-readers": {
13931
- level: "warn",
13932
- group: "deprecated",
13933
- since: "1.105",
13934
- site: true,
13935
- 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.",
13936
- wrong: `---
13937
- import { local, resource } from 'kay'
13938
- import notesApi from '../api/notes'
13939
- import { save } from './notes'
13940
-
13941
- const list = resource(notesApi, '/')
13942
- const notes = local({ key: 'id', read: () => [], put: save })
13943
- ---
13944
- p {list.value()?.length} on the server, {notes.rows().length} here, {notes.unsynced()} waiting`,
13945
- right: `---
13946
- import { local, resource } from 'kay'
13947
- import notesApi from '../api/notes'
13948
- import { save } from './notes'
13949
-
13950
- const list = resource(notesApi, '/')
13951
- const notes = local({ key: 'id', read: () => [], put: save })
13952
- ---
13953
- p {list.data()?.length} on the server, {notes.data().length} here, {notes.sync.queued()} waiting`
13954
- },
13955
- "deprecated-live-api": {
13956
- level: "warn",
13957
- group: "deprecated",
13958
- since: "1.105",
13959
- site: true,
13960
- 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.",
13961
- wrong: `// src/live.ts
13962
- import { live } from 'kay'
13963
-
13964
- export const room = live((id: string) => ({ id, users: 0 }))
13965
-
13966
- room.set('lobby', { id: 'lobby', users: 3 })`,
13967
- right: `// src/live.ts
13968
- import { live } from 'kay'
13969
-
13970
- export const room = live((id: string) => ({ id, users: 0 }))
13971
-
13972
- room.set({ id: 'lobby', users: 3 }, { key: 'lobby' })`
13973
- },
13974
- "deprecated-action-type": {
13975
- level: "warn",
13976
- group: "deprecated",
13977
- since: "1.105",
13978
- site: true,
13979
- 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.",
13980
- wrong: `---
13981
- import type { Action } from 'kay'
13982
-
13983
- const { run } = props<{ run: Action<never, unknown> }>()
13984
- ---
13985
- form(action={run})
13986
- button Go`,
13987
- right: `---
13988
- import type { Action } from 'kay'
13989
-
13990
- const { run } = props<{ run: Action }>()
13991
- ---
13992
- form(action={run})
13993
- button Go`
13994
- },
13995
- "deprecated-action-readers": {
13996
- level: "warn",
13997
- group: "deprecated",
13998
- since: "1.105",
13999
- site: true,
14000
- 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.",
14001
- wrong: `---
14002
- import { add } from './notes.kay'
14003
- ---
14004
- form(action={add})
14005
- input(name="title" aria-invalid={add.error('title') ? 'true' : undefined})
14006
- if add.failed()
14007
- p Not saved`,
14008
- right: `---
14009
- import { add } from './notes.kay'
14010
- ---
14011
- form(action={add})
14012
- input(name="title" aria-invalid={add.form.error('title') ? 'true' : undefined})
14013
- if add.form.failed()
14014
- p Not saved`
14015
- },
14273
+ ...ACTION_OPTIONS,
14274
+ ...SOURCE_READERS,
14016
14275
  "deprecated-ui-props": {
14017
14276
  level: "warn",
14018
14277
  group: "deprecated",
@@ -14051,43 +14310,6 @@ Card(class={{ head: 'p-6' }})`,
14051
14310
  import Card from './card.kay'
14052
14311
  ---
14053
14312
  Card(parts={{ head: 'p-6' }})`
14054
- },
14055
- "deprecated-script-fence": {
14056
- level: "warn",
14057
- group: "deprecated",
14058
- since: "1.102",
14059
- 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>`.",
14060
- wrong: `--- script
14061
- const { title } = props<{ title: string }>()
14062
- ---
14063
- h1 {title}`,
14064
- right: `---
14065
- const { title } = props<{ title: string }>()
14066
- ---
14067
- h1 {title}`
14068
- },
14069
- "deprecated-schema-type": {
14070
- level: "warn",
14071
- group: "deprecated",
14072
- since: "1.103",
14073
- site: true,
14074
- 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.",
14075
- wrong: `---
14076
- import type { TSchema } from 'kay/library'
14077
-
14078
- export function check<Fields extends TSchema>(fields: Fields) {
14079
- return fields
14080
- }
14081
- ---
14082
- p x`,
14083
- right: `---
14084
- import type { Schema } from 'kay/library'
14085
-
14086
- export function check<Fields extends Schema>(fields: Fields) {
14087
- return fields
14088
- }
14089
- ---
14090
- p x`
14091
14313
  },
14092
14314
  "deprecated-package-names": {
14093
14315
  level: "warn",
@@ -15202,6 +15424,32 @@ for row, i of rows() key={i}
15202
15424
  };
15203
15425
  });
15204
15426
 
15427
+ // src/compiler/schema-lints.ts
15428
+ var SCHEMA_LINTS;
15429
+ var init_schema_lints = __esm(() => {
15430
+ SCHEMA_LINTS = {
15431
+ "schema-without-json-schema": {
15432
+ level: "warn",
15433
+ group: "forms",
15434
+ site: true,
15435
+ 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.",
15436
+ wrong: `--- server
15437
+ import { action } from 'kay'
15438
+ import * as v from 'valibot'
15439
+
15440
+ export const add = action({ input: v.object({ title: v.string() }) }, ({ title }) => title)
15441
+ ---
15442
+ p x`,
15443
+ right: `--- server
15444
+ import { action, s } from 'kay'
15445
+
15446
+ export const add = action({ input: { title: s.string({ max: 200 }) } }, ({ title }) => title)
15447
+ ---
15448
+ p x`
15449
+ }
15450
+ };
15451
+ });
15452
+
15205
15453
  // src/compiler/serial-awaits.ts
15206
15454
  function stepOf(statement) {
15207
15455
  if (statement.type !== "VariableDeclaration" || statement.kind !== "const" || statement.declarations.length !== 1)
@@ -15303,11 +15551,13 @@ var ROUTE_LINTS;
15303
15551
  var init_route_lints = __esm(() => {
15304
15552
  init_link_flags();
15305
15553
  init_loop_lints();
15554
+ init_schema_lints();
15306
15555
  init_serial_awaits();
15307
15556
  ROUTE_LINTS = {
15308
15557
  ...SERIAL_AWAITS_LINTS,
15309
15558
  ...LOOP_LINTS,
15310
15559
  ...LINK_LINTS,
15560
+ ...SCHEMA_LINTS,
15311
15561
  "text-size-colour": {
15312
15562
  level: "warn",
15313
15563
  group: "code",
@@ -19338,9 +19588,11 @@ function compileKay(original, filename, options = {}) {
19338
19588
  const hydratableServer = options.output === "html" && options.hydratable === true;
19339
19589
  const twin = hydratableServer && !options.twinBuild && island === undefined && !routeFile ? `./${basename5(filename)}${ISLAND_TWIN}` : undefined;
19340
19590
  const pin = file.pin;
19591
+ const hydrated = hydratableServer && (island !== undefined || options.twinBuild === true);
19592
+ const lazy = lazyImportsOf(file, script.imports, options, hydrated, routeFile, client);
19341
19593
  const rawCause = island === undefined ? undefined : islandCause(file, script) ?? browserCause(file, script, live);
19342
19594
  const cause = withInteractive(realCause(rawCause, expansion, original), script);
19343
- 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: hydratableServer && (island !== undefined || options.twinBuild === true), moduleId: islandId(filename, options.root), includeServer: options.includeServer, params: options.params, paramTypes: options.paramTypes, outerQueries: options.outerQueries, outerGuards: options.outerGuards, outerSlots: options.outerSlots, layoutFile: basename5(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) => expansion.real(offset) } : undefined, relocateImport: options.relocateImport, contextModule: options.check === true ? options.contextModule : undefined, ui: options.output === undefined ? undefined : options.ui, uiAdded: options.output === undefined ? options.ui : undefined, errorPage: isErrorPage(basename5(filename)), cardPage: basename5(filename) === CARD_PAGE, special: basename5(filename).startsWith("_") && basename5(filename) !== LAYOUT };
19595
+ 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: basename5(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) => 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(basename5(filename)), cardPage: basename5(filename) === CARD_PAGE, special: basename5(filename).startsWith("_") && basename5(filename) !== LAYOUT };
19344
19596
  const analysis = generate(file, script, server, { ...generateOptions, name: SELF });
19345
19597
  const imported = new Map([...script.imports, ...server?.imports ?? []].flatMap((binding) => {
19346
19598
  const kind = binding.typeOnly ? undefined : kindOf(options.importedSignals, binding.source, binding.imported);
@@ -19377,7 +19629,7 @@ function compileKay(original, filename, options = {}) {
19377
19629
  const fenceLints = [script.fence, script.moduleFence, server?.fence].flatMap((fence) => fence ? [...cssImportsWithoutText(fence), ...asyncReplies(fence), ...openRedirects(fence), ...missingCaptchas(fence), ...unreturnedFails(fence)] : []);
19378
19630
  const browserScript = (island !== undefined || options.insideIsland === true) && !routeFile ? scriptFences(script) : [];
19379
19631
  const unusedLints = broken ? [] : [...unreadNames(source, file.template, script, server, found.findings), ...constantSignals(source, [file.script, file.module], found.findings)];
19380
- 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), ...spelledOutScriptFence(file), ...retiredAllowComments(source), ...deprecatedIslandForms(file, script), ...deprecatedIslandAttributes(file), ...deprecatedChildrenProp(file, script), ...linkFlags(file), ...deprecatedPartsClass(file), ...deprecatedPageSettings(source, server), ...ignoredIslandExport(script, island !== undefined), ...malformedInteractive(script));
19632
+ 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));
19381
19633
  }
19382
19634
  if (checked && pin !== undefined)
19383
19635
  diagnostics.push(...markerMismatch(pin, pageFile));
@@ -19572,13 +19824,13 @@ var init_compiler = __esm(() => {
19572
19824
  init_deprecated_island();
19573
19825
  init_deprecated_page();
19574
19826
  init_deprecated_parts();
19575
- init_deprecated_script_fence();
19576
19827
  init_fence_checks();
19577
19828
  init_fence_redirects();
19578
19829
  init_host();
19579
19830
  init_island_arguments();
19580
19831
  init_island_cause();
19581
19832
  init_island_marker();
19833
+ init_lazy_imports();
19582
19834
  init_link_flags();
19583
19835
  init_lints();
19584
19836
  init_mapping();
@@ -20510,7 +20762,7 @@ var GUARD = "_guard.ts";
20510
20762
  var PARENT = "..";
20511
20763
  var OUTSIDE = "__";
20512
20764
  var WORD_CHARACTER = /[\w$]/;
20513
- var codeOf2 = new WeakMap;
20765
+ var codeOf3 = new WeakMap;
20514
20766
  function shadowPath(root, file) {
20515
20767
  return join11(projectPaths(root).types, `${relative3(root, file).split(sep4).map((part) => part === PARENT ? OUTSIDE : part).join(sep4)}.tsx`);
20516
20768
  }
@@ -20646,10 +20898,10 @@ function inFences(shadow, start, end) {
20646
20898
  return codeIn(shadow).fences.some((span) => start >= span.start && end <= span.end);
20647
20899
  }
20648
20900
  function codeIn(shadow) {
20649
- let spans = codeOf2.get(shadow);
20901
+ let spans = codeOf3.get(shadow);
20650
20902
  if (!spans) {
20651
20903
  const { script, server, module, template } = parseKay(shadow.source);
20652
- codeOf2.set(shadow, spans = { fences: [script, server, module].filter((span) => span !== undefined), expressions: expressionSpans(template) });
20904
+ codeOf3.set(shadow, spans = { fences: [script, server, module].filter((span) => span !== undefined), expressions: expressionSpans(template) });
20653
20905
  }
20654
20906
  return spans;
20655
20907
  }
@@ -20786,7 +21038,7 @@ var NON_BLANK = /\S/;
20786
21038
  var NON_BLANK_OR_END = /\S|$/;
20787
21039
  var SPACE7 = /\s/;
20788
21040
  var INDENTATION = /^[ \t]*$/;
20789
- var LINE_COMMENT = /\/\/.*$/;
21041
+ var LINE_COMMENT2 = /\/\/.*$/;
20790
21042
  var STATEMENT_START2 = /[^\s)\]}]/;
20791
21043
  var EXPECTED_SPACES = /of (\d+) spaces?/;
20792
21044
  var FOUND_SPACES = /found (\d+)\./;
@@ -20889,7 +21141,7 @@ function alignedAfterRewrite(linted, line) {
20889
21141
  } else if (character === "(" || character === "[" || character === "{") {
20890
21142
  const call = character === "(";
20891
21143
  const opened = lineStart(tsx, at);
20892
- brackets.push({ call, line: opened, aligned: call && NON_BLANK.test(tsx.slice(at + 1, lineEnd2(tsx, at)).replace(LINE_COMMENT, "")), arguments: 0, pending: call, locked: false });
21144
+ brackets.push({ call, line: opened, aligned: call && NON_BLANK.test(tsx.slice(at + 1, lineEnd2(tsx, at)).replace(LINE_COMMENT2, "")), arguments: 0, pending: call, locked: false });
20893
21145
  } else if (character === ")" || character === "]" || character === "}") {
20894
21146
  brackets.pop();
20895
21147
  } else if (character === "," && top?.call) {