Schema Creation
The t Object
All built-in types are stored in a single t
object. They can be used to type specific data in schemas.
import { t } from "encodexx";
console.log(t)
Usage
To describe a schema using types, pass them to the Serializer
class constructor. You can also use arrays and objects to describe more complex structures.
Info
Functions like t.or()
, t.optional()
, and others return a regular type and can be used just like the rest.
// .encode("some string") const serializer1 = new Serializer(t.str) // .encode(124.34634), .encode("string") const serializer2 = new Serializer(t.or(t.float64, t.str))
const serializer = new Serializer([t.or(t.float64, t.str)])
const serializer = new Serializer({ title: t.str, info: { chart: [{ xValue: t.or(t.float64, t.str), yValue: t.or(t.float64, t.str) }], status: t.enumerate("200", "201", "400", "500") }})
What’s Next?
Read about the types you are interested in in the following chapters.