@kevisual/router 0.0.39 → 0.0.41
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/router-browser.d.ts +11 -15
- package/dist/router-browser.js +688 -21
- package/dist/router-simple.d.ts +2 -2
- package/dist/router.d.ts +107 -17
- package/dist/router.js +929 -385
- package/package.json +6 -8
- package/src/result/error.ts +2 -5
- package/src/route.ts +2 -3
- package/src/server/cookie.ts +543 -0
- package/src/server/server.ts +1 -1
package/dist/router-browser.js
CHANGED
|
@@ -56,11 +56,8 @@ class CustomError extends Error {
|
|
|
56
56
|
* @param err
|
|
57
57
|
* @returns
|
|
58
58
|
*/
|
|
59
|
-
static isError(
|
|
60
|
-
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
59
|
+
static isError(error) {
|
|
60
|
+
return error instanceof CustomError || (typeof error === 'object' && error !== null && 'code' in error);
|
|
64
61
|
}
|
|
65
62
|
parse(e) {
|
|
66
63
|
if (e) {
|
|
@@ -579,8 +576,8 @@ class QueryRouter {
|
|
|
579
576
|
setContext(ctx) {
|
|
580
577
|
this.context = ctx;
|
|
581
578
|
}
|
|
582
|
-
getList() {
|
|
583
|
-
return this.routes.map((r) => {
|
|
579
|
+
getList(filter) {
|
|
580
|
+
return this.routes.filter(filter || (() => true)).map((r) => {
|
|
584
581
|
return pick$1(r, pickValue);
|
|
585
582
|
});
|
|
586
583
|
}
|
|
@@ -710,8 +707,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
710
707
|
async run(msg, ctx) {
|
|
711
708
|
const handle = this.handle;
|
|
712
709
|
if (handle) {
|
|
713
|
-
|
|
714
|
-
return handle(result);
|
|
710
|
+
return handle(msg, ctx);
|
|
715
711
|
}
|
|
716
712
|
return super.run(msg, ctx);
|
|
717
713
|
}
|
|
@@ -1867,8 +1863,8 @@ class Doc {
|
|
|
1867
1863
|
|
|
1868
1864
|
const version = {
|
|
1869
1865
|
major: 4,
|
|
1870
|
-
minor:
|
|
1871
|
-
patch:
|
|
1866
|
+
minor: 2,
|
|
1867
|
+
patch: 1,
|
|
1872
1868
|
};
|
|
1873
1869
|
|
|
1874
1870
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
@@ -1938,16 +1934,6 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
|
1938
1934
|
}
|
|
1939
1935
|
return payload;
|
|
1940
1936
|
};
|
|
1941
|
-
// const handleChecksResult = (
|
|
1942
|
-
// checkResult: ParsePayload,
|
|
1943
|
-
// originalResult: ParsePayload,
|
|
1944
|
-
// ctx: ParseContextInternal
|
|
1945
|
-
// ): util.MaybeAsync<ParsePayload> => {
|
|
1946
|
-
// // if the checks mutated the value && there are no issues, re-parse the result
|
|
1947
|
-
// if (checkResult.value !== originalResult.value && !checkResult.issues.length)
|
|
1948
|
-
// return inst._zod.parse(checkResult, ctx);
|
|
1949
|
-
// return originalResult;
|
|
1950
|
-
// };
|
|
1951
1937
|
const handleCanaryResult = (canary, payload, ctx) => {
|
|
1952
1938
|
// abort if the canary is aborted
|
|
1953
1939
|
if (aborted(canary)) {
|
|
@@ -3585,6 +3571,659 @@ function _check(fn, params) {
|
|
|
3585
3571
|
return ch;
|
|
3586
3572
|
}
|
|
3587
3573
|
|
|
3574
|
+
// function initializeContext<T extends schemas.$ZodType>(inputs: JSONSchemaGeneratorParams<T>): ToJSONSchemaContext<T> {
|
|
3575
|
+
// return {
|
|
3576
|
+
// processor: inputs.processor,
|
|
3577
|
+
// metadataRegistry: inputs.metadata ?? globalRegistry,
|
|
3578
|
+
// target: inputs.target ?? "draft-2020-12",
|
|
3579
|
+
// unrepresentable: inputs.unrepresentable ?? "throw",
|
|
3580
|
+
// };
|
|
3581
|
+
// }
|
|
3582
|
+
function initializeContext(params) {
|
|
3583
|
+
// Normalize target: convert old non-hyphenated versions to hyphenated versions
|
|
3584
|
+
let target = params?.target ?? "draft-2020-12";
|
|
3585
|
+
if (target === "draft-4")
|
|
3586
|
+
target = "draft-04";
|
|
3587
|
+
if (target === "draft-7")
|
|
3588
|
+
target = "draft-07";
|
|
3589
|
+
return {
|
|
3590
|
+
processors: params.processors ?? {},
|
|
3591
|
+
metadataRegistry: params?.metadata ?? globalRegistry,
|
|
3592
|
+
target,
|
|
3593
|
+
unrepresentable: params?.unrepresentable ?? "throw",
|
|
3594
|
+
override: params?.override ?? (() => { }),
|
|
3595
|
+
io: params?.io ?? "output",
|
|
3596
|
+
counter: 0,
|
|
3597
|
+
seen: new Map(),
|
|
3598
|
+
cycles: params?.cycles ?? "ref",
|
|
3599
|
+
reused: params?.reused ?? "inline",
|
|
3600
|
+
external: params?.external ?? undefined,
|
|
3601
|
+
};
|
|
3602
|
+
}
|
|
3603
|
+
function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
3604
|
+
var _a;
|
|
3605
|
+
const def = schema._zod.def;
|
|
3606
|
+
// check for schema in seens
|
|
3607
|
+
const seen = ctx.seen.get(schema);
|
|
3608
|
+
if (seen) {
|
|
3609
|
+
seen.count++;
|
|
3610
|
+
// check if cycle
|
|
3611
|
+
const isCycle = _params.schemaPath.includes(schema);
|
|
3612
|
+
if (isCycle) {
|
|
3613
|
+
seen.cycle = _params.path;
|
|
3614
|
+
}
|
|
3615
|
+
return seen.schema;
|
|
3616
|
+
}
|
|
3617
|
+
// initialize
|
|
3618
|
+
const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
|
|
3619
|
+
ctx.seen.set(schema, result);
|
|
3620
|
+
// custom method overrides default behavior
|
|
3621
|
+
const overrideSchema = schema._zod.toJSONSchema?.();
|
|
3622
|
+
if (overrideSchema) {
|
|
3623
|
+
result.schema = overrideSchema;
|
|
3624
|
+
}
|
|
3625
|
+
else {
|
|
3626
|
+
const params = {
|
|
3627
|
+
..._params,
|
|
3628
|
+
schemaPath: [..._params.schemaPath, schema],
|
|
3629
|
+
path: _params.path,
|
|
3630
|
+
};
|
|
3631
|
+
const parent = schema._zod.parent;
|
|
3632
|
+
if (parent) {
|
|
3633
|
+
// schema was cloned from another schema
|
|
3634
|
+
result.ref = parent;
|
|
3635
|
+
process(parent, ctx, params);
|
|
3636
|
+
ctx.seen.get(parent).isParent = true;
|
|
3637
|
+
}
|
|
3638
|
+
else if (schema._zod.processJSONSchema) {
|
|
3639
|
+
schema._zod.processJSONSchema(ctx, result.schema, params);
|
|
3640
|
+
}
|
|
3641
|
+
else {
|
|
3642
|
+
const _json = result.schema;
|
|
3643
|
+
const processor = ctx.processors[def.type];
|
|
3644
|
+
if (!processor) {
|
|
3645
|
+
throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
|
|
3646
|
+
}
|
|
3647
|
+
processor(schema, ctx, _json, params);
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
// metadata
|
|
3651
|
+
const meta = ctx.metadataRegistry.get(schema);
|
|
3652
|
+
if (meta)
|
|
3653
|
+
Object.assign(result.schema, meta);
|
|
3654
|
+
if (ctx.io === "input" && isTransforming(schema)) {
|
|
3655
|
+
// examples/defaults only apply to output type of pipe
|
|
3656
|
+
delete result.schema.examples;
|
|
3657
|
+
delete result.schema.default;
|
|
3658
|
+
}
|
|
3659
|
+
// set prefault as default
|
|
3660
|
+
if (ctx.io === "input" && result.schema._prefault)
|
|
3661
|
+
(_a = result.schema).default ?? (_a.default = result.schema._prefault);
|
|
3662
|
+
delete result.schema._prefault;
|
|
3663
|
+
// pulling fresh from ctx.seen in case it was overwritten
|
|
3664
|
+
const _result = ctx.seen.get(schema);
|
|
3665
|
+
return _result.schema;
|
|
3666
|
+
}
|
|
3667
|
+
function extractDefs(ctx, schema
|
|
3668
|
+
// params: EmitParams
|
|
3669
|
+
) {
|
|
3670
|
+
// iterate over seen map;
|
|
3671
|
+
const root = ctx.seen.get(schema);
|
|
3672
|
+
if (!root)
|
|
3673
|
+
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
3674
|
+
// returns a ref to the schema
|
|
3675
|
+
// defId will be empty if the ref points to an external schema (or #)
|
|
3676
|
+
const makeURI = (entry) => {
|
|
3677
|
+
// comparing the seen objects because sometimes
|
|
3678
|
+
// multiple schemas map to the same seen object.
|
|
3679
|
+
// e.g. lazy
|
|
3680
|
+
// external is configured
|
|
3681
|
+
const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
3682
|
+
if (ctx.external) {
|
|
3683
|
+
const externalId = ctx.external.registry.get(entry[0])?.id; // ?? "__shared";// `__schema${ctx.counter++}`;
|
|
3684
|
+
// check if schema is in the external registry
|
|
3685
|
+
const uriGenerator = ctx.external.uri ?? ((id) => id);
|
|
3686
|
+
if (externalId) {
|
|
3687
|
+
return { ref: uriGenerator(externalId) };
|
|
3688
|
+
}
|
|
3689
|
+
// otherwise, add to __shared
|
|
3690
|
+
const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
|
|
3691
|
+
entry[1].defId = id; // set defId so it will be reused if needed
|
|
3692
|
+
return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
|
|
3693
|
+
}
|
|
3694
|
+
if (entry[1] === root) {
|
|
3695
|
+
return { ref: "#" };
|
|
3696
|
+
}
|
|
3697
|
+
// self-contained schema
|
|
3698
|
+
const uriPrefix = `#`;
|
|
3699
|
+
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
|
|
3700
|
+
const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
|
|
3701
|
+
return { defId, ref: defUriPrefix + defId };
|
|
3702
|
+
};
|
|
3703
|
+
// stored cached version in `def` property
|
|
3704
|
+
// remove all properties, set $ref
|
|
3705
|
+
const extractToDef = (entry) => {
|
|
3706
|
+
// if the schema is already a reference, do not extract it
|
|
3707
|
+
if (entry[1].schema.$ref) {
|
|
3708
|
+
return;
|
|
3709
|
+
}
|
|
3710
|
+
const seen = entry[1];
|
|
3711
|
+
const { ref, defId } = makeURI(entry);
|
|
3712
|
+
seen.def = { ...seen.schema };
|
|
3713
|
+
// defId won't be set if the schema is a reference to an external schema
|
|
3714
|
+
// or if the schema is the root schema
|
|
3715
|
+
if (defId)
|
|
3716
|
+
seen.defId = defId;
|
|
3717
|
+
// wipe away all properties except $ref
|
|
3718
|
+
const schema = seen.schema;
|
|
3719
|
+
for (const key in schema) {
|
|
3720
|
+
delete schema[key];
|
|
3721
|
+
}
|
|
3722
|
+
schema.$ref = ref;
|
|
3723
|
+
};
|
|
3724
|
+
// throw on cycles
|
|
3725
|
+
// break cycles
|
|
3726
|
+
if (ctx.cycles === "throw") {
|
|
3727
|
+
for (const entry of ctx.seen.entries()) {
|
|
3728
|
+
const seen = entry[1];
|
|
3729
|
+
if (seen.cycle) {
|
|
3730
|
+
throw new Error("Cycle detected: " +
|
|
3731
|
+
`#/${seen.cycle?.join("/")}/<root>` +
|
|
3732
|
+
'\n\nSet the `cycles` parameter to `"ref"` to resolve cyclical schemas with defs.');
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
// extract schemas into $defs
|
|
3737
|
+
for (const entry of ctx.seen.entries()) {
|
|
3738
|
+
const seen = entry[1];
|
|
3739
|
+
// convert root schema to # $ref
|
|
3740
|
+
if (schema === entry[0]) {
|
|
3741
|
+
extractToDef(entry); // this has special handling for the root schema
|
|
3742
|
+
continue;
|
|
3743
|
+
}
|
|
3744
|
+
// extract schemas that are in the external registry
|
|
3745
|
+
if (ctx.external) {
|
|
3746
|
+
const ext = ctx.external.registry.get(entry[0])?.id;
|
|
3747
|
+
if (schema !== entry[0] && ext) {
|
|
3748
|
+
extractToDef(entry);
|
|
3749
|
+
continue;
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
// extract schemas with `id` meta
|
|
3753
|
+
const id = ctx.metadataRegistry.get(entry[0])?.id;
|
|
3754
|
+
if (id) {
|
|
3755
|
+
extractToDef(entry);
|
|
3756
|
+
continue;
|
|
3757
|
+
}
|
|
3758
|
+
// break cycles
|
|
3759
|
+
if (seen.cycle) {
|
|
3760
|
+
// any
|
|
3761
|
+
extractToDef(entry);
|
|
3762
|
+
continue;
|
|
3763
|
+
}
|
|
3764
|
+
// extract reused schemas
|
|
3765
|
+
if (seen.count > 1) {
|
|
3766
|
+
if (ctx.reused === "ref") {
|
|
3767
|
+
extractToDef(entry);
|
|
3768
|
+
// biome-ignore lint:
|
|
3769
|
+
continue;
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
function finalize(ctx, schema) {
|
|
3775
|
+
//
|
|
3776
|
+
// iterate over seen map;
|
|
3777
|
+
const root = ctx.seen.get(schema);
|
|
3778
|
+
if (!root)
|
|
3779
|
+
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
3780
|
+
// flatten _refs
|
|
3781
|
+
const flattenRef = (zodSchema) => {
|
|
3782
|
+
const seen = ctx.seen.get(zodSchema);
|
|
3783
|
+
const schema = seen.def ?? seen.schema;
|
|
3784
|
+
const _cached = { ...schema };
|
|
3785
|
+
// already seen
|
|
3786
|
+
if (seen.ref === null) {
|
|
3787
|
+
return;
|
|
3788
|
+
}
|
|
3789
|
+
// flatten ref if defined
|
|
3790
|
+
const ref = seen.ref;
|
|
3791
|
+
seen.ref = null; // prevent recursion
|
|
3792
|
+
if (ref) {
|
|
3793
|
+
flattenRef(ref);
|
|
3794
|
+
// merge referenced schema into current
|
|
3795
|
+
const refSchema = ctx.seen.get(ref).schema;
|
|
3796
|
+
if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
|
|
3797
|
+
schema.allOf = schema.allOf ?? [];
|
|
3798
|
+
schema.allOf.push(refSchema);
|
|
3799
|
+
}
|
|
3800
|
+
else {
|
|
3801
|
+
Object.assign(schema, refSchema);
|
|
3802
|
+
Object.assign(schema, _cached); // prevent overwriting any fields in the original schema
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
// execute overrides
|
|
3806
|
+
if (!seen.isParent)
|
|
3807
|
+
ctx.override({
|
|
3808
|
+
zodSchema: zodSchema,
|
|
3809
|
+
jsonSchema: schema,
|
|
3810
|
+
path: seen.path ?? [],
|
|
3811
|
+
});
|
|
3812
|
+
};
|
|
3813
|
+
for (const entry of [...ctx.seen.entries()].reverse()) {
|
|
3814
|
+
flattenRef(entry[0]);
|
|
3815
|
+
}
|
|
3816
|
+
const result = {};
|
|
3817
|
+
if (ctx.target === "draft-2020-12") {
|
|
3818
|
+
result.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
3819
|
+
}
|
|
3820
|
+
else if (ctx.target === "draft-07") {
|
|
3821
|
+
result.$schema = "http://json-schema.org/draft-07/schema#";
|
|
3822
|
+
}
|
|
3823
|
+
else if (ctx.target === "draft-04") {
|
|
3824
|
+
result.$schema = "http://json-schema.org/draft-04/schema#";
|
|
3825
|
+
}
|
|
3826
|
+
else if (ctx.target === "openapi-3.0") ;
|
|
3827
|
+
else ;
|
|
3828
|
+
if (ctx.external?.uri) {
|
|
3829
|
+
const id = ctx.external.registry.get(schema)?.id;
|
|
3830
|
+
if (!id)
|
|
3831
|
+
throw new Error("Schema is missing an `id` property");
|
|
3832
|
+
result.$id = ctx.external.uri(id);
|
|
3833
|
+
}
|
|
3834
|
+
Object.assign(result, root.def ?? root.schema);
|
|
3835
|
+
// build defs object
|
|
3836
|
+
const defs = ctx.external?.defs ?? {};
|
|
3837
|
+
for (const entry of ctx.seen.entries()) {
|
|
3838
|
+
const seen = entry[1];
|
|
3839
|
+
if (seen.def && seen.defId) {
|
|
3840
|
+
defs[seen.defId] = seen.def;
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3843
|
+
// set definitions in result
|
|
3844
|
+
if (ctx.external) ;
|
|
3845
|
+
else {
|
|
3846
|
+
if (Object.keys(defs).length > 0) {
|
|
3847
|
+
if (ctx.target === "draft-2020-12") {
|
|
3848
|
+
result.$defs = defs;
|
|
3849
|
+
}
|
|
3850
|
+
else {
|
|
3851
|
+
result.definitions = defs;
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
try {
|
|
3856
|
+
// this "finalizes" this schema and ensures all cycles are removed
|
|
3857
|
+
// each call to finalize() is functionally independent
|
|
3858
|
+
// though the seen map is shared
|
|
3859
|
+
const finalized = JSON.parse(JSON.stringify(result));
|
|
3860
|
+
Object.defineProperty(finalized, "~standard", {
|
|
3861
|
+
value: {
|
|
3862
|
+
...schema["~standard"],
|
|
3863
|
+
jsonSchema: {
|
|
3864
|
+
input: createStandardJSONSchemaMethod(schema, "input"),
|
|
3865
|
+
output: createStandardJSONSchemaMethod(schema, "output"),
|
|
3866
|
+
},
|
|
3867
|
+
},
|
|
3868
|
+
enumerable: false,
|
|
3869
|
+
writable: false,
|
|
3870
|
+
});
|
|
3871
|
+
return finalized;
|
|
3872
|
+
}
|
|
3873
|
+
catch (_err) {
|
|
3874
|
+
throw new Error("Error converting schema to JSON.");
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
function isTransforming(_schema, _ctx) {
|
|
3878
|
+
const ctx = _ctx ?? { seen: new Set() };
|
|
3879
|
+
if (ctx.seen.has(_schema))
|
|
3880
|
+
return false;
|
|
3881
|
+
ctx.seen.add(_schema);
|
|
3882
|
+
const def = _schema._zod.def;
|
|
3883
|
+
if (def.type === "transform")
|
|
3884
|
+
return true;
|
|
3885
|
+
if (def.type === "array")
|
|
3886
|
+
return isTransforming(def.element, ctx);
|
|
3887
|
+
if (def.type === "set")
|
|
3888
|
+
return isTransforming(def.valueType, ctx);
|
|
3889
|
+
if (def.type === "lazy")
|
|
3890
|
+
return isTransforming(def.getter(), ctx);
|
|
3891
|
+
if (def.type === "promise" ||
|
|
3892
|
+
def.type === "optional" ||
|
|
3893
|
+
def.type === "nonoptional" ||
|
|
3894
|
+
def.type === "nullable" ||
|
|
3895
|
+
def.type === "readonly" ||
|
|
3896
|
+
def.type === "default" ||
|
|
3897
|
+
def.type === "prefault") {
|
|
3898
|
+
return isTransforming(def.innerType, ctx);
|
|
3899
|
+
}
|
|
3900
|
+
if (def.type === "intersection") {
|
|
3901
|
+
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
3902
|
+
}
|
|
3903
|
+
if (def.type === "record" || def.type === "map") {
|
|
3904
|
+
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
3905
|
+
}
|
|
3906
|
+
if (def.type === "pipe") {
|
|
3907
|
+
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
3908
|
+
}
|
|
3909
|
+
if (def.type === "object") {
|
|
3910
|
+
for (const key in def.shape) {
|
|
3911
|
+
if (isTransforming(def.shape[key], ctx))
|
|
3912
|
+
return true;
|
|
3913
|
+
}
|
|
3914
|
+
return false;
|
|
3915
|
+
}
|
|
3916
|
+
if (def.type === "union") {
|
|
3917
|
+
for (const option of def.options) {
|
|
3918
|
+
if (isTransforming(option, ctx))
|
|
3919
|
+
return true;
|
|
3920
|
+
}
|
|
3921
|
+
return false;
|
|
3922
|
+
}
|
|
3923
|
+
if (def.type === "tuple") {
|
|
3924
|
+
for (const item of def.items) {
|
|
3925
|
+
if (isTransforming(item, ctx))
|
|
3926
|
+
return true;
|
|
3927
|
+
}
|
|
3928
|
+
if (def.rest && isTransforming(def.rest, ctx))
|
|
3929
|
+
return true;
|
|
3930
|
+
return false;
|
|
3931
|
+
}
|
|
3932
|
+
return false;
|
|
3933
|
+
}
|
|
3934
|
+
/**
|
|
3935
|
+
* Creates a toJSONSchema method for a schema instance.
|
|
3936
|
+
* This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
|
|
3937
|
+
*/
|
|
3938
|
+
const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
3939
|
+
const ctx = initializeContext({ ...params, processors });
|
|
3940
|
+
process(schema, ctx);
|
|
3941
|
+
extractDefs(ctx, schema);
|
|
3942
|
+
return finalize(ctx, schema);
|
|
3943
|
+
};
|
|
3944
|
+
const createStandardJSONSchemaMethod = (schema, io) => (params) => {
|
|
3945
|
+
const { libraryOptions, target } = params ?? {};
|
|
3946
|
+
const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors: {} });
|
|
3947
|
+
process(schema, ctx);
|
|
3948
|
+
extractDefs(ctx, schema);
|
|
3949
|
+
return finalize(ctx, schema);
|
|
3950
|
+
};
|
|
3951
|
+
|
|
3952
|
+
const formatMap = {
|
|
3953
|
+
guid: "uuid",
|
|
3954
|
+
url: "uri",
|
|
3955
|
+
datetime: "date-time",
|
|
3956
|
+
json_string: "json-string",
|
|
3957
|
+
regex: "", // do not set
|
|
3958
|
+
};
|
|
3959
|
+
// ==================== SIMPLE TYPE PROCESSORS ====================
|
|
3960
|
+
const stringProcessor = (schema, ctx, _json, _params) => {
|
|
3961
|
+
const json = _json;
|
|
3962
|
+
json.type = "string";
|
|
3963
|
+
const { minimum, maximum, format, patterns, contentEncoding } = schema._zod
|
|
3964
|
+
.bag;
|
|
3965
|
+
if (typeof minimum === "number")
|
|
3966
|
+
json.minLength = minimum;
|
|
3967
|
+
if (typeof maximum === "number")
|
|
3968
|
+
json.maxLength = maximum;
|
|
3969
|
+
// custom pattern overrides format
|
|
3970
|
+
if (format) {
|
|
3971
|
+
json.format = formatMap[format] ?? format;
|
|
3972
|
+
if (json.format === "")
|
|
3973
|
+
delete json.format; // empty format is not valid
|
|
3974
|
+
}
|
|
3975
|
+
if (contentEncoding)
|
|
3976
|
+
json.contentEncoding = contentEncoding;
|
|
3977
|
+
if (patterns && patterns.size > 0) {
|
|
3978
|
+
const regexes = [...patterns];
|
|
3979
|
+
if (regexes.length === 1)
|
|
3980
|
+
json.pattern = regexes[0].source;
|
|
3981
|
+
else if (regexes.length > 1) {
|
|
3982
|
+
json.allOf = [
|
|
3983
|
+
...regexes.map((regex) => ({
|
|
3984
|
+
...(ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0"
|
|
3985
|
+
? { type: "string" }
|
|
3986
|
+
: {}),
|
|
3987
|
+
pattern: regex.source,
|
|
3988
|
+
})),
|
|
3989
|
+
];
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
};
|
|
3993
|
+
const numberProcessor = (schema, ctx, _json, _params) => {
|
|
3994
|
+
const json = _json;
|
|
3995
|
+
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
|
|
3996
|
+
if (typeof format === "string" && format.includes("int"))
|
|
3997
|
+
json.type = "integer";
|
|
3998
|
+
else
|
|
3999
|
+
json.type = "number";
|
|
4000
|
+
if (typeof exclusiveMinimum === "number") {
|
|
4001
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
4002
|
+
json.minimum = exclusiveMinimum;
|
|
4003
|
+
json.exclusiveMinimum = true;
|
|
4004
|
+
}
|
|
4005
|
+
else {
|
|
4006
|
+
json.exclusiveMinimum = exclusiveMinimum;
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
if (typeof minimum === "number") {
|
|
4010
|
+
json.minimum = minimum;
|
|
4011
|
+
if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") {
|
|
4012
|
+
if (exclusiveMinimum >= minimum)
|
|
4013
|
+
delete json.minimum;
|
|
4014
|
+
else
|
|
4015
|
+
delete json.exclusiveMinimum;
|
|
4016
|
+
}
|
|
4017
|
+
}
|
|
4018
|
+
if (typeof exclusiveMaximum === "number") {
|
|
4019
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
4020
|
+
json.maximum = exclusiveMaximum;
|
|
4021
|
+
json.exclusiveMaximum = true;
|
|
4022
|
+
}
|
|
4023
|
+
else {
|
|
4024
|
+
json.exclusiveMaximum = exclusiveMaximum;
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
if (typeof maximum === "number") {
|
|
4028
|
+
json.maximum = maximum;
|
|
4029
|
+
if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") {
|
|
4030
|
+
if (exclusiveMaximum <= maximum)
|
|
4031
|
+
delete json.maximum;
|
|
4032
|
+
else
|
|
4033
|
+
delete json.exclusiveMaximum;
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
if (typeof multipleOf === "number")
|
|
4037
|
+
json.multipleOf = multipleOf;
|
|
4038
|
+
};
|
|
4039
|
+
const booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
4040
|
+
json.type = "boolean";
|
|
4041
|
+
};
|
|
4042
|
+
const neverProcessor = (_schema, _ctx, json, _params) => {
|
|
4043
|
+
json.not = {};
|
|
4044
|
+
};
|
|
4045
|
+
const anyProcessor = (_schema, _ctx, _json, _params) => {
|
|
4046
|
+
// empty schema accepts anything
|
|
4047
|
+
};
|
|
4048
|
+
const unknownProcessor = (_schema, _ctx, _json, _params) => {
|
|
4049
|
+
// empty schema accepts anything
|
|
4050
|
+
};
|
|
4051
|
+
const enumProcessor = (schema, _ctx, json, _params) => {
|
|
4052
|
+
const def = schema._zod.def;
|
|
4053
|
+
const values = getEnumValues(def.entries);
|
|
4054
|
+
// Number enums can have both string and number values
|
|
4055
|
+
if (values.every((v) => typeof v === "number"))
|
|
4056
|
+
json.type = "number";
|
|
4057
|
+
if (values.every((v) => typeof v === "string"))
|
|
4058
|
+
json.type = "string";
|
|
4059
|
+
json.enum = values;
|
|
4060
|
+
};
|
|
4061
|
+
const customProcessor = (_schema, ctx, _json, _params) => {
|
|
4062
|
+
if (ctx.unrepresentable === "throw") {
|
|
4063
|
+
throw new Error("Custom types cannot be represented in JSON Schema");
|
|
4064
|
+
}
|
|
4065
|
+
};
|
|
4066
|
+
const transformProcessor = (_schema, ctx, _json, _params) => {
|
|
4067
|
+
if (ctx.unrepresentable === "throw") {
|
|
4068
|
+
throw new Error("Transforms cannot be represented in JSON Schema");
|
|
4069
|
+
}
|
|
4070
|
+
};
|
|
4071
|
+
// ==================== COMPOSITE TYPE PROCESSORS ====================
|
|
4072
|
+
const arrayProcessor = (schema, ctx, _json, params) => {
|
|
4073
|
+
const json = _json;
|
|
4074
|
+
const def = schema._zod.def;
|
|
4075
|
+
const { minimum, maximum } = schema._zod.bag;
|
|
4076
|
+
if (typeof minimum === "number")
|
|
4077
|
+
json.minItems = minimum;
|
|
4078
|
+
if (typeof maximum === "number")
|
|
4079
|
+
json.maxItems = maximum;
|
|
4080
|
+
json.type = "array";
|
|
4081
|
+
json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
|
|
4082
|
+
};
|
|
4083
|
+
const objectProcessor = (schema, ctx, _json, params) => {
|
|
4084
|
+
const json = _json;
|
|
4085
|
+
const def = schema._zod.def;
|
|
4086
|
+
json.type = "object";
|
|
4087
|
+
json.properties = {};
|
|
4088
|
+
const shape = def.shape;
|
|
4089
|
+
for (const key in shape) {
|
|
4090
|
+
json.properties[key] = process(shape[key], ctx, {
|
|
4091
|
+
...params,
|
|
4092
|
+
path: [...params.path, "properties", key],
|
|
4093
|
+
});
|
|
4094
|
+
}
|
|
4095
|
+
// required keys
|
|
4096
|
+
const allKeys = new Set(Object.keys(shape));
|
|
4097
|
+
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
4098
|
+
const v = def.shape[key]._zod;
|
|
4099
|
+
if (ctx.io === "input") {
|
|
4100
|
+
return v.optin === undefined;
|
|
4101
|
+
}
|
|
4102
|
+
else {
|
|
4103
|
+
return v.optout === undefined;
|
|
4104
|
+
}
|
|
4105
|
+
}));
|
|
4106
|
+
if (requiredKeys.size > 0) {
|
|
4107
|
+
json.required = Array.from(requiredKeys);
|
|
4108
|
+
}
|
|
4109
|
+
// catchall
|
|
4110
|
+
if (def.catchall?._zod.def.type === "never") {
|
|
4111
|
+
// strict
|
|
4112
|
+
json.additionalProperties = false;
|
|
4113
|
+
}
|
|
4114
|
+
else if (!def.catchall) {
|
|
4115
|
+
// regular
|
|
4116
|
+
if (ctx.io === "output")
|
|
4117
|
+
json.additionalProperties = false;
|
|
4118
|
+
}
|
|
4119
|
+
else if (def.catchall) {
|
|
4120
|
+
json.additionalProperties = process(def.catchall, ctx, {
|
|
4121
|
+
...params,
|
|
4122
|
+
path: [...params.path, "additionalProperties"],
|
|
4123
|
+
});
|
|
4124
|
+
}
|
|
4125
|
+
};
|
|
4126
|
+
const unionProcessor = (schema, ctx, json, params) => {
|
|
4127
|
+
const def = schema._zod.def;
|
|
4128
|
+
// Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
|
|
4129
|
+
// This includes both z.xor() and discriminated unions
|
|
4130
|
+
const isExclusive = def.inclusive === false;
|
|
4131
|
+
const options = def.options.map((x, i) => process(x, ctx, {
|
|
4132
|
+
...params,
|
|
4133
|
+
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
|
|
4134
|
+
}));
|
|
4135
|
+
if (isExclusive) {
|
|
4136
|
+
json.oneOf = options;
|
|
4137
|
+
}
|
|
4138
|
+
else {
|
|
4139
|
+
json.anyOf = options;
|
|
4140
|
+
}
|
|
4141
|
+
};
|
|
4142
|
+
const intersectionProcessor = (schema, ctx, json, params) => {
|
|
4143
|
+
const def = schema._zod.def;
|
|
4144
|
+
const a = process(def.left, ctx, {
|
|
4145
|
+
...params,
|
|
4146
|
+
path: [...params.path, "allOf", 0],
|
|
4147
|
+
});
|
|
4148
|
+
const b = process(def.right, ctx, {
|
|
4149
|
+
...params,
|
|
4150
|
+
path: [...params.path, "allOf", 1],
|
|
4151
|
+
});
|
|
4152
|
+
const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
|
|
4153
|
+
const allOf = [
|
|
4154
|
+
...(isSimpleIntersection(a) ? a.allOf : [a]),
|
|
4155
|
+
...(isSimpleIntersection(b) ? b.allOf : [b]),
|
|
4156
|
+
];
|
|
4157
|
+
json.allOf = allOf;
|
|
4158
|
+
};
|
|
4159
|
+
const nullableProcessor = (schema, ctx, json, params) => {
|
|
4160
|
+
const def = schema._zod.def;
|
|
4161
|
+
const inner = process(def.innerType, ctx, params);
|
|
4162
|
+
const seen = ctx.seen.get(schema);
|
|
4163
|
+
if (ctx.target === "openapi-3.0") {
|
|
4164
|
+
seen.ref = def.innerType;
|
|
4165
|
+
json.nullable = true;
|
|
4166
|
+
}
|
|
4167
|
+
else {
|
|
4168
|
+
json.anyOf = [inner, { type: "null" }];
|
|
4169
|
+
}
|
|
4170
|
+
};
|
|
4171
|
+
const nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
4172
|
+
const def = schema._zod.def;
|
|
4173
|
+
process(def.innerType, ctx, params);
|
|
4174
|
+
const seen = ctx.seen.get(schema);
|
|
4175
|
+
seen.ref = def.innerType;
|
|
4176
|
+
};
|
|
4177
|
+
const defaultProcessor = (schema, ctx, json, params) => {
|
|
4178
|
+
const def = schema._zod.def;
|
|
4179
|
+
process(def.innerType, ctx, params);
|
|
4180
|
+
const seen = ctx.seen.get(schema);
|
|
4181
|
+
seen.ref = def.innerType;
|
|
4182
|
+
json.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
4183
|
+
};
|
|
4184
|
+
const prefaultProcessor = (schema, ctx, json, params) => {
|
|
4185
|
+
const def = schema._zod.def;
|
|
4186
|
+
process(def.innerType, ctx, params);
|
|
4187
|
+
const seen = ctx.seen.get(schema);
|
|
4188
|
+
seen.ref = def.innerType;
|
|
4189
|
+
if (ctx.io === "input")
|
|
4190
|
+
json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
|
|
4191
|
+
};
|
|
4192
|
+
const catchProcessor = (schema, ctx, json, params) => {
|
|
4193
|
+
const def = schema._zod.def;
|
|
4194
|
+
process(def.innerType, ctx, params);
|
|
4195
|
+
const seen = ctx.seen.get(schema);
|
|
4196
|
+
seen.ref = def.innerType;
|
|
4197
|
+
let catchValue;
|
|
4198
|
+
try {
|
|
4199
|
+
catchValue = def.catchValue(undefined);
|
|
4200
|
+
}
|
|
4201
|
+
catch {
|
|
4202
|
+
throw new Error("Dynamic catch values are not supported in JSON Schema");
|
|
4203
|
+
}
|
|
4204
|
+
json.default = catchValue;
|
|
4205
|
+
};
|
|
4206
|
+
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
4207
|
+
const def = schema._zod.def;
|
|
4208
|
+
const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
|
|
4209
|
+
process(innerType, ctx, params);
|
|
4210
|
+
const seen = ctx.seen.get(schema);
|
|
4211
|
+
seen.ref = innerType;
|
|
4212
|
+
};
|
|
4213
|
+
const readonlyProcessor = (schema, ctx, json, params) => {
|
|
4214
|
+
const def = schema._zod.def;
|
|
4215
|
+
process(def.innerType, ctx, params);
|
|
4216
|
+
const seen = ctx.seen.get(schema);
|
|
4217
|
+
seen.ref = def.innerType;
|
|
4218
|
+
json.readOnly = true;
|
|
4219
|
+
};
|
|
4220
|
+
const optionalProcessor = (schema, ctx, _json, params) => {
|
|
4221
|
+
const def = schema._zod.def;
|
|
4222
|
+
process(def.innerType, ctx, params);
|
|
4223
|
+
const seen = ctx.seen.get(schema);
|
|
4224
|
+
seen.ref = def.innerType;
|
|
4225
|
+
};
|
|
4226
|
+
|
|
3588
4227
|
const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
|
|
3589
4228
|
$ZodISODateTime.init(inst, def);
|
|
3590
4229
|
ZodStringFormat.init(inst, def);
|
|
@@ -3676,6 +4315,13 @@ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
|
3676
4315
|
|
|
3677
4316
|
const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
3678
4317
|
$ZodType.init(inst, def);
|
|
4318
|
+
Object.assign(inst["~standard"], {
|
|
4319
|
+
jsonSchema: {
|
|
4320
|
+
input: createStandardJSONSchemaMethod(inst, "input"),
|
|
4321
|
+
output: createStandardJSONSchemaMethod(inst, "output"),
|
|
4322
|
+
},
|
|
4323
|
+
});
|
|
4324
|
+
inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
|
|
3679
4325
|
inst.def = def;
|
|
3680
4326
|
inst.type = def.type;
|
|
3681
4327
|
Object.defineProperty(inst, "_def", { value: def });
|
|
@@ -3757,6 +4403,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
|
3757
4403
|
const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
|
|
3758
4404
|
$ZodString.init(inst, def);
|
|
3759
4405
|
ZodType.init(inst, def);
|
|
4406
|
+
inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
|
|
3760
4407
|
const bag = inst._zod.bag;
|
|
3761
4408
|
inst.format = bag.format ?? null;
|
|
3762
4409
|
inst.minLength = bag.minimum ?? null;
|
|
@@ -3914,6 +4561,7 @@ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
|
|
|
3914
4561
|
const ZodNumber = /*@__PURE__*/ $constructor("ZodNumber", (inst, def) => {
|
|
3915
4562
|
$ZodNumber.init(inst, def);
|
|
3916
4563
|
ZodType.init(inst, def);
|
|
4564
|
+
inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json);
|
|
3917
4565
|
inst.gt = (value, params) => inst.check(_gt(value, params));
|
|
3918
4566
|
inst.gte = (value, params) => inst.check(_gte(value, params));
|
|
3919
4567
|
inst.min = (value, params) => inst.check(_gte(value, params));
|
|
@@ -3952,6 +4600,7 @@ function int(params) {
|
|
|
3952
4600
|
const ZodBoolean = /*@__PURE__*/ $constructor("ZodBoolean", (inst, def) => {
|
|
3953
4601
|
$ZodBoolean.init(inst, def);
|
|
3954
4602
|
ZodType.init(inst, def);
|
|
4603
|
+
inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json);
|
|
3955
4604
|
});
|
|
3956
4605
|
function boolean(params) {
|
|
3957
4606
|
return _boolean(ZodBoolean, params);
|
|
@@ -3959,6 +4608,7 @@ function boolean(params) {
|
|
|
3959
4608
|
const ZodAny = /*@__PURE__*/ $constructor("ZodAny", (inst, def) => {
|
|
3960
4609
|
$ZodAny.init(inst, def);
|
|
3961
4610
|
ZodType.init(inst, def);
|
|
4611
|
+
inst._zod.processJSONSchema = (ctx, json, params) => anyProcessor();
|
|
3962
4612
|
});
|
|
3963
4613
|
function any() {
|
|
3964
4614
|
return _any(ZodAny);
|
|
@@ -3966,6 +4616,7 @@ function any() {
|
|
|
3966
4616
|
const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
|
|
3967
4617
|
$ZodUnknown.init(inst, def);
|
|
3968
4618
|
ZodType.init(inst, def);
|
|
4619
|
+
inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
|
|
3969
4620
|
});
|
|
3970
4621
|
function unknown() {
|
|
3971
4622
|
return _unknown(ZodUnknown);
|
|
@@ -3973,6 +4624,7 @@ function unknown() {
|
|
|
3973
4624
|
const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
|
|
3974
4625
|
$ZodNever.init(inst, def);
|
|
3975
4626
|
ZodType.init(inst, def);
|
|
4627
|
+
inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
|
|
3976
4628
|
});
|
|
3977
4629
|
function never(params) {
|
|
3978
4630
|
return _never(ZodNever, params);
|
|
@@ -3980,6 +4632,7 @@ function never(params) {
|
|
|
3980
4632
|
const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
|
|
3981
4633
|
$ZodArray.init(inst, def);
|
|
3982
4634
|
ZodType.init(inst, def);
|
|
4635
|
+
inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
|
|
3983
4636
|
inst.element = def.element;
|
|
3984
4637
|
inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
|
|
3985
4638
|
inst.nonempty = (params) => inst.check(_minLength(1, params));
|
|
@@ -3993,6 +4646,7 @@ function array(element, params) {
|
|
|
3993
4646
|
const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
|
|
3994
4647
|
$ZodObjectJIT.init(inst, def);
|
|
3995
4648
|
ZodType.init(inst, def);
|
|
4649
|
+
inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
|
|
3996
4650
|
defineLazy(inst, "shape", () => {
|
|
3997
4651
|
return def.shape;
|
|
3998
4652
|
});
|
|
@@ -4025,6 +4679,7 @@ function object(shape, params) {
|
|
|
4025
4679
|
const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
|
|
4026
4680
|
$ZodUnion.init(inst, def);
|
|
4027
4681
|
ZodType.init(inst, def);
|
|
4682
|
+
inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
|
|
4028
4683
|
inst.options = def.options;
|
|
4029
4684
|
});
|
|
4030
4685
|
function union(options, params) {
|
|
@@ -4037,6 +4692,7 @@ function union(options, params) {
|
|
|
4037
4692
|
const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
|
|
4038
4693
|
$ZodIntersection.init(inst, def);
|
|
4039
4694
|
ZodType.init(inst, def);
|
|
4695
|
+
inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
|
|
4040
4696
|
});
|
|
4041
4697
|
function intersection(left, right) {
|
|
4042
4698
|
return new ZodIntersection({
|
|
@@ -4048,6 +4704,7 @@ function intersection(left, right) {
|
|
|
4048
4704
|
const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
|
|
4049
4705
|
$ZodEnum.init(inst, def);
|
|
4050
4706
|
ZodType.init(inst, def);
|
|
4707
|
+
inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
|
|
4051
4708
|
inst.enum = def.entries;
|
|
4052
4709
|
inst.options = Object.values(def.entries);
|
|
4053
4710
|
const keys = new Set(Object.keys(def.entries));
|
|
@@ -4095,6 +4752,7 @@ function _enum(values, params) {
|
|
|
4095
4752
|
const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
|
|
4096
4753
|
$ZodTransform.init(inst, def);
|
|
4097
4754
|
ZodType.init(inst, def);
|
|
4755
|
+
inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
|
|
4098
4756
|
inst._zod.parse = (payload, _ctx) => {
|
|
4099
4757
|
if (_ctx.direction === "backward") {
|
|
4100
4758
|
throw new $ZodEncodeError(inst.constructor.name);
|
|
@@ -4135,6 +4793,7 @@ function transform(fn) {
|
|
|
4135
4793
|
const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
|
|
4136
4794
|
$ZodOptional.init(inst, def);
|
|
4137
4795
|
ZodType.init(inst, def);
|
|
4796
|
+
inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
|
|
4138
4797
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
4139
4798
|
});
|
|
4140
4799
|
function optional(innerType) {
|
|
@@ -4146,6 +4805,7 @@ function optional(innerType) {
|
|
|
4146
4805
|
const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
|
|
4147
4806
|
$ZodNullable.init(inst, def);
|
|
4148
4807
|
ZodType.init(inst, def);
|
|
4808
|
+
inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
|
|
4149
4809
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
4150
4810
|
});
|
|
4151
4811
|
function nullable(innerType) {
|
|
@@ -4157,6 +4817,7 @@ function nullable(innerType) {
|
|
|
4157
4817
|
const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
|
|
4158
4818
|
$ZodDefault.init(inst, def);
|
|
4159
4819
|
ZodType.init(inst, def);
|
|
4820
|
+
inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
|
|
4160
4821
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
4161
4822
|
inst.removeDefault = inst.unwrap;
|
|
4162
4823
|
});
|
|
@@ -4172,6 +4833,7 @@ function _default(innerType, defaultValue) {
|
|
|
4172
4833
|
const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
|
|
4173
4834
|
$ZodPrefault.init(inst, def);
|
|
4174
4835
|
ZodType.init(inst, def);
|
|
4836
|
+
inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
|
|
4175
4837
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
4176
4838
|
});
|
|
4177
4839
|
function prefault(innerType, defaultValue) {
|
|
@@ -4186,6 +4848,7 @@ function prefault(innerType, defaultValue) {
|
|
|
4186
4848
|
const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
|
|
4187
4849
|
$ZodNonOptional.init(inst, def);
|
|
4188
4850
|
ZodType.init(inst, def);
|
|
4851
|
+
inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
|
|
4189
4852
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
4190
4853
|
});
|
|
4191
4854
|
function nonoptional(innerType, params) {
|
|
@@ -4198,6 +4861,7 @@ function nonoptional(innerType, params) {
|
|
|
4198
4861
|
const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
|
|
4199
4862
|
$ZodCatch.init(inst, def);
|
|
4200
4863
|
ZodType.init(inst, def);
|
|
4864
|
+
inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
|
|
4201
4865
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
4202
4866
|
inst.removeCatch = inst.unwrap;
|
|
4203
4867
|
});
|
|
@@ -4211,6 +4875,7 @@ function _catch(innerType, catchValue) {
|
|
|
4211
4875
|
const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
|
|
4212
4876
|
$ZodPipe.init(inst, def);
|
|
4213
4877
|
ZodType.init(inst, def);
|
|
4878
|
+
inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
|
|
4214
4879
|
inst.in = def.in;
|
|
4215
4880
|
inst.out = def.out;
|
|
4216
4881
|
});
|
|
@@ -4225,6 +4890,7 @@ function pipe(in_, out) {
|
|
|
4225
4890
|
const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
|
|
4226
4891
|
$ZodReadonly.init(inst, def);
|
|
4227
4892
|
ZodType.init(inst, def);
|
|
4893
|
+
inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
|
|
4228
4894
|
inst.unwrap = () => inst._zod.def.innerType;
|
|
4229
4895
|
});
|
|
4230
4896
|
function readonly(innerType) {
|
|
@@ -4236,6 +4902,7 @@ function readonly(innerType) {
|
|
|
4236
4902
|
const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
|
|
4237
4903
|
$ZodCustom.init(inst, def);
|
|
4238
4904
|
ZodType.init(inst, def);
|
|
4905
|
+
inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
|
|
4239
4906
|
});
|
|
4240
4907
|
function refine(fn, _params = {}) {
|
|
4241
4908
|
return _refine(ZodCustom, fn, _params);
|