import schema from "@primate/schema";
import array from "@primate/schema/array";
import file from "@primate/schema/file";
import number from "@primate/schema/number";
import string from "@primate/schema/string";
// options:
// coerce: accept string values as valid by trying to coerce them first to target type
// strict: make sure all fields are present
const form = schema({
id: number,
title: string,
tags: array.of(string).min(2),
content: file,
}, { coerce: true, strict: false });
form.validate({ id: "1", title: "foobar" });
// -> success: returns validated fields, coerced to correct type if option
// `coerce` was set to true
// -> failure: throws, with validation errors
General purpose validation module.