authhero 0.2.1 → 0.2.2

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.
@@ -1 +1 @@
1
- var authhero=function(I){"use strict";var Ps=Object.defineProperty;var xr=I=>{throw TypeError(I)};var Zs=(I,C,v)=>C in I?Ps(I,C,{enumerable:!0,configurable:!0,writable:!0,value:v}):I[C]=v;var m=(I,C,v)=>Zs(I,typeof C!="symbol"?C+"":C,v),kr=(I,C,v)=>C.has(I)||xr("Cannot "+v);var f=(I,C,v)=>(kr(I,C,"read from private field"),v?v.call(I):C.get(I)),$=(I,C,v)=>C.has(I)?xr("Cannot add the same private member more than once"):C instanceof WeakSet?C.add(I):C.set(I,v),R=(I,C,v,ut)=>(kr(I,C,"write to private field"),ut?ut.call(I,v):C.set(I,v),v);var Ee,F,_r,st,at,le,ve,ne,A,N,G,se,it,Se,Ce,ot,ct,br,K,wr;function C(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(r);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(r,n[s])&&(t[n[s]]=r[n[s]]);return t}typeof SuppressedError=="function"&&SuppressedError;function v(r,e){var t;return((t=r==null?void 0:r._def)===null||t===void 0?void 0:t.typeName)===e}function ut(r){return"_def"in r}function Ze(r,e){const t=r.ZodType.prototype[e];r.ZodType.prototype[e]=function(...n){const s=t.apply(this,n);return s._def.openapi=this._def.openapi,s}}function Or(r){if(typeof r.ZodType.prototype.openapi<"u")return;r.ZodType.prototype.openapi=function(s,a){var i,o,c,u,d,h;const T=typeof s=="string"?a:s,S=T??{},{param:E}=S,w=C(S,["param"]),D=Object.assign(Object.assign({},(i=this._def.openapi)===null||i===void 0?void 0:i._internal),typeof s=="string"?{refId:s}:void 0),L=Object.assign(Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o.metadata),w),!((u=(c=this._def.openapi)===null||c===void 0?void 0:c.metadata)===null||u===void 0)&&u.param||E?{param:Object.assign(Object.assign({},(h=(d=this._def.openapi)===null||d===void 0?void 0:d.metadata)===null||h===void 0?void 0:h.param),E)}:void 0),z=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(D).length>0?{_internal:D}:void 0),Object.keys(L).length>0?{metadata:L}:void 0)}));if(v(this,"ZodObject")){const Y=this.extend;z.extend=function(...Ie){var he,ae,ee,Pe,ye,$t;const Lt=Y.apply(this,Ie);return Lt._def.openapi={_internal:{extendedFrom:!((ae=(he=this._def.openapi)===null||he===void 0?void 0:he._internal)===null||ae===void 0)&&ae.refId?{refId:(Pe=(ee=this._def.openapi)===null||ee===void 0?void 0:ee._internal)===null||Pe===void 0?void 0:Pe.refId,schema:this}:(ye=this._def.openapi)===null||ye===void 0?void 0:ye._internal.extendedFrom},metadata:($t=Lt._def.openapi)===null||$t===void 0?void 0:$t.metadata},Lt}}return z},Ze(r,"optional"),Ze(r,"nullable"),Ze(r,"default"),Ze(r,"transform"),Ze(r,"refine");const e=r.ZodObject.prototype.deepPartial;r.ZodObject.prototype.deepPartial=function(){const s=this._def.shape(),a=e.apply(this),i=a._def.shape();return Object.entries(i).forEach(([o,c])=>{var u,d;c._def.openapi=(d=(u=s[o])===null||u===void 0?void 0:u._def)===null||d===void 0?void 0:d.openapi}),a._def.openapi=void 0,a};const t=r.ZodObject.prototype.pick;r.ZodObject.prototype.pick=function(...s){const a=t.apply(this,s);return a._def.openapi=void 0,a};const n=r.ZodObject.prototype.omit;r.ZodObject.prototype.omit=function(...s){const a=n.apply(this,s);return a._def.openapi=void 0,a}}function dt(r,e){if(r==null||e===null||e===void 0)return r===e;if(r===e||r.valueOf()===e.valueOf())return!0;if(Array.isArray(r)&&(!Array.isArray(e)||r.length!==e.length)||!(r instanceof Object)||!(e instanceof Object))return!1;const t=Object.keys(r);return Object.keys(e).every(n=>t.indexOf(n)!==-1)&&t.every(n=>dt(r[n],e[n]))}class Tr{constructor(){this.buckets=new Map}put(e){const t=this.hashCodeOf(e),n=this.buckets.get(t);if(!n){this.buckets.set(t,[e]);return}n.some(a=>dt(a,e))||n.push(e)}contains(e){const t=this.hashCodeOf(e),n=this.buckets.get(t);return n?n.some(s=>dt(s,e)):!1}values(){return[...this.buckets.values()].flat()}stats(){let e=0,t=0,n=0;for(const a of this.buckets.values())e+=1,t+=a.length,a.length>1&&(n+=1);const s=e/t;return{totalBuckets:e,collisions:n,totalValues:t,hashEffectiveness:s}}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(typeof e=="string"){for(let n=0;n<e.length;n++)t^=e.charCodeAt(n)*n;return t}if(typeof e=="number")return e;if(typeof e=="object")for(const[n,s]of Object.entries(e))t^=this.hashCodeOf(n)+this.hashCodeOf(s??"");return t}}function Ae(r){return r==null}function Ne(r,e){const t={};return Object.entries(r).forEach(([n,s])=>{t[n]=e(s)}),t}function jr(r,e){const t={};return Object.entries(r).forEach(([n,s])=>{e.some(a=>a===n)||(t[n]=s)}),t}function _e(r,e){const t={};return Object.entries(r).forEach(([n,s])=>{e(s,n)||(t[n]=s)}),t}function Ut(r){return r.filter(e=>!Ae(e))}const jt=dt;function Rr(r){const e=new Tr;return r.forEach(t=>e.put(t)),[...e.values()]}function Ht(r){return typeof r=="string"}class Er{constructor(e){this.parents=e,this._definitions=[]}get definitions(){var e,t;return[...(t=(e=this.parents)===null||e===void 0?void 0:e.flatMap(s=>s.definitions))!==null&&t!==void 0?t:[],...this._definitions]}register(e,t){const n=this.schemaWithRefId(e,t);return this._definitions.push({type:"schema",schema:n}),n}registerParameter(e,t){var n,s,a;const i=this.schemaWithRefId(e,t),o=(n=i._def.openapi)===null||n===void 0?void 0:n.metadata,c=i.openapi(Object.assign(Object.assign({},o),{param:Object.assign(Object.assign({},o==null?void 0:o.param),{name:(a=(s=o==null?void 0:o.param)===null||s===void 0?void 0:s.name)!==null&&a!==void 0?a:e})}));return this._definitions.push({type:"parameter",schema:c}),c}registerPath(e){this._definitions.push({type:"route",route:e})}registerWebhook(e){this._definitions.push({type:"webhook",webhook:e})}registerComponent(e,t,n){return this._definitions.push({type:"component",componentType:e,name:t,component:n}),{name:t,ref:{$ref:`#/components/${e}/${t}`}}}schemaWithRefId(e,t){return t.openapi(e)}}class lt{constructor(e){this.message=e}}class De extends lt{constructor(e,t){super(e),this.data=t}}class ht extends lt{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 Me(r,e){try{return r()}catch(t){throw t instanceof ht?new ht(Object.assign(Object.assign({},t.data),e)):t}}class Sr extends lt{constructor(e){super("Unknown zod object type, please specify `type` and other OpenAPI props using `ZodSchema.openapi`."),this.data=e}}class P{static getMetadata(e){var t;const n=this.unwrapChained(e),s=e._def.openapi?e._def.openapi:n._def.openapi,a=(t=e.description)!==null&&t!==void 0?t:n.description;return{_internal:s==null?void 0:s._internal,metadata:Object.assign({description:a},s==null?void 0:s.metadata)}}static getInternalMetadata(e){const t=this.unwrapChained(e),n=e._def.openapi?e._def.openapi:t._def.openapi;return n==null?void 0:n._internal}static getParamMetadata(e){var t,n;const s=this.unwrapChained(e),a=e._def.openapi?e._def.openapi:s._def.openapi,i=(t=e.description)!==null&&t!==void 0?t:s.description;return{_internal:a==null?void 0:a._internal,metadata:Object.assign(Object.assign({},a==null?void 0:a.metadata),{param:Object.assign({description:i},(n=a==null?void 0:a.metadata)===null||n===void 0?void 0:n.param)})}}static buildSchemaMetadata(e){return _e(jr(e,["param"]),Ae)}static buildParameterMetadata(e){return _e(e,Ae)}static applySchemaMetadata(e,t){return _e(Object.assign(Object.assign({},e),this.buildSchemaMetadata(t)),Ae)}static getRefId(e){var t;return(t=this.getInternalMetadata(e))===null||t===void 0?void 0:t.refId}static unwrapChained(e){return this.unwrapUntil(e)}static getDefaultValue(e){const t=this.unwrapUntil(e,"ZodDefault");return t==null?void 0:t._def.defaultValue()}static unwrapUntil(e,t){return t&&v(e,t)?e:v(e,"ZodOptional")||v(e,"ZodNullable")||v(e,"ZodBranded")?this.unwrapUntil(e.unwrap(),t):v(e,"ZodDefault")||v(e,"ZodReadonly")?this.unwrapUntil(e._def.innerType,t):v(e,"ZodEffects")?this.unwrapUntil(e._def.schema,t):v(e,"ZodPipeline")?this.unwrapUntil(e._def.in,t):t?void 0:e}static isOptionalSchema(e){return v(e,"ZodEffects")?this.isOptionalSchema(e._def.schema):e.isOptional()}}class Cr{transform(e,t,n){var s,a;const i=e._def.type;return Object.assign(Object.assign({},t("array")),{items:n(i),minItems:(s=e._def.minLength)===null||s===void 0?void 0:s.value,maxItems:(a=e._def.maxLength)===null||a===void 0?void 0:a.value})}}class Ir{transform(e){return Object.assign(Object.assign({},e("string")),{pattern:"^d+$"})}}class Pr{transform(e,t,n,s,a){const i=[...e.options.values()],o=i.map(s);return t?{oneOf:n(o,t)}:{oneOf:o,discriminator:this.mapDiscriminator(i,e.discriminator,a)}}mapDiscriminator(e,t,n){if(e.some(a=>P.getRefId(a)===void 0))return;const s={};return e.forEach(a=>{var i;const o=P.getRefId(a),c=(i=a.shape)===null||i===void 0?void 0:i[t];if(v(c,"ZodEnum")||v(c,"ZodNativeEnum")){Object.values(c.enum).filter(Ht).forEach(h=>{s[h]=n(o)});return}const u=c==null?void 0:c._def.value;if(typeof u!="string")throw new Error(`Discriminator ${t} could not be found in one of the values of a discriminated union`);s[u]=n(o)}),{propertyName:t,mapping:s}}}class Zr{transform(e,t){return Object.assign(Object.assign({},t("string")),{enum:e._def.values})}}class Ar{transform(e,t,n,s){const i={allOf:this.flattenIntersectionTypes(e).map(s)};return t?{anyOf:n([i],t)}:i}flattenIntersectionTypes(e){if(!v(e,"ZodIntersection"))return[e];const t=this.flattenIntersectionTypes(e._def.left),n=this.flattenIntersectionTypes(e._def.right);return[...t,...n]}}class Nr{transform(e,t){return Object.assign(Object.assign({},t(typeof e._def.value)),{enum:[e._def.value]})}}function Dr(r){const t=Object.keys(r).filter(a=>typeof r[r[a]]!="number").map(a=>r[a]),n=t.filter(a=>typeof a=="number").length,s=n===0?"string":n===t.length?"numeric":"mixed";return{values:t,type:s}}class Mr{transform(e,t){const{type:n,values:s}=Dr(e._def.values);if(n==="mixed")throw new lt("Enum has mixed string and number values, please specify the OpenAPI type manually");return Object.assign(Object.assign({},t(n==="numeric"?"integer":"string")),{enum:s})}}class $r{transform(e,t,n){return Object.assign(Object.assign({},t(e.isInt?"integer":"number")),n(e._def.checks))}}class Lr{transform(e,t,n,s){var a;const i=(a=P.getInternalMetadata(e))===null||a===void 0?void 0:a.extendedFrom,o=this.requiredKeysOf(e),c=Ne(e._def.shape(),s);if(!i)return Object.assign(Object.assign(Object.assign(Object.assign({},n("object")),{properties:c,default:t}),o.length>0?{required:o}:{}),this.generateAdditionalProperties(e,s));const u=i.schema;s(u);const d=this.requiredKeysOf(u),h=Ne(u==null?void 0:u._def.shape(),s),T=Object.fromEntries(Object.entries(c).filter(([w,D])=>!jt(h[w],D))),S=o.filter(w=>!d.includes(w)),E=Object.assign(Object.assign(Object.assign(Object.assign({},n("object")),{default:t,properties:T}),S.length>0?{required:S}:{}),this.generateAdditionalProperties(e,s));return{allOf:[{$ref:`#/components/schemas/${i.refId}`},E]}}generateAdditionalProperties(e,t){const n=e._def.unknownKeys,s=e._def.catchall;return v(s,"ZodNever")?n==="strict"?{additionalProperties:!1}:{}:{additionalProperties:t(s)}}requiredKeysOf(e){return Object.entries(e._def.shape()).filter(([t,n])=>!P.isOptionalSchema(n)).map(([t,n])=>t)}}class Vr{transform(e,t,n){const s=e._def.valueType,a=e._def.keyType,i=n(s);if(v(a,"ZodEnum")||v(a,"ZodNativeEnum")){const c=Object.values(a.enum).filter(Ht).reduce((u,d)=>Object.assign(Object.assign({},u),{[d]:i}),{});return Object.assign(Object.assign({},t("object")),{properties:c})}return Object.assign(Object.assign({},t("object")),{additionalProperties:i})}}class Ur{transform(e,t){var n,s,a;const i=this.getZodStringCheck(e,"regex"),o=(n=this.getZodStringCheck(e,"length"))===null||n===void 0?void 0:n.value,c=Number.isFinite(e.minLength)&&(s=e.minLength)!==null&&s!==void 0?s:void 0,u=Number.isFinite(e.maxLength)&&(a=e.maxLength)!==null&&a!==void 0?a:void 0;return Object.assign(Object.assign({},t("string")),{minLength:o??c,maxLength:o??u,format:this.mapStringFormat(e),pattern:i==null?void 0:i.regex.source})}mapStringFormat(e){if(e.isUUID)return"uuid";if(e.isEmail)return"email";if(e.isURL)return"uri";if(e.isDatetime)return"date-time"}getZodStringCheck(e,t){return e._def.checks.find(n=>n.kind===t)}}class Hr{constructor(e){this.versionSpecifics=e}transform(e,t,n){const{items:s}=e._def,a=s.map(n);return Object.assign(Object.assign({},t("array")),this.versionSpecifics.mapTupleItems(a))}}class qr{transform(e,t,n){const a=this.flattenUnionTypes(e).map(i=>{const o=this.unwrapNullable(i);return n(o)});return{anyOf:t(a)}}flattenUnionTypes(e){return v(e,"ZodUnion")?e._def.options.flatMap(n=>this.flattenUnionTypes(n)):[e]}unwrapNullable(e){return v(e,"ZodNullable")?this.unwrapNullable(e.unwrap()):e}}class Wr{constructor(e){this.versionSpecifics=e,this.objectTransformer=new Lr,this.stringTransformer=new Ur,this.numberTransformer=new $r,this.bigIntTransformer=new Ir,this.literalTransformer=new Nr,this.enumTransformer=new Zr,this.nativeEnumTransformer=new Mr,this.arrayTransformer=new Cr,this.unionTransformer=new qr,this.discriminatedUnionTransformer=new Pr,this.intersectionTransformer=new Ar,this.recordTransformer=new Vr,this.tupleTransformer=new Hr(e)}transform(e,t,n,s,a){if(v(e,"ZodNull"))return this.versionSpecifics.nullType;if(v(e,"ZodUnknown")||v(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(v(e,"ZodObject"))return this.objectTransformer.transform(e,a,o=>this.versionSpecifics.mapNullableType(o,t),n);const i=this.transformSchemaWithoutDefault(e,t,n,s);return Object.assign(Object.assign({},i),{default:a})}transformSchemaWithoutDefault(e,t,n,s){if(v(e,"ZodUnknown")||v(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(v(e,"ZodString"))return this.stringTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(v(e,"ZodNumber"))return this.numberTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),i=>this.versionSpecifics.getNumberChecks(i));if(v(e,"ZodBigInt"))return this.bigIntTransformer.transform(i=>this.versionSpecifics.mapNullableType(i,t));if(v(e,"ZodBoolean"))return this.versionSpecifics.mapNullableType("boolean",t);if(v(e,"ZodLiteral"))return this.literalTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(v(e,"ZodEnum"))return this.enumTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(v(e,"ZodNativeEnum"))return this.nativeEnumTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(v(e,"ZodArray"))return this.arrayTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),n);if(v(e,"ZodTuple"))return this.tupleTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),n);if(v(e,"ZodUnion"))return this.unionTransformer.transform(e,i=>this.versionSpecifics.mapNullableOfArray(i,t),n);if(v(e,"ZodDiscriminatedUnion"))return this.discriminatedUnionTransformer.transform(e,t,i=>this.versionSpecifics.mapNullableOfArray(i,t),n,s);if(v(e,"ZodIntersection"))return this.intersectionTransformer.transform(e,t,i=>this.versionSpecifics.mapNullableOfArray(i,t),n);if(v(e,"ZodRecord"))return this.recordTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),n);if(v(e,"ZodDate"))return this.versionSpecifics.mapNullableType("string",t);const a=P.getRefId(e);throw new Sr({currentSchema:e._def,schemaName:a})}}class qt{constructor(e,t){this.definitions=e,this.versionSpecifics=t,this.schemaRefs={},this.paramRefs={},this.pathRefs={},this.rawComponents=[],this.openApiTransformer=new Wr(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:s,name:a,component:i})=>{var o;(o=n[s])!==null&&o!==void 0||(n[s]={}),n[s][a]=i}),Object.assign(Object.assign({},n),{schemas:Object.assign(Object.assign({},(e=n.schemas)!==null&&e!==void 0?e:{}),this.schemaRefs),parameters:Object.assign(Object.assign({},(t=n.parameters)!==null&&t!==void 0?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 s=e.findIndex(i=>i===t.type),a=e.findIndex(i=>i===n.type);return s-a})}generateSingle(e){if(!("type"in e)){this.generateSchemaWithRef(e);return}switch(e.type){case"parameter":this.generateParameterDefinition(e.schema);return;case"schema":this.generateSchemaWithRef(e.schema);return;case"route":this.generateSingleRoute(e.route);return;case"component":this.rawComponents.push(e);return}}generateParameterDefinition(e){const t=P.getRefId(e),n=this.generateParameter(e);return t&&(this.paramRefs[t]=n),n}getParameterRef(e,t){var n,s,a,i,o;const c=(n=e==null?void 0:e.metadata)===null||n===void 0?void 0:n.param,u=!((s=e==null?void 0:e._internal)===null||s===void 0)&&s.refId?this.paramRefs[(a=e._internal)===null||a===void 0?void 0:a.refId]:void 0;if(!(!(!((i=e==null?void 0:e._internal)===null||i===void 0)&&i.refId)||!u)){if(c&&u.in!==c.in||t!=null&&t.in&&u.in!==t.in)throw new De(`Conflicting location for parameter ${u.name}`,{key:"in",values:Ut([u.in,t==null?void 0:t.in,c==null?void 0:c.in])});if(c&&u.name!==c.name||t!=null&&t.name&&u.name!==(t==null?void 0:t.name))throw new De("Conflicting names for parameter",{key:"name",values:Ut([u.name,t==null?void 0:t.name,c==null?void 0:c.name])});return{$ref:`#/components/parameters/${(o=e._internal)===null||o===void 0?void 0:o.refId}`}}}generateInlineParameters(e,t){var n;const s=P.getMetadata(e),a=(n=s==null?void 0:s.metadata)===null||n===void 0?void 0:n.param,i=this.getParameterRef(s,{in:t});if(i)return[i];if(v(e,"ZodObject")){const o=e._def.shape();return Object.entries(o).map(([u,d])=>{var h,T;const S=P.getMetadata(d),E=this.getParameterRef(S,{in:t,name:u});if(E)return E;const w=(h=S==null?void 0:S.metadata)===null||h===void 0?void 0:h.param;if(w!=null&&w.name&&w.name!==u)throw new De("Conflicting names for parameter",{key:"name",values:[u,w.name]});if(w!=null&&w.in&&w.in!==t)throw new De(`Conflicting location for parameter ${(T=w.name)!==null&&T!==void 0?T:u}`,{key:"in",values:[t,w.in]});return this.generateParameter(d.openapi({param:{name:u,in:t}}))})}if(a!=null&&a.in&&a.in!==t)throw new De(`Conflicting location for parameter ${a.name}`,{key:"in",values:[t,a.in]});return[this.generateParameter(e.openapi({param:{in:t}}))]}generateSimpleParameter(e){var t;const n=P.getParamMetadata(e),s=(t=n==null?void 0:n.metadata)===null||t===void 0?void 0:t.param,a=!P.isOptionalSchema(e)&&!e.isNullable(),i=this.generateSchemaWithRef(e);return Object.assign({schema:i,required:a},s?P.buildParameterMetadata(s):{})}generateParameter(e){var t;const n=P.getMetadata(e),s=(t=n==null?void 0:n.metadata)===null||t===void 0?void 0:t.param,a=s==null?void 0:s.name,i=s==null?void 0:s.in;if(!a)throw new ht({missingField:"name"});if(!i)throw new ht({missingField:"in",paramName:a});const o=this.generateSimpleParameter(e);return Object.assign(Object.assign({},o),{in:i,name:a})}generateSchemaWithMetadata(e){var t;const n=P.unwrapChained(e),s=P.getMetadata(e),a=P.getDefaultValue(e),i=!((t=s==null?void 0:s.metadata)===null||t===void 0)&&t.type?{type:s==null?void 0:s.metadata.type}:this.toOpenAPISchema(n,e.isNullable(),a);return s!=null&&s.metadata?P.applySchemaMetadata(i,s.metadata):_e(i,Ae)}constructReferencedOpenAPISchema(e){var t;const n=P.getMetadata(e),s=P.unwrapChained(e),a=P.getDefaultValue(e),i=e.isNullable();return!((t=n==null?void 0:n.metadata)===null||t===void 0)&&t.type?this.versionSpecifics.mapNullableType(n.metadata.type,i):this.toOpenAPISchema(s,i,a)}generateSimpleSchema(e){var t;const n=P.getMetadata(e),s=P.getRefId(e);if(!s||!this.schemaRefs[s])return this.generateSchemaWithMetadata(e);const a=this.schemaRefs[s],i={$ref:this.generateSchemaRef(s)},o=_e(P.buildSchemaMetadata((t=n==null?void 0:n.metadata)!==null&&t!==void 0?t:{}),(d,h)=>d===void 0||jt(d,a[h]));if(o.type)return{allOf:[i,o]};const c=_e(this.constructReferencedOpenAPISchema(e),(d,h)=>d===void 0||jt(d,a[h])),u=P.applySchemaMetadata(c,o);return Object.keys(u).length>0?{allOf:[i,u]}:i}generateSchemaWithRef(e){const t=P.getRefId(e),n=this.generateSimpleSchema(e);return t&&this.schemaRefs[t]===void 0?(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=C(e,["content"]),s=this.getBodyContent(t);return Object.assign(Object.assign({},n),{content:s})}getParameters(e){if(!e)return[];const{headers:t}=e,n=this.cleanParameter(e.query),s=this.cleanParameter(e.params),a=this.cleanParameter(e.cookies),i=Me(()=>n?this.generateInlineParameters(n,"query"):[],{location:"query"}),o=Me(()=>s?this.generateInlineParameters(s,"path"):[],{location:"path"}),c=Me(()=>a?this.generateInlineParameters(a,"cookie"):[],{location:"cookie"}),u=Me(()=>{if(Array.isArray(t))return t.flatMap(h=>this.generateInlineParameters(h,"header"));const d=this.cleanParameter(t);return d?this.generateInlineParameters(d,"header"):[]},{location:"header"});return[...o,...i,...u,...c]}cleanParameter(e){if(e)return v(e,"ZodEffects")?this.cleanParameter(e._def.schema):e}generatePath(e){const{method:t,path:n,request:s,responses:a}=e,i=C(e,["method","path","request","responses"]),o=Ne(a,h=>this.getResponse(h)),c=Me(()=>this.getParameters(s),{route:`${t} ${n}`}),u=this.getRequestBody(s==null?void 0:s.body);return{[t]:Object.assign(Object.assign(Object.assign(Object.assign({},i),c.length>0?{parameters:[...i.parameters||[],...c]}:{}),u?{requestBody:u}:{}),{responses:o})}}generateSingleRoute(e){const t=this.generatePath(e);return this.pathRefs[e.path]=Object.assign(Object.assign({},this.pathRefs[e.path]),t),t}getResponse(e){var{content:t,headers:n}=e,s=C(e,["content","headers"]);const a=t?{content:this.getBodyContent(t)}:{};if(!n)return Object.assign(Object.assign({},s),a);const i=v(n,"ZodObject")?this.getResponseHeaders(n):n;return Object.assign(Object.assign(Object.assign({},s),{headers:i}),a)}getResponseHeaders(e){const t=e._def.shape();return Ne(t,s=>this.generateSimpleParameter(s))}getBodyContent(e){return Ne(e,t=>{if(!t||!ut(t.schema))return t;const{schema:n}=t,s=C(t,["schema"]),a=this.generateSchemaWithRef(n);return Object.assign({schema:a},s)})}toOpenAPISchema(e,t,n){return this.openApiTransformer.transform(e,t,s=>this.generateSchemaWithRef(s),s=>this.generateSchemaRef(s),n)}}class Br{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=Rr(e);return{items:t.length===1?t[0]:{anyOf:t},minItems:e.length,maxItems:e.length}}getNumberChecks(e){return Object.assign({},...e.map(t=>{switch(t.kind){case"min":return t.inclusive?{minimum:Number(t.value)}:{minimum:Number(t.value),exclusiveMinimum:!0};case"max":return t.inclusive?{maximum:Number(t.value)}:{maximum:Number(t.value),exclusiveMaximum:!0};default:return{}}}))}}class Fr{constructor(e){const t=new Br;this.generator=new qt(e,t)}generateDocument(e){const t=this.generator.generateDocumentData();return Object.assign(Object.assign({},e),t)}generateComponents(){return this.generator.generateComponents()}}class Gr{get nullType(){return{type:"null"}}mapNullableOfArray(e,t){return t?[...e,this.nullType]:e}mapNullableType(e,t){return e?t?{type:Array.isArray(e)?[...e,"null"]:[e,"null"]}:{type:e}:{}}mapTupleItems(e){return{prefixItems:e}}getNumberChecks(e){return Object.assign({},...e.map(t=>{switch(t.kind){case"min":return t.inclusive?{minimum:Number(t.value)}:{exclusiveMinimum:Number(t.value)};case"max":return t.inclusive?{maximum:Number(t.value)}:{exclusiveMaximum:Number(t.value)};default:return{}}}))}}function Kr(r){return"type"in r&&r.type==="webhook"}class Yr{constructor(e){this.definitions=e,this.webhookRefs={};const t=new Gr;this.generator=new qt(this.definitions,t)}generateDocument(e){const t=this.generator.generateDocumentData();return this.definitions.filter(Kr).forEach(n=>this.generateSingleWebhook(n.webhook)),Object.assign(Object.assign(Object.assign({},e),t),{webhooks:this.webhookRefs})}generateComponents(){return this.generator.generateComponents()}generateSingleWebhook(e){const t=this.generator.generatePath(e);return this.webhookRefs[e.path]=Object.assign(Object.assign({},this.webhookRefs[e.path]),t),t}}var Wt=r=>{const e=r.split("/");return e[0]===""&&e.shift(),e},Qr=r=>{const{groups:e,path:t}=Jr(r),n=Wt(t);return Xr(n,e)},Jr=r=>{const e=[];return r=r.replace(/\{[^}]+\}/g,(t,n)=>{const s=`@${n}`;return e.push([s,t]),s}),{groups:e,path:r}},Xr=(r,e)=>{for(let t=e.length-1;t>=0;t--){const[n]=e[t];for(let s=r.length-1;s>=0;s--)if(r[s].includes(n)){r[s]=r[s].replace(n,e[t][1]);break}}return r},ft={},Bt=r=>{if(r==="*")return"*";const e=r.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);return e?(ft[r]||(e[2]?ft[r]=[r,e[1],new RegExp("^"+e[2]+"$")]:ft[r]=[r,e[1],!0]),ft[r]):null},zr=r=>{try{return decodeURI(r)}catch{return r.replace(/(?:%[0-9A-Fa-f]{2})+/g,e=>{try{return decodeURI(e)}catch{return e}})}},Ft=r=>{const e=r.url,t=e.indexOf("/",8);let n=t;for(;n<e.length;n++){const s=e.charCodeAt(n);if(s===37){const a=e.indexOf("?",n),i=e.slice(t,a===-1?void 0:a);return zr(i.includes("%25")?i.replace(/%25/g,"%2525"):i)}else if(s===63)break}return e.slice(t,n)},en=r=>{const e=Ft(r);return e.length>1&&e[e.length-1]==="/"?e.slice(0,-1):e},fe=(...r)=>{let e="",t=!1;for(let n of r)e[e.length-1]==="/"&&(e=e.slice(0,-1),t=!0),n[0]!=="/"&&(n=`/${n}`),n==="/"&&t?e=`${e}/`:n!=="/"&&(e=`${e}${n}`),n==="/"&&e===""&&(e="/");return e},Gt=r=>{if(!r.match(/\:.+\?$/))return null;const e=r.split("/"),t=[];let n="";return e.forEach(s=>{if(s!==""&&!/\:/.test(s))n+="/"+s;else if(/\:/.test(s))if(/\?/.test(s)){t.length===0&&n===""?t.push("/"):t.push(n);const a=s.replace("?","");n+="/"+a,t.push(n)}else n+="/"+s}),t.filter((s,a,i)=>i.indexOf(s)===a)},Rt=r=>/[%+]/.test(r)?(r.indexOf("+")!==-1&&(r=r.replace(/\+/g," ")),/%/.test(r)?pt(r):r):r,Kt=(r,e,t)=>{let n;if(!t&&e&&!/[%+]/.test(e)){let i=r.indexOf(`?${e}`,8);for(i===-1&&(i=r.indexOf(`&${e}`,8));i!==-1;){const o=r.charCodeAt(i+e.length+1);if(o===61){const c=i+e.length+2,u=r.indexOf("&",c);return Rt(r.slice(c,u===-1?void 0:u))}else if(o==38||isNaN(o))return"";i=r.indexOf(`&${e}`,i+1)}if(n=/[%+]/.test(r),!n)return}const s={};n??(n=/[%+]/.test(r));let a=r.indexOf("?",8);for(;a!==-1;){const i=r.indexOf("&",a+1);let o=r.indexOf("=",a);o>i&&i!==-1&&(o=-1);let c=r.slice(a+1,o===-1?i===-1?void 0:i:o);if(n&&(c=Rt(c)),a=i,c==="")continue;let u;o===-1?u="":(u=r.slice(o+1,i===-1?void 0:i),n&&(u=Rt(u))),t?(s[c]&&Array.isArray(s[c])||(s[c]=[]),s[c].push(u)):s[c]??(s[c]=u)}return e?s[e]:s},tn=Kt,rn=(r,e)=>Kt(r,e,!0),pt=decodeURIComponent,nn=/^[\w!#$%&'*.^`|~+-]+$/,sn=/^[ !#-:<-[\]-~]*$/,an=(r,e)=>r.trim().split(";").reduce((n,s)=>{s=s.trim();const a=s.indexOf("=");if(a===-1)return n;const i=s.substring(0,a).trim();if(!nn.test(i))return n;let o=s.substring(a+1).trim();return o.startsWith('"')&&o.endsWith('"')&&(o=o.slice(1,-1)),sn.test(o)&&(n[i]=pt(o)),n},{}),on=(r,e,t)=>{const n=r.req.raw.headers.get("Cookie");return n?an(n):{}},Et=class extends Error{constructor(e=500,t){super(t==null?void 0:t.message,{cause:t==null?void 0:t.cause});m(this,"res");m(this,"status");this.res=t==null?void 0:t.res,this.status=e}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}},cn=(r,e)=>new Response(r,{headers:{"Content-Type":e}}).formData(),un=(r,e)=>async(t,n)=>{let s={};const a=t.req.header("Content-Type");switch(r){case"json":if(!a||!/^application\/([a-z-\.]+\+)?json/.test(a)){const o=`Invalid HTTP header: Content-Type=${a}`;throw new Et(400,{message:o})}try{s=await t.req.json()}catch{const o="Malformed JSON in request body";throw new Et(400,{message:o})}break;case"form":{if(!a)break;if(t.req.bodyCache.formData){s=await t.req.bodyCache.formData;break}try{const o=await t.req.arrayBuffer(),c=await cn(o,a),u={};c.forEach((d,h)=>{h.endsWith("[]")?u[h]===void 0?u[h]=[d]:Array.isArray(u[h])&&u[h].push(d):u[h]=d}),s=u,t.req.bodyCache.formData=c}catch(o){let c="Malformed FormData request.";throw c+=o instanceof Error?` ${o.message}`:` ${String(o)}`,new Et(400,{message:c})}break}case"query":s=Object.fromEntries(Object.entries(t.req.queries()).map(([o,c])=>c.length===1?[o,c[0]]:[o,c]));break;case"param":s=t.req.param();break;case"header":s=t.req.header();break;case"cookie":s=on(t);break}const i=await e(s,t);if(i instanceof Response)return i;t.req.addValidatedData(r,i),await n()};const be=(r,e,t)=>un(r,async(n,s)=>{const a=await e.safeParseAsync(n);if(t){const i=await t({data:n,...a},s);if(i){if(i instanceof Response)return i;if("response"in i)return i.response}}return a.success?a.data:s.json(a,400)});var dn=async(r,e=Object.create(null))=>{const{all:t=!1,dot:n=!1}=e,a=(r instanceof Yt?r.raw.headers:r.headers).get("Content-Type");return a!==null&&a.startsWith("multipart/form-data")||a!==null&&a.startsWith("application/x-www-form-urlencoded")?ln(r,{all:t,dot:n}):{}};async function ln(r,e){const t=await r.formData();return t?hn(t,e):{}}function hn(r,e){const t=Object.create(null);return r.forEach((n,s)=>{e.all||s.endsWith("[]")?fn(t,s,n):t[s]=n}),e.dot&&Object.entries(t).forEach(([n,s])=>{n.includes(".")&&(pn(t,n,s),delete t[n])}),t}var fn=(r,e,t)=>{r[e]!==void 0?Array.isArray(r[e])?r[e].push(t):r[e]=[r[e],t]:r[e]=t},pn=(r,e,t)=>{let n=r;const s=e.split(".");s.forEach((a,i)=>{i===s.length-1?n[a]=t:((!n[a]||typeof n[a]!="object"||Array.isArray(n[a])||n[a]instanceof File)&&(n[a]=Object.create(null)),n=n[a])})},Yt=(_r=class{constructor(r,e="/",t=[[]]){m(this,"raw");$(this,Ee);$(this,F);m(this,"routeIndex",0);m(this,"path");m(this,"bodyCache",{});m(this,"cachedBody",r=>{const{bodyCache:e,raw:t}=this,n=e[r];if(n)return n;const s=Object.keys(e)[0];return s?e[s].then(a=>(s==="json"&&(a=JSON.stringify(a)),new Response(a)[r]())):e[r]=t[r]()});this.raw=r,this.path=e,R(this,F,t),R(this,Ee,{})}param(r){return r?this.getDecodedParam(r):this.getAllDecodedParams()}getDecodedParam(r){const e=f(this,F)[0][this.routeIndex][1][r],t=this.getParamValue(e);return t?/\%/.test(t)?pt(t):t:void 0}getAllDecodedParams(){const r={},e=Object.keys(f(this,F)[0][this.routeIndex][1]);for(const t of e){const n=this.getParamValue(f(this,F)[0][this.routeIndex][1][t]);n&&typeof n=="string"&&(r[t]=/\%/.test(n)?pt(n):n)}return r}getParamValue(r){return f(this,F)[1]?f(this,F)[1][r]:r}query(r){return tn(this.url,r)}queries(r){return rn(this.url,r)}header(r){if(r)return this.raw.headers.get(r.toLowerCase())??void 0;const e={};return this.raw.headers.forEach((t,n)=>{e[n]=t}),e}async parseBody(r){var e;return(e=this.bodyCache).parsedBody??(e.parsedBody=await dn(this,r))}json(){return this.cachedBody("json")}text(){return this.cachedBody("text")}arrayBuffer(){return this.cachedBody("arrayBuffer")}blob(){return this.cachedBody("blob")}formData(){return this.cachedBody("formData")}addValidatedData(r,e){f(this,Ee)[r]=e}valid(r){return f(this,Ee)[r]}get url(){return this.raw.url}get method(){return this.raw.method}get matchedRoutes(){return f(this,F)[0].map(([[,r]])=>r)}get routePath(){return f(this,F)[0].map(([[,r]])=>r)[this.routeIndex].path}},Ee=new WeakMap,F=new WeakMap,_r),mn={Stringify:1,BeforeStream:2,Stream:3},Qt=async(r,e,t,n,s)=>{const a=r.callbacks;return a!=null&&a.length?(s?s[0]+=r:s=[r],Promise.all(a.map(o=>o({phase:e,buffer:s,context:n}))).then(o=>Promise.all(o.filter(Boolean).map(c=>Qt(c,e,!1,n,s))).then(()=>s[0]))):Promise.resolve(r)},gn="text/plain; charset=UTF-8",St=(r,e={})=>(Object.entries(e).forEach(([t,n])=>r.set(t,n)),r),mt=(br=class{constructor(r,e){$(this,st);$(this,at);m(this,"env",{});$(this,le);m(this,"finalized",!1);m(this,"error");$(this,ve,200);$(this,ne);$(this,A);$(this,N);$(this,G);$(this,se,!0);$(this,it);$(this,Se);$(this,Ce);$(this,ot);$(this,ct);m(this,"render",(...r)=>(f(this,Se)??R(this,Se,e=>this.html(e)),f(this,Se).call(this,...r)));m(this,"setLayout",r=>R(this,it,r));m(this,"getLayout",()=>f(this,it));m(this,"setRenderer",r=>{R(this,Se,r)});m(this,"header",(r,e,t)=>{if(e===void 0){f(this,A)?f(this,A).delete(r):f(this,N)&&delete f(this,N)[r.toLocaleLowerCase()],this.finalized&&this.res.headers.delete(r);return}t!=null&&t.append?(f(this,A)||(R(this,se,!1),R(this,A,new Headers(f(this,N))),R(this,N,{})),f(this,A).append(r,e)):f(this,A)?f(this,A).set(r,e):(f(this,N)??R(this,N,{}),f(this,N)[r.toLowerCase()]=e),this.finalized&&(t!=null&&t.append?this.res.headers.append(r,e):this.res.headers.set(r,e))});m(this,"status",r=>{R(this,se,!1),R(this,ve,r)});m(this,"set",(r,e)=>{f(this,le)??R(this,le,{}),f(this,le)[r]=e});m(this,"get",r=>f(this,le)?f(this,le)[r]:void 0);m(this,"newResponse",(r,e,t)=>{if(f(this,se)&&!t&&!e&&f(this,ve)===200)return new Response(r,{headers:f(this,N)});if(e&&typeof e!="number"){const s=new Headers(e.headers);f(this,A)&&f(this,A).forEach((i,o)=>{o==="set-cookie"?s.append(o,i):s.set(o,i)});const a=St(s,f(this,N));return new Response(r,{headers:a,status:e.status??f(this,ve)})}const n=typeof e=="number"?e:f(this,ve);f(this,N)??R(this,N,{}),f(this,A)??R(this,A,new Headers),St(f(this,A),f(this,N)),f(this,G)&&(f(this,G).headers.forEach((s,a)=>{var i,o;a==="set-cookie"?(i=f(this,A))==null||i.append(a,s):(o=f(this,A))==null||o.set(a,s)}),St(f(this,A),f(this,N))),t??(t={});for(const[s,a]of Object.entries(t))if(typeof a=="string")f(this,A).set(s,a);else{f(this,A).delete(s);for(const i of a)f(this,A).append(s,i)}return new Response(r,{status:n,headers:f(this,A)})});m(this,"body",(r,e,t)=>typeof e=="number"?this.newResponse(r,e,t):this.newResponse(r,e));m(this,"text",(r,e,t)=>{if(!f(this,N)){if(f(this,se)&&!t&&!e)return new Response(r);R(this,N,{})}return f(this,N)["content-type"]=gn,typeof e=="number"?this.newResponse(r,e,t):this.newResponse(r,e)});m(this,"json",(r,e,t)=>{const n=JSON.stringify(r);return f(this,N)??R(this,N,{}),f(this,N)["content-type"]="application/json; charset=UTF-8",typeof e=="number"?this.newResponse(n,e,t):this.newResponse(n,e)});m(this,"html",(r,e,t)=>(f(this,N)??R(this,N,{}),f(this,N)["content-type"]="text/html; charset=UTF-8",typeof r=="object"&&(r instanceof Promise||(r=r.toString()),r instanceof Promise)?r.then(n=>Qt(n,mn.Stringify,!1,{})).then(n=>typeof e=="number"?this.newResponse(n,e,t):this.newResponse(n,e)):typeof e=="number"?this.newResponse(r,e,t):this.newResponse(r,e)));m(this,"redirect",(r,e)=>(f(this,A)??R(this,A,new Headers),f(this,A).set("Location",r),this.newResponse(null,e??302)));m(this,"notFound",()=>(f(this,Ce)??R(this,Ce,()=>new Response),f(this,Ce).call(this,this)));R(this,st,r),e&&(R(this,ne,e.executionCtx),this.env=e.env,R(this,Ce,e.notFoundHandler),R(this,ct,e.path),R(this,ot,e.matchResult))}get req(){return f(this,at)??R(this,at,new Yt(f(this,st),f(this,ct),f(this,ot))),f(this,at)}get event(){if(f(this,ne)&&"respondWith"in f(this,ne))return f(this,ne);throw Error("This context has no FetchEvent")}get executionCtx(){if(f(this,ne))return f(this,ne);throw Error("This context has no ExecutionContext")}get res(){return R(this,se,!1),f(this,G)||R(this,G,new Response("404 Not Found",{status:404}))}set res(r){if(R(this,se,!1),f(this,G)&&r){f(this,G).headers.delete("content-type");for(const[e,t]of f(this,G).headers.entries())if(e==="set-cookie"){const n=f(this,G).headers.getSetCookie();r.headers.delete("set-cookie");for(const s of n)r.headers.append("set-cookie",s)}else r.headers.set(e,t)}R(this,G,r),this.finalized=!0}get var(){return{...f(this,le)}}},st=new WeakMap,at=new WeakMap,le=new WeakMap,ve=new WeakMap,ne=new WeakMap,A=new WeakMap,N=new WeakMap,G=new WeakMap,se=new WeakMap,it=new WeakMap,Se=new WeakMap,Ce=new WeakMap,ot=new WeakMap,ct=new WeakMap,br),Jt=(r,e,t)=>(n,s)=>{let a=-1;return i(0);async function i(o){if(o<=a)throw new Error("next() called multiple times");a=o;let c,u=!1,d;if(r[o]?(d=r[o][0][0],n instanceof mt&&(n.req.routeIndex=o)):d=o===r.length&&s||void 0,!d)n instanceof mt&&n.finalized===!1&&t&&(c=await t(n));else try{c=await d(n,()=>i(o+1))}catch(h){if(h instanceof Error&&n instanceof mt&&e)n.error=h,c=await e(h,n),u=!0;else throw h}return c&&(n.finalized===!1||u)&&(n.res=c),n}},M="ALL",vn="all",yn=["get","post","put","delete","options","patch"],Xt="Can not add a route since the matcher is already built.",zt=class extends Error{},_n=Symbol("composedHandler"),bn=r=>r.text("404 Not Found",404),er=(r,e)=>"getResponse"in r?r.getResponse():(console.error(r),e.text("Internal Server Error",500)),tr=(wr=class{constructor(e={}){m(this,"get");m(this,"post");m(this,"put");m(this,"delete");m(this,"options");m(this,"patch");m(this,"all");m(this,"on");m(this,"use");m(this,"router");m(this,"getPath");m(this,"_basePath","/");$(this,K,"/");m(this,"routes",[]);m(this,"notFoundHandler",bn);m(this,"errorHandler",er);m(this,"onError",e=>(this.errorHandler=e,this));m(this,"notFound",e=>(this.notFoundHandler=e,this));m(this,"fetch",(e,...t)=>this.dispatch(e,t[1],t[0],e.method));m(this,"request",(e,t,n,s)=>{if(e instanceof Request)return t!==void 0&&(e=new Request(e,t)),this.fetch(e,n,s);e=e.toString();const a=/^https?:\/\//.test(e)?e:`http://localhost${fe("/",e)}`,i=new Request(a,t);return this.fetch(i,n,s)});m(this,"fire",()=>{addEventListener("fetch",e=>{e.respondWith(this.dispatch(e.request,e,void 0,e.request.method))})});[...yn,vn].forEach(s=>{this[s]=(a,...i)=>(typeof a=="string"?R(this,K,a):this.addRoute(s,f(this,K),a),i.forEach(o=>{typeof o!="string"&&this.addRoute(s,f(this,K),o)}),this)}),this.on=(s,a,...i)=>{for(const o of[a].flat()){R(this,K,o);for(const c of[s].flat())i.map(u=>{this.addRoute(c.toUpperCase(),f(this,K),u)})}return this},this.use=(s,...a)=>(typeof s=="string"?R(this,K,s):(R(this,K,"*"),a.unshift(s)),a.forEach(i=>{this.addRoute(M,f(this,K),i)}),this);const n=e.strict??!0;delete e.strict,Object.assign(this,e),this.getPath=n?e.getPath??Ft:en}clone(){const e=new tr({router:this.router,getPath:this.getPath});return e.routes=this.routes,e}route(e,t){const n=this.basePath(e);return t.routes.map(s=>{let a;t.errorHandler===er?a=s.handler:(a=async(i,o)=>(await Jt([],t.errorHandler)(i,()=>s.handler(i,o))).res,a[_n]=s.handler),n.addRoute(s.method,s.path,a)}),this}basePath(e){const t=this.clone();return t._basePath=fe(this._basePath,e),t}mount(e,t,n){let s,a;n&&(typeof n=="function"?a=n:(a=n.optionHandler,s=n.replaceRequest));const i=a?c=>{const u=a(c);return Array.isArray(u)?u:[u]}:c=>{let u;try{u=c.executionCtx}catch{}return[c.env,u]};s||(s=(()=>{const c=fe(this._basePath,e),u=c==="/"?0:c.length;return d=>{const h=new URL(d.url);return h.pathname=h.pathname.slice(u)||"/",new Request(h,d)}})());const o=async(c,u)=>{const d=await t(s(c.req.raw),...i(c));if(d)return d;await u()};return this.addRoute(M,fe(e,"*"),o),this}addRoute(e,t,n){e=e.toUpperCase(),t=fe(this._basePath,t);const s={path:t,method:e,handler:n};this.router.add(e,t,[n,s]),this.routes.push(s)}matchRoute(e,t){return this.router.match(e,t)}handleError(e,t){if(e instanceof Error)return this.errorHandler(e,t);throw e}dispatch(e,t,n,s){if(s==="HEAD")return(async()=>new Response(null,await this.dispatch(e,t,n,"GET")))();const a=this.getPath(e,{env:n}),i=this.matchRoute(s,a),o=new mt(e,{path:a,matchResult:i,env:n,executionCtx:t,notFoundHandler:this.notFoundHandler});if(i[0].length===1){let u;try{u=i[0][0][0][0](o,async()=>{o.res=await this.notFoundHandler(o)})}catch(d){return this.handleError(d,o)}return u instanceof Promise?u.then(d=>d||(o.finalized?o.res:this.notFoundHandler(o))).catch(d=>this.handleError(d,o)):u??this.notFoundHandler(o)}const c=Jt(i[0],this.errorHandler,this.notFoundHandler);return(async()=>{try{const u=await c(o);if(!u.finalized)throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return u.res}catch(u){return this.handleError(u,o)}})()}},K=new WeakMap,wr),gt="[^/]+",$e=".*",Le="(?:|/.*)",Ve=Symbol(),wn=new Set(".\\+*[^]$()");function xn(r,e){return r.length===1?e.length===1?r<e?-1:1:-1:e.length===1||r===$e||r===Le?1:e===$e||e===Le?-1:r===gt?1:e===gt?-1:r.length===e.length?r<e?-1:1:e.length-r.length}var Ct=class{constructor(){m(this,"index");m(this,"varIndex");m(this,"children",Object.create(null))}insert(e,t,n,s,a){if(e.length===0){if(this.index!==void 0)throw Ve;if(a)return;this.index=t;return}const[i,...o]=e,c=i==="*"?o.length===0?["","",$e]:["","",gt]:i==="/*"?["","",Le]:i.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);let u;if(c){const d=c[1];let h=c[2]||gt;if(d&&c[2]&&(h=h.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(h)))throw Ve;if(u=this.children[h],!u){if(Object.keys(this.children).some(T=>T!==$e&&T!==Le))throw Ve;if(a)return;u=this.children[h]=new Ct,d!==""&&(u.varIndex=s.varIndex++)}!a&&d!==""&&n.push([d,u.varIndex])}else if(u=this.children[i],!u){if(Object.keys(this.children).some(d=>d.length>1&&d!==$e&&d!==Le))throw Ve;if(a)return;u=this.children[i]=new Ct}u.insert(o,t,n,s,a)}buildRegExpStr(){const t=Object.keys(this.children).sort(xn).map(n=>{const s=this.children[n];return(typeof s.varIndex=="number"?`(${n})@${s.varIndex}`:wn.has(n)?`\\${n}`:n)+s.buildRegExpStr()});return typeof this.index=="number"&&t.unshift(`#${this.index}`),t.length===0?"":t.length===1?t[0]:"(?:"+t.join("|")+")"}},kn=class{constructor(){m(this,"context",{varIndex:0});m(this,"root",new Ct)}insert(r,e,t){const n=[],s=[];for(let i=0;;){let o=!1;if(r=r.replace(/\{[^}]+\}/g,c=>{const u=`@\\${i}`;return s[i]=[u,c],i++,o=!0,u}),!o)break}const a=r.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let i=s.length-1;i>=0;i--){const[o]=s[i];for(let c=a.length-1;c>=0;c--)if(a[c].indexOf(o)!==-1){a[c]=a[c].replace(o,s[i][1]);break}}return this.root.insert(a,e,n,this.context,t),n}buildRegExp(){let r=this.root.buildRegExpStr();if(r==="")return[/^$/,[],[]];let e=0;const t=[],n=[];return r=r.replace(/#(\d+)|@(\d+)|\.\*\$/g,(s,a,i)=>typeof a<"u"?(t[++e]=Number(a),"$()"):(typeof i<"u"&&(n[Number(i)]=++e),"")),[new RegExp(`^${r}`),t,n]}},rr=[],On=[/^$/,[],Object.create(null)],vt=Object.create(null);function nr(r){return vt[r]??(vt[r]=new RegExp(r==="*"?"":`^${r.replace(/\/\*$|([.\\+*[^\]$()])/g,(e,t)=>t?`\\${t}`:"(?:|/.*)")}$`))}function Tn(){vt=Object.create(null)}function jn(r){var u;const e=new kn,t=[];if(r.length===0)return On;const n=r.map(d=>[!/\*|\/:/.test(d[0]),...d]).sort(([d,h],[T,S])=>d?1:T?-1:h.length-S.length),s=Object.create(null);for(let d=0,h=-1,T=n.length;d<T;d++){const[S,E,w]=n[d];S?s[E]=[w.map(([L])=>[L,Object.create(null)]),rr]:h++;let D;try{D=e.insert(E,h,S)}catch(L){throw L===Ve?new zt(E):L}S||(t[h]=w.map(([L,z])=>{const Y=Object.create(null);for(z-=1;z>=0;z--){const[Ie,he]=D[z];Y[Ie]=he}return[L,Y]}))}const[a,i,o]=e.buildRegExp();for(let d=0,h=t.length;d<h;d++)for(let T=0,S=t[d].length;T<S;T++){const E=(u=t[d][T])==null?void 0:u[1];if(!E)continue;const w=Object.keys(E);for(let D=0,L=w.length;D<L;D++)E[w[D]]=o[E[w[D]]]}const c=[];for(const d in i)c[d]=t[i[d]];return[a,c,s]}function we(r,e){if(r){for(const t of Object.keys(r).sort((n,s)=>s.length-n.length))if(nr(t).test(e))return[...r[t]]}}var Rn=class{constructor(){m(this,"name","RegExpRouter");m(this,"middleware");m(this,"routes");this.middleware={[M]:Object.create(null)},this.routes={[M]:Object.create(null)}}add(r,e,t){var o;const{middleware:n,routes:s}=this;if(!n||!s)throw new Error(Xt);n[r]||[n,s].forEach(c=>{c[r]=Object.create(null),Object.keys(c[M]).forEach(u=>{c[r][u]=[...c[M][u]]})}),e==="/*"&&(e="*");const a=(e.match(/\/:/g)||[]).length;if(/\*$/.test(e)){const c=nr(e);r===M?Object.keys(n).forEach(u=>{var d;(d=n[u])[e]||(d[e]=we(n[u],e)||we(n[M],e)||[])}):(o=n[r])[e]||(o[e]=we(n[r],e)||we(n[M],e)||[]),Object.keys(n).forEach(u=>{(r===M||r===u)&&Object.keys(n[u]).forEach(d=>{c.test(d)&&n[u][d].push([t,a])})}),Object.keys(s).forEach(u=>{(r===M||r===u)&&Object.keys(s[u]).forEach(d=>c.test(d)&&s[u][d].push([t,a]))});return}const i=Gt(e)||[e];for(let c=0,u=i.length;c<u;c++){const d=i[c];Object.keys(s).forEach(h=>{var T;(r===M||r===h)&&((T=s[h])[d]||(T[d]=[...we(n[h],d)||we(n[M],d)||[]]),s[h][d].push([t,a-u+c+1]))})}}match(r,e){Tn();const t=this.buildAllMatchers();return this.match=(n,s)=>{const a=t[n]||t[M],i=a[2][s];if(i)return i;const o=s.match(a[0]);if(!o)return[[],rr];const c=o.indexOf("",1);return[a[1][c],o]},this.match(r,e)}buildAllMatchers(){const r=Object.create(null);return[...Object.keys(this.routes),...Object.keys(this.middleware)].forEach(e=>{r[e]||(r[e]=this.buildMatcher(e))}),this.middleware=this.routes=void 0,r}buildMatcher(r){const e=[];let t=r===M;return[this.middleware,this.routes].forEach(n=>{const s=n[r]?Object.keys(n[r]).map(a=>[a,n[r][a]]):[];s.length!==0?(t||(t=!0),e.push(...s)):r!==M&&e.push(...Object.keys(n[M]).map(a=>[a,n[M][a]]))}),t?jn(e):null}},En=class{constructor(r){m(this,"name","SmartRouter");m(this,"routers",[]);m(this,"routes",[]);Object.assign(this,r)}add(r,e,t){if(!this.routes)throw new Error(Xt);this.routes.push([r,e,t])}match(r,e){if(!this.routes)throw new Error("Fatal error");const{routers:t,routes:n}=this,s=t.length;let a=0,i;for(;a<s;a++){const o=t[a];try{n.forEach(c=>{o.add(...c)}),i=o.match(r,e)}catch(c){if(c instanceof zt)continue;throw c}this.match=o.match.bind(o),this.routers=[o],this.routes=void 0;break}if(a===s)throw new Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,i}get activeRouter(){if(this.routes||this.routers.length!==1)throw new Error("No active router has been determined yet.");return this.routers[0]}},sr=class{constructor(r,e,t){m(this,"methods");m(this,"children");m(this,"patterns");m(this,"order",0);m(this,"name");m(this,"params",Object.create(null));if(this.children=t||Object.create(null),this.methods=[],this.name="",r&&e){const n=Object.create(null);n[r]={handler:e,possibleKeys:[],score:0,name:this.name},this.methods=[n]}this.patterns=[]}insert(r,e,t){this.name=`${r} ${e}`,this.order=++this.order;let n=this;const s=Qr(e),a=[];for(let c=0,u=s.length;c<u;c++){const d=s[c];if(Object.keys(n.children).includes(d)){n=n.children[d];const T=Bt(d);T&&a.push(T[1]);continue}n.children[d]=new sr;const h=Bt(d);h&&(n.patterns.push(h),a.push(h[1])),n=n.children[d]}n.methods.length||(n.methods=[]);const i=Object.create(null),o={handler:t,possibleKeys:a.filter((c,u,d)=>d.indexOf(c)===u),name:this.name,score:this.order};return i[r]=o,n.methods.push(i),n}gHSets(r,e,t,n){const s=[];for(let a=0,i=r.methods.length;a<i;a++){const o=r.methods[a],c=o[e]||o[M],u=Object.create(null);c!==void 0&&(c.params=Object.create(null),c.possibleKeys.forEach(d=>{const h=u[c.name];c.params[d]=n[d]&&!h?n[d]:t[d]??n[d],u[c.name]=!0}),s.push(c))}return s}search(r,e){const t=[];this.params=Object.create(null);let s=[this];const a=Wt(e);for(let o=0,c=a.length;o<c;o++){const u=a[o],d=o===c-1,h=[];for(let T=0,S=s.length;T<S;T++){const E=s[T],w=E.children[u];w&&(w.params=E.params,d===!0?(w.children["*"]&&t.push(...this.gHSets(w.children["*"],r,E.params,Object.create(null))),t.push(...this.gHSets(w,r,E.params,Object.create(null)))):h.push(w));for(let D=0,L=E.patterns.length;D<L;D++){const z=E.patterns[D],Y={...E.params};if(z==="*"){const ye=E.children["*"];ye&&(t.push(...this.gHSets(ye,r,E.params,Object.create(null))),h.push(ye));continue}if(u==="")continue;const[Ie,he,ae]=z,ee=E.children[Ie],Pe=a.slice(o).join("/");if(ae instanceof RegExp&&ae.test(Pe)){Y[he]=Pe,t.push(...this.gHSets(ee,r,E.params,Y));continue}(ae===!0||ae instanceof RegExp&&ae.test(u))&&typeof Ie=="string"&&(Y[he]=u,d===!0?(t.push(...this.gHSets(ee,r,Y,E.params)),ee.children["*"]&&t.push(...this.gHSets(ee.children["*"],r,Y,E.params))):(ee.params=Y,h.push(ee)))}}s=h}return[t.sort((o,c)=>o.score-c.score).map(({handler:o,params:c})=>[o,c])]}},Sn=class{constructor(){m(this,"name","TrieRouter");m(this,"node");this.node=new sr}add(r,e,t){const n=Gt(e);if(n){for(const s of n)this.node.insert(r,s,t);return}this.node.insert(r,e,t)}match(r,e){return this.node.search(r,e)}},Cn=class extends tr{constructor(r={}){super(r),this.router=r.router??new En({routers:[new Rn,new Sn]})}},j;(function(r){r.assertEqual=s=>s;function e(s){}r.assertIs=e;function t(s){throw new Error}r.assertNever=t,r.arrayToEnum=s=>{const a={};for(const i of s)a[i]=i;return a},r.getValidEnumValues=s=>{const a=r.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),i={};for(const o of a)i[o]=s[o];return r.objectValues(i)},r.objectValues=s=>r.objectKeys(s).map(function(a){return s[a]}),r.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const a=[];for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&a.push(i);return a},r.find=(s,a)=>{for(const i of s)if(a(i))return i},r.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function n(s,a=" | "){return s.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}r.joinValues=n,r.jsonStringifyReplacer=(s,a)=>typeof a=="bigint"?a.toString():a})(j||(j={}));var It;(function(r){r.mergeShapes=(e,t)=>({...e,...t})})(It||(It={}));const g=j.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ie=r=>{switch(typeof r){case"undefined":return g.undefined;case"string":return g.string;case"number":return isNaN(r)?g.nan:g.number;case"boolean":return g.boolean;case"function":return g.function;case"bigint":return g.bigint;case"symbol":return g.symbol;case"object":return Array.isArray(r)?g.array:r===null?g.null:r.then&&typeof r.then=="function"&&r.catch&&typeof r.catch=="function"?g.promise:typeof Map<"u"&&r instanceof Map?g.map:typeof Set<"u"&&r instanceof Set?g.set:typeof Date<"u"&&r instanceof Date?g.date:g.object;default:return g.unknown}},l=j.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"]),In=r=>JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:");class H extends Error{constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const t=e||function(a){return a.message},n={_errors:[]},s=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(s);else if(i.code==="invalid_return_type")s(i.returnTypeError);else if(i.code==="invalid_arguments")s(i.argumentsError);else if(i.path.length===0)n._errors.push(t(i));else{let o=n,c=0;for(;c<i.path.length;){const u=i.path[c];c===i.path.length-1?(o[u]=o[u]||{_errors:[]},o[u]._errors.push(t(i))):o[u]=o[u]||{_errors:[]},o=o[u],c++}}};return s(this),n}static assert(e){if(!(e instanceof H))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,j.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},n=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):n.push(e(s));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}H.create=r=>new H(r);const xe=(r,e)=>{let t;switch(r.code){case l.invalid_type:r.received===g.undefined?t="Required":t=`Expected ${r.expected}, received ${r.received}`;break;case l.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(r.expected,j.jsonStringifyReplacer)}`;break;case l.unrecognized_keys:t=`Unrecognized key(s) in object: ${j.joinValues(r.keys,", ")}`;break;case l.invalid_union:t="Invalid input";break;case l.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${j.joinValues(r.options)}`;break;case l.invalid_enum_value:t=`Invalid enum value. Expected ${j.joinValues(r.options)}, received '${r.received}'`;break;case l.invalid_arguments:t="Invalid function arguments";break;case l.invalid_return_type:t="Invalid function return type";break;case l.invalid_date:t="Invalid date";break;case l.invalid_string:typeof r.validation=="object"?"includes"in r.validation?(t=`Invalid input: must include "${r.validation.includes}"`,typeof r.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${r.validation.position}`)):"startsWith"in r.validation?t=`Invalid input: must start with "${r.validation.startsWith}"`:"endsWith"in r.validation?t=`Invalid input: must end with "${r.validation.endsWith}"`:j.assertNever(r.validation):r.validation!=="regex"?t=`Invalid ${r.validation}`:t="Invalid";break;case l.too_small:r.type==="array"?t=`Array must contain ${r.exact?"exactly":r.inclusive?"at least":"more than"} ${r.minimum} element(s)`:r.type==="string"?t=`String must contain ${r.exact?"exactly":r.inclusive?"at least":"over"} ${r.minimum} character(s)`:r.type==="number"?t=`Number must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${r.minimum}`:r.type==="date"?t=`Date must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(r.minimum))}`:t="Invalid input";break;case l.too_big:r.type==="array"?t=`Array must contain ${r.exact?"exactly":r.inclusive?"at most":"less than"} ${r.maximum} element(s)`:r.type==="string"?t=`String must contain ${r.exact?"exactly":r.inclusive?"at most":"under"} ${r.maximum} character(s)`:r.type==="number"?t=`Number must be ${r.exact?"exactly":r.inclusive?"less than or equal to":"less than"} ${r.maximum}`:r.type==="bigint"?t=`BigInt must be ${r.exact?"exactly":r.inclusive?"less than or equal to":"less than"} ${r.maximum}`:r.type==="date"?t=`Date must be ${r.exact?"exactly":r.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(r.maximum))}`:t="Invalid input";break;case l.custom:t="Invalid input";break;case l.invalid_intersection_types:t="Intersection results could not be merged";break;case l.not_multiple_of:t=`Number must be a multiple of ${r.multipleOf}`;break;case l.not_finite:t="Number must be finite";break;default:t=e.defaultError,j.assertNever(r)}return{message:t}};let ar=xe;function Pn(r){ar=r}function yt(){return ar}const _t=r=>{const{data:e,path:t,errorMaps:n,issueData:s}=r,a=[...t,...s.path||[]],i={...s,path:a};if(s.message!==void 0)return{...s,path:a,message:s.message};let o="";const c=n.filter(u=>!!u).slice().reverse();for(const u of c)o=u(i,{data:e,defaultError:o}).message;return{...s,path:a,message:o}},Zn=[];function p(r,e){const t=yt(),n=_t({issueData:e,data:r.data,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,t,t===xe?void 0:xe].filter(s=>!!s)});r.common.issues.push(n)}class V{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const s of t){if(s.status==="aborted")return b;s.status==="dirty"&&e.dirty(),n.push(s.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const s of t){const a=await s.key,i=await s.value;n.push({key:a,value:i})}return V.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const s of t){const{key:a,value:i}=s;if(a.status==="aborted"||i.status==="aborted")return b;a.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||s.alwaysSet)&&(n[a.value]=i.value)}return{status:e.value,value:n}}}const b=Object.freeze({status:"aborted"}),ke=r=>({status:"dirty",value:r}),U=r=>({status:"valid",value:r}),Pt=r=>r.status==="aborted",Zt=r=>r.status==="dirty",Ue=r=>r.status==="valid",He=r=>typeof Promise<"u"&&r instanceof Promise;function bt(r,e,t,n){if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(r)}function ir(r,e,t,n,s){if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(r,t),t}typeof SuppressedError=="function"&&SuppressedError;var y;(function(r){r.errToObj=e=>typeof e=="string"?{message:e}:e||{},r.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(y||(y={}));var qe,We;class Q{constructor(e,t,n,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const or=(r,e)=>{if(Ue(e))return{success:!0,data:e.value};if(!r.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 H(r.common.issues);return this._error=t,this._error}}};function x(r){if(!r)return{};const{errorMap:e,invalid_type_error:t,required_error:n,description:s}=r;if(e&&(t||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(i,o)=>{var c,u;const{message:d}=r;return i.code==="invalid_enum_value"?{message:d??o.defaultError}:typeof o.data>"u"?{message:(c=d??n)!==null&&c!==void 0?c:o.defaultError}:i.code!=="invalid_type"?{message:o.defaultError}:{message:(u=d??t)!==null&&u!==void 0?u:o.defaultError}},description:s}}class k{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)}get description(){return this._def.description}_getType(e){return ie(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:ie(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new V,ctx:{common:e.parent.common,data:e.data,parsedType:ie(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(He(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){var n;const s={common:{issues:[],async:(n=t==null?void 0:t.async)!==null&&n!==void 0?n:!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ie(e)},a=this._parseSync({data:e,path:s.path,parent:s});return or(s,a)}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==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:ie(e)},s=this._parse({data:e,path:n.path,parent:n}),a=await(He(s)?s:Promise.resolve(s));return or(n,a)}refine(e,t){const n=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,a)=>{const i=e(s),o=()=>a.addIssue({code:l.custom,...n(s)});return typeof Promise<"u"&&i instanceof Promise?i.then(c=>c?!0:(o(),!1)):i?!0:(o(),!1)})}refinement(e,t){return this._refinement((n,s)=>e(n)?!0:(s.addIssue(typeof t=="function"?t(n,s):t),!1))}_refinement(e){return new B({schema:this,typeName:_.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return X.create(this,this._def)}nullable(){return de.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return W.create(this,this._def)}promise(){return Re.create(this,this._def)}or(e){return Ke.create([this,e],this._def)}and(e){return Ye.create(this,e,this._def)}transform(e){return new B({...x(this._def),schema:this,typeName:_.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new et({...x(this._def),innerType:this,defaultValue:t,typeName:_.ZodDefault})}brand(){return new Dt({typeName:_.ZodBranded,type:this,...x(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new tt({...x(this._def),innerType:this,catchValue:t,typeName:_.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return rt.create(this,e)}readonly(){return nt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const An=/^c[^\s-]{8,}$/i,Nn=/^[0-9a-z]+$/,Dn=/^[0-9A-HJKMNP-TV-Z]{26}$/,Mn=/^[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,$n=/^[a-z0-9_-]{21}$/i,Ln=/^[-+]?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)?)??$/,Vn=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Un="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let At;const Hn=/^(?:(?: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])$/,qn=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,Wn=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,cr="((\\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])))",Bn=new RegExp(`^${cr}$`);function ur(r){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return r.precision?e=`${e}\\.\\d{${r.precision}}`:r.precision==null&&(e=`${e}(\\.\\d+)?`),e}function Fn(r){return new RegExp(`^${ur(r)}$`)}function dr(r){let e=`${cr}T${ur(r)}`;const t=[];return t.push(r.local?"Z?":"Z"),r.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Gn(r,e){return!!((e==="v4"||!e)&&Hn.test(r)||(e==="v6"||!e)&&qn.test(r))}class q extends k{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==g.string){const a=this._getOrReturnCtx(e);return p(a,{code:l.invalid_type,expected:g.string,received:a.parsedType}),b}const n=new V;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),p(s,{code:l.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="max")e.data.length>a.value&&(s=this._getOrReturnCtx(e,s),p(s,{code:l.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="length"){const i=e.data.length>a.value,o=e.data.length<a.value;(i||o)&&(s=this._getOrReturnCtx(e,s),i?p(s,{code:l.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&p(s,{code:l.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),n.dirty())}else if(a.kind==="email")Vn.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"email",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="emoji")At||(At=new RegExp(Un,"u")),At.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"emoji",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="uuid")Mn.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"uuid",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="nanoid")$n.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"nanoid",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid")An.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"cuid",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid2")Nn.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"cuid2",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="ulid")Dn.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"ulid",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),p(s,{validation:"url",code:l.invalid_string,message:a.message}),n.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"regex",code:l.invalid_string,message:a.message}),n.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(s=this._getOrReturnCtx(e,s),p(s,{code:l.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),n.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(s=this._getOrReturnCtx(e,s),p(s,{code:l.invalid_string,validation:{startsWith:a.value},message:a.message}),n.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(s=this._getOrReturnCtx(e,s),p(s,{code:l.invalid_string,validation:{endsWith:a.value},message:a.message}),n.dirty()):a.kind==="datetime"?dr(a).test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{code:l.invalid_string,validation:"datetime",message:a.message}),n.dirty()):a.kind==="date"?Bn.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{code:l.invalid_string,validation:"date",message:a.message}),n.dirty()):a.kind==="time"?Fn(a).test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{code:l.invalid_string,validation:"time",message:a.message}),n.dirty()):a.kind==="duration"?Ln.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"duration",code:l.invalid_string,message:a.message}),n.dirty()):a.kind==="ip"?Gn(e.data,a.version)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"ip",code:l.invalid_string,message:a.message}),n.dirty()):a.kind==="base64"?Wn.test(e.data)||(s=this._getOrReturnCtx(e,s),p(s,{validation:"base64",code:l.invalid_string,message:a.message}),n.dirty()):j.assertNever(a);return{status:n.value,value:e.data}}_regex(e,t,n){return this.refinement(s=>e.test(s),{validation:t,code:l.invalid_string,...y.errToObj(n)})}_addCheck(e){return new q({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...y.errToObj(e)})}url(e){return this._addCheck({kind:"url",...y.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...y.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...y.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...y.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...y.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...y.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...y.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...y.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...y.errToObj(e)})}datetime(e){var t,n;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(t=e==null?void 0:e.offset)!==null&&t!==void 0?t:!1,local:(n=e==null?void 0:e.local)!==null&&n!==void 0?n:!1,...y.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...y.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...y.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...y.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...y.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...y.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...y.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...y.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...y.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...y.errToObj(t)})}nonempty(e){return this.min(1,y.errToObj(e))}trim(){return new q({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new q({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new q({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}q.create=r=>{var e;return new q({checks:[],typeName:_.ZodString,coerce:(e=r==null?void 0:r.coerce)!==null&&e!==void 0?e:!1,...x(r)})};function Kn(r,e){const t=(r.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,s=t>n?t:n,a=parseInt(r.toFixed(s).replace(".","")),i=parseInt(e.toFixed(s).replace(".",""));return a%i/Math.pow(10,s)}class oe extends k{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==g.number){const a=this._getOrReturnCtx(e);return p(a,{code:l.invalid_type,expected:g.number,received:a.parsedType}),b}let n;const s=new V;for(const a of this._def.checks)a.kind==="int"?j.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),p(n,{code:l.invalid_type,expected:"integer",received:"float",message:a.message}),s.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),p(n,{code:l.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),p(n,{code:l.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?Kn(e.data,a.value)!==0&&(n=this._getOrReturnCtx(e,n),p(n,{code:l.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),p(n,{code:l.not_finite,message:a.message}),s.dirty()):j.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,y.toString(t))}gt(e,t){return this.setLimit("min",e,!1,y.toString(t))}lte(e,t){return this.setLimit("max",e,!0,y.toString(t))}lt(e,t){return this.setLimit("max",e,!1,y.toString(t))}setLimit(e,t,n,s){return new oe({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:y.toString(s)}]})}_addCheck(e){return new oe({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:y.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:y.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:y.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:y.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:y.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:y.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:y.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:y.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:y.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&j.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(t===null||n.value>t)&&(t=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(t)&&Number.isFinite(e)}}oe.create=r=>new oe({checks:[],typeName:_.ZodNumber,coerce:(r==null?void 0:r.coerce)||!1,...x(r)});class ce extends k{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==g.bigint){const a=this._getOrReturnCtx(e);return p(a,{code:l.invalid_type,expected:g.bigint,received:a.parsedType}),b}let n;const s=new V;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),p(n,{code:l.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),p(n,{code:l.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),p(n,{code:l.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):j.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,y.toString(t))}gt(e,t){return this.setLimit("min",e,!1,y.toString(t))}lte(e,t){return this.setLimit("max",e,!0,y.toString(t))}lt(e,t){return this.setLimit("max",e,!1,y.toString(t))}setLimit(e,t,n,s){return new ce({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:y.toString(s)}]})}_addCheck(e){return new ce({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:y.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:y.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:y.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:y.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:y.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}ce.create=r=>{var e;return new ce({checks:[],typeName:_.ZodBigInt,coerce:(e=r==null?void 0:r.coerce)!==null&&e!==void 0?e:!1,...x(r)})};class Be extends k{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==g.boolean){const n=this._getOrReturnCtx(e);return p(n,{code:l.invalid_type,expected:g.boolean,received:n.parsedType}),b}return U(e.data)}}Be.create=r=>new Be({typeName:_.ZodBoolean,coerce:(r==null?void 0:r.coerce)||!1,...x(r)});class pe extends k{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==g.date){const a=this._getOrReturnCtx(e);return p(a,{code:l.invalid_type,expected:g.date,received:a.parsedType}),b}if(isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return p(a,{code:l.invalid_date}),b}const n=new V;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),p(s,{code:l.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),n.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(s=this._getOrReturnCtx(e,s),p(s,{code:l.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),n.dirty()):j.assertNever(a);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new pe({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:y.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:y.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}pe.create=r=>new pe({checks:[],coerce:(r==null?void 0:r.coerce)||!1,typeName:_.ZodDate,...x(r)});class wt extends k{_parse(e){if(this._getType(e)!==g.symbol){const n=this._getOrReturnCtx(e);return p(n,{code:l.invalid_type,expected:g.symbol,received:n.parsedType}),b}return U(e.data)}}wt.create=r=>new wt({typeName:_.ZodSymbol,...x(r)});class Fe extends k{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return p(n,{code:l.invalid_type,expected:g.undefined,received:n.parsedType}),b}return U(e.data)}}Fe.create=r=>new Fe({typeName:_.ZodUndefined,...x(r)});class Ge extends k{_parse(e){if(this._getType(e)!==g.null){const n=this._getOrReturnCtx(e);return p(n,{code:l.invalid_type,expected:g.null,received:n.parsedType}),b}return U(e.data)}}Ge.create=r=>new Ge({typeName:_.ZodNull,...x(r)});class Oe extends k{constructor(){super(...arguments),this._any=!0}_parse(e){return U(e.data)}}Oe.create=r=>new Oe({typeName:_.ZodAny,...x(r)});class me extends k{constructor(){super(...arguments),this._unknown=!0}_parse(e){return U(e.data)}}me.create=r=>new me({typeName:_.ZodUnknown,...x(r)});class te extends k{_parse(e){const t=this._getOrReturnCtx(e);return p(t,{code:l.invalid_type,expected:g.never,received:t.parsedType}),b}}te.create=r=>new te({typeName:_.ZodNever,...x(r)});class xt extends k{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return p(n,{code:l.invalid_type,expected:g.void,received:n.parsedType}),b}return U(e.data)}}xt.create=r=>new xt({typeName:_.ZodVoid,...x(r)});class W extends k{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),s=this._def;if(t.parsedType!==g.array)return p(t,{code:l.invalid_type,expected:g.array,received:t.parsedType}),b;if(s.exactLength!==null){const i=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(i||o)&&(p(t,{code:i?l.too_big:l.too_small,minimum:o?s.exactLength.value:void 0,maximum:i?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),n.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(p(t,{code:l.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),n.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(p(t,{code:l.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),n.dirty()),t.common.async)return Promise.all([...t.data].map((i,o)=>s.type._parseAsync(new Q(t,i,t.path,o)))).then(i=>V.mergeArray(n,i));const a=[...t.data].map((i,o)=>s.type._parseSync(new Q(t,i,t.path,o)));return V.mergeArray(n,a)}get element(){return this._def.type}min(e,t){return new W({...this._def,minLength:{value:e,message:y.toString(t)}})}max(e,t){return new W({...this._def,maxLength:{value:e,message:y.toString(t)}})}length(e,t){return new W({...this._def,exactLength:{value:e,message:y.toString(t)}})}nonempty(e){return this.min(1,e)}}W.create=(r,e)=>new W({type:r,minLength:null,maxLength:null,exactLength:null,typeName:_.ZodArray,...x(e)});function Te(r){if(r instanceof Z){const e={};for(const t in r.shape){const n=r.shape[t];e[t]=X.create(Te(n))}return new Z({...r._def,shape:()=>e})}else return r instanceof W?new W({...r._def,type:Te(r.element)}):r instanceof X?X.create(Te(r.unwrap())):r instanceof de?de.create(Te(r.unwrap())):r instanceof J?J.create(r.items.map(e=>Te(e))):r}class Z extends k{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=j.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==g.object){const u=this._getOrReturnCtx(e);return p(u,{code:l.invalid_type,expected:g.object,received:u.parsedType}),b}const{status:n,ctx:s}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof te&&this._def.unknownKeys==="strip"))for(const u in s.data)i.includes(u)||o.push(u);const c=[];for(const u of i){const d=a[u],h=s.data[u];c.push({key:{status:"valid",value:u},value:d._parse(new Q(s,h,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof te){const u=this._def.unknownKeys;if(u==="passthrough")for(const d of o)c.push({key:{status:"valid",value:d},value:{status:"valid",value:s.data[d]}});else if(u==="strict")o.length>0&&(p(s,{code:l.unrecognized_keys,keys:o}),n.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const d of o){const h=s.data[d];c.push({key:{status:"valid",value:d},value:u._parse(new Q(s,h,s.path,d)),alwaysSet:d in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const d of c){const h=await d.key,T=await d.value;u.push({key:h,value:T,alwaysSet:d.alwaysSet})}return u}).then(u=>V.mergeObjectSync(n,u)):V.mergeObjectSync(n,c)}get shape(){return this._def.shape()}strict(e){return y.errToObj,new Z({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,n)=>{var s,a,i,o;const c=(i=(a=(s=this._def).errorMap)===null||a===void 0?void 0:a.call(s,t,n).message)!==null&&i!==void 0?i:n.defaultError;return t.code==="unrecognized_keys"?{message:(o=y.errToObj(e).message)!==null&&o!==void 0?o:c}:{message:c}}}:{}})}strip(){return new Z({...this._def,unknownKeys:"strip"})}passthrough(){return new Z({...this._def,unknownKeys:"passthrough"})}extend(e){return new Z({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new Z({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:_.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new Z({...this._def,catchall:e})}pick(e){const t={};return j.objectKeys(e).forEach(n=>{e[n]&&this.shape[n]&&(t[n]=this.shape[n])}),new Z({...this._def,shape:()=>t})}omit(e){const t={};return j.objectKeys(this.shape).forEach(n=>{e[n]||(t[n]=this.shape[n])}),new Z({...this._def,shape:()=>t})}deepPartial(){return Te(this)}partial(e){const t={};return j.objectKeys(this.shape).forEach(n=>{const s=this.shape[n];e&&!e[n]?t[n]=s:t[n]=s.optional()}),new Z({...this._def,shape:()=>t})}required(e){const t={};return j.objectKeys(this.shape).forEach(n=>{if(e&&!e[n])t[n]=this.shape[n];else{let a=this.shape[n];for(;a instanceof X;)a=a._def.innerType;t[n]=a}}),new Z({...this._def,shape:()=>t})}keyof(){return lr(j.objectKeys(this.shape))}}Z.create=(r,e)=>new Z({shape:()=>r,unknownKeys:"strip",catchall:te.create(),typeName:_.ZodObject,...x(e)}),Z.strictCreate=(r,e)=>new Z({shape:()=>r,unknownKeys:"strict",catchall:te.create(),typeName:_.ZodObject,...x(e)}),Z.lazycreate=(r,e)=>new Z({shape:r,unknownKeys:"strip",catchall:te.create(),typeName:_.ZodObject,...x(e)});class Ke extends k{_parse(e){const{ctx:t}=this._processInputParams(e),n=this._def.options;function s(a){for(const o of a)if(o.result.status==="valid")return o.result;for(const o of a)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const i=a.map(o=>new H(o.ctx.common.issues));return p(t,{code:l.invalid_union,unionErrors:i}),b}if(t.common.async)return Promise.all(n.map(async a=>{const i={...t,common:{...t.common,issues:[]},parent:null};return{result:await a._parseAsync({data:t.data,path:t.path,parent:i}),ctx:i}})).then(s);{let a;const i=[];for(const c of n){const u={...t,common:{...t.common,issues:[]},parent:null},d=c._parseSync({data:t.data,path:t.path,parent:u});if(d.status==="valid")return d;d.status==="dirty"&&!a&&(a={result:d,ctx:u}),u.common.issues.length&&i.push(u.common.issues)}if(a)return t.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(c=>new H(c));return p(t,{code:l.invalid_union,unionErrors:o}),b}}get options(){return this._def.options}}Ke.create=(r,e)=>new Ke({options:r,typeName:_.ZodUnion,...x(e)});const re=r=>r instanceof Je?re(r.schema):r instanceof B?re(r.innerType()):r instanceof Xe?[r.value]:r instanceof ue?r.options:r instanceof ze?j.objectValues(r.enum):r instanceof et?re(r._def.innerType):r instanceof Fe?[void 0]:r instanceof Ge?[null]:r instanceof X?[void 0,...re(r.unwrap())]:r instanceof de?[null,...re(r.unwrap())]:r instanceof Dt||r instanceof nt?re(r.unwrap()):r instanceof tt?re(r._def.innerType):[];class kt extends k{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==g.object)return p(t,{code:l.invalid_type,expected:g.object,received:t.parsedType}),b;const n=this.discriminator,s=t.data[n],a=this.optionsMap.get(s);return a?t.common.async?a._parseAsync({data:t.data,path:t.path,parent:t}):a._parseSync({data:t.data,path:t.path,parent:t}):(p(t,{code:l.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),b)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,n){const s=new Map;for(const a of t){const i=re(a.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of i){if(s.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);s.set(o,a)}}return new kt({typeName:_.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...x(n)})}}function Nt(r,e){const t=ie(r),n=ie(e);if(r===e)return{valid:!0,data:r};if(t===g.object&&n===g.object){const s=j.objectKeys(e),a=j.objectKeys(r).filter(o=>s.indexOf(o)!==-1),i={...r,...e};for(const o of a){const c=Nt(r[o],e[o]);if(!c.valid)return{valid:!1};i[o]=c.data}return{valid:!0,data:i}}else if(t===g.array&&n===g.array){if(r.length!==e.length)return{valid:!1};const s=[];for(let a=0;a<r.length;a++){const i=r[a],o=e[a],c=Nt(i,o);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return t===g.date&&n===g.date&&+r==+e?{valid:!0,data:r}:{valid:!1}}class Ye extends k{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=(a,i)=>{if(Pt(a)||Pt(i))return b;const o=Nt(a.value,i.value);return o.valid?((Zt(a)||Zt(i))&&t.dirty(),{status:t.value,value:o.data}):(p(n,{code:l.invalid_intersection_types}),b)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([a,i])=>s(a,i)):s(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}}Ye.create=(r,e,t)=>new Ye({left:r,right:e,typeName:_.ZodIntersection,...x(t)});class J extends k{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.array)return p(n,{code:l.invalid_type,expected:g.array,received:n.parsedType}),b;if(n.data.length<this._def.items.length)return p(n,{code:l.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),b;!this._def.rest&&n.data.length>this._def.items.length&&(p(n,{code:l.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...n.data].map((i,o)=>{const c=this._def.items[o]||this._def.rest;return c?c._parse(new Q(n,i,n.path,o)):null}).filter(i=>!!i);return n.common.async?Promise.all(a).then(i=>V.mergeArray(t,i)):V.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new J({...this._def,rest:e})}}J.create=(r,e)=>{if(!Array.isArray(r))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new J({items:r,typeName:_.ZodTuple,rest:null,...x(e)})};class Qe extends k{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.object)return p(n,{code:l.invalid_type,expected:g.object,received:n.parsedType}),b;const s=[],a=this._def.keyType,i=this._def.valueType;for(const o in n.data)s.push({key:a._parse(new Q(n,o,n.path,o)),value:i._parse(new Q(n,n.data[o],n.path,o)),alwaysSet:o in n.data});return n.common.async?V.mergeObjectAsync(t,s):V.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,n){return t instanceof k?new Qe({keyType:e,valueType:t,typeName:_.ZodRecord,...x(n)}):new Qe({keyType:q.create(),valueType:e,typeName:_.ZodRecord,...x(t)})}}class Ot extends k{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.map)return p(n,{code:l.invalid_type,expected:g.map,received:n.parsedType}),b;const s=this._def.keyType,a=this._def.valueType,i=[...n.data.entries()].map(([o,c],u)=>({key:s._parse(new Q(n,o,n.path,[u,"key"])),value:a._parse(new Q(n,c,n.path,[u,"value"]))}));if(n.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const c of i){const u=await c.key,d=await c.value;if(u.status==="aborted"||d.status==="aborted")return b;(u.status==="dirty"||d.status==="dirty")&&t.dirty(),o.set(u.value,d.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const c of i){const u=c.key,d=c.value;if(u.status==="aborted"||d.status==="aborted")return b;(u.status==="dirty"||d.status==="dirty")&&t.dirty(),o.set(u.value,d.value)}return{status:t.value,value:o}}}}Ot.create=(r,e,t)=>new Ot({valueType:e,keyType:r,typeName:_.ZodMap,...x(t)});class ge extends k{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.set)return p(n,{code:l.invalid_type,expected:g.set,received:n.parsedType}),b;const s=this._def;s.minSize!==null&&n.data.size<s.minSize.value&&(p(n,{code:l.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&n.data.size>s.maxSize.value&&(p(n,{code:l.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const a=this._def.valueType;function i(c){const u=new Set;for(const d of c){if(d.status==="aborted")return b;d.status==="dirty"&&t.dirty(),u.add(d.value)}return{status:t.value,value:u}}const o=[...n.data.values()].map((c,u)=>a._parse(new Q(n,c,n.path,u)));return n.common.async?Promise.all(o).then(c=>i(c)):i(o)}min(e,t){return new ge({...this._def,minSize:{value:e,message:y.toString(t)}})}max(e,t){return new ge({...this._def,maxSize:{value:e,message:y.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}ge.create=(r,e)=>new ge({valueType:r,minSize:null,maxSize:null,typeName:_.ZodSet,...x(e)});class je extends k{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==g.function)return p(t,{code:l.invalid_type,expected:g.function,received:t.parsedType}),b;function n(o,c){return _t({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,yt(),xe].filter(u=>!!u),issueData:{code:l.invalid_arguments,argumentsError:c}})}function s(o,c){return _t({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,yt(),xe].filter(u=>!!u),issueData:{code:l.invalid_return_type,returnTypeError:c}})}const a={errorMap:t.common.contextualErrorMap},i=t.data;if(this._def.returns instanceof Re){const o=this;return U(async function(...c){const u=new H([]),d=await o._def.args.parseAsync(c,a).catch(S=>{throw u.addIssue(n(c,S)),u}),h=await Reflect.apply(i,this,d);return await o._def.returns._def.type.parseAsync(h,a).catch(S=>{throw u.addIssue(s(h,S)),u})})}else{const o=this;return U(function(...c){const u=o._def.args.safeParse(c,a);if(!u.success)throw new H([n(c,u.error)]);const d=Reflect.apply(i,this,u.data),h=o._def.returns.safeParse(d,a);if(!h.success)throw new H([s(d,h.error)]);return h.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new je({...this._def,args:J.create(e).rest(me.create())})}returns(e){return new je({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,n){return new je({args:e||J.create([]).rest(me.create()),returns:t||me.create(),typeName:_.ZodFunction,...x(n)})}}class Je extends k{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Je.create=(r,e)=>new Je({getter:r,typeName:_.ZodLazy,...x(e)});class Xe extends k{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return p(t,{received:t.data,code:l.invalid_literal,expected:this._def.value}),b}return{status:"valid",value:e.data}}get value(){return this._def.value}}Xe.create=(r,e)=>new Xe({value:r,typeName:_.ZodLiteral,...x(e)});function lr(r,e){return new ue({values:r,typeName:_.ZodEnum,...x(e)})}class ue extends k{constructor(){super(...arguments),qe.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),n=this._def.values;return p(t,{expected:j.joinValues(n),received:t.parsedType,code:l.invalid_type}),b}if(bt(this,qe)||ir(this,qe,new Set(this._def.values)),!bt(this,qe).has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return p(t,{received:t.data,code:l.invalid_enum_value,options:n}),b}return U(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return ue.create(e,{...this._def,...t})}exclude(e,t=this._def){return ue.create(this.options.filter(n=>!e.includes(n)),{...this._def,...t})}}qe=new WeakMap,ue.create=lr;class ze extends k{constructor(){super(...arguments),We.set(this,void 0)}_parse(e){const t=j.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==g.string&&n.parsedType!==g.number){const s=j.objectValues(t);return p(n,{expected:j.joinValues(s),received:n.parsedType,code:l.invalid_type}),b}if(bt(this,We)||ir(this,We,new Set(j.getValidEnumValues(this._def.values))),!bt(this,We).has(e.data)){const s=j.objectValues(t);return p(n,{received:n.data,code:l.invalid_enum_value,options:s}),b}return U(e.data)}get enum(){return this._def.values}}We=new WeakMap,ze.create=(r,e)=>new ze({values:r,typeName:_.ZodNativeEnum,...x(e)});class Re extends k{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==g.promise&&t.common.async===!1)return p(t,{code:l.invalid_type,expected:g.promise,received:t.parsedType}),b;const n=t.parsedType===g.promise?t.data:Promise.resolve(t.data);return U(n.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Re.create=(r,e)=>new Re({type:r,typeName:_.ZodPromise,...x(e)});class B extends k{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===_.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=this._def.effect||null,a={addIssue:i=>{p(n,i),i.fatal?t.abort():t.dirty()},get path(){return n.path}};if(a.addIssue=a.addIssue.bind(a),s.type==="preprocess"){const i=s.transform(n.data,a);if(n.common.async)return Promise.resolve(i).then(async o=>{if(t.value==="aborted")return b;const c=await this._def.schema._parseAsync({data:o,path:n.path,parent:n});return c.status==="aborted"?b:c.status==="dirty"||t.value==="dirty"?ke(c.value):c});{if(t.value==="aborted")return b;const o=this._def.schema._parseSync({data:i,path:n.path,parent:n});return o.status==="aborted"?b:o.status==="dirty"||t.value==="dirty"?ke(o.value):o}}if(s.type==="refinement"){const i=o=>{const c=s.refinement(o,a);if(n.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(n.common.async===!1){const o=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return o.status==="aborted"?b:(o.status==="dirty"&&t.dirty(),i(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(o=>o.status==="aborted"?b:(o.status==="dirty"&&t.dirty(),i(o.value).then(()=>({status:t.value,value:o.value}))))}if(s.type==="transform")if(n.common.async===!1){const i=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!Ue(i))return i;const o=s.transform(i.value,a);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(i=>Ue(i)?Promise.resolve(s.transform(i.value,a)).then(o=>({status:t.value,value:o})):i);j.assertNever(s)}}B.create=(r,e,t)=>new B({schema:r,typeName:_.ZodEffects,effect:e,...x(t)}),B.createWithPreprocess=(r,e,t)=>new B({schema:e,effect:{type:"preprocess",transform:r},typeName:_.ZodEffects,...x(t)});class X extends k{_parse(e){return this._getType(e)===g.undefined?U(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}X.create=(r,e)=>new X({innerType:r,typeName:_.ZodOptional,...x(e)});class de extends k{_parse(e){return this._getType(e)===g.null?U(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}de.create=(r,e)=>new de({innerType:r,typeName:_.ZodNullable,...x(e)});class et extends k{_parse(e){const{ctx:t}=this._processInputParams(e);let n=t.data;return t.parsedType===g.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}et.create=(r,e)=>new et({innerType:r,typeName:_.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...x(e)});class tt extends k{_parse(e){const{ctx:t}=this._processInputParams(e),n={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return He(s)?s.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new H(n.common.issues)},input:n.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new H(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}tt.create=(r,e)=>new tt({innerType:r,typeName:_.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...x(e)});class Tt extends k{_parse(e){if(this._getType(e)!==g.nan){const n=this._getOrReturnCtx(e);return p(n,{code:l.invalid_type,expected:g.nan,received:n.parsedType}),b}return{status:"valid",value:e.data}}}Tt.create=r=>new Tt({typeName:_.ZodNaN,...x(r)});const Yn=Symbol("zod_brand");class Dt extends k{_parse(e){const{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}}class rt extends k{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return a.status==="aborted"?b:a.status==="dirty"?(t.dirty(),ke(a.value)):this._def.out._parseAsync({data:a.value,path:n.path,parent:n})})();{const s=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return s.status==="aborted"?b:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:n.path,parent:n})}}static create(e,t){return new rt({in:e,out:t,typeName:_.ZodPipeline})}}class nt extends k{_parse(e){const t=this._def.innerType._parse(e),n=s=>(Ue(s)&&(s.value=Object.freeze(s.value)),s);return He(t)?t.then(s=>n(s)):n(t)}unwrap(){return this._def.innerType}}nt.create=(r,e)=>new nt({innerType:r,typeName:_.ZodReadonly,...x(e)});function hr(r,e={},t){return r?Oe.create().superRefine((n,s)=>{var a,i;if(!r(n)){const o=typeof e=="function"?e(n):typeof e=="string"?{message:e}:e,c=(i=(a=o.fatal)!==null&&a!==void 0?a:t)!==null&&i!==void 0?i:!0,u=typeof o=="string"?{message:o}:o;s.addIssue({code:"custom",...u,fatal:c})}}):Oe.create()}const Qn={object:Z.lazycreate};var _;(function(r){r.ZodString="ZodString",r.ZodNumber="ZodNumber",r.ZodNaN="ZodNaN",r.ZodBigInt="ZodBigInt",r.ZodBoolean="ZodBoolean",r.ZodDate="ZodDate",r.ZodSymbol="ZodSymbol",r.ZodUndefined="ZodUndefined",r.ZodNull="ZodNull",r.ZodAny="ZodAny",r.ZodUnknown="ZodUnknown",r.ZodNever="ZodNever",r.ZodVoid="ZodVoid",r.ZodArray="ZodArray",r.ZodObject="ZodObject",r.ZodUnion="ZodUnion",r.ZodDiscriminatedUnion="ZodDiscriminatedUnion",r.ZodIntersection="ZodIntersection",r.ZodTuple="ZodTuple",r.ZodRecord="ZodRecord",r.ZodMap="ZodMap",r.ZodSet="ZodSet",r.ZodFunction="ZodFunction",r.ZodLazy="ZodLazy",r.ZodLiteral="ZodLiteral",r.ZodEnum="ZodEnum",r.ZodEffects="ZodEffects",r.ZodNativeEnum="ZodNativeEnum",r.ZodOptional="ZodOptional",r.ZodNullable="ZodNullable",r.ZodDefault="ZodDefault",r.ZodCatch="ZodCatch",r.ZodPromise="ZodPromise",r.ZodBranded="ZodBranded",r.ZodPipeline="ZodPipeline",r.ZodReadonly="ZodReadonly"})(_||(_={}));const Jn=(r,e={message:`Input not instance of ${r.name}`})=>hr(t=>t instanceof r,e),fr=q.create,pr=oe.create,Xn=Tt.create,zn=ce.create,mr=Be.create,es=pe.create,ts=wt.create,rs=Fe.create,ns=Ge.create,ss=Oe.create,as=me.create,is=te.create,os=xt.create,cs=W.create,us=Z.create,ds=Z.strictCreate,ls=Ke.create,hs=kt.create,fs=Ye.create,ps=J.create,ms=Qe.create,gs=Ot.create,vs=ge.create,ys=je.create,_s=Je.create,bs=Xe.create,ws=ue.create,xs=ze.create,ks=Re.create,gr=B.create,Os=X.create,Ts=de.create,js=B.createWithPreprocess,Rs=rt.create;var O=Object.freeze({__proto__:null,defaultErrorMap:xe,setErrorMap:Pn,getErrorMap:yt,makeIssue:_t,EMPTY_PATH:Zn,addIssueToContext:p,ParseStatus:V,INVALID:b,DIRTY:ke,OK:U,isAborted:Pt,isDirty:Zt,isValid:Ue,isAsync:He,get util(){return j},get objectUtil(){return It},ZodParsedType:g,getParsedType:ie,ZodType:k,datetimeRegex:dr,ZodString:q,ZodNumber:oe,ZodBigInt:ce,ZodBoolean:Be,ZodDate:pe,ZodSymbol:wt,ZodUndefined:Fe,ZodNull:Ge,ZodAny:Oe,ZodUnknown:me,ZodNever:te,ZodVoid:xt,ZodArray:W,ZodObject:Z,ZodUnion:Ke,ZodDiscriminatedUnion:kt,ZodIntersection:Ye,ZodTuple:J,ZodRecord:Qe,ZodMap:Ot,ZodSet:ge,ZodFunction:je,ZodLazy:Je,ZodLiteral:Xe,ZodEnum:ue,ZodNativeEnum:ze,ZodPromise:Re,ZodEffects:B,ZodTransformer:B,ZodOptional:X,ZodNullable:de,ZodDefault:et,ZodCatch:tt,ZodNaN:Tt,BRAND:Yn,ZodBranded:Dt,ZodPipeline:rt,ZodReadonly:nt,custom:hr,Schema:k,ZodSchema:k,late:Qn,get ZodFirstPartyTypeKind(){return _},coerce:{string:r=>q.create({...r,coerce:!0}),number:r=>oe.create({...r,coerce:!0}),boolean:r=>Be.create({...r,coerce:!0}),bigint:r=>ce.create({...r,coerce:!0}),date:r=>pe.create({...r,coerce:!0})},any:ss,array:cs,bigint:zn,boolean:mr,date:es,discriminatedUnion:hs,effect:gr,enum:ws,function:ys,instanceof:Jn,intersection:fs,lazy:_s,literal:bs,map:gs,nan:Xn,nativeEnum:xs,never:is,null:ns,nullable:Ts,number:pr,object:us,oboolean:()=>mr().optional(),onumber:()=>pr().optional(),optional:Os,ostring:()=>fr().optional(),pipeline:Rs,preprocess:js,promise:ks,record:ms,set:vs,strictObject:ds,string:fr,symbol:ts,transformer:gr,tuple:ps,undefined:rs,union:ls,unknown:as,void:os,NEVER:b,ZodIssueCode:l,quotelessJson:In,ZodError:H}),Mt=class Vt extends Cn{constructor(t){super(t);m(this,"openAPIRegistry");m(this,"defaultHook");m(this,"openapi",({middleware:t,...n},s,a=this.defaultHook)=>{var u,d,h,T,S,E;this.openAPIRegistry.registerPath(n);const i=[];if((u=n.request)!=null&&u.query){const w=be("query",n.request.query,a);i.push(w)}if((d=n.request)!=null&&d.params){const w=be("param",n.request.params,a);i.push(w)}if((h=n.request)!=null&&h.headers){const w=be("header",n.request.headers,a);i.push(w)}if((T=n.request)!=null&&T.cookies){const w=be("cookie",n.request.cookies,a);i.push(w)}const o=(E=(S=n.request)==null?void 0:S.body)==null?void 0:E.content;if(o)for(const w of Object.keys(o)){if(!o[w])continue;const D=o[w].schema;if(D instanceof k){if(w.startsWith("application/json")){const L=be("json",D,a);i.push(L)}if(w.startsWith("multipart/form-data")||w.startsWith("application/x-www-form-urlencoded")){const L=be("form",D,a);i.push(L)}}}const c=t?Array.isArray(t)?t:[t]:[];return this.on([n.method],n.path.replaceAll(/\/{(.+?)}/g,"/:$1"),...c,...i,s),this});m(this,"getOpenAPIDocument",t=>new Fr(this.openAPIRegistry.definitions).generateDocument(t));m(this,"getOpenAPI31Document",t=>new Yr(this.openAPIRegistry.definitions).generateDocument(t));m(this,"doc",(t,n)=>this.get(t,s=>{const a=typeof n=="function"?n(s):n;try{const i=this.getOpenAPIDocument(a);return s.json(i)}catch(i){return s.json(i,500)}}));m(this,"doc31",(t,n)=>this.get(t,s=>{const a=typeof n=="function"?n(s):n;try{const i=this.getOpenAPI31Document(a);return s.json(i)}catch(i){return s.json(i,500)}}));this.openAPIRegistry=new Er,this.defaultHook=t==null?void 0:t.defaultHook}route(t,n){const s=t.replaceAll(/:([^\/]+)/g,"{$1}");return super.route(t,n),n instanceof Vt?(n.openAPIRegistry.definitions.forEach(a=>{switch(a.type){case"component":return this.openAPIRegistry.registerComponent(a.componentType,a.name,a.component);case"route":return this.openAPIRegistry.registerPath({...a.route,path:fe(s,a.route.path)});case"webhook":return this.openAPIRegistry.registerWebhook({...a.webhook,path:fe(s,a.webhook.path)});case"schema":return this.openAPIRegistry.register(a.schema._def.openapi._internal.refId,a.schema);case"parameter":return this.openAPIRegistry.registerParameter(a.schema._def.openapi._internal.refId,a.schema);default:{const i=a;throw new Error(`Unknown registry type: ${i}`)}}}),this):this}basePath(t){return new Vt({...super.basePath(t),defaultHook:this.defaultHook})}},vr=r=>{const e={...r,getRoutingPath(){return r.path.replaceAll(/\/{(.+?)}/g,"/:$1")}};return Object.defineProperty(e,"getRoutingPath",{enumerable:!1})};Or(O);const Es=O.object({alg:O.string(),e:O.string(),kid:O.string(),kty:O.string(),n:O.string(),use:O.string().optional()}),Ss=O.object({keys:O.array(Es)}),yr=O.object({issuer:O.string(),authorization_endpoint:O.string(),token_endpoint:O.string(),device_authorization_endpoint:O.string(),userinfo_endpoint:O.string(),mfa_challenge_endpoint:O.string(),jwks_uri:O.string(),registration_endpoint:O.string(),revocation_endpoint:O.string(),scopes_supported:O.array(O.string()),response_types_supported:O.array(O.string()),code_challenge_methods_supported:O.array(O.string()),response_modes_supported:O.array(O.string()),subject_types_supported:O.array(O.string()),id_token_signing_alg_values_supported:O.array(O.string()),token_endpoint_auth_methods_supported:O.array(O.string()),claims_supported:O.array(O.string()),request_uri_parameter_supported:O.boolean(),request_parameter_supported:O.boolean(),token_endpoint_auth_signing_alg_values_supported:O.array(O.string())}),Cs=new Mt().openapi(vr({tags:["jwks"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:Ss}},description:"List of tenants"}}}),async r=>{const{env:e}=r,t=[{alg:"RS256",e:"AQAB",kid:"hZ42TWGWLdmyKfwGVA6c2",kty:"RSA",n:"nUd-mktFZQNfVwmXufxcVcvJo6Lkb-jDuymtfQunmEhWCctOccWx9e7LX7_9uN15ZnRS7XJInPMRs9KLYdZ0GCnE2HM_QbrEoHpdkCRgyTE-KzmoaEv_AOVGE_Kg0-0ct3r9Z7aJLDVAsxXl1C9y8Gr7ZYkq0c4DyZr9VT8nQiwZQERbfxXdXw-5RLj21S_Lm-LL-AjKvry_TDBLpfUFJV18SVsM07lY_V45TwykNewRdaGLspFIeGdG5j5eByV8ifzBqvzOSptSCsmOTtW-ceWUk0FPD7g_KKzjjbzenoB0TC8mBb_4vWZlHnuGIAs2YoTFglp9uNu7t_OVl3Svo6ZE6alzUnaNfZNeAi78KPHYQ4tDWPjpYNfGynsiD0nojkDSPCIak56jWNYjj614cPEBiv9MVQRiSbBxpiGhMoHlW_QCCPMcXygLAaRs_tUksqoH4QB80krifG2yHPgGDPjXK1_0cYzV80iOcQIeoceqhkSSc6YxzzgDrQcsV2k3bizRQSL83GWkpdHhTZn-Q_JzsW_bDY_f9fjigYbRnoDSgS7038VFIPc92StE41MdgvIQMomcyEE4lYK1uv1Mo6cnXbCZhm8tvddo7VKNorOB4nsiv8DGrWPlzQBca9VN4C1oE2mH-3WLFR7XEkBHWVouOdTWM2S3K9F10YtahkM"}];return r.json({keys:t},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${e.JWKS_CACHE_TIMEOUT_IN_SECONDS}, stale-while-revalidate=${e.JWKS_CACHE_TIMEOUT_IN_SECONDS*2}, stale-if-error=86400`}})}).openapi(vr({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:yr}},description:"List of tenants"}}}),async r=>{const{env:e}=r,{ISSUER:t}=e,n=yr.parse({issuer:t,authorization_endpoint:`${t}authorize`,token_endpoint:`${t}oauth/token`,device_authorization_endpoint:`${t}oauth/device/code`,userinfo_endpoint:`${t}userinfo`,mfa_challenge_endpoint:`${t}mfa/challenge`,jwks_uri:`${t}.well-known/jwks.json`,registration_endpoint:`${t}oidc/register`,revocation_endpoint:`${t}oauth/revoke`,scopes_supported:["openid","profile","offline_access","name","given_name","family_name","nickname","email","email_verified","picture","created_at","identities","phone","address"],response_types_supported:["code","token","id_token","code token","code id_token","token id_token","code token id_token"],code_challenge_methods_supported:["S256","plain"],response_modes_supported:["query","fragment","form_post"],subject_types_supported:["public"],id_token_signing_alg_values_supported:["HS256","RS256"],token_endpoint_auth_methods_supported:["client_secret_basic","client_secret_post","private_key_jwt"],claims_supported:["aud","auth_time","created_at","email","email_verified","exp","family_name","given_name","iat","identities","iss","name","nickname","phone_number","picture","sub"],request_uri_parameter_supported:!1,request_parameter_supported:!1,token_endpoint_auth_signing_alg_values_supported:["RS256","RS384","PS256"]});return r.json(n,{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${e.JWKS_CACHE_TIMEOUT_IN_SECONDS}, stale-while-revalidate=${e.JWKS_CACHE_TIMEOUT_IN_SECONDS*2}, stale-if-error=86400`}})});function Is(){const r=new Mt;r.get("/",t=>t.text("Hello, authhero!"));const e=new Mt().route("/.well-known",Cs);return e.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Oauth endpoints"}}),r.route("/",e),r}return I.init=Is,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"}),I}({});
1
+ var authhero=function(V){"use strict";var Qo=Object.defineProperty;var ds=V=>{throw TypeError(V)};var Xo=(V,L,k)=>L in V?Qo(V,L,{enumerable:!0,configurable:!0,writable:!0,value:k}):V[L]=k;var y=(V,L,k)=>Xo(V,typeof L!="symbol"?L+"":L,k),us=(V,L,k)=>L.has(V)||ds("Cannot "+k);var m=(V,L,k)=>(us(V,L,"read from private field"),k?k.call(V):L.get(V)),Y=(V,L,k)=>L.has(V)?ds("Cannot add the same private member more than once"):L instanceof WeakSet?L.add(V):L.set(V,k),M=(V,L,k,fn)=>(us(V,L,"write to private field"),fn?fn.call(V,k):L.set(V,k),k);var mt,fe,is,dn,un,Ue,Je,Re,W,F,me,Ee,ln,gt,_t,pn,hn,os,ge,cs;function L(n,e){var t={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(n);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(n,r[s])&&(t[r[s]]=n[r[s]]);return t}typeof SuppressedError=="function"&&SuppressedError;function k(n,e){var t;return((t=n==null?void 0:n._def)===null||t===void 0?void 0:t.typeName)===e}function fn(n){return"_def"in n}function yt(n,e){const t=n.ZodType.prototype[e];n.ZodType.prototype[e]=function(...r){const s=t.apply(this,r);return s._def.openapi=this._def.openapi,s}}function ls(n){if(typeof n.ZodType.prototype.openapi<"u")return;n.ZodType.prototype.openapi=function(s,a){var i,o,d,u,l,p;const C=typeof s=="string"?a:s,D=C??{},{param:N}=D,R=L(D,["param"]),H=Object.assign(Object.assign({},(i=this._def.openapi)===null||i===void 0?void 0:i._internal),typeof s=="string"?{refId:s}:void 0),K=Object.assign(Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o.metadata),R),!((u=(d=this._def.openapi)===null||d===void 0?void 0:d.metadata)===null||u===void 0)&&u.param||N?{param:Object.assign(Object.assign({},(p=(l=this._def.openapi)===null||l===void 0?void 0:l.metadata)===null||p===void 0?void 0:p.param),N)}:void 0),se=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(K).length>0?{metadata:K}:void 0)}));if(k(this,"ZodObject")){const ae=this.extend;se.extend=function(...qe){var oe,ie,te,Oe,_e,Qe;const Xe=ae.apply(this,qe);return Xe._def.openapi={_internal:{extendedFrom:!((ie=(oe=this._def.openapi)===null||oe===void 0?void 0:oe._internal)===null||ie===void 0)&&ie.refId?{refId:(Oe=(te=this._def.openapi)===null||te===void 0?void 0:te._internal)===null||Oe===void 0?void 0:Oe.refId,schema:this}:(_e=this._def.openapi)===null||_e===void 0?void 0:_e._internal.extendedFrom},metadata:(Qe=Xe._def.openapi)===null||Qe===void 0?void 0:Qe.metadata},Xe}}return se},yt(n,"optional"),yt(n,"nullable"),yt(n,"default"),yt(n,"transform"),yt(n,"refine");const e=n.ZodObject.prototype.deepPartial;n.ZodObject.prototype.deepPartial=function(){const s=this._def.shape(),a=e.apply(this),i=a._def.shape();return Object.entries(i).forEach(([o,d])=>{var u,l;d._def.openapi=(l=(u=s[o])===null||u===void 0?void 0:u._def)===null||l===void 0?void 0:l.openapi}),a._def.openapi=void 0,a};const t=n.ZodObject.prototype.pick;n.ZodObject.prototype.pick=function(...s){const a=t.apply(this,s);return a._def.openapi=void 0,a};const r=n.ZodObject.prototype.omit;n.ZodObject.prototype.omit=function(...s){const a=r.apply(this,s);return a._def.openapi=void 0,a}}function mn(n,e){if(n==null||e===null||e===void 0)return n===e;if(n===e||n.valueOf()===e.valueOf())return!0;if(Array.isArray(n)&&(!Array.isArray(e)||n.length!==e.length)||!(n instanceof Object)||!(e instanceof Object))return!1;const t=Object.keys(n);return Object.keys(e).every(r=>t.indexOf(r)!==-1)&&t.every(r=>mn(n[r],e[r]))}class ps{constructor(){this.buckets=new Map}put(e){const t=this.hashCodeOf(e),r=this.buckets.get(t);if(!r){this.buckets.set(t,[e]);return}r.some(a=>mn(a,e))||r.push(e)}contains(e){const t=this.hashCodeOf(e),r=this.buckets.get(t);return r?r.some(s=>mn(s,e)):!1}values(){return[...this.buckets.values()].flat()}stats(){let e=0,t=0,r=0;for(const a of this.buckets.values())e+=1,t+=a.length,a.length>1&&(r+=1);const s=e/t;return{totalBuckets:e,collisions:r,totalValues:t,hashEffectiveness:s}}hashCodeOf(e){let t=0;if(Array.isArray(e)){for(let r=0;r<e.length;r++)t^=this.hashCodeOf(e[r])*r;return t}if(typeof e=="string"){for(let r=0;r<e.length;r++)t^=e.charCodeAt(r)*r;return t}if(typeof e=="number")return e;if(typeof e=="object")for(const[r,s]of Object.entries(e))t^=this.hashCodeOf(r)+this.hashCodeOf(s??"");return t}}function vt(n){return n==null}function bt(n,e){const t={};return Object.entries(n).forEach(([r,s])=>{t[r]=e(s)}),t}function hs(n,e){const t={};return Object.entries(n).forEach(([r,s])=>{e.some(a=>a===r)||(t[r]=s)}),t}function et(n,e){const t={};return Object.entries(n).forEach(([r,s])=>{e(s,r)||(t[r]=s)}),t}function dr(n){return n.filter(e=>!vt(e))}const Bn=mn;function fs(n){const e=new ps;return n.forEach(t=>e.put(t)),[...e.values()]}function ur(n){return typeof n=="string"}class ms{constructor(e){this.parents=e,this._definitions=[]}get definitions(){var e,t;return[...(t=(e=this.parents)===null||e===void 0?void 0:e.flatMap(s=>s.definitions))!==null&&t!==void 0?t:[],...this._definitions]}register(e,t){const r=this.schemaWithRefId(e,t);return this._definitions.push({type:"schema",schema:r}),r}registerParameter(e,t){var r,s,a;const i=this.schemaWithRefId(e,t),o=(r=i._def.openapi)===null||r===void 0?void 0:r.metadata,d=i.openapi(Object.assign(Object.assign({},o),{param:Object.assign(Object.assign({},o==null?void 0:o.param),{name:(a=(s=o==null?void 0:o.param)===null||s===void 0?void 0:s.name)!==null&&a!==void 0?a:e})}));return this._definitions.push({type:"parameter",schema:d}),d}registerPath(e){this._definitions.push({type:"route",route:e})}registerWebhook(e){this._definitions.push({type:"webhook",webhook:e})}registerComponent(e,t,r){return this._definitions.push({type:"component",componentType:e,name:t,component:r}),{name:t,ref:{$ref:`#/components/${e}/${t}`}}}schemaWithRefId(e,t){return t.openapi(e)}}class gn{constructor(e){this.message=e}}class kt extends gn{constructor(e,t){super(e),this.data=t}}class _n extends gn{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 wt(n,e){try{return n()}catch(t){throw t instanceof _n?new _n(Object.assign(Object.assign({},t.data),e)):t}}class gs extends gn{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 r=this.unwrapChained(e),s=e._def.openapi?e._def.openapi:r._def.openapi,a=(t=e.description)!==null&&t!==void 0?t:r.description;return{_internal:s==null?void 0:s._internal,metadata:Object.assign({description:a},s==null?void 0:s.metadata)}}static getInternalMetadata(e){const t=this.unwrapChained(e),r=e._def.openapi?e._def.openapi:t._def.openapi;return r==null?void 0:r._internal}static getParamMetadata(e){var t,r;const s=this.unwrapChained(e),a=e._def.openapi?e._def.openapi:s._def.openapi,i=(t=e.description)!==null&&t!==void 0?t:s.description;return{_internal:a==null?void 0:a._internal,metadata:Object.assign(Object.assign({},a==null?void 0:a.metadata),{param:Object.assign({description:i},(r=a==null?void 0:a.metadata)===null||r===void 0?void 0:r.param)})}}static buildSchemaMetadata(e){return et(hs(e,["param"]),vt)}static buildParameterMetadata(e){return et(e,vt)}static applySchemaMetadata(e,t){return et(Object.assign(Object.assign({},e),this.buildSchemaMetadata(t)),vt)}static getRefId(e){var t;return(t=this.getInternalMetadata(e))===null||t===void 0?void 0:t.refId}static unwrapChained(e){return this.unwrapUntil(e)}static getDefaultValue(e){const t=this.unwrapUntil(e,"ZodDefault");return t==null?void 0:t._def.defaultValue()}static unwrapUntil(e,t){return t&&k(e,t)?e:k(e,"ZodOptional")||k(e,"ZodNullable")||k(e,"ZodBranded")?this.unwrapUntil(e.unwrap(),t):k(e,"ZodDefault")||k(e,"ZodReadonly")?this.unwrapUntil(e._def.innerType,t):k(e,"ZodEffects")?this.unwrapUntil(e._def.schema,t):k(e,"ZodPipeline")?this.unwrapUntil(e._def.in,t):t?void 0:e}static isOptionalSchema(e){return k(e,"ZodEffects")?this.isOptionalSchema(e._def.schema):e.isOptional()}}class _s{transform(e,t,r){var s,a;const i=e._def.type;return Object.assign(Object.assign({},t("array")),{items:r(i),minItems:(s=e._def.minLength)===null||s===void 0?void 0:s.value,maxItems:(a=e._def.maxLength)===null||a===void 0?void 0:a.value})}}class ys{transform(e){return Object.assign(Object.assign({},e("string")),{pattern:"^d+$"})}}class vs{transform(e,t,r,s,a){const i=[...e.options.values()],o=i.map(s);return t?{oneOf:r(o,t)}:{oneOf:o,discriminator:this.mapDiscriminator(i,e.discriminator,a)}}mapDiscriminator(e,t,r){if(e.some(a=>U.getRefId(a)===void 0))return;const s={};return e.forEach(a=>{var i;const o=U.getRefId(a),d=(i=a.shape)===null||i===void 0?void 0:i[t];if(k(d,"ZodEnum")||k(d,"ZodNativeEnum")){Object.values(d.enum).filter(ur).forEach(p=>{s[p]=r(o)});return}const u=d==null?void 0:d._def.value;if(typeof u!="string")throw new Error(`Discriminator ${t} could not be found in one of the values of a discriminated union`);s[u]=r(o)}),{propertyName:t,mapping:s}}}class bs{transform(e,t){return Object.assign(Object.assign({},t("string")),{enum:e._def.values})}}class ks{transform(e,t,r,s){const i={allOf:this.flattenIntersectionTypes(e).map(s)};return t?{anyOf:r([i],t)}:i}flattenIntersectionTypes(e){if(!k(e,"ZodIntersection"))return[e];const t=this.flattenIntersectionTypes(e._def.left),r=this.flattenIntersectionTypes(e._def.right);return[...t,...r]}}class ws{transform(e,t){return Object.assign(Object.assign({},t(typeof e._def.value)),{enum:[e._def.value]})}}function xs(n){const t=Object.keys(n).filter(a=>typeof n[n[a]]!="number").map(a=>n[a]),r=t.filter(a=>typeof a=="number").length,s=r===0?"string":r===t.length?"numeric":"mixed";return{values:t,type:s}}class Os{transform(e,t){const{type:r,values:s}=xs(e._def.values);if(r==="mixed")throw new gn("Enum has mixed string and number values, please specify the OpenAPI type manually");return Object.assign(Object.assign({},t(r==="numeric"?"integer":"string")),{enum:s})}}class Ts{transform(e,t,r){return Object.assign(Object.assign({},t(e.isInt?"integer":"number")),r(e._def.checks))}}class js{transform(e,t,r,s){var a;const i=(a=U.getInternalMetadata(e))===null||a===void 0?void 0:a.extendedFrom,o=this.requiredKeysOf(e),d=bt(e._def.shape(),s);if(!i)return Object.assign(Object.assign(Object.assign(Object.assign({},r("object")),{properties:d,default:t}),o.length>0?{required:o}:{}),this.generateAdditionalProperties(e,s));const u=i.schema;s(u);const l=this.requiredKeysOf(u),p=bt(u==null?void 0:u._def.shape(),s),C=Object.fromEntries(Object.entries(d).filter(([R,H])=>!Bn(p[R],H))),D=o.filter(R=>!l.includes(R)),N=Object.assign(Object.assign(Object.assign(Object.assign({},r("object")),{default:t,properties:C}),D.length>0?{required:D}:{}),this.generateAdditionalProperties(e,s));return{allOf:[{$ref:`#/components/schemas/${i.refId}`},N]}}generateAdditionalProperties(e,t){const r=e._def.unknownKeys,s=e._def.catchall;return k(s,"ZodNever")?r==="strict"?{additionalProperties:!1}:{}:{additionalProperties:t(s)}}requiredKeysOf(e){return Object.entries(e._def.shape()).filter(([t,r])=>!U.isOptionalSchema(r)).map(([t,r])=>t)}}class Zs{transform(e,t,r){const s=e._def.valueType,a=e._def.keyType,i=r(s);if(k(a,"ZodEnum")||k(a,"ZodNativeEnum")){const d=Object.values(a.enum).filter(ur).reduce((u,l)=>Object.assign(Object.assign({},u),{[l]:i}),{});return Object.assign(Object.assign({},t("object")),{properties:d})}return Object.assign(Object.assign({},t("object")),{additionalProperties:i})}}class Rs{transform(e,t){var r,s,a;const i=this.getZodStringCheck(e,"regex"),o=(r=this.getZodStringCheck(e,"length"))===null||r===void 0?void 0:r.value,d=Number.isFinite(e.minLength)&&(s=e.minLength)!==null&&s!==void 0?s:void 0,u=Number.isFinite(e.maxLength)&&(a=e.maxLength)!==null&&a!==void 0?a:void 0;return Object.assign(Object.assign({},t("string")),{minLength:o??d,maxLength:o??u,format:this.mapStringFormat(e),pattern:i==null?void 0:i.regex.source})}mapStringFormat(e){if(e.isUUID)return"uuid";if(e.isEmail)return"email";if(e.isURL)return"uri";if(e.isDatetime)return"date-time"}getZodStringCheck(e,t){return e._def.checks.find(r=>r.kind===t)}}class Es{constructor(e){this.versionSpecifics=e}transform(e,t,r){const{items:s}=e._def,a=s.map(r);return Object.assign(Object.assign({},t("array")),this.versionSpecifics.mapTupleItems(a))}}class Ss{transform(e,t,r){const a=this.flattenUnionTypes(e).map(i=>{const o=this.unwrapNullable(i);return r(o)});return{anyOf:t(a)}}flattenUnionTypes(e){return k(e,"ZodUnion")?e._def.options.flatMap(r=>this.flattenUnionTypes(r)):[e]}unwrapNullable(e){return k(e,"ZodNullable")?this.unwrapNullable(e.unwrap()):e}}class Cs{constructor(e){this.versionSpecifics=e,this.objectTransformer=new js,this.stringTransformer=new Rs,this.numberTransformer=new Ts,this.bigIntTransformer=new ys,this.literalTransformer=new ws,this.enumTransformer=new bs,this.nativeEnumTransformer=new Os,this.arrayTransformer=new _s,this.unionTransformer=new Ss,this.discriminatedUnionTransformer=new vs,this.intersectionTransformer=new ks,this.recordTransformer=new Zs,this.tupleTransformer=new Es(e)}transform(e,t,r,s,a){if(k(e,"ZodNull"))return this.versionSpecifics.nullType;if(k(e,"ZodUnknown")||k(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(k(e,"ZodObject"))return this.objectTransformer.transform(e,a,o=>this.versionSpecifics.mapNullableType(o,t),r);const i=this.transformSchemaWithoutDefault(e,t,r,s);return Object.assign(Object.assign({},i),{default:a})}transformSchemaWithoutDefault(e,t,r,s){if(k(e,"ZodUnknown")||k(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(k(e,"ZodString"))return this.stringTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(k(e,"ZodNumber"))return this.numberTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),i=>this.versionSpecifics.getNumberChecks(i));if(k(e,"ZodBigInt"))return this.bigIntTransformer.transform(i=>this.versionSpecifics.mapNullableType(i,t));if(k(e,"ZodBoolean"))return this.versionSpecifics.mapNullableType("boolean",t);if(k(e,"ZodLiteral"))return this.literalTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(k(e,"ZodEnum"))return this.enumTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(k(e,"ZodNativeEnum"))return this.nativeEnumTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(k(e,"ZodArray"))return this.arrayTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),r);if(k(e,"ZodTuple"))return this.tupleTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),r);if(k(e,"ZodUnion"))return this.unionTransformer.transform(e,i=>this.versionSpecifics.mapNullableOfArray(i,t),r);if(k(e,"ZodDiscriminatedUnion"))return this.discriminatedUnionTransformer.transform(e,t,i=>this.versionSpecifics.mapNullableOfArray(i,t),r,s);if(k(e,"ZodIntersection"))return this.intersectionTransformer.transform(e,t,i=>this.versionSpecifics.mapNullableOfArray(i,t),r);if(k(e,"ZodRecord"))return this.recordTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),r);if(k(e,"ZodDate"))return this.versionSpecifics.mapNullableType("string",t);const a=U.getRefId(e);throw new gs({currentSchema:e._def,schemaName:a})}}class lr{constructor(e,t){this.definitions=e,this.versionSpecifics=t,this.schemaRefs={},this.paramRefs={},this.pathRefs={},this.rawComponents=[],this.openApiTransformer=new Cs(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 r={};return this.rawComponents.forEach(({componentType:s,name:a,component:i})=>{var o;(o=r[s])!==null&&o!==void 0||(r[s]={}),r[s][a]=i}),Object.assign(Object.assign({},r),{schemas:Object.assign(Object.assign({},(e=r.schemas)!==null&&e!==void 0?e:{}),this.schemaRefs),parameters:Object.assign(Object.assign({},(t=r.parameters)!==null&&t!==void 0?t:{}),this.paramRefs)})}sortDefinitions(){const e=["schema","parameter","component","route"];this.definitions.sort((t,r)=>{if(!("type"in t))return"type"in r?-1:0;if(!("type"in r))return 1;const s=e.findIndex(i=>i===t.type),a=e.findIndex(i=>i===r.type);return s-a})}generateSingle(e){if(!("type"in e)){this.generateSchemaWithRef(e);return}switch(e.type){case"parameter":this.generateParameterDefinition(e.schema);return;case"schema":this.generateSchemaWithRef(e.schema);return;case"route":this.generateSingleRoute(e.route);return;case"component":this.rawComponents.push(e);return}}generateParameterDefinition(e){const t=U.getRefId(e),r=this.generateParameter(e);return t&&(this.paramRefs[t]=r),r}getParameterRef(e,t){var r,s,a,i,o;const d=(r=e==null?void 0:e.metadata)===null||r===void 0?void 0:r.param,u=!((s=e==null?void 0:e._internal)===null||s===void 0)&&s.refId?this.paramRefs[(a=e._internal)===null||a===void 0?void 0:a.refId]:void 0;if(!(!(!((i=e==null?void 0:e._internal)===null||i===void 0)&&i.refId)||!u)){if(d&&u.in!==d.in||t!=null&&t.in&&u.in!==t.in)throw new kt(`Conflicting location for parameter ${u.name}`,{key:"in",values:dr([u.in,t==null?void 0:t.in,d==null?void 0:d.in])});if(d&&u.name!==d.name||t!=null&&t.name&&u.name!==(t==null?void 0:t.name))throw new kt("Conflicting names for parameter",{key:"name",values:dr([u.name,t==null?void 0:t.name,d==null?void 0:d.name])});return{$ref:`#/components/parameters/${(o=e._internal)===null||o===void 0?void 0:o.refId}`}}}generateInlineParameters(e,t){var r;const s=U.getMetadata(e),a=(r=s==null?void 0:s.metadata)===null||r===void 0?void 0:r.param,i=this.getParameterRef(s,{in:t});if(i)return[i];if(k(e,"ZodObject")){const o=e._def.shape();return Object.entries(o).map(([u,l])=>{var p,C;const D=U.getMetadata(l),N=this.getParameterRef(D,{in:t,name:u});if(N)return N;const R=(p=D==null?void 0:D.metadata)===null||p===void 0?void 0:p.param;if(R!=null&&R.name&&R.name!==u)throw new kt("Conflicting names for parameter",{key:"name",values:[u,R.name]});if(R!=null&&R.in&&R.in!==t)throw new kt(`Conflicting location for parameter ${(C=R.name)!==null&&C!==void 0?C:u}`,{key:"in",values:[t,R.in]});return this.generateParameter(l.openapi({param:{name:u,in:t}}))})}if(a!=null&&a.in&&a.in!==t)throw new kt(`Conflicting location for parameter ${a.name}`,{key:"in",values:[t,a.in]});return[this.generateParameter(e.openapi({param:{in:t}}))]}generateSimpleParameter(e){var t;const r=U.getParamMetadata(e),s=(t=r==null?void 0:r.metadata)===null||t===void 0?void 0:t.param,a=!U.isOptionalSchema(e)&&!e.isNullable(),i=this.generateSchemaWithRef(e);return Object.assign({schema:i,required:a},s?U.buildParameterMetadata(s):{})}generateParameter(e){var t;const r=U.getMetadata(e),s=(t=r==null?void 0:r.metadata)===null||t===void 0?void 0:t.param,a=s==null?void 0:s.name,i=s==null?void 0:s.in;if(!a)throw new _n({missingField:"name"});if(!i)throw new _n({missingField:"in",paramName:a});const o=this.generateSimpleParameter(e);return Object.assign(Object.assign({},o),{in:i,name:a})}generateSchemaWithMetadata(e){var t;const r=U.unwrapChained(e),s=U.getMetadata(e),a=U.getDefaultValue(e),i=!((t=s==null?void 0:s.metadata)===null||t===void 0)&&t.type?{type:s==null?void 0:s.metadata.type}:this.toOpenAPISchema(r,e.isNullable(),a);return s!=null&&s.metadata?U.applySchemaMetadata(i,s.metadata):et(i,vt)}constructReferencedOpenAPISchema(e){var t;const r=U.getMetadata(e),s=U.unwrapChained(e),a=U.getDefaultValue(e),i=e.isNullable();return!((t=r==null?void 0:r.metadata)===null||t===void 0)&&t.type?this.versionSpecifics.mapNullableType(r.metadata.type,i):this.toOpenAPISchema(s,i,a)}generateSimpleSchema(e){var t;const r=U.getMetadata(e),s=U.getRefId(e);if(!s||!this.schemaRefs[s])return this.generateSchemaWithMetadata(e);const a=this.schemaRefs[s],i={$ref:this.generateSchemaRef(s)},o=et(U.buildSchemaMetadata((t=r==null?void 0:r.metadata)!==null&&t!==void 0?t:{}),(l,p)=>l===void 0||Bn(l,a[p]));if(o.type)return{allOf:[i,o]};const d=et(this.constructReferencedOpenAPISchema(e),(l,p)=>l===void 0||Bn(l,a[p])),u=U.applySchemaMetadata(d,o);return Object.keys(u).length>0?{allOf:[i,u]}:i}generateSchemaWithRef(e){const t=U.getRefId(e),r=this.generateSimpleSchema(e);return t&&this.schemaRefs[t]===void 0?(this.schemaRefs[t]=r,{$ref:this.generateSchemaRef(t)}):r}generateSchemaRef(e){return`#/components/schemas/${e}`}getRequestBody(e){if(!e)return;const{content:t}=e,r=L(e,["content"]),s=this.getBodyContent(t);return Object.assign(Object.assign({},r),{content:s})}getParameters(e){if(!e)return[];const{headers:t}=e,r=this.cleanParameter(e.query),s=this.cleanParameter(e.params),a=this.cleanParameter(e.cookies),i=wt(()=>r?this.generateInlineParameters(r,"query"):[],{location:"query"}),o=wt(()=>s?this.generateInlineParameters(s,"path"):[],{location:"path"}),d=wt(()=>a?this.generateInlineParameters(a,"cookie"):[],{location:"cookie"}),u=wt(()=>{if(Array.isArray(t))return t.flatMap(p=>this.generateInlineParameters(p,"header"));const l=this.cleanParameter(t);return l?this.generateInlineParameters(l,"header"):[]},{location:"header"});return[...o,...i,...u,...d]}cleanParameter(e){if(e)return k(e,"ZodEffects")?this.cleanParameter(e._def.schema):e}generatePath(e){const{method:t,path:r,request:s,responses:a}=e,i=L(e,["method","path","request","responses"]),o=bt(a,p=>this.getResponse(p)),d=wt(()=>this.getParameters(s),{route:`${t} ${r}`}),u=this.getRequestBody(s==null?void 0:s.body);return{[t]:Object.assign(Object.assign(Object.assign(Object.assign({},i),d.length>0?{parameters:[...i.parameters||[],...d]}:{}),u?{requestBody:u}:{}),{responses:o})}}generateSingleRoute(e){const t=this.generatePath(e);return this.pathRefs[e.path]=Object.assign(Object.assign({},this.pathRefs[e.path]),t),t}getResponse(e){var{content:t,headers:r}=e,s=L(e,["content","headers"]);const a=t?{content:this.getBodyContent(t)}:{};if(!r)return Object.assign(Object.assign({},s),a);const i=k(r,"ZodObject")?this.getResponseHeaders(r):r;return Object.assign(Object.assign(Object.assign({},s),{headers:i}),a)}getResponseHeaders(e){const t=e._def.shape();return bt(t,s=>this.generateSimpleParameter(s))}getBodyContent(e){return bt(e,t=>{if(!t||!fn(t.schema))return t;const{schema:r}=t,s=L(t,["schema"]),a=this.generateSchemaWithRef(r);return Object.assign({schema:a},s)})}toOpenAPISchema(e,t,r){return this.openApiTransformer.transform(e,t,s=>this.generateSchemaWithRef(s),s=>this.generateSchemaRef(s),r)}}class Is{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=fs(e);return{items:t.length===1?t[0]:{anyOf:t},minItems:e.length,maxItems:e.length}}getNumberChecks(e){return Object.assign({},...e.map(t=>{switch(t.kind){case"min":return t.inclusive?{minimum:Number(t.value)}:{minimum:Number(t.value),exclusiveMinimum:!0};case"max":return t.inclusive?{maximum:Number(t.value)}:{maximum:Number(t.value),exclusiveMaximum:!0};default:return{}}}))}}class Ps{constructor(e){const t=new Is;this.generator=new lr(e,t)}generateDocument(e){const t=this.generator.generateDocumentData();return Object.assign(Object.assign({},e),t)}generateComponents(){return this.generator.generateComponents()}}class Ns{get nullType(){return{type:"null"}}mapNullableOfArray(e,t){return t?[...e,this.nullType]:e}mapNullableType(e,t){return e?t?{type:Array.isArray(e)?[...e,"null"]:[e,"null"]}:{type:e}:{}}mapTupleItems(e){return{prefixItems:e}}getNumberChecks(e){return Object.assign({},...e.map(t=>{switch(t.kind){case"min":return t.inclusive?{minimum:Number(t.value)}:{exclusiveMinimum:Number(t.value)};case"max":return t.inclusive?{maximum:Number(t.value)}:{exclusiveMaximum:Number(t.value)};default:return{}}}))}}function As(n){return"type"in n&&n.type==="webhook"}class $s{constructor(e){this.definitions=e,this.webhookRefs={};const t=new Ns;this.generator=new lr(this.definitions,t)}generateDocument(e){const t=this.generator.generateDocumentData();return this.definitions.filter(As).forEach(r=>this.generateSingleWebhook(r.webhook)),Object.assign(Object.assign(Object.assign({},e),t),{webhooks:this.webhookRefs})}generateComponents(){return this.generator.generateComponents()}generateSingleWebhook(e){const t=this.generator.generatePath(e);return this.webhookRefs[e.path]=Object.assign(Object.assign({},this.webhookRefs[e.path]),t),t}}var pr=n=>{const e=n.split("/");return e[0]===""&&e.shift(),e},Ms=n=>{const{groups:e,path:t}=Ds(n),r=pr(t);return Ls(r,e)},Ds=n=>{const e=[];return n=n.replace(/\{[^}]+\}/g,(t,r)=>{const s=`@${r}`;return e.push([s,t]),s}),{groups:e,path:n}},Ls=(n,e)=>{for(let t=e.length-1;t>=0;t--){const[r]=e[t];for(let s=n.length-1;s>=0;s--)if(n[s].includes(r)){n[s]=n[s].replace(r,e[t][1]);break}}return n},yn={},hr=n=>{if(n==="*")return"*";const e=n.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);return e?(yn[n]||(e[2]?yn[n]=[n,e[1],new RegExp("^"+e[2]+"$")]:yn[n]=[n,e[1],!0]),yn[n]):null},Vs=n=>{try{return decodeURI(n)}catch{return n.replace(/(?:%[0-9A-Fa-f]{2})+/g,e=>{try{return decodeURI(e)}catch{return e}})}},fr=n=>{const e=n.url,t=e.indexOf("/",8);let r=t;for(;r<e.length;r++){const s=e.charCodeAt(r);if(s===37){const a=e.indexOf("?",r),i=e.slice(t,a===-1?void 0:a);return Vs(i.includes("%25")?i.replace(/%25/g,"%2525"):i)}else if(s===63)break}return e.slice(t,r)},Us=n=>{const e=fr(n);return e.length>1&&e[e.length-1]==="/"?e.slice(0,-1):e},Be=(...n)=>{let e="",t=!1;for(let r of n)e[e.length-1]==="/"&&(e=e.slice(0,-1),t=!0),r[0]!=="/"&&(r=`/${r}`),r==="/"&&t?e=`${e}/`:r!=="/"&&(e=`${e}${r}`),r==="/"&&e===""&&(e="/");return e},mr=n=>{if(!n.match(/\:.+\?$/))return null;const e=n.split("/"),t=[];let r="";return e.forEach(s=>{if(s!==""&&!/\:/.test(s))r+="/"+s;else if(/\:/.test(s))if(/\?/.test(s)){t.length===0&&r===""?t.push("/"):t.push(r);const a=s.replace("?","");r+="/"+a,t.push(r)}else r+="/"+s}),t.filter((s,a,i)=>i.indexOf(s)===a)},Wn=n=>/[%+]/.test(n)?(n.indexOf("+")!==-1&&(n=n.replace(/\+/g," ")),/%/.test(n)?vn(n):n):n,gr=(n,e,t)=>{let r;if(!t&&e&&!/[%+]/.test(e)){let i=n.indexOf(`?${e}`,8);for(i===-1&&(i=n.indexOf(`&${e}`,8));i!==-1;){const o=n.charCodeAt(i+e.length+1);if(o===61){const d=i+e.length+2,u=n.indexOf("&",d);return Wn(n.slice(d,u===-1?void 0:u))}else if(o==38||isNaN(o))return"";i=n.indexOf(`&${e}`,i+1)}if(r=/[%+]/.test(n),!r)return}const s={};r??(r=/[%+]/.test(n));let a=n.indexOf("?",8);for(;a!==-1;){const i=n.indexOf("&",a+1);let o=n.indexOf("=",a);o>i&&i!==-1&&(o=-1);let d=n.slice(a+1,o===-1?i===-1?void 0:i:o);if(r&&(d=Wn(d)),a=i,d==="")continue;let u;o===-1?u="":(u=n.slice(o+1,i===-1?void 0:i),r&&(u=Wn(u))),t?(s[d]&&Array.isArray(s[d])||(s[d]=[]),s[d].push(u)):s[d]??(s[d]=u)}return e?s[e]:s},qs=gr,Bs=(n,e)=>gr(n,e,!0),vn=decodeURIComponent,Ws=/^[\w!#$%&'*.^`|~+-]+$/,Hs=/^[ !#-:<-[\]-~]*$/,Fs=(n,e)=>n.trim().split(";").reduce((r,s)=>{s=s.trim();const a=s.indexOf("=");if(a===-1)return r;const i=s.substring(0,a).trim();if(!Ws.test(i))return r;let o=s.substring(a+1).trim();return o.startsWith('"')&&o.endsWith('"')&&(o=o.slice(1,-1)),Hs.test(o)&&(r[i]=vn(o)),r},{}),Ks=(n,e,t)=>{const r=n.req.raw.headers.get("Cookie");return r?Fs(r):{}},bn=class extends Error{constructor(e=500,t){super(t==null?void 0:t.message,{cause:t==null?void 0:t.cause});y(this,"res");y(this,"status");this.res=t==null?void 0:t.res,this.status=e}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}},Gs=(n,e)=>new Response(n,{headers:{"Content-Type":e}}).formData(),zs=(n,e)=>async(t,r)=>{let s={};const a=t.req.header("Content-Type");switch(n){case"json":if(!a||!/^application\/([a-z-\.]+\+)?json/.test(a)){const o=`Invalid HTTP header: Content-Type=${a}`;throw new bn(400,{message:o})}try{s=await t.req.json()}catch{const o="Malformed JSON in request body";throw new bn(400,{message:o})}break;case"form":{if(!a)break;if(t.req.bodyCache.formData){s=await t.req.bodyCache.formData;break}try{const o=await t.req.arrayBuffer(),d=await Gs(o,a),u={};d.forEach((l,p)=>{p.endsWith("[]")?u[p]===void 0?u[p]=[l]:Array.isArray(u[p])&&u[p].push(l):u[p]=l}),s=u,t.req.bodyCache.formData=d}catch(o){let d="Malformed FormData request.";throw d+=o instanceof Error?` ${o.message}`:` ${String(o)}`,new bn(400,{message:d})}break}case"query":s=Object.fromEntries(Object.entries(t.req.queries()).map(([o,d])=>d.length===1?[o,d[0]]:[o,d]));break;case"param":s=t.req.param();break;case"header":s=t.req.header();break;case"cookie":s=Ks(t);break}const i=await e(s,t);if(i instanceof Response)return i;t.req.addValidatedData(n,i),await r()};const tt=(n,e,t)=>zs(n,async(r,s)=>{const a=await e.safeParseAsync(r);if(t){const i=await t({data:r,...a},s);if(i){if(i instanceof Response)return i;if("response"in i)return i.response}}return a.success?a.data:s.json(a,400)});var Ys=async(n,e=Object.create(null))=>{const{all:t=!1,dot:r=!1}=e,a=(n instanceof _r?n.raw.headers:n.headers).get("Content-Type");return a!==null&&a.startsWith("multipart/form-data")||a!==null&&a.startsWith("application/x-www-form-urlencoded")?Js(n,{all:t,dot:r}):{}};async function Js(n,e){const t=await n.formData();return t?Qs(t,e):{}}function Qs(n,e){const t=Object.create(null);return n.forEach((r,s)=>{e.all||s.endsWith("[]")?Xs(t,s,r):t[s]=r}),e.dot&&Object.entries(t).forEach(([r,s])=>{r.includes(".")&&(ea(t,r,s),delete t[r])}),t}var Xs=(n,e,t)=>{n[e]!==void 0?Array.isArray(n[e])?n[e].push(t):n[e]=[n[e],t]:n[e]=t},ea=(n,e,t)=>{let r=n;const s=e.split(".");s.forEach((a,i)=>{i===s.length-1?r[a]=t:((!r[a]||typeof r[a]!="object"||Array.isArray(r[a])||r[a]instanceof File)&&(r[a]=Object.create(null)),r=r[a])})},_r=(is=class{constructor(n,e="/",t=[[]]){y(this,"raw");Y(this,mt);Y(this,fe);y(this,"routeIndex",0);y(this,"path");y(this,"bodyCache",{});y(this,"cachedBody",n=>{const{bodyCache:e,raw:t}=this,r=e[n];if(r)return r;const s=Object.keys(e)[0];return s?e[s].then(a=>(s==="json"&&(a=JSON.stringify(a)),new Response(a)[n]())):e[n]=t[n]()});this.raw=n,this.path=e,M(this,fe,t),M(this,mt,{})}param(n){return n?this.getDecodedParam(n):this.getAllDecodedParams()}getDecodedParam(n){const e=m(this,fe)[0][this.routeIndex][1][n],t=this.getParamValue(e);return t?/\%/.test(t)?vn(t):t:void 0}getAllDecodedParams(){const n={},e=Object.keys(m(this,fe)[0][this.routeIndex][1]);for(const t of e){const r=this.getParamValue(m(this,fe)[0][this.routeIndex][1][t]);r&&typeof r=="string"&&(n[t]=/\%/.test(r)?vn(r):r)}return n}getParamValue(n){return m(this,fe)[1]?m(this,fe)[1][n]:n}query(n){return qs(this.url,n)}queries(n){return Bs(this.url,n)}header(n){if(n)return this.raw.headers.get(n.toLowerCase())??void 0;const e={};return this.raw.headers.forEach((t,r)=>{e[r]=t}),e}async parseBody(n){var e;return(e=this.bodyCache).parsedBody??(e.parsedBody=await Ys(this,n))}json(){return this.cachedBody("json")}text(){return this.cachedBody("text")}arrayBuffer(){return this.cachedBody("arrayBuffer")}blob(){return this.cachedBody("blob")}formData(){return this.cachedBody("formData")}addValidatedData(n,e){m(this,mt)[n]=e}valid(n){return m(this,mt)[n]}get url(){return this.raw.url}get method(){return this.raw.method}get matchedRoutes(){return m(this,fe)[0].map(([[,n]])=>n)}get routePath(){return m(this,fe)[0].map(([[,n]])=>n)[this.routeIndex].path}},mt=new WeakMap,fe=new WeakMap,is),ta={Stringify:1,BeforeStream:2,Stream:3},yr=async(n,e,t,r,s)=>{const a=n.callbacks;return a!=null&&a.length?(s?s[0]+=n:s=[n],Promise.all(a.map(o=>o({phase:e,buffer:s,context:r}))).then(o=>Promise.all(o.filter(Boolean).map(d=>yr(d,e,!1,r,s))).then(()=>s[0]))):Promise.resolve(n)},na="text/plain; charset=UTF-8",Hn=(n,e={})=>(Object.entries(e).forEach(([t,r])=>n.set(t,r)),n),kn=(os=class{constructor(n,e){Y(this,dn);Y(this,un);y(this,"env",{});Y(this,Ue);y(this,"finalized",!1);y(this,"error");Y(this,Je,200);Y(this,Re);Y(this,W);Y(this,F);Y(this,me);Y(this,Ee,!0);Y(this,ln);Y(this,gt);Y(this,_t);Y(this,pn);Y(this,hn);y(this,"render",(...n)=>(m(this,gt)??M(this,gt,e=>this.html(e)),m(this,gt).call(this,...n)));y(this,"setLayout",n=>M(this,ln,n));y(this,"getLayout",()=>m(this,ln));y(this,"setRenderer",n=>{M(this,gt,n)});y(this,"header",(n,e,t)=>{if(e===void 0){m(this,W)?m(this,W).delete(n):m(this,F)&&delete m(this,F)[n.toLocaleLowerCase()],this.finalized&&this.res.headers.delete(n);return}t!=null&&t.append?(m(this,W)||(M(this,Ee,!1),M(this,W,new Headers(m(this,F))),M(this,F,{})),m(this,W).append(n,e)):m(this,W)?m(this,W).set(n,e):(m(this,F)??M(this,F,{}),m(this,F)[n.toLowerCase()]=e),this.finalized&&(t!=null&&t.append?this.res.headers.append(n,e):this.res.headers.set(n,e))});y(this,"status",n=>{M(this,Ee,!1),M(this,Je,n)});y(this,"set",(n,e)=>{m(this,Ue)??M(this,Ue,{}),m(this,Ue)[n]=e});y(this,"get",n=>m(this,Ue)?m(this,Ue)[n]:void 0);y(this,"newResponse",(n,e,t)=>{if(m(this,Ee)&&!t&&!e&&m(this,Je)===200)return new Response(n,{headers:m(this,F)});if(e&&typeof e!="number"){const s=new Headers(e.headers);m(this,W)&&m(this,W).forEach((i,o)=>{o==="set-cookie"?s.append(o,i):s.set(o,i)});const a=Hn(s,m(this,F));return new Response(n,{headers:a,status:e.status??m(this,Je)})}const r=typeof e=="number"?e:m(this,Je);m(this,F)??M(this,F,{}),m(this,W)??M(this,W,new Headers),Hn(m(this,W),m(this,F)),m(this,me)&&(m(this,me).headers.forEach((s,a)=>{var i,o;a==="set-cookie"?(i=m(this,W))==null||i.append(a,s):(o=m(this,W))==null||o.set(a,s)}),Hn(m(this,W),m(this,F))),t??(t={});for(const[s,a]of Object.entries(t))if(typeof a=="string")m(this,W).set(s,a);else{m(this,W).delete(s);for(const i of a)m(this,W).append(s,i)}return new Response(n,{status:r,headers:m(this,W)})});y(this,"body",(n,e,t)=>typeof e=="number"?this.newResponse(n,e,t):this.newResponse(n,e));y(this,"text",(n,e,t)=>{if(!m(this,F)){if(m(this,Ee)&&!t&&!e)return new Response(n);M(this,F,{})}return m(this,F)["content-type"]=na,typeof e=="number"?this.newResponse(n,e,t):this.newResponse(n,e)});y(this,"json",(n,e,t)=>{const r=JSON.stringify(n);return m(this,F)??M(this,F,{}),m(this,F)["content-type"]="application/json; charset=UTF-8",typeof e=="number"?this.newResponse(r,e,t):this.newResponse(r,e)});y(this,"html",(n,e,t)=>(m(this,F)??M(this,F,{}),m(this,F)["content-type"]="text/html; charset=UTF-8",typeof n=="object"&&(n instanceof Promise||(n=n.toString()),n instanceof Promise)?n.then(r=>yr(r,ta.Stringify,!1,{})).then(r=>typeof e=="number"?this.newResponse(r,e,t):this.newResponse(r,e)):typeof e=="number"?this.newResponse(n,e,t):this.newResponse(n,e)));y(this,"redirect",(n,e)=>(m(this,W)??M(this,W,new Headers),m(this,W).set("Location",n),this.newResponse(null,e??302)));y(this,"notFound",()=>(m(this,_t)??M(this,_t,()=>new Response),m(this,_t).call(this,this)));M(this,dn,n),e&&(M(this,Re,e.executionCtx),this.env=e.env,M(this,_t,e.notFoundHandler),M(this,hn,e.path),M(this,pn,e.matchResult))}get req(){return m(this,un)??M(this,un,new _r(m(this,dn),m(this,hn),m(this,pn))),m(this,un)}get event(){if(m(this,Re)&&"respondWith"in m(this,Re))return m(this,Re);throw Error("This context has no FetchEvent")}get executionCtx(){if(m(this,Re))return m(this,Re);throw Error("This context has no ExecutionContext")}get res(){return M(this,Ee,!1),m(this,me)||M(this,me,new Response("404 Not Found",{status:404}))}set res(n){if(M(this,Ee,!1),m(this,me)&&n){m(this,me).headers.delete("content-type");for(const[e,t]of m(this,me).headers.entries())if(e==="set-cookie"){const r=m(this,me).headers.getSetCookie();n.headers.delete("set-cookie");for(const s of r)n.headers.append("set-cookie",s)}else n.headers.set(e,t)}M(this,me,n),this.finalized=!0}get var(){return{...m(this,Ue)}}},dn=new WeakMap,un=new WeakMap,Ue=new WeakMap,Je=new WeakMap,Re=new WeakMap,W=new WeakMap,F=new WeakMap,me=new WeakMap,Ee=new WeakMap,ln=new WeakMap,gt=new WeakMap,_t=new WeakMap,pn=new WeakMap,hn=new WeakMap,os),vr=(n,e,t)=>(r,s)=>{let a=-1;return i(0);async function i(o){if(o<=a)throw new Error("next() called multiple times");a=o;let d,u=!1,l;if(n[o]?(l=n[o][0][0],r instanceof kn&&(r.req.routeIndex=o)):l=o===n.length&&s||void 0,!l)r instanceof kn&&r.finalized===!1&&t&&(d=await t(r));else try{d=await l(r,()=>i(o+1))}catch(p){if(p instanceof Error&&r instanceof kn&&e)r.error=p,d=await e(p,r),u=!0;else throw p}return d&&(r.finalized===!1||u)&&(r.res=d),r}},G="ALL",ra="all",sa=["get","post","put","delete","options","patch"],br="Can not add a route since the matcher is already built.",kr=class extends Error{},aa=Symbol("composedHandler"),ia=n=>n.text("404 Not Found",404),wr=(n,e)=>"getResponse"in n?n.getResponse():(console.error(n),e.text("Internal Server Error",500)),xr=(cs=class{constructor(e={}){y(this,"get");y(this,"post");y(this,"put");y(this,"delete");y(this,"options");y(this,"patch");y(this,"all");y(this,"on");y(this,"use");y(this,"router");y(this,"getPath");y(this,"_basePath","/");Y(this,ge,"/");y(this,"routes",[]);y(this,"notFoundHandler",ia);y(this,"errorHandler",wr);y(this,"onError",e=>(this.errorHandler=e,this));y(this,"notFound",e=>(this.notFoundHandler=e,this));y(this,"fetch",(e,...t)=>this.dispatch(e,t[1],t[0],e.method));y(this,"request",(e,t,r,s)=>{if(e instanceof Request)return t!==void 0&&(e=new Request(e,t)),this.fetch(e,r,s);e=e.toString();const a=/^https?:\/\//.test(e)?e:`http://localhost${Be("/",e)}`,i=new Request(a,t);return this.fetch(i,r,s)});y(this,"fire",()=>{addEventListener("fetch",e=>{e.respondWith(this.dispatch(e.request,e,void 0,e.request.method))})});[...sa,ra].forEach(s=>{this[s]=(a,...i)=>(typeof a=="string"?M(this,ge,a):this.addRoute(s,m(this,ge),a),i.forEach(o=>{typeof o!="string"&&this.addRoute(s,m(this,ge),o)}),this)}),this.on=(s,a,...i)=>{for(const o of[a].flat()){M(this,ge,o);for(const d of[s].flat())i.map(u=>{this.addRoute(d.toUpperCase(),m(this,ge),u)})}return this},this.use=(s,...a)=>(typeof s=="string"?M(this,ge,s):(M(this,ge,"*"),a.unshift(s)),a.forEach(i=>{this.addRoute(G,m(this,ge),i)}),this);const r=e.strict??!0;delete e.strict,Object.assign(this,e),this.getPath=r?e.getPath??fr:Us}clone(){const e=new xr({router:this.router,getPath:this.getPath});return e.routes=this.routes,e}route(e,t){const r=this.basePath(e);return t.routes.map(s=>{let a;t.errorHandler===wr?a=s.handler:(a=async(i,o)=>(await vr([],t.errorHandler)(i,()=>s.handler(i,o))).res,a[aa]=s.handler),r.addRoute(s.method,s.path,a)}),this}basePath(e){const t=this.clone();return t._basePath=Be(this._basePath,e),t}mount(e,t,r){let s,a;r&&(typeof r=="function"?a=r:(a=r.optionHandler,s=r.replaceRequest));const i=a?d=>{const u=a(d);return Array.isArray(u)?u:[u]}:d=>{let u;try{u=d.executionCtx}catch{}return[d.env,u]};s||(s=(()=>{const d=Be(this._basePath,e),u=d==="/"?0:d.length;return l=>{const p=new URL(l.url);return p.pathname=p.pathname.slice(u)||"/",new Request(p,l)}})());const o=async(d,u)=>{const l=await t(s(d.req.raw),...i(d));if(l)return l;await u()};return this.addRoute(G,Be(e,"*"),o),this}addRoute(e,t,r){e=e.toUpperCase(),t=Be(this._basePath,t);const s={path:t,method:e,handler:r};this.router.add(e,t,[r,s]),this.routes.push(s)}matchRoute(e,t){return this.router.match(e,t)}handleError(e,t){if(e instanceof Error)return this.errorHandler(e,t);throw e}dispatch(e,t,r,s){if(s==="HEAD")return(async()=>new Response(null,await this.dispatch(e,t,r,"GET")))();const a=this.getPath(e,{env:r}),i=this.matchRoute(s,a),o=new kn(e,{path:a,matchResult:i,env:r,executionCtx:t,notFoundHandler:this.notFoundHandler});if(i[0].length===1){let u;try{u=i[0][0][0][0](o,async()=>{o.res=await this.notFoundHandler(o)})}catch(l){return this.handleError(l,o)}return u instanceof Promise?u.then(l=>l||(o.finalized?o.res:this.notFoundHandler(o))).catch(l=>this.handleError(l,o)):u??this.notFoundHandler(o)}const d=vr(i[0],this.errorHandler,this.notFoundHandler);return(async()=>{try{const u=await d(o);if(!u.finalized)throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");return u.res}catch(u){return this.handleError(u,o)}})()}},ge=new WeakMap,cs),wn="[^/]+",xt=".*",Ot="(?:|/.*)",Tt=Symbol(),oa=new Set(".\\+*[^]$()");function ca(n,e){return n.length===1?e.length===1?n<e?-1:1:-1:e.length===1||n===xt||n===Ot?1:e===xt||e===Ot?-1:n===wn?1:e===wn?-1:n.length===e.length?n<e?-1:1:e.length-n.length}var Fn=class{constructor(){y(this,"index");y(this,"varIndex");y(this,"children",Object.create(null))}insert(e,t,r,s,a){if(e.length===0){if(this.index!==void 0)throw Tt;if(a)return;this.index=t;return}const[i,...o]=e,d=i==="*"?o.length===0?["","",xt]:["","",wn]:i==="/*"?["","",Ot]:i.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);let u;if(d){const l=d[1];let p=d[2]||wn;if(l&&d[2]&&(p=p.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(p)))throw Tt;if(u=this.children[p],!u){if(Object.keys(this.children).some(C=>C!==xt&&C!==Ot))throw Tt;if(a)return;u=this.children[p]=new Fn,l!==""&&(u.varIndex=s.varIndex++)}!a&&l!==""&&r.push([l,u.varIndex])}else if(u=this.children[i],!u){if(Object.keys(this.children).some(l=>l.length>1&&l!==xt&&l!==Ot))throw Tt;if(a)return;u=this.children[i]=new Fn}u.insert(o,t,r,s,a)}buildRegExpStr(){const t=Object.keys(this.children).sort(ca).map(r=>{const s=this.children[r];return(typeof s.varIndex=="number"?`(${r})@${s.varIndex}`:oa.has(r)?`\\${r}`:r)+s.buildRegExpStr()});return typeof this.index=="number"&&t.unshift(`#${this.index}`),t.length===0?"":t.length===1?t[0]:"(?:"+t.join("|")+")"}},da=class{constructor(){y(this,"context",{varIndex:0});y(this,"root",new Fn)}insert(n,e,t){const r=[],s=[];for(let i=0;;){let o=!1;if(n=n.replace(/\{[^}]+\}/g,d=>{const u=`@\\${i}`;return s[i]=[u,d],i++,o=!0,u}),!o)break}const a=n.match(/(?::[^\/]+)|(?:\/\*$)|./g)||[];for(let i=s.length-1;i>=0;i--){const[o]=s[i];for(let d=a.length-1;d>=0;d--)if(a[d].indexOf(o)!==-1){a[d]=a[d].replace(o,s[i][1]);break}}return this.root.insert(a,e,r,this.context,t),r}buildRegExp(){let n=this.root.buildRegExpStr();if(n==="")return[/^$/,[],[]];let e=0;const t=[],r=[];return n=n.replace(/#(\d+)|@(\d+)|\.\*\$/g,(s,a,i)=>typeof a<"u"?(t[++e]=Number(a),"$()"):(typeof i<"u"&&(r[Number(i)]=++e),"")),[new RegExp(`^${n}`),t,r]}},Or=[],ua=[/^$/,[],Object.create(null)],xn=Object.create(null);function Tr(n){return xn[n]??(xn[n]=new RegExp(n==="*"?"":`^${n.replace(/\/\*$|([.\\+*[^\]$()])/g,(e,t)=>t?`\\${t}`:"(?:|/.*)")}$`))}function la(){xn=Object.create(null)}function pa(n){var u;const e=new da,t=[];if(n.length===0)return ua;const r=n.map(l=>[!/\*|\/:/.test(l[0]),...l]).sort(([l,p],[C,D])=>l?1:C?-1:p.length-D.length),s=Object.create(null);for(let l=0,p=-1,C=r.length;l<C;l++){const[D,N,R]=r[l];D?s[N]=[R.map(([K])=>[K,Object.create(null)]),Or]:p++;let H;try{H=e.insert(N,p,D)}catch(K){throw K===Tt?new kr(N):K}D||(t[p]=R.map(([K,se])=>{const ae=Object.create(null);for(se-=1;se>=0;se--){const[qe,oe]=H[se];ae[qe]=oe}return[K,ae]}))}const[a,i,o]=e.buildRegExp();for(let l=0,p=t.length;l<p;l++)for(let C=0,D=t[l].length;C<D;C++){const N=(u=t[l][C])==null?void 0:u[1];if(!N)continue;const R=Object.keys(N);for(let H=0,K=R.length;H<K;H++)N[R[H]]=o[N[R[H]]]}const d=[];for(const l in i)d[l]=t[i[l]];return[a,d,s]}function nt(n,e){if(n){for(const t of Object.keys(n).sort((r,s)=>s.length-r.length))if(Tr(t).test(e))return[...n[t]]}}var ha=class{constructor(){y(this,"name","RegExpRouter");y(this,"middleware");y(this,"routes");this.middleware={[G]:Object.create(null)},this.routes={[G]:Object.create(null)}}add(n,e,t){var o;const{middleware:r,routes:s}=this;if(!r||!s)throw new Error(br);r[n]||[r,s].forEach(d=>{d[n]=Object.create(null),Object.keys(d[G]).forEach(u=>{d[n][u]=[...d[G][u]]})}),e==="/*"&&(e="*");const a=(e.match(/\/:/g)||[]).length;if(/\*$/.test(e)){const d=Tr(e);n===G?Object.keys(r).forEach(u=>{var l;(l=r[u])[e]||(l[e]=nt(r[u],e)||nt(r[G],e)||[])}):(o=r[n])[e]||(o[e]=nt(r[n],e)||nt(r[G],e)||[]),Object.keys(r).forEach(u=>{(n===G||n===u)&&Object.keys(r[u]).forEach(l=>{d.test(l)&&r[u][l].push([t,a])})}),Object.keys(s).forEach(u=>{(n===G||n===u)&&Object.keys(s[u]).forEach(l=>d.test(l)&&s[u][l].push([t,a]))});return}const i=mr(e)||[e];for(let d=0,u=i.length;d<u;d++){const l=i[d];Object.keys(s).forEach(p=>{var C;(n===G||n===p)&&((C=s[p])[l]||(C[l]=[...nt(r[p],l)||nt(r[G],l)||[]]),s[p][l].push([t,a-u+d+1]))})}}match(n,e){la();const t=this.buildAllMatchers();return this.match=(r,s)=>{const a=t[r]||t[G],i=a[2][s];if(i)return i;const o=s.match(a[0]);if(!o)return[[],Or];const d=o.indexOf("",1);return[a[1][d],o]},this.match(n,e)}buildAllMatchers(){const n=Object.create(null);return[...Object.keys(this.routes),...Object.keys(this.middleware)].forEach(e=>{n[e]||(n[e]=this.buildMatcher(e))}),this.middleware=this.routes=void 0,n}buildMatcher(n){const e=[];let t=n===G;return[this.middleware,this.routes].forEach(r=>{const s=r[n]?Object.keys(r[n]).map(a=>[a,r[n][a]]):[];s.length!==0?(t||(t=!0),e.push(...s)):n!==G&&e.push(...Object.keys(r[G]).map(a=>[a,r[G][a]]))}),t?pa(e):null}},fa=class{constructor(n){y(this,"name","SmartRouter");y(this,"routers",[]);y(this,"routes",[]);Object.assign(this,n)}add(n,e,t){if(!this.routes)throw new Error(br);this.routes.push([n,e,t])}match(n,e){if(!this.routes)throw new Error("Fatal error");const{routers:t,routes:r}=this,s=t.length;let a=0,i;for(;a<s;a++){const o=t[a];try{r.forEach(d=>{o.add(...d)}),i=o.match(n,e)}catch(d){if(d instanceof kr)continue;throw d}this.match=o.match.bind(o),this.routers=[o],this.routes=void 0;break}if(a===s)throw new Error("Fatal error");return this.name=`SmartRouter + ${this.activeRouter.name}`,i}get activeRouter(){if(this.routes||this.routers.length!==1)throw new Error("No active router has been determined yet.");return this.routers[0]}},jr=class{constructor(n,e,t){y(this,"methods");y(this,"children");y(this,"patterns");y(this,"order",0);y(this,"name");y(this,"params",Object.create(null));if(this.children=t||Object.create(null),this.methods=[],this.name="",n&&e){const r=Object.create(null);r[n]={handler:e,possibleKeys:[],score:0,name:this.name},this.methods=[r]}this.patterns=[]}insert(n,e,t){this.name=`${n} ${e}`,this.order=++this.order;let r=this;const s=Ms(e),a=[];for(let d=0,u=s.length;d<u;d++){const l=s[d];if(Object.keys(r.children).includes(l)){r=r.children[l];const C=hr(l);C&&a.push(C[1]);continue}r.children[l]=new jr;const p=hr(l);p&&(r.patterns.push(p),a.push(p[1])),r=r.children[l]}r.methods.length||(r.methods=[]);const i=Object.create(null),o={handler:t,possibleKeys:a.filter((d,u,l)=>l.indexOf(d)===u),name:this.name,score:this.order};return i[n]=o,r.methods.push(i),r}gHSets(n,e,t,r){const s=[];for(let a=0,i=n.methods.length;a<i;a++){const o=n.methods[a],d=o[e]||o[G],u=Object.create(null);d!==void 0&&(d.params=Object.create(null),d.possibleKeys.forEach(l=>{const p=u[d.name];d.params[l]=r[l]&&!p?r[l]:t[l]??r[l],u[d.name]=!0}),s.push(d))}return s}search(n,e){const t=[];this.params=Object.create(null);let s=[this];const a=pr(e);for(let o=0,d=a.length;o<d;o++){const u=a[o],l=o===d-1,p=[];for(let C=0,D=s.length;C<D;C++){const N=s[C],R=N.children[u];R&&(R.params=N.params,l===!0?(R.children["*"]&&t.push(...this.gHSets(R.children["*"],n,N.params,Object.create(null))),t.push(...this.gHSets(R,n,N.params,Object.create(null)))):p.push(R));for(let H=0,K=N.patterns.length;H<K;H++){const se=N.patterns[H],ae={...N.params};if(se==="*"){const _e=N.children["*"];_e&&(t.push(...this.gHSets(_e,n,N.params,Object.create(null))),p.push(_e));continue}if(u==="")continue;const[qe,oe,ie]=se,te=N.children[qe],Oe=a.slice(o).join("/");if(ie instanceof RegExp&&ie.test(Oe)){ae[oe]=Oe,t.push(...this.gHSets(te,n,N.params,ae));continue}(ie===!0||ie instanceof RegExp&&ie.test(u))&&typeof qe=="string"&&(ae[oe]=u,l===!0?(t.push(...this.gHSets(te,n,ae,N.params)),te.children["*"]&&t.push(...this.gHSets(te.children["*"],n,ae,N.params))):(te.params=ae,p.push(te)))}}s=p}return[t.sort((o,d)=>o.score-d.score).map(({handler:o,params:d})=>[o,d])]}},ma=class{constructor(){y(this,"name","TrieRouter");y(this,"node");this.node=new jr}add(n,e,t){const r=mr(e);if(r){for(const s of r)this.node.insert(n,s,t);return}this.node.insert(n,e,t)}match(n,e){return this.node.search(n,e)}},ga=class extends xr{constructor(n={}){super(n),this.router=n.router??new fa({routers:[new ha,new ma]})}},A;(function(n){n.assertEqual=s=>s;function e(s){}n.assertIs=e;function t(s){throw new Error}n.assertNever=t,n.arrayToEnum=s=>{const a={};for(const i of s)a[i]=i;return a},n.getValidEnumValues=s=>{const a=n.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),i={};for(const o of a)i[o]=s[o];return n.objectValues(i)},n.objectValues=s=>n.objectKeys(s).map(function(a){return s[a]}),n.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const a=[];for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&a.push(i);return a},n.find=(s,a)=>{for(const i of s)if(a(i))return i},n.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function r(s,a=" | "){return s.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}n.joinValues=r,n.jsonStringifyReplacer=(s,a)=>typeof a=="bigint"?a.toString():a})(A||(A={}));var Kn;(function(n){n.mergeShapes=(e,t)=>({...e,...t})})(Kn||(Kn={}));const v=A.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Se=n=>{switch(typeof n){case"undefined":return v.undefined;case"string":return v.string;case"number":return isNaN(n)?v.nan:v.number;case"boolean":return v.boolean;case"function":return v.function;case"bigint":return v.bigint;case"symbol":return v.symbol;case"object":return Array.isArray(n)?v.array:n===null?v.null:n.then&&typeof n.then=="function"&&n.catch&&typeof n.catch=="function"?v.promise:typeof Map<"u"&&n instanceof Map?v.map:typeof Set<"u"&&n instanceof Set?v.set:typeof Date<"u"&&n instanceof Date?v.date:v.object;default:return v.unknown}},h=A.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"]),_a=n=>JSON.stringify(n,null,2).replace(/"([^"]+)":/g,"$1:");class ne extends Error{constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const t=e||function(a){return a.message},r={_errors:[]},s=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(s);else if(i.code==="invalid_return_type")s(i.returnTypeError);else if(i.code==="invalid_arguments")s(i.argumentsError);else if(i.path.length===0)r._errors.push(t(i));else{let o=r,d=0;for(;d<i.path.length;){const u=i.path[d];d===i.path.length-1?(o[u]=o[u]||{_errors:[]},o[u]._errors.push(t(i))):o[u]=o[u]||{_errors:[]},o=o[u],d++}}};return s(this),r}static assert(e){if(!(e instanceof ne))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,A.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},r=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}ne.create=n=>new ne(n);const rt=(n,e)=>{let t;switch(n.code){case h.invalid_type:n.received===v.undefined?t="Required":t=`Expected ${n.expected}, received ${n.received}`;break;case h.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(n.expected,A.jsonStringifyReplacer)}`;break;case h.unrecognized_keys:t=`Unrecognized key(s) in object: ${A.joinValues(n.keys,", ")}`;break;case h.invalid_union:t="Invalid input";break;case h.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${A.joinValues(n.options)}`;break;case h.invalid_enum_value:t=`Invalid enum value. Expected ${A.joinValues(n.options)}, received '${n.received}'`;break;case h.invalid_arguments:t="Invalid function arguments";break;case h.invalid_return_type:t="Invalid function return type";break;case h.invalid_date:t="Invalid date";break;case h.invalid_string:typeof n.validation=="object"?"includes"in n.validation?(t=`Invalid input: must include "${n.validation.includes}"`,typeof n.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${n.validation.position}`)):"startsWith"in n.validation?t=`Invalid input: must start with "${n.validation.startsWith}"`:"endsWith"in n.validation?t=`Invalid input: must end with "${n.validation.endsWith}"`:A.assertNever(n.validation):n.validation!=="regex"?t=`Invalid ${n.validation}`:t="Invalid";break;case h.too_small:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at least":"more than"} ${n.minimum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at least":"over"} ${n.minimum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(n.minimum))}`:t="Invalid input";break;case h.too_big:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at most":"less than"} ${n.maximum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at most":"under"} ${n.maximum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="bigint"?t=`BigInt must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly":n.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(n.maximum))}`:t="Invalid input";break;case h.custom:t="Invalid input";break;case h.invalid_intersection_types:t="Intersection results could not be merged";break;case h.not_multiple_of:t=`Number must be a multiple of ${n.multipleOf}`;break;case h.not_finite:t="Number must be finite";break;default:t=e.defaultError,A.assertNever(n)}return{message:t}};let Zr=rt;function ya(n){Zr=n}function On(){return Zr}const Tn=n=>{const{data:e,path:t,errorMaps:r,issueData:s}=n,a=[...t,...s.path||[]],i={...s,path:a};if(s.message!==void 0)return{...s,path:a,message:s.message};let o="";const d=r.filter(u=>!!u).slice().reverse();for(const u of d)o=u(i,{data:e,defaultError:o}).message;return{...s,path:a,message:o}},va=[];function g(n,e){const t=On(),r=Tn({issueData:e,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,t,t===rt?void 0:rt].filter(s=>!!s)});n.common.issues.push(r)}class J{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const s of t){if(s.status==="aborted")return j;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const s of t){const a=await s.key,i=await s.value;r.push({key:a,value:i})}return J.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const s of t){const{key:a,value:i}=s;if(a.status==="aborted"||i.status==="aborted")return j;a.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||s.alwaysSet)&&(r[a.value]=i.value)}return{status:e.value,value:r}}}const j=Object.freeze({status:"aborted"}),st=n=>({status:"dirty",value:n}),X=n=>({status:"valid",value:n}),Gn=n=>n.status==="aborted",zn=n=>n.status==="dirty",jt=n=>n.status==="valid",Zt=n=>typeof Promise<"u"&&n instanceof Promise;function jn(n,e,t,r){if(typeof e=="function"?n!==e||!r:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(n)}function Rr(n,e,t,r,s){if(typeof e=="function"?n!==e||!s:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(n,t),t}typeof SuppressedError=="function"&&SuppressedError;var w;(function(n){n.errToObj=e=>typeof e=="string"?{message:e}:e||{},n.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(w||(w={}));var Rt,Et;class ye{constructor(e,t,r,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Er=(n,e)=>{if(jt(e))return{success:!0,data:e.value};if(!n.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 ne(n.common.issues);return this._error=t,this._error}}};function E(n){if(!n)return{};const{errorMap:e,invalid_type_error:t,required_error:r,description:s}=n;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(i,o)=>{var d,u;const{message:l}=n;return i.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:(d=l??r)!==null&&d!==void 0?d:o.defaultError}:i.code!=="invalid_type"?{message:o.defaultError}:{message:(u=l??t)!==null&&u!==void 0?u:o.defaultError}},description:s}}class I{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)}get description(){return this._def.description}_getType(e){return Se(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Se(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new J,ctx:{common:e.parent.common,data:e.data,parsedType:Se(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Zt(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 r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){var r;const s={common:{issues:[],async:(r=t==null?void 0:t.async)!==null&&r!==void 0?r:!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Se(e)},a=this._parseSync({data:e,path:s.path,parent:s});return Er(s,a)}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Se(e)},s=this._parse({data:e,path:r.path,parent:r}),a=await(Zt(s)?s:Promise.resolve(s));return Er(r,a)}refine(e,t){const r=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,a)=>{const i=e(s),o=()=>a.addIssue({code:h.custom,...r(s)});return typeof Promise<"u"&&i instanceof Promise?i.then(d=>d?!0:(o(),!1)):i?!0:(o(),!1)})}refinement(e,t){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof t=="function"?t(r,s):t),!1))}_refinement(e){return new ue({schema:this,typeName:O.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return be.create(this,this._def)}nullable(){return Ne.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return de.create(this,this._def)}promise(){return ct.create(this,this._def)}or(e){return Pt.create([this,e],this._def)}and(e){return Nt.create(this,e,this._def)}transform(e){return new ue({...E(this._def),schema:this,typeName:O.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new Lt({...E(this._def),innerType:this,defaultValue:t,typeName:O.ZodDefault})}brand(){return new Qn({typeName:O.ZodBranded,type:this,...E(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Vt({...E(this._def),innerType:this,catchValue:t,typeName:O.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Ut.create(this,e)}readonly(){return qt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const ba=/^c[^\s-]{8,}$/i,ka=/^[0-9a-z]+$/,wa=/^[0-9A-HJKMNP-TV-Z]{26}$/,xa=/^[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,Oa=/^[a-z0-9_-]{21}$/i,Ta=/^[-+]?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)?)??$/,ja=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Za="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Yn;const Ra=/^(?:(?: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])$/,Ea=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,Sa=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Sr="((\\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])))",Ca=new RegExp(`^${Sr}$`);function Cr(n){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return n.precision?e=`${e}\\.\\d{${n.precision}}`:n.precision==null&&(e=`${e}(\\.\\d+)?`),e}function Ia(n){return new RegExp(`^${Cr(n)}$`)}function Ir(n){let e=`${Sr}T${Cr(n)}`;const t=[];return t.push(n.local?"Z?":"Z"),n.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Pa(n,e){return!!((e==="v4"||!e)&&Ra.test(n)||(e==="v6"||!e)&&Ea.test(n))}class ce extends I{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==v.string){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_type,expected:v.string,received:a.parsedType}),j}const r=new J;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),g(s,{code:h.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="max")e.data.length>a.value&&(s=this._getOrReturnCtx(e,s),g(s,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="length"){const i=e.data.length>a.value,o=e.data.length<a.value;(i||o)&&(s=this._getOrReturnCtx(e,s),i?g(s,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&g(s,{code:h.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),r.dirty())}else if(a.kind==="email")ja.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"email",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="emoji")Yn||(Yn=new RegExp(Za,"u")),Yn.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"emoji",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="uuid")xa.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"uuid",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="nanoid")Oa.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"nanoid",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid")ba.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"cuid",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid2")ka.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"cuid2",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="ulid")wa.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"ulid",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),g(s,{validation:"url",code:h.invalid_string,message:a.message}),r.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"regex",code:h.invalid_string,message:a.message}),r.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(s=this._getOrReturnCtx(e,s),g(s,{code:h.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),r.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(s=this._getOrReturnCtx(e,s),g(s,{code:h.invalid_string,validation:{startsWith:a.value},message:a.message}),r.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(s=this._getOrReturnCtx(e,s),g(s,{code:h.invalid_string,validation:{endsWith:a.value},message:a.message}),r.dirty()):a.kind==="datetime"?Ir(a).test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{code:h.invalid_string,validation:"datetime",message:a.message}),r.dirty()):a.kind==="date"?Ca.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{code:h.invalid_string,validation:"date",message:a.message}),r.dirty()):a.kind==="time"?Ia(a).test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{code:h.invalid_string,validation:"time",message:a.message}),r.dirty()):a.kind==="duration"?Ta.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"duration",code:h.invalid_string,message:a.message}),r.dirty()):a.kind==="ip"?Pa(e.data,a.version)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"ip",code:h.invalid_string,message:a.message}),r.dirty()):a.kind==="base64"?Sa.test(e.data)||(s=this._getOrReturnCtx(e,s),g(s,{validation:"base64",code:h.invalid_string,message:a.message}),r.dirty()):A.assertNever(a);return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement(s=>e.test(s),{validation:t,code:h.invalid_string,...w.errToObj(r)})}_addCheck(e){return new ce({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...w.errToObj(e)})}url(e){return this._addCheck({kind:"url",...w.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...w.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...w.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...w.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...w.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...w.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...w.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...w.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...w.errToObj(e)})}datetime(e){var t,r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(t=e==null?void 0:e.offset)!==null&&t!==void 0?t:!1,local:(r=e==null?void 0:e.local)!==null&&r!==void 0?r:!1,...w.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...w.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...w.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...w.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...w.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...w.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...w.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...w.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...w.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...w.errToObj(t)})}nonempty(e){return this.min(1,w.errToObj(e))}trim(){return new ce({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new ce({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new ce({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}ce.create=n=>{var e;return new ce({checks:[],typeName:O.ZodString,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...E(n)})};function Na(n,e){const t=(n.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=t>r?t:r,a=parseInt(n.toFixed(s).replace(".","")),i=parseInt(e.toFixed(s).replace(".",""));return a%i/Math.pow(10,s)}class Ce extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==v.number){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_type,expected:v.number,received:a.parsedType}),j}let r;const s=new J;for(const a of this._def.checks)a.kind==="int"?A.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{code:h.invalid_type,expected:"integer",received:"float",message:a.message}),s.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(r=this._getOrReturnCtx(e,r),g(r,{code:h.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(r=this._getOrReturnCtx(e,r),g(r,{code:h.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?Na(e.data,a.value)!==0&&(r=this._getOrReturnCtx(e,r),g(r,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),g(r,{code:h.not_finite,message:a.message}),s.dirty()):A.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,w.toString(t))}gt(e,t){return this.setLimit("min",e,!1,w.toString(t))}lte(e,t){return this.setLimit("max",e,!0,w.toString(t))}lt(e,t){return this.setLimit("max",e,!1,w.toString(t))}setLimit(e,t,r,s){return new Ce({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:w.toString(s)}]})}_addCheck(e){return new Ce({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:w.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:w.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:w.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:w.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:w.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:w.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:w.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:w.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:w.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&A.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(t===null||r.value>t)&&(t=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Ce.create=n=>new Ce({checks:[],typeName:O.ZodNumber,coerce:(n==null?void 0:n.coerce)||!1,...E(n)});class Ie extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==v.bigint){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_type,expected:v.bigint,received:a.parsedType}),j}let r;const s=new J;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(r=this._getOrReturnCtx(e,r),g(r,{code:h.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(r=this._getOrReturnCtx(e,r),g(r,{code:h.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),g(r,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):A.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,w.toString(t))}gt(e,t){return this.setLimit("min",e,!1,w.toString(t))}lte(e,t){return this.setLimit("max",e,!0,w.toString(t))}lt(e,t){return this.setLimit("max",e,!1,w.toString(t))}setLimit(e,t,r,s){return new Ie({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:w.toString(s)}]})}_addCheck(e){return new Ie({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:w.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:w.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:w.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:w.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:w.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Ie.create=n=>{var e;return new Ie({checks:[],typeName:O.ZodBigInt,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...E(n)})};class St extends I{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==v.boolean){const r=this._getOrReturnCtx(e);return g(r,{code:h.invalid_type,expected:v.boolean,received:r.parsedType}),j}return X(e.data)}}St.create=n=>new St({typeName:O.ZodBoolean,coerce:(n==null?void 0:n.coerce)||!1,...E(n)});class We extends I{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==v.date){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_type,expected:v.date,received:a.parsedType}),j}if(isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return g(a,{code:h.invalid_date}),j}const r=new J;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),g(s,{code:h.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(s=this._getOrReturnCtx(e,s),g(s,{code:h.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):A.assertNever(a);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new We({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:w.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:w.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}We.create=n=>new We({checks:[],coerce:(n==null?void 0:n.coerce)||!1,typeName:O.ZodDate,...E(n)});class Zn extends I{_parse(e){if(this._getType(e)!==v.symbol){const r=this._getOrReturnCtx(e);return g(r,{code:h.invalid_type,expected:v.symbol,received:r.parsedType}),j}return X(e.data)}}Zn.create=n=>new Zn({typeName:O.ZodSymbol,...E(n)});class Ct extends I{_parse(e){if(this._getType(e)!==v.undefined){const r=this._getOrReturnCtx(e);return g(r,{code:h.invalid_type,expected:v.undefined,received:r.parsedType}),j}return X(e.data)}}Ct.create=n=>new Ct({typeName:O.ZodUndefined,...E(n)});class It extends I{_parse(e){if(this._getType(e)!==v.null){const r=this._getOrReturnCtx(e);return g(r,{code:h.invalid_type,expected:v.null,received:r.parsedType}),j}return X(e.data)}}It.create=n=>new It({typeName:O.ZodNull,...E(n)});class at extends I{constructor(){super(...arguments),this._any=!0}_parse(e){return X(e.data)}}at.create=n=>new at({typeName:O.ZodAny,...E(n)});class He extends I{constructor(){super(...arguments),this._unknown=!0}_parse(e){return X(e.data)}}He.create=n=>new He({typeName:O.ZodUnknown,...E(n)});class Te extends I{_parse(e){const t=this._getOrReturnCtx(e);return g(t,{code:h.invalid_type,expected:v.never,received:t.parsedType}),j}}Te.create=n=>new Te({typeName:O.ZodNever,...E(n)});class Rn extends I{_parse(e){if(this._getType(e)!==v.undefined){const r=this._getOrReturnCtx(e);return g(r,{code:h.invalid_type,expected:v.void,received:r.parsedType}),j}return X(e.data)}}Rn.create=n=>new Rn({typeName:O.ZodVoid,...E(n)});class de extends I{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),s=this._def;if(t.parsedType!==v.array)return g(t,{code:h.invalid_type,expected:v.array,received:t.parsedType}),j;if(s.exactLength!==null){const i=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(i||o)&&(g(t,{code:i?h.too_big:h.too_small,minimum:o?s.exactLength.value:void 0,maximum:i?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(g(t,{code:h.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(g(t,{code:h.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((i,o)=>s.type._parseAsync(new ye(t,i,t.path,o)))).then(i=>J.mergeArray(r,i));const a=[...t.data].map((i,o)=>s.type._parseSync(new ye(t,i,t.path,o)));return J.mergeArray(r,a)}get element(){return this._def.type}min(e,t){return new de({...this._def,minLength:{value:e,message:w.toString(t)}})}max(e,t){return new de({...this._def,maxLength:{value:e,message:w.toString(t)}})}length(e,t){return new de({...this._def,exactLength:{value:e,message:w.toString(t)}})}nonempty(e){return this.min(1,e)}}de.create=(n,e)=>new de({type:n,minLength:null,maxLength:null,exactLength:null,typeName:O.ZodArray,...E(e)});function it(n){if(n instanceof q){const e={};for(const t in n.shape){const r=n.shape[t];e[t]=be.create(it(r))}return new q({...n._def,shape:()=>e})}else return n instanceof de?new de({...n._def,type:it(n.element)}):n instanceof be?be.create(it(n.unwrap())):n instanceof Ne?Ne.create(it(n.unwrap())):n instanceof ve?ve.create(n.items.map(e=>it(e))):n}class q extends I{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=A.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==v.object){const u=this._getOrReturnCtx(e);return g(u,{code:h.invalid_type,expected:v.object,received:u.parsedType}),j}const{status:r,ctx:s}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof Te&&this._def.unknownKeys==="strip"))for(const u in s.data)i.includes(u)||o.push(u);const d=[];for(const u of i){const l=a[u],p=s.data[u];d.push({key:{status:"valid",value:u},value:l._parse(new ye(s,p,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof Te){const u=this._def.unknownKeys;if(u==="passthrough")for(const l of o)d.push({key:{status:"valid",value:l},value:{status:"valid",value:s.data[l]}});else if(u==="strict")o.length>0&&(g(s,{code:h.unrecognized_keys,keys:o}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const l of o){const p=s.data[l];d.push({key:{status:"valid",value:l},value:u._parse(new ye(s,p,s.path,l)),alwaysSet:l in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const l of d){const p=await l.key,C=await l.value;u.push({key:p,value:C,alwaysSet:l.alwaysSet})}return u}).then(u=>J.mergeObjectSync(r,u)):J.mergeObjectSync(r,d)}get shape(){return this._def.shape()}strict(e){return w.errToObj,new q({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{var s,a,i,o;const d=(i=(a=(s=this._def).errorMap)===null||a===void 0?void 0:a.call(s,t,r).message)!==null&&i!==void 0?i:r.defaultError;return t.code==="unrecognized_keys"?{message:(o=w.errToObj(e).message)!==null&&o!==void 0?o:d}:{message:d}}}:{}})}strip(){return new q({...this._def,unknownKeys:"strip"})}passthrough(){return new q({...this._def,unknownKeys:"passthrough"})}extend(e){return new q({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new q({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:O.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new q({...this._def,catchall:e})}pick(e){const t={};return A.objectKeys(e).forEach(r=>{e[r]&&this.shape[r]&&(t[r]=this.shape[r])}),new q({...this._def,shape:()=>t})}omit(e){const t={};return A.objectKeys(this.shape).forEach(r=>{e[r]||(t[r]=this.shape[r])}),new q({...this._def,shape:()=>t})}deepPartial(){return it(this)}partial(e){const t={};return A.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];e&&!e[r]?t[r]=s:t[r]=s.optional()}),new q({...this._def,shape:()=>t})}required(e){const t={};return A.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])t[r]=this.shape[r];else{let a=this.shape[r];for(;a instanceof be;)a=a._def.innerType;t[r]=a}}),new q({...this._def,shape:()=>t})}keyof(){return Pr(A.objectKeys(this.shape))}}q.create=(n,e)=>new q({shape:()=>n,unknownKeys:"strip",catchall:Te.create(),typeName:O.ZodObject,...E(e)}),q.strictCreate=(n,e)=>new q({shape:()=>n,unknownKeys:"strict",catchall:Te.create(),typeName:O.ZodObject,...E(e)}),q.lazycreate=(n,e)=>new q({shape:n,unknownKeys:"strip",catchall:Te.create(),typeName:O.ZodObject,...E(e)});class Pt extends I{_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;function s(a){for(const o of a)if(o.result.status==="valid")return o.result;for(const o of a)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const i=a.map(o=>new ne(o.ctx.common.issues));return g(t,{code:h.invalid_union,unionErrors:i}),j}if(t.common.async)return Promise.all(r.map(async a=>{const i={...t,common:{...t.common,issues:[]},parent:null};return{result:await a._parseAsync({data:t.data,path:t.path,parent:i}),ctx:i}})).then(s);{let a;const i=[];for(const d of r){const u={...t,common:{...t.common,issues:[]},parent:null},l=d._parseSync({data:t.data,path:t.path,parent:u});if(l.status==="valid")return l;l.status==="dirty"&&!a&&(a={result:l,ctx:u}),u.common.issues.length&&i.push(u.common.issues)}if(a)return t.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(d=>new ne(d));return g(t,{code:h.invalid_union,unionErrors:o}),j}}get options(){return this._def.options}}Pt.create=(n,e)=>new Pt({options:n,typeName:O.ZodUnion,...E(e)});const je=n=>n instanceof $t?je(n.schema):n instanceof ue?je(n.innerType()):n instanceof Mt?[n.value]:n instanceof Pe?n.options:n instanceof Dt?A.objectValues(n.enum):n instanceof Lt?je(n._def.innerType):n instanceof Ct?[void 0]:n instanceof It?[null]:n instanceof be?[void 0,...je(n.unwrap())]:n instanceof Ne?[null,...je(n.unwrap())]:n instanceof Qn||n instanceof qt?je(n.unwrap()):n instanceof Vt?je(n._def.innerType):[];class En extends I{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==v.object)return g(t,{code:h.invalid_type,expected:v.object,received:t.parsedType}),j;const r=this.discriminator,s=t.data[r],a=this.optionsMap.get(s);return a?t.common.async?a._parseAsync({data:t.data,path:t.path,parent:t}):a._parseSync({data:t.data,path:t.path,parent:t}):(g(t,{code:h.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),j)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){const s=new Map;for(const a of t){const i=je(a.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of i){if(s.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);s.set(o,a)}}return new En({typeName:O.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...E(r)})}}function Jn(n,e){const t=Se(n),r=Se(e);if(n===e)return{valid:!0,data:n};if(t===v.object&&r===v.object){const s=A.objectKeys(e),a=A.objectKeys(n).filter(o=>s.indexOf(o)!==-1),i={...n,...e};for(const o of a){const d=Jn(n[o],e[o]);if(!d.valid)return{valid:!1};i[o]=d.data}return{valid:!0,data:i}}else if(t===v.array&&r===v.array){if(n.length!==e.length)return{valid:!1};const s=[];for(let a=0;a<n.length;a++){const i=n[a],o=e[a],d=Jn(i,o);if(!d.valid)return{valid:!1};s.push(d.data)}return{valid:!0,data:s}}else return t===v.date&&r===v.date&&+n==+e?{valid:!0,data:n}:{valid:!1}}class Nt extends I{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(a,i)=>{if(Gn(a)||Gn(i))return j;const o=Jn(a.value,i.value);return o.valid?((zn(a)||zn(i))&&t.dirty(),{status:t.value,value:o.data}):(g(r,{code:h.invalid_intersection_types}),j)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([a,i])=>s(a,i)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Nt.create=(n,e,t)=>new Nt({left:n,right:e,typeName:O.ZodIntersection,...E(t)});class ve extends I{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==v.array)return g(r,{code:h.invalid_type,expected:v.array,received:r.parsedType}),j;if(r.data.length<this._def.items.length)return g(r,{code:h.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),j;!this._def.rest&&r.data.length>this._def.items.length&&(g(r,{code:h.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...r.data].map((i,o)=>{const d=this._def.items[o]||this._def.rest;return d?d._parse(new ye(r,i,r.path,o)):null}).filter(i=>!!i);return r.common.async?Promise.all(a).then(i=>J.mergeArray(t,i)):J.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new ve({...this._def,rest:e})}}ve.create=(n,e)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ve({items:n,typeName:O.ZodTuple,rest:null,...E(e)})};class At extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==v.object)return g(r,{code:h.invalid_type,expected:v.object,received:r.parsedType}),j;const s=[],a=this._def.keyType,i=this._def.valueType;for(const o in r.data)s.push({key:a._parse(new ye(r,o,r.path,o)),value:i._parse(new ye(r,r.data[o],r.path,o)),alwaysSet:o in r.data});return r.common.async?J.mergeObjectAsync(t,s):J.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof I?new At({keyType:e,valueType:t,typeName:O.ZodRecord,...E(r)}):new At({keyType:ce.create(),valueType:e,typeName:O.ZodRecord,...E(t)})}}class Sn extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==v.map)return g(r,{code:h.invalid_type,expected:v.map,received:r.parsedType}),j;const s=this._def.keyType,a=this._def.valueType,i=[...r.data.entries()].map(([o,d],u)=>({key:s._parse(new ye(r,o,r.path,[u,"key"])),value:a._parse(new ye(r,d,r.path,[u,"value"]))}));if(r.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const d of i){const u=await d.key,l=await d.value;if(u.status==="aborted"||l.status==="aborted")return j;(u.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(u.value,l.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const d of i){const u=d.key,l=d.value;if(u.status==="aborted"||l.status==="aborted")return j;(u.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(u.value,l.value)}return{status:t.value,value:o}}}}Sn.create=(n,e,t)=>new Sn({valueType:e,keyType:n,typeName:O.ZodMap,...E(t)});class Fe extends I{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==v.set)return g(r,{code:h.invalid_type,expected:v.set,received:r.parsedType}),j;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(g(r,{code:h.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(g(r,{code:h.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const a=this._def.valueType;function i(d){const u=new Set;for(const l of d){if(l.status==="aborted")return j;l.status==="dirty"&&t.dirty(),u.add(l.value)}return{status:t.value,value:u}}const o=[...r.data.values()].map((d,u)=>a._parse(new ye(r,d,r.path,u)));return r.common.async?Promise.all(o).then(d=>i(d)):i(o)}min(e,t){return new Fe({...this._def,minSize:{value:e,message:w.toString(t)}})}max(e,t){return new Fe({...this._def,maxSize:{value:e,message:w.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}Fe.create=(n,e)=>new Fe({valueType:n,minSize:null,maxSize:null,typeName:O.ZodSet,...E(e)});class ot extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==v.function)return g(t,{code:h.invalid_type,expected:v.function,received:t.parsedType}),j;function r(o,d){return Tn({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,On(),rt].filter(u=>!!u),issueData:{code:h.invalid_arguments,argumentsError:d}})}function s(o,d){return Tn({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,On(),rt].filter(u=>!!u),issueData:{code:h.invalid_return_type,returnTypeError:d}})}const a={errorMap:t.common.contextualErrorMap},i=t.data;if(this._def.returns instanceof ct){const o=this;return X(async function(...d){const u=new ne([]),l=await o._def.args.parseAsync(d,a).catch(D=>{throw u.addIssue(r(d,D)),u}),p=await Reflect.apply(i,this,l);return await o._def.returns._def.type.parseAsync(p,a).catch(D=>{throw u.addIssue(s(p,D)),u})})}else{const o=this;return X(function(...d){const u=o._def.args.safeParse(d,a);if(!u.success)throw new ne([r(d,u.error)]);const l=Reflect.apply(i,this,u.data),p=o._def.returns.safeParse(l,a);if(!p.success)throw new ne([s(l,p.error)]);return p.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new ot({...this._def,args:ve.create(e).rest(He.create())})}returns(e){return new ot({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new ot({args:e||ve.create([]).rest(He.create()),returns:t||He.create(),typeName:O.ZodFunction,...E(r)})}}class $t extends I{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}$t.create=(n,e)=>new $t({getter:n,typeName:O.ZodLazy,...E(e)});class Mt extends I{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return g(t,{received:t.data,code:h.invalid_literal,expected:this._def.value}),j}return{status:"valid",value:e.data}}get value(){return this._def.value}}Mt.create=(n,e)=>new Mt({value:n,typeName:O.ZodLiteral,...E(e)});function Pr(n,e){return new Pe({values:n,typeName:O.ZodEnum,...E(e)})}class Pe extends I{constructor(){super(...arguments),Rt.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return g(t,{expected:A.joinValues(r),received:t.parsedType,code:h.invalid_type}),j}if(jn(this,Rt)||Rr(this,Rt,new Set(this._def.values)),!jn(this,Rt).has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return g(t,{received:t.data,code:h.invalid_enum_value,options:r}),j}return X(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return Pe.create(e,{...this._def,...t})}exclude(e,t=this._def){return Pe.create(this.options.filter(r=>!e.includes(r)),{...this._def,...t})}}Rt=new WeakMap,Pe.create=Pr;class Dt extends I{constructor(){super(...arguments),Et.set(this,void 0)}_parse(e){const t=A.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==v.string&&r.parsedType!==v.number){const s=A.objectValues(t);return g(r,{expected:A.joinValues(s),received:r.parsedType,code:h.invalid_type}),j}if(jn(this,Et)||Rr(this,Et,new Set(A.getValidEnumValues(this._def.values))),!jn(this,Et).has(e.data)){const s=A.objectValues(t);return g(r,{received:r.data,code:h.invalid_enum_value,options:s}),j}return X(e.data)}get enum(){return this._def.values}}Et=new WeakMap,Dt.create=(n,e)=>new Dt({values:n,typeName:O.ZodNativeEnum,...E(e)});class ct extends I{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==v.promise&&t.common.async===!1)return g(t,{code:h.invalid_type,expected:v.promise,received:t.parsedType}),j;const r=t.parsedType===v.promise?t.data:Promise.resolve(t.data);return X(r.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}ct.create=(n,e)=>new ct({type:n,typeName:O.ZodPromise,...E(e)});class ue extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===O.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=this._def.effect||null,a={addIssue:i=>{g(r,i),i.fatal?t.abort():t.dirty()},get path(){return r.path}};if(a.addIssue=a.addIssue.bind(a),s.type==="preprocess"){const i=s.transform(r.data,a);if(r.common.async)return Promise.resolve(i).then(async o=>{if(t.value==="aborted")return j;const d=await this._def.schema._parseAsync({data:o,path:r.path,parent:r});return d.status==="aborted"?j:d.status==="dirty"||t.value==="dirty"?st(d.value):d});{if(t.value==="aborted")return j;const o=this._def.schema._parseSync({data:i,path:r.path,parent:r});return o.status==="aborted"?j:o.status==="dirty"||t.value==="dirty"?st(o.value):o}}if(s.type==="refinement"){const i=o=>{const d=s.refinement(o,a);if(r.common.async)return Promise.resolve(d);if(d instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?j:(o.status==="dirty"&&t.dirty(),i(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>o.status==="aborted"?j:(o.status==="dirty"&&t.dirty(),i(o.value).then(()=>({status:t.value,value:o.value}))))}if(s.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!jt(i))return i;const o=s.transform(i.value,a);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>jt(i)?Promise.resolve(s.transform(i.value,a)).then(o=>({status:t.value,value:o})):i);A.assertNever(s)}}ue.create=(n,e,t)=>new ue({schema:n,typeName:O.ZodEffects,effect:e,...E(t)}),ue.createWithPreprocess=(n,e,t)=>new ue({schema:e,effect:{type:"preprocess",transform:n},typeName:O.ZodEffects,...E(t)});class be extends I{_parse(e){return this._getType(e)===v.undefined?X(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}be.create=(n,e)=>new be({innerType:n,typeName:O.ZodOptional,...E(e)});class Ne extends I{_parse(e){return this._getType(e)===v.null?X(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ne.create=(n,e)=>new Ne({innerType:n,typeName:O.ZodNullable,...E(e)});class Lt extends I{_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===v.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Lt.create=(n,e)=>new Lt({innerType:n,typeName:O.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...E(e)});class Vt extends I{_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Zt(s)?s.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new ne(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new ne(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Vt.create=(n,e)=>new Vt({innerType:n,typeName:O.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...E(e)});class Cn extends I{_parse(e){if(this._getType(e)!==v.nan){const r=this._getOrReturnCtx(e);return g(r,{code:h.invalid_type,expected:v.nan,received:r.parsedType}),j}return{status:"valid",value:e.data}}}Cn.create=n=>new Cn({typeName:O.ZodNaN,...E(n)});const Aa=Symbol("zod_brand");class Qn extends I{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class Ut extends I{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?j:a.status==="dirty"?(t.dirty(),st(a.value)):this._def.out._parseAsync({data:a.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?j:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,t){return new Ut({in:e,out:t,typeName:O.ZodPipeline})}}class qt extends I{_parse(e){const t=this._def.innerType._parse(e),r=s=>(jt(s)&&(s.value=Object.freeze(s.value)),s);return Zt(t)?t.then(s=>r(s)):r(t)}unwrap(){return this._def.innerType}}qt.create=(n,e)=>new qt({innerType:n,typeName:O.ZodReadonly,...E(e)});function Nr(n,e={},t){return n?at.create().superRefine((r,s)=>{var a,i;if(!n(r)){const o=typeof e=="function"?e(r):typeof e=="string"?{message:e}:e,d=(i=(a=o.fatal)!==null&&a!==void 0?a:t)!==null&&i!==void 0?i:!0,u=typeof o=="string"?{message:o}:o;s.addIssue({code:"custom",...u,fatal:d})}}):at.create()}const $a={object:q.lazycreate};var O;(function(n){n.ZodString="ZodString",n.ZodNumber="ZodNumber",n.ZodNaN="ZodNaN",n.ZodBigInt="ZodBigInt",n.ZodBoolean="ZodBoolean",n.ZodDate="ZodDate",n.ZodSymbol="ZodSymbol",n.ZodUndefined="ZodUndefined",n.ZodNull="ZodNull",n.ZodAny="ZodAny",n.ZodUnknown="ZodUnknown",n.ZodNever="ZodNever",n.ZodVoid="ZodVoid",n.ZodArray="ZodArray",n.ZodObject="ZodObject",n.ZodUnion="ZodUnion",n.ZodDiscriminatedUnion="ZodDiscriminatedUnion",n.ZodIntersection="ZodIntersection",n.ZodTuple="ZodTuple",n.ZodRecord="ZodRecord",n.ZodMap="ZodMap",n.ZodSet="ZodSet",n.ZodFunction="ZodFunction",n.ZodLazy="ZodLazy",n.ZodLiteral="ZodLiteral",n.ZodEnum="ZodEnum",n.ZodEffects="ZodEffects",n.ZodNativeEnum="ZodNativeEnum",n.ZodOptional="ZodOptional",n.ZodNullable="ZodNullable",n.ZodDefault="ZodDefault",n.ZodCatch="ZodCatch",n.ZodPromise="ZodPromise",n.ZodBranded="ZodBranded",n.ZodPipeline="ZodPipeline",n.ZodReadonly="ZodReadonly"})(O||(O={}));const Ma=(n,e={message:`Input not instance of ${n.name}`})=>Nr(t=>t instanceof n,e),Ar=ce.create,$r=Ce.create,Da=Cn.create,La=Ie.create,Mr=St.create,Va=We.create,Ua=Zn.create,qa=Ct.create,Ba=It.create,Wa=at.create,Ha=He.create,Fa=Te.create,Ka=Rn.create,Ga=de.create,za=q.create,Ya=q.strictCreate,Ja=Pt.create,Qa=En.create,Xa=Nt.create,ei=ve.create,ti=At.create,ni=Sn.create,ri=Fe.create,si=ot.create,ai=$t.create,ii=Mt.create,oi=Pe.create,ci=Dt.create,di=ct.create,Dr=ue.create,ui=be.create,li=Ne.create,pi=ue.createWithPreprocess,hi=Ut.create;var z=Object.freeze({__proto__:null,defaultErrorMap:rt,setErrorMap:ya,getErrorMap:On,makeIssue:Tn,EMPTY_PATH:va,addIssueToContext:g,ParseStatus:J,INVALID:j,DIRTY:st,OK:X,isAborted:Gn,isDirty:zn,isValid:jt,isAsync:Zt,get util(){return A},get objectUtil(){return Kn},ZodParsedType:v,getParsedType:Se,ZodType:I,datetimeRegex:Ir,ZodString:ce,ZodNumber:Ce,ZodBigInt:Ie,ZodBoolean:St,ZodDate:We,ZodSymbol:Zn,ZodUndefined:Ct,ZodNull:It,ZodAny:at,ZodUnknown:He,ZodNever:Te,ZodVoid:Rn,ZodArray:de,ZodObject:q,ZodUnion:Pt,ZodDiscriminatedUnion:En,ZodIntersection:Nt,ZodTuple:ve,ZodRecord:At,ZodMap:Sn,ZodSet:Fe,ZodFunction:ot,ZodLazy:$t,ZodLiteral:Mt,ZodEnum:Pe,ZodNativeEnum:Dt,ZodPromise:ct,ZodEffects:ue,ZodTransformer:ue,ZodOptional:be,ZodNullable:Ne,ZodDefault:Lt,ZodCatch:Vt,ZodNaN:Cn,BRAND:Aa,ZodBranded:Qn,ZodPipeline:Ut,ZodReadonly:qt,custom:Nr,Schema:I,ZodSchema:I,late:$a,get ZodFirstPartyTypeKind(){return O},coerce:{string:n=>ce.create({...n,coerce:!0}),number:n=>Ce.create({...n,coerce:!0}),boolean:n=>St.create({...n,coerce:!0}),bigint:n=>Ie.create({...n,coerce:!0}),date:n=>We.create({...n,coerce:!0})},any:Wa,array:Ga,bigint:La,boolean:Mr,date:Va,discriminatedUnion:Qa,effect:Dr,enum:oi,function:si,instanceof:Ma,intersection:Xa,lazy:ai,literal:ii,map:ni,nan:Da,nativeEnum:ci,never:Fa,null:Ba,nullable:li,number:$r,object:za,oboolean:()=>Mr().optional(),onumber:()=>$r().optional(),optional:ui,ostring:()=>Ar().optional(),pipeline:hi,preprocess:pi,promise:di,record:ti,set:ri,strictObject:Ya,string:Ar,symbol:Ua,transformer:Dr,tuple:ei,undefined:qa,union:Ja,unknown:Ha,void:Ka,NEVER:j,ZodIssueCode:h,quotelessJson:_a,ZodError:ne}),Bt=class cr extends ga{constructor(t){super(t);y(this,"openAPIRegistry");y(this,"defaultHook");y(this,"openapi",({middleware:t,...r},s,a=this.defaultHook)=>{var u,l,p,C,D,N;this.openAPIRegistry.registerPath(r);const i=[];if((u=r.request)!=null&&u.query){const R=tt("query",r.request.query,a);i.push(R)}if((l=r.request)!=null&&l.params){const R=tt("param",r.request.params,a);i.push(R)}if((p=r.request)!=null&&p.headers){const R=tt("header",r.request.headers,a);i.push(R)}if((C=r.request)!=null&&C.cookies){const R=tt("cookie",r.request.cookies,a);i.push(R)}const o=(N=(D=r.request)==null?void 0:D.body)==null?void 0:N.content;if(o)for(const R of Object.keys(o)){if(!o[R])continue;const H=o[R].schema;if(H instanceof I){if(R.startsWith("application/json")){const K=tt("json",H,a);i.push(K)}if(R.startsWith("multipart/form-data")||R.startsWith("application/x-www-form-urlencoded")){const K=tt("form",H,a);i.push(K)}}}const d=t?Array.isArray(t)?t:[t]:[];return this.on([r.method],r.path.replaceAll(/\/{(.+?)}/g,"/:$1"),...d,...i,s),this});y(this,"getOpenAPIDocument",t=>new Ps(this.openAPIRegistry.definitions).generateDocument(t));y(this,"getOpenAPI31Document",t=>new $s(this.openAPIRegistry.definitions).generateDocument(t));y(this,"doc",(t,r)=>this.get(t,s=>{const a=typeof r=="function"?r(s):r;try{const i=this.getOpenAPIDocument(a);return s.json(i)}catch(i){return s.json(i,500)}}));y(this,"doc31",(t,r)=>this.get(t,s=>{const a=typeof r=="function"?r(s):r;try{const i=this.getOpenAPI31Document(a);return s.json(i)}catch(i){return s.json(i,500)}}));this.openAPIRegistry=new ms,this.defaultHook=t==null?void 0:t.defaultHook}route(t,r){const s=t.replaceAll(/:([^\/]+)/g,"{$1}");return super.route(t,r),r instanceof cr?(r.openAPIRegistry.definitions.forEach(a=>{switch(a.type){case"component":return this.openAPIRegistry.registerComponent(a.componentType,a.name,a.component);case"route":return this.openAPIRegistry.registerPath({...a.route,path:Be(s,a.route.path)});case"webhook":return this.openAPIRegistry.registerWebhook({...a.webhook,path:Be(s,a.webhook.path)});case"schema":return this.openAPIRegistry.register(a.schema._def.openapi._internal.refId,a.schema);case"parameter":return this.openAPIRegistry.registerParameter(a.schema._def.openapi._internal.refId,a.schema);default:{const i=a;throw new Error(`Unknown registry type: ${i}`)}}}),this):this}basePath(t){return new cr({...super.basePath(t),defaultHook:this.defaultHook})}},Ke=n=>{const e={...n,getRoutingPath(){return n.path.replaceAll(/\/{(.+?)}/g,"/:$1")}};return Object.defineProperty(e,"getRoutingPath",{enumerable:!1})};ls(z);function fi(n,e){var t={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(n);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(n,r[s])&&(t[r[s]]=n[r[s]]);return t}function mi(n,e){var t;return((t=n==null?void 0:n._def)===null||t===void 0?void 0:t.typeName)===e}function Wt(n,e){const t=n.ZodType.prototype[e];n.ZodType.prototype[e]=function(...r){const s=t.apply(this,r);return s._def.openapi=this._def.openapi,s}}function gi(n){if(typeof n.ZodType.prototype.openapi<"u")return;n.ZodType.prototype.openapi=function(s,a){var i,o,d,u,l,p;const C=typeof s=="string"?a:s,D=C??{},{param:N}=D,R=fi(D,["param"]),H=Object.assign(Object.assign({},(i=this._def.openapi)===null||i===void 0?void 0:i._internal),typeof s=="string"?{refId:s}:void 0),K=Object.assign(Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o.metadata),R),!((u=(d=this._def.openapi)===null||d===void 0?void 0:d.metadata)===null||u===void 0)&&u.param||N?{param:Object.assign(Object.assign({},(p=(l=this._def.openapi)===null||l===void 0?void 0:l.metadata)===null||p===void 0?void 0:p.param),N)}:void 0),se=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(K).length>0?{metadata:K}:void 0)}));if(mi(this,"ZodObject")){const ae=this.extend;se.extend=function(...qe){var oe,ie,te,Oe,_e,Qe;const Xe=ae.apply(this,qe);return Xe._def.openapi={_internal:{extendedFrom:!((ie=(oe=this._def.openapi)===null||oe===void 0?void 0:oe._internal)===null||ie===void 0)&&ie.refId?{refId:(Oe=(te=this._def.openapi)===null||te===void 0?void 0:te._internal)===null||Oe===void 0?void 0:Oe.refId,schema:this}:(_e=this._def.openapi)===null||_e===void 0?void 0:_e._internal.extendedFrom},metadata:(Qe=Xe._def.openapi)===null||Qe===void 0?void 0:Qe.metadata},Xe}}return se},Wt(n,"optional"),Wt(n,"nullable"),Wt(n,"default"),Wt(n,"transform"),Wt(n,"refine");const e=n.ZodObject.prototype.deepPartial;n.ZodObject.prototype.deepPartial=function(){const s=this._def.shape(),a=e.apply(this),i=a._def.shape();return Object.entries(i).forEach(([o,d])=>{var u,l;d._def.openapi=(l=(u=s[o])===null||u===void 0?void 0:u._def)===null||l===void 0?void 0:l.openapi}),a._def.openapi=void 0,a};const t=n.ZodObject.prototype.pick;n.ZodObject.prototype.pick=function(...s){const a=t.apply(this,s);return a._def.openapi=void 0,a};const r=n.ZodObject.prototype.omit;n.ZodObject.prototype.omit=function(...s){const a=r.apply(this,s);return a._def.openapi=void 0,a}}new Set(".\\+*[^]$()");var $;(function(n){n.assertEqual=s=>s;function e(s){}n.assertIs=e;function t(s){throw new Error}n.assertNever=t,n.arrayToEnum=s=>{const a={};for(const i of s)a[i]=i;return a},n.getValidEnumValues=s=>{const a=n.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),i={};for(const o of a)i[o]=s[o];return n.objectValues(i)},n.objectValues=s=>n.objectKeys(s).map(function(a){return s[a]}),n.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const a=[];for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&a.push(i);return a},n.find=(s,a)=>{for(const i of s)if(a(i))return i},n.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function r(s,a=" | "){return s.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}n.joinValues=r,n.jsonStringifyReplacer=(s,a)=>typeof a=="bigint"?a.toString():a})($||($={}));var Xn;(function(n){n.mergeShapes=(e,t)=>({...e,...t})})(Xn||(Xn={}));const b=$.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ae=n=>{switch(typeof n){case"undefined":return b.undefined;case"string":return b.string;case"number":return isNaN(n)?b.nan:b.number;case"boolean":return b.boolean;case"function":return b.function;case"bigint":return b.bigint;case"symbol":return b.symbol;case"object":return Array.isArray(n)?b.array:n===null?b.null:n.then&&typeof n.then=="function"&&n.catch&&typeof n.catch=="function"?b.promise:typeof Map<"u"&&n instanceof Map?b.map:typeof Set<"u"&&n instanceof Set?b.set:typeof Date<"u"&&n instanceof Date?b.date:b.object;default:return b.unknown}},f=$.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"]),_i=n=>JSON.stringify(n,null,2).replace(/"([^"]+)":/g,"$1:");class re extends Error{constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const t=e||function(a){return a.message},r={_errors:[]},s=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(s);else if(i.code==="invalid_return_type")s(i.returnTypeError);else if(i.code==="invalid_arguments")s(i.argumentsError);else if(i.path.length===0)r._errors.push(t(i));else{let o=r,d=0;for(;d<i.path.length;){const u=i.path[d];d===i.path.length-1?(o[u]=o[u]||{_errors:[]},o[u]._errors.push(t(i))):o[u]=o[u]||{_errors:[]},o=o[u],d++}}};return s(this),r}static assert(e){if(!(e instanceof re))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,$.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},r=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}re.create=n=>new re(n);const dt=(n,e)=>{let t;switch(n.code){case f.invalid_type:n.received===b.undefined?t="Required":t=`Expected ${n.expected}, received ${n.received}`;break;case f.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(n.expected,$.jsonStringifyReplacer)}`;break;case f.unrecognized_keys:t=`Unrecognized key(s) in object: ${$.joinValues(n.keys,", ")}`;break;case f.invalid_union:t="Invalid input";break;case f.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${$.joinValues(n.options)}`;break;case f.invalid_enum_value:t=`Invalid enum value. Expected ${$.joinValues(n.options)}, received '${n.received}'`;break;case f.invalid_arguments:t="Invalid function arguments";break;case f.invalid_return_type:t="Invalid function return type";break;case f.invalid_date:t="Invalid date";break;case f.invalid_string:typeof n.validation=="object"?"includes"in n.validation?(t=`Invalid input: must include "${n.validation.includes}"`,typeof n.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${n.validation.position}`)):"startsWith"in n.validation?t=`Invalid input: must start with "${n.validation.startsWith}"`:"endsWith"in n.validation?t=`Invalid input: must end with "${n.validation.endsWith}"`:$.assertNever(n.validation):n.validation!=="regex"?t=`Invalid ${n.validation}`:t="Invalid";break;case f.too_small:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at least":"more than"} ${n.minimum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at least":"over"} ${n.minimum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(n.minimum))}`:t="Invalid input";break;case f.too_big:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at most":"less than"} ${n.maximum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at most":"under"} ${n.maximum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="bigint"?t=`BigInt must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly":n.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(n.maximum))}`:t="Invalid input";break;case f.custom:t="Invalid input";break;case f.invalid_intersection_types:t="Intersection results could not be merged";break;case f.not_multiple_of:t=`Number must be a multiple of ${n.multipleOf}`;break;case f.not_finite:t="Number must be finite";break;default:t=e.defaultError,$.assertNever(n)}return{message:t}};let Lr=dt;function yi(n){Lr=n}function In(){return Lr}const Pn=n=>{const{data:e,path:t,errorMaps:r,issueData:s}=n,a=[...t,...s.path||[]],i={...s,path:a};if(s.message!==void 0)return{...s,path:a,message:s.message};let o="";const d=r.filter(u=>!!u).slice().reverse();for(const u of d)o=u(i,{data:e,defaultError:o}).message;return{...s,path:a,message:o}},vi=[];function _(n,e){const t=In(),r=Pn({issueData:e,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,t,t===dt?void 0:dt].filter(s=>!!s)});n.common.issues.push(r)}class Q{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const s of t){if(s.status==="aborted")return Z;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const s of t){const a=await s.key,i=await s.value;r.push({key:a,value:i})}return Q.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const s of t){const{key:a,value:i}=s;if(a.status==="aborted"||i.status==="aborted")return Z;a.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||s.alwaysSet)&&(r[a.value]=i.value)}return{status:e.value,value:r}}}const Z=Object.freeze({status:"aborted"}),Nn=n=>({status:"dirty",value:n}),ee=n=>({status:"valid",value:n}),er=n=>n.status==="aborted",tr=n=>n.status==="dirty",Ht=n=>n.status==="valid",Ft=n=>typeof Promise<"u"&&n instanceof Promise;function An(n,e,t,r){if(typeof e=="function"?n!==e||!r:!e.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(n)}function Vr(n,e,t,r,s){if(typeof e=="function"?n!==e||!s:!e.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(n,t),t}var x;(function(n){n.errToObj=e=>typeof e=="string"?{message:e}:e||{},n.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(x||(x={}));var Kt,Gt;class ke{constructor(e,t,r,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Ur=(n,e)=>{if(Ht(e))return{success:!0,data:e.value};if(!n.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 re(n.common.issues);return this._error=t,this._error}}};function S(n){if(!n)return{};const{errorMap:e,invalid_type_error:t,required_error:r,description:s}=n;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(a,i)=>{var o,d;const{message:u}=n;return a.code==="invalid_enum_value"?{message:u??i.defaultError}:typeof i.data>"u"?{message:(o=u??r)!==null&&o!==void 0?o:i.defaultError}:a.code!=="invalid_type"?{message:i.defaultError}:{message:(d=u??t)!==null&&d!==void 0?d:i.defaultError}},description:s}}class P{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)}get description(){return this._def.description}_getType(e){return Ae(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Ae(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new Q,ctx:{common:e.parent.common,data:e.data,parsedType:Ae(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Ft(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 r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){var r;const s={common:{issues:[],async:(r=t==null?void 0:t.async)!==null&&r!==void 0?r:!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ae(e)},a=this._parseSync({data:e,path:s.path,parent:s});return Ur(s,a)}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ae(e)},s=this._parse({data:e,path:r.path,parent:r}),a=await(Ft(s)?s:Promise.resolve(s));return Ur(r,a)}refine(e,t){const r=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,a)=>{const i=e(s),o=()=>a.addIssue({code:f.custom,...r(s)});return typeof Promise<"u"&&i instanceof Promise?i.then(d=>d?!0:(o(),!1)):i?!0:(o(),!1)})}refinement(e,t){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof t=="function"?t(r,s):t),!1))}_refinement(e){return new he({schema:this,typeName:T.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return xe.create(this,this._def)}nullable(){return Ve.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return pe.create(this,this._def)}promise(){return ht.create(this,this._def)}or(e){return Qt.create([this,e],this._def)}and(e){return Xt.create(this,e,this._def)}transform(e){return new he({...S(this._def),schema:this,typeName:T.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new sn({...S(this._def),innerType:this,defaultValue:t,typeName:T.ZodDefault})}brand(){return new sr({typeName:T.ZodBranded,type:this,...S(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new an({...S(this._def),innerType:this,catchValue:t,typeName:T.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return on.create(this,e)}readonly(){return cn.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const bi=/^c[^\s-]{8,}$/i,ki=/^[0-9a-z]+$/,wi=/^[0-9A-HJKMNP-TV-Z]{26}$/,xi=/^[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,Oi=/^[a-z0-9_-]{21}$/i,Ti=/^[-+]?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)?)??$/,ji=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Zi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let nr;const Ri=/^(?:(?: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])$/,Ei=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,Si=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,qr="((\\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])))",Ci=new RegExp(`^${qr}$`);function Br(n){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return n.precision?e=`${e}\\.\\d{${n.precision}}`:n.precision==null&&(e=`${e}(\\.\\d+)?`),e}function Ii(n){return new RegExp(`^${Br(n)}$`)}function Wr(n){let e=`${qr}T${Br(n)}`;const t=[];return t.push(n.local?"Z?":"Z"),n.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Pi(n,e){return!!((e==="v4"||!e)&&Ri.test(n)||(e==="v6"||!e)&&Ei.test(n))}class le extends P{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==b.string){const s=this._getOrReturnCtx(e);return _(s,{code:f.invalid_type,expected:b.string,received:s.parsedType}),Z}const t=new Q;let r;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(r=this._getOrReturnCtx(e,r),_(r,{code:f.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),t.dirty());else if(s.kind==="max")e.data.length>s.value&&(r=this._getOrReturnCtx(e,r),_(r,{code:f.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),t.dirty());else if(s.kind==="length"){const a=e.data.length>s.value,i=e.data.length<s.value;(a||i)&&(r=this._getOrReturnCtx(e,r),a?_(r,{code:f.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):i&&_(r,{code:f.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),t.dirty())}else if(s.kind==="email")ji.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"email",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="emoji")nr||(nr=new RegExp(Zi,"u")),nr.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"emoji",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="uuid")xi.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"uuid",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="nanoid")Oi.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"nanoid",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="cuid")bi.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"cuid",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="cuid2")ki.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"cuid2",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="ulid")wi.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"ulid",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{r=this._getOrReturnCtx(e,r),_(r,{validation:"url",code:f.invalid_string,message:s.message}),t.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"regex",code:f.invalid_string,message:s.message}),t.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(r=this._getOrReturnCtx(e,r),_(r,{code:f.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),t.dirty()):s.kind==="toLowerCase"?e.data=e.data.toLowerCase():s.kind==="toUpperCase"?e.data=e.data.toUpperCase():s.kind==="startsWith"?e.data.startsWith(s.value)||(r=this._getOrReturnCtx(e,r),_(r,{code:f.invalid_string,validation:{startsWith:s.value},message:s.message}),t.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(r=this._getOrReturnCtx(e,r),_(r,{code:f.invalid_string,validation:{endsWith:s.value},message:s.message}),t.dirty()):s.kind==="datetime"?Wr(s).test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{code:f.invalid_string,validation:"datetime",message:s.message}),t.dirty()):s.kind==="date"?Ci.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{code:f.invalid_string,validation:"date",message:s.message}),t.dirty()):s.kind==="time"?Ii(s).test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{code:f.invalid_string,validation:"time",message:s.message}),t.dirty()):s.kind==="duration"?Ti.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"duration",code:f.invalid_string,message:s.message}),t.dirty()):s.kind==="ip"?Pi(e.data,s.version)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"ip",code:f.invalid_string,message:s.message}),t.dirty()):s.kind==="base64"?Si.test(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{validation:"base64",code:f.invalid_string,message:s.message}),t.dirty()):$.assertNever(s);return{status:t.value,value:e.data}}_regex(e,t,r){return this.refinement(s=>e.test(s),{validation:t,code:f.invalid_string,...x.errToObj(r)})}_addCheck(e){return new le({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...x.errToObj(e)})}url(e){return this._addCheck({kind:"url",...x.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...x.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...x.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...x.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...x.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...x.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...x.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...x.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...x.errToObj(e)})}datetime(e){var t,r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(t=e==null?void 0:e.offset)!==null&&t!==void 0?t:!1,local:(r=e==null?void 0:e.local)!==null&&r!==void 0?r:!1,...x.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...x.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...x.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...x.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...x.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...x.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...x.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...x.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...x.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...x.errToObj(t)})}nonempty(e){return this.min(1,x.errToObj(e))}trim(){return new le({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new le({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new le({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}le.create=n=>{var e;return new le({checks:[],typeName:T.ZodString,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...S(n)})};function Ni(n,e){const t=(n.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=t>r?t:r,a=parseInt(n.toFixed(s).replace(".","")),i=parseInt(e.toFixed(s).replace(".",""));return a%i/Math.pow(10,s)}class $e extends P{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==b.number){const s=this._getOrReturnCtx(e);return _(s,{code:f.invalid_type,expected:b.number,received:s.parsedType}),Z}let t;const r=new Q;for(const s of this._def.checks)s.kind==="int"?$.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),_(t,{code:f.invalid_type,expected:"integer",received:"float",message:s.message}),r.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(t=this._getOrReturnCtx(e,t),_(t,{code:f.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),r.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(t=this._getOrReturnCtx(e,t),_(t,{code:f.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),r.dirty()):s.kind==="multipleOf"?Ni(e.data,s.value)!==0&&(t=this._getOrReturnCtx(e,t),_(t,{code:f.not_multiple_of,multipleOf:s.value,message:s.message}),r.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),_(t,{code:f.not_finite,message:s.message}),r.dirty()):$.assertNever(s);return{status:r.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,x.toString(t))}gt(e,t){return this.setLimit("min",e,!1,x.toString(t))}lte(e,t){return this.setLimit("max",e,!0,x.toString(t))}lt(e,t){return this.setLimit("max",e,!1,x.toString(t))}setLimit(e,t,r,s){return new $e({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:x.toString(s)}]})}_addCheck(e){return new $e({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:x.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:x.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:x.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:x.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:x.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:x.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:x.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:x.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:x.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&$.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(t===null||r.value>t)&&(t=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}$e.create=n=>new $e({checks:[],typeName:T.ZodNumber,coerce:(n==null?void 0:n.coerce)||!1,...S(n)});class Me extends P{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==b.bigint){const s=this._getOrReturnCtx(e);return _(s,{code:f.invalid_type,expected:b.bigint,received:s.parsedType}),Z}let t;const r=new Q;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(t=this._getOrReturnCtx(e,t),_(t,{code:f.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),r.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(t=this._getOrReturnCtx(e,t),_(t,{code:f.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),r.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),_(t,{code:f.not_multiple_of,multipleOf:s.value,message:s.message}),r.dirty()):$.assertNever(s);return{status:r.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,x.toString(t))}gt(e,t){return this.setLimit("min",e,!1,x.toString(t))}lte(e,t){return this.setLimit("max",e,!0,x.toString(t))}lt(e,t){return this.setLimit("max",e,!1,x.toString(t))}setLimit(e,t,r,s){return new Me({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:x.toString(s)}]})}_addCheck(e){return new Me({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:x.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:x.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:x.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:x.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:x.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Me.create=n=>{var e;return new Me({checks:[],typeName:T.ZodBigInt,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...S(n)})};class zt extends P{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==b.boolean){const t=this._getOrReturnCtx(e);return _(t,{code:f.invalid_type,expected:b.boolean,received:t.parsedType}),Z}return ee(e.data)}}zt.create=n=>new zt({typeName:T.ZodBoolean,coerce:(n==null?void 0:n.coerce)||!1,...S(n)});class Ge extends P{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==b.date){const s=this._getOrReturnCtx(e);return _(s,{code:f.invalid_type,expected:b.date,received:s.parsedType}),Z}if(isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return _(s,{code:f.invalid_date}),Z}const t=new Q;let r;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(r=this._getOrReturnCtx(e,r),_(r,{code:f.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),t.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(r=this._getOrReturnCtx(e,r),_(r,{code:f.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),t.dirty()):$.assertNever(s);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Ge({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:x.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:x.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}Ge.create=n=>new Ge({checks:[],coerce:(n==null?void 0:n.coerce)||!1,typeName:T.ZodDate,...S(n)});class $n extends P{_parse(e){if(this._getType(e)!==b.symbol){const t=this._getOrReturnCtx(e);return _(t,{code:f.invalid_type,expected:b.symbol,received:t.parsedType}),Z}return ee(e.data)}}$n.create=n=>new $n({typeName:T.ZodSymbol,...S(n)});class Yt extends P{_parse(e){if(this._getType(e)!==b.undefined){const t=this._getOrReturnCtx(e);return _(t,{code:f.invalid_type,expected:b.undefined,received:t.parsedType}),Z}return ee(e.data)}}Yt.create=n=>new Yt({typeName:T.ZodUndefined,...S(n)});class Jt extends P{_parse(e){if(this._getType(e)!==b.null){const t=this._getOrReturnCtx(e);return _(t,{code:f.invalid_type,expected:b.null,received:t.parsedType}),Z}return ee(e.data)}}Jt.create=n=>new Jt({typeName:T.ZodNull,...S(n)});class ut extends P{constructor(){super(...arguments),this._any=!0}_parse(e){return ee(e.data)}}ut.create=n=>new ut({typeName:T.ZodAny,...S(n)});class ze extends P{constructor(){super(...arguments),this._unknown=!0}_parse(e){return ee(e.data)}}ze.create=n=>new ze({typeName:T.ZodUnknown,...S(n)});class Ze extends P{_parse(e){const t=this._getOrReturnCtx(e);return _(t,{code:f.invalid_type,expected:b.never,received:t.parsedType}),Z}}Ze.create=n=>new Ze({typeName:T.ZodNever,...S(n)});class Mn extends P{_parse(e){if(this._getType(e)!==b.undefined){const t=this._getOrReturnCtx(e);return _(t,{code:f.invalid_type,expected:b.void,received:t.parsedType}),Z}return ee(e.data)}}Mn.create=n=>new Mn({typeName:T.ZodVoid,...S(n)});class pe extends P{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),s=this._def;if(t.parsedType!==b.array)return _(t,{code:f.invalid_type,expected:b.array,received:t.parsedType}),Z;if(s.exactLength!==null){const i=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(i||o)&&(_(t,{code:i?f.too_big:f.too_small,minimum:o?s.exactLength.value:void 0,maximum:i?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(_(t,{code:f.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(_(t,{code:f.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((i,o)=>s.type._parseAsync(new ke(t,i,t.path,o)))).then(i=>Q.mergeArray(r,i));const a=[...t.data].map((i,o)=>s.type._parseSync(new ke(t,i,t.path,o)));return Q.mergeArray(r,a)}get element(){return this._def.type}min(e,t){return new pe({...this._def,minLength:{value:e,message:x.toString(t)}})}max(e,t){return new pe({...this._def,maxLength:{value:e,message:x.toString(t)}})}length(e,t){return new pe({...this._def,exactLength:{value:e,message:x.toString(t)}})}nonempty(e){return this.min(1,e)}}pe.create=(n,e)=>new pe({type:n,minLength:null,maxLength:null,exactLength:null,typeName:T.ZodArray,...S(e)});function lt(n){if(n instanceof B){const e={};for(const t in n.shape){const r=n.shape[t];e[t]=xe.create(lt(r))}return new B({...n._def,shape:()=>e})}else return n instanceof pe?new pe({...n._def,type:lt(n.element)}):n instanceof xe?xe.create(lt(n.unwrap())):n instanceof Ve?Ve.create(lt(n.unwrap())):n instanceof we?we.create(n.items.map(e=>lt(e))):n}class B extends P{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=$.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==b.object){const d=this._getOrReturnCtx(e);return _(d,{code:f.invalid_type,expected:b.object,received:d.parsedType}),Z}const{status:t,ctx:r}=this._processInputParams(e),{shape:s,keys:a}=this._getCached(),i=[];if(!(this._def.catchall instanceof Ze&&this._def.unknownKeys==="strip"))for(const d in r.data)a.includes(d)||i.push(d);const o=[];for(const d of a){const u=s[d],l=r.data[d];o.push({key:{status:"valid",value:d},value:u._parse(new ke(r,l,r.path,d)),alwaysSet:d in r.data})}if(this._def.catchall instanceof Ze){const d=this._def.unknownKeys;if(d==="passthrough")for(const u of i)o.push({key:{status:"valid",value:u},value:{status:"valid",value:r.data[u]}});else if(d==="strict")i.length>0&&(_(r,{code:f.unrecognized_keys,keys:i}),t.dirty());else if(d!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const d=this._def.catchall;for(const u of i){const l=r.data[u];o.push({key:{status:"valid",value:u},value:d._parse(new ke(r,l,r.path,u)),alwaysSet:u in r.data})}}return r.common.async?Promise.resolve().then(async()=>{const d=[];for(const u of o){const l=await u.key,p=await u.value;d.push({key:l,value:p,alwaysSet:u.alwaysSet})}return d}).then(d=>Q.mergeObjectSync(t,d)):Q.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return x.errToObj,new B({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{var s,a,i,o;const d=(i=(a=(s=this._def).errorMap)===null||a===void 0?void 0:a.call(s,t,r).message)!==null&&i!==void 0?i:r.defaultError;return t.code==="unrecognized_keys"?{message:(o=x.errToObj(e).message)!==null&&o!==void 0?o:d}:{message:d}}}:{}})}strip(){return new B({...this._def,unknownKeys:"strip"})}passthrough(){return new B({...this._def,unknownKeys:"passthrough"})}extend(e){return new B({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new B({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:T.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new B({...this._def,catchall:e})}pick(e){const t={};return $.objectKeys(e).forEach(r=>{e[r]&&this.shape[r]&&(t[r]=this.shape[r])}),new B({...this._def,shape:()=>t})}omit(e){const t={};return $.objectKeys(this.shape).forEach(r=>{e[r]||(t[r]=this.shape[r])}),new B({...this._def,shape:()=>t})}deepPartial(){return lt(this)}partial(e){const t={};return $.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];e&&!e[r]?t[r]=s:t[r]=s.optional()}),new B({...this._def,shape:()=>t})}required(e){const t={};return $.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])t[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof xe;)s=s._def.innerType;t[r]=s}}),new B({...this._def,shape:()=>t})}keyof(){return Hr($.objectKeys(this.shape))}}B.create=(n,e)=>new B({shape:()=>n,unknownKeys:"strip",catchall:Ze.create(),typeName:T.ZodObject,...S(e)}),B.strictCreate=(n,e)=>new B({shape:()=>n,unknownKeys:"strict",catchall:Ze.create(),typeName:T.ZodObject,...S(e)}),B.lazycreate=(n,e)=>new B({shape:n,unknownKeys:"strip",catchall:Ze.create(),typeName:T.ZodObject,...S(e)});class Qt extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;function s(a){for(const o of a)if(o.result.status==="valid")return o.result;for(const o of a)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const i=a.map(o=>new re(o.ctx.common.issues));return _(t,{code:f.invalid_union,unionErrors:i}),Z}if(t.common.async)return Promise.all(r.map(async a=>{const i={...t,common:{...t.common,issues:[]},parent:null};return{result:await a._parseAsync({data:t.data,path:t.path,parent:i}),ctx:i}})).then(s);{let a;const i=[];for(const d of r){const u={...t,common:{...t.common,issues:[]},parent:null},l=d._parseSync({data:t.data,path:t.path,parent:u});if(l.status==="valid")return l;l.status==="dirty"&&!a&&(a={result:l,ctx:u}),u.common.issues.length&&i.push(u.common.issues)}if(a)return t.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(d=>new re(d));return _(t,{code:f.invalid_union,unionErrors:o}),Z}}get options(){return this._def.options}}Qt.create=(n,e)=>new Qt({options:n,typeName:T.ZodUnion,...S(e)});const De=n=>n instanceof tn?De(n.schema):n instanceof he?De(n.innerType()):n instanceof nn?[n.value]:n instanceof Le?n.options:n instanceof rn?$.objectValues(n.enum):n instanceof sn?De(n._def.innerType):n instanceof Yt?[void 0]:n instanceof Jt?[null]:n instanceof xe?[void 0,...De(n.unwrap())]:n instanceof Ve?[null,...De(n.unwrap())]:n instanceof sr||n instanceof cn?De(n.unwrap()):n instanceof an?De(n._def.innerType):[];class Dn extends P{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==b.object)return _(t,{code:f.invalid_type,expected:b.object,received:t.parsedType}),Z;const r=this.discriminator,s=t.data[r],a=this.optionsMap.get(s);return a?t.common.async?a._parseAsync({data:t.data,path:t.path,parent:t}):a._parseSync({data:t.data,path:t.path,parent:t}):(_(t,{code:f.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),Z)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){const s=new Map;for(const a of t){const i=De(a.shape[e]);if(!i.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const o of i){if(s.has(o))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);s.set(o,a)}}return new Dn({typeName:T.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...S(r)})}}function rr(n,e){const t=Ae(n),r=Ae(e);if(n===e)return{valid:!0,data:n};if(t===b.object&&r===b.object){const s=$.objectKeys(e),a=$.objectKeys(n).filter(o=>s.indexOf(o)!==-1),i={...n,...e};for(const o of a){const d=rr(n[o],e[o]);if(!d.valid)return{valid:!1};i[o]=d.data}return{valid:!0,data:i}}else if(t===b.array&&r===b.array){if(n.length!==e.length)return{valid:!1};const s=[];for(let a=0;a<n.length;a++){const i=n[a],o=e[a],d=rr(i,o);if(!d.valid)return{valid:!1};s.push(d.data)}return{valid:!0,data:s}}else return t===b.date&&r===b.date&&+n==+e?{valid:!0,data:n}:{valid:!1}}class Xt extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(a,i)=>{if(er(a)||er(i))return Z;const o=rr(a.value,i.value);return o.valid?((tr(a)||tr(i))&&t.dirty(),{status:t.value,value:o.data}):(_(r,{code:f.invalid_intersection_types}),Z)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([a,i])=>s(a,i)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Xt.create=(n,e,t)=>new Xt({left:n,right:e,typeName:T.ZodIntersection,...S(t)});class we extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==b.array)return _(r,{code:f.invalid_type,expected:b.array,received:r.parsedType}),Z;if(r.data.length<this._def.items.length)return _(r,{code:f.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Z;!this._def.rest&&r.data.length>this._def.items.length&&(_(r,{code:f.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const s=[...r.data].map((a,i)=>{const o=this._def.items[i]||this._def.rest;return o?o._parse(new ke(r,a,r.path,i)):null}).filter(a=>!!a);return r.common.async?Promise.all(s).then(a=>Q.mergeArray(t,a)):Q.mergeArray(t,s)}get items(){return this._def.items}rest(e){return new we({...this._def,rest:e})}}we.create=(n,e)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new we({items:n,typeName:T.ZodTuple,rest:null,...S(e)})};class en extends P{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==b.object)return _(r,{code:f.invalid_type,expected:b.object,received:r.parsedType}),Z;const s=[],a=this._def.keyType,i=this._def.valueType;for(const o in r.data)s.push({key:a._parse(new ke(r,o,r.path,o)),value:i._parse(new ke(r,r.data[o],r.path,o)),alwaysSet:o in r.data});return r.common.async?Q.mergeObjectAsync(t,s):Q.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof P?new en({keyType:e,valueType:t,typeName:T.ZodRecord,...S(r)}):new en({keyType:le.create(),valueType:e,typeName:T.ZodRecord,...S(t)})}}class Ln extends P{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==b.map)return _(r,{code:f.invalid_type,expected:b.map,received:r.parsedType}),Z;const s=this._def.keyType,a=this._def.valueType,i=[...r.data.entries()].map(([o,d],u)=>({key:s._parse(new ke(r,o,r.path,[u,"key"])),value:a._parse(new ke(r,d,r.path,[u,"value"]))}));if(r.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const d of i){const u=await d.key,l=await d.value;if(u.status==="aborted"||l.status==="aborted")return Z;(u.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(u.value,l.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const d of i){const u=d.key,l=d.value;if(u.status==="aborted"||l.status==="aborted")return Z;(u.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(u.value,l.value)}return{status:t.value,value:o}}}}Ln.create=(n,e,t)=>new Ln({valueType:e,keyType:n,typeName:T.ZodMap,...S(t)});class Ye extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==b.set)return _(r,{code:f.invalid_type,expected:b.set,received:r.parsedType}),Z;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(_(r,{code:f.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(_(r,{code:f.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const a=this._def.valueType;function i(d){const u=new Set;for(const l of d){if(l.status==="aborted")return Z;l.status==="dirty"&&t.dirty(),u.add(l.value)}return{status:t.value,value:u}}const o=[...r.data.values()].map((d,u)=>a._parse(new ke(r,d,r.path,u)));return r.common.async?Promise.all(o).then(d=>i(d)):i(o)}min(e,t){return new Ye({...this._def,minSize:{value:e,message:x.toString(t)}})}max(e,t){return new Ye({...this._def,maxSize:{value:e,message:x.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}Ye.create=(n,e)=>new Ye({valueType:n,minSize:null,maxSize:null,typeName:T.ZodSet,...S(e)});class pt extends P{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==b.function)return _(t,{code:f.invalid_type,expected:b.function,received:t.parsedType}),Z;function r(o,d){return Pn({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,In(),dt].filter(u=>!!u),issueData:{code:f.invalid_arguments,argumentsError:d}})}function s(o,d){return Pn({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,In(),dt].filter(u=>!!u),issueData:{code:f.invalid_return_type,returnTypeError:d}})}const a={errorMap:t.common.contextualErrorMap},i=t.data;if(this._def.returns instanceof ht){const o=this;return ee(async function(...d){const u=new re([]),l=await o._def.args.parseAsync(d,a).catch(C=>{throw u.addIssue(r(d,C)),u}),p=await Reflect.apply(i,this,l);return await o._def.returns._def.type.parseAsync(p,a).catch(C=>{throw u.addIssue(s(p,C)),u})})}else{const o=this;return ee(function(...d){const u=o._def.args.safeParse(d,a);if(!u.success)throw new re([r(d,u.error)]);const l=Reflect.apply(i,this,u.data),p=o._def.returns.safeParse(l,a);if(!p.success)throw new re([s(l,p.error)]);return p.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new pt({...this._def,args:we.create(e).rest(ze.create())})}returns(e){return new pt({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new pt({args:e||we.create([]).rest(ze.create()),returns:t||ze.create(),typeName:T.ZodFunction,...S(r)})}}class tn extends P{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}tn.create=(n,e)=>new tn({getter:n,typeName:T.ZodLazy,...S(e)});class nn extends P{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return _(t,{received:t.data,code:f.invalid_literal,expected:this._def.value}),Z}return{status:"valid",value:e.data}}get value(){return this._def.value}}nn.create=(n,e)=>new nn({value:n,typeName:T.ZodLiteral,...S(e)});function Hr(n,e){return new Le({values:n,typeName:T.ZodEnum,...S(e)})}class Le extends P{constructor(){super(...arguments),Kt.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return _(t,{expected:$.joinValues(r),received:t.parsedType,code:f.invalid_type}),Z}if(An(this,Kt)||Vr(this,Kt,new Set(this._def.values)),!An(this,Kt).has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return _(t,{received:t.data,code:f.invalid_enum_value,options:r}),Z}return ee(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return Le.create(e,{...this._def,...t})}exclude(e,t=this._def){return Le.create(this.options.filter(r=>!e.includes(r)),{...this._def,...t})}}Kt=new WeakMap,Le.create=Hr;class rn extends P{constructor(){super(...arguments),Gt.set(this,void 0)}_parse(e){const t=$.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==b.string&&r.parsedType!==b.number){const s=$.objectValues(t);return _(r,{expected:$.joinValues(s),received:r.parsedType,code:f.invalid_type}),Z}if(An(this,Gt)||Vr(this,Gt,new Set($.getValidEnumValues(this._def.values))),!An(this,Gt).has(e.data)){const s=$.objectValues(t);return _(r,{received:r.data,code:f.invalid_enum_value,options:s}),Z}return ee(e.data)}get enum(){return this._def.values}}Gt=new WeakMap,rn.create=(n,e)=>new rn({values:n,typeName:T.ZodNativeEnum,...S(e)});class ht extends P{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==b.promise&&t.common.async===!1)return _(t,{code:f.invalid_type,expected:b.promise,received:t.parsedType}),Z;const r=t.parsedType===b.promise?t.data:Promise.resolve(t.data);return ee(r.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}ht.create=(n,e)=>new ht({type:n,typeName:T.ZodPromise,...S(e)});class he extends P{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===T.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=this._def.effect||null,a={addIssue:i=>{_(r,i),i.fatal?t.abort():t.dirty()},get path(){return r.path}};if(a.addIssue=a.addIssue.bind(a),s.type==="preprocess"){const i=s.transform(r.data,a);if(r.common.async)return Promise.resolve(i).then(async o=>{if(t.value==="aborted")return Z;const d=await this._def.schema._parseAsync({data:o,path:r.path,parent:r});return d.status==="aborted"?Z:d.status==="dirty"||t.value==="dirty"?Nn(d.value):d});{if(t.value==="aborted")return Z;const o=this._def.schema._parseSync({data:i,path:r.path,parent:r});return o.status==="aborted"?Z:o.status==="dirty"||t.value==="dirty"?Nn(o.value):o}}if(s.type==="refinement"){const i=o=>{const d=s.refinement(o,a);if(r.common.async)return Promise.resolve(d);if(d instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?Z:(o.status==="dirty"&&t.dirty(),i(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>o.status==="aborted"?Z:(o.status==="dirty"&&t.dirty(),i(o.value).then(()=>({status:t.value,value:o.value}))))}if(s.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Ht(i))return i;const o=s.transform(i.value,a);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>Ht(i)?Promise.resolve(s.transform(i.value,a)).then(o=>({status:t.value,value:o})):i);$.assertNever(s)}}he.create=(n,e,t)=>new he({schema:n,typeName:T.ZodEffects,effect:e,...S(t)}),he.createWithPreprocess=(n,e,t)=>new he({schema:e,effect:{type:"preprocess",transform:n},typeName:T.ZodEffects,...S(t)});class xe extends P{_parse(e){return this._getType(e)===b.undefined?ee(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}xe.create=(n,e)=>new xe({innerType:n,typeName:T.ZodOptional,...S(e)});class Ve extends P{_parse(e){return this._getType(e)===b.null?ee(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ve.create=(n,e)=>new Ve({innerType:n,typeName:T.ZodNullable,...S(e)});class sn extends P{_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===b.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}sn.create=(n,e)=>new sn({innerType:n,typeName:T.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...S(e)});class an extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Ft(s)?s.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new re(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new re(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}an.create=(n,e)=>new an({innerType:n,typeName:T.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...S(e)});class Vn extends P{_parse(e){if(this._getType(e)!==b.nan){const t=this._getOrReturnCtx(e);return _(t,{code:f.invalid_type,expected:b.nan,received:t.parsedType}),Z}return{status:"valid",value:e.data}}}Vn.create=n=>new Vn({typeName:T.ZodNaN,...S(n)});const Ai=Symbol("zod_brand");class sr extends P{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class on extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Z:s.status==="dirty"?(t.dirty(),Nn(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Z:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,t){return new on({in:e,out:t,typeName:T.ZodPipeline})}}class cn extends P{_parse(e){const t=this._def.innerType._parse(e),r=s=>(Ht(s)&&(s.value=Object.freeze(s.value)),s);return Ft(t)?t.then(s=>r(s)):r(t)}unwrap(){return this._def.innerType}}cn.create=(n,e)=>new cn({innerType:n,typeName:T.ZodReadonly,...S(e)});function Fr(n,e={},t){return n?ut.create().superRefine((r,s)=>{var a,i;if(!n(r)){const o=typeof e=="function"?e(r):typeof e=="string"?{message:e}:e,d=(i=(a=o.fatal)!==null&&a!==void 0?a:t)!==null&&i!==void 0?i:!0,u=typeof o=="string"?{message:o}:o;s.addIssue({code:"custom",...u,fatal:d})}}):ut.create()}const $i={object:B.lazycreate};var T;(function(n){n.ZodString="ZodString",n.ZodNumber="ZodNumber",n.ZodNaN="ZodNaN",n.ZodBigInt="ZodBigInt",n.ZodBoolean="ZodBoolean",n.ZodDate="ZodDate",n.ZodSymbol="ZodSymbol",n.ZodUndefined="ZodUndefined",n.ZodNull="ZodNull",n.ZodAny="ZodAny",n.ZodUnknown="ZodUnknown",n.ZodNever="ZodNever",n.ZodVoid="ZodVoid",n.ZodArray="ZodArray",n.ZodObject="ZodObject",n.ZodUnion="ZodUnion",n.ZodDiscriminatedUnion="ZodDiscriminatedUnion",n.ZodIntersection="ZodIntersection",n.ZodTuple="ZodTuple",n.ZodRecord="ZodRecord",n.ZodMap="ZodMap",n.ZodSet="ZodSet",n.ZodFunction="ZodFunction",n.ZodLazy="ZodLazy",n.ZodLiteral="ZodLiteral",n.ZodEnum="ZodEnum",n.ZodEffects="ZodEffects",n.ZodNativeEnum="ZodNativeEnum",n.ZodOptional="ZodOptional",n.ZodNullable="ZodNullable",n.ZodDefault="ZodDefault",n.ZodCatch="ZodCatch",n.ZodPromise="ZodPromise",n.ZodBranded="ZodBranded",n.ZodPipeline="ZodPipeline",n.ZodReadonly="ZodReadonly"})(T||(T={}));const Mi=(n,e={message:`Input not instance of ${n.name}`})=>Fr(t=>t instanceof n,e),Kr=le.create,Gr=$e.create,Di=Vn.create,Li=Me.create,zr=zt.create,Vi=Ge.create,Ui=$n.create,qi=Yt.create,Bi=Jt.create,Wi=ut.create,Hi=ze.create,Fi=Ze.create,Ki=Mn.create,Gi=pe.create,zi=B.create,Yi=B.strictCreate,Ji=Qt.create,Qi=Dn.create,Xi=Xt.create,eo=we.create,to=en.create,no=Ln.create,ro=Ye.create,so=pt.create,ao=tn.create,io=nn.create,oo=Le.create,co=rn.create,uo=ht.create,Yr=he.create,lo=xe.create,po=Ve.create,ho=he.createWithPreprocess,fo=on.create;var c=Object.freeze({__proto__:null,defaultErrorMap:dt,setErrorMap:yi,getErrorMap:In,makeIssue:Pn,EMPTY_PATH:vi,addIssueToContext:_,ParseStatus:Q,INVALID:Z,DIRTY:Nn,OK:ee,isAborted:er,isDirty:tr,isValid:Ht,isAsync:Ft,get util(){return $},get objectUtil(){return Xn},ZodParsedType:b,getParsedType:Ae,ZodType:P,datetimeRegex:Wr,ZodString:le,ZodNumber:$e,ZodBigInt:Me,ZodBoolean:zt,ZodDate:Ge,ZodSymbol:$n,ZodUndefined:Yt,ZodNull:Jt,ZodAny:ut,ZodUnknown:ze,ZodNever:Ze,ZodVoid:Mn,ZodArray:pe,ZodObject:B,ZodUnion:Qt,ZodDiscriminatedUnion:Dn,ZodIntersection:Xt,ZodTuple:we,ZodRecord:en,ZodMap:Ln,ZodSet:Ye,ZodFunction:pt,ZodLazy:tn,ZodLiteral:nn,ZodEnum:Le,ZodNativeEnum:rn,ZodPromise:ht,ZodEffects:he,ZodTransformer:he,ZodOptional:xe,ZodNullable:Ve,ZodDefault:sn,ZodCatch:an,ZodNaN:Vn,BRAND:Ai,ZodBranded:sr,ZodPipeline:on,ZodReadonly:cn,custom:Fr,Schema:P,ZodSchema:P,late:$i,get ZodFirstPartyTypeKind(){return T},coerce:{string:n=>le.create({...n,coerce:!0}),number:n=>$e.create({...n,coerce:!0}),boolean:n=>zt.create({...n,coerce:!0}),bigint:n=>Me.create({...n,coerce:!0}),date:n=>Ge.create({...n,coerce:!0})},any:Wi,array:Gi,bigint:Li,boolean:zr,date:Vi,discriminatedUnion:Qi,effect:Yr,enum:oo,function:so,instanceof:Mi,intersection:Xi,lazy:ao,literal:io,map:no,nan:Di,nativeEnum:co,never:Fi,null:Bi,nullable:po,number:Gr,object:zi,oboolean:()=>zr().optional(),onumber:()=>Gr().optional(),optional:lo,ostring:()=>Kr().optional(),pipeline:fo,preprocess:ho,promise:uo,record:to,set:ro,strictObject:Yi,string:Kr,symbol:Ui,transformer:Yr,tuple:eo,undefined:qi,union:Ji,unknown:Hi,void:Ki,NEVER:Z,ZodIssueCode:f,quotelessJson:_i,ZodError:re});gi(c);const mo=c.object({start:c.number(),limit:c.number(),length:c.number()}),ar=c.object({created_at:c.string(),updated_at:c.string()}),go=c.object({email:c.string().optional(),email_verified:c.boolean().optional(),name:c.string().optional(),username:c.string().optional(),given_name:c.string().optional(),phone_number:c.string().optional(),phone_verified:c.boolean().optional(),family_name:c.string().optional()}).catchall(c.any()),_o=c.object({connection:c.string(),user_id:c.string(),provider:c.string(),isSocial:c.boolean(),access_token:c.string().optional(),access_token_secret:c.string().optional(),refresh_token:c.string().optional(),profileData:go.optional()}),Jr=c.object({email:c.string().optional(),username:c.string().optional(),given_name:c.string().optional(),family_name:c.string().optional(),nickname:c.string().optional(),name:c.string().optional(),picture:c.string().optional(),locale:c.string().optional(),linked_to:c.string().optional(),profileData:c.string().optional(),user_id:c.string().optional()});Jr.extend({email_verified:c.boolean().default(!1),verify_email:c.boolean().optional(),last_ip:c.string().optional(),last_login:c.string().optional(),user_id:c.string().optional(),provider:c.string().default("email"),connection:c.string().default("email")}).extend(ar.shape).extend({user_id:c.string(),email:c.string(),is_social:c.boolean(),login_count:c.number(),identities:c.array(_o).optional()}),Jr.extend({email:c.string(),login_count:c.number(),multifactor:c.array(c.string()).optional(),last_ip:c.string().optional(),last_login:c.string().optional(),user_id:c.string()}).catchall(c.any());const yo=c.object({id:c.string(),name:c.string(),allowed_web_origins:c.string().transform(n=>n===null?"":n).default(""),allowed_callback_urls:c.string().transform(n=>n===null?"":n).default(""),allowed_logout_urls:c.string().transform(n=>n===null?"":n).default(""),email_validation:c.enum(["enabled","disabled","enforced"]).default("enforced"),client_secret:c.string().default(""),disable_sign_ups:c.boolean().default(!1)});c.object({created_at:c.string().transform(n=>n===null?"":n),updated_at:c.string().transform(n=>n===null?"":n)}).extend(yo.shape);var Qr=(n=>(n.TOKEN="token",n.TOKEN_ID_TOKEN="token id_token",n.CODE="code",n))(Qr||{}),Xr=(n=>(n.QUERY="query",n.FRAGMENT="fragment",n.FORM_POST="form_post",n.WEB_MESSAGE="web_message",n))(Xr||{}),es=(n=>(n.S265="S256",n.plain="plain",n))(es||{});const Un=c.object({client_id:c.string(),vendor_id:c.string().optional(),response_type:c.nativeEnum(Qr).optional(),response_mode:c.nativeEnum(Xr).optional(),redirect_uri:c.string().optional(),audience:c.string().optional(),state:c.string().optional(),nonce:c.string().optional(),scope:c.string().optional(),code_challenge_method:c.nativeEnum(es).optional(),code_challenge:c.string().optional(),username:c.string().optional()});c.object({colors:c.object({primary:c.string(),page_background:c.object({type:c.string().optional(),start:c.string().optional(),end:c.string().optional(),angle_deg:c.number().optional()}).optional()}).optional(),logo_url:c.string().optional(),favicon_url:c.string().optional(),font:c.object({url:c.string()}).optional()});const vo=c.object({id:c.string().optional(),name:c.string(),client_id:c.string().optional(),client_secret:c.string().optional(),authorization_endpoint:c.string().optional(),response_type:c.custom().optional(),response_mode:c.custom().optional(),private_key:c.string().optional(),kid:c.string().optional(),team_id:c.string().optional(),token_endpoint:c.string().optional(),token_exchange_basic_auth:c.boolean().optional(),userinfo_endpoint:c.string().optional(),scope:c.string().optional()}),ts=c.object({id:c.string(),created_at:c.string().transform(n=>n===null?"":n),updated_at:c.string().transform(n=>n===null?"":n)}).extend(vo.shape),bo=c.object({domain:c.string(),dkim_private_key:c.string().optional(),dkim_public_key:c.string().optional(),email_api_key:c.string().optional(),email_service:c.union([c.literal("mailgun"),c.literal("mailchannels")]).optional()}),ns=c.object({id:c.string(),name:c.string(),domains:c.array(bo),allowed_callback_urls:c.array(c.string()),allowed_logout_urls:c.array(c.string()),allowed_web_origins:c.array(c.string()),email_validation:c.union([c.literal("enabled"),c.literal("disabled"),c.literal("enforced")]),tenant_id:c.string(),client_secret:c.string(),disable_sign_ups:c.boolean(),tenant:c.object({name:c.string(),audience:c.string().optional(),logo:c.string().optional(),primary_color:c.string().optional(),secondary_color:c.string().optional(),sender_email:c.string(),sender_name:c.string(),support_url:c.string().optional(),language:c.string().length(2).optional()})});ns.extend({connections:c.array(ts)}),ns.extend({connections:c.array(ts.partial())});const ko=c.enum(["password_reset","email_verification","otp","oauth2","oauth2_state","ticket"]);c.object({code_id:c.string().openapi({description:"The code that will be used in for instance an email verification flow"}),login_id:c.string().openapi({description:"The id of the login session that the code is connected to"}),code_type:ko,created_at:c.string(),expires_at:c.string(),used_at:c.string().optional()});const wo=c.object({domain:c.string(),dkim_private_key:c.string().optional(),dkim_public_key:c.string().optional(),email_api_key:c.string().optional(),email_service:c.enum(["mailgun","mailchannels"])});ar.extend({...wo.shape,id:c.string()}),c.object({trigger_id:c.enum(["post-user-registration","post-user-login"]),enabled:c.boolean().default(!1),url:c.string(),hook_id:c.string().optional()}).extend({...ar.shape,hook_id:c.string()});const xo=c.object({alg:c.string(),e:c.string(),kid:c.string(),kty:c.string(),n:c.string(),use:c.string().optional()}),Oo=c.object({keys:c.array(xo)}),rs=c.object({issuer:c.string(),authorization_endpoint:c.string(),token_endpoint:c.string(),device_authorization_endpoint:c.string(),userinfo_endpoint:c.string(),mfa_challenge_endpoint:c.string(),jwks_uri:c.string(),registration_endpoint:c.string(),revocation_endpoint:c.string(),scopes_supported:c.array(c.string()),response_types_supported:c.array(c.string()),code_challenge_methods_supported:c.array(c.string()),response_modes_supported:c.array(c.string()),subject_types_supported:c.array(c.string()),id_token_signing_alg_values_supported:c.array(c.string()),token_endpoint_auth_methods_supported:c.array(c.string()),claims_supported:c.array(c.string()),request_uri_parameter_supported:c.boolean(),request_parameter_supported:c.boolean(),token_endpoint_auth_signing_alg_values_supported:c.array(c.string())}),To=c.object({login_id:c.string().openapi({description:"This is is used as the state in the universal login"}),auth0Client:c.string().optional(),authParams:Un,expires_at:c.string(),deleted_at:c.string(),ip:c.string().optional()}).openapi({description:"This represents a login sesion"});c.object({...To.shape,created_at:c.string(),updated_at:c.string()});const jo=c.enum(["sapi","ssa","fsa","ss","ssa","fs","s","f","fp","slo","scoa","fcoa","seccft","cls","seacft","serft"]),Zo=c.object({name:c.string(),version:c.string(),env:c.object({node:c.string().optional()}).optional()});c.object({type:jo,date:c.string(),description:c.string().optional(),log_id:c.string().optional(),_id:c.string().optional(),ip:c.string(),user_agent:c.string(),details:c.any().optional(),isMobile:c.boolean(),user_id:c.string().optional(),user_name:c.string().optional(),connection:c.string().optional(),connection_id:c.string().optional(),client_id:c.string().optional(),client_name:c.string().optional(),audience:c.string().optional(),scope:c.array(c.string()).optional(),strategy:c.string().optional(),strategy_type:c.string().optional(),hostname:c.string().optional(),auth0_client:Zo.optional()});const Ro=c.object({user_id:c.string(),password:c.string(),algorithm:c.enum(["bcrypt","argon2id"]).default("argon2id")});c.object({...Ro.shape,created_at:c.string(),updated_at:c.string()});const Eo=c.object({session_id:c.string(),client_id:c.string(),expires_at:c.string(),used_at:c.string(),deleted_at:c.string().optional(),user_id:c.string()});c.object({created_at:c.string(),...Eo.shape}),c.object({private_key:c.string(),public_key:c.string(),kid:c.string(),created_at:c.string(),revoked_at:c.string().optional()}),c.object({kid:c.string().openapi({description:"The key id of the signing key"}),cert:c.string().openapi({description:"The public certificate of the signing key"}),fingerprint:c.string().openapi({description:"The cert fingerprint"}),thumbprint:c.string().openapi({description:"The cert thumbprint"}),pkcs7:c.string().optional().openapi({description:"The public certificate of the signing key in pkcs7 format"}),current:c.boolean().optional().openapi({description:"True if the key is the current key"}),next:c.boolean().optional().openapi({description:"True if the key is the next key"}),previous:c.boolean().optional().openapi({description:"True if the key is the previous key"}),current_since:c.string().optional().openapi({description:"The date and time when the key became the current key"}),current_until:c.string().optional().openapi({description:"The date and time when the current key was rotated"}),revoked:c.boolean().optional().openapi({description:"True if the key is revoked"}),revoked_at:c.string().optional().openapi({description:"The date and time when the key was revoked"})});const ir=c.object({name:c.string(),audience:c.string(),sender_email:c.string().email(),sender_name:c.string(),support_url:c.string().url().optional(),logo:c.string().url().optional(),primary_color:c.string().optional(),secondary_color:c.string().optional(),language:c.string().optional()}),qn=ir.extend({created_at:c.string().transform(n=>n===null?"":n),updated_at:c.string().transform(n=>n===null?"":n)});c.object({logoUrl:c.string(),loginBackgroundImage:c.string().nullish(),style:c.object({primaryColor:c.string(),buttonTextColor:c.string(),primaryHoverColor:c.string()}),supportEmail:c.string().nullable(),supportUrl:c.string().nullable(),name:c.string(),showGreyishBackground:c.boolean().optional(),termsAndConditionsUrl:c.string().nullable(),companyName:c.string().optional(),checkoutHideSocial:c.boolean().optional(),siteUrl:c.string().nullable(),manageSubscriptionsUrl:c.string().optional()});var ss=(n=>(n.RefreshToken="refresh_token",n.AuthorizationCode="authorization_code",n.ClientCredential="client_credentials",n.Passwordless="passwordless",n.Password="password",n))(ss||{});const or=c.nativeEnum(ss);c.object({grant_type:or.refine(n=>n==="authorization_code"),code:c.string(),client_secret:c.string(),client_id:c.string()}),c.object({grant_type:or.refine(n=>n==="authorization_code"),code:c.string(),code_verifier:c.string(),client_id:c.string().optional(),redirect_uri:c.string()}),c.object({grant_type:or.refine(n=>n==="client_credentials"),scope:c.string().optional(),client_secret:c.string(),client_id:c.string(),audience:c.string().optional()}),c.object({access_token:c.string(),id_token:c.string().optional(),scope:c.string().optional(),state:c.string().optional(),refresh_token:c.string().optional(),token_type:c.string(),expires_in:c.number()}),c.object({code:c.string(),state:c.string().optional()});const So=c.object({button_border_radius:c.number(),button_border_weight:c.number(),buttons_style:c.enum(["pill"]),input_border_radius:c.number(),input_border_weight:c.number(),inputs_style:c.enum(["pill"]),show_widget_shadow:c.boolean(),widget_border_weight:c.number(),widget_corner_radius:c.number()}),Co=c.object({base_focus_color:c.string(),base_hover_color:c.string(),body_text:c.string(),captcha_widget_theme:c.enum(["auto"]),error:c.string(),header:c.string(),icons:c.string(),input_background:c.string(),input_border:c.string(),input_filled_text:c.string(),input_labels_placeholders:c.string(),links_focused_components:c.string(),primary_button:c.string(),primary_button_label:c.string(),secondary_button_border:c.string(),secondary_button_label:c.string(),success:c.string(),widget_background:c.string(),widget_border:c.string()}),ft=c.object({bold:c.boolean(),size:c.number()}),Io=c.object({body_text:ft,buttons_text:ft,font_url:c.string(),input_labels:ft,links:ft,links_style:c.enum(["normal"]),reference_text_size:c.number(),subtitle:ft,title:ft}),Po=c.object({background_color:c.string(),background_image_url:c.string(),page_layout:c.enum(["center"])}),No=c.object({header_text_alignment:c.enum(["center"]),logo_height:c.number(),logo_position:c.enum(["center"]),logo_url:c.string(),social_buttons_layout:c.enum(["bottom"])});c.object({borders:So,colors:Co,displayName:c.string(),fonts:Io,page_background:Po,widget:No}).extend({themeId:c.string()});const Ao=c.object({id:c.string(),expires_at:c.string(),auth0Client:c.string().optional(),authParams:Un});c.object({...Ao.shape,created_at:c.string(),updated_at:c.string()});const $o=c.object({id:c.string(),email:c.string(),code:c.string(),ip:c.string().optional(),send:c.enum(["code","link"]),authParams:Un,expires_at:c.string(),used_at:c.string().optional(),user_id:c.string().optional()});c.object({created_at:c.string(),...$o.shape});const Mo=c.object({authParams:Un,code:c.string(),user_id:c.string(),created_at:c.string(),expires_at:c.string(),used_at:c.string().optional()});c.object({...Mo.shape,created_at:c.string()});const Do=new Bt().openapi(Ke({tags:["jwks"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:Oo}},description:"List of tenants"}}}),async n=>{const{env:e}=n,t=[{alg:"RS256",e:"AQAB",kid:"hZ42TWGWLdmyKfwGVA6c2",kty:"RSA",n:"nUd-mktFZQNfVwmXufxcVcvJo6Lkb-jDuymtfQunmEhWCctOccWx9e7LX7_9uN15ZnRS7XJInPMRs9KLYdZ0GCnE2HM_QbrEoHpdkCRgyTE-KzmoaEv_AOVGE_Kg0-0ct3r9Z7aJLDVAsxXl1C9y8Gr7ZYkq0c4DyZr9VT8nQiwZQERbfxXdXw-5RLj21S_Lm-LL-AjKvry_TDBLpfUFJV18SVsM07lY_V45TwykNewRdaGLspFIeGdG5j5eByV8ifzBqvzOSptSCsmOTtW-ceWUk0FPD7g_KKzjjbzenoB0TC8mBb_4vWZlHnuGIAs2YoTFglp9uNu7t_OVl3Svo6ZE6alzUnaNfZNeAi78KPHYQ4tDWPjpYNfGynsiD0nojkDSPCIak56jWNYjj614cPEBiv9MVQRiSbBxpiGhMoHlW_QCCPMcXygLAaRs_tUksqoH4QB80krifG2yHPgGDPjXK1_0cYzV80iOcQIeoceqhkSSc6YxzzgDrQcsV2k3bizRQSL83GWkpdHhTZn-Q_JzsW_bDY_f9fjigYbRnoDSgS7038VFIPc92StE41MdgvIQMomcyEE4lYK1uv1Mo6cnXbCZhm8tvddo7VKNorOB4nsiv8DGrWPlzQBca9VN4C1oE2mH-3WLFR7XEkBHWVouOdTWM2S3K9F10YtahkM"}];return n.json({keys:t},{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${e.JWKS_CACHE_TIMEOUT_IN_SECONDS}, stale-while-revalidate=${e.JWKS_CACHE_TIMEOUT_IN_SECONDS*2}, stale-if-error=86400`}})}).openapi(Ke({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:rs}},description:"List of tenants"}}}),async n=>{const{env:e}=n,{ISSUER:t}=e,r=rs.parse({issuer:t,authorization_endpoint:`${t}authorize`,token_endpoint:`${t}oauth/token`,device_authorization_endpoint:`${t}oauth/device/code`,userinfo_endpoint:`${t}userinfo`,mfa_challenge_endpoint:`${t}mfa/challenge`,jwks_uri:`${t}.well-known/jwks.json`,registration_endpoint:`${t}oidc/register`,revocation_endpoint:`${t}oauth/revoke`,scopes_supported:["openid","profile","offline_access","name","given_name","family_name","nickname","email","email_verified","picture","created_at","identities","phone","address"],response_types_supported:["code","token","id_token","code token","code id_token","token id_token","code token id_token"],code_challenge_methods_supported:["S256","plain"],response_modes_supported:["query","fragment","form_post"],subject_types_supported:["public"],id_token_signing_alg_values_supported:["HS256","RS256"],token_endpoint_auth_methods_supported:["client_secret_basic","client_secret_post","private_key_jwt"],claims_supported:["aud","auth_time","created_at","email","email_verified","exp","family_name","given_name","iat","identities","iss","name","nickname","phone_number","picture","sub"],request_uri_parameter_supported:!1,request_parameter_supported:!1,token_endpoint_auth_signing_alg_values_supported:["RS256","RS384","PS256"]});return n.json(r,{headers:{"access-control-allow-origin":"*","access-control-allow-method":"GET","cache-control":`public, max-age=${e.JWKS_CACHE_TIMEOUT_IN_SECONDS}, stale-while-revalidate=${e.JWKS_CACHE_TIMEOUT_IN_SECONDS*2}, stale-if-error=86400`}})});async function Lo({userAdapter:n,tenant_id:e,email:t}){var o;const{users:r}=await n.list(e,{page:0,per_page:10,include_totals:!1,q:`email:${t}`}),s=r.filter(d=>!(d.provider==="auth2"&&!d.email_verified));if(s.length===0)return;const a=s.filter(d=>!d.linked_to);if(a.length>0)return a.length>1&&console.error("More than one primary user found for same email"),a[0];const i=await n.get(e,(o=s[0])==null?void 0:o.linked_to);if(!i)throw new Error("Primary account not found");return i}function Vo(n){return async(e,t)=>{if(!t.email||!t.email_verified)return n.users.create(e,t);const r=await Lo({userAdapter:n.users,tenant_id:e,email:t.email});return r?(await n.users.create(e,{...t,linked_to:r.user_id}),r):n.users.create(e,t)}}async function Uo(n,e,t){for await(const r of e)(await fetch(r.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).ok}function qo(n,e){return async(t,r)=>{const{hooks:s}=await e.hooks.list(t,{q:"trigger_id:post-user-registration",page:0,per_page:100,include_totals:!1});return await Uo(n,s,{tenant_id:t,user:r,trigger_id:"post-user-registration"}),r}}function Bo(n,e){return async(t,r)=>{let s=await Vo(e)(t,r);return await qo(n,e)(t,s),s}}function Wo(n,e){return{...e,users:{...e.users,create:Bo(n,e)}}}const Ho=z.object({page:z.string().min(0).optional().default("0").transform(n=>parseInt(n,10)).openapi({description:"The page number where 0 is the first page"}),per_page:z.string().min(1).optional().default("10").transform(n=>parseInt(n,10)).openapi({description:"The number of items per page"}),include_totals:z.string().optional().default("false").transform(n=>n==="true").openapi({description:"If the total number of items should be included in the response"}),sort:z.string().regex(/^.+:(-1|1)$/).optional().openapi({description:"A property that should have the format 'string:-1' or 'string:1'"}),q:z.string().optional().openapi({description:"A lucene query string used to filter the results"})});function Fo(n){if(!n)return;const[e="",t]=n.split(":");return{sort_by:e,sort_order:t==="1"?"asc":"desc"}}const Ko=mo.extend({tenants:z.array(qn)}),Go=new Bt().openapi(Ke({tags:["tenants"],method:"get",path:"/",request:{query:Ho},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:z.union([z.array(qn),Ko])}},description:"List of tenants"}}}),async n=>{const{page:e,per_page:t,include_totals:r,sort:s,q:a}=n.req.valid("query"),i=await n.env.data.tenants.list({page:e,per_page:t,include_totals:r,sort:Fo(s),q:a});return r?n.json(i):n.json(i.tenants)}).openapi(Ke({tags:["tenants"],method:"get",path:"/{id}",request:{params:z.object({id:z.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:qn}},description:"A tenant"}}}),async n=>{const{id:e}=n.req.valid("param"),t=await n.env.data.tenants.get(e);if(!t)throw new bn(404);return console.log("tenant",t),n.json(t)}).openapi(Ke({tags:["tenants"],method:"delete",path:"/{id}",request:{params:z.object({id:z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async n=>{const{id:e}=n.req.valid("param");return await n.env.data.tenants.remove(e),n.text("OK")}).openapi(Ke({tags:["tenants"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:z.object(ir.shape).partial()}}},params:z.object({id:z.string()})},security:[{Bearer:["auth:write"]}],responses:{200:{description:"Status"}}}),async n=>{const{id:e}=n.req.valid("param"),t=n.req.valid("json");return await n.env.data.tenants.update(e,t),n.text("OK")}).openapi(Ke({tags:["tenants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:z.object(ir.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"tenant/json":{schema:qn}},description:"An tenant"}}}),async n=>{const e=n.req.valid("json"),t=await n.env.data.tenants.create(e);return n.json(t,{status:201})});let as=!1;function zo(n){n.use(async(e,t)=>(as||(n.openAPIRegistry.registerComponent("securitySchemes","Bearer",{type:"oauth2",scheme:"bearer",flows:{implicit:{authorizationUrl:`${e.env.AUTH_URL}/authorize`,scopes:{openid:"Basic user information",email:"User email",profile:"User profile information"}}}}),as=!0),await t()))}function Yo(n){const e=new Bt;e.use(async(r,s)=>(r.env.data=Wo(r,n.dataAdapter),s()));const t=e.route("/api/v2/tenants",Go);return zo(t),t.doc("/api/v2/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Management api"}}),t}function Jo(n){const e=new Bt;e.get("/",s=>s.text("Hello, authhero!"));const t=Yo(n);e.route("/api/v2",t);const r=new Bt().route("/.well-known",Do);return r.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Oauth endpoints"}}),e.route("/",r),e}return V.init=Jo,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"}),V}({});