@kevisual/router 0.0.39 → 0.0.40

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