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.
package/dist/authhero.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var xr=Object.defineProperty;var Lt=r=>{throw TypeError(r)};var kr=(r,e,t)=>e in r?xr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var p=(r,e,t)=>kr(r,typeof e!="symbol"?e+"":e,t),Vt=(r,e,t)=>e.has(r)||Lt("Cannot "+t);var f=(r,e,t)=>(Vt(r,e,"read from private field"),t?t.call(r):e.get(r)),D=(r,e,t)=>e.has(r)?Lt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),j=(r,e,t,n)=>(Vt(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function Ae(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}function x(r,e){var t;return((t=r==null?void 0:r._def)===null||t===void 0?void 0:t.typeName)===e}function Or(r){return"_def"in r}function Ie(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 Tr(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,b=Ae(S,["param"]),A=Object.assign(Object.assign({},(i=this._def.openapi)===null||i===void 0?void 0:i._internal),typeof s=="string"?{refId:s}:void 0),M=Object.assign(Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o.metadata),b),!((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),K=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(A).length>0?{_internal:A}:void 0),Object.keys(M).length>0?{metadata:M}:void 0)}));if(x(this,"ZodObject")){const U=this.extend;K.extend=function(...ve){var se,z,Y,ye,le,Ot;const Tt=U.apply(this,ve);return Tt._def.openapi={_internal:{extendedFrom:!((z=(se=this._def.openapi)===null||se===void 0?void 0:se._internal)===null||z===void 0)&&z.refId?{refId:(ye=(Y=this._def.openapi)===null||Y===void 0?void 0:Y._internal)===null||ye===void 0?void 0:ye.refId,schema:this}:(le=this._def.openapi)===null||le===void 0?void 0:le._internal.extendedFrom},metadata:(Ot=Tt._def.openapi)===null||Ot===void 0?void 0:Ot.metadata},Tt}}return K},Ie(r,"optional"),Ie(r,"nullable"),Ie(r,"default"),Ie(r,"transform"),Ie(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 lt(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=>lt(r[n],e[n]))}class jr{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=>lt(a,e))||n.push(e)}contains(e){const t=this.hashCodeOf(e),n=this.buckets.get(t);return n?n.some(s=>lt(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 $e(r){return r==null}function Le(r,e){const t={};return Object.entries(r).forEach(([n,s])=>{t[n]=e(s)}),t}function Rr(r,e){const t={};return Object.entries(r).forEach(([n,s])=>{e.some(a=>a===n)||(t[n]=s)}),t}function ke(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=>!$e(e))}const Ct=lt;function Er(r){const e=new jr;return r.forEach(t=>e.put(t)),[...e.values()]}function Xt(r){return typeof r=="string"}class Sr{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 xt{constructor(e){this.message=e}}class Pe extends xt{constructor(e,t){super(e),this.data=t}}class ht extends xt{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 Ze(r,e){try{return r()}catch(t){throw t instanceof ht?new ht(Object.assign(Object.assign({},t.data),e)):t}}class Cr extends xt{constructor(e){super("Unknown zod object type, please specify `type` and other OpenAPI props using `ZodSchema.openapi`."),this.data=e}}class C{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 ke(Rr(e,["param"]),$e)}static buildParameterMetadata(e){return ke(e,$e)}static applySchemaMetadata(e,t){return ke(Object.assign(Object.assign({},e),this.buildSchemaMetadata(t)),$e)}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&&x(e,t)?e:x(e,"ZodOptional")||x(e,"ZodNullable")||x(e,"ZodBranded")?this.unwrapUntil(e.unwrap(),t):x(e,"ZodDefault")||x(e,"ZodReadonly")?this.unwrapUntil(e._def.innerType,t):x(e,"ZodEffects")?this.unwrapUntil(e._def.schema,t):x(e,"ZodPipeline")?this.unwrapUntil(e._def.in,t):t?void 0:e}static isOptionalSchema(e){return x(e,"ZodEffects")?this.isOptionalSchema(e._def.schema):e.isOptional()}}class Ir{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 Pr{transform(e){return Object.assign(Object.assign({},e("string")),{pattern:"^d+$"})}}class Zr{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=>C.getRefId(a)===void 0))return;const s={};return e.forEach(a=>{var i;const o=C.getRefId(a),c=(i=a.shape)===null||i===void 0?void 0:i[t];if(x(c,"ZodEnum")||x(c,"ZodNativeEnum")){Object.values(c.enum).filter(Xt).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 Ar{transform(e,t){return Object.assign(Object.assign({},t("string")),{enum:e._def.values})}}class Nr{transform(e,t,n,s){const i={allOf:this.flattenIntersectionTypes(e).map(s)};return t?{anyOf:n([i],t)}:i}flattenIntersectionTypes(e){if(!x(e,"ZodIntersection"))return[e];const t=this.flattenIntersectionTypes(e._def.left),n=this.flattenIntersectionTypes(e._def.right);return[...t,...n]}}class Dr{transform(e,t){return Object.assign(Object.assign({},t(typeof e._def.value)),{enum:[e._def.value]})}}function Mr(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 $r{transform(e,t){const{type:n,values:s}=Mr(e._def.values);if(n==="mixed")throw new xt("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 Lr{transform(e,t,n){return Object.assign(Object.assign({},t(e.isInt?"integer":"number")),n(e._def.checks))}}class Vr{transform(e,t,n,s){var a;const i=(a=C.getInternalMetadata(e))===null||a===void 0?void 0:a.extendedFrom,o=this.requiredKeysOf(e),c=Le(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=Le(u==null?void 0:u._def.shape(),s),T=Object.fromEntries(Object.entries(c).filter(([b,A])=>!Ct(h[b],A))),S=o.filter(b=>!d.includes(b)),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 x(s,"ZodNever")?n==="strict"?{additionalProperties:!1}:{}:{additionalProperties:t(s)}}requiredKeysOf(e){return Object.entries(e._def.shape()).filter(([t,n])=>!C.isOptionalSchema(n)).map(([t,n])=>t)}}class Ur{transform(e,t,n){const s=e._def.valueType,a=e._def.keyType,i=n(s);if(x(a,"ZodEnum")||x(a,"ZodNativeEnum")){const c=Object.values(a.enum).filter(Xt).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 Hr{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 qr{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 Wr{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 x(e,"ZodUnion")?e._def.options.flatMap(n=>this.flattenUnionTypes(n)):[e]}unwrapNullable(e){return x(e,"ZodNullable")?this.unwrapNullable(e.unwrap()):e}}class Br{constructor(e){this.versionSpecifics=e,this.objectTransformer=new Vr,this.stringTransformer=new Hr,this.numberTransformer=new Lr,this.bigIntTransformer=new Pr,this.literalTransformer=new Dr,this.enumTransformer=new Ar,this.nativeEnumTransformer=new $r,this.arrayTransformer=new Ir,this.unionTransformer=new Wr,this.discriminatedUnionTransformer=new Zr,this.intersectionTransformer=new Nr,this.recordTransformer=new Ur,this.tupleTransformer=new qr(e)}transform(e,t,n,s,a){if(x(e,"ZodNull"))return this.versionSpecifics.nullType;if(x(e,"ZodUnknown")||x(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(x(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(x(e,"ZodUnknown")||x(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(x(e,"ZodString"))return this.stringTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(x(e,"ZodNumber"))return this.numberTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),i=>this.versionSpecifics.getNumberChecks(i));if(x(e,"ZodBigInt"))return this.bigIntTransformer.transform(i=>this.versionSpecifics.mapNullableType(i,t));if(x(e,"ZodBoolean"))return this.versionSpecifics.mapNullableType("boolean",t);if(x(e,"ZodLiteral"))return this.literalTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(x(e,"ZodEnum"))return this.enumTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(x(e,"ZodNativeEnum"))return this.nativeEnumTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(x(e,"ZodArray"))return this.arrayTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),n);if(x(e,"ZodTuple"))return this.tupleTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),n);if(x(e,"ZodUnion"))return this.unionTransformer.transform(e,i=>this.versionSpecifics.mapNullableOfArray(i,t),n);if(x(e,"ZodDiscriminatedUnion"))return this.discriminatedUnionTransformer.transform(e,t,i=>this.versionSpecifics.mapNullableOfArray(i,t),n,s);if(x(e,"ZodIntersection"))return this.intersectionTransformer.transform(e,t,i=>this.versionSpecifics.mapNullableOfArray(i,t),n);if(x(e,"ZodRecord"))return this.recordTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),n);if(x(e,"ZodDate"))return this.versionSpecifics.mapNullableType("string",t);const a=C.getRefId(e);throw new Cr({currentSchema:e._def,schemaName:a})}}class zt{constructor(e,t){this.definitions=e,this.versionSpecifics=t,this.schemaRefs={},this.paramRefs={},this.pathRefs={},this.rawComponents=[],this.openApiTransformer=new Br(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=C.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 Pe(`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 Pe("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=C.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(x(e,"ZodObject")){const o=e._def.shape();return Object.entries(o).map(([u,d])=>{var h,T;const S=C.getMetadata(d),E=this.getParameterRef(S,{in:t,name:u});if(E)return E;const b=(h=S==null?void 0:S.metadata)===null||h===void 0?void 0:h.param;if(b!=null&&b.name&&b.name!==u)throw new Pe("Conflicting names for parameter",{key:"name",values:[u,b.name]});if(b!=null&&b.in&&b.in!==t)throw new Pe(`Conflicting location for parameter ${(T=b.name)!==null&&T!==void 0?T:u}`,{key:"in",values:[t,b.in]});return this.generateParameter(d.openapi({param:{name:u,in:t}}))})}if(a!=null&&a.in&&a.in!==t)throw new Pe(`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=C.getParamMetadata(e),s=(t=n==null?void 0:n.metadata)===null||t===void 0?void 0:t.param,a=!C.isOptionalSchema(e)&&!e.isNullable(),i=this.generateSchemaWithRef(e);return Object.assign({schema:i,required:a},s?C.buildParameterMetadata(s):{})}generateParameter(e){var t;const n=C.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=C.unwrapChained(e),s=C.getMetadata(e),a=C.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?C.applySchemaMetadata(i,s.metadata):ke(i,$e)}constructReferencedOpenAPISchema(e){var t;const n=C.getMetadata(e),s=C.unwrapChained(e),a=C.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=C.getMetadata(e),s=C.getRefId(e);if(!s||!this.schemaRefs[s])return this.generateSchemaWithMetadata(e);const a=this.schemaRefs[s],i={$ref:this.generateSchemaRef(s)},o=ke(C.buildSchemaMetadata((t=n==null?void 0:n.metadata)!==null&&t!==void 0?t:{}),(d,h)=>d===void 0||Ct(d,a[h]));if(o.type)return{allOf:[i,o]};const c=ke(this.constructReferencedOpenAPISchema(e),(d,h)=>d===void 0||Ct(d,a[h])),u=C.applySchemaMetadata(c,o);return Object.keys(u).length>0?{allOf:[i,u]}:i}generateSchemaWithRef(e){const t=C.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=Ae(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=Ze(()=>n?this.generateInlineParameters(n,"query"):[],{location:"query"}),o=Ze(()=>s?this.generateInlineParameters(s,"path"):[],{location:"path"}),c=Ze(()=>a?this.generateInlineParameters(a,"cookie"):[],{location:"cookie"}),u=Ze(()=>{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 x(e,"ZodEffects")?this.cleanParameter(e._def.schema):e}generatePath(e){const{method:t,path:n,request:s,responses:a}=e,i=Ae(e,["method","path","request","responses"]),o=Le(a,h=>this.getResponse(h)),c=Ze(()=>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=Ae(e,["content","headers"]);const a=t?{content:this.getBodyContent(t)}:{};if(!n)return Object.assign(Object.assign({},s),a);const i=x(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 Le(t,s=>this.generateSimpleParameter(s))}getBodyContent(e){return Le(e,t=>{if(!t||!Or(t.schema))return t;const{schema:n}=t,s=Ae(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 Fr{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=Er(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 Gr{constructor(e){const t=new Fr;this.generator=new zt(e,t)}generateDocument(e){const t=this.generator.generateDocumentData();return Object.assign(Object.assign({},e),t)}generateComponents(){return this.generator.generateComponents()}}class Kr{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 Yr(r){return"type"in r&&r.type==="webhook"}class Qr{constructor(e){this.definitions=e,this.webhookRefs={};const t=new Kr;this.generator=new zt(this.definitions,t)}generateDocument(e){const t=this.generator.generateDocumentData();return this.definitions.filter(Yr).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 er=r=>{const e=r.split("/");return e[0]===""&&e.shift(),e},Jr=r=>{const{groups:e,path:t}=Xr(r),n=er(t);return zr(n,e)},Xr=r=>{const e=[];return r=r.replace(/\{[^}]+\}/g,(t,n)=>{const s=`@${n}`;return e.push([s,t]),s}),{groups:e,path:r}},zr=(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},ct={},Ht=r=>{if(r==="*")return"*";const e=r.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);return e?(ct[r]||(e[2]?ct[r]=[r,e[1],new RegExp("^"+e[2]+"$")]:ct[r]=[r,e[1],!0]),ct[r]):null},en=r=>{try{return decodeURI(r)}catch{return r.replace(/(?:%[0-9A-Fa-f]{2})+/g,e=>{try{return decodeURI(e)}catch{return e}})}},tr=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 en(i.includes("%25")?i.replace(/%25/g,"%2525"):i)}else if(s===63)break}return e.slice(t,n)},tn=r=>{const e=tr(r);return e.length>1&&e[e.length-1]==="/"?e.slice(0,-1):e},he=(...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},rr=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)},jt=r=>/[%+]/.test(r)?(r.indexOf("+")!==-1&&(r=r.replace(/\+/g," ")),/%/.test(r)?ft(r):r):r,nr=(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 jt(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=jt(c)),a=i,c==="")continue;let u;o===-1?u="":(u=r.slice(o+1,i===-1?void 0:i),n&&(u=jt(u))),t?(s[c]&&Array.isArray(s[c])||(s[c]=[]),s[c].push(u)):s[c]??(s[c]=u)}return e?s[e]:s},rn=nr,nn=(r,e)=>nr(r,e,!0),ft=decodeURIComponent,sn=/^[\w!#$%&'*.^`|~+-]+$/,an=/^[ !#-:<-[\]-~]*$/,on=(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(!sn.test(i))return n;let o=s.substring(a+1).trim();return o.startsWith('"')&&o.endsWith('"')&&(o=o.slice(1,-1)),an.test(o)&&(n[i]=ft(o)),n},{}),cn=(r,e,t)=>{const n=r.req.raw.headers.get("Cookie");return n?on(n):{}},Rt=class extends Error{constructor(e=500,t){super(t==null?void 0:t.message,{cause:t==null?void 0:t.cause});p(this,"res");p(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})}},un=(r,e)=>new Response(r,{headers:{"Content-Type":e}}).formData(),dn=(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 Rt(400,{message:o})}try{s=await t.req.json()}catch{const o="Malformed JSON in request body";throw new Rt(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 un(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 Rt(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=cn(t);break}const i=await e(s,t);if(i instanceof Response)return i;t.req.addValidatedData(r,i),await n()};const _e=(r,e,t)=>dn(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 ln=async(r,e=Object.create(null))=>{const{all:t=!1,dot:n=!1}=e,a=(r instanceof sr?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")?hn(r,{all:t,dot:n}):{}};async function hn(r,e){const t=await r.formData();return t?fn(t,e):{}}function fn(r,e){const t=Object.create(null);return r.forEach((n,s)=>{e.all||s.endsWith("[]")?pn(t,s,n):t[s]=n}),e.dot&&Object.entries(t).forEach(([n,s])=>{n.includes(".")&&(mn(t,n,s),delete t[n])}),t}var pn=(r,e,t)=>{r[e]!==void 0?Array.isArray(r[e])?r[e].push(t):r[e]=[r[e],t]:r[e]=t},mn=(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])})},Te,H,Yt,sr=(Yt=class{constructor(r,e="/",t=[[]]){p(this,"raw");D(this,Te);D(this,H);p(this,"routeIndex",0);p(this,"path");p(this,"bodyCache",{});p(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,j(this,H,t),j(this,Te,{})}param(r){return r?this.getDecodedParam(r):this.getAllDecodedParams()}getDecodedParam(r){const e=f(this,H)[0][this.routeIndex][1][r],t=this.getParamValue(e);return t?/\%/.test(t)?ft(t):t:void 0}getAllDecodedParams(){const r={},e=Object.keys(f(this,H)[0][this.routeIndex][1]);for(const t of e){const n=this.getParamValue(f(this,H)[0][this.routeIndex][1][t]);n&&typeof n=="string"&&(r[t]=/\%/.test(n)?ft(n):n)}return r}getParamValue(r){return f(this,H)[1]?f(this,H)[1][r]:r}query(r){return rn(this.url,r)}queries(r){return nn(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 ln(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,Te)[r]=e}valid(r){return f(this,Te)[r]}get url(){return this.raw.url}get method(){return this.raw.method}get matchedRoutes(){return f(this,H)[0].map(([[,r]])=>r)}get routePath(){return f(this,H)[0].map(([[,r]])=>r)[this.routeIndex].path}},Te=new WeakMap,H=new WeakMap,Yt),gn={Stringify:1,BeforeStream:2,Stream:3},ar=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=>ar(c,e,!1,n,s))).then(()=>s[0]))):Promise.resolve(r)},vn="text/plain; charset=UTF-8",Et=(r,e={})=>(Object.entries(e).forEach(([t,n])=>r.set(t,n)),r),rt,nt,ie,fe,te,I,Z,q,re,st,je,Re,at,it,Qt,ut=(Qt=class{constructor(r,e){D(this,rt);D(this,nt);p(this,"env",{});D(this,ie);p(this,"finalized",!1);p(this,"error");D(this,fe,200);D(this,te);D(this,I);D(this,Z);D(this,q);D(this,re,!0);D(this,st);D(this,je);D(this,Re);D(this,at);D(this,it);p(this,"render",(...r)=>(f(this,je)??j(this,je,e=>this.html(e)),f(this,je).call(this,...r)));p(this,"setLayout",r=>j(this,st,r));p(this,"getLayout",()=>f(this,st));p(this,"setRenderer",r=>{j(this,je,r)});p(this,"header",(r,e,t)=>{if(e===void 0){f(this,I)?f(this,I).delete(r):f(this,Z)&&delete f(this,Z)[r.toLocaleLowerCase()],this.finalized&&this.res.headers.delete(r);return}t!=null&&t.append?(f(this,I)||(j(this,re,!1),j(this,I,new Headers(f(this,Z))),j(this,Z,{})),f(this,I).append(r,e)):f(this,I)?f(this,I).set(r,e):(f(this,Z)??j(this,Z,{}),f(this,Z)[r.toLowerCase()]=e),this.finalized&&(t!=null&&t.append?this.res.headers.append(r,e):this.res.headers.set(r,e))});p(this,"status",r=>{j(this,re,!1),j(this,fe,r)});p(this,"set",(r,e)=>{f(this,ie)??j(this,ie,{}),f(this,ie)[r]=e});p(this,"get",r=>f(this,ie)?f(this,ie)[r]:void 0);p(this,"newResponse",(r,e,t)=>{if(f(this,re)&&!t&&!e&&f(this,fe)===200)return new Response(r,{headers:f(this,Z)});if(e&&typeof e!="number"){const s=new Headers(e.headers);f(this,I)&&f(this,I).forEach((i,o)=>{o==="set-cookie"?s.append(o,i):s.set(o,i)});const a=Et(s,f(this,Z));return new Response(r,{headers:a,status:e.status??f(this,fe)})}const n=typeof e=="number"?e:f(this,fe);f(this,Z)??j(this,Z,{}),f(this,I)??j(this,I,new Headers),Et(f(this,I),f(this,Z)),f(this,q)&&(f(this,q).headers.forEach((s,a)=>{var i,o;a==="set-cookie"?(i=f(this,I))==null||i.append(a,s):(o=f(this,I))==null||o.set(a,s)}),Et(f(this,I),f(this,Z))),t??(t={});for(const[s,a]of Object.entries(t))if(typeof a=="string")f(this,I).set(s,a);else{f(this,I).delete(s);for(const i of a)f(this,I).append(s,i)}return new Response(r,{status:n,headers:f(this,I)})});p(this,"body",(r,e,t)=>typeof e=="number"?this.newResponse(r,e,t):this.newResponse(r,e));p(this,"text",(r,e,t)=>{if(!f(this,Z)){if(f(this,re)&&!t&&!e)return new Response(r);j(this,Z,{})}return f(this,Z)["content-type"]=vn,typeof e=="number"?this.newResponse(r,e,t):this.newResponse(r,e)});p(this,"json",(r,e,t)=>{const n=JSON.stringify(r);return f(this,Z)??j(this,Z,{}),f(this,Z)["content-type"]="application/json; charset=UTF-8",typeof e=="number"?this.newResponse(n,e,t):this.newResponse(n,e)});p(this,"html",(r,e,t)=>(f(this,Z)??j(this,Z,{}),f(this,Z)["content-type"]="text/html; charset=UTF-8",typeof r=="object"&&(r instanceof Promise||(r=r.toString()),r instanceof Promise)?r.then(n=>ar(n,gn.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)));p(this,"redirect",(r,e)=>(f(this,I)??j(this,I,new Headers),f(this,I).set("Location",r),this.newResponse(null,e??302)));p(this,"notFound",()=>(f(this,Re)??j(this,Re,()=>new Response),f(this,Re).call(this,this)));j(this,rt,r),e&&(j(this,te,e.executionCtx),this.env=e.env,j(this,Re,e.notFoundHandler),j(this,it,e.path),j(this,at,e.matchResult))}get req(){return f(this,nt)??j(this,nt,new sr(f(this,rt),f(this,it),f(this,at))),f(this,nt)}get event(){if(f(this,te)&&"respondWith"in f(this,te))return f(this,te);throw Error("This context has no FetchEvent")}get executionCtx(){if(f(this,te))return f(this,te);throw Error("This context has no ExecutionContext")}get res(){return j(this,re,!1),f(this,q)||j(this,q,new Response("404 Not Found",{status:404}))}set res(r){if(j(this,re,!1),f(this,q)&&r){f(this,q).headers.delete("content-type");for(const[e,t]of f(this,q).headers.entries())if(e==="set-cookie"){const n=f(this,q).headers.getSetCookie();r.headers.delete("set-cookie");for(const s of n)r.headers.append("set-cookie",s)}else r.headers.set(e,t)}j(this,q,r),this.finalized=!0}get var(){return{...f(this,ie)}}},rt=new WeakMap,nt=new WeakMap,ie=new WeakMap,fe=new WeakMap,te=new WeakMap,I=new WeakMap,Z=new WeakMap,q=new WeakMap,re=new WeakMap,st=new WeakMap,je=new WeakMap,Re=new WeakMap,at=new WeakMap,it=new WeakMap,Qt),qt=(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 ut&&(n.req.routeIndex=o)):d=o===r.length&&s||void 0,!d)n instanceof ut&&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 ut&&e)n.error=h,c=await e(h,n),u=!0;else throw h}return c&&(n.finalized===!1||u)&&(n.res=c),n}},N="ALL",yn="all",_n=["get","post","put","delete","options","patch"],ir="Can not add a route since the matcher is already built.",or=class extends Error{},bn=Symbol("composedHandler"),wn=r=>r.text("404 Not Found",404),Wt=(r,e)=>"getResponse"in r?r.getResponse():(console.error(r),e.text("Internal Server Error",500)),W,Jt,cr=(Jt=class{constructor(e={}){p(this,"get");p(this,"post");p(this,"put");p(this,"delete");p(this,"options");p(this,"patch");p(this,"all");p(this,"on");p(this,"use");p(this,"router");p(this,"getPath");p(this,"_basePath","/");D(this,W,"/");p(this,"routes",[]);p(this,"notFoundHandler",wn);p(this,"errorHandler",Wt);p(this,"onError",e=>(this.errorHandler=e,this));p(this,"notFound",e=>(this.notFoundHandler=e,this));p(this,"fetch",(e,...t)=>this.dispatch(e,t[1],t[0],e.method));p(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${he("/",e)}`,i=new Request(a,t);return this.fetch(i,n,s)});p(this,"fire",()=>{addEventListener("fetch",e=>{e.respondWith(this.dispatch(e.request,e,void 0,e.request.method))})});[..._n,yn].forEach(s=>{this[s]=(a,...i)=>(typeof a=="string"?j(this,W,a):this.addRoute(s,f(this,W),a),i.forEach(o=>{typeof o!="string"&&this.addRoute(s,f(this,W),o)}),this)}),this.on=(s,a,...i)=>{for(const o of[a].flat()){j(this,W,o);for(const c of[s].flat())i.map(u=>{this.addRoute(c.toUpperCase(),f(this,W),u)})}return this},this.use=(s,...a)=>(typeof s=="string"?j(this,W,s):(j(this,W,"*"),a.unshift(s)),a.forEach(i=>{this.addRoute(N,f(this,W),i)}),this);const n=e.strict??!0;delete e.strict,Object.assign(this,e),this.getPath=n?e.getPath??tr:tn}clone(){const e=new cr({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===Wt?a=s.handler:(a=async(i,o)=>(await qt([],t.errorHandler)(i,()=>s.handler(i,o))).res,a[bn]=s.handler),n.addRoute(s.method,s.path,a)}),this}basePath(e){const t=this.clone();return t._basePath=he(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=he(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(N,he(e,"*"),o),this}addRoute(e,t,n){e=e.toUpperCase(),t=he(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 ut(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=qt(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)}})()}},W=new WeakMap,Jt),pt="[^/]+",Ve=".*",Ue="(?:|/.*)",Ne=Symbol(),xn=new Set(".\\+*[^]$()");function kn(r,e){return r.length===1?e.length===1?r<e?-1:1:-1:e.length===1||r===Ve||r===Ue?1:e===Ve||e===Ue?-1:r===pt?1:e===pt?-1:r.length===e.length?r<e?-1:1:e.length-r.length}var It=class{constructor(){p(this,"index");p(this,"varIndex");p(this,"children",Object.create(null))}insert(e,t,n,s,a){if(e.length===0){if(this.index!==void 0)throw Ne;if(a)return;this.index=t;return}const[i,...o]=e,c=i==="*"?o.length===0?["","",Ve]:["","",pt]:i==="/*"?["","",Ue]:i.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);let u;if(c){const d=c[1];let h=c[2]||pt;if(d&&c[2]&&(h=h.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(h)))throw Ne;if(u=this.children[h],!u){if(Object.keys(this.children).some(T=>T!==Ve&&T!==Ue))throw Ne;if(a)return;u=this.children[h]=new It,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!==Ve&&d!==Ue))throw Ne;if(a)return;u=this.children[i]=new It}u.insert(o,t,n,s,a)}buildRegExpStr(){const t=Object.keys(this.children).sort(kn).map(n=>{const s=this.children[n];return(typeof s.varIndex=="number"?`(${n})@${s.varIndex}`:xn.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("|")+")"}},On=class{constructor(){p(this,"context",{varIndex:0});p(this,"root",new It)}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]}},ur=[],Tn=[/^$/,[],Object.create(null)],dt=Object.create(null);function dr(r){return dt[r]??(dt[r]=new RegExp(r==="*"?"":`^${r.replace(/\/\*$|([.\\+*[^\]$()])/g,(e,t)=>t?`\\${t}`:"(?:|/.*)")}$`))}function jn(){dt=Object.create(null)}function Rn(r){var u;const e=new On,t=[];if(r.length===0)return Tn;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,b]=n[d];S?s[E]=[b.map(([M])=>[M,Object.create(null)]),ur]:h++;let A;try{A=e.insert(E,h,S)}catch(M){throw M===Ne?new or(E):M}S||(t[h]=b.map(([M,K])=>{const U=Object.create(null);for(K-=1;K>=0;K--){const[ve,se]=A[K];U[ve]=se}return[M,U]}))}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 b=Object.keys(E);for(let A=0,M=b.length;A<M;A++)E[b[A]]=o[E[b[A]]]}const c=[];for(const d in i)c[d]=t[i[d]];return[a,c,s]}function be(r,e){if(r){for(const t of Object.keys(r).sort((n,s)=>s.length-n.length))if(dr(t).test(e))return[...r[t]]}}var En=class{constructor(){p(this,"name","RegExpRouter");p(this,"middleware");p(this,"routes");this.middleware={[N]:Object.create(null)},this.routes={[N]:Object.create(null)}}add(r,e,t){var o;const{middleware:n,routes:s}=this;if(!n||!s)throw new Error(ir);n[r]||[n,s].forEach(c=>{c[r]=Object.create(null),Object.keys(c[N]).forEach(u=>{c[r][u]=[...c[N][u]]})}),e==="/*"&&(e="*");const a=(e.match(/\/:/g)||[]).length;if(/\*$/.test(e)){const c=dr(e);r===N?Object.keys(n).forEach(u=>{var d;(d=n[u])[e]||(d[e]=be(n[u],e)||be(n[N],e)||[])}):(o=n[r])[e]||(o[e]=be(n[r],e)||be(n[N],e)||[]),Object.keys(n).forEach(u=>{(r===N||r===u)&&Object.keys(n[u]).forEach(d=>{c.test(d)&&n[u][d].push([t,a])})}),Object.keys(s).forEach(u=>{(r===N||r===u)&&Object.keys(s[u]).forEach(d=>c.test(d)&&s[u][d].push([t,a]))});return}const i=rr(e)||[e];for(let c=0,u=i.length;c<u;c++){const d=i[c];Object.keys(s).forEach(h=>{var T;(r===N||r===h)&&((T=s[h])[d]||(T[d]=[...be(n[h],d)||be(n[N],d)||[]]),s[h][d].push([t,a-u+c+1]))})}}match(r,e){jn();const t=this.buildAllMatchers();return this.match=(n,s)=>{const a=t[n]||t[N],i=a[2][s];if(i)return i;const o=s.match(a[0]);if(!o)return[[],ur];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===N;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!==N&&e.push(...Object.keys(n[N]).map(a=>[a,n[N][a]]))}),t?Rn(e):null}},Sn=class{constructor(r){p(this,"name","SmartRouter");p(this,"routers",[]);p(this,"routes",[]);Object.assign(this,r)}add(r,e,t){if(!this.routes)throw new Error(ir);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 or)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]}},lr=class{constructor(r,e,t){p(this,"methods");p(this,"children");p(this,"patterns");p(this,"order",0);p(this,"name");p(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=Jr(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=Ht(d);T&&a.push(T[1]);continue}n.children[d]=new lr;const h=Ht(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[N],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=er(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],b=E.children[u];b&&(b.params=E.params,d===!0?(b.children["*"]&&t.push(...this.gHSets(b.children["*"],r,E.params,Object.create(null))),t.push(...this.gHSets(b,r,E.params,Object.create(null)))):h.push(b));for(let A=0,M=E.patterns.length;A<M;A++){const K=E.patterns[A],U={...E.params};if(K==="*"){const le=E.children["*"];le&&(t.push(...this.gHSets(le,r,E.params,Object.create(null))),h.push(le));continue}if(u==="")continue;const[ve,se,z]=K,Y=E.children[ve],ye=a.slice(o).join("/");if(z instanceof RegExp&&z.test(ye)){U[se]=ye,t.push(...this.gHSets(Y,r,E.params,U));continue}(z===!0||z instanceof RegExp&&z.test(u))&&typeof ve=="string"&&(U[se]=u,d===!0?(t.push(...this.gHSets(Y,r,U,E.params)),Y.children["*"]&&t.push(...this.gHSets(Y.children["*"],r,U,E.params))):(Y.params=U,h.push(Y)))}}s=h}return[t.sort((o,c)=>o.score-c.score).map(({handler:o,params:c})=>[o,c])]}},Cn=class{constructor(){p(this,"name","TrieRouter");p(this,"node");this.node=new lr}add(r,e,t){const n=rr(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)}},In=class extends cr{constructor(r={}){super(r),this.router=r.router??new Sn({routers:[new En,new Cn]})}},R;(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})(R||(R={}));var Pt;(function(r){r.mergeShapes=(e,t)=>({...e,...t})})(Pt||(Pt={}));const g=R.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ae=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=R.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"]),Pn=r=>JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:");class V 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 V))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,R.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()}}V.create=r=>new V(r);const Ee=(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,R.jsonStringifyReplacer)}`;break;case l.unrecognized_keys:t=`Unrecognized key(s) in object: ${R.joinValues(r.keys,", ")}`;break;case l.invalid_union:t="Invalid input";break;case l.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${R.joinValues(r.options)}`;break;case l.invalid_enum_value:t=`Invalid enum value. Expected ${R.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}"`:R.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,R.assertNever(r)}return{message:t}};let hr=Ee;function Zn(r){hr=r}function mt(){return hr}const gt=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}},An=[];function m(r,e){const t=mt(),n=gt({issueData:e,data:r.data,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,t,t===Ee?void 0:Ee].filter(s=>!!s)});r.common.issues.push(n)}class ${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 _;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 $.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 _;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 _=Object.freeze({status:"aborted"}),xe=r=>({status:"dirty",value:r}),L=r=>({status:"valid",value:r}),Zt=r=>r.status==="aborted",At=r=>r.status==="dirty",He=r=>r.status==="valid",qe=r=>typeof Promise<"u"&&r instanceof Promise;function vt(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 fr(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}var v;(function(r){r.errToObj=e=>typeof e=="string"?{message:e}:e||{},r.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(v||(v={}));var De,Me;class J{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 Bt=(r,e)=>{if(He(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 V(r.common.issues);return this._error=t,this._error}}};function w(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 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 $,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(qe(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:ae(e)},a=this._parseSync({data:e,path:s.path,parent:s});return Bt(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:ae(e)},s=this._parse({data:e,path:n.path,parent:n}),a=await(qe(s)?s:Promise.resolve(s));return Bt(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 G({schema:this,typeName:y.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return Q.create(this,this._def)}nullable(){return de.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return F.create(this,this._def)}promise(){return Ce.create(this,this._def)}or(e){return Ge.create([this,e],this._def)}and(e){return Ke.create(this,e,this._def)}transform(e){return new G({...w(this._def),schema:this,typeName:y.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new ze({...w(this._def),innerType:this,defaultValue:t,typeName:y.ZodDefault})}brand(){return new $t({typeName:y.ZodBranded,type:this,...w(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new et({...w(this._def),innerType:this,catchValue:t,typeName:y.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return ot.create(this,e)}readonly(){return tt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Nn=/^c[^\s-]{8,}$/i,Dn=/^[0-9a-z]+$/,Mn=/^[0-9A-HJKMNP-TV-Z]{26}$/,$n=/^[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,Ln=/^[a-z0-9_-]{21}$/i,Vn=/^[-+]?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)?)??$/,Un=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Hn="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let St;const qn=/^(?:(?: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])$/,Wn=/^(([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})))$/,Bn=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,pr="((\\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])))",Fn=new RegExp(`^${pr}$`);function mr(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 Gn(r){return new RegExp(`^${mr(r)}$`)}function gr(r){let e=`${pr}T${mr(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 Kn(r,e){return!!((e==="v4"||!e)&&qn.test(r)||(e==="v6"||!e)&&Wn.test(r))}class B extends k{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==g.string){const a=this._getOrReturnCtx(e);return m(a,{code:l.invalid_type,expected:g.string,received:a.parsedType}),_}const n=new $;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),m(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),m(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?m(s,{code:l.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&m(s,{code:l.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),n.dirty())}else if(a.kind==="email")Un.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"email",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="emoji")St||(St=new RegExp(Hn,"u")),St.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"emoji",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="uuid")$n.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"uuid",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="nanoid")Ln.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"nanoid",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid")Nn.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"cuid",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid2")Dn.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"cuid2",code:l.invalid_string,message:a.message}),n.dirty());else if(a.kind==="ulid")Mn.test(e.data)||(s=this._getOrReturnCtx(e,s),m(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),m(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),m(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),m(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),m(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),m(s,{code:l.invalid_string,validation:{endsWith:a.value},message:a.message}),n.dirty()):a.kind==="datetime"?gr(a).test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{code:l.invalid_string,validation:"datetime",message:a.message}),n.dirty()):a.kind==="date"?Fn.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{code:l.invalid_string,validation:"date",message:a.message}),n.dirty()):a.kind==="time"?Gn(a).test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{code:l.invalid_string,validation:"time",message:a.message}),n.dirty()):a.kind==="duration"?Vn.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"duration",code:l.invalid_string,message:a.message}),n.dirty()):a.kind==="ip"?Kn(e.data,a.version)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"ip",code:l.invalid_string,message:a.message}),n.dirty()):a.kind==="base64"?Bn.test(e.data)||(s=this._getOrReturnCtx(e,s),m(s,{validation:"base64",code:l.invalid_string,message:a.message}),n.dirty()):R.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,...v.errToObj(n)})}_addCheck(e){return new B({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...v.errToObj(e)})}url(e){return this._addCheck({kind:"url",...v.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...v.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...v.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...v.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...v.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...v.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...v.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...v.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...v.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,...v.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,...v.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...v.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...v.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...v.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...v.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...v.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...v.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...v.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...v.errToObj(t)})}nonempty(e){return this.min(1,v.errToObj(e))}trim(){return new B({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new B({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new B({...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}}B.create=r=>{var e;return new B({checks:[],typeName:y.ZodString,coerce:(e=r==null?void 0:r.coerce)!==null&&e!==void 0?e:!1,...w(r)})};function Yn(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 m(a,{code:l.invalid_type,expected:g.number,received:a.parsedType}),_}let n;const s=new $;for(const a of this._def.checks)a.kind==="int"?R.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),m(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),m(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),m(n,{code:l.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?Yn(e.data,a.value)!==0&&(n=this._getOrReturnCtx(e,n),m(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),m(n,{code:l.not_finite,message:a.message}),s.dirty()):R.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,v.toString(t))}gt(e,t){return this.setLimit("min",e,!1,v.toString(t))}lte(e,t){return this.setLimit("max",e,!0,v.toString(t))}lt(e,t){return this.setLimit("max",e,!1,v.toString(t))}setLimit(e,t,n,s){return new oe({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:v.toString(s)}]})}_addCheck(e){return new oe({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:v.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:v.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:v.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:v.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:v.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:v.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:v.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:v.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:v.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"&&R.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:y.ZodNumber,coerce:(r==null?void 0:r.coerce)||!1,...w(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 m(a,{code:l.invalid_type,expected:g.bigint,received:a.parsedType}),_}let n;const s=new $;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),m(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),m(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),m(n,{code:l.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):R.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,v.toString(t))}gt(e,t){return this.setLimit("min",e,!1,v.toString(t))}lte(e,t){return this.setLimit("max",e,!0,v.toString(t))}lt(e,t){return this.setLimit("max",e,!1,v.toString(t))}setLimit(e,t,n,s){return new ce({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:v.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:v.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:v.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:v.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:v.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:v.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:y.ZodBigInt,coerce:(e=r==null?void 0:r.coerce)!==null&&e!==void 0?e:!1,...w(r)})};class We extends k{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==g.boolean){const n=this._getOrReturnCtx(e);return m(n,{code:l.invalid_type,expected:g.boolean,received:n.parsedType}),_}return L(e.data)}}We.create=r=>new We({typeName:y.ZodBoolean,coerce:(r==null?void 0:r.coerce)||!1,...w(r)});class me 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 m(a,{code:l.invalid_type,expected:g.date,received:a.parsedType}),_}if(isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return m(a,{code:l.invalid_date}),_}const n=new $;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),m(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),m(s,{code:l.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),n.dirty()):R.assertNever(a);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new me({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:v.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:v.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}}me.create=r=>new me({checks:[],coerce:(r==null?void 0:r.coerce)||!1,typeName:y.ZodDate,...w(r)});class yt extends k{_parse(e){if(this._getType(e)!==g.symbol){const n=this._getOrReturnCtx(e);return m(n,{code:l.invalid_type,expected:g.symbol,received:n.parsedType}),_}return L(e.data)}}yt.create=r=>new yt({typeName:y.ZodSymbol,...w(r)});class Be extends k{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return m(n,{code:l.invalid_type,expected:g.undefined,received:n.parsedType}),_}return L(e.data)}}Be.create=r=>new Be({typeName:y.ZodUndefined,...w(r)});class Fe extends k{_parse(e){if(this._getType(e)!==g.null){const n=this._getOrReturnCtx(e);return m(n,{code:l.invalid_type,expected:g.null,received:n.parsedType}),_}return L(e.data)}}Fe.create=r=>new Fe({typeName:y.ZodNull,...w(r)});class Se extends k{constructor(){super(...arguments),this._any=!0}_parse(e){return L(e.data)}}Se.create=r=>new Se({typeName:y.ZodAny,...w(r)});class pe extends k{constructor(){super(...arguments),this._unknown=!0}_parse(e){return L(e.data)}}pe.create=r=>new pe({typeName:y.ZodUnknown,...w(r)});class ne extends k{_parse(e){const t=this._getOrReturnCtx(e);return m(t,{code:l.invalid_type,expected:g.never,received:t.parsedType}),_}}ne.create=r=>new ne({typeName:y.ZodNever,...w(r)});class _t extends k{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return m(n,{code:l.invalid_type,expected:g.void,received:n.parsedType}),_}return L(e.data)}}_t.create=r=>new _t({typeName:y.ZodVoid,...w(r)});class F extends k{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),s=this._def;if(t.parsedType!==g.array)return m(t,{code:l.invalid_type,expected:g.array,received:t.parsedType}),_;if(s.exactLength!==null){const i=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(i||o)&&(m(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&&(m(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&&(m(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 J(t,i,t.path,o)))).then(i=>$.mergeArray(n,i));const a=[...t.data].map((i,o)=>s.type._parseSync(new J(t,i,t.path,o)));return $.mergeArray(n,a)}get element(){return this._def.type}min(e,t){return new F({...this._def,minLength:{value:e,message:v.toString(t)}})}max(e,t){return new F({...this._def,maxLength:{value:e,message:v.toString(t)}})}length(e,t){return new F({...this._def,exactLength:{value:e,message:v.toString(t)}})}nonempty(e){return this.min(1,e)}}F.create=(r,e)=>new F({type:r,minLength:null,maxLength:null,exactLength:null,typeName:y.ZodArray,...w(e)});function we(r){if(r instanceof P){const e={};for(const t in r.shape){const n=r.shape[t];e[t]=Q.create(we(n))}return new P({...r._def,shape:()=>e})}else return r instanceof F?new F({...r._def,type:we(r.element)}):r instanceof Q?Q.create(we(r.unwrap())):r instanceof de?de.create(we(r.unwrap())):r instanceof X?X.create(r.items.map(e=>we(e))):r}class P 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=R.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==g.object){const u=this._getOrReturnCtx(e);return m(u,{code:l.invalid_type,expected:g.object,received:u.parsedType}),_}const{status:n,ctx:s}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof ne&&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 J(s,h,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof ne){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&&(m(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 J(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=>$.mergeObjectSync(n,u)):$.mergeObjectSync(n,c)}get shape(){return this._def.shape()}strict(e){return v.errToObj,new P({...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=v.errToObj(e).message)!==null&&o!==void 0?o:c}:{message:c}}}:{}})}strip(){return new P({...this._def,unknownKeys:"strip"})}passthrough(){return new P({...this._def,unknownKeys:"passthrough"})}extend(e){return new P({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new P({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:y.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new P({...this._def,catchall:e})}pick(e){const t={};return R.objectKeys(e).forEach(n=>{e[n]&&this.shape[n]&&(t[n]=this.shape[n])}),new P({...this._def,shape:()=>t})}omit(e){const t={};return R.objectKeys(this.shape).forEach(n=>{e[n]||(t[n]=this.shape[n])}),new P({...this._def,shape:()=>t})}deepPartial(){return we(this)}partial(e){const t={};return R.objectKeys(this.shape).forEach(n=>{const s=this.shape[n];e&&!e[n]?t[n]=s:t[n]=s.optional()}),new P({...this._def,shape:()=>t})}required(e){const t={};return R.objectKeys(this.shape).forEach(n=>{if(e&&!e[n])t[n]=this.shape[n];else{let a=this.shape[n];for(;a instanceof Q;)a=a._def.innerType;t[n]=a}}),new P({...this._def,shape:()=>t})}keyof(){return vr(R.objectKeys(this.shape))}}P.create=(r,e)=>new P({shape:()=>r,unknownKeys:"strip",catchall:ne.create(),typeName:y.ZodObject,...w(e)});P.strictCreate=(r,e)=>new P({shape:()=>r,unknownKeys:"strict",catchall:ne.create(),typeName:y.ZodObject,...w(e)});P.lazycreate=(r,e)=>new P({shape:r,unknownKeys:"strip",catchall:ne.create(),typeName:y.ZodObject,...w(e)});class Ge 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 V(o.ctx.common.issues));return m(t,{code:l.invalid_union,unionErrors:i}),_}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 V(c));return m(t,{code:l.invalid_union,unionErrors:o}),_}}get options(){return this._def.options}}Ge.create=(r,e)=>new Ge({options:r,typeName:y.ZodUnion,...w(e)});const ee=r=>r instanceof Qe?ee(r.schema):r instanceof G?ee(r.innerType()):r instanceof Je?[r.value]:r instanceof ue?r.options:r instanceof Xe?R.objectValues(r.enum):r instanceof ze?ee(r._def.innerType):r instanceof Be?[void 0]:r instanceof Fe?[null]:r instanceof Q?[void 0,...ee(r.unwrap())]:r instanceof de?[null,...ee(r.unwrap())]:r instanceof $t||r instanceof tt?ee(r.unwrap()):r instanceof et?ee(r._def.innerType):[];class kt extends k{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==g.object)return m(t,{code:l.invalid_type,expected:g.object,received:t.parsedType}),_;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}):(m(t,{code:l.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),_)}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=ee(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:y.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...w(n)})}}function Nt(r,e){const t=ae(r),n=ae(e);if(r===e)return{valid:!0,data:r};if(t===g.object&&n===g.object){const s=R.objectKeys(e),a=R.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 Ke extends k{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=(a,i)=>{if(Zt(a)||Zt(i))return _;const o=Nt(a.value,i.value);return o.valid?((At(a)||At(i))&&t.dirty(),{status:t.value,value:o.data}):(m(n,{code:l.invalid_intersection_types}),_)};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}))}}Ke.create=(r,e,t)=>new Ke({left:r,right:e,typeName:y.ZodIntersection,...w(t)});class X extends k{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.array)return m(n,{code:l.invalid_type,expected:g.array,received:n.parsedType}),_;if(n.data.length<this._def.items.length)return m(n,{code:l.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),_;!this._def.rest&&n.data.length>this._def.items.length&&(m(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 J(n,i,n.path,o)):null}).filter(i=>!!i);return n.common.async?Promise.all(a).then(i=>$.mergeArray(t,i)):$.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new X({...this._def,rest:e})}}X.create=(r,e)=>{if(!Array.isArray(r))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new X({items:r,typeName:y.ZodTuple,rest:null,...w(e)})};class Ye 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 m(n,{code:l.invalid_type,expected:g.object,received:n.parsedType}),_;const s=[],a=this._def.keyType,i=this._def.valueType;for(const o in n.data)s.push({key:a._parse(new J(n,o,n.path,o)),value:i._parse(new J(n,n.data[o],n.path,o)),alwaysSet:o in n.data});return n.common.async?$.mergeObjectAsync(t,s):$.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,n){return t instanceof k?new Ye({keyType:e,valueType:t,typeName:y.ZodRecord,...w(n)}):new Ye({keyType:B.create(),valueType:e,typeName:y.ZodRecord,...w(t)})}}class bt 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 m(n,{code:l.invalid_type,expected:g.map,received:n.parsedType}),_;const s=this._def.keyType,a=this._def.valueType,i=[...n.data.entries()].map(([o,c],u)=>({key:s._parse(new J(n,o,n.path,[u,"key"])),value:a._parse(new J(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 _;(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 _;(u.status==="dirty"||d.status==="dirty")&&t.dirty(),o.set(u.value,d.value)}return{status:t.value,value:o}}}}bt.create=(r,e,t)=>new bt({valueType:e,keyType:r,typeName:y.ZodMap,...w(t)});class ge extends k{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==g.set)return m(n,{code:l.invalid_type,expected:g.set,received:n.parsedType}),_;const s=this._def;s.minSize!==null&&n.data.size<s.minSize.value&&(m(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&&(m(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 _;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 J(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:v.toString(t)}})}max(e,t){return new ge({...this._def,maxSize:{value:e,message:v.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:y.ZodSet,...w(e)});class Oe extends k{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==g.function)return m(t,{code:l.invalid_type,expected:g.function,received:t.parsedType}),_;function n(o,c){return gt({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,mt(),Ee].filter(u=>!!u),issueData:{code:l.invalid_arguments,argumentsError:c}})}function s(o,c){return gt({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,mt(),Ee].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 Ce){const o=this;return L(async function(...c){const u=new V([]),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 L(function(...c){const u=o._def.args.safeParse(c,a);if(!u.success)throw new V([n(c,u.error)]);const d=Reflect.apply(i,this,u.data),h=o._def.returns.safeParse(d,a);if(!h.success)throw new V([s(d,h.error)]);return h.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new Oe({...this._def,args:X.create(e).rest(pe.create())})}returns(e){return new Oe({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,n){return new Oe({args:e||X.create([]).rest(pe.create()),returns:t||pe.create(),typeName:y.ZodFunction,...w(n)})}}class Qe 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})}}Qe.create=(r,e)=>new Qe({getter:r,typeName:y.ZodLazy,...w(e)});class Je extends k{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return m(t,{received:t.data,code:l.invalid_literal,expected:this._def.value}),_}return{status:"valid",value:e.data}}get value(){return this._def.value}}Je.create=(r,e)=>new Je({value:r,typeName:y.ZodLiteral,...w(e)});function vr(r,e){return new ue({values:r,typeName:y.ZodEnum,...w(e)})}class ue extends k{constructor(){super(...arguments),De.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),n=this._def.values;return m(t,{expected:R.joinValues(n),received:t.parsedType,code:l.invalid_type}),_}if(vt(this,De)||fr(this,De,new Set(this._def.values)),!vt(this,De).has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return m(t,{received:t.data,code:l.invalid_enum_value,options:n}),_}return L(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})}}De=new WeakMap;ue.create=vr;class Xe extends k{constructor(){super(...arguments),Me.set(this,void 0)}_parse(e){const t=R.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==g.string&&n.parsedType!==g.number){const s=R.objectValues(t);return m(n,{expected:R.joinValues(s),received:n.parsedType,code:l.invalid_type}),_}if(vt(this,Me)||fr(this,Me,new Set(R.getValidEnumValues(this._def.values))),!vt(this,Me).has(e.data)){const s=R.objectValues(t);return m(n,{received:n.data,code:l.invalid_enum_value,options:s}),_}return L(e.data)}get enum(){return this._def.values}}Me=new WeakMap;Xe.create=(r,e)=>new Xe({values:r,typeName:y.ZodNativeEnum,...w(e)});class Ce 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 m(t,{code:l.invalid_type,expected:g.promise,received:t.parsedType}),_;const n=t.parsedType===g.promise?t.data:Promise.resolve(t.data);return L(n.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Ce.create=(r,e)=>new Ce({type:r,typeName:y.ZodPromise,...w(e)});class G extends k{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===y.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=>{m(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 _;const c=await this._def.schema._parseAsync({data:o,path:n.path,parent:n});return c.status==="aborted"?_:c.status==="dirty"||t.value==="dirty"?xe(c.value):c});{if(t.value==="aborted")return _;const o=this._def.schema._parseSync({data:i,path:n.path,parent:n});return o.status==="aborted"?_:o.status==="dirty"||t.value==="dirty"?xe(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"?_:(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"?_:(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(!He(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=>He(i)?Promise.resolve(s.transform(i.value,a)).then(o=>({status:t.value,value:o})):i);R.assertNever(s)}}G.create=(r,e,t)=>new G({schema:r,typeName:y.ZodEffects,effect:e,...w(t)});G.createWithPreprocess=(r,e,t)=>new G({schema:e,effect:{type:"preprocess",transform:r},typeName:y.ZodEffects,...w(t)});class Q extends k{_parse(e){return this._getType(e)===g.undefined?L(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Q.create=(r,e)=>new Q({innerType:r,typeName:y.ZodOptional,...w(e)});class de extends k{_parse(e){return this._getType(e)===g.null?L(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}de.create=(r,e)=>new de({innerType:r,typeName:y.ZodNullable,...w(e)});class ze 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}}ze.create=(r,e)=>new ze({innerType:r,typeName:y.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...w(e)});class et 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 qe(s)?s.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new V(n.common.issues)},input:n.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new V(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}et.create=(r,e)=>new et({innerType:r,typeName:y.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...w(e)});class wt extends k{_parse(e){if(this._getType(e)!==g.nan){const n=this._getOrReturnCtx(e);return m(n,{code:l.invalid_type,expected:g.nan,received:n.parsedType}),_}return{status:"valid",value:e.data}}}wt.create=r=>new wt({typeName:y.ZodNaN,...w(r)});const Qn=Symbol("zod_brand");class $t 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 ot 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"?_:a.status==="dirty"?(t.dirty(),xe(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"?_: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 ot({in:e,out:t,typeName:y.ZodPipeline})}}class tt extends k{_parse(e){const t=this._def.innerType._parse(e),n=s=>(He(s)&&(s.value=Object.freeze(s.value)),s);return qe(t)?t.then(s=>n(s)):n(t)}unwrap(){return this._def.innerType}}tt.create=(r,e)=>new tt({innerType:r,typeName:y.ZodReadonly,...w(e)});function yr(r,e={},t){return r?Se.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})}}):Se.create()}const Jn={object:P.lazycreate};var y;(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"})(y||(y={}));const Xn=(r,e={message:`Input not instance of ${r.name}`})=>yr(t=>t instanceof r,e),_r=B.create,br=oe.create,zn=wt.create,es=ce.create,wr=We.create,ts=me.create,rs=yt.create,ns=Be.create,ss=Fe.create,as=Se.create,is=pe.create,os=ne.create,cs=_t.create,us=F.create,ds=P.create,ls=P.strictCreate,hs=Ge.create,fs=kt.create,ps=Ke.create,ms=X.create,gs=Ye.create,vs=bt.create,ys=ge.create,_s=Oe.create,bs=Qe.create,ws=Je.create,xs=ue.create,ks=Xe.create,Os=Ce.create,Ft=G.create,Ts=Q.create,js=de.create,Rs=G.createWithPreprocess,Es=ot.create,Ss=()=>_r().optional(),Cs=()=>br().optional(),Is=()=>wr().optional(),Ps={string:r=>B.create({...r,coerce:!0}),number:r=>oe.create({...r,coerce:!0}),boolean:r=>We.create({...r,coerce:!0}),bigint:r=>ce.create({...r,coerce:!0}),date:r=>me.create({...r,coerce:!0})},Zs=_;var O=Object.freeze({__proto__:null,defaultErrorMap:Ee,setErrorMap:Zn,getErrorMap:mt,makeIssue:gt,EMPTY_PATH:An,addIssueToContext:m,ParseStatus:$,INVALID:_,DIRTY:xe,OK:L,isAborted:Zt,isDirty:At,isValid:He,isAsync:qe,get util(){return R},get objectUtil(){return Pt},ZodParsedType:g,getParsedType:ae,ZodType:k,datetimeRegex:gr,ZodString:B,ZodNumber:oe,ZodBigInt:ce,ZodBoolean:We,ZodDate:me,ZodSymbol:yt,ZodUndefined:Be,ZodNull:Fe,ZodAny:Se,ZodUnknown:pe,ZodNever:ne,ZodVoid:_t,ZodArray:F,ZodObject:P,ZodUnion:Ge,ZodDiscriminatedUnion:kt,ZodIntersection:Ke,ZodTuple:X,ZodRecord:Ye,ZodMap:bt,ZodSet:ge,ZodFunction:Oe,ZodLazy:Qe,ZodLiteral:Je,ZodEnum:ue,ZodNativeEnum:Xe,ZodPromise:Ce,ZodEffects:G,ZodTransformer:G,ZodOptional:Q,ZodNullable:de,ZodDefault:ze,ZodCatch:et,ZodNaN:wt,BRAND:Qn,ZodBranded:$t,ZodPipeline:ot,ZodReadonly:tt,custom:yr,Schema:k,ZodSchema:k,late:Jn,get ZodFirstPartyTypeKind(){return y},coerce:Ps,any:as,array:us,bigint:es,boolean:wr,date:ts,discriminatedUnion:fs,effect:Ft,enum:xs,function:_s,instanceof:Xn,intersection:ps,lazy:bs,literal:ws,map:vs,nan:zn,nativeEnum:ks,never:os,null:ss,nullable:js,number:br,object:ds,oboolean:Is,onumber:Cs,optional:Ts,ostring:Ss,pipeline:Es,preprocess:Rs,promise:Os,record:gs,set:ys,strictObject:ls,string:_r,symbol:rs,transformer:Ft,tuple:ms,undefined:ns,union:hs,unknown:is,void:cs,NEVER:Zs,ZodIssueCode:l,quotelessJson:Pn,ZodError:V}),Dt=class Mt extends In{constructor(t){super(t);p(this,"openAPIRegistry");p(this,"defaultHook");p(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 b=_e("query",n.request.query,a);i.push(b)}if((d=n.request)!=null&&d.params){const b=_e("param",n.request.params,a);i.push(b)}if((h=n.request)!=null&&h.headers){const b=_e("header",n.request.headers,a);i.push(b)}if((T=n.request)!=null&&T.cookies){const b=_e("cookie",n.request.cookies,a);i.push(b)}const o=(E=(S=n.request)==null?void 0:S.body)==null?void 0:E.content;if(o)for(const b of Object.keys(o)){if(!o[b])continue;const A=o[b].schema;if(A instanceof k){if(b.startsWith("application/json")){const M=_e("json",A,a);i.push(M)}if(b.startsWith("multipart/form-data")||b.startsWith("application/x-www-form-urlencoded")){const M=_e("form",A,a);i.push(M)}}}const c=t?Array.isArray(t)?t:[t]:[];return this.on([n.method],n.path.replaceAll(/\/{(.+?)}/g,"/:$1"),...c,...i,s),this});p(this,"getOpenAPIDocument",t=>new Gr(this.openAPIRegistry.definitions).generateDocument(t));p(this,"getOpenAPI31Document",t=>new Qr(this.openAPIRegistry.definitions).generateDocument(t));p(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)}}));p(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 Sr,this.defaultHook=t==null?void 0:t.defaultHook}route(t,n){const s=t.replaceAll(/:([^\/]+)/g,"{$1}");return super.route(t,n),n instanceof Mt?(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:he(s,a.route.path)});case"webhook":return this.openAPIRegistry.registerWebhook({...a.webhook,path:he(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 Mt({...super.basePath(t),defaultHook:this.defaultHook})}},Gt=r=>{const e={...r,getRoutingPath(){return r.path.replaceAll(/\/{(.+?)}/g,"/:$1")}};return Object.defineProperty(e,"getRoutingPath",{enumerable:!1})};Tr(O);const As=O.object({alg:O.string(),e:O.string(),kid:O.string(),kty:O.string(),n:O.string(),use:O.string().optional()}),Ns=O.object({keys:O.array(As)}),Kt=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())}),Ds=new Dt().openapi(Gt({tags:["jwks"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:Ns}},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(Gt({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:Kt}},description:"List of tenants"}}}),async r=>{const{env:e}=r,{ISSUER:t}=e,n=Kt.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 Ms(){const r=new Dt;r.get("/",t=>t.text("Hello, authhero!"));const e=new Dt().route("/.well-known",Ds);return e.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Oauth endpoints"}}),r.route("/",e),r}exports.init=Ms;
1
+ "use strict";var ds=Object.defineProperty;var or=n=>{throw TypeError(n)};var us=(n,e,t)=>e in n?ds(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var g=(n,e,t)=>us(n,typeof e!="symbol"?e+"":e,t),cr=(n,e,t)=>e.has(n)||or("Cannot "+t);var m=(n,e,t)=>(cr(n,e,"read from private field"),t?t.call(n):e.get(n)),K=(n,e,t)=>e.has(n)?or("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),A=(n,e,t,r)=>(cr(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function bt(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 C(n,e){var t;return((t=n==null?void 0:n._def)===null||t===void 0?void 0:t.typeName)===e}function ls(n){return"_def"in n}function gt(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 ps(n){if(typeof n.ZodType.prototype.openapi<"u")return;n.ZodType.prototype.openapi=function(s,a){var i,o,d,u,l,p;const R=typeof s=="string"?a:s,D=R??{},{param:N}=D,j=bt(D,["param"]),V=Object.assign(Object.assign({},(i=this._def.openapi)===null||i===void 0?void 0:i._internal),typeof s=="string"?{refId:s}:void 0),H=Object.assign(Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o.metadata),j),!((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),ee=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(V).length>0?{_internal:V}:void 0),Object.keys(H).length>0?{metadata:H}:void 0)}));if(C(this,"ZodObject")){const te=this.extend;ee.extend=function(...Re){var ae,ne,X,ge,ie,Ue;const qe=te.apply(this,Re);return qe._def.openapi={_internal:{extendedFrom:!((ne=(ae=this._def.openapi)===null||ae===void 0?void 0:ae._internal)===null||ne===void 0)&&ne.refId?{refId:(ge=(X=this._def.openapi)===null||X===void 0?void 0:X._internal)===null||ge===void 0?void 0:ge.refId,schema:this}:(ie=this._def.openapi)===null||ie===void 0?void 0:ie._internal.extendedFrom},metadata:(Ue=qe._def.openapi)===null||Ue===void 0?void 0:Ue.metadata},qe}}return ee},gt(n,"optional"),gt(n,"nullable"),gt(n,"default"),gt(n,"transform"),gt(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 yn(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=>yn(n[r],e[r]))}class hs{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=>yn(a,e))||r.push(e)}contains(e){const t=this.hashCodeOf(e),r=this.buckets.get(t);return r?r.some(s=>yn(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 jt(n){return n==null}function Zt(n,e){const t={};return Object.entries(n).forEach(([r,s])=>{t[r]=e(s)}),t}function fs(n,e){const t={};return Object.entries(n).forEach(([r,s])=>{e.some(a=>a===r)||(t[r]=s)}),t}function st(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=>!jt(e))}const Hn=yn;function ms(n){const e=new hs;return n.forEach(t=>e.put(t)),[...e.values()]}function wr(n){return typeof n=="string"}class gs{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 Mn{constructor(e){this.message=e}}class _t extends Mn{constructor(e,t){super(e),this.data=t}}class vn extends Mn{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 yt(n,e){try{return n()}catch(t){throw t instanceof vn?new vn(Object.assign(Object.assign({},t.data),e)):t}}class _s extends Mn{constructor(e){super("Unknown zod object type, please specify `type` and other OpenAPI props using `ZodSchema.openapi`."),this.data=e}}class L{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 st(fs(e,["param"]),jt)}static buildParameterMetadata(e){return st(e,jt)}static applySchemaMetadata(e,t){return st(Object.assign(Object.assign({},e),this.buildSchemaMetadata(t)),jt)}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&&C(e,t)?e:C(e,"ZodOptional")||C(e,"ZodNullable")||C(e,"ZodBranded")?this.unwrapUntil(e.unwrap(),t):C(e,"ZodDefault")||C(e,"ZodReadonly")?this.unwrapUntil(e._def.innerType,t):C(e,"ZodEffects")?this.unwrapUntil(e._def.schema,t):C(e,"ZodPipeline")?this.unwrapUntil(e._def.in,t):t?void 0:e}static isOptionalSchema(e){return C(e,"ZodEffects")?this.isOptionalSchema(e._def.schema):e.isOptional()}}class ys{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 vs{transform(e){return Object.assign(Object.assign({},e("string")),{pattern:"^d+$"})}}class bs{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=>L.getRefId(a)===void 0))return;const s={};return e.forEach(a=>{var i;const o=L.getRefId(a),d=(i=a.shape)===null||i===void 0?void 0:i[t];if(C(d,"ZodEnum")||C(d,"ZodNativeEnum")){Object.values(d.enum).filter(wr).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 ks{transform(e,t){return Object.assign(Object.assign({},t("string")),{enum:e._def.values})}}class ws{transform(e,t,r,s){const i={allOf:this.flattenIntersectionTypes(e).map(s)};return t?{anyOf:r([i],t)}:i}flattenIntersectionTypes(e){if(!C(e,"ZodIntersection"))return[e];const t=this.flattenIntersectionTypes(e._def.left),r=this.flattenIntersectionTypes(e._def.right);return[...t,...r]}}class xs{transform(e,t){return Object.assign(Object.assign({},t(typeof e._def.value)),{enum:[e._def.value]})}}function Os(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 Ts{transform(e,t){const{type:r,values:s}=Os(e._def.values);if(r==="mixed")throw new Mn("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 js{transform(e,t,r){return Object.assign(Object.assign({},t(e.isInt?"integer":"number")),r(e._def.checks))}}class Zs{transform(e,t,r,s){var a;const i=(a=L.getInternalMetadata(e))===null||a===void 0?void 0:a.extendedFrom,o=this.requiredKeysOf(e),d=Zt(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=Zt(u==null?void 0:u._def.shape(),s),R=Object.fromEntries(Object.entries(d).filter(([j,V])=>!Hn(p[j],V))),D=o.filter(j=>!l.includes(j)),N=Object.assign(Object.assign(Object.assign(Object.assign({},r("object")),{default:t,properties:R}),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 C(s,"ZodNever")?r==="strict"?{additionalProperties:!1}:{}:{additionalProperties:t(s)}}requiredKeysOf(e){return Object.entries(e._def.shape()).filter(([t,r])=>!L.isOptionalSchema(r)).map(([t,r])=>t)}}class Rs{transform(e,t,r){const s=e._def.valueType,a=e._def.keyType,i=r(s);if(C(a,"ZodEnum")||C(a,"ZodNativeEnum")){const d=Object.values(a.enum).filter(wr).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 Es{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 Ss{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 Cs{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 C(e,"ZodUnion")?e._def.options.flatMap(r=>this.flattenUnionTypes(r)):[e]}unwrapNullable(e){return C(e,"ZodNullable")?this.unwrapNullable(e.unwrap()):e}}class Is{constructor(e){this.versionSpecifics=e,this.objectTransformer=new Zs,this.stringTransformer=new Es,this.numberTransformer=new js,this.bigIntTransformer=new vs,this.literalTransformer=new xs,this.enumTransformer=new ks,this.nativeEnumTransformer=new Ts,this.arrayTransformer=new ys,this.unionTransformer=new Cs,this.discriminatedUnionTransformer=new bs,this.intersectionTransformer=new ws,this.recordTransformer=new Rs,this.tupleTransformer=new Ss(e)}transform(e,t,r,s,a){if(C(e,"ZodNull"))return this.versionSpecifics.nullType;if(C(e,"ZodUnknown")||C(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(C(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(C(e,"ZodUnknown")||C(e,"ZodAny"))return this.versionSpecifics.mapNullableType(void 0,t);if(C(e,"ZodString"))return this.stringTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(C(e,"ZodNumber"))return this.numberTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),i=>this.versionSpecifics.getNumberChecks(i));if(C(e,"ZodBigInt"))return this.bigIntTransformer.transform(i=>this.versionSpecifics.mapNullableType(i,t));if(C(e,"ZodBoolean"))return this.versionSpecifics.mapNullableType("boolean",t);if(C(e,"ZodLiteral"))return this.literalTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(C(e,"ZodEnum"))return this.enumTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(C(e,"ZodNativeEnum"))return this.nativeEnumTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t));if(C(e,"ZodArray"))return this.arrayTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),r);if(C(e,"ZodTuple"))return this.tupleTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),r);if(C(e,"ZodUnion"))return this.unionTransformer.transform(e,i=>this.versionSpecifics.mapNullableOfArray(i,t),r);if(C(e,"ZodDiscriminatedUnion"))return this.discriminatedUnionTransformer.transform(e,t,i=>this.versionSpecifics.mapNullableOfArray(i,t),r,s);if(C(e,"ZodIntersection"))return this.intersectionTransformer.transform(e,t,i=>this.versionSpecifics.mapNullableOfArray(i,t),r);if(C(e,"ZodRecord"))return this.recordTransformer.transform(e,i=>this.versionSpecifics.mapNullableType(i,t),r);if(C(e,"ZodDate"))return this.versionSpecifics.mapNullableType("string",t);const a=L.getRefId(e);throw new _s({currentSchema:e._def,schemaName:a})}}class xr{constructor(e,t){this.definitions=e,this.versionSpecifics=t,this.schemaRefs={},this.paramRefs={},this.pathRefs={},this.rawComponents=[],this.openApiTransformer=new Is(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=L.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 _t(`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 _t("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=L.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(C(e,"ZodObject")){const o=e._def.shape();return Object.entries(o).map(([u,l])=>{var p,R;const D=L.getMetadata(l),N=this.getParameterRef(D,{in:t,name:u});if(N)return N;const j=(p=D==null?void 0:D.metadata)===null||p===void 0?void 0:p.param;if(j!=null&&j.name&&j.name!==u)throw new _t("Conflicting names for parameter",{key:"name",values:[u,j.name]});if(j!=null&&j.in&&j.in!==t)throw new _t(`Conflicting location for parameter ${(R=j.name)!==null&&R!==void 0?R:u}`,{key:"in",values:[t,j.in]});return this.generateParameter(l.openapi({param:{name:u,in:t}}))})}if(a!=null&&a.in&&a.in!==t)throw new _t(`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=L.getParamMetadata(e),s=(t=r==null?void 0:r.metadata)===null||t===void 0?void 0:t.param,a=!L.isOptionalSchema(e)&&!e.isNullable(),i=this.generateSchemaWithRef(e);return Object.assign({schema:i,required:a},s?L.buildParameterMetadata(s):{})}generateParameter(e){var t;const r=L.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 vn({missingField:"name"});if(!i)throw new vn({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=L.unwrapChained(e),s=L.getMetadata(e),a=L.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?L.applySchemaMetadata(i,s.metadata):st(i,jt)}constructReferencedOpenAPISchema(e){var t;const r=L.getMetadata(e),s=L.unwrapChained(e),a=L.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=L.getMetadata(e),s=L.getRefId(e);if(!s||!this.schemaRefs[s])return this.generateSchemaWithMetadata(e);const a=this.schemaRefs[s],i={$ref:this.generateSchemaRef(s)},o=st(L.buildSchemaMetadata((t=r==null?void 0:r.metadata)!==null&&t!==void 0?t:{}),(l,p)=>l===void 0||Hn(l,a[p]));if(o.type)return{allOf:[i,o]};const d=st(this.constructReferencedOpenAPISchema(e),(l,p)=>l===void 0||Hn(l,a[p])),u=L.applySchemaMetadata(d,o);return Object.keys(u).length>0?{allOf:[i,u]}:i}generateSchemaWithRef(e){const t=L.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=bt(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=yt(()=>r?this.generateInlineParameters(r,"query"):[],{location:"query"}),o=yt(()=>s?this.generateInlineParameters(s,"path"):[],{location:"path"}),d=yt(()=>a?this.generateInlineParameters(a,"cookie"):[],{location:"cookie"}),u=yt(()=>{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 C(e,"ZodEffects")?this.cleanParameter(e._def.schema):e}generatePath(e){const{method:t,path:r,request:s,responses:a}=e,i=bt(e,["method","path","request","responses"]),o=Zt(a,p=>this.getResponse(p)),d=yt(()=>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=bt(e,["content","headers"]);const a=t?{content:this.getBodyContent(t)}:{};if(!r)return Object.assign(Object.assign({},s),a);const i=C(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 Zt(t,s=>this.generateSimpleParameter(s))}getBodyContent(e){return Zt(e,t=>{if(!t||!ls(t.schema))return t;const{schema:r}=t,s=bt(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 Ps{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=ms(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 Ns{constructor(e){const t=new Ps;this.generator=new xr(e,t)}generateDocument(e){const t=this.generator.generateDocumentData();return Object.assign(Object.assign({},e),t)}generateComponents(){return this.generator.generateComponents()}}class As{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 $s(n){return"type"in n&&n.type==="webhook"}class Ms{constructor(e){this.definitions=e,this.webhookRefs={};const t=new As;this.generator=new xr(this.definitions,t)}generateDocument(e){const t=this.generator.generateDocumentData();return this.definitions.filter($s).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 Or=n=>{const e=n.split("/");return e[0]===""&&e.shift(),e},Ds=n=>{const{groups:e,path:t}=Ls(n),r=Or(t);return Vs(r,e)},Ls=n=>{const e=[];return n=n.replace(/\{[^}]+\}/g,(t,r)=>{const s=`@${r}`;return e.push([s,t]),s}),{groups:e,path:n}},Vs=(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},hn={},ur=n=>{if(n==="*")return"*";const e=n.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);return e?(hn[n]||(e[2]?hn[n]=[n,e[1],new RegExp("^"+e[2]+"$")]:hn[n]=[n,e[1],!0]),hn[n]):null},Us=n=>{try{return decodeURI(n)}catch{return n.replace(/(?:%[0-9A-Fa-f]{2})+/g,e=>{try{return decodeURI(e)}catch{return e}})}},Tr=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 Us(i.includes("%25")?i.replace(/%25/g,"%2525"):i)}else if(s===63)break}return e.slice(t,r)},qs=n=>{const e=Tr(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},jr=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)},Un=n=>/[%+]/.test(n)?(n.indexOf("+")!==-1&&(n=n.replace(/\+/g," ")),/%/.test(n)?bn(n):n):n,Zr=(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 Un(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=Un(d)),a=i,d==="")continue;let u;o===-1?u="":(u=n.slice(o+1,i===-1?void 0:i),r&&(u=Un(u))),t?(s[d]&&Array.isArray(s[d])||(s[d]=[]),s[d].push(u)):s[d]??(s[d]=u)}return e?s[e]:s},Bs=Zr,Ws=(n,e)=>Zr(n,e,!0),bn=decodeURIComponent,Hs=/^[\w!#$%&'*.^`|~+-]+$/,Fs=/^[ !#-:<-[\]-~]*$/,Ks=(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(!Hs.test(i))return r;let o=s.substring(a+1).trim();return o.startsWith('"')&&o.endsWith('"')&&(o=o.slice(1,-1)),Fs.test(o)&&(r[i]=bn(o)),r},{}),Gs=(n,e,t)=>{const r=n.req.raw.headers.get("Cookie");return r?Ks(r):{}},fn=class extends Error{constructor(e=500,t){super(t==null?void 0:t.message,{cause:t==null?void 0:t.cause});g(this,"res");g(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})}},zs=(n,e)=>new Response(n,{headers:{"Content-Type":e}}).formData(),Ys=(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 fn(400,{message:o})}try{s=await t.req.json()}catch{const o="Malformed JSON in request body";throw new fn(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 zs(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 fn(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=Gs(t);break}const i=await e(s,t);if(i instanceof Response)return i;t.req.addValidatedData(n,i),await r()};const Qe=(n,e,t)=>Ys(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 Js=async(n,e=Object.create(null))=>{const{all:t=!1,dot:r=!1}=e,a=(n instanceof Rr?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")?Qs(n,{all:t,dot:r}):{}};async function Qs(n,e){const t=await n.formData();return t?Xs(t,e):{}}function Xs(n,e){const t=Object.create(null);return n.forEach((r,s)=>{e.all||s.endsWith("[]")?ea(t,s,r):t[s]=r}),e.dot&&Object.entries(t).forEach(([r,s])=>{r.includes(".")&&(ta(t,r,s),delete t[r])}),t}var ea=(n,e,t)=>{n[e]!==void 0?Array.isArray(n[e])?n[e].push(t):n[e]=[n[e],t]:n[e]=t},ta=(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])})},ot,oe,vr,Rr=(vr=class{constructor(n,e="/",t=[[]]){g(this,"raw");K(this,ot);K(this,oe);g(this,"routeIndex",0);g(this,"path");g(this,"bodyCache",{});g(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,A(this,oe,t),A(this,ot,{})}param(n){return n?this.getDecodedParam(n):this.getAllDecodedParams()}getDecodedParam(n){const e=m(this,oe)[0][this.routeIndex][1][n],t=this.getParamValue(e);return t?/\%/.test(t)?bn(t):t:void 0}getAllDecodedParams(){const n={},e=Object.keys(m(this,oe)[0][this.routeIndex][1]);for(const t of e){const r=this.getParamValue(m(this,oe)[0][this.routeIndex][1][t]);r&&typeof r=="string"&&(n[t]=/\%/.test(r)?bn(r):r)}return n}getParamValue(n){return m(this,oe)[1]?m(this,oe)[1][n]:n}query(n){return Bs(this.url,n)}queries(n){return Ws(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 Js(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,ot)[n]=e}valid(n){return m(this,ot)[n]}get url(){return this.raw.url}get method(){return this.raw.method}get matchedRoutes(){return m(this,oe)[0].map(([[,n]])=>n)}get routePath(){return m(this,oe)[0].map(([[,n]])=>n)[this.routeIndex].path}},ot=new WeakMap,oe=new WeakMap,vr),na={Stringify:1,BeforeStream:2,Stream:3},Er=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=>Er(d,e,!1,r,s))).then(()=>s[0]))):Promise.resolve(n)},ra="text/plain; charset=UTF-8",qn=(n,e={})=>(Object.entries(e).forEach(([t,r])=>n.set(t,r)),n),an,on,Ie,He,Oe,U,W,ce,Te,cn,ct,dt,dn,un,br,mn=(br=class{constructor(n,e){K(this,an);K(this,on);g(this,"env",{});K(this,Ie);g(this,"finalized",!1);g(this,"error");K(this,He,200);K(this,Oe);K(this,U);K(this,W);K(this,ce);K(this,Te,!0);K(this,cn);K(this,ct);K(this,dt);K(this,dn);K(this,un);g(this,"render",(...n)=>(m(this,ct)??A(this,ct,e=>this.html(e)),m(this,ct).call(this,...n)));g(this,"setLayout",n=>A(this,cn,n));g(this,"getLayout",()=>m(this,cn));g(this,"setRenderer",n=>{A(this,ct,n)});g(this,"header",(n,e,t)=>{if(e===void 0){m(this,U)?m(this,U).delete(n):m(this,W)&&delete m(this,W)[n.toLocaleLowerCase()],this.finalized&&this.res.headers.delete(n);return}t!=null&&t.append?(m(this,U)||(A(this,Te,!1),A(this,U,new Headers(m(this,W))),A(this,W,{})),m(this,U).append(n,e)):m(this,U)?m(this,U).set(n,e):(m(this,W)??A(this,W,{}),m(this,W)[n.toLowerCase()]=e),this.finalized&&(t!=null&&t.append?this.res.headers.append(n,e):this.res.headers.set(n,e))});g(this,"status",n=>{A(this,Te,!1),A(this,He,n)});g(this,"set",(n,e)=>{m(this,Ie)??A(this,Ie,{}),m(this,Ie)[n]=e});g(this,"get",n=>m(this,Ie)?m(this,Ie)[n]:void 0);g(this,"newResponse",(n,e,t)=>{if(m(this,Te)&&!t&&!e&&m(this,He)===200)return new Response(n,{headers:m(this,W)});if(e&&typeof e!="number"){const s=new Headers(e.headers);m(this,U)&&m(this,U).forEach((i,o)=>{o==="set-cookie"?s.append(o,i):s.set(o,i)});const a=qn(s,m(this,W));return new Response(n,{headers:a,status:e.status??m(this,He)})}const r=typeof e=="number"?e:m(this,He);m(this,W)??A(this,W,{}),m(this,U)??A(this,U,new Headers),qn(m(this,U),m(this,W)),m(this,ce)&&(m(this,ce).headers.forEach((s,a)=>{var i,o;a==="set-cookie"?(i=m(this,U))==null||i.append(a,s):(o=m(this,U))==null||o.set(a,s)}),qn(m(this,U),m(this,W))),t??(t={});for(const[s,a]of Object.entries(t))if(typeof a=="string")m(this,U).set(s,a);else{m(this,U).delete(s);for(const i of a)m(this,U).append(s,i)}return new Response(n,{status:r,headers:m(this,U)})});g(this,"body",(n,e,t)=>typeof e=="number"?this.newResponse(n,e,t):this.newResponse(n,e));g(this,"text",(n,e,t)=>{if(!m(this,W)){if(m(this,Te)&&!t&&!e)return new Response(n);A(this,W,{})}return m(this,W)["content-type"]=ra,typeof e=="number"?this.newResponse(n,e,t):this.newResponse(n,e)});g(this,"json",(n,e,t)=>{const r=JSON.stringify(n);return m(this,W)??A(this,W,{}),m(this,W)["content-type"]="application/json; charset=UTF-8",typeof e=="number"?this.newResponse(r,e,t):this.newResponse(r,e)});g(this,"html",(n,e,t)=>(m(this,W)??A(this,W,{}),m(this,W)["content-type"]="text/html; charset=UTF-8",typeof n=="object"&&(n instanceof Promise||(n=n.toString()),n instanceof Promise)?n.then(r=>Er(r,na.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)));g(this,"redirect",(n,e)=>(m(this,U)??A(this,U,new Headers),m(this,U).set("Location",n),this.newResponse(null,e??302)));g(this,"notFound",()=>(m(this,dt)??A(this,dt,()=>new Response),m(this,dt).call(this,this)));A(this,an,n),e&&(A(this,Oe,e.executionCtx),this.env=e.env,A(this,dt,e.notFoundHandler),A(this,un,e.path),A(this,dn,e.matchResult))}get req(){return m(this,on)??A(this,on,new Rr(m(this,an),m(this,un),m(this,dn))),m(this,on)}get event(){if(m(this,Oe)&&"respondWith"in m(this,Oe))return m(this,Oe);throw Error("This context has no FetchEvent")}get executionCtx(){if(m(this,Oe))return m(this,Oe);throw Error("This context has no ExecutionContext")}get res(){return A(this,Te,!1),m(this,ce)||A(this,ce,new Response("404 Not Found",{status:404}))}set res(n){if(A(this,Te,!1),m(this,ce)&&n){m(this,ce).headers.delete("content-type");for(const[e,t]of m(this,ce).headers.entries())if(e==="set-cookie"){const r=m(this,ce).headers.getSetCookie();n.headers.delete("set-cookie");for(const s of r)n.headers.append("set-cookie",s)}else n.headers.set(e,t)}A(this,ce,n),this.finalized=!0}get var(){return{...m(this,Ie)}}},an=new WeakMap,on=new WeakMap,Ie=new WeakMap,He=new WeakMap,Oe=new WeakMap,U=new WeakMap,W=new WeakMap,ce=new WeakMap,Te=new WeakMap,cn=new WeakMap,ct=new WeakMap,dt=new WeakMap,dn=new WeakMap,un=new WeakMap,br),lr=(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 mn&&(r.req.routeIndex=o)):l=o===n.length&&s||void 0,!l)r instanceof mn&&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 mn&&e)r.error=p,d=await e(p,r),u=!0;else throw p}return d&&(r.finalized===!1||u)&&(r.res=d),r}},F="ALL",sa="all",aa=["get","post","put","delete","options","patch"],Sr="Can not add a route since the matcher is already built.",Cr=class extends Error{},ia=Symbol("composedHandler"),oa=n=>n.text("404 Not Found",404),pr=(n,e)=>"getResponse"in n?n.getResponse():(console.error(n),e.text("Internal Server Error",500)),de,kr,Ir=(kr=class{constructor(e={}){g(this,"get");g(this,"post");g(this,"put");g(this,"delete");g(this,"options");g(this,"patch");g(this,"all");g(this,"on");g(this,"use");g(this,"router");g(this,"getPath");g(this,"_basePath","/");K(this,de,"/");g(this,"routes",[]);g(this,"notFoundHandler",oa);g(this,"errorHandler",pr);g(this,"onError",e=>(this.errorHandler=e,this));g(this,"notFound",e=>(this.notFoundHandler=e,this));g(this,"fetch",(e,...t)=>this.dispatch(e,t[1],t[0],e.method));g(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)});g(this,"fire",()=>{addEventListener("fetch",e=>{e.respondWith(this.dispatch(e.request,e,void 0,e.request.method))})});[...aa,sa].forEach(s=>{this[s]=(a,...i)=>(typeof a=="string"?A(this,de,a):this.addRoute(s,m(this,de),a),i.forEach(o=>{typeof o!="string"&&this.addRoute(s,m(this,de),o)}),this)}),this.on=(s,a,...i)=>{for(const o of[a].flat()){A(this,de,o);for(const d of[s].flat())i.map(u=>{this.addRoute(d.toUpperCase(),m(this,de),u)})}return this},this.use=(s,...a)=>(typeof s=="string"?A(this,de,s):(A(this,de,"*"),a.unshift(s)),a.forEach(i=>{this.addRoute(F,m(this,de),i)}),this);const r=e.strict??!0;delete e.strict,Object.assign(this,e),this.getPath=r?e.getPath??Tr:qs}clone(){const e=new Ir({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===pr?a=s.handler:(a=async(i,o)=>(await lr([],t.errorHandler)(i,()=>s.handler(i,o))).res,a[ia]=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(F,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 mn(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=lr(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)}})()}},de=new WeakMap,kr),kn="[^/]+",Rt=".*",Et="(?:|/.*)",kt=Symbol(),ca=new Set(".\\+*[^]$()");function da(n,e){return n.length===1?e.length===1?n<e?-1:1:-1:e.length===1||n===Rt||n===Et?1:e===Rt||e===Et?-1:n===kn?1:e===kn?-1:n.length===e.length?n<e?-1:1:e.length-n.length}var Fn=class{constructor(){g(this,"index");g(this,"varIndex");g(this,"children",Object.create(null))}insert(e,t,r,s,a){if(e.length===0){if(this.index!==void 0)throw kt;if(a)return;this.index=t;return}const[i,...o]=e,d=i==="*"?o.length===0?["","",Rt]:["","",kn]:i==="/*"?["","",Et]:i.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);let u;if(d){const l=d[1];let p=d[2]||kn;if(l&&d[2]&&(p=p.replace(/^\((?!\?:)(?=[^)]+\)$)/,"(?:"),/\((?!\?:)/.test(p)))throw kt;if(u=this.children[p],!u){if(Object.keys(this.children).some(R=>R!==Rt&&R!==Et))throw kt;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!==Rt&&l!==Et))throw kt;if(a)return;u=this.children[i]=new Fn}u.insert(o,t,r,s,a)}buildRegExpStr(){const t=Object.keys(this.children).sort(da).map(r=>{const s=this.children[r];return(typeof s.varIndex=="number"?`(${r})@${s.varIndex}`:ca.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("|")+")"}},ua=class{constructor(){g(this,"context",{varIndex:0});g(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]}},Pr=[],la=[/^$/,[],Object.create(null)],gn=Object.create(null);function Nr(n){return gn[n]??(gn[n]=new RegExp(n==="*"?"":`^${n.replace(/\/\*$|([.\\+*[^\]$()])/g,(e,t)=>t?`\\${t}`:"(?:|/.*)")}$`))}function pa(){gn=Object.create(null)}function ha(n){var u;const e=new ua,t=[];if(n.length===0)return la;const r=n.map(l=>[!/\*|\/:/.test(l[0]),...l]).sort(([l,p],[R,D])=>l?1:R?-1:p.length-D.length),s=Object.create(null);for(let l=0,p=-1,R=r.length;l<R;l++){const[D,N,j]=r[l];D?s[N]=[j.map(([H])=>[H,Object.create(null)]),Pr]:p++;let V;try{V=e.insert(N,p,D)}catch(H){throw H===kt?new Cr(N):H}D||(t[p]=j.map(([H,ee])=>{const te=Object.create(null);for(ee-=1;ee>=0;ee--){const[Re,ae]=V[ee];te[Re]=ae}return[H,te]}))}const[a,i,o]=e.buildRegExp();for(let l=0,p=t.length;l<p;l++)for(let R=0,D=t[l].length;R<D;R++){const N=(u=t[l][R])==null?void 0:u[1];if(!N)continue;const j=Object.keys(N);for(let V=0,H=j.length;V<H;V++)N[j[V]]=o[N[j[V]]]}const d=[];for(const l in i)d[l]=t[i[l]];return[a,d,s]}function Xe(n,e){if(n){for(const t of Object.keys(n).sort((r,s)=>s.length-r.length))if(Nr(t).test(e))return[...n[t]]}}var fa=class{constructor(){g(this,"name","RegExpRouter");g(this,"middleware");g(this,"routes");this.middleware={[F]:Object.create(null)},this.routes={[F]:Object.create(null)}}add(n,e,t){var o;const{middleware:r,routes:s}=this;if(!r||!s)throw new Error(Sr);r[n]||[r,s].forEach(d=>{d[n]=Object.create(null),Object.keys(d[F]).forEach(u=>{d[n][u]=[...d[F][u]]})}),e==="/*"&&(e="*");const a=(e.match(/\/:/g)||[]).length;if(/\*$/.test(e)){const d=Nr(e);n===F?Object.keys(r).forEach(u=>{var l;(l=r[u])[e]||(l[e]=Xe(r[u],e)||Xe(r[F],e)||[])}):(o=r[n])[e]||(o[e]=Xe(r[n],e)||Xe(r[F],e)||[]),Object.keys(r).forEach(u=>{(n===F||n===u)&&Object.keys(r[u]).forEach(l=>{d.test(l)&&r[u][l].push([t,a])})}),Object.keys(s).forEach(u=>{(n===F||n===u)&&Object.keys(s[u]).forEach(l=>d.test(l)&&s[u][l].push([t,a]))});return}const i=jr(e)||[e];for(let d=0,u=i.length;d<u;d++){const l=i[d];Object.keys(s).forEach(p=>{var R;(n===F||n===p)&&((R=s[p])[l]||(R[l]=[...Xe(r[p],l)||Xe(r[F],l)||[]]),s[p][l].push([t,a-u+d+1]))})}}match(n,e){pa();const t=this.buildAllMatchers();return this.match=(r,s)=>{const a=t[r]||t[F],i=a[2][s];if(i)return i;const o=s.match(a[0]);if(!o)return[[],Pr];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===F;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!==F&&e.push(...Object.keys(r[F]).map(a=>[a,r[F][a]]))}),t?ha(e):null}},ma=class{constructor(n){g(this,"name","SmartRouter");g(this,"routers",[]);g(this,"routes",[]);Object.assign(this,n)}add(n,e,t){if(!this.routes)throw new Error(Sr);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 Cr)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]}},Ar=class{constructor(n,e,t){g(this,"methods");g(this,"children");g(this,"patterns");g(this,"order",0);g(this,"name");g(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=Ds(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 R=ur(l);R&&a.push(R[1]);continue}r.children[l]=new Ar;const p=ur(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[F],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=Or(e);for(let o=0,d=a.length;o<d;o++){const u=a[o],l=o===d-1,p=[];for(let R=0,D=s.length;R<D;R++){const N=s[R],j=N.children[u];j&&(j.params=N.params,l===!0?(j.children["*"]&&t.push(...this.gHSets(j.children["*"],n,N.params,Object.create(null))),t.push(...this.gHSets(j,n,N.params,Object.create(null)))):p.push(j));for(let V=0,H=N.patterns.length;V<H;V++){const ee=N.patterns[V],te={...N.params};if(ee==="*"){const ie=N.children["*"];ie&&(t.push(...this.gHSets(ie,n,N.params,Object.create(null))),p.push(ie));continue}if(u==="")continue;const[Re,ae,ne]=ee,X=N.children[Re],ge=a.slice(o).join("/");if(ne instanceof RegExp&&ne.test(ge)){te[ae]=ge,t.push(...this.gHSets(X,n,N.params,te));continue}(ne===!0||ne instanceof RegExp&&ne.test(u))&&typeof Re=="string"&&(te[ae]=u,l===!0?(t.push(...this.gHSets(X,n,te,N.params)),X.children["*"]&&t.push(...this.gHSets(X.children["*"],n,te,N.params))):(X.params=te,p.push(X)))}}s=p}return[t.sort((o,d)=>o.score-d.score).map(({handler:o,params:d})=>[o,d])]}},ga=class{constructor(){g(this,"name","TrieRouter");g(this,"node");this.node=new Ar}add(n,e,t){const r=jr(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)}},_a=class extends Ir{constructor(n={}){super(n),this.router=n.router??new ma({routers:[new fa,new ga]})}},$;(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 Kn;(function(n){n.mergeShapes=(e,t)=>({...e,...t})})(Kn||(Kn={}));const v=$.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=$.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"]),ya=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 ut=(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,$.jsonStringifyReplacer)}`;break;case h.unrecognized_keys:t=`Unrecognized key(s) in object: ${$.joinValues(n.keys,", ")}`;break;case h.invalid_union:t="Invalid input";break;case h.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${$.joinValues(n.options)}`;break;case h.invalid_enum_value:t=`Invalid enum value. Expected ${$.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}"`:$.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,$.assertNever(n)}return{message:t}};let $r=ut;function va(n){$r=n}function wn(){return $r}const xn=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}},ba=[];function _(n,e){const t=wn(),r=xn({issueData:e,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,t,t===ut?void 0:ut].filter(s=>!!s)});n.common.issues.push(r)}class z{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 T;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 z.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 T;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 T=Object.freeze({status:"aborted"}),rt=n=>({status:"dirty",value:n}),J=n=>({status:"valid",value:n}),Gn=n=>n.status==="aborted",zn=n=>n.status==="dirty",St=n=>n.status==="valid",Ct=n=>typeof Promise<"u"&&n instanceof Promise;function On(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 Mr(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 k;(function(n){n.errToObj=e=>typeof e=="string"?{message:e}:e||{},n.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(k||(k={}));var wt,xt;class ve{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 hr=(n,e)=>{if(St(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 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 z,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(Ct(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 hr(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(Ct(s)?s:Promise.resolve(s));return hr(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 fe({schema:this,typeName:x.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return _e.create(this,this._def)}nullable(){return $e.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return pe.create(this,this._def)}promise(){return pt.create(this,this._def)}or(e){return At.create([this,e],this._def)}and(e){return $t.create(this,e,this._def)}transform(e){return new fe({...E(this._def),schema:this,typeName:x.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new Ut({...E(this._def),innerType:this,defaultValue:t,typeName:x.ZodDefault})}brand(){return new rr({typeName:x.ZodBranded,type:this,...E(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new qt({...E(this._def),innerType:this,catchValue:t,typeName:x.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return ln.create(this,e)}readonly(){return Bt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const ka=/^c[^\s-]{8,}$/i,wa=/^[0-9a-z]+$/,xa=/^[0-9A-HJKMNP-TV-Z]{26}$/,Oa=/^[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,Ta=/^[a-z0-9_-]{21}$/i,ja=/^[-+]?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)?)??$/,Za=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Ra="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Bn;const Ea=/^(?:(?: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])$/,Sa=/^(([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})))$/,Ca=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Dr="((\\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])))",Ia=new RegExp(`^${Dr}$`);function Lr(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 Pa(n){return new RegExp(`^${Lr(n)}$`)}function Vr(n){let e=`${Dr}T${Lr(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 Na(n,e){return!!((e==="v4"||!e)&&Ea.test(n)||(e==="v6"||!e)&&Sa.test(n))}class ue extends I{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==v.string){const a=this._getOrReturnCtx(e);return _(a,{code:h.invalid_type,expected:v.string,received:a.parsedType}),T}const r=new z;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),_(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),_(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?_(s,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&_(s,{code:h.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),r.dirty())}else if(a.kind==="email")Za.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"email",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="emoji")Bn||(Bn=new RegExp(Ra,"u")),Bn.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"emoji",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="uuid")Oa.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"uuid",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="nanoid")Ta.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"nanoid",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid")ka.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"cuid",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid2")wa.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"cuid2",code:h.invalid_string,message:a.message}),r.dirty());else if(a.kind==="ulid")xa.test(e.data)||(s=this._getOrReturnCtx(e,s),_(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),_(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),_(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),_(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),_(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),_(s,{code:h.invalid_string,validation:{endsWith:a.value},message:a.message}),r.dirty()):a.kind==="datetime"?Vr(a).test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{code:h.invalid_string,validation:"datetime",message:a.message}),r.dirty()):a.kind==="date"?Ia.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{code:h.invalid_string,validation:"date",message:a.message}),r.dirty()):a.kind==="time"?Pa(a).test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{code:h.invalid_string,validation:"time",message:a.message}),r.dirty()):a.kind==="duration"?ja.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"duration",code:h.invalid_string,message:a.message}),r.dirty()):a.kind==="ip"?Na(e.data,a.version)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"ip",code:h.invalid_string,message:a.message}),r.dirty()):a.kind==="base64"?Ca.test(e.data)||(s=this._getOrReturnCtx(e,s),_(s,{validation:"base64",code:h.invalid_string,message:a.message}),r.dirty()):$.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,...k.errToObj(r)})}_addCheck(e){return new ue({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...k.errToObj(e)})}url(e){return this._addCheck({kind:"url",...k.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...k.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...k.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...k.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...k.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...k.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...k.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...k.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...k.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,...k.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,...k.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...k.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...k.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...k.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...k.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...k.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...k.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...k.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...k.errToObj(t)})}nonempty(e){return this.min(1,k.errToObj(e))}trim(){return new ue({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new ue({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new ue({...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}}ue.create=n=>{var e;return new ue({checks:[],typeName:x.ZodString,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...E(n)})};function Aa(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 Pe 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 _(a,{code:h.invalid_type,expected:v.number,received:a.parsedType}),T}let r;const s=new z;for(const a of this._def.checks)a.kind==="int"?$.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),_(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),_(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),_(r,{code:h.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?Aa(e.data,a.value)!==0&&(r=this._getOrReturnCtx(e,r),_(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),_(r,{code:h.not_finite,message:a.message}),s.dirty()):$.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,k.toString(t))}gt(e,t){return this.setLimit("min",e,!1,k.toString(t))}lte(e,t){return this.setLimit("max",e,!0,k.toString(t))}lt(e,t){return this.setLimit("max",e,!1,k.toString(t))}setLimit(e,t,r,s){return new Pe({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:k.toString(s)}]})}_addCheck(e){return new Pe({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:k.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:k.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:k.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:k.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:k.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:k.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:k.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:k.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:k.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)}}Pe.create=n=>new Pe({checks:[],typeName:x.ZodNumber,coerce:(n==null?void 0:n.coerce)||!1,...E(n)});class Ne 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 _(a,{code:h.invalid_type,expected:v.bigint,received:a.parsedType}),T}let r;const s=new z;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),_(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),_(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),_(r,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):$.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,k.toString(t))}gt(e,t){return this.setLimit("min",e,!1,k.toString(t))}lte(e,t){return this.setLimit("max",e,!0,k.toString(t))}lt(e,t){return this.setLimit("max",e,!1,k.toString(t))}setLimit(e,t,r,s){return new Ne({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:k.toString(s)}]})}_addCheck(e){return new Ne({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:k.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:k.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:k.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:k.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:k.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}}Ne.create=n=>{var e;return new Ne({checks:[],typeName:x.ZodBigInt,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...E(n)})};class It extends I{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==v.boolean){const r=this._getOrReturnCtx(e);return _(r,{code:h.invalid_type,expected:v.boolean,received:r.parsedType}),T}return J(e.data)}}It.create=n=>new It({typeName:x.ZodBoolean,coerce:(n==null?void 0:n.coerce)||!1,...E(n)});class Ge 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 _(a,{code:h.invalid_type,expected:v.date,received:a.parsedType}),T}if(isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return _(a,{code:h.invalid_date}),T}const r=new z;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),_(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),_(s,{code:h.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):$.assertNever(a);return{status:r.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:k.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:k.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:x.ZodDate,...E(n)});class Tn extends I{_parse(e){if(this._getType(e)!==v.symbol){const r=this._getOrReturnCtx(e);return _(r,{code:h.invalid_type,expected:v.symbol,received:r.parsedType}),T}return J(e.data)}}Tn.create=n=>new Tn({typeName:x.ZodSymbol,...E(n)});class Pt extends I{_parse(e){if(this._getType(e)!==v.undefined){const r=this._getOrReturnCtx(e);return _(r,{code:h.invalid_type,expected:v.undefined,received:r.parsedType}),T}return J(e.data)}}Pt.create=n=>new Pt({typeName:x.ZodUndefined,...E(n)});class Nt extends I{_parse(e){if(this._getType(e)!==v.null){const r=this._getOrReturnCtx(e);return _(r,{code:h.invalid_type,expected:v.null,received:r.parsedType}),T}return J(e.data)}}Nt.create=n=>new Nt({typeName:x.ZodNull,...E(n)});class lt extends I{constructor(){super(...arguments),this._any=!0}_parse(e){return J(e.data)}}lt.create=n=>new lt({typeName:x.ZodAny,...E(n)});class Fe extends I{constructor(){super(...arguments),this._unknown=!0}_parse(e){return J(e.data)}}Fe.create=n=>new Fe({typeName:x.ZodUnknown,...E(n)});class je extends I{_parse(e){const t=this._getOrReturnCtx(e);return _(t,{code:h.invalid_type,expected:v.never,received:t.parsedType}),T}}je.create=n=>new je({typeName:x.ZodNever,...E(n)});class jn extends I{_parse(e){if(this._getType(e)!==v.undefined){const r=this._getOrReturnCtx(e);return _(r,{code:h.invalid_type,expected:v.void,received:r.parsedType}),T}return J(e.data)}}jn.create=n=>new jn({typeName:x.ZodVoid,...E(n)});class pe extends I{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),s=this._def;if(t.parsedType!==v.array)return _(t,{code:h.invalid_type,expected:v.array,received:t.parsedType}),T;if(s.exactLength!==null){const i=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(i||o)&&(_(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&&(_(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&&(_(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 ve(t,i,t.path,o)))).then(i=>z.mergeArray(r,i));const a=[...t.data].map((i,o)=>s.type._parseSync(new ve(t,i,t.path,o)));return z.mergeArray(r,a)}get element(){return this._def.type}min(e,t){return new pe({...this._def,minLength:{value:e,message:k.toString(t)}})}max(e,t){return new pe({...this._def,maxLength:{value:e,message:k.toString(t)}})}length(e,t){return new pe({...this._def,exactLength:{value:e,message:k.toString(t)}})}nonempty(e){return this.min(1,e)}}pe.create=(n,e)=>new pe({type:n,minLength:null,maxLength:null,exactLength:null,typeName:x.ZodArray,...E(e)});function tt(n){if(n instanceof q){const e={};for(const t in n.shape){const r=n.shape[t];e[t]=_e.create(tt(r))}return new q({...n._def,shape:()=>e})}else return n instanceof pe?new pe({...n._def,type:tt(n.element)}):n instanceof _e?_e.create(tt(n.unwrap())):n instanceof $e?$e.create(tt(n.unwrap())):n instanceof be?be.create(n.items.map(e=>tt(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=$.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==v.object){const u=this._getOrReturnCtx(e);return _(u,{code:h.invalid_type,expected:v.object,received:u.parsedType}),T}const{status:r,ctx:s}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof je&&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 ve(s,p,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof je){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&&(_(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 ve(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,R=await l.value;u.push({key:p,value:R,alwaysSet:l.alwaysSet})}return u}).then(u=>z.mergeObjectSync(r,u)):z.mergeObjectSync(r,d)}get shape(){return this._def.shape()}strict(e){return k.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=k.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:x.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new q({...this._def,catchall:e})}pick(e){const t={};return $.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 $.objectKeys(this.shape).forEach(r=>{e[r]||(t[r]=this.shape[r])}),new q({...this._def,shape:()=>t})}deepPartial(){return tt(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 q({...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 a=this.shape[r];for(;a instanceof _e;)a=a._def.innerType;t[r]=a}}),new q({...this._def,shape:()=>t})}keyof(){return Ur($.objectKeys(this.shape))}}q.create=(n,e)=>new q({shape:()=>n,unknownKeys:"strip",catchall:je.create(),typeName:x.ZodObject,...E(e)});q.strictCreate=(n,e)=>new q({shape:()=>n,unknownKeys:"strict",catchall:je.create(),typeName:x.ZodObject,...E(e)});q.lazycreate=(n,e)=>new q({shape:n,unknownKeys:"strip",catchall:je.create(),typeName:x.ZodObject,...E(e)});class At 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 re(o.ctx.common.issues));return _(t,{code:h.invalid_union,unionErrors:i}),T}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:h.invalid_union,unionErrors:o}),T}}get options(){return this._def.options}}At.create=(n,e)=>new At({options:n,typeName:x.ZodUnion,...E(e)});const xe=n=>n instanceof Dt?xe(n.schema):n instanceof fe?xe(n.innerType()):n instanceof Lt?[n.value]:n instanceof Ae?n.options:n instanceof Vt?$.objectValues(n.enum):n instanceof Ut?xe(n._def.innerType):n instanceof Pt?[void 0]:n instanceof Nt?[null]:n instanceof _e?[void 0,...xe(n.unwrap())]:n instanceof $e?[null,...xe(n.unwrap())]:n instanceof rr||n instanceof Bt?xe(n.unwrap()):n instanceof qt?xe(n._def.innerType):[];class Dn extends I{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==v.object)return _(t,{code:h.invalid_type,expected:v.object,received:t.parsedType}),T;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:h.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),T)}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=xe(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:x.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...E(r)})}}function Yn(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=$.objectKeys(e),a=$.objectKeys(n).filter(o=>s.indexOf(o)!==-1),i={...n,...e};for(const o of a){const d=Yn(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=Yn(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 $t extends I{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(a,i)=>{if(Gn(a)||Gn(i))return T;const o=Yn(a.value,i.value);return o.valid?((zn(a)||zn(i))&&t.dirty(),{status:t.value,value:o.data}):(_(r,{code:h.invalid_intersection_types}),T)};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}))}}$t.create=(n,e,t)=>new $t({left:n,right:e,typeName:x.ZodIntersection,...E(t)});class be extends I{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==v.array)return _(r,{code:h.invalid_type,expected:v.array,received:r.parsedType}),T;if(r.data.length<this._def.items.length)return _(r,{code:h.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),T;!this._def.rest&&r.data.length>this._def.items.length&&(_(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 ve(r,i,r.path,o)):null}).filter(i=>!!i);return r.common.async?Promise.all(a).then(i=>z.mergeArray(t,i)):z.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new be({...this._def,rest:e})}}be.create=(n,e)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new be({items:n,typeName:x.ZodTuple,rest:null,...E(e)})};class Mt 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 _(r,{code:h.invalid_type,expected:v.object,received:r.parsedType}),T;const s=[],a=this._def.keyType,i=this._def.valueType;for(const o in r.data)s.push({key:a._parse(new ve(r,o,r.path,o)),value:i._parse(new ve(r,r.data[o],r.path,o)),alwaysSet:o in r.data});return r.common.async?z.mergeObjectAsync(t,s):z.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof I?new Mt({keyType:e,valueType:t,typeName:x.ZodRecord,...E(r)}):new Mt({keyType:ue.create(),valueType:e,typeName:x.ZodRecord,...E(t)})}}class Zn 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 _(r,{code:h.invalid_type,expected:v.map,received:r.parsedType}),T;const s=this._def.keyType,a=this._def.valueType,i=[...r.data.entries()].map(([o,d],u)=>({key:s._parse(new ve(r,o,r.path,[u,"key"])),value:a._parse(new ve(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 T;(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 T;(u.status==="dirty"||l.status==="dirty")&&t.dirty(),o.set(u.value,l.value)}return{status:t.value,value:o}}}}Zn.create=(n,e,t)=>new Zn({valueType:e,keyType:n,typeName:x.ZodMap,...E(t)});class ze extends I{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==v.set)return _(r,{code:h.invalid_type,expected:v.set,received:r.parsedType}),T;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(_(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&&(_(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 T;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 ve(r,d,r.path,u)));return r.common.async?Promise.all(o).then(d=>i(d)):i(o)}min(e,t){return new ze({...this._def,minSize:{value:e,message:k.toString(t)}})}max(e,t){return new ze({...this._def,maxSize:{value:e,message:k.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}ze.create=(n,e)=>new ze({valueType:n,minSize:null,maxSize:null,typeName:x.ZodSet,...E(e)});class at extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==v.function)return _(t,{code:h.invalid_type,expected:v.function,received:t.parsedType}),T;function r(o,d){return xn({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,wn(),ut].filter(u=>!!u),issueData:{code:h.invalid_arguments,argumentsError:d}})}function s(o,d){return xn({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,wn(),ut].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 pt){const o=this;return J(async function(...d){const u=new re([]),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 J(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 at({...this._def,args:be.create(e).rest(Fe.create())})}returns(e){return new at({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new at({args:e||be.create([]).rest(Fe.create()),returns:t||Fe.create(),typeName:x.ZodFunction,...E(r)})}}class Dt 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})}}Dt.create=(n,e)=>new Dt({getter:n,typeName:x.ZodLazy,...E(e)});class Lt extends I{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return _(t,{received:t.data,code:h.invalid_literal,expected:this._def.value}),T}return{status:"valid",value:e.data}}get value(){return this._def.value}}Lt.create=(n,e)=>new Lt({value:n,typeName:x.ZodLiteral,...E(e)});function Ur(n,e){return new Ae({values:n,typeName:x.ZodEnum,...E(e)})}class Ae extends I{constructor(){super(...arguments),wt.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:h.invalid_type}),T}if(On(this,wt)||Mr(this,wt,new Set(this._def.values)),!On(this,wt).has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return _(t,{received:t.data,code:h.invalid_enum_value,options:r}),T}return J(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 Ae.create(e,{...this._def,...t})}exclude(e,t=this._def){return Ae.create(this.options.filter(r=>!e.includes(r)),{...this._def,...t})}}wt=new WeakMap;Ae.create=Ur;class Vt extends I{constructor(){super(...arguments),xt.set(this,void 0)}_parse(e){const t=$.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==v.string&&r.parsedType!==v.number){const s=$.objectValues(t);return _(r,{expected:$.joinValues(s),received:r.parsedType,code:h.invalid_type}),T}if(On(this,xt)||Mr(this,xt,new Set($.getValidEnumValues(this._def.values))),!On(this,xt).has(e.data)){const s=$.objectValues(t);return _(r,{received:r.data,code:h.invalid_enum_value,options:s}),T}return J(e.data)}get enum(){return this._def.values}}xt=new WeakMap;Vt.create=(n,e)=>new Vt({values:n,typeName:x.ZodNativeEnum,...E(e)});class pt 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 _(t,{code:h.invalid_type,expected:v.promise,received:t.parsedType}),T;const r=t.parsedType===v.promise?t.data:Promise.resolve(t.data);return J(r.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}pt.create=(n,e)=>new pt({type:n,typeName:x.ZodPromise,...E(e)});class fe extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===x.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 T;const d=await this._def.schema._parseAsync({data:o,path:r.path,parent:r});return d.status==="aborted"?T:d.status==="dirty"||t.value==="dirty"?rt(d.value):d});{if(t.value==="aborted")return T;const o=this._def.schema._parseSync({data:i,path:r.path,parent:r});return o.status==="aborted"?T:o.status==="dirty"||t.value==="dirty"?rt(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"?T:(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"?T:(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(!St(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=>St(i)?Promise.resolve(s.transform(i.value,a)).then(o=>({status:t.value,value:o})):i);$.assertNever(s)}}fe.create=(n,e,t)=>new fe({schema:n,typeName:x.ZodEffects,effect:e,...E(t)});fe.createWithPreprocess=(n,e,t)=>new fe({schema:e,effect:{type:"preprocess",transform:n},typeName:x.ZodEffects,...E(t)});class _e extends I{_parse(e){return this._getType(e)===v.undefined?J(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}_e.create=(n,e)=>new _e({innerType:n,typeName:x.ZodOptional,...E(e)});class $e extends I{_parse(e){return this._getType(e)===v.null?J(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}$e.create=(n,e)=>new $e({innerType:n,typeName:x.ZodNullable,...E(e)});class Ut 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}}Ut.create=(n,e)=>new Ut({innerType:n,typeName:x.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...E(e)});class qt 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 Ct(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}}qt.create=(n,e)=>new qt({innerType:n,typeName:x.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...E(e)});class Rn extends I{_parse(e){if(this._getType(e)!==v.nan){const r=this._getOrReturnCtx(e);return _(r,{code:h.invalid_type,expected:v.nan,received:r.parsedType}),T}return{status:"valid",value:e.data}}}Rn.create=n=>new Rn({typeName:x.ZodNaN,...E(n)});const $a=Symbol("zod_brand");class rr 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 ln 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"?T:a.status==="dirty"?(t.dirty(),rt(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"?T: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 ln({in:e,out:t,typeName:x.ZodPipeline})}}class Bt extends I{_parse(e){const t=this._def.innerType._parse(e),r=s=>(St(s)&&(s.value=Object.freeze(s.value)),s);return Ct(t)?t.then(s=>r(s)):r(t)}unwrap(){return this._def.innerType}}Bt.create=(n,e)=>new Bt({innerType:n,typeName:x.ZodReadonly,...E(e)});function qr(n,e={},t){return n?lt.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})}}):lt.create()}const Ma={object:q.lazycreate};var x;(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"})(x||(x={}));const Da=(n,e={message:`Input not instance of ${n.name}`})=>qr(t=>t instanceof n,e),Br=ue.create,Wr=Pe.create,La=Rn.create,Va=Ne.create,Hr=It.create,Ua=Ge.create,qa=Tn.create,Ba=Pt.create,Wa=Nt.create,Ha=lt.create,Fa=Fe.create,Ka=je.create,Ga=jn.create,za=pe.create,Ya=q.create,Ja=q.strictCreate,Qa=At.create,Xa=Dn.create,ei=$t.create,ti=be.create,ni=Mt.create,ri=Zn.create,si=ze.create,ai=at.create,ii=Dt.create,oi=Lt.create,ci=Ae.create,di=Vt.create,ui=pt.create,fr=fe.create,li=_e.create,pi=$e.create,hi=fe.createWithPreprocess,fi=ln.create,mi=()=>Br().optional(),gi=()=>Wr().optional(),_i=()=>Hr().optional(),yi={string:n=>ue.create({...n,coerce:!0}),number:n=>Pe.create({...n,coerce:!0}),boolean:n=>It.create({...n,coerce:!0}),bigint:n=>Ne.create({...n,coerce:!0}),date:n=>Ge.create({...n,coerce:!0})},vi=T;var G=Object.freeze({__proto__:null,defaultErrorMap:ut,setErrorMap:va,getErrorMap:wn,makeIssue:xn,EMPTY_PATH:ba,addIssueToContext:_,ParseStatus:z,INVALID:T,DIRTY:rt,OK:J,isAborted:Gn,isDirty:zn,isValid:St,isAsync:Ct,get util(){return $},get objectUtil(){return Kn},ZodParsedType:v,getParsedType:Se,ZodType:I,datetimeRegex:Vr,ZodString:ue,ZodNumber:Pe,ZodBigInt:Ne,ZodBoolean:It,ZodDate:Ge,ZodSymbol:Tn,ZodUndefined:Pt,ZodNull:Nt,ZodAny:lt,ZodUnknown:Fe,ZodNever:je,ZodVoid:jn,ZodArray:pe,ZodObject:q,ZodUnion:At,ZodDiscriminatedUnion:Dn,ZodIntersection:$t,ZodTuple:be,ZodRecord:Mt,ZodMap:Zn,ZodSet:ze,ZodFunction:at,ZodLazy:Dt,ZodLiteral:Lt,ZodEnum:Ae,ZodNativeEnum:Vt,ZodPromise:pt,ZodEffects:fe,ZodTransformer:fe,ZodOptional:_e,ZodNullable:$e,ZodDefault:Ut,ZodCatch:qt,ZodNaN:Rn,BRAND:$a,ZodBranded:rr,ZodPipeline:ln,ZodReadonly:Bt,custom:qr,Schema:I,ZodSchema:I,late:Ma,get ZodFirstPartyTypeKind(){return x},coerce:yi,any:Ha,array:za,bigint:Va,boolean:Hr,date:Ua,discriminatedUnion:Xa,effect:fr,enum:ci,function:ai,instanceof:Da,intersection:ei,lazy:ii,literal:oi,map:ri,nan:La,nativeEnum:di,never:Ka,null:Wa,nullable:pi,number:Wr,object:Ya,oboolean:_i,onumber:gi,optional:li,ostring:mi,pipeline:fi,preprocess:hi,promise:ui,record:ni,set:si,strictObject:Ja,string:Br,symbol:qa,transformer:fr,tuple:ti,undefined:Ba,union:Qa,unknown:Fa,void:Ga,NEVER:vi,ZodIssueCode:h,quotelessJson:ya,ZodError:re}),Wt=class Jn extends _a{constructor(t){super(t);g(this,"openAPIRegistry");g(this,"defaultHook");g(this,"openapi",({middleware:t,...r},s,a=this.defaultHook)=>{var u,l,p,R,D,N;this.openAPIRegistry.registerPath(r);const i=[];if((u=r.request)!=null&&u.query){const j=Qe("query",r.request.query,a);i.push(j)}if((l=r.request)!=null&&l.params){const j=Qe("param",r.request.params,a);i.push(j)}if((p=r.request)!=null&&p.headers){const j=Qe("header",r.request.headers,a);i.push(j)}if((R=r.request)!=null&&R.cookies){const j=Qe("cookie",r.request.cookies,a);i.push(j)}const o=(N=(D=r.request)==null?void 0:D.body)==null?void 0:N.content;if(o)for(const j of Object.keys(o)){if(!o[j])continue;const V=o[j].schema;if(V instanceof I){if(j.startsWith("application/json")){const H=Qe("json",V,a);i.push(H)}if(j.startsWith("multipart/form-data")||j.startsWith("application/x-www-form-urlencoded")){const H=Qe("form",V,a);i.push(H)}}}const d=t?Array.isArray(t)?t:[t]:[];return this.on([r.method],r.path.replaceAll(/\/{(.+?)}/g,"/:$1"),...d,...i,s),this});g(this,"getOpenAPIDocument",t=>new Ns(this.openAPIRegistry.definitions).generateDocument(t));g(this,"getOpenAPI31Document",t=>new Ms(this.openAPIRegistry.definitions).generateDocument(t));g(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)}}));g(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 gs,this.defaultHook=t==null?void 0:t.defaultHook}route(t,r){const s=t.replaceAll(/:([^\/]+)/g,"{$1}");return super.route(t,r),r instanceof Jn?(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 Jn({...super.basePath(t),defaultHook:this.defaultHook})}},We=n=>{const e={...n,getRoutingPath(){return n.path.replaceAll(/\/{(.+?)}/g,"/:$1")}};return Object.defineProperty(e,"getRoutingPath",{enumerable:!1})};ps(G);function bi(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 ki(n,e){var t;return((t=n==null?void 0:n._def)===null||t===void 0?void 0:t.typeName)===e}function vt(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 wi(n){if(typeof n.ZodType.prototype.openapi<"u")return;n.ZodType.prototype.openapi=function(s,a){var i,o,d,u,l,p;const R=typeof s=="string"?a:s,D=R??{},{param:N}=D,j=bi(D,["param"]),V=Object.assign(Object.assign({},(i=this._def.openapi)===null||i===void 0?void 0:i._internal),typeof s=="string"?{refId:s}:void 0),H=Object.assign(Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o.metadata),j),!((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),ee=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(V).length>0?{_internal:V}:void 0),Object.keys(H).length>0?{metadata:H}:void 0)}));if(ki(this,"ZodObject")){const te=this.extend;ee.extend=function(...Re){var ae,ne,X,ge,ie,Ue;const qe=te.apply(this,Re);return qe._def.openapi={_internal:{extendedFrom:!((ne=(ae=this._def.openapi)===null||ae===void 0?void 0:ae._internal)===null||ne===void 0)&&ne.refId?{refId:(ge=(X=this._def.openapi)===null||X===void 0?void 0:X._internal)===null||ge===void 0?void 0:ge.refId,schema:this}:(ie=this._def.openapi)===null||ie===void 0?void 0:ie._internal.extendedFrom},metadata:(Ue=qe._def.openapi)===null||Ue===void 0?void 0:Ue.metadata},qe}}return ee},vt(n,"optional"),vt(n,"nullable"),vt(n,"default"),vt(n,"transform"),vt(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 M;(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})(M||(M={}));var Qn;(function(n){n.mergeShapes=(e,t)=>({...e,...t})})(Qn||(Qn={}));const b=M.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ce=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=M.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"]),xi=n=>JSON.stringify(n,null,2).replace(/"([^"]+)":/g,"$1:");class se 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 se))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,M.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()}}se.create=n=>new se(n);const ht=(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,M.jsonStringifyReplacer)}`;break;case f.unrecognized_keys:t=`Unrecognized key(s) in object: ${M.joinValues(n.keys,", ")}`;break;case f.invalid_union:t="Invalid input";break;case f.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${M.joinValues(n.options)}`;break;case f.invalid_enum_value:t=`Invalid enum value. Expected ${M.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}"`:M.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,M.assertNever(n)}return{message:t}};let Fr=ht;function Oi(n){Fr=n}function En(){return Fr}const Sn=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}},Ti=[];function y(n,e){const t=En(),r=Sn({issueData:e,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,t,t===ht?void 0:ht].filter(s=>!!s)});n.common.issues.push(r)}class Y{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 Y.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"}),Cn=n=>({status:"dirty",value:n}),Q=n=>({status:"valid",value:n}),Xn=n=>n.status==="aborted",er=n=>n.status==="dirty",Ht=n=>n.status==="valid",Ft=n=>typeof Promise<"u"&&n instanceof Promise;function In(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 Kr(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 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 Ot,Tt;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 mr=(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 se(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 Ce(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Ce(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new Y,ctx:{common:e.parent.common,data:e.data,parsedType:Ce(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:Ce(e)},a=this._parseSync({data:e,path:s.path,parent:s});return mr(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:Ce(e)},s=this._parse({data:e,path:r.path,parent:r}),a=await(Ft(s)?s:Promise.resolve(s));return mr(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 me({schema:this,typeName:O.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return ye.create(this,this._def)}nullable(){return Ve.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return he.create(this,this._def)}promise(){return mt.create(this,this._def)}or(e){return Yt.create([this,e],this._def)}and(e){return Jt.create(this,e,this._def)}transform(e){return new me({...S(this._def),schema:this,typeName:O.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new nn({...S(this._def),innerType:this,defaultValue:t,typeName:O.ZodDefault})}brand(){return new sr({typeName:O.ZodBranded,type:this,...S(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new rn({...S(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 pn.create(this,e)}readonly(){return sn.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const ji=/^c[^\s-]{8,}$/i,Zi=/^[0-9a-z]+$/,Ri=/^[0-9A-HJKMNP-TV-Z]{26}$/,Ei=/^[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,Si=/^[a-z0-9_-]{21}$/i,Ci=/^[-+]?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)?)??$/,Ii=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Pi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Wn;const Ni=/^(?:(?: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])$/,Ai=/^(([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})))$/,$i=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Gr="((\\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])))",Mi=new RegExp(`^${Gr}$`);function zr(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 Di(n){return new RegExp(`^${zr(n)}$`)}function Yr(n){let e=`${Gr}T${zr(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 Li(n,e){return!!((e==="v4"||!e)&&Ni.test(n)||(e==="v6"||!e)&&Ai.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 y(s,{code:f.invalid_type,expected:b.string,received:s.parsedType}),Z}const t=new Y;let r;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(r=this._getOrReturnCtx(e,r),y(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),y(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?y(r,{code:f.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):i&&y(r,{code:f.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),t.dirty())}else if(s.kind==="email")Ii.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"email",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="emoji")Wn||(Wn=new RegExp(Pi,"u")),Wn.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"emoji",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="uuid")Ei.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"uuid",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="nanoid")Si.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"nanoid",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="cuid")ji.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"cuid",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="cuid2")Zi.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"cuid2",code:f.invalid_string,message:s.message}),t.dirty());else if(s.kind==="ulid")Ri.test(e.data)||(r=this._getOrReturnCtx(e,r),y(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),y(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),y(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),y(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),y(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),y(r,{code:f.invalid_string,validation:{endsWith:s.value},message:s.message}),t.dirty()):s.kind==="datetime"?Yr(s).test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{code:f.invalid_string,validation:"datetime",message:s.message}),t.dirty()):s.kind==="date"?Mi.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{code:f.invalid_string,validation:"date",message:s.message}),t.dirty()):s.kind==="time"?Di(s).test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{code:f.invalid_string,validation:"time",message:s.message}),t.dirty()):s.kind==="duration"?Ci.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"duration",code:f.invalid_string,message:s.message}),t.dirty()):s.kind==="ip"?Li(e.data,s.version)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"ip",code:f.invalid_string,message:s.message}),t.dirty()):s.kind==="base64"?$i.test(e.data)||(r=this._getOrReturnCtx(e,r),y(r,{validation:"base64",code:f.invalid_string,message:s.message}),t.dirty()):M.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,...w.errToObj(r)})}_addCheck(e){return new le({...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 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:O.ZodString,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...S(n)})};function Vi(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 Me 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 y(s,{code:f.invalid_type,expected:b.number,received:s.parsedType}),Z}let t;const r=new Y;for(const s of this._def.checks)s.kind==="int"?M.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),y(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),y(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),y(t,{code:f.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),r.dirty()):s.kind==="multipleOf"?Vi(e.data,s.value)!==0&&(t=this._getOrReturnCtx(e,t),y(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),y(t,{code:f.not_finite,message:s.message}),r.dirty()):M.assertNever(s);return{status:r.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 Me({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:w.toString(s)}]})}_addCheck(e){return new Me({...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"&&M.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)}}Me.create=n=>new Me({checks:[],typeName:O.ZodNumber,coerce:(n==null?void 0:n.coerce)||!1,...S(n)});class De 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 y(s,{code:f.invalid_type,expected:b.bigint,received:s.parsedType}),Z}let t;const r=new Y;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),y(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),y(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),y(t,{code:f.not_multiple_of,multipleOf:s.value,message:s.message}),r.dirty()):M.assertNever(s);return{status:r.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 De({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:w.toString(s)}]})}_addCheck(e){return new De({...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}}De.create=n=>{var e;return new De({checks:[],typeName:O.ZodBigInt,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...S(n)})};class Kt extends P{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==b.boolean){const t=this._getOrReturnCtx(e);return y(t,{code:f.invalid_type,expected:b.boolean,received:t.parsedType}),Z}return Q(e.data)}}Kt.create=n=>new Kt({typeName:O.ZodBoolean,coerce:(n==null?void 0:n.coerce)||!1,...S(n)});class Ye 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 y(s,{code:f.invalid_type,expected:b.date,received:s.parsedType}),Z}if(isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return y(s,{code:f.invalid_date}),Z}const t=new Y;let r;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(r=this._getOrReturnCtx(e,r),y(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),y(r,{code:f.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),t.dirty()):M.assertNever(s);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Ye({...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}}Ye.create=n=>new Ye({checks:[],coerce:(n==null?void 0:n.coerce)||!1,typeName:O.ZodDate,...S(n)});class Pn extends P{_parse(e){if(this._getType(e)!==b.symbol){const t=this._getOrReturnCtx(e);return y(t,{code:f.invalid_type,expected:b.symbol,received:t.parsedType}),Z}return Q(e.data)}}Pn.create=n=>new Pn({typeName:O.ZodSymbol,...S(n)});class Gt extends P{_parse(e){if(this._getType(e)!==b.undefined){const t=this._getOrReturnCtx(e);return y(t,{code:f.invalid_type,expected:b.undefined,received:t.parsedType}),Z}return Q(e.data)}}Gt.create=n=>new Gt({typeName:O.ZodUndefined,...S(n)});class zt extends P{_parse(e){if(this._getType(e)!==b.null){const t=this._getOrReturnCtx(e);return y(t,{code:f.invalid_type,expected:b.null,received:t.parsedType}),Z}return Q(e.data)}}zt.create=n=>new zt({typeName:O.ZodNull,...S(n)});class ft extends P{constructor(){super(...arguments),this._any=!0}_parse(e){return Q(e.data)}}ft.create=n=>new ft({typeName:O.ZodAny,...S(n)});class Ke extends P{constructor(){super(...arguments),this._unknown=!0}_parse(e){return Q(e.data)}}Ke.create=n=>new Ke({typeName:O.ZodUnknown,...S(n)});class Ze extends P{_parse(e){const t=this._getOrReturnCtx(e);return y(t,{code:f.invalid_type,expected:b.never,received:t.parsedType}),Z}}Ze.create=n=>new Ze({typeName:O.ZodNever,...S(n)});class Nn extends P{_parse(e){if(this._getType(e)!==b.undefined){const t=this._getOrReturnCtx(e);return y(t,{code:f.invalid_type,expected:b.void,received:t.parsedType}),Z}return Q(e.data)}}Nn.create=n=>new Nn({typeName:O.ZodVoid,...S(n)});class he extends P{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),s=this._def;if(t.parsedType!==b.array)return y(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)&&(y(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&&(y(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&&(y(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=>Y.mergeArray(r,i));const a=[...t.data].map((i,o)=>s.type._parseSync(new ke(t,i,t.path,o)));return Y.mergeArray(r,a)}get element(){return this._def.type}min(e,t){return new he({...this._def,minLength:{value:e,message:w.toString(t)}})}max(e,t){return new he({...this._def,maxLength:{value:e,message:w.toString(t)}})}length(e,t){return new he({...this._def,exactLength:{value:e,message:w.toString(t)}})}nonempty(e){return this.min(1,e)}}he.create=(n,e)=>new he({type:n,minLength:null,maxLength:null,exactLength:null,typeName:O.ZodArray,...S(e)});function nt(n){if(n instanceof B){const e={};for(const t in n.shape){const r=n.shape[t];e[t]=ye.create(nt(r))}return new B({...n._def,shape:()=>e})}else return n instanceof he?new he({...n._def,type:nt(n.element)}):n instanceof ye?ye.create(nt(n.unwrap())):n instanceof Ve?Ve.create(nt(n.unwrap())):n instanceof we?we.create(n.items.map(e=>nt(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=M.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==b.object){const d=this._getOrReturnCtx(e);return y(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&&(y(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=>Y.mergeObjectSync(t,d)):Y.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return w.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=w.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:O.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new B({...this._def,catchall:e})}pick(e){const t={};return M.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 M.objectKeys(this.shape).forEach(r=>{e[r]||(t[r]=this.shape[r])}),new B({...this._def,shape:()=>t})}deepPartial(){return nt(this)}partial(e){const t={};return M.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 M.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])t[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof ye;)s=s._def.innerType;t[r]=s}}),new B({...this._def,shape:()=>t})}keyof(){return Jr(M.objectKeys(this.shape))}}B.create=(n,e)=>new B({shape:()=>n,unknownKeys:"strip",catchall:Ze.create(),typeName:O.ZodObject,...S(e)});B.strictCreate=(n,e)=>new B({shape:()=>n,unknownKeys:"strict",catchall:Ze.create(),typeName:O.ZodObject,...S(e)});B.lazycreate=(n,e)=>new B({shape:n,unknownKeys:"strip",catchall:Ze.create(),typeName:O.ZodObject,...S(e)});class Yt 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 se(o.ctx.common.issues));return y(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 se(d));return y(t,{code:f.invalid_union,unionErrors:o}),Z}}get options(){return this._def.options}}Yt.create=(n,e)=>new Yt({options:n,typeName:O.ZodUnion,...S(e)});const Ee=n=>n instanceof Xt?Ee(n.schema):n instanceof me?Ee(n.innerType()):n instanceof en?[n.value]:n instanceof Le?n.options:n instanceof tn?M.objectValues(n.enum):n instanceof nn?Ee(n._def.innerType):n instanceof Gt?[void 0]:n instanceof zt?[null]:n instanceof ye?[void 0,...Ee(n.unwrap())]:n instanceof Ve?[null,...Ee(n.unwrap())]:n instanceof sr||n instanceof sn?Ee(n.unwrap()):n instanceof rn?Ee(n._def.innerType):[];class Ln extends P{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==b.object)return y(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}):(y(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=Ee(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 Ln({typeName:O.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...S(r)})}}function tr(n,e){const t=Ce(n),r=Ce(e);if(n===e)return{valid:!0,data:n};if(t===b.object&&r===b.object){const s=M.objectKeys(e),a=M.objectKeys(n).filter(o=>s.indexOf(o)!==-1),i={...n,...e};for(const o of a){const d=tr(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=tr(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 Jt extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(a,i)=>{if(Xn(a)||Xn(i))return Z;const o=tr(a.value,i.value);return o.valid?((er(a)||er(i))&&t.dirty(),{status:t.value,value:o.data}):(y(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}))}}Jt.create=(n,e,t)=>new Jt({left:n,right:e,typeName:O.ZodIntersection,...S(t)});class we extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==b.array)return y(r,{code:f.invalid_type,expected:b.array,received:r.parsedType}),Z;if(r.data.length<this._def.items.length)return y(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&&(y(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=>Y.mergeArray(t,a)):Y.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:O.ZodTuple,rest:null,...S(e)})};class Qt 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 y(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?Y.mergeObjectAsync(t,s):Y.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof P?new Qt({keyType:e,valueType:t,typeName:O.ZodRecord,...S(r)}):new Qt({keyType:le.create(),valueType:e,typeName:O.ZodRecord,...S(t)})}}class An 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 y(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}}}}An.create=(n,e,t)=>new An({valueType:e,keyType:n,typeName:O.ZodMap,...S(t)});class Je extends P{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==b.set)return y(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&&(y(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&&(y(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 Je({...this._def,minSize:{value:e,message:w.toString(t)}})}max(e,t){return new Je({...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)}}Je.create=(n,e)=>new Je({valueType:n,minSize:null,maxSize:null,typeName:O.ZodSet,...S(e)});class it extends P{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==b.function)return y(t,{code:f.invalid_type,expected:b.function,received:t.parsedType}),Z;function r(o,d){return Sn({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,En(),ht].filter(u=>!!u),issueData:{code:f.invalid_arguments,argumentsError:d}})}function s(o,d){return Sn({data:o,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,En(),ht].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 mt){const o=this;return Q(async function(...d){const u=new se([]),l=await o._def.args.parseAsync(d,a).catch(R=>{throw u.addIssue(r(d,R)),u}),p=await Reflect.apply(i,this,l);return await o._def.returns._def.type.parseAsync(p,a).catch(R=>{throw u.addIssue(s(p,R)),u})})}else{const o=this;return Q(function(...d){const u=o._def.args.safeParse(d,a);if(!u.success)throw new se([r(d,u.error)]);const l=Reflect.apply(i,this,u.data),p=o._def.returns.safeParse(l,a);if(!p.success)throw new se([s(l,p.error)]);return p.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new it({...this._def,args:we.create(e).rest(Ke.create())})}returns(e){return new it({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new it({args:e||we.create([]).rest(Ke.create()),returns:t||Ke.create(),typeName:O.ZodFunction,...S(r)})}}class Xt 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})}}Xt.create=(n,e)=>new Xt({getter:n,typeName:O.ZodLazy,...S(e)});class en extends P{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return y(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}}en.create=(n,e)=>new en({value:n,typeName:O.ZodLiteral,...S(e)});function Jr(n,e){return new Le({values:n,typeName:O.ZodEnum,...S(e)})}class Le extends P{constructor(){super(...arguments),Ot.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return y(t,{expected:M.joinValues(r),received:t.parsedType,code:f.invalid_type}),Z}if(In(this,Ot)||Kr(this,Ot,new Set(this._def.values)),!In(this,Ot).has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return y(t,{received:t.data,code:f.invalid_enum_value,options:r}),Z}return Q(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})}}Ot=new WeakMap;Le.create=Jr;class tn extends P{constructor(){super(...arguments),Tt.set(this,void 0)}_parse(e){const t=M.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==b.string&&r.parsedType!==b.number){const s=M.objectValues(t);return y(r,{expected:M.joinValues(s),received:r.parsedType,code:f.invalid_type}),Z}if(In(this,Tt)||Kr(this,Tt,new Set(M.getValidEnumValues(this._def.values))),!In(this,Tt).has(e.data)){const s=M.objectValues(t);return y(r,{received:r.data,code:f.invalid_enum_value,options:s}),Z}return Q(e.data)}get enum(){return this._def.values}}Tt=new WeakMap;tn.create=(n,e)=>new tn({values:n,typeName:O.ZodNativeEnum,...S(e)});class mt 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 y(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 Q(r.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}mt.create=(n,e)=>new mt({type:n,typeName:O.ZodPromise,...S(e)});class me extends P{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=>{y(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"?Cn(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"?Cn(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);M.assertNever(s)}}me.create=(n,e,t)=>new me({schema:n,typeName:O.ZodEffects,effect:e,...S(t)});me.createWithPreprocess=(n,e,t)=>new me({schema:e,effect:{type:"preprocess",transform:n},typeName:O.ZodEffects,...S(t)});class ye extends P{_parse(e){return this._getType(e)===b.undefined?Q(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ye.create=(n,e)=>new ye({innerType:n,typeName:O.ZodOptional,...S(e)});class Ve extends P{_parse(e){return this._getType(e)===b.null?Q(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ve.create=(n,e)=>new Ve({innerType:n,typeName:O.ZodNullable,...S(e)});class nn 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}}nn.create=(n,e)=>new nn({innerType:n,typeName:O.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...S(e)});class rn 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 se(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new se(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}rn.create=(n,e)=>new rn({innerType:n,typeName:O.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...S(e)});class $n extends P{_parse(e){if(this._getType(e)!==b.nan){const t=this._getOrReturnCtx(e);return y(t,{code:f.invalid_type,expected:b.nan,received:t.parsedType}),Z}return{status:"valid",value:e.data}}}$n.create=n=>new $n({typeName:O.ZodNaN,...S(n)});const Ui=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 pn 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(),Cn(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 pn({in:e,out:t,typeName:O.ZodPipeline})}}class sn 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}}sn.create=(n,e)=>new sn({innerType:n,typeName:O.ZodReadonly,...S(e)});function Qr(n,e={},t){return n?ft.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})}}):ft.create()}const qi={object:B.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 Bi=(n,e={message:`Input not instance of ${n.name}`})=>Qr(t=>t instanceof n,e),Xr=le.create,es=Me.create,Wi=$n.create,Hi=De.create,ts=Kt.create,Fi=Ye.create,Ki=Pn.create,Gi=Gt.create,zi=zt.create,Yi=ft.create,Ji=Ke.create,Qi=Ze.create,Xi=Nn.create,eo=he.create,to=B.create,no=B.strictCreate,ro=Yt.create,so=Ln.create,ao=Jt.create,io=we.create,oo=Qt.create,co=An.create,uo=Je.create,lo=it.create,po=Xt.create,ho=en.create,fo=Le.create,mo=tn.create,go=mt.create,gr=me.create,_o=ye.create,yo=Ve.create,vo=me.createWithPreprocess,bo=pn.create,ko=()=>Xr().optional(),wo=()=>es().optional(),xo=()=>ts().optional(),Oo={string:n=>le.create({...n,coerce:!0}),number:n=>Me.create({...n,coerce:!0}),boolean:n=>Kt.create({...n,coerce:!0}),bigint:n=>De.create({...n,coerce:!0}),date:n=>Ye.create({...n,coerce:!0})},To=Z;var c=Object.freeze({__proto__:null,defaultErrorMap:ht,setErrorMap:Oi,getErrorMap:En,makeIssue:Sn,EMPTY_PATH:Ti,addIssueToContext:y,ParseStatus:Y,INVALID:Z,DIRTY:Cn,OK:Q,isAborted:Xn,isDirty:er,isValid:Ht,isAsync:Ft,get util(){return M},get objectUtil(){return Qn},ZodParsedType:b,getParsedType:Ce,ZodType:P,datetimeRegex:Yr,ZodString:le,ZodNumber:Me,ZodBigInt:De,ZodBoolean:Kt,ZodDate:Ye,ZodSymbol:Pn,ZodUndefined:Gt,ZodNull:zt,ZodAny:ft,ZodUnknown:Ke,ZodNever:Ze,ZodVoid:Nn,ZodArray:he,ZodObject:B,ZodUnion:Yt,ZodDiscriminatedUnion:Ln,ZodIntersection:Jt,ZodTuple:we,ZodRecord:Qt,ZodMap:An,ZodSet:Je,ZodFunction:it,ZodLazy:Xt,ZodLiteral:en,ZodEnum:Le,ZodNativeEnum:tn,ZodPromise:mt,ZodEffects:me,ZodTransformer:me,ZodOptional:ye,ZodNullable:Ve,ZodDefault:nn,ZodCatch:rn,ZodNaN:$n,BRAND:Ui,ZodBranded:sr,ZodPipeline:pn,ZodReadonly:sn,custom:Qr,Schema:P,ZodSchema:P,late:qi,get ZodFirstPartyTypeKind(){return O},coerce:Oo,any:Yi,array:eo,bigint:Hi,boolean:ts,date:Fi,discriminatedUnion:so,effect:gr,enum:fo,function:lo,instanceof:Bi,intersection:ao,lazy:po,literal:ho,map:co,nan:Wi,nativeEnum:mo,never:Qi,null:zi,nullable:yo,number:es,object:to,oboolean:xo,onumber:wo,optional:_o,ostring:ko,pipeline:bo,preprocess:vo,promise:go,record:oo,set:uo,strictObject:no,string:Xr,symbol:Ki,transformer:gr,tuple:io,undefined:Gi,union:ro,unknown:Ji,void:Xi,NEVER:To,ZodIssueCode:f,quotelessJson:xi,ZodError:se});wi(c);const jo=c.object({start:c.number(),limit:c.number(),length:c.number()}),ar=c.object({created_at:c.string(),updated_at:c.string()}),Zo=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()),Ro=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:Zo.optional()}),ns=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()}),Eo=ns.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")});Eo.extend(ar.shape).extend({user_id:c.string(),email:c.string(),is_social:c.boolean(),login_count:c.number(),identities:c.array(Ro).optional()});ns.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 So=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(So.shape);var rs=(n=>(n.TOKEN="token",n.TOKEN_ID_TOKEN="token id_token",n.CODE="code",n))(rs||{}),ss=(n=>(n.QUERY="query",n.FRAGMENT="fragment",n.FORM_POST="form_post",n.WEB_MESSAGE="web_message",n))(ss||{}),as=(n=>(n.S265="S256",n.plain="plain",n))(as||{});const Vn=c.object({client_id:c.string(),vendor_id:c.string().optional(),response_type:c.nativeEnum(rs).optional(),response_mode:c.nativeEnum(ss).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(as).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 Co=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()}),is=c.object({id:c.string(),created_at:c.string().transform(n=>n===null?"":n),updated_at:c.string().transform(n=>n===null?"":n)}).extend(Co.shape),Io=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()}),os=c.object({id:c.string(),name:c.string(),domains:c.array(Io),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()})});os.extend({connections:c.array(is)});os.extend({connections:c.array(is.partial())});const Po=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:Po,created_at:c.string(),expires_at:c.string(),used_at:c.string().optional()});const No=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({...No.shape,id:c.string()});const Ao=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()});Ao.extend({...ar.shape,hook_id:c.string()});const $o=c.object({alg:c.string(),e:c.string(),kid:c.string(),kty:c.string(),n:c.string(),use:c.string().optional()}),Mo=c.object({keys:c.array($o)}),_r=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())}),Do=c.object({login_id:c.string().openapi({description:"This is is used as the state in the universal login"}),auth0Client:c.string().optional(),authParams:Vn,expires_at:c.string(),deleted_at:c.string(),ip:c.string().optional()}).openapi({description:"This represents a login sesion"});c.object({...Do.shape,created_at:c.string(),updated_at:c.string()});const Lo=c.enum(["sapi","ssa","fsa","ss","ssa","fs","s","f","fp","slo","scoa","fcoa","seccft","cls","seacft","serft"]),Vo=c.object({name:c.string(),version:c.string(),env:c.object({node:c.string().optional()}).optional()});c.object({type:Lo,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:Vo.optional()});const Uo=c.object({user_id:c.string(),password:c.string(),algorithm:c.enum(["bcrypt","argon2id"]).default("argon2id")});c.object({...Uo.shape,created_at:c.string(),updated_at:c.string()});const qo=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(),...qo.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 nr=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()}),_n=nr.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 cs=(n=>(n.RefreshToken="refresh_token",n.AuthorizationCode="authorization_code",n.ClientCredential="client_credentials",n.Passwordless="passwordless",n.Password="password",n))(cs||{});const ir=c.nativeEnum(cs);c.object({grant_type:ir.refine(n=>n==="authorization_code"),code:c.string(),client_secret:c.string(),client_id:c.string()});c.object({grant_type:ir.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:ir.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 Bo=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()}),Wo=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()}),et=c.object({bold:c.boolean(),size:c.number()}),Ho=c.object({body_text:et,buttons_text:et,font_url:c.string(),input_labels:et,links:et,links_style:c.enum(["normal"]),reference_text_size:c.number(),subtitle:et,title:et}),Fo=c.object({background_color:c.string(),background_image_url:c.string(),page_layout:c.enum(["center"])}),Ko=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"])}),Go=c.object({borders:Bo,colors:Wo,displayName:c.string(),fonts:Ho,page_background:Fo,widget:Ko});Go.extend({themeId:c.string()});const zo=c.object({id:c.string(),expires_at:c.string(),auth0Client:c.string().optional(),authParams:Vn});c.object({...zo.shape,created_at:c.string(),updated_at:c.string()});const Yo=c.object({id:c.string(),email:c.string(),code:c.string(),ip:c.string().optional(),send:c.enum(["code","link"]),authParams:Vn,expires_at:c.string(),used_at:c.string().optional(),user_id:c.string().optional()});c.object({created_at:c.string(),...Yo.shape});const Jo=c.object({authParams:Vn,code:c.string(),user_id:c.string(),created_at:c.string(),expires_at:c.string(),used_at:c.string().optional()});c.object({...Jo.shape,created_at:c.string()});const Qo=new Wt().openapi(We({tags:["jwks"],method:"get",path:"/jwks.json",request:{},responses:{200:{content:{"application/json":{schema:Mo}},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(We({tags:["well known"],method:"get",path:"/openid-configuration",request:{},responses:{200:{content:{"application/json":{schema:_r}},description:"List of tenants"}}}),async n=>{const{env:e}=n,{ISSUER:t}=e,r=_r.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 Xo({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 ec(n){return async(e,t)=>{if(!t.email||!t.email_verified)return n.users.create(e,t);const r=await Xo({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 tc(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 nc(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 tc(n,s,{tenant_id:t,user:r,trigger_id:"post-user-registration"}),r}}function rc(n,e){return async(t,r)=>{let s=await ec(e)(t,r);return await nc(n,e)(t,s),s}}function sc(n,e){return{...e,users:{...e.users,create:rc(n,e)}}}const ac=G.object({page:G.string().min(0).optional().default("0").transform(n=>parseInt(n,10)).openapi({description:"The page number where 0 is the first page"}),per_page:G.string().min(1).optional().default("10").transform(n=>parseInt(n,10)).openapi({description:"The number of items per page"}),include_totals:G.string().optional().default("false").transform(n=>n==="true").openapi({description:"If the total number of items should be included in the response"}),sort:G.string().regex(/^.+:(-1|1)$/).optional().openapi({description:"A property that should have the format 'string:-1' or 'string:1'"}),q:G.string().optional().openapi({description:"A lucene query string used to filter the results"})});function ic(n){if(!n)return;const[e="",t]=n.split(":");return{sort_by:e,sort_order:t==="1"?"asc":"desc"}}const oc=jo.extend({tenants:G.array(_n)}),cc=new Wt().openapi(We({tags:["tenants"],method:"get",path:"/",request:{query:ac},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:G.union([G.array(_n),oc])}},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:ic(s),q:a});return r?n.json(i):n.json(i.tenants)}).openapi(We({tags:["tenants"],method:"get",path:"/{id}",request:{params:G.object({id:G.string()})},security:[{Bearer:["auth:read"]}],responses:{200:{content:{"tenant/json":{schema:_n}},description:"A tenant"}}}),async n=>{const{id:e}=n.req.valid("param"),t=await n.env.data.tenants.get(e);if(!t)throw new fn(404);return console.log("tenant",t),n.json(t)}).openapi(We({tags:["tenants"],method:"delete",path:"/{id}",request:{params:G.object({id:G.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(We({tags:["tenants"],method:"patch",path:"/{id}",request:{body:{content:{"application/json":{schema:G.object(nr.shape).partial()}}},params:G.object({id:G.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(We({tags:["tenants"],method:"post",path:"/",request:{body:{content:{"application/json":{schema:G.object(nr.shape)}}}},security:[{Bearer:["auth:write"]}],responses:{200:{content:{"tenant/json":{schema:_n}},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 yr=!1;function dc(n){n.use(async(e,t)=>(yr||(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"}}}}),yr=!0),await t()))}function uc(n){const e=new Wt;e.use(async(r,s)=>(r.env.data=sc(r,n.dataAdapter),s()));const t=e.route("/api/v2/tenants",cc);return dc(t),t.doc("/api/v2/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Management api"}}),t}function lc(n){const e=new Wt;e.get("/",s=>s.text("Hello, authhero!"));const t=uc(n);e.route("/api/v2",t);const r=new Wt().route("/.well-known",Qo);return r.doc("/spec",{openapi:"3.0.0",info:{version:"1.0.0",title:"Oauth endpoints"}}),e.route("/",r),e}exports.init=lc;