Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/schemable.ts

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
import * as fun from "https://deno.land/x/fun@v.2.0.0-alpha.11/schemable.ts";

Functions

A helper function to build a generic Schema that can be used with any Schemable.

Type Aliases

Takes a Schemable and returns a Schemable<ReadonlyArray>

Wraps a boolean type in Schemable.

Takes two schemables, left and right, and returns the intersection of them. This means that any value for must match both schemables.

Takes an id and a thunk returning a schemable and returns a schemable that matches the return value of the thunk. This schemable is necessary for handling recursive or corecursive schemables.

These are the super-types that a Literal schema must extent. They are used to constrain the inputs for LiteralSchemable.

Wraps a union of literals in Schemable.

Takes a Schemable and returns a Schemable<A | null>;

Wraps a number type in Schemable.

Takes a struct of Schemables and returns a Schemable for a struct that matches, key for key, the input schemables but the values can also be partial.

Takes a Schemable and returns a Schemable<ReadonlyRecord>

A Schema is the a function that takes a generic schemable and builds a specific model from it.

A Schemable is the union of all schemable methods. This allows one to build an arbitrary Schema using the Schemable interface, then pass a concrete Schemable implementation to the Schema. Thus, one can build a single model and produce decoders, guards, or jsonschema from that model.

Wraps a string type in Schemable.

Takes a struct of Schemables and returns a Schemable for a struct that matches, key for key, the input schemables.

Takes a tuple of Schemables and returns a Schemable for a tuple that matches, index for index, the input schemables.

Extracts the inner type of a Schema

Takes a Schemable and returns a Schemable<A | undefined>;

Takes two schemables, left and right, and returns the union of them. This means that any value for must match either schemable.

Wraps an unknown type in Schemable. This is the best escape hatch when a Schema isn't known ahead of time.