@inixiative/json-rules 3.17.0 → 3.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Rt from'dayjs';import jb from'dayjs/plugin/isoWeek.js';import Ib from'dayjs/plugin/quarterOfYear.js';import qb from'dayjs/plugin/timezone.js';import Vb from'dayjs/plugin/utc.js';import eR from'dayjs/plugin/isSameOrAfter.js';import tR from'dayjs/plugin/isSameOrBefore.js';import {distance}from'fastest-levenshtein';import {RE2JS}from're2js';var Fs=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var lm=typeof global=="object"&&global&&global.Object===Object&&global,Jn=lm;var pm=typeof self=="object"&&self&&self.Object===Object&&self,dm=Jn||pm||Function("return this")(),oe=dm;var fm=oe.Symbol,Oe=fm;var ll=Object.prototype,um=ll.hasOwnProperty,cm=ll.toString,sn=Oe?Oe.toStringTag:void 0;function mm(e){var t=um.call(e,sn),r=e[sn];try{e[sn]=void 0;var o=!0;}catch{}var n=cm.call(e);return o&&(t?e[sn]=r:delete e[sn]),n}var pl=mm;var gm=Object.prototype,ym=gm.toString;function hm(e){return ym.call(e)}var dl=hm;var wm="[object Null]",Sm="[object Undefined]",fl=Oe?Oe.toStringTag:void 0;function bm(e){return e==null?e===void 0?Sm:wm:fl&&fl in Object(e)?pl(e):dl(e)}var Le=bm;function Rm(e){return e!=null&&typeof e=="object"}var ie=Rm;var Om="[object Symbol]";function xm(e){return typeof e=="symbol"||ie(e)&&Le(e)==Om}var Qr=xm;function Em(e,t){for(var r=-1,o=e==null?0:e.length,n=Array(o);++r<o;)n[r]=t(e[r],r,e);return n}var ul=Em;var $m=Array.isArray,U=$m;var cl=Oe?Oe.prototype:void 0,ml=cl?cl.toString:void 0;function gl(e){if(typeof e=="string")return e;if(U(e))return ul(e,gl)+"";if(Qr(e))return ml?ml.call(e):"";var t=e+"";return t=="0"&&1/e==-Infinity?"-0":t}var yl=gl;function vm(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var J=vm;function Nm(e){return e}var Zr=Nm;var Am="[object AsyncFunction]",Tm="[object Function]",km="[object GeneratorFunction]",Cm="[object Proxy]";function Mm(e){if(!J(e))return false;var t=Le(e);return t==Tm||t==km||t==Am||t==Cm}var Yr=Mm;var Lm=oe["__core-js_shared__"],Qn=Lm;var hl=(function(){var e=/[^.]+$/.exec(Qn&&Qn.keys&&Qn.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""})();function _m(e){return !!hl&&hl in e}var wl=_m;var Dm=Function.prototype,Fm=Dm.toString;function jm(e){if(e!=null){try{return Fm.call(e)}catch{}try{return e+""}catch{}}return ""}var Ct=jm;var Im=/[\\^$.*+?()[\]{}|]/g,qm=/^\[object .+?Constructor\]$/,Vm=Function.prototype,Bm=Object.prototype,Wm=Vm.toString,Um=Bm.hasOwnProperty,Km=RegExp("^"+Wm.call(Um).replace(Im,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Gm(e){if(!J(e)||wl(e))return false;var t=Yr(e)?Km:qm;return t.test(Ct(e))}var Sl=Gm;function zm(e,t){return e?.[t]}var bl=zm;function Hm(e,t){var r=bl(e,t);return Sl(r)?r:void 0}var Ae=Hm;var Jm=Ae(oe,"WeakMap"),Zn=Jm;var Rl=Object.create,Qm=(function(){function e(){}return function(t){if(!J(t))return {};if(Rl)return Rl(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}})(),Ol=Qm;function Zm(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}var xl=Zm;function Ym(e,t){var r=-1,o=e.length;for(t||(t=Array(o));++r<o;)t[r]=e[r];return t}var Yn=Ym;var Xm=800,eg=16,tg=Date.now;function rg(e){var t=0,r=0;return function(){var o=tg(),n=eg-(o-r);if(r=o,n>0){if(++t>=Xm)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var El=rg;function og(e){return function(){return e}}var $l=og;var ng=(function(){try{var e=Ae(Object,"defineProperty");return e({},"",{}),e}catch{}})(),Xr=ng;var ig=Xr?function(e,t){return Xr(e,"toString",{configurable:true,enumerable:false,value:$l(t),writable:true})}:Zr,Pl=ig;var sg=El(Pl),vl=sg;function ag(e,t){for(var r=-1,o=e==null?0:e.length;++r<o&&t(e[r],r,e)!==false;);return e}var Nl=ag;var lg=9007199254740991,pg=/^(?:0|[1-9]\d*)$/;function dg(e,t){var r=typeof e;return t=t??lg,!!t&&(r=="number"||r!="symbol"&&pg.test(e))&&e>-1&&e%1==0&&e<t}var Qt=dg;function fg(e,t,r){t=="__proto__"&&Xr?Xr(e,t,{configurable:true,enumerable:true,value:r,writable:true}):e[t]=r;}var eo=fg;function ug(e,t){return e===t||e!==e&&t!==t}var lt=ug;var cg=Object.prototype,mg=cg.hasOwnProperty;function gg(e,t,r){var o=e[t];(!(mg.call(e,t)&<(o,r))||r===void 0&&!(t in e))&&eo(e,t,r);}var to=gg;function yg(e,t,r,o){var n=!r;r||(r={});for(var i=-1,s=t.length;++i<s;){var a=t[i],l=o?o(r[a],e[a],a,r,e):void 0;l===void 0&&(l=e[a]),n?eo(r,a,l):to(r,a,l);}return r}var pt=yg;var Al=Math.max;function hg(e,t,r){return t=Al(t===void 0?e.length-1:t,0),function(){for(var o=arguments,n=-1,i=Al(o.length-t,0),s=Array(i);++n<i;)s[n]=o[t+n];n=-1;for(var a=Array(t+1);++n<t;)a[n]=o[n];return a[t]=r(s),xl(e,this,a)}}var Tl=hg;function wg(e,t){return vl(Tl(e,t,Zr),e+"")}var kl=wg;var Sg=9007199254740991;function bg(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Sg}var ro=bg;function Rg(e){return e!=null&&ro(e.length)&&!Yr(e)}var dt=Rg;function Og(e,t,r){if(!J(r))return false;var o=typeof t;return (o=="number"?dt(r)&&Qt(t,r.length):o=="string"&&t in r)?lt(r[t],e):false}var Xn=Og;function xg(e){return kl(function(t,r){var o=-1,n=r.length,i=n>1?r[n-1]:void 0,s=n>2?r[2]:void 0;for(i=e.length>3&&typeof i=="function"?(n--,i):void 0,s&&Xn(r[0],r[1],s)&&(i=n<3?void 0:i,n=1),t=Object(t);++o<n;){var a=r[o];a&&e(t,a,o,i);}return t})}var Cl=xg;var Eg=Object.prototype;function $g(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||Eg;return e===r}var oo=$g;function Pg(e,t){for(var r=-1,o=Array(e);++r<e;)o[r]=t(r);return o}var Ml=Pg;var vg="[object Arguments]";function Ng(e){return ie(e)&&Le(e)==vg}var js=Ng;var Ll=Object.prototype,Ag=Ll.hasOwnProperty,Tg=Ll.propertyIsEnumerable,kg=js((function(){return arguments})())?js:function(e){return ie(e)&&Ag.call(e,"callee")&&!Tg.call(e,"callee")},Pr=kg;function Cg(){return false}var _l=Cg;var jl=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Dl=jl&&typeof module=="object"&&module&&!module.nodeType&&module,Mg=Dl&&Dl.exports===jl,Fl=Mg?oe.Buffer:void 0,Lg=Fl?Fl.isBuffer:void 0,_g=Lg||_l,Mt=_g;var Dg="[object Arguments]",Fg="[object Array]",jg="[object Boolean]",Ig="[object Date]",qg="[object Error]",Vg="[object Function]",Bg="[object Map]",Wg="[object Number]",Ug="[object Object]",Kg="[object RegExp]",Gg="[object Set]",zg="[object String]",Hg="[object WeakMap]",Jg="[object ArrayBuffer]",Qg="[object DataView]",Zg="[object Float32Array]",Yg="[object Float64Array]",Xg="[object Int8Array]",ey="[object Int16Array]",ty="[object Int32Array]",ry="[object Uint8Array]",oy="[object Uint8ClampedArray]",ny="[object Uint16Array]",iy="[object Uint32Array]",z={};z[Zg]=z[Yg]=z[Xg]=z[ey]=z[ty]=z[ry]=z[oy]=z[ny]=z[iy]=true;z[Dg]=z[Fg]=z[Jg]=z[jg]=z[Qg]=z[Ig]=z[qg]=z[Vg]=z[Bg]=z[Wg]=z[Ug]=z[Kg]=z[Gg]=z[zg]=z[Hg]=false;function sy(e){return ie(e)&&ro(e.length)&&!!z[Le(e)]}var Il=sy;function ay(e){return function(t){return e(t)}}var no=ay;var ql=typeof exports=="object"&&exports&&!exports.nodeType&&exports,an=ql&&typeof module=="object"&&module&&!module.nodeType&&module,ly=an&&an.exports===ql,Is=ly&&Jn.process,py=(function(){try{var e=an&&an.require&&an.require("util").types;return e||Is&&Is.binding&&Is.binding("util")}catch{}})(),Lt=py;var Vl=Lt&&Lt.isTypedArray,dy=Vl?no(Vl):Il,io=dy;var fy=Object.prototype,uy=fy.hasOwnProperty;function cy(e,t){var r=U(e),o=!r&&Pr(e),n=!r&&!o&&Mt(e),i=!r&&!o&&!n&&io(e),s=r||o||n||i,a=s?Ml(e.length,String):[],l=a.length;for(var d in e)(t||uy.call(e,d))&&!(s&&(d=="length"||n&&(d=="offset"||d=="parent")||i&&(d=="buffer"||d=="byteLength"||d=="byteOffset")||Qt(d,l)))&&a.push(d);return a}var ei=cy;function my(e,t){return function(r){return e(t(r))}}var ti=my;var gy=ti(Object.keys,Object),Bl=gy;var yy=Object.prototype,hy=yy.hasOwnProperty;function wy(e){if(!oo(e))return Bl(e);var t=[];for(var r in Object(e))hy.call(e,r)&&r!="constructor"&&t.push(r);return t}var Wl=wy;function Sy(e){return dt(e)?ei(e):Wl(e)}var ft=Sy;function by(e){var t=[];if(e!=null)for(var r in Object(e))t.push(r);return t}var Ul=by;var Ry=Object.prototype,Oy=Ry.hasOwnProperty;function xy(e){if(!J(e))return Ul(e);var t=oo(e),r=[];for(var o in e)o=="constructor"&&(t||!Oy.call(e,o))||r.push(o);return r}var Kl=xy;function Ey(e){return dt(e)?ei(e,true):Kl(e)}var ut=Ey;var $y=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Py=/^\w*$/;function vy(e,t){if(U(e))return false;var r=typeof e;return r=="number"||r=="symbol"||r=="boolean"||e==null||Qr(e)?true:Py.test(e)||!$y.test(e)||t!=null&&e in Object(t)}var so=vy;var Ny=Ae(Object,"create"),_t=Ny;function Ay(){this.__data__=_t?_t(null):{},this.size=0;}var Gl=Ay;function Ty(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var zl=Ty;var ky="__lodash_hash_undefined__",Cy=Object.prototype,My=Cy.hasOwnProperty;function Ly(e){var t=this.__data__;if(_t){var r=t[e];return r===ky?void 0:r}return My.call(t,e)?t[e]:void 0}var Hl=Ly;var _y=Object.prototype,Dy=_y.hasOwnProperty;function Fy(e){var t=this.__data__;return _t?t[e]!==void 0:Dy.call(t,e)}var Jl=Fy;var jy="__lodash_hash_undefined__";function Iy(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=_t&&t===void 0?jy:t,this}var Ql=Iy;function ao(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1]);}}ao.prototype.clear=Gl;ao.prototype.delete=zl;ao.prototype.get=Hl;ao.prototype.has=Jl;ao.prototype.set=Ql;var qs=ao;function qy(){this.__data__=[],this.size=0;}var Zl=qy;function Vy(e,t){for(var r=e.length;r--;)if(lt(e[r][0],t))return r;return -1}var Zt=Vy;var By=Array.prototype,Wy=By.splice;function Uy(e){var t=this.__data__,r=Zt(t,e);if(r<0)return false;var o=t.length-1;return r==o?t.pop():Wy.call(t,r,1),--this.size,true}var Yl=Uy;function Ky(e){var t=this.__data__,r=Zt(t,e);return r<0?void 0:t[r][1]}var Xl=Ky;function Gy(e){return Zt(this.__data__,e)>-1}var ep=Gy;function zy(e,t){var r=this.__data__,o=Zt(r,e);return o<0?(++this.size,r.push([e,t])):r[o][1]=t,this}var tp=zy;function lo(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1]);}}lo.prototype.clear=Zl;lo.prototype.delete=Yl;lo.prototype.get=Xl;lo.prototype.has=ep;lo.prototype.set=tp;var Yt=lo;var Hy=Ae(oe,"Map"),Xt=Hy;function Jy(){this.size=0,this.__data__={hash:new qs,map:new(Xt||Yt),string:new qs};}var rp=Jy;function Qy(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var op=Qy;function Zy(e,t){var r=e.__data__;return op(t)?r[typeof t=="string"?"string":"hash"]:r.map}var er=Zy;function Yy(e){var t=er(this,e).delete(e);return this.size-=t?1:0,t}var np=Yy;function Xy(e){return er(this,e).get(e)}var ip=Xy;function eh(e){return er(this,e).has(e)}var sp=eh;function th(e,t){var r=er(this,e),o=r.size;return r.set(e,t),this.size+=r.size==o?0:1,this}var ap=th;function po(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1]);}}po.prototype.clear=rp;po.prototype.delete=np;po.prototype.get=ip;po.prototype.has=sp;po.prototype.set=ap;var vr=po;var rh="Expected a function";function Vs(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(rh);var r=function(){var o=arguments,n=t?t.apply(this,o):o[0],i=r.cache;if(i.has(n))return i.get(n);var s=e.apply(this,o);return r.cache=i.set(n,s)||i,s};return r.cache=new(Vs.Cache||vr),r}Vs.Cache=vr;var lp=Vs;var oh=500;function nh(e){var t=lp(e,function(o){return r.size===oh&&r.clear(),o}),r=t.cache;return t}var pp=nh;var ih=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,sh=/\\(\\)?/g,ah=pp(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(ih,function(r,o,n,i){t.push(n?i.replace(sh,"$1"):o||r);}),t}),dp=ah;function lh(e){return e==null?"":yl(e)}var fp=lh;function ph(e,t){return U(e)?e:so(e,t)?[e]:dp(fp(e))}var fo=ph;function fh(e){if(typeof e=="string"||Qr(e))return e;var t=e+"";return t=="0"&&1/e==-Infinity?"-0":t}var ct=fh;function uh(e,t){t=fo(t,e);for(var r=0,o=t.length;e!=null&&r<o;)e=e[ct(t[r++])];return r&&r==o?e:void 0}var ri=uh;function ch(e,t,r){var o=e==null?void 0:ri(e,t);return o===void 0?r:o}var up=ch;function mh(e,t){for(var r=-1,o=t.length,n=e.length;++r<o;)e[n+r]=t[r];return e}var oi=mh;var gh=ti(Object.getPrototypeOf,Object),uo=gh;var yh="[object Object]",hh=Function.prototype,wh=Object.prototype,cp=hh.toString,Sh=wh.hasOwnProperty,bh=cp.call(Object);function Rh(e){if(!ie(e)||Le(e)!=yh)return false;var t=uo(e);if(t===null)return true;var r=Sh.call(t,"constructor")&&t.constructor;return typeof r=="function"&&r instanceof r&&cp.call(r)==bh}var fe=Rh;function Oh(){if(!arguments.length)return [];var e=arguments[0];return U(e)?e:[e]}var ni=Oh;function xh(){this.__data__=new Yt,this.size=0;}var mp=xh;function Eh(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var gp=Eh;function $h(e){return this.__data__.get(e)}var yp=$h;function Ph(e){return this.__data__.has(e)}var hp=Ph;var vh=200;function Nh(e,t){var r=this.__data__;if(r instanceof Yt){var o=r.__data__;if(!Xt||o.length<vh-1)return o.push([e,t]),this.size=++r.size,this;r=this.__data__=new vr(o);}return r.set(e,t),this.size=r.size,this}var wp=Nh;function co(e){var t=this.__data__=new Yt(e);this.size=t.size;}co.prototype.clear=mp;co.prototype.delete=gp;co.prototype.get=yp;co.prototype.has=hp;co.prototype.set=wp;var mt=co;function Ah(e,t){return e&&pt(t,ft(t),e)}var Sp=Ah;function Th(e,t){return e&&pt(t,ut(t),e)}var bp=Th;var Ep=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Rp=Ep&&typeof module=="object"&&module&&!module.nodeType&&module,kh=Rp&&Rp.exports===Ep,Op=kh?oe.Buffer:void 0,xp=Op?Op.allocUnsafe:void 0;function Ch(e,t){if(t)return e.slice();var r=e.length,o=xp?xp(r):new e.constructor(r);return e.copy(o),o}var ii=Ch;function Mh(e,t){for(var r=-1,o=e==null?0:e.length,n=0,i=[];++r<o;){var s=e[r];t(s,r,e)&&(i[n++]=s);}return i}var $p=Mh;function Lh(){return []}var si=Lh;var _h=Object.prototype,Dh=_h.propertyIsEnumerable,Pp=Object.getOwnPropertySymbols,Fh=Pp?function(e){return e==null?[]:(e=Object(e),$p(Pp(e),function(t){return Dh.call(e,t)}))}:si,mo=Fh;function jh(e,t){return pt(e,mo(e),t)}var vp=jh;var Ih=Object.getOwnPropertySymbols,qh=Ih?function(e){for(var t=[];e;)oi(t,mo(e)),e=uo(e);return t}:si,ai=qh;function Vh(e,t){return pt(e,ai(e),t)}var Np=Vh;function Bh(e,t,r){var o=t(e);return U(e)?o:oi(o,r(e))}var li=Bh;function Wh(e){return li(e,ft,mo)}var ln=Wh;function Uh(e){return li(e,ut,ai)}var Ap=Uh;var Kh=Ae(oe,"DataView"),pi=Kh;var Gh=Ae(oe,"Promise"),di=Gh;var zh=Ae(oe,"Set"),fi=zh;var Tp="[object Map]",Hh="[object Object]",kp="[object Promise]",Cp="[object Set]",Mp="[object WeakMap]",Lp="[object DataView]",Jh=Ct(pi),Qh=Ct(Xt),Zh=Ct(di),Yh=Ct(fi),Xh=Ct(Zn),Nr=Le;(pi&&Nr(new pi(new ArrayBuffer(1)))!=Lp||Xt&&Nr(new Xt)!=Tp||di&&Nr(di.resolve())!=kp||fi&&Nr(new fi)!=Cp||Zn&&Nr(new Zn)!=Mp)&&(Nr=function(e){var t=Le(e),r=t==Hh?e.constructor:void 0,o=r?Ct(r):"";if(o)switch(o){case Jh:return Lp;case Qh:return Tp;case Zh:return kp;case Yh:return Cp;case Xh:return Mp}return t});var Dt=Nr;var ew=Object.prototype,tw=ew.hasOwnProperty;function rw(e){var t=e.length,r=new e.constructor(t);return t&&typeof e[0]=="string"&&tw.call(e,"index")&&(r.index=e.index,r.input=e.input),r}var _p=rw;var ow=oe.Uint8Array,go=ow;function nw(e){var t=new e.constructor(e.byteLength);return new go(t).set(new go(e)),t}var yo=nw;function iw(e,t){var r=t?yo(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)}var Dp=iw;var sw=/\w*$/;function aw(e){var t=new e.constructor(e.source,sw.exec(e));return t.lastIndex=e.lastIndex,t}var Fp=aw;var jp=Oe?Oe.prototype:void 0,Ip=jp?jp.valueOf:void 0;function lw(e){return Ip?Object(Ip.call(e)):{}}var qp=lw;function pw(e,t){var r=t?yo(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)}var ui=pw;var dw="[object Boolean]",fw="[object Date]",uw="[object Map]",cw="[object Number]",mw="[object RegExp]",gw="[object Set]",yw="[object String]",hw="[object Symbol]",ww="[object ArrayBuffer]",Sw="[object DataView]",bw="[object Float32Array]",Rw="[object Float64Array]",Ow="[object Int8Array]",xw="[object Int16Array]",Ew="[object Int32Array]",$w="[object Uint8Array]",Pw="[object Uint8ClampedArray]",vw="[object Uint16Array]",Nw="[object Uint32Array]";function Aw(e,t,r){var o=e.constructor;switch(t){case ww:return yo(e);case dw:case fw:return new o(+e);case Sw:return Dp(e,r);case bw:case Rw:case Ow:case xw:case Ew:case $w:case Pw:case vw:case Nw:return ui(e,r);case uw:return new o;case cw:case yw:return new o(e);case mw:return Fp(e);case gw:return new o;case hw:return qp(e)}}var Vp=Aw;function Tw(e){return typeof e.constructor=="function"&&!oo(e)?Ol(uo(e)):{}}var ci=Tw;var kw="[object Map]";function Cw(e){return ie(e)&&Dt(e)==kw}var Bp=Cw;var Wp=Lt&&Lt.isMap,Mw=Wp?no(Wp):Bp,Up=Mw;var Lw="[object Set]";function _w(e){return ie(e)&&Dt(e)==Lw}var Kp=_w;var Gp=Lt&&Lt.isSet,Dw=Gp?no(Gp):Kp,zp=Dw;var Fw=1,jw=2,Iw=4,Hp="[object Arguments]",qw="[object Array]",Vw="[object Boolean]",Bw="[object Date]",Ww="[object Error]",Jp="[object Function]",Uw="[object GeneratorFunction]",Kw="[object Map]",Gw="[object Number]",Qp="[object Object]",zw="[object RegExp]",Hw="[object Set]",Jw="[object String]",Qw="[object Symbol]",Zw="[object WeakMap]",Yw="[object ArrayBuffer]",Xw="[object DataView]",eS="[object Float32Array]",tS="[object Float64Array]",rS="[object Int8Array]",oS="[object Int16Array]",nS="[object Int32Array]",iS="[object Uint8Array]",sS="[object Uint8ClampedArray]",aS="[object Uint16Array]",lS="[object Uint32Array]",K={};K[Hp]=K[qw]=K[Yw]=K[Xw]=K[Vw]=K[Bw]=K[eS]=K[tS]=K[rS]=K[oS]=K[nS]=K[Kw]=K[Gw]=K[Qp]=K[zw]=K[Hw]=K[Jw]=K[Qw]=K[iS]=K[sS]=K[aS]=K[lS]=true;K[Ww]=K[Jp]=K[Zw]=false;function mi(e,t,r,o,n,i){var s,a=t&Fw,l=t&jw,d=t&Iw;if(r&&(s=n?r(e,o,n,i):r(e)),s!==void 0)return s;if(!J(e))return e;var p=U(e);if(p){if(s=_p(e),!a)return Yn(e,s)}else {var f=Dt(e),u=f==Jp||f==Uw;if(Mt(e))return ii(e,a);if(f==Qp||f==Hp||u&&!n){if(s=l||u?{}:ci(e),!a)return l?Np(e,bp(s,e)):vp(e,Sp(s,e))}else {if(!K[f])return n?e:{};s=Vp(e,f,a);}}i||(i=new mt);var m=i.get(e);if(m)return m;i.set(e,s),zp(e)?e.forEach(function(g){s.add(mi(g,t,r,g,e,i));}):Up(e)&&e.forEach(function(g,w){s.set(w,mi(g,t,r,w,e,i));});var y=d?l?Ap:ln:l?ut:ft,c=p?void 0:y(e);return Nl(c||e,function(g,w){c&&(w=g,g=e[w]),to(s,w,mi(g,t,r,w,e,i));}),s}var gi=mi;var pS=1,dS=4;function fS(e){return gi(e,pS|dS)}var yi=fS;var uS=1,cS=4;function mS(e,t){return t=typeof t=="function"?t:void 0,gi(e,uS|cS,t)}var Bs=mS;var gS="__lodash_hash_undefined__";function yS(e){return this.__data__.set(e,gS),this}var Zp=yS;function hS(e){return this.__data__.has(e)}var Yp=hS;function hi(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new vr;++t<r;)this.add(e[t]);}hi.prototype.add=hi.prototype.push=Zp;hi.prototype.has=Yp;var Xp=hi;function wS(e,t){for(var r=-1,o=e==null?0:e.length;++r<o;)if(t(e[r],r,e))return true;return false}var wi=wS;function SS(e,t){return e.has(t)}var ed=SS;var bS=1,RS=2;function OS(e,t,r,o,n,i){var s=r&bS,a=e.length,l=t.length;if(a!=l&&!(s&&l>a))return false;var d=i.get(e),p=i.get(t);if(d&&p)return d==t&&p==e;var f=-1,u=true,m=r&RS?new Xp:void 0;for(i.set(e,t),i.set(t,e);++f<a;){var y=e[f],c=t[f];if(o)var g=s?o(c,y,f,t,e,i):o(y,c,f,e,t,i);if(g!==void 0){if(g)continue;u=false;break}if(m){if(!wi(t,function(w,R){if(!ed(m,R)&&(y===w||n(y,w,r,o,i)))return m.push(R)})){u=false;break}}else if(!(y===c||n(y,c,r,o,i))){u=false;break}}return i.delete(e),i.delete(t),u}var Si=OS;function xS(e){var t=-1,r=Array(e.size);return e.forEach(function(o,n){r[++t]=[n,o];}),r}var td=xS;function ES(e){var t=-1,r=Array(e.size);return e.forEach(function(o){r[++t]=o;}),r}var rd=ES;var $S=1,PS=2,vS="[object Boolean]",NS="[object Date]",AS="[object Error]",TS="[object Map]",kS="[object Number]",CS="[object RegExp]",MS="[object Set]",LS="[object String]",_S="[object Symbol]",DS="[object ArrayBuffer]",FS="[object DataView]",od=Oe?Oe.prototype:void 0,Ws=od?od.valueOf:void 0;function jS(e,t,r,o,n,i,s){switch(r){case FS:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return false;e=e.buffer,t=t.buffer;case DS:return !(e.byteLength!=t.byteLength||!i(new go(e),new go(t)));case vS:case NS:case kS:return lt(+e,+t);case AS:return e.name==t.name&&e.message==t.message;case CS:case LS:return e==t+"";case TS:var a=td;case MS:var l=o&$S;if(a||(a=rd),e.size!=t.size&&!l)return false;var d=s.get(e);if(d)return d==t;o|=PS,s.set(e,t);var p=Si(a(e),a(t),o,n,i,s);return s.delete(e),p;case _S:if(Ws)return Ws.call(e)==Ws.call(t)}return false}var nd=jS;var IS=1,qS=Object.prototype,VS=qS.hasOwnProperty;function BS(e,t,r,o,n,i){var s=r&IS,a=ln(e),l=a.length,d=ln(t),p=d.length;if(l!=p&&!s)return false;for(var f=l;f--;){var u=a[f];if(!(s?u in t:VS.call(t,u)))return false}var m=i.get(e),y=i.get(t);if(m&&y)return m==t&&y==e;var c=true;i.set(e,t),i.set(t,e);for(var g=s;++f<l;){u=a[f];var w=e[u],R=t[u];if(o)var S=s?o(R,w,u,t,e,i):o(w,R,u,e,t,i);if(!(S===void 0?w===R||n(w,R,r,o,i):S)){c=false;break}g||(g=u=="constructor");}if(c&&!g){var b=e.constructor,$=t.constructor;b!=$&&"constructor"in e&&"constructor"in t&&!(typeof b=="function"&&b instanceof b&&typeof $=="function"&&$ instanceof $)&&(c=false);}return i.delete(e),i.delete(t),c}var id=BS;var WS=1,sd="[object Arguments]",ad="[object Array]",bi="[object Object]",US=Object.prototype,ld=US.hasOwnProperty;function KS(e,t,r,o,n,i){var s=U(e),a=U(t),l=s?ad:Dt(e),d=a?ad:Dt(t);l=l==sd?bi:l,d=d==sd?bi:d;var p=l==bi,f=d==bi,u=l==d;if(u&&Mt(e)){if(!Mt(t))return false;s=true,p=false;}if(u&&!p)return i||(i=new mt),s||io(e)?Si(e,t,r,o,n,i):nd(e,t,l,r,o,n,i);if(!(r&WS)){var m=p&&ld.call(e,"__wrapped__"),y=f&&ld.call(t,"__wrapped__");if(m||y){var c=m?e.value():e,g=y?t.value():t;return i||(i=new mt),n(c,g,r,o,i)}}return u?(i||(i=new mt),id(e,t,r,o,n,i)):false}var pd=KS;function dd(e,t,r,o,n){return e===t?true:e==null||t==null||!ie(e)&&!ie(t)?e!==e&&t!==t:pd(e,t,r,o,dd,n)}var ho=dd;var GS=1,zS=2;function HS(e,t,r,o){var n=r.length,i=n,s=!o;if(e==null)return !i;for(e=Object(e);n--;){var a=r[n];if(s&&a[2]?a[1]!==e[a[0]]:!(a[0]in e))return false}for(;++n<i;){a=r[n];var l=a[0],d=e[l],p=a[1];if(s&&a[2]){if(d===void 0&&!(l in e))return false}else {var f=new mt;if(o)var u=o(d,p,l,e,t,f);if(!(u===void 0?ho(p,d,GS|zS,o,f):u))return false}}return true}var fd=HS;function JS(e){return e===e&&!J(e)}var Ri=JS;function QS(e){for(var t=ft(e),r=t.length;r--;){var o=t[r],n=e[o];t[r]=[o,n,Ri(n)];}return t}var ud=QS;function ZS(e,t){return function(r){return r==null?false:r[e]===t&&(t!==void 0||e in Object(r))}}var Oi=ZS;function YS(e){var t=ud(e);return t.length==1&&t[0][2]?Oi(t[0][0],t[0][1]):function(r){return r===e||fd(r,e,t)}}var cd=YS;function XS(e,t){return e!=null&&t in Object(e)}var md=XS;function eb(e,t,r){t=fo(t,e);for(var o=-1,n=t.length,i=false;++o<n;){var s=ct(t[o]);if(!(i=e!=null&&r(e,s)))break;e=e[s];}return i||++o!=n?i:(n=e==null?0:e.length,!!n&&ro(n)&&Qt(s,n)&&(U(e)||Pr(e)))}var gd=eb;function tb(e,t){return e!=null&&gd(e,t,md)}var yd=tb;var rb=1,ob=2;function nb(e,t){return so(e)&&Ri(t)?Oi(ct(e),t):function(r){var o=up(r,e);return o===void 0&&o===t?yd(r,e):ho(t,o,rb|ob)}}var hd=nb;function ib(e){return function(t){return t?.[e]}}var wd=ib;function sb(e){return function(t){return ri(t,e)}}var Sd=sb;function ab(e){return so(e)?wd(ct(e)):Sd(e)}var bd=ab;function lb(e){return typeof e=="function"?e:e==null?Zr:typeof e=="object"?U(e)?hd(e[0],e[1]):cd(e):bd(e)}var Rd=lb;function pb(e){return function(t,r,o){for(var n=-1,i=Object(t),s=o(t),a=s.length;a--;){var l=s[e?a:++n];if(r(i[l],l,i)===false)break}return t}}var Od=pb;var db=Od(),xi=db;function fb(e,t){return e&&xi(e,t,ft)}var xd=fb;function ub(e,t){return function(r,o){if(r==null)return r;if(!dt(r))return e(r,o);for(var n=r.length,i=t?n:-1,s=Object(r);(t?i--:++i<n)&&o(s[i],i,s)!==false;);return r}}var Ed=ub;var cb=Ed(xd),$d=cb;function mb(e,t,r){(r!==void 0&&!lt(e[t],r)||r===void 0&&!(t in e))&&eo(e,t,r);}var pn=mb;function gb(e){return ie(e)&&dt(e)}var Pd=gb;function yb(e,t){if(!(t==="constructor"&&typeof e[t]=="function")&&t!="__proto__")return e[t]}var dn=yb;function hb(e){return pt(e,ut(e))}var vd=hb;function wb(e,t,r,o,n,i,s){var a=dn(e,r),l=dn(t,r),d=s.get(l);if(d){pn(e,r,d);return}var p=i?i(a,l,r+"",e,t,s):void 0,f=p===void 0;if(f){var u=U(l),m=!u&&Mt(l),y=!u&&!m&&io(l);p=l,u||m||y?U(a)?p=a:Pd(a)?p=Yn(a):m?(f=false,p=ii(l,true)):y?(f=false,p=ui(l,true)):p=[]:fe(l)||Pr(l)?(p=a,Pr(a)?p=vd(a):(!J(a)||Yr(a))&&(p=ci(l))):f=false;}f&&(s.set(l,p),n(p,l,o,i,s),s.delete(l)),pn(e,r,p);}var Nd=wb;function Ad(e,t,r,o,n){e!==t&&xi(t,function(i,s){if(n||(n=new mt),J(i))Nd(e,t,s,r,Ad,o,n);else {var a=o?o(dn(e,s),i,s+"",e,t,n):void 0;a===void 0&&(a=i),pn(e,s,a);}},ut);}var Td=Ad;function Sb(e,t){return ho(e,t)}var Ft=Sb;var bb=Cl(function(e,t,r){Td(e,t,r);}),Ei=bb;function Rb(e,t,r,o){if(!J(e))return e;t=fo(t,e);for(var n=-1,i=t.length,s=i-1,a=e;a!=null&&++n<i;){var l=ct(t[n]),d=r;if(l==="__proto__"||l==="constructor"||l==="prototype")return e;if(n!=s){var p=a[l];d=o?o(p,l,a):void 0,d===void 0&&(d=J(p)?p:Qt(t[n+1])?[]:{});}to(a,l,d),a=a[l];}return e}var kd=Rb;function Ob(e,t,r){return e==null?e:kd(e,t,r)}var fn=Ob;function xb(e,t){var r;return $d(e,function(o,n,i){return r=t(o,n,i),!r}),!!r}var Cd=xb;function Eb(e,t,r){var o=U(e)?wi:Cd;return r&&Xn(e,t,r)&&(t=void 0),o(e,Rd(t))}var Us=Eb;var $b=/^(\$+)\.(.*)$/,L=e=>{let t=$b.exec(e);return t?{depth:t[1].length,path:t[2]}:null},Ks=(e,t,r)=>`Scope ref '${e}' needs depth ${t} but only ${r} ${r===1?"scope is":"scopes are"} in reach`,qe=(e,t)=>{let r=L(e);return r?r.depth>t.length?{outOfBounds:Ks(e,r.depth,t.length)}:{scope:t[t.length-r.depth],path:r.path}:{scope:t[t.length-1],path:e}},Pb=/\[(\d+)\]|\[(["'])(.*?)\2\]|([^.[\]]+)/g,vb=e=>e===""?[""]:[...e.matchAll(Pb)].map(t=>t[1]??t[3]??t[4]),Nb=(e,t)=>{if(e==null)return;let r=Object(e);return Object.hasOwn(r,t)?r[t]:void 0},ue=(e,t)=>vb(t).reduce(Nb,e),tr=(e,t)=>{let r=qe(e,t);if("outOfBounds"in r)throw new Error(r.outOfBounds);return ue(r.scope,r.path)},$i=(e,t)=>L(e)?tr(e,t):ue(t[0],e),un=(e,t)=>`Scope ref '${e}' is not supported by ${t}(); evaluate with check()`,Pi=(e,t)=>{if(!(!("field"in e)||typeof e.field!="string")&&L(e.field))throw new Error(un(e.field,t))};var So={postgres:"postgres",mysql:"mysql"},Ld=e=>Object.values(So).includes(e),Gs={string:{caseInsensitive:false,fuzzy:false},prismaOptions:{datasource:{provider:"postgresql"}},sql:{dialect:So.postgres},clock:{finestUnit:"second"}},Ab=new Set(Object.keys(Gs)),wo=e=>Bs(e,t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&!fe(t)?t:void 0),Md=Symbol.for("@inixiative/json-rules/engineGlobals@3"),cn=()=>{let e=globalThis;return e[Md]??={store:yi(Gs),registry:new Map},e[Md]},Tb=e=>{let t={};for(let[r,o]of Object.entries(e))r.includes(".")?fn(t,r,wo(o)):t[r]=Ei(t[r]??{},wo(o));return t},_d=(e,t,r)=>{for(let[o,n]of Object.entries(r)){let i=`${t}.${o}`;ue(e,i)===void 0&&fn(e,i,wo(n));}},kb=e=>e!=null&&typeof e.then=="function",Cb=(e,t)=>{if(!e||e.includes("."))throw new Error(`engine globals namespace "${e}" must be one non-empty segment`);if(Ab.has(e))throw new Error(`engine globals namespace "${e}" belongs to json-rules`);let{store:r,registry:o}=cn(),n=o.get(e);if(n){if(Ft(n,t))return;throw new Error(`engine globals namespace "${e}" is registered with other defaults`)}o.set(e,wo(t)),_d(r,e,t);},ze={set:(e,t)=>{fn(cn().store,e,wo(t));},get:e=>ue(cn().store,e),reset:()=>{let e=cn();e.store=yi(Gs);for(let[t,r]of e.registry)_d(e.store,t,r);},with:(e,t)=>{let r=cn(),o=r.store;r.store=Ei(wo(o),Tb(e));try{let n=t();if(kb(n))throw new Error("engineGlobals.with() callback must be synchronous (it returned a Promise).");return n}finally{r.store=o;}}},Mb=new Set(["postgresql","cockroachdb","mongodb"]),Dd=e=>Mb.has(e),se=e=>e??ze.get("string.caseInsensitive")??false,vi=e=>{let t=e??ze.get("string.fuzzy")??false;return t?t===true?{}:t:false};var h={equals:"equals",notEquals:"notEquals",lessThan:"lessThan",lessThanEquals:"lessThanEquals",greaterThan:"greaterThan",greaterThanEquals:"greaterThanEquals",contains:"contains",notContains:"notContains",in:"in",notIn:"notIn",matches:"matches",notMatches:"notMatches",between:"between",notBetween:"notBetween",isEmpty:"isEmpty",notEmpty:"notEmpty",exists:"exists",notExists:"notExists",startsWith:"startsWith",notStartsWith:"notStartsWith",endsWith:"endsWith",notEndsWith:"notEndsWith"},x={all:"all",any:"any",none:"none",atLeast:"atLeast",atMost:"atMost",exactly:"exactly",empty:"empty",notEmpty:"notEmpty"},v={before:"before",after:"after",onOrBefore:"onOrBefore",onOrAfter:"onOrAfter",notBefore:"notBefore",notAfter:"notAfter",within:"within",notWithin:"notWithin",between:"between",notBetween:"notBetween",dayIn:"dayIn",dayNotIn:"dayNotIn"};var Q={String:"String",Boolean:"Boolean",Int:"Int",BigInt:"BigInt",Float:"Float",Decimal:"Decimal",DateTime:"DateTime",Json:"Json",Bytes:"Bytes",Enum:"Enum"},He=["Int","Float","Decimal","BigInt"],bo=["String",...He,"DateTime"],rr=["String"],Ni=["String","Boolean","Int","BigInt","Float","Decimal","DateTime","Enum"],Ai=Object.values(Q),Fd=Ai,Lb={check:"check",toPrisma:"toPrisma",toSql:"toSql"},ki=e=>typeof e=="string"&&Object.hasOwn(Q,e),C=["check","toPrisma","toSql"],Ro=["check","toPrisma"],Ti=["check","toSql"],It={none:"none",scalar:"scalar",ordered:"ordered",array:"array",string:"string",pattern:"pattern",range:"range",dateValue:"dateValue",dateRange:"dateRange",dateWindow:"dateWindow",dayList:"dayList",count:"count",predicate:"predicate"},Oo={[h.equals]:{kinds:Ni,targets:C,valueShape:"scalar"},[h.notEquals]:{negates:h.equals,kinds:Ni,targets:C,valueShape:"scalar"},[h.lessThan]:{kinds:bo,targets:C,valueShape:"ordered",comparator:"lt"},[h.lessThanEquals]:{kinds:bo,targets:C,valueShape:"ordered",comparator:"lte"},[h.greaterThan]:{kinds:bo,targets:C,valueShape:"ordered",comparator:"gt"},[h.greaterThanEquals]:{kinds:bo,targets:C,valueShape:"ordered",comparator:"gte"},[h.in]:{kinds:Ni,targets:C,valueShape:"array"},[h.notIn]:{negates:h.in,kinds:Ni,targets:C,valueShape:"array"},[h.contains]:{kinds:rr,targets:C,valueShape:"string"},[h.notContains]:{negates:h.contains,kinds:rr,targets:C,valueShape:"string"},[h.startsWith]:{kinds:rr,targets:C,valueShape:"string"},[h.notStartsWith]:{negates:h.startsWith,kinds:rr,targets:C,valueShape:"string"},[h.endsWith]:{kinds:rr,targets:C,valueShape:"string"},[h.notEndsWith]:{negates:h.endsWith,kinds:rr,targets:C,valueShape:"string"},[h.matches]:{kinds:rr,targets:Ti,valueShape:"pattern"},[h.notMatches]:{negates:h.matches,kinds:rr,targets:Ti,valueShape:"pattern"},[h.between]:{kinds:bo,targets:C,valueShape:"range"},[h.notBetween]:{negates:h.between,kinds:bo,targets:C,valueShape:"range"},[h.isEmpty]:{kinds:Fd,targets:C,valueShape:"none"},[h.notEmpty]:{kinds:Fd,targets:C,valueShape:"none"},[h.exists]:{kinds:Ai,targets:C,valueShape:"none"},[h.notExists]:{kinds:Ai,targets:C,valueShape:"none"}},xo={[v.before]:{kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"lt"},[v.after]:{kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"gt"},[v.onOrBefore]:{kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"lte"},[v.onOrAfter]:{kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"gte"},[v.notBefore]:{negates:v.before,kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"gte"},[v.notAfter]:{negates:v.after,kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"lte"},[v.within]:{kinds:["DateTime"],targets:C,valueShape:"dateWindow",acceptsExpr:true},[v.notWithin]:{negates:v.within,kinds:["DateTime"],targets:C,valueShape:"dateWindow",acceptsExpr:true},[v.between]:{kinds:["DateTime"],targets:C,valueShape:"dateRange",acceptsExpr:true},[v.notBetween]:{negates:v.between,kinds:["DateTime"],targets:C,valueShape:"dateRange",acceptsExpr:true},[v.dayIn]:{kinds:["DateTime"],targets:Ti,valueShape:"dayList",acceptsExpr:false},[v.dayNotIn]:{negates:v.dayIn,kinds:["DateTime"],targets:Ti,valueShape:"dayList",acceptsExpr:false}},mn={[x.all]:{targets:Ro,valueShape:"predicate",holdsOnNoRows:true},[x.any]:{targets:Ro,valueShape:"predicate",holdsOnNoRows:false},[x.none]:{targets:Ro,valueShape:"predicate",holdsOnNoRows:true},[x.atLeast]:{targets:Ro,valueShape:"count",comparator:"gte",holdsOnNoRows:true},[x.atMost]:{targets:Ro,valueShape:"count",comparator:"lte",holdsOnNoRows:true},[x.exactly]:{targets:Ro,valueShape:"count",comparator:"equals",holdsOnNoRows:true},[x.empty]:{targets:C,valueShape:"none",holdsOnNoRows:true},[x.notEmpty]:{targets:C,valueShape:"none",holdsOnNoRows:false}},jd={field:Oo,date:xo,array:mn},jt=(e,t)=>Object.hasOwn(jd[t],e)?jd[t][e]:void 0,Eo=e=>typeof e.operator=="string"?jt(e.operator,"field"):typeof e.dateOperator=="string"?jt(e.dateOperator,"date"):void 0,or=(e,t)=>jt(e,t)?.comparator,qt=(e,t)=>{let r=jt(e,t);if(!r)throw le(e,t);return r.valueShape},Ci=(e,t,r)=>jt(e,t)?.targets.includes(r)??false,_b=(e,t)=>{let r=Object.keys(Oo).filter(n=>{let i=Oo[n];return !(!i.kinds.includes(e)||t&&!i.targets.includes(t))}),o=Object.keys(xo).filter(n=>{let i=xo[n];return !(!i.kinds.includes(e)||t&&!i.targets.includes(t))});return {field:r,date:o}},Db=e=>Object.keys(mn).filter(t=>e?mn[t].targets.includes(e):true),Id=[...Object.entries(Oo),...Object.entries(xo)],_e=(...e)=>Id.flatMap(([t,r])=>e.includes(r.valueShape)?[t]:[]),nr=_e("none"),$o=_e("ordered"),gn=_e("dateWindow"),Ve=_e("range","dateRange","dateWindow"),qd=_e("ordered","string","pattern","array"),gt=[h.contains,h.notContains],zs=[h.equals,h.notEquals,h.in,h.notIn,h.exists,h.notExists],Mi=_e("scalar","ordered","range"),yt=["sum","avg"],Fb=()=>Mi,ht=_e("scalar"),ir=_e("array"),Vd=_e("scalar","array"),Bd=_e("dayList"),Wd=_e("dateRange"),Ud=_e("scalar","ordered","range","dateValue","dateRange"),Kd=(...e)=>Object.entries(mn).flatMap(([t,r])=>e.includes(r.valueShape)?[t]:[]),yn=Kd("count"),Hs=e=>typeof e.condition!="object"||e.condition===null?null:e.arrayOperator===x.atLeast&&e.count===1?x.any:(e.arrayOperator===x.atMost||e.arrayOperator===x.exactly)&&e.count===0?x.none:null,hn=e=>yn.includes(e.arrayOperator)&&Hs(e)===null,Li=Kd("predicate","count"),Js=[x.any,x.all,x.none,x.empty,x.notEmpty],Gd=[x.any,x.atLeast],B=[...Object.entries(Oo),...Object.entries(xo)].flatMap(([e,t])=>t.negates?[e]:[]),_i=[...B,h.isEmpty,h.notExists],zd=Object.entries(mn).flatMap(([e,t])=>t.holdsOnNoRows?[e]:[]),Hd=B.filter(e=>_e("string").includes(e)),Po=B.filter(e=>Ve.includes(e)),Jd=(...e)=>Id.flatMap(([t,r])=>r.comparator&&e.includes(r.comparator)&&!B.includes(t)?[t]:[]),Di=Jd("lt","lte"),Qd=Jd("gt","gte"),Zd=["Int","BigInt"],Yd=[...He,"DateTime","Boolean","String"],Xd=["Int","BigInt","Float","Boolean","String"],ef=["scalar","ordered","string"],wn=["second","minute","hour","day","week","month","quarter","year"],Je={years:{interval:"months",factor:12,calendar:true,clock:"year"},quarters:{interval:"months",factor:3,calendar:true,clock:"quarter"},months:{interval:"months",factor:1,calendar:true,clock:"month"},weeks:{interval:"days",factor:7,calendar:true,clock:"week"},days:{interval:"days",factor:1,calendar:true,clock:"day"},hours:{interval:"secs",factor:3600,calendar:false,clock:"hour"},minutes:{interval:"secs",factor:60,calendar:false,clock:"minute"},seconds:{interval:"secs",factor:1,calendar:false,clock:"second"}},tf=["months","days","secs"],vo=e=>Object.hasOwn(Je,e),Ar=e=>vo(e)&&Je[e].calendar,Fi={year:"year",quarter:"quarter",month:"month",week:"week",isoWeek:"week",day:"day",hour:"hour",minute:"minute",second:"second"},ji=Object.keys(Fi),rf=e=>typeof e=="string"&&Object.hasOwn(Fi,e),No=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],of=e=>No.includes(e.toLowerCase()),nf=(e,t=[])=>Object.fromEntries([...Object.entries(e).flatMap(([r,o])=>o.negates?[[o.negates,r]]:[]),...t].flatMap(([r,o])=>[[r,o],[o,r]])),Sn=nf(Oo,[[h.isEmpty,h.notEmpty],[h.exists,h.notExists]]),sf=nf(xo),Ii={[h.lessThan]:h.greaterThanEquals,[h.lessThanEquals]:h.greaterThan,[h.greaterThan]:h.lessThanEquals,[h.greaterThanEquals]:h.lessThan,[v.onOrBefore]:v.after,[v.onOrAfter]:v.before};var qi=e=>new Error(`${e}: ArrayRule.field is required (fieldless arrayOps are check-only)`),le=(e,t)=>new Error(`Unknown ${t} operator: ${String(e)}`),af=(e,t)=>new Error(`'${e}' is finer than the engine's clock.finestUnit '${t}'`),Ao=e=>new Error(`${e} requires a count`),Qe=e=>new Error(`${e} requires a range date expression (a period or rolling window), not a single point`),De=e=>new Error(`${e} requires a condition to check against array elements`),sr=e=>new Error(`'${e}' is a relation: it exists or not; compare its fields with '${e}.<field>'.`),Vi=e=>new Error(`'${e}' is a list of rows: compare it with an arrayOperator (any / all / none / empty / atLeast \u2026).`),Bi=e=>gt.includes(e.operator)&&vi(e.fuzzy)?new Error("Fuzzy matching has no compiled form \u2014 evaluate it in memory with check()."):null,Wi=(e,t)=>!$o.includes(e)&&!Ve.includes(e)?null:(Ve.includes(e)&&Array.isArray(t)?t:[t]).some(o=>typeof o=="boolean"||typeof o=="object"&&o!==null&&!(o instanceof Date))?new Error(`'${e}' orders numbers, strings and dates; it can't compare ${JSON.stringify(t)}`):null,ar=e=>new Error(`aggregate.mode must be one of ${yt.join(" / ")}, not '${String(e)}'`),wt=()=>new Error("A condition is exactly one of: a field, date, array or aggregate rule, all, any, or if/then[/else]"),F=(e,t,r)=>new Error(`${t} has no ${e==="toSql"?"SQL":"Prisma"} form${r?` (${r})`:""}; use ${e==="toSql"?"check()":"toSql() or check()"}.`),St=e=>new Error(`Windowing (filter/orderBy/take/skip) is not supported by ${e}() for this rule; evaluate with check()${e==="toPrisma"?" \u2014 toPrisma compiles a filter alone and an extremal take: 1":""}.`),To=(e,t)=>new Error(`'${e}' reads through the to-many relation '${t.prefix}'; compare its rows with an arrayOperator rule on '${t.prefix}'.`),ko=(e,t)=>new Error(`'${e}' continues past '${t}', which is not a Json column`),k=class extends Error{name="UsageError"};Rt.extend(Vb);Rt.extend(qb);Rt.extend(Ib);Rt.extend(jb);var Y=e=>{if(!fe(e))return false;let t=e;return "ago"in t||"ahead"in t||"this"in t||"last"in t||"next"in t||"start"in t||"end"in t},Ze="UTC",bn=e=>{if(e.now===void 0)throw new k("date expressions require `now` to be supplied to the evaluator");let t=Rt(e.now).tz(e.timeZone);if(!t.isValid())throw new k(`invalid \`now\`: ${String(e.now)}`);return t},Qs=(e,t)=>Object.entries(e).reduce((r,[o,n])=>Je[o].interval===t?r+n*Je[o].factor:r,0),lf="YYYY-MM-DDTHH:mm:ss.SSS",lr=(e,t,r,o)=>{let n=Qs(t,"months"),i=Qs(t,"days"),s=Qs(t,"secs"),a=Rt.utc(e.tz(o).format(lf));return n&&(a=a.add(r*n,"month")),i&&(a=a.add(r*i,"day")),s&&(a=a.add(r*s*1e3,"millisecond")),Rt.tz(a.format(lf),o)},Bb=e=>"ago"in e||"ahead"in e,Ui=(e,t)=>t===-1?{ago:e}:{ahead:e},we=e=>Bb(e)?"ago"in e?[e.ago,-1]:[e.ahead,1]:null,Rn=e=>"this"in e||"last"in e||"next"in e,On=e=>"start"in e||"end"in e,Co=e=>"this"in e?e.this:"last"in e?e.last:e.next,Wb=e=>{let t=Co(e);if(typeof t!="string"||!ji.includes(t))throw new Error(`Unknown period unit '${String(t)}'`);return t},Ub=(e,t)=>e==="week"?t.weekStart==="sunday"?"week":"isoWeek":e,Zs=(e,t)=>{let r=bn(t),o=Wb(e),n=o==="isoWeek"?"week":o,i=r;"last"in e?i=r.subtract(1,n):"next"in e&&(i=r.add(1,n));let s=Ub(o,t);return [i.startOf(s),i.endOf(s)]},Ys=(e,t)=>{let r=we(e);if(r)return lr(bn(t),...r,t.timeZone);if(On(e)){let o="start"in e?e.start:e.end,[n,i]=Zs(o,t);return "start"in e?n:i}throw new Error("a point operator requires a rolling or start/end edge expression, not a bare period")},Mo=(e,t,r)=>{if(Rn(e)){let[o,n]=Zs(e,r),i=Eo({dateOperator:t})?.negates??t;return Di.includes(i)?o:n}return Ys(e,r)},Lo=(e,t)=>{if(Rn(e))return Zs(e,t);let r=we(e);if(r){let o=bn(t),n=lr(o,...r,t.timeZone);return r[1]===-1?[n,o]:[o,n]}throw Qe("within")};var pf=["value","bind","path"],xe=e=>typeof e.path=="string"&&e.path!=="",kr=e=>xe(e)?L(e.path)??{depth:0,path:e.path}:null,xn=(e,t)=>{if(e.value!==void 0)return t.value(e.value);if(e.bind!==void 0)return t.bind(e.bind,e.bindOptional);if(xe(e))return t.path(e.path);throw new Error("No value, path or bind specified")},Ki=e=>fe(e)&&(e.value!==void 0||xe(e)||typeof e.bind=="string"),Xs=(e,t,r)=>{if(!r||!Object.hasOwn(r,e)){if(t===true)return null;throw new k(`Missing binding for "${e}"`)}let o=r[e];return o===void 0?null:o},Gi=(e,t,r)=>{if(t===true)return null;throw new k(`Unresolved binding '${e}' \u2014 resolve bindings (bindRule / bindLens) before compiling with ${r}().`)},Vt=(e,t,r)=>xn(e,{value:o=>o,bind:(o,n)=>Xs(o,n,r),path:o=>$i(o,t)??null});var ff=e=>typeof e=="object"&&e!==null,ta=e=>"if"in e||"then"in e||"else"in e,Te=e=>"arrayOperator"in e||"aggregate"in e,uf=e=>[...["all","any"].flatMap(t=>Array.isArray(e[t])?e[t].map((r,o)=>({key:t,index:o,child:r,nested:false})):[]),...ta(e)?["if","then","else"].flatMap(t=>e[t]!==void 0?[{key:t,child:e[t],nested:false}]:[]):[],...["condition","filter"].flatMap(t=>e[t]!==void 0?[{key:t,child:e[t],nested:true}]:[])],Fe=e=>"all"in e||"any"in e||ta(e),H=(e,t,r)=>{if(!ff(e))return;let o=e,n=t(o,r),i=n===void 0?r:n;for(let{child:s,nested:a}of uf(o))a?i!==false&&H(s,t,i):H(s,t,r);},cf=(e,t,r,o)=>{let n=false;return H(e,(i,s)=>(!n&&t(i,s)&&(n=true),n?false:r?.(i,s)),o),n},pr=(e,t,r)=>{if(!ff(e))return e;let o=r,n={...e},i=t.rewrite?t.rewrite(n,o):n,s=uf(i),a=s.some(d=>d.nested)&&t.below?t.below(i,o):o;for(let d of ["all","any"])Array.isArray(i[d])&&(i[d]=[...i[d]]);for(let{key:d,index:p,child:f,nested:u}of s){if(u&&a===false)continue;let m=pr(f,t,u?a:o);p===void 0?i[d]=m:i[d][p]=m;}let l=t.after?t.after(i,o):i;return l===i&&Kb(i,e)?e:l},Kb=(e,t)=>{let r=Object.keys(e);return r.length!==Object.keys(t).length?false:r.every(o=>{let[n,i]=[e[o],t[o]];return n===i?true:Array.isArray(n)&&Array.isArray(i)&&n.length===i.length&&n.every((s,a)=>s===i[a])})},Gb=(e,t)=>fe(e)?Object.fromEntries(Object.entries(e).map(([r,o])=>[r,Ki(o)?t(o,Ar(r)?"whole":"number"):o])):e,ea=(e,t)=>{let r=Y(e)?we(e):null;return r?Ui(Gb(r[0],t),r[1]):e},_o=(e,t)=>{let r="dateOperator"in e;if(!r&&!("operator"in e))return e;let o=e;if(r&&e.value!==void 0){let n=Array.isArray(e.value)?e.value.map(i=>ea(i,t)):ea(e.value,t);o={...o,value:n};}if(Ki(e.offset)){let n=r?{...e.offset,...e.offset.value!==void 0&&{value:ea(e.offset.value,t)}}:e.offset;o={...o,offset:t(n,r?"shift":"number")};}return Ki(o)&&(o=t(o,"value")),o},En=e=>{let t=[];return _o(e,(r,o)=>(t.push({source:r,role:o}),r)),t},ra=e=>En(e).flatMap(({source:t,role:r})=>xe(t)?[{ref:t.path,role:r}]:[]),dr=e=>ra(e).map(t=>t.ref),Do=e=>[...Array.isArray(e.orderBy)?e.orderBy.flatMap(t=>typeof t?.field=="string"?[t.field]:[]):[],...typeof e.aggregate?.field=="string"?[e.aggregate.field]:[]],zb={all:"all",any:"any",if:"if",field:"field",aggregate:"aggregate",array:"array",date:"date"},Cr=()=>(e,t)=>({required:[...e],optional:[...t]}),df={all:Cr()(["all"],["error"]),any:Cr()(["any"],["error"]),if:Cr()(["if","then"],["else","error"]),field:Cr()(["field","operator"],["value","path","bind","bindOptional","offset","caseInsensitive","fuzzy","coerceType","error"]),aggregate:Cr()(["field","aggregate","operator"],["value","path","bind","bindOptional","condition","filter","orderBy","take","skip","error"]),array:Cr()(["arrayOperator"],["field","condition","count","filter","orderBy","take","skip","error"]),date:Cr()(["field","dateOperator"],["value","path","bind","bindOptional","offset","error"])},Hb=e=>({required:[...df[e].required],optional:[...df[e].optional]}),ne=e=>{let t=new Set;return "all"in e&&t.add("all"),"any"in e&&t.add("any"),ta(e)&&t.add("if"),"arrayOperator"in e&&t.add("array"),"dateOperator"in e&&t.add("date"),"aggregate"in e?t.add("aggregate"):"operator"in e&&t.add("field"),t.size===1?[...t][0]:null},G=e=>e.length===0?true:e.length===1?e[0]:{all:[...e]},oa=e=>typeof e=="object"&&"all"in e&&Array.isArray(e.all)?e.all.flatMap(oa):[e],Bt=e=>e.length===0?false:e.length===1?e[0]:{any:[...e]};var Jb=e=>En(e).flatMap(({source:t})=>typeof t.bind=="string"?[t]:[]),$n=(e,{required:t=false}={})=>{let r=new Set;return H(e,o=>{for(let n of Jb(o))(!t||n.bindOptional!==true)&&r.add(n.bind);}),[...r].sort()},na=(e,t)=>{let r=o=>{if(typeof o.bind!="string"||!Object.hasOwn(t,o.bind))return o;let{bind:n,bindOptional:i,...s}=o;return {...s,value:Xs(n,true,t)}};return pr(e,{rewrite:o=>_o(_o(o,r),r)})};var mf=BigInt(Number.MAX_SAFE_INTEGER),Pn=e=>{if(e>mf||e<-mf)throw new RangeError(`BigInt ${e} is outside the safe integer range (\xB12^53); json-rules compares BigInt as Int.`);return Number(e)},ia=e=>typeof e=="bigint"?Pn(e):typeof e=="string"&&e.trim()!==""&&Number.isFinite(Number(e))?Number(e):e,zi=(e,t)=>{if(e==null)return null;let r=ia(e);if(typeof r!="number"||!Number.isFinite(r))throw new Error(`${t} reads a number (got ${String(e)})`);return r},Be=([e,t])=>t<e?[t,e]:[e,t],Ye=(e,t)=>{if(!Array.isArray(e)||e.length!==2)throw new Error(`${t} operator requires an array of two values`);return [e[0],e[1]]},Fo=(e,t)=>{let r=Ye(e,t);if(!r.every(ce))throw new Error(`${t} requires two ends that order \u2014 numbers, strings or dates (got ${JSON.stringify(e)})`);return r},Hi=e=>{if(!Array.isArray(e))throw new Error(`in / notIn requires a list (got ${JSON.stringify(e)})`);return e},We=e=>{let t=Hi(e),r=t.filter(o=>o!==null);return {values:r,hasNull:r.length!==t.length}},ce=e=>typeof e=="string"||typeof e=="number"||e instanceof Date;var sa=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&(!Ar(t)||Number.isInteger(e))?null:`${t} must be a non-negative${Ar(t)?" whole":""} number (got ${String(e)})`,aa=(e,t,r)=>{let o=typeof e=="number"?e:zi(t(e),e.path?`'${e.path}' (${r})`:r),n=o===null?null:sa(o,r);if(n===null)return o;if(typeof e!="number"&&xe(e))return null;throw new Error(n)},Mr=(e,t)=>{let r={};for(let[o,n]of Object.entries(e)){if(n===void 0)continue;let i=aa(n,t,o);if(i===null)return null;r[o]=i;}return r},bt=(e,t)=>{let r=we(e);if(!r)return e;let o=Mr(r[0],t);return o?Ui(o,r[1]):null};var Qb=e=>{let t=we(e);if(t)return fe(t[0])?Object.keys(t[0]).flatMap(n=>vo(n)?[Je[n].clock]:[]):[];let r=On(e)?"start"in e?e.start:e.end:e;if(!fe(r))return [];let o=Co(r);return rf(o)?[Fi[o]]:[]},gf=(e,t)=>[...ni(e),t].filter(Y).flatMap(Qb),Zb=e=>ni(e).some(Y),Ji=e=>wn.indexOf(e),Yb=()=>{let e=ze.get("clock.finestUnit");if(wn.includes(e))return e;if(typeof e=="string"&&vo(e))return Je[e].clock;throw new k(`clock.finestUnit reads a clock unit, singular or plural (got ${String(e)})`)},Wt=(e,t)=>{let r=gf(e,t);if(r.length===0)return null;let o=Yb(),n=r.find(i=>Ji(i)<Ji(o));return n?af(n,o):null},la=e=>fe(e)?e.value:void 0,Xb=e=>{let t=null;return H(e,r=>{if(!("dateOperator"in r))return;let o=la(r.offset),n=Wt(r.value,o);if(n)throw n;if(Zb(r.value))for(let i of gf(r.value,o))(t===null||Ji(i)<t)&&(t=Ji(i));}),t===null?null:wn[t]};var Lr=(e,t)=>{if(e==null)return null;if(Array.isArray(e)){let o=e.map(n=>Lr(n,t));return o.some(n=>n===null)?null:o}let r=ia(e);if(typeof r!="number"||!Number.isFinite(r))throw new Error(`offset needs a numeric comparison value (got ${String(e)})`);return r+t},_r=e=>zi(e,"an offset"),jo=e=>{if(e==null)return null;let t=Y(e)?we(e):null;if(!t)throw new Error(`a date offset reads { ago } or { ahead } (got ${JSON.stringify(e)})`);return t};Rt.extend(Vb);Rt.extend(qb);Rt.extend(tR);Rt.extend(eR);var wf=(e,t,r={},o)=>{let n=tr(e.field,t),i=Dr(r,u=>Vt(u,t,o)),s=i.timeZone;if(n==null)return B.includes(e.dateOperator)?true:e.error||`${e.field} has no value`;let a=ce(n)?fr(n,s):null;if(!a?.isValid())throw new Error(`${e.field} is not a valid date: ${String(n)}`);let l=u=>e.error||`${e.field} ${u}`;if(Bd.includes(e.dateOperator)){let u=pa(Vt(e,t,o));if(u===null)return e.error||`${e.field} has no comparison value`;let m=u.includes(a.tz(s).day()),y=u.map(c=>No[c]).join(" or ");return e.dateOperator===v.dayIn?m||l(`must be on ${y}`):!m||l(`must not be on ${y}`)}let d=nR(e,t,i,s,o);if(d===null)return e.error||`${e.field} has no comparison value`;let[p,f=p]=d;switch(e.dateOperator){case v.before:return a.isBefore(p)||l(`must be before ${p.format()}`);case v.after:return a.isAfter(p)||l(`must be after ${p.format()}`);case v.onOrBefore:return a.isSameOrBefore(p)||l(`must be on or before ${p.format()}`);case v.onOrAfter:return a.isSameOrAfter(p)||l(`must be on or after ${p.format()}`);case v.within:return a.isSameOrAfter(p)&&a.isSameOrBefore(f)||l(`must be within ${p.format()} and ${f.format()}`);case v.notBefore:return a.isSameOrAfter(p)||l(`must not be before ${p.format()}`);case v.notAfter:return a.isSameOrBefore(p)||l(`must not be after ${p.format()}`);case v.notWithin:return a.isBefore(p)||a.isAfter(f)||l(`must not be within ${p.format()} and ${f.format()}`);case v.between:return a.isSameOrAfter(p)&&a.isSameOrBefore(f)||l(`must be between ${p.format()} and ${f.format()}`);case v.notBetween:return a.isBefore(p)||a.isAfter(f)||l(`must not be between ${p.format()} and ${f.format()}`);default:throw le(e.dateOperator,"date")}},nR=(e,t,r,o,n)=>{let i=e.dateOperator,s=g=>Vt(g,t,n),a=Vt(e,t,n);if(a==null)return null;let l=e.offset===void 0?void 0:s(e.offset),d=Wt(a,l);if(d)throw d;let p=l===void 0?void 0:jo(l);if(p===null)return null;let f=g=>{if(p===void 0)return g;let w=Mr(p[0],s);return w&&lr(g,w,p[1],o)};if(gn.includes(i)){if(!Y(a))throw Qe(i);let g=bt(a,s);return g&&Lo(g,r)}let u=(g,w)=>{if(g==null)return null;if(Y(g)){let S=bt(g,s);return S&&Ys(S,r)}let R=fr(g,o);if(!R.isValid())throw new Error(`Invalid ${w}: ${String(g)}`);return R};if(Wd.includes(i)){let[g,w]=Ye(a,i),R=u(g,"start date"),S=u(w,"end date");if(!R||!S)return null;let[b,$]=Be([R,S]),E=f(b),I=f($);return E&&I?[E,I]:null}if(Array.isArray(a))throw new Error(`${i} operator requires a single date value`);let m=g=>{let w=bt(g,s);return w&&Mo(w,i,r)},y=Y(a)?m(a):u(a,"comparison date");if(!y)return null;let c=f(y);return c&&[c]},Dr=(e,t)=>{let r=e.timeZone;if(r===void 0||typeof r=="string")return {...e,timeZone:hf(r??Ze)};if(kr(r))throw new k(`timeZone is one per evaluation; give it as a string or a { bind }, not the row path '${r.path}'`);let o=t(r);if(o!=null&&typeof o!="string")throw new k(`timeZone reads a zone name (got ${String(o)})`);return {...e,timeZone:hf(o??Ze)}},yf=new Set,hf=e=>{if(yf.has(e))return e;try{new Intl.DateTimeFormat("en-US",{timeZone:e});}catch{throw new k(`invalid time zone: ${e}`)}return yf.add(e),e},iR=/\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?\s*(?:[zZ]|[+-]\d{2}(?::?\d{2})?)$/,sR=e=>iR.test(e.trim())||/\b(?:GMT|UTC)\b/.test(e),fr=(e,t)=>{if(typeof e=="string"&&/^-?\d+$/.test(e.trim()))return Rt(Number(e));if(typeof e=="string"&&!sR(e)){let r=Rt(e);return r.isValid()?Rt.tz(e,t):r}return typeof e=="string"?Rt(new Date(e.trim())):Rt(e)},Qi=(e,t)=>{let r=ce(e)?fr(e,t):Rt(Number.NaN);if(!r.isValid())throw new Error(`Invalid date value: ${String(e)}`);return r.toDate()},pa=e=>{if(e==null)return null;if(!Array.isArray(e))throw new Error("a weekday operator requires an array of day names");return e.map(t=>{let r=No.indexOf(String(t).toLowerCase());if(r===-1)throw new Error(`Unknown day name: ${String(t)}`);return r})};var lR=e=>e<=3?0:e<=6?1:2,pR=(e,t)=>{let{maxDistance:r,maxRatio:o}=e,n=[];return typeof r=="number"&&n.push(r),typeof o=="number"&&n.push(Math.floor(t*o)),n.length>0?Math.min(...n):lR(t)},Sf=e=>e.split(/[^a-z0-9\p{L}]+/u).filter(Boolean),dR=e=>/^\d+$/.test(e),fR=(e,t,r)=>e===t?true:Math.abs(e.length-t.length)>r?false:distance(e,t)<=r,bf=(e,t,r={})=>{let o=t.trim().toLowerCase();if(!o)return true;let n=e.toLowerCase();if(n.includes(o))return true;let i=Sf(o);if(i.length===0)return false;let s=Sf(n);return s.length===0?false:i.every(a=>{let l=pR(r,a.length);return l===0||dR(a)?s.includes(a):s.some(d=>fR(a,d,l))})};var ur=e=>{let t=e instanceof RegExp?e.source:e,r=e instanceof RegExp?e.flags:"";if(/[^i]/.test(r))throw new Error(`Refused pattern /${t}/${r}: only the 'i' flag is supported`);let o=r==="i";try{return {source:t,caseInsensitive:o,re:RE2JS.compile(t,o?RE2JS.CASE_INSENSITIVE:0)}}catch(n){throw new Error(`Refused pattern /${t}/: ${n.message}`)}},Io={d:"0-9",w:"0-9A-Za-z_",s:"\\t\\n\\f\\r "},Of={alnum:"0-9A-Za-z",alpha:"A-Za-z",ascii:"\\u0000-\\u007f",blank:"\\t ",cntrl:"\\u0000-\\u001f\\u007f",digit:"0-9",graph:"!-~",lower:"a-z",print:" -~",punct:"!-/:-@\\[-`{-~",space:"\\t\\n\\v\\f\\r ",upper:"A-Z",word:"0-9A-Za-z_",xdigit:"0-9A-Fa-f"},uR=/[\\^$.|?*+()[\]{}]/,da=255,xf=e=>e<=65535?`\\u${e.toString(16).padStart(4,"0")}`:`\\U${e.toString(16).padStart(8,"0")}`,cR=e=>uR.test(e)?`\\${e}`:e,vn=e=>{let t=s=>{throw new Error(`Refused pattern /${e}/: ${s} has no Postgres form`)},r="",o=0,n=()=>{/^([*+?]|\{\d)/.test(e.slice(o))&&t("a quantified anchor");},i=s=>{let a=e[o+1];if(o+=2,Object.hasOwn(Io,a))return s?Io[a]:`[${Io[a]}]`;let l=a.toLowerCase();if(a!==l&&Object.hasOwn(Io,l))return s&&t(`a negated class \\${a} inside brackets`),`[^${Io[l]}]`;if(a==="p"||a==="P")return t("a Unicode class");if(a==="C")return t("\\C");if(a==="x"){let d=e[o]==="{",p=d?e.indexOf("}",o):o+2,f=e.slice(d?o+1:o,p);return o=d?p+1:p,xf(Number.parseInt(f,16))}if(a>="0"&&a<="7"){let d=a;for(;d.length<3&&e[o]>="0"&&e[o]<="7";)d+=e[o++];return xf(Number.parseInt(d,8))}if(!s&&(a==="b"||a==="B")){let d=`[${Io.w}]`;return a==="b"?`(?:(?<=${d})(?!${d})|(?<!${d})(?=${d}))`:`(?:(?<=${d})(?=${d})|(?<!${d})(?!${d}))`}if(!s&&(a==="z"||a==="A"))return n(),a==="z"?"\\Z":"\\A";if(a==="Q"){let d=e.indexOf("\\E",o),p=e.slice(o,d===-1?void 0:d);return o=d===-1?e.length:d+2,[...p].map(s?f=>/[\\\]^-]/.test(f)?`\\${f}`:f:cR).join("")}return `\\${a}`};for(;o<e.length;){let s=e[o];if(s==="\\")r+=i(false);else if(s===".")r+="[^\\n]",o++;else if(s==="("&&e[o+1]==="?"){let a=/^\(\?P?<[^>]+>/.exec(e.slice(o));a?(r+="(",o+=a[0].length):e[o+2]===":"?(r+="(?:",o+=3):t("a flag group");}else if(s==="{"){let a=/^\{(0|[1-9]\d*)(?:,(0|[1-9]\d*)?)?\}/.exec(e.slice(o));if(!a){r+="\\{",o++;continue}(Number(a[1])>da||Number(a[2]??0)>da)&&t(`a repeat count past ${da}`),r+=a[0],o+=a[0].length;}else if(s==="["){r+="[",o++,e[o]==="^"&&(r+="^",o++),e[o]==="]"&&(r+="\\]",o++);let a=false,l=false,d=0;for(;o<e.length&&e[o]!=="]";){let p=l?null:/^\[:(\^?)([a-z]+):\]/.exec(e.slice(o)),f=!!p||/^\\[dswDSW]/.test(e.slice(o)),u=e[o]==="-"&&d>0&&e[o+1]!=="]"&&!l;p?(p[1]&&t(`a negated class [:^${p[2]}:]`),Object.hasOwn(Of,p[2])||t(`the class [:${p[2]}:]`),r+=Of[p[2]],o+=p[0].length):e[o]==="\\"?r+=i(true):u&&a?(r+="\\-",o++):(r+=e[o]==="["?"\\[":e[o],o++);let m=l;l=u&&!a,a=f||m,d++;}r+="]",o++;}else r+=s,o++,(s==="^"||s==="$")&&n();}return r},Ef=(e,t)=>{try{let{source:r}=ur(e);return t==="toSql"&&vn(r),null}catch(r){return r.message}};var $f=e=>e==null||e===""||Array.isArray(e)&&e.length===0,Se=(e,t)=>{let r=t==null;return r&&(e.offset!==void 0||qd.includes(e.operator))?true:Ve.includes(e.operator)?r||Array.isArray(t)&&t.some(o=>o==null):false},Ut=e=>nr.includes(e.operator)||ht.includes(e.operator)&&e.value===null&&e.path===void 0&&e.bind===void 0,Yi=(e,t)=>{let r=t.filter(n=>Array.isArray(n)||n===null),o=n=>r.map(i=>({...e,operator:n,value:i}));return e.operator===h.in?Bt(o(h.equals)):G(o(h.notEquals))},jr=e=>typeof e=="string"?e.toLowerCase():Array.isArray(e)?e.map(jr):e,Pf=e=>typeof e=="bigint"?Pn(e):Array.isArray(e)&&e.some(t=>typeof t=="bigint")?e.map(t=>typeof t=="bigint"?Pn(t):t):e,vf=(e,t,r)=>{if(e==null)return e;if(He.includes(t)){if(typeof e!="string"||e.trim()==="")return e;if(t==="BigInt"&&/^-?\d+$/.test(e.trim()))return Pn(BigInt(e.trim()));let o=Number(e);return Number.isFinite(o)?o:e}switch(t){case "DateTime":{if(e instanceof Date)return e.getTime();if(typeof e=="number"||typeof e!="string")return e;let o=fr(e,r);return o.isValid()?o.valueOf():e}case "Boolean":return e==="true"?true:e==="false"?false:e;case "String":return typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):e;default:return e}},Fr=(e,t,r=Ze)=>t===void 0?e:Array.isArray(e)?e.map(o=>vf(o,t,r)):vf(e,t,r),Nn=(e,t,r,o={},n)=>{let i=n?n.value:tr(e.field,t);if(o.absent==="unknown"&&!_i.includes(e.operator)&&(i===void 0||xe(e)&&$i(e.path,t)===void 0))return e.error||`${e.field} is unknown`;let s=i??null,a=e.coerceType??(s instanceof Date?"DateTime":void 0),l=a==="DateTime"?Dr(o,S=>Vt(S,t,r)).timeZone:Ze,d=Fr(Pf(s),a,l),p=!nr.includes(e.operator),f=p?mR(Fr(Pf(Vt(e,t,r)??null),a,l),e,t,r):void 0;if(p&&Se(e,f))return B.includes(e.operator)&&d==null?true:e.error||`${e.field} has no comparison value`;let u=S=>e.error||`${e.field} ${S}${p?` ${f instanceof RegExp?String(f):JSON.stringify(f)}`:""}`,m=se(e.caseInsensitive),y=S=>m?jr(S):S,c=y(d),g=y(f),w=vi(e.fuzzy),R=()=>w&&typeof d=="string"&&typeof f=="string"?bf(d,f,w):Array.isArray(d)?c.some(S=>Ft(S,g)):gR(c,g);switch(e.operator){case h.equals:return Ft(c,g)||u("must equal");case h.notEquals:return !Ft(c,g)||u("must not equal");case h.lessThan:return Zi(d,f,"lt")||u("must be less than");case h.lessThanEquals:return Zi(d,f,"lte")||u("must be less than or equal to");case h.greaterThan:return Zi(d,f,"gt")||u("must be greater than");case h.greaterThanEquals:return Zi(d,f,"gte")||u("must be greater than or equal to");case h.in:return Hi(g).some(S=>Ft(S,c))||u("must be one of");case h.notIn:return !Hi(g).some(S=>Ft(S,c))||u("must not be one of");case h.contains:return R()||u("must contain");case h.notContains:return !R()||u("must not contain");case h.matches:return Nf(d)&&Af(f)&&ur(f).re.test(d)||u("must match pattern");case h.notMatches:return !Nf(d)||!Af(f)||!ur(f).re.test(d)||u("must not match pattern");case h.between:{let S=Tf(f,e.operator);if(!Cf(d,S))return u("must be between");let b=qo(d),[$,E]=S;return b>=$&&b<=E||u("must be between")}case h.notBetween:{let S=Tf(f,e.operator);if(!Cf(d,S))return true;let b=qo(d),[$,E]=S;return b<$||b>E||u("must not be between")}case h.isEmpty:return $f(d)||u("must be empty");case h.notEmpty:return !$f(d)||u("must not be empty");case h.exists:return d!=null||u("must exist");case h.notExists:return d==null||u("must not exist");case h.startsWith:return typeof c=="string"&&typeof g=="string"&&c.startsWith(g)||u("must start with");case h.endsWith:return typeof c=="string"&&typeof g=="string"&&c.endsWith(g)||u("must end with");case h.notStartsWith:return !(typeof c=="string"&&typeof g=="string"&&c.startsWith(g))||u("must not start with");case h.notEndsWith:return !(typeof c=="string"&&typeof g=="string"&&c.endsWith(g))||u("must not end with");default:throw new Error("Unknown operator")}},mR=(e,t,r,o)=>{if(t.offset===void 0)return e;let n=_r(Vt(t.offset,r,o));return n===null?null:Lr(e,n)},qo=e=>e instanceof Date?e.getTime():e,Zi=(e,t,r)=>{if(!yR(e,t)||!ce(t))return false;let o=qo(e),n=qo(t);switch(r){case "lt":return o<n;case "lte":return o<=n;case "gt":return o>n;case "gte":return o>=n}},Nf=e=>typeof e=="string",Af=e=>typeof e=="string"||e instanceof RegExp,Tf=(e,t)=>Be(Fo(e,t).map(r=>qo(r))),gR=(e,t)=>typeof e=="string"&&typeof t=="string"&&e.includes(t),yR=(e,t)=>ce(e)&&ce(t)&&kf(e)===kf(t),kf=e=>e instanceof Date?"date":typeof e,Cf=(e,t)=>ce(e)&&typeof qo(e)==typeof t[0];var Ee=e=>e.filter!==void 0||!!e.orderBy?.length||e.take!==void 0||e.skip!==void 0,hR=e=>{if(typeof e!="object"||e===null)return null;let t=e,r=ne(t);return r!=="field"&&r!=="date"||typeof t.field!="string"?null:{op:String(r==="date"?t.dateOperator:t.operator),field:t.field}},wR=e=>{if(e.filter!==void 0||e.skip!==void 0&&e.skip!==0||e.take!==1||e.orderBy?.length!==1)return null;let{field:t,dir:r}=e.orderBy[0];if(r!=="asc"&&r!=="desc")return null;let o=null;if(e.arrayOperator===x.all?o="all":(e.arrayOperator===x.any||e.arrayOperator===x.atLeast&&e.count===1)&&(o="any"),!o)return null;let n=hR(e.condition);if(!n||n.field!==t)return null;let i=Di.includes(n.op),s=Qd.includes(n.op);if(!i&&!s)return null;let a=r==="desc";if(!(o==="all"?a&&i||!a&&s:a&&s||!a&&i))return null;let{orderBy:d,take:p,skip:f,count:u,...m}=e;if(o==="any")return {...m,arrayOperator:x.any};let y={field:t,operator:h.exists};return {any:[{field:e.field,arrayOperator:x.empty},{all:[{field:e.field,arrayOperator:x.any,condition:y},{...m,arrayOperator:x.all,condition:{if:y,then:e.condition}}]}]}},fa=(e,t,r)=>{let o=e;return t.filter!==void 0&&r&&(o=o.filter(r)),t.orderBy?.length&&(o=Mf(o,t.orderBy)),t.skip!==void 0&&(o=o.slice(t.skip)),t.take!==void 0&&(o=o.slice(0,t.take)),o},Mf=(e,t)=>[...e].sort((r,o)=>{for(let{field:n,dir:i}of t){let s=SR(ue(r,n),ue(o,n),i);if(s!==0)return s}return 0}),SR=(e,t,r)=>{let o=e==null,n=t==null;if(o||n)return o===n?0:o?1:-1;let i=e instanceof Date?e.getTime():e,s=t instanceof Date?t.getTime():t,a=i<s?-1:i>s?1:0;return r==="asc"?a:-a},Vo=e=>{if(!Ee(e))return e;let t=!!e.orderBy?.length||e.take!==void 0||e.skip!==void 0;if(e.filter!==void 0&&!t){let{filter:r,...o}=e;if("aggregate"in e)return {...o,condition:e.condition===void 0?r:G([r,e.condition])};switch(e.arrayOperator){case "all":return {...o,condition:{if:r,then:e.condition??true}};case "empty":return {...o,arrayOperator:"none",condition:r};case "notEmpty":return {...o,arrayOperator:"any",condition:r};default:return {...o,condition:e.condition===void 0?r:G([r,e.condition])}}}return "aggregate"in e||e.filter!==void 0?null:wR(e)};var bR=e=>H(e,t=>{let r=ne(t);if(!(r==="all"||r==="any")){if(r==="array"&&!("field"in t))return false;throw new Error("check: when data is an array, every leaf must be a fieldless arrayOperator (composable with all/any)")}}),me=(e,t,r)=>(Array.isArray(t)&&bR(e),Ot(e,t,{...r,scopes:[t]})),Ot=(e,t,r)=>{if(typeof e=="boolean")return e;let o=e;switch(ne(e)){case "all":return RR(o.all,t,r,o.error);case "any":return OR(o.any,t,r,o.error);case "if":return xR(o,t,r);case "array":return $R(o,r);case "aggregate":return ER(o,r);case "date":return wf(o,r.scopes,r,r.bindings);case "field":return Nn(o,r.scopes,r.bindings,r);default:throw wt()}},Xi=(e,t)=>({...e,scopes:[...e.scopes,t]}),RR=(e,t,r,o)=>{let n=[];for(let i of e){let s=Ot(i,t,r);s!==true&&(typeof s=="string"?n.push(s):n.push("false"));}return n.length?o||(n.length===1?n[0]:`All conditions must pass: ${n.join(" AND ")}`):true},OR=(e,t,r,o)=>{let n=[];for(let i of e){let s=Ot(i,t,r);if(s===true)return true;typeof s=="string"&&n.push(s);}return o||(n.length===1?n[0]:`At least one condition must pass: ${n.join(" OR ")}`)},xR=(e,t,r)=>Ot(e.if,t,r)===true?Ot(e.then,t,r):e.else!==void 0?Ot(e.else,t,r):true,Lf=(e,t)=>{if(e==null)return [];if(!Array.isArray(e))throw new Error(`${t} must be an array`);return e},ER=(e,t)=>{let r=Lf(tr(e.field,t.scopes),e.field),o=e.filter,n=fa(r,e,o?m=>Ot(o,m,Xi(t,m))===true:void 0),{mode:i,field:s}=e.aggregate;if(!yt.includes(i))throw ar(i);let a=e.condition,d=(a?n.filter(m=>Ot(a,m,Xi(t,m))===true):n).flatMap((m,y)=>{let c=s?ue(m,s):m;if(c==null)return [];if(typeof c!="number"||!Number.isFinite(c)){let g=`${e.field}[${y}]${s?`.${s}`:""}`;throw new Error(`${g} must be a finite number`)}return [c]}),p=d.reduce((m,y)=>m+y,0),f=i==="sum"||d.length===0?p:p/d.length,u={...e,field:`${e.field} ${i}`};return Nn(u,t.scopes,t.bindings,t,{value:f})},$R=(e,t)=>{let r=Lf(e.field?tr(e.field,t.scopes):t.scopes[t.scopes.length-1],e.field||"(root)"),o=e.filter,n=fa(r,e,o?f=>Ot(o,f,Xi(t,f))===true:void 0),i=f=>e.error||`${e.field} ${f}`,s=e.condition,a=Li.includes(e.arrayOperator);if(a&&s===void 0)throw De(e.arrayOperator);let l=e.count??0;if(yn.includes(e.arrayOperator)&&e.count===void 0)throw Ao(e.arrayOperator);let d=0,p=0;if(a&&s!==void 0){if(n.length>0&&!Us(n,J))return i("contains only primitive values; use 'in' or 'contains' instead of array operators on primitive arrays");let f=n.map(u=>Ot(s,u,Xi(t,u)));d=f.filter(u=>u===true).length,p=f.filter(u=>typeof u=="string").length;}switch(e.arrayOperator){case x.empty:return !n.length||i("must be empty");case x.notEmpty:return !!n.length||i("must not be empty");case x.all:return d===n.length||i(`all elements must match (${p} failed)`);case x.any:return !!d||i("at least one element must match");case x.none:return !d||i(`no elements should match (${d} matched)`);case x.atLeast:return d>=l||i(`at least ${l} elements must match (${d} matched)`);case x.atMost:return d<=l||i(`at most ${l} elements must match (${d} matched)`);case x.exactly:return d===l||i(`exactly ${l} elements must match (${d} matched)`);default:throw le(e.arrayOperator,"array")}};var O=(e,t)=>e!==void 0&&Object.hasOwn(e,t)?e[t]:void 0,Kt=(e,t,r)=>(Object.hasOwn(e,t)||(e[t]=r()),e[t]),T=(e,t)=>O(e?.models,t),$e=(e,t,r)=>O(T(e,t)?.fields,r);var ke=({fieldMap:e,model:t})=>`${e}:${t}`,_f=(e,t)=>{let r=e.indexOf(":");return r===-1?{mapName:t,modelName:e}:{mapName:e.slice(0,r),modelName:e.slice(r+1)}};var Df=(e,t,r,o)=>{let n={};for(let i of e){let s=O(i,t);if(s==null)continue;let a=String(s);if(Object.hasOwn(n,a)){let l=o==="one"?`endpoint[0] must be the "one" side of a oneToMany bridge \u2014 swap endpoints if '${r}' is the "many" side`:`oneToOne bridges require unique '${t}' on both endpoints`;throw new Error(`indexBridges: duplicate '${t}' value '${a}' on '${r}' \u2014 ${l}.`)}n[a]=i;}return n},PR=(e,t)=>{let r={};for(let o of e){let n=O(o,t);n!=null&&Kt(r,String(n),()=>[]).push(o);}return r},Ff=(e,t)=>{let r={};for(let o of e.bridges??[]){let[n,i]=o.endpoints,s=ke(n),a=ke(i),l=o.cardinality==="oneToMany"?"one":"oneToOne",d=(u,m)=>Kt(Kt(r,u,()=>({})),m,()=>({})),p=O(t,s);p&&(d(n.fieldMap,n.model)[n.on]=Df(p,n.on,s,l));let f=O(t,a);f&&(o.cardinality==="oneToMany"?d(i.fieldMap,i.model)[i.on]=PR(f,i.on):d(i.fieldMap,i.model)[i.on]=Df(f,i.on,a,"oneToOne"));}return r};var es=e=>{let t={maps:structuredClone(e.maps),bridges:e.bridges?structuredClone(e.bridges):void 0};for(let r of e.bridges??[]){let[o,n]=r.endpoints,i=ke(o),s=ke(n),a=T(O(t.maps,o.fieldMap),o.model),l=T(O(t.maps,n.fieldMap),n.model);if(!a)throw new Error(`stitchFieldMaps: endpoint '${i}' not found`);if(!l)throw new Error(`stitchFieldMaps: endpoint '${s}' not found`);if(o.fieldMap===n.fieldMap&&o.model===n.model)throw new Error(`stitchFieldMaps: self-bridge '${i}' to itself is not supported`);if(!O(a.fields,o.on))throw new Error(`stitchFieldMaps: endpoint '${i}' has no field '${o.on}' for join`);if(!O(l.fields,n.on))throw new Error(`stitchFieldMaps: endpoint '${s}' has no field '${n.on}' for join`);if(O(a.fields,s))throw new Error(`stitchFieldMaps: bridge '${s}' already injected on '${i}'`);if(O(l.fields,i))throw new Error(`stitchFieldMaps: bridge '${i}' already injected on '${s}'`);let d=r.cardinality==="oneToMany";a.fields[s]={kind:"bridge",type:s,isList:d},l.fields[i]={kind:"bridge",type:i,isList:false};}return t};var Bo=(e,t,r)=>{if(e?.isList||t?.isList){if(!(e?.isList&&!t?.isList&>.includes(r)))return "a list column compares with no column but by membership";if(e?.kind!=="enum"&&t?.kind!=="enum")return null}let o=[e,t].filter(n=>n?.kind==="enum");return o.length===0?null:o.length===1||e?.type!==t?.type?"an enum compares only with an enum column of its own type":ht.includes(r)?null:`an enum column orders by declaration on the database, not as check() compares its text ('${r}')`};var je=e=>e.kind==="scalar"&&e.type==="Json",V=e=>e.kind==="object"||e.kind==="bridge",Ir=(e,t)=>e.values??O(t,e.type);var Pe=(e,t,r)=>{if(!e||!("maps"in e))return e;if(!t)throw new Error(`${r}: 'map' is a FieldMapSet \u2014 'mapName' is required to resolve which map to use.`);let o=O(e.maps,t);if(!o)throw new Error(`${r}: fieldMap set has no entry for '${t}'`);return o};var Xe=(e,t)=>e.kind==="object"?{mapName:t,modelName:e.type}:e.kind==="bridge"?_f(e.type,t):null;function*cr(e,t,r){let o=r.split("."),n=t;for(let i=0;i<o.length;i++){let s=o[i],a=$e(O(e,n.mapName),n.modelName,s),l=a?Xe(a,n.mapName):null;if(yield {index:i,field:s,at:n,entry:a,next:l},!l)return;n={...l,relPath:[...n.relPath,s]};}}var te=(e,t,r)=>{let o=e.split("."),n=[],i={mapName:"",modelName:r,relPath:[]};for(let{index:s,field:a,at:l,entry:d}of cr({"":t},i,e)){let p=l.modelName;if(!d)return {kind:"fallback",hops:n};if(d.kind==="bridge")return {kind:"bridge",hops:n};let f=s===o.length-1;if(d.kind==="object"){if(!T(t,d.type))return {kind:"fallback",hops:n};if(f)return {kind:"direct",hops:n,entry:d,model:p,column:a};n.push({field:a,prefix:o.slice(0,s+1).join("."),entry:d,from:p});continue}return f?{kind:"direct",hops:n,entry:d,model:p,column:a}:je(d)?{kind:"json-path",hops:n,entry:d,model:p,column:a,stopIndex:s+1,jsonPath:o.slice(s+1)}:{kind:"past-scalar",hops:n,column:a}}return {kind:"fallback",hops:n}},mr=(e,t,r)=>t&&r?te(e,t,r):void 0,X=(e,t,r)=>{let o=mr(e,t,r);return o?.kind==="direct"?o.entry:void 0},jf=(e,t,r)=>te(e,t,r).hops.filter(o=>!o.entry.isList&&o.entry.isRequired===false).map(o=>o.prefix),An=(e,t,r)=>{let o=te(e,t,r);return o.kind==="direct"&&o.entry.kind==="object"?o.entry.type:null},gr=(e,t,r)=>te(e,t,r).kind==="bridge",xt=(e,t,r)=>!!t&&!!r&&cf(e,(o,n)=>typeof o.field=="string"&&o.field!==""&&gr(o.field,t,n),(o,n)=>(typeof o.field=="string"?An(o.field,t,n):n)??false,r);var qr=e=>e?.kind==="json-path"?"json-path":e?.kind!=="direct"?"unknown":e.entry.kind==="object"?e.entry.isList?"relations":"relation":e.entry.isList?"list":e.entry.kind==="enum"?"enum":If(e.entry.type),If=e=>e===Q.Json?"json":e===Q.Enum?"enum":e===Q.DateTime?"instant":e===Q.String?"text":"scalar",ts=(e,t,r)=>{let o=X(e.field,t,r);return o?o.kind==="scalar"&&(o.type==="String"||o.type==="Json"):e.coerceType===void 0||e.coerceType==="String"||e.coerceType==="Json"},rs=(e,t,r)=>{if(qr(mr(e,t,r))==="relations")throw Vi(e)},Vr=e=>e!=="scalar"&&e!=="instant"&&e!=="list"&&e!=="enum"&&e!=="relation"&&e!=="relations",yr=(e,t)=>Vr(e)&&qf(t),qf=e=>typeof e=="string"||Array.isArray(e)&&e.some(qf),Ie=(e,t,r)=>{let o=qr(mr(e.field,t,r));return o==="unknown"&&e.coerceType!==void 0?If(e.coerceType):o},et=e=>{if(!e.isList){if(e.kind==="enum")return Q.Enum;if(!(e.kind!=="scalar"||e.type===Q.Json))return ki(e.type)?e.type:void 0}};var Vf=new WeakSet,ns=e=>(Vf.add(e),e),Bf=e=>{if(e===null||typeof e!="object")return false;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Wf=e=>{let t=[],r=(o,n)=>{if(o!==null&&typeof o=="object"&&Vf.has(o)){t.push({path:n});return}if(Array.isArray(o))for(let[i,s]of o.entries())r(s,[...n,i]);else if(Bf(o))for(let[i,s]of Object.entries(o))r(s,[...n,i]);};return r(e,[]),t},vR=["__step","__field"],os=e=>Array.isArray(e)?e.some(os):Bf(e)?Object.entries(e).some(([t,r])=>vR.includes(t)||os(r)):false;var NR={[h.equals]:"equals",[h.notEquals]:"equals",[h.lessThan]:"lt",[h.lessThanEquals]:"lte",[h.greaterThan]:"gt",[h.greaterThanEquals]:"gte"},Uf=(e,t,r)=>{let o=te(e,t,r);if(o.kind!=="direct"||o.hops.length>0)return `'${e}' is not a column of ${r} (a relation hop or an undeclared path)`;let{entry:n}=o;return V(n)?`'${e}' is a relation`:je(n)?`'${e}' is a Json column`:n.isList?`'${e}' is a list column`:n},is=(e,t,r,o,n=false)=>{let i=e.path;if(n)return {problem:"inside a counting step (a count or relation aggregate) a groupBy carries no column reference"};let s=L(i);if(s&&s.depth>1)return {problem:`'${i}' reads an enclosing scope, which a Prisma filter can't reach`};if(!s&&o)return {problem:`'${i}' reads the root row, which a Prisma relation filter can't reach`};if(!t||!r)return {problem:"comparing two columns needs the map and model"};let a=NR[e.operator];if(!a)return {problem:`'${e.operator}' takes no column reference in Prisma`};if(e.offset!==void 0)return {problem:"an offset is arithmetic, which Prisma lacks"};let l=Uf(e.field,t,r);if(typeof l=="string")return {problem:l};let d=s?s.path:i,p=Uf(d,t,r);if(typeof p=="string")return {problem:p};if(l.kind!==p.kind||l.type!==p.type)return {problem:`'${e.field}' (${l.type}) and '${d}' (${p.type}) are not the same type`};let f=Bo(l,p,e.operator);return f?{problem:f}:l.type==="String"&&se(e.caseInsensitive)?{problem:"a case-insensitive column comparison compiles to ILIKE"}:{key:a,ref:ns({__field:{model:r,field:d}}),field:l,column:p,columnPath:d}},ss=(e,t)=>new Error(`Path '${e}' compares to a column, which the Prisma rail supports only between columns of the same model and type: ${t}. Use toSql() or check().`),Kf=new WeakSet,ua=new WeakSet,Br=(e,t,r=false)=>(Kf.add(e),(r||t!==void 0&&ua.has(t))&&ua.add(e),e),Gf=e=>e!==void 0&&Kf.has(e),zf=e=>e!==void 0&&ua.has(e);var ca=e=>({field:e,operator:"notExists"}),AR=(e,t)=>{let r=t(e);if(r===null){let i=e.operator??e.dateOperator;return B.includes(i)?{field:e.field,operator:"exists"}:true}if("aggregate"in r){let i=O(Sn,r.operator);return i?{...r,operator:i}:{...r,operator:O(Ii,r.operator)}}if(typeof r.dateOperator=="string"){let i=O(sf,r.dateOperator);return i?{...r,dateOperator:i}:Bt([{...r,dateOperator:O(Ii,r.dateOperator)},ca(r.field)])}if(typeof r.arrayOperator=="string"){let i=r.count;switch(r.arrayOperator){case x.any:return {...r,arrayOperator:x.none};case x.none:return {...r,arrayOperator:x.any};case x.all:return {...r,arrayOperator:x.any,condition:Ue(r.condition,t)};case x.empty:return {...r,arrayOperator:x.notEmpty};case x.notEmpty:return {...r,arrayOperator:x.empty};case x.atLeast:return i<=0?false:{...r,arrayOperator:x.atMost,count:i-1};case x.atMost:return {...r,arrayOperator:x.atLeast,count:i+1};case x.exactly:return Bt([...i>0?[{...r,arrayOperator:x.atMost,count:i-1}]:[],{...r,arrayOperator:x.atLeast,count:i+1}])}}let o=O(Sn,r.operator);if(o)return {...r,operator:o};let n=typeof r.path=="string"&&r.path!==""?L(r.path)??{depth:1,path:r.path}:null;return Bt([{...r,operator:O(Ii,r.operator)},ca(r.field),...n&&n.depth===1?[ca(n.path)]:[]])},Ue=(e,t=r=>r)=>{if(typeof e=="boolean")return !e;let r=e;if(Array.isArray(r.all))return Bt(r.all.map(o=>Ue(o,t)));if(Array.isArray(r.any))return G(r.any.map(o=>Ue(o,t)));if("if"in r){let o=G([r.if,Ue(r.then,t)]);return r.else===void 0?o:{any:[o,G([Ue(r.if,t),Ue(r.else,t)])]}}return AR(r,t)},Hf=e=>ne(e)==="field"&&e.value!==void 0&&Se(e,e.value)?null:e;var Jf,Qf=e=>{Jf=e;},ae=(e,t,r)=>Jf(e,t,r);var TR=e=>{let t=L(e);throw t&&t.depth>1?new Error(un(e,"toPrisma")):new Error(`Path '${e}' compares to a column, which isn't supported on the Prisma rail; use toSql() or check().`)},tt=e=>xn(e,{value:t=>{if(os(t))throw new Error("toPrisma: a value holding a '__step' or '__field' key is reserved for the plan's own references");return t},path:t=>TR(t),bind:(t,r)=>Gi(t,r,"toPrisma")}),Tn=e=>tt(e),Wo=e=>Dr({now:e?.now,timeZone:e?.timeZone,weekStart:e?.weekStart},Tn),Uo=e=>t=>{let r=typeof t.operator=="string"||typeof t.dateOperator=="string",o=t.value!==void 0||typeof t.path=="string"&&t.path!==""||typeof t.bind=="string";if(!r||"aggregate"in t||!o||typeof t.operator=="string"&&typeof t.path=="string"&&t.path!=="")return t;let n=Ie({field:String(t.field)},e?.map,e?.model);if((n==="json"||n==="json-path")&&typeof t.operator=="string"&&$o.includes(t.operator))throw F("toPrisma",`The complement of '${t.operator}' on the Json value '${t.field}'`,"it keeps values of other types");let i=tt(t),s=t.offset===void 0?void 0:tt(t.offset);if(t.offset!==void 0&&s==null)return null;let{path:a,bind:l,bindOptional:d,...p}=t,f={...p,value:i,...t.offset!==void 0&&{offset:{value:s}}};return typeof t.dateOperator=="string"?i==null||Se({operator:t.dateOperator},i)?null:f:Hf(f)};var rt=()=>({}),Wr=rt,Et=()=>({OR:[]}),ma=e=>Object.keys(e).length===0,Zf=e=>{let t=Object.keys(e);return t.length===1&&t[0]==="OR"&&Array.isArray(e.OR)&&e.OR.length===0},Ke=e=>{if(e.some(Zf))return Et();let t=e.filter(r=>!ma(r));return t.length===0?rt():t.length===1?t[0]:{AND:t}},W=e=>{if(e.some(ma))return rt();let t=e.filter(r=>!Zf(r));return t.length===0?Et():t.length===1?t[0]:{OR:t}},Ce=e=>ma(e)?e:{NOT:e},Yf=(e,t,r)=>Ke(e.all.map(o=>ae(o,t,r))),Xf=(e,t,r)=>W(e.any.map(o=>ae(o,t,r))),eu=(e,t,r)=>{if(xt(e,t?.map,t?.model))return Wr();let o=ae(Ue(e.if,Uo(t)),t,r),n=ae(e.then,t,r),i=W([o,n]);if(e.else!==void 0){let s=ae(e.if,t,r),a=ae(e.else,t,r);return Ke([i,W([s,a])])}return i};var kR=(e,t,r,o)=>{let n=T(e,t);if(!n)return null;for(let i of Object.values(n.fields))if(i.kind==="object"&&i.type===r&&(i.fromFields?.length??0)>0&&(i.toFields?.length??0)>0&&(o===void 0||i.relationName===o))return i;return null},hr=(e,t,r)=>{if(r.fromFields?.length)return r.fromFields.map((n,i)=>({here:n,there:r.toFields?.[i]??"id"}));let o=kR(e,r.type,t,r.relationName);return o?.fromFields?.length?o.fromFields.map((n,i)=>({here:o.toFields?.[i]??"id",there:n})):null},as=(e,t,r,o)=>{if(o.relationName===void 0)return null;let n=Object.entries(T(e,o.type)?.fields??{}).filter(([i,s])=>s.kind==="object"&&s.type===t&&s.relationName===o.relationName&&!(o.type===t&&i===r));return n.length===1?{field:n[0][0],entry:n[0][1]}:null};var Ur=(e,t)=>{let r=e.split("."),o=t;for(let n=r.length-1;n>=0;n--)o={[r[n]]:o};return o};var Ko=(e,t,r,o)=>{let n=e.split("."),i=te(e,t,r);if(i.kind==="bridge")throw new Error(`'${e}' crosses a bridge: ${o.toLowerCase()} aren't supported across a bridge \u2014 no one database holds both sides.`);if(i.kind!=="direct"||i.entry.kind!=="object"){let l=i.hops.at(-1)?.entry.type??r;throw new Error(`Field '${n[i.hops.length]}' is not a relation in model '${l}'. ${o} require a relation field.`)}let s=i.hops.find(l=>l.entry.isList);if(s)throw new Error(`Intermediate field '${s.field}' in path '${e}' is a list relation. Only the final segment can be a list relation for ${o.toLowerCase()}.`);if(!i.entry.isList)throw new Error(`Field '${i.column}' is not a list relation in model '${i.model}'. ${o} only apply to one-to-many or many-to-many relations.`);let a=hr(t,i.model,i.entry);if(!a){let l=Object.values(T(t,i.entry.type)?.fields??{}).some(d=>d.kind==="object"&&d.type===i.model&&d.isList&&!d.fromFields?.length);throw new Error(l?`'${i.model}.${i.column}' is an implicit many-to-many relation. ${o} require an explicit join model with a FK \u2014 convert to an explicit @relation or use prisma.$queryRaw.`:`Cannot determine FK relationship between '${i.model}' and '${i.entry.type}'. Ensure the FieldMap contains both sides of the relation.`)}if(a.length>1)throw new Error(`${o} do not support composite FK relations ('${i.model}.${i.column}'). Use prisma.$queryRaw.`);return {through:i.hops.map(l=>l.field).join("."),target:i.entry.type,parentKey:a[0].here,targetKey:a[0].there}},ls=(e,t,r,o,n)=>{let i={operation:"groupBy",model:t.target,args:{by:[t.targetKey],where:r,having:o},extract:t.targetKey},s=ns({__step:e.steps.length});e.steps.push(i);let a={[t.parentKey]:{in:s}},l=n?Ce(a):a;return t.through?Ur(t.through,l):l};var Sr=e=>({ok:e.length===0,errors:e}),kn=(e,t)=>{if(!e.ok)throw new Error(`${t}:
|
|
1
|
+
import Rt from'dayjs';import jb from'dayjs/plugin/isoWeek.js';import Ib from'dayjs/plugin/quarterOfYear.js';import qb from'dayjs/plugin/timezone.js';import Vb from'dayjs/plugin/utc.js';import tR from'dayjs/plugin/isSameOrAfter.js';import rR from'dayjs/plugin/isSameOrBefore.js';import {distance}from'fastest-levenshtein';import {RE2JS}from're2js';var js=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var lm=typeof global=="object"&&global&&global.Object===Object&&global,Qn=lm;var pm=typeof self=="object"&&self&&self.Object===Object&&self,dm=Qn||pm||Function("return this")(),oe=dm;var fm=oe.Symbol,xe=fm;var ll=Object.prototype,um=ll.hasOwnProperty,cm=ll.toString,sn=xe?xe.toStringTag:void 0;function mm(e){var t=um.call(e,sn),r=e[sn];try{e[sn]=void 0;var o=!0;}catch{}var n=cm.call(e);return o&&(t?e[sn]=r:delete e[sn]),n}var pl=mm;var gm=Object.prototype,ym=gm.toString;function hm(e){return ym.call(e)}var dl=hm;var wm="[object Null]",Sm="[object Undefined]",fl=xe?xe.toStringTag:void 0;function bm(e){return e==null?e===void 0?Sm:wm:fl&&fl in Object(e)?pl(e):dl(e)}var Le=bm;function Rm(e){return e!=null&&typeof e=="object"}var ie=Rm;var Om="[object Symbol]";function xm(e){return typeof e=="symbol"||ie(e)&&Le(e)==Om}var Qr=xm;function Em(e,t){for(var r=-1,o=e==null?0:e.length,n=Array(o);++r<o;)n[r]=t(e[r],r,e);return n}var ul=Em;var $m=Array.isArray,U=$m;var cl=xe?xe.prototype:void 0,ml=cl?cl.toString:void 0;function gl(e){if(typeof e=="string")return e;if(U(e))return ul(e,gl)+"";if(Qr(e))return ml?ml.call(e):"";var t=e+"";return t=="0"&&1/e==-Infinity?"-0":t}var yl=gl;function vm(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var J=vm;function Nm(e){return e}var Zr=Nm;var Am="[object AsyncFunction]",Tm="[object Function]",km="[object GeneratorFunction]",Cm="[object Proxy]";function Mm(e){if(!J(e))return false;var t=Le(e);return t==Tm||t==km||t==Am||t==Cm}var Yr=Mm;var Lm=oe["__core-js_shared__"],Zn=Lm;var hl=(function(){var e=/[^.]+$/.exec(Zn&&Zn.keys&&Zn.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""})();function _m(e){return !!hl&&hl in e}var wl=_m;var Dm=Function.prototype,Fm=Dm.toString;function jm(e){if(e!=null){try{return Fm.call(e)}catch{}try{return e+""}catch{}}return ""}var Ct=jm;var Im=/[\\^$.*+?()[\]{}|]/g,qm=/^\[object .+?Constructor\]$/,Vm=Function.prototype,Bm=Object.prototype,Wm=Vm.toString,Um=Bm.hasOwnProperty,Km=RegExp("^"+Wm.call(Um).replace(Im,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Gm(e){if(!J(e)||wl(e))return false;var t=Yr(e)?Km:qm;return t.test(Ct(e))}var Sl=Gm;function zm(e,t){return e?.[t]}var bl=zm;function Hm(e,t){var r=bl(e,t);return Sl(r)?r:void 0}var Te=Hm;var Jm=Te(oe,"WeakMap"),Yn=Jm;var Rl=Object.create,Qm=(function(){function e(){}return function(t){if(!J(t))return {};if(Rl)return Rl(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}})(),Ol=Qm;function Zm(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}var xl=Zm;function Ym(e,t){var r=-1,o=e.length;for(t||(t=Array(o));++r<o;)t[r]=e[r];return t}var Xn=Ym;var Xm=800,eg=16,tg=Date.now;function rg(e){var t=0,r=0;return function(){var o=tg(),n=eg-(o-r);if(r=o,n>0){if(++t>=Xm)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var El=rg;function og(e){return function(){return e}}var $l=og;var ng=(function(){try{var e=Te(Object,"defineProperty");return e({},"",{}),e}catch{}})(),Xr=ng;var ig=Xr?function(e,t){return Xr(e,"toString",{configurable:true,enumerable:false,value:$l(t),writable:true})}:Zr,Pl=ig;var sg=El(Pl),vl=sg;function ag(e,t){for(var r=-1,o=e==null?0:e.length;++r<o&&t(e[r],r,e)!==false;);return e}var Nl=ag;var lg=9007199254740991,pg=/^(?:0|[1-9]\d*)$/;function dg(e,t){var r=typeof e;return t=t??lg,!!t&&(r=="number"||r!="symbol"&&pg.test(e))&&e>-1&&e%1==0&&e<t}var Qt=dg;function fg(e,t,r){t=="__proto__"&&Xr?Xr(e,t,{configurable:true,enumerable:true,value:r,writable:true}):e[t]=r;}var eo=fg;function ug(e,t){return e===t||e!==e&&t!==t}var lt=ug;var cg=Object.prototype,mg=cg.hasOwnProperty;function gg(e,t,r){var o=e[t];(!(mg.call(e,t)&<(o,r))||r===void 0&&!(t in e))&&eo(e,t,r);}var to=gg;function yg(e,t,r,o){var n=!r;r||(r={});for(var i=-1,s=t.length;++i<s;){var a=t[i],l=o?o(r[a],e[a],a,r,e):void 0;l===void 0&&(l=e[a]),n?eo(r,a,l):to(r,a,l);}return r}var pt=yg;var Al=Math.max;function hg(e,t,r){return t=Al(t===void 0?e.length-1:t,0),function(){for(var o=arguments,n=-1,i=Al(o.length-t,0),s=Array(i);++n<i;)s[n]=o[t+n];n=-1;for(var a=Array(t+1);++n<t;)a[n]=o[n];return a[t]=r(s),xl(e,this,a)}}var Tl=hg;function wg(e,t){return vl(Tl(e,t,Zr),e+"")}var kl=wg;var Sg=9007199254740991;function bg(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Sg}var ro=bg;function Rg(e){return e!=null&&ro(e.length)&&!Yr(e)}var dt=Rg;function Og(e,t,r){if(!J(r))return false;var o=typeof t;return (o=="number"?dt(r)&&Qt(t,r.length):o=="string"&&t in r)?lt(r[t],e):false}var ei=Og;function xg(e){return kl(function(t,r){var o=-1,n=r.length,i=n>1?r[n-1]:void 0,s=n>2?r[2]:void 0;for(i=e.length>3&&typeof i=="function"?(n--,i):void 0,s&&ei(r[0],r[1],s)&&(i=n<3?void 0:i,n=1),t=Object(t);++o<n;){var a=r[o];a&&e(t,a,o,i);}return t})}var Cl=xg;var Eg=Object.prototype;function $g(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||Eg;return e===r}var oo=$g;function Pg(e,t){for(var r=-1,o=Array(e);++r<e;)o[r]=t(r);return o}var Ml=Pg;var vg="[object Arguments]";function Ng(e){return ie(e)&&Le(e)==vg}var Is=Ng;var Ll=Object.prototype,Ag=Ll.hasOwnProperty,Tg=Ll.propertyIsEnumerable,kg=Is((function(){return arguments})())?Is:function(e){return ie(e)&&Ag.call(e,"callee")&&!Tg.call(e,"callee")},Pr=kg;function Cg(){return false}var _l=Cg;var jl=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Dl=jl&&typeof module=="object"&&module&&!module.nodeType&&module,Mg=Dl&&Dl.exports===jl,Fl=Mg?oe.Buffer:void 0,Lg=Fl?Fl.isBuffer:void 0,_g=Lg||_l,Mt=_g;var Dg="[object Arguments]",Fg="[object Array]",jg="[object Boolean]",Ig="[object Date]",qg="[object Error]",Vg="[object Function]",Bg="[object Map]",Wg="[object Number]",Ug="[object Object]",Kg="[object RegExp]",Gg="[object Set]",zg="[object String]",Hg="[object WeakMap]",Jg="[object ArrayBuffer]",Qg="[object DataView]",Zg="[object Float32Array]",Yg="[object Float64Array]",Xg="[object Int8Array]",ey="[object Int16Array]",ty="[object Int32Array]",ry="[object Uint8Array]",oy="[object Uint8ClampedArray]",ny="[object Uint16Array]",iy="[object Uint32Array]",H={};H[Zg]=H[Yg]=H[Xg]=H[ey]=H[ty]=H[ry]=H[oy]=H[ny]=H[iy]=true;H[Dg]=H[Fg]=H[Jg]=H[jg]=H[Qg]=H[Ig]=H[qg]=H[Vg]=H[Bg]=H[Wg]=H[Ug]=H[Kg]=H[Gg]=H[zg]=H[Hg]=false;function sy(e){return ie(e)&&ro(e.length)&&!!H[Le(e)]}var Il=sy;function ay(e){return function(t){return e(t)}}var no=ay;var ql=typeof exports=="object"&&exports&&!exports.nodeType&&exports,an=ql&&typeof module=="object"&&module&&!module.nodeType&&module,ly=an&&an.exports===ql,qs=ly&&Qn.process,py=(function(){try{var e=an&&an.require&&an.require("util").types;return e||qs&&qs.binding&&qs.binding("util")}catch{}})(),Lt=py;var Vl=Lt&&Lt.isTypedArray,dy=Vl?no(Vl):Il,io=dy;var fy=Object.prototype,uy=fy.hasOwnProperty;function cy(e,t){var r=U(e),o=!r&&Pr(e),n=!r&&!o&&Mt(e),i=!r&&!o&&!n&&io(e),s=r||o||n||i,a=s?Ml(e.length,String):[],l=a.length;for(var d in e)(t||uy.call(e,d))&&!(s&&(d=="length"||n&&(d=="offset"||d=="parent")||i&&(d=="buffer"||d=="byteLength"||d=="byteOffset")||Qt(d,l)))&&a.push(d);return a}var ti=cy;function my(e,t){return function(r){return e(t(r))}}var ri=my;var gy=ri(Object.keys,Object),Bl=gy;var yy=Object.prototype,hy=yy.hasOwnProperty;function wy(e){if(!oo(e))return Bl(e);var t=[];for(var r in Object(e))hy.call(e,r)&&r!="constructor"&&t.push(r);return t}var Wl=wy;function Sy(e){return dt(e)?ti(e):Wl(e)}var ft=Sy;function by(e){var t=[];if(e!=null)for(var r in Object(e))t.push(r);return t}var Ul=by;var Ry=Object.prototype,Oy=Ry.hasOwnProperty;function xy(e){if(!J(e))return Ul(e);var t=oo(e),r=[];for(var o in e)o=="constructor"&&(t||!Oy.call(e,o))||r.push(o);return r}var Kl=xy;function Ey(e){return dt(e)?ti(e,true):Kl(e)}var ut=Ey;var $y=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Py=/^\w*$/;function vy(e,t){if(U(e))return false;var r=typeof e;return r=="number"||r=="symbol"||r=="boolean"||e==null||Qr(e)?true:Py.test(e)||!$y.test(e)||t!=null&&e in Object(t)}var so=vy;var Ny=Te(Object,"create"),_t=Ny;function Ay(){this.__data__=_t?_t(null):{},this.size=0;}var Gl=Ay;function Ty(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var zl=Ty;var ky="__lodash_hash_undefined__",Cy=Object.prototype,My=Cy.hasOwnProperty;function Ly(e){var t=this.__data__;if(_t){var r=t[e];return r===ky?void 0:r}return My.call(t,e)?t[e]:void 0}var Hl=Ly;var _y=Object.prototype,Dy=_y.hasOwnProperty;function Fy(e){var t=this.__data__;return _t?t[e]!==void 0:Dy.call(t,e)}var Jl=Fy;var jy="__lodash_hash_undefined__";function Iy(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=_t&&t===void 0?jy:t,this}var Ql=Iy;function ao(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1]);}}ao.prototype.clear=Gl;ao.prototype.delete=zl;ao.prototype.get=Hl;ao.prototype.has=Jl;ao.prototype.set=Ql;var Vs=ao;function qy(){this.__data__=[],this.size=0;}var Zl=qy;function Vy(e,t){for(var r=e.length;r--;)if(lt(e[r][0],t))return r;return -1}var Zt=Vy;var By=Array.prototype,Wy=By.splice;function Uy(e){var t=this.__data__,r=Zt(t,e);if(r<0)return false;var o=t.length-1;return r==o?t.pop():Wy.call(t,r,1),--this.size,true}var Yl=Uy;function Ky(e){var t=this.__data__,r=Zt(t,e);return r<0?void 0:t[r][1]}var Xl=Ky;function Gy(e){return Zt(this.__data__,e)>-1}var ep=Gy;function zy(e,t){var r=this.__data__,o=Zt(r,e);return o<0?(++this.size,r.push([e,t])):r[o][1]=t,this}var tp=zy;function lo(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1]);}}lo.prototype.clear=Zl;lo.prototype.delete=Yl;lo.prototype.get=Xl;lo.prototype.has=ep;lo.prototype.set=tp;var Yt=lo;var Hy=Te(oe,"Map"),Xt=Hy;function Jy(){this.size=0,this.__data__={hash:new Vs,map:new(Xt||Yt),string:new Vs};}var rp=Jy;function Qy(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var op=Qy;function Zy(e,t){var r=e.__data__;return op(t)?r[typeof t=="string"?"string":"hash"]:r.map}var er=Zy;function Yy(e){var t=er(this,e).delete(e);return this.size-=t?1:0,t}var np=Yy;function Xy(e){return er(this,e).get(e)}var ip=Xy;function eh(e){return er(this,e).has(e)}var sp=eh;function th(e,t){var r=er(this,e),o=r.size;return r.set(e,t),this.size+=r.size==o?0:1,this}var ap=th;function po(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var o=e[t];this.set(o[0],o[1]);}}po.prototype.clear=rp;po.prototype.delete=np;po.prototype.get=ip;po.prototype.has=sp;po.prototype.set=ap;var vr=po;var rh="Expected a function";function Bs(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(rh);var r=function(){var o=arguments,n=t?t.apply(this,o):o[0],i=r.cache;if(i.has(n))return i.get(n);var s=e.apply(this,o);return r.cache=i.set(n,s)||i,s};return r.cache=new(Bs.Cache||vr),r}Bs.Cache=vr;var lp=Bs;var oh=500;function nh(e){var t=lp(e,function(o){return r.size===oh&&r.clear(),o}),r=t.cache;return t}var pp=nh;var ih=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,sh=/\\(\\)?/g,ah=pp(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(ih,function(r,o,n,i){t.push(n?i.replace(sh,"$1"):o||r);}),t}),dp=ah;function lh(e){return e==null?"":yl(e)}var fp=lh;function ph(e,t){return U(e)?e:so(e,t)?[e]:dp(fp(e))}var fo=ph;function fh(e){if(typeof e=="string"||Qr(e))return e;var t=e+"";return t=="0"&&1/e==-Infinity?"-0":t}var ct=fh;function uh(e,t){t=fo(t,e);for(var r=0,o=t.length;e!=null&&r<o;)e=e[ct(t[r++])];return r&&r==o?e:void 0}var oi=uh;function ch(e,t,r){var o=e==null?void 0:oi(e,t);return o===void 0?r:o}var up=ch;function mh(e,t){for(var r=-1,o=t.length,n=e.length;++r<o;)e[n+r]=t[r];return e}var ni=mh;var gh=ri(Object.getPrototypeOf,Object),uo=gh;var yh="[object Object]",hh=Function.prototype,wh=Object.prototype,cp=hh.toString,Sh=wh.hasOwnProperty,bh=cp.call(Object);function Rh(e){if(!ie(e)||Le(e)!=yh)return false;var t=uo(e);if(t===null)return true;var r=Sh.call(t,"constructor")&&t.constructor;return typeof r=="function"&&r instanceof r&&cp.call(r)==bh}var fe=Rh;function Oh(){if(!arguments.length)return [];var e=arguments[0];return U(e)?e:[e]}var ii=Oh;function xh(){this.__data__=new Yt,this.size=0;}var mp=xh;function Eh(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var gp=Eh;function $h(e){return this.__data__.get(e)}var yp=$h;function Ph(e){return this.__data__.has(e)}var hp=Ph;var vh=200;function Nh(e,t){var r=this.__data__;if(r instanceof Yt){var o=r.__data__;if(!Xt||o.length<vh-1)return o.push([e,t]),this.size=++r.size,this;r=this.__data__=new vr(o);}return r.set(e,t),this.size=r.size,this}var wp=Nh;function co(e){var t=this.__data__=new Yt(e);this.size=t.size;}co.prototype.clear=mp;co.prototype.delete=gp;co.prototype.get=yp;co.prototype.has=hp;co.prototype.set=wp;var mt=co;function Ah(e,t){return e&&pt(t,ft(t),e)}var Sp=Ah;function Th(e,t){return e&&pt(t,ut(t),e)}var bp=Th;var Ep=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Rp=Ep&&typeof module=="object"&&module&&!module.nodeType&&module,kh=Rp&&Rp.exports===Ep,Op=kh?oe.Buffer:void 0,xp=Op?Op.allocUnsafe:void 0;function Ch(e,t){if(t)return e.slice();var r=e.length,o=xp?xp(r):new e.constructor(r);return e.copy(o),o}var si=Ch;function Mh(e,t){for(var r=-1,o=e==null?0:e.length,n=0,i=[];++r<o;){var s=e[r];t(s,r,e)&&(i[n++]=s);}return i}var $p=Mh;function Lh(){return []}var ai=Lh;var _h=Object.prototype,Dh=_h.propertyIsEnumerable,Pp=Object.getOwnPropertySymbols,Fh=Pp?function(e){return e==null?[]:(e=Object(e),$p(Pp(e),function(t){return Dh.call(e,t)}))}:ai,mo=Fh;function jh(e,t){return pt(e,mo(e),t)}var vp=jh;var Ih=Object.getOwnPropertySymbols,qh=Ih?function(e){for(var t=[];e;)ni(t,mo(e)),e=uo(e);return t}:ai,li=qh;function Vh(e,t){return pt(e,li(e),t)}var Np=Vh;function Bh(e,t,r){var o=t(e);return U(e)?o:ni(o,r(e))}var pi=Bh;function Wh(e){return pi(e,ft,mo)}var ln=Wh;function Uh(e){return pi(e,ut,li)}var Ap=Uh;var Kh=Te(oe,"DataView"),di=Kh;var Gh=Te(oe,"Promise"),fi=Gh;var zh=Te(oe,"Set"),ui=zh;var Tp="[object Map]",Hh="[object Object]",kp="[object Promise]",Cp="[object Set]",Mp="[object WeakMap]",Lp="[object DataView]",Jh=Ct(di),Qh=Ct(Xt),Zh=Ct(fi),Yh=Ct(ui),Xh=Ct(Yn),Nr=Le;(di&&Nr(new di(new ArrayBuffer(1)))!=Lp||Xt&&Nr(new Xt)!=Tp||fi&&Nr(fi.resolve())!=kp||ui&&Nr(new ui)!=Cp||Yn&&Nr(new Yn)!=Mp)&&(Nr=function(e){var t=Le(e),r=t==Hh?e.constructor:void 0,o=r?Ct(r):"";if(o)switch(o){case Jh:return Lp;case Qh:return Tp;case Zh:return kp;case Yh:return Cp;case Xh:return Mp}return t});var Dt=Nr;var ew=Object.prototype,tw=ew.hasOwnProperty;function rw(e){var t=e.length,r=new e.constructor(t);return t&&typeof e[0]=="string"&&tw.call(e,"index")&&(r.index=e.index,r.input=e.input),r}var _p=rw;var ow=oe.Uint8Array,go=ow;function nw(e){var t=new e.constructor(e.byteLength);return new go(t).set(new go(e)),t}var yo=nw;function iw(e,t){var r=t?yo(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)}var Dp=iw;var sw=/\w*$/;function aw(e){var t=new e.constructor(e.source,sw.exec(e));return t.lastIndex=e.lastIndex,t}var Fp=aw;var jp=xe?xe.prototype:void 0,Ip=jp?jp.valueOf:void 0;function lw(e){return Ip?Object(Ip.call(e)):{}}var qp=lw;function pw(e,t){var r=t?yo(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)}var ci=pw;var dw="[object Boolean]",fw="[object Date]",uw="[object Map]",cw="[object Number]",mw="[object RegExp]",gw="[object Set]",yw="[object String]",hw="[object Symbol]",ww="[object ArrayBuffer]",Sw="[object DataView]",bw="[object Float32Array]",Rw="[object Float64Array]",Ow="[object Int8Array]",xw="[object Int16Array]",Ew="[object Int32Array]",$w="[object Uint8Array]",Pw="[object Uint8ClampedArray]",vw="[object Uint16Array]",Nw="[object Uint32Array]";function Aw(e,t,r){var o=e.constructor;switch(t){case ww:return yo(e);case dw:case fw:return new o(+e);case Sw:return Dp(e,r);case bw:case Rw:case Ow:case xw:case Ew:case $w:case Pw:case vw:case Nw:return ci(e,r);case uw:return new o;case cw:case yw:return new o(e);case mw:return Fp(e);case gw:return new o;case hw:return qp(e)}}var Vp=Aw;function Tw(e){return typeof e.constructor=="function"&&!oo(e)?Ol(uo(e)):{}}var mi=Tw;var kw="[object Map]";function Cw(e){return ie(e)&&Dt(e)==kw}var Bp=Cw;var Wp=Lt&&Lt.isMap,Mw=Wp?no(Wp):Bp,Up=Mw;var Lw="[object Set]";function _w(e){return ie(e)&&Dt(e)==Lw}var Kp=_w;var Gp=Lt&&Lt.isSet,Dw=Gp?no(Gp):Kp,zp=Dw;var Fw=1,jw=2,Iw=4,Hp="[object Arguments]",qw="[object Array]",Vw="[object Boolean]",Bw="[object Date]",Ww="[object Error]",Jp="[object Function]",Uw="[object GeneratorFunction]",Kw="[object Map]",Gw="[object Number]",Qp="[object Object]",zw="[object RegExp]",Hw="[object Set]",Jw="[object String]",Qw="[object Symbol]",Zw="[object WeakMap]",Yw="[object ArrayBuffer]",Xw="[object DataView]",eS="[object Float32Array]",tS="[object Float64Array]",rS="[object Int8Array]",oS="[object Int16Array]",nS="[object Int32Array]",iS="[object Uint8Array]",sS="[object Uint8ClampedArray]",aS="[object Uint16Array]",lS="[object Uint32Array]",K={};K[Hp]=K[qw]=K[Yw]=K[Xw]=K[Vw]=K[Bw]=K[eS]=K[tS]=K[rS]=K[oS]=K[nS]=K[Kw]=K[Gw]=K[Qp]=K[zw]=K[Hw]=K[Jw]=K[Qw]=K[iS]=K[sS]=K[aS]=K[lS]=true;K[Ww]=K[Jp]=K[Zw]=false;function gi(e,t,r,o,n,i){var s,a=t&Fw,l=t&jw,d=t&Iw;if(r&&(s=n?r(e,o,n,i):r(e)),s!==void 0)return s;if(!J(e))return e;var p=U(e);if(p){if(s=_p(e),!a)return Xn(e,s)}else {var f=Dt(e),u=f==Jp||f==Uw;if(Mt(e))return si(e,a);if(f==Qp||f==Hp||u&&!n){if(s=l||u?{}:mi(e),!a)return l?Np(e,bp(s,e)):vp(e,Sp(s,e))}else {if(!K[f])return n?e:{};s=Vp(e,f,a);}}i||(i=new mt);var m=i.get(e);if(m)return m;i.set(e,s),zp(e)?e.forEach(function(g){s.add(gi(g,t,r,g,e,i));}):Up(e)&&e.forEach(function(g,w){s.set(w,gi(g,t,r,w,e,i));});var y=d?l?Ap:ln:l?ut:ft,c=p?void 0:y(e);return Nl(c||e,function(g,w){c&&(w=g,g=e[w]),to(s,w,gi(g,t,r,w,e,i));}),s}var yi=gi;var pS=1,dS=4;function fS(e){return yi(e,pS|dS)}var hi=fS;var uS=1,cS=4;function mS(e,t){return t=typeof t=="function"?t:void 0,yi(e,uS|cS,t)}var Ws=mS;var gS="__lodash_hash_undefined__";function yS(e){return this.__data__.set(e,gS),this}var Zp=yS;function hS(e){return this.__data__.has(e)}var Yp=hS;function wi(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new vr;++t<r;)this.add(e[t]);}wi.prototype.add=wi.prototype.push=Zp;wi.prototype.has=Yp;var Xp=wi;function wS(e,t){for(var r=-1,o=e==null?0:e.length;++r<o;)if(t(e[r],r,e))return true;return false}var Si=wS;function SS(e,t){return e.has(t)}var ed=SS;var bS=1,RS=2;function OS(e,t,r,o,n,i){var s=r&bS,a=e.length,l=t.length;if(a!=l&&!(s&&l>a))return false;var d=i.get(e),p=i.get(t);if(d&&p)return d==t&&p==e;var f=-1,u=true,m=r&RS?new Xp:void 0;for(i.set(e,t),i.set(t,e);++f<a;){var y=e[f],c=t[f];if(o)var g=s?o(c,y,f,t,e,i):o(y,c,f,e,t,i);if(g!==void 0){if(g)continue;u=false;break}if(m){if(!Si(t,function(w,R){if(!ed(m,R)&&(y===w||n(y,w,r,o,i)))return m.push(R)})){u=false;break}}else if(!(y===c||n(y,c,r,o,i))){u=false;break}}return i.delete(e),i.delete(t),u}var bi=OS;function xS(e){var t=-1,r=Array(e.size);return e.forEach(function(o,n){r[++t]=[n,o];}),r}var td=xS;function ES(e){var t=-1,r=Array(e.size);return e.forEach(function(o){r[++t]=o;}),r}var rd=ES;var $S=1,PS=2,vS="[object Boolean]",NS="[object Date]",AS="[object Error]",TS="[object Map]",kS="[object Number]",CS="[object RegExp]",MS="[object Set]",LS="[object String]",_S="[object Symbol]",DS="[object ArrayBuffer]",FS="[object DataView]",od=xe?xe.prototype:void 0,Us=od?od.valueOf:void 0;function jS(e,t,r,o,n,i,s){switch(r){case FS:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return false;e=e.buffer,t=t.buffer;case DS:return !(e.byteLength!=t.byteLength||!i(new go(e),new go(t)));case vS:case NS:case kS:return lt(+e,+t);case AS:return e.name==t.name&&e.message==t.message;case CS:case LS:return e==t+"";case TS:var a=td;case MS:var l=o&$S;if(a||(a=rd),e.size!=t.size&&!l)return false;var d=s.get(e);if(d)return d==t;o|=PS,s.set(e,t);var p=bi(a(e),a(t),o,n,i,s);return s.delete(e),p;case _S:if(Us)return Us.call(e)==Us.call(t)}return false}var nd=jS;var IS=1,qS=Object.prototype,VS=qS.hasOwnProperty;function BS(e,t,r,o,n,i){var s=r&IS,a=ln(e),l=a.length,d=ln(t),p=d.length;if(l!=p&&!s)return false;for(var f=l;f--;){var u=a[f];if(!(s?u in t:VS.call(t,u)))return false}var m=i.get(e),y=i.get(t);if(m&&y)return m==t&&y==e;var c=true;i.set(e,t),i.set(t,e);for(var g=s;++f<l;){u=a[f];var w=e[u],R=t[u];if(o)var S=s?o(R,w,u,t,e,i):o(w,R,u,e,t,i);if(!(S===void 0?w===R||n(w,R,r,o,i):S)){c=false;break}g||(g=u=="constructor");}if(c&&!g){var b=e.constructor,$=t.constructor;b!=$&&"constructor"in e&&"constructor"in t&&!(typeof b=="function"&&b instanceof b&&typeof $=="function"&&$ instanceof $)&&(c=false);}return i.delete(e),i.delete(t),c}var id=BS;var WS=1,sd="[object Arguments]",ad="[object Array]",Ri="[object Object]",US=Object.prototype,ld=US.hasOwnProperty;function KS(e,t,r,o,n,i){var s=U(e),a=U(t),l=s?ad:Dt(e),d=a?ad:Dt(t);l=l==sd?Ri:l,d=d==sd?Ri:d;var p=l==Ri,f=d==Ri,u=l==d;if(u&&Mt(e)){if(!Mt(t))return false;s=true,p=false;}if(u&&!p)return i||(i=new mt),s||io(e)?bi(e,t,r,o,n,i):nd(e,t,l,r,o,n,i);if(!(r&WS)){var m=p&&ld.call(e,"__wrapped__"),y=f&&ld.call(t,"__wrapped__");if(m||y){var c=m?e.value():e,g=y?t.value():t;return i||(i=new mt),n(c,g,r,o,i)}}return u?(i||(i=new mt),id(e,t,r,o,n,i)):false}var pd=KS;function dd(e,t,r,o,n){return e===t?true:e==null||t==null||!ie(e)&&!ie(t)?e!==e&&t!==t:pd(e,t,r,o,dd,n)}var ho=dd;var GS=1,zS=2;function HS(e,t,r,o){var n=r.length,i=n,s=!o;if(e==null)return !i;for(e=Object(e);n--;){var a=r[n];if(s&&a[2]?a[1]!==e[a[0]]:!(a[0]in e))return false}for(;++n<i;){a=r[n];var l=a[0],d=e[l],p=a[1];if(s&&a[2]){if(d===void 0&&!(l in e))return false}else {var f=new mt;if(o)var u=o(d,p,l,e,t,f);if(!(u===void 0?ho(p,d,GS|zS,o,f):u))return false}}return true}var fd=HS;function JS(e){return e===e&&!J(e)}var Oi=JS;function QS(e){for(var t=ft(e),r=t.length;r--;){var o=t[r],n=e[o];t[r]=[o,n,Oi(n)];}return t}var ud=QS;function ZS(e,t){return function(r){return r==null?false:r[e]===t&&(t!==void 0||e in Object(r))}}var xi=ZS;function YS(e){var t=ud(e);return t.length==1&&t[0][2]?xi(t[0][0],t[0][1]):function(r){return r===e||fd(r,e,t)}}var cd=YS;function XS(e,t){return e!=null&&t in Object(e)}var md=XS;function eb(e,t,r){t=fo(t,e);for(var o=-1,n=t.length,i=false;++o<n;){var s=ct(t[o]);if(!(i=e!=null&&r(e,s)))break;e=e[s];}return i||++o!=n?i:(n=e==null?0:e.length,!!n&&ro(n)&&Qt(s,n)&&(U(e)||Pr(e)))}var gd=eb;function tb(e,t){return e!=null&&gd(e,t,md)}var yd=tb;var rb=1,ob=2;function nb(e,t){return so(e)&&Oi(t)?xi(ct(e),t):function(r){var o=up(r,e);return o===void 0&&o===t?yd(r,e):ho(t,o,rb|ob)}}var hd=nb;function ib(e){return function(t){return t?.[e]}}var wd=ib;function sb(e){return function(t){return oi(t,e)}}var Sd=sb;function ab(e){return so(e)?wd(ct(e)):Sd(e)}var bd=ab;function lb(e){return typeof e=="function"?e:e==null?Zr:typeof e=="object"?U(e)?hd(e[0],e[1]):cd(e):bd(e)}var Rd=lb;function pb(e){return function(t,r,o){for(var n=-1,i=Object(t),s=o(t),a=s.length;a--;){var l=s[e?a:++n];if(r(i[l],l,i)===false)break}return t}}var Od=pb;var db=Od(),Ei=db;function fb(e,t){return e&&Ei(e,t,ft)}var xd=fb;function ub(e,t){return function(r,o){if(r==null)return r;if(!dt(r))return e(r,o);for(var n=r.length,i=t?n:-1,s=Object(r);(t?i--:++i<n)&&o(s[i],i,s)!==false;);return r}}var Ed=ub;var cb=Ed(xd),$d=cb;function mb(e,t,r){(r!==void 0&&!lt(e[t],r)||r===void 0&&!(t in e))&&eo(e,t,r);}var pn=mb;function gb(e){return ie(e)&&dt(e)}var Pd=gb;function yb(e,t){if(!(t==="constructor"&&typeof e[t]=="function")&&t!="__proto__")return e[t]}var dn=yb;function hb(e){return pt(e,ut(e))}var vd=hb;function wb(e,t,r,o,n,i,s){var a=dn(e,r),l=dn(t,r),d=s.get(l);if(d){pn(e,r,d);return}var p=i?i(a,l,r+"",e,t,s):void 0,f=p===void 0;if(f){var u=U(l),m=!u&&Mt(l),y=!u&&!m&&io(l);p=l,u||m||y?U(a)?p=a:Pd(a)?p=Xn(a):m?(f=false,p=si(l,true)):y?(f=false,p=ci(l,true)):p=[]:fe(l)||Pr(l)?(p=a,Pr(a)?p=vd(a):(!J(a)||Yr(a))&&(p=mi(l))):f=false;}f&&(s.set(l,p),n(p,l,o,i,s),s.delete(l)),pn(e,r,p);}var Nd=wb;function Ad(e,t,r,o,n){e!==t&&Ei(t,function(i,s){if(n||(n=new mt),J(i))Nd(e,t,s,r,Ad,o,n);else {var a=o?o(dn(e,s),i,s+"",e,t,n):void 0;a===void 0&&(a=i),pn(e,s,a);}},ut);}var Td=Ad;function Sb(e,t){return ho(e,t)}var Ft=Sb;var bb=Cl(function(e,t,r){Td(e,t,r);}),$i=bb;function Rb(e,t,r,o){if(!J(e))return e;t=fo(t,e);for(var n=-1,i=t.length,s=i-1,a=e;a!=null&&++n<i;){var l=ct(t[n]),d=r;if(l==="__proto__"||l==="constructor"||l==="prototype")return e;if(n!=s){var p=a[l];d=o?o(p,l,a):void 0,d===void 0&&(d=J(p)?p:Qt(t[n+1])?[]:{});}to(a,l,d),a=a[l];}return e}var kd=Rb;function Ob(e,t,r){return e==null?e:kd(e,t,r)}var fn=Ob;function xb(e,t){var r;return $d(e,function(o,n,i){return r=t(o,n,i),!r}),!!r}var Cd=xb;function Eb(e,t,r){var o=U(e)?Si:Cd;return r&&ei(e,t,r)&&(t=void 0),o(e,Rd(t))}var Ks=Eb;var $b=/^(\$+)\.(.*)$/,L=e=>{let t=$b.exec(e);return t?{depth:t[1].length,path:t[2]}:null},Gs=(e,t,r)=>`Scope ref '${e}' needs depth ${t} but only ${r} ${r===1?"scope is":"scopes are"} in reach`,qe=(e,t)=>{let r=L(e);return r?r.depth>t.length?{outOfBounds:Gs(e,r.depth,t.length)}:{scope:t[t.length-r.depth],path:r.path}:{scope:t[t.length-1],path:e}},Pb=/\[(\d+)\]|\[(["'])(.*?)\2\]|([^.[\]]+)/g,vb=e=>e===""?[""]:[...e.matchAll(Pb)].map(t=>t[1]??t[3]??t[4]),Nb=(e,t)=>{if(e==null)return;let r=Object(e);return Object.hasOwn(r,t)?r[t]:void 0},ue=(e,t)=>vb(t).reduce(Nb,e),tr=(e,t)=>{let r=qe(e,t);if("outOfBounds"in r)throw new Error(r.outOfBounds);return ue(r.scope,r.path)},Pi=(e,t)=>L(e)?tr(e,t):ue(t[0],e),un=(e,t)=>`Scope ref '${e}' is not supported by ${t}(); evaluate with check()`,vi=(e,t)=>{if(!(!("field"in e)||typeof e.field!="string")&&L(e.field))throw new Error(un(e.field,t))};var So={postgres:"postgres",mysql:"mysql"},Ld=e=>Object.values(So).includes(e),zs={string:{caseInsensitive:false,fuzzy:false},prismaOptions:{datasource:{provider:"postgresql"}},sql:{dialect:So.postgres},clock:{finestUnit:"second"}},Ab=new Set(Object.keys(zs)),wo=e=>Ws(e,t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&!fe(t)?t:void 0),Md=Symbol.for("@inixiative/json-rules/engineGlobals@3"),cn=()=>{let e=globalThis;return e[Md]??={store:hi(zs),registry:new Map},e[Md]},Tb=e=>{let t={};for(let[r,o]of Object.entries(e))r.includes(".")?fn(t,r,wo(o)):t[r]=$i(t[r]??{},wo(o));return t},_d=(e,t,r)=>{for(let[o,n]of Object.entries(r)){let i=`${t}.${o}`;ue(e,i)===void 0&&fn(e,i,wo(n));}},kb=e=>e!=null&&typeof e.then=="function",Cb=(e,t)=>{if(!e||e.includes("."))throw new Error(`engine globals namespace "${e}" must be one non-empty segment`);if(Ab.has(e))throw new Error(`engine globals namespace "${e}" belongs to json-rules`);let{store:r,registry:o}=cn(),n=o.get(e);if(n){if(Ft(n,t))return;throw new Error(`engine globals namespace "${e}" is registered with other defaults`)}o.set(e,wo(t)),_d(r,e,t);},ze={set:(e,t)=>{fn(cn().store,e,wo(t));},get:e=>ue(cn().store,e),reset:()=>{let e=cn();e.store=hi(zs);for(let[t,r]of e.registry)_d(e.store,t,r);},with:(e,t)=>{let r=cn(),o=r.store;r.store=$i(wo(o),Tb(e));try{let n=t();if(kb(n))throw new Error("engineGlobals.with() callback must be synchronous (it returned a Promise).");return n}finally{r.store=o;}}},Mb=new Set(["postgresql","cockroachdb","mongodb"]),Dd=e=>Mb.has(e),se=e=>e??ze.get("string.caseInsensitive")??false,Ni=e=>{let t=e??ze.get("string.fuzzy")??false;return t?t===true?{}:t:false};var h={equals:"equals",notEquals:"notEquals",lessThan:"lessThan",lessThanEquals:"lessThanEquals",greaterThan:"greaterThan",greaterThanEquals:"greaterThanEquals",contains:"contains",notContains:"notContains",in:"in",notIn:"notIn",matches:"matches",notMatches:"notMatches",between:"between",notBetween:"notBetween",isEmpty:"isEmpty",notEmpty:"notEmpty",exists:"exists",notExists:"notExists",startsWith:"startsWith",notStartsWith:"notStartsWith",endsWith:"endsWith",notEndsWith:"notEndsWith"},x={all:"all",any:"any",none:"none",atLeast:"atLeast",atMost:"atMost",exactly:"exactly",empty:"empty",notEmpty:"notEmpty"},v={before:"before",after:"after",onOrBefore:"onOrBefore",onOrAfter:"onOrAfter",notBefore:"notBefore",notAfter:"notAfter",within:"within",notWithin:"notWithin",between:"between",notBetween:"notBetween",dayIn:"dayIn",dayNotIn:"dayNotIn"};var Q={String:"String",Boolean:"Boolean",Int:"Int",BigInt:"BigInt",Float:"Float",Decimal:"Decimal",DateTime:"DateTime",Json:"Json",Bytes:"Bytes",Enum:"Enum"},He=["Int","Float","Decimal","BigInt"],bo=["String",...He,"DateTime"],rr=["String"],Ai=["String","Boolean","Int","BigInt","Float","Decimal","DateTime","Enum"],Ti=Object.values(Q),Fd=Ti,Lb={check:"check",toPrisma:"toPrisma",toSql:"toSql"},Ci=e=>typeof e=="string"&&Object.hasOwn(Q,e),C=["check","toPrisma","toSql"],Ro=["check","toPrisma"],ki=["check","toSql"],It={none:"none",scalar:"scalar",ordered:"ordered",array:"array",string:"string",pattern:"pattern",range:"range",dateValue:"dateValue",dateRange:"dateRange",dateWindow:"dateWindow",dayList:"dayList",count:"count",predicate:"predicate"},Oo={[h.equals]:{kinds:Ai,targets:C,valueShape:"scalar"},[h.notEquals]:{negates:h.equals,kinds:Ai,targets:C,valueShape:"scalar"},[h.lessThan]:{kinds:bo,targets:C,valueShape:"ordered",comparator:"lt"},[h.lessThanEquals]:{kinds:bo,targets:C,valueShape:"ordered",comparator:"lte"},[h.greaterThan]:{kinds:bo,targets:C,valueShape:"ordered",comparator:"gt"},[h.greaterThanEquals]:{kinds:bo,targets:C,valueShape:"ordered",comparator:"gte"},[h.in]:{kinds:Ai,targets:C,valueShape:"array"},[h.notIn]:{negates:h.in,kinds:Ai,targets:C,valueShape:"array"},[h.contains]:{kinds:rr,targets:C,valueShape:"string"},[h.notContains]:{negates:h.contains,kinds:rr,targets:C,valueShape:"string"},[h.startsWith]:{kinds:rr,targets:C,valueShape:"string"},[h.notStartsWith]:{negates:h.startsWith,kinds:rr,targets:C,valueShape:"string"},[h.endsWith]:{kinds:rr,targets:C,valueShape:"string"},[h.notEndsWith]:{negates:h.endsWith,kinds:rr,targets:C,valueShape:"string"},[h.matches]:{kinds:rr,targets:ki,valueShape:"pattern"},[h.notMatches]:{negates:h.matches,kinds:rr,targets:ki,valueShape:"pattern"},[h.between]:{kinds:bo,targets:C,valueShape:"range"},[h.notBetween]:{negates:h.between,kinds:bo,targets:C,valueShape:"range"},[h.isEmpty]:{kinds:Fd,targets:C,valueShape:"none"},[h.notEmpty]:{kinds:Fd,targets:C,valueShape:"none"},[h.exists]:{kinds:Ti,targets:C,valueShape:"none"},[h.notExists]:{kinds:Ti,targets:C,valueShape:"none"}},xo={[v.before]:{kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"lt"},[v.after]:{kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"gt"},[v.onOrBefore]:{kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"lte"},[v.onOrAfter]:{kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"gte"},[v.notBefore]:{negates:v.before,kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"gte"},[v.notAfter]:{negates:v.after,kinds:["DateTime"],targets:C,valueShape:"dateValue",acceptsExpr:true,comparator:"lte"},[v.within]:{kinds:["DateTime"],targets:C,valueShape:"dateWindow",acceptsExpr:true},[v.notWithin]:{negates:v.within,kinds:["DateTime"],targets:C,valueShape:"dateWindow",acceptsExpr:true},[v.between]:{kinds:["DateTime"],targets:C,valueShape:"dateRange",acceptsExpr:true},[v.notBetween]:{negates:v.between,kinds:["DateTime"],targets:C,valueShape:"dateRange",acceptsExpr:true},[v.dayIn]:{kinds:["DateTime"],targets:ki,valueShape:"dayList",acceptsExpr:false},[v.dayNotIn]:{negates:v.dayIn,kinds:["DateTime"],targets:ki,valueShape:"dayList",acceptsExpr:false}},mn={[x.all]:{targets:Ro,valueShape:"predicate",holdsOnNoRows:true},[x.any]:{targets:Ro,valueShape:"predicate",holdsOnNoRows:false},[x.none]:{targets:Ro,valueShape:"predicate",holdsOnNoRows:true},[x.atLeast]:{targets:Ro,valueShape:"count",comparator:"gte",holdsOnNoRows:true},[x.atMost]:{targets:Ro,valueShape:"count",comparator:"lte",holdsOnNoRows:true},[x.exactly]:{targets:Ro,valueShape:"count",comparator:"equals",holdsOnNoRows:true},[x.empty]:{targets:C,valueShape:"none",holdsOnNoRows:true},[x.notEmpty]:{targets:C,valueShape:"none",holdsOnNoRows:false}},jd={field:Oo,date:xo,array:mn},jt=(e,t)=>Object.hasOwn(jd[t],e)?jd[t][e]:void 0,Eo=e=>typeof e.operator=="string"?jt(e.operator,"field"):typeof e.dateOperator=="string"?jt(e.dateOperator,"date"):void 0,or=(e,t)=>jt(e,t)?.comparator,qt=(e,t)=>{let r=jt(e,t);if(!r)throw le(e,t);return r.valueShape},Mi=(e,t,r)=>jt(e,t)?.targets.includes(r)??false,_b=(e,t)=>{let r=Object.keys(Oo).filter(n=>{let i=Oo[n];return !(!i.kinds.includes(e)||t&&!i.targets.includes(t))}),o=Object.keys(xo).filter(n=>{let i=xo[n];return !(!i.kinds.includes(e)||t&&!i.targets.includes(t))});return {field:r,date:o}},Db=e=>Object.keys(mn).filter(t=>e?mn[t].targets.includes(e):true),Id=[...Object.entries(Oo),...Object.entries(xo)],_e=(...e)=>Id.flatMap(([t,r])=>e.includes(r.valueShape)?[t]:[]),nr=_e("none"),$o=_e("ordered"),gn=_e("dateWindow"),Ve=_e("range","dateRange","dateWindow"),qd=_e("ordered","string","pattern","array"),gt=[h.contains,h.notContains],Hs=[h.equals,h.notEquals,h.in,h.notIn,h.exists,h.notExists],Li=_e("scalar","ordered","range"),yt=["sum","avg"],Fb=()=>Li,ht=_e("scalar"),ir=_e("array"),Vd=_e("scalar","array"),Bd=_e("dayList"),Wd=_e("dateRange"),Ud=_e("scalar","ordered","range","dateValue","dateRange"),Kd=(...e)=>Object.entries(mn).flatMap(([t,r])=>e.includes(r.valueShape)?[t]:[]),yn=Kd("count"),Js=e=>typeof e.condition!="object"||e.condition===null?null:e.arrayOperator===x.atLeast&&e.count===1?x.any:(e.arrayOperator===x.atMost||e.arrayOperator===x.exactly)&&e.count===0?x.none:null,hn=e=>yn.includes(e.arrayOperator)&&Js(e)===null,_i=Kd("predicate","count"),Qs=[x.any,x.all,x.none,x.empty,x.notEmpty],Gd=[x.any,x.atLeast],B=[...Object.entries(Oo),...Object.entries(xo)].flatMap(([e,t])=>t.negates?[e]:[]),Di=[...B,h.isEmpty,h.notExists],zd=Object.entries(mn).flatMap(([e,t])=>t.holdsOnNoRows?[e]:[]),Hd=B.filter(e=>_e("string").includes(e)),Po=B.filter(e=>Ve.includes(e)),Jd=(...e)=>Id.flatMap(([t,r])=>r.comparator&&e.includes(r.comparator)&&!B.includes(t)?[t]:[]),Fi=Jd("lt","lte"),Qd=Jd("gt","gte"),Zd=["Int","BigInt"],Yd=[...He,"DateTime","Boolean","String"],Xd=["Int","BigInt","Float","Boolean","String"],ef=["scalar","ordered","string"],wn=["second","minute","hour","day","week","month","quarter","year"],Je={years:{interval:"months",factor:12,calendar:true,clock:"year"},quarters:{interval:"months",factor:3,calendar:true,clock:"quarter"},months:{interval:"months",factor:1,calendar:true,clock:"month"},weeks:{interval:"days",factor:7,calendar:true,clock:"week"},days:{interval:"days",factor:1,calendar:true,clock:"day"},hours:{interval:"secs",factor:3600,calendar:false,clock:"hour"},minutes:{interval:"secs",factor:60,calendar:false,clock:"minute"},seconds:{interval:"secs",factor:1,calendar:false,clock:"second"}},tf=["months","days","secs"],vo=e=>Object.hasOwn(Je,e),Ar=e=>vo(e)&&Je[e].calendar,ji={year:"year",quarter:"quarter",month:"month",week:"week",isoWeek:"week",day:"day",hour:"hour",minute:"minute",second:"second"},Ii=Object.keys(ji),rf=e=>typeof e=="string"&&Object.hasOwn(ji,e),No=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],of=e=>No.includes(e.toLowerCase()),nf=(e,t=[])=>Object.fromEntries([...Object.entries(e).flatMap(([r,o])=>o.negates?[[o.negates,r]]:[]),...t].flatMap(([r,o])=>[[r,o],[o,r]])),Sn=nf(Oo,[[h.isEmpty,h.notEmpty],[h.exists,h.notExists]]),sf=nf(xo),qi={[h.lessThan]:h.greaterThanEquals,[h.lessThanEquals]:h.greaterThan,[h.greaterThan]:h.lessThanEquals,[h.greaterThanEquals]:h.lessThan,[v.onOrBefore]:v.after,[v.onOrAfter]:v.before};var Vi=e=>new Error(`${e}: ArrayRule.field is required (fieldless arrayOps are check-only)`),le=(e,t)=>new Error(`Unknown ${t} operator: ${String(e)}`),af=(e,t)=>new Error(`'${e}' is finer than the engine's clock.finestUnit '${t}'`),Ao=e=>new Error(`${e} requires a count`),Qe=e=>new Error(`${e} requires a range date expression (a period or rolling window), not a single point`),De=e=>new Error(`${e} requires a condition to check against array elements`),sr=e=>new Error(`'${e}' is a relation: it exists or not; compare its fields with '${e}.<field>'.`),Bi=e=>new Error(`'${e}' is a list of rows: compare it with an arrayOperator (any / all / none / empty / atLeast \u2026).`),Wi=e=>gt.includes(e.operator)&&Ni(e.fuzzy)?new Error("Fuzzy matching has no compiled form \u2014 evaluate it in memory with check()."):null,Ui=(e,t)=>!$o.includes(e)&&!Ve.includes(e)?null:(Ve.includes(e)&&Array.isArray(t)?t:[t]).some(o=>typeof o=="boolean"||typeof o=="object"&&o!==null&&!(o instanceof Date))?new Error(`'${e}' orders numbers, strings and dates; it can't compare ${JSON.stringify(t)}`):null,ar=e=>new Error(`aggregate.mode must be one of ${yt.join(" / ")}, not '${String(e)}'`),wt=()=>new Error("A condition is exactly one of: a field, date, array or aggregate rule, all, any, or if/then[/else]"),F=(e,t,r)=>new Error(`${t} has no ${e==="toSql"?"SQL":"Prisma"} form${r?` (${r})`:""}; use ${e==="toSql"?"check()":"toSql() or check()"}.`),St=e=>new Error(`Windowing (filter/orderBy/take/skip) is not supported by ${e}() for this rule; evaluate with check()${e==="toPrisma"?" \u2014 toPrisma compiles a filter alone and an extremal take: 1":""}.`),To=(e,t)=>new Error(`'${e}' reads through the to-many relation '${t.prefix}'; compare its rows with an arrayOperator rule on '${t.prefix}'.`),ko=(e,t)=>new Error(`'${e}' continues past '${t}', which is not a Json column`),k=class extends Error{name="UsageError"};Rt.extend(Vb);Rt.extend(qb);Rt.extend(Ib);Rt.extend(jb);var Y=e=>{if(!fe(e))return false;let t=e;return "ago"in t||"ahead"in t||"this"in t||"last"in t||"next"in t||"start"in t||"end"in t},Ze="UTC",bn=e=>{if(e.now===void 0)throw new k("date expressions require `now` to be supplied to the evaluator");let t=Rt(e.now).tz(e.timeZone);if(!t.isValid())throw new k(`invalid \`now\`: ${String(e.now)}`);return t},Zs=(e,t)=>Object.entries(e).reduce((r,[o,n])=>Je[o].interval===t?r+n*Je[o].factor:r,0),lf="YYYY-MM-DDTHH:mm:ss.SSS",lr=(e,t,r,o)=>{let n=Zs(t,"months"),i=Zs(t,"days"),s=Zs(t,"secs"),a=Rt.utc(e.tz(o).format(lf));return n&&(a=a.add(r*n,"month")),i&&(a=a.add(r*i,"day")),s&&(a=a.add(r*s*1e3,"millisecond")),Rt.tz(a.format(lf),o)},Bb=e=>"ago"in e||"ahead"in e,Ki=(e,t)=>t===-1?{ago:e}:{ahead:e},we=e=>Bb(e)?"ago"in e?[e.ago,-1]:[e.ahead,1]:null,Rn=e=>"this"in e||"last"in e||"next"in e,On=e=>"start"in e||"end"in e,Co=e=>"this"in e?e.this:"last"in e?e.last:e.next,Wb=e=>{let t=Co(e);if(typeof t!="string"||!Ii.includes(t))throw new Error(`Unknown period unit '${String(t)}'`);return t},Ub=(e,t)=>e==="week"?t.weekStart==="sunday"?"week":"isoWeek":e,Ys=(e,t)=>{let r=bn(t),o=Wb(e),n=o==="isoWeek"?"week":o,i=r;"last"in e?i=r.subtract(1,n):"next"in e&&(i=r.add(1,n));let s=Ub(o,t);return [i.startOf(s),i.endOf(s)]},Xs=(e,t)=>{let r=we(e);if(r)return lr(bn(t),...r,t.timeZone);if(On(e)){let o="start"in e?e.start:e.end,[n,i]=Ys(o,t);return "start"in e?n:i}throw new Error("a point operator requires a rolling or start/end edge expression, not a bare period")},Mo=(e,t,r)=>{if(Rn(e)){let[o,n]=Ys(e,r),i=Eo({dateOperator:t})?.negates??t;return Fi.includes(i)?o:n}return Xs(e,r)},Lo=(e,t)=>{if(Rn(e))return Ys(e,t);let r=we(e);if(r){let o=bn(t),n=lr(o,...r,t.timeZone);return r[1]===-1?[n,o]:[o,n]}throw Qe("within")};var pf=["value","bind","path"],Ee=e=>typeof e.path=="string"&&e.path!=="",kr=e=>Ee(e)?L(e.path)??{depth:0,path:e.path}:null,xn=(e,t)=>{if(e.value!==void 0)return t.value(e.value);if(e.bind!==void 0)return t.bind(e.bind,e.bindOptional);if(Ee(e))return t.path(e.path);throw new Error("No value, path or bind specified")},Gi=e=>fe(e)&&(e.value!==void 0||Ee(e)||typeof e.bind=="string"),ea=(e,t,r)=>{if(!r||!Object.hasOwn(r,e)){if(t===true)return null;throw new k(`Missing binding for "${e}"`)}let o=r[e];return o===void 0?null:o},zi=(e,t,r)=>{if(t===true)return null;throw new k(`Unresolved binding '${e}' \u2014 resolve bindings (bindRule / bindLens) before compiling with ${r}().`)},Vt=(e,t,r)=>xn(e,{value:o=>o,bind:(o,n)=>ea(o,n,r),path:o=>Pi(o,t)??null});var ff=e=>typeof e=="object"&&e!==null,ra=e=>"if"in e||"then"in e||"else"in e,Se=e=>"arrayOperator"in e||"aggregate"in e,uf=e=>[...["all","any"].flatMap(t=>Array.isArray(e[t])?e[t].map((r,o)=>({key:t,index:o,child:r,nested:false})):[]),...ra(e)?["if","then","else"].flatMap(t=>e[t]!==void 0?[{key:t,child:e[t],nested:false}]:[]):[],...["condition","filter"].flatMap(t=>e[t]!==void 0?[{key:t,child:e[t],nested:true}]:[])],Fe=e=>"all"in e||"any"in e||ra(e),G=(e,t,r)=>{if(!ff(e))return;let o=e,n=t(o,r),i=n===void 0?r:n;for(let{child:s,nested:a}of uf(o))a?i!==false&&G(s,t,i):G(s,t,r);},cf=(e,t,r,o)=>{let n=false;return G(e,(i,s)=>(!n&&t(i,s)&&(n=true),n?false:r?.(i,s)),o),n},pr=(e,t,r)=>{if(!ff(e))return e;let o=r,n={...e},i=t.rewrite?t.rewrite(n,o):n,s=uf(i),a=s.some(d=>d.nested)&&t.below?t.below(i,o):o;for(let d of ["all","any"])Array.isArray(i[d])&&(i[d]=[...i[d]]);for(let{key:d,index:p,child:f,nested:u}of s){if(u&&a===false)continue;let m=pr(f,t,u?a:o);p===void 0?i[d]=m:i[d][p]=m;}let l=t.after?t.after(i,o):i;return l===i&&Kb(i,e)?e:l},Kb=(e,t)=>{let r=Object.keys(e);return r.length!==Object.keys(t).length?false:r.every(o=>{let[n,i]=[e[o],t[o]];return n===i?true:Array.isArray(n)&&Array.isArray(i)&&n.length===i.length&&n.every((s,a)=>s===i[a])})},Gb=(e,t)=>fe(e)?Object.fromEntries(Object.entries(e).map(([r,o])=>[r,Gi(o)?t(o,Ar(r)?"whole":"number"):o])):e,ta=(e,t)=>{let r=Y(e)?we(e):null;return r?Ki(Gb(r[0],t),r[1]):e},_o=(e,t)=>{let r="dateOperator"in e;if(!r&&!("operator"in e))return e;let o=e;if(r&&e.value!==void 0){let n=Array.isArray(e.value)?e.value.map(i=>ta(i,t)):ta(e.value,t);o={...o,value:n};}if(Gi(e.offset)){let n=r?{...e.offset,...e.offset.value!==void 0&&{value:ta(e.offset.value,t)}}:e.offset;o={...o,offset:t(n,r?"shift":"number")};}return Gi(o)&&(o=t(o,"value")),o},En=e=>{let t=[];return _o(e,(r,o)=>(t.push({source:r,role:o}),r)),t},$n=e=>En(e).flatMap(({source:t,role:r})=>Ee(t)?[{ref:t.path,role:r}]:[]),dr=e=>$n(e).map(t=>t.ref),Do=e=>[...Array.isArray(e.orderBy)?e.orderBy.flatMap(t=>typeof t?.field=="string"?[t.field]:[]):[],...typeof e.aggregate?.field=="string"?[e.aggregate.field]:[]],zb={all:"all",any:"any",if:"if",field:"field",aggregate:"aggregate",array:"array",date:"date"},Cr=()=>(e,t)=>({required:[...e],optional:[...t]}),df={all:Cr()(["all"],["error"]),any:Cr()(["any"],["error"]),if:Cr()(["if","then"],["else","error"]),field:Cr()(["field","operator"],["value","path","bind","bindOptional","offset","caseInsensitive","fuzzy","coerceType","error"]),aggregate:Cr()(["field","aggregate","operator"],["value","path","bind","bindOptional","condition","filter","orderBy","take","skip","error"]),array:Cr()(["arrayOperator"],["field","condition","count","filter","orderBy","take","skip","error"]),date:Cr()(["field","dateOperator"],["value","path","bind","bindOptional","offset","error"])},Hb=e=>({required:[...df[e].required],optional:[...df[e].optional]}),ne=e=>{let t=new Set;return "all"in e&&t.add("all"),"any"in e&&t.add("any"),ra(e)&&t.add("if"),"arrayOperator"in e&&t.add("array"),"dateOperator"in e&&t.add("date"),"aggregate"in e?t.add("aggregate"):"operator"in e&&t.add("field"),t.size===1?[...t][0]:null},z=e=>e.length===0?true:e.length===1?e[0]:{all:[...e]},oa=e=>typeof e=="object"&&"all"in e&&Array.isArray(e.all)?e.all.flatMap(oa):[e],Bt=e=>e.length===0?false:e.length===1?e[0]:{any:[...e]};var Jb=e=>En(e).flatMap(({source:t})=>typeof t.bind=="string"?[t]:[]),Pn=(e,{required:t=false}={})=>{let r=new Set;return G(e,o=>{for(let n of Jb(o))(!t||n.bindOptional!==true)&&r.add(n.bind);}),[...r].sort()},Qb=e=>{let t=new Set;return G(e,r=>{typeof r.field=="string"&&t.add(r.field);for(let{ref:o}of $n(r))t.add(o);return Se(r)?false:void 0}),[...t].sort()},na=(e,t)=>{let r=o=>{if(typeof o.bind!="string"||!Object.hasOwn(t,o.bind))return o;let{bind:n,bindOptional:i,...s}=o;return {...s,value:ea(n,true,t)}};return pr(e,{rewrite:o=>_o(_o(o,r),r)})};var mf=BigInt(Number.MAX_SAFE_INTEGER),vn=e=>{if(e>mf||e<-mf)throw new RangeError(`BigInt ${e} is outside the safe integer range (\xB12^53); json-rules compares BigInt as Int.`);return Number(e)},ia=e=>typeof e=="bigint"?vn(e):typeof e=="string"&&e.trim()!==""&&Number.isFinite(Number(e))?Number(e):e,Hi=(e,t)=>{if(e==null)return null;let r=ia(e);if(typeof r!="number"||!Number.isFinite(r))throw new Error(`${t} reads a number (got ${String(e)})`);return r},Be=([e,t])=>t<e?[t,e]:[e,t],Ye=(e,t)=>{if(!Array.isArray(e)||e.length!==2)throw new Error(`${t} operator requires an array of two values`);return [e[0],e[1]]},Fo=(e,t)=>{let r=Ye(e,t);if(!r.every(ce))throw new Error(`${t} requires two ends that order \u2014 numbers, strings or dates (got ${JSON.stringify(e)})`);return r},Ji=e=>{if(!Array.isArray(e))throw new Error(`in / notIn requires a list (got ${JSON.stringify(e)})`);return e},We=e=>{let t=Ji(e),r=t.filter(o=>o!==null);return {values:r,hasNull:r.length!==t.length}},ce=e=>typeof e=="string"||typeof e=="number"||e instanceof Date;var sa=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&(!Ar(t)||Number.isInteger(e))?null:`${t} must be a non-negative${Ar(t)?" whole":""} number (got ${String(e)})`,aa=(e,t,r)=>{let o=typeof e=="number"?e:Hi(t(e),e.path?`'${e.path}' (${r})`:r),n=o===null?null:sa(o,r);if(n===null)return o;if(typeof e!="number"&&Ee(e))return null;throw new Error(n)},Mr=(e,t)=>{let r={};for(let[o,n]of Object.entries(e)){if(n===void 0)continue;let i=aa(n,t,o);if(i===null)return null;r[o]=i;}return r},bt=(e,t)=>{let r=we(e);if(!r)return e;let o=Mr(r[0],t);return o?Ki(o,r[1]):null};var Zb=e=>{let t=we(e);if(t)return fe(t[0])?Object.keys(t[0]).flatMap(n=>vo(n)?[Je[n].clock]:[]):[];let r=On(e)?"start"in e?e.start:e.end:e;if(!fe(r))return [];let o=Co(r);return rf(o)?[ji[o]]:[]},gf=(e,t)=>[...ii(e),t].filter(Y).flatMap(Zb),Yb=e=>ii(e).some(Y),Qi=e=>wn.indexOf(e),Xb=()=>{let e=ze.get("clock.finestUnit");if(wn.includes(e))return e;if(typeof e=="string"&&vo(e))return Je[e].clock;throw new k(`clock.finestUnit reads a clock unit, singular or plural (got ${String(e)})`)},Wt=(e,t)=>{let r=gf(e,t);if(r.length===0)return null;let o=Xb(),n=r.find(i=>Qi(i)<Qi(o));return n?af(n,o):null},la=e=>fe(e)?e.value:void 0,eR=e=>{let t=null;return G(e,r=>{if(!("dateOperator"in r))return;let o=la(r.offset),n=Wt(r.value,o);if(n)throw n;if(Yb(r.value))for(let i of gf(r.value,o))(t===null||Qi(i)<t)&&(t=Qi(i));}),t===null?null:wn[t]};var Lr=(e,t)=>{if(e==null)return null;if(Array.isArray(e)){let o=e.map(n=>Lr(n,t));return o.some(n=>n===null)?null:o}let r=ia(e);if(typeof r!="number"||!Number.isFinite(r))throw new Error(`offset needs a numeric comparison value (got ${String(e)})`);return r+t},_r=e=>Hi(e,"an offset"),jo=e=>{if(e==null)return null;let t=Y(e)?we(e):null;if(!t)throw new Error(`a date offset reads { ago } or { ahead } (got ${JSON.stringify(e)})`);return t};Rt.extend(Vb);Rt.extend(qb);Rt.extend(rR);Rt.extend(tR);var wf=(e,t,r={},o)=>{let n=tr(e.field,t),i=Dr(r,u=>Vt(u,t,o)),s=i.timeZone;if(n==null)return B.includes(e.dateOperator)?true:e.error||`${e.field} has no value`;let a=ce(n)?fr(n,s):null;if(!a?.isValid())throw new Error(`${e.field} is not a valid date: ${String(n)}`);let l=u=>e.error||`${e.field} ${u}`;if(Bd.includes(e.dateOperator)){let u=pa(Vt(e,t,o));if(u===null)return e.error||`${e.field} has no comparison value`;let m=u.includes(a.tz(s).day()),y=u.map(c=>No[c]).join(" or ");return e.dateOperator===v.dayIn?m||l(`must be on ${y}`):!m||l(`must not be on ${y}`)}let d=iR(e,t,i,s,o);if(d===null)return e.error||`${e.field} has no comparison value`;let[p,f=p]=d;switch(e.dateOperator){case v.before:return a.isBefore(p)||l(`must be before ${p.format()}`);case v.after:return a.isAfter(p)||l(`must be after ${p.format()}`);case v.onOrBefore:return a.isSameOrBefore(p)||l(`must be on or before ${p.format()}`);case v.onOrAfter:return a.isSameOrAfter(p)||l(`must be on or after ${p.format()}`);case v.within:return a.isSameOrAfter(p)&&a.isSameOrBefore(f)||l(`must be within ${p.format()} and ${f.format()}`);case v.notBefore:return a.isSameOrAfter(p)||l(`must not be before ${p.format()}`);case v.notAfter:return a.isSameOrBefore(p)||l(`must not be after ${p.format()}`);case v.notWithin:return a.isBefore(p)||a.isAfter(f)||l(`must not be within ${p.format()} and ${f.format()}`);case v.between:return a.isSameOrAfter(p)&&a.isSameOrBefore(f)||l(`must be between ${p.format()} and ${f.format()}`);case v.notBetween:return a.isBefore(p)||a.isAfter(f)||l(`must not be between ${p.format()} and ${f.format()}`);default:throw le(e.dateOperator,"date")}},iR=(e,t,r,o,n)=>{let i=e.dateOperator,s=g=>Vt(g,t,n),a=Vt(e,t,n);if(a==null)return null;let l=e.offset===void 0?void 0:s(e.offset),d=Wt(a,l);if(d)throw d;let p=l===void 0?void 0:jo(l);if(p===null)return null;let f=g=>{if(p===void 0)return g;let w=Mr(p[0],s);return w&&lr(g,w,p[1],o)};if(gn.includes(i)){if(!Y(a))throw Qe(i);let g=bt(a,s);return g&&Lo(g,r)}let u=(g,w)=>{if(g==null)return null;if(Y(g)){let S=bt(g,s);return S&&Xs(S,r)}let R=fr(g,o);if(!R.isValid())throw new Error(`Invalid ${w}: ${String(g)}`);return R};if(Wd.includes(i)){let[g,w]=Ye(a,i),R=u(g,"start date"),S=u(w,"end date");if(!R||!S)return null;let[b,$]=Be([R,S]),E=f(b),I=f($);return E&&I?[E,I]:null}if(Array.isArray(a))throw new Error(`${i} operator requires a single date value`);let m=g=>{let w=bt(g,s);return w&&Mo(w,i,r)},y=Y(a)?m(a):u(a,"comparison date");if(!y)return null;let c=f(y);return c&&[c]},Dr=(e,t)=>{let r=e.timeZone;if(r===void 0||typeof r=="string")return {...e,timeZone:hf(r??Ze)};if(kr(r))throw new k(`timeZone is one per evaluation; give it as a string or a { bind }, not the row path '${r.path}'`);let o=t(r);if(o!=null&&typeof o!="string")throw new k(`timeZone reads a zone name (got ${String(o)})`);return {...e,timeZone:hf(o??Ze)}},yf=new Set,hf=e=>{if(yf.has(e))return e;try{new Intl.DateTimeFormat("en-US",{timeZone:e});}catch{throw new k(`invalid time zone: ${e}`)}return yf.add(e),e},sR=/\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?\s*(?:[zZ]|[+-]\d{2}(?::?\d{2})?)$/,aR=e=>sR.test(e.trim())||/\b(?:GMT|UTC)\b/.test(e),fr=(e,t)=>{if(typeof e=="string"&&/^-?\d+$/.test(e.trim()))return Rt(Number(e));if(typeof e=="string"&&!aR(e)){let r=Rt(e);return r.isValid()?Rt.tz(e,t):r}return typeof e=="string"?Rt(new Date(e.trim())):Rt(e)},Zi=(e,t)=>{let r=ce(e)?fr(e,t):Rt(Number.NaN);if(!r.isValid())throw new Error(`Invalid date value: ${String(e)}`);return r.toDate()},pa=e=>{if(e==null)return null;if(!Array.isArray(e))throw new Error("a weekday operator requires an array of day names");return e.map(t=>{let r=No.indexOf(String(t).toLowerCase());if(r===-1)throw new Error(`Unknown day name: ${String(t)}`);return r})};var pR=e=>e<=3?0:e<=6?1:2,dR=(e,t)=>{let{maxDistance:r,maxRatio:o}=e,n=[];return typeof r=="number"&&n.push(r),typeof o=="number"&&n.push(Math.floor(t*o)),n.length>0?Math.min(...n):pR(t)},Sf=e=>e.split(/[^a-z0-9\p{L}]+/u).filter(Boolean),fR=e=>/^\d+$/.test(e),uR=(e,t,r)=>e===t?true:Math.abs(e.length-t.length)>r?false:distance(e,t)<=r,bf=(e,t,r={})=>{let o=t.trim().toLowerCase();if(!o)return true;let n=e.toLowerCase();if(n.includes(o))return true;let i=Sf(o);if(i.length===0)return false;let s=Sf(n);return s.length===0?false:i.every(a=>{let l=dR(r,a.length);return l===0||fR(a)?s.includes(a):s.some(d=>uR(a,d,l))})};var ur=e=>{let t=e instanceof RegExp?e.source:e,r=e instanceof RegExp?e.flags:"";if(/[^i]/.test(r))throw new Error(`Refused pattern /${t}/${r}: only the 'i' flag is supported`);let o=r==="i";try{return {source:t,caseInsensitive:o,re:RE2JS.compile(t,o?RE2JS.CASE_INSENSITIVE:0)}}catch(n){throw new Error(`Refused pattern /${t}/: ${n.message}`)}},Io={d:"0-9",w:"0-9A-Za-z_",s:"\\t\\n\\f\\r "},Of={alnum:"0-9A-Za-z",alpha:"A-Za-z",ascii:"\\u0000-\\u007f",blank:"\\t ",cntrl:"\\u0000-\\u001f\\u007f",digit:"0-9",graph:"!-~",lower:"a-z",print:" -~",punct:"!-/:-@\\[-`{-~",space:"\\t\\n\\v\\f\\r ",upper:"A-Z",word:"0-9A-Za-z_",xdigit:"0-9A-Fa-f"},cR=/[\\^$.|?*+()[\]{}]/,da=255,xf=e=>e<=65535?`\\u${e.toString(16).padStart(4,"0")}`:`\\U${e.toString(16).padStart(8,"0")}`,mR=e=>cR.test(e)?`\\${e}`:e,Nn=e=>{let t=s=>{throw new Error(`Refused pattern /${e}/: ${s} has no Postgres form`)},r="",o=0,n=()=>{/^([*+?]|\{\d)/.test(e.slice(o))&&t("a quantified anchor");},i=s=>{let a=e[o+1];if(o+=2,Object.hasOwn(Io,a))return s?Io[a]:`[${Io[a]}]`;let l=a.toLowerCase();if(a!==l&&Object.hasOwn(Io,l))return s&&t(`a negated class \\${a} inside brackets`),`[^${Io[l]}]`;if(a==="p"||a==="P")return t("a Unicode class");if(a==="C")return t("\\C");if(a==="x"){let d=e[o]==="{",p=d?e.indexOf("}",o):o+2,f=e.slice(d?o+1:o,p);return o=d?p+1:p,xf(Number.parseInt(f,16))}if(a>="0"&&a<="7"){let d=a;for(;d.length<3&&e[o]>="0"&&e[o]<="7";)d+=e[o++];return xf(Number.parseInt(d,8))}if(!s&&(a==="b"||a==="B")){let d=`[${Io.w}]`;return a==="b"?`(?:(?<=${d})(?!${d})|(?<!${d})(?=${d}))`:`(?:(?<=${d})(?=${d})|(?<!${d})(?!${d}))`}if(!s&&(a==="z"||a==="A"))return n(),a==="z"?"\\Z":"\\A";if(a==="Q"){let d=e.indexOf("\\E",o),p=e.slice(o,d===-1?void 0:d);return o=d===-1?e.length:d+2,[...p].map(s?f=>/[\\\]^-]/.test(f)?`\\${f}`:f:mR).join("")}return `\\${a}`};for(;o<e.length;){let s=e[o];if(s==="\\")r+=i(false);else if(s===".")r+="[^\\n]",o++;else if(s==="("&&e[o+1]==="?"){let a=/^\(\?P?<[^>]+>/.exec(e.slice(o));a?(r+="(",o+=a[0].length):e[o+2]===":"?(r+="(?:",o+=3):t("a flag group");}else if(s==="{"){let a=/^\{(0|[1-9]\d*)(?:,(0|[1-9]\d*)?)?\}/.exec(e.slice(o));if(!a){r+="\\{",o++;continue}(Number(a[1])>da||Number(a[2]??0)>da)&&t(`a repeat count past ${da}`),r+=a[0],o+=a[0].length;}else if(s==="["){r+="[",o++,e[o]==="^"&&(r+="^",o++),e[o]==="]"&&(r+="\\]",o++);let a=false,l=false,d=0;for(;o<e.length&&e[o]!=="]";){let p=l?null:/^\[:(\^?)([a-z]+):\]/.exec(e.slice(o)),f=!!p||/^\\[dswDSW]/.test(e.slice(o)),u=e[o]==="-"&&d>0&&e[o+1]!=="]"&&!l;p?(p[1]&&t(`a negated class [:^${p[2]}:]`),Object.hasOwn(Of,p[2])||t(`the class [:${p[2]}:]`),r+=Of[p[2]],o+=p[0].length):e[o]==="\\"?r+=i(true):u&&a?(r+="\\-",o++):(r+=e[o]==="["?"\\[":e[o],o++);let m=l;l=u&&!a,a=f||m,d++;}r+="]",o++;}else r+=s,o++,(s==="^"||s==="$")&&n();}return r},Ef=(e,t)=>{try{let{source:r}=ur(e);return t==="toSql"&&Nn(r),null}catch(r){return r.message}};var $f=e=>e==null||e===""||Array.isArray(e)&&e.length===0,be=(e,t)=>{let r=t==null;return r&&(e.offset!==void 0||qd.includes(e.operator))?true:Ve.includes(e.operator)?r||Array.isArray(t)&&t.some(o=>o==null):false},Ut=e=>nr.includes(e.operator)||ht.includes(e.operator)&&e.value===null&&e.path===void 0&&e.bind===void 0,Xi=(e,t)=>{let r=t.filter(n=>Array.isArray(n)||n===null),o=n=>r.map(i=>({...e,operator:n,value:i}));return e.operator===h.in?Bt(o(h.equals)):z(o(h.notEquals))},jr=e=>typeof e=="string"?e.toLowerCase():Array.isArray(e)?e.map(jr):e,Pf=e=>typeof e=="bigint"?vn(e):Array.isArray(e)&&e.some(t=>typeof t=="bigint")?e.map(t=>typeof t=="bigint"?vn(t):t):e,vf=(e,t,r)=>{if(e==null)return e;if(He.includes(t)){if(typeof e!="string"||e.trim()==="")return e;if(t==="BigInt"&&/^-?\d+$/.test(e.trim()))return vn(BigInt(e.trim()));let o=Number(e);return Number.isFinite(o)?o:e}switch(t){case "DateTime":{if(e instanceof Date)return e.getTime();if(typeof e=="number"||typeof e!="string")return e;let o=fr(e,r);return o.isValid()?o.valueOf():e}case "Boolean":return e==="true"?true:e==="false"?false:e;case "String":return typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):e;default:return e}},Fr=(e,t,r=Ze)=>t===void 0?e:Array.isArray(e)?e.map(o=>vf(o,t,r)):vf(e,t,r),An=(e,t,r,o={},n)=>{let i=n?n.value:tr(e.field,t);if(o.absent==="unknown"&&!Di.includes(e.operator)&&(i===void 0||Ee(e)&&Pi(e.path,t)===void 0))return e.error||`${e.field} is unknown`;let s=i??null,a=e.coerceType??(s instanceof Date?"DateTime":void 0),l=a==="DateTime"?Dr(o,S=>Vt(S,t,r)).timeZone:Ze,d=Fr(Pf(s),a,l),p=!nr.includes(e.operator),f=p?gR(Fr(Pf(Vt(e,t,r)??null),a,l),e,t,r):void 0;if(p&&be(e,f))return B.includes(e.operator)&&d==null?true:e.error||`${e.field} has no comparison value`;let u=S=>e.error||`${e.field} ${S}${p?` ${f instanceof RegExp?String(f):JSON.stringify(f)}`:""}`,m=se(e.caseInsensitive),y=S=>m?jr(S):S,c=y(d),g=y(f),w=Ni(e.fuzzy),R=()=>w&&typeof d=="string"&&typeof f=="string"?bf(d,f,w):Array.isArray(d)?c.some(S=>Ft(S,g)):yR(c,g);switch(e.operator){case h.equals:return Ft(c,g)||u("must equal");case h.notEquals:return !Ft(c,g)||u("must not equal");case h.lessThan:return Yi(d,f,"lt")||u("must be less than");case h.lessThanEquals:return Yi(d,f,"lte")||u("must be less than or equal to");case h.greaterThan:return Yi(d,f,"gt")||u("must be greater than");case h.greaterThanEquals:return Yi(d,f,"gte")||u("must be greater than or equal to");case h.in:return Ji(g).some(S=>Ft(S,c))||u("must be one of");case h.notIn:return !Ji(g).some(S=>Ft(S,c))||u("must not be one of");case h.contains:return R()||u("must contain");case h.notContains:return !R()||u("must not contain");case h.matches:return Nf(d)&&Af(f)&&ur(f).re.test(d)||u("must match pattern");case h.notMatches:return !Nf(d)||!Af(f)||!ur(f).re.test(d)||u("must not match pattern");case h.between:{let S=Tf(f,e.operator);if(!Cf(d,S))return u("must be between");let b=qo(d),[$,E]=S;return b>=$&&b<=E||u("must be between")}case h.notBetween:{let S=Tf(f,e.operator);if(!Cf(d,S))return true;let b=qo(d),[$,E]=S;return b<$||b>E||u("must not be between")}case h.isEmpty:return $f(d)||u("must be empty");case h.notEmpty:return !$f(d)||u("must not be empty");case h.exists:return d!=null||u("must exist");case h.notExists:return d==null||u("must not exist");case h.startsWith:return typeof c=="string"&&typeof g=="string"&&c.startsWith(g)||u("must start with");case h.endsWith:return typeof c=="string"&&typeof g=="string"&&c.endsWith(g)||u("must end with");case h.notStartsWith:return !(typeof c=="string"&&typeof g=="string"&&c.startsWith(g))||u("must not start with");case h.notEndsWith:return !(typeof c=="string"&&typeof g=="string"&&c.endsWith(g))||u("must not end with");default:throw new Error("Unknown operator")}},gR=(e,t,r,o)=>{if(t.offset===void 0)return e;let n=_r(Vt(t.offset,r,o));return n===null?null:Lr(e,n)},qo=e=>e instanceof Date?e.getTime():e,Yi=(e,t,r)=>{if(!hR(e,t)||!ce(t))return false;let o=qo(e),n=qo(t);switch(r){case "lt":return o<n;case "lte":return o<=n;case "gt":return o>n;case "gte":return o>=n}},Nf=e=>typeof e=="string",Af=e=>typeof e=="string"||e instanceof RegExp,Tf=(e,t)=>Be(Fo(e,t).map(r=>qo(r))),yR=(e,t)=>typeof e=="string"&&typeof t=="string"&&e.includes(t),hR=(e,t)=>ce(e)&&ce(t)&&kf(e)===kf(t),kf=e=>e instanceof Date?"date":typeof e,Cf=(e,t)=>ce(e)&&typeof qo(e)==typeof t[0];var $e=e=>e.filter!==void 0||!!e.orderBy?.length||e.take!==void 0||e.skip!==void 0,wR=e=>{if(typeof e!="object"||e===null)return null;let t=e,r=ne(t);return r!=="field"&&r!=="date"||typeof t.field!="string"?null:{op:String(r==="date"?t.dateOperator:t.operator),field:t.field}},SR=e=>{if(e.filter!==void 0||e.skip!==void 0&&e.skip!==0||e.take!==1||e.orderBy?.length!==1)return null;let{field:t,dir:r}=e.orderBy[0];if(r!=="asc"&&r!=="desc")return null;let o=null;if(e.arrayOperator===x.all?o="all":(e.arrayOperator===x.any||e.arrayOperator===x.atLeast&&e.count===1)&&(o="any"),!o)return null;let n=wR(e.condition);if(!n||n.field!==t)return null;let i=Fi.includes(n.op),s=Qd.includes(n.op);if(!i&&!s)return null;let a=r==="desc";if(!(o==="all"?a&&i||!a&&s:a&&s||!a&&i))return null;let{orderBy:d,take:p,skip:f,count:u,...m}=e;if(o==="any")return {...m,arrayOperator:x.any};let y={field:t,operator:h.exists};return {any:[{field:e.field,arrayOperator:x.empty},{all:[{field:e.field,arrayOperator:x.any,condition:y},{...m,arrayOperator:x.all,condition:{if:y,then:e.condition}}]}]}},fa=(e,t,r)=>{let o=e;return t.filter!==void 0&&r&&(o=o.filter(r)),t.orderBy?.length&&(o=Mf(o,t.orderBy)),t.skip!==void 0&&(o=o.slice(t.skip)),t.take!==void 0&&(o=o.slice(0,t.take)),o},Mf=(e,t)=>[...e].sort((r,o)=>{for(let{field:n,dir:i}of t){let s=bR(ue(r,n),ue(o,n),i);if(s!==0)return s}return 0}),bR=(e,t,r)=>{let o=e==null,n=t==null;if(o||n)return o===n?0:o?1:-1;let i=e instanceof Date?e.getTime():e,s=t instanceof Date?t.getTime():t,a=i<s?-1:i>s?1:0;return r==="asc"?a:-a},Vo=e=>{if(!$e(e))return e;let t=!!e.orderBy?.length||e.take!==void 0||e.skip!==void 0;if(e.filter!==void 0&&!t){let{filter:r,...o}=e;if("aggregate"in e)return {...o,condition:e.condition===void 0?r:z([r,e.condition])};switch(e.arrayOperator){case "all":return {...o,condition:{if:r,then:e.condition??true}};case "empty":return {...o,arrayOperator:"none",condition:r};case "notEmpty":return {...o,arrayOperator:"any",condition:r};default:return {...o,condition:e.condition===void 0?r:z([r,e.condition])}}}return "aggregate"in e||e.filter!==void 0?null:SR(e)};var RR=e=>G(e,t=>{let r=ne(t);if(!(r==="all"||r==="any")){if(r==="array"&&!("field"in t))return false;throw new Error("check: when data is an array, every leaf must be a fieldless arrayOperator (composable with all/any)")}}),me=(e,t,r)=>(Array.isArray(t)&&RR(e),Ot(e,t,{...r,scopes:[t]})),Ot=(e,t,r)=>{if(typeof e=="boolean")return e;let o=e;switch(ne(e)){case "all":return OR(o.all,t,r,o.error);case "any":return xR(o.any,t,r,o.error);case "if":return ER(o,t,r);case "array":return PR(o,r);case "aggregate":return $R(o,r);case "date":return wf(o,r.scopes,r,r.bindings);case "field":return An(o,r.scopes,r.bindings,r);default:throw wt()}},es=(e,t)=>({...e,scopes:[...e.scopes,t]}),OR=(e,t,r,o)=>{let n=[];for(let i of e){let s=Ot(i,t,r);s!==true&&(typeof s=="string"?n.push(s):n.push("false"));}return n.length?o||(n.length===1?n[0]:`All conditions must pass: ${n.join(" AND ")}`):true},xR=(e,t,r,o)=>{let n=[];for(let i of e){let s=Ot(i,t,r);if(s===true)return true;typeof s=="string"&&n.push(s);}return o||(n.length===1?n[0]:`At least one condition must pass: ${n.join(" OR ")}`)},ER=(e,t,r)=>Ot(e.if,t,r)===true?Ot(e.then,t,r):e.else!==void 0?Ot(e.else,t,r):true,Lf=(e,t)=>{if(e==null)return [];if(!Array.isArray(e))throw new Error(`${t} must be an array`);return e},$R=(e,t)=>{let r=Lf(tr(e.field,t.scopes),e.field),o=e.filter,n=fa(r,e,o?m=>Ot(o,m,es(t,m))===true:void 0),{mode:i,field:s}=e.aggregate;if(!yt.includes(i))throw ar(i);let a=e.condition,d=(a?n.filter(m=>Ot(a,m,es(t,m))===true):n).flatMap((m,y)=>{let c=s?ue(m,s):m;if(c==null)return [];if(typeof c!="number"||!Number.isFinite(c)){let g=`${e.field}[${y}]${s?`.${s}`:""}`;throw new Error(`${g} must be a finite number`)}return [c]}),p=d.reduce((m,y)=>m+y,0),f=i==="sum"||d.length===0?p:p/d.length,u={...e,field:`${e.field} ${i}`};return An(u,t.scopes,t.bindings,t,{value:f})},PR=(e,t)=>{let r=Lf(e.field?tr(e.field,t.scopes):t.scopes[t.scopes.length-1],e.field||"(root)"),o=e.filter,n=fa(r,e,o?f=>Ot(o,f,es(t,f))===true:void 0),i=f=>e.error||`${e.field} ${f}`,s=e.condition,a=_i.includes(e.arrayOperator);if(a&&s===void 0)throw De(e.arrayOperator);let l=e.count??0;if(yn.includes(e.arrayOperator)&&e.count===void 0)throw Ao(e.arrayOperator);let d=0,p=0;if(a&&s!==void 0){if(n.length>0&&!Ks(n,J))return i("contains only primitive values; use 'in' or 'contains' instead of array operators on primitive arrays");let f=n.map(u=>Ot(s,u,es(t,u)));d=f.filter(u=>u===true).length,p=f.filter(u=>typeof u=="string").length;}switch(e.arrayOperator){case x.empty:return !n.length||i("must be empty");case x.notEmpty:return !!n.length||i("must not be empty");case x.all:return d===n.length||i(`all elements must match (${p} failed)`);case x.any:return !!d||i("at least one element must match");case x.none:return !d||i(`no elements should match (${d} matched)`);case x.atLeast:return d>=l||i(`at least ${l} elements must match (${d} matched)`);case x.atMost:return d<=l||i(`at most ${l} elements must match (${d} matched)`);case x.exactly:return d===l||i(`exactly ${l} elements must match (${d} matched)`);default:throw le(e.arrayOperator,"array")}};var O=(e,t)=>e!==void 0&&Object.hasOwn(e,t)?e[t]:void 0,Kt=(e,t,r)=>(Object.hasOwn(e,t)||(e[t]=r()),e[t]),T=(e,t)=>O(e?.models,t),Pe=(e,t,r)=>O(T(e,t)?.fields,r);var ke=({fieldMap:e,model:t})=>`${e}:${t}`,_f=(e,t)=>{let r=e.indexOf(":");return r===-1?{mapName:t,modelName:e}:{mapName:e.slice(0,r),modelName:e.slice(r+1)}};var Df=(e,t,r,o)=>{let n={};for(let i of e){let s=O(i,t);if(s==null)continue;let a=String(s);if(Object.hasOwn(n,a)){let l=o==="one"?`endpoint[0] must be the "one" side of a oneToMany bridge \u2014 swap endpoints if '${r}' is the "many" side`:`oneToOne bridges require unique '${t}' on both endpoints`;throw new Error(`indexBridges: duplicate '${t}' value '${a}' on '${r}' \u2014 ${l}.`)}n[a]=i;}return n},vR=(e,t)=>{let r={};for(let o of e){let n=O(o,t);n!=null&&Kt(r,String(n),()=>[]).push(o);}return r},Ff=(e,t)=>{let r={};for(let o of e.bridges??[]){let[n,i]=o.endpoints,s=ke(n),a=ke(i),l=o.cardinality==="oneToMany"?"one":"oneToOne",d=(u,m)=>Kt(Kt(r,u,()=>({})),m,()=>({})),p=O(t,s);p&&(d(n.fieldMap,n.model)[n.on]=Df(p,n.on,s,l));let f=O(t,a);f&&(o.cardinality==="oneToMany"?d(i.fieldMap,i.model)[i.on]=vR(f,i.on):d(i.fieldMap,i.model)[i.on]=Df(f,i.on,a,"oneToOne"));}return r};var ts=e=>{let t={maps:structuredClone(e.maps),bridges:e.bridges?structuredClone(e.bridges):void 0};for(let r of e.bridges??[]){let[o,n]=r.endpoints,i=ke(o),s=ke(n),a=T(O(t.maps,o.fieldMap),o.model),l=T(O(t.maps,n.fieldMap),n.model);if(!a)throw new Error(`stitchFieldMaps: endpoint '${i}' not found`);if(!l)throw new Error(`stitchFieldMaps: endpoint '${s}' not found`);if(o.fieldMap===n.fieldMap&&o.model===n.model)throw new Error(`stitchFieldMaps: self-bridge '${i}' to itself is not supported`);if(!O(a.fields,o.on))throw new Error(`stitchFieldMaps: endpoint '${i}' has no field '${o.on}' for join`);if(!O(l.fields,n.on))throw new Error(`stitchFieldMaps: endpoint '${s}' has no field '${n.on}' for join`);if(O(a.fields,s))throw new Error(`stitchFieldMaps: bridge '${s}' already injected on '${i}'`);if(O(l.fields,i))throw new Error(`stitchFieldMaps: bridge '${i}' already injected on '${s}'`);let d=r.cardinality==="oneToMany";a.fields[s]={kind:"bridge",type:s,isList:d},l.fields[i]={kind:"bridge",type:i,isList:false};}return t};var Bo=(e,t,r)=>{if(e?.isList||t?.isList){if(!(e?.isList&&!t?.isList&>.includes(r)))return "a list column compares with no column but by membership";if(e?.kind!=="enum"&&t?.kind!=="enum")return null}let o=[e,t].filter(n=>n?.kind==="enum");return o.length===0?null:o.length===1||e?.type!==t?.type?"an enum compares only with an enum column of its own type":ht.includes(r)?null:`an enum column orders by declaration on the database, not as check() compares its text ('${r}')`};var je=e=>e.kind==="scalar"&&e.type==="Json",V=e=>e.kind==="object"||e.kind==="bridge",Ir=(e,t)=>e.values??O(t,e.type);var ve=(e,t,r)=>{if(!e||!("maps"in e))return e;if(!t)throw new Error(`${r}: 'map' is a FieldMapSet \u2014 'mapName' is required to resolve which map to use.`);let o=O(e.maps,t);if(!o)throw new Error(`${r}: fieldMap set has no entry for '${t}'`);return o};var Xe=(e,t)=>e.kind==="object"?{mapName:t,modelName:e.type}:e.kind==="bridge"?_f(e.type,t):null;function*cr(e,t,r){let o=r.split("."),n=t;for(let i=0;i<o.length;i++){let s=o[i],a=Pe(O(e,n.mapName),n.modelName,s),l=a?Xe(a,n.mapName):null;if(yield {index:i,field:s,at:n,entry:a,next:l},!l)return;n={...l,relPath:[...n.relPath,s]};}}var te=(e,t,r)=>{let o=e.split("."),n=[],i={mapName:"",modelName:r,relPath:[]};for(let{index:s,field:a,at:l,entry:d}of cr({"":t},i,e)){let p=l.modelName;if(!d)return {kind:"fallback",hops:n};if(d.kind==="bridge")return {kind:"bridge",hops:n};let f=s===o.length-1;if(d.kind==="object"){if(!T(t,d.type))return {kind:"fallback",hops:n};if(f)return {kind:"direct",hops:n,entry:d,model:p,column:a};n.push({field:a,prefix:o.slice(0,s+1).join("."),entry:d,from:p});continue}return f?{kind:"direct",hops:n,entry:d,model:p,column:a}:je(d)?{kind:"json-path",hops:n,entry:d,model:p,column:a,stopIndex:s+1,jsonPath:o.slice(s+1)}:{kind:"past-scalar",hops:n,column:a}}return {kind:"fallback",hops:n}},mr=(e,t,r)=>t&&r?te(e,t,r):void 0,X=(e,t,r)=>{let o=mr(e,t,r);return o?.kind==="direct"?o.entry:void 0},jf=(e,t,r)=>te(e,t,r).hops.filter(o=>!o.entry.isList&&o.entry.isRequired===false).map(o=>o.prefix),Tn=(e,t,r)=>{let o=te(e,t,r);return o.kind==="direct"&&o.entry.kind==="object"?o.entry.type:null},gr=(e,t,r)=>te(e,t,r).kind==="bridge",xt=(e,t,r)=>!!t&&!!r&&cf(e,(o,n)=>typeof o.field=="string"&&o.field!==""&&gr(o.field,t,n),(o,n)=>(typeof o.field=="string"?Tn(o.field,t,n):n)??false,r);var qr=e=>e?.kind==="json-path"?"json-path":e?.kind!=="direct"?"unknown":e.entry.kind==="object"?e.entry.isList?"relations":"relation":e.entry.isList?"list":e.entry.kind==="enum"?"enum":If(e.entry.type),If=e=>e===Q.Json?"json":e===Q.Enum?"enum":e===Q.DateTime?"instant":e===Q.String?"text":"scalar",rs=(e,t,r)=>{let o=X(e.field,t,r);return o?o.kind==="scalar"&&(o.type==="String"||o.type==="Json"):e.coerceType===void 0||e.coerceType==="String"||e.coerceType==="Json"},os=(e,t,r)=>{if(qr(mr(e,t,r))==="relations")throw Bi(e)},Vr=e=>e!=="scalar"&&e!=="instant"&&e!=="list"&&e!=="enum"&&e!=="relation"&&e!=="relations",yr=(e,t)=>Vr(e)&&qf(t),qf=e=>typeof e=="string"||Array.isArray(e)&&e.some(qf),Ie=(e,t,r)=>{let o=qr(mr(e.field,t,r));return o==="unknown"&&e.coerceType!==void 0?If(e.coerceType):o},et=e=>{if(!e.isList){if(e.kind==="enum")return Q.Enum;if(!(e.kind!=="scalar"||e.type===Q.Json))return Ci(e.type)?e.type:void 0}};var Vf=new WeakSet,is=e=>(Vf.add(e),e),Bf=e=>{if(e===null||typeof e!="object")return false;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Wf=e=>{let t=[],r=(o,n)=>{if(o!==null&&typeof o=="object"&&Vf.has(o)){t.push({path:n});return}if(Array.isArray(o))for(let[i,s]of o.entries())r(s,[...n,i]);else if(Bf(o))for(let[i,s]of Object.entries(o))r(s,[...n,i]);};return r(e,[]),t},NR=["__step","__field"],ns=e=>Array.isArray(e)?e.some(ns):Bf(e)?Object.entries(e).some(([t,r])=>NR.includes(t)||ns(r)):false;var AR={[h.equals]:"equals",[h.notEquals]:"equals",[h.lessThan]:"lt",[h.lessThanEquals]:"lte",[h.greaterThan]:"gt",[h.greaterThanEquals]:"gte"},Uf=(e,t,r)=>{let o=te(e,t,r);if(o.kind!=="direct"||o.hops.length>0)return `'${e}' is not a column of ${r} (a relation hop or an undeclared path)`;let{entry:n}=o;return V(n)?`'${e}' is a relation`:je(n)?`'${e}' is a Json column`:n.isList?`'${e}' is a list column`:n},ss=(e,t,r,o,n=false)=>{let i=e.path;if(n)return {problem:"inside a counting step (a count or relation aggregate) a groupBy carries no column reference"};let s=L(i);if(s&&s.depth>1)return {problem:`'${i}' reads an enclosing scope, which a Prisma filter can't reach`};if(!s&&o)return {problem:`'${i}' reads the root row, which a Prisma relation filter can't reach`};if(!t||!r)return {problem:"comparing two columns needs the map and model"};let a=AR[e.operator];if(!a)return {problem:`'${e.operator}' takes no column reference in Prisma`};if(e.offset!==void 0)return {problem:"an offset is arithmetic, which Prisma lacks"};let l=Uf(e.field,t,r);if(typeof l=="string")return {problem:l};let d=s?s.path:i,p=Uf(d,t,r);if(typeof p=="string")return {problem:p};if(l.kind!==p.kind||l.type!==p.type)return {problem:`'${e.field}' (${l.type}) and '${d}' (${p.type}) are not the same type`};let f=Bo(l,p,e.operator);return f?{problem:f}:l.type==="String"&&se(e.caseInsensitive)?{problem:"a case-insensitive column comparison compiles to ILIKE"}:{key:a,ref:is({__field:{model:r,field:d}}),field:l,column:p,columnPath:d}},as=(e,t)=>new Error(`Path '${e}' compares to a column, which the Prisma rail supports only between columns of the same model and type: ${t}. Use toSql() or check().`),Kf=new WeakSet,ua=new WeakSet,Br=(e,t,r=false)=>(Kf.add(e),(r||t!==void 0&&ua.has(t))&&ua.add(e),e),Gf=e=>e!==void 0&&Kf.has(e),zf=e=>e!==void 0&&ua.has(e);var ca=e=>({field:e,operator:"notExists"}),TR=(e,t)=>{let r=t(e);if(r===null){let i=e.operator??e.dateOperator;return B.includes(i)?{field:e.field,operator:"exists"}:true}if("aggregate"in r){let i=O(Sn,r.operator);return i?{...r,operator:i}:{...r,operator:O(qi,r.operator)}}if(typeof r.dateOperator=="string"){let i=O(sf,r.dateOperator);return i?{...r,dateOperator:i}:Bt([{...r,dateOperator:O(qi,r.dateOperator)},ca(r.field)])}if(typeof r.arrayOperator=="string"){let i=r.count;switch(r.arrayOperator){case x.any:return {...r,arrayOperator:x.none};case x.none:return {...r,arrayOperator:x.any};case x.all:return {...r,arrayOperator:x.any,condition:Ue(r.condition,t)};case x.empty:return {...r,arrayOperator:x.notEmpty};case x.notEmpty:return {...r,arrayOperator:x.empty};case x.atLeast:return i<=0?false:{...r,arrayOperator:x.atMost,count:i-1};case x.atMost:return {...r,arrayOperator:x.atLeast,count:i+1};case x.exactly:return Bt([...i>0?[{...r,arrayOperator:x.atMost,count:i-1}]:[],{...r,arrayOperator:x.atLeast,count:i+1}])}}let o=O(Sn,r.operator);if(o)return {...r,operator:o};let n=typeof r.path=="string"&&r.path!==""?L(r.path)??{depth:1,path:r.path}:null;return Bt([{...r,operator:O(qi,r.operator)},ca(r.field),...n&&n.depth===1?[ca(n.path)]:[]])},Ue=(e,t=r=>r)=>{if(typeof e=="boolean")return !e;let r=e;if(Array.isArray(r.all))return Bt(r.all.map(o=>Ue(o,t)));if(Array.isArray(r.any))return z(r.any.map(o=>Ue(o,t)));if("if"in r){let o=z([r.if,Ue(r.then,t)]);return r.else===void 0?o:{any:[o,z([Ue(r.if,t),Ue(r.else,t)])]}}return TR(r,t)},Hf=e=>ne(e)==="field"&&e.value!==void 0&&be(e,e.value)?null:e;var Jf,Qf=e=>{Jf=e;},ae=(e,t,r)=>Jf(e,t,r);var kR=e=>{let t=L(e);throw t&&t.depth>1?new Error(un(e,"toPrisma")):new Error(`Path '${e}' compares to a column, which isn't supported on the Prisma rail; use toSql() or check().`)},tt=e=>xn(e,{value:t=>{if(ns(t))throw new Error("toPrisma: a value holding a '__step' or '__field' key is reserved for the plan's own references");return t},path:t=>kR(t),bind:(t,r)=>zi(t,r,"toPrisma")}),kn=e=>tt(e),Wo=e=>Dr({now:e?.now,timeZone:e?.timeZone,weekStart:e?.weekStart},kn),Uo=e=>t=>{let r=typeof t.operator=="string"||typeof t.dateOperator=="string",o=t.value!==void 0||typeof t.path=="string"&&t.path!==""||typeof t.bind=="string";if(!r||"aggregate"in t||!o||typeof t.operator=="string"&&typeof t.path=="string"&&t.path!=="")return t;let n=Ie({field:String(t.field)},e?.map,e?.model);if((n==="json"||n==="json-path")&&typeof t.operator=="string"&&$o.includes(t.operator))throw F("toPrisma",`The complement of '${t.operator}' on the Json value '${t.field}'`,"it keeps values of other types");let i=tt(t),s=t.offset===void 0?void 0:tt(t.offset);if(t.offset!==void 0&&s==null)return null;let{path:a,bind:l,bindOptional:d,...p}=t,f={...p,value:i,...t.offset!==void 0&&{offset:{value:s}}};return typeof t.dateOperator=="string"?i==null||be({operator:t.dateOperator},i)?null:f:Hf(f)};var rt=()=>({}),Wr=rt,Et=()=>({OR:[]}),ma=e=>Object.keys(e).length===0,Zf=e=>{let t=Object.keys(e);return t.length===1&&t[0]==="OR"&&Array.isArray(e.OR)&&e.OR.length===0},Ke=e=>{if(e.some(Zf))return Et();let t=e.filter(r=>!ma(r));return t.length===0?rt():t.length===1?t[0]:{AND:t}},W=e=>{if(e.some(ma))return rt();let t=e.filter(r=>!Zf(r));return t.length===0?Et():t.length===1?t[0]:{OR:t}},Ce=e=>ma(e)?e:{NOT:e},Yf=(e,t,r)=>Ke(e.all.map(o=>ae(o,t,r))),Xf=(e,t,r)=>W(e.any.map(o=>ae(o,t,r))),eu=(e,t,r)=>{if(xt(e,t?.map,t?.model))return Wr();let o=ae(Ue(e.if,Uo(t)),t,r),n=ae(e.then,t,r),i=W([o,n]);if(e.else!==void 0){let s=ae(e.if,t,r),a=ae(e.else,t,r);return Ke([i,W([s,a])])}return i};var CR=(e,t,r,o)=>{let n=T(e,t);if(!n)return null;for(let i of Object.values(n.fields))if(i.kind==="object"&&i.type===r&&(i.fromFields?.length??0)>0&&(i.toFields?.length??0)>0&&(o===void 0||i.relationName===o))return i;return null},hr=(e,t,r)=>{if(r.fromFields?.length)return r.fromFields.map((n,i)=>({here:n,there:r.toFields?.[i]??"id"}));let o=CR(e,r.type,t,r.relationName);return o?.fromFields?.length?o.fromFields.map((n,i)=>({here:o.toFields?.[i]??"id",there:n})):null},ls=(e,t,r,o)=>{if(o.relationName===void 0)return null;let n=Object.entries(T(e,o.type)?.fields??{}).filter(([i,s])=>s.kind==="object"&&s.type===t&&s.relationName===o.relationName&&!(o.type===t&&i===r));return n.length===1?{field:n[0][0],entry:n[0][1]}:null};var Ur=(e,t)=>{let r=e.split("."),o=t;for(let n=r.length-1;n>=0;n--)o={[r[n]]:o};return o};var Ko=(e,t,r,o)=>{let n=e.split("."),i=te(e,t,r);if(i.kind==="bridge")throw new Error(`'${e}' crosses a bridge: ${o.toLowerCase()} aren't supported across a bridge \u2014 no one database holds both sides.`);if(i.kind!=="direct"||i.entry.kind!=="object"){let l=i.hops.at(-1)?.entry.type??r;throw new Error(`Field '${n[i.hops.length]}' is not a relation in model '${l}'. ${o} require a relation field.`)}let s=i.hops.find(l=>l.entry.isList);if(s)throw new Error(`Intermediate field '${s.field}' in path '${e}' is a list relation. Only the final segment can be a list relation for ${o.toLowerCase()}.`);if(!i.entry.isList)throw new Error(`Field '${i.column}' is not a list relation in model '${i.model}'. ${o} only apply to one-to-many or many-to-many relations.`);let a=hr(t,i.model,i.entry);if(!a){let l=Object.values(T(t,i.entry.type)?.fields??{}).some(d=>d.kind==="object"&&d.type===i.model&&d.isList&&!d.fromFields?.length);throw new Error(l?`'${i.model}.${i.column}' is an implicit many-to-many relation. ${o} require an explicit join model with a FK \u2014 convert to an explicit @relation or use prisma.$queryRaw.`:`Cannot determine FK relationship between '${i.model}' and '${i.entry.type}'. Ensure the FieldMap contains both sides of the relation.`)}if(a.length>1)throw new Error(`${o} do not support composite FK relations ('${i.model}.${i.column}'). Use prisma.$queryRaw.`);return {through:i.hops.map(l=>l.field).join("."),target:i.entry.type,parentKey:a[0].here,targetKey:a[0].there}},ps=(e,t,r,o,n)=>{let i={operation:"groupBy",model:t.target,args:{by:[t.targetKey],where:r,having:o},extract:t.targetKey},s=is({__step:e.steps.length});e.steps.push(i);let a={[t.parentKey]:{in:s}},l=n?Ce(a):a;return t.through?Ur(t.through,l):l};var Sr=e=>({ok:e.length===0,errors:e}),Cn=(e,t)=>{if(!e.ok)throw new Error(`${t}:
|
|
2
2
|
${e.errors.map(r=>`${r.path}: ${r.message}`).join(`
|
|
3
|
-
`)}`)},zo=(e,t={})=>{let r={target:t.target??"check",errors:[],map:Pe(t.map,t.mapName,"toPrisma"),scopeModels:[t.model],stepScopes:[false]};return Gt(e,"$",r,1),t.positive&&MR(e,r),Sr(r.errors)},CR=["if","array","aggregate"],MR=(e,t)=>H(e,r=>{let o=ne(r),n=r.operator??r.dateOperator;return (o&&CR.includes(o)||typeof n=="string"&&_i.includes(n))&&P(t,"$","notPositive",`${o==="field"||o==="date"?n:o} can hold on a missing value`),false}),LR=(e,t={})=>{kn(zo(e,t),"validateRule");},Gt=(e,t,r,o)=>{if(typeof e=="boolean")return;if(!wr(e)){P(r,t,"invalid_condition","Condition must be a boolean or object");return}let n=ne(e);if(!n){P(r,t,"ambiguous_condition",wt().message);return}switch(n){case "all":tu(e.all,`${t}.all`,r,o);break;case "any":tu(e.any,`${t}.any`,r,o);break;case "if":Gt(e.if,`${t}.if`,r,o),Gt(e.then,`${t}.then`,r,o),"else"in e&&e.else!==void 0&&Gt(e.else,`${t}.else`,r,o);break;case "field":_R(e,t,r,o);break;case "aggregate":jR(e,t,r,o);break;case "array":IR(e,t,r,o);break;case "date":qR(e,t,r,o);break}},tu=(e,t,r,o)=>{if(!Array.isArray(e)){P(r,t,"logical_array_required","Logical operator requires an array of conditions");return}e.forEach((n,i)=>{Gt(n,`${t}[${i}]`,r,o);});},ds=(e,t,r,o)=>{typeof e.field=="string"&&nu(e.field,"field",`${t}.field`,r,o);},nu=(e,t,r,o,n,i=false)=>{let s=L(e)??(t==="path"?{depth:n}:null);if(!s)return;let a=t==="field"?"Field":"Path";s.depth>n&&P(o,r,"scope_out_of_bounds",Ks(e,s.depth,n)),o.target==="toPrisma"&&!i?P(o,r,`unsupported_prisma_${t}`,t==="path"?`Path '${e}' compares to a column, which isn't supported on the Prisma rail; use toSql() or check()`:`${a} '${e}' is not supported by toPrisma()`):o.target==="toSql"&&(t==="field"||s.depth>1)&&P(o,r,`unsupported_sql_${t}`,`${a} '${e}' is not supported by toSql()`);},ps=(e,t,r,o=false)=>{e.stepScopes[t]=o||e.stepScopes[t-1]===true;let n=e.scopeModels[t-1];e.scopeModels[t]=e.map&&n&&typeof r=="string"?An(r,e.map,n)??void 0:void 0;},Go=(e,t,r,o,n=false)=>{let i=pf.filter(a=>e[a]!==void 0);if(i.length>1)return P(r,t,"ambiguous_value_source","Takes one of value, path or bind"),null;if(i.length===0)return P(r,t,"missing_value_source","Requires value, path or bind"),null;let[s]=i;return s!=="value"&&(typeof e[s]!="string"||e[s]==="")?(P(r,`${t}.${s}`,"invalid_value_source",`${s} is a non-empty string`),null):(e.bindOptional!==void 0&&(s!=="bind"||typeof e.bindOptional!="boolean")&&P(r,`${t}.bindOptional`,"invalid_value_source","bindOptional is a boolean beside bind"),s==="path"&&nu(e.path,"path",`${t}.path`,r,o,n),s)},iu=(e,t,r,o,n,i)=>{let{offset:s}=e;if(s===void 0)return;let a=`${o}.offset`;if(!Ud.includes(r)){P(n,a,"unsupported_offset_operator",`Operator '${r}' has no comparison point to offset`);return}if(!wr(s)){P(n,a,"invalid_offset","An offset is one of { value }, { path } or { bind }");return}let l=Go(s,a,n,i);if(l==="path"){let f=s.path,u=kr(s);t==="date"&&u&&u.depth<=1&&n.target==="toSql"&&P(n,`${a}.path`,"unsupported_sql_path",`A row path on a date offset ('${f}') is not supported by toSql()`);return}if(l!=="value")return;let d=s.value;if(t==="field"){(typeof d!="number"||!Number.isFinite(d))&&P(n,`${a}.value`,"invalid_offset","A field offset value is a number");return}let p=wr(d)&&Object.keys(d).length===1&&Y(d)?we(d):null;if(!p){P(n,`${a}.value`,"invalid_offset","A date offset value is { ago } or { ahead }");return}lu(p[0],`${a}.value.${Object.keys(d)[0]}`,n,i);},su=(e,t,r,o)=>{o.target!=="toSql"||!Ve.includes(t)||kr(e)&&P(o,`${r}.path`,"unsupported_sql_path",`A range read from the row ('${e.path}') is not supported by toSql()`);},_R=(e,t,r,o)=>{if(typeof e.field!="string"&&P(r,`${t}.field`,"field_required","Field rule requires a string field"),ds(e,t,r,o),typeof e.operator!="string"||!jt(e.operator,"field")){P(r,`${t}.operator`,"invalid_operator",le(e.operator,"field").message);return}let n=e.operator;iu(e,"field",n,t,r,o),Ci(n,"field",r.target)||P(r,`${t}.operator`,`unsupported_${fs(r.target)}_operator`,`Operator '${n}' is not supported by ${r.target}()`),e.coerceType!==void 0&&!ki(e.coerceType)&&P(r,`${t}.coerceType`,"invalid_coerce_type",`coerceType must be one of: ${Object.keys(Q).join(", ")}`);let i=qt(n,"field");if(i==="none"){VR(e,t,r);return}if(Go(e,t,r,o,true)!==null){if(su(e,n,t,r),r.target==="toPrisma"&&typeof e.path=="string"){let s=is(e,r.map,r.scopeModels[o-1],o>1,r.stepScopes[o-1]===true);"problem"in s&&P(r,`${t}.path`,"unsupported_prisma_path",ss(e.path,s.problem).message);}if(r.target==="toSql"&&typeof e.path=="string"&&r.map){let s=r.scopeModels[o-1],a=(L(e.path)??{path:e.path}).path,l=Bo(X(e.field,r.map,s),X(a,r.map,s),n);l&&P(r,`${t}.path`,"unsupported_sql_path",`'${e.path}': ${l}`);}r.target==="toSql"&&typeof e.path=="string"&&["array","pattern","string"].includes(i)&&((r.map?X(e.field,r.map,r.scopeModels[o-1]):void 0)?.isList&>.includes(n)||P(r,`${t}.path`,"unsupported_sql_path",`'${n}' against the column '${e.path}' has no SQL form`)),!(typeof e.path=="string"||typeof e.bind=="string")&&(DR(e,n,t,r,o),FR(i,e.value,n,`${t}.value`,r));}},DR=(e,t,r,o,n)=>{if(o.target!=="toPrisma"||!o.map||typeof e.field!="string")return;let i=X(e.field,o.map,o.scopeModels[n-1]);if(!i)return;let s=e.value,a=se(e.caseInsensitive),l=ir.includes(t)&&Array.isArray(s),d=p=>P(o,`${r}.value`,"unsupported_prisma_operator",F("toPrisma",p).message);i.isList&&!l&&Array.isArray(s)&&s.includes(null)?d(`A list holding null in '${e.field}'`):i.isList&&!l&&a&&yr("text",s)?d(`A case-insensitive comparison on the list '${e.field}'`):je(i)&&a&&d(`A case-insensitive comparison on the Json column '${e.field}'`);},FR=(e,t,r,o,n)=>{switch(e){case "scalar":case "string":e==="string"&&typeof t!="string"&&P(n,o,"invalid_string_value",`Operator '${r}' requires a string value`);return;case "ordered":ce(t)||P(n,o,"invalid_ordered_value",`Operator '${r}' requires a string, number, or Date value`);return;case "array":Array.isArray(t)||P(n,o,"invalid_membership_value",`Operator '${r}' requires an array value`);return;case "pattern":{if(!(typeof t=="string"||t instanceof RegExp)){P(n,o,"invalid_pattern_value",`Operator '${r}' requires a string or RegExp value`);return}let i=Ef(t,n.target);i&&P(n,o,"unsupported_pattern",i);return}case "range":try{Fo(t,r);}catch(i){P(n,o,"invalid_range_value",i.message);}return}},au=(e,t,r,o,n)=>{let i=r.scopeModels[o-1];if(!(r.target!=="toPrisma"||!r.map||!i||typeof e.field!="string"))try{Ko(e.field,r.map,i,n);}catch(s){P(r,`${t}.field`,"unsupported_prisma_relation",s.message);}},jR=(e,t,r,o)=>{if(au(e,t,r,o,"Aggregate rules"),e.offset!==void 0&&P(r,`${t}.offset`,"unexpected_offset","Aggregate rules take no offset"),pu(e,t,r,o),typeof e.field!="string"&&P(r,`${t}.field`,"field_required","Aggregate rule requires a string field"),ds(e,t,r,o),!wr(e.aggregate)){P(r,`${t}.aggregate`,"invalid_aggregate","aggregate must be an object");return}let n=e.aggregate;if(yt.includes(n.mode)||P(r,`${t}.aggregate.mode`,"invalid_aggregate_mode",ar(n.mode).message),"field"in n&&n.field!==void 0&&typeof n.field!="string"&&P(r,`${t}.aggregate.field`,"invalid_aggregate_field","aggregate.field must be a string"),!Mi.includes(e.operator)){P(r,`${t}.operator`,"invalid_aggregate_operator",`Aggregate rules only support: ${Mi.join(", ")}`);return}if(r.target==="toPrisma"&&typeof e.path=="string"&&P(r,`${t}.path`,"unsupported_prisma_aggregate_path","path is not supported by toPrisma() for aggregate rules; use value instead"),"condition"in e&&e.condition!==void 0&&(r.target==="toSql"&&P(r,`${t}.condition`,"unsupported_sql_aggregate_condition","Aggregate condition filtering is not supported by toSql(); use check() or toPrisma()"),ps(r,o,e.field,true),Gt(e.condition,`${t}.condition`,r,o+1)),Go(e,t,r,o)===null||typeof e.path=="string"||typeof e.bind=="string")return;let i=e.value;Ve.includes(e.operator)?BR(i)||P(r,`${t}.value`,"invalid_range_value",`Operator '${e.operator}' requires a two-item numeric range`):typeof i!="number"&&P(r,`${t}.value`,"invalid_aggregate_value","Aggregate rule value must be a number");},IR=(e,t,r,o)=>{if(typeof e.field!="string"&&r.target!=="check"&&P(r,`${t}.field`,"field_required","Array rule requires a string field for this target"),ds(e,t,r,o),pu(e,t,r,o),typeof e.arrayOperator!="string"||!jt(e.arrayOperator,"array")){P(r,`${t}.arrayOperator`,"invalid_array_operator",le(e.arrayOperator,"array").message);return}let n=e.arrayOperator;hn(e)&&au(e,t,r,o,"Count operators");let i=r.target==="toPrisma"&&r.map&&typeof e.field=="string"?X(e.field,r.map,r.scopeModels[o-1]):void 0;i&&!V(i)&&n!=="empty"&&n!=="notEmpty"&&P(r,`${t}.arrayOperator`,"unsupported_prisma_array_operator",F("toPrisma",`'${n}' over the array column '${e.field}'`).message),Ci(n,"array",r.target)||P(r,`${t}.arrayOperator`,`unsupported_${fs(r.target)}_array_operator`,`Array operator '${n}' is not supported by ${r.target}()`);let s=qt(n,"array"),a=e.condition!==void 0,l=()=>{e.count!==void 0&&P(r,`${t}.count`,"unexpected_count",`Array operator '${n}' does not accept count`);};s==="none"?(a&&P(r,`${t}.condition`,"unexpected_condition",`Array operator '${n}' does not accept condition`),l()):s==="predicate"?(a?(ps(r,o,e.field),Gt(e.condition,`${t}.condition`,r,o+1)):P(r,`${t}.condition`,"missing_condition",De(n).message),l()):s==="count"&&(typeof e.count!="number"?P(r,`${t}.count`,"missing_count",Ao(n).message):e.count!==void 0&&!(typeof e.count=="number"&&Number.isInteger(e.count)&&e.count>=0)&&P(r,`${t}.count`,"invalid_count","count must be a non-negative whole number"),a?(ps(r,o,e.field,hn(e)),Gt(e.condition,`${t}.condition`,r,o+1)):P(r,`${t}.condition`,"missing_condition",De(n).message));},qR=(e,t,r,o)=>{if(typeof e.field!="string"&&P(r,`${t}.field`,"field_required","Date rule requires a string field"),ds(e,t,r,o),typeof e.dateOperator!="string"||!jt(e.dateOperator,"date")){P(r,`${t}.dateOperator`,"invalid_date_operator",le(e.dateOperator,"date").message);return}let n=e.dateOperator;iu(e,"date",n,t,r,o);let i=Wt(e.value,la(e.offset));i&&P(r,t,"clock_unit_below_floor",i.message),Ci(n,"date",r.target)||P(r,`${t}.dateOperator`,`unsupported_${fs(r.target)}_date_operator`,`Date operator '${n}' is not supported by ${r.target}()`);let s=qt(n,"date");if(s==="dayList"){if(Go(e,t,r,o)!=="value")return;let a=e.value;(!Array.isArray(a)||!a.every(l=>typeof l=="string"&&of(l)))&&P(r,`${t}.value`,"invalid_day_list",`Date operator '${n}' requires an array of day names (${No.join(", ")})`);return}if(Go(e,t,r,o)!==null&&(su(e,n,t,r),!(typeof e.path=="string"||typeof e.bind=="string"))){if(Y(e.value)){ou(e.value,n,`${t}.value`,r,o);return}if(gn.includes(n)){P(r,`${t}.value`,"invalid_date_range",Qe(n).message);return}if(s==="dateRange"){if(!WR(e.value)){P(r,`${t}.value`,"invalid_date_range",`Date operator '${n}' requires a two-item date range`);return}e.value.forEach((a,l)=>{Y(a)?ou(a,n,`${t}.value[${l}]`,r,o):ce(a)&&!fr(a,Ze).isValid()&&P(r,`${t}.value[${l}]`,"invalid_date_value",`Date operator '${n}' value '${String(a)}' does not parse as a date`);});return}if(!ce(e.value)){P(r,`${t}.value`,"invalid_date_value",`Date operator '${n}' requires a date-like value`);return}fr(e.value,Ze).isValid()||P(r,`${t}.value`,"invalid_date_value",`Date operator '${n}' value '${String(e.value)}' does not parse as a date`);}},lu=(e,t,r,o)=>{if(!wr(e)||Object.keys(e).length===0){P(r,t,"invalid_relative_units","Relative offset requires at least one unit");return}for(let[n,i]of Object.entries(e)){if(!vo(n)){P(r,`${t}.${n}`,"invalid_relative_unit",`Unknown relative unit '${n}'`);continue}let s=wr(i)?Go(i,`${t}.${n}`,r,o):"literal";if(s===null||s==="path"||s==="bind")continue;let a=s==="value"?i.value:i,l=sa(a,n);l&&P(r,`${t}.${n}`,"invalid_relative_magnitude",l);}},ru=(e,t,r)=>{(typeof e!="string"||!ji.includes(e))&&P(r,t,"invalid_period_unit",`Unknown period unit '${String(e)}'`);},ou=(e,t,r,o,n)=>{let i=gn.includes(t),s=we(e);if(s){lu(s[0],r,o,n);return}if(Rn(e)){ru(Co(e),r,o);return}if(On(e)){if(i){P(o,r,"invalid_date_range",Qe(t).message);return}let a="start"in e?e.start:e.end;if(!wr(a)||!Rn(a)){P(o,r,"invalid_period_unit","start/end requires a this/last/next period");return}ru(Co(a),r,o);return}P(o,r,"invalid_date_expression","Unrecognized date expression");},VR=(e,t,r)=>{"value"in e&&e.value!==void 0&&P(r,`${t}.value`,"unexpected_value","Rule does not accept value"),"path"in e&&e.path!==void 0&&P(r,`${t}.path`,"unexpected_path","Rule does not accept path"),"bind"in e&&e.bind!==void 0&&P(r,`${t}.bind`,"unexpected_bind","Rule does not accept bind");},fs=e=>e==="toPrisma"?"prisma":e==="toSql"?"sql":"check",wr=e=>fe(e),BR=e=>Array.isArray(e)&&e.length===2&&typeof e[0]=="number"&&typeof e[1]=="number",WR=e=>Array.isArray(e)&&e.length===2&&(ce(e[0])||Y(e[0]))&&(ce(e[1])||Y(e[1])),pu=(e,t,r,o)=>{if(Ee(e)&&r.target!=="check"&&(r.target==="toPrisma"&&Vo(e)!==null||P(r,t,`unsupported_${fs(r.target)}_window`,St(r.target).message)),"filter"in e&&e.filter!==void 0&&(ps(r,o,e.field),Gt(e.filter,`${t}.filter`,r,o+1)),"orderBy"in e&&e.orderBy!==void 0){let i=e.orderBy;Array.isArray(i)?i.forEach((s,a)=>{(!wr(s)||typeof s.field!="string"||s.dir!=="asc"&&s.dir!=="desc")&&P(r,`${t}.orderBy[${a}]`,"invalid_order_by",'orderBy entries must be { field: string, dir: "asc" | "desc" }');}):P(r,`${t}.orderBy`,"invalid_order_by","orderBy must be an array of { field, dir }");}for(let i of ["take","skip"])if(i in e&&e[i]!==void 0){let s=e[i];(typeof s!="number"||!Number.isInteger(s)||s<0)&&P(r,`${t}.${i}`,`invalid_window_${i}`,`${i} must be a non-negative integer`);}},P=(e,t,r,o)=>{e.errors.push({path:t,code:r,message:o});};var UR=/[.:]/,ga=e=>{let t=[];for(let[r,o]of Object.entries(e.maps))for(let[n,i]of Object.entries(o.models))for(let[s,a]of Object.entries(i.fields))a.kind!=="bridge"&&UR.test(s)&&t.push({path:`${ke({fieldMap:r,model:n})}.${s}`,message:"contains forbidden character . or :",code:"invalid_field_name"});return Sr(t)},du=e=>kn(ga(e),"validateFieldMaps");var ot=e=>!Object.hasOwn(e,"parent"),$t=e=>{let t=[],r=new Set,o=e;for(;!ot(o);){if(r.has(o))throw new Error("cycle detected in narrowing parent chain");if(Object.hasOwn(o,"model")||Object.hasOwn(o,"maps"))throw new Error("a narrowing carries a base lens key (model / maps); it has a parent instead");r.add(o),t.unshift(o),o=o.parent;}return t},nt=e=>ot(e)?e:$t(e)[0].parent;var ya=(e,t)=>t.length?G([...t,e]):e,KR=e=>{if(dr(e).length)return false;let t=e.field,r=typeof t=="string"?L(t):null;try{return me(r?{...e,field:r.path}:e,{})===!0}catch{return false}},ha=(e,t)=>{if(!t.length)return e;if(!KR(e))return G([...t.flatMap(n=>n.clamps),e]);let[r,...o]=t;return Bt([G([...r.clamps,ha(e,o)]),G([{field:r.prefix,operator:"notExists"},e])])},Jo=(e,t,{paths:r=false}={})=>pr(e,{rewrite:o=>{if(Fe(o))return o;if(typeof o.field!="string"||o.field==="")throw new A(`narrowRule: cannot re-root a relation clamp of unknown shape under '${t}'`,"unsupported_clamp");let n=dr(o),i=n.find(a=>L(a));if(r&&i)throw new A(`prefixConditionFields: cannot re-root a scope ref ('${i}') under '${t}'`,"unsupported_clamp");if(n.length&&!r)throw new A(`narrowRule: cannot re-root a relation clamp with a path reference ('${n[0]}') under '${t}'. Author the clamp without 'path', or anchor it at the relation itself.`,"unsupported_clamp");if(L(o.field))throw new A(`narrowRule: cannot re-root a relation clamp with a scope ref field ('${o.field}') under '${t}'. Author the clamp against the model's own columns.`,"unsupported_clamp");if(Te(o)){for(let a of [o.condition,o.filter])if(a!==void 0&&Ho(a).escaping!==null)throw new A(`narrowRule: cannot re-root a relation clamp on '${o.field}' under '${t}': '${Ho(a).escaping}' inside it reads the row being re-rooted. Anchor such clamps at the relation's own model.`,"unsupported_clamp")}return {...r?_o(o,a=>xe(a)?{...a,path:`${t}.${a.path}`}:a):o,field:`${t}.${o.field}`}},below:()=>false}),wa=(e,t)=>t.flatMap(r=>{let o=D(e,r.map,r.model,r.relPath);if(o.whereClauses.length===0)return [];if(r.isList)throw new A(`narrowRule: cannot enforce a to-many relation clamp on '${r.prefix}' without an arrayOperator condition to anchor it (row-scoped). Traverse '${r.prefix}' via an array operator (any/all/none/...) so the clamp can be injected safely.`,"unsupported_clamp");return [{prefix:r.prefix,clamps:o.whereClauses.map(n=>Jo(n,r.prefix))}]}),fu=(e,t)=>wa(e,t).flatMap(r=>r.clamps),cu=(e,t,r)=>{let o=qe(e,r);if("outOfBounds"in o)throw new A(`narrowRule: ${o.outOfBounds}`,"scope_out_of_bounds");if(!o.scope)return {hops:[],end:null};let n=e.slice(0,e.length-o.path.length);return ve(t.lens.maps,o.scope,o.path,n==="$."?"":n)},GR=(e,t,r)=>{if(L(e))return cu(e,t,r).hops;let o=r.length===1?"":`${"$".repeat(r.length)}.`;return r[0]?ve(t.lens.maps,r[0],e,o).hops:[]},uu=(e,t,r)=>{if(Fe(e)||typeof e.field!="string"||e.field==="")return null;let{hops:o,end:n}=cu(e.field,t,r);return {hops:o,below:n}},Kr=(e,t,r)=>pr(e,{below:(o,n)=>{let i=uu(o,t,n);return i?i.below?[...n,i.below]:Te(o)?[...n,null]:false:false},after:(o,n)=>{let i=uu(o,t,n);if(!i)return o;let s=fu(t,dr(o).flatMap(f=>GR(f,t,n))),a=i.below;if(!a||!Te(o))return ya(ha(o,wa(t,i.hops)),s);let l=[...D(t,a.mapName,a.modelName,a.relPath).whereClauses,...fu(t,Do(o).flatMap(f=>ve(t.lens.maps,a,f).hops))],d=o.condition===void 0||o.arrayOperator===x.all||Ee(o),p={...o};return l.length&&d?p.filter=G([...o.filter!==void 0?[o.filter]:[],...l]):l.length&&(p.condition=G([...l,o.condition])),ya(ha(p,wa(t,i.hops.slice(0,-1))),s)}},[r]),Qo=(e,t)=>{let r=M(t),o=D(r,r.lens.mapName,r.lens.model,[]),n=Kr(e,r,{mapName:r.lens.mapName,modelName:r.lens.model,relPath:[]});return ya(n,o.whereClauses)};var Sa=(e,t)=>{let r=Fr(e,Q.DateTime,t);return typeof r=="number"&&!Number.isNaN(new Date(r).getTime())?r:void 0},zR=(e,t,r)=>o=>{if(o==null)return o;let n=Sa(o,r);if(n===void 0)throw new Error(`Invalid date value for DateTime field '${e}': ${String(o)}`);return t==="toPrisma"?new Date(n):new Date(n).toISOString()},Zo=(e,t,r,o,n)=>{if(t==null||r?.kind==="json-path")return t;let i=r?.kind==="direct"?r.entry:void 0;if(i?.isList)return t;let s=i?et(i):void 0;if(e.coerceType!==void 0&&s!==void 0&&e.coerceType!==s)throw new Error(`coerceType '${e.coerceType}' overrides ${s} field '${e.field}', but ${o} compares the column as stored \u2014 evaluate it in memory with check(), or drop the override.`);if((s??e.coerceType)===Q.DateTime){let l=zR(e.field,o,n());return Array.isArray(t)?t.map(l):l(t)}if(e.coerceType===void 0&&s===Q.String&&(Array.isArray(t)?t:[t]).some(l=>typeof l=="number"||typeof l=="boolean"))throw new Error(`'${e.field}' is String but the literal is not a string; pass a string, or stamp coerceType: 'String'.`);if(e.coerceType===void 0&&s!==void 0&&(He.includes(s)||s===Q.Boolean)&&(Array.isArray(t)?t:[t]).some(l=>typeof l=="string"))throw new Error(`'${e.field}' is ${s} but the literal is a string; pass a ${s===Q.Boolean?"boolean":"number"}, or stamp coerceType: '${s}'.`);return e.coerceType!==void 0&&Xd.includes(e.coerceType)?Fr(t,e.coerceType,e.coerceType===Q.DateTime?n():void 0):t};var mu=e=>Array.isArray(e)?e.flatMap(mu):[e],Cn=e=>e.value===void 0?null:mu(e.value),HR=e=>Sa(e)!==void 0,JR=/^-?\d+(\.\d+)?$/,QR={String:{expected:"a string",fits:e=>typeof e=="string"},Enum:{expected:"a string",fits:e=>typeof e=="string"},Int:{expected:"an integer",fits:Number.isSafeInteger},BigInt:{expected:"an integer",fits:Number.isSafeInteger},Float:{expected:"a number",fits:Number.isFinite},Decimal:{expected:"a number or a numeric string",fits:e=>Number.isFinite(e)||typeof e=="string"&&JR.test(e)},Boolean:{expected:"a boolean",fits:e=>typeof e=="boolean"},DateTime:{expected:"a date",fits:HR},Json:{expected:"a value",fits:()=>true},Bytes:{expected:"a value",fits:()=>true}},ZR=e=>typeof e=="string"?`'${e}'`:typeof e=="object"&&e!==null?JSON.stringify(e):String(e),us=(e,t)=>{let r="coerceType"in e?e.coerceType:void 0,o=r??t;if(o===void 0||o===Q.Json)return [];let n="operator"in e?e.operator:e.dateOperator,i=Eo(e);if(!i)return [];let a=r!==void 0&&r!==t?`field '${e.field}' coerced to ${o}`:`${o} field '${e.field}'`;if(!i.kinds.includes(o))return [{path:e.field,code:"operator_kind_mismatch",message:`operator '${n}' does not apply to ${a} (applies to: ${i.kinds.join(", ")})`}];if(e.offset!==void 0&&!("dateOperator"in e?o===Q.DateTime:He.includes(o)))return [{path:e.field,code:"invalid_offset",message:`an offset does not apply to ${a}`}];if("dateOperator"in e||i.valueShape==="none"||i.valueShape==="pattern")return [];if(ef.includes(i.valueShape)&&Array.isArray(e.value))return [{path:e.field,code:"invalid_value_shape",message:`operator '${n}' compares one value, but ${a} was given a list`}];let{expected:l,fits:d}=QR[o],p=u=>{try{return d(Fr(u,o))}catch{return false}},f=u=>d(u)||r!==void 0&&p(u);return (Cn(e)??[]).filter(u=>u!==null&&!f(u)).map(u=>({path:e.field,code:"invalid_value",message:`value ${ZR(u)} does not fit ${a} (expected ${l})`}))},gu=(e,t,r)=>{if(r.isList===true||je(r))return null;let o=V(r)?`arrayOperator '${t}' needs a list, but '${e}' is a to-one relation \u2014 a single related record; address its fields directly (e.g. '${e}.<field>')`:`arrayOperator '${t}' needs a list, but '${e}' is a single ${et(r)??r.type} value`;return {path:e,code:"invalid_array_operator",message:o}};var YR=(e,t,r,o)=>H(e,(n,i)=>{let s=ne(n);if(s===null)return o.push({path:typeof n.field=="string"?n.field:"",code:"ambiguous_condition",message:wt().message}),false;if(Fe(n))return;let a=n,l=w=>{let R=qe(w,i);return "outOfBounds"in R?(o.push({path:w,code:"scope_out_of_bounds",message:R.outOfBounds}),null):{scope:R.scope,field:R.path}},d=i[i.length-1],p=true,f=null;if("field"in a&&typeof a.field=="string"&&a.field!==""){let w=en(t,i,a.field);"issue"in w?(o.push({path:a.field,...w.issue}),p=false):{next:d,walked:f}=w;}let u=f?.entry??null,m=f?.terminalFieldName??null,y=f?.entry.kind==="enum",c=f?.entry.type??null,g=f&&f.jsonSubPath.length===0?ms(f.terminalEffect,f.terminalFieldName):null;for(let{ref:w,role:R}of ra(a)){let S=L(w)?l(w):{scope:Pt(t),field:w};if(!S||S.scope.open)continue;let b=Yo(t,S.scope,S.field);if(!b){o.push({path:w,...cs(t,S.scope,S.field,R==="value"?"path (comparison ref) does not resolve through the narrowed lens":"offset or magnitude ref does not resolve through the narrowed lens")});continue}if(V(b.entry)){o.push({path:w,code:"not_in_lens",message:"a value ref reads a column, not a relation"});continue}let $=et(b.entry);if(R==="value"||R==="shift"||$===void 0)continue;(R==="whole"?Zd.includes($):He.includes($))||o.push({path:w,code:"not_in_lens",message:`${R==="whole"?"a calendar unit reads a whole number":"an offset or magnitude reads a number"}, not ${$}`});}if(!p)return false;if("arrayOperator"in a&&typeof a.field=="string"&&u){let w=gu(a.field,a.arrayOperator,u);if(w)return o.push(w),false}if(u&&V(u)&&(s==="field"||s==="date")&&(u.isList||!Ut(a))){let w=a.field;return o.push({path:w,code:"operator_kind_mismatch",message:(u.isList?Vi(w):sr(w)).message}),false}if(!u?.isList&&(s==="field"||s==="date")&&o.push(...us(a,u?et(u):void 0)),!d.open)for(let w of Do(a))w!==""&&!Yo(t,d,w)&&o.push({path:w,...cs(t,d,w,"an orderBy or aggregate field does not resolve through the narrowed lens")});if(g&&"operator"in a&&m){let w=Cn(a);if(w){let R=new Set(g),S=y?`enum '${c}'`:`field '${m}'`;for(let b of w)typeof b=="string"&&!R.has(b)&&o.push({path:m,code:"value_not_allowed",message:`value '${b}' is not in the allowed set for ${S} (allowed: ${[...R].join(", ")})`});}}return [...i,d]},[r]),Mn=(e,t,r,o,n)=>{let i=[];return YR(e,t,{mapName:r,modelName:o,relPath:n,open:false},i),i},Xo=(e,t)=>{let r=M(t);try{let o=Mn(e,r,r.lens.mapName,r.lens.model,[]);return o.length===0&&Qo(e,t),Sr(o)}catch(o){if(!(o instanceof A))throw o;return Sr([{path:"",code:o.code,message:o.message}])}};var Dn=e=>e===void 0?void 0:Array.isArray(e)?e:[e],Fn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&("where"in e||"label"in e||"groupBy"in e||"from"in e),br=e=>{if(Fn(e))return e;if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===0)throw XR();return {where:e}},XR=()=>new A("sources: {} is not a Condition \u2014 use `true` for an unconstrained source","invalid_source"),Oa=["__offpath__"],yu=new WeakMap,eO=(e,t)=>{if(!t)return new Map;let r=JSON.stringify([Ln(t.parent),Ln(e.maps),e.mapName,e.model,t.mapDefaults??null]),o=yu.get(t);if(o?.fingerprint===r)return o.trees;let n=new Map;return yu.set(t,{fingerprint:r,trees:n}),n},hu=new WeakMap,tO=0,Ln=e=>{let t=hu.get(e);return t===void 0&&(t=tO++,hu.set(e,t)),t},ge="\0",rO=e=>{let t=Object.entries(e.fields);return {relations:new Set(t.filter(([,r])=>V(r)).map(([r])=>r)),gated:t.filter(([,r])=>r.options!==void 0||r.kind==="enum"||r.values!==void 0)}},gs=e=>e?String(Ln(e)):"",M=e=>{let t=nt(e),r=ot(e)?[]:$t(e);return {lens:t,chain:r,origin:r[0],memo:{trees:eO(t,r[0]),vetted:new Set,effects:new Map,places:new Map,models:new Map,refs:new Map,compiles:new Map}}},ys=(e,t)=>e===null?new Set(t):new Set(t.filter(r=>e.has(r))),oO=(e,t)=>{if(t.picks&&(e.picks=ys(e.picks,t.picks)),t.omits)for(let r of t.omits)e.omits.add(r);},bu=(e,t,r)=>{e.set(t,ys(e.get(t)??null,r));},Ru=(e,t,r)=>{let o=e.get(t)??new Set;for(let n of r)o.add(n);e.set(t,o);},nO=(e,t,r)=>{if(r.enumPicks)for(let[o,n]of Object.entries(r.enumPicks))bu(e,o,n);if(r.enumOmits)for(let[o,n]of Object.entries(r.enumOmits))Ru(t,o,n);},ba=(e,t,r)=>JSON.stringify([e,t,r]),iO=(e,t,r,o,n,i,s,a)=>{if(s&&oO(e,t),t.where!==void 0&&i&&(n(t.where),e.whereClauses.push(r(t.where)),(a?e.modelWheres:e.pathWheres).push({where:t.where,layer:o})),t.sources)for(let[l,d]of Object.entries(t.sources)){let p=br(d),f=e.sources.get(l)??[],u=e.sourceWheres.get(l)??[];p.where!==void 0&&i&&(n(p.where,true),f.push(r(p.where)),u.push(p.where)),e.sources.set(l,f),e.sourceWheres.set(l,u);let m=Dn(p.groupBy);for(let[y,c,g]of [["label",p.label,e.sourceLabels.get(l)],["groupBy",m,e.sourceGroupBys.get(l)]]){if(c===void 0)continue;let w=ba(l,y,c);g!==void 0&&ba(l,y,g)===w||e.sourceDeclaredAt.set(w,o);}p.label!==void 0&&e.sourceLabels.set(l,p.label),m!==void 0&&e.sourceGroupBys.set(l,m),p.from==="mapDefaults"&&!e.sourcesFromMapDefaults.has(l)&&e.sourcesFromMapDefaults.set(l,o);}},A=class extends Error{constructor(r,o){super(r);this.code=o;}code;name="LensRefusal"},xa=e=>new A(`a bare path ('${e}') reads the root row, which a clamp at a relation visit or a model default doesn't stand on: use a literal, a bind, or a \`$\` scope ref`,"invalid_value_source"),sO=(e,t,r)=>Mn(e,t,r.mapName,r.modelName,r.relPath),aO=e=>new A(`a later layer's clamp reads what its parent does not show: '${e.path}' ${e.message}`,e.code),Ea=e=>new A(`the scope ref '${e}' climbs out of the clamp: a clamp reads its own row ('$.'), literals and binds`,"scope_out_of_bounds"),Ho=e=>{let t=null,r=null;return H(e,(o,n)=>{if(Fe(o))return;let i=dr(o);for(let s of [...typeof o.field=="string"?[o.field]:[],...i]){let a=L(s);r===null&&a&&a.depth>n&&(r=s);}for(let s of i)t===null&&!L(s)&&(t=s);return Te(o)?n+1:void 0},1),{bare:t,escaping:r}},Ra=(e,t)=>{let r={mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]},o=[r];if(t.relPath.length>0)for(let i of ve(e.lens.maps,r,t.relPath.join(".")).hops)o.push({mapName:i.map,modelName:i.model,relPath:i.relPath});let n=o[o.length-1];return o.length===t.relPath.length+1&&n.mapName===t.mapName&&n.modelName===t.modelName?o:null},_n=(e,t)=>{let r=e;for(let o of t)r=O(r?.relations,o);return r},$a=(e,t,r)=>{let o=i=>O(O(e.mapDefaults,i.mapName)?.models,i.modelName);if(!r){let i=o(t);return {defaults:i?[i]:[],path:void 0}}let n=[];for(let[i,s]of r.entries()){let a=_n(o(s),t.relPath.slice(i));a&&n.push(a);}return {defaults:n,path:_n(e.root,t.relPath)}},lO=(e,t,r,o)=>{let n=_n(t.root,r.relPath),i=[r.relPath.join(ge),Object.keys(n?.relations??{}).join(ge),(n?.omits??[]).join(ge)].join(`${ge}${ge}`),s=o.get(i);if(s)return s;let a=new Map,l={lens:e},d=Ra(l,r)??[r],p=new Set(d.map(u=>`${u.mapName}:${u.modelName}`)),f=[{at:r,below:[]}];for(;f.length>0;){let{at:u,below:m}=f.shift(),y=T(O(e.maps,u.mapName),u.modelName)?.fields??{},{defaults:c,path:g}=$a(t,u,Ra(l,u)),w=new Set(c.flatMap(b=>Object.keys(b.relations??{}))),R=new Set([...c,...g?[g]:[]].flatMap(b=>b.omits??[])),S=[];for(let[b,$]of Object.entries(y)){if(!w.has(b)||R.has(b)||g?.relations!==void 0&&Object.hasOwn(g.relations,b))continue;let E=Xe($,u.mapName);if(!E||!T(O(e.maps,E.mapName),E.modelName))continue;let I=`${E.mapName}:${E.modelName}`;p.has(I)||(p.add(I),S.push(b),f.push({at:{...E,relPath:[...u.relPath,b]},below:[...m,b]}));}a.set(m.join("."),S);}return o.set(i,a),a},pO=(e,t,r,o)=>{if(!o)return $a(t,r,null).defaults.flatMap(d=>Object.keys(d.relations??{}));let n=r.relPath.length;for(;n>0&&_n(t.root,r.relPath.slice(0,n))===void 0;)n--;let i={...o[n],relPath:r.relPath.slice(0,n)},a=lO(e.lens,t,i,e.memo?.trees??new Map).get(r.relPath.slice(n).join("."))??[];return [...n===r.relPath.length?Object.keys(_n(t.root,r.relPath)?.relations??{}):[],...a]},jn=(e,t,r)=>{let o=t;for(let n of ve(e.lens.maps,t,r).hops){let i=n.relPath[n.relPath.length-1];if(!D(e,o.mapName,o.modelName,o.relPath).relations.has(i))return n.prefix;o={mapName:n.map,modelName:n.model,relPath:n.relPath};}return null},D=(e,t,r,o)=>{let n=e.memo?wu(e,t,r,o):null,i=n===null?void 0:e.memo?.effects.get(n);if(i){if(!e.unvetted&&i.unchecked){for(let j of i.unchecked)j();i.unchecked=null;}return i.effect}let s=[],a={picks:null,omits:new Set,enumValuesByField:new Map,whereClauses:[],pathWheres:[],modelWheres:[],sources:new Map,sourceWheres:new Map,sourceLabels:new Map,sourceGroupBys:new Map,sourceDeclaredAt:new Map,sourcesFromMapDefaults:new Map,relations:new Set,relationFields:new Set},l=O(e.lens.maps,t),d=T(l,r);if(!d)return a;let p=e.memo?.models.get(d);p||(p=rO(d),e.memo?.models.set(d,p)),a.relationFields=p.relations;let f={mapName:t,modelName:r,relPath:o},u=e.origin??e.chain[0],m=`${gs(u)}${ge}${t}${ge}${r}${ge}${o.join(ge)}`,y=e.memo?.places.get(m);if(!y){let j=Ra(e,f);y={trail:j,turnedOn:u?pO(e,u,f,j):[]},e.memo?.places.set(m,y);}let{trail:c}=y,g=new Map,w=new Map,R=new Map,S=new Map,b=j=>j,$=0,E=()=>{},I=true,pe=true,N=(j,q=false)=>{iO(a,j,b,$,E,I,pe,q),nO(g,w,j);};for(let[j,q]of e.chain.entries()){$=j;let Er={...e,clamp:false,skipClampsOf:void 0,skipHidingOf:void 0,chain:e.chain.slice(0,j)};I=q!==e.skipClampsOf,pe=q!==e.skipHidingOf,b=ee=>j===0?ee:Kr(ee,Er,{mapName:t,modelName:r,relPath:o});for(let[ee,ye]of Object.entries(O(q.mapDefaults,t)?.enums??{}))ye.picks&&bu(R,ee,ye.picks),ye.omits&&Ru(S,ee,ye.omits);let{defaults:nn,path:$r}=$a(q,f,c),de=j===0?null:Er,at=ee=>(ye,he=false)=>{let Ne=e.memo?.refs.get(ye);if(Ne||(Ne=Ho(ye),e.memo?.refs.set(ye,Ne)),Ne.bare!==null&&!(ee&&!he))throw xa(Ne.bare);if(Ne.escaping!==null)throw Ea(Ne.escaping);if(!de)return;let sl=()=>{let Hn=typeof ye=="object"&&ye!==null?`${Ln(ye)}${ge}${wu(de,t,r,o)}`:null;if(Hn!==null&&de.memo?.vetted.has(Hn))return;let[al]=sO(ye,de,f);if(al)throw aO(al);Hn!==null&&de.memo?.vetted.add(Hn);};e.unvetted?s.push(sl):sl();};E=at(false);let Jr=O(O(q.mapDefaults,t)?.models,r);for(let ee of nn)N(ee,ee===Jr);$r&&(E=at(o.length===0&&c!==null),N($r));}if(u&&e.chain.includes(u))for(let j of y.turnedOn)a.relationFields.has(j)&&!a.omits.has(j)&&a.relations.add(j);for(let[j,q]of p.gated){let Er=q.kind==="enum",$r=q.options?.map(ee=>ee.value)??(Er?Ir(q,l?.enums):q.values);if(!$r)continue;let de=$r;if(Er){let ee=R.get(q.type),ye=S.get(q.type);ee&&(de=de.filter(he=>ee.has(he))),ye&&(de=de.filter(he=>!ye.has(he)));}let at=g.get(j),Jr=w.get(j);at&&(de=de.filter(ee=>at.has(ee))),Jr&&(de=de.filter(ee=>!Jr.has(ee))),a.enumValuesByField.set(j,de);}return n!==null&&e.memo?.effects.set(n,{effect:a,unchecked:s.length?s:null}),a},wu=(e,t,r,o)=>{let n=Su.get(e);if(n===void 0){n=`${gs(e.origin)}${ge}${gs(e.skipClampsOf)}${ge}${gs(e.skipHidingOf)}${ge}`;for(let i of e.chain)n+=`${Ln(i)},`;Su.set(e,n);}return `${n}${ge}${t}${ge}${r}${ge}${o.join(ge)}`},Su=new WeakMap,zt=e=>{let t=[],r=(o,n)=>{let i=O(e.lens.maps,o.mapName);if(!T(i,o.modelName))return;let s=D(e,o.mapName,o.modelName,o.relPath);t.push({path:n,at:o,effect:s});for(let a of s.relations){let l=$e(i,o.modelName,a),d=l&&Xe(l,o.mapName);d&&r({...d,relPath:[...o.relPath,a]},`${n}.${a}`);}};return r({mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]},e.lens.model),t},hs=(e,t,r,o)=>D(e,t,r,Oa).sources.has(o),ws=(e,t,r,o)=>new A(`source '${o}' at '${e}' offers mapDefaults.${t}.models.${r}.sources.${o}, which no layer declares`,"invalid_source"),vt=(e,t)=>e.omits.has(t)?false:e.relationFields.has(t)?e.relations.has(t):!(e.picks!==null&&!e.picks.has(t)),ms=(e,t)=>e.enumValuesByField.get(t)??null,Gr=(e,t,r)=>{let o=r.split("."),n=[],i=[];for(let{index:s,field:a,at:l,entry:d,next:p}of cr(e.lens.maps,t,r)){if(!d)return {resolution:{outcome:"missing",index:s,hops:n},effects:i};let f=D(e,l.mapName,l.modelName,l.relPath);if(!(e.clamp&&V(d)?!f.omits.has(a):vt(f,a)))return {resolution:{outcome:"hidden",index:s,hops:n},effects:i};let m={field:a,entry:d,mapName:l.mapName,model:l.modelName,relPath:[...l.relPath]};n.push(m),i.push(f);let y=s===o.length-1;if(y||je(d))return {resolution:{outcome:"resolved",hops:n,terminal:m,jsonSubPath:y?[]:o.slice(s+1)},effects:i};if(!p)return {resolution:{outcome:"pastScalar",index:s,hops:n},effects:i}}return {resolution:{outcome:"missing",index:o.length,hops:n},effects:i}},tn=(e,t,r,o,n)=>{let i=n==="label"?t.sourceLabels.get(o):t.sourceGroupBys.get(o);if(i===void 0)return true;let s=t.sourceDeclaredAt.get(ba(o,n,i)),a=(p,f)=>Gr(p,r,f).resolution.outcome!=="hidden",l={...e,clamp:true},d={...l,skipHidingOf:s===void 0?void 0:e.chain[s]};return (typeof i=="string"?[i]:i).every(p=>jn(e,r,p)===null&&(a(l,p)||a(d,p)))},Yo=(e,t,r)=>{let{resolution:o,effects:n}=Gr(e,t,r);if(o.outcome!=="resolved")return null;let{terminal:i,jsonSubPath:s}=o;return {mapName:i.mapName,modelName:i.model,relPath:i.relPath,entry:i.entry,terminalEffect:n[n.length-1],terminalFieldName:i.field,jsonSubPath:s}},cs=(e,t,r,o)=>{let{resolution:n}=Gr(e,t,r);if(n.outcome!=="hidden")return {code:"not_in_lens",message:o};let i=r.split("."),s=n.hops.at(-1),a=s?{mapName:s.mapName,modelName:s.model,relPath:[...s.relPath,s.field]}:t,l=s&&Xe(s.entry,s.mapName),d=l?{...l,relPath:a.relPath}:t,p=D(e,d.mapName,d.modelName,d.relPath),f=i[n.index];return !p.relationFields.has(f)||p.omits.has(f)?{code:"not_in_lens",message:o}:{code:"not_in_lens",message:`'${i.slice(0,n.index+1).join(".")}' is a relation the lens does not turn on (turn it on with \`relations\`)`}},Pt=e=>({mapName:e.lens.mapName,modelName:e.lens.model,relPath:[],open:false}),en=(e,t,r)=>{let o=qe(r,t);if("outOfBounds"in o)return {issue:{code:"scope_out_of_bounds",message:o.outOfBounds}};if(o.scope.open)return {from:o.scope,next:o.scope,walked:null};let n=Yo(e,o.scope,o.path);if(!n)return {issue:cs(e,o.scope,o.path,"path does not resolve through the narrowed lens")};let i=je(n.entry),s=Xe(n.entry,n.mapName),a=s?{...s,relPath:[...n.relPath,n.terminalFieldName],open:i}:{...o.scope,open:i};return {from:o.scope,next:a,walked:n}},ve=(e,t,r,o="")=>{let n=r.split("."),i=[],s=null;for(let{index:a,field:l,at:d,entry:p,next:f}of cr(e,t,r)){if(!p||!f)break;let u=[...d.relPath,l];i.push({map:f.mapName,model:f.modelName,relPath:u,prefix:`${o}${n.slice(0,a+1).join(".")}`,isList:p.isList===true}),a===n.length-1&&(s={...f,relPath:[...u]});}return {hops:i,end:s}};var va="parent:",Na=e=>e.startsWith(va),xu=e=>Na(e)?e.slice(va.length):e,Pa=(e,t)=>{let r={...e};if(e.where!==void 0&&(r.where=t(e.where)),e.sources){let o={};for(let[n,i]of Object.entries(e.sources))o[n]=Fn(i)?i.where!==void 0?{...i,where:t(i.where)}:i:t(i);r.sources=o;}if("relations"in e&&e.relations){let o={};for(let[n,i]of Object.entries(e.relations))o[n]=Pa(i,t);r.relations=o;}return r},Eu=(e,t)=>{let r={};for(let[o,n]of Object.entries(e.mapDefaults??{})){let i={};for(let[s,a]of Object.entries(n.models??{}))i[s]=Pa(a,t);r[o]=n.models?{...n,models:i}:n;}return {...e,root:e.root?Pa(e.root,t):void 0,mapDefaults:e.mapDefaults?r:void 0}},Aa=e=>{let t=[];return Eu(e,r=>(t.push(r),r)),t},Ou=e=>{let t=new Set;for(let r of Aa(e))for(let o of $n(r))Na(o)||t.add(o);return t},$u=e=>{let t=new Set;for(let r of $t(e))for(let o of Aa(r))for(let n of $n(o,{required:true}))t.add(xu(n));return [...t].sort()},Pu=(e,t)=>{if(ot(e))return e;let r={...t};for(let[o,n]of Object.entries(t))r[`${va}${o}`]=n;return {...Eu(e,o=>na(o,r)),parent:Pu(e.parent,t)}},vu=(e,t)=>Pu(e,t),Nu=e=>{let t=[],r=new Set;for(let n of $t(e.parent))for(let i of Ou(n))r.add(i);for(let n of Ou(e))r.has(n)&&t.push(`bind name '${n}' already declared by an ancestor narrowing \u2014 rename it, or reference the inherited one as 'parent:${n}'`);let o=new Set;for(let n of Aa(e))for(let i of $n(n))Na(i)&&o.add(xu(i));for(let n of o)r.has(n)||t.push(`bind 'parent:${n}' references an inherited binding no ancestor declares`);return t};var Tu=(e,t)=>e===void 0?t:t===void 0?e:{all:[e,t]},dO=(e,t)=>{if(!e||!t)return e??t;let r={...e};for(let[o,n]of Object.entries(t)){let i=r[o];if(i===void 0){r[o]=n;continue}let s=br(i),a=br(n),l=Tu(s.where,a.where);r[o]={...s,...a,...l===void 0?{}:{where:l}};}return r},ku=(e,t)=>{let r=Tu(e?.where,t.where),o=dO(e?.sources,t.sources);return {...e,...r===void 0?{}:{where:r},...o?{sources:o}:{}}},fO=(e,t)=>{let r={...e?.models};for(let[o,n]of Object.entries(t))r[o]=ku(r[o],n);return {...e,models:r}},Au=(e,t)=>{let r={...e.mapDefaults};for(let[o,{models:n}]of Object.entries(t.mapDefaults??{}))r[o]=fO(r[o],n);return {...e,...t.root?{root:ku(e.root,t.root)}:{},...t.mapDefaults?{mapDefaults:r}:{}}},Ta=(e,t)=>ot(e)?Au({parent:e},t):ot(e.parent)?Au(e,t):{...e,parent:Ta(e.parent,t)};var Cu=(e,t)=>{let r=M(t),o=(n,i)=>typeof n=="string"&&n!==""?en(r,i,n):null;return pr(e,{rewrite:(n,i)=>{if(ne(n)!=="field"||n.coerceType)return n;let s=o(n.field,i);if(!s||"issue"in s||!s.walked||s.walked.jsonSubPath.length)return n;let{entry:a}=s.walked;return a.kind==="scalar"&&Yd.includes(a.type)?{...n,coerceType:a.type}:n},below:(n,i)=>{if(!Te(n))return false;let s=o(n.field,i),a=s&&!("issue"in s)?s.walked?.entry:void 0;return s&&!("issue"in s)&&a&&V(a)?[...i,s.next]:false}},[Pt(r)])};var Mu=({maps:e,bridges:t,mapName:r,model:o})=>({...es({maps:e,bridges:t}),mapName:r,model:o});var uO=(e,t)=>H(e,(r,o)=>{if(t.sources.add(o[o.length-1].mapName),Fe(r)||typeof r.field!="string"||r.field==="")return;let n=en(t.policy,o,r.field);return "issue"in n?false:(n.walked&&(t.sources.add(n.walked.mapName),(n.walked.entry.kind==="bridge"||n.walked.mapName!==n.from.mapName)&&(t.bridgesCrossed=true)),[...o,n.next])},[Pt(t.policy)]),Lu=(e,t)=>{let o={policy:M(t),sources:new Set,bridgesCrossed:false};return uO(e,o),{sources:[...o.sources].sort(),bridgesCrossed:o.bridgesCrossed,supportedTargets:C.filter(n=>(n==="check"||!o.bridgesCrossed)&&zo(e,{target:n,map:o.policy.lens,mapName:o.policy.lens.mapName,model:o.policy.lens.model}).ok),errors:Xo(e,t).errors}};var cO=new Set([It.scalar,It.ordered,It.array,It.dayList,It.dateValue]),mO=new Set([It.none,It.count]),gO=e=>{if(e.offset!==void 0||En(e).some(({source:r})=>r.value===void 0))return {values:[],dynamic:true};let t=Eo(e);return t?mO.has(t.valueShape)?{values:[],dynamic:false}:cO.has(t.valueShape)?"value"in e?{values:Cn(e)??[],dynamic:false}:{values:[],dynamic:false}:{values:[],dynamic:true}:{values:[],dynamic:true}},yO=e=>e instanceof Date?`d:${+e}`:e instanceof RegExp?`r:${e}`:typeof e=="object"&&e!==null?`j:${JSON.stringify(e)}`:`p:${typeof e}:${String(e)}`,_u=(e,t)=>{let r=M(t),o=r.lens.model,n=new Map,i=new Map,s=(l,d)=>{if(l.length===0)return;let p=Yo(r,{mapName:r.lens.mapName,modelName:o,relPath:[]},l.join("."));if(!p||p.jsonSubPath.length>0)return;let{mapName:f,modelName:u,relPath:m,terminalEffect:y,terminalFieldName:c}=p;if(!y.sources.has(c))return;let g=[o,...m].join("."),w=`${g}|${c}`,R=n.get(w);R||(R={path:g,mapName:f,model:u,field:c,values:[],dynamic:false},n.set(w,R));let S=gO(d);S.dynamic&&(R.dynamic=true);let b=i.get(w)??new Set;i.set(w,b);for(let $ of S.values){let E=yO($);b.has(E)||(b.add(E),R.values.push($));}},a=(l,d)=>{let p=qe(l,d);if(!("outOfBounds"in p))return [...p.scope,...p.path.split(".")]};return H(e,(l,d)=>{if(Fe(l))return;let p=typeof l.field=="string"?a(l.field,d):d.at(-1);return p?(!Te(l)&&typeof l.field=="string"&&s(p,l),[...d,p]):false},[[]]),[...n.values()]};var Ss=(e,t,r,o)=>{let n=hO(e,t,r);if(n.options===t)return o(n.condition,n.options);try{return o(n.condition,n.options)}catch(i){if(i instanceof A||i instanceof k)throw i;try{o(e,n.options);}catch{throw i}throw new A(`${r}: the lens's clamps on this rule have no ${r} form \u2014 ${i.message}`,"unsupported_target")}},hO=(e,t,r)=>{if(t?.lens===void 0)return {condition:e,options:t};let{lens:o}=t;if(t.map!==void 0||t.mapName!==void 0||t.model!==void 0)throw new k(`${r}: pass \`lens\` or \`map\` / \`mapName\` / \`model\`, not both \u2014 the lens names its own`);let n=Xo(e,o);if(!n.ok)throw new Error(`${r}: the rule leaves the lens \u2014 ${n.errors.map(s=>`${s.path}: ${s.message}`).join("; ")}`);let i=nt(o);return {condition:Qo(e,o),options:{...t,lens:void 0,map:i,mapName:i.mapName,model:i.model}}};var bs=(e,t,r,o)=>{if(!Vd.includes(e.operator))throw new Error(`'${e.operator}' does not apply to the enum '${e.field}'; compare its values with equals / in.`);let n=se(e.caseInsensitive),i=Ir(r,o?.enums),{values:s,hasNull:a}=We(ht.includes(e.operator)?[t]:t);if(!n&&(!i||s.every(f=>typeof f=="string"&&i.includes(f))))return null;if(!i)throw new Error(`'${e.field}' is an enum: a case-insensitive comparison reads its declared values, which the map doesn't list.`);let l=f=>n?f.toLowerCase():f,d=new Set(s.filter(f=>typeof f=="string").map(f=>l(f))),p=i.filter(f=>d.has(l(f)));return B.includes(e.operator)?{values:i.filter(f=>!p.includes(f)),matchesNull:!a}:{values:p,matchesNull:a}};var re=e=>`"${e.replace(/"/g,'""')}"`;var be=e=>e.replace(/\\/g,"\\\\").replace(/%/g,"\\%").replace(/_/g,"\\_"),ka=(e,t,r=false)=>{let[o,...n]=e.split("."),i=t?`${re(t)}.${re(o)}`:re(o);if(n.length===0)return i;let s=n.map(Ca),a=s.pop();return [i,...s].join("->")+(r?"->":"->>")+a},Ca=e=>`'${e.replace(/'/g,"''")}'`;var wO=["@prisma/client/runtime/client","@prisma/client/runtime/library"],Rs,SO=()=>{if(Rs!==void 0)return Rs;for(let e of bO())for(let t of wO)try{let r=e(t);if(r.AnyNull!==void 0)return Rs=r.AnyNull,Rs}catch{}},bO=()=>{let e=[];try{let t=globalThis.process?.getBuiltinModule?.("module")?.createRequire;t&&e.push(t(import.meta.url));}catch{}return typeof Fs=="function"&&e.push(Fs),e},Du=()=>{let e=ze.get("prismaOptions.anyNull")??SO();if(e===void 0)throw new Error("A null check on a Json field needs Prisma's AnyNull, and @prisma/client isn't installed: engineGlobals.set('prismaOptions.anyNull', Prisma.AnyNull).");return e};var Fu=(e,t)=>{let r=_r(tt(t));return r===null?null:Lr(e,r)},ju=(e,t,r)=>{if(e===null)return null;let o=jo(tt(t)),n=o&&Mr(o[0],Tn);return !o||!n?null:lr(Rt(e),n,o[1],Wo(r).timeZone).toDate()};var La=(e,t)=>Ie(e,t?.map,t?.model),Nt=e=>e==="json"||e==="json-path",Rr=e=>Nt(e)?Du():null,zr=(e,t)=>t?.map&&t?.model?jf(e,t.map,t.model).map(r=>Ur(r,{is:null})):[],_a=(e,t)=>{let r=La(e,t);return [...Nt(r)||r==="list"||X(e.field,t?.map,t?.model)?.isRequired===false?[it(e.field,{equals:Rr(r)},t)]:[],...zr(e.field,t)]},Os=(e,t,r,o)=>{if(r.mode&&Nt(o)&&Array.isArray(t))throw F("toPrisma",`A case-insensitive comparison of a Json value with the list ${JSON.stringify(t)}`);if(!r.mode||typeof t!="string")return {[e]:t,...r};if(!Nt(o))return {[e]:be(t),...r};if(/[%_\\"\u0000-\u001f]/.test(t))throw F("toPrisma",`A case-insensitive equality on Json against '${t}'`,"Prisma matches the JSON text, where %, _, a backslash, a quote or a control character doesn't read as itself");return {[e]:t,...r}},Da=(e,t,r,o)=>{let n=t?.datasource?.provider??ze.get("prismaOptions.datasource.provider");return se(e.caseInsensitive)&&Dd(n)&&yr(r,o)?{mode:"insensitive"}:{}},Iu=(e,t)=>{if(e==="list")return [{isEmpty:true}];let r=t?[{equals:""}]:[];return Nt(e)?[...r,{equals:[]}]:r},qu=e=>"isEmpty"in e?{isEmpty:false}:{not:e.equals},Fa=(e,t,r,o,n)=>{let i=a=>it(e,a,n),s=Iu(t,o);return r?W([i({equals:Rr(t)}),...zr(e,n),...s.map(a=>i(a))]):Ke([...t==="list"?[]:[i({not:Rr(t)})],...s.map(a=>i(qu(a)))])},OO=(e,t)=>{if(!Ut(e))throw sr(e.field);let o=(n=>it(e.field,n,t))({is:{}});return me({...e,field:"relation"},{relation:null})===true?Ce(o):o},xO=(e,t)=>X(e.field,t?.map,t?.model),Ma=rt(),EO=(e,t,r)=>{if(t==="list"||Nt(t)||xO(e,r)?.isRequired!==true)return null;let o=e.field.split(".").slice(0,-1).join(".");return o?it(o,{is:{}},r):Ma},Vu=(e,t)=>{let r=c=>it(e.field,c,t),o=La(e,t),n=()=>_a(e,t),i=ts(e,t?.map,t?.model);if(o==="relation")return OO(e,t);let s=EO(e,o,t),a=s&&(s===Ma?Et():Ce(s)),l=c=>s&&a?me({field:"f",operator:c,value:null},{f:null})===true?a:s:null;if(s&&a&&Ut(e)){let c=Iu(o,i);return e.operator===h.isEmpty?W([a,...c.map(r)]):e.operator===h.notEmpty?Ke([s,...c.map(g=>r(qu(g)))]):l(e.operator)}switch(e.operator){case h.exists:case h.notExists:{if(e.operator===h.exists)return o==="list"?Ce(r({equals:null})):r({not:Rr(o)});let c=n();return c.length?W(c):r({equals:Rr(o)})}case h.isEmpty:case h.notEmpty:return Fa(e.field,o,e.operator===h.isEmpty,i,t)}if(xe(e)){let c=is(e,t?.map,t?.model,Gf(t),zf(t));if("problem"in c)throw ss(e.path,c.problem);let g=r({[c.key]:c.ref}),w=($,E)=>E.isRequired===false?it($,{equals:null},t):null,R=($,E)=>E.isRequired===false?it($,{not:null},t):Ma,S=w(e.field,c.field),b=w(c.columnPath,c.column);return e.operator===h.equals?S&&b?W([g,Ke([S,b])]):g:e.operator===h.notEquals?W([Ce(g),...S?[Ke([S,R(c.columnPath,c.column)])]:[],...b?[Ke([R(e.field,c.field),b])]:[]]):g}let d=Bu(e,t);if(Se(e,d))return W(B.includes(e.operator)?n():[]);if(d===null&&ht.includes(e.operator)){let c=l(e.operator);if(c)return c}if(o==="list"&&ir.includes(e.operator)&&Array.isArray(d))return ae(Yi(e,d),t);if(o==="list"&&Array.isArray(d)&&d.includes(null))throw F("toPrisma",`A list holding null in '${e.field}'`);if(o==="list"&&se(e.caseInsensitive)&&yr("text",d))throw F("toPrisma",`A case-insensitive comparison on the list '${e.field}'`);let p=o==="enum"?X(e.field,t?.map,t?.model):void 0,f=p?bs(e,d,p,t?.map):null;if(f){let c=r({in:f.values});return f.matchesNull?W([c,...n()]):c}if(ir.includes(e.operator)){let{values:c,hasNull:g}=We(d),w=Da(e,t,o,c),R=Nt(o)?e.operator===h.in?W(c.map(S=>r(Os("equals",S,w,o)))):Ke(c.map(S=>r(Os("not",S,w,o)))):r({[e.operator]:c,...w});return e.operator===h.in?g?W([R,...n()]):R:g?Ke([R,s??r({not:Rr(o)})]):W([R,...n()])}let u=c=>{if(!Nt(o)||c!==h.contains)return r(In({...e,operator:c},t));let g=r({array_contains:[$O(e,d,t,o)]});return typeof d=="string"?W([r(In({...e,operator:c},t)),g]):g};if(e.operator===h.contains)return u(h.contains);let m=Hd.includes(e.operator)?Sn[e.operator]:Po.includes(e.operator)?h.between:void 0;if(m){if(Nt(o))throw F("toPrisma",`'${e.operator}' on the Json value '${e.field}'`,"it keeps values of other types");return W([Ce(u(m)),...n()])}let y=r(In(e,t));return e.operator===h.equals&&d===null?W([y,...zr(e.field,t)]):e.operator===h.notEquals&&o==="list"?d===null?Ce(r({equals:null})):W([Ce(r({equals:d})),...n()]):e.operator===h.notEquals&&d!==null?W([y,...n()]):y},Bu=(e,t)=>{let r=Zo(e,tt(e),mr(e.field,t?.map,t?.model),"toPrisma",()=>Wo(t).timeZone);return e.offset===void 0?r:Fu(r,e.offset)},In=(e,t)=>{let r=Bi(e);if(r)throw r;let o=La(e,t),n=()=>Bu(e,t),i=d=>Da(e,t,o,d),s=d=>{let p=n();if(o==="list"){if(d!=="contains")throw new Error(`Operator '${d}' does not apply to the list '${e.field}'.`);return {has:p}}let f=Nt(o)?PO[d]:d,u=typeof p=="string"?be(p):p;return {[f]:u,...i(p)}},a=Wi(e.operator,n());if(a)throw a;let l=or(e.operator,"field");if(l&&$o.includes(e.operator))return {[l]:n()};switch(e.operator){case h.equals:{let d=n()??Rr(o);return Os("equals",d,i(d),o)}case h.notEquals:{let d=n()??Rr(o);return Os("not",d,i(d),o)}case h.in:case h.notIn:return {[e.operator]:n()};case h.contains:return s("contains");case h.startsWith:return s("startsWith");case h.endsWith:return s("endsWith");case h.matches:case h.notMatches:throw F("toPrisma",`'${e.operator}'`,"Prisma has no pattern filter");case h.between:case h.notBetween:{let[d,p]=Be(Ye(n(),e.operator));return {gte:d,lte:p}}default:throw new Error(`Operator '${e.operator}' is built by buildFieldRule`)}},$O=(e,t,r,o)=>{if(typeof t=="object"&&t!==null)throw new Error(`Membership of an object or a list in the Json array '${e.field}' has no exact Prisma form; use toSql() or check().`);if(Da(e,r,o,t).mode)throw F("toPrisma",`A case-insensitive member of the Json array '${e.field}'`);return t},PO={contains:"string_contains",startsWith:"string_starts_with",endsWith:"string_ends_with"},it=(e,t,r)=>{if(!r?.map||!r?.model)return Ur(e,t);let o=te(e,r.map,r.model),n=o.hops.find(s=>s.entry.isList);if(n)throw To(e,n);let i=e.split(".");switch(o.kind){case "fallback":case "direct":return Ur(e,t);case "bridge":return Wr();case "past-scalar":throw ko(e,o.column);case "json-path":{let s={path:o.jsonPath,...t},a=i.slice(0,o.stopIndex).join(".");return Ur(a,s)}}};var Wu=(e,t,r)=>{if(Ee(e)){let o=Vo(e);if(!o)throw St("toPrisma");return ae(o,t,r)}if(!t?.map||!t?.model||!r)throw new Error("Aggregate rules require a FieldMap and model to generate a Prisma plan. Pass { map, model } options to toPrisma().");if(!yt.includes(e.aggregate.mode))throw ar(e.aggregate.mode);if(!e.aggregate.field)throw new Error("Prisma aggregate rules require aggregate.field to specify the numeric field on the related model.");return vO(e,t,r)},vO=(e,t,r)=>{let o=Ko(e.field,t.map,t.model,"Aggregate rules");if(e.condition&&xt(e.condition,t.map,o.target))return Wr();let n=e.aggregate.field??"",i=$e(t.map,o.target,n);if(!i)throw new Error(`aggregate.field '${n}' does not exist on model '${o.target}'.`);if(i.kind!=="scalar"||je(i))throw new Error(`aggregate.field '${n}' on model '${o.target}' must be a numeric scalar, got ${i.kind==="scalar"?"Json":`'${i.kind}'`}.`);let s=Uo(t)(e);if(s===null||Se(s,s.value))return Et();let a=Nn(s,[{}],void 0,{},{value:0})===true,l=a?Ue(s):s,d=In(l,t),p={[e.aggregate.mode==="sum"?"_sum":"_avg"]:d},f=Po.includes(l.operator)?Ce({[n]:p}):{[n]:p},u=e.condition?ae(e.condition,Br({...t,model:o.target},t,true),r):rt(),m=ls(r,o,u,f,a);return a?W([m,...zr(e.field,t)]):m};var Ku=(e,t,r)=>{if(!e.field)throw new Error("toPrisma: count-based ArrayRule requires a field path");let o=Ko(e.field,t.map,t.model,"Count operators");if(e.condition===void 0)throw De(e.arrayOperator);if(e.count===void 0)throw Ao(e.arrayOperator);let n=e.count;if(e.arrayOperator===x.atLeast&&n===0)return rt();let i=ae(e.condition,Br({...t,model:o.target},t,true),r),s=ja(e),a=s?Uu(x.atLeast,e.arrayOperator===x.atMost?n+1:1,o.targetKey):Uu(e.arrayOperator,n,o.targetKey);return ls(r,o,i,a,s)},Uu=(e,t,r)=>{let o=or(e,"array");if(!o)throw new Error(`'${e}' does not count`);return {[r]:{_count:{[o]:t}}}};var Gu=(e,t,r)=>{let o=zu(e,t,r);return e.field&&ja(e)&&!Hu(e.field,t)?W([o,...zr(e.field,t)]):o},ja=e=>me({...e,field:"items"},{items:[]})===true,NO=e=>{let t=Hs(e);if(!t)return null;let{count:r,...o}=e;return {...o,arrayOperator:t}},zu=(e,t,r)=>{if(Ee(e)){let s=Vo(e);if(!s)throw St("toPrisma");return ae(s,t,r)}if(e.condition!==void 0&&!Gd.includes(e.arrayOperator)&&xt(e.condition,t?.map,Ju(e,t)?.model))return Wr();let o=NO(e);if(o)return zu(o,t,r);if(yn.includes(e.arrayOperator)){if(t?.map&&t?.model&&r)return Ku(e,t,r);throw new Error(`ArrayOperator '${e.arrayOperator}' requires a FieldMap and model to generate a multi-step plan. Pass { map, model } options to toPrisma(). Without them, use prisma.$queryRaw for count-based relation filtering.`)}if(!e.field)throw qi("toPrisma");let{field:n}=e;if(Hu(n,t))return AO(e,n,Ie({field:n},t?.map,t?.model),t);let i=TO(e,t,r);return it(e.field,i,t)},Hu=(e,t)=>{let r=Ie({field:e},t?.map,t?.model);return r==="list"||r==="json"||r==="json-path"},AO=(e,t,r,o)=>{switch(e.arrayOperator){case x.empty:case x.notEmpty:return Fa(t,r,e.arrayOperator===x.empty,false,o);default:throw F("toPrisma",`'${e.arrayOperator}' over the ${r==="list"?"list":"Json array"} '${t}'`,r==="list"?"test a list's membership with 'contains'":void 0)}},Ju=(e,t)=>{if(!t?.map||!t?.model||!e.field)return t&&Br({...t});let r=An(e.field,t.map,t.model);return Br(r?{...t,model:r}:{...t})},TO=(e,t,r)=>{let o=Ju(e,t);switch(e.arrayOperator){case x.all:if(!e.condition)throw De(e.arrayOperator);return {none:ae(Ue(e.condition,Uo(o)),o,r)};case x.any:if(!e.condition)throw De(e.arrayOperator);return {some:ae(e.condition,o,r)};case x.none:if(!e.condition)throw De(e.arrayOperator);return {none:ae(e.condition,o,r)};case x.empty:return {none:{}};case x.notEmpty:return {some:{}};default:throw le(e.arrayOperator,"array")}};var Qu=(e,t)=>{let r=t?.map,o=Ie({field:e.field},r,t?.model);if(o==="json"||o==="json-path")throw F("toPrisma",`A date rule on the Json value '${e.field}'`,"Prisma compares Json text");let n=X(e.field,r,t?.model);if(n&&!V(n)&&et(n)!==Q.DateTime)throw F("toPrisma",`A date rule on the ${n.type} field '${e.field}'`,`Prisma compares it as ${n.type}, not as an instant`);let i=B.includes(e.dateOperator)?_a(e,t):[],s=kO(e,t);if(s===null)return W(i);let a=it(e.field,s,t),l=Po.includes(e.dateOperator)?Ce(a):a;return W([l,...i])},kO=(e,t)=>{let r=Wo(t),o=Tn,n=m=>e.offset===void 0?m:ju(m,e.offset,t),i=m=>{if(m==null)return null;if(!Y(m))return Qi(m,r.timeZone);let y=bt(m,o);return y&&Mo(y,e.dateOperator,r).toDate()},s=()=>{let m=tt(e);if(m==null)return m;let y=e.offset===void 0?void 0:tt(e.offset),c=Wt(m,y);if(c)throw c;return m},a=()=>n(i(s())),l=()=>{let m=s();if(m==null)return null;let y=Ye(m,e.dateOperator).map(i);if(y[0]===null||y[1]===null)return null;let[c,g]=Be(y).map(n);return c&&g?[c,g]:null},d=()=>{let m=s();if(m==null)return null;if(!Y(m))throw Qe(e.dateOperator);let y=bt(m,o);if(!y)return null;let[c,g]=Lo(y,r);return [c.toDate(),g.toDate()]},p=m=>{let y=a();return y===null?null:{[m]:y}},f=m=>m?{gte:m[0],lte:m[1]}:null,u=or(e.dateOperator,"date");if(u)return p(u);switch(e.dateOperator){case v.within:case v.notWithin:return f(d());case v.between:case v.notBetween:return f(l());case v.dayIn:case v.dayNotIn:throw F("toPrisma",`'${e.dateOperator}'`);default:throw le(e.dateOperator,"date")}};var Ia=(e,t,r)=>{if(typeof e=="boolean")return e?{}:Et();Pi(e,"toPrisma");let o=ne(e);(o==="field"||o==="date")&&rs(e.field,t?.map,t?.model);let n=e;switch(o){case "all":return Yf(n,t,r);case "any":return Xf(n,t,r);case "if":return eu(n,t,r);case "array":return Gu(n,t,r);case "aggregate":return Wu(n,t,r);case "date":return Qu(n,t);case "field":return Vu(n,t);default:throw wt()}};Qf(Ia);var Yu=async(e,t)=>{let r=e.steps.filter(i=>i.operation==="groupBy"),o=e.steps.find(i=>i.operation==="where");if(!o)throw new Error("executePrismaPlan: result has no where step");let n=[];for(let i of r){let s=Xu(t,i.model),a=Zu(i.args,i.refs,n,t),l=await s[i.operation](a);n.push(l.map(d=>d[i.extract]).filter(d=>d!=null));}return Zu(o.where,o.refs,n,t)},Xu=(e,t)=>{let r=t.charAt(0).toLowerCase()+t.slice(1),o=e[r];if(!o)throw new Error(`executePrismaPlan: no delegate for model '${t}'. Ensure prismaDelegate has a key '${r}'.`);return o},CO=(e,t)=>{let r=Xu(e,t.model).fields,o=r&&Object.hasOwn(r,t.field)?r[t.field]:void 0;if(o===void 0)throw new Error(`executePrismaPlan: the '${t.model}' delegate has no field reference '${t.field}' (fields.${t.field}).`);return o},MO=(e,t)=>t.reduce((r,o)=>r!==null&&typeof r=="object"&&Object.hasOwn(r,o)?r[o]:void 0,e),qa=(e,t,r)=>{if(t.length===0)return r;let[o,...n]=t,i=e,s=Array.isArray(e)?[...e]:{...i};return s[o]=qa(i[o],n,r),s},Zu=(e,t,r,o)=>{let n=e;for(let{path:i}of t??[]){let s=MO(e,i);if(s&&typeof s.__step=="number"){let a=s.__step;if(a>=r.length)throw new Error(`Step ref __step: ${a} out of range (${r.length} steps executed)`);n=qa(n,i,r[a]);}else if(s&&typeof s.__field=="object"&&s.__field!==null)n=qa(n,i,CO(o,s.__field));else throw new Error(`executePrismaPlan: no reference at the recorded location ${i.join(".")}`)}return n};var LO=e=>e?.map?{...e,map:Pe(e.map,e.mapName,"toPrisma")}:e,qn=(e,t)=>Ss(e,t,"toPrisma",_O),_O=(e,t)=>{let r={steps:[]},o=Ia(e,LO(t),r),n=(i,s)=>{let a=Wf(s);return a.length?{...i,refs:a}:i};return {steps:[...r.steps.map(i=>n(i,i.args)),n({operation:"where",where:o},o)]}};var DO=/^-?\d+(\.\d+)?$/,ec=e=>typeof e=="string"?DO.test(e)?Number(e):e:typeof e=="object"&&e!==null&&typeof e.toNumber=="function"?e.toNumber():e,Va=(e,t)=>e?.kind!=="scalar"||e.type!=="Decimal"?t:Array.isArray(t)?t.map(ec):ec(t);var xs=(e,t,r,o,n)=>{let i=`${r.mapName}\0${r.modelName}`;for(let a of t){if(typeof a=="boolean")continue;let l=e.memo?.compiles.get(a)??new Map;e.memo?.compiles.set(a,l);let d=l.get(i);if(d===void 0){let[p]=zo(a,{target:"toPrisma",map:e.lens,mapName:r.mapName,model:r.modelName}).errors;d=p?p.message:null,l.set(i,d);}if(d!==null)return new A(`${o}: ${d}`,"unsupported_clamp")}if(n)return null;let s=false;for(let a of t)H(a,l=>{("aggregate"in l||hn(l))&&(s=true);});return s?new A(`${o} needs a counting step (executePrismaPlan), which a relation's where in a select can't run`,"unsupported_clamp"):null},Es=(e,t)=>{try{return t()}catch(r){throw r instanceof A||r instanceof k?r:new A(`${e}: ${r.message}`,"unsupported_clamp")}};var tc=(e,t)=>e===""?t:t===""?e:`${e}.${t}`,Ge=e=>{let t=new Set,r=n=>{n&&t.add(n);},o=(n,i)=>{let s=qe(n,i);return "outOfBounds"in s?null:tc(s.scope,s.path)};return H(e,(n,i)=>{if(Fe(n))return;for(let l of dr(n))r(L(l)?o(l,i):l);let s=typeof n.field=="string"&&n.field!==""?o(n.field,i):null;if(r(s),!Te(n))return;let a=s??i[i.length-1];for(let l of Do(n))r(tc(a,l));return [...i,a]},[""]),[...t]};var Ba=(e,t,r,o,n)=>{let i={};for(let[s,a]of Object.entries(o.fields)){if(!vt(t,s))continue;let l=t.enumValuesByField.get(s),d=n(s)?.filter(f=>l===void 0||l.includes(f.value)),p=tn(e,t,r,s,"groupBy")?t.sourceGroupBys.get(s):void 0;i[s]={...a,...l!==void 0&&{values:l},...d!==void 0&&{options:d},...p!==void 0&&{groupBy:p}};}return i},rc=(e,t,r,o,n)=>{let{mapName:i,modelName:s}=t,a=T(O(e.lens.maps,i),s),l=Ba(e,r,t,a,m=>{let y=n.get(`${o}|${m}`),c=r.enumValuesByField.get(m);return y??O(a.fields,m)?.options??c?.map(g=>({value:g,label:g}))}),d={};for(let[m,y]of r.sources)vt(r,m)&&(d[m]=y);let p={};for(let[m,y]of r.sourceLabels)vt(r,m)&&tn(e,r,t,m,"label")&&(p[m]=y);let f={};for(let[m,y]of r.sourceGroupBys)vt(r,m)&&tn(e,r,t,m,"groupBy")&&(f[m]=y);let u={};for(let m of r.sourcesFromMapDefaults.keys()){if(!hs(e,i,s,m))throw ws(o,i,s,m);Object.hasOwn(d,m)&&(u[m]="mapDefaults");}return {mapName:i,model:s,fields:l,whereClauses:r.whereClauses,sources:d,sourceLabels:p,sourceGroupBys:f,sourceFrom:u}},oc=e=>{let t=new Map;for(let r of e.sourceValues??[])t.set(`${r.path}|${r.field}`,r.options);return t},nc=(e,t={})=>Vn(M(e),t),Vn=(e,t={})=>{let r=oc(t),o={};for(let{path:n,at:i,effect:s}of zt(e))o[n]=rc(e,i,s,n,r);return o},ic=(e,t,r={})=>Wa(M(e),t,r),Wa=(e,t,r={})=>{let o={mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]};if(t!=="")for(let s of cr(e.lens.maps,o,t)){let a=D(e,s.at.mapName,s.at.modelName,s.at.relPath);if(!s.next||!a.relations.has(s.field))return null;o={...s.next,relPath:[...s.at.relPath,s.field]};}if(!T(O(e.lens.maps,o.mapName),o.modelName))return null;let n=D(e,o.mapName,o.modelName,o.relPath),i=[e.lens.model,...o.relPath].join(".");return rc(e,o,n,i,oc(r))};var $s=(e,t,r,o,n)=>{let i=e.split("."),{hops:s}=ve(t,{mapName:r,modelName:o,relPath:[]},e),a=s.find((f,u)=>f.isList&&u<i.length-1);if(a)return `${n} cannot traverse to-many relation '${i[s.indexOf(a)]}'`;if(s.length===i.length)return `${n} must end on a scalar column, '${i.at(-1)}' is a relation`;let l=s.at(-1)??{map:r,model:o},d=i[s.length],p=$e(O(t,l.map),l.model,d);return p?V(p)?`${n} relation '${d}' has no resolvable target`:s.length===i.length-1?null:`${n} segment '${d}' is not a relation`:`${n} segment '${d}' not on model '${l.model}'`},sc=(e,t,r,o,n,i,s,a)=>{let l=$s(n,e.lens.maps,t,r,i);if(l)throw new A(`${i} '${n}': ${l}`,"invalid_source");let{hops:d}=ve(e.lens.maps,{mapName:t,modelName:r,relPath:o},n),p=d.slice(0,n.split(".").length-1);for(let f of p){let u=f.relPath.join(".");if(s.has(u))continue;s.add(u);let m=D(e,f.map,f.model,f.relPath);for(let y of m.whereClauses)a.push(Jo(y,f.prefix));}},FO=(e,t,r,o,n,i)=>{let s=[],a=new Set;for(let l of n)sc(e,t,r,o,l,"groupBy",a,s);return i?.includes(".")&&sc(e,t,r,o,i,"label",a,s),s},Bn=(e,t)=>{let r=ue(e,t);return r==null||typeof r=="object"?void 0:String(r)},Ps=(e,t)=>{let r=[];for(let o of t){let n=Bn(e,o);if(n===void 0)return;r.push(n);}return r},Ua=(e,t)=>JSON.stringify([e??null,t]),jO=(e,t,r,o)=>{let n=Ua(o,t),i=e.get(n);i===void 0?e.set(n,{value:t,...r!==void 0?{label:r}:{},...o!==void 0?{groups:o}:{}}):r!==void 0&&(i.label===void 0||r<i.label)&&e.set(n,{...i,label:r});},vs=(e,t,r,o,n)=>{let i=ue(t,r),s=o==null?void 0:String(o);for(let a of Array.isArray(i)?i:[i])a==null||typeof a=="object"||jO(e,String(a),s,n);},Ns=e=>[...e.values()].sort((t,r)=>{let o=(t.groups===void 0?0:1)-(r.groups===void 0?0:1);if(o!==0)return o;let n=t.groups??[],i=r.groups??[];for(let s=0;s<Math.max(n.length,i.length);s++){let a=(n[s]??"").localeCompare(i[s]??"","en",{numeric:true});if(a!==0)return a}return (t.label??t.value).localeCompare(r.label??r.value,"en",{numeric:true})||t.value.localeCompare(r.value,"en",{numeric:true})}),IO=(e,t,r,o,n)=>{let{hops:i}=te(n,t,o),s=n.split("."),a=i.at(-1)?.entry.type??o,l=s[i.length];for(let{endpoints:d}of e.bridges??[]){let[p,f]=d;for(let[u,m]of [[p,f],[f,p]])if(u.fieldMap===r&&u.model===a&&ke(m)===l)return [...s.slice(0,i.length),u.on].join(".")}throw new A(`'${n}' crosses no bridge the lens declares on ${a}`,"not_in_lens")},As=(e,t,r,o)=>{let n=Pe(e,t,"toPrisma");return [...new Set(o.map(i=>gr(i,n,r)?IO(e,n,t,r,i):i))]},qO=(e,t,r,o)=>{if(t.length===0)return [];let n={mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]},{hops:i,end:s}=ve(e.lens.maps,n,t.join("."));if(!s)throw new A(`source at '${t.join(".")}': its path doesn't resolve on the field maps`,"not_in_lens");let a=[n,...i.map(p=>({mapName:p.map,modelName:p.model}))],l=t.length;for(;l>0&&!r.has(t.slice(0,l).join("."));)l--;let d=l>0?r.get(t.slice(0,l).join("."))??null:null;for(let p=l;p<t.length;p++){let f=E=>{d=E,r.set(t.slice(0,p+1).join("."),E);},u=a[p],m=D(e,u.mapName,u.modelName,t.slice(0,p)).whereClauses,y=d===null?m:[...m,d];if(y.length===0&&!o){f(null);continue}let c=O(e.lens.maps,u.mapName),g=c&&$e(c,u.modelName,t[p]);if(!g)throw new A(`source at '${t.join(".")}': '${t[p]}' isn't declared on ${u.modelName}`,"not_in_lens");let w=a[p+1],R=ke({fieldMap:u.mapName,model:u.modelName}),S=g.kind==="bridge"?$e(O(e.lens.maps,w.mapName),w.modelName,R):void 0,b=g.kind==="bridge"?S&&{field:R,entry:S}:c?as(c,u.modelName,t[p],g):null;if(!b&&y.length===0){f(null);continue}if(!b)throw new A(`source at '${t.join(".")}': '${t[p]}' on ${u.modelName} declares no inverse, so the clamps above can't be carried down to it`,"unsupported_clamp");let $=G(y);try{let E={field:b.field,operator:"exists"};f(b.entry.isList?{field:b.field,arrayOperator:"any",condition:$}:y.length?G([E,Jo($,b.field)]):E);}catch(E){throw E instanceof A?new A(`source at '${t.join(".")}': the clamps above can't be carried down to it \u2014 ${E.message}`,E.code):E}}return d===null?[]:[d]},ac=e=>Or(M(e)),Or=(e,t=Vn(e))=>{let r=new Map,o=n=>{let i=r.get(n)??new Map;return r.set(n,i),i};return Object.entries(t).flatMap(([n,i])=>Object.keys(i.sources).map(s=>{let a=O(i.sourceLabels,s),l=O(i.sourceGroupBys,s),d=Object.hasOwn(i.sourceFrom,s),p={mapName:i.mapName,modelName:i.model,relPath:n.split(".").slice(1)},f=D(e,p.mapName,p.modelName,p.relPath),u=(f.sourceWheres.get(s)??[]).map(N=>Kr(N,e,p)),m=FO(e,p.mapName,p.modelName,p.relPath,l??[],a),y=O(i.fields,s)?.values,c=d?f.sourcesFromMapDefaults.get(s):void 0,g=c===void 0?void 0:e.chain[c],R=[...qO(g===void 0?e:{...e,skipClampsOf:g},p.relPath,o(g),g===void 0&&!d),...u,...m,...y?[{field:s,operator:"in",value:[...y]}]:[]],S=G([...i.whereClauses,...R]),b=G([...i.whereClauses,...u,...m,...y?[{field:s,operator:"in",value:[...y]}]:[]]),$=e.lens.bridges?.length?Pe(e.lens,p.mapName,"toPrisma"):void 0,E=$?[...Ge(S),...a===void 0?[]:[a],...l??[]].find(N=>gr(N,$,p.modelName)):void 0,I=E!==void 0&&$?G(oa(S).filter(N=>xt(N,$,p.modelName))):void 0,pe=xs(e,[...i.whereClauses,...R],p,`source '${s}' at '${n}'`,true);if(pe)throw pe;return {path:n,visit:i,field:s,...d&&{from:"mapDefaults"},...a!==void 0&&{label:a},...l!==void 0&&{groupBy:l},where:S,rowWhere:b,...E!==void 0&&{bridged:E},...I!==void 0&&{recheck:I}}}))};var za=(e,t)=>{for(let r of t){let o=e;for(let n of r.split("."))o=Kt(o,n,()=>({}));}return e},Ts=(e,t)=>{for(let[r,o]of Object.entries(t))Ts(Kt(e,r,()=>({})),o);return e},Ha=e=>e.whereClauses.flatMap(Ge),lc=(e,t)=>{let r=new Map;for(let o of t){if(o.from)continue;let n=o.path.split(".").slice(1).join("."),i=[o.field,...o.label===void 0?[]:[o.label],...o.groupBy??[],...Ge(o.rowWhere)];r.set(n,[...r.get(n)??[],...o.bridged===void 0?i:As(e.lens,o.visit.mapName,o.visit.model,i)]);}return r},pc=(e,t)=>e.get(t.relPath.join("."))??[],VO=(e,t,r)=>za(Ts({},r??{}),Ha(D(e,t.mapName,t.modelName,t.relPath))),dc=e=>({mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]}),Ja=(e,t,r)=>({...r,relPath:[...e.relPath,t]}),BO=(e,t,r,o)=>{if(!r.whereClauses.length)return;let n=G(r.whereClauses),i=xs(e,r.whereClauses,t,`toLensSelect: the clamp on '${t.relPath.join(".")}'`,false);if(i)throw i;if(e.inspect)return;let s=Es(`toLensSelect: the clamp on '${t.relPath.join(".")}'`,()=>qn(n,{...o,map:e.lens,mapName:t.mapName,model:t.modelName})),{where:a}=s.steps[0];return Object.keys(a).length?a:void 0},WO=(e,t,r,o)=>{let n=T(e,o.type)?.fields??{},i=a=>{let l=a===void 0?void 0:O(n,a);return l&&!V(l)?a:void 0},s=e?as(e,t,r,o):null;return i(o.toFields?.[0])??i(s?.entry.fromFields?.[0])??i("id")},fc=(e,t,r,o,n,i)=>{let s=T(O(e.lens.maps,t.mapName),t.modelName)?.fields??{},a=D(e,t.mapName,t.modelName,t.relPath),l=r==="paths"?o:za(Ts({},o),[...Ha(a),...pc(i,t)]),d={};for(let[p,f]of Object.entries(s)){let u=r!=="paths"&&vt(a,p),m=O(l,p);if(!u&&m===void 0||f.kind==="bridge")continue;if(f.kind!=="object"){d[p]=true;continue}let y=u?"declared":"paths";if(y==="paths"&&m===void 0)continue;let c=Ja(t,p,{mapName:t.mapName,modelName:f.type}),g=fc(e,c,y,m??{},n,i),w=f.isList&&y!=="paths"&&m===void 0?BO(e,c,D(e,c.mapName,c.modelName,c.relPath),n):void 0,R=Object.keys(g).length?void 0:WO(O(e.lens.maps,t.mapName),t.modelName,p,f),S=R===void 0?g:{[R]:true};Object.keys(S).length&&(d[p]={select:S,...w&&{where:w}});}return d},uc=(e,t={})=>Qa(M(e),t),Qa=(e,t={},r=Or(e))=>{let o=fc(e,dc(e),"declared",{},t,lc(e,r));if(!Object.values(o).some(n=>n===true)){let n=O(T(O(e.lens.maps,e.lens.mapName),e.lens.model)?.fields,"id");n&&!V(n)&&(o.id=true);}return {select:o}},Ka=(e,t)=>e==null?e:Array.isArray(e)?e.flatMap(r=>{let o=typeof r=="object"&&r!==null?t(r):null;return o===null?[]:[o]}):typeof e=="object"?t(e):null,Ga=(e,t,r,o)=>{let n={},i=T(O(e.lens.maps,t.mapName),t.modelName);for(let[s,a]of Object.entries(o)){if(!Object.hasOwn(r,s))continue;let l=O(i?.fields,s),d=l?Xe(l,t.mapName):null;n[s]=d?Ka(r[s],p=>Ga(e,Ja(t,s,d),p,a)):Va(l,r[s]);}return n},cc=(e,t,r,o,n,i,s)=>{let a=D(e,t.mapName,t.modelName,t.relPath);if(!a.whereClauses.every(f=>me(f,r,i)===true))return null;let l=T(O(e.lens.maps,t.mapName),t.modelName)?.fields??{},d=n?za(Ts({},o),[...Ha(a),...pc(s,t)]):{},p={};for(let[f,u]of Object.entries(l)){if(!Object.hasOwn(r,f))continue;let m=O(d,f),y=Xe(u,t.mapName);if(!y){(vt(a,f)||m!==void 0)&&(p[f]=Va(u,r[f]));continue}let c=Ja(t,f,y);if(vt(a,f)){let g=!Array.isArray(r[f])||m!==void 0;p[f]=Ka(r[f],w=>cc(e,c,w,m??{},n,i,s)??(n&&g?Ga(e,c,w,VO(e,c,m)):null));}else m!==void 0&&(p[f]=Ka(r[f],g=>Ga(e,c,g,m)));}return p},mc=(e,t,{keepClampColumns:r=false,...o}={})=>{let n=M(e),i=dc(n),s=r?lc(n,Or(n)):new Map;return t.flatMap(a=>{let l=cc(n,i,a,{},r,o,s);return l===null?[]:[l]})};var UO="materializeSources needs fetched or keepClampColumns rows, not viewer rows",Za=(e,t,r)=>new k(`${e}: a row at '${t}' ${r}${r.includes(":")?" \u2014 rows across a bridge hold the far side inline under its bridge field":""}`),Wn=(e,t,r,o,n,i=UO)=>{for(let s of n){let a=[r];for(let{index:l,field:d,entry:p,next:f}of cr(e.lens.maps,t,s)){if(!p)break;let u=s.split(".").slice(0,l+1).join("."),m=[];for(let y of a){if(y===null||typeof y!="object")continue;if(!Object.hasOwn(y,d))throw Za(i,o,`lacks '${u}', which a read needs`);let c=y[d];if(f&&c==null&&p.fromFields?.some(g=>{let w=y[g];return w!=null}))throw Za(i,o,`'${u}' is null while its key is set \u2014 a projection hid the row`);if(!(!f||c===null||c===void 0)){if(Array.isArray(c)!==(p.isList===true))throw Za(i,o,`'${u}' holds ${Array.isArray(c)?"a list where it names one row":"one row where it names a list"}`);m.push(...Array.isArray(c)?c:[c]);}}if(!f)break;a=m;}}},Ya=(e,t)=>{let r={mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]};return [r,...ve(e.lens.maps,r,t.split(".").slice(1).join(".")).hops.map(o=>({mapName:o.map,modelName:o.model,relPath:o.relPath}))]},KO=(e,t,r,o)=>{let n=r.split(".").slice(1),i=Ya(e,r),s=(l,d)=>{let p=i[l],f=D(e,p.mapName,p.modelName,p.relPath).whereClauses,u=G(f),m=f.flatMap(Ge),y=[e.lens.model,...n.slice(0,l)].join(".");return d.filter(c=>(Wn(e,p,c,y,m),me(u,c,o)===true))},a=s(0,t);for(let[l,d]of n.entries()){let p=[],f=[e.lens.model,...n.slice(0,l)].join(".");for(let u of a){Wn(e,i[l],u,f,[d]);let m=ue(u,d);Array.isArray(m)?p.push(...m):m!=null&&p.push(m);}a=s(l+1,p);}return {rows:a,visit:i[i.length-1]}},gc=(e,t,r)=>{let o=M(e);return Or(o).map(({path:n,visit:i,field:s,from:a,label:l,groupBy:d,rowWhere:p})=>{if(a)throw new k(`materializeSources: '${n}.${s}' offers its model's own source, which a fetched collection can't hold \u2014 query it with toSourceQueries and materializeSourceQuery.`);let f=[s,...Ge(p),...l===void 0?[]:[l],...d??[]],u=new Map,m=KO(o,t,n,r);for(let y of m.rows)Wn(o,m.visit,y,n,f),me(p,y,r)===true&&vs(u,y,s,l===void 0?void 0:Bn(y,l),d===void 0?void 0:Ps(y,d));return {path:n,mapName:i.mapName,model:i.model,field:s,options:Ns(u)}})};var ks={value:"value",query:"query"},yc=(e,t,r={})=>{let{rowShape:o="prisma",lens:n,order:i=ks.value,...s}=r,a=o==="sql",{recheck:l}=e,d=y=>false,p=y=>true;if(l!==void 0){if(n===void 0)throw new k(`materializeSourceQuery: '${e.path}.${e.field}' reads across a bridge \u2014 its rows are candidates; pass { lens } with rows holding the far side`);let y=M(n),c=Ya(y,e.path).at(-1);if(!c||c.mapName!==e.mapName||c.modelName!==e.model)throw new k(`materializeSourceQuery: the lens doesn't reach ${e.mapName}:${e.model} at '${e.path}' \u2014 pass the lens the query was compiled from`);let g=Pe(y.lens,e.mapName,"toPrisma");d=S=>g!==void 0&&gr(S,g,e.model);let w=[...Ge(l),...e.label!==void 0&&d(e.label)?[e.label]:[],...(e.groupBy??[]).filter(d)],R="materializeSourceQuery needs candidate rows holding the far side of each bridge the source reads";p=S=>(Wn(y,c,S,e.path,w,R),me(l,S,s)===true);}let f=y=>e.label===void 0?void 0:a&&e.label.includes(".")&&!d(e.label)?y.__label:Bn(y,e.label),u=e.groupBy?.map((y,c)=>a&&!d(y)?`__group_${c}`:y),m=new Map;for(let y of t)p(y)&&vs(m,y,e.field,f(y),u===void 0?void 0:Ps(y,u));return {path:e.path,mapName:e.mapName,model:e.model,field:e.field,options:i===ks.query?[...m.values()]:Ns(m)}};var GO=(e,t)=>`${e}::${t}`,zO=(e,t,r)=>{let o=e.get(t);if(!o){e.set(t,r.values?{...r,values:[...r.values]}:r);return}let n=o;if(r.values&&o.values){let i=new Set([...o.values,...r.values]);n={...n,values:[...i]};}else !r.values&&o.values&&(n={...n,values:void 0});r.groupBy!==void 0&&n.groupBy===void 0&&(n={...n,groupBy:r.groupBy}),n!==o&&e.set(t,n);},hc=(e,t={})=>Xa(M(e),t),Xa=(e,t={})=>{let{lens:r}=e,o=new Map;for(let l of t.sourceValues??[]){let d=`${l.mapName}::${l.model}::${l.field}`,p=o.get(d)??new Map;for(let f of l.options)p.set(Ua(f.groups,f.value),f);o.set(d,p);}let n=new Map;for(let{at:l,effect:d}of zt(e)){let{mapName:p,modelName:f}=l,u=T(O(r.maps,p),f);if(!u)continue;let m=GO(p,f),y=n.get(m);y||(y={mapName:p,modelName:f,fields:new Map},n.set(m,y));let c=Ba(e,d,l,u,g=>{let w=o.get(`${p}::${f}::${g}`);return w&&[...w.values()]});for(let[g,w]of Object.entries(c)){let R=w.groupBy,S=y.fields.get(g)?.groupBy;if(R!==void 0&&S!==void 0&&JSON.stringify(S)!==JSON.stringify(R))throw new A(`projectLens: '${f}.${g}' is grouped by different axes on different paths ([${S}] vs [${R}]) \u2014 one surface field cannot carry two partition namespaces`,"invalid_source");zO(y.fields,g,w);}}let i={};for(let{mapName:l,modelName:d,fields:p}of n.values()){let f=O(i,l);f||(f={models:{}},i[l]=f);let u={},m=new Map;for(let[y,c]of p)if(u[y]=c.options===void 0&&c.values?{...c,options:c.values.map(g=>({value:g,label:g}))}:c,c.kind==="enum"&&c.values){let g=m.get(c.type)??new Set;for(let w of c.values)g.add(w);m.set(c.type,g);}f.models[d]={...T(O(r.maps,l),d),fields:u};for(let[y,c]of m)f.enums??={},f.enums[y]=[...c];}let s=r.bridges?.filter(l=>{let[d,p]=l.endpoints,f=$e(O(i,d.fieldMap),d.model,ke(p)),u=$e(O(i,p.fieldMap),p.model,ke(d));return f!==void 0||u!==void 0}),a={maps:i};return s&&s.length>0&&(a.bridges=s),{...a,mapName:r.mapName,model:r.model}};var wc=(e,t,r,o,n)=>{if(e===void 0)return;let i=Ho(e),s=o==="root.where"?null:i.bare;if(s!==null){n.push({path:o,code:"invalid_value_source",message:xa(s).message});return}let{escaping:a}=i;if(a!==null){n.push({path:o,code:"scope_out_of_bounds",message:Ea(a).message});return}let l=new Set,d={...t,clamp:t.chain.length===0};for(let{mapName:p,modelName:f,relPath:u}of r)for(let m of Mn(e,d,p,f,u)){let y=`'${m.path}' ${m.message}`;l.has(y)||(l.add(y),n.push({path:o,code:m.code,message:y}));}},HO=(e,t,r,o,n,i)=>{let s={...r,chain:[...r.chain,t]},a=new Set;for(let l of o){let d=D(s,l.mapName,l.modelName,l.relPath);for(let[p,f]of Object.entries(e.sources??{})){let u=br(f);for(let m of ["label","groupBy"]){if(u[m]===void 0||a.has(`${p}|${m}`))continue;let y=m==="label"?u.label:Dn(u.groupBy),c=m==="label"?d.sourceLabels.get(p):d.sourceGroupBys.get(p);if(JSON.stringify(y)!==JSON.stringify(c))continue;let w=(typeof c=="string"?[c]:c??[]).map(R=>jn(s,l,R)).find(R=>R!==null);if(w){a.add(`${p}|${m}`),i.push({path:`${n}.sources.${p}`,code:"invalid_source",message:`${m} '${String(u[m])}' crosses '${w}', a relation the lens does not show there (not turned on, or omitted)`});continue}tn(s,d,l,p,m)||(a.add(`${p}|${m}`),i.push({path:`${n}.sources.${p}`,code:"invalid_source",message:`${m} '${String(u[m])}' reads a column hidden by another layer`}));}}}},JO=(e,t,r,o)=>{for(let n of r){if(!t&&n.picks&&!n.picks.includes(e))return "not in ancestor's picks";if(n.omits?.includes(e))return "was omitted by ancestor"}return !t&&o?.picks&&!o.picks.includes(e)?"not visible from defaults.picks":o?.omits?.includes(e)?"already excluded by defaults":null},QO=(e,t,r,o,n,i,s,a,l,d,p,f,u=false)=>{let m=e.omits?.some(c=>{let g=O(i,c);return g===void 0||!V(g)});e.picks&&m&&d.push({path:`${l}`,code:"conflicting_selection",message:"cannot specify both picks and omits of a column"});for(let c of ["picks","omits"])for(let g of e[c]??[]){let w=O(i,g);if(!w){d.push({path:`${l}.${c}`,code:"not_in_lens",message:`field '${g}' not on model`});continue}let R=V(w);if(R&&c==="picks"){d.push({path:`${l}.picks`,code:"wrong_kind",message:`'${g}' is a relation: picks names columns; turn a relation on with \`relations\``});continue}let S=JO(g,R,t,r);S&&d.push({path:`${l}.${c}`,code:"not_visible",message:`'${g}' ${S}`});}let y=(c,g,w)=>{let R=O(i,g);if(!R){d.push({path:`${l}.${c}`,code:"not_in_lens",message:`field '${g}' not on model`});return}if(R.kind!=="enum"){d.push({path:`${l}.${c}`,code:"wrong_kind",message:`field '${g}' is not an enum field`});return}let S=Ir(R,a);for(let b of w)S&&!S.includes(b)&&d.push({path:`${l}.${c}.${g}`,code:"value_not_allowed",message:`'${b}' is not a known value of enum '${R.type}'`});};for(let[c,g]of Object.entries(e.enumPicks??{}))y("enumPicks",c,g);for(let[c,g]of Object.entries(e.enumOmits??{}))y("enumOmits",c,g);wc(e.where,p,f,`${l}.where`,d);for(let[c,g]of Object.entries(e.sources??{})){let w=O(i,c);if(!w){d.push({path:`${l}.sources`,code:"not_in_lens",message:`field '${c}' not on model`});continue}if(V(w)){d.push({path:`${l}.sources.${c}`,code:"wrong_kind",message:`'${c}' is a relation: a source offers a column's values`});continue}let R;try{R=br(g);}catch(E){if(!(E instanceof A))throw E;d.push({path:`${l}.sources.${c}`,code:E.code,message:E.message});continue}let S=R.from;if(S!==void 0){let E=S!=="mapDefaults"?`from takes 'mapDefaults', not '${String(S)}'`:u?"a mapDefaults source is what a path source's from: 'mapDefaults' points at; it can't point itself":R.label!==void 0||R.groupBy!==void 0?"a from: 'mapDefaults' source takes the model source's label and groupBy":null;E&&d.push({path:`${l}.sources.${c}`,code:"invalid_source",message:E});}let b=R.label?.includes(".")?R.label:void 0;if(R.label!==void 0)if(b){let E=$s(b,o,n,s,"label");E&&d.push({path:`${l}.sources.${c}`,code:"invalid_source",message:`${E}`});}else {let E=O(i,R.label);E?V(E)&&d.push({path:`${l}.sources.${c}`,code:"wrong_kind",message:`label '${R.label}' is a relation, not a column`}):d.push({path:`${l}.sources.${c}`,code:"not_in_lens",message:`label column '${R.label}' not on model`});}let $=Dn(R.groupBy);if($!==void 0||b!==void 0){let E=/^__(group(_\d+)?|label)$/;(E.test(c)||R.label!==void 0&&E.test(R.label))&&d.push({path:`${l}.sources.${c}`,code:"invalid_source",message:"'__group*' / '__label' names are reserved on grouped or path-labeled sources (sql column aliases)"});}if($!==void 0){for(let I of $){let pe=$s(I,o,n,s,"groupBy");pe&&d.push({path:`${l}.sources.${c}`,code:"invalid_source",message:`${pe}`});}let E=JSON.stringify($);for(let I of t){let pe=O(I.sources,c);if(pe===void 0)continue;let N=Dn(br(pe).groupBy);N!==void 0&&JSON.stringify(N)!==E&&d.push({path:`${l}.sources.${c}`,code:"not_visible",message:`groupBy [${$}] conflicts with an ancestor layer's groupBy [${N}]`});}}wc(R.where,p,f,`${l}.sources.${c}`,d);}},ZO=(e,t,r,o,n)=>{for(let[i,s]of Object.entries(t)){let a=O(r,i);if(!a){n.push({path:`mapDefaults.${e}.enums.${i}`,code:"not_in_lens",message:"enum not in registry"});continue}let l=null,d=new Set;for(let f of o){let u=f[i];if(u&&(u.picks&&(l=ys(l,u.picks)),u.omits))for(let m of u.omits)d.add(m);}let p=f=>!(d.has(f)||l&&!l.has(f));for(let f of s.picks??[])a.includes(f)?p(f)||n.push({path:`mapDefaults.${e}.enums.${i}.picks`,code:"not_visible",message:`'${f}' not visible from ancestors`}):n.push({path:`mapDefaults.${e}.enums.${i}.picks`,code:"value_not_allowed",message:`'${f}' not a known value`});for(let f of s.omits??[])a.includes(f)?p(f)||n.push({path:`mapDefaults.${e}.enums.${i}.omits`,code:"not_visible",message:`'${f}' already excluded by ancestors`}):n.push({path:`mapDefaults.${e}.enums.${i}.omits`,code:"value_not_allowed",message:`'${f}' not a known value`});}},YO=(e,t,r,o,n,i,s)=>{let a=D(t,r.mapName,r.modelName,r.relPath);for(let l of ["enumPicks","enumOmits"])for(let[d,p]of Object.entries(e[l]??{})){let f=O(o,d);if(f?.kind!=="enum")continue;let u=Ir(f,n)??[],m=ms(a,d)??u;for(let y of p)u.includes(y)&&!m.includes(y)&&s.push({path:`${i}.${l}.${d}`,code:"not_visible",message:`'${y}' is not visible (not allowed by the inherited enum narrowing)`});}},Sc=(e,t,r,o)=>e.map(n=>({mapName:o,modelName:r,relPath:[...n.relPath,t]})),el=(e,t,r,o,n,i,s,a,l,d,p)=>{let f=O(n,i),u=T(f,s);if(!u)return;let m=o.length===0,y={...d,chain:[...d.chain,r],unvetted:true},c=p.isDefault?void 0:O(O(r.mapDefaults,i)?.models,s),w=[...o.map(b=>O(O(b.mapDefaults,i)?.models,s)).filter(b=>b!==void 0),...t],R={mapName:i,modelName:s,relPath:Oa};QO(e,w,c,n,i,u.fields,s,f?.enums,a,l,d,m?p.isDefault?[R,...p.parent]:p.parent:p.composed,p.isDefault),YO(e,p.isDefault?d:{...d,chain:[...d.chain,{parent:r.parent,mapDefaults:r.mapDefaults}],unvetted:true},p.isDefault?R:p.parent[0]??R,u.fields,f?.enums,a,l),HO(e,r,d,p.composed,a,l);let S={...d,chain:[...d.chain,r]};if(!p.isDefault)for(let[b,$]of Object.entries(e.sources??{}))!Fn($)||$.from!=="mapDefaults"||hs(S,i,s,b)||l.push({path:`${a}.sources.${b}`,code:"invalid_source",message:ws([nt(r).model,...p.parent[0]?.relPath??[]].join("."),i,s,b).message});for(let[b,$]of Object.entries(e.relations??{})){let E=O(u.fields,b);if(!E){l.push({path:`${a}.relations`,code:"not_in_lens",message:`'${b}' not on model`});continue}if(!V(E)){l.push({path:`${a}.relations`,code:"wrong_kind",message:`'${b}' is not a relation (kind=${E.kind})`});continue}let I=q=>D(d,q.mapName,q.modelName,q.relPath).relations.has(b),pe=q=>D(y,q.mapName,q.modelName,q.relPath).relations.has(b);if(!m&&!(p.isDefault?p.parent.some(I):p.parent.every(I))){l.push({path:`${a}.relations`,code:"not_visible",message:`'${b}' is not shown by the parent${p.isDefault?` wherever ${s} is visited`:""}: only the first narrowing over the base lens turns a relation on`});continue}let N=Xe(E,i);if(!N)continue;if(!T(O(n,N.mapName),N.modelName)){l.push({path:`${a}.relations.${b}`,code:"not_in_lens",message:"target model not found in lens"});continue}let j=t.map(q=>O(q.relations,b)).filter(q=>q!==void 0);el($,j,r,o,n,N.mapName,N.modelName,`${a}.relations.${b}`,l,d,{parent:Sc(p.isDefault?p.parent.filter(I):p.parent,b,N.modelName,N.mapName),composed:Sc(p.composed.filter(pe),b,N.modelName,N.mapName),isDefault:p.isDefault});}},tl=e=>{let t=[];try{XO(e,t);}catch(r){if(!(r instanceof A))throw r;t.some(o=>o.code===r.code)||t.push({path:"",code:r.code,message:r.message});}return Sr(t)},XO=(e,t)=>{let r=nt(e),o=$t(e.parent),n=M(e.parent),i=zt(n),s=[],a=u=>{try{u();}catch(m){if(!(m instanceof A))throw m;s.push(m);}},l=null,d=()=>(l??=zt({...n,chain:[...n.chain,e],unvetted:true}),l);for(let[u,m]of Object.entries(e.mapDefaults??{})){let y=O(r.maps,u);if(!y){t.push({path:`mapDefaults.${u}`,code:"not_in_lens",message:"not in lens"});continue}let c=o.map(g=>O(g.mapDefaults,u)?.enums).filter(g=>g!==void 0);for(let[g,w]of Object.entries(m.models??{})){if(!T(y,g)){t.push({path:`mapDefaults.${u}.models.${g}`,code:"not_in_lens",message:"not in fieldMap"});continue}let S=o.map(E=>O(O(E.mapDefaults,u)?.models,g)).filter(E=>E!==void 0),b=E=>E.map(({at:I})=>I).filter(I=>I.mapName===u&&I.modelName===g),$=[];a(()=>{$=b(d());}),a(()=>el(w,S,e,o,r.maps,u,g,`mapDefaults.${u}.models.${g}`,t,n,{parent:b(i),composed:$,isDefault:!0}));}m.enums&&ZO(u,m.enums,y.enums,c,t);}if(e.root){let u=r.mapName,m=r.model,y=O(r.maps,u);if(!y)t.push({path:"root",code:"not_in_lens",message:`lens map '${u}' not in lens`});else if(!T(y,m))t.push({path:"root",code:"not_in_lens",message:`lens model '${m}' not in fieldMap`});else {let c=o.map(w=>w.root).filter(w=>w!==void 0),g={mapName:u,modelName:m,relPath:[]};a(()=>el(e.root,c,e,o,r.maps,u,m,"root",t,n,{parent:[g],composed:[g],isDefault:!1}));}}for(let u of Nu(e))t.push({path:"bindings",code:"invalid_binding",message:u});let p={...n,chain:[...n.chain,e],inspect:true},f;a(()=>{f=Or(p,Vn(p));}),a(()=>Xa(p)),a(()=>Qa(p,{},f)),a(()=>{let u=new Map;for(let{at:m}of d()){u.set(m.relPath.join("."),m),a(()=>Wa(p,m.relPath.join(".")));let y=m.relPath.at(-1),c=u.get(m.relPath.slice(0,-1).join("."));if(y===void 0||!c)continue;let w=$e(O(r.maps,c.mapName),c.modelName,y)?.isList?{field:y,arrayOperator:"any",condition:!0}:{field:y,operator:"exists"};a(()=>Kr(w,p,c));}});for(let u of s)t.some(m=>u.message.includes(m.message))||t.push({path:"",code:u.code,message:u.message});},Cs=e=>kn(tl(e),"validateNarrowing");function bc(e,{by:t="path",...r}={}){return t==="model"?hc(e,r):nc(e,r)}var Rc=(e,t,r,o={})=>{let n=M(e),{resolution:i}=Gr(n,Pt(n),r);if(i.outcome!=="resolved")return {ok:false,reason:i.outcome};let{hops:s,terminal:a,jsonSubPath:l}=i;if(V(a.entry))return {ok:false,reason:"relation"};if(s.some(f=>f!==a&&f.entry.isList))return {ok:false,reason:"list"};let d=(f,u)=>u!==null&&typeof u=="object"&&D(n,f.mapName,f.model,f.relPath).whereClauses.every(m=>me(m,u,o)===true),p=d(s[0],t)?t:null;for(let[f,u]of s.entries()){if(p===null||typeof p!="object")return {ok:true,value:null};let m=O(p,u.field);if(u===a)return {ok:true,value:l.length?ue(m,l.join(".")):m};p=d(s[f+1],m)?m:null;}return {ok:true,value:null}};var ex=e=>"maps"in e,Oc=(e,t)=>{let r=i=>{let s=O(t,i);if(!s)throw new Error(`composeLens: no stored lens '${i}'`);return s},o=[...r(e).parents,e];if(new Set(o).size!==o.length)throw new Error(`composeLens: '${e}' lists a layer twice in its parents`);let n=null;for(let[i,s]of o.entries()){let a=r(s);if(Object.hasOwn(a,"parent"))throw new Error(`composeLens: '${s}' carries a parent; a layer composes only through \`parents\``);let{id:l,parents:d,...p}=a;if(d.join("\0")!==o.slice(0,i).join("\0"))throw new Error(`composeLens: '${s}' composes with [${d.join(", ")}], not [${o.slice(0,i).join(", ")}] as '${e}' lists`);if(ex(a)!==(i===0))throw new Error(i===0?`composeLens: '${s}' is not a base lens, so it can't head '${e}''s parents`:`composeLens: '${s}' is a base lens, so it can only head a chain`);if(n===null){n=p;continue}let u={parent:n,...p};Cs(u),n=u;}return n},xc=(e,t)=>{let r=ot(e)?[]:$t(e);if(t.length!==r.length+1)throw new Error(`storeLens: the lens has ${r.length+1} layers, base included, but ${t.length} ids`);return [{...nt(e),id:t[0],parents:[]},...r.map(({parent:o,...n},i)=>({...n,id:t[i+1],parents:t.slice(0,i+1)}))]};var Ec=e=>e instanceof Date?e.toISOString():Array.isArray(e)&&e.some(t=>t instanceof Date)?e.map(Ec):e,_=(e,t)=>(e.params.push(Ec(t)),`$${++e.paramIndex}`);var Ht=(e,t,{jsonb:r=false}={})=>{let o=()=>({sql:ka(e,void 0,r),shape:e.includes(".")?"json-path":"unknown"});if(!t.map||!t.currentModel||!t.currentAlias)return o();let n=te(e,t.map,t.currentModel);if(n.kind==="past-scalar")throw ko(e,n.column);if(n.kind==="bridge")throw new Error(`'${e}' crosses a bridge to another source; toSql() has no column for it`);if(n.kind==="fallback"||n.entry.kind==="object"&&n.entry.isList)return o();let i=n.hops.find(p=>p.entry.isList);if(i)throw To(e,i);let s=t.currentAlias;for(let p of n.hops){let f=$c(t,s,p);if(!f)return o();s=f;}let a=qr(n);if(n.kind==="direct"&&n.entry.kind==="object"){let p={field:n.column,entry:n.entry,from:n.model},f=hr(t.map,n.model,n.entry),u=$c(t,s,p);return !f||!u?o():{sql:`${re(u)}.${re(f[0].there)}`,shape:a}}let l=n.kind==="json-path"?[n.column,...n.jsonPath]:[n.column],d=ka(l.join("."),s,r);return {sql:a==="json"&&!r?`NULLIF(${d}, 'null'::jsonb)`:d,shape:a}},At=(e,t,r)=>Ht(e,t,r).sql,$c=(e,t,r)=>{let o=`${t}.${r.field}`,n=e.joinRegistry?.get(o);if(n)return n;if(!e.joinCounter||!e.map)return null;let i=`t${e.joinCounter.n+1}`,s=tx(e.map,r.from,t,r.entry,i);return s?(e.joinCounter.n+=1,e.joins?.push(s),e.joinRegistry?.set(o,i),i):null},tx=(e,t,r,o,n)=>{let i=o.type,s=T(e,i)?.dbName??i,a=hr(e,t,o);if(!a)return null;let l=a.map(({here:d,there:p})=>`${re(n)}.${re(p)} = ${re(r)}.${re(d)}`).join(" AND ");return `LEFT JOIN ${re(s)} AS ${re(n)} ON ${l}`};var Jt={type:"value",value:null},Tt=e=>e.type==="value"&&(e.value===null||e.value===void 0),rx=(e,t)=>{let r=L(e)??{depth:1,path:e};if(r.depth>1)throw new Error(un(e,"toSql"));let o=Ht(r.path,t);if(o.shape==="relation")throw new Error(`'${e}' is a relation; a value ref reads a column`);return {type:"column",...o}},Re=(e,t)=>xn(e,{value:r=>({type:"value",value:r}),path:r=>rx(r,t),bind:(r,o)=>({type:"value",value:Gi(r,o,"toSql")})}),Hr=e=>t=>{let r=Re(t,e);if(r.type==="column")throw new Error(`'${t.path}' is a row ref`);return r.value},st=e=>Dr(e.dateConfig??{},Hr(e));var ox={lt:"<",lte:"<=",gt:">",gte:">=",equals:"="},rn=(e,t)=>{let r=or(e,t);return r?{symbol:ox[r],negated:B.includes(e)}:void 0},Pc=(e,t)=>e.type==="column"?e.sql:_(t,e.value),Me=(e,t)=>`(${t} OR ${e} IS NULL)`,kt=(e,t,r=true)=>t&&r?`${e} IS NULL`:"FALSE",Ms=(e,t,r,o,n)=>{if(Tt(r))return kt(e,o);let i=`${e} ${t} ${Pc(r,n)}`;return o?Me(e,i):i},Un=(e,t,r,o,n=true)=>{if(!t||t.some(Tt))return kt(e,r,n);let[i,s]=t.map(f=>Pc(f,o)),a=t.some(f=>f.type==="column"),l=a?"SYMMETRIC ":"";if(!r)return `${e} BETWEEN ${l}${i} AND ${s}`;let d=`${e} NOT BETWEEN ${l}${i} AND ${s}`,p=a?`(${d} AND ${i} IS NOT NULL AND ${s} IS NOT NULL)`:d;return n?Me(e,p):p};var Ac=()=>{let e=ze.get("sql.dialect");if(!Ld(e))throw new k(`toWhereSql: sql.dialect '${String(e)}' is not a SQL dialect \u2014 ${Object.values(So).join(", ")} are`);return e},Z=e=>new Error(`toWhereSql: ${e} has no SQL form here \u2014 it writes ${zs.join(", ")}, all and any, and ${Js.join(", ")} over a to-many relation.`),Tc=(e,t)=>rl(e,t,""),vc=(e,t,r,o)=>{let n=Object.hasOwn(e,o)?e[o]:void 0;if(typeof n!="string"||n==="")throw new k(`toWhereSql: no ${r} for '${o}' in \`${t}\``);return n},rl=(e,t,r,o={clamps:()=>[]})=>{Ac();let{columns:n,tables:i={},map:s,mapName:a,model:l}=t??{};if(typeof n!="object"||n===null)throw new k("toWhereSql: `columns` maps each field path to its SQL");if(typeof i!="object"||i===null)throw new k("toWhereSql: `tables` maps each to-many relation path to its table");if(!s||!l)throw new k("toWhereSql: `map` and `model` are required \u2014 a literal is typed by its column, and a date, Json or list value is refused by it");let d=Pe(s,a,"toWhereSql");if(!T(d,l))throw new k(`toWhereSql: the map has no model '${l}'`);return on(e,{map:d,model:l,column:p=>vc(n,"columns","column",`${r}${p}`),table:p=>vc(i,"tables","table",`${r}${p}`),clamps:"clamps"in o?o.clamps:()=>[],joined:"joined"in o?o.joined:null,joinedRow:null})},on=(e,t)=>{if(typeof e=="boolean")return e?"TRUE":"FALSE";let r=e;switch(ne(r)){case "all":{let o=r.all;return o.length?`(${o.map(n=>on(n,t)).join(" AND ")})`:"TRUE"}case "any":{let o=r.any;return o.length?`(${o.map(n=>on(n,t)).join(" OR ")})`:"FALSE"}case "field":return ix(e,t);case "if":throw Z("if / then / else");case "array":return nx(e,t);case "aggregate":throw Z("aggregate");case "date":throw Z(`dateOperator '${String(r.dateOperator)}'`);default:throw Z("a condition that is not exactly one node kind")}},nx=(e,t)=>{let{arrayOperator:r,field:o}=e;if(!Js.includes(r))throw Z(`arrayOperator '${r}'`);if(Ee(e))throw Z(`a window (filter / orderBy / take / skip) on '${o}'`);if(!o)throw Z(`the fieldless arrayOperator '${r}'`);let n=te(o,t.map,t.model);if(n.kind==="fallback")throw new Error(`toWhereSql: '${o}' is not a field the map declares on ${t.model}`);if(n.kind==="bridge")throw Z(`'${o}', which crosses a bridge`);if(n.hops.length)throw Z(`arrayOperator '${r}' on '${o}', behind the relation '${n.hops[0].prefix}'`);if(n.kind!=="direct"||qr(n)!=="relations")throw Z(`arrayOperator '${r}' on '${o}', which is not a to-many relation`);let i=hr(t.map,n.model,n.entry);if(!i)throw Z(`'${o}', whose relation keys the map does not declare`);if(Li.includes(r)&&e.condition===void 0)throw De(r);if(t.joinedRow!==null)throw new Error(`toWhereSql: arrayOperator '${r}' on '${o}' inside an any over the joined '${t.joinedRow}' \u2014 a joined row's own to-many relations have no join here; compile with toMany: 'subquery'`);let s={map:t.map,model:n.entry.type,column:p=>t.column(`${o}.${p}`),table:p=>t.table(`${o}.${p}`),clamps:p=>t.clamps(`${o}.${p}`),joined:t.joined,joinedRow:null};if(t.joined){if(zd.includes(r))throw new Error(`toWhereSql: arrayOperator '${r}' on '${o}', a relation the caller joins, holds when it has no rows \u2014 that takes an anti-join, not the topic's join. Only notEmpty and any(condition) read a joined relation; compile with toMany: 'subquery' for the rest`);t.joined(o,r);let p=`${s.column(i[0].there)} IS NOT NULL`;return r!==x.any?p:`(${p} AND ${on(e.condition,{...s,joinedRow:o})})`}let a=[...i.map(({here:p,there:f})=>`${s.column(f)} = ${t.column(p)}`),...t.clamps(o).map(({where:p,clamps:f})=>`(${on(p,{...s,clamps:f})})`)],l=p=>`(SELECT 1 FROM ${t.table(o)} WHERE ${[...a,...p?[p]:[]].join(" AND ")})`,d=()=>`(${on(e.condition,s)})`;switch(r){case x.any:return `EXISTS ${l(d())}`;case x.none:return `NOT EXISTS ${l(d())}`;case x.all:return `NOT EXISTS ${l(`${d()} IS NOT TRUE`)}`;case x.empty:return `NOT EXISTS ${l()}`;default:return `EXISTS ${l()}`}},ix=(e,t)=>{if(!zs.includes(e.operator))throw Z(`operator '${e.operator}'`);if(e.bind!==void 0)throw Z(`bind '${e.bind}' on '${e.field}'`);if(e.path!==void 0)throw Z(`comparing '${e.field}' with the column '${e.path}'`);if(e.offset!==void 0)throw Z(`an offset on '${e.field}'`);if(e.coerceType!==void 0)throw Z(`coerceType on '${e.field}'`);if(se(e.caseInsensitive))throw Z(`a case-insensitive comparison on '${e.field}'`);if(L(e.field))throw Z(`the scoped field '${e.field}'`);let r=te(e.field,t.map,t.model),o=sx(e,r,t),[n]=r.kind==="direct"?us(e,et(r.entry)):[];if(n)throw new Error(`toWhereSql: ${n.message}`);if(e.operator===h.exists)return `${o} IS NOT NULL`;if(e.operator===h.notExists)return `${o} IS NULL`;if(e.value===void 0)throw new Error("No value, path or bind specified");let i=Zo(e,e.value,r,"toWhereSql",()=>Ze);if(Se(e,i))return kt(o,B.includes(e.operator));let s=a=>ax(a,e.field);switch(e.operator){case h.equals:return i===null?`${o} IS NULL`:`${o} = ${s(i)}`;case h.notEquals:return i===null?`${o} IS NOT NULL`:Me(o,`${o} <> ${s(i)}`);case h.in:{let{values:a,hasNull:l}=We(Nc(e,i));if(!a.length)return l?`${o} IS NULL`:"FALSE";let d=`${o} IN (${a.map(s).join(", ")})`;return l?Me(o,d):d}default:{let{values:a,hasNull:l}=We(Nc(e,i));if(!a.length)return l?`${o} IS NOT NULL`:"TRUE";let d=`${o} NOT IN (${a.map(s).join(", ")})`;return l?`(${d} AND ${o} IS NOT NULL)`:Me(o,d)}}},sx=(e,t,r)=>{if(t.kind==="fallback")throw new Error(`toWhereSql: '${e.field}' is not a field the map declares on ${r.model}`);if(t.kind==="past-scalar")throw ko(e.field,t.column);if(t.kind==="bridge")throw Z(`'${e.field}', which crosses a bridge`);let o=t.hops.find(s=>s.entry.isList);if(o)throw To(e.field,o);let n=qr(t),i=Ut(e);if(r.joinedRow!==null&&(t.hops.length||n==="relation"))throw new Error(`toWhereSql: '${e.field}' inside an any over the joined '${r.joinedRow}' reads the relation '${t.hops[0]?.prefix??e.field}' \u2014 a joined row's own relations have no join here; compile with toMany: 'subquery'`);if(n==="relation"&&t.kind==="direct"){if(!i)throw sr(e.field);let s=hr(r.map,t.model,t.entry);if(!s)throw Z(`'${e.field}', whose relation keys the map does not declare`);return r.column(`${e.field}.${s[0].there}`)}if(n==="relations")throw new Error(`toWhereSql: '${e.field}' is a to-many relation \u2014 its rows take an arrayOperator rule: { field: '${e.field}', arrayOperator: 'notEmpty' } for a row${r.joined?"; for no rows, compile with toMany: 'subquery'":", 'empty' for none"}`);if(n==="json"||n==="json-path")throw Z(`the Json value '${e.field}'`);if(i)return r.column(e.field);if(n==="instant")throw Z(`the date '${e.field}'`);if(n==="list")throw Z(`the list '${e.field}'`);return r.column(e.field)},Nc=(e,t)=>{if(!Array.isArray(t))throw new Error(`toWhereSql: '${e.operator}' on '${e.field}' takes a list of values`);return t},ax=(e,t)=>{if(typeof e=="string"){let r=e.replace(/'/g,"''");return `'${Ac()===So.mysql?r.replace(/\\/g,"\\\\"):r}'`}if(typeof e=="number"&&Number.isFinite(e)||typeof e=="bigint")return String(e);if(typeof e=="boolean")return e?"TRUE":"FALSE";throw Z(`the value ${e instanceof Date?"a Date":JSON.stringify(e)} for '${t}'`)};var lx=(e,t,r)=>{H(r,(o,n)=>{if(typeof o.field!="string")return;let i=jn(e,n,o.field);if(i!==null)throw new Error(`toLensWhereSql: '${o.field}' at ${n.relPath.length?`'${n.relPath.join(".")}'`:"the root"} crosses '${i}', a relation the lens hides \u2014 a hop's clamps are reported at its own path, so a where may only cross hops the lens shows`);return Te(o)?ve(e.lens.maps,n,o.field).end??false:void 0},t);},Mc=(e,t,r)=>{let{end:o}=ve(e.lens.maps,t,r);if(!o)return null;let{pathWheres:n,modelWheres:i}=D(e,o.mapName,o.modelName,o.relPath);return {end:o,clamps:[...n.map(s=>({...s,isDefault:false})),...i.map(s=>({...s,isDefault:true}))]}},Lc=(e,t,r)=>o=>{let n=Mc(e,t,o);return n?n.clamps.filter(i=>i.layer<r).map(i=>({where:i.where,clamps:Lc(e,n.end,i.layer)})):[]},kc=(e,t,r,o)=>{let n=e.map(({where:i,layer:s})=>rl(i,t,r,o(s)));return n.length===1?n[0]:`(${n.join(" AND ")})`},px=(e,t)=>{let r=new Set,o=new Map;return n=>({joined:(i,s)=>{let a=Mc(e,t,i);if(!a)throw new Error(`toLensWhereSql: '${i}' reaches no relation`);let{end:l,clamps:d}=a,p=d.find(f=>f.layer>=n);if(p)throw new Error(`toLensWhereSql: the root where of layer ${n+1} reads '${i}' on the caller's join, whose ON carries a clamp of layer ${p.layer+1} (${p.isDefault?`${l.modelName}'s default where`:"its where"}) \u2014 check() reads a where through the clamps of the layers above its own only. Move that clamp into a narrowing above layer ${n+1}, or compile with toMany: 'subquery'`);if(d.some(f=>f.isDefault)){let f=`${l.mapName}.${l.modelName}`,u=o.get(f),m=l.mapName===t.mapName&&l.modelName===t.modelName?`the root is a ${l.modelName} too`:u!==void 0&&u!==i?`the root where also reads '${u}', which reaches ${l.modelName} too`:null;if(m!==null)throw new Error(`toLensWhereSql: the root where reads '${i}' on the caller's join, and ${l.modelName} has a default where, but ${m} \u2014 mapDefaults holds one predicate per model, which reads one table alias, and two aliases need it. Compile with toMany: 'subquery'`);o.set(f,i);}if(s===x.any){if(r.has(i))throw new Error(`toLensWhereSql: the root reads '${i}' with two any rules \u2014 on the caller's join one joined row stands for the relation, so both conditions would have to hold on the same row, where check() lets each find its own. Write one any whose condition says which row, or compile with toMany: 'subquery'`);r.add(i);}}})},Cc=(e,t)=>()=>({joined:r=>{throw new Error(`toLensWhereSql: ${e} reads the to-many relation '${r}' \u2014 with toMany: 'join' ${t}; only the root's where reads a joined relation`)}}),_c=(e,{columns:t,tables:r,toMany:o="subquery"})=>{if(o!=="subquery"&&o!=="join")throw new k(`toLensWhereSql: toMany '${String(o)}' is neither 'subquery' nor 'join'`);let n=M(e),i={root:null,relations:{},mapDefaults:{}};for(let{at:s,effect:a}of zt(n)){let l={columns:t,tables:r,map:n.lens,mapName:s.mapName,model:s.modelName},d=p=>({clamps:Lc(n,s,p)});for(let{where:p}of [...a.pathWheres,...a.modelWheres])lx(n,s,p);if(a.pathWheres.length){let p=s.relPath.join("."),f=o==="subquery"?d:p?Cc(`the where at '${p}'`,"it sits in that relation's join ON, ahead of the joins below it"):px(n,s),u=kc(a.pathWheres,l,p?`${p}.`:"",f);p?i.relations[p]=u:i.root=u;}if(a.modelWheres.length){let p=Kt(i.mapDefaults,s.mapName,()=>({models:{}})),f=o==="subquery"?d:Cc(`the default where of ${s.modelName}`,`it compiles once for every path that reaches ${s.modelName}, and the join exists only where the lens shows the relation`),u=kc(a.modelWheres,l,`${s.modelName}.`,f),m=O(p.models,s.modelName);if(m!==void 0&&m!==u)throw new Error(`toLensWhereSql: the default where of ${s.modelName} reads a to-many relation whose clamps differ between the paths that reach ${s.modelName} \u2014 a model default compiles to one predicate for every path`);p.models[s.modelName]=u;}}return i};var Dc=e=>Array.isArray(e)?e.some(Dc):typeof e=="object"&&e!==null,Fc=(e,t,r,o)=>{let n=`NULLIF(${t}, 'null'::jsonb)`,i=`jsonb_typeof(${n})`,s=`(${n} #>> '{}')`,a=S=>`${_(o,JSON.stringify(S))}::jsonb`,l=se(e.caseInsensitive),d=S=>l?`LOWER(${S})`:S,p=B.includes(e.operator),f=S=>Me(n,`NOT (${S})`);if(Se(e,r))return kt(n,p);let u=Wi(e.operator,r);if(u)throw u;let m=S=>{if(Dc(S))throw F("toSql",`A case-insensitive comparison of '${e.field}' with a list holding objects`);return a(jr(S))},y=S=>l&&typeof S=="string"?`(${i} = 'string' AND LOWER(${s}) = LOWER(${_(o,S)}))`:l&&Array.isArray(S)?`(${i} = 'array' AND LOWER(${n}::text)::jsonb = ${m(S)})`:`${n} = ${a(S)}`,c=S=>`(${i} = 'string' AND ${d(s)} LIKE ${d(_(o,S))})`,g=S=>{let b=$=>`(CASE WHEN ${i} = 'array' THEN EXISTS (SELECT 1 FROM jsonb_array_elements(${n}) AS e WHERE ${$}) ELSE FALSE END)`;return l&&typeof S=="string"?b(`jsonb_typeof(e) = 'string' AND LOWER(e #>> '{}') = LOWER(${_(o,S)})`):l&&Array.isArray(S)?b(`LOWER(e::text)::jsonb = ${m(S)}`):typeof S=="object"&&S!==null?b(`e = ${a(S)}`):`(${i} = 'array' AND ${n} @> ${a([S])})`},w=S=>typeof S=="string"?`(${c(`%${be(S)}%`)} OR ${g(S)})`:g(S);switch(e.operator){case h.equals:return r===null?`${n} IS NULL`:y(r);case h.notEquals:return r===null?`${n} IS NOT NULL`:f(y(r));case h.in:case h.notIn:{let{values:S,hasNull:b}=We(r),$=S.length?`(${S.map(y).join(" OR ")})`:"FALSE";return e.operator===h.in?b?`(${$} OR ${n} IS NULL)`:$:b?`(NOT ${$} AND ${n} IS NOT NULL)`:f($)}case h.between:case h.notBetween:{let[S,b]=r,$=`(${i} = jsonb_typeof(${a(S)}) AND ${n} BETWEEN ${a(S)} AND ${a(b)})`;return e.operator===h.between?$:f($)}case h.contains:return w(r);case h.notContains:return f(w(r));case h.startsWith:return c(`${be(String(r))}%`);case h.endsWith:return c(`%${be(String(r))}`);case h.notStartsWith:return f(c(`${be(String(r))}%`));case h.notEndsWith:return f(c(`%${be(String(r))}`));case h.matches:case h.notMatches:{let{source:S,caseInsensitive:b}=ur(r),$=`(${i} = 'string' AND ${s} ~${b?"*":""} ${_(o,vn(S))})`;return e.operator===h.matches?$:f($)}}let R=rn(e.operator,"field")?.symbol;if(R)return `(${i} = jsonb_typeof(${a(r)}) AND ${n} ${R} ${a(r)})`;throw new Error(`Operator '${e.operator}' is not supported on a Json value in SQL`)};var jc=e=>typeof e=="object"&&kr(e)!==null,Kn=({sql:e,shape:t},r)=>{if(t!=="json-path"&&t!=="text")return `to_timestamp(EXTRACT(EPOCH FROM ${e}))`;let o=_(r,st(r).timeZone);return `(CASE WHEN btrim(${e}) ~ '^-?[0-9]+(\\.[0-9]+)?$' THEN to_timestamp(btrim(${e})::numeric / 1000) WHEN ${e} ~* '[0-9]{2}:[0-9]{2}(:[0-9]{2}(\\.[0-9]+)?)?\\s*(z|[+-][0-9]{2}(:?[0-9]{2})?)\\s*$' OR ${e} ~* '\\m(gmt|utc)\\M' THEN (${e})::timestamptz ELSE (${e})::timestamp AT TIME ZONE ${o} END)`},Ls=e=>Object.values(e).some(jc),fx=(e,t,r)=>{let o=Ar(r),n=o?"int":"double precision";if(typeof e=="number"||!jc(e)){let a=aa(e,Hr(t),r);return `${_(t,a)}::${n}`}let i=Re(e,t).sql;return `(CASE WHEN ${o?`${i} >= 0 AND ${i} = trunc(${i})`:`${i} >= 0`} THEN ${i} END)::${n}`},ux=(e,t)=>`make_interval(${tf.flatMap(o=>{let n=Object.keys(e).filter(i=>e[i]!==void 0&&Je[i].interval===o).map(i=>{let s=fx(e[i],t,i),{factor:a}=Je[i];return a===1?s:`${a} * ${s}`});return n.length?[`${o} => ${n.join(" + ")}`]:[]}).join(", ")})`,Gn=(e,t,r,o)=>{let n=st(o).timeZone;if(e.type==="value"&&!Ls(t)){let l=Mr(t,Hr(o));return e.value===null||e.value===void 0||l===null?Jt:{type:"value",value:lr(Rt(e.value),l,r,n).toDate()}}let i=e.type==="column"?e.computed?e.sql:Kn(e,o):`${_(o,e.value??null)}::timestamptz`,s=_(o,n);return {type:"column",computed:true,sql:`(((${i} AT TIME ZONE ${s}) ${r===1?"+":"-"} ${ux(t,o)}) AT TIME ZONE ${s})`}};var ol=(e,t,r)=>{let o=Re(t,r);if(e.type==="value"&&o.type==="value"){let i=_r(o.value);return i===null?Jt:{type:"value",value:Lr(e.value,i)}}let n=(i,s)=>i.type==="column"?`(${i.sql})::double precision`:`${_(r,s(i.value)??null)}::double precision`;return {type:"column",computed:true,sql:`(${n(e,i=>i)} + ${n(o,_r)})`}},Ic=(e,t,r)=>{if(Tt(e))return Jt;let o=Re(t,r);if(o.type==="column")throw new Error(`A row path on a date offset ('${t.path}') is check-only; evaluate with check()`);let n=jo(o.value);return n===null?Jt:Gn(e,...n,r)};var qc,Vc=e=>{qc=e;},xr=(e,t)=>qc(e,t);var Ds=(e,t,r)=>{let o=Bi(e);if(o)throw o;let n=r===void 0?Ht(e.field,t):{sql:r,shape:"scalar"};if(n.shape==="relation"&&!Ut(e))throw sr(e.field);let i=r===void 0,s=xe(e)&&t.map&&t.currentModel?(L(e.path)??{path:e.path}).path:null;if(s!==null){let b=Bo(X(e.field,t.map,t.currentModel),X(s,t.map,t.currentModel),e.operator);if(b)throw F("toSql",`Comparing '${e.field}' with the column '${e.path}'`,b)}if(n.shape==="enum"&&!nr.includes(e.operator)){let b=Wc(e,t),$=X(e.field,t.map,t.currentModel),E=b!==_s&&$&&!Se(e,b)?bs(e,b,$,t.map):null;if(E){let I=`${n.sql}::text = ANY(${_(t,E.values)})`;return E.matchesNull?Me(n.sql,I):I}}let a=n.shape==="enum"&&!nr.includes(e.operator)&&s===null?{...n,sql:`${n.sql}::text`}:n;if((n.shape==="json"||n.shape==="json-path")&&!nr.includes(e.operator)){let b=Wc(e,t);if(b===_s)throw new Error(`The Json value '${e.field}' compares against an operand known when compiling, not one read per row.`);return Fc(e,At(e.field,t,{jsonb:true}),b,t)}let d=b=>{if(b.type==="column"&&!b.computed&&(b.shape==="json"||b.shape==="json-path"))throw F("toSql",`'${e.field}' compared with a Json value read per row`,"SQL would compare its text")};if(Ve.includes(e.operator)){let b=Gc(e,t);return b?.forEach(d),Un(a.sql,b,B.includes(e.operator),t,i)}let p=Uc(e,t);if(d(p),p.type==="column"&&qt(e.operator,"field")==="string"&&!Vr(n.shape)&&n.shape!=="list")throw F("toSql",`'${e.operator}' on '${e.field}'`,"it is not text");if(p.type==="column"&&p.computed&&n.shape==="text"&&r===void 0)throw F("toSql",`'${e.field}' against a value moved by an offset`,"an offset moves a number or a date");let f=a.sql,u=rn(e.operator,"field");if(u)return Ms(f,u.symbol,p,false,t);if(p.type==="value"&&Se(e,p.value))return kt(f,B.includes(e.operator),i);let m=p.type==="column"&&p.computed===true,y=se(e.caseInsensitive)&&(p.type==="column"?!m&&Vr(n.shape)&&Vr(p.shape):yr(n.shape,p.value)),c=b=>y?`LOWER(${b})`:b,g=b=>y?jr(b):b;if(n.shape==="list"&&p.type==="column"&>.includes(e.operator)){if(X(e.field,t.map,t.currentModel)?.type!=="String"||!Vr(p.shape))throw F("toSql",`'${e.operator}' on the list '${e.field}' with a member read per row ('${e.path}')`,"Postgres matches a member of the list's own type only");let b=se(e.caseInsensitive)&&Vr(p.shape)?`EXISTS (SELECT 1 FROM unnest(${f}) AS e WHERE LOWER(e) = LOWER(${p.sql}))`:`array_position(${f}, ${p.sql}) IS NOT NULL`;return e.operator===h.contains?`(${p.sql} IS NOT NULL AND ${b})`:`(${f} IS NULL OR (${p.sql} IS NOT NULL AND NOT ${b}))`}if(n.shape==="list"&&p.type==="value"){let b=se(e.caseInsensitive)&&yr("text",p.value);if(gt.includes(e.operator)){let $=_(t,p.value),E=b?`EXISTS (SELECT 1 FROM unnest(${f}) AS e WHERE LOWER(e) = LOWER(${$}))`:`array_position(${f}, ${$}) IS NOT NULL`;return e.operator===h.contains?E:`NOT ${E}`}if(ir.includes(e.operator)&&Array.isArray(p.value))return xr(Yi(e,p.value),t);if(cx(e.operator))throw new Error(`'${e.operator}' does not apply to the list '${e.field}'; test its members with contains.`);if(b&&ht.includes(e.operator)&&Array.isArray(p.value)){let $=_(t,jr(p.value)),E=`(${f} IS NOT NULL AND ARRAY(SELECT LOWER(e) FROM unnest(${f}) AS e) = ${$})`;return e.operator===h.equals?E:Me(f,`NOT ${E}`)}}let w=p.type==="value"?p.value:void 0,R=p.type==="column"?p.sql:void 0;if(R!==void 0&&(ir.includes(e.operator)||["pattern","string"].includes(qt(e.operator,"field"))))throw F("toSql",`'${e.operator}' against an operand read per row ('${e.path}')`);let S=b=>i?Me(f,b):b;switch(e.operator){case h.equals:return m?`${f} = ${R}`:R!==void 0?`${c(f)} IS NOT DISTINCT FROM ${c(R)}`:w===null?`${f} IS NULL`:`${c(f)} = ${c(_(t,w))}`;case h.notEquals:return m?S(`${f} <> ${R}`):R!==void 0?`${c(f)} IS DISTINCT FROM ${c(R)}`:w===null?`${f} IS NOT NULL`:S(`${c(f)} <> ${c(_(t,w))}`);case h.in:{let{values:b,hasNull:$}=We(w);if(!b.length)return $?`${f} IS NULL`:"FALSE";let E=`${c(f)} = ANY(${_(t,g(b))})`;return $?S(E):E}case h.notIn:{let{values:b,hasNull:$}=We(w);if(!b.length)return $?`${f} IS NOT NULL`:"TRUE";let E=`${c(f)} <> ALL(${_(t,g(b))})`;return $?`(${E} AND ${f} IS NOT NULL)`:S(E)}case h.contains:return `${c(f)} LIKE ${c(_(t,`%${be(String(w))}%`))}`;case h.notContains:return S(`${c(f)} NOT LIKE ${c(_(t,`%${be(String(w))}%`))}`);case h.startsWith:return `${c(f)} LIKE ${c(_(t,`${be(String(w))}%`))}`;case h.endsWith:return `${c(f)} LIKE ${c(_(t,`%${be(String(w))}`))}`;case h.notStartsWith:return S(`${c(f)} NOT LIKE ${c(_(t,`${be(String(w))}%`))}`);case h.notEndsWith:return S(`${c(f)} NOT LIKE ${c(_(t,`%${be(String(w))}`))}`);case h.matches:return Bc(f,w,false,t);case h.notMatches:return S(Bc(f,w,true,t));case h.isEmpty:case h.notEmpty:return nl(e.field,n,e.operator===h.isEmpty,t,ts(e,t.map,t.currentModel));case h.exists:return `${f} IS NOT NULL`;case h.notExists:return `${f} IS NULL`;default:throw new Error(`Unknown operator: ${e.operator}`)}},Uc=(e,t)=>{if(nr.includes(e.operator))return {type:"value",value:void 0};let r=Kc(e,Re(e,t),t);return e.offset===void 0?r:ol(r,e.offset,t)},Kc=(e,t,r)=>t.type==="column"?t:{type:"value",value:Zo(e,t.value,mr(e.field,r.map,r.currentModel),"toSql",()=>st(r).timeZone)},Gc=(e,t)=>{let r=Kc(e,Re(e,t),t),o=r.type==="value"?r.value:void 0;if(o==null)return null;let n=Ye(o,e.operator);return n.some(i=>i!=null&&!ce(i))&&Fo(o,e.operator),Be(n).map(i=>{let s={type:"value",value:i};return e.offset===void 0?s:ol(s,e.offset,t)})},Bc=(e,t,r,o)=>{if(typeof t!="string"&&!(t instanceof RegExp))throw new Error("matches requires a string or RegExp pattern");let{source:n,caseInsensitive:i}=ur(t);return `${e} ${r?"!":""}~${i?"*":""} ${_(o,vn(n))}`},_s=Symbol("not known"),Wc=(e,t)=>{if(Ve.includes(e.operator)){let o=Gc(e,t);return o?o.every(n=>n.type==="value")?o.map(n=>n.value):_s:null}let r=Uc(e,t);return r.type==="value"?r.value:_s},nl=(e,t,r,o,n)=>{let{sql:i,shape:s}=t;if(s==="list")return r?`(${i} IS NULL OR cardinality(${i}) = 0)`:`cardinality(${i}) > 0`;if(s==="json"||s==="json-path"){let a=At(e,o,{jsonb:true}),l=["'null'::jsonb",...n?[`'""'::jsonb`]:[],"'[]'::jsonb"].join(", ");return r?`(${a} IS NULL OR ${a} IN (${l}))`:`${a} NOT IN (${l})`}return n?r?`(${i} IS NULL OR ${i} = '')`:`(${i} IS NOT NULL AND ${i} <> '')`:r?`${i} IS NULL`:`${i} IS NOT NULL`},cx=e=>qt(e,"field")==="string"&&!gt.includes(e);var zc=(e,t)=>{if(Ee(e))throw St("toSql");if(e.condition)throw new Error("Aggregate condition filtering is not yet supported by toSql(). Use check() for in-memory evaluation or toPrisma() for database queries.");let r=mx(e,t);return Ds(e,t,r)},mx=(e,t)=>{let{mode:r,field:o}=e.aggregate;if(!yt.includes(r))throw ar(r);let n=r==="sum"?"SUM":"AVG",i=Ie({field:e.field},t.map,t.currentModel);if(i==="relation"||X(e.field,t.map,t.currentModel)?.kind==="object")throw new Error(`Field '${e.field}' is a relation \u2014 toSql() cannot aggregate relation lists. Use toPrisma() instead.`);if(o?.includes("."))throw new Error(`aggregate.field '${o}' contains a nested path \u2014 toSql() only supports flat field names. Use check() for nested paths.`);let s=i==="list",a=At(e.field,t,{jsonb:!s}),l=s?a:`(CASE WHEN jsonb_typeof(${a}) = 'array' THEN ${a} END)`;if(s){if(o)throw new Error("aggregate.field is not supported for native array types. Use a JSONB column for object arrays.");return `(SELECT ${`COALESCE(${n}(elem), 0)`} FROM unnest(${l}) AS elem)`}if(o){let f=`(elem->>${Ca(o)})::numeric`;return `(SELECT ${`COALESCE(${n}(${f}), 0)`} FROM jsonb_array_elements(${l}) AS elem)`}return `(SELECT ${`COALESCE(${n}(elem::numeric), 0)`} FROM jsonb_array_elements_text(${l}) AS elem)`};var Hc=(e,t)=>{if(Ee(e))throw St("toSql");if(!e.field)throw qi("toSql");if(Ie({field:e.field},t.map,t.currentModel)==="relation"||X(e.field,t.map,t.currentModel)?.kind==="object")throw new Error(`Field '${e.field}' is a relation \u2014 relation arrays are not supported in SQL; use toPrisma().`);switch(e.arrayOperator){case x.empty:case x.notEmpty:{let o=Ht(e.field,t),n=e.arrayOperator===x.empty;if(o.shape==="list")return nl(e.field,o,n,t,false);let i=At(e.field,t,{jsonb:true});return `(CASE WHEN jsonb_typeof(${i}) = 'array' THEN jsonb_array_length(${i}) ${n?"=":">"} 0 ELSE ${n?"TRUE":"FALSE"} END)`}case x.all:case x.any:case x.none:case x.atLeast:case x.atMost:case x.exactly:throw new Error(`Array operator '${e.arrayOperator}' with conditions is not supported in SQL. Use application-level filtering for complex array operations.`);default:throw le(e.arrayOperator,"array")}};var gx=(e,t)=>e.type==="column"&&!e.computed?{type:"column",sql:Kn(e,t),computed:true}:e,Jc=e=>e===void 0||e==="instant"||e==="text"||e==="json-path"||e==="unknown",Qc=e=>F("toSql",`A date rule on '${e}'`,"it is not a date column"),Zc=(e,t,r)=>{let o=t.some(i=>i.type==="column"),n=e.shape==="json-path"||e.shape==="text";return o||n?{lhs:Kn(e,r),ends:t.map(i=>gx(i,r))}:{lhs:e.sql,ends:t}},Yc=(e,t)=>{let r=Ht(e.field,t);if(!Jc(r.shape))throw Qc(e.field);let o=Re(e,t);if(o.type==="column"&&!Jc(o.shape))throw Qc(String(e.path??e.field));if(!Tt(o)){let s=e.offset===void 0?void 0:Re(e.offset,t),a=Wt(o.type==="value"?o.value:void 0,s?.type==="value"?s.value:void 0);if(a)throw a}let n=rn(e.dateOperator,"date");if(n){let{lhs:s,ends:a}=Zc(r,[hx(e,t)],t);return Ms(s,n.symbol,a[0],n.negated,t)}let i=(s,a)=>{if(!s)return Un(r.sql,null,a,t);let{lhs:l,ends:d}=Zc(r,s,t);return Un(l,d,a,t)};switch(e.dateOperator){case v.within:case v.notWithin:return i(wx(e,t),B.includes(e.dateOperator));case v.between:case v.notBetween:return i(Sx(e,t),B.includes(e.dateOperator));case v.dayIn:case v.dayNotIn:{let s=e.dateOperator===v.dayNotIn,a=Re(e,t);if(a.type==="column")throw F("toSql",`A weekday list read from the row ('${e.path}')`);let l=pa(a.value);if(l===null)return kt(r.sql,s);let d=_(t,st(t).timeZone),p=_(t,l),f=`EXTRACT(DOW FROM (${Kn(r,t)} AT TIME ZONE ${d}))`;return e.dateOperator===v.dayIn?`${f} = ANY(${p})`:Me(r.sql,`${f} <> ALL(${p})`)}default:throw le(e.dateOperator,"date")}},Xc=e=>({type:"value",value:bn(st(e)).toDate()}),yx=(e,t,r)=>{let o=we(e);if(o&&Ls(o[0]))return Gn(Xc(r),...o,r);let n=bt(e,Hr(r));return n===null?Jt:{type:"value",value:Mo(n,t,st(r)).toDate()}},em=(e,t,r)=>e==null?Jt:Y(e)?yx(e,t,r):{type:"value",value:Qi(e,st(r).timeZone)},tm=(e,t,r)=>t.offset===void 0?e:Ic(e,t.offset,r),hx=(e,t)=>{let r=Re(e,t),o=r.type==="column"?r:em(r.value,e.dateOperator,t);return tm(o,e,t)},wx=(e,t)=>{let r=Re(e,t);if(Tt(r))return null;if(r.type==="column"||!Y(r.value))throw Qe(e.dateOperator);let o=we(r.value);if(o&&Ls(o[0])){let s=Xc(t),a=Gn(s,...o,t);return o[1]===-1?[a,s]:[s,a]}let n=bt(r.value,Hr(t));if(n===null)return null;let i=Lo(n,st(t));return [{type:"value",value:i[0].toDate()},{type:"value",value:i[1].toDate()}]},Sx=(e,t)=>{let r=Re(e,t);if(Tt(r))return null;let o=r.type==="value"?r.value:void 0,n=Ye(o,e.dateOperator).map(l=>em(l,e.dateOperator,t));if(n.some(Tt))return null;let[i,s]=n;return (i.type==="value"&&s.type==="value"?Be([i.value,s.value]).map(l=>({type:"value",value:l})):n).map(l=>tm(l,e,t))};var rm=(e,t)=>e.all.length===0?"TRUE":`(${e.all.map(o=>xr(o,t)).join(" AND ")})`,om=(e,t)=>e.any.length===0?"FALSE":`(${e.any.map(o=>xr(o,t)).join(" OR ")})`,nm=(e,t)=>{if(xt(e,t.map,t.currentModel))return "TRUE";let r=xr(e.if,t),o=xr(e.then,t);if(e.else!==void 0){let n=xr(e.else,t);return `(((${r}) IS NOT TRUE OR ${o}) AND ((${r}) IS TRUE OR ${n}))`}return `((${r}) IS NOT TRUE OR ${o})`};var zn=(e,t)=>{if(typeof e=="boolean")return e?"TRUE":"FALSE";if(Pi(e,"toSql"),"field"in e&&typeof e.field=="string"&&t.map&&t.currentModel&&gr(e.field,t.map,t.currentModel))return "TRUE";let r=ne(e);(r==="field"||r==="date")&&rs(e.field,t.map,t.currentModel);let o=e;switch(r){case "all":return rm(o,t);case "any":return om(o,t);case "if":return nm(o,t);case "array":return Hc(o,t);case "aggregate":return zc(o,t);case "date":return Yc(o,t);case "field":return Ds(o,t);default:throw wt()}};Vc(zn);var il=e=>{let t=Pe(e?.map,e?.mapName,"toSql"),r=!!(t&&e?.model),o=e?.alias??(r?"t0":void 0);return {params:[],paramIndex:0,dateConfig:{now:e?.now,timeZone:e?.timeZone,weekStart:e?.weekStart},map:t,currentModel:e?.model,currentAlias:o,joinCounter:r?{n:0}:void 0,joins:r?[]:void 0,joinRegistry:r?new Map:void 0}},bx=(e,t)=>Ss(e,t,"toSql",Rx),Rx=(e,t)=>{let r=il(t);return {sql:zn(e,r),params:r.params,joins:r.joins??[]}};var im=(e,t)=>{let[r,...o]=t,n=e[r];if(o.length===0){n===void 0&&(e[r]=true);return}let i=n!==void 0&&n!==true?n.select:{};im(i,o),e[r]={select:i};},Ox=(e,t,r,o,n,i,s,a,l,d)=>{let p=Es(`source '${n}' at '${t}'`,()=>qn(a,{...l,map:e,mapName:r,model:o})),f=p.steps.at(-1),u=f.where,m=p.steps.length>1||(f.refs?.length??0)>0,y=Pe(e,r,"toPrisma"),c=N=>d!==void 0&&te(N,y,o).kind==="bridge",g=i!==void 0&&!c(i)?i:void 0,w=(s??[]).map(N=>c(N)?void 0:N),R=N=>{let j=te(N,y,o);return j.kind==="json-path"?N.split(".").slice(0,j.stopIndex).join("."):N},S=d===void 0?[]:As(e,r,o,[...Ge(d),...i!==void 0&&g===void 0?[i]:[],...(s??[]).filter(c)].map(R)).filter(N=>N!==n),b=g?.includes(".")?g:void 0,$=[...w.filter(N=>N!==void 0),...b?[b]:[],...S],E={[n]:true,...g&&!b?{[g]:true}:{}};for(let N of $)im(E,N.split("."));let I={model:o,...s||b||d!==void 0?{}:{distinct:g?[n,g]:[n]},select:E,where:u,...m?{steps:p.steps}:{}},pe;try{for(let he of S){let Ne=te(he,y,o);if(!(Ne.kind==="direct"&&!Ne.hops.length&&Ne.entry.kind!=="object"))throw new Error(Ne.kind==="direct"?`the re-check reads '${he}' through a relation, which flat SQL rows can't hold \u2014 run the Prisma query`:`the re-check reads '${he}', which is not a column of ${o} \u2014 run the Prisma query`)}let N=il({...l,map:e,mapName:r,model:o,alias:"t0"}),j=zn(a,N),q=b?At(b,N):void 0,Er=w.map((he,Ne)=>he===void 0?void 0:`${At(he,N)} AS ${re(`__group_${Ne}`)}`),nn=N.joins??[],$r=nn.length?` ${nn.join(" ")}`:"",de=j?.trim()?` WHERE ${j}`:"",at=re("t0"),Jr=[`${at}.${re(n)}`,...q?[`${q} AS ${re("__label")}`]:g?[`${at}.${re(g)}`]:[],...Er.filter(he=>he!==void 0),...S.map(he=>`${at}.${re(he)}`)].join(", "),ee=T(O(e.maps,r),o)?.dbName??o;pe={sql:`SELECT DISTINCT ${Jr} FROM ${re(ee)} AS ${at}${$r}${de}`,params:N.params};}catch(N){pe={sql:null,params:[],error:N instanceof Error?N.message:String(N)};}return {prisma:I,sql:pe}},sm=(e,t={})=>{let{lens:r}=M(e);return ac(e).map(({path:o,visit:n,field:i,label:s,groupBy:a,where:l,recheck:d})=>{let p=l,{prisma:f,sql:u}=Ox(r,o,n.mapName,n.model,i,s,a,p,t,d);return {path:o,mapName:n.mapName,model:n.model,field:i,...s!==void 0?{label:s}:{},...a!==void 0?{groupBy:a}:{},composedWhere:p,prisma:f,sql:u,...d!==void 0?{recheck:d}:{}}})};var am=(e,t)=>{let r=M(e);return Gr(r,Pt(r),t).resolution};/*! Bundled license information:
|
|
3
|
+
`)}`)},zo=(e,t={})=>{let r={target:t.target??"check",errors:[],map:ve(t.map,t.mapName,"toPrisma"),scopeModels:[t.model],stepScopes:[false]};return Gt(e,"$",r,1),t.positive&&LR(e,r),Sr(r.errors)},MR=["if","array","aggregate"],LR=(e,t)=>G(e,r=>{let o=ne(r),n=r.operator??r.dateOperator;return (o&&MR.includes(o)||typeof n=="string"&&Di.includes(n))&&P(t,"$","notPositive",`${o==="field"||o==="date"?n:o} can hold on a missing value`),false}),_R=(e,t={})=>{Cn(zo(e,t),"validateRule");},Gt=(e,t,r,o)=>{if(typeof e=="boolean")return;if(!wr(e)){P(r,t,"invalid_condition","Condition must be a boolean or object");return}let n=ne(e);if(!n){P(r,t,"ambiguous_condition",wt().message);return}switch(n){case "all":tu(e.all,`${t}.all`,r,o);break;case "any":tu(e.any,`${t}.any`,r,o);break;case "if":Gt(e.if,`${t}.if`,r,o),Gt(e.then,`${t}.then`,r,o),"else"in e&&e.else!==void 0&&Gt(e.else,`${t}.else`,r,o);break;case "field":DR(e,t,r,o);break;case "aggregate":IR(e,t,r,o);break;case "array":qR(e,t,r,o);break;case "date":VR(e,t,r,o);break}},tu=(e,t,r,o)=>{if(!Array.isArray(e)){P(r,t,"logical_array_required","Logical operator requires an array of conditions");return}e.forEach((n,i)=>{Gt(n,`${t}[${i}]`,r,o);});},fs=(e,t,r,o)=>{typeof e.field=="string"&&nu(e.field,"field",`${t}.field`,r,o);},nu=(e,t,r,o,n,i=false)=>{let s=L(e)??(t==="path"?{depth:n}:null);if(!s)return;let a=t==="field"?"Field":"Path";s.depth>n&&P(o,r,"scope_out_of_bounds",Gs(e,s.depth,n)),o.target==="toPrisma"&&!i?P(o,r,`unsupported_prisma_${t}`,t==="path"?`Path '${e}' compares to a column, which isn't supported on the Prisma rail; use toSql() or check()`:`${a} '${e}' is not supported by toPrisma()`):o.target==="toSql"&&(t==="field"||s.depth>1)&&P(o,r,`unsupported_sql_${t}`,`${a} '${e}' is not supported by toSql()`);},ds=(e,t,r,o=false)=>{e.stepScopes[t]=o||e.stepScopes[t-1]===true;let n=e.scopeModels[t-1];e.scopeModels[t]=e.map&&n&&typeof r=="string"?Tn(r,e.map,n)??void 0:void 0;},Go=(e,t,r,o,n=false)=>{let i=pf.filter(a=>e[a]!==void 0);if(i.length>1)return P(r,t,"ambiguous_value_source","Takes one of value, path or bind"),null;if(i.length===0)return P(r,t,"missing_value_source","Requires value, path or bind"),null;let[s]=i;return s!=="value"&&(typeof e[s]!="string"||e[s]==="")?(P(r,`${t}.${s}`,"invalid_value_source",`${s} is a non-empty string`),null):(e.bindOptional!==void 0&&(s!=="bind"||typeof e.bindOptional!="boolean")&&P(r,`${t}.bindOptional`,"invalid_value_source","bindOptional is a boolean beside bind"),s==="path"&&nu(e.path,"path",`${t}.path`,r,o,n),s)},iu=(e,t,r,o,n,i)=>{let{offset:s}=e;if(s===void 0)return;let a=`${o}.offset`;if(!Ud.includes(r)){P(n,a,"unsupported_offset_operator",`Operator '${r}' has no comparison point to offset`);return}if(!wr(s)){P(n,a,"invalid_offset","An offset is one of { value }, { path } or { bind }");return}let l=Go(s,a,n,i);if(l==="path"){let f=s.path,u=kr(s);t==="date"&&u&&u.depth<=1&&n.target==="toSql"&&P(n,`${a}.path`,"unsupported_sql_path",`A row path on a date offset ('${f}') is not supported by toSql()`);return}if(l!=="value")return;let d=s.value;if(t==="field"){(typeof d!="number"||!Number.isFinite(d))&&P(n,`${a}.value`,"invalid_offset","A field offset value is a number");return}let p=wr(d)&&Object.keys(d).length===1&&Y(d)?we(d):null;if(!p){P(n,`${a}.value`,"invalid_offset","A date offset value is { ago } or { ahead }");return}lu(p[0],`${a}.value.${Object.keys(d)[0]}`,n,i);},su=(e,t,r,o)=>{o.target!=="toSql"||!Ve.includes(t)||kr(e)&&P(o,`${r}.path`,"unsupported_sql_path",`A range read from the row ('${e.path}') is not supported by toSql()`);},DR=(e,t,r,o)=>{if(typeof e.field!="string"&&P(r,`${t}.field`,"field_required","Field rule requires a string field"),fs(e,t,r,o),typeof e.operator!="string"||!jt(e.operator,"field")){P(r,`${t}.operator`,"invalid_operator",le(e.operator,"field").message);return}let n=e.operator;iu(e,"field",n,t,r,o),Mi(n,"field",r.target)||P(r,`${t}.operator`,`unsupported_${us(r.target)}_operator`,`Operator '${n}' is not supported by ${r.target}()`),e.coerceType!==void 0&&!Ci(e.coerceType)&&P(r,`${t}.coerceType`,"invalid_coerce_type",`coerceType must be one of: ${Object.keys(Q).join(", ")}`);let i=qt(n,"field");if(i==="none"){BR(e,t,r);return}if(Go(e,t,r,o,true)!==null){if(su(e,n,t,r),r.target==="toPrisma"&&typeof e.path=="string"){let s=ss(e,r.map,r.scopeModels[o-1],o>1,r.stepScopes[o-1]===true);"problem"in s&&P(r,`${t}.path`,"unsupported_prisma_path",as(e.path,s.problem).message);}if(r.target==="toSql"&&typeof e.path=="string"&&r.map){let s=r.scopeModels[o-1],a=(L(e.path)??{path:e.path}).path,l=Bo(X(e.field,r.map,s),X(a,r.map,s),n);l&&P(r,`${t}.path`,"unsupported_sql_path",`'${e.path}': ${l}`);}r.target==="toSql"&&typeof e.path=="string"&&["array","pattern","string"].includes(i)&&((r.map?X(e.field,r.map,r.scopeModels[o-1]):void 0)?.isList&>.includes(n)||P(r,`${t}.path`,"unsupported_sql_path",`'${n}' against the column '${e.path}' has no SQL form`)),!(typeof e.path=="string"||typeof e.bind=="string")&&(FR(e,n,t,r,o),jR(i,e.value,n,`${t}.value`,r));}},FR=(e,t,r,o,n)=>{if(o.target!=="toPrisma"||!o.map||typeof e.field!="string")return;let i=X(e.field,o.map,o.scopeModels[n-1]);if(!i)return;let s=e.value,a=se(e.caseInsensitive),l=ir.includes(t)&&Array.isArray(s),d=p=>P(o,`${r}.value`,"unsupported_prisma_operator",F("toPrisma",p).message);i.isList&&!l&&Array.isArray(s)&&s.includes(null)?d(`A list holding null in '${e.field}'`):i.isList&&!l&&a&&yr("text",s)?d(`A case-insensitive comparison on the list '${e.field}'`):je(i)&&a&&d(`A case-insensitive comparison on the Json column '${e.field}'`);},jR=(e,t,r,o,n)=>{switch(e){case "scalar":case "string":e==="string"&&typeof t!="string"&&P(n,o,"invalid_string_value",`Operator '${r}' requires a string value`);return;case "ordered":ce(t)||P(n,o,"invalid_ordered_value",`Operator '${r}' requires a string, number, or Date value`);return;case "array":Array.isArray(t)||P(n,o,"invalid_membership_value",`Operator '${r}' requires an array value`);return;case "pattern":{if(!(typeof t=="string"||t instanceof RegExp)){P(n,o,"invalid_pattern_value",`Operator '${r}' requires a string or RegExp value`);return}let i=Ef(t,n.target);i&&P(n,o,"unsupported_pattern",i);return}case "range":try{Fo(t,r);}catch(i){P(n,o,"invalid_range_value",i.message);}return}},au=(e,t,r,o,n)=>{let i=r.scopeModels[o-1];if(!(r.target!=="toPrisma"||!r.map||!i||typeof e.field!="string"))try{Ko(e.field,r.map,i,n);}catch(s){P(r,`${t}.field`,"unsupported_prisma_relation",s.message);}},IR=(e,t,r,o)=>{if(au(e,t,r,o,"Aggregate rules"),e.offset!==void 0&&P(r,`${t}.offset`,"unexpected_offset","Aggregate rules take no offset"),pu(e,t,r,o),typeof e.field!="string"&&P(r,`${t}.field`,"field_required","Aggregate rule requires a string field"),fs(e,t,r,o),!wr(e.aggregate)){P(r,`${t}.aggregate`,"invalid_aggregate","aggregate must be an object");return}let n=e.aggregate;if(yt.includes(n.mode)||P(r,`${t}.aggregate.mode`,"invalid_aggregate_mode",ar(n.mode).message),"field"in n&&n.field!==void 0&&typeof n.field!="string"&&P(r,`${t}.aggregate.field`,"invalid_aggregate_field","aggregate.field must be a string"),!Li.includes(e.operator)){P(r,`${t}.operator`,"invalid_aggregate_operator",`Aggregate rules only support: ${Li.join(", ")}`);return}if(r.target==="toPrisma"&&typeof e.path=="string"&&P(r,`${t}.path`,"unsupported_prisma_aggregate_path","path is not supported by toPrisma() for aggregate rules; use value instead"),"condition"in e&&e.condition!==void 0&&(r.target==="toSql"&&P(r,`${t}.condition`,"unsupported_sql_aggregate_condition","Aggregate condition filtering is not supported by toSql(); use check() or toPrisma()"),ds(r,o,e.field,true),Gt(e.condition,`${t}.condition`,r,o+1)),Go(e,t,r,o)===null||typeof e.path=="string"||typeof e.bind=="string")return;let i=e.value;Ve.includes(e.operator)?WR(i)||P(r,`${t}.value`,"invalid_range_value",`Operator '${e.operator}' requires a two-item numeric range`):typeof i!="number"&&P(r,`${t}.value`,"invalid_aggregate_value","Aggregate rule value must be a number");},qR=(e,t,r,o)=>{if(typeof e.field!="string"&&r.target!=="check"&&P(r,`${t}.field`,"field_required","Array rule requires a string field for this target"),fs(e,t,r,o),pu(e,t,r,o),typeof e.arrayOperator!="string"||!jt(e.arrayOperator,"array")){P(r,`${t}.arrayOperator`,"invalid_array_operator",le(e.arrayOperator,"array").message);return}let n=e.arrayOperator;hn(e)&&au(e,t,r,o,"Count operators");let i=r.target==="toPrisma"&&r.map&&typeof e.field=="string"?X(e.field,r.map,r.scopeModels[o-1]):void 0;i&&!V(i)&&n!=="empty"&&n!=="notEmpty"&&P(r,`${t}.arrayOperator`,"unsupported_prisma_array_operator",F("toPrisma",`'${n}' over the array column '${e.field}'`).message),Mi(n,"array",r.target)||P(r,`${t}.arrayOperator`,`unsupported_${us(r.target)}_array_operator`,`Array operator '${n}' is not supported by ${r.target}()`);let s=qt(n,"array"),a=e.condition!==void 0,l=()=>{e.count!==void 0&&P(r,`${t}.count`,"unexpected_count",`Array operator '${n}' does not accept count`);};s==="none"?(a&&P(r,`${t}.condition`,"unexpected_condition",`Array operator '${n}' does not accept condition`),l()):s==="predicate"?(a?(ds(r,o,e.field),Gt(e.condition,`${t}.condition`,r,o+1)):P(r,`${t}.condition`,"missing_condition",De(n).message),l()):s==="count"&&(typeof e.count!="number"?P(r,`${t}.count`,"missing_count",Ao(n).message):e.count!==void 0&&!(typeof e.count=="number"&&Number.isInteger(e.count)&&e.count>=0)&&P(r,`${t}.count`,"invalid_count","count must be a non-negative whole number"),a?(ds(r,o,e.field,hn(e)),Gt(e.condition,`${t}.condition`,r,o+1)):P(r,`${t}.condition`,"missing_condition",De(n).message));},VR=(e,t,r,o)=>{if(typeof e.field!="string"&&P(r,`${t}.field`,"field_required","Date rule requires a string field"),fs(e,t,r,o),typeof e.dateOperator!="string"||!jt(e.dateOperator,"date")){P(r,`${t}.dateOperator`,"invalid_date_operator",le(e.dateOperator,"date").message);return}let n=e.dateOperator;iu(e,"date",n,t,r,o);let i=Wt(e.value,la(e.offset));i&&P(r,t,"clock_unit_below_floor",i.message),Mi(n,"date",r.target)||P(r,`${t}.dateOperator`,`unsupported_${us(r.target)}_date_operator`,`Date operator '${n}' is not supported by ${r.target}()`);let s=qt(n,"date");if(s==="dayList"){if(Go(e,t,r,o)!=="value")return;let a=e.value;(!Array.isArray(a)||!a.every(l=>typeof l=="string"&&of(l)))&&P(r,`${t}.value`,"invalid_day_list",`Date operator '${n}' requires an array of day names (${No.join(", ")})`);return}if(Go(e,t,r,o)!==null&&(su(e,n,t,r),!(typeof e.path=="string"||typeof e.bind=="string"))){if(Y(e.value)){ou(e.value,n,`${t}.value`,r,o);return}if(gn.includes(n)){P(r,`${t}.value`,"invalid_date_range",Qe(n).message);return}if(s==="dateRange"){if(!UR(e.value)){P(r,`${t}.value`,"invalid_date_range",`Date operator '${n}' requires a two-item date range`);return}e.value.forEach((a,l)=>{Y(a)?ou(a,n,`${t}.value[${l}]`,r,o):ce(a)&&!fr(a,Ze).isValid()&&P(r,`${t}.value[${l}]`,"invalid_date_value",`Date operator '${n}' value '${String(a)}' does not parse as a date`);});return}if(!ce(e.value)){P(r,`${t}.value`,"invalid_date_value",`Date operator '${n}' requires a date-like value`);return}fr(e.value,Ze).isValid()||P(r,`${t}.value`,"invalid_date_value",`Date operator '${n}' value '${String(e.value)}' does not parse as a date`);}},lu=(e,t,r,o)=>{if(!wr(e)||Object.keys(e).length===0){P(r,t,"invalid_relative_units","Relative offset requires at least one unit");return}for(let[n,i]of Object.entries(e)){if(!vo(n)){P(r,`${t}.${n}`,"invalid_relative_unit",`Unknown relative unit '${n}'`);continue}let s=wr(i)?Go(i,`${t}.${n}`,r,o):"literal";if(s===null||s==="path"||s==="bind")continue;let a=s==="value"?i.value:i,l=sa(a,n);l&&P(r,`${t}.${n}`,"invalid_relative_magnitude",l);}},ru=(e,t,r)=>{(typeof e!="string"||!Ii.includes(e))&&P(r,t,"invalid_period_unit",`Unknown period unit '${String(e)}'`);},ou=(e,t,r,o,n)=>{let i=gn.includes(t),s=we(e);if(s){lu(s[0],r,o,n);return}if(Rn(e)){ru(Co(e),r,o);return}if(On(e)){if(i){P(o,r,"invalid_date_range",Qe(t).message);return}let a="start"in e?e.start:e.end;if(!wr(a)||!Rn(a)){P(o,r,"invalid_period_unit","start/end requires a this/last/next period");return}ru(Co(a),r,o);return}P(o,r,"invalid_date_expression","Unrecognized date expression");},BR=(e,t,r)=>{"value"in e&&e.value!==void 0&&P(r,`${t}.value`,"unexpected_value","Rule does not accept value"),"path"in e&&e.path!==void 0&&P(r,`${t}.path`,"unexpected_path","Rule does not accept path"),"bind"in e&&e.bind!==void 0&&P(r,`${t}.bind`,"unexpected_bind","Rule does not accept bind");},us=e=>e==="toPrisma"?"prisma":e==="toSql"?"sql":"check",wr=e=>fe(e),WR=e=>Array.isArray(e)&&e.length===2&&typeof e[0]=="number"&&typeof e[1]=="number",UR=e=>Array.isArray(e)&&e.length===2&&(ce(e[0])||Y(e[0]))&&(ce(e[1])||Y(e[1])),pu=(e,t,r,o)=>{if($e(e)&&r.target!=="check"&&(r.target==="toPrisma"&&Vo(e)!==null||P(r,t,`unsupported_${us(r.target)}_window`,St(r.target).message)),"filter"in e&&e.filter!==void 0&&(ds(r,o,e.field),Gt(e.filter,`${t}.filter`,r,o+1)),"orderBy"in e&&e.orderBy!==void 0){let i=e.orderBy;Array.isArray(i)?i.forEach((s,a)=>{(!wr(s)||typeof s.field!="string"||s.dir!=="asc"&&s.dir!=="desc")&&P(r,`${t}.orderBy[${a}]`,"invalid_order_by",'orderBy entries must be { field: string, dir: "asc" | "desc" }');}):P(r,`${t}.orderBy`,"invalid_order_by","orderBy must be an array of { field, dir }");}for(let i of ["take","skip"])if(i in e&&e[i]!==void 0){let s=e[i];(typeof s!="number"||!Number.isInteger(s)||s<0)&&P(r,`${t}.${i}`,`invalid_window_${i}`,`${i} must be a non-negative integer`);}},P=(e,t,r,o)=>{e.errors.push({path:t,code:r,message:o});};var KR=/[.:]/,ga=e=>{let t=[];for(let[r,o]of Object.entries(e.maps))for(let[n,i]of Object.entries(o.models))for(let[s,a]of Object.entries(i.fields))a.kind!=="bridge"&&KR.test(s)&&t.push({path:`${ke({fieldMap:r,model:n})}.${s}`,message:"contains forbidden character . or :",code:"invalid_field_name"});return Sr(t)},du=e=>Cn(ga(e),"validateFieldMaps");var ot=e=>!Object.hasOwn(e,"parent"),$t=e=>{let t=[],r=new Set,o=e;for(;!ot(o);){if(r.has(o))throw new Error("cycle detected in narrowing parent chain");if(Object.hasOwn(o,"model")||Object.hasOwn(o,"maps"))throw new Error("a narrowing carries a base lens key (model / maps); it has a parent instead");r.add(o),t.unshift(o),o=o.parent;}return t},nt=e=>ot(e)?e:$t(e)[0].parent;var ya=(e,t)=>t.length?z([...t,e]):e,GR=e=>{if(dr(e).length)return false;let t=e.field,r=typeof t=="string"?L(t):null;try{return me(r?{...e,field:r.path}:e,{})===!0}catch{return false}},ha=(e,t)=>{if(!t.length)return e;if(!GR(e))return z([...t.flatMap(n=>n.clamps),e]);let[r,...o]=t;return Bt([z([...r.clamps,ha(e,o)]),z([{field:r.prefix,operator:"notExists"},e])])},Jo=(e,t,{paths:r=false}={})=>pr(e,{rewrite:o=>{if(Fe(o))return o;if(typeof o.field!="string"||o.field==="")throw new A(`narrowRule: cannot re-root a relation clamp of unknown shape under '${t}'`,"unsupported_clamp");let n=dr(o),i=n.find(a=>L(a));if(r&&i)throw new A(`prefixConditionFields: cannot re-root a scope ref ('${i}') under '${t}'`,"unsupported_clamp");if(n.length&&!r)throw new A(`narrowRule: cannot re-root a relation clamp with a path reference ('${n[0]}') under '${t}'. Author the clamp without 'path', or anchor it at the relation itself.`,"unsupported_clamp");if(L(o.field))throw new A(`narrowRule: cannot re-root a relation clamp with a scope ref field ('${o.field}') under '${t}'. Author the clamp against the model's own columns.`,"unsupported_clamp");if(Se(o)){for(let a of [o.condition,o.filter])if(a!==void 0&&Ho(a).escaping!==null)throw new A(`narrowRule: cannot re-root a relation clamp on '${o.field}' under '${t}': '${Ho(a).escaping}' inside it reads the row being re-rooted. Anchor such clamps at the relation's own model.`,"unsupported_clamp")}return {...r?_o(o,a=>Ee(a)?{...a,path:`${t}.${a.path}`}:a):o,field:`${t}.${o.field}`}},below:()=>false}),wa=(e,t)=>t.flatMap(r=>{let o=D(e,r.map,r.model,r.relPath);if(o.whereClauses.length===0)return [];if(r.isList)throw new A(`narrowRule: cannot enforce a to-many relation clamp on '${r.prefix}' without an arrayOperator condition to anchor it (row-scoped). Traverse '${r.prefix}' via an array operator (any/all/none/...) so the clamp can be injected safely.`,"unsupported_clamp");return [{prefix:r.prefix,clamps:o.whereClauses.map(n=>Jo(n,r.prefix))}]}),fu=(e,t)=>wa(e,t).flatMap(r=>r.clamps),cu=(e,t,r)=>{let o=qe(e,r);if("outOfBounds"in o)throw new A(`narrowRule: ${o.outOfBounds}`,"scope_out_of_bounds");if(!o.scope)return {hops:[],end:null};let n=e.slice(0,e.length-o.path.length);return Ne(t.lens.maps,o.scope,o.path,n==="$."?"":n)},zR=(e,t,r)=>{if(L(e))return cu(e,t,r).hops;let o=r.length===1?"":`${"$".repeat(r.length)}.`;return r[0]?Ne(t.lens.maps,r[0],e,o).hops:[]},uu=(e,t,r)=>{if(Fe(e)||typeof e.field!="string"||e.field==="")return null;let{hops:o,end:n}=cu(e.field,t,r);return {hops:o,below:n}},Kr=(e,t,r)=>pr(e,{below:(o,n)=>{let i=uu(o,t,n);return i?i.below?[...n,i.below]:Se(o)?[...n,null]:false:false},after:(o,n)=>{let i=uu(o,t,n);if(!i)return o;let s=fu(t,dr(o).flatMap(f=>zR(f,t,n))),a=i.below;if(!a||!Se(o))return ya(ha(o,wa(t,i.hops)),s);let l=[...D(t,a.mapName,a.modelName,a.relPath).whereClauses,...fu(t,Do(o).flatMap(f=>Ne(t.lens.maps,a,f).hops))],d=o.condition===void 0||o.arrayOperator===x.all||$e(o),p={...o};return l.length&&d?p.filter=z([...o.filter!==void 0?[o.filter]:[],...l]):l.length&&(p.condition=z([...l,o.condition])),ya(ha(p,wa(t,i.hops.slice(0,-1))),s)}},[r]),Qo=(e,t)=>{let r=M(t),o=D(r,r.lens.mapName,r.lens.model,[]),n=Kr(e,r,{mapName:r.lens.mapName,modelName:r.lens.model,relPath:[]});return ya(n,o.whereClauses)};var Sa=(e,t)=>{let r=Fr(e,Q.DateTime,t);return typeof r=="number"&&!Number.isNaN(new Date(r).getTime())?r:void 0},HR=(e,t,r)=>o=>{if(o==null)return o;let n=Sa(o,r);if(n===void 0)throw new Error(`Invalid date value for DateTime field '${e}': ${String(o)}`);return t==="toPrisma"?new Date(n):new Date(n).toISOString()},Zo=(e,t,r,o,n)=>{if(t==null||r?.kind==="json-path")return t;let i=r?.kind==="direct"?r.entry:void 0;if(i?.isList)return t;let s=i?et(i):void 0;if(e.coerceType!==void 0&&s!==void 0&&e.coerceType!==s)throw new Error(`coerceType '${e.coerceType}' overrides ${s} field '${e.field}', but ${o} compares the column as stored \u2014 evaluate it in memory with check(), or drop the override.`);if((s??e.coerceType)===Q.DateTime){let l=HR(e.field,o,n());return Array.isArray(t)?t.map(l):l(t)}if(e.coerceType===void 0&&s===Q.String&&(Array.isArray(t)?t:[t]).some(l=>typeof l=="number"||typeof l=="boolean"))throw new Error(`'${e.field}' is String but the literal is not a string; pass a string, or stamp coerceType: 'String'.`);if(e.coerceType===void 0&&s!==void 0&&(He.includes(s)||s===Q.Boolean)&&(Array.isArray(t)?t:[t]).some(l=>typeof l=="string"))throw new Error(`'${e.field}' is ${s} but the literal is a string; pass a ${s===Q.Boolean?"boolean":"number"}, or stamp coerceType: '${s}'.`);return e.coerceType!==void 0&&Xd.includes(e.coerceType)?Fr(t,e.coerceType,e.coerceType===Q.DateTime?n():void 0):t};var mu=e=>Array.isArray(e)?e.flatMap(mu):[e],Mn=e=>e.value===void 0?null:mu(e.value),JR=e=>Sa(e)!==void 0,QR=/^-?\d+(\.\d+)?$/,ZR={String:{expected:"a string",fits:e=>typeof e=="string"},Enum:{expected:"a string",fits:e=>typeof e=="string"},Int:{expected:"an integer",fits:Number.isSafeInteger},BigInt:{expected:"an integer",fits:Number.isSafeInteger},Float:{expected:"a number",fits:Number.isFinite},Decimal:{expected:"a number or a numeric string",fits:e=>Number.isFinite(e)||typeof e=="string"&&QR.test(e)},Boolean:{expected:"a boolean",fits:e=>typeof e=="boolean"},DateTime:{expected:"a date",fits:JR},Json:{expected:"a value",fits:()=>true},Bytes:{expected:"a value",fits:()=>true}},YR=e=>typeof e=="string"?`'${e}'`:typeof e=="object"&&e!==null?JSON.stringify(e):String(e),cs=(e,t)=>{let r="coerceType"in e?e.coerceType:void 0,o=r??t;if(o===void 0||o===Q.Json)return [];let n="operator"in e?e.operator:e.dateOperator,i=Eo(e);if(!i)return [];let a=r!==void 0&&r!==t?`field '${e.field}' coerced to ${o}`:`${o} field '${e.field}'`;if(!i.kinds.includes(o))return [{path:e.field,code:"operator_kind_mismatch",message:`operator '${n}' does not apply to ${a} (applies to: ${i.kinds.join(", ")})`}];if(e.offset!==void 0&&!("dateOperator"in e?o===Q.DateTime:He.includes(o)))return [{path:e.field,code:"invalid_offset",message:`an offset does not apply to ${a}`}];if("dateOperator"in e||i.valueShape==="none"||i.valueShape==="pattern")return [];if(ef.includes(i.valueShape)&&Array.isArray(e.value))return [{path:e.field,code:"invalid_value_shape",message:`operator '${n}' compares one value, but ${a} was given a list`}];let{expected:l,fits:d}=ZR[o],p=u=>{try{return d(Fr(u,o))}catch{return false}},f=u=>d(u)||r!==void 0&&p(u);return (Mn(e)??[]).filter(u=>u!==null&&!f(u)).map(u=>({path:e.field,code:"invalid_value",message:`value ${YR(u)} does not fit ${a} (expected ${l})`}))},gu=(e,t,r)=>{if(r.isList===true||je(r))return null;let o=V(r)?`arrayOperator '${t}' needs a list, but '${e}' is a to-one relation \u2014 a single related record; address its fields directly (e.g. '${e}.<field>')`:`arrayOperator '${t}' needs a list, but '${e}' is a single ${et(r)??r.type} value`;return {path:e,code:"invalid_array_operator",message:o}};var XR=(e,t,r,o)=>G(e,(n,i)=>{let s=ne(n);if(s===null)return o.push({path:typeof n.field=="string"?n.field:"",code:"ambiguous_condition",message:wt().message}),false;if(Fe(n))return;let a=n,l=w=>{let R=qe(w,i);return "outOfBounds"in R?(o.push({path:w,code:"scope_out_of_bounds",message:R.outOfBounds}),null):{scope:R.scope,field:R.path}},d=i[i.length-1],p=true,f=null;if("field"in a&&typeof a.field=="string"&&a.field!==""){let w=en(t,i,a.field);"issue"in w?(o.push({path:a.field,...w.issue}),p=false):{next:d,walked:f}=w;}let u=f?.entry??null,m=f?.terminalFieldName??null,y=f?.entry.kind==="enum",c=f?.entry.type??null,g=f&&f.jsonSubPath.length===0?gs(f.terminalEffect,f.terminalFieldName):null;for(let{ref:w,role:R}of $n(a)){let S=L(w)?l(w):{scope:Pt(t),field:w};if(!S||S.scope.open)continue;let b=Yo(t,S.scope,S.field);if(!b){o.push({path:w,...ms(t,S.scope,S.field,R==="value"?"path (comparison ref) does not resolve through the narrowed lens":"offset or magnitude ref does not resolve through the narrowed lens")});continue}if(V(b.entry)){o.push({path:w,code:"not_in_lens",message:"a value ref reads a column, not a relation"});continue}let $=et(b.entry);if(R==="value"||R==="shift"||$===void 0)continue;(R==="whole"?Zd.includes($):He.includes($))||o.push({path:w,code:"not_in_lens",message:`${R==="whole"?"a calendar unit reads a whole number":"an offset or magnitude reads a number"}, not ${$}`});}if(!p)return false;if("arrayOperator"in a&&typeof a.field=="string"&&u){let w=gu(a.field,a.arrayOperator,u);if(w)return o.push(w),false}if(u&&V(u)&&(s==="field"||s==="date")&&(u.isList||!Ut(a))){let w=a.field;return o.push({path:w,code:"operator_kind_mismatch",message:(u.isList?Bi(w):sr(w)).message}),false}if(!u?.isList&&(s==="field"||s==="date")&&o.push(...cs(a,u?et(u):void 0)),!d.open)for(let w of Do(a))w!==""&&!Yo(t,d,w)&&o.push({path:w,...ms(t,d,w,"an orderBy or aggregate field does not resolve through the narrowed lens")});if(g&&"operator"in a&&m){let w=Mn(a);if(w){let R=new Set(g),S=y?`enum '${c}'`:`field '${m}'`;for(let b of w)typeof b=="string"&&!R.has(b)&&o.push({path:m,code:"value_not_allowed",message:`value '${b}' is not in the allowed set for ${S} (allowed: ${[...R].join(", ")})`});}}return [...i,d]},[r]),Ln=(e,t,r,o,n)=>{let i=[];return XR(e,t,{mapName:r,modelName:o,relPath:n,open:false},i),i},Xo=(e,t)=>{let r=M(t);try{let o=Ln(e,r,r.lens.mapName,r.lens.model,[]);return o.length===0&&Qo(e,t),Sr(o)}catch(o){if(!(o instanceof A))throw o;return Sr([{path:"",code:o.code,message:o.message}])}};var Fn=e=>e===void 0?void 0:Array.isArray(e)?e:[e],jn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&("where"in e||"label"in e||"groupBy"in e||"from"in e),br=e=>{if(jn(e))return e;if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===0)throw eO();return {where:e}},eO=()=>new A("sources: {} is not a Condition \u2014 use `true` for an unconstrained source","invalid_source"),Oa=["__offpath__"],yu=new WeakMap,tO=(e,t)=>{if(!t)return new Map;let r=JSON.stringify([_n(t.parent),_n(e.maps),e.mapName,e.model,t.mapDefaults??null]),o=yu.get(t);if(o?.fingerprint===r)return o.trees;let n=new Map;return yu.set(t,{fingerprint:r,trees:n}),n},hu=new WeakMap,rO=0,_n=e=>{let t=hu.get(e);return t===void 0&&(t=rO++,hu.set(e,t)),t},ge="\0",oO=e=>{let t=Object.entries(e.fields);return {relations:new Set(t.filter(([,r])=>V(r)).map(([r])=>r)),gated:t.filter(([,r])=>r.options!==void 0||r.kind==="enum"||r.values!==void 0)}},ys=e=>e?String(_n(e)):"",M=e=>{let t=nt(e),r=ot(e)?[]:$t(e);return {lens:t,chain:r,origin:r[0],memo:{trees:tO(t,r[0]),vetted:new Set,effects:new Map,places:new Map,models:new Map,refs:new Map,compiles:new Map}}},hs=(e,t)=>e===null?new Set(t):new Set(t.filter(r=>e.has(r))),nO=(e,t)=>{if(t.picks&&(e.picks=hs(e.picks,t.picks)),t.omits)for(let r of t.omits)e.omits.add(r);},bu=(e,t,r)=>{e.set(t,hs(e.get(t)??null,r));},Ru=(e,t,r)=>{let o=e.get(t)??new Set;for(let n of r)o.add(n);e.set(t,o);},iO=(e,t,r)=>{if(r.enumPicks)for(let[o,n]of Object.entries(r.enumPicks))bu(e,o,n);if(r.enumOmits)for(let[o,n]of Object.entries(r.enumOmits))Ru(t,o,n);},ba=(e,t,r)=>JSON.stringify([e,t,r]),sO=(e,t,r,o,n,i,s,a)=>{if(s&&nO(e,t),t.where!==void 0&&i&&(n(t.where),e.whereClauses.push(r(t.where)),(a?e.modelWheres:e.pathWheres).push({where:t.where,layer:o})),t.sources)for(let[l,d]of Object.entries(t.sources)){let p=br(d),f=e.sources.get(l)??[],u=e.sourceWheres.get(l)??[];p.where!==void 0&&i&&(n(p.where,true),f.push(r(p.where)),u.push(p.where)),e.sources.set(l,f),e.sourceWheres.set(l,u);let m=Fn(p.groupBy);for(let[y,c,g]of [["label",p.label,e.sourceLabels.get(l)],["groupBy",m,e.sourceGroupBys.get(l)]]){if(c===void 0)continue;let w=ba(l,y,c);g!==void 0&&ba(l,y,g)===w||e.sourceDeclaredAt.set(w,o);}p.label!==void 0&&e.sourceLabels.set(l,p.label),m!==void 0&&e.sourceGroupBys.set(l,m),p.from==="mapDefaults"&&!e.sourcesFromMapDefaults.has(l)&&e.sourcesFromMapDefaults.set(l,o);}},A=class extends Error{constructor(r,o){super(r);this.code=o;}code;name="LensRefusal"},xa=e=>new A(`a bare path ('${e}') reads the root row, which a clamp at a relation visit or a model default doesn't stand on: use a literal, a bind, or a \`$\` scope ref`,"invalid_value_source"),aO=(e,t,r)=>Ln(e,t,r.mapName,r.modelName,r.relPath),lO=e=>new A(`a later layer's clamp reads what its parent does not show: '${e.path}' ${e.message}`,e.code),Ea=e=>new A(`the scope ref '${e}' climbs out of the clamp: a clamp reads its own row ('$.'), literals and binds`,"scope_out_of_bounds"),Ho=e=>{let t=null,r=null;return G(e,(o,n)=>{if(Fe(o))return;let i=dr(o);for(let s of [...typeof o.field=="string"?[o.field]:[],...i]){let a=L(s);r===null&&a&&a.depth>n&&(r=s);}for(let s of i)t===null&&!L(s)&&(t=s);return Se(o)?n+1:void 0},1),{bare:t,escaping:r}},Ra=(e,t)=>{let r={mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]},o=[r];if(t.relPath.length>0)for(let i of Ne(e.lens.maps,r,t.relPath.join(".")).hops)o.push({mapName:i.map,modelName:i.model,relPath:i.relPath});let n=o[o.length-1];return o.length===t.relPath.length+1&&n.mapName===t.mapName&&n.modelName===t.modelName?o:null},Dn=(e,t)=>{let r=e;for(let o of t)r=O(r?.relations,o);return r},$a=(e,t,r)=>{let o=i=>O(O(e.mapDefaults,i.mapName)?.models,i.modelName);if(!r){let i=o(t);return {defaults:i?[i]:[],path:void 0}}let n=[];for(let[i,s]of r.entries()){let a=Dn(o(s),t.relPath.slice(i));a&&n.push(a);}return {defaults:n,path:Dn(e.root,t.relPath)}},pO=(e,t,r,o)=>{let n=Dn(t.root,r.relPath),i=[r.relPath.join(ge),Object.keys(n?.relations??{}).join(ge),(n?.omits??[]).join(ge)].join(`${ge}${ge}`),s=o.get(i);if(s)return s;let a=new Map,l={lens:e},d=Ra(l,r)??[r],p=new Set(d.map(u=>`${u.mapName}:${u.modelName}`)),f=[{at:r,below:[]}];for(;f.length>0;){let{at:u,below:m}=f.shift(),y=T(O(e.maps,u.mapName),u.modelName)?.fields??{},{defaults:c,path:g}=$a(t,u,Ra(l,u)),w=new Set(c.flatMap(b=>Object.keys(b.relations??{}))),R=new Set([...c,...g?[g]:[]].flatMap(b=>b.omits??[])),S=[];for(let[b,$]of Object.entries(y)){if(!w.has(b)||R.has(b)||g?.relations!==void 0&&Object.hasOwn(g.relations,b))continue;let E=Xe($,u.mapName);if(!E||!T(O(e.maps,E.mapName),E.modelName))continue;let I=`${E.mapName}:${E.modelName}`;p.has(I)||(p.add(I),S.push(b),f.push({at:{...E,relPath:[...u.relPath,b]},below:[...m,b]}));}a.set(m.join("."),S);}return o.set(i,a),a},dO=(e,t,r,o)=>{if(!o)return $a(t,r,null).defaults.flatMap(d=>Object.keys(d.relations??{}));let n=r.relPath.length;for(;n>0&&Dn(t.root,r.relPath.slice(0,n))===void 0;)n--;let i={...o[n],relPath:r.relPath.slice(0,n)},a=pO(e.lens,t,i,e.memo?.trees??new Map).get(r.relPath.slice(n).join("."))??[];return [...n===r.relPath.length?Object.keys(Dn(t.root,r.relPath)?.relations??{}):[],...a]},In=(e,t,r)=>{let o=t;for(let n of Ne(e.lens.maps,t,r).hops){let i=n.relPath[n.relPath.length-1];if(!D(e,o.mapName,o.modelName,o.relPath).relations.has(i))return n.prefix;o={mapName:n.map,modelName:n.model,relPath:n.relPath};}return null},D=(e,t,r,o)=>{let n=e.memo?wu(e,t,r,o):null,i=n===null?void 0:e.memo?.effects.get(n);if(i){if(!e.unvetted&&i.unchecked){for(let j of i.unchecked)j();i.unchecked=null;}return i.effect}let s=[],a={picks:null,omits:new Set,enumValuesByField:new Map,whereClauses:[],pathWheres:[],modelWheres:[],sources:new Map,sourceWheres:new Map,sourceLabels:new Map,sourceGroupBys:new Map,sourceDeclaredAt:new Map,sourcesFromMapDefaults:new Map,relations:new Set,relationFields:new Set},l=O(e.lens.maps,t),d=T(l,r);if(!d)return a;let p=e.memo?.models.get(d);p||(p=oO(d),e.memo?.models.set(d,p)),a.relationFields=p.relations;let f={mapName:t,modelName:r,relPath:o},u=e.origin??e.chain[0],m=`${ys(u)}${ge}${t}${ge}${r}${ge}${o.join(ge)}`,y=e.memo?.places.get(m);if(!y){let j=Ra(e,f);y={trail:j,turnedOn:u?dO(e,u,f,j):[]},e.memo?.places.set(m,y);}let{trail:c}=y,g=new Map,w=new Map,R=new Map,S=new Map,b=j=>j,$=0,E=()=>{},I=true,pe=true,N=(j,q=false)=>{sO(a,j,b,$,E,I,pe,q),iO(g,w,j);};for(let[j,q]of e.chain.entries()){$=j;let Er={...e,clamp:false,skipClampsOf:void 0,skipHidingOf:void 0,chain:e.chain.slice(0,j)};I=q!==e.skipClampsOf,pe=q!==e.skipHidingOf,b=ee=>j===0?ee:Kr(ee,Er,{mapName:t,modelName:r,relPath:o});for(let[ee,ye]of Object.entries(O(q.mapDefaults,t)?.enums??{}))ye.picks&&bu(R,ee,ye.picks),ye.omits&&Ru(S,ee,ye.omits);let{defaults:nn,path:$r}=$a(q,f,c),de=j===0?null:Er,at=ee=>(ye,he=false)=>{let Ae=e.memo?.refs.get(ye);if(Ae||(Ae=Ho(ye),e.memo?.refs.set(ye,Ae)),Ae.bare!==null&&!(ee&&!he))throw xa(Ae.bare);if(Ae.escaping!==null)throw Ea(Ae.escaping);if(!de)return;let sl=()=>{let Jn=typeof ye=="object"&&ye!==null?`${_n(ye)}${ge}${wu(de,t,r,o)}`:null;if(Jn!==null&&de.memo?.vetted.has(Jn))return;let[al]=aO(ye,de,f);if(al)throw lO(al);Jn!==null&&de.memo?.vetted.add(Jn);};e.unvetted?s.push(sl):sl();};E=at(false);let Jr=O(O(q.mapDefaults,t)?.models,r);for(let ee of nn)N(ee,ee===Jr);$r&&(E=at(o.length===0&&c!==null),N($r));}if(u&&e.chain.includes(u))for(let j of y.turnedOn)a.relationFields.has(j)&&!a.omits.has(j)&&a.relations.add(j);for(let[j,q]of p.gated){let Er=q.kind==="enum",$r=q.options?.map(ee=>ee.value)??(Er?Ir(q,l?.enums):q.values);if(!$r)continue;let de=$r;if(Er){let ee=R.get(q.type),ye=S.get(q.type);ee&&(de=de.filter(he=>ee.has(he))),ye&&(de=de.filter(he=>!ye.has(he)));}let at=g.get(j),Jr=w.get(j);at&&(de=de.filter(ee=>at.has(ee))),Jr&&(de=de.filter(ee=>!Jr.has(ee))),a.enumValuesByField.set(j,de);}return n!==null&&e.memo?.effects.set(n,{effect:a,unchecked:s.length?s:null}),a},wu=(e,t,r,o)=>{let n=Su.get(e);if(n===void 0){n=`${ys(e.origin)}${ge}${ys(e.skipClampsOf)}${ge}${ys(e.skipHidingOf)}${ge}`;for(let i of e.chain)n+=`${_n(i)},`;Su.set(e,n);}return `${n}${ge}${t}${ge}${r}${ge}${o.join(ge)}`},Su=new WeakMap,zt=e=>{let t=[],r=(o,n)=>{let i=O(e.lens.maps,o.mapName);if(!T(i,o.modelName))return;let s=D(e,o.mapName,o.modelName,o.relPath);t.push({path:n,at:o,effect:s});for(let a of s.relations){let l=Pe(i,o.modelName,a),d=l&&Xe(l,o.mapName);d&&r({...d,relPath:[...o.relPath,a]},`${n}.${a}`);}};return r({mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]},e.lens.model),t},ws=(e,t,r,o)=>D(e,t,r,Oa).sources.has(o),Ss=(e,t,r,o)=>new A(`source '${o}' at '${e}' offers mapDefaults.${t}.models.${r}.sources.${o}, which no layer declares`,"invalid_source"),vt=(e,t)=>e.omits.has(t)?false:e.relationFields.has(t)?e.relations.has(t):!(e.picks!==null&&!e.picks.has(t)),gs=(e,t)=>e.enumValuesByField.get(t)??null,Gr=(e,t,r)=>{let o=r.split("."),n=[],i=[];for(let{index:s,field:a,at:l,entry:d,next:p}of cr(e.lens.maps,t,r)){if(!d)return {resolution:{outcome:"missing",index:s,hops:n},effects:i};let f=D(e,l.mapName,l.modelName,l.relPath);if(!(e.clamp&&V(d)?!f.omits.has(a):vt(f,a)))return {resolution:{outcome:"hidden",index:s,hops:n},effects:i};let m={field:a,entry:d,mapName:l.mapName,model:l.modelName,relPath:[...l.relPath]};n.push(m),i.push(f);let y=s===o.length-1;if(y||je(d))return {resolution:{outcome:"resolved",hops:n,terminal:m,jsonSubPath:y?[]:o.slice(s+1)},effects:i};if(!p)return {resolution:{outcome:"pastScalar",index:s,hops:n},effects:i}}return {resolution:{outcome:"missing",index:o.length,hops:n},effects:i}},tn=(e,t,r,o,n)=>{let i=n==="label"?t.sourceLabels.get(o):t.sourceGroupBys.get(o);if(i===void 0)return true;let s=t.sourceDeclaredAt.get(ba(o,n,i)),a=(p,f)=>Gr(p,r,f).resolution.outcome!=="hidden",l={...e,clamp:true},d={...l,skipHidingOf:s===void 0?void 0:e.chain[s]};return (typeof i=="string"?[i]:i).every(p=>In(e,r,p)===null&&(a(l,p)||a(d,p)))},Yo=(e,t,r)=>{let{resolution:o,effects:n}=Gr(e,t,r);if(o.outcome!=="resolved")return null;let{terminal:i,jsonSubPath:s}=o;return {mapName:i.mapName,modelName:i.model,relPath:i.relPath,entry:i.entry,terminalEffect:n[n.length-1],terminalFieldName:i.field,jsonSubPath:s}},ms=(e,t,r,o)=>{let{resolution:n}=Gr(e,t,r);if(n.outcome!=="hidden")return {code:"not_in_lens",message:o};let i=r.split("."),s=n.hops.at(-1),a=s?{mapName:s.mapName,modelName:s.model,relPath:[...s.relPath,s.field]}:t,l=s&&Xe(s.entry,s.mapName),d=l?{...l,relPath:a.relPath}:t,p=D(e,d.mapName,d.modelName,d.relPath),f=i[n.index];return !p.relationFields.has(f)||p.omits.has(f)?{code:"not_in_lens",message:o}:{code:"not_in_lens",message:`'${i.slice(0,n.index+1).join(".")}' is a relation the lens does not turn on (turn it on with \`relations\`)`}},Pt=e=>({mapName:e.lens.mapName,modelName:e.lens.model,relPath:[],open:false}),en=(e,t,r)=>{let o=qe(r,t);if("outOfBounds"in o)return {issue:{code:"scope_out_of_bounds",message:o.outOfBounds}};if(o.scope.open)return {from:o.scope,next:o.scope,walked:null};let n=Yo(e,o.scope,o.path);if(!n)return {issue:ms(e,o.scope,o.path,"path does not resolve through the narrowed lens")};let i=je(n.entry),s=Xe(n.entry,n.mapName),a=s?{...s,relPath:[...n.relPath,n.terminalFieldName],open:i}:{...o.scope,open:i};return {from:o.scope,next:a,walked:n}},Ne=(e,t,r,o="")=>{let n=r.split("."),i=[],s=null;for(let{index:a,field:l,at:d,entry:p,next:f}of cr(e,t,r)){if(!p||!f)break;let u=[...d.relPath,l];i.push({map:f.mapName,model:f.modelName,relPath:u,prefix:`${o}${n.slice(0,a+1).join(".")}`,isList:p.isList===true}),a===n.length-1&&(s={...f,relPath:[...u]});}return {hops:i,end:s}};var va="parent:",Na=e=>e.startsWith(va),xu=e=>Na(e)?e.slice(va.length):e,Pa=(e,t)=>{let r={...e};if(e.where!==void 0&&(r.where=t(e.where)),e.sources){let o={};for(let[n,i]of Object.entries(e.sources))o[n]=jn(i)?i.where!==void 0?{...i,where:t(i.where)}:i:t(i);r.sources=o;}if("relations"in e&&e.relations){let o={};for(let[n,i]of Object.entries(e.relations))o[n]=Pa(i,t);r.relations=o;}return r},Eu=(e,t)=>{let r={};for(let[o,n]of Object.entries(e.mapDefaults??{})){let i={};for(let[s,a]of Object.entries(n.models??{}))i[s]=Pa(a,t);r[o]=n.models?{...n,models:i}:n;}return {...e,root:e.root?Pa(e.root,t):void 0,mapDefaults:e.mapDefaults?r:void 0}},Aa=e=>{let t=[];return Eu(e,r=>(t.push(r),r)),t},Ou=e=>{let t=new Set;for(let r of Aa(e))for(let o of Pn(r))Na(o)||t.add(o);return t},$u=e=>{let t=new Set;for(let r of $t(e))for(let o of Aa(r))for(let n of Pn(o,{required:true}))t.add(xu(n));return [...t].sort()},Pu=(e,t)=>{if(ot(e))return e;let r={...t};for(let[o,n]of Object.entries(t))r[`${va}${o}`]=n;return {...Eu(e,o=>na(o,r)),parent:Pu(e.parent,t)}},vu=(e,t)=>Pu(e,t),Nu=e=>{let t=[],r=new Set;for(let n of $t(e.parent))for(let i of Ou(n))r.add(i);for(let n of Ou(e))r.has(n)&&t.push(`bind name '${n}' already declared by an ancestor narrowing \u2014 rename it, or reference the inherited one as 'parent:${n}'`);let o=new Set;for(let n of Aa(e))for(let i of Pn(n))Na(i)&&o.add(xu(i));for(let n of o)r.has(n)||t.push(`bind 'parent:${n}' references an inherited binding no ancestor declares`);return t};var Tu=(e,t)=>e===void 0?t:t===void 0?e:{all:[e,t]},fO=(e,t)=>{if(!e||!t)return e??t;let r={...e};for(let[o,n]of Object.entries(t)){let i=r[o];if(i===void 0){r[o]=n;continue}let s=br(i),a=br(n),l=Tu(s.where,a.where);r[o]={...s,...a,...l===void 0?{}:{where:l}};}return r},ku=(e,t)=>{let r=Tu(e?.where,t.where),o=fO(e?.sources,t.sources);return {...e,...r===void 0?{}:{where:r},...o?{sources:o}:{}}},uO=(e,t)=>{let r={...e?.models};for(let[o,n]of Object.entries(t))r[o]=ku(r[o],n);return {...e,models:r}},Au=(e,t)=>{let r={...e.mapDefaults};for(let[o,{models:n}]of Object.entries(t.mapDefaults??{}))r[o]=uO(r[o],n);return {...e,...t.root?{root:ku(e.root,t.root)}:{},...t.mapDefaults?{mapDefaults:r}:{}}},Ta=(e,t)=>ot(e)?Au({parent:e},t):ot(e.parent)?Au(e,t):{...e,parent:Ta(e.parent,t)};var Cu=(e,t)=>{let r=M(t),o=(n,i)=>typeof n=="string"&&n!==""?en(r,i,n):null;return pr(e,{rewrite:(n,i)=>{if(ne(n)!=="field"||n.coerceType)return n;let s=o(n.field,i);if(!s||"issue"in s||!s.walked||s.walked.jsonSubPath.length)return n;let{entry:a}=s.walked;return a.kind==="scalar"&&Yd.includes(a.type)?{...n,coerceType:a.type}:n},below:(n,i)=>{if(!Se(n))return false;let s=o(n.field,i),a=s&&!("issue"in s)?s.walked?.entry:void 0;return s&&!("issue"in s)&&a&&V(a)?[...i,s.next]:false}},[Pt(r)])};var Mu=({maps:e,bridges:t,mapName:r,model:o})=>({...ts({maps:e,bridges:t}),mapName:r,model:o});var cO=(e,t)=>G(e,(r,o)=>{if(t.sources.add(o[o.length-1].mapName),Fe(r)||typeof r.field!="string"||r.field==="")return;let n=en(t.policy,o,r.field);return "issue"in n?false:(n.walked&&(t.sources.add(n.walked.mapName),(n.walked.entry.kind==="bridge"||n.walked.mapName!==n.from.mapName)&&(t.bridgesCrossed=true)),[...o,n.next])},[Pt(t.policy)]),Lu=(e,t)=>{let o={policy:M(t),sources:new Set,bridgesCrossed:false};return cO(e,o),{sources:[...o.sources].sort(),bridgesCrossed:o.bridgesCrossed,supportedTargets:C.filter(n=>(n==="check"||!o.bridgesCrossed)&&zo(e,{target:n,map:o.policy.lens,mapName:o.policy.lens.mapName,model:o.policy.lens.model}).ok),errors:Xo(e,t).errors}};var mO=new Set([It.scalar,It.ordered,It.array,It.dayList,It.dateValue]),gO=new Set([It.none,It.count]),yO=e=>{if(e.offset!==void 0||En(e).some(({source:r})=>r.value===void 0))return {values:[],dynamic:true};let t=Eo(e);return t?gO.has(t.valueShape)?{values:[],dynamic:false}:mO.has(t.valueShape)?"value"in e?{values:Mn(e)??[],dynamic:false}:{values:[],dynamic:false}:{values:[],dynamic:true}:{values:[],dynamic:true}},hO=e=>e instanceof Date?`d:${+e}`:e instanceof RegExp?`r:${e}`:typeof e=="object"&&e!==null?`j:${JSON.stringify(e)}`:`p:${typeof e}:${String(e)}`,_u=(e,t)=>{let r=M(t),o=r.lens.model,n=new Map,i=new Map,s=(l,d)=>{if(l.length===0)return;let p=Yo(r,{mapName:r.lens.mapName,modelName:o,relPath:[]},l.join("."));if(!p||p.jsonSubPath.length>0)return;let{mapName:f,modelName:u,relPath:m,terminalEffect:y,terminalFieldName:c}=p;if(!y.sources.has(c))return;let g=[o,...m].join("."),w=`${g}|${c}`,R=n.get(w);R||(R={path:g,mapName:f,model:u,field:c,values:[],dynamic:false},n.set(w,R));let S=yO(d);S.dynamic&&(R.dynamic=true);let b=i.get(w)??new Set;i.set(w,b);for(let $ of S.values){let E=hO($);b.has(E)||(b.add(E),R.values.push($));}},a=(l,d)=>{let p=qe(l,d);if(!("outOfBounds"in p))return [...p.scope,...p.path.split(".")]};return G(e,(l,d)=>{if(Fe(l))return;let p=typeof l.field=="string"?a(l.field,d):d.at(-1);return p?(!Se(l)&&typeof l.field=="string"&&s(p,l),[...d,p]):false},[[]]),[...n.values()]};var bs=(e,t,r,o)=>{let n=wO(e,t,r);if(n.options===t)return o(n.condition,n.options);try{return o(n.condition,n.options)}catch(i){if(i instanceof A||i instanceof k)throw i;try{o(e,n.options);}catch{throw i}throw new A(`${r}: the lens's clamps on this rule have no ${r} form \u2014 ${i.message}`,"unsupported_target")}},wO=(e,t,r)=>{if(t?.lens===void 0)return {condition:e,options:t};let{lens:o}=t;if(t.map!==void 0||t.mapName!==void 0||t.model!==void 0)throw new k(`${r}: pass \`lens\` or \`map\` / \`mapName\` / \`model\`, not both \u2014 the lens names its own`);let n=Xo(e,o);if(!n.ok)throw new Error(`${r}: the rule leaves the lens \u2014 ${n.errors.map(s=>`${s.path}: ${s.message}`).join("; ")}`);let i=nt(o);return {condition:Qo(e,o),options:{...t,lens:void 0,map:i,mapName:i.mapName,model:i.model}}};var Rs=(e,t,r,o)=>{if(!Vd.includes(e.operator))throw new Error(`'${e.operator}' does not apply to the enum '${e.field}'; compare its values with equals / in.`);let n=se(e.caseInsensitive),i=Ir(r,o?.enums),{values:s,hasNull:a}=We(ht.includes(e.operator)?[t]:t);if(!n&&(!i||s.every(f=>typeof f=="string"&&i.includes(f))))return null;if(!i)throw new Error(`'${e.field}' is an enum: a case-insensitive comparison reads its declared values, which the map doesn't list.`);let l=f=>n?f.toLowerCase():f,d=new Set(s.filter(f=>typeof f=="string").map(f=>l(f))),p=i.filter(f=>d.has(l(f)));return B.includes(e.operator)?{values:i.filter(f=>!p.includes(f)),matchesNull:!a}:{values:p,matchesNull:a}};var re=e=>`"${e.replace(/"/g,'""')}"`;var Re=e=>e.replace(/\\/g,"\\\\").replace(/%/g,"\\%").replace(/_/g,"\\_"),ka=(e,t,r=false)=>{let[o,...n]=e.split("."),i=t?`${re(t)}.${re(o)}`:re(o);if(n.length===0)return i;let s=n.map(Ca),a=s.pop();return [i,...s].join("->")+(r?"->":"->>")+a},Ca=e=>`'${e.replace(/'/g,"''")}'`;var SO=["@prisma/client/runtime/client","@prisma/client/runtime/library"],Os,bO=()=>{if(Os!==void 0)return Os;for(let e of RO())for(let t of SO)try{let r=e(t);if(r.AnyNull!==void 0)return Os=r.AnyNull,Os}catch{}},RO=()=>{let e=[];try{let t=globalThis.process?.getBuiltinModule?.("module")?.createRequire;t&&e.push(t(import.meta.url));}catch{}return typeof js=="function"&&e.push(js),e},Du=()=>{let e=ze.get("prismaOptions.anyNull")??bO();if(e===void 0)throw new Error("A null check on a Json field needs Prisma's AnyNull, and @prisma/client isn't installed: engineGlobals.set('prismaOptions.anyNull', Prisma.AnyNull).");return e};var Fu=(e,t)=>{let r=_r(tt(t));return r===null?null:Lr(e,r)},ju=(e,t,r)=>{if(e===null)return null;let o=jo(tt(t)),n=o&&Mr(o[0],kn);return !o||!n?null:lr(Rt(e),n,o[1],Wo(r).timeZone).toDate()};var La=(e,t)=>Ie(e,t?.map,t?.model),Nt=e=>e==="json"||e==="json-path",Rr=e=>Nt(e)?Du():null,zr=(e,t)=>t?.map&&t?.model?jf(e,t.map,t.model).map(r=>Ur(r,{is:null})):[],_a=(e,t)=>{let r=La(e,t);return [...Nt(r)||r==="list"||X(e.field,t?.map,t?.model)?.isRequired===false?[it(e.field,{equals:Rr(r)},t)]:[],...zr(e.field,t)]},xs=(e,t,r,o)=>{if(r.mode&&Nt(o)&&Array.isArray(t))throw F("toPrisma",`A case-insensitive comparison of a Json value with the list ${JSON.stringify(t)}`);if(!r.mode||typeof t!="string")return {[e]:t,...r};if(!Nt(o))return {[e]:Re(t),...r};if(/[%_\\"\u0000-\u001f]/.test(t))throw F("toPrisma",`A case-insensitive equality on Json against '${t}'`,"Prisma matches the JSON text, where %, _, a backslash, a quote or a control character doesn't read as itself");return {[e]:t,...r}},Da=(e,t,r,o)=>{let n=t?.datasource?.provider??ze.get("prismaOptions.datasource.provider");return se(e.caseInsensitive)&&Dd(n)&&yr(r,o)?{mode:"insensitive"}:{}},Iu=(e,t)=>{if(e==="list")return [{isEmpty:true}];let r=t?[{equals:""}]:[];return Nt(e)?[...r,{equals:[]}]:r},qu=e=>"isEmpty"in e?{isEmpty:false}:{not:e.equals},Fa=(e,t,r,o,n)=>{let i=a=>it(e,a,n),s=Iu(t,o);return r?W([i({equals:Rr(t)}),...zr(e,n),...s.map(a=>i(a))]):Ke([...t==="list"?[]:[i({not:Rr(t)})],...s.map(a=>i(qu(a)))])},xO=(e,t)=>{if(!Ut(e))throw sr(e.field);let o=(n=>it(e.field,n,t))({is:{}});return me({...e,field:"relation"},{relation:null})===true?Ce(o):o},EO=(e,t)=>X(e.field,t?.map,t?.model),Ma=rt(),$O=(e,t,r)=>{if(t==="list"||Nt(t)||EO(e,r)?.isRequired!==true)return null;let o=e.field.split(".").slice(0,-1).join(".");return o?it(o,{is:{}},r):Ma},Vu=(e,t)=>{let r=c=>it(e.field,c,t),o=La(e,t),n=()=>_a(e,t),i=rs(e,t?.map,t?.model);if(o==="relation")return xO(e,t);let s=$O(e,o,t),a=s&&(s===Ma?Et():Ce(s)),l=c=>s&&a?me({field:"f",operator:c,value:null},{f:null})===true?a:s:null;if(s&&a&&Ut(e)){let c=Iu(o,i);return e.operator===h.isEmpty?W([a,...c.map(r)]):e.operator===h.notEmpty?Ke([s,...c.map(g=>r(qu(g)))]):l(e.operator)}switch(e.operator){case h.exists:case h.notExists:{if(e.operator===h.exists)return o==="list"?Ce(r({equals:null})):r({not:Rr(o)});let c=n();return c.length?W(c):r({equals:Rr(o)})}case h.isEmpty:case h.notEmpty:return Fa(e.field,o,e.operator===h.isEmpty,i,t)}if(Ee(e)){let c=ss(e,t?.map,t?.model,Gf(t),zf(t));if("problem"in c)throw as(e.path,c.problem);let g=r({[c.key]:c.ref}),w=($,E)=>E.isRequired===false?it($,{equals:null},t):null,R=($,E)=>E.isRequired===false?it($,{not:null},t):Ma,S=w(e.field,c.field),b=w(c.columnPath,c.column);return e.operator===h.equals?S&&b?W([g,Ke([S,b])]):g:e.operator===h.notEquals?W([Ce(g),...S?[Ke([S,R(c.columnPath,c.column)])]:[],...b?[Ke([R(e.field,c.field),b])]:[]]):g}let d=Bu(e,t);if(be(e,d))return W(B.includes(e.operator)?n():[]);if(d===null&&ht.includes(e.operator)){let c=l(e.operator);if(c)return c}if(o==="list"&&ir.includes(e.operator)&&Array.isArray(d))return ae(Xi(e,d),t);if(o==="list"&&Array.isArray(d)&&d.includes(null))throw F("toPrisma",`A list holding null in '${e.field}'`);if(o==="list"&&se(e.caseInsensitive)&&yr("text",d))throw F("toPrisma",`A case-insensitive comparison on the list '${e.field}'`);let p=o==="enum"?X(e.field,t?.map,t?.model):void 0,f=p?Rs(e,d,p,t?.map):null;if(f){let c=r({in:f.values});return f.matchesNull?W([c,...n()]):c}if(ir.includes(e.operator)){let{values:c,hasNull:g}=We(d),w=Da(e,t,o,c),R=Nt(o)?e.operator===h.in?W(c.map(S=>r(xs("equals",S,w,o)))):Ke(c.map(S=>r(xs("not",S,w,o)))):r({[e.operator]:c,...w});return e.operator===h.in?g?W([R,...n()]):R:g?Ke([R,s??r({not:Rr(o)})]):W([R,...n()])}let u=c=>{if(!Nt(o)||c!==h.contains)return r(qn({...e,operator:c},t));let g=r({array_contains:[PO(e,d,t,o)]});return typeof d=="string"?W([r(qn({...e,operator:c},t)),g]):g};if(e.operator===h.contains)return u(h.contains);let m=Hd.includes(e.operator)?Sn[e.operator]:Po.includes(e.operator)?h.between:void 0;if(m){if(Nt(o))throw F("toPrisma",`'${e.operator}' on the Json value '${e.field}'`,"it keeps values of other types");return W([Ce(u(m)),...n()])}let y=r(qn(e,t));return e.operator===h.equals&&d===null?W([y,...zr(e.field,t)]):e.operator===h.notEquals&&o==="list"?d===null?Ce(r({equals:null})):W([Ce(r({equals:d})),...n()]):e.operator===h.notEquals&&d!==null?W([y,...n()]):y},Bu=(e,t)=>{let r=Zo(e,tt(e),mr(e.field,t?.map,t?.model),"toPrisma",()=>Wo(t).timeZone);return e.offset===void 0?r:Fu(r,e.offset)},qn=(e,t)=>{let r=Wi(e);if(r)throw r;let o=La(e,t),n=()=>Bu(e,t),i=d=>Da(e,t,o,d),s=d=>{let p=n();if(o==="list"){if(d!=="contains")throw new Error(`Operator '${d}' does not apply to the list '${e.field}'.`);return {has:p}}let f=Nt(o)?vO[d]:d,u=typeof p=="string"?Re(p):p;return {[f]:u,...i(p)}},a=Ui(e.operator,n());if(a)throw a;let l=or(e.operator,"field");if(l&&$o.includes(e.operator))return {[l]:n()};switch(e.operator){case h.equals:{let d=n()??Rr(o);return xs("equals",d,i(d),o)}case h.notEquals:{let d=n()??Rr(o);return xs("not",d,i(d),o)}case h.in:case h.notIn:return {[e.operator]:n()};case h.contains:return s("contains");case h.startsWith:return s("startsWith");case h.endsWith:return s("endsWith");case h.matches:case h.notMatches:throw F("toPrisma",`'${e.operator}'`,"Prisma has no pattern filter");case h.between:case h.notBetween:{let[d,p]=Be(Ye(n(),e.operator));return {gte:d,lte:p}}default:throw new Error(`Operator '${e.operator}' is built by buildFieldRule`)}},PO=(e,t,r,o)=>{if(typeof t=="object"&&t!==null)throw new Error(`Membership of an object or a list in the Json array '${e.field}' has no exact Prisma form; use toSql() or check().`);if(Da(e,r,o,t).mode)throw F("toPrisma",`A case-insensitive member of the Json array '${e.field}'`);return t},vO={contains:"string_contains",startsWith:"string_starts_with",endsWith:"string_ends_with"},it=(e,t,r)=>{if(!r?.map||!r?.model)return Ur(e,t);let o=te(e,r.map,r.model),n=o.hops.find(s=>s.entry.isList);if(n)throw To(e,n);let i=e.split(".");switch(o.kind){case "fallback":case "direct":return Ur(e,t);case "bridge":return Wr();case "past-scalar":throw ko(e,o.column);case "json-path":{let s={path:o.jsonPath,...t},a=i.slice(0,o.stopIndex).join(".");return Ur(a,s)}}};var Wu=(e,t,r)=>{if($e(e)){let o=Vo(e);if(!o)throw St("toPrisma");return ae(o,t,r)}if(!t?.map||!t?.model||!r)throw new Error("Aggregate rules require a FieldMap and model to generate a Prisma plan. Pass { map, model } options to toPrisma().");if(!yt.includes(e.aggregate.mode))throw ar(e.aggregate.mode);if(!e.aggregate.field)throw new Error("Prisma aggregate rules require aggregate.field to specify the numeric field on the related model.");return NO(e,t,r)},NO=(e,t,r)=>{let o=Ko(e.field,t.map,t.model,"Aggregate rules");if(e.condition&&xt(e.condition,t.map,o.target))return Wr();let n=e.aggregate.field??"",i=Pe(t.map,o.target,n);if(!i)throw new Error(`aggregate.field '${n}' does not exist on model '${o.target}'.`);if(i.kind!=="scalar"||je(i))throw new Error(`aggregate.field '${n}' on model '${o.target}' must be a numeric scalar, got ${i.kind==="scalar"?"Json":`'${i.kind}'`}.`);let s=Uo(t)(e);if(s===null||be(s,s.value))return Et();let a=An(s,[{}],void 0,{},{value:0})===true,l=a?Ue(s):s,d=qn(l,t),p={[e.aggregate.mode==="sum"?"_sum":"_avg"]:d},f=Po.includes(l.operator)?Ce({[n]:p}):{[n]:p},u=e.condition?ae(e.condition,Br({...t,model:o.target},t,true),r):rt(),m=ps(r,o,u,f,a);return a?W([m,...zr(e.field,t)]):m};var Ku=(e,t,r)=>{if(!e.field)throw new Error("toPrisma: count-based ArrayRule requires a field path");let o=Ko(e.field,t.map,t.model,"Count operators");if(e.condition===void 0)throw De(e.arrayOperator);if(e.count===void 0)throw Ao(e.arrayOperator);let n=e.count;if(e.arrayOperator===x.atLeast&&n===0)return rt();let i=ae(e.condition,Br({...t,model:o.target},t,true),r),s=ja(e),a=s?Uu(x.atLeast,e.arrayOperator===x.atMost?n+1:1,o.targetKey):Uu(e.arrayOperator,n,o.targetKey);return ps(r,o,i,a,s)},Uu=(e,t,r)=>{let o=or(e,"array");if(!o)throw new Error(`'${e}' does not count`);return {[r]:{_count:{[o]:t}}}};var Gu=(e,t,r)=>{let o=zu(e,t,r);return e.field&&ja(e)&&!Hu(e.field,t)?W([o,...zr(e.field,t)]):o},ja=e=>me({...e,field:"items"},{items:[]})===true,AO=e=>{let t=Js(e);if(!t)return null;let{count:r,...o}=e;return {...o,arrayOperator:t}},zu=(e,t,r)=>{if($e(e)){let s=Vo(e);if(!s)throw St("toPrisma");return ae(s,t,r)}if(e.condition!==void 0&&!Gd.includes(e.arrayOperator)&&xt(e.condition,t?.map,Ju(e,t)?.model))return Wr();let o=AO(e);if(o)return zu(o,t,r);if(yn.includes(e.arrayOperator)){if(t?.map&&t?.model&&r)return Ku(e,t,r);throw new Error(`ArrayOperator '${e.arrayOperator}' requires a FieldMap and model to generate a multi-step plan. Pass { map, model } options to toPrisma(). Without them, use prisma.$queryRaw for count-based relation filtering.`)}if(!e.field)throw Vi("toPrisma");let{field:n}=e;if(Hu(n,t))return TO(e,n,Ie({field:n},t?.map,t?.model),t);let i=kO(e,t,r);return it(e.field,i,t)},Hu=(e,t)=>{let r=Ie({field:e},t?.map,t?.model);return r==="list"||r==="json"||r==="json-path"},TO=(e,t,r,o)=>{switch(e.arrayOperator){case x.empty:case x.notEmpty:return Fa(t,r,e.arrayOperator===x.empty,false,o);default:throw F("toPrisma",`'${e.arrayOperator}' over the ${r==="list"?"list":"Json array"} '${t}'`,r==="list"?"test a list's membership with 'contains'":void 0)}},Ju=(e,t)=>{if(!t?.map||!t?.model||!e.field)return t&&Br({...t});let r=Tn(e.field,t.map,t.model);return Br(r?{...t,model:r}:{...t})},kO=(e,t,r)=>{let o=Ju(e,t);switch(e.arrayOperator){case x.all:if(!e.condition)throw De(e.arrayOperator);return {none:ae(Ue(e.condition,Uo(o)),o,r)};case x.any:if(!e.condition)throw De(e.arrayOperator);return {some:ae(e.condition,o,r)};case x.none:if(!e.condition)throw De(e.arrayOperator);return {none:ae(e.condition,o,r)};case x.empty:return {none:{}};case x.notEmpty:return {some:{}};default:throw le(e.arrayOperator,"array")}};var Qu=(e,t)=>{let r=t?.map,o=Ie({field:e.field},r,t?.model);if(o==="json"||o==="json-path")throw F("toPrisma",`A date rule on the Json value '${e.field}'`,"Prisma compares Json text");let n=X(e.field,r,t?.model);if(n&&!V(n)&&et(n)!==Q.DateTime)throw F("toPrisma",`A date rule on the ${n.type} field '${e.field}'`,`Prisma compares it as ${n.type}, not as an instant`);let i=B.includes(e.dateOperator)?_a(e,t):[],s=CO(e,t);if(s===null)return W(i);let a=it(e.field,s,t),l=Po.includes(e.dateOperator)?Ce(a):a;return W([l,...i])},CO=(e,t)=>{let r=Wo(t),o=kn,n=m=>e.offset===void 0?m:ju(m,e.offset,t),i=m=>{if(m==null)return null;if(!Y(m))return Zi(m,r.timeZone);let y=bt(m,o);return y&&Mo(y,e.dateOperator,r).toDate()},s=()=>{let m=tt(e);if(m==null)return m;let y=e.offset===void 0?void 0:tt(e.offset),c=Wt(m,y);if(c)throw c;return m},a=()=>n(i(s())),l=()=>{let m=s();if(m==null)return null;let y=Ye(m,e.dateOperator).map(i);if(y[0]===null||y[1]===null)return null;let[c,g]=Be(y).map(n);return c&&g?[c,g]:null},d=()=>{let m=s();if(m==null)return null;if(!Y(m))throw Qe(e.dateOperator);let y=bt(m,o);if(!y)return null;let[c,g]=Lo(y,r);return [c.toDate(),g.toDate()]},p=m=>{let y=a();return y===null?null:{[m]:y}},f=m=>m?{gte:m[0],lte:m[1]}:null,u=or(e.dateOperator,"date");if(u)return p(u);switch(e.dateOperator){case v.within:case v.notWithin:return f(d());case v.between:case v.notBetween:return f(l());case v.dayIn:case v.dayNotIn:throw F("toPrisma",`'${e.dateOperator}'`);default:throw le(e.dateOperator,"date")}};var Ia=(e,t,r)=>{if(typeof e=="boolean")return e?{}:Et();vi(e,"toPrisma");let o=ne(e);(o==="field"||o==="date")&&os(e.field,t?.map,t?.model);let n=e;switch(o){case "all":return Yf(n,t,r);case "any":return Xf(n,t,r);case "if":return eu(n,t,r);case "array":return Gu(n,t,r);case "aggregate":return Wu(n,t,r);case "date":return Qu(n,t);case "field":return Vu(n,t);default:throw wt()}};Qf(Ia);var Yu=async(e,t)=>{let r=e.steps.filter(i=>i.operation==="groupBy"),o=e.steps.find(i=>i.operation==="where");if(!o)throw new Error("executePrismaPlan: result has no where step");let n=[];for(let i of r){let s=Xu(t,i.model),a=Zu(i.args,i.refs,n,t),l=await s[i.operation](a);n.push(l.map(d=>d[i.extract]).filter(d=>d!=null));}return Zu(o.where,o.refs,n,t)},Xu=(e,t)=>{let r=t.charAt(0).toLowerCase()+t.slice(1),o=e[r];if(!o)throw new Error(`executePrismaPlan: no delegate for model '${t}'. Ensure prismaDelegate has a key '${r}'.`);return o},MO=(e,t)=>{let r=Xu(e,t.model).fields,o=r&&Object.hasOwn(r,t.field)?r[t.field]:void 0;if(o===void 0)throw new Error(`executePrismaPlan: the '${t.model}' delegate has no field reference '${t.field}' (fields.${t.field}).`);return o},LO=(e,t)=>t.reduce((r,o)=>r!==null&&typeof r=="object"&&Object.hasOwn(r,o)?r[o]:void 0,e),qa=(e,t,r)=>{if(t.length===0)return r;let[o,...n]=t,i=e,s=Array.isArray(e)?[...e]:{...i};return s[o]=qa(i[o],n,r),s},Zu=(e,t,r,o)=>{let n=e;for(let{path:i}of t??[]){let s=LO(e,i);if(s&&typeof s.__step=="number"){let a=s.__step;if(a>=r.length)throw new Error(`Step ref __step: ${a} out of range (${r.length} steps executed)`);n=qa(n,i,r[a]);}else if(s&&typeof s.__field=="object"&&s.__field!==null)n=qa(n,i,MO(o,s.__field));else throw new Error(`executePrismaPlan: no reference at the recorded location ${i.join(".")}`)}return n};var _O=e=>e?.map?{...e,map:ve(e.map,e.mapName,"toPrisma")}:e,Vn=(e,t)=>bs(e,t,"toPrisma",DO),DO=(e,t)=>{let r={steps:[]},o=Ia(e,_O(t),r),n=(i,s)=>{let a=Wf(s);return a.length?{...i,refs:a}:i};return {steps:[...r.steps.map(i=>n(i,i.args)),n({operation:"where",where:o},o)]}};var FO=/^-?\d+(\.\d+)?$/,ec=e=>typeof e=="string"?FO.test(e)?Number(e):e:typeof e=="object"&&e!==null&&typeof e.toNumber=="function"?e.toNumber():e,Va=(e,t)=>e?.kind!=="scalar"||e.type!=="Decimal"?t:Array.isArray(t)?t.map(ec):ec(t);var Es=(e,t,r,o,n)=>{let i=`${r.mapName}\0${r.modelName}`;for(let a of t){if(typeof a=="boolean")continue;let l=e.memo?.compiles.get(a)??new Map;e.memo?.compiles.set(a,l);let d=l.get(i);if(d===void 0){let[p]=zo(a,{target:"toPrisma",map:e.lens,mapName:r.mapName,model:r.modelName}).errors;d=p?p.message:null,l.set(i,d);}if(d!==null)return new A(`${o}: ${d}`,"unsupported_clamp")}if(n)return null;let s=false;for(let a of t)G(a,l=>{("aggregate"in l||hn(l))&&(s=true);});return s?new A(`${o} needs a counting step (executePrismaPlan), which a relation's where in a select can't run`,"unsupported_clamp"):null},$s=(e,t)=>{try{return t()}catch(r){throw r instanceof A||r instanceof k?r:new A(`${e}: ${r.message}`,"unsupported_clamp")}};var tc=(e,t)=>e===""?t:t===""?e:`${e}.${t}`,Ge=e=>{let t=new Set,r=n=>{n&&t.add(n);},o=(n,i)=>{let s=qe(n,i);return "outOfBounds"in s?null:tc(s.scope,s.path)};return G(e,(n,i)=>{if(Fe(n))return;for(let l of dr(n))r(L(l)?o(l,i):l);let s=typeof n.field=="string"&&n.field!==""?o(n.field,i):null;if(r(s),!Se(n))return;let a=s??i[i.length-1];for(let l of Do(n))r(tc(a,l));return [...i,a]},[""]),[...t]};var Ba=(e,t,r,o,n)=>{let i={};for(let[s,a]of Object.entries(o.fields)){if(!vt(t,s))continue;let l=t.enumValuesByField.get(s),d=n(s)?.filter(f=>l===void 0||l.includes(f.value)),p=tn(e,t,r,s,"groupBy")?t.sourceGroupBys.get(s):void 0;i[s]={...a,...l!==void 0&&{values:l},...d!==void 0&&{options:d},...p!==void 0&&{groupBy:p}};}return i},rc=(e,t,r,o,n)=>{let{mapName:i,modelName:s}=t,a=T(O(e.lens.maps,i),s),l=Ba(e,r,t,a,m=>{let y=n.get(`${o}|${m}`),c=r.enumValuesByField.get(m);return y??O(a.fields,m)?.options??c?.map(g=>({value:g,label:g}))}),d={};for(let[m,y]of r.sources)vt(r,m)&&(d[m]=y);let p={};for(let[m,y]of r.sourceLabels)vt(r,m)&&tn(e,r,t,m,"label")&&(p[m]=y);let f={};for(let[m,y]of r.sourceGroupBys)vt(r,m)&&tn(e,r,t,m,"groupBy")&&(f[m]=y);let u={};for(let m of r.sourcesFromMapDefaults.keys()){if(!ws(e,i,s,m))throw Ss(o,i,s,m);Object.hasOwn(d,m)&&(u[m]="mapDefaults");}return {mapName:i,model:s,fields:l,whereClauses:r.whereClauses,sources:d,sourceLabels:p,sourceGroupBys:f,sourceFrom:u}},oc=e=>{let t=new Map;for(let r of e.sourceValues??[])t.set(`${r.path}|${r.field}`,r.options);return t},nc=(e,t={})=>Bn(M(e),t),Bn=(e,t={})=>{let r=oc(t),o={};for(let{path:n,at:i,effect:s}of zt(e))o[n]=rc(e,i,s,n,r);return o},ic=(e,t,r={})=>Wa(M(e),t,r),Wa=(e,t,r={})=>{let o={mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]};if(t!=="")for(let s of cr(e.lens.maps,o,t)){let a=D(e,s.at.mapName,s.at.modelName,s.at.relPath);if(!s.next||!a.relations.has(s.field))return null;o={...s.next,relPath:[...s.at.relPath,s.field]};}if(!T(O(e.lens.maps,o.mapName),o.modelName))return null;let n=D(e,o.mapName,o.modelName,o.relPath),i=[e.lens.model,...o.relPath].join(".");return rc(e,o,n,i,oc(r))};var Ps=(e,t,r,o,n)=>{let i=e.split("."),{hops:s}=Ne(t,{mapName:r,modelName:o,relPath:[]},e),a=s.find((f,u)=>f.isList&&u<i.length-1);if(a)return `${n} cannot traverse to-many relation '${i[s.indexOf(a)]}'`;if(s.length===i.length)return `${n} must end on a scalar column, '${i.at(-1)}' is a relation`;let l=s.at(-1)??{map:r,model:o},d=i[s.length],p=Pe(O(t,l.map),l.model,d);return p?V(p)?`${n} relation '${d}' has no resolvable target`:s.length===i.length-1?null:`${n} segment '${d}' is not a relation`:`${n} segment '${d}' not on model '${l.model}'`},sc=(e,t,r,o,n,i,s,a)=>{let l=Ps(n,e.lens.maps,t,r,i);if(l)throw new A(`${i} '${n}': ${l}`,"invalid_source");let{hops:d}=Ne(e.lens.maps,{mapName:t,modelName:r,relPath:o},n),p=d.slice(0,n.split(".").length-1);for(let f of p){let u=f.relPath.join(".");if(s.has(u))continue;s.add(u);let m=D(e,f.map,f.model,f.relPath);for(let y of m.whereClauses)a.push(Jo(y,f.prefix));}},jO=(e,t,r,o,n,i)=>{let s=[],a=new Set;for(let l of n)sc(e,t,r,o,l,"groupBy",a,s);return i?.includes(".")&&sc(e,t,r,o,i,"label",a,s),s},Wn=(e,t)=>{let r=ue(e,t);return r==null||typeof r=="object"?void 0:String(r)},vs=(e,t)=>{let r=[];for(let o of t){let n=Wn(e,o);if(n===void 0)return;r.push(n);}return r},Ua=(e,t)=>JSON.stringify([e??null,t]),IO=(e,t,r,o)=>{let n=Ua(o,t),i=e.get(n);i===void 0?e.set(n,{value:t,...r!==void 0?{label:r}:{},...o!==void 0?{groups:o}:{}}):r!==void 0&&(i.label===void 0||r<i.label)&&e.set(n,{...i,label:r});},Ns=(e,t,r,o,n)=>{let i=ue(t,r),s=o==null?void 0:String(o);for(let a of Array.isArray(i)?i:[i])a==null||typeof a=="object"||IO(e,String(a),s,n);},As=e=>[...e.values()].sort((t,r)=>{let o=(t.groups===void 0?0:1)-(r.groups===void 0?0:1);if(o!==0)return o;let n=t.groups??[],i=r.groups??[];for(let s=0;s<Math.max(n.length,i.length);s++){let a=(n[s]??"").localeCompare(i[s]??"","en",{numeric:true});if(a!==0)return a}return (t.label??t.value).localeCompare(r.label??r.value,"en",{numeric:true})||t.value.localeCompare(r.value,"en",{numeric:true})}),qO=(e,t,r,o,n)=>{let{hops:i}=te(n,t,o),s=n.split("."),a=i.at(-1)?.entry.type??o,l=s[i.length];for(let{endpoints:d}of e.bridges??[]){let[p,f]=d;for(let[u,m]of [[p,f],[f,p]])if(u.fieldMap===r&&u.model===a&&ke(m)===l)return [...s.slice(0,i.length),u.on].join(".")}throw new A(`'${n}' crosses no bridge the lens declares on ${a}`,"not_in_lens")},Ts=(e,t,r,o)=>{let n=ve(e,t,"toPrisma");return [...new Set(o.map(i=>gr(i,n,r)?qO(e,n,t,r,i):i))]},VO=(e,t,r,o)=>{if(t.length===0)return [];let n={mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]},{hops:i,end:s}=Ne(e.lens.maps,n,t.join("."));if(!s)throw new A(`source at '${t.join(".")}': its path doesn't resolve on the field maps`,"not_in_lens");let a=[n,...i.map(p=>({mapName:p.map,modelName:p.model}))],l=t.length;for(;l>0&&!r.has(t.slice(0,l).join("."));)l--;let d=l>0?r.get(t.slice(0,l).join("."))??null:null;for(let p=l;p<t.length;p++){let f=E=>{d=E,r.set(t.slice(0,p+1).join("."),E);},u=a[p],m=D(e,u.mapName,u.modelName,t.slice(0,p)).whereClauses,y=d===null?m:[...m,d];if(y.length===0&&!o){f(null);continue}let c=O(e.lens.maps,u.mapName),g=c&&Pe(c,u.modelName,t[p]);if(!g)throw new A(`source at '${t.join(".")}': '${t[p]}' isn't declared on ${u.modelName}`,"not_in_lens");let w=a[p+1],R=ke({fieldMap:u.mapName,model:u.modelName}),S=g.kind==="bridge"?Pe(O(e.lens.maps,w.mapName),w.modelName,R):void 0,b=g.kind==="bridge"?S&&{field:R,entry:S}:c?ls(c,u.modelName,t[p],g):null;if(!b&&y.length===0){f(null);continue}if(!b)throw new A(`source at '${t.join(".")}': '${t[p]}' on ${u.modelName} declares no inverse, so the clamps above can't be carried down to it`,"unsupported_clamp");let $=z(y);try{let E={field:b.field,operator:"exists"};f(b.entry.isList?{field:b.field,arrayOperator:"any",condition:$}:y.length?z([E,Jo($,b.field)]):E);}catch(E){throw E instanceof A?new A(`source at '${t.join(".")}': the clamps above can't be carried down to it \u2014 ${E.message}`,E.code):E}}return d===null?[]:[d]},ac=e=>Or(M(e)),Or=(e,t=Bn(e))=>{let r=new Map,o=n=>{let i=r.get(n)??new Map;return r.set(n,i),i};return Object.entries(t).flatMap(([n,i])=>Object.keys(i.sources).map(s=>{let a=O(i.sourceLabels,s),l=O(i.sourceGroupBys,s),d=Object.hasOwn(i.sourceFrom,s),p={mapName:i.mapName,modelName:i.model,relPath:n.split(".").slice(1)},f=D(e,p.mapName,p.modelName,p.relPath),u=(f.sourceWheres.get(s)??[]).map(N=>Kr(N,e,p)),m=jO(e,p.mapName,p.modelName,p.relPath,l??[],a),y=O(i.fields,s)?.values,c=d?f.sourcesFromMapDefaults.get(s):void 0,g=c===void 0?void 0:e.chain[c],R=[...VO(g===void 0?e:{...e,skipClampsOf:g},p.relPath,o(g),g===void 0&&!d),...u,...m,...y?[{field:s,operator:"in",value:[...y]}]:[]],S=z([...i.whereClauses,...R]),b=z([...i.whereClauses,...u,...m,...y?[{field:s,operator:"in",value:[...y]}]:[]]),$=e.lens.bridges?.length?ve(e.lens,p.mapName,"toPrisma"):void 0,E=$?[...Ge(S),...a===void 0?[]:[a],...l??[]].find(N=>gr(N,$,p.modelName)):void 0,I=E!==void 0&&$?z(oa(S).filter(N=>xt(N,$,p.modelName))):void 0,pe=Es(e,[...i.whereClauses,...R],p,`source '${s}' at '${n}'`,true);if(pe)throw pe;return {path:n,visit:i,field:s,...d&&{from:"mapDefaults"},...a!==void 0&&{label:a},...l!==void 0&&{groupBy:l},where:S,rowWhere:b,...E!==void 0&&{bridged:E},...I!==void 0&&{recheck:I}}}))};var za=(e,t)=>{for(let r of t){let o=e;for(let n of r.split("."))o=Kt(o,n,()=>({}));}return e},ks=(e,t)=>{for(let[r,o]of Object.entries(t))ks(Kt(e,r,()=>({})),o);return e},Ha=e=>e.whereClauses.flatMap(Ge),lc=(e,t)=>{let r=new Map;for(let o of t){if(o.from)continue;let n=o.path.split(".").slice(1).join("."),i=[o.field,...o.label===void 0?[]:[o.label],...o.groupBy??[],...Ge(o.rowWhere)];r.set(n,[...r.get(n)??[],...o.bridged===void 0?i:Ts(e.lens,o.visit.mapName,o.visit.model,i)]);}return r},pc=(e,t)=>e.get(t.relPath.join("."))??[],BO=(e,t,r)=>za(ks({},r??{}),Ha(D(e,t.mapName,t.modelName,t.relPath))),dc=e=>({mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]}),Ja=(e,t,r)=>({...r,relPath:[...e.relPath,t]}),WO=(e,t,r,o)=>{if(!r.whereClauses.length)return;let n=z(r.whereClauses),i=Es(e,r.whereClauses,t,`toLensSelect: the clamp on '${t.relPath.join(".")}'`,false);if(i)throw i;if(e.inspect)return;let s=$s(`toLensSelect: the clamp on '${t.relPath.join(".")}'`,()=>Vn(n,{...o,map:e.lens,mapName:t.mapName,model:t.modelName})),{where:a}=s.steps[0];return Object.keys(a).length?a:void 0},UO=(e,t,r,o)=>{let n=T(e,o.type)?.fields??{},i=a=>{let l=a===void 0?void 0:O(n,a);return l&&!V(l)?a:void 0},s=e?ls(e,t,r,o):null;return i(o.toFields?.[0])??i(s?.entry.fromFields?.[0])??i("id")},fc=(e,t,r,o,n,i)=>{let s=T(O(e.lens.maps,t.mapName),t.modelName)?.fields??{},a=D(e,t.mapName,t.modelName,t.relPath),l=r==="paths"?o:za(ks({},o),[...Ha(a),...pc(i,t)]),d={};for(let[p,f]of Object.entries(s)){let u=r!=="paths"&&vt(a,p),m=O(l,p);if(!u&&m===void 0||f.kind==="bridge")continue;if(f.kind!=="object"){d[p]=true;continue}let y=u?"declared":"paths";if(y==="paths"&&m===void 0)continue;let c=Ja(t,p,{mapName:t.mapName,modelName:f.type}),g=fc(e,c,y,m??{},n,i),w=f.isList&&y!=="paths"&&m===void 0?WO(e,c,D(e,c.mapName,c.modelName,c.relPath),n):void 0,R=Object.keys(g).length?void 0:UO(O(e.lens.maps,t.mapName),t.modelName,p,f),S=R===void 0?g:{[R]:true};Object.keys(S).length&&(d[p]={select:S,...w&&{where:w}});}return d},uc=(e,t={})=>Qa(M(e),t),Qa=(e,t={},r=Or(e))=>{let o=fc(e,dc(e),"declared",{},t,lc(e,r));if(!Object.values(o).some(n=>n===true)){let n=O(T(O(e.lens.maps,e.lens.mapName),e.lens.model)?.fields,"id");n&&!V(n)&&(o.id=true);}return {select:o}},Ka=(e,t)=>e==null?e:Array.isArray(e)?e.flatMap(r=>{let o=typeof r=="object"&&r!==null?t(r):null;return o===null?[]:[o]}):typeof e=="object"?t(e):null,Ga=(e,t,r,o)=>{let n={},i=T(O(e.lens.maps,t.mapName),t.modelName);for(let[s,a]of Object.entries(o)){if(!Object.hasOwn(r,s))continue;let l=O(i?.fields,s),d=l?Xe(l,t.mapName):null;n[s]=d?Ka(r[s],p=>Ga(e,Ja(t,s,d),p,a)):Va(l,r[s]);}return n},cc=(e,t,r,o,n,i,s)=>{let a=D(e,t.mapName,t.modelName,t.relPath);if(!a.whereClauses.every(f=>me(f,r,i)===true))return null;let l=T(O(e.lens.maps,t.mapName),t.modelName)?.fields??{},d=n?za(ks({},o),[...Ha(a),...pc(s,t)]):{},p={};for(let[f,u]of Object.entries(l)){if(!Object.hasOwn(r,f))continue;let m=O(d,f),y=Xe(u,t.mapName);if(!y){(vt(a,f)||m!==void 0)&&(p[f]=Va(u,r[f]));continue}let c=Ja(t,f,y);if(vt(a,f)){let g=!Array.isArray(r[f])||m!==void 0;p[f]=Ka(r[f],w=>cc(e,c,w,m??{},n,i,s)??(n&&g?Ga(e,c,w,BO(e,c,m)):null));}else m!==void 0&&(p[f]=Ka(r[f],g=>Ga(e,c,g,m)));}return p},mc=(e,t,{keepClampColumns:r=false,...o}={})=>{let n=M(e),i=dc(n),s=r?lc(n,Or(n)):new Map;return t.flatMap(a=>{let l=cc(n,i,a,{},r,o,s);return l===null?[]:[l]})};var KO="materializeSources needs fetched or keepClampColumns rows, not viewer rows",Za=(e,t,r)=>new k(`${e}: a row at '${t}' ${r}${r.includes(":")?" \u2014 rows across a bridge hold the far side inline under its bridge field":""}`),Un=(e,t,r,o,n,i=KO)=>{for(let s of n){let a=[r];for(let{index:l,field:d,entry:p,next:f}of cr(e.lens.maps,t,s)){if(!p)break;let u=s.split(".").slice(0,l+1).join("."),m=[];for(let y of a){if(y===null||typeof y!="object")continue;if(!Object.hasOwn(y,d))throw Za(i,o,`lacks '${u}', which a read needs`);let c=y[d];if(f&&c==null&&p.fromFields?.some(g=>{let w=y[g];return w!=null}))throw Za(i,o,`'${u}' is null while its key is set \u2014 a projection hid the row`);if(!(!f||c===null||c===void 0)){if(Array.isArray(c)!==(p.isList===true))throw Za(i,o,`'${u}' holds ${Array.isArray(c)?"a list where it names one row":"one row where it names a list"}`);m.push(...Array.isArray(c)?c:[c]);}}if(!f)break;a=m;}}},Ya=(e,t)=>{let r={mapName:e.lens.mapName,modelName:e.lens.model,relPath:[]};return [r,...Ne(e.lens.maps,r,t.split(".").slice(1).join(".")).hops.map(o=>({mapName:o.map,modelName:o.model,relPath:o.relPath}))]},GO=(e,t,r,o)=>{let n=r.split(".").slice(1),i=Ya(e,r),s=(l,d)=>{let p=i[l],f=D(e,p.mapName,p.modelName,p.relPath).whereClauses,u=z(f),m=f.flatMap(Ge),y=[e.lens.model,...n.slice(0,l)].join(".");return d.filter(c=>(Un(e,p,c,y,m),me(u,c,o)===true))},a=s(0,t);for(let[l,d]of n.entries()){let p=[],f=[e.lens.model,...n.slice(0,l)].join(".");for(let u of a){Un(e,i[l],u,f,[d]);let m=ue(u,d);Array.isArray(m)?p.push(...m):m!=null&&p.push(m);}a=s(l+1,p);}return {rows:a,visit:i[i.length-1]}},gc=(e,t,r)=>{let o=M(e);return Or(o).map(({path:n,visit:i,field:s,from:a,label:l,groupBy:d,rowWhere:p})=>{if(a)throw new k(`materializeSources: '${n}.${s}' offers its model's own source, which a fetched collection can't hold \u2014 query it with toSourceQueries and materializeSourceQuery.`);let f=[s,...Ge(p),...l===void 0?[]:[l],...d??[]],u=new Map,m=GO(o,t,n,r);for(let y of m.rows)Un(o,m.visit,y,n,f),me(p,y,r)===true&&Ns(u,y,s,l===void 0?void 0:Wn(y,l),d===void 0?void 0:vs(y,d));return {path:n,mapName:i.mapName,model:i.model,field:s,options:As(u)}})};var Cs={value:"value",query:"query"},yc=(e,t,r={})=>{let{rowShape:o="prisma",lens:n,order:i=Cs.value,...s}=r,a=o==="sql",{recheck:l}=e,d=y=>false,p=y=>true;if(l!==void 0){if(n===void 0)throw new k(`materializeSourceQuery: '${e.path}.${e.field}' reads across a bridge \u2014 its rows are candidates; pass { lens } with rows holding the far side`);let y=M(n),c=Ya(y,e.path).at(-1);if(!c||c.mapName!==e.mapName||c.modelName!==e.model)throw new k(`materializeSourceQuery: the lens doesn't reach ${e.mapName}:${e.model} at '${e.path}' \u2014 pass the lens the query was compiled from`);let g=ve(y.lens,e.mapName,"toPrisma");d=S=>g!==void 0&&gr(S,g,e.model);let w=[...Ge(l),...e.label!==void 0&&d(e.label)?[e.label]:[],...(e.groupBy??[]).filter(d)],R="materializeSourceQuery needs candidate rows holding the far side of each bridge the source reads";p=S=>(Un(y,c,S,e.path,w,R),me(l,S,s)===true);}let f=y=>e.label===void 0?void 0:a&&e.label.includes(".")&&!d(e.label)?y.__label:Wn(y,e.label),u=e.groupBy?.map((y,c)=>a&&!d(y)?`__group_${c}`:y),m=new Map;for(let y of t)p(y)&&Ns(m,y,e.field,f(y),u===void 0?void 0:vs(y,u));return {path:e.path,mapName:e.mapName,model:e.model,field:e.field,options:i===Cs.query?[...m.values()]:As(m)}};var zO=(e,t)=>`${e}::${t}`,HO=(e,t,r)=>{let o=e.get(t);if(!o){e.set(t,r.values?{...r,values:[...r.values]}:r);return}let n=o;if(r.values&&o.values){let i=new Set([...o.values,...r.values]);n={...n,values:[...i]};}else !r.values&&o.values&&(n={...n,values:void 0});r.groupBy!==void 0&&n.groupBy===void 0&&(n={...n,groupBy:r.groupBy}),n!==o&&e.set(t,n);},hc=(e,t={})=>Xa(M(e),t),Xa=(e,t={})=>{let{lens:r}=e,o=new Map;for(let l of t.sourceValues??[]){let d=`${l.mapName}::${l.model}::${l.field}`,p=o.get(d)??new Map;for(let f of l.options)p.set(Ua(f.groups,f.value),f);o.set(d,p);}let n=new Map;for(let{at:l,effect:d}of zt(e)){let{mapName:p,modelName:f}=l,u=T(O(r.maps,p),f);if(!u)continue;let m=zO(p,f),y=n.get(m);y||(y={mapName:p,modelName:f,fields:new Map},n.set(m,y));let c=Ba(e,d,l,u,g=>{let w=o.get(`${p}::${f}::${g}`);return w&&[...w.values()]});for(let[g,w]of Object.entries(c)){let R=w.groupBy,S=y.fields.get(g)?.groupBy;if(R!==void 0&&S!==void 0&&JSON.stringify(S)!==JSON.stringify(R))throw new A(`projectLens: '${f}.${g}' is grouped by different axes on different paths ([${S}] vs [${R}]) \u2014 one surface field cannot carry two partition namespaces`,"invalid_source");HO(y.fields,g,w);}}let i={};for(let{mapName:l,modelName:d,fields:p}of n.values()){let f=O(i,l);f||(f={models:{}},i[l]=f);let u={},m=new Map;for(let[y,c]of p)if(u[y]=c.options===void 0&&c.values?{...c,options:c.values.map(g=>({value:g,label:g}))}:c,c.kind==="enum"&&c.values){let g=m.get(c.type)??new Set;for(let w of c.values)g.add(w);m.set(c.type,g);}f.models[d]={...T(O(r.maps,l),d),fields:u};for(let[y,c]of m)f.enums??={},f.enums[y]=[...c];}let s=r.bridges?.filter(l=>{let[d,p]=l.endpoints,f=Pe(O(i,d.fieldMap),d.model,ke(p)),u=Pe(O(i,p.fieldMap),p.model,ke(d));return f!==void 0||u!==void 0}),a={maps:i};return s&&s.length>0&&(a.bridges=s),{...a,mapName:r.mapName,model:r.model}};var wc=(e,t,r,o,n)=>{if(e===void 0)return;let i=Ho(e),s=o==="root.where"?null:i.bare;if(s!==null){n.push({path:o,code:"invalid_value_source",message:xa(s).message});return}let{escaping:a}=i;if(a!==null){n.push({path:o,code:"scope_out_of_bounds",message:Ea(a).message});return}let l=new Set,d={...t,clamp:t.chain.length===0};for(let{mapName:p,modelName:f,relPath:u}of r)for(let m of Ln(e,d,p,f,u)){let y=`'${m.path}' ${m.message}`;l.has(y)||(l.add(y),n.push({path:o,code:m.code,message:y}));}},JO=(e,t,r,o,n,i)=>{let s={...r,chain:[...r.chain,t]},a=new Set;for(let l of o){let d=D(s,l.mapName,l.modelName,l.relPath);for(let[p,f]of Object.entries(e.sources??{})){let u=br(f);for(let m of ["label","groupBy"]){if(u[m]===void 0||a.has(`${p}|${m}`))continue;let y=m==="label"?u.label:Fn(u.groupBy),c=m==="label"?d.sourceLabels.get(p):d.sourceGroupBys.get(p);if(JSON.stringify(y)!==JSON.stringify(c))continue;let w=(typeof c=="string"?[c]:c??[]).map(R=>In(s,l,R)).find(R=>R!==null);if(w){a.add(`${p}|${m}`),i.push({path:`${n}.sources.${p}`,code:"invalid_source",message:`${m} '${String(u[m])}' crosses '${w}', a relation the lens does not show there (not turned on, or omitted)`});continue}tn(s,d,l,p,m)||(a.add(`${p}|${m}`),i.push({path:`${n}.sources.${p}`,code:"invalid_source",message:`${m} '${String(u[m])}' reads a column hidden by another layer`}));}}}},QO=(e,t,r,o)=>{for(let n of r){if(!t&&n.picks&&!n.picks.includes(e))return "not in ancestor's picks";if(n.omits?.includes(e))return "was omitted by ancestor"}return !t&&o?.picks&&!o.picks.includes(e)?"not visible from defaults.picks":o?.omits?.includes(e)?"already excluded by defaults":null},ZO=(e,t,r,o,n,i,s,a,l,d,p,f,u=false)=>{let m=e.omits?.some(c=>{let g=O(i,c);return g===void 0||!V(g)});e.picks&&m&&d.push({path:`${l}`,code:"conflicting_selection",message:"cannot specify both picks and omits of a column"});for(let c of ["picks","omits"])for(let g of e[c]??[]){let w=O(i,g);if(!w){d.push({path:`${l}.${c}`,code:"not_in_lens",message:`field '${g}' not on model`});continue}let R=V(w);if(R&&c==="picks"){d.push({path:`${l}.picks`,code:"wrong_kind",message:`'${g}' is a relation: picks names columns; turn a relation on with \`relations\``});continue}let S=QO(g,R,t,r);S&&d.push({path:`${l}.${c}`,code:"not_visible",message:`'${g}' ${S}`});}let y=(c,g,w)=>{let R=O(i,g);if(!R){d.push({path:`${l}.${c}`,code:"not_in_lens",message:`field '${g}' not on model`});return}if(R.kind!=="enum"){d.push({path:`${l}.${c}`,code:"wrong_kind",message:`field '${g}' is not an enum field`});return}let S=Ir(R,a);for(let b of w)S&&!S.includes(b)&&d.push({path:`${l}.${c}.${g}`,code:"value_not_allowed",message:`'${b}' is not a known value of enum '${R.type}'`});};for(let[c,g]of Object.entries(e.enumPicks??{}))y("enumPicks",c,g);for(let[c,g]of Object.entries(e.enumOmits??{}))y("enumOmits",c,g);wc(e.where,p,f,`${l}.where`,d);for(let[c,g]of Object.entries(e.sources??{})){let w=O(i,c);if(!w){d.push({path:`${l}.sources`,code:"not_in_lens",message:`field '${c}' not on model`});continue}if(V(w)){d.push({path:`${l}.sources.${c}`,code:"wrong_kind",message:`'${c}' is a relation: a source offers a column's values`});continue}let R;try{R=br(g);}catch(E){if(!(E instanceof A))throw E;d.push({path:`${l}.sources.${c}`,code:E.code,message:E.message});continue}let S=R.from;if(S!==void 0){let E=S!=="mapDefaults"?`from takes 'mapDefaults', not '${String(S)}'`:u?"a mapDefaults source is what a path source's from: 'mapDefaults' points at; it can't point itself":R.label!==void 0||R.groupBy!==void 0?"a from: 'mapDefaults' source takes the model source's label and groupBy":null;E&&d.push({path:`${l}.sources.${c}`,code:"invalid_source",message:E});}let b=R.label?.includes(".")?R.label:void 0;if(R.label!==void 0)if(b){let E=Ps(b,o,n,s,"label");E&&d.push({path:`${l}.sources.${c}`,code:"invalid_source",message:`${E}`});}else {let E=O(i,R.label);E?V(E)&&d.push({path:`${l}.sources.${c}`,code:"wrong_kind",message:`label '${R.label}' is a relation, not a column`}):d.push({path:`${l}.sources.${c}`,code:"not_in_lens",message:`label column '${R.label}' not on model`});}let $=Fn(R.groupBy);if($!==void 0||b!==void 0){let E=/^__(group(_\d+)?|label)$/;(E.test(c)||R.label!==void 0&&E.test(R.label))&&d.push({path:`${l}.sources.${c}`,code:"invalid_source",message:"'__group*' / '__label' names are reserved on grouped or path-labeled sources (sql column aliases)"});}if($!==void 0){for(let I of $){let pe=Ps(I,o,n,s,"groupBy");pe&&d.push({path:`${l}.sources.${c}`,code:"invalid_source",message:`${pe}`});}let E=JSON.stringify($);for(let I of t){let pe=O(I.sources,c);if(pe===void 0)continue;let N=Fn(br(pe).groupBy);N!==void 0&&JSON.stringify(N)!==E&&d.push({path:`${l}.sources.${c}`,code:"not_visible",message:`groupBy [${$}] conflicts with an ancestor layer's groupBy [${N}]`});}}wc(R.where,p,f,`${l}.sources.${c}`,d);}},YO=(e,t,r,o,n)=>{for(let[i,s]of Object.entries(t)){let a=O(r,i);if(!a){n.push({path:`mapDefaults.${e}.enums.${i}`,code:"not_in_lens",message:"enum not in registry"});continue}let l=null,d=new Set;for(let f of o){let u=f[i];if(u&&(u.picks&&(l=hs(l,u.picks)),u.omits))for(let m of u.omits)d.add(m);}let p=f=>!(d.has(f)||l&&!l.has(f));for(let f of s.picks??[])a.includes(f)?p(f)||n.push({path:`mapDefaults.${e}.enums.${i}.picks`,code:"not_visible",message:`'${f}' not visible from ancestors`}):n.push({path:`mapDefaults.${e}.enums.${i}.picks`,code:"value_not_allowed",message:`'${f}' not a known value`});for(let f of s.omits??[])a.includes(f)?p(f)||n.push({path:`mapDefaults.${e}.enums.${i}.omits`,code:"not_visible",message:`'${f}' already excluded by ancestors`}):n.push({path:`mapDefaults.${e}.enums.${i}.omits`,code:"value_not_allowed",message:`'${f}' not a known value`});}},XO=(e,t,r,o,n,i,s)=>{let a=D(t,r.mapName,r.modelName,r.relPath);for(let l of ["enumPicks","enumOmits"])for(let[d,p]of Object.entries(e[l]??{})){let f=O(o,d);if(f?.kind!=="enum")continue;let u=Ir(f,n)??[],m=gs(a,d)??u;for(let y of p)u.includes(y)&&!m.includes(y)&&s.push({path:`${i}.${l}.${d}`,code:"not_visible",message:`'${y}' is not visible (not allowed by the inherited enum narrowing)`});}},Sc=(e,t,r,o)=>e.map(n=>({mapName:o,modelName:r,relPath:[...n.relPath,t]})),el=(e,t,r,o,n,i,s,a,l,d,p)=>{let f=O(n,i),u=T(f,s);if(!u)return;let m=o.length===0,y={...d,chain:[...d.chain,r],unvetted:true},c=p.isDefault?void 0:O(O(r.mapDefaults,i)?.models,s),w=[...o.map(b=>O(O(b.mapDefaults,i)?.models,s)).filter(b=>b!==void 0),...t],R={mapName:i,modelName:s,relPath:Oa};ZO(e,w,c,n,i,u.fields,s,f?.enums,a,l,d,m?p.isDefault?[R,...p.parent]:p.parent:p.composed,p.isDefault),XO(e,p.isDefault?d:{...d,chain:[...d.chain,{parent:r.parent,mapDefaults:r.mapDefaults}],unvetted:true},p.isDefault?R:p.parent[0]??R,u.fields,f?.enums,a,l),JO(e,r,d,p.composed,a,l);let S={...d,chain:[...d.chain,r]};if(!p.isDefault)for(let[b,$]of Object.entries(e.sources??{}))!jn($)||$.from!=="mapDefaults"||ws(S,i,s,b)||l.push({path:`${a}.sources.${b}`,code:"invalid_source",message:Ss([nt(r).model,...p.parent[0]?.relPath??[]].join("."),i,s,b).message});for(let[b,$]of Object.entries(e.relations??{})){let E=O(u.fields,b);if(!E){l.push({path:`${a}.relations`,code:"not_in_lens",message:`'${b}' not on model`});continue}if(!V(E)){l.push({path:`${a}.relations`,code:"wrong_kind",message:`'${b}' is not a relation (kind=${E.kind})`});continue}let I=q=>D(d,q.mapName,q.modelName,q.relPath).relations.has(b),pe=q=>D(y,q.mapName,q.modelName,q.relPath).relations.has(b);if(!m&&!(p.isDefault?p.parent.some(I):p.parent.every(I))){l.push({path:`${a}.relations`,code:"not_visible",message:`'${b}' is not shown by the parent${p.isDefault?` wherever ${s} is visited`:""}: only the first narrowing over the base lens turns a relation on`});continue}let N=Xe(E,i);if(!N)continue;if(!T(O(n,N.mapName),N.modelName)){l.push({path:`${a}.relations.${b}`,code:"not_in_lens",message:"target model not found in lens"});continue}let j=t.map(q=>O(q.relations,b)).filter(q=>q!==void 0);el($,j,r,o,n,N.mapName,N.modelName,`${a}.relations.${b}`,l,d,{parent:Sc(p.isDefault?p.parent.filter(I):p.parent,b,N.modelName,N.mapName),composed:Sc(p.composed.filter(pe),b,N.modelName,N.mapName),isDefault:p.isDefault});}},tl=e=>{let t=[];try{ex(e,t);}catch(r){if(!(r instanceof A))throw r;t.some(o=>o.code===r.code)||t.push({path:"",code:r.code,message:r.message});}return Sr(t)},ex=(e,t)=>{let r=nt(e),o=$t(e.parent),n=M(e.parent),i=zt(n),s=[],a=u=>{try{u();}catch(m){if(!(m instanceof A))throw m;s.push(m);}},l=null,d=()=>(l??=zt({...n,chain:[...n.chain,e],unvetted:true}),l);for(let[u,m]of Object.entries(e.mapDefaults??{})){let y=O(r.maps,u);if(!y){t.push({path:`mapDefaults.${u}`,code:"not_in_lens",message:"not in lens"});continue}let c=o.map(g=>O(g.mapDefaults,u)?.enums).filter(g=>g!==void 0);for(let[g,w]of Object.entries(m.models??{})){if(!T(y,g)){t.push({path:`mapDefaults.${u}.models.${g}`,code:"not_in_lens",message:"not in fieldMap"});continue}let S=o.map(E=>O(O(E.mapDefaults,u)?.models,g)).filter(E=>E!==void 0),b=E=>E.map(({at:I})=>I).filter(I=>I.mapName===u&&I.modelName===g),$=[];a(()=>{$=b(d());}),a(()=>el(w,S,e,o,r.maps,u,g,`mapDefaults.${u}.models.${g}`,t,n,{parent:b(i),composed:$,isDefault:!0}));}m.enums&&YO(u,m.enums,y.enums,c,t);}if(e.root){let u=r.mapName,m=r.model,y=O(r.maps,u);if(!y)t.push({path:"root",code:"not_in_lens",message:`lens map '${u}' not in lens`});else if(!T(y,m))t.push({path:"root",code:"not_in_lens",message:`lens model '${m}' not in fieldMap`});else {let c=o.map(w=>w.root).filter(w=>w!==void 0),g={mapName:u,modelName:m,relPath:[]};a(()=>el(e.root,c,e,o,r.maps,u,m,"root",t,n,{parent:[g],composed:[g],isDefault:!1}));}}for(let u of Nu(e))t.push({path:"bindings",code:"invalid_binding",message:u});let p={...n,chain:[...n.chain,e],inspect:true},f;a(()=>{f=Or(p,Bn(p));}),a(()=>Xa(p)),a(()=>Qa(p,{},f)),a(()=>{let u=new Map;for(let{at:m}of d()){u.set(m.relPath.join("."),m),a(()=>Wa(p,m.relPath.join(".")));let y=m.relPath.at(-1),c=u.get(m.relPath.slice(0,-1).join("."));if(y===void 0||!c)continue;let w=Pe(O(r.maps,c.mapName),c.modelName,y)?.isList?{field:y,arrayOperator:"any",condition:!0}:{field:y,operator:"exists"};a(()=>Kr(w,p,c));}});for(let u of s)t.some(m=>u.message.includes(m.message))||t.push({path:"",code:u.code,message:u.message});},Ms=e=>Cn(tl(e),"validateNarrowing");function bc(e,{by:t="path",...r}={}){return t==="model"?hc(e,r):nc(e,r)}var Rc=(e,t,r,o={})=>{let n=M(e),{resolution:i}=Gr(n,Pt(n),r);if(i.outcome!=="resolved")return {ok:false,reason:i.outcome};let{hops:s,terminal:a,jsonSubPath:l}=i;if(V(a.entry))return {ok:false,reason:"relation"};if(s.some(f=>f!==a&&f.entry.isList))return {ok:false,reason:"list"};let d=(f,u)=>u!==null&&typeof u=="object"&&D(n,f.mapName,f.model,f.relPath).whereClauses.every(m=>me(m,u,o)===true),p=d(s[0],t)?t:null;for(let[f,u]of s.entries()){if(p===null||typeof p!="object")return {ok:true,value:null};let m=O(p,u.field);if(u===a)return {ok:true,value:l.length?ue(m,l.join(".")):m};p=d(s[f+1],m)?m:null;}return {ok:true,value:null}};var tx=e=>"maps"in e,Oc=(e,t)=>{let r=i=>{let s=O(t,i);if(!s)throw new Error(`composeLens: no stored lens '${i}'`);return s},o=[...r(e).parents,e];if(new Set(o).size!==o.length)throw new Error(`composeLens: '${e}' lists a layer twice in its parents`);let n=null;for(let[i,s]of o.entries()){let a=r(s);if(Object.hasOwn(a,"parent"))throw new Error(`composeLens: '${s}' carries a parent; a layer composes only through \`parents\``);let{id:l,parents:d,...p}=a;if(d.join("\0")!==o.slice(0,i).join("\0"))throw new Error(`composeLens: '${s}' composes with [${d.join(", ")}], not [${o.slice(0,i).join(", ")}] as '${e}' lists`);if(tx(a)!==(i===0))throw new Error(i===0?`composeLens: '${s}' is not a base lens, so it can't head '${e}''s parents`:`composeLens: '${s}' is a base lens, so it can only head a chain`);if(n===null){n=p;continue}let u={parent:n,...p};Ms(u),n=u;}return n},xc=(e,t)=>{let r=ot(e)?[]:$t(e);if(t.length!==r.length+1)throw new Error(`storeLens: the lens has ${r.length+1} layers, base included, but ${t.length} ids`);return [{...nt(e),id:t[0],parents:[]},...r.map(({parent:o,...n},i)=>({...n,id:t[i+1],parents:t.slice(0,i+1)}))]};var Ec=e=>e instanceof Date?e.toISOString():Array.isArray(e)&&e.some(t=>t instanceof Date)?e.map(Ec):e,_=(e,t)=>(e.params.push(Ec(t)),`$${++e.paramIndex}`);var Ht=(e,t,{jsonb:r=false}={})=>{let o=()=>({sql:ka(e,void 0,r),shape:e.includes(".")?"json-path":"unknown"});if(!t.map||!t.currentModel||!t.currentAlias)return o();let n=te(e,t.map,t.currentModel);if(n.kind==="past-scalar")throw ko(e,n.column);if(n.kind==="bridge")throw new Error(`'${e}' crosses a bridge to another source; toSql() has no column for it`);if(n.kind==="fallback"||n.entry.kind==="object"&&n.entry.isList)return o();let i=n.hops.find(p=>p.entry.isList);if(i)throw To(e,i);let s=t.currentAlias;for(let p of n.hops){let f=$c(t,s,p);if(!f)return o();s=f;}let a=qr(n);if(n.kind==="direct"&&n.entry.kind==="object"){let p={field:n.column,entry:n.entry,from:n.model},f=hr(t.map,n.model,n.entry),u=$c(t,s,p);return !f||!u?o():{sql:`${re(u)}.${re(f[0].there)}`,shape:a}}let l=n.kind==="json-path"?[n.column,...n.jsonPath]:[n.column],d=ka(l.join("."),s,r);return {sql:a==="json"&&!r?`NULLIF(${d}, 'null'::jsonb)`:d,shape:a}},At=(e,t,r)=>Ht(e,t,r).sql,$c=(e,t,r)=>{let o=`${t}.${r.field}`,n=e.joinRegistry?.get(o);if(n)return n;if(!e.joinCounter||!e.map)return null;let i=`t${e.joinCounter.n+1}`,s=rx(e.map,r.from,t,r.entry,i);return s?(e.joinCounter.n+=1,e.joins?.push(s),e.joinRegistry?.set(o,i),i):null},rx=(e,t,r,o,n)=>{let i=o.type,s=T(e,i)?.dbName??i,a=hr(e,t,o);if(!a)return null;let l=a.map(({here:d,there:p})=>`${re(n)}.${re(p)} = ${re(r)}.${re(d)}`).join(" AND ");return `LEFT JOIN ${re(s)} AS ${re(n)} ON ${l}`};var Jt={type:"value",value:null},Tt=e=>e.type==="value"&&(e.value===null||e.value===void 0),ox=(e,t)=>{let r=L(e)??{depth:1,path:e};if(r.depth>1)throw new Error(un(e,"toSql"));let o=Ht(r.path,t);if(o.shape==="relation")throw new Error(`'${e}' is a relation; a value ref reads a column`);return {type:"column",...o}},Oe=(e,t)=>xn(e,{value:r=>({type:"value",value:r}),path:r=>ox(r,t),bind:(r,o)=>({type:"value",value:zi(r,o,"toSql")})}),Hr=e=>t=>{let r=Oe(t,e);if(r.type==="column")throw new Error(`'${t.path}' is a row ref`);return r.value},st=e=>Dr(e.dateConfig??{},Hr(e));var nx={lt:"<",lte:"<=",gt:">",gte:">=",equals:"="},rn=(e,t)=>{let r=or(e,t);return r?{symbol:nx[r],negated:B.includes(e)}:void 0},Pc=(e,t)=>e.type==="column"?e.sql:_(t,e.value),Me=(e,t)=>`(${t} OR ${e} IS NULL)`,kt=(e,t,r=true)=>t&&r?`${e} IS NULL`:"FALSE",Ls=(e,t,r,o,n)=>{if(Tt(r))return kt(e,o);let i=`${e} ${t} ${Pc(r,n)}`;return o?Me(e,i):i},Kn=(e,t,r,o,n=true)=>{if(!t||t.some(Tt))return kt(e,r,n);let[i,s]=t.map(f=>Pc(f,o)),a=t.some(f=>f.type==="column"),l=a?"SYMMETRIC ":"";if(!r)return `${e} BETWEEN ${l}${i} AND ${s}`;let d=`${e} NOT BETWEEN ${l}${i} AND ${s}`,p=a?`(${d} AND ${i} IS NOT NULL AND ${s} IS NOT NULL)`:d;return n?Me(e,p):p};var Ac=()=>{let e=ze.get("sql.dialect");if(!Ld(e))throw new k(`toWhereSql: sql.dialect '${String(e)}' is not a SQL dialect \u2014 ${Object.values(So).join(", ")} are`);return e},Z=e=>new Error(`toWhereSql: ${e} has no SQL form here \u2014 it writes ${Hs.join(", ")}, all and any, and ${Qs.join(", ")} over a to-many relation.`),Tc=(e,t)=>rl(e,t,""),vc=(e,t,r,o)=>{let n=Object.hasOwn(e,o)?e[o]:void 0;if(typeof n!="string"||n==="")throw new k(`toWhereSql: no ${r} for '${o}' in \`${t}\``);return n},rl=(e,t,r,o={clamps:()=>[]})=>{Ac();let{columns:n,tables:i={},map:s,mapName:a,model:l}=t??{};if(typeof n!="object"||n===null)throw new k("toWhereSql: `columns` maps each field path to its SQL");if(typeof i!="object"||i===null)throw new k("toWhereSql: `tables` maps each to-many relation path to its table");if(!s||!l)throw new k("toWhereSql: `map` and `model` are required \u2014 a literal is typed by its column, and a date, Json or list value is refused by it");let d=ve(s,a,"toWhereSql");if(!T(d,l))throw new k(`toWhereSql: the map has no model '${l}'`);return on(e,{map:d,model:l,column:p=>vc(n,"columns","column",`${r}${p}`),table:p=>vc(i,"tables","table",`${r}${p}`),clamps:"clamps"in o?o.clamps:()=>[],joined:"joined"in o?o.joined:null,joinedRow:null})},on=(e,t)=>{if(typeof e=="boolean")return e?"TRUE":"FALSE";let r=e;switch(ne(r)){case "all":{let o=r.all;return o.length?`(${o.map(n=>on(n,t)).join(" AND ")})`:"TRUE"}case "any":{let o=r.any;return o.length?`(${o.map(n=>on(n,t)).join(" OR ")})`:"FALSE"}case "field":return sx(e,t);case "if":throw Z("if / then / else");case "array":return ix(e,t);case "aggregate":throw Z("aggregate");case "date":throw Z(`dateOperator '${String(r.dateOperator)}'`);default:throw Z("a condition that is not exactly one node kind")}},ix=(e,t)=>{let{arrayOperator:r,field:o}=e;if(!Qs.includes(r))throw Z(`arrayOperator '${r}'`);if($e(e))throw Z(`a window (filter / orderBy / take / skip) on '${o}'`);if(!o)throw Z(`the fieldless arrayOperator '${r}'`);let n=te(o,t.map,t.model);if(n.kind==="fallback")throw new Error(`toWhereSql: '${o}' is not a field the map declares on ${t.model}`);if(n.kind==="bridge")throw Z(`'${o}', which crosses a bridge`);if(n.hops.length)throw Z(`arrayOperator '${r}' on '${o}', behind the relation '${n.hops[0].prefix}'`);if(n.kind!=="direct"||qr(n)!=="relations")throw Z(`arrayOperator '${r}' on '${o}', which is not a to-many relation`);let i=hr(t.map,n.model,n.entry);if(!i)throw Z(`'${o}', whose relation keys the map does not declare`);if(_i.includes(r)&&e.condition===void 0)throw De(r);if(t.joinedRow!==null)throw new Error(`toWhereSql: arrayOperator '${r}' on '${o}' inside an any over the joined '${t.joinedRow}' \u2014 a joined row's own to-many relations have no join here; compile with toMany: 'subquery'`);let s={map:t.map,model:n.entry.type,column:p=>t.column(`${o}.${p}`),table:p=>t.table(`${o}.${p}`),clamps:p=>t.clamps(`${o}.${p}`),joined:t.joined,joinedRow:null};if(t.joined){if(zd.includes(r))throw new Error(`toWhereSql: arrayOperator '${r}' on '${o}', a relation the caller joins, holds when it has no rows \u2014 that takes an anti-join, not the topic's join. Only notEmpty and any(condition) read a joined relation; compile with toMany: 'subquery' for the rest`);t.joined(o,r);let p=`${s.column(i[0].there)} IS NOT NULL`;return r!==x.any?p:`(${p} AND ${on(e.condition,{...s,joinedRow:o})})`}let a=[...i.map(({here:p,there:f})=>`${s.column(f)} = ${t.column(p)}`),...t.clamps(o).map(({where:p,clamps:f})=>`(${on(p,{...s,clamps:f})})`)],l=p=>`(SELECT 1 FROM ${t.table(o)} WHERE ${[...a,...p?[p]:[]].join(" AND ")})`,d=()=>`(${on(e.condition,s)})`;switch(r){case x.any:return `EXISTS ${l(d())}`;case x.none:return `NOT EXISTS ${l(d())}`;case x.all:return `NOT EXISTS ${l(`${d()} IS NOT TRUE`)}`;case x.empty:return `NOT EXISTS ${l()}`;default:return `EXISTS ${l()}`}},sx=(e,t)=>{if(!Hs.includes(e.operator))throw Z(`operator '${e.operator}'`);if(e.bind!==void 0)throw Z(`bind '${e.bind}' on '${e.field}'`);if(e.path!==void 0)throw Z(`comparing '${e.field}' with the column '${e.path}'`);if(e.offset!==void 0)throw Z(`an offset on '${e.field}'`);if(e.coerceType!==void 0)throw Z(`coerceType on '${e.field}'`);if(se(e.caseInsensitive))throw Z(`a case-insensitive comparison on '${e.field}'`);if(L(e.field))throw Z(`the scoped field '${e.field}'`);let r=te(e.field,t.map,t.model),o=ax(e,r,t),[n]=r.kind==="direct"?cs(e,et(r.entry)):[];if(n)throw new Error(`toWhereSql: ${n.message}`);if(e.operator===h.exists)return `${o} IS NOT NULL`;if(e.operator===h.notExists)return `${o} IS NULL`;if(e.value===void 0)throw new Error("No value, path or bind specified");let i=Zo(e,e.value,r,"toWhereSql",()=>Ze);if(be(e,i))return kt(o,B.includes(e.operator));let s=a=>lx(a,e.field);switch(e.operator){case h.equals:return i===null?`${o} IS NULL`:`${o} = ${s(i)}`;case h.notEquals:return i===null?`${o} IS NOT NULL`:Me(o,`${o} <> ${s(i)}`);case h.in:{let{values:a,hasNull:l}=We(Nc(e,i));if(!a.length)return l?`${o} IS NULL`:"FALSE";let d=`${o} IN (${a.map(s).join(", ")})`;return l?Me(o,d):d}default:{let{values:a,hasNull:l}=We(Nc(e,i));if(!a.length)return l?`${o} IS NOT NULL`:"TRUE";let d=`${o} NOT IN (${a.map(s).join(", ")})`;return l?`(${d} AND ${o} IS NOT NULL)`:Me(o,d)}}},ax=(e,t,r)=>{if(t.kind==="fallback")throw new Error(`toWhereSql: '${e.field}' is not a field the map declares on ${r.model}`);if(t.kind==="past-scalar")throw ko(e.field,t.column);if(t.kind==="bridge")throw Z(`'${e.field}', which crosses a bridge`);let o=t.hops.find(s=>s.entry.isList);if(o)throw To(e.field,o);let n=qr(t),i=Ut(e);if(r.joinedRow!==null&&(t.hops.length||n==="relation"))throw new Error(`toWhereSql: '${e.field}' inside an any over the joined '${r.joinedRow}' reads the relation '${t.hops[0]?.prefix??e.field}' \u2014 a joined row's own relations have no join here; compile with toMany: 'subquery'`);if(n==="relation"&&t.kind==="direct"){if(!i)throw sr(e.field);let s=hr(r.map,t.model,t.entry);if(!s)throw Z(`'${e.field}', whose relation keys the map does not declare`);return r.column(`${e.field}.${s[0].there}`)}if(n==="relations")throw new Error(`toWhereSql: '${e.field}' is a to-many relation \u2014 its rows take an arrayOperator rule: { field: '${e.field}', arrayOperator: 'notEmpty' } for a row${r.joined?"; for no rows, compile with toMany: 'subquery'":", 'empty' for none"}`);if(n==="json"||n==="json-path")throw Z(`the Json value '${e.field}'`);if(i)return r.column(e.field);if(n==="instant")throw Z(`the date '${e.field}'`);if(n==="list")throw Z(`the list '${e.field}'`);return r.column(e.field)},Nc=(e,t)=>{if(!Array.isArray(t))throw new Error(`toWhereSql: '${e.operator}' on '${e.field}' takes a list of values`);return t},lx=(e,t)=>{if(typeof e=="string"){let r=e.replace(/'/g,"''");return `'${Ac()===So.mysql?r.replace(/\\/g,"\\\\"):r}'`}if(typeof e=="number"&&Number.isFinite(e)||typeof e=="bigint")return String(e);if(typeof e=="boolean")return e?"TRUE":"FALSE";throw Z(`the value ${e instanceof Date?"a Date":JSON.stringify(e)} for '${t}'`)};var px=(e,t,r)=>{G(r,(o,n)=>{if(typeof o.field!="string")return;let i=In(e,n,o.field);if(i!==null)throw new Error(`toLensWhereSql: '${o.field}' at ${n.relPath.length?`'${n.relPath.join(".")}'`:"the root"} crosses '${i}', a relation the lens hides \u2014 a hop's clamps are reported at its own path, so a where may only cross hops the lens shows`);return Se(o)?Ne(e.lens.maps,n,o.field).end??false:void 0},t);},Mc=(e,t,r)=>{let{end:o}=Ne(e.lens.maps,t,r);if(!o)return null;let{pathWheres:n,modelWheres:i}=D(e,o.mapName,o.modelName,o.relPath);return {end:o,clamps:[...n.map(s=>({...s,isDefault:false})),...i.map(s=>({...s,isDefault:true}))]}},Lc=(e,t,r)=>o=>{let n=Mc(e,t,o);return n?n.clamps.filter(i=>i.layer<r).map(i=>({where:i.where,clamps:Lc(e,n.end,i.layer)})):[]},kc=(e,t,r,o)=>{let n=e.map(({where:i,layer:s})=>rl(i,t,r,o(s)));return n.length===1?n[0]:`(${n.join(" AND ")})`},dx=(e,t)=>{let r=new Set,o=new Map;return n=>({joined:(i,s)=>{let a=Mc(e,t,i);if(!a)throw new Error(`toLensWhereSql: '${i}' reaches no relation`);let{end:l,clamps:d}=a,p=d.find(f=>f.layer>=n);if(p)throw new Error(`toLensWhereSql: the root where of layer ${n+1} reads '${i}' on the caller's join, whose ON carries a clamp of layer ${p.layer+1} (${p.isDefault?`${l.modelName}'s default where`:"its where"}) \u2014 check() reads a where through the clamps of the layers above its own only. Move that clamp into a narrowing above layer ${n+1}, or compile with toMany: 'subquery'`);if(d.some(f=>f.isDefault)){let f=`${l.mapName}.${l.modelName}`,u=o.get(f),m=l.mapName===t.mapName&&l.modelName===t.modelName?`the root is a ${l.modelName} too`:u!==void 0&&u!==i?`the root where also reads '${u}', which reaches ${l.modelName} too`:null;if(m!==null)throw new Error(`toLensWhereSql: the root where reads '${i}' on the caller's join, and ${l.modelName} has a default where, but ${m} \u2014 mapDefaults holds one predicate per model, which reads one table alias, and two aliases need it. Compile with toMany: 'subquery'`);o.set(f,i);}if(s===x.any){if(r.has(i))throw new Error(`toLensWhereSql: the root reads '${i}' with two any rules \u2014 on the caller's join one joined row stands for the relation, so both conditions would have to hold on the same row, where check() lets each find its own. Write one any whose condition says which row, or compile with toMany: 'subquery'`);r.add(i);}}})},Cc=(e,t)=>()=>({joined:r=>{throw new Error(`toLensWhereSql: ${e} reads the to-many relation '${r}' \u2014 with toMany: 'join' ${t}; only the root's where reads a joined relation`)}}),_c=(e,{columns:t,tables:r,toMany:o="subquery"})=>{if(o!=="subquery"&&o!=="join")throw new k(`toLensWhereSql: toMany '${String(o)}' is neither 'subquery' nor 'join'`);let n=M(e),i={root:null,relations:{},mapDefaults:{}};for(let{at:s,effect:a}of zt(n)){let l={columns:t,tables:r,map:n.lens,mapName:s.mapName,model:s.modelName},d=p=>({clamps:Lc(n,s,p)});for(let{where:p}of [...a.pathWheres,...a.modelWheres])px(n,s,p);if(a.pathWheres.length){let p=s.relPath.join("."),f=o==="subquery"?d:p?Cc(`the where at '${p}'`,"it sits in that relation's join ON, ahead of the joins below it"):dx(n,s),u=kc(a.pathWheres,l,p?`${p}.`:"",f);p?i.relations[p]=u:i.root=u;}if(a.modelWheres.length){let p=Kt(i.mapDefaults,s.mapName,()=>({models:{}})),f=o==="subquery"?d:Cc(`the default where of ${s.modelName}`,`it compiles once for every path that reaches ${s.modelName}, and the join exists only where the lens shows the relation`),u=kc(a.modelWheres,l,`${s.modelName}.`,f),m=O(p.models,s.modelName);if(m!==void 0&&m!==u)throw new Error(`toLensWhereSql: the default where of ${s.modelName} reads a to-many relation whose clamps differ between the paths that reach ${s.modelName} \u2014 a model default compiles to one predicate for every path`);p.models[s.modelName]=u;}}return i};var Dc=e=>Array.isArray(e)?e.some(Dc):typeof e=="object"&&e!==null,Fc=(e,t,r,o)=>{let n=`NULLIF(${t}, 'null'::jsonb)`,i=`jsonb_typeof(${n})`,s=`(${n} #>> '{}')`,a=S=>`${_(o,JSON.stringify(S))}::jsonb`,l=se(e.caseInsensitive),d=S=>l?`LOWER(${S})`:S,p=B.includes(e.operator),f=S=>Me(n,`NOT (${S})`);if(be(e,r))return kt(n,p);let u=Ui(e.operator,r);if(u)throw u;let m=S=>{if(Dc(S))throw F("toSql",`A case-insensitive comparison of '${e.field}' with a list holding objects`);return a(jr(S))},y=S=>l&&typeof S=="string"?`(${i} = 'string' AND LOWER(${s}) = LOWER(${_(o,S)}))`:l&&Array.isArray(S)?`(${i} = 'array' AND LOWER(${n}::text)::jsonb = ${m(S)})`:`${n} = ${a(S)}`,c=S=>`(${i} = 'string' AND ${d(s)} LIKE ${d(_(o,S))})`,g=S=>{let b=$=>`(CASE WHEN ${i} = 'array' THEN EXISTS (SELECT 1 FROM jsonb_array_elements(${n}) AS e WHERE ${$}) ELSE FALSE END)`;return l&&typeof S=="string"?b(`jsonb_typeof(e) = 'string' AND LOWER(e #>> '{}') = LOWER(${_(o,S)})`):l&&Array.isArray(S)?b(`LOWER(e::text)::jsonb = ${m(S)}`):typeof S=="object"&&S!==null?b(`e = ${a(S)}`):`(${i} = 'array' AND ${n} @> ${a([S])})`},w=S=>typeof S=="string"?`(${c(`%${Re(S)}%`)} OR ${g(S)})`:g(S);switch(e.operator){case h.equals:return r===null?`${n} IS NULL`:y(r);case h.notEquals:return r===null?`${n} IS NOT NULL`:f(y(r));case h.in:case h.notIn:{let{values:S,hasNull:b}=We(r),$=S.length?`(${S.map(y).join(" OR ")})`:"FALSE";return e.operator===h.in?b?`(${$} OR ${n} IS NULL)`:$:b?`(NOT ${$} AND ${n} IS NOT NULL)`:f($)}case h.between:case h.notBetween:{let[S,b]=r,$=`(${i} = jsonb_typeof(${a(S)}) AND ${n} BETWEEN ${a(S)} AND ${a(b)})`;return e.operator===h.between?$:f($)}case h.contains:return w(r);case h.notContains:return f(w(r));case h.startsWith:return c(`${Re(String(r))}%`);case h.endsWith:return c(`%${Re(String(r))}`);case h.notStartsWith:return f(c(`${Re(String(r))}%`));case h.notEndsWith:return f(c(`%${Re(String(r))}`));case h.matches:case h.notMatches:{let{source:S,caseInsensitive:b}=ur(r),$=`(${i} = 'string' AND ${s} ~${b?"*":""} ${_(o,Nn(S))})`;return e.operator===h.matches?$:f($)}}let R=rn(e.operator,"field")?.symbol;if(R)return `(${i} = jsonb_typeof(${a(r)}) AND ${n} ${R} ${a(r)})`;throw new Error(`Operator '${e.operator}' is not supported on a Json value in SQL`)};var jc=e=>typeof e=="object"&&kr(e)!==null,Gn=({sql:e,shape:t},r)=>{if(t!=="json-path"&&t!=="text")return `to_timestamp(EXTRACT(EPOCH FROM ${e}))`;let o=_(r,st(r).timeZone);return `(CASE WHEN btrim(${e}) ~ '^-?[0-9]+(\\.[0-9]+)?$' THEN to_timestamp(btrim(${e})::numeric / 1000) WHEN ${e} ~* '[0-9]{2}:[0-9]{2}(:[0-9]{2}(\\.[0-9]+)?)?\\s*(z|[+-][0-9]{2}(:?[0-9]{2})?)\\s*$' OR ${e} ~* '\\m(gmt|utc)\\M' THEN (${e})::timestamptz ELSE (${e})::timestamp AT TIME ZONE ${o} END)`},_s=e=>Object.values(e).some(jc),ux=(e,t,r)=>{let o=Ar(r),n=o?"int":"double precision";if(typeof e=="number"||!jc(e)){let a=aa(e,Hr(t),r);return `${_(t,a)}::${n}`}let i=Oe(e,t).sql;return `(CASE WHEN ${o?`${i} >= 0 AND ${i} = trunc(${i})`:`${i} >= 0`} THEN ${i} END)::${n}`},cx=(e,t)=>`make_interval(${tf.flatMap(o=>{let n=Object.keys(e).filter(i=>e[i]!==void 0&&Je[i].interval===o).map(i=>{let s=ux(e[i],t,i),{factor:a}=Je[i];return a===1?s:`${a} * ${s}`});return n.length?[`${o} => ${n.join(" + ")}`]:[]}).join(", ")})`,zn=(e,t,r,o)=>{let n=st(o).timeZone;if(e.type==="value"&&!_s(t)){let l=Mr(t,Hr(o));return e.value===null||e.value===void 0||l===null?Jt:{type:"value",value:lr(Rt(e.value),l,r,n).toDate()}}let i=e.type==="column"?e.computed?e.sql:Gn(e,o):`${_(o,e.value??null)}::timestamptz`,s=_(o,n);return {type:"column",computed:true,sql:`(((${i} AT TIME ZONE ${s}) ${r===1?"+":"-"} ${cx(t,o)}) AT TIME ZONE ${s})`}};var ol=(e,t,r)=>{let o=Oe(t,r);if(e.type==="value"&&o.type==="value"){let i=_r(o.value);return i===null?Jt:{type:"value",value:Lr(e.value,i)}}let n=(i,s)=>i.type==="column"?`(${i.sql})::double precision`:`${_(r,s(i.value)??null)}::double precision`;return {type:"column",computed:true,sql:`(${n(e,i=>i)} + ${n(o,_r)})`}},Ic=(e,t,r)=>{if(Tt(e))return Jt;let o=Oe(t,r);if(o.type==="column")throw new Error(`A row path on a date offset ('${t.path}') is check-only; evaluate with check()`);let n=jo(o.value);return n===null?Jt:zn(e,...n,r)};var qc,Vc=e=>{qc=e;},xr=(e,t)=>qc(e,t);var Fs=(e,t,r)=>{let o=Wi(e);if(o)throw o;let n=r===void 0?Ht(e.field,t):{sql:r,shape:"scalar"};if(n.shape==="relation"&&!Ut(e))throw sr(e.field);let i=r===void 0,s=Ee(e)&&t.map&&t.currentModel?(L(e.path)??{path:e.path}).path:null;if(s!==null){let b=Bo(X(e.field,t.map,t.currentModel),X(s,t.map,t.currentModel),e.operator);if(b)throw F("toSql",`Comparing '${e.field}' with the column '${e.path}'`,b)}if(n.shape==="enum"&&!nr.includes(e.operator)){let b=Wc(e,t),$=X(e.field,t.map,t.currentModel),E=b!==Ds&&$&&!be(e,b)?Rs(e,b,$,t.map):null;if(E){let I=`${n.sql}::text = ANY(${_(t,E.values)})`;return E.matchesNull?Me(n.sql,I):I}}let a=n.shape==="enum"&&!nr.includes(e.operator)&&s===null?{...n,sql:`${n.sql}::text`}:n;if((n.shape==="json"||n.shape==="json-path")&&!nr.includes(e.operator)){let b=Wc(e,t);if(b===Ds)throw new Error(`The Json value '${e.field}' compares against an operand known when compiling, not one read per row.`);return Fc(e,At(e.field,t,{jsonb:true}),b,t)}let d=b=>{if(b.type==="column"&&!b.computed&&(b.shape==="json"||b.shape==="json-path"))throw F("toSql",`'${e.field}' compared with a Json value read per row`,"SQL would compare its text")};if(Ve.includes(e.operator)){let b=Gc(e,t);return b?.forEach(d),Kn(a.sql,b,B.includes(e.operator),t,i)}let p=Uc(e,t);if(d(p),p.type==="column"&&qt(e.operator,"field")==="string"&&!Vr(n.shape)&&n.shape!=="list")throw F("toSql",`'${e.operator}' on '${e.field}'`,"it is not text");if(p.type==="column"&&p.computed&&n.shape==="text"&&r===void 0)throw F("toSql",`'${e.field}' against a value moved by an offset`,"an offset moves a number or a date");let f=a.sql,u=rn(e.operator,"field");if(u)return Ls(f,u.symbol,p,false,t);if(p.type==="value"&&be(e,p.value))return kt(f,B.includes(e.operator),i);let m=p.type==="column"&&p.computed===true,y=se(e.caseInsensitive)&&(p.type==="column"?!m&&Vr(n.shape)&&Vr(p.shape):yr(n.shape,p.value)),c=b=>y?`LOWER(${b})`:b,g=b=>y?jr(b):b;if(n.shape==="list"&&p.type==="column"&>.includes(e.operator)){if(X(e.field,t.map,t.currentModel)?.type!=="String"||!Vr(p.shape))throw F("toSql",`'${e.operator}' on the list '${e.field}' with a member read per row ('${e.path}')`,"Postgres matches a member of the list's own type only");let b=se(e.caseInsensitive)&&Vr(p.shape)?`EXISTS (SELECT 1 FROM unnest(${f}) AS e WHERE LOWER(e) = LOWER(${p.sql}))`:`array_position(${f}, ${p.sql}) IS NOT NULL`;return e.operator===h.contains?`(${p.sql} IS NOT NULL AND ${b})`:`(${f} IS NULL OR (${p.sql} IS NOT NULL AND NOT ${b}))`}if(n.shape==="list"&&p.type==="value"){let b=se(e.caseInsensitive)&&yr("text",p.value);if(gt.includes(e.operator)){let $=_(t,p.value),E=b?`EXISTS (SELECT 1 FROM unnest(${f}) AS e WHERE LOWER(e) = LOWER(${$}))`:`array_position(${f}, ${$}) IS NOT NULL`;return e.operator===h.contains?E:`NOT ${E}`}if(ir.includes(e.operator)&&Array.isArray(p.value))return xr(Xi(e,p.value),t);if(mx(e.operator))throw new Error(`'${e.operator}' does not apply to the list '${e.field}'; test its members with contains.`);if(b&&ht.includes(e.operator)&&Array.isArray(p.value)){let $=_(t,jr(p.value)),E=`(${f} IS NOT NULL AND ARRAY(SELECT LOWER(e) FROM unnest(${f}) AS e) = ${$})`;return e.operator===h.equals?E:Me(f,`NOT ${E}`)}}let w=p.type==="value"?p.value:void 0,R=p.type==="column"?p.sql:void 0;if(R!==void 0&&(ir.includes(e.operator)||["pattern","string"].includes(qt(e.operator,"field"))))throw F("toSql",`'${e.operator}' against an operand read per row ('${e.path}')`);let S=b=>i?Me(f,b):b;switch(e.operator){case h.equals:return m?`${f} = ${R}`:R!==void 0?`${c(f)} IS NOT DISTINCT FROM ${c(R)}`:w===null?`${f} IS NULL`:`${c(f)} = ${c(_(t,w))}`;case h.notEquals:return m?S(`${f} <> ${R}`):R!==void 0?`${c(f)} IS DISTINCT FROM ${c(R)}`:w===null?`${f} IS NOT NULL`:S(`${c(f)} <> ${c(_(t,w))}`);case h.in:{let{values:b,hasNull:$}=We(w);if(!b.length)return $?`${f} IS NULL`:"FALSE";let E=`${c(f)} = ANY(${_(t,g(b))})`;return $?S(E):E}case h.notIn:{let{values:b,hasNull:$}=We(w);if(!b.length)return $?`${f} IS NOT NULL`:"TRUE";let E=`${c(f)} <> ALL(${_(t,g(b))})`;return $?`(${E} AND ${f} IS NOT NULL)`:S(E)}case h.contains:return `${c(f)} LIKE ${c(_(t,`%${Re(String(w))}%`))}`;case h.notContains:return S(`${c(f)} NOT LIKE ${c(_(t,`%${Re(String(w))}%`))}`);case h.startsWith:return `${c(f)} LIKE ${c(_(t,`${Re(String(w))}%`))}`;case h.endsWith:return `${c(f)} LIKE ${c(_(t,`%${Re(String(w))}`))}`;case h.notStartsWith:return S(`${c(f)} NOT LIKE ${c(_(t,`${Re(String(w))}%`))}`);case h.notEndsWith:return S(`${c(f)} NOT LIKE ${c(_(t,`%${Re(String(w))}`))}`);case h.matches:return Bc(f,w,false,t);case h.notMatches:return S(Bc(f,w,true,t));case h.isEmpty:case h.notEmpty:return nl(e.field,n,e.operator===h.isEmpty,t,rs(e,t.map,t.currentModel));case h.exists:return `${f} IS NOT NULL`;case h.notExists:return `${f} IS NULL`;default:throw new Error(`Unknown operator: ${e.operator}`)}},Uc=(e,t)=>{if(nr.includes(e.operator))return {type:"value",value:void 0};let r=Kc(e,Oe(e,t),t);return e.offset===void 0?r:ol(r,e.offset,t)},Kc=(e,t,r)=>t.type==="column"?t:{type:"value",value:Zo(e,t.value,mr(e.field,r.map,r.currentModel),"toSql",()=>st(r).timeZone)},Gc=(e,t)=>{let r=Kc(e,Oe(e,t),t),o=r.type==="value"?r.value:void 0;if(o==null)return null;let n=Ye(o,e.operator);return n.some(i=>i!=null&&!ce(i))&&Fo(o,e.operator),Be(n).map(i=>{let s={type:"value",value:i};return e.offset===void 0?s:ol(s,e.offset,t)})},Bc=(e,t,r,o)=>{if(typeof t!="string"&&!(t instanceof RegExp))throw new Error("matches requires a string or RegExp pattern");let{source:n,caseInsensitive:i}=ur(t);return `${e} ${r?"!":""}~${i?"*":""} ${_(o,Nn(n))}`},Ds=Symbol("not known"),Wc=(e,t)=>{if(Ve.includes(e.operator)){let o=Gc(e,t);return o?o.every(n=>n.type==="value")?o.map(n=>n.value):Ds:null}let r=Uc(e,t);return r.type==="value"?r.value:Ds},nl=(e,t,r,o,n)=>{let{sql:i,shape:s}=t;if(s==="list")return r?`(${i} IS NULL OR cardinality(${i}) = 0)`:`cardinality(${i}) > 0`;if(s==="json"||s==="json-path"){let a=At(e,o,{jsonb:true}),l=["'null'::jsonb",...n?[`'""'::jsonb`]:[],"'[]'::jsonb"].join(", ");return r?`(${a} IS NULL OR ${a} IN (${l}))`:`${a} NOT IN (${l})`}return n?r?`(${i} IS NULL OR ${i} = '')`:`(${i} IS NOT NULL AND ${i} <> '')`:r?`${i} IS NULL`:`${i} IS NOT NULL`},mx=e=>qt(e,"field")==="string"&&!gt.includes(e);var zc=(e,t)=>{if($e(e))throw St("toSql");if(e.condition)throw new Error("Aggregate condition filtering is not yet supported by toSql(). Use check() for in-memory evaluation or toPrisma() for database queries.");let r=gx(e,t);return Fs(e,t,r)},gx=(e,t)=>{let{mode:r,field:o}=e.aggregate;if(!yt.includes(r))throw ar(r);let n=r==="sum"?"SUM":"AVG",i=Ie({field:e.field},t.map,t.currentModel);if(i==="relation"||X(e.field,t.map,t.currentModel)?.kind==="object")throw new Error(`Field '${e.field}' is a relation \u2014 toSql() cannot aggregate relation lists. Use toPrisma() instead.`);if(o?.includes("."))throw new Error(`aggregate.field '${o}' contains a nested path \u2014 toSql() only supports flat field names. Use check() for nested paths.`);let s=i==="list",a=At(e.field,t,{jsonb:!s}),l=s?a:`(CASE WHEN jsonb_typeof(${a}) = 'array' THEN ${a} END)`;if(s){if(o)throw new Error("aggregate.field is not supported for native array types. Use a JSONB column for object arrays.");return `(SELECT ${`COALESCE(${n}(elem), 0)`} FROM unnest(${l}) AS elem)`}if(o){let f=`(elem->>${Ca(o)})::numeric`;return `(SELECT ${`COALESCE(${n}(${f}), 0)`} FROM jsonb_array_elements(${l}) AS elem)`}return `(SELECT ${`COALESCE(${n}(elem::numeric), 0)`} FROM jsonb_array_elements_text(${l}) AS elem)`};var Hc=(e,t)=>{if($e(e))throw St("toSql");if(!e.field)throw Vi("toSql");if(Ie({field:e.field},t.map,t.currentModel)==="relation"||X(e.field,t.map,t.currentModel)?.kind==="object")throw new Error(`Field '${e.field}' is a relation \u2014 relation arrays are not supported in SQL; use toPrisma().`);switch(e.arrayOperator){case x.empty:case x.notEmpty:{let o=Ht(e.field,t),n=e.arrayOperator===x.empty;if(o.shape==="list")return nl(e.field,o,n,t,false);let i=At(e.field,t,{jsonb:true});return `(CASE WHEN jsonb_typeof(${i}) = 'array' THEN jsonb_array_length(${i}) ${n?"=":">"} 0 ELSE ${n?"TRUE":"FALSE"} END)`}case x.all:case x.any:case x.none:case x.atLeast:case x.atMost:case x.exactly:throw new Error(`Array operator '${e.arrayOperator}' with conditions is not supported in SQL. Use application-level filtering for complex array operations.`);default:throw le(e.arrayOperator,"array")}};var yx=(e,t)=>e.type==="column"&&!e.computed?{type:"column",sql:Gn(e,t),computed:true}:e,Jc=e=>e===void 0||e==="instant"||e==="text"||e==="json-path"||e==="unknown",Qc=e=>F("toSql",`A date rule on '${e}'`,"it is not a date column"),Zc=(e,t,r)=>{let o=t.some(i=>i.type==="column"),n=e.shape==="json-path"||e.shape==="text";return o||n?{lhs:Gn(e,r),ends:t.map(i=>yx(i,r))}:{lhs:e.sql,ends:t}},Yc=(e,t)=>{let r=Ht(e.field,t);if(!Jc(r.shape))throw Qc(e.field);let o=Oe(e,t);if(o.type==="column"&&!Jc(o.shape))throw Qc(String(e.path??e.field));if(!Tt(o)){let s=e.offset===void 0?void 0:Oe(e.offset,t),a=Wt(o.type==="value"?o.value:void 0,s?.type==="value"?s.value:void 0);if(a)throw a}let n=rn(e.dateOperator,"date");if(n){let{lhs:s,ends:a}=Zc(r,[wx(e,t)],t);return Ls(s,n.symbol,a[0],n.negated,t)}let i=(s,a)=>{if(!s)return Kn(r.sql,null,a,t);let{lhs:l,ends:d}=Zc(r,s,t);return Kn(l,d,a,t)};switch(e.dateOperator){case v.within:case v.notWithin:return i(Sx(e,t),B.includes(e.dateOperator));case v.between:case v.notBetween:return i(bx(e,t),B.includes(e.dateOperator));case v.dayIn:case v.dayNotIn:{let s=e.dateOperator===v.dayNotIn,a=Oe(e,t);if(a.type==="column")throw F("toSql",`A weekday list read from the row ('${e.path}')`);let l=pa(a.value);if(l===null)return kt(r.sql,s);let d=_(t,st(t).timeZone),p=_(t,l),f=`EXTRACT(DOW FROM (${Gn(r,t)} AT TIME ZONE ${d}))`;return e.dateOperator===v.dayIn?`${f} = ANY(${p})`:Me(r.sql,`${f} <> ALL(${p})`)}default:throw le(e.dateOperator,"date")}},Xc=e=>({type:"value",value:bn(st(e)).toDate()}),hx=(e,t,r)=>{let o=we(e);if(o&&_s(o[0]))return zn(Xc(r),...o,r);let n=bt(e,Hr(r));return n===null?Jt:{type:"value",value:Mo(n,t,st(r)).toDate()}},em=(e,t,r)=>e==null?Jt:Y(e)?hx(e,t,r):{type:"value",value:Zi(e,st(r).timeZone)},tm=(e,t,r)=>t.offset===void 0?e:Ic(e,t.offset,r),wx=(e,t)=>{let r=Oe(e,t),o=r.type==="column"?r:em(r.value,e.dateOperator,t);return tm(o,e,t)},Sx=(e,t)=>{let r=Oe(e,t);if(Tt(r))return null;if(r.type==="column"||!Y(r.value))throw Qe(e.dateOperator);let o=we(r.value);if(o&&_s(o[0])){let s=Xc(t),a=zn(s,...o,t);return o[1]===-1?[a,s]:[s,a]}let n=bt(r.value,Hr(t));if(n===null)return null;let i=Lo(n,st(t));return [{type:"value",value:i[0].toDate()},{type:"value",value:i[1].toDate()}]},bx=(e,t)=>{let r=Oe(e,t);if(Tt(r))return null;let o=r.type==="value"?r.value:void 0,n=Ye(o,e.dateOperator).map(l=>em(l,e.dateOperator,t));if(n.some(Tt))return null;let[i,s]=n;return (i.type==="value"&&s.type==="value"?Be([i.value,s.value]).map(l=>({type:"value",value:l})):n).map(l=>tm(l,e,t))};var rm=(e,t)=>e.all.length===0?"TRUE":`(${e.all.map(o=>xr(o,t)).join(" AND ")})`,om=(e,t)=>e.any.length===0?"FALSE":`(${e.any.map(o=>xr(o,t)).join(" OR ")})`,nm=(e,t)=>{if(xt(e,t.map,t.currentModel))return "TRUE";let r=xr(e.if,t),o=xr(e.then,t);if(e.else!==void 0){let n=xr(e.else,t);return `(((${r}) IS NOT TRUE OR ${o}) AND ((${r}) IS TRUE OR ${n}))`}return `((${r}) IS NOT TRUE OR ${o})`};var Hn=(e,t)=>{if(typeof e=="boolean")return e?"TRUE":"FALSE";if(vi(e,"toSql"),"field"in e&&typeof e.field=="string"&&t.map&&t.currentModel&&gr(e.field,t.map,t.currentModel))return "TRUE";let r=ne(e);(r==="field"||r==="date")&&os(e.field,t.map,t.currentModel);let o=e;switch(r){case "all":return rm(o,t);case "any":return om(o,t);case "if":return nm(o,t);case "array":return Hc(o,t);case "aggregate":return zc(o,t);case "date":return Yc(o,t);case "field":return Fs(o,t);default:throw wt()}};Vc(Hn);var il=e=>{let t=ve(e?.map,e?.mapName,"toSql"),r=!!(t&&e?.model),o=e?.alias??(r?"t0":void 0);return {params:[],paramIndex:0,dateConfig:{now:e?.now,timeZone:e?.timeZone,weekStart:e?.weekStart},map:t,currentModel:e?.model,currentAlias:o,joinCounter:r?{n:0}:void 0,joins:r?[]:void 0,joinRegistry:r?new Map:void 0}},Rx=(e,t)=>bs(e,t,"toSql",Ox),Ox=(e,t)=>{let r=il(t);return {sql:Hn(e,r),params:r.params,joins:r.joins??[]}};var im=(e,t)=>{let[r,...o]=t,n=e[r];if(o.length===0){n===void 0&&(e[r]=true);return}let i=n!==void 0&&n!==true?n.select:{};im(i,o),e[r]={select:i};},xx=(e,t,r,o,n,i,s,a,l,d)=>{let p=$s(`source '${n}' at '${t}'`,()=>Vn(a,{...l,map:e,mapName:r,model:o})),f=p.steps.at(-1),u=f.where,m=p.steps.length>1||(f.refs?.length??0)>0,y=ve(e,r,"toPrisma"),c=N=>d!==void 0&&te(N,y,o).kind==="bridge",g=i!==void 0&&!c(i)?i:void 0,w=(s??[]).map(N=>c(N)?void 0:N),R=N=>{let j=te(N,y,o);return j.kind==="json-path"?N.split(".").slice(0,j.stopIndex).join("."):N},S=d===void 0?[]:Ts(e,r,o,[...Ge(d),...i!==void 0&&g===void 0?[i]:[],...(s??[]).filter(c)].map(R)).filter(N=>N!==n),b=g?.includes(".")?g:void 0,$=[...w.filter(N=>N!==void 0),...b?[b]:[],...S],E={[n]:true,...g&&!b?{[g]:true}:{}};for(let N of $)im(E,N.split("."));let I={model:o,...s||b||d!==void 0?{}:{distinct:g?[n,g]:[n]},select:E,where:u,...m?{steps:p.steps}:{}},pe;try{for(let he of S){let Ae=te(he,y,o);if(!(Ae.kind==="direct"&&!Ae.hops.length&&Ae.entry.kind!=="object"))throw new Error(Ae.kind==="direct"?`the re-check reads '${he}' through a relation, which flat SQL rows can't hold \u2014 run the Prisma query`:`the re-check reads '${he}', which is not a column of ${o} \u2014 run the Prisma query`)}let N=il({...l,map:e,mapName:r,model:o,alias:"t0"}),j=Hn(a,N),q=b?At(b,N):void 0,Er=w.map((he,Ae)=>he===void 0?void 0:`${At(he,N)} AS ${re(`__group_${Ae}`)}`),nn=N.joins??[],$r=nn.length?` ${nn.join(" ")}`:"",de=j?.trim()?` WHERE ${j}`:"",at=re("t0"),Jr=[`${at}.${re(n)}`,...q?[`${q} AS ${re("__label")}`]:g?[`${at}.${re(g)}`]:[],...Er.filter(he=>he!==void 0),...S.map(he=>`${at}.${re(he)}`)].join(", "),ee=T(O(e.maps,r),o)?.dbName??o;pe={sql:`SELECT DISTINCT ${Jr} FROM ${re(ee)} AS ${at}${$r}${de}`,params:N.params};}catch(N){pe={sql:null,params:[],error:N instanceof Error?N.message:String(N)};}return {prisma:I,sql:pe}},sm=(e,t={})=>{let{lens:r}=M(e);return ac(e).map(({path:o,visit:n,field:i,label:s,groupBy:a,where:l,recheck:d})=>{let p=l,{prisma:f,sql:u}=xx(r,o,n.mapName,n.model,i,s,a,p,t,d);return {path:o,mapName:n.mapName,model:n.model,field:i,...s!==void 0?{label:s}:{},...a!==void 0?{groupBy:a}:{},composedWhere:p,prisma:f,sql:u,...d!==void 0?{recheck:d}:{}}})};var am=(e,t)=>{let r=M(e);return Gr(r,Pt(r),t).resolution};/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
lodash-es/lodash.js:
|
|
6
6
|
(**
|
|
@@ -12,5 +12,5 @@ lodash-es/lodash.js:
|
|
|
12
12
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
13
13
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
14
14
|
*)
|
|
15
|
-
*/export{
|
|
15
|
+
*/export{Ti as ALL_KINDS,x as ArrayOperator,wn as CLOCK_UNITS,zb as ConditionShape,v as DateOperator,Q as FieldKind,A as LensRefusal,He as NUMERIC_KINDS,h as Operator,Lb as RuleTarget,Cs as SourceOptionOrder,So as SqlDialect,k as UsageError,It as ValueShape,Ke as andWhere,du as assertValidFieldMaps,Ms as assertValidNarrowing,_R as assertValidRule,vu as bindLens,na as bindRule,me as check,Ta as clampLens,eR as clockUnit,Cu as coerceRule,Oc as composeLens,Mu as createLens,Lu as describeRule,_u as describeRuleSources,ze as engineGlobals,Yu as executePrismaPlan,Fb as getAggregateOperators,Db as getArrayOperators,Hb as getConditionShapeKeys,nt as getLensRoot,_b as getOperatorsForKind,qt as getValueShape,Ff as indexBridges,ic as lensVisit,Pn as listBindings,Qb as listFields,$u as listLensBindings,rt as matchAll,Et as matchNothing,yc as materializeSourceQuery,gc as materializeSources,Qo as narrowRule,W as orWhere,Mf as orderRecords,L as parseScopeRef,Jo as prefixConditionFields,bc as projectLens,mc as projectRows,Rc as readLensValue,qe as readScopeRef,Cb as registerEngineGlobals,ts as stitchFieldMaps,xc as storeLens,uc as toLensSelect,_c as toLensWhereSql,Vn as toPrisma,sm as toSourceQueries,Rx as toSql,Tc as toWhereSql,ga as validateFieldMaps,tl as validateNarrowing,zo as validateRule,Xo as validateRuleInLens,am as walkLensPath};//# sourceMappingURL=index.js.map
|
|
16
16
|
//# sourceMappingURL=index.js.map
|