SchemaBuilder
What createSchemaBuilder returns. Its methods are plain functions, so they can be destructured: const { build, validate } = createSchemaBuilder().
Generics
TFieldTypesextends Record<string, FieldTypeDef>TRulesextends Record<string, RuleDef>TFormRulesextends Record<string, FormRuleDef>TExtensionPropsextends ExtensionProps
Definition
SchemaBuilderbuild(json: JsonForm) => BuiltSchemavalidate(json: unknown) => ValidateResultdefineForm(definition: TypedForm) => TypedFormgetInitialInput(json: JsonForm) => Record<string, unknown>getItemInput(field: JsonField) => unknowngetFieldTree(json: JsonForm) => FieldNode[]getLayout(json: JsonForm) => FormLayoutgetVisibility(json: JsonForm) => VisibilitywalkFields(json: JsonForm) => Generator<WalkedField>rulesForKind(kind: ValueKind) => [name: string, def: RuleDef][]kindsReadonly<Record<string, KindDef>>fieldTypesReadonly<TFieldTypes>rulesReadonly<TRules>formRulesReadonly<TFormRules>extensionsreadonly SchemaExtension[]
Methods
build
const schema = builder.build(json)
const schema = builder.build<TInput, TOutput>(json)Checks the definition and builds the Valibot schema of the whole form: an object schema with a key for each field, in a v.pipe() with one check that runs every form rule when it has any. Throws one DefinitionError with every issue. With your input type, and your output type when it differs, the schema is typed as a TypedBuiltSchema. See TypeScript.
validate
const result = builder.validate(json)Every issue in a definition, in document order, as a ValidateResult. It never throws, whatever json is. See checking definitions.
defineForm
const definition = builder.defineForm(definition)Types a definition written in TypeScript against the builder's registries and extensions, and returns it unchanged. See TypeScript and TypedForm.
getInitialInput
const input = builder.getInitialInput(json)Formisch's initialInput: each field's default, nested the way the value is, the builder's own container types included. A container of kind object gives an object, and one of kind array without a default gives []. It never throws, and leaves out a field with issues. A field that conditions clear when the form starts starts blank.
getItemInput
const input = builder.getItemInput(field)The input of a new item of a list, for Formisch's insert(): an object of the defaults of its fields, or the default of its of field. Undefined for a field that isn't a container of kind array. It never throws.
getFieldTree
const fields = builder.getFieldTree(json)The definition's fields as a tree of FieldNodes, each with its role, for a renderer. Throws a DefinitionError like build().
getLayout
const layout = builder.getLayout(json)The definition's layout as a FormLayout, with every reference resolved: its steps, each a tree of sections, rows, slots and fields. Without a layout, one step with every field in order. Throws a DefinitionError like build().
getVisibility
const visibility = builder.getVisibility(json)What the conditions of the builder's extensions hide, for any input, as a Visibility. Without extensions or conditions, nothing is hidden. Throws a DefinitionError like build(). See conditions.
walkFields
for (const field of builder.walkFields(json)) {
// ...
}Every field of the definition, at every depth, in document order, as WalkedFields with their kinds, the builder's own container types included. A group or a list comes before its fields, and the fields of a list's items come once. It never throws, and a container with issues isn't walked into.
rulesForKind
const rules = builder.rulesForKind(kind)The registered rules that fit a field of kind, as [name, def] pairs, like for a rule picker. See listing rules.
Registries
kinds, fieldTypes, rules, formRules and extensions are the builder's registries: the built-in entries merged with yours.