@draht/schema 2026.11.5-1 → 2026.11.14-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builders.d.ts +29 -0
- package/dist/builders.d.ts.map +1 -1
- package/dist/builders.js +28 -0
- package/dist/builders.js.map +1 -1
- package/dist/checks.d.ts +24 -6
- package/dist/checks.d.ts.map +1 -1
- package/dist/checks.js +52 -14
- package/dist/checks.js.map +1 -1
- package/dist/coerce.d.ts.map +1 -1
- package/dist/coerce.js +41 -2
- package/dist/coerce.js.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js +12 -7
- package/dist/compiler.js.map +1 -1
- package/dist/explain.d.ts.map +1 -1
- package/dist/explain.js +25 -15
- package/dist/explain.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/typebox-static.d.ts +9 -1
- package/dist/typebox-static.d.ts.map +1 -1
- package/dist/typebox-static.js +3 -1
- package/dist/typebox-static.js.map +1 -1
- package/dist/validator.d.ts +9 -0
- package/dist/validator.d.ts.map +1 -1
- package/dist/validator.js +12 -2
- package/dist/validator.js.map +1 -1
- package/package.json +2 -2
- /package/{LICENSES → THIRD_PARTY_NOTICES}/typebox-LICENSE +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox-static.d.ts","sourceRoot":"","sources":["../src/typebox-static.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typebox-static.d.ts","sourceRoot":"","sources":["../src/typebox-static.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,sHAAsH;AACtH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;CAAE,GACnE,UAAU,CAAC,CAAC,EA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,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,MAAM,CACrG,CAAC,CAAC,CAAC,CAAC,CACJ;CACD,GAAG;IACH,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,MAAM,CACtG,CAAC,CAAC,CAAC,CAAC,CACJ;CACD,CACD,CAAC;AAEJ,KAAK,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAC;AAGjD,KAAK,SAAS,CAAC,OAAO,IAAI,OAAO,SAAS,uBAAuB,GAAG,qCAAqC,GACtG,MAAM,GACN,MAAM,CAAC"}
|
package/dist/typebox-static.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// The static types of TypeBox-built schemas, read from the type shapes TypeBox 1.x declares (`'~kind'`, `'~optional'`,
|
|
2
2
|
// `'~readonly'`, `'~unsafe'`) without importing TypeBox, so `Static` also types tool arguments of TypeBox schemas.
|
|
3
|
-
// Only the common kinds are mapped; every other kind (
|
|
3
|
+
// Only the common kinds are mapped; every other kind (Intersect, Cyclic, Ref, ...) is `unknown`. Tuples are plain
|
|
4
|
+
// tuples: an element marked `Type.Optional`, `Type.Rest` or `Type.Readonly` is typed by its schema alone (`[string]`
|
|
5
|
+
// where TypeBox gives `[string?]`), unlike TypeBox; tuples of tool and API schemas are fixed pairs, typed exactly.
|
|
4
6
|
export {};
|
|
5
7
|
//# sourceMappingURL=typebox-static.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox-static.js","sourceRoot":"","sources":["../src/typebox-static.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,mHAAmH;AACnH,
|
|
1
|
+
{"version":3,"file":"typebox-static.js","sourceRoot":"","sources":["../src/typebox-static.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,mHAAmH;AACnH,kHAAkH;AAClH,qHAAqH;AACrH,mHAAmH","sourcesContent":["// The static types of TypeBox-built schemas, read from the type shapes TypeBox 1.x declares (`'~kind'`, `'~optional'`,\n// `'~readonly'`, `'~unsafe'`) without importing TypeBox, so `Static` also types tool arguments of TypeBox schemas.\n// Only the common kinds are mapped; every other kind (Intersect, Cyclic, Ref, ...) is `unknown`. Tuples are plain\n// tuples: an element marked `Type.Optional`, `Type.Rest` or `Type.Readonly` is typed by its schema alone (`[string]`\n// where TypeBox gives `[string?]`), unlike TypeBox; tuples of tool and API schemas are fixed pairs, typed exactly.\n\nimport type { Static } from \"./builders.ts\";\n\n/** The value type of a TypeBox schema type by its `'~kind'`, or its `Type.Unsafe` type; `unknown` for other kinds. */\nexport type TypeBoxStatic<S> = S extends { readonly \"~kind\": infer K }\n\t? KindStatic<S, K>\n\t: S extends { readonly \"~unsafe\": infer T }\n\t\t? T\n\t\t: unknown;\n\ninterface Primitives {\n\tString: string;\n\tNumber: number;\n\tInteger: number;\n\tBoolean: boolean;\n\tNull: null;\n\tBigInt: bigint;\n\tUndefined: undefined;\n\tUnknown: unknown;\n\tAny: any;\n}\n\ntype KindStatic<S, K> = K extends keyof Primitives\n\t? Primitives[K]\n\t: K extends \"Literal\"\n\t\t? S extends { readonly const: infer V }\n\t\t\t? V\n\t\t\t: unknown\n\t\t: K extends \"Array\"\n\t\t\t? S extends { readonly items: infer I }\n\t\t\t\t? Static<I>[]\n\t\t\t\t: unknown\n\t\t\t: K extends \"Object\"\n\t\t\t\t? S extends { readonly properties: infer P }\n\t\t\t\t\t? ObjectStatic<P>\n\t\t\t\t\t: unknown\n\t\t\t\t: K extends \"Union\"\n\t\t\t\t\t? S extends { readonly anyOf: readonly (infer B)[] }\n\t\t\t\t\t\t? Static<B>\n\t\t\t\t\t\t: unknown\n\t\t\t\t\t: K extends \"Record\"\n\t\t\t\t\t\t? S extends { readonly patternProperties: infer P }\n\t\t\t\t\t\t\t? Record<RecordKey<keyof P>, Static<P[keyof P]>>\n\t\t\t\t\t\t\t: unknown\n\t\t\t\t\t\t: K extends \"Enum\"\n\t\t\t\t\t\t\t? S extends { readonly enum: readonly (infer V)[] }\n\t\t\t\t\t\t\t\t? V\n\t\t\t\t\t\t\t\t: unknown\n\t\t\t\t\t\t\t: K extends \"Tuple\"\n\t\t\t\t\t\t\t\t? S extends { readonly items: infer I extends readonly unknown[] }\n\t\t\t\t\t\t\t\t\t? { -readonly [N in keyof I]: Static<I[N]> }\n\t\t\t\t\t\t\t\t\t: unknown\n\t\t\t\t\t\t\t\t: unknown;\n\ntype Optional = { readonly \"~optional\": true };\n\ntype Readonly = { readonly \"~readonly\": true };\n\n// As TypeBox: no properties is `object`; `'~optional'` properties may be omitted, `'~readonly'` ones are readonly.\ntype ObjectStatic<P> = keyof P extends never\n\t? object\n\t: Simplify<\n\t\t\t{ -readonly [K in keyof P as P[K] extends Optional | Readonly ? never : K]: Static<P[K]> } & {\n\t\t\t\t-readonly [K in keyof P as P[K] extends Optional ? (P[K] extends Readonly ? never : K) : never]?: Static<\n\t\t\t\t\tP[K]\n\t\t\t\t>;\n\t\t\t} & {\n\t\t\t\treadonly [K in keyof P as P[K] extends Readonly ? (P[K] extends Optional ? never : K) : never]: Static<\n\t\t\t\t\tP[K]\n\t\t\t\t>;\n\t\t\t} & {\n\t\t\t\treadonly [K in keyof P as P[K] extends Optional ? (P[K] extends Readonly ? K : never) : never]?: Static<\n\t\t\t\t\tP[K]\n\t\t\t\t>;\n\t\t\t}\n\t\t>;\n\ntype Simplify<T> = { [K in keyof T]: T[K] } & {};\n\n// TypeBox's key patterns for integer and number keys; every other pattern types its keys as strings.\ntype RecordKey<Pattern> = Pattern extends \"^-?(?:0|[1-9][0-9]*)$\" | \"^-?(?:0|[1-9][0-9]*)(?:\\\\.[0-9]+)?$\"\n\t? number\n\t: string;\n"]}
|
package/dist/validator.d.ts
CHANGED
|
@@ -22,6 +22,15 @@ export declare class Validator<T = unknown> {
|
|
|
22
22
|
* kept, so a validator whose values always pass never pays for it.
|
|
23
23
|
*/
|
|
24
24
|
errors(value: unknown): ValidationError[];
|
|
25
|
+
/**
|
|
26
|
+
* `value` itself when it is valid, else its errors: check() and errors() in one result, without coercion.
|
|
27
|
+
*
|
|
28
|
+
* Not TypeBox's `Value.Parse`, which also clones, fills defaults, converts and strips undeclared properties before
|
|
29
|
+
* it checks. This only checks: the strict replacement where `Value.Parse` is used to validate (its other steps
|
|
30
|
+
* change nothing for a valid value of a schema without defaults or extra properties). Use `parse()` with
|
|
31
|
+
* `coerce: true` for conversion.
|
|
32
|
+
*/
|
|
33
|
+
validate(value: unknown): ParseResult<T>;
|
|
25
34
|
}
|
|
26
35
|
/** A validator compiled with `coerce: true`: it also coerces loosely typed input towards the schema. */
|
|
27
36
|
export declare class CoercingValidator<T = unknown> extends Validator<T> {
|
package/dist/validator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElG;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,UAAU,EAC3C,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,cAAc,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,GACjD,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,wBAAgB,OAAO,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,OAA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CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,wBAAgB,OAAO,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAazG,oHAAoH;AACpH,qBAAa,SAAS,CAAC,CAAC,GAAG,OAAO;IACjC,iGAAiG;IACjG,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC;IAC/C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IACtC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IAC3C,OAAO,CAAC,SAAS,CAAoC;IAErD,YAAY,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAKpE;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,EAAE,CAIxC;IAED;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAEvC;CACD;AAED,wGAAwG;AACxG,qBAAa,iBAAiB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAC/D,OAAO,CAAC,OAAO,CAAkC;IAEjD;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAG9B;IAED,4FAA4F;IAC5F,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAEpC;CACD"}
|
package/dist/validator.js
CHANGED
|
@@ -32,6 +32,17 @@ export class Validator {
|
|
|
32
32
|
this.explainer ??= new Explainer(compiler(this.schema, this.options), this.schema);
|
|
33
33
|
return this.explainer.errors(value);
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* `value` itself when it is valid, else its errors: check() and errors() in one result, without coercion.
|
|
37
|
+
*
|
|
38
|
+
* Not TypeBox's `Value.Parse`, which also clones, fills defaults, converts and strips undeclared properties before
|
|
39
|
+
* it checks. This only checks: the strict replacement where `Value.Parse` is used to validate (its other steps
|
|
40
|
+
* change nothing for a valid value of a schema without defaults or extra properties). Use `parse()` with
|
|
41
|
+
* `coerce: true` for conversion.
|
|
42
|
+
*/
|
|
43
|
+
validate(value) {
|
|
44
|
+
return this.check(value) ? { ok: true, value } : { ok: false, errors: this.errors(value) };
|
|
45
|
+
}
|
|
35
46
|
}
|
|
36
47
|
/** A validator compiled with `coerce: true`: it also coerces loosely typed input towards the schema. */
|
|
37
48
|
export class CoercingValidator extends Validator {
|
|
@@ -48,8 +59,7 @@ export class CoercingValidator extends Validator {
|
|
|
48
59
|
}
|
|
49
60
|
/** Coerces `value`, then checks it: the coerced value when it is valid, else its errors. */
|
|
50
61
|
parse(value) {
|
|
51
|
-
|
|
52
|
-
return this.check(coerced) ? { ok: true, value: coerced } : { ok: false, errors: this.errors(coerced) };
|
|
62
|
+
return this.validate(this.coerce(value));
|
|
53
63
|
}
|
|
54
64
|
}
|
|
55
65
|
function compileCheck(schema, options) {
|
package/dist/validator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA,mHAAmH;AAGnH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAazC,MAAM,UAAU,OAAO,CACtB,MAAS,EACT,OAAO,GAAmB,UAAU;IAEpC,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC,MAAM,KAAK,IAAI;QAC7B,CAAC,CAAC,IAAI,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CAAC;QACb,OAAO,KAAK,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,KAAK,KAAK,OAAO;YAAE,MAAM,KAAK,CAAC;QACnC,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;AACF,CAAC","sourcesContent":["// compile(): a schema to a Validator, whose `check` is the fast boolean path and whose `errors` explains failures.\n\nimport type { Static } from \"./builders.ts\";\nimport { Coercer } from \"./coerce.ts\";\nimport { Compiler, RESTART } from \"./compiler.ts\";\nimport { Explainer } from \"./explain.ts\";\nimport type { Check, CompileOptions, JsonSchema, ParseResult, ValidationError } from \"./types.ts\";\n\n/**\n * Compiles `schema` into a Validator. Throws if the schema is malformed or a `$ref` names nothing (register other\n * documents with `options.schemas`). The schema is read, never modified. With `coerce: true` the validator also\n * coerces and parses loosely typed input.\n */\nexport function compile<S extends JsonSchema>(\n\tschema: S,\n\toptions: CompileOptions & { readonly coerce: true },\n): CoercingValidator<Static<S>>;\nexport function compile<S extends JsonSchema>(schema: S, options?: CompileOptions): Validator<Static<S>>;\nexport function compile<S extends JsonSchema>(\n\tschema: S,\n\toptions: CompileOptions = NO_OPTIONS,\n): Validator<Static<S>> | CoercingValidator<Static<S>> {\n\tconst check = compileCheck(schema, options);\n\treturn options.coerce === true\n\t\t? new CoercingValidator(schema, options, check)\n\t\t: new Validator(schema, options, check);\n}\n\nconst NO_OPTIONS: CompileOptions = Object.freeze({});\n\n/** A compiled schema whose valid values have type `T` (`unknown` unless the schema was built with the builders). */\nexport class Validator<T = unknown> {\n\t/** Whether `value` is valid. A plain function: it may be passed around without its validator. */\n\treadonly check: (value: unknown) => value is T;\n\tprotected readonly schema: JsonSchema;\n\tprotected readonly options: CompileOptions;\n\tprivate explainer: Explainer | undefined = undefined;\n\n\tconstructor(schema: JsonSchema, options: CompileOptions, check: Check) {\n\t\t// A compiled check is exactly the test that a value has the schema's static type.\n\t\tthis.check = check as (value: unknown) => value is T;\n\t\tthis.schema = schema;\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * Why `value` is invalid: one error per failing keyword, `[]` when it is valid. Built on the first failure and\n\t * kept, so a validator whose values always pass never pays for it.\n\t */\n\terrors(value: unknown): ValidationError[] {\n\t\tif (this.check(value)) return [];\n\t\tthis.explainer ??= new Explainer(compiler(this.schema, this.options), this.schema);\n\t\treturn this.explainer.errors(value);\n\t}\n\n\t/**\n\t * `value` itself when it is valid, else its errors: check() and errors() in one result, without coercion.\n\t *\n\t * Not TypeBox's `Value.Parse`, which also clones, fills defaults, converts and strips undeclared properties before\n\t * it checks. This only checks: the strict replacement where `Value.Parse` is used to validate (its other steps\n\t * change nothing for a valid value of a schema without defaults or extra properties). Use `parse()` with\n\t * `coerce: true` for conversion.\n\t */\n\tvalidate(value: unknown): ParseResult<T> {\n\t\treturn this.check(value) ? { ok: true, value } : { ok: false, errors: this.errors(value) };\n\t}\n}\n\n/** A validator compiled with `coerce: true`: it also coerces loosely typed input towards the schema. */\nexport class CoercingValidator<T = unknown> extends Validator<T> {\n\tprivate coercer: Coercer | undefined = undefined;\n\n\t/**\n\t * `value` coerced towards the schema: numeric strings to numbers, `\"true\"` to `true`, a single value to a one-item\n\t * array, an optional `null` dropped, the first union branch the value converts to (the README lists every rule).\n\t * Only the changed paths are copied; `value` comes back itself when nothing changes, and is never modified. Values\n\t * that cannot be coerced stay as they are. The rules are built on the first call.\n\t */\n\tcoerce(value: unknown): unknown {\n\t\tthis.coercer ??= new Coercer(compiler(this.schema, this.options), this.schema);\n\t\treturn this.coercer.coerce(value);\n\t}\n\n\t/** Coerces `value`, then checks it: the coerced value when it is valid, else its errors. */\n\tparse(value: unknown): ParseResult<T> {\n\t\treturn this.validate(this.coerce(value));\n\t}\n}\n\nfunction compileCheck(schema: JsonSchema, options: CompileOptions): Check {\n\treturn compiler(schema, options).root();\n}\n\n// Most schemas compile without tracking the dynamic scope; one with a bookended $dynamicRef compiles again with it.\nfunction compiler(schema: JsonSchema, options: CompileOptions): Compiler {\n\tconst plain = new Compiler(schema, options, false);\n\ttry {\n\t\tplain.root();\n\t\treturn plain;\n\t} catch (error) {\n\t\tif (error !== RESTART) throw error;\n\t\treturn new Compiler(schema, options, true);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draht/schema",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.14-1",
|
|
4
4
|
"description": "JSON Schema validation without eval: drafts 2020-12 and 7, compiled into plain closures",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist",
|
|
23
23
|
"README.md",
|
|
24
24
|
"CHANGELOG.md",
|
|
25
|
-
"
|
|
25
|
+
"THIRD_PARTY_NOTICES"
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
28
|
"clean": "node ../../scripts/package-files.mjs clean dist",
|
|
File without changes
|