Try it online

Each example introduces one idea, and everything re-runs as you type. This is finitio.js in your browser — nothing is sent to a server.

A lone dot is the Any type: the set of every value the host language can represent.

schema.fioFinitio
.
data.jsonJSON
"Hello World"
Loading finitio.js…

The three things Finitio does

Every example above reports each one separately, because they answer different questions.

  • Validating asks whether a value already belongs to the type, as a plain question of set membership. Nothing is converted.
  • Dressing converts an exchange-level document into host-language values: a string becomes a Date, a triple of integers becomes a Color. A value can fail validation and still dress successfully — that is the point of a contract.
  • Undressing is the inverse, turning host values back into something you can serialise. A schema opts in by naming an Output type.

A few pointers

  • Since Finitio 0.4 the builtin types live in the standard library, so schemas start with @import finitio/data.
  • The last anonymous type in a schema is the main type: it is what the document is checked against.
  • Constraints are expressions of the host language — JavaScript here — and can be named, as in String( s | nonEmpty: s.length > 0 ), so failures say which rule broke.
  • Types can take type parameters, as in Resource<T> = { data: T, links: [String] }, and are instantiated with Resource<Person>.
  • The full grammar is in the type system reference.