mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
4.6 KiB
4.6 KiB
Changelog
[Unreleased]
Added
unsafe<T>(schema)types a schema as acceptingTwithout checking it, as TypeBox'sType.Unsafedoes.recursive<T>(id, build)builds a schema that contains itself (a tree), with its type given asT.Validator.validate(value)returns{ ok: true, value }or{ ok: false, errors }without coercing, on every validator.Statictypes TypeBox'sEnum,Tuple,BigIntandUndefinedschemas.- TypeBox's JavaScript types validate and coerce as TypeBox does:
{ type: "bigint" }(Type.BigInt) and{ type: "undefined" }(Type.Undefined), withValue.Convert's rules for both; the number keywords apply to numbers and bigints alike, with bounds of either kind. Thebigint()builder builds the former. equal(a, b): JSON equality asconst,enumanduniqueItemscompare, a drop-in for TypeBox'sValue.Equal.
Changed
- Faster checks, still without eval: object and array loops run
const, smallenums, type lists, number bounds, string lengths and patterns inline instead of calling a closure; a closed object looks up keys in declared order first;anyOfbranches that are bare types (asnullablebuilds) run as one type test. Checks take about 16% less time across the benchmark's speed cases, up to 30% less for tagged unions and 45% less for nullable properties.
Fixed
- A
numberorintegerno longer acceptsNaN,Infinityor-Infinity, as in TypeBox; before, an unboundednum()accepted them. JSON has neither, so only values built in code are affected. Errors name the value (expected number, got NaN). - The third-party licenses are in
THIRD_PARTY_NOTICES/, renamed fromLICENSES/, which Vite's license notices read as the package's license file, failing browser builds that bundle the package. - A required property set to
undefinedis valid when its schema takesundefined(a union withType.Undefined(),Type.Unknown(),Type.Any()), as in TypeBox; before, it was always missing. An optional one set toundefinedstill counts as absent. - Fixed local
$refs in schemas whose root$idis a relative path with a directory, such asschemas/tool.json: the$idwas applied twice, socompilethrew andunresolvedRefs: "reject"rejected valid tool arguments. Relative$ids are now also applied once withunevaluatedProperties/unevaluatedItems, when explaining errors under nested resources, and on the first coercion of a schema with$dynamicRef(#11697)
[1.5.0] - 2026-11-02
Added
- Initial release:
compile(schema, options)validates JSON Schema drafts 2020-12 and 7 withoutevalornew Function, compiling a schema once into plain closures.Validator.checkis the boolean check (a type guard for schemas built with the builders),Validator.errorsreports each failure with a JSON Pointer path. Format checks are in the optional@earendil-works/pi-schema/formatsentry point. - Schema builders (
str,num,int,bool,nul,unknown,lit,oneOf,obj,opt,arr,tuple,map,union,nullable,bytes) that return plain JSON Schema typed with the values it accepts (Static<typeof schema>). compile(schema, { coerce: true })addscoerce(value)andparse(value)for loosely typed input such as a model's tool call arguments: optionalnulls dropped, TypeBox 1.3.27'sValue.Convertrules keyed on JSON Schema keywords (numeric strings,"true", single values to arrays,const/enummembers, union branches), then Ajv-style primitive coercion bytype.coercecopies only the paths it changes and returns the input itself when nothing changes;parsecoerces, then checks. Validators compiled without the option have neither; the README lists every rule.Staticalso types TypeBox-built schemas, from TypeBox 1.x's type shapes and without importing TypeBox: String, Number, Integer, Boolean, Null, Literal, Array, Object (withType.OptionalandType.Readonlyproperties), Union, Record, Unsafe, Unknown and Any give TypeBox's static type; other TypeBox kinds giveunknown.unresolvedRefs: "reject"compiles a$refthat names nothing asfalse(the error isunresolved reference <ref>) instead of throwing, for schemas whose references may dangle.formatsalso checksurlandjson-pointer-uri-fragment, as TypeBox and ajv-formats do.npm run benchcompares conformance, speed (with and without eval), setup cost, memory and bundle size with ata-validator (generated code and its interpreter), Ajv, Zod (native schemas, andz.fromJSONSchemafor the test suite), TypeBox, @cfworker/json-schema and omptype.