Schemas
Stof objects as schemas.
FirstSchema: {
#[schema((target_value: str): bool => target_value.len() > 2)]
/// First name - valid if the length is greater than 2.
first: "First"
#[schema((
// can use tuples & lists to create pipelines (&& w/short circuits)
(target_value: unknown): bool => (typeof target_value) == "str",
(target_value: str): bool => {"Last", "Example"}.contains(target_value),
))]
/// Last name - valid if a string that is either "Last" or "Example".
last: "Last"
}
#[main]
fn main() {
const target = new { first: "Bob", last: "Example" };
assert(self.FirstSchema.schemafy(target)); // returns true (valid)
target.first = "AJ";
assert_not(self.FirstSchema.schemafy(target)); // returns false (invalid)
target.first = "Bob";
target.last = "NotInSet";
assert_not(self.FirstSchema.schemafy(target)); // invalid
target.last = 53;
assert_not(self.FirstSchema.schemafy(target)); // not a str (second fn never gets called)
}Schema Functions
Complete Signature
Sub Schemas
External Field Schema
Combinations
Remove Invalid Fields
Remove Not-defined Fields
Last updated