oatschema 0.0.0-stage → 0.1.0

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.
Files changed (59) hide show
  1. package/AUTHORS +4 -0
  2. package/CHANGELOG.md +28 -0
  3. package/LICENSE +201 -0
  4. package/README.md +201 -2
  5. package/THIRD-PARTY-NOTICES +28 -0
  6. package/dist/ajv.d.ts +21 -0
  7. package/dist/ajv.js +28 -0
  8. package/dist/bundled.d.ts +1 -0
  9. package/dist/bundled.js +18 -0
  10. package/dist/compiled/0.8.0/audio-transcription.js +4 -0
  11. package/dist/compiled/0.8.0/classification.js +4 -0
  12. package/dist/compiled/0.8.0/document-extraction.js +4 -0
  13. package/dist/compiled/0.8.0/embedding.js +4 -0
  14. package/dist/compiled/0.8.0/entity-extraction.js +4 -0
  15. package/dist/compiled/0.8.0/generic.js +4 -0
  16. package/dist/compiled/0.8.0/geolocation.js +4 -0
  17. package/dist/compiled/0.8.0/llm-output.js +4 -0
  18. package/dist/compiled/0.8.0/object-detection.js +4 -0
  19. package/dist/compiled/0.8.0/ranking.js +4 -0
  20. package/dist/compiled/0.8.0/regression.js +4 -0
  21. package/dist/compiled/0.8.0/temporal-segmentation.js +4 -0
  22. package/dist/compiled/index.js +30 -0
  23. package/dist/errors.d.ts +27 -0
  24. package/dist/errors.js +63 -0
  25. package/dist/formats.d.ts +13 -0
  26. package/dist/formats.js +106 -0
  27. package/dist/index.d.ts +34 -0
  28. package/dist/index.js +58 -0
  29. package/dist/names.d.ts +33 -0
  30. package/dist/names.js +33 -0
  31. package/dist/validate/audio-transcription.d.ts +27 -0
  32. package/dist/validate/audio-transcription.js +14 -0
  33. package/dist/validate/classification.d.ts +27 -0
  34. package/dist/validate/classification.js +14 -0
  35. package/dist/validate/document-extraction.d.ts +27 -0
  36. package/dist/validate/document-extraction.js +14 -0
  37. package/dist/validate/embedding.d.ts +27 -0
  38. package/dist/validate/embedding.js +14 -0
  39. package/dist/validate/entity-extraction.d.ts +27 -0
  40. package/dist/validate/entity-extraction.js +14 -0
  41. package/dist/validate/generic.d.ts +27 -0
  42. package/dist/validate/generic.js +14 -0
  43. package/dist/validate/geolocation.d.ts +27 -0
  44. package/dist/validate/geolocation.js +14 -0
  45. package/dist/validate/llm-output.d.ts +27 -0
  46. package/dist/validate/llm-output.js +14 -0
  47. package/dist/validate/object-detection.d.ts +27 -0
  48. package/dist/validate/object-detection.js +14 -0
  49. package/dist/validate/ranking.d.ts +27 -0
  50. package/dist/validate/ranking.js +14 -0
  51. package/dist/validate/regression.d.ts +27 -0
  52. package/dist/validate/regression.js +14 -0
  53. package/dist/validate/temporal-segmentation.d.ts +27 -0
  54. package/dist/validate/temporal-segmentation.js +14 -0
  55. package/dist/validate.d.ts +40 -0
  56. package/dist/validate.js +59 -0
  57. package/dist/validation.d.ts +74 -0
  58. package/dist/validation.js +328 -0
  59. package/package.json +72 -4
package/AUTHORS ADDED
@@ -0,0 +1,4 @@
1
+ The OATS Authors are the copyright holders of OATS. This file lists them.
2
+ Individuals and organisations may add themselves when they contribute.
3
+
4
+ Dorsal Hub LTD
package/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ This package uses its own semantic version. `SCHEMA_VERSION` gives the default OATS schema version of each release.
4
+
5
+ ## 0.1.0 (2026-10-30)
6
+
7
+ Validation, with precompiled validators.
8
+
9
+ - `oatschema/validate`: `validate`, `isValid`, `iterErrors` and `getValidator`, for a schema name, an optional schema version and `{ checkFormats }`. `validate` throws a `ValidationError` for the first error, and `iterErrors` yields every error. Validators are cached.
10
+ - `oatschema/validate/<name>`: `getValidator` for one schema, so a page loads only that schema's validator.
11
+ - The validators are compiled ahead of time, generate no code at run time and import nothing outside the package, so they run under a strict Content Security Policy (`script-src 'self'`) and in a browser without a bundler. The package still has no runtime dependencies.
12
+ - `ValidationError` has `message`, `reason`, `path`, `keyword`, `schemaPath`, `schemaName` and `schemaVersion`. It shows values from the record as `…`, and its size is bounded whatever the record holds: `reason` is at most 1,000 characters and each path string at most 100.
13
+ - Failures inside `anyOf`, `oneOf` and `if`/`then` are reported as oatschema-py reports them: one error for a failed `anyOf` or `oneOf`, and the `then` error without a separate `if` error.
14
+ - Verdicts match oatschema-py on every example in the OATS 0.8.0 release, with format checks on and off. One known difference: integers above 2^53, which `JSON.parse` rounds, can make a `uniqueItems` list fail.
15
+ - `date-time` follows RFC 3339 strictly, and `uri` accepts any absolute RFC 3986 URI. Both match the format checks oatschema-py uses.
16
+ - `oatschema/ajv`: `addOatsKeywords(ajv)` and `addOatsFormats(ajv)`, for people who validate with their own Ajv.
17
+ - `SchemaVersion`, a union of the bundled versions, and `isSchemaVersion(value)`. Every `version` parameter now takes a `SchemaVersion`, and `availableVersions()` returns `SchemaVersion[]`. **Breaking for TypeScript callers** that pass a `string`; narrow it with `isSchemaVersion` first. JavaScript callers are unaffected.
18
+ - `UnknownSchemaError` and `SchemaLookupError` keep their names. Their messages shorten a long requested name or version.
19
+ - The package now ships `AUTHORS`, and `THIRD-PARTY-NOTICES` with Ajv's MIT licence, which covers the generated validator code.
20
+ - Published from GitHub Actions with npm trusted publishing and provenance.
21
+
22
+ ## 0.0.1 (2026-10-18)
23
+
24
+ First release. Schema access only; validation is planned for 0.1.0.
25
+
26
+ - Bundles OATS schema version 0.8.0, the first public OATS release, copied unchanged from the `oatschema/oats` release tag. Its 12 schemas are `audio-transcription`, `classification`, `document-extraction`, `embedding`, `entity-extraction`, `generic`, `geolocation`, `llm-output`, `object-detection`, `ranking`, `regression` and `temporal-segmentation`. `SCHEMA_VERSION` is 0.8.0.
27
+ - `getSchema`, `getSchemaJson`, `availableVersions`, `SCHEMA_VERSION`, `SCHEMA_NAMES` and `SchemaName`.
28
+ - `UnknownSchemaError` and `SchemaLookupError`.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,202 @@
1
- # Temporary Holding Version
1
+ # oatschema
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/oatschema.svg)](https://www.npmjs.com/package/oatschema)
4
+ [![CI](https://github.com/oatschema/oatschema-js/actions/workflows/ci.yml/badge.svg)](https://github.com/oatschema/oatschema-js/actions/workflows/ci.yml)
5
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/oatschema/oatschema-js/blob/main/LICENSE)
6
+
7
+ The [OATS](https://oatschema.org) (Open Annotation Task Schemas) JSON schemas and validators for JavaScript and TypeScript.
8
+
9
+ OATS is a collection of strict, versioned JSON Schema 2020-12 schemas, defining and validating the structured outputs of machine learning models, workflow steps and annotation. Models, pipelines and people write the same JSON for each task, so a classification, a transcription or a set of detected objects has one shape, whatever produced it. This package bundles the schemas so you can validate those records anywhere. (OATS is unrelated to the W3C Web Annotation data model, formerly Open Annotation.)
10
+
11
+ - **No dependencies, no I/O.** The schemas are embedded in the module, so the package works the same in Node.js 22+, browsers, Deno, Bun and any bundler.
12
+ - **Validation built in.** Validators are compiled ahead of time, so they generate no code at run time. They work under a strict Content Security Policy (`script-src 'self'`) and in a browser page without a bundler, and a page can load the validator for one schema only.
13
+ - **Same verdicts as Python.** On every example in the OATS release, the validators agree with [oatschema-py](https://github.com/oatschema/oatschema-py), with format checks on and off.
14
+ - **Exactly as released.** Each schema is byte-identical to its [oatschema/oats](https://github.com/oatschema/oats) release.
15
+ - **Typed.** ESM with TypeScript types. Schema names and versions are union types, so typos fail at compile time.
16
+
17
+ ## Quick start
18
+
19
+ ```
20
+ npm install oatschema
21
+ ```
22
+
23
+ ```ts
24
+ import { getSchema, SCHEMA_VERSION } from "oatschema";
25
+ import { validate, isValid } from "oatschema/validate";
26
+
27
+ const schema = getSchema("classification"); // a fresh plain object, safe to modify
28
+ schema.$id; // "https://oatschema.org/0.8.0/classification"
29
+ SCHEMA_VERSION; // "0.8.0", used when you don't pass a version
30
+
31
+ isValid({ labels: [{ label: "cat", score: 0.92 }] }, "classification"); // true
32
+ validate({ labels: [{ label: "cat", score: 1.5 }] }, "classification");
33
+ // throws ValidationError: classification 0.8.0 at /labels/0/score: … is greater than the maximum of 1
34
+ ```
35
+
36
+ ## Schemas
37
+
38
+ | Name | Holds |
39
+ | :--- | :--- |
40
+ | `audio-transcription` | Transcribed speech, with timed segments, speakers and non-verbal events |
41
+ | `classification` | Predicted labels with scores and an optional vocabulary |
42
+ | `document-extraction` | Document layout and content: text blocks, coordinates and pages |
43
+ | `embedding` | A dense or sparse vector and the model that produced it |
44
+ | `entity-extraction` | Entities linked to their evidence, and relations between them |
45
+ | `generic` | Arbitrary key-value data |
46
+ | `geolocation` | A geographic feature, as a strict subset of GeoJSON |
47
+ | `llm-output` | One prompt and response, with generation parameters and usage |
48
+ | `object-detection` | Boxes, polygons and their hierarchy within a source |
49
+ | `ranking` | Ranked results for a query, such as search or retrieval hits |
50
+ | `regression` | Numeric predictions, intervals and forecasts |
51
+ | `temporal-segmentation` | Labelled time intervals, such as chapters, scenes or speaker turns |
52
+
53
+ Browse every schema, its fields and the changelog at [oatschema.org](https://oatschema.org).
54
+
55
+ ## Validating records
56
+
57
+ `oatschema/validate` checks a record (a JSON value, such as the result of `JSON.parse`) against a bundled schema:
58
+
59
+ ```ts
60
+ import { getValidator, isValid, iterErrors, validate, ValidationError } from "oatschema/validate";
61
+
62
+ const record = JSON.parse(text);
63
+ if (!isValid(record, "classification")) {
64
+ for (const error of iterErrors(record, "classification")) {
65
+ console.log(error.path, error.keyword, error.reason); // ["labels", 0, "score"] "maximum" "… is greater than the maximum of 1"
66
+ }
67
+ }
68
+
69
+ try {
70
+ validate(record, "classification", "0.8.0");
71
+ } catch (error) {
72
+ if (error instanceof ValidationError) {
73
+ console.log(error.message); // classification 0.8.0 at /labels/0/score: … is greater than the maximum of 1
74
+ }
75
+ }
76
+
77
+ const validator = getValidator("classification"); // cached, so get it once and reuse it
78
+ validator.isValid(record);
79
+ ```
80
+
81
+ - `validate` throws a `ValidationError` for the first error. `iterErrors` yields every error, and `isValid` returns a boolean.
82
+ - Formats (`date-time` and `uri`) are checked unless you pass `{ checkFormats: false }`, as in `isValid(record, "classification", undefined, { checkFormats: false })`.
83
+ - Pass the schema version a record was written for. A version read from a record is a `string`; narrow it with `isSchemaVersion(version)` first.
84
+
85
+ **Errors never quote the record.** A `ValidationError` shows each value from the record as `…` and quotes only property names, so a multi-megabyte value can't end up in a log. `reason` is at most 1,000 characters, each string in `path` at most 100, and `message` adds the schema, version and location. It has:
86
+
87
+ | Property | Holds |
88
+ | :--- | :--- |
89
+ | `message` | `classification 0.8.0 at /labels/0/score: … is greater than the maximum of 1` |
90
+ | `reason` | `… is greater than the maximum of 1` |
91
+ | `path` | `["labels", 0, "score"]`: where in the record, with array indices as numbers |
92
+ | `keyword` | `"maximum"`: the JSON Schema keyword that rejected the value |
93
+ | `schemaPath` | `["properties", "labels", "items", "properties", "score", "maximum"]`: where in the schema |
94
+ | `schemaName`, `schemaVersion` | The schema it was checked against |
95
+
96
+ ### One schema only
97
+
98
+ `oatschema/validate` loads the validators for every schema (about 56 KB gzipped). A page that checks one schema can load just that one, plus about 7 KB of shared code:
99
+
100
+ ```ts
101
+ import { getValidator } from "oatschema/validate/document-extraction";
102
+
103
+ const validator = getValidator(); // or getValidator("0.8.0", { checkFormats: false })
104
+ validator.validate(record);
105
+ ```
106
+
107
+ ### In a browser, without a bundler
108
+
109
+ Every module in `dist/` imports only other files in `dist/` by relative path, and nothing evaluates code from strings. Serve the package's `dist/` directory from your own origin and import the file you need:
110
+
111
+ ```html
112
+ <script type="module">
113
+ import { getValidator } from "/static/oatschema/dist/validate/classification.js";
114
+ getValidator().isValid({ labels: [{ label: "cat" }] });
115
+ </script>
116
+ ```
117
+
118
+ ### Same verdicts as oatschema-py
119
+
120
+ The validators are compiled from the schemas with [Ajv](https://ajv.js.org), but no Ajv code or type is part of the API. The repository's `conformance/` directory holds every example from each bundled OATS release, with its expected verdict, plus format edge cases checked against the jsonschema-rs version oatschema-py uses. The tests check every case here, and a script checks the same cases against oatschema-py. They agree on all of them, with format checks on and off.
121
+
122
+ `date-time` follows RFC 3339 strictly (a `T` separator, an offset with a colon, real dates, and leap seconds only at 23:59:60 UTC), and `uri` accepts any absolute RFC 3986 URI, including `x:`. Both match jsonschema-rs on every case in `conformance/formats.json`.
123
+
124
+ Known differences from oatschema-py:
125
+
126
+ - **One changes a verdict:** JavaScript numbers hold integers exactly only up to 2^53. `JSON.parse` rounds larger ones, so two different large integers in a `uniqueItems` list (such as `embedding`'s sparse `indices` or `document-extraction`'s page lists) can become equal and fail here while oatschema-py accepts them. Keep such integers below 9007199254740992.
127
+
128
+ These don't change a verdict:
129
+
130
+ - Property names in messages are shortened to 100 characters. oatschema-py quotes them in full, within its 1,000-character limit.
131
+ - When a record has several errors, the two packages may list them in a different order, so `validate` can report a different one of them.
132
+ - Records must be JSON values. Values JSON can't hold, such as `undefined`, `NaN`, functions, class instances and cyclic objects, give no particular result.
133
+
134
+ ### With your own Ajv
135
+
136
+ If you already compile schemas with Ajv, `oatschema/ajv` registers the two OATS keywords and the same `date-time` and `uri` checks:
137
+
138
+ ```ts
139
+ import { Ajv2020 } from "ajv/dist/2020.js";
140
+ import { getSchema } from "oatschema";
141
+ import { addOatsFormats, addOatsKeywords } from "oatschema/ajv";
142
+
143
+ const ajv = new Ajv2020({ allErrors: true, strictTypes: false, strictTuples: false, strictRequired: false });
144
+ addOatsFormats(addOatsKeywords(ajv));
145
+ const check = ajv.compile(getSchema("classification"));
146
+ ```
147
+
148
+ - `x-license` and `x-version` are the only non-standard keywords in OATS. Registering them keeps Ajv's strict mode on for everything else.
149
+ - The three relaxed options switch off Ajv's style checks, which reject some valid 2020-12 patterns that OATS uses, such as `required` inside an `if`.
150
+ - Compile each schema once per Ajv instance and reuse the function. Compiling a second copy with the same `$id` throws; fetch the first with `ajv.getSchema(schema.$id)`.
151
+ - Ajv's own error objects can carry property names from the record at any length. `oatschema/validate` bounds its errors; with your own Ajv, that's up to you.
152
+
153
+ ## API
154
+
155
+ From `oatschema`:
156
+
157
+ | Export | Description |
158
+ | :--- | :--- |
159
+ | `getSchema(name, version?)` | The schema as a new object on every call |
160
+ | `getSchemaJson(name, version?)` | The schema file's text, exactly as released |
161
+ | `availableVersions()` | Every bundled schema version, oldest first |
162
+ | `SCHEMA_VERSION` | The default schema version, the newest bundled |
163
+ | `SCHEMA_NAMES`, `SchemaName` | The schema names, as an array and a union type |
164
+ | `SchemaVersion`, `isSchemaVersion(value)` | The bundled versions as a union type, and a guard that narrows a string to it |
165
+ | `UnknownSchemaError` | Thrown for a name that exists in no bundled version |
166
+ | `SchemaLookupError` | Thrown for a version that isn't bundled, or that lacks the schema |
167
+
168
+ From `oatschema/validate`:
169
+
170
+ | Export | Description |
171
+ | :--- | :--- |
172
+ | `validate(record, name, version?, options?)` | Throws a `ValidationError` for the first error |
173
+ | `isValid(record, name, version?, options?)` | Whether the record conforms |
174
+ | `iterErrors(record, name, version?, options?)` | An iterator over every error |
175
+ | `getValidator(name, version?, options?)` | A cached `Validator` with `validate`, `isValid` and `iterErrors` methods |
176
+ | `ValidationError` | A record that doesn't conform |
177
+
178
+ `oatschema/validate` also re-exports `UnknownSchemaError` and `SchemaLookupError`, and the types `Validator`, `ValidateOptions` and `ValidationErrorDetails`. `oatschema/validate/<name>` exports `getValidator(version?, options?)` for that schema, `ValidationError`, `SchemaLookupError` and the same types. `oatschema/ajv` exports `addOatsKeywords(ajv)` and `addOatsFormats(ajv)`.
179
+
180
+ - `version` must be exact: `"0.8.0"`, never `"0.8"` or `"latest"`.
181
+ - `options` is `{ checkFormats?: boolean }`. Any other key, or a `checkFormats` that isn't a boolean, throws a `TypeError`.
182
+ - `UnknownSchemaError` and `SchemaLookupError` carry the requested `schemaName`, and `SchemaLookupError` also carries `schemaVersion`.
183
+
184
+ ## Versions
185
+
186
+ **Schema versions.** Before OATS 1.0, a new release may reject records an older one accepted, or the reverse, so pass the version a record was written for.
187
+
188
+ - Each `$id` includes its version (`https://oatschema.org/0.8.0/classification`), so several versions can share one Ajv instance.
189
+ - Each schema states its own version in `x-version`.
190
+ - This package bundles OATS 0.8.0, the first public release, and every later one. For 0.4.0 to 0.7.0, use the Python package, [oatschema-py](https://github.com/oatschema/oatschema-py).
191
+
192
+ **Package versions.** The package has its own semantic version, which never encodes a schema version; read `SCHEMA_VERSION` instead. Upgrading never removes a schema version, but it can move the default. Before 1.0, a release that changes the default is a minor bump, so npm's default `^0.x.y` range keeps your default fixed.
193
+
194
+ ## Contributing
195
+
196
+ Schema changes belong in [oatschema/oats](https://github.com/oatschema/oats). For this package, see [CONTRIBUTING.md](https://github.com/oatschema/oatschema-js/blob/main/CONTRIBUTING.md). Commits need a DCO sign-off (`git commit -s`).
197
+
198
+ ## License
199
+
200
+ Apache-2.0. Copyright [The OATS Authors](https://github.com/oatschema/oatschema-js/blob/main/AUTHORS).
201
+
202
+ The precompiled validators in `dist/compiled/` are generated by Ajv, which is MIT-licensed; its licence is in `THIRD-PARTY-NOTICES`.
@@ -0,0 +1,28 @@
1
+ oatschema includes code generated by Ajv, the JSON Schema validator
2
+ (https://ajv.js.org), in the precompiled validators under dist/compiled/.
3
+ The generated code was produced with ajv 8.20.0, which is licensed as follows.
4
+
5
+ --------------------------------------------------------------------------------
6
+
7
+ The MIT License (MIT)
8
+
9
+ Copyright (c) 2015-2021 Evgeny Poberezkin
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
package/dist/ajv.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /** The part of an Ajv instance that {@link addOatsKeywords} uses. */
2
+ export interface KeywordTarget {
3
+ addKeyword(definition: {
4
+ keyword: string;
5
+ schemaType: "object" | "string";
6
+ }): unknown;
7
+ }
8
+ /** The part of an Ajv instance that {@link addOatsFormats} uses. */
9
+ export interface FormatTarget {
10
+ addFormat(name: string, format: (value: string) => boolean): unknown;
11
+ }
12
+ /**
13
+ * Register the two non-standard OATS keywords, `x-license` (an object) and `x-version` (a string), so that Ajv's
14
+ * strict mode accepts the schemas. Returns `ajv`.
15
+ */
16
+ export declare function addOatsKeywords<T extends KeywordTarget>(ajv: T): T;
17
+ /**
18
+ * Register the `date-time` and `uri` formats with the same checks as `oatschema/validate`, which are stricter than
19
+ * `ajv-formats` for `date-time` (RFC 3339 only) and accept every RFC 3986 URI. Returns `ajv`.
20
+ */
21
+ export declare function addOatsFormats<T extends FormatTarget>(ajv: T): T;
package/dist/ajv.js ADDED
@@ -0,0 +1,28 @@
1
+ // SPDX-FileCopyrightText: 2026 The OATS Authors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Helpers for validating OATS records with your own Ajv instance.
5
+ *
6
+ * `oatschema/validate` needs no Ajv. Use these only if you already compile schemas with Ajv yourself.
7
+ *
8
+ * @module
9
+ */
10
+ import { isDateTime, isUri } from "./formats.js";
11
+ /**
12
+ * Register the two non-standard OATS keywords, `x-license` (an object) and `x-version` (a string), so that Ajv's
13
+ * strict mode accepts the schemas. Returns `ajv`.
14
+ */
15
+ export function addOatsKeywords(ajv) {
16
+ ajv.addKeyword({ keyword: "x-license", schemaType: "object" });
17
+ ajv.addKeyword({ keyword: "x-version", schemaType: "string" });
18
+ return ajv;
19
+ }
20
+ /**
21
+ * Register the `date-time` and `uri` formats with the same checks as `oatschema/validate`, which are stricter than
22
+ * `ajv-formats` for `date-time` (RFC 3339 only) and accept every RFC 3986 URI. Returns `ajv`.
23
+ */
24
+ export function addOatsFormats(ajv) {
25
+ ajv.addFormat("date-time", isDateTime);
26
+ ajv.addFormat("uri", isUri);
27
+ return ajv;
28
+ }
@@ -0,0 +1 @@
1
+ export declare const BUNDLED: ReadonlyMap<string, ReadonlyMap<string, string>>;