schema-truth 0.8.12 → 0.8.14
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-91NQz0R7.js → ajv-BzXa3loS.js} +1 -1
- package/dist/ajv.js +1 -1
- package/dist/{arktype-Cl_XiSs3.js → arktype-o5UiPNHq.js} +28 -23
- 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-BxbvZp5H.js → cli-6GScU3W_.js} +2 -2
- package/dist/{effect-BLTKj8GH.js → effect-CYQf9Lw6.js} +5 -6
- package/dist/effect.js +1 -1
- package/dist/{helper-DRuGda2P.js → helper-DpwdwX03.js} +186 -15
- package/dist/index.d.ts +5 -0
- package/dist/index.js +9 -9
- package/dist/{typebox-BTCR9bNo.js → typebox-2MLHaziq.js} +5 -6
- package/dist/typebox.js +1 -1
- package/dist/{valibot-C1qkFYn6.js → valibot-CRyUoeJj.js} +5 -6
- package/dist/valibot.js +1 -1
- package/dist/{yup-Cec-EEni.js → yup-BqKfyIcd.js} +1 -1
- package/dist/yup.js +1 -1
- package/dist/{zod-CnDLSw9x.js → zod-xz1vNbs5.js} +26 -26
- package/dist/zod.js +1 -1
- package/package.json +1 -1
- package/dist/bigint-CkHij6xv.js +0 -70
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dt as normalizeTypes, Et as makeSafeKey, c as sanitizeSchema } from "./helper-DpwdwX03.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.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToAjv } from "./ajv-
|
|
1
|
+
export { t as schemaToAjv } from "./ajv-BzXa3loS.js";
|
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import { A as unionPrimitiveTypes,
|
|
2
|
-
import { n as bigintCall, r as bigintLiteral, t as bigintBounds } from "./bigint-CkHij6xv.js";
|
|
1
|
+
import { A as unionPrimitiveTypes, C as isNullMatchedFirst, D as ownProperties, Dt as normalizeTypes, E as numberWirePattern, Et as makeSafeKey, F as regexSource, G as planDocument, Gn as UNSAFE_GENERATED_MARKER, Gt as isDeepLocalPointer, H as definitionsOf, It as hasCombinator, J as schemaNamer, Jt as isNullable, Ln as QUOTE_OR_BACKSLASH_PATTERN, M as wireNullText, N as wireNumericKind, O as stringboolPattern, On as NUMBER_RANGES, Ot as resolveOpenAPIRef, P as formatPattern, Q as enumWithoutWrappedNull, Qt as isQuoted, Rt as hasFixedItemCount, S as integerWirePattern, T as isPrimitiveUnion, Tt as issueMessageExpression, U as emitOptionsOf, Ut as isArktypeDefinition, W as missingDefinitionComment, Wt as isComposite, Y as discriminatedMembers, Yt as isObjectPrototypeProperty, _ as valueListLiteral, at as arktypePreprocess, bn as INTEGER_TEXT_PATTERN, c as sanitizeSchema, ct as callbackReturn, d as hasParameterSerialization, dn as DEFAULT_ROOT_NAME, dt as findCodeExtensionKeysInSchema, en as isRootRef, et as itemsSchemaOf, f as parameterReaders, g as notPredicate, gt as isKeywordOnlyMember, h as isBigintFormat, ht as foldAllOfMembers, i as isEvaluatedKeyExpression, it as bigintValueLiteral, j as wireArrayOnce, k as stringboolTruthyPattern, lt as callbackType, m as withoutParameterSerialization, mn as DEFINITION_REF_PREFIXES, mt as constraintPredicate, nn as isShapelessMember, nt as bigintCall, ot as arktypeUnionLimit, p as propertyEmitOptions, pt as constraintMessage, q as rootNameOf, qt as isNullTypeMember, r as evaluatedProperties, rn as isStringWireLocation, rt as bigintLiteral, st as arktypeWrap, tn as isSchemaObject, tt as bigintBounds, u as withPolymorphicBases, ut as dslUnionMembers, v as hoistNestedRefs, vt as regexLiteral, w as isNullTextRead, x as impliedWireType, zt as hasFixedLength } from "./helper-DpwdwX03.js";
|
|
3
2
|
// src/generator/arktype/number.ts
|
|
4
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The comparators of a numeric node: `>= 1`, `< 5`, `% 2`. A 2020-12 numeric
|
|
5
|
+
* `exclusiveMinimum` beside `minimum` is a bound of its own, and only the stricter of the
|
|
6
|
+
* two is emitted: it says as much as both, and ArkType throws on a definition whose
|
|
7
|
+
* bounds leave no value (`number >= 0 & number > 10 & number <= 5`) when it is loaded.
|
|
8
|
+
*/
|
|
5
9
|
function numericConstraints(schema) {
|
|
6
10
|
return [
|
|
7
|
-
schema.minimum
|
|
8
|
-
op: schema.exclusiveMinimum === true ? ">" : ">=",
|
|
9
|
-
value: String(schema.minimum)
|
|
10
|
-
} : typeof schema.exclusiveMinimum === "number" ? {
|
|
11
|
+
typeof schema.exclusiveMinimum === "number" && (schema.minimum === void 0 || schema.exclusiveMinimum >= schema.minimum) ? {
|
|
11
12
|
op: ">",
|
|
12
13
|
value: String(schema.exclusiveMinimum)
|
|
13
|
-
} : void 0
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
} : schema.minimum === void 0 ? void 0 : {
|
|
15
|
+
op: schema.exclusiveMinimum === true ? ">" : ">=",
|
|
16
|
+
value: String(schema.minimum)
|
|
17
|
+
},
|
|
18
|
+
typeof schema.exclusiveMaximum === "number" && (schema.maximum === void 0 || schema.exclusiveMaximum <= schema.maximum) ? {
|
|
18
19
|
op: "<",
|
|
19
20
|
value: String(schema.exclusiveMaximum)
|
|
20
|
-
} : void 0
|
|
21
|
+
} : schema.maximum === void 0 ? void 0 : {
|
|
22
|
+
op: schema.exclusiveMaximum === true ? "<" : "<=",
|
|
23
|
+
value: String(schema.maximum)
|
|
24
|
+
},
|
|
21
25
|
schema.multipleOf !== void 0 ? {
|
|
22
26
|
op: "%",
|
|
23
27
|
value: String(schema.multipleOf)
|
|
@@ -189,7 +193,7 @@ function integer(schema, options) {
|
|
|
189
193
|
function lit(v, isBigint) {
|
|
190
194
|
if (v === null) return "null";
|
|
191
195
|
if (typeof v === "string") return `'${v}'`;
|
|
192
|
-
if (typeof v === "number" && isBigint) return
|
|
196
|
+
if (typeof v === "number" && isBigint) return bigintValueLiteral(v);
|
|
193
197
|
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
194
198
|
return JSON.stringify(v) ?? "null";
|
|
195
199
|
}
|
|
@@ -201,7 +205,7 @@ function isDslLiteralUnion(members) {
|
|
|
201
205
|
}
|
|
202
206
|
/**
|
|
203
207
|
* The ArkType definition of an enum: a `"a | b | c"` string union, or
|
|
204
|
-
* `type.enumerated(a, b, c)` past {@link
|
|
208
|
+
* `type.enumerated(a, b, c)` past the members {@link arktypeUnionLimit} allows. The members of an
|
|
205
209
|
* int64 / uint64 enum are bigint literals, as the value they match is.
|
|
206
210
|
*/
|
|
207
211
|
function _enum(schema) {
|
|
@@ -221,7 +225,7 @@ function _enum(schema) {
|
|
|
221
225
|
return expr;
|
|
222
226
|
}
|
|
223
227
|
const members = schema.enum.map((v) => lit(v, isBigint));
|
|
224
|
-
if (members.length >
|
|
228
|
+
if (members.length > arktypeUnionLimit(members)) return `type.enumerated(${members.join(",")})${describe}`;
|
|
225
229
|
const expr = `"${members.join(" | ")}"`;
|
|
226
230
|
if (errorMessage) return `type(${expr})${describe}`;
|
|
227
231
|
return expr;
|
|
@@ -475,16 +479,17 @@ function chunksOf(items, size) {
|
|
|
475
479
|
}
|
|
476
480
|
/**
|
|
477
481
|
* A union of ArkType expressions. Quoted members join into one string-DSL union, unless
|
|
478
|
-
*
|
|
482
|
+
* it has more members than {@link arktypeUnionLimit} allows: then literals become
|
|
479
483
|
* `type.enumerated(...)` and anything else is joined in groups, so no single string is
|
|
480
484
|
* long enough to exceed TypeScript's instantiation depth.
|
|
481
485
|
*/
|
|
482
486
|
function unionStr(schemas, inScope = false) {
|
|
483
487
|
if (!schemas.every(isQuoted)) return schemas.reduce(combine("|", inScope));
|
|
484
|
-
const members = schemas.
|
|
485
|
-
|
|
488
|
+
const members = schemas.flatMap((s) => dslUnionMembers(s.slice(1, -1)));
|
|
489
|
+
const limit = arktypeUnionLimit(members);
|
|
490
|
+
if (members.length <= limit) return `"${members.join(" | ")}"`;
|
|
486
491
|
if (isDslLiteralUnion(members)) return `type.enumerated(${members.join(",")})`;
|
|
487
|
-
return chunksOf(members,
|
|
492
|
+
return chunksOf(members, limit).map((group) => `"${group.join(" | ")}"`).reduce(combine("|", inScope));
|
|
488
493
|
}
|
|
489
494
|
function intersectionStr(schemas, inScope = false) {
|
|
490
495
|
return schemas.every(isQuoted) ? `"${schemas.map((s) => s.slice(1, -1)).join(" & ")}"` : schemas.reduce(combine("&", inScope));
|
|
@@ -523,7 +528,7 @@ function keywordConstraint(schema) {
|
|
|
523
528
|
}
|
|
524
529
|
function formatConst(value, isBigint) {
|
|
525
530
|
if (typeof value === "string") return `"'${value}'"`;
|
|
526
|
-
if (typeof value === "number" && isBigint) return `"${value}
|
|
531
|
+
if (typeof value === "number" && isBigint) return `"${bigintValueLiteral(value)}"`;
|
|
527
532
|
if (typeof value === "number" || typeof value === "boolean") return `"${String(value)}"`;
|
|
528
533
|
if (value !== null && typeof value === "object") return "\"unknown\"";
|
|
529
534
|
return `"${JSON.stringify(value) ?? "null"}"`;
|
|
@@ -744,8 +749,8 @@ function node(schema, rootName, isArktype, options) {
|
|
|
744
749
|
const unevaluatedItems = schema.unevaluatedItems;
|
|
745
750
|
const baseTuple = arktypeWrap$1(wireArray(describeWithMessage(isSchemaObject(unevaluatedItems) ? (() => {
|
|
746
751
|
const rest = arktype(unevaluatedItems, rootName, isArktype, options);
|
|
747
|
-
const
|
|
748
|
-
return `type([${items.join(",")},"..."
|
|
752
|
+
const restArray = isQuoted(rest) ? `"${rest.slice(1, -1)}[]"` : isArktypeDefinition(rest) ? `[${rest},"[]"]` : `${rest}.array()`;
|
|
753
|
+
return `type([${items.join(",")},"...",${restArray}])`;
|
|
749
754
|
})() : `type([${items.join(",")}])`, schema["x-prefixItems-message"])), schema);
|
|
750
755
|
const unevalItemsMessage = schema["x-unevaluatedItems-message"];
|
|
751
756
|
return unevaluatedItems === false && unevalItemsMessage ? `${baseTuple}.describe(${JSON.stringify(unevalItemsMessage)})` : baseTuple;
|
package/dist/arktype.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToArktype } from "./arktype-
|
|
1
|
+
export { t as schemaToArktype } from "./arktype-o5UiPNHq.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-BzXa3loS.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-6GScU3W_.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-o5UiPNHq.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-6GScU3W_.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-CYQf9Lw6.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-6GScU3W_.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-2MLHaziq.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-6GScU3W_.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-CRyUoeJj.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-6GScU3W_.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-BqKfyIcd.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-6GScU3W_.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-xz1vNbs5.js";
|
|
3
|
+
import { n as version, t as cli } from "../cli-6GScU3W_.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 { $t as isRecord } from "./helper-DpwdwX03.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.14";
|
|
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,5 +1,4 @@
|
|
|
1
|
-
import { A as unionPrimitiveTypes,
|
|
2
|
-
import { n as bigintCall, r as bigintLiteral, t as bigintBounds } from "./bigint-CkHij6xv.js";
|
|
1
|
+
import { A as unionPrimitiveTypes, Ct as effectMessage, D as ownProperties, Dt as normalizeTypes, E as numberWirePattern, Et as makeSafeKey, F as regexSource, G as planDocument, Gn as UNSAFE_GENERATED_MARKER, H as definitionsOf, Ht as hasType, It as hasCombinator, J as schemaNamer, Jt as isNullable, K as renderDefinitions, Kt as isDefaultOnlyMember, L as deepEqualExpression, Lt as hasConditional, N as wireNumericKind, O as stringboolPattern, On as NUMBER_RANGES, P as formatPattern, Q as enumWithoutWrappedNull, R as jsLiteral, Rt as hasFixedItemCount, S as integerWirePattern, St as effectErrorPart, T as isPrimitiveUnion, U as emitOptionsOf, Wt as isComposite, Y as discriminatedMembers, Yt as isObjectPrototypeProperty, Z as hasRootSelfReference, _ as valueListLiteral, b as effectWrap, bn as INTEGER_TEXT_PATTERN, c as sanitizeSchema, d as hasParameterSerialization, dn as DEFAULT_ROOT_NAME, dt as findCodeExtensionKeysInSchema, et as itemsSchemaOf, f as parameterReaders, g as notPredicate, gt as isKeywordOnlyMember, h as isBigintFormat, ht as foldAllOfMembers, i as isEvaluatedKeyExpression, it as bigintValueLiteral, j as wireArrayOnce, k as stringboolTruthyPattern, l as refTarget, m as withoutParameterSerialization, mt as constraintPredicate, nn as isShapelessMember, nt as bigintCall, p as propertyEmitOptions, pt as constraintMessage, q as rootNameOf, qt as isNullTypeMember, r as evaluatedProperties, rn as isStringWireLocation, rt as bigintLiteral, s as typeDeclaration, tn as isSchemaObject, tt as bigintBounds, u as withPolymorphicBases, v as hoistNestedRefs, vt as regexLiteral, w as isNullTextRead, x as impliedWireType, xt as effectError, y as effectPreprocess, zt as hasFixedLength } from "./helper-DpwdwX03.js";
|
|
3
2
|
// src/generator/effect/number.ts
|
|
4
3
|
/** The bound and `multipleOf` checks of a numeric node. */
|
|
5
4
|
function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
|
|
@@ -16,12 +15,12 @@ function numberChecks(schema, lit = (n) => `${n}`, suffix = "") {
|
|
|
16
15
|
return [
|
|
17
16
|
(() => {
|
|
18
17
|
if (schema.minimum !== void 0) return schema.exclusiveMinimum === true ? `Schema.isGreaterThan${suffix}(${lit(schema.minimum)}${exMinErrorPart})` : `Schema.isGreaterThanOrEqualTo${suffix}(${lit(schema.minimum)}${minErrorPart})`;
|
|
19
|
-
if (typeof schema.exclusiveMinimum === "number") return `Schema.isGreaterThan${suffix}(${lit(schema.exclusiveMinimum)}${exMinErrorPart})`;
|
|
20
18
|
})(),
|
|
19
|
+
typeof schema.exclusiveMinimum === "number" ? `Schema.isGreaterThan${suffix}(${lit(schema.exclusiveMinimum)}${exMinErrorPart})` : void 0,
|
|
21
20
|
(() => {
|
|
22
21
|
if (schema.maximum !== void 0) return schema.exclusiveMaximum === true ? `Schema.isLessThan${suffix}(${lit(schema.maximum)}${exMaxErrorPart})` : `Schema.isLessThanOrEqualTo${suffix}(${lit(schema.maximum)}${maxErrorPart})`;
|
|
23
|
-
if (typeof schema.exclusiveMaximum === "number") return `Schema.isLessThan${suffix}(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})`;
|
|
24
22
|
})(),
|
|
23
|
+
typeof schema.exclusiveMaximum === "number" ? `Schema.isLessThan${suffix}(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})` : void 0,
|
|
25
24
|
schema.multipleOf === void 0 ? void 0 : suffix === "BigInt" ? `Schema.makeFilter((input)=>input%${lit(schema.multipleOf)}===0n${multipleOfErrorPart})` : `Schema.isMultipleOf(${lit(schema.multipleOf)}${multipleOfErrorPart})`
|
|
26
25
|
].filter((v) => v !== void 0);
|
|
27
26
|
}
|
|
@@ -93,7 +92,7 @@ function integer(schema, options) {
|
|
|
93
92
|
function literal(v, isBigint) {
|
|
94
93
|
if (v === null) return "null";
|
|
95
94
|
if (typeof v === "string") return `"${v}"`;
|
|
96
|
-
if (typeof v === "number" && isBigint) return
|
|
95
|
+
if (typeof v === "number" && isBigint) return bigintValueLiteral(v);
|
|
97
96
|
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
98
97
|
return JSON.stringify(v) ?? "null";
|
|
99
98
|
}
|
|
@@ -548,7 +547,7 @@ function node(schema, rootName, isEffect, options) {
|
|
|
548
547
|
}
|
|
549
548
|
if (schema.const !== void 0) {
|
|
550
549
|
const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
|
|
551
|
-
const literalCode = typeof schema.const === "number" && isInt64(schema) ? `Schema.Literal(${schema.const}
|
|
550
|
+
const literalCode = typeof schema.const === "number" && isInt64(schema) ? `Schema.Literal(${bigintValueLiteral(schema.const)})` : isComposite(schema.const) ? deepEqualSchema([schema.const]) : `Schema.Literal(${JSON.stringify(schema.const)})`;
|
|
552
551
|
const withMessage = constMessage ? `${literalCode}.annotate(${effectError(constMessage)})` : literalCode;
|
|
553
552
|
const input = literalInput([schema.const]);
|
|
554
553
|
return effectWrap$1(input ? `${input}.pipe(Schema.decodeTo(${withMessage}))` : withMessage, schema);
|
package/dist/effect.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToEffect } from "./effect-
|
|
1
|
+
export { t as schemaToEffect } from "./effect-CYQf9Lw6.js";
|
|
@@ -1620,6 +1620,51 @@ function readCodeExtension(schema, key, options) {
|
|
|
1620
1620
|
}
|
|
1621
1621
|
// src/helper/arktype-wrap.ts
|
|
1622
1622
|
/**
|
|
1623
|
+
* The most members a string-DSL union of string literals (`"'a' | 'b' | ..."`) may have.
|
|
1624
|
+
* ArkType parses the string at the type level, and a longer union exceeds TypeScript's
|
|
1625
|
+
* instantiation depth (TS2589), so a longer one is written another way.
|
|
1626
|
+
*/
|
|
1627
|
+
const ARKTYPE_STRING_UNION_LIMIT = 16;
|
|
1628
|
+
/**
|
|
1629
|
+
* The most members a string-DSL union may have when one of them is not a string literal
|
|
1630
|
+
* (`null`, a number, a keyword such as `string`): such a union exceeds TypeScript's
|
|
1631
|
+
* instantiation depth sooner, at 13 members.
|
|
1632
|
+
*/
|
|
1633
|
+
const ARKTYPE_MIXED_UNION_LIMIT = 12;
|
|
1634
|
+
/** A string-DSL member that is one string literal. */
|
|
1635
|
+
const DSL_STRING_LITERAL_PATTERN = /^'[^'\\]*'$/u;
|
|
1636
|
+
/** The most members a string-DSL union of `members` may have. */
|
|
1637
|
+
function arktypeUnionLimit(members) {
|
|
1638
|
+
return members.every((member) => DSL_STRING_LITERAL_PATTERN.test(member)) ? ARKTYPE_STRING_UNION_LIMIT : ARKTYPE_MIXED_UNION_LIMIT;
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* The top-level members of a string-DSL definition (its text without the outer quotes):
|
|
1642
|
+
* the text split at each ` | ` outside a quoted literal (where a backslash escapes the next
|
|
1643
|
+
* character) and outside brackets.
|
|
1644
|
+
*/
|
|
1645
|
+
function dslUnionMembers(definition) {
|
|
1646
|
+
const members = [];
|
|
1647
|
+
let depth = 0;
|
|
1648
|
+
let quote = "";
|
|
1649
|
+
let start = 0;
|
|
1650
|
+
for (let i = 0; i < definition.length; i += 1) {
|
|
1651
|
+
const char = definition[i];
|
|
1652
|
+
if (quote !== "") {
|
|
1653
|
+
if (char === "\\") i += 1;
|
|
1654
|
+
else if (char === quote) quote = "";
|
|
1655
|
+
} else if (char === "'" || char === "\"") quote = char;
|
|
1656
|
+
else if (char === "(" || char === "[" || char === "{") depth += 1;
|
|
1657
|
+
else if (char === ")" || char === "]" || char === "}") depth -= 1;
|
|
1658
|
+
else if (depth === 0 && definition.startsWith(" | ", i)) {
|
|
1659
|
+
members.push(definition.slice(start, i));
|
|
1660
|
+
start = i + 3;
|
|
1661
|
+
i += 2;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
members.push(definition.slice(start));
|
|
1665
|
+
return members;
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1623
1668
|
* A definition a callback checks values against at validation time. Inside
|
|
1624
1669
|
* `scope({...})` it goes through the scope (bound to `$`), which resolves the aliases
|
|
1625
1670
|
* it may name; the global `type(...)` cannot. An expression that already evaluates to a
|
|
@@ -1665,7 +1710,7 @@ function arktypePreprocess(readers, inner, input = "unknown") {
|
|
|
1665
1710
|
function arktypeWrap(arktypeStr, schema, options) {
|
|
1666
1711
|
const inScope = options?.scopeMode === true;
|
|
1667
1712
|
const isDefinition = isArktypeDefinition;
|
|
1668
|
-
const withNullable = isNullable(schema) && options?.nullSchema !== true ? isQuoted(arktypeStr) ? `"${arktypeStr.slice(1, -1)} | null"` : inScope && isDefinition(arktypeStr) ? `[${arktypeStr},"|","null"]` : `type(${arktypeStr}).or("null")` : arktypeStr;
|
|
1713
|
+
const withNullable = isNullable(schema) && options?.nullSchema !== true ? isQuoted(arktypeStr) && dslUnionMembers(arktypeStr.slice(1, -1)).length < ARKTYPE_MIXED_UNION_LIMIT ? `"${arktypeStr.slice(1, -1)} | null"` : inScope && isDefinition(arktypeStr) ? `[${arktypeStr},"|","null"]` : `type(${arktypeStr}).or("null")` : arktypeStr;
|
|
1669
1714
|
const withReadonly = schema["x-readonly"] === true ? isDefinition(withNullable) ? `type(${withNullable}).readonly()` : `${withNullable}.readonly()` : withNullable;
|
|
1670
1715
|
const brand = schema["x-brand"];
|
|
1671
1716
|
const withBrand = typeof brand === "string" ? isDefinition(withReadonly) ? `type(${withReadonly}).brand("${brand}")` : `${withReadonly}.brand("${brand}")` : withReadonly;
|
|
@@ -1680,6 +1725,127 @@ function arktypeWrap(arktypeStr, schema, options) {
|
|
|
1680
1725
|
if (inScope && isDefinition(withCodeExts)) return `[${withCodeExts},"@",${text}]`;
|
|
1681
1726
|
return `${isDefinition(withCodeExts) ? `type(${withCodeExts})` : withCodeExts}.describe(${text})`;
|
|
1682
1727
|
}
|
|
1728
|
+
// src/helper/bigint.ts
|
|
1729
|
+
/** A bigint literal, `5n`, spelled in digits however the number prints. */
|
|
1730
|
+
function bigintLiteral(n) {
|
|
1731
|
+
return `${BigInt(n)}n`;
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* A schema value (a `default`, an `enum` member) as the literal of a bigint schema: `1e21`
|
|
1735
|
+
* is `1000000000000000000000n`, not `1e+21n`, which does not parse. A fractional or
|
|
1736
|
+
* non-finite number is no bigint (`BigInt(1.5)` throws) and stays a number literal, which
|
|
1737
|
+
* no bigint equals.
|
|
1738
|
+
*/
|
|
1739
|
+
function bigintValueLiteral(n) {
|
|
1740
|
+
return Number.isInteger(n) ? bigintLiteral(n) : String(n);
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* A `BigInt(5)` call, the spelling `format: bigint` has always used. A divisor a number
|
|
1744
|
+
* cannot hold exactly is written as a literal, `12345678901234567n`, which keeps every digit.
|
|
1745
|
+
*/
|
|
1746
|
+
function bigintCall(n) {
|
|
1747
|
+
return typeof n === "bigint" ? `${n}n` : `BigInt(${n})`;
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* A bigint check takes an integer, but a schema's bound can be fractional: `BigInt(0.5)`
|
|
1751
|
+
* throws a `RangeError` and `0.5n` does not parse. A fractional bound is rounded to the
|
|
1752
|
+
* integer that admits the same bigints: an inclusive minimum and an exclusive maximum
|
|
1753
|
+
* round up, an inclusive maximum and an exclusive minimum round down. A non-finite bound
|
|
1754
|
+
* (a YAML `.inf`) is left out; `sanitizeSchema` drops it before the generator anyway.
|
|
1755
|
+
*/
|
|
1756
|
+
function bigintBound(value, round) {
|
|
1757
|
+
return value !== void 0 && Number.isFinite(value) ? Math[round](value) : void 0;
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* The positive integer divisor a bigint `multipleOf` check can use. An integer is taken as
|
|
1761
|
+
* it is (`BigInt(value)` is exact for any integer a number holds), and a negative one by its
|
|
1762
|
+
* absolute value, which has the same multiples. A bigint `x` is a multiple of `p / q` (in
|
|
1763
|
+
* lowest terms) exactly when it is a multiple of `p`, so a fraction reduces to its
|
|
1764
|
+
* numerator: 2.5 is 5/2 and becomes `5`. The fraction is read from the number's shortest
|
|
1765
|
+
* decimal spelling. Zero or a non-finite divisor has no such integer and is left out (a
|
|
1766
|
+
* bigint `% 0n` throws). A reduced divisor a number cannot hold exactly stays a bigint.
|
|
1767
|
+
*/
|
|
1768
|
+
function bigintDivisor(value) {
|
|
1769
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value === 0) return void 0;
|
|
1770
|
+
const magnitude = Math.abs(value);
|
|
1771
|
+
if (Number.isInteger(magnitude)) return magnitude;
|
|
1772
|
+
const match = /^(\d+)(?:\.(\d+))?(?:e-(\d+))?$/.exec(String(magnitude));
|
|
1773
|
+
if (!match) return void 0;
|
|
1774
|
+
const [, whole = "", fraction = "", exponent = "0"] = match;
|
|
1775
|
+
const scale = fraction.length + Number(exponent);
|
|
1776
|
+
const numerator = BigInt(whole + fraction);
|
|
1777
|
+
let [a, b] = [numerator, 10n ** BigInt(scale)];
|
|
1778
|
+
while (b !== 0n) [a, b] = [b, a % b];
|
|
1779
|
+
const divisor = numerator / a;
|
|
1780
|
+
return BigInt(Number(divisor)) === divisor ? Number(divisor) : divisor;
|
|
1781
|
+
}
|
|
1782
|
+
/**
|
|
1783
|
+
* The schema with its bounds and `multipleOf` made integers a bigint check can take: see
|
|
1784
|
+
* {@link bigintBound} and {@link bigintDivisor}. A bound or divisor that has no such
|
|
1785
|
+
* integer is left out, together with the draft-04 boolean or the message that belongs to it.
|
|
1786
|
+
*/
|
|
1787
|
+
function bigintBounds(schema) {
|
|
1788
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, "x-multipleOf-message": multipleOfMessage, ...rest } = schema;
|
|
1789
|
+
const isExclusiveMin = exclusiveMinimum === true;
|
|
1790
|
+
const isExclusiveMax = exclusiveMaximum === true;
|
|
1791
|
+
const min = bigintBound(minimum, isExclusiveMin ? "floor" : "ceil");
|
|
1792
|
+
const max = bigintBound(maximum, isExclusiveMax ? "ceil" : "floor");
|
|
1793
|
+
const exMin = typeof exclusiveMinimum === "number" ? bigintBound(exclusiveMinimum, "floor") : min !== void 0 ? exclusiveMinimum : void 0;
|
|
1794
|
+
const exMax = typeof exclusiveMaximum === "number" ? bigintBound(exclusiveMaximum, "ceil") : max !== void 0 ? exclusiveMaximum : void 0;
|
|
1795
|
+
const divisor = bigintDivisor(multipleOf);
|
|
1796
|
+
return {
|
|
1797
|
+
...rest,
|
|
1798
|
+
...min !== void 0 && { minimum: min },
|
|
1799
|
+
...max !== void 0 && { maximum: max },
|
|
1800
|
+
...exMin !== void 0 && { exclusiveMinimum: exMin },
|
|
1801
|
+
...exMax !== void 0 && { exclusiveMaximum: exMax },
|
|
1802
|
+
...divisor !== void 0 && { multipleOf: divisor },
|
|
1803
|
+
...divisor !== void 0 && multipleOfMessage !== void 0 && { "x-multipleOf-message": multipleOfMessage }
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Whether a bigint-format node is emitted as bigints. An `enum` or `const` is spelled with
|
|
1808
|
+
* bigint literals for `int64` / `uint64` and with number literals for `format: bigint`;
|
|
1809
|
+
* any other node is a bigint schema only as an `integer` (a `number` with the format is a
|
|
1810
|
+
* plain number schema).
|
|
1811
|
+
*/
|
|
1812
|
+
function isBigintSchema(node) {
|
|
1813
|
+
if (node.enum !== void 0 || node.const !== void 0) return node.format !== "bigint";
|
|
1814
|
+
return (node.type === void 0 ? [] : [node.type].flat()).includes("integer");
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* Whether a default can be written for a node of the given bigint format: a fraction has
|
|
1818
|
+
* no bigint spelling, and `BigInt(1.5)` would throw as the generated module loads.
|
|
1819
|
+
*/
|
|
1820
|
+
function isWritableBigintDefault(value, format) {
|
|
1821
|
+
return typeof value !== "number" || format === void 0 || Number.isInteger(value);
|
|
1822
|
+
}
|
|
1823
|
+
/**
|
|
1824
|
+
* The bigint `format` (`int64`, `uint64` or `bigint`) a node's values have: its own, or the
|
|
1825
|
+
* one on the definition its `$ref` names, on an `allOf` member or on every non-null member
|
|
1826
|
+
* of a union (the first one's), so a `default` beside a
|
|
1827
|
+
* `$ref` is written as the bigint the target holds. `holdsBigint` narrows which nodes count,
|
|
1828
|
+
* for a target that spells some of them (an `enum`) with numbers. A reference already being
|
|
1829
|
+
* read ends the search, as a cycle does.
|
|
1830
|
+
*/
|
|
1831
|
+
function bigintFormatOf(schema, definitions, holdsBigint = () => true) {
|
|
1832
|
+
const search = (node, reading) => {
|
|
1833
|
+
const { format } = node;
|
|
1834
|
+
if ((format === "int64" || format === "uint64" || format === "bigint") && holdsBigint(node)) return format;
|
|
1835
|
+
if (node.$ref !== void 0 && !reading.has(node.$ref)) {
|
|
1836
|
+
const target = definitionOf$1(node.$ref, definitions);
|
|
1837
|
+
const found = target === void 0 ? void 0 : search(target, /* @__PURE__ */ new Set([...reading, node.$ref]));
|
|
1838
|
+
if (found !== void 0) return found;
|
|
1839
|
+
}
|
|
1840
|
+
for (const member of node.allOf ?? []) {
|
|
1841
|
+
const found = search(member, reading);
|
|
1842
|
+
if (found !== void 0) return found;
|
|
1843
|
+
}
|
|
1844
|
+
const [first, ...rest] = (node.anyOf ?? node.oneOf ?? []).filter((member) => member.type !== "null").map((member) => search(member, reading));
|
|
1845
|
+
return first !== void 0 && rest.every((found) => found !== void 0) ? first : void 0;
|
|
1846
|
+
};
|
|
1847
|
+
return search(schema, /* @__PURE__ */ new Set());
|
|
1848
|
+
}
|
|
1683
1849
|
// src/helper/schema.ts
|
|
1684
1850
|
/** `definitions` and `$defs` read as one map, `$defs` winning on a shared name. */
|
|
1685
1851
|
function collectDefinitions(schema) {
|
|
@@ -2035,6 +2201,7 @@ function typeboxDefaultOpt(schema, stringWire = false, definitions) {
|
|
|
2035
2201
|
const result = coerceDefault(schema, schema.default, definitions);
|
|
2036
2202
|
if (!result.keep) return [];
|
|
2037
2203
|
const value = stringWire ? String(result.value) : result.value;
|
|
2204
|
+
if (typeof value === "number" && bigintFormatOf(schema, definitions, isBigintSchema) === "bigint") return Number.isInteger(value) ? [`default:${bigintLiteral(value)}`] : [];
|
|
2038
2205
|
return [`default:${typeof value === "boolean" || typeof value === "number" ? `${value}` : JSON.stringify(value)}`];
|
|
2039
2206
|
}
|
|
2040
2207
|
/**
|
|
@@ -2272,10 +2439,10 @@ function effectPreprocess(readers, inner) {
|
|
|
2272
2439
|
return `Schema.Unknown.pipe(${readers.map((reader) => `Schema.decodeTo(Schema.Unknown,SchemaTransformation.transform<unknown,unknown>({decode:${reader},encode:(output)=>output}))`).join(",")},Schema.decodeTo(${inner}))`;
|
|
2273
2440
|
}
|
|
2274
2441
|
/** A default as the Effect literal of the schema's decoded type: a bigint for a 64-bit integer. */
|
|
2275
|
-
function defaultLiteral$1(
|
|
2442
|
+
function defaultLiteral$1(format, value) {
|
|
2276
2443
|
if (typeof value === "number") {
|
|
2277
|
-
if (
|
|
2278
|
-
if (
|
|
2444
|
+
if (format === "int64" || format === "uint64") return bigintValueLiteral(value);
|
|
2445
|
+
if (format === "bigint") return `BigInt(${value})`;
|
|
2279
2446
|
}
|
|
2280
2447
|
return jsLiteral(value);
|
|
2281
2448
|
}
|
|
@@ -2309,7 +2476,8 @@ function effectWrap(effectStr, schema, options) {
|
|
|
2309
2476
|
const withCodeExts = codeChain.length === 0 ? withBrand : `${withBrand}${codeChain.join("")}`;
|
|
2310
2477
|
const defaultResult = schema.default !== void 0 ? coerceDefault(schema, schema.default, options?.definitions) : void 0;
|
|
2311
2478
|
const decodingDefault = options?.stringWire === true ? "Schema.withDecodingDefaultType" : "Schema.withDecodingDefault";
|
|
2312
|
-
const
|
|
2479
|
+
const defaultFormat = typeof defaultResult?.value === "number" ? bigintFormatOf(schema, options?.definitions, isBigintSchema) : void 0;
|
|
2480
|
+
const withDefault = defaultResult?.keep === true && isWritableBigintDefault(defaultResult.value, defaultFormat) ? `${withCodeExts}.pipe(${decodingDefault}(Effect.succeed(${defaultLiteral$1(defaultFormat, defaultResult.value)})))` : withCodeExts;
|
|
2313
2481
|
const examples = examplesOf(schema);
|
|
2314
2482
|
const ann = {};
|
|
2315
2483
|
if (schema.description !== void 0) ann.description = schema.description;
|
|
@@ -2426,7 +2594,7 @@ function isBigintFormat(schema) {
|
|
|
2426
2594
|
}
|
|
2427
2595
|
/** A value as a TypeScript literal. Numbers of a bigint schema are `0n`, not `0`. */
|
|
2428
2596
|
function literal(value, bigint) {
|
|
2429
|
-
if (bigint && typeof value === "number" && Number.
|
|
2597
|
+
if (bigint && typeof value === "number" && Number.isInteger(value)) return bigintLiteral(value);
|
|
2430
2598
|
return JSON.stringify(value);
|
|
2431
2599
|
}
|
|
2432
2600
|
/**
|
|
@@ -2932,7 +3100,7 @@ function nonNullType(schema, flavour, rootName) {
|
|
|
2932
3100
|
return `(${members.join(" & ")})`;
|
|
2933
3101
|
}
|
|
2934
3102
|
if (schema.not) return "unknown";
|
|
2935
|
-
const literal = (value) => typeof value === "number" && isInt64(schema) ?
|
|
3103
|
+
const literal = (value) => typeof value === "number" && isInt64(schema) ? bigintValueLiteral(value) : jsLiteral(value);
|
|
2936
3104
|
if (schema.const !== void 0) return literal(schema.const);
|
|
2937
3105
|
if (schema.enum) {
|
|
2938
3106
|
if (schema.enum.length === 1) return literal(schema.enum[0]);
|
|
@@ -3060,11 +3228,11 @@ function unlessEvaluated(isEvaluated, body) {
|
|
|
3060
3228
|
}
|
|
3061
3229
|
// src/helper/valibot-wrap.ts
|
|
3062
3230
|
/** A default as the Valibot literal of the schema's input: a bigint for a 64-bit integer. */
|
|
3063
|
-
function defaultLiteral(
|
|
3231
|
+
function defaultLiteral(format, value, stringWire) {
|
|
3064
3232
|
if (stringWire) return jsLiteral(wireDefaultValue(value));
|
|
3065
3233
|
if (typeof value === "number") {
|
|
3066
|
-
if (
|
|
3067
|
-
if (
|
|
3234
|
+
if (format === "int64" || format === "uint64") return bigintValueLiteral(value);
|
|
3235
|
+
if (format === "bigint") return `BigInt(${value})`;
|
|
3068
3236
|
}
|
|
3069
3237
|
return jsLiteral(value);
|
|
3070
3238
|
}
|
|
@@ -3091,7 +3259,8 @@ function valibotWrap(valibotStr, schema, options) {
|
|
|
3091
3259
|
const withNullable = isNullable(schema) && options?.nullSchema !== true || nullText && !isNullMatchedFirst(schema) ? `v.nullable(${valibotStr})` : valibotStr;
|
|
3092
3260
|
const withNullText = nullText ? `v.pipe(v.unknown(),v.transform(${wireNullText("input")}),${withNullable})` : withNullable;
|
|
3093
3261
|
const defaultResult = schema.default !== void 0 ? coerceDefault(schema, schema.default, options?.definitions) : void 0;
|
|
3094
|
-
const
|
|
3262
|
+
const defaultFormat = typeof defaultResult?.value === "number" ? bigintFormatOf(schema, options?.definitions, isBigintSchema) : void 0;
|
|
3263
|
+
const withDefault = defaultResult?.keep === true && isWritableBigintDefault(defaultResult.value, defaultFormat) ? `v.optional(${withNullText},${defaultLiteral(defaultFormat, defaultResult.value, options?.stringWire === true)})` : withNullText;
|
|
3095
3264
|
const examples = examplesOf(schema);
|
|
3096
3265
|
const actions = [];
|
|
3097
3266
|
if (schema.description !== void 0) actions.push(`v.description(${JSON.stringify(schema.description)})`);
|
|
@@ -3129,11 +3298,13 @@ function valibotWrap(valibotStr, schema, options) {
|
|
|
3129
3298
|
* @see https://zod.dev/metadata
|
|
3130
3299
|
*/
|
|
3131
3300
|
function zodWrap(zodStr, schema, options) {
|
|
3301
|
+
const bigintFormat = () => bigintFormatOf(schema, options?.definitions, isBigintSchema);
|
|
3132
3302
|
const formatLiteral = (value) => {
|
|
3133
3303
|
if (typeof value === "boolean") return `${value}`;
|
|
3134
3304
|
if (typeof value === "number") {
|
|
3135
|
-
|
|
3136
|
-
if (
|
|
3305
|
+
const format = bigintFormat();
|
|
3306
|
+
if (format === "int64" || format === "uint64") return bigintValueLiteral(value);
|
|
3307
|
+
if (format === "bigint") return `BigInt(${value})`;
|
|
3137
3308
|
return `${value}`;
|
|
3138
3309
|
}
|
|
3139
3310
|
if (schema.type === "date" && typeof value === "string") return `new Date(${JSON.stringify(value)})`;
|
|
@@ -3141,7 +3312,7 @@ function zodWrap(zodStr, schema, options) {
|
|
|
3141
3312
|
};
|
|
3142
3313
|
const defaultResult = schema.default !== void 0 ? coerceDefault(schema, schema.default, options?.definitions) : void 0;
|
|
3143
3314
|
const withNullable = isNullable(schema) && options?.nullSchema !== true ? `${zodStr}.nullable()` : zodStr;
|
|
3144
|
-
const withDefault = defaultResult?.keep ? `${withNullable}.default(${formatLiteral(defaultResult.value)})` : withNullable;
|
|
3315
|
+
const withDefault = defaultResult?.keep === true && (typeof defaultResult.value !== "number" || isWritableBigintDefault(defaultResult.value, bigintFormat())) ? `${withNullable}.default(${formatLiteral(defaultResult.value)})` : withNullable;
|
|
3145
3316
|
const withReadonly = schema["x-readonly"] === true ? `${withDefault}.readonly()` : withDefault;
|
|
3146
3317
|
const withPrefault = schema["x-prefault"] !== void 0 ? `${withReadonly}.prefault(${formatLiteral(schema["x-prefault"])})` : withReadonly;
|
|
3147
3318
|
const withCatch = schema["x-catch"] !== void 0 ? `${withPrefault}.catch(${formatLiteral(schema["x-catch"])})` : withPrefault;
|
|
@@ -3168,4 +3339,4 @@ function zodWrap(zodStr, schema, options) {
|
|
|
3168
3339
|
if (preprocess) return preprocess;
|
|
3169
3340
|
return withMeta;
|
|
3170
3341
|
}
|
|
3171
|
-
export { isOptionalByDefault as $,
|
|
3342
|
+
export { isOptionalByDefault as $, isRecord as $t, unionPrimitiveTypes as A, NUMERIC_KEYWORDS as An, toPascalCase as At, typeboxMetaOpts as B, STRINGBOOL_TRUTHY_PATTERN as Bn, hasNumericKeyword as Bt, isNullMatchedFirst as C, JSON_SCHEMA_TYPES as Cn, effectMessage as Ct, ownProperties as D, NUMBER_FORMATS as Dn, normalizeTypes as Dt, numberWirePattern as E, NOT_KEYWORD_UNSUPPORTED_MARKER as En, makeSafeKey as Et, regexSource as F, PARAM_LOCATIONS as Fn, zodErrorPart as Ft, planDocument as G, UNSAFE_GENERATED_MARKER as Gn, isDeepLocalPointer as Gt, definitionsOf as H, STRING_KEYWORDS as Hn, hasType as Ht, timePattern as I, PARAM_STYLES as In, hasCombinator as It, schemaNamer as J, ZOD_CODE_EXTENSION_KEYS as Jn, isNullable as Jt, renderDefinitions as K, VALIBOT_CODE_EXTENSION_KEYS as Kn, isDefaultOnlyMember as Kt, deepEqualExpression as L, QUOTE_OR_BACKSLASH_PATTERN as Ln, hasConditional as Lt, wireNullText as M, OFFSET_PATTERN_SOURCE as Mn, valibotErrorPart as Mt, wireNumericKind as N, OPENAPI_COMPONENT_SUFFIX_MAP as Nn, zodBaseError as Nt, stringboolPattern as O, NUMBER_RANGES as On, resolveOpenAPIRef as Ot, formatPattern as P, OUTPUT_EXTENSION as Pn, zodError as Pt, enumWithoutWrappedNull as Q, isQuoted as Qt, jsLiteral as R, ROOT_REFS as Rn, hasFixedItemCount as Rt, integerWirePattern as S, ISO_4217_CURRENCY_CODES as Sn, effectErrorPart as St, isPrimitiveUnion as T, NON_IDENTIFIER_CHARACTER_PATTERN as Tn, issueMessageExpression as Tt, emitOptionsOf as U, STRING_WIRE_LOCATIONS as Un, isArktypeDefinition as Ut, typeboxRefOpt as V, STRING_FORMATS as Vn, hasStringKeyword as Vt, missingDefinitionComment as W, UNICODE_ESCAPE_PATTERN as Wn, isComposite as Wt, cyclicDefinitionNames as X, isPlainObject as Xt, discriminatedMembers as Y, isObjectPrototypeProperty as Yt, hasRootSelfReference as Z, isPrimitive as Zt, valueListLiteral as _, IDENTIFIER_PATTERN as _n, patternSource as _t, unlessEvaluated as a, ANCHOR_REF_PATTERN as an, arktypePreprocess as at, effectWrap as b, INTEGER_TEXT_PATTERN as bn, definitionOf$1 as bt, sanitizeSchema as c, COMPONENT_SCHEMA_REF_PREFIX as cn, callbackReturn as ct, hasParameterSerialization as d, DEFAULT_ROOT_NAME as dn, findCodeExtensionKeysInSchema as dt, isRootRef as en, itemsSchemaOf as et, parameterReaders as f, DEFINITION_KEYWORDS as fn, hasNotKeyword as ft, notPredicate as g, FORMAT_PATTERNS as gn, isKeywordOnlyMember as gt, isBigintFormat as h, EFFECT_CODE_EXTENSION_KEYS as hn, foldAllOfMembers as ht, isEvaluatedKeyExpression as i, ALL_CODE_EXTENSION_KEYS as in, bigintValueLiteral as it, wireArrayOnce as j, OBJECT_PROTOTYPE_PROPERTIES as jn, valibotError as jt, stringboolTruthyPattern as k, NUMBER_WIRE_PATTERN as kn, toIdentifierPascalCase as kt, refTarget as l, CONTENT_ENCODINGS as ln, callbackType as lt, withoutParameterSerialization as m, DEFINITION_REF_PREFIXES as mn, constraintPredicate as mt, valibotWrap as n, isShapelessMember as nn, bigintCall as nt, typeboxWrap as o, ARKTYPE_CODE_EXTENSION_KEYS as on, arktypeUnionLimit as ot, propertyEmitOptions as p, DEFINITION_POINTER_PATTERN as pn, constraintMessage as pt, rootNameOf as q, WIRE_PRIMITIVE_ORDER as qn, isNullTypeMember as qt, evaluatedProperties as r, isStringWireLocation as rn, bigintLiteral as rt, typeDeclaration as s, ARROW_FUNCTION_PATTERN as sn, arktypeWrap as st, zodWrap as t, isSchemaObject as tn, bigintBounds as tt, withPolymorphicBases as u, DATE_PATTERN_SOURCE as un, dslUnionMembers as ut, hoistNestedRefs as v, IF_THEN_ELSE_UNSUPPORTED_MARKER as vn, regexLiteral as vt, isNullTextRead as w, MISSING_DEFINITION_PREFIX as wn, encodeNonAscii as wt, impliedWireType as x, INTEGER_WIRE_PATTERN as xn, effectError as xt, effectPreprocess as y, INPUT_EXTENSIONS as yn, coerceDefault as yt, typeboxDefaultOpt as z, STRINGBOOL_PATTERN as zn, hasFixedLength as zt };
|
package/dist/index.d.ts
CHANGED
|
@@ -111,6 +111,7 @@ export declare function normalizeTypes(types?: string | readonly string[]): stri
|
|
|
111
111
|
export type DefaultSchema = {
|
|
112
112
|
readonly $ref?: string;
|
|
113
113
|
readonly type?: string | readonly string[];
|
|
114
|
+
readonly format?: string;
|
|
114
115
|
readonly nullable?: boolean;
|
|
115
116
|
readonly enum?: readonly unknown[];
|
|
116
117
|
readonly const?: unknown;
|
|
@@ -168,6 +169,10 @@ type DefaultResult = {
|
|
|
168
169
|
export declare function coerceDefault(schema: DefaultSchema, value: unknown, definitions?: {
|
|
169
170
|
readonly [name: string]: DefaultSchema;
|
|
170
171
|
}): DefaultResult;
|
|
172
|
+
/** The definition a local `$ref` names, when `definitions` has it. */
|
|
173
|
+
export declare function definitionOf(ref: string, definitions: {
|
|
174
|
+
readonly [name: string]: DefaultSchema;
|
|
175
|
+
} | undefined): DefaultSchema | undefined;
|
|
171
176
|
/**
|
|
172
177
|
* A message as the expression an emitted check evaluates for each issue: an arrow source
|
|
173
178
|
* is applied to the issue, a sentence becomes a string literal.
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { An as NUMERIC_KEYWORDS, At as toPascalCase, Bn as STRINGBOOL_TRUTHY_PATTERN, Cn as JSON_SCHEMA_TYPES, Ct as effectMessage, Dn as NUMBER_FORMATS, Dt as normalizeTypes, En as NOT_KEYWORD_UNSUPPORTED_MARKER, Et as makeSafeKey, Fn as PARAM_LOCATIONS, Ft as zodErrorPart, Gn as UNSAFE_GENERATED_MARKER, Hn as STRING_KEYWORDS, In as PARAM_STYLES, Jn as ZOD_CODE_EXTENSION_KEYS, Kn as VALIBOT_CODE_EXTENSION_KEYS, Ln as QUOTE_OR_BACKSLASH_PATTERN, Mn as OFFSET_PATTERN_SOURCE, Mt as valibotErrorPart, Nn as OPENAPI_COMPONENT_SUFFIX_MAP, Nt as zodBaseError, On as NUMBER_RANGES, Ot as resolveOpenAPIRef, Pn as OUTPUT_EXTENSION, Pt as zodError, Rn as ROOT_REFS, Sn as ISO_4217_CURRENCY_CODES, St as effectErrorPart, Tn as NON_IDENTIFIER_CHARACTER_PATTERN, Tt as issueMessageExpression, Un as STRING_WIRE_LOCATIONS, Vn as STRING_FORMATS, Wn as UNICODE_ESCAPE_PATTERN, _n as IDENTIFIER_PATTERN, an as ANCHOR_REF_PATTERN, bn as INTEGER_TEXT_PATTERN, bt as definitionOf, cn as COMPONENT_SCHEMA_REF_PREFIX, dn as DEFAULT_ROOT_NAME, fn as DEFINITION_KEYWORDS, gn as FORMAT_PATTERNS, hn as EFFECT_CODE_EXTENSION_KEYS, in as ALL_CODE_EXTENSION_KEYS, jn as OBJECT_PROTOTYPE_PROPERTIES, jt as valibotError, kn as NUMBER_WIRE_PATTERN, kt as toIdentifierPascalCase, ln as CONTENT_ENCODINGS, mn as DEFINITION_REF_PREFIXES, on as ARKTYPE_CODE_EXTENSION_KEYS, pn as DEFINITION_POINTER_PATTERN, qn as WIRE_PRIMITIVE_ORDER, sn as ARROW_FUNCTION_PATTERN, un as DATE_PATTERN_SOURCE, vn as IF_THEN_ELSE_UNSUPPORTED_MARKER, wn as MISSING_DEFINITION_PREFIX, wt as encodeNonAscii, xn as INTEGER_WIRE_PATTERN, xt as effectError, yn as INPUT_EXTENSIONS, yt as coerceDefault, zn as STRINGBOOL_PATTERN } from "./helper-DpwdwX03.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-
|
|
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 };
|
|
3
|
+
import { n as ajv, t as schemaToAjv } from "./ajv-BzXa3loS.js";
|
|
4
|
+
import { n as arktype, t as schemaToArktype } from "./arktype-o5UiPNHq.js";
|
|
5
|
+
import { n as effect, r as wholeValueMessage, t as schemaToEffect } from "./effect-CYQf9Lw6.js";
|
|
6
|
+
import { n as nestedTypeboxOptions, r as typebox, t as schemaToTypebox } from "./typebox-2MLHaziq.js";
|
|
7
|
+
import { n as valibot, t as schemaToValibot } from "./valibot-CRyUoeJj.js";
|
|
8
|
+
import { n as yup, t as schemaToYup } from "./yup-BqKfyIcd.js";
|
|
9
|
+
import { i as zod, n as forwardIssue, r as nestedIssueMessageWrap, t as schemaToZod } from "./zod-xz1vNbs5.js";
|
|
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, definitionOf, 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 };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { $ as isOptionalByDefault, B as typeboxMetaOpts, Bt as
|
|
2
|
-
import { t as bigintBounds } from "./bigint-CkHij6xv.js";
|
|
1
|
+
import { $ as isOptionalByDefault, B as typeboxMetaOpts, Bt as hasNumericKeyword, Dt as normalizeTypes, En as NOT_KEYWORD_UNSUPPORTED_MARKER, Et as makeSafeKey, G as planDocument, Gt as isDeepLocalPointer, H as definitionsOf, It as hasCombinator, J as schemaNamer, Jt as isNullable, K as renderDefinitions, Kt as isDefaultOnlyMember, O as stringboolPattern, Ot as resolveOpenAPIRef, Q as enumWithoutWrappedNull, U as emitOptionsOf, V as typeboxRefOpt, Vt as hasStringKeyword, W as missingDefinitionComment, Wt as isComposite, X as cyclicDefinitionNames, Y as discriminatedMembers, Z as hasRootSelfReference, _t as patternSource, c as sanitizeSchema, dn as DEFAULT_ROOT_NAME, en as isRootRef, et as itemsSchemaOf, ft as hasNotKeyword, gt as isKeywordOnlyMember, ht as foldAllOfMembers, k as stringboolTruthyPattern, kn as NUMBER_WIRE_PATTERN, mn as DEFINITION_REF_PREFIXES, nn as isShapelessMember, o as typeboxWrap, q as rootNameOf, qt as isNullTypeMember, rn as isStringWireLocation, tt as bigintBounds, u as withPolymorphicBases, v as hoistNestedRefs, xn as INTEGER_WIRE_PATTERN, z as typeboxDefaultOpt, zt as hasFixedLength } from "./helper-DpwdwX03.js";
|
|
3
2
|
// src/generator/typebox/enum.ts
|
|
4
3
|
function lit(v) {
|
|
5
4
|
if (v === null) return "null";
|
|
@@ -394,12 +393,12 @@ function keywordSchema(schema) {
|
|
|
394
393
|
* embedding any meta options from the schema. Returns `Type.X(payload)` when
|
|
395
394
|
* no options.
|
|
396
395
|
*/
|
|
397
|
-
function tbComp(name, payload, schema, extraOpts = [], ref) {
|
|
396
|
+
function tbComp(name, payload, schema, extraOpts = [], ref, definitions) {
|
|
398
397
|
const opts = [
|
|
399
398
|
...typeboxRefOpt(ref),
|
|
400
399
|
...extraOpts,
|
|
401
400
|
...typeboxMetaOpts(schema),
|
|
402
|
-
...typeboxDefaultOpt(schema)
|
|
401
|
+
...typeboxDefaultOpt(schema, false, definitions)
|
|
403
402
|
];
|
|
404
403
|
return opts.length === 0 ? `${name}(${payload})` : `${name}(${payload},{${opts.join(",")}})`;
|
|
405
404
|
}
|
|
@@ -459,13 +458,13 @@ function typebox(schema, rootName = DEFAULT_ROOT_NAME, isTypebox = false, option
|
|
|
459
458
|
const literal = literals.length === 1 ? literals[0] : `Type.Union([${literals.join(",")}])`;
|
|
460
459
|
return `Type.Intersect([${member},Type.Object({${makeSafeKey(discriminated.propertyName)}:${literal}})])`;
|
|
461
460
|
});
|
|
462
|
-
return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(schema["x-oneOf-message"]), hostRef), schema);
|
|
461
|
+
return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(schema["x-oneOf-message"]), hostRef, definitions), schema);
|
|
463
462
|
}
|
|
464
463
|
if (schema.anyOf) {
|
|
465
464
|
if (schema.anyOf.length === 0) return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
|
|
466
465
|
const schemas = schema.anyOf.map((s) => typebox(s, rootName, isTypebox, childOptions));
|
|
467
466
|
const anyOfMessage = schema["x-implication-message"] ?? schema["x-anyOf-message"];
|
|
468
|
-
return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(anyOfMessage), hostRef), schema);
|
|
467
|
+
return typeboxWrap(tbComp("Type.Union", `[${schemas.join(",")}]`, schema, messageOpt(anyOfMessage), hostRef, definitions), schema);
|
|
469
468
|
}
|
|
470
469
|
if (schema.allOf) {
|
|
471
470
|
if (schema.allOf.length === 0) return typeboxWrap(tbPrim("Type.Any", schema, [], hostRef), schema);
|
package/dist/typebox.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToTypebox } from "./typebox-
|
|
1
|
+
export { t as schemaToTypebox } from "./typebox-2MLHaziq.js";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { $ as isOptionalByDefault, A as unionPrimitiveTypes,
|
|
2
|
-
import { n as bigintCall, r as bigintLiteral, t as bigintBounds } from "./bigint-CkHij6xv.js";
|
|
1
|
+
import { $ as isOptionalByDefault, A as unionPrimitiveTypes, D as ownProperties, Dt as normalizeTypes, E as numberWirePattern, Et as makeSafeKey, F as regexSource, G as planDocument, Gn as UNSAFE_GENERATED_MARKER, H as definitionsOf, Ht as hasType, It as hasCombinator, J as schemaNamer, Jt as isNullable, K as renderDefinitions, Kt as isDefaultOnlyMember, L as deepEqualExpression, Lt as hasConditional, Mt as valibotErrorPart, N as wireNumericKind, O as stringboolPattern, On as NUMBER_RANGES, P as formatPattern, Q as enumWithoutWrappedNull, R as jsLiteral, Rt as hasFixedItemCount, S as integerWirePattern, T as isPrimitiveUnion, Tt as issueMessageExpression, U as emitOptionsOf, Y as discriminatedMembers, Yt as isObjectPrototypeProperty, Z as hasRootSelfReference, Zt as isPrimitive, _ as valueListLiteral, a as unlessEvaluated, bn as INTEGER_TEXT_PATTERN, c as sanitizeSchema, d as hasParameterSerialization, dn as DEFAULT_ROOT_NAME, dt as findCodeExtensionKeysInSchema, et as itemsSchemaOf, f as parameterReaders, g as notPredicate, gt as isKeywordOnlyMember, h as isBigintFormat, ht as foldAllOfMembers, i as isEvaluatedKeyExpression, it as bigintValueLiteral, j as wireArrayOnce, jt as valibotError, k as stringboolTruthyPattern, l as refTarget, m as withoutParameterSerialization, mt as constraintPredicate, n as valibotWrap, nn as isShapelessMember, nt as bigintCall, p as propertyEmitOptions, pt as constraintMessage, q as rootNameOf, qt as isNullTypeMember, r as evaluatedProperties, rn as isStringWireLocation, rt as bigintLiteral, s as typeDeclaration, tn as isSchemaObject, tt as bigintBounds, u as withPolymorphicBases, v as hoistNestedRefs, vt as regexLiteral, w as isNullTextRead, x as impliedWireType, zt as hasFixedLength } from "./helper-DpwdwX03.js";
|
|
3
2
|
// src/generator/valibot/type.ts
|
|
4
3
|
/** The TypeScript type declared beside a recursive Valibot schema: its output type. */
|
|
5
4
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
@@ -24,12 +23,12 @@ function numberActions(schema, lit = (n) => `${n}`) {
|
|
|
24
23
|
return [
|
|
25
24
|
(() => {
|
|
26
25
|
if (schema.minimum !== void 0) return schema.exclusiveMinimum === true ? `v.gtValue(${lit(schema.minimum)}${exMinErrorPart})` : `v.minValue(${lit(schema.minimum)}${minErrorPart})`;
|
|
27
|
-
if (typeof schema.exclusiveMinimum === "number") return `v.gtValue(${lit(schema.exclusiveMinimum)}${exMinErrorPart})`;
|
|
28
26
|
})(),
|
|
27
|
+
typeof schema.exclusiveMinimum === "number" ? `v.gtValue(${lit(schema.exclusiveMinimum)}${exMinErrorPart})` : void 0,
|
|
29
28
|
(() => {
|
|
30
29
|
if (schema.maximum !== void 0) return schema.exclusiveMaximum === true ? `v.ltValue(${lit(schema.maximum)}${exMaxErrorPart})` : `v.maxValue(${lit(schema.maximum)}${maxErrorPart})`;
|
|
31
|
-
if (typeof schema.exclusiveMaximum === "number") return `v.ltValue(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})`;
|
|
32
30
|
})(),
|
|
31
|
+
typeof schema.exclusiveMaximum === "number" ? `v.ltValue(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})` : void 0,
|
|
33
32
|
schema.multipleOf !== void 0 ? `v.multipleOf(${lit(schema.multipleOf)}${multipleOfErrorPart})` : void 0
|
|
34
33
|
].filter((v) => v !== void 0);
|
|
35
34
|
}
|
|
@@ -128,7 +127,7 @@ function integer(schema, options) {
|
|
|
128
127
|
function lit(v, isBigint) {
|
|
129
128
|
if (v === null) return "null";
|
|
130
129
|
if (typeof v === "string") return `'${v.replaceAll("'", "\\'")}'`;
|
|
131
|
-
if (typeof v === "number" && isBigint) return
|
|
130
|
+
if (typeof v === "number" && isBigint) return bigintValueLiteral(v);
|
|
132
131
|
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
133
132
|
return JSON.stringify(v) ?? "null";
|
|
134
133
|
}
|
|
@@ -577,7 +576,7 @@ function node(schema, rootName, isValibot, options) {
|
|
|
577
576
|
const msgArg = constMessage ? valibotError(constMessage) : "";
|
|
578
577
|
const errorPart = msgArg ? `,${msgArg}` : "";
|
|
579
578
|
if (value === null) return valibotWrap$1(`v.null(${msgArg})`, schema);
|
|
580
|
-
const literal = typeof value === "number" && isInt64(schema) ? `v.literal(${value}
|
|
579
|
+
const literal = typeof value === "number" && isInt64(schema) ? `v.literal(${bigintValueLiteral(value)}${errorPart})` : isPrimitive(value) ? `v.literal(${JSON.stringify(value)}${errorPart})` : `v.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
|
|
581
580
|
const input = literalInput([value]);
|
|
582
581
|
return valibotWrap$1(input ? prependPipe(input, literal) : literal, schema);
|
|
583
582
|
}
|
package/dist/valibot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToValibot } from "./valibot-
|
|
1
|
+
export { t as schemaToValibot } from "./valibot-CRyUoeJj.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dt as normalizeTypes, Et as makeSafeKey, J as schemaNamer, c as sanitizeSchema, q as rootNameOf } from "./helper-DpwdwX03.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.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToYup } from "./yup-
|
|
1
|
+
export { t as schemaToYup } from "./yup-BqKfyIcd.js";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { A as unionPrimitiveTypes,
|
|
2
|
-
import { n as bigintCall, r as bigintLiteral, t as bigintBounds } from "./bigint-CkHij6xv.js";
|
|
1
|
+
import { A as unionPrimitiveTypes, C as isNullMatchedFirst, Dt as normalizeTypes, E as numberWirePattern, Et as makeSafeKey, Ft as zodErrorPart, G as planDocument, Gn as UNSAFE_GENERATED_MARKER, H as definitionsOf, Ht as hasType, I as timePattern, It as hasCombinator, J as schemaNamer, Jt as isNullable, K as renderDefinitions, Kt as isDefaultOnlyMember, L as deepEqualExpression, Lt as hasConditional, M as wireNullText, N as wireNumericKind, Nt as zodBaseError, Pt as zodError, Q as enumWithoutWrappedNull, S as integerWirePattern, Sn as ISO_4217_CURRENCY_CODES, T as isPrimitiveUnion, Tt as issueMessageExpression, U as emitOptionsOf, Wt as isComposite, Xt as isPlainObject, Y as discriminatedMembers, Yt as isObjectPrototypeProperty, Z as hasRootSelfReference, Zt as isPrimitive, _ as valueListLiteral, a as unlessEvaluated, c as sanitizeSchema, d as hasParameterSerialization, dn as DEFAULT_ROOT_NAME, dt as findCodeExtensionKeysInSchema, et as itemsSchemaOf, f as parameterReaders, g as notPredicate, gt as isKeywordOnlyMember, h as isBigintFormat, ht as foldAllOfMembers, i as isEvaluatedKeyExpression, it as bigintValueLiteral, j as wireArrayOnce, l as refTarget, m as withoutParameterSerialization, mt as constraintPredicate, nn as isShapelessMember, nt as bigintCall, p as propertyEmitOptions, pt as constraintMessage, q as rootNameOf, qt as isNullTypeMember, r as evaluatedProperties, rn as isStringWireLocation, rt as bigintLiteral, s as typeDeclaration, t as zodWrap, tn as isSchemaObject, tt as bigintBounds, u as withPolymorphicBases, v as hoistNestedRefs, vt as regexLiteral, w as isNullTextRead, x as impliedWireType, zt as hasFixedLength } from "./helper-DpwdwX03.js";
|
|
3
2
|
// src/generator/zod/type.ts
|
|
4
3
|
/** The TypeScript type declared beside a recursive Zod schema. */
|
|
5
4
|
function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
@@ -19,6 +18,11 @@ function type(schema, rootName = DEFAULT_ROOT_NAME) {
|
|
|
19
18
|
function zodWireNumber(kind, inner) {
|
|
20
19
|
return `z.preprocess((val)=>typeof val==='string'&&${kind === "integer" ? integerWirePattern() : numberWirePattern()}.test(val)?Number(val):val,${inner})`;
|
|
21
20
|
}
|
|
21
|
+
/** Two chained checks as one, or `undefined` when neither is there. */
|
|
22
|
+
function joinChecks(first, second) {
|
|
23
|
+
if (first === void 0) return second;
|
|
24
|
+
return second === void 0 ? first : `${first}${second}`;
|
|
25
|
+
}
|
|
22
26
|
/**
|
|
23
27
|
* Generates a Zod schema for number types (number / float32 / float64), with
|
|
24
28
|
* min/max/multipleOf constraints and `x-*-message` vendor extensions translated
|
|
@@ -39,30 +43,28 @@ function number(schema, options) {
|
|
|
39
43
|
const minErrorPart = minErrorArg ? `,${minErrorArg}` : "";
|
|
40
44
|
const exMinErrorArg = exclusiveMinMessage ? zodError(exclusiveMinMessage) : "";
|
|
41
45
|
const exMinErrorPart = exMinErrorArg ? `,${exMinErrorArg}` : "";
|
|
42
|
-
const minimum = (() => {
|
|
46
|
+
const minimum = joinChecks((() => {
|
|
43
47
|
if (schema.minimum !== void 0) {
|
|
44
48
|
if (schema.minimum === 0 && schema.exclusiveMinimum === true) return `.positive(${exMinErrorArg})`;
|
|
45
49
|
if (schema.minimum === 0 && schema.exclusiveMinimum === false) return `.nonnegative(${minErrorArg})`;
|
|
46
50
|
if (schema.exclusiveMinimum === true) return `.gt(${schema.minimum}${exMinErrorPart})`;
|
|
47
51
|
return `.min(${schema.minimum}${minErrorPart})`;
|
|
48
52
|
}
|
|
49
|
-
|
|
50
|
-
})();
|
|
53
|
+
})(), typeof schema.exclusiveMinimum === "number" ? `.gt(${schema.exclusiveMinimum}${exMinErrorPart})` : void 0);
|
|
51
54
|
const maximumMessage = schema["x-maximum-message"];
|
|
52
55
|
const exclusiveMaxMessage = schema["x-exclusiveMaximum-message"];
|
|
53
56
|
const maxErrorArg = maximumMessage ? zodError(maximumMessage) : "";
|
|
54
57
|
const maxErrorPart = maxErrorArg ? `,${maxErrorArg}` : "";
|
|
55
58
|
const exMaxErrorArg = exclusiveMaxMessage ? zodError(exclusiveMaxMessage) : "";
|
|
56
59
|
const exMaxErrorPart = exMaxErrorArg ? `,${exMaxErrorArg}` : "";
|
|
57
|
-
const maximum = (() => {
|
|
60
|
+
const maximum = joinChecks((() => {
|
|
58
61
|
if (schema.maximum !== void 0) {
|
|
59
62
|
if (schema.maximum === 0 && schema.exclusiveMaximum === true) return `.negative(${exMaxErrorArg})`;
|
|
60
63
|
if (schema.maximum === 0 && schema.exclusiveMaximum === false) return `.nonpositive(${maxErrorArg})`;
|
|
61
64
|
if (schema.exclusiveMaximum === true) return `.lt(${schema.maximum}${exMaxErrorPart})`;
|
|
62
65
|
return `.max(${schema.maximum}${maxErrorPart})`;
|
|
63
66
|
}
|
|
64
|
-
|
|
65
|
-
})();
|
|
67
|
+
})(), typeof schema.exclusiveMaximum === "number" ? `.lt(${schema.exclusiveMaximum}${exMaxErrorPart})` : void 0);
|
|
66
68
|
const multipleOfMessage = schema["x-multipleOf-message"];
|
|
67
69
|
const multipleOfErrorArg = multipleOfMessage ? `,${zodError(multipleOfMessage)}` : baseErrorArg ? `,${baseErrorArg}` : "";
|
|
68
70
|
const innerChain = [
|
|
@@ -121,28 +123,26 @@ function integer(node, options) {
|
|
|
121
123
|
const minErrorPart = minErrorArg ? `,${minErrorArg}` : "";
|
|
122
124
|
const exMinErrorArg = exclusiveMinMessage ? zodError(exclusiveMinMessage) : "";
|
|
123
125
|
const exMinErrorPart = exMinErrorArg ? `,${exMinErrorArg}` : "";
|
|
124
|
-
const minimum = (() => {
|
|
125
|
-
if (schema.minimum
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
})();
|
|
126
|
+
const minimum = joinChecks((() => {
|
|
127
|
+
if (typeof schema.minimum !== "number") return void 0;
|
|
128
|
+
if (schema.minimum === 0 && schema.exclusiveMinimum === true) return `.positive(${exMinErrorArg})`;
|
|
129
|
+
if (schema.minimum === 0 && schema.exclusiveMinimum === false) return `.nonnegative(${minErrorArg})`;
|
|
130
|
+
if (schema.exclusiveMinimum === true) return `.gt(${lit(schema.minimum)}${exMinErrorPart})`;
|
|
131
|
+
return `.min(${lit(schema.minimum)}${minErrorPart})`;
|
|
132
|
+
})(), typeof schema.exclusiveMinimum === "number" ? `.gt(${lit(schema.exclusiveMinimum)}${exMinErrorPart})` : void 0);
|
|
132
133
|
const maximumMessage = schema["x-maximum-message"] ?? errorMessage;
|
|
133
134
|
const exclusiveMaxMessage = schema["x-exclusiveMaximum-message"] ?? errorMessage;
|
|
134
135
|
const maxErrorArg = maximumMessage ? zodError(maximumMessage) : "";
|
|
135
136
|
const maxErrorPart = maxErrorArg ? `,${maxErrorArg}` : "";
|
|
136
137
|
const exMaxErrorArg = exclusiveMaxMessage ? zodError(exclusiveMaxMessage) : "";
|
|
137
138
|
const exMaxErrorPart = exMaxErrorArg ? `,${exMaxErrorArg}` : "";
|
|
138
|
-
const maximum = (() => {
|
|
139
|
-
if (schema.maximum
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
})();
|
|
139
|
+
const maximum = joinChecks((() => {
|
|
140
|
+
if (typeof schema.maximum !== "number") return void 0;
|
|
141
|
+
if (schema.maximum === 0 && schema.exclusiveMaximum === true) return `.negative(${exMaxErrorArg})`;
|
|
142
|
+
if (schema.maximum === 0 && schema.exclusiveMaximum === false) return `.nonpositive(${maxErrorArg})`;
|
|
143
|
+
if (schema.exclusiveMaximum === true) return `.lt(${lit(schema.maximum)}${exMaxErrorPart})`;
|
|
144
|
+
return `.max(${lit(schema.maximum)}${maxErrorPart})`;
|
|
145
|
+
})(), typeof schema.exclusiveMaximum === "number" ? `.lt(${lit(schema.exclusiveMaximum)}${exMaxErrorPart})` : void 0);
|
|
146
146
|
const multipleOfMessage = schema["x-multipleOf-message"] ?? errorMessage;
|
|
147
147
|
const multipleOfErrorArg = zodErrorPart(multipleOfMessage);
|
|
148
148
|
const multipleOf = schema.multipleOf !== void 0 ? `.multipleOf(${lit(schema.multipleOf)}${multipleOfErrorArg})` : void 0;
|
|
@@ -187,7 +187,7 @@ function integer(node, options) {
|
|
|
187
187
|
function lit(v, isBigint) {
|
|
188
188
|
if (v === null) return "null";
|
|
189
189
|
if (typeof v === "string") return `'${v.replaceAll("'", "\\'")}'`;
|
|
190
|
-
if (typeof v === "number" && isBigint) return
|
|
190
|
+
if (typeof v === "number" && isBigint) return bigintValueLiteral(v);
|
|
191
191
|
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
192
192
|
return JSON.stringify(v) ?? "null";
|
|
193
193
|
}
|
|
@@ -710,7 +710,7 @@ function node(schema, rootName, isZod, options) {
|
|
|
710
710
|
const value = schema.const;
|
|
711
711
|
const constMessage = schema["x-const-message"] ?? schema["x-error-message"];
|
|
712
712
|
const errorPart = zodErrorPart(constMessage);
|
|
713
|
-
const literal = typeof value === "number" && isInt64(schema) ? `z.literal(${value}
|
|
713
|
+
const literal = typeof value === "number" && isInt64(schema) ? `z.literal(${bigintValueLiteral(value)}${errorPart})` : isPrimitive(value) ? `z.literal(${JSON.stringify(value)}${errorPart})` : `z.custom<${JSON.stringify(value)}>((input) => ${deepEqualExpression(value, "input")}${errorPart})`;
|
|
714
714
|
return zodWrap$1(literalInput([value], literal) ?? literal, schema);
|
|
715
715
|
}
|
|
716
716
|
if (schema.enum) {
|
package/dist/zod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as schemaToZod } from "./zod-
|
|
1
|
+
export { t as schemaToZod } from "./zod-xz1vNbs5.js";
|
package/package.json
CHANGED
package/dist/bigint-CkHij6xv.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// src/helper/bigint.ts
|
|
2
|
-
/** A bigint literal, `5n`, spelled in digits however the number prints. */
|
|
3
|
-
function bigintLiteral(n) {
|
|
4
|
-
return `${BigInt(n)}n`;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* A `BigInt(5)` call, the spelling `format: bigint` has always used. A divisor a number
|
|
8
|
-
* cannot hold exactly is written as a literal, `12345678901234567n`, which keeps every digit.
|
|
9
|
-
*/
|
|
10
|
-
function bigintCall(n) {
|
|
11
|
-
return typeof n === "bigint" ? `${n}n` : `BigInt(${n})`;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* A bigint check takes an integer, but a schema's bound can be fractional: `BigInt(0.5)`
|
|
15
|
-
* throws a `RangeError` and `0.5n` does not parse. A fractional bound is rounded to the
|
|
16
|
-
* integer that admits the same bigints: an inclusive minimum and an exclusive maximum
|
|
17
|
-
* round up, an inclusive maximum and an exclusive minimum round down. A non-finite bound
|
|
18
|
-
* (a YAML `.inf`) is left out; `sanitizeSchema` drops it before the generator anyway.
|
|
19
|
-
*/
|
|
20
|
-
function bigintBound(value, round) {
|
|
21
|
-
return value !== void 0 && Number.isFinite(value) ? Math[round](value) : void 0;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* The positive integer divisor a bigint `multipleOf` check can use. An integer is taken as
|
|
25
|
-
* it is (`BigInt(value)` is exact for any integer a number holds), and a negative one by its
|
|
26
|
-
* absolute value, which has the same multiples. A bigint `x` is a multiple of `p / q` (in
|
|
27
|
-
* lowest terms) exactly when it is a multiple of `p`, so a fraction reduces to its
|
|
28
|
-
* numerator: 2.5 is 5/2 and becomes `5`. The fraction is read from the number's shortest
|
|
29
|
-
* decimal spelling. Zero or a non-finite divisor has no such integer and is left out (a
|
|
30
|
-
* bigint `% 0n` throws). A reduced divisor a number cannot hold exactly stays a bigint.
|
|
31
|
-
*/
|
|
32
|
-
function bigintDivisor(value) {
|
|
33
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value === 0) return void 0;
|
|
34
|
-
const magnitude = Math.abs(value);
|
|
35
|
-
if (Number.isInteger(magnitude)) return magnitude;
|
|
36
|
-
const match = /^(\d+)(?:\.(\d+))?(?:e-(\d+))?$/.exec(String(magnitude));
|
|
37
|
-
if (!match) return void 0;
|
|
38
|
-
const [, whole = "", fraction = "", exponent = "0"] = match;
|
|
39
|
-
const scale = fraction.length + Number(exponent);
|
|
40
|
-
const numerator = BigInt(whole + fraction);
|
|
41
|
-
let [a, b] = [numerator, 10n ** BigInt(scale)];
|
|
42
|
-
while (b !== 0n) [a, b] = [b, a % b];
|
|
43
|
-
const divisor = numerator / a;
|
|
44
|
-
return BigInt(Number(divisor)) === divisor ? Number(divisor) : divisor;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The schema with its bounds and `multipleOf` made integers a bigint check can take: see
|
|
48
|
-
* {@link bigintBound} and {@link bigintDivisor}. A bound or divisor that has no such
|
|
49
|
-
* integer is left out, together with the draft-04 boolean or the message that belongs to it.
|
|
50
|
-
*/
|
|
51
|
-
function bigintBounds(schema) {
|
|
52
|
-
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, "x-multipleOf-message": multipleOfMessage, ...rest } = schema;
|
|
53
|
-
const isExclusiveMin = exclusiveMinimum === true;
|
|
54
|
-
const isExclusiveMax = exclusiveMaximum === true;
|
|
55
|
-
const min = bigintBound(minimum, isExclusiveMin ? "floor" : "ceil");
|
|
56
|
-
const max = bigintBound(maximum, isExclusiveMax ? "ceil" : "floor");
|
|
57
|
-
const exMin = typeof exclusiveMinimum === "number" ? bigintBound(exclusiveMinimum, "floor") : min !== void 0 ? exclusiveMinimum : void 0;
|
|
58
|
-
const exMax = typeof exclusiveMaximum === "number" ? bigintBound(exclusiveMaximum, "ceil") : max !== void 0 ? exclusiveMaximum : void 0;
|
|
59
|
-
const divisor = bigintDivisor(multipleOf);
|
|
60
|
-
return {
|
|
61
|
-
...rest,
|
|
62
|
-
...min !== void 0 && { minimum: min },
|
|
63
|
-
...max !== void 0 && { maximum: max },
|
|
64
|
-
...exMin !== void 0 && { exclusiveMinimum: exMin },
|
|
65
|
-
...exMax !== void 0 && { exclusiveMaximum: exMax },
|
|
66
|
-
...divisor !== void 0 && { multipleOf: divisor },
|
|
67
|
-
...divisor !== void 0 && multipleOfMessage !== void 0 && { "x-multipleOf-message": multipleOfMessage }
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
export { bigintCall as n, bigintLiteral as r, bigintBounds as t };
|