Betterlol/moon_zod/core does not have a README file
pub(all) struct ConstraintInfo {
min_value : Double
max_value : Double
format : String
pattern : String
is_int : Bool
is_positive : Bool
is_negative : Bool
multiple_of : Double
custom_messages : Array[String]
}pub(all) struct Schema {
schema_type : SchemaType
rules : Array[Rule]
description : String
required_error : String
invalid_type_error : String
name : String
brand : String
} derive(Debug)string().min(2).message("姓名至少需要 2 个字符")let s = object({"a": string(), "b": number()}).omit(["b"])
s.parse(json) // validates only field "a"fn Schema::parse_object(self : Schema, spec : Map[String, Schema], mode : ObjectMode, json : Json, path_stack : Array[String]) -> Result[Json, Array[ValidationError]]fn Schema::parse_preprocess(self : Schema, closure : TransformClosure, inner : Schema, json : Json, path_stack : Array[String]) -> Result[Json, Array[ValidationError]]fn Schema::parse_transform(_self : Schema, inner : Schema, closure : TransformClosure, json : Json, path_stack : Array[String]) -> Result[Json, Array[ValidationError]]let s = object({"name": string(), "age": number()}).partial()
s.parse(json) // all fields are now optionallet s = object({"a": string(), "b": number()}).pick(["a"])
s.parse(json) // validates only field "a"let s = string().transform(fn(json) {
match json {
String(s) => Ok(Json::string(s + "!"))
_ => Err("expected string")
}
})pub(all) enum SchemaType {
StringType
NumberType
BooleanType
NullType
AnyType
UnknownType
ObjectType(Map[String, Schema], ObjectMode)
ArrayType(Schema)
TupleType(Array[Schema])
OptionalType(Schema)
DefaultType(Schema, Json)
EnumType(Array[String])
UnionType(Array[Schema])
IntersectionType(Array[Schema])
PreprocessType(TransformClosure, Schema)
TransformType(Schema, TransformClosure)
LiteralType(Json)
} derive(Debug)fn escape_function_name(name : String) -> Stringfn escape_ident(name : String) -> Stringfn escape_mbt_string(s : String) -> Stringfn escape_type_name(name : String) -> Stringfn escape_variable_name(name : String) -> Stringfn format_double_simple(v : Double) -> Stringfn is_keyword(name : String) -> Boollet schema = @moon_zod.literal(Json::string("hello"))
schema.parse(Json::string("hello")) // Ok
schema.parse(Json::string("world")) // ErrA runtime JSON schema validation library for MoonBit, inspired by Zod and Pydantic
Dependencies