@draht/schema 0.0.0-stage → 2026.11.5-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/LICENSES/typebox-LICENSE +23 -0
- package/dist/annotations.d.ts +44 -0
- package/dist/annotations.d.ts.map +1 -0
- package/dist/annotations.js +193 -0
- package/dist/annotations.js.map +1 -0
- package/dist/builders.d.ts +114 -0
- package/dist/builders.d.ts.map +1 -0
- package/dist/builders.js +98 -0
- package/dist/builders.js.map +1 -0
- package/dist/checks.d.ts +96 -0
- package/dist/checks.d.ts.map +1 -0
- package/dist/checks.js +540 -0
- package/dist/checks.js.map +1 -0
- package/dist/coerce.d.ts +53 -0
- package/dist/coerce.d.ts.map +1 -0
- package/dist/coerce.js +585 -0
- package/dist/coerce.js.map +1 -0
- package/dist/compiler.d.ts +53 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +546 -0
- package/dist/compiler.js.map +1 -0
- package/dist/explain.d.ts +29 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +382 -0
- package/dist/explain.js.map +1 -0
- package/dist/formats/index.d.ts +7 -0
- package/dist/formats/index.d.ts.map +1 -0
- package/dist/formats/index.js +51 -0
- package/dist/formats/index.js.map +1 -0
- package/dist/formats/typebox/date.d.ts +7 -0
- package/dist/formats/typebox/date.d.ts.map +1 -0
- package/dist/formats/typebox/date.js +47 -0
- package/dist/formats/typebox/date.js.map +1 -0
- package/dist/formats/typebox/date_time.d.ts +7 -0
- package/dist/formats/typebox/date_time.d.ts.map +1 -0
- package/dist/formats/typebox/date_time.js +39 -0
- package/dist/formats/typebox/date_time.js.map +1 -0
- package/dist/formats/typebox/duration.d.ts +6 -0
- package/dist/formats/typebox/duration.d.ts.map +1 -0
- package/dist/formats/typebox/duration.js +36 -0
- package/dist/formats/typebox/duration.js.map +1 -0
- package/dist/formats/typebox/email.d.ts +6 -0
- package/dist/formats/typebox/email.d.ts.map +1 -0
- package/dist/formats/typebox/email.js +36 -0
- package/dist/formats/typebox/email.js.map +1 -0
- package/dist/formats/typebox/hostname.d.ts +8 -0
- package/dist/formats/typebox/hostname.d.ts.map +1 -0
- package/dist/formats/typebox/hostname.js +38 -0
- package/dist/formats/typebox/hostname.js.map +1 -0
- package/dist/formats/typebox/idn_email.d.ts +6 -0
- package/dist/formats/typebox/idn_email.d.ts.map +1 -0
- package/dist/formats/typebox/idn_email.js +36 -0
- package/dist/formats/typebox/idn_email.js.map +1 -0
- package/dist/formats/typebox/idn_hostname.d.ts +9 -0
- package/dist/formats/typebox/idn_hostname.d.ts.map +1 -0
- package/dist/formats/typebox/idn_hostname.js +39 -0
- package/dist/formats/typebox/idn_hostname.js.map +1 -0
- package/dist/formats/typebox/idna/format/bidi.d.ts +4 -0
- package/dist/formats/typebox/idna/format/bidi.d.ts.map +1 -0
- package/dist/formats/typebox/idna/format/bidi.js +132 -0
- package/dist/formats/typebox/idna/format/bidi.js.map +1 -0
- package/dist/formats/typebox/idna/format/puny.d.ts +4 -0
- package/dist/formats/typebox/idna/format/puny.d.ts.map +1 -0
- package/dist/formats/typebox/idna/format/puny.js +172 -0
- package/dist/formats/typebox/idna/format/puny.js.map +1 -0
- package/dist/formats/typebox/idna/hostname.d.ts +2 -0
- package/dist/formats/typebox/idna/hostname.d.ts.map +1 -0
- package/dist/formats/typebox/idna/hostname.js +43 -0
- package/dist/formats/typebox/idna/hostname.js.map +1 -0
- package/dist/formats/typebox/idna/idn-hostname.d.ts +2 -0
- package/dist/formats/typebox/idna/idn-hostname.d.ts.map +1 -0
- package/dist/formats/typebox/idna/idn-hostname.js +71 -0
- package/dist/formats/typebox/idna/idn-hostname.js.map +1 -0
- package/dist/formats/typebox/idna/index.d.ts +3 -0
- package/dist/formats/typebox/idna/index.d.ts.map +1 -0
- package/dist/formats/typebox/idna/index.js +30 -0
- package/dist/formats/typebox/idna/index.js.map +1 -0
- package/dist/formats/typebox/idna/label/ascii.d.ts +2 -0
- package/dist/formats/typebox/idna/label/ascii.d.ts.map +1 -0
- package/dist/formats/typebox/idna/label/ascii.js +37 -0
- package/dist/formats/typebox/idna/label/ascii.js.map +1 -0
- package/dist/formats/typebox/idna/label/puny.d.ts +2 -0
- package/dist/formats/typebox/idna/label/puny.d.ts.map +1 -0
- package/dist/formats/typebox/idna/label/puny.js +56 -0
- package/dist/formats/typebox/idna/label/puny.js.map +1 -0
- package/dist/formats/typebox/idna/label/unicode.d.ts +2 -0
- package/dist/formats/typebox/idna/label/unicode.d.ts.map +1 -0
- package/dist/formats/typebox/idna/label/unicode.js +134 -0
- package/dist/formats/typebox/idna/label/unicode.js.map +1 -0
- package/dist/formats/typebox/idna/pattern/pattern.d.ts +31 -0
- package/dist/formats/typebox/idna/pattern/pattern.d.ts.map +1 -0
- package/dist/formats/typebox/idna/pattern/pattern.js +98 -0
- package/dist/formats/typebox/idna/pattern/pattern.js.map +1 -0
- package/dist/formats/typebox/ipv4.d.ts +6 -0
- package/dist/formats/typebox/ipv4.d.ts.map +1 -0
- package/dist/formats/typebox/ipv4.js +36 -0
- package/dist/formats/typebox/ipv4.js.map +1 -0
- package/dist/formats/typebox/ipv6.d.ts +6 -0
- package/dist/formats/typebox/ipv6.d.ts.map +1 -0
- package/dist/formats/typebox/ipv6.js +36 -0
- package/dist/formats/typebox/ipv6.js.map +1 -0
- package/dist/formats/typebox/iri.d.ts +6 -0
- package/dist/formats/typebox/iri.d.ts.map +1 -0
- package/dist/formats/typebox/iri.js +63 -0
- package/dist/formats/typebox/iri.js.map +1 -0
- package/dist/formats/typebox/iri_reference.d.ts +6 -0
- package/dist/formats/typebox/iri_reference.d.ts.map +1 -0
- package/dist/formats/typebox/iri_reference.js +40 -0
- package/dist/formats/typebox/iri_reference.js.map +1 -0
- package/dist/formats/typebox/json_pointer.d.ts +7 -0
- package/dist/formats/typebox/json_pointer.d.ts.map +1 -0
- package/dist/formats/typebox/json_pointer.js +37 -0
- package/dist/formats/typebox/json_pointer.js.map +1 -0
- package/dist/formats/typebox/json_pointer_uri_fragment.d.ts +7 -0
- package/dist/formats/typebox/json_pointer_uri_fragment.d.ts.map +1 -0
- package/dist/formats/typebox/json_pointer_uri_fragment.js +37 -0
- package/dist/formats/typebox/json_pointer_uri_fragment.js.map +1 -0
- package/dist/formats/typebox/regex.d.ts +6 -0
- package/dist/formats/typebox/regex.d.ts.map +1 -0
- package/dist/formats/typebox/regex.js +41 -0
- package/dist/formats/typebox/regex.js.map +1 -0
- package/dist/formats/typebox/relative_json_pointer.d.ts +7 -0
- package/dist/formats/typebox/relative_json_pointer.d.ts.map +1 -0
- package/dist/formats/typebox/relative_json_pointer.js +37 -0
- package/dist/formats/typebox/relative_json_pointer.js.map +1 -0
- package/dist/formats/typebox/time.d.ts +6 -0
- package/dist/formats/typebox/time.d.ts.map +1 -0
- package/dist/formats/typebox/time.js +60 -0
- package/dist/formats/typebox/time.js.map +1 -0
- package/dist/formats/typebox/uri.d.ts +6 -0
- package/dist/formats/typebox/uri.d.ts.map +1 -0
- package/dist/formats/typebox/uri.js +36 -0
- package/dist/formats/typebox/uri.js.map +1 -0
- package/dist/formats/typebox/uri_reference.d.ts +6 -0
- package/dist/formats/typebox/uri_reference.d.ts.map +1 -0
- package/dist/formats/typebox/uri_reference.js +36 -0
- package/dist/formats/typebox/uri_reference.js.map +1 -0
- package/dist/formats/typebox/uri_template.d.ts +6 -0
- package/dist/formats/typebox/uri_template.d.ts.map +1 -0
- package/dist/formats/typebox/uri_template.js +37 -0
- package/dist/formats/typebox/uri_template.js.map +1 -0
- package/dist/formats/typebox/url.d.ts +7 -0
- package/dist/formats/typebox/url.d.ts.map +1 -0
- package/dist/formats/typebox/url.js +36 -0
- package/dist/formats/typebox/url.js.map +1 -0
- package/dist/formats/typebox/uuid.d.ts +7 -0
- package/dist/formats/typebox/uuid.d.ts.map +1 -0
- package/dist/formats/typebox/uuid.js +37 -0
- package/dist/formats/typebox/uuid.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/resolver.d.ts +58 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +209 -0
- package/dist/resolver.js.map +1 -0
- package/dist/shared.d.ts +9 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +33 -0
- package/dist/shared.js.map +1 -0
- package/dist/typebox-static.d.ts +48 -0
- package/dist/typebox-static.d.ts.map +1 -0
- package/dist/typebox-static.js +5 -0
- package/dist/typebox-static.js.map +1 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validator.d.ts +39 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +71 -0
- package/dist/validator.js.map +1 -0
- package/package.json +62 -5
- package/README.md +0 -3
|
@@ -0,0 +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,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;QAC/C,CAAC,CAAC,IAAI,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,GAAmB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAErD,oHAAoH;AACpH,MAAM,OAAO,SA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AC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACzG,CAAC;CACD;AAED,SAAS,YAAY,CAAC,MAAkB,EAAE,OAAuB;IAChE,OAAO,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC;AAED,oHAAoH;AACpH,SAAS,QAAQ,CAAC,MAAkB,EAAE,OAAuB;IAC5D,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACnD,IAAI,CAAC;QACJ,KAAK,CAAC,IAAI,EAAE,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\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\tconst coerced = this.coerce(value);\n\t\treturn this.check(coerced) ? { ok: true, value: coerced } : { ok: false, errors: this.errors(coerced) };\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,63 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@draht/schema",
|
|
3
|
+
"version": "2026.11.5-1",
|
|
4
|
+
"description": "JSON Schema validation without eval: drafts 2020-12 and 7, compiled into plain closures",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./formats": {
|
|
15
|
+
"source": "./src/formats/index.ts",
|
|
16
|
+
"types": "./dist/formats/index.d.ts",
|
|
17
|
+
"import": "./dist/formats/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md",
|
|
24
|
+
"CHANGELOG.md",
|
|
25
|
+
"LICENSES"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"clean": "node ../../scripts/package-files.mjs clean dist",
|
|
29
|
+
"build": "tsc -p tsconfig.build.json",
|
|
30
|
+
"test": "vitest --run",
|
|
31
|
+
"bench": "node --expose-gc test/bench/all.ts",
|
|
32
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"json-schema",
|
|
36
|
+
"validation",
|
|
37
|
+
"validator",
|
|
38
|
+
"csp"
|
|
39
|
+
],
|
|
40
|
+
"author": "Oskar Freye",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/draht-dev/draht.git",
|
|
48
|
+
"directory": "packages/schema"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": "^22.23.4 || ^24.22.1 || ^26.12.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@cfworker/json-schema": "4.1.1",
|
|
55
|
+
"@oh-my-pi/omptype": "18.13.3",
|
|
56
|
+
"ajv": "8.20.0",
|
|
57
|
+
"ajv-formats": "3.0.1",
|
|
58
|
+
"ata-validator": "1.61.3",
|
|
59
|
+
"typebox": "1.3.27",
|
|
60
|
+
"vitest": "4.1.12",
|
|
61
|
+
"zod": "4.6.7"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/README.md
DELETED