Custom Types

Rx validators should be implemented to allow the registration of more types by the end user. There are two ways to do this: naming a schema constructed from types or implementing a custom type in the implementation language. Schemata constructed from core types are by definition portable to all compliant Rx implementations, which makes it a convenient way to quickly write portable types. These types are not (yet) parameterizable, though, and are limited to the features provided by core types.

When natively implementing a new type, consider following the example of the Rx test suite in providing portable test data for other implementors to test against if at all possible. If portability isn't a goal, of course, you can write types that are closely tied to your language's native types without any worries.

Meta Schema

Rx core types can be used to validate core type schema definitions. In other words, it is possible to write a schema that validates the input used to build a schema for any core Rx type. These schemata live under tag:codesimply.com,2008:rx/meta/, though implementations are not required to implement them. Their definitions are given on the core type pages for each type.

In addition to the metaschemata for each core type, there are two "helper" schemata:

/.meta/range, the schema for range values:

{
  "type": "//rec",
  "optional": {
    "min"   : { "type": "//num" },
    "max"   : { "type": "//num" },
    "min-ex": { "type": "//num" },
    "max-ex": { "type": "//num" }
  }
}

/.meta/schema, the schema for schemata:

{
  "type": "//any",
  "of": [
    {
      "type"    : "//rec",
      "required": { "type": "//str" },
      "rest"    : "//any"
    },
    "//str",
  ]
}

When a schema is given as a string S it must be replaced with (the equivalent of) { "type": S } before further evaluation.