schemair 0.1.0 → 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/README.md +420 -11
- package/dist/authoring/index.cjs +13 -350
- package/dist/authoring/index.d.cts +2 -90
- package/dist/authoring/index.d.ts +2 -90
- package/dist/authoring/index.js +2 -304
- package/dist/authoring-D3V0iyTe.js +362 -0
- package/dist/authoring-Dnrg5TXm.cjs +389 -0
- package/dist/chunk-BgLxgFZR.js +18 -0
- package/dist/definition/index.cjs +10 -2
- package/dist/definition/index.d.cts +3 -21
- package/dist/definition/index.d.ts +3 -21
- package/dist/definition/index.js +2 -2
- package/dist/definition-BLLBpLKv.cjs +1187 -0
- package/dist/definition-DmYnDmQO.js +1115 -0
- package/dist/index-4aMF0cTE.d.ts +368 -0
- package/dist/index-BqfGAU1K.d.ts +56 -0
- package/dist/{index-eK2Xgrwp.d.ts → index-CBbd4hXJ.d.ts} +13 -2
- package/dist/index-CIim1dG7.d.cts +92 -0
- package/dist/{index-TACcK_mi.d.cts → index-CNjYUKvu.d.cts} +13 -2
- package/dist/index-CQynt7ft.d.cts +420 -0
- package/dist/index-D3mfwaSO.d.cts +56 -0
- package/dist/index-DDMwVy2I.d.cts +368 -0
- package/dist/index-DM5DSLLL.d.ts +99 -0
- package/dist/index-DXWoNYFB.d.ts +92 -0
- package/dist/index-DhmHCGpT.d.cts +99 -0
- package/dist/index-bQy-C-1l.d.ts +418 -0
- package/dist/index.cjs +64 -52
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -5
- package/dist/integrations/json-schema/index.cjs +328 -0
- package/dist/integrations/json-schema/index.d.cts +53 -0
- package/dist/integrations/json-schema/index.d.ts +53 -0
- package/dist/integrations/json-schema/index.js +324 -0
- package/dist/integrations/standard-schema/index.cjs +32 -0
- package/dist/integrations/standard-schema/index.d.cts +22 -0
- package/dist/integrations/standard-schema/index.d.ts +22 -0
- package/dist/integrations/standard-schema/index.js +32 -0
- package/dist/payload/index.cjs +1 -1
- package/dist/payload/index.d.cts +1 -55
- package/dist/payload/index.d.ts +1 -55
- package/dist/payload/index.js +1 -1
- package/dist/relations/index.cjs +3 -1
- package/dist/relations/index.d.cts +2 -2
- package/dist/relations/index.d.ts +2 -2
- package/dist/relations/index.js +2 -2
- package/dist/{relations-CMz_0nf4.cjs → relations-Cymx4iTc.cjs} +158 -5
- package/dist/{relations-By0bK3UK.js → relations-ysXDmi-Z.js} +147 -6
- package/dist/spec/index.cjs +9 -0
- package/dist/spec/index.d.cts +2 -2
- package/dist/spec/index.d.ts +2 -2
- package/dist/spec/index.js +3 -1
- package/dist/standard/index.cjs +810 -0
- package/dist/standard/index.d.cts +3 -0
- package/dist/standard/index.d.ts +3 -0
- package/dist/standard/index.js +777 -0
- package/dist/standard-DhKsxu9U.js +471 -0
- package/dist/standard-etPFZDJI.cjs +513 -0
- package/dist/type-interpreter/index.cjs +3 -3
- package/dist/type-interpreter/index.d.cts +2 -99
- package/dist/type-interpreter/index.d.ts +2 -99
- package/dist/type-interpreter/index.js +2 -2
- package/dist/{type-interpreter-Ck0VDhzn.js → type-interpreter-DnrId8aM.js} +5 -284
- package/dist/{type-interpreter-DAIBUqKf.cjs → type-interpreter-OLt2W2yd.cjs} +15 -294
- package/package.json +38 -3
- package/dist/definition-BXj3T94L.js +0 -467
- package/dist/definition-DSZZTz4e.cjs +0 -473
- package/dist/index-CEzHfht2.d.ts +0 -269
- package/dist/index-rzkFjgrt.d.cts +0 -269
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { i as STANDARD_CONSTRAINT_PATHS, o as STANDARD_SEMANTIC_PATHS } from "../../standard-DhKsxu9U.js";
|
|
2
|
+
import { pathKey } from "../../standard/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/integrations/json-schema/index.ts
|
|
5
|
+
function diagnostic(context, code, message, path, severity = "warning") {
|
|
6
|
+
context.diagnostics.push({
|
|
7
|
+
code,
|
|
8
|
+
message,
|
|
9
|
+
path,
|
|
10
|
+
severity
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function mergeKeyword(target, source) {
|
|
14
|
+
if (source) Object.assign(target, source);
|
|
15
|
+
}
|
|
16
|
+
function extension(target, value) {
|
|
17
|
+
const existing = target["x-schemair"];
|
|
18
|
+
target["x-schemair"] = {
|
|
19
|
+
...existing && typeof existing === "object" && !Array.isArray(existing) ? existing : {},
|
|
20
|
+
...value,
|
|
21
|
+
version: 1
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function standardSemantic(path, node) {
|
|
25
|
+
const key = pathKey(path);
|
|
26
|
+
const stringFormats = {
|
|
27
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.date)]: "date",
|
|
28
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.datetime)]: "date-time",
|
|
29
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.datetimeIso)]: "date-time",
|
|
30
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.email)]: "email",
|
|
31
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.url)]: "uri",
|
|
32
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.ipV4)]: "ipv4",
|
|
33
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.ipV6)]: "ipv6",
|
|
34
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.uuid)]: "uuid",
|
|
35
|
+
[pathKey(STANDARD_SEMANTIC_PATHS.string.uuidV4)]: "uuid"
|
|
36
|
+
};
|
|
37
|
+
if (node.name === "string" && stringFormats[key]) return { format: stringFormats[key] };
|
|
38
|
+
if (node.name === "number" && key === pathKey(STANDARD_SEMANTIC_PATHS.number.integer)) return { type: "integer" };
|
|
39
|
+
if (node.name === "number" && key === pathKey(STANDARD_SEMANTIC_PATHS.number.safeInteger)) return {
|
|
40
|
+
type: "integer",
|
|
41
|
+
minimum: -9007199254740991,
|
|
42
|
+
maximum: 9007199254740991
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function standardConstraint(constraint, target) {
|
|
46
|
+
const key = pathKey(constraint.constraintPath);
|
|
47
|
+
const value = constraint.args;
|
|
48
|
+
switch (key) {
|
|
49
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.string.minLength): return typeof value === "number" ? { minLength: value } : void 0;
|
|
50
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.string.maxLength): return typeof value === "number" ? { maxLength: value } : void 0;
|
|
51
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.string.pattern): return typeof value === "string" ? { pattern: value } : void 0;
|
|
52
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.number.minimum): return typeof value === "number" ? { minimum: value } : void 0;
|
|
53
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.number.maximum): return typeof value === "number" ? { maximum: value } : void 0;
|
|
54
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.number.exclusiveMinimum): return typeof value === "number" ? target === "draft-2020-12" ? { exclusiveMinimum: value } : {
|
|
55
|
+
minimum: value,
|
|
56
|
+
exclusiveMinimum: true
|
|
57
|
+
} : void 0;
|
|
58
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.number.exclusiveMaximum): return typeof value === "number" ? target === "draft-2020-12" ? { exclusiveMaximum: value } : {
|
|
59
|
+
maximum: value,
|
|
60
|
+
exclusiveMaximum: true
|
|
61
|
+
} : void 0;
|
|
62
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.number.multipleOf): return typeof value === "number" ? { multipleOf: value } : void 0;
|
|
63
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.array.minItems): return typeof value === "number" ? { minItems: value } : void 0;
|
|
64
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.array.maxItems): return typeof value === "number" ? { maxItems: value } : void 0;
|
|
65
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.array.uniqueItems): return typeof value === "boolean" ? { uniqueItems: value } : void 0;
|
|
66
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.record.minProperties): return typeof value === "number" ? { minProperties: value } : void 0;
|
|
67
|
+
case pathKey(STANDARD_CONSTRAINT_PATHS.record.maxProperties): return typeof value === "number" ? { maxProperties: value } : void 0;
|
|
68
|
+
default: return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function applyMetadata(target, node, context, path) {
|
|
72
|
+
if ("semanticPath" in node && node.semanticPath) {
|
|
73
|
+
const custom = context.options.semanticMapper?.(node.semanticPath, node);
|
|
74
|
+
const mapped = custom ?? standardSemantic(node.semanticPath, node);
|
|
75
|
+
if (mapped) {
|
|
76
|
+
mergeKeyword(target, mapped);
|
|
77
|
+
extension(target, { semanticPath: node.semanticPath });
|
|
78
|
+
if (custom === void 0) diagnostic(context, "semantic.lossy", `Semantic path ${node.semanticPath.join("/")} is approximated by JSON Schema keywords`, path);
|
|
79
|
+
} else {
|
|
80
|
+
extension(target, { semanticPath: node.semanticPath });
|
|
81
|
+
diagnostic(context, "semantic.unmapped", `Semantic path ${node.semanticPath.join("/")} has no lossless JSON Schema mapping`, path);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if ("constraints" in node && node.constraints) for (const constraint of node.constraints) {
|
|
85
|
+
const mapped = context.options.constraintMapper?.(constraint, node) ?? standardConstraint(constraint, context.target);
|
|
86
|
+
if (mapped) mergeKeyword(target, mapped);
|
|
87
|
+
else {
|
|
88
|
+
const prior = target["x-schemair"];
|
|
89
|
+
const meta = prior && typeof prior === "object" && !Array.isArray(prior) ? prior : {};
|
|
90
|
+
extension(target, { constraints: [...Array.isArray(meta.constraints) ? meta.constraints : [], {
|
|
91
|
+
constraintPath: [...constraint.constraintPath],
|
|
92
|
+
...constraint.args === void 0 ? {} : { args: constraint.args }
|
|
93
|
+
}] });
|
|
94
|
+
diagnostic(context, "constraint.unmapped", `Constraint ${constraint.constraintPath.join("/")} has no lossless JSON Schema mapping`, path);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function project(node, context, path) {
|
|
99
|
+
if (context.stack.includes(node)) {
|
|
100
|
+
diagnostic(context, "schema.cycle", "Cyclic schema graph requires an explicit ref strategy", path, "error");
|
|
101
|
+
const cycle = {};
|
|
102
|
+
extension(cycle, { selfRef: true });
|
|
103
|
+
return cycle;
|
|
104
|
+
}
|
|
105
|
+
context.stack.push(node);
|
|
106
|
+
let result;
|
|
107
|
+
switch (node.kind) {
|
|
108
|
+
case "primitive":
|
|
109
|
+
if (context.target === "openapi-3.0" && node.name === "null") {
|
|
110
|
+
result = {};
|
|
111
|
+
extension(result, { original: {
|
|
112
|
+
kind: "primitive",
|
|
113
|
+
name: "null"
|
|
114
|
+
} });
|
|
115
|
+
diagnostic(context, "openapi.null.unsupported", "OpenAPI 3.0 Schema Objects cannot represent a standalone null type", path, "error");
|
|
116
|
+
} else result = { type: node.name === "null" ? "null" : node.name };
|
|
117
|
+
applyMetadata(result, node, context, path);
|
|
118
|
+
break;
|
|
119
|
+
case "literal":
|
|
120
|
+
if (context.target === "openapi-3.0") {
|
|
121
|
+
result = { enum: [node.literal] };
|
|
122
|
+
extension(result, { literal: node.literal });
|
|
123
|
+
diagnostic(context, "openapi.literal.lossy", "OpenAPI 3.0 has no const keyword; the literal is projected as a single-value enum", path);
|
|
124
|
+
} else result = { const: node.literal };
|
|
125
|
+
break;
|
|
126
|
+
case "literalUnion":
|
|
127
|
+
result = { enum: [...node.values] };
|
|
128
|
+
extension(result, { union: {
|
|
129
|
+
kind: "literalUnion",
|
|
130
|
+
values: [...node.values]
|
|
131
|
+
} });
|
|
132
|
+
break;
|
|
133
|
+
case "nullable": {
|
|
134
|
+
const inner = project(node.value, context, [...path, "value"]);
|
|
135
|
+
if (context.target === "openapi-3.0") {
|
|
136
|
+
result = {
|
|
137
|
+
...inner,
|
|
138
|
+
nullable: true
|
|
139
|
+
};
|
|
140
|
+
extension(result, { union: {
|
|
141
|
+
kind: "nullable",
|
|
142
|
+
value: true
|
|
143
|
+
} });
|
|
144
|
+
diagnostic(context, "openapi.nullable.lossy", "OpenAPI 3.0 nullable is preserved as an extension because it is not equivalent to JSON Schema null union semantics", path);
|
|
145
|
+
} else result = { anyOf: [inner, { type: "null" }] };
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case "array":
|
|
149
|
+
result = {
|
|
150
|
+
type: "array",
|
|
151
|
+
items: project(node.elementSchema, context, [...path, "elementSchema"])
|
|
152
|
+
};
|
|
153
|
+
applyMetadata(result, node, context, path);
|
|
154
|
+
break;
|
|
155
|
+
case "tuple":
|
|
156
|
+
if (context.target === "draft-07") result = {
|
|
157
|
+
type: "array",
|
|
158
|
+
items: node.elementSchemas.map((item, index) => project(item, context, [
|
|
159
|
+
...path,
|
|
160
|
+
"elementSchemas",
|
|
161
|
+
index
|
|
162
|
+
])),
|
|
163
|
+
additionalItems: false,
|
|
164
|
+
minItems: node.elementSchemas.length,
|
|
165
|
+
maxItems: node.elementSchemas.length
|
|
166
|
+
};
|
|
167
|
+
else if (context.target === "openapi-3.0") {
|
|
168
|
+
const elements = node.elementSchemas.map((item, index) => project(item, context, [
|
|
169
|
+
...path,
|
|
170
|
+
"elementSchemas",
|
|
171
|
+
index
|
|
172
|
+
]));
|
|
173
|
+
result = {
|
|
174
|
+
type: "array",
|
|
175
|
+
items: {}
|
|
176
|
+
};
|
|
177
|
+
extension(result, { union: {
|
|
178
|
+
kind: "tuple",
|
|
179
|
+
length: node.elementSchemas.length,
|
|
180
|
+
elementSchemas: elements
|
|
181
|
+
} });
|
|
182
|
+
diagnostic(context, "openapi.tuple.lossy", "OpenAPI 3.0 has no tuple form; tuple position schemas are retained only in x-schemair", path);
|
|
183
|
+
} else result = {
|
|
184
|
+
type: "array",
|
|
185
|
+
prefixItems: node.elementSchemas.map((item, index) => project(item, context, [
|
|
186
|
+
...path,
|
|
187
|
+
"elementSchemas",
|
|
188
|
+
index
|
|
189
|
+
])),
|
|
190
|
+
items: false,
|
|
191
|
+
minItems: node.elementSchemas.length,
|
|
192
|
+
maxItems: node.elementSchemas.length
|
|
193
|
+
};
|
|
194
|
+
break;
|
|
195
|
+
case "record": {
|
|
196
|
+
const properties = {};
|
|
197
|
+
const required = [];
|
|
198
|
+
for (const field of node.fields) {
|
|
199
|
+
properties[field.key] = project(field.schema, context, [
|
|
200
|
+
...path,
|
|
201
|
+
"fields",
|
|
202
|
+
field.key
|
|
203
|
+
]);
|
|
204
|
+
if (field.required) required.push(field.key);
|
|
205
|
+
}
|
|
206
|
+
result = {
|
|
207
|
+
type: "object",
|
|
208
|
+
properties
|
|
209
|
+
};
|
|
210
|
+
if (required.length) result.required = required;
|
|
211
|
+
if (node.additionalFields === void 0) result.additionalProperties = false;
|
|
212
|
+
else if (node.additionalFields === true) result.additionalProperties = true;
|
|
213
|
+
else result.additionalProperties = project(node.additionalFields, context, [...path, "additionalFields"]);
|
|
214
|
+
applyMetadata(result, node, context, path);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case "taggedUnion":
|
|
218
|
+
result = { oneOf: node.variants.map((variant, index) => project(variant.schema, context, [
|
|
219
|
+
...path,
|
|
220
|
+
"variants",
|
|
221
|
+
index
|
|
222
|
+
])) };
|
|
223
|
+
extension(result, { union: {
|
|
224
|
+
kind: "taggedUnion",
|
|
225
|
+
discriminator: node.discriminator,
|
|
226
|
+
variants: node.variants.map((variant) => ({
|
|
227
|
+
key: variant.key,
|
|
228
|
+
description: variant.description ?? null
|
|
229
|
+
}))
|
|
230
|
+
} });
|
|
231
|
+
diagnostic(context, "union.tagged.lossy", "SchemaIR tagged-union keys are not JSON Schema validation semantics", path);
|
|
232
|
+
break;
|
|
233
|
+
case "ref": {
|
|
234
|
+
const reference = context.options.refStrategy?.(node.refPath);
|
|
235
|
+
result = reference ? { $ref: reference } : {};
|
|
236
|
+
if (!reference) {
|
|
237
|
+
extension(result, { refPath: node.refPath });
|
|
238
|
+
diagnostic(context, "ref.unresolved", `No JSON Schema ref strategy resolved ${node.refPath.join("/")}`, path, "error");
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
case "selfRef":
|
|
243
|
+
result = {};
|
|
244
|
+
extension(result, { selfRef: true });
|
|
245
|
+
diagnostic(context, "ref.self", "selfRef needs a caller-owned JSON Schema anchor strategy", path, "error");
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
context.stack.pop();
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
function fidelity(diagnostics) {
|
|
252
|
+
if (diagnostics.some((item) => item.severity === "error")) return "unsupported";
|
|
253
|
+
if (diagnostics.length) return "lossy";
|
|
254
|
+
return "exact";
|
|
255
|
+
}
|
|
256
|
+
/** Project a SchemaNode into JSON Schema Draft 2020-12 without hiding loss. */
|
|
257
|
+
function schemaNodeToJsonSchema(node, options = {}) {
|
|
258
|
+
const target = options.target ?? "draft-2020-12";
|
|
259
|
+
if (target === "openapi-3.0") return schemaNodeToOpenApiSchema(node, options);
|
|
260
|
+
const context = {
|
|
261
|
+
options,
|
|
262
|
+
target,
|
|
263
|
+
diagnostics: [],
|
|
264
|
+
stack: []
|
|
265
|
+
};
|
|
266
|
+
return {
|
|
267
|
+
schema: project(node, context, []),
|
|
268
|
+
fidelity: fidelity(context.diagnostics),
|
|
269
|
+
diagnostics: context.diagnostics
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/** Project a SchemaNode to an OpenAPI 3.0 Schema Object. */
|
|
273
|
+
function schemaNodeToOpenApiSchema(node, options = {}) {
|
|
274
|
+
const context = {
|
|
275
|
+
options,
|
|
276
|
+
target: "openapi-3.0",
|
|
277
|
+
diagnostics: [],
|
|
278
|
+
stack: []
|
|
279
|
+
};
|
|
280
|
+
return {
|
|
281
|
+
schema: project(node, context, []),
|
|
282
|
+
fidelity: fidelity(context.diagnostics),
|
|
283
|
+
diagnostics: context.diagnostics
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/** Alias emphasizing that this is a diagnostic-bearing projection operation. */
|
|
287
|
+
const schemaNodeToJsonSchemaWithDiagnostics = schemaNodeToJsonSchema;
|
|
288
|
+
/**
|
|
289
|
+
* Expose a runtime SchemaIR declaration through Standard JSON Schema V1.
|
|
290
|
+
*
|
|
291
|
+
* SchemaIR declarations do not perform input/output transformations, so both
|
|
292
|
+
* converter methods project the same contract. Lossy projections are allowed
|
|
293
|
+
* because their preserved metadata remains in `x-schemair`; unsupported
|
|
294
|
+
* projections throw as required by the Standard JSON Schema protocol.
|
|
295
|
+
*/
|
|
296
|
+
function schemaIRToStandardJsonSchema(node, options = {}) {
|
|
297
|
+
const convert = (target) => {
|
|
298
|
+
const { target: _ignoredTarget, ...projectionOptions } = options;
|
|
299
|
+
const projectionTarget = target === "openapi-3.0" || target === "draft-2020-12" || target === "draft-07" ? target : void 0;
|
|
300
|
+
const result = projectionTarget === "openapi-3.0" ? schemaNodeToOpenApiSchema(node, projectionOptions) : projectionTarget ? schemaNodeToJsonSchema(node, {
|
|
301
|
+
...projectionOptions,
|
|
302
|
+
target: projectionTarget
|
|
303
|
+
}) : void 0;
|
|
304
|
+
if (!result) throw new Error(`SchemaIR Standard JSON Schema adapter does not support target ${target}`);
|
|
305
|
+
if (result.fidelity === "unsupported") {
|
|
306
|
+
const details = result.diagnostics.map((item) => item.message).join("; ");
|
|
307
|
+
throw new Error(`SchemaIR cannot be represented as JSON Schema: ${details}`);
|
|
308
|
+
}
|
|
309
|
+
return result.schema;
|
|
310
|
+
};
|
|
311
|
+
return { "~standard": {
|
|
312
|
+
version: 1,
|
|
313
|
+
vendor: "schemair",
|
|
314
|
+
jsonSchema: {
|
|
315
|
+
input: ({ target }) => convert(target),
|
|
316
|
+
output: ({ target }) => convert(target)
|
|
317
|
+
}
|
|
318
|
+
} };
|
|
319
|
+
}
|
|
320
|
+
/** Uppercase acronym alias matching the protocol name. */
|
|
321
|
+
const schemaIRToStandardJSONSchema = schemaIRToStandardJsonSchema;
|
|
322
|
+
|
|
323
|
+
//#endregion
|
|
324
|
+
export { schemaIRToStandardJSONSchema, schemaIRToStandardJsonSchema, schemaNodeToJsonSchema, schemaNodeToJsonSchemaWithDiagnostics, schemaNodeToOpenApiSchema };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const require_payload_index = require('../../payload/index.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/integrations/standard-schema/index.ts
|
|
4
|
+
function toStandardIssue(issue) {
|
|
5
|
+
const path = issue.path.length > 0 ? [...issue.path] : void 0;
|
|
6
|
+
return path === void 0 ? { message: issue.message } : {
|
|
7
|
+
message: issue.message,
|
|
8
|
+
path
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Expose a serializable SchemaIR declaration through the Standard Schema
|
|
13
|
+
* runtime protocol. Validation is always asynchronous so caller-owned refs
|
|
14
|
+
* and semantic/constraint providers can use async implementations.
|
|
15
|
+
*
|
|
16
|
+
* The adapter never transforms a payload and intentionally does not expose
|
|
17
|
+
* `~standard.types` because the declaration is runtime data.
|
|
18
|
+
*/
|
|
19
|
+
function schemaIRToStandardSchema(schema, options = {}) {
|
|
20
|
+
return { "~standard": {
|
|
21
|
+
version: 1,
|
|
22
|
+
vendor: "schemair",
|
|
23
|
+
validate: async (value) => {
|
|
24
|
+
const result = await require_payload_index.validatePayloadAsync(value, schema, options);
|
|
25
|
+
if (result.status === "accepted") return { value };
|
|
26
|
+
return { issues: result.issues.map(toStandardIssue) };
|
|
27
|
+
}
|
|
28
|
+
} };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.schemaIRToStandardSchema = schemaIRToStandardSchema;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ct as SchemaNode } from "../../index-DDMwVy2I.cjs";
|
|
2
|
+
import { t as AsyncPayloadValidationContext } from "../../index-D3mfwaSO.cjs";
|
|
3
|
+
import { StandardSchemaV1, StandardSchemaV1 as StandardSchemaV1$1 } from "@standard-schema/spec";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/standard-schema/index.d.ts
|
|
6
|
+
/** Options captured by a Standard Schema adapter at construction time. */
|
|
7
|
+
type StandardSchemaAdapterOptions = AsyncPayloadValidationContext;
|
|
8
|
+
/** Runtime-only Standard Schema surface for a dynamic SchemaIR declaration. */
|
|
9
|
+
type SchemaIRStandardSchema = {
|
|
10
|
+
readonly '~standard': Omit<StandardSchemaV1$1.Props, 'types'>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Expose a serializable SchemaIR declaration through the Standard Schema
|
|
14
|
+
* runtime protocol. Validation is always asynchronous so caller-owned refs
|
|
15
|
+
* and semantic/constraint providers can use async implementations.
|
|
16
|
+
*
|
|
17
|
+
* The adapter never transforms a payload and intentionally does not expose
|
|
18
|
+
* `~standard.types` because the declaration is runtime data.
|
|
19
|
+
*/
|
|
20
|
+
declare function schemaIRToStandardSchema(schema: SchemaNode, options?: StandardSchemaAdapterOptions): SchemaIRStandardSchema;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SchemaIRStandardSchema, StandardSchemaAdapterOptions, type StandardSchemaV1, schemaIRToStandardSchema };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ct as SchemaNode } from "../../index-4aMF0cTE.js";
|
|
2
|
+
import { t as AsyncPayloadValidationContext } from "../../index-BqfGAU1K.js";
|
|
3
|
+
import { StandardSchemaV1, StandardSchemaV1 as StandardSchemaV1$1 } from "@standard-schema/spec";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/standard-schema/index.d.ts
|
|
6
|
+
/** Options captured by a Standard Schema adapter at construction time. */
|
|
7
|
+
type StandardSchemaAdapterOptions = AsyncPayloadValidationContext;
|
|
8
|
+
/** Runtime-only Standard Schema surface for a dynamic SchemaIR declaration. */
|
|
9
|
+
type SchemaIRStandardSchema = {
|
|
10
|
+
readonly '~standard': Omit<StandardSchemaV1$1.Props, 'types'>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Expose a serializable SchemaIR declaration through the Standard Schema
|
|
14
|
+
* runtime protocol. Validation is always asynchronous so caller-owned refs
|
|
15
|
+
* and semantic/constraint providers can use async implementations.
|
|
16
|
+
*
|
|
17
|
+
* The adapter never transforms a payload and intentionally does not expose
|
|
18
|
+
* `~standard.types` because the declaration is runtime data.
|
|
19
|
+
*/
|
|
20
|
+
declare function schemaIRToStandardSchema(schema: SchemaNode, options?: StandardSchemaAdapterOptions): SchemaIRStandardSchema;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SchemaIRStandardSchema, StandardSchemaAdapterOptions, type StandardSchemaV1, schemaIRToStandardSchema };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { validatePayloadAsync } from "../../payload/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/integrations/standard-schema/index.ts
|
|
4
|
+
function toStandardIssue(issue) {
|
|
5
|
+
const path = issue.path.length > 0 ? [...issue.path] : void 0;
|
|
6
|
+
return path === void 0 ? { message: issue.message } : {
|
|
7
|
+
message: issue.message,
|
|
8
|
+
path
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Expose a serializable SchemaIR declaration through the Standard Schema
|
|
13
|
+
* runtime protocol. Validation is always asynchronous so caller-owned refs
|
|
14
|
+
* and semantic/constraint providers can use async implementations.
|
|
15
|
+
*
|
|
16
|
+
* The adapter never transforms a payload and intentionally does not expose
|
|
17
|
+
* `~standard.types` because the declaration is runtime data.
|
|
18
|
+
*/
|
|
19
|
+
function schemaIRToStandardSchema(schema, options = {}) {
|
|
20
|
+
return { "~standard": {
|
|
21
|
+
version: 1,
|
|
22
|
+
vendor: "schemair",
|
|
23
|
+
validate: async (value) => {
|
|
24
|
+
const result = await validatePayloadAsync(value, schema, options);
|
|
25
|
+
if (result.status === "accepted") return { value };
|
|
26
|
+
return { issues: result.issues.map(toStandardIssue) };
|
|
27
|
+
}
|
|
28
|
+
} };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { schemaIRToStandardSchema };
|
package/dist/payload/index.cjs
CHANGED
package/dist/payload/index.d.cts
CHANGED
|
@@ -1,56 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/payload/validator.d.ts
|
|
4
|
-
type PayloadPath = readonly (string | number)[];
|
|
5
|
-
interface PayloadValidationDiagnostic {
|
|
6
|
-
readonly code: string;
|
|
7
|
-
readonly path: PayloadPath;
|
|
8
|
-
readonly message: string;
|
|
9
|
-
}
|
|
10
|
-
type PayloadValidationResult = {
|
|
11
|
-
readonly status: 'accepted';
|
|
12
|
-
readonly issues: readonly [];
|
|
13
|
-
} | {
|
|
14
|
-
readonly status: 'rejected' | 'unknown';
|
|
15
|
-
readonly issues: readonly PayloadValidationDiagnostic[];
|
|
16
|
-
};
|
|
17
|
-
type PayloadProviderDecision = boolean | {
|
|
18
|
-
readonly status: 'accepted' | 'rejected' | 'unknown' | 'unsupported';
|
|
19
|
-
readonly message?: string;
|
|
20
|
-
};
|
|
21
|
-
interface PayloadProviderContext {
|
|
22
|
-
readonly path: PayloadPath;
|
|
23
|
-
readonly schema: SchemaNode;
|
|
24
|
-
readonly rootSchema: SchemaNode;
|
|
25
|
-
}
|
|
26
|
-
interface PayloadResolutionContext extends PayloadProviderContext {
|
|
27
|
-
readonly refPath: readonly string[];
|
|
28
|
-
}
|
|
29
|
-
type PayloadResolution = SchemaNode | {
|
|
30
|
-
readonly status: 'resolved';
|
|
31
|
-
readonly schema: SchemaNode;
|
|
32
|
-
} | {
|
|
33
|
-
readonly status: 'unknown' | 'unsupported';
|
|
34
|
-
readonly message?: string;
|
|
35
|
-
} | undefined;
|
|
36
|
-
type SemanticProvider = (semanticPath: readonly string[], value: unknown, context: PayloadProviderContext) => PayloadProviderDecision | Promise<PayloadProviderDecision | undefined> | undefined;
|
|
37
|
-
type ConstraintProvider = (constraintPath: readonly string[], args: unknown, value: unknown, context: PayloadProviderContext) => PayloadProviderDecision | Promise<PayloadProviderDecision | undefined> | undefined;
|
|
38
|
-
type SyncSemanticProvider = (semanticPath: readonly string[], value: unknown, context: PayloadProviderContext) => PayloadProviderDecision | undefined;
|
|
39
|
-
type SyncConstraintProvider = (constraintPath: readonly string[], args: unknown, value: unknown, context: PayloadProviderContext) => PayloadProviderDecision | undefined;
|
|
40
|
-
type SyncPayloadResolution = PayloadResolution;
|
|
41
|
-
interface SyncPayloadValidationContext {
|
|
42
|
-
readonly resolveRef?: (refPath: readonly string[], context: PayloadResolutionContext) => SyncPayloadResolution;
|
|
43
|
-
readonly semanticProvider?: SyncSemanticProvider;
|
|
44
|
-
readonly constraintProvider?: SyncConstraintProvider;
|
|
45
|
-
}
|
|
46
|
-
interface PayloadValidationContext {
|
|
47
|
-
readonly resolveRef?: (refPath: readonly string[], context: PayloadResolutionContext) => PayloadResolution | Promise<PayloadResolution>;
|
|
48
|
-
readonly semanticProvider?: SemanticProvider;
|
|
49
|
-
readonly constraintProvider?: ConstraintProvider;
|
|
50
|
-
}
|
|
51
|
-
/** Context accepted by the asynchronous payload validation entry point. */
|
|
52
|
-
type AsyncPayloadValidationContext = PayloadValidationContext;
|
|
53
|
-
declare function validatePayload(value: unknown, schema: SchemaNode, context?: SyncPayloadValidationContext): PayloadValidationResult;
|
|
54
|
-
declare function validatePayloadAsync(value: unknown, schema: SchemaNode, context?: AsyncPayloadValidationContext): Promise<PayloadValidationResult>;
|
|
55
|
-
//#endregion
|
|
1
|
+
import { _ as validatePayloadAsync, a as PayloadProviderDecision, c as PayloadValidationContext, d as SemanticProvider, f as SyncConstraintProvider, g as validatePayload, h as SyncSemanticProvider, i as PayloadProviderContext, l as PayloadValidationDiagnostic, m as SyncPayloadValidationContext, n as ConstraintProvider, o as PayloadResolution, p as SyncPayloadResolution, r as PayloadPath, s as PayloadResolutionContext, t as AsyncPayloadValidationContext, u as PayloadValidationResult } from "../index-D3mfwaSO.cjs";
|
|
56
2
|
export { AsyncPayloadValidationContext, ConstraintProvider, PayloadPath, PayloadProviderContext, PayloadProviderDecision, PayloadResolution, PayloadResolutionContext, PayloadValidationContext, PayloadValidationDiagnostic, PayloadValidationResult, SemanticProvider, SyncConstraintProvider, SyncPayloadResolution, SyncPayloadValidationContext, SyncSemanticProvider, validatePayload, validatePayloadAsync };
|
package/dist/payload/index.d.ts
CHANGED
|
@@ -1,56 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/payload/validator.d.ts
|
|
4
|
-
type PayloadPath = readonly (string | number)[];
|
|
5
|
-
interface PayloadValidationDiagnostic {
|
|
6
|
-
readonly code: string;
|
|
7
|
-
readonly path: PayloadPath;
|
|
8
|
-
readonly message: string;
|
|
9
|
-
}
|
|
10
|
-
type PayloadValidationResult = {
|
|
11
|
-
readonly status: 'accepted';
|
|
12
|
-
readonly issues: readonly [];
|
|
13
|
-
} | {
|
|
14
|
-
readonly status: 'rejected' | 'unknown';
|
|
15
|
-
readonly issues: readonly PayloadValidationDiagnostic[];
|
|
16
|
-
};
|
|
17
|
-
type PayloadProviderDecision = boolean | {
|
|
18
|
-
readonly status: 'accepted' | 'rejected' | 'unknown' | 'unsupported';
|
|
19
|
-
readonly message?: string;
|
|
20
|
-
};
|
|
21
|
-
interface PayloadProviderContext {
|
|
22
|
-
readonly path: PayloadPath;
|
|
23
|
-
readonly schema: SchemaNode;
|
|
24
|
-
readonly rootSchema: SchemaNode;
|
|
25
|
-
}
|
|
26
|
-
interface PayloadResolutionContext extends PayloadProviderContext {
|
|
27
|
-
readonly refPath: readonly string[];
|
|
28
|
-
}
|
|
29
|
-
type PayloadResolution = SchemaNode | {
|
|
30
|
-
readonly status: 'resolved';
|
|
31
|
-
readonly schema: SchemaNode;
|
|
32
|
-
} | {
|
|
33
|
-
readonly status: 'unknown' | 'unsupported';
|
|
34
|
-
readonly message?: string;
|
|
35
|
-
} | undefined;
|
|
36
|
-
type SemanticProvider = (semanticPath: readonly string[], value: unknown, context: PayloadProviderContext) => PayloadProviderDecision | Promise<PayloadProviderDecision | undefined> | undefined;
|
|
37
|
-
type ConstraintProvider = (constraintPath: readonly string[], args: unknown, value: unknown, context: PayloadProviderContext) => PayloadProviderDecision | Promise<PayloadProviderDecision | undefined> | undefined;
|
|
38
|
-
type SyncSemanticProvider = (semanticPath: readonly string[], value: unknown, context: PayloadProviderContext) => PayloadProviderDecision | undefined;
|
|
39
|
-
type SyncConstraintProvider = (constraintPath: readonly string[], args: unknown, value: unknown, context: PayloadProviderContext) => PayloadProviderDecision | undefined;
|
|
40
|
-
type SyncPayloadResolution = PayloadResolution;
|
|
41
|
-
interface SyncPayloadValidationContext {
|
|
42
|
-
readonly resolveRef?: (refPath: readonly string[], context: PayloadResolutionContext) => SyncPayloadResolution;
|
|
43
|
-
readonly semanticProvider?: SyncSemanticProvider;
|
|
44
|
-
readonly constraintProvider?: SyncConstraintProvider;
|
|
45
|
-
}
|
|
46
|
-
interface PayloadValidationContext {
|
|
47
|
-
readonly resolveRef?: (refPath: readonly string[], context: PayloadResolutionContext) => PayloadResolution | Promise<PayloadResolution>;
|
|
48
|
-
readonly semanticProvider?: SemanticProvider;
|
|
49
|
-
readonly constraintProvider?: ConstraintProvider;
|
|
50
|
-
}
|
|
51
|
-
/** Context accepted by the asynchronous payload validation entry point. */
|
|
52
|
-
type AsyncPayloadValidationContext = PayloadValidationContext;
|
|
53
|
-
declare function validatePayload(value: unknown, schema: SchemaNode, context?: SyncPayloadValidationContext): PayloadValidationResult;
|
|
54
|
-
declare function validatePayloadAsync(value: unknown, schema: SchemaNode, context?: AsyncPayloadValidationContext): Promise<PayloadValidationResult>;
|
|
55
|
-
//#endregion
|
|
1
|
+
import { _ as validatePayloadAsync, a as PayloadProviderDecision, c as PayloadValidationContext, d as SemanticProvider, f as SyncConstraintProvider, g as validatePayload, h as SyncSemanticProvider, i as PayloadProviderContext, l as PayloadValidationDiagnostic, m as SyncPayloadValidationContext, n as ConstraintProvider, o as PayloadResolution, p as SyncPayloadResolution, r as PayloadPath, s as PayloadResolutionContext, t as AsyncPayloadValidationContext, u as PayloadValidationResult } from "../index-BqfGAU1K.js";
|
|
56
2
|
export { AsyncPayloadValidationContext, ConstraintProvider, PayloadPath, PayloadProviderContext, PayloadProviderDecision, PayloadResolution, PayloadResolutionContext, PayloadValidationContext, PayloadValidationDiagnostic, PayloadValidationResult, SemanticProvider, SyncConstraintProvider, SyncPayloadResolution, SyncPayloadValidationContext, SyncSemanticProvider, validatePayload, validatePayloadAsync };
|
package/dist/payload/index.js
CHANGED
package/dist/relations/index.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const require_relations = require('../relations-
|
|
1
|
+
const require_relations = require('../relations-Cymx4iTc.cjs');
|
|
2
2
|
|
|
3
|
+
exports.checkOperationRelation = require_relations.checkOperationRelation;
|
|
4
|
+
exports.checkOperationRelationAsync = require_relations.checkOperationRelationAsync;
|
|
3
5
|
exports.checkSchemaAssignability = require_relations.checkSchemaAssignability;
|
|
4
6
|
exports.checkSchemaAssignabilityAsync = require_relations.checkSchemaAssignabilityAsync;
|
|
5
7
|
exports.checkSchemaRelation = require_relations.checkSchemaRelation;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { AsyncRelationContext, RelationContext, RelationDiagnostic, RelationPath, RelationProviderContext, RelationProviderDecision, RelationResolution, RelationResolutionContext, RelationResult, RelationSide, RelationStatus, checkSchemaAssignability, checkSchemaAssignabilityAsync, checkSchemaRelation, checkSchemaRelationAsync };
|
|
1
|
+
import { _ as checkSchemaAssignabilityAsync, a as AsyncRelationContext, c as RelationPath, d as RelationResolution, f as RelationResolutionContext, g as checkSchemaAssignability, h as RelationStatus, i as checkOperationRelationAsync, l as RelationProviderContext, m as RelationSide, n as OperationRelationDirection, o as RelationContext, p as RelationResult, r as checkOperationRelation, s as RelationDiagnostic, t as OperationRelationComponent, u as RelationProviderDecision, v as checkSchemaRelation, y as checkSchemaRelationAsync } from "../index-CNjYUKvu.cjs";
|
|
2
|
+
export { AsyncRelationContext, OperationRelationComponent, OperationRelationDirection, RelationContext, RelationDiagnostic, RelationPath, RelationProviderContext, RelationProviderDecision, RelationResolution, RelationResolutionContext, RelationResult, RelationSide, RelationStatus, checkOperationRelation, checkOperationRelationAsync, checkSchemaAssignability, checkSchemaAssignabilityAsync, checkSchemaRelation, checkSchemaRelationAsync };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { AsyncRelationContext, RelationContext, RelationDiagnostic, RelationPath, RelationProviderContext, RelationProviderDecision, RelationResolution, RelationResolutionContext, RelationResult, RelationSide, RelationStatus, checkSchemaAssignability, checkSchemaAssignabilityAsync, checkSchemaRelation, checkSchemaRelationAsync };
|
|
1
|
+
import { _ as checkSchemaAssignabilityAsync, a as AsyncRelationContext, c as RelationPath, d as RelationResolution, f as RelationResolutionContext, g as checkSchemaAssignability, h as RelationStatus, i as checkOperationRelationAsync, l as RelationProviderContext, m as RelationSide, n as OperationRelationDirection, o as RelationContext, p as RelationResult, r as checkOperationRelation, s as RelationDiagnostic, t as OperationRelationComponent, u as RelationProviderDecision, v as checkSchemaRelation, y as checkSchemaRelationAsync } from "../index-CBbd4hXJ.js";
|
|
2
|
+
export { AsyncRelationContext, OperationRelationComponent, OperationRelationDirection, RelationContext, RelationDiagnostic, RelationPath, RelationProviderContext, RelationProviderDecision, RelationResolution, RelationResolutionContext, RelationResult, RelationSide, RelationStatus, checkOperationRelation, checkOperationRelationAsync, checkSchemaAssignability, checkSchemaAssignabilityAsync, checkSchemaRelation, checkSchemaRelationAsync };
|
package/dist/relations/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { a as checkSchemaRelation, i as checkSchemaAssignabilityAsync, n as checkOperationRelationAsync, o as checkSchemaRelationAsync, r as checkSchemaAssignability, t as checkOperationRelation } from "../relations-ysXDmi-Z.js";
|
|
2
2
|
|
|
3
|
-
export { checkSchemaAssignability, checkSchemaAssignabilityAsync, checkSchemaRelation, checkSchemaRelationAsync };
|
|
3
|
+
export { checkOperationRelation, checkOperationRelationAsync, checkSchemaAssignability, checkSchemaAssignabilityAsync, checkSchemaRelation, checkSchemaRelationAsync };
|