directus-extension-sql-query-panel 1.2.1 → 1.3.0

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/api.js CHANGED
@@ -1 +1 @@
1
- var e,t;!function(e){e.assertEqual=e=>e,e.assertIs=function(e){},e.assertNever=function(e){throw new Error},e.arrayToEnum=e=>{const t={};for(const a of e)t[a]=a;return t},e.getValidEnumValues=t=>{const a=e.objectKeys(t).filter((e=>"number"!=typeof t[t[e]])),s={};for(const e of a)s[e]=t[e];return e.objectValues(s)},e.objectValues=t=>e.objectKeys(t).map((function(e){return t[e]})),e.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.push(a);return t},e.find=(e,t)=>{for(const a of e)if(t(a))return a},e.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&isFinite(e)&&Math.floor(e)===e,e.joinValues=function(e,t=" | "){return e.map((e=>"string"==typeof e?`'${e}'`:e)).join(t)},e.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t}(e||(e={})),function(e){e.mergeShapes=(e,t)=>({...e,...t})}(t||(t={}));const a=e.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),s=e=>{switch(typeof e){case"undefined":return a.undefined;case"string":return a.string;case"number":return isNaN(e)?a.nan:a.number;case"boolean":return a.boolean;case"function":return a.function;case"bigint":return a.bigint;case"symbol":return a.symbol;case"object":return Array.isArray(e)?a.array:null===e?a.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?a.promise:"undefined"!=typeof Map&&e instanceof Map?a.map:"undefined"!=typeof Set&&e instanceof Set?a.set:"undefined"!=typeof Date&&e instanceof Date?a.date:a.object;default:return a.unknown}},n=e.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class r extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},a={_errors:[]},s=e=>{for(const n of e.issues)if("invalid_union"===n.code)n.unionErrors.map(s);else if("invalid_return_type"===n.code)s(n.returnTypeError);else if("invalid_arguments"===n.code)s(n.argumentsError);else if(0===n.path.length)a._errors.push(t(n));else{let e=a,s=0;for(;s<n.path.length;){const a=n.path[s];s===n.path.length-1?(e[a]=e[a]||{_errors:[]},e[a]._errors.push(t(n))):e[a]=e[a]||{_errors:[]},e=e[a],s++}}};return s(this),a}static assert(e){if(!(e instanceof r))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,e.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},a=[];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))):a.push(e(s));return{formErrors:a,fieldErrors:t}}get formErrors(){return this.flatten()}}r.create=e=>new r(e);const i=(t,s)=>{let r;switch(t.code){case n.invalid_type:r=t.received===a.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case n.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,e.jsonStringifyReplacer)}`;break;case n.unrecognized_keys:r=`Unrecognized key(s) in object: ${e.joinValues(t.keys,", ")}`;break;case n.invalid_union:r="Invalid input";break;case n.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${e.joinValues(t.options)}`;break;case n.invalid_enum_value:r=`Invalid enum value. Expected ${e.joinValues(t.options)}, received '${t.received}'`;break;case n.invalid_arguments:r="Invalid function arguments";break;case n.invalid_return_type:r="Invalid function return type";break;case n.invalid_date:r="Invalid date";break;case n.invalid_string:"object"==typeof t.validation?"includes"in t.validation?(r=`Invalid input: must include "${t.validation.includes}"`,"number"==typeof t.validation.position&&(r=`${r} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:e.assertNever(t.validation):r="regex"!==t.validation?`Invalid ${t.validation}`:"Invalid";break;case n.too_small:r="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:"number"===t.type?`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:"date"===t.type?`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:"Invalid input";break;case n.too_big:r="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:"number"===t.type?`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"bigint"===t.type?`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"date"===t.type?`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:"Invalid input";break;case n.custom:r="Invalid input";break;case n.invalid_intersection_types:r="Intersection results could not be merged";break;case n.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case n.not_finite:r="Number must be finite";break;default:r=s.defaultError,e.assertNever(t)}return{message:r}};let o=i;function d(){return o}const c=e=>{const{data:t,path:a,errorMaps:s,issueData:n}=e,r=[...a,...n.path||[]],i={...n,path:r};if(void 0!==n.message)return{...n,path:r,message:n.message};let o="";const d=s.filter((e=>!!e)).slice().reverse();for(const e of d)o=e(i,{data:t,defaultError:o}).message;return{...n,path:r,message:o}};function u(e,t){const a=d(),s=c({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,a,a===i?void 0:i].filter((e=>!!e))});e.common.issues.push(s)}class l{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const a=[];for(const s of t){if("aborted"===s.status)return h;"dirty"===s.status&&e.dirty(),a.push(s.value)}return{status:e.value,value:a}}static async mergeObjectAsync(e,t){const a=[];for(const e of t){const t=await e.key,s=await e.value;a.push({key:t,value:s})}return l.mergeObjectSync(e,a)}static mergeObjectSync(e,t){const a={};for(const s of t){const{key:t,value:n}=s;if("aborted"===t.status)return h;if("aborted"===n.status)return h;"dirty"===t.status&&e.dirty(),"dirty"===n.status&&e.dirty(),"__proto__"===t.value||void 0===n.value&&!s.alwaysSet||(a[t.value]=n.value)}return{status:e.value,value:a}}}const h=Object.freeze({status:"aborted"}),p=e=>({status:"dirty",value:e}),m=e=>({status:"valid",value:e}),f=e=>"aborted"===e.status,y=e=>"dirty"===e.status,_=e=>"valid"===e.status,v=e=>"undefined"!=typeof Promise&&e instanceof Promise;function g(e,t,a,s){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}function b(e,t,a,s,n){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,a),a}var k,x,w;"function"==typeof SuppressedError&&SuppressedError,function(e){e.errToObj=e=>"string"==typeof e?{message:e}:e||{},e.toString=e=>"string"==typeof e?e:null==e?void 0:e.message}(k||(k={}));class Z{constructor(e,t,a,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=a,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 T=(e,t)=>{if(_(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new r(e.common.issues);return this._error=t,this._error}}};function O(e){if(!e)return{};const{errorMap:t,invalid_type_error:a,required_error:s,description:n}=e;if(t&&(a||s))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');if(t)return{errorMap:t,description:n};return{errorMap:(t,n)=>{var r,i;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:n.defaultError}:void 0===n.data?{message:null!==(r=null!=o?o:s)&&void 0!==r?r:n.defaultError}:"invalid_type"!==t.code?{message:n.defaultError}:{message:null!==(i=null!=o?o:a)&&void 0!==i?i:n.defaultError}},description:n}}class j{get description(){return this._def.description}_getType(e){return s(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:s(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new l,ctx:{common:e.parent.common,data:e.data,parsedType:s(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(v(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 a=this.safeParse(e,t);if(a.success)return a.data;throw a.error}safeParse(e,t){var a;const n={common:{issues:[],async:null!==(a=null==t?void 0:t.async)&&void 0!==a&&a,contextualErrorMap:null==t?void 0:t.errorMap},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:s(e)},r=this._parseSync({data:e,path:n.path,parent:n});return T(n,r)}"~validate"(e){var t,a;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:s(e)};if(!this["~standard"].async)try{const t=this._parseSync({data:e,path:[],parent:n});return _(t)?{value:t.value}:{issues:n.common.issues}}catch(e){(null===(a=null===(t=null==e?void 0:e.message)||void 0===t?void 0:t.toLowerCase())||void 0===a?void 0:a.includes("encountered"))&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then((e=>_(e)?{value:e.value}:{issues:n.common.issues}))}async parseAsync(e,t){const a=await this.safeParseAsync(e,t);if(a.success)return a.data;throw a.error}async safeParseAsync(e,t){const a={common:{issues:[],contextualErrorMap:null==t?void 0:t.errorMap,async:!0},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:s(e)},n=this._parse({data:e,path:a.path,parent:a}),r=await(v(n)?n:Promise.resolve(n));return T(a,r)}refine(e,t){const a=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement(((t,s)=>{const r=e(t),i=()=>s.addIssue({code:n.custom,...a(t)});return"undefined"!=typeof Promise&&r instanceof Promise?r.then((e=>!!e||(i(),!1))):!!r||(i(),!1)}))}refinement(e,t){return this._refinement(((a,s)=>!!e(a)||(s.addIssue("function"==typeof t?t(a,s):t),!1)))}_refinement(e){return new je({schema:this,typeName:De.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return Ce.create(this,this._def)}nullable(){return Ae.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return de.create(this)}promise(){return Oe.create(this,this._def)}or(e){return le.create([this,e],this._def)}and(e){return fe.create(this,e,this._def)}transform(e){return new je({...O(this._def),schema:this,typeName:De.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new Se({...O(this._def),innerType:this,defaultValue:t,typeName:De.ZodDefault})}brand(){return new Re({typeName:De.ZodBranded,type:this,...O(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new Ee({...O(this._def),innerType:this,catchValue:t,typeName:De.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return Pe.create(this,e)}readonly(){return $e.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const C=/^c[^\s-]{8,}$/i,A=/^[0-9a-z]+$/,S=/^[0-9A-HJKMNP-TV-Z]{26}$/i,E=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,N=/^[a-z0-9_-]{21}$/i,I=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,R=/^[-+]?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)?)??$/,P=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;let $;const M=/^(?:(?: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])$/,F=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,L=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,D=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,z=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,V=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,U="((\\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])))",q=new RegExp(`^${U}$`);function K(e){let t="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`),t}function B(e){let t=`${U}T${K(e)}`;const a=[];return a.push(e.local?"Z?":"Z"),e.offset&&a.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${a.join("|")})`,new RegExp(`^${t}$`)}function W(e,t){if(!I.test(e))return!1;try{const[a]=e.split("."),s=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),n=JSON.parse(atob(s));return"object"==typeof n&&null!==n&&(!(!n.typ||!n.alg)&&(!t||n.alg===t))}catch(e){return!1}}function J(e,t){return!("v4"!==t&&t||!F.test(e))||!("v6"!==t&&t||!D.test(e))}class H extends j{_parse(t){this._def.coerce&&(t.data=String(t.data));if(this._getType(t)!==a.string){const e=this._getOrReturnCtx(t);return u(e,{code:n.invalid_type,expected:a.string,received:e.parsedType}),h}const s=new l;let r;for(const a of this._def.checks)if("min"===a.kind)t.data.length<a.value&&(r=this._getOrReturnCtx(t,r),u(r,{code:n.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if("max"===a.kind)t.data.length>a.value&&(r=this._getOrReturnCtx(t,r),u(r,{code:n.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if("length"===a.kind){const e=t.data.length>a.value,i=t.data.length<a.value;(e||i)&&(r=this._getOrReturnCtx(t,r),e?u(r,{code:n.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):i&&u(r,{code:n.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),s.dirty())}else if("email"===a.kind)P.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"email",code:n.invalid_string,message:a.message}),s.dirty());else if("emoji"===a.kind)$||($=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),$.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"emoji",code:n.invalid_string,message:a.message}),s.dirty());else if("uuid"===a.kind)E.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"uuid",code:n.invalid_string,message:a.message}),s.dirty());else if("nanoid"===a.kind)N.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"nanoid",code:n.invalid_string,message:a.message}),s.dirty());else if("cuid"===a.kind)C.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"cuid",code:n.invalid_string,message:a.message}),s.dirty());else if("cuid2"===a.kind)A.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"cuid2",code:n.invalid_string,message:a.message}),s.dirty());else if("ulid"===a.kind)S.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"ulid",code:n.invalid_string,message:a.message}),s.dirty());else if("url"===a.kind)try{new URL(t.data)}catch(e){r=this._getOrReturnCtx(t,r),u(r,{validation:"url",code:n.invalid_string,message:a.message}),s.dirty()}else if("regex"===a.kind){a.regex.lastIndex=0;a.regex.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"regex",code:n.invalid_string,message:a.message}),s.dirty())}else if("trim"===a.kind)t.data=t.data.trim();else if("includes"===a.kind)t.data.includes(a.value,a.position)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),s.dirty());else if("toLowerCase"===a.kind)t.data=t.data.toLowerCase();else if("toUpperCase"===a.kind)t.data=t.data.toUpperCase();else if("startsWith"===a.kind)t.data.startsWith(a.value)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:{startsWith:a.value},message:a.message}),s.dirty());else if("endsWith"===a.kind)t.data.endsWith(a.value)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:{endsWith:a.value},message:a.message}),s.dirty());else if("datetime"===a.kind){B(a).test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:"datetime",message:a.message}),s.dirty())}else if("date"===a.kind){q.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:"date",message:a.message}),s.dirty())}else if("time"===a.kind){new RegExp(`^${K(a)}$`).test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:"time",message:a.message}),s.dirty())}else"duration"===a.kind?R.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"duration",code:n.invalid_string,message:a.message}),s.dirty()):"ip"===a.kind?(i=t.data,("v4"!==(o=a.version)&&o||!M.test(i))&&("v6"!==o&&o||!L.test(i))&&(r=this._getOrReturnCtx(t,r),u(r,{validation:"ip",code:n.invalid_string,message:a.message}),s.dirty())):"jwt"===a.kind?W(t.data,a.alg)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"jwt",code:n.invalid_string,message:a.message}),s.dirty()):"cidr"===a.kind?J(t.data,a.version)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"cidr",code:n.invalid_string,message:a.message}),s.dirty()):"base64"===a.kind?z.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"base64",code:n.invalid_string,message:a.message}),s.dirty()):"base64url"===a.kind?V.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"base64url",code:n.invalid_string,message:a.message}),s.dirty()):e.assertNever(a);var i,o;return{status:s.value,value:t.data}}_regex(e,t,a){return this.refinement((t=>e.test(t)),{validation:t,code:n.invalid_string,...k.errToObj(a)})}_addCheck(e){return new H({...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)})}base64url(e){return this._addCheck({kind:"base64url",...k.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...k.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...k.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...k.errToObj(e)})}datetime(e){var t,a;return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,offset:null!==(t=null==e?void 0:e.offset)&&void 0!==t&&t,local:null!==(a=null==e?void 0:e.local)&&void 0!==a&&a,...k.errToObj(null==e?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,...k.errToObj(null==e?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:null==t?void 0:t.position,...k.errToObj(null==t?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 H({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new H({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new H({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find((e=>"datetime"===e.kind))}get isDate(){return!!this._def.checks.find((e=>"date"===e.kind))}get isTime(){return!!this._def.checks.find((e=>"time"===e.kind))}get isDuration(){return!!this._def.checks.find((e=>"duration"===e.kind))}get isEmail(){return!!this._def.checks.find((e=>"email"===e.kind))}get isURL(){return!!this._def.checks.find((e=>"url"===e.kind))}get isEmoji(){return!!this._def.checks.find((e=>"emoji"===e.kind))}get isUUID(){return!!this._def.checks.find((e=>"uuid"===e.kind))}get isNANOID(){return!!this._def.checks.find((e=>"nanoid"===e.kind))}get isCUID(){return!!this._def.checks.find((e=>"cuid"===e.kind))}get isCUID2(){return!!this._def.checks.find((e=>"cuid2"===e.kind))}get isULID(){return!!this._def.checks.find((e=>"ulid"===e.kind))}get isIP(){return!!this._def.checks.find((e=>"ip"===e.kind))}get isCIDR(){return!!this._def.checks.find((e=>"cidr"===e.kind))}get isBase64(){return!!this._def.checks.find((e=>"base64"===e.kind))}get isBase64url(){return!!this._def.checks.find((e=>"base64url"===e.kind))}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}function Y(e,t){const a=(e.toString().split(".")[1]||"").length,s=(t.toString().split(".")[1]||"").length,n=a>s?a:s;return parseInt(e.toFixed(n).replace(".",""))%parseInt(t.toFixed(n).replace(".",""))/Math.pow(10,n)}H.create=e=>{var t;return new H({checks:[],typeName:De.ZodString,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...O(e)})};class G extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){this._def.coerce&&(t.data=Number(t.data));if(this._getType(t)!==a.number){const e=this._getOrReturnCtx(t);return u(e,{code:n.invalid_type,expected:a.number,received:e.parsedType}),h}let s;const r=new l;for(const a of this._def.checks)if("int"===a.kind)e.isInteger(t.data)||(s=this._getOrReturnCtx(t,s),u(s,{code:n.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty());else if("min"===a.kind){(a.inclusive?t.data<a.value:t.data<=a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty())}else if("max"===a.kind){(a.inclusive?t.data>a.value:t.data>=a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty())}else"multipleOf"===a.kind?0!==Y(t.data,a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):"finite"===a.kind?Number.isFinite(t.data)||(s=this._getOrReturnCtx(t,s),u(s,{code:n.not_finite,message:a.message}),r.dirty()):e.assertNever(a);return{status:r.value,value:t.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,a,s){return new G({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:a,message:k.toString(s)}]})}_addCheck(e){return new G({...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)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find((t=>"int"===t.kind||"multipleOf"===t.kind&&e.isInteger(t.value)))}get isFinite(){let e=null,t=null;for(const a of this._def.checks){if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;"min"===a.kind?(null===t||a.value>t)&&(t=a.value):"max"===a.kind&&(null===e||a.value<e)&&(e=a.value)}return Number.isFinite(t)&&Number.isFinite(e)}}G.create=e=>new G({checks:[],typeName:De.ZodNumber,coerce:(null==e?void 0:e.coerce)||!1,...O(e)});class Q extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch(e){return this._getInvalidInput(t)}if(this._getType(t)!==a.bigint)return this._getInvalidInput(t);let s;const r=new l;for(const a of this._def.checks)if("min"===a.kind){(a.inclusive?t.data<a.value:t.data<=a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty())}else if("max"===a.kind){(a.inclusive?t.data>a.value:t.data>=a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty())}else"multipleOf"===a.kind?t.data%a.value!==BigInt(0)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):e.assertNever(a);return{status:r.value,value:t.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.bigint,received:t.parsedType}),h}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,a,s){return new Q({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:a,message:k.toString(s)}]})}_addCheck(e){return new Q({...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)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}Q.create=e=>{var t;return new Q({checks:[],typeName:De.ZodBigInt,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...O(e)})};class X extends j{_parse(e){this._def.coerce&&(e.data=Boolean(e.data));if(this._getType(e)!==a.boolean){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.boolean,received:t.parsedType}),h}return m(e.data)}}X.create=e=>new X({typeName:De.ZodBoolean,coerce:(null==e?void 0:e.coerce)||!1,...O(e)});class ee extends j{_parse(t){this._def.coerce&&(t.data=new Date(t.data));if(this._getType(t)!==a.date){const e=this._getOrReturnCtx(t);return u(e,{code:n.invalid_type,expected:a.date,received:e.parsedType}),h}if(isNaN(t.data.getTime())){return u(this._getOrReturnCtx(t),{code:n.invalid_date}),h}const s=new l;let r;for(const a of this._def.checks)"min"===a.kind?t.data.getTime()<a.value&&(r=this._getOrReturnCtx(t,r),u(r,{code:n.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),s.dirty()):"max"===a.kind?t.data.getTime()>a.value&&(r=this._getOrReturnCtx(t,r),u(r,{code:n.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),s.dirty()):e.assertNever(a);return{status:s.value,value:new Date(t.data.getTime())}}_addCheck(e){return new ee({...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)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}ee.create=e=>new ee({checks:[],coerce:(null==e?void 0:e.coerce)||!1,typeName:De.ZodDate,...O(e)});class te extends j{_parse(e){if(this._getType(e)!==a.symbol){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.symbol,received:t.parsedType}),h}return m(e.data)}}te.create=e=>new te({typeName:De.ZodSymbol,...O(e)});class ae extends j{_parse(e){if(this._getType(e)!==a.undefined){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.undefined,received:t.parsedType}),h}return m(e.data)}}ae.create=e=>new ae({typeName:De.ZodUndefined,...O(e)});class se extends j{_parse(e){if(this._getType(e)!==a.null){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.null,received:t.parsedType}),h}return m(e.data)}}se.create=e=>new se({typeName:De.ZodNull,...O(e)});class ne extends j{constructor(){super(...arguments),this._any=!0}_parse(e){return m(e.data)}}ne.create=e=>new ne({typeName:De.ZodAny,...O(e)});class re extends j{constructor(){super(...arguments),this._unknown=!0}_parse(e){return m(e.data)}}re.create=e=>new re({typeName:De.ZodUnknown,...O(e)});class ie extends j{_parse(e){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.never,received:t.parsedType}),h}}ie.create=e=>new ie({typeName:De.ZodNever,...O(e)});class oe extends j{_parse(e){if(this._getType(e)!==a.undefined){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.void,received:t.parsedType}),h}return m(e.data)}}oe.create=e=>new oe({typeName:De.ZodVoid,...O(e)});class de extends j{_parse(e){const{ctx:t,status:s}=this._processInputParams(e),r=this._def;if(t.parsedType!==a.array)return u(t,{code:n.invalid_type,expected:a.array,received:t.parsedType}),h;if(null!==r.exactLength){const e=t.data.length>r.exactLength.value,a=t.data.length<r.exactLength.value;(e||a)&&(u(t,{code:e?n.too_big:n.too_small,minimum:a?r.exactLength.value:void 0,maximum:e?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),s.dirty())}if(null!==r.minLength&&t.data.length<r.minLength.value&&(u(t,{code:n.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),s.dirty()),null!==r.maxLength&&t.data.length>r.maxLength.value&&(u(t,{code:n.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),s.dirty()),t.common.async)return Promise.all([...t.data].map(((e,a)=>r.type._parseAsync(new Z(t,e,t.path,a))))).then((e=>l.mergeArray(s,e)));const i=[...t.data].map(((e,a)=>r.type._parseSync(new Z(t,e,t.path,a))));return l.mergeArray(s,i)}get element(){return this._def.type}min(e,t){return new de({...this._def,minLength:{value:e,message:k.toString(t)}})}max(e,t){return new de({...this._def,maxLength:{value:e,message:k.toString(t)}})}length(e,t){return new de({...this._def,exactLength:{value:e,message:k.toString(t)}})}nonempty(e){return this.min(1,e)}}function ce(e){if(e instanceof ue){const t={};for(const a in e.shape){const s=e.shape[a];t[a]=Ce.create(ce(s))}return new ue({...e._def,shape:()=>t})}return e instanceof de?new de({...e._def,type:ce(e.element)}):e instanceof Ce?Ce.create(ce(e.unwrap())):e instanceof Ae?Ae.create(ce(e.unwrap())):e instanceof ye?ye.create(e.items.map((e=>ce(e)))):e}de.create=(e,t)=>new de({type:e,minLength:null,maxLength:null,exactLength:null,typeName:De.ZodArray,...O(t)});class ue extends j{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const t=this._def.shape(),a=e.objectKeys(t);return this._cached={shape:t,keys:a}}_parse(e){if(this._getType(e)!==a.object){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.object,received:t.parsedType}),h}const{status:t,ctx:s}=this._processInputParams(e),{shape:r,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof ie&&"strip"===this._def.unknownKeys))for(const e in s.data)i.includes(e)||o.push(e);const d=[];for(const e of i){const t=r[e],a=s.data[e];d.push({key:{status:"valid",value:e},value:t._parse(new Z(s,a,s.path,e)),alwaysSet:e in s.data})}if(this._def.catchall instanceof ie){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of o)d.push({key:{status:"valid",value:e},value:{status:"valid",value:s.data[e]}});else if("strict"===e)o.length>0&&(u(s,{code:n.unrecognized_keys,keys:o}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of o){const a=s.data[t];d.push({key:{status:"valid",value:t},value:e._parse(new Z(s,a,s.path,t)),alwaysSet:t in s.data})}}return s.common.async?Promise.resolve().then((async()=>{const e=[];for(const t of d){const a=await t.key,s=await t.value;e.push({key:a,value:s,alwaysSet:t.alwaysSet})}return e})).then((e=>l.mergeObjectSync(t,e))):l.mergeObjectSync(t,d)}get shape(){return this._def.shape()}strict(e){return k.errToObj,new ue({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,a)=>{var s,n,r,i;const o=null!==(r=null===(n=(s=this._def).errorMap)||void 0===n?void 0:n.call(s,t,a).message)&&void 0!==r?r:a.defaultError;return"unrecognized_keys"===t.code?{message:null!==(i=k.errToObj(e).message)&&void 0!==i?i:o}:{message:o}}}:{}})}strip(){return new ue({...this._def,unknownKeys:"strip"})}passthrough(){return new ue({...this._def,unknownKeys:"passthrough"})}extend(e){return new ue({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new ue({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:De.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new ue({...this._def,catchall:e})}pick(t){const a={};return e.objectKeys(t).forEach((e=>{t[e]&&this.shape[e]&&(a[e]=this.shape[e])})),new ue({...this._def,shape:()=>a})}omit(t){const a={};return e.objectKeys(this.shape).forEach((e=>{t[e]||(a[e]=this.shape[e])})),new ue({...this._def,shape:()=>a})}deepPartial(){return ce(this)}partial(t){const a={};return e.objectKeys(this.shape).forEach((e=>{const s=this.shape[e];t&&!t[e]?a[e]=s:a[e]=s.optional()})),new ue({...this._def,shape:()=>a})}required(t){const a={};return e.objectKeys(this.shape).forEach((e=>{if(t&&!t[e])a[e]=this.shape[e];else{let t=this.shape[e];for(;t instanceof Ce;)t=t._def.innerType;a[e]=t}})),new ue({...this._def,shape:()=>a})}keyof(){return we(e.objectKeys(this.shape))}}ue.create=(e,t)=>new ue({shape:()=>e,unknownKeys:"strip",catchall:ie.create(),typeName:De.ZodObject,...O(t)}),ue.strictCreate=(e,t)=>new ue({shape:()=>e,unknownKeys:"strict",catchall:ie.create(),typeName:De.ZodObject,...O(t)}),ue.lazycreate=(e,t)=>new ue({shape:e,unknownKeys:"strip",catchall:ie.create(),typeName:De.ZodObject,...O(t)});class le extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a=this._def.options;if(t.common.async)return Promise.all(a.map((async e=>{const a={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:a}),ctx:a}}))).then((function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const a of e)if("dirty"===a.result.status)return t.common.issues.push(...a.ctx.common.issues),a.result;const a=e.map((e=>new r(e.ctx.common.issues)));return u(t,{code:n.invalid_union,unionErrors:a}),h}));{let e;const s=[];for(const n of a){const a={...t,common:{...t.common,issues:[]},parent:null},r=n._parseSync({data:t.data,path:t.path,parent:a});if("valid"===r.status)return r;"dirty"!==r.status||e||(e={result:r,ctx:a}),a.common.issues.length&&s.push(a.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const i=s.map((e=>new r(e)));return u(t,{code:n.invalid_union,unionErrors:i}),h}}get options(){return this._def.options}}le.create=(e,t)=>new le({options:e,typeName:De.ZodUnion,...O(t)});const he=t=>t instanceof ke?he(t.schema):t instanceof je?he(t.innerType()):t instanceof xe?[t.value]:t instanceof Ze?t.options:t instanceof Te?e.objectValues(t.enum):t instanceof Se?he(t._def.innerType):t instanceof ae?[void 0]:t instanceof se?[null]:t instanceof Ce?[void 0,...he(t.unwrap())]:t instanceof Ae?[null,...he(t.unwrap())]:t instanceof Re||t instanceof $e?he(t.unwrap()):t instanceof Ee?he(t._def.innerType):[];class pe extends j{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==a.object)return u(t,{code:n.invalid_type,expected:a.object,received:t.parsedType}),h;const s=this.discriminator,r=t.data[s],i=this.optionsMap.get(r);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(u(t,{code:n.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),h)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,a){const s=new Map;for(const a of t){const t=he(a.shape[e]);if(!t.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const n of t){if(s.has(n))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(n)}`);s.set(n,a)}}return new pe({typeName:De.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...O(a)})}}function me(t,n){const r=s(t),i=s(n);if(t===n)return{valid:!0,data:t};if(r===a.object&&i===a.object){const a=e.objectKeys(n),s=e.objectKeys(t).filter((e=>-1!==a.indexOf(e))),r={...t,...n};for(const e of s){const a=me(t[e],n[e]);if(!a.valid)return{valid:!1};r[e]=a.data}return{valid:!0,data:r}}if(r===a.array&&i===a.array){if(t.length!==n.length)return{valid:!1};const e=[];for(let a=0;a<t.length;a++){const s=me(t[a],n[a]);if(!s.valid)return{valid:!1};e.push(s.data)}return{valid:!0,data:e}}return r===a.date&&i===a.date&&+t==+n?{valid:!0,data:t}:{valid:!1}}class fe extends j{_parse(e){const{status:t,ctx:a}=this._processInputParams(e),s=(e,s)=>{if(f(e)||f(s))return h;const r=me(e.value,s.value);return r.valid?((y(e)||y(s))&&t.dirty(),{status:t.value,value:r.data}):(u(a,{code:n.invalid_intersection_types}),h)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then((([e,t])=>s(e,t))):s(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}fe.create=(e,t,a)=>new fe({left:e,right:t,typeName:De.ZodIntersection,...O(a)});class ye extends j{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==a.array)return u(s,{code:n.invalid_type,expected:a.array,received:s.parsedType}),h;if(s.data.length<this._def.items.length)return u(s,{code:n.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),h;!this._def.rest&&s.data.length>this._def.items.length&&(u(s,{code:n.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const r=[...s.data].map(((e,t)=>{const a=this._def.items[t]||this._def.rest;return a?a._parse(new Z(s,e,s.path,t)):null})).filter((e=>!!e));return s.common.async?Promise.all(r).then((e=>l.mergeArray(t,e))):l.mergeArray(t,r)}get items(){return this._def.items}rest(e){return new ye({...this._def,rest:e})}}ye.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ye({items:e,typeName:De.ZodTuple,rest:null,...O(t)})};class _e extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==a.object)return u(s,{code:n.invalid_type,expected:a.object,received:s.parsedType}),h;const r=[],i=this._def.keyType,o=this._def.valueType;for(const e in s.data)r.push({key:i._parse(new Z(s,e,s.path,e)),value:o._parse(new Z(s,s.data[e],s.path,e)),alwaysSet:e in s.data});return s.common.async?l.mergeObjectAsync(t,r):l.mergeObjectSync(t,r)}get element(){return this._def.valueType}static create(e,t,a){return new _e(t instanceof j?{keyType:e,valueType:t,typeName:De.ZodRecord,...O(a)}:{keyType:H.create(),valueType:e,typeName:De.ZodRecord,...O(t)})}}class ve extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==a.map)return u(s,{code:n.invalid_type,expected:a.map,received:s.parsedType}),h;const r=this._def.keyType,i=this._def.valueType,o=[...s.data.entries()].map((([e,t],a)=>({key:r._parse(new Z(s,e,s.path,[a,"key"])),value:i._parse(new Z(s,t,s.path,[a,"value"]))})));if(s.common.async){const e=new Map;return Promise.resolve().then((async()=>{for(const a of o){const s=await a.key,n=await a.value;if("aborted"===s.status||"aborted"===n.status)return h;"dirty"!==s.status&&"dirty"!==n.status||t.dirty(),e.set(s.value,n.value)}return{status:t.value,value:e}}))}{const e=new Map;for(const a of o){const s=a.key,n=a.value;if("aborted"===s.status||"aborted"===n.status)return h;"dirty"!==s.status&&"dirty"!==n.status||t.dirty(),e.set(s.value,n.value)}return{status:t.value,value:e}}}}ve.create=(e,t,a)=>new ve({valueType:t,keyType:e,typeName:De.ZodMap,...O(a)});class ge extends j{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==a.set)return u(s,{code:n.invalid_type,expected:a.set,received:s.parsedType}),h;const r=this._def;null!==r.minSize&&s.data.size<r.minSize.value&&(u(s,{code:n.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),t.dirty()),null!==r.maxSize&&s.data.size>r.maxSize.value&&(u(s,{code:n.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),t.dirty());const i=this._def.valueType;function o(e){const a=new Set;for(const s of e){if("aborted"===s.status)return h;"dirty"===s.status&&t.dirty(),a.add(s.value)}return{status:t.value,value:a}}const d=[...s.data.values()].map(((e,t)=>i._parse(new Z(s,e,s.path,t))));return s.common.async?Promise.all(d).then((e=>o(e))):o(d)}min(e,t){return new ge({...this._def,minSize:{value:e,message:k.toString(t)}})}max(e,t){return new ge({...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)}}ge.create=(e,t)=>new ge({valueType:e,minSize:null,maxSize:null,typeName:De.ZodSet,...O(t)});class be extends j{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==a.function)return u(t,{code:n.invalid_type,expected:a.function,received:t.parsedType}),h;function s(e,a){return c({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,d(),i].filter((e=>!!e)),issueData:{code:n.invalid_arguments,argumentsError:a}})}function o(e,a){return c({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,d(),i].filter((e=>!!e)),issueData:{code:n.invalid_return_type,returnTypeError:a}})}const l={errorMap:t.common.contextualErrorMap},p=t.data;if(this._def.returns instanceof Oe){const e=this;return m((async function(...t){const a=new r([]),n=await e._def.args.parseAsync(t,l).catch((e=>{throw a.addIssue(s(t,e)),a})),i=await Reflect.apply(p,this,n);return await e._def.returns._def.type.parseAsync(i,l).catch((e=>{throw a.addIssue(o(i,e)),a}))}))}{const e=this;return m((function(...t){const a=e._def.args.safeParse(t,l);if(!a.success)throw new r([s(t,a.error)]);const n=Reflect.apply(p,this,a.data),i=e._def.returns.safeParse(n,l);if(!i.success)throw new r([o(n,i.error)]);return i.data}))}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new be({...this._def,args:ye.create(e).rest(re.create())})}returns(e){return new be({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,a){return new be({args:e||ye.create([]).rest(re.create()),returns:t||re.create(),typeName:De.ZodFunction,...O(a)})}}class ke extends j{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})}}ke.create=(e,t)=>new ke({getter:e,typeName:De.ZodLazy,...O(t)});class xe extends j{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return u(t,{received:t.data,code:n.invalid_literal,expected:this._def.value}),h}return{status:"valid",value:e.data}}get value(){return this._def.value}}function we(e,t){return new Ze({values:e,typeName:De.ZodEnum,...O(t)})}xe.create=(e,t)=>new xe({value:e,typeName:De.ZodLiteral,...O(t)});class Ze extends j{constructor(){super(...arguments),x.set(this,void 0)}_parse(t){if("string"!=typeof t.data){const a=this._getOrReturnCtx(t),s=this._def.values;return u(a,{expected:e.joinValues(s),received:a.parsedType,code:n.invalid_type}),h}if(g(this,x)||b(this,x,new Set(this._def.values)),!g(this,x).has(t.data)){const e=this._getOrReturnCtx(t),a=this._def.values;return u(e,{received:e.data,code:n.invalid_enum_value,options:a}),h}return m(t.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 Ze.create(e,{...this._def,...t})}exclude(e,t=this._def){return Ze.create(this.options.filter((t=>!e.includes(t))),{...this._def,...t})}}x=new WeakMap,Ze.create=we;class Te extends j{constructor(){super(...arguments),w.set(this,void 0)}_parse(t){const s=e.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==a.string&&r.parsedType!==a.number){const t=e.objectValues(s);return u(r,{expected:e.joinValues(t),received:r.parsedType,code:n.invalid_type}),h}if(g(this,w)||b(this,w,new Set(e.getValidEnumValues(this._def.values))),!g(this,w).has(t.data)){const t=e.objectValues(s);return u(r,{received:r.data,code:n.invalid_enum_value,options:t}),h}return m(t.data)}get enum(){return this._def.values}}w=new WeakMap,Te.create=(e,t)=>new Te({values:e,typeName:De.ZodNativeEnum,...O(t)});class Oe extends j{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==a.promise&&!1===t.common.async)return u(t,{code:n.invalid_type,expected:a.promise,received:t.parsedType}),h;const s=t.parsedType===a.promise?t.data:Promise.resolve(t.data);return m(s.then((e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap}))))}}Oe.create=(e,t)=>new Oe({type:e,typeName:De.ZodPromise,...O(t)});class je extends j{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===De.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:a,ctx:s}=this._processInputParams(t),n=this._def.effect||null,r={addIssue:e=>{u(s,e),e.fatal?a.abort():a.dirty()},get path(){return s.path}};if(r.addIssue=r.addIssue.bind(r),"preprocess"===n.type){const e=n.transform(s.data,r);if(s.common.async)return Promise.resolve(e).then((async e=>{if("aborted"===a.value)return h;const t=await this._def.schema._parseAsync({data:e,path:s.path,parent:s});return"aborted"===t.status?h:"dirty"===t.status||"dirty"===a.value?p(t.value):t}));{if("aborted"===a.value)return h;const t=this._def.schema._parseSync({data:e,path:s.path,parent:s});return"aborted"===t.status?h:"dirty"===t.status||"dirty"===a.value?p(t.value):t}}if("refinement"===n.type){const e=e=>{const t=n.refinement(e,r);if(s.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===s.common.async){const t=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return"aborted"===t.status?h:("dirty"===t.status&&a.dirty(),e(t.value),{status:a.value,value:t.value})}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then((t=>"aborted"===t.status?h:("dirty"===t.status&&a.dirty(),e(t.value).then((()=>({status:a.value,value:t.value}))))))}if("transform"===n.type){if(!1===s.common.async){const e=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!_(e))return e;const t=n.transform(e.value,r);if(t instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:a.value,value:t}}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then((e=>_(e)?Promise.resolve(n.transform(e.value,r)).then((e=>({status:a.value,value:e}))):e))}e.assertNever(n)}}je.create=(e,t,a)=>new je({schema:e,typeName:De.ZodEffects,effect:t,...O(a)}),je.createWithPreprocess=(e,t,a)=>new je({schema:t,effect:{type:"preprocess",transform:e},typeName:De.ZodEffects,...O(a)});class Ce extends j{_parse(e){return this._getType(e)===a.undefined?m(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ce.create=(e,t)=>new Ce({innerType:e,typeName:De.ZodOptional,...O(t)});class Ae extends j{_parse(e){return this._getType(e)===a.null?m(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ae.create=(e,t)=>new Ae({innerType:e,typeName:De.ZodNullable,...O(t)});class Se extends j{_parse(e){const{ctx:t}=this._processInputParams(e);let s=t.data;return t.parsedType===a.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Se.create=(e,t)=>new Se({innerType:e,typeName:De.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...O(t)});class Ee extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return v(s)?s.then((e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new r(a.common.issues)},input:a.data})}))):{status:"valid",value:"valid"===s.status?s.value:this._def.catchValue({get error(){return new r(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}Ee.create=(e,t)=>new Ee({innerType:e,typeName:De.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...O(t)});class Ne extends j{_parse(e){if(this._getType(e)!==a.nan){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.nan,received:t.parsedType}),h}return{status:"valid",value:e.data}}}Ne.create=e=>new Ne({typeName:De.ZodNaN,...O(e)});const Ie=Symbol("zod_brand");class Re extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a=t.data;return this._def.type._parse({data:a,path:t.path,parent:t})}unwrap(){return this._def.type}}class Pe extends j{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.common.async){return(async()=>{const e=await this._def.in._parseAsync({data:a.data,path:a.path,parent:a});return"aborted"===e.status?h:"dirty"===e.status?(t.dirty(),p(e.value)):this._def.out._parseAsync({data:e.value,path:a.path,parent:a})})()}{const e=this._def.in._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===e.status?h:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:a.path,parent:a})}}static create(e,t){return new Pe({in:e,out:t,typeName:De.ZodPipeline})}}class $e extends j{_parse(e){const t=this._def.innerType._parse(e),a=e=>(_(e)&&(e.value=Object.freeze(e.value)),e);return v(t)?t.then((e=>a(e))):a(t)}unwrap(){return this._def.innerType}}function Me(e,t){const a="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof a?{message:a}:a}function Fe(e,t={},a){return e?ne.create().superRefine(((s,n)=>{var r,i;const o=e(s);if(o instanceof Promise)return o.then((e=>{var r,i;if(!e){const e=Me(t,s),o=null===(i=null!==(r=e.fatal)&&void 0!==r?r:a)||void 0===i||i;n.addIssue({code:"custom",...e,fatal:o})}}));if(!o){const e=Me(t,s),o=null===(i=null!==(r=e.fatal)&&void 0!==r?r:a)||void 0===i||i;n.addIssue({code:"custom",...e,fatal:o})}})):ne.create()}$e.create=(e,t)=>new $e({innerType:e,typeName:De.ZodReadonly,...O(t)});const Le={object:ue.lazycreate};var De;!function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"}(De||(De={}));const ze=H.create,Ve=G.create,Ue=Ne.create,qe=Q.create,Ke=X.create,Be=ee.create,We=te.create,Je=ae.create,He=se.create,Ye=ne.create,Ge=re.create,Qe=ie.create,Xe=oe.create,et=de.create,tt=ue.create,at=ue.strictCreate,st=le.create,nt=pe.create,rt=fe.create,it=ye.create,ot=_e.create,dt=ve.create,ct=ge.create,ut=be.create,lt=ke.create,ht=xe.create,pt=Ze.create,mt=Te.create,ft=Oe.create,yt=je.create,_t=Ce.create,vt=Ae.create,gt=je.createWithPreprocess,bt=Pe.create,kt={string:e=>H.create({...e,coerce:!0}),number:e=>G.create({...e,coerce:!0}),boolean:e=>X.create({...e,coerce:!0}),bigint:e=>Q.create({...e,coerce:!0}),date:e=>ee.create({...e,coerce:!0})},xt=h;var wt=Object.freeze({__proto__:null,defaultErrorMap:i,setErrorMap:function(e){o=e},getErrorMap:d,makeIssue:c,EMPTY_PATH:[],addIssueToContext:u,ParseStatus:l,INVALID:h,DIRTY:p,OK:m,isAborted:f,isDirty:y,isValid:_,isAsync:v,get util(){return e},get objectUtil(){return t},ZodParsedType:a,getParsedType:s,ZodType:j,datetimeRegex:B,ZodString:H,ZodNumber:G,ZodBigInt:Q,ZodBoolean:X,ZodDate:ee,ZodSymbol:te,ZodUndefined:ae,ZodNull:se,ZodAny:ne,ZodUnknown:re,ZodNever:ie,ZodVoid:oe,ZodArray:de,ZodObject:ue,ZodUnion:le,ZodDiscriminatedUnion:pe,ZodIntersection:fe,ZodTuple:ye,ZodRecord:_e,ZodMap:ve,ZodSet:ge,ZodFunction:be,ZodLazy:ke,ZodLiteral:xe,ZodEnum:Ze,ZodNativeEnum:Te,ZodPromise:Oe,ZodEffects:je,ZodTransformer:je,ZodOptional:Ce,ZodNullable:Ae,ZodDefault:Se,ZodCatch:Ee,ZodNaN:Ne,BRAND:Ie,ZodBranded:Re,ZodPipeline:Pe,ZodReadonly:$e,custom:Fe,Schema:j,ZodSchema:j,late:Le,get ZodFirstPartyTypeKind(){return De},coerce:kt,any:Ye,array:et,bigint:qe,boolean:Ke,date:Be,discriminatedUnion:nt,effect:yt,enum:pt,function:ut,instanceof:(e,t={message:`Input not instance of ${e.name}`})=>Fe((t=>t instanceof e),t),intersection:rt,lazy:lt,literal:ht,map:dt,nan:Ue,nativeEnum:mt,never:Qe,null:He,nullable:vt,number:Ve,object:tt,oboolean:()=>Ke().optional(),onumber:()=>Ve().optional(),optional:_t,ostring:()=>ze().optional(),pipeline:bt,preprocess:gt,promise:ft,record:ot,set:ct,strictObject:at,string:ze,symbol:We,transformer:yt,tuple:it,undefined:Je,union:st,unknown:Ge,void:Xe,NEVER:xt,ZodIssueCode:n,quotelessJson:e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),ZodError:r}),Zt=["interface","display","layout","module","panel","theme"],Tt=["hook","endpoint"],Ot=["operation"],jt="directus:extension",Ct=wt.object({app:wt.string(),api:wt.string()}),At=wt.object({request:wt.optional(wt.object({urls:wt.array(wt.string()),methods:wt.array(wt.union([wt.literal("GET"),wt.literal("POST"),wt.literal("PATCH"),wt.literal("PUT"),wt.literal("DELETE")]))})),log:wt.optional(wt.object({})),sleep:wt.optional(wt.object({}))}),St=wt.optional(wt.object({enabled:wt.boolean(),requestedScopes:At})),Et=wt.union([wt.object({type:wt.enum(Tt),name:wt.string(),source:wt.string()}),wt.object({type:wt.enum(Zt),name:wt.string(),source:wt.string()}),wt.object({type:wt.enum(Ot),name:wt.string(),source:Ct})]),Nt=wt.object({host:wt.string(),hidden:wt.boolean().optional()}),It=wt.object({type:wt.enum(Zt),path:wt.string(),source:wt.string()}),Rt=wt.object({type:wt.enum(Tt),path:wt.string(),source:wt.string(),sandbox:St}),Pt=wt.object({type:wt.enum(Ot),path:Ct,source:Ct,sandbox:St}),$t=wt.object({type:wt.literal("bundle"),partial:wt.boolean().optional(),path:Ct,entries:wt.array(Et)});wt.array(Et);var Mt=Nt.and(wt.union([It,Rt,Pt,$t]));wt.object({name:wt.string(),version:wt.string(),type:wt.union([wt.literal("module"),wt.literal("commonjs")]).optional(),description:wt.string().optional(),icon:wt.string().optional(),dependencies:wt.record(wt.string()).optional(),devDependencies:wt.record(wt.string()).optional(),[jt]:Mt});var Ft=(e=>(e.REQUEST="sql-query.request",e.RESPONSE="sql-query.response",e))(Ft||{});const Lt=[],Dt=[{name:"insights",config:(e,{database:t,services:a,emitter:s})=>{const{PanelsService:n}=a;async function r(e,a){if(new RegExp(["delete","update","insert","execute","kill","drop"].map((e=>`\\b${e}\\b`)).join("|")).test(e.toLowerCase()))throw new Error("SQL query is blacklisted");const s=e.match(/{{\w+}}/g);if(s)throw new Error(`Missing query param: ${s.join(", ").replace(/{{|}}/g,"")}`);return(e=>{let t=[],a=[];if(e&&e.rows&&e.fields)t=e.rows,a=e.fields.map((e=>e.name));else if(Array.isArray(e)){const s=e[0];if(Array.isArray(s)){const[s,n]=e;t=2===s.length&&Array.isArray(s[0])?s.at(0):s,a=(2===n.length&&Array.isArray(n[0])?n.at(0):n).map((e=>e.name))}else t=e,a=Object.keys(s)}else e.recordset&&(t=e.recordset,a=e.recordset.columns?Object.keys(e.recordset.columns):[]);return{items:t,headers:a}})(await t.raw(e,a))}e.get("/query/:panelId",(async(e,t)=>{try{const{query:a,variables:i,panel:o}=await async function(e){const t=e.params.panelId;if(!t)throw new Error("Missing panelId");const a=new n({accountability:e.accountability,schema:e.schema}),r=await a.readOne(t);let{variables:i,query:o}=await s.emitFilter(Ft.REQUEST,{variables:Object.assign({dashboard:r.dashboard},e.query??{}),query:r.options.sql},e);for(const e in i){if(!e.match(/^[a-zA-Z0-9_]+$/))throw new Error(`Invalid variable name: ${e}`);o=o.replace(new RegExp(`{{${e}}}`,"g"),`:${e}`)}return{query:o,variables:i,panel:r}}(e);let d=await r(a,i);d=await s.emitFilter(Ft.RESPONSE,d,e);let c=Number(o.options.cache??300);return c=c>0?c:300,t.set("Cache-control",`public, max-age=${c}`),t.json(d)}catch(e){return t.status(400).json({error:e.message})}}))}}],zt=[];export{Dt as endpoints,Lt as hooks,zt as operations};
1
+ var e,t;!function(e){e.assertEqual=e=>e,e.assertIs=function(e){},e.assertNever=function(e){throw new Error},e.arrayToEnum=e=>{const t={};for(const a of e)t[a]=a;return t},e.getValidEnumValues=t=>{const a=e.objectKeys(t).filter(e=>"number"!=typeof t[t[e]]),s={};for(const e of a)s[e]=t[e];return e.objectValues(s)},e.objectValues=t=>e.objectKeys(t).map(function(e){return t[e]}),e.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.push(a);return t},e.find=(e,t)=>{for(const a of e)if(t(a))return a},e.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&isFinite(e)&&Math.floor(e)===e,e.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},e.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t}(e||(e={})),function(e){e.mergeShapes=(e,t)=>({...e,...t})}(t||(t={}));const a=e.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),s=e=>{switch(typeof e){case"undefined":return a.undefined;case"string":return a.string;case"number":return isNaN(e)?a.nan:a.number;case"boolean":return a.boolean;case"function":return a.function;case"bigint":return a.bigint;case"symbol":return a.symbol;case"object":return Array.isArray(e)?a.array:null===e?a.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?a.promise:"undefined"!=typeof Map&&e instanceof Map?a.map:"undefined"!=typeof Set&&e instanceof Set?a.set:"undefined"!=typeof Date&&e instanceof Date?a.date:a.object;default:return a.unknown}},n=e.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class r extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},a={_errors:[]},s=e=>{for(const n of e.issues)if("invalid_union"===n.code)n.unionErrors.map(s);else if("invalid_return_type"===n.code)s(n.returnTypeError);else if("invalid_arguments"===n.code)s(n.argumentsError);else if(0===n.path.length)a._errors.push(t(n));else{let e=a,s=0;for(;s<n.path.length;){const a=n.path[s];s===n.path.length-1?(e[a]=e[a]||{_errors:[]},e[a]._errors.push(t(n))):e[a]=e[a]||{_errors:[]},e=e[a],s++}}};return s(this),a}static assert(e){if(!(e instanceof r))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,e.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},a=[];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))):a.push(e(s));return{formErrors:a,fieldErrors:t}}get formErrors(){return this.flatten()}}r.create=e=>new r(e);const i=(t,s)=>{let r;switch(t.code){case n.invalid_type:r=t.received===a.undefined?"Required":`Expected ${t.expected}, received ${t.received}`;break;case n.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(t.expected,e.jsonStringifyReplacer)}`;break;case n.unrecognized_keys:r=`Unrecognized key(s) in object: ${e.joinValues(t.keys,", ")}`;break;case n.invalid_union:r="Invalid input";break;case n.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${e.joinValues(t.options)}`;break;case n.invalid_enum_value:r=`Invalid enum value. Expected ${e.joinValues(t.options)}, received '${t.received}'`;break;case n.invalid_arguments:r="Invalid function arguments";break;case n.invalid_return_type:r="Invalid function return type";break;case n.invalid_date:r="Invalid date";break;case n.invalid_string:"object"==typeof t.validation?"includes"in t.validation?(r=`Invalid input: must include "${t.validation.includes}"`,"number"==typeof t.validation.position&&(r=`${r} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?r=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?r=`Invalid input: must end with "${t.validation.endsWith}"`:e.assertNever(t.validation):r="regex"!==t.validation?`Invalid ${t.validation}`:"Invalid";break;case n.too_small:r="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:"number"===t.type?`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:"date"===t.type?`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:"Invalid input";break;case n.too_big:r="array"===t.type?`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:"string"===t.type?`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:"number"===t.type?`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"bigint"===t.type?`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:"date"===t.type?`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:"Invalid input";break;case n.custom:r="Invalid input";break;case n.invalid_intersection_types:r="Intersection results could not be merged";break;case n.not_multiple_of:r=`Number must be a multiple of ${t.multipleOf}`;break;case n.not_finite:r="Number must be finite";break;default:r=s.defaultError,e.assertNever(t)}return{message:r}};let o=i;function d(){return o}const c=e=>{const{data:t,path:a,errorMaps:s,issueData:n}=e,r=[...a,...n.path||[]],i={...n,path:r};if(void 0!==n.message)return{...n,path:r,message:n.message};let o="";const d=s.filter(e=>!!e).slice().reverse();for(const e of d)o=e(i,{data:t,defaultError:o}).message;return{...n,path:r,message:o}};function u(e,t){const a=d(),s=c({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,a,a===i?void 0:i].filter(e=>!!e)});e.common.issues.push(s)}class l{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const a=[];for(const s of t){if("aborted"===s.status)return h;"dirty"===s.status&&e.dirty(),a.push(s.value)}return{status:e.value,value:a}}static async mergeObjectAsync(e,t){const a=[];for(const e of t){const t=await e.key,s=await e.value;a.push({key:t,value:s})}return l.mergeObjectSync(e,a)}static mergeObjectSync(e,t){const a={};for(const s of t){const{key:t,value:n}=s;if("aborted"===t.status)return h;if("aborted"===n.status)return h;"dirty"===t.status&&e.dirty(),"dirty"===n.status&&e.dirty(),"__proto__"===t.value||void 0===n.value&&!s.alwaysSet||(a[t.value]=n.value)}return{status:e.value,value:a}}}const h=Object.freeze({status:"aborted"}),p=e=>({status:"dirty",value:e}),m=e=>({status:"valid",value:e}),f=e=>"aborted"===e.status,y=e=>"dirty"===e.status,_=e=>"valid"===e.status,v=e=>"undefined"!=typeof Promise&&e instanceof Promise;function g(e,t,a,s){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}function b(e,t,a,s,n){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,a),a}var k,x,w;"function"==typeof SuppressedError&&SuppressedError,function(e){e.errToObj=e=>"string"==typeof e?{message:e}:e||{},e.toString=e=>"string"==typeof e?e:null==e?void 0:e.message}(k||(k={}));class Z{constructor(e,t,a,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=a,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 T=(e,t)=>{if(_(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new r(e.common.issues);return this._error=t,this._error}}};function O(e){if(!e)return{};const{errorMap:t,invalid_type_error:a,required_error:s,description:n}=e;if(t&&(a||s))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');if(t)return{errorMap:t,description:n};return{errorMap:(t,n)=>{var r,i;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:n.defaultError}:void 0===n.data?{message:null!==(r=null!=o?o:s)&&void 0!==r?r:n.defaultError}:"invalid_type"!==t.code?{message:n.defaultError}:{message:null!==(i=null!=o?o:a)&&void 0!==i?i:n.defaultError}},description:n}}class j{get description(){return this._def.description}_getType(e){return s(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:s(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new l,ctx:{common:e.parent.common,data:e.data,parsedType:s(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(v(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 a=this.safeParse(e,t);if(a.success)return a.data;throw a.error}safeParse(e,t){var a;const n={common:{issues:[],async:null!==(a=null==t?void 0:t.async)&&void 0!==a&&a,contextualErrorMap:null==t?void 0:t.errorMap},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:s(e)},r=this._parseSync({data:e,path:n.path,parent:n});return T(n,r)}"~validate"(e){var t,a;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:s(e)};if(!this["~standard"].async)try{const t=this._parseSync({data:e,path:[],parent:n});return _(t)?{value:t.value}:{issues:n.common.issues}}catch(e){(null===(a=null===(t=null==e?void 0:e.message)||void 0===t?void 0:t.toLowerCase())||void 0===a?void 0:a.includes("encountered"))&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(e=>_(e)?{value:e.value}:{issues:n.common.issues})}async parseAsync(e,t){const a=await this.safeParseAsync(e,t);if(a.success)return a.data;throw a.error}async safeParseAsync(e,t){const a={common:{issues:[],contextualErrorMap:null==t?void 0:t.errorMap,async:!0},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:s(e)},n=this._parse({data:e,path:a.path,parent:a}),r=await(v(n)?n:Promise.resolve(n));return T(a,r)}refine(e,t){const a=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement((t,s)=>{const r=e(t),i=()=>s.addIssue({code:n.custom,...a(t)});return"undefined"!=typeof Promise&&r instanceof Promise?r.then(e=>!!e||(i(),!1)):!!r||(i(),!1)})}refinement(e,t){return this._refinement((a,s)=>!!e(a)||(s.addIssue("function"==typeof t?t(a,s):t),!1))}_refinement(e){return new Ae({schema:this,typeName:Ve.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return Se.create(this,this._def)}nullable(){return Ee.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ue.create(this)}promise(){return Ce.create(this,this._def)}or(e){return pe.create([this,e],this._def)}and(e){return _e.create(this,e,this._def)}transform(e){return new Ae({...O(this._def),schema:this,typeName:Ve.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new Ne({...O(this._def),innerType:this,defaultValue:t,typeName:Ve.ZodDefault})}brand(){return new $e({typeName:Ve.ZodBranded,type:this,...O(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new Ie({...O(this._def),innerType:this,catchValue:t,typeName:Ve.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return Me.create(this,e)}readonly(){return Fe.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const C=/^c[^\s-]{8,}$/i,A=/^[0-9a-z]+$/,S=/^[0-9A-HJKMNP-TV-Z]{26}$/i,E=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,N=/^[a-z0-9_-]{21}$/i,I=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,R=/^[-+]?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)?)??$/,P=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;let $;const M=/^(?:(?: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])$/,F=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,L=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,D=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,z=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,V=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,U="((\\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])))",q=new RegExp(`^${U}$`);function K(e){let t="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`),t}function B(e){return new RegExp(`^${K(e)}$`)}function W(e){let t=`${U}T${K(e)}`;const a=[];return a.push(e.local?"Z?":"Z"),e.offset&&a.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${a.join("|")})`,new RegExp(`^${t}$`)}function J(e,t){return!("v4"!==t&&t||!M.test(e))||!("v6"!==t&&t||!L.test(e))}function H(e,t){if(!I.test(e))return!1;try{const[a]=e.split("."),s=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),n=JSON.parse(atob(s));return"object"==typeof n&&null!==n&&(!(!n.typ||!n.alg)&&(!t||n.alg===t))}catch(e){return!1}}function Y(e,t){return!("v4"!==t&&t||!F.test(e))||!("v6"!==t&&t||!D.test(e))}class G extends j{_parse(t){this._def.coerce&&(t.data=String(t.data));if(this._getType(t)!==a.string){const e=this._getOrReturnCtx(t);return u(e,{code:n.invalid_type,expected:a.string,received:e.parsedType}),h}const s=new l;let r;for(const a of this._def.checks)if("min"===a.kind)t.data.length<a.value&&(r=this._getOrReturnCtx(t,r),u(r,{code:n.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if("max"===a.kind)t.data.length>a.value&&(r=this._getOrReturnCtx(t,r),u(r,{code:n.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),s.dirty());else if("length"===a.kind){const e=t.data.length>a.value,i=t.data.length<a.value;(e||i)&&(r=this._getOrReturnCtx(t,r),e?u(r,{code:n.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):i&&u(r,{code:n.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),s.dirty())}else if("email"===a.kind)P.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"email",code:n.invalid_string,message:a.message}),s.dirty());else if("emoji"===a.kind)$||($=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),$.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"emoji",code:n.invalid_string,message:a.message}),s.dirty());else if("uuid"===a.kind)E.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"uuid",code:n.invalid_string,message:a.message}),s.dirty());else if("nanoid"===a.kind)N.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"nanoid",code:n.invalid_string,message:a.message}),s.dirty());else if("cuid"===a.kind)C.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"cuid",code:n.invalid_string,message:a.message}),s.dirty());else if("cuid2"===a.kind)A.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"cuid2",code:n.invalid_string,message:a.message}),s.dirty());else if("ulid"===a.kind)S.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"ulid",code:n.invalid_string,message:a.message}),s.dirty());else if("url"===a.kind)try{new URL(t.data)}catch(e){r=this._getOrReturnCtx(t,r),u(r,{validation:"url",code:n.invalid_string,message:a.message}),s.dirty()}else if("regex"===a.kind){a.regex.lastIndex=0;a.regex.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"regex",code:n.invalid_string,message:a.message}),s.dirty())}else if("trim"===a.kind)t.data=t.data.trim();else if("includes"===a.kind)t.data.includes(a.value,a.position)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),s.dirty());else if("toLowerCase"===a.kind)t.data=t.data.toLowerCase();else if("toUpperCase"===a.kind)t.data=t.data.toUpperCase();else if("startsWith"===a.kind)t.data.startsWith(a.value)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:{startsWith:a.value},message:a.message}),s.dirty());else if("endsWith"===a.kind)t.data.endsWith(a.value)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:{endsWith:a.value},message:a.message}),s.dirty());else if("datetime"===a.kind){W(a).test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:"datetime",message:a.message}),s.dirty())}else if("date"===a.kind){q.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:"date",message:a.message}),s.dirty())}else if("time"===a.kind){B(a).test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{code:n.invalid_string,validation:"time",message:a.message}),s.dirty())}else"duration"===a.kind?R.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"duration",code:n.invalid_string,message:a.message}),s.dirty()):"ip"===a.kind?J(t.data,a.version)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"ip",code:n.invalid_string,message:a.message}),s.dirty()):"jwt"===a.kind?H(t.data,a.alg)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"jwt",code:n.invalid_string,message:a.message}),s.dirty()):"cidr"===a.kind?Y(t.data,a.version)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"cidr",code:n.invalid_string,message:a.message}),s.dirty()):"base64"===a.kind?z.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"base64",code:n.invalid_string,message:a.message}),s.dirty()):"base64url"===a.kind?V.test(t.data)||(r=this._getOrReturnCtx(t,r),u(r,{validation:"base64url",code:n.invalid_string,message:a.message}),s.dirty()):e.assertNever(a);return{status:s.value,value:t.data}}_regex(e,t,a){return this.refinement(t=>e.test(t),{validation:t,code:n.invalid_string,...k.errToObj(a)})}_addCheck(e){return new G({...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)})}base64url(e){return this._addCheck({kind:"base64url",...k.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...k.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...k.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...k.errToObj(e)})}datetime(e){var t,a;return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,offset:null!==(t=null==e?void 0:e.offset)&&void 0!==t&&t,local:null!==(a=null==e?void 0:e.local)&&void 0!==a&&a,...k.errToObj(null==e?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,...k.errToObj(null==e?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:null==t?void 0:t.position,...k.errToObj(null==t?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 G({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new G({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new G({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}function Q(e,t){const a=(e.toString().split(".")[1]||"").length,s=(t.toString().split(".")[1]||"").length,n=a>s?a:s;return parseInt(e.toFixed(n).replace(".",""))%parseInt(t.toFixed(n).replace(".",""))/Math.pow(10,n)}G.create=e=>{var t;return new G({checks:[],typeName:Ve.ZodString,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...O(e)})};class X extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){this._def.coerce&&(t.data=Number(t.data));if(this._getType(t)!==a.number){const e=this._getOrReturnCtx(t);return u(e,{code:n.invalid_type,expected:a.number,received:e.parsedType}),h}let s;const r=new l;for(const a of this._def.checks)if("int"===a.kind)e.isInteger(t.data)||(s=this._getOrReturnCtx(t,s),u(s,{code:n.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty());else if("min"===a.kind){(a.inclusive?t.data<a.value:t.data<=a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty())}else if("max"===a.kind){(a.inclusive?t.data>a.value:t.data>=a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty())}else"multipleOf"===a.kind?0!==Q(t.data,a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):"finite"===a.kind?Number.isFinite(t.data)||(s=this._getOrReturnCtx(t,s),u(s,{code:n.not_finite,message:a.message}),r.dirty()):e.assertNever(a);return{status:r.value,value:t.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,a,s){return new X({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:a,message:k.toString(s)}]})}_addCheck(e){return new X({...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)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(t=>"int"===t.kind||"multipleOf"===t.kind&&e.isInteger(t.value))}get isFinite(){let e=null,t=null;for(const a of this._def.checks){if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;"min"===a.kind?(null===t||a.value>t)&&(t=a.value):"max"===a.kind&&(null===e||a.value<e)&&(e=a.value)}return Number.isFinite(t)&&Number.isFinite(e)}}X.create=e=>new X({checks:[],typeName:Ve.ZodNumber,coerce:(null==e?void 0:e.coerce)||!1,...O(e)});class ee extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch(e){return this._getInvalidInput(t)}if(this._getType(t)!==a.bigint)return this._getInvalidInput(t);let s;const r=new l;for(const a of this._def.checks)if("min"===a.kind){(a.inclusive?t.data<a.value:t.data<=a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty())}else if("max"===a.kind){(a.inclusive?t.data>a.value:t.data>=a.value)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty())}else"multipleOf"===a.kind?t.data%a.value!==BigInt(0)&&(s=this._getOrReturnCtx(t,s),u(s,{code:n.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):e.assertNever(a);return{status:r.value,value:t.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.bigint,received:t.parsedType}),h}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,a,s){return new ee({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:a,message:k.toString(s)}]})}_addCheck(e){return new ee({...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)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}ee.create=e=>{var t;return new ee({checks:[],typeName:Ve.ZodBigInt,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...O(e)})};class te extends j{_parse(e){this._def.coerce&&(e.data=Boolean(e.data));if(this._getType(e)!==a.boolean){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.boolean,received:t.parsedType}),h}return m(e.data)}}te.create=e=>new te({typeName:Ve.ZodBoolean,coerce:(null==e?void 0:e.coerce)||!1,...O(e)});class ae extends j{_parse(t){this._def.coerce&&(t.data=new Date(t.data));if(this._getType(t)!==a.date){const e=this._getOrReturnCtx(t);return u(e,{code:n.invalid_type,expected:a.date,received:e.parsedType}),h}if(isNaN(t.data.getTime())){return u(this._getOrReturnCtx(t),{code:n.invalid_date}),h}const s=new l;let r;for(const a of this._def.checks)"min"===a.kind?t.data.getTime()<a.value&&(r=this._getOrReturnCtx(t,r),u(r,{code:n.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),s.dirty()):"max"===a.kind?t.data.getTime()>a.value&&(r=this._getOrReturnCtx(t,r),u(r,{code:n.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),s.dirty()):e.assertNever(a);return{status:s.value,value:new Date(t.data.getTime())}}_addCheck(e){return new ae({...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)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}ae.create=e=>new ae({checks:[],coerce:(null==e?void 0:e.coerce)||!1,typeName:Ve.ZodDate,...O(e)});class se extends j{_parse(e){if(this._getType(e)!==a.symbol){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.symbol,received:t.parsedType}),h}return m(e.data)}}se.create=e=>new se({typeName:Ve.ZodSymbol,...O(e)});class ne extends j{_parse(e){if(this._getType(e)!==a.undefined){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.undefined,received:t.parsedType}),h}return m(e.data)}}ne.create=e=>new ne({typeName:Ve.ZodUndefined,...O(e)});class re extends j{_parse(e){if(this._getType(e)!==a.null){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.null,received:t.parsedType}),h}return m(e.data)}}re.create=e=>new re({typeName:Ve.ZodNull,...O(e)});class ie extends j{constructor(){super(...arguments),this._any=!0}_parse(e){return m(e.data)}}ie.create=e=>new ie({typeName:Ve.ZodAny,...O(e)});class oe extends j{constructor(){super(...arguments),this._unknown=!0}_parse(e){return m(e.data)}}oe.create=e=>new oe({typeName:Ve.ZodUnknown,...O(e)});class de extends j{_parse(e){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.never,received:t.parsedType}),h}}de.create=e=>new de({typeName:Ve.ZodNever,...O(e)});class ce extends j{_parse(e){if(this._getType(e)!==a.undefined){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.void,received:t.parsedType}),h}return m(e.data)}}ce.create=e=>new ce({typeName:Ve.ZodVoid,...O(e)});class ue extends j{_parse(e){const{ctx:t,status:s}=this._processInputParams(e),r=this._def;if(t.parsedType!==a.array)return u(t,{code:n.invalid_type,expected:a.array,received:t.parsedType}),h;if(null!==r.exactLength){const e=t.data.length>r.exactLength.value,a=t.data.length<r.exactLength.value;(e||a)&&(u(t,{code:e?n.too_big:n.too_small,minimum:a?r.exactLength.value:void 0,maximum:e?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),s.dirty())}if(null!==r.minLength&&t.data.length<r.minLength.value&&(u(t,{code:n.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),s.dirty()),null!==r.maxLength&&t.data.length>r.maxLength.value&&(u(t,{code:n.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),s.dirty()),t.common.async)return Promise.all([...t.data].map((e,a)=>r.type._parseAsync(new Z(t,e,t.path,a)))).then(e=>l.mergeArray(s,e));const i=[...t.data].map((e,a)=>r.type._parseSync(new Z(t,e,t.path,a)));return l.mergeArray(s,i)}get element(){return this._def.type}min(e,t){return new ue({...this._def,minLength:{value:e,message:k.toString(t)}})}max(e,t){return new ue({...this._def,maxLength:{value:e,message:k.toString(t)}})}length(e,t){return new ue({...this._def,exactLength:{value:e,message:k.toString(t)}})}nonempty(e){return this.min(1,e)}}function le(e){if(e instanceof he){const t={};for(const a in e.shape){const s=e.shape[a];t[a]=Se.create(le(s))}return new he({...e._def,shape:()=>t})}return e instanceof ue?new ue({...e._def,type:le(e.element)}):e instanceof Se?Se.create(le(e.unwrap())):e instanceof Ee?Ee.create(le(e.unwrap())):e instanceof ve?ve.create(e.items.map(e=>le(e))):e}ue.create=(e,t)=>new ue({type:e,minLength:null,maxLength:null,exactLength:null,typeName:Ve.ZodArray,...O(t)});class he extends j{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const t=this._def.shape(),a=e.objectKeys(t);return this._cached={shape:t,keys:a}}_parse(e){if(this._getType(e)!==a.object){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.object,received:t.parsedType}),h}const{status:t,ctx:s}=this._processInputParams(e),{shape:r,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof de&&"strip"===this._def.unknownKeys))for(const e in s.data)i.includes(e)||o.push(e);const d=[];for(const e of i){const t=r[e],a=s.data[e];d.push({key:{status:"valid",value:e},value:t._parse(new Z(s,a,s.path,e)),alwaysSet:e in s.data})}if(this._def.catchall instanceof de){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of o)d.push({key:{status:"valid",value:e},value:{status:"valid",value:s.data[e]}});else if("strict"===e)o.length>0&&(u(s,{code:n.unrecognized_keys,keys:o}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of o){const a=s.data[t];d.push({key:{status:"valid",value:t},value:e._parse(new Z(s,a,s.path,t)),alwaysSet:t in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const e=[];for(const t of d){const a=await t.key,s=await t.value;e.push({key:a,value:s,alwaysSet:t.alwaysSet})}return e}).then(e=>l.mergeObjectSync(t,e)):l.mergeObjectSync(t,d)}get shape(){return this._def.shape()}strict(e){return k.errToObj,new he({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,a)=>{var s,n,r,i;const o=null!==(r=null===(n=(s=this._def).errorMap)||void 0===n?void 0:n.call(s,t,a).message)&&void 0!==r?r:a.defaultError;return"unrecognized_keys"===t.code?{message:null!==(i=k.errToObj(e).message)&&void 0!==i?i:o}:{message:o}}}:{}})}strip(){return new he({...this._def,unknownKeys:"strip"})}passthrough(){return new he({...this._def,unknownKeys:"passthrough"})}extend(e){return new he({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new he({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:Ve.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new he({...this._def,catchall:e})}pick(t){const a={};return e.objectKeys(t).forEach(e=>{t[e]&&this.shape[e]&&(a[e]=this.shape[e])}),new he({...this._def,shape:()=>a})}omit(t){const a={};return e.objectKeys(this.shape).forEach(e=>{t[e]||(a[e]=this.shape[e])}),new he({...this._def,shape:()=>a})}deepPartial(){return le(this)}partial(t){const a={};return e.objectKeys(this.shape).forEach(e=>{const s=this.shape[e];t&&!t[e]?a[e]=s:a[e]=s.optional()}),new he({...this._def,shape:()=>a})}required(t){const a={};return e.objectKeys(this.shape).forEach(e=>{if(t&&!t[e])a[e]=this.shape[e];else{let t=this.shape[e];for(;t instanceof Se;)t=t._def.innerType;a[e]=t}}),new he({...this._def,shape:()=>a})}keyof(){return Te(e.objectKeys(this.shape))}}he.create=(e,t)=>new he({shape:()=>e,unknownKeys:"strip",catchall:de.create(),typeName:Ve.ZodObject,...O(t)}),he.strictCreate=(e,t)=>new he({shape:()=>e,unknownKeys:"strict",catchall:de.create(),typeName:Ve.ZodObject,...O(t)}),he.lazycreate=(e,t)=>new he({shape:e,unknownKeys:"strip",catchall:de.create(),typeName:Ve.ZodObject,...O(t)});class pe extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a=this._def.options;if(t.common.async)return Promise.all(a.map(async e=>{const a={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:a}),ctx:a}})).then(function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const a of e)if("dirty"===a.result.status)return t.common.issues.push(...a.ctx.common.issues),a.result;const a=e.map(e=>new r(e.ctx.common.issues));return u(t,{code:n.invalid_union,unionErrors:a}),h});{let e;const s=[];for(const n of a){const a={...t,common:{...t.common,issues:[]},parent:null},r=n._parseSync({data:t.data,path:t.path,parent:a});if("valid"===r.status)return r;"dirty"!==r.status||e||(e={result:r,ctx:a}),a.common.issues.length&&s.push(a.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const i=s.map(e=>new r(e));return u(t,{code:n.invalid_union,unionErrors:i}),h}}get options(){return this._def.options}}pe.create=(e,t)=>new pe({options:e,typeName:Ve.ZodUnion,...O(t)});const me=t=>t instanceof we?me(t.schema):t instanceof Ae?me(t.innerType()):t instanceof Ze?[t.value]:t instanceof Oe?t.options:t instanceof je?e.objectValues(t.enum):t instanceof Ne?me(t._def.innerType):t instanceof ne?[void 0]:t instanceof re?[null]:t instanceof Se?[void 0,...me(t.unwrap())]:t instanceof Ee?[null,...me(t.unwrap())]:t instanceof $e||t instanceof Fe?me(t.unwrap()):t instanceof Ie?me(t._def.innerType):[];class fe extends j{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==a.object)return u(t,{code:n.invalid_type,expected:a.object,received:t.parsedType}),h;const s=this.discriminator,r=t.data[s],i=this.optionsMap.get(r);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(u(t,{code:n.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),h)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,a){const s=new Map;for(const a of t){const t=me(a.shape[e]);if(!t.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const n of t){if(s.has(n))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(n)}`);s.set(n,a)}}return new fe({typeName:Ve.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...O(a)})}}function ye(t,n){const r=s(t),i=s(n);if(t===n)return{valid:!0,data:t};if(r===a.object&&i===a.object){const a=e.objectKeys(n),s=e.objectKeys(t).filter(e=>-1!==a.indexOf(e)),r={...t,...n};for(const e of s){const a=ye(t[e],n[e]);if(!a.valid)return{valid:!1};r[e]=a.data}return{valid:!0,data:r}}if(r===a.array&&i===a.array){if(t.length!==n.length)return{valid:!1};const e=[];for(let a=0;a<t.length;a++){const s=ye(t[a],n[a]);if(!s.valid)return{valid:!1};e.push(s.data)}return{valid:!0,data:e}}return r===a.date&&i===a.date&&+t===+n?{valid:!0,data:t}:{valid:!1}}class _e extends j{_parse(e){const{status:t,ctx:a}=this._processInputParams(e),s=(e,s)=>{if(f(e)||f(s))return h;const r=ye(e.value,s.value);return r.valid?((y(e)||y(s))&&t.dirty(),{status:t.value,value:r.data}):(u(a,{code:n.invalid_intersection_types}),h)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then(([e,t])=>s(e,t)):s(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}}_e.create=(e,t,a)=>new _e({left:e,right:t,typeName:Ve.ZodIntersection,...O(a)});class ve extends j{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==a.array)return u(s,{code:n.invalid_type,expected:a.array,received:s.parsedType}),h;if(s.data.length<this._def.items.length)return u(s,{code:n.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),h;!this._def.rest&&s.data.length>this._def.items.length&&(u(s,{code:n.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const r=[...s.data].map((e,t)=>{const a=this._def.items[t]||this._def.rest;return a?a._parse(new Z(s,e,s.path,t)):null}).filter(e=>!!e);return s.common.async?Promise.all(r).then(e=>l.mergeArray(t,e)):l.mergeArray(t,r)}get items(){return this._def.items}rest(e){return new ve({...this._def,rest:e})}}ve.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ve({items:e,typeName:Ve.ZodTuple,rest:null,...O(t)})};class ge extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==a.object)return u(s,{code:n.invalid_type,expected:a.object,received:s.parsedType}),h;const r=[],i=this._def.keyType,o=this._def.valueType;for(const e in s.data)r.push({key:i._parse(new Z(s,e,s.path,e)),value:o._parse(new Z(s,s.data[e],s.path,e)),alwaysSet:e in s.data});return s.common.async?l.mergeObjectAsync(t,r):l.mergeObjectSync(t,r)}get element(){return this._def.valueType}static create(e,t,a){return new ge(t instanceof j?{keyType:e,valueType:t,typeName:Ve.ZodRecord,...O(a)}:{keyType:G.create(),valueType:e,typeName:Ve.ZodRecord,...O(t)})}}class be extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==a.map)return u(s,{code:n.invalid_type,expected:a.map,received:s.parsedType}),h;const r=this._def.keyType,i=this._def.valueType,o=[...s.data.entries()].map(([e,t],a)=>({key:r._parse(new Z(s,e,s.path,[a,"key"])),value:i._parse(new Z(s,t,s.path,[a,"value"]))}));if(s.common.async){const e=new Map;return Promise.resolve().then(async()=>{for(const a of o){const s=await a.key,n=await a.value;if("aborted"===s.status||"aborted"===n.status)return h;"dirty"!==s.status&&"dirty"!==n.status||t.dirty(),e.set(s.value,n.value)}return{status:t.value,value:e}})}{const e=new Map;for(const a of o){const s=a.key,n=a.value;if("aborted"===s.status||"aborted"===n.status)return h;"dirty"!==s.status&&"dirty"!==n.status||t.dirty(),e.set(s.value,n.value)}return{status:t.value,value:e}}}}be.create=(e,t,a)=>new be({valueType:t,keyType:e,typeName:Ve.ZodMap,...O(a)});class ke extends j{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==a.set)return u(s,{code:n.invalid_type,expected:a.set,received:s.parsedType}),h;const r=this._def;null!==r.minSize&&s.data.size<r.minSize.value&&(u(s,{code:n.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),t.dirty()),null!==r.maxSize&&s.data.size>r.maxSize.value&&(u(s,{code:n.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),t.dirty());const i=this._def.valueType;function o(e){const a=new Set;for(const s of e){if("aborted"===s.status)return h;"dirty"===s.status&&t.dirty(),a.add(s.value)}return{status:t.value,value:a}}const d=[...s.data.values()].map((e,t)=>i._parse(new Z(s,e,s.path,t)));return s.common.async?Promise.all(d).then(e=>o(e)):o(d)}min(e,t){return new ke({...this._def,minSize:{value:e,message:k.toString(t)}})}max(e,t){return new ke({...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)}}ke.create=(e,t)=>new ke({valueType:e,minSize:null,maxSize:null,typeName:Ve.ZodSet,...O(t)});class xe extends j{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==a.function)return u(t,{code:n.invalid_type,expected:a.function,received:t.parsedType}),h;function s(e,a){return c({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,d(),i].filter(e=>!!e),issueData:{code:n.invalid_arguments,argumentsError:a}})}function o(e,a){return c({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,d(),i].filter(e=>!!e),issueData:{code:n.invalid_return_type,returnTypeError:a}})}const l={errorMap:t.common.contextualErrorMap},p=t.data;if(this._def.returns instanceof Ce){const e=this;return m(async function(...t){const a=new r([]),n=await e._def.args.parseAsync(t,l).catch(e=>{throw a.addIssue(s(t,e)),a}),i=await Reflect.apply(p,this,n);return await e._def.returns._def.type.parseAsync(i,l).catch(e=>{throw a.addIssue(o(i,e)),a})})}{const e=this;return m(function(...t){const a=e._def.args.safeParse(t,l);if(!a.success)throw new r([s(t,a.error)]);const n=Reflect.apply(p,this,a.data),i=e._def.returns.safeParse(n,l);if(!i.success)throw new r([o(n,i.error)]);return i.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new xe({...this._def,args:ve.create(e).rest(oe.create())})}returns(e){return new xe({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,a){return new xe({args:e||ve.create([]).rest(oe.create()),returns:t||oe.create(),typeName:Ve.ZodFunction,...O(a)})}}class we extends j{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})}}we.create=(e,t)=>new we({getter:e,typeName:Ve.ZodLazy,...O(t)});class Ze extends j{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return u(t,{received:t.data,code:n.invalid_literal,expected:this._def.value}),h}return{status:"valid",value:e.data}}get value(){return this._def.value}}function Te(e,t){return new Oe({values:e,typeName:Ve.ZodEnum,...O(t)})}Ze.create=(e,t)=>new Ze({value:e,typeName:Ve.ZodLiteral,...O(t)});class Oe extends j{constructor(){super(...arguments),x.set(this,void 0)}_parse(t){if("string"!=typeof t.data){const a=this._getOrReturnCtx(t),s=this._def.values;return u(a,{expected:e.joinValues(s),received:a.parsedType,code:n.invalid_type}),h}if(g(this,x)||b(this,x,new Set(this._def.values)),!g(this,x).has(t.data)){const e=this._getOrReturnCtx(t),a=this._def.values;return u(e,{received:e.data,code:n.invalid_enum_value,options:a}),h}return m(t.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 Oe.create(e,{...this._def,...t})}exclude(e,t=this._def){return Oe.create(this.options.filter(t=>!e.includes(t)),{...this._def,...t})}}x=new WeakMap,Oe.create=Te;class je extends j{constructor(){super(...arguments),w.set(this,void 0)}_parse(t){const s=e.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==a.string&&r.parsedType!==a.number){const t=e.objectValues(s);return u(r,{expected:e.joinValues(t),received:r.parsedType,code:n.invalid_type}),h}if(g(this,w)||b(this,w,new Set(e.getValidEnumValues(this._def.values))),!g(this,w).has(t.data)){const t=e.objectValues(s);return u(r,{received:r.data,code:n.invalid_enum_value,options:t}),h}return m(t.data)}get enum(){return this._def.values}}w=new WeakMap,je.create=(e,t)=>new je({values:e,typeName:Ve.ZodNativeEnum,...O(t)});class Ce extends j{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==a.promise&&!1===t.common.async)return u(t,{code:n.invalid_type,expected:a.promise,received:t.parsedType}),h;const s=t.parsedType===a.promise?t.data:Promise.resolve(t.data);return m(s.then(e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Ce.create=(e,t)=>new Ce({type:e,typeName:Ve.ZodPromise,...O(t)});class Ae extends j{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Ve.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:a,ctx:s}=this._processInputParams(t),n=this._def.effect||null,r={addIssue:e=>{u(s,e),e.fatal?a.abort():a.dirty()},get path(){return s.path}};if(r.addIssue=r.addIssue.bind(r),"preprocess"===n.type){const e=n.transform(s.data,r);if(s.common.async)return Promise.resolve(e).then(async e=>{if("aborted"===a.value)return h;const t=await this._def.schema._parseAsync({data:e,path:s.path,parent:s});return"aborted"===t.status?h:"dirty"===t.status||"dirty"===a.value?p(t.value):t});{if("aborted"===a.value)return h;const t=this._def.schema._parseSync({data:e,path:s.path,parent:s});return"aborted"===t.status?h:"dirty"===t.status||"dirty"===a.value?p(t.value):t}}if("refinement"===n.type){const e=e=>{const t=n.refinement(e,r);if(s.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===s.common.async){const t=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return"aborted"===t.status?h:("dirty"===t.status&&a.dirty(),e(t.value),{status:a.value,value:t.value})}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(t=>"aborted"===t.status?h:("dirty"===t.status&&a.dirty(),e(t.value).then(()=>({status:a.value,value:t.value}))))}if("transform"===n.type){if(!1===s.common.async){const e=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!_(e))return e;const t=n.transform(e.value,r);if(t instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:a.value,value:t}}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then(e=>_(e)?Promise.resolve(n.transform(e.value,r)).then(e=>({status:a.value,value:e})):e)}e.assertNever(n)}}Ae.create=(e,t,a)=>new Ae({schema:e,typeName:Ve.ZodEffects,effect:t,...O(a)}),Ae.createWithPreprocess=(e,t,a)=>new Ae({schema:t,effect:{type:"preprocess",transform:e},typeName:Ve.ZodEffects,...O(a)});class Se extends j{_parse(e){return this._getType(e)===a.undefined?m(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Se.create=(e,t)=>new Se({innerType:e,typeName:Ve.ZodOptional,...O(t)});class Ee extends j{_parse(e){return this._getType(e)===a.null?m(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ee.create=(e,t)=>new Ee({innerType:e,typeName:Ve.ZodNullable,...O(t)});class Ne extends j{_parse(e){const{ctx:t}=this._processInputParams(e);let s=t.data;return t.parsedType===a.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Ne.create=(e,t)=>new Ne({innerType:e,typeName:Ve.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...O(t)});class Ie extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return v(s)?s.then(e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new r(a.common.issues)},input:a.data})})):{status:"valid",value:"valid"===s.status?s.value:this._def.catchValue({get error(){return new r(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}}Ie.create=(e,t)=>new Ie({innerType:e,typeName:Ve.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...O(t)});class Re extends j{_parse(e){if(this._getType(e)!==a.nan){const t=this._getOrReturnCtx(e);return u(t,{code:n.invalid_type,expected:a.nan,received:t.parsedType}),h}return{status:"valid",value:e.data}}}Re.create=e=>new Re({typeName:Ve.ZodNaN,...O(e)});const Pe=Symbol("zod_brand");class $e extends j{_parse(e){const{ctx:t}=this._processInputParams(e),a=t.data;return this._def.type._parse({data:a,path:t.path,parent:t})}unwrap(){return this._def.type}}class Me extends j{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.common.async){return(async()=>{const e=await this._def.in._parseAsync({data:a.data,path:a.path,parent:a});return"aborted"===e.status?h:"dirty"===e.status?(t.dirty(),p(e.value)):this._def.out._parseAsync({data:e.value,path:a.path,parent:a})})()}{const e=this._def.in._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===e.status?h:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:a.path,parent:a})}}static create(e,t){return new Me({in:e,out:t,typeName:Ve.ZodPipeline})}}class Fe extends j{_parse(e){const t=this._def.innerType._parse(e),a=e=>(_(e)&&(e.value=Object.freeze(e.value)),e);return v(t)?t.then(e=>a(e)):a(t)}unwrap(){return this._def.innerType}}function Le(e,t){const a="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof a?{message:a}:a}function De(e,t={},a){return e?ie.create().superRefine((s,n)=>{var r,i;const o=e(s);if(o instanceof Promise)return o.then(e=>{var r,i;if(!e){const e=Le(t,s),o=null===(i=null!==(r=e.fatal)&&void 0!==r?r:a)||void 0===i||i;n.addIssue({code:"custom",...e,fatal:o})}});if(!o){const e=Le(t,s),o=null===(i=null!==(r=e.fatal)&&void 0!==r?r:a)||void 0===i||i;n.addIssue({code:"custom",...e,fatal:o})}}):ie.create()}Fe.create=(e,t)=>new Fe({innerType:e,typeName:Ve.ZodReadonly,...O(t)});const ze={object:he.lazycreate};var Ve;!function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"}(Ve||(Ve={}));const Ue=G.create,qe=X.create,Ke=Re.create,Be=ee.create,We=te.create,Je=ae.create,He=se.create,Ye=ne.create,Ge=re.create,Qe=ie.create,Xe=oe.create,et=de.create,tt=ce.create,at=ue.create,st=he.create,nt=he.strictCreate,rt=pe.create,it=fe.create,ot=_e.create,dt=ve.create,ct=ge.create,ut=be.create,lt=ke.create,ht=xe.create,pt=we.create,mt=Ze.create,ft=Oe.create,yt=je.create,_t=Ce.create,vt=Ae.create,gt=Se.create,bt=Ee.create,kt=Ae.createWithPreprocess,xt=Me.create,wt={string:e=>G.create({...e,coerce:!0}),number:e=>X.create({...e,coerce:!0}),boolean:e=>te.create({...e,coerce:!0}),bigint:e=>ee.create({...e,coerce:!0}),date:e=>ae.create({...e,coerce:!0})},Zt=h;var Tt=Object.freeze({__proto__:null,defaultErrorMap:i,setErrorMap:function(e){o=e},getErrorMap:d,makeIssue:c,EMPTY_PATH:[],addIssueToContext:u,ParseStatus:l,INVALID:h,DIRTY:p,OK:m,isAborted:f,isDirty:y,isValid:_,isAsync:v,get util(){return e},get objectUtil(){return t},ZodParsedType:a,getParsedType:s,ZodType:j,datetimeRegex:W,ZodString:G,ZodNumber:X,ZodBigInt:ee,ZodBoolean:te,ZodDate:ae,ZodSymbol:se,ZodUndefined:ne,ZodNull:re,ZodAny:ie,ZodUnknown:oe,ZodNever:de,ZodVoid:ce,ZodArray:ue,ZodObject:he,ZodUnion:pe,ZodDiscriminatedUnion:fe,ZodIntersection:_e,ZodTuple:ve,ZodRecord:ge,ZodMap:be,ZodSet:ke,ZodFunction:xe,ZodLazy:we,ZodLiteral:Ze,ZodEnum:Oe,ZodNativeEnum:je,ZodPromise:Ce,ZodEffects:Ae,ZodTransformer:Ae,ZodOptional:Se,ZodNullable:Ee,ZodDefault:Ne,ZodCatch:Ie,ZodNaN:Re,BRAND:Pe,ZodBranded:$e,ZodPipeline:Me,ZodReadonly:Fe,custom:De,Schema:j,ZodSchema:j,late:ze,get ZodFirstPartyTypeKind(){return Ve},coerce:wt,any:Qe,array:at,bigint:Be,boolean:We,date:Je,discriminatedUnion:it,effect:vt,enum:ft,function:ht,instanceof:(e,t={message:`Input not instance of ${e.name}`})=>De(t=>t instanceof e,t),intersection:ot,lazy:pt,literal:mt,map:ut,nan:Ke,nativeEnum:yt,never:et,null:Ge,nullable:bt,number:qe,object:st,oboolean:()=>We().optional(),onumber:()=>qe().optional(),optional:gt,ostring:()=>Ue().optional(),pipeline:xt,preprocess:kt,promise:_t,record:ct,set:lt,strictObject:nt,string:Ue,symbol:He,transformer:vt,tuple:dt,undefined:Ye,union:rt,unknown:Xe,void:tt,NEVER:Zt,ZodIssueCode:n,quotelessJson:e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),ZodError:r}),Ot=["interface","display","layout","module","panel","theme"],jt=["hook","endpoint"],Ct=["operation"],At="directus:extension",St=Tt.object({app:Tt.string(),api:Tt.string()}),Et=Tt.object({request:Tt.optional(Tt.object({urls:Tt.array(Tt.string()),methods:Tt.array(Tt.union([Tt.literal("GET"),Tt.literal("POST"),Tt.literal("PATCH"),Tt.literal("PUT"),Tt.literal("DELETE")]))})),log:Tt.optional(Tt.object({})),sleep:Tt.optional(Tt.object({}))}),Nt=Tt.optional(Tt.object({enabled:Tt.boolean(),requestedScopes:Et})),It=Tt.union([Tt.object({type:Tt.enum(jt),name:Tt.string(),source:Tt.string()}),Tt.object({type:Tt.enum(Ot),name:Tt.string(),source:Tt.string()}),Tt.object({type:Tt.enum(Ct),name:Tt.string(),source:St})]),Rt=Tt.object({host:Tt.string(),hidden:Tt.boolean().optional()}),Pt=Tt.object({type:Tt.enum(Ot),path:Tt.string(),source:Tt.string()}),$t=Tt.object({type:Tt.enum(jt),path:Tt.string(),source:Tt.string(),sandbox:Nt}),Mt=Tt.object({type:Tt.enum(Ct),path:St,source:St,sandbox:Nt}),Ft=Tt.object({type:Tt.literal("bundle"),partial:Tt.boolean().optional(),path:St,entries:Tt.array(It)});Tt.array(It);var Lt=Rt.and(Tt.union([Pt,$t,Mt,Ft]));Tt.object({name:Tt.string(),version:Tt.string(),type:Tt.union([Tt.literal("module"),Tt.literal("commonjs")]).optional(),description:Tt.string().optional(),icon:Tt.string().optional(),dependencies:Tt.record(Tt.string()).optional(),devDependencies:Tt.record(Tt.string()).optional(),[At]:Lt});var Dt=(e=>(e.REQUEST="sql-query.request",e.RESPONSE="sql-query.response",e))(Dt||{});const zt=[],Vt=[{name:"insights",config:(e,{database:t,services:a,emitter:s})=>{const{PanelsService:n}=a;async function r(e,a){if(new RegExp(["delete","update","insert","execute","kill","drop"].map(e=>`\\b${e}\\b`).join("|")).test(e.toLowerCase()))throw new Error("SQL query is blacklisted");const s=e.match(/{{\w+}}/g);if(s)throw new Error(`Missing query param: ${s.join(", ").replace(/{{|}}/g,"")}`);return(e=>{let t=[],a=[];if(e&&e.rows&&e.fields)t=e.rows,a=e.fields.map(e=>e.name);else if(Array.isArray(e)){const s=e[0];if(Array.isArray(s)){const[s,n]=e;t=2===s.length&&Array.isArray(s[0])?s.at(0):s,a=(2===n.length&&Array.isArray(n[0])?n.at(0):n).map(e=>e.name)}else t=e,a=Object.keys(s)}else e.recordset&&(t=e.recordset,a=e.recordset.columns?Object.keys(e.recordset.columns):[]);return{items:t,headers:a}})(await t.raw(e,a))}e.get("/query/:panelId",async(e,t)=>{try{const{query:a,variables:i,panel:o,cache:d}=await async function(e){const t=e.params.panelId;if(!t)throw new Error("Missing panelId");const a=new n({accountability:e.accountability,schema:e.schema}),r=await a.readOne(t);let{variables:i,query:o}=await s.emitFilter(Dt.REQUEST,{variables:Object.assign({dashboard:r.dashboard},e.query??{}),query:r.options.sql},e);for(const e in i){if(!e.match(/^[a-zA-Z0-9_]+$/))throw new Error(`Invalid variable name: ${e}`);o=o.replace(new RegExp(`{{${e}}}`,"g"),`:${e}`)}return{query:o,variables:i,panel:r,cache:a.cache}}(e);let c=await r(a,i),u=Number(o.options.cache??300);u=u>0?u:300;const l=`insights:query:${o.id}:${JSON.stringify(i)}`,h=e.query.noCache;return"true"===h||"1"===h||"true"===String(h)?(c=await r(a,i),d&&await d.set(l,c,u)):c=await async function(e,t,a,s){if(!e)return await s();const n=await e.get(t);if(n)return n;const r=await s();return await e.set(t,r,a),r}(d,l,u,()=>r(a,i)),c=await s.emitFilter(Dt.RESPONSE,c,e),t.set("Cache-control",`public, max-age=${u}`),t.json(c)}catch(e){return t.status(400).json({error:e.message})}})}}],Ut=[];export{Vt as endpoints,zt as hooks,Ut as operations};
package/dist/app.js CHANGED
@@ -1 +1 @@
1
- import{useApi as e,useStores as t,definePanel as n}from"@directus/extensions-sdk";import{onMounted as a,nextTick as o,getCurrentScope as r,onScopeDispose as l,getCurrentInstance as i,computed as s,shallowRef as u,ref as c,watch as d,toValue as f,resolveComponent as v,resolveDirective as h,createElementBlock as p,openBlock as m,createElementVNode as b,normalizeProps as g,guardReactiveProps as y,unref as w,createCommentVNode as k,normalizeClass as x,createVNode as q,withCtx as S,Fragment as _,renderList as C,normalizeStyle as L,createTextVNode as T,createBlock as A,toDisplayString as j,mergeProps as R,renderSlot as $,withModifiers as E,withDirectives as O,defineComponent as z,toRefs as D,createSlots as B}from"vue";import{useRouter as N}from"vue-router";import{useI18n as W}from"vue-i18n";var H="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function I(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var P=/^\s+|\s+$/g,M=/^[-+]0x[0-9a-f]+$/i,U=/^0b[01]+$/i,V=/^0o[0-7]+$/i,G=parseInt,Q="object"==typeof H&&H&&H.Object===Object&&H,Y="object"==typeof self&&self&&self.Object===Object&&self,F=Q||Y||Function("return this")(),J=Object.prototype.toString,Z=Math.max,K=Math.min,X=function(){return F.Date.now()};function ee(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function te(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==J.call(e)}(e))return NaN;if(ee(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=ee(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(P,"");var n=U.test(e);return n||V.test(e)?G(e.slice(2),n?2:8):M.test(e)?NaN:+e}var ne=I((function(e,t,n){var a,o,r,l,i,s,u=0,c=!1,d=!1,f=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function v(t){var n=a,r=o;return a=o=void 0,u=t,l=e.apply(r,n)}function h(e){var n=e-s;return void 0===s||n>=t||n<0||d&&e-u>=r}function p(){var e=X();if(h(e))return m(e);i=setTimeout(p,function(e){var n=t-(e-s);return d?K(n,r-(e-u)):n}(e))}function m(e){return i=void 0,f&&a?v(e):(a=o=void 0,l)}function b(){var e=X(),n=h(e);if(a=arguments,o=this,s=e,n){if(void 0===i)return function(e){return u=e,i=setTimeout(p,t),c?v(e):l}(s);if(d)return i=setTimeout(p,t),v(s)}return void 0===i&&(i=setTimeout(p,t)),l}return t=te(t)||0,ee(n)&&(c=!!n.leading,r=(d="maxWait"in n)?Z(te(n.maxWait)||0,t):r,f="trailing"in n?!!n.trailing:f),b.cancel=function(){void 0!==i&&clearTimeout(i),u=0,a=s=o=i=void 0},b.flush=function(){return void 0===i?l:m(X())},b}));const ae="undefined"!=typeof window&&"undefined"!=typeof document;function oe(e,t=!0,n){i()?a(e,n):t?e():o(e)}"undefined"!=typeof WorkerGlobalScope&&(globalThis,WorkerGlobalScope);const re=ae?window:void 0;function le(e){var t;const n=f(e);return null!=(t=null==n?void 0:n.$el)?t:n}function ie(e){const t=function(){const e=u(!1),t=i();return t&&a((()=>{e.value=!0}),t),e}();return s((()=>(t.value,Boolean(e()))))}function se(e,t,n={}){const{window:a=re,...o}=n;let i;const u=ie((()=>a&&"ResizeObserver"in a)),c=()=>{i&&(i.disconnect(),i=void 0)},v=s((()=>{const t=f(e);return Array.isArray(t)?t.map((e=>le(e))):[le(t)]})),h=d(v,(e=>{if(c(),u.value&&a){i=new ResizeObserver(t);for(const t of e)t&&i.observe(t,o)}}),{immediate:!0,flush:"post"}),p=()=>{c(),h()};var m;return m=p,r()&&l(m),{isSupported:u,stop:p}}function ue(e,t={width:0,height:0},n={}){const{window:a=re,box:o="content-box"}=n,r=s((()=>{var t,n;return null==(n=null==(t=le(e))?void 0:t.namespaceURI)?void 0:n.includes("svg")})),l=u(t.width),i=u(t.height),{stop:c}=se(e,(([t])=>{const n="border-box"===o?t.borderBoxSize:"content-box"===o?t.contentBoxSize:t.devicePixelContentBoxSize;if(a&&r.value){const t=le(e);if(t){const e=t.getBoundingClientRect();l.value=e.width,i.value=e.height}}else if(n){const e=(s=n,Array.isArray(s)?s:[s]);l.value=e.reduce(((e,{inlineSize:t})=>e+t),0),i.value=e.reduce(((e,{blockSize:t})=>e+t),0)}else l.value=t.contentRect.width,i.value=t.contentRect.height;var s}),n);oe((()=>{const n=le(e);n&&(l.value="offsetWidth"in n?n.offsetWidth:t.width,i.value="offsetHeight"in n?n.offsetHeight:t.height)}));const f=d((()=>le(e)),(e=>{l.value=e?t.width:0,i.value=e?t.height:0}));return{width:l,height:i,stop:function(){c(),f()}}}function ce(e,t){const{containerStyle:n,wrapperProps:a,scrollTo:o,calculateRange:r,currentList:l,containerRef:i}="itemHeight"in t?function(e,t){const n=de(t),{state:a,source:o,currentList:r,size:l,containerRef:i}=n,u={overflowY:"auto"},{itemHeight:c,overscan:d=5}=e,f=fe(a,o,c),v=ve(o,c),h=he("vertical",d,v,f,n),p=pe(c,o),m=s((()=>p(a.value.start))),b=be(c,o);me(l,t,i,h);const g=ye("vertical",h,p,i),y=s((()=>({style:{width:"100%",height:b.value-m.value+"px",marginTop:`${m.value}px`}})));return{calculateRange:h,scrollTo:g,containerStyle:u,wrapperProps:y,currentList:r,containerRef:i}}(t,e):function(e,t){const n=de(t),{state:a,source:o,currentList:r,size:l,containerRef:i}=n,u={overflowX:"auto"},{itemWidth:c,overscan:d=5}=e,f=fe(a,o,c),v=ve(o,c),h=he("horizontal",d,v,f,n),p=pe(c,o),m=s((()=>p(a.value.start))),b=be(c,o);me(l,t,i,h);const g=ye("horizontal",h,p,i),y=s((()=>({style:{height:"100%",width:b.value-m.value+"px",marginLeft:`${m.value}px`,display:"flex"}})));return{scrollTo:g,calculateRange:h,wrapperProps:y,containerStyle:u,currentList:r,containerRef:i}}(t,e);return{list:l,scrollTo:o,containerProps:{ref:i,onScroll:()=>{r()},style:n},wrapperProps:a}}function de(e){const t=u(null),n=ue(t),a=c([]),o=u(e);return{state:c({start:0,end:10}),source:o,currentList:a,size:n,containerRef:t}}function fe(e,t,n){return a=>{if("number"==typeof n)return Math.ceil(a/n);const{start:o=0}=e.value;let r=0,l=0;for(let e=o;e<t.value.length;e++){if(r+=n(e),l=e,r>a)break}return l-o}}function ve(e,t){return n=>{if("number"==typeof t)return Math.floor(n/t)+1;let a=0,o=0;for(let r=0;r<e.value.length;r++){if(a+=t(r),a>=n){o=r;break}}return o+1}}function he(e,t,n,a,{containerRef:o,state:r,currentList:l,source:i}){return()=>{const s=o.value;if(s){const o=n("vertical"===e?s.scrollTop:s.scrollLeft),u=a("vertical"===e?s.clientHeight:s.clientWidth),c=o-t,d=o+u+t;r.value={start:c<0?0:c,end:d>i.value.length?i.value.length:d},l.value=i.value.slice(r.value.start,r.value.end).map(((e,t)=>({data:e,index:t+r.value.start})))}}}function pe(e,t){return n=>{if("number"==typeof e){return n*e}return t.value.slice(0,n).reduce(((t,n,a)=>t+e(a)),0)}}function me(e,t,n,a){d([e.width,e.height,t,n],(()=>{a()}))}function be(e,t){return s((()=>"number"==typeof e?t.value.length*e:t.value.reduce(((t,n,a)=>t+e(a)),0)))}const ge={horizontal:"scrollLeft",vertical:"scrollTop"};function ye(e,t,n,a){return o=>{a.value&&(a.value[ge[e]]=n(o),t())}}const we={sum:"Σ",avg:"μ",count:"#",count_unique:"#!"},ke={sum:(e,t)=>e.reduce(((e,n)=>e+Number.parseInt(n[t])),0),avg:(e,t)=>Math.round(ke.sum(e,t)/e.length),count:e=>e.length,count_unique:(e,t)=>new Set(e.map((e=>e[t]))).size,count_groups:(e,t)=>e.reduce(((e,n)=>{const a=n[t];return e[a]=(e[a]||0)+1,e}),{})};var xe=[],qe=[];function Se(e,t){if(e&&"undefined"!=typeof document){var n,a=!0===t.prepend?"prepend":"append",o=!0===t.singleTag,r="string"==typeof t.container?document.querySelector(t.container):document.getElementsByTagName("head")[0];if(o){var l=xe.indexOf(r);-1===l&&(l=xe.push(r)-1,qe[l]={}),n=qe[l]&&qe[l][a]?qe[l][a]:qe[l][a]=i()}else n=i();65279===e.charCodeAt(0)&&(e=e.substring(1)),n.styleSheet?n.styleSheet.cssText+=e:n.appendChild(document.createTextNode(e))}function i(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),t.attributes)for(var n=Object.keys(t.attributes),o=0;o<n.length;o++)e.setAttribute(n[o],t.attributes[n[o]]);var l="prepend"===a?"afterbegin":"beforeend";return r.insertAdjacentElement(l,e),e}}Se("\nbody {\n --v-table-color: var(--v-input-color);\n --v-table-background-color: var(--v-input-background-color);\n}\n.sql-query-table[data-v-1fe562b8] {\n position: relative;\n height: var(--v-table-height);\n overflow-y: auto;\n\n --sqt-head--background: var(--background-normal, var(--theme--background));\n --sqt-head--color: color: var(--foreground-normal, var(--theme--foreground));\n\n --sqt-foot--background: var(--background-normal, var(--theme--background));\n --sqt-foot--color: color: var(--foreground-normal, var(--theme--foreground));\n}\ntable[data-v-1fe562b8] {\n min-width: 100%;\n min-height: 100%;\n border-collapse: collapse;\n border-spacing: 0;\n background-color: var(--v-table-background-color);\n color: var(--v-table-color);\n}\ntable thead[data-v-1fe562b8] {\n background-color: var(--sqt-head--background);\n color: var(--sqt-head--color);\n border-bottom: var(--border-width) solid var(--v-input-border-color);\n}\ntable thead.fixed[data-v-1fe562b8] {\n position: sticky;\n top: 0;\n z-index: 3;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);\n}\ntable thead tr.headers th[data-v-1fe562b8] {\n padding: 8px;\n font-weight: bold;\n min-width: 3rem;\n background-color: var(--sqt-head--background);\n color: var(--sqt-head--color);\n border-bottom: var(--border-width) solid var(--v-input-border-color);\n}\ntable tr.search th[data-v-1fe562b8] {\n padding: 0;\n}\ntable tr.search th .search-input.v-input[data-v-1fe562b8] {\n margin: 0;\n border: none;\n}\ntable th .sort-icon[data-v-1fe562b8] {\n opacity: 0;\n}\ntable th:hover .sort-icon[data-v-1fe562b8] {\n opacity: 0.5;\n}\ntable th .sort-icon.show[data-v-1fe562b8] {\n opacity: 1;\n}\ntable th.select[data-v-1fe562b8] {\n width: 2rem;\n}\ntable td[data-v-1fe562b8] {\n padding: 8px;\n align: middle;\n border-bottom: var(--border-width) solid var(--v-input-border-color);\n}\ntable tr.clickable[data-v-1fe562b8]:hover {\n background-color: var(--theme--background-subdued);\n cursor: pointer\n}\ntable tr.active[data-v-1fe562b8] {\n background-color: var(--theme--background-accent);\n}\ntable tbody[data-v-1fe562b8] {\n display: contents;\n}\ntable tfoot tr[data-v-1fe562b8] {\n position: sticky;\n bottom: 0;\n background-color: var(--sqt-foot--background);\n color: var(--sqt-foot--color);\n box-shadow: var(--card-shadow);\n}\ntable tfoot tr td[data-v-1fe562b8] {\n padding: 8px;\n height: 44px;\n font-weight: bold;\n background-color: var(--sqt-foot--background);\n color: var(--sqt-foot--color);\n}\n",{});var _e=(e,t)=>{const n=e.__vccOpts||e;for(const[e,a]of t)n[e]=a;return n};const Ce={class:"sql-query-table"},Le={key:0,class:"search"},Te={colspan:"80%"},Ae={class:"headers"},je=["onClick","align"],Re={key:0},$e={key:1},Ee=["colspan"],Oe={key:0},ze={colspan:"100%"},De=["onClick"],Be={key:2},Ne={key:0,class:"v-text-overflow"},We={__name:"FastTable",props:{loading:Boolean,headers:{type:Array,validator:e=>e.every((e=>e.value&&e.text)),required:!0},items:{type:Array,required:!0},sort:String,sortDesc:Boolean,fixedHeader:Boolean,rowClickable:Boolean},emits:["update:sort","update:sortDesc","click:row"],setup(e,{emit:t}){const{t:n}=W(),a=e,o=c(""),r=s((()=>a.headers.filter((e=>e.searchable)))),l=s((()=>{console.debug(a.sort,a.sortDesc);const e=o.value?o.value.toLowerCase().trim():"";return e?a.items.filter((t=>r.value.some((n=>t[n.value]&&t[n.value].toLowerCase().includes(e))))):[...a.items]})),{list:i,containerProps:u,wrapperProps:d}=ce(l,{itemHeight:40}),f=s((()=>{const e=function(e,t){if(!t.some((e=>!!e.summarise)))return null;const n={};for(const a of t){if(!a.summarise)continue;const t=ke[a.summarise];if(!t)throw new Error(`Summariser function for ${a.summarise} not found.`);const o=t(e,a.value);if("count_groups"===a.summarise){let e=JSON.stringify(o,null,1).replace("{\n","").replace("\n}","").replace(/[",]/g,"");n[a.value]=e}else n[a.value]=`${we[a.summarise]} ${o}`}return n}(l.value,a.headers);return e})),z=t,D=c(null);return(t,l)=>{const s=v("v-icon"),c=v("v-input"),B=v("v-progress-linear"),N=v("v-card-title"),W=v("v-card"),H=h("tooltip");return m(),p("div",Ce,[b("table",g(y(w(u))),[b("thead",{class:x(["table-header",{fixed:e.fixedHeader}])},[r.value.length&&e.items.length>10?(m(),p("tr",Le,[b("th",Te,[q(c,{modelValue:o.value,"onUpdate:modelValue":l[0]||(l[0]=e=>o.value=e),small:"",trim:"",class:"search-input",rounded:"",placeholder:"Search"},{prepend:S((()=>[q(s,{name:"search"})])),_:1},8,["modelValue"])])])):k("v-if",!0),b("tr",Ae,[(m(!0),p(_,null,C(e.headers,(n=>(m(),p("th",{style:L({minWidth:`${n.width||t.auto}ch`}),key:n.value,onClick:e=>function(e){e.sortable&&(z("update:sort",e.value),z("update:sortDesc",!a.sortDesc))}(n),align:n.align||"left"},[T(j(n.text)+" ",1),n.sortable?(m(),A(s,{key:0,name:"sort",small:"",class:x(["sort-icon",{show:e.sort===n.value}]),style:L(`transform: ${e.sortDesc?"rotateZ(0deg) rotateY(0deg)":"rotateZ(180deg) rotateY(180deg)"}; transition: .2s all ease`)},null,8,["class","style"])):k("v-if",!0)],12,je)))),128)),t.$slots["item-append"]?(m(),p("th",Re,"#")):k("v-if",!0)]),e.loading?(m(),p("tr",$e,[b("td",{colspan:e.headers.length+1},[q(B,{indeterminate:""})],8,Ee)])):k("v-if",!0)],2),e.loading||e.items.length?(m(),p("tbody",g(R({key:1},w(d))),[$(t.$slots,"default",{items:w(i)},(()=>[(m(!0),p(_,null,C(w(i),(({data:n})=>(m(),p("tr",{onClick:e=>{D.value=n,z("click:row",{item:n,event:e})},class:x({clickable:e.rowClickable,active:D.value===n})},[(m(!0),p(_,null,C(e.headers,(e=>(m(),p("td",{key:e.value,class:x(`align-${e.align}`)},j(n[e.value]),3)))),128)),t.$slots["item-append"]?(m(),p("td",{key:0,onClick:l[1]||(l[1]=E((()=>{}),["stop"]))},[$(t.$slots,"item-append",{item:n},void 0,!0)])):k("v-if",!0)],10,De)))),256))]),!0),k(" This is to fill up any remaining height in the table "),l[2]||(l[2]=b("tr",null,[b("td",{style:{height:"100%"}})],-1))],16)):(m(),p("tbody",Oe,[b("tr",null,[b("td",ze,[q(W,{style:{padding:"2rem","--v-card-max-width":"100%",margin:"2rem auto"}},{default:S((()=>[q(N,null,{default:S((()=>[q(s,{name:"info",style:{"margin-right":"2rem"}}),T(" "+j(w(n)("no_items")),1)])),_:1})])),_:1})])])])),f.value?(m(),p("tfoot",Be,[b("tr",null,[(m(!0),p(_,null,C(e.headers,(e=>O((m(),p("td",{key:e.value},[f.value[e.value]?(m(),p("code",Ne,j(f.value[e.value]),1)):k("v-if",!0)])),[[H,e.summarise]]))),128))])])):k("v-if",!0)],16)])}}};var He=_e(We,[["__scopeId","data-v-1fe562b8"]]);const Ie={key:0,class:"center"},Pe={key:0};var Me=z({__name:"panel",props:{id:{},showHeader:{type:Boolean},sql:{},cache:{},columns:{},download:{type:Boolean,default:!0},is_static:{type:Boolean},actions:{}},setup(n){const a=N(),r=n,{id:l,showHeader:i,download:u,is_static:f}=D(r),b=c(!1),g=c(""),y=c(""),L=c(null),R=c(null),$=e(),{useInsightsStore:E}=t(),z=E(),W=c(new Set),H=s((()=>{const e=new Set(W.value),t=r.sql.match(/{{ \w+ }}/g);return t&&t.forEach((t=>e.add(t.replace(/{{ | }}/g,"")))),e})),I=s((()=>{const e={},t=[];return H.value.forEach((n=>{const a=z.getVariable(n);null==a?t.push(n):e[n]=a})),t.length?t:e}));if(f.value)o(Y);else{const e=ne(Y,1e3);d(I,(()=>{Array.isArray(I.value)?y.value=`Please specify: ${I.value.join(" & ")}`:(y.value="",R.value||(b.value=!0),e())}),{immediate:!0})}const P=s((()=>r.columns?.length>0?r.columns.map((e=>({...e,text:e.text||e.value}))):L.value)),M=c({by:null,desc:!1});d(M,(({by:e,desc:t})=>{e&&R.value&&(R.value=R.value.sort(((n,a)=>n[e]<a[e]?t?1:-1:n[e]>a[e]?t?-1:1:0)))}),{deep:!0});let U,V,G=!1,Q={};async function Y(){if(b.value=!1,Array.isArray(I.value))Q={};else{if(!G){let e=!H.value.size;for(const t in I.value)Q[t]!==I.value[t]&&(e=!0),Q[t]=I.value[t];if(!e)return;b.value=!0}g.value="";try{const e={};V=e;const{data:t}=await $.get(`insights/query/${l.value}`,{params:I.value});if(V!==e)return;t.error&&(g.value=t.error),G=!1,r.cache&&setTimeout((()=>{G=!0}),1e3*r.cache);const n=JSON.stringify(t);if(U===n)return void(b.value=!1);if(U=n,L.value=null,R.value=null,t.headers&&t.items){const e=t.items.length>2;L.value=t.headers.map((function(t,n){const a=t.replace(/_/g," ").replace(/(?:^|\s)\S/g,(function(e){return e.toUpperCase()}));return{text:a,value:t,width:a.length+1,sortable:e}}));const n=r.columns&&r.columns.filter((e=>e.isNumber));R.value=n?t.items.map((e=>(n.forEach((t=>{e[t.value]=""!==e[t.value]?1*e[t.value]:null})),e))):t.items}}catch(e){const t=e.response?.data?.error||e.message;t.includes("Missing query param")?(y.value=t.replace("Missing query param","Please specify"),t.split(": ")[1].split(", ").forEach((e=>W.value.add(e)))):g.value=t}b.value=!1}}const F=s((()=>r.actions?.find((e=>e.row))));function J(){const e=L.value||P.value;if(e&&R.value){let t=e.map((e=>e.text)).join(",");t+="\r\n",t+=function(){if(!R.value)return;let e="";return R.value.forEach((t=>{for(let n in t)/[, ]/.test(t[n])?e+=`"${t[n].replace(/"/g,'\\"')}",`:e+=t[n]+",";e+="\r\n"})),e}();const n=(new Date).toISOString()+".csv",a=new Blob([t],{type:"text/csv;charset=utf-8;"});if(navigator.msSaveBlob)navigator.msSaveBlob(a,n);else{const e=document.createElement("a");if(void 0!==e.download){const t=URL.createObjectURL(a);e.setAttribute("href",t),e.setAttribute("download",n),e.style.visibility="hidden",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}}}function Z({item:e}){F.value&&K(F.value,e)}function K(e,t){e.filter&&e.filter.forEach((({variable:e,value:n})=>{z.setVariable(e,n.replace(/%(\w+)%/g,((e,n)=>t[n])))})),e.link&&a.push(function(e,t){let n=e;for(let e in t)n=n.replace(new RegExp(`%${e}%`,"g"),t[e]);return n}(e.link,t))}return(e,t)=>{const n=v("v-progress-circular"),a=v("v-notice"),o=v("v-icon"),r=v("v-button"),l=h("tooltip");return m(),p("div",{class:x(["sql-panel-container",{"has-header":w(i)}])},[b.value||g.value||y.value?(m(),p("div",Ie,[b.value?(m(),A(n,{key:0,indeterminate:""})):y.value?(m(),A(a,{key:1,type:"info",center:""},{default:S((()=>[T(j(y.value),1)])),_:1})):(m(),A(a,{key:2,type:"danger",center:""},{default:S((()=>[T(j(g.value),1)])),_:1}))])):P.value&&R.value?(m(),p(_,{key:1},[w(u)?(m(),A(r,{key:0,onClick:J,icon:"",secondary:"",class:"export-csv-button"},{default:S((()=>[q(o,{name:"download-file"})])),_:1})):k("v-if",!0),q(He,{headers:P.value,items:R.value,"onClick:row":Z,sort:M.value.by,"onUpdate:sort":t[0]||(t[0]=e=>M.value.by=e),sortDesc:M.value.desc,"onUpdate:sortDesc":t[1]||(t[1]=e=>M.value.desc=e),rowClickable:!!F.value,"fixed-header":""},B({_:2},[e.actions?.find((e=>!e.row))?{name:"item-append",fn:S((({item:t})=>[(m(!0),p(_,null,C(e.actions.filter((e=>!e.row)),(e=>O((m(),A(r,{outlined:"",onClick:n=>K(e,t),icon:!e.show_label,"x-small":""},{default:S((()=>[q(o,{name:e.icon},null,8,["name"]),e.show_label?(m(),p("span",Pe,j(e.label),1)):k("v-if",!0)])),_:2},1032,["onClick","icon"])),[[l,e.label]]))),256))])),key:"0"}:void 0]),1032,["headers","items","sort","sortDesc","rowClickable"])],64)):k("v-if",!0)],2)}}});Se("\n.sql-panel-container {\n width: 100%;\n height: 100%;\n --v-table-height: 100%;\n}\n.sql-panel-container .v-text-overflow {\n user-select: text;\n white-space: pre-wrap;\n}\n.sql-panel-container .center {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n}\n.export-csv-button {\n position: absolute;\n right: 0;\n bottom: 0;\n z-index: 2;\n opacity: 0.8;\n}\n.export-csv-button .button {\n border-radius: var(--border-radius) 0 0 0 !important;\n}\n",{});const Ue=[],Ve=[],Ge=[],Qe=[],Ye=[n({id:"sql-query",name:"SQL Query panel",icon:"view_list",description:"Show result of a stored SQL query as a table",component:Me,skipUndefinedKeys:["sql"],options:[{field:"sql",name:"SQL query",type:"string",meta:{note:"Supports variables in the format of {{variable_name}}. Don't quote string variables. Example: SELECT * FROM tasks WHERE list = {{list}} AND status IN ({{status}})",interface:"input-code",width:"full",options:{language:"sql"}}},{field:"columns",name:"Columns",type:"json",special:"cast-json",meta:{width:"full",interface:"list",options:{addLabel:"Add column",label:"{{name}} - {{width}}",fields:[{field:"value",name:"Column Name",type:"string",note:"As returned by query",meta:{required:!0,width:"half",interface:"input",options:{trim:!0,softLength:100}}},{field:"text",name:"Label",type:"string",note:"What to display in the column header (Default is same as name)",meta:{width:"half",interface:"input",options:{trim:!0,softLength:100}}},{field:"width",name:"Width",type:"integer",meta:{required:!0,width:"half",interface:"input",options:{min:1,max:300},note:"Width of the column in ch (character width). Default is 10."},schema:{default_value:10}},{field:"isNumber",name:"Is Numberic",type:"boolean",meta:{width:"half",interface:"boolean"}},{field:"sortable",name:"Sortable",type:"boolean",meta:{width:"half",interface:"boolean"}},{field:"searchable",name:"Searchable",type:"boolean",meta:{width:"half",interface:"boolean"}},{field:"summarise",name:"Summarise",type:"string",meta:{width:"half",interface:"select-dropdown",options:{choices:[{text:"Sum",value:"sum"},{text:"Average",value:"avg"},{text:"Count",value:"count"},{text:"Count Unique",value:"count_unique"},{text:"Count Groups",value:"count_groups"}]}}}]}}},{field:"actions",name:"Actions",type:"json",special:"cast-json",meta:{width:"full",interface:"list",options:{addLabel:"Add action",label:"{{{label}}",fields:[{field:"label",name:"Label",type:"string",meta:{required:!0,width:"half",interface:"input",options:{trim:!0,softLength:50}}},{field:"row",name:"Activate on row click",type:"boolean",meta:{note:"If you don't want to show the action button, but want to activate the action on row click",width:"half",interface:"boolean"}},{field:"link",name:"Goto Link",type:"string",meta:{note:"Variables per row can be inserted as such %column_name%",width:"half",interface:"input",options:{trim:!0}}},{field:"filter",name:"Set Variables",type:"json",meta:{note:"Change dashboard variables based on the values of an item",width:"half",interface:"list",options:{fields:[{field:"variable",name:"variable",type:"string",meta:{type:"string",field:"variable",width:"half",display:"formatted-value",options:{trim:!0},required:!0,interface:"input"}},{field:"value",name:"value",type:"string",meta:{note:"A raw value or use %column_name% to use values from the row",type:"string",field:"value",width:"half",options:{trim:!0},required:!0,interface:"input"}}]}}},{field:"icon",name:"Icon",type:"string",meta:{note:"Leave blank to not show an icon",width:"half",interface:"select-icon"}},{field:"show_label",name:"Show label",type:"boolean",meta:{width:"half",interface:"boolean"}}]}}},{field:"download",name:"Download button",type:"boolean",meta:{width:"half",interface:"boolean",options:{label:"Show"}},schema:{default_value:!0}},{field:"is_static",name:"Is static",type:"boolean",meta:{width:"half",interface:"boolean",options:{label:"Yes"},note:"If the result will not be affect when variables are changed, you can check this box to improve performance."},schema:{default_value:!1}},{field:"cache",name:"Cache Response",type:"integer",meta:{width:"half",interface:"input",options:{min:10,max:3600},note:"Tells the browser how long to cache results for. Default is 30 seconds."},schema:{default_value:300}}],minWidth:10,minHeight:10})],Fe=[],Je=[];export{Ve as displays,Ue as interfaces,Ge as layouts,Qe as modules,Je as operations,Ye as panels,Fe as themes};
1
+ import{useApi as e,useStores as t,definePanel as n}from"@directus/extensions-sdk";import{onMounted as a,nextTick as o,getCurrentScope as r,onScopeDispose as l,getCurrentInstance as i,computed as s,shallowRef as u,ref as c,watch as d,toValue as f,resolveComponent as v,resolveDirective as h,createElementBlock as p,openBlock as m,createElementVNode as b,normalizeProps as g,guardReactiveProps as y,unref as w,createCommentVNode as k,normalizeClass as x,createVNode as q,withCtx as S,Fragment as _,renderList as C,normalizeStyle as R,withDirectives as L,createTextVNode as A,createBlock as T,withModifiers as $,toDisplayString as j,mergeProps as E,renderSlot as O,defineComponent as B,toRefs as z,createSlots as D}from"vue";import{useRouter as N}from"vue-router";import{useI18n as W}from"vue-i18n";var H,I,P="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function M(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var U=M(function(){if(I)return H;I=1;var e=/^\s+|\s+$/g,t=/^[-+]0x[0-9a-f]+$/i,n=/^0b[01]+$/i,a=/^0o[0-7]+$/i,o=parseInt,r="object"==typeof P&&P&&P.Object===Object&&P,l="object"==typeof self&&self&&self.Object===Object&&self,i=r||l||Function("return this")(),s=Object.prototype.toString,u=Math.max,c=Math.min,d=function(){return i.Date.now()};function f(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function v(r){if("number"==typeof r)return r;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==s.call(e)}(r))return NaN;if(f(r)){var l="function"==typeof r.valueOf?r.valueOf():r;r=f(l)?l+"":l}if("string"!=typeof r)return 0===r?r:+r;r=r.replace(e,"");var i=n.test(r);return i||a.test(r)?o(r.slice(2),i?2:8):t.test(r)?NaN:+r}return H=function(e,t,n){var a,o,r,l,i,s,h=0,p=!1,m=!1,b=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function g(t){var n=a,r=o;return a=o=void 0,h=t,l=e.apply(r,n)}function y(e){var n=e-s;return void 0===s||n>=t||n<0||m&&e-h>=r}function w(){var e=d();if(y(e))return k(e);i=setTimeout(w,function(e){var n=t-(e-s);return m?c(n,r-(e-h)):n}(e))}function k(e){return i=void 0,b&&a?g(e):(a=o=void 0,l)}function x(){var e=d(),n=y(e);if(a=arguments,o=this,s=e,n){if(void 0===i)return function(e){return h=e,i=setTimeout(w,t),p?g(e):l}(s);if(m)return i=setTimeout(w,t),g(s)}return void 0===i&&(i=setTimeout(w,t)),l}return t=v(t)||0,f(n)&&(p=!!n.leading,r=(m="maxWait"in n)?u(v(n.maxWait)||0,t):r,b="trailing"in n?!!n.trailing:b),x.cancel=function(){void 0!==i&&clearTimeout(i),h=0,a=s=o=i=void 0},x.flush=function(){return void 0===i?l:k(d())},x}}());const V="undefined"!=typeof window&&"undefined"!=typeof document;function G(e,t=!0,n){i()?a(e,n):t?e():o(e)}"undefined"!=typeof WorkerGlobalScope&&(globalThis,WorkerGlobalScope);const Q=V?window:void 0;function Y(e){var t;const n=f(e);return null!=(t=null==n?void 0:n.$el)?t:n}function F(e){const t=function(){const e=u(!1),t=i();return t&&a(()=>{e.value=!0},t),e}();return s(()=>(t.value,Boolean(e())))}function J(e,t,n={}){const{window:a=Q,...o}=n;let i;const u=F(()=>a&&"ResizeObserver"in a),c=()=>{i&&(i.disconnect(),i=void 0)},v=s(()=>{const t=f(e);return Array.isArray(t)?t.map(e=>Y(e)):[Y(t)]}),h=d(v,e=>{if(c(),u.value&&a){i=new ResizeObserver(t);for(const t of e)t&&i.observe(t,o)}},{immediate:!0,flush:"post"}),p=()=>{c(),h()};var m;return m=p,r()&&l(m),{isSupported:u,stop:p}}function Z(e,t={width:0,height:0},n={}){const{window:a=Q,box:o="content-box"}=n,r=s(()=>{var t,n;return null==(n=null==(t=Y(e))?void 0:t.namespaceURI)?void 0:n.includes("svg")}),l=u(t.width),i=u(t.height),{stop:c}=J(e,([t])=>{const n="border-box"===o?t.borderBoxSize:"content-box"===o?t.contentBoxSize:t.devicePixelContentBoxSize;if(a&&r.value){const t=Y(e);if(t){const e=t.getBoundingClientRect();l.value=e.width,i.value=e.height}}else if(n){const e=(s=n,Array.isArray(s)?s:[s]);l.value=e.reduce((e,{inlineSize:t})=>e+t,0),i.value=e.reduce((e,{blockSize:t})=>e+t,0)}else l.value=t.contentRect.width,i.value=t.contentRect.height;var s},n);G(()=>{const n=Y(e);n&&(l.value="offsetWidth"in n?n.offsetWidth:t.width,i.value="offsetHeight"in n?n.offsetHeight:t.height)});const f=d(()=>Y(e),e=>{l.value=e?t.width:0,i.value=e?t.height:0});return{width:l,height:i,stop:function(){c(),f()}}}function K(e,t){const{containerStyle:n,wrapperProps:a,scrollTo:o,calculateRange:r,currentList:l,containerRef:i}="itemHeight"in t?function(e,t){const n=X(t),{state:a,source:o,currentList:r,size:l,containerRef:i}=n,u={overflowY:"auto"},{itemHeight:c,overscan:d=5}=e,f=ee(a,o,c),v=te(o,c),h=ne("vertical",d,v,f,n),p=ae(c,o),m=s(()=>p(a.value.start)),b=re(c,o);oe(l,t,i,h);const g=ie("vertical",h,p,i),y=s(()=>({style:{width:"100%",height:b.value-m.value+"px",marginTop:`${m.value}px`}}));return{calculateRange:h,scrollTo:g,containerStyle:u,wrapperProps:y,currentList:r,containerRef:i}}(t,e):function(e,t){const n=X(t),{state:a,source:o,currentList:r,size:l,containerRef:i}=n,u={overflowX:"auto"},{itemWidth:c,overscan:d=5}=e,f=ee(a,o,c),v=te(o,c),h=ne("horizontal",d,v,f,n),p=ae(c,o),m=s(()=>p(a.value.start)),b=re(c,o);oe(l,t,i,h);const g=ie("horizontal",h,p,i),y=s(()=>({style:{height:"100%",width:b.value-m.value+"px",marginLeft:`${m.value}px`,display:"flex"}}));return{scrollTo:g,calculateRange:h,wrapperProps:y,containerStyle:u,currentList:r,containerRef:i}}(t,e);return{list:l,scrollTo:o,containerProps:{ref:i,onScroll:()=>{r()},style:n},wrapperProps:a}}function X(e){const t=u(null),n=Z(t),a=c([]),o=u(e);return{state:c({start:0,end:10}),source:o,currentList:a,size:n,containerRef:t}}function ee(e,t,n){return a=>{if("number"==typeof n)return Math.ceil(a/n);const{start:o=0}=e.value;let r=0,l=0;for(let e=o;e<t.value.length;e++){if(r+=n(e),l=e,r>a)break}return l-o}}function te(e,t){return n=>{if("number"==typeof t)return Math.floor(n/t)+1;let a=0,o=0;for(let r=0;r<e.value.length;r++){if(a+=t(r),a>=n){o=r;break}}return o+1}}function ne(e,t,n,a,{containerRef:o,state:r,currentList:l,source:i}){return()=>{const s=o.value;if(s){const o=n("vertical"===e?s.scrollTop:s.scrollLeft),u=a("vertical"===e?s.clientHeight:s.clientWidth),c=o-t,d=o+u+t;r.value={start:c<0?0:c,end:d>i.value.length?i.value.length:d},l.value=i.value.slice(r.value.start,r.value.end).map((e,t)=>({data:e,index:t+r.value.start}))}}}function ae(e,t){return n=>{if("number"==typeof e){return n*e}return t.value.slice(0,n).reduce((t,n,a)=>t+e(a),0)}}function oe(e,t,n,a){d([e.width,e.height,()=>f(t),n],()=>{a()})}function re(e,t){return s(()=>"number"==typeof e?t.value.length*e:t.value.reduce((t,n,a)=>t+e(a),0))}const le={horizontal:"scrollLeft",vertical:"scrollTop"};function ie(e,t,n,a){return o=>{a.value&&(a.value[le[e]]=n(o),t())}}const se={sum:"Σ",avg:"μ",count:"#",count_unique:"#!"},ue={sum:(e,t)=>e.reduce((e,n)=>e+Number.parseInt(n[t]),0),avg:(e,t)=>Math.round(ue.sum(e,t)/e.length),count:e=>e.length,count_unique:(e,t)=>new Set(e.map(e=>e[t])).size,count_groups:(e,t)=>e.reduce((e,n)=>{const a=n[t];return e[a]=(e[a]||0)+1,e},{})};var ce=[],de=[];function fe(e,t){if(e&&"undefined"!=typeof document){var n,a=!0===t.prepend?"prepend":"append",o=!0===t.singleTag,r="string"==typeof t.container?document.querySelector(t.container):document.getElementsByTagName("head")[0];if(o){var l=ce.indexOf(r);-1===l&&(l=ce.push(r)-1,de[l]={}),n=de[l]&&de[l][a]?de[l][a]:de[l][a]=i()}else n=i();65279===e.charCodeAt(0)&&(e=e.substring(1)),n.styleSheet?n.styleSheet.cssText+=e:n.appendChild(document.createTextNode(e))}function i(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),t.attributes)for(var n=Object.keys(t.attributes),o=0;o<n.length;o++)e.setAttribute(n[o],t.attributes[n[o]]);var l="prepend"===a?"afterbegin":"beforeend";return r.insertAdjacentElement(l,e),e}}fe("\nbody {\n --v-table-color: var(--v-input-color);\n --v-table-background-color: var(--v-input-background-color);\n}\n.sql-query-table[data-v-9e325291] {\n position: relative;\n height: var(--v-table-height);\n overflow-y: auto;\n\n --sqt-head--background: var(--background-normal, var(--theme--background));\n --sqt-head--color: color: var(--foreground-normal, var(--theme--foreground));\n\n --sqt-foot--background: var(--background-normal, var(--theme--background));\n --sqt-foot--color: color: var(--foreground-normal, var(--theme--foreground));\n}\ntable[data-v-9e325291] {\n min-width: 100%;\n min-height: 100%;\n border-collapse: collapse;\n border-spacing: 0;\n background-color: var(--v-table-background-color);\n color: var(--v-table-color);\n}\ntable thead[data-v-9e325291] {\n background-color: var(--sqt-head--background);\n color: var(--sqt-head--color);\n border-bottom: var(--border-width) solid var(--v-input-border-color);\n}\ntable thead.fixed[data-v-9e325291] {\n position: sticky;\n top: 0;\n z-index: 3;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);\n}\ntable thead tr.headers th[data-v-9e325291] {\n padding: 8px;\n font-weight: bold;\n min-width: 3rem;\n background-color: var(--sqt-head--background);\n color: var(--sqt-head--color);\n border-bottom: var(--border-width) solid var(--v-input-border-color);\n}\ntable tr.search th[data-v-9e325291] {\n padding: 0;\n}\ntable tr.search th .search-input.v-input[data-v-9e325291] {\n margin: 0;\n border: none;\n}\ntable th .sort-icon[data-v-9e325291] {\n opacity: 0;\n}\ntable th:hover .sort-icon[data-v-9e325291] {\n opacity: 0.5;\n}\ntable th .sort-icon.show[data-v-9e325291] {\n opacity: 1;\n}\ntable th.select[data-v-9e325291] {\n width: 2rem;\n}\ntable td[data-v-9e325291] {\n padding: 8px;\n align: middle;\n border-bottom: var(--border-width) solid var(--v-input-border-color);\n}\ntable tr.clickable[data-v-9e325291]:hover {\n background-color: var(--theme--background-subdued);\n cursor: pointer\n}\ntable tr.active[data-v-9e325291] {\n background-color: var(--theme--background-accent);\n}\ntable tbody[data-v-9e325291] {\n display: contents;\n}\ntable tfoot tr[data-v-9e325291] {\n position: sticky;\n bottom: 0;\n background-color: var(--sqt-foot--background);\n color: var(--sqt-foot--color);\n box-shadow: var(--card-shadow);\n}\ntable tfoot tr td[data-v-9e325291] {\n padding: 8px;\n height: 44px;\n font-weight: bold;\n background-color: var(--sqt-foot--background);\n color: var(--sqt-foot--color);\n}\n",{});var ve=(e,t)=>{const n=e.__vccOpts||e;for(const[e,a]of t)n[e]=a;return n};const he={class:"sql-query-table"},pe={key:0,class:"search"},me={colspan:"80%"},be={class:"headers"},ge=["onClick","align"],ye={key:0},we={key:1},ke=["colspan"],xe={key:0},qe={colspan:"100%"},Se=["onClick"],_e={key:2},Ce={key:0,class:"v-text-overflow"},Re={__name:"FastTable",props:{loading:Boolean,headers:{type:Array,validator:e=>e.every(e=>e.value&&e.text),required:!0},items:{type:Array,required:!0},sort:String,sortDesc:Boolean,fixedHeader:Boolean,rowClickable:Boolean,showRefresh:Boolean},emits:["update:sort","update:sortDesc","click:row","refresh"],setup(e,{emit:t}){const{t:n}=W(),a=e,o=c(""),r=s(()=>a.headers.filter(e=>e.searchable)),l=s(()=>{console.debug(a.sort,a.sortDesc);const e=o.value?o.value.toLowerCase().trim():"";return e?a.items.filter(t=>r.value.some(n=>t[n.value]&&t[n.value].toLowerCase().includes(e))):[...a.items]}),{list:i,containerProps:u,wrapperProps:d}=K(l,{itemHeight:40}),f=s(()=>{const e=function(e,t){if(!t.some(e=>!!e.summarise))return null;const n={};for(const a of t){if(!a.summarise)continue;const t=ue[a.summarise];if(!t)throw new Error(`Summariser function for ${a.summarise} not found.`);const o=t(e,a.value);if("count_groups"===a.summarise){let e=JSON.stringify(o,null,1).replace("{\n","").replace("\n}","").replace(/[",]/g,"");n[a.value]=e}else n[a.value]=`${se[a.summarise]} ${o}`}return n}(l.value,a.headers);return e}),B=t,z=c(null);return(t,l)=>{const s=v("v-icon"),c=v("v-input"),D=v("v-progress-linear"),N=v("v-card-title"),W=v("v-card"),H=h("tooltip");return m(),p("div",he,[b("table",g(y(w(u))),[b("thead",{class:x(["table-header",{fixed:e.fixedHeader}])},[r.value.length&&e.items.length>10?(m(),p("tr",pe,[b("th",me,[q(c,{modelValue:o.value,"onUpdate:modelValue":l[0]||(l[0]=e=>o.value=e),small:"",trim:"",class:"search-input",rounded:"",placeholder:"Search"},{prepend:S(()=>[q(s,{name:"search"})]),_:1},8,["modelValue"])])])):k("v-if",!0),b("tr",be,[(m(!0),p(_,null,C(e.headers,(n,o)=>(m(),p("th",{style:R({minWidth:`${n.width||t.auto}ch`}),key:n.value,onClick:e=>function(e){e.sortable&&(B("update:sort",e.value),B("update:sortDesc",!a.sortDesc))}(n),align:n.align||"left"},[0===o&&e.showRefresh?L((m(),T(s,{key:0,icon:"",small:"",secondary:"",right:"",onClick:l[1]||(l[1]=$(e=>B("refresh"),["stop"])),name:"refresh",clickable:""},null,512)),[[H,"Refresh"]]):k("v-if",!0),A(" "+j(n.text)+" ",1),n.sortable?(m(),T(s,{key:1,name:"sort",small:"",class:x(["sort-icon",{show:e.sort===n.value}]),style:R(`transform: ${e.sortDesc?"rotateZ(0deg) rotateY(0deg)":"rotateZ(180deg) rotateY(180deg)"}; transition: .2s all ease`)},null,8,["class","style"])):k("v-if",!0)],12,ge))),128)),t.$slots["item-append"]?(m(),p("th",ye,"#")):k("v-if",!0)]),e.loading?(m(),p("tr",we,[b("td",{colspan:e.headers.length+1},[q(D,{indeterminate:""})],8,ke)])):k("v-if",!0)],2),e.loading||e.items.length?(m(),p("tbody",g(E({key:1},w(d))),[O(t.$slots,"default",{items:w(i)},()=>[(m(!0),p(_,null,C(w(i),({data:n})=>(m(),p("tr",{onClick:e=>{z.value=n,B("click:row",{item:n,event:e})},class:x({clickable:e.rowClickable,active:z.value===n})},[(m(!0),p(_,null,C(e.headers,e=>(m(),p("td",{key:e.value,class:x(`align-${e.align}`)},j(n[e.value]),3))),128)),t.$slots["item-append"]?(m(),p("td",{key:0,onClick:l[2]||(l[2]=$(()=>{},["stop"]))},[O(t.$slots,"item-append",{item:n},void 0,!0)])):k("v-if",!0)],10,Se))),256))],!0),k(" This is to fill up any remaining height in the table "),l[3]||(l[3]=b("tr",null,[b("td",{style:{height:"100%"}})],-1))],16)):(m(),p("tbody",xe,[b("tr",null,[b("td",qe,[q(W,{style:{padding:"2rem","--v-card-max-width":"100%",margin:"2rem auto"}},{default:S(()=>[q(N,null,{default:S(()=>[q(s,{name:"info",style:{"margin-right":"2rem"}}),A(" "+j(w(n)("no_items")),1)]),_:1})]),_:1})])])])),f.value?(m(),p("tfoot",_e,[b("tr",null,[(m(!0),p(_,null,C(e.headers,e=>L((m(),p("td",{key:e.value},[f.value[e.value]?(m(),p("code",Ce,j(f.value[e.value]),1)):k("v-if",!0)])),[[H,e.summarise]])),128))])])):k("v-if",!0)],16)])}}};var Le=ve(Re,[["__scopeId","data-v-9e325291"]]);const Ae={key:0,class:"center"},Te={key:0};var $e=B({__name:"panel",props:{id:{},showHeader:{type:Boolean},sql:{},cache:{},columns:{},download:{type:Boolean,default:!0},is_static:{type:Boolean},allow_refresh:{type:Boolean},actions:{}},setup(n){const a=N(),r=n,{id:l,showHeader:i,download:u,is_static:f}=z(r),b=c(!1),g=c(""),y=c(""),R=c(null),$=c(null),E=e(),{useInsightsStore:O}=t(),B=O(),W=c(new Set),H=s(()=>{const e=new Set(W.value),t=r.sql.match(/{{ \w+ }}/g);return t&&t.forEach(t=>e.add(t.replace(/{{ | }}/g,""))),e}),I=s(()=>{const e={},t=[];return H.value.forEach(n=>{const a=B.getVariable(n);null==a?t.push(n):e[n]=a}),t.length?t:e});if(f.value)o(F);else{const e=U(F,1e3);d(I,()=>{Array.isArray(I.value)?y.value=`Please specify: ${I.value.join(" & ")}`:(y.value="",$.value||(b.value=!0),e())},{immediate:!0})}const P=s(()=>r.columns?.length>0?r.columns.map(e=>({...e,text:e.text||e.value})):R.value),M=c({by:null,desc:!1});d(M,({by:e,desc:t})=>{e&&$.value&&($.value=$.value.sort((n,a)=>n[e]<a[e]?t?1:-1:n[e]>a[e]?t?-1:1:0))},{deep:!0});let V,G=!1,Q=null,Y={};async function F(e=!1){if(b.value=!1,Array.isArray(I.value))Y={};else{if(G||e)e&&(b.value=!0);else{let e=!H.value.size;for(const t in I.value)Y[t]!==I.value[t]&&(e=!0),Y[t]=I.value[t];if(!e)return;b.value=!0}g.value="";try{const t={};V=t;const n={...I.value},{data:a}=await E.get(`insights/query/${l.value}`,{params:n,headers:{"Cache-Control":e?"no-cache":void 0}});if(V!==t)return;a.error&&(g.value=a.error),G=!1,r.cache&&setTimeout(()=>{G=!0},1e3*r.cache);const o=JSON.stringify(a);if(Q===o)return void(b.value=!1);if(Q=o,R.value=null,$.value=null,a.headers&&a.items){const e=a.items.length>2;R.value=a.headers.map(function(t,n){const a=t.replace(/_/g," ").replace(/(?:^|\s)\S/g,function(e){return e.toUpperCase()});return{text:a,value:t,width:a.length+1,sortable:e}});const t=r.columns&&r.columns.filter(e=>e.isNumber);$.value=t?a.items.map(e=>(t.forEach(t=>{e[t.value]=""!==e[t.value]?1*e[t.value]:null}),e)):a.items}}catch(e){const t=e.response?.data?.error||e.message;t.includes("Missing query param")?(y.value=t.replace("Missing query param","Please specify"),t.split(": ")[1].split(", ").forEach(e=>W.value.add(e))):g.value=t}b.value=!1}}const J=s(()=>r.actions?.find(e=>e.row));function Z(){const e=R.value||P.value;if(e&&$.value){let t=e.map(e=>e.text).join(",");t+="\r\n",t+=function(){if(!$.value)return;let e="";return $.value.forEach(t=>{for(let n in t)/[, ]/.test(t[n])?e+=`"${t[n].replace(/"/g,'\\"')}",`:e+=t[n]+",";e+="\r\n"}),e}();const n=(new Date).toISOString()+".csv",a=new Blob([t],{type:"text/csv;charset=utf-8;"});if(navigator.msSaveBlob)navigator.msSaveBlob(a,n);else{const e=document.createElement("a");if(void 0!==e.download){const t=URL.createObjectURL(a);e.setAttribute("href",t),e.setAttribute("download",n),e.style.visibility="hidden",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}}}function K({item:e}){J.value&&X(J.value,e)}function X(e,t){e.filter&&e.filter.forEach(({variable:e,value:n})=>{B.setVariable(e,n.replace(/%(\w+)%/g,(e,n)=>t[n]))}),e.link&&a.push(function(e,t){let n=e;for(let e in t)n=n.replace(new RegExp(`%${e}%`,"g"),t[e]);return n}(e.link,t))}async function ee(){b.value=!0,await F(!0)}return(e,t)=>{const a=v("v-progress-circular"),o=v("v-notice"),r=v("v-icon"),l=v("v-button"),s=h("tooltip");return m(),p("div",{class:x(["sql-panel-container",{"has-header":w(i)}])},[b.value||g.value||y.value?(m(),p("div",Ae,[b.value?(m(),T(a,{key:0,indeterminate:""})):y.value?(m(),T(o,{key:1,type:"info",center:""},{default:S(()=>[A(j(y.value),1)]),_:1})):(m(),T(o,{key:2,type:"danger",center:""},{default:S(()=>[A(j(g.value),1)]),_:1}))])):P.value&&$.value?(m(),p(_,{key:1},[w(u)?(m(),T(l,{key:0,onClick:Z,icon:"",secondary:"",class:"export-csv-button"},{default:S(()=>[q(r,{name:"download-file"})]),_:1})):k("v-if",!0),q(Le,{headers:P.value,items:$.value,"onClick:row":K,onRefresh:ee,sort:M.value.by,"onUpdate:sort":t[0]||(t[0]=e=>M.value.by=e),sortDesc:M.value.desc,"onUpdate:sortDesc":t[1]||(t[1]=e=>M.value.desc=e),rowClickable:!!J.value,showRefresh:n.allow_refresh,"fixed-header":""},D({_:2},[n.actions?.find(e=>!e.row)?{name:"item-append",fn:S(({item:e})=>[(m(!0),p(_,null,C(n.actions.filter(e=>!e.row),t=>L((m(),T(l,{outlined:"",onClick:n=>X(t,e),icon:!t.show_label,"x-small":""},{default:S(()=>[q(r,{name:t.icon},null,8,["name"]),t.show_label?(m(),p("span",Te,j(t.label),1)):k("v-if",!0)]),_:2},1032,["onClick","icon"])),[[s,t.label]])),256))]),key:"0"}:void 0]),1032,["headers","items","sort","sortDesc","rowClickable","showRefresh"])],64)):k("v-if",!0)],2)}}});fe("\n.sql-panel-container {\n width: 100%;\n height: 100%;\n --v-table-height: 100%;\n}\n.sql-panel-container .v-text-overflow {\n user-select: text;\n white-space: pre-wrap;\n}\n.sql-panel-container .center {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n}\n.export-csv-button {\n position: absolute;\n right: 0;\n bottom: 0;\n z-index: 2;\n opacity: 0.8;\n}\n.export-csv-button .button {\n border-radius: var(--border-radius) 0 0 0 !important;\n}\n",{});const je=[],Ee=[],Oe=[],Be=[],ze=[n({id:"sql-query",name:"SQL Query panel",icon:"view_list",description:"Show result of a stored SQL query as a table",component:$e,skipUndefinedKeys:["sql"],options:[{field:"sql",name:"SQL query",type:"string",meta:{note:"Supports variables in the format of {{variable_name}}. Don't quote string variables. Example: SELECT * FROM tasks WHERE list = {{list}} AND status IN ({{status}})",interface:"input-code",width:"full",options:{language:"sql"}}},{field:"columns",name:"Columns",type:"json",meta:{width:"full",interface:"list",options:{addLabel:"Add column",label:"{{name}} - {{width}}",fields:[{field:"value",name:"Column Name",type:"string",note:"As returned by query",meta:{required:!0,width:"half",interface:"input",options:{trim:!0,softLength:100}}},{field:"text",name:"Label",type:"string",note:"What to display in the column header (Default is same as name)",meta:{width:"half",interface:"input",options:{trim:!0,softLength:100}}},{field:"width",name:"Width",type:"integer",meta:{required:!0,width:"half",interface:"input",options:{min:1,max:300},note:"Width of the column in ch (character width). Default is 10."},schema:{default_value:10}},{field:"isNumber",name:"Is Numeric",type:"boolean",meta:{width:"half",interface:"boolean"}},{field:"sortable",name:"Sortable",type:"boolean",meta:{width:"half",interface:"boolean"}},{field:"searchable",name:"Searchable",type:"boolean",meta:{width:"half",interface:"boolean"}},{field:"summarise",name:"Summarise",type:"string",meta:{width:"half",interface:"select-dropdown",options:{choices:[{text:"Sum",value:"sum"},{text:"Average",value:"avg"},{text:"Count",value:"count"},{text:"Count Unique",value:"count_unique"},{text:"Count Groups",value:"count_groups"}]}}}]}}},{field:"actions",name:"Actions",type:"json",meta:{width:"full",interface:"list",options:{addLabel:"Add action",label:"{{{label}}",fields:[{field:"label",name:"Label",type:"string",meta:{required:!0,width:"half",interface:"input",options:{trim:!0,softLength:50}}},{field:"row",name:"Activate on row click",type:"boolean",meta:{note:"If you don't want to show the action button, but want to activate the action on row click",width:"half",interface:"boolean"}},{field:"link",name:"Goto Link",type:"string",meta:{note:"Variables per row can be inserted as such %column_name%",width:"half",interface:"input",options:{trim:!0}}},{field:"filter",name:"Set Variables",type:"json",meta:{note:"Change dashboard variables based on the values of an item",width:"half",interface:"list",options:{fields:[{field:"variable",name:"variable",type:"string",meta:{type:"string",field:"variable",width:"half",display:"formatted-value",options:{trim:!0},required:!0,interface:"input"}},{field:"value",name:"value",type:"string",meta:{note:"A raw value or use %column_name% to use values from the row",type:"string",field:"value",width:"half",options:{trim:!0},required:!0,interface:"input"}}]}}},{field:"icon",name:"Icon",type:"string",meta:{note:"Leave blank to not show an icon",width:"half",interface:"select-icon"}},{field:"show_label",name:"Show label",type:"boolean",meta:{width:"half",interface:"boolean"}}]}}},{field:"download",name:"Download button",type:"boolean",meta:{width:"half",interface:"boolean",options:{label:"Show"}},schema:{default_value:!0}},{field:"is_static",name:"Is static",type:"boolean",meta:{width:"half",interface:"boolean",options:{label:"Yes"},note:"If the result will not be affect when variables are changed, you can check this box to improve performance."},schema:{default_value:!1}},{field:"cache",name:"Cache Response",type:"integer",meta:{width:"half",interface:"input",options:{min:10,max:3600},note:"Tells the browser how long to cache results for. Default is 30 seconds."},schema:{default_value:300}},{field:"allow_refresh",name:"Allow refresh",type:"boolean",meta:{width:"half",interface:"boolean",note:"Allow the user to bypass the cache and fetch a fresh result"},schema:{default_value:!1}}],minWidth:10,minHeight:10})],De=[],Ne=[];export{Ee as displays,je as interfaces,Oe as layouts,Be as modules,Ne as operations,ze as panels,De as themes};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus-extension-sql-query-panel",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "Insights Panel for viewing results for dynamic sql queries",
6
6
  "icon": "extension",
@@ -45,10 +45,12 @@
45
45
  "add": "directus-extension add"
46
46
  },
47
47
  "devDependencies": {
48
- "@directus/extensions-sdk": "^14.0.0",
49
- "@types/node": "^20.17.30",
48
+ "@directus/extensions-sdk": "^15.0.0",
49
+ "@types/keyv": "^3.1.4",
50
+ "@types/node": "^20.19.17",
51
+ "@vueuse/core": "^13.9.0",
50
52
  "lodash.debounce": "^4.0.8",
51
- "typescript": "^5.8.3",
53
+ "typescript": "^5.9.2",
52
54
  "vue": "^3.5.13"
53
55
  },
54
56
  "dependencies": {