UNPKG

firetruss

Version:

Advanced data sync layer for Firebase and Vue.js

1 lines 71 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("lodash"),require("vue")):(t="undefined"!=typeof globalThis?globalThis:t||self).Truss=e(t._,t.Vue)}(this,function(g,u){"use strict";var a;g=g&&Object.prototype.hasOwnProperty.call(g,"default")?g.default:g,u=u&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u;function c(){a.digestRequest>h||(a.digestRequest=h+1)}var e,h=0,l=!1,f={active:"undefined"!=typeof window&&window.angular};f.active?(e=window.angular.module("firetruss",[]),f.digest=c,f.watch=function(){throw new Error("Angular watch proxy not yet initialized")},f.defineModule=function(t){e.constant("Truss",t)},f.debounceDigest=function(t){var e;t?(e=g.debounce(c,t),f.digest=function(){a.digestRequest>h||(l?c:e)()}):f.digest=c},e.config(["$provide",function(t){t.decorator("$rootScope",["$delegate","$exceptionHandler",function(t,e){var r=t;f.watch=r.$watch.bind(r);var n,i,o=Object.getPrototypeOf(r),s=o.$digest;return o.$digest=c,o.$digest.original=s,(a=new u({data:{digestRequest:0}})).$watch(function(){return a.digestRequest},function(){a.digestRequest>h?u.nextTick(function(){a.digestRequest<=h||(l=!0,r.$digest.original.call(r),h=a.digestRequest=a.digestRequest+1)}):l=!1}),g.last(a._watchers).id=1/0,n=Object.getPrototypeOf(g.last(a._watchers)),i=n.get,n.get=function(){try{return i.call(this)}catch(t){if(this.vm._watcher!==this||!u.config.errorHandler)throw t;u.config.errorHandler(t,this.vm,"uncaught render error")}},r}])}])):g.forEach(["digest","watch","defineModule","debounceDigest"],function(t){f[t]=g.noop});function n(t,e){this.key=t,this.value=e,this.touch()}n.prototype.touch=function(){this.timestamp=Date.now()};function t(t,e){this._items=Object.create(null),this._size=0,this._maxSize=t,this._pruningSize=e||Math.ceil(.1*t)}t.prototype.has=function(t){return Boolean(this._items[t])},t.prototype.get=function(t){var e=this._items[t];if(e)return e.touch(),e.value},t.prototype.set=function(t,e){var r=this._items[t];r?r.value=e:(this._size>=this._maxSize&&this._prune(),this._items[t]=new n(t,e),this._size+=1)},t.prototype.delete=function(t){this._items[t]&&(delete this._items[t],--this._size)},t.prototype._prune=function(){for(var t=0,e=g(this._items).toArray().sortBy("timestamp").take(this._pruningSize).value();t<e.length;t+=1){var r=e[t];this.delete(r.key)}};var i=new t(1e3),r={};function p(t){return t?t.toString().replace(/[\\.$#[\]/]/g,function(t){return"\\"+t.charCodeAt(0).toString(16)}):t}function d(t){return t?t.toString().replace(/\\[0-9a-f]{2}/gi,function(t){return String.fromCharCode(parseInt(t.slice(1),16))}):t}function _(t){if(!g.isObject(t)||!Object.isExtensible(t))return t;var e,r,n,i=t;for(var o in t){t.hasOwnProperty(o)&&(e=t[o],r=p(o),n=_(e),r===o&&n===e||(i===t&&(i=g.clone(t)),i[r]=n,i[o]===e&&delete i[o]))}return i}function y(){for(var t=[],e=0,r=arguments;e<r.length;e+=1){var n=r[e];g.isString(n)||(n=""+n),"/"===n.charAt(0)&&t.splice(0,t.length),t.push(n)}return"/"===t[0]&&(t[0]=""),t.join("/")}function v(t,e){var r=(e?"esc:":"")+t,n=i.get(r);return n||(n=t.split("/"),e||(n=g.map(n,d)),i.set(r,n)),n}function o(t){var e=this;this.variables=[];var r=g.endsWith(t,"/$*");r&&(t=t.slice(0,-3));var n=t.replace(/\/\$[^/]*/g,function(t){return 1<t.length&&e.variables.push(t.slice(1)),""});if(Object.freeze(this.variables),/[.$#[\]]|\\(?![0-9a-f][0-9a-f])/i.test(n))throw new Error("Path pattern has unescaped keys: "+t);this._regex=new RegExp("^"+n.replace(/\u0001/g,"/([^/]+)")+(r?"($|/)":"$"))}function b(t){var e=r[t];return e||(e=new o(t),1e3===g.size(r)&&delete r[g.keys(r)[0]],r[t]=e),e}o.prototype.match=function(t){this._regex.lastIndex=0;var e=this._regex.exec(t);if(e){for(var r={},n=0;n<this.variables.length;n++)r[this.variables[n]]=d(e[n+1]);return r}},o.prototype.test=function(t){return this._regex.test(t)},o.prototype.toString=function(){return this._regex.toString()};function s(t){var e=t.path,r=t.value,n=t.exists,i=t.writeSerial;this._path=e,this._value=r,this._exists=void 0===r?n||!1:null!==r,this._writeSerial=i}var m="2.0.0",w={path:{configurable:!0},exists:{configurable:!0},value:{configurable:!0},key:{configurable:!0},writeSerial:{configurable:!0}};w.path.get=function(){return this._path},w.exists.get=function(){return this._exists},w.value.get=function(){if(void 0===this._value)throw new Error("Value omitted from snapshot");return this._value},w.key.get=function(){return void 0===this._key&&(this._key=d(this._path.replace(/.*\//,""))),this._key},w.writeSerial.get=function(){return this._writeSerial},Object.defineProperties(s.prototype,w);function $(t){var e=this;this._idCounter=0,this._deferreds={},this._suspended=!1,this._servers={},this._callbacks={},this._log=g.noop,this._inboundMessages=[],this._outboundMessages=[],this._flushMessageQueue=this._flushMessageQueue.bind(this),this._port=t.port||t,this._shared=!!t.port,Object.seal(this),this._port.onmessage=this._receive.bind(this),window.addEventListener("unload",function(){e._send({msg:"destroy"})})}function k(e,t){if(!e||g.isError(e))return e;var r=new Error(e.message);for(var n in r.params=t,e)if("message"!==n&&e.hasOwnProperty(n))try{r[n]=e[n]}catch(t){r.extra=r.extra||{},r.extra[n]=e[n]}return r}$.prototype.init=function(t,e){var r=[];try{var n=window.localStorage||window.sessionStorage;if(!n)throw new Error("localStorage and sessionStorage not available");for(var i=0;i<n.length;i++){var o=n.key(i);r.push({key:o,value:n.getItem(o)})}}catch(t){}return this._send({msg:"init",storage:r,config:e}).then(function(t){var e=t.version.match(/^(\d+)\.(\d+)\.(\d+)(-.*)?$/);if(e){var r=m.match(/^(\d+)\.(\d+)\.(\d+)(-.*)?$/);if(!(e[1]===r[1]&&(e[2]>r[2]||e[2]===r[2]&&e[3]>=r[3])))return Promise.reject(new Error("Incompatible Firetruss worker version: "+t.version+" ("+m+" or better required)"))}return t})},$.prototype.suspend=function(t){void 0===t&&(t=!0),this._suspended!==t&&((this._suspended=t)||(this._receiveMessages(this._inboundMessages),this._inboundMessages=[],this._outboundMessages.length&&Promise.resolve().then(this._flushMessageQueue)))},$.prototype.enableLogging=function(t){t?(!0===t&&(t=console.log.bind(console)),this._log=t):this._log=g.noop},$.prototype._send=function(r){var t,e,n=this;return r.id=++this._idCounter,r.oneWay?t=Promise.resolve():(t=new Promise(function(t,e){n._deferreds[r.id]={resolve:t,reject:e}}),((e=this._deferreds[r.id]).promise=t).sent=new Promise(function(t){e.resolveSent=t}),e.params=r),this._outboundMessages.length||this._suspended||Promise.resolve().then(this._flushMessageQueue),this._log("send:",r),this._outboundMessages.push(r),t},$.prototype._flushMessageQueue=function(){try{this._port.postMessage(this._outboundMessages),this._outboundMessages=[]}catch(t){throw t.extra={messages:this._outboundMessages},t}},$.prototype._receive=function(t){this._suspended?this._inboundMessages=this._inboundMessages.concat(t.data):this._receiveMessages(t.data)},$.prototype._receiveMessages=function(t){for(var e=0,r=t;e<r.length;e+=1){var n=r[e];this._log("recv:",n);var i=this[n.msg];if(!g.isFunction(i))throw new Error("Unknown message: "+n.msg);i.call(this,n)}},$.prototype.bindExposedFunction=function(t){return function(){return this._send({msg:"call",name:t,args:Array.prototype.slice.call(arguments)})}.bind(this)},$.prototype.resolve=function(t){var e=this._deferreds[t.id];if(!e)throw new Error("Received resolution to inexistent Firebase call");delete this._deferreds[t.id],e.resolve(t.result)},$.prototype.reject=function(t){var e=this._deferreds[t.id];if(!e)throw new Error("Received rejection of inexistent Firebase call");delete this._deferreds[t.id],e.reject(k(t.error,e.params))},$.prototype.updateLocalStorage=function(t){var e=t.items;try{for(var r=window.localStorage||window.sessionStorage,n=0,i=e;n<i.length;n+=1){var o=i[n];null===o.value?r.removeItem(o.key):r.setItem(o.key,o.value)}}catch(t){}},$.prototype.trackServer=function(t){if(this._servers.hasOwnProperty(t))return Promise.resolve();var e=this._servers[t]={authListeners:[]},r=this._registerCallback(this._authCallback.bind(this,e));this._send({msg:"onAuth",url:t,callbackId:r})},$.prototype._authCallback=function(t,e){t.auth=e;for(var r=0,n=t.authListeners;r<n.length;r+=1){(0,n[r])(e)}},$.prototype.onAuth=function(t,e,r){var n=e.bind(r);n.callback=e,n.context=r,this._servers[t].authListeners.push(n),n(this.getAuth(t))},$.prototype.offAuth=function(t,e,r){for(var n=this._servers[t].authListeners,i=0;i<n.length;i++){var o=n[i];if(o.callback===e&&o.context===r){n.splice(i,1);break}}},$.prototype.getAuth=function(t){return this._servers[t].auth},$.prototype.authWithCustomToken=function(t,e){return this._send({msg:"authWithCustomToken",url:t,authToken:e})},$.prototype.unauth=function(t){return this._send({msg:"unauth",url:t})},$.prototype.set=function(t,e,r){return this._send({msg:"set",url:t,value:e,writeSerial:r})},$.prototype.update=function(t,e,r){return this._send({msg:"update",url:t,value:e,writeSerial:r})},$.prototype.once=function(t,e){return this._send({msg:"once",url:t,writeSerial:e}).then(function(t){return new s(t)})},$.prototype.on=function(t,e,r,n,i,o,s,a){var c={listenerKey:t,eventType:n,snapshotCallback:i,cancelCallback:o,context:s,params:{msg:"on",listenerKey:t,url:e,spec:r,eventType:n,options:a}},u=this._onCallback.bind(this,c);this._registerCallback(u,c),i.__callbackIds=i.__callbackIds||[],i.__callbackIds.push(c.id),this._send({msg:"on",listenerKey:t,url:e,spec:r,eventType:n,callbackId:c.id,options:a}).catch(function(t){u(t)})},$.prototype.off=function(e,t,r,n,i,o){var s,a=this,c=[];if(i){if(!(s=this._findAndRemoveCallbackId(i,function(t){return g.isMatch(t,{listenerKey:e,eventType:n,context:o})})))return Promise.resolve();c.push(s)}else for(var u=0,h=g.keys(this._callbacks);u<h.length;u+=1){var l=h[u],p=this._callbacks[l];p.listenerKey!==e||n&&p.eventType!==n||c.push(l)}for(var f=0,d=c;f<d.length;f+=1){var _=d[f];this._nullifyCallback(_)}return this._send({msg:"off",listenerKey:e,url:t,spec:r,eventType:n,callbackId:s}).then(function(){for(var t=0,e=c;t<e.length;t+=1){var r=e[t];a._deregisterCallback(r)}})},$.prototype._onCallback=function(t,e,r){var n;e?(this._deregisterCallback(t.id),n=k(e,t.params),t.cancelCallback?t.cancelCallback.call(t.context,n):console.error(n)):t.snapshotCallback.call(t.context,new s(r))},$.prototype.transaction=function(t,e,r,n){return this._send({msg:"transaction",url:t,oldValue:e,relativeUpdates:r,writeSerial:n}).then(function(t){return t.snapshots&&(t.snapshots=g.map(t.snapshots,function(t){return new s(t)})),t})},$.prototype.onDisconnect=function(t,e,r){return this._send({msg:"onDisconnect",url:t,method:e,value:r})},$.prototype.bounceConnection=function(){return this._send({msg:"bounceConnection"})},$.prototype.callback=function(t){var e=t.id,r=t.args,n=this._callbacks[e];if(!n)throw new Error("Unregistered callback: "+e);n.callback.apply(null,r)},$.prototype._registerCallback=function(t,e){return(e=e||{}).callback=t,e.id="cb"+ ++this._idCounter,(this._callbacks[e.id]=e).id},$.prototype._nullifyCallback=function(t){this._callbacks[t].callback=g.noop},$.prototype._deregisterCallback=function(t){delete this._callbacks[t]},$.prototype._findAndRemoveCallbackId=function(t,e){if(t.__callbackIds)for(var r=0;r<t.__callbackIds.length;){var n=t.__callbackIds[r],i=this._callbacks[n];if(i){if(e(i))return t.__callbackIds.splice(r,1),n;r+=1}else t.__callbackIds.splice(r,1)}};var P={};Object.freeze(P);var O=function(t,e,r){this._tree=t,this._path=e.replace(/^\/*/,"/").replace(/\/$/,"")||"/",r&&(this._annotations=r,Object.freeze(r))},E={$ref:{configurable:!0},key:{configurable:!0},path:{configurable:!0},_pathPrefix:{configurable:!0},parent:{configurable:!0},annotations:{configurable:!0}};E.$ref.get=function(){return this},E.key.get=function(){return this._key||(this._key=d(this._path.replace(/.*\//,""))),this._key},E.path.get=function(){return this._path},E._pathPrefix.get=function(){return"/"===this._path?"":this._path},E.parent.get=function(){return new C(this._tree,this._path.replace(/\/[^/]*$/,""),this._annotations)},E.annotations.get=function(){return this._annotations||P},O.prototype.child=function(){if(!arguments.length)return this;for(var t=[],e=0,r=arguments;e<r.length;e+=1){var n=r[e];if(g.isNil(n))return;t.push(p(n))}return new C(this._tree,this._pathPrefix+"/"+t.join("/"),this._annotations)},O.prototype.children=function(){var t=arguments;if(!arguments.length)return this;for(var e=[],r=0;r<arguments.length;r++){var n=t[r];if(g.isArray(n)){for(var i={},o=this._pathPrefix+(e.length?"/"+e.join("/"):""),s=g.slice(t,r+1),a=0,c=n;a<c.length;a+=1){var u=c[a],h=new C(this._tree,o+"/"+p(u),this._annotations),l=h.children.apply(h,s);l&&(i[u]=l)}return i}if(g.isNil(n))return;e.push(p(n))}return new C(this._tree,this._pathPrefix+"/"+e.join("/"),this._annotations)},O.prototype.peek=function(t){return this._tree.truss.peek(this,t)},O.prototype.match=function(t){return b(t).match(this.path)},O.prototype.test=function(t){return b(t).test(this.path)},O.prototype.isEqual=function(t){return t instanceof O&&(this._tree===t._tree&&this.toString()===t.toString()&&g.isEqual(this._annotations,t._annotations))},O.prototype.belongsTo=function(t){return this._tree.truss===t},Object.defineProperties(O.prototype,E);var j=function(o){function e(t,e,r,n){o.call(this,t,e,n),this._spec=this._copyAndValidateSpec(r);var i=g(this._spec).map(function(t,e){return e+"="+encodeURIComponent(JSON.stringify(t))}).sortBy().join("&");this._string=this._path+"?"+i,Object.freeze(this)}o&&(e.__proto__=o),(e.prototype=Object.create(o&&o.prototype)).constructor=e;var t={ready:{configurable:!0},constraints:{configurable:!0}};return t.ready.get=function(){return this._tree.isQueryReady(this)},t.constraints.get=function(){return this._spec},e.prototype.annotate=function(t){return new e(this._tree,this._path,this._spec,g.assign({},this._annotations,t))},e.prototype._copyAndValidateSpec=function(e){if(!e.by)throw new Error('Query needs "by" clause: '+JSON.stringify(e));if(1<("at"in e)+("from"in e)+("to"in e))throw new Error('Query must contain at most one of "at", "from", or "to" clauses: '+JSON.stringify(e));if(1<("first"in e)+("last"in e))throw new Error('Query must contain at most one of "first" or "last" clauses: '+JSON.stringify(e));if(!g.some(["at","from","to","first","last"],function(t){return t in e}))throw new Error('Query must contain at least one of "at", "from", "to", "first", or "last" clauses: '+JSON.stringify(e));if("$key"!==(e=g.clone(e)).by&&"$value"!==e.by){if(!(e.by instanceof C))throw new Error('Query "by" value must be a reference: '+e.by);var t=e.by.toString();if(!g.startsWith(t,this._path))throw new Error('Query "by" value must be a descendant of target reference: '+e.by);if(t=t.slice(this._path.length).replace(/^\/?/,""),!g.includes(t,"/"))throw new Error('Query "by" value must not be a direct child of target reference: '+e.by);e.by=t.replace(/.*?\//,"")}return Object.freeze(e),e},e.prototype.toString=function(){return this._string},Object.defineProperties(e.prototype,t),e}(O),C=function(n){function e(t,e,r){n.call(this,t,e,r),Object.freeze(this)}n&&(e.__proto__=n),(e.prototype=Object.create(n&&n.prototype)).constructor=e;var t={ready:{configurable:!0},value:{configurable:!0}};return t.ready.get=function(){return this._tree.isReferenceReady(this)},t.value.get=function(){return this._tree.getObject(this.path)},e.prototype.toString=function(){return this._path},e.prototype.annotate=function(t){return new e(this._tree,this._path,g.assign({},this._annotations,t))},e.prototype.query=function(t){return new j(this._tree,this._path,t,this._annotations)},e.prototype.set=function(t){var e;return this._checkForUndefinedPath(),this._tree.update(this,"set",((e={})[this.path]=t,e))},e.prototype.update=function(t){return this._checkForUndefinedPath(),this._tree.update(this,"update",t)},e.prototype.override=function(t){var e;return this._checkForUndefinedPath(),this._tree.update(this,"override",((e={})[this.path]=t,e))},e.prototype.commit=function(t){return this._checkForUndefinedPath(),this._tree.commit(this,t)},e.prototype._checkForUndefinedPath=function(){if("/undefined"===this.path)throw new Error("Invalid path for operation: "+this.path)},Object.defineProperties(e.prototype,t),e}(O),S=Object.freeze({".sv":"timestamp"});function R(t,e){return g.isEqualWith(t,e,x)}function x(t,e){return t===e||null==t||null==e||t.$truss||e.$truss?t===e:t.isEqual?t.isEqual(e):void 0}function T(t,e){for(var r=0,n=Object.getOwnPropertyNames(t.prototype);r<n.length;r+=1){var i=n[r];"constructor"!==i&&Object.defineProperty(e.prototype,i,Object.getOwnPropertyDescriptor(t.prototype,i))}}var D="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function A(t){g.assign(this,{name:t,numRecomputes:0,numUpdates:0,runtime:0})}var z,M,I=(function(s){(function(){var t,e,r,n,i,o;"undefined"!=typeof performance&&null!==performance&&performance.now?s.exports=function(){return performance.now()}:"undefined"!=typeof process&&null!==process&&process.hrtime?(s.exports=function(){return(t()-i)/1e6},e=process.hrtime,n=(t=function(){var t=e();return 1e9*t[0]+t[1]})(),o=1e9*process.uptime(),i=n-o):r=Date.now?(s.exports=function(){return Date.now()-r},Date.now()):(s.exports=function(){return(new Date).getTime()-r},(new Date).getTime())}).call(D)}(M={path:z,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&M.path)}},M.exports),M.exports),q={runtimePerRecompute:{configurable:!0}};A.prototype.add=function(t){this.runtime+=t.runtime,this.numUpdates+=t.numUpdates,this.numRecomputes+=t.numRecomputes},q.runtimePerRecompute.get=function(){return this.numRecomputes?this.runtime/this.numRecomputes:0},A.prototype.toLogParts=function(t){return[this.name+":"," "+(this.runtime/1e3).toFixed(2)+"s","("+(this.runtime/t.runtime*100).toFixed(1)+"%)"," "+this.numUpdates+" upd /",this.numRecomputes+" runs","("+(this.numUpdates/this.numRecomputes*100).toFixed(1)+"%)"," "+this.runtimePerRecompute.toFixed(2)+"ms / run"]},Object.defineProperties(A.prototype,q);function V(){this._items={}}var F={list:{configurable:!0}};V.prototype.for=function(t){return this._items[t]||(this._items[t]=new A(t)),this._items[t]},F.list.get=function(){return g(this._items).values().sortBy(function(t){return-t.runtime}).value()},V.prototype.log=function(t){void 0===t&&(t=10);var e,r,n,i,o=this.list;o.length&&(e=new A("=== Total"),g.forEach(o,function(t){e.add(t)}),o=g.take(o,t),r=new A("--- Above"),g.forEach(o,function(t){r.add(t)}),(n=g.map(o,function(t){return t.toLogParts(e)})).push(r.toLogParts(e)),n.push(e.toLogParts(e)),i=g.map(g.range(n[0].length),function(e){return g(n).map(function(t){return t[e].length}).max()}),g.forEach(n,function(t){console.log(g.map(t,function(t,e){return g.padLeft(t,i[e])}).join(" "))}))},V.prototype.wrap=function(n,t,i){var o=this.for(t+"."+i);return function(){var t=I(),e=this._computedWatchers&&this._computedWatchers[i].value;try{var r=n.call(this);return R(e,r)||(o.numUpdates+=1),r}finally{o.runtime+=I()-t,o.numRecomputes+=1}}},Object.defineProperties(V.prototype,F);function U(t,e,r,n,i){var o=this;Object.freeze(e),this._scope=t,this._connections=e,this._tree=r,this._method=n,this._subConnectors={},this._disconnects={},this._angularUnwatches=void 0,this._data={},this._vue=new u({data:{descriptors:{},refs:i||{},values:g.mapValues(e,g.constant(void 0))}}),this.destroy=this.destroy,Object.seal(this),this._linkScopeProperties(),g.forEach(e,function(t,e){g.isFunction(t)?o._bindComputedConnection(e,t):o._connect(e,t)}),f.active&&t&&t.$on&&t.$id&&t.$on("$destroy",function(){o.destroy()})}var W=new V,K={ready:{configurable:!0},at:{configurable:!0},data:{configurable:!0}};function N(t){if(t)return t instanceof O?t.toString():g.mapValues(t,N)}function L(t){return function(){try{return Promise.resolve(t.apply(this,arguments))}catch(t){return Promise.reject(t)}}}function Q(t,e){return(t=H(t,function(){e=null})).cancel=function(){e&&(e(),e=null)},function n(i,o){var s=i.then,r=i.catch;i.then=function(t,e){var r=s.call(i,t,e);return r[o]=i[o],n(r,o),r};i.catch=function(t){var e=r.call(i,t);return e[o]=i[o],n(e,o),e};return i}(t,"cancel"),t}function H(t,e){return e?(e=L(e),t.then(function(t){return e().then(function(){return t})},function(t){return e().then(function(){return Promise.reject(t)})})):t}K.ready.get=function(){var n=this;return g.every(this._connections,function(t,e){var r=n._vue.descriptors[e];return!!r&&(r instanceof O?r.ready:n._subConnectors[e].ready)})},K.at.get=function(){return this._vue.refs},K.data.get=function(){return this._data},U.prototype.destroy=function(){var r=this;this._unlinkScopeProperties(),g.forEach(this._angularUnwatches,function(t){t()}),g.forEach(this._connections,function(t,e){r._disconnect(e)}),this._vue.$destroy()},U.prototype._linkScopeProperties=function(){var r=this,t=g.mapValues(this._connections,function(t,e){return{configurable:!0,enumerable:!1,get:function(){var t=r._vue.descriptors[e];return t instanceof C?t.value:r._vue.values[e]}}});if(Object.defineProperties(this._data,t),this._scope){for(var e in this._connections)if(e in this._scope)throw new Error("Property already defined on connection target: "+e);Object.defineProperties(this._scope,t),this._scope.__ob__&&this._scope.__ob__.dep.notify()}},U.prototype._unlinkScopeProperties=function(){var r=this;this._scope&&g.forEach(this._connections,function(t,e){delete r._scope[e]})},U.prototype._bindComputedConnection=function(t,e){var r=W.for("connection.at."+t),n=this._computeConnection.bind(this,e,r),i=this._updateComputedConnection.bind(this,t,e,r),o=f.active&&!e.angularWatchSuppressed;this._vue.$watch(n,i,{immediate:!o}),o&&(this._angularUnwatches||(this._angularUnwatches=[]),this._angularUnwatches.push(f.watch(n,i,!0)))},U.prototype._computeConnection=function(t,e){var r=I();try{return N(t.call(this._scope))}finally{e.runtime+=I()-r,e.numRecomputes+=1}},U.prototype._updateComputedConnection=function(t,e,r){var n=g.isFunction(e)?e(this._scope):e,i=!R(this._vue.descriptors[t],n);i&&(r&&i&&(r.numUpdates+=1),n?(n instanceof O||!g.has(this._subConnectors,t)?(this._disconnect(t),this._connect(t,n)):this._subConnectors[t]._updateConnections(n),u.set(this._vue.descriptors,t,n),f.digest()):this._disconnect(t))},U.prototype._updateConnections=function(r){var n=this;g.forEach(r,function(t,e){n._updateComputedConnection(e,t)}),g.forEach(this._connections,function(t,e){g.has(r,e)||n._updateComputedConnection(e)}),this._connections=r},U.prototype._connect=function(e,t){var r,n,i,o,s,a=this;u.set(this._vue.descriptors,e,t),f.digest(),t&&(u.set(this._vue.values,e,void 0),t instanceof C?(u.set(this._vue.refs,e,t),this._disconnects[e]=this._tree.connectReference(t,this._method)):t instanceof j?(u.set(this._vue.refs,e,t),r=this._updateQueryValue.bind(this,e),this._disconnects[e]=this._tree.connectQuery(t,r,this._method)):(n={},i={},u.set(this._vue.refs,e,i),o=this._subConnectors[e]=new U(n,t,this._tree,this._method,i),s=this._disconnects[e]=this._tree.truss.observe(function(){return o.ready},function(t){t&&(s(),delete a._disconnects[e],u.set(a._vue.values,e,n),f.digest())})))},U.prototype._disconnect=function(t){u.delete(this._vue.refs,t),this._updateRefValue(t,void 0),g.has(this._subConnectors,t)&&(this._subConnectors[t].destroy(),delete this._subConnectors[t]),this._disconnects[t]&&this._disconnects[t](),delete this._disconnects[t],u.delete(this._vue.descriptors,t),f.digest()},U.prototype._updateRefValue=function(t,e){this._vue.values[t]!==e&&(u.set(this._vue.values,t,e),f.digest())},U.prototype._updateQueryValue=function(t,e){this._vue.values[t]||(u.set(this._vue.values,t,{}),f.digest());var r=this._vue.values[t];for(var n in r)r.hasOwnProperty(n)&&(g.includes(e,n)||(u.delete(r,n),f.digest()));for(var i=this._tree.getObject(this._vue.descriptors[t].path),o=0,s=e;o<s.length;o+=1){var a=s[o];r.hasOwnProperty(a)||(u.set(r,a,i[a]),f.digest())}},Object.defineProperties(U.prototype,K);function B(t,e,r){this._operation=t,this._delay=e,this._callback=r,this._fired=!1}var J=["read","write","auth","set","update","commit","connect","peek","authenticate","unathenticate","certify","all"],G=[];B.prototype.initiate=function(){var t=this;this.cancel(),this._fired=!1;var e=Date.now()-this._operation._startTimestamp;this._timeoutId=setTimeout(function(){t._fired=!0,t._callback(t._operation)},this._delay-e)},B.prototype.cancel=function(){this._fired&&this._callback(this._operation),this._timeoutId&&clearTimeout(this._timeoutId)};function Y(t,e,r,n){this._type=t,this._method=e,this._target=r,this._operand=n,this._ready=!1,this._running=!1,this._ended=!1,this._tries=0,this._startTimestamp=Date.now(),this._slowHandles=[]}var X={type:{configurable:!0},method:{configurable:!0},target:{configurable:!0},targets:{configurable:!0},operand:{configurable:!0},ready:{configurable:!0},running:{configurable:!0},ended:{configurable:!0},tries:{configurable:!0},error:{configurable:!0}};X.type.get=function(){return this._type},X.method.get=function(){return this._method},X.target.get=function(){return this._target},X.targets.get=function(){var r=this;return"update"!==this._method?[this._target]:g.map(this._operand,function(t,e){return new C(r._target._tree,y(r._target.path,e),r._target._annotations)})},X.operand.get=function(){return this._operand},X.ready.get=function(){return this._ready},X.running.get=function(){return this._running},X.ended.get=function(){return this._ended},X.tries.get=function(){return this._tries},X.error.get=function(){return this._error},Y.prototype.onSlow=function(t,e){var r=new B(this,t,e);this._slowHandles.push(r),r.initiate()},Y.prototype._setRunning=function(t){this._running=t},Y.prototype._setEnded=function(t){this._ended=t},Y.prototype._markReady=function(t){this._ready=!0,t||(this._tries=0),g.forEach(this._slowHandles,function(t){return t.cancel()})},Y.prototype._clearReady=function(){this._ready=!1,this._startTimestamp=Date.now(),g.forEach(this._slowHandles,function(t){return t.initiate()})},Y.prototype._incrementTries=function(){this._tries++},Object.defineProperties(Y.prototype,X);function Z(t){this._bridge=t,this._callbacks={},Object.freeze(this)}Z.prototype.intercept=function(t,e){if(!g.includes(J,t))throw new Error("Unknown intercept operation type: "+t);var r=g.difference(g.keys(e),["onBefore","onAfter","onError","onFailure"]);if(r.length)throw new Error("Unknown intercept callback types: "+r.join(", "));var n={onBefore:this._addCallback("onBefore",t,e.onBefore),onAfter:this._addCallback("onAfter",t,e.onAfter),onError:this._addCallback("onError",t,e.onError),onFailure:this._addCallback("onFailure",t,e.onFailure)};return this._removeCallbacks.bind(this,t,n)},Z.prototype._addCallback=function(t,e,r){if(r){var n=this._getCallbacksKey(t,e),i=L(r);return(this._callbacks[n]||(this._callbacks[n]=[])).push(i),i}},Z.prototype._removeCallback=function(t,e,r){var n;r&&(n=this._getCallbacksKey(t,e),this._callbacks[n]&&g.pull(this._callbacks[n],r))},Z.prototype._removeCallbacks=function(r,t){var n=this;g.forEach(t,function(t,e){n._removeCallback(e,r,t)})},Z.prototype._getCallbacks=function(t,e,r){return[].concat(this._callbacks[this._getCallbacksKey(t,r)]||G,this._callbacks[this._getCallbacksKey(t,e)]||G,this._callbacks[this._getCallbacksKey(t,"all")]||G)},Z.prototype._getCallbacksKey=function(t,e){return t+"_"+e},Z.prototype.execute=function(t,e,r,n,i){var o=this;i=L(i);var s=this.createOperation(t,e,r,n);return this.begin(s).then(function(){var e=function(){return i().catch(function(t){return o._retryOrEnd(s,t).then(e)})};return e()}).then(function(t){return o.end(s).then(function(){return t})})},Z.prototype.createOperation=function(t,e,r,n){return new Y(t,e,r,n)},Z.prototype.begin=function(e){var r=this;return Promise.all(g.map(this._getCallbacks("onBefore",e.type,e.method),function(t){return t(e)})).then(function(){e.ended||e._setRunning(!0)},function(t){return r.end(e,t)})},Z.prototype.markReady=function(t){t._markReady()},Z.prototype.clearReady=function(t){t._clearReady()},Z.prototype.retry=function(r,e){return r._incrementTries(),r._error=e,Promise.all(g.map(this._getCallbacks("onError",r.type,r.method),function(t){return t(r,e)})).then(function(t){if(!r.ended){var e=g.some(t);return e&&delete r._error,e}})},Z.prototype._retryOrEnd=function(e,r){var n=this;return this.retry(e,r).then(function(t){if(!t)return n.end(e,r)},function(t){return n.end(e,t)})},Z.prototype.end=function(e,t){var r=this;return e.ended?Promise.resolve():(e._setRunning(!1),e._setEnded(!0),t?e._error=t:delete e._error,Promise.all(g.map(this._getCallbacks("onAfter",e.type,e.method),function(t){return t(e)})).then(function(){return r._afterEnd(e)},function(t){return e._error=t,r._afterEnd(e)}))},Z.prototype._afterEnd=function(e){if(e._markReady(!0),!e.error)return Promise.resolve();var t=this._getCallbacks("onFailure",e.type,e.method);return t&&setTimeout(function(){g.forEach(t,function(t){return t(e)})},0),Promise.reject(e.error)};function tt(){this._lastUniqueKeyTime=0,this._lastRandomValues=[]}var et="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",rt=window.crypto&&window.crypto.getRandomValues&&window.crypto.getRandomValues.bind(window.crypto);tt.prototype.generateUniqueKey=function(t){t=t||Date.now();for(var e=new Array(20),r=t,n=7;0<=n;n--)e[n]=et.charAt(63&r),r=Math.floor(r/64);if(t===this._lastUniqueKeyTime){for(var i=11;0<=i&&63===this._lastRandomValues[i];)this._lastRandomValues[i]=0,--i;if(-1===i)throw new Error("Internal assertion failure: ran out of unique IDs for this millisecond");this._lastRandomValues[i]+=1}else if(this._lastUniqueKeyTime=t,rt){var o=new Uint8Array(12);rt(o);for(var s=0;s<12;s++)this._lastRandomValues[s]=o[s]&(s?63:15)}else for(var a=0;a<12;a++)this._lastRandomValues[a]=Math.floor(Math.random()*(a?64:16));for(var c=0;c<12;c++)e[c+8]=et[this._lastRandomValues[c]];return e.join("")};function nt(t,e,r,n){this._rootUrl=t,this._tree=e,this._dispatcher=n,this._bridge=r,this._vue=new u({data:{$root:{connected:void 0,timeOffset:0,user:void 0,userid:void 0,nowAtInterval:function(t){var e,r=this,n="now"+t;return this.hasOwnProperty(n)||((e=function(){u.set(r,n,Date.now()+r.timeOffset),f.digest()})(),setInterval(e,t)),this[n]}}}}),this._auth={serial:0,initialAuthChangeReceived:!1},r.onAuth(t,this._handleAuthChange,this),this._connectInfoProperty("serverTimeOffset","timeOffset"),this._connectInfoProperty("connected","connected"),Object.freeze(this)}var it={root:{configurable:!0}};it.root.get=function(){return this._vue.$data.$root},nt.prototype.destroy=function(){this._bridge.offAuth(this._rootUrl,this._handleAuthChange,this),this._vue.$destroy()},nt.prototype.authenticate=function(t){var e=this;return this._auth.serial++,this._dispatcher.execute("auth","authenticate",new C(this._tree,"/"),t,function(){return e._bridge.authWithCustomToken(e._rootUrl,t)})},nt.prototype.unauthenticate=function(){var e=this;return this._auth.serial++,this._handleAuthChange(null).then(function(t){if(t)return e._dispatcher.execute("auth","unauthenticate",new C(e._tree,"/"),void 0,function(){return e._bridge.unauth(e._rootUrl)})})},nt.prototype._handleAuthChange=function(t){var e=this,r=!this._auth.initialAuthChangeReceived&&this._auth.serial;if(void 0!==t&&(this._auth.initialAuthChangeReceived=!0),!r){var n=this._auth.serial;return this.root.user===t?Promise.resolve(!1):this._dispatcher.execute("auth","certify",new C(this._tree,"/"),t,function(){return e.root.user!==t&&n===e._auth.serial&&(t&&Object.freeze(t),e.root.user=t,e.root.userid=t&&t.uid,f.digest(),!0)})}},nt.prototype._isAuthChangeStale=function(t){return this.root.user===t},nt.prototype._connectInfoProperty=function(t,e){var r=this,n=this._rootUrl+"/.info/"+t;this._bridge.on(n,n,null,"value",function(t){r.root[e]=t.value,f.digest()})},Object.defineProperties(nt.prototype,it);function ot(){}var st,at,ct={$$$trussCheck:!0,__ob__:!0},ut={$meta:{configurable:!0},$store:{configurable:!0},$now:{configurable:!0},$$finalizers:{configurable:!0}};ut.$meta.get=function(){return this.$truss.meta},ut.$store.get=function(){return this.$truss.store},ut.$now.get=function(){return this.$truss.now},ot.prototype.$newKey=function(){return this.$truss.newKey()},ot.prototype.$intercept=function(t,e){var r=this;if(this.$destroyed)throw new Error("Object already destroyed");var n=this.$truss.intercept(t,e),i=function(){n(),g.pull(r.$$finalizers,i)};return this.$$finalizers.push(i),i},ot.prototype.$connect=function(t,e){var r=this;if(this.$destroyed)throw new Error("Object already destroyed");e||(e=t,t=void 0);var n=this.$truss.connect(t,function r(n,t){if(!t||t instanceof O)return t;return g.mapValues(t,function(t){if(t instanceof O)return t;if(g.isFunction(t)){var e=function(){return n.$$touchThis(),r(n,t.call(this))};return e.angularWatchSuppressed=!0,e}return r(n,t)})}(this,e)),i=n.destroy,o=function(){return g.pull(r.$$finalizers,o),i.call(n)};return this.$$finalizers.push(o),n.destroy=o,n},ot.prototype.$peek=function(t,e){var r=this;if(this.$destroyed)throw new Error("Object already destroyed");var n=H(this.$truss.peek(t,e),function(){g.pull(r.$$finalizers,n.cancel)});return this.$$finalizers.push(n.cancel),n},ot.prototype.$observe=function(t,e,r){var n=this;if(this.$destroyed)throw new Error("Object already destroyed");var i=this.$truss.observe(function(){return n.$$touchThis(),t.call(n)},e.bind(this),r),o=function(){i(),g.pull(n.$$finalizers,o)};return this.$$finalizers.push(o),o},ot.prototype.$when=function(t,e){var r=this;if(this.$destroyed)throw new Error("Object already destroyed");var n=this.$truss.when(function(){return r.$$touchThis(),t.call(r)},e);return H(n,function(){g.pull(r.$$finalizers,n.cancel)}),this.$$finalizers.push(n.cancel),n},ut.$$finalizers.get=function(){return Object.defineProperty(this,"$$finalizers",{value:[],writable:!1,enumerable:!1,configurable:!1}),this.$$finalizers},Object.defineProperties(ot.prototype,ut);function ht(){}var lt={$parent:{configurable:!0},$path:{configurable:!0},$truss:{configurable:!0},$ref:{configurable:!0},$refs:{configurable:!0},$key:{configurable:!0},$data:{configurable:!0},$hidden:{configurable:!0},$empty:{configurable:!0},$keys:{configurable:!0},$values:{configurable:!0},$ready:{configurable:!0},$overridden:{configurable:!0},$$initializers:{configurable:!0},$destroyed:{configurable:!0}};lt.$parent.get=function(){return st.$parent.value},lt.$path.get=function(){return st.$path.value},lt.$truss.get=function(){return Object.defineProperty(this,"$truss",{value:this.$parent.$truss}),this.$truss},lt.$ref.get=function(){return Object.defineProperty(this,"$ref",{value:new C(this.$truss._tree,this.$path)}),this.$ref},lt.$refs.get=function(){return this.$ref},lt.$key.get=function(){return Object.defineProperty(this,"$key",{value:d(this.$path.slice(this.$path.lastIndexOf("/")+1))}),this.$key},lt.$data.get=function(){return this},lt.$hidden.get=function(){return!1},lt.$empty.get=function(){return g.isEmpty(this.$data)},lt.$keys.get=function(){return g.keys(this.$data)},lt.$values.get=function(){return g.values(this.$data)},lt.$ready.get=function(){return this.$ref.ready},lt.$overridden.get=function(){return!1},ht.prototype.$nextTick=function(){var t=this;if(this.$destroyed)throw new Error("Object already destroyed");var e=this.$truss.nextTick();return H(e,function(){g.pull(t.$$finalizers,e.cancel)}),this.$$finalizers.push(e.cancel),e},ht.prototype.$freezeComputedProperty=function(){if(!g.isBoolean(at))throw new Error("Cannot freeze a computed property outside of its getter function");at=!0},ht.prototype.$set=function(t){return this.$ref.set(t)},ht.prototype.$update=function(t){return this.$ref.update(t)},ht.prototype.$override=function(t){return this.$ref.override(t)},ht.prototype.$commit=function(t,e){return this.$ref.commit(t,e)},ht.prototype.$$touchThis=function(){this.__ob__?this.__ob__.dep.depend():this.$parent?(this.$parent.hasOwnProperty("$data")?this.$parent.$data:this.$parent)[this.$key]:this.$store},lt.$$initializers.get=function(){return Object.defineProperty(this,"$$initializers",{value:[],writable:!1,enumerable:!1,configurable:!0}),this.$$initializers},lt.$destroyed.get=function(){return!1},Object.defineProperties(ht.prototype,lt),T(ot,ht),g.forEach(ht.prototype,function(t,e){Object.defineProperty(ht.prototype,e,{value:t,enumerable:!1,configurable:!1,writable:!1})});function pt(t){this.error=t}function ft(t){this.value=t}function dt(t){this._trie={Class:ht},this._debug=t,Object.freeze(this)}dt.prototype.init=function(t,e){var r=this;g.isPlainObject(t)&&(g.forEach(t,function(t,e){t.$trussMount||(t.$$trussMount=t.$$trussMount||[],t.$$trussMount.push(e))}),t=g.values(t),g.forEach(t,function(t){!t.$trussMount&&t.$$trussMount&&(t.$trussMount=t.$$trussMount,delete t.$$trussMount)})),t=g.uniq(t),g.forEach(t,function(t){return r._mountClass(t,e)}),this._decorateTrie(this._trie)},dt.prototype.destroy=function(){},dt.prototype._getMount=function(t,e,r){for(var n,i=0,o=v(t,!0);i<o.length;i+=1){var s=o[i],a=s?n.children&&(n.children[s]||!e&&n.children.$):this._trie;if(!a){if(!e)return;n.children=n.children||{},a=n.children[s]={Class:ht}}if(n=a,r&&r(n))break}return n},dt.prototype._findMount=function(t,e){if(t(e=e||this._trie))return e;for(var r=0,n=g.keys(e.children);r<n.length;r+=1){var i=n[r],o=this._findMount(t,e.children[i]);if(o)return o}},dt.prototype._decorateTrie=function(e){var r=this;g.forEach(e.children,function(t){r._decorateTrie(t),(t.local||t.localDescendants)&&(e.localDescendants=!0)})},dt.prototype._augmentClass=function(t){for(var e,r=t.prototype;r&&r.constructor!==Object;){for(var n=0,i=Object.getOwnPropertyNames(r);n<i.length;n+=1){var o=i[n],s=Object.getOwnPropertyDescriptor(r,o);if("$"===o.charAt(0)){if("$finalize"===o)continue;if(g.isEqual(s,Object.getOwnPropertyDescriptor(ht.prototype,o)))continue;throw new Error('Property names starting with "$" are reserved: '+t.name+"."+o)}!s.get||e&&e[o]||((e=e||{})[o]={name:o,fullName:r.constructor.name+"."+o,get:s.get,set:s.set})}r=Object.getPrototypeOf(r)}for(var a=0,c=Object.getOwnPropertyNames(ht.prototype);a<c.length;a+=1){var u=c[a];"constructor"===u||t.prototype.hasOwnProperty(u)||Object.defineProperty(t.prototype,u,Object.getOwnPropertyDescriptor(ht.prototype,u))}return e},dt.prototype._mountClass=function(a,c){var u=this,h=this._augmentClass(a),l=[],t=a.$trussMount;if(!t)throw new Error("Class "+a.name+" lacks a $trussMount static property");g.isArray(t)||(t=[t]),g.forEach(t,function(t){if(g.isString(t)&&(t={path:t}),!c&&"/"===t.path)throw new Error("Data root already accessed, too late to mount class");for(var e=b(t.path),r=0,n=e.variables;r<n.length;r+=1){var i=n[r];if("$"===i||"$"===i.charAt(1))throw new Error("Invalid variable name: "+i);if("$"===i.charAt(0)&&(g.has(ht.prototype,i)||ct[i]))throw new Error("Variable name conflicts with built-in property or method: "+i);l.push(i)}var o=t.path.match(/\/([^/]*)$/)[1];if("$"===o.charAt(0)){if(t.placeholder)throw new Error("Class "+a.name+" mounted at wildcard "+o+" cannot be a placeholder")}else g.has(t,"placeholder")||(t.placeholder={});var s=u._getMount(t.path.replace(/\$[^/]*/g,"$"),!0);if(s.matcher&&(s.escapedKey===o||"$"===s.escapedKey.charAt(0)&&"$"===o.charAt(0)))throw new Error("Multiple classes mounted at "+t.path+": "+s.Class.name+", "+a.name);g.assign(s,{Class:a,matcher:e,computedProperties:h,escapedKey:o},g.pick(t,"placeholder","local","keysUnsafe","hidden"))}),g.forEach(l,function(t){a.prototype[t]||Object.defineProperty(a.prototype,t,{get:function(){return st?st[t]&&st[t].value:void 0}})})},dt.prototype.createObject=function(t,e){var r=this,n=this._getMount(t)||{Class:ht};try{if(n.matcher){var i=n.matcher.match(t);for(var o in i)e[o]={value:i[o]}}st=e;var s=new n.Class;return st=null,f.active&&this._wrapProperties(s),n.keysUnsafe&&(e.$data={value:Object.create(null),configurable:!0,enumerable:!0}),n.hidden&&(e.$hidden={value:!0}),n.computedProperties&&g.forEach(n.computedProperties,function(t){e[t.name]=r._buildComputedPropertyDescriptor(s,t)}),s}catch(t){throw t.extra=g.assign({mount:n,properties:e,className:n.Class&&n.Class.name},t.extra),t}},dt.prototype._wrapProperties=function(i){g.forEach(i,function(t,e){var r,n="$_"+e;Object.defineProperties(i,((r={})[n]={value:t,writable:!0},r[e]={get:function(){return i[n]},set:function(t){i[n]=t,f.digest()},enumerable:!0,configurable:!0},r))})},dt.prototype._buildComputedPropertyDescriptor=function(s,a){var c,u,h=this,l=W.for(a.fullName),p=!1;return s.$$initializers.push(function(t){var e=!1,r=function(t,e){if(this.$destroyed)return;this.$$touchThis();var r=at;at=!1;var n,i=I();try{try{n=t.get.call(this)}catch(t){n=new pt(t)}finally{e.runtime+=I()-i,e.numRecomputes+=1}return at&&(n=new ft(n)),n}finally{at=r}}.bind(s,a,l);h._debug&&(r.toString=function(){return a.fullName});var n=function(){e=!0},n=t.$watch(r,function(t){if(s.$destroyed)n();else if(u&&(u.cancel&&u.cancel(),u=void 0),g.isObject(t)&&g.isFunction(t.then)){var e=t.then(function(t){e===u&&o(t)},function(t){if(e===u&&o(new pt(t))&&!t.trussExpectedException)throw t});u=e}else if(o(t)&&(f.digest(),t instanceof pt&&!t.error.trussExpectedException))throw t.error},{immediate:!0}),i=g.last(t._watchers);function o(t){return t instanceof ft&&(t=t.value,n(),g.pull(s.$$finalizers,n)),!R(c,t)&&(l.numUpdates+=1,p=!0,s[a.name]=t,p=!1,function e(t){if(g.isNil(t)||!g.isObject(t)||Object.isFrozen(t)||t.$truss)return t;t=Object.freeze(t);if(g.isArray(t))return g.map(t,function(t){return e(t)});return g.mapValues(t,function(t){return e(t)})}(t),1)}i.id=-i.id,e?n():s.$$finalizers.push(n)}),{enumerable:!0,configurable:!0,get:function(){if(!p&&c instanceof pt)throw c.error;return c},set:function(t){if(p)c=t;else{if(!a.set)throw new Error("You cannot set a computed property: "+a.name);a.set.call(this,t)}}}},dt.prototype.destroyObject=function(t){if(g.has(t,"$$finalizers"))for(var e=0,r=g.clone(t.$$finalizers);e<r.length;e+=1){(0,r[e])()}g.isFunction(t.$finalize)&&t.$finalize(),Object.defineProperty(t,"$destroyed",{value:!0,enumerable:!1,configurable:!1})},dt.prototype.isPlaceholder=function(t){var e=this._getMount(t);return e&&e.placeholder},dt.prototype.isLocal=function(t,e){var r=this._getMount(t,!1,function(t){return t.local});if(r&&r.local)return!0;if(this._hasLocalProperties(r,e))throw new Error("Write on a mix of local and remote tree paths.");return!1},dt.prototype._hasLocalProperties=function(t,e){if(!t)return!1;if(t.local)return!0;if(!t.localDescendants||!g.isObject(e))return!1;for(var r in e){if(this._hasLocalProperties(t.children[p(r)]||t.children.$,e[r]))return!0}return!1},dt.prototype.forEachPlaceholderChild=function(t,e){var r=this._getMount(t);g.forEach(r&&r.children,function(t){t.placeholder&&e(t)})},dt.prototype.checkVueObject=function(e,t,r){var n=!r;n&&(r=[]);try{for(var i=0,o=Object.getOwnPropertyNames(e);i<o.length;i+=1){var s=o[i];if(!(ct[s]||ht.prototype.hasOwnProperty(s)||/^\$_/.test(s))){var a=this._findMount(function(t){return t.Class===e.constructor});if(!(a&&a.matcher&&g.includes(a.matcher.variables,s))){var c=void 0;try{c=e[s]}catch(t){continue}if(!g.isArray(e)||!/\d+/.test(s)&&"length"!==s){var u=Object.getOwnPropertyDescriptor(e,s);if("value"in u||!u.get)throw new Error("Value at "+t+", contained in a Firetruss object, has a rogue property: "+s);if(e.$truss&&u.enumerable)try{throw e[s]=c,new Error("Firetruss object at "+t+" has an enumerable non-Firebase property: "+s)}catch(t){if("firebase_overwrite"!==t.trussCode)throw t}}g.isObject(c)&&!c.$$$trussCheck&&Object.isExtensible(c)&&!(g.isFunction(c)||c instanceof Promise)&&(c.$$$trussCheck=!0,r.push(c),this.checkVueObject(c,y(t,p(s)),r))}}}}finally{if(n)for(var h=0,l=r;h<l.length;h+=1){delete l[h].$$$trussCheck}}};function _t(t,e){this._coupler=t,this._query=e,this._listeners=[],this._keys=[],this._url=this._coupler._rootUrl+e.path,this._segments=v(e.path,!0),this._listening=!1,this.ready=!1}_t.prototype.attach=function(t,e){this._listen(),this._listeners.push({operation:t,keysCallback:e}),e&&e(this._keys)},_t.prototype.detach=function(t){var e=g.findIndex(this._listeners,{operation:t});return 0<=e&&this._listeners.splice(e,1),this._listeners.length},_t.prototype._listen=function(){this._listening||(this._coupler._bridge.on(this._query.toString(),this._url,this._query.constraints,"value",this._handleSnapshot,this._handleError,this,{sync:!0}),this._listening=!0)},_t.prototype.destroy=function(){this._coupler._bridge.off(this._query.toString(),this._url,this._query.constraints,"value",this._handleSnapshot,this),this._listening=!1,this.ready=!1,f.digest();for(var t=0,e=this._keys;t<e.length;t+=1){var r=e[t];this._coupler._decoupleSegments(this._segments.concat(r))}},_t.prototype._handleSnapshot=function(a){var c=this;this._coupler._queueSnapshotCallback(function(){if(c._listeners.length&&c._listening){var t=c._updateKeys(a);if(c._coupler._applySnapshot(a),!c.ready){c.ready=!0,f.digest();for(var e=0,r=c._listeners;e<r.length;e+=1){var n=r[e];c._coupler._dispatcher.markReady(n.operation)}}if(t)for(var i=0,o=c._listeners;i<o.length;i+=1){var s=o[i];s.keysCallback&&s.keysCallback(t)}}})},_t.prototype._updateKeys=function(t){var e,r;if(t.path===this._query.path)if((e=g.keys(t.value)).sort(),g.isEqual(this._keys,e))e=null;else{for(var n=0,i=g.difference(e,this._keys);n<i.length;n+=1){var o=i[n];this._coupler._coupleSegments(this._segments.concat(o))}for(var s=0,a=g.difference(this._keys,e);s<a.length;s+=1){var c=a[s];this._coupler._decoupleSegments(this._segments.concat(c))}this._keys=e}else t.path.replace(/\/[^/]+/,"")===this._query.path&&(r=g.includes(this._keys,t.key),t.value?r||(this._coupler._coupleSegments(this._segments.concat(t.key)),this._keys.push(t.key),this._keys.sort(),e=this._keys):r&&(this._coupler._decoupleSegments(this._segments.concat(t.key)),g.pull(this._keys,t.key),this._keys.sort(),e=this._keys));return e},_t.prototype._handleError=function(n){var i=this;this._listeners.length&&this._listening&&(this._listening=!1,this.ready=!1,f.digest(),Promise.all(g.map(this._listeners,function(e){return i._coupler._dispatcher.clearReady(e.operation),i._coupler._dispatcher.retry(e.operation,n).catch(function(t){return e.operation._disconnect(t),!1})})).then(function(t){if(g.some(t))i._listeners.length&&i._listen();else for(var e=0,r=i._listeners;e<r.length;e+=1){r[e].operation._disconnect(n)}}))};function yt(t,e,r){this._coupler=t,this.path=e,this.parent=r,this.url=this._coupler._rootUrl+e,this.operations=[],this.queryCount=0,this.listening=!1,this.ready=!1,this.children={}}var gt={active:{configurable:!0},count:{configurable:!0}};gt.active.get=function(){return this.count||this.queryCount},gt.count.get=function(){return this.operations.length},yt.prototype.listen=function(t){var e=this;if(!t&&this.count){if(this.listening)return;g.forEach(this.operations,function(t){e._coupler._dispatcher.clearReady(t)}),this._coupler._bridge.on(this.url,this.url,null,"value",this._handleSnapshot,this._handleError,this,{sync:!0}),this.listening=!0}else g.forEach(this.children,function(t){t.listen()})},yt.prototype.unlisten=function(t){!t&&this.listening?(this._coupler._bridge.off(this.url,this.url,null,"value",this._handleSnapshot,this),this.listening=!1,this._forAllDescendants(function(t){return!t.listening&&void(t.ready&&(t.ready=!1,f.digest()))})):g.forEach(this.children,function(t){t.unlisten()})},yt.prototype._handleSnapshot=function(t){var i=this;this._coupler._queueSnapshotCallback(function(){i.listening&&i._coupler.isTrunkCoupled(t.path)&&(i._coupler._applySnapshot(t),i.ready||t.path!==i.path||(i.ready=!0,f.digest(),i.unlisten(!0),i._forAllDescendants(function(t){for(var e=0,r=t.operations;e<r.length;e+=1){var n=r[e];i._coupler._dispatcher.markReady(n)}})))})},yt.prototype._handleError=function(n){var i=this;if(this.count&&this.listening)return this.listening=!1,this._forAllDescendants(function(t){if(t.listening)return!1;t.ready&&(t.ready=!1,f.digest());for(var e=0,r=t.operations;e<r.length;e+=1){var n=r[e];i._coupler._dispatcher.clearReady(n)}}),Promise.all(g.map(this.operations,function(e){return i._coupler._dispatcher.retry(e,n).catch(function(t){return e._disconnect(t),!1})})).then(function(t){if(g.some(t))i.count&&i.listen();else for(var e=0,r=i.operations;e<r.length;e+=1){r[e]._disconnect(n)}})},yt.prototype._forAllDescendants=function(e){!1!==e(this)&&g.forEach(this.children,function(t){return t._forAllDescendants(e)})},yt.prototype.collectCoupledDescendantPaths=function(e){return(e=e||{})[this.path]=this.active,this.active||g.forEach(this.children,function(t){t.collectCoupledDescendantPaths(e)}),e},Object.defineProperties(yt.prototype,gt);function vt(t,e,r,n,i){this._rootUrl=t,this._bridge=e,this._dispatcher=r,this._applySnapshot=n,this._pendingSnapshotCallbacks=[],this._throttled={processPendingSnapshots:this._processPendingSnapshots},this._prunePath=i,this._vue=new u({data:{root:void 0,queryHandlers:{}}}),this._vue._renderProxy=this._vue,this._nodeIndex=Object.create(null),Object.freeze(this),this._vue.$data.root=new yt(this,"/"),this._nodeIndex["/"]=this._root}var bt={_root:{configurable:!0},_queryHandlers:{configurable:!0}};bt._root.get=function(){return this._vue.$data.root},bt._queryHandlers.get=function(){return this._vue.$data.queryHandlers},vt.prototype.destroy=function(){g.forEach(this._queryHandlers,function(t){t.destroy()}),this._root.unlisten(),this._vue.$destroy()},vt.prototype.couple=function(t,e){return this._coupleSegments(v(t,!0),e)},vt.prototype._coupleSegments=function(t,e){for(var r,n=!e,i=!1,o=0,s=t;o<s.length;o+=1){var a=s[o],c=a?r.children&&r.children[a]:this._root;c||(c=new yt(this,("/"===r.path?"":r.path)+"/"+a,r),u.set(r.children,a,c),this._nodeIndex[c.path]=c),n=n||c.listening,i=i||c.ready,r=c}e?r.operations.push(e):r.queryCount++,n?e