@stonecrop/graphql-middleware 0.8.7 → 0.8.8
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/index.cjs +40 -36
- package/dist/index.js +339 -3331
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/plugin/postgraphile.d.ts +31 -0
- package/dist/src/plugin/postgraphile.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("graphql"),ye=require("node:fs"),kt=require("node:path"),De=require("postgraphile/utils"),E=require("postgraphile/grafast");var v;(function(n){n.assertEqual=s=>{};function e(s){}n.assertIs=e;function t(s){throw new Error}n.assertNever=t,n.arrayToEnum=s=>{const a={};for(const i of s)a[i]=i;return a},n.getValidEnumValues=s=>{const a=n.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),i={};for(const o of a)i[o]=s[o];return n.objectValues(i)},n.objectValues=s=>n.objectKeys(s).map(function(a){return s[a]}),n.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const a=[];for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&a.push(i);return a},n.find=(s,a)=>{for(const i of s)if(a(i))return i},n.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,a=" | "){return s.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}n.joinValues=r,n.jsonStringifyReplacer=(s,a)=>typeof a=="bigint"?a.toString():a})(v||(v={}));var je;(function(n){n.mergeShapes=(e,t)=>({...e,...t})})(je||(je={}));const f=v.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Z=n=>{switch(typeof n){case"undefined":return f.undefined;case"string":return f.string;case"number":return Number.isNaN(n)?f.nan:f.number;case"boolean":return f.boolean;case"function":return f.function;case"bigint":return f.bigint;case"symbol":return f.symbol;case"object":return Array.isArray(n)?f.array:n===null?f.null:n.then&&typeof n.then=="function"&&n.catch&&typeof n.catch=="function"?f.promise:typeof Map<"u"&&n instanceof Map?f.map:typeof Set<"u"&&n instanceof Set?f.set:typeof Date<"u"&&n instanceof Date?f.date:f.object;default:return f.unknown}},d=v.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 j extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(a){return a.message},r={_errors:[]},s=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(s);else if(i.code==="invalid_return_type")s(i.returnTypeError);else if(i.code==="invalid_arguments")s(i.argumentsError);else if(i.path.length===0)r._errors.push(t(i));else{let o=r,c=0;for(;c<i.path.length;){const l=i.path[c];c===i.path.length-1?(o[l]=o[l]||{_errors:[]},o[l]._errors.push(t(i))):o[l]=o[l]||{_errors:[]},o=o[l],c++}}};return s(this),r}static assert(e){if(!(e instanceof j))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,v.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},r=[];for(const s of this.issues)if(s.path.length>0){const a=s.path[0];t[a]=t[a]||[],t[a].push(e(s))}else r.push(e(s));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}j.create=n=>new j(n);const ge=(n,e)=>{let t;switch(n.code){case d.invalid_type:n.received===f.undefined?t="Required":t=`Expected ${n.expected}, received ${n.received}`;break;case d.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(n.expected,v.jsonStringifyReplacer)}`;break;case d.unrecognized_keys:t=`Unrecognized key(s) in object: ${v.joinValues(n.keys,", ")}`;break;case d.invalid_union:t="Invalid input";break;case d.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${v.joinValues(n.options)}`;break;case d.invalid_enum_value:t=`Invalid enum value. Expected ${v.joinValues(n.options)}, received '${n.received}'`;break;case d.invalid_arguments:t="Invalid function arguments";break;case d.invalid_return_type:t="Invalid function return type";break;case d.invalid_date:t="Invalid date";break;case d.invalid_string:typeof n.validation=="object"?"includes"in n.validation?(t=`Invalid input: must include "${n.validation.includes}"`,typeof n.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${n.validation.position}`)):"startsWith"in n.validation?t=`Invalid input: must start with "${n.validation.startsWith}"`:"endsWith"in n.validation?t=`Invalid input: must end with "${n.validation.endsWith}"`:v.assertNever(n.validation):n.validation!=="regex"?t=`Invalid ${n.validation}`:t="Invalid";break;case d.too_small:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at least":"more than"} ${n.minimum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at least":"over"} ${n.minimum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="bigint"?t=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(n.minimum))}`:t="Invalid input";break;case d.too_big:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at most":"less than"} ${n.maximum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at most":"under"} ${n.maximum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="bigint"?t=`BigInt must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly":n.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(n.maximum))}`:t="Invalid input";break;case d.custom:t="Invalid input";break;case d.invalid_intersection_types:t="Intersection results could not be merged";break;case d.not_multiple_of:t=`Number must be a multiple of ${n.multipleOf}`;break;case d.not_finite:t="Number must be finite";break;default:t=e.defaultError,v.assertNever(n)}return{message:t}};let xt=ge;function bt(){return xt}const wt=n=>{const{data:e,path:t,errorMaps:r,issueData:s}=n,a=[...t,...s.path||[]],i={...s,path:a};if(s.message!==void 0)return{...s,path:a,message:s.message};let o="";const c=r.filter(l=>!!l).slice().reverse();for(const l of c)o=l(i,{data:e,defaultError:o}).message;return{...s,path:a,message:o}};function u(n,e){const t=bt(),r=wt({issueData:e,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,t,t===ge?void 0:ge].filter(s=>!!s)});n.common.issues.push(r)}class S{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const s of t){if(s.status==="aborted")return y;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const s of t){const a=await s.key,i=await s.value;r.push({key:a,value:i})}return S.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const s of t){const{key:a,value:i}=s;if(a.status==="aborted"||i.status==="aborted")return y;a.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||s.alwaysSet)&&(r[a.value]=i.value)}return{status:e.value,value:r}}}const y=Object.freeze({status:"aborted"}),H=n=>({status:"dirty",value:n}),A=n=>({status:"valid",value:n}),Ee=n=>n.status==="aborted",Ze=n=>n.status==="dirty",B=n=>n.status==="valid",re=n=>typeof Promise<"u"&&n instanceof Promise;var p;(function(n){n.errToObj=e=>typeof e=="string"?{message:e}:e||{},n.toString=e=>typeof e=="string"?e:e?.message})(p||(p={}));class R{constructor(e,t,r,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Me=(n,e)=>{if(B(e))return{success:!0,data:e.value};if(!n.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new j(n.common.issues);return this._error=t,this._error}}};function g(n){if(!n)return{};const{errorMap:e,invalid_type_error:t,required_error:r,description:s}=n;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(i,o)=>{const{message:c}=n;return i.code==="invalid_enum_value"?{message:c??o.defaultError}:typeof o.data>"u"?{message:c??r??o.defaultError}:i.code!=="invalid_type"?{message:o.defaultError}:{message:c??t??o.defaultError}},description:s}}class _{get description(){return this._def.description}_getType(e){return Z(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Z(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new S,ctx:{common:e.parent.common,data:e.data,parsedType:Z(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(re(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){const r={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)},s=this._parseSync({data:e,path:r.path,parent:r});return Me(r,s)}"~validate"(e){const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)};if(!this["~standard"].async)try{const r=this._parseSync({data:e,path:[],parent:t});return B(r)?{value:r.value}:{issues:t.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(r=>B(r)?{value:r.value}:{issues:t.common.issues})}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Z(e)},s=this._parse({data:e,path:r.path,parent:r}),a=await(re(s)?s:Promise.resolve(s));return Me(r,a)}refine(e,t){const r=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,a)=>{const i=e(s),o=()=>a.addIssue({code:d.custom,...r(s)});return typeof Promise<"u"&&i instanceof Promise?i.then(c=>c?!0:(o(),!1)):i?!0:(o(),!1)})}refinement(e,t){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof t=="function"?t(r,s):t),!1))}_refinement(e){return new U({schema:this,typeName:m.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:t=>this["~validate"](t)}}optional(){return M.create(this,this._def)}nullable(){return J.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return $.create(this)}promise(){return ce.create(this,this._def)}or(e){return ae.create([this,e],this._def)}and(e){return ie.create(this,e,this._def)}transform(e){return new U({...g(this._def),schema:this,typeName:m.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new xe({...g(this._def),innerType:this,defaultValue:t,typeName:m.ZodDefault})}brand(){return new Jt({typeName:m.ZodBranded,type:this,...g(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new be({...g(this._def),innerType:this,catchValue:t,typeName:m.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Te.create(this,e)}readonly(){return we.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const St=/^c[^\s-]{8,}$/i,Tt=/^[0-9a-z]+$/,At=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ct=/^[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,Nt=/^[a-z0-9_-]{21}$/i,Ot=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,$t=/^[-+]?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)?)??$/,Rt=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,It="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let me;const Dt=/^(?:(?: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])$/,jt=/^(?:(?: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])$/,Et=/^(([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]))$/,Zt=/^(([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])$/,Mt=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Lt=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,He="((\\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])))",Pt=new RegExp(`^${He}$`);function Qe(n){let e="[0-5]\\d";n.precision?e=`${e}\\.\\d{${n.precision}}`:n.precision==null&&(e=`${e}(\\.\\d+)?`);const t=n.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function qt(n){return new RegExp(`^${Qe(n)}$`)}function Vt(n){let e=`${He}T${Qe(n)}`;const t=[];return t.push(n.local?"Z?":"Z"),n.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Ft(n,e){return!!((e==="v4"||!e)&&Dt.test(n)||(e==="v6"||!e)&&Et.test(n))}function Bt(n,e){if(!Ot.test(n))return!1;try{const[t]=n.split(".");if(!t)return!1;const r=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function zt(n,e){return!!((e==="v4"||!e)&&jt.test(n)||(e==="v6"||!e)&&Zt.test(n))}class D extends _{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==f.string){const a=this._getOrReturnCtx(e);return u(a,{code:d.invalid_type,expected:f.string,received:a.parsedType}),y}const r=new S;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),u(s,{code:d.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="max")e.data.length>a.value&&(s=this._getOrReturnCtx(e,s),u(s,{code:d.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="length"){const i=e.data.length>a.value,o=e.data.length<a.value;(i||o)&&(s=this._getOrReturnCtx(e,s),i?u(s,{code:d.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&u(s,{code:d.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),r.dirty())}else if(a.kind==="email")Rt.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"email",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="emoji")me||(me=new RegExp(It,"u")),me.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"emoji",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="uuid")Ct.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"uuid",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="nanoid")Nt.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"nanoid",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid")St.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"cuid",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid2")Tt.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"cuid2",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="ulid")At.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"ulid",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),u(s,{validation:"url",code:d.invalid_string,message:a.message}),r.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"regex",code:d.invalid_string,message:a.message}),r.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(s=this._getOrReturnCtx(e,s),u(s,{code:d.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),r.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(s=this._getOrReturnCtx(e,s),u(s,{code:d.invalid_string,validation:{startsWith:a.value},message:a.message}),r.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(s=this._getOrReturnCtx(e,s),u(s,{code:d.invalid_string,validation:{endsWith:a.value},message:a.message}),r.dirty()):a.kind==="datetime"?Vt(a).test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{code:d.invalid_string,validation:"datetime",message:a.message}),r.dirty()):a.kind==="date"?Pt.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{code:d.invalid_string,validation:"date",message:a.message}),r.dirty()):a.kind==="time"?qt(a).test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{code:d.invalid_string,validation:"time",message:a.message}),r.dirty()):a.kind==="duration"?$t.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"duration",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="ip"?Ft(e.data,a.version)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"ip",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="jwt"?Bt(e.data,a.alg)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"jwt",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="cidr"?zt(e.data,a.version)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"cidr",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="base64"?Mt.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"base64",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="base64url"?Lt.test(e.data)||(s=this._getOrReturnCtx(e,s),u(s,{validation:"base64url",code:d.invalid_string,message:a.message}),r.dirty()):v.assertNever(a);return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement(s=>e.test(s),{validation:t,code:d.invalid_string,...p.errToObj(r)})}_addCheck(e){return new D({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...p.errToObj(e)})}url(e){return this._addCheck({kind:"url",...p.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...p.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...p.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...p.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...p.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...p.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...p.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...p.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...p.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...p.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...p.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...p.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...p.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...p.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...p.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...p.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...p.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...p.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...p.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...p.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...p.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...p.errToObj(t)})}nonempty(e){return this.min(1,p.errToObj(e))}trim(){return new D({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new D({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new D({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}D.create=n=>new D({checks:[],typeName:m.ZodString,coerce:n?.coerce??!1,...g(n)});function Ut(n,e){const t=(n.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=t>r?t:r,a=Number.parseInt(n.toFixed(s).replace(".","")),i=Number.parseInt(e.toFixed(s).replace(".",""));return a%i/10**s}class X extends _{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==f.number){const a=this._getOrReturnCtx(e);return u(a,{code:d.invalid_type,expected:f.number,received:a.parsedType}),y}let r;const s=new S;for(const a of this._def.checks)a.kind==="int"?v.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),u(r,{code:d.invalid_type,expected:"integer",received:"float",message:a.message}),s.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(r=this._getOrReturnCtx(e,r),u(r,{code:d.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(r=this._getOrReturnCtx(e,r),u(r,{code:d.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?Ut(e.data,a.value)!==0&&(r=this._getOrReturnCtx(e,r),u(r,{code:d.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),u(r,{code:d.not_finite,message:a.message}),s.dirty()):v.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,p.toString(t))}gt(e,t){return this.setLimit("min",e,!1,p.toString(t))}lte(e,t){return this.setLimit("max",e,!0,p.toString(t))}lt(e,t){return this.setLimit("max",e,!1,p.toString(t))}setLimit(e,t,r,s){return new X({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:p.toString(s)}]})}_addCheck(e){return new X({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:p.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:p.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:p.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:p.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:p.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:p.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:p.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:p.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:p.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&v.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(t===null||r.value>t)&&(t=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}X.create=n=>new X({checks:[],typeName:m.ZodNumber,coerce:n?.coerce||!1,...g(n)});class K extends _{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==f.bigint)return this._getInvalidInput(e);let r;const s=new S;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(r=this._getOrReturnCtx(e,r),u(r,{code:d.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(r=this._getOrReturnCtx(e,r),u(r,{code:d.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),u(r,{code:d.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):v.assertNever(a);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return u(t,{code:d.invalid_type,expected:f.bigint,received:t.parsedType}),y}gte(e,t){return this.setLimit("min",e,!0,p.toString(t))}gt(e,t){return this.setLimit("min",e,!1,p.toString(t))}lte(e,t){return this.setLimit("max",e,!0,p.toString(t))}lt(e,t){return this.setLimit("max",e,!1,p.toString(t))}setLimit(e,t,r,s){return new K({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:p.toString(s)}]})}_addCheck(e){return new K({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:p.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:p.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:p.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:p.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:p.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}K.create=n=>new K({checks:[],typeName:m.ZodBigInt,coerce:n?.coerce??!1,...g(n)});class _e extends _{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==f.boolean){const r=this._getOrReturnCtx(e);return u(r,{code:d.invalid_type,expected:f.boolean,received:r.parsedType}),y}return A(e.data)}}_e.create=n=>new _e({typeName:m.ZodBoolean,coerce:n?.coerce||!1,...g(n)});class se extends _{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==f.date){const a=this._getOrReturnCtx(e);return u(a,{code:d.invalid_type,expected:f.date,received:a.parsedType}),y}if(Number.isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return u(a,{code:d.invalid_date}),y}const r=new S;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),u(s,{code:d.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(s=this._getOrReturnCtx(e,s),u(s,{code:d.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):v.assertNever(a);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new se({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:p.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:p.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}se.create=n=>new se({checks:[],coerce:n?.coerce||!1,typeName:m.ZodDate,...g(n)});class Le extends _{_parse(e){if(this._getType(e)!==f.symbol){const r=this._getOrReturnCtx(e);return u(r,{code:d.invalid_type,expected:f.symbol,received:r.parsedType}),y}return A(e.data)}}Le.create=n=>new Le({typeName:m.ZodSymbol,...g(n)});class Pe extends _{_parse(e){if(this._getType(e)!==f.undefined){const r=this._getOrReturnCtx(e);return u(r,{code:d.invalid_type,expected:f.undefined,received:r.parsedType}),y}return A(e.data)}}Pe.create=n=>new Pe({typeName:m.ZodUndefined,...g(n)});class qe extends _{_parse(e){if(this._getType(e)!==f.null){const r=this._getOrReturnCtx(e);return u(r,{code:d.invalid_type,expected:f.null,received:r.parsedType}),y}return A(e.data)}}qe.create=n=>new qe({typeName:m.ZodNull,...g(n)});class Ve extends _{constructor(){super(...arguments),this._any=!0}_parse(e){return A(e.data)}}Ve.create=n=>new Ve({typeName:m.ZodAny,...g(n)});class ve extends _{constructor(){super(...arguments),this._unknown=!0}_parse(e){return A(e.data)}}ve.create=n=>new ve({typeName:m.ZodUnknown,...g(n)});class L extends _{_parse(e){const t=this._getOrReturnCtx(e);return u(t,{code:d.invalid_type,expected:f.never,received:t.parsedType}),y}}L.create=n=>new L({typeName:m.ZodNever,...g(n)});class Fe extends _{_parse(e){if(this._getType(e)!==f.undefined){const r=this._getOrReturnCtx(e);return u(r,{code:d.invalid_type,expected:f.void,received:r.parsedType}),y}return A(e.data)}}Fe.create=n=>new Fe({typeName:m.ZodVoid,...g(n)});class $ extends _{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),s=this._def;if(t.parsedType!==f.array)return u(t,{code:d.invalid_type,expected:f.array,received:t.parsedType}),y;if(s.exactLength!==null){const i=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(i||o)&&(u(t,{code:i?d.too_big:d.too_small,minimum:o?s.exactLength.value:void 0,maximum:i?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(u(t,{code:d.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(u(t,{code:d.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((i,o)=>s.type._parseAsync(new R(t,i,t.path,o)))).then(i=>S.mergeArray(r,i));const a=[...t.data].map((i,o)=>s.type._parseSync(new R(t,i,t.path,o)));return S.mergeArray(r,a)}get element(){return this._def.type}min(e,t){return new $({...this._def,minLength:{value:e,message:p.toString(t)}})}max(e,t){return new $({...this._def,maxLength:{value:e,message:p.toString(t)}})}length(e,t){return new $({...this._def,exactLength:{value:e,message:p.toString(t)}})}nonempty(e){return this.min(1,e)}}$.create=(n,e)=>new $({type:n,minLength:null,maxLength:null,exactLength:null,typeName:m.ZodArray,...g(e)});function F(n){if(n instanceof x){const e={};for(const t in n.shape){const r=n.shape[t];e[t]=M.create(F(r))}return new x({...n._def,shape:()=>e})}else return n instanceof $?new $({...n._def,type:F(n.element)}):n instanceof M?M.create(F(n.unwrap())):n instanceof J?J.create(F(n.unwrap())):n instanceof V?V.create(n.items.map(e=>F(e))):n}class x extends _{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=v.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==f.object){const l=this._getOrReturnCtx(e);return u(l,{code:d.invalid_type,expected:f.object,received:l.parsedType}),y}const{status:r,ctx:s}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof L&&this._def.unknownKeys==="strip"))for(const l in s.data)i.includes(l)||o.push(l);const c=[];for(const l of i){const h=a[l],w=s.data[l];c.push({key:{status:"valid",value:l},value:h._parse(new R(s,w,s.path,l)),alwaysSet:l in s.data})}if(this._def.catchall instanceof L){const l=this._def.unknownKeys;if(l==="passthrough")for(const h of o)c.push({key:{status:"valid",value:h},value:{status:"valid",value:s.data[h]}});else if(l==="strict")o.length>0&&(u(s,{code:d.unrecognized_keys,keys:o}),r.dirty());else if(l!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const l=this._def.catchall;for(const h of o){const w=s.data[h];c.push({key:{status:"valid",value:h},value:l._parse(new R(s,w,s.path,h)),alwaysSet:h in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const l=[];for(const h of c){const w=await h.key,P=await h.value;l.push({key:w,value:P,alwaysSet:h.alwaysSet})}return l}).then(l=>S.mergeObjectSync(r,l)):S.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(e){return p.errToObj,new x({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{const s=this._def.errorMap?.(t,r).message??r.defaultError;return t.code==="unrecognized_keys"?{message:p.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new x({...this._def,unknownKeys:"strip"})}passthrough(){return new x({...this._def,unknownKeys:"passthrough"})}extend(e){return new x({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new x({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:m.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new x({...this._def,catchall:e})}pick(e){const t={};for(const r of v.objectKeys(e))e[r]&&this.shape[r]&&(t[r]=this.shape[r]);return new x({...this._def,shape:()=>t})}omit(e){const t={};for(const r of v.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new x({...this._def,shape:()=>t})}deepPartial(){return F(this)}partial(e){const t={};for(const r of v.objectKeys(this.shape)){const s=this.shape[r];e&&!e[r]?t[r]=s:t[r]=s.optional()}return new x({...this._def,shape:()=>t})}required(e){const t={};for(const r of v.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let a=this.shape[r];for(;a instanceof M;)a=a._def.innerType;t[r]=a}return new x({...this._def,shape:()=>t})}keyof(){return Ge(v.objectKeys(this.shape))}}x.create=(n,e)=>new x({shape:()=>n,unknownKeys:"strip",catchall:L.create(),typeName:m.ZodObject,...g(e)});x.strictCreate=(n,e)=>new x({shape:()=>n,unknownKeys:"strict",catchall:L.create(),typeName:m.ZodObject,...g(e)});x.lazycreate=(n,e)=>new x({shape:n,unknownKeys:"strip",catchall:L.create(),typeName:m.ZodObject,...g(e)});class ae extends _{_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;function s(a){for(const o of a)if(o.result.status==="valid")return o.result;for(const o of a)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const i=a.map(o=>new j(o.ctx.common.issues));return u(t,{code:d.invalid_union,unionErrors:i}),y}if(t.common.async)return Promise.all(r.map(async a=>{const i={...t,common:{...t.common,issues:[]},parent:null};return{result:await a._parseAsync({data:t.data,path:t.path,parent:i}),ctx:i}})).then(s);{let a;const i=[];for(const c of r){const l={...t,common:{...t.common,issues:[]},parent:null},h=c._parseSync({data:t.data,path:t.path,parent:l});if(h.status==="valid")return h;h.status==="dirty"&&!a&&(a={result:h,ctx:l}),l.common.issues.length&&i.push(l.common.issues)}if(a)return t.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(c=>new j(c));return u(t,{code:d.invalid_union,unionErrors:o}),y}}get options(){return this._def.options}}ae.create=(n,e)=>new ae({options:n,typeName:m.ZodUnion,...g(e)});function ke(n,e){const t=Z(n),r=Z(e);if(n===e)return{valid:!0,data:n};if(t===f.object&&r===f.object){const s=v.objectKeys(e),a=v.objectKeys(n).filter(o=>s.indexOf(o)!==-1),i={...n,...e};for(const o of a){const c=ke(n[o],e[o]);if(!c.valid)return{valid:!1};i[o]=c.data}return{valid:!0,data:i}}else if(t===f.array&&r===f.array){if(n.length!==e.length)return{valid:!1};const s=[];for(let a=0;a<n.length;a++){const i=n[a],o=e[a],c=ke(i,o);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return t===f.date&&r===f.date&&+n==+e?{valid:!0,data:n}:{valid:!1}}class ie extends _{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(a,i)=>{if(Ee(a)||Ee(i))return y;const o=ke(a.value,i.value);return o.valid?((Ze(a)||Ze(i))&&t.dirty(),{status:t.value,value:o.data}):(u(r,{code:d.invalid_intersection_types}),y)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([a,i])=>s(a,i)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}ie.create=(n,e,t)=>new ie({left:n,right:e,typeName:m.ZodIntersection,...g(t)});class V extends _{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.array)return u(r,{code:d.invalid_type,expected:f.array,received:r.parsedType}),y;if(r.data.length<this._def.items.length)return u(r,{code:d.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),y;!this._def.rest&&r.data.length>this._def.items.length&&(u(r,{code:d.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...r.data].map((i,o)=>{const c=this._def.items[o]||this._def.rest;return c?c._parse(new R(r,i,r.path,o)):null}).filter(i=>!!i);return r.common.async?Promise.all(a).then(i=>S.mergeArray(t,i)):S.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new V({...this._def,rest:e})}}V.create=(n,e)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new V({items:n,typeName:m.ZodTuple,rest:null,...g(e)})};class oe extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.object)return u(r,{code:d.invalid_type,expected:f.object,received:r.parsedType}),y;const s=[],a=this._def.keyType,i=this._def.valueType;for(const o in r.data)s.push({key:a._parse(new R(r,o,r.path,o)),value:i._parse(new R(r,r.data[o],r.path,o)),alwaysSet:o in r.data});return r.common.async?S.mergeObjectAsync(t,s):S.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof _?new oe({keyType:e,valueType:t,typeName:m.ZodRecord,...g(r)}):new oe({keyType:D.create(),valueType:e,typeName:m.ZodRecord,...g(t)})}}class Be extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.map)return u(r,{code:d.invalid_type,expected:f.map,received:r.parsedType}),y;const s=this._def.keyType,a=this._def.valueType,i=[...r.data.entries()].map(([o,c],l)=>({key:s._parse(new R(r,o,r.path,[l,"key"])),value:a._parse(new R(r,c,r.path,[l,"value"]))}));if(r.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const c of i){const l=await c.key,h=await c.value;if(l.status==="aborted"||h.status==="aborted")return y;(l.status==="dirty"||h.status==="dirty")&&t.dirty(),o.set(l.value,h.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const c of i){const l=c.key,h=c.value;if(l.status==="aborted"||h.status==="aborted")return y;(l.status==="dirty"||h.status==="dirty")&&t.dirty(),o.set(l.value,h.value)}return{status:t.value,value:o}}}}Be.create=(n,e,t)=>new Be({valueType:e,keyType:n,typeName:m.ZodMap,...g(t)});class ee extends _{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.set)return u(r,{code:d.invalid_type,expected:f.set,received:r.parsedType}),y;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(u(r,{code:d.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(u(r,{code:d.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const a=this._def.valueType;function i(c){const l=new Set;for(const h of c){if(h.status==="aborted")return y;h.status==="dirty"&&t.dirty(),l.add(h.value)}return{status:t.value,value:l}}const o=[...r.data.values()].map((c,l)=>a._parse(new R(r,c,r.path,l)));return r.common.async?Promise.all(o).then(c=>i(c)):i(o)}min(e,t){return new ee({...this._def,minSize:{value:e,message:p.toString(t)}})}max(e,t){return new ee({...this._def,maxSize:{value:e,message:p.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}ee.create=(n,e)=>new ee({valueType:n,minSize:null,maxSize:null,typeName:m.ZodSet,...g(e)});class ze extends _{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})}}ze.create=(n,e)=>new ze({getter:n,typeName:m.ZodLazy,...g(e)});class Ue extends _{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return u(t,{received:t.data,code:d.invalid_literal,expected:this._def.value}),y}return{status:"valid",value:e.data}}get value(){return this._def.value}}Ue.create=(n,e)=>new Ue({value:n,typeName:m.ZodLiteral,...g(e)});function Ge(n,e){return new z({values:n,typeName:m.ZodEnum,...g(e)})}class z extends _{_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return u(t,{expected:v.joinValues(r),received:t.parsedType,code:d.invalid_type}),y}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return u(t,{received:t.data,code:d.invalid_enum_value,options:r}),y}return A(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return z.create(e,{...this._def,...t})}exclude(e,t=this._def){return z.create(this.options.filter(r=>!e.includes(r)),{...this._def,...t})}}z.create=Ge;class Je extends _{_parse(e){const t=v.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==f.string&&r.parsedType!==f.number){const s=v.objectValues(t);return u(r,{expected:v.joinValues(s),received:r.parsedType,code:d.invalid_type}),y}if(this._cache||(this._cache=new Set(v.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const s=v.objectValues(t);return u(r,{received:r.data,code:d.invalid_enum_value,options:s}),y}return A(e.data)}get enum(){return this._def.values}}Je.create=(n,e)=>new Je({values:n,typeName:m.ZodNativeEnum,...g(e)});class ce extends _{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.promise&&t.common.async===!1)return u(t,{code:d.invalid_type,expected:f.promise,received:t.parsedType}),y;const r=t.parsedType===f.promise?t.data:Promise.resolve(t.data);return A(r.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}ce.create=(n,e)=>new ce({type:n,typeName:m.ZodPromise,...g(e)});class U extends _{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===m.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=this._def.effect||null,a={addIssue:i=>{u(r,i),i.fatal?t.abort():t.dirty()},get path(){return r.path}};if(a.addIssue=a.addIssue.bind(a),s.type==="preprocess"){const i=s.transform(r.data,a);if(r.common.async)return Promise.resolve(i).then(async o=>{if(t.value==="aborted")return y;const c=await this._def.schema._parseAsync({data:o,path:r.path,parent:r});return c.status==="aborted"?y:c.status==="dirty"||t.value==="dirty"?H(c.value):c});{if(t.value==="aborted")return y;const o=this._def.schema._parseSync({data:i,path:r.path,parent:r});return o.status==="aborted"?y:o.status==="dirty"||t.value==="dirty"?H(o.value):o}}if(s.type==="refinement"){const i=o=>{const c=s.refinement(o,a);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?y:(o.status==="dirty"&&t.dirty(),i(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>o.status==="aborted"?y:(o.status==="dirty"&&t.dirty(),i(o.value).then(()=>({status:t.value,value:o.value}))))}if(s.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!B(i))return y;const o=s.transform(i.value,a);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>B(i)?Promise.resolve(s.transform(i.value,a)).then(o=>({status:t.value,value:o})):y);v.assertNever(s)}}U.create=(n,e,t)=>new U({schema:n,typeName:m.ZodEffects,effect:e,...g(t)});U.createWithPreprocess=(n,e,t)=>new U({schema:e,effect:{type:"preprocess",transform:n},typeName:m.ZodEffects,...g(t)});class M extends _{_parse(e){return this._getType(e)===f.undefined?A(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}M.create=(n,e)=>new M({innerType:n,typeName:m.ZodOptional,...g(e)});class J extends _{_parse(e){return this._getType(e)===f.null?A(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}J.create=(n,e)=>new J({innerType:n,typeName:m.ZodNullable,...g(e)});class xe extends _{_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===f.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}xe.create=(n,e)=>new xe({innerType:n,typeName:m.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...g(e)});class be extends _{_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return re(s)?s.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new j(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new j(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}be.create=(n,e)=>new be({innerType:n,typeName:m.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...g(e)});class We extends _{_parse(e){if(this._getType(e)!==f.nan){const r=this._getOrReturnCtx(e);return u(r,{code:d.invalid_type,expected:f.nan,received:r.parsedType}),y}return{status:"valid",value:e.data}}}We.create=n=>new We({typeName:m.ZodNaN,...g(n)});class Jt extends _{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class Te extends _{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?y:a.status==="dirty"?(t.dirty(),H(a.value)):this._def.out._parseAsync({data:a.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?y:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,t){return new Te({in:e,out:t,typeName:m.ZodPipeline})}}class we extends _{_parse(e){const t=this._def.innerType._parse(e),r=s=>(B(s)&&(s.value=Object.freeze(s.value)),s);return re(t)?t.then(s=>r(s)):r(t)}unwrap(){return this._def.innerType}}we.create=(n,e)=>new we({innerType:n,typeName:m.ZodReadonly,...g(e)});var m;(function(n){n.ZodString="ZodString",n.ZodNumber="ZodNumber",n.ZodNaN="ZodNaN",n.ZodBigInt="ZodBigInt",n.ZodBoolean="ZodBoolean",n.ZodDate="ZodDate",n.ZodSymbol="ZodSymbol",n.ZodUndefined="ZodUndefined",n.ZodNull="ZodNull",n.ZodAny="ZodAny",n.ZodUnknown="ZodUnknown",n.ZodNever="ZodNever",n.ZodVoid="ZodVoid",n.ZodArray="ZodArray",n.ZodObject="ZodObject",n.ZodUnion="ZodUnion",n.ZodDiscriminatedUnion="ZodDiscriminatedUnion",n.ZodIntersection="ZodIntersection",n.ZodTuple="ZodTuple",n.ZodRecord="ZodRecord",n.ZodMap="ZodMap",n.ZodSet="ZodSet",n.ZodFunction="ZodFunction",n.ZodLazy="ZodLazy",n.ZodLiteral="ZodLiteral",n.ZodEnum="ZodEnum",n.ZodEffects="ZodEffects",n.ZodNativeEnum="ZodNativeEnum",n.ZodOptional="ZodOptional",n.ZodNullable="ZodNullable",n.ZodDefault="ZodDefault",n.ZodCatch="ZodCatch",n.ZodPromise="ZodPromise",n.ZodBranded="ZodBranded",n.ZodPipeline="ZodPipeline",n.ZodReadonly="ZodReadonly"})(m||(m={}));const k=D.create,Q=_e.create,de=ve.create;L.create;const te=$.create,ne=x.create,Wt=ae.create;ie.create;V.create;const Ae=oe.create,Ye=z.create;ce.create;M.create;J.create;const Xe=Ye(["Data","Text","Int","Float","Decimal","Check","Date","Time","Datetime","Duration","DateRange","JSON","Code","Link","Doctype","Attach","Currency","Quantity","Select"]),Ke={Data:{component:"ATextInput",fieldtype:"Data"},Text:{component:"ATextInput",fieldtype:"Text"},Int:{component:"ANumericInput",fieldtype:"Int"},Float:{component:"ANumericInput",fieldtype:"Float"},Decimal:{component:"ADecimalInput",fieldtype:"Decimal"},Check:{component:"ACheckbox",fieldtype:"Check"},Date:{component:"ADatePicker",fieldtype:"Date"},Time:{component:"ATimeInput",fieldtype:"Time"},Datetime:{component:"ADatetimePicker",fieldtype:"Datetime"},Duration:{component:"ADurationInput",fieldtype:"Duration"},DateRange:{component:"ADateRangePicker",fieldtype:"DateRange"},JSON:{component:"ACodeEditor",fieldtype:"JSON"},Code:{component:"ACodeEditor",fieldtype:"Code"},Link:{component:"ALink",fieldtype:"Link"},Doctype:{component:"ATable",fieldtype:"Doctype"},Attach:{component:"AFileAttach",fieldtype:"Attach"},Currency:{component:"ACurrencyInput",fieldtype:"Currency"},Quantity:{component:"AQuantityInput",fieldtype:"Quantity"},Select:{component:"ADropdown",fieldtype:"Select"}};function Ht(n){return Ke[n]?.component??"ATextInput"}const et=Wt([k(),te(k()),Ae(k(),de())]),tt=ne({errorMessage:k()}).passthrough(),ue=ne({fieldname:k().min(1),fieldtype:Xe,component:k().optional(),label:k().optional(),width:k().optional(),align:Ye(["left","center","right","start","end"]).optional(),required:Q().optional(),readOnly:Q().optional(),edit:Q().optional(),hidden:Q().optional(),value:de().optional(),default:de().optional(),options:et.optional(),mask:k().optional(),validation:tt.optional()}),nt=ne({label:k().min(1),handler:k().min(1),requiredFields:te(k()).optional(),allowedStates:te(k()).optional(),confirm:Q().optional(),args:Ae(k(),de()).optional()}),rt=ne({states:te(k()).optional(),actions:Ae(k(),nt).optional()}),Ce=ne({name:k().min(1),slug:k().min(1).optional(),tableName:k().optional(),fields:te(ue),workflow:rt.optional(),inherits:k().optional(),listDoctype:k().optional(),parentDoctype:k().optional()});function Qt(n){const e=ue.safeParse(n);return e.success?{success:!0,errors:[]}:{success:!1,errors:e.error.issues.map(t=>({path:t.path,message:t.message}))}}function Ne(n){const e=Ce.safeParse(n);return e.success?{success:!0,errors:[]}:{success:!1,errors:e.error.issues.map(t=>({path:t.path,message:t.message}))}}function Gt(n){return ue.parse(n)}function Oe(n){return Ce.parse(n)}function Yt(n){return n.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function Xt(n){return n.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)}function Kt(n){return n.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ")}function st(n){const e=n.replace(/([A-Z])/g," $1").trim();return e.charAt(0).toUpperCase()+e.slice(1)}function en(n){return n.split(/[-_\s]+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function Y(n){return n.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}function at(n){return n.replace(/([a-z])([A-Z])/g,"$1_$2").replace(/[\s-]+/g,"_").toLowerCase()}const it={String:{component:"ATextInput",fieldtype:"Data"},Int:{component:"ANumericInput",fieldtype:"Int"},Float:{component:"ANumericInput",fieldtype:"Float"},Boolean:{component:"ACheckbox",fieldtype:"Check"},ID:{component:"ATextInput",fieldtype:"Data"}},ot={BigFloat:{component:"ADecimalInput",fieldtype:"Decimal"},BigDecimal:{component:"ADecimalInput",fieldtype:"Decimal"},Decimal:{component:"ADecimalInput",fieldtype:"Decimal"},BigInt:{component:"ANumericInput",fieldtype:"Int"},Long:{component:"ANumericInput",fieldtype:"Int"},UUID:{component:"ATextInput",fieldtype:"Data"},DateTime:{component:"ADatetimePicker",fieldtype:"Datetime"},Datetime:{component:"ADatetimePicker",fieldtype:"Datetime"},Date:{component:"ADatePicker",fieldtype:"Date"},Time:{component:"ATimeInput",fieldtype:"Time"},Interval:{component:"ADurationInput",fieldtype:"Duration"},Duration:{component:"ADurationInput",fieldtype:"Duration"},JSON:{component:"ACodeEditor",fieldtype:"JSON"},JSONObject:{component:"ACodeEditor",fieldtype:"JSON"},JsonNode:{component:"ACodeEditor",fieldtype:"JSON"}},tn=new Set(["Cursor"]);function nn(n){const e={...ot};for(const[t,r]of Object.entries(it))e[t]=r;if(n)for(const[t,r]of Object.entries(n))e[t]={component:r.component??"ATextInput",fieldtype:r.fieldtype??"Data"};return e}const rn=["Connection","Edge","Input","Patch","Payload","Condition","Filter","OrderBy","Aggregate","AggregateResult","AggregateFilter","DeleteResponse","InsertResponse","UpdateResponse","MutationResponse"],sn=new Set(["Query","Mutation","Subscription"]);function ct(n,e){if(n.startsWith("__")||sn.has(n)||n==="Node")return!1;for(const r of rn)if(n.endsWith(r))return!1;const t=e.getFields();return Object.keys(t).length!==0}const an=new Set(["nodeId","__typename","clientMutationId"]);function dt(n,e,t){return!an.has(n)}function Se(n){let e=!1,t=!1,r=n;return T.isNonNullType(r)&&(e=!0,r=r.ofType),T.isListType(r)&&(t=!0,r=r.ofType,T.isNonNullType(r)&&(r=r.ofType)),{namedType:r,required:e,isList:t}}function on(n){const e=n.getFields().edges;if(!e)return;const{namedType:t,isList:r}=Se(e.type);if(!r||!T.isObjectType(t))return;const s=t.getFields().node;if(!s)return;const{namedType:a}=Se(s.type);if(T.isObjectType(a))return a.name}function lt(n,e,t,r={}){const{namedType:s,required:a,isList:i}=Se(e.type),o=nn(r.customScalars),c={fieldname:n,label:st(n),component:"ATextInput",fieldtype:"Data"};if(a&&(c.required=!0),T.isScalarType(s)){if(tn.has(s.name))return c._unmapped=!0,r.includeUnmappedMeta&&(c._graphqlType=s.name),c;const l=o[s.name];return l?(c.component=l.component,c.fieldtype=l.fieldtype):(c._unmapped=!0,r.includeUnmappedMeta&&(c._graphqlType=s.name)),c}if(T.isEnumType(s))return c.component="ADropdown",c.fieldtype="Select",c.options=s.getValues().map(l=>l.name),c;if(T.isObjectType(s)){if(!i&&t.has(s.name))return c.component="ALink",c.fieldtype="Link",c.options=Y(s.name),c;const l=on(s);return l&&t.has(l)?(c.component="ATable",c.fieldtype="Doctype",c.options=Y(l),c):i&&t.has(s.name)?(c.component="ATable",c.fieldtype="Doctype",c.options=Y(s.name),c):(c._unmapped=!0,r.includeUnmappedMeta&&(c._graphqlType=s.name),c)}return c._unmapped=!0,r.includeUnmappedMeta&&(c._graphqlType=s.name),c}function cn(n,e={}){const t=dn(n),r=t.getTypeMap(),s=new Set,a=t.getQueryType(),i=t.getMutationType(),o=t.getSubscriptionType();a&&s.add(a.name),i&&s.add(i.name),o&&s.add(o.name);const c=e.isEntityType??ct,l=new Set;for(const[b,C]of Object.entries(r))T.isObjectType(C)&&(s.has(b)||c(b,C)&&l.add(b));let h=l;if(e.include){const b=new Set(e.include);h=new Set([...l].filter(C=>b.has(C)))}if(e.exclude){const b=new Set(e.exclude);h=new Set([...h].filter(C=>!b.has(C)))}const w=e.isEntityField??dt,P=e.deriveTableName??(b=>at(b)),I=[];for(const b of h){const C=r[b];if(!T.isObjectType(C))continue;const _t=C.getFields(),Re=e.typeOverrides?.[b],vt=Object.entries(_t).filter(([N,W])=>w(N,W,C)).map(([N,W])=>{if(e.classifyField){const q=e.classifyField(N,W,C);if(q!=null)return{fieldname:N,label:q.label??N,component:q.component??"ATextInput",fieldtype:q.fieldtype??"Data",...q}}const he=lt(N,W,l,e);return Re?.[N]?{...he,...Re[N]}:he}).map(N=>{if(!e.includeUnmappedMeta){const{_graphqlType:W,_unmapped:he,...q}=N;return q}return N}),pe={name:b,slug:Y(b),fields:vt},Ie=P(b);Ie&&(pe.tableName=Ie),e.includeUnmappedMeta&&(pe._graphqlTypeName=b),I.push(pe)}return I}function dn(n){return typeof n=="string"?T.buildSchema(n):T.buildClientSchema(n)}const O=new Map;class le extends Error{constructor(e,t){const r=t.map(s=>` ${s.path.join(".")}: ${s.message}`).join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@stonecrop/schema"),D=require("node:fs"),C=require("node:path"),R=require("postgraphile/utils"),m=require("postgraphile/grafast"),p=new Map;class $ extends Error{constructor(e,r){const o=r.map(n=>` ${n.path.join(".")}: ${n.message}`).join(`
|
|
2
2
|
`);super(`Invalid doctype definition in ${e}:
|
|
3
|
-
${
|
|
4
|
-
${
|
|
5
|
-
`)}`);return{valid:!0}};function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type FieldMeta {
|
|
3
|
+
${o}`),this.file=e,this.errors=r,this.name="DoctypeValidationError"}}function M(t,e={}){const r=D.readdirSync(t);for(const o of r){const n=C.join(t,o);D.statSync(n).isDirectory()?M(n,e):o.endsWith(".json")&&T(n,e)}}function T(t,e){const r=D.readFileSync(t,"utf-8");let o;try{o=JSON.parse(r)}catch(i){const s={path:[],message:`Invalid JSON: ${i instanceof Error?i.message:String(i)}`};if(e.continueOnError){e.onError?.(t,[s]);return}throw new $(t,[s])}const n=a.validateDoctype(o);if(!n.success){if(e.continueOnError){e.onError?.(t,n.errors);return}throw new $(t,n.errors)}const c=a.parseDoctype(o);p.set(c.name,c)}function E(t,e={}){for(const[r,o]of Object.entries(t)){const n={...o,name:r},c=a.validateDoctype(n);if(!c.success){if(e.continueOnError){e.onError?.(r,c.errors);continue}throw new $(r,c.errors)}const i=a.parseDoctype(n);p.set(i.name,i)}}function S(t){return p.get(t)}function N(){return Array.from(p.values())}function B(t){return p.has(t)}function L(){p.clear()}function _(){const t=[];for(const e of p.values()){e.inherits&&!p.has(e.inherits)&&t.push({path:[e.name,"inherits"],message:`References unknown doctype: ${e.inherits}`}),e.listDoctype&&!p.has(e.listDoctype)&&t.push({path:[e.name,"listDoctype"],message:`References unknown doctype: ${e.listDoctype}`}),e.parentDoctype&&!p.has(e.parentDoctype)&&t.push({path:[e.name,"parentDoctype"],message:`References unknown doctype: ${e.parentDoctype}`});for(const r of e.fields)r.fieldtype==="Link"&&typeof r.options=="string"&&(p.has(r.options)||t.push({path:[e.name,"fields",r.fieldname,"options"],message:`Link references unknown doctype: ${r.options}`}))}return t}const w=new Map;function A(t,e){w.set(t,e)}function P(t){return w.get(t)}function x(t){return w.has(t)}function I(){w.clear()}const J=async(t,e)=>{const[r]=t,{doctype:o}=e,n=[];for(const c of o.fields)c.required&&(r[c.fieldname]===void 0||r[c.fieldname]===null)&&n.push(c.label??c.fieldname);if(n.length>0)throw new Error(`Missing required fields: ${n.join(", ")}`);return{valid:!0}},H=async(t,e)=>{const[r]=t,{doctype:o}=e,n=[];for(const c of o.fields){const i=r[c.fieldname];if(i==null)continue;const s=G(c.fieldname,i,c.fieldtype);s&&n.push(s)}if(n.length>0)throw new Error(`Field type validation failed:
|
|
4
|
+
${n.join(`
|
|
5
|
+
`)}`);return{valid:!0}};function G(t,e,r){switch(r){case"Int":if(typeof e!="number"||!Number.isInteger(e))return`${t}: expected integer, got ${typeof e}`;break;case"Float":case"Decimal":case"Currency":case"Quantity":if(typeof e!="number"&&typeof e!="string")return`${t}: expected number, got ${typeof e}`;break;case"Check":if(typeof e!="boolean")return`${t}: expected boolean, got ${typeof e}`;break;case"Data":case"Text":case"Code":case"Link":if(typeof e!="string")return`${t}: expected string, got ${typeof e}`;break;case"Date":case"Time":case"Datetime":if(typeof e!="string"&&!(e instanceof Date))return`${t}: expected date string or Date, got ${typeof e}`;break;case"JSON":if(typeof e!="object")return`${t}: expected object, got ${typeof e}`;break;case"Table":if(!Array.isArray(e))return`${t}: expected array, got ${typeof e}`;break}return null}const Q=async()=>({ok:!0}),k={validateRequiredFields:J,validateFieldTypes:H,noop:Q};function W(){for(const[t,e]of Object.entries(k))A(t,e)}const v=t=>{const e=t.inflection?.recordFieldName??U,r=t.inflection?.connectionFieldName??V,o=t.inflection?.orderByTypeName??K;return R.extendSchema(()=>({typeDefs:R.gql`
|
|
6
|
+
type StonecropFieldMeta {
|
|
9
7
|
fieldname: String!
|
|
10
8
|
fieldtype: String!
|
|
11
9
|
label: String
|
|
@@ -13,7 +11,7 @@ ${s.join(`
|
|
|
13
11
|
options: JSON
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
type
|
|
14
|
+
type StonecropActionDefinition {
|
|
17
15
|
label: String!
|
|
18
16
|
handler: String!
|
|
19
17
|
requiredFields: [String!]
|
|
@@ -22,64 +20,70 @@ ${s.join(`
|
|
|
22
20
|
args: JSON
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
type
|
|
23
|
+
type StonecropWorkflowMeta {
|
|
26
24
|
states: [String!]
|
|
27
25
|
actions: JSON
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
type
|
|
28
|
+
type StonecropDoctypeMeta {
|
|
31
29
|
name: String!
|
|
32
30
|
tableName: String
|
|
33
|
-
fields: [
|
|
34
|
-
workflow:
|
|
31
|
+
fields: [StonecropFieldMeta!]!
|
|
32
|
+
workflow: StonecropWorkflowMeta
|
|
35
33
|
listDoctype: String
|
|
36
34
|
parentDoctype: String
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
type
|
|
37
|
+
type StonecropRecordResult {
|
|
40
38
|
data: JSON
|
|
41
39
|
doctype: String!
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
type
|
|
42
|
+
type StonecropRecordsResult {
|
|
45
43
|
data: [JSON!]!
|
|
46
44
|
doctype: String!
|
|
47
45
|
count: Int!
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
type
|
|
48
|
+
type StonecropActionResult {
|
|
51
49
|
success: Boolean!
|
|
52
50
|
data: JSON
|
|
53
51
|
error: String
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
type Query {
|
|
57
|
-
stonecropMeta(doctype: String!):
|
|
58
|
-
stonecropAllMeta: [
|
|
59
|
-
stonecropRecord(doctype: String!, id: String!):
|
|
60
|
-
stonecropRecords(
|
|
54
|
+
extend type Query {
|
|
55
|
+
stonecropMeta(doctype: String!): StonecropDoctypeMeta
|
|
56
|
+
stonecropAllMeta: [StonecropDoctypeMeta!]!
|
|
57
|
+
stonecropRecord(doctype: String!, id: String!): StonecropRecordResult
|
|
58
|
+
stonecropRecords(
|
|
59
|
+
doctype: String!
|
|
60
|
+
filters: JSON
|
|
61
|
+
orderBy: String
|
|
62
|
+
limit: Int
|
|
63
|
+
offset: Int
|
|
64
|
+
): StonecropRecordsResult
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
type Mutation {
|
|
64
|
-
stonecropAction(doctype: String!, action: String!, args: JSON):
|
|
67
|
+
extend type Mutation {
|
|
68
|
+
stonecropAction(doctype: String!, action: String!, args: JSON): StonecropActionResult!
|
|
65
69
|
}
|
|
66
|
-
`,objects:{Query:{plans:{stonecropMeta(
|
|
70
|
+
`,objects:{Query:{plans:{stonecropMeta(n,c){const i=c.getRaw().doctype;return m.lambda(i,s=>S(s)??null)},stonecropAllMeta(){return m.constant(N())},stonecropRecord(n,c){const i=c.getRaw().doctype,s=c.getRaw().id;return m.loadOne(m.object({doctype:i,id:s}),async y=>await Promise.all(y.map(async d=>{const f=S(d.doctype);if(!f)throw new Error(`Unknown doctype: ${d.doctype}`);if(!f.tableName)throw new Error(`Doctype ${d.doctype} has no table mapping`);const u=Y(f,e),g=await t.executor.query(u,{id:d.id});return{data:X(g,f,e),doctype:d.doctype}})))},stonecropRecords(n,c){const i=c.getRaw(),s=i.doctype,y=i.filters,d=i.orderBy,f=i.limit,u=i.offset;return m.loadOne(m.object({doctype:s,filters:y,orderBy:d,limit:f,offset:u}),async g=>await Promise.all(g.map(async l=>{const b=S(l.doctype);if(!b)throw new Error(`Unknown doctype: ${l.doctype}`);if(!b.tableName)throw new Error(`Doctype ${l.doctype} has no table mapping`);const O=z(b,{limit:l.limit,offset:l.offset,orderBy:l.orderBy},r,o),h=await t.executor.query(O,{limit:l.limit,offset:l.offset,orderBy:l.orderBy}),j=Z(h,b,r);return{data:j,doctype:l.doctype,count:j.length}})))}}},Mutation:{plans:{stonecropAction(n,c){const i=c.getRaw(),s=i.doctype,y=i.action,d=i.args;return m.loadOne(m.object({doctype:s,action:y,actionArgs:d}),async f=>await Promise.all(f.map(async u=>{const g=S(u.doctype);if(!g)return{success:!1,data:null,error:`Unknown doctype: ${u.doctype}`};const l=g.workflow?.actions?.[u.action];if(!l)return{success:!1,data:null,error:`Unknown action: ${u.action} on ${u.doctype}`};const b=P(l.handler);if(!b)return{success:!1,data:null,error:`Handler not registered: ${l.handler}`};const O={doctype:g,executor:t.executor};try{return{success:!0,data:await b(u.actionArgs??[],O),error:null}}catch(h){return{success:!1,data:null,error:h instanceof Error?h.message:String(h)}}})))}}}}}))};function q(t){return t.replace(/_([a-z])/g,(e,r)=>r.toUpperCase())}function F(t){const e=q(t);return e.charAt(0).toUpperCase()+e.slice(1)}function U(t){const e=t.replace(/s$/,"");return`${q(e)}ById`}function V(t){return`all${F(t)}`}function K(t){return`${F(t)}OrderBy`}function Y(t,e){const r=t.fields.map(n=>n.fieldname).join(`
|
|
67
71
|
`);return`
|
|
68
72
|
query GetRecord($id: UUID!) {
|
|
69
|
-
${
|
|
70
|
-
${
|
|
73
|
+
${e(t.tableName)}(id: $id) {
|
|
74
|
+
${r}
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
|
-
`}function
|
|
74
|
-
`),r=
|
|
75
|
-
query GetRecords($limit: Int, $offset: Int, $orderBy: [${
|
|
76
|
-
${
|
|
77
|
+
`}function z(t,e,r,o){const n=t.fields.map(d=>d.fieldname).join(`
|
|
78
|
+
`),c=r(t.tableName),i=o(t.tableName),s=[];e.limit&&s.push("first: $limit"),e.offset&&s.push("offset: $offset"),e.orderBy&&s.push("orderBy: $orderBy");const y=s.length>0?`(${s.join(", ")})`:"";return`
|
|
79
|
+
query GetRecords($limit: Int, $offset: Int, $orderBy: [${i}!]) {
|
|
80
|
+
${c}${y} {
|
|
77
81
|
nodes {
|
|
78
|
-
${
|
|
82
|
+
${n}
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
|
-
`}function
|
|
86
|
+
`}function X(t,e,r){const o=r(e.tableName);return t[o]}function Z(t,e,r){const o=r(e.tableName);return t[o]?.nodes??[]}class ee{endpoint;headers;metaCache=new Map;constructor(e){this.endpoint=e.endpoint,this.headers={"Content-Type":"application/json",...e.headers}}async query(e,r){const n=await(await fetch(this.endpoint,{method:"POST",headers:this.headers,body:JSON.stringify({query:e,variables:r})})).json();if(n.errors?.length)throw new Error(n.errors[0].message);return n.data}async mutate(e,r){return this.query(e,r)}async getMeta(e){const r=this.metaCache.get(e.doctype);if(r)return r;const o=await this.query(`
|
|
83
87
|
query GetMeta($doctype: String!) {
|
|
84
88
|
stonecropMeta(doctype: $doctype) {
|
|
85
89
|
name
|
|
@@ -105,7 +109,7 @@ ${s.join(`
|
|
|
105
109
|
parentDoctype
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
|
-
`,{doctype:e.doctype});return
|
|
112
|
+
`,{doctype:e.doctype});return o.stonecropMeta&&this.metaCache.set(e.doctype,o.stonecropMeta),o.stonecropMeta}async getAllMeta(){const e=await this.query(`
|
|
109
113
|
query GetAllMeta {
|
|
110
114
|
stonecropAllMeta {
|
|
111
115
|
name
|
|
@@ -131,13 +135,13 @@ ${s.join(`
|
|
|
131
135
|
parentDoctype
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
|
-
`);for(const
|
|
138
|
+
`);for(const r of e.stonecropAllMeta)this.metaCache.set(r.name,r);return e.stonecropAllMeta}async getRecord(e,r){return(await this.query(`
|
|
135
139
|
query GetRecord($doctype: String!, $id: String!) {
|
|
136
140
|
stonecropRecord(doctype: $doctype, id: $id) {
|
|
137
141
|
data
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
|
-
`,{doctype:e.name,id:
|
|
144
|
+
`,{doctype:e.name,id:r})).stonecropRecord.data}async getRecords(e,r){return(await this.query(`
|
|
141
145
|
query GetRecords(
|
|
142
146
|
$doctype: String!
|
|
143
147
|
$filters: JSON
|
|
@@ -156,7 +160,7 @@ ${s.join(`
|
|
|
156
160
|
count
|
|
157
161
|
}
|
|
158
162
|
}
|
|
159
|
-
`,{doctype:e.name,...
|
|
163
|
+
`,{doctype:e.name,...r})).stonecropRecords.data}async runAction(e,r,o){return(await this.query(`
|
|
160
164
|
mutation RunAction($doctype: String!, $action: String!, $args: JSON) {
|
|
161
165
|
stonecropAction(doctype: $doctype, action: $action, args: $args) {
|
|
162
166
|
success
|
|
@@ -164,4 +168,4 @@ ${s.join(`
|
|
|
164
168
|
error
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
|
-
`,{doctype:e.name,action:
|
|
171
|
+
`,{doctype:e.name,action:r,args:o})).stonecropAction}clearMetaCache(){this.metaCache.clear()}}Object.defineProperty(exports,"ActionDefinition",{enumerable:!0,get:()=>a.ActionDefinition});Object.defineProperty(exports,"DoctypeMeta",{enumerable:!0,get:()=>a.DoctypeMeta});Object.defineProperty(exports,"FieldMeta",{enumerable:!0,get:()=>a.FieldMeta});Object.defineProperty(exports,"FieldOptions",{enumerable:!0,get:()=>a.FieldOptions});Object.defineProperty(exports,"FieldValidation",{enumerable:!0,get:()=>a.FieldValidation});Object.defineProperty(exports,"GQL_SCALAR_MAP",{enumerable:!0,get:()=>a.GQL_SCALAR_MAP});Object.defineProperty(exports,"StonecropFieldType",{enumerable:!0,get:()=>a.StonecropFieldType});Object.defineProperty(exports,"TYPE_MAP",{enumerable:!0,get:()=>a.TYPE_MAP});Object.defineProperty(exports,"WELL_KNOWN_SCALARS",{enumerable:!0,get:()=>a.WELL_KNOWN_SCALARS});Object.defineProperty(exports,"WorkflowMeta",{enumerable:!0,get:()=>a.WorkflowMeta});Object.defineProperty(exports,"camelToLabel",{enumerable:!0,get:()=>a.camelToLabel});Object.defineProperty(exports,"camelToSnake",{enumerable:!0,get:()=>a.camelToSnake});Object.defineProperty(exports,"classifyFieldType",{enumerable:!0,get:()=>a.classifyFieldType});Object.defineProperty(exports,"convertGraphQLSchema",{enumerable:!0,get:()=>a.convertGraphQLSchema});Object.defineProperty(exports,"defaultIsEntityField",{enumerable:!0,get:()=>a.defaultIsEntityField});Object.defineProperty(exports,"defaultIsEntityType",{enumerable:!0,get:()=>a.defaultIsEntityType});Object.defineProperty(exports,"getDefaultComponent",{enumerable:!0,get:()=>a.getDefaultComponent});Object.defineProperty(exports,"parseDoctype",{enumerable:!0,get:()=>a.parseDoctype});Object.defineProperty(exports,"parseField",{enumerable:!0,get:()=>a.parseField});Object.defineProperty(exports,"pascalToSnake",{enumerable:!0,get:()=>a.pascalToSnake});Object.defineProperty(exports,"snakeToCamel",{enumerable:!0,get:()=>a.snakeToCamel});Object.defineProperty(exports,"snakeToLabel",{enumerable:!0,get:()=>a.snakeToLabel});Object.defineProperty(exports,"toPascalCase",{enumerable:!0,get:()=>a.toPascalCase});Object.defineProperty(exports,"toSlug",{enumerable:!0,get:()=>a.toSlug});Object.defineProperty(exports,"validateDoctype",{enumerable:!0,get:()=>a.validateDoctype});Object.defineProperty(exports,"validateField",{enumerable:!0,get:()=>a.validateField});exports.DoctypeValidationError=$;exports.StonecropClient=ee;exports.builtinHandlers=k;exports.clearHandlers=I;exports.clearRegistry=L;exports.createStonecropPlugin=v;exports.getAllMeta=N;exports.getHandler=P;exports.getMeta=S;exports.hasHandler=x;exports.hasMeta=B;exports.loadDoctypes=M;exports.loadDoctypesFromObject=E;exports.registerBuiltinHandlers=W;exports.registerHandler=A;exports.validateReferences=_;
|