SchemaModule

Schema

The Schema module contains primitive schemas, collection and recursion combinators, union constructors, and the operations that parse or check a completed declaration.

Use Schema.parse for untrusted Data. It decodes fields, applies constraints and refinements, accumulates independent failures as SchemaErrors, and invokes the model constructor only after the fields succeed.

Use Schema.check when a typed value came from another constructor, an import, or a database mapper. It reads the declared fields back from the value and checks them.

The same model constructor runs again, so cross-field invariants are checked too. Success returns the checked value itself.

The Schema quickstart introduces the workflow. The member catalogue below is the complete construction and execution vocabulary.

Summary

NameSignatureSynopsis
textSchema.text Describes text input.
intSchema.int Describes a 32-bit integer.
int64Schema.int64 Describes a 64-bit integer.
decimalSchema.decimal Describes a decimal number.
floatSchema.float Describes a double-precision number.
boolSchema.bool Describes a Boolean value.
dateSchema.date Describes a calendar date.
dateTimeSchema.dateTime Describes a date and time with an offset.
guidSchema.guid Describes a GUID.
listWithSchema.listWith itemDescribes a list using an explicit item schema.
listSchema.list ()Describes a list by resolving its item schema from 'item.
optionSchema.option itemDescribes an optional value.
mapWithSchema.mapWith itemDescribes a string-keyed map using an explicit value schema.
mapSchema.map ()Describes a string-keyed map by resolving its value schema from 'item.
deferSchema.defer schemaDefers a recursive schema reference until an interpreter needs it.
tryConvertSchema.tryConvert forward backward schemaMaps a schema through a fallible projected conversion.
convertSchema.convert forward backward schemaMaps a schema through a total, reversible domain conversion.
refineSchema.refine refinement schemaMaps a raw schema through a reusable bidirectional refinement.
validateSchema.validate validation schemaAdds executable value validation to a schema.
unionSchema.union casesDescribes the recommended internally tagged union using the type discriminator and named fields.
unionWithSchema.unionWith representation casesDescribes a union using an explicit complete wire representation.
enumSchema.enum casesDescribes a scalar enum.
constrainSchema.constrain constraint' schemaRequires a schema's values to satisfy a constraint.
constrainAllSchema.constrainAll constraints schemaRequires a schema's values to satisfy every constraint, in declaration order.
mustSupplySchema.mustSupply schemaRequires boundary input for this schema to be supplied.
mayOmitSchema.mayOmit schemaAllows boundary input for an option-typed schema to be omitted.
withFormatSchema.withFormat format schemaAdds format metadata.
describeSchema.describe text schemaAdds human-readable description metadata.
withDefaultSchema.withDefault value schemaAdds default-value metadata.
formatSchema.format schemaNo description available.
descriptionSchema.description schemaNo description available.
defaultValueSchema.defaultValue schemaNo description available.
constraintsSchema.constraints schemaNo description available.
supplySchema.supply schemaReturns the boundary supply declaration attached to a schema, when one was made.
isRefinedSchema.isRefined schemaNo description available.
primitiveKindSchema.primitiveKind schemaNo description available.
underlyingPrimitiveKindSchema.underlyingPrimitiveKind schemaNo description available.
rawConstraintsSchema.rawConstraints schemaNo description available.
inspectUnderlyingSchema.inspectUnderlying schemaNo description available.
allConstraintsSchema.allConstraints schemaNo description available.
compilePlanSchema.compilePlan factory schemaCompiles a record schema with a typed interpreter factory.
defaultsSchema.defaults The default raw-input parsing options.
constructorErrorAtSchema.constructorErrorAt path optionsPlaces a record-constructor failure at a field path.
parseWithSchema.parseWith configure schema inputParses structured data after configuring parser options.
parseSchema.parse schema inputParses source-neutral structured data, runs constraints and refinements, and invokes record constructors.
parseRetainingInputSchema.parseRetainingInput schema inputParses source-neutral structured data while retaining it for redisplay and error lookup.
parseWithOptionsSchema.parseWithOptions options schema inputParses structured data with a C#-friendly options delegate.
checkSchema.check schema valueChecks an existing typed value, such as a freely constructed draft, through the schema's constraints, refinements, and record constructor.
admitSchema.admit create project draftAdmits a permissive draft model schema into a trusted domain schema through an admission function and a projection, preserving fields, wire names, constraints, and metadata.

text

Schema.text
Member
Describes text input.

Returns

Schema<string>

int

Schema.int
Member
Describes a 32-bit integer.

Returns

Schema<int>

int64

Schema.int64
Member
Describes a 64-bit integer.

Returns

Schema<int64>

decimal

Schema.decimal
Member
Describes a decimal number.

Returns

Schema<decimal>

float

Schema.float
Member
Describes a double-precision number.

Returns

Schema<float>

bool

Schema.bool
Member
Describes a Boolean value.

Returns

Schema<bool>

date

Schema.date
Member
Describes a calendar date.

Returns

Schema<DateOnly>

dateTime

Schema.dateTime
Member
Describes a date and time with an offset.

Returns

Schema<DateTimeOffset>

guid

Schema.guid
Member
Describes a GUID.

Returns

Schema<Guid>

listWith

Schema.listWith item
Member
Describes a list using an explicit item schema.

Parameters

NameTypeDescription
itemSchema<'a>

Returns

Schema<'a list>

list

Schema.list ()
Member
Describes a list by resolving its item schema from 'item.

Parameters

NameTypeDescription
unit

Returns

Schema<^item list>

option

Schema.option item
Member
Describes an optional value.

Parameters

NameTypeDescription
itemSchema<'a>

Returns

Schema<'a option>

mapWith

Schema.mapWith item
Member
Describes a string-keyed map using an explicit value schema.

Parameters

NameTypeDescription
itemSchema<'a>

Returns

Schema<Map<string, 'a>>

map

Schema.map ()
Member
Describes a string-keyed map by resolving its value schema from 'item.

Parameters

NameTypeDescription
unit

Returns

Schema<Map<string, ^item>>

defer

Schema.defer schema
Member
Defers a recursive schema reference until an interpreter needs it.

Parameters

NameTypeDescription
schemaunit -> Schema<'a>

Returns

Schema<'a>

tryConvert

Schema.tryConvert forward backward schema
Member
Maps a schema through a fallible projected conversion.

Parameters

NameTypeDescription
forward'a -> Result<'b, SchemaError list>
backward'b -> 'a
schemaSchema<'a>

Returns

Schema<'b>

convert

Schema.convert forward backward schema
Member
Maps a schema through a total, reversible domain conversion.

Parameters

NameTypeDescription
forward'a -> 'b
backward'b -> 'a
schemaSchema<'a>

Returns

Schema<'b>

refine

Schema.refine refinement schema
Member
Maps a raw schema through a reusable bidirectional refinement.

Parameters

NameTypeDescription
refinementRefinement<'raw, 'value>
schemaSchema<'raw>

Returns

Schema<'value>

validate

Schema.validate validation schema
Member
Adds executable value validation to a schema.

Parameters

NameTypeDescription
validation'value -> Result<unit, SchemaError>
schemaSchema<'value>

Returns

Schema<'value>

union

Schema.union cases
Member
Describes the recommended internally tagged union using the type discriminator and named fields.

Parameters

NameTypeDescription
casesUnionCase<'a> list

Returns

Schema<'a>

unionWith

Schema.unionWith representation cases
Member
Describes a union using an explicit complete wire representation.

Parameters

NameTypeDescription
representationUnionRepresentation
casesUnionCase<'a> list

Returns

Schema<'a>

enum

Schema.enum cases
Member
Describes a scalar enum.

Parameters

NameTypeDescription
casesEnumCase<'a> list

Returns

Schema<'a>

constrain

Schema.constrain constraint' schema
Member
Requires a schema's values to satisfy a constraint.

Parameters

NameTypeDescription
constraint'Constraint<'a>
schemaSchema<'a>

Returns

Schema<'a>

Verification Examples

Schema.text |> Schema.constrain (Constraint.lengthBetween 2 40)

constrainAll

Schema.constrainAll constraints schema
Member
Requires a schema's values to satisfy every constraint, in declaration order.

Parameters

NameTypeDescription
constraintsConstraint<'a> list
schemaSchema<'a>

Returns

Schema<'a>

Verification Examples

Schema.text |> Schema.constrainAll [ Constraint.present; Constraint.trimmed ]

mustSupply

Schema.mustSupply schema
Member
Requires boundary input for this schema to be supplied.

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

Schema<'a>

Verification Examples

Schema.text |> Schema.mustSupply

mayOmit

Schema.mayOmit schema
Member
Allows boundary input for an option-typed schema to be omitted.

Parameters

NameTypeDescription
schemaSchema<'a option>

Returns

Schema<'a option>

Verification Examples

Schema.option Schema.text |> Schema.mayOmit

withFormat

Schema.withFormat format schema
Member
Adds format metadata.

Parameters

NameTypeDescription
formatSchemaFormat
schemaSchema<'a>

Returns

Schema<'a>

describe

Schema.describe text schema
Member
Adds human-readable description metadata.

Parameters

NameTypeDescription
textstring
schemaSchema<'a>

Returns

Schema<'a>

withDefault

Schema.withDefault value schema
Member
Adds default-value metadata.

Parameters

NameTypeDescription
value'a
schemaSchema<'a>

Returns

Schema<'a>

format

Schema.format schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

SchemaFormat option

description

Schema.description schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

string option

defaultValue

Schema.defaultValue schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

'a option

constraints

Schema.constraints schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

ConstraintDescription list

supply

Schema.supply schema
Member
Returns the boundary supply declaration attached to a schema, when one was made.

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

Supply option

isRefined

Schema.isRefined schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

bool

primitiveKind

Schema.primitiveKind schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

PrimitiveValueKind

underlyingPrimitiveKind

Schema.underlyingPrimitiveKind schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

PrimitiveValueKind

rawConstraints

Schema.rawConstraints schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

ConstraintDescription list

inspectUnderlying

Schema.inspectUnderlying schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

'a -> 'b

allConstraints

Schema.allConstraints schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

ConstraintDescription list

compilePlan

Schema.compilePlan factory schema
Member
Compiles a record schema with a typed interpreter factory.

Parameters

NameTypeDescription
factoryIRecordPlanCompiler<'a, 'b>
schemaSchema<'a>

Returns

'b

defaults

Schema.defaults
Member
The default raw-input parsing options.

Returns

SchemaParseOptions

constructorErrorAt

Schema.constructorErrorAt path options
Member
Places a record-constructor failure at a field path.

Parameters

NameTypeDescription
pathstring
optionsSchemaParseOptions

Returns

SchemaParseOptions

parseWith

Schema.parseWith configure schema input
Member
Parses structured data after configuring parser options.

Parameters

NameTypeDescription
configureSchemaParseOptions -> SchemaParseOptions
schemaSchema<'a>
inputData

Returns

Result<'a, SchemaErrors>

parse

Schema.parse schema input
Member
Parses source-neutral structured data, runs constraints and refinements, and invokes record constructors.

Parameters

NameTypeDescription
schemaSchema<'a>
inputData

Returns

Result<'a, SchemaErrors>

parseRetainingInput

Schema.parseRetainingInput schema input
Member
Parses source-neutral structured data while retaining it for redisplay and error lookup.

Parameters

NameTypeDescription
schemaSchema<'a>
inputData

Returns

RetainedParseResult<'a>

parseWithOptions

Schema.parseWithOptions options schema input
Member
Parses structured data with a C#-friendly options delegate.

Parameters

NameTypeDescription
optionsFunc<SchemaParseOptions, SchemaParseOptions>
schemaSchema<'a>
inputData

Returns

Result<'a, SchemaErrors>

check

Schema.check schema value
Member
Checks an existing typed value, such as a freely constructed draft, through the schema's constraints, refinements, and record constructor.

Parameters

NameTypeDescription
schemaSchema<'a>
value'a

Returns

Result<'a, SchemaErrors>

admit

Schema.admit create project draft
Member
Admits a permissive draft model schema into a trusted domain schema through an admission function and a projection, preserving fields, wire names, constraints, and metadata.

Parameters

NameTypeDescription
create'draft -> Result<'domain, SchemaError list>
project'domain -> 'draft
draftSchema<'draft>

Returns

Schema<'domain>