@xschemadev/core 0.0.6 → 0.2.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/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/ir/constraints.d.ts +52 -0
- package/dist/ir/constraints.d.ts.map +1 -0
- package/dist/ir/constraints.js +6 -0
- package/dist/ir/constraints.js.map +1 -0
- package/dist/ir/index.d.ts +9 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +8 -0
- package/dist/ir/index.js.map +1 -0
- package/dist/ir/nodes.d.ts +157 -0
- package/dist/ir/nodes.d.ts.map +1 -0
- package/dist/ir/nodes.js +11 -0
- package/dist/ir/nodes.js.map +1 -0
- package/dist/parser/collections.d.ts +11 -0
- package/dist/parser/collections.d.ts.map +1 -0
- package/dist/parser/collections.js +219 -0
- package/dist/parser/collections.js.map +1 -0
- package/dist/parser/composition.d.ts +14 -0
- package/dist/parser/composition.d.ts.map +1 -0
- package/dist/parser/composition.js +36 -0
- package/dist/parser/composition.js.map +1 -0
- package/dist/parser/context.d.ts +12 -0
- package/dist/parser/context.d.ts.map +1 -0
- package/dist/parser/context.js +10 -0
- package/dist/parser/context.js.map +1 -0
- package/dist/parser/index.d.ts +19 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +325 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/primitives.d.ts +8 -0
- package/dist/parser/primitives.d.ts.map +1 -0
- package/dist/parser/primitives.js +28 -0
- package/dist/parser/primitives.js.map +1 -0
- package/dist/parser/values.d.ts +8 -0
- package/dist/parser/values.d.ts.map +1 -0
- package/dist/parser/values.js +16 -0
- package/dist/parser/values.js.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/json-schema.d.ts +66 -0
- package/dist/schema/json-schema.d.ts.map +1 -0
- package/dist/schema/json-schema.js +6 -0
- package/dist/schema/json-schema.js.map +1 -0
- package/dist/types.d.ts +6 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/code-builder.d.ts +49 -0
- package/dist/utils/code-builder.d.ts.map +1 -0
- package/dist/utils/code-builder.js +112 -0
- package/dist/utils/code-builder.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json-pointer.d.ts +14 -0
- package/dist/utils/json-pointer.d.ts.map +1 -0
- package/dist/utils/json-pointer.js +17 -0
- package/dist/utils/json-pointer.js.map +1 -0
- package/dist/utils/primitives.d.ts +28 -0
- package/dist/utils/primitives.d.ts.map +1 -0
- package/dist/utils/primitives.js +57 -0
- package/dist/utils/primitives.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser context for tracking state during parsing
|
|
3
|
+
*/
|
|
4
|
+
import type { JSONSchema } from "../schema/json-schema.js";
|
|
5
|
+
export interface ParseContext {
|
|
6
|
+
/** Root schema for $ref resolution */
|
|
7
|
+
rootSchema: JSONSchema;
|
|
8
|
+
/** Tracks $ref paths currently being resolved (cycle detection) */
|
|
9
|
+
resolving: Set<string>;
|
|
10
|
+
}
|
|
11
|
+
export declare function createContext(rootSchema: JSONSchema): ParseContext;
|
|
12
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/parser/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,WAAW,YAAY;IAC5B,sCAAsC;IACtC,UAAU,EAAE,UAAU,CAAC;IACvB,mEAAmE;IACnE,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,YAAY,CAKlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/parser/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,MAAM,UAAU,aAAa,CAAC,UAAsB;IACnD,OAAO;QACN,UAAU;QACV,SAAS,EAAE,IAAI,GAAG,EAAE;KACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema Parser
|
|
3
|
+
* Converts JSON Schema to SchemaNode IR
|
|
4
|
+
*/
|
|
5
|
+
import type { JSONSchema } from "../schema/json-schema.js";
|
|
6
|
+
import type { SchemaNode } from "../ir/nodes.js";
|
|
7
|
+
import { type ParseContext } from "./context.js";
|
|
8
|
+
export type { ParseContext } from "./context.js";
|
|
9
|
+
/**
|
|
10
|
+
* Parse a JSON Schema into SchemaNode IR
|
|
11
|
+
* Expects schemas to be pre-normalized to draft2020-12 by the bundler.
|
|
12
|
+
* @param schema The JSON Schema to parse
|
|
13
|
+
*/
|
|
14
|
+
export declare function parse(schema: JSONSchema | boolean): SchemaNode;
|
|
15
|
+
/**
|
|
16
|
+
* Internal schema parser - recursive
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseSchema(schema: JSONSchema | boolean, ctx: ParseContext): SchemaNode;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAYhE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,UAAU,CAQ9D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAC1B,MAAM,EAAE,UAAU,GAAG,OAAO,EAC5B,GAAG,EAAE,YAAY,GACf,UAAU,CA4JZ"}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema Parser
|
|
3
|
+
* Converts JSON Schema to SchemaNode IR
|
|
4
|
+
*/
|
|
5
|
+
// Note: $ref resolution is handled by the Go CLI bundler
|
|
6
|
+
import { isEmptyObject } from "../utils/primitives.js";
|
|
7
|
+
import { createContext } from "./context.js";
|
|
8
|
+
import { parseString, parseNumber } from "./primitives.js";
|
|
9
|
+
import { parseObject, parseArray } from "./collections.js";
|
|
10
|
+
import { parseAllOf, parseAnyOf, parseOneOf, parseNot, parseConditional, } from "./composition.js";
|
|
11
|
+
import { parseLiteral, parseEnum } from "./values.js";
|
|
12
|
+
/**
|
|
13
|
+
* Parse a JSON Schema into SchemaNode IR
|
|
14
|
+
* Expects schemas to be pre-normalized to draft2020-12 by the bundler.
|
|
15
|
+
* @param schema The JSON Schema to parse
|
|
16
|
+
*/
|
|
17
|
+
export function parse(schema) {
|
|
18
|
+
// Handle boolean schemas at root level
|
|
19
|
+
if (typeof schema === "boolean") {
|
|
20
|
+
return schema ? { kind: "any" } : { kind: "never" };
|
|
21
|
+
}
|
|
22
|
+
const ctx = createContext(schema);
|
|
23
|
+
return parseSchema(schema, ctx);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Internal schema parser - recursive
|
|
27
|
+
*/
|
|
28
|
+
export function parseSchema(schema, ctx) {
|
|
29
|
+
// Handle boolean schemas
|
|
30
|
+
if (typeof schema === "boolean") {
|
|
31
|
+
return schema ? { kind: "any" } : { kind: "never" };
|
|
32
|
+
}
|
|
33
|
+
// Handle $ref — recursive back-edges left by the processor
|
|
34
|
+
if (schema.$ref) {
|
|
35
|
+
const ref = schema.$ref;
|
|
36
|
+
if (ctx.resolving.has(ref)) {
|
|
37
|
+
return { kind: "ref", ref };
|
|
38
|
+
}
|
|
39
|
+
const target = resolveJsonPointerInSchema(ref, ctx.rootSchema);
|
|
40
|
+
if (target === undefined) {
|
|
41
|
+
throw new Error(`Encountered unresolvable $ref "${ref}" - schemas must be bundled by the Go CLI before processing.`);
|
|
42
|
+
}
|
|
43
|
+
ctx.resolving.add(ref);
|
|
44
|
+
const result = parseSchema(target, ctx);
|
|
45
|
+
ctx.resolving.delete(ref);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
// Handle not - check before composition since { not: {} } = never
|
|
49
|
+
if (schema.not !== undefined) {
|
|
50
|
+
if (typeof schema.not === "object" && isEmptyObject(schema.not)) {
|
|
51
|
+
return { kind: "never" };
|
|
52
|
+
}
|
|
53
|
+
return parseNot(schema.not, ctx, parseSchema);
|
|
54
|
+
}
|
|
55
|
+
// Handle if/then/else
|
|
56
|
+
if (schema.if !== undefined) {
|
|
57
|
+
return parseConditional(schema, ctx, parseSchema);
|
|
58
|
+
}
|
|
59
|
+
// Check for composition operators
|
|
60
|
+
const hasAllOf = schema.allOf && schema.allOf.length > 0;
|
|
61
|
+
const hasAnyOf = schema.anyOf && schema.anyOf.length > 0;
|
|
62
|
+
const hasOneOf = schema.oneOf && schema.oneOf.length > 0;
|
|
63
|
+
// Check for base schema keywords alongside composition operators.
|
|
64
|
+
// If we have base constraints (like additionalProperties/dependencies/etc), they must
|
|
65
|
+
// be intersected with the composition result.
|
|
66
|
+
const hasBaseSchema = schema.type !== undefined ||
|
|
67
|
+
// object keywords
|
|
68
|
+
schema.properties !== undefined ||
|
|
69
|
+
schema.additionalProperties !== undefined ||
|
|
70
|
+
schema.patternProperties !== undefined ||
|
|
71
|
+
schema.required !== undefined ||
|
|
72
|
+
schema.propertyNames !== undefined ||
|
|
73
|
+
schema.minProperties !== undefined ||
|
|
74
|
+
schema.maxProperties !== undefined ||
|
|
75
|
+
schema.dependentRequired !== undefined ||
|
|
76
|
+
schema.dependentSchemas !== undefined ||
|
|
77
|
+
schema.dependencies !== undefined ||
|
|
78
|
+
schema.unevaluatedProperties !== undefined ||
|
|
79
|
+
// array keywords
|
|
80
|
+
schema.items !== undefined ||
|
|
81
|
+
schema.prefixItems !== undefined ||
|
|
82
|
+
schema.additionalItems !== undefined ||
|
|
83
|
+
schema.minItems !== undefined ||
|
|
84
|
+
schema.maxItems !== undefined ||
|
|
85
|
+
schema.uniqueItems !== undefined ||
|
|
86
|
+
schema.contains !== undefined ||
|
|
87
|
+
schema.unevaluatedItems !== undefined ||
|
|
88
|
+
// primitive keywords
|
|
89
|
+
schema.minimum !== undefined ||
|
|
90
|
+
schema.maximum !== undefined ||
|
|
91
|
+
schema.exclusiveMinimum !== undefined ||
|
|
92
|
+
schema.exclusiveMaximum !== undefined ||
|
|
93
|
+
schema.multipleOf !== undefined ||
|
|
94
|
+
schema.minLength !== undefined ||
|
|
95
|
+
schema.maxLength !== undefined ||
|
|
96
|
+
schema.pattern !== undefined ||
|
|
97
|
+
schema.format !== undefined ||
|
|
98
|
+
// value keywords
|
|
99
|
+
schema.enum !== undefined ||
|
|
100
|
+
schema.const !== undefined;
|
|
101
|
+
if (hasAllOf || hasAnyOf || hasOneOf) {
|
|
102
|
+
return parseComposition(schema, ctx, hasBaseSchema);
|
|
103
|
+
}
|
|
104
|
+
// Handle enum
|
|
105
|
+
if (schema.enum !== undefined) {
|
|
106
|
+
return parseEnum(schema);
|
|
107
|
+
}
|
|
108
|
+
// Handle const
|
|
109
|
+
if (schema.const !== undefined) {
|
|
110
|
+
return parseLiteral(schema);
|
|
111
|
+
}
|
|
112
|
+
// Handle type
|
|
113
|
+
const type = schema.type;
|
|
114
|
+
if (Array.isArray(type)) {
|
|
115
|
+
// Multiple types - create union
|
|
116
|
+
const variants = type.map((t) => {
|
|
117
|
+
// Draft3: type array can contain inline schemas
|
|
118
|
+
if (typeof t === "object" && t !== null) {
|
|
119
|
+
return parseSchema(t, ctx);
|
|
120
|
+
}
|
|
121
|
+
const typeSchema = { ...schema, type: t };
|
|
122
|
+
delete typeSchema.enum;
|
|
123
|
+
return parseSchema(typeSchema, ctx);
|
|
124
|
+
});
|
|
125
|
+
if (variants.length === 0)
|
|
126
|
+
return { kind: "never" };
|
|
127
|
+
if (variants.length === 1)
|
|
128
|
+
return variants[0];
|
|
129
|
+
return { kind: "union", variants };
|
|
130
|
+
}
|
|
131
|
+
if (!type) {
|
|
132
|
+
// No type - infer from keywords or return typeGuarded
|
|
133
|
+
return parseTypeless(schema, ctx);
|
|
134
|
+
}
|
|
135
|
+
// Parse by type
|
|
136
|
+
let result;
|
|
137
|
+
switch (type) {
|
|
138
|
+
case "string":
|
|
139
|
+
result = parseString(schema);
|
|
140
|
+
break;
|
|
141
|
+
case "number":
|
|
142
|
+
result = parseNumber(schema, false);
|
|
143
|
+
break;
|
|
144
|
+
case "integer":
|
|
145
|
+
result = parseNumber(schema, true);
|
|
146
|
+
break;
|
|
147
|
+
case "boolean":
|
|
148
|
+
result = { kind: "boolean" };
|
|
149
|
+
break;
|
|
150
|
+
case "null":
|
|
151
|
+
result = { kind: "null" };
|
|
152
|
+
break;
|
|
153
|
+
case "object":
|
|
154
|
+
result = parseObject(schema, ctx, parseSchema);
|
|
155
|
+
break;
|
|
156
|
+
case "array":
|
|
157
|
+
result = parseArray(schema, ctx, parseSchema);
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
result = { kind: "any" };
|
|
161
|
+
}
|
|
162
|
+
// Handle nullable (OpenAPI 3.0)
|
|
163
|
+
if (schema.nullable === true) {
|
|
164
|
+
return { kind: "nullable", inner: result };
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Resolve a JSON pointer ref against a schema root.
|
|
170
|
+
* Handles "#" (root) and "#/path/to/node" (JSON pointer).
|
|
171
|
+
*/
|
|
172
|
+
function resolveJsonPointerInSchema(ref, root) {
|
|
173
|
+
if (ref === "#")
|
|
174
|
+
return root;
|
|
175
|
+
if (!ref.startsWith("#/"))
|
|
176
|
+
return undefined;
|
|
177
|
+
const segments = ref
|
|
178
|
+
.slice(2)
|
|
179
|
+
.split("/")
|
|
180
|
+
.map((s) => s.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
181
|
+
let current = root;
|
|
182
|
+
for (const segment of segments) {
|
|
183
|
+
if (current === null || current === undefined)
|
|
184
|
+
return undefined;
|
|
185
|
+
if (typeof current !== "object")
|
|
186
|
+
return undefined;
|
|
187
|
+
if (Array.isArray(current)) {
|
|
188
|
+
const idx = Number(segment);
|
|
189
|
+
if (Number.isNaN(idx) || idx < 0 || idx >= current.length)
|
|
190
|
+
return undefined;
|
|
191
|
+
current = current[idx];
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
current = current[segment];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (current === undefined)
|
|
198
|
+
return undefined;
|
|
199
|
+
if (typeof current === "boolean")
|
|
200
|
+
return current;
|
|
201
|
+
if (typeof current === "object" && current !== null)
|
|
202
|
+
return current;
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
function parseComposition(schema, ctx, hasBaseSchema) {
|
|
206
|
+
const parts = [];
|
|
207
|
+
// Add base schema constraints if present
|
|
208
|
+
if (hasBaseSchema) {
|
|
209
|
+
const baseSchema = { ...schema };
|
|
210
|
+
delete baseSchema.allOf;
|
|
211
|
+
delete baseSchema.anyOf;
|
|
212
|
+
delete baseSchema.oneOf;
|
|
213
|
+
parts.push(parseSchema(baseSchema, ctx));
|
|
214
|
+
}
|
|
215
|
+
// Add allOf (intersection)
|
|
216
|
+
if (schema.allOf && schema.allOf.length > 0) {
|
|
217
|
+
const allOfNode = parseAllOf(schema.allOf, ctx, parseSchema);
|
|
218
|
+
// Flatten single-item intersection
|
|
219
|
+
if (allOfNode.schemas.length === 1) {
|
|
220
|
+
parts.push(allOfNode.schemas[0]);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
parts.push(allOfNode);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Add anyOf (union)
|
|
227
|
+
if (schema.anyOf && schema.anyOf.length > 0) {
|
|
228
|
+
const anyOfNode = parseAnyOf(schema.anyOf, ctx, parseSchema);
|
|
229
|
+
// Flatten single-item union
|
|
230
|
+
if (anyOfNode.variants.length === 1) {
|
|
231
|
+
parts.push(anyOfNode.variants[0]);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
parts.push(anyOfNode);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// Add oneOf (exactly one)
|
|
238
|
+
if (schema.oneOf && schema.oneOf.length > 0) {
|
|
239
|
+
const oneOfNode = parseOneOf(schema.oneOf, ctx, parseSchema);
|
|
240
|
+
// Flatten single-item oneOf
|
|
241
|
+
if (oneOfNode.schemas.length === 1) {
|
|
242
|
+
parts.push(oneOfNode.schemas[0]);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
parts.push(oneOfNode);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Combine parts with intersection
|
|
249
|
+
if (parts.length === 0)
|
|
250
|
+
return { kind: "any" };
|
|
251
|
+
if (parts.length === 1)
|
|
252
|
+
return parts[0];
|
|
253
|
+
return {
|
|
254
|
+
kind: "intersection",
|
|
255
|
+
schemas: parts,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function parseTypeless(schema, ctx) {
|
|
259
|
+
const guards = [];
|
|
260
|
+
// Check for object keywords
|
|
261
|
+
// Note: required as boolean (draft3 property-level) should NOT trigger object detection
|
|
262
|
+
// Only array-style required (draft4+) indicates schema-level object constraints
|
|
263
|
+
const hasObjectKeywords = schema.properties !== undefined ||
|
|
264
|
+
schema.additionalProperties !== undefined ||
|
|
265
|
+
schema.patternProperties !== undefined ||
|
|
266
|
+
(Array.isArray(schema.required) && schema.required.length > 0) ||
|
|
267
|
+
schema.propertyNames !== undefined ||
|
|
268
|
+
schema.minProperties !== undefined ||
|
|
269
|
+
schema.maxProperties !== undefined ||
|
|
270
|
+
schema.dependentRequired !== undefined ||
|
|
271
|
+
schema.dependentSchemas !== undefined ||
|
|
272
|
+
schema.dependencies !== undefined ||
|
|
273
|
+
schema.unevaluatedProperties !== undefined;
|
|
274
|
+
// Check for array keywords
|
|
275
|
+
const hasArrayKeywords = schema.items !== undefined ||
|
|
276
|
+
schema.prefixItems !== undefined ||
|
|
277
|
+
schema.additionalItems !== undefined ||
|
|
278
|
+
schema.minItems !== undefined ||
|
|
279
|
+
schema.maxItems !== undefined ||
|
|
280
|
+
schema.uniqueItems !== undefined ||
|
|
281
|
+
schema.contains !== undefined ||
|
|
282
|
+
schema.unevaluatedItems !== undefined;
|
|
283
|
+
// Check for numeric keywords
|
|
284
|
+
const hasNumericKeywords = schema.minimum !== undefined ||
|
|
285
|
+
schema.maximum !== undefined ||
|
|
286
|
+
schema.exclusiveMinimum !== undefined ||
|
|
287
|
+
schema.exclusiveMaximum !== undefined ||
|
|
288
|
+
schema.multipleOf !== undefined;
|
|
289
|
+
// Check for string keywords
|
|
290
|
+
const hasStringKeywords = schema.minLength !== undefined ||
|
|
291
|
+
schema.maxLength !== undefined ||
|
|
292
|
+
schema.pattern !== undefined;
|
|
293
|
+
if (hasObjectKeywords) {
|
|
294
|
+
guards.push({
|
|
295
|
+
check: "object",
|
|
296
|
+
schema: parseObject(schema, ctx, parseSchema),
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (hasArrayKeywords) {
|
|
300
|
+
guards.push({
|
|
301
|
+
check: "array",
|
|
302
|
+
schema: parseArray(schema, ctx, parseSchema),
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
if (hasNumericKeywords) {
|
|
306
|
+
guards.push({
|
|
307
|
+
check: "number",
|
|
308
|
+
schema: parseNumber(schema, false),
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
if (hasStringKeywords) {
|
|
312
|
+
guards.push({
|
|
313
|
+
check: "string",
|
|
314
|
+
schema: parseString(schema),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (guards.length === 0) {
|
|
318
|
+
return { kind: "any" };
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
kind: "typeGuarded",
|
|
322
|
+
guards,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,yDAAyD;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAqB,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACN,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAItD;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,MAA4B;IACjD,uCAAuC;IACvC,IAAI,OAAO,MAAM,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACrD,CAAC;IAED,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,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4B;IAC5B,MAAM,iBAAiB,GACtB,MAAM,CAAC,SAAS,KAAK,SAAS;QAC9B,MAAM,CAAC,SAAS,KAAK,SAAS;QAC9B,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC;IAE9B,IAAI,iBAAiB,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC;YACX,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC;SAC7C,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC;YACX,KAAK,EAAE,OAAO;YACd,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC;SAC5C,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,kBAAkB,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,CAAC;YACX,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC;SAClC,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,iBAAiB,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC;YACX,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;SAC3B,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACxB,CAAC;IAED,OAAO;QACN,IAAI,EAAE,aAAa;QACnB,MAAM;KACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsers for primitive types: string, number, boolean, null
|
|
3
|
+
*/
|
|
4
|
+
import type { JSONSchema } from "../schema/json-schema.js";
|
|
5
|
+
import type { StringNode, NumberNode } from "../ir/nodes.js";
|
|
6
|
+
export declare function parseString(schema: JSONSchema): StringNode;
|
|
7
|
+
export declare function parseNumber(schema: JSONSchema, integer: boolean): NumberNode;
|
|
8
|
+
//# sourceMappingURL=primitives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/parser/primitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE7D,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAU1D;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,UAAU,CAY5E"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsers for primitive types: string, number, boolean, null
|
|
3
|
+
*/
|
|
4
|
+
export function parseString(schema) {
|
|
5
|
+
return {
|
|
6
|
+
kind: "string",
|
|
7
|
+
constraints: {
|
|
8
|
+
minLength: schema.minLength,
|
|
9
|
+
maxLength: schema.maxLength,
|
|
10
|
+
pattern: schema.pattern,
|
|
11
|
+
},
|
|
12
|
+
format: schema.format,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function parseNumber(schema, integer) {
|
|
16
|
+
return {
|
|
17
|
+
kind: "number",
|
|
18
|
+
integer,
|
|
19
|
+
constraints: {
|
|
20
|
+
minimum: schema.minimum,
|
|
21
|
+
maximum: schema.maximum,
|
|
22
|
+
exclusiveMinimum: schema.exclusiveMinimum, // already normalized to number by Go CLI
|
|
23
|
+
exclusiveMaximum: schema.exclusiveMaximum, // already normalized to number by Go CLI
|
|
24
|
+
multipleOf: schema.multipleOf,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=primitives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/parser/primitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC7C,OAAO;QACN,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE;YACZ,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;SACvB;QACD,MAAM,EAAE,MAAM,CAAC,MAAM;KACrB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAkB,EAAE,OAAgB;IAC/D,OAAO;QACN,IAAI,EAAE,QAAQ;QACd,OAAO;QACP,WAAW,EAAE;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,EAAE,yCAAyC;YACpF,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,EAAE,yCAAyC;YACpF,UAAU,EAAE,MAAM,CAAC,UAAU;SAC7B;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsers for value types: literal, enum
|
|
3
|
+
*/
|
|
4
|
+
import type { JSONSchema } from "../schema/json-schema.js";
|
|
5
|
+
import type { LiteralNode, EnumNode } from "../ir/nodes.js";
|
|
6
|
+
export declare function parseLiteral(schema: JSONSchema): LiteralNode;
|
|
7
|
+
export declare function parseEnum(schema: JSONSchema): EnumNode;
|
|
8
|
+
//# sourceMappingURL=values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../src/parser/values.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE5D,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,CAK5D;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAKtD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsers for value types: literal, enum
|
|
3
|
+
*/
|
|
4
|
+
export function parseLiteral(schema) {
|
|
5
|
+
return {
|
|
6
|
+
kind: "literal",
|
|
7
|
+
value: schema.const,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function parseEnum(schema) {
|
|
11
|
+
return {
|
|
12
|
+
kind: "enum",
|
|
13
|
+
values: schema.enum,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/parser/values.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC9C,OAAO;QACN,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,MAAM,CAAC,KAAK;KACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAkB;IAC3C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,MAAM,CAAC,IAAK;KACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema type definition
|
|
3
|
+
* Covers draft-3, draft-4, draft-6, draft-7, draft-2019-09, draft-2020-12, and OpenAPI 3.0
|
|
4
|
+
*/
|
|
5
|
+
export interface JSONSchema {
|
|
6
|
+
$schema?: string;
|
|
7
|
+
$id?: string;
|
|
8
|
+
$ref?: string;
|
|
9
|
+
$defs?: Record<string, JSONSchema | boolean>;
|
|
10
|
+
definitions?: Record<string, JSONSchema | boolean>;
|
|
11
|
+
$comment?: string;
|
|
12
|
+
$anchor?: string;
|
|
13
|
+
$dynamicRef?: string;
|
|
14
|
+
$dynamicAnchor?: string;
|
|
15
|
+
$vocabulary?: Record<string, boolean>;
|
|
16
|
+
type?: string | string[];
|
|
17
|
+
enum?: unknown[];
|
|
18
|
+
const?: unknown;
|
|
19
|
+
anyOf?: (JSONSchema | boolean)[];
|
|
20
|
+
oneOf?: (JSONSchema | boolean)[];
|
|
21
|
+
allOf?: (JSONSchema | boolean)[];
|
|
22
|
+
not?: JSONSchema | boolean;
|
|
23
|
+
properties?: Record<string, JSONSchema | boolean>;
|
|
24
|
+
required?: string[] | boolean;
|
|
25
|
+
additionalProperties?: boolean | JSONSchema;
|
|
26
|
+
patternProperties?: Record<string, JSONSchema | boolean>;
|
|
27
|
+
propertyNames?: JSONSchema | boolean;
|
|
28
|
+
minProperties?: number;
|
|
29
|
+
maxProperties?: number;
|
|
30
|
+
items?: JSONSchema | (JSONSchema | boolean)[] | boolean;
|
|
31
|
+
prefixItems?: (JSONSchema | boolean)[];
|
|
32
|
+
additionalItems?: boolean | JSONSchema;
|
|
33
|
+
minItems?: number;
|
|
34
|
+
maxItems?: number;
|
|
35
|
+
uniqueItems?: boolean;
|
|
36
|
+
contains?: JSONSchema | boolean;
|
|
37
|
+
minContains?: number;
|
|
38
|
+
maxContains?: number;
|
|
39
|
+
minLength?: number;
|
|
40
|
+
maxLength?: number;
|
|
41
|
+
pattern?: string;
|
|
42
|
+
format?: string;
|
|
43
|
+
minimum?: number;
|
|
44
|
+
maximum?: number;
|
|
45
|
+
exclusiveMinimum?: number;
|
|
46
|
+
exclusiveMaximum?: number;
|
|
47
|
+
multipleOf?: number;
|
|
48
|
+
description?: string;
|
|
49
|
+
default?: unknown;
|
|
50
|
+
title?: string;
|
|
51
|
+
nullable?: boolean;
|
|
52
|
+
readOnly?: boolean;
|
|
53
|
+
if?: JSONSchema | boolean;
|
|
54
|
+
then?: JSONSchema | boolean;
|
|
55
|
+
else?: JSONSchema | boolean;
|
|
56
|
+
dependentSchemas?: Record<string, JSONSchema | boolean>;
|
|
57
|
+
dependentRequired?: Record<string, string[]>;
|
|
58
|
+
dependencies?: Record<string, string[] | JSONSchema | boolean>;
|
|
59
|
+
disallow?: string | string[] | JSONSchema[];
|
|
60
|
+
extends?: JSONSchema | JSONSchema[];
|
|
61
|
+
divisibleBy?: number;
|
|
62
|
+
unevaluatedItems?: JSONSchema | boolean;
|
|
63
|
+
unevaluatedProperties?: JSONSchema | boolean;
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../../src/schema/json-schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,UAAU;IAE1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,E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AAE,MAAM,GAAG,OAAO,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../../src/schema/json-schema.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
export interface XSchemaAdapter {
|
|
2
|
-
readonly __brand: "xschema-adapter";
|
|
3
|
-
readonly name: string;
|
|
4
|
-
readonly language: string;
|
|
5
|
-
}
|
|
6
1
|
export interface ConvertInput {
|
|
7
2
|
namespace: string;
|
|
8
3
|
id: string;
|
|
4
|
+
varName: string;
|
|
9
5
|
schema: object;
|
|
10
6
|
}
|
|
11
7
|
export interface ConvertResult {
|
|
12
8
|
namespace: string;
|
|
13
9
|
id: string;
|
|
10
|
+
varName: string;
|
|
14
11
|
imports: string[];
|
|
15
|
-
schema
|
|
16
|
-
type
|
|
12
|
+
schema?: string;
|
|
13
|
+
type?: string;
|
|
14
|
+
validate?: string;
|
|
15
|
+
validationImports?: string[];
|
|
17
16
|
}
|
|
18
17
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B"}
|