/** * Declarative property schemas. * * One source of truth serves three consumers: runtime validation (with stable * JSON paths), the published JSON Schema, and the compact `catalog()` / * `describe()` contracts. Keeping them derived from one definition is what * stops the documentation from drifting away from the validator. */ import { DiagnosticBag } from '../diagnostics.js'; import { type JsonValue } from '../json.js'; export type PropSchema = StringPropSchema | TextPropSchema | NumberPropSchema | BooleanPropSchema | UrlPropSchema | ListPropSchema | ObjectPropSchema | RecordPropSchema | OneOfPropSchema | JsonPropSchema | BlocksPropSchema; interface PropSchemaBase { /** Reject the document when the property is absent. */ required?: boolean; description?: string; } export interface StringPropSchema extends PropSchemaBase { kind: 'string'; default?: string; enum?: readonly string[]; maxLength?: number; /** Validate as a node-safe identifier (`^[a-z0-9][a-z0-9-]{0,63}$`). */ id?: boolean; } /** Long-form single-line or multi-line text. Escaped at emission. */ export interface TextPropSchema extends PropSchemaBase { kind: 'text'; default?: string; maxLength?: number; } export interface NumberPropSchema extends PropSchemaBase { kind: 'number'; default?: number; min?: number; max?: number; integer?: boolean; } export interface BooleanPropSchema extends PropSchemaBase { kind: 'boolean'; default?: boolean; } /** * A link or asset reference. A relative path stays local; an absolute URL must * use an allowlisted scheme. `data:` and `javascript:` are never accepted. */ export interface UrlPropSchema extends PropSchemaBase { kind: 'url'; default?: string; schemes?: readonly string[]; /** * The value is an asset the page loads, gated by this network capability. The * compiler adds an allowed remote origin to the page's policy, wherever the * prop sits (list items and nested slots included). */ asset?: 'images' | 'media'; /** * A blocked remote reference fails validation at its own path instead of * leaving the renderer to drop it. For assets with no visible fallback, such * as a video poster. */ rejectBlocked?: boolean; } export interface ListPropSchema extends PropSchemaBase { kind: 'list'; of: PropSchema; minItems?: number; maxItems?: number; } export interface ObjectPropSchema extends PropSchemaBase { kind: 'object'; fields: Record; } /** An open-keyed map, e.g. `state` or key/value lists. */ export interface RecordPropSchema extends PropSchemaBase { kind: 'record'; of: PropSchema; maxKeys?: number; } export interface OneOfPropSchema extends PropSchemaBase { kind: 'oneOf'; options: readonly PropSchema[]; } /** * A bounded, structurally-opaque JSON value validated by a capability adapter * (for example an `ak:diagram` typed IR payload). It is still size-bounded and * still scanned for forbidden keys. */ export interface JsonPropSchema extends PropSchemaBase { kind: 'json'; description: string; maxBytes?: number; /** JSON Schema `$ref` used when projecting this prop into the spec schema. */ schemaRef?: string; } /** * A nested list of child blocks. The list never enters `props`: the normalizer * builds each entry as an IR node in `IrNode.slots`. Allowed as a top-level * block prop or as a field of a `list(obj(...))` prop; registration rejects * any deeper position. */ export interface BlocksPropSchema extends PropSchemaBase { kind: 'blocks'; /** Default 1. */ minItems?: number; /** Default 40. */ maxItems?: number; /** Child block types the slot accepts; absent or `'*'` accepts any block. */ accepts?: readonly string[] | '*'; } export declare const BLOCKS_PROP_DEFAULTS: { readonly minItems: 1; readonly maxItems: 40; }; export declare const DEFAULT_URL_SCHEMES: readonly ["https", "http", "mailto"]; export declare const NODE_ID_PATTERN: RegExp; export type PropValues = Record; export interface PropValidationResult { /** Validated values with defaults applied, in schema key order. */ values: PropValues; /** Node-safe author IDs discovered in this subtree, mapped to their paths. */ authorIds: { id: string; path: string; }[]; } /** * Validate one property value against its schema, appending diagnostics and * returning the normalized value (or `undefined` when absent/optional). */ export declare function validateProp(schema: PropSchema, value: unknown, path: string, bag: DiagnosticBag): JsonValue | undefined; /** * Validate a props object against a block's property schema. Unknown keys are * errors: a silently ignored prop is a silent authoring mistake. */ export declare function validateProps(fields: Record, value: unknown, path: string, bag: DiagnosticBag): PropValues; /** Project a prop schema into JSON Schema for the published spec contract. */ export declare function propSchemaToJsonSchema(schema: PropSchema): Record; export {}; //# sourceMappingURL=prop-schema.d.ts.map