@kayjs/kay 1.105.0 → 1.107.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/eslint.js +777 -210
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +2 -2
- package/llms/actions-from-islands.md +2 -2
- package/llms/actions-refused-fields.md +22 -0
- package/llms/actions.md +24 -41
- package/llms/analytics.md +1 -1
- package/llms/api-from-islands.md +1 -1
- package/llms/api-routes.md +6 -6
- package/llms/browser-only.md +1 -1
- package/llms/check-and-tools.md +1 -1
- package/llms/code-lints.md +2 -2
- package/llms/compiler-api.md +1 -1
- package/llms/component-libraries.md +1 -0
- package/llms/components.md +1 -1
- package/llms/content-cms.md +1 -1
- package/llms/content-markdown-to-caching.md +1 -1
- package/llms/content-preview.md +2 -2
- package/llms/content.md +21 -21
- package/llms/deprecated-lints-1-105-libraries.md +2 -0
- package/llms/deprecated-lints-1-105.md +3 -3
- package/llms/deprecated-lints.md +4 -4
- package/llms/dev-tool.md +2 -2
- package/llms/environment.md +22 -22
- package/llms/files.md +5 -5
- package/llms/island-and-form-lints.md +1 -0
- package/llms/islands-state-to-ids.md +2 -1
- package/llms/islands.md +10 -1
- package/llms/local-collections.md +2 -2
- package/llms/mcp.md +2 -1
- package/llms/navigation-from-code.md +1 -1
- package/llms/notifications.md +4 -2
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +3 -3
- package/llms/rate-limits.md +1 -1
- package/llms/recipes.md +16 -16
- package/llms/rooms.md +4 -4
- package/llms/routing-endpoints-and-base.md +1 -1
- package/llms/routing.md +5 -5
- package/llms/schemas.md +14 -7
- package/llms/server.md +7 -7
- package/llms/site.md +9 -9
- package/llms/sitemap-search-fonts.md +2 -0
- package/llms/styles-and-assets.md +2 -1
- package/llms/templates-elements-slots-snippets.md +2 -2
- package/llms/testing-browser.md +20 -0
- package/llms/testing.md +1 -1
- package/llms/upgrading-1-105-config.md +2 -2
- package/llms/upgrading.md +37 -4
- package/llms/whats-new-archive.md +35 -66
- package/llms/whats-new.md +47 -28
- package/llms.txt +1 -1
- package/package.json +24 -11
- package/src/add.ts +1 -1
- package/src/build/class-table.ts +2 -2
- package/src/build/client.ts +27 -30
- package/src/build/entry-files.ts +19 -0
- package/src/build/lazy-components.ts +130 -0
- package/src/build/lazy-manifest.ts +56 -0
- package/src/build/lazy-stubs.ts +31 -0
- package/src/build/plugin.ts +16 -11
- package/src/build/runtime-chunk.ts +1 -1
- package/src/build/styles.ts +3 -3
- package/src/build/transform.ts +19 -7
- package/src/build/ui-layers.ts +30 -0
- package/src/build/ui.ts +108 -11
- package/src/build/variants.ts +125 -46
- package/src/build/worker-bundle.ts +6 -0
- package/src/check/action-options.ts +56 -0
- package/src/check/boot.ts +22 -1
- package/src/check/call-result.ts +242 -0
- package/src/check/config-objects.ts +17 -2
- package/src/check/diagnose.ts +22 -0
- package/src/check/handler-events.ts +149 -0
- package/src/check/index.ts +6 -2
- package/src/check/link-flag-tests.ts +130 -0
- package/src/check/project.ts +4 -3
- package/src/check/refusal-calls.ts +2 -2
- package/src/check/regroup.ts +5 -3
- package/src/check/renamed-packages.ts +58 -14
- package/src/check/schema-builders.ts +256 -0
- package/src/check/schema-json.ts +226 -0
- package/src/check/secret-keys.ts +15 -2
- package/src/check/shadow-types.ts +13 -9
- package/src/check/template-hints.ts +1 -1
- package/src/check/tool-labels.ts +11 -9
- package/src/check/ui-types.ts +4 -3
- package/src/check/ui.ts +14 -11
- package/src/commands/env-declare.ts +18 -6
- package/src/commands/routes.ts +1 -1
- package/src/compiler/a11y.ts +8 -1
- package/src/compiler/ast.ts +1 -1
- package/src/compiler/bound-props.ts +1 -1
- package/src/compiler/codegen.ts +13 -23
- package/src/compiler/deprecated-lints-1-105.ts +41 -0
- package/src/compiler/deprecated-lints-1-106.ts +14 -0
- package/src/compiler/deprecated-lints-1-107.ts +14 -0
- package/src/compiler/deprecated-lints.ts +17 -60
- package/src/compiler/deprecated-typed-lints.ts +23 -0
- package/src/compiler/dom-here.ts +72 -0
- package/src/compiler/dom.ts +23 -23
- package/src/compiler/fence-checks.ts +12 -11
- package/src/compiler/field-described.ts +2 -2
- package/src/compiler/helper-imports.ts +1 -1
- package/src/compiler/html-fields.ts +92 -0
- package/src/compiler/html-initial.ts +5 -3
- package/src/compiler/html.ts +14 -31
- package/src/compiler/import-edits.ts +15 -0
- package/src/compiler/index.ts +10 -3
- package/src/compiler/island-declaration.ts +15 -0
- package/src/compiler/items.ts +5 -5
- package/src/compiler/kay-exports.ts +1 -0
- package/src/compiler/lazy-imports.ts +357 -0
- package/src/compiler/link-flags.ts +6 -5
- package/src/compiler/lints.ts +12 -12
- package/src/compiler/parser.ts +2 -2
- package/src/compiler/rest-omits.ts +15 -0
- package/src/compiler/route-lints.ts +2 -0
- package/src/compiler/schema-lints.ts +13 -0
- package/src/compiler/script-server.ts +6 -3
- package/src/config-loader.ts +10 -2
- package/src/config-resolve.ts +3 -1
- package/src/config-shape.ts +2 -2
- package/src/config.ts +20 -4
- package/src/content/markdown.ts +2 -3
- package/src/content/validate.ts +1 -1
- package/src/generate-resource.ts +9 -9
- package/src/generate.ts +1 -1
- package/src/mcp/guards.ts +1 -1
- package/src/mcp/tools.ts +1 -1
- package/src/migrate/content.ts +61 -55
- package/src/new.ts +6 -2
- package/src/runtime/action-shared.ts +2 -2
- package/src/runtime/action.ts +51 -4
- package/src/runtime/client.ts +10 -0
- package/src/runtime/dom-lazy.ts +276 -0
- package/src/runtime/field-errors.ts +58 -0
- package/src/runtime/field-refusal.ts +179 -0
- package/src/runtime/form-types.ts +99 -0
- package/src/runtime/form.ts +25 -9
- package/src/runtime/html.ts +42 -6
- package/src/runtime/index.ts +2 -0
- package/src/runtime/island.server.ts +36 -2
- package/src/runtime/markdown-autolink.ts +69 -0
- package/src/runtime/markdown-render.client.ts +39 -3
- package/src/runtime/markdown.client.ts +6 -3
- package/src/runtime/markdown.server.ts +6 -3
- package/src/runtime/markdown.ts +125 -1
- package/src/runtime/navigate-api.ts +10 -5
- package/src/runtime/persist.ts +7 -7
- package/src/runtime/query-param.ts +1 -1
- package/src/runtime/reactive.ts +14 -0
- package/src/runtime/sanitize.ts +3 -1
- package/src/runtime/schema-record.ts +32 -0
- package/src/runtime/schema.client.ts +101 -14
- package/src/runtime/schema.ts +328 -26
- package/src/runtime/standard-schema.ts +32 -0
- package/src/runtime/swap-focus.ts +59 -11
- package/src/runtime/validate-run.client.ts +179 -0
- package/src/runtime/validate.client.ts +11 -0
- package/src/runtime/validate.ts +4 -137
- package/src/server/action-module.ts +16 -0
- package/src/server/actions.ts +54 -57
- package/src/server/answer.ts +102 -0
- package/src/server/api-input.ts +166 -0
- package/src/server/api-modules.ts +1 -1
- package/src/server/api.ts +12 -32
- package/src/server/app-stages.ts +38 -26
- package/src/server/app.ts +5 -2
- package/src/server/client.ts +2 -0
- package/src/server/dev-ui.ts +2 -2
- package/src/server/dev.ts +7 -9
- package/src/server/env-state.ts +1 -1
- package/src/server/env.ts +11 -3
- package/src/server/favicon.ts +47 -1
- package/src/server/file-limit.ts +7 -1
- package/src/server/forms.ts +1 -1
- package/src/server/host-allowlist.ts +7 -7
- package/src/server/image-metadata-bmff.ts +1 -1
- package/src/server/index.ts +2 -0
- package/src/server/kay-routes.ts +221 -0
- package/src/server/kay-server.ts +228 -0
- package/src/server/kept-exports.ts +1 -0
- package/src/server/kept-pages.ts +3 -3
- package/src/server/library.ts +2 -2
- package/src/server/mcp.ts +14 -13
- package/src/server/notifications.ts +4 -2
- package/src/server/offline.ts +24 -7
- package/src/server/openapi.ts +12 -3
- package/src/server/phases.ts +249 -0
- package/src/server/protection.ts +6 -6
- package/src/server/proxy-key.ts +8 -8
- package/src/server/push-settings.ts +16 -2
- package/src/server/push.ts +12 -4
- package/src/server/query.ts +17 -31
- package/src/server/receive.ts +43 -0
- package/src/server/render-document.ts +13 -3
- package/src/server/render.ts +1 -1
- package/src/server/request-context.ts +137 -0
- package/src/server/schema-check.ts +1 -1
- package/src/server/scope.ts +20 -13
- package/src/server/signals.ts +4 -4
- package/src/server/socket.ts +19 -47
- package/src/server/stream.ts +1 -1
- package/src/server/validate.ts +346 -0
- package/src/template-ws.ts +1 -1
- package/src/test/a11y-dom.ts +70 -0
- package/src/test/html-snapshot.ts +103 -0
- package/src/test/index.ts +2 -1
- package/src/test/mount.ts +14 -3
- package/src/test/page-checks.ts +12 -0
- package/src/test/screenshot-match.ts +2 -2
- package/src/test/shared-modules.ts +27 -5
- package/src/test/site-types.ts +5 -1
- package/types/build/class-table.d.ts +1 -1
- package/types/build/class-table.d.ts.map +1 -1
- package/types/build/client.d.ts +3 -2
- package/types/build/client.d.ts.map +1 -1
- package/types/build/entry-files.d.ts +4 -0
- package/types/build/entry-files.d.ts.map +1 -0
- package/types/build/lazy-components.d.ts +6 -0
- package/types/build/lazy-components.d.ts.map +1 -0
- package/types/build/lazy-manifest.d.ts +19 -0
- package/types/build/lazy-manifest.d.ts.map +1 -0
- package/types/build/lazy-stubs.d.ts +5 -0
- package/types/build/lazy-stubs.d.ts.map +1 -0
- package/types/build/plugin.d.ts +1 -0
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/transform.d.ts +4 -1
- package/types/build/transform.d.ts.map +1 -1
- package/types/build/ui-layers.d.ts +5 -0
- package/types/build/ui-layers.d.ts.map +1 -0
- package/types/build/ui.d.ts +7 -0
- package/types/build/ui.d.ts.map +1 -1
- package/types/build/variants.d.ts +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/build/worker-bundle.d.ts +1 -0
- package/types/build/worker-bundle.d.ts.map +1 -1
- package/types/check/action-options.d.ts +3 -0
- package/types/check/action-options.d.ts.map +1 -0
- package/types/check/boot.d.ts.map +1 -1
- package/types/check/call-result.d.ts +7 -0
- package/types/check/call-result.d.ts.map +1 -0
- package/types/check/config-objects.d.ts.map +1 -1
- package/types/check/diagnose.d.ts.map +1 -1
- package/types/check/handler-events.d.ts +9 -0
- package/types/check/handler-events.d.ts.map +1 -0
- package/types/check/index.d.ts +1 -0
- package/types/check/index.d.ts.map +1 -1
- package/types/check/link-flag-tests.d.ts +4 -0
- package/types/check/link-flag-tests.d.ts.map +1 -0
- package/types/check/project.d.ts.map +1 -1
- package/types/check/regroup.d.ts +1 -1
- package/types/check/regroup.d.ts.map +1 -1
- package/types/check/renamed-packages.d.ts +1 -0
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/schema-builders.d.ts +3 -0
- package/types/check/schema-builders.d.ts.map +1 -0
- package/types/check/schema-json.d.ts +3 -0
- package/types/check/schema-json.d.ts.map +1 -0
- package/types/check/secret-keys.d.ts.map +1 -1
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/check/template-hints.d.ts +1 -0
- package/types/check/template-hints.d.ts.map +1 -1
- package/types/check/tool-labels.d.ts.map +1 -1
- package/types/check/ui-types.d.ts.map +1 -1
- package/types/check/ui.d.ts.map +1 -1
- package/types/commands/env-declare.d.ts.map +1 -1
- package/types/compiler/a11y.d.ts.map +1 -1
- package/types/compiler/bound-props.d.ts +1 -0
- package/types/compiler/bound-props.d.ts.map +1 -1
- package/types/compiler/codegen.d.ts +3 -0
- package/types/compiler/codegen.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-105.d.ts +39 -0
- package/types/compiler/deprecated-lints-1-105.d.ts.map +1 -0
- package/types/compiler/deprecated-lints-1-106.d.ts +12 -0
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -0
- package/types/compiler/deprecated-lints-1-107.d.ts +12 -0
- package/types/compiler/deprecated-lints-1-107.d.ts.map +1 -0
- package/types/compiler/deprecated-lints.d.ts +41 -22
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/deprecated-typed-lints.d.ts +21 -0
- package/types/compiler/deprecated-typed-lints.d.ts.map +1 -0
- package/types/compiler/dom-here.d.ts +14 -0
- package/types/compiler/dom-here.d.ts.map +1 -0
- package/types/compiler/dom.d.ts +1 -0
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/fence-checks.d.ts.map +1 -1
- package/types/compiler/field-described.d.ts +1 -1
- package/types/compiler/field-described.d.ts.map +1 -1
- package/types/compiler/html-fields.d.ts +19 -0
- package/types/compiler/html-fields.d.ts.map +1 -0
- package/types/compiler/html-initial.d.ts +3 -2
- package/types/compiler/html-initial.d.ts.map +1 -1
- package/types/compiler/html.d.ts.map +1 -1
- package/types/compiler/import-edits.d.ts +1 -0
- package/types/compiler/import-edits.d.ts.map +1 -1
- package/types/compiler/index.d.ts +3 -0
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-declaration.d.ts +5 -0
- package/types/compiler/island-declaration.d.ts.map +1 -1
- package/types/compiler/items.d.ts +4 -1
- package/types/compiler/items.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/lazy-imports.d.ts +33 -0
- package/types/compiler/lazy-imports.d.ts.map +1 -0
- package/types/compiler/link-flags.d.ts +6 -0
- package/types/compiler/link-flags.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +61 -34
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/rest-omits.d.ts +4 -0
- package/types/compiler/rest-omits.d.ts.map +1 -0
- package/types/compiler/route-lints.d.ts +8 -0
- package/types/compiler/route-lints.d.ts.map +1 -1
- package/types/compiler/schema-lints.d.ts +11 -0
- package/types/compiler/schema-lints.d.ts.map +1 -0
- package/types/compiler/script-server.d.ts.map +1 -1
- package/types/config-loader.d.ts.map +1 -1
- package/types/config-resolve.d.ts.map +1 -1
- package/types/config.d.ts +15 -2
- package/types/config.d.ts.map +1 -1
- package/types/content/markdown.d.ts.map +1 -1
- package/types/migrate/content.d.ts.map +1 -1
- package/types/new.d.ts +1 -0
- package/types/new.d.ts.map +1 -1
- package/types/runtime/action-shared.d.ts +1 -1
- package/types/runtime/action-shared.d.ts.map +1 -1
- package/types/runtime/action.d.ts +29 -1
- package/types/runtime/action.d.ts.map +1 -1
- package/types/runtime/client.d.ts.map +1 -1
- package/types/runtime/dom-lazy.d.ts +6 -0
- package/types/runtime/dom-lazy.d.ts.map +1 -0
- package/types/runtime/field-errors.d.ts +4 -0
- package/types/runtime/field-errors.d.ts.map +1 -0
- package/types/runtime/field-refusal.d.ts +37 -0
- package/types/runtime/field-refusal.d.ts.map +1 -0
- package/types/runtime/form-types.d.ts +6 -0
- package/types/runtime/form-types.d.ts.map +1 -0
- package/types/runtime/form.d.ts +4 -2
- package/types/runtime/form.d.ts.map +1 -1
- package/types/runtime/html.d.ts +3 -0
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -0
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +2 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/markdown-autolink.d.ts +11 -0
- package/types/runtime/markdown-autolink.d.ts.map +1 -0
- package/types/runtime/markdown-render.client.d.ts +2 -1
- package/types/runtime/markdown-render.client.d.ts.map +1 -1
- package/types/runtime/markdown.client.d.ts +3 -1
- package/types/runtime/markdown.client.d.ts.map +1 -1
- package/types/runtime/markdown.d.ts +11 -0
- package/types/runtime/markdown.d.ts.map +1 -1
- package/types/runtime/markdown.server.d.ts +3 -1
- package/types/runtime/markdown.server.d.ts.map +1 -1
- package/types/runtime/navigate-api.d.ts +1 -1
- package/types/runtime/navigate-api.d.ts.map +1 -1
- package/types/runtime/persist.d.ts +2 -2
- package/types/runtime/persist.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +3 -0
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/sanitize.d.ts.map +1 -1
- package/types/runtime/schema-record.d.ts +9 -0
- package/types/runtime/schema-record.d.ts.map +1 -0
- package/types/runtime/schema.client.d.ts.map +1 -1
- package/types/runtime/schema.d.ts +99 -10
- package/types/runtime/schema.d.ts.map +1 -1
- package/types/runtime/standard-schema.d.ts +37 -0
- package/types/runtime/standard-schema.d.ts.map +1 -0
- package/types/runtime/swap-focus.d.ts.map +1 -1
- package/types/runtime/validate-run.client.d.ts +4 -0
- package/types/runtime/validate-run.client.d.ts.map +1 -0
- package/types/runtime/validate.client.d.ts +4 -0
- package/types/runtime/validate.client.d.ts.map +1 -0
- package/types/runtime/validate.d.ts +1 -21
- package/types/runtime/validate.d.ts.map +1 -1
- package/types/server/action-module.d.ts +2 -0
- package/types/server/action-module.d.ts.map +1 -0
- package/types/server/actions.d.ts +1 -0
- package/types/server/actions.d.ts.map +1 -1
- package/types/server/answer.d.ts +6 -0
- package/types/server/answer.d.ts.map +1 -0
- package/types/server/api-input.d.ts +19 -0
- package/types/server/api-input.d.ts.map +1 -0
- package/types/server/api.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +7 -3
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +2 -0
- package/types/server/app.d.ts.map +1 -1
- package/types/server/client.d.ts +1 -0
- package/types/server/client.d.ts.map +1 -1
- package/types/server/dev.d.ts +1 -1
- package/types/server/dev.d.ts.map +1 -1
- package/types/server/env-state.d.ts.map +1 -1
- package/types/server/env.d.ts +5 -1
- package/types/server/env.d.ts.map +1 -1
- package/types/server/favicon.d.ts +3 -1
- package/types/server/favicon.d.ts.map +1 -1
- package/types/server/file-limit.d.ts.map +1 -1
- package/types/server/host-allowlist.d.ts +3 -3
- package/types/server/host-allowlist.d.ts.map +1 -1
- package/types/server/index.d.ts +2 -0
- package/types/server/index.d.ts.map +1 -1
- package/types/server/kay-routes.d.ts +47 -0
- package/types/server/kay-routes.d.ts.map +1 -0
- package/types/server/kay-server.d.ts +25 -0
- package/types/server/kay-server.d.ts.map +1 -0
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/kept-pages.d.ts +1 -1
- package/types/server/kept-pages.d.ts.map +1 -1
- package/types/server/library.d.ts +2 -1
- package/types/server/library.d.ts.map +1 -1
- package/types/server/mcp.d.ts +1 -1
- package/types/server/mcp.d.ts.map +1 -1
- package/types/server/notifications.d.ts +2 -1
- package/types/server/notifications.d.ts.map +1 -1
- package/types/server/offline.d.ts.map +1 -1
- package/types/server/openapi.d.ts.map +1 -1
- package/types/server/phases.d.ts +36 -0
- package/types/server/phases.d.ts.map +1 -0
- package/types/server/protection.d.ts +3 -2
- package/types/server/protection.d.ts.map +1 -1
- package/types/server/proxy-key.d.ts +3 -3
- package/types/server/proxy-key.d.ts.map +1 -1
- package/types/server/push-settings.d.ts +1 -1
- package/types/server/push-settings.d.ts.map +1 -1
- package/types/server/push.d.ts +1 -0
- package/types/server/push.d.ts.map +1 -1
- package/types/server/query.d.ts.map +1 -1
- package/types/server/receive.d.ts +9 -0
- package/types/server/receive.d.ts.map +1 -0
- package/types/server/render-document.d.ts.map +1 -1
- package/types/server/request-context.d.ts +29 -0
- package/types/server/request-context.d.ts.map +1 -0
- package/types/server/schema-check.d.ts +1 -0
- package/types/server/schema-check.d.ts.map +1 -1
- package/types/server/scope.d.ts +1 -1
- package/types/server/scope.d.ts.map +1 -1
- package/types/server/socket.d.ts +3 -5
- package/types/server/socket.d.ts.map +1 -1
- package/types/server/validate.d.ts +26 -0
- package/types/server/validate.d.ts.map +1 -0
- package/types/test/a11y-dom.d.ts +20 -0
- package/types/test/a11y-dom.d.ts.map +1 -0
- package/types/test/html-snapshot.d.ts +4 -0
- package/types/test/html-snapshot.d.ts.map +1 -0
- package/types/test/index.d.ts.map +1 -1
- package/types/test/mount.d.ts +3 -0
- package/types/test/mount.d.ts.map +1 -1
- package/types/test/page-checks.d.ts +6 -0
- package/types/test/page-checks.d.ts.map +1 -0
- package/types/test/screenshot-match.d.ts +1 -1
- package/types/test/screenshot-match.d.ts.map +1 -1
- package/types/test/shared-modules.d.ts.map +1 -1
- package/types/test/site-types.d.ts +3 -1
- package/types/test/site-types.d.ts.map +1 -1
- package/src/check/schema-type.ts +0 -9
- package/src/compiler/deprecated-script-fence.ts +0 -26
- package/src/server/field-errors.ts +0 -136
- package/types/check/schema-type.d.ts +0 -3
- package/types/check/schema-type.d.ts.map +0 -1
- package/types/compiler/deprecated-script-fence.d.ts +0 -3
- package/types/compiler/deprecated-script-fence.d.ts.map +0 -1
- package/types/server/field-errors.d.ts +0 -6
- package/types/server/field-errors.d.ts.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
id = "kay"
|
|
2
2
|
name = "Kay"
|
|
3
3
|
description = "Highlighting and the kay language server for .kay components"
|
|
4
|
-
version = "1.
|
|
4
|
+
version = "1.107.0"
|
|
5
5
|
schema_version = 1
|
|
6
6
|
authors = [ "Kaynooo" ]
|
|
7
7
|
repository = "https://github.com/Kayno0o/kayjs"
|
|
8
8
|
|
|
9
9
|
[grammars.kay]
|
|
10
10
|
repository = "https://github.com/Kayno0o/kayjs"
|
|
11
|
-
rev = "v1.
|
|
11
|
+
rev = "v1.107.0"
|
|
12
12
|
path = "editors/tree-sitter-kay"
|
|
13
13
|
|
|
14
14
|
[language_servers.kay]
|
|
@@ -15,7 +15,7 @@ A third argument limits attempts and traps bots, its `protect` group holding `ra
|
|
|
15
15
|
import { s, action } from 'kay'
|
|
16
16
|
|
|
17
17
|
export const contact = action(
|
|
18
|
-
|
|
18
|
+
{ message: s.string({ max: 2000 }) },
|
|
19
19
|
async ({ message }) => message.length,
|
|
20
20
|
{ protect: { rateLimit: { max: 5, window: '1m' }, honeypot: 'website', minTime: '3s' } },
|
|
21
21
|
)
|
|
@@ -88,7 +88,7 @@ See [Rate limits](rate-limits.md#limit-attempts-in-a-guard-or-an-api-route).
|
|
|
88
88
|
- `minTime` is given `early` for a post sent too soon or `expired` for a stamp missing, forged or past `ttl`, as a page from before a restart sends.
|
|
89
89
|
- `proofOfWork` is given `missing`, `expired` or `wrong` as below.
|
|
90
90
|
- `maxSize` is given the most bytes a post may send, as a number whatever size `maxSize` was written as.
|
|
91
|
-
- Each is a string or a function; `serverError` is given the error and the action's `ctx` (see [Refused posts](actions.md#refused-posts)). A function runs in the request's locale, so it may word the refusal with `t()`; `serverError` may be async.
|
|
91
|
+
- Each is a string or a function; `serverError` is given the error and the action's `ctx` (see [Refused posts](actions-refused-fields.md#refused-posts)). A function runs in the request's locale, so it may word the refusal with `t()`; `serverError` may be async.
|
|
92
92
|
|
|
93
93
|
#### Proof of work
|
|
94
94
|
|
|
@@ -70,7 +70,7 @@ An action whose handler is an `async function*`, or returns any async iterable,
|
|
|
70
70
|
import { s, action } from 'kay'
|
|
71
71
|
import { complete } from '../data'
|
|
72
72
|
|
|
73
|
-
export const reply = action(
|
|
73
|
+
export const reply = action({ prompt: s.string({ max: 2000 }) }, async function* ({ prompt }) {
|
|
74
74
|
let text = ''
|
|
75
75
|
|
|
76
76
|
for await (const piece of complete(prompt))
|
|
@@ -118,7 +118,7 @@ p {column()}
|
|
|
118
118
|
### Calling from an island
|
|
119
119
|
|
|
120
120
|
- An island imports the action from the page and calls it, as in [Call an action from an island](#call-an-action-from-an-island): `const { ok, data, error } = await add({ title })`, or `const id = await add({ title }).orThrow()` to throw the failure.
|
|
121
|
-
- An `
|
|
121
|
+
- An optional field (`optional: true`) takes `undefined` as the field left out, `exactOptionalPropertyTypes` or not: `resize({ file, width: max ?? undefined })`. A wrong field is reported at that field, not against the `FormData` form of the call.
|
|
122
122
|
- Once a call went through, the page shows what it changed, its loads run again as `refresh()` runs them, where the page swap runs: islands whose props did not change keep their state. A page with `liveRefresh: true` in its [settings](routing.md#page-settings) is left alone when every cached key the handler invalidated (`cached(..., { live: true })`) is one the page or a `resource()` follows: its live connection, once open, shows them a moment after the answer (`x-kay-invalidated` names the keys on the answer; a streaming action's end event names them, as it goes on invalidating until the stream ends). One key not followed, more than 20 keys or a connection that is down load the page as before, and `refresh: true` always does.
|
|
123
123
|
- `add({ title }, { refresh: false })` leaves the page as it is, so a frequent write from an island (a vote, an undo) needs no API route to avoid the refresh; `add` answers a refusal as a result, as `await add(input, { refresh: false })` does.
|
|
124
124
|
- `await add.settled()` resolves once no call to `add` is in flight, whichever way they went (a stream counts until it ends; it never rejects), so an island that fired writes without awaiting them waits for them there; `save.settled()` does the same for the calls made through a `track()` handle.
|
|
@@ -26,6 +26,28 @@
|
|
|
26
26
|
- A field with a `bind:`, a spread, `disabled` or `multiple` keeps what the template gives, and one the page renders through another component is not the form's own.
|
|
27
27
|
- On a page posting no refused form, every field renders as written.
|
|
28
28
|
|
|
29
|
+
### Refused posts
|
|
30
|
+
|
|
31
|
+
- `ctx.deny(status, { message, errors, data })` is the one refusal of a guard, a page, an action and an endpoint, `refuse(status, { ... })` throws it from anywhere; `return` it so `form.failed()` types `data`. `ctx.fail` is its old spelling until 1.108 (`unreturned-fail`).
|
|
32
|
+
- A post the schema refuses, or whose handler denies with `ctx.deny(status, { data })`, is answered with the page it came from, rendered with the failure's status, rather than with a redirect.
|
|
33
|
+
- There `add.form.failed()` returns `{ status, message, values, errors, data }`, typed from the action, or `undefined`.
|
|
34
|
+
- `values` is what the form posted (fields named like a password left out).
|
|
35
|
+
- `errors` is a message per refused field, the schema's `error` option when set.
|
|
36
|
+
- `data` is what `ctx.deny` received.
|
|
37
|
+
- `return ctx.deny(409, { errors: { email: 'Already taken' } })` puts a message on a field, typed from the schema's keys, with `''` for the form's own, so `error email`, `aria-invalid`, `add.form.error('email')`, the value re-fill and an island's `ActionError.errors` (and a kayjs-ui `FormField` named `email`) follow it with and without JavaScript.
|
|
38
|
+
- A rate limit's refusal sits under `errors['']`, read by `add.form.error()`, and a text `data` is that message: `return ctx.deny(502, { data: 'Not sent; try again later' })`.
|
|
39
|
+
- The page renders as a visit of it would, through the app's plugins and the page's guards, and nothing the visitor typed is lost however long it is.
|
|
40
|
+
- Reloading it posts again, as after any form a server answers in place.
|
|
41
|
+
- The page is the one the post was sent from, as `ctx.params` reads it below, the home page when it names none or another site.
|
|
42
|
+
- Without the page swap the browser shows the action's URL, so the page carries a `base` naming its own URL, and its relative links lead where they did.
|
|
43
|
+
- Each form on it posting to an action names that page in a `kay_back` query parameter, so a post refused again renders the same page, however many times in a row, and one that goes through goes back to it.
|
|
44
|
+
- A handler that throws, a mail server down say, is logged as any server error, `onError` included, and answered as a refusal with status 500.
|
|
45
|
+
- A plain form post then renders its page with the message under the form and what was typed kept, read by `add.form.error()`, and a call answers `{ ok: false }` with it in `errors['']`.
|
|
46
|
+
- The message is `Something went wrong on our side; try again later` unless the site words it as `kay.action.serverError` ([Locales](locales-texts.md)) or the action words its own, `action(schema, handler, { messages: { serverError: 'Not sent; write to hello@example.com instead' } })`, so a handler needs no `try`/`catch` of its own to tell the visitor.
|
|
47
|
+
- `serverError` may be a function given the error and `ctx`, sync or async, to word it from what is loaded per request or the page's `ctx.locale`: `serverError: async () => 'Write to ' + (await settings.one()).email`. Its text is answered with the same status 500; one that throws, or answers a blank text, leaves kay's message (a throw logged beside the handler's error), and a redirect or denial thrown from it is no answer either.
|
|
48
|
+
- An action past its `timeout` (`serve.timeout` or the action's own) answers 504 the same way, worded `kay.action.timeout` (`This took too long; try again later`) and reported as a server error.
|
|
49
|
+
- A redirect or a guard's denial thrown is no error.
|
|
50
|
+
|
|
29
51
|
### Reading the outcome
|
|
30
52
|
|
|
31
53
|
- `add.form.failed()`, `add.data()`, `add.status()` and `add.form.error('title')` read the outcome from any template, layout, component or island, and from the server fence. What a form shows is read from `add.form` (`failed()`, `error(field)`, `validate(form, field)`), apart from the call state on `add` itself (`pending()`, `status()`, `data()`, `progress()`, `settled()`, `track()`); `failed()`, `error()` and `validate()` on `add` work until 1.108 and `deprecated-action-readers` rewrites them.
|
package/llms/actions.md
CHANGED
|
@@ -15,7 +15,7 @@ An action is an Elysia schema and a handler a page's server fence exports, and `
|
|
|
15
15
|
import { s, action } from 'kay'
|
|
16
16
|
|
|
17
17
|
export const subscribe = action(
|
|
18
|
-
|
|
18
|
+
{ email: s.string({ min: 3, max: 200 }) },
|
|
19
19
|
async ({ email }) => email.toLowerCase(),
|
|
20
20
|
)
|
|
21
21
|
---
|
|
@@ -33,7 +33,7 @@ An `error` line inside the form shows the message of the field, the schema's `er
|
|
|
33
33
|
import { s, action } from 'kay'
|
|
34
34
|
|
|
35
35
|
export const rename = action(
|
|
36
|
-
|
|
36
|
+
{ name: s.string({ min: 1, max: 80, error: 'Write a name' }) },
|
|
37
37
|
async ({ name }, ctx) => {
|
|
38
38
|
if (name === 'admin')
|
|
39
39
|
return ctx.deny(409, { message: 'That name is taken' })
|
|
@@ -73,7 +73,7 @@ The handler's result comes back on the next render of the page, once, through `c
|
|
|
73
73
|
--- server
|
|
74
74
|
import { s, action } from 'kay'
|
|
75
75
|
|
|
76
|
-
export const createToken = action(
|
|
76
|
+
export const createToken = action({ label: s.string({ max: 80 }) }, async () => crypto.randomUUID())
|
|
77
77
|
|
|
78
78
|
const done = createToken.data()
|
|
79
79
|
---
|
|
@@ -92,7 +92,7 @@ form(action={createToken})
|
|
|
92
92
|
--- server
|
|
93
93
|
import { s, action } from 'kay'
|
|
94
94
|
|
|
95
|
-
export const create = action(
|
|
95
|
+
export const create = action({ title: s.string({ max: 200 }) }, async ({ title }, ctx) => {
|
|
96
96
|
const id = crypto.randomUUID()
|
|
97
97
|
return ctx.redirect(`/posts/${id}`)
|
|
98
98
|
})
|
|
@@ -104,14 +104,14 @@ form(action={create})
|
|
|
104
104
|
|
|
105
105
|
### Accept a file
|
|
106
106
|
|
|
107
|
-
`s.
|
|
107
|
+
`s.file()` in the schema, `input(type="file" name="avatar")` in the form, and the handler gets a `File`:
|
|
108
108
|
|
|
109
109
|
```kay
|
|
110
110
|
--- server
|
|
111
111
|
import { s, action } from 'kay'
|
|
112
112
|
|
|
113
113
|
export const upload = action(
|
|
114
|
-
|
|
114
|
+
{ avatar: s.file({ type: 'image/png' }) },
|
|
115
115
|
async ({ avatar }) => avatar.size,
|
|
116
116
|
{ maxSize: '10mb' },
|
|
117
117
|
)
|
|
@@ -133,8 +133,8 @@ A page's or a layout's server fence exports actions: an Elysia schema and a hand
|
|
|
133
133
|
import { s, action } from 'kay'
|
|
134
134
|
import { addTodo, listTodos } from '../data'
|
|
135
135
|
|
|
136
|
-
const newTodo = s.
|
|
137
|
-
title: s.
|
|
136
|
+
const newTodo = s.object({
|
|
137
|
+
title: s.string({ min: 1, max: 200, error: 'Write a title' }),
|
|
138
138
|
})
|
|
139
139
|
|
|
140
140
|
export const add = action(newTodo, async ({ title }, ctx) => {
|
|
@@ -158,14 +158,16 @@ form(action={add})
|
|
|
158
158
|
```
|
|
159
159
|
|
|
160
160
|
- `actions: { protect, maxSize, messages }` in `kay.config.ts` is the default of every action, `protect` key by key: an action's own `rateLimit` replaces the app's, and `protect: false` takes none of the app's checks (the app's `maxSize` and `messages` still apply). `actions: { beforeRun, onSuccess, onError }` hook every run, before the action's own hooks of the same name: [hooks](hooks.md#the-apps-own-hooks).
|
|
161
|
+
- Since 1.107 the options come first and hold the input: `action({ input: { title: s.string() }, maxSize: '1mb', guards }, handler)`, as an API route's do; `input` is a record of fields or any schema, and `action({ guards }, handler)` has none. `action(schema, handler, options)` and `action(handler, options)` work until 2.0 (`deprecated-action-options`).
|
|
162
|
+
- Input is read by `validate(schema, value, { source })`, the one path an action, an API route, a socket message, `defineEnv` and a collection share: a form is read as the numbers, booleans and lists it spells, and a call from an island (JSON) never is, so `'3'` for an int is refused there. An unknown key is refused in JSON; a form post drops the fields the schema does not name, as a browser sends controls the app does not own. A refusal is worded in the request's locale and carries the `kay.invalid.*` key it is worded under.
|
|
161
163
|
- An action with no input leaves the schema out: `action(async (ctx) => { ... }, protection?)`, validated as an empty object, its handler getting the context alone, called as `signOut()`, `signOut(undefined, { refresh: false })` or `site.call(signOut)`, and posted by `form(action={signOut})`.
|
|
162
164
|
- An action several pages and components share lives in an `_actions.kay` of a routes directory, a `--- server` fence alone, no closing `---` needed: it is served like a layout's actions, behind the guards of its directory and above, reading the params of every page below it, and `page = { guards: false }` opens it as a layout's.
|
|
163
165
|
- A page or a component imports it by its path, `import { removeTissue } from '../routes/admin/_actions.kay'`, in the server fence of a page or an island alike; no route file is imported, and `kay build`, `kay check` and `kay routes` see it as they see a layout's actions.
|
|
164
|
-
- `s.
|
|
165
|
-
- A string field with no `maxLength` of its own is refused past 10,000 characters, with the error of a declared `maxLength`, and carries that bound to the form's `maxlength` and to the tool's schema; whatever builder wrote it, `t.Record` values, tuples and a string in an API route's `body` included. A field with an `enum`, a `const`, or a secret name such as `password` keeps none. Declare a tighter one for a name, an email or a title, which `kay check` warns of (`unbounded-string`), and a longer one for a field that takes more.
|
|
166
|
+
- `s.email()` accepts one plain address, the same check in the browser, on the server, in kayjs-auth and in kayjs-mail: letters and digits of any script, `+tag`, an internationalised domain; a local part up to 64 characters, labels up to 63, no quotes, comments, IP domain, name with angle brackets, list, line break or space around it, 254 characters at most, a host typed as is (no soft hyphen, zero-width space, fullwidth letter or ideographic full stop). Non-ASCII local parts and IDN domains pass for every app field; kayjs-auth alone also refuses a Latin, Cyrillic or Greek mix. `isEmail(value)` from `kay` is that check, `normalizeAddress(value)` from `kay/library` the form to store (trimmed, lower case, punycode domain).
|
|
167
|
+
- A string field with no `max` (`maxLength`) of its own is refused past 10,000 characters, with the error of a declared `maxLength`, and carries that bound to the form's `maxlength` and to the tool's schema; whatever builder wrote it, `t.Record` values, tuples and a string in an API route's `body` included. A field with an `enum`, a `const`, or a secret name such as `password` keeps none. Declare a tighter one for a name, an email or a title, which `kay check` warns of (`unbounded-string`), and a longer one for a field that takes more.
|
|
166
168
|
- `s` from `kay` builds the schema. A schema shared by API modules, server fences and islands, and the types an island reads off it, are in [Schemas](schemas.md).
|
|
167
169
|
- The handler's second argument is the request context every route shares (see routing, "The request context"), `request`, `url`, `locale`, `params`, `cookies`, `locals`, `headers`, `redirect`, `notFound` and `deny`, with `status(code)`.
|
|
168
|
-
- `ctx.redirect`, `ctx.notFound()` and `ctx.deny()` throw, as in a page, and a handler writes `return ctx.redirect(...)`, as a guard does; a call or a form post is answered with the redirect or a 404 as plain text, `redirect` with 303 unless given. `ctx.deny(status, { message, errors, data })` fails the post as in the next lines when it holds `data` or `errors` (400 to 599)
|
|
170
|
+
- `ctx.redirect`, `ctx.notFound()` and `ctx.deny()` throw, as in a page, and a handler writes `return ctx.redirect(...)`, as a guard does; a call or a form post is answered with the redirect or a 404 as plain text, `redirect` with 303 unless given. `ctx.deny(status, { message, errors, data })` fails the post as in the next lines when it holds a `message`, `data` or `errors` (400 to 599), a `message` alone being the form's message (`add.form.error()`, an `ActionError`'s text); `deny(status)` with nothing, and `deny(status, 'text')` until 1.108, stop with plain text. A helper given the action's `ctx`, such as `limit.check(ctx)`, fails the form with its message and keeps the `Retry-After` it set; a stream that denies before its first value fails the call, and one denying after it ends the stream in an `ActionError`.
|
|
169
171
|
- Its `url` is the page's the post came from, as its guards read it, and its `locale` that page's, or the site's `lang` without `i18n`.
|
|
170
172
|
- A location outside ASCII, such as `/blog/日本語`, goes out percent-encoded, from pages and guards too.
|
|
171
173
|
- A location holding a control character, or a scheme other than `http:` and `https:`, such as `javascript:`, throws.
|
|
@@ -173,9 +175,12 @@ form(action={add})
|
|
|
173
175
|
### Forms
|
|
174
176
|
|
|
175
177
|
- `form(action={add})` posts without JavaScript.
|
|
176
|
-
- Inside it, `input(field="title")`, on an `input`, `textarea` or `select`, renders `name="title"` plus the constraints the browser checks without JavaScript that the schema gives `title`: `required` where the server would refuse the field left blank (never for a boolean, so a checkbox stays optional, nor a list), `minlength`, `maxlength`, `pattern` (matched anywhere, as the schema matches it, and left out when the browser could not read it), `min
|
|
177
|
-
- `s.
|
|
178
|
-
- `
|
|
178
|
+
- Inside it, `input(field="title")`, on an `input`, `textarea` or `select`, renders `name="title"` plus the constraints the browser checks without JavaScript that the schema gives `title`: `required` where the server would refuse the field left blank (never for a boolean, so a checkbox stays optional, nor a list), `minlength`, `maxlength`, `pattern` (matched anywhere, as the schema matches it, and left out when the browser could not read it), `min` and `max`, each unless the template writes it.
|
|
179
|
+
- It also writes the `type` of an `input` that has none, from the schema: `email` and `url` for `s.email()` and `s.url()`, `number` for `s.int()` and `s.number()` (with `step="any"` for the latter), `date` for `s.date()`, `checkbox` for `s.boolean()` (filled as ticked when a refused post or `values` holds it) and `file` for `s.file()` and `s.files()`, with `accept` from their `type` and `multiple` for the list. A `type` the template writes wins, and takes `accept`, `multiple` and `step` with it. A component requiring the field (kayjs-ui's `Field`) sees the schema's type, so a file takes no `aria-required`; `missing-autocomplete` leaves an email `input(field=...)` and a field named like a password alone.
|
|
180
|
+
- `autocomplete` comes from the field's own `autocomplete` option (`s.string({ autocomplete: 'one-time-code' })`), else `email` and `url` for those formats, else the name: `firstName`, `lastName`, `username`, `phone`, `postalCode`, `currentPassword`, `newPassword`, `otp`, `birthday`.
|
|
181
|
+
- `select(field="topic")` with no `option` written renders one per value of `s.enum` or `s.union` of `s.literal`s (a record's texts word them; a field that may be left out starts with a blank option) and selects the one a refused post or `values` holds. A static page and a server island render them; an island's own browser render does not.
|
|
182
|
+
- `s.enum(values)` has no `default` unless the options give one: an optional enum field left out reads `undefined` and a required one is refused with a 422, where Elysia's own fills the first value in.
|
|
183
|
+
- `s.enum(TOPICS)` of a record is an enum of its keys, typed as their union with no cast, for a `select(field="topic")` whose options come from `Object.entries(TOPICS)`.
|
|
179
184
|
- `field` takes written text, never both `field` and `name`, and only inside such a form.
|
|
180
185
|
- `kay check` verifies every `field` and `name` against the schema.
|
|
181
186
|
- Once kay's script runs it sets `novalidate` on every form posting to an action and checks the form against the schema itself, so the schema's `error` messages show rather than the browser's, then the constraints the template wrote itself. `validate` (or `validate="blur"`) on the `form` shows them as text instead, in the `data-field="<name>"` elements outside islands (a FormField's); `blur` checks each field as it loses focus too.
|
|
@@ -193,12 +198,12 @@ form(action={add})
|
|
|
193
198
|
### Form values
|
|
194
199
|
|
|
195
200
|
- A plain form posts text, read against the schema before it validates.
|
|
196
|
-
- An `s.
|
|
201
|
+
- An `s.number()`, `s.int()` or `s.boolean()` field becomes one, a number only from decimal text such as `-1.5` or `2e3`, never `0x10`.
|
|
197
202
|
- A ticked checkbox posts `on`, read as `true`, and an unticked one nothing, read as `false` when the field is required.
|
|
198
|
-
- An `s.
|
|
203
|
+
- An `s.list()` field takes a single value or none as a list.
|
|
199
204
|
- The spaces around each text are dropped, so `minLength: 10` counts what was typed and ten spaces fill nothing.
|
|
200
|
-
- An optional field left blank counts as left out, `undefined` for `s.
|
|
201
|
-
- A field named like a password or a secret keeps its spaces, as does one whose schema says so, `s.
|
|
205
|
+
- An optional field left blank counts as left out, `undefined` for `s.string({ optional: true })`.
|
|
206
|
+
- A field named like a password or a secret keeps its spaces, as does one whose schema says so, `s.string({ trim: false })` for a code block.
|
|
202
207
|
- A call from an island with its input, not a form's fields, reaches the schema as sent.
|
|
203
208
|
- An island holding a form may call the action with its fields instead, `await add(new FormData(form))`: the server reads them as it reads a plain form post, numbers, booleans and arrays coerced from their text, spaces around text dropped and a blank optional field left out, files and the honeypot included, and answers as a call, so the island shows the field errors of the `ActionError` and goes on once it resolves.
|
|
204
209
|
- To check a form in the browser with rules of its own, showing their messages as text rather than the browser's bubbles, an island holding the form gives it `onSubmit` and `novalidate`.
|
|
@@ -223,28 +228,6 @@ form(action={add})
|
|
|
223
228
|
- `label(field="name")` writes the label's `for` and the `id` of the one control of that field in the form, `<action>-<field>` (`save-name`), so `label(for="name")` and `input#name(field="name")` become two `field`. It is `form-misuse` when the form has no control of that field or several (a group of radios or boxes: write `for` and `id` yourself), when the label also writes `for`, or when the control writes its own `id`. Forms posting to one action, such as one per row, repeat the id: write `for` and `id` there.
|
|
224
229
|
- `button(action={move.with({ id })})` outside a form posts that action: kay wraps it in a `form(action={...})` that has no box of its own (`display: contents`, set by a hashed `style` rule in the head, so a strict CSP holds), so a static page posts and an island calls it, with the `.with()` arguments; the button is then the only child of its form for `:first-child` and `first:` styles. In a `p` it is `invalid-nesting`. Inside a form it is `form-misuse`: the form's own button posts the form.
|
|
225
230
|
|
|
226
|
-
### Refused posts
|
|
227
|
-
|
|
228
|
-
- `ctx.deny(status, { message, errors, data })` is the one refusal of a guard, a page, an action and an endpoint, `refuse(status, { ... })` throws it from anywhere; `return` it so `form.failed()` types `data`. `ctx.fail` is its old spelling until 1.108 (`unreturned-fail`).
|
|
229
|
-
- A post the schema refuses, or whose handler denies with `ctx.deny(status, { data })`, is answered with the page it came from, rendered with the failure's status, rather than with a redirect.
|
|
230
|
-
- There `add.form.failed()` returns `{ status, message, values, errors, data }`, typed from the action, or `undefined`.
|
|
231
|
-
- `values` is what the form posted (fields named like a password left out).
|
|
232
|
-
- `errors` is a message per refused field, the schema's `error` option when set.
|
|
233
|
-
- `data` is what `ctx.deny` received.
|
|
234
|
-
- `return ctx.deny(409, { errors: { email: 'Already taken' } })` puts a message on a field, typed from the schema's keys, with `''` for the form's own, so `error email`, `aria-invalid`, `add.form.error('email')`, the value re-fill and an island's `ActionError.errors` (and a kayjs-ui `FormField` named `email`) follow it with and without JavaScript.
|
|
235
|
-
- A rate limit's refusal sits under `errors['']`, read by `add.form.error()`, and a text `data` is that message: `return ctx.deny(502, { data: 'Not sent; try again later' })`.
|
|
236
|
-
- The page renders as a visit of it would, through the app's plugins and the page's guards, and nothing the visitor typed is lost however long it is.
|
|
237
|
-
- Reloading it posts again, as after any form a server answers in place.
|
|
238
|
-
- The page is the one the post was sent from, as `ctx.params` reads it below, the home page when it names none or another site.
|
|
239
|
-
- Without the page swap the browser shows the action's URL, so the page carries a `base` naming its own URL, and its relative links lead where they did.
|
|
240
|
-
- Each form on it posting to an action names that page in a `kay_back` query parameter, so a post refused again renders the same page, however many times in a row, and one that goes through goes back to it.
|
|
241
|
-
- A handler that throws, a mail server down say, is logged as any server error, `onError` included, and answered as a refusal with status 500.
|
|
242
|
-
- A plain form post then renders its page with the message under the form and what was typed kept, read by `add.form.error()`, and a call answers `{ ok: false }` with it in `errors['']`.
|
|
243
|
-
- The message is `Something went wrong on our side; try again later` unless the site words it as `kay.action.serverError` ([Locales](locales-texts.md)) or the action words its own, `action(schema, handler, { messages: { serverError: 'Not sent; write to hello@example.com instead' } })`, so a handler needs no `try`/`catch` of its own to tell the visitor.
|
|
244
|
-
- `serverError` may be a function given the error and `ctx`, sync or async, to word it from what is loaded per request or the page's `ctx.locale`: `serverError: async () => 'Write to ' + (await settings.one()).email`. Its text is answered with the same status 500; one that throws, or answers a blank text, leaves kay's message (a throw logged beside the handler's error), and a redirect or denial thrown from it is no answer either.
|
|
245
|
-
- An action past its `timeout` (`serve.timeout` or the action's own) answers 504 the same way, worded `kay.action.timeout` (`This took too long; try again later`) and reported as a server error.
|
|
246
|
-
- A redirect or a guard's denial thrown is no error.
|
|
247
|
-
|
|
248
231
|
### Params of the posting page
|
|
249
232
|
|
|
250
233
|
- `ctx.params` holds the params of the page the action was posted from, matched against the route of the page exporting it, as its guards read them. In an action declared in a page, `kay check` types it from that page's route, a matcher's value as it gives it and an optional param `| undefined`, so `ctx.params.id` is a `number` under `[id=integer]` and a misspelled one is an error; a layout's or an `_actions.kay` action, and a guard, cover several routes and read `unknown`.
|
|
@@ -260,4 +243,4 @@ form(action={add})
|
|
|
260
243
|
|
|
261
244
|
### Files
|
|
262
245
|
|
|
263
|
-
- What an action takes of a file, `s.
|
|
246
|
+
- What an action takes of a file, `s.file()`, `s.files()`, the form encoding and the body limit, is in [Stored files](files.md#files-posted-to-an-action).
|
package/llms/analytics.md
CHANGED
|
@@ -38,7 +38,7 @@ export default defineConfig({
|
|
|
38
38
|
```ts
|
|
39
39
|
import { track } from 'kay/analytics'
|
|
40
40
|
|
|
41
|
-
export const signup = action(
|
|
41
|
+
export const signup = action({ plan: s.string() }, async ({ plan }, ctx) => {
|
|
42
42
|
await track(ctx, 'signup', { plan })
|
|
43
43
|
})
|
|
44
44
|
```
|
package/llms/api-from-islands.md
CHANGED
package/llms/api-routes.md
CHANGED
|
@@ -16,7 +16,7 @@ export default api()
|
|
|
16
16
|
.post(
|
|
17
17
|
'/',
|
|
18
18
|
({ body }) => addNote(body.title),
|
|
19
|
-
{ body: s.
|
|
19
|
+
{ body: s.object({ title: s.string() }) },
|
|
20
20
|
)
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -94,7 +94,7 @@ export default defineConfig({ mcp: true })
|
|
|
94
94
|
import { s, action } from 'kay'
|
|
95
95
|
|
|
96
96
|
export const addNote = action(
|
|
97
|
-
|
|
97
|
+
{ title: s.string({ min: 3, max: 80 }) },
|
|
98
98
|
async ({ title }) => ({ title }),
|
|
99
99
|
{ tool: 'Create a note' },
|
|
100
100
|
)
|
|
@@ -129,8 +129,8 @@ import { complete, listRooms } from '../data'
|
|
|
129
129
|
export default api()
|
|
130
130
|
.get('/rooms', () => listRooms())
|
|
131
131
|
.ws('/:room', {
|
|
132
|
-
body: s.
|
|
133
|
-
response: s.
|
|
132
|
+
body: s.object({ text: s.string() }),
|
|
133
|
+
response: s.object({ from: s.string(), text: s.string() }),
|
|
134
134
|
message(ws, { text }) {
|
|
135
135
|
ws.send({ from: ws.data.user?.name ?? 'guest', text })
|
|
136
136
|
},
|
|
@@ -138,7 +138,7 @@ export default api()
|
|
|
138
138
|
.post(
|
|
139
139
|
'/answer',
|
|
140
140
|
({ body }) => eventStream(complete(body.prompt)),
|
|
141
|
-
{ body: s.
|
|
141
|
+
{ body: s.object({ prompt: s.string() }) },
|
|
142
142
|
)
|
|
143
143
|
```
|
|
144
144
|
|
|
@@ -201,7 +201,7 @@ export default api()
|
|
|
201
201
|
### OpenAPI
|
|
202
202
|
|
|
203
203
|
- `openapi: true` in kay.config.ts serves an OpenAPI 3.1 document of every module's routes at `/api/openapi.json`, read from the schemas they declare.
|
|
204
|
-
- Path params are written in braces; `params`, `query` and `headers` are parameters; `body` is JSON, or multipart when it holds an `s.
|
|
204
|
+
- Path params are written in braces; `params`, `query` and `headers` are parameters; `body` is JSON, or multipart when it holds an `s.file()`; `response` is one schema or one per status.
|
|
205
205
|
- A route's `detail` gives its `summary`, `description`, `tags`, the module's path by default, and `deprecated`.
|
|
206
206
|
- `detail: { hide: true }` leaves a route out; websockets are left out.
|
|
207
207
|
- A route behind guards is marked `x-kay-guarded: true`, with no guard file named. A document no `_guard.ts` of the API directory protects leaves the guarded routes out, as it is open to anyone; behind a guard it lists all.
|
package/llms/browser-only.md
CHANGED
|
@@ -65,7 +65,7 @@ onMount(() => drawMap(center))
|
|
|
65
65
|
- A read through `globalThis` is not seen, nor one in a chunk carrying a `process` polyfill of its own, which binds the name.
|
|
66
66
|
- `kay dev` and `bun test` build the same way, so they refuse it too.
|
|
67
67
|
- `kay check` reports the same refusal before any build, as `server-only-in-island` at each island's import of the module, one per island reaching it, or at the read in the island's own script: an island, or a module it reaches through relative imports, `.ts` modules with an angle-bracket cast too, that reads `process` or `Bun` as the module loads. A read inside a function is left to the build, as only the build knows whether the island calls it; `process.env.NODE_ENV` and a `typeof` guard pass.
|
|
68
|
-
- In the browser kay's `s` builds
|
|
68
|
+
- In the browser kay's `s` builds the plain JSON Schema of each field, so a module an island imports may build schemas as it loads and keep a schema beside its `Static` type, and the island may call `validate(schema, value, { source })` from `kay` on it, the validator being a chunk the first call loads: [Schemas](schemas.md#schemas).
|
|
69
69
|
- An island reaching a builtin a browser lacks, `bun:sqlite` or `async_hooks` through a database library say, is refused with the imports leading there, one line per island: `src/counter.kay -> src/links.ts -> src/db.ts -> bun:sqlite`, cut at the first package since the fix is never inside one. The message says an island cannot import a server module: keep the constants and types an island needs in a module importing no server code. `mountComponent` in `bun test` reports the same chain.
|
|
70
70
|
- `kay check` reports it too, as `browser-builtin-import` at each of the island's imports leading there, with the same chain, once per distinct chain. It bundles the import for the browser as the build does, so a package's `browser` condition and field count, a type-only or unused import passes, and only the builtins the build refuses do: `async_hooks`, `worker_threads` and `bun:*`, not `node:path`, `events` or `node:crypto`. A package marked `sideEffects: false` is followed too, a `.kay` component the island renders is followed through its own imports and reported at the island's import of it, and an import that fails to bundle leaves the other imports' reports intact. One island gets one report per chain. Imports of `kay` and its entries are left out. In a project that never names `process` or `Bun` it follows the islands themselves, not the static components.
|
|
71
71
|
- An island bundles all of a module it imports, so a helper beside a database the module opens as it loads brings the database along: move the helper to a module importing none of it.
|
package/llms/check-and-tools.md
CHANGED
|
@@ -83,7 +83,7 @@ kay fmt --check
|
|
|
83
83
|
- `--since 1.46` reports and, with `--fix`, fixes the `deprecated` lints that came in that minor alone, as `kay upgrade` runs it; it does not go with `--only`.
|
|
84
84
|
- `--entry` names the server entry whose `app` types `ctx.locals` and the app routes, `src/server.ts` by default, as `kay build --entry` does (see [Locals](server.md#locals)).
|
|
85
85
|
- It fails on errors, and on warnings too with `--deny-warnings` (see [Lints and warnings](lints.md#lints-and-warnings)).
|
|
86
|
-
- `--fix` first applies the quick fixes that change nothing else, removing an unread prop or writing `onclick` as `onClick`, (with `envFiles` in kay.config.ts, also the raw `process.env.X` reads `kay env` warns of: each is declared in the app's `export const env = defineEnv(s.
|
|
86
|
+
- `--fix` first applies the quick fixes that change nothing else, removing an unread prop or writing `onclick` as `onClick`, (with `envFiles` in kay.config.ts, also the raw `process.env.X` reads `kay env` warns of: each is declared in the app's `export const env = defineEnv(s.object({` or a new `src/env.ts`, a `?? 'default'` becoming its default, the reads `env.X`; one assigned, destructured, in a `.kay` file or beside an `env` of its own keeps its warning, a rewritten file loads the schema, which checks the environment on import, and `kay upgrade` skips it), then reports what is left; the others, such as a key or a `maxLength` to choose, stay the editor's.
|
|
87
87
|
- `--only seo` prints one group's lints alone, as an audit (see [Lints and warnings](lints.md#lints-and-warnings)).
|
|
88
88
|
- `--format github` prints each problem as a workflow command, `::error file=...,line=...,col=...::message`, which GitHub and Forgejo Actions show on the diff, as the CI `kay new` writes does, its `file` relative to `GITHUB_WORKSPACE`, the repository's root, when set;
|
|
89
89
|
- `--format json` prints `{ errors, warnings, problems }` on stdout, each problem's `file` relative to the current directory with its `line`, `column`, `endLine`, `endColumn`, `severity`, `code` and `message`;
|
package/llms/code-lints.md
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
| `unkept-page` | warn | code | A page saying `keep: true` that `kay build` does not keep prerendered, as it reads the request or the clock, imports a package, holds module state or renders differently each time: reported by `kay build` at the file and line that decided it, never by `kay check`, and no `// kay-allow` comment reaches it. |
|
|
23
23
|
| `removed-ui-token` | warn | code | A kayjs-ui theme token or utility under its old `kui-` name, such as `--color-kui-canvas` or `bg-kui-surface2`, which stopped working in 1.75: a utility builds nothing and a `var()` of it resolves to nothing. `kay check --fix` rewrites it to the app's own name where one stands for it, and the report says where to set the rest: a `--kui-border-*` knob and a `kui-` utility with no new form are reported without a fix. Names quoted in a comment are not reported |
|
|
24
24
|
| `text-size-colour` | warn | code | A theme colour named like a Tailwind text size (`--color-base`, `--color-lg`) in the project's CSS while a file uses that `text-` utility: `text-base` is then the font size and the text colour at once, so the text takes the colour (the page background where `base` is the ground) and vanishes. Every use is reported. Rename the colour (`--color-background`) or write the size as `text-[1rem]` |
|
|
25
|
-
| `unknown-tool-label` | warn | code | A key of a `toolLabels` object on `Chat` that names no tool of the project (an export in snake case, a `tool.name` or the name of a `tool()`), whose calls show the raw name. |
|
|
26
|
-
| `public-env-outside-src` | warn | code | An `s.
|
|
25
|
+
| `unknown-tool-label` | warn | code | A key of a `toolLabels` or `toolIcons` object on `Chat` that names no tool of the project (an export in snake case, a `tool.name` or the name of a `tool()`), whose calls show the raw name or no icon. |
|
|
26
|
+
| `public-env-outside-src` | warn | code | An `s.public(` in a `.ts` file outside `src/` (tests left out), such as `common/env.ts`: kay finds public fields only in the modules under `src`, so an island reads it as a plain string and the browser is not sent it. Declare the field in a `defineEnv` in a module under `src`. Reported by `kay check`, set with `lints` or allowed with `// kay-allow public-env-outside-src` |
|
|
27
27
|
| `browser-global-at-load` | deny | code | A module a page imports reading `window` or another browser-only name as it loads ([details](browser-only.md#browser-globals-on-the-server)). |
|
|
28
28
|
| `unmounted-jobs` | warn | code | A `src/jobs.ts` that no plugin under `src/plugins/` and no `src/server.ts` imports directly (not through a third module): the queues in it are mounted by nothing, so none runs. Define and mount queues in `src/jobs/*.ts`, the one home of jobs; a plugin re-exporting `src/jobs.ts` is accepted. |
|
|
29
29
|
| `unused-status-page` | warn | code | A status page (`_401.kay`, `_403.kay`, `_429.kay`, `_503.kay`) in a directory with no route: it answers for the routes of its directory and below, so no page renders it. Move it beside the pages it answers for, or delete it. |
|
package/llms/compiler-api.md
CHANGED
|
@@ -20,6 +20,6 @@ for (const diagnostic of diagnostics)
|
|
|
20
20
|
|
|
21
21
|
- `compileKay(source, filename, options?)` returns `{ tsx, map, island?, cause?, classes, diagnostics }`, `cause` being what makes the component an island: `{ kind, name, span, line, source? }`, `span` the offsets in the source and `source` the module of a `kay` value. `why` is the same cause as a sentence, deprecated for `cause`. A problem in the source is reported in `diagnostics`. `filename` is read for its base name and, with `root`, its island id: a `_layout.kay`, `_404.kay` or `_error.kay`, like a file with a `--- server` fence, is a route file the server renders, never an island.
|
|
22
22
|
- `tsx` is the generated code: TSX for type checking by default, or with `output: 'html'` or `output: 'dom'` the server's or the browser's code that runs. `map` maps it back to the source, `island` is the component's island id when it renders as one, `classes` the `.class` shorthand names a CSS scanner cannot read off the template.
|
|
23
|
-
- Options: `root` (island ids are paths relative to it), `includeServer: false` for a browser build, `params` and `paramTypes` typing `ctx.params`, `check: true` for the type-checking output's link, form field and island prop assertions plus the lints, with `lints` setting their levels, `inspect` for `data-kay-src`, and `hydratable`, `twinBuild`, `clientOnly`, `insideIsland` and `
|
|
23
|
+
- Options: `root` (island ids are paths relative to it), `includeServer: false` for a browser build, `params` and `paramTypes` typing `ctx.params`, `check: true` for the type-checking output's link, form field and island prop assertions plus the lints, with `lints` setting their levels, `inspect` for `data-kay-src`, and `hydratable`, `twinBuild`, `clientOnly`, `insideIsland`, `importedSignals`, `writtenProps` and `components`, which kay's own build sets.
|
|
24
24
|
- A `Diagnostic` is `{ start, end, message, label?, related?, note?, help?, code?, severity?, fixes? }`, `start` and `end` offsets into `source`, `code` a lint's name, `severity` `'warning'` for a lint at the `warn` level.
|
|
25
25
|
- `formatDiagnostic(source, filename, diagnostic, paint?)` prints it as `kay check` does, with the file, line and column, the source line and its `help`; `paint` is `(styles, text) => string` for colour, plain text without it.
|
|
@@ -118,6 +118,7 @@ export function auth({ prefix = '/auth' } = {}): KayExtension {
|
|
|
118
118
|
- `uiConfigEntries(text)` from `kay/library` reads an app's `src/ui.ts` text as `{ key, keySpan, value }` entries (spans into the text, const objects and spreads followed), for a command that rewrites it, as `kay ui eject` does; undefined when it does not parse.
|
|
119
119
|
- A library keeping its own tables in the app's Postgres reads the connection and the schema like kay's `pgData`: `connectionOf(source)` (a Bun `SQL`, a pg-orm `Database` or a URL, the `PgSource` type), `relationsMissing(db, names)` (whether a table does not exist) and `privilegeRefused(error)` (a statement refused for a role that may not create tables, Postgres 42501), all from `kay/library`.
|
|
120
120
|
- `references: [path]` lists stylesheets the app's own may `@apply` and read `theme()` of with no `@reference` line, as if each began with one (kayjs-ui lists its `theme.css`): added after the Tailwind import of each stylesheet of the app (or of one using `@apply`, `@variant` or a theme function without it), and it writes no rule.
|
|
121
|
+
- `ui: path` names a module whose default export is `defineUi({ ... })`, written as an app's `src/ui.ts` is (string and object literals only), absolute or relative to the project root: its parts and variants restyle components, the library's own or kayjs-ui's, in every app listing the extension, with no `src/ui.ts` line (see [Restyle a component from src/ui.ts](styles-and-assets.md)). The app's `src/ui.ts` wins over it, a later extension over an earlier one, each part and each variant value replacing the one under it. Keys name components as in `src/ui.ts`, resolved from the app's `src/`; one naming a component the app lacks is ignored, and `kay check` reports the file's other problems. A component a worker imports gets it too, `kay dev`'s Styles tab shows it, and the classes it writes reach the CSS from `node_modules` as well. `kay dev` rebuilds when the file changes inside the project, and picks up one elsewhere on a restart.
|
|
121
122
|
- `devTool: { module }` names a browser module, `${import.meta.dir}/devTool.ts`, that adds a tab to the dev tool every dev page carries, with no declaration in the app: see [A tab for a library](dev-tool.md#a-tab-for-a-library).
|
|
122
123
|
|
|
123
124
|
The conventions a library follows are in [Component libraries: conventions](component-library-conventions.md).
|
package/llms/components.md
CHANGED
|
@@ -134,7 +134,7 @@ ul
|
|
|
134
134
|
| Fence | What it is | Allowed on |
|
|
135
135
|
| --- | --- | --- |
|
|
136
136
|
| `---` | The component script, run wherever the component renders | Every `.kay` file; written `--- <T>` for a generic component |
|
|
137
|
-
| `--- script` | The same fence, for a script that follows a `--- server`, `--- module` or `--- style` fence, where a bare `---` would close that one; as a file's first fence it is
|
|
137
|
+
| `--- script` | The same fence, for a script that follows a `--- server`, `--- module` or `--- style` fence, where a bare `---` would close that one; as a file's first fence it is a `fence-invalid` error, write `---` | After another fence |
|
|
138
138
|
| `--- server` | Code run on the server for each request, never sent to the browser | Pages, layouts and the other `_` route files; `fence-invalid` on a component |
|
|
139
139
|
| `--- module` | Module-level code, run once per bundle, whose exports other files import | Every file; no props, and not on a browser-only component |
|
|
140
140
|
| `--- style` | CSS scoped to the component | Every file |
|
package/llms/content-cms.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
### Markdown files
|
|
10
10
|
|
|
11
11
|
- A Markdown file starts with YAML frontmatter between `---` lines.
|
|
12
|
-
- Every entry's data is read against the schema: defaults filled in, an `s.
|
|
12
|
+
- Every entry's data is read against the schema: defaults filled in, an `s.date()` decoded from its text. A date that names no day, `2024-02-30` or `T24:00`, or that cannot be decoded, `2024-03-10 10:00` (seconds are needed), is refused at its field's line.
|
|
13
13
|
- An entry it refuses, or one that does not parse, fails `kay check` at the field's line, naming the field's whole path (`packs.0.price`), and fails `kay build` and the first load; a loader's refused entry is instead left out and logged ([Loaded collections](content-cms.md#loaded-collections)).
|
|
14
14
|
- Defaults fill nested objects and list items too, and `migrations: [renameField(...), convertField(...), setField(...)]` on the collection carries entries over after a schema change ([Loaded collections](content-cms.md#loaded-collections)).
|
|
15
15
|
- Headings get ids, unique in the entry, and link to themselves: an ASCII title keeps the lowercase words joined by `-` (`Don’t stop` is `dont-stop`), a title with letters beyond ASCII keeps them (`Été & Café` is `été-café`, `日本語` is `日本語`), a title with no letter or digit is `heading`, and a repeat takes `-1`, `-2` (`a`, `a-1`, `a-1-1`).
|
package/llms/content-preview.md
CHANGED
|
@@ -53,8 +53,8 @@ A CMS running in the app's server, as a kay extension, reads and edits the colle
|
|
|
53
53
|
- `fieldInput(schema, options)` from `kay/content` tells a CMS how to enter a field (reported as `x-kay-input`): a placeholder, a prefix or suffix, rows, labels, lines, a list item's title or a `when` on a sibling; a collection's `description` is shown above its entries ([kayjs-cms](../../cms/llms/fields.md)).
|
|
54
54
|
- `unique(schema)` from `kay/content` marks a field (reported as `x-kay-unique: true`) whose value no other entry of the collection, of the same locale in a localized one, may hold: `saveEntry`, a folder entry's source and a draft's check refuse a repeat with the issue `is already the code of a` at the field's path, read against every entry, drafts included. A save of a loaded entry is checked again in its turn; a folder's files cannot be, so two commits of one value pass. Nothing checks entries already stored.
|
|
55
55
|
- `colorField()`, `moneyField({ currency })`, `tagsField()`, `linkField()`, `geoField()` and `iconField(iconifySet)` from `kay/content` are ready-made kinds with a control in kayjs-cms ([kayjs-cms](../../cms/llms/fields.md#ready-made-kinds)).
|
|
56
|
-
- `blocks({ hero: s.
|
|
57
|
-
- `reference`, `imageField`, `fileField`, `markdownField` and `customField` from `kay/content` give fields a CMS edits apart, `reference('authors')` say, reported in the schema as `x-kay: { kind, collection? }`: the slug of another collection's entry ([checked by `kay check`, `kay build` and every write](content.md#point-at-another-collections-entry)), the path the site serves an image or a file at (an upload's `files.url(key)` or a public file's), Markdown. `imageField({ accept, maxSize, minWidth, minHeight, alt, width, height })` and `fileField({ accept, maxSize })` also take what the editor asks of a file and, for an image, the keys of the fields beside it that hold its alt text and size (reported in `x-kay`; `FieldHint` from `kay/content` types it), which kayjs-cms fills in and leaves out of its form ([kayjs-cms](../../cms/llms/uploads.md)). `customField(kind, schema)` wraps any schema, not only a string, in a kind of the app's own, `customField('color', s.
|
|
56
|
+
- `blocks({ hero: s.object({ ... }), text: s.object({ ... }) })` from `kay/content` is a list of items of several types, each stored as an object with a `type` key naming its block (`{ type: 'hero', ... }`) and read as the union discriminated on `type`; a CMS adds an item by its type and shows its own fields ([kayjs-cms](../../cms/llms/fields.md#blocks)).
|
|
57
|
+
- `reference`, `imageField`, `fileField`, `markdownField` and `customField` from `kay/content` give fields a CMS edits apart, `reference('authors')` say, reported in the schema as `x-kay: { kind, collection? }`: the slug of another collection's entry ([checked by `kay check`, `kay build` and every write](content.md#point-at-another-collections-entry)), the path the site serves an image or a file at (an upload's `files.url(key)` or a public file's), Markdown. `imageField({ accept, maxSize, minWidth, minHeight, alt, width, height })` and `fileField({ accept, maxSize })` also take what the editor asks of a file and, for an image, the keys of the fields beside it that hold its alt text and size (reported in `x-kay`; `FieldHint` from `kay/content` types it), which kayjs-cms fills in and leaves out of its form ([kayjs-cms](../../cms/llms/uploads.md)). `customField(kind, schema)` wraps any schema, not only a string, in a kind of the app's own, `customField('color', s.string({ pattern: '^#[0-9a-f]{6}$' }))`, which kayjs-cms edits with `src/cms/fields/<kind>.kay` ([kayjs-cms](../../cms/llms.txt)); the schema alone validates a save, and a built-in kind's name (`text`, `image`...) is refused.
|
|
58
58
|
- `await entries(name, { locale?, slug?, offset?, limit? })` from `kay/content` lists the entries as their source holds them, drafts included, those of one locale, of one slug, or a stretch of them in their order (a folder's files sorted, a loader's as it gives them) when asked, a folder reading no other file, a loader giving every entry and the filter applied after unless it has `get` (`collections()` and `collectionInfo()` from `kay/content` run a loader too, for its body and count, unless it has `count`; reads at the same moment share one run of `load`): `{ slug, locale?, path?, data, body?, draft, problem? }`.
|
|
59
59
|
- `data` is an object of fields typed by `DataValue` from `kay/content` (data holding a list or a plain value comes with no `data` and its `problem`).
|
|
60
60
|
- A folder entry's file is as written with its `path` relative to the repository (a file that does not parse comes with no `data` and its `problem`, a Markdown one with its `body` when the frontmatter alone fails; a folder missing, as beside a build alone, throws).
|
package/llms/content.md
CHANGED
|
@@ -11,11 +11,11 @@ import { s } from 'kay'
|
|
|
11
11
|
import { collection } from 'kay/content'
|
|
12
12
|
|
|
13
13
|
export const posts = collection('content/posts', {
|
|
14
|
-
schema: s.
|
|
15
|
-
title: s.
|
|
16
|
-
date: s.
|
|
17
|
-
tags: s.
|
|
18
|
-
draft: s.
|
|
14
|
+
schema: s.object({
|
|
15
|
+
title: s.string(),
|
|
16
|
+
date: s.date(),
|
|
17
|
+
tags: s.list(s.string(), { default: [] }),
|
|
18
|
+
draft: s.boolean({ optional: true }),
|
|
19
19
|
}),
|
|
20
20
|
route: '/blog/:slug',
|
|
21
21
|
draft: post => post.data.draft === true,
|
|
@@ -66,7 +66,7 @@ A page at the route that reads the request (`ctx.cookies`, `ctx.query`, a sessio
|
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
68
|
export const posts = collection('content/posts', {
|
|
69
|
-
schema: s.
|
|
69
|
+
schema: s.object({ title: s.string(), date: s.date() }),
|
|
70
70
|
route: '/blog/:slug',
|
|
71
71
|
feed: { path: '/blog/rss.xml', title: 'Blog' },
|
|
72
72
|
})
|
|
@@ -75,7 +75,7 @@ export const posts = collection('content/posts', {
|
|
|
75
75
|
- `a(href={post.url}) ...` links it; `url` is the path as `route()` writes it, so kay puts the base and the page's locale on it as on any link.
|
|
76
76
|
- A localized entry's `url` has its own slug, so `(await posts.translation(post, 'fr'))?.url` is the page of its translation, on a page that read the entry with `get()`, `alternate('fr')` gives it too. A dotted slug, `v1.2`, is a page, not a file; so is an entry's `release.html` (re-read on `invalidate()`); links ending in `.png` are files. A slug the route cannot write (`..`) leaves its entry out, logged. The CMS reads the route before `url`.
|
|
77
77
|
- A feed item with no `path` links the entry's `url`, absolute on the site, in the locale's feed under its prefix, as `trailingSlash` writes a page's address. A `url` function next to a `route` is overridden by the route, and a feed item's `path` is still read.
|
|
78
|
-
- The page whose pattern is the route prerenders and lists its entries in the sitemap by itself, with the entry's head (title, description, dates, the feed's `link rel="alternate"`) and, with `modified: 'updatedAt'` naming an `s.
|
|
78
|
+
- The page whose pattern is the route prerenders and lists its entries in the sitemap by itself, with the entry's head (title, description, dates, the feed's `link rel="alternate"`) and, with `modified: 'updatedAt'` naming an `s.date()` field, a `lastmod` per URL and `article:modified_time` (`modified: 'mtime'` takes each file's time, `modified: 'git'` its last commit's date from one `git log` for the folder, kept while HEAD stays (a load then costs one `git rev-parse`), a file edited since taking its time, the file's time for a file git does not know or outside a repository; the date is also `entry.modified`, a folder's entry only, and a schema field named `mtime` or `git` is read as a field; a shallow clone dates every file at its one commit, so a `git` build wants the history); its own `prerender`, `sitemap` and `lastmod` win. `kay check` reports two collections with one route, as the page cannot tell which it lists. An optional-param page (`blog/[[page]].kay`) is never taken for it.
|
|
79
79
|
- The route has one param, the slug: `:slug`, or `*slug` for slugs with folders, and `collection()` refuses any other.
|
|
80
80
|
- `kay check` reports a route no page's pattern matches (`src/routes/blog/[slug].kay`, whatever its param is named); a page listing the entries in `prerender: posts` while another page serves the route is reported too.
|
|
81
81
|
- A collection with no `route` has no `url`.
|
|
@@ -113,7 +113,7 @@ import { collection } from 'kay/content'
|
|
|
113
113
|
import Callout from './components/callout.kay'
|
|
114
114
|
|
|
115
115
|
export const posts = collection('content/posts', {
|
|
116
|
-
schema: s.
|
|
116
|
+
schema: s.object({ title: s.string() }),
|
|
117
117
|
components: { Callout },
|
|
118
118
|
})
|
|
119
119
|
```
|
|
@@ -127,7 +127,7 @@ import { s } from 'kay'
|
|
|
127
127
|
import { collection } from 'kay/content'
|
|
128
128
|
|
|
129
129
|
export const posts = collection('content/posts', {
|
|
130
|
-
schema: s.
|
|
130
|
+
schema: s.object({ title: s.string(), date: s.date() }),
|
|
131
131
|
feed: {
|
|
132
132
|
path: '/blog/rss.xml',
|
|
133
133
|
title: 'Blog',
|
|
@@ -149,14 +149,14 @@ import { s } from 'kay'
|
|
|
149
149
|
import { collection } from 'kay/content'
|
|
150
150
|
|
|
151
151
|
export const posts = collection('content/posts', {
|
|
152
|
-
schema: s.
|
|
152
|
+
schema: s.object({ title: s.string() }),
|
|
153
153
|
localized: true,
|
|
154
154
|
})
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
### Point at another collection's entry
|
|
158
158
|
|
|
159
|
-
`reference('authors')` from `kay/content` is a field holding the slug of an entry of the collection exported as `authors`, also in a list (`s.
|
|
159
|
+
`reference('authors')` from `kay/content` is a field holding the slug of an entry of the collection exported as `authors`, also in a list (`s.list(reference('authors'))`), an object or a `blocks()` item. `kay check` and `kay build` fail on a slug that collection has no entry for (any locale's, in a localized one), or on a collection the content config does not export, naming the file and the line of the field; a write through `saveEntry` and `showDraft` refuses it as an issue at the field's path. A collection with a loader is not read by the check, so a reference to it is checked only when written. The check accepts a reference to a draft, as an editor may point at one before publishing it, and `resolve` returns undefined for it until the entry is published.
|
|
160
160
|
|
|
161
161
|
`resolve(slug, collection)` from `kay/content` gives the entry, or undefined for a null, undefined or hidden one (a draft in production), and an array of slugs gives the entries found, in order. In a localized collection it reads as `get` does, the request's locale with the default locale's as fallback:
|
|
162
162
|
|
|
@@ -173,7 +173,7 @@ p {author?.data.name}
|
|
|
173
173
|
|
|
174
174
|
### Render Markdown a user writes
|
|
175
175
|
|
|
176
|
-
`markdownHtml(text)` from `kay/markdown` renders it as it comes, in an island too, as a `SafeHtml`, its images `loading="lazy"`. Under Tailwind's preflight such text shows unstyled: with kayjs-ui the container takes `class="kui-prose"`. In an island marked (about 15 KB gzip) loads on the first call outside hydration: the text shows as written until it arrives, then a template or effect that called it runs again formatted, and a failed load leaves the text as written. While an island hydrates, that text as written stands in for markup the server drew formatted, which `property` leaves in place, written again after hydration (by an effect running for another value, or from a `memo` that cached it) too, and marked waits for the text to change or be written again, so a page whose Markdown never changes never loads it; a component that changes the HTML before writing it returns the stand-in as it is when `isHeldMarkdown(html)` from `kay/markdown` is true, which is always false on the server. `markdownLoaded()` from `kay/markdown` tells whether marked has arrived, so a component linking words in the HTML reads them from the Markdown itself until then, as the text as written shows no code apart; a template or effect reading it runs again once marked has loaded, it loads nothing, and it is always true on the server. A call outside a template or effect, such as a click handler, awaits `markdownReady()` from `kay/markdown` first, and an island about to stream Markdown starts the load early with `void markdownReady()`, as kayjs-ai's Chat does on send.
|
|
176
|
+
`markdownHtml(text)` from `kay/markdown` renders it as it comes, in an island too, as a `SafeHtml`, its images `loading="lazy"` and a fence's `code` keeping its `language-*` class (no other). A bare URL or address links where Bun.markdown links it, server and island alike (`[[https://x.y/?a=1&b=2]]` links the URL without its brackets), except a URL closed by `**` or `~~` of its own emphasis, where Bun links the marks too (Bun.markdown's own bug, oven-sh/bun#43980), and a URL right after an HTML tag, a code span, an image or an escape, which an island links and Bun leaves as text. `markdownHtml(text, { inline: [{ pattern, render }] })` draws custom inline syntax, in order, outside code and links, server and island alike: `render(match)` gets the match and groups as plain text (`&`, `<`, `>`, `"` stand as entities in what `pattern` reads) and returns text (escaped), a link `{ text, href }` (sanitized like any link) or `undefined` to leave it, e.g. `{ pattern: /\[\[([^\]]+)\]\]/, render: ([, name]) => ({ text: name, href: `/notes/${name}` }) }`. Under Tailwind's preflight such text shows unstyled: with kayjs-ui the container takes `class="kui-prose"`. In an island marked (about 15 KB gzip) loads on the first call outside hydration: the text shows as written until it arrives, then a template or effect that called it runs again formatted, and a failed load leaves the text as written. While an island hydrates, that text as written stands in for markup the server drew formatted, which `property` leaves in place, written again after hydration (by an effect running for another value, or from a `memo` that cached it) too, and marked waits for the text to change or be written again, so a page whose Markdown never changes never loads it; a component that changes the HTML before writing it returns the stand-in as it is when `isHeldMarkdown(html)` from `kay/markdown` is true, which is always false on the server. `markdownLoaded()` from `kay/markdown` tells whether marked has arrived, so a component linking words in the HTML reads them from the Markdown itself until then, as the text as written shows no code apart; a template or effect reading it runs again once marked has loaded, it loads nothing, and it is always true on the server. A call outside a template or effect, such as a click handler, awaits `markdownReady()` from `kay/markdown` first, and an island about to stream Markdown starts the load early with `void markdownReady()`, as kayjs-ai's Chat does on send.
|
|
177
177
|
|
|
178
178
|
```kay
|
|
179
179
|
---
|
|
@@ -200,11 +200,11 @@ import { collection } from 'kay/content'
|
|
|
200
200
|
import Callout from './components/callout.kay'
|
|
201
201
|
|
|
202
202
|
export const posts = collection('content/posts', {
|
|
203
|
-
schema: s.
|
|
204
|
-
title: s.
|
|
205
|
-
date: s.
|
|
206
|
-
tags: s.
|
|
207
|
-
draft: s.
|
|
203
|
+
schema: s.object({
|
|
204
|
+
title: s.string(),
|
|
205
|
+
date: s.date(),
|
|
206
|
+
tags: s.list(s.string(), { default: [] }),
|
|
207
|
+
draft: s.boolean({ optional: true }),
|
|
208
208
|
}),
|
|
209
209
|
components: { Callout },
|
|
210
210
|
draft: post => post.data.draft === true,
|
|
@@ -221,7 +221,7 @@ export const posts = collection('content/posts', {
|
|
|
221
221
|
})
|
|
222
222
|
|
|
223
223
|
export const authors = collection('content/authors', {
|
|
224
|
-
schema: s.
|
|
224
|
+
schema: s.object({ name: s.string() }),
|
|
225
225
|
})
|
|
226
226
|
```
|
|
227
227
|
|
|
@@ -263,9 +263,9 @@ article
|
|
|
263
263
|
- An entry `draft` returns true for shows in development (`kay dev`, or the server's `dev` option, which wins over `NODE_ENV`) and to a visitor in preview mode only.
|
|
264
264
|
- Everywhere else a draft is left out of `all()`, `get()`, prerendering, the sitemap and the feed.
|
|
265
265
|
- `draft: 'draft'`, a boolean field's name, holds back the entries where it is true, which a CMS then reads and publishes by writing false.
|
|
266
|
-
- `publishAt: 'publishAt'`, an `s.
|
|
267
|
-
- `unpublishAt: 'endsAt'`, another `s.
|
|
268
|
-
- The date is read as `s.
|
|
266
|
+
- `publishAt: 'publishAt'`, an `s.date()` field's name, holds an entry back until that time, as a draft is, and shows it by itself then, in `all()`, `get()`, `translation()`, the pages prerendered from it, the sitemap and the feed; `kay dev` and preview mode show it at once. An entry with no date, or a date in the past, is published: a server down at that time shows it from its next boot, and one whose loader fails then logs once and reads the dates again every minute, its start waiting for the first read one second at most. A draft stays one whatever its date, so `draft: 'draft'` and `publishAt` together hold an entry until it is neither.
|
|
267
|
+
- `unpublishAt: 'endsAt'`, another `s.date()` field's name, takes an entry down from that time on, as a draft is, in the same places and by itself: the pages that read the collection render again, the page of an ended entry answers 410 Gone when its code calls `ctx.notFound()` after `get()` finds nothing (a draft or an entry not yet published stays 404), or what its code does otherwise (`ctx.redirect(...)`), and a redirect from the path, in `redirects` or added while the site runs, wins over the 410 (any `ctx.notFound()` of the same render answers 410 once `get()` found an ended entry, and an app's own 410 can be redirected the same way), the visit being listed on the missing pages screen, and a server down then catches up as it starts. No date never ends; `kay dev` and preview mode keep showing it; with `publishAt` an entry has a window.
|
|
268
|
+
- The date is read as `s.date()` reads it, never in the server's time zone: `2026-10-20` is 00:00 UTC, and `2026-10-20T08:00:00+02:00` is that instant; write the offset for an hour in your own zone, as an hour with neither `Z` nor an offset is refused. A field that is not an `s.date()` is a type error in `kay check` and fails the boot.
|
|
269
269
|
- A server refreshes the prerendered pages that read the collection when a date passes, in each process on its own clock, so replicas sharing a store each do it and the app writes no cron, job or webhook; `live: true` pages follow too, and the sitemap is built afresh. The entry's own page, which the build did not list, renders per request until the next build. A static export (`kay build --static`) cannot change by itself: it leaves the entry out until the next build, so rebuild on a schedule in CI.
|
|
270
270
|
- `order: 'position'`, a number field's name, orders the entries by it, ascending, those without a number last, unless `sort` says otherwise; kayjs-cms then lists them so and moves an entry up or down by writing the field, so the editor never types the numbers.
|
|
271
271
|
- `live: true` has every open page that read the collection (`all()`, `get()`, `translation()`) in its server fence or a layout's show it afresh in each tab once `posts.invalidate()` drops it, so a kayjs-cms save or removal shows in the other open tabs; it is the collection's side of `cached(..., { live: true })` ([Following cached values](live-values.md#following-cached-values)), with the same cost, and read it directly: a read inside a `cached` load follows only when that `cached` has `live: true`; a page reading it is rendered per request and a static export of it fails with `export-server-render`.
|