@correctlyjs/schemars 0.0.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.
package/AGENTS.md ADDED
@@ -0,0 +1,9 @@
1
+ # Schemars extension consumer guidance
2
+
3
+ - Install `@correctlyjs/schemars` alongside a compatible `correctly`; the peer dependency declares the supported Correctly API.
4
+ - Import `schemars` from `@correctlyjs/schemars/ajv` and opt in per Ajv validator. Importing the package does not enable it globally.
5
+ - The package root exports `schemarsEras`, `SchemarsEra`, `SchemarsVersion`, and `SchemarsVersionSelection`; the factory implements `AjvExtension` from `correctly/validators/ajv`.
6
+ - Types derive from the literal catalog in `src/eras.ts`; keep that module self-contained so CI can load both Git revisions. Version selections must be reviewed exact releases or ordered closed ranges within one era.
7
+ - `version` identifies an upstream Schemars release or closed range within one reviewed era, not this package's npm version.
8
+ - Consult `docs/guide.md` for the complete supported format and precision contract.
9
+ - This package releases independently of Correctly. Each newly reviewed upstream release needs its own extension changeset and publication.
package/LICENSE ADDED
@@ -0,0 +1,373 @@
1
+ Mozilla Public License Version 2.0
2
+ ==================================
3
+
4
+ 1. Definitions
5
+ --------------
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, import, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You. For
80
+ purposes of this definition, "control" means (a) the power, direct
81
+ or indirect, to cause the direction or management of such entity,
82
+ whether by contract or otherwise, or (b) ownership of more than
83
+ fifty percent (50%) of the outstanding shares or beneficial
84
+ ownership of such entity.
85
+
86
+ 2. License Grants and Conditions
87
+ --------------------------------
88
+
89
+ 2.1. Grants
90
+
91
+ Each Contributor hereby grants You a world-wide, royalty-free,
92
+ non-exclusive license:
93
+
94
+ (a) under intellectual property rights (other than patent or trademark)
95
+ Licensable by such Contributor to use, reproduce, make available,
96
+ modify, display, perform, distribute, and otherwise exploit its
97
+ Contributions, either on an unmodified basis, with Modifications, or
98
+ as part of a Larger Work; and
99
+
100
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
101
+ for sale, have made, import, and otherwise transfer either its
102
+ Contributions or its Contributor Version.
103
+
104
+ 2.2. Effective Date
105
+
106
+ The licenses granted in Section 2.1 with respect to any Contribution
107
+ become effective for each Contribution on the date the Contributor first
108
+ distributes such Contribution.
109
+
110
+ 2.3. Limitations on Grant Scope
111
+
112
+ The licenses granted in this Section 2 are the only rights granted under
113
+ this License. No additional rights or licenses will be implied from the
114
+ distribution or licensing of Covered Software under this License.
115
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
116
+ Contributor:
117
+
118
+ (a) for any code that a Contributor has removed from Covered Software;
119
+ or
120
+
121
+ (b) for infringements caused by: (i) Your and any other third party's
122
+ modifications of Covered Software, or (ii) the combination of its
123
+ Contributions with other software (except as part of its Contributor
124
+ Version); or
125
+
126
+ (c) under Patent Claims infringed by Covered Software in the absence of
127
+ its Contributions.
128
+
129
+ This License does not grant any rights in the trademarks, service marks,
130
+ or logos of any Contributor (except as may be necessary to comply with
131
+ the notice requirements in Section 3.4).
132
+
133
+ 2.4. Subsequent Licenses
134
+
135
+ No Contributor makes additional grants as a result of Your choice to
136
+ distribute the Covered Software under a subsequent version of this
137
+ License (see Section 10.2) or under the terms of a Secondary License (if
138
+ permitted under the terms of Section 3.3).
139
+
140
+ 2.5. Representation
141
+
142
+ Each Contributor represents that the Contributor believes its
143
+ Contributions are its original creation(s) or it has sufficient rights
144
+ to grant the rights to its Contributions conveyed by this License.
145
+
146
+ 2.6. Fair Use
147
+
148
+ This License is not intended to limit any rights You have under
149
+ applicable copyright doctrines of fair use, fair dealing, or other
150
+ equivalents.
151
+
152
+ 2.7. Conditions
153
+
154
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
+ in Section 2.1.
156
+
157
+ 3. Responsibilities
158
+ -------------------
159
+
160
+ 3.1. Distribution of Source Form
161
+
162
+ All distribution of Covered Software in Source Code Form, including any
163
+ Modifications that You create or to which You contribute, must be under
164
+ the terms of this License. You must inform recipients that the Source
165
+ Code Form of the Covered Software is governed by the terms of this
166
+ License, and how they can obtain a copy of this License. You may not
167
+ attempt to alter or restrict the recipients' rights in the Source Code
168
+ Form.
169
+
170
+ 3.2. Distribution of Executable Form
171
+
172
+ If You distribute Covered Software in Executable Form then:
173
+
174
+ (a) such Covered Software must also be made available in Source Code
175
+ Form, as described in Section 3.1, and You must inform recipients of
176
+ the Executable Form how they can obtain a copy of such Source Code
177
+ Form by reasonable means in a timely manner, at a charge no more
178
+ than the cost of distribution to the recipient; and
179
+
180
+ (b) You may distribute such Executable Form under the terms of this
181
+ License, or sublicense it under different terms, provided that the
182
+ license for the Executable Form does not attempt to limit or alter
183
+ the recipients' rights in the Source Code Form under this License.
184
+
185
+ 3.3. Distribution of a Larger Work
186
+
187
+ You may create and distribute a Larger Work under terms of Your choice,
188
+ provided that You also comply with the requirements of this License for
189
+ the Covered Software. If the Larger Work is a combination of Covered
190
+ Software with a work governed by one or more Secondary Licenses, and the
191
+ Covered Software is not Incompatible With Secondary Licenses, this
192
+ License permits You to additionally distribute such Covered Software
193
+ under the terms of such Secondary License(s), so that the recipient of
194
+ the Larger Work may, at their option, further distribute the Covered
195
+ Software under the terms of either this License or such Secondary
196
+ License(s).
197
+
198
+ 3.4. Notices
199
+
200
+ You may not remove or alter the substance of any license notices
201
+ (including copyright notices, patent notices, disclaimers of warranty,
202
+ or limitations of liability) contained within the Source Code Form of
203
+ the Covered Software, except that You may alter any license notices to
204
+ the extent required to remedy known factual inaccuracies.
205
+
206
+ 3.5. Application of Additional Terms
207
+
208
+ You may choose to offer, and to charge a fee for, warranty, support,
209
+ indemnity or liability obligations to one or more recipients of Covered
210
+ Software. However, You may do so only on Your own behalf, and not on
211
+ behalf of any Contributor. You must make it absolutely clear that any
212
+ such warranty, support, indemnity, or liability obligation is offered by
213
+ You alone, and You hereby agree to indemnify every Contributor for any
214
+ liability incurred by such Contributor as a result of warranty, support,
215
+ indemnity or liability terms You offer. You may include additional
216
+ disclaimers of warranty and limitations of liability specific to any
217
+ jurisdiction.
218
+
219
+ 4. Inability to Comply Due to Statute or Regulation
220
+ ---------------------------------------------------
221
+
222
+ If it is impossible for You to comply with any of the terms of this
223
+ License with respect to some or all of the Covered Software due to
224
+ statute, judicial order, or regulation then You must: (a) comply with
225
+ the terms of this License to the maximum extent possible; and (b)
226
+ describe the limitations and the code they affect. Such description must
227
+ be placed in a text file included with all distributions of the Covered
228
+ Software under this License. Except to the extent prohibited by statute
229
+ or regulation, such description must be sufficiently detailed for a
230
+ recipient of ordinary skill to be able to understand it.
231
+
232
+ 5. Termination
233
+ --------------
234
+
235
+ 5.1. The rights granted under this License will terminate automatically
236
+ if You fail to comply with any of its terms. However, if You become
237
+ compliant, then the rights granted under this License from a particular
238
+ Contributor are reinstated (a) provisionally, unless and until such
239
+ Contributor explicitly and finally terminates Your grants, and (b) on an
240
+ ongoing basis, if such Contributor fails to notify You of the
241
+ non-compliance by some reasonable means prior to 60 days after You have
242
+ come back into compliance. Moreover, Your grants from a particular
243
+ Contributor are reinstated on an ongoing basis if such Contributor
244
+ notifies You of the non-compliance by some reasonable means, this is the
245
+ first time You have received notice of non-compliance with this License
246
+ from such Contributor, and You become compliant prior to 30 days after
247
+ Your receipt of the notice.
248
+
249
+ 5.2. If You initiate litigation against any entity by asserting a patent
250
+ infringement claim (excluding declaratory judgment actions,
251
+ counter-claims, and cross-claims) alleging that a Contributor Version
252
+ directly or indirectly infringes any patent, then the rights granted to
253
+ You by any and all Contributors for the Covered Software under Section
254
+ 2.1 of this License shall terminate.
255
+
256
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257
+ end user license agreements (excluding distributors and resellers) which
258
+ have been validly granted by You or Your distributors under this License
259
+ prior to termination shall survive termination.
260
+
261
+ ************************************************************************
262
+ * *
263
+ * 6. Disclaimer of Warranty *
264
+ * ------------------------- *
265
+ * *
266
+ * Covered Software is provided under this License on an "as is" *
267
+ * basis, without warranty of any kind, either expressed, implied, or *
268
+ * statutory, including, without limitation, warranties that the *
269
+ * Covered Software is free of defects, merchantable, fit for a *
270
+ * particular purpose or non-infringing. The entire risk as to the *
271
+ * quality and performance of the Covered Software is with You. *
272
+ * Should any Covered Software prove defective in any respect, You *
273
+ * (not any Contributor) assume the cost of any necessary servicing, *
274
+ * repair, or correction. This disclaimer of warranty constitutes an *
275
+ * essential part of this License. No use of any Covered Software is *
276
+ * authorized under this License except under this disclaimer. *
277
+ * *
278
+ ************************************************************************
279
+
280
+ ************************************************************************
281
+ * *
282
+ * 7. Limitation of Liability *
283
+ * -------------------------- *
284
+ * *
285
+ * Under no circumstances and under no legal theory, whether tort *
286
+ * (including negligence), contract, or otherwise, shall any *
287
+ * Contributor, or anyone who distributes Covered Software as *
288
+ * permitted above, be liable to You for any direct, indirect, *
289
+ * special, incidental, or consequential damages of any character *
290
+ * including, without limitation, damages for lost profits, loss of *
291
+ * goodwill, work stoppage, computer failure or malfunction, or any *
292
+ * and all other commercial damages or losses, even if such party *
293
+ * shall have been informed of the possibility of such damages. This *
294
+ * limitation of liability shall not apply to liability for death or *
295
+ * personal injury resulting from such party's negligence to the *
296
+ * extent applicable law prohibits such limitation. Some *
297
+ * jurisdictions do not allow the exclusion or limitation of *
298
+ * incidental or consequential damages, so this exclusion and *
299
+ * limitation may not apply to You. *
300
+ * *
301
+ ************************************************************************
302
+
303
+ 8. Litigation
304
+ -------------
305
+
306
+ Any litigation relating to this License may be brought only in the
307
+ courts of a jurisdiction where the defendant maintains its principal
308
+ place of business and such litigation shall be governed by laws of that
309
+ jurisdiction, without reference to its conflict-of-law provisions.
310
+ Nothing in this Section shall prevent a party's ability to bring
311
+ cross-claims or counter-claims.
312
+
313
+ 9. Miscellaneous
314
+ ----------------
315
+
316
+ This License represents the complete agreement concerning the subject
317
+ matter hereof. If any provision of this License is held to be
318
+ unenforceable, such provision shall be reformed only to the extent
319
+ necessary to make it enforceable. Any law or regulation which provides
320
+ that the language of a contract shall be construed against the drafter
321
+ shall not be used to construe this License against a Contributor.
322
+
323
+ 10. Versions of the License
324
+ ---------------------------
325
+
326
+ 10.1. New Versions
327
+
328
+ Mozilla Foundation is the license steward. Except as provided in Section
329
+ 10.3, no one other than the license steward has the right to modify or
330
+ publish new versions of this License. Each version will be given a
331
+ distinguishing version number.
332
+
333
+ 10.2. Effect of New Versions
334
+
335
+ You may distribute the Covered Software under the terms of the version
336
+ of the License under which You originally received the Covered Software,
337
+ or under the terms of any subsequent version published by the license
338
+ steward.
339
+
340
+ 10.3. Modified Versions
341
+
342
+ If you create software not governed by this License, and you want to
343
+ create a new license for such software, you may create and use a
344
+ modified version of this License if you rename the license and remove
345
+ any references to the name of the license steward (except to note that
346
+ such modified license differs from this License).
347
+
348
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
349
+ Licenses
350
+
351
+ If You choose to distribute Source Code Form that is Incompatible With
352
+ Secondary Licenses under the terms of this version of the License, the
353
+ notice described in Exhibit B of this License must be attached.
354
+
355
+ Exhibit A - Source Code Form License Notice
356
+ -------------------------------------------
357
+
358
+ This Source Code Form is subject to the terms of the Mozilla Public
359
+ License, v. 2.0. If a copy of the MPL was not distributed with this
360
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
361
+
362
+ If it is not possible or desirable to put the notice in a particular
363
+ file, then You may include the notice in a location (such as a LICENSE
364
+ file in a relevant directory) where a recipient would be likely to look
365
+ for such a notice.
366
+
367
+ You may add additional accurate notices of copyright ownership.
368
+
369
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
370
+ ---------------------------------------------------------
371
+
372
+ This Source Code Form is "Incompatible With Secondary Licenses", as
373
+ defined by the Mozilla Public License, v. 2.0.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @correctlyjs/schemars
2
+
3
+ Schemars format assertions for [Correctly](https://www.npmjs.com/package/correctly), with independently reviewed compatibility eras.
4
+
5
+ Install `correctly` and `@correctlyjs/schemars` in the project. Correctly 0.1.x provides the supported validator API; Node 22.18 or later is required.
6
+
7
+ ```ts
8
+ import { defineConfig } from "correctly"
9
+ import { ajv } from "correctly/validators/ajv"
10
+ import { schemars } from "@correctlyjs/schemars/ajv"
11
+
12
+ export default defineConfig({
13
+ associations: [
14
+ {
15
+ files: ["turbo.json"],
16
+ validate: ajv({
17
+ schema: "https://turbo.build/schema.json",
18
+ extensions: [schemars({ version: ">=0.8.15 <=0.8.22" })],
19
+ }),
20
+ },
21
+ ],
22
+ })
23
+ ```
24
+
25
+ The `version` option selects the upstream Schemars contract. It is independent of this package's npm version. Every stable upstream release requires a compatibility review and an extension release; Correctly core has its own release cadence. The CLI and editors use the same project-installed implementation.
26
+
27
+ The first era covers Schemars 0.8.15 through 0.8.22. Exact releases and closed ranges within one reviewed era are supported. Unknown versions, open ranges, and ranges crossing eras fail. Import `schemarsEras` and the `SchemarsEra`, `SchemarsVersion`, and `SchemarsVersionSelection` types from `@correctlyjs/schemars` to inspect the immutable TypeScript catalog and type reusable configuration. The factory accepts only reviewed releases and ordered ranges within one era at compile time, and checks them again at runtime. The Ajv factory lives at `@correctlyjs/schemars/ajv` and returns `AjvExtension` from `correctly/validators/ajv`.
28
+
29
+ See the [guide](docs/guide.md) for all 24 format assertions and precision limits, and the [maintainer workflow](https://github.com/jeremybanka/correctly/blob/main/packages/schemars/tests/public/fixtures/README.md) for pinned Rust generators and release review. Consumers do not need Rust.
package/dist/ajv.d.mts ADDED
@@ -0,0 +1,9 @@
1
+ import { r as SchemarsVersionSelection } from "./eras-BDoQsmuP.mjs";
2
+ import { AjvExtension } from "correctly/validators/ajv";
3
+ //#region src/ajv.d.ts
4
+ /** Select one reviewed schema contract, using an exact release or closed range. */
5
+ export declare function schemars(options: {
6
+ version: SchemarsVersionSelection;
7
+ }): AjvExtension;
8
+ //#endregion
9
+ //# sourceMappingURL=ajv.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ajv.d.mts","names":[],"sources":["../src/ajv.ts"],"mappings":";;;;wBA+DgB,SAAS;EACxB,SAAS;IACN"}
package/dist/ajv.mjs ADDED
@@ -0,0 +1,106 @@
1
+ import { t as schemarsEras } from "./eras-CSKjWAIy.mjs";
2
+ import { isIP } from "node:net";
3
+ //#region src/select-era.ts
4
+ function compareVersions(left, right) {
5
+ const a = left.split(".").map(Number), b = right.split(".").map(Number);
6
+ for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] - b[i];
7
+ return 0;
8
+ }
9
+ const VERSION = "(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)";
10
+ const EXACT = new RegExp(`^${VERSION}$`);
11
+ const RANGE = new RegExp(`^>=(${VERSION}) <=(${VERSION})$`);
12
+ function selectSchemarsEra(selection, eras = schemarsEras) {
13
+ const range = typeof selection === "string" ? RANGE.exec(selection) : null;
14
+ const from = range?.[1] ?? selection, through = range?.[2] ?? selection;
15
+ if (typeof from !== "string" || !EXACT.test(from) || !EXACT.test(through) || compareVersions(from, through) > 0) throw new Error(`Unsupported Schemars version selection: ${JSON.stringify(selection)}. Use an exact reviewed release or a closed range such as ">=0.8.15 <=0.8.22".`);
16
+ const first = eras.find((era) => era.versions.includes(from)), last = eras.find((era) => era.versions.includes(through));
17
+ if (!first || !last) throw new Error(`Unsupported Schemars version selection: ${JSON.stringify(selection)}. Reviewed eras: ${eras.map((era) => `${era.since}–${era.versions.at(-1)}`).join(", ")}. Unreviewed releases are not enabled implicitly.`);
18
+ if (first !== last) throw new Error(`Schemars range ${JSON.stringify(selection)} crosses compatibility eras. Select releases from one era to avoid combining different validation semantics.`);
19
+ return first;
20
+ }
21
+ //#endregion
22
+ //#region src/ajv.ts
23
+ const formats = {};
24
+ for (const bits of [
25
+ 8,
26
+ 16,
27
+ 32,
28
+ 64,
29
+ 128
30
+ ]) {
31
+ formats[`int${bits}`] = {
32
+ type: "number",
33
+ validate: (value) => Number.isInteger(value) && value >= -(2 ** (bits - 1)) && value < 2 ** (bits - 1)
34
+ };
35
+ formats[`uint${bits}`] = {
36
+ type: "number",
37
+ validate: (value) => Number.isInteger(value) && value >= 0 && value < 2 ** bits
38
+ };
39
+ }
40
+ formats.int = {
41
+ type: "number",
42
+ validate: Number.isInteger
43
+ };
44
+ formats.uint = {
45
+ type: "number",
46
+ validate: (value) => Number.isInteger(value) && value >= 0
47
+ };
48
+ formats.float = {
49
+ type: "number",
50
+ validate: (value) => Number.isFinite(value) && Math.abs(value) <= (2 - 2 ** -23) * 2 ** 127
51
+ };
52
+ formats.double = {
53
+ type: "number",
54
+ validate: Number.isFinite
55
+ };
56
+ formats.ip = {
57
+ type: "string",
58
+ validate: (value) => isIP(value) !== 0
59
+ };
60
+ formats.phone = {
61
+ type: "string",
62
+ validate: (value) => /^\+[1-9]\d{1,14}$/.test(value)
63
+ };
64
+ function partialDateTime(value) {
65
+ const match = /^(?:(\d{4})-(\d{2})-(\d{2})T)?(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?$/.exec(value);
66
+ if (!match) return false;
67
+ const [, year, month, day, hour, minute, second] = match;
68
+ if (Number(hour) > 23 || Number(minute) > 59 || Number(second) > 60) return false;
69
+ if (second === "60" && minute !== "59") return false;
70
+ if (year === void 0) return true;
71
+ const y = Number(year), m = Number(month), d = Number(day);
72
+ const days = [
73
+ 31,
74
+ y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0) ? 29 : 28,
75
+ 31,
76
+ 30,
77
+ 31,
78
+ 30,
79
+ 31,
80
+ 31,
81
+ 30,
82
+ 31,
83
+ 30,
84
+ 31
85
+ ];
86
+ return m >= 1 && m <= 12 && d >= 1 && d <= days[m - 1];
87
+ }
88
+ formats["partial-date-time"] = {
89
+ type: "string",
90
+ validate: partialDateTime
91
+ };
92
+ const implementations = { "0.8.15": formats };
93
+ /** Select one reviewed schema contract, using an exact release or closed range. */
94
+ function schemars(options) {
95
+ const era = selectSchemarsEra(options.version);
96
+ const implementation = implementations[era.since];
97
+ if (!implementation) throw new Error(`Schemars era ${era.since} has no validator implementation`);
98
+ return {
99
+ id: `schemars@${options.version}`,
100
+ formats: implementation
101
+ };
102
+ }
103
+ //#endregion
104
+ export { schemars };
105
+
106
+ //# sourceMappingURL=ajv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ajv.mjs","names":[],"sources":["../src/select-era.ts","../src/ajv.ts"],"sourcesContent":["import { schemarsEras, type EraDefinition, type SchemarsEra } from \"./eras.ts\"\n\nexport function compareVersions(left: string, right: string): number {\n\tconst a = left.split(\".\").map(Number),\n\t\tb = right.split(\".\").map(Number)\n\tfor (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i]! - b[i]!\n\treturn 0\n}\nconst VERSION = \"(?:0|[1-9][0-9]*)\\\\.(?:0|[1-9][0-9]*)\\\\.(?:0|[1-9][0-9]*)\"\nconst EXACT = new RegExp(`^${VERSION}$`)\nconst RANGE = new RegExp(`^>=(${VERSION}) <=(${VERSION})$`)\nexport function selectSchemarsEra(selection: string): SchemarsEra\nexport function selectSchemarsEra<Era extends EraDefinition>(\n\tselection: string,\n\teras: readonly Era[],\n): Era\nexport function selectSchemarsEra(\n\tselection: string,\n\teras: readonly EraDefinition[] = schemarsEras,\n): EraDefinition {\n\tconst range = typeof selection === \"string\" ? RANGE.exec(selection) : null\n\tconst from = range?.[1] ?? selection,\n\t\tthrough = range?.[2] ?? selection\n\tif (\n\t\ttypeof from !== \"string\" ||\n\t\t!EXACT.test(from) ||\n\t\t!EXACT.test(through) ||\n\t\tcompareVersions(from, through) > 0\n\t)\n\t\tthrow new Error(\n\t\t\t`Unsupported Schemars version selection: ${JSON.stringify(selection)}. Use an exact reviewed release or a closed range such as \">=0.8.15 <=0.8.22\".`,\n\t\t)\n\tconst first = eras.find((era) => era.versions.includes(from)),\n\t\tlast = eras.find((era) => era.versions.includes(through))\n\tif (!first || !last)\n\t\tthrow new Error(\n\t\t\t`Unsupported Schemars version selection: ${JSON.stringify(selection)}. Reviewed eras: ${eras.map((era) => `${era.since}–${era.versions.at(-1)}`).join(\", \")}. Unreviewed releases are not enabled implicitly.`,\n\t\t)\n\tif (first !== last)\n\t\tthrow new Error(\n\t\t\t`Schemars range ${JSON.stringify(selection)} crosses compatibility eras. Select releases from one era to avoid combining different validation semantics.`,\n\t\t)\n\treturn first\n}\n","import { isIP } from \"node:net\"\nimport { selectSchemarsEra } from \"./select-era.ts\"\nimport type { SchemarsEra, SchemarsVersionSelection } from \"./eras.ts\"\nimport type { AjvExtension } from \"correctly/validators/ajv\"\n\nconst formats: Record<string, NonNullable<AjvExtension[\"formats\"]>[string]> = {}\nfor (const bits of [8, 16, 32, 64, 128]) {\n\tformats[`int${bits}`] = {\n\t\ttype: \"number\",\n\t\tvalidate: (value: number) =>\n\t\t\tNumber.isInteger(value) &&\n\t\t\tvalue >= -(2 ** (bits - 1)) &&\n\t\t\tvalue < 2 ** (bits - 1),\n\t}\n\tformats[`uint${bits}`] = {\n\t\ttype: \"number\",\n\t\tvalidate: (value: number) =>\n\t\t\tNumber.isInteger(value) && value >= 0 && value < 2 ** bits,\n\t}\n}\nformats.int = { type: \"number\", validate: Number.isInteger }\nformats.uint = {\n\ttype: \"number\",\n\tvalidate: (value: number) => Number.isInteger(value) && value >= 0,\n}\nformats.float = {\n\ttype: \"number\",\n\tvalidate: (value: number) =>\n\t\tNumber.isFinite(value) && Math.abs(value) <= (2 - 2 ** -23) * 2 ** 127,\n}\nformats.double = { type: \"number\", validate: Number.isFinite }\nformats.ip = { type: \"string\", validate: (value: string) => isIP(value) !== 0 }\nformats.phone = {\n\ttype: \"string\",\n\tvalidate: (value: string) => /^\\+[1-9]\\d{1,14}$/.test(value),\n}\n\nfunction partialDateTime(value: string): boolean {\n\t// 0.8.22 assigns this format to BOTH NaiveDateTime and NaiveTime.\n\tconst match =\n\t\t/^(?:(\\d{4})-(\\d{2})-(\\d{2})T)?(\\d{2}):(\\d{2}):(\\d{2})(?:\\.\\d{1,9})?$/.exec(\n\t\t\tvalue,\n\t\t)\n\tif (!match) return false\n\tconst [, year, month, day, hour, minute, second] = match\n\tif (Number(hour) > 23 || Number(minute) > 59 || Number(second) > 60)\n\t\treturn false\n\tif (second === \"60\" && minute !== \"59\") return false\n\tif (year === undefined) return true\n\tconst y = Number(year),\n\t\tm = Number(month),\n\t\td = Number(day)\n\tconst leap = y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0)\n\tconst days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n\treturn m >= 1 && m <= 12 && d >= 1 && d <= days[m - 1]!\n}\nformats[\"partial-date-time\"] = { type: \"string\", validate: partialDateTime }\n\nconst implementations = {\n\t\"0.8.15\": formats,\n} satisfies Record<SchemarsEra[\"since\"], typeof formats>\n\n/** Select one reviewed schema contract, using an exact release or closed range. */\nexport function schemars(options: {\n\tversion: SchemarsVersionSelection\n}): AjvExtension {\n\tconst era = selectSchemarsEra(options.version)\n\tconst implementation = implementations[era.since]\n\tif (!implementation)\n\t\tthrow new Error(`Schemars era ${era.since} has no validator implementation`)\n\treturn { id: `schemars@${options.version}`, formats: implementation }\n}\n"],"mappings":"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"}
@@ -0,0 +1,24 @@
1
+ //#region src/eras.d.ts
2
+ /** Structural shape used when checking historical or candidate catalogs. */
3
+ type EraDefinition = {
4
+ readonly since: string;
5
+ readonly versions: readonly string[];
6
+ };
7
+ /** Reviewed releases, grouped by identical generated schema contracts.
8
+ * Keep this module self-contained: CI loads it from both Git revisions.
9
+ */
10
+ declare const schemarsEras: readonly [Readonly<{
11
+ since: "0.8.15";
12
+ versions: readonly ["0.8.15", "0.8.16", "0.8.17", "0.8.18", "0.8.19", "0.8.20", "0.8.21", "0.8.22"];
13
+ }>];
14
+ /** One of the compatibility eras reviewed by this package. */
15
+ type SchemarsEra = (typeof schemarsEras)[number];
16
+ /** An exact reviewed upstream release. */
17
+ type SchemarsVersion = SchemarsEra["versions"][number];
18
+ type ClosedRanges<Versions extends readonly string[], Ranges extends string = never> = Versions extends readonly [infer First extends string, ...infer Rest extends readonly string[]] ? ClosedRanges<Rest, Ranges | `>=${First} <=${Versions[number]}`> : Ranges;
19
+ type VersionSelection<Era extends EraDefinition> = Era extends EraDefinition ? Era["versions"][number] | ClosedRanges<Era["versions"]> : never;
20
+ /** An exact reviewed release or an ordered, inclusive range within one era. */
21
+ type SchemarsVersionSelection = VersionSelection<SchemarsEra>;
22
+ //#endregion
23
+ export { schemarsEras as i, SchemarsVersion as n, SchemarsVersionSelection as r, SchemarsEra as t };
24
+ //# sourceMappingURL=eras-BDoQsmuP.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eras-BDoQsmuP.d.mts","names":[],"sources":["../src/eras.ts"],"mappings":";;KACY;WACF;WACA;;;;;cAMG,wBAAY;;;;;KAiBb,sBAAsB;;KAEtB,kBAAkB;KAGzB,aACJ,oCACA,iCACG,iCACG,+BACG,kCAEP,aAAa,MAAM,cAAc,WAAW,sBAC5C;KAGS,iBAAiB,YAAY,iBACxC,YAAY,gBACT,0BAA0B,aAAa;;KAI/B,2BAA2B,iBAAiB"}
@@ -0,0 +1,21 @@
1
+ //#region src/eras.ts
2
+ /** Reviewed releases, grouped by identical generated schema contracts.
3
+ * Keep this module self-contained: CI loads it from both Git revisions.
4
+ */
5
+ const schemarsEras = Object.freeze([Object.freeze({
6
+ since: "0.8.15",
7
+ versions: Object.freeze([
8
+ "0.8.15",
9
+ "0.8.16",
10
+ "0.8.17",
11
+ "0.8.18",
12
+ "0.8.19",
13
+ "0.8.20",
14
+ "0.8.21",
15
+ "0.8.22"
16
+ ])
17
+ })]);
18
+ //#endregion
19
+ export { schemarsEras as t };
20
+
21
+ //# sourceMappingURL=eras-CSKjWAIy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eras-CSKjWAIy.mjs","names":[],"sources":["../src/eras.ts"],"sourcesContent":["/** Structural shape used when checking historical or candidate catalogs. */\nexport type EraDefinition = {\n\treadonly since: string\n\treadonly versions: readonly string[]\n}\n\n/** Reviewed releases, grouped by identical generated schema contracts.\n * Keep this module self-contained: CI loads it from both Git revisions.\n */\nexport const schemarsEras = Object.freeze([\n\tObject.freeze({\n\t\tsince: \"0.8.15\",\n\t\tversions: Object.freeze([\n\t\t\t\"0.8.15\",\n\t\t\t\"0.8.16\",\n\t\t\t\"0.8.17\",\n\t\t\t\"0.8.18\",\n\t\t\t\"0.8.19\",\n\t\t\t\"0.8.20\",\n\t\t\t\"0.8.21\",\n\t\t\t\"0.8.22\",\n\t\t] as const),\n\t}),\n] as const satisfies readonly EraDefinition[])\n\n/** One of the compatibility eras reviewed by this package. */\nexport type SchemarsEra = (typeof schemarsEras)[number]\n/** An exact reviewed upstream release. */\nexport type SchemarsVersion = SchemarsEra[\"versions\"][number]\n\n// The ordered tuple supplies each lower bound and only upper bounds at or after it.\ntype ClosedRanges<\n\tVersions extends readonly string[],\n\tRanges extends string = never,\n> = Versions extends readonly [\n\tinfer First extends string,\n\t...infer Rest extends readonly string[],\n]\n\t? ClosedRanges<Rest, Ranges | `>=${First} <=${Versions[number]}`>\n\t: Ranges\n\n// Distribute over eras before constructing ranges so they cannot cross eras.\nexport type VersionSelection<Era extends EraDefinition> =\n\tEra extends EraDefinition\n\t\t? Era[\"versions\"][number] | ClosedRanges<Era[\"versions\"]>\n\t\t: never\n\n/** An exact reviewed release or an ordered, inclusive range within one era. */\nexport type SchemarsVersionSelection = VersionSelection<SchemarsEra>\n"],"mappings":";;;;AASA,MAAa,eAAe,OAAO,OAAO,CACzC,OAAO,OAAO;CACb,OAAO;CACP,UAAU,OAAO,OAAO;EACvB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,CAAU;AACX,CAAC,CACF,CAA6C"}
@@ -0,0 +1,2 @@
1
+ import { i as schemarsEras, n as SchemarsVersion, r as SchemarsVersionSelection, t as SchemarsEra } from "./eras-BDoQsmuP.mjs";
2
+ export { type SchemarsEra, type SchemarsVersion, type SchemarsVersionSelection, schemarsEras };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { t as schemarsEras } from "./eras-CSKjWAIy.mjs";
2
+ export { schemarsEras };
package/docs/guide.md ADDED
@@ -0,0 +1,39 @@
1
+ # Schemars compatibility guide
2
+
3
+ Import the `schemars` factory from `@correctlyjs/schemars/ajv`. It implements `AjvExtension` from `correctly/validators/ajv`. The package root exports the `schemarsEras` catalog and the `SchemarsEra`, `SchemarsVersion`, and `SchemarsVersionSelection` types.
4
+
5
+ `schemars({ version: "0.8.22" })` selects an exact reviewed upstream Schemars release. `schemars({ version: ">=0.8.15 <=0.8.22" })` selects a closed range within one compatibility era. The first era contains **0.8.15, 0.8.16, 0.8.17, 0.8.18, 0.8.19, 0.8.20, 0.8.21, and 0.8.22**: all eight independently pinned generators and matching derive crates produce the same 74 schemas. The exported, immutable `schemarsEras` catalog lists every reviewed release and its era's starting version.
6
+
7
+ The required `version` argument accepts exactly `major.minor.patch` or `>=major.minor.patch <=major.minor.patch` (one space, inclusive bounds). Both endpoints must be reviewed releases in the same era. Reversed bounds, prereleases, caret/tilde ranges, wildcards, open ranges, unreviewed endpoints, and ranges crossing eras are rejected. Future releases never become supported implicitly. Diagnostic IDs preserve the selection, for example `schemars@>=0.8.15 <=0.8.22`. The selection is an explicit compatibility assertion by the configuration author; Correctly cannot infer which Schemars release generated a schema.
8
+
9
+ The catalog lives in TypeScript as a deeply frozen literal tuple. `SchemarsEra` is the union of its actual entries, `SchemarsVersion` is the union of exact reviewed releases, and `SchemarsVersionSelection` also includes ordered, inclusive ranges within each era. `schemars({ version })` uses that selection type, so editors suggest supported selections and TypeScript rejects unreviewed versions, reversed bounds, and ranges crossing eras. Adding a reviewed release updates the types from the same data; adding an era also requires its Ajv implementation at compile time. Runtime checks remain in place for JavaScript callers and values that bypass static typing.
10
+
11
+ When storing a selection in a separate options object, use `satisfies { version: SchemarsVersionSelection }` or a const assertion to preserve its literal type. An arbitrary `string` is deliberately not accepted as a reviewed selection.
12
+
13
+ An era is a frozen generated-schema contract with its own validation semantics. Extending an era adds a tested release without changing those semantics; changed generated schemas require a new era beginning at that release. Each newly reviewed stable Schemars release requires a new @correctlyjs/schemars release, even when schemas are identical. This policy concerns upstream emitted formats, not Rust execution or identical Serde deserialization. Releases outside the catalog and forks, including `oxc-schemars`, are not covered by the upstream pins; schemas using the same vocabulary can explicitly opt into the documented contract.
14
+
15
+ The complete format inventory is below. Numeric predicates apply to numbers and string predicates to strings, following JSON Schema's format semantics; other instance types require the schema's `type` constraint. All numeric bounds are evaluated on parsed JavaScript numbers.
16
+
17
+ | Emitted format | Origin | Assertion |
18
+ | ------------------------------------------------ | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19
+ | `int8`, `int16`, `int32`, `int64`, `int128` | `i8` through `i128` | Integer in −2ⁿ⁻¹ ≤ x < 2ⁿ⁻¹ for the named width n. |
20
+ | `uint8`, `uint16`, `uint32`, `uint64`, `uint128` | `u8` through `u128` | Integer in 0 ≤ x < 2ⁿ for the named width n. |
21
+ | `int`, `uint` | `isize`, `usize` | Integer; `uint` additionally requires x ≥ 0. No target architecture is encoded, so no platform width is inferred. |
22
+ | `float` | `f32` | Finite number with absolute value ≤ (2 − 2⁻²³) × 2¹²⁷. No exact binary32 representability or minimum nonzero magnitude is required. |
23
+ | `double` | `f64` | Finite JavaScript number. |
24
+ | `ip` | `IpAddr` | IPv4 or IPv6 literal, checked by Node's `net.isIP`; no hostname lookup. |
25
+ | `ipv4`, `ipv6` | `Ipv4Addr`, `Ipv6Addr` | The corresponding ajv-formats 3.0.1 full-mode assertion. |
26
+ | `date`, `date-time` | Chrono `NaiveDate`, `DateTime` | ajv-formats 3.0.1 full-mode assertions; dates use four-digit years and date-times require a timezone. |
27
+ | `partial-date-time` | Chrono `NaiveDateTime` **and** `NaiveTime` | Either `YYYY-MM-DDTHH:MM:SS` or `HH:MM:SS`, optionally followed by 1–9 fractional digits, with no timezone. Gregorian date validity, hours 00–23, minutes 00–59, seconds 00–59 or leap second 60 when the minute is 59. Years 0000–9999. |
28
+ | `uuid` | UUID 0.8 and 1 integrations | ajv-formats 3.0.1 full-mode UUID assertion. |
29
+ | `uri` | URL integration and derive `url` | ajv-formats 3.0.1 full-mode URI assertion. |
30
+ | `email` | Derive `email` | ajv-formats 3.0.1 full-mode email assertion. |
31
+ | `phone` | Derive `phone` | Canonical international syntax: `+` followed by 2–15 ASCII digits, first digit nonzero. No spaces, local-number inference, country allocation database, or reachability check. |
32
+
33
+ This accounts for **all 24 distinct emitted format names**, including optional integrations and derive attributes. Nonzero types preserve their generated minimum/not-zero constraints. Atomic types, collections, and other wrappers use the same underlying formats. Decimal integrations emit a standard string pattern, semver emits a standard pattern, and remaining integrations add no new formats.
34
+
35
+ Some names do not encode enough information to reproduce a Rust type. The `partial-date-time` assertion accepts the union because this era assigns the same name to both date-times and times; it cannot distinguish them. Standard `date`/`date-time` format behavior and the four-digit-year policy do not cover Chrono's extended-year serialization. Schemars emits `phone` without specifying a numbering policy; the syntax above is Correctly's explicit interpretation, not a promise to reproduce a particular Rust phone library. Custom `JsonSchema` implementations, `schema_with` callbacks, arbitrary format names, and OpenAPI generator settings are outside this finite compatibility contract and need their own extensions where applicable. This era's normal generated draft-7 schemas are tested directly; extension assertions also work in Correctly's draft-2020-12 engine. This does not add draft-2019-09 or OpenAPI dialect support.
36
+
37
+ **Numeric precision:** parsing still uses IEEE-754 binary64. Integers above 2⁵³−1 can round before any schema assertion, including 64/128-bit bounds, runs. For example, the valid Rust `u64` value `18446744073709551615` rounds to 2⁶⁴ and fails the upper bound. Smaller in-range integers may round and still pass. This extension does not offer lossless large-integer validation. Store exact large quantities as strings with an appropriate schema when exact decimal digits matter.
38
+
39
+ Each reviewed release has its own exact Cargo manifest and lockfile, with every optional integration enabled and the matching derive crate locked. `pnpm test:schemars` runs all eight historical generators with `cargo run --locked`, comparing their 592 schemas structurally against the shared era corpus; it also checks Renovate's separate candidate probe. Public tests compile the corpus and exercise positive/negative cases for every emitted format in both supported dialects, integer boundaries, nonzero/nested types, association isolation, CLI/LSP agreement, and version/range selection. Rust is a development dependency only. The [maintainer workflow](https://github.com/jeremybanka/correctly/blob/main/packages/schemars/tests/public/fixtures/README.md) documents the required CI review and release steps.
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@correctlyjs/schemars",
3
+ "version": "0.0.0",
4
+ "description": "Reviewed Schemars compatibility eras for Correctly",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/jeremybanka/correctly.git",
8
+ "directory": "packages/schemars"
9
+ },
10
+ "license": "MPL-2.0",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.mts",
15
+ "import": "./dist/index.mjs"
16
+ },
17
+ "./ajv": {
18
+ "types": "./dist/ajv.d.mts",
19
+ "import": "./dist/ajv.mjs"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "src",
25
+ "docs",
26
+ "LICENSE",
27
+ "README.md",
28
+ "AGENTS.md"
29
+ ],
30
+ "scripts": {
31
+ "build": "vp pack",
32
+ "test": "vp test",
33
+ "test:watch": "vp test watch",
34
+ "test:distribution": "vp test tests/private/distribution.test.ts"
35
+ },
36
+ "devDependencies": {
37
+ "correctly": "workspace:*"
38
+ },
39
+ "peerDependencies": {
40
+ "correctly": "^0.1.0"
41
+ },
42
+ "engines": {
43
+ "node": ">=22.18.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }
package/src/ajv.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { isIP } from "node:net"
2
+ import { selectSchemarsEra } from "./select-era.ts"
3
+ import type { SchemarsEra, SchemarsVersionSelection } from "./eras.ts"
4
+ import type { AjvExtension } from "correctly/validators/ajv"
5
+
6
+ const formats: Record<string, NonNullable<AjvExtension["formats"]>[string]> = {}
7
+ for (const bits of [8, 16, 32, 64, 128]) {
8
+ formats[`int${bits}`] = {
9
+ type: "number",
10
+ validate: (value: number) =>
11
+ Number.isInteger(value) &&
12
+ value >= -(2 ** (bits - 1)) &&
13
+ value < 2 ** (bits - 1),
14
+ }
15
+ formats[`uint${bits}`] = {
16
+ type: "number",
17
+ validate: (value: number) =>
18
+ Number.isInteger(value) && value >= 0 && value < 2 ** bits,
19
+ }
20
+ }
21
+ formats.int = { type: "number", validate: Number.isInteger }
22
+ formats.uint = {
23
+ type: "number",
24
+ validate: (value: number) => Number.isInteger(value) && value >= 0,
25
+ }
26
+ formats.float = {
27
+ type: "number",
28
+ validate: (value: number) =>
29
+ Number.isFinite(value) && Math.abs(value) <= (2 - 2 ** -23) * 2 ** 127,
30
+ }
31
+ formats.double = { type: "number", validate: Number.isFinite }
32
+ formats.ip = { type: "string", validate: (value: string) => isIP(value) !== 0 }
33
+ formats.phone = {
34
+ type: "string",
35
+ validate: (value: string) => /^\+[1-9]\d{1,14}$/.test(value),
36
+ }
37
+
38
+ function partialDateTime(value: string): boolean {
39
+ // 0.8.22 assigns this format to BOTH NaiveDateTime and NaiveTime.
40
+ const match =
41
+ /^(?:(\d{4})-(\d{2})-(\d{2})T)?(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?$/.exec(
42
+ value,
43
+ )
44
+ if (!match) return false
45
+ const [, year, month, day, hour, minute, second] = match
46
+ if (Number(hour) > 23 || Number(minute) > 59 || Number(second) > 60)
47
+ return false
48
+ if (second === "60" && minute !== "59") return false
49
+ if (year === undefined) return true
50
+ const y = Number(year),
51
+ m = Number(month),
52
+ d = Number(day)
53
+ const leap = y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0)
54
+ const days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
55
+ return m >= 1 && m <= 12 && d >= 1 && d <= days[m - 1]!
56
+ }
57
+ formats["partial-date-time"] = { type: "string", validate: partialDateTime }
58
+
59
+ const implementations = {
60
+ "0.8.15": formats,
61
+ } satisfies Record<SchemarsEra["since"], typeof formats>
62
+
63
+ /** Select one reviewed schema contract, using an exact release or closed range. */
64
+ export function schemars(options: {
65
+ version: SchemarsVersionSelection
66
+ }): AjvExtension {
67
+ const era = selectSchemarsEra(options.version)
68
+ const implementation = implementations[era.since]
69
+ if (!implementation)
70
+ throw new Error(`Schemars era ${era.since} has no validator implementation`)
71
+ return { id: `schemars@${options.version}`, formats: implementation }
72
+ }
package/src/eras.ts ADDED
@@ -0,0 +1,49 @@
1
+ /** Structural shape used when checking historical or candidate catalogs. */
2
+ export type EraDefinition = {
3
+ readonly since: string
4
+ readonly versions: readonly string[]
5
+ }
6
+
7
+ /** Reviewed releases, grouped by identical generated schema contracts.
8
+ * Keep this module self-contained: CI loads it from both Git revisions.
9
+ */
10
+ export const schemarsEras = Object.freeze([
11
+ Object.freeze({
12
+ since: "0.8.15",
13
+ versions: Object.freeze([
14
+ "0.8.15",
15
+ "0.8.16",
16
+ "0.8.17",
17
+ "0.8.18",
18
+ "0.8.19",
19
+ "0.8.20",
20
+ "0.8.21",
21
+ "0.8.22",
22
+ ] as const),
23
+ }),
24
+ ] as const satisfies readonly EraDefinition[])
25
+
26
+ /** One of the compatibility eras reviewed by this package. */
27
+ export type SchemarsEra = (typeof schemarsEras)[number]
28
+ /** An exact reviewed upstream release. */
29
+ export type SchemarsVersion = SchemarsEra["versions"][number]
30
+
31
+ // The ordered tuple supplies each lower bound and only upper bounds at or after it.
32
+ type ClosedRanges<
33
+ Versions extends readonly string[],
34
+ Ranges extends string = never,
35
+ > = Versions extends readonly [
36
+ infer First extends string,
37
+ ...infer Rest extends readonly string[],
38
+ ]
39
+ ? ClosedRanges<Rest, Ranges | `>=${First} <=${Versions[number]}`>
40
+ : Ranges
41
+
42
+ // Distribute over eras before constructing ranges so they cannot cross eras.
43
+ export type VersionSelection<Era extends EraDefinition> =
44
+ Era extends EraDefinition
45
+ ? Era["versions"][number] | ClosedRanges<Era["versions"]>
46
+ : never
47
+
48
+ /** An exact reviewed release or an ordered, inclusive range within one era. */
49
+ export type SchemarsVersionSelection = VersionSelection<SchemarsEra>
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export {
2
+ schemarsEras,
3
+ type SchemarsEra,
4
+ type SchemarsVersion,
5
+ type SchemarsVersionSelection,
6
+ } from "./eras.ts"
@@ -0,0 +1,44 @@
1
+ import { schemarsEras, type EraDefinition, type SchemarsEra } from "./eras.ts"
2
+
3
+ export function compareVersions(left: string, right: string): number {
4
+ const a = left.split(".").map(Number),
5
+ b = right.split(".").map(Number)
6
+ for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i]! - b[i]!
7
+ return 0
8
+ }
9
+ const VERSION = "(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)"
10
+ const EXACT = new RegExp(`^${VERSION}$`)
11
+ const RANGE = new RegExp(`^>=(${VERSION}) <=(${VERSION})$`)
12
+ export function selectSchemarsEra(selection: string): SchemarsEra
13
+ export function selectSchemarsEra<Era extends EraDefinition>(
14
+ selection: string,
15
+ eras: readonly Era[],
16
+ ): Era
17
+ export function selectSchemarsEra(
18
+ selection: string,
19
+ eras: readonly EraDefinition[] = schemarsEras,
20
+ ): EraDefinition {
21
+ const range = typeof selection === "string" ? RANGE.exec(selection) : null
22
+ const from = range?.[1] ?? selection,
23
+ through = range?.[2] ?? selection
24
+ if (
25
+ typeof from !== "string" ||
26
+ !EXACT.test(from) ||
27
+ !EXACT.test(through) ||
28
+ compareVersions(from, through) > 0
29
+ )
30
+ throw new Error(
31
+ `Unsupported Schemars version selection: ${JSON.stringify(selection)}. Use an exact reviewed release or a closed range such as ">=0.8.15 <=0.8.22".`,
32
+ )
33
+ const first = eras.find((era) => era.versions.includes(from)),
34
+ last = eras.find((era) => era.versions.includes(through))
35
+ if (!first || !last)
36
+ throw new Error(
37
+ `Unsupported Schemars version selection: ${JSON.stringify(selection)}. Reviewed eras: ${eras.map((era) => `${era.since}–${era.versions.at(-1)}`).join(", ")}. Unreviewed releases are not enabled implicitly.`,
38
+ )
39
+ if (first !== last)
40
+ throw new Error(
41
+ `Schemars range ${JSON.stringify(selection)} crosses compatibility eras. Select releases from one era to avoid combining different validation semantics.`,
42
+ )
43
+ return first
44
+ }