@kayjs/kay 1.105.0 → 1.106.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint.js +435 -120
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +1 -1
- package/llms/actions-from-islands.md +2 -2
- package/llms/actions.md +22 -19
- package/llms/analytics.md +1 -1
- package/llms/api-from-islands.md +1 -1
- package/llms/api-routes.md +6 -6
- package/llms/check-and-tools.md +1 -1
- package/llms/code-lints.md +2 -2
- package/llms/compiler-api.md +1 -1
- package/llms/component-libraries.md +1 -0
- package/llms/content-cms.md +1 -1
- package/llms/content-markdown-to-caching.md +1 -1
- package/llms/content-preview.md +2 -2
- package/llms/content.md +21 -21
- package/llms/deprecated-lints-1-105-libraries.md +2 -0
- package/llms/deprecated-lints-1-105.md +3 -3
- package/llms/deprecated-lints.md +3 -2
- package/llms/dev-tool.md +2 -2
- package/llms/environment.md +22 -22
- package/llms/files.md +5 -5
- package/llms/islands-state-to-ids.md +2 -1
- package/llms/local-collections.md +2 -2
- package/llms/mcp.md +2 -1
- package/llms/navigation-from-code.md +1 -1
- package/llms/notifications.md +4 -2
- package/llms/project.md +1 -1
- package/llms/rate-limits.md +1 -1
- package/llms/recipes.md +16 -16
- package/llms/rooms.md +4 -4
- package/llms/routing-endpoints-and-base.md +1 -1
- package/llms/routing.md +5 -5
- package/llms/schemas.md +10 -5
- package/llms/server.md +7 -7
- package/llms/site.md +9 -9
- package/llms/sitemap-search-fonts.md +2 -0
- package/llms/styles-and-assets.md +2 -1
- package/llms/templates-elements-slots-snippets.md +2 -2
- package/llms/testing-browser.md +20 -0
- package/llms/testing.md +1 -1
- package/llms/upgrading-1-105-config.md +2 -2
- package/llms/upgrading.md +18 -3
- package/llms/whats-new-archive.md +35 -66
- package/llms/whats-new.md +34 -28
- package/llms.txt +1 -1
- package/package.json +15 -11
- package/src/add.ts +1 -1
- package/src/build/class-table.ts +2 -2
- package/src/build/client.ts +7 -6
- package/src/build/plugin.ts +14 -11
- package/src/build/styles.ts +3 -3
- package/src/build/transform.ts +3 -1
- package/src/build/ui-layers.ts +30 -0
- package/src/build/ui.ts +108 -11
- package/src/build/variants.ts +119 -43
- package/src/build/worker-bundle.ts +6 -0
- package/src/check/boot.ts +22 -1
- package/src/check/call-result.ts +242 -0
- package/src/check/config-objects.ts +17 -2
- package/src/check/diagnose.ts +22 -0
- package/src/check/handler-events.ts +149 -0
- package/src/check/index.ts +6 -2
- package/src/check/link-flag-tests.ts +130 -0
- package/src/check/project.ts +4 -3
- package/src/check/refusal-calls.ts +2 -2
- package/src/check/regroup.ts +5 -3
- package/src/check/renamed-packages.ts +58 -14
- package/src/check/schema-builders.ts +256 -0
- package/src/check/secret-keys.ts +15 -2
- package/src/check/shadow-types.ts +2 -0
- package/src/check/template-hints.ts +1 -1
- package/src/check/tool-labels.ts +11 -9
- package/src/check/ui-types.ts +4 -3
- package/src/check/ui.ts +14 -11
- package/src/commands/env-declare.ts +18 -6
- package/src/commands/routes.ts +1 -1
- package/src/compiler/a11y.ts +8 -1
- package/src/compiler/ast.ts +1 -1
- package/src/compiler/bound-props.ts +1 -1
- package/src/compiler/codegen.ts +6 -6
- package/src/compiler/deprecated-lints-1-106.ts +14 -0
- package/src/compiler/deprecated-lints.ts +10 -5
- package/src/compiler/deprecated-typed-lints.ts +23 -0
- package/src/compiler/dom-here.ts +72 -0
- package/src/compiler/dom.ts +23 -23
- package/src/compiler/fence-checks.ts +12 -11
- package/src/compiler/field-described.ts +2 -2
- package/src/compiler/helper-imports.ts +1 -1
- package/src/compiler/html-fields.ts +92 -0
- package/src/compiler/html-initial.ts +5 -3
- package/src/compiler/html.ts +14 -31
- package/src/compiler/index.ts +3 -1
- package/src/compiler/items.ts +5 -5
- package/src/compiler/link-flags.ts +6 -5
- package/src/compiler/lints.ts +12 -12
- package/src/compiler/rest-omits.ts +15 -0
- package/src/config-loader.ts +10 -2
- package/src/config-resolve.ts +3 -1
- package/src/config-shape.ts +2 -2
- package/src/config.ts +20 -4
- package/src/content/markdown.ts +2 -3
- package/src/generate-resource.ts +9 -9
- package/src/generate.ts +1 -1
- package/src/mcp/guards.ts +1 -1
- package/src/mcp/tools.ts +1 -1
- package/src/migrate/content.ts +61 -55
- package/src/runtime/action-shared.ts +2 -2
- package/src/runtime/action.ts +6 -2
- package/src/runtime/form-types.ts +99 -0
- package/src/runtime/form.ts +22 -7
- package/src/runtime/html.ts +36 -5
- package/src/runtime/markdown-autolink.ts +69 -0
- package/src/runtime/markdown-render.client.ts +39 -3
- package/src/runtime/markdown.client.ts +6 -3
- package/src/runtime/markdown.server.ts +6 -3
- package/src/runtime/markdown.ts +125 -1
- package/src/runtime/navigate-api.ts +10 -5
- package/src/runtime/persist.ts +7 -7
- package/src/runtime/query-param.ts +1 -1
- package/src/runtime/reactive.ts +14 -0
- package/src/runtime/sanitize.ts +3 -1
- package/src/runtime/schema-record.ts +31 -0
- package/src/runtime/schema.client.ts +1 -4
- package/src/runtime/schema.ts +321 -26
- package/src/runtime/swap-focus.ts +59 -11
- package/src/server/action-module.ts +16 -0
- package/src/server/actions.ts +6 -14
- package/src/server/api-modules.ts +1 -1
- package/src/server/api.ts +13 -1
- package/src/server/app-stages.ts +23 -18
- package/src/server/dev-ui.ts +2 -2
- package/src/server/env-state.ts +1 -1
- package/src/server/env.ts +11 -3
- package/src/server/favicon.ts +47 -1
- package/src/server/image-metadata-bmff.ts +1 -1
- package/src/server/kept-pages.ts +3 -3
- package/src/server/library.ts +2 -0
- package/src/server/mcp.ts +13 -12
- package/src/server/notifications.ts +4 -2
- package/src/server/offline.ts +24 -7
- package/src/server/push-settings.ts +16 -2
- package/src/server/push.ts +12 -4
- package/src/server/query.ts +13 -6
- package/src/server/render.ts +1 -1
- package/src/server/scope.ts +20 -13
- package/src/server/signals.ts +4 -4
- package/src/template-ws.ts +1 -1
- package/src/test/a11y-dom.ts +70 -0
- package/src/test/html-snapshot.ts +103 -0
- package/src/test/index.ts +2 -1
- package/src/test/mount.ts +8 -1
- package/src/test/page-checks.ts +12 -0
- package/src/test/screenshot-match.ts +2 -2
- package/src/test/shared-modules.ts +27 -5
- package/src/test/site-types.ts +5 -1
- package/types/build/class-table.d.ts +1 -1
- package/types/build/class-table.d.ts.map +1 -1
- package/types/build/client.d.ts.map +1 -1
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/transform.d.ts +1 -0
- package/types/build/transform.d.ts.map +1 -1
- package/types/build/ui-layers.d.ts +5 -0
- package/types/build/ui-layers.d.ts.map +1 -0
- package/types/build/ui.d.ts +7 -0
- package/types/build/ui.d.ts.map +1 -1
- package/types/build/variants.d.ts +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/build/worker-bundle.d.ts +1 -0
- package/types/build/worker-bundle.d.ts.map +1 -1
- package/types/check/boot.d.ts.map +1 -1
- package/types/check/call-result.d.ts +7 -0
- package/types/check/call-result.d.ts.map +1 -0
- package/types/check/config-objects.d.ts.map +1 -1
- package/types/check/diagnose.d.ts.map +1 -1
- package/types/check/handler-events.d.ts +9 -0
- package/types/check/handler-events.d.ts.map +1 -0
- package/types/check/index.d.ts +1 -0
- package/types/check/index.d.ts.map +1 -1
- package/types/check/link-flag-tests.d.ts +4 -0
- package/types/check/link-flag-tests.d.ts.map +1 -0
- package/types/check/project.d.ts.map +1 -1
- package/types/check/regroup.d.ts +1 -1
- package/types/check/regroup.d.ts.map +1 -1
- package/types/check/renamed-packages.d.ts +1 -0
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/schema-builders.d.ts +3 -0
- package/types/check/schema-builders.d.ts.map +1 -0
- package/types/check/secret-keys.d.ts.map +1 -1
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/check/template-hints.d.ts +1 -0
- package/types/check/template-hints.d.ts.map +1 -1
- package/types/check/tool-labels.d.ts.map +1 -1
- package/types/check/ui-types.d.ts.map +1 -1
- package/types/check/ui.d.ts.map +1 -1
- package/types/commands/env-declare.d.ts.map +1 -1
- package/types/compiler/a11y.d.ts.map +1 -1
- package/types/compiler/bound-props.d.ts +1 -0
- package/types/compiler/bound-props.d.ts.map +1 -1
- package/types/compiler/codegen.d.ts +1 -0
- package/types/compiler/codegen.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-106.d.ts +12 -0
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -0
- package/types/compiler/deprecated-lints.d.ts +32 -5
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/deprecated-typed-lints.d.ts +21 -0
- package/types/compiler/deprecated-typed-lints.d.ts.map +1 -0
- package/types/compiler/dom-here.d.ts +14 -0
- package/types/compiler/dom-here.d.ts.map +1 -0
- package/types/compiler/dom.d.ts +1 -0
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/fence-checks.d.ts.map +1 -1
- package/types/compiler/field-described.d.ts +1 -1
- package/types/compiler/field-described.d.ts.map +1 -1
- package/types/compiler/html-fields.d.ts +19 -0
- package/types/compiler/html-fields.d.ts.map +1 -0
- package/types/compiler/html-initial.d.ts +3 -2
- package/types/compiler/html-initial.d.ts.map +1 -1
- package/types/compiler/html.d.ts.map +1 -1
- package/types/compiler/index.d.ts +1 -0
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/items.d.ts +4 -1
- package/types/compiler/items.d.ts.map +1 -1
- package/types/compiler/link-flags.d.ts +6 -0
- package/types/compiler/link-flags.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +44 -17
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/rest-omits.d.ts +4 -0
- package/types/compiler/rest-omits.d.ts.map +1 -0
- package/types/config-loader.d.ts.map +1 -1
- package/types/config-resolve.d.ts.map +1 -1
- package/types/config.d.ts +15 -2
- package/types/config.d.ts.map +1 -1
- package/types/content/markdown.d.ts.map +1 -1
- package/types/migrate/content.d.ts.map +1 -1
- package/types/runtime/action-shared.d.ts +1 -1
- package/types/runtime/action-shared.d.ts.map +1 -1
- package/types/runtime/action.d.ts +3 -0
- package/types/runtime/action.d.ts.map +1 -1
- package/types/runtime/form-types.d.ts +6 -0
- package/types/runtime/form-types.d.ts.map +1 -0
- package/types/runtime/form.d.ts +3 -1
- package/types/runtime/form.d.ts.map +1 -1
- package/types/runtime/html.d.ts +3 -0
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/markdown-autolink.d.ts +11 -0
- package/types/runtime/markdown-autolink.d.ts.map +1 -0
- package/types/runtime/markdown-render.client.d.ts +2 -1
- package/types/runtime/markdown-render.client.d.ts.map +1 -1
- package/types/runtime/markdown.client.d.ts +3 -1
- package/types/runtime/markdown.client.d.ts.map +1 -1
- package/types/runtime/markdown.d.ts +11 -0
- package/types/runtime/markdown.d.ts.map +1 -1
- package/types/runtime/markdown.server.d.ts +3 -1
- package/types/runtime/markdown.server.d.ts.map +1 -1
- package/types/runtime/navigate-api.d.ts +1 -1
- package/types/runtime/navigate-api.d.ts.map +1 -1
- package/types/runtime/persist.d.ts +2 -2
- package/types/runtime/persist.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +3 -0
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/sanitize.d.ts.map +1 -1
- package/types/runtime/schema-record.d.ts +9 -0
- package/types/runtime/schema-record.d.ts.map +1 -0
- package/types/runtime/schema.client.d.ts.map +1 -1
- package/types/runtime/schema.d.ts +94 -10
- package/types/runtime/schema.d.ts.map +1 -1
- package/types/runtime/swap-focus.d.ts.map +1 -1
- package/types/server/action-module.d.ts +2 -0
- package/types/server/action-module.d.ts.map +1 -0
- package/types/server/actions.d.ts +1 -0
- package/types/server/actions.d.ts.map +1 -1
- package/types/server/api.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +3 -2
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/env-state.d.ts.map +1 -1
- package/types/server/env.d.ts +5 -1
- package/types/server/env.d.ts.map +1 -1
- package/types/server/favicon.d.ts +3 -1
- package/types/server/favicon.d.ts.map +1 -1
- package/types/server/kept-pages.d.ts +1 -1
- package/types/server/kept-pages.d.ts.map +1 -1
- package/types/server/library.d.ts +2 -0
- package/types/server/library.d.ts.map +1 -1
- package/types/server/mcp.d.ts +1 -1
- package/types/server/mcp.d.ts.map +1 -1
- package/types/server/notifications.d.ts +2 -1
- package/types/server/notifications.d.ts.map +1 -1
- package/types/server/offline.d.ts.map +1 -1
- package/types/server/push-settings.d.ts +1 -1
- package/types/server/push-settings.d.ts.map +1 -1
- package/types/server/push.d.ts +1 -0
- package/types/server/push.d.ts.map +1 -1
- package/types/server/query.d.ts.map +1 -1
- package/types/server/scope.d.ts +1 -1
- package/types/server/scope.d.ts.map +1 -1
- package/types/test/a11y-dom.d.ts +20 -0
- package/types/test/a11y-dom.d.ts.map +1 -0
- package/types/test/html-snapshot.d.ts +4 -0
- package/types/test/html-snapshot.d.ts.map +1 -0
- package/types/test/index.d.ts.map +1 -1
- package/types/test/mount.d.ts +3 -0
- package/types/test/mount.d.ts.map +1 -1
- package/types/test/page-checks.d.ts +6 -0
- package/types/test/page-checks.d.ts.map +1 -0
- package/types/test/screenshot-match.d.ts +1 -1
- package/types/test/screenshot-match.d.ts.map +1 -1
- package/types/test/shared-modules.d.ts.map +1 -1
- package/types/test/site-types.d.ts +3 -1
- package/types/test/site-types.d.ts.map +1 -1
package/src/compiler/html.ts
CHANGED
|
@@ -9,7 +9,8 @@ import { actionOf, failedBlockOf, marksServerIsland, sectionOf, serverIslandOf }
|
|
|
9
9
|
import { decodeEntities } from './expression'
|
|
10
10
|
import { addFieldDescribed, addInvalidAttribute } from './field-described'
|
|
11
11
|
import { valuesOf } from './form-info'
|
|
12
|
-
import {
|
|
12
|
+
import { addClassAttribute, addFieldFill, addSchemaOptions, listsFromSchema, schemaTypeCall } from './html-fields'
|
|
13
|
+
import { addInitial } from './html-initial'
|
|
13
14
|
import { Markup } from './html-parts'
|
|
14
15
|
import { addRowItem, childItems, constDeclaration, contentOf, errorParagraphArguments, fixedSource, isDeclaration, rowKeying, slotValue, soleDynamic } from './items'
|
|
15
16
|
import { END_MARKER, escapeStaticAttribute, escapeText, fromRoot, helperName, RAW_ELEMENTS, START_MARKER, TemplateWriter, VOID_ELEMENTS } from './markup'
|
|
@@ -480,7 +481,8 @@ export class HtmlTemplate extends TemplateWriter {
|
|
|
480
481
|
const describable = fieldAria !== undefined
|
|
481
482
|
let ownDescribed: (() => void) | undefined
|
|
482
483
|
let refusing: (() => void) | undefined
|
|
483
|
-
const
|
|
484
|
+
const schemaType = schemaTypeCall(b, name, type, field, target)
|
|
485
|
+
const fieldDescribed = (own: (() => void) | undefined, refusing?: () => void) => addFieldDescribed(b, own, type, fieldAria, refusing, schemaType)
|
|
484
486
|
|
|
485
487
|
markup.text(`<${name}${element.fixed ?? ''}`)
|
|
486
488
|
|
|
@@ -492,32 +494,7 @@ export class HtmlTemplate extends TemplateWriter {
|
|
|
492
494
|
if (unit !== undefined)
|
|
493
495
|
markup.text(` data-kay-u="${unit.id}"`)
|
|
494
496
|
|
|
495
|
-
|
|
496
|
-
const classes = plan.classes
|
|
497
|
-
|
|
498
|
-
markup.dynamic(() => {
|
|
499
|
-
b.add(`${helperName('nonEmptyAttribute')}("class", ${helperName('className')}(`)
|
|
500
|
-
this.classList(classes)
|
|
501
|
-
b.add('))')
|
|
502
|
-
})
|
|
503
|
-
}
|
|
504
|
-
else if (plan.classes?.expression) {
|
|
505
|
-
const { text, expression } = plan.classes
|
|
506
|
-
|
|
507
|
-
markup.text(' class="')
|
|
508
|
-
markup.dynamic(() => b.add(`${helperName('className')}([${JSON.stringify(text)}, (`).addSource(expression).add(')])'))
|
|
509
|
-
markup.text('"')
|
|
510
|
-
}
|
|
511
|
-
else if (plan.classes?.pieces) {
|
|
512
|
-
const { pieces } = plan.classes
|
|
513
|
-
|
|
514
|
-
markup.text(' class="')
|
|
515
|
-
markup.dynamic(() => b.add(`${helperName('className')}(${JSON.stringify(pieces)})`))
|
|
516
|
-
markup.text('"')
|
|
517
|
-
}
|
|
518
|
-
else if (plan.classes) {
|
|
519
|
-
markup.text(` class="${escapeStaticAttribute(plan.classes.text)}"`)
|
|
520
|
-
}
|
|
497
|
+
addClassAttribute(b, markup, plan.classes, classes => this.classList(classes))
|
|
521
498
|
|
|
522
499
|
for (const attribute of plan.attributes) {
|
|
523
500
|
if (attribute.kind === 'binding') {
|
|
@@ -667,7 +644,7 @@ export class HtmlTemplate extends TemplateWriter {
|
|
|
667
644
|
}
|
|
668
645
|
|
|
669
646
|
if (filled)
|
|
670
|
-
|
|
647
|
+
addFieldFill(b, this.src, element, markup, { filled, fieldArguments, own: ownFill, box: checkboxValue, values, name: field.name }, field, name === 'input' && !this.named(element, 'type'))
|
|
671
648
|
|
|
672
649
|
if (field.invalid) {
|
|
673
650
|
refusing = fieldArguments
|
|
@@ -751,12 +728,18 @@ export class HtmlTemplate extends TemplateWriter {
|
|
|
751
728
|
// A refused post's text takes the place of the textarea's static value.
|
|
752
729
|
const staticContent = field?.fill === 'content' && plan.valueText !== undefined ? undefined : plan.staticContent
|
|
753
730
|
|
|
754
|
-
|
|
731
|
+
const fromSchema = listsFromSchema(name, children, field)
|
|
732
|
+
|
|
733
|
+
if (field && (fromSchema || (children.length > 0 && field.fill === 'selected')) && target) {
|
|
755
734
|
const own = selected
|
|
756
735
|
|
|
757
736
|
markup.dynamic(() => {
|
|
758
737
|
b.add(`${helperName('refillOptions')}(KayFormValue((`).addSource(target).add(`), ${JSON.stringify(field.name)}), `)
|
|
759
|
-
|
|
738
|
+
|
|
739
|
+
if (fromSchema)
|
|
740
|
+
addSchemaOptions(b, target, field.name)
|
|
741
|
+
else
|
|
742
|
+
this.markup(children, true)
|
|
760
743
|
|
|
761
744
|
if (own) {
|
|
762
745
|
b.add(', () => ')
|
package/src/compiler/index.ts
CHANGED
|
@@ -80,6 +80,8 @@ export interface CompileOptions {
|
|
|
80
80
|
namedRefresh?: boolean | undefined
|
|
81
81
|
// Server output of a static component's `?island` twin, which carries markers like an island.
|
|
82
82
|
twinBuild?: boolean | undefined
|
|
83
|
+
// The props the component's call sites write, when all are known: the `...rest` of its props leaves out only these of the ones it declares.
|
|
84
|
+
writtenProps?: ReadonlySet<string> | undefined
|
|
83
85
|
// Whether the file is a page of a routes directory (`isPageFile`), which nothing renders inside an island, so a page without a server fence reads its loops as static as the build does, is refused `--- client` and `--- island`, and is no island by its pin; `false` says it is a component, where a root `@block` is refused.
|
|
84
86
|
page?: boolean | undefined
|
|
85
87
|
// Whether the file is known to be a component, which has no `--- server` fence: a library checked on its own has pages no routes directory names, so only a caller knowing its routes says so.
|
|
@@ -325,7 +327,7 @@ export function compileKay(original: string, filename: string, options: CompileO
|
|
|
325
327
|
const pin = file.pin
|
|
326
328
|
const rawCause = island === undefined ? undefined : islandCause(file, script) ?? browserCause(file, script, live)
|
|
327
329
|
const cause = withInteractive(realCause(rawCause, expansion, original), script)
|
|
328
|
-
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, 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: basename(filename) === LAYOUT, component: options.page === false && !routeFile, check: options.check, route: options.check === true && pageFile, pageFile, namedRefresh: options.namedRefresh, insideIsland: options.insideIsland, inspect: options.inspect, inspectSource: expansion ? { text: original, real: (offset: number) => expansion.real(offset) } : undefined, relocateImport: options.relocateImport, contextModule: options.check === true ? options.contextModule : undefined, ui: options.output === undefined ? undefined : options.ui, uiAdded: options.output === undefined ? options.ui : undefined, errorPage: isErrorPage(basename(filename)), cardPage: basename(filename) === CARD_PAGE, special: basename(filename).startsWith('_') && basename(filename) !== LAYOUT }
|
|
330
|
+
const generateOptions = { cause: options.inspect === true && cause !== undefined ? describeCause(cause) : undefined, classTable: options.classTable, classMerge: options.classMerge, awaitAlert: options.awaitAlert, island, client, lives: island === undefined ? undefined : liveBindings(script, options.importedSignals).map(binding => binding.local), twin, writtenProps: options.writtenProps, output: options.output, failedCode, hydratable: 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: basename(filename) === LAYOUT, component: options.page === false && !routeFile, check: options.check, route: options.check === true && pageFile, pageFile, namedRefresh: options.namedRefresh, insideIsland: options.insideIsland, inspect: options.inspect, inspectSource: expansion ? { text: original, real: (offset: number) => expansion.real(offset) } : undefined, relocateImport: options.relocateImport, contextModule: options.check === true ? options.contextModule : undefined, ui: options.output === undefined ? undefined : options.ui, uiAdded: options.output === undefined ? options.ui : undefined, errorPage: isErrorPage(basename(filename)), cardPage: basename(filename) === CARD_PAGE, special: basename(filename).startsWith('_') && basename(filename) !== LAYOUT }
|
|
329
331
|
// The analysis pass names the component so no read resolves to it, then the name is chosen free of what the code reads.
|
|
330
332
|
const analysis = generate(file, script, server, { ...generateOptions, name: SELF })
|
|
331
333
|
const imported = new Map<string, SignalKind>([...script.imports, ...server?.imports ?? []].flatMap((binding) => {
|
package/src/compiler/items.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { parsedBindingNames } from './pattern-names'
|
|
|
9
9
|
export type Item
|
|
10
10
|
= | { kind: 'text', text: string }
|
|
11
11
|
| { kind: 'element', node: ElementNode }
|
|
12
|
-
| { kind: 'expression', node: TextExpression }
|
|
12
|
+
| { kind: 'expression', node: TextExpression, line: Node }
|
|
13
13
|
| { kind: 'component', node: ElementNode }
|
|
14
14
|
| { kind: 'slot', node: ElementNode }
|
|
15
15
|
| { kind: 'if', node: IfNode }
|
|
@@ -91,7 +91,7 @@ export function childItems(nodes: Node[]): Item[] {
|
|
|
91
91
|
if (part.kind === 'element')
|
|
92
92
|
element(part)
|
|
93
93
|
else if (part.kind === 'expression')
|
|
94
|
-
items.push({ kind: 'expression', node: part })
|
|
94
|
+
items.push({ kind: 'expression', node: part, line: node })
|
|
95
95
|
else if (part.text !== '')
|
|
96
96
|
text(part.text)
|
|
97
97
|
}
|
|
@@ -244,7 +244,7 @@ export function fixedSource(element: ElementNode): string {
|
|
|
244
244
|
return names.length === 0 ? '' : `, { ${names.map(name => `${JSON.stringify(name)}: ""`).join(', ')} }`
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
// What an `error` or `pending` line outside every form of its file reads: the form it renders in, and the message the action gave a field; the import drops a repeat.
|
|
248
|
-
export function ambientHelpers(facts: { ambientForm: boolean }): ('formHere' | 'formError')[] {
|
|
249
|
-
return facts.ambientForm ? ['formHere', 'formError'] : []
|
|
247
|
+
// What an `error` or `pending` line outside every form of its file reads: the form it renders in, and the message the action gave a field; in the browser a snippet called in a form is built in that form's scope; the import drops a repeat.
|
|
248
|
+
export function ambientHelpers(facts: { ambientForm: boolean, snippet: boolean, forms: ReadonlyMap<unknown, unknown> }, mode: string): ('formHere' | 'formError' | 'issueScope')[] {
|
|
249
|
+
return [...facts.ambientForm ? ['formHere' as const, 'formError' as const] : [], ...mode === 'dom' && facts.snippet && facts.forms.size > 0 ? ['issueScope' as const] : []]
|
|
250
250
|
}
|
|
@@ -3,7 +3,7 @@ import type { Lint } from './lints'
|
|
|
3
3
|
import { editDistance } from './aria'
|
|
4
4
|
import { elementsIn } from './ast'
|
|
5
5
|
|
|
6
|
-
interface Renamed {
|
|
6
|
+
export interface Renamed {
|
|
7
7
|
name: string
|
|
8
8
|
value: string
|
|
9
9
|
// What a `false` value of the old name becomes, for a flag that was off by that word.
|
|
@@ -23,13 +23,14 @@ export const LINK_LINTS = {
|
|
|
23
23
|
|
|
24
24
|
// The attributes a link, or an element around links, takes to say how the swap follows it, named as the options of `navigate()` are: `scroll`, `transition`, `prefetch`, and `reload` for a full load.
|
|
25
25
|
const FLAGS = new Set(['data-scroll', 'data-transition', 'data-prefetch', 'data-reload'])
|
|
26
|
+
|
|
26
27
|
// The names before 1.105 and what each became: `data-keep-scroll` is `data-scroll="keep"`, `data-no-transition` is `data-transition="false"`, `data-no-prefetch` is `data-prefetch="false"`.
|
|
27
|
-
const
|
|
28
|
+
export const OLD_LINK_FLAGS: Record<string, Renamed> = {
|
|
28
29
|
'data-keep-scroll': { name: 'data-scroll', value: 'keep', off: 'top' },
|
|
29
30
|
'data-no-transition': { name: 'data-transition', value: 'false' },
|
|
30
31
|
'data-no-prefetch': { name: 'data-prefetch', value: 'false' },
|
|
31
32
|
}
|
|
32
|
-
const NEARBY = [...FLAGS, ...Object.keys(
|
|
33
|
+
const NEARBY = [...FLAGS, ...Object.keys(OLD_LINK_FLAGS)]
|
|
33
34
|
|
|
34
35
|
// The name an attribute is written with, none for a spread or a `{name}` shorthand.
|
|
35
36
|
function nameOf(attribute: Attribute): Span | undefined {
|
|
@@ -66,7 +67,7 @@ export function linkFlags(file: KayFile): Diagnostic[] {
|
|
|
66
67
|
continue
|
|
67
68
|
|
|
68
69
|
const name = file.source.slice(at.start, at.end)
|
|
69
|
-
const old =
|
|
70
|
+
const old = OLD_LINK_FLAGS[name]
|
|
70
71
|
|
|
71
72
|
if (old !== undefined) {
|
|
72
73
|
found.push(oldFlag(file.source, attribute, at, name, old))
|
|
@@ -79,7 +80,7 @@ export function linkFlags(file: KayFile): Diagnostic[] {
|
|
|
79
80
|
if (meant === undefined)
|
|
80
81
|
continue
|
|
81
82
|
|
|
82
|
-
const renamed =
|
|
83
|
+
const renamed = OLD_LINK_FLAGS[meant]
|
|
83
84
|
const to = renamed === undefined ? meant : `${renamed.name}="${renamed.value}"`
|
|
84
85
|
// An old name written with a value keeps that value after the name, so writing `name="value"` there would leave two: that case gets the help alone.
|
|
85
86
|
const fixes = renamed !== undefined && attribute.kind !== 'boolean' ? [] : [{ title: `Write \`${to}\``, safe: false, edits: [{ ...at, text: to }] }]
|
package/src/compiler/lints.ts
CHANGED
|
@@ -295,8 +295,8 @@ export const LINTS = {
|
|
|
295
295
|
level: 'warn',
|
|
296
296
|
group: 'forms',
|
|
297
297
|
summary: 'A string field of an action\'s schema named like a short value (`name`, `email`, `title`, `subject`, `slug`, `phone`, `code`...) with no `maxLength` of its own: every string field is refused past 10,000 characters by default, which is far too long for these. Any other field keeps the default, and a secret such as a password is left alone.',
|
|
298
|
-
wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.
|
|
299
|
-
right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.
|
|
298
|
+
wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.object({ title: s.string() }), async ({ title }) => create(title))\n---\nform(action={add})\n input(name="title")',
|
|
299
|
+
right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.object({ title: s.string({ max: 200 }) }), async ({ title }) => create(title))\n---\nform(action={add})\n input(name="title")',
|
|
300
300
|
},
|
|
301
301
|
'css-import-without-text': {
|
|
302
302
|
level: 'deny',
|
|
@@ -309,22 +309,22 @@ export const LINTS = {
|
|
|
309
309
|
level: 'warn',
|
|
310
310
|
group: 'code',
|
|
311
311
|
summary: 'An `async` function returning `ask()` from kayjs-ai: the reply is a thenable, so the function awaits it and the action, API route or `await` block reading it gets the whole text at once, with no streaming. The fix removes `async` (not from a function with a return type); a function that awaits something first returns `ask(...).stream()` instead, and `return await ask(...)` says the whole text is meant, which this lint leaves alone. Found in `.kay` fences and `.ts` modules alike.',
|
|
312
|
-
wrong: '--- server\nimport { ask } from \'@kayjs/ai\'\nimport { action, s } from \'kay\'\n\nexport const reply = action(s.
|
|
313
|
-
right: '--- server\nimport { ask } from \'@kayjs/ai\'\nimport { action, s } from \'kay\'\n\nexport const reply = action(s.
|
|
312
|
+
wrong: '--- server\nimport { ask } from \'@kayjs/ai\'\nimport { action, s } from \'kay\'\n\nexport const reply = action(s.object({ messages: s.list(s.string()) }), async ({ messages }) => ask(messages))\n---\np x',
|
|
313
|
+
right: '--- server\nimport { ask } from \'@kayjs/ai\'\nimport { action, s } from \'kay\'\n\nexport const reply = action(s.object({ messages: s.list(s.string()) }), ({ messages }) => ask(messages))\n---\np x',
|
|
314
314
|
},
|
|
315
315
|
'unreturned-fail': {
|
|
316
316
|
level: 'deny',
|
|
317
317
|
group: 'code',
|
|
318
318
|
summary: 'A `ctx.fail(...)` statement in an action\'s handler (or `fail(...)` destructured from the context) that is not returned: `fail` returns the failure the action answers with, where `deny`, `notFound` and `redirect` throw, so the statement does nothing and the handler carries on. An arrow function with an expression body already returns, and a nested function is left alone. The fix prepends `return`. Found in `.kay` fences and `.ts` modules alike.',
|
|
319
|
-
wrong: '--- server\nexport const rename = action(s.
|
|
320
|
-
right: '--- server\nexport const rename = action(s.
|
|
319
|
+
wrong: '--- server\nexport const rename = action(s.object({ name: s.string() }), ({ name }, ctx) => {\n if (name === \'admin\')\n ctx.fail(409, \'That name is taken\')\n\n return name\n})\n---\np x',
|
|
320
|
+
right: '--- server\nexport const rename = action(s.object({ name: s.string() }), ({ name }, ctx) => {\n if (name === \'admin\')\n return ctx.fail(409, \'That name is taken\')\n\n return name\n})\n---\np x',
|
|
321
321
|
},
|
|
322
322
|
'missing-captcha': {
|
|
323
323
|
level: 'warn',
|
|
324
324
|
group: 'forms',
|
|
325
325
|
summary: 'A call to `password.register`, `password.requestReset`, `magicLink.request` or `password.signIn` on an auth (a receiver named `auth`, or ending in `auth`), with no `captcha` option, while no `captcha: false` is written in the same file or in an `authCore` (`createAuth` before 1.91) call of the project (`kay check` reads every module): kayjs-auth asks a proof of work by default, so such a call answers `{ ok: false, error: \'captcha\' }` until the form carries the challenge. Put `input(type="hidden" name="captcha" data-kay-work={await auth.captcha.challenge(\'register\')})` in the form (action `\'reset\'`, `\'magic-link\'` or `\'sign-in\'` for the others), read the field in the action and pass it as `{ captcha: input.captcha }`. Found in `.kay` fences and `.ts` modules alike.',
|
|
326
|
-
wrong: '--- server\nexport const reset = action(s.
|
|
327
|
-
right: '--- server\nexport const reset = action(s.
|
|
326
|
+
wrong: '--- server\nexport const reset = action(s.object({ email: s.string() }), ({ email }, ctx) => ctx.locals.auth.password.requestReset(email))\n---\np x',
|
|
327
|
+
right: '--- server\nexport const reset = action(s.object({ email: s.string(), captcha: s.string() }), ({ email, captcha }, ctx) => ctx.locals.auth.password.requestReset(email, { captcha }))\n---\np x',
|
|
328
328
|
},
|
|
329
329
|
'positional-key': {
|
|
330
330
|
level: 'deny',
|
|
@@ -411,8 +411,8 @@ export const LINTS = {
|
|
|
411
411
|
group: 'security',
|
|
412
412
|
site: true,
|
|
413
413
|
summary: 'With `mcp`, an action that sets `tool` and a `honeypot`, `minTime` or `proofOfWork`, with no `_guard.ts` covering it: an agent calls it without the form those protections ask of a person, so anonymous callers can spam it. A guard, or a `rateLimit` with `tool` alone, keeps it in hand.',
|
|
414
|
-
wrong: '// kay.config.ts sets mcp: true\nexport const subscribe = action(s.
|
|
415
|
-
right: '// src/routes/_guard.ts covers it, or the action keeps tool and drops the honeypot\nexport const subscribe = action(s.
|
|
414
|
+
wrong: '// kay.config.ts sets mcp: true\nexport const subscribe = action(s.object({ email: s.string() }), save, { tool: true, protect: { honeypot: \'website\' } })',
|
|
415
|
+
right: '// src/routes/_guard.ts covers it, or the action keeps tool and drops the honeypot\nexport const subscribe = action(s.object({ email: s.string() }), save, { tool: true, protect: { rateLimit: { max: 5, window: \'1m\' } } })',
|
|
416
416
|
},
|
|
417
417
|
'external-redirect': {
|
|
418
418
|
level: 'warn',
|
|
@@ -489,8 +489,8 @@ export const LINTS = {
|
|
|
489
489
|
group: 'code',
|
|
490
490
|
site: true,
|
|
491
491
|
summary: 'An API route `.ws()` with a `body` and no `response`, written with an object literal of options and no spread: an island\'s `socket()` receives its messages as `unknown`, so `last()` and `on()` need a cast. Add `response: chats.response` when it sends through `rooms()`, or a `response` schema; a route only other clients read can allow the lint.',
|
|
492
|
-
wrong: 'export default api().ws(\'/\', { body: s.
|
|
493
|
-
right: 'export default api().ws(\'/\', { body: s.
|
|
492
|
+
wrong: 'export default api().ws(\'/\', { body: s.object({ text: s.string() }), message(ws, { text }) { chats.publish(\'main\', { text }) } })',
|
|
493
|
+
right: 'export default api().ws(\'/\', { body: s.object({ text: s.string() }), response: chats.response, message(ws, { text }) { chats.publish(\'main\', { text }) } })',
|
|
494
494
|
},
|
|
495
495
|
'unsized-image': {
|
|
496
496
|
level: 'warn',
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TemplateFacts } from './ast'
|
|
2
|
+
import type { PropsDeclaration } from './script'
|
|
3
|
+
|
|
4
|
+
// The keys `omit` takes out of the props to make the rest object: the declared props that can arrive (all of them, or the ones `written` names), then what a component that merges parts owns (`class`, `parts`, its recipe's variants and the app's).
|
|
5
|
+
export function restOmits(props: PropsDeclaration, written: ReadonlySet<string> | undefined, facts: TemplateFacts): string[] {
|
|
6
|
+
const owned = facts.parts?.merges === true
|
|
7
|
+
const declared = props.bindings.filter(binding => written?.has(binding.key) ?? true)
|
|
8
|
+
|
|
9
|
+
return [
|
|
10
|
+
...declared.map(binding => JSON.stringify(binding.key)),
|
|
11
|
+
...owned ? ['"class"', '"parts"'] : [],
|
|
12
|
+
...owned && facts.recipe !== undefined ? [`...${facts.recipe}.variants`] : [],
|
|
13
|
+
...owned ? Object.keys(facts.ui?.variants ?? {}).map(name => JSON.stringify(name)) : [],
|
|
14
|
+
]
|
|
15
|
+
}
|
package/src/config-loader.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { existsSync, realpathSync } from 'node:fs'
|
|
|
4
4
|
import { dirname, join, resolve } from 'node:path'
|
|
5
5
|
import process from 'node:process'
|
|
6
6
|
import { APP_DEPENDENCIES, dependencyNames, libraryMessageExtensions, readManifest } from './build/manifests'
|
|
7
|
+
import { setUiLayers } from './build/ui-layers'
|
|
7
8
|
import { KayError } from './compiler/errors'
|
|
8
9
|
import { APP_CONTEXT, CONFIG_FILE } from './config'
|
|
9
10
|
import { resolveConfig } from './config-resolve'
|
|
@@ -14,7 +15,14 @@ import { publicEnvFiles } from './server/env-state'
|
|
|
14
15
|
|
|
15
16
|
// `fresh` reads the file again as it is now, as `kay dev` does once it changed, rather than the module this process imported first.
|
|
16
17
|
export async function loadConfig(root: string, fresh = false): Promise<LoadedConfig> {
|
|
17
|
-
return withTailwind(root, withSiteUrl(withPublicFields(root, withExtensions(withAppContext(root, withLibraryMessages(root, await importConfig(root, fresh)))))))
|
|
18
|
+
return withUiLayers(root, await withTailwind(root, withSiteUrl(withPublicFields(root, withExtensions(withAppContext(root, withLibraryMessages(root, await importConfig(root, fresh))))))))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The config, once the `ui` files of its extensions are known to the build of the project.
|
|
22
|
+
function withUiLayers<Config extends KayConfig>(root: string, config: Config): Config {
|
|
23
|
+
setUiLayers(root, config.extensions)
|
|
24
|
+
|
|
25
|
+
return config
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
const CONFIG_TIMEOUT = 30_000
|
|
@@ -332,7 +340,7 @@ export async function withConfig<Options extends ConfigInput>(root: string, opti
|
|
|
332
340
|
// The options are resolved as the file is, so a code call may pass a list's function or an old key as `kay.config.ts` may.
|
|
333
341
|
const given = await resolveConfig(options) as KayConfig & Omit<Options, keyof ConfigInput>
|
|
334
342
|
|
|
335
|
-
return withTailwind(root, withPublicFields(root, withAppContext(root, mergeConfig(withLibraryMessages(root, await importConfig(root)), given))))
|
|
343
|
+
return withUiLayers(root, await withTailwind(root, withPublicFields(root, withAppContext(root, mergeConfig(withLibraryMessages(root, await importConfig(root)), given)))))
|
|
336
344
|
}
|
|
337
345
|
|
|
338
346
|
// `config` is as `kay.config.ts` writes it, so the extensions the options name lie under it rather than the file's.
|
package/src/config-resolve.ts
CHANGED
|
@@ -173,13 +173,15 @@ export async function resolveConfig(config: ConfigInput): Promise<KayConfig> {
|
|
|
173
173
|
])
|
|
174
174
|
const cors = config.cors === undefined ? undefined : await loadKeys(config.cors, ['origins'])
|
|
175
175
|
const { onStart, ...kept } = config
|
|
176
|
+
// An extension's config is written as `kay.config.ts` is, so its keys of before 1.105 move as the app's do.
|
|
177
|
+
const extensions = config.extensions === undefined ? undefined : await Promise.all(config.extensions.map(async extension => extension.config === undefined ? extension : { ...extension, config: await resolveConfig(extension.config) }))
|
|
176
178
|
|
|
177
179
|
for (const key of MOVED_KEYS)
|
|
178
180
|
delete kept[key]
|
|
179
181
|
|
|
180
182
|
const { ops, onError, paths } = resolveOps(config)
|
|
181
183
|
const routes = resolveEndpoints(config, paths, resolveMcp(config.mcp))
|
|
182
|
-
const resolved: Record<string, unknown> = { ...kept, security, proxy: resolveProxy(proxy), ...routes, robots, i18n, redirects, assets, ops, cors, client: resolveClient(config), onListen: config.onListen ?? onStart, onError: config.onError ?? onError }
|
|
184
|
+
const resolved: Record<string, unknown> = { ...kept, ...extensions !== undefined && { extensions }, security, proxy: resolveProxy(proxy), ...routes, robots, i18n, redirects, assets, ops, cors, client: resolveClient(config), onListen: config.onListen ?? onStart, onError: config.onError ?? onError }
|
|
183
185
|
|
|
184
186
|
for (const key of Object.keys(resolved)) {
|
|
185
187
|
if (resolved[key] === undefined)
|
package/src/config-shape.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BudgetConfig } from './build/budget'
|
|
2
|
-
import type { ActionsConfig, AssetsConfig, CardConfig, ClientConfig, ConfigInput, CookieDefaults, DeprecatedMcp, DeprecatedOpenApi, DeprecatedPath, DeprecatedServe, DirsConfig, EndpointsConfig, FaviconConfig, HealthConfig, I18nInput, ImageFormats, ImageLimits, ImagesInput, JobsConfig, LimitsConfig, LiveConfig, LogConfig, ManifestConfig, MarkdownConfig, MetricsConfig, ObserveInput, OfflineConfig, OpsConfig, PreviewConfig, ProxyConfig, RemoteImages, RobotsConfig, SecurityConfig, SeoConfig, ServeConfig, SitemapConfig } from './config'
|
|
2
|
+
import type { ActionsConfig, AssetsConfig, CardConfig, ClientConfig, ConfigInput, CookieDefaults, DeprecatedMcp, DeprecatedOpenApi, DeprecatedPath, DeprecatedServe, DirsConfig, EndpointsConfig, FaviconConfig, HealthConfig, I18nInput, ImageFormats, ImageLimits, ImagesInput, JobsConfig, LimitsConfig, LiveConfig, LogConfig, ManifestConfig, ManifestShareTarget, MarkdownConfig, MetricsConfig, ObserveInput, OfflineConfig, OpsConfig, PreviewConfig, ProxyConfig, RemoteImages, RobotsConfig, SecurityConfig, SeoConfig, ServeConfig, SitemapConfig } from './config'
|
|
3
3
|
import type { Rule } from './config-rules'
|
|
4
4
|
import type { McpConfig } from './server/api-modules'
|
|
5
5
|
import type { OpenApiConfig } from './server/openapi'
|
|
@@ -45,7 +45,7 @@ const JOBS: Record<keyof (JobsConfig & DeprecatedPath), Rule> = { guards: guardO
|
|
|
45
45
|
const METRICS: Record<keyof (MetricsConfig & DeprecatedPath), Rule> = { path: str, token: either(lit(true), SECRET) }
|
|
46
46
|
const BUDGET: Record<keyof BudgetConfig, Rule> = { js: bytes, css: bytes, weight: bytes, grade: oneOf('A', 'B', 'C', 'D', 'E', 'F', 'G') }
|
|
47
47
|
const FAVICON: Record<keyof FaviconConfig, Rule> = { image: str, svg: str }
|
|
48
|
-
const MANIFEST: Record<keyof ManifestConfig, Rule> = { shortName: str, themeColor: either(str, bag({ light: str, dark: str })), backgroundColor: str, display: oneOf('fullscreen', 'standalone', 'minimal-ui', 'browser'), orientation: oneOf('any', 'natural', 'landscape', 'landscape-primary', 'landscape-secondary', 'portrait', 'portrait-primary', 'portrait-secondary'), startUrl: str, scope: str, maskable: str, shortcuts: list(obj) }
|
|
48
|
+
const MANIFEST: Record<keyof ManifestConfig, Rule> = { shortName: str, themeColor: either(str, bag({ light: str, dark: str })), backgroundColor: str, display: oneOf('fullscreen', 'standalone', 'minimal-ui', 'browser'), orientation: oneOf('any', 'natural', 'landscape', 'landscape-primary', 'landscape-secondary', 'portrait', 'portrait-primary', 'portrait-secondary'), startUrl: str, scope: str, maskable: str, shortcuts: list(obj), shareTarget: bag({ action: str, files: list(str), params: bag({ title: str, text: str, url: str, files: str }) } satisfies Record<keyof ManifestShareTarget, Rule>) }
|
|
49
49
|
const MARKDOWN: Record<keyof MarkdownConfig, Rule> = { highlight: fn, transform: fn, preprocess: fn, containers: bool, footnotes: bool, headingLinks: bool, readingSpeed: num, imageSizes: str }
|
|
50
50
|
const CARD: Record<keyof CardConfig, Rule> = { font: bag({ family: str, weight: num }), background: str, color: str, logo: str }
|
|
51
51
|
const AVIF = either(bool, bag({ quality: num }))
|
package/src/config.ts
CHANGED
|
@@ -310,7 +310,7 @@ export interface EndpointsConfig {
|
|
|
310
310
|
api?: string | undefined
|
|
311
311
|
// Where the OpenAPI document is served, `/api/openapi.json` under the API prefix by default; its reference page is set in `openapi.reference`.
|
|
312
312
|
openapi?: string | undefined
|
|
313
|
-
// Where the MCP endpoint is served, `/_kay/mcp` by default. `/mcp`, where it was served before 1.105,
|
|
313
|
+
// Where the MCP endpoint is served, `/_kay/mcp` by default. `/mcp`, where it was served before 1.105, is answered in place until 2.0 when this is not set.
|
|
314
314
|
mcp?: string | undefined
|
|
315
315
|
// Where the health check is served, `/_kay/health` by default.
|
|
316
316
|
health?: string | undefined
|
|
@@ -439,6 +439,17 @@ export interface ManifestConfig {
|
|
|
439
439
|
maskable?: string | undefined
|
|
440
440
|
// The pages a launcher offers from the app's icon.
|
|
441
441
|
shortcuts?: ManifestShortcut[] | undefined
|
|
442
|
+
// Lists the installed app among the apps a device's share sheet offers, the shared title, text, link and files posted to an action.
|
|
443
|
+
shareTarget?: ManifestShareTarget | undefined
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export interface ManifestShareTarget {
|
|
447
|
+
// Where a share is posted: an action as `'src/routes/share.kay#receive'`, the page file relative to the root and the exported action's name, or a path of the site (`'/share'`) for a route of your own taking a POST. The action reads `title`, `text`, `url` and `files`, whichever the sharing app sent, all optional.
|
|
448
|
+
action: string
|
|
449
|
+
// The kinds of file the app takes, as MIME types or extensions (`['image/*', '.pdf']`); with some the share is posted as `multipart/form-data` and the action reads them as `files`, without any only text and a link are shared.
|
|
450
|
+
files?: string[] | undefined
|
|
451
|
+
// The field each part of a share is posted as, `title`, `text`, `url` and `files` by default.
|
|
452
|
+
params?: { title?: string | undefined, text?: string | undefined, url?: string | undefined, files?: string | undefined } | undefined
|
|
442
453
|
}
|
|
443
454
|
|
|
444
455
|
export interface ManifestShortcut {
|
|
@@ -626,8 +637,10 @@ export interface KayExtension<Server extends PluginInput = AnyElysia> {
|
|
|
626
637
|
appFiles?: Record<string, string> | undefined
|
|
627
638
|
// The server plugin named by the module that exports it, `{ path: './src/auth', export: 'auth' }` for `export const auth` (`default` by default): imported only as `pages()` builds the app, and baked into an executable `kay build --compile` makes, which a path built at run time inside a library could not be. The export is the plugin, a function building it, or an object carrying it as `plugin`, as a library's `authCore` result does. `kay check` types the locals off the module itself, and off the extension's `Server` argument when it has one; used beside `server`, the module wins. A path is relative to the project root. `prepare` runs with the export before the plugin is taken from it, for a library to hand the app's module what the extension was given; a throw stops the server.
|
|
628
639
|
serverModule?: { path: string, export?: string | undefined, prepare?: ((exported: unknown) => void | Promise<void>) | undefined } | undefined
|
|
629
|
-
// Config laid under the app's `kay.config.ts`: objects merged key by key, arrays joined with the extension's items first, any other value the app sets winning. Bun plugins the library's files need go in its `plugins`.
|
|
630
|
-
config?: Omit<
|
|
640
|
+
// Config laid under the app's `kay.config.ts`: objects merged key by key, arrays joined with the extension's items first, any other value the app sets winning. Bun plugins the library's files need go in its `plugins`. It takes what `kay.config.ts` does, the keys of before 1.105 included (`fonts`, `favicon`, `observe`...), which work until 1.108 under `deprecated-config-groups`.
|
|
641
|
+
config?: Omit<ConfigInput, 'extensions'> | undefined
|
|
642
|
+
// A module whose default export is `defineUi({ ... })`, written as `src/ui.ts` is (string and object literals only), absolute or relative to the project root: the parts and variants it sets for components, the app's own or a library's, reach every app listing the extension, under the app's own `src/ui.ts`. A part or a variant value the app sets replaces the extension's, and a later extension's replaces an earlier one's. Names and relative specifiers resolve from the app's `src/`.
|
|
643
|
+
ui?: string | undefined
|
|
631
644
|
// A directory of `.kay` pages, layouts and guards laid over the app's routes under `prefix`, the root by default: a file of the app at the same path replaces the library's.
|
|
632
645
|
// Its directories are absolute, as a library gives them from `import.meta.dir`, or relative to the project root.
|
|
633
646
|
routes?: { dir: string, prefix?: string | undefined } | undefined
|
|
@@ -782,7 +795,10 @@ type CaseVariant<Key, Known> = { [Name in keyof Known & string]: Lowercase<Name>
|
|
|
782
795
|
type Misspelled<Key, Known> = [CaseVariant<Key, Known>] extends [never] ? 'unknown option' : `unknown option, did you mean \`${CaseVariant<Key, Known> & string}\`?`
|
|
783
796
|
|
|
784
797
|
// A symbol key is no option a config names, and an object a library returns may carry one, as `pgData()`'s `Symbol.asyncDispose` does.
|
|
785
|
-
type UnknownKeys<Given, Known> = Given extends object ? { [Key in Exclude<keyof Given,
|
|
798
|
+
type UnknownKeys<Given, Known> = Given extends object ? { [Key in Exclude<keyof Given, AllKeys<Known> | symbol>]: Misspelled<Key, Known> } : unknown
|
|
799
|
+
|
|
800
|
+
// The keys of every member of a union of object shapes (`{ env } | { file }`), where `keyof` keeps only the keys they share, none for that one.
|
|
801
|
+
type AllKeys<Known> = Known extends unknown ? keyof Known : never
|
|
786
802
|
|
|
787
803
|
type Method = (...args: never[]) => unknown
|
|
788
804
|
|
package/src/content/markdown.ts
CHANGED
|
@@ -102,8 +102,7 @@ export const LOADED_HTML: SanitizeOptions = { ...MARKDOWN_KEPT, relativeUrls: tr
|
|
|
102
102
|
const LOADED: SanitizeOptions = { ...LOADED_HTML, attributes: { ...MARKDOWN_KEPT.attributes, h1: ['id'], h2: ['id'], h3: ['id'], h4: ['id'], h5: ['id'], h6: ['id'], code: ['class'] } }
|
|
103
103
|
// A link the sanitizer wrote that stays on the site: its `href` names no http(s) URL.
|
|
104
104
|
const OWN_LINK = /<a href="((?!https?:\/\/)[^"]*)" rel="nofollow ugc">/gi
|
|
105
|
-
// The only
|
|
106
|
-
const CODE_CLASS = /<code class="(?!language-[\w+#.-]+")[^"]*">/g
|
|
105
|
+
// The only id kept on a heading: a slug in its shape, so a loader's text cannot pick a camelCase global name (the sanitizer keeps no class on a code block but its language).
|
|
107
106
|
const HEADING_ID = /<(h[1-6]) id="(?![\p{Ll}\p{N}][\p{Ll}\p{N}_-]*")[^"]*"/gu
|
|
108
107
|
// The private characters standing for a component's placeholder while the sanitizer, which reads no tag name with a hyphen, goes over the rest.
|
|
109
108
|
const HELD_PLACEHOLDER = /\uE010(\d+)\uE011|\uE012(\d+)\uE011|\uE013/g
|
|
@@ -241,7 +240,7 @@ export function countWords(html: string): number {
|
|
|
241
240
|
function sanitizedComponents(html: string): string {
|
|
242
241
|
const held = html.replace(PRIVATE_CHARS, char => `&#${char.codePointAt(0)};`).replace(PLACEHOLDER_TAG, (_, selfClosing: string | undefined, opening: string | undefined) => heldPlaceholder(selfClosing, opening))
|
|
243
242
|
|
|
244
|
-
return withoutInnerRel(sanitizedMarkdown(held, LOADED, false).replace(
|
|
243
|
+
return withoutInnerRel(sanitizedMarkdown(held, LOADED, false).replace(HEADING_ID, '<$1').replace(HELD_PLACEHOLDER, (_, selfClosing: string | undefined, opening: string | undefined) => restoredPlaceholder(selfClosing, opening)))
|
|
245
244
|
}
|
|
246
245
|
|
|
247
246
|
// The sanitizer marks every link as a user's; a link to the site or to a heading is the entry's own, so only one leaving the site keeps its `rel`.
|
package/src/generate-resource.ts
CHANGED
|
@@ -33,14 +33,14 @@ interface TypeDescription {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// The range of a 4-byte column, which a bare integer schema would let a post exceed.
|
|
36
|
-
const INT4 = '{
|
|
36
|
+
const INT4 = '{ min: -2147483648, max: 2147483647 }'
|
|
37
37
|
|
|
38
38
|
const TYPES: Record<FieldType, TypeDescription> = {
|
|
39
|
-
string: { column: 'f.varchar(200)', schema: 's.
|
|
40
|
-
text: { column: 'f.text()', schema: 's.
|
|
41
|
-
int: { column: 'f.integer()', schema: `s.
|
|
42
|
-
float: { column: 'f.doublePrecision()', schema: 's.
|
|
43
|
-
boolean: { column: 'f.boolean().default(false)', schema: 's.
|
|
39
|
+
string: { column: 'f.varchar(200)', schema: 's.string({ min: 1, max: 200 })', sample: '\'First\'', posted: '\'First\'', shown: 'First' },
|
|
40
|
+
text: { column: 'f.text()', schema: 's.string({ min: 1, max: 10_000 })', sample: '\'Some text\'', posted: '\'Some text\'', shown: 'Some text' },
|
|
41
|
+
int: { column: 'f.integer()', schema: `s.int(${INT4})`, sample: '42', posted: '\'42\'', shown: '42' },
|
|
42
|
+
float: { column: 'f.doublePrecision()', schema: 's.number()', sample: '4.25', posted: '\'4.25\'', shown: '4.25' },
|
|
43
|
+
boolean: { column: 'f.boolean().default(false)', schema: 's.boolean()', sample: 'true', posted: '\'on\'', shown: 'true' },
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
const ALIASES: Record<string, FieldType> = { string: 'string', text: 'text', int: 'int', integer: 'int', float: 'float', number: 'float', boolean: 'boolean', bool: 'boolean' }
|
|
@@ -170,19 +170,19 @@ const fields = {
|
|
|
170
170
|
${schemas}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
export const create = action(
|
|
173
|
+
export const create = action(fields, async (input, ctx) => {
|
|
174
174
|
await db.repo(${names.pascal}).write.insertOne(input)
|
|
175
175
|
|
|
176
176
|
return ctx.redirect('${list}')
|
|
177
177
|
})
|
|
178
178
|
|
|
179
|
-
export const update = action(
|
|
179
|
+
export const update = action({ id: s.int(${INT4}), ...fields }, async ({ id, ...values }, ctx) => {
|
|
180
180
|
await db.repo(${names.pascal}).write.updateOne(values, { id })
|
|
181
181
|
|
|
182
182
|
return ctx.redirect('${list}')
|
|
183
183
|
})
|
|
184
184
|
|
|
185
|
-
export const remove = action(
|
|
185
|
+
export const remove = action({ id: s.int(${INT4}) }, async ({ id }, ctx) => {
|
|
186
186
|
await db.repo(${names.pascal}).write.deleteOne({ id })
|
|
187
187
|
|
|
188
188
|
return ctx.redirect('${list}')
|
package/src/generate.ts
CHANGED
|
@@ -21,7 +21,7 @@ const WORD_BREAK = /[-_]+/g
|
|
|
21
21
|
// Words an action cannot be exported as, or that its own file already names: the `action` and `s` it calls, `title` its handler reads.
|
|
22
22
|
const RESERVED = new Set(['action', 's', 'title', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof', 'let', 'new', 'null', 'return', 'static', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while', 'with', 'yield', 'implements', 'interface', 'package', 'private', 'protected', 'public', 'eval', 'arguments'])
|
|
23
23
|
// The action added to an `_actions.kay`, or printed for the author to add when the file holds more than a server fence.
|
|
24
|
-
const ACTION_BODY = (name: string) => `export const ${name} = action(\n
|
|
24
|
+
const ACTION_BODY = (name: string) => `export const ${name} = action(\n { title: s.string({ min: 1, max: 200 }) },\n ({ title }) => title,\n)\n`
|
|
25
25
|
const LINE_BREAK = /\r?\n/
|
|
26
26
|
const LINE_BREAKS = /\r?\n/g
|
|
27
27
|
const TABLES_FILE = 'src/db/tables.ts'
|
package/src/mcp/guards.ts
CHANGED
package/src/mcp/tools.ts
CHANGED
|
@@ -216,7 +216,7 @@ function tools(root: string, write: boolean): Tool[] {
|
|
|
216
216
|
return []
|
|
217
217
|
|
|
218
218
|
if (typeof value !== 'number' || !Number.isInteger(value))
|
|
219
|
-
throw new
|
|
219
|
+
throw new TypeError(`${name} takes a whole number of pixels`)
|
|
220
220
|
|
|
221
221
|
return [`--${name}=${value}`]
|
|
222
222
|
})
|