schema-truth 0.8.3 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/{ajv-DejgT2o1.js → ajv-BjWqjOc9.js} +1 -1
- package/dist/ajv.d.ts +1 -1
- package/dist/ajv.js +1 -1
- package/dist/{arktype-CzTltPwP.js → arktype-pHeYh_IG.js} +33 -7
- package/dist/arktype.d.ts +2 -2
- package/dist/arktype.js +1 -1
- package/dist/cli/ajv.d.ts +0 -0
- package/dist/cli/ajv.js +2 -2
- package/dist/cli/arktype.d.ts +0 -0
- package/dist/cli/arktype.js +2 -2
- package/dist/cli/effect.d.ts +0 -0
- package/dist/cli/effect.js +2 -2
- package/dist/cli/typebox.d.ts +0 -0
- package/dist/cli/typebox.js +2 -2
- package/dist/cli/valibot.d.ts +0 -0
- package/dist/cli/valibot.js +2 -2
- package/dist/cli/yup.d.ts +0 -0
- package/dist/cli/yup.js +2 -2
- package/dist/cli/zod.d.ts +0 -0
- package/dist/cli/zod.js +2 -2
- package/dist/{cli-71Np9i5L.js → cli-CtOh--vr.js} +2 -2
- package/dist/{effect-Dj8qARFi.js → effect-CM1XVqvf.js} +12 -6
- package/dist/effect.d.ts +2 -2
- package/dist/effect.js +1 -1
- package/dist/{helper-WSNbEQKr.js → helper-1oDB5NHM.js} +23 -10
- package/dist/{index-DLVjyrKu.d.ts → index-DZry7F2L.d.ts} +1 -1
- package/dist/{index-DU2Nd8eI.d.ts → index-MUEfIMdR.d.ts} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -8
- package/dist/parser-RBrkz7ZL.js +0 -0
- package/dist/{typebox-RAJnIZwI.js → typebox-D1GT2WSK.js} +8 -4
- package/dist/typebox.d.ts +2 -2
- package/dist/typebox.js +1 -1
- package/dist/{valibot-CLUhG6tp.js → valibot-1p_Y7fu6.js} +5 -4
- package/dist/valibot.d.ts +2 -2
- package/dist/valibot.js +1 -1
- package/dist/{yup-DfE_ofEu.js → yup-IOat93gr.js} +1 -1
- package/dist/yup.d.ts +2 -2
- package/dist/yup.js +1 -1
- package/dist/{zod-BhYAQ3iW.js → zod-B-mxbHoq.js} +9 -5
- package/dist/zod.d.ts +2 -2
- package/dist/zod.js +1 -1
- package/package.json +16 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 - present, Truth Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Schema Truth
|
|
2
2
|
|
|
3
|
-
**[schema-truth](https://www.npmjs.com/package/schema-truth)** generates type-safe validation schemas from a [JSON Schema](https://json-schema.org/) or [OpenAPI](https://
|
|
3
|
+
**[schema-truth](https://www.npmjs.com/package/schema-truth)** generates type-safe validation schemas from a [JSON Schema](https://json-schema.org/) or [OpenAPI](https://openapis.org/) document — one CLI per target library, each written in that library's own idiom.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -141,4 +141,4 @@ export const User = yup.object({
|
|
|
141
141
|
|
|
142
142
|
## License
|
|
143
143
|
|
|
144
|
-
Distributed under the MIT License. See [LICENSE](https://github.com/nakita628/
|
|
144
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/nakita628/truth/blob/main/LICENSE) for more information.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as sanitizeSchema, vt as makeSafeKey, yt as normalizeTypes } from "./helper-1oDB5NHM.js";
|
|
2
2
|
// 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-BjWqjOc9.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, Ft as isArktypeDefinition, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Ln as UNSAFE_GENERATED_MARKER, Lt as isDeepLocalPointer, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, S as isNullMatchedFirst, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, Wt as isQuoted, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, bn as NUMBER_RANGES, bt as resolveOpenAPIRef, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, et as arktypePreprocess, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, j as wireNullText, jt as hasFixedLength, k as unionPrimitiveTypes, kn as QUOTE_OR_BACKSLASH_PATTERN, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, nt as callbackReturn, on as DEFINITION_REF_PREFIXES, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, rt as callbackType, s as sanitizeSchema, st as constraintPredicate, tt as arktypeWrap, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
|
|
2
2
|
// src/generator/arktype/number.ts
|
|
3
3
|
/** The comparators of a numeric node: `>= 1`, `< 5`, `% 2`. */
|
|
4
4
|
function numericConstraints(schema) {
|
|
@@ -207,8 +207,15 @@ function lit(v, isBigint) {
|
|
|
207
207
|
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
208
208
|
return JSON.stringify(v) ?? "null";
|
|
209
209
|
}
|
|
210
|
+
/** A member of a string-DSL union that is one literal, and the same text as a JS literal. */
|
|
211
|
+
const DSL_LITERAL_PATTERN = /^(?:'[^'\\]*'|-?\d+(?:\.\d+)?(?:e[+-]?\d+)?n?|true|false|null)$/u;
|
|
212
|
+
/** Whether every member of a string-DSL union is a single literal `type.enumerated` takes. */
|
|
213
|
+
function isDslLiteralUnion(members) {
|
|
214
|
+
return members.every((member) => DSL_LITERAL_PATTERN.test(member));
|
|
215
|
+
}
|
|
210
216
|
/**
|
|
211
|
-
* The ArkType definition of an enum: a `"a | b | c"` string union
|
|
217
|
+
* The ArkType definition of an enum: a `"a | b | c"` string union, or
|
|
218
|
+
* `type.enumerated(a, b, c)` past {@link ARKTYPE_STRING_UNION_LIMIT} members. The members of an
|
|
212
219
|
* int64 / uint64 enum are bigint literals, as the value they match is.
|
|
213
220
|
*/
|
|
214
221
|
function _enum(schema) {
|
|
@@ -227,7 +234,9 @@ function _enum(schema) {
|
|
|
227
234
|
if (errorMessage) return `type(${expr})${describe}`;
|
|
228
235
|
return expr;
|
|
229
236
|
}
|
|
230
|
-
const
|
|
237
|
+
const members = schema.enum.map((v) => lit(v, isBigint));
|
|
238
|
+
if (members.length > 16) return `type.enumerated(${members.join(",")})${describe}`;
|
|
239
|
+
const expr = `"${members.join(" | ")}"`;
|
|
231
240
|
if (errorMessage) return `type(${expr})${describe}`;
|
|
232
241
|
return expr;
|
|
233
242
|
}
|
|
@@ -473,8 +482,22 @@ function string(schema) {
|
|
|
473
482
|
function combine(op, inScope) {
|
|
474
483
|
return (acc, s) => inScope && isArktypeDefinition(acc) ? `[${acc},"${op}",${s}]` : `type(${acc}).${op === "&" ? "and" : "or"}(${s})`;
|
|
475
484
|
}
|
|
485
|
+
/** `items` in consecutive groups of at most `size`. */
|
|
486
|
+
function chunksOf(items, size) {
|
|
487
|
+
return Array.from({ length: Math.ceil(items.length / size) }, (_, i) => items.slice(i * size, (i + 1) * size));
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* A union of ArkType expressions. Quoted members join into one string-DSL union, unless
|
|
491
|
+
* there are more than {@link ARKTYPE_STRING_UNION_LIMIT} of them: then literals become
|
|
492
|
+
* `type.enumerated(...)` and anything else is joined in groups, so no single string is
|
|
493
|
+
* long enough to exceed TypeScript's instantiation depth.
|
|
494
|
+
*/
|
|
476
495
|
function unionStr(schemas, inScope = false) {
|
|
477
|
-
|
|
496
|
+
if (!schemas.every(isQuoted)) return schemas.reduce(combine("|", inScope));
|
|
497
|
+
const members = schemas.map((s) => s.slice(1, -1));
|
|
498
|
+
if (members.length <= 16) return `"${members.join(" | ")}"`;
|
|
499
|
+
if (isDslLiteralUnion(members)) return `type.enumerated(${members.join(",")})`;
|
|
500
|
+
return chunksOf(members, 16).map((group) => `"${group.join(" | ")}"`).reduce(combine("|", inScope));
|
|
478
501
|
}
|
|
479
502
|
function intersectionStr(schemas, inScope = false) {
|
|
480
503
|
return schemas.every(isQuoted) ? `"${schemas.map((s) => s.slice(1, -1)).join(" & ")}"` : schemas.reduce(combine("&", inScope));
|
|
@@ -567,7 +590,10 @@ function node(schema, rootName, isArktype, options) {
|
|
|
567
590
|
...options?.unsafeCodeExtensions === true && { unsafeCodeExtensions: true },
|
|
568
591
|
...isArktype && { scopeMode: true }
|
|
569
592
|
};
|
|
570
|
-
const arktypeWrap$1 = (arktypeStr, s) => arktypeWrap(arktypeStr, s,
|
|
593
|
+
const arktypeWrap$1 = (arktypeStr, s, extra) => arktypeWrap(arktypeStr, s, {
|
|
594
|
+
...codeExtOpts,
|
|
595
|
+
...extra
|
|
596
|
+
});
|
|
571
597
|
const readonly = (v) => options?.readonly ? `${v}.readonly()` : v;
|
|
572
598
|
const isStringWireParam = isStringWireLocation(options?.paramIn);
|
|
573
599
|
const isWireCoerced = isStringWireParam && schema["x-coerce"] !== false;
|
|
@@ -688,7 +714,7 @@ function node(schema, rootName, isArktype, options) {
|
|
|
688
714
|
if (schema.enum) {
|
|
689
715
|
const values = schema.enum.filter((value) => value !== null);
|
|
690
716
|
const input = values.length > 0 ? literalInput(values) : void 0;
|
|
691
|
-
if (input === void 0) return arktypeWrap$1(_enum(schema), schema);
|
|
717
|
+
if (input === void 0) return arktypeWrap$1(_enum(enumWithoutWrappedNull(schema)), schema);
|
|
692
718
|
const hasNull = values.length < schema.enum.length;
|
|
693
719
|
return arktypeWrap$1(wireNumeric(input, _enum({
|
|
694
720
|
...schema,
|
|
@@ -777,7 +803,7 @@ function node(schema, rootName, isArktype, options) {
|
|
|
777
803
|
if (isWireCoerced) return arktypeWrap$1("\"string.date.parse\"", schema);
|
|
778
804
|
return arktypeWrap$1("\"Date\"", schema);
|
|
779
805
|
}
|
|
780
|
-
if (types.length === 1 && types[0] === "null") return arktypeWrap$1("\"null\"", schema);
|
|
806
|
+
if (types.length === 1 && types[0] === "null") return arktypeWrap$1("\"null\"", schema, { nullSchema: true });
|
|
781
807
|
if (typeof schema.additionalProperties === "object") return readonly(arktypeWrap$1(object(schema, rootName, isArktype, options), schema));
|
|
782
808
|
return arktypeWrap$1("\"unknown\"", schema);
|
|
783
809
|
}
|
package/dist/arktype.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-DZry7F2L.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-MUEfIMdR.js";
|
|
3
3
|
/**
|
|
4
4
|
* A whole JSON Schema document as an ArkType module. A document with definitions becomes
|
|
5
5
|
* a `scope({...}).export()` so members can name one another; one without is a bare
|
package/dist/arktype.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToArktype } from "./arktype-
|
|
1
|
+
export { t as schemaToArktype } from "./arktype-pHeYh_IG.js";
|
package/dist/cli/ajv.d.ts
CHANGED
|
File without changes
|
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-BjWqjOc9.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-CtOh--vr.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.d.ts
CHANGED
|
File without changes
|
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-pHeYh_IG.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-CtOh--vr.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.d.ts
CHANGED
|
File without changes
|
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-CM1XVqvf.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-CtOh--vr.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.d.ts
CHANGED
|
File without changes
|
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-D1GT2WSK.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-CtOh--vr.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.d.ts
CHANGED
|
File without changes
|
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-1p_Y7fu6.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-CtOh--vr.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.d.ts
CHANGED
|
File without changes
|
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-IOat93gr.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-CtOh--vr.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.d.ts
CHANGED
|
File without changes
|
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-B-mxbHoq.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-CtOh--vr.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 {
|
|
1
|
+
import { Gt as isRecord } from "./helper-1oDB5NHM.js";
|
|
2
2
|
import { i as fmt, n as parseSchemaFile } from "./parser-RBrkz7ZL.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
|
// package.json
|
|
12
|
-
var version = "0.8.
|
|
12
|
+
var version = "0.8.5";
|
|
13
13
|
// src/file/index.ts
|
|
14
14
|
/** Creates the directory and its parents. An existing directory is not an error. */
|
|
15
15
|
function mkdir(dir) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as wireArrayOnce, At as
|
|
1
|
+
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, D as stringboolPattern, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, I as deepEqualExpression, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, L as jsLiteral, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, Pt as hasType, Rt as isDefaultOnlyMember, T as numberWirePattern, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, b as impliedWireType, bn as NUMBER_RANGES, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, ht as effectMessage, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, mt as effectErrorPart, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, pt as effectError, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, u as hasParameterSerialization, v as effectPreprocess, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, y as effectWrap, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
|
|
2
2
|
// src/generator/effect/number.ts
|
|
3
3
|
/** The bound and `multipleOf` checks of a numeric node. */
|
|
4
4
|
function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
|
|
@@ -127,7 +127,12 @@ function _enum(schema) {
|
|
|
127
127
|
const errorMessage = schema["x-enum-message"] ?? schema["x-error-message"];
|
|
128
128
|
const annotate = (code) => errorMessage ? `${code}.annotate(${effectError(errorMessage)})` : code;
|
|
129
129
|
const tuple = (arr) => `Schema.Tuple([${arr.map((i) => `Schema.Literal(${lit(i)})`).join(",")}])`;
|
|
130
|
-
const literals = (values) =>
|
|
130
|
+
const literals = (values) => {
|
|
131
|
+
const nonNull = values.filter((v) => v !== null);
|
|
132
|
+
if (nonNull.length === 0) return "Schema.Null";
|
|
133
|
+
const code = nonNull.length > 1 ? `Schema.Literals([${nonNull.map(lit).join(",")}])` : `Schema.Literal(${lit(nonNull[0])})`;
|
|
134
|
+
return nonNull.length < values.length ? `Schema.NullOr(${code})` : code;
|
|
135
|
+
};
|
|
131
136
|
if (hasType(schema, "number") || hasType(schema, "integer") || hasType(schema, "boolean")) return annotate(literals(schema.enum));
|
|
132
137
|
if (hasType(schema, "array")) {
|
|
133
138
|
if (schema.enum.length === 1 && Array.isArray(schema.enum[0])) return annotate(tuple(schema.enum[0]));
|
|
@@ -449,7 +454,8 @@ function node(schema, rootName, isEffect, options) {
|
|
|
449
454
|
...isNullTextRead(s) && { nullText: true }
|
|
450
455
|
};
|
|
451
456
|
};
|
|
452
|
-
const effectWrap$1 = (effectStr, s) => effectWrap(effectStr, s, {
|
|
457
|
+
const effectWrap$1 = (effectStr, s, extra) => effectWrap(effectStr, s, {
|
|
458
|
+
...extra,
|
|
453
459
|
...codeExtOpts,
|
|
454
460
|
...wireOptions(s),
|
|
455
461
|
...options?.definitions !== void 0 && { definitions: options.definitions }
|
|
@@ -545,7 +551,7 @@ function node(schema, rootName, isEffect, options) {
|
|
|
545
551
|
if (schema.enum) {
|
|
546
552
|
const values = schema.enum.filter((value) => value !== null);
|
|
547
553
|
const input = values.length > 0 ? literalInput(values) : void 0;
|
|
548
|
-
if (input === void 0) return effectWrap$1(_enum(schema), schema);
|
|
554
|
+
if (input === void 0) return effectWrap$1(_enum(enumWithoutWrappedNull(schema)), schema);
|
|
549
555
|
const hasNull = values.length < schema.enum.length;
|
|
550
556
|
const piped = `${input}.pipe(Schema.decodeTo(${_enum({
|
|
551
557
|
...schema,
|
|
@@ -627,7 +633,7 @@ function node(schema, rootName, isEffect, options) {
|
|
|
627
633
|
return out;
|
|
628
634
|
})();
|
|
629
635
|
const checks = [
|
|
630
|
-
isFixedLength ? `Schema.
|
|
636
|
+
isFixedLength ? `Schema.isBetweenLength(${schema.minItems},${schema.minItems}${sizeArg})` : void 0,
|
|
631
637
|
!isFixedLength && typeof schema.minItems === "number" ? `Schema.isMinLength(${schema.minItems}${minArg})` : void 0,
|
|
632
638
|
!isFixedLength && typeof schema.maxItems === "number" ? `Schema.isMaxLength(${schema.maxItems}${maxArg})` : void 0,
|
|
633
639
|
schema.uniqueItems === true ? `Schema.isUnique(${uniqueArg.slice(1)})` : void 0,
|
|
@@ -640,7 +646,7 @@ function node(schema, rootName, isEffect, options) {
|
|
|
640
646
|
if (isWireCoerced) return effectWrap$1("Schema.DateFromString", schema);
|
|
641
647
|
return effectWrap$1("Schema.Date", schema);
|
|
642
648
|
}
|
|
643
|
-
if (types.length === 1 && types[0] === "null") return effectWrap$1("Schema.Null", schema);
|
|
649
|
+
if (types.length === 1 && types[0] === "null") return effectWrap$1("Schema.Null", schema, { nullSchema: true });
|
|
644
650
|
if (typeof schema.additionalProperties === "object") return effectWrap$1(object(schema, rootName, isEffect, options), schema);
|
|
645
651
|
return effectWrap$1("Schema.Unknown", schema);
|
|
646
652
|
}
|
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-DZry7F2L.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-MUEfIMdR.js";
|
|
3
3
|
/**
|
|
4
4
|
* A whole JSON Schema document as an Effect Schema module: imports, `$defs` in
|
|
5
5
|
* dependency order, the root export, and the inferred type.
|
package/dist/effect.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToEffect } from "./effect-
|
|
1
|
+
export { t as schemaToEffect } from "./effect-CM1XVqvf.js";
|
|
@@ -397,7 +397,7 @@ const UNSAFE_GENERATED_MARKER = "// @generated-with-unsafe-code-extensions";
|
|
|
397
397
|
/** The first line of a file whose generator dropped `if` / `then` / `else`. */
|
|
398
398
|
const IF_THEN_ELSE_UNSUPPORTED_MARKER = "// FIXME: JSON Schema if/then/else is not yet supported by this generator; conditional validation is omitted";
|
|
399
399
|
/** The first line of a TypeBox file whose generator dropped a `not` keyword. */
|
|
400
|
-
const NOT_KEYWORD_UNSUPPORTED_MARKER = "// FIXME: JSON Schema `not` is not enforced by this generator; TypeBox v1 has no runtime `Type.Not` and `Value.Check` ignores the keyword (
|
|
400
|
+
const NOT_KEYWORD_UNSUPPORTED_MARKER = "// FIXME: JSON Schema `not` is not enforced by this generator; TypeBox v1 has no runtime `Type.Not` and `Value.Check` ignores the keyword (the schema is generated without it)";
|
|
401
401
|
/** The comment left where a `$ref` names a definition the document does not hold. */
|
|
402
402
|
const MISSING_DEFINITION_PREFIX = "// ⚠️ missing definition for ";
|
|
403
403
|
/** A JSON Pointer `$ref` to a named definition: `#/$defs/Name` or `#/definitions/Name`. */
|
|
@@ -1554,8 +1554,8 @@ function hasKeyword(root, keywords) {
|
|
|
1554
1554
|
}
|
|
1555
1555
|
/**
|
|
1556
1556
|
* Whether a schema (at any depth) uses the JSON Schema `not` keyword. The TypeBox
|
|
1557
|
-
* generator falls back to `Type.Any()` because TypeBox v1
|
|
1558
|
-
* and `Value.Check` does not evaluate `not`.
|
|
1557
|
+
* generator drops the keyword (a bare `not` falls back to `Type.Any()`) because TypeBox v1
|
|
1558
|
+
* has no runtime `Type.Not(...)` and `Value.Check` does not evaluate `not`.
|
|
1559
1559
|
*/
|
|
1560
1560
|
function hasNotKeyword(schema) {
|
|
1561
1561
|
return hasKeyword(schema, ["not"]);
|
|
@@ -1666,7 +1666,7 @@ function arktypePreprocess(readers, inner, input = "unknown") {
|
|
|
1666
1666
|
function arktypeWrap(arktypeStr, schema, options) {
|
|
1667
1667
|
const inScope = options?.scopeMode === true;
|
|
1668
1668
|
const isDefinition = isArktypeDefinition;
|
|
1669
|
-
const withNullable = isNullable(schema) ? isQuoted(arktypeStr) ? `"${arktypeStr.slice(1, -1)} | null"` : inScope && isDefinition(arktypeStr) ? `[${arktypeStr},"|","null"]` : `type(${arktypeStr}).or("null")` : arktypeStr;
|
|
1669
|
+
const withNullable = isNullable(schema) && options?.nullSchema !== true ? isQuoted(arktypeStr) ? `"${arktypeStr.slice(1, -1)} | null"` : inScope && isDefinition(arktypeStr) ? `[${arktypeStr},"|","null"]` : `type(${arktypeStr}).or("null")` : arktypeStr;
|
|
1670
1670
|
const withReadonly = schema["x-readonly"] === true ? isDefinition(withNullable) ? `type(${withNullable}).readonly()` : `${withNullable}.readonly()` : withNullable;
|
|
1671
1671
|
const brand = schema["x-brand"];
|
|
1672
1672
|
const withBrand = typeof brand === "string" ? isDefinition(withReadonly) ? `type(${withReadonly}).brand("${brand}")` : `${withReadonly}.brand("${brand}")` : withReadonly;
|
|
@@ -1698,6 +1698,19 @@ function itemsSchemaOf(items) {
|
|
|
1698
1698
|
if (isSchemaList(items)) return items[0];
|
|
1699
1699
|
}
|
|
1700
1700
|
/**
|
|
1701
|
+
* The node an enum emitter reads: without the `null` among its values when the nullability
|
|
1702
|
+
* wrapper adds `null` already (`type: ['string', 'null'], enum: ['a', null]`), so the value is
|
|
1703
|
+
* not listed twice. An enum of nothing but `null` keeps it.
|
|
1704
|
+
*/
|
|
1705
|
+
function enumWithoutWrappedNull(schema) {
|
|
1706
|
+
if (schema.enum === void 0 || !isNullable(schema)) return schema;
|
|
1707
|
+
const values = schema.enum.filter((value) => value !== null);
|
|
1708
|
+
return values.length === 0 || values.length === schema.enum.length ? schema : {
|
|
1709
|
+
...schema,
|
|
1710
|
+
enum: values
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1701
1714
|
* The example values of a node: `examples` as given, or the single OpenAPI `example`
|
|
1702
1715
|
* lifted into a list. `undefined` when the node carries neither.
|
|
1703
1716
|
*/
|
|
@@ -2284,7 +2297,7 @@ function defaultLiteral$1(schema, value) {
|
|
|
2284
2297
|
*/
|
|
2285
2298
|
function effectWrap(effectStr, schema, options) {
|
|
2286
2299
|
const nullText = options?.nullText === true;
|
|
2287
|
-
const withNullable = isNullable(schema) || nullText && !isNullMatchedFirst(schema) ? `Schema.NullOr(${effectStr})` : effectStr;
|
|
2300
|
+
const withNullable = isNullable(schema) && options?.nullSchema !== true || nullText && !isNullMatchedFirst(schema) ? `Schema.NullOr(${effectStr})` : effectStr;
|
|
2288
2301
|
const withNullText = nullText ? effectPreprocess([wireNullText("input")], withNullable) : withNullable;
|
|
2289
2302
|
const brand = schema["x-brand"];
|
|
2290
2303
|
const withBrand = typeof brand === "string" ? `${withNullText}.pipe(Schema.brand("${brand}"))` : withNullText;
|
|
@@ -2968,8 +2981,8 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
2968
2981
|
* time, because TypeBox stores metadata on the schema object during
|
|
2969
2982
|
* construction and exposes no post-construction `.meta()` method.
|
|
2970
2983
|
*/
|
|
2971
|
-
function typeboxWrap(typeboxStr, schema, definitions) {
|
|
2972
|
-
const withNullable = isNullable(schema) ? `Type.Union([${typeboxStr},Type.Null()])` : typeboxStr;
|
|
2984
|
+
function typeboxWrap(typeboxStr, schema, definitions, options) {
|
|
2985
|
+
const withNullable = isNullable(schema) && options?.nullSchema !== true ? `Type.Union([${typeboxStr},Type.Null()])` : typeboxStr;
|
|
2973
2986
|
const withReadonly = schema["x-readonly"] === true ? `Type.Readonly(${withNullable})` : withNullable;
|
|
2974
2987
|
return hasKeptDefault(schema, definitions) ? `Type.Optional(${withReadonly})` : withReadonly;
|
|
2975
2988
|
}
|
|
@@ -3061,7 +3074,7 @@ function defaultLiteral(schema, value, stringWire) {
|
|
|
3061
3074
|
*/
|
|
3062
3075
|
function valibotWrap(valibotStr, schema, options) {
|
|
3063
3076
|
const nullText = options?.nullText === true;
|
|
3064
|
-
const withNullable = isNullable(schema) || nullText && !isNullMatchedFirst(schema) ? `v.nullable(${valibotStr})` : valibotStr;
|
|
3077
|
+
const withNullable = isNullable(schema) && options?.nullSchema !== true || nullText && !isNullMatchedFirst(schema) ? `v.nullable(${valibotStr})` : valibotStr;
|
|
3065
3078
|
const withNullText = nullText ? `v.pipe(v.unknown(),v.transform(${wireNullText("input")}),${withNullable})` : withNullable;
|
|
3066
3079
|
const defaultResult = schema.default !== void 0 ? coerceDefault(schema, schema.default, options?.definitions) : void 0;
|
|
3067
3080
|
const withDefault = defaultResult?.keep ? `v.optional(${withNullText},${defaultLiteral(schema, defaultResult.value, options?.stringWire === true)})` : withNullText;
|
|
@@ -3113,7 +3126,7 @@ function zodWrap(zodStr, schema, options) {
|
|
|
3113
3126
|
return JSON.stringify(value);
|
|
3114
3127
|
};
|
|
3115
3128
|
const defaultResult = schema.default !== void 0 ? coerceDefault(schema, schema.default, options?.definitions) : void 0;
|
|
3116
|
-
const withNullable = isNullable(schema) ? `${zodStr}.nullable()` : zodStr;
|
|
3129
|
+
const withNullable = isNullable(schema) && options?.nullSchema !== true ? `${zodStr}.nullable()` : zodStr;
|
|
3117
3130
|
const withDefault = defaultResult?.keep ? `${withNullable}.default(${formatLiteral(defaultResult.value)})` : withNullable;
|
|
3118
3131
|
const withReadonly = schema["x-readonly"] === true ? `${withDefault}.readonly()` : withDefault;
|
|
3119
3132
|
const withPrefault = schema["x-prefault"] !== void 0 ? `${withReadonly}.prefault(${formatLiteral(schema["x-prefault"])})` : withReadonly;
|
|
@@ -3141,4 +3154,4 @@ function zodWrap(zodStr, schema, options) {
|
|
|
3141
3154
|
if (preprocess) return preprocess;
|
|
3142
3155
|
return withMeta;
|
|
3143
3156
|
}
|
|
3144
|
-
export {
|
|
3157
|
+
export { itemsSchemaOf as $, ARROW_FUNCTION_PATTERN as $t, wireArrayOnce as A, ROOT_REFS as An, hasFixedItemCount as At, typeboxRefOpt as B, ZOD_CODE_EXTENSION_KEYS as Bn, isNullable as Bt, isNullTextRead as C, OBJECT_PROTOTYPE_PROPERTIES as Cn, valibotError as Ct, stringboolPattern as D, PARAM_LOCATIONS as Dn, zodErrorPart as Dt, ownProperties as E, OUTPUT_EXTENSION as En, zodError as Et, timePattern as F, STRING_WIRE_LOCATIONS as Fn, isArktypeDefinition as Ft, renderDefinitions as G, isRecord as Gt, emitOptionsOf as H, isPlainObject as Ht, deepEqualExpression as I, UNICODE_ESCAPE_PATTERN as In, isComposite as It, discriminatedMembers as J, isShapelessMember as Jt, rootNameOf as K, isRootRef as Kt, jsLiteral as L, UNSAFE_GENERATED_MARKER as Ln, isDeepLocalPointer as Lt, wireNumericKind as M, STRINGBOOL_TRUTHY_PATTERN as Mn, hasNumericKeyword as Mt, formatPattern as N, STRING_FORMATS as Nn, hasStringKeyword as Nt, stringboolTruthyPattern as O, PARAM_STYLES as On, hasCombinator as Ot, regexSource as P, STRING_KEYWORDS as Pn, hasType as Pt, isOptionalByDefault as Q, ARKTYPE_CODE_EXTENSION_KEYS as Qt, typeboxDefaultOpt as R, VALIBOT_CODE_EXTENSION_KEYS as Rn, isDefaultOnlyMember as Rt, isNullMatchedFirst as S, NUMERIC_KEYWORDS as Sn, toPascalCase as St, numberWirePattern as T, OPENAPI_COMPONENT_SUFFIX_MAP as Tn, zodBaseError as Tt, missingDefinitionComment as U, isPrimitive as Ut, definitionsOf as V, isObjectPrototypeProperty as Vt, planDocument as W, isQuoted as Wt, hasRootSelfReference as X, ALL_CODE_EXTENSION_KEYS as Xt, cyclicDefinitionNames as Y, isStringWireLocation as Yt, enumWithoutWrappedNull as Z, ANCHOR_REF_PATTERN as Zt, hoistNestedRefs as _, NON_IDENTIFIER_CHARACTER_PATTERN as _n, issueMessageExpression as _t, typeboxWrap as a, DEFINITION_POINTER_PATTERN as an, hasNotKeyword as at, impliedWireType as b, NUMBER_RANGES as bn, resolveOpenAPIRef as bt, refTarget as c, FORMAT_PATTERNS as cn, foldAllOfMembers as ct, parameterReaders as d, INPUT_EXTENSIONS as dn, regexLiteral as dt, COMPONENT_SCHEMA_REF_PREFIX as en, arktypePreprocess as et, propertyEmitOptions as f, INTEGER_TEXT_PATTERN as fn, coerceDefault as ft, valueListLiteral as g, MISSING_DEFINITION_PREFIX as gn, encodeNonAscii as gt, notPredicate as h, JSON_SCHEMA_TYPES as hn, effectMessage as ht, isEvaluatedKeyExpression as i, DEFINITION_KEYWORDS as in, findCodeExtensionKeysInSchema as it, wireNullText as j, STRINGBOOL_PATTERN as jn, hasFixedLength as jt, unionPrimitiveTypes as k, QUOTE_OR_BACKSLASH_PATTERN as kn, hasConditional as kt, withPolymorphicBases as l, IDENTIFIER_PATTERN as ln, isKeywordOnlyMember as lt, isBigintFormat as m, ISO_4217_CURRENCY_CODES as mn, effectErrorPart as mt, valibotWrap as n, DATE_PATTERN_SOURCE as nn, callbackReturn as nt, typeDeclaration as o, DEFINITION_REF_PREFIXES as on, constraintMessage as ot, withoutParameterSerialization as p, INTEGER_WIRE_PATTERN as pn, effectError as pt, schemaNamer as q, isSchemaObject as qt, evaluatedProperties as r, DEFAULT_ROOT_NAME as rn, callbackType as rt, sanitizeSchema as s, EFFECT_CODE_EXTENSION_KEYS as sn, constraintPredicate as st, zodWrap as t, CONTENT_ENCODINGS as tn, arktypeWrap as tt, hasParameterSerialization as u, IF_THEN_ELSE_UNSUPPORTED_MARKER as un, patternSource as ut, effectPreprocess as v, NOT_KEYWORD_UNSUPPORTED_MARKER as vn, makeSafeKey as vt, isPrimitiveUnion as w, OFFSET_PATTERN_SOURCE as wn, valibotErrorPart as wt, integerWirePattern as x, NUMBER_WIRE_PATTERN as xn, toIdentifierPascalCase as xt, effectWrap as y, NUMBER_FORMATS as yn, normalizeTypes as yt, typeboxMetaOpts as z, WIRE_PRIMITIVE_ORDER as zn, isNullTypeMember as zt };
|
|
@@ -163,7 +163,7 @@ declare const UNSAFE_GENERATED_MARKER = "// @generated-with-unsafe-code-extensio
|
|
|
163
163
|
/** The first line of a file whose generator dropped `if` / `then` / `else`. */
|
|
164
164
|
declare const IF_THEN_ELSE_UNSUPPORTED_MARKER = "// FIXME: JSON Schema if/then/else is not yet supported by this generator; conditional validation is omitted";
|
|
165
165
|
/** The first line of a TypeBox file whose generator dropped a `not` keyword. */
|
|
166
|
-
declare const NOT_KEYWORD_UNSUPPORTED_MARKER = "// FIXME: JSON Schema `not` is not enforced by this generator; TypeBox v1 has no runtime `Type.Not` and `Value.Check` ignores the keyword (
|
|
166
|
+
declare const NOT_KEYWORD_UNSUPPORTED_MARKER = "// FIXME: JSON Schema `not` is not enforced by this generator; TypeBox v1 has no runtime `Type.Not` and `Value.Check` ignores the keyword (the schema is generated without it)";
|
|
167
167
|
/** The comment left where a `$ref` names a definition the document does not hold. */
|
|
168
168
|
declare const MISSING_DEFINITION_PREFIX = "// ⚠️ missing definition for ";
|
|
169
169
|
/** A JSON Pointer `$ref` to a named definition: `#/$defs/Name` or `#/definitions/Name`. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as ParamStyle, m as ParamIn, r as JSONSchema } from "./index-
|
|
1
|
+
import { h as ParamStyle, m as ParamIn, r as JSONSchema } from "./index-DZry7F2L.js";
|
|
2
2
|
/** Named schemas a `default` beside a `$ref` is reconciled against. */
|
|
3
3
|
type SchemaDefinitions = {
|
|
4
4
|
readonly [name: string]: JSONSchema;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $ as QUOTE_OR_BACKSLASH_PATTERN, A as DEFINITION_REF_PREFIXES, B as MISSING_DEFINITION_PREFIX, C as ARROW_FUNCTION_PATTERN, D as DEFAULT_ROOT_NAME, E as DATE_PATTERN_SOURCE, F as INPUT_EXTENSIONS, G as NUMBER_WIRE_PATTERN, H as NOT_KEYWORD_UNSUPPORTED_MARKER, I as INTEGER_TEXT_PATTERN, J as OFFSET_PATTERN_SOURCE, K as NUMERIC_KEYWORDS, L as INTEGER_WIRE_PATTERN, M as FORMAT_PATTERNS, N as IDENTIFIER_PATTERN, O as DEFINITION_KEYWORDS, P as IF_THEN_ELSE_UNSUPPORTED_MARKER, Q as PARAM_STYLES, R as ISO_4217_CURRENCY_CODES, S as ARKTYPE_CODE_EXTENSION_KEYS, T as CONTENT_ENCODINGS, U as NUMBER_FORMATS, V as NON_IDENTIFIER_CHARACTER_PATTERN, W as NUMBER_RANGES, X as OUTPUT_EXTENSION, Y as OPENAPI_COMPONENT_SUFFIX_MAP, Z as PARAM_LOCATIONS, _ as XExtMessages, a as JSONSchemaNumberFormat, at as STRING_WIRE_LOCATIONS, b as ALL_CODE_EXTENSION_KEYS, c as JSONSchemaTypes, ct as VALIBOT_CODE_EXTENSION_KEYS, d as Ref, et as ROOT_REFS, f as parseSchemaFile, g as XExtParam, h as ParamStyle, i as JSONSchemaFormat, it as STRING_KEYWORDS, j as EFFECT_CODE_EXTENSION_KEYS, k as DEFINITION_POINTER_PATTERN, l as LocalRef, lt as WIRE_PRIMITIVE_ORDER, m as ParamIn, n as ExternalRef, nt as STRINGBOOL_TRUTHY_PATTERN, o as JSONSchemaStringFormat, ot as UNICODE_ESCAPE_PATTERN, p as XExtTransform, q as OBJECT_PROTOTYPE_PROPERTIES, r as JSONSchema, rt as STRING_FORMATS, s as JSONSchemaType, st as UNSAFE_GENERATED_MARKER, t as ContentEncoding, tt as STRINGBOOL_PATTERN, u as ParseError, ut as ZOD_CODE_EXTENSION_KEYS, v as XExtCode, w as COMPONENT_SCHEMA_REF_PREFIX, x as ANCHOR_REF_PATTERN, y as JSONValue, z as JSON_SCHEMA_TYPES } from "./index-
|
|
1
|
+
import { $ as QUOTE_OR_BACKSLASH_PATTERN, A as DEFINITION_REF_PREFIXES, B as MISSING_DEFINITION_PREFIX, C as ARROW_FUNCTION_PATTERN, D as DEFAULT_ROOT_NAME, E as DATE_PATTERN_SOURCE, F as INPUT_EXTENSIONS, G as NUMBER_WIRE_PATTERN, H as NOT_KEYWORD_UNSUPPORTED_MARKER, I as INTEGER_TEXT_PATTERN, J as OFFSET_PATTERN_SOURCE, K as NUMERIC_KEYWORDS, L as INTEGER_WIRE_PATTERN, M as FORMAT_PATTERNS, N as IDENTIFIER_PATTERN, O as DEFINITION_KEYWORDS, P as IF_THEN_ELSE_UNSUPPORTED_MARKER, Q as PARAM_STYLES, R as ISO_4217_CURRENCY_CODES, S as ARKTYPE_CODE_EXTENSION_KEYS, T as CONTENT_ENCODINGS, U as NUMBER_FORMATS, V as NON_IDENTIFIER_CHARACTER_PATTERN, W as NUMBER_RANGES, X as OUTPUT_EXTENSION, Y as OPENAPI_COMPONENT_SUFFIX_MAP, Z as PARAM_LOCATIONS, _ as XExtMessages, a as JSONSchemaNumberFormat, at as STRING_WIRE_LOCATIONS, b as ALL_CODE_EXTENSION_KEYS, c as JSONSchemaTypes, ct as VALIBOT_CODE_EXTENSION_KEYS, d as Ref, et as ROOT_REFS, f as parseSchemaFile, g as XExtParam, h as ParamStyle, i as JSONSchemaFormat, it as STRING_KEYWORDS, j as EFFECT_CODE_EXTENSION_KEYS, k as DEFINITION_POINTER_PATTERN, l as LocalRef, lt as WIRE_PRIMITIVE_ORDER, m as ParamIn, n as ExternalRef, nt as STRINGBOOL_TRUTHY_PATTERN, o as JSONSchemaStringFormat, ot as UNICODE_ESCAPE_PATTERN, p as XExtTransform, q as OBJECT_PROTOTYPE_PROPERTIES, r as JSONSchema, rt as STRING_FORMATS, s as JSONSchemaType, st as UNSAFE_GENERATED_MARKER, t as ContentEncoding, tt as STRINGBOOL_PATTERN, u as ParseError, ut as ZOD_CODE_EXTENSION_KEYS, v as XExtCode, w as COMPONENT_SCHEMA_REF_PREFIX, x as ANCHOR_REF_PATTERN, y as JSONValue, z as JSON_SCHEMA_TYPES } from "./index-DZry7F2L.js";
|
|
2
2
|
import { schemaToAjv } from "./ajv.js";
|
|
3
|
-
import { n as GenerateOptions, r as SchemaDefinitions, t as EmitOptions } from "./index-
|
|
3
|
+
import { n as GenerateOptions, r as SchemaDefinitions, t as EmitOptions } from "./index-MUEfIMdR.js";
|
|
4
4
|
import { schemaToArktype } from "./arktype.js";
|
|
5
5
|
import { schemaToEffect } from "./effect.js";
|
|
6
6
|
import { TypeboxGenerateOptions, schemaToTypebox } from "./typebox.js";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $t as
|
|
1
|
+
import { $t as ARROW_FUNCTION_PATTERN, An as ROOT_REFS, Bn as ZOD_CODE_EXTENSION_KEYS, Cn as OBJECT_PROTOTYPE_PROPERTIES, Ct as valibotError, Dn as PARAM_LOCATIONS, Dt as zodErrorPart, En as OUTPUT_EXTENSION, Et as zodError, Fn as STRING_WIRE_LOCATIONS, In as UNICODE_ESCAPE_PATTERN, Ln as UNSAFE_GENERATED_MARKER, Mn as STRINGBOOL_TRUTHY_PATTERN, Nn as STRING_FORMATS, On as PARAM_STYLES, Pn as STRING_KEYWORDS, Qt as ARKTYPE_CODE_EXTENSION_KEYS, Rn as VALIBOT_CODE_EXTENSION_KEYS, Sn as NUMERIC_KEYWORDS, St as toPascalCase, Tn as OPENAPI_COMPONENT_SUFFIX_MAP, Tt as zodBaseError, Xt as ALL_CODE_EXTENSION_KEYS, Zt as ANCHOR_REF_PATTERN, _n as NON_IDENTIFIER_CHARACTER_PATTERN, _t as issueMessageExpression, an as DEFINITION_POINTER_PATTERN, bn as NUMBER_RANGES, bt as resolveOpenAPIRef, cn as FORMAT_PATTERNS, dn as INPUT_EXTENSIONS, en as COMPONENT_SCHEMA_REF_PREFIX, fn as INTEGER_TEXT_PATTERN, ft as coerceDefault, gn as MISSING_DEFINITION_PREFIX, gt as encodeNonAscii, hn as JSON_SCHEMA_TYPES, ht as effectMessage, in as DEFINITION_KEYWORDS, jn as STRINGBOOL_PATTERN, kn as QUOTE_OR_BACKSLASH_PATTERN, ln as IDENTIFIER_PATTERN, mn as ISO_4217_CURRENCY_CODES, mt as effectErrorPart, nn as DATE_PATTERN_SOURCE, on as DEFINITION_REF_PREFIXES, pn as INTEGER_WIRE_PATTERN, pt as effectError, rn as DEFAULT_ROOT_NAME, sn as EFFECT_CODE_EXTENSION_KEYS, tn as CONTENT_ENCODINGS, un as IF_THEN_ELSE_UNSUPPORTED_MARKER, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, wn as OFFSET_PATTERN_SOURCE, wt as valibotErrorPart, xn as NUMBER_WIRE_PATTERN, xt as toIdentifierPascalCase, yn as NUMBER_FORMATS, yt as normalizeTypes, zn as WIRE_PRIMITIVE_ORDER } from "./helper-1oDB5NHM.js";
|
|
2
2
|
import { i as fmt, n as parseSchemaFile, r as FormatError, t as ParseError } from "./parser-RBrkz7ZL.js";
|
|
3
|
-
import { n as ajv, t as schemaToAjv } from "./ajv-
|
|
4
|
-
import { n as arktype, t as schemaToArktype } from "./arktype-
|
|
5
|
-
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-
|
|
6
|
-
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-
|
|
7
|
-
import { n as valibot, t as schemaToValibot } from "./valibot-
|
|
8
|
-
import { n as yup, t as schemaToYup } from "./yup-
|
|
9
|
-
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-
|
|
3
|
+
import { n as ajv, t as schemaToAjv } from "./ajv-BjWqjOc9.js";
|
|
4
|
+
import { n as arktype, t as schemaToArktype } from "./arktype-pHeYh_IG.js";
|
|
5
|
+
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-CM1XVqvf.js";
|
|
6
|
+
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-D1GT2WSK.js";
|
|
7
|
+
import { n as valibot, t as schemaToValibot } from "./valibot-1p_Y7fu6.js";
|
|
8
|
+
import { n as yup, t as schemaToYup } from "./yup-IOat93gr.js";
|
|
9
|
+
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-B-mxbHoq.js";
|
|
10
10
|
export { ALL_CODE_EXTENSION_KEYS, ANCHOR_REF_PATTERN, ARKTYPE_CODE_EXTENSION_KEYS, ARROW_FUNCTION_PATTERN, COMPONENT_SCHEMA_REF_PREFIX, CONTENT_ENCODINGS, DATE_PATTERN_SOURCE, DEFAULT_ROOT_NAME, DEFINITION_KEYWORDS, DEFINITION_POINTER_PATTERN, DEFINITION_REF_PREFIXES, EFFECT_CODE_EXTENSION_KEYS, FORMAT_PATTERNS, FormatError, IDENTIFIER_PATTERN, IF_THEN_ELSE_UNSUPPORTED_MARKER, INPUT_EXTENSIONS, INTEGER_TEXT_PATTERN, INTEGER_WIRE_PATTERN, ISO_4217_CURRENCY_CODES, JSON_SCHEMA_TYPES, MISSING_DEFINITION_PREFIX, NON_IDENTIFIER_CHARACTER_PATTERN, NOT_KEYWORD_UNSUPPORTED_MARKER, NUMBER_FORMATS, NUMBER_RANGES, NUMBER_WIRE_PATTERN, NUMERIC_KEYWORDS, OBJECT_PROTOTYPE_PROPERTIES, OFFSET_PATTERN_SOURCE, OPENAPI_COMPONENT_SUFFIX_MAP, OUTPUT_EXTENSION, PARAM_LOCATIONS, PARAM_STYLES, ParseError, QUOTE_OR_BACKSLASH_PATTERN, ROOT_REFS, STRINGBOOL_PATTERN, STRINGBOOL_TRUTHY_PATTERN, STRING_FORMATS, STRING_KEYWORDS, STRING_WIRE_LOCATIONS, UNICODE_ESCAPE_PATTERN, UNSAFE_GENERATED_MARKER, VALIBOT_CODE_EXTENSION_KEYS, WIRE_PRIMITIVE_ORDER, ZOD_CODE_EXTENSION_KEYS, ajv, arktype, coerceDefault, effect, effectError, effectErrorPart, effectMessage, encodeNonAscii, fmt, forwardIssue, issueMessageExpression, makeSafeKey, nestedIssueMessageWrap, nestedTypeboxOptions, normalizeTypes, parseSchemaFile, resolveOpenAPIRef, schemaToAjv, schemaToArktype, schemaToEffect, schemaToTypebox, schemaToValibot, schemaToYup, schemaToZod, toIdentifierPascalCase, toPascalCase, typebox, valibot, valibotError, valibotErrorPart, wholeValueMessage, yup, zod, zodBaseError, zodError, zodErrorPart };
|
package/dist/parser-RBrkz7ZL.js
CHANGED
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as itemsSchemaOf, B as typeboxRefOpt, Bt as isNullable, D as stringboolPattern, G as renderDefinitions, H as emitOptionsOf, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Kt as isRootRef, Lt as isDeepLocalPointer, Mt as hasNumericKeyword, Nt as hasStringKeyword, O as stringboolTruthyPattern, Ot as hasCombinator, Q as isOptionalByDefault, R as typeboxDefaultOpt, Rt as isDefaultOnlyMember, T as numberWirePattern, U as missingDefinitionComment, V as definitionsOf, W as planDocument, X as hasRootSelfReference, Y as cyclicDefinitionNames, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, a as typeboxWrap, at as hasNotKeyword, bt as resolveOpenAPIRef, ct as foldAllOfMembers, jt as hasFixedLength, l as withPolymorphicBases, lt as isKeywordOnlyMember, on as DEFINITION_REF_PREFIXES, q as schemaNamer, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, ut as patternSource, vn as NOT_KEYWORD_UNSUPPORTED_MARKER, vt as makeSafeKey, x as integerWirePattern, yt as normalizeTypes, z as typeboxMetaOpts, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
|
|
2
2
|
// src/generator/typebox/enum.ts
|
|
3
3
|
function lit(v) {
|
|
4
4
|
if (v === null) return "null";
|
|
@@ -435,14 +435,18 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
435
435
|
], hostRef);
|
|
436
436
|
return typeboxWrap(baseResult, withMergedDefault, definitions);
|
|
437
437
|
}
|
|
438
|
-
if (schema.not)
|
|
438
|
+
if (schema.not) {
|
|
439
|
+
const { not: dropped, ...withoutNot } = schema;
|
|
440
|
+
if (dropped !== void 0 && withoutNot.type !== void 0) return typebox(withoutNot, rootName, isTypebox, options);
|
|
441
|
+
return typeboxWrap(tbPrim("Type.Any", schema, messageOpt(schema["x-not-message"]), hostRef), schema);
|
|
442
|
+
}
|
|
439
443
|
if (schema.const !== void 0) {
|
|
440
444
|
const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
|
|
441
445
|
if (schema.const === null) return typeboxWrap(tbPrim("Type.Null", schema, messageOpt(constMessage), hostRef), schema);
|
|
442
446
|
if (typeof schema.const === "object") return typeboxWrap(tbPrim("Type.Any", schema, messageOpt(constMessage), hostRef), schema);
|
|
443
447
|
return typeboxWrap(tbComp("Type.Literal", JSON.stringify(schema.const), schema, messageOpt(constMessage), hostRef), schema);
|
|
444
448
|
}
|
|
445
|
-
if (schema.enum) return typeboxWrap(_enum(schema, hostRef), schema);
|
|
449
|
+
if (schema.enum) return typeboxWrap(_enum(enumWithoutWrappedNull(schema), hostRef), schema);
|
|
446
450
|
if (schema.properties) return readonly(typeboxWrap(object(schema, rootName, isTypebox, options), schema));
|
|
447
451
|
const types = normalizeTypes(schema.type);
|
|
448
452
|
if (types.includes("string")) return typeboxWrap(string(schema, hostRef), schema);
|
|
@@ -511,7 +515,7 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
511
515
|
const wire = wireString(schema, hostRef);
|
|
512
516
|
return typeboxWrap(`Codec(${wire}).Decode((value)=>new Date(value)).Encode((value)=>value.toISOString())`, schema);
|
|
513
517
|
}
|
|
514
|
-
if (types.length === 1 && types[0] === "null") return typeboxWrap(tbPrim("Type.Null", schema, [], hostRef), schema);
|
|
518
|
+
if (types.length === 1 && types[0] === "null") return typeboxWrap(tbPrim("Type.Null", schema, [], hostRef), schema, void 0, { nullSchema: true });
|
|
515
519
|
if (typeof schema.additionalProperties === "object") return readonly(typeboxWrap(object(schema, rootName, isTypebox, options), schema));
|
|
516
520
|
return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
|
|
517
521
|
}
|
package/dist/typebox.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-DZry7F2L.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-MUEfIMdR.js";
|
|
3
3
|
/** The options of `schemaToTypebox`: the common ones, plus a host `$ref` name. */
|
|
4
4
|
export type TypeboxGenerateOptions = Omit<GenerateOptions, 'unsafeCodeExtensions'> & {
|
|
5
5
|
/**
|
package/dist/typebox.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToTypebox } from "./typebox-
|
|
1
|
+
export { t as schemaToTypebox } from "./typebox-D1GT2WSK.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as wireArrayOnce, At as
|
|
1
|
+
import { $ as itemsSchemaOf, A as wireArrayOnce, At as hasFixedItemCount, Bt as isNullable, C as isNullTextRead, Ct as valibotError, D as stringboolPattern, E as ownProperties, G as renderDefinitions, H as emitOptionsOf, I as deepEqualExpression, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, L as jsLiteral, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, N as formatPattern, O as stringboolTruthyPattern, Ot as hasCombinator, P as regexSource, Pt as hasType, Q as isOptionalByDefault, Rt as isDefaultOnlyMember, T as numberWirePattern, Ut as isPrimitive, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, bn as NUMBER_RANGES, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, fn as INTEGER_TEXT_PATTERN, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, n as valibotWrap, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, wt as valibotErrorPart, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
|
|
2
2
|
// src/generator/valibot/type.ts
|
|
3
3
|
/** The TypeScript type declared beside a recursive Valibot schema: its output type. */
|
|
4
4
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
@@ -471,7 +471,8 @@ function node(schema, rootName, isValibot, options) {
|
|
|
471
471
|
...isNullTextRead(s) && { nullText: true }
|
|
472
472
|
};
|
|
473
473
|
};
|
|
474
|
-
const valibotWrap$1 = (valibotStr, s) => valibotWrap(valibotStr, s, {
|
|
474
|
+
const valibotWrap$1 = (valibotStr, s, extra) => valibotWrap(valibotStr, s, {
|
|
475
|
+
...extra,
|
|
475
476
|
...codeExtOpts,
|
|
476
477
|
...wireOptions(s),
|
|
477
478
|
...options?.definitions !== void 0 && { definitions: options.definitions }
|
|
@@ -582,7 +583,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
582
583
|
if (schema.enum) {
|
|
583
584
|
const values = schema.enum.filter((value) => value !== null);
|
|
584
585
|
const input = values.length > 0 ? literalInput(values) : void 0;
|
|
585
|
-
if (input === void 0) return valibotWrap$1(_enum(schema), schema);
|
|
586
|
+
if (input === void 0) return valibotWrap$1(_enum(enumWithoutWrappedNull(schema)), schema);
|
|
586
587
|
const hasNull = values.length < schema.enum.length;
|
|
587
588
|
const piped = prependPipe(input, _enum({
|
|
588
589
|
...schema,
|
|
@@ -677,7 +678,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
677
678
|
if (isWireCoerced) return valibotWrap$1(`v.pipe(v.string(),v.transform((input)=>new Date(input)),v.date())`, schema);
|
|
678
679
|
return valibotWrap$1("v.date()", schema);
|
|
679
680
|
}
|
|
680
|
-
if (types.length === 1 && types[0] === "null") return valibotWrap$1("v.null()", schema);
|
|
681
|
+
if (types.length === 1 && types[0] === "null") return valibotWrap$1("v.null()", schema, { nullSchema: true });
|
|
681
682
|
if (typeof schema.additionalProperties === "object") return readonly(valibotWrap$1(object(schema, rootName, isValibot, options), schema));
|
|
682
683
|
return valibotWrap$1("v.any()", schema);
|
|
683
684
|
}
|
package/dist/valibot.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-DZry7F2L.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-MUEfIMdR.js";
|
|
3
3
|
/**
|
|
4
4
|
* A whole JSON Schema document as a Valibot module: imports, `$defs` in dependency
|
|
5
5
|
* order, the root export, and the inferred output type.
|
package/dist/valibot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToValibot } from "./valibot-
|
|
1
|
+
export { t as schemaToValibot } from "./valibot-1p_Y7fu6.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as rootNameOf,
|
|
1
|
+
import { K as rootNameOf, q as schemaNamer, s as sanitizeSchema, vt as makeSafeKey, yt as normalizeTypes } from "./helper-1oDB5NHM.js";
|
|
2
2
|
// src/generator/yup/integer.ts
|
|
3
3
|
/**
|
|
4
4
|
* Generate a Yup integer schema as `yup.number().integer()`, with `minimum`
|
package/dist/yup.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-DZry7F2L.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-MUEfIMdR.js";
|
|
3
3
|
/**
|
|
4
4
|
* Convert a JSON Schema document to Yup schema source.
|
|
5
5
|
*
|
package/dist/yup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToYup } from "./yup-
|
|
1
|
+
export { t as schemaToYup } from "./yup-IOat93gr.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as itemsSchemaOf, A as wireArrayOnce, Bt as isNullable, C as isNullTextRead, Dt as zodErrorPart, Et as zodError, F as timePattern, G as renderDefinitions, H as emitOptionsOf, Ht as isPlainObject, I as deepEqualExpression, It as isComposite, J as discriminatedMembers, Jt as isShapelessMember, K as rootNameOf, Ln as UNSAFE_GENERATED_MARKER, M as wireNumericKind, Ot as hasCombinator, Pt as hasType, Rt as isDefaultOnlyMember, S as isNullMatchedFirst, T as numberWirePattern, Tt as zodBaseError, Ut as isPrimitive, V as definitionsOf, Vt as isObjectPrototypeProperty, W as planDocument, X as hasRootSelfReference, Yt as isStringWireLocation, Z as enumWithoutWrappedNull, _ as hoistNestedRefs, _t as issueMessageExpression, b as impliedWireType, c as refTarget, ct as foldAllOfMembers, d as parameterReaders, dt as regexLiteral, f as propertyEmitOptions, g as valueListLiteral, h as notPredicate, i as isEvaluatedKeyExpression, it as findCodeExtensionKeysInSchema, j as wireNullText, jt as hasFixedLength, k as unionPrimitiveTypes, kt as hasConditional, l as withPolymorphicBases, lt as isKeywordOnlyMember, m as isBigintFormat, mn as ISO_4217_CURRENCY_CODES, o as typeDeclaration, ot as constraintMessage, p as withoutParameterSerialization, q as schemaNamer, qt as isSchemaObject, r as evaluatedProperties, rn as DEFAULT_ROOT_NAME, s as sanitizeSchema, st as constraintPredicate, t as zodWrap, u as hasParameterSerialization, vt as makeSafeKey, w as isPrimitiveUnion, x as integerWirePattern, yt as normalizeTypes, zt as isNullTypeMember } from "./helper-1oDB5NHM.js";
|
|
2
2
|
// src/generator/zod/type.ts
|
|
3
3
|
/** The TypeScript type declared beside a recursive Zod schema. */
|
|
4
4
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
@@ -549,7 +549,10 @@ function zodNotPredicate(inner, parent) {
|
|
|
549
549
|
const bigint = isBigintFormat(parent);
|
|
550
550
|
const shared = notPredicate(inner, "val", "val", bigint);
|
|
551
551
|
if (shared !== void 0) return shared;
|
|
552
|
-
if (Array.isArray(inner.enum))
|
|
552
|
+
if (Array.isArray(inner.enum)) {
|
|
553
|
+
const list = valueListLiteral(inner.enum, bigint);
|
|
554
|
+
return isNullable(parent) && !inner.enum.includes(null) ? `(val) => val === null || !${list}.includes(val)` : `(val) => !${list}.includes(val)`;
|
|
555
|
+
}
|
|
553
556
|
if (inner.oneOf || inner.anyOf || inner.allOf) return `(val) => !${zod(inner)}.safeParse(val).success`;
|
|
554
557
|
}
|
|
555
558
|
/**
|
|
@@ -610,7 +613,8 @@ function node(schema, rootName, isZod, options) {
|
|
|
610
613
|
const isStringWireParam = isStringWireLocation(options?.paramIn);
|
|
611
614
|
const isWireCoerced = isStringWireParam && schema["x-coerce"] !== false;
|
|
612
615
|
const codeExtOpts = options?.unsafeCodeExtensions === true ? { unsafeCodeExtensions: true } : {};
|
|
613
|
-
const zodWrap$1 = (zodStr, s) => zodWrap(zodStr, s, {
|
|
616
|
+
const zodWrap$1 = (zodStr, s, extra) => zodWrap(zodStr, s, {
|
|
617
|
+
...extra,
|
|
614
618
|
...codeExtOpts,
|
|
615
619
|
...options?.definitions !== void 0 && { definitions: options.definitions }
|
|
616
620
|
});
|
|
@@ -709,7 +713,7 @@ function node(schema, rootName, isZod, options) {
|
|
|
709
713
|
if (schema.enum) {
|
|
710
714
|
const values = schema.enum.filter((value) => value !== null);
|
|
711
715
|
const input = values.length > 0 ? literalInput(values) : void 0;
|
|
712
|
-
if (input === void 0) return zodWrap$1(_enum(schema), schema);
|
|
716
|
+
if (input === void 0) return zodWrap$1(_enum(enumWithoutWrappedNull(schema)), schema);
|
|
713
717
|
const hasNull = values.length < schema.enum.length;
|
|
714
718
|
const piped = `${input}.pipe(${_enum({
|
|
715
719
|
...schema,
|
|
@@ -804,7 +808,7 @@ function node(schema, rootName, isZod, options) {
|
|
|
804
808
|
}
|
|
805
809
|
if (types.length === 1 && types[0] === "null") {
|
|
806
810
|
const errorMessage = schema["x-error-message"];
|
|
807
|
-
return zodWrap$1(`z.null(${errorMessage ? zodError(errorMessage) : ""})`, schema);
|
|
811
|
+
return zodWrap$1(`z.null(${errorMessage ? zodError(errorMessage) : ""})`, schema, { nullSchema: true });
|
|
808
812
|
}
|
|
809
813
|
if (typeof schema.additionalProperties === "object") return readonly(zodWrap$1(object(schema, rootName, isZod, options), schema));
|
|
810
814
|
return zodWrap$1("z.any()", schema);
|
package/dist/zod.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-DZry7F2L.js";
|
|
2
|
+
import { n as GenerateOptions } from "./index-MUEfIMdR.js";
|
|
3
3
|
/**
|
|
4
4
|
* A whole JSON Schema document as a Zod module: imports, `$defs` in dependency order,
|
|
5
5
|
* the root export, and the inferred type.
|
package/dist/zod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToZod } from "./zod-
|
|
1
|
+
export { t as schemaToZod } from "./zod-B-mxbHoq.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "schema-truth",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"description": "Generate Zod/Valibot/Effect/TypeBox/ArkType/Ajv/Yup schemas from JSON or YAML files",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ajv",
|
|
@@ -11,14 +11,15 @@
|
|
|
11
11
|
"yup",
|
|
12
12
|
"zod"
|
|
13
13
|
],
|
|
14
|
-
"homepage": "https://github.com/nakita628/schema-truth",
|
|
14
|
+
"homepage": "https://github.com/nakita628/truth/tree/main/npm/schema-truth#readme",
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/nakita628/
|
|
16
|
+
"url": "https://github.com/nakita628/truth/issues"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/nakita628/
|
|
21
|
+
"url": "git+https://github.com/nakita628/truth.git",
|
|
22
|
+
"directory": "npm/schema-truth"
|
|
22
23
|
},
|
|
23
24
|
"bin": {
|
|
24
25
|
"schema-truth-ajv": "dist/cli/ajv.js",
|
|
@@ -94,21 +95,22 @@
|
|
|
94
95
|
}
|
|
95
96
|
},
|
|
96
97
|
"publishConfig": {
|
|
97
|
-
"access": "public"
|
|
98
|
-
|
|
99
|
-
"scripts": {
|
|
100
|
-
"build": "vp pack",
|
|
101
|
-
"check": "vp check",
|
|
102
|
-
"fix": "vp check --fix",
|
|
103
|
-
"test": "vp test"
|
|
98
|
+
"access": "public",
|
|
99
|
+
"provenance": true
|
|
104
100
|
},
|
|
105
101
|
"dependencies": {
|
|
106
102
|
"@apidevtools/json-schema-ref-parser": "^16.0.5",
|
|
107
|
-
"@effect/platform-node": "4.1.
|
|
108
|
-
"effect": "4.1.
|
|
103
|
+
"@effect/platform-node": "4.1.2",
|
|
104
|
+
"effect": "4.1.2",
|
|
109
105
|
"oxfmt": "^0.75.0"
|
|
110
106
|
},
|
|
111
107
|
"devDependencies": {
|
|
112
108
|
"@types/node": "26.6.6"
|
|
109
|
+
},
|
|
110
|
+
"scripts": {
|
|
111
|
+
"build": "vp pack",
|
|
112
|
+
"check": "vp check",
|
|
113
|
+
"fix": "vp check --fix",
|
|
114
|
+
"test": "vp test"
|
|
113
115
|
}
|
|
114
|
-
}
|
|
116
|
+
}
|