mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
feat(schema): add pi-schema, JSON Schema builders and validation without eval
@earendil-works/pi-schema compiles JSON Schema (drafts 2020-12 and 7) once into plain closures: no eval or new Function, so it runs under a strict CSP. It passes 2,222 of the 2,223 core tests of the official JSON-Schema-Test-Suite, checks Chord-style argument schemas within 1.2x of TypeBox's JIT, and keeps 3,200 compiled schemas in 7.9 MB (TypeBox: 54.7 MB). - compile(schema, options) returns a Validator: check() is the boolean check (a type guard for builder schemas), errors() reports each failure with a JSON Pointer path, missing and unknown fields at the field. - Builders (str, int, obj, opt, union, ...) return plain JSON Schema typed with the values it accepts (Static<typeof schema>). - Formats are an optional entry point (./formats), adapted from TypeBox (MIT). - Tests run the vendored suite (drafts 2020-12 and 7, with optional and format tests); npm run bench compares conformance, speed, setup cost, memory and bundle size with TypeBox, @cfworker/json-schema and omptype.
This commit is contained in:
parent
7ef8680abd
commit
fab2c5353e
255 changed files with 37963 additions and 2 deletions
|
|
@ -26,6 +26,7 @@ const WORKSPACE = {
|
|||
"@earendil-works/pi-codemode": "packages/codemode/src",
|
||||
"@earendil-works/pi-telemetry": "packages/telemetry/src",
|
||||
"@earendil-works/pi-mcp": "packages/mcp/src",
|
||||
"@earendil-works/pi-schema": "packages/schema/src",
|
||||
"@earendil-works/pi-tui": "packages/tui/src",
|
||||
};
|
||||
|
||||
|
|
@ -34,6 +35,10 @@ const WORKSPACE = {
|
|||
* graph it is allowed to reach.
|
||||
*/
|
||||
const BUDGETS = {
|
||||
"packages/schema": {
|
||||
// The format checks (vendored from TypeBox, about 40 KB) load only through ./formats.
|
||||
".": { maxFiles: 10, forbid: ["schema/src/formats/"] },
|
||||
},
|
||||
"packages/ai": {
|
||||
"./models": {
|
||||
// Request telemetry reaches pi-ai's telemetry.ts and pi-telemetry's root (index, noop, metrics, memory).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue