Rx: Simple, Extensible Schemata
Terminology
There are really only two things you need to know about in Rx: types and schemata. A type is an abstract descripition of a type of data. For example, "an integer" or "an associative array" are data types. When they're made into concrete, checkable constraints, they become schemata. This is done by parameterizing them.
A Rx type is identified by a unique URL, generally in the tag: schema. When writing these in schema definitions, there is a form of shorthand available. If the string begins with a slash, it is assumed to be in the format: /id/rest, where id is in a list of known identifiers that expand to base URLs.
For example, given this prefix table:
rubric | tag:codesimply.com,2008:rubric/ |
x | http://example.com/x-ample/ |
...then type names may be supplied as /rubric/tag or /x/int instead of tag:codesimply.com,2008:rubric/tag or http://example.com/x-ample/tag respectively.
The empty prefix is always reserved for the core type tag prefix:
(empty) | tag:codesimply.com,2008:rx/core/ |
Types located under tag:codesimply.com,2008:rx/core/ are the core types and must be implemented by all Rx implementations. These are detailed below. While users can define their own custom types, quite a lot of data validation rules can be expressed using the core types.
Prefixes starting with a period are reserved for use by Rx. The following are defined:
.rx | tag:codesimply.com,2008:rx/ |
.meta | tag:codesimply.com,2008:rx/meta/ |
This page gives a brief overview of the core types, which will be defined in detail elsewhere, later.
Single Types
The basic scalar (one-value) types are:
//nil | the lack of a value (undef, null, nil, etc) |
---|---|
//def | any defined value; anything that is not //nil |
//bool | a value that is either true or false |
//num | a number; may be parameterized by a range |
//int | a integer; any number such that (x == floor(x)); may be parameterized by range |
//str | a string, even the empty string |
//one | any single value -- anything //def that is not a collection |
Collection Types
The basic collecting (many-value) types are:
//arr | a list of values all of one type; may be parameterized by length |
---|---|
//seq | a list of values all of varying types; each slot has a schema |
//rec | a record of named entries, each with its own schema |
//map | a map of names to values, with all the values matching one schema |
Combination Types
The basic combination types are:
//any | either anything at all, or any of a given list of schematas |
---|---|
//all | a list of schemata; checked data must validate against them all |