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
Operations
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.
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.
mapWithKeySchema.mapWithKey parseKey renderKey itemDescribes a map whose key type converts to and from object property names.
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.

Operations

kind:member

text

Schema.text
Member
Describes text input.

Returns

Schema<string>
kind:member

int

Schema.int
Member
Describes a 32-bit integer.

Returns

Schema<int>
kind:member

int64

Schema.int64
Member
Describes a 64-bit integer.

Returns

Schema<int64>
kind:member

decimal

Schema.decimal
Member
Describes a decimal number.

Returns

Schema<decimal>
kind:member

float

Schema.float
Member
Describes a double-precision number.

Returns

Schema<float>
kind:member

bool

Schema.bool
Member
Describes a Boolean value.

Returns

Schema<bool>
kind:member

dateTime

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

Returns

Schema<DateTimeOffset>
kind:member

guid

Schema.guid
Member
Describes a GUID.

Returns

Schema<Guid>
kind:member

listWith

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

Parameters

NameTypeDescription
itemSchema<'a>

Returns

Schema<'a list>
kind:member

list

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

Parameters

NameTypeDescription
unit

Returns

Schema<^item list>
kind:membershape:option

option

Schema.option item
Member
Describes an optional value.

Parameters

NameTypeDescription
itemSchema<'a>

Returns

Schema<'a option>
kind:member

mapWith

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

Parameters

NameTypeDescription
itemSchema<'a>

Returns

Schema<Map<string, 'a>>
kind:member

mapWithKey

Schema.mapWithKey parseKey renderKey item
Member
Describes a map whose key type converts to and from object property names.

Parameters

NameTypeDescription
parseKeystring -> 'aConverts an input property name to a model key.
renderKey'a -> stringConverts a model key to an output property name.
itemSchema<'b>The schema for each map value.

Returns

Schema<Map<'a, 'b>>

Verification Examples

type LocaleTag = LocaleTag of string
let schema = Schema.mapWithKey LocaleTag (fun (LocaleTag value) -> value) Schema.text
kind:member

map

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

Parameters

NameTypeDescription
unit

Returns

Schema<Map<string, ^item>>
kind:member

defer

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

Parameters

NameTypeDescription
schemaunit -> Schema<'a>

Returns

Schema<'a>
kind:member

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>
kind:member

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>
kind:member

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>
kind:member

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>
kind:member

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>
kind:member

unionWith

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

Parameters

NameTypeDescription
representationUnionRepresentation
casesUnionCase<'a> list

Returns

Schema<'a>
kind:member

enum

Schema.enum cases
Member
Describes a scalar enum.

Parameters

NameTypeDescription
casesEnumCase<'a> list

Returns

Schema<'a>
kind:member

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)
kind:member

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 ]
kind:member

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
kind:member

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
kind:member

withFormat

Schema.withFormat format schema
Member
Adds format metadata.

Parameters

NameTypeDescription
formatSchemaFormat
schemaSchema<'a>

Returns

Schema<'a>
kind:member

describe

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

Parameters

NameTypeDescription
textstring
schemaSchema<'a>

Returns

Schema<'a>
kind:member

withDefault

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

Parameters

NameTypeDescription
value'a
schemaSchema<'a>

Returns

Schema<'a>
kind:member

format

Schema.format schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

SchemaFormat option
kind:member

description

Schema.description schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

string option
kind:member

defaultValue

Schema.defaultValue schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

'a option
kind:member

constraints

Schema.constraints schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

ConstraintDescription list
kind:member

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
kind:member

isRefined

Schema.isRefined schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

bool
kind:member

primitiveKind

Schema.primitiveKind schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

PrimitiveValueKind
kind:member

underlyingPrimitiveKind

Schema.underlyingPrimitiveKind schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

PrimitiveValueKind
kind:member

rawConstraints

Schema.rawConstraints schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

ConstraintDescription list
kind:member

inspectUnderlying

Schema.inspectUnderlying schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

'a -> 'b
kind:member

allConstraints

Schema.allConstraints schema
Member

Parameters

NameTypeDescription
schemaSchema<'a>

Returns

ConstraintDescription list
kind:member

compilePlan

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

Parameters

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

Returns

'b
kind:member

defaults

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

Returns

SchemaParseOptions
kind:member

constructorErrorAt

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

Parameters

NameTypeDescription
pathstring
optionsSchemaParseOptions

Returns

SchemaParseOptions
kind:member

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>
kind:member

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>
kind:member

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>
kind:member

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>
kind:member

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>
kind:member

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>