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
| Name | Signature | Synopsis |
|---|---|---|
| text | Schema.text | Describes text input. |
| int | Schema.int | Describes a 32-bit integer. |
| int64 | Schema.int64 | Describes a 64-bit integer. |
| decimal | Schema.decimal | Describes a decimal number. |
| float | Schema.float | Describes a double-precision number. |
| bool | Schema.bool | Describes a Boolean value. |
| date | Schema.date | Describes a calendar date. |
| dateTime | Schema.dateTime | Describes a date and time with an offset. |
| guid | Schema.guid | Describes a GUID. |
| listWith | Schema.listWith item | Describes a list using an explicit item schema. |
| list | Schema.list () | Describes a list by resolving its item schema from 'item. |
| option | Schema.option item | Describes an optional value. |
| mapWith | Schema.mapWith item | Describes a string-keyed map using an explicit value schema. |
| map | Schema.map () | Describes a string-keyed map by resolving its value schema from 'item. |
| defer | Schema.defer schema | Defers a recursive schema reference until an interpreter needs it. |
| tryConvert | Schema.tryConvert forward backward schema | Maps a schema through a fallible projected conversion. |
| convert | Schema.convert forward backward schema | Maps a schema through a total, reversible domain conversion. |
| refine | Schema.refine refinement schema | Maps a raw schema through a reusable bidirectional refinement. |
| validate | Schema.validate validation schema | Adds executable value validation to a schema. |
| union | Schema.union cases | Describes the recommended internally tagged union using the type discriminator and named fields. |
| unionWith | Schema.unionWith representation cases | Describes a union using an explicit complete wire representation. |
| enum | Schema.enum cases | Describes a scalar enum. |
| constrain | Schema.constrain constraint' schema | Requires a schema's values to satisfy a constraint. |
| constrainAll | Schema.constrainAll constraints schema | Requires a schema's values to satisfy every constraint, in declaration order. |
| mustSupply | Schema.mustSupply schema | Requires boundary input for this schema to be supplied. |
| mayOmit | Schema.mayOmit schema | Allows boundary input for an option-typed schema to be omitted. |
| withFormat | Schema.withFormat format schema | Adds format metadata. |
| describe | Schema.describe text schema | Adds human-readable description metadata. |
| withDefault | Schema.withDefault value schema | Adds default-value metadata. |
| format | Schema.format schema | No description available. |
| description | Schema.description schema | No description available. |
| defaultValue | Schema.defaultValue schema | No description available. |
| constraints | Schema.constraints schema | No description available. |
| supply | Schema.supply schema | Returns the boundary supply declaration attached to a schema, when one was made. |
| isRefined | Schema.isRefined schema | No description available. |
| primitiveKind | Schema.primitiveKind schema | No description available. |
| underlyingPrimitiveKind | Schema.underlyingPrimitiveKind schema | No description available. |
| rawConstraints | Schema.rawConstraints schema | No description available. |
| inspectUnderlying | Schema.inspectUnderlying schema | No description available. |
| allConstraints | Schema.allConstraints schema | No description available. |
| compilePlan | Schema.compilePlan factory schema | Compiles a record schema with a typed interpreter factory. |
| defaults | Schema.defaults | The default raw-input parsing options. |
| constructorErrorAt | Schema.constructorErrorAt path options | Places a record-constructor failure at a field path. |
| parseWith | Schema.parseWith configure schema input | Parses structured data after configuring parser options. |
| parse | Schema.parse schema input | Parses source-neutral structured data, runs constraints and refinements, and invokes record constructors. |
| parseRetainingInput | Schema.parseRetainingInput schema input | Parses source-neutral structured data while retaining it for redisplay and error lookup. |
| parseWithOptions | Schema.parseWithOptions options schema input | Parses structured data with a C#-friendly options delegate. |
| check | Schema.check schema value | Checks an existing typed value, such as a freely constructed draft, through the schema's constraints, refinements, and record constructor. |
| admit | Schema.admit create project draft | 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. |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| item | Schema<'a> |
Returns
'item.Parameters
| Name | Type | Description |
|---|---|---|
| unit |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| item | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| item | Schema<'a> |
Returns
'item.Parameters
| Name | Type | Description |
|---|---|---|
| unit |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | unit -> Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| forward | 'a -> Result<'b, SchemaError list> | |
| backward | 'b -> 'a | |
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| forward | 'a -> 'b | |
| backward | 'b -> 'a | |
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| refinement | Refinement<'raw, 'value> | |
| schema | Schema<'raw> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| validation | 'value -> Result<unit, SchemaError> | |
| schema | Schema<'value> |
Returns
type discriminator and named fields.Parameters
| Name | Type | Description |
|---|---|---|
| cases | UnionCase<'a> list |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| representation | UnionRepresentation | |
| cases | UnionCase<'a> list |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| cases | EnumCase<'a> list |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| constraint' | Constraint<'a> | |
| schema | Schema<'a> |
Returns
Verification Examples
Schema.text |> Schema.constrain (Constraint.lengthBetween 2 40)Parameters
| Name | Type | Description |
|---|---|---|
| constraints | Constraint<'a> list | |
| schema | Schema<'a> |
Returns
Verification Examples
Schema.text |> Schema.constrainAll [ Constraint.present; Constraint.trimmed ]Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Verification Examples
Schema.text |> Schema.mustSupplyParameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a option> |
Returns
Verification Examples
Schema.option Schema.text |> Schema.mayOmitParameters
| Name | Type | Description |
|---|---|---|
| format | SchemaFormat | |
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | |
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'a | |
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| factory | IRecordPlanCompiler<'a, 'b> | |
| schema | Schema<'a> |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | |
| options | SchemaParseOptions |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| configure | SchemaParseOptions -> SchemaParseOptions | |
| schema | Schema<'a> | |
| input | Data |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> | |
| input | Data |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> | |
| input | Data |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| options | Func<SchemaParseOptions, SchemaParseOptions> | |
| schema | Schema<'a> | |
| input | Data |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'a> | |
| value | 'a |
Returns
Parameters
| Name | Type | Description |
|---|---|---|
| create | 'draft -> Result<'domain, SchemaError list> | |
| project | 'domain -> 'draft | |
| draft | Schema<'draft> |