pouchdb-all-dbs
Version:
PouchDB allDbs plugin
2 lines (1 loc) • 9.49 kB
JavaScript
!function t(e,n,r){function o(u,c){if(!n[u]){if(!e[u]){var s="function"==typeof require&&require;if(!c&&s)return s(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var a=n[u]={exports:{}};e[u][0].call(a.exports,function(t){var n=e[u][1][t];return o(n?n:t)},a,a.exports,t,e,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(t,e,n){(function(e){"use strict";var r=t("pouchdb-promise");n.once=function(t){var e=!1;return n.getArguments(function(n){if(e)throw console.trace(),new Error("once called more than once");e=!0,t.apply(this,n)})},n.getArguments=function(t){return function(){for(var e=arguments.length,n=new Array(e),r=-1;++r<e;)n[r]=arguments[r];return t.call(this,n)}},n.toPromise=function(t){return n.getArguments(function(o){var i,u=this,c="function"==typeof o[o.length-1]?o.pop():!1;c&&(i=function(t,n){e.nextTick(function(){c(t,n)})});var s=new r(function(e,r){try{var i=n.once(function(t,n){t?r(t):e(n)});o.push(i),t.apply(u,o)}catch(c){r(c)}});return i&&s.then(function(t){i(null,t)},i),s.cancel=function(){return this},s})},n.inherits=t("inherits")}).call(this,t("_process"))},{_process:8,inherits:5,"pouchdb-promise":7}],2:[function(t,e,n){(function(n,r){"use strict";function o(){this.queue=new u,this.running=!1}var i=t("argsarray"),u=t("tiny-queue"),c=r.setImmediate||n.nextTick;o.prototype.add=function(t,e){e=e||function(){},this.queue.push({fun:t,callback:e}),this.processNext()},o.prototype.processNext=function(){var t=this;if(!t.running&&t.queue.length){t.running=!0;var e=t.queue.shift();c(function(){e.fun(i(function(n){e.callback.apply(null,n),t.running=!1,t.processNext()}))})}},e.exports=o}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:8,argsarray:3,"tiny-queue":9}],3:[function(t,e,n){"use strict";function r(t){return function(){var e=arguments.length;if(e){for(var n=[],r=-1;++r<e;)n[r]=arguments[r];return t.call(this,n)}return t.call(this,[])}}e.exports=r},{}],4:[function(t,e,n){(function(t){"use strict";function n(){a=!0;for(var t,e,n=l.length;n;){for(e=l,l=[],t=-1;++t<n;)e[t]();n=l.length}a=!1}function r(t){1!==l.push(t)||a||o()}var o,i=t.MutationObserver||t.WebKitMutationObserver;if(i){var u=0,c=new i(n),s=t.document.createTextNode("");c.observe(s,{characterData:!0}),o=function(){s.data=u=++u%2}}else if(t.setImmediate||"undefined"==typeof t.MessageChannel)o="document"in t&&"onreadystatechange"in t.document.createElement("script")?function(){var e=t.document.createElement("script");e.onreadystatechange=function(){n(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},t.document.documentElement.appendChild(e)}:function(){setTimeout(n,0)};else{var f=new t.MessageChannel;f.port1.onmessage=n,o=function(){f.port2.postMessage(0)}}var a,l=[];e.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(t,e,n){"function"==typeof Object.create?e.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},{}],6:[function(t,e,n){"use strict";function r(){}function o(t){if("function"!=typeof t)throw new TypeError("resolver must be a function");this.state=w,this.queue=[],this.outcome=void 0,t!==r&&s(this,t)}function i(t,e,n){this.promise=t,"function"==typeof e&&(this.onFulfilled=e,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function u(t,e,n){d(function(){var r;try{r=e(n)}catch(o){return v.reject(t,o)}r===t?v.reject(t,new TypeError("Cannot resolve promise with itself")):v.resolve(t,r)})}function c(t){var e=t&&t.then;return t&&"object"==typeof t&&"function"==typeof e?function(){e.apply(t,arguments)}:void 0}function s(t,e){function n(e){i||(i=!0,v.reject(t,e))}function r(e){i||(i=!0,v.resolve(t,e))}function o(){e(r,n)}var i=!1,u=f(o);"error"===u.status&&n(u.value)}function f(t,e){var n={};try{n.value=t(e),n.status="success"}catch(r){n.status="error",n.value=r}return n}function a(t){return t instanceof this?t:v.resolve(new this(r),t)}function l(t){var e=new this(r);return v.reject(e,t)}function h(t){function e(t,e){function r(t){u[e]=t,++c!==o||i||(i=!0,v.resolve(f,u))}n.resolve(t).then(r,function(t){i||(i=!0,v.reject(f,t))})}var n=this;if("[object Array]"!==Object.prototype.toString.call(t))return this.reject(new TypeError("must be an array"));var o=t.length,i=!1;if(!o)return this.resolve([]);for(var u=new Array(o),c=0,s=-1,f=new this(r);++s<o;)e(t[s],s);return f}function p(t){function e(t){n.resolve(t).then(function(t){i||(i=!0,v.resolve(c,t))},function(t){i||(i=!0,v.reject(c,t))})}var n=this;if("[object Array]"!==Object.prototype.toString.call(t))return this.reject(new TypeError("must be an array"));var o=t.length,i=!1;if(!o)return this.resolve([]);for(var u=-1,c=new this(r);++u<o;)e(t[u]);return c}var d=t("immediate"),v={},y=["REJECTED"],m=["FULFILLED"],w=["PENDING"];e.exports=o,o.prototype["catch"]=function(t){return this.then(null,t)},o.prototype.then=function(t,e){if("function"!=typeof t&&this.state===m||"function"!=typeof e&&this.state===y)return this;var n=new this.constructor(r);if(this.state!==w){var o=this.state===m?t:e;u(n,o,this.outcome)}else this.queue.push(new i(n,t,e));return n},i.prototype.callFulfilled=function(t){v.resolve(this.promise,t)},i.prototype.otherCallFulfilled=function(t){u(this.promise,this.onFulfilled,t)},i.prototype.callRejected=function(t){v.reject(this.promise,t)},i.prototype.otherCallRejected=function(t){u(this.promise,this.onRejected,t)},v.resolve=function(t,e){var n=f(c,e);if("error"===n.status)return v.reject(t,n.value);var r=n.value;if(r)s(t,r);else{t.state=m,t.outcome=e;for(var o=-1,i=t.queue.length;++o<i;)t.queue[o].callFulfilled(e)}return t},v.reject=function(t,e){t.state=y,t.outcome=e;for(var n=-1,r=t.queue.length;++n<r;)t.queue[n].callRejected(e);return t},o.resolve=a,o.reject=l,o.all=h,o.race=p},{immediate:4}],7:[function(t,e,n){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t["default"]:t}var o=r(t("lie")),i="function"==typeof Promise?Promise:o;e.exports=i},{lie:6}],8:[function(t,e,n){function r(){h&&a&&(h=!1,a.length?l=a.concat(l):p=-1,l.length&&o())}function o(){if(!h){var t=c(r);h=!0;for(var e=l.length;e;){for(a=l,l=[];++p<e;)a&&a[p].run();p=-1,e=l.length}a=null,h=!1,s(t)}}function i(t,e){this.fun=t,this.array=e}function u(){}var c,s,f=e.exports={};!function(){try{c=setTimeout}catch(t){c=function(){throw new Error("setTimeout is not defined")}}try{s=clearTimeout}catch(t){s=function(){throw new Error("clearTimeout is not defined")}}}();var a,l=[],h=!1,p=-1;f.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];l.push(new i(t,e)),1!==l.length||h||c(o,0)},i.prototype.run=function(){this.fun.apply(null,this.array)},f.title="browser",f.browser=!0,f.env={},f.argv=[],f.version="",f.versions={},f.on=u,f.addListener=u,f.once=u,f.off=u,f.removeListener=u,f.removeAllListeners=u,f.emit=u,f.binding=function(t){throw new Error("process.binding is not supported")},f.cwd=function(){return"/"},f.chdir=function(t){throw new Error("process.chdir is not supported")},f.umask=function(){return 0}},{}],9:[function(t,e,n){"use strict";function r(){this.length=0}r.prototype.push=function(t){var e={item:t};this.last?this.last=this.last.next=e:this.last=this.first=e,this.length++},r.prototype.shift=function(){var t=this.first;return t?(this.first=t.next,--this.length||(this.last=void 0),t.item):void 0},r.prototype.slice=function(t,e){t="undefined"==typeof t?0:t,e="undefined"==typeof e?1/0:e;for(var n=[],r=0,o=this.first;o&&!(--e<0);o=o.next)++r>t&&n.push(o.item);return n},e.exports=r},{}],10:[function(t,e,n){"use strict";function r(t){return c+t}function o(t){return t.slice(c.length)}var i=t("./pouch-utils"),u=t("./taskqueue"),c="db_";e.exports=function(t){function e(t){t&&console.error(t)}function n(){p.add(function(e){return a?e():(a=new t(h),void e())})}function s(t){return t.replace(/^_pouch_/,"")}function f(t){return t===h||-1!==t.indexOf("-mrview-")||/^https?:\/\//.test(t)}var a,l,h="pouch__all_dbs__",p=new u;t.on("created",function(t){t=s(t),f(t)||(t=r(t),n(),p.add(function(e){a.get(t).then(function(){})["catch"](function(e){if("not_found"!==e.name)throw e;return a.put({_id:t})}).then(function(){l&&(l[t]=!0),e()},e)},e))}),t.on("destroyed",function(t){t=s(t),f(t)||(t=r(t),n(),p.add(function(e){a.get(t).then(function(t){return a.remove(t)})["catch"](function(t){if("not_found"!==t.name)throw t}).then(function(){l&&delete l[t],e()},e)},e))}),t.allDbs=i.toPromise(function(t){n(),p.add(function(t){if(l)return t(null,Object.keys(l).map(o));var e={startkey:c,endkey:c+""};a.allDocs(e).then(function(e){l={};var n=[];e.rows.forEach(function(t){n.push(o(t.key)),l[t.key]=!0}),t(null,n)})["catch"](function(e){console.error(e),t(e)})},t)}),t.resetAllDbs=i.toPromise(function(t){p.add(function(t){a.destroy().then(function(){a=null,l=null,t()})["catch"](function(e){console.error(e),t(e)})},t)})},"undefined"!=typeof window&&window.PouchDB&&e.exports(window.PouchDB)},{"./pouch-utils":1,"./taskqueue":2}]},{},[10]);