//#region src/core/types.d.ts /** * Core types for schema-components. * * These types define the vocabulary shared between the schema walker, * component resolver, and React components. */ /** A raw JSON object (JSON Schema or OpenAPI document). */ type JsonObject = Record; /** * Metadata attached to schemas via `.meta()` or passed as props to * ``. Every field is also available as a top-level * prop on `` (with TypeScript-enforced exclusivity * between prop and `meta`). */ interface SchemaMeta { readOnly?: boolean; writeOnly?: boolean; description?: string; title?: string; deprecated?: boolean; /** Component hint — resolved before theme adapter. */ component?: string; /** Sort order for object fields. Lower values render first. */ order?: number; /** Arbitrary UI hints passed through to theme adapters. */ [key: string]: unknown; } /** * Resolved editability state for a walked field. `presentation` renders * as a read-only value, `input` as a write-only input (e.g. password * fields), `editable` as a full input that round-trips through * `onChange`. Produced by {@link resolveEditability}. */ type Editability = "presentation" | "input" | "editable"; /** * Resolved editability state for a single field. * * Priority (highest wins): * 1. Property-level readOnly → presentation * 2. Property-level writeOnly → input * 3. Component-level readOnly → presentation * 4. Component-level writeOnly → input * 5. Schema root readOnly → presentation * 6. Schema root writeOnly → input * 7. Neither → editable */ declare function resolveEditability(propertyMeta: SchemaMeta | undefined, componentMeta: SchemaMeta | undefined, rootMeta: SchemaMeta | undefined): Editability; /** * Recursive mapped type that mirrors a schema's shape for per-field * overrides. Each leaf accepts schema meta overrides and an optional * per-field validation error callback. Objects recurse and also accept * their own overrides. */ type FieldOverrides = { [K in keyof T]?: T[K] extends object ? FieldOverrides & FieldOverride : FieldOverride }; /** * Per-field override. Extends SchemaMeta with rendering controls * and a per-field validation error callback. */ type FieldOverride = Partial & { /** Called with the ZodError when this field fails validation. */onValidationError?: (error: unknown) => void; /** Hide this field when false. Defaults to true (visible). */ visible?: boolean; }; /** * All schema types the walker can produce. * Used as the discriminant in the WalkedField tagged union. */ type SchemaType = "string" | "number" | "boolean" | "null" | "enum" | "literal" | "object" | "array" | "tuple" | "record" | "union" | "discriminatedUnion" | "conditional" | "negation" | "file" | "never" | "unknown"; /** Constraints that apply to string schemas. */ interface StringConstraints { minLength?: number; maxLength?: number; pattern?: string; format?: string; /** Derived RegExp from the format string, if the format is recognised. */ formatPattern?: RegExp; contentEncoding?: string; contentMediaType?: string; } /** Constraints that apply to number/integer schemas. */ interface NumberConstraints { minimum?: number; maximum?: number; exclusiveMinimum?: number; exclusiveMaximum?: number; multipleOf?: number; } /** Constraints that apply to array schemas. */ interface ArrayConstraints { minItems?: number; maxItems?: number; uniqueItems?: boolean; minContains?: number; maxContains?: number; } /** Constraints that apply to object schemas. */ interface ObjectConstraints { minProperties?: number; maxProperties?: number; } /** Constraints that apply to file schemas. */ interface FileConstraints { mimeTypes?: string[]; } /** * Union of all constraint types. Renderers can narrow by checking * the WalkedField's `type` discriminant. */ type FieldConstraints = StringConstraints | NumberConstraints | ArrayConstraints | ObjectConstraints | FileConstraints | Record; /** * Properties common to every WalkedField variant. * The `type` field acts as the discriminant for the tagged union. */ interface FieldBase { editability: Editability; meta: SchemaMeta; /** Whether the field is optional (not in `required`). */ isOptional?: boolean; /** Whether the field is nullable (`anyOf [T, null]` or `type: ["...", "null"]`). */ isNullable?: boolean; /** Default value from the schema's `default` keyword. */ defaultValue?: unknown; /** Example values from the schema's `examples` keyword. */ examples?: unknown[]; } interface StringField extends FieldBase { type: "string"; constraints: StringConstraints; } interface NumberField extends FieldBase { type: "number"; constraints: NumberConstraints; /** * True when the underlying schema declared `type: "integer"` rather * than `type: "number"`. Renderers consult this to set HTML * `inputmode="numeric"` and `step="1"` (for whole-number editing) * instead of `inputmode="decimal"`. */ isInteger: boolean; } interface BooleanField extends FieldBase { type: "boolean"; constraints: Record; } interface NullField extends FieldBase { type: "null"; constraints: Record; } interface EnumField extends FieldBase { type: "enum"; constraints: Record; /** * Enum values from JSON Schema `enum`. Per Draft 2020-12 §6.1.2, * `enum` accepts an array of arbitrary JSON values — not only * primitives. Object and array values are preserved verbatim. */ enumValues: unknown[]; } interface LiteralField extends FieldBase { type: "literal"; constraints: Record; /** * Const values from JSON Schema `const`. Per Draft 2020-12 §6.1.3, * `const` accepts any JSON value (object or array included), not * only primitives. The walker emits a single-element array because * `const` is scalar by definition; the field shape mirrors * `EnumField` for renderer symmetry. */ literalValues: unknown[]; } interface ObjectField extends FieldBase { type: "object"; constraints: ObjectConstraints; /** Map of property name → walked sub-schema. */ fields: Record; /** Property names declared in `required`. */ requiredFields: string[]; /** Regex-keyed sub-schemas from `patternProperties`. */ patternProperties?: Record; /** Whether `additionalProperties` is explicitly `false` (closed). */ additionalPropertiesClosed?: boolean; /** Schema for additional properties when not `false` and not a Record. */ additionalPropertiesSchema?: WalkedField; /** Property-presence-activated sub-schemas from `dependentSchemas`. */ dependentSchemas?: Record; /** Property-presence-conditional required fields from `dependentRequired`. */ dependentRequired?: Record; /** Constraint schema for unevaluated properties. */ unevaluatedProperties?: WalkedField; /** Whether unevaluatedProperties is explicitly `false`. */ unevaluatedPropertiesClosed?: boolean; /** Schema constraining property names (from `propertyNames`). */ propertyNames?: WalkedField; } interface ArrayField extends FieldBase { type: "array"; constraints: ArrayConstraints; /** The element sub-schema. */ element?: WalkedField; /** * Walked schema that at least one array item must match * (`contains` keyword). Constrains element membership at runtime; * paired with `minContains`/`maxContains` for cardinality. */ contains?: WalkedField; /** Walked schema for unevaluated items. */ unevaluatedItems?: WalkedField; /** * Whether `unevaluatedItems` is explicitly `false` (no extras * permitted beyond the items evaluated by `items`/`prefixItems`/ * `contains`). Parallel to `additionalPropertiesClosed` and * `unevaluatedPropertiesClosed` on `ObjectField`. */ unevaluatedItemsClosed?: boolean; } interface TupleField extends FieldBase { type: "tuple"; constraints: ArrayConstraints; /** Positional element schemas from `prefixItems`. */ prefixItems: WalkedField[]; /** * Schema for items beyond the `prefixItems` length. In Draft 2020-12, * `items` adjacent to `prefixItems` describes the rest element. When * absent, additional items are permitted but unconstrained. */ restItems?: WalkedField; /** * Walked schema that at least one array item must match * (`contains` keyword). Tuples may declare it alongside positional * element schemas to require the presence of a specific element. */ contains?: WalkedField; /** * Walked schema for `unevaluatedItems` adjacent to `prefixItems`. * Permits additional items only when they satisfy this schema. */ unevaluatedItems?: WalkedField; /** * Whether `unevaluatedItems` is explicitly `false` on a tuple. With * `prefixItems` declared, this forbids any items beyond the prefix * length. */ unevaluatedItemsClosed?: boolean; } interface RecordField extends FieldBase { type: "record"; constraints: ObjectConstraints; /** Key name validation schema (from `propertyNames`). */ keyType: WalkedField; /** Value schema (from `additionalProperties`). */ valueType: WalkedField; } interface UnionField extends FieldBase { type: "union"; constraints: Record; /** The union options. */ options: WalkedField[]; } interface DiscriminatedUnionField extends FieldBase { type: "discriminatedUnion"; constraints: Record; /** The union options. */ options: WalkedField[]; /** Property name that discriminates between options. */ discriminator: string; } interface ConditionalField extends FieldBase { type: "conditional"; constraints: Record; /** The `if` sub-schema. */ ifClause: WalkedField; /** The `then` sub-schema. */ thenClause?: WalkedField; /** The `else` sub-schema. */ elseClause?: WalkedField; } interface NegationField extends FieldBase { type: "negation"; constraints: Record; /** The negated sub-schema. */ negated: WalkedField; } interface FileField extends FieldBase { type: "file"; constraints: FileConstraints; } /** Schema position where `false` appears — the field cannot have any value. */ interface NeverField extends FieldBase { type: "never"; constraints: Record; } interface UnknownField extends FieldBase { type: "unknown"; constraints: Record; } /** * Tagged union of all schema field types produced by the walker. * Use `field.type` to narrow to a specific variant. */ type WalkedField = StringField | NumberField | BooleanField | NullField | EnumField | LiteralField | ObjectField | ArrayField | TupleField | RecordField | UnionField | DiscriminatedUnionField | ConditionalField | NegationField | NeverField | FileField | UnknownField; /** Type guard: narrows a `WalkedField` to its `string` variant. */ declare function isStringField(field: WalkedField): field is StringField; /** Type guard: narrows a `WalkedField` to its `number` variant. */ declare function isNumberField(field: WalkedField): field is NumberField; /** Type guard: narrows a `WalkedField` to its `boolean` variant. */ declare function isBooleanField(field: WalkedField): field is BooleanField; /** Type guard: narrows a `WalkedField` to its `null` variant. */ declare function isNullField(field: WalkedField): field is NullField; /** Type guard: narrows a `WalkedField` to its `enum` variant. */ declare function isEnumField(field: WalkedField): field is EnumField; /** Type guard: narrows a `WalkedField` to its `literal` variant. */ declare function isLiteralField(field: WalkedField): field is LiteralField; /** Type guard: narrows a `WalkedField` to its `object` variant. */ declare function isObjectField(field: WalkedField): field is ObjectField; /** Type guard: narrows a `WalkedField` to its `array` variant. */ declare function isArrayField(field: WalkedField): field is ArrayField; /** Type guard: narrows a `WalkedField` to its `tuple` variant. */ declare function isTupleField(field: WalkedField): field is TupleField; /** Type guard: narrows a `WalkedField` to its `record` variant. */ declare function isRecordField(field: WalkedField): field is RecordField; /** Type guard: narrows a `WalkedField` to its plain `union` variant. */ declare function isUnionField(field: WalkedField): field is UnionField; /** Type guard: narrows a `WalkedField` to its `discriminatedUnion` variant. */ declare function isDiscriminatedUnionField(field: WalkedField): field is DiscriminatedUnionField; /** Type guard: narrows a `WalkedField` to its `conditional` (if/then/else) variant. */ declare function isConditionalField(field: WalkedField): field is ConditionalField; /** Type guard: narrows a `WalkedField` to its `negation` (`not`) variant. */ declare function isNegationField(field: WalkedField): field is NegationField; /** Type guard: narrows a `WalkedField` to its `file` variant. */ declare function isFileField(field: WalkedField): field is FileField; /** Type guard: narrows a `WalkedField` to its `never` variant (false schema). */ declare function isNeverField(field: WalkedField): field is NeverField; /** Type guard: narrows a `WalkedField` to its `unknown` variant (permissive). */ declare function isUnknownField(field: WalkedField): field is UnknownField; //#endregion export { UnknownField as A, isNeverField as B, RecordField as C, StringField as D, StringConstraints as E, isDiscriminatedUnionField as F, isStringField as G, isNumberField as H, isEnumField as I, isUnknownField as J, isTupleField as K, isFileField as L, isArrayField as M, isBooleanField as N, TupleField as O, isConditionalField as P, isLiteralField as R, ObjectField as S, SchemaType as T, isObjectField as U, isNullField as V, isRecordField as W, resolveEditability as Y, NeverField as _, DiscriminatedUnionField as a, NumberField as b, FieldBase as c, FieldOverrides as d, FileConstraints as f, NegationField as g, LiteralField as h, ConditionalField as i, WalkedField as j, UnionField as k, FieldConstraints as l, JsonObject as m, ArrayField as n, Editability as o, FileField as p, isUnionField as q, BooleanField as r, EnumField as s, ArrayConstraints as t, FieldOverride as u, NullField as v, SchemaMeta as w, ObjectConstraints as x, NumberConstraints as y, isNegationField as z };