@onvo-ai/react
Version:
The react SDK for Onvo AI dashboard builder
1 lines • 1.97 MB
JavaScript
import*as e from"react";import t,{useRef as n,useState as o,useEffect as r,useMemo as a,createContext as i,memo as s,useContext as l,Children as c,isValidElement as u,cloneElement as d,PureComponent as h,createRef as p,useLayoutEffect as f,useCallback as m,forwardRef as g,Component as v,createElement as y,useImperativeHandle as b,useId as w}from"react";import{jsx as x,Fragment as k,jsxs as E}from"react/jsx-runtime";import*as _ from"react-dom";import O,{createPortal as C,flushSync as S}from"react-dom";function D(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}function M(e,t){var n;return(null===(n=null==e?void 0:e._def)||void 0===n?void 0:n.typeName)===t}function N(e,t){const n=e.ZodType.prototype[t];e.ZodType.prototype[t]=function(...e){const t=n.apply(this,e);return t._def.openapi=this._def.openapi,t}}function P(e){if(void 0!==e.ZodType.prototype.openapi)return;e.ZodType.prototype.openapi=function(e,t){var n,o,r,a,i,s;const l="string"==typeof e?t:e,c=null!=l?l:{},{param:u}=c,d=D(c,["param"]),h=Object.assign(Object.assign({},null===(n=this._def.openapi)||void 0===n?void 0:n._internal),"string"==typeof e?{refId:e}:void 0),p=Object.assign(Object.assign(Object.assign({},null===(o=this._def.openapi)||void 0===o?void 0:o.metadata),d),(null===(a=null===(r=this._def.openapi)||void 0===r?void 0:r.metadata)||void 0===a?void 0:a.param)||u?{param:Object.assign(Object.assign({},null===(s=null===(i=this._def.openapi)||void 0===i?void 0:i.metadata)||void 0===s?void 0:s.param),u)}:void 0),f=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(h).length>0?{_internal:h}:void 0),Object.keys(p).length>0?{metadata:p}:void 0)}));if(M(this,"ZodObject")){const e=this.extend;f.extend=function(...t){var n,o,r,a,i,s,l;const c=e.apply(this,t);return c._def.openapi={_internal:{extendedFrom:(null===(o=null===(n=this._def.openapi)||void 0===n?void 0:n._internal)||void 0===o?void 0:o.refId)?{refId:null===(a=null===(r=this._def.openapi)||void 0===r?void 0:r._internal)||void 0===a?void 0:a.refId,schema:this}:null===(s=null===(i=this._def.openapi)||void 0===i?void 0:i._internal)||void 0===s?void 0:s.extendedFrom},metadata:null===(l=c._def.openapi)||void 0===l?void 0:l.metadata},c}}return f},N(e,"optional"),N(e,"nullable"),N(e,"default"),N(e,"transform"),N(e,"refine");const t=e.ZodObject.prototype.deepPartial;e.ZodObject.prototype.deepPartial=function(){const e=this._def.shape(),n=t.apply(this),o=n._def.shape();return Object.entries(o).forEach(([t,n])=>{var o,r;n._def.openapi=null===(r=null===(o=e[t])||void 0===o?void 0:o._def)||void 0===r?void 0:r.openapi}),n._def.openapi=void 0,n};const n=e.ZodObject.prototype.pick;e.ZodObject.prototype.pick=function(...e){const t=n.apply(this,e);return t._def.openapi=void 0,t};const o=e.ZodObject.prototype.omit;e.ZodObject.prototype.omit=function(...e){const t=o.apply(this,e);return t._def.openapi=void 0,t}}function T(e,t){if(null==e||null==t)return e===t;if(e===t||e.valueOf()===t.valueOf())return!0;if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1}if(!(e instanceof Object&&t instanceof Object))return!1;const n=Object.keys(e);return Object.keys(t).every(e=>-1!==n.indexOf(e))&&n.every(n=>T(e[n],t[n]))}"function"==typeof SuppressedError&&SuppressedError;class I{constructor(){this.buckets=new Map}put(e){const t=this.hashCodeOf(e),n=this.buckets.get(t);if(!n)return void this.buckets.set(t,[e]);const o=n.some(t=>T(t,e));o||n.push(e)}contains(e){const t=this.hashCodeOf(e),n=this.buckets.get(t);return!!n&&n.some(t=>T(t,e))}values(){return[...this.buckets.values()].flat()}stats(){let e=0,t=0,n=0;for(const o of this.buckets.values())e+=1,t+=o.length,o.length>1&&(n+=1);return{totalBuckets:e,collisions:n,totalValues:t,hashEffectiveness:e/t}}hashCodeOf(e){let t=0;if(Array.isArray(e)){for(let n=0;n<e.length;n++)t^=this.hashCodeOf(e[n])*n;return t}if("string"==typeof e){for(let n=0;n<e.length;n++)t^=e.charCodeAt(n)*n;return t}if("number"==typeof e)return e;if("object"==typeof e)for(const[n,o]of Object.entries(e))t^=this.hashCodeOf(n)+this.hashCodeOf(null!=o?o:"");return t}}function L(e){return void 0===e}function A(e,t){const n={};return Object.entries(e).forEach(([e,o])=>{n[e]=t(o)}),n}function R(e,t){const n={};return Object.entries(e).forEach(([e,o])=>{t(o,e)||(n[e]=o)}),n}function j(e){return e.filter(e=>!L(e))}const z=T;function F(e){return"string"==typeof e}class B{constructor(e){this.message=e}}class $ extends B{constructor(e,t){super(e),this.data=t}}class V extends B{constructor(e){super(`Missing parameter data, please specify \`${e.missingField}\` and other OpenAPI parameter props using the \`param\` field of \`ZodSchema.openapi\``),this.data=e}}function W(e,t){try{return e()}catch(e){if(e instanceof V)throw new V(Object.assign(Object.assign({},e.data),t));throw e}}class H extends B{constructor(e){super("Unknown zod object type, please specify `type` and other OpenAPI props using `ZodSchema.openapi`."),this.data=e}}class U{static getMetadata(e){var t;const n=this.unwrapChained(e),o=e._def.openapi?e._def.openapi:n._def.openapi,r=null!==(t=e.description)&&void 0!==t?t:n.description;return{_internal:null==o?void 0:o._internal,metadata:Object.assign({description:r},null==o?void 0:o.metadata)}}static getInternalMetadata(e){const t=this.unwrapChained(e),n=e._def.openapi?e._def.openapi:t._def.openapi;return null==n?void 0:n._internal}static getParamMetadata(e){var t,n;const o=this.unwrapChained(e),r=e._def.openapi?e._def.openapi:o._def.openapi,a=null!==(t=e.description)&&void 0!==t?t:o.description;return{_internal:null==r?void 0:r._internal,metadata:Object.assign(Object.assign({},null==r?void 0:r.metadata),{param:Object.assign({description:a},null===(n=null==r?void 0:r.metadata)||void 0===n?void 0:n.param)})}}static buildSchemaMetadata(e){return R(function(e,t){const n={};return Object.entries(e).forEach(([e,o])=>{t.some(t=>t===e)||(n[e]=o)}),n}(e,["param"]),L)}static buildParameterMetadata(e){return R(e,L)}static applySchemaMetadata(e,t){return R(Object.assign(Object.assign({},e),this.buildSchemaMetadata(t)),L)}static getRefId(e){var t;return null===(t=this.getInternalMetadata(e))||void 0===t?void 0:t.refId}static unwrapChained(e){return this.unwrapUntil(e)}static getDefaultValue(e){const t=this.unwrapUntil(e,"ZodDefault");return null==t?void 0:t._def.defaultValue()}static unwrapUntil(e,t){return t&&M(e,t)?e:M(e,"ZodOptional")||M(e,"ZodNullable")||M(e,"ZodBranded")?this.unwrapUntil(e.unwrap(),t):M(e,"ZodDefault")||M(e,"ZodReadonly")?this.unwrapUntil(e._def.innerType,t):M(e,"ZodEffects")?this.unwrapUntil(e._def.schema,t):M(e,"ZodPipeline")?this.unwrapUntil(e._def.in,t):t?void 0:e}static isOptionalSchema(e){return e.isOptional()}}class Z{transform(e,t,n){var o,r;const a=e._def.type;return Object.assign(Object.assign({},t("array")),{items:n(a),minItems:null===(o=e._def.minLength)||void 0===o?void 0:o.value,maxItems:null===(r=e._def.maxLength)||void 0===r?void 0:r.value})}}class q{transform(e){return Object.assign(Object.assign({},e("string")),{pattern:"^d+$"})}}class Y{transform(e,t,n,o,r){const a=[...e.options.values()],i=a.map(o);return t?{oneOf:n(i,t)}:{oneOf:i,discriminator:this.mapDiscriminator(a,e.discriminator,r)}}mapDiscriminator(e,t,n){if(e.some(e=>void 0===U.getRefId(e)))return;const o={};return e.forEach(e=>{var r;const a=U.getRefId(e),i=null===(r=e.shape)||void 0===r?void 0:r[t];if(M(i,"ZodEnum")||M(i,"ZodNativeEnum")){return void Object.values(i.enum).filter(F).forEach(e=>{o[e]=n(a)})}const s=null==i?void 0:i._def.value;if("string"!=typeof s)throw new Error(`Discriminator ${t} could not be found in one of the values of a discriminated union`);o[s]=n(a)}),{propertyName:t,mapping:o}}}class G{transform(e,t){return Object.assign(Object.assign({},t("string")),{enum:e._def.values})}}class K{transform(e,t,n,o){const r={allOf:this.flattenIntersectionTypes(e).map(o)};return t?{anyOf:n([r],t)}:r}flattenIntersectionTypes(e){if(!M(e,"ZodIntersection"))return[e];return[...this.flattenIntersectionTypes(e._def.left),...this.flattenIntersectionTypes(e._def.right)]}}class X{transform(e,t){return Object.assign(Object.assign({},t(typeof e._def.value)),{enum:[e._def.value]})}}class J{transform(e,t){const{type:n,values:o}=function(e){const t=Object.keys(e).filter(t=>"number"!=typeof e[e[t]]).map(t=>e[t]),n=t.filter(e=>"number"==typeof e).length;return{values:t,type:0===n?"string":n===t.length?"numeric":"mixed"}}(e._def.values);if("mixed"===n)throw new B("Enum has mixed string and number values, please specify the OpenAPI type manually");return Object.assign(Object.assign({},t("numeric"===n?"integer":"string")),{enum:o})}}class Q{transform(e,t,n){return Object.assign(Object.assign({},t(e.isInt?"integer":"number")),n(e._def.checks))}}class ee{transform(e,t,n,o){var r;const a=null===(r=U.getInternalMetadata(e))||void 0===r?void 0:r.extendedFrom,i=this.requiredKeysOf(e),s=A(e._def.shape(),o);if(!a)return Object.assign(Object.assign(Object.assign(Object.assign({},n("object")),{properties:s,default:t}),i.length>0?{required:i}:{}),this.generateAdditionalProperties(e,o));const l=a.schema;o(l);const c=this.requiredKeysOf(l),u=A(null==l?void 0:l._def.shape(),o),d=Object.fromEntries(Object.entries(s).filter(([e,t])=>!z(u[e],t))),h=i.filter(e=>!c.includes(e)),p=Object.assign(Object.assign(Object.assign(Object.assign({},n("object")),{default:t,properties:d}),h.length>0?{required:h}:{}),this.generateAdditionalProperties(e,o));return{allOf:[{$ref:`#/components/schemas/${a.refId}`},p]}}generateAdditionalProperties(e,t){const n=e._def.unknownKeys,o=e._def.catchall;return M(o,"ZodNever")?"strict"===n?{additionalProperties:!1}:{}:{additionalProperties:t(o)}}requiredKeysOf(e){return Object.entries(e._def.shape()).filter(([e,t])=>!U.isOptionalSchema(t)).map(([e,t])=>e)}}class te{transform(e,t,n){const o=e._def.valueType,r=e._def.keyType,a=n(o);if(M(r,"ZodEnum")||M(r,"ZodNativeEnum")){const e=Object.values(r.enum).filter(F).reduce((e,t)=>Object.assign(Object.assign({},e),{[t]:a}),{});return Object.assign(Object.assign({},t("object")),{properties:e})}return Object.assign(Object.assign({},t("object")),{additionalProperties:a})}}class ne{transform(e,t){var n,o,r;const a=this.getZodStringCheck(e,"regex"),i=null===(n=this.getZodStringCheck(e,"length"))||void 0===n?void 0:n.value,s=Number.isFinite(e.minLength)&&null!==(o=e.minLength)&&void 0!==o?o:void 0,l=Number.isFinite(e.maxLength)&&null!==(r=e.maxLength)&&void 0!==r?r:void 0;return Object.assign(Object.assign({},t("string")),{minLength:null!=i?i:s,maxLength:null!=i?i:l,format:this.mapStringFormat(e),pattern:null==a?void 0:a.regex.source})}mapStringFormat(e){return e.isUUID?"uuid":e.isEmail?"email":e.isURL?"uri":e.isDate?"date":e.isDatetime?"date-time":e.isCUID?"cuid":e.isCUID2?"cuid2":e.isULID?"ulid":e.isIP?"ip":e.isEmoji?"emoji":void 0}getZodStringCheck(e,t){return e._def.checks.find(e=>e.kind===t)}}class oe{constructor(e){this.versionSpecifics=e}transform(e,t,n){const{items:o}=e._def,r=o.map(n);return Object.assign(Object.assign({},t("array")),this.versionSpecifics.mapTupleItems(r))}}class re{transform(e,t,n){return{anyOf:t(this.flattenUnionTypes(e).map(e=>{const t=this.unwrapNullable(e);return n(t)}))}}flattenUnionTypes(e){if(!M(e,"ZodUnion"))return[e];return e._def.options.flatMap(e=>this.flattenUnionTypes(e))}unwrapNullable(e){return M(e,"ZodNullable")?this.unwrapNullable(e.unwrap()):e}}class ae{constructor(e){this.versionSpecifics=e,this.objectTransformer=new ee,this.stringTransformer=new ne,this.numberTransformer=new Q,this.bigIntTransformer=new q,this.literalTransformer=new X,this.enumTransformer=new G,this.nativeEnumTransformer=new J,this.arrayTransformer=new Z,this.unionTransformer=new re,this.discriminatedUnionTransformer=new Y,this.intersectionTransformer=new K,this.recordTransformer=new te,this.tupleTransformer=new oe(e)}transform(e,t,n,o,r){if(M(e,"ZodNull"))return this.versionSpecifics.nullType;if(M(e,"ZodUnknown")||M(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(M(e,"ZodObject"))return this.objectTransformer.transform(e,r,e=>this.versionSpecifics.mapNullableType(e,t),n);const a=this.transformSchemaWithoutDefault(e,t,n,o);return Object.assign(Object.assign({},a),{default:r})}transformSchemaWithoutDefault(e,t,n,o){if(M(e,"ZodUnknown")||M(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(M(e,"ZodString"))return this.stringTransformer.transform(e,e=>this.versionSpecifics.mapNullableType(e,t));if(M(e,"ZodNumber"))return this.numberTransformer.transform(e,e=>this.versionSpecifics.mapNullableType(e,t),e=>this.versionSpecifics.getNumberChecks(e));if(M(e,"ZodBigInt"))return this.bigIntTransformer.transform(e=>this.versionSpecifics.mapNullableType(e,t));if(M(e,"ZodBoolean"))return this.versionSpecifics.mapNullableType("boolean",t);if(M(e,"ZodLiteral"))return this.literalTransformer.transform(e,e=>this.versionSpecifics.mapNullableType(e,t));if(M(e,"ZodEnum"))return this.enumTransformer.transform(e,e=>this.versionSpecifics.mapNullableType(e,t));if(M(e,"ZodNativeEnum"))return this.nativeEnumTransformer.transform(e,e=>this.versionSpecifics.mapNullableType(e,t));if(M(e,"ZodArray"))return this.arrayTransformer.transform(e,e=>this.versionSpecifics.mapNullableType(e,t),n);if(M(e,"ZodTuple"))return this.tupleTransformer.transform(e,e=>this.versionSpecifics.mapNullableType(e,t),n);if(M(e,"ZodUnion"))return this.unionTransformer.transform(e,e=>this.versionSpecifics.mapNullableOfArray(e,t),n);if(M(e,"ZodDiscriminatedUnion"))return this.discriminatedUnionTransformer.transform(e,t,e=>this.versionSpecifics.mapNullableOfArray(e,t),n,o);if(M(e,"ZodIntersection"))return this.intersectionTransformer.transform(e,t,e=>this.versionSpecifics.mapNullableOfArray(e,t),n);if(M(e,"ZodRecord"))return this.recordTransformer.transform(e,e=>this.versionSpecifics.mapNullableType(e,t),n);if(M(e,"ZodDate"))return this.versionSpecifics.mapNullableType("string",t);const r=U.getRefId(e);throw new H({currentSchema:e._def,schemaName:r})}}class ie{constructor(e,t){this.definitions=e,this.versionSpecifics=t,this.schemaRefs={},this.paramRefs={},this.pathRefs={},this.rawComponents=[],this.openApiTransformer=new ae(t),this.sortDefinitions()}generateDocumentData(){return this.definitions.forEach(e=>this.generateSingle(e)),{components:this.buildComponents(),paths:this.pathRefs}}generateComponents(){return this.definitions.forEach(e=>this.generateSingle(e)),{components:this.buildComponents()}}buildComponents(){var e,t;const n={};return this.rawComponents.forEach(({componentType:e,name:t,component:o})=>{var r;null!==(r=n[e])&&void 0!==r||(n[e]={}),n[e][t]=o}),Object.assign(Object.assign({},n),{schemas:Object.assign(Object.assign({},null!==(e=n.schemas)&&void 0!==e?e:{}),this.schemaRefs),parameters:Object.assign(Object.assign({},null!==(t=n.parameters)&&void 0!==t?t:{}),this.paramRefs)})}sortDefinitions(){const e=["schema","parameter","component","route"];this.definitions.sort((t,n)=>{if(!("type"in t))return"type"in n?-1:0;if(!("type"in n))return 1;const o=e.findIndex(e=>e===t.type),r=e.findIndex(e=>e===n.type);return o-r})}generateSingle(e){if("type"in e)switch(e.type){case"parameter":return void this.generateParameterDefinition(e.schema);case"schema":return void this.generateSchemaWithRef(e.schema);case"route":return void this.generateSingleRoute(e.route);case"component":return void this.rawComponents.push(e)}else this.generateSchemaWithRef(e)}generateParameterDefinition(e){const t=U.getRefId(e),n=this.generateParameter(e);return t&&(this.paramRefs[t]=n),n}getParameterRef(e,t){var n,o,r,a,i;const s=null===(n=null==e?void 0:e.metadata)||void 0===n?void 0:n.param,l=(null===(o=null==e?void 0:e._internal)||void 0===o?void 0:o.refId)?this.paramRefs[null===(r=e._internal)||void 0===r?void 0:r.refId]:void 0;if((null===(a=null==e?void 0:e._internal)||void 0===a?void 0:a.refId)&&l){if(s&&l.in!==s.in||(null==t?void 0:t.in)&&l.in!==t.in)throw new $(`Conflicting location for parameter ${l.name}`,{key:"in",values:j([l.in,null==t?void 0:t.in,null==s?void 0:s.in])});if(s&&l.name!==s.name||(null==t?void 0:t.name)&&l.name!==(null==t?void 0:t.name))throw new $("Conflicting names for parameter",{key:"name",values:j([l.name,null==t?void 0:t.name,null==s?void 0:s.name])});return{$ref:`#/components/parameters/${null===(i=e._internal)||void 0===i?void 0:i.refId}`}}}generateInlineParameters(e,t){var n;const o=U.getMetadata(e),r=null===(n=null==o?void 0:o.metadata)||void 0===n?void 0:n.param,a=this.getParameterRef(o,{in:t});if(a)return[a];if(M(e,"ZodObject")){const n=e._def.shape(),o=Object.entries(n).map(([e,n])=>{var o,r;const a=U.getMetadata(n),i=this.getParameterRef(a,{in:t,name:e});if(i)return i;const s=null===(o=null==a?void 0:a.metadata)||void 0===o?void 0:o.param;if((null==s?void 0:s.name)&&s.name!==e)throw new $("Conflicting names for parameter",{key:"name",values:[e,s.name]});if((null==s?void 0:s.in)&&s.in!==t)throw new $(`Conflicting location for parameter ${null!==(r=s.name)&&void 0!==r?r:e}`,{key:"in",values:[t,s.in]});return this.generateParameter(n.openapi({param:{name:e,in:t}}))});return o}if((null==r?void 0:r.in)&&r.in!==t)throw new $(`Conflicting location for parameter ${r.name}`,{key:"in",values:[t,r.in]});return[this.generateParameter(e.openapi({param:{in:t}}))]}generateSimpleParameter(e){var t;const n=U.getParamMetadata(e),o=null===(t=null==n?void 0:n.metadata)||void 0===t?void 0:t.param,r=!U.isOptionalSchema(e)&&!e.isNullable(),a=this.generateSchemaWithRef(e);return Object.assign({schema:a,required:r},o?U.buildParameterMetadata(o):{})}generateParameter(e){var t;const n=U.getMetadata(e),o=null===(t=null==n?void 0:n.metadata)||void 0===t?void 0:t.param,r=null==o?void 0:o.name,a=null==o?void 0:o.in;if(!r)throw new V({missingField:"name"});if(!a)throw new V({missingField:"in",paramName:r});const i=this.generateSimpleParameter(e);return Object.assign(Object.assign({},i),{in:a,name:r})}generateSchemaWithMetadata(e){var t;const n=U.unwrapChained(e),o=U.getMetadata(e),r=U.getDefaultValue(e),a=(null===(t=null==o?void 0:o.metadata)||void 0===t?void 0:t.type)?{type:null==o?void 0:o.metadata.type}:this.toOpenAPISchema(n,e.isNullable(),r);return(null==o?void 0:o.metadata)?U.applySchemaMetadata(a,o.metadata):R(a,L)}constructReferencedOpenAPISchema(e){var t;const n=U.getMetadata(e),o=U.unwrapChained(e),r=U.getDefaultValue(e),a=e.isNullable();return(null===(t=null==n?void 0:n.metadata)||void 0===t?void 0:t.type)?this.versionSpecifics.mapNullableType(n.metadata.type,a):this.toOpenAPISchema(o,a,r)}generateSimpleSchema(e){var t;const n=U.getMetadata(e),o=U.getRefId(e);if(!o||!this.schemaRefs[o])return this.generateSchemaWithMetadata(e);const r=this.schemaRefs[o],a={$ref:this.generateSchemaRef(o)},i=R(U.buildSchemaMetadata(null!==(t=null==n?void 0:n.metadata)&&void 0!==t?t:{}),(e,t)=>void 0===e||z(e,r[t]));if(i.type)return{allOf:[a,i]};const s=R(this.constructReferencedOpenAPISchema(e),(e,t)=>void 0===e||z(e,r[t])),l=U.applySchemaMetadata(s,i);return Object.keys(l).length>0?{allOf:[a,l]}:a}generateSchemaWithRef(e){const t=U.getRefId(e),n=this.generateSimpleSchema(e);return t&&void 0===this.schemaRefs[t]?(this.schemaRefs[t]=n,{$ref:this.generateSchemaRef(t)}):n}generateSchemaRef(e){return`#/components/schemas/${e}`}getRequestBody(e){if(!e)return;const{content:t}=e,n=D(e,["content"]),o=this.getBodyContent(t);return Object.assign(Object.assign({},n),{content:o})}getParameters(e){if(!e)return[];const{headers:t}=e,n=this.cleanParameter(e.query),o=this.cleanParameter(e.params),r=this.cleanParameter(e.cookies),a=W(()=>n?this.generateInlineParameters(n,"query"):[],{location:"query"}),i=W(()=>o?this.generateInlineParameters(o,"path"):[],{location:"path"}),s=W(()=>r?this.generateInlineParameters(r,"cookie"):[],{location:"cookie"});return[...i,...a,...W(()=>{if(Array.isArray(t))return t.flatMap(e=>this.generateInlineParameters(e,"header"));const e=this.cleanParameter(t);return e?this.generateInlineParameters(e,"header"):[]},{location:"header"}),...s]}cleanParameter(e){if(e)return M(e,"ZodEffects")?this.cleanParameter(e._def.schema):e}generatePath(e){const{method:t,path:n,request:o,responses:r}=e,a=D(e,["method","path","request","responses"]),i=A(r,e=>this.getResponse(e)),s=W(()=>this.getParameters(o),{route:`${t} ${n}`}),l=this.getRequestBody(null==o?void 0:o.body);return{[t]:Object.assign(Object.assign(Object.assign(Object.assign({},a),s.length>0?{parameters:[...a.parameters||[],...s]}:{}),l?{requestBody:l}:{}),{responses:i})}}generateSingleRoute(e){const t=this.generatePath(e);return this.pathRefs[e.path]=Object.assign(Object.assign({},this.pathRefs[e.path]),t),t}getResponse(e){if(this.isReferenceObject(e))return e;const{content:t,headers:n}=e,o=D(e,["content","headers"]),r=t?{content:this.getBodyContent(t)}:{};if(!n)return Object.assign(Object.assign({},o),r);const a=M(n,"ZodObject")?this.getResponseHeaders(n):n;return Object.assign(Object.assign(Object.assign({},o),{headers:a}),r)}isReferenceObject(e){return"$ref"in e}getResponseHeaders(e){const t=A(e._def.shape(),e=>this.generateSimpleParameter(e));return t}getBodyContent(e){return A(e,e=>{if(!e||!function(e){return"_def"in e}(e.schema))return e;const{schema:t}=e,n=D(e,["schema"]),o=this.generateSchemaWithRef(t);return Object.assign({schema:o},n)})}toOpenAPISchema(e,t,n){return this.openApiTransformer.transform(e,t,e=>this.generateSchemaWithRef(e),e=>this.generateSchemaRef(e),n)}}class se{get nullType(){return{nullable:!0}}mapNullableOfArray(e,t){return t?[...e,this.nullType]:e}mapNullableType(e,t){return Object.assign(Object.assign({},e?{type:e}:void 0),t?this.nullType:void 0)}mapTupleItems(e){const t=function(e){const t=new I;return e.forEach(e=>t.put(e)),[...t.values()]}(e);return{items:1===t.length?t[0]:{anyOf:t},minItems:e.length,maxItems:e.length}}getNumberChecks(e){return Object.assign({},...e.map(e=>{switch(e.kind){case"min":return e.inclusive?{minimum:Number(e.value)}:{minimum:Number(e.value),exclusiveMinimum:!0};case"max":return e.inclusive?{maximum:Number(e.value)}:{maximum:Number(e.value),exclusiveMaximum:!0};default:return{}}}))}}var le,ce;!function(e){e.assertEqual=e=>{},e.assertIs=function(e){},e.assertNever=function(e){throw new Error},e.arrayToEnum=e=>{const t={};for(const n of e)t[n]=n;return t},e.getValidEnumValues=t=>{const n=e.objectKeys(t).filter(e=>"number"!=typeof t[t[e]]),o={};for(const e of n)o[e]=t[e];return e.objectValues(o)},e.objectValues=t=>e.objectKeys(t).map(function(e){return t[e]}),e.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t},e.find=(e,t)=>{for(const n of e)if(t(n))return n},e.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&Number.isFinite(e)&&Math.floor(e)===e,e.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},e.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t}(le||(le={})),function(e){e.mergeShapes=(e,t)=>({...e,...t})}(ce||(ce={}));const ue=le.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),de=e=>{switch(typeof e){case"undefined":return ue.undefined;case"string":return ue.string;case"number":return Number.isNaN(e)?ue.nan:ue.number;case"boolean":return ue.boolean;case"function":return ue.function;case"bigint":return ue.bigint;case"symbol":return ue.symbol;case"object":return Array.isArray(e)?ue.array:null===e?ue.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?ue.promise:"undefined"!=typeof Map&&e instanceof Map?ue.map:"undefined"!=typeof Set&&e instanceof Set?ue.set:"undefined"!=typeof Date&&e instanceof Date?ue.date:ue.object;default:return ue.unknown}},he=le.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class pe extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},n={_errors:[]},o=e=>{for(const r of e.issues)if("invalid_union"===r.code)r.unionErrors.map(o);else if("invalid_return_type"===r.code)o(r.returnTypeError);else if("invalid_arguments"===r.code)o(r.argumentsError);else if(0===r.path.length)n._errors.push(t(r));else{let e=n,o=0;for(;o<r.path.length;){const n=r.path[o];o===r.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(r))):e[n]=e[n]||{_errors:[]},e=e[n],o++}}};return o(this),n}static assert(e){if(!(e instanceof pe))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,le.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},n=[];for(const o of this.issues)if(o.path.length>0){const n=o.path[0];t[n]=t[n]||[],t[n].push(e(o))}else n.push(e(o));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}pe.create=e=>new pe(e);const fe=(e,t)=>{let n;switch(e.code){case he.invalid_type:n=e.received===ue.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case he.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,le.jsonStringifyReplacer)}`;break;case he.unrecognized_keys:n=`Unrecognized key(s) in object: ${le.joinValues(e.keys,", ")}`;break;case he.invalid_union:n="Invalid input";break;case he.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${le.joinValues(e.options)}`;break;case he.invalid_enum_value:n=`Invalid enum value. Expected ${le.joinValues(e.options)}, received '${e.received}'`;break;case he.invalid_arguments:n="Invalid function arguments";break;case he.invalid_return_type:n="Invalid function return type";break;case he.invalid_date:n="Invalid date";break;case he.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:le.assertNever(e.validation):n="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case he.too_small:n="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type||"bigint"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case he.too_big:n="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case he.custom:n="Invalid input";break;case he.invalid_intersection_types:n="Intersection results could not be merged";break;case he.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case he.not_finite:n="Number must be finite";break;default:n=t.defaultError,le.assertNever(e)}return{message:n}};let me=fe;function ge(){return me}const ve=e=>{const{data:t,path:n,errorMaps:o,issueData:r}=e,a=[...n,...r.path||[]],i={...r,path:a};if(void 0!==r.message)return{...r,path:a,message:r.message};let s="";const l=o.filter(e=>!!e).slice().reverse();for(const e of l)s=e(i,{data:t,defaultError:s}).message;return{...r,path:a,message:s}};function ye(e,t){const n=ge(),o=ve({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===fe?void 0:fe].filter(e=>!!e)});e.common.issues.push(o)}class be{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const o of t){if("aborted"===o.status)return we;"dirty"===o.status&&e.dirty(),n.push(o.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const e of t){const t=await e.key,o=await e.value;n.push({key:t,value:o})}return be.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const o of t){const{key:t,value:r}=o;if("aborted"===t.status)return we;if("aborted"===r.status)return we;"dirty"===t.status&&e.dirty(),"dirty"===r.status&&e.dirty(),"__proto__"===t.value||void 0===r.value&&!o.alwaysSet||(n[t.value]=r.value)}return{status:e.value,value:n}}}const we=Object.freeze({status:"aborted"}),xe=e=>({status:"dirty",value:e}),ke=e=>({status:"valid",value:e}),Ee=e=>"aborted"===e.status,_e=e=>"dirty"===e.status,Oe=e=>"valid"===e.status,Ce=e=>"undefined"!=typeof Promise&&e instanceof Promise;var Se;!function(e){e.errToObj=e=>"string"==typeof e?{message:e}:e||{},e.toString=e=>"string"==typeof e?e:e?.message}(Se||(Se={}));class De{constructor(e,t,n,o){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=o}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Me=(e,t)=>{if(Oe(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new pe(e.common.issues);return this._error=t,this._error}}};function Ne(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:o,description:r}=e;if(t&&(n||o))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');if(t)return{errorMap:t,description:r};return{errorMap:(t,r)=>{const{message:a}=e;return"invalid_enum_value"===t.code?{message:a??r.defaultError}:void 0===r.data?{message:a??o??r.defaultError}:"invalid_type"!==t.code?{message:r.defaultError}:{message:a??n??r.defaultError}},description:r}}class Pe{get description(){return this._def.description}_getType(e){return de(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:de(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new be,ctx:{common:e.parent.common,data:e.data,parsedType:de(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Ce(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const n=this.safeParse(e,t);if(n.success)return n.data;throw n.error}safeParse(e,t){const n={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:de(e)},o=this._parseSync({data:e,path:n.path,parent:n});return Me(n,o)}"~validate"(e){const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:de(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:t});return Oe(n)?{value:n.value}:{issues:t.common.issues}}catch(e){e?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(e=>Oe(e)?{value:e.value}:{issues:t.common.issues})}async parseAsync(e,t){const n=await this.safeParseAsync(e,t);if(n.success)return n.data;throw n.error}async safeParseAsync(e,t){const n={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:de(e)},o=this._parse({data:e,path:n.path,parent:n}),r=await(Ce(o)?o:Promise.resolve(o));return Me(n,r)}refine(e,t){const n=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement((t,o)=>{const r=e(t),a=()=>o.addIssue({code:he.custom,...n(t)});return"undefined"!=typeof Promise&&r instanceof Promise?r.then(e=>!!e||(a(),!1)):!!r||(a(),!1)})}refinement(e,t){return this._refinement((n,o)=>!!e(n)||(o.addIssue("function"==typeof t?t(n,o):t),!1))}_refinement(e){return new It({schema:this,typeName:Zt.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return Lt.create(this,this._def)}nullable(){return At.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ft.create(this)}promise(){return Tt.create(this,this._def)}or(e){return vt.create([this,e],this._def)}and(e){return xt.create(this,e,this._def)}transform(e){return new It({...Ne(this._def),schema:this,typeName:Zt.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new Rt({...Ne(this._def),innerType:this,defaultValue:t,typeName:Zt.ZodDefault})}brand(){return new Bt({typeName:Zt.ZodBranded,type:this,...Ne(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new jt({...Ne(this._def),innerType:this,catchValue:t,typeName:Zt.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return $t.create(this,e)}readonly(){return Vt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Te=/^c[^\s-]{8,}$/i,Ie=/^[0-9a-z]+$/,Le=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ae=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Re=/^[a-z0-9_-]{21}$/i,je=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ze=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Fe=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;let Be;const $e=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ve=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,We=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,He=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Ue=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ze=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,qe="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Ye=new RegExp(`^${qe}$`);function Ge(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e.precision?"+":"?"}`}function Ke(e){return new RegExp(`^${Ge(e)}$`)}function Xe(e){let t=`${qe}T${Ge(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function Je(e,t){return!("v4"!==t&&t||!$e.test(e))||!("v6"!==t&&t||!We.test(e))}function Qe(e,t){if(!je.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const o=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),r=JSON.parse(atob(o));return"object"==typeof r&&null!==r&&((!("typ"in r)||"JWT"===r?.typ)&&(!!r.alg&&(!t||r.alg===t)))}catch{return!1}}function et(e,t){return!("v4"!==t&&t||!Ve.test(e))||!("v6"!==t&&t||!He.test(e))}class tt extends Pe{_parse(e){this._def.coerce&&(e.data=String(e.data));if(this._getType(e)!==ue.string){const t=this._getOrReturnCtx(e);return ye(t,{code:he.invalid_type,expected:ue.string,received:t.parsedType}),we}const t=new be;let n;for(const o of this._def.checks)if("min"===o.kind)e.data.length<o.value&&(n=this._getOrReturnCtx(e,n),ye(n,{code:he.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),t.dirty());else if("max"===o.kind)e.data.length>o.value&&(n=this._getOrReturnCtx(e,n),ye(n,{code:he.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),t.dirty());else if("length"===o.kind){const r=e.data.length>o.value,a=e.data.length<o.value;(r||a)&&(n=this._getOrReturnCtx(e,n),r?ye(n,{code:he.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}):a&&ye(n,{code:he.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message}),t.dirty())}else if("email"===o.kind)Fe.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"email",code:he.invalid_string,message:o.message}),t.dirty());else if("emoji"===o.kind)Be||(Be=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Be.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"emoji",code:he.invalid_string,message:o.message}),t.dirty());else if("uuid"===o.kind)Ae.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"uuid",code:he.invalid_string,message:o.message}),t.dirty());else if("nanoid"===o.kind)Re.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"nanoid",code:he.invalid_string,message:o.message}),t.dirty());else if("cuid"===o.kind)Te.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"cuid",code:he.invalid_string,message:o.message}),t.dirty());else if("cuid2"===o.kind)Ie.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"cuid2",code:he.invalid_string,message:o.message}),t.dirty());else if("ulid"===o.kind)Le.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"ulid",code:he.invalid_string,message:o.message}),t.dirty());else if("url"===o.kind)try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),ye(n,{validation:"url",code:he.invalid_string,message:o.message}),t.dirty()}else if("regex"===o.kind){o.regex.lastIndex=0;o.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"regex",code:he.invalid_string,message:o.message}),t.dirty())}else if("trim"===o.kind)e.data=e.data.trim();else if("includes"===o.kind)e.data.includes(o.value,o.position)||(n=this._getOrReturnCtx(e,n),ye(n,{code:he.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),t.dirty());else if("toLowerCase"===o.kind)e.data=e.data.toLowerCase();else if("toUpperCase"===o.kind)e.data=e.data.toUpperCase();else if("startsWith"===o.kind)e.data.startsWith(o.value)||(n=this._getOrReturnCtx(e,n),ye(n,{code:he.invalid_string,validation:{startsWith:o.value},message:o.message}),t.dirty());else if("endsWith"===o.kind)e.data.endsWith(o.value)||(n=this._getOrReturnCtx(e,n),ye(n,{code:he.invalid_string,validation:{endsWith:o.value},message:o.message}),t.dirty());else if("datetime"===o.kind){Xe(o).test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{code:he.invalid_string,validation:"datetime",message:o.message}),t.dirty())}else if("date"===o.kind){Ye.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{code:he.invalid_string,validation:"date",message:o.message}),t.dirty())}else if("time"===o.kind){Ke(o).test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{code:he.invalid_string,validation:"time",message:o.message}),t.dirty())}else"duration"===o.kind?ze.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"duration",code:he.invalid_string,message:o.message}),t.dirty()):"ip"===o.kind?Je(e.data,o.version)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"ip",code:he.invalid_string,message:o.message}),t.dirty()):"jwt"===o.kind?Qe(e.data,o.alg)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"jwt",code:he.invalid_string,message:o.message}),t.dirty()):"cidr"===o.kind?et(e.data,o.version)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"cidr",code:he.invalid_string,message:o.message}),t.dirty()):"base64"===o.kind?Ue.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"base64",code:he.invalid_string,message:o.message}),t.dirty()):"base64url"===o.kind?Ze.test(e.data)||(n=this._getOrReturnCtx(e,n),ye(n,{validation:"base64url",code:he.invalid_string,message:o.message}),t.dirty()):le.assertNever(o);return{status:t.value,value:e.data}}_regex(e,t,n){return this.refinement(t=>e.test(t),{validation:t,code:he.invalid_string,...Se.errToObj(n)})}_addCheck(e){return new tt({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...Se.errToObj(e)})}url(e){return this._addCheck({kind:"url",...Se.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...Se.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...Se.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...Se.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...Se.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...Se.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...Se.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...Se.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...Se.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...Se.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...Se.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...Se.errToObj(e)})}datetime(e){return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===e?.precision?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...Se.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===e?.precision?null:e?.precision,...Se.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...Se.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...Se.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...Se.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...Se.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...Se.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...Se.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...Se.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...Se.errToObj(t)})}nonempty(e){return this.min(1,Se.errToObj(e))}trim(){return new tt({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new tt({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new tt({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}function nt(e,t){const n=(e.toString().split(".")[1]||"").length,o=(t.toString().split(".")[1]||"").length,r=n>o?n:o;return Number.parseInt(e.toFixed(r).replace(".",""))%Number.parseInt(t.toFixed(r).replace(".",""))/10**r}tt.create=e=>new tt({checks:[],typeName:Zt.ZodString,coerce:e?.coerce??!1,...Ne(e)});class ot extends Pe{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){this._def.coerce&&(e.data=Number(e.data));if(this._getType(e)!==ue.number){const t=this._getOrReturnCtx(e);return ye(t,{code:he.invalid_type,expected:ue.number,received:t.parsedType}),we}let t;const n=new be;for(const o of this._def.checks)if("int"===o.kind)le.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),ye(t,{code:he.invalid_type,expected:"integer",received:"float",message:o.message}),n.dirty());else if("min"===o.kind){(o.inclusive?e.data<o.value:e.data<=o.value)&&(t=this._getOrReturnCtx(e,t),ye(t,{code:he.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),n.dirty())}else if("max"===o.kind){(o.inclusive?e.data>o.value:e.data>=o.value)&&(t=this._getOrReturnCtx(e,t),ye(t,{code:he.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),n.dirty())}else"multipleOf"===o.kind?0!==nt(e.data,o.value)&&(t=this._getOrReturnCtx(e,t),ye(t,{code:he.not_multiple_of,multipleOf:o.value,message:o.message}),n.dirty()):"finite"===o.kind?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),ye(t,{code:he.not_finite,message:o.message}),n.dirty()):le.assertNever(o);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,Se.toString(t))}gt(e,t){return this.setLimit("min",e,!1,Se.toString(t))}lte(e,t){return this.setLimit("max",e,!0,Se.toString(t))}lt(e,t){return this.setLimit("max",e,!1,Se.toString(t))}setLimit(e,t,n,o){return new ot({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:Se.toString(o)}]})}_addCheck(e){return new ot({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:Se.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Se.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Se.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Se.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Se.toString(e)}