@verdant-web/store 3.12.0 → 3.12.1

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.
@@ -3,7 +3,7 @@
3
3
  Use "options.replacer" or "options.ignoreUnknown"
4
4
  `)},_domwindow:function(){return m("domwindow")},_bigint:function(l){return m("bigint:"+l.toString())},_process:function(){return m("process")},_timer:function(){return m("timer")},_pipe:function(){return m("pipe")},_tcp:function(){return m("tcp")},_udp:function(){return m("udp")},_tty:function(){return m("tty")},_statwatcher:function(){return m("statwatcher")},_securecontext:function(){return m("securecontext")},_connection:function(){return m("connection")},_zlib:function(){return m("zlib")},_context:function(){return m("context")},_nodescript:function(){return m("nodescript")},_httpparser:function(){return m("httpparser")},_dataview:function(){return m("dataview")},_signal:function(){return m("signal")},_fsevent:function(){return m("fsevent")},_tlswrap:function(){return m("tlswrap")}}}function R(){return{buf:"",write:function(w){this.buf+=w},end:function(w){this.buf+=w},read:function(){return this.buf}}}e.writeToStream=function(w,D,f){return f===void 0&&(f=D,D={}),O(D=I(w,D),f).dispatch(w)}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_9a5aa49d.js","/")},{buffer:3,crypto:5,lYpoI2:11}],2:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){(function(y){"use strict";var E=typeof Uint8Array<"u"?Uint8Array:Array,g="+".charCodeAt(0),v="/".charCodeAt(0),I="0".charCodeAt(0),_="a".charCodeAt(0),O="A".charCodeAt(0),R="-".charCodeAt(0),w="_".charCodeAt(0);function D(f){return f=f.charCodeAt(0),f===g||f===R?62:f===v||f===w?63:f<I?-1:f<I+10?f-I+26+26:f<O+26?f-O:f<_+26?f-_+26:void 0}y.toByteArray=function(f){var m,l;if(0<f.length%4)throw new Error("Invalid string. Length must be a multiple of 4");var x=f.length,x=f.charAt(x-2)==="="?2:f.charAt(x-1)==="="?1:0,C=new E(3*f.length/4-x),j=0<x?f.length-4:f.length,B=0;function M(k){C[B++]=k}for(m=0;m<j;m+=4,0)M((16711680&(l=D(f.charAt(m))<<18|D(f.charAt(m+1))<<12|D(f.charAt(m+2))<<6|D(f.charAt(m+3))))>>16),M((65280&l)>>8),M(255&l);return x==2?M(255&(l=D(f.charAt(m))<<2|D(f.charAt(m+1))>>4)):x==1&&(M((l=D(f.charAt(m))<<10|D(f.charAt(m+1))<<4|D(f.charAt(m+2))>>2)>>8&255),M(255&l)),C},y.fromByteArray=function(f){var m,l,x,C,j=f.length%3,B="";function M(k){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(k)}for(m=0,x=f.length-j;m<x;m+=3)l=(f[m]<<16)+(f[m+1]<<8)+f[m+2],B+=M((C=l)>>18&63)+M(C>>12&63)+M(C>>6&63)+M(63&C);switch(j){case 1:B=(B+=M((l=f[f.length-1])>>2))+M(l<<4&63)+"==";break;case 2:B=(B=(B+=M((l=(f[f.length-2]<<8)+f[f.length-1])>>10))+M(l>>4&63))+M(l<<2&63)+"="}return B}})(e===void 0?this.base64js={}:e)}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js","/node_modules/gulp-browserify/node_modules/base64-js/lib")},{buffer:3,lYpoI2:11}],3:[function(n,i,e){(function(t,r,g,s,a,u,d,p,S){var y=n("base64-js"),E=n("ieee754");function g(c,h,b){if(!(this instanceof g))return new g(c,h,b);var A,P,T,V,W=typeof c;if(h==="base64"&&W=="string")for(c=(V=c).trim?V.trim():V.replace(/^\s+|\s+$/g,"");c.length%4!=0;)c+="=";if(W=="number")A=te(c);else if(W=="string")A=g.byteLength(c,h);else{if(W!="object")throw new Error("First argument needs to be a number, array or string.");A=te(c.length)}if(g._useTypedArrays?P=g._augment(new Uint8Array(A)):((P=this).length=A,P._isBuffer=!0),g._useTypedArrays&&typeof c.byteLength=="number")P._set(c);else if(H(V=c)||g.isBuffer(V)||V&&typeof V=="object"&&typeof V.length=="number")for(T=0;T<A;T++)g.isBuffer(c)?P[T]=c.readUInt8(T):P[T]=c[T];else if(W=="string")P.write(c,0,h);else if(W=="number"&&!g._useTypedArrays&&!b)for(T=0;T<A;T++)P[T]=0;return P}function v(c,h,b,A){return g._charsWritten=jt(function(P){for(var T=[],V=0;V<P.length;V++)T.push(255&P.charCodeAt(V));return T}(h),c,b,A)}function I(c,h,b,A){return g._charsWritten=jt(function(P){for(var T,V,W=[],X=0;X<P.length;X++)V=P.charCodeAt(X),T=V>>8,V=V%256,W.push(V),W.push(T);return W}(h),c,b,A)}function _(c,h,b){var A="";b=Math.min(c.length,b);for(var P=h;P<b;P++)A+=String.fromCharCode(c[P]);return A}function O(c,h,b,T){T||(F(typeof b=="boolean","missing or invalid endian"),F(h!=null,"missing offset"),F(h+1<c.length,"Trying to read beyond buffer length"));var P,T=c.length;if(!(T<=h))return b?(P=c[h],h+1<T&&(P|=c[h+1]<<8)):(P=c[h]<<8,h+1<T&&(P|=c[h+1])),P}function R(c,h,b,T){T||(F(typeof b=="boolean","missing or invalid endian"),F(h!=null,"missing offset"),F(h+3<c.length,"Trying to read beyond buffer length"));var P,T=c.length;if(!(T<=h))return b?(h+2<T&&(P=c[h+2]<<16),h+1<T&&(P|=c[h+1]<<8),P|=c[h],h+3<T&&(P+=c[h+3]<<24>>>0)):(h+1<T&&(P=c[h+1]<<16),h+2<T&&(P|=c[h+2]<<8),h+3<T&&(P|=c[h+3]),P+=c[h]<<24>>>0),P}function w(c,h,b,A){if(A||(F(typeof b=="boolean","missing or invalid endian"),F(h!=null,"missing offset"),F(h+1<c.length,"Trying to read beyond buffer length")),!(c.length<=h))return A=O(c,h,b,!0),32768&A?-1*(65535-A+1):A}function D(c,h,b,A){if(A||(F(typeof b=="boolean","missing or invalid endian"),F(h!=null,"missing offset"),F(h+3<c.length,"Trying to read beyond buffer length")),!(c.length<=h))return A=R(c,h,b,!0),2147483648&A?-1*(4294967295-A+1):A}function f(c,h,b,A){return A||(F(typeof b=="boolean","missing or invalid endian"),F(h+3<c.length,"Trying to read beyond buffer length")),E.read(c,h,b,23,4)}function m(c,h,b,A){return A||(F(typeof b=="boolean","missing or invalid endian"),F(h+7<c.length,"Trying to read beyond buffer length")),E.read(c,h,b,52,8)}function l(c,h,b,A,P){if(P||(F(h!=null,"missing value"),F(typeof A=="boolean","missing or invalid endian"),F(b!=null,"missing offset"),F(b+1<c.length,"trying to write beyond buffer length"),ni(h,65535)),P=c.length,!(P<=b))for(var T=0,V=Math.min(P-b,2);T<V;T++)c[b+T]=(h&255<<8*(A?T:1-T))>>>8*(A?T:1-T)}function x(c,h,b,A,P){if(P||(F(h!=null,"missing value"),F(typeof A=="boolean","missing or invalid endian"),F(b!=null,"missing offset"),F(b+3<c.length,"trying to write beyond buffer length"),ni(h,4294967295)),P=c.length,!(P<=b))for(var T=0,V=Math.min(P-b,4);T<V;T++)c[b+T]=h>>>8*(A?T:3-T)&255}function C(c,h,b,A,P){P||(F(h!=null,"missing value"),F(typeof A=="boolean","missing or invalid endian"),F(b!=null,"missing offset"),F(b+1<c.length,"Trying to write beyond buffer length"),ii(h,32767,-32768)),c.length<=b||l(c,0<=h?h:65535+h+1,b,A,P)}function j(c,h,b,A,P){P||(F(h!=null,"missing value"),F(typeof A=="boolean","missing or invalid endian"),F(b!=null,"missing offset"),F(b+3<c.length,"Trying to write beyond buffer length"),ii(h,2147483647,-2147483648)),c.length<=b||x(c,0<=h?h:4294967295+h+1,b,A,P)}function B(c,h,b,A,P){P||(F(h!=null,"missing value"),F(typeof A=="boolean","missing or invalid endian"),F(b!=null,"missing offset"),F(b+3<c.length,"Trying to write beyond buffer length"),lr(h,34028234663852886e22,-34028234663852886e22)),c.length<=b||E.write(c,h,b,A,23,4)}function M(c,h,b,A,P){P||(F(h!=null,"missing value"),F(typeof A=="boolean","missing or invalid endian"),F(b!=null,"missing offset"),F(b+7<c.length,"Trying to write beyond buffer length"),lr(h,17976931348623157e292,-17976931348623157e292)),c.length<=b||E.write(c,h,b,A,52,8)}e.Buffer=g,e.SlowBuffer=g,e.INSPECT_MAX_BYTES=50,g.poolSize=8192,g._useTypedArrays=function(){try{var c=new ArrayBuffer(0),h=new Uint8Array(c);return h.foo=function(){return 42},h.foo()===42&&typeof h.subarray=="function"}catch{return!1}}(),g.isEncoding=function(c){switch(String(c).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},g.isBuffer=function(c){return!(c==null||!c._isBuffer)},g.byteLength=function(c,h){var b;switch(c+="",h||"utf8"){case"hex":b=c.length/2;break;case"utf8":case"utf-8":b=Ee(c).length;break;case"ascii":case"binary":case"raw":b=c.length;break;case"base64":b=ar(c).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":b=2*c.length;break;default:throw new Error("Unknown encoding")}return b},g.concat=function(c,h){if(F(H(c),`Usage: Buffer.concat(list, [totalLength])
5
5
  list should be an Array.`),c.length===0)return new g(0);if(c.length===1)return c[0];if(typeof h!="number")for(P=h=0;P<c.length;P++)h+=c[P].length;for(var b=new g(h),A=0,P=0;P<c.length;P++){var T=c[P];T.copy(b,A),A+=T.length}return b},g.prototype.write=function(c,h,b,A){isFinite(h)?isFinite(b)||(A=b,b=void 0):(X=A,A=h,h=b,b=X),h=Number(h)||0;var P,T,V,W,X=this.length-h;switch((!b||X<(b=Number(b)))&&(b=X),A=String(A||"utf8").toLowerCase()){case"hex":P=function(be,ie,re,Z){re=Number(re)||0;var G=be.length-re;(!Z||G<(Z=Number(Z)))&&(Z=G),F((G=ie.length)%2==0,"Invalid hex string"),G/2<Z&&(Z=G/2);for(var Ze=0;Ze<Z;Ze++){var dr=parseInt(ie.substr(2*Ze,2),16);F(!isNaN(dr),"Invalid hex string"),be[re+Ze]=dr}return g._charsWritten=2*Ze,Ze}(this,c,h,b);break;case"utf8":case"utf-8":T=this,V=h,W=b,P=g._charsWritten=jt(Ee(c),T,V,W);break;case"ascii":case"binary":P=v(this,c,h,b);break;case"base64":T=this,V=h,W=b,P=g._charsWritten=jt(ar(c),T,V,W);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":P=I(this,c,h,b);break;default:throw new Error("Unknown encoding")}return P},g.prototype.toString=function(c,h,b){var A,P,T,V,W=this;if(c=String(c||"utf8").toLowerCase(),h=Number(h)||0,(b=b!==void 0?Number(b):W.length)===h)return"";switch(c){case"hex":A=function(X,be,ie){var re=X.length;(!be||be<0)&&(be=0),(!ie||ie<0||re<ie)&&(ie=re);for(var Z="",G=be;G<ie;G++)Z+=K(X[G]);return Z}(W,h,b);break;case"utf8":case"utf-8":A=function(X,be,ie){var re="",Z="";ie=Math.min(X.length,ie);for(var G=be;G<ie;G++)X[G]<=127?(re+=cr(Z)+String.fromCharCode(X[G]),Z=""):Z+="%"+X[G].toString(16);return re+cr(Z)}(W,h,b);break;case"ascii":case"binary":A=_(W,h,b);break;case"base64":P=W,V=b,A=(T=h)===0&&V===P.length?y.fromByteArray(P):y.fromByteArray(P.slice(T,V));break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":A=function(X,be,ie){for(var re=X.slice(be,ie),Z="",G=0;G<re.length;G+=2)Z+=String.fromCharCode(re[G]+256*re[G+1]);return Z}(W,h,b);break;default:throw new Error("Unknown encoding")}return A},g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},g.prototype.copy=function(c,h,b,A){if(h=h||0,(A=A||A===0?A:this.length)!==(b=b||0)&&c.length!==0&&this.length!==0){F(b<=A,"sourceEnd < sourceStart"),F(0<=h&&h<c.length,"targetStart out of bounds"),F(0<=b&&b<this.length,"sourceStart out of bounds"),F(0<=A&&A<=this.length,"sourceEnd out of bounds"),A>this.length&&(A=this.length);var P=(A=c.length-h<A-b?c.length-h+b:A)-b;if(P<100||!g._useTypedArrays)for(var T=0;T<P;T++)c[T+h]=this[T+b];else c._set(this.subarray(b,b+P),h)}},g.prototype.slice=function(c,h){var b=this.length;if(c=q(c,b,0),h=q(h,b,b),g._useTypedArrays)return g._augment(this.subarray(c,h));for(var A=h-c,P=new g(A,void 0,!0),T=0;T<A;T++)P[T]=this[T+c];return P},g.prototype.get=function(c){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(c)},g.prototype.set=function(c,h){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(c,h)},g.prototype.readUInt8=function(c,h){if(h||(F(c!=null,"missing offset"),F(c<this.length,"Trying to read beyond buffer length")),!(c>=this.length))return this[c]},g.prototype.readUInt16LE=function(c,h){return O(this,c,!0,h)},g.prototype.readUInt16BE=function(c,h){return O(this,c,!1,h)},g.prototype.readUInt32LE=function(c,h){return R(this,c,!0,h)},g.prototype.readUInt32BE=function(c,h){return R(this,c,!1,h)},g.prototype.readInt8=function(c,h){if(h||(F(c!=null,"missing offset"),F(c<this.length,"Trying to read beyond buffer length")),!(c>=this.length))return 128&this[c]?-1*(255-this[c]+1):this[c]},g.prototype.readInt16LE=function(c,h){return w(this,c,!0,h)},g.prototype.readInt16BE=function(c,h){return w(this,c,!1,h)},g.prototype.readInt32LE=function(c,h){return D(this,c,!0,h)},g.prototype.readInt32BE=function(c,h){return D(this,c,!1,h)},g.prototype.readFloatLE=function(c,h){return f(this,c,!0,h)},g.prototype.readFloatBE=function(c,h){return f(this,c,!1,h)},g.prototype.readDoubleLE=function(c,h){return m(this,c,!0,h)},g.prototype.readDoubleBE=function(c,h){return m(this,c,!1,h)},g.prototype.writeUInt8=function(c,h,b){b||(F(c!=null,"missing value"),F(h!=null,"missing offset"),F(h<this.length,"trying to write beyond buffer length"),ni(c,255)),h>=this.length||(this[h]=c)},g.prototype.writeUInt16LE=function(c,h,b){l(this,c,h,!0,b)},g.prototype.writeUInt16BE=function(c,h,b){l(this,c,h,!1,b)},g.prototype.writeUInt32LE=function(c,h,b){x(this,c,h,!0,b)},g.prototype.writeUInt32BE=function(c,h,b){x(this,c,h,!1,b)},g.prototype.writeInt8=function(c,h,b){b||(F(c!=null,"missing value"),F(h!=null,"missing offset"),F(h<this.length,"Trying to write beyond buffer length"),ii(c,127,-128)),h>=this.length||(0<=c?this.writeUInt8(c,h,b):this.writeUInt8(255+c+1,h,b))},g.prototype.writeInt16LE=function(c,h,b){C(this,c,h,!0,b)},g.prototype.writeInt16BE=function(c,h,b){C(this,c,h,!1,b)},g.prototype.writeInt32LE=function(c,h,b){j(this,c,h,!0,b)},g.prototype.writeInt32BE=function(c,h,b){j(this,c,h,!1,b)},g.prototype.writeFloatLE=function(c,h,b){B(this,c,h,!0,b)},g.prototype.writeFloatBE=function(c,h,b){B(this,c,h,!1,b)},g.prototype.writeDoubleLE=function(c,h,b){M(this,c,h,!0,b)},g.prototype.writeDoubleBE=function(c,h,b){M(this,c,h,!1,b)},g.prototype.fill=function(c,h,b){if(h=h||0,b=b||this.length,F(typeof(c=typeof(c=c||0)=="string"?c.charCodeAt(0):c)=="number"&&!isNaN(c),"value is not a number"),F(h<=b,"end < start"),b!==h&&this.length!==0){F(0<=h&&h<this.length,"start out of bounds"),F(0<=b&&b<=this.length,"end out of bounds");for(var A=h;A<b;A++)this[A]=c}},g.prototype.inspect=function(){for(var c=[],h=this.length,b=0;b<h;b++)if(c[b]=K(this[b]),b===e.INSPECT_MAX_BYTES){c[b+1]="...";break}return"<Buffer "+c.join(" ")+">"},g.prototype.toArrayBuffer=function(){if(typeof Uint8Array>"u")throw new Error("Buffer.toArrayBuffer not supported in this browser");if(g._useTypedArrays)return new g(this).buffer;for(var c=new Uint8Array(this.length),h=0,b=c.length;h<b;h+=1)c[h]=this[h];return c.buffer};var k=g.prototype;function q(c,h,b){return typeof c!="number"?b:h<=(c=~~c)?h:0<=c||0<=(c+=h)?c:0}function te(c){return(c=~~Math.ceil(+c))<0?0:c}function H(c){return(Array.isArray||function(h){return Object.prototype.toString.call(h)==="[object Array]"})(c)}function K(c){return c<16?"0"+c.toString(16):c.toString(16)}function Ee(c){for(var h=[],b=0;b<c.length;b++){var A=c.charCodeAt(b);if(A<=127)h.push(c.charCodeAt(b));else for(var P=b,T=(55296<=A&&A<=57343&&b++,encodeURIComponent(c.slice(P,b+1)).substr(1).split("%")),V=0;V<T.length;V++)h.push(parseInt(T[V],16))}return h}function ar(c){return y.toByteArray(c)}function jt(c,h,b,A){for(var P=0;P<A&&!(P+b>=h.length||P>=c.length);P++)h[P+b]=c[P];return P}function cr(c){try{return decodeURIComponent(c)}catch{return String.fromCharCode(65533)}}function ni(c,h){F(typeof c=="number","cannot write a non-number as a number"),F(0<=c,"specified a negative value for writing an unsigned value"),F(c<=h,"value is larger than maximum value for type"),F(Math.floor(c)===c,"value has a fractional component")}function ii(c,h,b){F(typeof c=="number","cannot write a non-number as a number"),F(c<=h,"value larger than maximum allowed value"),F(b<=c,"value smaller than minimum allowed value"),F(Math.floor(c)===c,"value has a fractional component")}function lr(c,h,b){F(typeof c=="number","cannot write a non-number as a number"),F(c<=h,"value larger than maximum allowed value"),F(b<=c,"value smaller than minimum allowed value")}function F(c,h){if(!c)throw new Error(h||"Failed assertion")}g._augment=function(c){return c._isBuffer=!0,c._get=c.get,c._set=c.set,c.get=k.get,c.set=k.set,c.write=k.write,c.toString=k.toString,c.toLocaleString=k.toString,c.toJSON=k.toJSON,c.copy=k.copy,c.slice=k.slice,c.readUInt8=k.readUInt8,c.readUInt16LE=k.readUInt16LE,c.readUInt16BE=k.readUInt16BE,c.readUInt32LE=k.readUInt32LE,c.readUInt32BE=k.readUInt32BE,c.readInt8=k.readInt8,c.readInt16LE=k.readInt16LE,c.readInt16BE=k.readInt16BE,c.readInt32LE=k.readInt32LE,c.readInt32BE=k.readInt32BE,c.readFloatLE=k.readFloatLE,c.readFloatBE=k.readFloatBE,c.readDoubleLE=k.readDoubleLE,c.readDoubleBE=k.readDoubleBE,c.writeUInt8=k.writeUInt8,c.writeUInt16LE=k.writeUInt16LE,c.writeUInt16BE=k.writeUInt16BE,c.writeUInt32LE=k.writeUInt32LE,c.writeUInt32BE=k.writeUInt32BE,c.writeInt8=k.writeInt8,c.writeInt16LE=k.writeInt16LE,c.writeInt16BE=k.writeInt16BE,c.writeInt32LE=k.writeInt32LE,c.writeInt32BE=k.writeInt32BE,c.writeFloatLE=k.writeFloatLE,c.writeFloatBE=k.writeFloatBE,c.writeDoubleLE=k.writeDoubleLE,c.writeDoubleBE=k.writeDoubleBE,c.fill=k.fill,c.inspect=k.inspect,c.toArrayBuffer=k.toArrayBuffer,c}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/buffer/index.js","/node_modules/gulp-browserify/node_modules/buffer")},{"base64-js":2,buffer:3,ieee754:10,lYpoI2:11}],4:[function(n,i,e){(function(t,r,y,s,a,u,d,p,S){var y=n("buffer").Buffer,E=4,g=new y(E);g.fill(0),i.exports={hash:function(v,I,_,O){for(var R=I(function(l,x){l.length%E!=0&&(C=l.length+(E-l.length%E),l=y.concat([l,g],C));for(var C,j=[],B=x?l.readInt32BE:l.readInt32LE,M=0;M<l.length;M+=E)j.push(B.call(l,M));return j}(v=y.isBuffer(v)?v:new y(v),O),8*v.length),I=O,w=new y(_),D=I?w.writeInt32BE:w.writeInt32LE,f=0;f<R.length;f++)D.call(w,R[f],4*f,!0);return w}}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/helpers.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:11}],5:[function(n,i,e){(function(t,r,y,s,a,u,d,p,S){var y=n("buffer").Buffer,E=n("./sha"),g=n("./sha256"),v=n("./rng"),I={sha1:E,sha256:g,md5:n("./md5")},_=64,O=new y(_);function R(l,x){var C=I[l=l||"sha1"],j=[];return C||w("algorithm:",l,"is not yet supported"),{update:function(B){return y.isBuffer(B)||(B=new y(B)),j.push(B),B.length,this},digest:function(B){var M=y.concat(j),M=x?function(k,q,te){y.isBuffer(q)||(q=new y(q)),y.isBuffer(te)||(te=new y(te)),q.length>_?q=k(q):q.length<_&&(q=y.concat([q,O],_));for(var H=new y(_),K=new y(_),Ee=0;Ee<_;Ee++)H[Ee]=54^q[Ee],K[Ee]=92^q[Ee];return te=k(y.concat([H,te])),k(y.concat([K,te]))}(C,x,M):C(M);return j=null,B?M.toString(B):M}}}function w(){var l=[].slice.call(arguments).join(" ");throw new Error([l,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join(`
6
- `))}O.fill(0),e.createHash=function(l){return R(l)},e.createHmac=R,e.randomBytes=function(l,x){if(!x||!x.call)return new y(v(l));try{x.call(this,void 0,new y(v(l)))}catch(C){x(C)}};var D,f=["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],m=function(l){e[l]=function(){w("sorry,",l,"is not implemented yet")}};for(D in f)m(f[D],D)}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./md5":6,"./rng":7,"./sha":8,"./sha256":9,buffer:3,lYpoI2:11}],6:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){var y=n("./helpers");function E(w,D){w[D>>5]|=128<<D%32,w[14+(D+64>>>9<<4)]=D;for(var f=1732584193,m=-271733879,l=-1732584194,x=271733878,C=0;C<w.length;C+=16){var j=f,B=m,M=l,k=x,f=v(f,m,l,x,w[C+0],7,-680876936),x=v(x,f,m,l,w[C+1],12,-389564586),l=v(l,x,f,m,w[C+2],17,606105819),m=v(m,l,x,f,w[C+3],22,-1044525330);f=v(f,m,l,x,w[C+4],7,-176418897),x=v(x,f,m,l,w[C+5],12,1200080426),l=v(l,x,f,m,w[C+6],17,-1473231341),m=v(m,l,x,f,w[C+7],22,-45705983),f=v(f,m,l,x,w[C+8],7,1770035416),x=v(x,f,m,l,w[C+9],12,-1958414417),l=v(l,x,f,m,w[C+10],17,-42063),m=v(m,l,x,f,w[C+11],22,-1990404162),f=v(f,m,l,x,w[C+12],7,1804603682),x=v(x,f,m,l,w[C+13],12,-40341101),l=v(l,x,f,m,w[C+14],17,-1502002290),f=I(f,m=v(m,l,x,f,w[C+15],22,1236535329),l,x,w[C+1],5,-165796510),x=I(x,f,m,l,w[C+6],9,-1069501632),l=I(l,x,f,m,w[C+11],14,643717713),m=I(m,l,x,f,w[C+0],20,-373897302),f=I(f,m,l,x,w[C+5],5,-701558691),x=I(x,f,m,l,w[C+10],9,38016083),l=I(l,x,f,m,w[C+15],14,-660478335),m=I(m,l,x,f,w[C+4],20,-405537848),f=I(f,m,l,x,w[C+9],5,568446438),x=I(x,f,m,l,w[C+14],9,-1019803690),l=I(l,x,f,m,w[C+3],14,-187363961),m=I(m,l,x,f,w[C+8],20,1163531501),f=I(f,m,l,x,w[C+13],5,-1444681467),x=I(x,f,m,l,w[C+2],9,-51403784),l=I(l,x,f,m,w[C+7],14,1735328473),f=_(f,m=I(m,l,x,f,w[C+12],20,-1926607734),l,x,w[C+5],4,-378558),x=_(x,f,m,l,w[C+8],11,-2022574463),l=_(l,x,f,m,w[C+11],16,1839030562),m=_(m,l,x,f,w[C+14],23,-35309556),f=_(f,m,l,x,w[C+1],4,-1530992060),x=_(x,f,m,l,w[C+4],11,1272893353),l=_(l,x,f,m,w[C+7],16,-155497632),m=_(m,l,x,f,w[C+10],23,-1094730640),f=_(f,m,l,x,w[C+13],4,681279174),x=_(x,f,m,l,w[C+0],11,-358537222),l=_(l,x,f,m,w[C+3],16,-722521979),m=_(m,l,x,f,w[C+6],23,76029189),f=_(f,m,l,x,w[C+9],4,-640364487),x=_(x,f,m,l,w[C+12],11,-421815835),l=_(l,x,f,m,w[C+15],16,530742520),f=O(f,m=_(m,l,x,f,w[C+2],23,-995338651),l,x,w[C+0],6,-198630844),x=O(x,f,m,l,w[C+7],10,1126891415),l=O(l,x,f,m,w[C+14],15,-1416354905),m=O(m,l,x,f,w[C+5],21,-57434055),f=O(f,m,l,x,w[C+12],6,1700485571),x=O(x,f,m,l,w[C+3],10,-1894986606),l=O(l,x,f,m,w[C+10],15,-1051523),m=O(m,l,x,f,w[C+1],21,-2054922799),f=O(f,m,l,x,w[C+8],6,1873313359),x=O(x,f,m,l,w[C+15],10,-30611744),l=O(l,x,f,m,w[C+6],15,-1560198380),m=O(m,l,x,f,w[C+13],21,1309151649),f=O(f,m,l,x,w[C+4],6,-145523070),x=O(x,f,m,l,w[C+11],10,-1120210379),l=O(l,x,f,m,w[C+2],15,718787259),m=O(m,l,x,f,w[C+9],21,-343485551),f=R(f,j),m=R(m,B),l=R(l,M),x=R(x,k)}return Array(f,m,l,x)}function g(w,D,f,m,l,x){return R((D=R(R(D,w),R(m,x)))<<l|D>>>32-l,f)}function v(w,D,f,m,l,x,C){return g(D&f|~D&m,w,D,l,x,C)}function I(w,D,f,m,l,x,C){return g(D&m|f&~m,w,D,l,x,C)}function _(w,D,f,m,l,x,C){return g(D^f^m,w,D,l,x,C)}function O(w,D,f,m,l,x,C){return g(f^(D|~m),w,D,l,x,C)}function R(w,D){var f=(65535&w)+(65535&D);return(w>>16)+(D>>16)+(f>>16)<<16|65535&f}i.exports=function(w){return y.hash(w,E,16)}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:11}],7:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){var y;i.exports=y||function(E){for(var g,v=new Array(E),I=0;I<E;I++)!(3&I)&&(g=4294967296*Math.random()),v[I]=g>>>((3&I)<<3)&255;return v}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:11}],8:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){var y=n("./helpers");function E(I,_){I[_>>5]|=128<<24-_%32,I[15+(_+64>>9<<4)]=_;for(var O,R,w,D=Array(80),f=1732584193,m=-271733879,l=-1732584194,x=271733878,C=-1009589776,j=0;j<I.length;j+=16){for(var B=f,M=m,k=l,q=x,te=C,H=0;H<80;H++){D[H]=H<16?I[j+H]:v(D[H-3]^D[H-8]^D[H-14]^D[H-16],1);var K=g(g(v(f,5),(K=m,R=l,w=x,(O=H)<20?K&R|~K&w:!(O<40)&&O<60?K&R|K&w|R&w:K^R^w)),g(g(C,D[H]),(O=H)<20?1518500249:O<40?1859775393:O<60?-1894007588:-899497514)),C=x,x=l,l=v(m,30),m=f,f=K}f=g(f,B),m=g(m,M),l=g(l,k),x=g(x,q),C=g(C,te)}return Array(f,m,l,x,C)}function g(I,_){var O=(65535&I)+(65535&_);return(I>>16)+(_>>16)+(O>>16)<<16|65535&O}function v(I,_){return I<<_|I>>>32-_}i.exports=function(I){return y.hash(I,E,20,!0)}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:11}],9:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){function y(_,O){var R=(65535&_)+(65535&O);return(_>>16)+(O>>16)+(R>>16)<<16|65535&R}function E(_,O){var R,w=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),D=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),f=new Array(64);_[O>>5]|=128<<24-O%32,_[15+(O+64>>9<<4)]=O;for(var m,l,x=0;x<_.length;x+=16){for(var C=D[0],j=D[1],B=D[2],M=D[3],k=D[4],q=D[5],te=D[6],H=D[7],K=0;K<64;K++)f[K]=K<16?_[K+x]:y(y(y((l=f[K-2],v(l,17)^v(l,19)^I(l,10)),f[K-7]),(l=f[K-15],v(l,7)^v(l,18)^I(l,3))),f[K-16]),R=y(y(y(y(H,v(l=k,6)^v(l,11)^v(l,25)),k&q^~k&te),w[K]),f[K]),m=y(v(m=C,2)^v(m,13)^v(m,22),C&j^C&B^j&B),H=te,te=q,q=k,k=y(M,R),M=B,B=j,j=C,C=y(R,m);D[0]=y(C,D[0]),D[1]=y(j,D[1]),D[2]=y(B,D[2]),D[3]=y(M,D[3]),D[4]=y(k,D[4]),D[5]=y(q,D[5]),D[6]=y(te,D[6]),D[7]=y(H,D[7])}return D}var g=n("./helpers"),v=function(_,O){return _>>>O|_<<32-O},I=function(_,O){return _>>>O};i.exports=function(_){return g.hash(_,E,32,!0)}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:11}],10:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){e.read=function(y,E,g,v,x){var _,O,R=8*x-v-1,w=(1<<R)-1,D=w>>1,f=-7,m=g?x-1:0,l=g?-1:1,x=y[E+m];for(m+=l,_=x&(1<<-f)-1,x>>=-f,f+=R;0<f;_=256*_+y[E+m],m+=l,f-=8);for(O=_&(1<<-f)-1,_>>=-f,f+=v;0<f;O=256*O+y[E+m],m+=l,f-=8);if(_===0)_=1-D;else{if(_===w)return O?NaN:1/0*(x?-1:1);O+=Math.pow(2,v),_-=D}return(x?-1:1)*O*Math.pow(2,_-v)},e.write=function(y,E,g,v,I,C){var O,R,w=8*C-I-1,D=(1<<w)-1,f=D>>1,m=I===23?Math.pow(2,-24)-Math.pow(2,-77):0,l=v?0:C-1,x=v?1:-1,C=E<0||E===0&&1/E<0?1:0;for(E=Math.abs(E),isNaN(E)||E===1/0?(R=isNaN(E)?1:0,O=D):(O=Math.floor(Math.log(E)/Math.LN2),E*(v=Math.pow(2,-O))<1&&(O--,v*=2),2<=(E+=1<=O+f?m/v:m*Math.pow(2,1-f))*v&&(O++,v/=2),D<=O+f?(R=0,O=D):1<=O+f?(R=(E*v-1)*Math.pow(2,I),O+=f):(R=E*Math.pow(2,f-1)*Math.pow(2,I),O=0));8<=I;y[g+l]=255&R,l+=x,R/=256,I-=8);for(O=O<<I|R,w+=I;0<w;y[g+l]=255&O,l+=x,O/=256,w-=8);y[g+l-x]|=128*C}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/ieee754/index.js","/node_modules/gulp-browserify/node_modules/ieee754")},{buffer:3,lYpoI2:11}],11:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){var y,E,g;function v(){}(t=i.exports={}).nextTick=(E=typeof window<"u"&&window.setImmediate,g=typeof window<"u"&&window.postMessage&&window.addEventListener,E?function(I){return window.setImmediate(I)}:g?(y=[],window.addEventListener("message",function(I){var _=I.source;_!==window&&_!==null||I.data!=="process-tick"||(I.stopPropagation(),0<y.length&&y.shift()())},!0),function(I){y.push(I),window.postMessage("process-tick","*")}):function(I){setTimeout(I,0)}),t.title="browser",t.browser=!0,t.env={},t.argv=[],t.on=v,t.addListener=v,t.once=v,t.off=v,t.removeListener=v,t.removeAllListeners=v,t.emit=v,t.binding=function(I){throw new Error("process.binding is not supported")},t.cwd=function(){return"/"},t.chdir=function(I){throw new Error("process.chdir is not supported")}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/process/browser.js","/node_modules/gulp-browserify/node_modules/process")},{buffer:3,lYpoI2:11}]},{},[1])(1)})});var Ge={};ur(Ge,{__addDisposableResource:()=>No,__assign:()=>Cn,__asyncDelegator:()=>ko,__asyncGenerator:()=>To,__asyncValues:()=>Bo,__await:()=>dt,__awaiter:()=>Eo,__classPrivateFieldGet:()=>Vo,__classPrivateFieldIn:()=>zo,__classPrivateFieldSet:()=>Uo,__createBinding:()=>An,__decorate:()=>Io,__disposeResources:()=>$o,__esDecorate:()=>Aa,__exportStar:()=>Po,__extends:()=>So,__generator:()=>Co,__importDefault:()=>Lo,__importStar:()=>Mo,__makeTemplateObject:()=>jo,__metadata:()=>Do,__param:()=>_o,__propKey:()=>Fa,__read:()=>Ni,__rest:()=>Oo,__runInitializers:()=>Ra,__setFunctionName:()=>Ta,__spread:()=>Ao,__spreadArray:()=>Fo,__spreadArrays:()=>Ro,__values:()=>Pn,default:()=>ja});function So(n,i){if(typeof i!="function"&&i!==null)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");zi(n,i);function e(){this.constructor=n}n.prototype=i===null?Object.create(i):(e.prototype=i.prototype,new e)}function Oo(n,i){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&i.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(n);r<t.length;r++)i.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(n,t[r])&&(e[t[r]]=n[t[r]]);return e}function Io(n,i,e,t){var r=arguments.length,o=r<3?i:t===null?t=Object.getOwnPropertyDescriptor(i,e):t,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(n,i,e,t);else for(var a=n.length-1;a>=0;a--)(s=n[a])&&(o=(r<3?s(o):r>3?s(i,e,o):s(i,e))||o);return r>3&&o&&Object.defineProperty(i,e,o),o}function _o(n,i){return function(e,t){i(e,t,n)}}function Aa(n,i,e,t,r,o){function s(_){if(_!==void 0&&typeof _!="function")throw new TypeError("Function expected");return _}for(var a=t.kind,u=a==="getter"?"get":a==="setter"?"set":"value",d=!i&&n?t.static?n:n.prototype:null,p=i||(d?Object.getOwnPropertyDescriptor(d,t.name):{}),S,y=!1,E=e.length-1;E>=0;E--){var g={};for(var v in t)g[v]=v==="access"?{}:t[v];for(var v in t.access)g.access[v]=t.access[v];g.addInitializer=function(_){if(y)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(_||null))};var I=(0,e[E])(a==="accessor"?{get:p.get,set:p.set}:p[u],g);if(a==="accessor"){if(I===void 0)continue;if(I===null||typeof I!="object")throw new TypeError("Object expected");(S=s(I.get))&&(p.get=S),(S=s(I.set))&&(p.set=S),(S=s(I.init))&&r.unshift(S)}else(S=s(I))&&(a==="field"?r.unshift(S):p[u]=S)}d&&Object.defineProperty(d,t.name,p),y=!0}function Ra(n,i,e){for(var t=arguments.length>2,r=0;r<i.length;r++)e=t?i[r].call(n,e):i[r].call(n);return t?e:void 0}function Fa(n){return typeof n=="symbol"?n:"".concat(n)}function Ta(n,i,e){return typeof i=="symbol"&&(i=i.description?"[".concat(i.description,"]"):""),Object.defineProperty(n,"name",{configurable:!0,value:e?"".concat(e," ",i):i})}function Do(n,i){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,i)}function Eo(n,i,e,t){function r(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function a(p){try{d(t.next(p))}catch(S){s(S)}}function u(p){try{d(t.throw(p))}catch(S){s(S)}}function d(p){p.done?o(p.value):r(p.value).then(a,u)}d((t=t.apply(n,i||[])).next())})}function Co(n,i){var e={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},t,r,o,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(d){return function(p){return u([d,p])}}function u(d){if(t)throw new TypeError("Generator is already executing.");for(;s&&(s=0,d[0]&&(e=0)),e;)try{if(t=1,r&&(o=d[0]&2?r.return:d[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,d[1])).done)return o;switch(r=0,o&&(d=[d[0]&2,o.value]),d[0]){case 0:case 1:o=d;break;case 4:return e.label++,{value:d[1],done:!1};case 5:e.label++,r=d[1],d=[0];continue;case 7:d=e.ops.pop(),e.trys.pop();continue;default:if(o=e.trys,!(o=o.length>0&&o[o.length-1])&&(d[0]===6||d[0]===2)){e=0;continue}if(d[0]===3&&(!o||d[1]>o[0]&&d[1]<o[3])){e.label=d[1];break}if(d[0]===6&&e.label<o[1]){e.label=o[1],o=d;break}if(o&&e.label<o[2]){e.label=o[2],e.ops.push(d);break}o[2]&&e.ops.pop(),e.trys.pop();continue}d=i.call(n,e)}catch(p){d=[6,p],r=0}finally{t=o=0}if(d[0]&5)throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}}function Po(n,i){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(i,e)&&An(i,n,e)}function Pn(n){var i=typeof Symbol=="function"&&Symbol.iterator,e=i&&n[i],t=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&t>=n.length&&(n=void 0),{value:n&&n[t++],done:!n}}};throw new TypeError(i?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ni(n,i){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var t=e.call(n),r,o=[],s;try{for(;(i===void 0||i-- >0)&&!(r=t.next()).done;)o.push(r.value)}catch(a){s={error:a}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(s)throw s.error}}return o}function Ao(){for(var n=[],i=0;i<arguments.length;i++)n=n.concat(Ni(arguments[i]));return n}function Ro(){for(var n=0,i=0,e=arguments.length;i<e;i++)n+=arguments[i].length;for(var t=Array(n),r=0,i=0;i<e;i++)for(var o=arguments[i],s=0,a=o.length;s<a;s++,r++)t[r]=o[s];return t}function Fo(n,i,e){if(e||arguments.length===2)for(var t=0,r=i.length,o;t<r;t++)(o||!(t in i))&&(o||(o=Array.prototype.slice.call(i,0,t)),o[t]=i[t]);return n.concat(o||Array.prototype.slice.call(i))}function dt(n){return this instanceof dt?(this.v=n,this):new dt(n)}function To(n,i,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e.apply(n,i||[]),r,o=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(y){t[y]&&(r[y]=function(E){return new Promise(function(g,v){o.push([y,E,g,v])>1||a(y,E)})})}function a(y,E){try{u(t[y](E))}catch(g){S(o[0][3],g)}}function u(y){y.value instanceof dt?Promise.resolve(y.value.v).then(d,p):S(o[0][2],y)}function d(y){a("next",y)}function p(y){a("throw",y)}function S(y,E){y(E),o.shift(),o.length&&a(o[0][0],o[0][1])}}function ko(n){var i,e;return i={},t("next"),t("throw",function(r){throw r}),t("return"),i[Symbol.iterator]=function(){return this},i;function t(r,o){i[r]=n[r]?function(s){return(e=!e)?{value:dt(n[r](s)),done:!1}:o?o(s):s}:o}}function Bo(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=n[Symbol.asyncIterator],e;return i?i.call(n):(n=typeof Pn=="function"?Pn(n):n[Symbol.iterator](),e={},t("next"),t("throw"),t("return"),e[Symbol.asyncIterator]=function(){return this},e);function t(o){e[o]=n[o]&&function(s){return new Promise(function(a,u){s=n[o](s),r(a,u,s.done,s.value)})}}function r(o,s,a,u){Promise.resolve(u).then(function(d){o({value:d,done:a})},s)}}function jo(n,i){return Object.defineProperty?Object.defineProperty(n,"raw",{value:i}):n.raw=i,n}function Mo(n){if(n&&n.__esModule)return n;var i={};if(n!=null)for(var e in n)e!=="default"&&Object.prototype.hasOwnProperty.call(n,e)&&An(i,n,e);return ka(i,n),i}function Lo(n){return n&&n.__esModule?n:{default:n}}function Vo(n,i,e,t){if(e==="a"&&!t)throw new TypeError("Private accessor was defined without a getter");if(typeof i=="function"?n!==i||!t:!i.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?t:e==="a"?t.call(n):t?t.value:i.get(n)}function Uo(n,i,e,t,r){if(t==="m")throw new TypeError("Private method is not writable");if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof i=="function"?n!==i||!r:!i.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t==="a"?r.call(n,e):r?r.value=e:i.set(n,e),e}function zo(n,i){if(i===null||typeof i!="object"&&typeof i!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof n=="function"?i===n:n.has(i)}function No(n,i,e){if(i!=null){if(typeof i!="object"&&typeof i!="function")throw new TypeError("Object expected.");var t;if(e){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");t=i[Symbol.asyncDispose]}if(t===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");t=i[Symbol.dispose]}if(typeof t!="function")throw new TypeError("Object not disposable.");n.stack.push({value:i,dispose:t,async:e})}else e&&n.stack.push({async:!0});return i}function $o(n){function i(t){n.error=n.hasError?new Ba(t,n.error,"An error was suppressed during disposal."):t,n.hasError=!0}function e(){for(;n.stack.length;){var t=n.stack.pop();try{var r=t.dispose&&t.dispose.call(t.value);if(t.async)return Promise.resolve(r).then(e,function(o){return i(o),e()})}catch(o){i(o)}}if(n.hasError)throw n.error}return e()}var zi,Cn,An,ka,Ba,ja,Ye=fs(()=>{zi=function(n,i){return zi=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},zi(n,i)};Cn=function(){return Cn=Object.assign||function(i){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(i[o]=e[o])}return i},Cn.apply(this,arguments)};An=Object.create?function(n,i,e,t){t===void 0&&(t=e);var r=Object.getOwnPropertyDescriptor(i,e);(!r||("get"in r?!i.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return i[e]}}),Object.defineProperty(n,t,r)}:function(n,i,e,t){t===void 0&&(t=e),n[t]=i[e]};ka=Object.create?function(n,i){Object.defineProperty(n,"default",{enumerable:!0,value:i})}:function(n,i){n.default=i};Ba=typeof SuppressedError=="function"?SuppressedError:function(n,i,e){var t=new Error(e);return t.name="SuppressedError",t.error=n,t.suppressed=i,t};ja={__extends:So,__assign:Cn,__rest:Oo,__decorate:Io,__param:_o,__metadata:Do,__awaiter:Eo,__generator:Co,__createBinding:An,__exportStar:Po,__values:Pn,__read:Ni,__spread:Ao,__spreadArrays:Ro,__spreadArray:Fo,__await:dt,__asyncGenerator:To,__asyncDelegator:ko,__asyncValues:Bo,__makeTemplateObject:jo,__importStar:Mo,__importDefault:Lo,__classPrivateFieldGet:Vo,__classPrivateFieldSet:Uo,__classPrivateFieldIn:zo,__addDisposableResource:No,__disposeResources:$o}});var qo=oe(Ko=>{"use strict";Object.defineProperty(Ko,"__esModule",{value:!0})});var Ki=oe(De=>{"use strict";Object.defineProperty(De,"__esModule",{value:!0});De.invokeEventHandlersAsync=De.invokeEventHandlers=De.eventHandlerSafeInvokeAsync=De.eventHandlerSafeInvoke=void 0;var Ho=(Ye(),et(Ge));function Wo(n,i,e){try{return n(i,e),{succeeded:!0}}catch(t){return{error:t,succeeded:!1}}}De.eventHandlerSafeInvoke=Wo;function $i(n,i,e){return(0,Ho.__awaiter)(this,void 0,void 0,function*(){try{return yield n(i,e),{succeeded:!0}}catch(t){return{error:t,succeeded:!1}}})}De.eventHandlerSafeInvokeAsync=$i;function Ma(n,i,e,t){for(let r of n){let{succeeded:o,error:s}=Wo(r,i,e);if(!o&&t?.swallowExceptions!==!0)throw s}}De.invokeEventHandlers=Ma;function La(n,i,e,t){return(0,Ho.__awaiter)(this,void 0,void 0,function*(){if(t?.parallelize===!1)for(let r of n){let{succeeded:o,error:s}=yield $i(r,i,e);if(!o&&t?.swallowExceptions!==!0)throw s}else{let r=[];for(let o of n)r.push($i(o,i,e).then(({succeeded:s,error:a})=>{if(!s&&t?.swallowExceptions!==!0)throw a}));yield Promise.all(r)}})}De.invokeEventHandlersAsync=La});var Go=oe(Rn=>{"use strict";Object.defineProperty(Rn,"__esModule",{value:!0});Rn.TypedEvent=void 0;var Va=(Ye(),et(Ge)),Qo=Ki(),Jo={swallowExceptions:!1,parallelize:!0},qi=class{constructor(){this._handlers=[]}attach(i){this._handlers.push(i)}detach(i){this.tryRemoveHandler(i)}invoke(i,e,t=Jo){(0,Qo.invokeEventHandlers)(this._handlers,i,e,t)}invokeAsync(i,e,t=Jo){return(0,Va.__awaiter)(this,void 0,void 0,function*(){yield(0,Qo.invokeEventHandlersAsync)(this._handlers,i,e,t)})}tryRemoveHandler(i){let e=this._handlers.findIndex(t=>t===i);e>=0&&this._handlers.splice(e,1)}};Rn.TypedEvent=qi});var Wi=oe(Hi=>{"use strict";Object.defineProperty(Hi,"__esModule",{value:!0});var Ua=(Ye(),et(Ge));(0,Ua.__exportStar)(Go(),Hi)});var Yo=oe(Fn=>{"use strict";Object.defineProperty(Fn,"__esModule",{value:!0});Fn.FinalizationRegistryMissingError=void 0;var Qi=class extends Error{};Fn.FinalizationRegistryMissingError=Qi});var Gi=oe(Tn=>{"use strict";Object.defineProperty(Tn,"__esModule",{value:!0});Tn.WeakHandlerHolder=void 0;var za=Yo(),Ji=class{constructor(i){this._refs=[];try{this._finalizationRegistry=new FinalizationRegistry(i)}catch(e){throw e.name==="FinalizationRegistry"?new za.FinalizationRegistryMissingError("FinalizationRegistry is not defined. Weak Events cannot be used. Please consult 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry' for compatibility information"):e}}getWeakHandler(i,e){let t=new WeakRef(e);return this._finalizationRegistry.register(e,{eventSource:i,handlerRef:t},t),this._refs.push(t),t}releaseWeakHandler(i){let t=this._refs.find(r=>r?.deref()===i)||new WeakRef(i);return this._finalizationRegistry.unregister(t),t}unregisterRef(i){this._finalizationRegistry.unregister(i)}};Tn.WeakHandlerHolder=Ji});var Xo=oe(kn=>{"use strict";Object.defineProperty(kn,"__esModule",{value:!0});kn.WeakEvent=void 0;var Yi=(Ye(),et(Ge)),Na=Wi(),$a=Gi(),Xi=Ki(),Ka={swallowExceptions:!1,parallelize:!0},Zi=class{constructor(){this._handlers=[],this._handlerFinalizedEvent=new Na.TypedEvent,this.handlerFinalizedEvent=this._handlerFinalizedEvent,this._refHolder=new $a.WeakHandlerHolder(i=>{this.onHandlerFinalizer(i)})}invoke(i,e,t){for(let r of this._handlers){let o=r?.deref();if(o){let{succeeded:s,error:a}=(0,Xi.eventHandlerSafeInvoke)(o,i,e);if(!s&&t?.swallowExceptions!==!0)throw a}else this.releaseHandler(r)}}invokeAsync(i,e,t=Ka){return(0,Yi.__awaiter)(this,void 0,void 0,function*(){t?.parallelize===!1?yield this.sequentialInvokeAsync(i,e,t):yield this.parallelInvokeAsync(i,e,t)})}sequentialInvokeAsync(i,e,t){return(0,Yi.__awaiter)(this,void 0,void 0,function*(){for(let r of this._handlers){let o=r?.deref();if(o){let{succeeded:s,error:a}=yield(0,Xi.eventHandlerSafeInvokeAsync)(o,i,e);if(!s&&t.swallowExceptions!==!0)throw a}else this.releaseHandler(r)}})}parallelInvokeAsync(i,e,t){return(0,Yi.__awaiter)(this,void 0,void 0,function*(){let r=[];for(let o of this._handlers){let s=o?.deref();s?r.push((0,Xi.eventHandlerSafeInvokeAsync)(s,i,e).then(({succeeded:a,error:u})=>{if(!a&&t.swallowExceptions!==!0)throw u})):this.releaseHandler(o)}yield Promise.all(r)})}attach(i){this._handlers.push(this._refHolder.getWeakHandler(this,i))}detach(i){let e=this._refHolder.releaseWeakHandler(i);this.tryRemoveHandlerRef(e)}onHandlerFinalizer(i){this.tryRemoveHandlerRef(i?.handlerRef),this._handlerFinalizedEvent.invokeAsync(this,i,{swallowExceptions:!0})}tryRemoveHandlerRef(i){let e=this._handlers.findIndex(t=>t===i);e>=0&&this._handlers.splice(e,1)}releaseHandler(i){this._refHolder.unregisterRef(i),this.tryRemoveHandlerRef(i)}};kn.WeakEvent=Zi});var es=oe(Bn=>{"use strict";Object.defineProperty(Bn,"__esModule",{value:!0});var Zo=(Ye(),et(Ge));(0,Zo.__exportStar)(Gi(),Bn);(0,Zo.__exportStar)(Xo(),Bn)});var ts=oe(Ft=>{"use strict";Object.defineProperty(Ft,"__esModule",{value:!0});var er=(Ye(),et(Ge));(0,er.__exportStar)(qo(),Ft);(0,er.__exportStar)(Wi(),Ft);(0,er.__exportStar)(es(),Ft)});var sr={};ur(sr,{Client:()=>Xe,ClientDescriptor:()=>ti,Entity:()=>he,EntityFile:()=>fe,MigrationPathError:()=>at,ServerSync:()=>ft,Storage:()=>Xe,StorageDescriptor:()=>ti,UndoHistory:()=>Je,authorization:()=>rc,cliSync:()=>oc,collection:()=>Pi,createDefaultMigration:()=>Ai,createMigration:()=>Ri,id:()=>ic,migrate:()=>an,schema:()=>It});var Er=ke(Ne(),1),qt=4,gt=36;function Ir(n){return n.toString(gt).padStart(qt,"0")}function ws(n){return n.toString().padStart(6,"0")}var Ut=class{constructor(){this.latest={time:Date.now(),counter:0,node:vs()},this.zeroCounter=0,this.now=i=>(this.latest=Dr(this.latest),this.get(i,this.latest)),this.OLD_now=i=>(this.latest=Dr(this.latest),ws(i)+Ss(this.latest)),this.timerState=()=>this.latest,this.update=i=>{let e=i.slice(qt);this.latest=xs(this.latest,Cr(e))},this.get=(i,e)=>Ir(i)+_r(e),this.zero=i=>Ir(i)+_r({time:0,counter:this.zeroCounter++,node:this.latest.node}),this.getWallClockTime=ui}},zt=class extends Error{constructor(...i){super(),this.type="ClockDriftError",this.message=["maximum clock drift exceeded"].concat(i).join(" ")}},Nt=class extends Error{constructor(){super(),this.type="OverflowError",this.message="timestamp counter overflow"}},ci=4,li=7,$t=60*1e3,mt=9;function vs(){return Er.default.slug().padStart(li,"0").slice(0,li)}function _r(n){let i=new Date(n.time).getTime().toString(gt).padStart(mt,"0"),e=n.counter.toString(gt).padStart(ci,"0"),t=n.node.padStart(li,"0");return`${i}${e}${t}`}function Dr(n){let i=Date.now(),e=Math.max(n.time,i),t=n.time===e?n.counter+1:0;if(e-i>$t)throw new zt(e,i,$t);if(t>65535)throw new Nt;return{time:e,counter:t,node:n.node}}function xs(n,i){let e=Date.now(),t=Math.max(e,Math.max(n.time,i.time)),r=Math.max(n.counter,i.counter),o;if(n.time===t&&i.time===t?o=r+1:n.time===t?o=n.counter+1:i.time===t?o=i.counter+1:o=0,t-e>$t)throw new zt(t,e,$t);if(o>65535)throw new Nt;return{time:t,counter:o,node:n.node}}function Cr(n){let i=n.slice(0,mt),e=n.slice(mt,mt+ci),t=n.slice(mt+ci),r=parseInt(i,gt),o=parseInt(e,gt);if(isNaN(r)||isNaN(o))throw new Error("invalid clock format");return{time:r,counter:o,node:t}}function Ss(n){let i=new Date(n.time).toISOString(),e=n.counter.toString(16).toUpperCase().padStart(4,"0"),t=n.node.padStart(16,"0");return`${i}-${e}-${t}`}function Kt(n){return parseInt(n.slice(0,qt),36)}function di(n,i){return Kt(n)-Kt(i)}function ui(n){return Cr(n.slice(qt)).time}var Ht,Os=new Uint8Array(16);function fi(){if(!Ht&&(Ht=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!Ht))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ht(Os)}var Pr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Is(n){return typeof n=="string"&&Pr.test(n)}var Ar=Is;var ee=[];for(Wt=0;Wt<256;++Wt)ee.push((Wt+256).toString(16).substr(1));var Wt;function _s(n){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(ee[n[i+0]]+ee[n[i+1]]+ee[n[i+2]]+ee[n[i+3]]+"-"+ee[n[i+4]]+ee[n[i+5]]+"-"+ee[n[i+6]]+ee[n[i+7]]+"-"+ee[n[i+8]]+ee[n[i+9]]+"-"+ee[n[i+10]]+ee[n[i+11]]+ee[n[i+12]]+ee[n[i+13]]+ee[n[i+14]]+ee[n[i+15]]).toLowerCase();if(!Ar(e))throw TypeError("Stringified UUID is invalid");return e}var Rr=_s;function Ds(n,i,e){n=n||{};var t=n.random||(n.rng||fi)();if(t[6]=t[6]&15|64,t[8]=t[8]&63|128,i){e=e||0;for(var r=0;r<16;++r)i[e+r]=t[r];return i}return Rr(t)}var yt=Ds;function Q(n){return Oe(n)||we(n)}function tt(n,i){return n===i?!0:!(!Q(n)||!Q(i)||n["@@type"]!==i["@@type"]||n.id!==i.id)}var Es="/",bt=":",pi=new WeakMap;function ne(n){let i=me(n);return L(!!i,`Object ${JSON.stringify(n)} does not have an OID assigned to it`),i}function me(n){if(U(n))return pi.get(n)}function N(n,i){return L(U(n),`Only objects can be assigned OIDs, received ${JSON.stringify(n)}`),mi(n)&&Gt(n),pi.set(n,i),n}function mi(n){return!!me(n)}function Gt(n){return pi.delete(n),n}function gi(n,i,e){if(mi(n))return ne(n);{let t=ve(i,e);return N(n,t),t}}function Fr(n,i,e){if(mi(n)){let t=ne(n);if(Ce(t,i))return ne(n);{let r=ve(i,e);return N(n,r),r}}else{let t=ve(i,e);return N(n,t),t}}var hi={".":"&dot;","/":"&slash;",":":"&colon;"};function Tr(n){return n.replace(/[/]/g,hi["/"]).replace(/[:]/g,hi[":"]).replace(/[.]/g,hi["."])}function kr(n){return n.replace(/&slash;/g,"/").replace(/&colon;/g,":").replace(/&dot;/g,".")}function Y(n,i,e){let t=Tr(n)+Es+Tr(i);return e&&(t+=bt+e),t}function ve(n,i=Cs){let{collection:e,id:t}=ce(n);return Y(e,t,i())}function ce(n){let[i,e,...t]=n.split("/");t.length&&(console.error(`OID ${n} has more than 3 segments. Attempting to parse it anyway.`),e+="/"+t.join("/"));let[r,o]=e.split(bt),s;return r.includes(".")?s=r.slice(0,r.indexOf(".")):s=r,{collection:kr(i),id:kr(s),subId:o}}function nt(n,i){let e=ne(n);if(Array.isArray(n)){let t;for(let r=0;r<n.length;r++)t=n[r],U(t)&&!Q(t)&&(Fr(t,e,i),nt(t,i))}else if(U(n)&&!Q(n))for(let t of Object.keys(n))U(n[t])&&!Q(n[t])&&(Fr(n[t],e,i),nt(n[t],i))}function Qt(n){if(Gt(n),Array.isArray(n))for(let i=0;i<n.length;i++)Qt(n[i]);else if(U(n))for(let i of Object.keys(n))Qt(n[i])}function Cs(){return yt().slice(0,8)}function ae(n){return{"@@type":"ref",id:n}}function Jt(n,i=new Map){if(Array.isArray(n)){let e=ne(n),t=N([],e);for(let r=0;r<n.length;r++){let o=n[r];if(U(o)){if(Oe(o))throw new Error("An attempt was made to normalize an already normalized object! This is an error in verdant itself.");if(we(o)){t[r]=o;continue}else{let s=ne(o);t[r]=ae(s),Jt(o,i)}}else t[r]=o}i.set(e,t)}else if(U(n)&&!Q(n)){let e=ne(n),t=N({},e);for(let r of Object.keys(n)){let o=n[r];if(U(o)){if(Oe(o))throw new Error("An attempt was made to normalize an already normalized object! This is an error in verdant itself.");if(we(o))t[r]=o;else{let s=ne(o);t[r]=ae(s),Jt(o,i)}}else t[r]=o}i.set(e,t)}else Q(n);return i}function $(n){return n.split(".")[0].split(bt)[0]}function yi(n){let i=$(n),e=ve(i,()=>"\uFFFF");return[`${i}${bt}`,e]}function Ce(n,i){return $(n)===$(i)}function Yt(n){return!n.includes(bt)}var Lr=ke(Mr(),1);function Ps(n,i){return typeof i!="object"||i===null||Array.isArray(i)?i:Object.fromEntries(Object.entries(i).sort(([e],[t])=>e<t?-1:e>t?1:0))}function wt(n){return JSON.stringify(n,Ps)}function le(n,i=!0){if(U(n)||Array.isArray(n)){let e=me(n),t;if(Array.isArray(n))t=n.map(r=>le(r,i));else{t={};for(let[r,o]of Object.entries(n))t[r]=le(o,i)}return i&&e&&N(t,e),t}return n}function Be(n){return(0,Lr.default)(n)}function U(n){return n&&typeof n=="object"}function Vr(n){for(var i=[],e=[n],t=0;e.length;){var r=e.pop();if(typeof r=="boolean")t+=4;else if(typeof r=="string")t+=r.length*2;else if(typeof r=="number")t+=8;else if(typeof r=="object"&&i.indexOf(r)===-1){i.push(r);for(var o in r)e.push(r[o])}}return t}function L(n,i="assertion failed"){if(!n)throw new Error(i)}function Xt(n=16){return yt().replace("-","").slice(0,n)}function Ur(n,i){for(let e=n.length-1;e>=0;e--)if(i(n[e]))return e;return-1}function zr(n,i){let e;return function(...t){let r=this;clearTimeout(e),e=setTimeout(()=>n.apply(r,t),i)}}function Nr(n,i){let e=0,t;return function(...r){let o=this,s=Date.now();s-e>=i?(e=s,n.apply(o,r),clearTimeout(t)):(clearTimeout(t),t=setTimeout(()=>{e=s,n.apply(o,r)},i))}}function we(n){return n&&n["@@type"]==="file"}function vt(n){return{"@@type":"file",id:n}}function it(n){return typeof File<"u"&&n instanceof File||typeof Blob<"u"&&n instanceof Blob}function Zt(n){return n&&U(n)&&typeof n.id=="string"&&typeof n.remote=="boolean"&&typeof n.name=="string"&&typeof n.type=="string"}var rt="__@@oid_do_not_use",Pe="@@id";function As(n){if(U(n))return n[Pe]||n[rt]}function Rs(n){return U(n)&&(delete n[rt],delete n[Pe]),n}function Fs(n){let i=As(n);i&&N(n,i)}function xt(n){if(Fs(n),Rs(n),Array.isArray(n))for(let i=0;i<n.length;i++)xt(n[i]);else if(U(n))for(let i of Object.keys(n))xt(n[i])}function Ts(n){let{collection:i,id:e,subId:t}=ce(n);return Y(i,e,t)}var ks=/"\w+\/[^"]+?(\.[^"]+)+\:[\S]+?"/g;function Bs(n){return n.replaceAll(ks,i=>{let e=i.slice(1,i.length-1);return`"${Ts(e)}"`})}function bi(n){return JSON.parse(Bs(JSON.stringify(n)))}function wi(n){let i=$(n);return[`${i}.`,`${i}.\uFFFF`]}function vi(n){return n===Pe||n===rt}function Oe(n){return n&&typeof n=="object"&&n["@@type"]==="ref"}function xi(n){return U(n)&&!Q(n)}function js(n,i){return n===i?!0:Q(n)&&Q(i)?tt(n,i):!1}function St(n,i,e,t,r=[],o){let s=o?.authz,a=ne(n);function u(d,p,S,y){if(!xi(p))js(p,S)||(y?r.push(Me({oid:a,timestamp:e(),data:{op:"list-set",index:d,value:p}},s)):r.push(Me({oid:a,timestamp:e(),data:{op:"set",name:d,value:p}},s)));else{let E=me(S),g=me(p);g&&!Ce(a,g)?(p=le(p,!1),g=ve(a,t),N(p,g)):o?.mergeUnknownObjects?!g&&E?(N(p,E),g=E):g=gi(p,a,t):g=gi(p,a,t),L(!!g,"Error: no value OID was resolved during diff. This is a bug in Verdant."),L(Ce(a,g),`Error: value OID ${g} is not related to parent OID ${a}. This is a bug in Verdant.`),S===void 0||g!==E?(Ae(p,g,e,t,r),r.push(Me({oid:a,timestamp:e(),data:{op:"set",name:d,value:ae(g)}},s)),E!==void 0&&r.push(Me({oid:E,timestamp:e(),data:{op:"delete"}},s))):St(S,p,e,t,r,o)}}if(Array.isArray(n)&&Array.isArray(i)){for(let p=0;p<i.length;p++){let S=i[p],y=n[p];u(p,S,y,!0)}let d=n.length-i.length;if(d>0){for(let p=i.length;p<n.length;p++){let S=n[p],y=me(S);y&&r.push(Me({oid:y,timestamp:e(),data:{op:"delete"}},s))}r.push(Me({oid:a,timestamp:e(),data:{op:"list-delete",index:i.length,count:d}},s))}}else{if(Array.isArray(n)||Array.isArray(i))throw new Error("Cannot diff an array with an object");if(xi(n)&&xi(i)){let d=new Set(Object.keys(n));for(let[p,S]of Object.entries(i)){if(S===void 0&&o?.defaultUndefined||(d.delete(p),vi(p)))continue;let y=n[p];u(p,S,y,!1)}if(!o?.defaultUndefined)for(let p of d)vi(p)||r.push(Me({oid:a,timestamp:e(),data:{op:"remove",name:p}},s))}}return r}function Ae(n,i,e,t,r=[],o){N(n,i),nt(n,t);let s=Jt(n);for(let a of s.keys()){let u=s.get(a),d={oid:a,timestamp:e(),data:{op:"initialize",value:Gt(u)}};r.push(Me(d,o?.authz))}return r}function Me(n,i){return i&&(n.authz=i),n}function Ot(n){let i={};for(let e of n)e.oid in i?i[e.oid].push(e):i[e.oid]=[e];return i}function Kr(n){let i={};for(let e of n){let t=$(e.oid);t in i?i[t].push(e):i[t]=[e]}return i}function qr(n){let i={};for(let e of n){let t=$(e.oid);t in i?i[t].push(e):i[t]=[e]}return i}function je(n){return Array.isArray(n)?!0:(console.error(`Cannot apply list patch; expected array, received ${JSON.stringify(n)}. This suggests your data is changing from a list to an object over time. (OID: ${me(n)})`),!1)}function $e(n,i,e){if(n==null&&i.op!=="initialize")return n;let t=n,r,o;function s(a){e&&Q(a)&&e.push(a)}switch(i.op){case"set":s(t[i.name]),t[i.name]=i.value;break;case"remove":s(t[i.name]),delete t[i.name];break;case"list-set":je(n)&&(s(n[i.index]),n[i.index]=i.value);break;case"list-push":je(n)&&n.push(i.value);break;case"list-delete":je(n)&&(s(n[i.index]),n.splice(i.index,i.count));break;case"list-move-by-index":je(n)&&(o=n.splice(i.from,1),n.splice(i.to,0,o[0]));break;case"list-remove":if(je(n))do{let a=i.value;i.only==="last"?Oe(a)?r=Ur(n,u=>u.id===a.id):r=n.lastIndexOf(a):Oe(a)?r=n.findIndex(u=>u.id===a.id):r=n.indexOf(a),r!==-1&&(s(n[r]),n.splice(r,1))}while(!i.only&&r!==-1);break;case"list-add":je(n)&&(n.some(u=>Oe(u)&&Oe(i.value)?u.id===i.value.id:u===i.value)||n.push(i.value));break;case"list-move-by-ref":je(n)&&(r=n.findIndex(a=>tt(a,i.value)),o=n.splice(r,1),n.splice(i.index,0,o[0]));break;case"list-insert":if(je(n)){if(!i.value&&!i.values)throw new Error(`Cannot apply list insert patch; expected value or values, received ${JSON.stringify(i)}`);i.value?n.splice(i.index,0,i.value):n.splice(i.index,0,...i.values)}break;case"delete":Array.isArray(n)?n.forEach(s):U(n)&&Object.values(n||{}).forEach(s);return;case"initialize":return le(i.value);case"touch":return n;default:throw new Error(`Unsupported patch operation: ${i.op}`)}return n}function en(n,i,e=[]){if(Array.isArray(n))for(let t=0;t<n.length;t++){let r=n[t];n[t]=$r(r,i,e),U(n[t])&&en(n[t],i,e)}else if(!we(n)){if(U(n)){L(me(n),`Object ${JSON.stringify(n)} must have an oid`);for(let t of Object.keys(n))n[t]=$r(n[t],i,e),U(n[t])&&en(n[t],i,e)}}return e}function $r(n,i,e){if(Oe(n)){e.push(n.id);let t=i.get(n.id);return L(!!t,`No value was found in object map for ${n.id}`),N(t,n.id)}else return n}function Hr(n){return n.data.op==="set"?n.data.name:!1}function Wr(n,i){return i.has(!0)?!0:n.data.op==="set"||n.data.op==="remove"?i.has(n.data.name):!1}function tn(n){return{oid:n.oid,timestamp:n.timestamp,data:n.data,authz:n.authz}}var Le;(function(n){n[n.Realtime=0]="Realtime",n[n.Push=1]="Push",n[n.PassiveRealtime=2]="PassiveRealtime",n[n.PassivePush=3]="PassivePush",n[n.ReadOnlyPull=4]="ReadOnlyPull",n[n.ReadOnlyRealtime=5]="ReadOnlyRealtime"})(Le||(Le={}));var Qr=ke(Ne(),1),Ms=n=>Object.assign({type:"object"},n),Ls=n=>Object.assign({type:"array"},n),Vs=n=>Object.assign({type:"string"},n),Us=n=>Object.assign({type:"number"},n),zs=n=>Object.assign({type:"boolean"},n),Ns=n=>Object.assign({type:"any"},n),$s=n=>Object.assign({type:"map"},n),Ks=n=>Object.assign({type:"file"},n),qs=()=>({type:"string",default:Qr.default}),Jr={object:Ms,array:Ls,string:Vs,number:Us,boolean:zs,any:Ns,map:$s,file:Ks,id:qs};var Zr=ke(Ne(),1);function Si(n){return n.equals!==void 0}function Oi(n){return n.gte!==void 0||n.lte!==void 0||n.gt!==void 0||n.lt!==void 0}function Hs(n){return!!n.match}function Ii(n){return n.startsWith!==void 0}function Gr(n){return!Oi(n)&&!Si(n)&&!Hs(n)&&!Ii(n)&&n.order}function xe(n){return n.type==="any"?!0:n.type==="map"?!1:n.nullable}function Re(n){return n?n.type==="map"||n.type==="array"?!0:n.type==="file"?!1:n.default!==void 0:!1}function Di(n){if(!(!n||!Re(n)))return n.type==="file"?xe(n)?null:void 0:n.type==="map"?{}:n.type==="array"?xe(n)?null:[]:n.type==="object"?xe(n)?null:void 0:typeof n.default=="function"?n.default():n.default}function Fe(n,i){for(let[e,t]of Object.entries(n.fields)){let r=Ei(t);(r!==void 0&&i[e]===void 0||!xe(t)&&i[e]===null)&&(i[e]=r),i[e]&&Ke(i[e],t)}return i}function Ke(n,i){if(n==null)return n;if(i.type==="object")for(let[e,t]of Object.entries(i.properties)){if(n[e]===void 0){let r=Ei(t);r!==void 0&&(n[e]=r)}Ke(n[e],t)}else if(i.type==="array")for(let e of n)Ke(e,i.items);else if(i.type==="map")for(let[e,t]of Object.entries(n))e===Pe||e===rt||Ke(t,i.values)}function Ei(n){if(n.type==="string"||n.type==="number"||n.type==="boolean"||n.type==="any"){if(n.default&&typeof n.default=="function")return n.default();if(n.default!==void 0)return JSON.parse(JSON.stringify(n.default))}if(n.type==="array")return[];if(n.type==="map")return{};if(n.type!=="any"&&n.nullable)return null;if(n.type==="object"&&n.default){let i=typeof n.default=="function"?n.default():JSON.parse(JSON.stringify(n.default));for(let[e,t]of Object.entries(n.properties))i[e]===void 0&&(i[e]=Ei(t));return i}}function Ci(n,i){for(let[e,t]of Object.entries(i))e===Pe||e===rt||(n.fields[e]?_i(t,n.fields[e]):delete i[e]);return i}function _i(n,i){if(U(n)&&i.type==="object")for(let[e,t]of Object.entries(n))i.properties[e]?_i(t,i.properties[e]):delete n[e];else if(Array.isArray(n)&&i.type==="array")for(let e of n)_i(e,i.items)}function Yr(n,i){for(let[e,t]of Object.entries(i))if(e!==Pe){if(!n[e])return{type:"invalid-key",fieldPath:[e],message:`Invalid field "${e}"`};if(t){let r=Te({field:n[e],value:t,fieldPath:[e]});if(r)return r}}}function Te({field:n,value:i,fieldPath:e=[],depth:t,requireDefaults:r}){if(!(t!==void 0&&t<=0)&&!(xe(n)&&i===null)){if(i===null&&(r||!Re(n)))return{type:"no-default",fieldPath:e,message:`Invalid null value for field ${Ie(e)}`};if(n.type==="object"){if(!U(i))return{type:"invalid-type",fieldPath:e,message:`Expected object ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`};for(let[o,s]of Object.entries(n.properties))o!==Pe&&i[o]&&Te({field:s,value:i[o],fieldPath:[...e,o],depth:t!==void 0?t-1:void 0});for(let o of Object.keys(i))if(!n.properties[o])return{type:"invalid-key",fieldPath:[...e,o],message:`Invalid unexpected field "${o}" on value ${Ie(e)}`}}else if(n.type==="array"){if(!Array.isArray(i))return i===null&&n.nullable?void 0:{type:"invalid-value",fieldPath:e,message:`Expected array ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`};for(let o of i)Te({field:n.items,value:o,fieldPath:[...e,"[]"],depth:t!==void 0?t-1:void 0})}else if(n.type==="map"){if(!U(i))return{type:"invalid-type",fieldPath:e,message:`Expected map for field ${Ie(e)}, got ${i}`};for(let[o,s]of Object.entries(i))Te({field:n.values,value:s,fieldPath:[...e,o],depth:t!==void 0?t-1:void 0})}else if(n.type==="string"){if(typeof i!="string")return{type:"invalid-type",fieldPath:e,message:`Expected string ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`};if(n.options&&!n.options.includes(i))return{type:"invalid-value",fieldPath:e,message:`Expected one of ${n.options.join(", ")} for field ${Ie(e)}, got ${i}`}}else if(n.type==="boolean"){if(typeof i!="boolean")return{type:"invalid-type",fieldPath:e,message:`Expected boolean ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`}}else if(n.type==="number"){if(typeof i!="number")return{type:"invalid-type",fieldPath:e,message:`Expected number ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`}}else if(n.type==="file"&&!it(i)&&!Zt(i))return{type:"invalid-type",fieldPath:e,message:`Expected file ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`}}}function Ie(n){return n.length===0?"root":n.join(".")}function Xr(n,i){let e={};for(let[t,r]of Object.entries(i))n[t]&&(e[t]=nn({field:n[t],value:r,fieldPath:[t]}));return e}function nn({field:n,value:i,fieldPath:e=[],depth:t}){let r=Te({field:n,value:i,fieldPath:e,depth:t,requireDefaults:!0});if(r)throw new Error(`Validation error: ${r.message}`);if(n.type==="object"){if(!U(i))return i;let o={};for(let[s,a]of Object.entries(n.properties))o[s]=nn({field:a,value:i[s],fieldPath:[...e,s],depth:t!==void 0?t-1:void 0});return o}else{if(n.type==="array")return Array.isArray(i)?i.map(o=>nn({field:n.items,value:o,fieldPath:[...e,"[]"],depth:t!==void 0?t-1:void 0})):i;if(n.type==="map"){if(!U(i))return i;let o={};for(let[s,a]of Object.entries(i))o[s]=nn({field:n.values,value:a,fieldPath:[...e,s],depth:t!==void 0?t-1:void 0});return o}else return i}}function Ve(n,i){var e;return n.type==="object"?n.properties[i]:n.type==="array"?n.items:n.type==="map"?n.values:n.type==="any"?n:"type"in n?null:(e=n[i])!==null&&e!==void 0?e:null}var Ws=function(n,i){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&i.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(n);r<t.length;r++)i.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(n,t[r])&&(e[t[r]]=n[t[r]]);return e};function Pi(n){var{synthetics:i,indexes:e}=n,t=Ws(n,["synthetics","indexes"]);let r=Object.assign(Object.assign({},i),e);for(let[o,s]of Object.entries(t.fields))"indexed"in s&&(r[o]={field:o});return Object.assign(Object.assign({},t),{indexes:r})}function It(n){return n}It.collection=Pi;It.fields=Jr;It.generated={id:Zr.default};var rn="\uFFFFFE",Qs="\0",Js="\uFFFFFF";function de(...n){let i=Gs(n);return i.length===1?i[0]:i}function qe(...n){return n.join(rn)+`${Js}`}function He(...n){return n.join(rn)+`${rn}${Qs}`}function Gs(n){let i=[[]];for(let e of n)if(Array.isArray(e)){let t=[];for(let r of i)for(let o of e)t.push(r.concat(o));i=t}else for(let t of i)t.push(`${e}`);return Array.from(new Set(i.map(e=>e.join(rn))))}function Ys(n){return!!n.field}function Xs(n,i){let e={};for(let[t,r]of Object.entries(n.indexes||{})){let o=r;Ys(o)?e[t]=Se(i[o.field]):e[t]=Se(o.compute(i))}return e}function Zs(n,i){return Object.entries(n.compounds||{}).reduce((e,[t,r])=>(e[t]=de(...r.of.map(o=>i[o])),e),{})}function ea(n,i){return Object.entries(n.fields).reduce((e,[t,r])=>("indexed"in r&&(e[t]=Se(i[t])),e),{})}function on(n,i){let e=Object.assign(Object.assign({[n.primaryKey]:i[n.primaryKey]},ea(n,i)),Xs(n,i));return Object.assign(e,Zs(n,Object.assign(Object.assign({},i),e))),e["@@@snapshot"]=JSON.stringify(i),e}var ta="null";function Se(n){if(n===null)return ta;if(typeof n=="string"||typeof n=="number")return n;if(typeof n=="boolean"||n===null)return`${n}`;if(n===void 0)return"undefined";if(Array.isArray(n))return n.map(Se);throw new Error(`Unsupported index value: ${n}`)}var eo={version:0,collections:{}};function an(n,i,e){let t=typeof i=="function",r=t?eo:n,o=t?n:i,s=t?i:e,a=Object.keys(o.collections).filter(v=>r.collections[v]&&wt(r.collections[v])!==wt(o.collections[v])),u=Object.keys(r.collections).filter(v=>!o.collections[v]),d=Object.keys(o.collections).filter(v=>!r.collections[v]),p=new Set;for(let v of a){let I=r.collections[v].fields,_=o.collections[v].fields;Object.keys(_).some(O=>{var R,w;return!(!((R=I[O])===null||R===void 0)&&R.default)&&((w=_[O])===null||w===void 0?void 0:w.default)})&&p.add(v),Object.keys(I).some(O=>!_[O])&&p.add(v)}let S={},y={};for(let v of[...a,...d]){let I=sn(r.collections[v]),_=sn(o.collections[v]),O=_.filter(w=>!I.find(D=>D.name===w.name)),R=I.filter(w=>!_.find(D=>D.name===w.name));O.length>0&&(S[v]=O,a.includes(v)&&p.add(v)),R.length>0&&(y[v]=R,a.includes(v)&&p.add(v))}let E=(v,I)=>Fe(o.collections[v],I),g=v=>I=>{let _=o.collections[v];return Fe(_,Ci(_,I))};return{version:o.version,migrate:async v=>{let I=[];if(await s({migrate:async(_,O)=>{let R=g(_),w=async D=>{let f=await O(D);return N(f,ne(D)),R(f)};await v.migrate(_,w),I.push(_),p.delete(_)},identity:_=>_,withDefaults:E,info:{changedCollections:a,addedCollections:d,removedCollections:u},queries:v.queries,mutations:v.mutations}),o.version>1){v.log("debug","auto-migrating collections with new defaults",p);for(let O of p)await v.migrate(O,g(O)),I.push(O);let _=a.filter(O=>!I.includes(O));_.length>0&&console.error(`Unmigrated changed collections from version ${r.version} to version ${o.version}:`,_)}},removedCollections:u,addedIndexes:S,removedIndexes:y,allCollections:Object.keys(o.collections),changedCollections:a,addedCollections:d,oldCollections:Object.keys(r.collections),oldSchema:r,newSchema:o}}function sn(n){return n?[...Object.keys(n.indexes||{}).map(i=>({name:i,multiEntry:["array","string[]","number[]","boolean[]"].includes(n.indexes[i].type),synthetic:!0,compound:!1})),...Object.keys(n.compounds||{}).map(i=>({name:i,multiEntry:n.compounds[i].of.some(e=>(n.fields[e]||n.indexes[e]).type==="array"),synthetic:!1,compound:!0}))]:[]}function Ai(n,i){return an(i?n:{version:0,collections:{}},i||n,async({migrate:t,info:r})=>{if((i||n).version!==1)for(let o of r.changedCollections)await t(o,s=>s)})}function Ri(n,i,e){let t=typeof i=="function"||i===void 0,r=t?eo:n,o=t?n:i,s=t?i:e;L(r,"Invalid arguments to createMigration"),L(o,"Invalid arguments to createMigration");let{changedCollections:a,addedCollections:u,removedCollections:d,addedIndexes:p,removedIndexes:S,autoMigratedCollections:y,autoMigration:E}=na(r,o);return{version:o.version,migrate:async g=>{let v=[];if(await s?.({migrate:async(_,O)=>{let R=E(_),w=async D=>{let f=await O(D);N(f,ne(D));let m=R(f),l=Yr(o.collections[_].fields,m);return m};await g.migrate(_,w),v.push(_),y.delete(_)},info:{changedCollections:a,addedCollections:u,removedCollections:d},queries:g.queries,mutations:g.mutations}),o.version>1){g.log("debug","auto-migrating collections with new defaults",y);for(let O of y)await g.migrate(O,E(O)),v.push(O);for(let O of d)await g.deleteCollection(O);let _=a.filter(O=>!v.includes(O));_.length>0&&console.error(`Unmigrated changed collections from version ${r.version} to version ${o.version}:`,_)}},removedCollections:d,addedIndexes:p,removedIndexes:S,allCollections:Object.keys(o.collections),changedCollections:a,addedCollections:u,oldCollections:Object.keys(r.collections),oldSchema:r,newSchema:o}}function na(n,i){let e=Object.keys(i.collections).filter(p=>n.collections[p]&&wt(n.collections[p])!==wt(i.collections[p])),t=Object.keys(n.collections).filter(p=>!i.collections[p]),r=Object.keys(i.collections).filter(p=>!n.collections[p]),o=new Set;for(let p of e){let S=n.collections[p].fields,y=i.collections[p].fields;Object.keys(y).some(E=>!Re(S[E])&&Re(y[E]))&&o.add(p),Object.keys(S).some(E=>!y[E])&&o.add(p)}let s={},a={};for(let p of[...e,...r]){let S=sn(n.collections[p]),y=sn(i.collections[p]),E=y.filter(v=>!S.find(I=>I.name===v.name)),g=S.filter(v=>!y.find(I=>I.name===v.name));E.length>0&&(s[p]=E,e.includes(p)&&o.add(p)),g.length>0&&(a[p]=g,e.includes(p)&&o.add(p))}return{changedCollections:e,addedCollections:r,removedCollections:t,addedIndexes:s,removedIndexes:a,autoMigratedCollections:o,withDefaults:(p,S)=>Fe(i.collections[p],S),autoMigration:p=>S=>{let y=i.collections[p];return Fe(y,Ci(y,S))}}}var Fi={};var cn=class{constructor(i,e){this.getNow=i,this.createSubId=e,this.isPrimitive=t=>!U(t)||Q(t),this.createDiff=(t,r,o={})=>St(t,r,this.getNow,this.createSubId,[],o),this.createInitialize=(t,r)=>Ae(t,r,this.getNow,this.createSubId),this.createSet=(t,r,o)=>{if(this.isPrimitive(o))return[{oid:t,timestamp:this.getNow(),data:{op:"set",name:r,value:o}}];{let s=ve(t,this.createSubId);return[...Ae(o,s,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"set",value:ae(s),name:r}}]}},this.createRemove=(t,r)=>[{oid:t,timestamp:this.getNow(),data:{op:"remove",name:r}}],this.createListSet=(t,r,o)=>{if(this.isPrimitive(o))return[{oid:t,timestamp:this.getNow(),data:{op:"list-set",index:r,value:o}}];{let s=ve(t,this.createSubId);return[...Ae(o,s,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-set",index:r,value:ae(s)}}]}},this.createListPush=(t,r)=>{if(this.isPrimitive(r))return[{oid:t,timestamp:this.getNow(),data:{op:"list-push",value:r}}];{let o=ve(t,this.createSubId);return[...Ae(r,o,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-push",value:ae(o)}}]}},this.createListAdd=(t,r)=>this.isPrimitive(r)?[{oid:t,timestamp:this.getNow(),data:{op:"list-add",value:r}}]:[{oid:t,timestamp:this.getNow(),data:{op:"list-add",value:ae(r)}}],this.createListInsert=(t,r,o)=>{if(this.isPrimitive(o))return[{oid:t,timestamp:this.getNow(),data:{op:"list-insert",value:o,index:r}}];{let s=ve(t,this.createSubId);return[...Ae(o,s,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-insert",value:ae(s),index:r}}]}},this.createListRemove=(t,r,o)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-remove",value:r,only:o}}],this.createListDelete=(t,r,o=1)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-delete",index:r,count:o}}],this.createListMoveByRef=(t,r,o)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-move-by-ref",value:r,index:o}}],this.createListMoveByIndex=(t,r,o)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-move-by-index",from:r,to:o}}],this.createDelete=t=>[{oid:t,timestamp:this.getNow(),data:{op:"delete"}}],this.createDeleteAll=t=>t.map(r=>({oid:r,timestamp:this.getNow(),data:{op:"delete"}}))}};var z=class{constructor(i){this._onAllUnsubscribed=i,this.subscribers={},this.counts={},this._disabled=!1,this.disposed=!1,this.subscriberCount=e=>{var t;return(t=this.counts[e])!==null&&t!==void 0?t:0},this.totalSubscriberCount=()=>Object.values(this.counts).reduce((e,t)=>e+t,0),this.subscribe=(e,t)=>{let r=Xt(),o=this.subscribers[e];return o||(o=this.subscribers[e]={}),o[r]=t,this.counts[e]=(this.counts[e]||0)+1,()=>{this.subscribers[e]&&(delete this.subscribers[e][r],this.counts[e]--,this.counts[e]===0&&(delete this.subscribers[e],delete this.counts[e],this._onAllUnsubscribed&&this._onAllUnsubscribed(e)))}},this.emit=(e,...t)=>{this._disabled||this.subscribers[e]&&Object.values(this.subscribers[e]).forEach(r=>r(...t))},this.dispose=()=>{this._disabled=!0,this.disposed=!0;let e=Object.keys(this.subscribers);this.subscribers={},this.counts={},e.forEach(t=>{this._onAllUnsubscribed&&this._onAllUnsubscribed(t)})},this.disable=()=>{this._disabled=!0}}get disabled(){return this._disabled}};function to(n,i,e,t){if(i==null)return[{oid:n,timestamp:t(),data:{op:"delete"}}];let r=le(i),o=[];for(let s of e){let a=ia(n,r,s,t);o.unshift(...a),$e(r,s.data)}return o}function ia(n,i,e,t){let r=e.data;switch(r.op){case"set":case"remove":return[{oid:n,timestamp:t(),data:{op:"set",name:r.name,value:i[r.name]}}];case"list-insert":return[{oid:n,timestamp:t(),data:{op:"list-delete",index:r.index,count:1}}];case"list-delete":return[{oid:n,timestamp:t(),data:{op:"list-insert",index:r.index,values:i.slice(r.index,r.count)}}];case"list-move-by-ref":return[{oid:n,timestamp:t(),data:{op:"list-move-by-ref",value:r.value,index:i.indexOf(r.value)}}];case"list-move-by-index":return[{oid:n,timestamp:t(),data:{op:"list-move-by-index",from:r.to,to:r.from}}];case"delete":return[{oid:n,timestamp:t(),data:{op:"initialize",value:i}}];case"list-push":return[{oid:n,timestamp:t(),data:{op:"list-remove",value:r.value,only:"last"}}];case"list-remove":if(r.only==="last"){let o=i.lastIndexOf(r.value);return[{oid:n,timestamp:t(),data:{op:"list-insert",index:o,values:[r.value]}}]}else if(r.only==="first"){let o=i.indexOf(r.value);return[{oid:n,timestamp:t(),data:{op:"list-insert",index:o,values:[r.value]}}]}else{let o=[],s=i.indexOf(r.value);for(;s!==-1;)o.push(s),s=i.indexOf(r.value,s+1);return o.map(a=>({oid:n,timestamp:t(),data:{op:"list-insert",index:a,value:r.value}}))}case"list-add":return[{oid:n,timestamp:t(),data:{op:"list-remove",value:r.value,only:"last"}}];case"list-set":return[{oid:n,timestamp:t(),data:{op:"list-set",index:r.index,value:i[r.index]}}];case"initialize":return[{oid:n,timestamp:t(),data:{op:"delete"}}];case"touch":return[];default:throw new Error(`Cannot undo operation type: ${r.op}`)}}var ot=class{constructor(i){this.flusher=i,this.batches=new Map,this.flush=e=>{let t=this.batches.get(e);if(t)return t.flush()},this.discard=e=>{let t=this.batches.get(e);t&&(t.discard(),this.batches.delete(e))},this.flushAll=()=>[...this.batches.values()].map(e=>e.flush()),this.getSize=e=>{let t=this.batches.get(e);return t?t.items.length:0}}add({key:i,userData:e,items:t,max:r,timeout:o}){let s=this.batches.get(i);return s||(s=new Ti({max:r||null,startedAt:Date.now(),userData:e,timeout:o||null,flusher:this.flusher,key:i}),this.batches.set(i,s)),s.update({items:t,max:r,timeout:o,userData:e}),s}},Ti=class{constructor({max:i,startedAt:e,timeout:t,userData:r,flusher:o,key:s}){this.items=[],this.update=({items:a,max:u,timeout:d,userData:p})=>{this.items.push(...a),u!==void 0&&(this.max=u),d!==void 0&&(this.timeout=d),p&&(this.userData=p);let S=this.items.length!==0&&this.timeout!==null&&!this.flushTimeout;this.max!==null&&this.items.length>=this.max?this.flush():S&&this.timeout!==null&&(this.flushTimeout=setTimeout(this.flush,this.timeout))},this.flush=()=>{this.flushTimeout&&clearTimeout(this.flushTimeout),this.flushTimeout=void 0;let a=this.items;return this.items=[],this.flusher(a,this.key,this.userData)},this.discard=()=>{this.flushTimeout&&clearTimeout(this.flushTimeout),this.flushTimeout=void 0,this.items=[]},this.max=i,this.startedAt=e,this.timeout=t,this.userData=r,this.flusher=o,this.key=s}};function no(n,i){let e,t;return(...r)=>{let o=i();return e&&e.length===o.length&&e.every((s,a)=>s===o[a])||(e=[...o],t=n(...r)),t}}var _t;(function(n){n[n.InvalidRequest=4e3]="InvalidRequest",n[n.BodyRequired=4001]="BodyRequired",n[n.NoToken=4010]="NoToken",n[n.InvalidToken=4011]="InvalidToken",n[n.TokenExpired=4012]="TokenExpired",n[n.Forbidden=4030]="Forbidden",n[n.NotFound=4040]="NotFound",n[n.Unexpected=5e3]="Unexpected",n[n.ConfigurationError=5010]="ConfigurationError",n[n.NoFileStorage=5011]="NoFileStorage"})(_t||(_t={}));var st=class extends Error{constructor(i,e,t){super(t??`Verdant error: ${i}`,{cause:e}),this.code=i,this.toResponse=()=>JSON.stringify({code:this.code})}get httpStatus(){let i=Math.floor(this.code/10);return i<600?i:500}};st.Code=_t;function io(n){return typeof n=="object"&&"code"in n&&typeof n.code=="number"}function ra(n){return typeof Buffer<"u"?Buffer.from(n).toString("base64"):btoa(n)}function oa(n){return typeof Buffer<"u"?Buffer.from(n,"base64").toString():atob(n)}var We={onlyUser:n=>ra(`u:${n}:*`),onlyMe:()=>We.onlyUser(ki),decode:n=>{let e=oa(n).split(":");if(e.length!==3)throw new Error("Invalid authz string");return{scope:e[0],subject:e[1],action:e[2]}}},ki="$$_originator_$$";function ro(n,i){let{operations:e,baselines:t}=n;if(e)for(let r of e)r.authz&&We.decode(r.authz).subject===ki&&(r.authz=We.onlyUser(i));if(t)for(let r of t)r.authz&&We.decode(r.authz).subject===ki&&(r.authz=We.onlyUser(i))}var Bi=typeof window<"u"?window.indexedDB:void 0;function ue(n){return n instanceof Error&&n.name==="AbortError"}function J(n){return new Promise((i,e)=>{n.onsuccess=()=>{i(n.result)},n.onerror=()=>{n.error&&ue(n.error)?i(n.result):e(n.error)}})}function Qe(n,i){return new Promise((e,t)=>{let r=n.transaction([i],"readonly"),s=r.objectStore(i).openCursor(),a=0,u=0;s.onsuccess=function(d){let p=s.result;p&&(a++,u=u+Vr(p.value),p.continue())},s.onerror=function(d){s.error&&ue(s.error)?e({count:a,size:u}):t(s.error)},r.oncomplete=function(d){e({count:a,size:u})},r.onabort=function(d){t(d)},r.onerror=function(d){t(d)}})}function ln(n,i){let e=n.transaction(i,"readonly"),t=i.map(r=>{let o=e.objectStore(r);return J(o.getAll())});return Promise.all(t)}async function ge(n){n.close(),await new Promise((i,e)=>{i()})}async function dn(n,i=Bi){let e=i.deleteDatabase([n,"meta"].join("_")),t=i.deleteDatabase([n,"collections"].join("_"));await Promise.all([new Promise((r,o)=>{e.onsuccess=r,e.onerror=o}),new Promise((r,o)=>{t.onsuccess=r,t.onerror=o})]),window.location.reload()}function oo(n,i=window.indexedDB){return J(i.deleteDatabase(n))}async function so(n=window.indexedDB){return n.databases()}function un(n,i,e,t,r){let o=n.transaction(i,e);if(t){let s=()=>{r?.("debug","aborting transaction");try{o.abort()}catch(a){r?.("debug","aborting transaction failed",a)}};t.addEventListener("abort",s),o.addEventListener("error",()=>{t.removeEventListener("abort",s)}),o.addEventListener("complete",()=>{t.removeEventListener("abort",s)})}return o}var _e=class{constructor(){this._disposes=[];this.disposed=!1;this.dispose=()=>{this.disposed=!0,this._disposes.forEach(i=>i()),this._disposes=[]};this.addDispose=i=>{this._disposes.push(i)}}};var se=class extends _e{constructor(e,{log:t}={}){super();this.db=e;this.globalAbortController=new AbortController;this.createTransaction=(e,t)=>{let r=un(this.db,e,t?.mode||"readonly",t?.abort,this.log);return this.globalAbortController.signal.addEventListener("abort",r.abort),r.addEventListener("complete",()=>{this.globalAbortController.signal.removeEventListener("abort",r.abort)}),r.addEventListener("error",()=>{this.globalAbortController.signal.removeEventListener("abort",r.abort)}),r};this.run=async(e,t,r)=>{if(this.disposed||r?.transaction?.error)return Promise.resolve(void 0);let s=(r?.transaction||this.createTransaction([e],r)).objectStore(e),a=t(s);return J(a)};this.runAll=async(e,t,r)=>{if(this.disposed||r?.transaction?.error)return Promise.resolve([]);let s=(r?.transaction||this.createTransaction([e],r)).objectStore(e),a=t(s);return Promise.all(a.map(J))};this.iterate=async(e,t,r,o)=>{let a=(o?.transaction||this.createTransaction([e],o)).objectStore(e),u=t(a);return Array.isArray(u)?Promise.all(u.map(d=>new Promise((p,S)=>{d.onsuccess=()=>{let y=d.result;y?(r(y.value,a),y.continue()):p()},d.onerror=()=>{d.error&&ue(d.error)?p():S(d.error)}}))).then(()=>{}):new Promise((d,p)=>{u.onsuccess=()=>{let S=u.result;S?r(S.value,a)?d():S.continue():d()},u.onerror=()=>{u.error&&ue(u.error)?d():p(u.error)}})};this.clear=e=>this.run(e,t=>t.clear(),{mode:"readwrite"});this.log=t,this.addDispose(()=>{this.globalAbortController.abort()})}};var fn=class extends se{constructor(){super(...arguments);this.getAckInfo=async()=>{let e=await this.run("info",t=>t.get("ack"));return e||{globalAckTimestamp:null,type:"ack"}};this.setGlobalAck=async e=>{await this.run("info",t=>t.put({type:"ack",globalAckTimestamp:e}),{mode:"readwrite"})}}};var hn=class extends se{constructor(e,t){super(e,t);this.getAllForDocument=async(e,{mode:t="readonly",transaction:r}={})=>{let o=[];return await this.iterateOverAllForDocument(e,s=>{o.push(s)},{mode:t,transaction:r}),o};this.iterateOverAllForDocument=async(e,t,{mode:r="readonly",transaction:o}={})=>this.iterate("baselines",s=>{let a=$(e),[u,d]=yi(e),[p,S]=wi(e);return[s.openCursor(IDBKeyRange.only(a)),s.openCursor(IDBKeyRange.bound(u,d,!1,!1)),s.openCursor(IDBKeyRange.bound(p,S,!1,!1))]},t,{mode:r,transaction:o});this.iterateOverAllForCollection=async(e,t,{mode:r="readonly",transaction:o}={})=>this.iterate("baselines",s=>[s.openCursor(IDBKeyRange.bound(e,e+"\uFFFF",!1,!1))],t,{mode:r,transaction:o});this.getAllForMultipleDocuments=async(e,{mode:t="readonly"}={})=>(await this.runAll("baselines",o=>e.flatMap(s=>{let a=$(s),[u,d]=yi(s),[p,S]=wi(s);return[o.get(a),o.getAll(IDBKeyRange.bound(u,d,!1,!1)),o.getAll(IDBKeyRange.bound(p,S,!1,!1))]}),{mode:t})).flat();this.getAllSince=async(e,{mode:t="readonly"}={})=>this.run("baselines",r=>{let o=e?IDBKeyRange.lowerBound(e,!0):void 0;return r.index("timestamp").getAll(o)},{mode:t});this.get=async(e,{transaction:t,mode:r="readonly"}={})=>this.run("baselines",o=>o.get(e),{mode:r,transaction:t});this.set=async(e,{transaction:t}={})=>{await this.run("baselines",r=>r.put(e),{mode:"readwrite",transaction:t})};this.setAll=async(e,{transaction:t}={})=>{await this.runAll("baselines",r=>e.map(o=>r.put(o)),{mode:"readwrite",transaction:t})};this.reset=()=>this.clear("baselines");this.delete=async(e,{transaction:t})=>{await this.run("baselines",r=>r.delete(e),{mode:"readwrite",transaction:t})}}};var ao=ke(Ne(),1);var pn=class extends se{constructor(){super(...arguments);this.get=async({transaction:e}={})=>{if(this.cached)return this.cached;let t=await this.run("info",r=>r.get("localReplicaInfo"),{transaction:e});return t?(this.cached=t,t):(this._creating||(this._creating=(async()=>{let o={type:"localReplicaInfo",id:(0,ao.default)(),userId:void 0,ackedLogicalTime:null,lastSyncedLogicalTime:null};await this.run("info",s=>s.put(o),{mode:"readwrite"}),this.cached=o})()),await this._creating,this.get({transaction:e}))};this.update=async(e,{transaction:t}={})=>{let r=await this.get({transaction:t});Object.assign(r,e),await this.run("info",o=>o.put(r),{mode:"readwrite"}),this.cached=r};this.reset=async()=>{let e=await this.get();e.ackedLogicalTime=null,e.lastSyncedLogicalTime=null,await this.run("info",t=>t.put(e),{mode:"readwrite"})}}};var mn=class{constructor(i){this.meta=i;this.createOperation=async i=>{let e=await this.meta.localReplica.get();return{type:"op",timestamp:this.meta.now,replicaId:e.id,operations:i.operations.map(tn)}};this.createMigrationOperation=async({targetVersion:i,...e})=>{let t=await this.meta.localReplica.get();return{type:"op",operations:e.operations.map(r=>({...r,timestamp:this.meta.time.zero(i)})),timestamp:this.meta.time.zero(i),replicaId:t.id}};this.createSyncStep1=async i=>{let e=await this.meta.localReplica.get(),t=i===null?null:e.lastSyncedLogicalTime,r=[],o=new Set;t?await this.meta.operations.iterateOverAllLocalOperations(a=>{r.push(tn(a)),o.add($(a.oid))},{after:t,mode:"readwrite"}):await this.meta.operations.iterateOverAllOperations(a=>{r.push(tn(a)),o.add($(a.oid))},{mode:"readwrite"});let s=[];return t||(s=await this.meta.baselines.getAllSince("")),{type:"sync",schemaVersion:this.meta.schema.currentVersion,timestamp:this.meta.now,replicaId:e.id,resyncAll:!e.lastSyncedLogicalTime,operations:r,baselines:s,since:t}};this.createPresenceUpdate=async i=>{let e=await this.meta.localReplica.get();return{type:"presence-update",presence:i.presence,replicaId:e.id,internal:i.internal}};this.createHeartbeat=async()=>{let i=await this.meta.localReplica.get();return{type:"heartbeat",timestamp:this.meta.now,replicaId:i.id}};this.createAck=async i=>{let e=await this.meta.localReplica.get();return{type:"ack",timestamp:this.meta.now,replicaId:e.id,nonce:i}}}};var gn=class extends se{constructor(e,t){super(e,t);this.iterateOverAllOperationsForDocument=async(e,t,{to:r,from:o,after:s,mode:a="readonly",transaction:u}={})=>{let p=(u||this.createTransaction(["operations"],{mode:a})).objectStore("operations"),S=p.index("d_t"),y=o||s,E=y?de(e,y):He(e),g=r?de(e,r):qe(e),v=IDBKeyRange.bound(E,g,!!s,!1),I=S.openCursor(v,"next");return new Promise((_,O)=>{let R;I.onsuccess=w=>{let D=I.result;if(D){let f=D.value;L(f.oid.startsWith(e)),L(R===void 0||R<=f.timestamp,`expected ${R} <= ${f.timestamp}`),t(f,p),R=f.timestamp,D.continue()}else _()},I.onerror=w=>{if(ue(I.error)){_();return}else O(I.error)}})};this.iterateOverAllOperationsForEntity=async(e,t,{after:r,to:o,mode:s,transaction:a})=>{let d=(a||this.createTransaction(["operations"],{mode:s})).objectStore("operations"),p=r?de(e,r):He(e),S=o?de(e,o):qe(e),y=IDBKeyRange.bound(p,S,!!r,!1),E=d.openCursor(y,"next");return new Promise((g,v)=>{let I;E.onsuccess=_=>{let O=E.result;if(O){let R=O.value;L(R.oid.startsWith(e)),L(I===void 0||I<=R.timestamp,`expected ${I} <= ${R.timestamp}`),t(R,d),I=R.timestamp,O.continue()}else g()},E.onerror=_=>{ue(E.error)?g():v(E.error)}})};this.iterateOverAllOperationsForCollection=async(e,t,{after:r,to:o,mode:s,transaction:a})=>{let u=a||this.createTransaction(["operations"],{mode:s});return this.iterate("operations",d=>d.openCursor(IDBKeyRange.bound(e,e+"\uFFFF",!1,!1),"next"),t,{mode:s,transaction:u})};this.iterateOverAllLocalOperations=async(e,{before:t,after:r,mode:o="readonly",transaction:s})=>{let u=(s||this.createTransaction(["operations"],{mode:o})).objectStore("operations"),d=u.index("l_t"),p=r?de(!0,r):He(!0),S=t?de(!0,t):qe(!0),y=IDBKeyRange.bound(p,S,!!r,!0),E=d.openCursor(y,"next");return new Promise((g,v)=>{let I;E.onsuccess=_=>{let O=E.result;if(O){let R=O.value;L(I===void 0||I<=R.timestamp,`expected ${I} <= ${R.timestamp}`),e(R,u),I=R.timestamp,O.continue()}else g()},E.onerror=_=>{ue(E.error)?g():v(E.error)}})};this.iterateOverAllOperations=async(e,{before:t,transaction:r,mode:o,from:s})=>{await this.iterate("operations",a=>{let u=s?He(s):void 0,d=t?qe(t):void 0,p=u&&d?IDBKeyRange.bound(u,d,!1,!0):u?IDBKeyRange.lowerBound(u,!1):d?IDBKeyRange.upperBound(d,!0):void 0;return a.index("timestamp").openCursor(p,"next")},e,{mode:o,transaction:r})};this.addOperations=async(e,{transaction:t}={})=>this.insert(e.map(this.addCompoundIndexes),{transaction:t});this.addCompoundIndexes=e=>({...e,oid_timestamp:de(e.oid,e.timestamp),l_t:de(e.isLocal,e.timestamp),d_t:de($(e.oid),e.timestamp)});this.insert=async(e,{transaction:t})=>{let r=new Set;return await this.runAll("operations",o=>e.map(s=>(r.add($(s.oid)),o.put(s))),{mode:"readwrite",transaction:t}),Array.from(r)};this.reset=()=>this.clear("operations")}};var yn=class{constructor(i,e){this.db=i;this.currentVersion=e;this.cached=null;this.get=async()=>{if(this.cached)return this.cached;let r=this.db.transaction("info","readonly").objectStore("info").get("schema"),o=await J(r);return o?(this.cached=JSON.parse(o.schema),this.cached):null};this.set=async i=>{let o=this.db.transaction("info","readwrite").objectStore("info").put({type:"schema",schema:JSON.stringify(i)});this.cached=i,await J(o)}}};var Dt=class extends z{constructor({disableRebasing:e,context:t,onOperation:r}){super();this.time=new Ut;this.disableRebasing=!1;this._closing=!1;this.setContext=e=>{this.context=e};this.close=()=>{this._closing=!0};this.createTransaction=(e,t={})=>un(this.db,e,t.write?"readwrite":"readonly",t.abort,this.context.log);this.getAllDocumentRelatedOids=async e=>{let t=new Set,r=$(e);L(r===e,"Must be root document OID"),t.add(r);let o=this.createTransaction(["baselines","operations"]);return await Promise.all([this.baselines.iterateOverAllForDocument(r,s=>{t.add(s.oid)},{transaction:o}),this.operations.iterateOverAllOperationsForDocument(r,s=>{t.add(s.oid)},{transaction:o})]),Array.from(t)};this.getAllCollectionRelatedOids=async e=>{let t=new Set,r=this.db.transaction(["baselines","operations"],"readwrite");return await Promise.all([this.baselines.iterateOverAllForCollection(e,o=>{t.add(o.oid)},{transaction:r}),this.operations.iterateOverAllOperationsForCollection(e,o=>{t.add(o.oid)},{transaction:r})]),Array.from(t)};this.getDocumentSnapshot=async(e,t={})=>{let r=$(e);L(r===e,"Must be root document OID");let o=this.db.transaction(["baselines","operations"],"readwrite"),s=await this.baselines.getAllForDocument(r,{transaction:o}),a=new Map;for(let d of s)d.snapshot&&N(d.snapshot,d.oid),a.set(d.oid,d.snapshot);await this.operations.iterateOverAllOperationsForDocument(r,d=>{let p=a.get(d.oid)||void 0,S=$e(p,d.data);S&&N(S,d.oid),a.set(d.oid,S)},{transaction:o,to:t.to||this.now});let u=a.get(r);return u&&en(u,a),u};this.getDocumentData=async(e,t)=>{let r=this.createTransaction(["baselines","operations"],t),o=[],s={};return await Promise.all([this.baselines.iterateOverAllForDocument(e,a=>{o.push(a)},{transaction:r}),this.operations.iterateOverAllOperationsForDocument(e,a=>{s[a.oid]??=[],s[a.oid].push(a)},{transaction:r})]),{baselines:o,operations:s}};this.getDocumentAuthz=async e=>{let t=await this.baselines.get(e);if(t)return t.authz;let r;return await this.operations.iterateOverAllOperationsForEntity(e,o=>{if(o.data.op==="initialize")return r=o.authz,!0},{}),r};this.ack=async e=>{let t=await this.localReplica.get();e>this.now||(this.emit("message",{type:"ack",replicaId:t.id,timestamp:e}),!this._closing&&(!t.ackedLogicalTime||e>t.ackedLogicalTime)&&this.localReplica.update({ackedLogicalTime:e}))};this.insertLocalOperations=async(e,t)=>{if(e.length===0)return;this.log("debug",`Inserting ${e.length} local operations`,e);for(let o of e)o.isLocal=!0;await this.operations.addOperations(e,t);let r=await this.messageCreator.createOperation({operations:e});this.emit("message",r),this.tryAutonomousRebase(),this.onOperation&&e.forEach(o=>this.onOperation(o))};this.insertRemoteOperations=async(e,t)=>{if(e.length===0)return[];this.log("debug",`Inserting ${e.length} remote operations`,e);let r=await this.operations.addOperations(e.map(o=>({...o,isLocal:!1})),t);return this.ack(e[e.length-1].timestamp),this.onOperation&&e.forEach(o=>this.onOperation(o)),r};this.insertRemoteBaselines=async(e,t)=>{if(e.length===0)return[];this.log("debug",`Inserting ${e.length} remote baselines`),await this.baselines.setAll(e,t);let r=new Set;return e.forEach(o=>{r.add($(o.oid))}),Array.from(r)};this.insertData=async(e,t)=>{let r=this.createTransaction(["baselines","operations"],{...t,write:!0});e.baselines&&await this.insertRemoteBaselines(e.baselines,{transaction:r}),!t?.abort?.aborted&&e.operations&&(e.isLocal?await this.insertLocalOperations(e.operations,{transaction:r}):await this.insertRemoteOperations(e.operations,{transaction:r}))};this.updateLastSynced=async e=>{if(!this._closing)return this.localReplica.update({lastSyncedLogicalTime:e})};this.lastSyncedTimestamp=async()=>(await this.localReplica.get()).lastSyncedLogicalTime;this.tryAutonomousRebase=async()=>{this.disableRebasing||(await this.localReplica.get()).lastSyncedLogicalTime||await this.runRebase(this.now)};this.runRebase=async e=>{if(this._closing)return;let t,r=new Set,o=this.createTransaction(["baselines","operations"],{write:!0}),s=0;if(await this.operations.iterateOverAllOperations(u=>{r.add(u.oid),t=u.timestamp,s++},{before:e,transaction:o}),!r.size||this._closing)return;let a=[];for(let u of r)a.push(await this.rebase(u,t||e,o));this.emit("rebase",a)};this.rebase=async(e,t,r)=>{let o=(await this.localReplica.get()).id;this.log("debug","[",o,"]","Rebasing",e,"up to",t);let s=r||this.createTransaction(["operations","baselines"],{write:!0}),a=await this.baselines.get(e,{transaction:s}),u=a?.snapshot||void 0,d=0,p=a?.authz,S=[];await this.operations.iterateOverAllOperationsForEntity(e,(E,g)=>{(!a||E.timestamp>a.timestamp)&&(u=$e(u,E.data,S),E.data.op==="initialize"&&(p=E.authz)),d++,g.delete(E.oid_timestamp)},{to:t,transaction:s}),u&&N(u,e);let y={oid:e,snapshot:u,timestamp:t,authz:p};if(y.snapshot?await this.baselines.set(y,{transaction:s}):await this.baselines.delete(e,{transaction:s}),this.log("debug","successfully rebased",e,"up to",t,":",u,"and deleted",d,"operations"),S.length){let E=S.filter(we);E.length&&this.emit("filesDeleted",E)}return y};this.reset=async()=>{await this.operations.reset(),await this.baselines.reset(),await this.localReplica.reset()};this.updateSchema=async(e,t)=>{let r=await this.schema.get();if(r&&t===r.version&&r.version===e.version&&JSON.stringify(r)!==JSON.stringify(e))throw console.error(`Schema mismatch for version ${e.version}
6
+ `))}O.fill(0),e.createHash=function(l){return R(l)},e.createHmac=R,e.randomBytes=function(l,x){if(!x||!x.call)return new y(v(l));try{x.call(this,void 0,new y(v(l)))}catch(C){x(C)}};var D,f=["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],m=function(l){e[l]=function(){w("sorry,",l,"is not implemented yet")}};for(D in f)m(f[D],D)}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./md5":6,"./rng":7,"./sha":8,"./sha256":9,buffer:3,lYpoI2:11}],6:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){var y=n("./helpers");function E(w,D){w[D>>5]|=128<<D%32,w[14+(D+64>>>9<<4)]=D;for(var f=1732584193,m=-271733879,l=-1732584194,x=271733878,C=0;C<w.length;C+=16){var j=f,B=m,M=l,k=x,f=v(f,m,l,x,w[C+0],7,-680876936),x=v(x,f,m,l,w[C+1],12,-389564586),l=v(l,x,f,m,w[C+2],17,606105819),m=v(m,l,x,f,w[C+3],22,-1044525330);f=v(f,m,l,x,w[C+4],7,-176418897),x=v(x,f,m,l,w[C+5],12,1200080426),l=v(l,x,f,m,w[C+6],17,-1473231341),m=v(m,l,x,f,w[C+7],22,-45705983),f=v(f,m,l,x,w[C+8],7,1770035416),x=v(x,f,m,l,w[C+9],12,-1958414417),l=v(l,x,f,m,w[C+10],17,-42063),m=v(m,l,x,f,w[C+11],22,-1990404162),f=v(f,m,l,x,w[C+12],7,1804603682),x=v(x,f,m,l,w[C+13],12,-40341101),l=v(l,x,f,m,w[C+14],17,-1502002290),f=I(f,m=v(m,l,x,f,w[C+15],22,1236535329),l,x,w[C+1],5,-165796510),x=I(x,f,m,l,w[C+6],9,-1069501632),l=I(l,x,f,m,w[C+11],14,643717713),m=I(m,l,x,f,w[C+0],20,-373897302),f=I(f,m,l,x,w[C+5],5,-701558691),x=I(x,f,m,l,w[C+10],9,38016083),l=I(l,x,f,m,w[C+15],14,-660478335),m=I(m,l,x,f,w[C+4],20,-405537848),f=I(f,m,l,x,w[C+9],5,568446438),x=I(x,f,m,l,w[C+14],9,-1019803690),l=I(l,x,f,m,w[C+3],14,-187363961),m=I(m,l,x,f,w[C+8],20,1163531501),f=I(f,m,l,x,w[C+13],5,-1444681467),x=I(x,f,m,l,w[C+2],9,-51403784),l=I(l,x,f,m,w[C+7],14,1735328473),f=_(f,m=I(m,l,x,f,w[C+12],20,-1926607734),l,x,w[C+5],4,-378558),x=_(x,f,m,l,w[C+8],11,-2022574463),l=_(l,x,f,m,w[C+11],16,1839030562),m=_(m,l,x,f,w[C+14],23,-35309556),f=_(f,m,l,x,w[C+1],4,-1530992060),x=_(x,f,m,l,w[C+4],11,1272893353),l=_(l,x,f,m,w[C+7],16,-155497632),m=_(m,l,x,f,w[C+10],23,-1094730640),f=_(f,m,l,x,w[C+13],4,681279174),x=_(x,f,m,l,w[C+0],11,-358537222),l=_(l,x,f,m,w[C+3],16,-722521979),m=_(m,l,x,f,w[C+6],23,76029189),f=_(f,m,l,x,w[C+9],4,-640364487),x=_(x,f,m,l,w[C+12],11,-421815835),l=_(l,x,f,m,w[C+15],16,530742520),f=O(f,m=_(m,l,x,f,w[C+2],23,-995338651),l,x,w[C+0],6,-198630844),x=O(x,f,m,l,w[C+7],10,1126891415),l=O(l,x,f,m,w[C+14],15,-1416354905),m=O(m,l,x,f,w[C+5],21,-57434055),f=O(f,m,l,x,w[C+12],6,1700485571),x=O(x,f,m,l,w[C+3],10,-1894986606),l=O(l,x,f,m,w[C+10],15,-1051523),m=O(m,l,x,f,w[C+1],21,-2054922799),f=O(f,m,l,x,w[C+8],6,1873313359),x=O(x,f,m,l,w[C+15],10,-30611744),l=O(l,x,f,m,w[C+6],15,-1560198380),m=O(m,l,x,f,w[C+13],21,1309151649),f=O(f,m,l,x,w[C+4],6,-145523070),x=O(x,f,m,l,w[C+11],10,-1120210379),l=O(l,x,f,m,w[C+2],15,718787259),m=O(m,l,x,f,w[C+9],21,-343485551),f=R(f,j),m=R(m,B),l=R(l,M),x=R(x,k)}return Array(f,m,l,x)}function g(w,D,f,m,l,x){return R((D=R(R(D,w),R(m,x)))<<l|D>>>32-l,f)}function v(w,D,f,m,l,x,C){return g(D&f|~D&m,w,D,l,x,C)}function I(w,D,f,m,l,x,C){return g(D&m|f&~m,w,D,l,x,C)}function _(w,D,f,m,l,x,C){return g(D^f^m,w,D,l,x,C)}function O(w,D,f,m,l,x,C){return g(f^(D|~m),w,D,l,x,C)}function R(w,D){var f=(65535&w)+(65535&D);return(w>>16)+(D>>16)+(f>>16)<<16|65535&f}i.exports=function(w){return y.hash(w,E,16)}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:11}],7:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){var y;i.exports=y||function(E){for(var g,v=new Array(E),I=0;I<E;I++)!(3&I)&&(g=4294967296*Math.random()),v[I]=g>>>((3&I)<<3)&255;return v}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:11}],8:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){var y=n("./helpers");function E(I,_){I[_>>5]|=128<<24-_%32,I[15+(_+64>>9<<4)]=_;for(var O,R,w,D=Array(80),f=1732584193,m=-271733879,l=-1732584194,x=271733878,C=-1009589776,j=0;j<I.length;j+=16){for(var B=f,M=m,k=l,q=x,te=C,H=0;H<80;H++){D[H]=H<16?I[j+H]:v(D[H-3]^D[H-8]^D[H-14]^D[H-16],1);var K=g(g(v(f,5),(K=m,R=l,w=x,(O=H)<20?K&R|~K&w:!(O<40)&&O<60?K&R|K&w|R&w:K^R^w)),g(g(C,D[H]),(O=H)<20?1518500249:O<40?1859775393:O<60?-1894007588:-899497514)),C=x,x=l,l=v(m,30),m=f,f=K}f=g(f,B),m=g(m,M),l=g(l,k),x=g(x,q),C=g(C,te)}return Array(f,m,l,x,C)}function g(I,_){var O=(65535&I)+(65535&_);return(I>>16)+(_>>16)+(O>>16)<<16|65535&O}function v(I,_){return I<<_|I>>>32-_}i.exports=function(I){return y.hash(I,E,20,!0)}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:11}],9:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){function y(_,O){var R=(65535&_)+(65535&O);return(_>>16)+(O>>16)+(R>>16)<<16|65535&R}function E(_,O){var R,w=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),D=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),f=new Array(64);_[O>>5]|=128<<24-O%32,_[15+(O+64>>9<<4)]=O;for(var m,l,x=0;x<_.length;x+=16){for(var C=D[0],j=D[1],B=D[2],M=D[3],k=D[4],q=D[5],te=D[6],H=D[7],K=0;K<64;K++)f[K]=K<16?_[K+x]:y(y(y((l=f[K-2],v(l,17)^v(l,19)^I(l,10)),f[K-7]),(l=f[K-15],v(l,7)^v(l,18)^I(l,3))),f[K-16]),R=y(y(y(y(H,v(l=k,6)^v(l,11)^v(l,25)),k&q^~k&te),w[K]),f[K]),m=y(v(m=C,2)^v(m,13)^v(m,22),C&j^C&B^j&B),H=te,te=q,q=k,k=y(M,R),M=B,B=j,j=C,C=y(R,m);D[0]=y(C,D[0]),D[1]=y(j,D[1]),D[2]=y(B,D[2]),D[3]=y(M,D[3]),D[4]=y(k,D[4]),D[5]=y(q,D[5]),D[6]=y(te,D[6]),D[7]=y(H,D[7])}return D}var g=n("./helpers"),v=function(_,O){return _>>>O|_<<32-O},I=function(_,O){return _>>>O};i.exports=function(_){return g.hash(_,E,32,!0)}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:11}],10:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){e.read=function(y,E,g,v,x){var _,O,R=8*x-v-1,w=(1<<R)-1,D=w>>1,f=-7,m=g?x-1:0,l=g?-1:1,x=y[E+m];for(m+=l,_=x&(1<<-f)-1,x>>=-f,f+=R;0<f;_=256*_+y[E+m],m+=l,f-=8);for(O=_&(1<<-f)-1,_>>=-f,f+=v;0<f;O=256*O+y[E+m],m+=l,f-=8);if(_===0)_=1-D;else{if(_===w)return O?NaN:1/0*(x?-1:1);O+=Math.pow(2,v),_-=D}return(x?-1:1)*O*Math.pow(2,_-v)},e.write=function(y,E,g,v,I,C){var O,R,w=8*C-I-1,D=(1<<w)-1,f=D>>1,m=I===23?Math.pow(2,-24)-Math.pow(2,-77):0,l=v?0:C-1,x=v?1:-1,C=E<0||E===0&&1/E<0?1:0;for(E=Math.abs(E),isNaN(E)||E===1/0?(R=isNaN(E)?1:0,O=D):(O=Math.floor(Math.log(E)/Math.LN2),E*(v=Math.pow(2,-O))<1&&(O--,v*=2),2<=(E+=1<=O+f?m/v:m*Math.pow(2,1-f))*v&&(O++,v/=2),D<=O+f?(R=0,O=D):1<=O+f?(R=(E*v-1)*Math.pow(2,I),O+=f):(R=E*Math.pow(2,f-1)*Math.pow(2,I),O=0));8<=I;y[g+l]=255&R,l+=x,R/=256,I-=8);for(O=O<<I|R,w+=I;0<w;y[g+l]=255&O,l+=x,O/=256,w-=8);y[g+l-x]|=128*C}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/ieee754/index.js","/node_modules/gulp-browserify/node_modules/ieee754")},{buffer:3,lYpoI2:11}],11:[function(n,i,e){(function(t,r,o,s,a,u,d,p,S){var y,E,g;function v(){}(t=i.exports={}).nextTick=(E=typeof window<"u"&&window.setImmediate,g=typeof window<"u"&&window.postMessage&&window.addEventListener,E?function(I){return window.setImmediate(I)}:g?(y=[],window.addEventListener("message",function(I){var _=I.source;_!==window&&_!==null||I.data!=="process-tick"||(I.stopPropagation(),0<y.length&&y.shift()())},!0),function(I){y.push(I),window.postMessage("process-tick","*")}):function(I){setTimeout(I,0)}),t.title="browser",t.browser=!0,t.env={},t.argv=[],t.on=v,t.addListener=v,t.once=v,t.off=v,t.removeListener=v,t.removeAllListeners=v,t.emit=v,t.binding=function(I){throw new Error("process.binding is not supported")},t.cwd=function(){return"/"},t.chdir=function(I){throw new Error("process.chdir is not supported")}}).call(this,n("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},n("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/process/browser.js","/node_modules/gulp-browserify/node_modules/process")},{buffer:3,lYpoI2:11}]},{},[1])(1)})});var Ge={};ur(Ge,{__addDisposableResource:()=>No,__assign:()=>Cn,__asyncDelegator:()=>ko,__asyncGenerator:()=>To,__asyncValues:()=>Bo,__await:()=>dt,__awaiter:()=>Eo,__classPrivateFieldGet:()=>Vo,__classPrivateFieldIn:()=>zo,__classPrivateFieldSet:()=>Uo,__createBinding:()=>An,__decorate:()=>Io,__disposeResources:()=>$o,__esDecorate:()=>Aa,__exportStar:()=>Po,__extends:()=>So,__generator:()=>Co,__importDefault:()=>Lo,__importStar:()=>Mo,__makeTemplateObject:()=>jo,__metadata:()=>Do,__param:()=>_o,__propKey:()=>Fa,__read:()=>Ni,__rest:()=>Oo,__runInitializers:()=>Ra,__setFunctionName:()=>Ta,__spread:()=>Ao,__spreadArray:()=>Fo,__spreadArrays:()=>Ro,__values:()=>Pn,default:()=>ja});function So(n,i){if(typeof i!="function"&&i!==null)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");zi(n,i);function e(){this.constructor=n}n.prototype=i===null?Object.create(i):(e.prototype=i.prototype,new e)}function Oo(n,i){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&i.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(n);r<t.length;r++)i.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(n,t[r])&&(e[t[r]]=n[t[r]]);return e}function Io(n,i,e,t){var r=arguments.length,o=r<3?i:t===null?t=Object.getOwnPropertyDescriptor(i,e):t,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(n,i,e,t);else for(var a=n.length-1;a>=0;a--)(s=n[a])&&(o=(r<3?s(o):r>3?s(i,e,o):s(i,e))||o);return r>3&&o&&Object.defineProperty(i,e,o),o}function _o(n,i){return function(e,t){i(e,t,n)}}function Aa(n,i,e,t,r,o){function s(_){if(_!==void 0&&typeof _!="function")throw new TypeError("Function expected");return _}for(var a=t.kind,u=a==="getter"?"get":a==="setter"?"set":"value",d=!i&&n?t.static?n:n.prototype:null,p=i||(d?Object.getOwnPropertyDescriptor(d,t.name):{}),S,y=!1,E=e.length-1;E>=0;E--){var g={};for(var v in t)g[v]=v==="access"?{}:t[v];for(var v in t.access)g.access[v]=t.access[v];g.addInitializer=function(_){if(y)throw new TypeError("Cannot add initializers after decoration has completed");o.push(s(_||null))};var I=(0,e[E])(a==="accessor"?{get:p.get,set:p.set}:p[u],g);if(a==="accessor"){if(I===void 0)continue;if(I===null||typeof I!="object")throw new TypeError("Object expected");(S=s(I.get))&&(p.get=S),(S=s(I.set))&&(p.set=S),(S=s(I.init))&&r.unshift(S)}else(S=s(I))&&(a==="field"?r.unshift(S):p[u]=S)}d&&Object.defineProperty(d,t.name,p),y=!0}function Ra(n,i,e){for(var t=arguments.length>2,r=0;r<i.length;r++)e=t?i[r].call(n,e):i[r].call(n);return t?e:void 0}function Fa(n){return typeof n=="symbol"?n:"".concat(n)}function Ta(n,i,e){return typeof i=="symbol"&&(i=i.description?"[".concat(i.description,"]"):""),Object.defineProperty(n,"name",{configurable:!0,value:e?"".concat(e," ",i):i})}function Do(n,i){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,i)}function Eo(n,i,e,t){function r(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function a(p){try{d(t.next(p))}catch(S){s(S)}}function u(p){try{d(t.throw(p))}catch(S){s(S)}}function d(p){p.done?o(p.value):r(p.value).then(a,u)}d((t=t.apply(n,i||[])).next())})}function Co(n,i){var e={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},t,r,o,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(d){return function(p){return u([d,p])}}function u(d){if(t)throw new TypeError("Generator is already executing.");for(;s&&(s=0,d[0]&&(e=0)),e;)try{if(t=1,r&&(o=d[0]&2?r.return:d[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,d[1])).done)return o;switch(r=0,o&&(d=[d[0]&2,o.value]),d[0]){case 0:case 1:o=d;break;case 4:return e.label++,{value:d[1],done:!1};case 5:e.label++,r=d[1],d=[0];continue;case 7:d=e.ops.pop(),e.trys.pop();continue;default:if(o=e.trys,!(o=o.length>0&&o[o.length-1])&&(d[0]===6||d[0]===2)){e=0;continue}if(d[0]===3&&(!o||d[1]>o[0]&&d[1]<o[3])){e.label=d[1];break}if(d[0]===6&&e.label<o[1]){e.label=o[1],o=d;break}if(o&&e.label<o[2]){e.label=o[2],e.ops.push(d);break}o[2]&&e.ops.pop(),e.trys.pop();continue}d=i.call(n,e)}catch(p){d=[6,p],r=0}finally{t=o=0}if(d[0]&5)throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}}function Po(n,i){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(i,e)&&An(i,n,e)}function Pn(n){var i=typeof Symbol=="function"&&Symbol.iterator,e=i&&n[i],t=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&t>=n.length&&(n=void 0),{value:n&&n[t++],done:!n}}};throw new TypeError(i?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ni(n,i){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var t=e.call(n),r,o=[],s;try{for(;(i===void 0||i-- >0)&&!(r=t.next()).done;)o.push(r.value)}catch(a){s={error:a}}finally{try{r&&!r.done&&(e=t.return)&&e.call(t)}finally{if(s)throw s.error}}return o}function Ao(){for(var n=[],i=0;i<arguments.length;i++)n=n.concat(Ni(arguments[i]));return n}function Ro(){for(var n=0,i=0,e=arguments.length;i<e;i++)n+=arguments[i].length;for(var t=Array(n),r=0,i=0;i<e;i++)for(var o=arguments[i],s=0,a=o.length;s<a;s++,r++)t[r]=o[s];return t}function Fo(n,i,e){if(e||arguments.length===2)for(var t=0,r=i.length,o;t<r;t++)(o||!(t in i))&&(o||(o=Array.prototype.slice.call(i,0,t)),o[t]=i[t]);return n.concat(o||Array.prototype.slice.call(i))}function dt(n){return this instanceof dt?(this.v=n,this):new dt(n)}function To(n,i,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e.apply(n,i||[]),r,o=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(y){t[y]&&(r[y]=function(E){return new Promise(function(g,v){o.push([y,E,g,v])>1||a(y,E)})})}function a(y,E){try{u(t[y](E))}catch(g){S(o[0][3],g)}}function u(y){y.value instanceof dt?Promise.resolve(y.value.v).then(d,p):S(o[0][2],y)}function d(y){a("next",y)}function p(y){a("throw",y)}function S(y,E){y(E),o.shift(),o.length&&a(o[0][0],o[0][1])}}function ko(n){var i,e;return i={},t("next"),t("throw",function(r){throw r}),t("return"),i[Symbol.iterator]=function(){return this},i;function t(r,o){i[r]=n[r]?function(s){return(e=!e)?{value:dt(n[r](s)),done:!1}:o?o(s):s}:o}}function Bo(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=n[Symbol.asyncIterator],e;return i?i.call(n):(n=typeof Pn=="function"?Pn(n):n[Symbol.iterator](),e={},t("next"),t("throw"),t("return"),e[Symbol.asyncIterator]=function(){return this},e);function t(o){e[o]=n[o]&&function(s){return new Promise(function(a,u){s=n[o](s),r(a,u,s.done,s.value)})}}function r(o,s,a,u){Promise.resolve(u).then(function(d){o({value:d,done:a})},s)}}function jo(n,i){return Object.defineProperty?Object.defineProperty(n,"raw",{value:i}):n.raw=i,n}function Mo(n){if(n&&n.__esModule)return n;var i={};if(n!=null)for(var e in n)e!=="default"&&Object.prototype.hasOwnProperty.call(n,e)&&An(i,n,e);return ka(i,n),i}function Lo(n){return n&&n.__esModule?n:{default:n}}function Vo(n,i,e,t){if(e==="a"&&!t)throw new TypeError("Private accessor was defined without a getter");if(typeof i=="function"?n!==i||!t:!i.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?t:e==="a"?t.call(n):t?t.value:i.get(n)}function Uo(n,i,e,t,r){if(t==="m")throw new TypeError("Private method is not writable");if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof i=="function"?n!==i||!r:!i.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t==="a"?r.call(n,e):r?r.value=e:i.set(n,e),e}function zo(n,i){if(i===null||typeof i!="object"&&typeof i!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof n=="function"?i===n:n.has(i)}function No(n,i,e){if(i!=null){if(typeof i!="object"&&typeof i!="function")throw new TypeError("Object expected.");var t;if(e){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");t=i[Symbol.asyncDispose]}if(t===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");t=i[Symbol.dispose]}if(typeof t!="function")throw new TypeError("Object not disposable.");n.stack.push({value:i,dispose:t,async:e})}else e&&n.stack.push({async:!0});return i}function $o(n){function i(t){n.error=n.hasError?new Ba(t,n.error,"An error was suppressed during disposal."):t,n.hasError=!0}function e(){for(;n.stack.length;){var t=n.stack.pop();try{var r=t.dispose&&t.dispose.call(t.value);if(t.async)return Promise.resolve(r).then(e,function(o){return i(o),e()})}catch(o){i(o)}}if(n.hasError)throw n.error}return e()}var zi,Cn,An,ka,Ba,ja,Ye=fs(()=>{zi=function(n,i){return zi=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},zi(n,i)};Cn=function(){return Cn=Object.assign||function(i){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(i[o]=e[o])}return i},Cn.apply(this,arguments)};An=Object.create?function(n,i,e,t){t===void 0&&(t=e);var r=Object.getOwnPropertyDescriptor(i,e);(!r||("get"in r?!i.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return i[e]}}),Object.defineProperty(n,t,r)}:function(n,i,e,t){t===void 0&&(t=e),n[t]=i[e]};ka=Object.create?function(n,i){Object.defineProperty(n,"default",{enumerable:!0,value:i})}:function(n,i){n.default=i};Ba=typeof SuppressedError=="function"?SuppressedError:function(n,i,e){var t=new Error(e);return t.name="SuppressedError",t.error=n,t.suppressed=i,t};ja={__extends:So,__assign:Cn,__rest:Oo,__decorate:Io,__param:_o,__metadata:Do,__awaiter:Eo,__generator:Co,__createBinding:An,__exportStar:Po,__values:Pn,__read:Ni,__spread:Ao,__spreadArrays:Ro,__spreadArray:Fo,__await:dt,__asyncGenerator:To,__asyncDelegator:ko,__asyncValues:Bo,__makeTemplateObject:jo,__importStar:Mo,__importDefault:Lo,__classPrivateFieldGet:Vo,__classPrivateFieldSet:Uo,__classPrivateFieldIn:zo,__addDisposableResource:No,__disposeResources:$o}});var qo=oe(Ko=>{"use strict";Object.defineProperty(Ko,"__esModule",{value:!0})});var Ki=oe(De=>{"use strict";Object.defineProperty(De,"__esModule",{value:!0});De.invokeEventHandlersAsync=De.invokeEventHandlers=De.eventHandlerSafeInvokeAsync=De.eventHandlerSafeInvoke=void 0;var Ho=(Ye(),et(Ge));function Wo(n,i,e){try{return n(i,e),{succeeded:!0}}catch(t){return{error:t,succeeded:!1}}}De.eventHandlerSafeInvoke=Wo;function $i(n,i,e){return(0,Ho.__awaiter)(this,void 0,void 0,function*(){try{return yield n(i,e),{succeeded:!0}}catch(t){return{error:t,succeeded:!1}}})}De.eventHandlerSafeInvokeAsync=$i;function Ma(n,i,e,t){for(let r of n){let{succeeded:o,error:s}=Wo(r,i,e);if(!o&&t?.swallowExceptions!==!0)throw s}}De.invokeEventHandlers=Ma;function La(n,i,e,t){return(0,Ho.__awaiter)(this,void 0,void 0,function*(){if(t?.parallelize===!1)for(let r of n){let{succeeded:o,error:s}=yield $i(r,i,e);if(!o&&t?.swallowExceptions!==!0)throw s}else{let r=[];for(let o of n)r.push($i(o,i,e).then(({succeeded:s,error:a})=>{if(!s&&t?.swallowExceptions!==!0)throw a}));yield Promise.all(r)}})}De.invokeEventHandlersAsync=La});var Go=oe(Rn=>{"use strict";Object.defineProperty(Rn,"__esModule",{value:!0});Rn.TypedEvent=void 0;var Va=(Ye(),et(Ge)),Qo=Ki(),Jo={swallowExceptions:!1,parallelize:!0},qi=class{constructor(){this._handlers=[]}attach(i){this._handlers.push(i)}detach(i){this.tryRemoveHandler(i)}invoke(i,e,t=Jo){(0,Qo.invokeEventHandlers)(this._handlers,i,e,t)}invokeAsync(i,e,t=Jo){return(0,Va.__awaiter)(this,void 0,void 0,function*(){yield(0,Qo.invokeEventHandlersAsync)(this._handlers,i,e,t)})}tryRemoveHandler(i){let e=this._handlers.findIndex(t=>t===i);e>=0&&this._handlers.splice(e,1)}};Rn.TypedEvent=qi});var Wi=oe(Hi=>{"use strict";Object.defineProperty(Hi,"__esModule",{value:!0});var Ua=(Ye(),et(Ge));(0,Ua.__exportStar)(Go(),Hi)});var Yo=oe(Fn=>{"use strict";Object.defineProperty(Fn,"__esModule",{value:!0});Fn.FinalizationRegistryMissingError=void 0;var Qi=class extends Error{};Fn.FinalizationRegistryMissingError=Qi});var Gi=oe(Tn=>{"use strict";Object.defineProperty(Tn,"__esModule",{value:!0});Tn.WeakHandlerHolder=void 0;var za=Yo(),Ji=class{constructor(i){this._refs=[];try{this._finalizationRegistry=new FinalizationRegistry(i)}catch(e){throw e.name==="FinalizationRegistry"?new za.FinalizationRegistryMissingError("FinalizationRegistry is not defined. Weak Events cannot be used. Please consult 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry' for compatibility information"):e}}getWeakHandler(i,e){let t=new WeakRef(e);return this._finalizationRegistry.register(e,{eventSource:i,handlerRef:t},t),this._refs.push(t),t}releaseWeakHandler(i){let t=this._refs.find(r=>r?.deref()===i)||new WeakRef(i);return this._finalizationRegistry.unregister(t),t}unregisterRef(i){this._finalizationRegistry.unregister(i)}};Tn.WeakHandlerHolder=Ji});var Xo=oe(kn=>{"use strict";Object.defineProperty(kn,"__esModule",{value:!0});kn.WeakEvent=void 0;var Yi=(Ye(),et(Ge)),Na=Wi(),$a=Gi(),Xi=Ki(),Ka={swallowExceptions:!1,parallelize:!0},Zi=class{constructor(){this._handlers=[],this._handlerFinalizedEvent=new Na.TypedEvent,this.handlerFinalizedEvent=this._handlerFinalizedEvent,this._refHolder=new $a.WeakHandlerHolder(i=>{this.onHandlerFinalizer(i)})}invoke(i,e,t){for(let r of this._handlers){let o=r?.deref();if(o){let{succeeded:s,error:a}=(0,Xi.eventHandlerSafeInvoke)(o,i,e);if(!s&&t?.swallowExceptions!==!0)throw a}else this.releaseHandler(r)}}invokeAsync(i,e,t=Ka){return(0,Yi.__awaiter)(this,void 0,void 0,function*(){t?.parallelize===!1?yield this.sequentialInvokeAsync(i,e,t):yield this.parallelInvokeAsync(i,e,t)})}sequentialInvokeAsync(i,e,t){return(0,Yi.__awaiter)(this,void 0,void 0,function*(){for(let r of this._handlers){let o=r?.deref();if(o){let{succeeded:s,error:a}=yield(0,Xi.eventHandlerSafeInvokeAsync)(o,i,e);if(!s&&t.swallowExceptions!==!0)throw a}else this.releaseHandler(r)}})}parallelInvokeAsync(i,e,t){return(0,Yi.__awaiter)(this,void 0,void 0,function*(){let r=[];for(let o of this._handlers){let s=o?.deref();s?r.push((0,Xi.eventHandlerSafeInvokeAsync)(s,i,e).then(({succeeded:a,error:u})=>{if(!a&&t.swallowExceptions!==!0)throw u})):this.releaseHandler(o)}yield Promise.all(r)})}attach(i){this._handlers.push(this._refHolder.getWeakHandler(this,i))}detach(i){let e=this._refHolder.releaseWeakHandler(i);this.tryRemoveHandlerRef(e)}onHandlerFinalizer(i){this.tryRemoveHandlerRef(i?.handlerRef),this._handlerFinalizedEvent.invokeAsync(this,i,{swallowExceptions:!0})}tryRemoveHandlerRef(i){let e=this._handlers.findIndex(t=>t===i);e>=0&&this._handlers.splice(e,1)}releaseHandler(i){this._refHolder.unregisterRef(i),this.tryRemoveHandlerRef(i)}};kn.WeakEvent=Zi});var es=oe(Bn=>{"use strict";Object.defineProperty(Bn,"__esModule",{value:!0});var Zo=(Ye(),et(Ge));(0,Zo.__exportStar)(Gi(),Bn);(0,Zo.__exportStar)(Xo(),Bn)});var ts=oe(Ft=>{"use strict";Object.defineProperty(Ft,"__esModule",{value:!0});var er=(Ye(),et(Ge));(0,er.__exportStar)(qo(),Ft);(0,er.__exportStar)(Wi(),Ft);(0,er.__exportStar)(es(),Ft)});var sr={};ur(sr,{Client:()=>Xe,ClientDescriptor:()=>ti,Entity:()=>he,EntityFile:()=>fe,MigrationPathError:()=>at,ServerSync:()=>ft,Storage:()=>Xe,StorageDescriptor:()=>ti,UndoHistory:()=>Je,authorization:()=>rc,cliSync:()=>oc,collection:()=>Pi,createDefaultMigration:()=>Ai,createMigration:()=>Ri,id:()=>ic,migrate:()=>an,schema:()=>It});var Er=ke(Ne(),1),qt=4,gt=36;function Ir(n){return n.toString(gt).padStart(qt,"0")}function ws(n){return n.toString().padStart(6,"0")}var Ut=class{constructor(){this.latest={time:Date.now(),counter:0,node:vs()},this.zeroCounter=0,this.now=i=>(this.latest=Dr(this.latest),this.get(i,this.latest)),this.OLD_now=i=>(this.latest=Dr(this.latest),ws(i)+Ss(this.latest)),this.timerState=()=>this.latest,this.update=i=>{let e=i.slice(qt);this.latest=xs(this.latest,Cr(e))},this.get=(i,e)=>Ir(i)+_r(e),this.zero=i=>Ir(i)+_r({time:0,counter:this.zeroCounter++,node:this.latest.node}),this.getWallClockTime=ui}},zt=class extends Error{constructor(...i){super(),this.type="ClockDriftError",this.message=["maximum clock drift exceeded"].concat(i).join(" ")}},Nt=class extends Error{constructor(){super(),this.type="OverflowError",this.message="timestamp counter overflow"}},ci=4,li=7,$t=60*1e3,mt=9;function vs(){return Er.default.slug().padStart(li,"0").slice(0,li)}function _r(n){let i=new Date(n.time).getTime().toString(gt).padStart(mt,"0"),e=n.counter.toString(gt).padStart(ci,"0"),t=n.node.padStart(li,"0");return`${i}${e}${t}`}function Dr(n){let i=Date.now(),e=Math.max(n.time,i),t=n.time===e?n.counter+1:0;if(e-i>$t)throw new zt(e,i,$t);if(t>65535)throw new Nt;return{time:e,counter:t,node:n.node}}function xs(n,i){let e=Date.now(),t=Math.max(e,Math.max(n.time,i.time)),r=Math.max(n.counter,i.counter),o;if(n.time===t&&i.time===t?o=r+1:n.time===t?o=n.counter+1:i.time===t?o=i.counter+1:o=0,t-e>$t)throw new zt(t,e,$t);if(o>65535)throw new Nt;return{time:t,counter:o,node:n.node}}function Cr(n){let i=n.slice(0,mt),e=n.slice(mt,mt+ci),t=n.slice(mt+ci),r=parseInt(i,gt),o=parseInt(e,gt);if(isNaN(r)||isNaN(o))throw new Error("invalid clock format");return{time:r,counter:o,node:t}}function Ss(n){let i=new Date(n.time).toISOString(),e=n.counter.toString(16).toUpperCase().padStart(4,"0"),t=n.node.padStart(16,"0");return`${i}-${e}-${t}`}function Kt(n){return parseInt(n.slice(0,qt),36)}function di(n,i){return Kt(n)-Kt(i)}function ui(n){return Cr(n.slice(qt)).time}var Ht,Os=new Uint8Array(16);function fi(){if(!Ht&&(Ht=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!Ht))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Ht(Os)}var Pr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Is(n){return typeof n=="string"&&Pr.test(n)}var Ar=Is;var ee=[];for(Wt=0;Wt<256;++Wt)ee.push((Wt+256).toString(16).substr(1));var Wt;function _s(n){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(ee[n[i+0]]+ee[n[i+1]]+ee[n[i+2]]+ee[n[i+3]]+"-"+ee[n[i+4]]+ee[n[i+5]]+"-"+ee[n[i+6]]+ee[n[i+7]]+"-"+ee[n[i+8]]+ee[n[i+9]]+"-"+ee[n[i+10]]+ee[n[i+11]]+ee[n[i+12]]+ee[n[i+13]]+ee[n[i+14]]+ee[n[i+15]]).toLowerCase();if(!Ar(e))throw TypeError("Stringified UUID is invalid");return e}var Rr=_s;function Ds(n,i,e){n=n||{};var t=n.random||(n.rng||fi)();if(t[6]=t[6]&15|64,t[8]=t[8]&63|128,i){e=e||0;for(var r=0;r<16;++r)i[e+r]=t[r];return i}return Rr(t)}var yt=Ds;function Q(n){return Oe(n)||we(n)}function tt(n,i){return n===i?!0:!(!Q(n)||!Q(i)||n["@@type"]!==i["@@type"]||n.id!==i.id)}var Es="/",bt=":",pi=new WeakMap;function ne(n){let i=me(n);return L(!!i,`Object ${JSON.stringify(n)} does not have an OID assigned to it`),i}function me(n){if(U(n))return pi.get(n)}function N(n,i){return L(U(n),`Only objects can be assigned OIDs, received ${JSON.stringify(n)}`),mi(n)&&Gt(n),pi.set(n,i),n}function mi(n){return!!me(n)}function Gt(n){return pi.delete(n),n}function gi(n,i,e){if(mi(n))return ne(n);{let t=ve(i,e);return N(n,t),t}}function Fr(n,i,e){if(mi(n)){let t=ne(n);if(Ce(t,i))return ne(n);{let r=ve(i,e);return N(n,r),r}}else{let t=ve(i,e);return N(n,t),t}}var hi={".":"&dot;","/":"&slash;",":":"&colon;"};function Tr(n){return n.replace(/[/]/g,hi["/"]).replace(/[:]/g,hi[":"]).replace(/[.]/g,hi["."])}function kr(n){return n.replace(/&slash;/g,"/").replace(/&colon;/g,":").replace(/&dot;/g,".")}function Y(n,i,e){let t=Tr(n)+Es+Tr(i);return e&&(t+=bt+e),t}function ve(n,i=Cs){let{collection:e,id:t}=ce(n);return Y(e,t,i())}function ce(n){let[i,e,...t]=n.split("/");t.length&&(console.error(`OID ${n} has more than 3 segments. Attempting to parse it anyway.`),e+="/"+t.join("/"));let[r,o]=e.split(bt),s;return r.includes(".")?s=r.slice(0,r.indexOf(".")):s=r,{collection:kr(i),id:kr(s),subId:o}}function nt(n,i){let e=ne(n);if(Array.isArray(n)){let t;for(let r=0;r<n.length;r++)t=n[r],U(t)&&!Q(t)&&(Fr(t,e,i),nt(t,i))}else if(U(n)&&!Q(n))for(let t of Object.keys(n))U(n[t])&&!Q(n[t])&&(Fr(n[t],e,i),nt(n[t],i))}function Qt(n){if(Gt(n),Array.isArray(n))for(let i=0;i<n.length;i++)Qt(n[i]);else if(U(n))for(let i of Object.keys(n))Qt(n[i])}function Cs(){return yt().slice(0,8)}function ae(n){return{"@@type":"ref",id:n}}function Jt(n,i=new Map){if(Array.isArray(n)){let e=ne(n),t=N([],e);for(let r=0;r<n.length;r++){let o=n[r];if(U(o)){if(Oe(o))throw new Error("An attempt was made to normalize an already normalized object! This is an error in verdant itself.");if(we(o)){t[r]=o;continue}else{let s=ne(o);t[r]=ae(s),Jt(o,i)}}else t[r]=o}i.set(e,t)}else if(U(n)&&!Q(n)){let e=ne(n),t=N({},e);for(let r of Object.keys(n)){let o=n[r];if(U(o)){if(Oe(o))throw new Error("An attempt was made to normalize an already normalized object! This is an error in verdant itself.");if(we(o))t[r]=o;else{let s=ne(o);t[r]=ae(s),Jt(o,i)}}else t[r]=o}i.set(e,t)}else Q(n);return i}function $(n){return n.split(".")[0].split(bt)[0]}function yi(n){let i=$(n),e=ve(i,()=>"\uFFFF");return[`${i}${bt}`,e]}function Ce(n,i){return $(n)===$(i)}function Yt(n){return!n.includes(bt)}var Lr=ke(Mr(),1);function Ps(n,i){return typeof i!="object"||i===null||Array.isArray(i)?i:Object.fromEntries(Object.entries(i).sort(([e],[t])=>e<t?-1:e>t?1:0))}function wt(n){return JSON.stringify(n,Ps)}function le(n,i=!0){if(!i&&typeof structuredClone=="function")return structuredClone(n);if(U(n)||Array.isArray(n)){let e=me(n),t;if(Array.isArray(n))t=n.map(r=>le(r,i));else{t={};for(let[r,o]of Object.entries(n))t[r]=le(o,i)}return i&&e&&N(t,e),t}return n}function Be(n){return(0,Lr.default)(n)}function U(n){return n&&typeof n=="object"}function Vr(n){for(var i=[],e=[n],t=0;e.length;){var r=e.pop();if(typeof r=="boolean")t+=4;else if(typeof r=="string")t+=r.length*2;else if(typeof r=="number")t+=8;else if(typeof r=="object"&&i.indexOf(r)===-1){i.push(r);for(var o in r)e.push(r[o])}}return t}function L(n,i="assertion failed"){if(!n)throw new Error(i)}function Xt(n=16){return yt().replace("-","").slice(0,n)}function Ur(n,i){for(let e=n.length-1;e>=0;e--)if(i(n[e]))return e;return-1}function zr(n,i){let e;return function(...t){let r=this;clearTimeout(e),e=setTimeout(()=>n.apply(r,t),i)}}function Nr(n,i){let e=0,t;return function(...r){let o=this,s=Date.now();s-e>=i?(e=s,n.apply(o,r),clearTimeout(t)):(clearTimeout(t),t=setTimeout(()=>{e=s,n.apply(o,r)},i))}}function we(n){return n&&n["@@type"]==="file"}function vt(n){return{"@@type":"file",id:n}}function it(n){return typeof File<"u"&&n instanceof File||typeof Blob<"u"&&n instanceof Blob}function Zt(n){return n&&U(n)&&typeof n.id=="string"&&typeof n.remote=="boolean"&&typeof n.name=="string"&&typeof n.type=="string"}var rt="__@@oid_do_not_use",Pe="@@id";function As(n){if(U(n))return n[Pe]||n[rt]}function Rs(n){return U(n)&&(delete n[rt],delete n[Pe]),n}function Fs(n){let i=As(n);i&&N(n,i)}function xt(n){if(Fs(n),Rs(n),Array.isArray(n))for(let i=0;i<n.length;i++)xt(n[i]);else if(U(n))for(let i of Object.keys(n))xt(n[i])}function Ts(n){let{collection:i,id:e,subId:t}=ce(n);return Y(i,e,t)}var ks=/"\w+\/[^"]+?(\.[^"]+)+\:[\S]+?"/g;function Bs(n){return n.replaceAll(ks,i=>{let e=i.slice(1,i.length-1);return`"${Ts(e)}"`})}function bi(n){return JSON.parse(Bs(JSON.stringify(n)))}function wi(n){let i=$(n);return[`${i}.`,`${i}.\uFFFF`]}function vi(n){return n===Pe||n===rt}function Oe(n){return n&&typeof n=="object"&&n["@@type"]==="ref"}function xi(n){return U(n)&&!Q(n)}function js(n,i){return n===i?!0:Q(n)&&Q(i)?tt(n,i):!1}function St(n,i,e,t,r=[],o){let s=o?.authz,a=ne(n);function u(d,p,S,y){if(!xi(p))js(p,S)||(y?r.push(Me({oid:a,timestamp:e(),data:{op:"list-set",index:d,value:p}},s)):r.push(Me({oid:a,timestamp:e(),data:{op:"set",name:d,value:p}},s)));else{let E=me(S),g=me(p);g&&!Ce(a,g)?(p=le(p,!1),g=ve(a,t),N(p,g)):o?.mergeUnknownObjects?!g&&E?(N(p,E),g=E):g=gi(p,a,t):g=gi(p,a,t),L(!!g,"Error: no value OID was resolved during diff. This is a bug in Verdant."),L(Ce(a,g),`Error: value OID ${g} is not related to parent OID ${a}. This is a bug in Verdant.`),S===void 0||g!==E?(Ae(p,g,e,t,r),r.push(Me({oid:a,timestamp:e(),data:{op:"set",name:d,value:ae(g)}},s)),E!==void 0&&r.push(Me({oid:E,timestamp:e(),data:{op:"delete"}},s))):St(S,p,e,t,r,o)}}if(Array.isArray(n)&&Array.isArray(i)){for(let p=0;p<i.length;p++){let S=i[p],y=n[p];u(p,S,y,!0)}let d=n.length-i.length;if(d>0){for(let p=i.length;p<n.length;p++){let S=n[p],y=me(S);y&&r.push(Me({oid:y,timestamp:e(),data:{op:"delete"}},s))}r.push(Me({oid:a,timestamp:e(),data:{op:"list-delete",index:i.length,count:d}},s))}}else{if(Array.isArray(n)||Array.isArray(i))throw new Error("Cannot diff an array with an object");if(xi(n)&&xi(i)){let d=new Set(Object.keys(n));for(let[p,S]of Object.entries(i)){if(S===void 0&&o?.defaultUndefined||(d.delete(p),vi(p)))continue;let y=n[p];u(p,S,y,!1)}if(!o?.defaultUndefined)for(let p of d)vi(p)||r.push(Me({oid:a,timestamp:e(),data:{op:"remove",name:p}},s))}}return r}function Ae(n,i,e,t,r=[],o){N(n,i),nt(n,t);let s=Jt(n);for(let a of s.keys()){let u=s.get(a),d={oid:a,timestamp:e(),data:{op:"initialize",value:Gt(u)}};r.push(Me(d,o?.authz))}return r}function Me(n,i){return i&&(n.authz=i),n}function Ot(n){let i={};for(let e of n)e.oid in i?i[e.oid].push(e):i[e.oid]=[e];return i}function Kr(n){let i={};for(let e of n){let t=$(e.oid);t in i?i[t].push(e):i[t]=[e]}return i}function qr(n){let i={};for(let e of n){let t=$(e.oid);t in i?i[t].push(e):i[t]=[e]}return i}function je(n){return Array.isArray(n)?!0:(console.error(`Cannot apply list patch; expected array, received ${JSON.stringify(n)}. This suggests your data is changing from a list to an object over time. (OID: ${me(n)})`),!1)}function $e(n,i,e){if(n==null&&i.op!=="initialize")return n;let t=n,r,o;function s(a){e&&Q(a)&&e.push(a)}switch(i.op){case"set":s(t[i.name]),t[i.name]=i.value;break;case"remove":s(t[i.name]),delete t[i.name];break;case"list-set":je(n)&&(s(n[i.index]),n[i.index]=i.value);break;case"list-push":je(n)&&n.push(i.value);break;case"list-delete":je(n)&&(s(n[i.index]),n.splice(i.index,i.count));break;case"list-move-by-index":je(n)&&(o=n.splice(i.from,1),n.splice(i.to,0,o[0]));break;case"list-remove":if(je(n))do{let a=i.value;i.only==="last"?Oe(a)?r=Ur(n,u=>u.id===a.id):r=n.lastIndexOf(a):Oe(a)?r=n.findIndex(u=>u.id===a.id):r=n.indexOf(a),r!==-1&&(s(n[r]),n.splice(r,1))}while(!i.only&&r!==-1);break;case"list-add":je(n)&&(n.some(u=>Oe(u)&&Oe(i.value)?u.id===i.value.id:u===i.value)||n.push(i.value));break;case"list-move-by-ref":je(n)&&(r=n.findIndex(a=>tt(a,i.value)),o=n.splice(r,1),n.splice(i.index,0,o[0]));break;case"list-insert":if(je(n)){if(!i.value&&!i.values)throw new Error(`Cannot apply list insert patch; expected value or values, received ${JSON.stringify(i)}`);i.value?n.splice(i.index,0,i.value):n.splice(i.index,0,...i.values)}break;case"delete":Array.isArray(n)?n.forEach(s):U(n)&&Object.values(n||{}).forEach(s);return;case"initialize":return le(i.value);case"touch":return n;default:throw new Error(`Unsupported patch operation: ${i.op}`)}return n}function en(n,i,e=[]){if(Array.isArray(n))for(let t=0;t<n.length;t++){let r=n[t];n[t]=$r(r,i,e),U(n[t])&&en(n[t],i,e)}else if(!we(n)){if(U(n)){L(me(n),`Object ${JSON.stringify(n)} must have an oid`);for(let t of Object.keys(n))n[t]=$r(n[t],i,e),U(n[t])&&en(n[t],i,e)}}return e}function $r(n,i,e){if(Oe(n)){e.push(n.id);let t=i.get(n.id);return L(!!t,`No value was found in object map for ${n.id}`),N(t,n.id)}else return n}function Hr(n){return n.data.op==="set"?n.data.name:!1}function Wr(n,i){return i.has(!0)?!0:n.data.op==="set"||n.data.op==="remove"?i.has(n.data.name):!1}function tn(n){return{oid:n.oid,timestamp:n.timestamp,data:n.data,authz:n.authz}}var Le;(function(n){n[n.Realtime=0]="Realtime",n[n.Push=1]="Push",n[n.PassiveRealtime=2]="PassiveRealtime",n[n.PassivePush=3]="PassivePush",n[n.ReadOnlyPull=4]="ReadOnlyPull",n[n.ReadOnlyRealtime=5]="ReadOnlyRealtime"})(Le||(Le={}));var Qr=ke(Ne(),1),Ms=n=>Object.assign({type:"object"},n),Ls=n=>Object.assign({type:"array"},n),Vs=n=>Object.assign({type:"string"},n),Us=n=>Object.assign({type:"number"},n),zs=n=>Object.assign({type:"boolean"},n),Ns=n=>Object.assign({type:"any"},n),$s=n=>Object.assign({type:"map"},n),Ks=n=>Object.assign({type:"file"},n),qs=()=>({type:"string",default:Qr.default}),Jr={object:Ms,array:Ls,string:Vs,number:Us,boolean:zs,any:Ns,map:$s,file:Ks,id:qs};var Zr=ke(Ne(),1);function Si(n){return n.equals!==void 0}function Oi(n){return n.gte!==void 0||n.lte!==void 0||n.gt!==void 0||n.lt!==void 0}function Hs(n){return!!n.match}function Ii(n){return n.startsWith!==void 0}function Gr(n){return!Oi(n)&&!Si(n)&&!Hs(n)&&!Ii(n)&&n.order}function xe(n){return n.type==="any"?!0:n.type==="map"?!1:n.nullable}function Re(n){return n?n.type==="map"||n.type==="array"?!0:n.type==="file"?!1:n.default!==void 0:!1}function Di(n){if(!(!n||!Re(n)))return n.type==="file"?xe(n)?null:void 0:n.type==="map"?{}:n.type==="array"?xe(n)?null:[]:n.type==="object"?xe(n)?null:void 0:typeof n.default=="function"?n.default():n.default}function Fe(n,i){for(let[e,t]of Object.entries(n.fields)){let r=Ei(t);(r!==void 0&&i[e]===void 0||!xe(t)&&i[e]===null)&&(i[e]=r),i[e]&&Ke(i[e],t)}return i}function Ke(n,i){if(n==null)return n;if(i.type==="object")for(let[e,t]of Object.entries(i.properties)){if(n[e]===void 0){let r=Ei(t);r!==void 0&&(n[e]=r)}Ke(n[e],t)}else if(i.type==="array")for(let e of n)Ke(e,i.items);else if(i.type==="map")for(let[e,t]of Object.entries(n))e===Pe||e===rt||Ke(t,i.values)}function Ei(n){if(n.type==="string"||n.type==="number"||n.type==="boolean"||n.type==="any"){if(n.default&&typeof n.default=="function")return n.default();if(n.default!==void 0)return JSON.parse(JSON.stringify(n.default))}if(n.type==="array")return[];if(n.type==="map")return{};if(n.type!=="any"&&n.nullable)return null;if(n.type==="object"&&n.default){let i=typeof n.default=="function"?n.default():JSON.parse(JSON.stringify(n.default));for(let[e,t]of Object.entries(n.properties))i[e]===void 0&&(i[e]=Ei(t));return i}}function Ci(n,i){for(let[e,t]of Object.entries(i))e===Pe||e===rt||(n.fields[e]?_i(t,n.fields[e]):delete i[e]);return i}function _i(n,i){if(U(n)&&i.type==="object")for(let[e,t]of Object.entries(n))i.properties[e]?_i(t,i.properties[e]):delete n[e];else if(Array.isArray(n)&&i.type==="array")for(let e of n)_i(e,i.items)}function Yr(n,i){for(let[e,t]of Object.entries(i))if(e!==Pe){if(!n[e])return{type:"invalid-key",fieldPath:[e],message:`Invalid field "${e}"`};if(t){let r=Te({field:n[e],value:t,fieldPath:[e]});if(r)return r}}}function Te({field:n,value:i,fieldPath:e=[],depth:t,requireDefaults:r}){if(!(t!==void 0&&t<=0)&&!(xe(n)&&i===null)){if(i===null&&(r||!Re(n)))return{type:"no-default",fieldPath:e,message:`Invalid null value for field ${Ie(e)}`};if(n.type==="object"){if(!U(i))return{type:"invalid-type",fieldPath:e,message:`Expected object ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`};for(let[o,s]of Object.entries(n.properties))o!==Pe&&i[o]&&Te({field:s,value:i[o],fieldPath:[...e,o],depth:t!==void 0?t-1:void 0});for(let o of Object.keys(i))if(!n.properties[o])return{type:"invalid-key",fieldPath:[...e,o],message:`Invalid unexpected field "${o}" on value ${Ie(e)}`}}else if(n.type==="array"){if(!Array.isArray(i))return i===null&&n.nullable?void 0:{type:"invalid-value",fieldPath:e,message:`Expected array ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`};for(let o of i)Te({field:n.items,value:o,fieldPath:[...e,"[]"],depth:t!==void 0?t-1:void 0})}else if(n.type==="map"){if(!U(i))return{type:"invalid-type",fieldPath:e,message:`Expected map for field ${Ie(e)}, got ${i}`};for(let[o,s]of Object.entries(i))Te({field:n.values,value:s,fieldPath:[...e,o],depth:t!==void 0?t-1:void 0})}else if(n.type==="string"){if(typeof i!="string")return{type:"invalid-type",fieldPath:e,message:`Expected string ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`};if(n.options&&!n.options.includes(i))return{type:"invalid-value",fieldPath:e,message:`Expected one of ${n.options.join(", ")} for field ${Ie(e)}, got ${i}`}}else if(n.type==="boolean"){if(typeof i!="boolean")return{type:"invalid-type",fieldPath:e,message:`Expected boolean ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`}}else if(n.type==="number"){if(typeof i!="number")return{type:"invalid-type",fieldPath:e,message:`Expected number ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`}}else if(n.type==="file"&&!it(i)&&!Zt(i))return{type:"invalid-type",fieldPath:e,message:`Expected file ${n.nullable?"or null ":""}for field ${Ie(e)}, got ${i}`}}}function Ie(n){return n.length===0?"root":n.join(".")}function Xr(n,i){let e={};for(let[t,r]of Object.entries(i))n[t]&&(e[t]=nn({field:n[t],value:r,fieldPath:[t]}));return e}function nn({field:n,value:i,fieldPath:e=[],depth:t}){let r=Te({field:n,value:i,fieldPath:e,depth:t,requireDefaults:!0});if(r)throw new Error(`Validation error: ${r.message}`);if(n.type==="object"){if(!U(i))return i;let o={};for(let[s,a]of Object.entries(n.properties))o[s]=nn({field:a,value:i[s],fieldPath:[...e,s],depth:t!==void 0?t-1:void 0});return o}else{if(n.type==="array")return Array.isArray(i)?i.map(o=>nn({field:n.items,value:o,fieldPath:[...e,"[]"],depth:t!==void 0?t-1:void 0})):i;if(n.type==="map"){if(!U(i))return i;let o={};for(let[s,a]of Object.entries(i))o[s]=nn({field:n.values,value:a,fieldPath:[...e,s],depth:t!==void 0?t-1:void 0});return o}else return i}}function Ve(n,i){var e;return n.type==="object"?n.properties[i]:n.type==="array"?n.items:n.type==="map"?n.values:n.type==="any"?n:"type"in n?null:(e=n[i])!==null&&e!==void 0?e:null}var Ws=function(n,i){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&i.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(n);r<t.length;r++)i.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(n,t[r])&&(e[t[r]]=n[t[r]]);return e};function Pi(n){var{synthetics:i,indexes:e}=n,t=Ws(n,["synthetics","indexes"]);let r=Object.assign(Object.assign({},i),e);for(let[o,s]of Object.entries(t.fields))"indexed"in s&&(r[o]={field:o});return Object.assign(Object.assign({},t),{indexes:r})}function It(n){return n}It.collection=Pi;It.fields=Jr;It.generated={id:Zr.default};var rn="\uFFFFFE",Qs="\0",Js="\uFFFFFF";function de(...n){let i=Gs(n);return i.length===1?i[0]:i}function qe(...n){return n.join(rn)+`${Js}`}function He(...n){return n.join(rn)+`${rn}${Qs}`}function Gs(n){let i=[[]];for(let e of n)if(Array.isArray(e)){let t=[];for(let r of i)for(let o of e)t.push(r.concat(o));i=t}else for(let t of i)t.push(`${e}`);return Array.from(new Set(i.map(e=>e.join(rn))))}function Ys(n){return!!n.field}function Xs(n,i){let e={};for(let[t,r]of Object.entries(n.indexes||{})){let o=r;Ys(o)?e[t]=Se(i[o.field]):e[t]=Se(o.compute(i))}return e}function Zs(n,i){return Object.entries(n.compounds||{}).reduce((e,[t,r])=>(e[t]=de(...r.of.map(o=>i[o])),e),{})}function ea(n,i){return Object.entries(n.fields).reduce((e,[t,r])=>("indexed"in r&&(e[t]=Se(i[t])),e),{})}function on(n,i){let e=Object.assign(Object.assign({[n.primaryKey]:i[n.primaryKey]},ea(n,i)),Xs(n,i));return Object.assign(e,Zs(n,Object.assign(Object.assign({},i),e))),e["@@@snapshot"]=JSON.stringify(i),e}var ta="null";function Se(n){if(n===null)return ta;if(typeof n=="string"||typeof n=="number")return n;if(typeof n=="boolean"||n===null)return`${n}`;if(n===void 0)return"undefined";if(Array.isArray(n))return n.map(Se);throw new Error(`Unsupported index value: ${n}`)}var eo={version:0,collections:{}};function an(n,i,e){let t=typeof i=="function",r=t?eo:n,o=t?n:i,s=t?i:e,a=Object.keys(o.collections).filter(v=>r.collections[v]&&wt(r.collections[v])!==wt(o.collections[v])),u=Object.keys(r.collections).filter(v=>!o.collections[v]),d=Object.keys(o.collections).filter(v=>!r.collections[v]),p=new Set;for(let v of a){let I=r.collections[v].fields,_=o.collections[v].fields;Object.keys(_).some(O=>{var R,w;return!(!((R=I[O])===null||R===void 0)&&R.default)&&((w=_[O])===null||w===void 0?void 0:w.default)})&&p.add(v),Object.keys(I).some(O=>!_[O])&&p.add(v)}let S={},y={};for(let v of[...a,...d]){let I=sn(r.collections[v]),_=sn(o.collections[v]),O=_.filter(w=>!I.find(D=>D.name===w.name)),R=I.filter(w=>!_.find(D=>D.name===w.name));O.length>0&&(S[v]=O,a.includes(v)&&p.add(v)),R.length>0&&(y[v]=R,a.includes(v)&&p.add(v))}let E=(v,I)=>Fe(o.collections[v],I),g=v=>I=>{let _=o.collections[v];return Fe(_,Ci(_,I))};return{version:o.version,migrate:async v=>{let I=[];if(await s({migrate:async(_,O)=>{let R=g(_),w=async D=>{let f=await O(D);return N(f,ne(D)),R(f)};await v.migrate(_,w),I.push(_),p.delete(_)},identity:_=>_,withDefaults:E,info:{changedCollections:a,addedCollections:d,removedCollections:u},queries:v.queries,mutations:v.mutations}),o.version>1){v.log("debug","auto-migrating collections with new defaults",p);for(let O of p)await v.migrate(O,g(O)),I.push(O);let _=a.filter(O=>!I.includes(O));_.length>0&&console.error(`Unmigrated changed collections from version ${r.version} to version ${o.version}:`,_)}},removedCollections:u,addedIndexes:S,removedIndexes:y,allCollections:Object.keys(o.collections),changedCollections:a,addedCollections:d,oldCollections:Object.keys(r.collections),oldSchema:r,newSchema:o}}function sn(n){return n?[...Object.keys(n.indexes||{}).map(i=>({name:i,multiEntry:["array","string[]","number[]","boolean[]"].includes(n.indexes[i].type),synthetic:!0,compound:!1})),...Object.keys(n.compounds||{}).map(i=>({name:i,multiEntry:n.compounds[i].of.some(e=>(n.fields[e]||n.indexes[e]).type==="array"),synthetic:!1,compound:!0}))]:[]}function Ai(n,i){return an(i?n:{version:0,collections:{}},i||n,async({migrate:t,info:r})=>{if((i||n).version!==1)for(let o of r.changedCollections)await t(o,s=>s)})}function Ri(n,i,e){let t=typeof i=="function"||i===void 0,r=t?eo:n,o=t?n:i,s=t?i:e;L(r,"Invalid arguments to createMigration"),L(o,"Invalid arguments to createMigration");let{changedCollections:a,addedCollections:u,removedCollections:d,addedIndexes:p,removedIndexes:S,autoMigratedCollections:y,autoMigration:E}=na(r,o);return{version:o.version,migrate:async g=>{let v=[];if(await s?.({migrate:async(_,O)=>{let R=E(_),w=async D=>{let f=await O(D);N(f,ne(D));let m=R(f),l=Yr(o.collections[_].fields,m);return m};await g.migrate(_,w),v.push(_),y.delete(_)},info:{changedCollections:a,addedCollections:u,removedCollections:d},queries:g.queries,mutations:g.mutations}),o.version>1){g.log("debug","auto-migrating collections with new defaults",y);for(let O of y)await g.migrate(O,E(O)),v.push(O);for(let O of d)await g.deleteCollection(O);let _=a.filter(O=>!v.includes(O));_.length>0&&console.error(`Unmigrated changed collections from version ${r.version} to version ${o.version}:`,_)}},removedCollections:d,addedIndexes:p,removedIndexes:S,allCollections:Object.keys(o.collections),changedCollections:a,addedCollections:u,oldCollections:Object.keys(r.collections),oldSchema:r,newSchema:o}}function na(n,i){let e=Object.keys(i.collections).filter(p=>n.collections[p]&&wt(n.collections[p])!==wt(i.collections[p])),t=Object.keys(n.collections).filter(p=>!i.collections[p]),r=Object.keys(i.collections).filter(p=>!n.collections[p]),o=new Set;for(let p of e){let S=n.collections[p].fields,y=i.collections[p].fields;Object.keys(y).some(E=>!Re(S[E])&&Re(y[E]))&&o.add(p),Object.keys(S).some(E=>!y[E])&&o.add(p)}let s={},a={};for(let p of[...e,...r]){let S=sn(n.collections[p]),y=sn(i.collections[p]),E=y.filter(v=>!S.find(I=>I.name===v.name)),g=S.filter(v=>!y.find(I=>I.name===v.name));E.length>0&&(s[p]=E,e.includes(p)&&o.add(p)),g.length>0&&(a[p]=g,e.includes(p)&&o.add(p))}return{changedCollections:e,addedCollections:r,removedCollections:t,addedIndexes:s,removedIndexes:a,autoMigratedCollections:o,withDefaults:(p,S)=>Fe(i.collections[p],S),autoMigration:p=>S=>{let y=i.collections[p];return Fe(y,Ci(y,S))}}}var Fi={};var cn=class{constructor(i,e){this.getNow=i,this.createSubId=e,this.isPrimitive=t=>!U(t)||Q(t),this.createDiff=(t,r,o={})=>St(t,r,this.getNow,this.createSubId,[],o),this.createInitialize=(t,r)=>Ae(t,r,this.getNow,this.createSubId),this.createSet=(t,r,o)=>{if(this.isPrimitive(o))return[{oid:t,timestamp:this.getNow(),data:{op:"set",name:r,value:o}}];{let s=ve(t,this.createSubId);return[...Ae(o,s,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"set",value:ae(s),name:r}}]}},this.createRemove=(t,r)=>[{oid:t,timestamp:this.getNow(),data:{op:"remove",name:r}}],this.createListSet=(t,r,o)=>{if(this.isPrimitive(o))return[{oid:t,timestamp:this.getNow(),data:{op:"list-set",index:r,value:o}}];{let s=ve(t,this.createSubId);return[...Ae(o,s,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-set",index:r,value:ae(s)}}]}},this.createListPush=(t,r)=>{if(this.isPrimitive(r))return[{oid:t,timestamp:this.getNow(),data:{op:"list-push",value:r}}];{let o=ve(t,this.createSubId);return[...Ae(r,o,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-push",value:ae(o)}}]}},this.createListAdd=(t,r)=>this.isPrimitive(r)?[{oid:t,timestamp:this.getNow(),data:{op:"list-add",value:r}}]:[{oid:t,timestamp:this.getNow(),data:{op:"list-add",value:ae(r)}}],this.createListInsert=(t,r,o)=>{if(this.isPrimitive(o))return[{oid:t,timestamp:this.getNow(),data:{op:"list-insert",value:o,index:r}}];{let s=ve(t,this.createSubId);return[...Ae(o,s,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-insert",value:ae(s),index:r}}]}},this.createListRemove=(t,r,o)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-remove",value:r,only:o}}],this.createListDelete=(t,r,o=1)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-delete",index:r,count:o}}],this.createListMoveByRef=(t,r,o)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-move-by-ref",value:r,index:o}}],this.createListMoveByIndex=(t,r,o)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-move-by-index",from:r,to:o}}],this.createDelete=t=>[{oid:t,timestamp:this.getNow(),data:{op:"delete"}}],this.createDeleteAll=t=>t.map(r=>({oid:r,timestamp:this.getNow(),data:{op:"delete"}}))}};var z=class{constructor(i){this._onAllUnsubscribed=i,this.subscribers={},this.counts={},this._disabled=!1,this.disposed=!1,this.subscriberCount=e=>{var t;return(t=this.counts[e])!==null&&t!==void 0?t:0},this.totalSubscriberCount=()=>Object.values(this.counts).reduce((e,t)=>e+t,0),this.subscribe=(e,t)=>{let r=Xt(),o=this.subscribers[e];return o||(o=this.subscribers[e]={}),o[r]=t,this.counts[e]=(this.counts[e]||0)+1,()=>{this.subscribers[e]&&(delete this.subscribers[e][r],this.counts[e]--,this.counts[e]===0&&(delete this.subscribers[e],delete this.counts[e],this._onAllUnsubscribed&&this._onAllUnsubscribed(e)))}},this.emit=(e,...t)=>{this._disabled||this.subscribers[e]&&Object.values(this.subscribers[e]).forEach(r=>r(...t))},this.dispose=()=>{this._disabled=!0,this.disposed=!0;let e=Object.keys(this.subscribers);this.subscribers={},this.counts={},e.forEach(t=>{this._onAllUnsubscribed&&this._onAllUnsubscribed(t)})},this.disable=()=>{this._disabled=!0}}get disabled(){return this._disabled}};function to(n,i,e,t){if(i==null)return[{oid:n,timestamp:t(),data:{op:"delete"}}];let r=le(i),o=[];for(let s of e){let a=ia(n,r,s,t);o.unshift(...a),$e(r,s.data)}return o}function ia(n,i,e,t){let r=e.data;switch(r.op){case"set":case"remove":return[{oid:n,timestamp:t(),data:{op:"set",name:r.name,value:i[r.name]}}];case"list-insert":return[{oid:n,timestamp:t(),data:{op:"list-delete",index:r.index,count:1}}];case"list-delete":return[{oid:n,timestamp:t(),data:{op:"list-insert",index:r.index,values:i.slice(r.index,r.count)}}];case"list-move-by-ref":return[{oid:n,timestamp:t(),data:{op:"list-move-by-ref",value:r.value,index:i.indexOf(r.value)}}];case"list-move-by-index":return[{oid:n,timestamp:t(),data:{op:"list-move-by-index",from:r.to,to:r.from}}];case"delete":return[{oid:n,timestamp:t(),data:{op:"initialize",value:i}}];case"list-push":return[{oid:n,timestamp:t(),data:{op:"list-remove",value:r.value,only:"last"}}];case"list-remove":if(r.only==="last"){let o=i.lastIndexOf(r.value);return[{oid:n,timestamp:t(),data:{op:"list-insert",index:o,values:[r.value]}}]}else if(r.only==="first"){let o=i.indexOf(r.value);return[{oid:n,timestamp:t(),data:{op:"list-insert",index:o,values:[r.value]}}]}else{let o=[],s=i.indexOf(r.value);for(;s!==-1;)o.push(s),s=i.indexOf(r.value,s+1);return o.map(a=>({oid:n,timestamp:t(),data:{op:"list-insert",index:a,value:r.value}}))}case"list-add":return[{oid:n,timestamp:t(),data:{op:"list-remove",value:r.value,only:"last"}}];case"list-set":return[{oid:n,timestamp:t(),data:{op:"list-set",index:r.index,value:i[r.index]}}];case"initialize":return[{oid:n,timestamp:t(),data:{op:"delete"}}];case"touch":return[];default:throw new Error(`Cannot undo operation type: ${r.op}`)}}var ot=class{constructor(i){this.flusher=i,this.batches=new Map,this.flush=e=>{let t=this.batches.get(e);if(t)return t.flush()},this.discard=e=>{let t=this.batches.get(e);t&&(t.discard(),this.batches.delete(e))},this.flushAll=()=>[...this.batches.values()].map(e=>e.flush()),this.getSize=e=>{let t=this.batches.get(e);return t?t.items.length:0}}add({key:i,userData:e,items:t,max:r,timeout:o}){let s=this.batches.get(i);return s||(s=new Ti({max:r||null,startedAt:Date.now(),userData:e,timeout:o||null,flusher:this.flusher,key:i}),this.batches.set(i,s)),s.update({items:t,max:r,timeout:o,userData:e}),s}},Ti=class{constructor({max:i,startedAt:e,timeout:t,userData:r,flusher:o,key:s}){this.items=[],this.update=({items:a,max:u,timeout:d,userData:p})=>{this.items.push(...a),u!==void 0&&(this.max=u),d!==void 0&&(this.timeout=d),p&&(this.userData=p);let S=this.items.length!==0&&this.timeout!==null&&!this.flushTimeout;this.max!==null&&this.items.length>=this.max?this.flush():S&&this.timeout!==null&&(this.flushTimeout=setTimeout(this.flush,this.timeout))},this.flush=()=>{this.flushTimeout&&clearTimeout(this.flushTimeout),this.flushTimeout=void 0;let a=this.items;return this.items=[],this.flusher(a,this.key,this.userData)},this.discard=()=>{this.flushTimeout&&clearTimeout(this.flushTimeout),this.flushTimeout=void 0,this.items=[]},this.max=i,this.startedAt=e,this.timeout=t,this.userData=r,this.flusher=o,this.key=s}};function no(n,i){let e,t;return(...r)=>{let o=i();return e&&e.length===o.length&&e.every((s,a)=>s===o[a])||(e=[...o],t=n(...r)),t}}var _t;(function(n){n[n.InvalidRequest=4e3]="InvalidRequest",n[n.BodyRequired=4001]="BodyRequired",n[n.NoToken=4010]="NoToken",n[n.InvalidToken=4011]="InvalidToken",n[n.TokenExpired=4012]="TokenExpired",n[n.Forbidden=4030]="Forbidden",n[n.NotFound=4040]="NotFound",n[n.Unexpected=5e3]="Unexpected",n[n.ConfigurationError=5010]="ConfigurationError",n[n.NoFileStorage=5011]="NoFileStorage"})(_t||(_t={}));var st=class extends Error{constructor(i,e,t){super(t??`Verdant error: ${i}`,{cause:e}),this.code=i,this.toResponse=()=>JSON.stringify({code:this.code})}get httpStatus(){let i=Math.floor(this.code/10);return i<600?i:500}};st.Code=_t;function io(n){return typeof n=="object"&&"code"in n&&typeof n.code=="number"}function ra(n){return typeof Buffer<"u"?Buffer.from(n).toString("base64"):btoa(n)}function oa(n){return typeof Buffer<"u"?Buffer.from(n,"base64").toString():atob(n)}var We={onlyUser:n=>ra(`u:${n}:*`),onlyMe:()=>We.onlyUser(ki),decode:n=>{let e=oa(n).split(":");if(e.length!==3)throw new Error("Invalid authz string");return{scope:e[0],subject:e[1],action:e[2]}}},ki="$$_originator_$$";function ro(n,i){let{operations:e,baselines:t}=n;if(e)for(let r of e)r.authz&&We.decode(r.authz).subject===ki&&(r.authz=We.onlyUser(i));if(t)for(let r of t)r.authz&&We.decode(r.authz).subject===ki&&(r.authz=We.onlyUser(i))}var Bi=typeof window<"u"?window.indexedDB:void 0;function ue(n){return n instanceof Error&&n.name==="AbortError"}function J(n){return new Promise((i,e)=>{n.onsuccess=()=>{i(n.result)},n.onerror=()=>{n.error&&ue(n.error)?i(n.result):e(n.error)}})}function Qe(n,i){return new Promise((e,t)=>{let r=n.transaction([i],"readonly"),s=r.objectStore(i).openCursor(),a=0,u=0;s.onsuccess=function(d){let p=s.result;p&&(a++,u=u+Vr(p.value),p.continue())},s.onerror=function(d){s.error&&ue(s.error)?e({count:a,size:u}):t(s.error)},r.oncomplete=function(d){e({count:a,size:u})},r.onabort=function(d){t(d)},r.onerror=function(d){t(d)}})}function ln(n,i){let e=n.transaction(i,"readonly"),t=i.map(r=>{let o=e.objectStore(r);return J(o.getAll())});return Promise.all(t)}async function ge(n){n.close(),await new Promise((i,e)=>{i()})}async function dn(n,i=Bi){let e=i.deleteDatabase([n,"meta"].join("_")),t=i.deleteDatabase([n,"collections"].join("_"));await Promise.all([new Promise((r,o)=>{e.onsuccess=r,e.onerror=o}),new Promise((r,o)=>{t.onsuccess=r,t.onerror=o})]),window.location.reload()}function oo(n,i=window.indexedDB){return J(i.deleteDatabase(n))}async function so(n=window.indexedDB){return n.databases()}function un(n,i,e,t,r){let o=n.transaction(i,e);if(t){let s=()=>{r?.("debug","aborting transaction");try{o.abort()}catch(a){r?.("debug","aborting transaction failed",a)}};t.addEventListener("abort",s),o.addEventListener("error",()=>{t.removeEventListener("abort",s)}),o.addEventListener("complete",()=>{t.removeEventListener("abort",s)})}return o}var _e=class{constructor(){this._disposes=[];this.disposed=!1;this.dispose=()=>{this.disposed=!0,this._disposes.forEach(i=>i()),this._disposes=[]};this.addDispose=i=>{this._disposes.push(i)}}};var se=class extends _e{constructor(e,{log:t}={}){super();this.db=e;this.globalAbortController=new AbortController;this.createTransaction=(e,t)=>{let r=un(this.db,e,t?.mode||"readonly",t?.abort,this.log);return this.globalAbortController.signal.addEventListener("abort",r.abort),r.addEventListener("complete",()=>{this.globalAbortController.signal.removeEventListener("abort",r.abort)}),r.addEventListener("error",()=>{this.globalAbortController.signal.removeEventListener("abort",r.abort)}),r};this.run=async(e,t,r)=>{if(this.disposed||r?.transaction?.error)return Promise.resolve(void 0);let s=(r?.transaction||this.createTransaction([e],r)).objectStore(e),a=t(s);return J(a)};this.runAll=async(e,t,r)=>{if(this.disposed||r?.transaction?.error)return Promise.resolve([]);let s=(r?.transaction||this.createTransaction([e],r)).objectStore(e),a=t(s);return Promise.all(a.map(J))};this.iterate=async(e,t,r,o)=>{let a=(o?.transaction||this.createTransaction([e],o)).objectStore(e),u=t(a);return Array.isArray(u)?Promise.all(u.map(d=>new Promise((p,S)=>{d.onsuccess=()=>{let y=d.result;y?(r(y.value,a),y.continue()):p()},d.onerror=()=>{d.error&&ue(d.error)?p():S(d.error)}}))).then(()=>{}):new Promise((d,p)=>{u.onsuccess=()=>{let S=u.result;S?r(S.value,a)?d():S.continue():d()},u.onerror=()=>{u.error&&ue(u.error)?d():p(u.error)}})};this.clear=e=>this.run(e,t=>t.clear(),{mode:"readwrite"});this.log=t,this.addDispose(()=>{this.globalAbortController.abort()})}};var fn=class extends se{constructor(){super(...arguments);this.getAckInfo=async()=>{let e=await this.run("info",t=>t.get("ack"));return e||{globalAckTimestamp:null,type:"ack"}};this.setGlobalAck=async e=>{await this.run("info",t=>t.put({type:"ack",globalAckTimestamp:e}),{mode:"readwrite"})}}};var hn=class extends se{constructor(e,t){super(e,t);this.getAllForDocument=async(e,{mode:t="readonly",transaction:r}={})=>{let o=[];return await this.iterateOverAllForDocument(e,s=>{o.push(s)},{mode:t,transaction:r}),o};this.iterateOverAllForDocument=async(e,t,{mode:r="readonly",transaction:o}={})=>this.iterate("baselines",s=>{let a=$(e),[u,d]=yi(e),[p,S]=wi(e);return[s.openCursor(IDBKeyRange.only(a)),s.openCursor(IDBKeyRange.bound(u,d,!1,!1)),s.openCursor(IDBKeyRange.bound(p,S,!1,!1))]},t,{mode:r,transaction:o});this.iterateOverAllForCollection=async(e,t,{mode:r="readonly",transaction:o}={})=>this.iterate("baselines",s=>[s.openCursor(IDBKeyRange.bound(e,e+"\uFFFF",!1,!1))],t,{mode:r,transaction:o});this.getAllForMultipleDocuments=async(e,{mode:t="readonly"}={})=>(await this.runAll("baselines",o=>e.flatMap(s=>{let a=$(s),[u,d]=yi(s),[p,S]=wi(s);return[o.get(a),o.getAll(IDBKeyRange.bound(u,d,!1,!1)),o.getAll(IDBKeyRange.bound(p,S,!1,!1))]}),{mode:t})).flat();this.getAllSince=async(e,{mode:t="readonly"}={})=>this.run("baselines",r=>{let o=e?IDBKeyRange.lowerBound(e,!0):void 0;return r.index("timestamp").getAll(o)},{mode:t});this.get=async(e,{transaction:t,mode:r="readonly"}={})=>this.run("baselines",o=>o.get(e),{mode:r,transaction:t});this.set=async(e,{transaction:t}={})=>{await this.run("baselines",r=>r.put(e),{mode:"readwrite",transaction:t})};this.setAll=async(e,{transaction:t}={})=>{await this.runAll("baselines",r=>e.map(o=>r.put(o)),{mode:"readwrite",transaction:t})};this.reset=()=>this.clear("baselines");this.delete=async(e,{transaction:t})=>{await this.run("baselines",r=>r.delete(e),{mode:"readwrite",transaction:t})}}};var ao=ke(Ne(),1);var pn=class extends se{constructor(){super(...arguments);this.get=async({transaction:e}={})=>{if(this.cached)return this.cached;let t=await this.run("info",r=>r.get("localReplicaInfo"),{transaction:e});return t?(this.cached=t,t):(this._creating||(this._creating=(async()=>{let o={type:"localReplicaInfo",id:(0,ao.default)(),userId:void 0,ackedLogicalTime:null,lastSyncedLogicalTime:null};await this.run("info",s=>s.put(o),{mode:"readwrite"}),this.cached=o})()),await this._creating,this.get({transaction:e}))};this.update=async(e,{transaction:t}={})=>{let r=await this.get({transaction:t});Object.assign(r,e),await this.run("info",o=>o.put(r),{mode:"readwrite"}),this.cached=r};this.reset=async()=>{let e=await this.get();e.ackedLogicalTime=null,e.lastSyncedLogicalTime=null,await this.run("info",t=>t.put(e),{mode:"readwrite"})}}};var mn=class{constructor(i){this.meta=i;this.createOperation=async i=>{let e=await this.meta.localReplica.get();return{type:"op",timestamp:this.meta.now,replicaId:e.id,operations:i.operations.map(tn)}};this.createMigrationOperation=async({targetVersion:i,...e})=>{let t=await this.meta.localReplica.get();return{type:"op",operations:e.operations.map(r=>({...r,timestamp:this.meta.time.zero(i)})),timestamp:this.meta.time.zero(i),replicaId:t.id}};this.createSyncStep1=async i=>{let e=await this.meta.localReplica.get(),t=i===null?null:e.lastSyncedLogicalTime,r=[],o=new Set;t?await this.meta.operations.iterateOverAllLocalOperations(a=>{r.push(tn(a)),o.add($(a.oid))},{after:t,mode:"readwrite"}):await this.meta.operations.iterateOverAllOperations(a=>{r.push(tn(a)),o.add($(a.oid))},{mode:"readwrite"});let s=[];return t||(s=await this.meta.baselines.getAllSince("")),{type:"sync",schemaVersion:this.meta.schema.currentVersion,timestamp:this.meta.now,replicaId:e.id,resyncAll:!e.lastSyncedLogicalTime,operations:r,baselines:s,since:t}};this.createPresenceUpdate=async i=>{let e=await this.meta.localReplica.get();return{type:"presence-update",presence:i.presence,replicaId:e.id,internal:i.internal}};this.createHeartbeat=async()=>{let i=await this.meta.localReplica.get();return{type:"heartbeat",timestamp:this.meta.now,replicaId:i.id}};this.createAck=async i=>{let e=await this.meta.localReplica.get();return{type:"ack",timestamp:this.meta.now,replicaId:e.id,nonce:i}}}};var gn=class extends se{constructor(e,t){super(e,t);this.iterateOverAllOperationsForDocument=async(e,t,{to:r,from:o,after:s,mode:a="readonly",transaction:u}={})=>{let p=(u||this.createTransaction(["operations"],{mode:a})).objectStore("operations"),S=p.index("d_t"),y=o||s,E=y?de(e,y):He(e),g=r?de(e,r):qe(e),v=IDBKeyRange.bound(E,g,!!s,!1),I=S.openCursor(v,"next");return new Promise((_,O)=>{let R;I.onsuccess=w=>{let D=I.result;if(D){let f=D.value;L(f.oid.startsWith(e)),L(R===void 0||R<=f.timestamp,`expected ${R} <= ${f.timestamp}`),t(f,p),R=f.timestamp,D.continue()}else _()},I.onerror=w=>{if(ue(I.error)){_();return}else O(I.error)}})};this.iterateOverAllOperationsForEntity=async(e,t,{after:r,to:o,mode:s,transaction:a})=>{let d=(a||this.createTransaction(["operations"],{mode:s})).objectStore("operations"),p=r?de(e,r):He(e),S=o?de(e,o):qe(e),y=IDBKeyRange.bound(p,S,!!r,!1),E=d.openCursor(y,"next");return new Promise((g,v)=>{let I;E.onsuccess=_=>{let O=E.result;if(O){let R=O.value;L(R.oid.startsWith(e)),L(I===void 0||I<=R.timestamp,`expected ${I} <= ${R.timestamp}`),t(R,d),I=R.timestamp,O.continue()}else g()},E.onerror=_=>{ue(E.error)?g():v(E.error)}})};this.iterateOverAllOperationsForCollection=async(e,t,{after:r,to:o,mode:s,transaction:a})=>{let u=a||this.createTransaction(["operations"],{mode:s});return this.iterate("operations",d=>d.openCursor(IDBKeyRange.bound(e,e+"\uFFFF",!1,!1),"next"),t,{mode:s,transaction:u})};this.iterateOverAllLocalOperations=async(e,{before:t,after:r,mode:o="readonly",transaction:s})=>{let u=(s||this.createTransaction(["operations"],{mode:o})).objectStore("operations"),d=u.index("l_t"),p=r?de(!0,r):He(!0),S=t?de(!0,t):qe(!0),y=IDBKeyRange.bound(p,S,!!r,!0),E=d.openCursor(y,"next");return new Promise((g,v)=>{let I;E.onsuccess=_=>{let O=E.result;if(O){let R=O.value;L(I===void 0||I<=R.timestamp,`expected ${I} <= ${R.timestamp}`),e(R,u),I=R.timestamp,O.continue()}else g()},E.onerror=_=>{ue(E.error)?g():v(E.error)}})};this.iterateOverAllOperations=async(e,{before:t,transaction:r,mode:o,from:s})=>{await this.iterate("operations",a=>{let u=s?He(s):void 0,d=t?qe(t):void 0,p=u&&d?IDBKeyRange.bound(u,d,!1,!0):u?IDBKeyRange.lowerBound(u,!1):d?IDBKeyRange.upperBound(d,!0):void 0;return a.index("timestamp").openCursor(p,"next")},e,{mode:o,transaction:r})};this.addOperations=async(e,{transaction:t}={})=>this.insert(e.map(this.addCompoundIndexes),{transaction:t});this.addCompoundIndexes=e=>({...e,oid_timestamp:de(e.oid,e.timestamp),l_t:de(e.isLocal,e.timestamp),d_t:de($(e.oid),e.timestamp)});this.insert=async(e,{transaction:t})=>{let r=new Set;return await this.runAll("operations",o=>e.map(s=>(r.add($(s.oid)),o.put(s))),{mode:"readwrite",transaction:t}),Array.from(r)};this.reset=()=>this.clear("operations")}};var yn=class{constructor(i,e){this.db=i;this.currentVersion=e;this.cached=null;this.get=async()=>{if(this.cached)return this.cached;let r=this.db.transaction("info","readonly").objectStore("info").get("schema"),o=await J(r);return o?(this.cached=JSON.parse(o.schema),this.cached):null};this.set=async i=>{let o=this.db.transaction("info","readwrite").objectStore("info").put({type:"schema",schema:JSON.stringify(i)});this.cached=i,await J(o)}}};var Dt=class extends z{constructor({disableRebasing:e,context:t,onOperation:r}){super();this.time=new Ut;this.disableRebasing=!1;this._closing=!1;this.setContext=e=>{this.context=e};this.close=()=>{this._closing=!0};this.createTransaction=(e,t={})=>un(this.db,e,t.write?"readwrite":"readonly",t.abort,this.context.log);this.getAllDocumentRelatedOids=async e=>{let t=new Set,r=$(e);L(r===e,"Must be root document OID"),t.add(r);let o=this.createTransaction(["baselines","operations"]);return await Promise.all([this.baselines.iterateOverAllForDocument(r,s=>{t.add(s.oid)},{transaction:o}),this.operations.iterateOverAllOperationsForDocument(r,s=>{t.add(s.oid)},{transaction:o})]),Array.from(t)};this.getAllCollectionRelatedOids=async e=>{let t=new Set,r=this.db.transaction(["baselines","operations"],"readwrite");return await Promise.all([this.baselines.iterateOverAllForCollection(e,o=>{t.add(o.oid)},{transaction:r}),this.operations.iterateOverAllOperationsForCollection(e,o=>{t.add(o.oid)},{transaction:r})]),Array.from(t)};this.getDocumentSnapshot=async(e,t={})=>{let r=$(e);L(r===e,"Must be root document OID");let o=this.db.transaction(["baselines","operations"],"readwrite"),s=await this.baselines.getAllForDocument(r,{transaction:o}),a=new Map;for(let d of s)d.snapshot&&N(d.snapshot,d.oid),a.set(d.oid,d.snapshot);await this.operations.iterateOverAllOperationsForDocument(r,d=>{let p=a.get(d.oid)||void 0,S=$e(p,d.data);S&&N(S,d.oid),a.set(d.oid,S)},{transaction:o,to:t.to||this.now});let u=a.get(r);return u&&en(u,a),u};this.getDocumentData=async(e,t)=>{let r=this.createTransaction(["baselines","operations"],t),o=[],s={};return await Promise.all([this.baselines.iterateOverAllForDocument(e,a=>{o.push(a)},{transaction:r}),this.operations.iterateOverAllOperationsForDocument(e,a=>{s[a.oid]??=[],s[a.oid].push(a)},{transaction:r})]),{baselines:o,operations:s}};this.getDocumentAuthz=async e=>{let t=await this.baselines.get(e);if(t)return t.authz;let r;return await this.operations.iterateOverAllOperationsForEntity(e,o=>{if(o.data.op==="initialize")return r=o.authz,!0},{}),r};this.ack=async e=>{let t=await this.localReplica.get();e>this.now||(this.emit("message",{type:"ack",replicaId:t.id,timestamp:e}),!this._closing&&(!t.ackedLogicalTime||e>t.ackedLogicalTime)&&this.localReplica.update({ackedLogicalTime:e}))};this.insertLocalOperations=async(e,t)=>{if(e.length===0)return;this.log("debug",`Inserting ${e.length} local operations`,e);for(let o of e)o.isLocal=!0;await this.operations.addOperations(e,t);let r=await this.messageCreator.createOperation({operations:e});this.emit("message",r),this.tryAutonomousRebase(),this.onOperation&&e.forEach(o=>this.onOperation(o))};this.insertRemoteOperations=async(e,t)=>{if(e.length===0)return[];this.log("debug",`Inserting ${e.length} remote operations`,e);let r=await this.operations.addOperations(e.map(o=>({...o,isLocal:!1})),t);return this.ack(e[e.length-1].timestamp),this.onOperation&&e.forEach(o=>this.onOperation(o)),r};this.insertRemoteBaselines=async(e,t)=>{if(e.length===0)return[];this.log("debug",`Inserting ${e.length} remote baselines`),await this.baselines.setAll(e,t);let r=new Set;return e.forEach(o=>{r.add($(o.oid))}),Array.from(r)};this.insertData=async(e,t)=>{let r=this.createTransaction(["baselines","operations"],{...t,write:!0});e.baselines&&await this.insertRemoteBaselines(e.baselines,{transaction:r}),!t?.abort?.aborted&&e.operations&&(e.isLocal?await this.insertLocalOperations(e.operations,{transaction:r}):await this.insertRemoteOperations(e.operations,{transaction:r}))};this.updateLastSynced=async e=>{if(!this._closing)return this.localReplica.update({lastSyncedLogicalTime:e})};this.lastSyncedTimestamp=async()=>(await this.localReplica.get()).lastSyncedLogicalTime;this.tryAutonomousRebase=async()=>{this.disableRebasing||(await this.localReplica.get()).lastSyncedLogicalTime||await this.runRebase(this.now)};this.runRebase=async e=>{if(this._closing)return;let t,r=new Set,o=this.createTransaction(["baselines","operations"],{write:!0}),s=0;if(await this.operations.iterateOverAllOperations(u=>{r.add(u.oid),t=u.timestamp,s++},{before:e,transaction:o}),!r.size||this._closing)return;let a=[];for(let u of r)a.push(await this.rebase(u,t||e,o));this.emit("rebase",a)};this.rebase=async(e,t,r)=>{let o=(await this.localReplica.get()).id;this.log("debug","[",o,"]","Rebasing",e,"up to",t);let s=r||this.createTransaction(["operations","baselines"],{write:!0}),a=await this.baselines.get(e,{transaction:s}),u=a?.snapshot||void 0,d=0,p=a?.authz,S=[];await this.operations.iterateOverAllOperationsForEntity(e,(E,g)=>{(!a||E.timestamp>a.timestamp)&&(u=$e(u,E.data,S),E.data.op==="initialize"&&(p=E.authz)),d++,g.delete(E.oid_timestamp)},{to:t,transaction:s}),u&&N(u,e);let y={oid:e,snapshot:u,timestamp:t,authz:p};if(y.snapshot?await this.baselines.set(y,{transaction:s}):await this.baselines.delete(e,{transaction:s}),this.log("debug","successfully rebased",e,"up to",t,":",u,"and deleted",d,"operations"),S.length){let E=S.filter(we);E.length&&this.emit("filesDeleted",E)}return y};this.reset=async()=>{await this.operations.reset(),await this.baselines.reset(),await this.localReplica.reset()};this.updateSchema=async(e,t)=>{let r=await this.schema.get();if(r&&t===r.version&&r.version===e.version&&JSON.stringify(r)!==JSON.stringify(e))throw console.error(`Schema mismatch for version ${e.version}
7
7
  ${JSON.stringify(r)}
8
8
  ${JSON.stringify(e)}`),new Error("Schema has changed without a version change! Any changes to your schema must be accompanied by a change in schema version and a migration routine.");await this.schema.set(e)};this.setGlobalAck=async e=>{this._closing||(await this.ackInfo.setGlobalAck(e),this.disableRebasing||await this.runRebase(e))};this.manualRebase=async()=>{if(this._closing||this.disableRebasing)return;let e=await this.ackInfo.getAckInfo();e.globalAckTimestamp&&this.runRebase(e.globalAckTimestamp)};this.export=async()=>{let e=this.db,[t,r]=await ln(e,["baselines","operations"]),o=await this.localReplica.get(),s=await this.schema.get();if(!s)throw new Error("Cannot export Client data before initializing");return{operations:r,baselines:t,localReplica:o,schemaVersion:s.version}};this.resetFrom=async e=>{let r=this.db.transaction(["baselines","operations","info"],"readwrite");await J(r.objectStore("baselines").clear()),await J(r.objectStore("operations").clear()),await J(r.objectStore("info").clear()),e.localReplica&&await this.localReplica.update({ackedLogicalTime:e.localReplica.ackedLogicalTime,lastSyncedLogicalTime:e.localReplica.lastSyncedLogicalTime},{transaction:r})};this.stats=async()=>{let e=this.db,t=await Qe(e,"operations"),r=await Qe(e,"baselines");return{operationsSize:t,baselinesSize:r}};this.context=t,this.schema=new yn(t.metaDb,t.schema.version),this.operations=new gn(this.db,{log:t.log}),this.baselines=new hn(this.db,{log:t.log}),this.localReplica=new pn(this.db),this.ackInfo=new fn(this.db),this.messageCreator=new mn(this),this.patchCreator=new cn(()=>this.now),this.onOperation=r,e&&(this.disableRebasing=e)}get db(){return this.context.metaDb}get log(){return this.context.log}get now(){return this.time.now(this.schema.currentVersion)}};function co(n){return n.schema&&(n.schemaVersion=n.schema.version,delete n.schema),n}var sa=[aa,ca,la,da,ua,fa];function bn({indexedDB:n=window.indexedDB,namespace:i,log:e,metadataVersion:t=5}){return new Promise((r,o)=>{let s=n.open(`${i}_meta`,t),a=!1;s.onupgradeneeded=async u=>{let d=s.result,p=s.transaction,S=sa.slice(u.oldVersion);for(let y of S)await y(d,p);await new Promise((y,E)=>{p.addEventListener("complete",y),p.addEventListener("error",E)}),u.oldVersion||(a=!0)},s.onerror=()=>{console.error("Error opening database",s.error),o(s.error)},s.onsuccess=()=>{r({db:s.result,wasInitialized:a})}})}async function lo({wipNamespace:n,namespace:i,indexedDB:e,log:t,metadataVersion:r}){let o=await bn({namespace:n,indexedDB:e,log:t,metadataVersion:r});if(!o.wasInitialized)return o;t?.("debug","Beginning copy of production metadata database to WIP");let{db:s}=await bn({namespace:i,indexedDB:e,log:t,metadataVersion:r}),a=s.transaction(["baselines","operations","info"],"readonly"),[u,d,p]=await Promise.all([J(a.objectStore("baselines").getAll()),J(a.objectStore("operations").getAll()),J(a.objectStore("info").getAll())]),S=o.db.transaction(["baselines","operations","info"],"readwrite"),y=S.objectStore("baselines"),E=S.objectStore("operations"),g=S.objectStore("info");for(let v of u)y.put(v);for(let v of d)E.put(v);for(let v of p)g.put(v);return await new Promise((v,I)=>{S.oncomplete=()=>{v()},S.onerror=_=>{I(_)},S.onabort=_=>{I(_)}}),await ge(s),t?.("debug","Finished copy of production metadata database to WIP. Copied:",u.length,"baselines,",d.length,"operations"),o}async function aa(n,i){let e=n.createObjectStore("baselines",{keyPath:"oid"}),t=n.createObjectStore("operations",{keyPath:"oid_timestamp"}),r=n.createObjectStore("info",{keyPath:"type"});e.createIndex("timestamp","timestamp"),t.createIndex("isLocal_timestamp","isLocal_timestamp"),t.createIndex("documentOid_timestamp","documentOid_timestamp")}async function ca(n,i){let e=i.objectStore("operations");await new Promise((t,r)=>{let o=e.openCursor();o.onsuccess=()=>{let s=o.result;if(s){let{isLocal_timestamp:a,documentOid_timestamp:u,...d}=s.value;s.update({...d,l_t:a,d_t:u}),s.continue()}else t()},o.onerror=s=>{r(o.error)}}),e.deleteIndex("isLocal_timestamp"),e.deleteIndex("documentOid_timestamp"),e.createIndex("l_t","l_t",{unique:!1}),e.createIndex("o_t","o_t",{unique:!1}),e.createIndex("d_t","d_t",{unique:!1})}async function la(n,i){i.objectStore("operations").createIndex("timestamp","timestamp")}async function da(n,i){let e=n.createObjectStore("files",{keyPath:"id"});e.createIndex("remote","remote"),e.createIndex("deletedAt","deletedAt")}async function ua(n,i){let e=i.objectStore("operations");await new Promise((r,o)=>{let s=e.openCursor();s.onsuccess=()=>{let a=s.result;if(a){let u=bi(a.value);u.oid_timestamp!==a.primaryKey?(a.delete(),e.put(u)):a.update(u),a.continue()}else r()},s.onerror=a=>{o(s.error)}});let t=i.objectStore("baselines");await new Promise((r,o)=>{let s=t.openCursor();s.onsuccess=()=>{let a=s.result;if(a){let u=bi(a.value);u.oid!==a.primaryKey?(a.delete(),t.put(u)):a.update(u),a.continue()}else r()},s.onerror=a=>{o(s.error)}})}async function fa(n,i){i.objectStore("files").createIndex("timestamp","timestamp")}async function wn(n,i,e,t){function r(a,u){let d,p,S=n.open([i,"collections"].join("_"),e);S.onupgradeneeded=async y=>{d=y.oldVersion;let E=S.transaction;p=S.result,E.abort()},S.onsuccess=y=>{a([S.result.version,S.result])},S.onblocked=y=>{t?.("Database blocked, waiting...")},S.onerror=y=>{a([d,p])}}let[o,s]=await new Promise(r);return await ge(s),o}async function uo(n,i,e,t,r){function o(s,a){let u=n.open([i,"collections"].join("_"),e),d=!1;u.onupgradeneeded=p=>{let S=u.transaction;t(S,u.result,p),d=!0},u.onsuccess=p=>{d?s(u.result):a(new Error("Database was not upgraded when a version change was expected"))},u.onerror=p=>{a(u.error||new Error("Unknown error"))},u.onblocked=p=>{r?.("Database upgrade blocked, waiting...")}}return new Promise(o)}async function fo(n,i){typeof navigator<"u"&&navigator.locks?await navigator.locks.request(`verdant_migration_${n}`,i):await i()}async function Ue({indexedDB:n=Bi,namespace:i,version:e,context:t}){t.log("debug","Opening database",i,"at version",e);let r=await new Promise((o,s)=>{let a=n.open([i,"collections"].join("_"),e);a.onupgradeneeded=async u=>{a.transaction.abort(),t.log("error","Database upgrade needed, but not expected","Expected",e,"Got",a.result.version),s(a.error||new Error(`Migration error: database version changed unexpectedly when reading current data. Expected ${e}, got ${a.result.version}`))},a.onsuccess=u=>{o(a.result)},a.onblocked=u=>{s(new Error("Migration error: database blocked"))},a.onerror=u=>{s(new Error("Migration error: database error"))}});return r.addEventListener("versionchange",o=>{r.close()}),r}async function ho(n,i){let e=new Array;for(let u=0;u<n.objectStoreNames.length;u++)e.push(n.objectStoreNames[u]);let t=n.transaction(e,"readonly"),r=e.map(u=>t.objectStore(u)),o=await Promise.all(r.map(u=>J(u.getAll()))),s=i.transaction(e,"readwrite"),a=e.map(u=>s.objectStore(u));for(let u=0;u<a.length;u++)await Promise.all(o[u].map(d=>J(a[u].put(d))))}var ha=n=>IDBKeyRange.only(Se(n.equals)),pa=n=>{},ma=n=>{let i=n.gte||n.gt,e=n.lte||n.lt;return i===e?IDBKeyRange.only(Se(i)):i?e?IDBKeyRange.bound(Se(i),Se(e),!!n.gt,!!n.lt):IDBKeyRange.lowerBound(Se(i),!!n.gt):IDBKeyRange.upperBound(Se(e),!!n.lt)},ga=(n,i,e)=>{let t=n.collections[i].compounds[e.where];L(t,`Index ${e.where} does not exist on collection ${i}`);let r=Object.keys(e.match).sort((u,d)=>t.of.indexOf(u)-t.of.indexOf(d));for(let u of r)if(t.of.indexOf(u)!==r.indexOf(u))throw new Error(`Compound index ${e.where} does not have ${u} at the start of its order`);let o=r.map(u=>e.match[u]);if(r.length===t.of.length)return IDBKeyRange.only(de(...o));let s=He(...o),a=qe(...o);return IDBKeyRange.bound(s,a)};function ya(n){let i=n.startsWith,e=n.startsWith+"\uFFFF";return IDBKeyRange.bound(i,e)}function vn(n,i,e){if(e)return Oi(e)?ma(e):Si(e)?ha(e):Gr(e)?pa(e):Ii(e)?ya(e):ga(n,i,e)}function ji(n,i,e){return n.transaction(i,e?"readwrite":"readonly").objectStore(i)}async function xn({collection:n,index:i,context:e}){let t=ji(e.documentDb,n),r=i?.where?t.index(i.where):t,o=vn(e.schema,n,i),s=i?.order==="desc"?"prev":"next",a=r.openCursor(o,s);return await new Promise((d,p)=>{a.onsuccess=()=>{let S=a.result;d(S?Y(n,S.primaryKey.toString()):null)},a.onerror=()=>{a.error?.name==="InvalidStateError"?(e.log("error","findOne query failed with InvalidStateError",a.error),d(null)):ue(a.error)?d(null):p(a.error)}})}async function Sn({collection:n,index:i,context:e}){let t=ji(e.documentDb,n),r=i?.where?t.index(i.where):t,o=vn(e.schema,n,i),s=i?.order==="desc"?"prev":"next",a=r.openCursor(o,s);return await new Promise((d,p)=>{let S=new Set;a.onsuccess=()=>{let y=a.result;y?(S.add(Y(n,y.primaryKey.toString())),y.continue()):d(Array.from(S))},a.onerror=()=>{a.error?.name==="InvalidStateError"?(e.log("error","findAll query failed with InvalidStateError",a.error),d([])):ue(a.error)?d([]):p(a.error)}})}async function Et({collection:n,index:i,context:e,limit:t,offset:r}){let o=ji(e.documentDb,n),s=i?.where?o.index(i.where):o,a=vn(e.schema,n,i),u=i?.order==="desc"?"prev":"next",d=s.openCursor(a,u),p=!r,S=!1,y=0;return{result:await new Promise((g,v)=>{let I=new Set;d.onsuccess=()=>{y++;let _=d.result;_?r&&!p?(_.advance(r),p=!0):(t&&I.size<t&&I.add(Y(n,_.primaryKey.toString())),t&&y>t?(S=!0,g(Array.from(I))):_.continue()):g(Array.from(I))},d.onerror=()=>{d.error?.name==="InvalidStateError"?(e.log("error","find query failed with InvalidStateError",d.error),g([])):ue(d.error)?g([]):v(d.error)}}),hasNextPage:S}}function po({migration:n,meta:i,getMigrationNow:e,newOids:t}){return n.allCollections.reduce((r,o)=>(r[o]={put:async(s,a)=>{Fe(n.newSchema.collections[o],s);let u=s[n.newSchema.collections[o].primaryKey],d=Y(o,u);return t.push(d),await i.insertLocalOperations(Ae(s,d,e,void 0,void 0,{authz:a?.access})),s},delete:async s=>{let a=Y(o,s),u=await i.getDocumentAuthz(a),d=await i.getAllDocumentRelatedOids(a);return i.insertLocalOperations(d.map(p=>({oid:p,timestamp:e(),data:{op:"delete"},authz:u})))}},r),{})}function ba({migration:n,context:i,meta:e}){return n.oldCollections.reduce((t,r)=>(t[r]={get:async o=>{let s=Y(r,o);return await e.getDocumentSnapshot(s,{to:e.time.now(n.oldSchema.version)})},findOne:async o=>{let s=await xn({collection:r,index:o,context:i});return s?await e.getDocumentSnapshot(s,{to:e.time.now(n.oldSchema.version)}):null},findAll:async o=>{let s=await Sn({collection:r,index:o,context:i});return await Promise.all(s.map(u=>e.getDocumentSnapshot(u,{to:e.time.now(n.oldSchema.version)})))}},t),{})}function mo({meta:n,migration:i,context:e}){function t(){return n.time.zero(i.version)}let r=new Array,o=ba({migration:i,context:e,meta:n}),s=po({migration:i,getMigrationNow:t,newOids:r,meta:n}),a=async p=>{let S=await n.getAllCollectionRelatedOids(p);return n.insertLocalOperations(S.map(y=>({oid:y,timestamp:t(),data:{op:"delete"}})))},u=new Array;return{log:e.log,newOids:r,deleteCollection:a,migrate:async(p,S)=>{let y=await o[p].findAll();await Promise.all(y.filter(Boolean).map(async E=>{let g=ne(E);L(!!g,`Document is missing an OID: ${JSON.stringify(E)}`);let v=await n.getDocumentAuthz(g),I=le(E),_=await S(E);if(_){xt(I),xt(_),nt(_);let O=St(I,_,t,void 0,[],{mergeUnknownObjects:!0,authz:v});O.length>0&&await n.insertLocalOperations(O)}}))},queries:o,mutations:s,awaitables:u}}function go({meta:n,migration:i,context:e}){function t(){return n.time.zero(i.version)}let r=new Array,o=new Proxy({},{get(){throw new Error("Queries are not available in initial migrations; there is no database yet!")}}),s=po({migration:i,getMigrationNow:t,newOids:r,meta:n});return{log:e.log,newOids:r,deleteCollection:()=>{throw new Error("Calling deleteCollection() in initial migrations is not supported! Use initial migrations to seed initial data using mutations.")},migrate:()=>{throw new Error("Calling migrate() in initial migrations is not supported! Use initial migrations to seed initial data using mutations.")},queries:o,mutations:s,awaitables:[]}}var yo=typeof window<"u"?window.indexedDB:void 0;async function Ct({context:n,toRun:i,meta:e,indexedDB:t=yo,namespace:r=n.namespace}){await fo(r,async()=>{for(let o of i){let s;if(o.oldSchema.version===0)s=go({meta:e,migration:o,context:n}),await o.migrate(s);else{let d=await Ue({indexedDB:t,namespace:r,version:o.oldSchema.version,context:n});s=mo({meta:e,migration:o,context:{...n,documentDb:d}});try{await o.migrate(s),await Promise.all(s.awaitables)}catch(p){throw n.log("critical",`Migration failed (${o.oldSchema.version} -> ${o.newSchema.version})`,p),p instanceof Error?p:new Error("Unknown error during migration")}await ge(d)}n.log("debug","Upgrading database",r,"to version",o.newSchema.version);let a=await Oa({migration:o,indexedDB:t,namespace:r,context:n}),u=await Sa({meta:e,currentVersion:o.oldSchema.version,newVersion:o.newSchema.version});for(let d of o.allCollections){let S=a.transaction(d,"readwrite").objectStore(d),E=(await wa(S)).map(O=>Y(d,`${O}`));E.push(...s.newOids.filter(O=>ce(O).collection===d),...u.filter(O=>ce(O).collection===d));let v=(await Promise.all(E.map(async O=>{try{let R=await e.getDocumentSnapshot(O);return[O,R]}catch(R){return n.log("error","Could not regenerate snapshot during migration for oid",O,"this document will not be preserved",R),null}}))).filter(O=>!!O).map(([O,R])=>{if(!R)return[O,void 0];let w=on(o.newSchema.collections[d],R);return[O,w]}),_=a.transaction(d,"readwrite").objectStore(d);await Promise.all(v.map(([O,R])=>{if(R)return xa(_,R);{let{id:w}=ce(O);return va(_,w)}}))}await ge(a),n.log("debug",`Migration of ${r} complete.`),n.log("info",`
9
9
  \u2B06\uFE0F v${o.newSchema.version} Migration complete. Here's the rundown: