@kevisual/router 0.0.37 → 0.0.38

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