UNPKG

ydn.db

Version:

Javascript database library for IndexedDB, WebDatabase (WebSQL) and WebStorage (localStorage) storage mechanisms supporting version migration, advanced query and transaction workflow.

102 lines 169 kB
(function (name, definition, context) {if (typeof context['module'] !== 'undefined' && context['module']['exports']) {context['module']['exports'] = definition.apply(context);}else if (typeof context['define'] !== 'undefined' && context['define'] === 'function' && context['define']['amd']) {define(name, [], definition);}else {context[name] = definition();}})('ydn', function () {var l,r=this;function u(a){return void 0!==a} function ba(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null"; else if("function"==b&&"undefined"==typeof a.call)return"object";return b}function v(a){return"array"==ba(a)}function w(a){var b=ba(a);return"array"==b||"object"==b&&"number"==typeof a.length}function x(a){return"string"==typeof a}function ca(a){return"boolean"==typeof a}function da(a){return"number"==typeof a}function ea(a){return"function"==ba(a)}function y(a){var b=typeof a;return"object"==b&&null!=a||"function"==b}var fa="closure_uid_"+(1E9*Math.random()>>>0),ga=0; function ha(a,b,c){return a.call.apply(a.bind,arguments)}function ia(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}}function ja(a,b,c){ja=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?ha:ia;return ja.apply(null,arguments)} function ka(a,b){var c=Array.prototype.slice.call(arguments,1);return function(){var b=c.slice();b.push.apply(b,arguments);return a.apply(this,b)}}var la=Date.now||function(){return+new Date};function ma(a,b){var c=a.split("."),d=r;c[0]in d||!d.execScript||d.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)!c.length&&u(b)?d[e]=b:d[e]?d=d[e]:d=d[e]={}} function z(a,b){function c(){}c.prototype=b.prototype;a.D=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.Vb=function(a,c,f){for(var g=Array(arguments.length-2),h=2;h<arguments.length;h++)g[h-2]=arguments[h];return b.prototype[c].apply(a,g)}};function na(a){a.prototype.then=a.prototype.then;a.prototype.$goog_Thenable=!0}function oa(a){if(!a)return!1;try{return!!a.$goog_Thenable}catch(b){return!1}};function pa(a){if(Error.captureStackTrace)Error.captureStackTrace(this,pa);else{var b=Error().stack;b&&(this.stack=b)}a&&(this.message=String(a))}z(pa,Error);pa.prototype.name="CustomError";var qa;function ra(a,b){for(var c=a.split("%s"),d="",e=Array.prototype.slice.call(arguments,1);e.length&&1<c.length;)d+=c.shift()+e.shift();return d+c.join("%s")}function sa(a){return/^[\s\xa0]*$/.test(a)}var ta=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"")}; function ua(a){if(!va.test(a))return a;-1!=a.indexOf("&")&&(a=a.replace(wa,"&amp;"));-1!=a.indexOf("<")&&(a=a.replace(xa,"&lt;"));-1!=a.indexOf(">")&&(a=a.replace(ya,"&gt;"));-1!=a.indexOf('"')&&(a=a.replace(za,"&quot;"));-1!=a.indexOf("'")&&(a=a.replace(Aa,"&#39;"));-1!=a.indexOf("\x00")&&(a=a.replace(Ba,"&#0;"));return a}var wa=/&/g,xa=/</g,ya=/>/g,za=/"/g,Aa=/'/g,Ba=/\x00/g,va=/[\x00&<>"']/; function Ca(a){for(var b=0;1>b;b++)if('"'==a.charAt(0)&&'"'==a.charAt(a.length-1))return a.substring(1,a.length-1);return a}var Da={"\x00":"\\0","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\x0B":"\\x0B",'"':'\\"',"\\":"\\\\"},Ea={"'":"\\'"}; function Fa(a){a=String(a);if(a.quote)return a.quote();for(var b=['"'],c=0;c<a.length;c++){var d=a.charAt(c),e=d.charCodeAt(0),f=c+1,g;if(!(g=Da[d])){if(!(31<e&&127>e))if(d in Ea)d=Ea[d];else if(d in Da)d=Ea[d]=Da[d];else{e=d;g=d.charCodeAt(0);if(31<g&&127>g)e=d;else{if(256>g){if(e="\\x",16>g||256<g)e+="0"}else e="\\u",4096>g&&(e+="0");e+=g.toString(16).toUpperCase()}d=Ea[d]=e}g=d}b[f]=g}b.push('"');return b.join("")}function Ga(a,b){return a<b?-1:a>b?1:0};function Ha(a,b){b.unshift(a);pa.call(this,ra.apply(null,b));b.shift()}z(Ha,pa);Ha.prototype.name="AssertionError";function Ia(a,b){throw new Ha("Failure"+(a?": "+a:""),Array.prototype.slice.call(arguments,1));};var Ja=Array.prototype,Ka=Ja.indexOf?function(a,b,c){return Ja.indexOf.call(a,b,c)}:function(a,b,c){c=null==c?0:0>c?Math.max(0,a.length+c):c;if(x(a))return x(b)&&1==b.length?a.indexOf(b,c):-1;for(;c<a.length;c++)if(c in a&&a[c]===b)return c;return-1},La=Ja.forEach?function(a,b,c){Ja.forEach.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=x(a)?a.split(""):a,f=0;f<d;f++)f in e&&b.call(c,e[f],f,a)},Ma=Ja.map?function(a,b,c){return Ja.map.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=Array(d),f= x(a)?a.split(""):a,g=0;g<d;g++)g in f&&(e[g]=b.call(c,f[g],g,a));return e},Na=Ja.some?function(a,b,c){return Ja.some.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=x(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&b.call(c,e[f],f,a))return!0;return!1};function Oa(a,b){var c=Pa(a,b,void 0);return 0>c?null:x(a)?a.charAt(c):a[c]}function Pa(a,b,c){for(var d=a.length,e=x(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&b.call(c,e[f],f,a))return f;return-1} function Qa(a){if(!v(a))for(var b=a.length-1;0<=b;b--)delete a[b];a.length=0}function Ra(a){var b=a.length;if(0<b){for(var c=Array(b),d=0;d<b;d++)c[d]=a[d];return c}return[]}function Sa(a,b){for(var c=1;c<arguments.length;c++){var d=arguments[c];if(w(d)){var e=a.length||0,f=d.length||0;a.length=e+f;for(var g=0;g<f;g++)a[e+g]=d[g]}else a.push(d)}}function Ta(a,b,c){return 2>=arguments.length?Ja.slice.call(a,b):Ja.slice.call(a,b,c)} function Ua(a,b){if(!w(a)||!w(b)||a.length!=b.length)return!1;for(var c=a.length,d=Va,e=0;e<c;e++)if(!d(a[e],b[e]))return!1;return!0}function Va(a,b){return a===b};var Wa;a:{var Xa=r.navigator;if(Xa){var Ya=Xa.userAgent;if(Ya){Wa=Ya;break a}}Wa=""}function $a(a){return-1!=Wa.indexOf(a)};function ab(a,b){for(var c in a)b.call(void 0,a[c],c,a)}function bb(a,b){for(var c=w(b),d=c?b:arguments,c=c?0:1;c<d.length&&(a=a[d[c]],u(a));c++);return a}var cb="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");function db(a,b){for(var c,d,e=1;e<arguments.length;e++){d=arguments[e];for(c in d)a[c]=d[c];for(var f=0;f<cb.length;f++)c=cb[f],Object.prototype.hasOwnProperty.call(d,c)&&(a[c]=d[c])}} function eb(a){var b=arguments.length;if(1==b&&v(arguments[0]))return eb.apply(null,arguments[0]);for(var c={},d=0;d<b;d++)c[arguments[d]]=!0;return c};function fb(a){r.setTimeout(function(){throw a;},0)}var gb; function hb(){var a=r.MessageChannel;"undefined"===typeof a&&"undefined"!==typeof window&&window.postMessage&&window.addEventListener&&(a=function(){var a=document.createElement("iframe");a.style.display="none";a.src="";document.documentElement.appendChild(a);var b=a.contentWindow,a=b.document;a.open();a.write("");a.close();var c="callImmediate"+Math.random(),d="file:"==b.location.protocol?"*":b.location.protocol+"//"+b.location.host,a=ja(function(a){if(("*"==d||a.origin==d)&&a.data==c)this.port1.onmessage()}, this);b.addEventListener("message",a,!1);this.port1={};this.port2={postMessage:function(){b.postMessage(c,d)}}});if("undefined"!==typeof a&&!$a("Trident")&&!$a("MSIE")){var b=new a,c={},d=c;b.port1.onmessage=function(){if(u(c.next)){c=c.next;var a=c.ob;c.ob=null;a()}};return function(a){d.next={ob:a};d=d.next;b.port2.postMessage(0)}}return"undefined"!==typeof document&&"onreadystatechange"in document.createElement("script")?function(a){var b=document.createElement("script");b.onreadystatechange=function(){b.onreadystatechange= null;b.parentNode.removeChild(b);b=null;a();a=null};document.documentElement.appendChild(b)}:function(a){r.setTimeout(a,0)}};function ib(a,b){jb||lb();mb||(jb(),mb=!0);nb.push(new ob(a,b))}var jb;function lb(){if(r.Promise&&r.Promise.resolve){var a=r.Promise.resolve();jb=function(){a.then(pb)}}else jb=function(){var a=pb;!ea(r.setImmediate)||r.Window&&r.Window.prototype.setImmediate==r.setImmediate?(gb||(gb=hb()),gb(a)):r.setImmediate(a)}}var mb=!1,nb=[];[].push(function(){mb=!1;nb=[]});function pb(){for(;nb.length;){var a=nb;nb=[];for(var b=0;b<a.length;b++){var c=a[b];try{c.a.call(c.b)}catch(d){fb(d)}}}mb=!1} function ob(a,b){this.a=a;this.b=b};function qb(a,b){this.b=rb;this.h=void 0;this.a=this.c=null;this.f=this.g=!1;try{var c=this;a.call(b,function(a){sb(c,tb,a)},function(a){if(!(a instanceof ub))try{if(a instanceof Error)throw a;throw Error("Promise rejected.");}catch(b){}sb(c,vb,a)})}catch(d){sb(this,vb,d)}}var rb=0,tb=2,vb=3;qb.prototype.then=function(a,b,c){return wb(this,ea(a)?a:null,ea(b)?b:null,c)};na(qb);function xb(a){a.b==rb&&ib(function(){var a=new ub(void 0);yb(this,a)},a)} function yb(a,b){if(a.b==rb)if(a.c){var c=a.c;if(c.a){for(var d=0,e=-1,f=0,g;g=c.a[f];f++)if(g=g.sa)if(d++,g==a&&(e=f),0<=e&&1<d)break;0<=e&&(c.b==rb&&1==d?yb(c,b):(d=c.a.splice(e,1)[0],zb(c,d,vb,b)))}}else sb(a,vb,b)}function Ab(a,b){a.a&&a.a.length||a.b!=tb&&a.b!=vb||Bb(a);a.a||(a.a=[]);a.a.push(b)} function wb(a,b,c,d){var e={sa:null,sb:null,tb:null};e.sa=new qb(function(a,g){e.sb=b?function(c){try{var e=b.call(d,c);a(e)}catch(m){g(m)}}:a;e.tb=c?function(b){try{var e=c.call(d,b);!u(e)&&b instanceof ub?g(b):a(e)}catch(m){g(m)}}:g});e.sa.c=a;Ab(a,e);return e.sa}qb.prototype.i=function(a){this.b=rb;sb(this,tb,a)};qb.prototype.l=function(a){this.b=rb;sb(this,vb,a)}; function sb(a,b,c){if(a.b==rb){if(a==c)b=vb,c=new TypeError("Promise cannot resolve to itself");else{if(oa(c)){a.b=1;c.then(a.i,a.l,a);return}if(y(c))try{var d=c.then;if(ea(d)){Eb(a,c,d);return}}catch(e){b=vb,c=e}}a.h=c;a.b=b;Bb(a);b!=vb||c instanceof ub||Fb(a,c)}}function Eb(a,b,c){function d(b){f||(f=!0,a.l(b))}function e(b){f||(f=!0,a.i(b))}a.b=1;var f=!1;try{c.call(b,e,d)}catch(g){d(g)}}function Bb(a){a.g||(a.g=!0,ib(a.m,a))} qb.prototype.m=function(){for(;this.a&&this.a.length;){var a=this.a;this.a=[];for(var b=0;b<a.length;b++)zb(this,a[b],this.b,this.h)}this.g=!1};function zb(a,b,c,d){if(c==tb)b.sb(d);else{if(b.sa)for(;a&&a.f;a=a.c)a.f=!1;b.tb(d)}}function Fb(a,b){a.f=!0;ib(function(){a.f&&Gb.call(null,b)})}var Gb=fb;function ub(a){pa.call(this,a)}z(ub,pa);ub.prototype.name="cancel";/* Portions of this code are from MochiKit, received by The Closure Authors under the MIT license. All other code is Copyright 2005-2009 The Closure Authors. All Rights Reserved. */ function C(a,b){this.l=[];this.V=b||null;this.b=this.c=!1;this.g=void 0;this.qa=this.J=this.m=!1;this.i=0;this.f=null;this.G=0}l=C.prototype;l.za=function(a,b){this.m=!1;Hb(this,a,b)};function Hb(a,b,c){a.c=!0;a.g=c;a.b=!b;a.Ya()}function Ib(a){if(a.c){if(!a.qa)throw new Jb;a.qa=!1}}l.callback=function(a){Ib(this);Hb(this,!0,a)};l.o=function(a){Ib(this);Hb(this,!1,a)};l.K=function(a,b){return Kb(this,a,null,b)};l.mb=function(a,b){return Kb(this,null,a,b)};l.kb=function(a,b){return Kb(this,a,a,b)}; function Kb(a,b,c,d){a.l.push([b,c,d]);a.c&&a.Ya();return a}l.then=function(a,b,c){var d,e,f=new qb(function(a,b){d=a;e=b});Kb(this,d,function(a){e(a)});return f.then(a,b,c)};na(C);C.prototype.Ta=function(a){Kb(this,a.callback,a.o,a);return this};function Lb(a,b){b instanceof C?a.K(ja(b.pa,b)):a.K(function(){return b})}C.prototype.pa=function(a){var b=new C;this.Ta(b);a&&(b.f=this,this.G++);return b};function Mb(a){return Na(a.l,function(a){return ea(a[1])})} C.prototype.Ya=function(){this.i&&this.c&&Mb(this)&&(Nb(this.i),this.i=0);this.f&&(this.f.G--,delete this.f);for(var a=this.g,b=!1,c=!1;this.l.length&&!this.m;){var d=this.l.shift(),e=d[0],f=d[1],d=d[2];if(e=this.b?f:e)try{var g=e.call(d||this.V,a);u(g)&&(this.b=this.b&&(g==a||g instanceof Error),this.g=a=g);oa(a)&&(this.m=c=!0)}catch(h){a=h,this.b=!0,Mb(this)||(b=!0)}}this.g=a;c&&(c=ja(this.za,this,!0),g=ja(this.za,this,!1),a instanceof C?(Kb(a,c,g),a.J=!0):a.then(c,g));b&&(a=new Ob(a),Pb[a.Ga]= a,this.i=a.Ga)};function Qb(a){var b=new C;b.callback(a);return b}function Jb(){pa.call(this)}z(Jb,pa);Jb.prototype.message="Deferred has already fired";Jb.prototype.name="AlreadyCalledError";function Ob(a){this.Ga=r.setTimeout(ja(this.b,this),0);this.a=a}Ob.prototype.b=function(){delete Pb[this.Ga];window.console.error(this.a.stack);throw this.a;};var Pb={};function Nb(a){var b=Pb[a];b&&(r.clearTimeout(b.Ga),delete Pb[a])};var Rb=eb("area base br col command embed hr img input keygen link meta param source track wbr".split(" "));function Sb(){this.a="";this.b=Tb}Sb.prototype.ea=!0;Sb.prototype.aa=function(){return this.a};Sb.prototype.toString=function(){return"Const{"+this.a+"}"};function Ub(a){if(a instanceof Sb&&a.constructor===Sb&&a.b===Tb)return a.a;Ia("expected object of type Const, got '"+a+"'");return"type_error:Const"}var Tb={};function Vb(a){var b=new Sb;b.a=a;return b};function Wb(){this.a="";this.b=Xb}Wb.prototype.ea=!0;var Xb={};Wb.prototype.aa=function(){return this.a};Wb.prototype.toString=function(){return"SafeStyle{"+this.a+"}"};function Yb(a){var b=new Wb;b.a=a;return b}var Zb=Yb(""),$b=/^[-.%_!# a-zA-Z0-9]+$/;function ac(){this.a="";this.b=bc}l=ac.prototype;l.ea=!0;l.aa=function(){return this.a};l.$a=!0;l.ka=function(){return 1};l.toString=function(){return"SafeUrl{"+this.a+"}"};function cc(a){if(a instanceof ac&&a.constructor===ac&&a.b===bc)return a.a;Ia("expected object of type SafeUrl, got '"+a+"'");return"type_error:SafeUrl"}var dc=/^(?:(?:https?|mailto):|[^&:/?#]*(?:[/?#]|$))/i; function ec(a){try{var b=encodeURI(a)}catch(c){return"about:invalid#zClosurez"}return b.replace(fc,function(a){return gc[a]})}var fc=/[()']|%5B|%5D|%25/g,gc={"'":"%27","(":"%28",")":"%29","%5B":"[","%5D":"]","%25":"%"},bc={};function hc(a){var b=new ac;b.a=a;return b};function ic(){this.a=jc}l=ic.prototype;l.ea=!0;l.aa=function(){return""};l.$a=!0;l.ka=function(){return 1};l.toString=function(){return"TrustedResourceUrl{}"};var jc={};function kc(){this.a="";this.c=lc;this.b=null}l=kc.prototype;l.$a=!0;l.ka=function(){return this.b};l.ea=!0;l.aa=function(){return this.a};l.toString=function(){return"SafeHtml{"+this.a+"}"};function mc(a){if(a instanceof kc&&a.constructor===kc&&a.c===lc)return a.a;Ia("expected object of type SafeHtml, got '"+a+"'");return"type_error:SafeHtml"}function nc(a){if(a instanceof kc)return a;var b=null;a.$a&&(b=a.ka());return oc(ua(a.ea?a.aa():String(a)),b)} function pc(a){if(a instanceof kc)return a;a=nc(a);var b;b=mc(a).replace(/ /g," &#160;").replace(/(\r\n|\r|\n)/g,"<br>");return oc(b,a.ka())}var qc=/^[a-zA-Z0-9-]+$/,rc={action:!0,cite:!0,data:!0,formaction:!0,href:!0,manifest:!0,poster:!0,src:!0},sc={embed:!0,iframe:!0,link:!0,object:!0,script:!0,style:!0,template:!0}; function tc(a,b,c){if(!qc.test(a))throw Error("Invalid tag name <"+a+">.");if(a.toLowerCase()in sc)throw Error("Tag name <"+a+"> is not allowed for SafeHtml.");var d=null,e="<"+a;if(b)for(var f in b){if(!qc.test(f))throw Error('Invalid attribute name "'+f+'".');var g=b[f];if(null!=g){var h,k=a;h=f;if(g instanceof Sb)g=Ub(g);else if("style"==h.toLowerCase()){if(!y(g))throw Error('The "style" attribute requires goog.html.SafeStyle or map of style properties, '+typeof g+" given: "+g);if(!(g instanceof Wb)){var k="",m=void 0;for(m in g){if(!/^[-_a-zA-Z0-9]+$/.test(m))throw Error("Name allows only [-_a-zA-Z0-9], got: "+m);var n=g[m];null!=n&&(n instanceof Sb?n=Ub(n):$b.test(n)||(Ia("String value allows only [-.%_!# a-zA-Z0-9], got: "+n),n="zClosurez"),k+=m+":"+n+";")}g=k?Yb(k):Zb}k=void 0;g instanceof Wb&&g.constructor===Wb&&g.b===Xb?k=g.a:(Ia("expected object of type SafeStyle, got '"+g+"'"),k="type_error:SafeStyle");g=k}else{if(/^on/i.test(h))throw Error('Attribute "'+h+'" requires goog.string.Const value, "'+ g+'" given.');if(h.toLowerCase()in rc)if(g instanceof ic)g instanceof ic&&g.constructor===ic&&g.a===jc?g="":(Ia("expected object of type TrustedResourceUrl, got '"+g+"'"),g="type_error:TrustedResourceUrl");else if(g instanceof ac)g=cc(g);else throw Error('Attribute "'+h+'" on tag "'+k+'" requires goog.html.SafeUrl or goog.string.Const value, "'+g+'" given.');}g.ea&&(g=g.aa());h=h+'="'+ua(String(g))+'"';e=e+(" "+h)}}u(c)?v(c)||(c=[c]):c=[];!0===Rb[a.toLowerCase()]?e+=">":(d=uc(c),e+=">"+mc(d)+"</"+ a+">",d=d.ka());(a=b&&b.dir)&&(/^(ltr|rtl|auto)$/i.test(a)?d=0:d=null);return oc(e,d)}function uc(a){function b(a){v(a)?La(a,b):(a=nc(a),d+=mc(a),a=a.ka(),0==c?c=a:0!=a&&c!=a&&(c=null))}var c=0,d="";La(arguments,b);return oc(d,c)}var lc={};function oc(a,b){var c=new kc;c.a=a;c.b=b;return c}var vc=oc("",0);var wc=$a("Opera")||$a("OPR"),xc=$a("Trident")||$a("MSIE"),yc=$a("Gecko")&&-1==Wa.toLowerCase().indexOf("webkit")&&!($a("Trident")||$a("MSIE")),zc=-1!=Wa.toLowerCase().indexOf("webkit");zc&&$a("Mobile");$a("Macintosh");$a("Windows");$a("Linux")||$a("CrOS");var Ac=r.navigator||null;Ac&&(Ac.appVersion||"").indexOf("X11");$a("Android");!$a("iPhone")||$a("iPod")||$a("iPad");$a("iPad");function Bc(){var a=r.document;return a?a.documentMode:void 0} var Cc=function(){var a="",b;if(wc&&r.opera)return a=r.opera.version,ea(a)?a():a;yc?b=/rv\:([^\);]+)(\)|;)/:xc?b=/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/:zc&&(b=/WebKit\/(\S+)/);b&&(a=(a=b.exec(Wa))?a[1]:"");return xc&&(b=Bc(),b>parseFloat(a))?String(b):a}(),Dc={}; function Ec(a){var b;if(!(b=Dc[a])){b=0;for(var c=ta(String(Cc)).split("."),d=ta(String(a)).split("."),e=Math.max(c.length,d.length),f=0;0==b&&f<e;f++){var g=c[f]||"",h=d[f]||"",k=RegExp("(\\d*)(\\D*)","g"),m=RegExp("(\\d*)(\\D*)","g");do{var n=k.exec(g)||["","",""],p=m.exec(h)||["","",""];if(0==n[0].length&&0==p[0].length)break;b=Ga(0==n[1].length?0:parseInt(n[1],10),0==p[1].length?0:parseInt(p[1],10))||Ga(0==n[2].length,0==p[2].length)||Ga(n[2],p[2])}while(0==b)}b=Dc[a]=0<=b}return b} var Fc=r.document,Gc=Fc&&xc?Bc()||("CSS1Compat"==Fc.compatMode?parseInt(Cc,10):5):void 0;function Hc(a){var b;b||(b=Ic(a||arguments.callee.caller,[]));return b} function Ic(a,b){var c=[];if(0<=Ka(b,a))c.push("[...circular reference...]");else if(a&&50>b.length){c.push(Jc(a)+"(");for(var d=a.arguments,e=0;d&&e<d.length;e++){0<e&&c.push(", ");var f;f=d[e];switch(typeof f){case "object":f=f?"object":"null";break;case "string":break;case "number":f=String(f);break;case "boolean":f=f?"true":"false";break;case "function":f=(f=Jc(f))?f:"[fn]";break;default:f=typeof f}40<f.length&&(f=f.substr(0,40)+"...");c.push(f)}b.push(a);c.push(")\n");try{c.push(Ic(a.caller, b))}catch(g){c.push("[exception trying to get caller]\n")}}else a?c.push("[...long stack...]"):c.push("[end]");return c.join("")}function Jc(a){if(Kc[a])return Kc[a];a=String(a);if(!Kc[a]){var b=/function ([^\(]+)/.exec(a);Kc[a]=b?b[1]:"[Anonymous]"}return Kc[a]}var Kc={};function Lc(a,b,c,d,e){"number"==typeof e||Mc++;this.g=d||la();this.f=a;this.c=b;this.b=c;delete this.a}Lc.prototype.a=null;var Mc=0;function Nc(a){this.g=a;this.a=this.f=this.b=this.c=null}function Oc(a,b){this.name=a;this.value=b}Oc.prototype.toString=function(){return this.name};var Pc=new Oc("SHOUT",1200),Qc=new Oc("SEVERE",1E3),Rc=new Oc("WARNING",900),Sc=new Oc("INFO",800),Tc=new Oc("CONFIG",700),Uc=new Oc("FINE",500),Vc=new Oc("FINER",400),Wc=new Oc("FINEST",300),Xc=[new Oc("OFF",Infinity),Pc,Qc,Rc,Sc,Tc,Uc,Vc,Wc,new Oc("ALL",0)],Yc=null;Nc.prototype.getName=function(){return this.g}; function Zc(a){if(a.b)return a.b;if(a.c)return Zc(a.c);Ia("Root logger has no level set.");return null}Nc.prototype.log=function(a,b,c){if(a.value>=Zc(this).value)for(ea(b)&&(b=b()),a=new Lc(a,String(b),this.g),c&&(a.a=c),c="log:"+a.c,r.console&&(r.console.timeStamp?r.console.timeStamp(c):r.console.markTimeline&&r.console.markTimeline(c)),r.msWriteProfilerMark&&r.msWriteProfilerMark(c),c=this;c;){b=c;var d=a;if(b.a)for(var e=0,f=void 0;f=b.a[e];e++)f(d);c=c.c}};var $c={},ad=null; function bd(){ad||(ad=new Nc(""),$c[""]=ad,ad.b=Tc)}function cd(){bd();return ad}function D(a){bd();var b;if(!(b=$c[a])){b=new Nc(a);var c=a.lastIndexOf("."),d=a.substr(c+1),c=D(a.substr(0,c));c.f||(c.f={});c.f[d]=b;b.c=c;$c[a]=b}return b};function dd(a,b,c){a&&a.log(b,c,void 0)}function ed(a,b){a&&a.log(Qc,b,void 0)}function E(a,b){a&&a.log(Rc,b,void 0)}function fd(a,b){a&&a.log(Uc,b,void 0)};function I(a,b){a&&a.log(Wc,b,void 0)}function J(a,b){a&&a.log(Vc,b,void 0)};function K(a){pa.call(this,a);this.name="ydn.error.ArgumentException"}z(K,pa);function gd(a){pa.call(this,a);this.name="ydn.error.TypeError"}z(gd,pa);function hd(a){pa.call(this,a);this.name="ydn.error.NotSupportedException"}z(hd,pa);function id(a){pa.call(this,a);this.name="ydn.error.NotImplementedException"}z(id,pa);function jd(a){pa.call(this,a);this.name="ydn.error.InvalidOperationException"}z(jd,pa); function kd(a){Error.captureStackTrace?Error.captureStackTrace(this,kd):this.stack=Error().stack||"";a&&(this.message=String(a));this.name="ydn.error.InternalError"}z(kd,Error);kd.prototype.name="ydn.error.InternalError";function ld(a,b){C.call(this,0,b);this.h=[]}z(ld,C);l=ld.prototype;l.nb=function(a,b){this.h.push([a,b]);return this};function md(a,b){for(var c=0;c<a.h.length;c++)a.h[c][0].call(a.h[c][1],b)}l.callback=function(a){this.h.length=0;ld.D.callback.call(this,a)};l.o=function(a){this.h.length=0;ld.D.o.call(this,a)};l.Ta=function(a){ld.D.Ta.call(this,a);a instanceof ld&&a.nb(function(a){md(this,a)},this);return this};l.Mb=function(){return this};var nd={READ_ONLY:"readonly",READ_WRITE:"readwrite",VERSION_CHANGE:"versionchange"},od=nd.READ_ONLY,L=nd.READ_WRITE,pd=nd.VERSION_CHANGE,qd=r.indexedDB||r.mozIndexedDB||r.webkitIndexedDB||r.moz_indexedDB||r.msIndexedDB;C.prototype.done=C.prototype.K;C.prototype.fail=C.prototype.mb;C.prototype.always=C.prototype.kb;ld.prototype.then=ld.prototype.then;function rd(a,b){var c,d;2==arguments.length&&x(arguments[1])?(c=!0,d=arguments[1].split(".")):d=(c=w(b))?b:arguments;for(c=c?0:1;c<d.length&&(a=a[d[c]],u(a));c++);return a}function sd(a,b,c){if(a)if(-1==b.indexOf("."))a[b]=c;else{b=b.split(".");for(var d=b.pop(),e;e=b.shift();)y(a[e])||(a[e]={}),a=a[e];a[d]=c}}var td={}; function vd(a){var b=[a];a=new wd;for(var c=0,d,e;void 0!==(e=b.pop());){0===c%4&&12<c+4&&(a.write(c),c=0);d=typeof e;if(e instanceof Array)if(c+=4,0<e.length){b.push(td);for(d=e.length;d--;)b.push(e[d]);continue}else a.write(c);else if("number"===d)c+=1,a.write(c),xd(a,e);else if(e instanceof Date)c+=2,a.write(c),xd(a,e.valueOf());else if("string"===d){c+=3;a.write(c);c=a;for(d=0;d<e.length;d++){var f=e.charCodeAt(d);126>=f?c.write(f+1):16510>=f?(f-=127,c.write(128|f>>8,f&255)):c.write(192|f>>10, f>>2|255,(f|3)<<6)}c.write(0)}else if(e===td)a.write(0);else return"";c=0}for(b=a.a.length;"00"===a.a[--b];);a.a.length=++b;return a.toString()}function yd(a){for(var b=[],c=b,d=[],e,f,g=new zd(a);null!=Ad(g);)if(0===g.a)c=d.pop();else{if(null===g.a)break;do{e=g.a/4|0;a=g.a%4;for(var h=0;h<e;h++)f=[],c.push(f),d.push(c),c=f;if(0===a&&12<g.a+4)Ad(g);else break}while(1);1===a?c.push(Bd(g)):2===a?c.push(new Date(Bd(g))):3===a?c.push(Cd(g)):0===a&&(c=d.pop())}return b[0]} function xd(a,b){var c,d,e;c=b;var f=e=d=0;if(0!==c)if(isFinite(c)){0>c&&(d=1,c=-c);f=0;if(2.2250738585072014E-308<=c){for(e=c;1>e;)f--,e*=2;for(;2<=e;)f++,e/=2;e=f+1023}f=e?Math.floor(4503599627370496*(c/Math.pow(2,f)-1)):Math.floor(c/4.9E-324)}else e=2047,isNaN(c)?f=0x8000000000000:-Infinity===c&&(d=1);c=d;d=e;e=f;c&&(e=0xfffffffffffff-e,d=2047-d);a.write((c?0:128)|d>>4);a.write((d&15)<<4|0|e/281474976710656);e%=281474976710656;c=0|e/4294967296;a.write(c>>8,c&255);e%=4294967296;c=0|e/65536;a.write(c>> 8,c&255);c=e%65536;a.write(c>>8,c&255)}function Bd(a){var b=Ad(a)|0,c=b>>7?!1:!0,d=c?-1:1,e=(b&127)<<4,b=Ad(a)|0,e=e+(b>>4);c&&(e=2047-e);for(var b=[c?15-(b&15):b&15],f=6;f--;)b.push(c?255-(Ad(a)|0):Ad(a)|0);a=0;for(f=7;f--;)a=a/256+b[f];a/=16;return 0===a&&0===e?0:(a+1)*Math.pow(2,e-1023)*d} function Cd(a){for(var b=[],c=0,d=0,e=0,f,g;;){f=Ad(a);if(0===f||null==f)break;0===c?(g=f>>6,2>g&&!isNaN(f)?b.push(String.fromCharCode(f-1)):(c=g,d=f<<10,e++)):2===c?(b.push(String.fromCharCode(d+f+127)),c=d=e=0):2===e?(d+=f<<2,e++):(b.push(String.fromCharCode(d|f>>6)),c=d=e=0)}return b.join("")}function zd(a){this.a=null;this.b=a;this.c=this.b.length-1;this.index=-1}function Ad(a){return a.a=a.index<a.c?parseInt(a.b.charAt(++a.index)+a.b.charAt(++a.index),16):null} function wd(){this.a=[];this.b=void 0}wd.prototype.write=function(a){for(var b=0;b<arguments.length;b++)this.b=arguments[b].toString(16),this.a.push(2===this.b.length?this.b:this.b="0"+this.b)};wd.prototype.toString=function(){return this.a.length?this.a.join(""):""};function Dd(a,b){var c=vd(a),d=vd(b);return c>d?1:c==d?0:-1};function Ed(a,b,c){ld.call(this,0,c);this.C=a;this.h=[];this.v=[];this.ra=[];this.a=null;this.ma="";this.M=0}z(Ed,ld);l=Ed.prototype;l.ma="";l.logger=D("ydn.db.Request");function Fd(a,b,c){a.a=b;a.ma=c;J(a.logger,a+" BEGIN");if(b){for(c=0;c<a.v.length;c++)a.v[c][0].call(a.v[c][1],b);a.v.length=0}}function Gd(a){var b=new Ed(a.C);a.M++;Fd(b,a.a,a.ma+"C"+a.M);return b}function Hd(a){J(a.logger,a+" END");a.a=null}l.Ab=function(){return!!this.a}; l.abort=function(){J(this.logger,this+" aborting "+this.a);if(this.a)if(ea(this.a.abort))this.a.abort();else if(ea(this.a.executeSql))this.a.executeSql("ABORT",[],function(){},function(){return!0});else throw new hd;else throw new Id(this+" No active transaction");};function M(a,b,c){var d=a.ra.shift();c=!!c;d?d[0].call(d[1],b,c,function(b,c){M(a,b,c)}):c?a.o(b):a.callback(b)}function Jd(a,b,c){a.ra.push([b,c])}function N(a,b,c){a.a?b.call(c,a.a):a.v.push([b,c])} l.callback=function(a){J(this.logger,this+" SUCCESS");Ed.D.callback.call(this,a)};l.o=function(a){J(this.logger,this+" ERROR");Ed.D.o.call(this,a)};l.state=function(){return this.c?this.b?"rejected":"resolved":"pending"};function O(a){var b="";a.ma&&(b=a.a?"*":"",b="["+a.ma+b+"]");return a.C+b}function Kd(a,b){var c=new Ed(a);M(c,b);return c}l.toString=function(){return"Request:"+O(this)}; l.Ya=function(){this.i&&this.c&&Mb(this)&&(Nb(this.i),this.i=0);this.f&&(this.f.G--,delete this.f);for(var a=this.g,b=!1;this.l.length&&!this.m;){var c=this.l.shift(),d=c[0],e=c[1],c=c[2];if(d=this.b?e:d)d=d.call(c||this.V,a),u(d)&&(this.b=this.b&&(d==a||d instanceof Error),this.g=a=d),oa(a)&&(this.m=b=!0)}this.g=a;b&&(b=ja(this.za,this,!0),d=ja(this.za,this,!1),a instanceof C?(Kb(a,b,d),a.J=!0):a.then(b,d))}; l.toJSON=function(){var a=(this.ma||"").match(/B(\d+)T(\d+)(?:Q(\d+?))?(?:R(\d+))?/)||[];return{method:this.C?this.C.split(":"):[],branchNo:parseFloat(a[1]),transactionNo:parseFloat(a[2]),queueNo:parseFloat(a[3]),requestNo:parseFloat(a[4])}};var P=qd&&qd.cmp?ja(qd.cmp,qd):Dd,Ld=[];var Md;Md=!1;var Nd=Wa;Nd&&(-1!=Nd.indexOf("Firefox")||-1!=Nd.indexOf("Camino")||-1!=Nd.indexOf("iPad")||-1!=Nd.indexOf("iPhone")||-1!=Nd.indexOf("iPod")||-1!=Nd.indexOf("Chrome")||-1!=Nd.indexOf("Android")||-1!=Nd.indexOf("Safari")&&(Md=!0));var Od=Md;function Pd(){0!=Qd&&(this[fa]||(this[fa]=++ga));this.pa=this.pa;this.zb=this.zb}var Qd=0;Pd.prototype.pa=!1;function Rd(a,b){this.type=a;this.target=b}Rd.prototype.preventDefault=function(){};function Sd(a,b){Rd.call(this,a,b)}z(Sd,Rd);Sd.prototype.a=function(){return this.s};function Td(a,b,c,d,e){Rd.call(this,a,b);this.version=c;this.wb=d;this.rb=e}z(Td,Sd);l=Td.prototype;l.name="ReadyEvent";l.version=NaN;l.wb=NaN;l.rb=null;l.Sb=function(){return this.version};l.Eb=function(){return this.wb};l.Db=function(){return this.rb};function Ud(a,b,c){Rd.call(this,c||"error",a);this.error=b}z(Ud,Sd);Ud.prototype.toString=function(){return this.name+":"+(this.error?this.error:"")}; Ud.prototype.name="ErrorEvent";Ud.prototype.error=null;Ud.prototype.b=function(){return this.error};function Vd(a,b){Ud.call(this,a,b,"fail")}z(Vd,Ud);Vd.prototype.name="FailEvent";function Wd(a,b,c){var d;if(y(a))d=a.store,b=a.id,null!=a.parent&&(c=new Wd(a.parent));else if(u(b))d=a;else if(d=a.lastIndexOf("^|"),b=a,0<d&&(b=a.substr(d),c=new Wd(a.substring(0,d))),b=b.split("^:"),d=b[0],b=b[1],!u(b))throw Error("Invalid key value: "+a);this.s=d;this.A=b;this.parent=c||null}l=Wd.prototype;l.toJSON=function(){var a={store:this.s,id:this.A};this.parent&&(a.parent=this.parent.toJSON());return a}; l.valueOf=function(){return(this.parent?this.parent.valueOf()+"^|":"")+this.s+"^:"+this.A};l.toString=function(){return this.valueOf().replace("^|","|").replace("^:",":")};l.Ob=function(){return this.s};l.Bb=function(){return this.A};function Xd(a){return v(a.A)?a.A.join("^|"):a.A instanceof Date?+a.A:a.A}l.Nb=function(){return this.parent};function Yd(a){if(w(a)){for(var b=[],c=0,d=a.length;c<d;c++)b[c]=a[c];return b}return a};function Q(a,b,c,d){a>b&&(b=a=void 0);null===a&&(a=void 0);null===b&&(b=void 0);this.lower=a;this.upper=b;this.lowerOpen=!!c;this.upperOpen=!!d}Q.prototype.lower=void 0;Q.prototype.upper=void 0;Q.prototype.toJSON=function(){return Zd(this)};function $d(a){return ae(a)}function be(a){return new Q(a,a,!1,!1)}function ce(a,b,c,d){return new Q(a,b,c,d)}function de(a,b){return new Q(void 0,a,void 0,!!b)}function ee(a,b){return new Q(a,void 0,!!b,void 0)} function fe(a){var b;if(v(a))b=Ra(a),b.push("\uffff");else if(x(a))b=a+"\uffff";else if(da(a))b=a+2.220460492503131E-16,a-=2.220460492503131E-16;else return be(a);return ce(a,b,!1,!0)}function Zd(a){a=a||{};return{lower:a.lower,upper:a.upper,lowerOpen:a.lowerOpen,upperOpen:a.upperOpen}} function ae(a){return null!=a?null!=a.upper&&null!=a.lower?ge.bound(a.lower,a.upper,!!a.lowerOpen,!!a.upperOpen):null!=a.upper?ge.upperBound(a.upper,a.upperOpen):null!=a.lower?ge.lowerBound(a.lower,a.lowerOpen):null:null}function he(a){if(a instanceof Q)return"";if(null!=a){if(y(a)){for(var b in a){var c;if(c=a.hasOwnProperty(b))c=!(0<=Ka(["lower","upper","lowerOpen","upperOpen"],b));if(c)return'invalid attribute "'+b+'" in key range object'}return""}return"key range must be an object"}return""} function ie(a,b){var c=a.lower,d=a.upper,e=a.lowerOpen,f=a.upperOpen;null!=b.lower&&(null==a.lower||b.lower>=a.lower)&&(c=b.lower,e=b.lowerOpen||a.lowerOpen);null!=b.upper&&(null==a.upper||b.upper<=a.upper)&&(d=b.upper,f=b.upperOpen||a.upperOpen);return ce(c,d,e,f)} function je(a,b,c,d,e){if(c)if(c.lowerOpen||c.upperOpen||null==c.lower||null==c.upper||0!==P(c.lower,c.upper)){if(null!=c.lower){var f=c.lowerOpen?" > ":" >= ";d.push(a+f+"?");e.push(ke(c.lower,b))}null!=c.upper&&(f=c.upperOpen?" < ":" <= ",d.push(a+f+"?"),e.push(ke(c.upper,b)))}else d.push(a+" = ?"),e.push(ke(c.lower,b))} function le(a,b,c,d){var e,f,g,h;if("starts"==a||"^"==a)return fe(b);if("<"==a||"<="==a)e=b,g="<"==a;else if(">"==a||">="==a)f=b,h=">"==a;else if("="==a||"=="==a)e=f=b;else throw new K("invalid op: "+a);if("<"==c||"<="==c)e=d,g="<"==c;else if(">"==c||">="==c)f=d,h=">"==c;else if(u(c))throw new K("invalid op2: "+c);return ce(f,e,h,g)}var ge=r.IDBKeyRange||r.webkitIDBKeyRange||Q;function me(a,b,c,d,e,f){u(e)||(e=v(a)?a.join(", "):a);if(null!=a&&!x(a)&&!w(a))throw new K("index keyPath for "+e+" must be a string or array, but "+a+" is "+typeof a);v(a)&&Object.freeze&&Object.freeze(a);!u(a)&&u(e)&&(a=e);this.keyPath=a;this.h=w(this.keyPath);this.b=e;this.type=ne(b);if(u(b)){if(!u(this.type))throw new K("type invalid in index: "+this.b);if(v(this.keyPath))throw new K('composite key for store "'+this.b+'" must not specified type');}this.unique=!!c;this.multiEntry=!!d;this.i=x(this.type)? this.type:oe;this.f=x(e)?e:v(a)?this.keyPath.join(","):a;this.c=Fa(this.f);this.a=this.h?null:this.keyPath.split(".");this.g=f||null}function pe(a,b){if(null!=b){if(w(a.keyPath)){for(var c=[],d=0,e=a.keyPath.length;d<e;d++){var f=rd(b,a.keyPath[d]);c[d]=f}return c}return rd(b,a.keyPath)}}function qe(a,b,c){for(var d=0;d<a.a.length;d++)d==a.a.length-1?b[a.a[d]]=c:y(b[a.a[d]])||(b[a.a[d]]={})}var oe="TEXT";function ke(a,b){if("DATE"==b){if(a instanceof Date)return+a}else return null!=b?a:vd(a)} function re(a,b){return"DATE"==b?new Date(a):u(b)?a:yd(a)}var se=["BLOB","DATE","INTEGER","NUMERIC",oe];function ne(a){if(x(a))return a=Ka(se,a),se[a]}l=me.prototype;l.getName=function(){return this.b};l.toJSON=function(){return{name:this.b,keyPath:this.keyPath,type:this.type,unique:this.unique,multiEntry:this.multiEntry}};l.clone=function(){var a=v(this.keyPath)?Ra(this.keyPath):this.keyPath;return new me(a,this.type,this.unique,this.multiEntry,this.b,this.g)}; function te(a,b){return null!=a||null!=b?null!=a?null!=b?w(a)&&w(b)?Ua(a,b)?null:"expect: "+a+", but: "+b:ue(a,b)?null:"expect: "+a+", but: "+b:"keyPath: "+a+" no longer defined":"newly define "+b:null}l.hint=function(a){if(!a)return this;var b=v(this.keyPath)?Ra(this.keyPath):this.keyPath,c=this.type;u(a.type)||"TEXT"!=c||(c=void 0);return new me(b,c,this.unique,this.multiEntry,a.b)}; l.toString=function(){var a=this.multiEntry?"MultiEntry":"";this.a&&1<this.a.length&&(a+="Compound");return a+"Index:"+this.b};function ve(a,b,c,d,e,f,g,h){if(!x(a))throw new K("store name must be a string");this.c=a;this.keyPath=u(b)?b:null;this.l=w(this.keyPath);if(null!==this.keyPath&&!x(this.keyPath)&&!this.l)throw new K("keyPath must be a string or array");if(null!=c&&!ca(c))throw new K('invalid autoIncrement value in store "'+a+'"');this.b=!!c;var k;if(null!=d){k=ne(d);if(!u(k))throw new K('type "'+d+'" for primary key in store "'+this.c+'" is invalid.');if(this.l)throw new K('composite key for store "'+this.c+'" must not specified type'); }this.type=null!=k?k:this.b?"INTEGER":void 0;this.h=x(this.keyPath)?this.keyPath.split("."):[];this.a=e||[];a=[];for(b=0;b<this.a.length;b++){c=this.a[b].getName();if(0<=a.indexOf(c))throw new K('index "'+c+'" already defined in store: '+this.c);a.push(c)}this.da=!!f;this.ia=!!g;this.v=x(this.type)?this.type:oe;this.g=v(this.keyPath)?this.keyPath.join(","):x(this.keyPath)?this.keyPath:"_ROWID_";this.f=Fa(this.g);if(this.m=!!h){if(this.keyPath)throw new K('encrypted store "'+this.c+'" must not use inline key'); if(this.b)throw new K('encrypted store "'+this.c+'" must not use key generator');}this.i=[]}l=ve.prototype;l.da=!1;l.ia=!1;l.toJSON=function(){for(var a=[],b=0;b<this.a.length;b++)a.push(this.a[b].toJSON());return{name:this.c,keyPath:this.keyPath,autoIncrement:this.b,type:this.type,indexes:a}}; function we(a){var b="name keyPath autoIncrement type indexes dispatchEvents fixed Sync encrypted".split(" "),c;for(c in a)if(a.hasOwnProperty(c)&&-1==Ka(b,c))throw new K('Unknown attribute "'+c+'"');b=[];c=a.indexes||[];if(v(c))for(var d=0;d<c.length;d++){var e;e=c[d];var f="name unique type keyPath multiEntry generator".split(" "),g=void 0;for(g in e)if(e.hasOwnProperty(g)&&-1==Ka(f,g))throw new K("Unknown field: "+g+" in "+S(e));e=new me(e.keyPath,e.type,e.unique,e.multiEntry,e.name,e.generator); u(e.keyPath)&&e.keyPath===a.keyPath||b.push(e)}return new ve(a.name,a.keyPath,a.autoIncrement,"undefined"===a.type||"null"===a.type?void 0:a.type,b,a.dispatchEvents,a.fixed,a.encrypted)}function xe(a,b,c,d,e,f,g){a=ye(a,b,c,d,e,f,g);b="";0!=c&&(b+="SELECT "+a.select);b+=" FROM "+a.S;a.u&&(b+=" WHERE "+a.u);a.group&&(b+=" GROUP BY "+a.group);a.U&&(b+=" ORDER BY "+a.U);return b} function ye(a,b,c,d,e,f,g){var h={select:"",S:"",u:"",group:"",U:""},k=a.g,m=a.f,n=null;d!==k&&x(d)&&(n=ze(a,d));var p=!!n,q=d||k,t=Fa(q),A=p?n.type:a.type,B=p&&n.multiEntry;h.S=Ae(a);6===c?h.select="COUNT("+m+")":3===c||1===c||2===c?(h.select=m,null!=d&&d!=k&&(h.select+=", "+t)):h.select="*";d=g?"DISTINCT ":"";k=[];B?(B=Fa("ydn.db.me:"+a.getName()+":"+n.getName()),h.select=6===c?"COUNT("+d+B+"."+t+")":3===c||1===c||2===c?"DISTINCT "+Ae(a)+"."+m+", "+B+"."+t+" AS "+q:"DISTINCT "+Ae(a)+".*, "+B+"."+ t+" AS "+q,h.S=B+" INNER JOIN "+Ae(a)+" USING ("+m+")",null!=e&&(je(B+"."+t,A,e,k,b),0<k.length&&(h.u=h.u?h.u+(" AND "+k.join(" AND ")):k.join(" AND ")))):null!=e&&(je(t,A,e,k,b),0<k.length&&(h.u=h.u?h.u+(" AND "+k.join(" AND ")):k.join(" AND ")));p&&!n.unique&&g&&(h.group=t);a=f?"DESC":"ASC";h.U=t+" "+a;p&&(h.U+=", "+m+" "+a);return h} function Be(a,b,c,d,e,f,g,h,k){var m,n,p,q;null!=e?(m=e.lower,n=e.upper,p=e.lowerOpen,q=e.upperOpen,f?null!=n?(e=P(h,n),-1==e?(n=h,q=k):0==e&&(q=k||q)):(n=h,q=k):null!=m?(e=P(h,m),1==e?(m=h,p=k):0==e&&(p=k||p)):(m=h,p=k)):f?(n=h,q=k):(m=h,p=k);e=new Q(m,n,!!p,!!q);d=d?ze(a,d):null;b=ye(a,c,b,d?d.f:a.g,e,f,g);b="SELECT "+b.select+" FROM "+b.S+(b.u?" WHERE "+b.u:"")+(b.group?" GROUP BY "+b.group:"")+" ORDER BY "+b.U;d&&(b+=", "+a.f+(f?"DESC":"ASC"));return b} function Ce(a,b,c,d,e,f,g,h,k,m){var n=ze(a,d),p=n.f;d=n.c;var q=a.f,t=k?" <":" >",t=g?t+" ":t+"= ";g=ke(f,n.type);h=ke(h,a.type);n="";e?(a=ye(a,c,b,p,e,k,m),a.u+=" AND ",n=d+t+"?",c.push(g)):(e=k?de(f,!0):ee(f,!0),a=ye(a,c,b,p,e,k,m),n=a.u,a.u="");a.u+="("+n+" OR ("+d+" = ? AND "+q+t+"?))";c.push(g);c.push(h);return"SELECT "+a.select+" FROM "+a.S+" WHERE "+a.u+(a.group?" GROUP BY "+a.group:"")+" ORDER BY "+a.U}l.clone=function(){return we(this.toJSON())};l.index=function(a){return this.a[a]||null}; function ze(a,b){return Oa(a.a,function(a){return a.getName()==b})}function De(a,b){for(var c=0;c<a.a.length;c++)if(!te(a.a[c].keyPath,b))return a.a[c];return null}function Ee(a,b){return b===a.keyPath?!0:Na(a.a,function(a){return a.getName()==b})}function Ae(a){return Fa(a.c)} function Fe(a,b){if(!b)return a;var c=a.b,d=v(a.keyPath)?Ra(a.keyPath):a.keyPath,e=a.type,f=Ma(a.a,function(a){return a.clone()});u(b.type)||"TEXT"!=e||(e=void 0);v(b.keyPath)&&x(d)&&d==b.keyPath.join(",")&&(d=Ra(b.keyPath));for(var g=0,h=b.a.length;g<h;g++)if(b.a[g].h)for(var k=b.a[g].getName(),m=f.length-1;0<=m;m--)if(0<=k.indexOf(f[m].getName())){f[m]=b.a[g].clone();break}for(g=0;g<f.length;g++)(h=ze(b,f[g].getName()))&&(f[g]=f[g].hint(h));return new ve(b.c,d,c,e,f)}l.getName=function(){return this.c}; function Ie(a){return!!a.keyPath}function Je(a,b,c){if(b){if(!a.keyPath&&null!=c)return c;if(a.l){c=[];for(var d=0;d<a.keyPath.length;d++)c.push(rd(b,a.keyPath[d]));return c}if(a.keyPath)return bb(b,a.h)}}function Ke(a,b,c){for(var d=0;d<a.h.length;d++){var e=a.h[d];if(d==a.h.length-1){b[e]=c;break}u(b[e])||(b[e]={});b=b[e]}} function Le(a,b,c){var d=[],e=[];c=u(c)?c:Je(a,b);u(c)&&(e.push(a.f),d.push(ke(c,a.type)));for(var f=0;f<a.a.length;f++){var g=a.a[f];if(!g.multiEntry&&g.getName()!==a.keyPath&&"_default_"!=g.getName()){var h=pe(g,b);null!=h&&(d.push(ke(h,g.type)),e.push(g.c))}}a.ia?a.ia&&!a.keyPath&&0==a.a.length&&(x(b)&&-1==b.indexOf(";base64,")?d.push(b):d.push(S(b)),e.push("_default_")):(d.push(S(b)),e.push("_default_"));a=[];for(f=d.length-1;0<=f;f--)a[f]="?";return{pb:e,vb:a,values:d,key:c}} function Me(a,b){if(!b)return"missing store: "+a.c;if(a.c!=b.c)return"store name, expect: "+a.c+", but: "+b.c;var c=te(a.keyPath,b.keyPath);if(c)return"keyPath, "+c;if(u(a.b)&&u(b.b)&&a.b!=b.b)return"autoIncrement, expect: "+a.b+", but: "+b.b;if(a.a.length!=b.a.length)return"indexes length, expect: "+a.a.length+", but: "+b.a.length;if(u(a.type)&&u(b.type)&&(w(a.type)?!Ua(a.type,b.type):a.type!=b.type))return"data type, expect: "+a.type+", but: "+b.type;for(c=0;c<a.a.length;c++){var d=ze(b,a.a[c].getName()), e;e=a.a[c];if(d)if(e.b!=d.b)e="name, expect: "+e.b+", but: "+d.b;else{var f=te(e.keyPath,d.keyPath);e=f?"keyPath, "+f:null!=e.unique&&null!=d.unique&&e.unique!=d.unique?"unique, expect: "+e.unique+", but: "+d.unique:null!=e.multiEntry&&null!=d.multiEntry&&e.multiEntry!=d.multiEntry?"multiEntry, expect: "+e.multiEntry+", but: "+d.multiEntry:u(e.type)&&u(d.type)&&(w(e.type)?!Ua(e.type,d.type):e.type!=d.type)?"data type, expect: "+e.type+", but: "+d.type:""}else e="no index for "+e.b;if(0<e.length)return'index "'+ a.a[c].getName()+'" '+e}return""}function Ne(a,b){if(b)for(var c=0;c<a.a.length;c++){var d=a.a[c],e=b;if(d.g){var f=d.g(e),g=typeof f;if("string"==g||"number"==g||f instanceof Date||v(f)){for(g=0;g<d.a.length-1;g++)y(e[d.a[g]])||(e[d.a[g]]={});e[d.a[d.a.length-1]]=f}}}}function Oe(a,b){a.i.push(b)}function Pe(a,b,c,d,e){for(var f=0;f<a.i.length;f++)d!==f&&a.i[f].call(e,b,c)}l.toString=function(){return"Store:"+this.c+"["+this.a.length+"index]"};function Qe(a){return!x(a)||sa(a)?{}:JSON.parse(a)}function Re(a){var b;try{b=S(a)}catch(c){b=""}return b?b.substr(0,70)+(70<b.length?"...":""):""}function S(a){return JSON.stringify(a,void 0,void 0)};function Se(a,b){if(!a||sa(a))throw new K("store_name must be provided for primary full text index");if(!b||sa(b))throw new K("index_name must be provided for primary full text index");this.s=a};function Te(a,b,c){this.name=a;this.a=b;this.b=c||"";if(-1==["","en","fr"].indexOf(this.b))throw new K('Unsupported lang "'+c+" for full text search index "+a);}Te.prototype.getName=function(){return this.name};Te.prototype.count=function(){return this.a.length};Te.prototype.index=function(a){return this.a[a]}; function Ue(a){var b=["name","sources","lang"],c;for(c in a)if(a.hasOwnProperty(c)&&-1==Ka(b,c))throw new K("Unknown field: "+c+" in "+S(a));if(!v(a.sources))throw new K("indexes require for full text search index "+a.name+", but "+a.sources+" of type "+typeof a.sources+" found.");b=a.sources.map(function(a){var b=["storeName","keyPath","weight"],c;for(c in a)if(a.hasOwnProperty(c)&&-1==Ka(b,c))throw new K("Unknown field: "+c+" in "+Re(a));return new Se(a.storeName,a.keyPath)});return new Te(a.name, b,a.lang)};function Ve(a,b){var c,d,e=b;if(y(a)){d=a;c=["version","stores","fullTextCatalogs"];for(var f in d)if(d.hasOwnProperty(f)&&-1==Ka(c,f))throw new K("Unknown field: "+f+" in schema.");c=d.version;var e=[],g=d.stores||[];if(!v(g))throw new K("stores must be array");for(f=0;f<g.length;f++){var h=we(g[f]);if(-1!=Pa(e,function(a){return a.name==h.getName()}))throw new K('duplicate store name "'+h.getName()+'".');e.push(h)}}else x(a)?c=0==a.length?void 0:parseFloat(a):da(a)&&(c=a);if(u(c)){if(!da(c)||0> c)throw new K("Invalid version: "+c+" ("+a+")");isNaN(c)&&(c=void 0)}if(u(b)&&(!v(b)||0<b.length&&!(b[0]instanceof ve)))throw new K("stores");this.version=c;this.b=!u(this.version);this.stores=e||[];c=[];if(d&&d.fullTextCatalogs)for(f=0;f<d.fullTextCatalogs.length;f++)e=Ue(d.fullTextCatalogs[f]),c[f]=e,T(this,e.getName())||(g=[new me("k",oe),new me("v",oe)],e=new ve(e.getName(),"id",!1,void 0,g,!1,!1,!1),this.stores.push(e));this.c=c} Ve.prototype.toJSON=function(){var a=Ma(this.stores,function(a){return a.toJSON()}),b={};b.stores=a;u(this.version)&&(b.version=this.version);return b};Ve.prototype.b=!1;Ve.prototype.a=function(){return!1};function We(a){return Ma(a.stores,function(a){return a.getName()})}Ve.prototype.count=function(){return this.stores.length};function T(a,b){return Oa(a.stores,function(a){return a.getName()==b})}function Xe(a,b){return Na(a.stores,function(a){return a.getName()==b})} function Ye(a,b,c,d){if(!b||a.stores.length!=b.stores.length)return"Number of store: "+a.stores.length+" vs "+b.stores.length;for(var e=0;e<a.stores.length;e++){var f=T(b,a.stores[e].getName());if(f){c&&(f=Fe(f,a.stores[e]));if(d)for(var g=f,h=a.stores[e],k=0;k<h.a.length;k++){var m=h.a[k];Ee(g,m.getName())||"BLOB"!=m.type||(m=new me(m.keyPath,m.type,m.unique,m.multiEntry,m.getName()),g.a.push(m))}f=Me(a.stores[e],f);if(0<f.length)return'store: "'+a.stores[e].getName()+'" '+f}else return'missing object store "'+ a.stores[e].getName()+'"'}return""};function Ze(a,b){Ve.call(this,a,b)}z(Ze,Ve);Ze.prototype.a=function(){return!0};function $e(a,b){a.stores.push(b)};function af(a){Error.captureStackTrace?Error.captureStackTrace(this,af):this.stack=Error().stack||"";a&&(this.message=String(a));this.name="ydn.error.ArgumentException"}z(af,Error);z(af,Error);function bf(a){Error.captureStackTrace?Error.captureStackTrace(this,bf):this.stack=Error().stack||"";a&&(this.message=String(a));this.name="ydn.error.InternalError"}z(bf,Error);bf.prototype.name="ydn.InternalError"; function cf(a){Error.captureStackTrace?Error.captureStackTrace(this,cf):this.stack=Error().stack||"";a&&(this.message=String(a));this.name="ydn.error.ConstraintError"}z(cf,Error);cf.prototype.name="ydn.error.ConstraintError";function df(a){Error.captureStackTrace?Error.captureStackTrace(this,df):this.stack=Error().stack||"";a&&(this.message=String(a));this.name="ydn.error.InvalidOperationException"}z(af,Error); function ef(a){Error.captureStackTrace?Error.captureStackTrace(this,ef):this.stack=Error().stack||"";a&&(this.message=String(a));this.name="ydn.error.InvalidOperationError"}z(ef,Error);function ue(a,b){var c;c=c||{};if(null!=a&&null!=b){if(w(a)&&w(b)){if(a.length!=b.length)return!1;for(var d=0;d<a.length;d++)if(-1==Pa(b,function(b){return ue(b,a[d])}))return!1;return!0}if(w(a))return 1==a.length&&ue(a[0],b);if(w(b))return 1==b.length&&ue(b[0],a);if(y(a)&&y(a)){for(var e in a)if(a.hasOwnProperty(e)&&!c[e]){var f=ue(a[e],b[e]);if(!f)return!1}for(e in b)if(b.hasOwnProperty(e)&&!c[e]&&(f=ue(a[e],b[e]),!f))return!1;return!0}return a===b}return!1};/* Copyright 2012 YDN Authors, Yathit. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License");. */ function U(a,b,c){c=c||{};var d="autoSchema connectionTimeout size mechanisms policy isSerial Encryption".split(" "),e;for(e in c)if(c.hasOwnProperty(e)&&-1==Ka(d,e))throw new K('Unknown attribute "'+e+'" in options.');if(c.mechanisms){if(!v(c.mechanisms))throw new K("mechanisms attribute must be an array but "+ba(c.mechanisms)+" found.");for(e=0;e<c.mechanisms.length;e++)if(!(0<=Ka(ff,c.mechanisms[e])))throw new K('Invalid mechanism "'+c.mechanisms[e]+'"');}this.G=c.mechanisms||(Od?Ta(ff,1):ff); this.l=c.size;this.J=u(c.connectionTimeout)?c.connectionTimeout:3E3;this.a=null;this.f=[];this.Ha=!1;var f;if(b instanceof Ve)f=b;else if(y(b))for(c.autoSchema||!u(b.stores)?f=new Ze(b):f=new Ve(b),d=b.stores?b.stores.length:0,e=0;e<d;e++){var g=T(f,b.stores[e].name);b.stores[e].Sync&&E(this.logger,"Synchronization option for "+g.getName()+" ignored.")}else f=new Ze;b=this.ub(c.Encryption);this.b=f;for(e=0;e<this.b.count();e++)if((this.b.stores[e]||null).m){if(!b)throw Error("encryption option must be defined"); this.lb(this.b.stores[e]||null)}u(a)&&this.v(a);this.h=new C}U.prototype.logger=D("ydn.db.con.Storage");U.prototype.M=function(a){if(u(a)){var b=function(b){a(b.toJSON());a=void 0};if(this.a)this.a.P(b);else{var c=this;this.transaction(function(a){c.a.P(b,a)},null,od)}}return this.b?this.b.toJSON():null};U.prototype.v=function(a){if(this.a)throw new jd("Already connected with "+this.i);this.i=a;gf(this)};U.prototype.getName=function(){return this.i};var ff="indexeddb sqlite websql localstorage sessionstorage userdata memory".split(" "); l=U.prototype;l.Xa=function(){return null}; function gf(a){function b(b,e){b?(I(a.logger,a+": ready."),a.qb=NaN,d.ib=function(){},d.Qa=function(){a.a=null},d.bb=function(){},setTimeout(function(){hf(a,e);jf(a)},10),c.callback(e)):(E(a.logger,a+": database connection fail "+e.name),setTimeout(function(){hf(a,new Vd(a,e));if(a.f){var b=a.logger;for(b&&b.log(Sc,"Purging "+a.f.length+" transactions request.",void 0);b=a.f.shift();)b.L&&b.L("error",e)}},10),c.o(e))}for(var c=new C,d=null,e=a.G,f=0;f<e.length;f++){var g=e[f].toLowerCase();if(d=a.Xa(g)){d= a.Xa(g);break}}null===d?(e=new cf("No storage mechanism found."),b(!1,new Vd(a,e))):Kb(d.na(a.i,a.b),function(a){this.a=d;b(!0,new Td("ready",this,parseFloat(d.Oa()),parseFloat(a),null))},function(a){E(this.logger,this+": opening fail");b(!1,a)},a)}l.Ra=function(){if(this.a)return this.a.oa()};l.Ka=function(a,b){this.h.pa().kb(a,b)};function hf(a,b){setTimeout(function(){a.b.b&&a.h.c||(b instanceof Ud?a.h.o(b.error):a.h.callback())},4)}function kf(a){return!!a.a&&a.a.Pa()} l.close=function(){this.a&&(this.a.close(),this.a=null,I(this.logger,this+" closed"))};l.Rb=function(){return this.a?this.a.hb():null};l.qb=NaN;function jf(a){var b=a.f.shift();b&&(I(a.logger,"pop tx queue["+(a.f.length+1)+"]"),a.transaction(b.Da,b.Jb,b.mode,b.L));a.qb=la()} function lf(a,b,c,d,e){I(a.logger,"push tx queue["+a.f.length+"]");a.f.push({Da:b,Jb:c,mode:d,L:e});100<a.f.length&&0==a.f.length%100&&E(a.logger,"Transaction queue stack size is "+a.f.length+". It is too large, possibility due to incorrect usage.")}l.Ha=!1; l.transaction=function(a,b,c,d){var e=b;if(x(b))e=[b];else if(null!=b)if(w(b)){if(0==b.length)throw new K("number of store names must more than 0");for(var f=0;f<b.length;f++)if(!x(b[f]))throw new K("store name at "+f+" must be string but found "+typeof b[f]);}else throw new K("store names must be an array");else e=null;if(this.a&&this.a.Pa()&&!this.Ha){var g=this,h=u(c)?c:od;h==pd&&(this.Ha=!0);this.a.Ca(function(b){a(b);a=null},e,h,function(a,b){ea(d)&&(d(a,b),d=void 0);h==pd&&(g.Ha=!1);jf(g)})}else lf(this, a,e,c,d)};l.lb=function(a){E(this.logger,"Encryption option for "+a.getName()+" ignored.")};l.ub=function(){return!1};l.toString=function(){return"Storage:"+this.a};U.prototype.close=U.prototype.close;U.prototype.getType=U.prototype.Ra;U.prototype.getName=U.prototype.getName;U.prototype.getSchema=U.prototype.M;U.prototype.onReady=U.prototype.Ka;U.prototype.setName=U.prototype.v;U.prototype.transaction=U.prototype.transaction;U.prototype.db=U.prototype.Rb;ma("ydn.db.version","1.1.5");ma("ydn.db.cmp",P);ma("ydn.db.deleteDatabase",function(a,b){for(var c,d=0;d<Ld.length;d++){var e=Ld[d](a,b);e&&(c=e)}return c||Kd("IDBVersionChangeEvent ",null)}); Td.prototype.name=Td.prototype.name;Td.prototype.getVersion=Td.prototype.Sb;Td.prototype.getOldVersion=Td.prototype.Eb;Td.prototype.getOldSchema=Td.prototype.Db;Ud.prototype.getError=Ud.prototype.b;Ed.prototype.abort=Ed.prototype.abort;Ed.prototype.canAbort=Ed.prototype.Ab;ld.prototype.progress=ld.prototype.nb;ld.prototype.promise=ld.prototype.Mb;ma("ydn.db.KeyRange",Q);Q.only=be;Q.bound=ce;Q.upperBound=de;Q.lowerBound=ee;function mf(a,b,c,d){Pd.call(this);this.b=c;this.s=c.getName();this.N=void 0;this.f=!1;this.w=null;this.i=a;this.ra=b;this.M=this.C=!1;this.v=d||4;this.l=this.c=this.a=void 0;this.G=function(){throw new kd;};this.V=function(){throw new kd;};this.qa=function(){}}z(mf,Pd);l=mf.prototype; l.jb=function(a,b