@json-schema-engine/dialect-draft04 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Henry Andrews
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @json-schema-engine/dialect-draft04
2
+
3
+ JSON Schema draft-04 dialect for `@json-schema-engine/core`, assembled entirely through core's public dialect-authoring surface. draft-04's syntax differs from every later draft — `id` instead of `$id`, boolean `exclusiveMinimum`/`exclusiveMaximum` modifying sibling bounds, no `const`, `contains`, `propertyNames`, or `if`/`then`/`else` — so it ships separately rather than in core. Add this package when you need to validate draft-04 documents; they can coexist with every other draft in the same registry, including `$ref`s across the dialect boundary. Needs `@json-schema-engine/core` installed alongside.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @json-schema-engine/dialect-draft04 @json-schema-engine/core
9
+ ```
10
+
11
+ ## Example
12
+
13
+ ```ts
14
+ import assert from "node:assert";
15
+ import { createEngine } from "@json-schema-engine/core";
16
+ import { registerDraft04 } from "@json-schema-engine/dialect-draft04";
17
+
18
+ const engine = createEngine();
19
+ registerDraft04(engine);
20
+
21
+ const uri = engine.registerSchema(
22
+ {
23
+ $schema: "http://json-schema.org/draft-04/schema#",
24
+ minimum: 5,
25
+ exclusiveMinimum: true, // draft-04: a boolean modifying `minimum`
26
+ },
27
+ "https://example.com/draft-04",
28
+ );
29
+
30
+ assert.equal(engine.evaluate(uri, 5).valid, false);
31
+ assert.equal(engine.evaluate(uri, 6).valid, true);
32
+ ```
33
+
34
+ ## Status
35
+
36
+ Version 0.0.1 is published for initial public feedback on both the functionality and the documentation. APIs may change before 1.0. [STATUS.md](https://github.com/handrews/json-schema-engine/blob/main/STATUS.md) is the authoritative statement of what is built and what is staged.
37
+
38
+ ## Documentation
39
+
40
+ - [User guide](https://github.com/handrews/json-schema-engine/blob/main/docs/guide/index.md)
41
+ - [Dialects](https://github.com/handrews/json-schema-engine/blob/main/docs/guide/dialects.md)
42
+ - [Conformance](https://github.com/handrews/json-schema-engine/blob/main/docs/conformance.md)
43
+ - [Repository](https://github.com/handrews/json-schema-engine)
44
+
45
+ ## License
46
+
47
+ MIT
@@ -0,0 +1,24 @@
1
+ import { Engine, IdentifierExtractor } from "@json-schema-engine/core";
2
+ /** draft-04 dialect URI. */
3
+ export declare const DIALECT_DRAFT_04 = "http://json-schema.org/draft-04/schema";
4
+ /**
5
+ * draft-04 vocabulary identity (registry-internal; draft-04 predates
6
+ * `$vocabulary`, so this URI is never a spec-meaningful vocabulary document).
7
+ */
8
+ export declare const VOCAB_DRAFT_04 = "urn:jse:vocab:draft-04";
9
+ /**
10
+ * Identifier syntax for the draft-04 dialect: the keyword is `id` (no `$`);
11
+ * a schema object containing `$ref` has no identifiers at all, and a
12
+ * plain-fragment `id` is an anchor rather than a base change — the same
13
+ * legacy rules as draft-07/06's `$id` (see core's identifiersLegacy).
14
+ */
15
+ export declare const identifiersDraft04: IdentifierExtractor;
16
+ /**
17
+ * Registers the draft-04 vocabulary, dialect, and metaschema on an engine.
18
+ * Safe to call more than once per engine. Documents declaring
19
+ * `$schema: "http://json-schema.org/draft-04/schema#"` (or registered with
20
+ * that dialect URI) evaluate with draft-04 semantics afterwards, alongside
21
+ * every natively supported draft in the same registry.
22
+ */
23
+ export declare function registerDraft04(engine: Engine): void;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,MAAM,EACN,mBAAmB,EAKpB,MAAM,0BAA0B,CAAC;AAGlC,4BAA4B;AAC5B,eAAO,MAAM,gBAAgB,2CAA2C,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAIvD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,mBAQhC,CAAC;AAyJF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAUpD"}
package/dist/index.js ADDED
@@ -0,0 +1,191 @@
1
+ // JSON Schema draft-04 dialect (DESIGN.md M10, D11, D18), assembled entirely
2
+ // through @json-schema-engine/core's public surface — this package is the reference for
3
+ // third-party dialect authoring. Keywords draft-04 shares with draft-07 are
4
+ // harvested as behavior objects from the engine's registered draft-07
5
+ // dialect: behaviors are stateless shared values (draft-06 already reuses
6
+ // draft-07's objects the same way), harvesting `format` picks up the
7
+ // engine's formats/assertFormats configuration, and compiler lowerings
8
+ // added to the shared behaviors (M6.6) will apply here without changes.
9
+ // Only the keywords whose draft-04 semantics genuinely differ are defined
10
+ // below.
11
+ import { DIALECT_DRAFT_07, lowerIR, } from "@json-schema-engine/core";
12
+ import { METASCHEMAS_DRAFT_04 } from "./metaschema4.js";
13
+ /** draft-04 dialect URI. */
14
+ export const DIALECT_DRAFT_04 = "http://json-schema.org/draft-04/schema";
15
+ /**
16
+ * draft-04 vocabulary identity (registry-internal; draft-04 predates
17
+ * `$vocabulary`, so this URI is never a spec-meaningful vocabulary document).
18
+ */
19
+ export const VOCAB_DRAFT_04 = "urn:jse:vocab:draft-04";
20
+ const id04 = (name) => `${VOCAB_DRAFT_04}#${name}`;
21
+ /**
22
+ * Identifier syntax for the draft-04 dialect: the keyword is `id` (no `$`);
23
+ * a schema object containing `$ref` has no identifiers at all, and a
24
+ * plain-fragment `id` is an anchor rather than a base change — the same
25
+ * legacy rules as draft-07/06's `$id` (see core's identifiersLegacy).
26
+ */
27
+ export const identifiersDraft04 = (node) => {
28
+ if (Object.hasOwn(node, "$ref"))
29
+ return {};
30
+ const id = node.id;
31
+ if (typeof id !== "string")
32
+ return {};
33
+ if (id.startsWith("#")) {
34
+ return id.length > 1 ? { anchors: [id.slice(1)] } : {};
35
+ }
36
+ return { baseId: id };
37
+ };
38
+ /**
39
+ * Identifier/reserved keywords: no evaluation behavior, no annotation, and
40
+ * an empty lower() — the planner's capability check requires the function
41
+ * to exist, and an inert keyword's compiled contribution is legitimately
42
+ * nothing.
43
+ */
44
+ const structural = (name) => ({
45
+ id: id04(name),
46
+ analyze: () => ({ produces: [] }),
47
+ evaluate: () => true,
48
+ lower: () => undefined,
49
+ });
50
+ // draft-04's exclusiveMinimum/exclusiveMaximum are boolean modifiers on
51
+ // sibling minimum/maximum, not standalone assertions — so minimum/maximum
52
+ // read the sibling through ctx.schema (the same sibling-read pattern as
53
+ // 2020-12's contains with minContains) and the booleans themselves assert
54
+ // nothing. Params stay { limit } per the shared bounds-keyword shape (D13);
55
+ // exclusivity is recoverable from the schema itself.
56
+ // lower(): the exclusive/inclusive choice is plan-time data (the sibling
57
+ // boolean lives on lctx.schema, same sibling-read pattern as core's
58
+ // additionalItems reading lctx.schema.items) — so the comparison operator
59
+ // and message are picked once at lowering time rather than branching at
60
+ // runtime. Guard/compare/fail shape mirrors core's guardedCompare exemplar
61
+ // for 2020-12 minimum/maximum (validation.ts).
62
+ const minimum = {
63
+ id: id04("minimum"),
64
+ evaluate: (value, cursor, ctx) => {
65
+ const instance = cursor.value;
66
+ if (typeof instance !== "number")
67
+ return true;
68
+ const limit = value;
69
+ if (ctx.schema.exclusiveMinimum === true) {
70
+ if (instance > limit)
71
+ return true;
72
+ ctx.error(`must be > ${limit}`, { limit });
73
+ return false;
74
+ }
75
+ if (instance >= limit)
76
+ return true;
77
+ ctx.error(`must be >= ${limit}`, { limit });
78
+ return false;
79
+ },
80
+ lower: (value, lctx) => {
81
+ const exclusive = lctx.schema.exclusiveMinimum === true;
82
+ const op = exclusive ? ">" : ">=";
83
+ const message = exclusive
84
+ ? `must be > ${value}`
85
+ : `must be >= ${value}`;
86
+ lctx.emit(lowerIR.when(lowerIR.and(lowerIR.typeIs(lctx.instance, "number"), lowerIR.not(lowerIR.cmp(op, lctx.instance, lowerIR.constant(value)))), [lowerIR.failWith({ limit: lowerIR.constant(value) }, message)]));
87
+ },
88
+ };
89
+ const maximum = {
90
+ id: id04("maximum"),
91
+ evaluate: (value, cursor, ctx) => {
92
+ const instance = cursor.value;
93
+ if (typeof instance !== "number")
94
+ return true;
95
+ const limit = value;
96
+ if (ctx.schema.exclusiveMaximum === true) {
97
+ if (instance < limit)
98
+ return true;
99
+ ctx.error(`must be < ${limit}`, { limit });
100
+ return false;
101
+ }
102
+ if (instance <= limit)
103
+ return true;
104
+ ctx.error(`must be <= ${limit}`, { limit });
105
+ return false;
106
+ },
107
+ lower: (value, lctx) => {
108
+ const exclusive = lctx.schema.exclusiveMaximum === true;
109
+ const op = exclusive ? "<" : "<=";
110
+ const message = exclusive
111
+ ? `must be < ${value}`
112
+ : `must be <= ${value}`;
113
+ lctx.emit(lowerIR.when(lowerIR.and(lowerIR.typeIs(lctx.instance, "number"), lowerIR.not(lowerIR.cmp(op, lctx.instance, lowerIR.constant(value)))), [lowerIR.failWith({ limit: lowerIR.constant(value) }, message)]));
114
+ },
115
+ };
116
+ // Keywords draft-04 shares with draft-07, harvested from the engine's
117
+ // draft-07 dialect. Absent by omission: $id, $comment, if/then/else,
118
+ // propertyNames, contains, const, readOnly/writeOnly/examples, and the
119
+ // content keywords — none exist in draft-04, and the numeric 2020-12
120
+ // exclusiveMinimum/exclusiveMaximum are replaced by the boolean forms above.
121
+ // `type` is shared deliberately: draft-04's stricter integer (1.0 is not an
122
+ // integer) is unrepresentable after JSON.parse — the suite itself makes it
123
+ // optional (zeroTerminatedFloats.json) for exactly this reason.
124
+ const HARVESTED = [
125
+ "$ref",
126
+ "$schema",
127
+ "definitions",
128
+ "title",
129
+ "description",
130
+ "default",
131
+ "format",
132
+ "allOf",
133
+ "anyOf",
134
+ "oneOf",
135
+ "not",
136
+ "dependencies",
137
+ "properties",
138
+ "patternProperties",
139
+ "additionalProperties",
140
+ "items",
141
+ "additionalItems",
142
+ "type",
143
+ "enum",
144
+ "required",
145
+ "pattern",
146
+ "multipleOf",
147
+ "maxLength",
148
+ "minLength",
149
+ "maxItems",
150
+ "minItems",
151
+ "uniqueItems",
152
+ "maxProperties",
153
+ "minProperties",
154
+ ];
155
+ function draft04Vocabulary(engine) {
156
+ const draft07 = engine.dialects.getDialect(DIALECT_DRAFT_07);
157
+ const vocabulary = {};
158
+ for (const name of HARVESTED) {
159
+ const entry = draft07.keywords.get(name);
160
+ if (!entry) {
161
+ throw new Error(`draft-07 dialect is missing '${name}' — cannot assemble draft-04`);
162
+ }
163
+ vocabulary[name] = entry.behavior;
164
+ }
165
+ vocabulary.id = structural("id");
166
+ vocabulary.minimum = minimum;
167
+ vocabulary.maximum = maximum;
168
+ vocabulary.exclusiveMinimum = structural("exclusiveMinimum");
169
+ vocabulary.exclusiveMaximum = structural("exclusiveMaximum");
170
+ return vocabulary;
171
+ }
172
+ /**
173
+ * Registers the draft-04 vocabulary, dialect, and metaschema on an engine.
174
+ * Safe to call more than once per engine. Documents declaring
175
+ * `$schema: "http://json-schema.org/draft-04/schema#"` (or registered with
176
+ * that dialect URI) evaluate with draft-04 semantics afterwards, alongside
177
+ * every natively supported draft in the same registry.
178
+ */
179
+ export function registerDraft04(engine) {
180
+ if (engine.dialects.hasDialect(DIALECT_DRAFT_04))
181
+ return;
182
+ engine.registerVocabulary(VOCAB_DRAFT_04, draft04Vocabulary(engine));
183
+ engine.registerDialect(DIALECT_DRAFT_04, [VOCAB_DRAFT_04], {
184
+ identifiers: identifiersDraft04,
185
+ refIgnoresSiblings: true,
186
+ });
187
+ for (const [uri, doc] of METASCHEMAS_DRAFT_04) {
188
+ engine.registerSchema(doc, uri);
189
+ }
190
+ }
191
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wFAAwF;AACxF,4EAA4E;AAC5E,sEAAsE;AACtE,0EAA0E;AAC1E,qEAAqE;AACrE,uEAAuE;AACvE,wEAAwE;AACxE,0EAA0E;AAC1E,SAAS;AAET,OAAO,EAIL,gBAAgB,EAChB,OAAO,GAER,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,4BAA4B;AAC5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,wCAAwC,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEvD,MAAM,IAAI,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,GAAG,cAAc,IAAI,IAAI,EAAE,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAwB,CAAC,IAAI,EAAE,EAAE;IAC9D,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;IACnB,IAAI,OAAO,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AAC;IAC7D,UAAU,CAAC,gBAAgB,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC7D,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAO;IACzD,MAAM,CAAC,kBAAkB,CAAC,cAAc,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,MAAM,CAAC,eAAe,CAAC,gBAAgB,EAAE,CAAC,cAAc,CAAC,EAAE;QACzD,WAAW,EAAE,kBAAkB;QAC/B,kBAAkB,EAAE,IAAI;KACzB,CAAC,CAAC;IACH,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,oBAAoB,EAAE,CAAC;QAC9C,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { JsonValue } from "@json-schema-engine/core";
2
+ export declare const METASCHEMAS_DRAFT_04: readonly (readonly [string, JsonValue])[];
3
+ //# sourceMappingURL=metaschema4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metaschema4.d.ts","sourceRoot":"","sources":["../src/metaschema4.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,eAAO,MAAM,oBAAoB,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EA8NzE,CAAC"}
@@ -0,0 +1,224 @@
1
+ export const METASCHEMAS_DRAFT_04 = [
2
+ [
3
+ "http://json-schema.org/draft-04/schema",
4
+ {
5
+ id: "http://json-schema.org/draft-04/schema#",
6
+ $schema: "http://json-schema.org/draft-04/schema#",
7
+ description: "Core schema meta-schema",
8
+ definitions: {
9
+ schemaArray: {
10
+ type: "array",
11
+ minItems: 1,
12
+ items: {
13
+ $ref: "#",
14
+ },
15
+ },
16
+ positiveInteger: {
17
+ type: "integer",
18
+ minimum: 0,
19
+ },
20
+ positiveIntegerDefault0: {
21
+ allOf: [
22
+ {
23
+ $ref: "#/definitions/positiveInteger",
24
+ },
25
+ {
26
+ default: 0,
27
+ },
28
+ ],
29
+ },
30
+ simpleTypes: {
31
+ enum: [
32
+ "array",
33
+ "boolean",
34
+ "integer",
35
+ "null",
36
+ "number",
37
+ "object",
38
+ "string",
39
+ ],
40
+ },
41
+ stringArray: {
42
+ type: "array",
43
+ items: {
44
+ type: "string",
45
+ },
46
+ minItems: 1,
47
+ uniqueItems: true,
48
+ },
49
+ },
50
+ type: "object",
51
+ properties: {
52
+ id: {
53
+ type: "string",
54
+ },
55
+ $schema: {
56
+ type: "string",
57
+ },
58
+ title: {
59
+ type: "string",
60
+ },
61
+ description: {
62
+ type: "string",
63
+ },
64
+ default: {},
65
+ multipleOf: {
66
+ type: "number",
67
+ minimum: 0,
68
+ exclusiveMinimum: true,
69
+ },
70
+ maximum: {
71
+ type: "number",
72
+ },
73
+ exclusiveMaximum: {
74
+ type: "boolean",
75
+ default: false,
76
+ },
77
+ minimum: {
78
+ type: "number",
79
+ },
80
+ exclusiveMinimum: {
81
+ type: "boolean",
82
+ default: false,
83
+ },
84
+ maxLength: {
85
+ $ref: "#/definitions/positiveInteger",
86
+ },
87
+ minLength: {
88
+ $ref: "#/definitions/positiveIntegerDefault0",
89
+ },
90
+ pattern: {
91
+ type: "string",
92
+ format: "regex",
93
+ },
94
+ additionalItems: {
95
+ anyOf: [
96
+ {
97
+ type: "boolean",
98
+ },
99
+ {
100
+ $ref: "#",
101
+ },
102
+ ],
103
+ default: {},
104
+ },
105
+ items: {
106
+ anyOf: [
107
+ {
108
+ $ref: "#",
109
+ },
110
+ {
111
+ $ref: "#/definitions/schemaArray",
112
+ },
113
+ ],
114
+ default: {},
115
+ },
116
+ maxItems: {
117
+ $ref: "#/definitions/positiveInteger",
118
+ },
119
+ minItems: {
120
+ $ref: "#/definitions/positiveIntegerDefault0",
121
+ },
122
+ uniqueItems: {
123
+ type: "boolean",
124
+ default: false,
125
+ },
126
+ maxProperties: {
127
+ $ref: "#/definitions/positiveInteger",
128
+ },
129
+ minProperties: {
130
+ $ref: "#/definitions/positiveIntegerDefault0",
131
+ },
132
+ required: {
133
+ $ref: "#/definitions/stringArray",
134
+ },
135
+ additionalProperties: {
136
+ anyOf: [
137
+ {
138
+ type: "boolean",
139
+ },
140
+ {
141
+ $ref: "#",
142
+ },
143
+ ],
144
+ default: {},
145
+ },
146
+ definitions: {
147
+ type: "object",
148
+ additionalProperties: {
149
+ $ref: "#",
150
+ },
151
+ default: {},
152
+ },
153
+ properties: {
154
+ type: "object",
155
+ additionalProperties: {
156
+ $ref: "#",
157
+ },
158
+ default: {},
159
+ },
160
+ patternProperties: {
161
+ type: "object",
162
+ additionalProperties: {
163
+ $ref: "#",
164
+ },
165
+ default: {},
166
+ },
167
+ dependencies: {
168
+ type: "object",
169
+ additionalProperties: {
170
+ anyOf: [
171
+ {
172
+ $ref: "#",
173
+ },
174
+ {
175
+ $ref: "#/definitions/stringArray",
176
+ },
177
+ ],
178
+ },
179
+ },
180
+ enum: {
181
+ type: "array",
182
+ minItems: 1,
183
+ uniqueItems: true,
184
+ },
185
+ type: {
186
+ anyOf: [
187
+ {
188
+ $ref: "#/definitions/simpleTypes",
189
+ },
190
+ {
191
+ type: "array",
192
+ items: {
193
+ $ref: "#/definitions/simpleTypes",
194
+ },
195
+ minItems: 1,
196
+ uniqueItems: true,
197
+ },
198
+ ],
199
+ },
200
+ format: {
201
+ type: "string",
202
+ },
203
+ allOf: {
204
+ $ref: "#/definitions/schemaArray",
205
+ },
206
+ anyOf: {
207
+ $ref: "#/definitions/schemaArray",
208
+ },
209
+ oneOf: {
210
+ $ref: "#/definitions/schemaArray",
211
+ },
212
+ not: {
213
+ $ref: "#",
214
+ },
215
+ },
216
+ dependencies: {
217
+ exclusiveMaximum: ["maximum"],
218
+ exclusiveMinimum: ["minimum"],
219
+ },
220
+ default: {},
221
+ },
222
+ ],
223
+ ];
224
+ //# sourceMappingURL=metaschema4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metaschema4.js","sourceRoot":"","sources":["../src/metaschema4.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,oBAAoB,GAA8C;IAC7E;QACE,wCAAwC;QACxC;YACE,EAAE,EAAE,yCAAyC;YAC7C,OAAO,EAAE,yCAAyC;YAClD,WAAW,EAAE,yBAAyB;YACtC,WAAW,EAAE;gBACX,WAAW,EAAE;oBACX,IAAI,EAAE,OAAO;oBACb,QAAQ,EAAE,CAAC;oBACX,KAAK,EAAE;wBACL,IAAI,EAAE,GAAG;qBACV;iBACF;gBACD,eAAe,EAAE;oBACf,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE,CAAC;iBACX;gBACD,uBAAuB,EAAE;oBACvB,KAAK,EAAE;wBACL;4BACE,IAAI,EAAE,+BAA+B;yBACtC;wBACD;4BACE,OAAO,EAAE,CAAC;yBACX;qBACF;iBACF;gBACD,WAAW,EAAE;oBACX,IAAI,EAAE;wBACJ,OAAO;wBACP,SAAS;wBACT,SAAS;wBACT,MAAM;wBACN,QAAQ;wBACR,QAAQ;wBACR,QAAQ;qBACT;iBACF;gBACD,WAAW,EAAE;oBACX,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;qBACf;oBACD,QAAQ,EAAE,CAAC;oBACX,WAAW,EAAE,IAAI;iBAClB;aACF;YACD,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,EAAE,EAAE;oBACF,IAAI,EAAE,QAAQ;iBACf;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;iBACf;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;iBACf;gBACD,WAAW,EAAE;oBACX,IAAI,EAAE,QAAQ;iBACf;gBACD,OAAO,EAAE,EAAE;gB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AY,EAAE;gBACZ,gBAAgB,EAAE,CAAC,SAAS,CAAC;gBAC7B,gBAAgB,EAAE,CAAC,SAAS,CAAC;aAC9B;YACD,OAAO,EAAE,EAAE;SACZ;KACF;CACF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@json-schema-engine/dialect-draft04",
3
+ "version": "0.0.1",
4
+ "description": "JSON Schema draft-04 dialect for @json-schema-engine/core, assembled through the public dialect-authoring surface (DESIGN.md M10, D11)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "jse-source": "./src/index.ts",
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "license": "MIT",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "engines": {
19
+ "node": ">=22"
20
+ },
21
+ "dependencies": {
22
+ "@json-schema-engine/core": "^0.0.1"
23
+ },
24
+ "devDependencies": {
25
+ "@json-schema-engine/compiler": "^0.0.1",
26
+ "@json-schema-engine/formats": "^0.0.1",
27
+ "@json-schema-engine/test-kit": "^0.0.1"
28
+ },
29
+ "types": "./dist/index.d.ts",
30
+ "files": [
31
+ "dist",
32
+ "src"
33
+ ],
34
+ "sideEffects": false,
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/handrews/json-schema-engine.git",
38
+ "directory": "packages/dialect-draft04"
39
+ }
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,217 @@
1
+ // JSON Schema draft-04 dialect (DESIGN.md M10, D11, D18), assembled entirely
2
+ // through @json-schema-engine/core's public surface — this package is the reference for
3
+ // third-party dialect authoring. Keywords draft-04 shares with draft-07 are
4
+ // harvested as behavior objects from the engine's registered draft-07
5
+ // dialect: behaviors are stateless shared values (draft-06 already reuses
6
+ // draft-07's objects the same way), harvesting `format` picks up the
7
+ // engine's formats/assertFormats configuration, and compiler lowerings
8
+ // added to the shared behaviors (M6.6) will apply here without changes.
9
+ // Only the keywords whose draft-04 semantics genuinely differ are defined
10
+ // below.
11
+
12
+ import {
13
+ Engine,
14
+ IdentifierExtractor,
15
+ KeywordBehavior,
16
+ DIALECT_DRAFT_07,
17
+ lowerIR,
18
+ LoweringContext,
19
+ } from "@json-schema-engine/core";
20
+ import { METASCHEMAS_DRAFT_04 } from "./metaschema4.js";
21
+
22
+ /** draft-04 dialect URI. */
23
+ export const DIALECT_DRAFT_04 = "http://json-schema.org/draft-04/schema";
24
+
25
+ /**
26
+ * draft-04 vocabulary identity (registry-internal; draft-04 predates
27
+ * `$vocabulary`, so this URI is never a spec-meaningful vocabulary document).
28
+ */
29
+ export const VOCAB_DRAFT_04 = "urn:jse:vocab:draft-04";
30
+
31
+ const id04 = (name: string): string => `${VOCAB_DRAFT_04}#${name}`;
32
+
33
+ /**
34
+ * Identifier syntax for the draft-04 dialect: the keyword is `id` (no `$`);
35
+ * a schema object containing `$ref` has no identifiers at all, and a
36
+ * plain-fragment `id` is an anchor rather than a base change — the same
37
+ * legacy rules as draft-07/06's `$id` (see core's identifiersLegacy).
38
+ */
39
+ export const identifiersDraft04: IdentifierExtractor = (node) => {
40
+ if (Object.hasOwn(node, "$ref")) return {};
41
+ const id = node.id;
42
+ if (typeof id !== "string") return {};
43
+ if (id.startsWith("#")) {
44
+ return id.length > 1 ? { anchors: [id.slice(1)] } : {};
45
+ }
46
+ return { baseId: id };
47
+ };
48
+
49
+ /**
50
+ * Identifier/reserved keywords: no evaluation behavior, no annotation, and
51
+ * an empty lower() — the planner's capability check requires the function
52
+ * to exist, and an inert keyword's compiled contribution is legitimately
53
+ * nothing.
54
+ */
55
+ const structural = (name: string): KeywordBehavior => ({
56
+ id: id04(name),
57
+ analyze: () => ({ produces: [] }),
58
+ evaluate: () => true,
59
+ lower: () => undefined,
60
+ });
61
+
62
+ // draft-04's exclusiveMinimum/exclusiveMaximum are boolean modifiers on
63
+ // sibling minimum/maximum, not standalone assertions — so minimum/maximum
64
+ // read the sibling through ctx.schema (the same sibling-read pattern as
65
+ // 2020-12's contains with minContains) and the booleans themselves assert
66
+ // nothing. Params stay { limit } per the shared bounds-keyword shape (D13);
67
+ // exclusivity is recoverable from the schema itself.
68
+ // lower(): the exclusive/inclusive choice is plan-time data (the sibling
69
+ // boolean lives on lctx.schema, same sibling-read pattern as core's
70
+ // additionalItems reading lctx.schema.items) — so the comparison operator
71
+ // and message are picked once at lowering time rather than branching at
72
+ // runtime. Guard/compare/fail shape mirrors core's guardedCompare exemplar
73
+ // for 2020-12 minimum/maximum (validation.ts).
74
+ const minimum: KeywordBehavior = {
75
+ id: id04("minimum"),
76
+ evaluate: (value, cursor, ctx) => {
77
+ const instance = cursor.value;
78
+ if (typeof instance !== "number") return true;
79
+ const limit = value as number;
80
+ if (ctx.schema.exclusiveMinimum === true) {
81
+ if (instance > limit) return true;
82
+ ctx.error(`must be > ${limit}`, { limit });
83
+ return false;
84
+ }
85
+ if (instance >= limit) return true;
86
+ ctx.error(`must be >= ${limit}`, { limit });
87
+ return false;
88
+ },
89
+ lower: (value, lctx: LoweringContext) => {
90
+ const exclusive = lctx.schema.exclusiveMinimum === true;
91
+ const op = exclusive ? ">" : ">=";
92
+ const message = exclusive
93
+ ? `must be > ${value as number}`
94
+ : `must be >= ${value as number}`;
95
+ lctx.emit(
96
+ lowerIR.when(
97
+ lowerIR.and(
98
+ lowerIR.typeIs(lctx.instance, "number"),
99
+ lowerIR.not(lowerIR.cmp(op, lctx.instance, lowerIR.constant(value))),
100
+ ),
101
+ [lowerIR.failWith({ limit: lowerIR.constant(value) }, message)],
102
+ ),
103
+ );
104
+ },
105
+ };
106
+
107
+ const maximum: KeywordBehavior = {
108
+ id: id04("maximum"),
109
+ evaluate: (value, cursor, ctx) => {
110
+ const instance = cursor.value;
111
+ if (typeof instance !== "number") return true;
112
+ const limit = value as number;
113
+ if (ctx.schema.exclusiveMaximum === true) {
114
+ if (instance < limit) return true;
115
+ ctx.error(`must be < ${limit}`, { limit });
116
+ return false;
117
+ }
118
+ if (instance <= limit) return true;
119
+ ctx.error(`must be <= ${limit}`, { limit });
120
+ return false;
121
+ },
122
+ lower: (value, lctx: LoweringContext) => {
123
+ const exclusive = lctx.schema.exclusiveMaximum === true;
124
+ const op = exclusive ? "<" : "<=";
125
+ const message = exclusive
126
+ ? `must be < ${value as number}`
127
+ : `must be <= ${value as number}`;
128
+ lctx.emit(
129
+ lowerIR.when(
130
+ lowerIR.and(
131
+ lowerIR.typeIs(lctx.instance, "number"),
132
+ lowerIR.not(lowerIR.cmp(op, lctx.instance, lowerIR.constant(value))),
133
+ ),
134
+ [lowerIR.failWith({ limit: lowerIR.constant(value) }, message)],
135
+ ),
136
+ );
137
+ },
138
+ };
139
+
140
+ // Keywords draft-04 shares with draft-07, harvested from the engine's
141
+ // draft-07 dialect. Absent by omission: $id, $comment, if/then/else,
142
+ // propertyNames, contains, const, readOnly/writeOnly/examples, and the
143
+ // content keywords — none exist in draft-04, and the numeric 2020-12
144
+ // exclusiveMinimum/exclusiveMaximum are replaced by the boolean forms above.
145
+ // `type` is shared deliberately: draft-04's stricter integer (1.0 is not an
146
+ // integer) is unrepresentable after JSON.parse — the suite itself makes it
147
+ // optional (zeroTerminatedFloats.json) for exactly this reason.
148
+ const HARVESTED = [
149
+ "$ref",
150
+ "$schema",
151
+ "definitions",
152
+ "title",
153
+ "description",
154
+ "default",
155
+ "format",
156
+ "allOf",
157
+ "anyOf",
158
+ "oneOf",
159
+ "not",
160
+ "dependencies",
161
+ "properties",
162
+ "patternProperties",
163
+ "additionalProperties",
164
+ "items",
165
+ "additionalItems",
166
+ "type",
167
+ "enum",
168
+ "required",
169
+ "pattern",
170
+ "multipleOf",
171
+ "maxLength",
172
+ "minLength",
173
+ "maxItems",
174
+ "minItems",
175
+ "uniqueItems",
176
+ "maxProperties",
177
+ "minProperties",
178
+ ] as const;
179
+
180
+ function draft04Vocabulary(engine: Engine): Record<string, KeywordBehavior> {
181
+ const draft07 = engine.dialects.getDialect(DIALECT_DRAFT_07);
182
+ const vocabulary: Record<string, KeywordBehavior> = {};
183
+ for (const name of HARVESTED) {
184
+ const entry = draft07.keywords.get(name);
185
+ if (!entry) {
186
+ throw new Error(
187
+ `draft-07 dialect is missing '${name}' — cannot assemble draft-04`,
188
+ );
189
+ }
190
+ vocabulary[name] = entry.behavior;
191
+ }
192
+ vocabulary.id = structural("id");
193
+ vocabulary.minimum = minimum;
194
+ vocabulary.maximum = maximum;
195
+ vocabulary.exclusiveMinimum = structural("exclusiveMinimum");
196
+ vocabulary.exclusiveMaximum = structural("exclusiveMaximum");
197
+ return vocabulary;
198
+ }
199
+
200
+ /**
201
+ * Registers the draft-04 vocabulary, dialect, and metaschema on an engine.
202
+ * Safe to call more than once per engine. Documents declaring
203
+ * `$schema: "http://json-schema.org/draft-04/schema#"` (or registered with
204
+ * that dialect URI) evaluate with draft-04 semantics afterwards, alongside
205
+ * every natively supported draft in the same registry.
206
+ */
207
+ export function registerDraft04(engine: Engine): void {
208
+ if (engine.dialects.hasDialect(DIALECT_DRAFT_04)) return;
209
+ engine.registerVocabulary(VOCAB_DRAFT_04, draft04Vocabulary(engine));
210
+ engine.registerDialect(DIALECT_DRAFT_04, [VOCAB_DRAFT_04], {
211
+ identifiers: identifiersDraft04,
212
+ refIgnoresSiblings: true,
213
+ });
214
+ for (const [uri, doc] of METASCHEMAS_DRAFT_04) {
215
+ engine.registerSchema(doc, uri);
216
+ }
217
+ }
@@ -0,0 +1,231 @@
1
+ // The draft-04 metaschema, vendored verbatim from
2
+ // https://json-schema.org/draft-04/schema (JSON Schema specification
3
+ // artifact, BSD-licensed). Same role as core's metaschemas7.ts, but shipped
4
+ // here: core stays free of draft-04 syntax (D11), so the dialect package
5
+ // registers this as an ordinary schema resource through the public Engine
6
+ // surface. The id's empty fragment is stripped to the resource URI.
7
+ import { JsonValue } from "@json-schema-engine/core";
8
+
9
+ export const METASCHEMAS_DRAFT_04: readonly (readonly [string, JsonValue])[] = [
10
+ [
11
+ "http://json-schema.org/draft-04/schema",
12
+ {
13
+ id: "http://json-schema.org/draft-04/schema#",
14
+ $schema: "http://json-schema.org/draft-04/schema#",
15
+ description: "Core schema meta-schema",
16
+ definitions: {
17
+ schemaArray: {
18
+ type: "array",
19
+ minItems: 1,
20
+ items: {
21
+ $ref: "#",
22
+ },
23
+ },
24
+ positiveInteger: {
25
+ type: "integer",
26
+ minimum: 0,
27
+ },
28
+ positiveIntegerDefault0: {
29
+ allOf: [
30
+ {
31
+ $ref: "#/definitions/positiveInteger",
32
+ },
33
+ {
34
+ default: 0,
35
+ },
36
+ ],
37
+ },
38
+ simpleTypes: {
39
+ enum: [
40
+ "array",
41
+ "boolean",
42
+ "integer",
43
+ "null",
44
+ "number",
45
+ "object",
46
+ "string",
47
+ ],
48
+ },
49
+ stringArray: {
50
+ type: "array",
51
+ items: {
52
+ type: "string",
53
+ },
54
+ minItems: 1,
55
+ uniqueItems: true,
56
+ },
57
+ },
58
+ type: "object",
59
+ properties: {
60
+ id: {
61
+ type: "string",
62
+ },
63
+ $schema: {
64
+ type: "string",
65
+ },
66
+ title: {
67
+ type: "string",
68
+ },
69
+ description: {
70
+ type: "string",
71
+ },
72
+ default: {},
73
+ multipleOf: {
74
+ type: "number",
75
+ minimum: 0,
76
+ exclusiveMinimum: true,
77
+ },
78
+ maximum: {
79
+ type: "number",
80
+ },
81
+ exclusiveMaximum: {
82
+ type: "boolean",
83
+ default: false,
84
+ },
85
+ minimum: {
86
+ type: "number",
87
+ },
88
+ exclusiveMinimum: {
89
+ type: "boolean",
90
+ default: false,
91
+ },
92
+ maxLength: {
93
+ $ref: "#/definitions/positiveInteger",
94
+ },
95
+ minLength: {
96
+ $ref: "#/definitions/positiveIntegerDefault0",
97
+ },
98
+ pattern: {
99
+ type: "string",
100
+ format: "regex",
101
+ },
102
+ additionalItems: {
103
+ anyOf: [
104
+ {
105
+ type: "boolean",
106
+ },
107
+ {
108
+ $ref: "#",
109
+ },
110
+ ],
111
+ default: {},
112
+ },
113
+ items: {
114
+ anyOf: [
115
+ {
116
+ $ref: "#",
117
+ },
118
+ {
119
+ $ref: "#/definitions/schemaArray",
120
+ },
121
+ ],
122
+ default: {},
123
+ },
124
+ maxItems: {
125
+ $ref: "#/definitions/positiveInteger",
126
+ },
127
+ minItems: {
128
+ $ref: "#/definitions/positiveIntegerDefault0",
129
+ },
130
+ uniqueItems: {
131
+ type: "boolean",
132
+ default: false,
133
+ },
134
+ maxProperties: {
135
+ $ref: "#/definitions/positiveInteger",
136
+ },
137
+ minProperties: {
138
+ $ref: "#/definitions/positiveIntegerDefault0",
139
+ },
140
+ required: {
141
+ $ref: "#/definitions/stringArray",
142
+ },
143
+ additionalProperties: {
144
+ anyOf: [
145
+ {
146
+ type: "boolean",
147
+ },
148
+ {
149
+ $ref: "#",
150
+ },
151
+ ],
152
+ default: {},
153
+ },
154
+ definitions: {
155
+ type: "object",
156
+ additionalProperties: {
157
+ $ref: "#",
158
+ },
159
+ default: {},
160
+ },
161
+ properties: {
162
+ type: "object",
163
+ additionalProperties: {
164
+ $ref: "#",
165
+ },
166
+ default: {},
167
+ },
168
+ patternProperties: {
169
+ type: "object",
170
+ additionalProperties: {
171
+ $ref: "#",
172
+ },
173
+ default: {},
174
+ },
175
+ dependencies: {
176
+ type: "object",
177
+ additionalProperties: {
178
+ anyOf: [
179
+ {
180
+ $ref: "#",
181
+ },
182
+ {
183
+ $ref: "#/definitions/stringArray",
184
+ },
185
+ ],
186
+ },
187
+ },
188
+ enum: {
189
+ type: "array",
190
+ minItems: 1,
191
+ uniqueItems: true,
192
+ },
193
+ type: {
194
+ anyOf: [
195
+ {
196
+ $ref: "#/definitions/simpleTypes",
197
+ },
198
+ {
199
+ type: "array",
200
+ items: {
201
+ $ref: "#/definitions/simpleTypes",
202
+ },
203
+ minItems: 1,
204
+ uniqueItems: true,
205
+ },
206
+ ],
207
+ },
208
+ format: {
209
+ type: "string",
210
+ },
211
+ allOf: {
212
+ $ref: "#/definitions/schemaArray",
213
+ },
214
+ anyOf: {
215
+ $ref: "#/definitions/schemaArray",
216
+ },
217
+ oneOf: {
218
+ $ref: "#/definitions/schemaArray",
219
+ },
220
+ not: {
221
+ $ref: "#",
222
+ },
223
+ },
224
+ dependencies: {
225
+ exclusiveMaximum: ["maximum"],
226
+ exclusiveMinimum: ["minimum"],
227
+ },
228
+ default: {},
229
+ },
230
+ ],
231
+ ];