schema-truth 0.7.0 → 0.8.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/dist/{ajv-DTP2FXRr.js → ajv-DS9gtNZC.js} +1 -1
- package/dist/ajv.d.ts +1 -1
- package/dist/ajv.js +1 -1
- package/dist/{arktype-BdvvaBQX.js → arktype-CRZ8vXZ5.js} +94 -37
- package/dist/arktype.d.ts +3 -3
- package/dist/arktype.js +1 -1
- package/dist/cli/ajv.js +2 -2
- package/dist/cli/arktype.js +2 -2
- package/dist/cli/effect.js +2 -2
- package/dist/cli/typebox.js +2 -2
- package/dist/cli/valibot.js +2 -2
- package/dist/cli/yup.js +2 -2
- package/dist/cli/zod.js +2 -2
- package/dist/{cli-CL2mSark.js → cli-eAY8LqwP.js} +2 -2
- package/dist/{effect-mUknRPv_.js → effect-BkWovUi3.js} +52 -19
- package/dist/effect.d.ts +3 -3
- package/dist/effect.js +1 -1
- package/dist/{helper-Cfvb5UDq.js → helper-CbeedY35.js} +721 -38
- package/dist/{index-C2L8Ty0-.d.ts → index-DYzAccyT.d.ts} +29 -25
- package/dist/{index-DbV3dEmN.d.ts → index-G7UqNQ4w.d.ts} +54 -2
- package/dist/index.d.ts +54 -25
- package/dist/index.js +9 -9
- package/dist/{typebox-BdWJv3ND.js → typebox-wYeJqy7T.js} +33 -14
- package/dist/typebox.d.ts +3 -3
- package/dist/typebox.js +1 -1
- package/dist/{utils-WNBq1HR0.js → utils-Bky98UmP.js} +160 -31
- package/dist/{valibot-CaJIynCH.js → valibot-DQUEDYKt.js} +64 -23
- package/dist/valibot.d.ts +3 -3
- package/dist/valibot.js +1 -1
- package/dist/{yup-CM2TSFig.js → yup-BMpa9Co1.js} +2 -2
- package/dist/yup.d.ts +2 -2
- package/dist/yup.js +1 -1
- package/dist/{zod-BsXLZfwK.js → zod-Dq9LtqPL.js} +130 -91
- package/dist/zod.d.ts +3 -3
- package/dist/zod.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as normalizeTypes, s as makeSafeKey } from "./utils-
|
|
1
|
+
import { c as normalizeTypes, s as makeSafeKey } from "./utils-Bky98UmP.js";
|
|
2
2
|
//#region src/generator/ajv/integer.ts
|
|
3
3
|
/**
|
|
4
4
|
* Reconstruct a draft-07 integer schema. `minimum` is the only numeric keyword
|
package/dist/ajv.d.ts
CHANGED
package/dist/ajv.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToAjv } from "./ajv-
|
|
1
|
+
export { t as schemaToAjv } from "./ajv-DS9gtNZC.js";
|
|
@@ -1,34 +1,75 @@
|
|
|
1
|
-
import { $ as DEFINITION_REF_PREFIXES, B as isSchemaObject, D as isComposite, E as isArktypeDefinition, H as isStringWireLocation, I as isQuoted, M as isNullable, N as isObjectPrototypeProperty, O as isDeepLocalPointer,
|
|
2
|
-
import { A as
|
|
1
|
+
import { $ as DEFINITION_REF_PREFIXES, At as UNSAFE_GENERATED_MARKER, B as isSchemaObject, D as isComposite, E as isArktypeDefinition, H as isStringWireLocation, I as isQuoted, M as isNullable, N as isObjectPrototypeProperty, O as isDeepLocalPointer, R as isRootRef, S as hasFixedLength, St as QUOTE_OR_BACKSLASH_PATTERN, V as isShapelessMember, X as DEFAULT_ROOT_NAME, at as INTEGER_TEXT_PATTERN, c as normalizeTypes, j as isNullTypeMember, l as resolveOpenAPIRef, o as issueMessageExpression, pt as NUMBER_RANGES, s as makeSafeKey, x as hasFixedItemCount, y as hasCombinator } from "./utils-Bky98UmP.js";
|
|
2
|
+
import { A as wireNullText, B as emitOptionsOf, C as isPrimitiveUnion, D as stringboolTruthyPattern, E as stringboolPattern, G as schemaNamer, H as planDocument, M as formatPattern, N as regexSource, O as unionPrimitiveTypes, Q as findCodeExtensionKeysInSchema, S as isNullTextRead, T as ownProperties, V as missingDefinitionComment, W as rootNameOf, X as arktypePreprocess, Y as itemsSchemaOf, Z as arktypeWrap, at as regexLiteral, b as integerWirePattern, c as withPolymorphicBases, d as propertyEmitOptions, et as constraintMessage, f as withoutParameterSerialization, g as hoistNestedRefs, h as valueListLiteral, j as wireNumericKind, k as wireArrayOnce, l as hasParameterSerialization, m as notPredicate, nt as foldAllOfMembers, p as isBigintFormat, rt as isKeywordOnlyMember, tt as constraintPredicate, u as parameterReaders, w as numberWirePattern, x as isNullMatchedFirst, y as impliedWireType } from "./helper-CbeedY35.js";
|
|
3
3
|
//#region src/generator/arktype/number.ts
|
|
4
|
-
/** The
|
|
4
|
+
/** The comparators of a numeric node: `>= 1`, `< 5`, `% 2`. */
|
|
5
5
|
function numericConstraints(schema) {
|
|
6
6
|
return [
|
|
7
7
|
(() => {
|
|
8
|
-
if (schema.minimum !== void 0) return schema.exclusiveMinimum === true ?
|
|
9
|
-
|
|
8
|
+
if (schema.minimum !== void 0) return schema.exclusiveMinimum === true ? {
|
|
9
|
+
op: ">",
|
|
10
|
+
value: String(schema.minimum)
|
|
11
|
+
} : {
|
|
12
|
+
op: ">=",
|
|
13
|
+
value: String(schema.minimum)
|
|
14
|
+
};
|
|
15
|
+
if (typeof schema.exclusiveMinimum === "number") return {
|
|
16
|
+
op: ">",
|
|
17
|
+
value: String(schema.exclusiveMinimum)
|
|
18
|
+
};
|
|
10
19
|
})(),
|
|
11
20
|
(() => {
|
|
12
|
-
if (schema.maximum !== void 0) return schema.exclusiveMaximum === true ?
|
|
13
|
-
|
|
21
|
+
if (schema.maximum !== void 0) return schema.exclusiveMaximum === true ? {
|
|
22
|
+
op: "<",
|
|
23
|
+
value: String(schema.maximum)
|
|
24
|
+
} : {
|
|
25
|
+
op: "<=",
|
|
26
|
+
value: String(schema.maximum)
|
|
27
|
+
};
|
|
28
|
+
if (typeof schema.exclusiveMaximum === "number") return {
|
|
29
|
+
op: "<",
|
|
30
|
+
value: String(schema.exclusiveMaximum)
|
|
31
|
+
};
|
|
14
32
|
})(),
|
|
15
|
-
schema.multipleOf !== void 0 ?
|
|
16
|
-
|
|
33
|
+
schema.multipleOf !== void 0 ? {
|
|
34
|
+
op: "%",
|
|
35
|
+
value: String(schema.multipleOf)
|
|
36
|
+
} : void 0
|
|
37
|
+
].filter(isNumericBound);
|
|
38
|
+
}
|
|
39
|
+
function isNumericBound(bound) {
|
|
40
|
+
return bound !== void 0;
|
|
17
41
|
}
|
|
18
42
|
/** The range comparators of a fixed-width numeric `format`, if it has one. */
|
|
19
43
|
function rangeConstraints(format) {
|
|
20
44
|
const range = format === void 0 ? void 0 : NUMBER_RANGES[format];
|
|
21
45
|
if (range === void 0) return [];
|
|
22
|
-
return [
|
|
46
|
+
return [{
|
|
47
|
+
op: ">=",
|
|
48
|
+
value: range.minimum
|
|
49
|
+
}, {
|
|
50
|
+
op: "<=",
|
|
51
|
+
value: range.maximum
|
|
52
|
+
}];
|
|
23
53
|
}
|
|
24
54
|
/**
|
|
25
55
|
* A numeric keyword with its comparators as one quoted definition:
|
|
26
56
|
* `"number.integer >= 1 & number.integer <= 5"`. One definition, not an `.and()` chain
|
|
27
57
|
* of them, so a morph can validate its output against it with `.to()`.
|
|
28
58
|
*/
|
|
29
|
-
function constraintDefinition(base,
|
|
30
|
-
if (
|
|
31
|
-
return `"${
|
|
59
|
+
function constraintDefinition(base, bounds) {
|
|
60
|
+
if (bounds.length === 0) return `"${base}"`;
|
|
61
|
+
return `"${bounds.map((bound) => `${base} ${bound.op} ${bound.value}`).join(" & ")}"`;
|
|
62
|
+
}
|
|
63
|
+
/** Whether a bound's literal is exponent notation, which the ArkType string parser rejects. */
|
|
64
|
+
function usesExponent(bounds) {
|
|
65
|
+
return bounds.some((bound) => /[eE]/.test(bound.value));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Bounds as methods on `type("number")`: a JavaScript number literal, so `1e+21` and the
|
|
69
|
+
* float32 limits never enter the string parser.
|
|
70
|
+
*/
|
|
71
|
+
function methodChain(base, bounds) {
|
|
72
|
+
return `type("${base}")${bounds.map(boundMethod).join("")}`;
|
|
32
73
|
}
|
|
33
74
|
/**
|
|
34
75
|
* The `.narrow(...)` chain of a numeric node whose bounds carry their own messages: the
|
|
@@ -82,12 +123,12 @@ function hasPerKeywordMessage(schema) {
|
|
|
82
123
|
].some(Boolean);
|
|
83
124
|
}
|
|
84
125
|
/**
|
|
85
|
-
* A morph reading
|
|
86
|
-
*
|
|
87
|
-
*
|
|
126
|
+
* A morph reading wire text into a number. The text has to match the integer or JSON
|
|
127
|
+
* number grammar before `Number` sees it: `Number` accepts `""`, `" "`, `"0x10"` and,
|
|
128
|
+
* for an integer, `"1e3"`.
|
|
88
129
|
*/
|
|
89
130
|
function numberMorph(guard, expected) {
|
|
90
|
-
return `type("string").pipe((data, ctx) => { const value = Number(data); return Number.${guard}(value) ? value : ctx.error(${JSON.stringify(expected)}) })`;
|
|
131
|
+
return `type("string").pipe((data, ctx) => { const value = ${guard === "isSafeInteger" ? integerWirePattern() : numberWirePattern()}.test(data) ? Number(data) : Number.NaN; return Number.${guard}(value) ? value : ctx.error(${JSON.stringify(expected)}) })`;
|
|
91
132
|
}
|
|
92
133
|
/**
|
|
93
134
|
* The ArkType definition of a number node: the `number` keyword with its comparators,
|
|
@@ -97,13 +138,17 @@ function numberMorph(guard, expected) {
|
|
|
97
138
|
function number(schema) {
|
|
98
139
|
const errorMessage = schema["x-error-message"] ?? schema["x-required-message"];
|
|
99
140
|
const describe = errorMessage ? `.describe(${JSON.stringify(errorMessage)})` : "";
|
|
100
|
-
const
|
|
101
|
-
const constraints = [...
|
|
102
|
-
if (hasPerKeywordMessage(schema)) return `type(${constraintDefinition("number",
|
|
141
|
+
const range = rangeConstraints(schema.format === "float" || schema.format === "float32" ? "float32" : void 0);
|
|
142
|
+
const constraints = [...range, ...numericConstraints(schema)];
|
|
143
|
+
if (hasPerKeywordMessage(schema)) return `${usesExponent(range) ? methodChain("number", range) : `type(${constraintDefinition("number", range)})`}${numericNarrows(schema, errorMessage)}${describe}`;
|
|
144
|
+
if (usesExponent(constraints)) return `${methodChain("number", constraints)}${describe}`;
|
|
103
145
|
const definition = constraintDefinition("number", constraints);
|
|
104
146
|
if (errorMessage) return `type(${definition})${describe}`;
|
|
105
147
|
return definition;
|
|
106
148
|
}
|
|
149
|
+
function boundMethod(bound) {
|
|
150
|
+
return `.${bound.op === ">=" ? "atLeast" : bound.op === ">" ? "moreThan" : bound.op === "<=" ? "atMost" : bound.op === "<" ? "lessThan" : "divisibleBy"}(${bound.value})`;
|
|
151
|
+
}
|
|
107
152
|
//#endregion
|
|
108
153
|
//#region src/generator/arktype/integer.ts
|
|
109
154
|
/** Whether a node is a 64-bit integer: a value beyond 2^53 that is read as a bigint. */
|
|
@@ -149,8 +194,10 @@ function integer(schema, options) {
|
|
|
149
194
|
}
|
|
150
195
|
if (isInt64(schema)) return `${bigintMorph(options?.wire === true)}${bigintNarrows(schema, (n) => `${n}n`)}${describe}`;
|
|
151
196
|
const range = rangeConstraints(schema.format);
|
|
152
|
-
|
|
153
|
-
|
|
197
|
+
const constraints = [...range, ...numericConstraints(schema)];
|
|
198
|
+
if (hasPerKeywordMessage(schema)) return `${usesExponent(range) ? methodChain("number.integer", range) : `type(${constraintDefinition("number.integer", range)})`}${numericNarrows(schema, errorMessage)}${describe}`;
|
|
199
|
+
if (usesExponent(constraints)) return `${methodChain("number.integer", constraints)}${describe}`;
|
|
200
|
+
const definition = constraintDefinition("number.integer", constraints);
|
|
154
201
|
if (errorMessage) return `type(${definition})${describe}`;
|
|
155
202
|
return definition;
|
|
156
203
|
}
|
|
@@ -246,7 +293,7 @@ function object(schema, rootName, isArktype, options) {
|
|
|
246
293
|
const additionalMode = schema.additionalProperties === true ? "delete" : schema.additionalProperties === false ? "reject" : void 0;
|
|
247
294
|
const required = new Set(schema.required);
|
|
248
295
|
const props = Object.entries(schema.properties).map(([key, propSchema]) => {
|
|
249
|
-
const parsed = arktype(propSchema, rootName, isArktype, options);
|
|
296
|
+
const parsed = arktype(propSchema, rootName, isArktype, propertyEmitOptions(key, propSchema, options) ?? options);
|
|
250
297
|
if (!parsed) return null;
|
|
251
298
|
const isRequired = required.has(key);
|
|
252
299
|
const baseSafeKey = makeSafeKey(key);
|
|
@@ -452,6 +499,13 @@ function wireNumeric(morph, inner) {
|
|
|
452
499
|
function stringbool() {
|
|
453
500
|
return `type(${stringboolPattern()}).pipe((data) => ${stringboolTruthyPattern()}.test(data))`;
|
|
454
501
|
}
|
|
502
|
+
/** A keyword-only `allOf` member: the keywords apply when the value has their type. */
|
|
503
|
+
function keywordConstraint(schema) {
|
|
504
|
+
const body = constraintPredicate(schema, "data");
|
|
505
|
+
const message = constraintMessage(schema);
|
|
506
|
+
if (message === void 0) return `type("unknown").narrow((data) => ${body})`;
|
|
507
|
+
return `type("unknown").narrow((data, ctx) => (${body}) || ctx.mustBe(${JSON.stringify(message)}))`;
|
|
508
|
+
}
|
|
455
509
|
function formatConst(value, isBigint) {
|
|
456
510
|
if (typeof value === "string") return `"'${value}'"`;
|
|
457
511
|
if (typeof value === "number" && isBigint) return `"${value}n"`;
|
|
@@ -494,7 +548,7 @@ function node(schema, rootName, isArktype, options) {
|
|
|
494
548
|
const literalInput = (values) => {
|
|
495
549
|
if (values.every((v) => typeof v === "number")) {
|
|
496
550
|
if (isInt64(schema)) return bigintMorph(isWireCoerced);
|
|
497
|
-
if (isWireCoerced) return numberMorph("isFinite", "a number");
|
|
551
|
+
if (isWireCoerced) return wireNumericKind(schema, values) === "integer" ? numberMorph("isSafeInteger", "an integer") : numberMorph("isFinite", "a number");
|
|
498
552
|
}
|
|
499
553
|
if (isWireCoerced && values.every((v) => typeof v === "boolean")) return stringbool();
|
|
500
554
|
};
|
|
@@ -542,20 +596,20 @@ function node(schema, rootName, isArktype, options) {
|
|
|
542
596
|
if (schema.allOf) {
|
|
543
597
|
if (schema.allOf.length === 0) return arktypeWrap$1("\"unknown\"", schema);
|
|
544
598
|
const nullable = isNullable(schema) || schema.allOf.some(isNullTypeMember);
|
|
545
|
-
const members = schema.allOf.filter((s) => !isShapelessMember(s));
|
|
599
|
+
const members = foldAllOfMembers(schema.allOf.filter((s) => !isShapelessMember(s)), isWireCoerced);
|
|
546
600
|
if (isWireCoerced && members.length > 0 && members.every(isNumericMember)) {
|
|
547
601
|
const definitions = members.map((s) => s.type === "integer" ? integer(s) : number(s));
|
|
548
|
-
|
|
549
|
-
|
|
602
|
+
const isInteger = members.some((s) => s.type === "integer");
|
|
603
|
+
return arktypeWrap$1(wireNumeric(isInteger ? numberMorph("isSafeInteger", "an integer") : numberMorph("isFinite", "a number"), definitions.every(isQuoted) ? (() => {
|
|
550
604
|
const parts = definitions.map((d) => d.slice(1, -1)).filter((d) => d !== "number" && d !== "number.integer");
|
|
551
|
-
|
|
552
|
-
return
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
605
|
+
if (parts.length === 0) return isInteger ? "\"number.integer\"" : "\"number\"";
|
|
606
|
+
return `"${parts.join(" & ")}"`;
|
|
607
|
+
})() : definitions.length === 1 ? definitions[0] : intersectionStr(definitions, isArktype)), {
|
|
608
|
+
...schema,
|
|
609
|
+
nullable
|
|
610
|
+
});
|
|
557
611
|
}
|
|
558
|
-
const schemas = members.map((s) => arktype(s, rootName, isArktype, options));
|
|
612
|
+
const schemas = members.map((s) => isKeywordOnlyMember(s) ? keywordConstraint(s) : arktype(s, rootName, isArktype, options));
|
|
559
613
|
if (schemas.length === 0) return arktypeWrap$1("\"unknown\"", {
|
|
560
614
|
...schema,
|
|
561
615
|
nullable
|
|
@@ -570,9 +624,10 @@ function node(schema, rootName, isArktype, options) {
|
|
|
570
624
|
if (typeof inner !== "object" || inner === null) return arktypeWrap$1("\"unknown\"", schema);
|
|
571
625
|
const notMessage = schema["x-not-message"];
|
|
572
626
|
const predicate = (() => {
|
|
573
|
-
const
|
|
627
|
+
const bigint = isBigintFormat(withoutNot);
|
|
628
|
+
const shared = notPredicate(inner, "data", "data: unknown", bigint);
|
|
574
629
|
if (shared !== void 0) return shared;
|
|
575
|
-
if (Array.isArray(inner.enum)) return `(data: unknown) => !${
|
|
630
|
+
if (Array.isArray(inner.enum)) return `(data: unknown) => !${valueListLiteral(inner.enum, bigint)}.includes(data as never)`;
|
|
576
631
|
})();
|
|
577
632
|
if (withoutNot.type !== void 0) {
|
|
578
633
|
const base = arktype(withoutNot, rootName, isArktype, options);
|
|
@@ -688,6 +743,7 @@ function node(schema, rootName, isArktype, options) {
|
|
|
688
743
|
return arktypeWrap$1("\"Date\"", schema);
|
|
689
744
|
}
|
|
690
745
|
if (types.length === 1 && types[0] === "null") return arktypeWrap$1("\"null\"", schema);
|
|
746
|
+
if (typeof schema.additionalProperties === "object") return readonly(arktypeWrap$1(object(schema, rootName, isArktype, options), schema));
|
|
691
747
|
return arktypeWrap$1("\"unknown\"", schema);
|
|
692
748
|
}
|
|
693
749
|
//#endregion
|
|
@@ -697,7 +753,8 @@ function node(schema, rootName, isArktype, options) {
|
|
|
697
753
|
* a `scope({...}).export()` so members can name one another; one without is a bare
|
|
698
754
|
* `type(...)` export.
|
|
699
755
|
*/
|
|
700
|
-
function schemaToArktype(
|
|
756
|
+
function schemaToArktype(input, options) {
|
|
757
|
+
const schema = withPolymorphicBases(hoistNestedRefs(input));
|
|
701
758
|
const exportType = options?.exportType ?? true;
|
|
702
759
|
const emitOptions = emitOptionsOf(options);
|
|
703
760
|
const prefix = emitOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0 ? [UNSAFE_GENERATED_MARKER] : [];
|
package/dist/arktype.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
1
|
+
import { r as JSONSchema } from "./index-G7UqNQ4w.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-DYzAccyT.js";
|
|
3
3
|
//#region src/generator/arktype/index.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* A whole JSON Schema document as an ArkType module. A document with definitions becomes
|
|
6
6
|
* a `scope({...}).export()` so members can name one another; one without is a bare
|
|
7
7
|
* `type(...)` export.
|
|
8
8
|
*/
|
|
9
|
-
export declare function schemaToArktype(
|
|
9
|
+
export declare function schemaToArktype(input: JSONSchema, options?: GenerateOptions): string;
|
|
10
10
|
//#endregion
|
package/dist/arktype.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToArktype } from "./arktype-
|
|
1
|
+
export { t as schemaToArktype } from "./arktype-CRZ8vXZ5.js";
|
package/dist/cli/ajv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToAjv } from "../ajv-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToAjv } from "../ajv-DS9gtNZC.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-eAY8LqwP.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
package/dist/cli/arktype.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToArktype } from "../arktype-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToArktype } from "../arktype-CRZ8vXZ5.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-eAY8LqwP.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
package/dist/cli/effect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToEffect } from "../effect-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToEffect } from "../effect-BkWovUi3.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-eAY8LqwP.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
package/dist/cli/typebox.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToTypebox } from "../typebox-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToTypebox } from "../typebox-wYeJqy7T.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-eAY8LqwP.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
package/dist/cli/valibot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToValibot } from "../valibot-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToValibot } from "../valibot-DQUEDYKt.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-eAY8LqwP.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
package/dist/cli/yup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToYup } from "../yup-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToYup } from "../yup-BMpa9Co1.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-eAY8LqwP.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
package/dist/cli/zod.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as schemaToZod } from "../zod-
|
|
3
|
-
import { n as version, t as cli } from "../cli-
|
|
2
|
+
import { t as schemaToZod } from "../zod-Dq9LtqPL.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-eAY8LqwP.js";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
6
6
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as isRecord } from "./utils-
|
|
1
|
+
import { L as isRecord } from "./utils-Bky98UmP.js";
|
|
2
2
|
import { i as fmt, n as parseSchemaFile } from "./parser-CyJ2auea.js";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import path from "node:path";
|
|
@@ -9,7 +9,7 @@ import * as Stdio from "effect/Stdio";
|
|
|
9
9
|
import "@effect/platform-node/NodeFileSystem";
|
|
10
10
|
import * as FileSystem from "effect/FileSystem";
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "0.
|
|
12
|
+
var version = "0.8.1";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/file/index.ts
|
|
15
15
|
/** Creates the directory and its parents. An existing directory is not an error. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as isSchemaObject, H as isStringWireLocation, M as isNullable, N as isObjectPrototypeProperty,
|
|
2
|
-
import {
|
|
1
|
+
import { At as UNSAFE_GENERATED_MARKER, B as isSchemaObject, H as isStringWireLocation, M as isNullable, N as isObjectPrototypeProperty, S as hasFixedLength, T as hasType, V as isShapelessMember, X as DEFAULT_ROOT_NAME, at as INTEGER_TEXT_PATTERN, b as hasConditional, c as normalizeTypes, i as effectMessage, j as isNullTypeMember, k as isDefaultOnlyMember, n as effectError, pt as NUMBER_RANGES, r as effectErrorPart, s as makeSafeKey, x as hasFixedItemCount, y as hasCombinator } from "./utils-Bky98UmP.js";
|
|
2
|
+
import { B as emitOptionsOf, C as isPrimitiveUnion, D as stringboolTruthyPattern, E as stringboolPattern, F as jsLiteral, G as schemaNamer, H as planDocument, M as formatPattern, N as regexSource, O as unionPrimitiveTypes, Q as findCodeExtensionKeysInSchema, S as isNullTextRead, T as ownProperties, U as renderDefinitions, W as rootNameOf, Y as itemsSchemaOf, _ as effectPreprocess, at as regexLiteral, b as integerWirePattern, c as withPolymorphicBases, d as propertyEmitOptions, et as constraintMessage, f as withoutParameterSerialization, g as hoistNestedRefs, h as valueListLiteral, i as isEvaluatedKeyExpression, j as wireNumericKind, k as wireArrayOnce, l as hasParameterSerialization, m as notPredicate, nt as foldAllOfMembers, o as typeDeclaration, p as isBigintFormat, q as hasRootSelfReference, r as evaluatedProperties, rt as isKeywordOnlyMember, s as refTarget, tt as constraintPredicate, u as parameterReaders, v as effectWrap, w as numberWirePattern, y as impliedWireType, z as definitionsOf } from "./helper-CbeedY35.js";
|
|
3
3
|
//#region src/generator/effect/number.ts
|
|
4
4
|
/** The bound and `multipleOf` checks of a numeric node. */
|
|
5
5
|
function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
|
|
@@ -32,14 +32,21 @@ function rangeCheck(format, suffix = "") {
|
|
|
32
32
|
return [`Schema.isBetween${suffix}({minimum:${range.minimum},maximum:${range.maximum}})`];
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
* `Schema.FiniteFromString`, which
|
|
37
|
-
|
|
35
|
+
* Wire text checked against the integer or JSON number grammar, then decoded to a finite
|
|
36
|
+
* number. `Schema.FiniteFromString` uses `Number`, which accepts `""`, `" "` and `"0x10"`.
|
|
37
|
+
*/
|
|
38
|
+
function wireNumericInput(kind) {
|
|
39
|
+
return `Schema.String.check(Schema.isPattern(${kind === "integer" ? integerWirePattern() : numberWirePattern()})).pipe(Schema.decodeTo(Schema.Finite,SchemaTransformation.transform({decode:(input)=>Number(input),encode:(output)=>String(output)})))`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The Effect schema of a number node. On the string wire the text has to match the JSON
|
|
43
|
+
* number grammar before it is decoded to a finite number; `float` / `float32` carries
|
|
44
|
+
* its range.
|
|
38
45
|
*/
|
|
39
46
|
function number(schema, options) {
|
|
40
47
|
const errorMessage = schema["x-error-message"] ?? schema["x-required-message"];
|
|
41
48
|
const checks = [...rangeCheck(schema.format === "float" || schema.format === "float32" ? "float32" : void 0), ...numberChecks(schema)];
|
|
42
|
-
const input = options?.wire === true ? "
|
|
49
|
+
const input = options?.wire === true ? wireNumericInput("number") : "Schema.Number";
|
|
43
50
|
const base = checks.length > 0 ? `${input}.check(${checks.join(",")})` : input;
|
|
44
51
|
return errorMessage ? `${base}.annotate(${effectError(errorMessage)})` : base;
|
|
45
52
|
}
|
|
@@ -68,7 +75,7 @@ function int64Range(format) {
|
|
|
68
75
|
/**
|
|
69
76
|
* The Effect schema of an integer node. `int64` / `uint64` are bigints wherever they come
|
|
70
77
|
* from, `bigint` is one too, `int32` / `uint32` are their own filters, and on the string
|
|
71
|
-
* wire the text is
|
|
78
|
+
* wire the text has to match the integer grammar before it is decoded to a finite number.
|
|
72
79
|
*/
|
|
73
80
|
function integer(schema, options) {
|
|
74
81
|
const isWire = options?.wire === true;
|
|
@@ -81,7 +88,7 @@ function integer(schema, options) {
|
|
|
81
88
|
return annotate(checks.length > 0 ? `${input}.check(${checks.join(",")})` : input);
|
|
82
89
|
}
|
|
83
90
|
const checks = [schema.format === "int32" || schema.format === "uint32" ? `Schema.${schema.format === "uint32" ? "isUint32" : "isInt32"}(${errorMessage ? effectError(errorMessage) : ""})` : errorMessage ? `Schema.isInt(${effectError(errorMessage)})` : "Schema.isInt()", ...numberChecks(schema)];
|
|
84
|
-
return `${isWire ? "
|
|
91
|
+
return `${isWire ? wireNumericInput("integer") : "Schema.Number"}.check(${checks.join(",")})`;
|
|
85
92
|
}
|
|
86
93
|
//#endregion
|
|
87
94
|
//#region src/generator/effect/enum.ts
|
|
@@ -179,7 +186,7 @@ function object(schema, rootName, isEffect, options) {
|
|
|
179
186
|
}
|
|
180
187
|
const required = new Set(schema.required);
|
|
181
188
|
const props = Object.entries(schema.properties).map(([key, propSchema]) => {
|
|
182
|
-
const parsed = effect(propSchema, rootName, isEffect, options);
|
|
189
|
+
const parsed = effect(propSchema, rootName, isEffect, propertyEmitOptions(key, propSchema, options) ?? options);
|
|
183
190
|
if (!parsed) return null;
|
|
184
191
|
const safeKey = makeSafeKey(key);
|
|
185
192
|
const isRequired = required.has(key);
|
|
@@ -363,6 +370,7 @@ function intersect(schemas) {
|
|
|
363
370
|
const [first, ...rest] = schemas;
|
|
364
371
|
if (first === void 0) return "Schema.Unknown";
|
|
365
372
|
if (schemas.every(isStructExpr)) return `Schema.Struct({${schemas.map((s) => `...${s}.fields`).join(",")}})`;
|
|
373
|
+
if (schemas.some((s) => s.startsWith("Schema.suspend("))) return `(()=>{${schemas.map((s, i) => `const M${i}=${s}`).join(";")};return Schema.Unknown.pipe(Schema.refine((input):input is ${schemas.map((_, i) => `typeof M${i}.Type`).join("&")}=>${schemas.map((_, i) => `Schema.is(Schema.toEncoded(M${i}))(input)`).join("&&")}))})()`;
|
|
366
374
|
return `${first}.check(${rest.map((s) => `Schema.makeFilter((input)=>Schema.is(${s})(input))`).join(",")})`;
|
|
367
375
|
}
|
|
368
376
|
/**
|
|
@@ -379,6 +387,18 @@ function wholeValueMessage(inner, message) {
|
|
|
379
387
|
return `Schema.Unknown.check(Schema.makeFilter((input)=>Schema.is(${inner})(input),${effectError(message)})).pipe(Schema.decodeTo(${inner}))`;
|
|
380
388
|
}
|
|
381
389
|
/**
|
|
390
|
+
* An `allOf` with `unevaluatedProperties` beside it: the members' structs strip what they
|
|
391
|
+
* do not declare, so the keys no member evaluates are checked on the input before it is
|
|
392
|
+
* decoded. `inner` as given when the keyword is absent or every key is evaluated.
|
|
393
|
+
*/
|
|
394
|
+
function unevaluatedPropertiesCheck(inner, schema, rootName, isEffect, options) {
|
|
395
|
+
const unevaluated = schema.unevaluatedProperties;
|
|
396
|
+
if (unevaluated !== false && (typeof unevaluated !== "object" || unevaluated === null)) return inner;
|
|
397
|
+
const evaluated = evaluatedProperties(schema, options?.definitions);
|
|
398
|
+
if (evaluated === void 0) return inner;
|
|
399
|
+
return `Schema.Unknown.check(Schema.makeFilter(${`(input)=>typeof input!=='object'||input===null||Array.isArray(input)||Object.entries(input).every(([k,v])=>${isEvaluatedKeyExpression(evaluated, "k")}||${unevaluated === false ? "false" : `Schema.is(${effect(unevaluated, rootName, isEffect, options)})(v)`})`}${effectErrorPart(schema["x-unevaluatedProperties-message"])})).pipe(Schema.decodeTo(${inner}))`;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
382
402
|
* Generate Effect Schema code from a JSON Schema.
|
|
383
403
|
*
|
|
384
404
|
* The `options.readonly` flag is accepted for API symmetry with the other
|
|
@@ -394,6 +414,10 @@ function effect(schema, rootName = DEFAULT_ROOT_NAME, isEffect = false, options)
|
|
|
394
414
|
}
|
|
395
415
|
return node(schema, rootName, isEffect, options);
|
|
396
416
|
}
|
|
417
|
+
/** A keyword-only `allOf` member: the keywords apply when the value has their type. */
|
|
418
|
+
function keywordConstraint(schema) {
|
|
419
|
+
return `Schema.Unknown.check(Schema.makeFilter((input) => ${constraintPredicate(schema, "input")}${effectErrorPart(constraintMessage(schema))}))`;
|
|
420
|
+
}
|
|
397
421
|
function node(schema, rootName, isEffect, options) {
|
|
398
422
|
const isStringWireParam = isStringWireLocation(options?.paramIn);
|
|
399
423
|
const isWireCoerced = isStringWireParam && schema["x-coerce"] !== false;
|
|
@@ -407,13 +431,14 @@ function node(schema, rootName, isEffect, options) {
|
|
|
407
431
|
};
|
|
408
432
|
const effectWrap$1 = (effectStr, s) => effectWrap(effectStr, s, {
|
|
409
433
|
...codeExtOpts,
|
|
410
|
-
...wireOptions(s)
|
|
434
|
+
...wireOptions(s),
|
|
435
|
+
...options?.definitions !== void 0 && { definitions: options.definitions }
|
|
411
436
|
});
|
|
412
437
|
const wireArray = (v) => isStringWireParam ? effectPreprocess([wireArrayOnce("input")], v) : v;
|
|
413
438
|
const literalInput = (values) => {
|
|
414
439
|
if (values.every((v) => typeof v === "number")) {
|
|
415
440
|
if (isInt64(schema)) return int64Input(isWireCoerced);
|
|
416
|
-
if (isWireCoerced) return
|
|
441
|
+
if (isWireCoerced) return wireNumericInput(wireNumericKind(schema, values));
|
|
417
442
|
}
|
|
418
443
|
if (isWireCoerced && values.every((v) => typeof v === "boolean")) return stringbool();
|
|
419
444
|
};
|
|
@@ -451,14 +476,14 @@ function node(schema, rootName, isEffect, options) {
|
|
|
451
476
|
if (schema.allOf.length === 0) return effectWrap$1("Schema.Unknown", schema);
|
|
452
477
|
const nullable = isNullable(schema) || schema.allOf.some(isNullTypeMember);
|
|
453
478
|
const defaultValue = schema.allOf.find(isDefaultOnlyMember)?.default;
|
|
454
|
-
const schemas = schema.allOf.filter((s) => !isShapelessMember(s)).map((s) => effect(s, rootName, isEffect, options));
|
|
479
|
+
const schemas = foldAllOfMembers(schema.allOf.filter((s) => !isShapelessMember(s)), isWireCoerced).map((s) => isKeywordOnlyMember(s) ? keywordConstraint(s) : effect(s, rootName, isEffect, options));
|
|
455
480
|
if (schemas.length === 0) return effectWrap$1("Schema.Unknown", {
|
|
456
481
|
...schema,
|
|
457
482
|
nullable
|
|
458
483
|
});
|
|
459
484
|
const intersected = schemas.length === 1 ? schemas[0] : intersect(schemas);
|
|
460
485
|
const allOfMessage = schema["x-allOf-message"];
|
|
461
|
-
const baseResult = allOfMessage ? wholeValueMessage(intersected, allOfMessage) : intersected;
|
|
486
|
+
const baseResult = unevaluatedPropertiesCheck(allOfMessage ? wholeValueMessage(intersected, allOfMessage) : intersected, schema, rootName, isEffect, options);
|
|
462
487
|
if (defaultValue !== void 0) return `${nullable ? `Schema.NullOr(${baseResult})` : baseResult}.pipe(${isWireCoerced ? "Schema.withDecodingDefaultType" : "Schema.withDecodingDefault"}(Effect.succeed(${jsLiteral(defaultValue)})))`;
|
|
463
488
|
return effectWrap$1(baseResult, {
|
|
464
489
|
...schema,
|
|
@@ -471,9 +496,10 @@ function node(schema, rootName, isEffect, options) {
|
|
|
471
496
|
const notMessage = schema["x-not-message"];
|
|
472
497
|
const filterOpts = effectErrorPart(notMessage);
|
|
473
498
|
const predicate = (() => {
|
|
474
|
-
const
|
|
499
|
+
const bigint = isBigintFormat(withoutNot);
|
|
500
|
+
const shared = notPredicate(inner, "input", "input", bigint);
|
|
475
501
|
if (shared !== void 0) return shared;
|
|
476
|
-
if (Array.isArray(inner.enum)) return `(input) => !${
|
|
502
|
+
if (Array.isArray(inner.enum)) return `(input) => !${valueListLiteral(inner.enum, bigint)}.some((item) => item === input)`;
|
|
477
503
|
})();
|
|
478
504
|
if (withoutNot.type !== void 0) {
|
|
479
505
|
const base = effect(withoutNot, rootName, isEffect, options);
|
|
@@ -588,6 +614,7 @@ function node(schema, rootName, isEffect, options) {
|
|
|
588
614
|
return effectWrap$1("Schema.Date", schema);
|
|
589
615
|
}
|
|
590
616
|
if (types.length === 1 && types[0] === "null") return effectWrap$1("Schema.Null", schema);
|
|
617
|
+
if (typeof schema.additionalProperties === "object") return effectWrap$1(object(schema, rootName, isEffect, options), schema);
|
|
591
618
|
return effectWrap$1("Schema.Unknown", schema);
|
|
592
619
|
}
|
|
593
620
|
//#endregion
|
|
@@ -613,13 +640,19 @@ const EFFECT_ROOT_FALLBACK = `${DEFAULT_ROOT_NAME}_`;
|
|
|
613
640
|
* `options.readonly` is accepted for API symmetry and is a no-op: `Schema.Struct` and
|
|
614
641
|
* `Schema.Array` are already readonly at the type level.
|
|
615
642
|
*/
|
|
616
|
-
function schemaToEffect(
|
|
643
|
+
function schemaToEffect(input, options) {
|
|
644
|
+
const schema = withPolymorphicBases(hoistNestedRefs(input));
|
|
617
645
|
const exportType = options?.exportType ?? true;
|
|
618
|
-
const
|
|
619
|
-
const codeExtensionsPresent =
|
|
620
|
-
const toName = schemaNamer(
|
|
646
|
+
const baseOptions = emitOptionsOf(options);
|
|
647
|
+
const codeExtensionsPresent = baseOptions.unsafeCodeExtensions === true && findCodeExtensionKeysInSchema(schema).length > 0;
|
|
648
|
+
const toName = schemaNamer(baseOptions.openapi);
|
|
621
649
|
const pascalTitle = rootNameOf(schema, toName, EFFECT_ROOT_FALLBACK);
|
|
622
650
|
const plan = planDocument(schema, pascalTitle === "Schema" ? EFFECT_ROOT_FALLBACK : pascalTitle);
|
|
651
|
+
const definitions = definitionsOf(baseOptions, plan.definitions);
|
|
652
|
+
const emitOptions = definitions === void 0 ? baseOptions : {
|
|
653
|
+
...baseOptions,
|
|
654
|
+
definitions
|
|
655
|
+
};
|
|
623
656
|
const { rootName } = plan;
|
|
624
657
|
const needsTypeDef = plan.hasDefinitions || hasRootSelfReference(schema);
|
|
625
658
|
const typeDefsCode = needsTypeDef ? [`type _${rootName} = ${type(plan.root, rootName)}`, renderDefinitions(plan, toName, (def, name) => `type _${name} = ${type(def, name)}`)].filter(Boolean).join("\n\n") : "";
|
package/dist/effect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as JSONSchema } from "./index-
|
|
2
|
-
import { n as GenerateOptions } from "./index-
|
|
1
|
+
import { r as JSONSchema } from "./index-G7UqNQ4w.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-DYzAccyT.js";
|
|
3
3
|
//#region src/generator/effect/index.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* A whole JSON Schema document as an Effect Schema module: imports, `$defs` in
|
|
@@ -8,5 +8,5 @@ import { n as GenerateOptions } from "./index-C2L8Ty0-.js";
|
|
|
8
8
|
* `options.readonly` is accepted for API symmetry and is a no-op: `Schema.Struct` and
|
|
9
9
|
* `Schema.Array` are already readonly at the type level.
|
|
10
10
|
*/
|
|
11
|
-
export declare function schemaToEffect(
|
|
11
|
+
export declare function schemaToEffect(input: JSONSchema, options?: GenerateOptions): string;
|
|
12
12
|
//#endregion
|
package/dist/effect.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToEffect } from "./effect-
|
|
1
|
+
export { t as schemaToEffect } from "./effect-BkWovUi3.js";
|