Skip to main content

Handlers

Handlers are pipelines of value processors that execute on a value as it passes through different phases of processing.

  1. Normalizers ensure that input to be processed are in a "canonical form".
  2. Transformers convert normalized values to the schema's output format.
  3. Finalizers are used if the schema requires post-processing of values.
  4. Validators define the actual contract for the schema.
  5. Serializers convert validated values to serializable values that can be normalized.
  6. Conditions can be used to activate or deactivate a schema.
  7. Discriminators are used to select an element schema in a union.

All handlers operate in essentially the same manner: an input arrives and is passed to the handler's processor pipeline. Each processor in the pipeline reads its input, operates on the value, and produces an output that is passed to the next processor. The output from the final processor is the output from the handler.

If a handler returns null, the schema is explicitly returning nothing. The value null is not included in any output; if the schema was a child property, the key simply won't exist. If the schema returning null was the root schema, processing will return undefined.

If a handler returns undefined, it means "currently unable to produce a value", and will be retried until the output "stabilizes".

If a handler throws an error, it indicates that it can never produce a value.