directus-extension-sql-query-panel 1.0.10 → 1.0.11

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=(e=>(e.REQUEST="sql-query.request",e.RESPONSE="sql-query.response",e))(e||{});const r=[],a=[{name:"insights",config:(r,{database:a,services:t,emitter:s})=>{const{PanelsService:n}=t;async function i(e,r){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 t=e.match(/{{\w+}}/g);if(t)throw new Error(`Missing query param: ${t.join(", ").replace(/{{|}}/g,"")}`);return(e=>{let r=[],a=[];if(e.rows&&e.fields)r=e.rows,a=e.fields.map((e=>e.name));else if(Array.isArray(e)){const[t,s]=e;r=2===t.length&&Array.isArray(t[0])?t.at(0):t,a=(2===s.length&&Array.isArray(s[0])?s.at(0):s).map((e=>e.name))}else void 0!==e.length&&e.columns?(r=e,r.length>0&&(a=Object.keys(r[0]))):e.recordset&&(r=e.recordset,a=e.recordset.columns?Object.keys(e.recordset.columns):[]);return{items:r,headers:a}})(await a.raw(e,r))}r.get("/query/:panelId",(async(r,a)=>{var t;try{const{query:o,variables:l,panel:c}=await async function(r){var a;const t=r.params.panelId;if(!t)throw new Error("Missing panelId");const i=new n({accountability:r.accountability,schema:r.schema}),o=await i.readOne(t);let{variables:l,query:c}=await s.emitFilter(e.REQUEST,{variables:Object.assign({dashboard:o.dashboard},null!=(a=r.query)?a:{}),query:o.options.sql},r);for(const e in l){if(!e.match(/^[a-zA-Z0-9_]+$/))throw new Error(`Invalid variable name: ${e}`);c=c.replace(new RegExp(`{{${e}}}`,"g"),`:${e}`)}return{query:c,variables:l,panel:o}}(r);let u=await i(o,l);u=await s.emitFilter(e.RESPONSE,u,r);let y=Number(null!=(t=c.options.cache)?t:300);return y=y>0?y:300,a.set("Cache-control",`public, max-age=${y}`),a.json(u)}catch(e){return a.status(400).json({error:e.message})}}))}}],t=[];export{a as endpoints,r as hooks,t 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,v=e=>"valid"===e.status,_=e=>"undefined"!=typeof Promise&&e instanceof Promise;function g(e,t,a,s){if("a"===a&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?s:"a"===a?s.call(e):s?s.value:t.get(e)}function b(e,t,a,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?n.call(e,a):n?n.value=a: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(v(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(_(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 v(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=>v(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(_(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 Ee({...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 Se({...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]+$/,E=/^[0-9A-HJKMNP-TV-Z]{26}$/i,S=/^[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)S.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)E.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 Ee?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 Se?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 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.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 ve(t instanceof j?{keyType:e,valueType:t,typeName:De.ZodRecord,...O(a)}:{keyType:H.create(),valueType:e,typeName:De.ZodRecord,...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.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}}}}_e.create=(e,t,a)=>new _e({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,"f")||b(this,x,new Set(this._def.values),"f"),!g(this,x,"f").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,"f")||b(this,w,new Set(e.getValidEnumValues(this._def.values)),"f"),!g(this,w,"f").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(!v(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=>v(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 Ee 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}}Ee.create=(e,t)=>new Ee({innerType:e,typeName:De.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...O(t)});class Se 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 _(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}}Se.create=(e,t)=>new Se({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=>(v(e)&&(e.value=Object.freeze(e.value)),e);return _(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=ve.create,dt=_e.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,vt=Ce.create,_t=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:v,isAsync:_,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:ve,ZodMap:_e,ZodSet:ge,ZodFunction:be,ZodLazy:ke,ZodLiteral:xe,ZodEnum:Ze,ZodNativeEnum:Te,ZodPromise:Oe,ZodEffects:je,ZodTransformer:je,ZodOptional:Ce,ZodNullable:Ae,ZodDefault:Ee,ZodCatch:Se,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:_t,number:Ve,object:tt,oboolean:()=>Ke().optional(),onumber:()=>Ve().optional(),optional:vt,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({}))}),Et=wt.optional(wt.object({enabled:wt.boolean(),requestedScopes:At})),St=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:Et}),Pt=wt.object({type:wt.enum(Ot),path:Ct,source:Ct,sandbox:Et}),$t=wt.object({type:wt.literal("bundle"),partial:wt.boolean().optional(),path:Ct,entries:wt.array(St)});wt.array(St);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.rows&&e.fields)t=e.rows,a=e.fields.map((e=>e.name));else if(Array.isArray(e)){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 void 0!==e.length&&e.columns?(t=e,t.length>0&&(a=Object.keys(t[0]))):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};
package/dist/app.js CHANGED
@@ -1 +1 @@
1
- import{useApi as e,useStores as t,definePanel as a}from"@directus/extensions-sdk";import{ref as n,computed as o,resolveComponent as r,resolveDirective as l,openBlock as i,createElementBlock as s,createElementVNode as u,normalizeClass as c,createVNode as d,withCtx as v,createCommentVNode as b,Fragment as f,renderList as m,normalizeStyle as p,createTextVNode as h,toDisplayString as g,createBlock as y,unref as w,renderSlot as k,withModifiers as x,withDirectives as _,pushScopeId as q,popScopeId as S,defineComponent as C,toRefs as j,nextTick as A,watch as E,createSlots as $}from"vue";import{useRouter as L}from"vue-router";import{useI18n as O}from"vue-i18n";var T="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function D(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var N=NaN,B="[object Symbol]",I=/^\s+|\s+$/g,W=/^[-+]0x[0-9a-f]+$/i,M=/^0b[01]+$/i,U=/^0o[0-7]+$/i,V=parseInt,H="object"==typeof T&&T&&T.Object===Object&&T,R="object"==typeof self&&self&&self.Object===Object&&self,F=H||R||Function("return this")(),Q=Object.prototype.toString,z=Math.max,P=Math.min,Y=function(){return F.Date.now()};function G(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Z(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&Q.call(e)==B}(e))return N;if(G(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=G(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(I,"");var a=M.test(e);return a||U.test(e)?V(e.slice(2),a?2:8):W.test(e)?N:+e}var J=D((function(e,t,a){var n,o,r,l,i,s,u=0,c=!1,d=!1,v=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function b(t){var a=n,r=o;return n=o=void 0,u=t,l=e.apply(r,a)}function f(e){var a=e-s;return void 0===s||a>=t||a<0||d&&e-u>=r}function m(){var e=Y();if(f(e))return p(e);i=setTimeout(m,function(e){var a=t-(e-s);return d?P(a,r-(e-u)):a}(e))}function p(e){return i=void 0,v&&n?b(e):(n=o=void 0,l)}function h(){var e=Y(),a=f(e);if(n=arguments,o=this,s=e,a){if(void 0===i)return function(e){return u=e,i=setTimeout(m,t),c?b(e):l}(s);if(d)return i=setTimeout(m,t),b(s)}return void 0===i&&(i=setTimeout(m,t)),l}return t=Z(t)||0,G(a)&&(c=!!a.leading,r=(d="maxWait"in a)?z(Z(a.maxWait)||0,t):r,v="trailing"in a?!!a.trailing:v),h.cancel=function(){void 0!==i&&clearTimeout(i),u=0,n=s=o=i=void 0},h.flush=function(){return void 0===i?l:p(Y())},h}));const K={sum:"Σ",avg:"μ",count:"#",count_unique:"#!"},X={sum:(e,t)=>e.reduce(((e,a)=>e+Number.parseInt(a[t])),0),avg:(e,t)=>Math.round(X.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,a)=>{const n=a[t];return e[n]=(e[n]||0)+1,e}),{})};var ee=[],te=[];function ae(e,t){if(e&&"undefined"!=typeof document){var a,n=!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=ee.indexOf(r);-1===l&&(l=ee.push(r)-1,te[l]={}),a=te[l]&&te[l][n]?te[l][n]:te[l][n]=i()}else a=i();65279===e.charCodeAt(0)&&(e=e.substring(1)),a.styleSheet?a.styleSheet.cssText+=e:a.appendChild(document.createTextNode(e))}function i(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),t.attributes)for(var a=Object.keys(t.attributes),o=0;o<a.length;o++)e.setAttribute(a[o],t.attributes[a[o]]);var l="prepend"===n?"afterbegin":"beforeend";return r.insertAdjacentElement(l,e),e}}ae("\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-b55bbc9b] {\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-b55bbc9b] {\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-b55bbc9b] {\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-b55bbc9b] {\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-b55bbc9b] {\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-b55bbc9b] {\n padding: 0;\n}\ntable tr.search th .search-input.v-input[data-v-b55bbc9b] {\n margin: 0;\n border: none;\n}\ntable th .sort-icon[data-v-b55bbc9b] {\n opacity: 0;\n}\ntable th:hover .sort-icon[data-v-b55bbc9b] {\n opacity: 0.5;\n}\ntable th .sort-icon.show[data-v-b55bbc9b] {\n opacity: 1;\n}\ntable th.select[data-v-b55bbc9b] {\n width: 2rem;\n}\ntable td[data-v-b55bbc9b] {\n padding: 8px;\n align: middle;\n border-bottom: var(--border-width) solid var(--v-input-border-color);\n}\ntable tr.clickable[data-v-b55bbc9b]:hover {\n background-color: var(--theme--background-subdued);\n cursor: pointer\n}\ntable tbody[data-v-b55bbc9b] {\n display: contents;\n}\ntable tfoot tr[data-v-b55bbc9b] {\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-b55bbc9b] {\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 ne=(e,t)=>{const a=e.__vccOpts||e;for(const[e,n]of t)a[e]=n;return a};const oe=e=>(q("data-v-b55bbc9b"),e=e(),S(),e),re={class:"sql-query-table"},le={key:0,class:"search"},ie={colspan:"80%"},se={class:"headers"},ue=["onClick","align"],ce={key:0},de={key:1},ve=["colspan"],be={key:0},fe={colspan:"100%"},me={key:1},pe=["onClick"],he=oe((()=>u("tr",null,[u("td",{style:{height:"100%"}})],-1))),ge={key:2},ye={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:a}=O(),q=e,S=n(""),C=o((()=>q.headers.filter((e=>e.searchable)))),j=o((()=>{const e=S.value?S.value.toLowerCase().trim():"";return e?q.items.filter((t=>C.value.some((a=>t[a.value]&&t[a.value].toLowerCase().includes(e))))):q.items})),A=o((()=>{const e=function(e,t){if(!t.some((e=>!!e.summarise)))return null;const a={};for(const n of t){if(!n.summarise)continue;const t=X[n.summarise];if(!t)throw new Error(`Summariser function for ${n.summarise} not found.`);const o=t(e,n.value);if("count_groups"===n.summarise){let e=JSON.stringify(o,null,1).replace("{\n","").replace("\n}","").replace(/[",]/g,"");a[n.value]=e}else a[n.value]=`${K[n.summarise]} ${o}`}return a}(j.value,q.headers);return e})),E=t;return(t,n)=>{const o=r("v-icon"),$=r("v-input"),L=r("v-progress-linear"),O=r("v-card-title"),T=r("v-card"),D=l("tooltip");return i(),s("div",re,[u("table",null,[u("thead",{class:c(["table-header",{fixed:e.fixedHeader}])},[C.value.length&&e.items.length>10?(i(),s("tr",le,[u("th",ie,[d($,{modelValue:S.value,"onUpdate:modelValue":n[0]||(n[0]=e=>S.value=e),small:"",trim:"",class:"search-input",rounded:"",placeholder:"Search"},{prepend:v((()=>[d(o,{name:"search"})])),_:1},8,["modelValue"])])])):b("v-if",!0),u("tr",se,[(i(!0),s(f,null,m(e.headers,(a=>(i(),s("th",{style:p({minWidth:`${a.width||t.auto}ch`}),key:a.value,onClick:e=>function(e){e.sortable&&(E("update:sort",e.value),E("update:sortDesc",!q.sortDesc))}(a),align:a.align||"left"},[h(g(a.text)+" ",1),a.sortable?(i(),y(o,{key:0,name:"sort",small:"",class:c(["sort-icon",{show:e.sort===a.value}]),style:p(`transform: ${e.sortDesc?"rotateZ(0deg) rotateY(0deg)":"rotateZ(180deg) rotateY(180deg)"}; transition: .2s all ease`)},null,8,["class","style"])):b("v-if",!0)],12,ue)))),128)),t.$slots["item-append"]?(i(),s("th",ce,"#")):b("v-if",!0)]),e.loading?(i(),s("tr",de,[u("td",{colspan:e.headers.length+1},[d(L,{indeterminate:""})],8,ve)])):b("v-if",!0)],2),e.loading||e.items.length?(i(),s("tbody",me,[k(t.$slots,"default",{items:j.value},(()=>[(i(!0),s(f,null,m(j.value,(a=>(i(),s("tr",{onClick:e=>E("click:row",{item:a,event:e}),class:c({clickable:e.rowClickable})},[(i(!0),s(f,null,m(e.headers,(e=>(i(),s("td",{key:e.value,class:c(`align-${e.align}`)},g(a[e.value]),3)))),128)),t.$slots["item-append"]?(i(),s("td",{key:0,onClick:n[1]||(n[1]=x((()=>{}),["stop"]))},[k(t.$slots,"item-append",{item:a},void 0,!0)])):b("v-if",!0)],10,pe)))),256))]),!0),b(" This is to fill up any remaining height in the table "),he])):(i(),s("tbody",be,[u("tr",null,[u("td",fe,[d(T,{style:{padding:"2rem","--v-card-max-width":"100%",margin:"2rem auto"}},{default:v((()=>[d(O,null,{default:v((()=>[d(o,{name:"info",style:{"margin-right":"2rem"}}),h(" "+g(w(a)("no_items")),1)])),_:1})])),_:1})])])])),A.value?(i(),s("tfoot",ge,[u("tr",null,[(i(!0),s(f,null,m(e.headers,(e=>_((i(),s("td",{key:e.value},[A.value[e.value]?(i(),s("code",ye,g(A.value[e.value]),1)):b("v-if",!0)])),[[D,e.summarise]]))),128))])])):b("v-if",!0)])])}}};var ke=ne(we,[["__scopeId","data-v-b55bbc9b"],["__file","FastTable.vue"]]);const xe={key:0,class:"center"},_e={key:0};var qe=C({__name:"panel",props:{id:{},showHeader:{type:Boolean},columns:{},download:{type:Boolean,default:!0},is_static:{type:Boolean},actions:{}},setup(a){const u=L(),p=a,{id:k,showHeader:x,download:q,is_static:S}=j(p),C=n(!1),O=n(""),T=n(""),D=n(null),N=n(null),B=e(),{useInsightsStore:I}=t(),W=I(),M=n(new Set),U=o((()=>{const e={},t=[];return M.value.forEach((a=>{const n=W.getVariable(a);null==n?t.push(a):e[a]=n})),t.length?t:e}));if(S.value)A(F);else{const e=J(F,1e3);E(U,(()=>{Array.isArray(U.value)?T.value=`Please specify: ${U.value.join(" & ")}`:(T.value="",N.value||(C.value=!0),e())}),{immediate:!0})}const V=o((()=>{var e;return(null==(e=p.columns)?void 0:e.length)>0?p.columns.map((e=>({...e,text:e.text||e.value}))):D.value})),H=n({by:null,desc:!1});let R;async function F(){var e,t;if(!Array.isArray(U.value)){C.value=!0,O.value="",D.value=null,N.value=null;try{const e={};R=e;const{data:t}=await B.get(`insights/query/${k.value}`,{params:U.value});if(R!==e)return;if(t.error&&(O.value=t.error),t.headers&&t.items){const e=t.items.length>2;D.value=t.headers.map((function(t,a){const n=t.replace(/_/g," ").replace(/(?:^|\s)\S/g,(function(e){return e.toUpperCase()}));return{text:n,value:t,width:n.length+1,sortable:e}}));const a=p.columns&&p.columns.filter((e=>e.isNumber));N.value=a?t.items.map((e=>(a.forEach((t=>{e[t.value]=""!==e[t.value]?1*e[t.value]:null})),e))):t.items}}catch(a){const n=(null==(t=null==(e=a.response)?void 0:e.data)?void 0:t.error)||a.message;n.includes("Missing query param")?(T.value=n.replace("Missing query param","Please specify"),n.split(": ")[1].split(", ").forEach((e=>M.value.add(e)))):O.value=n}C.value=!1}}E(H,(({by:e,desc:t})=>{e&&N.value&&(N.value=N.value.sort(((a,n)=>a[e]<n[e]?t?1:-1:a[e]>n[e]?t?-1:1:0)))}),{deep:!0});const Q=o((()=>{var e;return null==(e=p.actions)?void 0:e.find((e=>e.row))}));function z(){if(V.value&&N.value){let e=Object.values(V.value).map((e=>e.text)).join(",");e+="\r\n",e+=function(){if(!N.value)return;let e="";return N.value.forEach((t=>{for(let a in t)/[, ]/.test(t[a])?e+=`"${t[a].replace(/"/g,'\\"')}",`:e+=t[a]+",";e+="\r\n"})),e}();const t=(new Date).toISOString()+".csv",a=new Blob([e],{type:"text/csv;charset=utf-8;"});if(navigator.msSaveBlob)navigator.msSaveBlob(a,t);else{const e=document.createElement("a");if(void 0!==e.download){const n=URL.createObjectURL(a);e.setAttribute("href",n),e.setAttribute("download",t),e.style.visibility="hidden",document.body.appendChild(e),e.click(),document.body.removeChild(e)}}}}function P({item:e}){Q.value&&Y(Q.value,e)}function Y(e,t){e.filter&&e.filter.forEach((({variable:e,value:a})=>{W.setVariable(e,a.replace(/%(\w+)%/g,((e,a)=>t[a])))})),e.link&&u.push(function(e,t){let a=e;for(let e in t)a=a.replace(new RegExp(`%${e}%`,"g"),t[e]);return a}(e.link,t))}return(e,t)=>{var a;const n=r("v-progress-circular"),o=r("v-notice"),u=r("v-icon"),p=r("v-button"),k=l("tooltip");return i(),s("div",{class:c(["sql-panel-container",{"has-header":w(x)}])},[C.value||O.value||T.value?(i(),s("div",xe,[C.value?(i(),y(n,{key:0,indeterminate:""})):T.value?(i(),y(o,{key:1,type:"info",center:""},{default:v((()=>[h(g(T.value),1)])),_:1})):(i(),y(o,{key:2,type:"danger",center:""},{default:v((()=>[h(g(O.value),1)])),_:1}))])):V.value&&N.value?(i(),s(f,{key:1},[w(q)?(i(),y(p,{key:0,onClick:z,icon:"",secondary:"",class:"export-csv-button"},{default:v((()=>[d(u,{name:"download-file"})])),_:1})):b("v-if",!0),d(ke,{headers:V.value,items:N.value,"onClick:row":P,sort:H.value.by,"onUpdate:sort":t[0]||(t[0]=e=>H.value.by=e),sortDesc:H.value.desc,"onUpdate:sortDesc":t[1]||(t[1]=e=>H.value.desc=e),rowClickable:!!Q.value,"fixed-header":""},$({_:2},[(null==(a=e.actions)?void 0:a.find((e=>!e.row)))?{name:"item-append",fn:v((({item:t})=>[(i(!0),s(f,null,m(e.actions.filter((e=>!e.row)),(e=>_((i(),y(p,{outlined:"",onClick:a=>Y(e,t),icon:!e.show_label,"x-small":""},{default:v((()=>[d(u,{name:e.icon},null,8,["name"]),e.show_label?(i(),s("span",_e,g(e.label),1)):b("v-if",!0)])),_:2},1032,["onClick","icon"])),[[k,e.label]]))),256))])),key:"0"}:void 0]),1032,["headers","items","sort","sortDesc","rowClickable"])],64)):b("v-if",!0)],2)}}});ae("\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 Se=[],Ce=[],je=[],Ae=[],Ee=[a({id:"sql-query",name:"SQL Query panel",icon:"view_list",description:"Show result of a stored SQL query as a table",component:ne(qe,[["__file","panel.vue"]]),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})],$e=[];export{Ce as displays,Se as interfaces,je as layouts,Ae as modules,$e as operations,Ee as panels};
1
+ import{useApi as e,useStores as t,definePanel as a}from"@directus/extensions-sdk";import{ref as n,computed as o,resolveComponent as r,resolveDirective as l,openBlock as i,createElementBlock as s,createElementVNode as u,normalizeClass as c,createVNode as d,withCtx as v,createCommentVNode as f,Fragment as m,renderList as p,normalizeStyle as h,createTextVNode as b,toDisplayString as g,createBlock as y,unref as w,renderSlot as k,withModifiers as x,withDirectives as q,defineComponent as _,toRefs as S,nextTick as C,watch as j,createSlots as A}from"vue";import{useRouter as E}from"vue-router";import{useI18n as O}from"vue-i18n";var T="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function $(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var L=/^\s+|\s+$/g,D=/^[-+]0x[0-9a-f]+$/i,N=/^0b[01]+$/i,B=/^0o[0-7]+$/i,I=parseInt,U="object"==typeof T&&T&&T.Object===Object&&T,W="object"==typeof self&&self&&self.Object===Object&&self,M=U||W||Function("return this")(),V=Object.prototype.toString,H=Math.max,R=Math.min,z=function(){return M.Date.now()};function F(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Q(e){if("number"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==V.call(e)}(e))return NaN;if(F(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=F(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(L,"");var a=N.test(e);return a||B.test(e)?I(e.slice(2),a?2:8):D.test(e)?NaN:+e}var P=$((function(e,t,a){var n,o,r,l,i,s,u=0,c=!1,d=!1,v=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function f(t){var a=n,r=o;return n=o=void 0,u=t,l=e.apply(r,a)}function m(e){var a=e-s;return void 0===s||a>=t||a<0||d&&e-u>=r}function p(){var e=z();if(m(e))return h(e);i=setTimeout(p,function(e){var a=t-(e-s);return d?R(a,r-(e-u)):a}(e))}function h(e){return i=void 0,v&&n?f(e):(n=o=void 0,l)}function b(){var e=z(),a=m(e);if(n=arguments,o=this,s=e,a){if(void 0===i)return function(e){return u=e,i=setTimeout(p,t),c?f(e):l}(s);if(d)return i=setTimeout(p,t),f(s)}return void 0===i&&(i=setTimeout(p,t)),l}return t=Q(t)||0,F(a)&&(c=!!a.leading,r=(d="maxWait"in a)?H(Q(a.maxWait)||0,t):r,v="trailing"in a?!!a.trailing:v),b.cancel=function(){void 0!==i&&clearTimeout(i),u=0,n=s=o=i=void 0},b.flush=function(){return void 0===i?l:h(z())},b}));const Y={sum:"Σ",avg:"μ",count:"#",count_unique:"#!"},G={sum:(e,t)=>e.reduce(((e,a)=>e+Number.parseInt(a[t])),0),avg:(e,t)=>Math.round(G.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,a)=>{const n=a[t];return e[n]=(e[n]||0)+1,e}),{})};var J=[],Z=[];function K(e,t){if(e&&"undefined"!=typeof document){var a,n=!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=J.indexOf(r);-1===l&&(l=J.push(r)-1,Z[l]={}),a=Z[l]&&Z[l][n]?Z[l][n]:Z[l][n]=i()}else a=i();65279===e.charCodeAt(0)&&(e=e.substring(1)),a.styleSheet?a.styleSheet.cssText+=e:a.appendChild(document.createTextNode(e))}function i(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),t.attributes)for(var a=Object.keys(t.attributes),o=0;o<a.length;o++)e.setAttribute(a[o],t.attributes[a[o]]);var l="prepend"===n?"afterbegin":"beforeend";return r.insertAdjacentElement(l,e),e}}K("\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-237c7425] {\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-237c7425] {\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-237c7425] {\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-237c7425] {\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-237c7425] {\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-237c7425] {\n padding: 0;\n}\ntable tr.search th .search-input.v-input[data-v-237c7425] {\n margin: 0;\n border: none;\n}\ntable th .sort-icon[data-v-237c7425] {\n opacity: 0;\n}\ntable th:hover .sort-icon[data-v-237c7425] {\n opacity: 0.5;\n}\ntable th .sort-icon.show[data-v-237c7425] {\n opacity: 1;\n}\ntable th.select[data-v-237c7425] {\n width: 2rem;\n}\ntable td[data-v-237c7425] {\n padding: 8px;\n align: middle;\n border-bottom: var(--border-width) solid var(--v-input-border-color);\n}\ntable tr.clickable[data-v-237c7425]:hover {\n background-color: var(--theme--background-subdued);\n cursor: pointer\n}\ntable tr.active[data-v-237c7425] {\n background-color: var(--theme--background-accent);\n}\ntable tbody[data-v-237c7425] {\n display: contents;\n}\ntable tfoot tr[data-v-237c7425] {\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-237c7425] {\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 X=(e,t)=>{const a=e.__vccOpts||e;for(const[e,n]of t)a[e]=n;return a};const ee={class:"sql-query-table"},te={key:0,class:"search"},ae={colspan:"80%"},ne={class:"headers"},oe=["onClick","align"],re={key:0},le={key:1},ie=["colspan"],se={key:0},ue={colspan:"100%"},ce={key:1},de=["onClick"],ve={key:2},fe={key:0,class:"v-text-overflow"},me={__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:a}=O(),_=e,S=n(""),C=o((()=>_.headers.filter((e=>e.searchable)))),j=o((()=>{const e=S.value?S.value.toLowerCase().trim():"";return e?_.items.filter((t=>C.value.some((a=>t[a.value]&&t[a.value].toLowerCase().includes(e))))):_.items})),A=o((()=>{const e=function(e,t){if(!t.some((e=>!!e.summarise)))return null;const a={};for(const n of t){if(!n.summarise)continue;const t=G[n.summarise];if(!t)throw new Error(`Summariser function for ${n.summarise} not found.`);const o=t(e,n.value);if("count_groups"===n.summarise){let e=JSON.stringify(o,null,1).replace("{\n","").replace("\n}","").replace(/[",]/g,"");a[n.value]=e}else a[n.value]=`${Y[n.summarise]} ${o}`}return a}(j.value,_.headers);return e})),E=t,T=n(null);return(t,n)=>{const o=r("v-icon"),O=r("v-input"),$=r("v-progress-linear"),L=r("v-card-title"),D=r("v-card"),N=l("tooltip");return i(),s("div",ee,[u("table",null,[u("thead",{class:c(["table-header",{fixed:e.fixedHeader}])},[C.value.length&&e.items.length>10?(i(),s("tr",te,[u("th",ae,[d(O,{modelValue:S.value,"onUpdate:modelValue":n[0]||(n[0]=e=>S.value=e),small:"",trim:"",class:"search-input",rounded:"",placeholder:"Search"},{prepend:v((()=>[d(o,{name:"search"})])),_:1},8,["modelValue"])])])):f("v-if",!0),u("tr",ne,[(i(!0),s(m,null,p(e.headers,(a=>(i(),s("th",{style:h({minWidth:`${a.width||t.auto}ch`}),key:a.value,onClick:e=>function(e){e.sortable&&(E("update:sort",e.value),E("update:sortDesc",!_.sortDesc))}(a),align:a.align||"left"},[b(g(a.text)+" ",1),a.sortable?(i(),y(o,{key:0,name:"sort",small:"",class:c(["sort-icon",{show:e.sort===a.value}]),style:h(`transform: ${e.sortDesc?"rotateZ(0deg) rotateY(0deg)":"rotateZ(180deg) rotateY(180deg)"}; transition: .2s all ease`)},null,8,["class","style"])):f("v-if",!0)],12,oe)))),128)),t.$slots["item-append"]?(i(),s("th",re,"#")):f("v-if",!0)]),e.loading?(i(),s("tr",le,[u("td",{colspan:e.headers.length+1},[d($,{indeterminate:""})],8,ie)])):f("v-if",!0)],2),e.loading||e.items.length?(i(),s("tbody",ce,[k(t.$slots,"default",{items:j.value},(()=>[(i(!0),s(m,null,p(j.value,(a=>(i(),s("tr",{onClick:e=>{T.value=a,E("click:row",{item:a,event:e})},class:c({clickable:e.rowClickable,active:T.value===a})},[(i(!0),s(m,null,p(e.headers,(e=>(i(),s("td",{key:e.value,class:c(`align-${e.align}`)},g(a[e.value]),3)))),128)),t.$slots["item-append"]?(i(),s("td",{key:0,onClick:n[1]||(n[1]=x((()=>{}),["stop"]))},[k(t.$slots,"item-append",{item:a},void 0,!0)])):f("v-if",!0)],10,de)))),256))]),!0),f(" This is to fill up any remaining height in the table "),n[2]||(n[2]=u("tr",null,[u("td",{style:{height:"100%"}})],-1))])):(i(),s("tbody",se,[u("tr",null,[u("td",ue,[d(D,{style:{padding:"2rem","--v-card-max-width":"100%",margin:"2rem auto"}},{default:v((()=>[d(L,null,{default:v((()=>[d(o,{name:"info",style:{"margin-right":"2rem"}}),b(" "+g(w(a)("no_items")),1)])),_:1})])),_:1})])])])),A.value?(i(),s("tfoot",ve,[u("tr",null,[(i(!0),s(m,null,p(e.headers,(e=>q((i(),s("td",{key:e.value},[A.value[e.value]?(i(),s("code",fe,g(A.value[e.value]),1)):f("v-if",!0)])),[[N,e.summarise]]))),128))])])):f("v-if",!0)])])}}};var pe=X(me,[["__scopeId","data-v-237c7425"],["__file","FastTable.vue"]]);const he={key:0,class:"center"},be={key:0};var ge=_({__name:"panel",props:{id:{},showHeader:{type:Boolean},sql:{},cache:{},columns:{},download:{type:Boolean,default:!0},is_static:{type:Boolean},actions:{}},setup(a){const u=E(),h=a,{id:k,showHeader:x,download:_,is_static:O}=S(h),T=n(!1),$=n(""),L=n(""),D=n(null),N=n(null),B=e(),{useInsightsStore:I}=t(),U=I(),W=n(new Set),M=o((()=>{const e=new Set(W.value),t=h.sql.match(/{{ \w+ }}/g);return t&&t.forEach((t=>e.add(t.replace(/{{ | }}/g,"")))),e})),V=o((()=>{const e={},t=[];return M.value.forEach((a=>{const n=U.getVariable(a);null==n?t.push(a):e[a]=n})),t.length?t:e}));if(O.value)C(G);else{const e=P(G,1e3);j(V,(()=>{Array.isArray(V.value)?L.value=`Please specify: ${V.value.join(" & ")}`:(L.value="",N.value||(T.value=!0),e())}),{immediate:!0})}const H=o((()=>h.columns?.length>0?h.columns.map((e=>({...e,text:e.text||e.value}))):D.value)),R=n({by:null,desc:!1});j(R,(({by:e,desc:t})=>{e&&N.value&&(N.value=N.value.sort(((a,n)=>a[e]<n[e]?t?1:-1:a[e]>n[e]?t?-1:1:0)))}),{deep:!0});let z,F,Q=!1,Y={};async function G(){if(T.value=!1,Array.isArray(V.value))Y={};else{if(!Q){let e=!M.value.size;for(const t in V.value)Y[t]!==V.value[t]&&(e=!0),Y[t]=V.value[t];if(!e)return;T.value=!0}$.value="";try{const e={};F=e;const{data:t}=await B.get(`insights/query/${k.value}`,{params:V.value});if(F!==e)return;t.error&&($.value=t.error),Q=!1,h.cache&&setTimeout((()=>{Q=!0}),1e3*h.cache);const a=JSON.stringify(t);if(z===a)return void(T.value=!1);if(z=a,D.value=null,N.value=null,t.headers&&t.items){const e=t.items.length>2;D.value=t.headers.map((function(t,a){const n=t.replace(/_/g," ").replace(/(?:^|\s)\S/g,(function(e){return e.toUpperCase()}));return{text:n,value:t,width:n.length+1,sortable:e}}));const a=h.columns&&h.columns.filter((e=>e.isNumber));N.value=a?t.items.map((e=>(a.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")?(L.value=t.replace("Missing query param","Please specify"),t.split(": ")[1].split(", ").forEach((e=>W.value.add(e)))):$.value=t}T.value=!1}}const J=o((()=>h.actions?.find((e=>e.row))));function Z(){if(H.value&&N.value){let e=Object.values(H.value).map((e=>e.text)).join(",");e+="\r\n",e+=function(){if(!N.value)return;let e="";return N.value.forEach((t=>{for(let a in t)/[, ]/.test(t[a])?e+=`"${t[a].replace(/"/g,'\\"')}",`:e+=t[a]+",";e+="\r\n"})),e}();const t=(new Date).toISOString()+".csv",a=new Blob([e],{type:"text/csv;charset=utf-8;"});if(navigator.msSaveBlob)navigator.msSaveBlob(a,t);else{const e=document.createElement("a");if(void 0!==e.download){const n=URL.createObjectURL(a);e.setAttribute("href",n),e.setAttribute("download",t),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:a})=>{U.setVariable(e,a.replace(/%(\w+)%/g,((e,a)=>t[a])))})),e.link&&u.push(function(e,t){let a=e;for(let e in t)a=a.replace(new RegExp(`%${e}%`,"g"),t[e]);return a}(e.link,t))}return(e,t)=>{const a=r("v-progress-circular"),n=r("v-notice"),o=r("v-icon"),u=r("v-button"),h=l("tooltip");return i(),s("div",{class:c(["sql-panel-container",{"has-header":w(x)}])},[T.value||$.value||L.value?(i(),s("div",he,[T.value?(i(),y(a,{key:0,indeterminate:""})):L.value?(i(),y(n,{key:1,type:"info",center:""},{default:v((()=>[b(g(L.value),1)])),_:1})):(i(),y(n,{key:2,type:"danger",center:""},{default:v((()=>[b(g($.value),1)])),_:1}))])):H.value&&N.value?(i(),s(m,{key:1},[w(_)?(i(),y(u,{key:0,onClick:Z,icon:"",secondary:"",class:"export-csv-button"},{default:v((()=>[d(o,{name:"download-file"})])),_:1})):f("v-if",!0),d(pe,{headers:H.value,items:N.value,"onClick:row":K,sort:R.value.by,"onUpdate:sort":t[0]||(t[0]=e=>R.value.by=e),sortDesc:R.value.desc,"onUpdate:sortDesc":t[1]||(t[1]=e=>R.value.desc=e),rowClickable:!!J.value,"fixed-header":""},A({_:2},[e.actions?.find((e=>!e.row))?{name:"item-append",fn:v((({item:t})=>[(i(!0),s(m,null,p(e.actions.filter((e=>!e.row)),(e=>q((i(),y(u,{outlined:"",onClick:a=>X(e,t),icon:!e.show_label,"x-small":""},{default:v((()=>[d(o,{name:e.icon},null,8,["name"]),e.show_label?(i(),s("span",be,g(e.label),1)):f("v-if",!0)])),_:2},1032,["onClick","icon"])),[[h,e.label]]))),256))])),key:"0"}:void 0]),1032,["headers","items","sort","sortDesc","rowClickable"])],64)):f("v-if",!0)],2)}}});K("\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 ye=[],we=[],ke=[],xe=[],qe=[a({id:"sql-query",name:"SQL Query panel",icon:"view_list",description:"Show result of a stored SQL query as a table",component:X(ge,[["__file","panel.vue"]]),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})],_e=[],Se=[];export{we as displays,ye as interfaces,ke as layouts,xe as modules,Se as operations,qe as panels,_e as themes};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus-extension-sql-query-panel",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "description": "Insights Panel for viewing results for dynamic sql queries",
6
6
  "icon": "extension",
@@ -45,12 +45,10 @@
45
45
  "add": "directus-extension add"
46
46
  },
47
47
  "devDependencies": {
48
- "@directus/extensions": "^0.1.1",
49
- "@directus/extensions-sdk": "10.1.14",
50
- "@directus/types": "^11.0.1",
51
- "@types/node": "^20.8.10",
48
+ "@directus/extensions-sdk": "^13.0.4",
49
+ "@types/node": "^20.17.30",
52
50
  "lodash.debounce": "^4.0.8",
53
- "typescript": "^5.2.2",
54
- "vue": "^3.3.7"
51
+ "typescript": "^5.8.3",
52
+ "vue": "^3.5.13"
55
53
  }
56
54
  }