//>>built
define("dojox/store/db/IndexedDB","dojo/_base/declare dojo/_base/lang dojo/Deferred dojo/when dojo/promise/all dojo/store/util/SimpleQueryEngine dojo/store/util/QueryResults".split(" "),function(W,X,Y,U,Z,ha,ia){function aa(a){var b=new Y;a.onsuccess=function(e){b.resolve(e.target.result)};a.onerror=function(){a.error.message=a.webkitErrorMessage;b.reject(a.error)};return b.promise}function M(a,b,e){if(z||N.length){a&&(N.push({cursor:a,priority:b,retry:e}),N.sort(function(f,g){return f.priority>g.priority?
1:-1}));if(1<=z)return;var p=N.pop();a=p&&p.cursor}if(a)try{a["continue"](),z++}catch(f){if("TransactionInactiveError"!==f.name&&0!==f.name||!p)throw f;p.retry()}}function ja(){return!0}function ba(a){function b(g,d){p?g&&e.then(function(h){h.forEach(g,d)}):(g&&f.push(g),e||(e=a.filter(function(h){p=!0;for(var k=0,l=f.length;k<l;k++)f[k].call(d,h);return!0})));return e}var e,p,f=[];return{total:a.total,filter:function(g,d){var h;return b(function(k){h||(h=!g.call(d,k))})},forEach:b,map:function(g,
d){var h=[];return b(function(k){h.push(g.call(d,k))}).then(function(){return h})},then:function(g,d){return b().then(g,d)}}}var N=[],z=0,V=/(.*)\*$/,A=window.IDBKeyRange||window.webkitIDBKeyRange;return W(null,{constructor:function(a){W.safeMixin(this,a);var b=this,e=this.dbConfig;this.indices=e.stores[this.storeName];this.cachedCount={};for(var p in b.indices)a=b.indices[p],"number"===typeof a&&(b.indices[p]={preference:a});this.db=this.db||e.db;if(!this.db){var f=e.openRequest;f||(f=e.openRequest=
window.indexedDB.open(e.name||"dojo-db",parseInt(e.version,10)),f.onupgradeneeded=function(){var g=b.db=f.result,d;for(d in e.stores){var h=e.stores[d];if(g.objectStoreNames.contains(d))k=f.transaction.objectStore(d);else{k=h.idProperty||"id";var k=g.createObjectStore(d,{keyPath:k,autoIncrement:h[k]&&h[k].autoIncrement||!1})}for(var l in h)k.indexNames.contains(l)||"autoIncrement"===l||!1===h[l].indexed||k.createIndex(l,l,h[l])}},e.available=aa(f));this.available=e.available.then(function(g){return b.db=
g})}},idProperty:"id",storeName:"",indices:{},queryEngine:ha,transaction:function(){var a=this;this._currentTransaction=null;return{abort:function(){a._currentTransaction.abort()},commit:function(){a._currentTransaction=null}}},_getTransaction:function(){if(!this._currentTransaction){this._currentTransaction=this.db.transaction([this.storeName],"readwrite");var a=this;this._currentTransaction.oncomplete=function(){a._currentTransaction=null};this._currentTransaction.onerror=function(b){}}return this._currentTransaction},
_callOnStore:function(a,b,e,p){var f=this;return U(this.available,function d(){var h=f._currentTransaction;if(h)var k=!0;else h=f._getTransaction();if(k)try{var l=h.objectStore(f.storeName);e&&(l=l.index(e));var D=l[a].apply(l,b)}catch(E){if("TransactionInactiveError"===E.name||"InvalidStateError"===E.name)return f._currentTransaction=null,d();throw E;}else l=h.objectStore(f.storeName),e&&(l=l.index(e)),D=l[a].apply(l,b);return p?D:aa(D)})},get:function(a){return this._callOnStore("get",[a])},getIdentity:function(a){return a[this.idProperty]},
put:function(a,b){b=b||{};this.cachedCount={};return this._callOnStore(!1===b.overwrite?"add":"put",[a])},add:function(a,b){b=b||{};b.overwrite=!1;return this.put(a,b)},remove:function(a){this.cachedCount={};return this._callOnStore("delete",[a])},query:function(a,b){function e(m,c,r){O++;var n=d.indices[m];if(n&&!1!==n.indexed&&(c=c||n.preference*(r||1)||.001,c>ca))return ca=c,B=m,!0;O++}b=b||{};var p=b.start||0,f=b.count||Infinity,g=b.sort,d=this;if(a.forEach){var h={sort:g},k=this.queryEngine({},
h),l=[],D=0,E=0;return ba({total:{then:function(){return Z(l).then(function(m){return m.reduce(function(c,r){return c+r})*D/(E||1)}).then.apply(this,arguments)}},filter:function(m,c){var r=0,n=[],u,w={},x=[];return Z(a.map(function(C,F){function y(v){ka.push(v);for(var G=[],P=[];n.every(function(K){if(0<K.length)return(K=K[0])&&P.push(K),G.push(K)});){if(r>=p+f||0===P.length){u=!0;return}v=k(P)[0];n[G.indexOf(v)].shift();if(r++>=p&&(x.push(v),!m.call(c,v))){u=!0;return}G=[];P=[]}return!0}var ka=n[F]=
[],da=d.query(C,h);l[F]=da.total;return da.filter(function(v){if(!u){var G=d.getIdentity(v);E++;if(G in w)return!0;D++;w[G]=!0;return y(v)}}).then(function(v){y(null);return v})})).then(function(){return x})}})}var Q=JSON.stringify(a)+"-"+JSON.stringify(b.sort),B,ca=0,O=0,R;for(R in a){var q=a[R];var ea=!1,H,I=null;if("boolean"!==typeof q){if(q)if(q.from||q.to)ea=!0,function(m,c){I={test:function(r){return!m||m<=r&&(!c||c>=r)},keyRange:m?c?A.bound(m,c,q.excludeFrom,q.excludeTo):A.lowerBound(m,q.excludeFrom):
A.upperBound(c,q.excludeTo)}}(q.from,q.to);else if("object"===typeof q&&q.contains)(function(m){var c,r=(c=m[0])&&c.match&&c.match(V);r?(c=r[1],c=A.bound(c,c+"~")):c=A.only(c);I={test:function(n){return m.every(function(u){var w=u&&u.match&&u.match(V);return w?(u=w[1],n&&n.some(function(x){return x.slice(0,u.length)===u})):n&&-1<n.indexOf(u)})},keyRange:c}})(q.contains);else if(H=q.match&&q.match(V))H=H[1],I=new RegExp("^"+H),I.keyRange=A.bound(H,H+"~");I&&(a[R]=I);e(R,null,ea?.1:1)}}if(g)if(g=g[0],
g.attribute===B||e(g.attribute,1))var J=g.descending;else{var S=!0;p=0;f=Infinity}if(B){var T=B in a?(q=a[B])&&q.keyRange?q.keyRange:A.only(q):null;var fa=[T,J?"prev":"next"]}else fa=[];var t=d.cachedPosition;if(t&&t.queryId===Q&&t.offset<p&&1<O){var L=t.preFilterOffset+1;d.cachedPosition=t=X.mixin({},t)}else t=d.cachedPosition={offset:-1,preFilterOffset:-1,queryId:Q},2>O&&(t.offset=t.preFilterOffset=(L=p)-1);var la=this.queryEngine(a);J={total:{then:function(m){function c(n){d.cachedCount[Q]=n;return Math.round((t.offset+
1.01)/(t.preFilterOffset+1.01)*n)}var r=d.cachedCount[Q];return r?m(c(r)):(this.then=(T?d._callOnStore("count",[T],B):d._callOnStore("count")).then(c)).then.apply(this,arguments)}},filter:function(m,c){function r(){U(d._callOnStore("openCursor",fa,B,!0),function(w){z++;w.onsuccess=function(x){z--;var C=x.target.result;if(C){if(L){C.advance(L);z++;L=!1;return}t.preFilterOffset++;try{var F=C.value;b.join&&(F=b.join(F));return U(F,function(y){if(la.matches(y)&&(t.offset++,t.offset>=p&&(u.push(y),!m.call(c,
y)||t.offset>=p+f-1))){w.lastCursor=C;n.resolve(u);M();return}return M(C,b.priority,function(){L=t.preFilterOffset;r()})})}catch(y){n.reject(y)}}else n.resolve(u);M()};w.onerror=function(x){z--;n.reject(x);M()}})}var n=new Y,u=[];r();return n.promise}};return S?(k=this.queryEngine({},b),S=X.delegate(J.filter(ja).then(function(m){return k(m)})),S.total=J.total,new ia(S)):b.rawResults?J:ba(J)}})});