diff --git a/dist/error_code.json b/dist/error_code.json index 1417fdf7..419b3c04 100644 --- a/dist/error_code.json +++ b/dist/error_code.json @@ -1,7 +1,7 @@ { "0": "System error", "1": "Lovefield library version mismatch.", - "2": "The database has not initialized yet.", + "2": "The database connection is not active.", "3": "Operation timeout.", "4": "Operation blocked.", "5": "Storage quota exceeded.", @@ -20,6 +20,7 @@ "110": "Attempt to import into a non-empty database.", "111": "Database name/version mismatch for import.", "112": "Import data not found.", + "113": "Attempt to call connect() on an already opened DB connection.", "200": "Constraint error", "201": "Duplicate keys are not allowed.", diff --git a/dist/lovefield.es6.js b/dist/lovefield.es6.js index 6e12407e..84b91838 100644 --- a/dist/lovefield.es6.js +++ b/dist/lovefield.es6.js @@ -5,20 +5,20 @@ else if("function"==b&&"undefined"==typeof a.call)return"object";return b}functi function oa(a,b,c){if(!a)throw Error();if(2b?1:0};function wa(a,b,c){this.eg=c;this.If=a;this.wg=b;this.md=0;this.gd=null}wa.prototype.get=function(){var a;0c?Math.max(0,a.length+c):c;if(ia(a))return ia(b)&&1==b.length?a.indexOf(b,c):-1;for(;c=arguments.length?xa.slice.call(a,b):xa.slice.call(a,b,c)} -function Fa(a){for(var b=[],c=0;cb?1:0};function wa(a,b,c){this.eg=c;this.If=a;this.wg=b;this.nd=0;this.gd=null}wa.prototype.get=function(){var a;0c?Math.max(0,a.length+c):c;if(ia(a))return ia(b)&&1==b.length?a.indexOf(b,c):-1;for(;c=arguments.length?Array.prototype.slice.call(a,b):Array.prototype.slice.call(a,b,c)}function Ea(a){for(var b=[],c=0;cd.length?"0"+d:d);return b};function vb(a){this.type=a}function wb(a){y.call(this,-1,a)}t(wb,y);function xb(a,b,c,d){c=c||function(a,b){return a==b};d=d||function(b){return a[b]};for(var e=a.length,f=b.length,h=[],k=0;kh[k][n-1]?k--:n--;return z}function yb(a){return Ca(arguments,function(a,c){return a+c},0)} -function zb(a){return yb.apply(null,arguments)/arguments.length}function Bb(a){var b=arguments.length;if(2>b)return 0;var c=zb.apply(null,arguments);return yb.apply(null,Aa(arguments,function(a){return Math.pow(a-c,2)}))/(b-1)}function Cb(a){return Math.sqrt(Bb.apply(null,arguments))};var Db="StopIteration"in p?p.StopIteration:{message:"StopIteration",stack:""};function Eb(){}Eb.prototype.next=function(){throw Db;};Eb.prototype.te=function(){return this};function Fb(a){if(a instanceof Eb)return a;if("function"==typeof a.te)return a.te(!1);if(ha(a)){var b=0,c=new Eb;c.next=function(){for(;;){if(b>=a.length)throw Db;if(b in a)return a[b++];b++}};return c}throw Error("Not implemented");} -function Gb(a,b){if(ha(a))try{za(a,b,void 0)}catch(c){if(c!==Db)throw c;}else{a=Fb(a);try{for(;;)b.call(void 0,a.next(),void 0,a)}catch(c){if(c!==Db)throw c;}}}function Hb(a){if(Da(arguments,function(a){return!a.length})||!arguments.length)return new Eb;var b=new Eb,c=arguments,d=Fa(c.length);b.next=function(){if(d){for(var a=Aa(d,function(a,b){return c[b][a]}),b=d.length-1;0<=b;b--){if(d[b]parseFloat(a))?String(b):a}(),Sb={};var Tb=Lb()||u("iPod"),Ub=u("iPad");!u("Android")||La()||u("Firefox")||Ka();var Vb=La(),Wb=u("Safari")&&!(La()||u("Coast")||Ka()||u("Edge")||u("Silk")||u("Android"))&&!(Lb()||u("iPad")||u("iPod"));/* +function y(a,b){this.oa=a;this.o=b||this.Fe()}var pb=0;m=y.prototype;m.id=g("oa");function qb(a){return a.o}m.Fe=function(){return{}};m.qf=g("o");m.Fa=function(){return{id:this.oa,value:this.qf()}};m.Fb=function(a){return"#"==a.substr(-1)?this.oa:null};function rb(a){return new y(a.id,a.value)}function sb(a){return new y(pb++,a||{})}function tb(a){if(null==a)return null;a=new Uint8Array(a);for(var b="",c=0;cd.length?"0"+d:d);return b};function ub(a){this.type=a}function vb(a){y.call(this,-1,a)}t(vb,y);function wb(a,b,c,d){c=c||function(a,b){return a==b};d=d||function(b){return a[b]};for(var e=a.length,f=b.length,h=[],k=0;kh[k][n-1]?k--:n--;return z}function xb(a){return Ba(arguments,function(a,c){return a+c},0)} +function yb(a){return xb.apply(null,arguments)/arguments.length}function Ab(a){var b=arguments.length;if(2>b)return 0;var c=yb.apply(null,arguments);return xb.apply(null,za(arguments,function(a){return Math.pow(a-c,2)}))/(b-1)}function Bb(a){return Math.sqrt(Ab.apply(null,arguments))};var Cb="StopIteration"in p?p.StopIteration:{message:"StopIteration",stack:""};function Db(){}Db.prototype.next=function(){throw Cb;};Db.prototype.te=function(){return this};function Eb(a){if(a instanceof Db)return a;if("function"==typeof a.te)return a.te(!1);if(ha(a)){var b=0,c=new Db;c.next=function(){for(;;){if(b>=a.length)throw Cb;if(b in a)return a[b++];b++}};return c}throw Error("Not implemented");} +function Fb(a,b){if(ha(a))try{ya(a,b,void 0)}catch(c){if(c!==Cb)throw c;}else{a=Eb(a);try{for(;;)b.call(void 0,a.next(),void 0,a)}catch(c){if(c!==Cb)throw c;}}}function Gb(a){if(Ca(arguments,function(a){return!a.length})||!arguments.length)return new Db;var b=new Db,c=arguments,d=Ea(c.length);b.next=function(){if(d){for(var a=za(d,function(a,b){return c[b][a]}),b=d.length-1;0<=b;b--){if(d[b]parseFloat(a))?String(b):a}(),Rb={};var Sb=Kb()||u("iPod"),Tb=u("iPad");!u("Android")||Ka()||u("Firefox")||Ja();var Ub=Ka(),Vb=u("Safari")&&!(Ka()||u("Coast")||Ja()||u("Edge")||u("Silk")||u("Android"))&&!(Kb()||u("iPad")||u("iPod"));/* Copyright 2015 The Lovefield Project Authors. All Rights Reserved. @@ -53,207 +53,208 @@ var ua=function(){if(Mb&&p.opera){var a;var b=p.opera.version;try{a=b()}catch(c) See the License for the specific language governing permissions and limitations under the License. */ -function Xb(){this.xg=Wb||Ub||Tb;this.Wf=!(this.xg||Nb&&!Sb[10]&&!(Sb[10]=0<=ta(10)));!Nb||Sb[11]||(Sb[11]=0<=ta(11));this.Fg=Vb||Wb}var Yb;function A(){return new window.Map}function Zb(a){var b=0,c=Array(a.size);a.forEach(function(a,e){c[b++]=e});return c}function B(a){var b=0,c=Array(a.size);a.forEach(function(a){c[b++]=a});return c};var $b={};r("lf.TransactionType",$b);$b.READ_ONLY=0;$b.READ_WRITE=1;function ac(a,b){this.pe=a;this.Oa=b||null;this.S=x()}ac.prototype.ia=function(){return 0==this.pe?this.rc():bc(this)};function bc(a){try{cc(a.Oa)}catch(b){return cb(b)}return dc(a).then(function(a){this.Oa.ia();return a}.bind(a))}function dc(a){ec(a);fc(a);return a.rc()} -function ec(a){a.Oa.rb.forEach(function(a,c){var d=this.Oa.ca().get(c),d=this.H(d.getName(),d.Cb.bind(d)),e=B(a.ya).map(function(a){return a.id()});0a.size)return!1;var c=!0;b.forEach(function(b){c=c&&a.has(b)});return c};function qc(a,b){this.oa=a;this.o=b||{}}function rc(a){var b=C();a.forEach(function(a){b.add(a>>9)});return D(b)}qc.prototype.Y=g("oa");function sc(a,b){b.forEach(function(a){this.o[a.id()]=a.Fa()},a)}function tc(a,b){b.forEach(function(a){delete this.o[a]},a)}qc.prototype.Fa=function(){return{id:this.oa,value:JSON.stringify(this.o)}};function uc(a){return new qc(a.id,JSON.parse(a.value))};function vc(a,b,c){this.X=a;this.Bb=b;this.hf=c}m=vc.prototype;m.get=function(a){if(0==a.length)return this.Md();var b=this.Bb;return wc(this,a).then(function(c){return a.map(function(a){var e=c.get(a>>9);return b(e.o[a])})})};function wc(a,b){var c=A(),d=x(),e=rc(b).map(function(a){return new v(function(b,d){var e;try{e=this.X.get(a)}catch(z){d(z);return}e.onerror=d;e.onsuccess=function(a){a=uc(a.target.result);c.set(a.Y(),a);b()}},this)},a);fb(e).then(function(){d.resolve(c)});return d.da} -m.Md=function(){return new v(function(a,b){var c=[],d;try{d=this.X.openCursor()}catch(e){b(e);return}d.onerror=b;d.onsuccess=function(){var b=d.result;if(b){var f;f=uc(b.value).o;for(var h in f)c.push(this.Bb(f[h]));b.continue()}else a(c)}.bind(this)},this)};m.Sb=function(a){return new v(function(b,c){var d;try{d=a()}catch(e){c(e);return}d.onsuccess=b;d.onerror=c},this)}; -m.put=function(a){if(0==a.length)return w();var b=A();a.forEach(function(a){var d;d=a.id()>>9;var e=b.get(d)||null;null===e&&(e=this.hf(this.X.name,d));sc(e,[a]);b.set(d,e)},this);a=B(b).map(function(a){return this.Sb(function(){return this.X.put(a.Fa())}.bind(this))},this);return fb(a)}; -m.remove=function(a){if(0==a.length)return this.Sb(function(){return this.X.clear()}.bind(this));var b=A();a.forEach(function(a){var d=a>>9,e=b.get(d)||null;null===e&&(e=this.hf(this.X.name,d));tc(e,[a]);b.set(d,e)},this);a=B(b).map(function(a){return this.Sb(function(){return 0==Object.keys(a.o).length?this.X.delete(a.Y()):this.X.put(a.Fa())}.bind(this))},this);return fb(a)};function xc(a,b,c){a=a.j(jc);var d=[c<<9,(c+1<<9)-1];b=a.Xa(b,d[0],d[1]);c=new qc(c);sc(c,b);return c} -function yc(a,b){return new qc(b)};function zc(){};function Ac(a){this.V=a.j(jc);this.D=a.j(kc);this.i=a.j(oc)}Ac.prototype.update=function(a){a.forEach(function(a){Bc(this,a);Cc(this,a)},this)};function Cc(a,b){var c=b.getName();b.ya.forEach(function(a,b){this.V.remove(c,b)},a);b.ua.forEach(function(a){this.V.set(c,a)},a);b.ma.forEach(function(a){this.V.set(c,a[1])},a)}function Bc(a,b){var c=a.i.table(b.getName());Dc(b).forEach(function(a){Ec(this,c,a)},a)} -function Ec(a,b,c){var d=a.D.mc.get(b.getName())||[],e=0;d.forEach(function(a){try{Fc(a,c),e++}catch(b){throw d.slice(0,e).forEach(function(a){Fc(a,[c[1],c[0]])},this),b;}},a)}function Fc(a,b){var c=null===b[1]?void 0:b[1].Fb(a.getName()),d=null===b[0]?void 0:b[0].Fb(a.getName());if(!q(d)&&q(c))a.add(c,b[1].id());else if(q(d)&&q(c)){if(null===c||null===d){if(c==d)return}else if(0==a.dc().compare(d,c))return;a.add(c,b[1].id());a.remove(d,b[0].id())}else q(d)&&!q(c)&&a.remove(d,b[0].id())};var Gc={};r("lf.ConstraintAction",Gc);Gc.RESTRICT=0;Gc.CASCADE=1;var Hc={};r("lf.ConstraintTiming",Hc);Hc.IMMEDIATE=0;Hc.DEFERRABLE=1;var Ic={};r("lf.Order",Ic);Ic.DESC=0;Ic.ASC=1;var Jc={};r("lf.Type",Jc);Jc.ARRAY_BUFFER=0;Jc.BOOLEAN=1;Jc.DATE_TIME=2;Jc.INTEGER=3;Jc.NUMBER=4;Jc.STRING=5;Jc.OBJECT=6;var Kc={0:null,1:!1,2:Object.freeze(new Date(0)),3:0,4:0,5:"",6:null};r("lf.type.DEFAULT_VALUES",Kc);function E(a,b){this.code=a;this.message="http://sn.im/2a0j3wn?c="+a;if(1a.size)return!1;var c=!0;b.forEach(function(b){c=c&&a.has(b)});return c};function pc(a,b){this.oa=a;this.o=b||{}}function qc(a){var b=C();a.forEach(function(a){b.add(a>>9)});return D(b)}pc.prototype.Y=g("oa");function rc(a,b){b.forEach(function(a){this.o[a.id()]=a.Fa()},a)}function sc(a,b){b.forEach(function(a){delete this.o[a]},a)}pc.prototype.Fa=function(){return{id:this.oa,value:JSON.stringify(this.o)}};function tc(a){return new pc(a.id,JSON.parse(a.value))};function uc(a,b,c){this.X=a;this.Bb=b;this.hf=c}m=uc.prototype;m.get=function(a){if(0==a.length)return this.Nd();var b=this.Bb;return vc(this,a).then(function(c){return a.map(function(a){var e=c.get(a>>9);return b(e.o[a])})})};function vc(a,b){var c=A(),d=x(),e=qc(b).map(function(a){return new v(function(b,d){var e;try{e=this.X.get(a)}catch(z){d(z);return}e.onerror=d;e.onsuccess=function(a){a=tc(a.target.result);c.set(a.Y(),a);b()}},this)},a);eb(e).then(function(){d.resolve(c)});return d.da} +m.Nd=function(){return new v(function(a,b){var c=[],d;try{d=this.X.openCursor()}catch(e){b(e);return}d.onerror=b;d.onsuccess=function(){var b=d.result;if(b){var f;f=tc(b.value).o;for(var h in f)c.push(this.Bb(f[h]));b.continue()}else a(c)}.bind(this)},this)};m.Sb=function(a){return new v(function(b,c){var d;try{d=a()}catch(e){c(e);return}d.onsuccess=b;d.onerror=c},this)}; +m.put=function(a){if(0==a.length)return w();var b=A();a.forEach(function(a){var d;d=a.id()>>9;var e=b.get(d)||null;null===e&&(e=this.hf(this.X.name,d));rc(e,[a]);b.set(d,e)},this);a=B(b).map(function(a){return this.Sb(function(){return this.X.put(a.Fa())}.bind(this))},this);return eb(a)}; +m.remove=function(a){if(0==a.length)return this.Sb(function(){return this.X.clear()}.bind(this));var b=A();a.forEach(function(a){var d=a>>9,e=b.get(d)||null;null===e&&(e=this.hf(this.X.name,d));sc(e,[a]);b.set(d,e)},this);a=B(b).map(function(a){return this.Sb(function(){return 0==Object.keys(a.o).length?this.X.delete(a.Y()):this.X.put(a.Fa())}.bind(this))},this);return eb(a)};function wc(a,b,c){a=a.l(ic);var d=[c<<9,(c+1<<9)-1];b=a.Xa(b,d[0],d[1]);c=new pc(c);rc(c,b);return c} +function xc(a,b){return new pc(b)};function yc(){};function zc(a){this.V=a.l(ic);this.D=a.l(jc);this.i=a.l(nc)}zc.prototype.update=function(a){a.forEach(function(a){Ac(this,a);Bc(this,a)},this)};function Bc(a,b){var c=b.getName();b.ya.forEach(function(a,b){this.V.remove(c,b)},a);b.ua.forEach(function(a){this.V.set(c,a)},a);b.ma.forEach(function(a){this.V.set(c,a[1])},a)}function Ac(a,b){var c=a.i.table(b.getName());Cc(b).forEach(function(a){Dc(this,c,a)},a)} +function Dc(a,b,c){var d=a.D.mc.get(b.getName())||[],e=0;d.forEach(function(a){try{Ec(a,c),e++}catch(b){throw d.slice(0,e).forEach(function(a){Ec(a,[c[1],c[0]])},this),b;}},a)}function Ec(a,b){var c=null===b[1]?void 0:b[1].Fb(a.getName()),d=null===b[0]?void 0:b[0].Fb(a.getName());if(!q(d)&&q(c))a.add(c,b[1].id());else if(q(d)&&q(c)){if(null===c||null===d){if(c==d)return}else if(0==a.dc().compare(d,c))return;a.add(c,b[1].id());a.remove(d,b[0].id())}else q(d)&&!q(c)&&a.remove(d,b[0].id())};var Fc={};r("lf.ConstraintAction",Fc);Fc.RESTRICT=0;Fc.CASCADE=1;var Gc={};r("lf.ConstraintTiming",Gc);Gc.IMMEDIATE=0;Gc.DEFERRABLE=1;var Hc={};r("lf.Order",Hc);Hc.DESC=0;Hc.ASC=1;var Ic={};r("lf.Type",Ic);Ic.ARRAY_BUFFER=0;Ic.BOOLEAN=1;Ic.DATE_TIME=2;Ic.INTEGER=3;Ic.NUMBER=4;Ic.STRING=5;Ic.OBJECT=6;var Jc={0:null,1:!1,2:Object.freeze(new Date(0)),3:0,4:0,5:"",6:null};r("lf.type.DEFAULT_VALUES",Jc);function E(a,b){this.code=a;this.message="http://sn.im/2a0j3wn?c="+a;if(1c.c||d.w==c.c&&!d.la&&!c.ea}function nd(){return new id(F,F,!1,!1)}function kd(a){return a.c==F&&a.w==F}function od(a){return a.c==a.w&&a.c!=F&&!a.ea&&!a.la}id.prototype.contains=function(a){var b=this.w==F||athis.c||a==this.c&&!this.ea)&&b}; -function md(a,b,c,d,e){function f(a){return c?a:1==a?-1:1}d=d||!1;e=e||!1;return a==F?b==F?(d?!e:e)?d?f(1):f(-1):0:f(-1):b==F?f(1):a=c[0]&&a<=c[1]});a.set("gte",function(a,c){return null===a||null===c?!1:a>=c});a.set("gt",function(a,c){return null===a||null===c?!1:a>c});a.set("in",function(a,c){return-1!=c.indexOf(a)});a.set("lte",function(a,c){return null===a||null===c?!1:a<=c});a.set("lt",function(a,c){return null===a||null===c?!1:a=c[0].getTime()&&a.getTime()<=c[1].getTime()});a.set("eq",function(a,c){return(null===a?-1:a.getTime())==(null===c?-1:c.getTime())});a.set("gte",function(a,c){return null===a||null===c?!1:a.getTime()>=c.getTime()});a.set("gt",function(a,c){return null===a||null===c?!1:a.getTime()>c.getTime()});a.set("in",function(a,c){return c.some(function(c){return c.getTime()==a.getTime()})});a.set("lte", -function(a,c){return null===a||null===c?!1:a.getTime()<=c.getTime()});a.set("lt",function(a,c){return null===a||null===c?!1:a.getTime()c&&(c=b[d]);a.ra().forEach(function(a){this.Sa.has(a.getName())||(b[a.getName()]=++c)},this);d=this.l.child("@table");return se(d,b)}.bind(this))}; -function te(a,b,c){var d=a.Sa.get(b);return null!=d?function(){var a={},b=x();this.l.orderByChild("T").equalTo(d).once("value",function(d){d.forEach(function(b){var d=c(b.val());a[parseInt(b.key(),10)]=d});b.resolve(a)});return b.da}.call(a).then(function(a){a["@rev"]={R:++this.La};return se(this.l,a)}.bind(a)):w()}M.prototype.tc=function(a){return te(this,a,l(null)).then(function(){this.Sa.delete(a);return se(this.l.child("@table/"+a),null,!0)}.bind(this))};M.prototype.dropTable=M.prototype.tc; -M.prototype.pc=function(a,b,c){return te(this,a,function(a){var e=a.P;e[b]=c;return{R:this.La+1,T:a.T,P:e}}.bind(this))};M.prototype.addTableColumn=M.prototype.pc;M.prototype.uc=function(a,b){return te(this,a,function(a){var d=a.P;delete d[b];return{R:this.La+1,T:a.T,P:d}}.bind(this))};M.prototype.dropTableColumn=M.prototype.uc;M.prototype.Jc=function(a,b,c){return te(this,a,function(a){var e=a.P;e[c]=e[b];delete e[b];return{R:this.La+1,T:a.T,P:e}}.bind(this))};M.prototype.renameTableColumn=M.prototype.Jc; -M.prototype.tb=function(){throw new E(351);};M.prototype.createRow=M.prototype.tb;M.prototype.Cc=g("Zb");M.prototype.getVersion=M.prototype.Cc;M.prototype.ec=function(a){var b=x();a=this.Sa.get(a);this.l.orderByChild("T").equalTo(a).once("value",function(a){var d=[];a.forEach(function(a){d.push(a.val().P)});b.resolve(d)});return b.da};M.prototype.dump=function(){var a={},b=Zb(this.Sa).map(function(b){return this.ec(b).then(function(d){a[b]=d})}.bind(this));return fb(b).then(function(){return a})}; -M.prototype.dump=M.prototype.dump;function ue(a,b,c){ac.call(this,b,c);this.l=a}t(ue,ac);ue.prototype.H=function(a){return this.l.Ac(a)}; -ue.prototype.rc=function(){if(0==this.pe)return this.S.resolve(),this.S.da;var a=this.Oa.rb;if(0==a.size)this.S.resolve();else{var b=this.l.La+1;this.l.La=b;var c={"@rev":{R:b}};a.forEach(function(a,e){var f=this.l.Sa.get(e);a.ua.forEach(function(a,d){c[d]={R:b,T:f,P:a.o}});a.ma.forEach(function(a,d){c[d]={R:b,T:f,P:a[1].o}});a.ya.forEach(function(a,b){c[b]=null})},this);this.l.l.update(c,function(c){null===c?this.S.resolve():(this.l.La=b-1,c=B(a).map(function(a){return ve(this.l,a.getName())},this), -fb(c).then(this.S.reject.bind(this.S),this.S.reject.bind(this.S)))}.bind(this))}return this.S.da};function we(){this.xa=A()}function xe(a,b){if(0==b.length)return B(a.xa);var c=[];b.forEach(function(a){a=this.xa.get(a)||null;null===a||c.push(a)},a);return c}we.prototype.getData=g("xa");we.prototype.get=function(a){return w(xe(this,a))};function ye(a,b){b.forEach(function(a){this.xa.set(a.id(),a)},a)}we.prototype.put=function(a){ye(this,a);return w()};function ze(a,b){0==b.length||b.length==a.xa.size?a.xa.clear():b.forEach(function(a){this.xa.delete(a)},a)} -we.prototype.remove=function(a){ze(this,a);return w()};function Ae(a){return 0==a.xa.size?0:Zb(a.xa).reduce(function(a,c){return a>c?a:c},0)};function Be(a,b){this.i=a;this.xf=b;this.Ic=A();this.La=-1;this.L=A();this.Sa=A();this.Cd=null}m=Be.prototype; -m.Ga=function(a){this.l=this.xf.child(this.i.name());var b=a||function(){return w()};return re(this.l,"@db/version").then(function(a){return null===a?se(this.l,Ce(this),!0).then(function(){var a=new M(0,this.l);return b(a)}.bind(this)):a==this.i.version()?re(this.l,"@rev/R").then(function(a){this.La=a;return re(this.l,"@table")}.bind(this)).then(function(a){for(var b in a)this.Sa.set(b,a[b]);a=this.i.ra().map(function(a){return ve(this,a.getName())},this);return fb(a)}.bind(this)).then(function(){De(this); -Ee(this);return w()}.bind(this)):this.be(a,b).then(function(){return this.Ga()}.bind(this))}.bind(this))};m.be=function(a,b){var c=new M(a,this.l);return c.Ga(this.i).then(function(){return w()}.bind(this)).then(function(){return b(c)}).then(function(){var a=this.l.child("@db");return se(a,{version:this.i.version()},!0)}.bind(this))}; -function Ee(a){a.l.off();a.l.on("child_removed",a.lg.bind(a));a.Dd&&(a.Dd.off(),a.Ic.clear());a.Dd=a.l.orderByChild("R").startAt(a.La+1);a.Dd.on("value",a.Zd.bind(a))}function De(a){qb=B(a.L).map(function(a){return Ae(a)}).reduce(function(a,c){return a>c?a:c},0)+1}m.lg=function(a){var b=a.val(),c=this.Ic.get(b.T)||null;null===c&&(c=C(),this.Ic.set(b.T,c));c.add(parseInt(a.key(),10))}; -m.Zd=function(a){var b=a.child("@rev/R").val();null!=b&&b!=this.La&&(this.La=b,a=Fe(this,a),a.forEach(function(a){var b=this.L.get(a.getName()),e=Zb(a.ya);0this.i.version()?c.reject(new E(108)):c.resolve()}.bind(a));return c.da}m.Ab=function(a,b,c){if(null!=this.l)return new Ze(this.l,a,c);throw new E(2);};m.close=aa(); -m.Ac=function(){throw new E(512);};m.subscribe=function(){throw new E(355);};m.Fc=function(){throw new E(355);};m.be=function(a,b){var c=x();ff(this).then(function(){a(new P(this.h,b,this.l)).then(function(){return this.je()}.bind(this)).then(c.resolve.bind(c))}.bind(this),c.reject.bind(c));return c.da}; -function ff(a){var b=a.i.ra(),c=new Ze(a.l,1,new dd(a.h,C())),d=new Ze(a.l,1,new dd(a.h,C()));Ye(c,"INSERT OR REPLACE INTO __lf_ver VALUES (0, ?)",[a.i.version()]);cf(c);return c.ia().then(function(a){function c(a,b){Ye(d,"INSERT INTO "+a+"(id, value) VALUES(?, ?)",[-1,JSON.stringify(rb(new wb(new vb(b))))])}var h=a[1];h.filter(function(a){return-1!=a.indexOf("__d__")}).forEach(function(a){Ye(d,"DROP TABLE "+a,[])});var k=[],n=[],z=[];b.map(function(a){-1==h.indexOf(a.getName())&&k.push(a.getName()); -a.zb&&(a.Aa().forEach(function(a){a=$e(a.m());k.push(a);n.push(a)}),a=$e(Re(a)),k.push(a),z.push(a))});k.forEach(function(a){Ye(d,"CREATE TABLE "+a+"(id INTEGER PRIMARY KEY, value TEXT)",[])});n.forEach(function(a){c(a,"btree")});z.forEach(function(a){c(a,"rowid")});return d.ia()})} -m.je=function(){var a=0,b=x(),c=function(b){var c=new Ze(this.l,0);Ye(c,"SELECT MAX(id) FROM "+b,[]);return c.ia().then(function(b){b=b[0].rows.item(0)[0];a=Math.max(b,a)})}.bind(this),d=this.i.ra().map(function(a){return c(a.getName())});fb(d).then(function(){b.resolve(a)},function(a){b.reject(a)});return b.da};function gf(a){this.Z=A();this.Yb=A();a.ra().forEach(function(a){this.Yb.set(a.getName(),C())},this)}m=gf.prototype;m.set=function(a,b){this.Z.set(b.id(),b);this.Yb.get(a).add(b.id())};m.Vb=function(a,b){var c=this.Yb.get(a);b.forEach(function(a){this.Z.set(a.id(),a);c.add(a.id())},this)};m.get=function(a){return this.Z.get(a)||null};function hf(a,b){return b.map(function(a){return this.get(a)},a)} -m.Xa=function(a,b,c){var d=[],e=Math.min(b,c),f=Math.max(b,c);a=this.Yb.get(a);if(a.size=e&&a<=f&&(a=this.Z.get(a),d.push(a))},this);else for(b=e;b<=f;++b)a.has(b)&&(c=this.Z.get(b),d.push(c));return d};m.remove=function(a,b){this.Z.delete(b);this.Yb.get(a).delete(b)};m.Ig=function(a){return null!=a?this.Yb.get(a).size:this.Z.size};m.clear=function(){this.Z.clear();this.Yb.clear()};function jf(a,b,c){var d=0,e=a.length;for(c=c||kf;d>1;0>c(a[f],b)?d=f+1:e=f}return d==e&&a[d]==b?d:~d}function kf(a,b){return a-b}function mf(a,b,c){c=jf(a,b,c);return 0>c?(a.splice(-(c+1),0,b),!0):!1};function nf(a,b,c,d){a=b?a.reverse():a;if(null==c&&null==d)return a;c=Math.min(q(c)?c:a.length,a.length);if(0==c)return[];d=Math.min(d||0,a.length);return a.slice(d,d+c)};function of(a){this.Yc=0==a?pf:qf;this.Xd=0==a?function(a){return null!=a?a.reverse():null}:function(a){return a||null};this.ce=0==a?rf:sf}t(of,zc);function qf(a,b){return a>b?1:ab?1:a==b?0:-1};m.Ob=function(a,b){var c=this.sb(a,b);return c[0]&&c[1]};m.nf=function(a){return a.filter(function(a){return null!==a}).sort(function(a,c){return this.ce(a,c)}.bind(this))};m.Rd=function(a){return this.Xd(a).c==F};m.qd=function(a){a=this.Xd(a);return[a.c,a.w]};m.Xc=function(a){return null!==a};m.toString=function(){return this.compare==pf?"SimpleComparator_DESC":"SimpleComparator_ASC"}; -function tf(a){of.call(this,a);this.Yc=0==a?uf:vf}t(tf,of);function vf(a,b){return null===a?null===b?0:-1:null===b?1:qf(a,b)}function uf(a,b){return vf(b,a)}tf.prototype.Ob=function(a,b){return null===a?kd(b):tf.ab.Ob.call(this,a,b)};tf.prototype.Gb=function(a,b){return null===a?null===b?0:-1:null===b?1:null};tf.prototype.min=function(a,b){var c=this.Gb(a,b);null===c&&(c=tf.ab.min.call(this,a,b));return c};tf.prototype.max=function(a,b){var c=this.Gb(a,b);null===c&&(c=tf.ab.max.call(this,a,b));return c};function wf(a){this.va=a.map(function(a){return new of(a)})}t(wf,zc);function xf(a,b,c,d){for(var e=0,f=0;fc.c||d.w==c.c&&!d.la&&!c.ea}function md(){return new hd(F,F,!1,!1)}function jd(a){return a.c==F&&a.w==F}function nd(a){return a.c==a.w&&a.c!=F&&!a.ea&&!a.la}hd.prototype.contains=function(a){var b=this.w==F||athis.c||a==this.c&&!this.ea)&&b}; +function ld(a,b,c,d,e){function f(a){return c?a:1==a?-1:1}d=d||!1;e=e||!1;return a==F?b==F?(d?!e:e)?d?f(1):f(-1):0:f(-1):b==F?f(1):a=c[0]&&a<=c[1]});a.set("gte",function(a,c){return null===a||null===c?!1:a>=c});a.set("gt",function(a,c){return null===a||null===c?!1:a>c});a.set("in",function(a,c){return-1!=c.indexOf(a)});a.set("lte",function(a,c){return null===a||null===c?!1:a<=c});a.set("lt",function(a,c){return null===a||null===c?!1:a=c[0].getTime()&&a.getTime()<=c[1].getTime()});a.set("eq",function(a,c){return(null===a?-1:a.getTime())==(null===c?-1:c.getTime())});a.set("gte",function(a,c){return null===a||null===c?!1:a.getTime()>=c.getTime()});a.set("gt",function(a,c){return null===a||null===c?!1:a.getTime()>c.getTime()});a.set("in",function(a,c){return c.some(function(c){return c.getTime()==a.getTime()})});a.set("lte", +function(a,c){return null===a||null===c?!1:a.getTime()<=c.getTime()});a.set("lt",function(a,c){return null===a||null===c?!1:a.getTime()c&&(c=b[d]);a.ra().forEach(function(a){this.Sa.has(a.getName())||(b[a.getName()]=++c)},this);d=this.j.child("@table");return re(d,b)}.bind(this))}; +function se(a,b,c){var d=a.Sa.get(b);return null!=d?function(){var a={},b=x();this.j.orderByChild("T").equalTo(d).once("value",function(d){d.forEach(function(b){var d=c(b.val());a[parseInt(b.key(),10)]=d});b.resolve(a)});return b.da}.call(a).then(function(a){a["@rev"]={R:++this.La};return re(this.j,a)}.bind(a)):w()}M.prototype.tc=function(a){return se(this,a,l(null)).then(function(){this.Sa.delete(a);return re(this.j.child("@table/"+a),null,!0)}.bind(this))};M.prototype.dropTable=M.prototype.tc; +M.prototype.pc=function(a,b,c){return se(this,a,function(a){var e=a.P;e[b]=c;return{R:this.La+1,T:a.T,P:e}}.bind(this))};M.prototype.addTableColumn=M.prototype.pc;M.prototype.uc=function(a,b){return se(this,a,function(a){var d=a.P;delete d[b];return{R:this.La+1,T:a.T,P:d}}.bind(this))};M.prototype.dropTableColumn=M.prototype.uc;M.prototype.Jc=function(a,b,c){return se(this,a,function(a){var e=a.P;e[c]=e[b];delete e[b];return{R:this.La+1,T:a.T,P:e}}.bind(this))};M.prototype.renameTableColumn=M.prototype.Jc; +M.prototype.tb=function(){throw new E(351);};M.prototype.createRow=M.prototype.tb;M.prototype.Cc=g("Zb");M.prototype.getVersion=M.prototype.Cc;M.prototype.ec=function(a){var b=x();a=this.Sa.get(a);this.j.orderByChild("T").equalTo(a).once("value",function(a){var d=[];a.forEach(function(a){d.push(a.val().P)});b.resolve(d)});return b.da};M.prototype.dump=function(){var a={},b=Yb(this.Sa).map(function(b){return this.ec(b).then(function(d){a[b]=d})}.bind(this));return eb(b).then(function(){return a})}; +M.prototype.dump=M.prototype.dump;function te(a,b,c){$b.call(this,b,c);this.j=a}t(te,$b);te.prototype.H=function(a){return this.j.Ac(a)}; +te.prototype.rc=function(){if(0==this.pe)return this.S.resolve(),this.S.da;var a=this.Oa.rb;if(0==a.size)this.S.resolve();else{var b=this.j.La+1;this.j.La=b;var c={"@rev":{R:b}};a.forEach(function(a,e){var f=this.j.Sa.get(e);a.ua.forEach(function(a,d){c[d]={R:b,T:f,P:a.o}});a.ma.forEach(function(a,d){c[d]={R:b,T:f,P:a[1].o}});a.ya.forEach(function(a,b){c[b]=null})},this);this.j.j.update(c,function(c){null===c?this.S.resolve():(this.j.La=b-1,c=B(a).map(function(a){return ue(this.j,a.getName())},this), +eb(c).then(this.S.reject.bind(this.S),this.S.reject.bind(this.S)))}.bind(this))}return this.S.da};function ve(){this.xa=A()}function we(a,b){if(0==b.length)return B(a.xa);var c=[];b.forEach(function(a){a=this.xa.get(a)||null;null===a||c.push(a)},a);return c}ve.prototype.getData=g("xa");ve.prototype.get=function(a){return w(we(this,a))};function xe(a,b){b.forEach(function(a){this.xa.set(a.id(),a)},a)}ve.prototype.put=function(a){xe(this,a);return w()};function ye(a,b){0==b.length||b.length==a.xa.size?a.xa.clear():b.forEach(function(a){this.xa.delete(a)},a)} +ve.prototype.remove=function(a){ye(this,a);return w()};function ze(a){return 0==a.xa.size?0:Yb(a.xa).reduce(function(a,c){return a>c?a:c},0)};function Ae(a,b){this.i=a;this.xf=b;this.Ic=A();this.La=-1;this.L=A();this.Sa=A();this.Dd=null}m=Ae.prototype; +m.Ga=function(a){this.j=this.xf.child(this.i.name());var b=a||function(){return w()};return qe(this.j,"@db/version").then(function(a){return null===a?re(this.j,Be(this),!0).then(function(){var a=new M(0,this.j);return b(a)}.bind(this)):a==this.i.version()?qe(this.j,"@rev/R").then(function(a){this.La=a;return qe(this.j,"@table")}.bind(this)).then(function(a){for(var b in a)this.Sa.set(b,a[b]);a=this.i.ra().map(function(a){return ue(this,a.getName())},this);return eb(a)}.bind(this)).then(function(){Ce(this); +De(this);return w()}.bind(this)):this.be(a,b).then(function(){return this.Ga()}.bind(this))}.bind(this))};m.be=function(a,b){var c=new M(a,this.j);return c.Ga(this.i).then(function(){return w()}.bind(this)).then(function(){return b(c)}).then(function(){var a=this.j.child("@db");return re(a,{version:this.i.version()},!0)}.bind(this))}; +function De(a){a.j.off();a.j.on("child_removed",a.lg.bind(a));a.Ed&&(a.Ed.off(),a.Ic.clear());a.Ed=a.j.orderByChild("R").startAt(a.La+1);a.Ed.on("value",a.Zd.bind(a))}function Ce(a){pb=B(a.L).map(function(a){return ze(a)}).reduce(function(a,c){return a>c?a:c},0)+1}m.lg=function(a){var b=a.val(),c=this.Ic.get(b.T)||null;null===c&&(c=C(),this.Ic.set(b.T,c));c.add(parseInt(a.key(),10))}; +m.Zd=function(a){var b=a.child("@rev/R").val();null!=b&&b!=this.La&&(this.La=b,a=Ee(this,a),a.forEach(function(a){var b=this.L.get(a.getName()),e=Yb(a.ya);0this.i.version()?c.reject(new E(108)):c.resolve()}.bind(a));return c.da}m.Ab=function(a,b,c){if(null!=this.j)return new Ye(this.j,a,c);throw new E(2);};m.close=aa(); +m.Ac=function(){throw new E(512);};m.subscribe=function(){throw new E(355);};m.Fc=function(){throw new E(355);};m.be=function(a,b){var c=x();ef(this).then(function(){a(new P(this.h,b,this.j)).then(function(){return this.je()}.bind(this)).then(c.resolve.bind(c))}.bind(this),c.reject.bind(c));return c.da}; +function ef(a){var b=a.i.ra(),c=new Ye(a.j,1,new cd(a.h,C())),d=new Ye(a.j,1,new cd(a.h,C()));Xe(c,"INSERT OR REPLACE INTO __lf_ver VALUES (0, ?)",[a.i.version()]);bf(c);return c.ia().then(function(a){function c(a,b){Xe(d,"INSERT INTO "+a+"(id, value) VALUES(?, ?)",[-1,JSON.stringify(qb(new vb(new ub(b))))])}var h=a[1];h.filter(function(a){return-1!=a.indexOf("__d__")}).forEach(function(a){Xe(d,"DROP TABLE "+a,[])});var k=[],n=[],z=[];b.map(function(a){-1==h.indexOf(a.getName())&&k.push(a.getName()); +a.zb&&(a.Aa().forEach(function(a){a=Ze(a.m());k.push(a);n.push(a)}),a=Ze(Qe(a)),k.push(a),z.push(a))});k.forEach(function(a){Xe(d,"CREATE TABLE "+a+"(id INTEGER PRIMARY KEY, value TEXT)",[])});n.forEach(function(a){c(a,"btree")});z.forEach(function(a){c(a,"rowid")});return d.ia()})} +m.je=function(){var a=0,b=x(),c=function(b){var c=new Ye(this.j,0);Xe(c,"SELECT MAX(id) FROM "+b,[]);return c.ia().then(function(b){b=b[0].rows.item(0)[0];a=Math.max(b,a)})}.bind(this),d=this.i.ra().map(function(a){return c(a.getName())});eb(d).then(function(){b.resolve(a)},function(a){b.reject(a)});return b.da};function ff(a){this.Z=A();this.Yb=A();a.ra().forEach(function(a){this.Yb.set(a.getName(),C())},this)}m=ff.prototype;m.set=function(a,b){this.Z.set(b.id(),b);this.Yb.get(a).add(b.id())};m.Vb=function(a,b){var c=this.Yb.get(a);b.forEach(function(a){this.Z.set(a.id(),a);c.add(a.id())},this)};m.get=function(a){return this.Z.get(a)||null};function gf(a,b){return b.map(function(a){return this.get(a)},a)} +m.Xa=function(a,b,c){var d=[],e=Math.min(b,c),f=Math.max(b,c);a=this.Yb.get(a);if(a.size=e&&a<=f&&(a=this.Z.get(a),d.push(a))},this);else for(b=e;b<=f;++b)a.has(b)&&(c=this.Z.get(b),d.push(c));return d};m.remove=function(a,b){this.Z.delete(b);this.Yb.get(a).delete(b)};m.Ig=function(a){return null!=a?this.Yb.get(a).size:this.Z.size};m.clear=function(){this.Z.clear();this.Yb.clear()};function hf(a,b,c){var d=0,e=a.length;for(c=c||jf;d>1;0>c(a[f],b)?d=f+1:e=f}return d==e&&a[d]==b?d:~d}function jf(a,b){return a-b}function kf(a,b,c){c=hf(a,b,c);return 0>c?(a.splice(-(c+1),0,b),!0):!1};function mf(a,b,c,d){a=b?a.reverse():a;if(null==c&&null==d)return a;c=Math.min(q(c)?c:a.length,a.length);if(0==c)return[];d=Math.min(d||0,a.length);return a.slice(d,d+c)};function nf(a){this.Yc=0==a?of:pf;this.Xd=0==a?function(a){return null!=a?a.reverse():null}:function(a){return a||null};this.ce=0==a?qf:rf}t(nf,yc);function pf(a,b){return a>b?1:ab?1:a==b?0:-1};m.Ob=function(a,b){var c=this.sb(a,b);return c[0]&&c[1]};m.nf=function(a){return a.filter(function(a){return null!==a}).sort(function(a,c){return this.ce(a,c)}.bind(this))};m.Rd=function(a){return this.Xd(a).c==F};m.rd=function(a){a=this.Xd(a);return[a.c,a.w]};m.Xc=function(a){return null!==a};m.toString=function(){return this.compare==of?"SimpleComparator_DESC":"SimpleComparator_ASC"}; +function sf(a){nf.call(this,a);this.Yc=0==a?tf:uf}t(sf,nf);function uf(a,b){return null===a?null===b?0:-1:null===b?1:pf(a,b)}function tf(a,b){return uf(b,a)}sf.prototype.Ob=function(a,b){return null===a?jd(b):sf.ab.Ob.call(this,a,b)};sf.prototype.Gb=function(a,b){return null===a?null===b?0:-1:null===b?1:null};sf.prototype.min=function(a,b){var c=this.Gb(a,b);null===c&&(c=sf.ab.min.call(this,a,b));return c};sf.prototype.max=function(a,b){var c=this.Gb(a,b);null===c&&(c=sf.ab.max.call(this,a,b));return c};function vf(a){this.va=a.map(function(a){return new nf(a)})}t(vf,yc);function wf(a,b,c,d){for(var e=0,f=0;f=a)throw new E(6,a);d=Cf(this,d);this.qa=d=Df(d)}else this.clear()}var Ef=[];m=Bf.prototype;m.getName=g("u");m.toString=function(){return this.qa.toString()};m.add=function(a,b){this.qa=this.qa.xb(a,b)};m.set=function(a,b){this.qa=this.qa.xb(a,b,!0)};m.remove=function(a,b){this.qa=this.qa.remove(a,b)};m.get=function(a){return this.qa.get(a)}; -m.Zc=function(a){if(null==a)return this.Ma().na;if(a instanceof id){if(kd(a))return this.Ma().na;if(od(a))return this.get(a.c).length}return this.Xa([a]).length};m.Ma=g("pb");m.Md=function(a,b,c,d){c=Array(a);this.qa.fill({offset:b?this.pb.na-a-d:d,count:a,me:0},c);return b?c.reverse():c}; -m.Xa=function(a,b,c,d){var e=Ff(this.qa).b[0];if(!q(e)||0==c)return Ef;b=b||!1;c=null!=c?Math.min(c,this.pb.na):this.pb.na;d=d||0;var f=Math.min(Math.max(this.pb.na-d,0),c);if(0==f)return Ef;if(!q(a)||1==a.length&&a[0]instanceof id&&kd(a[0]))return this.Md(f,b,c,d);a=this.O.nf(a);var h=Array(b?this.pb.na:f),k={count:0,W:h.length,reverse:b,K:d},n=this.O instanceof yf;a.forEach(function(a){for(var b=this.O.qd(a),b=this.O.Rd(a)?e:b[0],b=Gf(this.qa,b),c=k.count,d=0;null!=b&&k.countk.count&&h.splice(k.count,h.length-k.count);return b?nf(h,b,c,d):h};m.clear=function(){this.qa=If(this);this.pb.clear()};m.fb=function(a){return this.qa.fb(a)};m.min=function(){return this.Gb(this.O.min.bind(this.O))}; -m.max=function(){return this.Gb(this.O.max.bind(this.O))};function Jf(a,b,c){if(!a.O.Xc(b.b[c]))if(1=b.b.length)b=b.sa,c=0;else{var d=Jf(this,b,c);if(null!==d){b=d;break a}c++}while(null!==b);b=null}a:{c=Kf(this.qa);d=c.b.length-1;do if(0>d)c=c.lb,d=0;else{var e=Jf(this,c,d);if(null!==e){c=e;break a}d--}while(null!==c);c=null}return null===b||null===c?null:1==a(b[0],c[0])?b:c};m.Ia=g("sf");m.dc=g("O");m.Vd=function(a,b){return null!=a?-1==this.O.compare(a,b):!1};m.Na=function(a,b){return null!=a?0==this.O.compare(a,b):!1}; -m.Fa=function(){for(var a=[],b=Ff(this.qa);b;)a.push(new y(b.oa,[b.b,b.A])),b=b.sa;return a};function Lf(a,b,c,d){a=new Bf(b,a,c);d=Mf(d,a);a.qa=d;return a}function Nf(a,b){this.oa=a;this.C=b;this.ib=0;this.sa=this.lb=this.B=null;this.b=[];this.A=[];this.g=[]}function If(a){return new Nf(qb++,a)}function Q(a){return 0==a.ib}m=Nf.prototype;m.next=g("sa"); -function Of(a){function b(a){return null!=a?a.oa.toString():"_"}var c=a.oa+"["+a.b.join("|")+"]",d=a.g.map(function(a){return a.oa}).join("|"),e=a.A.join("/"),f=b(a.lb)+"{",f=Q(a)?f+e:f+d,f=f+"}"+b(a.B);a.sa&&(a=Of(a.sa),c=c+" "+a[0],f=f+" "+a[1]);return[c,f]}m.toString=function(){var a="",b=Of(this),a=a+(b[0]+"\n"+b[1]+"\n");this.g.length&&(a+=this.g[0].toString());return a};function Ff(a){return Q(a)?a:Ff(a.g[0])}function Kf(a){return Q(a)?a:Kf(a.g[a.g.length-1])} -function Pf(a,b){b&&(b.lb=a);a&&(a.sa=b)}function Cf(a,b){for(var c=b.length,d=0,e=If(a),f=e;0=c?c:257,k=b.slice(d,d+h);e.b=k.map(function(a){return a.key});e.A=k.map(function(a){return a.value});d+=h;c-=h;0=c.length)b=Qf(c);else{var d=c.length,e=0,b=If(a.C);for(b.ib=a.ib+2;0=d?d:257;var f=c.slice(e,e+a),h=Qf(f);h.B=b;b.g.length&&(b.b.push(f[0].b[0]),Pf(b.g[b.g.length-1],h));b.g.push(h);e+=a;d-=a}}return b}m.get=function(a){var b=Rf(this,a);if(Q(this)){var c=Ef;this.C.Na(this.b[b],a)&&(c=c.concat(this.A[b]));return c}b=this.C.Na(this.b[b],a)?b+1:b;return this.g[b].get(a)}; -m.fb=function(a){var b=Rf(this,a);return this.C.Na(this.b[b],a)?!0:Q(this)?!1:this.g[b].fb(a)};m.remove=function(a,b){Sf(this,a,-1,b);if(null===this.B){var c=this;1==this.g.length&&(c=this.g[0],c.B=null);return c}return this};function Tf(a){return Q(a)?a.b[0]:Tf(a.g[0])}function Vf(a){a.b=[];for(var b=1;be&&a.C.Na(a.b[e],b)){if(q(d)&&!a.C.Ia()&&f&&(h=a.A[e],d=jf(h,d,void 0),0>d?d=!1:(h.splice(d,1),d=!0),d&&a.C.Ma().remove(b,1),a.A[e].length))return!1;a.b.splice(e,1);f&&(f=a.C.Ia()?1:a.A[e].length,a.A.splice(e,1),a.C.Ma().remove(b,f))}if(256>a.b.length&&null!==a.B){a:{b=null;if(a.sa&&256a.sa.b.length?(c=a.sa,e=d=0):a.lb&&(c=a.lb,d=c.b.length,e=Q(c)?c.A.length:c.g.length);d=[d,0].concat(a.b);Array.prototype.splice.apply(c.b,d);d=null;Q(a)?d=a.A:(d=a.g,d.forEach(function(a){a.B=c}));d=[e,0].concat(d);Array.prototype.splice.apply(Q(c)?c.A:c.g,d);Pf(a.lb,a.sa);Q(c)||Vf(c);-1!=b&&(a.B.b.splice(b,1),a.B.g.splice(b,1))} -m.xb=function(a,b,c){var d=Rf(this,a);if(Q(this)){if(this.C.Na(this.b[d],a)){if(c)this.C.Ma().remove(a,this.C.Ia()?1:this.A[d].length),this.A[d]=this.C.Ia()?b:[b];else{if(this.C.Ia())throw new E(201);if(!mf(this.A[d],b))throw new E(109);}this.C.Ma().add(a,1);return this}this.b.splice(d,0,a);this.A.splice(d,0,this.C.Ia()?b:[b]);this.C.Ma().add(a,1);512==this.b.length?(d=If(this.C),a=If(this.C),a.ib=1,a.b=[this.b[256]],a.g=[this,d],a.B=this.B,this.B=a,d.b=this.b.splice(256),d.A=this.A.splice(256),d.B= -a,Pf(d,this.sa),Pf(this,d),d=a):d=this;return d}d=this.C.Na(this.b[d],a)?d+1:d;a=this.g[d].xb(a,b,c);Q(a)||1!=a.b.length||(this.b.splice(d,0,a.b[0]),a.g[1].B=this,a.g[0].B=this,this.g.splice(d,1,a.g[1]),this.g.splice(d,0,a.g[0]));return 512==this.b.length?Xf(this):this};function Xf(a){var b=If(a.C),c=If(a.C);b.B=a.B;b.ib=a.ib+1;b.b=[a.b[256]];b.g=[a,c];a.b.splice(256,1);c.B=b;c.ib=a.ib;c.b=a.b.splice(256);c.g=a.g.splice(257);c.g.forEach(function(a){a.B=c});a.B=b;Pf(c,a.sa);Pf(a,c);return b} -function Rf(a,b){for(var c=0,d=a.b.length;c>1;a.C.Vd(a.b[e],b)?c=e+1:d=e}return c}function Gf(a,b){if(!Q(a)){var c=Rf(a,b);a.C.Na(a.b[c],b)&&c++;return Gf(a.g[c],b)}return a} -m.Xa=function(a,b,c){function d(a){return a[0]?a[1]?0:1:-1}var e=this.C.dc(),f=0,h=this.b.length-1,k=this.b,n=d(e.sb(k[f],a)),z=d(e.sb(k[h],a));if(1!=n&&(-1!=n||-1!=z)){var O=function(a,b){var c=a+b>>1;return c==a?c+1:c},ca=function(b,c,f){if(b>=c)return 0==f?c:-1;var h=d(e.sb(k[b],a));if(0==h)return b;if(1==h)return-1;h=O(b,c);if(h==c)return 0==f?c:-1;var n=d(e.sb(k[h],a));return 0==n?ca(b,h,n):-1==n?ca(h+1,c,f):ca(b+1,h,n)},Ab=function(b,c){if(b>=c)return b;var f=d(e.sb(k[c],a));if(0==f)return c; -if(-1==f)return b;f=O(b,c);if(f==c)return b;var h=d(e.sb(k[f],a));return 0==h?Ab(f,c):1==h?Ab(b,f-1):-1};0!=n&&(f=ca(f+1,h,z));-1!=f&&(h=Ab(f,h),-1!=h&&h>=f&&Yf(this,b,c,f,h+1))}};function Hf(a,b,c,d){if(a.C.Ia())!b.reverse&&b.K?b.K--:c[b.count++]=a.A[d];else for(var e=0;e=b.W));++d)Hf(a,b,c,d)} +m.rd=function(a){var b=a.map(function(a,b){return this.va[b].rd(a)[0]},this);a=a.map(function(a,b){return this.va[b].rd(a)[1]},this);return[b,a]};m.Xc=function(a){return a.every(function(a,c){return this.va[c].Xc(a)},this)};function xf(a){vf.call(this,a);this.va=a.map(function(a){return new sf(a)})}t(xf,vf);function yf(){this.na=0}yf.prototype.add=function(a,b){this.na+=b};yf.prototype.remove=function(a,b){this.na-=b};yf.prototype.clear=function(){this.na=0};function zf(a,b){a.clear();b.forEach(function(a){this.na+=a.na},a)};function Af(a,b,c,d){this.u=a;this.O=b;this.sf=c;this.pb=new yf;if(d){a=511;a*=a*a;if(d.length>=a)throw new E(6,a);d=Bf(this,d);this.qa=d=Cf(d)}else this.clear()}var Df=[];m=Af.prototype;m.getName=g("u");m.toString=function(){return this.qa.toString()};m.add=function(a,b){this.qa=this.qa.xb(a,b)};m.set=function(a,b){this.qa=this.qa.xb(a,b,!0)};m.remove=function(a,b){this.qa=this.qa.remove(a,b)};m.get=function(a){return this.qa.get(a)}; +m.Zc=function(a){if(null==a)return this.Ma().na;if(a instanceof hd){if(jd(a))return this.Ma().na;if(nd(a))return this.get(a.c).length}return this.Xa([a]).length};m.Ma=g("pb");m.Nd=function(a,b,c,d){c=Array(a);this.qa.fill({offset:b?this.pb.na-a-d:d,count:a,me:0},c);return b?c.reverse():c}; +m.Xa=function(a,b,c,d){var e=Ef(this.qa).b[0];if(!q(e)||0==c)return Df;b=b||!1;c=null!=c?Math.min(c,this.pb.na):this.pb.na;d=d||0;var f=Math.min(Math.max(this.pb.na-d,0),c);if(0==f)return Df;if(!q(a)||1==a.length&&a[0]instanceof hd&&jd(a[0]))return this.Nd(f,b,c,d);a=this.O.nf(a);var h=Array(b?this.pb.na:f),k={count:0,W:h.length,reverse:b,K:d},n=this.O instanceof xf;a.forEach(function(a){for(var b=this.O.rd(a),b=this.O.Rd(a)?e:b[0],b=Ff(this.qa,b),c=k.count,d=0;null!=b&&k.countk.count&&h.splice(k.count,h.length-k.count);return b?mf(h,b,c,d):h};m.clear=function(){this.qa=Hf(this);this.pb.clear()};m.fb=function(a){return this.qa.fb(a)};m.min=function(){return this.Gb(this.O.min.bind(this.O))}; +m.max=function(){return this.Gb(this.O.max.bind(this.O))};function If(a,b,c){if(!a.O.Xc(b.b[c]))if(1=b.b.length)b=b.sa,c=0;else{var d=If(this,b,c);if(null!==d){b=d;break a}c++}while(null!==b);b=null}a:{c=Jf(this.qa);d=c.b.length-1;do if(0>d)c=c.lb,d=0;else{var e=If(this,c,d);if(null!==e){c=e;break a}d--}while(null!==c);c=null}return null===b||null===c?null:1==a(b[0],c[0])?b:c};m.Ia=g("sf");m.dc=g("O");m.Vd=function(a,b){return null!=a?-1==this.O.compare(a,b):!1};m.Na=function(a,b){return null!=a?0==this.O.compare(a,b):!1}; +m.Fa=function(){for(var a=[],b=Ef(this.qa);b;)a.push(new y(b.oa,[b.b,b.A])),b=b.sa;return a};function Kf(a,b,c,d){a=new Af(b,a,c);d=Lf(d,a);a.qa=d;return a}function Mf(a,b){this.oa=a;this.C=b;this.ib=0;this.sa=this.lb=this.B=null;this.b=[];this.A=[];this.g=[]}function Hf(a){return new Mf(pb++,a)}function Q(a){return 0==a.ib}m=Mf.prototype;m.next=g("sa"); +function Nf(a){function b(a){return null!=a?a.oa.toString():"_"}var c=a.oa+"["+a.b.join("|")+"]",d=a.g.map(function(a){return a.oa}).join("|"),e=a.A.join("/"),f=b(a.lb)+"{",f=Q(a)?f+e:f+d,f=f+"}"+b(a.B);a.sa&&(a=Nf(a.sa),c=c+" "+a[0],f=f+" "+a[1]);return[c,f]}m.toString=function(){var a="",b=Nf(this),a=a+(b[0]+"\n"+b[1]+"\n");this.g.length&&(a+=this.g[0].toString());return a};function Ef(a){return Q(a)?a:Ef(a.g[0])}function Jf(a){return Q(a)?a:Jf(a.g[a.g.length-1])} +function Of(a,b){b&&(b.lb=a);a&&(a.sa=b)}function Bf(a,b){for(var c=b.length,d=0,e=Hf(a),f=e;0=c?c:257,k=b.slice(d,d+h);e.b=k.map(function(a){return a.key});e.A=k.map(function(a){return a.value});d+=h;c-=h;0=c.length)b=Pf(c);else{var d=c.length,e=0,b=Hf(a.C);for(b.ib=a.ib+2;0=d?d:257;var f=c.slice(e,e+a),h=Pf(f);h.B=b;b.g.length&&(b.b.push(f[0].b[0]),Of(b.g[b.g.length-1],h));b.g.push(h);e+=a;d-=a}}return b}m.get=function(a){var b=Qf(this,a);if(Q(this)){var c=Df;this.C.Na(this.b[b],a)&&(c=c.concat(this.A[b]));return c}b=this.C.Na(this.b[b],a)?b+1:b;return this.g[b].get(a)}; +m.fb=function(a){var b=Qf(this,a);return this.C.Na(this.b[b],a)?!0:Q(this)?!1:this.g[b].fb(a)};m.remove=function(a,b){Rf(this,a,-1,b);if(null===this.B){var c=this;1==this.g.length&&(c=this.g[0],c.B=null);return c}return this};function Sf(a){return Q(a)?a.b[0]:Sf(a.g[0])}function Uf(a){a.b=[];for(var b=1;be&&a.C.Na(a.b[e],b)){if(q(d)&&!a.C.Ia()&&f&&(h=a.A[e],d=hf(h,d,void 0),0>d?d=!1:(h.splice(d,1),d=!0),d&&a.C.Ma().remove(b,1),a.A[e].length))return!1;a.b.splice(e,1);f&&(f=a.C.Ia()?1:a.A[e].length,a.A.splice(e,1),a.C.Ma().remove(b,f))}if(256>a.b.length&&null!==a.B){a:{b=null;if(a.sa&&256a.sa.b.length?(c=a.sa,e=d=0):a.lb&&(c=a.lb,d=c.b.length,e=Q(c)?c.A.length:c.g.length);d=[d,0].concat(a.b);Array.prototype.splice.apply(c.b,d);d=null;Q(a)?d=a.A:(d=a.g,d.forEach(function(a){a.B=c}));d=[e,0].concat(d);Array.prototype.splice.apply(Q(c)?c.A:c.g,d);Of(a.lb,a.sa);Q(c)||Uf(c);-1!=b&&(a.B.b.splice(b,1),a.B.g.splice(b,1))} +m.xb=function(a,b,c){var d=Qf(this,a);if(Q(this)){if(this.C.Na(this.b[d],a)){if(c)this.C.Ma().remove(a,this.C.Ia()?1:this.A[d].length),this.A[d]=this.C.Ia()?b:[b];else{if(this.C.Ia())throw new E(201);if(!kf(this.A[d],b))throw new E(109);}this.C.Ma().add(a,1);return this}this.b.splice(d,0,a);this.A.splice(d,0,this.C.Ia()?b:[b]);this.C.Ma().add(a,1);512==this.b.length?(d=Hf(this.C),a=Hf(this.C),a.ib=1,a.b=[this.b[256]],a.g=[this,d],a.B=this.B,this.B=a,d.b=this.b.splice(256),d.A=this.A.splice(256),d.B= +a,Of(d,this.sa),Of(this,d),d=a):d=this;return d}d=this.C.Na(this.b[d],a)?d+1:d;a=this.g[d].xb(a,b,c);Q(a)||1!=a.b.length||(this.b.splice(d,0,a.b[0]),a.g[1].B=this,a.g[0].B=this,this.g.splice(d,1,a.g[1]),this.g.splice(d,0,a.g[0]));return 512==this.b.length?Wf(this):this};function Wf(a){var b=Hf(a.C),c=Hf(a.C);b.B=a.B;b.ib=a.ib+1;b.b=[a.b[256]];b.g=[a,c];a.b.splice(256,1);c.B=b;c.ib=a.ib;c.b=a.b.splice(256);c.g=a.g.splice(257);c.g.forEach(function(a){a.B=c});a.B=b;Of(c,a.sa);Of(a,c);return b} +function Qf(a,b){for(var c=0,d=a.b.length;c>1;a.C.Vd(a.b[e],b)?c=e+1:d=e}return c}function Ff(a,b){if(!Q(a)){var c=Qf(a,b);a.C.Na(a.b[c],b)&&c++;return Ff(a.g[c],b)}return a} +m.Xa=function(a,b,c){function d(a){return a[0]?a[1]?0:1:-1}var e=this.C.dc(),f=0,h=this.b.length-1,k=this.b,n=d(e.sb(k[f],a)),z=d(e.sb(k[h],a));if(1!=n&&(-1!=n||-1!=z)){var O=function(a,b){var c=a+b>>1;return c==a?c+1:c},ca=function(b,c,f){if(b>=c)return 0==f?c:-1;var h=d(e.sb(k[b],a));if(0==h)return b;if(1==h)return-1;h=O(b,c);if(h==c)return 0==f?c:-1;var n=d(e.sb(k[h],a));return 0==n?ca(b,h,n):-1==n?ca(h+1,c,f):ca(b+1,h,n)},zb=function(b,c){if(b>=c)return b;var f=d(e.sb(k[c],a));if(0==f)return c; +if(-1==f)return b;f=O(b,c);if(f==c)return b;var h=d(e.sb(k[f],a));return 0==h?zb(f,c):1==h?zb(b,f-1):-1};0!=n&&(f=ca(f+1,h,z));-1!=f&&(h=zb(f,h),-1!=h&&h>=f&&Xf(this,b,c,f,h+1))}};function Gf(a,b,c,d){if(a.C.Ia())!b.reverse&&b.K?b.K--:c[b.count++]=a.A[d];else for(var e=0;e=b.W));++d)Gf(a,b,c,d)} m.fill=function(a,b){if(Q(this))for(var c=0;ca.offset)for(var d=this.A[c].length+a.offset;de.entries.length){a:{b=a.ha;a.ha=a.ka;a.ka=b;b=a.F;switch(a.F){case "gt":b="lt";break;case "lt":b="gt";break;case "gte":b="lte";break;case "lte":b="gte";break;default:break a}a.F=b;a.vc=Jd(Dd.zc(),a.ha.G(),a.F)}return[e,d]}return[d,e]}function Ag(a){var b={};a.gb().forEach(function(a){b[a.getName()]=null});return b} -function Bg(a,b,c){null===a.Yd&&(a.Yd=Ag(a.ka.H()));var d=new yd(new y(-1,a.Yd),!1);return Bd(b,c,d,[J(a.ka.H())])} -function Cg(a,b,c,d){var e=[b,c];d||(e=zg(a,b,c));b=e[0];c=e[1];var e=b,f=c,h=a.ha,k=a.ka;d&&(e=c,f=b,h=a.ka,k=a.ha);var n=new Lc,z=[];e.entries.forEach(function(a){var b=String(I(a,h));n.set(b,a)});var O=H(e),ca=H(f);f.entries.forEach(function(a){var b=I(a,k),c=String(b);null!==b&&n.has(c)?n.get(c).forEach(function(b){b=Bd(a,ca,b,O);z.push(b)}):d&&z.push(Bg(this,a,ca))}.bind(a));a=H(b).concat(H(c));return new G(z,a)} -function Dg(a,b,c,d,e){function f(a,b){var c=new yd(b,1a?b:a});break;case "DISTINCT":d=Tg(b,c);break;case "COUNT":d=Ug(b,c);break;case "SUM":d=Vg(b,c);break;case "AVG":a=Ug(b,c);0b.c.length)return a;this.$=a;this.Ta(this.$);return this.$};rh.prototype.Ta=function(a){if(a instanceof fh)for(;2c;c++){var d=Pd(a,0);Od(b,d)}Nd(a,b,0)}L(a).forEach(function(a){this.Ta(a)},this)};function sh(){T.call(this,0,0)}t(sh,T);sh.prototype.toString=l("cross_product");sh.prototype.fa=function(a){var b=a[0],c=a[1];a=[];for(var d=H(b),e=H(c),f=0;f=";case "gt":return">";case "in":return"IN";case "lte":return"<=";case "lt":return"<";case "match":return"LIKE";case "neq":return"<>";default:return"UNKNOWN"}}function Gh(a,b,c,d){return a instanceof Cd?"?"+a.za().toString():d?null!=a?"#":"NULL":"match"==b?"'"+a.toString()+"'":"in"==b?"("+a.map(function(a){return Dh(c,a)}).join(", ")+")":"between"==b?Dh(c,a[0])+" AND "+Dh(c,a[1]):Dh(c,a).toString()} -function Hh(a,b){return L(a).map(function(a){return"("+Ih(a,b)+")"}).join("and"==a.Rb?" AND ":" OR ")}function Jh(a){return[a.ha.m(),Fh(a.F),a.ka.m()].join(" ")}function Ih(a,b){if(a instanceof Ud){var c=a.M.m(),d=Fh(a.F),e=Gh(a.value,a.F,a.M.G(),b);return"="==d&&"NULL"==e?[c,"IS NULL"].join(" "):"<>"==d&&"NULL"==e?[c,"IS NOT NULL"].join(" "):[c,d,e].join(" ")}if(a instanceof wg)return Hh(a,b);if(a instanceof yg)return Jh(a);throw new E(357,typeof a);} -function Kh(a,b){var c=Ih(a,b);return c?" WHERE "+c:""}function Lh(a,b){var c="UPDATE "+a.table.getName()+" SET ",c=c+a.set.map(function(a){var b=a.M.m()+" = ";return-1!=a.Sc?b+"?"+a.Sc.toString():b+Dh(a.M.G(),a.value).toString()}).join(", ");a.s&&(c+=Kh(a.s,b));return c+";"} -function Mh(a,b){var c="*";a.f.length&&(c=a.f.map(function(a){return a.Wa()?a.m()+" AS "+a.Wa():a.m()}).join(", "));c="SELECT "+c+" FROM ";null!=a.yb&&0!=a.yb.size?c+=Nh(a,b):(c+=a.c.map(Oh).join(", "),a.s&&(c+=Kh(a.s,b)));if(a.N)var d=a.N.map(function(a){return a.M.m()+(0==a.kb?" DESC":" ASC")}).join(", "),c=c+(" ORDER BY "+d);a.ja&&(d=a.ja.map(function(a){return a.m()}).join(", "),c+=" GROUP BY "+d);a.W&&(c+=" LIMIT "+a.W.toString());a.K&&(c+=" SKIP "+a.K.toString());return c+";"} -function Oh(a){return J(a)!=a.getName()?a.getName()+" AS "+J(a):a.getName()}function Nh(a,b){for(var c=pg(a.s,function(a){return a instanceof yg}),d=c.map(Jh),e=Oh(a.c[0]),f=1;fa)throw new E(531);this.a.W=a}return this};V.prototype.limit=V.prototype.W;V.prototype.K=function(a){if(null!=(this.a.K||this.a.Xb))throw new E(529);if(a instanceof Cd)this.a.Xb=a;else{if(0>a)throw new E(531);this.a.K=a}return this};V.prototype.skip=V.prototype.K;V.prototype.N=function(a,b){$h(this,549);null==this.a.N&&(this.a.N=[]);this.a.N.push({M:a,kb:null!=b?b:1});return this}; -V.prototype.orderBy=V.prototype.N;V.prototype.ja=function(a){$h(this,549);if(null!=this.a.ja)throw new E(530);null==this.a.ja&&(this.a.ja=[]);this.a.ja.push.apply(this.a.ja,Array.prototype.slice.call(arguments));return this};V.prototype.groupBy=V.prototype.ja;function Zh(a,b){switch(a){case "COUNT":case "DISTINCT":return!0;case "AVG":case "GEOMEAN":case "STDDEV":case "SUM":return 4==b||3==b;case "MAX":case "MIN":return 4==b||3==b||5==b||2==b}return!1} -V.prototype.clone=function(){var a=new V(this.global,this.a.f);a.a=this.a.clone();a.a.Wc=null;return a};V.prototype.clone=V.prototype.clone;function bi(a,b){U.call(this,a,new Ah(a.j(oc)));this.a.table=b}t(bi,U);r("lf.query.UpdateBuilder",bi);bi.prototype.set=function(a,b){var c={Sc:b instanceof Cd?b.za():-1,M:a,value:b};null!=this.a.set?this.a.set.push(c):this.a.set=[c];return this};bi.prototype.set=bi.prototype.set;bi.prototype.s=function(a){this.zd();this.a.s=a;return this};bi.prototype.where=bi.prototype.s;bi.prototype.zd=function(){if(null!=this.a.s)throw new E(516);}; -bi.prototype.cb=function(){bi.ab.cb.call(this);if(null==this.a.set)throw new E(532);if(this.a.set.some(function(a){return a.value instanceof Cd}))throw new E(501);};function ci(a){this.a=a;this.Da=null}ci.prototype.hc=function(){null===this.Da&&(this.Da=this.ad());return this.Da};function di(a){ci.call(this,a)}t(di,ci);di.prototype.ad=function(){return this.a.$b?new ah(this.a.Ha,this.a.values):new $g(this.a.Ha,this.a.values)};function ei(a){ci.call(this,a)}t(ei,ci);ei.prototype.ad=function(){var a=new ch(this.a.table,this.a.set),b=null!=this.a.s?new dh(this.a.s.Kb()):null,c=new eh(this.a.table);null===b?Od(a,c):(Od(b,c),Od(a,b));return a};function fi(a,b,c){this.Da=a;this.ee=b;this.Ub=c}fi.prototype.hc=function(){this.Ub.forEach(function(a){this.Da=a.nb(this.Da,this.ee)},this);return this.Da};function gi(a,b){ci.call(this,a);this.Ub=b}t(gi,ci);gi.prototype.ad=function(){var a=new bh(this.a.c),b=null!=this.a.s?new dh(this.a.s.Kb()):null,c=new eh(this.a.c);null===b?Od(a,c):(Od(b,c),Od(a,b));return(new fi(a,this.a,this.Ub)).hc()};function hi(){}t(hi,nh);hi.prototype.nb=function(a,b){if(2>b.c.length)return a;this.$=a;this.Ta(this.$,b);return this.$};hi.prototype.Ta=function(a,b){if(a instanceof dh&&a.I instanceof yg){var c=a.I.Y(),d=Md(a,0);d instanceof fh&&(c=null!=b.yb&&b.yb.has(c),c=new mh(a.I,c),ug(a,d,c,c),a==this.$&&(this.$=c),a=c)}L(a).forEach(function(a){this.Ta(a,b)},this)};function ii(){this.Rc=C()}t(ii,nh);ii.prototype.nb=function(a,b){this.Rc.clear();if(!q(b.s))return a;this.$=a;this.Ta(this.$);this.Rc.clear();return this.$};ii.prototype.Ta=function(a){if(ji(a)){var b=a.I instanceof Ud?ki(this,a):li(this,a);this.Rc.add(a);b==a&&(b=Md(a,0));null!==b&&(fa(b.getParent())&&(this.$=b),ji(b)&&!this.Rc.has(b)&&this.Ta(b))}else L(a).forEach(function(a){this.Ta(a)},this)}; -function mi(a,b,c){var d=b;if(Md(b,0)instanceof dh)d=sg(b),mi(a,b,c);else if(ni(b)){var e=[],d=tg(b,c,function(a){a=new dh(a.I);e.push(a);return a});e.forEach(function(a){mi(this,a,c)},a)}return d}function ki(a,b){var c=C([J(b.I.M.H())]),d=function(a){return oi(this,a,c)}.bind(a);return mi(a,b,d)}function li(a,b){var c=C([J(b.I.ha.H()),J(b.I.ka.H())]),d=function(a){return oi(this,a,c)}.bind(a);return mi(a,b,d)} -function oi(a,b,c){var d=C();og(b).forEach(function(a){d.add(J(a.table))},a);b instanceof eh&&d.add(J(b.table));return pc(d,c)}function ji(a){return a instanceof dh&&!(a.I instanceof wg)}function ni(a){a=Md(a,0);return a instanceof fh||a instanceof mh};function pi(a,b){ci.call(this,a);this.Ub=b;this.df=this.Ve=this.mf=this.Ye=this.ye=this.Ke=this.lf=this.Ee=this.of=null}t(pi,ci); -pi.prototype.ad=function(){qi(this);2<=this.a.c.length&&(this.Ee=new fh);this.lf=null!=this.a.s?new dh(this.a.s.Kb()):null;this.a.N&&(this.Ye=new hh(this.a.N));null!=this.a.K&&0>8,O=0;Oe?1:0;return 1==c?d:-d};m.vg=function(a,b){return this.O(function(b){return b instanceof S?sd(a,b):I(a.entries[a.entries.length-1],b)},function(a){return a instanceof S?sd(b,a):I(b.entries[b.entries.length-1],a)})};m.Lf=function(a,b){return this.O(function(b){return I(a,b)},function(a){return I(b,a)})};function bj(a,b){this.Ja=a;this.J=b}function cj(a){return a.J.some(function(a){return a instanceof S},a)?dj(a):ej(a)}function dj(a){if(1==a.J.length&&"DISTINCT"==a.J[0].Jb)return a=sd(a.Ja,a.J[0]).entries.map(function(a){var b=new yd(new y(-1,{}),1b.getPriority()||2>b.getPriority())&&Cj(a.Ec,b.ca());a.Tb.xb(b);Fj(a);return b.Lb().da}function Fj(a){for(var b=a.Tb.Eb(),c=0;ce.entries.length){a:{b=a.ha;a.ha=a.ka;a.ka=b;b=a.F;switch(a.F){case "gt":b="lt";break;case "lt":b="gt";break;case "gte":b="lte";break;case "lte":b="gte";break;default:break a}a.F=b;a.vc=Id(Cd.zc(),a.ha.G(),a.F)}return[e,d]}return[d,e]}function zg(a){var b={};a.gb().forEach(function(a){b[a.getName()]=null});return b} +function Ag(a,b,c){null===a.Yd&&(a.Yd=zg(a.ka.H()));var d=new xd(new y(-1,a.Yd),!1);return Ad(b,c,d,[J(a.ka.H())])} +function Bg(a,b,c,d){var e=[b,c];d||(e=yg(a,b,c));b=e[0];c=e[1];var e=b,f=c,h=a.ha,k=a.ka;d&&(e=c,f=b,h=a.ka,k=a.ha);var n=new Kc,z=[];e.entries.forEach(function(a){var b=String(I(a,h));n.set(b,a)});var O=H(e),ca=H(f);f.entries.forEach(function(a){var b=I(a,k),c=String(b);null!==b&&n.has(c)?n.get(c).forEach(function(b){b=Ad(a,ca,b,O);z.push(b)}):d&&z.push(Ag(this,a,ca))}.bind(a));a=H(b).concat(H(c));return new G(z,a)} +function Cg(a,b,c,d,e){function f(a,b){var c=new xd(b,1a?b:a});break;case "DISTINCT":d=Sg(b,c);break;case "COUNT":d=Tg(b,c);break;case "SUM":d=Ug(b,c);break;case "AVG":a=Tg(b,c);0b.c.length)return a;this.$=a;this.Ta(this.$);return this.$};qh.prototype.Ta=function(a){if(a instanceof eh)for(;2c;c++){var d=Od(a,0);Nd(b,d)}Md(a,b,0)}L(a).forEach(function(a){this.Ta(a)},this)};function rh(){T.call(this,0,0)}t(rh,T);rh.prototype.toString=l("cross_product");rh.prototype.fa=function(a){var b=a[0],c=a[1];a=[];for(var d=H(b),e=H(c),f=0;f=";case "gt":return">";case "in":return"IN";case "lte":return"<=";case "lt":return"<";case "match":return"LIKE";case "neq":return"<>";default:return"UNKNOWN"}}function Fh(a,b,c,d){return a instanceof Bd?"?"+a.za().toString():d?null!=a?"#":"NULL":"match"==b?"'"+a.toString()+"'":"in"==b?"("+a.map(function(a){return Ch(c,a)}).join(", ")+")":"between"==b?Ch(c,a[0])+" AND "+Ch(c,a[1]):Ch(c,a).toString()} +function Gh(a,b){return L(a).map(function(a){return"("+Hh(a,b)+")"}).join("and"==a.Rb?" AND ":" OR ")}function Ih(a){return[a.ha.m(),Eh(a.F),a.ka.m()].join(" ")}function Hh(a,b){if(a instanceof Td){var c=a.M.m(),d=Eh(a.F),e=Fh(a.value,a.F,a.M.G(),b);return"="==d&&"NULL"==e?[c,"IS NULL"].join(" "):"<>"==d&&"NULL"==e?[c,"IS NOT NULL"].join(" "):[c,d,e].join(" ")}if(a instanceof vg)return Gh(a,b);if(a instanceof xg)return Ih(a);throw new E(357,typeof a);} +function Jh(a,b){var c=Hh(a,b);return c?" WHERE "+c:""}function Kh(a,b){var c="UPDATE "+a.table.getName()+" SET ",c=c+a.set.map(function(a){var b=a.M.m()+" = ";return-1!=a.Sc?b+"?"+a.Sc.toString():b+Ch(a.M.G(),a.value).toString()}).join(", ");a.s&&(c+=Jh(a.s,b));return c+";"} +function Lh(a,b){var c="*";a.f.length&&(c=a.f.map(function(a){return a.Wa()?a.m()+" AS "+a.Wa():a.m()}).join(", "));c="SELECT "+c+" FROM ";null!=a.yb&&0!=a.yb.size?c+=Mh(a,b):(c+=a.c.map(Nh).join(", "),a.s&&(c+=Jh(a.s,b)));if(a.N)var d=a.N.map(function(a){return a.M.m()+(0==a.kb?" DESC":" ASC")}).join(", "),c=c+(" ORDER BY "+d);a.ja&&(d=a.ja.map(function(a){return a.m()}).join(", "),c+=" GROUP BY "+d);a.W&&(c+=" LIMIT "+a.W.toString());a.K&&(c+=" SKIP "+a.K.toString());return c+";"} +function Nh(a){return J(a)!=a.getName()?a.getName()+" AS "+J(a):a.getName()}function Mh(a,b){for(var c=og(a.s,function(a){return a instanceof xg}),d=c.map(Ih),e=Nh(a.c[0]),f=1;fa)throw new E(531);this.a.W=a}return this};V.prototype.limit=V.prototype.W;V.prototype.K=function(a){if(null!=(this.a.K||this.a.Xb))throw new E(529);if(a instanceof Bd)this.a.Xb=a;else{if(0>a)throw new E(531);this.a.K=a}return this};V.prototype.skip=V.prototype.K;V.prototype.N=function(a,b){Zh(this,549);null==this.a.N&&(this.a.N=[]);this.a.N.push({M:a,kb:null!=b?b:1});return this}; +V.prototype.orderBy=V.prototype.N;V.prototype.ja=function(a){Zh(this,549);if(null!=this.a.ja)throw new E(530);null==this.a.ja&&(this.a.ja=[]);this.a.ja.push.apply(this.a.ja,Array.prototype.slice.call(arguments));return this};V.prototype.groupBy=V.prototype.ja;function Yh(a,b){switch(a){case "COUNT":case "DISTINCT":return!0;case "AVG":case "GEOMEAN":case "STDDEV":case "SUM":return 4==b||3==b;case "MAX":case "MIN":return 4==b||3==b||5==b||2==b}return!1} +V.prototype.clone=function(){var a=new V(this.global,this.a.f);a.a=this.a.clone();a.a.Wc=null;return a};V.prototype.clone=V.prototype.clone;function ai(a,b){U.call(this,a,new zh(a.l(nc)));this.a.table=b}t(ai,U);r("lf.query.UpdateBuilder",ai);ai.prototype.set=function(a,b){var c={Sc:b instanceof Bd?b.za():-1,M:a,value:b};null!=this.a.set?this.a.set.push(c):this.a.set=[c];return this};ai.prototype.set=ai.prototype.set;ai.prototype.s=function(a){this.Ad();this.a.s=a;return this};ai.prototype.where=ai.prototype.s;ai.prototype.Ad=function(){if(null!=this.a.s)throw new E(516);}; +ai.prototype.cb=function(){ai.ab.cb.call(this);if(null==this.a.set)throw new E(532);if(this.a.set.some(function(a){return a.value instanceof Bd}))throw new E(501);};function bi(a){this.a=a;this.Da=null}bi.prototype.hc=function(){null===this.Da&&(this.Da=this.ad());return this.Da};function ci(a){bi.call(this,a)}t(ci,bi);ci.prototype.ad=function(){return this.a.$b?new $g(this.a.Ha,this.a.values):new Zg(this.a.Ha,this.a.values)};function di(a){bi.call(this,a)}t(di,bi);di.prototype.ad=function(){var a=new bh(this.a.table,this.a.set),b=null!=this.a.s?new ch(this.a.s.Kb()):null,c=new dh(this.a.table);null===b?Nd(a,c):(Nd(b,c),Nd(a,b));return a};function ei(a,b,c){this.Da=a;this.ee=b;this.Ub=c}ei.prototype.hc=function(){this.Ub.forEach(function(a){this.Da=a.nb(this.Da,this.ee)},this);return this.Da};function fi(a,b){bi.call(this,a);this.Ub=b}t(fi,bi);fi.prototype.ad=function(){var a=new ah(this.a.c),b=null!=this.a.s?new ch(this.a.s.Kb()):null,c=new dh(this.a.c);null===b?Nd(a,c):(Nd(b,c),Nd(a,b));return(new ei(a,this.a,this.Ub)).hc()};function gi(){}t(gi,mh);gi.prototype.nb=function(a,b){if(2>b.c.length)return a;this.$=a;this.Ta(this.$,b);return this.$};gi.prototype.Ta=function(a,b){if(a instanceof ch&&a.I instanceof xg){var c=a.I.Y(),d=Ld(a,0);d instanceof eh&&(c=null!=b.yb&&b.yb.has(c),c=new lh(a.I,c),tg(a,d,c,c),a==this.$&&(this.$=c),a=c)}L(a).forEach(function(a){this.Ta(a,b)},this)};function hi(){this.Rc=C()}t(hi,mh);hi.prototype.nb=function(a,b){this.Rc.clear();if(!q(b.s))return a;this.$=a;this.Ta(this.$);this.Rc.clear();return this.$};hi.prototype.Ta=function(a){if(ii(a)){var b=a.I instanceof Td?ji(this,a):ki(this,a);this.Rc.add(a);b==a&&(b=Ld(a,0));null!==b&&(fa(b.getParent())&&(this.$=b),ii(b)&&!this.Rc.has(b)&&this.Ta(b))}else L(a).forEach(function(a){this.Ta(a)},this)}; +function li(a,b,c){var d=b;if(Ld(b,0)instanceof ch)d=rg(b),li(a,b,c);else if(mi(b)){var e=[],d=sg(b,c,function(a){a=new ch(a.I);e.push(a);return a});e.forEach(function(a){li(this,a,c)},a)}return d}function ji(a,b){var c=C([J(b.I.M.H())]),d=function(a){return ni(this,a,c)}.bind(a);return li(a,b,d)}function ki(a,b){var c=C([J(b.I.ha.H()),J(b.I.ka.H())]),d=function(a){return ni(this,a,c)}.bind(a);return li(a,b,d)} +function ni(a,b,c){var d=C();ng(b).forEach(function(a){d.add(J(a.table))},a);b instanceof dh&&d.add(J(b.table));return oc(d,c)}function ii(a){return a instanceof ch&&!(a.I instanceof vg)}function mi(a){a=Ld(a,0);return a instanceof eh||a instanceof lh};function oi(a,b){bi.call(this,a);this.Ub=b;this.df=this.Ve=this.mf=this.Ye=this.ye=this.Ke=this.lf=this.Ee=this.of=null}t(oi,bi); +oi.prototype.ad=function(){pi(this);2<=this.a.c.length&&(this.Ee=new eh);this.lf=null!=this.a.s?new ch(this.a.s.Kb()):null;this.a.N&&(this.Ye=new gh(this.a.N));null!=this.a.K&&0>8,O=0;Oe?1:0;return 1==c?d:-d};m.vg=function(a,b){return this.O(function(b){return b instanceof S?rd(a,b):I(a.entries[a.entries.length-1],b)},function(a){return a instanceof S?rd(b,a):I(b.entries[b.entries.length-1],a)})};m.Lf=function(a,b){return this.O(function(b){return I(a,b)},function(a){return I(b,a)})};function aj(a,b){this.Ja=a;this.J=b}function bj(a){return a.J.some(function(a){return a instanceof S},a)?cj(a):dj(a)}function cj(a){if(1==a.J.length&&"DISTINCT"==a.J[0].Jb)return a=rd(a.Ja,a.J[0]).entries.map(function(a){var b=new xd(new y(-1,{}),1b.getPriority()||2>b.getPriority())&&Bj(a.Ec,b.ca());a.Tb.xb(b);Ej(a);return b.Lb().da}function Ej(a){for(var b=a.Tb.Eb(),c=0;c opt_fromIndex ? Math.max(0, arr.length + opt_fromIndex) : opt_fromIndex; if (goog.isString(arr)) { @@ -1273,10 +1272,10 @@ goog.array.indexOf = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_F } return -1; }; -goog.array.lastIndexOf = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || goog.array.ARRAY_PROTOTYPE_.lastIndexOf) ? function(arr, obj, opt_fromIndex) { +goog.array.lastIndexOf = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.lastIndexOf) ? function(arr, obj, opt_fromIndex) { goog.asserts.assert(null != arr.length); var fromIndex = null == opt_fromIndex ? arr.length - 1 : opt_fromIndex; - return goog.array.ARRAY_PROTOTYPE_.lastIndexOf.call(arr, obj, fromIndex); + return Array.prototype.lastIndexOf.call(arr, obj, fromIndex); } : function(arr, obj, opt_fromIndex) { var fromIndex = null == opt_fromIndex ? arr.length - 1 : opt_fromIndex; 0 > fromIndex && (fromIndex = Math.max(0, arr.length + fromIndex)); @@ -1290,9 +1289,9 @@ goog.array.lastIndexOf = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATI } return -1; }; -goog.array.forEach = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || goog.array.ARRAY_PROTOTYPE_.forEach) ? function(arr, f, opt_obj) { +goog.array.forEach = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.forEach) ? function(arr, f, opt_obj) { goog.asserts.assert(null != arr.length); - goog.array.ARRAY_PROTOTYPE_.forEach.call(arr, f, opt_obj); + Array.prototype.forEach.call(arr, f, opt_obj); } : function(arr, f, opt_obj) { for (var l = arr.length, arr2 = goog.isString(arr) ? arr.split("") : arr, i = 0;i < l;i++) { i in arr2 && f.call(opt_obj, arr2[i], i, arr); @@ -1303,9 +1302,9 @@ goog.array.forEachRight = function(arr, f, opt_obj) { i in arr2 && f.call(opt_obj, arr2[i], i, arr); } }; -goog.array.filter = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || goog.array.ARRAY_PROTOTYPE_.filter) ? function(arr, f, opt_obj) { +goog.array.filter = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.filter) ? function(arr, f, opt_obj) { goog.asserts.assert(null != arr.length); - return goog.array.ARRAY_PROTOTYPE_.filter.call(arr, f, opt_obj); + return Array.prototype.filter.call(arr, f, opt_obj); } : function(arr, f, opt_obj) { for (var l = arr.length, res = [], resLength = 0, arr2 = goog.isString(arr) ? arr.split("") : arr, i = 0;i < l;i++) { if (i in arr2) { @@ -1315,19 +1314,19 @@ goog.array.filter = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FU } return res; }; -goog.array.map = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || goog.array.ARRAY_PROTOTYPE_.map) ? function(arr, f, opt_obj) { +goog.array.map = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.map) ? function(arr, f, opt_obj) { goog.asserts.assert(null != arr.length); - return goog.array.ARRAY_PROTOTYPE_.map.call(arr, f, opt_obj); + return Array.prototype.map.call(arr, f, opt_obj); } : function(arr, f, opt_obj) { for (var l = arr.length, res = Array(l), arr2 = goog.isString(arr) ? arr.split("") : arr, i = 0;i < l;i++) { i in arr2 && (res[i] = f.call(opt_obj, arr2[i], i, arr)); } return res; }; -goog.array.reduce = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || goog.array.ARRAY_PROTOTYPE_.reduce) ? function(arr, f, val, opt_obj) { +goog.array.reduce = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.reduce) ? function(arr, f, val, opt_obj) { goog.asserts.assert(null != arr.length); opt_obj && (f = goog.bind(f, opt_obj)); - return goog.array.ARRAY_PROTOTYPE_.reduce.call(arr, f, val); + return Array.prototype.reduce.call(arr, f, val); } : function(arr, f, val$$0, opt_obj) { var rval = val$$0; goog.array.forEach(arr, function(val, index) { @@ -1335,10 +1334,10 @@ goog.array.reduce = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FU }); return rval; }; -goog.array.reduceRight = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || goog.array.ARRAY_PROTOTYPE_.reduceRight) ? function(arr, f, val, opt_obj) { +goog.array.reduceRight = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.reduceRight) ? function(arr, f, val, opt_obj) { goog.asserts.assert(null != arr.length); opt_obj && (f = goog.bind(f, opt_obj)); - return goog.array.ARRAY_PROTOTYPE_.reduceRight.call(arr, f, val); + return Array.prototype.reduceRight.call(arr, f, val); } : function(arr, f, val$$0, opt_obj) { var rval = val$$0; goog.array.forEachRight(arr, function(val, index) { @@ -1346,9 +1345,9 @@ goog.array.reduceRight = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATI }); return rval; }; -goog.array.some = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || goog.array.ARRAY_PROTOTYPE_.some) ? function(arr, f, opt_obj) { +goog.array.some = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.some) ? function(arr, f, opt_obj) { goog.asserts.assert(null != arr.length); - return goog.array.ARRAY_PROTOTYPE_.some.call(arr, f, opt_obj); + return Array.prototype.some.call(arr, f, opt_obj); } : function(arr, f, opt_obj) { for (var l = arr.length, arr2 = goog.isString(arr) ? arr.split("") : arr, i = 0;i < l;i++) { if (i in arr2 && f.call(opt_obj, arr2[i], i, arr)) { @@ -1357,9 +1356,9 @@ goog.array.some = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNC } return !1; }; -goog.array.every = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || goog.array.ARRAY_PROTOTYPE_.every) ? function(arr, f, opt_obj) { +goog.array.every = goog.NATIVE_ARRAY_PROTOTYPES && (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.every) ? function(arr, f, opt_obj) { goog.asserts.assert(null != arr.length); - return goog.array.ARRAY_PROTOTYPE_.every.call(arr, f, opt_obj); + return Array.prototype.every.call(arr, f, opt_obj); } : function(arr, f, opt_obj) { for (var l = arr.length, arr2 = goog.isString(arr) ? arr.split("") : arr, i = 0;i < l;i++) { if (i in arr2 && !f.call(opt_obj, arr2[i], i, arr)) { @@ -1433,7 +1432,7 @@ goog.array.remove = function(arr, obj) { }; goog.array.removeAt = function(arr, i) { goog.asserts.assert(null != arr.length); - return 1 == goog.array.ARRAY_PROTOTYPE_.splice.call(arr, i, 1).length; + return 1 == Array.prototype.splice.call(arr, i, 1).length; }; goog.array.removeIf = function(arr, f, opt_obj) { var i = goog.array.findIndex(arr, f, opt_obj); @@ -1447,10 +1446,10 @@ goog.array.removeAllIf = function(arr, f, opt_obj) { return removedCount; }; goog.array.concat = function(var_args) { - return goog.array.ARRAY_PROTOTYPE_.concat.apply(goog.array.ARRAY_PROTOTYPE_, arguments); + return Array.prototype.concat.apply(Array.prototype, arguments); }; goog.array.join = function(var_args) { - return goog.array.ARRAY_PROTOTYPE_.concat.apply(goog.array.ARRAY_PROTOTYPE_, arguments); + return Array.prototype.concat.apply(Array.prototype, arguments); }; goog.array.toArray = function(object) { var length = object.length; @@ -1479,11 +1478,11 @@ goog.array.extend = function(arr1, var_args) { }; goog.array.splice = function(arr, index, howMany, var_args) { goog.asserts.assert(null != arr.length); - return goog.array.ARRAY_PROTOTYPE_.splice.apply(arr, goog.array.slice(arguments, 1)); + return Array.prototype.splice.apply(arr, goog.array.slice(arguments, 1)); }; goog.array.slice = function(arr, start, opt_end) { goog.asserts.assert(null != arr.length); - return 2 >= arguments.length ? goog.array.ARRAY_PROTOTYPE_.slice.call(arr, start) : goog.array.ARRAY_PROTOTYPE_.slice.call(arr, start, opt_end); + return 2 >= arguments.length ? Array.prototype.slice.call(arr, start) : Array.prototype.slice.call(arr, start, opt_end); }; goog.array.removeDuplicates = function(arr, opt_rv, opt_hashFn) { for (var returnArray = opt_rv || arr, defaultHashFn = function(item) { @@ -1638,14 +1637,14 @@ goog.array.flatten = function(var_args) { }; goog.array.rotate = function(array, n) { goog.asserts.assert(null != array.length); - array.length && (n %= array.length, 0 < n ? goog.array.ARRAY_PROTOTYPE_.unshift.apply(array, array.splice(-n, n)) : 0 > n && goog.array.ARRAY_PROTOTYPE_.push.apply(array, array.splice(0, -n))); + array.length && (n %= array.length, 0 < n ? Array.prototype.unshift.apply(array, array.splice(-n, n)) : 0 > n && Array.prototype.push.apply(array, array.splice(0, -n))); return array; }; goog.array.moveItem = function(arr, fromIndex, toIndex) { goog.asserts.assert(0 <= fromIndex && fromIndex < arr.length); goog.asserts.assert(0 <= toIndex && toIndex < arr.length); - var removedItems = goog.array.ARRAY_PROTOTYPE_.splice.call(arr, fromIndex, 1); - goog.array.ARRAY_PROTOTYPE_.splice.call(arr, toIndex, 0, removedItems[0]); + var removedItems = Array.prototype.splice.call(arr, fromIndex, 1); + Array.prototype.splice.call(arr, toIndex, 0, removedItems[0]); }; goog.array.zip = function(var_args) { if (!arguments.length) { @@ -11182,13 +11181,13 @@ goog.exportProperty(lf.proc.Transaction.prototype, "rollback", lf.proc.Transacti lf.proc.Database = function(global) { this.global_ = global; this.schema_ = global.getService(lf.service.SCHEMA); - this.initialized_ = !1; + this.isActive_ = !1; }; goog.exportSymbol("lf.proc.Database", lf.proc.Database); lf.proc.Database.prototype.init = function(opt_options) { this.global_.registerService(lf.service.SCHEMA, this.schema_); return lf.base.init(this.global_, opt_options).then(function() { - this.initialized_ = !0; + this.isActive_ = !0; this.runner_ = this.global_.getService(lf.service.RUNNER); return this; }.bind(this)); @@ -11198,62 +11197,62 @@ lf.proc.Database.prototype.getSchema = function() { return this.schema_; }; goog.exportProperty(lf.proc.Database.prototype, "getSchema", lf.proc.Database.prototype.getSchema); -lf.proc.Database.prototype.checkInit_ = function() { - if (!this.initialized_) { +lf.proc.Database.prototype.checkActive_ = function() { + if (!this.isActive_) { throw new lf.Exception(2); } }; lf.proc.Database.prototype.select = function(var_args) { - this.checkInit_(); + this.checkActive_(); var columns = 1 != arguments.length || goog.isDefAndNotNull(arguments[0]) ? Array.prototype.slice.call(arguments) : []; return new lf.query.SelectBuilder(this.global_, columns); }; goog.exportProperty(lf.proc.Database.prototype, "select", lf.proc.Database.prototype.select); lf.proc.Database.prototype.insert = function() { - this.checkInit_(); + this.checkActive_(); return new lf.query.InsertBuilder(this.global_); }; goog.exportProperty(lf.proc.Database.prototype, "insert", lf.proc.Database.prototype.insert); lf.proc.Database.prototype.insertOrReplace = function() { - this.checkInit_(); + this.checkActive_(); return new lf.query.InsertBuilder(this.global_, !0); }; goog.exportProperty(lf.proc.Database.prototype, "insertOrReplace", lf.proc.Database.prototype.insertOrReplace); lf.proc.Database.prototype.update = function(table) { - this.checkInit_(); + this.checkActive_(); return new lf.query.UpdateBuilder(this.global_, table); }; goog.exportProperty(lf.proc.Database.prototype, "update", lf.proc.Database.prototype.update); lf.proc.Database.prototype.delete = function() { - this.checkInit_(); + this.checkActive_(); return new lf.query.DeleteBuilder(this.global_); }; goog.exportProperty(lf.proc.Database.prototype, "delete", lf.proc.Database.prototype.delete); lf.proc.Database.prototype.observe = function(query, callback) { - this.checkInit_(); + this.checkActive_(); var observerRegistry = this.global_.getService(lf.service.OBSERVER_REGISTRY); observerRegistry.addObserver(query, callback); }; goog.exportProperty(lf.proc.Database.prototype, "observe", lf.proc.Database.prototype.observe); lf.proc.Database.prototype.unobserve = function(query, callback) { - this.checkInit_(); + this.checkActive_(); var observerRegistry = this.global_.getService(lf.service.OBSERVER_REGISTRY); observerRegistry.removeObserver(query, callback); }; goog.exportProperty(lf.proc.Database.prototype, "unobserve", lf.proc.Database.prototype.unobserve); lf.proc.Database.prototype.createTransaction = function() { - this.checkInit_(); + this.checkActive_(); return new lf.proc.Transaction(this.global_); }; goog.exportProperty(lf.proc.Database.prototype, "createTransaction", lf.proc.Database.prototype.createTransaction); lf.proc.Database.prototype.close = function() { lf.base.closeDatabase(this.global_); this.global_.clear(); - this.initialized_ = !1; + this.isActive_ = !1; }; goog.exportProperty(lf.proc.Database.prototype, "close", lf.proc.Database.prototype.close); lf.proc.Database.prototype.export = function() { - this.checkInit_(); + this.checkActive_(); var task = new lf.proc.ExportTask(this.global_); return this.runner_.scheduleTask(task).then(function(results) { return results[0].getPayloads()[0]; @@ -11261,13 +11260,16 @@ lf.proc.Database.prototype.export = function() { }; goog.exportProperty(lf.proc.Database.prototype, "export", lf.proc.Database.prototype.export); lf.proc.Database.prototype.import = function(data) { - this.checkInit_(); + this.checkActive_(); var task = new lf.proc.ImportTask(this.global_, data); return this.runner_.scheduleTask(task).then(function() { return null; }); }; goog.exportProperty(lf.proc.Database.prototype, "import", lf.proc.Database.prototype.import); +lf.proc.Database.prototype.isOpen = function() { + return this.isActive_; +}; lf.schema.BaseColumn = function(table, name, isUnique, isNullable, type, opt_alias) { this.table_ = table; this.name_ = name; @@ -11773,6 +11775,7 @@ lf.schema.Builder = function(dbName, dbVersion) { this.schema_ = new lf.schema.DatabaseSchema(dbName, dbVersion); this.tableBuilders_ = lf.structs.map.create(); this.finalized_ = !1; + this.db_ = null; }; goog.exportSymbol("lf.schema.Builder", lf.schema.Builder); lf.schema.Builder.prototype.checkForeignKeyValidity_ = function(builder) { @@ -11857,10 +11860,15 @@ lf.schema.Builder.prototype.getGlobal = function() { }; goog.exportProperty(lf.schema.Builder.prototype, "getGlobal", lf.schema.Builder.prototype.getGlobal); lf.schema.Builder.prototype.connect = function(opt_options) { - var global = this.getGlobal(); - global.isRegistered(lf.service.SCHEMA) || global.registerService(lf.service.SCHEMA, this.getSchema()); - var db = new lf.proc.Database(global); - return db.init(opt_options); + if (!goog.isNull(this.db_) && this.db_.isOpen()) { + throw new lf.Exception(113); + } + if (goog.isNull(this.db_)) { + var global = this.getGlobal(); + global.isRegistered(lf.service.SCHEMA) || global.registerService(lf.service.SCHEMA, this.getSchema()); + this.db_ = new lf.proc.Database(global); + } + return this.db_.init(opt_options); }; goog.exportProperty(lf.schema.Builder.prototype, "connect", lf.schema.Builder.prototype.connect); lf.schema.Builder.prototype.createTable = function(tableName) { diff --git a/dist/lovefield.min.js b/dist/lovefield.min.js index 5a3d6b99..58257d3f 100644 --- a/dist/lovefield.min.js +++ b/dist/lovefield.min.js @@ -5,20 +5,20 @@ else if("function"==b&&"undefined"==typeof a.call)return"object";return b}functi function oa(a,b,c){if(!a)throw Error();if(2b?1:0};function wa(a,b,c){this.hg=c;this.Mf=a;this.Bg=b;this.rd=0;this.ld=null}wa.prototype.get=function(){var a;0c?Math.max(0,a.length+c):c;if(ia(a))return ia(b)&&1==b.length?a.indexOf(b,c):-1;for(;c=arguments.length?xa.slice.call(a,b):xa.slice.call(a,b,c)} -function Fa(a){for(var b=[],c=0;cb?1:0};function wa(a,b,c){this.hg=c;this.Mf=a;this.Bg=b;this.sd=0;this.ld=null}wa.prototype.get=function(){var a;0c?Math.max(0,a.length+c):c;if(ia(a))return ia(b)&&1==b.length?a.indexOf(b,c):-1;for(;c=arguments.length?Array.prototype.slice.call(a,b):Array.prototype.slice.call(a,b,c)}function Ea(a){for(var b=[],c=0;cd.length?"0"+d:d);return b};function wb(a){this.type=a}function xb(a){y.call(this,-1,a)}t(xb,y);function yb(a,b,c,d){c=c||function(a,b){return a==b};d=d||function(b){return a[b]};for(var e=a.length,f=b.length,h=[],k=0;kh[k][n-1]?k--:n--;return A}function zb(a){return Ba(arguments,function(a,c){return a+c},0)} -function Ab(a){return zb.apply(null,arguments)/arguments.length}function Bb(a){var b=arguments.length;if(2>b)return 0;var c=Ab.apply(null,arguments);return zb.apply(null,Aa(arguments,function(a){return Math.pow(a-c,2)}))/(b-1)}function Cb(a){return Math.sqrt(Bb.apply(null,arguments))};var Db="StopIteration"in p?p.StopIteration:{message:"StopIteration",stack:""};function Eb(){}Eb.prototype.next=function(){throw Db;};Eb.prototype.rc=function(){return this};function Gb(a){if(a instanceof Eb)return a;if("function"==typeof a.rc)return a.rc(!1);if(ha(a)){var b=0,c=new Eb;c.next=function(){for(;;){if(b>=a.length)throw Db;if(b in a)return a[b++];b++}};return c}throw Error("Not implemented");} -function Hb(a,b){if(ha(a))try{za(a,b,void 0)}catch(c){if(c!==Db)throw c;}else{a=Gb(a);try{for(;;)b.call(void 0,a.next(),void 0,a)}catch(c){if(c!==Db)throw c;}}}function Ib(a){if(Ca(arguments,function(a){return!a.length})||!arguments.length)return new Eb;var b=new Eb,c=arguments,d=Fa(c.length);b.next=function(){if(d){for(var a=Aa(d,function(a,b){return c[b][a]}),b=d.length-1;0<=b;b--){if(d[b]2*this.Cb&&Kb(this),!0):!1};function Kb(a){if(a.Cb!=a.b.length){for(var b=0,c=0;b=d.b.length)throw Db;var e=d.b[b++];return a?e:d.o[e]};return e};function Mb(a,b){return Object.prototype.hasOwnProperty.call(a,b)};function Nb(){return u("iPhone")&&!u("iPod")&&!u("iPad")};var Ob=La(),Pb=u("Trident")||u("MSIE"),Qb=u("Edge"),Rb=u("Gecko")&&!(-1!=Ia.toLowerCase().indexOf("webkit")&&!u("Edge"))&&!(u("Trident")||u("MSIE"))&&!u("Edge"),Sb=-1!=Ia.toLowerCase().indexOf("webkit")&&!u("Edge");function Tb(){var a=Ia;if(Rb)return/rv\:([^\);]+)(\)|;)/.exec(a);if(Qb)return/Edge\/([\d\.]+)/.exec(a);if(Pb)return/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(a);if(Sb)return/WebKit\/(\S+)/.exec(a)} -var ua=function(){if(Ob&&p.opera){var a;var b=p.opera.version;try{a=b()}catch(c){a=b}return a}a="";(b=Tb())&&(a=b?b[1]:"");return Pb&&(b=(b=p.document)?b.documentMode:void 0,b>parseFloat(a))?String(b):a}(),Ub={};var Vb=Nb()||u("iPod"),Wb=u("iPad");!u("Android")||Ma()||u("Firefox")||La();var Xb=Ma(),Yb=u("Safari")&&!(Ma()||u("Coast")||La()||u("Edge")||u("Silk")||u("Android"))&&!(Nb()||u("iPad")||u("iPod"));/* +function y(a,b){this.oa=a;this.s=b||this.Ke()}var qb=0;m=y.prototype;m.id=g("oa");function rb(a){return a.s}m.Ke=function(){return{}};m.vf=g("s");m.Ga=function(){return{id:this.oa,value:this.vf()}};m.Hb=function(a){return"#"==a.substr(-1)?this.oa:null};function sb(a){return new y(a.id,a.value)}function tb(a){return new y(qb++,a||{})}function ub(a){if(null==a)return null;a=new Uint8Array(a);for(var b="",c=0;cd.length?"0"+d:d);return b};function vb(a){this.type=a}function wb(a){y.call(this,-1,a)}t(wb,y);function xb(a,b,c,d){c=c||function(a,b){return a==b};d=d||function(b){return a[b]};for(var e=a.length,f=b.length,h=[],k=0;kh[k][n-1]?k--:n--;return A}function yb(a){return Aa(arguments,function(a,c){return a+c},0)} +function zb(a){return yb.apply(null,arguments)/arguments.length}function Ab(a){var b=arguments.length;if(2>b)return 0;var c=zb.apply(null,arguments);return yb.apply(null,za(arguments,function(a){return Math.pow(a-c,2)}))/(b-1)}function Bb(a){return Math.sqrt(Ab.apply(null,arguments))};var Cb="StopIteration"in p?p.StopIteration:{message:"StopIteration",stack:""};function Db(){}Db.prototype.next=function(){throw Cb;};Db.prototype.rc=function(){return this};function Fb(a){if(a instanceof Db)return a;if("function"==typeof a.rc)return a.rc(!1);if(ha(a)){var b=0,c=new Db;c.next=function(){for(;;){if(b>=a.length)throw Cb;if(b in a)return a[b++];b++}};return c}throw Error("Not implemented");} +function Gb(a,b){if(ha(a))try{ya(a,b,void 0)}catch(c){if(c!==Cb)throw c;}else{a=Fb(a);try{for(;;)b.call(void 0,a.next(),void 0,a)}catch(c){if(c!==Cb)throw c;}}}function Hb(a){if(Ba(arguments,function(a){return!a.length})||!arguments.length)return new Db;var b=new Db,c=arguments,d=Ea(c.length);b.next=function(){if(d){for(var a=za(d,function(a,b){return c[b][a]}),b=d.length-1;0<=b;b--){if(d[b]2*this.Cb&&Jb(this),!0):!1};function Jb(a){if(a.Cb!=a.b.length){for(var b=0,c=0;b=d.b.length)throw Cb;var e=d.b[b++];return a?e:d.o[e]};return e};function Lb(a,b){return Object.prototype.hasOwnProperty.call(a,b)};function Mb(){return u("iPhone")&&!u("iPod")&&!u("iPad")};var Nb=Ka(),Ob=u("Trident")||u("MSIE"),Pb=u("Edge"),Qb=u("Gecko")&&!(-1!=Ha.toLowerCase().indexOf("webkit")&&!u("Edge"))&&!(u("Trident")||u("MSIE"))&&!u("Edge"),Rb=-1!=Ha.toLowerCase().indexOf("webkit")&&!u("Edge");function Sb(){var a=Ha;if(Qb)return/rv\:([^\);]+)(\)|;)/.exec(a);if(Pb)return/Edge\/([\d\.]+)/.exec(a);if(Ob)return/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(a);if(Rb)return/WebKit\/(\S+)/.exec(a)} +var ua=function(){if(Nb&&p.opera){var a;var b=p.opera.version;try{a=b()}catch(c){a=b}return a}a="";(b=Sb())&&(a=b?b[1]:"");return Ob&&(b=(b=p.document)?b.documentMode:void 0,b>parseFloat(a))?String(b):a}(),Tb={};var Ub=Mb()||u("iPod"),Vb=u("iPad");!u("Android")||La()||u("Firefox")||Ka();var Wb=La(),Xb=u("Safari")&&!(La()||u("Coast")||Ka()||u("Edge")||u("Silk")||u("Android"))&&!(Mb()||u("iPad")||u("iPod"));/* Copyright 2015 The Lovefield Project Authors. All Rights Reserved. @@ -56,211 +56,211 @@ var ua=function(){if(Ob&&p.opera){var a;var b=p.opera.version;try{a=b()}catch(c) See the License for the specific language governing permissions and limitations under the License. */ -function Zb(){this.oe=Yb||Wb||Vb;this.$f=!(this.oe||Pb&&!Ub[10]&&!(Ub[10]=0<=ta(10)));!Pb||Ub[11]||(Ub[11]=0<=ta(11));this.Jg=Xb||Yb;this.lg=q(window.Map)&&q(window.Map.prototype.values)&&q(window.Map.prototype.forEach)&&!this.oe;this.mg=q(window.Set)&&q(window.Set.prototype.values)&&q(window.Set.prototype.forEach)&&!this.oe}var $b;function ac(){q($b)||($b=new Zb);return $b};function z(){this.o=new Jb;Object.defineProperty(this,"size",{get:function(){return this.o.Cc()}})}z.prototype.clear=function(){this.o.clear()};z.prototype.clear=z.prototype.clear;z.prototype.delete=function(a){return this.o.remove(a)};z.prototype["delete"]=z.prototype.delete;z.prototype.forEach=function(a,b){return this.o.forEach(a,b)};z.prototype.forEach=z.prototype.forEach;z.prototype.get=function(a){return this.o.get(a)};z.prototype.get=z.prototype.get;z.prototype.has=function(a){return this.o.Ma(a)}; -z.prototype.has=z.prototype.has;z.prototype.set=function(a,b){return this.o.set(a,b)};z.prototype.set=z.prototype.set;var bc=ac().lg;function B(){return bc?new window.Map:new z}function cc(a){if(a instanceof z)return Lb(a.o);var b=0,c=Array(a.size);a.forEach(function(a,e){c[b++]=e});return c}function C(a){if(a instanceof z)return a.o.Ba();var b=0,c=Array(a.size);a.forEach(function(a){c[b++]=a});return c};var dc={};r("lf.TransactionType",dc);dc.READ_ONLY=0;dc.READ_WRITE=1;function ec(a,b){this.ve=a;this.Ra=b||null;this.U=x()}ec.prototype.ia=function(){return 0==this.ve?this.uc():fc(this)};function fc(a){try{gc(a.Ra)}catch(b){return db(b)}return hc(a).then(function(a){this.Ra.ia();return a}.bind(a))}function hc(a){ic(a);jc(a);return a.uc()} -function ic(a){a.Ra.tb.forEach(function(a,c){var d=this.Ra.ca().get(c),d=this.I(d.getName(),d.Fb.bind(d)),e=C(a.ya).map(function(a){return a.id()});0a.size)return!1;var c=!0;b.forEach(function(b){c=c&&a.has(b)});return c};function zc(a,b){this.oa=a;this.s=b||{}}function Ac(a){var b=D();a.forEach(function(a){b.add(a>>9)});return E(b)}zc.prototype.Z=g("oa");function Bc(a,b){b.forEach(function(a){this.s[a.id()]=a.Ga()},a)}function Cc(a,b){b.forEach(function(a){delete this.s[a]},a)}zc.prototype.Ga=function(){return{id:this.oa,value:JSON.stringify(this.s)}};function Dc(a){return new zc(a.id,JSON.parse(a.value))};function Ec(a,b,c){this.Y=a;this.Eb=b;this.nf=c}m=Ec.prototype;m.get=function(a){if(0==a.length)return this.Rd();var b=this.Eb;return Fc(this,a).then(function(c){return a.map(function(a){var e=c.get(a>>9);return b(e.s[a])})})};function Fc(a,b){var c=B(),d=x(),e=Ac(b).map(function(a){return new v(function(b,d){var e;try{e=this.Y.get(a)}catch(A){d(A);return}e.onerror=d;e.onsuccess=function(a){a=Dc(a.target.result);c.set(a.Z(),a);b()}},this)},a);gb(e).then(function(){d.resolve(c)});return d.da} -m.Rd=function(){return new v(function(a,b){var c=[],d;try{d=this.Y.openCursor()}catch(e){b(e);return}d.onerror=b;d.onsuccess=function(){var b=d.result;if(b){var f;f=Dc(b.value).s;for(var h in f)c.push(this.Eb(f[h]));b.continue()}else a(c)}.bind(this)},this)};m.Ub=function(a){return new v(function(b,c){var d;try{d=a()}catch(e){c(e);return}d.onsuccess=b;d.onerror=c},this)}; -m.put=function(a){if(0==a.length)return w();var b=B();a.forEach(function(a){var d;d=a.id()>>9;var e=b.get(d)||null;null===e&&(e=this.nf(this.Y.name,d));Bc(e,[a]);b.set(d,e)},this);a=C(b).map(function(a){return this.Ub(function(){return this.Y.put(a.Ga())}.bind(this))},this);return gb(a)}; -m.remove=function(a){if(0==a.length)return this.Ub(function(){return this.Y.clear()}.bind(this));var b=B();a.forEach(function(a){var d=a>>9,e=b.get(d)||null;null===e&&(e=this.nf(this.Y.name,d));Cc(e,[a]);b.set(d,e)},this);a=C(b).map(function(a){return this.Ub(function(){return 0==Object.keys(a.s).length?this.Y.delete(a.Z()):this.Y.put(a.Ga())}.bind(this))},this);return gb(a)};function Gc(a,b,c){a=a.j(nc);var d=[c<<9,(c+1<<9)-1];b=a.$a(b,d[0],d[1]);c=new zc(c);Bc(c,b);return c} -function Hc(a,b){return new zc(b)};function Ic(){};function Jc(a){this.W=a.j(nc);this.F=a.j(oc);this.i=a.j(sc)}Jc.prototype.update=function(a){a.forEach(function(a){Kc(this,a);Lc(this,a)},this)};function Lc(a,b){var c=b.getName();b.ya.forEach(function(a,b){this.W.remove(c,b)},a);b.ua.forEach(function(a){this.W.set(c,a)},a);b.ma.forEach(function(a){this.W.set(c,a[1])},a)}function Kc(a,b){var c=a.i.table(b.getName());Mc(b).forEach(function(a){Nc(this,c,a)},a)} -function Nc(a,b,c){var d=a.F.oc.get(b.getName())||[],e=0;d.forEach(function(a){try{Oc(a,c),e++}catch(b){throw d.slice(0,e).forEach(function(a){Oc(a,[c[1],c[0]])},this),b;}},a)}function Oc(a,b){var c=null===b[1]?void 0:b[1].Hb(a.getName()),d=null===b[0]?void 0:b[0].Hb(a.getName());if(!q(d)&&q(c))a.add(c,b[1].id());else if(q(d)&&q(c)){if(null===c||null===d){if(c==d)return}else if(0==a.fc().compare(d,c))return;a.add(c,b[1].id());a.remove(d,b[0].id())}else q(d)&&!q(c)&&a.remove(d,b[0].id())};var Pc={};r("lf.ConstraintAction",Pc);Pc.RESTRICT=0;Pc.CASCADE=1;var Qc={};r("lf.ConstraintTiming",Qc);Qc.IMMEDIATE=0;Qc.DEFERRABLE=1;var Rc={};r("lf.Order",Rc);Rc.DESC=0;Rc.ASC=1;var Sc={};r("lf.Type",Sc);Sc.ARRAY_BUFFER=0;Sc.BOOLEAN=1;Sc.DATE_TIME=2;Sc.INTEGER=3;Sc.NUMBER=4;Sc.STRING=5;Sc.OBJECT=6;var Tc={0:null,1:!1,2:Object.freeze(new Date(0)),3:0,4:0,5:"",6:null};r("lf.type.DEFAULT_VALUES",Tc);function F(a,b){this.code=a;this.message="http://sn.im/2a0j3wn?c="+a;if(1a.size)return!1;var c=!0;b.forEach(function(b){c=c&&a.has(b)});return c};function yc(a,b){this.oa=a;this.s=b||{}}function zc(a){var b=D();a.forEach(function(a){b.add(a>>9)});return E(b)}yc.prototype.Z=g("oa");function Ac(a,b){b.forEach(function(a){this.s[a.id()]=a.Ga()},a)}function Bc(a,b){b.forEach(function(a){delete this.s[a]},a)}yc.prototype.Ga=function(){return{id:this.oa,value:JSON.stringify(this.s)}};function Cc(a){return new yc(a.id,JSON.parse(a.value))};function Dc(a,b,c){this.Y=a;this.Eb=b;this.nf=c}m=Dc.prototype;m.get=function(a){if(0==a.length)return this.Sd();var b=this.Eb;return Ec(this,a).then(function(c){return a.map(function(a){var e=c.get(a>>9);return b(e.s[a])})})};function Ec(a,b){var c=B(),d=x(),e=zc(b).map(function(a){return new v(function(b,d){var e;try{e=this.Y.get(a)}catch(A){d(A);return}e.onerror=d;e.onsuccess=function(a){a=Cc(a.target.result);c.set(a.Z(),a);b()}},this)},a);fb(e).then(function(){d.resolve(c)});return d.da} +m.Sd=function(){return new v(function(a,b){var c=[],d;try{d=this.Y.openCursor()}catch(e){b(e);return}d.onerror=b;d.onsuccess=function(){var b=d.result;if(b){var f;f=Cc(b.value).s;for(var h in f)c.push(this.Eb(f[h]));b.continue()}else a(c)}.bind(this)},this)};m.Ub=function(a){return new v(function(b,c){var d;try{d=a()}catch(e){c(e);return}d.onsuccess=b;d.onerror=c},this)}; +m.put=function(a){if(0==a.length)return w();var b=B();a.forEach(function(a){var d;d=a.id()>>9;var e=b.get(d)||null;null===e&&(e=this.nf(this.Y.name,d));Ac(e,[a]);b.set(d,e)},this);a=C(b).map(function(a){return this.Ub(function(){return this.Y.put(a.Ga())}.bind(this))},this);return fb(a)}; +m.remove=function(a){if(0==a.length)return this.Ub(function(){return this.Y.clear()}.bind(this));var b=B();a.forEach(function(a){var d=a>>9,e=b.get(d)||null;null===e&&(e=this.nf(this.Y.name,d));Bc(e,[a]);b.set(d,e)},this);a=C(b).map(function(a){return this.Ub(function(){return 0==Object.keys(a.s).length?this.Y.delete(a.Z()):this.Y.put(a.Ga())}.bind(this))},this);return fb(a)};function Fc(a,b,c){a=a.l(mc);var d=[c<<9,(c+1<<9)-1];b=a.$a(b,d[0],d[1]);c=new yc(c);Ac(c,b);return c} +function Gc(a,b){return new yc(b)};function Hc(){};function Ic(a){this.W=a.l(mc);this.F=a.l(nc);this.i=a.l(rc)}Ic.prototype.update=function(a){a.forEach(function(a){Jc(this,a);Kc(this,a)},this)};function Kc(a,b){var c=b.getName();b.ya.forEach(function(a,b){this.W.remove(c,b)},a);b.ua.forEach(function(a){this.W.set(c,a)},a);b.ma.forEach(function(a){this.W.set(c,a[1])},a)}function Jc(a,b){var c=a.i.table(b.getName());Lc(b).forEach(function(a){Mc(this,c,a)},a)} +function Mc(a,b,c){var d=a.F.oc.get(b.getName())||[],e=0;d.forEach(function(a){try{Nc(a,c),e++}catch(b){throw d.slice(0,e).forEach(function(a){Nc(a,[c[1],c[0]])},this),b;}},a)}function Nc(a,b){var c=null===b[1]?void 0:b[1].Hb(a.getName()),d=null===b[0]?void 0:b[0].Hb(a.getName());if(!q(d)&&q(c))a.add(c,b[1].id());else if(q(d)&&q(c)){if(null===c||null===d){if(c==d)return}else if(0==a.fc().compare(d,c))return;a.add(c,b[1].id());a.remove(d,b[0].id())}else q(d)&&!q(c)&&a.remove(d,b[0].id())};var Oc={};r("lf.ConstraintAction",Oc);Oc.RESTRICT=0;Oc.CASCADE=1;var Pc={};r("lf.ConstraintTiming",Pc);Pc.IMMEDIATE=0;Pc.DEFERRABLE=1;var Qc={};r("lf.Order",Qc);Qc.DESC=0;Qc.ASC=1;var Rc={};r("lf.Type",Rc);Rc.ARRAY_BUFFER=0;Rc.BOOLEAN=1;Rc.DATE_TIME=2;Rc.INTEGER=3;Rc.NUMBER=4;Rc.STRING=5;Rc.OBJECT=6;var Sc={0:null,1:!1,2:Object.freeze(new Date(0)),3:0,4:0,5:"",6:null};r("lf.type.DEFAULT_VALUES",Sc);function F(a,b){this.code=a;this.message="http://sn.im/2a0j3wn?c="+a;if(1c.c||d.A==c.c&&!d.la&&!c.ea}function wd(){return new rd(G,G,!1,!1)}function td(a){return a.c==G&&a.A==G}function xd(a){return a.c==a.A&&a.c!=G&&!a.ea&&!a.la}rd.prototype.contains=function(a){var b=this.A==G||athis.c||a==this.c&&!this.ea)&&b}; -function vd(a,b,c,d,e){function f(a){return c?a:1==a?-1:1}d=d||!1;e=e||!1;return a==G?b==G?(d?!e:e)?d?f(1):f(-1):0:f(-1):b==G?f(1):a=c[0]&&a<=c[1]});a.set("gte",function(a,c){return null===a||null===c?!1:a>=c});a.set("gt",function(a,c){return null===a||null===c?!1:a>c});a.set("in",function(a,c){return-1!=c.indexOf(a)});a.set("lte",function(a,c){return null===a||null===c?!1:a<=c});a.set("lt",function(a,c){return null===a||null===c?!1:a=c[0].getTime()&&a.getTime()<=c[1].getTime()});a.set("eq",function(a,c){return(null===a?-1:a.getTime())==(null===c?-1:c.getTime())});a.set("gte",function(a,c){return null===a||null===c?!1:a.getTime()>=c.getTime()});a.set("gt",function(a,c){return null===a||null===c?!1:a.getTime()>c.getTime()});a.set("in",function(a,c){return c.some(function(c){return c.getTime()==a.getTime()})});a.set("lte", -function(a,c){return null===a||null===c?!1:a.getTime()<=c.getTime()});a.set("lt",function(a,c){return null===a||null===c?!1:a.getTime()c&&(c=b[d]);a.ra().forEach(function(a){this.Va.has(a.getName())||(b[a.getName()]=++c)},this);d=this.l.child("@table");return Be(d,b)}.bind(this))}; -function Ce(a,b,c){var d=a.Va.get(b);return null!=d?function(){var a={},b=x();this.l.orderByChild("T").equalTo(d).once("value",function(d){d.forEach(function(b){var d=c(b.val());a[parseInt(b.key(),10)]=d});b.resolve(a)});return b.da}.call(a).then(function(a){a["@rev"]={R:++this.Na};return Be(this.l,a)}.bind(a)):w()}N.prototype.wc=function(a){return Ce(this,a,l(null)).then(function(){this.Va.delete(a);return Be(this.l.child("@table/"+a),null,!0)}.bind(this))};N.prototype.dropTable=N.prototype.wc; -N.prototype.sc=function(a,b,c){return Ce(this,a,function(a){var e=a.P;e[b]=c;return{R:this.Na+1,T:a.T,P:e}}.bind(this))};N.prototype.addTableColumn=N.prototype.sc;N.prototype.xc=function(a,b){return Ce(this,a,function(a){var d=a.P;delete d[b];return{R:this.Na+1,T:a.T,P:d}}.bind(this))};N.prototype.dropTableColumn=N.prototype.xc;N.prototype.Nc=function(a,b,c){return Ce(this,a,function(a){var e=a.P;e[c]=e[b];delete e[b];return{R:this.Na+1,T:a.T,P:e}}.bind(this))};N.prototype.renameTableColumn=N.prototype.Nc; -N.prototype.vb=function(){throw new F(351);};N.prototype.createRow=N.prototype.vb;N.prototype.Gc=g("Pa");N.prototype.getVersion=N.prototype.Gc;N.prototype.gc=function(a){var b=x();a=this.Va.get(a);this.l.orderByChild("T").equalTo(a).once("value",function(a){var d=[];a.forEach(function(a){d.push(a.val().P)});b.resolve(d)});return b.da};N.prototype.dump=function(){var a={},b=cc(this.Va).map(function(b){return this.gc(b).then(function(d){a[b]=d})}.bind(this));return gb(b).then(function(){return a})}; -N.prototype.dump=N.prototype.dump;function De(a,b,c){ec.call(this,b,c);this.l=a}t(De,ec);De.prototype.I=function(a){return this.l.Ec(a)}; -De.prototype.uc=function(){if(0==this.ve)return this.U.resolve(),this.U.da;var a=this.Ra.tb;if(0==a.size)this.U.resolve();else{var b=this.l.Na+1;this.l.Na=b;var c={"@rev":{R:b}};a.forEach(function(a,e){var f=this.l.Va.get(e);a.ua.forEach(function(a,d){c[d]={R:b,T:f,P:a.s}});a.ma.forEach(function(a,d){c[d]={R:b,T:f,P:a[1].s}});a.ya.forEach(function(a,b){c[b]=null})},this);this.l.l.update(c,function(c){null===c?this.U.resolve():(this.l.Na=b-1,c=C(a).map(function(a){return Ee(this.l,a.getName())},this), -gb(c).then(this.U.reject.bind(this.U),this.U.reject.bind(this.U)))}.bind(this))}return this.U.da};function Fe(){this.xa=B()}function Ge(a,b){if(0==b.length)return C(a.xa);var c=[];b.forEach(function(a){a=this.xa.get(a)||null;null===a||c.push(a)},a);return c}Fe.prototype.getData=g("xa");Fe.prototype.get=function(a){return w(Ge(this,a))};function He(a,b){b.forEach(function(a){this.xa.set(a.id(),a)},a)}Fe.prototype.put=function(a){He(this,a);return w()};function Ie(a,b){0==b.length||b.length==a.xa.size?a.xa.clear():b.forEach(function(a){this.xa.delete(a)},a)} -Fe.prototype.remove=function(a){Ie(this,a);return w()};function Je(a){return 0==a.xa.size?0:cc(a.xa).reduce(function(a,c){return a>c?a:c},0)};function Ke(a,b){this.i=a;this.Cf=b;this.Mc=B();this.Na=-1;this.M=B();this.Va=B();this.Hd=null}m=Ke.prototype; -m.Ha=function(a){this.l=this.Cf.child(this.i.name());var b=a||function(){return w()};return Ae(this.l,"@db/version").then(function(a){return null===a?Be(this.l,Le(this),!0).then(function(){var a=new N(0,this.l);return b(a)}.bind(this)):a==this.i.version()?Ae(this.l,"@rev/R").then(function(a){this.Na=a;return Ae(this.l,"@table")}.bind(this)).then(function(a){for(var b in a)this.Va.set(b,a[b]);a=this.i.ra().map(function(a){return Ee(this,a.getName())},this);return gb(a)}.bind(this)).then(function(){Me(this); -Ne(this);return w()}.bind(this)):this.ge(a,b).then(function(){return this.Ha()}.bind(this))}.bind(this))};m.ge=function(a,b){var c=new N(a,this.l);return c.Ha(this.i).then(function(){return w()}.bind(this)).then(function(){return b(c)}).then(function(){var a=this.l.child("@db");return Be(a,{version:this.i.version()},!0)}.bind(this))}; -function Ne(a){a.l.off();a.l.on("child_removed",a.qg.bind(a));a.Id&&(a.Id.off(),a.Mc.clear());a.Id=a.l.orderByChild("R").startAt(a.Na+1);a.Id.on("value",a.de.bind(a))}function Me(a){rb=C(a.M).map(function(a){return Je(a)}).reduce(function(a,c){return a>c?a:c},0)+1}m.qg=function(a){var b=a.val(),c=this.Mc.get(b.T)||null;null===c&&(c=D(),this.Mc.set(b.T,c));c.add(parseInt(a.key(),10))}; -m.de=function(a){var b=a.child("@rev/R").val();null!=b&&b!=this.Na&&(this.Na=b,a=Oe(this,a),a.forEach(function(a){var b=this.M.get(a.getName()),e=cc(a.ya);0this.i.version()?c.reject(new F(108)):c.resolve()}.bind(a));return c.da}m.Db=function(a,b,c){if(null!=this.l)return new hf(this.l,a,c);throw new F(2);};m.close=aa(); -m.Ec=function(){throw new F(512);};m.subscribe=function(){throw new F(355);};m.Jc=function(){throw new F(355);};m.ge=function(a,b){var c=x();qf(this).then(function(){a(new Q(this.h,b,this.l)).then(function(){return this.pe()}.bind(this)).then(c.resolve.bind(c))}.bind(this),c.reject.bind(c));return c.da}; -function qf(a){var b=a.i.ra(),c=new hf(a.l,1,new md(a.h,D())),d=new hf(a.l,1,new md(a.h,D()));gf(c,"INSERT OR REPLACE INTO __lf_ver VALUES (0, ?)",[a.i.version()]);nf(c);return c.ia().then(function(a){function c(a,b){gf(d,"INSERT INTO "+a+"(id, value) VALUES(?, ?)",[-1,JSON.stringify(sb(new xb(new wb(b))))])}var h=a[1];h.filter(function(a){return-1!=a.indexOf("__d__")}).forEach(function(a){gf(d,"DROP TABLE "+a,[])});var k=[],n=[],A=[];b.map(function(a){-1==h.indexOf(a.getName())&&k.push(a.getName()); -a.Bb&&(a.Aa().forEach(function(a){a=jf(a.m());k.push(a);n.push(a)}),a=jf($e(a)),k.push(a),A.push(a))});k.forEach(function(a){gf(d,"CREATE TABLE "+a+"(id INTEGER PRIMARY KEY, value TEXT)",[])});n.forEach(function(a){c(a,"btree")});A.forEach(function(a){c(a,"rowid")});return d.ia()})} -m.pe=function(){var a=0,b=x(),c=function(b){var c=new hf(this.l,0);gf(c,"SELECT MAX(id) FROM "+b,[]);return c.ia().then(function(b){b=b[0].rows.item(0)[0];a=Math.max(b,a)})}.bind(this),d=this.i.ra().map(function(a){return c(a.getName())});gb(d).then(function(){b.resolve(a)},function(a){b.reject(a)});return b.da};function rf(a){this.o=B();this.ac=B();a.ra().forEach(function(a){this.ac.set(a.getName(),D())},this)}m=rf.prototype;m.set=function(a,b){this.o.set(b.id(),b);this.ac.get(a).add(b.id())};m.Xb=function(a,b){var c=this.ac.get(a);b.forEach(function(a){this.o.set(a.id(),a);c.add(a.id())},this)};m.get=function(a){return this.o.get(a)||null};function sf(a,b){return b.map(function(a){return this.get(a)},a)} -m.$a=function(a,b,c){var d=[],e=Math.min(b,c),f=Math.max(b,c);a=this.ac.get(a);if(a.size=e&&a<=f&&(a=this.o.get(a),d.push(a))},this);else for(b=e;b<=f;++b)a.has(b)&&(c=this.o.get(b),d.push(c));return d};m.remove=function(a,b){this.o.delete(b);this.ac.get(a).delete(b)};m.Cc=function(a){return null!=a?this.ac.get(a).size:this.o.size};m.clear=function(){this.o.clear();this.ac.clear()};function tf(a,b,c){var d=0,e=a.length;for(c=c||uf;d>1;0>c(a[f],b)?d=f+1:e=f}return d==e&&a[d]==b?d:~d}function uf(a,b){return a-b}function vf(a,b,c){c=tf(a,b,c);return 0>c?(a.splice(-(c+1),0,b),!0):!1};function wf(a,b,c,d){a=b?a.reverse():a;if(null==c&&null==d)return a;c=Math.min(q(c)?c:a.length,a.length);if(0==c)return[];d=Math.min(d||0,a.length);return a.slice(d,d+c)};function xf(a){this.bd=0==a?yf:zf;this.be=0==a?function(a){return null!=a?a.reverse():null}:function(a){return a||null};this.he=0==a?Af:Bf}t(xf,Ic);function zf(a,b){return a>b?1:ab?1:a==b?0:-1};m.Qb=function(a,b){var c=this.ub(a,b);return c[0]&&c[1]};m.sf=function(a){return a.filter(function(a){return null!==a}).sort(function(a,c){return this.he(a,c)}.bind(this))};m.Wd=function(a){return this.be(a).c==G};m.vd=function(a){a=this.be(a);return[a.c,a.A]};m.ad=function(a){return null!==a};m.toString=function(){return this.compare==yf?"SimpleComparator_DESC":"SimpleComparator_ASC"}; -function Cf(a){xf.call(this,a);this.bd=0==a?Df:Ef}t(Cf,xf);function Ef(a,b){return null===a?null===b?0:-1:null===b?1:zf(a,b)}function Df(a,b){return Ef(b,a)}Cf.prototype.Qb=function(a,b){return null===a?td(b):Cf.eb.Qb.call(this,a,b)};Cf.prototype.Ib=function(a,b){return null===a?null===b?0:-1:null===b?1:null};Cf.prototype.min=function(a,b){var c=this.Ib(a,b);null===c&&(c=Cf.eb.min.call(this,a,b));return c};Cf.prototype.max=function(a,b){var c=this.Ib(a,b);null===c&&(c=Cf.eb.max.call(this,a,b));return c};function Ff(a){this.va=a.map(function(a){return new xf(a)})}t(Ff,Ic);function Gf(a,b,c,d){for(var e=0,f=0;fc.c||d.A==c.c&&!d.la&&!c.ea}function vd(){return new qd(G,G,!1,!1)}function sd(a){return a.c==G&&a.A==G}function wd(a){return a.c==a.A&&a.c!=G&&!a.ea&&!a.la}qd.prototype.contains=function(a){var b=this.A==G||athis.c||a==this.c&&!this.ea)&&b}; +function ud(a,b,c,d,e){function f(a){return c?a:1==a?-1:1}d=d||!1;e=e||!1;return a==G?b==G?(d?!e:e)?d?f(1):f(-1):0:f(-1):b==G?f(1):a=c[0]&&a<=c[1]});a.set("gte",function(a,c){return null===a||null===c?!1:a>=c});a.set("gt",function(a,c){return null===a||null===c?!1:a>c});a.set("in",function(a,c){return-1!=c.indexOf(a)});a.set("lte",function(a,c){return null===a||null===c?!1:a<=c});a.set("lt",function(a,c){return null===a||null===c?!1:a=c[0].getTime()&&a.getTime()<=c[1].getTime()});a.set("eq",function(a,c){return(null===a?-1:a.getTime())==(null===c?-1:c.getTime())});a.set("gte",function(a,c){return null===a||null===c?!1:a.getTime()>=c.getTime()});a.set("gt",function(a,c){return null===a||null===c?!1:a.getTime()>c.getTime()});a.set("in",function(a,c){return c.some(function(c){return c.getTime()==a.getTime()})});a.set("lte", +function(a,c){return null===a||null===c?!1:a.getTime()<=c.getTime()});a.set("lt",function(a,c){return null===a||null===c?!1:a.getTime()c&&(c=b[d]);a.ra().forEach(function(a){this.Va.has(a.getName())||(b[a.getName()]=++c)},this);d=this.j.child("@table");return Ae(d,b)}.bind(this))}; +function Be(a,b,c){var d=a.Va.get(b);return null!=d?function(){var a={},b=x();this.j.orderByChild("T").equalTo(d).once("value",function(d){d.forEach(function(b){var d=c(b.val());a[parseInt(b.key(),10)]=d});b.resolve(a)});return b.da}.call(a).then(function(a){a["@rev"]={R:++this.Na};return Ae(this.j,a)}.bind(a)):w()}N.prototype.wc=function(a){return Be(this,a,l(null)).then(function(){this.Va.delete(a);return Ae(this.j.child("@table/"+a),null,!0)}.bind(this))};N.prototype.dropTable=N.prototype.wc; +N.prototype.sc=function(a,b,c){return Be(this,a,function(a){var e=a.P;e[b]=c;return{R:this.Na+1,T:a.T,P:e}}.bind(this))};N.prototype.addTableColumn=N.prototype.sc;N.prototype.xc=function(a,b){return Be(this,a,function(a){var d=a.P;delete d[b];return{R:this.Na+1,T:a.T,P:d}}.bind(this))};N.prototype.dropTableColumn=N.prototype.xc;N.prototype.Nc=function(a,b,c){return Be(this,a,function(a){var e=a.P;e[c]=e[b];delete e[b];return{R:this.Na+1,T:a.T,P:e}}.bind(this))};N.prototype.renameTableColumn=N.prototype.Nc; +N.prototype.vb=function(){throw new F(351);};N.prototype.createRow=N.prototype.vb;N.prototype.Gc=g("Pa");N.prototype.getVersion=N.prototype.Gc;N.prototype.gc=function(a){var b=x();a=this.Va.get(a);this.j.orderByChild("T").equalTo(a).once("value",function(a){var d=[];a.forEach(function(a){d.push(a.val().P)});b.resolve(d)});return b.da};N.prototype.dump=function(){var a={},b=bc(this.Va).map(function(b){return this.gc(b).then(function(d){a[b]=d})}.bind(this));return fb(b).then(function(){return a})}; +N.prototype.dump=N.prototype.dump;function Ce(a,b,c){dc.call(this,b,c);this.j=a}t(Ce,dc);Ce.prototype.I=function(a){return this.j.Ec(a)}; +Ce.prototype.uc=function(){if(0==this.ve)return this.U.resolve(),this.U.da;var a=this.Ra.tb;if(0==a.size)this.U.resolve();else{var b=this.j.Na+1;this.j.Na=b;var c={"@rev":{R:b}};a.forEach(function(a,e){var f=this.j.Va.get(e);a.ua.forEach(function(a,d){c[d]={R:b,T:f,P:a.s}});a.ma.forEach(function(a,d){c[d]={R:b,T:f,P:a[1].s}});a.ya.forEach(function(a,b){c[b]=null})},this);this.j.j.update(c,function(c){null===c?this.U.resolve():(this.j.Na=b-1,c=C(a).map(function(a){return De(this.j,a.getName())},this), +fb(c).then(this.U.reject.bind(this.U),this.U.reject.bind(this.U)))}.bind(this))}return this.U.da};function Ee(){this.xa=B()}function Fe(a,b){if(0==b.length)return C(a.xa);var c=[];b.forEach(function(a){a=this.xa.get(a)||null;null===a||c.push(a)},a);return c}Ee.prototype.getData=g("xa");Ee.prototype.get=function(a){return w(Fe(this,a))};function Ge(a,b){b.forEach(function(a){this.xa.set(a.id(),a)},a)}Ee.prototype.put=function(a){Ge(this,a);return w()};function He(a,b){0==b.length||b.length==a.xa.size?a.xa.clear():b.forEach(function(a){this.xa.delete(a)},a)} +Ee.prototype.remove=function(a){He(this,a);return w()};function Ie(a){return 0==a.xa.size?0:bc(a.xa).reduce(function(a,c){return a>c?a:c},0)};function Je(a,b){this.i=a;this.Cf=b;this.Mc=B();this.Na=-1;this.M=B();this.Va=B();this.Id=null}m=Je.prototype; +m.Ha=function(a){this.j=this.Cf.child(this.i.name());var b=a||function(){return w()};return ze(this.j,"@db/version").then(function(a){return null===a?Ae(this.j,Ke(this),!0).then(function(){var a=new N(0,this.j);return b(a)}.bind(this)):a==this.i.version()?ze(this.j,"@rev/R").then(function(a){this.Na=a;return ze(this.j,"@table")}.bind(this)).then(function(a){for(var b in a)this.Va.set(b,a[b]);a=this.i.ra().map(function(a){return De(this,a.getName())},this);return fb(a)}.bind(this)).then(function(){Le(this); +Me(this);return w()}.bind(this)):this.ge(a,b).then(function(){return this.Ha()}.bind(this))}.bind(this))};m.ge=function(a,b){var c=new N(a,this.j);return c.Ha(this.i).then(function(){return w()}.bind(this)).then(function(){return b(c)}).then(function(){var a=this.j.child("@db");return Ae(a,{version:this.i.version()},!0)}.bind(this))}; +function Me(a){a.j.off();a.j.on("child_removed",a.qg.bind(a));a.Jd&&(a.Jd.off(),a.Mc.clear());a.Jd=a.j.orderByChild("R").startAt(a.Na+1);a.Jd.on("value",a.de.bind(a))}function Le(a){qb=C(a.M).map(function(a){return Ie(a)}).reduce(function(a,c){return a>c?a:c},0)+1}m.qg=function(a){var b=a.val(),c=this.Mc.get(b.T)||null;null===c&&(c=D(),this.Mc.set(b.T,c));c.add(parseInt(a.key(),10))}; +m.de=function(a){var b=a.child("@rev/R").val();null!=b&&b!=this.Na&&(this.Na=b,a=Ne(this,a),a.forEach(function(a){var b=this.M.get(a.getName()),e=bc(a.ya);0this.i.version()?c.reject(new F(108)):c.resolve()}.bind(a));return c.da}m.Db=function(a,b,c){if(null!=this.j)return new gf(this.j,a,c);throw new F(2);};m.close=aa(); +m.Ec=function(){throw new F(512);};m.subscribe=function(){throw new F(355);};m.Jc=function(){throw new F(355);};m.ge=function(a,b){var c=x();pf(this).then(function(){a(new Q(this.h,b,this.j)).then(function(){return this.pe()}.bind(this)).then(c.resolve.bind(c))}.bind(this),c.reject.bind(c));return c.da}; +function pf(a){var b=a.i.ra(),c=new gf(a.j,1,new ld(a.h,D())),d=new gf(a.j,1,new ld(a.h,D()));ff(c,"INSERT OR REPLACE INTO __lf_ver VALUES (0, ?)",[a.i.version()]);mf(c);return c.ia().then(function(a){function c(a,b){ff(d,"INSERT INTO "+a+"(id, value) VALUES(?, ?)",[-1,JSON.stringify(rb(new wb(new vb(b))))])}var h=a[1];h.filter(function(a){return-1!=a.indexOf("__d__")}).forEach(function(a){ff(d,"DROP TABLE "+a,[])});var k=[],n=[],A=[];b.map(function(a){-1==h.indexOf(a.getName())&&k.push(a.getName()); +a.Bb&&(a.Aa().forEach(function(a){a=hf(a.m());k.push(a);n.push(a)}),a=hf(Ze(a)),k.push(a),A.push(a))});k.forEach(function(a){ff(d,"CREATE TABLE "+a+"(id INTEGER PRIMARY KEY, value TEXT)",[])});n.forEach(function(a){c(a,"btree")});A.forEach(function(a){c(a,"rowid")});return d.ia()})} +m.pe=function(){var a=0,b=x(),c=function(b){var c=new gf(this.j,0);ff(c,"SELECT MAX(id) FROM "+b,[]);return c.ia().then(function(b){b=b[0].rows.item(0)[0];a=Math.max(b,a)})}.bind(this),d=this.i.ra().map(function(a){return c(a.getName())});fb(d).then(function(){b.resolve(a)},function(a){b.reject(a)});return b.da};function qf(a){this.o=B();this.ac=B();a.ra().forEach(function(a){this.ac.set(a.getName(),D())},this)}m=qf.prototype;m.set=function(a,b){this.o.set(b.id(),b);this.ac.get(a).add(b.id())};m.Xb=function(a,b){var c=this.ac.get(a);b.forEach(function(a){this.o.set(a.id(),a);c.add(a.id())},this)};m.get=function(a){return this.o.get(a)||null};function rf(a,b){return b.map(function(a){return this.get(a)},a)} +m.$a=function(a,b,c){var d=[],e=Math.min(b,c),f=Math.max(b,c);a=this.ac.get(a);if(a.size=e&&a<=f&&(a=this.o.get(a),d.push(a))},this);else for(b=e;b<=f;++b)a.has(b)&&(c=this.o.get(b),d.push(c));return d};m.remove=function(a,b){this.o.delete(b);this.ac.get(a).delete(b)};m.Cc=function(a){return null!=a?this.ac.get(a).size:this.o.size};m.clear=function(){this.o.clear();this.ac.clear()};function sf(a,b,c){var d=0,e=a.length;for(c=c||tf;d>1;0>c(a[f],b)?d=f+1:e=f}return d==e&&a[d]==b?d:~d}function tf(a,b){return a-b}function uf(a,b,c){c=sf(a,b,c);return 0>c?(a.splice(-(c+1),0,b),!0):!1};function vf(a,b,c,d){a=b?a.reverse():a;if(null==c&&null==d)return a;c=Math.min(q(c)?c:a.length,a.length);if(0==c)return[];d=Math.min(d||0,a.length);return a.slice(d,d+c)};function wf(a){this.bd=0==a?xf:yf;this.be=0==a?function(a){return null!=a?a.reverse():null}:function(a){return a||null};this.he=0==a?zf:Af}t(wf,Hc);function yf(a,b){return a>b?1:ab?1:a==b?0:-1};m.Qb=function(a,b){var c=this.ub(a,b);return c[0]&&c[1]};m.sf=function(a){return a.filter(function(a){return null!==a}).sort(function(a,c){return this.he(a,c)}.bind(this))};m.Wd=function(a){return this.be(a).c==G};m.wd=function(a){a=this.be(a);return[a.c,a.A]};m.ad=function(a){return null!==a};m.toString=function(){return this.compare==xf?"SimpleComparator_DESC":"SimpleComparator_ASC"}; +function Bf(a){wf.call(this,a);this.bd=0==a?Cf:Df}t(Bf,wf);function Df(a,b){return null===a?null===b?0:-1:null===b?1:yf(a,b)}function Cf(a,b){return Df(b,a)}Bf.prototype.Qb=function(a,b){return null===a?sd(b):Bf.eb.Qb.call(this,a,b)};Bf.prototype.Ib=function(a,b){return null===a?null===b?0:-1:null===b?1:null};Bf.prototype.min=function(a,b){var c=this.Ib(a,b);null===c&&(c=Bf.eb.min.call(this,a,b));return c};Bf.prototype.max=function(a,b){var c=this.Ib(a,b);null===c&&(c=Bf.eb.max.call(this,a,b));return c};function Ef(a){this.va=a.map(function(a){return new wf(a)})}t(Ef,Hc);function Ff(a,b,c,d){for(var e=0,f=0;f=a)throw new F(6,a);d=Lf(this,d);this.qa=d=Mf(d)}else this.clear()}var Nf=[];m=Kf.prototype;m.getName=g("w");m.toString=function(){return this.qa.toString()};m.add=function(a,b){this.qa=this.qa.zb(a,b)};m.set=function(a,b){this.qa=this.qa.zb(a,b,!0)};m.remove=function(a,b){this.qa=this.qa.remove(a,b)};m.get=function(a){return this.qa.get(a)}; -m.cd=function(a){if(null==a)return this.Oa().na;if(a instanceof rd){if(td(a))return this.Oa().na;if(xd(a))return this.get(a.c).length}return this.$a([a]).length};m.Oa=g("rb");m.Rd=function(a,b,c,d){c=Array(a);this.qa.fill({offset:b?this.rb.na-a-d:d,count:a,se:0},c);return b?c.reverse():c}; -m.$a=function(a,b,c,d){var e=Of(this.qa).b[0];if(!q(e)||0==c)return Nf;b=b||!1;c=null!=c?Math.min(c,this.rb.na):this.rb.na;d=d||0;var f=Math.min(Math.max(this.rb.na-d,0),c);if(0==f)return Nf;if(!q(a)||1==a.length&&a[0]instanceof rd&&td(a[0]))return this.Rd(f,b,c,d);a=this.S.sf(a);var h=Array(b?this.rb.na:f),k={count:0,X:h.length,reverse:b,L:d},n=this.S instanceof Hf;a.forEach(function(a){for(var b=this.S.vd(a),b=this.S.Wd(a)?e:b[0],b=Pf(this.qa,b),c=k.count,d=0;null!=b&&k.countk.count&&h.splice(k.count,h.length-k.count);return b?wf(h,b,c,d):h};m.clear=function(){this.qa=Rf(this);this.rb.clear()};m.Ma=function(a){return this.qa.Ma(a)};m.min=function(){return this.Ib(this.S.min.bind(this.S))}; -m.max=function(){return this.Ib(this.S.max.bind(this.S))};function Sf(a,b,c){if(!a.S.ad(b.b[c]))if(1=b.b.length)b=b.sa,c=0;else{var d=Sf(this,b,c);if(null!==d){b=d;break a}c++}while(null!==b);b=null}a:{c=Tf(this.qa);d=c.b.length-1;do if(0>d)c=c.nb,d=0;else{var e=Sf(this,c,d);if(null!==e){c=e;break a}d--}while(null!==c);c=null}return null===b||null===c?null:1==a(b[0],c[0])?b:c};m.Ja=g("xf");m.fc=g("S");m.$d=function(a,b){return null!=a?-1==this.S.compare(a,b):!1};m.Qa=function(a,b){return null!=a?0==this.S.compare(a,b):!1}; -m.Ga=function(){for(var a=[],b=Of(this.qa);b;)a.push(new y(b.oa,[b.b,b.B])),b=b.sa;return a};function Uf(a,b,c,d){a=new Kf(b,a,c);d=Vf(d,a);a.qa=d;return a}function Wf(a,b){this.oa=a;this.D=b;this.kb=0;this.sa=this.nb=this.C=null;this.b=[];this.B=[];this.g=[]}function Rf(a){return new Wf(rb++,a)}function R(a){return 0==a.kb}m=Wf.prototype;m.next=g("sa"); -function Xf(a){function b(a){return null!=a?a.oa.toString():"_"}var c=a.oa+"["+a.b.join("|")+"]",d=a.g.map(function(a){return a.oa}).join("|"),e=a.B.join("/"),f=b(a.nb)+"{",f=R(a)?f+e:f+d,f=f+"}"+b(a.C);a.sa&&(a=Xf(a.sa),c=c+" "+a[0],f=f+" "+a[1]);return[c,f]}m.toString=function(){var a="",b=Xf(this),a=a+(b[0]+"\n"+b[1]+"\n");this.g.length&&(a+=this.g[0].toString());return a};function Of(a){return R(a)?a:Of(a.g[0])}function Tf(a){return R(a)?a:Tf(a.g[a.g.length-1])} -function Yf(a,b){b&&(b.nb=a);a&&(a.sa=b)}function Lf(a,b){for(var c=b.length,d=0,e=Rf(a),f=e;0=c?c:257,k=b.slice(d,d+h);e.b=k.map(function(a){return a.key});e.B=k.map(function(a){return a.value});d+=h;c-=h;0=c.length)b=Zf(c);else{var d=c.length,e=0,b=Rf(a.D);for(b.kb=a.kb+2;0=d?d:257;var f=c.slice(e,e+a),h=Zf(f);h.C=b;b.g.length&&(b.b.push(f[0].b[0]),Yf(b.g[b.g.length-1],h));b.g.push(h);e+=a;d-=a}}return b}m.get=function(a){var b=$f(this,a);if(R(this)){var c=Nf;this.D.Qa(this.b[b],a)&&(c=c.concat(this.B[b]));return c}b=this.D.Qa(this.b[b],a)?b+1:b;return this.g[b].get(a)}; -m.Ma=function(a){var b=$f(this,a);return this.D.Qa(this.b[b],a)?!0:R(this)?!1:this.g[b].Ma(a)};m.remove=function(a,b){ag(this,a,-1,b);if(null===this.C){var c=this;1==this.g.length&&(c=this.g[0],c.C=null);return c}return this};function bg(a){return R(a)?a.b[0]:bg(a.g[0])}function dg(a){a.b=[];for(var b=1;be&&a.D.Qa(a.b[e],b)){if(q(d)&&!a.D.Ja()&&f&&(h=a.B[e],d=tf(h,d,void 0),0>d?d=!1:(h.splice(d,1),d=!0),d&&a.D.Oa().remove(b,1),a.B[e].length))return!1;a.b.splice(e,1);f&&(f=a.D.Ja()?1:a.B[e].length,a.B.splice(e,1),a.D.Oa().remove(b,f))}if(256>a.b.length&&null!==a.C){a:{b=null;if(a.sa&&256a.sa.b.length?(c=a.sa,e=d=0):a.nb&&(c=a.nb,d=c.b.length,e=R(c)?c.B.length:c.g.length);d=[d,0].concat(a.b);Array.prototype.splice.apply(c.b,d);d=null;R(a)?d=a.B:(d=a.g,d.forEach(function(a){a.C=c}));d=[e,0].concat(d);Array.prototype.splice.apply(R(c)?c.B:c.g,d);Yf(a.nb,a.sa);R(c)||dg(c);-1!=b&&(a.C.b.splice(b,1),a.C.g.splice(b,1))} -m.zb=function(a,b,c){var d=$f(this,a);if(R(this)){if(this.D.Qa(this.b[d],a)){if(c)this.D.Oa().remove(a,this.D.Ja()?1:this.B[d].length),this.B[d]=this.D.Ja()?b:[b];else{if(this.D.Ja())throw new F(201);if(!vf(this.B[d],b))throw new F(109);}this.D.Oa().add(a,1);return this}this.b.splice(d,0,a);this.B.splice(d,0,this.D.Ja()?b:[b]);this.D.Oa().add(a,1);512==this.b.length?(d=Rf(this.D),a=Rf(this.D),a.kb=1,a.b=[this.b[256]],a.g=[this,d],a.C=this.C,this.C=a,d.b=this.b.splice(256),d.B=this.B.splice(256),d.C= -a,Yf(d,this.sa),Yf(this,d),d=a):d=this;return d}d=this.D.Qa(this.b[d],a)?d+1:d;a=this.g[d].zb(a,b,c);R(a)||1!=a.b.length||(this.b.splice(d,0,a.b[0]),a.g[1].C=this,a.g[0].C=this,this.g.splice(d,1,a.g[1]),this.g.splice(d,0,a.g[0]));return 512==this.b.length?fg(this):this};function fg(a){var b=Rf(a.D),c=Rf(a.D);b.C=a.C;b.kb=a.kb+1;b.b=[a.b[256]];b.g=[a,c];a.b.splice(256,1);c.C=b;c.kb=a.kb;c.b=a.b.splice(256);c.g=a.g.splice(257);c.g.forEach(function(a){a.C=c});a.C=b;Yf(c,a.sa);Yf(a,c);return b} -function $f(a,b){for(var c=0,d=a.b.length;c>1;a.D.$d(a.b[e],b)?c=e+1:d=e}return c}function Pf(a,b){if(!R(a)){var c=$f(a,b);a.D.Qa(a.b[c],b)&&c++;return Pf(a.g[c],b)}return a} -m.$a=function(a,b,c){function d(a){return a[0]?a[1]?0:1:-1}var e=this.D.fc(),f=0,h=this.b.length-1,k=this.b,n=d(e.ub(k[f],a)),A=d(e.ub(k[h],a));if(1!=n&&(-1!=n||-1!=A)){var O=function(a,b){var c=a+b>>1;return c==a?c+1:c},da=function(b,c,f){if(b>=c)return 0==f?c:-1;var h=d(e.ub(k[b],a));if(0==h)return b;if(1==h)return-1;h=O(b,c);if(h==c)return 0==f?c:-1;var n=d(e.ub(k[h],a));return 0==n?da(b,h,n):-1==n?da(h+1,c,f):da(b+1,h,n)},Fb=function(b,c){if(b>=c)return b;var f=d(e.ub(k[c],a));if(0==f)return c; -if(-1==f)return b;f=O(b,c);if(f==c)return b;var h=d(e.ub(k[f],a));return 0==h?Fb(f,c):1==h?Fb(b,f-1):-1};0!=n&&(f=da(f+1,h,A));-1!=f&&(h=Fb(f,h),-1!=h&&h>=f&&gg(this,b,c,f,h+1))}};function Qf(a,b,c,d){if(a.D.Ja())!b.reverse&&b.L?b.L--:c[b.count++]=a.B[d];else for(var e=0;e=b.X));++d)Qf(a,b,c,d)} +m.wd=function(a){var b=a.map(function(a,b){return this.va[b].wd(a)[0]},this);a=a.map(function(a,b){return this.va[b].wd(a)[1]},this);return[b,a]};m.ad=function(a){return a.every(function(a,c){return this.va[c].ad(a)},this)};function Gf(a){Ef.call(this,a);this.va=a.map(function(a){return new Bf(a)})}t(Gf,Ef);function Hf(){this.na=0}Hf.prototype.add=function(a,b){this.na+=b};Hf.prototype.remove=function(a,b){this.na-=b};Hf.prototype.clear=function(){this.na=0};function If(a,b){a.clear();b.forEach(function(a){this.na+=a.na},a)};function Jf(a,b,c,d){this.w=a;this.S=b;this.xf=c;this.rb=new Hf;if(d){a=511;a*=a*a;if(d.length>=a)throw new F(6,a);d=Kf(this,d);this.qa=d=Lf(d)}else this.clear()}var Mf=[];m=Jf.prototype;m.getName=g("w");m.toString=function(){return this.qa.toString()};m.add=function(a,b){this.qa=this.qa.zb(a,b)};m.set=function(a,b){this.qa=this.qa.zb(a,b,!0)};m.remove=function(a,b){this.qa=this.qa.remove(a,b)};m.get=function(a){return this.qa.get(a)}; +m.cd=function(a){if(null==a)return this.Oa().na;if(a instanceof qd){if(sd(a))return this.Oa().na;if(wd(a))return this.get(a.c).length}return this.$a([a]).length};m.Oa=g("rb");m.Sd=function(a,b,c,d){c=Array(a);this.qa.fill({offset:b?this.rb.na-a-d:d,count:a,se:0},c);return b?c.reverse():c}; +m.$a=function(a,b,c,d){var e=Nf(this.qa).b[0];if(!q(e)||0==c)return Mf;b=b||!1;c=null!=c?Math.min(c,this.rb.na):this.rb.na;d=d||0;var f=Math.min(Math.max(this.rb.na-d,0),c);if(0==f)return Mf;if(!q(a)||1==a.length&&a[0]instanceof qd&&sd(a[0]))return this.Sd(f,b,c,d);a=this.S.sf(a);var h=Array(b?this.rb.na:f),k={count:0,X:h.length,reverse:b,L:d},n=this.S instanceof Gf;a.forEach(function(a){for(var b=this.S.wd(a),b=this.S.Wd(a)?e:b[0],b=Of(this.qa,b),c=k.count,d=0;null!=b&&k.countk.count&&h.splice(k.count,h.length-k.count);return b?vf(h,b,c,d):h};m.clear=function(){this.qa=Qf(this);this.rb.clear()};m.Ma=function(a){return this.qa.Ma(a)};m.min=function(){return this.Ib(this.S.min.bind(this.S))}; +m.max=function(){return this.Ib(this.S.max.bind(this.S))};function Rf(a,b,c){if(!a.S.ad(b.b[c]))if(1=b.b.length)b=b.sa,c=0;else{var d=Rf(this,b,c);if(null!==d){b=d;break a}c++}while(null!==b);b=null}a:{c=Sf(this.qa);d=c.b.length-1;do if(0>d)c=c.nb,d=0;else{var e=Rf(this,c,d);if(null!==e){c=e;break a}d--}while(null!==c);c=null}return null===b||null===c?null:1==a(b[0],c[0])?b:c};m.Ja=g("xf");m.fc=g("S");m.$d=function(a,b){return null!=a?-1==this.S.compare(a,b):!1};m.Qa=function(a,b){return null!=a?0==this.S.compare(a,b):!1}; +m.Ga=function(){for(var a=[],b=Nf(this.qa);b;)a.push(new y(b.oa,[b.b,b.B])),b=b.sa;return a};function Tf(a,b,c,d){a=new Jf(b,a,c);d=Uf(d,a);a.qa=d;return a}function Vf(a,b){this.oa=a;this.D=b;this.kb=0;this.sa=this.nb=this.C=null;this.b=[];this.B=[];this.g=[]}function Qf(a){return new Vf(qb++,a)}function R(a){return 0==a.kb}m=Vf.prototype;m.next=g("sa"); +function Wf(a){function b(a){return null!=a?a.oa.toString():"_"}var c=a.oa+"["+a.b.join("|")+"]",d=a.g.map(function(a){return a.oa}).join("|"),e=a.B.join("/"),f=b(a.nb)+"{",f=R(a)?f+e:f+d,f=f+"}"+b(a.C);a.sa&&(a=Wf(a.sa),c=c+" "+a[0],f=f+" "+a[1]);return[c,f]}m.toString=function(){var a="",b=Wf(this),a=a+(b[0]+"\n"+b[1]+"\n");this.g.length&&(a+=this.g[0].toString());return a};function Nf(a){return R(a)?a:Nf(a.g[0])}function Sf(a){return R(a)?a:Sf(a.g[a.g.length-1])} +function Xf(a,b){b&&(b.nb=a);a&&(a.sa=b)}function Kf(a,b){for(var c=b.length,d=0,e=Qf(a),f=e;0=c?c:257,k=b.slice(d,d+h);e.b=k.map(function(a){return a.key});e.B=k.map(function(a){return a.value});d+=h;c-=h;0=c.length)b=Yf(c);else{var d=c.length,e=0,b=Qf(a.D);for(b.kb=a.kb+2;0=d?d:257;var f=c.slice(e,e+a),h=Yf(f);h.C=b;b.g.length&&(b.b.push(f[0].b[0]),Xf(b.g[b.g.length-1],h));b.g.push(h);e+=a;d-=a}}return b}m.get=function(a){var b=Zf(this,a);if(R(this)){var c=Mf;this.D.Qa(this.b[b],a)&&(c=c.concat(this.B[b]));return c}b=this.D.Qa(this.b[b],a)?b+1:b;return this.g[b].get(a)}; +m.Ma=function(a){var b=Zf(this,a);return this.D.Qa(this.b[b],a)?!0:R(this)?!1:this.g[b].Ma(a)};m.remove=function(a,b){$f(this,a,-1,b);if(null===this.C){var c=this;1==this.g.length&&(c=this.g[0],c.C=null);return c}return this};function ag(a){return R(a)?a.b[0]:ag(a.g[0])}function cg(a){a.b=[];for(var b=1;be&&a.D.Qa(a.b[e],b)){if(q(d)&&!a.D.Ja()&&f&&(h=a.B[e],d=sf(h,d,void 0),0>d?d=!1:(h.splice(d,1),d=!0),d&&a.D.Oa().remove(b,1),a.B[e].length))return!1;a.b.splice(e,1);f&&(f=a.D.Ja()?1:a.B[e].length,a.B.splice(e,1),a.D.Oa().remove(b,f))}if(256>a.b.length&&null!==a.C){a:{b=null;if(a.sa&&256a.sa.b.length?(c=a.sa,e=d=0):a.nb&&(c=a.nb,d=c.b.length,e=R(c)?c.B.length:c.g.length);d=[d,0].concat(a.b);Array.prototype.splice.apply(c.b,d);d=null;R(a)?d=a.B:(d=a.g,d.forEach(function(a){a.C=c}));d=[e,0].concat(d);Array.prototype.splice.apply(R(c)?c.B:c.g,d);Xf(a.nb,a.sa);R(c)||cg(c);-1!=b&&(a.C.b.splice(b,1),a.C.g.splice(b,1))} +m.zb=function(a,b,c){var d=Zf(this,a);if(R(this)){if(this.D.Qa(this.b[d],a)){if(c)this.D.Oa().remove(a,this.D.Ja()?1:this.B[d].length),this.B[d]=this.D.Ja()?b:[b];else{if(this.D.Ja())throw new F(201);if(!uf(this.B[d],b))throw new F(109);}this.D.Oa().add(a,1);return this}this.b.splice(d,0,a);this.B.splice(d,0,this.D.Ja()?b:[b]);this.D.Oa().add(a,1);512==this.b.length?(d=Qf(this.D),a=Qf(this.D),a.kb=1,a.b=[this.b[256]],a.g=[this,d],a.C=this.C,this.C=a,d.b=this.b.splice(256),d.B=this.B.splice(256),d.C= +a,Xf(d,this.sa),Xf(this,d),d=a):d=this;return d}d=this.D.Qa(this.b[d],a)?d+1:d;a=this.g[d].zb(a,b,c);R(a)||1!=a.b.length||(this.b.splice(d,0,a.b[0]),a.g[1].C=this,a.g[0].C=this,this.g.splice(d,1,a.g[1]),this.g.splice(d,0,a.g[0]));return 512==this.b.length?eg(this):this};function eg(a){var b=Qf(a.D),c=Qf(a.D);b.C=a.C;b.kb=a.kb+1;b.b=[a.b[256]];b.g=[a,c];a.b.splice(256,1);c.C=b;c.kb=a.kb;c.b=a.b.splice(256);c.g=a.g.splice(257);c.g.forEach(function(a){a.C=c});a.C=b;Xf(c,a.sa);Xf(a,c);return b} +function Zf(a,b){for(var c=0,d=a.b.length;c>1;a.D.$d(a.b[e],b)?c=e+1:d=e}return c}function Of(a,b){if(!R(a)){var c=Zf(a,b);a.D.Qa(a.b[c],b)&&c++;return Of(a.g[c],b)}return a} +m.$a=function(a,b,c){function d(a){return a[0]?a[1]?0:1:-1}var e=this.D.fc(),f=0,h=this.b.length-1,k=this.b,n=d(e.ub(k[f],a)),A=d(e.ub(k[h],a));if(1!=n&&(-1!=n||-1!=A)){var O=function(a,b){var c=a+b>>1;return c==a?c+1:c},da=function(b,c,f){if(b>=c)return 0==f?c:-1;var h=d(e.ub(k[b],a));if(0==h)return b;if(1==h)return-1;h=O(b,c);if(h==c)return 0==f?c:-1;var n=d(e.ub(k[h],a));return 0==n?da(b,h,n):-1==n?da(h+1,c,f):da(b+1,h,n)},Eb=function(b,c){if(b>=c)return b;var f=d(e.ub(k[c],a));if(0==f)return c; +if(-1==f)return b;f=O(b,c);if(f==c)return b;var h=d(e.ub(k[f],a));return 0==h?Eb(f,c):1==h?Eb(b,f-1):-1};0!=n&&(f=da(f+1,h,A));-1!=f&&(h=Eb(f,h),-1!=h&&h>=f&&fg(this,b,c,f,h+1))}};function Pf(a,b,c,d){if(a.D.Ja())!b.reverse&&b.L?b.L--:c[b.count++]=a.B[d];else for(var e=0;e=b.X));++d)Pf(a,b,c,d)} m.fill=function(a,b){if(R(this))for(var c=0;ca.offset)for(var d=this.B[c].length+a.offset;de.entries.length){a:{b=a.ha;a.ha=a.ka;a.ka=b;b=a.G;switch(a.G){case "gt":b="lt";break;case "lt":b="gt";break;case "gte":b="lte";break;case "lte":b="gte";break;default:break a}a.G=b;a.yc=Sd(Md.Dc(),a.ha.H(),a.G)}return[e,d]}return[d,e]}function Jg(a){var b={};a.ib().forEach(function(a){b[a.getName()]=null});return b} -function Kg(a,b,c){null===a.ce&&(a.ce=Jg(a.ka.I()));var d=new Hd(new y(-1,a.ce),!1);return Kd(b,c,d,[K(a.ka.I())])} -function Lg(a,b,c,d){var e=[b,c];d||(e=Ig(a,b,c));b=e[0];c=e[1];var e=b,f=c,h=a.ha,k=a.ka;d&&(e=c,f=b,h=a.ka,k=a.ha);var n=new Uc,A=[];e.entries.forEach(function(a){var b=String(J(a,h));n.set(b,a)});var O=I(e),da=I(f);f.entries.forEach(function(a){var b=J(a,k),c=String(b);null!==b&&n.has(c)?n.get(c).forEach(function(b){b=Kd(a,da,b,O);A.push(b)}):d&&A.push(Kg(this,a,da))}.bind(a));a=I(b).concat(I(c));return new H(A,a)} -function Mg(a,b,c,d,e){function f(a,b){var c=new Hd(b,1a?b:a});break;case "DISTINCT":d=bh(b,c);break;case "COUNT":d=ch(b,c);break;case "SUM":d=dh(b,c);break;case "AVG":a=ch(b,c);0b.c.length)return a;this.$=a;this.Wa(this.$);return this.$};Ah.prototype.Wa=function(a){if(a instanceof oh)for(;2c;c++){var d=Yd(a,0);Xd(b,d)}Wd(a,b,0)}M(a).forEach(function(a){this.Wa(a)},this)};function Bh(){U.call(this,0,0)}t(Bh,U);Bh.prototype.toString=l("cross_product");Bh.prototype.fa=function(a){var b=a[0],c=a[1];a=[];for(var d=I(b),e=I(c),f=0;f=";case "gt":return">";case "in":return"IN";case "lte":return"<=";case "lt":return"<";case "match":return"LIKE";case "neq":return"<>";default:return"UNKNOWN"}}function Ph(a,b,c,d){return a instanceof Ld?"?"+a.za().toString():d?null!=a?"#":"NULL":"match"==b?"'"+a.toString()+"'":"in"==b?"("+a.map(function(a){return Mh(c,a)}).join(", ")+")":"between"==b?Mh(c,a[0])+" AND "+Mh(c,a[1]):Mh(c,a).toString()} -function Qh(a,b){return M(a).map(function(a){return"("+Rh(a,b)+")"}).join("and"==a.Tb?" AND ":" OR ")}function Sh(a){return[a.ha.m(),Oh(a.G),a.ka.m()].join(" ")}function Rh(a,b){if(a instanceof ce){var c=a.N.m(),d=Oh(a.G),e=Ph(a.value,a.G,a.N.H(),b);return"="==d&&"NULL"==e?[c,"IS NULL"].join(" "):"<>"==d&&"NULL"==e?[c,"IS NOT NULL"].join(" "):[c,d,e].join(" ")}if(a instanceof Fg)return Qh(a,b);if(a instanceof Hg)return Sh(a);throw new F(357,typeof a);} -function Th(a,b){var c=Rh(a,b);return c?" WHERE "+c:""}function Uh(a,b){var c="UPDATE "+a.table.getName()+" SET ",c=c+a.set.map(function(a){var b=a.N.m()+" = ";return-1!=a.Wc?b+"?"+a.Wc.toString():b+Mh(a.N.H(),a.value).toString()}).join(", ");a.u&&(c+=Th(a.u,b));return c+";"} -function Vh(a,b){var c="*";a.f.length&&(c=a.f.map(function(a){return a.Za()?a.m()+" AS "+a.Za():a.m()}).join(", "));c="SELECT "+c+" FROM ";null!=a.Ab&&0!=a.Ab.size?c+=Wh(a,b):(c+=a.c.map(Xh).join(", "),a.u&&(c+=Th(a.u,b)));if(a.O)var d=a.O.map(function(a){return a.N.m()+(0==a.mb?" DESC":" ASC")}).join(", "),c=c+(" ORDER BY "+d);a.ja&&(d=a.ja.map(function(a){return a.m()}).join(", "),c+=" GROUP BY "+d);a.X&&(c+=" LIMIT "+a.X.toString());a.L&&(c+=" SKIP "+a.L.toString());return c+";"} -function Xh(a){return K(a)!=a.getName()?a.getName()+" AS "+K(a):a.getName()}function Wh(a,b){for(var c=yg(a.u,function(a){return a instanceof Hg}),d=c.map(Sh),e=Xh(a.c[0]),f=1;fa)throw new F(531);this.a.X=a}return this};W.prototype.limit=W.prototype.X;W.prototype.L=function(a){if(null!=(this.a.L||this.a.$b))throw new F(529);if(a instanceof Ld)this.a.$b=a;else{if(0>a)throw new F(531);this.a.L=a}return this};W.prototype.skip=W.prototype.L;W.prototype.O=function(a,b){ii(this,549);null==this.a.O&&(this.a.O=[]);this.a.O.push({N:a,mb:null!=b?b:1});return this}; -W.prototype.orderBy=W.prototype.O;W.prototype.ja=function(a){ii(this,549);if(null!=this.a.ja)throw new F(530);null==this.a.ja&&(this.a.ja=[]);this.a.ja.push.apply(this.a.ja,Array.prototype.slice.call(arguments));return this};W.prototype.groupBy=W.prototype.ja;function hi(a,b){switch(a){case "COUNT":case "DISTINCT":return!0;case "AVG":case "GEOMEAN":case "STDDEV":case "SUM":return 4==b||3==b;case "MAX":case "MIN":return 4==b||3==b||5==b||2==b}return!1} -W.prototype.clone=function(){var a=new W(this.global,this.a.f);a.a=this.a.clone();a.a.$c=null;return a};W.prototype.clone=W.prototype.clone;function ki(a,b){V.call(this,a,new Jh(a.j(sc)));this.a.table=b}t(ki,V);r("lf.query.UpdateBuilder",ki);ki.prototype.set=function(a,b){var c={Wc:b instanceof Ld?b.za():-1,N:a,value:b};null!=this.a.set?this.a.set.push(c):this.a.set=[c];return this};ki.prototype.set=ki.prototype.set;ki.prototype.u=function(a){this.Ed();this.a.u=a;return this};ki.prototype.where=ki.prototype.u;ki.prototype.Ed=function(){if(null!=this.a.u)throw new F(516);}; -ki.prototype.gb=function(){ki.eb.gb.call(this);if(null==this.a.set)throw new F(532);if(this.a.set.some(function(a){return a.value instanceof Ld}))throw new F(501);};function li(a){this.a=a;this.Ea=null}li.prototype.jc=function(){null===this.Ea&&(this.Ea=this.ed());return this.Ea};function mi(a){li.call(this,a)}t(mi,li);mi.prototype.ed=function(){return this.a.bc?new jh(this.a.Ia,this.a.values):new ih(this.a.Ia,this.a.values)};function ni(a){li.call(this,a)}t(ni,li);ni.prototype.ed=function(){var a=new lh(this.a.table,this.a.set),b=null!=this.a.u?new mh(this.a.u.Mb()):null,c=new nh(this.a.table);null===b?Xd(a,c):(Xd(b,c),Xd(a,b));return a};function oi(a,b,c){this.Ea=a;this.je=b;this.Wb=c}oi.prototype.jc=function(){this.Wb.forEach(function(a){this.Ea=a.pb(this.Ea,this.je)},this);return this.Ea};function pi(a,b){li.call(this,a);this.Wb=b}t(pi,li);pi.prototype.ed=function(){var a=new kh(this.a.c),b=null!=this.a.u?new mh(this.a.u.Mb()):null,c=new nh(this.a.c);null===b?Xd(a,c):(Xd(b,c),Xd(a,b));return(new oi(a,this.a,this.Wb)).jc()};function qi(){}t(qi,wh);qi.prototype.pb=function(a,b){if(2>b.c.length)return a;this.$=a;this.Wa(this.$,b);return this.$};qi.prototype.Wa=function(a,b){if(a instanceof mh&&a.J instanceof Hg){var c=a.J.Z(),d=Vd(a,0);d instanceof oh&&(c=null!=b.Ab&&b.Ab.has(c),c=new vh(a.J,c),Dg(a,d,c,c),a==this.$&&(this.$=c),a=c)}M(a).forEach(function(a){this.Wa(a,b)},this)};function ri(){this.Vc=D()}t(ri,wh);ri.prototype.pb=function(a,b){this.Vc.clear();if(!q(b.u))return a;this.$=a;this.Wa(this.$);this.Vc.clear();return this.$};ri.prototype.Wa=function(a){if(si(a)){var b=a.J instanceof ce?ti(this,a):ui(this,a);this.Vc.add(a);b==a&&(b=Vd(a,0));null!==b&&(fa(b.getParent())&&(this.$=b),si(b)&&!this.Vc.has(b)&&this.Wa(b))}else M(a).forEach(function(a){this.Wa(a)},this)}; -function vi(a,b,c){var d=b;if(Vd(b,0)instanceof mh)d=Bg(b),vi(a,b,c);else if(wi(b)){var e=[],d=Cg(b,c,function(a){a=new mh(a.J);e.push(a);return a});e.forEach(function(a){vi(this,a,c)},a)}return d}function ti(a,b){var c=D([K(b.J.N.I())]),d=function(a){return xi(this,a,c)}.bind(a);return vi(a,b,d)}function ui(a,b){var c=D([K(b.J.ha.I()),K(b.J.ka.I())]),d=function(a){return xi(this,a,c)}.bind(a);return vi(a,b,d)} -function xi(a,b,c){var d=D();xg(b).forEach(function(a){d.add(K(a.table))},a);b instanceof nh&&d.add(K(b.table));return yc(d,c)}function si(a){return a instanceof mh&&!(a.J instanceof Fg)}function wi(a){a=Vd(a,0);return a instanceof oh||a instanceof vh};function yi(a,b){li.call(this,a);this.Wb=b;this.jf=this.$e=this.rf=this.cf=this.De=this.Pe=this.qf=this.Je=this.tf=null}t(yi,li); -yi.prototype.ed=function(){zi(this);2<=this.a.c.length&&(this.Je=new oh);this.qf=null!=this.a.u?new mh(this.a.u.Mb()):null;this.a.O&&(this.cf=new qh(this.a.O));null!=this.a.L&&0>8,O=0;Oe?1:0;return 1==c?d:-d};m.Ag=function(a,b){return this.S(function(b){return b instanceof T?Bd(a,b):J(a.entries[a.entries.length-1],b)},function(a){return a instanceof T?Bd(b,a):J(b.entries[b.entries.length-1],a)})};m.Pf=function(a,b){return this.S(function(b){return J(a,b)},function(a){return J(b,a)})};function kj(a,b){this.Ka=a;this.K=b}function lj(a){return a.K.some(function(a){return a instanceof T},a)?mj(a):nj(a)}function mj(a){if(1==a.K.length&&"DISTINCT"==a.K[0].Lb)return a=Bd(a.Ka,a.K[0]).entries.map(function(a){var b=new Hd(new y(-1,{}),1b.getPriority()||2>b.getPriority())&&Lj(a.Ic,b.ca());a.Vb.zb(b);Oj(a);return b.Nb().da}function Oj(a){for(var b=a.Vb.Ba(),c=0;ce.entries.length){a:{b=a.ha;a.ha=a.ka;a.ka=b;b=a.G;switch(a.G){case "gt":b="lt";break;case "lt":b="gt";break;case "gte":b="lte";break;case "lte":b="gte";break;default:break a}a.G=b;a.yc=Rd(Ld.Dc(),a.ha.H(),a.G)}return[e,d]}return[d,e]}function Ig(a){var b={};a.ib().forEach(function(a){b[a.getName()]=null});return b} +function Jg(a,b,c){null===a.ce&&(a.ce=Ig(a.ka.I()));var d=new Gd(new y(-1,a.ce),!1);return Jd(b,c,d,[K(a.ka.I())])} +function Kg(a,b,c,d){var e=[b,c];d||(e=Hg(a,b,c));b=e[0];c=e[1];var e=b,f=c,h=a.ha,k=a.ka;d&&(e=c,f=b,h=a.ka,k=a.ha);var n=new Tc,A=[];e.entries.forEach(function(a){var b=String(J(a,h));n.set(b,a)});var O=I(e),da=I(f);f.entries.forEach(function(a){var b=J(a,k),c=String(b);null!==b&&n.has(c)?n.get(c).forEach(function(b){b=Jd(a,da,b,O);A.push(b)}):d&&A.push(Jg(this,a,da))}.bind(a));a=I(b).concat(I(c));return new H(A,a)} +function Lg(a,b,c,d,e){function f(a,b){var c=new Gd(b,1a?b:a});break;case "DISTINCT":d=ah(b,c);break;case "COUNT":d=bh(b,c);break;case "SUM":d=ch(b,c);break;case "AVG":a=bh(b,c);0b.c.length)return a;this.$=a;this.Wa(this.$);return this.$};zh.prototype.Wa=function(a){if(a instanceof nh)for(;2c;c++){var d=Xd(a,0);Wd(b,d)}Vd(a,b,0)}M(a).forEach(function(a){this.Wa(a)},this)};function Ah(){U.call(this,0,0)}t(Ah,U);Ah.prototype.toString=l("cross_product");Ah.prototype.fa=function(a){var b=a[0],c=a[1];a=[];for(var d=I(b),e=I(c),f=0;f=";case "gt":return">";case "in":return"IN";case "lte":return"<=";case "lt":return"<";case "match":return"LIKE";case "neq":return"<>";default:return"UNKNOWN"}}function Oh(a,b,c,d){return a instanceof Kd?"?"+a.za().toString():d?null!=a?"#":"NULL":"match"==b?"'"+a.toString()+"'":"in"==b?"("+a.map(function(a){return Lh(c,a)}).join(", ")+")":"between"==b?Lh(c,a[0])+" AND "+Lh(c,a[1]):Lh(c,a).toString()} +function Ph(a,b){return M(a).map(function(a){return"("+Qh(a,b)+")"}).join("and"==a.Tb?" AND ":" OR ")}function Rh(a){return[a.ha.m(),Nh(a.G),a.ka.m()].join(" ")}function Qh(a,b){if(a instanceof be){var c=a.N.m(),d=Nh(a.G),e=Oh(a.value,a.G,a.N.H(),b);return"="==d&&"NULL"==e?[c,"IS NULL"].join(" "):"<>"==d&&"NULL"==e?[c,"IS NOT NULL"].join(" "):[c,d,e].join(" ")}if(a instanceof Eg)return Ph(a,b);if(a instanceof Gg)return Rh(a);throw new F(357,typeof a);} +function Sh(a,b){var c=Qh(a,b);return c?" WHERE "+c:""}function Th(a,b){var c="UPDATE "+a.table.getName()+" SET ",c=c+a.set.map(function(a){var b=a.N.m()+" = ";return-1!=a.Wc?b+"?"+a.Wc.toString():b+Lh(a.N.H(),a.value).toString()}).join(", ");a.u&&(c+=Sh(a.u,b));return c+";"} +function Uh(a,b){var c="*";a.f.length&&(c=a.f.map(function(a){return a.Za()?a.m()+" AS "+a.Za():a.m()}).join(", "));c="SELECT "+c+" FROM ";null!=a.Ab&&0!=a.Ab.size?c+=Vh(a,b):(c+=a.c.map(Wh).join(", "),a.u&&(c+=Sh(a.u,b)));if(a.O)var d=a.O.map(function(a){return a.N.m()+(0==a.mb?" DESC":" ASC")}).join(", "),c=c+(" ORDER BY "+d);a.ja&&(d=a.ja.map(function(a){return a.m()}).join(", "),c+=" GROUP BY "+d);a.X&&(c+=" LIMIT "+a.X.toString());a.L&&(c+=" SKIP "+a.L.toString());return c+";"} +function Wh(a){return K(a)!=a.getName()?a.getName()+" AS "+K(a):a.getName()}function Vh(a,b){for(var c=xg(a.u,function(a){return a instanceof Gg}),d=c.map(Rh),e=Wh(a.c[0]),f=1;fa)throw new F(531);this.a.X=a}return this};W.prototype.limit=W.prototype.X;W.prototype.L=function(a){if(null!=(this.a.L||this.a.$b))throw new F(529);if(a instanceof Kd)this.a.$b=a;else{if(0>a)throw new F(531);this.a.L=a}return this};W.prototype.skip=W.prototype.L;W.prototype.O=function(a,b){hi(this,549);null==this.a.O&&(this.a.O=[]);this.a.O.push({N:a,mb:null!=b?b:1});return this}; +W.prototype.orderBy=W.prototype.O;W.prototype.ja=function(a){hi(this,549);if(null!=this.a.ja)throw new F(530);null==this.a.ja&&(this.a.ja=[]);this.a.ja.push.apply(this.a.ja,Array.prototype.slice.call(arguments));return this};W.prototype.groupBy=W.prototype.ja;function gi(a,b){switch(a){case "COUNT":case "DISTINCT":return!0;case "AVG":case "GEOMEAN":case "STDDEV":case "SUM":return 4==b||3==b;case "MAX":case "MIN":return 4==b||3==b||5==b||2==b}return!1} +W.prototype.clone=function(){var a=new W(this.global,this.a.f);a.a=this.a.clone();a.a.$c=null;return a};W.prototype.clone=W.prototype.clone;function ji(a,b){V.call(this,a,new Ih(a.l(rc)));this.a.table=b}t(ji,V);r("lf.query.UpdateBuilder",ji);ji.prototype.set=function(a,b){var c={Wc:b instanceof Kd?b.za():-1,N:a,value:b};null!=this.a.set?this.a.set.push(c):this.a.set=[c];return this};ji.prototype.set=ji.prototype.set;ji.prototype.u=function(a){this.Fd();this.a.u=a;return this};ji.prototype.where=ji.prototype.u;ji.prototype.Fd=function(){if(null!=this.a.u)throw new F(516);}; +ji.prototype.gb=function(){ji.eb.gb.call(this);if(null==this.a.set)throw new F(532);if(this.a.set.some(function(a){return a.value instanceof Kd}))throw new F(501);};function ki(a){this.a=a;this.Ea=null}ki.prototype.jc=function(){null===this.Ea&&(this.Ea=this.ed());return this.Ea};function li(a){ki.call(this,a)}t(li,ki);li.prototype.ed=function(){return this.a.bc?new ih(this.a.Ia,this.a.values):new hh(this.a.Ia,this.a.values)};function mi(a){ki.call(this,a)}t(mi,ki);mi.prototype.ed=function(){var a=new kh(this.a.table,this.a.set),b=null!=this.a.u?new lh(this.a.u.Mb()):null,c=new mh(this.a.table);null===b?Wd(a,c):(Wd(b,c),Wd(a,b));return a};function ni(a,b,c){this.Ea=a;this.je=b;this.Wb=c}ni.prototype.jc=function(){this.Wb.forEach(function(a){this.Ea=a.pb(this.Ea,this.je)},this);return this.Ea};function oi(a,b){ki.call(this,a);this.Wb=b}t(oi,ki);oi.prototype.ed=function(){var a=new jh(this.a.c),b=null!=this.a.u?new lh(this.a.u.Mb()):null,c=new mh(this.a.c);null===b?Wd(a,c):(Wd(b,c),Wd(a,b));return(new ni(a,this.a,this.Wb)).jc()};function pi(){}t(pi,vh);pi.prototype.pb=function(a,b){if(2>b.c.length)return a;this.$=a;this.Wa(this.$,b);return this.$};pi.prototype.Wa=function(a,b){if(a instanceof lh&&a.J instanceof Gg){var c=a.J.Z(),d=Ud(a,0);d instanceof nh&&(c=null!=b.Ab&&b.Ab.has(c),c=new uh(a.J,c),Cg(a,d,c,c),a==this.$&&(this.$=c),a=c)}M(a).forEach(function(a){this.Wa(a,b)},this)};function qi(){this.Vc=D()}t(qi,vh);qi.prototype.pb=function(a,b){this.Vc.clear();if(!q(b.u))return a;this.$=a;this.Wa(this.$);this.Vc.clear();return this.$};qi.prototype.Wa=function(a){if(ri(a)){var b=a.J instanceof be?si(this,a):ti(this,a);this.Vc.add(a);b==a&&(b=Ud(a,0));null!==b&&(fa(b.getParent())&&(this.$=b),ri(b)&&!this.Vc.has(b)&&this.Wa(b))}else M(a).forEach(function(a){this.Wa(a)},this)}; +function ui(a,b,c){var d=b;if(Ud(b,0)instanceof lh)d=Ag(b),ui(a,b,c);else if(vi(b)){var e=[],d=Bg(b,c,function(a){a=new lh(a.J);e.push(a);return a});e.forEach(function(a){ui(this,a,c)},a)}return d}function si(a,b){var c=D([K(b.J.N.I())]),d=function(a){return wi(this,a,c)}.bind(a);return ui(a,b,d)}function ti(a,b){var c=D([K(b.J.ha.I()),K(b.J.ka.I())]),d=function(a){return wi(this,a,c)}.bind(a);return ui(a,b,d)} +function wi(a,b,c){var d=D();wg(b).forEach(function(a){d.add(K(a.table))},a);b instanceof mh&&d.add(K(b.table));return xc(d,c)}function ri(a){return a instanceof lh&&!(a.J instanceof Eg)}function vi(a){a=Ud(a,0);return a instanceof nh||a instanceof uh};function xi(a,b){ki.call(this,a);this.Wb=b;this.jf=this.$e=this.rf=this.cf=this.De=this.Pe=this.qf=this.Je=this.tf=null}t(xi,ki); +xi.prototype.ed=function(){yi(this);2<=this.a.c.length&&(this.Je=new nh);this.qf=null!=this.a.u?new lh(this.a.u.Mb()):null;this.a.O&&(this.cf=new ph(this.a.O));null!=this.a.L&&0>8,O=0;Oe?1:0;return 1==c?d:-d};m.Ag=function(a,b){return this.S(function(b){return b instanceof T?Ad(a,b):J(a.entries[a.entries.length-1],b)},function(a){return a instanceof T?Ad(b,a):J(b.entries[b.entries.length-1],a)})};m.Pf=function(a,b){return this.S(function(b){return J(a,b)},function(a){return J(b,a)})};function jj(a,b){this.Ka=a;this.K=b}function kj(a){return a.K.some(function(a){return a instanceof T},a)?lj(a):mj(a)}function lj(a){if(1==a.K.length&&"DISTINCT"==a.K[0].Lb)return a=Ad(a.Ka,a.K[0]).entries.map(function(a){var b=new Gd(new y(-1,{}),1b.getPriority()||2>b.getPriority())&&Kj(a.Ic,b.ca());a.Vb.zb(b);Nj(a);return b.Nb().da}function Nj(a){for(var b=a.Vb.Ba(),c=0;c} */ ( lf.base.init(this.global_, opt_options).then(function() { - this.initialized_ = true; + this.isActive_ = true; this.runner_ = this.global_.getService(lf.service.RUNNER); return this; }.bind(this))); @@ -78,9 +81,9 @@ lf.proc.Database.prototype.getSchema = function() { /** @private */ -lf.proc.Database.prototype.checkInit_ = function() { - if (!this.initialized_) { - // 2: The database has not initialized yet. +lf.proc.Database.prototype.checkActive_ = function() { + if (!this.isActive_) { + // 2: The database connection is not active. throw new lf.Exception(2); } }; @@ -88,7 +91,7 @@ lf.proc.Database.prototype.checkInit_ = function() { /** @override @export */ lf.proc.Database.prototype.select = function(var_args) { - this.checkInit_(); + this.checkActive_(); var columns = arguments.length == 1 && !goog.isDefAndNotNull(arguments[0]) ? [] : Array.prototype.slice.call(arguments); @@ -98,35 +101,35 @@ lf.proc.Database.prototype.select = function(var_args) { /** @override @export */ lf.proc.Database.prototype.insert = function() { - this.checkInit_(); + this.checkActive_(); return new lf.query.InsertBuilder(this.global_); }; /** @override @export */ lf.proc.Database.prototype.insertOrReplace = function() { - this.checkInit_(); + this.checkActive_(); return new lf.query.InsertBuilder(this.global_, /* allowReplace */ true); }; /** @override @export */ lf.proc.Database.prototype.update = function(table) { - this.checkInit_(); + this.checkActive_(); return new lf.query.UpdateBuilder(this.global_, table); }; /** @override @export */ lf.proc.Database.prototype.delete = function() { - this.checkInit_(); + this.checkActive_(); return new lf.query.DeleteBuilder(this.global_); }; /** @override @export */ lf.proc.Database.prototype.observe = function(query, callback) { - this.checkInit_(); + this.checkActive_(); var observerRegistry = this.global_.getService( lf.service.OBSERVER_REGISTRY); observerRegistry.addObserver(query, callback); @@ -135,7 +138,7 @@ lf.proc.Database.prototype.observe = function(query, callback) { /** @override @export */ lf.proc.Database.prototype.unobserve = function(query, callback) { - this.checkInit_(); + this.checkActive_(); var observerRegistry = this.global_.getService( lf.service.OBSERVER_REGISTRY); observerRegistry.removeObserver(query, callback); @@ -144,7 +147,7 @@ lf.proc.Database.prototype.unobserve = function(query, callback) { /** @override @export */ lf.proc.Database.prototype.createTransaction = function(opt_type) { - this.checkInit_(); + this.checkActive_(); return new lf.proc.Transaction(this.global_); }; @@ -153,13 +156,13 @@ lf.proc.Database.prototype.createTransaction = function(opt_type) { lf.proc.Database.prototype.close = function() { lf.base.closeDatabase(this.global_); this.global_.clear(); - this.initialized_ = false; + this.isActive_ = false; }; /** @override @export */ lf.proc.Database.prototype.export = function() { - this.checkInit_(); + this.checkActive_(); var task = new lf.proc.ExportTask(this.global_); return this.runner_.scheduleTask(task).then(function(results) { return results[0].getPayloads()[0]; @@ -169,9 +172,15 @@ lf.proc.Database.prototype.export = function() { /** @override @export */ lf.proc.Database.prototype.import = function(data) { - this.checkInit_(); + this.checkActive_(); var task = new lf.proc.ImportTask(this.global_, data); return this.runner_.scheduleTask(task).then(function() { return null; }); }; + + +/** @return {boolean} */ +lf.proc.Database.prototype.isOpen = function() { + return this.isActive_; +}; diff --git a/lib/schema/builder.js b/lib/schema/builder.js index c3df9aca..d7d77e8c 100644 --- a/lib/schema/builder.js +++ b/lib/schema/builder.js @@ -48,6 +48,9 @@ lf.schema.Builder = function(dbName, dbVersion) { /** @private {boolean} */ this.finalized_ = false; + + /** @private {?lf.proc.Database} */ + this.db_ = null; }; @@ -238,18 +241,27 @@ lf.schema.Builder.prototype.getGlobal = function() { /** + * Instantiates a connection to the database. Note: This method can only be + * called once per Builder instance. Subsequent calls will throw an error. * @param {!lf.schema.ConnectOptions=} opt_options * @return {!IThenable} * @export */ lf.schema.Builder.prototype.connect = function(opt_options) { - var global = this.getGlobal(); - if (!global.isRegistered(lf.service.SCHEMA)) { - global.registerService(lf.service.SCHEMA, this.getSchema()); + if (!goog.isNull(this.db_) && this.db_.isOpen()) { + // 113: Attempt to call connect() on an already opened DB connection. + throw new lf.Exception(113); + } + + if (goog.isNull(this.db_)) { + var global = this.getGlobal(); + if (!global.isRegistered(lf.service.SCHEMA)) { + global.registerService(lf.service.SCHEMA, this.getSchema()); + } + this.db_ = new lf.proc.Database(global); } - var db = new lf.proc.Database(global); - return db.init(opt_options); + return this.db_.init(opt_options); }; diff --git a/spac/template/database.jstemplate b/spac/template/database.jstemplate index 9769fd52..22d3d427 100644 --- a/spac/template/database.jstemplate +++ b/spac/template/database.jstemplate @@ -4,6 +4,7 @@ goog.provide('#namespace'); /// #sort goog.require('#namespace.schema.Database'); +goog.require('lf.Exception'); goog.require('lf.Global'); /** @suppress {extraRequire} */ goog.require('lf.fn'); @@ -51,7 +52,19 @@ goog.require('lf.service.ServiceId'); * @return {!IThenable} */ #namespace.connect = function(opt_options) { - #namespace.getSchema(); - var db = new lf.proc.Database(#namespace.getGlobal()); - return db.init(opt_options); + if (!goog.isNull(#namespace.db_) && #namespace.db_.isOpen()) { + // 113: Attempt to call connect() on an already opened DB connection. + throw new lf.Exception(113); + } + + if (goog.isNull(#namespace.db_)) { + #namespace.getSchema(); + #namespace.db_ = new lf.proc.Database(#namespace.getGlobal()); + } + + return #namespace.db_.init(opt_options); }; + + +/** @private {?lf.proc.Database} */ +#namespace.db_ = null; diff --git a/spac/testdata/database.js b/spac/testdata/database.js index a1f458a6..fcb3ed7c 100644 --- a/spac/testdata/database.js +++ b/spac/testdata/database.js @@ -1,5 +1,6 @@ goog.provide('lovefield.db'); +goog.require('lf.Exception'); goog.require('lf.Global'); /** @suppress {extraRequire} */ goog.require('lf.fn'); @@ -47,7 +48,19 @@ lovefield.db.getSchema = function() { * @return {!IThenable} */ lovefield.db.connect = function(opt_options) { - lovefield.db.getSchema(); - var db = new lf.proc.Database(lovefield.db.getGlobal()); - return db.init(opt_options); + if (!goog.isNull(lovefield.db.db_) && lovefield.db.db_.isOpen()) { + // 113: Attempt to call connect() on an already opened DB connection. + throw new lf.Exception(113); + } + + if (goog.isNull(lovefield.db.db_)) { + lovefield.db.getSchema(); + lovefield.db.db_ = new lf.proc.Database(lovefield.db.getGlobal()); + } + + return lovefield.db.db_.init(opt_options); }; + + +/** @private {?lf.proc.Database} */ +lovefield.db.db_ = null; diff --git a/tests/backstore/external_change_observer_test.js b/tests/backstore/external_change_observer_test.js index f6012dce..44333b08 100644 --- a/tests/backstore/external_change_observer_test.js +++ b/tests/backstore/external_change_observer_test.js @@ -78,6 +78,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + function testExternalChangesApplied() { asyncTestCase.waitForAsync('testExternalChangesApplied'); diff --git a/tests/base/simulate_error_test.js b/tests/base/simulate_error_test.js index dee55fa2..a7ea5dfb 100644 --- a/tests/base/simulate_error_test.js +++ b/tests/base/simulate_error_test.js @@ -49,6 +49,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Tests that when simulateErrors has been called BaseBuilder#exec() rejects. */ diff --git a/tests/pred/combined_predicate_test.js b/tests/pred/combined_predicate_test.js index eb1382b3..c1e0e242 100644 --- a/tests/pred/combined_predicate_test.js +++ b/tests/pred/combined_predicate_test.js @@ -59,6 +59,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Tests that copy() creates an identical tree where each node is a new * instance. diff --git a/tests/pred/join_predicate_test.js b/tests/pred/join_predicate_test.js index 75346d37..0895d8d9 100644 --- a/tests/pred/join_predicate_test.js +++ b/tests/pred/join_predicate_test.js @@ -83,6 +83,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + function testCopy() { var original = e.jobId.eq(j.id); var copy = original.copy(); diff --git a/tests/pred/not_operator_test.js b/tests/pred/not_operator_test.js index 5ffe64cd..47035f68 100644 --- a/tests/pred/not_operator_test.js +++ b/tests/pred/not_operator_test.js @@ -55,6 +55,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Deletes the contents of all tables. * @return {!IThenable} diff --git a/tests/pred/null_predicate_test.js b/tests/pred/null_predicate_test.js index 136eb780..654328f2 100644 --- a/tests/pred/null_predicate_test.js +++ b/tests/pred/null_predicate_test.js @@ -50,6 +50,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Deletes the contents of all tables. * @return {!IThenable} diff --git a/tests/proc/aggregation_step_test.js b/tests/proc/aggregation_step_test.js index da8d1639..c1f3f73a 100644 --- a/tests/proc/aggregation_step_test.js +++ b/tests/proc/aggregation_step_test.js @@ -26,7 +26,6 @@ goog.require('lf.pred.JoinPredicate'); goog.require('lf.proc.AggregationStep'); goog.require('lf.proc.NoOpStep'); goog.require('lf.proc.Relation'); -goog.require('lf.schema.DataStoreType'); goog.require('lf.testing.NullableDataGenerator'); goog.require('lf.testing.hrSchema.MockDataGenerator'); @@ -82,13 +81,11 @@ function testFloatEquals(expected, value) { function setUp() { - asyncTestCase.waitForAsync('setUp'); var schema = hr.db.getSchema(); j = schema.getJob(); e = schema.getEmployee(); dataGenerator = new lf.testing.hrSchema.MockDataGenerator(schema); dataGenerator.generate(20, 100, 0); - hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}); // For the tests involving nullable integer columns, a different schema // is created. The tables in hr schema do not handle nullable integer @@ -98,10 +95,6 @@ function setUp() { nullableGenerator = new lf.testing.NullableDataGenerator(schemaWithNullable); nullableGenerator.generate(); - schemaBuilder.connect({storeType: lf.schema.DataStoreType.MEMORY}). - then(function() { - asyncTestCase.continueTesting(); - }); } diff --git a/tests/proc/end_to_end_test.js b/tests/proc/end_to_end_test.js index 36e01ad8..2eca4934 100644 --- a/tests/proc/end_to_end_test.js +++ b/tests/proc/end_to_end_test.js @@ -76,15 +76,13 @@ function testEndToEnd_StaticSchemaBundled() { } asyncTestCase.waitForAsync('testEndToEnd_StaticSchemaBundled'); - var dbGlobal; - + var dbGlobal = new lf.Global(); var globalFn = function() { return dbGlobal; }; var connectFn = function() { stub.reset(); var dbName = 'hrbdb' + goog.now(); - dbGlobal = new lf.Global(); stub.replace( goog.getObjectByName('hr.bdb.schema.Database.prototype'), 'name', diff --git a/tests/proc/end_to_end_tester.js b/tests/proc/end_to_end_tester.js index f25f051c..8cda0bd4 100644 --- a/tests/proc/end_to_end_tester.js +++ b/tests/proc/end_to_end_tester.js @@ -91,6 +91,7 @@ lf.testing.EndToEndTester.prototype.run = function() { this.testCases_.forEach(function(testCase) { tests.push(this.setUp_.bind(this, testCase[1])); tests.push(testCase[0]); + tests.push(this.tearDown_.bind(this)); }, this); return lf.testing.util.sequentiallyRun(tests); @@ -133,6 +134,16 @@ lf.testing.EndToEndTester.prototype.setUp_ = function(addSampleData) { }; +/** + * @return {!IThenable} + * @private + */ +lf.testing.EndToEndTester.prototype.tearDown_ = function() { + this.db_.close(); + return goog.Promise.resolve(); +}; + + /** * Populates the databse with sample data. * @return {!IThenable} A signal firing when the data has been added. diff --git a/tests/proc/end_to_end_transaction_test.js b/tests/proc/end_to_end_transaction_test.js index 49d68ba2..8aac05f0 100644 --- a/tests/proc/end_to_end_transaction_test.js +++ b/tests/proc/end_to_end_transaction_test.js @@ -94,6 +94,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Populates the database with sample data. * @return {!IThenable} A signal firing when the data has been added. diff --git a/tests/proc/group_by_step_test.js b/tests/proc/group_by_step_test.js index e6031e19..ae2a232d 100644 --- a/tests/proc/group_by_step_test.js +++ b/tests/proc/group_by_step_test.js @@ -20,7 +20,6 @@ goog.require('hr.db'); goog.require('lf.proc.GroupByStep'); goog.require('lf.proc.NoOpStep'); goog.require('lf.proc.Relation'); -goog.require('lf.schema.DataStoreType'); goog.require('lf.testing.hrSchema.MockDataGenerator'); @@ -42,7 +41,6 @@ function setUp() { e = schema.getEmployee(); dataGenerator = new lf.testing.hrSchema.MockDataGenerator(schema); dataGenerator.generate(20, 100, 0); - return hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}); } diff --git a/tests/proc/index_range_scan_pass_test.js b/tests/proc/index_range_scan_pass_test.js index 7057cea5..d87afd18 100644 --- a/tests/proc/index_range_scan_pass_test.js +++ b/tests/proc/index_range_scan_pass_test.js @@ -41,6 +41,10 @@ var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall( 'IndexRangeScanPassTest'); +/** @type {!lf.Database} */ +var db; + + /** @type {!hr.db.schema.Employee} */ var e; @@ -73,22 +77,28 @@ function setUp() { asyncTestCase.waitForAsync('setUp'); propertyReplacer = new goog.testing.PropertyReplacer(); - hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}).then(function(db) { - e = db.getSchema().getEmployee(); - j = db.getSchema().getJob(); - d = db.getSchema().getDepartment(); - dt = db.getSchema().getDummyTable(); - indexStore = /** @type {!lf.index.IndexStore} */ ( - hr.db.getGlobal().getService(lf.service.INDEX_STORE)); - pass = new lf.proc.IndexRangeScanPass(hr.db.getGlobal()); - }).then(function() { - asyncTestCase.continueTesting(); - }, fail); + var schema = hr.db.getSchema(); + e = schema.getEmployee(); + j = schema.getJob(); + d = schema.getDepartment(); + dt = schema.getDummyTable(); + + hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}).then( + function(database) { + db = database; + indexStore = /** @type {!lf.index.IndexStore} */ ( + hr.db.getGlobal().getService(lf.service.INDEX_STORE)); + pass = new lf.proc.IndexRangeScanPass(hr.db.getGlobal()); + }).then( + function() { + asyncTestCase.continueTesting(); + }, fail); } function tearDown() { propertyReplacer.reset(); + db.close(); } diff --git a/tests/proc/limit_skip_by_index_pass_test.js b/tests/proc/limit_skip_by_index_pass_test.js index dbbae47f..122f349c 100644 --- a/tests/proc/limit_skip_by_index_pass_test.js +++ b/tests/proc/limit_skip_by_index_pass_test.js @@ -41,6 +41,10 @@ var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall( 'LimitSkipByIndexPassTest'); +/** @type {!lf.Database} */ +var db; + + /** @type {!hr.db.schema.Employee} */ var e; @@ -52,12 +56,21 @@ var pass; function setUp() { asyncTestCase.waitForAsync('setUp'); - hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}).then(function(db) { - e = db.getSchema().getEmployee(); - pass = new lf.proc.LimitSkipByIndexPass(); - }).then(function() { - asyncTestCase.continueTesting(); - }, fail); + var schema = hr.db.getSchema(); + e = schema.getEmployee(); + pass = new lf.proc.LimitSkipByIndexPass(); + hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}).then( + function(database) { + db = database; + }).then( + function() { + asyncTestCase.continueTesting(); + }, fail); +} + + +function tearDown() { + db.close(); } diff --git a/tests/proc/order_by_index_pass_test.js b/tests/proc/order_by_index_pass_test.js index 13f751ae..8c5e8a0c 100644 --- a/tests/proc/order_by_index_pass_test.js +++ b/tests/proc/order_by_index_pass_test.js @@ -38,6 +38,10 @@ var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall( 'OrderByIndexPassTest'); +/** @type {!lf.Database} */ +var db; + + /** @type {!hr.db.schema.Employee} */ var e; @@ -54,6 +58,7 @@ function setUp() { asyncTestCase.waitForAsync('setUp'); hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}).then(function( database) { + db = database; e = database.getSchema().getEmployee(); dt = database.getSchema().getDummyTable(); pass = new lf.proc.OrderByIndexPass(hr.db.getGlobal()); @@ -63,6 +68,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * @param {!lf.schema.Table} table * @param {string} indexName diff --git a/tests/proc/push_down_selections_pass_test.js b/tests/proc/push_down_selections_pass_test.js index 5a1fb341..c0663ebd 100644 --- a/tests/proc/push_down_selections_pass_test.js +++ b/tests/proc/push_down_selections_pass_test.js @@ -15,7 +15,6 @@ * limitations under the License. */ goog.setTestOnly(); -goog.require('goog.testing.AsyncTestCase'); goog.require('goog.testing.jsunit'); goog.require('hr.db'); goog.require('lf.Order'); @@ -26,15 +25,9 @@ goog.require('lf.proc.PushDownSelectionsPass'); goog.require('lf.proc.SelectNode'); goog.require('lf.proc.TableAccessNode'); goog.require('lf.query.SelectContext'); -goog.require('lf.schema.DataStoreType'); goog.require('lf.testing.treeutil'); -/** @type {!goog.testing.AsyncTestCase} */ -var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall( - 'PushDownSelectionsPassTest'); - - /** @type {!lf.schema.Database} */ var schema; @@ -44,13 +37,8 @@ var pass; function setUp() { - asyncTestCase.waitForAsync('setUp'); - hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}).then(function(db) { - schema = db.getSchema(); - pass = new lf.proc.PushDownSelectionsPass(); - }).then(function() { - asyncTestCase.continueTesting(); - }, fail); + schema = hr.db.getSchema(); + pass = new lf.proc.PushDownSelectionsPass(); } diff --git a/tests/proc/relation_transformer_test.js b/tests/proc/relation_transformer_test.js index f4333e9d..9bc6c57a 100644 --- a/tests/proc/relation_transformer_test.js +++ b/tests/proc/relation_transformer_test.js @@ -16,7 +16,6 @@ */ goog.setTestOnly(); goog.require('goog.object'); -goog.require('goog.testing.AsyncTestCase'); goog.require('goog.testing.jsunit'); goog.require('hr.db'); goog.require('lf.Row'); @@ -26,16 +25,10 @@ goog.require('lf.pred.JoinPredicate'); goog.require('lf.proc.Relation'); goog.require('lf.proc.RelationEntry'); goog.require('lf.proc.RelationTransformer'); -goog.require('lf.schema.DataStoreType'); goog.require('lf.testing.hrSchema.EmployeeDataGenerator'); goog.require('lf.testing.hrSchema.JobDataGenerator'); -/** @type {!goog.testing.AsyncTestCase} */ -var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall( - 'RelationTransformerTest'); - - /** @type {!hr.db.schema.Job} */ var j; @@ -53,22 +46,18 @@ var sampleEmployees; function setUp() { - asyncTestCase.waitForAsync('setUp'); - hr.db.connect({storeType: lf.schema.DataStoreType.MEMORY}).then(function(db) { - j = db.getSchema().getJob(); - e = db.getSchema().getEmployee(); - generateSampleJobData(db); - asyncTestCase.continueTesting(); - }, fail); + var schema = hr.db.getSchema(); + j = schema.getJob(); + e = schema.getEmployee(); + generateSampleJobData(schema); } /** * Generates sample job data. - * @param {!lf.Database} db The db connection. + * @param {!lf.schema.Database} schema The db schema. */ -function generateSampleJobData(db) { - var schema = /** @type {!hr.db.schema.Database} */ (db.getSchema()); +function generateSampleJobData(schema) { var jobGenerator = new lf.testing.hrSchema.JobDataGenerator(schema); var jobCount = 10; diff --git a/tests/proc/runner_test.js b/tests/proc/runner_test.js index b21afff1..ef091732 100644 --- a/tests/proc/runner_test.js +++ b/tests/proc/runner_test.js @@ -56,6 +56,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** @return {!lf.structs.Set} */ function createScope() { var scope = lf.structs.set.create(); diff --git a/tests/proc/user_query_task_test.js b/tests/proc/user_query_task_test.js index d7feca65..b8a4ddf4 100644 --- a/tests/proc/user_query_task_test.js +++ b/tests/proc/user_query_task_test.js @@ -72,6 +72,7 @@ function setUp() { function tearDown() { asyncTestCase.waitForAsync('tearDown'); db.delete().from(j).exec().then(function() { + db.close(); asyncTestCase.continueTesting(); }); } diff --git a/tests/query/delete_test.js b/tests/query/delete_test.js index dad5be58..32d250f3 100644 --- a/tests/query/delete_test.js +++ b/tests/query/delete_test.js @@ -41,6 +41,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Tests that Delete#exec() fails if from() has not been called first. */ diff --git a/tests/query/insert_test.js b/tests/query/insert_test.js index 6c5ede29..b863065e 100644 --- a/tests/query/insert_test.js +++ b/tests/query/insert_test.js @@ -42,6 +42,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Tests that Insert#exec() fails if into() has not been called first. */ diff --git a/tests/query/select_test.js b/tests/query/select_test.js index b824731e..570b8bc2 100644 --- a/tests/query/select_test.js +++ b/tests/query/select_test.js @@ -46,6 +46,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Tests that Select#exec() fails if from() has not been called first. */ diff --git a/tests/query/to_sql_test.js b/tests/query/to_sql_test.js index 4f660e0f..e491bb4c 100644 --- a/tests/query/to_sql_test.js +++ b/tests/query/to_sql_test.js @@ -51,6 +51,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + function testInsertToSql() { var query = new lf.query.InsertBuilder(hr.db.getGlobal()); var job = lf.testing.hrSchemaSampleData.generateSampleJobData(db); diff --git a/tests/query/update_test.js b/tests/query/update_test.js index db760da8..29be552b 100644 --- a/tests/query/update_test.js +++ b/tests/query/update_test.js @@ -41,6 +41,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + /** * Tests that Update#exec() fails if set() has not been called first. */ diff --git a/tests/smoke/bundled_crud_test.js b/tests/smoke/bundled_crud_test.js index db7eee27..3df34108 100644 --- a/tests/smoke/bundled_crud_test.js +++ b/tests/smoke/bundled_crud_test.js @@ -61,6 +61,12 @@ function setUp() { } +function tearDown() { + db.close(); +} + + + function testCRUD() { if (!capability.indexedDb) { return; diff --git a/tests/smoke/crud_test.js b/tests/smoke/crud_test.js index e3d64e17..ad9046c8 100644 --- a/tests/smoke/crud_test.js +++ b/tests/smoke/crud_test.js @@ -58,6 +58,11 @@ function setUp() { } +function tearDown() { + db.close(); +} + + function testCRUD() { asyncTestCase.waitForAsync('testCRUD'); tester.testCRUD().then(function() { diff --git a/tests/smoke/persistent_index_test.js b/tests/smoke/persistent_index_test.js index 212ef49b..4dab6e09 100644 --- a/tests/smoke/persistent_index_test.js +++ b/tests/smoke/persistent_index_test.js @@ -103,6 +103,7 @@ function setUp() { function tearDown() { propertyReplacer.reset(); + db.close(); }