s3db.js 4.1.3 → 4.1.4

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.
@@ -12,7 +12,7 @@ ${JSON.stringify(i,null,2)}`}),this.resourceName=r,this.attributes=n,this.valida
12
12
  `+t+p.join(`,
13
13
  `+t)+`
14
14
  `+u+"}":"{"+p.join(",")+"}",t=u,d}}return Hr=function(s,c,f){var l;if(t="",r="",typeof f=="number")for(l=0;l<f;l+=1)r+=" ";else typeof f=="string"&&(r=f);if(i=c,c&&typeof c!="function"&&(typeof c!="object"||typeof c.length!="number"))throw new Error("JSON.stringify");return o("",{"":s})},Hr}var fa;function rc(){return fa||(fa=1,er.parse=ec(),er.stringify=tc()),er}var qr,ca;function nc(){if(ca)return qr;ca=1;var e={}.toString;return qr=Array.isArray||function(t){return e.call(t)=="[object Array]"},qr}var Kr,la;function ua(){if(la)return Kr;la=1;var e=Object.prototype.toString;return Kr=function(r){var n=e.call(r),i=n==="[object Arguments]";return i||(i=n!=="[object Array]"&&r!==null&&typeof r=="object"&&typeof r.length=="number"&&r.length>=0&&e.call(r.callee)==="[object Function]"),i},Kr}var Wr,ha;function ic(){if(ha)return Wr;ha=1;var e;if(!Object.keys){var t=Object.prototype.hasOwnProperty,r=Object.prototype.toString,n=ua(),i=Object.prototype.propertyIsEnumerable,a=!i.call({toString:null},"toString"),o=i.call(function(){},"prototype"),s=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],c=function(h){var u=h.constructor;return u&&u.prototype===h},f={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},l=function(){if(typeof window>"u")return!1;for(var h in window)try{if(!f["$"+h]&&t.call(window,h)&&window[h]!==null&&typeof window[h]=="object")try{c(window[h])}catch{return!0}}catch{return!0}return!1}(),d=function(h){if(typeof window>"u"||!l)return c(h);try{return c(h)}catch{return!1}};e=function(u){var p=u!==null&&typeof u=="object",v=r.call(u)==="[object Function]",_=n(u),w=p&&r.call(u)==="[object String]",E=[];if(!p&&!v&&!_)throw new TypeError("Object.keys called on a non-object");var S=o&&v;if(w&&u.length>0&&!t.call(u,0))for(var g=0;g<u.length;++g)E.push(String(g));if(_&&u.length>0)for(var A=0;A<u.length;++A)E.push(String(A));else for(var T in u)!(S&&T==="prototype")&&t.call(u,T)&&E.push(String(T));if(a)for(var b=d(u),x=0;x<s.length;++x)!(b&&s[x]==="constructor")&&t.call(u,s[x])&&E.push(s[x]);return E}}return Wr=e,Wr}var Vr,da;function ac(){if(da)return Vr;da=1;var e=Array.prototype.slice,t=ua(),r=Object.keys,n=r?function(o){return r(o)}:ic(),i=Object.keys;return n.shim=function(){if(Object.keys){var o=function(){var s=Object.keys(arguments);return s&&s.length===arguments.length}(1,2);o||(Object.keys=function(c){return t(c)?i(e.call(c)):i(c)})}else Object.keys=n;return Object.keys||n},Vr=n,Vr}var Gr={exports:{}},Yr,pa;function ya(){return pa||(pa=1,Yr=Object),Yr}var Jr,va;function oc(){return va||(va=1,Jr=Error),Jr}var Xr,ga;function sc(){return ga||(ga=1,Xr=EvalError),Xr}var Qr,_a;function fc(){return _a||(_a=1,Qr=RangeError),Qr}var en,wa;function cc(){return wa||(wa=1,en=ReferenceError),en}var tn,ba;function ma(){return ba||(ba=1,tn=SyntaxError),tn}var rn,xa;function tr(){return xa||(xa=1,rn=TypeError),rn}var nn,Ea;function lc(){return Ea||(Ea=1,nn=URIError),nn}var an,Sa;function uc(){return Sa||(Sa=1,an=Math.abs),an}var on,Aa;function hc(){return Aa||(Aa=1,on=Math.floor),on}var sn,ka;function dc(){return ka||(ka=1,sn=Math.max),sn}var fn,Ra;function pc(){return Ra||(Ra=1,fn=Math.min),fn}var cn,Oa;function yc(){return Oa||(Oa=1,cn=Math.pow),cn}var ln,Ta;function vc(){return Ta||(Ta=1,ln=Math.round),ln}var un,Ia;function gc(){return Ia||(Ia=1,un=Number.isNaN||function(t){return t!==t}),un}var hn,Pa;function _c(){if(Pa)return hn;Pa=1;var e=gc();return hn=function(r){return e(r)||r===0?r:r<0?-1:1},hn}var dn,Ca;function wc(){return Ca||(Ca=1,dn=Object.getOwnPropertyDescriptor),dn}var pn,Da;function rr(){if(Da)return pn;Da=1;var e=wc();if(e)try{e([],"length")}catch{e=null}return pn=e,pn}var yn,Fa;function nr(){if(Fa)return yn;Fa=1;var e=Object.defineProperty||!1;if(e)try{e({},"a",{value:1})}catch{e=!1}return yn=e,yn}var vn,Ma;function bc(){return Ma||(Ma=1,vn=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var t={},r=Symbol("test"),n=Object(r);if(typeof r=="string"||Object.prototype.toString.call(r)!=="[object Symbol]"||Object.prototype.toString.call(n)!=="[object Symbol]")return!1;var i=42;t[r]=i;for(var a in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var o=Object.getOwnPropertySymbols(t);if(o.length!==1||o[0]!==r||!Object.prototype.propertyIsEnumerable.call(t,r))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var s=Object.getOwnPropertyDescriptor(t,r);if(s.value!==i||s.enumerable!==!0)return!1}return!0}),vn}var gn,ja;function mc(){if(ja)return gn;ja=1;var e=typeof Symbol<"u"&&Symbol,t=bc();return gn=function(){return typeof e!="function"||typeof Symbol!="function"||typeof e("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},gn}var _n,La;function Na(){return La||(La=1,_n=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),_n}var wn,Ba;function Ua(){if(Ba)return wn;Ba=1;var e=ya();return wn=e.getPrototypeOf||null,wn}var bn,$a;function xc(){if($a)return bn;$a=1;var e="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,r=Math.max,n="[object Function]",i=function(c,f){for(var l=[],d=0;d<c.length;d+=1)l[d]=c[d];for(var h=0;h<f.length;h+=1)l[h+c.length]=f[h];return l},a=function(c,f){for(var l=[],d=f,h=0;d<c.length;d+=1,h+=1)l[h]=c[d];return l},o=function(s,c){for(var f="",l=0;l<s.length;l+=1)f+=s[l],l+1<s.length&&(f+=c);return f};return bn=function(c){var f=this;if(typeof f!="function"||t.apply(f)!==n)throw new TypeError(e+f);for(var l=a(arguments,1),d,h=function(){if(this instanceof d){var w=f.apply(this,i(l,arguments));return Object(w)===w?w:this}return f.apply(c,i(l,arguments))},u=r(0,f.length-l.length),p=[],v=0;v<u;v++)p[v]="$"+v;if(d=Function("binder","return function ("+o(p,",")+"){ return binder.apply(this,arguments); }")(h),f.prototype){var _=function(){};_.prototype=f.prototype,d.prototype=new _,_.prototype=null}return d},bn}var mn,za;function Rt(){if(za)return mn;za=1;var e=xc();return mn=Function.prototype.bind||e,mn}var xn,Za;function En(){return Za||(Za=1,xn=Function.prototype.call),xn}var Sn,Ha;function An(){return Ha||(Ha=1,Sn=Function.prototype.apply),Sn}var kn,qa;function Ec(){return qa||(qa=1,kn=typeof Reflect<"u"&&Reflect&&Reflect.apply),kn}var Rn,Ka;function Wa(){if(Ka)return Rn;Ka=1;var e=Rt(),t=An(),r=En(),n=Ec();return Rn=n||e.call(r,t),Rn}var On,Va;function Tn(){if(Va)return On;Va=1;var e=Rt(),t=tr(),r=En(),n=Wa();return On=function(a){if(a.length<1||typeof a[0]!="function")throw new t("a function is required");return n(e,r,a)},On}var In,Ga;function Sc(){if(Ga)return In;Ga=1;var e=Tn(),t=rr(),r;try{r=[].__proto__===Array.prototype}catch(o){if(!o||typeof o!="object"||!("code"in o)||o.code!=="ERR_PROTO_ACCESS")throw o}var n=!!r&&t&&t(Object.prototype,"__proto__"),i=Object,a=i.getPrototypeOf;return In=n&&typeof n.get=="function"?e([n.get]):typeof a=="function"?function(s){return a(s==null?s:i(s))}:!1,In}var Pn,Ya;function Ac(){if(Ya)return Pn;Ya=1;var e=Na(),t=Ua(),r=Sc();return Pn=e?function(i){return e(i)}:t?function(i){if(!i||typeof i!="object"&&typeof i!="function")throw new TypeError("getProto: not an object");return t(i)}:r?function(i){return r(i)}:null,Pn}var Cn,Ja;function kc(){if(Ja)return Cn;Ja=1;var e=Function.prototype.call,t=Object.prototype.hasOwnProperty,r=Rt();return Cn=r.call(e,t),Cn}var Dn,Xa;function Qa(){if(Xa)return Dn;Xa=1;var e,t=ya(),r=oc(),n=sc(),i=fc(),a=cc(),o=ma(),s=tr(),c=lc(),f=uc(),l=hc(),d=dc(),h=pc(),u=yc(),p=vc(),v=_c(),_=Function,w=function(ge){try{return _('"use strict"; return ('+ge+").constructor;")()}catch{}},E=rr(),S=nr(),g=function(){throw new s},A=E?function(){try{return arguments.callee,g}catch{try{return E(arguments,"callee").get}catch{return g}}}():g,T=mc()(),b=Ac(),x=Ua(),O=Na(),k=An(),F=En(),K={},G=typeof Uint8Array>"u"||!b?e:b(Uint8Array),oe={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?e:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?e:ArrayBuffer,"%ArrayIteratorPrototype%":T&&b?b([][Symbol.iterator]()):e,"%AsyncFromSyncIteratorPrototype%":e,"%AsyncFunction%":K,"%AsyncGenerator%":K,"%AsyncGeneratorFunction%":K,"%AsyncIteratorPrototype%":K,"%Atomics%":typeof Atomics>"u"?e:Atomics,"%BigInt%":typeof BigInt>"u"?e:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?e:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?e:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?e:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":r,"%eval%":eval,"%EvalError%":n,"%Float16Array%":typeof Float16Array>"u"?e:Float16Array,"%Float32Array%":typeof Float32Array>"u"?e:Float32Array,"%Float64Array%":typeof Float64Array>"u"?e:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?e:FinalizationRegistry,"%Function%":_,"%GeneratorFunction%":K,"%Int8Array%":typeof Int8Array>"u"?e:Int8Array,"%Int16Array%":typeof Int16Array>"u"?e:Int16Array,"%Int32Array%":typeof Int32Array>"u"?e:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":T&&b?b(b([][Symbol.iterator]())):e,"%JSON%":typeof JSON=="object"?JSON:e,"%Map%":typeof Map>"u"?e:Map,"%MapIteratorPrototype%":typeof Map>"u"||!T||!b?e:b(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":t,"%Object.getOwnPropertyDescriptor%":E,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?e:Promise,"%Proxy%":typeof Proxy>"u"?e:Proxy,"%RangeError%":i,"%ReferenceError%":a,"%Reflect%":typeof Reflect>"u"?e:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?e:Set,"%SetIteratorPrototype%":typeof Set>"u"||!T||!b?e:b(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?e:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":T&&b?b(""[Symbol.iterator]()):e,"%Symbol%":T?Symbol:e,"%SyntaxError%":o,"%ThrowTypeError%":A,"%TypedArray%":G,"%TypeError%":s,"%Uint8Array%":typeof Uint8Array>"u"?e:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?e:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?e:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?e:Uint32Array,"%URIError%":c,"%WeakMap%":typeof WeakMap>"u"?e:WeakMap,"%WeakRef%":typeof WeakRef>"u"?e:WeakRef,"%WeakSet%":typeof WeakSet>"u"?e:WeakSet,"%Function.prototype.call%":F,"%Function.prototype.apply%":k,"%Object.defineProperty%":S,"%Object.getPrototypeOf%":x,"%Math.abs%":f,"%Math.floor%":l,"%Math.max%":d,"%Math.min%":h,"%Math.pow%":u,"%Math.round%":p,"%Math.sign%":v,"%Reflect.getPrototypeOf%":O};if(b)try{null.error}catch(ge){var ft=b(b(ge));oe["%Error.prototype%"]=ft}var Q=function ge(B){var V;if(B==="%AsyncFunction%")V=w("async function () {}");else if(B==="%GeneratorFunction%")V=w("function* () {}");else if(B==="%AsyncGeneratorFunction%")V=w("async function* () {}");else if(B==="%AsyncGenerator%"){var U=ge("%AsyncGeneratorFunction%");U&&(V=U.prototype)}else if(B==="%AsyncIteratorPrototype%"){var Y=ge("%AsyncGenerator%");Y&&b&&(V=b(Y.prototype))}return oe[B]=V,V},ve={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},ct=Rt(),lt=kc(),Gt=ct.call(F,Array.prototype.concat),up=ct.call(k,Array.prototype.splice),Cf=ct.call(F,String.prototype.replace),Pr=ct.call(F,String.prototype.slice),hp=ct.call(F,RegExp.prototype.exec),dp=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,pp=/\\(\\)?/g,yp=function(B){var V=Pr(B,0,1),U=Pr(B,-1);if(V==="%"&&U!=="%")throw new o("invalid intrinsic syntax, expected closing `%`");if(U==="%"&&V!=="%")throw new o("invalid intrinsic syntax, expected opening `%`");var Y=[];return Cf(B,dp,function(_e,At,ee,Cr){Y[Y.length]=ee?Cf(Cr,pp,"$1"):At||_e}),Y},vp=function(B,V){var U=B,Y;if(lt(ve,U)&&(Y=ve[U],U="%"+Y[0]+"%"),lt(oe,U)){var _e=oe[U];if(_e===K&&(_e=Q(U)),typeof _e>"u"&&!V)throw new s("intrinsic "+B+" exists, but is not available. Please file an issue!");return{alias:Y,name:U,value:_e}}throw new o("intrinsic "+B+" does not exist!")};return Dn=function(B,V){if(typeof B!="string"||B.length===0)throw new s("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof V!="boolean")throw new s('"allowMissing" argument must be a boolean');if(hp(/^%?[^%]*%?$/,B)===null)throw new o("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var U=yp(B),Y=U.length>0?U[0]:"",_e=vp("%"+Y+"%",V),At=_e.name,ee=_e.value,Cr=!1,Li=_e.alias;Li&&(Y=Li[0],up(U,Gt([0,1],Li)));for(var Dr=1,Yt=!0;Dr<U.length;Dr+=1){var Oe=U[Dr],Fr=Pr(Oe,0,1),Mr=Pr(Oe,-1);if((Fr==='"'||Fr==="'"||Fr==="`"||Mr==='"'||Mr==="'"||Mr==="`")&&Fr!==Mr)throw new o("property names with quotes must have matching quotes");if((Oe==="constructor"||!Yt)&&(Cr=!0),Y+="."+Oe,At="%"+Y+"%",lt(oe,At))ee=oe[At];else if(ee!=null){if(!(Oe in ee)){if(!V)throw new s("base intrinsic for "+B+" exists, but the property is not available.");return}if(E&&Dr+1>=U.length){var jr=E(ee,Oe);Yt=!!jr,Yt&&"get"in jr&&!("originalValue"in jr.get)?ee=jr.get:ee=ee[Oe]}else Yt=lt(ee,Oe),ee=ee[Oe];Yt&&!Cr&&(oe[At]=ee)}}return ee},Dn}var Fn,eo;function Rc(){if(eo)return Fn;eo=1;var e=nr(),t=ma(),r=tr(),n=rr();return Fn=function(a,o,s){if(!a||typeof a!="object"&&typeof a!="function")throw new r("`obj` must be an object or a function`");if(typeof o!="string"&&typeof o!="symbol")throw new r("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new r("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new r("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new r("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new r("`loose`, if provided, must be a boolean");var c=arguments.length>3?arguments[3]:null,f=arguments.length>4?arguments[4]:null,l=arguments.length>5?arguments[5]:null,d=arguments.length>6?arguments[6]:!1,h=!!n&&n(a,o);if(e)e(a,o,{configurable:l===null&&h?h.configurable:!l,enumerable:c===null&&h?h.enumerable:!c,value:s,writable:f===null&&h?h.writable:!f});else if(d||!c&&!f&&!l)a[o]=s;else throw new t("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},Fn}var Mn,to;function Oc(){if(to)return Mn;to=1;var e=nr(),t=function(){return!!e};return t.hasArrayLengthDefineBug=function(){if(!e)return null;try{return e([],"length",{value:1}).length!==1}catch{return!0}},Mn=t,Mn}var jn,ro;function Tc(){if(ro)return jn;ro=1;var e=Qa(),t=Rc(),r=Oc()(),n=rr(),i=tr(),a=e("%Math.floor%");return jn=function(s,c){if(typeof s!="function")throw new i("`fn` is not a function");if(typeof c!="number"||c<0||c>4294967295||a(c)!==c)throw new i("`length` must be a positive 32-bit integer");var f=arguments.length>2&&!!arguments[2],l=!0,d=!0;if("length"in s&&n){var h=n(s,"length");h&&!h.configurable&&(l=!1),h&&!h.writable&&(d=!1)}return(l||d||!f)&&(r?t(s,"length",c,!0,!0):t(s,"length",c)),s},jn}var Ln,no;function Ic(){if(no)return Ln;no=1;var e=Rt(),t=An(),r=Wa();return Ln=function(){return r(e,t,arguments)},Ln}var io;function Pc(){return io||(io=1,function(e){var t=Tc(),r=nr(),n=Tn(),i=Ic();e.exports=function(o){var s=n(arguments),c=o.length-(arguments.length-1);return t(s,1+(c>0?c:0),!0)},r?r(e.exports,"apply",{value:i}):e.exports.apply=i}(Gr)),Gr.exports}var Nn,ao;function Cc(){if(ao)return Nn;ao=1;var e=Qa(),t=Tn(),r=t([e("%String.prototype.indexOf%")]);return Nn=function(i,a){var o=e(i,!!a);return typeof o=="function"&&r(i,".prototype.")>-1?t([o]):o},Nn}var Bn,oo;function Dc(){if(oo)return Bn;oo=1;var e=(typeof JSON<"u"?JSON:rc()).stringify,t=nc(),r=ac(),n=Pc(),i=Cc(),a=i("Array.prototype.join"),o=i("Array.prototype.indexOf"),s=i("Array.prototype.splice"),c=i("Array.prototype.sort"),f=function(h,u){for(var p="",v=0;v<h;v+=1)p+=u;return p},l=function(d,h,u){return u};return Bn=function(h){var u=arguments.length>1?arguments[1]:void 0,p=u&&u.space||"";typeof p=="number"&&(p=f(p," "));var v=!!u&&typeof u.cycles=="boolean"&&u.cycles,_=u&&u.replacer?n(u.replacer):l;if(u&&typeof u.collapseEmpty<"u"&&typeof u.collapseEmpty!="boolean")throw new TypeError("`collapseEmpty` must be a boolean, if provided");var w=!!u&&u.collapseEmpty,E=typeof u=="function"?u:u&&u.cmp,S=E&&function(A){var T=E.length>2&&function(x){return A[x]};return function(b,x){return E({key:b,value:A[b]},{key:x,value:A[x]},T?{__proto__:null,get:T}:void 0)}},g=[];return function A(T,b,x,O){var k=p?`
15
- `+f(O,p):"",F=p?": ":":";if(x&&x.toJSON&&typeof x.toJSON=="function"&&(x=x.toJSON()),x=_(T,b,x),x!==void 0){if(typeof x!="object"||x===null)return e(x);var K=function(lt,Gt){return w&&lt.length===0?Gt:(Gt==="[]"?"[":"{")+a(lt,",")+k+(Gt==="[]"?"]":"}")};if(t(x)){for(var Q=[],G=0;G<x.length;G++){var oe=A(x,G,x[G],O+1)||e(null);Q[Q.length]=k+p+oe}return K(Q,"[]")}if(o(g,x)!==-1){if(v)return e("__cycle__");throw new TypeError("Converting circular structure to JSON")}else g[g.length]=x;for(var ft=c(r(x),S&&S(x)),Q=[],G=0;G<ft.length;G++){var b=ft[G],ve=A(x,b,x[b],O+1);if(ve){var ct=e(b)+F+ve;Q[Q.length]=k+p+ct}}return s(g,o(g,x),1),K(Q,"{}")}}({"":h},"",h,0)},Bn}var Fc=Dc(),so=Qf(Fc);async function Un(e,t,r){if(!this.passphrase)return t.push({actual:e,type:"encryptionKeyMissing"}),e;try{return await zr(String(e),this.passphrase)}catch(n){t.push({actual:e,type:"encryptionProblem",error:n})}return e}class fo extends Df{constructor({options:t,passphrase:r,autoEncrypt:n=!0}={}){super(L.merge({},{useNewCustomCheckerFunction:!0,messages:{encryptionKeyMissing:"Missing configuration for secrets encryption.",encryptionProblem:"Problem encrypting secret. Actual: {actual}. Error: {error}"},defaults:{string:{trim:!0},object:{strict:"remove"}}},t)),this.passphrase=r,this.autoEncrypt=n,this.alias("secret",{type:"string",custom:this.autoEncrypt?Un:void 0,messages:{string:"The '{field}' field must be a string.",stringMin:"This secret '{field}' field length must be at least {expected} long."}}),this.alias("secretAny",{type:"any",custom:this.autoEncrypt?Un:void 0}),this.alias("secretNumber",{type:"number",custom:this.autoEncrypt?Un:void 0})}}const co=new Proxy(fo,{instance:null,construct(e,t){return this.instance||(this.instance=new e(...t)),this.instance}}),lo={trim:e=>e.trim(),encrypt:(e,{passphrase:t})=>zr(e,t),decrypt:(e,{passphrase:t})=>ia(e,t),toString:e=>String(e),fromArray:(e,{separator:t})=>e==null||!Array.isArray(e)?e:e.length===0?"[]":e.map(n=>typeof n=="string"?n.replace(/\\/g,"\\\\").replace(new RegExp(`\\${t}`,"g"),`\\${t}`):String(n)).join(t),toArray:(e,{separator:t})=>{if(e==null)return e;if(e==="[]")return[];if(e==="")return[];const r=[];let n="",i=0;const a=String(e);for(;i<a.length;)a[i]==="\\"&&i+1<a.length?a[i+1]===t?(n+=t,i+=2):a[i+1]==="\\"?(n+="\\",i+=2):(n+=a[i],i++):a[i]===t?(r.push(n),n="",i++):(n+=a[i],i++);return r.push(n),r},toJSON:e=>JSON.stringify(e),fromJSON:e=>JSON.parse(e),toNumber:e=>L.isString(e)?e.includes(".")?parseFloat(e):parseInt(e):e,toBool:e=>[!0,1,"true","1","yes","y"].includes(e),fromBool:e=>[!0,1,"true","1","yes","y"].includes(e)?"1":"0"};class Ie{constructor(t){const{map:r,name:n,attributes:i,passphrase:a,version:o=1,options:s={}}=t;this.name=n,this.version=o,this.attributes=i||{},this.passphrase=a??"secret",this.options=L.merge({},this.defaultOptions(),s);const c=this.preprocessAttributesForValidation(this.attributes);if(this.validator=new co({autoEncrypt:!1}).compile(L.merge({$$async:!0},c)),this.options.generateAutoHooks&&this.generateAutoHooks(),!L.isEmpty(r))this.map=r,this.reversedMap=L.invert(r);else{const f=Jt.flatten(this.attributes,{safe:!0}),l=Object.keys(f).filter(u=>!u.includes("$$")),d=this.extractObjectKeys(this.attributes),h=[...new Set([...l,...d])];this.reversedMap={...h},this.map=L.invert(this.reversedMap)}}defaultOptions(){return{autoEncrypt:!0,autoDecrypt:!0,arraySeparator:"|",generateAutoHooks:!0,hooks:{beforeMap:{},afterMap:{},beforeUnmap:{},afterUnmap:{}}}}addHook(t,r,n){this.options.hooks[t][r]||(this.options.hooks[t][r]=[]),this.options.hooks[t][r]=L.uniq([...this.options.hooks[t][r],n])}extractObjectKeys(t,r=""){const n=[];for(const[i,a]of Object.entries(t)){if(i.startsWith("$$"))continue;const o=r?`${r}.${i}`:i;typeof a=="object"&&a!==null&&!Array.isArray(a)&&(n.push(o),a.$$type==="object"&&n.push(...this.extractObjectKeys(a,o)))}return n}generateAutoHooks(){const t=Jt.flatten(L.cloneDeep(this.attributes),{safe:!0});for(const[r,n]of Object.entries(t))n.includes("array")?(this.addHook("beforeMap",r,"fromArray"),this.addHook("afterUnmap",r,"toArray")):(n.includes("secret")&&(this.options.autoEncrypt&&this.addHook("beforeMap",r,"encrypt"),this.options.autoDecrypt&&this.addHook("afterUnmap",r,"decrypt")),n.includes("number")&&(this.addHook("beforeMap",r,"toString"),this.addHook("afterUnmap",r,"toNumber")),n.includes("boolean")&&(this.addHook("beforeMap",r,"fromBool"),this.addHook("afterUnmap",r,"toBool")))}static import(t){let{map:r,name:n,options:i,version:a,attributes:o}=L.isString(t)?JSON.parse(t):t;return o=Ie._importAttributes(o),new Ie({map:r,name:n,options:i,version:a,attributes:o})}static _importAttributes(t){if(typeof t=="string"){try{const r=JSON.parse(t);if(typeof r=="object"&&r!==null)return Ie._importAttributes(r)}catch{}return t}if(Array.isArray(t))return t.map(r=>Ie._importAttributes(r));if(typeof t=="object"&&t!==null){const r={};for(const[n,i]of Object.entries(t))r[n]=Ie._importAttributes(i);return r}return t}export(){return{version:this.version,name:this.name,options:this.options,attributes:this._exportAttributes(this.attributes),map:this.map}}_exportAttributes(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(r=>this._exportAttributes(r));if(typeof t=="object"&&t!==null){const r={};for(const[n,i]of Object.entries(t))r[n]=this._exportAttributes(i);return r}return t}async applyHooksActions(t,r){for(const[n,i]of Object.entries(this.options.hooks[r]))for(const a of i){const o=L.get(t,n);o!==void 0&&typeof lo[a]=="function"&&L.set(t,n,await lo[a](o,{passphrase:this.passphrase,separator:this.options.arraySeparator}))}}async validate(t,{mutateOriginal:r=!1}={}){let n=r?t:L.cloneDeep(t);return await this.validator(n)}async mapper(t){const r=Jt.flatten(L.cloneDeep(t),{safe:!0});await this.applyHooksActions(r,"beforeMap");const n={_v:this.version+""};for(const[i,a]of Object.entries(r))n[this.map[i]]=a;return await this.applyHooksActions(n,"afterMap"),n}async unmapper(t){const r=L.cloneDeep(t);delete r._v,await this.applyHooksActions(r,"beforeUnmap");const n={};for(const[i,a]of Object.entries(r))n[this.reversedMap[i]]=a;return await this.applyHooksActions(n,"afterUnmap"),Jt.unflatten(n)}preprocessAttributesForValidation(t){const r={};for(const[n,i]of Object.entries(t))typeof i=="object"&&i!==null&&!Array.isArray(i)?r[n]={type:"object",properties:this.preprocessAttributesForValidation(i),strict:!1}:r[n]=i;return r}}var ht=typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:{},he=[],ne=[],Mc=typeof Uint8Array<"u"?Uint8Array:Array,$n=!1;function uo(){$n=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t<r;++t)he[t]=e[t],ne[e.charCodeAt(t)]=t;ne[45]=62,ne[95]=63}function jc(e){$n||uo();var t,r,n,i,a,o,s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");a=e[s-2]==="="?2:e[s-1]==="="?1:0,o=new Mc(s*3/4-a),n=a>0?s-4:s;var c=0;for(t=0,r=0;t<n;t+=4,r+=3)i=ne[e.charCodeAt(t)]<<18|ne[e.charCodeAt(t+1)]<<12|ne[e.charCodeAt(t+2)]<<6|ne[e.charCodeAt(t+3)],o[c++]=i>>16&255,o[c++]=i>>8&255,o[c++]=i&255;return a===2?(i=ne[e.charCodeAt(t)]<<2|ne[e.charCodeAt(t+1)]>>4,o[c++]=i&255):a===1&&(i=ne[e.charCodeAt(t)]<<10|ne[e.charCodeAt(t+1)]<<4|ne[e.charCodeAt(t+2)]>>2,o[c++]=i>>8&255,o[c++]=i&255),o}function Lc(e){return he[e>>18&63]+he[e>>12&63]+he[e>>6&63]+he[e&63]}function Nc(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16)+(e[a+1]<<8)+e[a+2],i.push(Lc(n));return i.join("")}function ho(e){$n||uo();for(var t,r=e.length,n=r%3,i="",a=[],o=16383,s=0,c=r-n;s<c;s+=o)a.push(Nc(e,s,s+o>c?c:s+o));return n===1?(t=e[r-1],i+=he[t>>2],i+=he[t<<4&63],i+="=="):n===2&&(t=(e[r-2]<<8)+e[r-1],i+=he[t>>10],i+=he[t>>4&63],i+=he[t<<2&63],i+="="),a.push(i),a.join("")}function ir(e,t,r,n,i){var a,o,s=i*8-n-1,c=(1<<s)-1,f=c>>1,l=-7,d=r?i-1:0,h=r?-1:1,u=e[t+d];for(d+=h,a=u&(1<<-l)-1,u>>=-l,l+=s;l>0;a=a*256+e[t+d],d+=h,l-=8);for(o=a&(1<<-l)-1,a>>=-l,l+=n;l>0;o=o*256+e[t+d],d+=h,l-=8);if(a===0)a=1-f;else{if(a===c)return o?NaN:(u?-1:1)*(1/0);o=o+Math.pow(2,n),a=a-f}return(u?-1:1)*o*Math.pow(2,a-n)}function po(e,t,r,n,i,a){var o,s,c,f=a*8-i-1,l=(1<<f)-1,d=l>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=n?0:a-1,p=n?1:-1,v=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+d>=1?t+=h/c:t+=h*Math.pow(2,1-d),t*c>=2&&(o++,c/=2),o+d>=l?(s=0,o=l):o+d>=1?(s=(t*c-1)*Math.pow(2,i),o=o+d):(s=t*Math.pow(2,d-1)*Math.pow(2,i),o=0));i>=8;e[r+u]=s&255,u+=p,s/=256,i-=8);for(o=o<<i|s,f+=i;f>0;e[r+u]=o&255,u+=p,o/=256,f-=8);e[r+u-p]|=v*128}var Bc={}.toString,yo=Array.isArray||function(e){return Bc.call(e)=="[object Array]"};/*!
15
+ `+f(O,p):"",F=p?": ":":";if(x&&x.toJSON&&typeof x.toJSON=="function"&&(x=x.toJSON()),x=_(T,b,x),x!==void 0){if(typeof x!="object"||x===null)return e(x);var K=function(lt,Gt){return w&&lt.length===0?Gt:(Gt==="[]"?"[":"{")+a(lt,",")+k+(Gt==="[]"?"]":"}")};if(t(x)){for(var Q=[],G=0;G<x.length;G++){var oe=A(x,G,x[G],O+1)||e(null);Q[Q.length]=k+p+oe}return K(Q,"[]")}if(o(g,x)!==-1){if(v)return e("__cycle__");throw new TypeError("Converting circular structure to JSON")}else g[g.length]=x;for(var ft=c(r(x),S&&S(x)),Q=[],G=0;G<ft.length;G++){var b=ft[G],ve=A(x,b,x[b],O+1);if(ve){var ct=e(b)+F+ve;Q[Q.length]=k+p+ct}}return s(g,o(g,x),1),K(Q,"{}")}}({"":h},"",h,0)},Bn}var Fc=Dc(),so=Qf(Fc);async function Un(e,t,r){if(!this.passphrase)return t.push({actual:e,type:"encryptionKeyMissing"}),e;try{return await zr(String(e),this.passphrase)}catch(n){t.push({actual:e,type:"encryptionProblem",error:n})}return e}class fo extends Df{constructor({options:t,passphrase:r,autoEncrypt:n=!0}={}){super(L.merge({},{useNewCustomCheckerFunction:!0,messages:{encryptionKeyMissing:"Missing configuration for secrets encryption.",encryptionProblem:"Problem encrypting secret. Actual: {actual}. Error: {error}"},defaults:{string:{trim:!0},object:{strict:"remove"}}},t)),this.passphrase=r,this.autoEncrypt=n,this.alias("secret",{type:"string",custom:this.autoEncrypt?Un:void 0,messages:{string:"The '{field}' field must be a string.",stringMin:"This secret '{field}' field length must be at least {expected} long."}}),this.alias("secretAny",{type:"any",custom:this.autoEncrypt?Un:void 0}),this.alias("secretNumber",{type:"number",custom:this.autoEncrypt?Un:void 0})}}const co=new Proxy(fo,{instance:null,construct(e,t){return this.instance||(this.instance=new e(...t)),this.instance}}),lo={trim:e=>e.trim(),encrypt:(e,{passphrase:t})=>zr(e,t),decrypt:(e,{passphrase:t})=>ia(e,t),toString:e=>String(e),fromArray:(e,{separator:t})=>e==null||!Array.isArray(e)?e:e.length===0?"[]":e.map(n=>typeof n=="string"?n.replace(/\\/g,"\\\\").replace(new RegExp(`\\${t}`,"g"),`\\${t}`):String(n)).join(t),toArray:(e,{separator:t})=>{if(e==null)return e;if(e==="[]")return[];if(e==="")return[];const r=[];let n="",i=0;const a=String(e);for(;i<a.length;)a[i]==="\\"&&i+1<a.length?a[i+1]===t?(n+=t,i+=2):a[i+1]==="\\"?(n+="\\",i+=2):(n+=a[i],i++):a[i]===t?(r.push(n),n="",i++):(n+=a[i],i++);return r.push(n),r},toJSON:e=>JSON.stringify(e),fromJSON:e=>JSON.parse(e),toNumber:e=>L.isString(e)?e.includes(".")?parseFloat(e):parseInt(e):e,toBool:e=>[!0,1,"true","1","yes","y"].includes(e),fromBool:e=>[!0,1,"true","1","yes","y"].includes(e)?"1":"0"};class Ie{constructor(t){const{map:r,name:n,attributes:i,passphrase:a,version:o=1,options:s={}}=t;this.name=n,this.version=o,this.attributes=i||{},this.passphrase=a??"secret",this.options=L.merge({},this.defaultOptions(),s),this.allNestedObjectsOptional=this.options.allNestedObjectsOptional??!1;const c=this.preprocessAttributesForValidation(this.attributes);if(this.validator=new co({autoEncrypt:!1}).compile(L.merge({$$async:!0},c)),this.options.generateAutoHooks&&this.generateAutoHooks(),!L.isEmpty(r))this.map=r,this.reversedMap=L.invert(r);else{const f=Jt.flatten(this.attributes,{safe:!0}),l=Object.keys(f).filter(u=>!u.includes("$$")),d=this.extractObjectKeys(this.attributes),h=[...new Set([...l,...d])];this.reversedMap={...h},this.map=L.invert(this.reversedMap)}}defaultOptions(){return{autoEncrypt:!0,autoDecrypt:!0,arraySeparator:"|",generateAutoHooks:!0,hooks:{beforeMap:{},afterMap:{},beforeUnmap:{},afterUnmap:{}}}}addHook(t,r,n){this.options.hooks[t][r]||(this.options.hooks[t][r]=[]),this.options.hooks[t][r]=L.uniq([...this.options.hooks[t][r],n])}extractObjectKeys(t,r=""){const n=[];for(const[i,a]of Object.entries(t)){if(i.startsWith("$$"))continue;const o=r?`${r}.${i}`:i;typeof a=="object"&&a!==null&&!Array.isArray(a)&&(n.push(o),a.$$type==="object"&&n.push(...this.extractObjectKeys(a,o)))}return n}generateAutoHooks(){const t=Jt.flatten(L.cloneDeep(this.attributes),{safe:!0});for(const[r,n]of Object.entries(t))n.includes("array")?(this.addHook("beforeMap",r,"fromArray"),this.addHook("afterUnmap",r,"toArray")):(n.includes("secret")&&(this.options.autoEncrypt&&this.addHook("beforeMap",r,"encrypt"),this.options.autoDecrypt&&this.addHook("afterUnmap",r,"decrypt")),n.includes("number")&&(this.addHook("beforeMap",r,"toString"),this.addHook("afterUnmap",r,"toNumber")),n.includes("boolean")&&(this.addHook("beforeMap",r,"fromBool"),this.addHook("afterUnmap",r,"toBool")))}static import(t){let{map:r,name:n,options:i,version:a,attributes:o}=L.isString(t)?JSON.parse(t):t;return o=Ie._importAttributes(o),new Ie({map:r,name:n,options:i,version:a,attributes:o})}static _importAttributes(t){if(typeof t=="string"){try{const r=JSON.parse(t);if(typeof r=="object"&&r!==null)return Ie._importAttributes(r)}catch{}return t}if(Array.isArray(t))return t.map(r=>Ie._importAttributes(r));if(typeof t=="object"&&t!==null){const r={};for(const[n,i]of Object.entries(t))r[n]=Ie._importAttributes(i);return r}return t}export(){return{version:this.version,name:this.name,options:this.options,attributes:this._exportAttributes(this.attributes),map:this.map}}_exportAttributes(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(r=>this._exportAttributes(r));if(typeof t=="object"&&t!==null){const r={};for(const[n,i]of Object.entries(t))r[n]=this._exportAttributes(i);return r}return t}async applyHooksActions(t,r){for(const[n,i]of Object.entries(this.options.hooks[r]))for(const a of i){const o=L.get(t,n);o!==void 0&&typeof lo[a]=="function"&&L.set(t,n,await lo[a](o,{passphrase:this.passphrase,separator:this.options.arraySeparator}))}}async validate(t,{mutateOriginal:r=!1}={}){let n=r?t:L.cloneDeep(t);return await this.validator(n)}async mapper(t){const r=Jt.flatten(L.cloneDeep(t),{safe:!0});await this.applyHooksActions(r,"beforeMap");const n={_v:this.version+""};for(const[i,a]of Object.entries(r))n[this.map[i]]=a;return await this.applyHooksActions(n,"afterMap"),n}async unmapper(t){const r=L.cloneDeep(t);delete r._v,await this.applyHooksActions(r,"beforeUnmap");const n={};for(const[i,a]of Object.entries(r))n[this.reversedMap[i]]=a;return await this.applyHooksActions(n,"afterUnmap"),Jt.unflatten(n)}preprocessAttributesForValidation(t){const r={};for(const[n,i]of Object.entries(t))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){const a=i.$$type&&i.$$type.includes("required"),o=i.$$type&&i.$$type.includes("optional"),s={type:"object",properties:this.preprocessAttributesForValidation(i),strict:!1};a||(o||this.allNestedObjectsOptional)&&(s.optional=!0),r[n]=s}else r[n]=i;return r}}var ht=typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:{},he=[],ne=[],Mc=typeof Uint8Array<"u"?Uint8Array:Array,$n=!1;function uo(){$n=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t<r;++t)he[t]=e[t],ne[e.charCodeAt(t)]=t;ne[45]=62,ne[95]=63}function jc(e){$n||uo();var t,r,n,i,a,o,s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");a=e[s-2]==="="?2:e[s-1]==="="?1:0,o=new Mc(s*3/4-a),n=a>0?s-4:s;var c=0;for(t=0,r=0;t<n;t+=4,r+=3)i=ne[e.charCodeAt(t)]<<18|ne[e.charCodeAt(t+1)]<<12|ne[e.charCodeAt(t+2)]<<6|ne[e.charCodeAt(t+3)],o[c++]=i>>16&255,o[c++]=i>>8&255,o[c++]=i&255;return a===2?(i=ne[e.charCodeAt(t)]<<2|ne[e.charCodeAt(t+1)]>>4,o[c++]=i&255):a===1&&(i=ne[e.charCodeAt(t)]<<10|ne[e.charCodeAt(t+1)]<<4|ne[e.charCodeAt(t+2)]>>2,o[c++]=i>>8&255,o[c++]=i&255),o}function Lc(e){return he[e>>18&63]+he[e>>12&63]+he[e>>6&63]+he[e&63]}function Nc(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16)+(e[a+1]<<8)+e[a+2],i.push(Lc(n));return i.join("")}function ho(e){$n||uo();for(var t,r=e.length,n=r%3,i="",a=[],o=16383,s=0,c=r-n;s<c;s+=o)a.push(Nc(e,s,s+o>c?c:s+o));return n===1?(t=e[r-1],i+=he[t>>2],i+=he[t<<4&63],i+="=="):n===2&&(t=(e[r-2]<<8)+e[r-1],i+=he[t>>10],i+=he[t>>4&63],i+=he[t<<2&63],i+="="),a.push(i),a.join("")}function ir(e,t,r,n,i){var a,o,s=i*8-n-1,c=(1<<s)-1,f=c>>1,l=-7,d=r?i-1:0,h=r?-1:1,u=e[t+d];for(d+=h,a=u&(1<<-l)-1,u>>=-l,l+=s;l>0;a=a*256+e[t+d],d+=h,l-=8);for(o=a&(1<<-l)-1,a>>=-l,l+=n;l>0;o=o*256+e[t+d],d+=h,l-=8);if(a===0)a=1-f;else{if(a===c)return o?NaN:(u?-1:1)*(1/0);o=o+Math.pow(2,n),a=a-f}return(u?-1:1)*o*Math.pow(2,a-n)}function po(e,t,r,n,i,a){var o,s,c,f=a*8-i-1,l=(1<<f)-1,d=l>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=n?0:a-1,p=n?1:-1,v=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+d>=1?t+=h/c:t+=h*Math.pow(2,1-d),t*c>=2&&(o++,c/=2),o+d>=l?(s=0,o=l):o+d>=1?(s=(t*c-1)*Math.pow(2,i),o=o+d):(s=t*Math.pow(2,d-1)*Math.pow(2,i),o=0));i>=8;e[r+u]=s&255,u+=p,s/=256,i-=8);for(o=o<<i|s,f+=i;f>0;e[r+u]=o&255,u+=p,o/=256,f-=8);e[r+u-p]|=v*128}var Bc={}.toString,yo=Array.isArray||function(e){return Bc.call(e)=="[object Array]"};/*!
16
16
  * The buffer module from node.js, for the browser.
17
17
  *
18
18
  * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
@@ -26,4 +26,4 @@ ${JSON.stringify(i,null,2)}`}),this.resourceName=r,this.attributes=n,this.valida
26
26
  `))):s=e.stylize("[Circular]","special")),Fe(o)){if(a&&i.match(/^\d+$/))return s;o=JSON.stringify(""+i),o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=e.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=e.stylize(o,"string"))}return o+": "+s}function Kl(e,t,r){var n=e.reduce(function(i,a){return a.indexOf(`
27
27
  `)>=0,i+a.replace(/\u001b\[\d\d?m/g,"").length+1},0);return n>60?r[0]+(t===""?"":t+`
28
28
  `)+" "+e.join(`,
29
- `)+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function Wl(e){return Array.isArray(e)}function Mo(e){return typeof e=="boolean"}function Vn(e){return e===null}function Vl(e){return typeof e=="number"}function Gn(e){return typeof e=="string"}function Fe(e){return e===void 0}function Yn(e){return Ot(e)&&Qn(e)==="[object RegExp]"}function Ot(e){return typeof e=="object"&&e!==null}function jo(e){return Ot(e)&&Qn(e)==="[object Date]"}function Jn(e){return Ot(e)&&(Qn(e)==="[object Error]"||e instanceof Error)}function Xn(e){return typeof e=="function"}function Qn(e){return Object.prototype.toString.call(e)}function Gl(e,t){if(!t||!Ot(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}function Lo(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ke(){this.head=null,this.tail=null,this.length=0}Ke.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},Ke.prototype.unshift=function(e){var t={data:e,next:this.head};this.length===0&&(this.tail=t),this.head=t,++this.length},Ke.prototype.shift=function(){if(this.length!==0){var e=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},Ke.prototype.clear=function(){this.head=this.tail=null,this.length=0},Ke.prototype.join=function(e){if(this.length===0)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r},Ke.prototype.concat=function(e){if(this.length===0)return y.alloc(0);if(this.length===1)return this.head.data;for(var t=y.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var Yl=y.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function Jl(e){if(e&&!Yl(e))throw new Error("Unknown encoding: "+e)}function Tt(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),Jl(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=Ql;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=eu;break;default:this.write=Xl;return}this.charBuffer=new y(6),this.charReceived=0,this.charLength=0}Tt.prototype.write=function(e){for(var t="";this.charLength;){var r=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived<this.charLength)return"";e=e.slice(r,e.length),t=this.charBuffer.slice(0,this.charLength).toString(this.encoding);var i=t.charCodeAt(t.length-1);if(i>=55296&&i<=56319){this.charLength+=this.surrogateSize,t="";continue}if(this.charReceived=this.charLength=0,e.length===0)return t;break}this.detectIncompleteChar(e);var n=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,n),n-=this.charReceived),t+=e.toString(this.encoding,0,n);var n=t.length-1,i=t.charCodeAt(n);if(i>=55296&&i<=56319){var a=this.surrogateSize;return this.charLength+=a,this.charReceived+=a,this.charBuffer.copy(this.charBuffer,a,0,a),e.copy(this.charBuffer,0,0,a),t.substring(0,n)}return t},Tt.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var r=e[e.length-t];if(t==1&&r>>5==6){this.charLength=2;break}if(t<=2&&r>>4==14){this.charLength=3;break}if(t<=3&&r>>3==30){this.charLength=4;break}}this.charReceived=t},Tt.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var r=this.charReceived,n=this.charBuffer,i=this.encoding;t+=n.slice(0,r).toString(i)}return t};function Xl(e){return e.toString(this.encoding)}function Ql(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function eu(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}N.ReadableState=No;var D=Ul("stream");W(N,R);function tu(e,t,r){if(typeof e.prependListener=="function")return e.prependListener(t,r);!e._events||!e._events[t]?e.on(t,r):Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]}function ru(e,t){return e.listeners(t).length}function No(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof ie&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16*1024;this.highWaterMark=r||r===0?r:n,this.highWaterMark=~~this.highWaterMark,this.buffer=new Ke,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(this.decoder=new Tt(e.encoding),this.encoding=e.encoding)}function N(e){if(!(this instanceof N))return new N(e);this._readableState=new No(e,this),this.readable=!0,e&&typeof e.read=="function"&&(this._read=e.read),R.call(this)}N.prototype.push=function(e,t){var r=this._readableState;return!r.objectMode&&typeof e=="string"&&(t=t||r.defaultEncoding,t!==r.encoding&&(e=y.from(e,t),t="")),Bo(this,r,e,t,!1)},N.prototype.unshift=function(e){var t=this._readableState;return Bo(this,t,e,"",!0)},N.prototype.isPaused=function(){return this._readableState.flowing===!1};function Bo(e,t,r,n,i){var a=au(t,r);if(a)e.emit("error",a);else if(r===null)t.reading=!1,ou(e,t);else if(t.objectMode||r&&r.length>0)if(t.ended&&!i){var o=new Error("stream.push() after EOF");e.emit("error",o)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}else{var c;t.decoder&&!i&&!n&&(r=t.decoder.write(r),c=!t.objectMode&&r.length===0),i||(t.reading=!1),c||(t.flowing&&t.length===0&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&dr(e))),su(e,t)}else i||(t.reading=!1);return nu(t)}function nu(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||e.length===0)}N.prototype.setEncoding=function(e){return this._readableState.decoder=new Tt(e),this._readableState.encoding=e,this};var Uo=8388608;function iu(e){return e>=Uo?e=Uo:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function $o(e,t){return e<=0||t.length===0&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=iu(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}N.prototype.read=function(e){D("read",e),e=parseInt(e,10);var t=this._readableState,r=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return D("read: emitReadable",t.length,t.ended),t.length===0&&t.ended?ti(this):dr(this),null;if(e=$o(e,t),e===0&&t.ended)return t.length===0&&ti(this),null;var n=t.needReadable;D("need readable",n),(t.length===0||t.length-e<t.highWaterMark)&&(n=!0,D("length less than watermark",n)),t.ended||t.reading?(n=!1,D("reading or ended",n)):n&&(D("do read"),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=$o(r,t)));var i;return e>0?i=Zo(e,t):i=null,i===null?(t.needReadable=!0,e=0):t.length-=e,t.length===0&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&ti(this)),i!==null&&this.emit("data",i),i};function au(e,t){var r=null;return!y.isBuffer(t)&&typeof t!="string"&&t!==null&&t!==void 0&&!e.objectMode&&(r=new TypeError("Invalid non-string/buffer chunk")),r}function ou(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,dr(e)}}function dr(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(D("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?te(zo,e):zo(e))}function zo(e){D("emit readable"),e.emit("readable"),ei(e)}function su(e,t){t.readingMore||(t.readingMore=!0,te(fu,e,t))}function fu(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(D("maybeReadMore read 0"),e.read(0),r!==t.length);)r=t.length;t.readingMore=!1}N.prototype._read=function(e){this.emit("error",new Error("not implemented"))},N.prototype.pipe=function(e,t){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=e;break;case 1:n.pipes=[n.pipes,e];break;default:n.pipes.push(e);break}n.pipesCount+=1,D("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||t.end!==!1,a=i?s:l;n.endEmitted?te(a):r.once("end",a),e.on("unpipe",o);function o(w){D("onunpipe"),w===r&&l()}function s(){D("onend"),e.end()}var c=cu(r);e.on("drain",c);var f=!1;function l(){D("cleanup"),e.removeListener("close",p),e.removeListener("finish",v),e.removeListener("drain",c),e.removeListener("error",u),e.removeListener("unpipe",o),r.removeListener("end",s),r.removeListener("end",l),r.removeListener("data",h),f=!0,n.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&c()}var d=!1;r.on("data",h);function h(w){D("ondata"),d=!1;var E=e.write(w);E===!1&&!d&&((n.pipesCount===1&&n.pipes===e||n.pipesCount>1&&Ho(n.pipes,e)!==-1)&&!f&&(D("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,d=!0),r.pause())}function u(w){D("onerror",w),_(),e.removeListener("error",u),ru(e,"error")===0&&e.emit("error",w)}tu(e,"error",u);function p(){e.removeListener("finish",v),_()}e.once("close",p);function v(){D("onfinish"),e.removeListener("close",p),_()}e.once("finish",v);function _(){D("unpipe"),r.unpipe(e)}return e.emit("pipe",r),n.flowing||(D("pipe resume"),r.resume()),e};function cu(e){return function(){var t=e._readableState;D("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&e.listeners("data").length&&(t.flowing=!0,ei(e))}}N.prototype.unpipe=function(e){var t=this._readableState;if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i<n;i++)r[i].emit("unpipe",this);return this}var a=Ho(t.pipes,e);return a===-1?this:(t.pipes.splice(a,1),t.pipesCount-=1,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit("unpipe",this),this)},N.prototype.on=function(e,t){var r=R.prototype.on.call(this,e,t);if(e==="data")this._readableState.flowing!==!1&&this.resume();else if(e==="readable"){var n=this._readableState;!n.endEmitted&&!n.readableListening&&(n.readableListening=n.needReadable=!0,n.emittedReadable=!1,n.reading?n.length&&dr(this):te(lu,this))}return r},N.prototype.addListener=N.prototype.on;function lu(e){D("readable nexttick read 0"),e.read(0)}N.prototype.resume=function(){var e=this._readableState;return e.flowing||(D("resume"),e.flowing=!0,uu(this,e)),this};function uu(e,t){t.resumeScheduled||(t.resumeScheduled=!0,te(hu,e,t))}function hu(e,t){t.reading||(D("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),ei(e),t.flowing&&!t.reading&&e.read(0)}N.prototype.pause=function(){return D("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(D("pause"),this._readableState.flowing=!1,this.emit("pause")),this};function ei(e){var t=e._readableState;for(D("flow",t.flowing);t.flowing&&e.read()!==null;);}N.prototype.wrap=function(e){var t=this._readableState,r=!1,n=this;e.on("end",function(){if(D("wrapped end"),t.decoder&&!t.ended){var o=t.decoder.end();o&&o.length&&n.push(o)}n.push(null)}),e.on("data",function(o){if(D("wrapped data"),t.decoder&&(o=t.decoder.write(o)),!(t.objectMode&&o==null)&&!(!t.objectMode&&(!o||!o.length))){var s=n.push(o);s||(r=!0,e.pause())}});for(var i in e)this[i]===void 0&&typeof e[i]=="function"&&(this[i]=function(o){return function(){return e[o].apply(e,arguments)}}(i));var a=["error","close","destroy","pause","resume"];return gu(a,function(o){e.on(o,n.emit.bind(n,o))}),n._read=function(o){D("wrapped _read",o),r&&(r=!1,e.resume())},n},N._fromList=Zo;function Zo(e,t){if(t.length===0)return null;var r;return t.objectMode?r=t.buffer.shift():!e||e>=t.length?(t.decoder?r=t.buffer.join(""):t.buffer.length===1?r=t.buffer.head.data:r=t.buffer.concat(t.length),t.buffer.clear()):r=du(e,t.buffer,t.decoder),r}function du(e,t,r){var n;return e<t.head.data.length?(n=t.head.data.slice(0,e),t.head.data=t.head.data.slice(e)):e===t.head.data.length?n=t.shift():n=r?pu(e,t):yu(e,t),n}function pu(e,t){var r=t.head,n=1,i=r.data;for(e-=i.length;r=r.next;){var a=r.data,o=e>a.length?a.length:e;if(o===a.length?i+=a:i+=a.slice(0,e),e-=o,e===0){o===a.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=a.slice(o));break}++n}return t.length-=n,i}function yu(e,t){var r=y.allocUnsafe(e),n=t.head,i=1;for(n.data.copy(r),e-=n.data.length;n=n.next;){var a=n.data,o=e>a.length?a.length:e;if(a.copy(r,r.length-e,0,o),e-=o,e===0){o===a.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=a.slice(o));break}++i}return t.length-=i,r}function ti(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,te(vu,t,e))}function vu(e,t){!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function gu(e,t){for(var r=0,n=e.length;r<n;r++)t(e[r],r)}function Ho(e,t){for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}H.WritableState=ri,W(H,R);function _u(){}function wu(e,t,r){this.chunk=e,this.encoding=t,this.callback=r,this.next=null}function ri(e,t){Object.defineProperty(this,"buffer",{get:Fo(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")}),e=e||{},this.objectMode=!!e.objectMode,t instanceof ie&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16*1024;this.highWaterMark=r||r===0?r:n,this.highWaterMark=~~this.highWaterMark,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1;var i=e.decodeStrings===!1;this.decodeStrings=!i,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(a){ku(t,a)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new Yo(this)}ri.prototype.getBuffer=function(){for(var t=this.bufferedRequest,r=[];t;)r.push(t),t=t.next;return r};function H(e){if(!(this instanceof H)&&!(this instanceof ie))return new H(e);this._writableState=new ri(e,this),this.writable=!0,e&&(typeof e.write=="function"&&(this._write=e.write),typeof e.writev=="function"&&(this._writev=e.writev)),R.call(this)}H.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))};function bu(e,t){var r=new Error("write after end");e.emit("error",r),te(t,r)}function mu(e,t,r,n){var i=!0,a=!1;return r===null?a=new TypeError("May not write null values to stream"):!y.isBuffer(r)&&typeof r!="string"&&r!==void 0&&!t.objectMode&&(a=new TypeError("Invalid non-string/buffer chunk")),a&&(e.emit("error",a),te(n,a),i=!1),i}H.prototype.write=function(e,t,r){var n=this._writableState,i=!1;return typeof t=="function"&&(r=t,t=null),y.isBuffer(e)?t="buffer":t||(t=n.defaultEncoding),typeof r!="function"&&(r=_u),n.ended?bu(this,r):mu(this,n,e,r)&&(n.pendingcb++,i=Eu(this,n,e,t,r)),i},H.prototype.cork=function(){var e=this._writableState;e.corked++},H.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.finished&&!e.bufferProcessing&&e.bufferedRequest&&Ko(this,e))},H.prototype.setDefaultEncoding=function(t){if(typeof t=="string"&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this};function xu(e,t,r){return!e.objectMode&&e.decodeStrings!==!1&&typeof t=="string"&&(t=y.from(t,r)),t}function Eu(e,t,r,n,i){r=xu(t,r,n),y.isBuffer(r)&&(n="buffer");var a=t.objectMode?1:r.length;t.length+=a;var o=t.length<t.highWaterMark;if(o||(t.needDrain=!0),t.writing||t.corked){var s=t.lastBufferedRequest;t.lastBufferedRequest=new wu(r,n,i),s?s.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else ni(e,t,!1,a,r,n,i);return o}function ni(e,t,r,n,i,a,o){t.writelen=n,t.writecb=o,t.writing=!0,t.sync=!0,r?e._writev(i,t.onwrite):e._write(i,a,t.onwrite),t.sync=!1}function Su(e,t,r,n,i){--t.pendingcb,r?te(i,n):i(n),e._writableState.errorEmitted=!0,e.emit("error",n)}function Au(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function ku(e,t){var r=e._writableState,n=r.sync,i=r.writecb;if(Au(r),t)Su(e,r,n,t,i);else{var a=Wo(r);!a&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest&&Ko(e,r),n?te(qo,e,r,a,i):qo(e,r,a,i)}}function qo(e,t,r,n){r||Ru(e,t),t.pendingcb--,n(),Go(e,t)}function Ru(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function Ko(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var n=t.bufferedRequestCount,i=new Array(n),a=t.corkedRequestsFree;a.entry=r;for(var o=0;r;)i[o]=r,r=r.next,o+=1;ni(e,t,!0,t.length,i,"",a.finish),t.pendingcb++,t.lastBufferedRequest=null,a.next?(t.corkedRequestsFree=a.next,a.next=null):t.corkedRequestsFree=new Yo(t)}else{for(;r;){var s=r.chunk,c=r.encoding,f=r.callback,l=t.objectMode?1:s.length;if(ni(e,t,!1,l,s,c,f),r=r.next,t.writing)break}r===null&&(t.lastBufferedRequest=null)}t.bufferedRequestCount=0,t.bufferedRequest=r,t.bufferProcessing=!1}H.prototype._write=function(e,t,r){r(new Error("not implemented"))},H.prototype._writev=null,H.prototype.end=function(e,t,r){var n=this._writableState;typeof e=="function"?(r=e,e=null,t=null):typeof t=="function"&&(r=t,t=null),e!=null&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),!n.ending&&!n.finished&&Ou(this,n,r)};function Wo(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function Vo(e,t){t.prefinished||(t.prefinished=!0,e.emit("prefinish"))}function Go(e,t){var r=Wo(t);return r&&(t.pendingcb===0?(Vo(e,t),t.finished=!0,e.emit("finish")):Vo(e,t)),r}function Ou(e,t,r){t.ending=!0,Go(e,t),r&&(t.finished?te(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function Yo(e){var t=this;this.next=null,this.entry=null,this.finish=function(r){var n=t.entry;for(t.entry=null;n;){var i=n.callback;e.pendingcb--,i(r),n=n.next}e.corkedRequestsFree?e.corkedRequestsFree.next=t:e.corkedRequestsFree=t}}W(ie,N);for(var Jo=Object.keys(H.prototype),ii=0;ii<Jo.length;ii++){var ai=Jo[ii];ie.prototype[ai]||(ie.prototype[ai]=H.prototype[ai])}function ie(e){if(!(this instanceof ie))return new ie(e);N.call(this,e),H.call(this,e),e&&e.readable===!1&&(this.readable=!1),e&&e.writable===!1&&(this.writable=!1),this.allowHalfOpen=!0,e&&e.allowHalfOpen===!1&&(this.allowHalfOpen=!1),this.once("end",Tu)}function Tu(){this.allowHalfOpen||this._writableState.ended||te(Iu,this)}function Iu(e){e.end()}W(re,ie);function Pu(e){this.afterTransform=function(t,r){return Cu(e,t,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null,this.writeencoding=null}function Cu(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));n.writechunk=null,n.writecb=null,r!=null&&e.push(r),i(t);var a=e._readableState;a.reading=!1,(a.needReadable||a.length<a.highWaterMark)&&e._read(a.highWaterMark)}function re(e){if(!(this instanceof re))return new re(e);ie.call(this,e),this._transformState=new Pu(this);var t=this;this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.once("prefinish",function(){typeof this._flush=="function"?this._flush(function(r){Xo(t,r)}):Xo(t)})}re.prototype.push=function(e,t){return this._transformState.needTransform=!1,ie.prototype.push.call(this,e,t)},re.prototype._transform=function(e,t,r){throw new Error("Not implemented")},re.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},re.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};function Xo(e,t){if(t)return e.emit("error",t);var r=e._writableState,n=e._transformState;if(r.length)throw new Error("Calling transform done when ws.length != 0");if(n.transforming)throw new Error("Calling transform done when still transforming");return e.push(null)}W(It,re);function It(e){if(!(this instanceof It))return new It(e);re.call(this,e)}It.prototype._transform=function(e,t,r){r(null,e)},W(Ee,R),Ee.Readable=N,Ee.Writable=H,Ee.Duplex=ie,Ee.Transform=re,Ee.PassThrough=It,Ee.Stream=Ee;function Ee(){R.call(this)}Ee.prototype.pipe=function(e,t){var r=this;function n(l){e.writable&&e.write(l)===!1&&r.pause&&r.pause()}r.on("data",n);function i(){r.readable&&r.resume&&r.resume()}e.on("drain",i),!e._isStdio&&(!t||t.end!==!1)&&(r.on("end",o),r.on("close",s));var a=!1;function o(){a||(a=!0,e.end())}function s(){a||(a=!0,typeof e.destroy=="function"&&e.destroy())}function c(l){if(f(),R.listenerCount(this,"error")===0)throw l}r.on("error",c),e.on("error",c);function f(){r.removeListener("data",n),e.removeListener("drain",i),r.removeListener("end",o),r.removeListener("close",s),r.removeListener("error",c),e.removeListener("error",c),r.removeListener("end",f),r.removeListener("close",f),e.removeListener("close",f)}return r.on("end",f),r.on("close",f),e.on("close",f),e.emit("pipe",r),e};class Qo extends R{constructor({resource:t}){super(),this.resource=t,this.client=t.client,this.stream=new Ff.ReadableStream({highWaterMark:this.client.parallelism*3,start:this._start.bind(this),pull:this._pull.bind(this),cancel:this._cancel.bind(this)})}build(){return this.stream.getReader()}async _start(t){this.controller=t,this.continuationToken=null,this.closeNextIteration=!1}async _pull(t){if(this.closeNextIteration){t.close();return}const r=await this.client.listObjects({prefix:`resource=${this.resource.name}`,continuationToken:this.continuationToken}),n=r?.Contents.map(i=>i.Key).map(i=>i.replace(this.client.config.keyPrefix,"")).map(i=>i.startsWith("/")?i.replace("/",""):i).map(i=>i.replace(`resource=${this.resource.name}/id=`,""));this.continuationToken=r.NextContinuationToken,this.enqueue(n),r.IsTruncated||(this.closeNextIteration=!0)}enqueue(t){t.forEach(r=>{this.controller.enqueue(r),this.emit("id",r)})}_cancel(t){console.warn("Stream cancelled",t)}}class es extends Qo{enqueue(t){this.controller.enqueue(t),this.emit("page",t)}}class ts extends R{constructor({resource:t,batchSize:r=10,concurrency:n=5}){if(super(),!t)throw new Error("Resource is required for ResourceReader");this.resource=t,this.client=t.client,this.batchSize=r,this.concurrency=n,this.input=new es({resource:this.resource}),this.transform=new re({objectMode:!0,transform:this._transform.bind(this)}),this.input.on("data",i=>{this.transform.write(i)}),this.input.on("end",()=>{this.transform.end()}),this.input.on("error",i=>{this.emit("error",i)}),this.transform.on("data",i=>{this.emit("data",i)}),this.transform.on("end",()=>{this.emit("end")}),this.transform.on("error",i=>{this.emit("error",i)})}build(){return this}async _transform(t,r,n){try{await ce.PromisePool.for(t).withConcurrency(this.concurrency).handleError(async(i,a)=>{this.emit("error",i,a)}).process(async i=>{const a=await this.resource.get(i);return this.push(a),a}),n()}catch(i){n(i)}}resume(){this.input.resume()}}class rs extends R{constructor({resource:t,batchSize:r=10,concurrency:n=5}){super(),this.resource=t,this.client=t.client,this.batchSize=r,this.concurrency=n,this.buffer=[],this.writing=!1,this.writable=new H({objectMode:!0,write:this._write.bind(this)}),this.writable.on("finish",()=>{this.emit("finish")}),this.writable.on("error",i=>{this.emit("error",i)})}build(){return this}write(t){return this.buffer.push(t),this._maybeWrite(),!0}end(){this.ended=!0,this._maybeWrite()}async _maybeWrite(){if(!this.writing&&!(this.buffer.length===0&&!this.ended)){for(this.writing=!0;this.buffer.length>0;){const t=this.buffer.splice(0,this.batchSize);try{await ce.PromisePool.for(t).withConcurrency(this.concurrency).handleError(async(r,n)=>{this.emit("error",r,n)}).process(async r=>{await this.resource.insert(r)})}catch(r){this.emit("error",r)}}this.writing=!1,this.ended&&this.writable.emit("finish")}}async _write(t,r,n){n()}}function Pt(e){return new Promise((t,r)=>{const n=[];e.on("data",i=>n.push(i)),e.on("error",r),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))})}function Ct(e){typeof e!="string"&&(e=String(e));let t=0;for(let r=0;r<e.length;r++){const n=e.codePointAt(r);n<=127?t+=1:n<=2047?t+=2:n<=65535?t+=3:n<=1114111&&(t+=4,n>65535&&r++)}return t}function ns(e){return e==null?"":typeof e=="boolean"?e?"1":"0":typeof e=="number"?String(e):typeof e=="string"?e:Array.isArray(e)?e.length===0?"[]":e.map(t=>String(t)).join("|"):typeof e=="object"?JSON.stringify(e):String(e)}function oi(e){const t={};for(const[r,n]of Object.entries(e)){const i=ns(n),a=Ct(i);t[r]=a}return t}function We(e){const t=oi(e);return Object.values(t).reduce((r,n)=>r+n,0)}const Se=2048;async function Du({resource:e,data:t,mappedData:r}){const n=We(r);return n>Se&&e.emit("exceedsLimit",{operation:"insert",totalSize:n,limit:Se,excess:n-Se,data:t}),{mappedData:r,body:""}}async function Fu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);return i>Se&&e.emit("exceedsLimit",{operation:"update",id:t,totalSize:i,limit:Se,excess:i-Se,data:r}),{mappedData:n,body:""}}async function Mu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);return i>Se&&e.emit("exceedsLimit",{operation:"upsert",id:t,totalSize:i,limit:Se,excess:i-Se,data:r}),{mappedData:n,body:""}}async function ju({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var Lu=Object.freeze({__proto__:null,handleGet:ju,handleInsert:Du,handleUpdate:Fu,handleUpsert:Mu});const yt=2048;async function Nu({resource:e,data:t,mappedData:r}){const n=We(r);if(n>yt)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${n} bytes, limit: ${yt} bytes`);return{mappedData:r,body:""}}async function Bu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);if(i>yt)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${yt} bytes`);return{mappedData:n,body:""}}async function Uu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);if(i>yt)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${yt} bytes`);return{mappedData:n,body:""}}async function $u({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var zu=Object.freeze({__proto__:null,handleGet:$u,handleInsert:Nu,handleUpdate:Bu,handleUpsert:Uu});const is=2048,as="...",os=Ct(as);async function Zu({resource:e,data:t,mappedData:r}){return si({resource:e,data:t,mappedData:r})}async function Hu({resource:e,id:t,data:r,mappedData:n}){return si({resource:e,data:r,mappedData:n})}async function qu({resource:e,id:t,data:r,mappedData:n}){return si({resource:e,data:r,mappedData:n})}async function Ku({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}function si({resource:e,data:t,mappedData:r}){const n=oi(r),i=Object.entries(n).sort(([,s],[,c])=>s-c),a={};let o=0;for(const[s,c]of i){const f=is-o;if(c<=f)a[s]=r[s],o+=c;else if(f>os){const l=f-os,d=ns(r[s]);let h="",u=0;for(let p=0;p<d.length;p++){const v=d[p],_=Ct(v);if(u+_<=l)h+=v,u+=_;else break}a[s]=h+as,o=is;break}else break}return{mappedData:a,body:""}}var Wu=Object.freeze({__proto__:null,handleGet:Ku,handleInsert:Zu,handleUpdate:Hu,handleUpsert:qu});const ss=2048,pr="$overflow",fi="true",Vu=Ct(pr)+Ct(fi);async function Gu({resource:e,data:t,mappedData:r}){return ci({resource:e,data:t,mappedData:r})}async function Yu({resource:e,id:t,data:r,mappedData:n}){return ci({resource:e,data:r,mappedData:n})}async function Ju({resource:e,id:t,data:r,mappedData:n}){return ci({resource:e,data:r,mappedData:n})}async function Xu({resource:e,metadata:t,body:r}){if(t[pr]===fi)try{const n=r?JSON.parse(r):{},i={...t};return delete i[pr],{metadata:{...i,...n},body:""}}catch{return{metadata:t,body:r}}return{metadata:t,body:r}}function ci({resource:e,data:t,mappedData:r}){if(We(r)<=ss)return{mappedData:r,body:""};const i=ss-Vu,a=oi(r),o=Object.entries(a).sort(([,d],[,h])=>d-h),s={},c={};let f=0;for(const[d,h]of o)f+h<=i?(s[d]=r[d],f+=h):c[d]=r[d];s[pr]=fi;const l=Object.keys(c).length>0?JSON.stringify(c):"";return{mappedData:s,body:l}}var Qu=Object.freeze({__proto__:null,handleGet:Xu,handleInsert:Gu,handleUpdate:Yu,handleUpsert:Ju});const fs={"user-management":Lu,"enforce-limits":zu,"data-truncate":Wu,"body-overflow":Qu};function vt(e){const t=fs[e];if(!t)throw new Error(`Unknown behavior: ${e}. Available behaviors: ${Object.keys(fs).join(", ")}`);return t}const eh="user-management";class li extends R{constructor({name:t,client:r,version:n="1",options:i={},attributes:a={},parallelism:o=10,passphrase:s="secret",observers:c=[],behavior:f=eh}){if(super(),this.name=t,this.client=r,this.version=n,this.behavior=f,this.observers=c,this.parallelism=o,this.passphrase=s??"secret",this.options={cache:!1,autoDecrypt:!0,timestamps:!1,partitions:{},paranoid:!0,...i},this.hooks={preInsert:[],afterInsert:[],preUpdate:[],afterUpdate:[],preDelete:[],afterDelete:[]},this.attributes=a||{},i.timestamps&&(this.attributes.createdAt="string|optional",this.attributes.updatedAt="string|optional",this.options.partitions.byCreatedDate||(this.options.partitions.byCreatedDate={fields:{createdAt:"date|maxlength:10"}}),this.options.partitions.byUpdatedDate||(this.options.partitions.byUpdatedDate={fields:{updatedAt:"date|maxlength:10"}})),this.schema=new Ie({name:t,attributes:this.attributes,passphrase:s,version:this.version,options:this.options}),this.validatePartitions(),this.setupPartitionHooks(),i.hooks){for(const[l,d]of Object.entries(i.hooks))if(Array.isArray(d)&&this.hooks[l])for(const h of d)this.hooks[l].push(h.bind(this))}}export(){const t=this.schema.export();return t.behavior=this.behavior,t}updateAttributes(t){const r=this.attributes;return this.attributes=t,this.options.timestamps&&(t.createdAt="string|optional",t.updatedAt="string|optional",this.options.partitions.byCreatedDate||(this.options.partitions.byCreatedDate={fields:{createdAt:"date|maxlength:10"}}),this.options.partitions.byUpdatedDate||(this.options.partitions.byUpdatedDate={fields:{updatedAt:"date|maxlength:10"}})),this.schema=new Ie({name:this.name,attributes:t,passphrase:this.passphrase,version:this.version,options:this.options}),this.validatePartitions(),this.setupPartitionHooks(),{oldAttributes:r,newAttributes:t}}addHook(t,r){this.hooks[t]&&this.hooks[t].push(r.bind(this))}async executeHooks(t,r){if(!this.hooks[t])return r;let n=r;for(const i of this.hooks[t])n=await i(n);return n}setupPartitionHooks(){const t=this.options.partitions;!t||Object.keys(t).length===0||(this.addHook("afterInsert",async r=>(await this.createPartitionReferences(r),r)),this.addHook("afterDelete",async r=>(await this.deletePartitionReferences(r),r)))}async validate(t){const r={original:L.cloneDeep(t),isValid:!1,errors:[]},n=await this.schema.validate(t,{mutateOriginal:!0});return n===!0?r.isValid=!0:r.errors=n,r.data=t,r}validatePartitions(){const t=this.options.partitions;if(!t||Object.keys(t).length===0)return;const r=Object.keys(this.attributes||{});for(const[n,i]of Object.entries(t))if(i.fields){for(const a of Object.keys(i.fields))if(!this.fieldExistsInAttributes(a))throw new Error(`Partition '${n}' uses field '${a}' which does not exist in resource version '${this.version}'. Available fields: ${r.join(", ")}. This version of resource does not have support for this partition.`)}}fieldExistsInAttributes(t){if(!t.includes("."))return Object.keys(this.attributes||{}).includes(t);const r=t.split(".");let n=this.attributes||{};for(const i of r){if(!n||typeof n!="object"||!(i in n))return!1;n=n[i]}return!0}applyPartitionRule(t,r){if(t==null)return t;let n=t;if(typeof r=="string"&&r.includes("maxlength:")){const i=r.match(/maxlength:(\d+)/);if(i){const a=parseInt(i[1]);typeof n=="string"&&n.length>a&&(n=n.substring(0,a))}}if(r.includes("date")){if(n instanceof Date)n=n.toISOString().split("T")[0];else if(typeof n=="string")try{if(n.includes("T")&&n.includes("Z"))n=n.split("T")[0];else{const i=new Date(n);isNaN(i.getTime())||(n=i.toISOString().split("T")[0])}}catch{}}return n}getResourceKey(t){return we(`resource=${this.name}`,`v=${this.version}`,`id=${t}`)}getPartitionKey(t,r,n){const i=this.options.partitions[t];if(!i)throw new Error(`Partition '${t}' not found`);const a=[],o=Object.entries(i.fields).sort(([s],[c])=>s.localeCompare(c));for(const[s,c]of o){const f=this.getNestedFieldValue(n,s),l=this.applyPartitionRule(f,c);if(l==null)return null;a.push(`${s}=${l}`)}return a.length===0?null:we(`resource=${this.name}`,`partition=${t}`,...a,`id=${r}`)}getNestedFieldValue(t,r){if(!r.includes("."))return t[r];const n=r.split(".");let i=t;for(const a of n){if(i==null||typeof i!="object")return;i=i[a]}return i}async insert({id:t,...r}){this.options.timestamps&&(r.createdAt=new Date().toISOString(),r.updatedAt=new Date().toISOString());const n=await this.executeHooks("preInsert",r),{errors:i,isValid:a,data:o}=await this.validate(n);if(!a)throw new Xt({bucket:this.client.config.bucket,resourceName:this.name,attributes:n,validation:i});!t&&t!==0&&(t=Zi());const s=await this.schema.mapper(o),c=vt(this.behavior),{mappedData:f,body:l}=await c.handleInsert({resource:this,data:o,mappedData:s}),d=this.getResourceKey(t);await this.client.putObject({metadata:f,key:d,body:l});const h=L.merge({id:t},o);return await this.executeHooks("afterInsert",h),this.emit("insert",h),h}async get(t){const r=this.getResourceKey(t),n=await this.client.headObject(r),i=this.extractVersionFromKey(r)||this.version;let o=await(await this.getSchemaForVersion(i)).unmapper(n.Metadata);const s=vt(this.behavior);let c="";if(n.ContentLength>0)try{const d=await this.client.getObject(r);c=await Pt(d.Body)}catch{c=""}const{metadata:f}=await s.handleGet({resource:this,metadata:o,body:c});let l=f;return l.id=t,l._contentLength=n.ContentLength,l._lastModified=n.LastModified,l._hasContent=n.ContentLength>0,l._mimeType=n.ContentType||null,n.VersionId&&(l._versionId=n.VersionId),n.Expiration&&(l._expiresAt=n.Expiration),l._definitionHash=this.getDefinitionHash(),this.emit("get",l),l}async exists(t){try{const r=this.getResourceKey(t);return await this.client.headObject(r),!0}catch{return!1}}async update(t,r){const n=await this.get(t);this.options.timestamps&&(r.updatedAt=new Date().toISOString());const i=await this.executeHooks("preUpdate",r),a=L.merge(n,i);delete a.id;const{isValid:o,errors:s,data:c}=await this.validate(a);if(!o)throw new Xt({bucket:this.client.bucket,resourceName:this.name,attributes:i,validation:s});const f=await this.schema.mapper(c),l=vt(this.behavior),{mappedData:d,body:h}=await l.handleUpdate({resource:this,id:t,data:c,mappedData:f}),u=this.getResourceKey(t);let p,v=h;if(h===""&&this.behavior!=="body-overflow")try{const _=await this.client.getObject(u);if(_.ContentLength>0){const w=Buffer.from(await _.Body.transformToByteArray()),E=w.toString();try{JSON.parse(E)}catch{v=w,p=_.ContentType}}}catch{}return await this.client.putObject({key:u,body:v,contentType:p,metadata:d}),c.id=t,await this.executeHooks("afterUpdate",c),await this.updatePartitionReferences(c),this.emit("update",i,c),c}async delete(t){let r;try{r=await this.get(t)}catch{r={id:t}}await this.executeHooks("preDelete",r);const n=this.getResourceKey(t),i=await this.client.deleteObject(n);return await this.executeHooks("afterDelete",r),this.emit("delete",t),i}async upsert({id:t,...r}){return await this.exists(t)?this.update(t,r):this.insert({id:t,...r})}async count({partition:t=null,partitionValues:r={}}={}){let n;if(t&&Object.keys(r).length>0){const a=this.options.partitions[t];if(!a)throw new Error(`Partition '${t}' not found`);const o=[],s=Object.entries(a.fields).sort(([c],[f])=>c.localeCompare(f));for(const[c,f]of s){const l=r[c];if(l!=null){const d=this.applyPartitionRule(l,f);o.push(`${c}=${d}`)}}o.length>0?n=`resource=${this.name}/partition=${t}/${o.join("/")}`:n=`resource=${this.name}/partition=${t}`}else n=`resource=${this.name}/v=${this.version}`;const i=await this.client.count({prefix:n});return this.emit("count",i),i}async insertMany(t){const{results:r}=await ce.PromisePool.for(t).withConcurrency(this.parallelism).handleError(async(n,i)=>{this.emit("error",n,i),this.observers.map(a=>a.emit("error",this.name,n,i))}).process(async n=>await this.insert(n));return this.emit("insertMany",t.length),r}async deleteMany(t){const r=L.chunk(t.map(i=>this.getResourceKey(i)),1e3),{results:n}=await ce.PromisePool.for(r).withConcurrency(this.parallelism).handleError(async(i,a)=>{this.emit("error",i,a),this.observers.map(o=>o.emit("error",this.name,i,a))}).process(async i=>{const a=await this.client.deleteObjects(i);return i.forEach(o=>{const c=o.split("/").find(l=>l.startsWith("id=")),f=c?c.replace("id=",""):null;f&&(this.emit("deleted",f),this.observers.map(l=>l.emit("deleted",this.name,f)))}),a});return this.emit("deleteMany",t.length),n}async deleteAll(){if(this.options.paranoid!==!1)throw new Error(`deleteAll() is a dangerous operation and requires paranoid: false option. Current paranoid setting: ${this.options.paranoid}`);const t=`resource=${this.name}/v=${this.version}`,r=await this.client.deleteAll({prefix:t});return this.emit("deleteAll",{version:this.version,prefix:t,deletedCount:r}),{deletedCount:r,version:this.version}}async deleteAllData(){if(this.options.paranoid!==!1)throw new Error(`deleteAllData() is a dangerous operation and requires paranoid: false option. Current paranoid setting: ${this.options.paranoid}`);const t=`resource=${this.name}`,r=await this.client.deleteAll({prefix:t});return this.emit("deleteAllData",{resource:this.name,prefix:t,deletedCount:r}),{deletedCount:r,resource:this.name}}async listIds({partition:t=null,partitionValues:r={}}={}){let n;if(t&&Object.keys(r).length>0){const o=this.options.partitions[t];if(!o)throw new Error(`Partition '${t}' not found`);const s=[],c=Object.entries(o.fields).sort(([f],[l])=>f.localeCompare(l));for(const[f,l]of c){const d=r[f];if(d!=null){const h=this.applyPartitionRule(d,l);s.push(`${f}=${h}`)}}s.length>0?n=`resource=${this.name}/partition=${t}/${s.join("/")}`:n=`resource=${this.name}/partition=${t}`}else n=`resource=${this.name}/v=${this.version}`;const a=(await this.client.getAllKeys({prefix:n})).map(o=>{const c=o.split("/").find(f=>f.startsWith("id="));return c?c.replace("id=",""):null}).filter(Boolean);return this.emit("listIds",a.length),a}async listByPartition({partition:t=null,partitionValues:r={}}={},n={}){const{limit:i,offset:a=0}=n;if(!t){let v=(await this.listIds({partition:t,partitionValues:r})).slice(a);i&&(v=v.slice(0,i));const{results:_}=await ce.PromisePool.for(v).withConcurrency(this.parallelism).process(async w=>await this.get(w));return this.emit("listByPartition",{partition:t,partitionValues:r,count:_.length}),_}const o=this.options.partitions[t];if(!o)throw new Error(`Partition '${t}' not found`);const s=[],c=Object.entries(o.fields).sort(([p],[v])=>p.localeCompare(v));for(const[p,v]of c){const _=r[p];if(_!=null){const w=this.applyPartitionRule(_,v);s.push(`${p}=${w}`)}}let f;s.length>0?f=`resource=${this.name}/partition=${t}/${s.join("/")}`:f=`resource=${this.name}/partition=${t}`;let h=(await this.client.getAllKeys({prefix:f})).map(p=>{const _=p.split("/").find(w=>w.startsWith("id="));return _?_.replace("id=",""):null}).filter(Boolean).slice(a);i&&(h=h.slice(0,i));const{results:u}=await ce.PromisePool.for(h).withConcurrency(this.parallelism).process(async p=>await this.getFromPartition(p,t,r));return this.emit("listByPartition",{partition:t,partitionValues:r,count:u.length}),u}async getMany(t){const{results:r}=await ce.PromisePool.for(t).withConcurrency(this.client.parallelism).process(async n=>{this.emit("id",n);const i=await this.get(n);return this.emit("data",i),i});return this.emit("getMany",t.length),r}async getAll(){let t=await this.listIds();if(t.length===0)return[];const{results:r}=await ce.PromisePool.for(t).withConcurrency(this.client.parallelism).process(async n=>await this.get(n));return this.emit("getAll",r.length),r}async page(t=0,r=100,{partition:n=null,partitionValues:i={}}={}){const a=await this.listIds({partition:n,partitionValues:i}),o=a.length,s=Math.ceil(o/r),c=a.slice(t*r,(t+1)*r),l={items:await Promise.all(c.map(d=>this.get(d))),totalItems:o,page:t,pageSize:r,totalPages:s};return this.emit("page",l),l}readable(){return new ts({resource:this}).build()}writable(){return new rs({resource:this}).build()}async setContent(t,r,n="application/octet-stream"){if(!Buffer.isBuffer(r))throw new Error("Content must be a Buffer");const i=this.getResourceKey(t);let a={};try{a=(await this.client.headObject(i)).Metadata||{}}catch{}const o=await this.client.putObject({key:i,body:r,contentType:n,metadata:a});return this.emit("setContent",t,r.length,n),o}async content(t){const r=this.getResourceKey(t);try{const n=await this.client.getObject(r),i=Buffer.from(await n.Body.transformToByteArray()),a=n.ContentType||null;return this.emit("content",t,i.length,a),{buffer:i,contentType:a}}catch(n){if(n.name==="NoSuchKey")return{buffer:null,contentType:null};throw n}}async hasContent(t){const r=this.getResourceKey(t);try{return(await this.client.headObject(r)).ContentLength>0}catch{return!1}}async deleteContent(t){const r=this.getResourceKey(t),i=(await this.client.headObject(r)).Metadata||{},a=await this.client.putObject({key:r,body:"",metadata:i});return this.emit("deleteContent",t),a}getDefinitionHash(){const r={...this.schema.export().attributes};this.options.timestamps&&(delete r.createdAt,delete r.updatedAt);const n=so(r);return`sha256:${Bi.createHash("sha256").update(n).digest("hex")}`}extractVersionFromKey(t){const n=t.split("/").find(i=>i.startsWith("v="));return n?n.replace("v=",""):null}async getSchemaForVersion(t){return this.schema}async createPartitionReferences(t){const r=this.options.partitions;if(!(!r||Object.keys(r).length===0))for(const[n,i]of Object.entries(r)){const a=this.getPartitionKey(n,t.id,t);if(a){const o=await this.schema.mapper(t),s=vt(this.behavior),{mappedData:c,body:f}=await s.handleInsert({resource:this,data:t,mappedData:o}),l={...c,_version:this.version};await this.client.putObject({key:a,metadata:l,body:f})}}}async deletePartitionReferences(t){const r=this.options.partitions;if(!r||Object.keys(r).length===0)return;const n=[];for(const[i,a]of Object.entries(r)){const o=this.getPartitionKey(i,t.id,t);o&&n.push(o)}if(n.length>0)try{await this.client.deleteObjects(n)}catch(i){console.warn("Some partition objects could not be deleted:",i.message)}}async query(t={}){const r=await this.getAll();return Object.keys(t).length===0?r:r.filter(n=>Object.entries(t).every(([i,a])=>n[i]===a))}async updatePartitionReferences(t){const r=this.options.partitions;if(!(!r||Object.keys(r).length===0))for(const[n,i]of Object.entries(r)){const a=this.getPartitionKey(n,t.id,t);if(a){const o=await this.schema.mapper(t),s=vt(this.behavior),{mappedData:c,body:f}=await s.handleUpdate({resource:this,id:t.id,data:t,mappedData:o}),l={...c,_version:this.version};try{await this.client.putObject({key:a,metadata:l,body:f})}catch(d){console.warn(`Partition object could not be updated for ${n}:`,d.message)}}}}async getFromPartition(t,r,n={}){const i=this.options.partitions[r];if(!i)throw new Error(`Partition '${r}' not found`);const a=[],o=Object.entries(i.fields).sort(([_],[w])=>_.localeCompare(w));for(const[_,w]of o){const E=n[_];if(E!=null){const S=this.applyPartitionRule(E,w);a.push(`${_}=${S}`)}}if(a.length===0)throw new Error(`No partition values provided for partition '${r}'`);const s=we(`resource=${this.name}`,`partition=${r}`,...a,`id=${t}`),c=await this.client.headObject(s),f=c.Metadata?._version||this.version;let d=await(await this.getSchemaForVersion(f)).unmapper(c.Metadata);const h=vt(this.behavior);let u="";if(c.ContentLength>0)try{const _=await this.client.getObject(s);u=await Pt(_.Body)}catch{u=""}const{metadata:p}=await h.handleGet({resource:this,metadata:d,body:u});let v=p;return v.id=t,v._contentLength=c.ContentLength,v._lastModified=c.LastModified,v._hasContent=c.ContentLength>0,v._mimeType=c.ContentType||null,v._partition=r,v._partitionValues=n,c.VersionId&&(v._versionId=c.VersionId),c.Expiration&&(v._expiresAt=c.Expiration),v._definitionHash=this.getDefinitionHash(),this.emit("getFromPartition",v),v}}class cs extends R{constructor(t){super(),this.version="1",this.s3dbVersion=(()=>{try{return"4.1.2"}catch{return"latest"}})(),this.resources={},this.savedMetadata=null,this.options=t,this.verbose=t.verbose||!1,this.parallelism=parseInt(t.parallelism+"")||10,this.plugins=t.plugins||[],this.cache=t.cache,this.passphrase=t.passphrase||"secret",this.client=t.client||new ra({verbose:this.verbose,parallelism:this.parallelism,connectionString:t.connectionString}),this.bucket=this.client.bucket,this.keyPrefix=this.client.keyPrefix}async connect(){await this.startPlugins();let t=null;if(await this.client.exists("s3db.json")){const n=await this.client.getObject("s3db.json");t=JSON.parse(await Pt(n?.Body))}else t=this.blankMetadataStructure(),await this.uploadMetadataFile();this.savedMetadata=t;const r=this.detectDefinitionChanges(t);for(const[n,i]of Object.entries(t.resources||{})){const a=i.currentVersion||"v0",o=i.versions?.[a];o&&(this.resources[n]=new li({name:n,client:this.client,version:a,options:{...o.options,partitions:i.partitions||o.options?.partitions||{}},attributes:o.attributes,behavior:o.behavior||"user-management",parallelism:this.parallelism,passphrase:this.passphrase,observers:[this]}))}r.length>0&&this.emit("resourceDefinitionsChanged",{changes:r,metadata:this.savedMetadata}),this.emit("connected",new Date)}detectDefinitionChanges(t){const r=[];for(const[n,i]of Object.entries(this.resources)){const a=this.generateDefinitionHash(i.export()),o=t.resources?.[n];if(!o)r.push({type:"new",resourceName:n,currentHash:a,savedHash:null});else{const s=o.currentVersion||"v0",f=o.versions?.[s]?.hash;f!==a&&r.push({type:"changed",resourceName:n,currentHash:a,savedHash:f,fromVersion:s,toVersion:this.getNextVersion(o.versions)})}}for(const[n,i]of Object.entries(t.resources||{}))if(!this.resources[n]){const a=i.currentVersion||"v0",o=i.versions?.[a];r.push({type:"deleted",resourceName:n,currentHash:null,savedHash:o?.hash,deletedVersion:a})}return r}generateDefinitionHash(t,r=void 0){const i={...t.attributes};t.options?.timestamps&&(delete i.createdAt,delete i.updatedAt);const a={attributes:i,behavior:r||t.behavior||"user-management"},o=so(a);return`sha256:${Bi.createHash("sha256").update(o).digest("hex")}`}getNextVersion(t={}){const r=Object.keys(t).filter(i=>i.startsWith("v")).map(i=>parseInt(i.substring(1))).filter(i=>!isNaN(i));return`v${(r.length>0?Math.max(...r):-1)+1}`}async startPlugins(){const t=this;if(!L.isEmpty(this.plugins)){const r=this.plugins.map(a=>L.isFunction(a)?new a(this):a),n=r.map(async a=>{a.beforeSetup&&await a.beforeSetup(),await a.setup(t),a.afterSetup&&await a.afterSetup()});await Promise.all(n);const i=r.map(async a=>{a.beforeStart&&await a.beforeStart(),await a.start(),a.afterStart&&await a.afterStart()});await Promise.all(i)}}async uploadMetadataFile(){const t={version:this.version,s3dbVersion:this.s3dbVersion,lastUpdated:new Date().toISOString(),resources:{}};Object.entries(this.resources).forEach(([r,n])=>{const i=n.export(),a=this.generateDefinitionHash(i),o=this.savedMetadata?.resources?.[r],s=o?.currentVersion||"v0",c=o?.versions?.[s];let f,l;!c||c.hash!==a?(f=this.getNextVersion(o?.versions),l=!0):(f=s,l=!1),t.resources[r]={currentVersion:f,partitions:i.options?.partitions||{},versions:{...o?.versions,[f]:{hash:a,attributes:i.attributes,options:i.options,behavior:i.behavior||"user-management",createdAt:l?new Date().toISOString():c?.createdAt}}},n.version!==f&&(n.version=f,n.emit("versionUpdated",{oldVersion:s,newVersion:f}))}),await this.client.putObject({key:"s3db.json",body:JSON.stringify(t,null,2),contentType:"application/json"}),this.savedMetadata=t,this.emit("metadataUploaded",t)}blankMetadataStructure(){return{version:"1",s3dbVersion:this.s3dbVersion,resources:{}}}resourceExists(t){return!!this.resources[t]}resourceExistsWithSameHash({name:t,attributes:r,options:n={},behavior:i="user-management"}){if(!this.resources[t])return{exists:!1,sameHash:!1,hash:null};const a=new li({name:t,attributes:r,behavior:i,observers:[],client:this.client,version:"temp",options:{cache:this.cache,...n}}),o=this.generateDefinitionHash(a.export(),i),s=this.generateDefinitionHash(this.resources[t].export(),this.resources[t].behavior);return{exists:!0,sameHash:o===s,hash:o,existingHash:s}}async createResourceIfNotExists({name:t,attributes:r,options:n={},behavior:i="user-management"}){const a=!!this.resources[t],o=this.resourceExistsWithSameHash({name:t,attributes:r,options:n,behavior:i});return o.exists&&o.sameHash?{resource:this.resources[t],created:!1,reason:"Resource already exists with same definition hash"}:{resource:await this.createResource({name:t,attributes:r,options:n,behavior:i}),created:!a,reason:a?"Resource updated with new definition":"New resource created"}}async createResource({name:t,attributes:r,options:n={},behavior:i="user-management"}){if(this.resources[t]){const c=this.resources[t];Object.assign(c.options,{cache:this.cache,...n}),i&&(c.behavior=i),c.updateAttributes(r);const f=this.generateDefinitionHash(c.export(),c.behavior),l=this.savedMetadata?.resources?.[t],d=l?.currentVersion||"v0",h=l?.versions?.[d];return(!h||h.hash!==f)&&await this.uploadMetadataFile(),this.emit("s3db.resourceUpdated",t),c}const o=this.savedMetadata?.resources?.[t]?.currentVersion||"v0",s=new li({name:t,attributes:r,behavior:i,observers:[this],client:this.client,version:o,options:{cache:this.cache,...n}});return this.resources[t]=s,await this.uploadMetadataFile(),this.emit("s3db.resourceCreated",t),s}resource(t){return this.resources[t]?this.resources[t]:Promise.reject(`resource ${t} does not exist`)}async listResources(){return Object.keys(this.resources).map(t=>({name:t}))}async getResource(t){if(!this.resources[t])throw new Error(`Resource not found: ${t}`);return this.resources[t]}get config(){return{version:this.version,s3dbVersion:this.s3dbVersion,bucket:this.bucket,keyPrefix:this.keyPrefix,parallelism:this.parallelism,verbose:this.verbose}}isConnected(){return!!this.savedMetadata}}class th extends cs{}class ui extends R{constructor(t={}){super(),this.config=t}async _set(t,r){}async _get(t){}async _del(t){}async _clear(t){}validateKey(t){if(t==null||typeof t!="string"||!t)throw new Error("Invalid key")}async set(t,r){return this.validateKey(t),await this._set(t,r),this.emit("set",r),r}async get(t){this.validateKey(t);const r=await this._get(t);return this.emit("get",r),r}async del(t){this.validateKey(t);const r=await this._del(t);return this.emit("delete",r),r}async delete(t){return this.del(t)}async clear(){const t=await this._clear();return this.emit("clear",t),t}}class rh extends ui{constructor(t={}){super(t),this.cache={},this.meta={},this.maxSize=t.maxSize||0,this.ttl=t.ttl||0}async _set(t,r){if(this.maxSize>0&&Object.keys(this.cache).length>=this.maxSize){const n=Object.entries(this.meta).sort((i,a)=>i[1].ts-a[1].ts)[0]?.[0];n&&(delete this.cache[n],delete this.meta[n])}return this.cache[t]=r,this.meta[t]={ts:Date.now()},r}async _get(t){if(!Object.prototype.hasOwnProperty.call(this.cache,t))return null;if(this.ttl>0){const r=Date.now(),n=this.meta[t];if(n&&r-n.ts>this.ttl*1e3)return delete this.cache[t],delete this.meta[t],null}return this.cache[t]}async _del(t){return delete this.cache[t],delete this.meta[t],!0}async _clear(){return this.cache={},this.meta={},!0}async size(){return Object.keys(this.cache).length}async keys(){return Object.keys(this.cache)}}var ls={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};function nh(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}function Ae(e,t,r,n,i){if(t.subarray&&e.subarray){e.set(t.subarray(r,r+n),i);return}for(var a=0;a<n;a++)e[i+a]=t[r+a]}var yr=Uint8Array,ae=Uint16Array,vr=Int32Array,ih=4,us=0,hs=1,ah=2;function gt(e){for(var t=e.length;--t>=0;)e[t]=0}var oh=0,ds=1,sh=2,fh=3,ch=258,hi=29,Dt=256,Ft=Dt+1+hi,_t=30,di=19,ps=2*Ft+1,Ve=15,pi=16,lh=7,yi=256,ys=16,vs=17,gs=18,vi=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],gr=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],uh=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],_s=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],hh=512,ke=new Array((Ft+2)*2);gt(ke);var Mt=new Array(_t*2);gt(Mt);var jt=new Array(hh);gt(jt);var Lt=new Array(ch-fh+1);gt(Lt);var gi=new Array(hi);gt(gi);var _r=new Array(_t);gt(_r);function _i(e,t,r,n,i){this.static_tree=e,this.extra_bits=t,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=e&&e.length}var ws,bs,ms;function wi(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}function xs(e){return e<256?jt[e]:jt[256+(e>>>7)]}function Nt(e,t){e.pending_buf[e.pending++]=t&255,e.pending_buf[e.pending++]=t>>>8&255}function X(e,t,r){e.bi_valid>pi-r?(e.bi_buf|=t<<e.bi_valid&65535,Nt(e,e.bi_buf),e.bi_buf=t>>pi-e.bi_valid,e.bi_valid+=r-pi):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r)}function pe(e,t,r){X(e,r[t*2],r[t*2+1])}function Es(e,t){var r=0;do r|=e&1,e>>>=1,r<<=1;while(--t>0);return r>>>1}function dh(e){e.bi_valid===16?(Nt(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=e.bi_buf&255,e.bi_buf>>=8,e.bi_valid-=8)}function ph(e,t){var r=t.dyn_tree,n=t.max_code,i=t.stat_desc.static_tree,a=t.stat_desc.has_stree,o=t.stat_desc.extra_bits,s=t.stat_desc.extra_base,c=t.stat_desc.max_length,f,l,d,h,u,p,v=0;for(h=0;h<=Ve;h++)e.bl_count[h]=0;for(r[e.heap[e.heap_max]*2+1]=0,f=e.heap_max+1;f<ps;f++)l=e.heap[f],h=r[r[l*2+1]*2+1]+1,h>c&&(h=c,v++),r[l*2+1]=h,!(l>n)&&(e.bl_count[h]++,u=0,l>=s&&(u=o[l-s]),p=r[l*2],e.opt_len+=p*(h+u),a&&(e.static_len+=p*(i[l*2+1]+u)));if(v!==0){do{for(h=c-1;e.bl_count[h]===0;)h--;e.bl_count[h]--,e.bl_count[h+1]+=2,e.bl_count[c]--,v-=2}while(v>0);for(h=c;h!==0;h--)for(l=e.bl_count[h];l!==0;)d=e.heap[--f],!(d>n)&&(r[d*2+1]!==h&&(e.opt_len+=(h-r[d*2+1])*r[d*2],r[d*2+1]=h),l--)}}function Ss(e,t,r){var n=new Array(Ve+1),i=0,a,o;for(a=1;a<=Ve;a++)n[a]=i=i+r[a-1]<<1;for(o=0;o<=t;o++){var s=e[o*2+1];s!==0&&(e[o*2]=Es(n[s]++,s))}}function yh(){var e,t,r,n,i,a=new Array(Ve+1);for(r=0,n=0;n<hi-1;n++)for(gi[n]=r,e=0;e<1<<vi[n];e++)Lt[r++]=n;for(Lt[r-1]=n,i=0,n=0;n<16;n++)for(_r[n]=i,e=0;e<1<<gr[n];e++)jt[i++]=n;for(i>>=7;n<_t;n++)for(_r[n]=i<<7,e=0;e<1<<gr[n]-7;e++)jt[256+i++]=n;for(t=0;t<=Ve;t++)a[t]=0;for(e=0;e<=143;)ke[e*2+1]=8,e++,a[8]++;for(;e<=255;)ke[e*2+1]=9,e++,a[9]++;for(;e<=279;)ke[e*2+1]=7,e++,a[7]++;for(;e<=287;)ke[e*2+1]=8,e++,a[8]++;for(Ss(ke,Ft+1,a),e=0;e<_t;e++)Mt[e*2+1]=5,Mt[e*2]=Es(e,5);ws=new _i(ke,vi,Dt+1,Ft,Ve),bs=new _i(Mt,gr,0,_t,Ve),ms=new _i(new Array(0),uh,0,di,lh)}function As(e){var t;for(t=0;t<Ft;t++)e.dyn_ltree[t*2]=0;for(t=0;t<_t;t++)e.dyn_dtree[t*2]=0;for(t=0;t<di;t++)e.bl_tree[t*2]=0;e.dyn_ltree[yi*2]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0}function ks(e){e.bi_valid>8?Nt(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0}function vh(e,t,r,n){ks(e),Nt(e,r),Nt(e,~r),Ae(e.pending_buf,e.window,t,r,e.pending),e.pending+=r}function Rs(e,t,r,n){var i=t*2,a=r*2;return e[i]<e[a]||e[i]===e[a]&&n[t]<=n[r]}function bi(e,t,r){for(var n=e.heap[r],i=r<<1;i<=e.heap_len&&(i<e.heap_len&&Rs(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!Rs(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n}function Os(e,t,r){var n,i,a=0,o,s;if(e.last_lit!==0)do n=e.pending_buf[e.d_buf+a*2]<<8|e.pending_buf[e.d_buf+a*2+1],i=e.pending_buf[e.l_buf+a],a++,n===0?pe(e,i,t):(o=Lt[i],pe(e,o+Dt+1,t),s=vi[o],s!==0&&(i-=gi[o],X(e,i,s)),n--,o=xs(n),pe(e,o,r),s=gr[o],s!==0&&(n-=_r[o],X(e,n,s)));while(a<e.last_lit);pe(e,yi,t)}function mi(e,t){var r=t.dyn_tree,n=t.stat_desc.static_tree,i=t.stat_desc.has_stree,a=t.stat_desc.elems,o,s,c=-1,f;for(e.heap_len=0,e.heap_max=ps,o=0;o<a;o++)r[o*2]!==0?(e.heap[++e.heap_len]=c=o,e.depth[o]=0):r[o*2+1]=0;for(;e.heap_len<2;)f=e.heap[++e.heap_len]=c<2?++c:0,r[f*2]=1,e.depth[f]=0,e.opt_len--,i&&(e.static_len-=n[f*2+1]);for(t.max_code=c,o=e.heap_len>>1;o>=1;o--)bi(e,r,o);f=a;do o=e.heap[1],e.heap[1]=e.heap[e.heap_len--],bi(e,r,1),s=e.heap[1],e.heap[--e.heap_max]=o,e.heap[--e.heap_max]=s,r[f*2]=r[o*2]+r[s*2],e.depth[f]=(e.depth[o]>=e.depth[s]?e.depth[o]:e.depth[s])+1,r[o*2+1]=r[s*2+1]=f,e.heap[1]=f++,bi(e,r,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],ph(e,t),Ss(r,c,e.bl_count)}function Ts(e,t,r){var n,i=-1,a,o=t[0*2+1],s=0,c=7,f=4;for(o===0&&(c=138,f=3),t[(r+1)*2+1]=65535,n=0;n<=r;n++)a=o,o=t[(n+1)*2+1],!(++s<c&&a===o)&&(s<f?e.bl_tree[a*2]+=s:a!==0?(a!==i&&e.bl_tree[a*2]++,e.bl_tree[ys*2]++):s<=10?e.bl_tree[vs*2]++:e.bl_tree[gs*2]++,s=0,i=a,o===0?(c=138,f=3):a===o?(c=6,f=3):(c=7,f=4))}function Is(e,t,r){var n,i=-1,a,o=t[0*2+1],s=0,c=7,f=4;for(o===0&&(c=138,f=3),n=0;n<=r;n++)if(a=o,o=t[(n+1)*2+1],!(++s<c&&a===o)){if(s<f)do pe(e,a,e.bl_tree);while(--s!==0);else a!==0?(a!==i&&(pe(e,a,e.bl_tree),s--),pe(e,ys,e.bl_tree),X(e,s-3,2)):s<=10?(pe(e,vs,e.bl_tree),X(e,s-3,3)):(pe(e,gs,e.bl_tree),X(e,s-11,7));s=0,i=a,o===0?(c=138,f=3):a===o?(c=6,f=3):(c=7,f=4)}}function gh(e){var t;for(Ts(e,e.dyn_ltree,e.l_desc.max_code),Ts(e,e.dyn_dtree,e.d_desc.max_code),mi(e,e.bl_desc),t=di-1;t>=3&&e.bl_tree[_s[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t}function _h(e,t,r,n){var i;for(X(e,t-257,5),X(e,r-1,5),X(e,n-4,4),i=0;i<n;i++)X(e,e.bl_tree[_s[i]*2+1],3);Is(e,e.dyn_ltree,t-1),Is(e,e.dyn_dtree,r-1)}function wh(e){var t=4093624447,r;for(r=0;r<=31;r++,t>>>=1)if(t&1&&e.dyn_ltree[r*2]!==0)return us;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return hs;for(r=32;r<Dt;r++)if(e.dyn_ltree[r*2]!==0)return hs;return us}var Ps=!1;function bh(e){Ps||(yh(),Ps=!0),e.l_desc=new wi(e.dyn_ltree,ws),e.d_desc=new wi(e.dyn_dtree,bs),e.bl_desc=new wi(e.bl_tree,ms),e.bi_buf=0,e.bi_valid=0,As(e)}function Cs(e,t,r,n){X(e,(oh<<1)+(n?1:0),3),vh(e,t,r)}function mh(e){X(e,ds<<1,3),pe(e,yi,ke),dh(e)}function xh(e,t,r,n){var i,a,o=0;e.level>0?(e.strm.data_type===ah&&(e.strm.data_type=wh(e)),mi(e,e.l_desc),mi(e,e.d_desc),o=gh(e),i=e.opt_len+3+7>>>3,a=e.static_len+3+7>>>3,a<=i&&(i=a)):i=a=r+5,r+4<=i&&t!==-1?Cs(e,t,r,n):e.strategy===ih||a===i?(X(e,(ds<<1)+(n?1:0),3),Os(e,ke,Mt)):(X(e,(sh<<1)+(n?1:0),3),_h(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),Os(e,e.dyn_ltree,e.dyn_dtree)),As(e),n&&ks(e)}function Me(e,t,r){return e.pending_buf[e.d_buf+e.last_lit*2]=t>>>8&255,e.pending_buf[e.d_buf+e.last_lit*2+1]=t&255,e.pending_buf[e.l_buf+e.last_lit]=r&255,e.last_lit++,t===0?e.dyn_ltree[r*2]++:(e.matches++,t--,e.dyn_ltree[(Lt[r]+Dt+1)*2]++,e.dyn_dtree[xs(t)*2]++),e.last_lit===e.lit_bufsize-1}function xi(e,t,r,n){for(var i=e&65535|0,a=e>>>16&65535|0,o=0;r!==0;){o=r>2e3?2e3:r,r-=o;do i=i+t[n++]|0,a=a+i|0;while(--o);i%=65521,a%=65521}return i|a<<16|0}function Eh(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;t[r]=e}return t}var Sh=Eh();function Z(e,t,r,n){var i=Sh,a=n+r;e^=-1;for(var o=n;o<a;o++)e=e>>>8^i[(e^t[o])&255];return e^-1}var Ge=0,Ah=1,kh=3,je=4,Ds=5,Le=0,Fs=1,Ne=-2,Rh=-3,Ei=-5,Oh=-1,Th=1,wr=2,Ih=3,Ph=4,Ch=2,Si=8,Dh=9,Fh=29,Mh=256,Ai=Mh+1+Fh,jh=30,Lh=19,Nh=2*Ai+1,Bh=15,C=3,Be=258,se=Be+C+1,Uh=32,ki=42,Ri=69,br=73,mr=91,xr=103,Ye=113,Bt=666,$=1,Ut=2,Je=3,wt=4,$h=3;function Ue(e,t){return e.msg=ls[t],t}function Ms(e){return(e<<1)-(e>4?9:0)}function Xe(e){for(var t=e.length;--t>=0;)e[t]=0}function $e(e){var t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),r!==0&&(Ae(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,t.pending===0&&(t.pending_out=0))}function q(e,t){xh(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,$e(e.strm)}function P(e,t){e.pending_buf[e.pending++]=t}function $t(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255}function zh(e,t,r,n){var i=e.avail_in;return i>n&&(i=n),i===0?0:(e.avail_in-=i,Ae(t,e.input,e.next_in,i,r),e.state.wrap===1?e.adler=xi(e.adler,t,i,r):e.state.wrap===2&&(e.adler=Z(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)}function js(e,t){var r=e.max_chain_length,n=e.strstart,i,a,o=e.prev_length,s=e.nice_match,c=e.strstart>e.w_size-se?e.strstart-(e.w_size-se):0,f=e.window,l=e.w_mask,d=e.prev,h=e.strstart+Be,u=f[n+o-1],p=f[n+o];e.prev_length>=e.good_match&&(r>>=2),s>e.lookahead&&(s=e.lookahead);do if(i=t,!(f[i+o]!==p||f[i+o-1]!==u||f[i]!==f[n]||f[++i]!==f[n+1])){n+=2,i++;do;while(f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&n<h);if(a=Be-(h-n),n=h-Be,a>o){if(e.match_start=t,o=a,a>=s)break;u=f[n+o-1],p=f[n+o]}}while((t=d[t&l])>c&&--r!==0);return o<=e.lookahead?o:e.lookahead}function zt(e){var t=e.w_size,r,n,i,a,o;do{if(a=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-se)){Ae(e.window,e.window,t,t,0),e.match_start-=t,e.strstart-=t,e.block_start-=t,n=e.hash_size,r=n;do i=e.head[--r],e.head[r]=i>=t?i-t:0;while(--n);n=t,r=n;do i=e.prev[--r],e.prev[r]=i>=t?i-t:0;while(--n);a+=t}if(e.strm.avail_in===0)break;if(n=zh(e.strm,e.window,e.strstart+e.lookahead,a),e.lookahead+=n,e.lookahead+e.insert>=C)for(o=e.strstart-e.insert,e.ins_h=e.window[o],e.ins_h=(e.ins_h<<e.hash_shift^e.window[o+1])&e.hash_mask;e.insert&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[o+C-1])&e.hash_mask,e.prev[o&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=o,o++,e.insert--,!(e.lookahead+e.insert<C)););}while(e.lookahead<se&&e.strm.avail_in!==0)}function Zh(e,t){var r=65535;for(r>e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(zt(e),e.lookahead===0&&t===Ge)return $;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+r;if((e.strstart===0||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,q(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-se&&(q(e,!1),e.strm.avail_out===0))return $}return e.insert=0,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):(e.strstart>e.block_start&&(q(e,!1),e.strm.avail_out===0),$)}function Oi(e,t){for(var r,n;;){if(e.lookahead<se){if(zt(e),e.lookahead<se&&t===Ge)return $;if(e.lookahead===0)break}if(r=0,e.lookahead>=C&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+C-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),r!==0&&e.strstart-r<=e.w_size-se&&(e.match_length=js(e,r)),e.match_length>=C)if(n=Me(e,e.strstart-e.match_start,e.match_length-C),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=C){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+C-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(--e.match_length!==0);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+1])&e.hash_mask;else n=Me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(q(e,!1),e.strm.avail_out===0))return $}return e.insert=e.strstart<C-1?e.strstart:C-1,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):e.last_lit&&(q(e,!1),e.strm.avail_out===0)?$:Ut}function bt(e,t){for(var r,n,i;;){if(e.lookahead<se){if(zt(e),e.lookahead<se&&t===Ge)return $;if(e.lookahead===0)break}if(r=0,e.lookahead>=C&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+C-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=C-1,r!==0&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-se&&(e.match_length=js(e,r),e.match_length<=5&&(e.strategy===Th||e.match_length===C&&e.strstart-e.match_start>4096)&&(e.match_length=C-1)),e.prev_length>=C&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-C,n=Me(e,e.strstart-1-e.prev_match,e.prev_length-C),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+C-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(--e.prev_length!==0);if(e.match_available=0,e.match_length=C-1,e.strstart++,n&&(q(e,!1),e.strm.avail_out===0))return $}else if(e.match_available){if(n=Me(e,0,e.window[e.strstart-1]),n&&q(e,!1),e.strstart++,e.lookahead--,e.strm.avail_out===0)return $}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=Me(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<C-1?e.strstart:C-1,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):e.last_lit&&(q(e,!1),e.strm.avail_out===0)?$:Ut}function Hh(e,t){for(var r,n,i,a,o=e.window;;){if(e.lookahead<=Be){if(zt(e),e.lookahead<=Be&&t===Ge)return $;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=C&&e.strstart>0&&(i=e.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){a=e.strstart+Be;do;while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&i<a);e.match_length=Be-(a-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=C?(r=Me(e,1,e.match_length-C),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=Me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(q(e,!1),e.strm.avail_out===0))return $}return e.insert=0,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):e.last_lit&&(q(e,!1),e.strm.avail_out===0)?$:Ut}function qh(e,t){for(var r;;){if(e.lookahead===0&&(zt(e),e.lookahead===0)){if(t===Ge)return $;break}if(e.match_length=0,r=Me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(q(e,!1),e.strm.avail_out===0))return $}return e.insert=0,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):e.last_lit&&(q(e,!1),e.strm.avail_out===0)?$:Ut}function ye(e,t,r,n,i){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=n,this.func=i}var mt;mt=[new ye(0,0,0,0,Zh),new ye(4,4,8,4,Oi),new ye(4,5,16,8,Oi),new ye(4,6,32,32,Oi),new ye(4,4,16,16,bt),new ye(8,16,32,32,bt),new ye(8,16,128,128,bt),new ye(8,32,128,256,bt),new ye(32,128,258,1024,bt),new ye(32,258,258,4096,bt)];function Kh(e){e.window_size=2*e.w_size,Xe(e.head),e.max_lazy_match=mt[e.level].max_lazy,e.good_match=mt[e.level].good_length,e.nice_match=mt[e.level].nice_length,e.max_chain_length=mt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=C-1,e.match_available=0,e.ins_h=0}function Wh(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Si,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new ae(Nh*2),this.dyn_dtree=new ae((2*jh+1)*2),this.bl_tree=new ae((2*Lh+1)*2),Xe(this.dyn_ltree),Xe(this.dyn_dtree),Xe(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new ae(Bh+1),this.heap=new ae(2*Ai+1),Xe(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new ae(2*Ai+1),Xe(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Vh(e){var t;return!e||!e.state?Ue(e,Ne):(e.total_in=e.total_out=0,e.data_type=Ch,t=e.state,t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?ki:Ye,e.adler=t.wrap===2?0:1,t.last_flush=Ge,bh(t),Le)}function Ls(e){var t=Vh(e);return t===Le&&Kh(e.state),t}function Gh(e,t,r,n,i,a){if(!e)return Ne;var o=1;if(t===Oh&&(t=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>Dh||r!==Si||n<8||n>15||t<0||t>9||a<0||a>Ph)return Ue(e,Ne);n===8&&(n=9);var s=new Wh;return e.state=s,s.strm=e,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<<s.w_bits,s.w_mask=s.w_size-1,s.hash_bits=i+7,s.hash_size=1<<s.hash_bits,s.hash_mask=s.hash_size-1,s.hash_shift=~~((s.hash_bits+C-1)/C),s.window=new yr(s.w_size*2),s.head=new ae(s.hash_size),s.prev=new ae(s.w_size),s.lit_bufsize=1<<i+6,s.pending_buf_size=s.lit_bufsize*4,s.pending_buf=new yr(s.pending_buf_size),s.d_buf=1*s.lit_bufsize,s.l_buf=3*s.lit_bufsize,s.level=t,s.strategy=a,s.method=r,Ls(e)}function Yh(e,t){var r,n,i,a;if(!e||!e.state||t>Ds||t<0)return e?Ue(e,Ne):Ne;if(n=e.state,!e.output||!e.input&&e.avail_in!==0||n.status===Bt&&t!==je)return Ue(e,e.avail_out===0?Ei:Ne);if(n.strm=e,r=n.last_flush,n.last_flush=t,n.status===ki)if(n.wrap===2)e.adler=0,P(n,31),P(n,139),P(n,8),n.gzhead?(P(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),P(n,n.gzhead.time&255),P(n,n.gzhead.time>>8&255),P(n,n.gzhead.time>>16&255),P(n,n.gzhead.time>>24&255),P(n,n.level===9?2:n.strategy>=wr||n.level<2?4:0),P(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(P(n,n.gzhead.extra.length&255),P(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=Z(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=Ri):(P(n,0),P(n,0),P(n,0),P(n,0),P(n,0),P(n,n.level===9?2:n.strategy>=wr||n.level<2?4:0),P(n,$h),n.status=Ye);else{var o=Si+(n.w_bits-8<<4)<<8,s=-1;n.strategy>=wr||n.level<2?s=0:n.level<6?s=1:n.level===6?s=2:s=3,o|=s<<6,n.strstart!==0&&(o|=Uh),o+=31-o%31,n.status=Ye,$t(n,o),n.strstart!==0&&($t(n,e.adler>>>16),$t(n,e.adler&65535)),e.adler=1}if(n.status===Ri)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(n.gzhead.extra.length&65535)&&!(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),$e(e),i=n.pending,n.pending===n.pending_buf_size));)P(n,n.gzhead.extra[n.gzindex]&255),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=br)}else n.status=br;if(n.status===br)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),$e(e),i=n.pending,n.pending===n.pending_buf_size)){a=1;break}n.gzindex<n.gzhead.name.length?a=n.gzhead.name.charCodeAt(n.gzindex++)&255:a=0,P(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.gzindex=0,n.status=mr)}else n.status=mr;if(n.status===mr)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),$e(e),i=n.pending,n.pending===n.pending_buf_size)){a=1;break}n.gzindex<n.gzhead.comment.length?a=n.gzhead.comment.charCodeAt(n.gzindex++)&255:a=0,P(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.status=xr)}else n.status=xr;if(n.status===xr&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&$e(e),n.pending+2<=n.pending_buf_size&&(P(n,e.adler&255),P(n,e.adler>>8&255),e.adler=0,n.status=Ye)):n.status=Ye),n.pending!==0){if($e(e),e.avail_out===0)return n.last_flush=-1,Le}else if(e.avail_in===0&&Ms(t)<=Ms(r)&&t!==je)return Ue(e,Ei);if(n.status===Bt&&e.avail_in!==0)return Ue(e,Ei);if(e.avail_in!==0||n.lookahead!==0||t!==Ge&&n.status!==Bt){var c=n.strategy===wr?qh(n,t):n.strategy===Ih?Hh(n,t):mt[n.level].func(n,t);if((c===Je||c===wt)&&(n.status=Bt),c===$||c===Je)return e.avail_out===0&&(n.last_flush=-1),Le;if(c===Ut&&(t===Ah?mh(n):t!==Ds&&(Cs(n,0,0,!1),t===kh&&(Xe(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),$e(e),e.avail_out===0))return n.last_flush=-1,Le}return t!==je?Le:n.wrap<=0?Fs:(n.wrap===2?(P(n,e.adler&255),P(n,e.adler>>8&255),P(n,e.adler>>16&255),P(n,e.adler>>24&255),P(n,e.total_in&255),P(n,e.total_in>>8&255),P(n,e.total_in>>16&255),P(n,e.total_in>>24&255)):($t(n,e.adler>>>16),$t(n,e.adler&65535)),$e(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending!==0?Le:Fs)}function Jh(e){var t;return!e||!e.state?Ne:(t=e.state.status,t!==ki&&t!==Ri&&t!==br&&t!==mr&&t!==xr&&t!==Ye&&t!==Bt?Ue(e,Ne):(e.state=null,t===Ye?Ue(e,Rh):Le))}var Er=30,Xh=12;function Qh(e,t){var r,n,i,a,o,s,c,f,l,d,h,u,p,v,_,w,E,S,g,A,T,b,x,O,k;r=e.state,n=e.next_in,O=e.input,i=n+(e.avail_in-5),a=e.next_out,k=e.output,o=a-(t-e.avail_out),s=a+(e.avail_out-257),c=r.dmax,f=r.wsize,l=r.whave,d=r.wnext,h=r.window,u=r.hold,p=r.bits,v=r.lencode,_=r.distcode,w=(1<<r.lenbits)-1,E=(1<<r.distbits)-1;e:do{p<15&&(u+=O[n++]<<p,p+=8,u+=O[n++]<<p,p+=8),S=v[u&w];t:for(;;){if(g=S>>>24,u>>>=g,p-=g,g=S>>>16&255,g===0)k[a++]=S&65535;else if(g&16){A=S&65535,g&=15,g&&(p<g&&(u+=O[n++]<<p,p+=8),A+=u&(1<<g)-1,u>>>=g,p-=g),p<15&&(u+=O[n++]<<p,p+=8,u+=O[n++]<<p,p+=8),S=_[u&E];r:for(;;){if(g=S>>>24,u>>>=g,p-=g,g=S>>>16&255,g&16){if(T=S&65535,g&=15,p<g&&(u+=O[n++]<<p,p+=8,p<g&&(u+=O[n++]<<p,p+=8)),T+=u&(1<<g)-1,T>c){e.msg="invalid distance too far back",r.mode=Er;break e}if(u>>>=g,p-=g,g=a-o,T>g){if(g=T-g,g>l&&r.sane){e.msg="invalid distance too far back",r.mode=Er;break e}if(b=0,x=h,d===0){if(b+=f-g,g<A){A-=g;do k[a++]=h[b++];while(--g);b=a-T,x=k}}else if(d<g){if(b+=f+d-g,g-=d,g<A){A-=g;do k[a++]=h[b++];while(--g);if(b=0,d<A){g=d,A-=g;do k[a++]=h[b++];while(--g);b=a-T,x=k}}}else if(b+=d-g,g<A){A-=g;do k[a++]=h[b++];while(--g);b=a-T,x=k}for(;A>2;)k[a++]=x[b++],k[a++]=x[b++],k[a++]=x[b++],A-=3;A&&(k[a++]=x[b++],A>1&&(k[a++]=x[b++]))}else{b=a-T;do k[a++]=k[b++],k[a++]=k[b++],k[a++]=k[b++],A-=3;while(A>2);A&&(k[a++]=k[b++],A>1&&(k[a++]=k[b++]))}}else if((g&64)===0){S=_[(S&65535)+(u&(1<<g)-1)];continue r}else{e.msg="invalid distance code",r.mode=Er;break e}break}}else if((g&64)===0){S=v[(S&65535)+(u&(1<<g)-1)];continue t}else if(g&32){r.mode=Xh;break e}else{e.msg="invalid literal/length code",r.mode=Er;break e}break}}while(n<i&&a<s);A=p>>3,n-=A,p-=A<<3,u&=(1<<p)-1,e.next_in=n,e.next_out=a,e.avail_in=n<i?5+(i-n):5-(n-i),e.avail_out=a<s?257+(s-a):257-(a-s),r.hold=u,r.bits=p}var xt=15,Ns=852,Bs=592,Us=0,Ti=1,$s=2,ed=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],td=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],rd=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],nd=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];function Zt(e,t,r,n,i,a,o,s){var c=s.bits,f=0,l=0,d=0,h=0,u=0,p=0,v=0,_=0,w=0,E=0,S,g,A,T,b,x=null,O=0,k,F=new ae(xt+1),K=new ae(xt+1),G=null,oe=0,ft,Q,ve;for(f=0;f<=xt;f++)F[f]=0;for(l=0;l<n;l++)F[t[r+l]]++;for(u=c,h=xt;h>=1&&F[h]===0;h--);if(u>h&&(u=h),h===0)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(d=1;d<h&&F[d]===0;d++);for(u<d&&(u=d),_=1,f=1;f<=xt;f++)if(_<<=1,_-=F[f],_<0)return-1;if(_>0&&(e===Us||h!==1))return-1;for(K[1]=0,f=1;f<xt;f++)K[f+1]=K[f]+F[f];for(l=0;l<n;l++)t[r+l]!==0&&(o[K[t[r+l]]++]=l);if(e===Us?(x=G=o,k=19):e===Ti?(x=ed,O-=257,G=td,oe-=257,k=256):(x=rd,G=nd,k=-1),E=0,l=0,f=d,b=a,p=u,v=0,A=-1,w=1<<u,T=w-1,e===Ti&&w>Ns||e===$s&&w>Bs)return 1;for(;;){ft=f-v,o[l]<k?(Q=0,ve=o[l]):o[l]>k?(Q=G[oe+o[l]],ve=x[O+o[l]]):(Q=96,ve=0),S=1<<f-v,g=1<<p,d=g;do g-=S,i[b+(E>>v)+g]=ft<<24|Q<<16|ve|0;while(g!==0);for(S=1<<f-1;E&S;)S>>=1;if(S!==0?(E&=S-1,E+=S):E=0,l++,--F[f]===0){if(f===h)break;f=t[r+o[l]]}if(f>u&&(E&T)!==A){for(v===0&&(v=u),b+=d,p=f-v,_=1<<p;p+v<h&&(_-=F[p+v],!(_<=0));)p++,_<<=1;if(w+=1<<p,e===Ti&&w>Ns||e===$s&&w>Bs)return 1;A=E&T,i[A]=u<<24|p<<16|b-a|0}}return E!==0&&(i[b+E]=f-v<<24|4194304|0),s.bits=u,0}var id=0,zs=1,Zs=2,Hs=4,ad=5,Sr=6,Ht=0,od=1,sd=2,ze=-2,fd=-3,cd=-4,ld=-5,qs=8,Ks=1,Ws=2,Vs=3,Gs=4,Ys=5,Js=6,Xs=7,Qs=8,ef=9,tf=10,rf=11,Re=12,Ii=13,nf=14,Pi=15,af=16,of=17,sf=18,ff=19,Ar=20,kr=21,cf=22,lf=23,uf=24,hf=25,df=26,Ci=27,pf=28,yf=29,M=30,ud=31,hd=32,dd=852,pd=592;function vf(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function yd(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new ae(320),this.work=new ae(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function vd(e){var t;return!e||!e.state?ze:(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=t.wrap&1),t.mode=Ks,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new vr(dd),t.distcode=t.distdyn=new vr(pd),t.sane=1,t.back=-1,Ht)}function gf(e){var t;return!e||!e.state?ze:(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,vd(e))}function gd(e,t){var r,n;return!e||!e.state||(n=e.state,t<0?(r=0,t=-t):(r=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?ze:(n.window!==null&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,gf(e))}function _d(e,t){var r,n;return e?(n=new yd,e.state=n,n.window=null,r=gd(e,t),r!==Ht&&(e.state=null),r):ze}var _f=!0,Di,Fi;function wd(e){if(_f){var t;for(Di=new vr(512),Fi=new vr(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Zt(zs,e.lens,0,288,Di,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Zt(Zs,e.lens,0,32,Fi,0,e.work,{bits:5}),_f=!1}e.lencode=Di,e.lenbits=9,e.distcode=Fi,e.distbits=5}function bd(e,t,r,n){var i,a=e.state;return a.window===null&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new yr(a.wsize)),n>=a.wsize?(Ae(a.window,t,r-a.wsize,a.wsize,0),a.wnext=0,a.whave=a.wsize):(i=a.wsize-a.wnext,i>n&&(i=n),Ae(a.window,t,r-n,i,a.wnext),n-=i,n?(Ae(a.window,t,r-n,n,0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0}function md(e,t){var r,n,i,a,o,s,c,f,l,d,h,u,p,v,_=0,w,E,S,g,A,T,b,x,O=new yr(4),k,F,K=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!e||!e.state||!e.output||!e.input&&e.avail_in!==0)return ze;r=e.state,r.mode===Re&&(r.mode=Ii),o=e.next_out,i=e.output,c=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,f=r.hold,l=r.bits,d=s,h=c,x=Ht;e:for(;;)switch(r.mode){case Ks:if(r.wrap===0){r.mode=Ii;break}for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(r.wrap&2&&f===35615){r.check=0,O[0]=f&255,O[1]=f>>>8&255,r.check=Z(r.check,O,2,0),f=0,l=0,r.mode=Ws;break}if(r.flags=0,r.head&&(r.head.done=!1),!(r.wrap&1)||(((f&255)<<8)+(f>>8))%31){e.msg="incorrect header check",r.mode=M;break}if((f&15)!==qs){e.msg="unknown compression method",r.mode=M;break}if(f>>>=4,l-=4,b=(f&15)+8,r.wbits===0)r.wbits=b;else if(b>r.wbits){e.msg="invalid window size",r.mode=M;break}r.dmax=1<<b,e.adler=r.check=1,r.mode=f&512?tf:Re,f=0,l=0;break;case Ws:for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(r.flags=f,(r.flags&255)!==qs){e.msg="unknown compression method",r.mode=M;break}if(r.flags&57344){e.msg="unknown header flags set",r.mode=M;break}r.head&&(r.head.text=f>>8&1),r.flags&512&&(O[0]=f&255,O[1]=f>>>8&255,r.check=Z(r.check,O,2,0)),f=0,l=0,r.mode=Vs;case Vs:for(;l<32;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.head&&(r.head.time=f),r.flags&512&&(O[0]=f&255,O[1]=f>>>8&255,O[2]=f>>>16&255,O[3]=f>>>24&255,r.check=Z(r.check,O,4,0)),f=0,l=0,r.mode=Gs;case Gs:for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.head&&(r.head.xflags=f&255,r.head.os=f>>8),r.flags&512&&(O[0]=f&255,O[1]=f>>>8&255,r.check=Z(r.check,O,2,0)),f=0,l=0,r.mode=Ys;case Ys:if(r.flags&1024){for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.length=f,r.head&&(r.head.extra_len=f),r.flags&512&&(O[0]=f&255,O[1]=f>>>8&255,r.check=Z(r.check,O,2,0)),f=0,l=0}else r.head&&(r.head.extra=null);r.mode=Js;case Js:if(r.flags&1024&&(u=r.length,u>s&&(u=s),u&&(r.head&&(b=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),Ae(r.head.extra,n,a,u,b)),r.flags&512&&(r.check=Z(r.check,n,u,a)),s-=u,a+=u,r.length-=u),r.length))break e;r.length=0,r.mode=Xs;case Xs:if(r.flags&2048){if(s===0)break e;u=0;do b=n[a+u++],r.head&&b&&r.length<65536&&(r.head.name+=String.fromCharCode(b));while(b&&u<s);if(r.flags&512&&(r.check=Z(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=Qs;case Qs:if(r.flags&4096){if(s===0)break e;u=0;do b=n[a+u++],r.head&&b&&r.length<65536&&(r.head.comment+=String.fromCharCode(b));while(b&&u<s);if(r.flags&512&&(r.check=Z(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.comment=null);r.mode=ef;case ef:if(r.flags&512){for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(f!==(r.check&65535)){e.msg="header crc mismatch",r.mode=M;break}f=0,l=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=Re;break;case tf:for(;l<32;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}e.adler=r.check=vf(f),f=0,l=0,r.mode=rf;case rf:if(r.havedict===0)return e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=s,r.hold=f,r.bits=l,sd;e.adler=r.check=1,r.mode=Re;case Re:if(t===ad||t===Sr)break e;case Ii:if(r.last){f>>>=l&7,l-=l&7,r.mode=Ci;break}for(;l<3;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}switch(r.last=f&1,f>>>=1,l-=1,f&3){case 0:r.mode=nf;break;case 1:if(wd(r),r.mode=Ar,t===Sr){f>>>=2,l-=2;break e}break;case 2:r.mode=of;break;case 3:e.msg="invalid block type",r.mode=M}f>>>=2,l-=2;break;case nf:for(f>>>=l&7,l-=l&7;l<32;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if((f&65535)!==(f>>>16^65535)){e.msg="invalid stored block lengths",r.mode=M;break}if(r.length=f&65535,f=0,l=0,r.mode=Pi,t===Sr)break e;case Pi:r.mode=af;case af:if(u=r.length,u){if(u>s&&(u=s),u>c&&(u=c),u===0)break e;Ae(i,n,a,u,o),s-=u,a+=u,c-=u,o+=u,r.length-=u;break}r.mode=Re;break;case of:for(;l<14;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(r.nlen=(f&31)+257,f>>>=5,l-=5,r.ndist=(f&31)+1,f>>>=5,l-=5,r.ncode=(f&15)+4,f>>>=4,l-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=M;break}r.have=0,r.mode=sf;case sf:for(;r.have<r.ncode;){for(;l<3;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.lens[K[r.have++]]=f&7,f>>>=3,l-=3}for(;r.have<19;)r.lens[K[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,k={bits:r.lenbits},x=Zt(id,r.lens,0,19,r.lencode,0,r.work,k),r.lenbits=k.bits,x){e.msg="invalid code lengths set",r.mode=M;break}r.have=0,r.mode=ff;case ff:for(;r.have<r.nlen+r.ndist;){for(;_=r.lencode[f&(1<<r.lenbits)-1],w=_>>>24,E=_>>>16&255,S=_&65535,!(w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(S<16)f>>>=w,l-=w,r.lens[r.have++]=S;else{if(S===16){for(F=w+2;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(f>>>=w,l-=w,r.have===0){e.msg="invalid bit length repeat",r.mode=M;break}b=r.lens[r.have-1],u=3+(f&3),f>>>=2,l-=2}else if(S===17){for(F=w+3;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}f>>>=w,l-=w,b=0,u=3+(f&7),f>>>=3,l-=3}else{for(F=w+7;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}f>>>=w,l-=w,b=0,u=11+(f&127),f>>>=7,l-=7}if(r.have+u>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=M;break}for(;u--;)r.lens[r.have++]=b}}if(r.mode===M)break;if(r.lens[256]===0){e.msg="invalid code -- missing end-of-block",r.mode=M;break}if(r.lenbits=9,k={bits:r.lenbits},x=Zt(zs,r.lens,0,r.nlen,r.lencode,0,r.work,k),r.lenbits=k.bits,x){e.msg="invalid literal/lengths set",r.mode=M;break}if(r.distbits=6,r.distcode=r.distdyn,k={bits:r.distbits},x=Zt(Zs,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,k),r.distbits=k.bits,x){e.msg="invalid distances set",r.mode=M;break}if(r.mode=Ar,t===Sr)break e;case Ar:r.mode=kr;case kr:if(s>=6&&c>=258){e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=s,r.hold=f,r.bits=l,Qh(e,h),o=e.next_out,i=e.output,c=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,f=r.hold,l=r.bits,r.mode===Re&&(r.back=-1);break}for(r.back=0;_=r.lencode[f&(1<<r.lenbits)-1],w=_>>>24,E=_>>>16&255,S=_&65535,!(w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(E&&(E&240)===0){for(g=w,A=E,T=S;_=r.lencode[T+((f&(1<<g+A)-1)>>g)],w=_>>>24,E=_>>>16&255,S=_&65535,!(g+w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}f>>>=g,l-=g,r.back+=g}if(f>>>=w,l-=w,r.back+=w,r.length=S,E===0){r.mode=df;break}if(E&32){r.back=-1,r.mode=Re;break}if(E&64){e.msg="invalid literal/length code",r.mode=M;break}r.extra=E&15,r.mode=cf;case cf:if(r.extra){for(F=r.extra;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.length+=f&(1<<r.extra)-1,f>>>=r.extra,l-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=lf;case lf:for(;_=r.distcode[f&(1<<r.distbits)-1],w=_>>>24,E=_>>>16&255,S=_&65535,!(w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if((E&240)===0){for(g=w,A=E,T=S;_=r.distcode[T+((f&(1<<g+A)-1)>>g)],w=_>>>24,E=_>>>16&255,S=_&65535,!(g+w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}f>>>=g,l-=g,r.back+=g}if(f>>>=w,l-=w,r.back+=w,E&64){e.msg="invalid distance code",r.mode=M;break}r.offset=S,r.extra=E&15,r.mode=uf;case uf:if(r.extra){for(F=r.extra;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.offset+=f&(1<<r.extra)-1,f>>>=r.extra,l-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=M;break}r.mode=hf;case hf:if(c===0)break e;if(u=h-c,r.offset>u){if(u=r.offset-u,u>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=M;break}u>r.wnext?(u-=r.wnext,p=r.wsize-u):p=r.wnext-u,u>r.length&&(u=r.length),v=r.window}else v=i,p=o-r.offset,u=r.length;u>c&&(u=c),c-=u,r.length-=u;do i[o++]=v[p++];while(--u);r.length===0&&(r.mode=kr);break;case df:if(c===0)break e;i[o++]=r.length,c--,r.mode=kr;break;case Ci:if(r.wrap){for(;l<32;){if(s===0)break e;s--,f|=n[a++]<<l,l+=8}if(h-=c,e.total_out+=h,r.total+=h,h&&(e.adler=r.check=r.flags?Z(r.check,i,h,o-h):xi(r.check,i,h,o-h)),h=c,(r.flags?f:vf(f))!==r.check){e.msg="incorrect data check",r.mode=M;break}f=0,l=0}r.mode=pf;case pf:if(r.wrap&&r.flags){for(;l<32;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(f!==(r.total&4294967295)){e.msg="incorrect length check",r.mode=M;break}f=0,l=0}r.mode=yf;case yf:x=od;break e;case M:x=fd;break e;case ud:return cd;case hd:default:return ze}return e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=s,r.hold=f,r.bits=l,(r.wsize||h!==e.avail_out&&r.mode<M&&(r.mode<Ci||t!==Hs))&&bd(e,e.output,e.next_out,h-e.avail_out),d-=e.avail_in,h-=e.avail_out,e.total_in+=d,e.total_out+=h,r.total+=h,r.wrap&&h&&(e.adler=r.check=r.flags?Z(r.check,i,h,e.next_out-h):xi(r.check,i,h,e.next_out-h)),e.data_type=r.bits+(r.last?64:0)+(r.mode===Re?128:0)+(r.mode===Ar||r.mode===Pi?256:0),(d===0&&h===0||t===Hs)&&x===Ht&&(x=ld),x}function xd(e){if(!e||!e.state)return ze;var t=e.state;return t.window&&(t.window=null),e.state=null,Ht}var Mi=0,Et=1,Rr=2,qt=3,Or=4,St=5,Kt=6,Wt=7,wf=0,bf=1,mf=2,xf=3,ji=4,Ef=5,Ed=6,Tr=0,Sf=1,Af=2,Sd=-1,Ad=-2,kd=-3,kf=-5,Rd=0,Od=1,Td=9,Id=-1,Pd=1,Cd=2,Dd=3,Fd=4,Md=0,jd=0,Ld=1,Nd=2,Rf=8;function fe(e){if(e<Et||e>Wt)throw new TypeError("Bad argument");this.mode=e,this.init_done=!1,this.write_in_progress=!1,this.pending_close=!1,this.windowBits=0,this.level=0,this.memLevel=0,this.strategy=0,this.dictionary=null}fe.prototype.init=function(e,t,r,n,i){this.windowBits=e,this.level=t,this.memLevel=r,this.strategy=n,(this.mode===qt||this.mode===Or)&&(this.windowBits+=16),this.mode===Wt&&(this.windowBits+=32),(this.mode===St||this.mode===Kt)&&(this.windowBits=-this.windowBits),this.strm=new nh;var a;switch(this.mode){case Et:case qt:case St:a=Gh(this.strm,this.level,Rf,this.windowBits,this.memLevel,this.strategy);break;case Rr:case Or:case Kt:case Wt:a=_d(this.strm,this.windowBits);break;default:throw new Error("Unknown mode "+this.mode)}if(a!==Tr){this._error(a);return}this.write_in_progress=!1,this.init_done=!0},fe.prototype.params=function(){throw new Error("deflateParams Not supported")},fe.prototype._writeCheck=function(){if(!this.init_done)throw new Error("write before init");if(this.mode===Mi)throw new Error("already finalized");if(this.write_in_progress)throw new Error("write already in progress");if(this.pending_close)throw new Error("close is pending")},fe.prototype.write=function(e,t,r,n,i,a,o){this._writeCheck(),this.write_in_progress=!0;var s=this;return xe.nextTick(function(){s.write_in_progress=!1;var c=s._write(e,t,r,n,i,a,o);s.callback(c[0],c[1]),s.pending_close&&s.close()}),this};function Bd(e,t){for(var r=0;r<e.length;r++)this[t+r]=e[r]}fe.prototype.writeSync=function(e,t,r,n,i,a,o){return this._writeCheck(),this._write(e,t,r,n,i,a,o)},fe.prototype._write=function(e,t,r,n,i,a,o){if(this.write_in_progress=!0,e!==wf&&e!==bf&&e!==mf&&e!==xf&&e!==ji&&e!==Ef)throw new Error("Invalid flush value");t==null&&(t=new y(0),n=0,r=0),i._set?i.set=i._set:i.set=Bd;var s=this.strm;s.avail_in=n,s.input=t,s.next_in=r,s.avail_out=o,s.output=i,s.next_out=a;var c;switch(this.mode){case Et:case qt:case St:c=Yh(s,e);break;case Wt:case Rr:case Or:case Kt:c=md(s,e);break;default:throw new Error("Unknown mode "+this.mode)}return this._checkError(c,s,e)||this._error(c),this.write_in_progress=!1,[s.avail_in,s.avail_out]},fe.prototype._checkError=function(e,t,r){switch(e){case Tr:case kf:if(t.avail_out!==0&&r===ji)return!1;break;case Sf:break;case Af:return!1;default:return!1}return!0},fe.prototype.close=function(){if(this.write_in_progress){this.pending_close=!0;return}this.pending_close=!1,this.mode===Et||this.mode===qt||this.mode===St?Jh(this.strm):xd(this.strm),this.mode=Mi};var Ir;fe.prototype.reset=function(){switch(this.mode){case Et:case St:Ir=Ls(this.strm);break;case Rr:case Kt:Ir=gf(this.strm);break}Ir!==Tr&&this._error(Ir)},fe.prototype._error=function(e){this.onerror(ls[e]+": "+this.strm.msg,e),this.write_in_progress=!1,this.pending_close&&this.close()};var Of=Object.freeze({__proto__:null,DEFLATE:Et,DEFLATERAW:St,GUNZIP:Or,GZIP:qt,INFLATE:Rr,INFLATERAW:Kt,NONE:Mi,UNZIP:Wt,Z_BEST_COMPRESSION:Td,Z_BEST_SPEED:Od,Z_BINARY:jd,Z_BLOCK:Ef,Z_BUF_ERROR:kf,Z_DATA_ERROR:kd,Z_DEFAULT_COMPRESSION:Id,Z_DEFAULT_STRATEGY:Md,Z_DEFLATED:Rf,Z_ERRNO:Sd,Z_FILTERED:Pd,Z_FINISH:ji,Z_FIXED:Fd,Z_FULL_FLUSH:xf,Z_HUFFMAN_ONLY:Cd,Z_NEED_DICT:Af,Z_NO_COMPRESSION:Rd,Z_NO_FLUSH:wf,Z_OK:Tr,Z_PARTIAL_FLUSH:bf,Z_RLE:Dd,Z_STREAM_END:Sf,Z_STREAM_ERROR:Ad,Z_SYNC_FLUSH:mf,Z_TEXT:Ld,Z_TREES:Ed,Z_UNKNOWN:Nd,Zlib:fe});function Ud(e,t){if(!e)throw new Error(t)}var m={};Object.keys(Of).forEach(function(e){m[e]=Of[e]}),m.Z_MIN_WINDOWBITS=8,m.Z_MAX_WINDOWBITS=15,m.Z_DEFAULT_WINDOWBITS=15,m.Z_MIN_CHUNK=64,m.Z_MAX_CHUNK=1/0,m.Z_DEFAULT_CHUNK=16384,m.Z_MIN_MEMLEVEL=1,m.Z_MAX_MEMLEVEL=9,m.Z_DEFAULT_MEMLEVEL=8,m.Z_MIN_LEVEL=-1,m.Z_MAX_LEVEL=9,m.Z_DEFAULT_LEVEL=m.Z_DEFAULT_COMPRESSION;var Vt={Z_OK:m.Z_OK,Z_STREAM_END:m.Z_STREAM_END,Z_NEED_DICT:m.Z_NEED_DICT,Z_ERRNO:m.Z_ERRNO,Z_STREAM_ERROR:m.Z_STREAM_ERROR,Z_DATA_ERROR:m.Z_DATA_ERROR,Z_MEM_ERROR:m.Z_MEM_ERROR,Z_BUF_ERROR:m.Z_BUF_ERROR,Z_VERSION_ERROR:m.Z_VERSION_ERROR};Object.keys(Vt).forEach(function(e){Vt[Vt[e]]=e});function $d(e){return new tt(e)}function zd(e){return new rt(e)}function Zd(e){return new at(e)}function Hd(e){return new ot(e)}function qd(e){return new nt(e)}function Kd(e){return new it(e)}function Wd(e){return new st(e)}function Vd(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new tt(t),e,r)}function Gd(e,t){return et(new tt(t),e)}function Yd(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new nt(t),e,r)}function Jd(e,t){return et(new nt(t),e)}function Xd(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new at(t),e,r)}function Qd(e,t){return et(new at(t),e)}function ep(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new st(t),e,r)}function tp(e,t){return et(new st(t),e)}function rp(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new rt(t),e,r)}function np(e,t){return et(new rt(t),e)}function ip(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new it(t),e,r)}function ap(e,t){return et(new it(t),e)}function op(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new ot(t),e,r)}function sp(e,t){return et(new ot(t),e)}function Qe(e,t,r){var n=[],i=0;e.on("error",o),e.on("end",s),e.end(t),a();function a(){for(var c;(c=e.read())!==null;)n.push(c),i+=c.length;e.once("readable",a)}function o(c){e.removeListener("end",s),e.removeListener("readable",a),r(c)}function s(){var c=y.concat(n,i);n=[],r(null,c),e.close()}}function et(e,t){if(typeof t=="string"&&(t=new y(t)),!y.isBuffer(t))throw new TypeError("Not a string or buffer");var r=m.Z_FINISH;return e._processChunk(t,r)}function tt(e){if(!(this instanceof tt))return new tt(e);j.call(this,e,m.DEFLATE)}function rt(e){if(!(this instanceof rt))return new rt(e);j.call(this,e,m.INFLATE)}function nt(e){if(!(this instanceof nt))return new nt(e);j.call(this,e,m.GZIP)}function it(e){if(!(this instanceof it))return new it(e);j.call(this,e,m.GUNZIP)}function at(e){if(!(this instanceof at))return new at(e);j.call(this,e,m.DEFLATERAW)}function ot(e){if(!(this instanceof ot))return new ot(e);j.call(this,e,m.INFLATERAW)}function st(e){if(!(this instanceof st))return new st(e);j.call(this,e,m.UNZIP)}function j(e,t){if(this._opts=e=e||{},this._chunkSize=e.chunkSize||m.Z_DEFAULT_CHUNK,re.call(this,e),e.flush&&e.flush!==m.Z_NO_FLUSH&&e.flush!==m.Z_PARTIAL_FLUSH&&e.flush!==m.Z_SYNC_FLUSH&&e.flush!==m.Z_FULL_FLUSH&&e.flush!==m.Z_FINISH&&e.flush!==m.Z_BLOCK)throw new Error("Invalid flush flag: "+e.flush);if(this._flushFlag=e.flush||m.Z_NO_FLUSH,e.chunkSize&&(e.chunkSize<m.Z_MIN_CHUNK||e.chunkSize>m.Z_MAX_CHUNK))throw new Error("Invalid chunk size: "+e.chunkSize);if(e.windowBits&&(e.windowBits<m.Z_MIN_WINDOWBITS||e.windowBits>m.Z_MAX_WINDOWBITS))throw new Error("Invalid windowBits: "+e.windowBits);if(e.level&&(e.level<m.Z_MIN_LEVEL||e.level>m.Z_MAX_LEVEL))throw new Error("Invalid compression level: "+e.level);if(e.memLevel&&(e.memLevel<m.Z_MIN_MEMLEVEL||e.memLevel>m.Z_MAX_MEMLEVEL))throw new Error("Invalid memLevel: "+e.memLevel);if(e.strategy&&e.strategy!=m.Z_FILTERED&&e.strategy!=m.Z_HUFFMAN_ONLY&&e.strategy!=m.Z_RLE&&e.strategy!=m.Z_FIXED&&e.strategy!=m.Z_DEFAULT_STRATEGY)throw new Error("Invalid strategy: "+e.strategy);if(e.dictionary&&!y.isBuffer(e.dictionary))throw new Error("Invalid dictionary: it should be a Buffer instance");this._binding=new m.Zlib(t);var r=this;this._hadError=!1,this._binding.onerror=function(a,o){r._binding=null,r._hadError=!0;var s=new Error(a);s.errno=o,s.code=Vt[o],r.emit("error",s)};var n=m.Z_DEFAULT_COMPRESSION;typeof e.level=="number"&&(n=e.level);var i=m.Z_DEFAULT_STRATEGY;typeof e.strategy=="number"&&(i=e.strategy),this._binding.init(e.windowBits||m.Z_DEFAULT_WINDOWBITS,n,e.memLevel||m.Z_DEFAULT_MEMLEVEL,i,e.dictionary),this._buffer=new y(this._chunkSize),this._offset=0,this._closed=!1,this._level=n,this._strategy=i,this.once("end",this.close)}W(j,re),j.prototype.params=function(e,t,r){if(e<m.Z_MIN_LEVEL||e>m.Z_MAX_LEVEL)throw new RangeError("Invalid compression level: "+e);if(t!=m.Z_FILTERED&&t!=m.Z_HUFFMAN_ONLY&&t!=m.Z_RLE&&t!=m.Z_FIXED&&t!=m.Z_DEFAULT_STRATEGY)throw new TypeError("Invalid strategy: "+t);if(this._level!==e||this._strategy!==t){var n=this;this.flush(m.Z_SYNC_FLUSH,function(){n._binding.params(e,t),n._hadError||(n._level=e,n._strategy=t,r&&r())})}else xe.nextTick(r)},j.prototype.reset=function(){return this._binding.reset()},j.prototype._flush=function(e){this._transform(new y(0),"",e)},j.prototype.flush=function(e,t){var r=this._writableState;if((typeof e=="function"||e===void 0&&!t)&&(t=e,e=m.Z_FULL_FLUSH),r.ended)t&&xe.nextTick(t);else if(r.ending)t&&this.once("end",t);else if(r.needDrain){var n=this;this.once("drain",function(){n.flush(t)})}else this._flushFlag=e,this.write(new y(0),"",t)},j.prototype.close=function(e){if(e&&xe.nextTick(e),!this._closed){this._closed=!0,this._binding.close();var t=this;xe.nextTick(function(){t.emit("close")})}},j.prototype._transform=function(e,t,r){var n,i=this._writableState,a=i.ending||i.ended,o=a&&(!e||i.length===e.length);if(!e===null&&!y.isBuffer(e))return r(new Error("invalid input"));o?n=m.Z_FINISH:(n=this._flushFlag,e.length>=i.length&&(this._flushFlag=this._opts.flush||m.Z_NO_FLUSH)),this._processChunk(e,n,r)},j.prototype._processChunk=function(e,t,r){var n=e&&e.length,i=this._chunkSize-this._offset,a=0,o=this,s=typeof r=="function";if(!s){var c=[],f=0,l;this.on("error",function(v){l=v});do var d=this._binding.writeSync(t,e,a,n,this._buffer,this._offset,i);while(!this._hadError&&p(d[0],d[1]));if(this._hadError)throw l;var h=y.concat(c,f);return this.close(),h}var u=this._binding.write(t,e,a,n,this._buffer,this._offset,i);u.buffer=e,u.callback=p;function p(v,_){if(!o._hadError){var w=i-_;if(Ud(w>=0,"have should not go down"),w>0){var E=o._buffer.slice(o._offset,o._offset+w);o._offset+=w,s?o.push(E):(c.push(E),f+=E.length)}if((_===0||o._offset>=o._chunkSize)&&(i=o._chunkSize,o._offset=0,o._buffer=new y(o._chunkSize)),_===0){if(a+=n-v,n=v,!s)return!0;var S=o._binding.write(t,e,a,n,o._buffer,o._offset,o._chunkSize);S.callback=p,S.buffer=e;return}if(!s)return!1;r()}}},W(tt,j),W(rt,j),W(nt,j),W(it,j),W(at,j),W(ot,j),W(st,j);var Tf={codes:Vt,createDeflate:$d,createInflate:zd,createDeflateRaw:Zd,createInflateRaw:Hd,createGzip:qd,createGunzip:Kd,createUnzip:Wd,deflate:Vd,deflateSync:Gd,gzip:Yd,gzipSync:Jd,deflateRaw:Xd,deflateRawSync:Qd,unzip:ep,unzipSync:tp,inflate:rp,inflateSync:np,gunzip:ip,gunzipSync:ap,inflateRaw:op,inflateRawSync:sp,Deflate:tt,Inflate:rt,Gzip:nt,Gunzip:it,DeflateRaw:at,InflateRaw:ot,Unzip:st,Zlib:j};class If extends ui{constructor({client:t,keyPrefix:r="cache",ttl:n=0,prefix:i=void 0}){super({client:t,keyPrefix:r,ttl:n,prefix:i}),this.client=t,this.keyPrefix=r,this.config.ttl=n,this.config.client=t,this.config.prefix=i!==void 0?i:r+(r.endsWith("/")?"":"/")}async _set(t,r){let n=JSON.stringify(r);const i=n.length;return n=Tf.gzipSync(n).toString("base64"),this.client.putObject({key:we(this.keyPrefix,t),body:n,contentEncoding:"gzip",contentType:"application/gzip",metadata:{compressor:"zlib",compressed:"true","client-id":this.client.id,"length-serialized":String(i),"length-compressed":String(n.length),"compression-gain":(n.length/i).toFixed(2)}})}async _get(t){try{const{Body:r}=await this.client.getObject(we(this.keyPrefix,t));let n=await Pt(r);return n=Buffer.from(n,"base64"),n=Tf.unzipSync(n).toString(),JSON.parse(n)}catch(r){if(r.name==="NoSuchKey"||r.name==="NotFound")return null;throw r}}async _del(t){return await this.client.deleteObject(we(this.keyPrefix,t)),!0}async _clear(){const t=await this.client.getAllKeys({prefix:this.keyPrefix});for(const r of t)await this.client.deleteObject(r)}async size(){return(await this.keys()).length}async keys(){const t=await this.client.getAllKeys({prefix:this.keyPrefix}),r=this.keyPrefix.endsWith("/")?this.keyPrefix:this.keyPrefix+"/";return t.map(n=>n.startsWith(r)?n.slice(r.length):n)}}class Pf extends R{async setup(t){}async start(){}async stop(){}beforeSetup(){this.emit("plugin.beforeSetup",new Date)}afterSetup(){this.emit("plugin.afterSetup",new Date)}beforeStart(){this.emit("plugin.beforeStart",new Date)}afterStart(){this.emit("plugin.afterStart",new Date)}beforeStop(){this.emit("plugin.beforeStop",new Date)}afterStop(){this.emit("plugin.afterStop",new Date)}}const fp={setup(e){},start(){},stop(){}},cp={async setup(e){this.client=e.client,this.map={PutObjectCommand:"put",GetObjectCommand:"get",HeadObjectCommand:"get",DeleteObjectCommand:"delete",DeleteObjectsCommand:"delete",ListObjectsV2Command:"list"},this.costs={total:0,prices:{put:.005/1e3,copy:.005/1e3,list:.005/1e3,post:.005/1e3,get:4e-4/1e3,select:4e-4/1e3,delete:4e-4/1e3},requests:{total:0,put:0,post:0,copy:0,list:0,get:0,select:0,delete:0},events:{total:0,PutObjectCommand:0,GetObjectCommand:0,HeadObjectCommand:0,DeleteObjectCommand:0,DeleteObjectsCommand:0,ListObjectsV2Command:0}},this.client.costs=JSON.parse(JSON.stringify(this.costs))},async start(){this.client.on("command.response",e=>this.addRequest(e,this.map[e]))},addRequest(e,t){this.costs.events[e]++,this.costs.events.total++,this.costs.requests.total++,this.costs.requests[t]++,this.costs.total+=this.costs.prices[t],this.client.costs.events[e]++,this.client.costs.events.total++,this.client.costs.requests.total++,this.client.costs.requests[t]++,this.client.costs.total+=this.client.costs.prices[t]}};class lp extends Pf{constructor(t={}){super(),this.driver=t.driver}async setup(t){this.database=t,this.driver||(this.driver=new If({keyPrefix:"cache",client:t.client})),this.installDatabaseProxy();for(const r of Object.values(t.resources))this.installResourcesProxies(r)}async start(){}async stop(){}installDatabaseProxy(){const t=this.installResourcesProxies.bind(this);this.database._createResource=this.database.createResource,this.database.createResource=async function(...r){const n=await this._createResource(...r);return t(n),n}}installResourcesProxies(t){t.cache=this.driver;let r=`resource=${t.name}`;this.driver.keyPrefix&&(this.driver.keyPrefix=we(this.driver.keyPrefix,r)),t.cacheKeyFor=async function({params:n={},action:i="list"}){let a=Object.keys(n).sort().map(o=>`${o}:${n[o]}`).join("|")||"empty";return a=await na(a),a=we(r,`action=${i}`,`${a}.json.gz`),a},t._count=t.count,t._listIds=t.listIds,t._getMany=t.getMany,t._getAll=t.getAll,t._page=t.page,t.count=async function(){const n=await this.cacheKeyFor({action:"count"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._count();return await this.cache.set(n,i),i},t.listIds=async function(){const n=await this.cacheKeyFor({action:"listIds"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._listIds();return await this.cache.set(n,i),i},t.getMany=async function(n){const i=await this.cacheKeyFor({action:"getMany",params:{ids:n}});try{const o=await this.cache.get(i);if(o)return o}catch(o){if(o.name!=="NoSuchKey")throw o}const a=await t._getMany(n);return await this.cache.set(i,a),a},t.getAll=async function(){const n=await this.cacheKeyFor({action:"getAll"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._getAll();return await this.cache.set(n,i),i},t.page=async function({offset:n,size:i}){const a=await this.cacheKeyFor({action:"page",params:{offset:n,size:i}});try{const s=await this.cache.get(a);if(s)return s}catch(s){if(s.name!=="NoSuchKey")throw s}const o=await t._page({offset:n,size:i});return await this.cache.set(a,o),o},t._insert=t.insert,t._update=t.update,t._delete=t.delete,t._deleteMany=t.deleteMany,t.insert=async function(...n){const i=await t._insert(...n);return await this.cache.clear(r),i},t.update=async function(...n){const i=await t._update(...n);return await this.cache.clear(r),i},t.delete=async function(...n){const i=await t._delete(...n);return await this.cache.clear(r),i},t.deleteMany=async function(...n){const i=await t._deleteMany(...n);return await this.cache.clear(r),i}}}return I.BaseError=ut,I.Cache=ui,I.CachePlugin=lp,I.Client=ra,I.ConnectionString=ta,I.CostsPlugin=cp,I.Database=cs,I.ErrorMap=Xi,I.InvalidResourceItem=Xt,I.MemoryCache=rh,I.MissingMetadata=Yi,I.NoSuchBucket=Vi,I.NoSuchKey=$r,I.NotFound=Gi,I.Plugin=Pf,I.PluginObject=fp,I.ResourceIdsPageReader=es,I.ResourceIdsReader=Qo,I.ResourceReader=ts,I.ResourceWriter=rs,I.S3Cache=If,I.S3_DEFAULT_ENDPOINT=ea,I.S3_DEFAULT_REGION=Qi,I.S3db=th,I.UnknownError=Ji,I.Validator=fo,I.ValidatorManager=co,I.decrypt=ia,I.encrypt=zr,I.sha256=na,I.streamToString=Pt,I}({},nanoid,lodashEs,promisePool,clientS3,crypto,flat,FastestValidator,web);
29
+ `)+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function Wl(e){return Array.isArray(e)}function Mo(e){return typeof e=="boolean"}function Vn(e){return e===null}function Vl(e){return typeof e=="number"}function Gn(e){return typeof e=="string"}function Fe(e){return e===void 0}function Yn(e){return Ot(e)&&Qn(e)==="[object RegExp]"}function Ot(e){return typeof e=="object"&&e!==null}function jo(e){return Ot(e)&&Qn(e)==="[object Date]"}function Jn(e){return Ot(e)&&(Qn(e)==="[object Error]"||e instanceof Error)}function Xn(e){return typeof e=="function"}function Qn(e){return Object.prototype.toString.call(e)}function Gl(e,t){if(!t||!Ot(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}function Lo(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ke(){this.head=null,this.tail=null,this.length=0}Ke.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},Ke.prototype.unshift=function(e){var t={data:e,next:this.head};this.length===0&&(this.tail=t),this.head=t,++this.length},Ke.prototype.shift=function(){if(this.length!==0){var e=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},Ke.prototype.clear=function(){this.head=this.tail=null,this.length=0},Ke.prototype.join=function(e){if(this.length===0)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r},Ke.prototype.concat=function(e){if(this.length===0)return y.alloc(0);if(this.length===1)return this.head.data;for(var t=y.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var Yl=y.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function Jl(e){if(e&&!Yl(e))throw new Error("Unknown encoding: "+e)}function Tt(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),Jl(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=Ql;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=eu;break;default:this.write=Xl;return}this.charBuffer=new y(6),this.charReceived=0,this.charLength=0}Tt.prototype.write=function(e){for(var t="";this.charLength;){var r=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived<this.charLength)return"";e=e.slice(r,e.length),t=this.charBuffer.slice(0,this.charLength).toString(this.encoding);var i=t.charCodeAt(t.length-1);if(i>=55296&&i<=56319){this.charLength+=this.surrogateSize,t="";continue}if(this.charReceived=this.charLength=0,e.length===0)return t;break}this.detectIncompleteChar(e);var n=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,n),n-=this.charReceived),t+=e.toString(this.encoding,0,n);var n=t.length-1,i=t.charCodeAt(n);if(i>=55296&&i<=56319){var a=this.surrogateSize;return this.charLength+=a,this.charReceived+=a,this.charBuffer.copy(this.charBuffer,a,0,a),e.copy(this.charBuffer,0,0,a),t.substring(0,n)}return t},Tt.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var r=e[e.length-t];if(t==1&&r>>5==6){this.charLength=2;break}if(t<=2&&r>>4==14){this.charLength=3;break}if(t<=3&&r>>3==30){this.charLength=4;break}}this.charReceived=t},Tt.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var r=this.charReceived,n=this.charBuffer,i=this.encoding;t+=n.slice(0,r).toString(i)}return t};function Xl(e){return e.toString(this.encoding)}function Ql(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function eu(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}N.ReadableState=No;var D=Ul("stream");W(N,R);function tu(e,t,r){if(typeof e.prependListener=="function")return e.prependListener(t,r);!e._events||!e._events[t]?e.on(t,r):Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]}function ru(e,t){return e.listeners(t).length}function No(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof ie&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16*1024;this.highWaterMark=r||r===0?r:n,this.highWaterMark=~~this.highWaterMark,this.buffer=new Ke,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(this.decoder=new Tt(e.encoding),this.encoding=e.encoding)}function N(e){if(!(this instanceof N))return new N(e);this._readableState=new No(e,this),this.readable=!0,e&&typeof e.read=="function"&&(this._read=e.read),R.call(this)}N.prototype.push=function(e,t){var r=this._readableState;return!r.objectMode&&typeof e=="string"&&(t=t||r.defaultEncoding,t!==r.encoding&&(e=y.from(e,t),t="")),Bo(this,r,e,t,!1)},N.prototype.unshift=function(e){var t=this._readableState;return Bo(this,t,e,"",!0)},N.prototype.isPaused=function(){return this._readableState.flowing===!1};function Bo(e,t,r,n,i){var a=au(t,r);if(a)e.emit("error",a);else if(r===null)t.reading=!1,ou(e,t);else if(t.objectMode||r&&r.length>0)if(t.ended&&!i){var o=new Error("stream.push() after EOF");e.emit("error",o)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}else{var c;t.decoder&&!i&&!n&&(r=t.decoder.write(r),c=!t.objectMode&&r.length===0),i||(t.reading=!1),c||(t.flowing&&t.length===0&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&dr(e))),su(e,t)}else i||(t.reading=!1);return nu(t)}function nu(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||e.length===0)}N.prototype.setEncoding=function(e){return this._readableState.decoder=new Tt(e),this._readableState.encoding=e,this};var Uo=8388608;function iu(e){return e>=Uo?e=Uo:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function $o(e,t){return e<=0||t.length===0&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=iu(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}N.prototype.read=function(e){D("read",e),e=parseInt(e,10);var t=this._readableState,r=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return D("read: emitReadable",t.length,t.ended),t.length===0&&t.ended?ti(this):dr(this),null;if(e=$o(e,t),e===0&&t.ended)return t.length===0&&ti(this),null;var n=t.needReadable;D("need readable",n),(t.length===0||t.length-e<t.highWaterMark)&&(n=!0,D("length less than watermark",n)),t.ended||t.reading?(n=!1,D("reading or ended",n)):n&&(D("do read"),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=$o(r,t)));var i;return e>0?i=Zo(e,t):i=null,i===null?(t.needReadable=!0,e=0):t.length-=e,t.length===0&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&ti(this)),i!==null&&this.emit("data",i),i};function au(e,t){var r=null;return!y.isBuffer(t)&&typeof t!="string"&&t!==null&&t!==void 0&&!e.objectMode&&(r=new TypeError("Invalid non-string/buffer chunk")),r}function ou(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,dr(e)}}function dr(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(D("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?te(zo,e):zo(e))}function zo(e){D("emit readable"),e.emit("readable"),ei(e)}function su(e,t){t.readingMore||(t.readingMore=!0,te(fu,e,t))}function fu(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(D("maybeReadMore read 0"),e.read(0),r!==t.length);)r=t.length;t.readingMore=!1}N.prototype._read=function(e){this.emit("error",new Error("not implemented"))},N.prototype.pipe=function(e,t){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=e;break;case 1:n.pipes=[n.pipes,e];break;default:n.pipes.push(e);break}n.pipesCount+=1,D("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||t.end!==!1,a=i?s:l;n.endEmitted?te(a):r.once("end",a),e.on("unpipe",o);function o(w){D("onunpipe"),w===r&&l()}function s(){D("onend"),e.end()}var c=cu(r);e.on("drain",c);var f=!1;function l(){D("cleanup"),e.removeListener("close",p),e.removeListener("finish",v),e.removeListener("drain",c),e.removeListener("error",u),e.removeListener("unpipe",o),r.removeListener("end",s),r.removeListener("end",l),r.removeListener("data",h),f=!0,n.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&c()}var d=!1;r.on("data",h);function h(w){D("ondata"),d=!1;var E=e.write(w);E===!1&&!d&&((n.pipesCount===1&&n.pipes===e||n.pipesCount>1&&Ho(n.pipes,e)!==-1)&&!f&&(D("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,d=!0),r.pause())}function u(w){D("onerror",w),_(),e.removeListener("error",u),ru(e,"error")===0&&e.emit("error",w)}tu(e,"error",u);function p(){e.removeListener("finish",v),_()}e.once("close",p);function v(){D("onfinish"),e.removeListener("close",p),_()}e.once("finish",v);function _(){D("unpipe"),r.unpipe(e)}return e.emit("pipe",r),n.flowing||(D("pipe resume"),r.resume()),e};function cu(e){return function(){var t=e._readableState;D("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&e.listeners("data").length&&(t.flowing=!0,ei(e))}}N.prototype.unpipe=function(e){var t=this._readableState;if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i<n;i++)r[i].emit("unpipe",this);return this}var a=Ho(t.pipes,e);return a===-1?this:(t.pipes.splice(a,1),t.pipesCount-=1,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit("unpipe",this),this)},N.prototype.on=function(e,t){var r=R.prototype.on.call(this,e,t);if(e==="data")this._readableState.flowing!==!1&&this.resume();else if(e==="readable"){var n=this._readableState;!n.endEmitted&&!n.readableListening&&(n.readableListening=n.needReadable=!0,n.emittedReadable=!1,n.reading?n.length&&dr(this):te(lu,this))}return r},N.prototype.addListener=N.prototype.on;function lu(e){D("readable nexttick read 0"),e.read(0)}N.prototype.resume=function(){var e=this._readableState;return e.flowing||(D("resume"),e.flowing=!0,uu(this,e)),this};function uu(e,t){t.resumeScheduled||(t.resumeScheduled=!0,te(hu,e,t))}function hu(e,t){t.reading||(D("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),ei(e),t.flowing&&!t.reading&&e.read(0)}N.prototype.pause=function(){return D("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(D("pause"),this._readableState.flowing=!1,this.emit("pause")),this};function ei(e){var t=e._readableState;for(D("flow",t.flowing);t.flowing&&e.read()!==null;);}N.prototype.wrap=function(e){var t=this._readableState,r=!1,n=this;e.on("end",function(){if(D("wrapped end"),t.decoder&&!t.ended){var o=t.decoder.end();o&&o.length&&n.push(o)}n.push(null)}),e.on("data",function(o){if(D("wrapped data"),t.decoder&&(o=t.decoder.write(o)),!(t.objectMode&&o==null)&&!(!t.objectMode&&(!o||!o.length))){var s=n.push(o);s||(r=!0,e.pause())}});for(var i in e)this[i]===void 0&&typeof e[i]=="function"&&(this[i]=function(o){return function(){return e[o].apply(e,arguments)}}(i));var a=["error","close","destroy","pause","resume"];return gu(a,function(o){e.on(o,n.emit.bind(n,o))}),n._read=function(o){D("wrapped _read",o),r&&(r=!1,e.resume())},n},N._fromList=Zo;function Zo(e,t){if(t.length===0)return null;var r;return t.objectMode?r=t.buffer.shift():!e||e>=t.length?(t.decoder?r=t.buffer.join(""):t.buffer.length===1?r=t.buffer.head.data:r=t.buffer.concat(t.length),t.buffer.clear()):r=du(e,t.buffer,t.decoder),r}function du(e,t,r){var n;return e<t.head.data.length?(n=t.head.data.slice(0,e),t.head.data=t.head.data.slice(e)):e===t.head.data.length?n=t.shift():n=r?pu(e,t):yu(e,t),n}function pu(e,t){var r=t.head,n=1,i=r.data;for(e-=i.length;r=r.next;){var a=r.data,o=e>a.length?a.length:e;if(o===a.length?i+=a:i+=a.slice(0,e),e-=o,e===0){o===a.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=a.slice(o));break}++n}return t.length-=n,i}function yu(e,t){var r=y.allocUnsafe(e),n=t.head,i=1;for(n.data.copy(r),e-=n.data.length;n=n.next;){var a=n.data,o=e>a.length?a.length:e;if(a.copy(r,r.length-e,0,o),e-=o,e===0){o===a.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=a.slice(o));break}++i}return t.length-=i,r}function ti(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,te(vu,t,e))}function vu(e,t){!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function gu(e,t){for(var r=0,n=e.length;r<n;r++)t(e[r],r)}function Ho(e,t){for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}H.WritableState=ri,W(H,R);function _u(){}function wu(e,t,r){this.chunk=e,this.encoding=t,this.callback=r,this.next=null}function ri(e,t){Object.defineProperty(this,"buffer",{get:Fo(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")}),e=e||{},this.objectMode=!!e.objectMode,t instanceof ie&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16*1024;this.highWaterMark=r||r===0?r:n,this.highWaterMark=~~this.highWaterMark,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1;var i=e.decodeStrings===!1;this.decodeStrings=!i,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(a){ku(t,a)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new Yo(this)}ri.prototype.getBuffer=function(){for(var t=this.bufferedRequest,r=[];t;)r.push(t),t=t.next;return r};function H(e){if(!(this instanceof H)&&!(this instanceof ie))return new H(e);this._writableState=new ri(e,this),this.writable=!0,e&&(typeof e.write=="function"&&(this._write=e.write),typeof e.writev=="function"&&(this._writev=e.writev)),R.call(this)}H.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))};function bu(e,t){var r=new Error("write after end");e.emit("error",r),te(t,r)}function mu(e,t,r,n){var i=!0,a=!1;return r===null?a=new TypeError("May not write null values to stream"):!y.isBuffer(r)&&typeof r!="string"&&r!==void 0&&!t.objectMode&&(a=new TypeError("Invalid non-string/buffer chunk")),a&&(e.emit("error",a),te(n,a),i=!1),i}H.prototype.write=function(e,t,r){var n=this._writableState,i=!1;return typeof t=="function"&&(r=t,t=null),y.isBuffer(e)?t="buffer":t||(t=n.defaultEncoding),typeof r!="function"&&(r=_u),n.ended?bu(this,r):mu(this,n,e,r)&&(n.pendingcb++,i=Eu(this,n,e,t,r)),i},H.prototype.cork=function(){var e=this._writableState;e.corked++},H.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.finished&&!e.bufferProcessing&&e.bufferedRequest&&Ko(this,e))},H.prototype.setDefaultEncoding=function(t){if(typeof t=="string"&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this};function xu(e,t,r){return!e.objectMode&&e.decodeStrings!==!1&&typeof t=="string"&&(t=y.from(t,r)),t}function Eu(e,t,r,n,i){r=xu(t,r,n),y.isBuffer(r)&&(n="buffer");var a=t.objectMode?1:r.length;t.length+=a;var o=t.length<t.highWaterMark;if(o||(t.needDrain=!0),t.writing||t.corked){var s=t.lastBufferedRequest;t.lastBufferedRequest=new wu(r,n,i),s?s.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else ni(e,t,!1,a,r,n,i);return o}function ni(e,t,r,n,i,a,o){t.writelen=n,t.writecb=o,t.writing=!0,t.sync=!0,r?e._writev(i,t.onwrite):e._write(i,a,t.onwrite),t.sync=!1}function Su(e,t,r,n,i){--t.pendingcb,r?te(i,n):i(n),e._writableState.errorEmitted=!0,e.emit("error",n)}function Au(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function ku(e,t){var r=e._writableState,n=r.sync,i=r.writecb;if(Au(r),t)Su(e,r,n,t,i);else{var a=Wo(r);!a&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest&&Ko(e,r),n?te(qo,e,r,a,i):qo(e,r,a,i)}}function qo(e,t,r,n){r||Ru(e,t),t.pendingcb--,n(),Go(e,t)}function Ru(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function Ko(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var n=t.bufferedRequestCount,i=new Array(n),a=t.corkedRequestsFree;a.entry=r;for(var o=0;r;)i[o]=r,r=r.next,o+=1;ni(e,t,!0,t.length,i,"",a.finish),t.pendingcb++,t.lastBufferedRequest=null,a.next?(t.corkedRequestsFree=a.next,a.next=null):t.corkedRequestsFree=new Yo(t)}else{for(;r;){var s=r.chunk,c=r.encoding,f=r.callback,l=t.objectMode?1:s.length;if(ni(e,t,!1,l,s,c,f),r=r.next,t.writing)break}r===null&&(t.lastBufferedRequest=null)}t.bufferedRequestCount=0,t.bufferedRequest=r,t.bufferProcessing=!1}H.prototype._write=function(e,t,r){r(new Error("not implemented"))},H.prototype._writev=null,H.prototype.end=function(e,t,r){var n=this._writableState;typeof e=="function"?(r=e,e=null,t=null):typeof t=="function"&&(r=t,t=null),e!=null&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),!n.ending&&!n.finished&&Ou(this,n,r)};function Wo(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function Vo(e,t){t.prefinished||(t.prefinished=!0,e.emit("prefinish"))}function Go(e,t){var r=Wo(t);return r&&(t.pendingcb===0?(Vo(e,t),t.finished=!0,e.emit("finish")):Vo(e,t)),r}function Ou(e,t,r){t.ending=!0,Go(e,t),r&&(t.finished?te(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function Yo(e){var t=this;this.next=null,this.entry=null,this.finish=function(r){var n=t.entry;for(t.entry=null;n;){var i=n.callback;e.pendingcb--,i(r),n=n.next}e.corkedRequestsFree?e.corkedRequestsFree.next=t:e.corkedRequestsFree=t}}W(ie,N);for(var Jo=Object.keys(H.prototype),ii=0;ii<Jo.length;ii++){var ai=Jo[ii];ie.prototype[ai]||(ie.prototype[ai]=H.prototype[ai])}function ie(e){if(!(this instanceof ie))return new ie(e);N.call(this,e),H.call(this,e),e&&e.readable===!1&&(this.readable=!1),e&&e.writable===!1&&(this.writable=!1),this.allowHalfOpen=!0,e&&e.allowHalfOpen===!1&&(this.allowHalfOpen=!1),this.once("end",Tu)}function Tu(){this.allowHalfOpen||this._writableState.ended||te(Iu,this)}function Iu(e){e.end()}W(re,ie);function Pu(e){this.afterTransform=function(t,r){return Cu(e,t,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null,this.writeencoding=null}function Cu(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));n.writechunk=null,n.writecb=null,r!=null&&e.push(r),i(t);var a=e._readableState;a.reading=!1,(a.needReadable||a.length<a.highWaterMark)&&e._read(a.highWaterMark)}function re(e){if(!(this instanceof re))return new re(e);ie.call(this,e),this._transformState=new Pu(this);var t=this;this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.once("prefinish",function(){typeof this._flush=="function"?this._flush(function(r){Xo(t,r)}):Xo(t)})}re.prototype.push=function(e,t){return this._transformState.needTransform=!1,ie.prototype.push.call(this,e,t)},re.prototype._transform=function(e,t,r){throw new Error("Not implemented")},re.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},re.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};function Xo(e,t){if(t)return e.emit("error",t);var r=e._writableState,n=e._transformState;if(r.length)throw new Error("Calling transform done when ws.length != 0");if(n.transforming)throw new Error("Calling transform done when still transforming");return e.push(null)}W(It,re);function It(e){if(!(this instanceof It))return new It(e);re.call(this,e)}It.prototype._transform=function(e,t,r){r(null,e)},W(Ee,R),Ee.Readable=N,Ee.Writable=H,Ee.Duplex=ie,Ee.Transform=re,Ee.PassThrough=It,Ee.Stream=Ee;function Ee(){R.call(this)}Ee.prototype.pipe=function(e,t){var r=this;function n(l){e.writable&&e.write(l)===!1&&r.pause&&r.pause()}r.on("data",n);function i(){r.readable&&r.resume&&r.resume()}e.on("drain",i),!e._isStdio&&(!t||t.end!==!1)&&(r.on("end",o),r.on("close",s));var a=!1;function o(){a||(a=!0,e.end())}function s(){a||(a=!0,typeof e.destroy=="function"&&e.destroy())}function c(l){if(f(),R.listenerCount(this,"error")===0)throw l}r.on("error",c),e.on("error",c);function f(){r.removeListener("data",n),e.removeListener("drain",i),r.removeListener("end",o),r.removeListener("close",s),r.removeListener("error",c),e.removeListener("error",c),r.removeListener("end",f),r.removeListener("close",f),e.removeListener("close",f)}return r.on("end",f),r.on("close",f),e.on("close",f),e.emit("pipe",r),e};class Qo extends R{constructor({resource:t}){super(),this.resource=t,this.client=t.client,this.stream=new Ff.ReadableStream({highWaterMark:this.client.parallelism*3,start:this._start.bind(this),pull:this._pull.bind(this),cancel:this._cancel.bind(this)})}build(){return this.stream.getReader()}async _start(t){this.controller=t,this.continuationToken=null,this.closeNextIteration=!1}async _pull(t){if(this.closeNextIteration){t.close();return}const r=await this.client.listObjects({prefix:`resource=${this.resource.name}`,continuationToken:this.continuationToken}),n=r?.Contents.map(i=>i.Key).map(i=>i.replace(this.client.config.keyPrefix,"")).map(i=>i.startsWith("/")?i.replace("/",""):i).map(i=>i.replace(`resource=${this.resource.name}/id=`,""));this.continuationToken=r.NextContinuationToken,this.enqueue(n),r.IsTruncated||(this.closeNextIteration=!0)}enqueue(t){t.forEach(r=>{this.controller.enqueue(r),this.emit("id",r)})}_cancel(t){console.warn("Stream cancelled",t)}}class es extends Qo{enqueue(t){this.controller.enqueue(t),this.emit("page",t)}}class ts extends R{constructor({resource:t,batchSize:r=10,concurrency:n=5}){if(super(),!t)throw new Error("Resource is required for ResourceReader");this.resource=t,this.client=t.client,this.batchSize=r,this.concurrency=n,this.input=new es({resource:this.resource}),this.transform=new re({objectMode:!0,transform:this._transform.bind(this)}),this.input.on("data",i=>{this.transform.write(i)}),this.input.on("end",()=>{this.transform.end()}),this.input.on("error",i=>{this.emit("error",i)}),this.transform.on("data",i=>{this.emit("data",i)}),this.transform.on("end",()=>{this.emit("end")}),this.transform.on("error",i=>{this.emit("error",i)})}build(){return this}async _transform(t,r,n){try{await ce.PromisePool.for(t).withConcurrency(this.concurrency).handleError(async(i,a)=>{this.emit("error",i,a)}).process(async i=>{const a=await this.resource.get(i);return this.push(a),a}),n()}catch(i){n(i)}}resume(){this.input.resume()}}class rs extends R{constructor({resource:t,batchSize:r=10,concurrency:n=5}){super(),this.resource=t,this.client=t.client,this.batchSize=r,this.concurrency=n,this.buffer=[],this.writing=!1,this.writable=new H({objectMode:!0,write:this._write.bind(this)}),this.writable.on("finish",()=>{this.emit("finish")}),this.writable.on("error",i=>{this.emit("error",i)})}build(){return this}write(t){return this.buffer.push(t),this._maybeWrite(),!0}end(){this.ended=!0,this._maybeWrite()}async _maybeWrite(){if(!this.writing&&!(this.buffer.length===0&&!this.ended)){for(this.writing=!0;this.buffer.length>0;){const t=this.buffer.splice(0,this.batchSize);try{await ce.PromisePool.for(t).withConcurrency(this.concurrency).handleError(async(r,n)=>{this.emit("error",r,n)}).process(async r=>{await this.resource.insert(r)})}catch(r){this.emit("error",r)}}this.writing=!1,this.ended&&this.writable.emit("finish")}}async _write(t,r,n){n()}}function Pt(e){return new Promise((t,r)=>{const n=[];e.on("data",i=>n.push(i)),e.on("error",r),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))})}function Ct(e){typeof e!="string"&&(e=String(e));let t=0;for(let r=0;r<e.length;r++){const n=e.codePointAt(r);n<=127?t+=1:n<=2047?t+=2:n<=65535?t+=3:n<=1114111&&(t+=4,n>65535&&r++)}return t}function ns(e){return e==null?"":typeof e=="boolean"?e?"1":"0":typeof e=="number"?String(e):typeof e=="string"?e:Array.isArray(e)?e.length===0?"[]":e.map(t=>String(t)).join("|"):typeof e=="object"?JSON.stringify(e):String(e)}function oi(e){const t={};for(const[r,n]of Object.entries(e)){const i=ns(n),a=Ct(i);t[r]=a}return t}function We(e){const t=oi(e);return Object.values(t).reduce((r,n)=>r+n,0)}const Se=2048;async function Du({resource:e,data:t,mappedData:r}){const n=We(r);return n>Se&&e.emit("exceedsLimit",{operation:"insert",totalSize:n,limit:Se,excess:n-Se,data:t}),{mappedData:r,body:""}}async function Fu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);return i>Se&&e.emit("exceedsLimit",{operation:"update",id:t,totalSize:i,limit:Se,excess:i-Se,data:r}),{mappedData:n,body:""}}async function Mu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);return i>Se&&e.emit("exceedsLimit",{operation:"upsert",id:t,totalSize:i,limit:Se,excess:i-Se,data:r}),{mappedData:n,body:""}}async function ju({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var Lu=Object.freeze({__proto__:null,handleGet:ju,handleInsert:Du,handleUpdate:Fu,handleUpsert:Mu});const yt=2048;async function Nu({resource:e,data:t,mappedData:r}){const n=We(r);if(n>yt)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${n} bytes, limit: ${yt} bytes`);return{mappedData:r,body:""}}async function Bu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);if(i>yt)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${yt} bytes`);return{mappedData:n,body:""}}async function Uu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);if(i>yt)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${yt} bytes`);return{mappedData:n,body:""}}async function $u({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var zu=Object.freeze({__proto__:null,handleGet:$u,handleInsert:Nu,handleUpdate:Bu,handleUpsert:Uu});const is=2048,as="...",os=Ct(as);async function Zu({resource:e,data:t,mappedData:r}){return si({resource:e,data:t,mappedData:r})}async function Hu({resource:e,id:t,data:r,mappedData:n}){return si({resource:e,data:r,mappedData:n})}async function qu({resource:e,id:t,data:r,mappedData:n}){return si({resource:e,data:r,mappedData:n})}async function Ku({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}function si({resource:e,data:t,mappedData:r}){const n=oi(r),i=Object.entries(n).sort(([,s],[,c])=>s-c),a={};let o=0;for(const[s,c]of i){const f=is-o;if(c<=f)a[s]=r[s],o+=c;else if(f>os){const l=f-os,d=ns(r[s]);let h="",u=0;for(let p=0;p<d.length;p++){const v=d[p],_=Ct(v);if(u+_<=l)h+=v,u+=_;else break}a[s]=h+as,o=is;break}else break}return{mappedData:a,body:""}}var Wu=Object.freeze({__proto__:null,handleGet:Ku,handleInsert:Zu,handleUpdate:Hu,handleUpsert:qu});const ss=2048,pr="$overflow",fi="true",Vu=Ct(pr)+Ct(fi);async function Gu({resource:e,data:t,mappedData:r}){return ci({resource:e,data:t,mappedData:r})}async function Yu({resource:e,id:t,data:r,mappedData:n}){return ci({resource:e,data:r,mappedData:n})}async function Ju({resource:e,id:t,data:r,mappedData:n}){return ci({resource:e,data:r,mappedData:n})}async function Xu({resource:e,metadata:t,body:r}){if(t[pr]===fi)try{const n=r?JSON.parse(r):{},i={...t};return delete i[pr],{metadata:{...i,...n},body:""}}catch{return{metadata:t,body:r}}return{metadata:t,body:r}}function ci({resource:e,data:t,mappedData:r}){if(We(r)<=ss)return{mappedData:r,body:""};const i=ss-Vu,a=oi(r),o=Object.entries(a).sort(([,d],[,h])=>d-h),s={},c={};let f=0;for(const[d,h]of o)f+h<=i?(s[d]=r[d],f+=h):c[d]=r[d];s[pr]=fi;const l=Object.keys(c).length>0?JSON.stringify(c):"";return{mappedData:s,body:l}}var Qu=Object.freeze({__proto__:null,handleGet:Xu,handleInsert:Gu,handleUpdate:Yu,handleUpsert:Ju});const fs={"user-management":Lu,"enforce-limits":zu,"data-truncate":Wu,"body-overflow":Qu};function vt(e){const t=fs[e];if(!t)throw new Error(`Unknown behavior: ${e}. Available behaviors: ${Object.keys(fs).join(", ")}`);return t}const eh="user-management";class li extends R{constructor({name:t,client:r,version:n="1",options:i={},attributes:a={},parallelism:o=10,passphrase:s="secret",observers:c=[],behavior:f=eh}){if(super(),this.name=t,this.client=r,this.version=n,this.behavior=f,this.observers=c,this.parallelism=o,this.passphrase=s??"secret",this.options={cache:!1,autoDecrypt:!0,timestamps:!1,partitions:{},paranoid:!0,allNestedObjectsOptional:i.allNestedObjectsOptional??!1,...i},this.hooks={preInsert:[],afterInsert:[],preUpdate:[],afterUpdate:[],preDelete:[],afterDelete:[]},this.attributes=a||{},i.timestamps&&(this.attributes.createdAt="string|optional",this.attributes.updatedAt="string|optional",this.options.partitions.byCreatedDate||(this.options.partitions.byCreatedDate={fields:{createdAt:"date|maxlength:10"}}),this.options.partitions.byUpdatedDate||(this.options.partitions.byUpdatedDate={fields:{updatedAt:"date|maxlength:10"}})),this.schema=new Ie({name:t,attributes:this.attributes,passphrase:s,version:this.version,options:{...this.options,allNestedObjectsOptional:this.options.allNestedObjectsOptional??!1}}),this.validatePartitions(),this.setupPartitionHooks(),i.hooks){for(const[l,d]of Object.entries(i.hooks))if(Array.isArray(d)&&this.hooks[l])for(const h of d)this.hooks[l].push(h.bind(this))}}export(){const t=this.schema.export();return t.behavior=this.behavior,t}updateAttributes(t){const r=this.attributes;return this.attributes=t,this.options.timestamps&&(t.createdAt="string|optional",t.updatedAt="string|optional",this.options.partitions.byCreatedDate||(this.options.partitions.byCreatedDate={fields:{createdAt:"date|maxlength:10"}}),this.options.partitions.byUpdatedDate||(this.options.partitions.byUpdatedDate={fields:{updatedAt:"date|maxlength:10"}})),this.schema=new Ie({name:this.name,attributes:t,passphrase:this.passphrase,version:this.version,options:this.options}),this.validatePartitions(),this.setupPartitionHooks(),{oldAttributes:r,newAttributes:t}}addHook(t,r){this.hooks[t]&&this.hooks[t].push(r.bind(this))}async executeHooks(t,r){if(!this.hooks[t])return r;let n=r;for(const i of this.hooks[t])n=await i(n);return n}setupPartitionHooks(){const t=this.options.partitions;!t||Object.keys(t).length===0||(this.addHook("afterInsert",async r=>(await this.createPartitionReferences(r),r)),this.addHook("afterDelete",async r=>(await this.deletePartitionReferences(r),r)))}async validate(t){const r={original:L.cloneDeep(t),isValid:!1,errors:[]},n=await this.schema.validate(t,{mutateOriginal:!0});return n===!0?r.isValid=!0:r.errors=n,r.data=t,r}validatePartitions(){const t=this.options.partitions;if(!t||Object.keys(t).length===0)return;const r=Object.keys(this.attributes||{});for(const[n,i]of Object.entries(t))if(i.fields){for(const a of Object.keys(i.fields))if(!this.fieldExistsInAttributes(a))throw new Error(`Partition '${n}' uses field '${a}' which does not exist in resource version '${this.version}'. Available fields: ${r.join(", ")}. This version of resource does not have support for this partition.`)}}fieldExistsInAttributes(t){if(!t.includes("."))return Object.keys(this.attributes||{}).includes(t);const r=t.split(".");let n=this.attributes||{};for(const i of r){if(!n||typeof n!="object"||!(i in n))return!1;n=n[i]}return!0}applyPartitionRule(t,r){if(t==null)return t;let n=t;if(typeof r=="string"&&r.includes("maxlength:")){const i=r.match(/maxlength:(\d+)/);if(i){const a=parseInt(i[1]);typeof n=="string"&&n.length>a&&(n=n.substring(0,a))}}if(r.includes("date")){if(n instanceof Date)n=n.toISOString().split("T")[0];else if(typeof n=="string")try{if(n.includes("T")&&n.includes("Z"))n=n.split("T")[0];else{const i=new Date(n);isNaN(i.getTime())||(n=i.toISOString().split("T")[0])}}catch{}}return n}getResourceKey(t){return we(`resource=${this.name}`,`v=${this.version}`,`id=${t}`)}getPartitionKey(t,r,n){const i=this.options.partitions[t];if(!i)throw new Error(`Partition '${t}' not found`);const a=[],o=Object.entries(i.fields).sort(([s],[c])=>s.localeCompare(c));for(const[s,c]of o){const f=this.getNestedFieldValue(n,s),l=this.applyPartitionRule(f,c);if(l==null)return null;a.push(`${s}=${l}`)}return a.length===0?null:we(`resource=${this.name}`,`partition=${t}`,...a,`id=${r}`)}getNestedFieldValue(t,r){if(!r.includes("."))return t[r];const n=r.split(".");let i=t;for(const a of n){if(i==null||typeof i!="object")return;i=i[a]}return i}async insert({id:t,...r}){this.options.timestamps&&(r.createdAt=new Date().toISOString(),r.updatedAt=new Date().toISOString());const n=await this.executeHooks("preInsert",r),{errors:i,isValid:a,data:o}=await this.validate(n);if(!a)throw new Xt({bucket:this.client.config.bucket,resourceName:this.name,attributes:n,validation:i});!t&&t!==0&&(t=Zi());const s=await this.schema.mapper(o),c=vt(this.behavior),{mappedData:f,body:l}=await c.handleInsert({resource:this,data:o,mappedData:s}),d=this.getResourceKey(t);await this.client.putObject({metadata:f,key:d,body:l});const h=L.merge({id:t},o);return await this.executeHooks("afterInsert",h),this.emit("insert",h),h}async get(t){const r=this.getResourceKey(t),n=await this.client.headObject(r),i=this.extractVersionFromKey(r)||this.version;let o=await(await this.getSchemaForVersion(i)).unmapper(n.Metadata);const s=vt(this.behavior);let c="";if(n.ContentLength>0)try{const d=await this.client.getObject(r);c=await Pt(d.Body)}catch{c=""}const{metadata:f}=await s.handleGet({resource:this,metadata:o,body:c});let l=f;return l.id=t,l._contentLength=n.ContentLength,l._lastModified=n.LastModified,l._hasContent=n.ContentLength>0,l._mimeType=n.ContentType||null,n.VersionId&&(l._versionId=n.VersionId),n.Expiration&&(l._expiresAt=n.Expiration),l._definitionHash=this.getDefinitionHash(),this.emit("get",l),l}async exists(t){try{const r=this.getResourceKey(t);return await this.client.headObject(r),!0}catch{return!1}}async update(t,r){const n=await this.get(t);this.options.timestamps&&(r.updatedAt=new Date().toISOString());const i=await this.executeHooks("preUpdate",r),a=L.merge(n,i);delete a.id;const{isValid:o,errors:s,data:c}=await this.validate(a);if(!o)throw new Xt({bucket:this.client.bucket,resourceName:this.name,attributes:i,validation:s});const f=await this.schema.mapper(c),l=vt(this.behavior),{mappedData:d,body:h}=await l.handleUpdate({resource:this,id:t,data:c,mappedData:f}),u=this.getResourceKey(t);let p,v=h;if(h===""&&this.behavior!=="body-overflow")try{const _=await this.client.getObject(u);if(_.ContentLength>0){const w=Buffer.from(await _.Body.transformToByteArray()),E=w.toString();try{JSON.parse(E)}catch{v=w,p=_.ContentType}}}catch{}return await this.client.putObject({key:u,body:v,contentType:p,metadata:d}),c.id=t,await this.executeHooks("afterUpdate",c),await this.updatePartitionReferences(c),this.emit("update",i,c),c}async delete(t){let r;try{r=await this.get(t)}catch{r={id:t}}await this.executeHooks("preDelete",r);const n=this.getResourceKey(t),i=await this.client.deleteObject(n);return await this.executeHooks("afterDelete",r),this.emit("delete",t),i}async upsert({id:t,...r}){return await this.exists(t)?this.update(t,r):this.insert({id:t,...r})}async count({partition:t=null,partitionValues:r={}}={}){let n;if(t&&Object.keys(r).length>0){const a=this.options.partitions[t];if(!a)throw new Error(`Partition '${t}' not found`);const o=[],s=Object.entries(a.fields).sort(([c],[f])=>c.localeCompare(f));for(const[c,f]of s){const l=r[c];if(l!=null){const d=this.applyPartitionRule(l,f);o.push(`${c}=${d}`)}}o.length>0?n=`resource=${this.name}/partition=${t}/${o.join("/")}`:n=`resource=${this.name}/partition=${t}`}else n=`resource=${this.name}/v=${this.version}`;const i=await this.client.count({prefix:n});return this.emit("count",i),i}async insertMany(t){const{results:r}=await ce.PromisePool.for(t).withConcurrency(this.parallelism).handleError(async(n,i)=>{this.emit("error",n,i),this.observers.map(a=>a.emit("error",this.name,n,i))}).process(async n=>await this.insert(n));return this.emit("insertMany",t.length),r}async deleteMany(t){const r=L.chunk(t.map(i=>this.getResourceKey(i)),1e3),{results:n}=await ce.PromisePool.for(r).withConcurrency(this.parallelism).handleError(async(i,a)=>{this.emit("error",i,a),this.observers.map(o=>o.emit("error",this.name,i,a))}).process(async i=>{const a=await this.client.deleteObjects(i);return i.forEach(o=>{const c=o.split("/").find(l=>l.startsWith("id=")),f=c?c.replace("id=",""):null;f&&(this.emit("deleted",f),this.observers.map(l=>l.emit("deleted",this.name,f)))}),a});return this.emit("deleteMany",t.length),n}async deleteAll(){if(this.options.paranoid!==!1)throw new Error(`deleteAll() is a dangerous operation and requires paranoid: false option. Current paranoid setting: ${this.options.paranoid}`);const t=`resource=${this.name}/v=${this.version}`,r=await this.client.deleteAll({prefix:t});return this.emit("deleteAll",{version:this.version,prefix:t,deletedCount:r}),{deletedCount:r,version:this.version}}async deleteAllData(){if(this.options.paranoid!==!1)throw new Error(`deleteAllData() is a dangerous operation and requires paranoid: false option. Current paranoid setting: ${this.options.paranoid}`);const t=`resource=${this.name}`,r=await this.client.deleteAll({prefix:t});return this.emit("deleteAllData",{resource:this.name,prefix:t,deletedCount:r}),{deletedCount:r,resource:this.name}}async listIds({partition:t=null,partitionValues:r={}}={}){let n;if(t&&Object.keys(r).length>0){const o=this.options.partitions[t];if(!o)throw new Error(`Partition '${t}' not found`);const s=[],c=Object.entries(o.fields).sort(([f],[l])=>f.localeCompare(l));for(const[f,l]of c){const d=r[f];if(d!=null){const h=this.applyPartitionRule(d,l);s.push(`${f}=${h}`)}}s.length>0?n=`resource=${this.name}/partition=${t}/${s.join("/")}`:n=`resource=${this.name}/partition=${t}`}else n=`resource=${this.name}/v=${this.version}`;const a=(await this.client.getAllKeys({prefix:n})).map(o=>{const c=o.split("/").find(f=>f.startsWith("id="));return c?c.replace("id=",""):null}).filter(Boolean);return this.emit("listIds",a.length),a}async listByPartition({partition:t=null,partitionValues:r={}}={},n={}){const{limit:i,offset:a=0}=n;if(!t){let v=(await this.listIds({partition:t,partitionValues:r})).slice(a);i&&(v=v.slice(0,i));const{results:_}=await ce.PromisePool.for(v).withConcurrency(this.parallelism).process(async w=>await this.get(w));return this.emit("listByPartition",{partition:t,partitionValues:r,count:_.length}),_}const o=this.options.partitions[t];if(!o)throw new Error(`Partition '${t}' not found`);const s=[],c=Object.entries(o.fields).sort(([p],[v])=>p.localeCompare(v));for(const[p,v]of c){const _=r[p];if(_!=null){const w=this.applyPartitionRule(_,v);s.push(`${p}=${w}`)}}let f;s.length>0?f=`resource=${this.name}/partition=${t}/${s.join("/")}`:f=`resource=${this.name}/partition=${t}`;let h=(await this.client.getAllKeys({prefix:f})).map(p=>{const _=p.split("/").find(w=>w.startsWith("id="));return _?_.replace("id=",""):null}).filter(Boolean).slice(a);i&&(h=h.slice(0,i));const{results:u}=await ce.PromisePool.for(h).withConcurrency(this.parallelism).process(async p=>await this.getFromPartition(p,t,r));return this.emit("listByPartition",{partition:t,partitionValues:r,count:u.length}),u}async getMany(t){const{results:r}=await ce.PromisePool.for(t).withConcurrency(this.client.parallelism).process(async n=>{this.emit("id",n);const i=await this.get(n);return this.emit("data",i),i});return this.emit("getMany",t.length),r}async getAll(){let t=await this.listIds();if(t.length===0)return[];const{results:r}=await ce.PromisePool.for(t).withConcurrency(this.client.parallelism).process(async n=>await this.get(n));return this.emit("getAll",r.length),r}async page(t=0,r=100,{partition:n=null,partitionValues:i={}}={}){const a=await this.listIds({partition:n,partitionValues:i}),o=a.length,s=Math.ceil(o/r),c=a.slice(t*r,(t+1)*r),l={items:await Promise.all(c.map(d=>this.get(d))),totalItems:o,page:t,pageSize:r,totalPages:s};return this.emit("page",l),l}readable(){return new ts({resource:this}).build()}writable(){return new rs({resource:this}).build()}async setContent(t,r,n="application/octet-stream"){if(!Buffer.isBuffer(r))throw new Error("Content must be a Buffer");const i=this.getResourceKey(t);let a={};try{a=(await this.client.headObject(i)).Metadata||{}}catch{}const o=await this.client.putObject({key:i,body:r,contentType:n,metadata:a});return this.emit("setContent",t,r.length,n),o}async content(t){const r=this.getResourceKey(t);try{const n=await this.client.getObject(r),i=Buffer.from(await n.Body.transformToByteArray()),a=n.ContentType||null;return this.emit("content",t,i.length,a),{buffer:i,contentType:a}}catch(n){if(n.name==="NoSuchKey")return{buffer:null,contentType:null};throw n}}async hasContent(t){const r=this.getResourceKey(t);try{return(await this.client.headObject(r)).ContentLength>0}catch{return!1}}async deleteContent(t){const r=this.getResourceKey(t),i=(await this.client.headObject(r)).Metadata||{},a=await this.client.putObject({key:r,body:"",metadata:i});return this.emit("deleteContent",t),a}getDefinitionHash(){const r={...this.schema.export().attributes};this.options.timestamps&&(delete r.createdAt,delete r.updatedAt);const n=so(r);return`sha256:${Bi.createHash("sha256").update(n).digest("hex")}`}extractVersionFromKey(t){const n=t.split("/").find(i=>i.startsWith("v="));return n?n.replace("v=",""):null}async getSchemaForVersion(t){return this.schema}async createPartitionReferences(t){const r=this.options.partitions;if(!(!r||Object.keys(r).length===0))for(const[n,i]of Object.entries(r)){const a=this.getPartitionKey(n,t.id,t);if(a){const o=await this.schema.mapper(t),s=vt(this.behavior),{mappedData:c,body:f}=await s.handleInsert({resource:this,data:t,mappedData:o}),l={...c,_version:this.version};await this.client.putObject({key:a,metadata:l,body:f})}}}async deletePartitionReferences(t){const r=this.options.partitions;if(!r||Object.keys(r).length===0)return;const n=[];for(const[i,a]of Object.entries(r)){const o=this.getPartitionKey(i,t.id,t);o&&n.push(o)}if(n.length>0)try{await this.client.deleteObjects(n)}catch(i){console.warn("Some partition objects could not be deleted:",i.message)}}async query(t={}){const r=await this.getAll();return Object.keys(t).length===0?r:r.filter(n=>Object.entries(t).every(([i,a])=>n[i]===a))}async updatePartitionReferences(t){const r=this.options.partitions;if(!(!r||Object.keys(r).length===0))for(const[n,i]of Object.entries(r)){const a=this.getPartitionKey(n,t.id,t);if(a){const o=await this.schema.mapper(t),s=vt(this.behavior),{mappedData:c,body:f}=await s.handleUpdate({resource:this,id:t.id,data:t,mappedData:o}),l={...c,_version:this.version};try{await this.client.putObject({key:a,metadata:l,body:f})}catch(d){console.warn(`Partition object could not be updated for ${n}:`,d.message)}}}}async getFromPartition(t,r,n={}){const i=this.options.partitions[r];if(!i)throw new Error(`Partition '${r}' not found`);const a=[],o=Object.entries(i.fields).sort(([_],[w])=>_.localeCompare(w));for(const[_,w]of o){const E=n[_];if(E!=null){const S=this.applyPartitionRule(E,w);a.push(`${_}=${S}`)}}if(a.length===0)throw new Error(`No partition values provided for partition '${r}'`);const s=we(`resource=${this.name}`,`partition=${r}`,...a,`id=${t}`),c=await this.client.headObject(s),f=c.Metadata?._version||this.version;let d=await(await this.getSchemaForVersion(f)).unmapper(c.Metadata);const h=vt(this.behavior);let u="";if(c.ContentLength>0)try{const _=await this.client.getObject(s);u=await Pt(_.Body)}catch{u=""}const{metadata:p}=await h.handleGet({resource:this,metadata:d,body:u});let v=p;return v.id=t,v._contentLength=c.ContentLength,v._lastModified=c.LastModified,v._hasContent=c.ContentLength>0,v._mimeType=c.ContentType||null,v._partition=r,v._partitionValues=n,c.VersionId&&(v._versionId=c.VersionId),c.Expiration&&(v._expiresAt=c.Expiration),v._definitionHash=this.getDefinitionHash(),this.emit("getFromPartition",v),v}}class cs extends R{constructor(t){super(),this.version="1",this.s3dbVersion=(()=>{try{return"4.1.3"}catch{return"latest"}})(),this.resources={},this.savedMetadata=null,this.options=t,this.verbose=t.verbose||!1,this.parallelism=parseInt(t.parallelism+"")||10,this.plugins=t.plugins||[],this.cache=t.cache,this.passphrase=t.passphrase||"secret",this.client=t.client||new ra({verbose:this.verbose,parallelism:this.parallelism,connectionString:t.connectionString}),this.bucket=this.client.bucket,this.keyPrefix=this.client.keyPrefix}async connect(){await this.startPlugins();let t=null;if(await this.client.exists("s3db.json")){const n=await this.client.getObject("s3db.json");t=JSON.parse(await Pt(n?.Body))}else t=this.blankMetadataStructure(),await this.uploadMetadataFile();this.savedMetadata=t;const r=this.detectDefinitionChanges(t);for(const[n,i]of Object.entries(t.resources||{})){const a=i.currentVersion||"v0",o=i.versions?.[a];o&&(this.resources[n]=new li({name:n,client:this.client,version:a,options:{...o.options,partitions:i.partitions||o.options?.partitions||{}},attributes:o.attributes,behavior:o.behavior||"user-management",parallelism:this.parallelism,passphrase:this.passphrase,observers:[this]}))}r.length>0&&this.emit("resourceDefinitionsChanged",{changes:r,metadata:this.savedMetadata}),this.emit("connected",new Date)}detectDefinitionChanges(t){const r=[];for(const[n,i]of Object.entries(this.resources)){const a=this.generateDefinitionHash(i.export()),o=t.resources?.[n];if(!o)r.push({type:"new",resourceName:n,currentHash:a,savedHash:null});else{const s=o.currentVersion||"v0",f=o.versions?.[s]?.hash;f!==a&&r.push({type:"changed",resourceName:n,currentHash:a,savedHash:f,fromVersion:s,toVersion:this.getNextVersion(o.versions)})}}for(const[n,i]of Object.entries(t.resources||{}))if(!this.resources[n]){const a=i.currentVersion||"v0",o=i.versions?.[a];r.push({type:"deleted",resourceName:n,currentHash:null,savedHash:o?.hash,deletedVersion:a})}return r}generateDefinitionHash(t,r=void 0){const i={...t.attributes};t.options?.timestamps&&(delete i.createdAt,delete i.updatedAt);const a={attributes:i,behavior:r||t.behavior||"user-management"},o=so(a);return`sha256:${Bi.createHash("sha256").update(o).digest("hex")}`}getNextVersion(t={}){const r=Object.keys(t).filter(i=>i.startsWith("v")).map(i=>parseInt(i.substring(1))).filter(i=>!isNaN(i));return`v${(r.length>0?Math.max(...r):-1)+1}`}async startPlugins(){const t=this;if(!L.isEmpty(this.plugins)){const r=this.plugins.map(a=>L.isFunction(a)?new a(this):a),n=r.map(async a=>{a.beforeSetup&&await a.beforeSetup(),await a.setup(t),a.afterSetup&&await a.afterSetup()});await Promise.all(n);const i=r.map(async a=>{a.beforeStart&&await a.beforeStart(),await a.start(),a.afterStart&&await a.afterStart()});await Promise.all(i)}}async uploadMetadataFile(){const t={version:this.version,s3dbVersion:this.s3dbVersion,lastUpdated:new Date().toISOString(),resources:{}};Object.entries(this.resources).forEach(([r,n])=>{const i=n.export(),a=this.generateDefinitionHash(i),o=this.savedMetadata?.resources?.[r],s=o?.currentVersion||"v0",c=o?.versions?.[s];let f,l;!c||c.hash!==a?(f=this.getNextVersion(o?.versions),l=!0):(f=s,l=!1),t.resources[r]={currentVersion:f,partitions:i.options?.partitions||{},versions:{...o?.versions,[f]:{hash:a,attributes:i.attributes,options:i.options,behavior:i.behavior||"user-management",createdAt:l?new Date().toISOString():c?.createdAt}}},n.version!==f&&(n.version=f,n.emit("versionUpdated",{oldVersion:s,newVersion:f}))}),await this.client.putObject({key:"s3db.json",body:JSON.stringify(t,null,2),contentType:"application/json"}),this.savedMetadata=t,this.emit("metadataUploaded",t)}blankMetadataStructure(){return{version:"1",s3dbVersion:this.s3dbVersion,resources:{}}}resourceExists(t){return!!this.resources[t]}resourceExistsWithSameHash({name:t,attributes:r,options:n={},behavior:i="user-management"}){if(!this.resources[t])return{exists:!1,sameHash:!1,hash:null};const a=new li({name:t,attributes:r,behavior:i,observers:[],client:this.client,version:"temp",options:{cache:this.cache,...n}}),o=this.generateDefinitionHash(a.export(),i),s=this.generateDefinitionHash(this.resources[t].export(),this.resources[t].behavior);return{exists:!0,sameHash:o===s,hash:o,existingHash:s}}async createResourceIfNotExists({name:t,attributes:r,options:n={},behavior:i="user-management"}){const a=!!this.resources[t],o=this.resourceExistsWithSameHash({name:t,attributes:r,options:n,behavior:i});return o.exists&&o.sameHash?{resource:this.resources[t],created:!1,reason:"Resource already exists with same definition hash"}:{resource:await this.createResource({name:t,attributes:r,options:n,behavior:i}),created:!a,reason:a?"Resource updated with new definition":"New resource created"}}async createResource({name:t,attributes:r,options:n={},behavior:i="user-management"}){if(this.resources[t]){const c=this.resources[t];Object.assign(c.options,{cache:this.cache,...n}),i&&(c.behavior=i),c.updateAttributes(r);const f=this.generateDefinitionHash(c.export(),c.behavior),l=this.savedMetadata?.resources?.[t],d=l?.currentVersion||"v0",h=l?.versions?.[d];return(!h||h.hash!==f)&&await this.uploadMetadataFile(),this.emit("s3db.resourceUpdated",t),c}const o=this.savedMetadata?.resources?.[t]?.currentVersion||"v0",s=new li({name:t,attributes:r,behavior:i,observers:[this],client:this.client,version:o,options:{cache:this.cache,...n}});return this.resources[t]=s,await this.uploadMetadataFile(),this.emit("s3db.resourceCreated",t),s}resource(t){return this.resources[t]?this.resources[t]:Promise.reject(`resource ${t} does not exist`)}async listResources(){return Object.keys(this.resources).map(t=>({name:t}))}async getResource(t){if(!this.resources[t])throw new Error(`Resource not found: ${t}`);return this.resources[t]}get config(){return{version:this.version,s3dbVersion:this.s3dbVersion,bucket:this.bucket,keyPrefix:this.keyPrefix,parallelism:this.parallelism,verbose:this.verbose}}isConnected(){return!!this.savedMetadata}}class th extends cs{}class ui extends R{constructor(t={}){super(),this.config=t}async _set(t,r){}async _get(t){}async _del(t){}async _clear(t){}validateKey(t){if(t==null||typeof t!="string"||!t)throw new Error("Invalid key")}async set(t,r){return this.validateKey(t),await this._set(t,r),this.emit("set",r),r}async get(t){this.validateKey(t);const r=await this._get(t);return this.emit("get",r),r}async del(t){this.validateKey(t);const r=await this._del(t);return this.emit("delete",r),r}async delete(t){return this.del(t)}async clear(){const t=await this._clear();return this.emit("clear",t),t}}class rh extends ui{constructor(t={}){super(t),this.cache={},this.meta={},this.maxSize=t.maxSize||0,this.ttl=t.ttl||0}async _set(t,r){if(this.maxSize>0&&Object.keys(this.cache).length>=this.maxSize){const n=Object.entries(this.meta).sort((i,a)=>i[1].ts-a[1].ts)[0]?.[0];n&&(delete this.cache[n],delete this.meta[n])}return this.cache[t]=r,this.meta[t]={ts:Date.now()},r}async _get(t){if(!Object.prototype.hasOwnProperty.call(this.cache,t))return null;if(this.ttl>0){const r=Date.now(),n=this.meta[t];if(n&&r-n.ts>this.ttl*1e3)return delete this.cache[t],delete this.meta[t],null}return this.cache[t]}async _del(t){return delete this.cache[t],delete this.meta[t],!0}async _clear(){return this.cache={},this.meta={},!0}async size(){return Object.keys(this.cache).length}async keys(){return Object.keys(this.cache)}}var ls={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};function nh(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}function Ae(e,t,r,n,i){if(t.subarray&&e.subarray){e.set(t.subarray(r,r+n),i);return}for(var a=0;a<n;a++)e[i+a]=t[r+a]}var yr=Uint8Array,ae=Uint16Array,vr=Int32Array,ih=4,us=0,hs=1,ah=2;function gt(e){for(var t=e.length;--t>=0;)e[t]=0}var oh=0,ds=1,sh=2,fh=3,ch=258,hi=29,Dt=256,Ft=Dt+1+hi,_t=30,di=19,ps=2*Ft+1,Ve=15,pi=16,lh=7,yi=256,ys=16,vs=17,gs=18,vi=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],gr=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],uh=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],_s=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],hh=512,ke=new Array((Ft+2)*2);gt(ke);var Mt=new Array(_t*2);gt(Mt);var jt=new Array(hh);gt(jt);var Lt=new Array(ch-fh+1);gt(Lt);var gi=new Array(hi);gt(gi);var _r=new Array(_t);gt(_r);function _i(e,t,r,n,i){this.static_tree=e,this.extra_bits=t,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=e&&e.length}var ws,bs,ms;function wi(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}function xs(e){return e<256?jt[e]:jt[256+(e>>>7)]}function Nt(e,t){e.pending_buf[e.pending++]=t&255,e.pending_buf[e.pending++]=t>>>8&255}function X(e,t,r){e.bi_valid>pi-r?(e.bi_buf|=t<<e.bi_valid&65535,Nt(e,e.bi_buf),e.bi_buf=t>>pi-e.bi_valid,e.bi_valid+=r-pi):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r)}function pe(e,t,r){X(e,r[t*2],r[t*2+1])}function Es(e,t){var r=0;do r|=e&1,e>>>=1,r<<=1;while(--t>0);return r>>>1}function dh(e){e.bi_valid===16?(Nt(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=e.bi_buf&255,e.bi_buf>>=8,e.bi_valid-=8)}function ph(e,t){var r=t.dyn_tree,n=t.max_code,i=t.stat_desc.static_tree,a=t.stat_desc.has_stree,o=t.stat_desc.extra_bits,s=t.stat_desc.extra_base,c=t.stat_desc.max_length,f,l,d,h,u,p,v=0;for(h=0;h<=Ve;h++)e.bl_count[h]=0;for(r[e.heap[e.heap_max]*2+1]=0,f=e.heap_max+1;f<ps;f++)l=e.heap[f],h=r[r[l*2+1]*2+1]+1,h>c&&(h=c,v++),r[l*2+1]=h,!(l>n)&&(e.bl_count[h]++,u=0,l>=s&&(u=o[l-s]),p=r[l*2],e.opt_len+=p*(h+u),a&&(e.static_len+=p*(i[l*2+1]+u)));if(v!==0){do{for(h=c-1;e.bl_count[h]===0;)h--;e.bl_count[h]--,e.bl_count[h+1]+=2,e.bl_count[c]--,v-=2}while(v>0);for(h=c;h!==0;h--)for(l=e.bl_count[h];l!==0;)d=e.heap[--f],!(d>n)&&(r[d*2+1]!==h&&(e.opt_len+=(h-r[d*2+1])*r[d*2],r[d*2+1]=h),l--)}}function Ss(e,t,r){var n=new Array(Ve+1),i=0,a,o;for(a=1;a<=Ve;a++)n[a]=i=i+r[a-1]<<1;for(o=0;o<=t;o++){var s=e[o*2+1];s!==0&&(e[o*2]=Es(n[s]++,s))}}function yh(){var e,t,r,n,i,a=new Array(Ve+1);for(r=0,n=0;n<hi-1;n++)for(gi[n]=r,e=0;e<1<<vi[n];e++)Lt[r++]=n;for(Lt[r-1]=n,i=0,n=0;n<16;n++)for(_r[n]=i,e=0;e<1<<gr[n];e++)jt[i++]=n;for(i>>=7;n<_t;n++)for(_r[n]=i<<7,e=0;e<1<<gr[n]-7;e++)jt[256+i++]=n;for(t=0;t<=Ve;t++)a[t]=0;for(e=0;e<=143;)ke[e*2+1]=8,e++,a[8]++;for(;e<=255;)ke[e*2+1]=9,e++,a[9]++;for(;e<=279;)ke[e*2+1]=7,e++,a[7]++;for(;e<=287;)ke[e*2+1]=8,e++,a[8]++;for(Ss(ke,Ft+1,a),e=0;e<_t;e++)Mt[e*2+1]=5,Mt[e*2]=Es(e,5);ws=new _i(ke,vi,Dt+1,Ft,Ve),bs=new _i(Mt,gr,0,_t,Ve),ms=new _i(new Array(0),uh,0,di,lh)}function As(e){var t;for(t=0;t<Ft;t++)e.dyn_ltree[t*2]=0;for(t=0;t<_t;t++)e.dyn_dtree[t*2]=0;for(t=0;t<di;t++)e.bl_tree[t*2]=0;e.dyn_ltree[yi*2]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0}function ks(e){e.bi_valid>8?Nt(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0}function vh(e,t,r,n){ks(e),Nt(e,r),Nt(e,~r),Ae(e.pending_buf,e.window,t,r,e.pending),e.pending+=r}function Rs(e,t,r,n){var i=t*2,a=r*2;return e[i]<e[a]||e[i]===e[a]&&n[t]<=n[r]}function bi(e,t,r){for(var n=e.heap[r],i=r<<1;i<=e.heap_len&&(i<e.heap_len&&Rs(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!Rs(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n}function Os(e,t,r){var n,i,a=0,o,s;if(e.last_lit!==0)do n=e.pending_buf[e.d_buf+a*2]<<8|e.pending_buf[e.d_buf+a*2+1],i=e.pending_buf[e.l_buf+a],a++,n===0?pe(e,i,t):(o=Lt[i],pe(e,o+Dt+1,t),s=vi[o],s!==0&&(i-=gi[o],X(e,i,s)),n--,o=xs(n),pe(e,o,r),s=gr[o],s!==0&&(n-=_r[o],X(e,n,s)));while(a<e.last_lit);pe(e,yi,t)}function mi(e,t){var r=t.dyn_tree,n=t.stat_desc.static_tree,i=t.stat_desc.has_stree,a=t.stat_desc.elems,o,s,c=-1,f;for(e.heap_len=0,e.heap_max=ps,o=0;o<a;o++)r[o*2]!==0?(e.heap[++e.heap_len]=c=o,e.depth[o]=0):r[o*2+1]=0;for(;e.heap_len<2;)f=e.heap[++e.heap_len]=c<2?++c:0,r[f*2]=1,e.depth[f]=0,e.opt_len--,i&&(e.static_len-=n[f*2+1]);for(t.max_code=c,o=e.heap_len>>1;o>=1;o--)bi(e,r,o);f=a;do o=e.heap[1],e.heap[1]=e.heap[e.heap_len--],bi(e,r,1),s=e.heap[1],e.heap[--e.heap_max]=o,e.heap[--e.heap_max]=s,r[f*2]=r[o*2]+r[s*2],e.depth[f]=(e.depth[o]>=e.depth[s]?e.depth[o]:e.depth[s])+1,r[o*2+1]=r[s*2+1]=f,e.heap[1]=f++,bi(e,r,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],ph(e,t),Ss(r,c,e.bl_count)}function Ts(e,t,r){var n,i=-1,a,o=t[0*2+1],s=0,c=7,f=4;for(o===0&&(c=138,f=3),t[(r+1)*2+1]=65535,n=0;n<=r;n++)a=o,o=t[(n+1)*2+1],!(++s<c&&a===o)&&(s<f?e.bl_tree[a*2]+=s:a!==0?(a!==i&&e.bl_tree[a*2]++,e.bl_tree[ys*2]++):s<=10?e.bl_tree[vs*2]++:e.bl_tree[gs*2]++,s=0,i=a,o===0?(c=138,f=3):a===o?(c=6,f=3):(c=7,f=4))}function Is(e,t,r){var n,i=-1,a,o=t[0*2+1],s=0,c=7,f=4;for(o===0&&(c=138,f=3),n=0;n<=r;n++)if(a=o,o=t[(n+1)*2+1],!(++s<c&&a===o)){if(s<f)do pe(e,a,e.bl_tree);while(--s!==0);else a!==0?(a!==i&&(pe(e,a,e.bl_tree),s--),pe(e,ys,e.bl_tree),X(e,s-3,2)):s<=10?(pe(e,vs,e.bl_tree),X(e,s-3,3)):(pe(e,gs,e.bl_tree),X(e,s-11,7));s=0,i=a,o===0?(c=138,f=3):a===o?(c=6,f=3):(c=7,f=4)}}function gh(e){var t;for(Ts(e,e.dyn_ltree,e.l_desc.max_code),Ts(e,e.dyn_dtree,e.d_desc.max_code),mi(e,e.bl_desc),t=di-1;t>=3&&e.bl_tree[_s[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t}function _h(e,t,r,n){var i;for(X(e,t-257,5),X(e,r-1,5),X(e,n-4,4),i=0;i<n;i++)X(e,e.bl_tree[_s[i]*2+1],3);Is(e,e.dyn_ltree,t-1),Is(e,e.dyn_dtree,r-1)}function wh(e){var t=4093624447,r;for(r=0;r<=31;r++,t>>>=1)if(t&1&&e.dyn_ltree[r*2]!==0)return us;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return hs;for(r=32;r<Dt;r++)if(e.dyn_ltree[r*2]!==0)return hs;return us}var Ps=!1;function bh(e){Ps||(yh(),Ps=!0),e.l_desc=new wi(e.dyn_ltree,ws),e.d_desc=new wi(e.dyn_dtree,bs),e.bl_desc=new wi(e.bl_tree,ms),e.bi_buf=0,e.bi_valid=0,As(e)}function Cs(e,t,r,n){X(e,(oh<<1)+(n?1:0),3),vh(e,t,r)}function mh(e){X(e,ds<<1,3),pe(e,yi,ke),dh(e)}function xh(e,t,r,n){var i,a,o=0;e.level>0?(e.strm.data_type===ah&&(e.strm.data_type=wh(e)),mi(e,e.l_desc),mi(e,e.d_desc),o=gh(e),i=e.opt_len+3+7>>>3,a=e.static_len+3+7>>>3,a<=i&&(i=a)):i=a=r+5,r+4<=i&&t!==-1?Cs(e,t,r,n):e.strategy===ih||a===i?(X(e,(ds<<1)+(n?1:0),3),Os(e,ke,Mt)):(X(e,(sh<<1)+(n?1:0),3),_h(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),Os(e,e.dyn_ltree,e.dyn_dtree)),As(e),n&&ks(e)}function Me(e,t,r){return e.pending_buf[e.d_buf+e.last_lit*2]=t>>>8&255,e.pending_buf[e.d_buf+e.last_lit*2+1]=t&255,e.pending_buf[e.l_buf+e.last_lit]=r&255,e.last_lit++,t===0?e.dyn_ltree[r*2]++:(e.matches++,t--,e.dyn_ltree[(Lt[r]+Dt+1)*2]++,e.dyn_dtree[xs(t)*2]++),e.last_lit===e.lit_bufsize-1}function xi(e,t,r,n){for(var i=e&65535|0,a=e>>>16&65535|0,o=0;r!==0;){o=r>2e3?2e3:r,r-=o;do i=i+t[n++]|0,a=a+i|0;while(--o);i%=65521,a%=65521}return i|a<<16|0}function Eh(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;t[r]=e}return t}var Sh=Eh();function Z(e,t,r,n){var i=Sh,a=n+r;e^=-1;for(var o=n;o<a;o++)e=e>>>8^i[(e^t[o])&255];return e^-1}var Ge=0,Ah=1,kh=3,je=4,Ds=5,Le=0,Fs=1,Ne=-2,Rh=-3,Ei=-5,Oh=-1,Th=1,wr=2,Ih=3,Ph=4,Ch=2,Si=8,Dh=9,Fh=29,Mh=256,Ai=Mh+1+Fh,jh=30,Lh=19,Nh=2*Ai+1,Bh=15,C=3,Be=258,se=Be+C+1,Uh=32,ki=42,Ri=69,br=73,mr=91,xr=103,Ye=113,Bt=666,$=1,Ut=2,Je=3,wt=4,$h=3;function Ue(e,t){return e.msg=ls[t],t}function Ms(e){return(e<<1)-(e>4?9:0)}function Xe(e){for(var t=e.length;--t>=0;)e[t]=0}function $e(e){var t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),r!==0&&(Ae(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,t.pending===0&&(t.pending_out=0))}function q(e,t){xh(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,$e(e.strm)}function P(e,t){e.pending_buf[e.pending++]=t}function $t(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255}function zh(e,t,r,n){var i=e.avail_in;return i>n&&(i=n),i===0?0:(e.avail_in-=i,Ae(t,e.input,e.next_in,i,r),e.state.wrap===1?e.adler=xi(e.adler,t,i,r):e.state.wrap===2&&(e.adler=Z(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)}function js(e,t){var r=e.max_chain_length,n=e.strstart,i,a,o=e.prev_length,s=e.nice_match,c=e.strstart>e.w_size-se?e.strstart-(e.w_size-se):0,f=e.window,l=e.w_mask,d=e.prev,h=e.strstart+Be,u=f[n+o-1],p=f[n+o];e.prev_length>=e.good_match&&(r>>=2),s>e.lookahead&&(s=e.lookahead);do if(i=t,!(f[i+o]!==p||f[i+o-1]!==u||f[i]!==f[n]||f[++i]!==f[n+1])){n+=2,i++;do;while(f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&f[++n]===f[++i]&&n<h);if(a=Be-(h-n),n=h-Be,a>o){if(e.match_start=t,o=a,a>=s)break;u=f[n+o-1],p=f[n+o]}}while((t=d[t&l])>c&&--r!==0);return o<=e.lookahead?o:e.lookahead}function zt(e){var t=e.w_size,r,n,i,a,o;do{if(a=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-se)){Ae(e.window,e.window,t,t,0),e.match_start-=t,e.strstart-=t,e.block_start-=t,n=e.hash_size,r=n;do i=e.head[--r],e.head[r]=i>=t?i-t:0;while(--n);n=t,r=n;do i=e.prev[--r],e.prev[r]=i>=t?i-t:0;while(--n);a+=t}if(e.strm.avail_in===0)break;if(n=zh(e.strm,e.window,e.strstart+e.lookahead,a),e.lookahead+=n,e.lookahead+e.insert>=C)for(o=e.strstart-e.insert,e.ins_h=e.window[o],e.ins_h=(e.ins_h<<e.hash_shift^e.window[o+1])&e.hash_mask;e.insert&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[o+C-1])&e.hash_mask,e.prev[o&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=o,o++,e.insert--,!(e.lookahead+e.insert<C)););}while(e.lookahead<se&&e.strm.avail_in!==0)}function Zh(e,t){var r=65535;for(r>e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(zt(e),e.lookahead===0&&t===Ge)return $;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+r;if((e.strstart===0||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,q(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-se&&(q(e,!1),e.strm.avail_out===0))return $}return e.insert=0,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):(e.strstart>e.block_start&&(q(e,!1),e.strm.avail_out===0),$)}function Oi(e,t){for(var r,n;;){if(e.lookahead<se){if(zt(e),e.lookahead<se&&t===Ge)return $;if(e.lookahead===0)break}if(r=0,e.lookahead>=C&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+C-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),r!==0&&e.strstart-r<=e.w_size-se&&(e.match_length=js(e,r)),e.match_length>=C)if(n=Me(e,e.strstart-e.match_start,e.match_length-C),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=C){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+C-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(--e.match_length!==0);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+1])&e.hash_mask;else n=Me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(q(e,!1),e.strm.avail_out===0))return $}return e.insert=e.strstart<C-1?e.strstart:C-1,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):e.last_lit&&(q(e,!1),e.strm.avail_out===0)?$:Ut}function bt(e,t){for(var r,n,i;;){if(e.lookahead<se){if(zt(e),e.lookahead<se&&t===Ge)return $;if(e.lookahead===0)break}if(r=0,e.lookahead>=C&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+C-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=C-1,r!==0&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-se&&(e.match_length=js(e,r),e.match_length<=5&&(e.strategy===Th||e.match_length===C&&e.strstart-e.match_start>4096)&&(e.match_length=C-1)),e.prev_length>=C&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-C,n=Me(e,e.strstart-1-e.prev_match,e.prev_length-C),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+C-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(--e.prev_length!==0);if(e.match_available=0,e.match_length=C-1,e.strstart++,n&&(q(e,!1),e.strm.avail_out===0))return $}else if(e.match_available){if(n=Me(e,0,e.window[e.strstart-1]),n&&q(e,!1),e.strstart++,e.lookahead--,e.strm.avail_out===0)return $}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=Me(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<C-1?e.strstart:C-1,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):e.last_lit&&(q(e,!1),e.strm.avail_out===0)?$:Ut}function Hh(e,t){for(var r,n,i,a,o=e.window;;){if(e.lookahead<=Be){if(zt(e),e.lookahead<=Be&&t===Ge)return $;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=C&&e.strstart>0&&(i=e.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){a=e.strstart+Be;do;while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&i<a);e.match_length=Be-(a-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=C?(r=Me(e,1,e.match_length-C),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=Me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(q(e,!1),e.strm.avail_out===0))return $}return e.insert=0,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):e.last_lit&&(q(e,!1),e.strm.avail_out===0)?$:Ut}function qh(e,t){for(var r;;){if(e.lookahead===0&&(zt(e),e.lookahead===0)){if(t===Ge)return $;break}if(e.match_length=0,r=Me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(q(e,!1),e.strm.avail_out===0))return $}return e.insert=0,t===je?(q(e,!0),e.strm.avail_out===0?Je:wt):e.last_lit&&(q(e,!1),e.strm.avail_out===0)?$:Ut}function ye(e,t,r,n,i){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=n,this.func=i}var mt;mt=[new ye(0,0,0,0,Zh),new ye(4,4,8,4,Oi),new ye(4,5,16,8,Oi),new ye(4,6,32,32,Oi),new ye(4,4,16,16,bt),new ye(8,16,32,32,bt),new ye(8,16,128,128,bt),new ye(8,32,128,256,bt),new ye(32,128,258,1024,bt),new ye(32,258,258,4096,bt)];function Kh(e){e.window_size=2*e.w_size,Xe(e.head),e.max_lazy_match=mt[e.level].max_lazy,e.good_match=mt[e.level].good_length,e.nice_match=mt[e.level].nice_length,e.max_chain_length=mt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=C-1,e.match_available=0,e.ins_h=0}function Wh(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Si,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new ae(Nh*2),this.dyn_dtree=new ae((2*jh+1)*2),this.bl_tree=new ae((2*Lh+1)*2),Xe(this.dyn_ltree),Xe(this.dyn_dtree),Xe(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new ae(Bh+1),this.heap=new ae(2*Ai+1),Xe(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new ae(2*Ai+1),Xe(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Vh(e){var t;return!e||!e.state?Ue(e,Ne):(e.total_in=e.total_out=0,e.data_type=Ch,t=e.state,t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?ki:Ye,e.adler=t.wrap===2?0:1,t.last_flush=Ge,bh(t),Le)}function Ls(e){var t=Vh(e);return t===Le&&Kh(e.state),t}function Gh(e,t,r,n,i,a){if(!e)return Ne;var o=1;if(t===Oh&&(t=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>Dh||r!==Si||n<8||n>15||t<0||t>9||a<0||a>Ph)return Ue(e,Ne);n===8&&(n=9);var s=new Wh;return e.state=s,s.strm=e,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<<s.w_bits,s.w_mask=s.w_size-1,s.hash_bits=i+7,s.hash_size=1<<s.hash_bits,s.hash_mask=s.hash_size-1,s.hash_shift=~~((s.hash_bits+C-1)/C),s.window=new yr(s.w_size*2),s.head=new ae(s.hash_size),s.prev=new ae(s.w_size),s.lit_bufsize=1<<i+6,s.pending_buf_size=s.lit_bufsize*4,s.pending_buf=new yr(s.pending_buf_size),s.d_buf=1*s.lit_bufsize,s.l_buf=3*s.lit_bufsize,s.level=t,s.strategy=a,s.method=r,Ls(e)}function Yh(e,t){var r,n,i,a;if(!e||!e.state||t>Ds||t<0)return e?Ue(e,Ne):Ne;if(n=e.state,!e.output||!e.input&&e.avail_in!==0||n.status===Bt&&t!==je)return Ue(e,e.avail_out===0?Ei:Ne);if(n.strm=e,r=n.last_flush,n.last_flush=t,n.status===ki)if(n.wrap===2)e.adler=0,P(n,31),P(n,139),P(n,8),n.gzhead?(P(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),P(n,n.gzhead.time&255),P(n,n.gzhead.time>>8&255),P(n,n.gzhead.time>>16&255),P(n,n.gzhead.time>>24&255),P(n,n.level===9?2:n.strategy>=wr||n.level<2?4:0),P(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(P(n,n.gzhead.extra.length&255),P(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=Z(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=Ri):(P(n,0),P(n,0),P(n,0),P(n,0),P(n,0),P(n,n.level===9?2:n.strategy>=wr||n.level<2?4:0),P(n,$h),n.status=Ye);else{var o=Si+(n.w_bits-8<<4)<<8,s=-1;n.strategy>=wr||n.level<2?s=0:n.level<6?s=1:n.level===6?s=2:s=3,o|=s<<6,n.strstart!==0&&(o|=Uh),o+=31-o%31,n.status=Ye,$t(n,o),n.strstart!==0&&($t(n,e.adler>>>16),$t(n,e.adler&65535)),e.adler=1}if(n.status===Ri)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(n.gzhead.extra.length&65535)&&!(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),$e(e),i=n.pending,n.pending===n.pending_buf_size));)P(n,n.gzhead.extra[n.gzindex]&255),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=br)}else n.status=br;if(n.status===br)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),$e(e),i=n.pending,n.pending===n.pending_buf_size)){a=1;break}n.gzindex<n.gzhead.name.length?a=n.gzhead.name.charCodeAt(n.gzindex++)&255:a=0,P(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.gzindex=0,n.status=mr)}else n.status=mr;if(n.status===mr)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),$e(e),i=n.pending,n.pending===n.pending_buf_size)){a=1;break}n.gzindex<n.gzhead.comment.length?a=n.gzhead.comment.charCodeAt(n.gzindex++)&255:a=0,P(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=Z(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.status=xr)}else n.status=xr;if(n.status===xr&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&$e(e),n.pending+2<=n.pending_buf_size&&(P(n,e.adler&255),P(n,e.adler>>8&255),e.adler=0,n.status=Ye)):n.status=Ye),n.pending!==0){if($e(e),e.avail_out===0)return n.last_flush=-1,Le}else if(e.avail_in===0&&Ms(t)<=Ms(r)&&t!==je)return Ue(e,Ei);if(n.status===Bt&&e.avail_in!==0)return Ue(e,Ei);if(e.avail_in!==0||n.lookahead!==0||t!==Ge&&n.status!==Bt){var c=n.strategy===wr?qh(n,t):n.strategy===Ih?Hh(n,t):mt[n.level].func(n,t);if((c===Je||c===wt)&&(n.status=Bt),c===$||c===Je)return e.avail_out===0&&(n.last_flush=-1),Le;if(c===Ut&&(t===Ah?mh(n):t!==Ds&&(Cs(n,0,0,!1),t===kh&&(Xe(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),$e(e),e.avail_out===0))return n.last_flush=-1,Le}return t!==je?Le:n.wrap<=0?Fs:(n.wrap===2?(P(n,e.adler&255),P(n,e.adler>>8&255),P(n,e.adler>>16&255),P(n,e.adler>>24&255),P(n,e.total_in&255),P(n,e.total_in>>8&255),P(n,e.total_in>>16&255),P(n,e.total_in>>24&255)):($t(n,e.adler>>>16),$t(n,e.adler&65535)),$e(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending!==0?Le:Fs)}function Jh(e){var t;return!e||!e.state?Ne:(t=e.state.status,t!==ki&&t!==Ri&&t!==br&&t!==mr&&t!==xr&&t!==Ye&&t!==Bt?Ue(e,Ne):(e.state=null,t===Ye?Ue(e,Rh):Le))}var Er=30,Xh=12;function Qh(e,t){var r,n,i,a,o,s,c,f,l,d,h,u,p,v,_,w,E,S,g,A,T,b,x,O,k;r=e.state,n=e.next_in,O=e.input,i=n+(e.avail_in-5),a=e.next_out,k=e.output,o=a-(t-e.avail_out),s=a+(e.avail_out-257),c=r.dmax,f=r.wsize,l=r.whave,d=r.wnext,h=r.window,u=r.hold,p=r.bits,v=r.lencode,_=r.distcode,w=(1<<r.lenbits)-1,E=(1<<r.distbits)-1;e:do{p<15&&(u+=O[n++]<<p,p+=8,u+=O[n++]<<p,p+=8),S=v[u&w];t:for(;;){if(g=S>>>24,u>>>=g,p-=g,g=S>>>16&255,g===0)k[a++]=S&65535;else if(g&16){A=S&65535,g&=15,g&&(p<g&&(u+=O[n++]<<p,p+=8),A+=u&(1<<g)-1,u>>>=g,p-=g),p<15&&(u+=O[n++]<<p,p+=8,u+=O[n++]<<p,p+=8),S=_[u&E];r:for(;;){if(g=S>>>24,u>>>=g,p-=g,g=S>>>16&255,g&16){if(T=S&65535,g&=15,p<g&&(u+=O[n++]<<p,p+=8,p<g&&(u+=O[n++]<<p,p+=8)),T+=u&(1<<g)-1,T>c){e.msg="invalid distance too far back",r.mode=Er;break e}if(u>>>=g,p-=g,g=a-o,T>g){if(g=T-g,g>l&&r.sane){e.msg="invalid distance too far back",r.mode=Er;break e}if(b=0,x=h,d===0){if(b+=f-g,g<A){A-=g;do k[a++]=h[b++];while(--g);b=a-T,x=k}}else if(d<g){if(b+=f+d-g,g-=d,g<A){A-=g;do k[a++]=h[b++];while(--g);if(b=0,d<A){g=d,A-=g;do k[a++]=h[b++];while(--g);b=a-T,x=k}}}else if(b+=d-g,g<A){A-=g;do k[a++]=h[b++];while(--g);b=a-T,x=k}for(;A>2;)k[a++]=x[b++],k[a++]=x[b++],k[a++]=x[b++],A-=3;A&&(k[a++]=x[b++],A>1&&(k[a++]=x[b++]))}else{b=a-T;do k[a++]=k[b++],k[a++]=k[b++],k[a++]=k[b++],A-=3;while(A>2);A&&(k[a++]=k[b++],A>1&&(k[a++]=k[b++]))}}else if((g&64)===0){S=_[(S&65535)+(u&(1<<g)-1)];continue r}else{e.msg="invalid distance code",r.mode=Er;break e}break}}else if((g&64)===0){S=v[(S&65535)+(u&(1<<g)-1)];continue t}else if(g&32){r.mode=Xh;break e}else{e.msg="invalid literal/length code",r.mode=Er;break e}break}}while(n<i&&a<s);A=p>>3,n-=A,p-=A<<3,u&=(1<<p)-1,e.next_in=n,e.next_out=a,e.avail_in=n<i?5+(i-n):5-(n-i),e.avail_out=a<s?257+(s-a):257-(a-s),r.hold=u,r.bits=p}var xt=15,Ns=852,Bs=592,Us=0,Ti=1,$s=2,ed=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],td=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],rd=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],nd=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];function Zt(e,t,r,n,i,a,o,s){var c=s.bits,f=0,l=0,d=0,h=0,u=0,p=0,v=0,_=0,w=0,E=0,S,g,A,T,b,x=null,O=0,k,F=new ae(xt+1),K=new ae(xt+1),G=null,oe=0,ft,Q,ve;for(f=0;f<=xt;f++)F[f]=0;for(l=0;l<n;l++)F[t[r+l]]++;for(u=c,h=xt;h>=1&&F[h]===0;h--);if(u>h&&(u=h),h===0)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(d=1;d<h&&F[d]===0;d++);for(u<d&&(u=d),_=1,f=1;f<=xt;f++)if(_<<=1,_-=F[f],_<0)return-1;if(_>0&&(e===Us||h!==1))return-1;for(K[1]=0,f=1;f<xt;f++)K[f+1]=K[f]+F[f];for(l=0;l<n;l++)t[r+l]!==0&&(o[K[t[r+l]]++]=l);if(e===Us?(x=G=o,k=19):e===Ti?(x=ed,O-=257,G=td,oe-=257,k=256):(x=rd,G=nd,k=-1),E=0,l=0,f=d,b=a,p=u,v=0,A=-1,w=1<<u,T=w-1,e===Ti&&w>Ns||e===$s&&w>Bs)return 1;for(;;){ft=f-v,o[l]<k?(Q=0,ve=o[l]):o[l]>k?(Q=G[oe+o[l]],ve=x[O+o[l]]):(Q=96,ve=0),S=1<<f-v,g=1<<p,d=g;do g-=S,i[b+(E>>v)+g]=ft<<24|Q<<16|ve|0;while(g!==0);for(S=1<<f-1;E&S;)S>>=1;if(S!==0?(E&=S-1,E+=S):E=0,l++,--F[f]===0){if(f===h)break;f=t[r+o[l]]}if(f>u&&(E&T)!==A){for(v===0&&(v=u),b+=d,p=f-v,_=1<<p;p+v<h&&(_-=F[p+v],!(_<=0));)p++,_<<=1;if(w+=1<<p,e===Ti&&w>Ns||e===$s&&w>Bs)return 1;A=E&T,i[A]=u<<24|p<<16|b-a|0}}return E!==0&&(i[b+E]=f-v<<24|4194304|0),s.bits=u,0}var id=0,zs=1,Zs=2,Hs=4,ad=5,Sr=6,Ht=0,od=1,sd=2,ze=-2,fd=-3,cd=-4,ld=-5,qs=8,Ks=1,Ws=2,Vs=3,Gs=4,Ys=5,Js=6,Xs=7,Qs=8,ef=9,tf=10,rf=11,Re=12,Ii=13,nf=14,Pi=15,af=16,of=17,sf=18,ff=19,Ar=20,kr=21,cf=22,lf=23,uf=24,hf=25,df=26,Ci=27,pf=28,yf=29,M=30,ud=31,hd=32,dd=852,pd=592;function vf(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function yd(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new ae(320),this.work=new ae(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function vd(e){var t;return!e||!e.state?ze:(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=t.wrap&1),t.mode=Ks,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new vr(dd),t.distcode=t.distdyn=new vr(pd),t.sane=1,t.back=-1,Ht)}function gf(e){var t;return!e||!e.state?ze:(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,vd(e))}function gd(e,t){var r,n;return!e||!e.state||(n=e.state,t<0?(r=0,t=-t):(r=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?ze:(n.window!==null&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,gf(e))}function _d(e,t){var r,n;return e?(n=new yd,e.state=n,n.window=null,r=gd(e,t),r!==Ht&&(e.state=null),r):ze}var _f=!0,Di,Fi;function wd(e){if(_f){var t;for(Di=new vr(512),Fi=new vr(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Zt(zs,e.lens,0,288,Di,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Zt(Zs,e.lens,0,32,Fi,0,e.work,{bits:5}),_f=!1}e.lencode=Di,e.lenbits=9,e.distcode=Fi,e.distbits=5}function bd(e,t,r,n){var i,a=e.state;return a.window===null&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new yr(a.wsize)),n>=a.wsize?(Ae(a.window,t,r-a.wsize,a.wsize,0),a.wnext=0,a.whave=a.wsize):(i=a.wsize-a.wnext,i>n&&(i=n),Ae(a.window,t,r-n,i,a.wnext),n-=i,n?(Ae(a.window,t,r-n,n,0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0}function md(e,t){var r,n,i,a,o,s,c,f,l,d,h,u,p,v,_=0,w,E,S,g,A,T,b,x,O=new yr(4),k,F,K=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!e||!e.state||!e.output||!e.input&&e.avail_in!==0)return ze;r=e.state,r.mode===Re&&(r.mode=Ii),o=e.next_out,i=e.output,c=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,f=r.hold,l=r.bits,d=s,h=c,x=Ht;e:for(;;)switch(r.mode){case Ks:if(r.wrap===0){r.mode=Ii;break}for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(r.wrap&2&&f===35615){r.check=0,O[0]=f&255,O[1]=f>>>8&255,r.check=Z(r.check,O,2,0),f=0,l=0,r.mode=Ws;break}if(r.flags=0,r.head&&(r.head.done=!1),!(r.wrap&1)||(((f&255)<<8)+(f>>8))%31){e.msg="incorrect header check",r.mode=M;break}if((f&15)!==qs){e.msg="unknown compression method",r.mode=M;break}if(f>>>=4,l-=4,b=(f&15)+8,r.wbits===0)r.wbits=b;else if(b>r.wbits){e.msg="invalid window size",r.mode=M;break}r.dmax=1<<b,e.adler=r.check=1,r.mode=f&512?tf:Re,f=0,l=0;break;case Ws:for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(r.flags=f,(r.flags&255)!==qs){e.msg="unknown compression method",r.mode=M;break}if(r.flags&57344){e.msg="unknown header flags set",r.mode=M;break}r.head&&(r.head.text=f>>8&1),r.flags&512&&(O[0]=f&255,O[1]=f>>>8&255,r.check=Z(r.check,O,2,0)),f=0,l=0,r.mode=Vs;case Vs:for(;l<32;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.head&&(r.head.time=f),r.flags&512&&(O[0]=f&255,O[1]=f>>>8&255,O[2]=f>>>16&255,O[3]=f>>>24&255,r.check=Z(r.check,O,4,0)),f=0,l=0,r.mode=Gs;case Gs:for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.head&&(r.head.xflags=f&255,r.head.os=f>>8),r.flags&512&&(O[0]=f&255,O[1]=f>>>8&255,r.check=Z(r.check,O,2,0)),f=0,l=0,r.mode=Ys;case Ys:if(r.flags&1024){for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.length=f,r.head&&(r.head.extra_len=f),r.flags&512&&(O[0]=f&255,O[1]=f>>>8&255,r.check=Z(r.check,O,2,0)),f=0,l=0}else r.head&&(r.head.extra=null);r.mode=Js;case Js:if(r.flags&1024&&(u=r.length,u>s&&(u=s),u&&(r.head&&(b=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),Ae(r.head.extra,n,a,u,b)),r.flags&512&&(r.check=Z(r.check,n,u,a)),s-=u,a+=u,r.length-=u),r.length))break e;r.length=0,r.mode=Xs;case Xs:if(r.flags&2048){if(s===0)break e;u=0;do b=n[a+u++],r.head&&b&&r.length<65536&&(r.head.name+=String.fromCharCode(b));while(b&&u<s);if(r.flags&512&&(r.check=Z(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=Qs;case Qs:if(r.flags&4096){if(s===0)break e;u=0;do b=n[a+u++],r.head&&b&&r.length<65536&&(r.head.comment+=String.fromCharCode(b));while(b&&u<s);if(r.flags&512&&(r.check=Z(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.comment=null);r.mode=ef;case ef:if(r.flags&512){for(;l<16;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(f!==(r.check&65535)){e.msg="header crc mismatch",r.mode=M;break}f=0,l=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=Re;break;case tf:for(;l<32;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}e.adler=r.check=vf(f),f=0,l=0,r.mode=rf;case rf:if(r.havedict===0)return e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=s,r.hold=f,r.bits=l,sd;e.adler=r.check=1,r.mode=Re;case Re:if(t===ad||t===Sr)break e;case Ii:if(r.last){f>>>=l&7,l-=l&7,r.mode=Ci;break}for(;l<3;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}switch(r.last=f&1,f>>>=1,l-=1,f&3){case 0:r.mode=nf;break;case 1:if(wd(r),r.mode=Ar,t===Sr){f>>>=2,l-=2;break e}break;case 2:r.mode=of;break;case 3:e.msg="invalid block type",r.mode=M}f>>>=2,l-=2;break;case nf:for(f>>>=l&7,l-=l&7;l<32;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if((f&65535)!==(f>>>16^65535)){e.msg="invalid stored block lengths",r.mode=M;break}if(r.length=f&65535,f=0,l=0,r.mode=Pi,t===Sr)break e;case Pi:r.mode=af;case af:if(u=r.length,u){if(u>s&&(u=s),u>c&&(u=c),u===0)break e;Ae(i,n,a,u,o),s-=u,a+=u,c-=u,o+=u,r.length-=u;break}r.mode=Re;break;case of:for(;l<14;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(r.nlen=(f&31)+257,f>>>=5,l-=5,r.ndist=(f&31)+1,f>>>=5,l-=5,r.ncode=(f&15)+4,f>>>=4,l-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=M;break}r.have=0,r.mode=sf;case sf:for(;r.have<r.ncode;){for(;l<3;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.lens[K[r.have++]]=f&7,f>>>=3,l-=3}for(;r.have<19;)r.lens[K[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,k={bits:r.lenbits},x=Zt(id,r.lens,0,19,r.lencode,0,r.work,k),r.lenbits=k.bits,x){e.msg="invalid code lengths set",r.mode=M;break}r.have=0,r.mode=ff;case ff:for(;r.have<r.nlen+r.ndist;){for(;_=r.lencode[f&(1<<r.lenbits)-1],w=_>>>24,E=_>>>16&255,S=_&65535,!(w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(S<16)f>>>=w,l-=w,r.lens[r.have++]=S;else{if(S===16){for(F=w+2;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(f>>>=w,l-=w,r.have===0){e.msg="invalid bit length repeat",r.mode=M;break}b=r.lens[r.have-1],u=3+(f&3),f>>>=2,l-=2}else if(S===17){for(F=w+3;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}f>>>=w,l-=w,b=0,u=3+(f&7),f>>>=3,l-=3}else{for(F=w+7;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}f>>>=w,l-=w,b=0,u=11+(f&127),f>>>=7,l-=7}if(r.have+u>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=M;break}for(;u--;)r.lens[r.have++]=b}}if(r.mode===M)break;if(r.lens[256]===0){e.msg="invalid code -- missing end-of-block",r.mode=M;break}if(r.lenbits=9,k={bits:r.lenbits},x=Zt(zs,r.lens,0,r.nlen,r.lencode,0,r.work,k),r.lenbits=k.bits,x){e.msg="invalid literal/lengths set",r.mode=M;break}if(r.distbits=6,r.distcode=r.distdyn,k={bits:r.distbits},x=Zt(Zs,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,k),r.distbits=k.bits,x){e.msg="invalid distances set",r.mode=M;break}if(r.mode=Ar,t===Sr)break e;case Ar:r.mode=kr;case kr:if(s>=6&&c>=258){e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=s,r.hold=f,r.bits=l,Qh(e,h),o=e.next_out,i=e.output,c=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,f=r.hold,l=r.bits,r.mode===Re&&(r.back=-1);break}for(r.back=0;_=r.lencode[f&(1<<r.lenbits)-1],w=_>>>24,E=_>>>16&255,S=_&65535,!(w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(E&&(E&240)===0){for(g=w,A=E,T=S;_=r.lencode[T+((f&(1<<g+A)-1)>>g)],w=_>>>24,E=_>>>16&255,S=_&65535,!(g+w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}f>>>=g,l-=g,r.back+=g}if(f>>>=w,l-=w,r.back+=w,r.length=S,E===0){r.mode=df;break}if(E&32){r.back=-1,r.mode=Re;break}if(E&64){e.msg="invalid literal/length code",r.mode=M;break}r.extra=E&15,r.mode=cf;case cf:if(r.extra){for(F=r.extra;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.length+=f&(1<<r.extra)-1,f>>>=r.extra,l-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=lf;case lf:for(;_=r.distcode[f&(1<<r.distbits)-1],w=_>>>24,E=_>>>16&255,S=_&65535,!(w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if((E&240)===0){for(g=w,A=E,T=S;_=r.distcode[T+((f&(1<<g+A)-1)>>g)],w=_>>>24,E=_>>>16&255,S=_&65535,!(g+w<=l);){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}f>>>=g,l-=g,r.back+=g}if(f>>>=w,l-=w,r.back+=w,E&64){e.msg="invalid distance code",r.mode=M;break}r.offset=S,r.extra=E&15,r.mode=uf;case uf:if(r.extra){for(F=r.extra;l<F;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}r.offset+=f&(1<<r.extra)-1,f>>>=r.extra,l-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=M;break}r.mode=hf;case hf:if(c===0)break e;if(u=h-c,r.offset>u){if(u=r.offset-u,u>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=M;break}u>r.wnext?(u-=r.wnext,p=r.wsize-u):p=r.wnext-u,u>r.length&&(u=r.length),v=r.window}else v=i,p=o-r.offset,u=r.length;u>c&&(u=c),c-=u,r.length-=u;do i[o++]=v[p++];while(--u);r.length===0&&(r.mode=kr);break;case df:if(c===0)break e;i[o++]=r.length,c--,r.mode=kr;break;case Ci:if(r.wrap){for(;l<32;){if(s===0)break e;s--,f|=n[a++]<<l,l+=8}if(h-=c,e.total_out+=h,r.total+=h,h&&(e.adler=r.check=r.flags?Z(r.check,i,h,o-h):xi(r.check,i,h,o-h)),h=c,(r.flags?f:vf(f))!==r.check){e.msg="incorrect data check",r.mode=M;break}f=0,l=0}r.mode=pf;case pf:if(r.wrap&&r.flags){for(;l<32;){if(s===0)break e;s--,f+=n[a++]<<l,l+=8}if(f!==(r.total&4294967295)){e.msg="incorrect length check",r.mode=M;break}f=0,l=0}r.mode=yf;case yf:x=od;break e;case M:x=fd;break e;case ud:return cd;case hd:default:return ze}return e.next_out=o,e.avail_out=c,e.next_in=a,e.avail_in=s,r.hold=f,r.bits=l,(r.wsize||h!==e.avail_out&&r.mode<M&&(r.mode<Ci||t!==Hs))&&bd(e,e.output,e.next_out,h-e.avail_out),d-=e.avail_in,h-=e.avail_out,e.total_in+=d,e.total_out+=h,r.total+=h,r.wrap&&h&&(e.adler=r.check=r.flags?Z(r.check,i,h,e.next_out-h):xi(r.check,i,h,e.next_out-h)),e.data_type=r.bits+(r.last?64:0)+(r.mode===Re?128:0)+(r.mode===Ar||r.mode===Pi?256:0),(d===0&&h===0||t===Hs)&&x===Ht&&(x=ld),x}function xd(e){if(!e||!e.state)return ze;var t=e.state;return t.window&&(t.window=null),e.state=null,Ht}var Mi=0,Et=1,Rr=2,qt=3,Or=4,St=5,Kt=6,Wt=7,wf=0,bf=1,mf=2,xf=3,ji=4,Ef=5,Ed=6,Tr=0,Sf=1,Af=2,Sd=-1,Ad=-2,kd=-3,kf=-5,Rd=0,Od=1,Td=9,Id=-1,Pd=1,Cd=2,Dd=3,Fd=4,Md=0,jd=0,Ld=1,Nd=2,Rf=8;function fe(e){if(e<Et||e>Wt)throw new TypeError("Bad argument");this.mode=e,this.init_done=!1,this.write_in_progress=!1,this.pending_close=!1,this.windowBits=0,this.level=0,this.memLevel=0,this.strategy=0,this.dictionary=null}fe.prototype.init=function(e,t,r,n,i){this.windowBits=e,this.level=t,this.memLevel=r,this.strategy=n,(this.mode===qt||this.mode===Or)&&(this.windowBits+=16),this.mode===Wt&&(this.windowBits+=32),(this.mode===St||this.mode===Kt)&&(this.windowBits=-this.windowBits),this.strm=new nh;var a;switch(this.mode){case Et:case qt:case St:a=Gh(this.strm,this.level,Rf,this.windowBits,this.memLevel,this.strategy);break;case Rr:case Or:case Kt:case Wt:a=_d(this.strm,this.windowBits);break;default:throw new Error("Unknown mode "+this.mode)}if(a!==Tr){this._error(a);return}this.write_in_progress=!1,this.init_done=!0},fe.prototype.params=function(){throw new Error("deflateParams Not supported")},fe.prototype._writeCheck=function(){if(!this.init_done)throw new Error("write before init");if(this.mode===Mi)throw new Error("already finalized");if(this.write_in_progress)throw new Error("write already in progress");if(this.pending_close)throw new Error("close is pending")},fe.prototype.write=function(e,t,r,n,i,a,o){this._writeCheck(),this.write_in_progress=!0;var s=this;return xe.nextTick(function(){s.write_in_progress=!1;var c=s._write(e,t,r,n,i,a,o);s.callback(c[0],c[1]),s.pending_close&&s.close()}),this};function Bd(e,t){for(var r=0;r<e.length;r++)this[t+r]=e[r]}fe.prototype.writeSync=function(e,t,r,n,i,a,o){return this._writeCheck(),this._write(e,t,r,n,i,a,o)},fe.prototype._write=function(e,t,r,n,i,a,o){if(this.write_in_progress=!0,e!==wf&&e!==bf&&e!==mf&&e!==xf&&e!==ji&&e!==Ef)throw new Error("Invalid flush value");t==null&&(t=new y(0),n=0,r=0),i._set?i.set=i._set:i.set=Bd;var s=this.strm;s.avail_in=n,s.input=t,s.next_in=r,s.avail_out=o,s.output=i,s.next_out=a;var c;switch(this.mode){case Et:case qt:case St:c=Yh(s,e);break;case Wt:case Rr:case Or:case Kt:c=md(s,e);break;default:throw new Error("Unknown mode "+this.mode)}return this._checkError(c,s,e)||this._error(c),this.write_in_progress=!1,[s.avail_in,s.avail_out]},fe.prototype._checkError=function(e,t,r){switch(e){case Tr:case kf:if(t.avail_out!==0&&r===ji)return!1;break;case Sf:break;case Af:return!1;default:return!1}return!0},fe.prototype.close=function(){if(this.write_in_progress){this.pending_close=!0;return}this.pending_close=!1,this.mode===Et||this.mode===qt||this.mode===St?Jh(this.strm):xd(this.strm),this.mode=Mi};var Ir;fe.prototype.reset=function(){switch(this.mode){case Et:case St:Ir=Ls(this.strm);break;case Rr:case Kt:Ir=gf(this.strm);break}Ir!==Tr&&this._error(Ir)},fe.prototype._error=function(e){this.onerror(ls[e]+": "+this.strm.msg,e),this.write_in_progress=!1,this.pending_close&&this.close()};var Of=Object.freeze({__proto__:null,DEFLATE:Et,DEFLATERAW:St,GUNZIP:Or,GZIP:qt,INFLATE:Rr,INFLATERAW:Kt,NONE:Mi,UNZIP:Wt,Z_BEST_COMPRESSION:Td,Z_BEST_SPEED:Od,Z_BINARY:jd,Z_BLOCK:Ef,Z_BUF_ERROR:kf,Z_DATA_ERROR:kd,Z_DEFAULT_COMPRESSION:Id,Z_DEFAULT_STRATEGY:Md,Z_DEFLATED:Rf,Z_ERRNO:Sd,Z_FILTERED:Pd,Z_FINISH:ji,Z_FIXED:Fd,Z_FULL_FLUSH:xf,Z_HUFFMAN_ONLY:Cd,Z_NEED_DICT:Af,Z_NO_COMPRESSION:Rd,Z_NO_FLUSH:wf,Z_OK:Tr,Z_PARTIAL_FLUSH:bf,Z_RLE:Dd,Z_STREAM_END:Sf,Z_STREAM_ERROR:Ad,Z_SYNC_FLUSH:mf,Z_TEXT:Ld,Z_TREES:Ed,Z_UNKNOWN:Nd,Zlib:fe});function Ud(e,t){if(!e)throw new Error(t)}var m={};Object.keys(Of).forEach(function(e){m[e]=Of[e]}),m.Z_MIN_WINDOWBITS=8,m.Z_MAX_WINDOWBITS=15,m.Z_DEFAULT_WINDOWBITS=15,m.Z_MIN_CHUNK=64,m.Z_MAX_CHUNK=1/0,m.Z_DEFAULT_CHUNK=16384,m.Z_MIN_MEMLEVEL=1,m.Z_MAX_MEMLEVEL=9,m.Z_DEFAULT_MEMLEVEL=8,m.Z_MIN_LEVEL=-1,m.Z_MAX_LEVEL=9,m.Z_DEFAULT_LEVEL=m.Z_DEFAULT_COMPRESSION;var Vt={Z_OK:m.Z_OK,Z_STREAM_END:m.Z_STREAM_END,Z_NEED_DICT:m.Z_NEED_DICT,Z_ERRNO:m.Z_ERRNO,Z_STREAM_ERROR:m.Z_STREAM_ERROR,Z_DATA_ERROR:m.Z_DATA_ERROR,Z_MEM_ERROR:m.Z_MEM_ERROR,Z_BUF_ERROR:m.Z_BUF_ERROR,Z_VERSION_ERROR:m.Z_VERSION_ERROR};Object.keys(Vt).forEach(function(e){Vt[Vt[e]]=e});function $d(e){return new tt(e)}function zd(e){return new rt(e)}function Zd(e){return new at(e)}function Hd(e){return new ot(e)}function qd(e){return new nt(e)}function Kd(e){return new it(e)}function Wd(e){return new st(e)}function Vd(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new tt(t),e,r)}function Gd(e,t){return et(new tt(t),e)}function Yd(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new nt(t),e,r)}function Jd(e,t){return et(new nt(t),e)}function Xd(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new at(t),e,r)}function Qd(e,t){return et(new at(t),e)}function ep(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new st(t),e,r)}function tp(e,t){return et(new st(t),e)}function rp(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new rt(t),e,r)}function np(e,t){return et(new rt(t),e)}function ip(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new it(t),e,r)}function ap(e,t){return et(new it(t),e)}function op(e,t,r){return typeof t=="function"&&(r=t,t={}),Qe(new ot(t),e,r)}function sp(e,t){return et(new ot(t),e)}function Qe(e,t,r){var n=[],i=0;e.on("error",o),e.on("end",s),e.end(t),a();function a(){for(var c;(c=e.read())!==null;)n.push(c),i+=c.length;e.once("readable",a)}function o(c){e.removeListener("end",s),e.removeListener("readable",a),r(c)}function s(){var c=y.concat(n,i);n=[],r(null,c),e.close()}}function et(e,t){if(typeof t=="string"&&(t=new y(t)),!y.isBuffer(t))throw new TypeError("Not a string or buffer");var r=m.Z_FINISH;return e._processChunk(t,r)}function tt(e){if(!(this instanceof tt))return new tt(e);j.call(this,e,m.DEFLATE)}function rt(e){if(!(this instanceof rt))return new rt(e);j.call(this,e,m.INFLATE)}function nt(e){if(!(this instanceof nt))return new nt(e);j.call(this,e,m.GZIP)}function it(e){if(!(this instanceof it))return new it(e);j.call(this,e,m.GUNZIP)}function at(e){if(!(this instanceof at))return new at(e);j.call(this,e,m.DEFLATERAW)}function ot(e){if(!(this instanceof ot))return new ot(e);j.call(this,e,m.INFLATERAW)}function st(e){if(!(this instanceof st))return new st(e);j.call(this,e,m.UNZIP)}function j(e,t){if(this._opts=e=e||{},this._chunkSize=e.chunkSize||m.Z_DEFAULT_CHUNK,re.call(this,e),e.flush&&e.flush!==m.Z_NO_FLUSH&&e.flush!==m.Z_PARTIAL_FLUSH&&e.flush!==m.Z_SYNC_FLUSH&&e.flush!==m.Z_FULL_FLUSH&&e.flush!==m.Z_FINISH&&e.flush!==m.Z_BLOCK)throw new Error("Invalid flush flag: "+e.flush);if(this._flushFlag=e.flush||m.Z_NO_FLUSH,e.chunkSize&&(e.chunkSize<m.Z_MIN_CHUNK||e.chunkSize>m.Z_MAX_CHUNK))throw new Error("Invalid chunk size: "+e.chunkSize);if(e.windowBits&&(e.windowBits<m.Z_MIN_WINDOWBITS||e.windowBits>m.Z_MAX_WINDOWBITS))throw new Error("Invalid windowBits: "+e.windowBits);if(e.level&&(e.level<m.Z_MIN_LEVEL||e.level>m.Z_MAX_LEVEL))throw new Error("Invalid compression level: "+e.level);if(e.memLevel&&(e.memLevel<m.Z_MIN_MEMLEVEL||e.memLevel>m.Z_MAX_MEMLEVEL))throw new Error("Invalid memLevel: "+e.memLevel);if(e.strategy&&e.strategy!=m.Z_FILTERED&&e.strategy!=m.Z_HUFFMAN_ONLY&&e.strategy!=m.Z_RLE&&e.strategy!=m.Z_FIXED&&e.strategy!=m.Z_DEFAULT_STRATEGY)throw new Error("Invalid strategy: "+e.strategy);if(e.dictionary&&!y.isBuffer(e.dictionary))throw new Error("Invalid dictionary: it should be a Buffer instance");this._binding=new m.Zlib(t);var r=this;this._hadError=!1,this._binding.onerror=function(a,o){r._binding=null,r._hadError=!0;var s=new Error(a);s.errno=o,s.code=Vt[o],r.emit("error",s)};var n=m.Z_DEFAULT_COMPRESSION;typeof e.level=="number"&&(n=e.level);var i=m.Z_DEFAULT_STRATEGY;typeof e.strategy=="number"&&(i=e.strategy),this._binding.init(e.windowBits||m.Z_DEFAULT_WINDOWBITS,n,e.memLevel||m.Z_DEFAULT_MEMLEVEL,i,e.dictionary),this._buffer=new y(this._chunkSize),this._offset=0,this._closed=!1,this._level=n,this._strategy=i,this.once("end",this.close)}W(j,re),j.prototype.params=function(e,t,r){if(e<m.Z_MIN_LEVEL||e>m.Z_MAX_LEVEL)throw new RangeError("Invalid compression level: "+e);if(t!=m.Z_FILTERED&&t!=m.Z_HUFFMAN_ONLY&&t!=m.Z_RLE&&t!=m.Z_FIXED&&t!=m.Z_DEFAULT_STRATEGY)throw new TypeError("Invalid strategy: "+t);if(this._level!==e||this._strategy!==t){var n=this;this.flush(m.Z_SYNC_FLUSH,function(){n._binding.params(e,t),n._hadError||(n._level=e,n._strategy=t,r&&r())})}else xe.nextTick(r)},j.prototype.reset=function(){return this._binding.reset()},j.prototype._flush=function(e){this._transform(new y(0),"",e)},j.prototype.flush=function(e,t){var r=this._writableState;if((typeof e=="function"||e===void 0&&!t)&&(t=e,e=m.Z_FULL_FLUSH),r.ended)t&&xe.nextTick(t);else if(r.ending)t&&this.once("end",t);else if(r.needDrain){var n=this;this.once("drain",function(){n.flush(t)})}else this._flushFlag=e,this.write(new y(0),"",t)},j.prototype.close=function(e){if(e&&xe.nextTick(e),!this._closed){this._closed=!0,this._binding.close();var t=this;xe.nextTick(function(){t.emit("close")})}},j.prototype._transform=function(e,t,r){var n,i=this._writableState,a=i.ending||i.ended,o=a&&(!e||i.length===e.length);if(!e===null&&!y.isBuffer(e))return r(new Error("invalid input"));o?n=m.Z_FINISH:(n=this._flushFlag,e.length>=i.length&&(this._flushFlag=this._opts.flush||m.Z_NO_FLUSH)),this._processChunk(e,n,r)},j.prototype._processChunk=function(e,t,r){var n=e&&e.length,i=this._chunkSize-this._offset,a=0,o=this,s=typeof r=="function";if(!s){var c=[],f=0,l;this.on("error",function(v){l=v});do var d=this._binding.writeSync(t,e,a,n,this._buffer,this._offset,i);while(!this._hadError&&p(d[0],d[1]));if(this._hadError)throw l;var h=y.concat(c,f);return this.close(),h}var u=this._binding.write(t,e,a,n,this._buffer,this._offset,i);u.buffer=e,u.callback=p;function p(v,_){if(!o._hadError){var w=i-_;if(Ud(w>=0,"have should not go down"),w>0){var E=o._buffer.slice(o._offset,o._offset+w);o._offset+=w,s?o.push(E):(c.push(E),f+=E.length)}if((_===0||o._offset>=o._chunkSize)&&(i=o._chunkSize,o._offset=0,o._buffer=new y(o._chunkSize)),_===0){if(a+=n-v,n=v,!s)return!0;var S=o._binding.write(t,e,a,n,o._buffer,o._offset,o._chunkSize);S.callback=p,S.buffer=e;return}if(!s)return!1;r()}}},W(tt,j),W(rt,j),W(nt,j),W(it,j),W(at,j),W(ot,j),W(st,j);var Tf={codes:Vt,createDeflate:$d,createInflate:zd,createDeflateRaw:Zd,createInflateRaw:Hd,createGzip:qd,createGunzip:Kd,createUnzip:Wd,deflate:Vd,deflateSync:Gd,gzip:Yd,gzipSync:Jd,deflateRaw:Xd,deflateRawSync:Qd,unzip:ep,unzipSync:tp,inflate:rp,inflateSync:np,gunzip:ip,gunzipSync:ap,inflateRaw:op,inflateRawSync:sp,Deflate:tt,Inflate:rt,Gzip:nt,Gunzip:it,DeflateRaw:at,InflateRaw:ot,Unzip:st,Zlib:j};class If extends ui{constructor({client:t,keyPrefix:r="cache",ttl:n=0,prefix:i=void 0}){super({client:t,keyPrefix:r,ttl:n,prefix:i}),this.client=t,this.keyPrefix=r,this.config.ttl=n,this.config.client=t,this.config.prefix=i!==void 0?i:r+(r.endsWith("/")?"":"/")}async _set(t,r){let n=JSON.stringify(r);const i=n.length;return n=Tf.gzipSync(n).toString("base64"),this.client.putObject({key:we(this.keyPrefix,t),body:n,contentEncoding:"gzip",contentType:"application/gzip",metadata:{compressor:"zlib",compressed:"true","client-id":this.client.id,"length-serialized":String(i),"length-compressed":String(n.length),"compression-gain":(n.length/i).toFixed(2)}})}async _get(t){try{const{Body:r}=await this.client.getObject(we(this.keyPrefix,t));let n=await Pt(r);return n=Buffer.from(n,"base64"),n=Tf.unzipSync(n).toString(),JSON.parse(n)}catch(r){if(r.name==="NoSuchKey"||r.name==="NotFound")return null;throw r}}async _del(t){return await this.client.deleteObject(we(this.keyPrefix,t)),!0}async _clear(){const t=await this.client.getAllKeys({prefix:this.keyPrefix});for(const r of t)await this.client.deleteObject(r)}async size(){return(await this.keys()).length}async keys(){const t=await this.client.getAllKeys({prefix:this.keyPrefix}),r=this.keyPrefix.endsWith("/")?this.keyPrefix:this.keyPrefix+"/";return t.map(n=>n.startsWith(r)?n.slice(r.length):n)}}class Pf extends R{async setup(t){}async start(){}async stop(){}beforeSetup(){this.emit("plugin.beforeSetup",new Date)}afterSetup(){this.emit("plugin.afterSetup",new Date)}beforeStart(){this.emit("plugin.beforeStart",new Date)}afterStart(){this.emit("plugin.afterStart",new Date)}beforeStop(){this.emit("plugin.beforeStop",new Date)}afterStop(){this.emit("plugin.afterStop",new Date)}}const fp={setup(e){},start(){},stop(){}},cp={async setup(e){this.client=e.client,this.map={PutObjectCommand:"put",GetObjectCommand:"get",HeadObjectCommand:"get",DeleteObjectCommand:"delete",DeleteObjectsCommand:"delete",ListObjectsV2Command:"list"},this.costs={total:0,prices:{put:.005/1e3,copy:.005/1e3,list:.005/1e3,post:.005/1e3,get:4e-4/1e3,select:4e-4/1e3,delete:4e-4/1e3},requests:{total:0,put:0,post:0,copy:0,list:0,get:0,select:0,delete:0},events:{total:0,PutObjectCommand:0,GetObjectCommand:0,HeadObjectCommand:0,DeleteObjectCommand:0,DeleteObjectsCommand:0,ListObjectsV2Command:0}},this.client.costs=JSON.parse(JSON.stringify(this.costs))},async start(){this.client.on("command.response",e=>this.addRequest(e,this.map[e]))},addRequest(e,t){this.costs.events[e]++,this.costs.events.total++,this.costs.requests.total++,this.costs.requests[t]++,this.costs.total+=this.costs.prices[t],this.client.costs.events[e]++,this.client.costs.events.total++,this.client.costs.requests.total++,this.client.costs.requests[t]++,this.client.costs.total+=this.client.costs.prices[t]}};class lp extends Pf{constructor(t={}){super(),this.driver=t.driver}async setup(t){this.database=t,this.driver||(this.driver=new If({keyPrefix:"cache",client:t.client})),this.installDatabaseProxy();for(const r of Object.values(t.resources))this.installResourcesProxies(r)}async start(){}async stop(){}installDatabaseProxy(){const t=this.installResourcesProxies.bind(this);this.database._createResource=this.database.createResource,this.database.createResource=async function(...r){const n=await this._createResource(...r);return t(n),n}}installResourcesProxies(t){t.cache=this.driver;let r=`resource=${t.name}`;this.driver.keyPrefix&&(this.driver.keyPrefix=we(this.driver.keyPrefix,r)),t.cacheKeyFor=async function({params:n={},action:i="list"}){let a=Object.keys(n).sort().map(o=>`${o}:${n[o]}`).join("|")||"empty";return a=await na(a),a=we(r,`action=${i}`,`${a}.json.gz`),a},t._count=t.count,t._listIds=t.listIds,t._getMany=t.getMany,t._getAll=t.getAll,t._page=t.page,t.count=async function(){const n=await this.cacheKeyFor({action:"count"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._count();return await this.cache.set(n,i),i},t.listIds=async function(){const n=await this.cacheKeyFor({action:"listIds"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._listIds();return await this.cache.set(n,i),i},t.getMany=async function(n){const i=await this.cacheKeyFor({action:"getMany",params:{ids:n}});try{const o=await this.cache.get(i);if(o)return o}catch(o){if(o.name!=="NoSuchKey")throw o}const a=await t._getMany(n);return await this.cache.set(i,a),a},t.getAll=async function(){const n=await this.cacheKeyFor({action:"getAll"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._getAll();return await this.cache.set(n,i),i},t.page=async function({offset:n,size:i}){const a=await this.cacheKeyFor({action:"page",params:{offset:n,size:i}});try{const s=await this.cache.get(a);if(s)return s}catch(s){if(s.name!=="NoSuchKey")throw s}const o=await t._page({offset:n,size:i});return await this.cache.set(a,o),o},t._insert=t.insert,t._update=t.update,t._delete=t.delete,t._deleteMany=t.deleteMany,t.insert=async function(...n){const i=await t._insert(...n);return await this.cache.clear(r),i},t.update=async function(...n){const i=await t._update(...n);return await this.cache.clear(r),i},t.delete=async function(...n){const i=await t._delete(...n);return await this.cache.clear(r),i},t.deleteMany=async function(...n){const i=await t._deleteMany(...n);return await this.cache.clear(r),i}}}return I.BaseError=ut,I.Cache=ui,I.CachePlugin=lp,I.Client=ra,I.ConnectionString=ta,I.CostsPlugin=cp,I.Database=cs,I.ErrorMap=Xi,I.InvalidResourceItem=Xt,I.MemoryCache=rh,I.MissingMetadata=Yi,I.NoSuchBucket=Vi,I.NoSuchKey=$r,I.NotFound=Gi,I.Plugin=Pf,I.PluginObject=fp,I.ResourceIdsPageReader=es,I.ResourceIdsReader=Qo,I.ResourceReader=ts,I.ResourceWriter=rs,I.S3Cache=If,I.S3_DEFAULT_ENDPOINT=ea,I.S3_DEFAULT_REGION=Qi,I.S3db=th,I.UnknownError=Ji,I.Validator=fo,I.ValidatorManager=co,I.decrypt=ia,I.encrypt=zr,I.sha256=na,I.streamToString=Pt,I}({},nanoid,lodashEs,promisePool,clientS3,crypto,flat,FastestValidator,web);