@verdant-web/store 2.7.9 → 2.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bundle/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Use "options.replacer" or "options.ignoreUnknown"
|
|
4
4
|
`)},_domwindow:function(){return p("domwindow")},_bigint:function(l){return p("bigint:"+l.toString())},_process:function(){return p("process")},_timer:function(){return p("timer")},_pipe:function(){return p("pipe")},_tcp:function(){return p("tcp")},_udp:function(){return p("udp")},_tty:function(){return p("tty")},_statwatcher:function(){return p("statwatcher")},_securecontext:function(){return p("securecontext")},_connection:function(){return p("connection")},_zlib:function(){return p("zlib")},_context:function(){return p("context")},_nodescript:function(){return p("nodescript")},_httpparser:function(){return p("httpparser")},_dataview:function(){return p("dataview")},_signal:function(){return p("signal")},_fsevent:function(){return p("fsevent")},_tlswrap:function(){return p("tlswrap")}}}function A(){return{buf:"",write:function(y){this.buf+=y},end:function(y){this.buf+=y},read:function(){return this.buf}}}e.writeToStream=function(y,I,d){return d===void 0&&(d=I,I={}),O(I=C(y,I),d).dispatch(y)}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_9a5aa49d.js","/")},{buffer:3,crypto:5,lYpoI2:11}],2:[function(i,t,e){(function(n,r,s,o,c,f,h,x,E){(function(g){"use strict";var P=typeof Uint8Array<"u"?Uint8Array:Array,b="+".charCodeAt(0),v="/".charCodeAt(0),C="0".charCodeAt(0),S="a".charCodeAt(0),O="A".charCodeAt(0),A="-".charCodeAt(0),y="_".charCodeAt(0);function I(d){return d=d.charCodeAt(0),d===b||d===A?62:d===v||d===y?63:d<C?-1:d<C+10?d-C+26+26:d<O+26?d-O:d<S+26?d-S+26:void 0}g.toByteArray=function(d){var p,l;if(0<d.length%4)throw new Error("Invalid string. Length must be a multiple of 4");var w=d.length,w=d.charAt(w-2)==="="?2:d.charAt(w-1)==="="?1:0,D=new P(3*d.length/4-w),F=0<w?d.length-4:d.length,B=0;function j(M){D[B++]=M}for(p=0;p<F;p+=4,0)j((16711680&(l=I(d.charAt(p))<<18|I(d.charAt(p+1))<<12|I(d.charAt(p+2))<<6|I(d.charAt(p+3))))>>16),j((65280&l)>>8),j(255&l);return w==2?j(255&(l=I(d.charAt(p))<<2|I(d.charAt(p+1))>>4)):w==1&&(j((l=I(d.charAt(p))<<10|I(d.charAt(p+1))<<4|I(d.charAt(p+2))>>2)>>8&255),j(255&l)),D},g.fromByteArray=function(d){var p,l,w,D,F=d.length%3,B="";function j(M){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(M)}for(p=0,w=d.length-F;p<w;p+=3)l=(d[p]<<16)+(d[p+1]<<8)+d[p+2],B+=j((D=l)>>18&63)+j(D>>12&63)+j(D>>6&63)+j(63&D);switch(F){case 1:B=(B+=j((l=d[d.length-1])>>2))+j(l<<4&63)+"==";break;case 2:B=(B=(B+=j((l=(d[d.length-2]<<8)+d[d.length-1])>>10))+j(l>>4&63))+j(l<<2&63)+"="}return B}})(e===void 0?this.base64js={}:e)}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,b,o,c,f,h,x,E){var g=i("base64-js"),P=i("ieee754");function b(a,u,m){if(!(this instanceof b))return new b(a,u,m);var T,_,k,L,Q=typeof a;if(u==="base64"&&Q=="string")for(a=(L=a).trim?L.trim():L.replace(/^\s+|\s+$/g,"");a.length%4!=0;)a+="=";if(Q=="number")T=ee(a);else if(Q=="string")T=b.byteLength(a,u);else{if(Q!="object")throw new Error("First argument needs to be a number, array or string.");T=ee(a.length)}if(b._useTypedArrays?_=b._augment(new Uint8Array(T)):((_=this).length=T,_._isBuffer=!0),b._useTypedArrays&&typeof a.byteLength=="number")_._set(a);else if(H(L=a)||b.isBuffer(L)||L&&typeof L=="object"&&typeof L.length=="number")for(k=0;k<T;k++)b.isBuffer(a)?_[k]=a.readUInt8(k):_[k]=a[k];else if(Q=="string")_.write(a,0,u);else if(Q=="number"&&!b._useTypedArrays&&!m)for(k=0;k<T;k++)_[k]=0;return _}function v(a,u,m,T){return b._charsWritten=lt(function(_){for(var k=[],L=0;L<_.length;L++)k.push(255&_.charCodeAt(L));return k}(u),a,m,T)}function C(a,u,m,T){return b._charsWritten=lt(function(_){for(var k,L,Q=[],Y=0;Y<_.length;Y++)L=_.charCodeAt(Y),k=L>>8,L=L%256,Q.push(L),Q.push(k);return Q}(u),a,m,T)}function S(a,u,m){var T="";m=Math.min(a.length,m);for(var _=u;_<m;_++)T+=String.fromCharCode(a[_]);return T}function O(a,u,m,k){k||(R(typeof m=="boolean","missing or invalid endian"),R(u!=null,"missing offset"),R(u+1<a.length,"Trying to read beyond buffer length"));var _,k=a.length;if(!(k<=u))return m?(_=a[u],u+1<k&&(_|=a[u+1]<<8)):(_=a[u]<<8,u+1<k&&(_|=a[u+1])),_}function A(a,u,m,k){k||(R(typeof m=="boolean","missing or invalid endian"),R(u!=null,"missing offset"),R(u+3<a.length,"Trying to read beyond buffer length"));var _,k=a.length;if(!(k<=u))return m?(u+2<k&&(_=a[u+2]<<16),u+1<k&&(_|=a[u+1]<<8),_|=a[u],u+3<k&&(_+=a[u+3]<<24>>>0)):(u+1<k&&(_=a[u+1]<<16),u+2<k&&(_|=a[u+2]<<8),u+3<k&&(_|=a[u+3]),_+=a[u]<<24>>>0),_}function y(a,u,m,T){if(T||(R(typeof m=="boolean","missing or invalid endian"),R(u!=null,"missing offset"),R(u+1<a.length,"Trying to read beyond buffer length")),!(a.length<=u))return T=O(a,u,m,!0),32768&T?-1*(65535-T+1):T}function I(a,u,m,T){if(T||(R(typeof m=="boolean","missing or invalid endian"),R(u!=null,"missing offset"),R(u+3<a.length,"Trying to read beyond buffer length")),!(a.length<=u))return T=A(a,u,m,!0),2147483648&T?-1*(4294967295-T+1):T}function d(a,u,m,T){return T||(R(typeof m=="boolean","missing or invalid endian"),R(u+3<a.length,"Trying to read beyond buffer length")),P.read(a,u,m,23,4)}function p(a,u,m,T){return T||(R(typeof m=="boolean","missing or invalid endian"),R(u+7<a.length,"Trying to read beyond buffer length")),P.read(a,u,m,52,8)}function l(a,u,m,T,_){if(_||(R(u!=null,"missing value"),R(typeof T=="boolean","missing or invalid endian"),R(m!=null,"missing offset"),R(m+1<a.length,"trying to write beyond buffer length"),bn(u,65535)),_=a.length,!(_<=m))for(var k=0,L=Math.min(_-m,2);k<L;k++)a[m+k]=(u&255<<8*(T?k:1-k))>>>8*(T?k:1-k)}function w(a,u,m,T,_){if(_||(R(u!=null,"missing value"),R(typeof T=="boolean","missing or invalid endian"),R(m!=null,"missing offset"),R(m+3<a.length,"trying to write beyond buffer length"),bn(u,4294967295)),_=a.length,!(_<=m))for(var k=0,L=Math.min(_-m,4);k<L;k++)a[m+k]=u>>>8*(T?k:3-k)&255}function D(a,u,m,T,_){_||(R(u!=null,"missing value"),R(typeof T=="boolean","missing or invalid endian"),R(m!=null,"missing offset"),R(m+1<a.length,"Trying to write beyond buffer length"),wn(u,32767,-32768)),a.length<=m||l(a,0<=u?u:65535+u+1,m,T,_)}function F(a,u,m,T,_){_||(R(u!=null,"missing value"),R(typeof T=="boolean","missing or invalid endian"),R(m!=null,"missing offset"),R(m+3<a.length,"Trying to write beyond buffer length"),wn(u,2147483647,-2147483648)),a.length<=m||w(a,0<=u?u:4294967295+u+1,m,T,_)}function B(a,u,m,T,_){_||(R(u!=null,"missing value"),R(typeof T=="boolean","missing or invalid endian"),R(m!=null,"missing offset"),R(m+3<a.length,"Trying to write beyond buffer length"),si(u,34028234663852886e22,-34028234663852886e22)),a.length<=m||P.write(a,u,m,T,23,4)}function j(a,u,m,T,_){_||(R(u!=null,"missing value"),R(typeof T=="boolean","missing or invalid endian"),R(m!=null,"missing offset"),R(m+7<a.length,"Trying to write beyond buffer length"),si(u,17976931348623157e292,-17976931348623157e292)),a.length<=m||P.write(a,u,m,T,52,8)}e.Buffer=b,e.SlowBuffer=b,e.INSPECT_MAX_BYTES=50,b.poolSize=8192,b._useTypedArrays=function(){try{var a=new ArrayBuffer(0),u=new Uint8Array(a);return u.foo=function(){return 42},u.foo()===42&&typeof u.subarray=="function"}catch{return!1}}(),b.isEncoding=function(a){switch(String(a).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}},b.isBuffer=function(a){return!(a==null||!a._isBuffer)},b.byteLength=function(a,u){var m;switch(a+="",u||"utf8"){case"hex":m=a.length/2;break;case"utf8":case"utf-8":m=be(a).length;break;case"ascii":case"binary":case"raw":m=a.length;break;case"base64":m=ii(a).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":m=2*a.length;break;default:throw new Error("Unknown encoding")}return m},b.concat=function(a,u){if(R(H(a),`Usage: Buffer.concat(list, [totalLength])
|
|
5
5
|
list should be an Array.`),a.length===0)return new b(0);if(a.length===1)return a[0];if(typeof u!="number")for(_=u=0;_<a.length;_++)u+=a[_].length;for(var m=new b(u),T=0,_=0;_<a.length;_++){var k=a[_];k.copy(m,T),T+=k.length}return m},b.prototype.write=function(a,u,m,T){isFinite(u)?isFinite(m)||(T=m,m=void 0):(Y=T,T=u,u=m,m=Y),u=Number(u)||0;var _,k,L,Q,Y=this.length-u;switch((!m||Y<(m=Number(m)))&&(m=Y),T=String(T||"utf8").toLowerCase()){case"hex":_=function(he,ie,re,G){re=Number(re)||0;var J=he.length-re;(!G||J<(G=Number(G)))&&(G=J),R((J=ie.length)%2==0,"Invalid hex string"),J/2<G&&(G=J/2);for(var Fe=0;Fe<G;Fe++){var oi=parseInt(ie.substr(2*Fe,2),16);R(!isNaN(oi),"Invalid hex string"),he[re+Fe]=oi}return b._charsWritten=2*Fe,Fe}(this,a,u,m);break;case"utf8":case"utf-8":k=this,L=u,Q=m,_=b._charsWritten=lt(be(a),k,L,Q);break;case"ascii":case"binary":_=v(this,a,u,m);break;case"base64":k=this,L=u,Q=m,_=b._charsWritten=lt(ii(a),k,L,Q);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":_=C(this,a,u,m);break;default:throw new Error("Unknown encoding")}return _},b.prototype.toString=function(a,u,m){var T,_,k,L,Q=this;if(a=String(a||"utf8").toLowerCase(),u=Number(u)||0,(m=m!==void 0?Number(m):Q.length)===u)return"";switch(a){case"hex":T=function(Y,he,ie){var re=Y.length;(!he||he<0)&&(he=0),(!ie||ie<0||re<ie)&&(ie=re);for(var G="",J=he;J<ie;J++)G+=$(Y[J]);return G}(Q,u,m);break;case"utf8":case"utf-8":T=function(Y,he,ie){var re="",G="";ie=Math.min(Y.length,ie);for(var J=he;J<ie;J++)Y[J]<=127?(re+=ri(G)+String.fromCharCode(Y[J]),G=""):G+="%"+Y[J].toString(16);return re+ri(G)}(Q,u,m);break;case"ascii":case"binary":T=S(Q,u,m);break;case"base64":_=Q,L=m,T=(k=u)===0&&L===_.length?g.fromByteArray(_):g.fromByteArray(_.slice(k,L));break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":T=function(Y,he,ie){for(var re=Y.slice(he,ie),G="",J=0;J<re.length;J+=2)G+=String.fromCharCode(re[J]+256*re[J+1]);return G}(Q,u,m);break;default:throw new Error("Unknown encoding")}return T},b.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},b.prototype.copy=function(a,u,m,T){if(u=u||0,(T=T||T===0?T:this.length)!==(m=m||0)&&a.length!==0&&this.length!==0){R(m<=T,"sourceEnd < sourceStart"),R(0<=u&&u<a.length,"targetStart out of bounds"),R(0<=m&&m<this.length,"sourceStart out of bounds"),R(0<=T&&T<=this.length,"sourceEnd out of bounds"),T>this.length&&(T=this.length);var _=(T=a.length-u<T-m?a.length-u+m:T)-m;if(_<100||!b._useTypedArrays)for(var k=0;k<_;k++)a[k+u]=this[k+m];else a._set(this.subarray(m,m+_),u)}},b.prototype.slice=function(a,u){var m=this.length;if(a=q(a,m,0),u=q(u,m,m),b._useTypedArrays)return b._augment(this.subarray(a,u));for(var T=u-a,_=new b(T,void 0,!0),k=0;k<T;k++)_[k]=this[k+a];return _},b.prototype.get=function(a){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(a)},b.prototype.set=function(a,u){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(a,u)},b.prototype.readUInt8=function(a,u){if(u||(R(a!=null,"missing offset"),R(a<this.length,"Trying to read beyond buffer length")),!(a>=this.length))return this[a]},b.prototype.readUInt16LE=function(a,u){return O(this,a,!0,u)},b.prototype.readUInt16BE=function(a,u){return O(this,a,!1,u)},b.prototype.readUInt32LE=function(a,u){return A(this,a,!0,u)},b.prototype.readUInt32BE=function(a,u){return A(this,a,!1,u)},b.prototype.readInt8=function(a,u){if(u||(R(a!=null,"missing offset"),R(a<this.length,"Trying to read beyond buffer length")),!(a>=this.length))return 128&this[a]?-1*(255-this[a]+1):this[a]},b.prototype.readInt16LE=function(a,u){return y(this,a,!0,u)},b.prototype.readInt16BE=function(a,u){return y(this,a,!1,u)},b.prototype.readInt32LE=function(a,u){return I(this,a,!0,u)},b.prototype.readInt32BE=function(a,u){return I(this,a,!1,u)},b.prototype.readFloatLE=function(a,u){return d(this,a,!0,u)},b.prototype.readFloatBE=function(a,u){return d(this,a,!1,u)},b.prototype.readDoubleLE=function(a,u){return p(this,a,!0,u)},b.prototype.readDoubleBE=function(a,u){return p(this,a,!1,u)},b.prototype.writeUInt8=function(a,u,m){m||(R(a!=null,"missing value"),R(u!=null,"missing offset"),R(u<this.length,"trying to write beyond buffer length"),bn(a,255)),u>=this.length||(this[u]=a)},b.prototype.writeUInt16LE=function(a,u,m){l(this,a,u,!0,m)},b.prototype.writeUInt16BE=function(a,u,m){l(this,a,u,!1,m)},b.prototype.writeUInt32LE=function(a,u,m){w(this,a,u,!0,m)},b.prototype.writeUInt32BE=function(a,u,m){w(this,a,u,!1,m)},b.prototype.writeInt8=function(a,u,m){m||(R(a!=null,"missing value"),R(u!=null,"missing offset"),R(u<this.length,"Trying to write beyond buffer length"),wn(a,127,-128)),u>=this.length||(0<=a?this.writeUInt8(a,u,m):this.writeUInt8(255+a+1,u,m))},b.prototype.writeInt16LE=function(a,u,m){D(this,a,u,!0,m)},b.prototype.writeInt16BE=function(a,u,m){D(this,a,u,!1,m)},b.prototype.writeInt32LE=function(a,u,m){F(this,a,u,!0,m)},b.prototype.writeInt32BE=function(a,u,m){F(this,a,u,!1,m)},b.prototype.writeFloatLE=function(a,u,m){B(this,a,u,!0,m)},b.prototype.writeFloatBE=function(a,u,m){B(this,a,u,!1,m)},b.prototype.writeDoubleLE=function(a,u,m){j(this,a,u,!0,m)},b.prototype.writeDoubleBE=function(a,u,m){j(this,a,u,!1,m)},b.prototype.fill=function(a,u,m){if(u=u||0,m=m||this.length,R(typeof(a=typeof(a=a||0)=="string"?a.charCodeAt(0):a)=="number"&&!isNaN(a),"value is not a number"),R(u<=m,"end < start"),m!==u&&this.length!==0){R(0<=u&&u<this.length,"start out of bounds"),R(0<=m&&m<=this.length,"end out of bounds");for(var T=u;T<m;T++)this[T]=a}},b.prototype.inspect=function(){for(var a=[],u=this.length,m=0;m<u;m++)if(a[m]=$(this[m]),m===e.INSPECT_MAX_BYTES){a[m+1]="...";break}return"<Buffer "+a.join(" ")+">"},b.prototype.toArrayBuffer=function(){if(typeof Uint8Array>"u")throw new Error("Buffer.toArrayBuffer not supported in this browser");if(b._useTypedArrays)return new b(this).buffer;for(var a=new Uint8Array(this.length),u=0,m=a.length;u<m;u+=1)a[u]=this[u];return a.buffer};var M=b.prototype;function q(a,u,m){return typeof a!="number"?m:u<=(a=~~a)?u:0<=a||0<=(a+=u)?a:0}function ee(a){return(a=~~Math.ceil(+a))<0?0:a}function H(a){return(Array.isArray||function(u){return Object.prototype.toString.call(u)==="[object Array]"})(a)}function $(a){return a<16?"0"+a.toString(16):a.toString(16)}function be(a){for(var u=[],m=0;m<a.length;m++){var T=a.charCodeAt(m);if(T<=127)u.push(a.charCodeAt(m));else for(var _=m,k=(55296<=T&&T<=57343&&m++,encodeURIComponent(a.slice(_,m+1)).substr(1).split("%")),L=0;L<k.length;L++)u.push(parseInt(k[L],16))}return u}function ii(a){return g.toByteArray(a)}function lt(a,u,m,T){for(var _=0;_<T&&!(_+m>=u.length||_>=a.length);_++)u[_+m]=a[_];return _}function ri(a){try{return decodeURIComponent(a)}catch{return String.fromCharCode(65533)}}function bn(a,u){R(typeof a=="number","cannot write a non-number as a number"),R(0<=a,"specified a negative value for writing an unsigned value"),R(a<=u,"value is larger than maximum value for type"),R(Math.floor(a)===a,"value has a fractional component")}function wn(a,u,m){R(typeof a=="number","cannot write a non-number as a number"),R(a<=u,"value larger than maximum allowed value"),R(m<=a,"value smaller than minimum allowed value"),R(Math.floor(a)===a,"value has a fractional component")}function si(a,u,m){R(typeof a=="number","cannot write a non-number as a number"),R(a<=u,"value larger than maximum allowed value"),R(m<=a,"value smaller than minimum allowed value")}function R(a,u){if(!a)throw new Error(u||"Failed assertion")}b._augment=function(a){return a._isBuffer=!0,a._get=a.get,a._set=a.set,a.get=M.get,a.set=M.set,a.write=M.write,a.toString=M.toString,a.toLocaleString=M.toString,a.toJSON=M.toJSON,a.copy=M.copy,a.slice=M.slice,a.readUInt8=M.readUInt8,a.readUInt16LE=M.readUInt16LE,a.readUInt16BE=M.readUInt16BE,a.readUInt32LE=M.readUInt32LE,a.readUInt32BE=M.readUInt32BE,a.readInt8=M.readInt8,a.readInt16LE=M.readInt16LE,a.readInt16BE=M.readInt16BE,a.readInt32LE=M.readInt32LE,a.readInt32BE=M.readInt32BE,a.readFloatLE=M.readFloatLE,a.readFloatBE=M.readFloatBE,a.readDoubleLE=M.readDoubleLE,a.readDoubleBE=M.readDoubleBE,a.writeUInt8=M.writeUInt8,a.writeUInt16LE=M.writeUInt16LE,a.writeUInt16BE=M.writeUInt16BE,a.writeUInt32LE=M.writeUInt32LE,a.writeUInt32BE=M.writeUInt32BE,a.writeInt8=M.writeInt8,a.writeInt16LE=M.writeInt16LE,a.writeInt16BE=M.writeInt16BE,a.writeInt32LE=M.writeInt32LE,a.writeInt32BE=M.writeInt32BE,a.writeFloatLE=M.writeFloatLE,a.writeFloatBE=M.writeFloatBE,a.writeDoubleLE=M.writeDoubleLE,a.writeDoubleBE=M.writeDoubleBE,a.fill=M.fill,a.inspect=M.inspect,a.toArrayBuffer=M.toArrayBuffer,a}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,g,o,c,f,h,x,E){var g=i("buffer").Buffer,P=4,b=new g(P);b.fill(0),t.exports={hash:function(v,C,S,O){for(var A=C(function(l,w){l.length%P!=0&&(D=l.length+(P-l.length%P),l=g.concat([l,b],D));for(var D,F=[],B=w?l.readInt32BE:l.readInt32LE,j=0;j<l.length;j+=P)F.push(B.call(l,j));return F}(v=g.isBuffer(v)?v:new g(v),O),8*v.length),C=O,y=new g(S),I=C?y.writeInt32BE:y.writeInt32LE,d=0;d<A.length;d++)I.call(y,A[d],4*d,!0);return y}}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,g,o,c,f,h,x,E){var g=i("buffer").Buffer,P=i("./sha"),b=i("./sha256"),v=i("./rng"),C={sha1:P,sha256:b,md5:i("./md5")},S=64,O=new g(S);function A(l,w){var D=C[l=l||"sha1"],F=[];return D||y("algorithm:",l,"is not yet supported"),{update:function(B){return g.isBuffer(B)||(B=new g(B)),F.push(B),B.length,this},digest:function(B){var j=g.concat(F),j=w?function(M,q,ee){g.isBuffer(q)||(q=new g(q)),g.isBuffer(ee)||(ee=new g(ee)),q.length>S?q=M(q):q.length<S&&(q=g.concat([q,O],S));for(var H=new g(S),$=new g(S),be=0;be<S;be++)H[be]=54^q[be],$[be]=92^q[be];return ee=M(g.concat([H,ee])),M(g.concat([$,ee]))}(D,w,j):D(j);return F=null,B?j.toString(B):j}}}function y(){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 A(l)},e.createHmac=A,e.randomBytes=function(l,w){if(!w||!w.call)return new g(v(l));try{w.call(this,void 0,new g(v(l)))}catch(D){w(D)}};var I,d=["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],p=function(l){e[l]=function(){y("sorry,",l,"is not implemented yet")}};for(I in d)p(d[I],I)}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){var g=i("./helpers");function P(y,I){y[I>>5]|=128<<I%32,y[14+(I+64>>>9<<4)]=I;for(var d=1732584193,p=-271733879,l=-1732584194,w=271733878,D=0;D<y.length;D+=16){var F=d,B=p,j=l,M=w,d=v(d,p,l,w,y[D+0],7,-680876936),w=v(w,d,p,l,y[D+1],12,-389564586),l=v(l,w,d,p,y[D+2],17,606105819),p=v(p,l,w,d,y[D+3],22,-1044525330);d=v(d,p,l,w,y[D+4],7,-176418897),w=v(w,d,p,l,y[D+5],12,1200080426),l=v(l,w,d,p,y[D+6],17,-1473231341),p=v(p,l,w,d,y[D+7],22,-45705983),d=v(d,p,l,w,y[D+8],7,1770035416),w=v(w,d,p,l,y[D+9],12,-1958414417),l=v(l,w,d,p,y[D+10],17,-42063),p=v(p,l,w,d,y[D+11],22,-1990404162),d=v(d,p,l,w,y[D+12],7,1804603682),w=v(w,d,p,l,y[D+13],12,-40341101),l=v(l,w,d,p,y[D+14],17,-1502002290),d=C(d,p=v(p,l,w,d,y[D+15],22,1236535329),l,w,y[D+1],5,-165796510),w=C(w,d,p,l,y[D+6],9,-1069501632),l=C(l,w,d,p,y[D+11],14,643717713),p=C(p,l,w,d,y[D+0],20,-373897302),d=C(d,p,l,w,y[D+5],5,-701558691),w=C(w,d,p,l,y[D+10],9,38016083),l=C(l,w,d,p,y[D+15],14,-660478335),p=C(p,l,w,d,y[D+4],20,-405537848),d=C(d,p,l,w,y[D+9],5,568446438),w=C(w,d,p,l,y[D+14],9,-1019803690),l=C(l,w,d,p,y[D+3],14,-187363961),p=C(p,l,w,d,y[D+8],20,1163531501),d=C(d,p,l,w,y[D+13],5,-1444681467),w=C(w,d,p,l,y[D+2],9,-51403784),l=C(l,w,d,p,y[D+7],14,1735328473),d=S(d,p=C(p,l,w,d,y[D+12],20,-1926607734),l,w,y[D+5],4,-378558),w=S(w,d,p,l,y[D+8],11,-2022574463),l=S(l,w,d,p,y[D+11],16,1839030562),p=S(p,l,w,d,y[D+14],23,-35309556),d=S(d,p,l,w,y[D+1],4,-1530992060),w=S(w,d,p,l,y[D+4],11,1272893353),l=S(l,w,d,p,y[D+7],16,-155497632),p=S(p,l,w,d,y[D+10],23,-1094730640),d=S(d,p,l,w,y[D+13],4,681279174),w=S(w,d,p,l,y[D+0],11,-358537222),l=S(l,w,d,p,y[D+3],16,-722521979),p=S(p,l,w,d,y[D+6],23,76029189),d=S(d,p,l,w,y[D+9],4,-640364487),w=S(w,d,p,l,y[D+12],11,-421815835),l=S(l,w,d,p,y[D+15],16,530742520),d=O(d,p=S(p,l,w,d,y[D+2],23,-995338651),l,w,y[D+0],6,-198630844),w=O(w,d,p,l,y[D+7],10,1126891415),l=O(l,w,d,p,y[D+14],15,-1416354905),p=O(p,l,w,d,y[D+5],21,-57434055),d=O(d,p,l,w,y[D+12],6,1700485571),w=O(w,d,p,l,y[D+3],10,-1894986606),l=O(l,w,d,p,y[D+10],15,-1051523),p=O(p,l,w,d,y[D+1],21,-2054922799),d=O(d,p,l,w,y[D+8],6,1873313359),w=O(w,d,p,l,y[D+15],10,-30611744),l=O(l,w,d,p,y[D+6],15,-1560198380),p=O(p,l,w,d,y[D+13],21,1309151649),d=O(d,p,l,w,y[D+4],6,-145523070),w=O(w,d,p,l,y[D+11],10,-1120210379),l=O(l,w,d,p,y[D+2],15,718787259),p=O(p,l,w,d,y[D+9],21,-343485551),d=A(d,F),p=A(p,B),l=A(l,j),w=A(w,M)}return Array(d,p,l,w)}function b(y,I,d,p,l,w){return A((I=A(A(I,y),A(p,w)))<<l|I>>>32-l,d)}function v(y,I,d,p,l,w,D){return b(I&d|~I&p,y,I,l,w,D)}function C(y,I,d,p,l,w,D){return b(I&p|d&~p,y,I,l,w,D)}function S(y,I,d,p,l,w,D){return b(I^d^p,y,I,l,w,D)}function O(y,I,d,p,l,w,D){return b(d^(I|~p),y,I,l,w,D)}function A(y,I){var d=(65535&y)+(65535&I);return(y>>16)+(I>>16)+(d>>16)<<16|65535&d}t.exports=function(y){return g.hash(y,P,16)}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){var g;t.exports=g||function(P){for(var b,v=new Array(P),C=0;C<P;C++)!(3&C)&&(b=4294967296*Math.random()),v[C]=b>>>((3&C)<<3)&255;return v}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){var g=i("./helpers");function P(C,S){C[S>>5]|=128<<24-S%32,C[15+(S+64>>9<<4)]=S;for(var O,A,y,I=Array(80),d=1732584193,p=-271733879,l=-1732584194,w=271733878,D=-1009589776,F=0;F<C.length;F+=16){for(var B=d,j=p,M=l,q=w,ee=D,H=0;H<80;H++){I[H]=H<16?C[F+H]:v(I[H-3]^I[H-8]^I[H-14]^I[H-16],1);var $=b(b(v(d,5),($=p,A=l,y=w,(O=H)<20?$&A|~$&y:!(O<40)&&O<60?$&A|$&y|A&y:$^A^y)),b(b(D,I[H]),(O=H)<20?1518500249:O<40?1859775393:O<60?-1894007588:-899497514)),D=w,w=l,l=v(p,30),p=d,d=$}d=b(d,B),p=b(p,j),l=b(l,M),w=b(w,q),D=b(D,ee)}return Array(d,p,l,w,D)}function b(C,S){var O=(65535&C)+(65535&S);return(C>>16)+(S>>16)+(O>>16)<<16|65535&O}function v(C,S){return C<<S|C>>>32-S}t.exports=function(C){return g.hash(C,P,20,!0)}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){function g(S,O){var A=(65535&S)+(65535&O);return(S>>16)+(O>>16)+(A>>16)<<16|65535&A}function P(S,O){var A,y=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),I=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),d=new Array(64);S[O>>5]|=128<<24-O%32,S[15+(O+64>>9<<4)]=O;for(var p,l,w=0;w<S.length;w+=16){for(var D=I[0],F=I[1],B=I[2],j=I[3],M=I[4],q=I[5],ee=I[6],H=I[7],$=0;$<64;$++)d[$]=$<16?S[$+w]:g(g(g((l=d[$-2],v(l,17)^v(l,19)^C(l,10)),d[$-7]),(l=d[$-15],v(l,7)^v(l,18)^C(l,3))),d[$-16]),A=g(g(g(g(H,v(l=M,6)^v(l,11)^v(l,25)),M&q^~M&ee),y[$]),d[$]),p=g(v(p=D,2)^v(p,13)^v(p,22),D&F^D&B^F&B),H=ee,ee=q,q=M,M=g(j,A),j=B,B=F,F=D,D=g(A,p);I[0]=g(D,I[0]),I[1]=g(F,I[1]),I[2]=g(B,I[2]),I[3]=g(j,I[3]),I[4]=g(M,I[4]),I[5]=g(q,I[5]),I[6]=g(ee,I[6]),I[7]=g(H,I[7])}return I}var b=i("./helpers"),v=function(S,O){return S>>>O|S<<32-O},C=function(S,O){return S>>>O};t.exports=function(S){return b.hash(S,P,32,!0)}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){e.read=function(g,P,b,v,w){var S,O,A=8*w-v-1,y=(1<<A)-1,I=y>>1,d=-7,p=b?w-1:0,l=b?-1:1,w=g[P+p];for(p+=l,S=w&(1<<-d)-1,w>>=-d,d+=A;0<d;S=256*S+g[P+p],p+=l,d-=8);for(O=S&(1<<-d)-1,S>>=-d,d+=v;0<d;O=256*O+g[P+p],p+=l,d-=8);if(S===0)S=1-I;else{if(S===y)return O?NaN:1/0*(w?-1:1);O+=Math.pow(2,v),S-=I}return(w?-1:1)*O*Math.pow(2,S-v)},e.write=function(g,P,b,v,C,D){var O,A,y=8*D-C-1,I=(1<<y)-1,d=I>>1,p=C===23?Math.pow(2,-24)-Math.pow(2,-77):0,l=v?0:D-1,w=v?1:-1,D=P<0||P===0&&1/P<0?1:0;for(P=Math.abs(P),isNaN(P)||P===1/0?(A=isNaN(P)?1:0,O=I):(O=Math.floor(Math.log(P)/Math.LN2),P*(v=Math.pow(2,-O))<1&&(O--,v*=2),2<=(P+=1<=O+d?p/v:p*Math.pow(2,1-d))*v&&(O++,v/=2),I<=O+d?(A=0,O=I):1<=O+d?(A=(P*v-1)*Math.pow(2,C),O+=d):(A=P*Math.pow(2,d-1)*Math.pow(2,C),O=0));8<=C;g[b+l]=255&A,l+=w,A/=256,C-=8);for(O=O<<C|A,y+=C;0<y;g[b+l]=255&O,l+=w,O/=256,y-=8);g[b+l-w]|=128*D}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){var g,P,b;function v(){}(n=t.exports={}).nextTick=(P=typeof window<"u"&&window.setImmediate,b=typeof window<"u"&&window.postMessage&&window.addEventListener,P?function(C){return window.setImmediate(C)}:b?(g=[],window.addEventListener("message",function(C){var S=C.source;S!==window&&S!==null||C.data!=="process-tick"||(C.stopPropagation(),0<g.length&&g.shift()())},!0),function(C){g.push(C),window.postMessage("process-tick","*")}):function(C){setTimeout(C,0)}),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.on=v,n.addListener=v,n.once=v,n.off=v,n.removeListener=v,n.removeAllListeners=v,n.emit=v,n.binding=function(C){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(C){throw new Error("process.chdir is not supported")}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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 ni={};hr(ni,{Client:()=>Be,ClientDescriptor:()=>gn,Entity:()=>ye,EntityFile:()=>ke,MigrationPathError:()=>Ve,ServerSync:()=>Ke,Storage:()=>Be,StorageDescriptor:()=>gn,collection:()=>zi,createDefaultMigration:()=>qn,createMigration:()=>Wn,migrate:()=>Rt,schema:()=>$i});var Oi=dt(ft(),1),ht=4,Qe=36;function bi(i){return i.toString(Qe).padStart(ht,"0")}function xr(i){return i.toString().padStart(6,"0")}var mt=class{constructor(){this.latest={time:Date.now(),counter:0,node:Or()};this.zeroCounter=0;this.now=t=>(this.latest=vi(this.latest),this.get(t,this.latest));this.OLD_now=t=>(this.latest=vi(this.latest),xr(t)+Dr(this.latest));this.timerState=()=>this.latest;this.update=t=>{let e=t.slice(ht);this.latest=Ir(this.latest,Si(e))};this.get=(t,e)=>bi(t)+wi(e);this.zero=t=>bi(t)+wi({time:0,counter:this.zeroCounter++,node:this.latest.node});this.getWallClockTime=t=>Si(t.slice(ht)).time}},yt=class extends Error{constructor(...e){super();this.type="ClockDriftError",this.message=["maximum clock drift exceeded"].concat(e).join(" ")}},gt=class extends Error{constructor(){super();this.type="OverflowError",this.message="timestamp counter overflow"}},Dn=4,Cn=7,bt=60*1e3,He=9;function Or(){return Oi.default.slug().padStart(Cn,"0").slice(0,Cn)}function wi(i){let t=new Date(i.time).getTime().toString(Qe).padStart(He,"0"),e=i.counter.toString(Qe).padStart(Dn,"0"),n=i.node.padStart(Cn,"0");return`${t}${e}${n}`}function vi(i){let t=Date.now(),e=Math.max(i.time,t),n=i.time===e?i.counter+1:0;if(e-t>bt)throw new yt(e,t,bt);if(n>65535)throw new gt;return{time:e,counter:n,node:i.node}}function Ir(i,t){let e=Date.now(),n=Math.max(e,Math.max(i.time,t.time)),r=Math.max(i.counter,t.counter),s;if(i.time===n&&t.time===n?s=r+1:i.time===n?s=i.counter+1:t.time===n?s=t.counter+1:s=0,n-e>bt)throw new yt(n,e,bt);if(s>65535)throw new gt;return{time:n,counter:s,node:i.node}}function Si(i){let t=i.slice(0,He),e=i.slice(He,He+Dn),n=i.slice(He+Dn),r=parseInt(t,Qe),s=parseInt(e,Qe);if(isNaN(r)||isNaN(s))throw new Error("invalid clock format");return{time:r,counter:s,node:n}}function Dr(i){let t=new Date(i.time).toISOString(),e=i.counter.toString(16).toUpperCase().padStart(4,"0"),n=i.node.padStart(16,"0");return`${t}-${e}-${n}`}function xi(i){return parseInt(i.slice(0,ht),36)}function Ii(i,t){return xi(i)-xi(t)}function se(i){return i&&i["@@type"]==="file"}function Di(i){return{"@@type":"file",id:i}}var wt,Cr=new Uint8Array(16);function En(){if(!wt&&(wt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!wt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return wt(Cr)}var Ci=/^(?:[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 Er(i){return typeof i=="string"&&Ci.test(i)}var Ei=Er;var Z=[];for(vt=0;vt<256;++vt)Z.push((vt+256).toString(16).substr(1));var vt;function Pr(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(Z[i[t+0]]+Z[i[t+1]]+Z[i[t+2]]+Z[i[t+3]]+"-"+Z[i[t+4]]+Z[i[t+5]]+"-"+Z[i[t+6]]+Z[i[t+7]]+"-"+Z[i[t+8]]+Z[i[t+9]]+"-"+Z[i[t+10]]+Z[i[t+11]]+Z[i[t+12]]+Z[i[t+13]]+Z[i[t+14]]+Z[i[t+15]]).toLowerCase();if(!Ei(e))throw TypeError("Stringified UUID is invalid");return e}var Pi=Pr;function _r(i,t,e){i=i||{};var n=i.random||(i.rng||En)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){e=e||0;for(var r=0;r<16;++r)t[e+r]=n[r];return t}return Pi(n)}var Je=_r;function te(i){return ne(i)||se(i)}function Pn(i,t){return i===t?!0:!(!te(i)||!te(t)||i["@@type"]!==t["@@type"]||i.id!==t.id)}var Ri=dt(Ai(),1);function Tr(i,t){return typeof t!="object"||t===null||Array.isArray(t)?t:Object.fromEntries(Object.entries(t).sort(([e],[n])=>e<n?-1:e>n?1:0))}function Ye(i){return JSON.stringify(i,Tr)}function oe(i,t=!0){if(z(i)||Array.isArray(i)){let e=ce(i),n;if(Array.isArray(i))n=i.map(r=>oe(r,t));else{n={};for(let[r,s]of Object.entries(i))n[r]=oe(s,t)}return t&&e&&K(n,e),n}return i}function Se(i){return(0,Ri.default)(i)}function z(i){return i&&typeof i=="object"}function ki(i){for(var t=[],e=[i],n=0;e.length;){var r=e.pop();if(typeof r=="boolean")n+=4;else if(typeof r=="string")n+=r.length*2;else if(typeof r=="number")n+=8;else if(typeof r=="object"&&t.indexOf(r)===-1){t.push(r);for(var s in r)e.push(r[s])}}return n}function V(i,t="assertion failed"){if(!i)throw new Error(t)}function St(i=16){return Je().replace("-","").slice(0,i)}function Mi(i,t){for(let e=i.length-1;e>=0;e--)if(t(i[e]))return e;return-1}function Bi(i,t){let e;return function(...n){let r=this;clearTimeout(e),e=setTimeout(()=>i.apply(r,n),t)}}var Ie="__@@oid_do_not_use",De="@@id",Ar="/",It=":",Tn=new WeakMap;function le(i){let t=ce(i);return V(!!t,`Object ${JSON.stringify(i)} does not have an OID assigned to it`),t}function ce(i){if(z(i))return Tn.get(i)??i[De]??i[Ie]}function K(i,t){return V(z(i),`Only objects can be assigned OIDs, received ${JSON.stringify(i)}`),Xe(i)&&Dt(i),Tn.set(i,t),i}function Xe(i){return!!ce(i)}function Dt(i){return Tn.delete(i),i}function An(i){return i===De||i===Ie}function Rn(i,t,e){if(Xe(i))return le(i);{let n=ge(t,e);return K(i,n),n}}function Fi(i,t,e){if(Xe(i)){let n=le(i);if(Ct(n,t))return le(i);{let r=ge(t,e);return K(i,r),r}}else{let n=ge(t,e);return K(i,n),n}}var _n={".":"˙","/":"&slash;",":":":"};function ji(i){return i.replace(/[/]/g,_n["/"]).replace(/[:]/g,_n[":"]).replace(/[.]/g,_n["."])}function Li(i){return i.replace(/&slash;/g,"/").replace(/:/g,":").replace(/˙/g,".")}function X(i,t,e){let n=ji(i)+Ar+ji(t);return e&&(n+=It+e),n}function ge(i,t=Br){let{collection:e,id:n}=ae(i);return X(e,n,t())}function ae(i){let[t,e]=i.split(It),[n,r,...s]=t.split("/");s.length&&(r+="/"+s.join("/"));let o;return r.includes(".")?o=r.slice(0,r.indexOf(".")):o=r,{collection:Li(n),id:Li(o),subId:e}}function je(i,t){let e=le(i);if(Array.isArray(i)){let n;for(let r=0;r<i.length;r++)n=i[r],z(n)&&!te(n)&&(Fi(n,e,t),je(n,t))}else if(z(i)&&!te(i))for(let n of Object.keys(i))z(i[n])&&!te(i[n])&&(Fi(i[n],e,t),je(i[n],t))}function Rr(i){if(z(i))return i[De]||i[Ie]}function kr(i){return z(i)&&(delete i[Ie],delete i[De]),i}function Mr(i){let t=Rr(i);t&&K(i,t)}function Ge(i){if(Mr(i),kr(i),Array.isArray(i))for(let t=0;t<i.length;t++)Ge(i[t]);else if(z(i))for(let t of Object.keys(i))Ge(i[t])}function xt(i){if(Dt(i),Array.isArray(i))for(let t=0;t<i.length;t++)xt(i[t]);else if(z(i))for(let t of Object.keys(i))xt(i[t])}function Br(){return Je().slice(0,8)}function we(i){return{"@@type":"ref",id:i}}function Ot(i,t=new Map){if(Array.isArray(i)){let e=le(i),n=K([],e);for(let r=0;r<i.length;r++){let s=i[r];if(z(s)){if(ne(s))throw new Error("An attempt was made to normalize an already normalized object! This is an error in verdant itself.");if(se(s)){n[r]=s;continue}else{let o=le(s);n[r]=we(o),Ot(s,t)}}else n[r]=s}t.set(e,n)}else if(z(i)&&!te(i)){let e=le(i),n=K({},e);for(let r of Object.keys(i)){let s=i[r];if(z(s)){if(ne(s))throw new Error("An attempt was made to normalize an already normalized object! This is an error in verdant itself.");if(se(s))n[r]=s;else{let o=le(s);n[r]=we(o),Ot(s,t)}}else n[r]=s}t.set(e,n)}else te(i);return t}function U(i){return i.split(".")[0].split(It)[0]}function kn(i){let t=U(i),e=ge(t,()=>"\uFFFF");return[`${t}${It}`,e]}function Mn(i){let t=U(i);return[`${t}.`,`${t}.\uFFFF`]}function Ct(i,t){return U(i)===U(t)}function Fr(i){let{collection:t,id:e,subId:n}=ae(i);return X(t,e,n)}var jr=/"[^"]+\/[^"]+?(\.[^"]+)+\:[^"]+"/g;function Lr(i){return i.replaceAll(jr,t=>{let e=t.slice(1,t.length-1);return`"${Fr(e)}"`})}function Bn(i){return JSON.parse(Lr(JSON.stringify(i)))}function ne(i){return i&&typeof i=="object"&&i["@@type"]==="ref"}function Fn(i){return z(i)&&!te(i)}function Vr(i,t){return i===t?!0:te(i)&&te(t)?Pn(i,t):!1}function Ze(i,t,e,n,r=[],s={}){let o=le(i);function c(f,h,x){if(!Fn(h))Vr(h,x)||r.push({oid:o,timestamp:e(),data:{op:"set",name:f,value:h}});else{let E=ce(x),g=ce(h);g&&!Ct(o,g)?(h=oe(h,!1),g=ge(o,n),K(h,g)):s.mergeUnknownObjects?!g&&E?(K(h,E),g=E):g=Rn(h,o,n):g=Rn(h,o,n),V(!!g,"Error: no value OID was resolved during diff. This is a bug in Verdant."),V(Ct(o,g),`Error: value OID ${g} is not related to parent OID ${o}. This is a bug in Verdant.`),x===void 0||g!==E?(xe(h,g,e,n,r),r.push({oid:o,timestamp:e(),data:{op:"set",name:f,value:we(g)}}),E!==void 0&&r.push({oid:E,timestamp:e(),data:{op:"delete"}})):Ze(x,h,e,n,r,s)}}if(Array.isArray(i)&&Array.isArray(t)){for(let h=0;h<t.length;h++){let x=t[h],E=i[h];c(h,x,E)}let f=i.length-t.length;if(f>0){for(let h=t.length;h<i.length;h++){let x=i[h],E=ce(x);E&&r.push({oid:E,timestamp:e(),data:{op:"delete"}})}r.push({oid:o,timestamp:e(),data:{op:"list-delete",index:t.length,count:f}})}}else{if(Array.isArray(i)||Array.isArray(t))throw new Error("Cannot diff an array with an object");if(Fn(i)&&Fn(t)){let f=new Set(Object.keys(i));for(let[h,x]of Object.entries(t)){if(x===void 0&&s.defaultUndefined||(f.delete(h),An(h)))continue;let E=i[h];c(h,x,E)}if(!s.defaultUndefined)for(let h of f)An(h)||r.push({oid:o,timestamp:e(),data:{op:"remove",name:h}})}}return r}function xe(i,t,e,n,r=[]){K(i,t),je(i,n);let s=Ot(i);for(let o of s.keys()){let c=s.get(o);r.push({oid:o,timestamp:e(),data:{op:"initialize",value:Dt(c)}})}return r}function Ni(i){let t={};for(let e of i)e.oid in t?t[e.oid].push(e):t[e.oid]=[e];return t}function jn(i){let t={};for(let e of i){let n=U(e.oid);n in t?t[n].push(e):t[n]=[e]}return t}function Ln(i){let t={};for(let e of i){let n=U(e.oid);n in t?t[n].push(e):t[n]=[e]}return t}function Ce(i){return Array.isArray(i)?!0:(console.error(`Cannot apply list patch; expected array, received ${JSON.stringify(i)}. This suggests your data is changing from a list to an object over time. (OID: ${ce(i)})`),!1)}function Ee(i,t,e){if(i==null&&t.op!=="initialize")return i;let n=i,r,s;function o(c){e&&te(c)&&e.push(c)}switch(t.op){case"set":o(n[t.name]),n[t.name]=t.value;break;case"remove":o(n[t.name]),delete n[t.name];break;case"list-push":Ce(i)&&i.push(t.value);break;case"list-delete":Ce(i)&&(o(i[t.index]),i.splice(t.index,t.count));break;case"list-move-by-index":Ce(i)&&(s=i.splice(t.from,1),i.splice(t.to,0,s[0]));break;case"list-remove":if(Ce(i))do{let c=t.value;t.only==="last"?ne(c)?r=Mi(i,f=>f.id===c.id):r=i.lastIndexOf(c):ne(c)?r=i.findIndex(f=>f.id===c.id):r=i.indexOf(c),r!==-1&&(o(i[r]),i.splice(r,1))}while(!t.only&&r!==-1);break;case"list-add":Ce(i)&&(i.some(f=>ne(f)&&ne(t.value)?f.id===t.value.id:f===t.value)||i.push(t.value));break;case"list-move-by-ref":Ce(i)&&(r=i.indexOf(t.value),s=i.splice(r,1),i.splice(t.index,0,s[0]));break;case"list-insert":if(Ce(i)){if(!t.value&&!t.values)throw new Error(`Cannot apply list insert patch; expected value or values, received ${JSON.stringify(t)}`);t.value?i.splice(t.index,0,t.value):i.splice(t.index,0,...t.values)}break;case"delete":Array.isArray(i)?i.forEach(o):z(i)&&Object.values(i||{}).forEach(o);return;case"initialize":return oe(t.value);default:throw new Error(`Unsupported patch operation: ${t.op}`)}return i}function Et(i,t,e=[]){if(Array.isArray(i))for(let n=0;n<i.length;n++){let r=i[n];i[n]=Vi(r,t,e),z(i[n])&&Et(i[n],t,e)}else if(!se(i)){if(z(i)){V(ce(i),`Object ${JSON.stringify(i)} must have an oid`);for(let n of Object.keys(i))i[n]=Vi(i[n],t,e),z(i[n])&&Et(i[n],t,e)}}return e}function Vi(i,t,e){if(ne(i)){e.push(i.id);let n=t.get(i.id);return V(!!n,`No value was found in object map for ${i.id}`),K(n,i.id)}else return i}function Nr(i){return i.type==="any"?!0:i.type==="map"?!1:i.nullable}function Nn(i){return i?i.type==="map"||i.type==="array"?!0:i.type==="file"?!1:i.type==="object"?!0:i.default!==void 0:!1}function Pt(i){return i.type==="map"||i.type==="object"||i.type==="array"||i.type==="file"||i.type==="any"?!1:i.indexed}function ve(i,t){for(let[e,n]of Object.entries(i.fields)){let r=Ui(n);(r!==void 0&&t[e]===void 0||!Nr(n)&&t[e]===null)&&(t[e]=r),t[e]&&Pe(t[e],n)}return t}function Pe(i,t){if(i==null)return i;if(t.type==="object")for(let[e,n]of Object.entries(t.properties)){if(i[e]===void 0){let r=Ui(n);r!==void 0&&(i[e]=r)}Pe(i[e],n)}else if(t.type==="array")for(let e of i)Pe(e,t.items);else if(t.type==="map")for(let[e,n]of Object.entries(i))e===De||e===Ie||Pe(n,t.values)}function Ui(i){if(i.type==="string"||i.type==="number"||i.type==="boolean"||i.type==="any"){if(i.default&&typeof i.default=="function")return i.default();if(i.default!==void 0)return JSON.parse(JSON.stringify(i.default))}if(i.type==="array")return[];if(i.type==="map")return{};if(i.type!=="any"&&i.nullable)return null}function Un(i,t){for(let[e,n]of Object.entries(t))e===De||e===Ie||(i.fields[e]?Vn(n,i.fields[e]):delete t[e]);return t}function Vn(i,t){if(z(i)&&t.type==="object")for(let[e,n]of Object.entries(i))t.properties[e]?Vn(n,t.properties[e]):delete i[e];else if(Array.isArray(i)&&t.type==="array")for(let e of i)Vn(e,t.items)}function Kn(i){return i.equals!==void 0}function zn(i){return i.gte!==void 0||i.lte!==void 0||i.gt!==void 0||i.lt!==void 0}function Ur(i){return!!i.match}function $n(i){return i.startsWith!==void 0}function Ki(i){return!zn(i)&&!Kn(i)&&!Ur(i)&&!$n(i)&&i.order}function zi({synthetics:i,indexes:t,...e}){let n={...i,...t};for(let[r,s]of Object.entries(e.fields))Pt(s)&&(n[r]={field:r});return{...e,indexes:n}}function $i(i){return i}var _t="\uFFFFFE",Kr="\0",zr="\uFFFFFF";function de(...i){let t=$r(i);return t.length===1?t[0]:t}function _e(...i){return i.join(_t)+`${zr}`}function Te(...i){return i.join(_t)+`${_t}${Kr}`}function $r(i){let t=[[]];for(let e of i)if(Array.isArray(e)){let n=[];for(let r of t)for(let s of e)n.push(r.concat(s));t=n}else for(let n of t)n.push(`${e}`);return Array.from(new Set(t.map(e=>e.join(_t))))}function qr(i){return!!i.field}function Wr(i,t){let e={};for(let[n,r]of Object.entries(i.indexes||{})){let s=r;qr(s)?e[n]=me(t[s.field]):e[n]=me(s.compute(t))}return e}function Hr(i,t){return Object.entries(i.compounds||{}).reduce((e,[n,r])=>(e[n]=de(...r.of.map(s=>t[s])),e),{})}function Qr(i,t){return Object.entries(i.fields).reduce((e,[n,r])=>(Pt(r)&&(e[n]=me(t[n])),e),{})}function Tt(i,t){return{[i.primaryKey]:t[i.primaryKey],...Qr(i,t),...Wr(i,t),...Hr(i,t),"@@@snapshot":t}}var Jr="null";function me(i){if(i===null)return Jr;if(typeof i=="string"||typeof i=="number")return i;if(typeof i=="boolean"||i===null)return`${i}`;if(i===void 0)return"undefined";if(Array.isArray(i))return i.map(me);throw new Error(`Unsupported index value: ${i}`)}var qi={version:0,collections:{}};function Rt(i,t,e){let n=typeof t=="function",r=n?qi:i,s=n?i:t,o=n?t:e,c=Object.keys(s.collections).filter(v=>r.collections[v]&&Ye(r.collections[v])!==Ye(s.collections[v])),f=Object.keys(r.collections).filter(v=>!s.collections[v]),h=Object.keys(s.collections).filter(v=>!r.collections[v]),x=new Set;for(let v of c){let C=r.collections[v].fields,S=s.collections[v].fields;Object.keys(S).some(O=>!C[O]?.default&&S[O]?.default)&&x.add(v),Object.keys(C).some(O=>!S[O])&&x.add(v)}let E={},g={};for(let v of[...c,...h]){let C=At(r.collections[v]),S=At(s.collections[v]),O=S.filter(y=>!C.find(I=>I.name===y.name)),A=C.filter(y=>!S.find(I=>I.name===y.name));O.length>0&&(E[v]=O,c.includes(v)&&x.add(v)),A.length>0&&(g[v]=A,c.includes(v)&&x.add(v))}let P=(v,C)=>ve(s.collections[v],C),b=v=>C=>{let S=s.collections[v];return ve(S,Un(S,C))};return{version:s.version,migrate:async v=>{let C=[];if(await o({migrate:async(S,O)=>{let A=b(S),y=async I=>{let d=await O(I);return K(d,le(I)),A(d)};await v.migrate(S,y),C.push(S),x.delete(S)},identity:S=>S,withDefaults:P,info:{changedCollections:c,addedCollections:h,removedCollections:f},queries:v.queries,mutations:v.mutations}),s.version>1){v.log("debug","auto-migrating collections with new defaults",x);for(let O of x)await v.migrate(O,b(O)),C.push(O);let S=c.filter(O=>!C.includes(O));S.length>0&&console.error(`Unmigrated changed collections from version ${r.version} to version ${s.version}:`,S)}},removedCollections:f,addedIndexes:E,removedIndexes:g,allCollections:Object.keys(s.collections),changedCollections:c,addedCollections:h,oldCollections:Object.keys(r.collections),oldSchema:r,newSchema:s}}function At(i){return i?[...Object.keys(i.indexes||{}).map(t=>({name:t,multiEntry:["array","string[]","number[]","boolean[]"].includes(i.indexes[t].type),synthetic:!0,compound:!1})),...Object.keys(i.compounds||{}).map(t=>({name:t,multiEntry:i.compounds[t].of.some(e=>(i.fields[e]||i.indexes[e]).type==="array"),synthetic:!1,compound:!0}))]:[]}function qn(i,t){return Rt(t?i:{version:0,collections:{}},t||i,async({migrate:n,info:r})=>{if((t||i).version!==1)for(let s of r.changedCollections)await n(s,o=>o)})}function Wn(i,t,e){let n=typeof t=="function"||t===void 0,r=n?qi:i,s=n?i:t,o=n?t:e;V(r,"Invalid arguments to createMigration"),V(s,"Invalid arguments to createMigration");let{changedCollections:c,addedCollections:f,removedCollections:h,addedIndexes:x,removedIndexes:E,autoMigratedCollections:g,autoMigration:P}=Yr(r,s);return{version:s.version,migrate:async b=>{let v=[];if(await o?.({migrate:async(S,O)=>{let A=P(S),y=async I=>{let d=await O(I);return K(d,le(I)),A(d)};await b.migrate(S,y),v.push(S),g.delete(S)},info:{changedCollections:c,addedCollections:f,removedCollections:h},queries:b.queries,mutations:b.mutations}),s.version>1){b.log("debug","auto-migrating collections with new defaults",g);for(let O of g)await b.migrate(O,P(O)),v.push(O);let S=c.filter(O=>!v.includes(O));S.length>0&&console.error(`Unmigrated changed collections from version ${r.version} to version ${s.version}:`,S)}},removedCollections:h,addedIndexes:x,removedIndexes:E,allCollections:Object.keys(s.collections),changedCollections:c,addedCollections:f,oldCollections:Object.keys(r.collections),oldSchema:r,newSchema:s}}function Yr(i,t){let e=Object.keys(t.collections).filter(x=>i.collections[x]&&Ye(i.collections[x])!==Ye(t.collections[x])),n=Object.keys(i.collections).filter(x=>!t.collections[x]),r=Object.keys(t.collections).filter(x=>!i.collections[x]),s=new Set;for(let x of e){let E=i.collections[x].fields,g=t.collections[x].fields;Object.keys(g).some(P=>!Nn(E[P])&&Nn(g[P]))&&s.add(x),Object.keys(E).some(P=>!g[P])&&s.add(x)}let o={},c={};for(let x of[...e,...r]){let E=At(i.collections[x]),g=At(t.collections[x]),P=g.filter(v=>!E.find(C=>C.name===v.name)),b=E.filter(v=>!g.find(C=>C.name===v.name));P.length>0&&(o[x]=P,e.includes(x)&&s.add(x)),b.length>0&&(c[x]=b,e.includes(x)&&s.add(x))}return{changedCollections:e,addedCollections:r,removedCollections:n,addedIndexes:o,removedIndexes:c,autoMigratedCollections:s,withDefaults:(x,E)=>ve(t.collections[x],E),autoMigration:x=>E=>{let g=t.collections[x];return ve(g,Un(g,E))}}}var kt=class{constructor(t,e){this.getNow=t;this.createSubId=e;this.createDiff=(t,e,n={})=>Ze(t,e,this.getNow,this.createSubId,[],n);this.createInitialize=(t,e)=>xe(t,e,this.getNow,this.createSubId);this.createSet=(t,e,n)=>{if(!z(n)||te(n))return[{oid:t,timestamp:this.getNow(),data:{op:"set",name:e,value:n}}];{let r=ge(t,this.createSubId);return[...xe(n,r,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"set",value:we(r),name:e}}]}};this.createRemove=(t,e)=>[{oid:t,timestamp:this.getNow(),data:{op:"remove",name:e}}];this.createListPush=(t,e)=>{if(z(e)){let n=ge(t,this.createSubId);return[...xe(e,n,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-push",value:we(n)}}]}else return[{oid:t,timestamp:this.getNow(),data:{op:"list-push",value:e}}]};this.createListAdd=(t,e)=>z(e)?[{oid:t,timestamp:this.getNow(),data:{op:"list-add",value:we(e)}}]:[{oid:t,timestamp:this.getNow(),data:{op:"list-add",value:e}}];this.createListInsert=(t,e,n)=>{if(z(n)){let r=ge(t,this.createSubId);return[...xe(n,r,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-insert",value:we(r),index:e}}]}else return[{oid:t,timestamp:this.getNow(),data:{op:"list-insert",value:n,index:e}}]};this.createListRemove=(t,e,n)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-remove",value:e,only:n}}];this.createListDelete=(t,e,n=1)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-delete",index:e,count:n}}];this.createListMoveByRef=(t,e,n)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-move-by-ref",value:e,index:n}}];this.createListMoveByIndex=(t,e,n)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-move-by-index",from:e,to:n}}];this.createDelete=t=>[{oid:t,timestamp:this.getNow(),data:{op:"delete"}}];this.createDeleteAll=t=>t.map(e=>({oid:e,timestamp:this.getNow(),data:{op:"delete"}}))}};var N=class{constructor(t){this._onAllUnsubscribed=t;this.subscribers={};this.counts={};this._disabled=!1;this.subscriberCount=t=>this.counts[t]??0;this.totalSubscriberCount=()=>Object.values(this.counts).reduce((t,e)=>t+e,0);this.subscribe=(t,e)=>{let n=St(),r=this.subscribers[t];return r||(r=this.subscribers[t]={}),r[n]=e,this.counts[t]=(this.counts[t]||0)+1,()=>{this.subscribers[t]&&(delete this.subscribers[t][n],this.counts[t]--,this.counts[t]===0&&(delete this.subscribers[t],delete this.counts[t],this._onAllUnsubscribed&&this._onAllUnsubscribed(t)))}};this.emit=(t,...e)=>{this._disabled||this.subscribers[t]&&Object.values(this.subscribers[t]).forEach(n=>n(...e))};this.dispose=()=>{let t=Object.keys(this.subscribers);this.subscribers={},this.counts={},t.forEach(e=>{this._onAllUnsubscribed&&this._onAllUnsubscribed(e)})};this.disable=()=>{this._disabled=!0}}get disabled(){return this._disabled}};function Wi(i,t,e,n){if(t===void 0)return[{oid:i,timestamp:n(),data:{op:"delete"}}];let r=oe(t),s=[];for(let o of e){let c=Gr(i,r,o,n);s.unshift(...c),Ee(r,o.data)}return s}function Gr(i,t,e,n){let r=e.data;switch(r.op){case"set":case"remove":return[{oid:i,timestamp:n(),data:{op:"set",name:r.name,value:t[r.name]}}];case"list-insert":return[{oid:i,timestamp:n(),data:{op:"list-delete",index:r.index,count:1}}];case"list-delete":return[{oid:i,timestamp:n(),data:{op:"list-insert",index:r.index,values:t.slice(r.index,r.count)}}];case"list-move-by-ref":return[{oid:i,timestamp:n(),data:{op:"list-move-by-ref",value:r.value,index:t.indexOf(r.value)}}];case"list-move-by-index":return[{oid:i,timestamp:n(),data:{op:"list-move-by-index",from:r.to,to:r.from}}];case"delete":return[{oid:i,timestamp:n(),data:{op:"initialize",value:t}}];case"list-push":return[{oid:i,timestamp:n(),data:{op:"list-remove",value:r.value,only:"last"}}];case"list-remove":if(r.only==="last"){let s=t.lastIndexOf(r.value);return[{oid:i,timestamp:n(),data:{op:"list-insert",index:s,values:[r.value]}}]}else if(r.only==="first"){let s=t.indexOf(r.value);return[{oid:i,timestamp:n(),data:{op:"list-insert",index:s,values:[r.value]}}]}else{let s=[],o=t.indexOf(r.value);for(;o!==-1;)s.push(o),o=t.indexOf(r.value,o+1);return s.map(c=>({oid:i,timestamp:n(),data:{op:"list-insert",index:c,value:r.value}}))}case"list-add":return[{oid:i,timestamp:n(),data:{op:"list-remove",value:r.value,only:"last"}}];case"initialize":return[{oid:i,timestamp:n(),data:{op:"delete"}}];default:throw new Error(`Cannot undo operation type: ${r.op}`)}}var Le=class{constructor(t){this.flusher=t;this.batches=new Map;this.flush=t=>{let e=this.batches.get(t);if(e)return e.flush()};this.discard=t=>{let e=this.batches.get(t);e&&(e.discard(),this.batches.delete(t))};this.flushAll=()=>[...this.batches.values()].map(t=>t.flush())}add({key:t,userData:e,items:n,max:r,timeout:s}){let o=this.batches.get(t);return o||(o=new Hn({max:r||null,startedAt:Date.now(),userData:e,timeout:s||null,flusher:this.flusher,key:t}),this.batches.set(t,o)),o.update({items:n,max:r,timeout:s,userData:e}),o}},Hn=class{constructor({max:t,startedAt:e,timeout:n,userData:r,flusher:s,key:o}){this.items=[];this.update=({items:t,max:e,timeout:n,userData:r})=>{this.items.push(...t),e!==void 0&&(this.max=e),n!==void 0&&(this.timeout=n),r&&(this.userData=r);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 t=this.items;return this.items=[],this.flusher(t,this.key,this.userData)};this.discard=()=>{this.flushTimeout&&clearTimeout(this.flushTimeout),this.flushTimeout=void 0,this.items=[]};this.max=t,this.startedAt=e,this.timeout=n,this.userData=r,this.flusher=s,this.key=o}};function W(i){return new Promise((t,e)=>{i.onsuccess=()=>{t(i.result)},i.onerror=()=>{e(i.error)}})}function et(i,t){return new Promise((e,n)=>{let r=i.transaction([t],"readonly"),o=r.objectStore(t).openCursor(),c=0,f=0;o.onsuccess=function(h){let x=o.result;x&&(c++,f=f+ki(x.value),x.continue())},o.onerror=function(h){n(h)},r.oncomplete=function(h){e({count:c,size:f})},r.onabort=function(h){n(h)},r.onerror=function(h){n(h)}})}function Hi(i,t){let e=i.transaction(t,"readonly"),n=t.map(r=>{let s=e.objectStore(r);return W(s.getAll())});return Promise.all(n)}async function Ae(i){i.close(),await new Promise((t,e)=>{t()})}async function Mt(i,t=window.indexedDB){let e=t.deleteDatabase([i,"meta"].join("_")),n=t.deleteDatabase([i,"collections"].join("_"));await Promise.all([new Promise((r,s)=>{e.onsuccess=r,e.onerror=s}),new Promise((r,s)=>{n.onsuccess=r,n.onerror=s})]),window.location.reload()}function Qi(i,t=window.indexedDB){return W(t.deleteDatabase(i))}async function Ji(i=window.indexedDB){return i.databases()}var pe=class{constructor(t){this.db=t;this.createTransaction=(t,e)=>this.db.transaction(t,e);this.run=async(t,e,n="readonly",r)=>{let o=(r||this.db.transaction(t,n)).objectStore(t),c=e(o);return W(c)};this.runAll=async(t,e,n="readonly",r)=>{let o=(r||this.db.transaction(t,n)).objectStore(t),c=e(o);return Promise.all(c.map(W))};this.iterate=async(t,e,n,r="readonly",s)=>{let c=(s||this.db.transaction(t,r)).objectStore(t),f=e(c);return Array.isArray(f)?Promise.all(f.map(h=>new Promise((x,E)=>{h.onsuccess=()=>{let g=h.result;g?(n(g.value,c),g.continue()):x()},h.onerror=E}))).then(()=>{}):new Promise((h,x)=>{f.onsuccess=()=>{let E=f.result;E?(n(E.value,c),E.continue()):h()},f.onerror=x})};this.clear=t=>this.run(t,e=>e.clear(),"readwrite")}};var Bt=class extends pe{constructor(){super(...arguments);this.getAckInfo=async()=>{let e=await this.run("info",n=>n.get("ack"));return e||{globalAckTimestamp:null,type:"ack"}};this.setGlobalAck=async e=>{await this.run("info",n=>n.put({type:"ack",globalAckTimestamp:e}),"readwrite")}}};var Ft=class extends pe{constructor(e){super(e);this.getAllForDocument=async(e,{mode:n="readonly",transaction:r}={})=>{let s=[];return await this.iterateOverAllForDocument(e,o=>{s.push(o)},{mode:n,transaction:r}),s};this.iterateOverAllForDocument=async(e,n,{mode:r="readonly",transaction:s}={})=>this.iterate("baselines",o=>{let c=U(e),[f,h]=kn(e),[x,E]=Mn(e);return[o.openCursor(IDBKeyRange.only(c)),o.openCursor(IDBKeyRange.bound(f,h,!1,!1)),o.openCursor(IDBKeyRange.bound(x,E,!1,!1))]},n,r,s);this.getAllForMultipleDocuments=async(e,{mode:n="readonly"}={})=>(await this.runAll("baselines",s=>e.flatMap(o=>{let c=U(o),[f,h]=kn(o),[x,E]=Mn(o);return[s.get(c),s.getAll(IDBKeyRange.bound(f,h,!1,!1)),s.getAll(IDBKeyRange.bound(x,E,!1,!1))]}),n)).flat();this.getAllSince=async(e,{mode:n="readonly"}={})=>this.run("baselines",r=>{let s=e?IDBKeyRange.lowerBound(e,!0):void 0;return r.index("timestamp").getAll(s)},n);this.get=async(e,{transaction:n,mode:r="readonly"}={})=>this.run("baselines",s=>s.get(e),r,n);this.set=async(e,{transaction:n}={})=>{await this.run("baselines",r=>r.put(e),"readwrite",n)};this.setAll=async(e,{transaction:n}={})=>{await this.runAll("baselines",r=>e.map(s=>r.put(s)),"readwrite",n)};this.reset=()=>this.clear("baselines");this.delete=async(e,{transaction:n})=>{await this.run("baselines",r=>r.delete(e),"readwrite",n)}}};var Yi=dt(ft(),1);var jt=class extends pe{constructor(){super(...arguments);this.get=async({transaction:e}={})=>{if(this.cached)return this.cached;let n=await this.run("info",r=>r.get("localReplicaInfo"),void 0,e);return n?(this.cached=n,n):(this._creating||(this._creating=(async()=>{let s={type:"localReplicaInfo",id:(0,Yi.default)(),ackedLogicalTime:null,lastSyncedLogicalTime:null};await this.run("info",o=>o.put(s),"readwrite"),this.cached=s})()),await this._creating,this.get({transaction:e}))};this.update=async(e,{transaction:n}={})=>{let r=await this.get({transaction:n});Object.assign(r,e),await this.run("info",s=>s.put(r),"readwrite"),this.cached=r};this.reset=async()=>{let e=await this.get();e.ackedLogicalTime=null,e.lastSyncedLogicalTime=null,await this.run("info",n=>n.put(e),"readwrite")}}};var Lt=class{constructor(t){this.meta=t;this.createOperation=async t=>{let e=await this.meta.localReplica.get();return{type:"op",timestamp:this.meta.now,replicaId:e.id,operations:t.operations.map(n=>({data:n.data,oid:n.oid,timestamp:n.timestamp}))}};this.createMigrationOperation=async({targetVersion:t,...e})=>{let n=await this.meta.localReplica.get();return{type:"op",operations:e.operations.map(r=>({...r,timestamp:this.meta.time.zero(t)})),timestamp:this.meta.time.zero(t),replicaId:n.id}};this.createSyncStep1=async t=>{let e=await this.meta.localReplica.get(),n=t===null?null:e.lastSyncedLogicalTime,r=[],s=new Set;n?await this.meta.operations.iterateOverAllLocalOperations(c=>{r.push({data:c.data,oid:c.oid,timestamp:c.timestamp}),s.add(U(c.oid))},{after:n,mode:"readwrite"}):await this.meta.operations.iterateOverAllOperations(c=>{r.push({data:c.data,oid:c.oid,timestamp:c.timestamp}),s.add(U(c.oid))},{mode:"readwrite"});let o=[];return n||(o=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:o,since:n}};this.createPresenceUpdate=async t=>{let e=await this.meta.localReplica.get();return{type:"presence-update",presence:t,replicaId:e.id}};this.createHeartbeat=async()=>{let t=await this.meta.localReplica.get();return{type:"heartbeat",timestamp:this.meta.now,replicaId:t.id}};this.createAck=async t=>{let e=await this.meta.localReplica.get();return{type:"ack",timestamp:this.meta.now,replicaId:e.id,nonce:t}}}};var Vt=class extends pe{constructor(){super(...arguments);this.iterateOverAllOperationsForDocument=async(e,n,{to:r,from:s,after:o,mode:c="readonly",transaction:f}={})=>{let x=(f||this.db.transaction("operations",c)).objectStore("operations"),E=x.index("d_t"),g=s||o,P=g?de(e,g):Te(e),b=r?de(e,r):_e(e),v=IDBKeyRange.bound(P,b,!!o,!1),C=E.openCursor(v,"next");return new Promise((S,O)=>{let A;C.onsuccess=y=>{let I=C.result;if(I){let d=I.value;V(d.oid.startsWith(e)),V(A===void 0||A<=d.timestamp,`expected ${A} <= ${d.timestamp}`),n(d,x),A=d.timestamp,I.continue()}else S()},C.onerror=y=>{O(y)}})};this.iterateOverAllOperationsForEntity=async(e,n,{after:r,to:s,mode:o,transaction:c})=>{let h=(c||this.db.transaction("operations",o)).objectStore("operations"),x=r?de(e,r):Te(e),E=s?de(e,s):_e(e),g=IDBKeyRange.bound(x,E,!!r,!1),P=h.openCursor(g,"next");return new Promise((b,v)=>{let C;P.onsuccess=S=>{let O=P.result;if(O){let A=O.value;V(A.oid.startsWith(e)),V(C===void 0||C<=A.timestamp,`expected ${C} <= ${A.timestamp}`),n(A,h),C=A.timestamp,O.continue()}else b()},P.onerror=S=>{v(S)}})};this.iterateOverAllLocalOperations=async(e,{before:n,after:r,mode:s="readonly",transaction:o})=>{let f=(o||this.db.transaction("operations",s)).objectStore("operations"),h=f.index("l_t"),x=r?de(!0,r):Te(!0),E=n?de(!0,n):_e(!0),g=IDBKeyRange.bound(x,E,!!r,!0),P=h.openCursor(g,"next");return new Promise((b,v)=>{let C;P.onsuccess=S=>{let O=P.result;if(O){let A=O.value;V(C===void 0||C<=A.timestamp,`expected ${C} <= ${A.timestamp}`),e(A,f),C=A.timestamp,O.continue()}else b()},P.onerror=S=>{v(S)}})};this.iterateOverAllOperations=async(e,{before:n,transaction:r,mode:s,from:o})=>{await this.iterate("operations",c=>{let f=o?Te(o):void 0,h=n?_e(n):void 0,x=f&&h?IDBKeyRange.bound(f,h,!1,!0):f?IDBKeyRange.lowerBound(f,!1):h?IDBKeyRange.upperBound(h,!0):void 0;return c.index("timestamp").openCursor(x,"next")},e,s,r)};this.addOperations=async(e,{transaction:n}={})=>this.insert(e.map(this.addCompoundIndexes),{transaction:n});this.addCompoundIndexes=e=>({...e,oid_timestamp:de(e.oid,e.timestamp),l_t:de(e.isLocal,e.timestamp),d_t:de(U(e.oid),e.timestamp)});this.insert=async(e,{transaction:n})=>{let r=new Set;return await this.runAll("operations",s=>e.map(o=>(r.add(U(o.oid)),s.put(o))),"readwrite",n),Array.from(r)};this.reset=()=>this.clear("operations")}};var Nt=class{constructor(t,e){this.db=t;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"),s=await W(r);return s?(this.cached=JSON.parse(s.schema),this.cached):null};this.set=async t=>{let s=this.db.transaction("info","readwrite").objectStore("info").put({type:"schema",schema:JSON.stringify(t)});this.cached=t,await W(s)}}};var tt=class extends N{constructor({disableRebasing:e,context:n}){super();this.time=new mt;this.disableRebasing=!1;this._closing=!1;this.setContext=e=>{this.context=e};this.close=()=>{this._closing=!0};this.createTransaction=e=>this.db.transaction(e,"readwrite");this.getAllDocumentRelatedOids=async e=>{let n=new Set,r=U(e);V(r===e,"Must be root document OID"),n.add(r);let s=this.db.transaction(["baselines","operations"],"readwrite");return await Promise.all([this.baselines.iterateOverAllForDocument(r,o=>{n.add(o.oid)},{transaction:s}),this.operations.iterateOverAllOperationsForDocument(r,o=>{n.add(o.oid)},{transaction:s})]),Array.from(n)};this.getDocumentSnapshot=async(e,n={})=>{let r=U(e);V(r===e,"Must be root document OID");let s=this.db.transaction(["baselines","operations"],"readwrite"),o=await this.baselines.getAllForDocument(r,{transaction:s}),c=new Map;for(let h of o)h.snapshot&&K(h.snapshot,h.oid),c.set(h.oid,h.snapshot);await this.operations.iterateOverAllOperationsForDocument(r,h=>{let x=c.get(h.oid)||void 0,E=Ee(x,h.data);E&&K(E,h.oid),c.set(h.oid,E)},{transaction:s,to:n.to||this.now});let f=c.get(r);return f&&Et(f,c),f};this.ack=async e=>{let n=await this.localReplica.get();e>this.now||(this.emit("message",{type:"ack",replicaId:n.id,timestamp:e}),!this._closing&&(!n.ackedLogicalTime||e>n.ackedLogicalTime)&&this.localReplica.update({ackedLogicalTime:e}))};this.insertLocalOperation=async e=>{if(e.length===0)return;this.log(`Inserting ${e.length} local operations`);for(let r of e)r.isLocal=!0;await this.operations.addOperations(e);let n=await this.messageCreator.createOperation({operations:e});this.emit("message",n),this.tryAutonomousRebase()};this.insertRemoteOperations=async e=>{if(e.length===0)return[];this.log(`Inserting ${e.length} remote operations`);let n=await this.operations.addOperations(e.map(r=>({...r,isLocal:!1})));return this.ack(e[e.length-1].timestamp),n};this.insertRemoteBaselines=async e=>{if(e.length===0)return[];this.log(`Inserting ${e.length} remote baselines`),await this.baselines.setAll(e);let n=new Set;return e.forEach(r=>{n.add(U(r.oid))}),Array.from(n)};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 n,r=new Set,s=this.db.transaction(["baselines","operations"],"readwrite"),o=0;if(await this.operations.iterateOverAllOperations(f=>{r.add(f.oid),n=f.timestamp,o++},{before:e,transaction:s}),!r.size){this.log("Cannot rebase, no operations prior to",e);return}if(this._closing)return;let c=[];for(let f of r)c.push(await this.rebase(f,n||e,s));this.emit("rebase",c)};this.rebase=async(e,n,r)=>{let s=(await this.localReplica.get()).id;this.log("[",s,"]","Rebasing",e,"up to",n);let o=r||this.db.transaction(["operations","baselines"],"readwrite"),c=await this.baselines.get(e,{transaction:o}),f=c?.snapshot||void 0,h=0,x=[];await this.operations.iterateOverAllOperationsForEntity(e,(g,P)=>{(!c||g.timestamp>c.timestamp)&&(f=Ee(f,g.data,x)),h++,P.delete(g.oid_timestamp)},{to:n,transaction:o}),f&&K(f,e);let E={oid:e,snapshot:f,timestamp:n};if(E.snapshot?await this.baselines.set(E,{transaction:o}):await this.baselines.delete(e,{transaction:o}),this.log("successfully rebased",e,"up to",n,":",f,"and deleted",h,"operations"),x.length){let g=x.filter(se);g.length&&this.emit("filesDeleted",g)}return E};this.reset=async()=>{await this.operations.reset(),await this.baselines.reset(),await this.localReplica.reset()};this.updateSchema=async(e,n)=>{let r=await this.schema.get();if(r&&n===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 A(l)},e.createHmac=A,e.randomBytes=function(l,w){if(!w||!w.call)return new g(v(l));try{w.call(this,void 0,new g(v(l)))}catch(D){w(D)}};var I,d=["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],p=function(l){e[l]=function(){y("sorry,",l,"is not implemented yet")}};for(I in d)p(d[I],I)}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){var g=i("./helpers");function P(y,I){y[I>>5]|=128<<I%32,y[14+(I+64>>>9<<4)]=I;for(var d=1732584193,p=-271733879,l=-1732584194,w=271733878,D=0;D<y.length;D+=16){var F=d,B=p,j=l,M=w,d=v(d,p,l,w,y[D+0],7,-680876936),w=v(w,d,p,l,y[D+1],12,-389564586),l=v(l,w,d,p,y[D+2],17,606105819),p=v(p,l,w,d,y[D+3],22,-1044525330);d=v(d,p,l,w,y[D+4],7,-176418897),w=v(w,d,p,l,y[D+5],12,1200080426),l=v(l,w,d,p,y[D+6],17,-1473231341),p=v(p,l,w,d,y[D+7],22,-45705983),d=v(d,p,l,w,y[D+8],7,1770035416),w=v(w,d,p,l,y[D+9],12,-1958414417),l=v(l,w,d,p,y[D+10],17,-42063),p=v(p,l,w,d,y[D+11],22,-1990404162),d=v(d,p,l,w,y[D+12],7,1804603682),w=v(w,d,p,l,y[D+13],12,-40341101),l=v(l,w,d,p,y[D+14],17,-1502002290),d=C(d,p=v(p,l,w,d,y[D+15],22,1236535329),l,w,y[D+1],5,-165796510),w=C(w,d,p,l,y[D+6],9,-1069501632),l=C(l,w,d,p,y[D+11],14,643717713),p=C(p,l,w,d,y[D+0],20,-373897302),d=C(d,p,l,w,y[D+5],5,-701558691),w=C(w,d,p,l,y[D+10],9,38016083),l=C(l,w,d,p,y[D+15],14,-660478335),p=C(p,l,w,d,y[D+4],20,-405537848),d=C(d,p,l,w,y[D+9],5,568446438),w=C(w,d,p,l,y[D+14],9,-1019803690),l=C(l,w,d,p,y[D+3],14,-187363961),p=C(p,l,w,d,y[D+8],20,1163531501),d=C(d,p,l,w,y[D+13],5,-1444681467),w=C(w,d,p,l,y[D+2],9,-51403784),l=C(l,w,d,p,y[D+7],14,1735328473),d=S(d,p=C(p,l,w,d,y[D+12],20,-1926607734),l,w,y[D+5],4,-378558),w=S(w,d,p,l,y[D+8],11,-2022574463),l=S(l,w,d,p,y[D+11],16,1839030562),p=S(p,l,w,d,y[D+14],23,-35309556),d=S(d,p,l,w,y[D+1],4,-1530992060),w=S(w,d,p,l,y[D+4],11,1272893353),l=S(l,w,d,p,y[D+7],16,-155497632),p=S(p,l,w,d,y[D+10],23,-1094730640),d=S(d,p,l,w,y[D+13],4,681279174),w=S(w,d,p,l,y[D+0],11,-358537222),l=S(l,w,d,p,y[D+3],16,-722521979),p=S(p,l,w,d,y[D+6],23,76029189),d=S(d,p,l,w,y[D+9],4,-640364487),w=S(w,d,p,l,y[D+12],11,-421815835),l=S(l,w,d,p,y[D+15],16,530742520),d=O(d,p=S(p,l,w,d,y[D+2],23,-995338651),l,w,y[D+0],6,-198630844),w=O(w,d,p,l,y[D+7],10,1126891415),l=O(l,w,d,p,y[D+14],15,-1416354905),p=O(p,l,w,d,y[D+5],21,-57434055),d=O(d,p,l,w,y[D+12],6,1700485571),w=O(w,d,p,l,y[D+3],10,-1894986606),l=O(l,w,d,p,y[D+10],15,-1051523),p=O(p,l,w,d,y[D+1],21,-2054922799),d=O(d,p,l,w,y[D+8],6,1873313359),w=O(w,d,p,l,y[D+15],10,-30611744),l=O(l,w,d,p,y[D+6],15,-1560198380),p=O(p,l,w,d,y[D+13],21,1309151649),d=O(d,p,l,w,y[D+4],6,-145523070),w=O(w,d,p,l,y[D+11],10,-1120210379),l=O(l,w,d,p,y[D+2],15,718787259),p=O(p,l,w,d,y[D+9],21,-343485551),d=A(d,F),p=A(p,B),l=A(l,j),w=A(w,M)}return Array(d,p,l,w)}function b(y,I,d,p,l,w){return A((I=A(A(I,y),A(p,w)))<<l|I>>>32-l,d)}function v(y,I,d,p,l,w,D){return b(I&d|~I&p,y,I,l,w,D)}function C(y,I,d,p,l,w,D){return b(I&p|d&~p,y,I,l,w,D)}function S(y,I,d,p,l,w,D){return b(I^d^p,y,I,l,w,D)}function O(y,I,d,p,l,w,D){return b(d^(I|~p),y,I,l,w,D)}function A(y,I){var d=(65535&y)+(65535&I);return(y>>16)+(I>>16)+(d>>16)<<16|65535&d}t.exports=function(y){return g.hash(y,P,16)}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){var g;t.exports=g||function(P){for(var b,v=new Array(P),C=0;C<P;C++)!(3&C)&&(b=4294967296*Math.random()),v[C]=b>>>((3&C)<<3)&255;return v}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){var g=i("./helpers");function P(C,S){C[S>>5]|=128<<24-S%32,C[15+(S+64>>9<<4)]=S;for(var O,A,y,I=Array(80),d=1732584193,p=-271733879,l=-1732584194,w=271733878,D=-1009589776,F=0;F<C.length;F+=16){for(var B=d,j=p,M=l,q=w,ee=D,H=0;H<80;H++){I[H]=H<16?C[F+H]:v(I[H-3]^I[H-8]^I[H-14]^I[H-16],1);var $=b(b(v(d,5),($=p,A=l,y=w,(O=H)<20?$&A|~$&y:!(O<40)&&O<60?$&A|$&y|A&y:$^A^y)),b(b(D,I[H]),(O=H)<20?1518500249:O<40?1859775393:O<60?-1894007588:-899497514)),D=w,w=l,l=v(p,30),p=d,d=$}d=b(d,B),p=b(p,j),l=b(l,M),w=b(w,q),D=b(D,ee)}return Array(d,p,l,w,D)}function b(C,S){var O=(65535&C)+(65535&S);return(C>>16)+(S>>16)+(O>>16)<<16|65535&O}function v(C,S){return C<<S|C>>>32-S}t.exports=function(C){return g.hash(C,P,20,!0)}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){function g(S,O){var A=(65535&S)+(65535&O);return(S>>16)+(O>>16)+(A>>16)<<16|65535&A}function P(S,O){var A,y=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),I=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),d=new Array(64);S[O>>5]|=128<<24-O%32,S[15+(O+64>>9<<4)]=O;for(var p,l,w=0;w<S.length;w+=16){for(var D=I[0],F=I[1],B=I[2],j=I[3],M=I[4],q=I[5],ee=I[6],H=I[7],$=0;$<64;$++)d[$]=$<16?S[$+w]:g(g(g((l=d[$-2],v(l,17)^v(l,19)^C(l,10)),d[$-7]),(l=d[$-15],v(l,7)^v(l,18)^C(l,3))),d[$-16]),A=g(g(g(g(H,v(l=M,6)^v(l,11)^v(l,25)),M&q^~M&ee),y[$]),d[$]),p=g(v(p=D,2)^v(p,13)^v(p,22),D&F^D&B^F&B),H=ee,ee=q,q=M,M=g(j,A),j=B,B=F,F=D,D=g(A,p);I[0]=g(D,I[0]),I[1]=g(F,I[1]),I[2]=g(B,I[2]),I[3]=g(j,I[3]),I[4]=g(M,I[4]),I[5]=g(q,I[5]),I[6]=g(ee,I[6]),I[7]=g(H,I[7])}return I}var b=i("./helpers"),v=function(S,O){return S>>>O|S<<32-O},C=function(S,O){return S>>>O};t.exports=function(S){return b.hash(S,P,32,!0)}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){e.read=function(g,P,b,v,w){var S,O,A=8*w-v-1,y=(1<<A)-1,I=y>>1,d=-7,p=b?w-1:0,l=b?-1:1,w=g[P+p];for(p+=l,S=w&(1<<-d)-1,w>>=-d,d+=A;0<d;S=256*S+g[P+p],p+=l,d-=8);for(O=S&(1<<-d)-1,S>>=-d,d+=v;0<d;O=256*O+g[P+p],p+=l,d-=8);if(S===0)S=1-I;else{if(S===y)return O?NaN:1/0*(w?-1:1);O+=Math.pow(2,v),S-=I}return(w?-1:1)*O*Math.pow(2,S-v)},e.write=function(g,P,b,v,C,D){var O,A,y=8*D-C-1,I=(1<<y)-1,d=I>>1,p=C===23?Math.pow(2,-24)-Math.pow(2,-77):0,l=v?0:D-1,w=v?1:-1,D=P<0||P===0&&1/P<0?1:0;for(P=Math.abs(P),isNaN(P)||P===1/0?(A=isNaN(P)?1:0,O=I):(O=Math.floor(Math.log(P)/Math.LN2),P*(v=Math.pow(2,-O))<1&&(O--,v*=2),2<=(P+=1<=O+d?p/v:p*Math.pow(2,1-d))*v&&(O++,v/=2),I<=O+d?(A=0,O=I):1<=O+d?(A=(P*v-1)*Math.pow(2,C),O+=d):(A=P*Math.pow(2,d-1)*Math.pow(2,C),O=0));8<=C;g[b+l]=255&A,l+=w,A/=256,C-=8);for(O=O<<C|A,y+=C;0<y;g[b+l]=255&O,l+=w,O/=256,y-=8);g[b+l-w]|=128*D}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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(i,t,e){(function(n,r,s,o,c,f,h,x,E){var g,P,b;function v(){}(n=t.exports={}).nextTick=(P=typeof window<"u"&&window.setImmediate,b=typeof window<"u"&&window.postMessage&&window.addEventListener,P?function(C){return window.setImmediate(C)}:b?(g=[],window.addEventListener("message",function(C){var S=C.source;S!==window&&S!==null||C.data!=="process-tick"||(C.stopPropagation(),0<g.length&&g.shift()())},!0),function(C){g.push(C),window.postMessage("process-tick","*")}):function(C){setTimeout(C,0)}),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.on=v,n.addListener=v,n.once=v,n.off=v,n.removeListener=v,n.removeAllListeners=v,n.emit=v,n.binding=function(C){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(C){throw new Error("process.chdir is not supported")}}).call(this,i("lYpoI2"),typeof self<"u"?self:typeof window<"u"?window:{},i("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 ni={};hr(ni,{Client:()=>Be,ClientDescriptor:()=>gn,Entity:()=>ye,EntityFile:()=>ke,MigrationPathError:()=>Ve,ServerSync:()=>Ke,Storage:()=>Be,StorageDescriptor:()=>gn,collection:()=>zi,createDefaultMigration:()=>qn,createMigration:()=>Wn,migrate:()=>Rt,schema:()=>$i});var Oi=dt(ft(),1),ht=4,Qe=36;function bi(i){return i.toString(Qe).padStart(ht,"0")}function xr(i){return i.toString().padStart(6,"0")}var mt=class{constructor(){this.latest={time:Date.now(),counter:0,node:Or()};this.zeroCounter=0;this.now=t=>(this.latest=vi(this.latest),this.get(t,this.latest));this.OLD_now=t=>(this.latest=vi(this.latest),xr(t)+Dr(this.latest));this.timerState=()=>this.latest;this.update=t=>{let e=t.slice(ht);this.latest=Ir(this.latest,Si(e))};this.get=(t,e)=>bi(t)+wi(e);this.zero=t=>bi(t)+wi({time:0,counter:this.zeroCounter++,node:this.latest.node});this.getWallClockTime=t=>Si(t.slice(ht)).time}},yt=class extends Error{constructor(...e){super();this.type="ClockDriftError",this.message=["maximum clock drift exceeded"].concat(e).join(" ")}},gt=class extends Error{constructor(){super();this.type="OverflowError",this.message="timestamp counter overflow"}},Dn=4,Cn=7,bt=60*1e3,He=9;function Or(){return Oi.default.slug().padStart(Cn,"0").slice(0,Cn)}function wi(i){let t=new Date(i.time).getTime().toString(Qe).padStart(He,"0"),e=i.counter.toString(Qe).padStart(Dn,"0"),n=i.node.padStart(Cn,"0");return`${t}${e}${n}`}function vi(i){let t=Date.now(),e=Math.max(i.time,t),n=i.time===e?i.counter+1:0;if(e-t>bt)throw new yt(e,t,bt);if(n>65535)throw new gt;return{time:e,counter:n,node:i.node}}function Ir(i,t){let e=Date.now(),n=Math.max(e,Math.max(i.time,t.time)),r=Math.max(i.counter,t.counter),s;if(i.time===n&&t.time===n?s=r+1:i.time===n?s=i.counter+1:t.time===n?s=t.counter+1:s=0,n-e>bt)throw new yt(n,e,bt);if(s>65535)throw new gt;return{time:n,counter:s,node:i.node}}function Si(i){let t=i.slice(0,He),e=i.slice(He,He+Dn),n=i.slice(He+Dn),r=parseInt(t,Qe),s=parseInt(e,Qe);if(isNaN(r)||isNaN(s))throw new Error("invalid clock format");return{time:r,counter:s,node:n}}function Dr(i){let t=new Date(i.time).toISOString(),e=i.counter.toString(16).toUpperCase().padStart(4,"0"),n=i.node.padStart(16,"0");return`${t}-${e}-${n}`}function xi(i){return parseInt(i.slice(0,ht),36)}function Ii(i,t){return xi(i)-xi(t)}function se(i){return i&&i["@@type"]==="file"}function Di(i){return{"@@type":"file",id:i}}var wt,Cr=new Uint8Array(16);function En(){if(!wt&&(wt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!wt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return wt(Cr)}var Ci=/^(?:[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 Er(i){return typeof i=="string"&&Ci.test(i)}var Ei=Er;var Z=[];for(vt=0;vt<256;++vt)Z.push((vt+256).toString(16).substr(1));var vt;function Pr(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(Z[i[t+0]]+Z[i[t+1]]+Z[i[t+2]]+Z[i[t+3]]+"-"+Z[i[t+4]]+Z[i[t+5]]+"-"+Z[i[t+6]]+Z[i[t+7]]+"-"+Z[i[t+8]]+Z[i[t+9]]+"-"+Z[i[t+10]]+Z[i[t+11]]+Z[i[t+12]]+Z[i[t+13]]+Z[i[t+14]]+Z[i[t+15]]).toLowerCase();if(!Ei(e))throw TypeError("Stringified UUID is invalid");return e}var Pi=Pr;function _r(i,t,e){i=i||{};var n=i.random||(i.rng||En)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){e=e||0;for(var r=0;r<16;++r)t[e+r]=n[r];return t}return Pi(n)}var Je=_r;function te(i){return ne(i)||se(i)}function Pn(i,t){return i===t?!0:!(!te(i)||!te(t)||i["@@type"]!==t["@@type"]||i.id!==t.id)}var Ri=dt(Ai(),1);function Tr(i,t){return typeof t!="object"||t===null||Array.isArray(t)?t:Object.fromEntries(Object.entries(t).sort(([e],[n])=>e<n?-1:e>n?1:0))}function Ye(i){return JSON.stringify(i,Tr)}function oe(i,t=!0){if(z(i)||Array.isArray(i)){let e=ce(i),n;if(Array.isArray(i))n=i.map(r=>oe(r,t));else{n={};for(let[r,s]of Object.entries(i))n[r]=oe(s,t)}return t&&e&&K(n,e),n}return i}function Se(i){return(0,Ri.default)(i)}function z(i){return i&&typeof i=="object"}function ki(i){for(var t=[],e=[i],n=0;e.length;){var r=e.pop();if(typeof r=="boolean")n+=4;else if(typeof r=="string")n+=r.length*2;else if(typeof r=="number")n+=8;else if(typeof r=="object"&&t.indexOf(r)===-1){t.push(r);for(var s in r)e.push(r[s])}}return n}function V(i,t="assertion failed"){if(!i)throw new Error(t)}function St(i=16){return Je().replace("-","").slice(0,i)}function Mi(i,t){for(let e=i.length-1;e>=0;e--)if(t(i[e]))return e;return-1}function Bi(i,t){let e;return function(...n){let r=this;clearTimeout(e),e=setTimeout(()=>i.apply(r,n),t)}}var Ie="__@@oid_do_not_use",De="@@id",Ar="/",It=":",Tn=new WeakMap;function le(i){let t=ce(i);return V(!!t,`Object ${JSON.stringify(i)} does not have an OID assigned to it`),t}function ce(i){if(z(i))return Tn.get(i)??i[De]??i[Ie]}function K(i,t){return V(z(i),`Only objects can be assigned OIDs, received ${JSON.stringify(i)}`),Xe(i)&&Dt(i),Tn.set(i,t),i}function Xe(i){return!!ce(i)}function Dt(i){return Tn.delete(i),i}function An(i){return i===De||i===Ie}function Rn(i,t,e){if(Xe(i))return le(i);{let n=ge(t,e);return K(i,n),n}}function Fi(i,t,e){if(Xe(i)){let n=le(i);if(Ct(n,t))return le(i);{let r=ge(t,e);return K(i,r),r}}else{let n=ge(t,e);return K(i,n),n}}var _n={".":"˙","/":"&slash;",":":":"};function ji(i){return i.replace(/[/]/g,_n["/"]).replace(/[:]/g,_n[":"]).replace(/[.]/g,_n["."])}function Li(i){return i.replace(/&slash;/g,"/").replace(/:/g,":").replace(/˙/g,".")}function X(i,t,e){let n=ji(i)+Ar+ji(t);return e&&(n+=It+e),n}function ge(i,t=Br){let{collection:e,id:n}=ae(i);return X(e,n,t())}function ae(i){let[t,e]=i.split(It),[n,r,...s]=t.split("/");s.length&&(r+="/"+s.join("/"));let o;return r.includes(".")?o=r.slice(0,r.indexOf(".")):o=r,{collection:Li(n),id:Li(o),subId:e}}function je(i,t){let e=le(i);if(Array.isArray(i)){let n;for(let r=0;r<i.length;r++)n=i[r],z(n)&&!te(n)&&(Fi(n,e,t),je(n,t))}else if(z(i)&&!te(i))for(let n of Object.keys(i))z(i[n])&&!te(i[n])&&(Fi(i[n],e,t),je(i[n],t))}function Rr(i){if(z(i))return i[De]||i[Ie]}function kr(i){return z(i)&&(delete i[Ie],delete i[De]),i}function Mr(i){let t=Rr(i);t&&K(i,t)}function Ge(i){if(Mr(i),kr(i),Array.isArray(i))for(let t=0;t<i.length;t++)Ge(i[t]);else if(z(i))for(let t of Object.keys(i))Ge(i[t])}function xt(i){if(Dt(i),Array.isArray(i))for(let t=0;t<i.length;t++)xt(i[t]);else if(z(i))for(let t of Object.keys(i))xt(i[t])}function Br(){return Je().slice(0,8)}function we(i){return{"@@type":"ref",id:i}}function Ot(i,t=new Map){if(Array.isArray(i)){let e=le(i),n=K([],e);for(let r=0;r<i.length;r++){let s=i[r];if(z(s)){if(ne(s))throw new Error("An attempt was made to normalize an already normalized object! This is an error in verdant itself.");if(se(s)){n[r]=s;continue}else{let o=le(s);n[r]=we(o),Ot(s,t)}}else n[r]=s}t.set(e,n)}else if(z(i)&&!te(i)){let e=le(i),n=K({},e);for(let r of Object.keys(i)){let s=i[r];if(z(s)){if(ne(s))throw new Error("An attempt was made to normalize an already normalized object! This is an error in verdant itself.");if(se(s))n[r]=s;else{let o=le(s);n[r]=we(o),Ot(s,t)}}else n[r]=s}t.set(e,n)}else te(i);return t}function U(i){return i.split(".")[0].split(It)[0]}function kn(i){let t=U(i),e=ge(t,()=>"\uFFFF");return[`${t}${It}`,e]}function Mn(i){let t=U(i);return[`${t}.`,`${t}.\uFFFF`]}function Ct(i,t){return U(i)===U(t)}function Fr(i){let{collection:t,id:e,subId:n}=ae(i);return X(t,e,n)}var jr=/"\w+\/[^"]+?(\.[^"]+)+\:[\S]+?"/g;function Lr(i){return i.replaceAll(jr,t=>{let e=t.slice(1,t.length-1);return`"${Fr(e)}"`})}function Bn(i){return JSON.parse(Lr(JSON.stringify(i)))}function ne(i){return i&&typeof i=="object"&&i["@@type"]==="ref"}function Fn(i){return z(i)&&!te(i)}function Vr(i,t){return i===t?!0:te(i)&&te(t)?Pn(i,t):!1}function Ze(i,t,e,n,r=[],s={}){let o=le(i);function c(f,h,x){if(!Fn(h))Vr(h,x)||r.push({oid:o,timestamp:e(),data:{op:"set",name:f,value:h}});else{let E=ce(x),g=ce(h);g&&!Ct(o,g)?(h=oe(h,!1),g=ge(o,n),K(h,g)):s.mergeUnknownObjects?!g&&E?(K(h,E),g=E):g=Rn(h,o,n):g=Rn(h,o,n),V(!!g,"Error: no value OID was resolved during diff. This is a bug in Verdant."),V(Ct(o,g),`Error: value OID ${g} is not related to parent OID ${o}. This is a bug in Verdant.`),x===void 0||g!==E?(xe(h,g,e,n,r),r.push({oid:o,timestamp:e(),data:{op:"set",name:f,value:we(g)}}),E!==void 0&&r.push({oid:E,timestamp:e(),data:{op:"delete"}})):Ze(x,h,e,n,r,s)}}if(Array.isArray(i)&&Array.isArray(t)){for(let h=0;h<t.length;h++){let x=t[h],E=i[h];c(h,x,E)}let f=i.length-t.length;if(f>0){for(let h=t.length;h<i.length;h++){let x=i[h],E=ce(x);E&&r.push({oid:E,timestamp:e(),data:{op:"delete"}})}r.push({oid:o,timestamp:e(),data:{op:"list-delete",index:t.length,count:f}})}}else{if(Array.isArray(i)||Array.isArray(t))throw new Error("Cannot diff an array with an object");if(Fn(i)&&Fn(t)){let f=new Set(Object.keys(i));for(let[h,x]of Object.entries(t)){if(x===void 0&&s.defaultUndefined||(f.delete(h),An(h)))continue;let E=i[h];c(h,x,E)}if(!s.defaultUndefined)for(let h of f)An(h)||r.push({oid:o,timestamp:e(),data:{op:"remove",name:h}})}}return r}function xe(i,t,e,n,r=[]){K(i,t),je(i,n);let s=Ot(i);for(let o of s.keys()){let c=s.get(o);r.push({oid:o,timestamp:e(),data:{op:"initialize",value:Dt(c)}})}return r}function Ni(i){let t={};for(let e of i)e.oid in t?t[e.oid].push(e):t[e.oid]=[e];return t}function jn(i){let t={};for(let e of i){let n=U(e.oid);n in t?t[n].push(e):t[n]=[e]}return t}function Ln(i){let t={};for(let e of i){let n=U(e.oid);n in t?t[n].push(e):t[n]=[e]}return t}function Ce(i){return Array.isArray(i)?!0:(console.error(`Cannot apply list patch; expected array, received ${JSON.stringify(i)}. This suggests your data is changing from a list to an object over time. (OID: ${ce(i)})`),!1)}function Ee(i,t,e){if(i==null&&t.op!=="initialize")return i;let n=i,r,s;function o(c){e&&te(c)&&e.push(c)}switch(t.op){case"set":o(n[t.name]),n[t.name]=t.value;break;case"remove":o(n[t.name]),delete n[t.name];break;case"list-push":Ce(i)&&i.push(t.value);break;case"list-delete":Ce(i)&&(o(i[t.index]),i.splice(t.index,t.count));break;case"list-move-by-index":Ce(i)&&(s=i.splice(t.from,1),i.splice(t.to,0,s[0]));break;case"list-remove":if(Ce(i))do{let c=t.value;t.only==="last"?ne(c)?r=Mi(i,f=>f.id===c.id):r=i.lastIndexOf(c):ne(c)?r=i.findIndex(f=>f.id===c.id):r=i.indexOf(c),r!==-1&&(o(i[r]),i.splice(r,1))}while(!t.only&&r!==-1);break;case"list-add":Ce(i)&&(i.some(f=>ne(f)&&ne(t.value)?f.id===t.value.id:f===t.value)||i.push(t.value));break;case"list-move-by-ref":Ce(i)&&(r=i.indexOf(t.value),s=i.splice(r,1),i.splice(t.index,0,s[0]));break;case"list-insert":if(Ce(i)){if(!t.value&&!t.values)throw new Error(`Cannot apply list insert patch; expected value or values, received ${JSON.stringify(t)}`);t.value?i.splice(t.index,0,t.value):i.splice(t.index,0,...t.values)}break;case"delete":Array.isArray(i)?i.forEach(o):z(i)&&Object.values(i||{}).forEach(o);return;case"initialize":return oe(t.value);default:throw new Error(`Unsupported patch operation: ${t.op}`)}return i}function Et(i,t,e=[]){if(Array.isArray(i))for(let n=0;n<i.length;n++){let r=i[n];i[n]=Vi(r,t,e),z(i[n])&&Et(i[n],t,e)}else if(!se(i)){if(z(i)){V(ce(i),`Object ${JSON.stringify(i)} must have an oid`);for(let n of Object.keys(i))i[n]=Vi(i[n],t,e),z(i[n])&&Et(i[n],t,e)}}return e}function Vi(i,t,e){if(ne(i)){e.push(i.id);let n=t.get(i.id);return V(!!n,`No value was found in object map for ${i.id}`),K(n,i.id)}else return i}function Nr(i){return i.type==="any"?!0:i.type==="map"?!1:i.nullable}function Nn(i){return i?i.type==="map"||i.type==="array"?!0:i.type==="file"?!1:i.type==="object"?!0:i.default!==void 0:!1}function Pt(i){return i.type==="map"||i.type==="object"||i.type==="array"||i.type==="file"||i.type==="any"?!1:i.indexed}function ve(i,t){for(let[e,n]of Object.entries(i.fields)){let r=Ui(n);(r!==void 0&&t[e]===void 0||!Nr(n)&&t[e]===null)&&(t[e]=r),t[e]&&Pe(t[e],n)}return t}function Pe(i,t){if(i==null)return i;if(t.type==="object")for(let[e,n]of Object.entries(t.properties)){if(i[e]===void 0){let r=Ui(n);r!==void 0&&(i[e]=r)}Pe(i[e],n)}else if(t.type==="array")for(let e of i)Pe(e,t.items);else if(t.type==="map")for(let[e,n]of Object.entries(i))e===De||e===Ie||Pe(n,t.values)}function Ui(i){if(i.type==="string"||i.type==="number"||i.type==="boolean"||i.type==="any"){if(i.default&&typeof i.default=="function")return i.default();if(i.default!==void 0)return JSON.parse(JSON.stringify(i.default))}if(i.type==="array")return[];if(i.type==="map")return{};if(i.type!=="any"&&i.nullable)return null}function Un(i,t){for(let[e,n]of Object.entries(t))e===De||e===Ie||(i.fields[e]?Vn(n,i.fields[e]):delete t[e]);return t}function Vn(i,t){if(z(i)&&t.type==="object")for(let[e,n]of Object.entries(i))t.properties[e]?Vn(n,t.properties[e]):delete i[e];else if(Array.isArray(i)&&t.type==="array")for(let e of i)Vn(e,t.items)}function Kn(i){return i.equals!==void 0}function zn(i){return i.gte!==void 0||i.lte!==void 0||i.gt!==void 0||i.lt!==void 0}function Ur(i){return!!i.match}function $n(i){return i.startsWith!==void 0}function Ki(i){return!zn(i)&&!Kn(i)&&!Ur(i)&&!$n(i)&&i.order}function zi({synthetics:i,indexes:t,...e}){let n={...i,...t};for(let[r,s]of Object.entries(e.fields))Pt(s)&&(n[r]={field:r});return{...e,indexes:n}}function $i(i){return i}var _t="\uFFFFFE",Kr="\0",zr="\uFFFFFF";function de(...i){let t=$r(i);return t.length===1?t[0]:t}function _e(...i){return i.join(_t)+`${zr}`}function Te(...i){return i.join(_t)+`${_t}${Kr}`}function $r(i){let t=[[]];for(let e of i)if(Array.isArray(e)){let n=[];for(let r of t)for(let s of e)n.push(r.concat(s));t=n}else for(let n of t)n.push(`${e}`);return Array.from(new Set(t.map(e=>e.join(_t))))}function qr(i){return!!i.field}function Wr(i,t){let e={};for(let[n,r]of Object.entries(i.indexes||{})){let s=r;qr(s)?e[n]=me(t[s.field]):e[n]=me(s.compute(t))}return e}function Hr(i,t){return Object.entries(i.compounds||{}).reduce((e,[n,r])=>(e[n]=de(...r.of.map(s=>t[s])),e),{})}function Qr(i,t){return Object.entries(i.fields).reduce((e,[n,r])=>(Pt(r)&&(e[n]=me(t[n])),e),{})}function Tt(i,t){return{[i.primaryKey]:t[i.primaryKey],...Qr(i,t),...Wr(i,t),...Hr(i,t),"@@@snapshot":t}}var Jr="null";function me(i){if(i===null)return Jr;if(typeof i=="string"||typeof i=="number")return i;if(typeof i=="boolean"||i===null)return`${i}`;if(i===void 0)return"undefined";if(Array.isArray(i))return i.map(me);throw new Error(`Unsupported index value: ${i}`)}var qi={version:0,collections:{}};function Rt(i,t,e){let n=typeof t=="function",r=n?qi:i,s=n?i:t,o=n?t:e,c=Object.keys(s.collections).filter(v=>r.collections[v]&&Ye(r.collections[v])!==Ye(s.collections[v])),f=Object.keys(r.collections).filter(v=>!s.collections[v]),h=Object.keys(s.collections).filter(v=>!r.collections[v]),x=new Set;for(let v of c){let C=r.collections[v].fields,S=s.collections[v].fields;Object.keys(S).some(O=>!C[O]?.default&&S[O]?.default)&&x.add(v),Object.keys(C).some(O=>!S[O])&&x.add(v)}let E={},g={};for(let v of[...c,...h]){let C=At(r.collections[v]),S=At(s.collections[v]),O=S.filter(y=>!C.find(I=>I.name===y.name)),A=C.filter(y=>!S.find(I=>I.name===y.name));O.length>0&&(E[v]=O,c.includes(v)&&x.add(v)),A.length>0&&(g[v]=A,c.includes(v)&&x.add(v))}let P=(v,C)=>ve(s.collections[v],C),b=v=>C=>{let S=s.collections[v];return ve(S,Un(S,C))};return{version:s.version,migrate:async v=>{let C=[];if(await o({migrate:async(S,O)=>{let A=b(S),y=async I=>{let d=await O(I);return K(d,le(I)),A(d)};await v.migrate(S,y),C.push(S),x.delete(S)},identity:S=>S,withDefaults:P,info:{changedCollections:c,addedCollections:h,removedCollections:f},queries:v.queries,mutations:v.mutations}),s.version>1){v.log("debug","auto-migrating collections with new defaults",x);for(let O of x)await v.migrate(O,b(O)),C.push(O);let S=c.filter(O=>!C.includes(O));S.length>0&&console.error(`Unmigrated changed collections from version ${r.version} to version ${s.version}:`,S)}},removedCollections:f,addedIndexes:E,removedIndexes:g,allCollections:Object.keys(s.collections),changedCollections:c,addedCollections:h,oldCollections:Object.keys(r.collections),oldSchema:r,newSchema:s}}function At(i){return i?[...Object.keys(i.indexes||{}).map(t=>({name:t,multiEntry:["array","string[]","number[]","boolean[]"].includes(i.indexes[t].type),synthetic:!0,compound:!1})),...Object.keys(i.compounds||{}).map(t=>({name:t,multiEntry:i.compounds[t].of.some(e=>(i.fields[e]||i.indexes[e]).type==="array"),synthetic:!1,compound:!0}))]:[]}function qn(i,t){return Rt(t?i:{version:0,collections:{}},t||i,async({migrate:n,info:r})=>{if((t||i).version!==1)for(let s of r.changedCollections)await n(s,o=>o)})}function Wn(i,t,e){let n=typeof t=="function"||t===void 0,r=n?qi:i,s=n?i:t,o=n?t:e;V(r,"Invalid arguments to createMigration"),V(s,"Invalid arguments to createMigration");let{changedCollections:c,addedCollections:f,removedCollections:h,addedIndexes:x,removedIndexes:E,autoMigratedCollections:g,autoMigration:P}=Yr(r,s);return{version:s.version,migrate:async b=>{let v=[];if(await o?.({migrate:async(S,O)=>{let A=P(S),y=async I=>{let d=await O(I);return K(d,le(I)),A(d)};await b.migrate(S,y),v.push(S),g.delete(S)},info:{changedCollections:c,addedCollections:f,removedCollections:h},queries:b.queries,mutations:b.mutations}),s.version>1){b.log("debug","auto-migrating collections with new defaults",g);for(let O of g)await b.migrate(O,P(O)),v.push(O);let S=c.filter(O=>!v.includes(O));S.length>0&&console.error(`Unmigrated changed collections from version ${r.version} to version ${s.version}:`,S)}},removedCollections:h,addedIndexes:x,removedIndexes:E,allCollections:Object.keys(s.collections),changedCollections:c,addedCollections:f,oldCollections:Object.keys(r.collections),oldSchema:r,newSchema:s}}function Yr(i,t){let e=Object.keys(t.collections).filter(x=>i.collections[x]&&Ye(i.collections[x])!==Ye(t.collections[x])),n=Object.keys(i.collections).filter(x=>!t.collections[x]),r=Object.keys(t.collections).filter(x=>!i.collections[x]),s=new Set;for(let x of e){let E=i.collections[x].fields,g=t.collections[x].fields;Object.keys(g).some(P=>!Nn(E[P])&&Nn(g[P]))&&s.add(x),Object.keys(E).some(P=>!g[P])&&s.add(x)}let o={},c={};for(let x of[...e,...r]){let E=At(i.collections[x]),g=At(t.collections[x]),P=g.filter(v=>!E.find(C=>C.name===v.name)),b=E.filter(v=>!g.find(C=>C.name===v.name));P.length>0&&(o[x]=P,e.includes(x)&&s.add(x)),b.length>0&&(c[x]=b,e.includes(x)&&s.add(x))}return{changedCollections:e,addedCollections:r,removedCollections:n,addedIndexes:o,removedIndexes:c,autoMigratedCollections:s,withDefaults:(x,E)=>ve(t.collections[x],E),autoMigration:x=>E=>{let g=t.collections[x];return ve(g,Un(g,E))}}}var kt=class{constructor(t,e){this.getNow=t;this.createSubId=e;this.createDiff=(t,e,n={})=>Ze(t,e,this.getNow,this.createSubId,[],n);this.createInitialize=(t,e)=>xe(t,e,this.getNow,this.createSubId);this.createSet=(t,e,n)=>{if(!z(n)||te(n))return[{oid:t,timestamp:this.getNow(),data:{op:"set",name:e,value:n}}];{let r=ge(t,this.createSubId);return[...xe(n,r,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"set",value:we(r),name:e}}]}};this.createRemove=(t,e)=>[{oid:t,timestamp:this.getNow(),data:{op:"remove",name:e}}];this.createListPush=(t,e)=>{if(z(e)){let n=ge(t,this.createSubId);return[...xe(e,n,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-push",value:we(n)}}]}else return[{oid:t,timestamp:this.getNow(),data:{op:"list-push",value:e}}]};this.createListAdd=(t,e)=>z(e)?[{oid:t,timestamp:this.getNow(),data:{op:"list-add",value:we(e)}}]:[{oid:t,timestamp:this.getNow(),data:{op:"list-add",value:e}}];this.createListInsert=(t,e,n)=>{if(z(n)){let r=ge(t,this.createSubId);return[...xe(n,r,this.getNow),{oid:t,timestamp:this.getNow(),data:{op:"list-insert",value:we(r),index:e}}]}else return[{oid:t,timestamp:this.getNow(),data:{op:"list-insert",value:n,index:e}}]};this.createListRemove=(t,e,n)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-remove",value:e,only:n}}];this.createListDelete=(t,e,n=1)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-delete",index:e,count:n}}];this.createListMoveByRef=(t,e,n)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-move-by-ref",value:e,index:n}}];this.createListMoveByIndex=(t,e,n)=>[{oid:t,timestamp:this.getNow(),data:{op:"list-move-by-index",from:e,to:n}}];this.createDelete=t=>[{oid:t,timestamp:this.getNow(),data:{op:"delete"}}];this.createDeleteAll=t=>t.map(e=>({oid:e,timestamp:this.getNow(),data:{op:"delete"}}))}};var N=class{constructor(t){this._onAllUnsubscribed=t;this.subscribers={};this.counts={};this._disabled=!1;this.subscriberCount=t=>this.counts[t]??0;this.totalSubscriberCount=()=>Object.values(this.counts).reduce((t,e)=>t+e,0);this.subscribe=(t,e)=>{let n=St(),r=this.subscribers[t];return r||(r=this.subscribers[t]={}),r[n]=e,this.counts[t]=(this.counts[t]||0)+1,()=>{this.subscribers[t]&&(delete this.subscribers[t][n],this.counts[t]--,this.counts[t]===0&&(delete this.subscribers[t],delete this.counts[t],this._onAllUnsubscribed&&this._onAllUnsubscribed(t)))}};this.emit=(t,...e)=>{this._disabled||this.subscribers[t]&&Object.values(this.subscribers[t]).forEach(n=>n(...e))};this.dispose=()=>{let t=Object.keys(this.subscribers);this.subscribers={},this.counts={},t.forEach(e=>{this._onAllUnsubscribed&&this._onAllUnsubscribed(e)})};this.disable=()=>{this._disabled=!0}}get disabled(){return this._disabled}};function Wi(i,t,e,n){if(t===void 0)return[{oid:i,timestamp:n(),data:{op:"delete"}}];let r=oe(t),s=[];for(let o of e){let c=Gr(i,r,o,n);s.unshift(...c),Ee(r,o.data)}return s}function Gr(i,t,e,n){let r=e.data;switch(r.op){case"set":case"remove":return[{oid:i,timestamp:n(),data:{op:"set",name:r.name,value:t[r.name]}}];case"list-insert":return[{oid:i,timestamp:n(),data:{op:"list-delete",index:r.index,count:1}}];case"list-delete":return[{oid:i,timestamp:n(),data:{op:"list-insert",index:r.index,values:t.slice(r.index,r.count)}}];case"list-move-by-ref":return[{oid:i,timestamp:n(),data:{op:"list-move-by-ref",value:r.value,index:t.indexOf(r.value)}}];case"list-move-by-index":return[{oid:i,timestamp:n(),data:{op:"list-move-by-index",from:r.to,to:r.from}}];case"delete":return[{oid:i,timestamp:n(),data:{op:"initialize",value:t}}];case"list-push":return[{oid:i,timestamp:n(),data:{op:"list-remove",value:r.value,only:"last"}}];case"list-remove":if(r.only==="last"){let s=t.lastIndexOf(r.value);return[{oid:i,timestamp:n(),data:{op:"list-insert",index:s,values:[r.value]}}]}else if(r.only==="first"){let s=t.indexOf(r.value);return[{oid:i,timestamp:n(),data:{op:"list-insert",index:s,values:[r.value]}}]}else{let s=[],o=t.indexOf(r.value);for(;o!==-1;)s.push(o),o=t.indexOf(r.value,o+1);return s.map(c=>({oid:i,timestamp:n(),data:{op:"list-insert",index:c,value:r.value}}))}case"list-add":return[{oid:i,timestamp:n(),data:{op:"list-remove",value:r.value,only:"last"}}];case"initialize":return[{oid:i,timestamp:n(),data:{op:"delete"}}];default:throw new Error(`Cannot undo operation type: ${r.op}`)}}var Le=class{constructor(t){this.flusher=t;this.batches=new Map;this.flush=t=>{let e=this.batches.get(t);if(e)return e.flush()};this.discard=t=>{let e=this.batches.get(t);e&&(e.discard(),this.batches.delete(t))};this.flushAll=()=>[...this.batches.values()].map(t=>t.flush())}add({key:t,userData:e,items:n,max:r,timeout:s}){let o=this.batches.get(t);return o||(o=new Hn({max:r||null,startedAt:Date.now(),userData:e,timeout:s||null,flusher:this.flusher,key:t}),this.batches.set(t,o)),o.update({items:n,max:r,timeout:s,userData:e}),o}},Hn=class{constructor({max:t,startedAt:e,timeout:n,userData:r,flusher:s,key:o}){this.items=[];this.update=({items:t,max:e,timeout:n,userData:r})=>{this.items.push(...t),e!==void 0&&(this.max=e),n!==void 0&&(this.timeout=n),r&&(this.userData=r);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 t=this.items;return this.items=[],this.flusher(t,this.key,this.userData)};this.discard=()=>{this.flushTimeout&&clearTimeout(this.flushTimeout),this.flushTimeout=void 0,this.items=[]};this.max=t,this.startedAt=e,this.timeout=n,this.userData=r,this.flusher=s,this.key=o}};function W(i){return new Promise((t,e)=>{i.onsuccess=()=>{t(i.result)},i.onerror=()=>{e(i.error)}})}function et(i,t){return new Promise((e,n)=>{let r=i.transaction([t],"readonly"),o=r.objectStore(t).openCursor(),c=0,f=0;o.onsuccess=function(h){let x=o.result;x&&(c++,f=f+ki(x.value),x.continue())},o.onerror=function(h){n(h)},r.oncomplete=function(h){e({count:c,size:f})},r.onabort=function(h){n(h)},r.onerror=function(h){n(h)}})}function Hi(i,t){let e=i.transaction(t,"readonly"),n=t.map(r=>{let s=e.objectStore(r);return W(s.getAll())});return Promise.all(n)}async function Ae(i){i.close(),await new Promise((t,e)=>{t()})}async function Mt(i,t=window.indexedDB){let e=t.deleteDatabase([i,"meta"].join("_")),n=t.deleteDatabase([i,"collections"].join("_"));await Promise.all([new Promise((r,s)=>{e.onsuccess=r,e.onerror=s}),new Promise((r,s)=>{n.onsuccess=r,n.onerror=s})]),window.location.reload()}function Qi(i,t=window.indexedDB){return W(t.deleteDatabase(i))}async function Ji(i=window.indexedDB){return i.databases()}var pe=class{constructor(t){this.db=t;this.createTransaction=(t,e)=>this.db.transaction(t,e);this.run=async(t,e,n="readonly",r)=>{let o=(r||this.db.transaction(t,n)).objectStore(t),c=e(o);return W(c)};this.runAll=async(t,e,n="readonly",r)=>{let o=(r||this.db.transaction(t,n)).objectStore(t),c=e(o);return Promise.all(c.map(W))};this.iterate=async(t,e,n,r="readonly",s)=>{let c=(s||this.db.transaction(t,r)).objectStore(t),f=e(c);return Array.isArray(f)?Promise.all(f.map(h=>new Promise((x,E)=>{h.onsuccess=()=>{let g=h.result;g?(n(g.value,c),g.continue()):x()},h.onerror=E}))).then(()=>{}):new Promise((h,x)=>{f.onsuccess=()=>{let E=f.result;E?(n(E.value,c),E.continue()):h()},f.onerror=x})};this.clear=t=>this.run(t,e=>e.clear(),"readwrite")}};var Bt=class extends pe{constructor(){super(...arguments);this.getAckInfo=async()=>{let e=await this.run("info",n=>n.get("ack"));return e||{globalAckTimestamp:null,type:"ack"}};this.setGlobalAck=async e=>{await this.run("info",n=>n.put({type:"ack",globalAckTimestamp:e}),"readwrite")}}};var Ft=class extends pe{constructor(e){super(e);this.getAllForDocument=async(e,{mode:n="readonly",transaction:r}={})=>{let s=[];return await this.iterateOverAllForDocument(e,o=>{s.push(o)},{mode:n,transaction:r}),s};this.iterateOverAllForDocument=async(e,n,{mode:r="readonly",transaction:s}={})=>this.iterate("baselines",o=>{let c=U(e),[f,h]=kn(e),[x,E]=Mn(e);return[o.openCursor(IDBKeyRange.only(c)),o.openCursor(IDBKeyRange.bound(f,h,!1,!1)),o.openCursor(IDBKeyRange.bound(x,E,!1,!1))]},n,r,s);this.getAllForMultipleDocuments=async(e,{mode:n="readonly"}={})=>(await this.runAll("baselines",s=>e.flatMap(o=>{let c=U(o),[f,h]=kn(o),[x,E]=Mn(o);return[s.get(c),s.getAll(IDBKeyRange.bound(f,h,!1,!1)),s.getAll(IDBKeyRange.bound(x,E,!1,!1))]}),n)).flat();this.getAllSince=async(e,{mode:n="readonly"}={})=>this.run("baselines",r=>{let s=e?IDBKeyRange.lowerBound(e,!0):void 0;return r.index("timestamp").getAll(s)},n);this.get=async(e,{transaction:n,mode:r="readonly"}={})=>this.run("baselines",s=>s.get(e),r,n);this.set=async(e,{transaction:n}={})=>{await this.run("baselines",r=>r.put(e),"readwrite",n)};this.setAll=async(e,{transaction:n}={})=>{await this.runAll("baselines",r=>e.map(s=>r.put(s)),"readwrite",n)};this.reset=()=>this.clear("baselines");this.delete=async(e,{transaction:n})=>{await this.run("baselines",r=>r.delete(e),"readwrite",n)}}};var Yi=dt(ft(),1);var jt=class extends pe{constructor(){super(...arguments);this.get=async({transaction:e}={})=>{if(this.cached)return this.cached;let n=await this.run("info",r=>r.get("localReplicaInfo"),void 0,e);return n?(this.cached=n,n):(this._creating||(this._creating=(async()=>{let s={type:"localReplicaInfo",id:(0,Yi.default)(),ackedLogicalTime:null,lastSyncedLogicalTime:null};await this.run("info",o=>o.put(s),"readwrite"),this.cached=s})()),await this._creating,this.get({transaction:e}))};this.update=async(e,{transaction:n}={})=>{let r=await this.get({transaction:n});Object.assign(r,e),await this.run("info",s=>s.put(r),"readwrite"),this.cached=r};this.reset=async()=>{let e=await this.get();e.ackedLogicalTime=null,e.lastSyncedLogicalTime=null,await this.run("info",n=>n.put(e),"readwrite")}}};var Lt=class{constructor(t){this.meta=t;this.createOperation=async t=>{let e=await this.meta.localReplica.get();return{type:"op",timestamp:this.meta.now,replicaId:e.id,operations:t.operations.map(n=>({data:n.data,oid:n.oid,timestamp:n.timestamp}))}};this.createMigrationOperation=async({targetVersion:t,...e})=>{let n=await this.meta.localReplica.get();return{type:"op",operations:e.operations.map(r=>({...r,timestamp:this.meta.time.zero(t)})),timestamp:this.meta.time.zero(t),replicaId:n.id}};this.createSyncStep1=async t=>{let e=await this.meta.localReplica.get(),n=t===null?null:e.lastSyncedLogicalTime,r=[],s=new Set;n?await this.meta.operations.iterateOverAllLocalOperations(c=>{r.push({data:c.data,oid:c.oid,timestamp:c.timestamp}),s.add(U(c.oid))},{after:n,mode:"readwrite"}):await this.meta.operations.iterateOverAllOperations(c=>{r.push({data:c.data,oid:c.oid,timestamp:c.timestamp}),s.add(U(c.oid))},{mode:"readwrite"});let o=[];return n||(o=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:o,since:n}};this.createPresenceUpdate=async t=>{let e=await this.meta.localReplica.get();return{type:"presence-update",presence:t,replicaId:e.id}};this.createHeartbeat=async()=>{let t=await this.meta.localReplica.get();return{type:"heartbeat",timestamp:this.meta.now,replicaId:t.id}};this.createAck=async t=>{let e=await this.meta.localReplica.get();return{type:"ack",timestamp:this.meta.now,replicaId:e.id,nonce:t}}}};var Vt=class extends pe{constructor(){super(...arguments);this.iterateOverAllOperationsForDocument=async(e,n,{to:r,from:s,after:o,mode:c="readonly",transaction:f}={})=>{let x=(f||this.db.transaction("operations",c)).objectStore("operations"),E=x.index("d_t"),g=s||o,P=g?de(e,g):Te(e),b=r?de(e,r):_e(e),v=IDBKeyRange.bound(P,b,!!o,!1),C=E.openCursor(v,"next");return new Promise((S,O)=>{let A;C.onsuccess=y=>{let I=C.result;if(I){let d=I.value;V(d.oid.startsWith(e)),V(A===void 0||A<=d.timestamp,`expected ${A} <= ${d.timestamp}`),n(d,x),A=d.timestamp,I.continue()}else S()},C.onerror=y=>{O(y)}})};this.iterateOverAllOperationsForEntity=async(e,n,{after:r,to:s,mode:o,transaction:c})=>{let h=(c||this.db.transaction("operations",o)).objectStore("operations"),x=r?de(e,r):Te(e),E=s?de(e,s):_e(e),g=IDBKeyRange.bound(x,E,!!r,!1),P=h.openCursor(g,"next");return new Promise((b,v)=>{let C;P.onsuccess=S=>{let O=P.result;if(O){let A=O.value;V(A.oid.startsWith(e)),V(C===void 0||C<=A.timestamp,`expected ${C} <= ${A.timestamp}`),n(A,h),C=A.timestamp,O.continue()}else b()},P.onerror=S=>{v(S)}})};this.iterateOverAllLocalOperations=async(e,{before:n,after:r,mode:s="readonly",transaction:o})=>{let f=(o||this.db.transaction("operations",s)).objectStore("operations"),h=f.index("l_t"),x=r?de(!0,r):Te(!0),E=n?de(!0,n):_e(!0),g=IDBKeyRange.bound(x,E,!!r,!0),P=h.openCursor(g,"next");return new Promise((b,v)=>{let C;P.onsuccess=S=>{let O=P.result;if(O){let A=O.value;V(C===void 0||C<=A.timestamp,`expected ${C} <= ${A.timestamp}`),e(A,f),C=A.timestamp,O.continue()}else b()},P.onerror=S=>{v(S)}})};this.iterateOverAllOperations=async(e,{before:n,transaction:r,mode:s,from:o})=>{await this.iterate("operations",c=>{let f=o?Te(o):void 0,h=n?_e(n):void 0,x=f&&h?IDBKeyRange.bound(f,h,!1,!0):f?IDBKeyRange.lowerBound(f,!1):h?IDBKeyRange.upperBound(h,!0):void 0;return c.index("timestamp").openCursor(x,"next")},e,s,r)};this.addOperations=async(e,{transaction:n}={})=>this.insert(e.map(this.addCompoundIndexes),{transaction:n});this.addCompoundIndexes=e=>({...e,oid_timestamp:de(e.oid,e.timestamp),l_t:de(e.isLocal,e.timestamp),d_t:de(U(e.oid),e.timestamp)});this.insert=async(e,{transaction:n})=>{let r=new Set;return await this.runAll("operations",s=>e.map(o=>(r.add(U(o.oid)),s.put(o))),"readwrite",n),Array.from(r)};this.reset=()=>this.clear("operations")}};var Nt=class{constructor(t,e){this.db=t;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"),s=await W(r);return s?(this.cached=JSON.parse(s.schema),this.cached):null};this.set=async t=>{let s=this.db.transaction("info","readwrite").objectStore("info").put({type:"schema",schema:JSON.stringify(t)});this.cached=t,await W(s)}}};var tt=class extends N{constructor({disableRebasing:e,context:n}){super();this.time=new mt;this.disableRebasing=!1;this._closing=!1;this.setContext=e=>{this.context=e};this.close=()=>{this._closing=!0};this.createTransaction=e=>this.db.transaction(e,"readwrite");this.getAllDocumentRelatedOids=async e=>{let n=new Set,r=U(e);V(r===e,"Must be root document OID"),n.add(r);let s=this.db.transaction(["baselines","operations"],"readwrite");return await Promise.all([this.baselines.iterateOverAllForDocument(r,o=>{n.add(o.oid)},{transaction:s}),this.operations.iterateOverAllOperationsForDocument(r,o=>{n.add(o.oid)},{transaction:s})]),Array.from(n)};this.getDocumentSnapshot=async(e,n={})=>{let r=U(e);V(r===e,"Must be root document OID");let s=this.db.transaction(["baselines","operations"],"readwrite"),o=await this.baselines.getAllForDocument(r,{transaction:s}),c=new Map;for(let h of o)h.snapshot&&K(h.snapshot,h.oid),c.set(h.oid,h.snapshot);await this.operations.iterateOverAllOperationsForDocument(r,h=>{let x=c.get(h.oid)||void 0,E=Ee(x,h.data);E&&K(E,h.oid),c.set(h.oid,E)},{transaction:s,to:n.to||this.now});let f=c.get(r);return f&&Et(f,c),f};this.ack=async e=>{let n=await this.localReplica.get();e>this.now||(this.emit("message",{type:"ack",replicaId:n.id,timestamp:e}),!this._closing&&(!n.ackedLogicalTime||e>n.ackedLogicalTime)&&this.localReplica.update({ackedLogicalTime:e}))};this.insertLocalOperation=async e=>{if(e.length===0)return;this.log(`Inserting ${e.length} local operations`);for(let r of e)r.isLocal=!0;await this.operations.addOperations(e);let n=await this.messageCreator.createOperation({operations:e});this.emit("message",n),this.tryAutonomousRebase()};this.insertRemoteOperations=async e=>{if(e.length===0)return[];this.log(`Inserting ${e.length} remote operations`);let n=await this.operations.addOperations(e.map(r=>({...r,isLocal:!1})));return this.ack(e[e.length-1].timestamp),n};this.insertRemoteBaselines=async e=>{if(e.length===0)return[];this.log(`Inserting ${e.length} remote baselines`),await this.baselines.setAll(e);let n=new Set;return e.forEach(r=>{n.add(U(r.oid))}),Array.from(n)};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 n,r=new Set,s=this.db.transaction(["baselines","operations"],"readwrite"),o=0;if(await this.operations.iterateOverAllOperations(f=>{r.add(f.oid),n=f.timestamp,o++},{before:e,transaction:s}),!r.size){this.log("Cannot rebase, no operations prior to",e);return}if(this._closing)return;let c=[];for(let f of r)c.push(await this.rebase(f,n||e,s));this.emit("rebase",c)};this.rebase=async(e,n,r)=>{let s=(await this.localReplica.get()).id;this.log("[",s,"]","Rebasing",e,"up to",n);let o=r||this.db.transaction(["operations","baselines"],"readwrite"),c=await this.baselines.get(e,{transaction:o}),f=c?.snapshot||void 0,h=0,x=[];await this.operations.iterateOverAllOperationsForEntity(e,(g,P)=>{(!c||g.timestamp>c.timestamp)&&(f=Ee(f,g.data,x)),h++,P.delete(g.oid_timestamp)},{to:n,transaction:o}),f&&K(f,e);let E={oid:e,snapshot:f,timestamp:n};if(E.snapshot?await this.baselines.set(E,{transaction:o}):await this.baselines.delete(e,{transaction:o}),this.log("successfully rebased",e,"up to",n,":",f,"and deleted",h,"operations"),x.length){let g=x.filter(se);g.length&&this.emit("filesDeleted",g)}return E};this.reset=async()=>{await this.operations.reset(),await this.baselines.reset(),await this.localReplica.reset()};this.updateSchema=async(e,n)=>{let r=await this.schema.get();if(r&&n===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.export=async()=>{let e=this.db,[n,r]=await Hi(e,["baselines","operations"]),s=await this.localReplica.get(),o=await this.schema.get();if(!o)throw new Error("Cannot export Client data before initializing");return{operations:r,baselines:n,localReplica:s,schema:o}};this.resetFrom=async e=>{let r=this.db.transaction(["baselines","operations","info"],"readwrite");await W(r.objectStore("baselines").clear()),await W(r.objectStore("operations").clear()),await W(r.objectStore("info").clear()),await this.localReplica.update({ackedLogicalTime:e.localReplica.ackedLogicalTime,lastSyncedLogicalTime:e.localReplica.lastSyncedLogicalTime},{transaction:r})};this.stats=async()=>{let e=this.db,n=await et(e,"operations"),r=await et(e,"baselines");return{operationsSize:n,baselinesSize:r}};this.context=n,this.schema=new Nt(n.metaDb,n.schema.version),this.operations=new Vt(this.db),this.baselines=new Ft(this.db),this.localReplica=new jt(this.db),this.ackInfo=new Bt(this.db),this.messageCreator=new Lt(this),this.patchCreator=new kt(()=>this.now),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)}};var Xr=[Zr,es,ts,ns,is];function Ut({indexedDB:i=window.indexedDB,namespace:t,log:e,metadataVersion:n=5}){return new Promise((r,s)=>{let o=i.open(`${t}_meta`,n),c=!1;o.onupgradeneeded=async f=>{let h=o.result,x=o.transaction,E=Xr.slice(f.oldVersion);for(let g of E)await g(h,x);await new Promise((g,P)=>{x.addEventListener("complete",g),x.addEventListener("error",P)}),f.oldVersion||(c=!0)},o.onerror=()=>{console.error("Error opening database",o.error),s(o.error)},o.onsuccess=()=>{r({db:o.result,wasInitialized:c})}})}async function Gi({wipNamespace:i,namespace:t,indexedDB:e,log:n,metadataVersion:r}){let s=await Ut({namespace:i,indexedDB:e,log:n,metadataVersion:r});if(!s.wasInitialized)return s;n?.("debug","Beginning copy of production metadata database to WIP");let{db:o}=await Ut({namespace:t,indexedDB:e,log:n,metadataVersion:r}),c=o.transaction(["baselines","operations","info"],"readonly"),[f,h,x]=await Promise.all([W(c.objectStore("baselines").getAll()),W(c.objectStore("operations").getAll()),W(c.objectStore("info").getAll())]),E=s.db.transaction(["baselines","operations","info"],"readwrite"),g=E.objectStore("baselines"),P=E.objectStore("operations"),b=E.objectStore("info");for(let v of f)g.put(v);for(let v of h)P.put(v);for(let v of x)b.put(v);return await new Promise((v,C)=>{E.oncomplete=()=>{v()},E.onerror=S=>{C(S)},E.onabort=S=>{C(S)}}),await Ae(o),n?.("debug","Finished copy of production metadata database to WIP. Copied:",f.length,"baselines,",h.length,"operations"),s}async function Zr(i,t){let e=i.createObjectStore("baselines",{keyPath:"oid"}),n=i.createObjectStore("operations",{keyPath:"oid_timestamp"}),r=i.createObjectStore("info",{keyPath:"type"});e.createIndex("timestamp","timestamp"),n.createIndex("isLocal_timestamp","isLocal_timestamp"),n.createIndex("documentOid_timestamp","documentOid_timestamp")}async function es(i,t){let e=t.objectStore("operations");await new Promise((n,r)=>{let s=e.openCursor();s.onsuccess=()=>{let o=s.result;if(o){let{isLocal_timestamp:c,documentOid_timestamp:f,...h}=o.value;o.update({...h,l_t:c,d_t:f}),o.continue()}else n()},s.onerror=o=>{r(s.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 ts(i,t){t.objectStore("operations").createIndex("timestamp","timestamp")}async function ns(i,t){let e=i.createObjectStore("files",{keyPath:"id"});e.createIndex("remote","remote"),e.createIndex("deletedAt","deletedAt")}async function is(i,t){let e=t.objectStore("operations");await new Promise((r,s)=>{let o=e.openCursor();o.onsuccess=()=>{let c=o.result;if(c){let f=Bn(c.value);f.oid_timestamp!==c.primaryKey?(c.delete(),e.put(f)):c.update(f),c.continue()}else r()},o.onerror=c=>{s(o.error)}});let n=t.objectStore("baselines");await new Promise((r,s)=>{let o=n.openCursor();o.onsuccess=()=>{let c=o.result;if(c){let f=Bn(c.value);f.oid!==c.primaryKey?(c.delete(),n.put(f)):c.update(f),c.continue()}else r()},o.onerror=c=>{s(o.error)}})}var rs=i=>IDBKeyRange.only(me(i.equals)),ss=i=>{},os=i=>{let t=i.gte||i.gt,e=i.lte||i.lt;return t===e?IDBKeyRange.only(me(t)):t?e?IDBKeyRange.bound(me(t),me(e),!!i.gt,!!i.lt):IDBKeyRange.lowerBound(me(t),!!i.gt):IDBKeyRange.upperBound(me(e),!!i.lt)},as=(i,t,e)=>{let n=i.collections[t].compounds[e.where];V(n,`Index ${e.where} does not exist on collection ${t}`);let r=Object.keys(e.match).sort((f,h)=>n.of.indexOf(f)-n.of.indexOf(h));for(let f of r)if(n.of.indexOf(f)!==r.indexOf(f))throw new Error(`Compound index ${e.where} does not have ${f} at the start of its order`);let s=r.map(f=>e.match[f]);if(r.length===n.of.length)return IDBKeyRange.only(de(...s));let o=Te(...s),c=_e(...s);return IDBKeyRange.bound(o,c)};function cs(i){let t=i.startsWith,e=i.startsWith+"\uFFFF";return IDBKeyRange.bound(t,e)}function Kt(i,t,e){if(e)return zn(e)?os(e):Kn(e)?rs(e):Ki(e)?ss(e):$n(e)?cs(e):as(i,t,e)}function Qn(i,t,e){return i.transaction(t,e?"readwrite":"readonly").objectStore(t)}async function zt({collection:i,index:t,context:e}){let n=Qn(e.documentDb,i),r=t?n.index(t.where):n,s=Kt(e.schema,i,t),o=t?.order==="desc"?"prev":"next",c=r.openCursor(s,o);return await new Promise((h,x)=>{c.onsuccess=()=>{let E=c.result;h(E?X(i,E.primaryKey.toString()):null)},c.onerror=()=>{c.error?.name==="InvalidStateError"?(e.log("error","findOne query failed with InvalidStateError",c.error),h(null)):x(c.error)}})}async function $t({collection:i,index:t,context:e}){let n=Qn(e.documentDb,i),r=t?n.index(t.where):n,s=Kt(e.schema,i,t),o=t?.order==="desc"?"prev":"next",c=r.openCursor(s,o);return await new Promise((h,x)=>{let E=new Set;c.onsuccess=()=>{let g=c.result;g?(E.add(X(i,g.primaryKey.toString())),g.continue()):h(Array.from(E))},c.onerror=()=>{c.error?.name==="InvalidStateError"?(e.log("error","findAll query failed with InvalidStateError",c.error),h([])):x(c.error)}})}async function nt({collection:i,index:t,context:e,limit:n,offset:r}){let s=Qn(e.documentDb,i),o=t?s.index(t.where):s,c=Kt(e.schema,i,t),f=t?.order==="desc"?"prev":"next",h=o.openCursor(c,f),x=!r,E=!1,g=0;return{result:await new Promise((b,v)=>{let C=new Set;h.onsuccess=()=>{g++;let S=h.result;S?r&&!x?(S.advance(r),x=!0):(n&&C.size<n&&C.add(X(i,S.primaryKey.toString())),n&&g>n?(E=!0,b(Array.from(C))):S.continue()):b(Array.from(C))},h.onerror=()=>{h.error?.name==="InvalidStateError"?(e.log("error","find query failed with InvalidStateError",h.error),b([])):v(h.error)}}),hasNextPage:E}}async function Jn(i,t,e,n){function r(c,f){let h,x,E=i.open([t,"collections"].join("_"),e);E.onupgradeneeded=async g=>{h=g.oldVersion;let P=E.transaction;x=E.result,P.abort()},E.onsuccess=g=>{c([E.result.version,E.result])},E.onblocked=g=>{n?.("Database blocked, waiting...")},E.onerror=g=>{c([h,x])}}let[s,o]=await new Promise(r);return await qt(o),s}async function qt(i){i.close(),await new Promise(t=>t())}async function Xi(i,t,e,n,r){function s(o,c){let f=i.open([t,"collections"].join("_"),e),h=!1;f.onupgradeneeded=x=>{let E=f.transaction;n(E,f.result,x),h=!0},f.onsuccess=x=>{f.result.close(),h?o():c(new Error("Database was not upgraded when a version change was expected"))},f.onerror=x=>{c(f.error||new Error("Unknown error"))},f.onblocked=x=>{r?.("Database upgrade blocked, waiting...")}}return new Promise(s)}async function Zi(i,t){typeof navigator<"u"&&navigator.locks?await navigator.locks.request(`verdant_migration_${i}`,t):await t()}async function Re(i,t,e,n){n?.("debug","Opening database",t,"at version",e);let r=await new Promise((s,o)=>{let c=i.open([t,"collections"].join("_"),e);c.onupgradeneeded=async f=>{c.transaction.abort(),n?.("error","Database upgrade needed, but not expected","Expected",e,"Got",c.result.version),o(c.error||new Error(`Migration error: database version changed unexpectedly when reading current data. Expected ${e}, got ${c.result.version}`))},c.onsuccess=f=>{s(c.result)},c.onblocked=f=>{o(new Error("Migration error: database blocked"))},c.onerror=f=>{o(new Error("Migration error: database error"))}});return r.addEventListener("versionchange",s=>{r.close()}),r}var Ve=class extends Error{constructor(e){super(e);this.message=e;this.name="MigrationPathError"}};function Wt({currentVersion:i,targetVersion:t,migrations:e}){let n=er({currentVersion:i,targetVersion:t,migrations:e});if(!n)throw new Ve(`No migration path found from ${i} to ${t}! This is a bug. If you're seeing this, contact the developer and provide them with the full contents of this message.`);return n}function er({currentVersion:i,targetVersion:t,migrations:e}){if(i===t)return[];let n=e.filter(r=>r.oldSchema.version===i).sort((r,s)=>s.newSchema.version-r.newSchema.version);for(;n.length>0;){let r=n.shift();if(r.newSchema.version>t)return null;if(r.newSchema.version===t)return[r];let s=er({currentVersion:r.newSchema.version,targetVersion:t,migrations:e});if(s)return[r,...s]}return null}var Gn=typeof window<"u"?window.indexedDB:void 0;async function it({version:i,indexedDB:t=Gn,migrations:e,meta:n,context:r}){if(r.schema.wip)throw new Error("Cannot open a production client with a WIP schema!");let s=await Jn(t,r.namespace,i,r.log);r.log("debug","Current database version:",s,"target version:",i);let o=Wt({currentVersion:s,targetVersion:i,migrations:e});return o.length>0&&(r.log("debug","Migrations to run:",o.map(c=>c.version)),await Yn({context:r,toRun:o,meta:n,indexedDB:t})),Re(t,r.namespace,i,r.log)}async function tr({version:i,indexedDB:t=Gn,migrations:e,meta:n,context:r,wipNamespace:s}){r.log("debug","Opening WIP database",s);let o=await Jn(t,s,i,r.log);if(o===i)r.log("info","WIP schema is up-to-date; not refreshing database");else{r.log("info","WIP schema is out-of-date; refreshing database");let c=Wt({currentVersion:o,targetVersion:i-1,migrations:e});if(c.length>0){await Yn({context:r,toRun:c,meta:n,indexedDB:t,namespace:s});let h=await Re(t,r.namespace,i-1,r.log),x=await Re(t,s,i-1,r.log),E=new Array;for(let S=0;S<h.objectStoreNames.length;S++)E.push(h.objectStoreNames[S]);let g=h.transaction(E,"readonly"),P=E.map(S=>g.objectStore(S)),b=await Promise.all(P.map(S=>W(S.getAll()))),v=x.transaction(E,"readwrite"),C=E.map(S=>v.objectStore(S));for(let S=0;S<C.length;S++)await Promise.all(b[S].map(O=>W(C[S].put(O))))}let f=Wt({currentVersion:i-1,targetVersion:i,migrations:e});f.length>0&&await Yn({context:r,toRun:f,meta:n,indexedDB:t,namespace:s})}return Re(t,s,i,r.log)}async function Yn({context:i,toRun:t,meta:e,indexedDB:n=Gn,namespace:r=i.namespace}){await Zi(r,async()=>{for(let s of t){let o;if(s.oldSchema.version===0)o=us({meta:e,migration:s,context:i}),await s.migrate(o);else{let h=await Re(n,r,s.oldSchema.version,i.log);o=ds({meta:e,migration:s,context:{...i,documentDb:h}});try{await s.migrate(o),await Promise.all(o.awaitables)}catch(x){throw i.log("critical",`Migration failed (${s.oldSchema.version} -> ${s.newSchema.version})`,x),x}await qt(h)}i.log("debug","Upgrading database",r,"to version",s.newSchema.version),await Xi(n,r,s.newSchema.version,(h,x)=>{for(let E of s.addedCollections)x.createObjectStore(E,{keyPath:s.newSchema.collections[E].primaryKey,autoIncrement:!1});for(let E of s.allCollections){let g=h.objectStore(E);for(let P of s.addedIndexes[E]||[])g.createIndex(P.name,P.name,{multiEntry:P.multiEntry});for(let P of s.removedIndexes[E]||[])g.deleteIndex(P.name)}for(let E of s.removedCollections)h.objectStore(E).clear()},i.log);let c=await ms({meta:e,currentVersion:s.oldSchema.version,newVersion:s.newSchema.version}),f=await Re(n,r,s.newSchema.version,i.log);for(let h of s.allCollections){let E=f.transaction(h,"readwrite").objectStore(h),P=(await ps(E)).map(O=>X(h,`${O}`));P.push(...o.newOids.filter(O=>ae(O).collection===h),...c.filter(O=>ae(O).collection===h));let v=(await Promise.all(P.map(async O=>{try{let A=await e.getDocumentSnapshot(O);return[O,A]}catch(A){return i.log("error","Could not regenerate snapshot during migration for oid",O,"this document will not be preserved",A),null}}))).filter(O=>!!O).map(([O,A])=>{if(!A)return[O,void 0];let y=Tt(s.newSchema.collections[h],A);return[O,y]}),S=f.transaction(h,"readwrite").objectStore(h);await Promise.all(v.map(([O,A])=>{if(A)return hs(S,A).catch(y=>{throw y});{let{id:y}=ae(O);return fs(S,y)}}))}await qt(f),i.log("debug",`Migration of ${r} complete.`),i.log(`
|
|
9
9
|
\u2B06\uFE0F v${s.newSchema.version} Migration complete. Here's the rundown:
|