snow-cms 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-browser.es.js +1 -1
- package/dist/index-browser2.es.js +1 -1
- package/dist/index.js +39 -39
- package/dist/index2.es.js +1 -1
- package/dist/index3.es.js +1 -1
- package/dist/index4.es.js +1 -1
- package/dist/milkdown.js +15 -15
- package/dist/rolldown-runtime.js +1 -1
- package/package.json +9 -9
package/dist/index-browser.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e,t}from"./rolldown-runtime.js";var n=function(e){return atob(e)},r=function(e){return btoa(e)};function i(e,t){e||=[],t||={};try{return new Blob(e,t)}catch(i){if(i.name!==`TypeError`)throw i;for(var n=new(typeof BlobBuilder<`u`?BlobBuilder:typeof MSBlobBuilder<`u`?MSBlobBuilder:typeof MozBlobBuilder<`u`?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}function a(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),i=0;i<t;i++)r[i]=e.charCodeAt(i);return n}function o(e,t){return i([a(e)],{type:t})}function s(e,t){return o(n(e),t)}function c(e){for(var t=``,n=new Uint8Array(e),r=n.byteLength,i=0;i<r;i++)t+=String.fromCharCode(n[i]);return t}function l(e,t){var n=new FileReader,r=typeof n.readAsBinaryString==`function`;n.onloadend=function(e){var n=e.target.result||``;if(r)return t(n);t(c(n))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function u(e,t){l(e,function(e){t(e)})}function d(e,t){u(e,function(e){t(r(e))})}function f(e,t){var n=new FileReader;n.onloadend=function(e){t(e.target.result||new ArrayBuffer(0))},n.readAsArrayBuffer(e)}var p=class extends Error{constructor(e,t,n){super(),this.status=e,this.name=t,this.message=n,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}};new p(401,`unauthorized`,`Name or password is incorrect.`);var m=new p(400,`bad_request`,`Missing JSON list of 'docs'`),h=new p(404,`not_found`,`missing`),g=new p(409,`conflict`,`Document update conflict`),_=new p(400,`bad_request`,`_id field must contain a string`),v=new p(412,`missing_id`,`_id is required for puts`),y=new p(400,`bad_request`,`Only reserved document ids may start with underscore.`);new p(412,`precondition_failed`,`Database not open`);var b=new p(500,`unknown_error`,`Database encountered an unknown error`),x=new p(500,`badarg`,`Some query argument is invalid`);new p(400,`invalid_request`,`Request was invalid`);var S=new p(400,`query_parse_error`,`Some query parameter is invalid`),ee=new p(500,`doc_validation`,`Bad special document member`),C=new p(400,`bad_request`,`Something wrong with the request`),w=new p(400,`bad_request`,`Document must be a JSON object`);new p(404,`not_found`,`Database not found`);var te=new p(500,`indexed_db_went_bad`,`unknown`);new p(500,`web_sql_went_bad`,`unknown`),new p(500,`levelDB_went_went_bad`,`unknown`),new p(403,`forbidden`,`Forbidden by design doc validate_doc_update function`);var ne=new p(400,`bad_request`,`Invalid rev format`);new p(412,`file_exists`,`The database could not be created, the file already exists.`);var re=new p(412,`missing_stub`,`A pre-existing attachment stub wasn't found`);new p(413,`invalid_url`,`Provided URL is invalid`);function T(e,t){function n(t){for(var n=Object.getOwnPropertyNames(e),r=0,i=n.length;r<i;r++)typeof e[n[r]]!=`function`&&(this[n[r]]=e[n[r]]);this.stack===void 0&&(this.stack=Error().stack),t!==void 0&&(this.reason=t)}return n.prototype=p.prototype,new n(t)}function E(e){if(typeof e!=`object`){var t=e;e=b,e.data=t}return`error`in e&&e.error===`conflict`&&(e.name=`conflict`,e.status=409),`name`in e||(e.name=e.error||`unknown`),`status`in e||(e.status=500),`message`in e||(e.message=e.message||e.reason),`stack`in e||(e.stack=Error().stack),e}var D=t(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,`defaultMaxListeners`,{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),O,ie=new Uint8Array(16);function ae(){if(!O&&(O=typeof crypto<`u`&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<`u`&&typeof msCrypto.getRandomValues==`function`&&msCrypto.getRandomValues.bind(msCrypto),!O))throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);return O(ie)}var oe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function se(e){return typeof e==`string`&&oe.test(e)}for(var k=[],A=0;A<256;++A)k.push((A+256).toString(16).substr(1));function ce(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=(k[e[t+0]]+k[e[t+1]]+k[e[t+2]]+k[e[t+3]]+`-`+k[e[t+4]]+k[e[t+5]]+`-`+k[e[t+6]]+k[e[t+7]]+`-`+k[e[t+8]]+k[e[t+9]]+`-`+k[e[t+10]]+k[e[t+11]]+k[e[t+12]]+k[e[t+13]]+k[e[t+14]]+k[e[t+15]]).toLowerCase();if(!se(n))throw TypeError(`Stringified UUID is invalid`);return n}function j(e,t,n){e||={};var r=e.random||(e.rng||ae)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n||=0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return ce(r)}var M=e(t(((e,t)=>{(function(n){if(typeof e==`object`)t.exports=n();else if(typeof define==`function`&&define.amd)define(n);else{var r;try{r=window}catch{r=self}r.SparkMD5=n()}})(function(e){var t=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`a`,`b`,`c`,`d`,`e`,`f`];function n(e,t){var n=e[0],r=e[1],i=e[2],a=e[3];n+=(r&i|~r&a)+t[0]-680876936|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[1]-389564586|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[2]+606105819|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[3]-1044525330|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[4]-176418897|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[5]+1200080426|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[6]-1473231341|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[7]-45705983|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[8]+1770035416|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[9]-1958414417|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[10]-42063|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[11]-1990404162|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[12]+1804603682|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[13]-40341101|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[14]-1502002290|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[15]+1236535329|0,r=(r<<22|r>>>10)+i|0,n+=(r&a|i&~a)+t[1]-165796510|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[6]-1069501632|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[11]+643717713|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[0]-373897302|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[5]-701558691|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[10]+38016083|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[15]-660478335|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[4]-405537848|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[9]+568446438|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[14]-1019803690|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[3]-187363961|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[8]+1163531501|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[13]-1444681467|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[2]-51403784|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[7]+1735328473|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[12]-1926607734|0,r=(r<<20|r>>>12)+i|0,n+=(r^i^a)+t[5]-378558|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[8]-2022574463|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[11]+1839030562|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[14]-35309556|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[1]-1530992060|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[4]+1272893353|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[7]-155497632|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[10]-1094730640|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[13]+681279174|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[0]-358537222|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[3]-722521979|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[6]+76029189|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[9]-640364487|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[12]-421815835|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[15]+530742520|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[2]-995338651|0,r=(r<<23|r>>>9)+i|0,n+=(i^(r|~a))+t[0]-198630844|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[7]+1126891415|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[14]-1416354905|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[5]-57434055|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[12]+1700485571|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[3]-1894986606|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[10]-1051523|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[1]-2054922799|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[8]+1873313359|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[15]-30611744|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[6]-1560198380|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[13]+1309151649|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[4]-145523070|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[11]-1120210379|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[2]+718787259|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[9]-343485551|0,r=(r<<21|r>>>11)+i|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=i+e[2]|0,e[3]=a+e[3]|0}function r(e){var t=[],n;for(n=0;n<64;n+=4)t[n>>2]=e.charCodeAt(n)+(e.charCodeAt(n+1)<<8)+(e.charCodeAt(n+2)<<16)+(e.charCodeAt(n+3)<<24);return t}function i(e){var t=[],n;for(n=0;n<64;n+=4)t[n>>2]=e[n]+(e[n+1]<<8)+(e[n+2]<<16)+(e[n+3]<<24);return t}function a(e){var t=e.length,i=[1732584193,-271733879,-1732584194,271733878],a,o,s,c,l,u;for(a=64;a<=t;a+=64)n(i,r(e.substring(a-64,a)));for(e=e.substring(a-64),o=e.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<o;a+=1)s[a>>2]|=e.charCodeAt(a)<<(a%4<<3);if(s[a>>2]|=128<<(a%4<<3),a>55)for(n(i,s),a=0;a<16;a+=1)s[a]=0;return c=t*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(c[2],16),u=parseInt(c[1],16)||0,s[14]=l,s[15]=u,n(i,s),i}function o(e){var t=e.length,r=[1732584193,-271733879,-1732584194,271733878],a,o,s,c,l,u;for(a=64;a<=t;a+=64)n(r,i(e.subarray(a-64,a)));for(e=a-64<t?e.subarray(a-64):new Uint8Array,o=e.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<o;a+=1)s[a>>2]|=e[a]<<(a%4<<3);if(s[a>>2]|=128<<(a%4<<3),a>55)for(n(r,s),a=0;a<16;a+=1)s[a]=0;return c=t*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(c[2],16),u=parseInt(c[1],16)||0,s[14]=l,s[15]=u,n(r,s),r}function s(e){var n=``,r;for(r=0;r<4;r+=1)n+=t[e>>r*8+4&15]+t[e>>r*8&15];return n}function c(e){var t;for(t=0;t<e.length;t+=1)e[t]=s(e[t]);return e.join(``)}c(a(`hello`)),typeof ArrayBuffer<`u`&&!ArrayBuffer.prototype.slice&&(function(){function t(e,t){return e=e|0||0,e<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(n,r){var i=this.byteLength,a=t(n,i),o=i,s,c,l,u;return r!==e&&(o=t(r,i)),a>o?new ArrayBuffer(0):(s=o-a,c=new ArrayBuffer(s),l=new Uint8Array(c),u=new Uint8Array(this,a,s),l.set(u),c)}})();function l(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function u(e,t){var n=e.length,r=new ArrayBuffer(n),i=new Uint8Array(r),a;for(a=0;a<n;a+=1)i[a]=e.charCodeAt(a);return t?i:r}function d(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function f(e,t,n){var r=new Uint8Array(e.byteLength+t.byteLength);return r.set(new Uint8Array(e)),r.set(new Uint8Array(t),e.byteLength),n?r:r.buffer}function p(e){var t=[],n=e.length,r;for(r=0;r<n-1;r+=2)t.push(parseInt(e.substr(r,2),16));return String.fromCharCode.apply(String,t)}function m(){this.reset()}return m.prototype.append=function(e){return this.appendBinary(l(e)),this},m.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t=this._buff.length,i;for(i=64;i<=t;i+=64)n(this._hash,r(this._buff.substring(i-64,i)));return this._buff=this._buff.substring(i-64),this},m.prototype.end=function(e){var t=this._buff,n=t.length,r,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a;for(r=0;r<n;r+=1)i[r>>2]|=t.charCodeAt(r)<<(r%4<<3);return this._finish(i,n),a=c(this._hash),e&&(a=p(a)),this.reset(),a},m.prototype.reset=function(){return this._buff=``,this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},m.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},m.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},m.prototype._finish=function(e,t){var r=t,i,a,o;if(e[r>>2]|=128<<(r%4<<3),r>55)for(n(this._hash,e),r=0;r<16;r+=1)e[r]=0;i=this._length*8,i=i.toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(i[2],16),o=parseInt(i[1],16)||0,e[14]=a,e[15]=o,n(this._hash,e)},m.hash=function(e,t){return m.hashBinary(l(e),t)},m.hashBinary=function(e,t){var n=c(a(e));return t?p(n):n},m.ArrayBuffer=function(){this.reset()},m.ArrayBuffer.prototype.append=function(e){var t=f(this._buff.buffer,e,!0),r=t.length,a;for(this._length+=e.byteLength,a=64;a<=r;a+=64)n(this._hash,i(t.subarray(a-64,a)));return this._buff=a-64<r?new Uint8Array(t.buffer.slice(a-64)):new Uint8Array,this},m.ArrayBuffer.prototype.end=function(e){var t=this._buff,n=t.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i,a;for(i=0;i<n;i+=1)r[i>>2]|=t[i]<<(i%4<<3);return this._finish(r,n),a=c(this._hash),e&&(a=p(a)),this.reset(),a},m.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array,this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.ArrayBuffer.prototype.getState=function(){var e=m.prototype.getState.call(this);return e.buff=d(e.buff),e},m.ArrayBuffer.prototype.setState=function(e){return e.buff=u(e.buff,!0),m.prototype.setState.call(this,e)},m.ArrayBuffer.prototype.destroy=m.prototype.destroy,m.ArrayBuffer.prototype._finish=m.prototype._finish,m.ArrayBuffer.hash=function(e,t){var n=c(o(new Uint8Array(e)));return t?p(n):n},m})}))()),le=self.setImmediate||self.setTimeout,ue=32768;function de(e){return r(e)}function fe(e,t,n,r,i){(n>0||r<t.size)&&(t=t.slice(n,r)),f(t,function(t){e.append(t),i()})}function N(e,t,n,r,i){(n>0||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t),i()}function P(e,t){var n=typeof e==`string`,r=n?e.length:e.size,i=Math.min(ue,r),a=Math.ceil(r/i),o=0,s=n?new M.default:new M.default.ArrayBuffer,c=n?N:fe;function l(){le(d)}function u(){t(de(s.end(!0))),s.destroy()}function d(){var t=o*i,n=t+i;o++,o<a?c(s,e,t,n,l):c(s,e,t,n,u)}d()}function F(e){return M.default.hash(e)}var I=e(D());function L(e){return typeof ArrayBuffer<`u`&&e instanceof ArrayBuffer||typeof Blob<`u`&&e instanceof Blob}function R(e){return e instanceof ArrayBuffer?e.slice(0):e.slice(0,e.size,e.type)}var z=Function.prototype.toString,B=z.call(Object);function V(e){var t=Object.getPrototypeOf(e);if(t===null)return!0;var n=t.constructor;return typeof n==`function`&&n instanceof n&&z.call(n)==B}function H(e){var t,n,r;if(!e||typeof e!=`object`)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=H(e[n]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(L(e))return R(e);if(!V(e))return e;for(n in t={},e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=H(e[n]);i!==void 0&&(t[n]=i)}return t}function U(e){var t=!1;return function(...n){if(t)throw Error(`once called more than once`);t=!0,e.apply(this,n)}}function W(e){return function(...t){t=H(t);var n=this,r=typeof t[t.length-1]==`function`?t.pop():!1,i=new Promise(function(r,i){var a;try{var o=U(function(e,t){e?i(e):r(t)});t.push(o),a=e.apply(n,t),a&&typeof a.then==`function`&&r(a)}catch(e){i(e)}});return r&&i.then(function(e){r(null,e)},r),i}}function pe(e,t,n){if(e.constructor.listeners(`debug`).length){for(var r=[`api`,e.name,t],i=0;i<n.length-1;i++)r.push(n[i]);e.constructor.emit(`debug`,r);var a=n[n.length-1];n[n.length-1]=function(n,r){var i=[`api`,e.name,t];i=i.concat(n?[`error`,n]:[`success`,r]),e.constructor.emit(`debug`,i),a(n,r)}}}function me(e,t){return W(function(...n){if(this._closed)return Promise.reject(Error(`database is closed`));if(this._destroyed)return Promise.reject(Error(`database is destroyed`));var r=this;return pe(r,e,n),this.taskqueue.isReady?t.apply(this,n):new Promise(function(t,i){r.taskqueue.addTask(function(a){a?i(a):t(r[e].apply(r,n))})})})}function G(e,t){for(var n={},r=0,i=t.length;r<i;r++){var a=t[r];a in e&&(n[a]=e[a])}return n}var he=6;function K(e){return e}function ge(e){return[{ok:e}]}function _e(e,t,n){var r=t.docs,i=new Map;r.forEach(function(e){i.has(e.id)?i.get(e.id).push(e):i.set(e.id,[e])});var a=i.size,o=0,s=Array(a);function c(){var e=[];s.forEach(function(t){t.docs.forEach(function(n){e.push({id:t.id,docs:[n]})})}),n(null,{results:e})}function l(){++o===a&&c()}function u(e,t,n){s[e]={id:t,docs:n},l()}var d=[];i.forEach(function(e,t){d.push(t)});var f=0;function p(){if(!(f>=d.length)){var e=Math.min(f+he,d.length),t=d.slice(f,e);m(t,f),f+=t.length}}function m(n,r){n.forEach(function(n,a){var o=r+a,s=i.get(n),c=G(s[0],[`atts_since`,`attachments`]);c.open_revs=s.map(function(e){return e.rev}),c.open_revs=c.open_revs.filter(K);var l=K;c.open_revs.length===0&&(delete c.open_revs,l=ge),[`revs`,`attachments`,`binary`,`ajax`,`latest`].forEach(function(e){e in t&&(c[e]=t[e])}),e.get(n,c,function(e,t){u(o,n,e?[{error:e}]:l(t)),p()})})}p()}var q;try{localStorage.setItem(`_pouch_check_localstorage`,1),q=!!localStorage.getItem(`_pouch_check_localstorage`)}catch{q=!1}function J(){return q}var Y=typeof queueMicrotask==`function`?queueMicrotask:function(e){Promise.resolve().then(e)},ve=class extends I.default{constructor(){super(),this._listeners={},J()&&addEventListener(`storage`,e=>{this.emit(e.key)})}addListener(e,t,n,r){if(this._listeners[t])return;var i=!1,a=this;function o(){if(!a._listeners[t])return;if(i){i=`waiting`;return}i=!0;var e=G(r,[`style`,`include_docs`,`attachments`,`conflicts`,`filter`,`doc_ids`,`view`,`since`,`query_params`,`binary`,`return_docs`]);function s(){i=!1}n.changes(e).on(`change`,function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on(`complete`,function(){i===`waiting`&&Y(o),i=!1}).on(`error`,s)}this._listeners[t]=o,this.on(e,o)}removeListener(e,t){t in this._listeners&&(super.removeListener(e,this._listeners[t]),delete this._listeners[t])}notifyLocalWindows(e){J()&&(localStorage[e]=localStorage[e]===`a`?`b`:`a`)}notify(e){this.emit(e),this.notifyLocalWindows(e)}};function X(e){if(typeof console<`u`&&typeof console[e]==`function`){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function ye(e,t,n){try{return!e(t,n)}catch(e){return T(C,`Filter function threw: `+e.toString())}}function be(e){var t={},n=e.filter&&typeof e.filter==`function`;return t.query=e.query_params,function(r){r.doc||={};var i=n&&ye(e.filter,r.doc,t);if(typeof i==`object`)return i;if(i)return!1;if(!e.include_docs)delete r.doc;else if(!e.attachments)for(var a in r.doc._attachments)Object.prototype.hasOwnProperty.call(r.doc._attachments,a)&&(r.doc._attachments[a].stub=!0);return!0}}function xe(){}xe.name;function Se(e){var t;if(e?typeof e==`string`?/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=T(y)):t=T(_):t=T(v),t)throw t}function Z(e){return typeof e._remote==`boolean`?e._remote:typeof e.type==`function`?(X(`warn`,`db.type() is deprecated and will be removed in a future version of PouchDB`),e.type()===`http`):!1}function Ce(e,t){return`listenerCount`in e?e.listenerCount(t):I.default.listenerCount(e,t)}function Q(e){if(!e)return null;var t=e.split(`/`);return t.length===2?t:t.length===1?[e,e]:null}function we(e){var t=Q(e);return t?t.join(`/`):null}function Te(e,t){var n=[],r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n.push(i),r.push(t[i]));return n.push(e),Function.apply(null,n).apply(null,r)}function $(e,t,n){return e.get(t).catch(function(e){if(e.status!==404)throw e;return{}}).then(function(r){var i=r._rev,a=n(r);return a?(a._id=t,a._rev=i,Ee(e,a,n)):{updated:!1,rev:i}})}function Ee(e,t,n){return e.put(t).then(function(e){return{updated:!0,rev:e.rev}},function(r){if(r.status!==409)throw r;return $(e,t._id,n)})}function De(e,t){if(!t)return j().replace(/-/g,``).toLowerCase();var n=Object.assign({},e);return delete n._rev_tree,F(JSON.stringify(n))}var Oe=j;export{ne as A,s as B,j as C,ee as D,C as E,S as F,l as G,d as H,g as I,n as K,b as L,h as M,re as N,te as O,w as P,T as R,F as S,x as T,u as U,o as V,i as W,Te as _,be as a,Oe as b,Se as c,Y as d,we as f,De as g,G as h,H as i,m as j,_ as k,Z as l,Q as m,me as n,X as o,U as p,r as q,_e as r,J as s,ve as t,Ce as u,W as v,D as w,P as x,$ as y,E as z};
|
|
1
|
+
import{r as e,t}from"./rolldown-runtime.js";var n=function(e){return atob(e)},r=function(e){return btoa(e)};function i(e,t){e||=[],t||={};try{return new Blob(e,t)}catch(i){if(i.name!==`TypeError`)throw i;for(var n=new(typeof BlobBuilder<`u`?BlobBuilder:typeof MSBlobBuilder<`u`?MSBlobBuilder:typeof MozBlobBuilder<`u`?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}function a(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),i=0;i<t;i++)r[i]=e.charCodeAt(i);return n}function o(e,t){return i([a(e)],{type:t})}function s(e,t){return o(n(e),t)}function c(e){for(var t=``,n=new Uint8Array(e),r=n.byteLength,i=0;i<r;i++)t+=String.fromCharCode(n[i]);return t}function l(e,t){var n=new FileReader,r=typeof n.readAsBinaryString==`function`;n.onloadend=function(e){var n=e.target.result||``;if(r)return t(n);t(c(n))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function u(e,t){l(e,function(e){t(e)})}function d(e,t){u(e,function(e){t(r(e))})}function f(e,t){var n=new FileReader;n.onloadend=function(e){t(e.target.result||new ArrayBuffer(0))},n.readAsArrayBuffer(e)}var p=class extends Error{constructor(e,t,n){super(),this.status=e,this.name=t,this.message=n,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}};new p(401,`unauthorized`,`Name or password is incorrect.`);var m=new p(400,`bad_request`,`Missing JSON list of 'docs'`),h=new p(404,`not_found`,`missing`),g=new p(409,`conflict`,`Document update conflict`),_=new p(400,`bad_request`,`_id field must contain a string`),v=new p(412,`missing_id`,`_id is required for puts`),y=new p(400,`bad_request`,`Only reserved document ids may start with underscore.`);new p(412,`precondition_failed`,`Database not open`);var b=new p(500,`unknown_error`,`Database encountered an unknown error`),x=new p(500,`badarg`,`Some query argument is invalid`);new p(400,`invalid_request`,`Request was invalid`);var ee=new p(400,`query_parse_error`,`Some query parameter is invalid`),te=new p(500,`doc_validation`,`Bad special document member`),S=new p(400,`bad_request`,`Something wrong with the request`),ne=new p(400,`bad_request`,`Document must be a JSON object`);new p(404,`not_found`,`Database not found`);var re=new p(500,`indexed_db_went_bad`,`unknown`);new p(500,`web_sql_went_bad`,`unknown`),new p(500,`levelDB_went_went_bad`,`unknown`),new p(403,`forbidden`,`Forbidden by design doc validate_doc_update function`);var ie=new p(400,`bad_request`,`Invalid rev format`);new p(412,`file_exists`,`The database could not be created, the file already exists.`);var ae=new p(412,`missing_stub`,`A pre-existing attachment stub wasn't found`);new p(413,`invalid_url`,`Provided URL is invalid`);function C(e,t){function n(t){for(var n=Object.getOwnPropertyNames(e),r=0,i=n.length;r<i;r++)typeof e[n[r]]!=`function`&&(this[n[r]]=e[n[r]]);this.stack===void 0&&(this.stack=Error().stack),t!==void 0&&(this.reason=t)}return n.prototype=p.prototype,new n(t)}function oe(e){if(typeof e!=`object`){var t=e;e=b,e.data=t}return`error`in e&&e.error===`conflict`&&(e.name=`conflict`,e.status=409),`name`in e||(e.name=e.error||`unknown`),`status`in e||(e.status=500),`message`in e||(e.message=e.message||e.reason),`stack`in e||(e.stack=Error().stack),e}var w=t(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),T,se=new Uint8Array(16);function ce(){if(!T&&(T=typeof crypto<`u`&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<`u`&&typeof msCrypto.getRandomValues==`function`&&msCrypto.getRandomValues.bind(msCrypto),!T))throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);return T(se)}var E=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function D(e){return typeof e==`string`&&E.test(e)}for(var O=[],k=0;k<256;++k)O.push((k+256).toString(16).substr(1));function le(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=(O[e[t+0]]+O[e[t+1]]+O[e[t+2]]+O[e[t+3]]+`-`+O[e[t+4]]+O[e[t+5]]+`-`+O[e[t+6]]+O[e[t+7]]+`-`+O[e[t+8]]+O[e[t+9]]+`-`+O[e[t+10]]+O[e[t+11]]+O[e[t+12]]+O[e[t+13]]+O[e[t+14]]+O[e[t+15]]).toLowerCase();if(!D(n))throw TypeError(`Stringified UUID is invalid`);return n}function A(e,t,n){e||={};var r=e.random||(e.rng||ce)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n||=0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return le(r)}var ue=t(((e,t)=>{(function(n){if(typeof e==`object`)t.exports=n();else if(typeof define==`function`&&define.amd)define(n);else{var r;try{r=window}catch{r=self}r.SparkMD5=n()}})(function(e){var t=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`a`,`b`,`c`,`d`,`e`,`f`];function n(e,t){var n=e[0],r=e[1],i=e[2],a=e[3];n+=(r&i|~r&a)+t[0]-680876936|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[1]-389564586|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[2]+606105819|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[3]-1044525330|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[4]-176418897|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[5]+1200080426|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[6]-1473231341|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[7]-45705983|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[8]+1770035416|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[9]-1958414417|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[10]-42063|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[11]-1990404162|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[12]+1804603682|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[13]-40341101|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[14]-1502002290|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[15]+1236535329|0,r=(r<<22|r>>>10)+i|0,n+=(r&a|i&~a)+t[1]-165796510|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[6]-1069501632|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[11]+643717713|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[0]-373897302|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[5]-701558691|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[10]+38016083|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[15]-660478335|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[4]-405537848|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[9]+568446438|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[14]-1019803690|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[3]-187363961|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[8]+1163531501|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[13]-1444681467|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[2]-51403784|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[7]+1735328473|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[12]-1926607734|0,r=(r<<20|r>>>12)+i|0,n+=(r^i^a)+t[5]-378558|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[8]-2022574463|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[11]+1839030562|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[14]-35309556|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[1]-1530992060|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[4]+1272893353|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[7]-155497632|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[10]-1094730640|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[13]+681279174|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[0]-358537222|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[3]-722521979|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[6]+76029189|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[9]-640364487|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[12]-421815835|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[15]+530742520|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[2]-995338651|0,r=(r<<23|r>>>9)+i|0,n+=(i^(r|~a))+t[0]-198630844|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[7]+1126891415|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[14]-1416354905|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[5]-57434055|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[12]+1700485571|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[3]-1894986606|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[10]-1051523|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[1]-2054922799|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[8]+1873313359|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[15]-30611744|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[6]-1560198380|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[13]+1309151649|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[4]-145523070|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[11]-1120210379|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[2]+718787259|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[9]-343485551|0,r=(r<<21|r>>>11)+i|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=i+e[2]|0,e[3]=a+e[3]|0}function r(e){var t=[],n;for(n=0;n<64;n+=4)t[n>>2]=e.charCodeAt(n)+(e.charCodeAt(n+1)<<8)+(e.charCodeAt(n+2)<<16)+(e.charCodeAt(n+3)<<24);return t}function i(e){var t=[],n;for(n=0;n<64;n+=4)t[n>>2]=e[n]+(e[n+1]<<8)+(e[n+2]<<16)+(e[n+3]<<24);return t}function a(e){var t=e.length,i=[1732584193,-271733879,-1732584194,271733878],a,o,s,c,l,u;for(a=64;a<=t;a+=64)n(i,r(e.substring(a-64,a)));for(e=e.substring(a-64),o=e.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<o;a+=1)s[a>>2]|=e.charCodeAt(a)<<(a%4<<3);if(s[a>>2]|=128<<(a%4<<3),a>55)for(n(i,s),a=0;a<16;a+=1)s[a]=0;return c=t*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(c[2],16),u=parseInt(c[1],16)||0,s[14]=l,s[15]=u,n(i,s),i}function o(e){var t=e.length,r=[1732584193,-271733879,-1732584194,271733878],a,o,s,c,l,u;for(a=64;a<=t;a+=64)n(r,i(e.subarray(a-64,a)));for(e=a-64<t?e.subarray(a-64):new Uint8Array,o=e.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<o;a+=1)s[a>>2]|=e[a]<<(a%4<<3);if(s[a>>2]|=128<<(a%4<<3),a>55)for(n(r,s),a=0;a<16;a+=1)s[a]=0;return c=t*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(c[2],16),u=parseInt(c[1],16)||0,s[14]=l,s[15]=u,n(r,s),r}function s(e){var n=``,r;for(r=0;r<4;r+=1)n+=t[e>>r*8+4&15]+t[e>>r*8&15];return n}function c(e){var t;for(t=0;t<e.length;t+=1)e[t]=s(e[t]);return e.join(``)}c(a(`hello`)),typeof ArrayBuffer<`u`&&!ArrayBuffer.prototype.slice&&(function(){function t(e,t){return e=e|0||0,e<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(n,r){var i=this.byteLength,a=t(n,i),o=i,s,c,l,u;return r!==e&&(o=t(r,i)),a>o?new ArrayBuffer(0):(s=o-a,c=new ArrayBuffer(s),l=new Uint8Array(c),u=new Uint8Array(this,a,s),l.set(u),c)}})();function l(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function u(e,t){var n=e.length,r=new ArrayBuffer(n),i=new Uint8Array(r),a;for(a=0;a<n;a+=1)i[a]=e.charCodeAt(a);return t?i:r}function d(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function f(e,t,n){var r=new Uint8Array(e.byteLength+t.byteLength);return r.set(new Uint8Array(e)),r.set(new Uint8Array(t),e.byteLength),n?r:r.buffer}function p(e){var t=[],n=e.length,r;for(r=0;r<n-1;r+=2)t.push(parseInt(e.substr(r,2),16));return String.fromCharCode.apply(String,t)}function m(){this.reset()}return m.prototype.append=function(e){return this.appendBinary(l(e)),this},m.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t=this._buff.length,i;for(i=64;i<=t;i+=64)n(this._hash,r(this._buff.substring(i-64,i)));return this._buff=this._buff.substring(i-64),this},m.prototype.end=function(e){var t=this._buff,n=t.length,r,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a;for(r=0;r<n;r+=1)i[r>>2]|=t.charCodeAt(r)<<(r%4<<3);return this._finish(i,n),a=c(this._hash),e&&(a=p(a)),this.reset(),a},m.prototype.reset=function(){return this._buff=``,this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},m.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},m.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},m.prototype._finish=function(e,t){var r=t,i,a,o;if(e[r>>2]|=128<<(r%4<<3),r>55)for(n(this._hash,e),r=0;r<16;r+=1)e[r]=0;i=this._length*8,i=i.toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(i[2],16),o=parseInt(i[1],16)||0,e[14]=a,e[15]=o,n(this._hash,e)},m.hash=function(e,t){return m.hashBinary(l(e),t)},m.hashBinary=function(e,t){var n=c(a(e));return t?p(n):n},m.ArrayBuffer=function(){this.reset()},m.ArrayBuffer.prototype.append=function(e){var t=f(this._buff.buffer,e,!0),r=t.length,a;for(this._length+=e.byteLength,a=64;a<=r;a+=64)n(this._hash,i(t.subarray(a-64,a)));return this._buff=a-64<r?new Uint8Array(t.buffer.slice(a-64)):new Uint8Array,this},m.ArrayBuffer.prototype.end=function(e){var t=this._buff,n=t.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i,a;for(i=0;i<n;i+=1)r[i>>2]|=t[i]<<(i%4<<3);return this._finish(r,n),a=c(this._hash),e&&(a=p(a)),this.reset(),a},m.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array,this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.ArrayBuffer.prototype.getState=function(){var e=m.prototype.getState.call(this);return e.buff=d(e.buff),e},m.ArrayBuffer.prototype.setState=function(e){return e.buff=u(e.buff,!0),m.prototype.setState.call(this,e)},m.ArrayBuffer.prototype.destroy=m.prototype.destroy,m.ArrayBuffer.prototype._finish=m.prototype._finish,m.ArrayBuffer.hash=function(e,t){var n=c(o(new Uint8Array(e)));return t?p(n):n},m})})),j=e(w()),M=e(ue()),de=self.setImmediate||self.setTimeout,fe=32768;function N(e){return r(e)}function P(e,t,n,r,i){(n>0||r<t.size)&&(t=t.slice(n,r)),f(t,function(t){e.append(t),i()})}function F(e,t,n,r,i){(n>0||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t),i()}function I(e,t){var n=typeof e==`string`,r=n?e.length:e.size,i=Math.min(fe,r),a=Math.ceil(r/i),o=0,s=n?new M.default:new M.default.ArrayBuffer,c=n?F:P;function l(){de(d)}function u(){t(N(s.end(!0))),s.destroy()}function d(){var t=o*i,n=t+i;o++,o<a?c(s,e,t,n,l):c(s,e,t,n,u)}d()}function L(e){return M.default.hash(e)}function R(e){return typeof ArrayBuffer<`u`&&e instanceof ArrayBuffer||typeof Blob<`u`&&e instanceof Blob}function z(e){return e instanceof ArrayBuffer?e.slice(0):e.slice(0,e.size,e.type)}var B=Function.prototype.toString,V=B.call(Object);function pe(e){var t=Object.getPrototypeOf(e);if(t===null)return!0;var n=t.constructor;return typeof n==`function`&&n instanceof n&&B.call(n)==V}function H(e){var t,n,r;if(!e||typeof e!=`object`)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=H(e[n]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(R(e))return z(e);if(!pe(e))return e;for(n in t={},e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=H(e[n]);i!==void 0&&(t[n]=i)}return t}function U(e){var t=!1;return function(...n){if(t)throw Error(`once called more than once`);t=!0,e.apply(this,n)}}function W(e){return function(...t){t=H(t);var n=this,r=typeof t[t.length-1]==`function`?t.pop():!1,i=new Promise(function(r,i){var a;try{var o=U(function(e,t){e?i(e):r(t)});t.push(o),a=e.apply(n,t),a&&typeof a.then==`function`&&r(a)}catch(e){i(e)}});return r&&i.then(function(e){r(null,e)},r),i}}function me(e,t,n){if(e.constructor.listeners(`debug`).length){for(var r=[`api`,e.name,t],i=0;i<n.length-1;i++)r.push(n[i]);e.constructor.emit(`debug`,r);var a=n[n.length-1];n[n.length-1]=function(n,r){var i=[`api`,e.name,t];i=i.concat(n?[`error`,n]:[`success`,r]),e.constructor.emit(`debug`,i),a(n,r)}}}function he(e,t){return W(function(...n){if(this._closed)return Promise.reject(Error(`database is closed`));if(this._destroyed)return Promise.reject(Error(`database is destroyed`));var r=this;return me(r,e,n),this.taskqueue.isReady?t.apply(this,n):new Promise(function(t,i){r.taskqueue.addTask(function(a){a?i(a):t(r[e].apply(r,n))})})})}function G(e,t){for(var n={},r=0,i=t.length;r<i;r++){var a=t[r];a in e&&(n[a]=e[a])}return n}var ge=6;function K(e){return e}function _e(e){return[{ok:e}]}function ve(e,t,n){var r=t.docs,i=new Map;r.forEach(function(e){i.has(e.id)?i.get(e.id).push(e):i.set(e.id,[e])});var a=i.size,o=0,s=Array(a);function c(){var e=[];s.forEach(function(t){t.docs.forEach(function(n){e.push({id:t.id,docs:[n]})})}),n(null,{results:e})}function l(){++o===a&&c()}function u(e,t,n){s[e]={id:t,docs:n},l()}var d=[];i.forEach(function(e,t){d.push(t)});var f=0;function p(){if(!(f>=d.length)){var e=Math.min(f+ge,d.length),t=d.slice(f,e);m(t,f),f+=t.length}}function m(n,r){n.forEach(function(n,a){var o=r+a,s=i.get(n),c=G(s[0],[`atts_since`,`attachments`]);c.open_revs=s.map(function(e){return e.rev}),c.open_revs=c.open_revs.filter(K);var l=K;c.open_revs.length===0&&(delete c.open_revs,l=_e),[`revs`,`attachments`,`binary`,`ajax`,`latest`].forEach(function(e){e in t&&(c[e]=t[e])}),e.get(n,c,function(e,t){u(o,n,e?[{error:e}]:l(t)),p()})})}p()}var q;try{localStorage.setItem(`_pouch_check_localstorage`,1),q=!!localStorage.getItem(`_pouch_check_localstorage`)}catch{q=!1}function J(){return q}var Y=typeof queueMicrotask==`function`?queueMicrotask:function(e){Promise.resolve().then(e)},ye=class extends j.default{constructor(){super(),this._listeners={},J()&&addEventListener(`storage`,e=>{this.emit(e.key)})}addListener(e,t,n,r){if(this._listeners[t])return;var i=!1,a=this;function o(){if(!a._listeners[t])return;if(i){i=`waiting`;return}i=!0;var e=G(r,[`style`,`include_docs`,`attachments`,`conflicts`,`filter`,`doc_ids`,`view`,`since`,`query_params`,`binary`,`return_docs`]);function s(){i=!1}n.changes(e).on(`change`,function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on(`complete`,function(){i===`waiting`&&Y(o),i=!1}).on(`error`,s)}this._listeners[t]=o,this.on(e,o)}removeListener(e,t){t in this._listeners&&(super.removeListener(e,this._listeners[t]),delete this._listeners[t])}notifyLocalWindows(e){J()&&(localStorage[e]=localStorage[e]===`a`?`b`:`a`)}notify(e){this.emit(e),this.notifyLocalWindows(e)}};function X(e){if(typeof console<`u`&&typeof console[e]==`function`){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function be(e,t,n){try{return!e(t,n)}catch(e){return C(S,`Filter function threw: `+e.toString())}}function xe(e){var t={},n=e.filter&&typeof e.filter==`function`;return t.query=e.query_params,function(r){r.doc||={};var i=n&&be(e.filter,r.doc,t);if(typeof i==`object`)return i;if(i)return!1;if(!e.include_docs)delete r.doc;else if(!e.attachments)for(var a in r.doc._attachments)Object.prototype.hasOwnProperty.call(r.doc._attachments,a)&&(r.doc._attachments[a].stub=!0);return!0}}function Z(){}Z.name;function Se(e){var t;if(e?typeof e==`string`?/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=C(y)):t=C(_):t=C(v),t)throw t}function Ce(e){return typeof e._remote==`boolean`?e._remote:typeof e.type==`function`?(X(`warn`,`db.type() is deprecated and will be removed in a future version of PouchDB`),e.type()===`http`):!1}function we(e,t){return`listenerCount`in e?e.listenerCount(t):j.default.listenerCount(e,t)}function Q(e){if(!e)return null;var t=e.split(`/`);return t.length===2?t:t.length===1?[e,e]:null}function Te(e){var t=Q(e);return t?t.join(`/`):null}function Ee(e,t){var n=[],r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n.push(i),r.push(t[i]));return n.push(e),Function.apply(null,n).apply(null,r)}function $(e,t,n){return e.get(t).catch(function(e){if(e.status!==404)throw e;return{}}).then(function(r){var i=r._rev,a=n(r);return a?(a._id=t,a._rev=i,De(e,a,n)):{updated:!1,rev:i}})}function De(e,t,n){return e.put(t).then(function(e){return{updated:!0,rev:e.rev}},function(r){if(r.status!==409)throw r;return $(e,t._id,n)})}function Oe(e,t){if(!t)return A().replace(/-/g,``).toLowerCase();var n=Object.assign({},e);return delete n._rev_tree,L(JSON.stringify(n))}var ke=A;export{ie as A,s as B,A as C,te as D,S as E,ee as F,l as G,d as H,g as I,n as K,b as L,h as M,ae as N,re as O,ne as P,C as R,L as S,x as T,u as U,o as V,i as W,Ee as _,xe as a,ke as b,Se as c,Y as d,Te as f,Oe as g,G as h,H as i,m as j,_ as k,Ce as l,Q as m,he as n,X as o,U as p,r as q,ve as r,J as s,ye as t,we as u,W as v,w,I as x,$ as y,oe as z};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import{B as e,R as t,S as n,d as r,i,l as a,o,y as s,z as c}from"./index-browser.es.js";import{a as l,c as u,d,f,h as p,i as m,l as h,n as g,o as _,p as v,r as y,s as b,t as x,u as S}from"./index3.es.js";var C=class e extends Error{constructor(t){super(),this.status=400,this.name=`query_parse_error`,this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}},ee=class e extends Error{constructor(t){super(),this.status=404,this.name=`not_found`,this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}},te=class e extends Error{constructor(t){super(),this.status=500,this.name=`invalid_value`,this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}};function w(e,t){return t&&e.then(function(e){r(function(){t(null,e)})},function(e){r(function(){t(e)})}),e}function ne(e){return function(...t){var n=t.pop(),r=e.apply(this,t);return typeof n==`function`&&w(r,n),r}}function re(e,t){return e.then(function(e){return t().then(function(){return e})},function(e){return t().then(function(){throw e})})}function T(e,t){return function(){var n=arguments,r=this;return e.add(function(){return t.apply(r,n)})}}function E(e){var t=new Set(e),n=Array(t.size),r=-1;return t.forEach(function(e){n[++r]=e}),n}function D(e){var t=Array(e.size),n=-1;return e.forEach(function(e,r){t[++n]=r}),t}var O=class{constructor(){this.promise=Promise.resolve()}add(e){return this.promise=this.promise.catch(()=>{}).then(()=>e()),this.promise}finish(){return this.promise}};function k(e){if(!e)return`undefined`;switch(typeof e){case`function`:return e.toString();case`string`:return e.toString();default:return JSON.stringify(e)}}function A(e,t){return k(e)+k(t)+`undefined`}async function ie(e,t,r,i,a,o){let c=A(r,i),l;if(!a&&(l=e._cachedViews=e._cachedViews||{},l[c]))return l[c];let u=e.info().then(async function(u){let d=u.db_name+`-mrview-`+(a?`temp`:n(c));function f(e){e.views=e.views||{};let n=t;n.indexOf(`/`)===-1&&(n=t+`/`+t);let r=e.views[n]=e.views[n]||{};if(!r[d])return r[d]=!0,e}await s(e,`_local/`+o,f);let p=(await e.registerDependentDatabase(d)).db;p.auto_compaction=!0;let m={name:d,db:p,sourceDB:e,adapter:e.adapter,mapFun:r,reduceFun:i},h;try{h=await m.db.get(`_local/lastSeq`)}catch(e){if(e.status!==404)throw e}return m.seq=h?h.seq:0,l&&m.db.once(`destroyed`,function(){delete l[c]}),m});return l&&(l[c]=u),u}var ae={},oe=new O,se=50;function j(e){return e.indexOf(`/`)===-1?[e,e]:e.split(`/`)}function ce(e){return e.length===1&&/^1-/.test(e[0].rev)}function le(e,t,n){try{e.emit(`error`,t)}catch{o(`error`,`The user's map/reduce function threw an uncaught error.
|
|
2
2
|
You can debug this error by doing:
|
|
3
3
|
myDatabase.on('error', function (err) { debugger; });
|
|
4
|
-
Please double-check your map/reduce function.`),o(`error`,t,n)}}function ue(t,n,i,o){function s(e,t,n){try{t(n)}catch(r){le(e,r,{fun:t,doc:n})}}function l(e,t,n,r,i){try{return{output:t(n,r,i)}}catch(a){return le(e,a,{fun:t,keys:n,values:r,rereduce:i}),{error:a}}}function u(e,t){let n=S(e.key,t.key);return n===0?S(e.value,t.value):n}function m(e,t,n){return n||=0,typeof t==`number`?e.slice(n,t+n):n>0?e.slice(n):e}function h(e){let t=e.value;return t&&typeof t==`object`&&t._id||e.id}function g(t){for(let n of t.rows){let t=n.doc&&n.doc._attachments;if(t)for(let n of Object.keys(t)){let r=t[n];t[n].data=e(r.data,r.content_type)}}}function _(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&g(t),t}}function y(e,t,n,r){let i=t[e];i!==void 0&&(r&&(i=encodeURIComponent(JSON.stringify(i))),n.push(e+`=`+i))}function b(e){if(e!==void 0){let t=Number(e);return!isNaN(t)&&t===parseInt(e,10)?t:e}}function x(e){return e.group_level=b(e.group_level),e.limit=b(e.limit),e.skip=b(e.skip),e}function k(e){if(e){if(typeof e!=`number`)return new C(`Invalid value for integer: "${e}"`);if(e<0)return new C(`Invalid value for positive integer: "${e}"`)}}function A(e,t){let n=e.descending?`endkey`:`startkey`,r=e.descending?`startkey`:`endkey`;if(e[n]!==void 0&&e[r]!==void 0&&S(e[n],e[r])>0)throw new C(`No rows can match your key range, reverse your start_key and end_key or set {descending : true}`);if(t.reduce&&e.reduce!==!1){if(e.include_docs)throw new C(`{include_docs:true} is invalid for reduce`);if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new C(`Multi-key fetches for reduce views must use {group: true}`)}for(let t of[`group_level`,`limit`,`skip`]){let n=k(e[t]);if(n)throw n}}async function ue(e,t,n){let r=[],i,a=`GET`,o;if(y(`reduce`,n,r),y(`include_docs`,n,r),y(`attachments`,n,r),y(`limit`,n,r),y(`descending`,n,r),y(`group`,n,r),y(`group_level`,n,r),y(`skip`,n,r),y(`stale`,n,r),y(`conflicts`,n,r),y(`startkey`,n,r,!0),y(`start_key`,n,r,!0),y(`endkey`,n,r,!0),y(`end_key`,n,r,!0),y(`inclusive_end`,n,r),y(`key`,n,r,!0),y(`update_seq`,n,r),r=r.join(`&`),r=r===``?``:`?`+r,n.keys!==void 0){let e=`keys=${encodeURIComponent(JSON.stringify(n.keys))}`;e.length+r.length+1<=2e3?r+=(r[0]===`?`?`&`:`?`)+e:(a=`POST`,typeof t==`string`?i={keys:n.keys}:t.keys=n.keys)}if(typeof t==`string`){let s=j(t),l=await e.fetch(`_design/`+s[0]+`/_view/`+s[1]+r,{headers:new p({"Content-Type":`application/json`}),method:a,body:JSON.stringify(i)});o=l.ok;let u=await l.json();if(!o)throw u.status=l.status,c(u);for(let e of u.rows)if(e.value&&e.value.error&&e.value.error===`builtin_reduce_error`)throw Error(e.reason);return new Promise(function(e){e(u)}).then(_(n))}i||={};for(let e of Object.keys(t))Array.isArray(t[e])?i[e]=t[e]:i[e]=t[e].toString();let s=await e.fetch(`_temp_view`+r,{headers:new p({"Content-Type":`application/json`}),method:`POST`,body:JSON.stringify(i)});o=s.ok;let l=await s.json();if(!o)throw l.status=s.status,c(l);return new Promise(function(e){e(l)}).then(_(n))}function M(e,t,n){return new Promise(function(r,i){e._query(t,n,function(e,t){if(e)return i(e);r(t)})})}function N(e){return new Promise(function(t,n){e._viewCleanup(function(e,r){if(e)return n(e);t(r)})})}function P(e){return function(t){if(t.status===404)return e;throw t}}async function F(e,t,n){let r=`_local/doc_`+e,i={_id:r,keys:[]},a=n.get(e),o=a[0],s=a[1];function c(){return ce(s)?Promise.resolve(i):t.db.get(r).catch(P(i))}function l(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Promise.resolve({rows:[]})}function u(e,t){let n=[],r=new Set;for(let e of t.rows){let t=e.doc;if(t&&(n.push(t),r.add(t._id),t._deleted=!o.has(t._id),!t._deleted)){let e=o.get(t._id);`value`in e&&(t.value=e.value)}}let i=D(o);for(let e of i)if(!r.has(e)){let t={_id:e},r=o.get(e);`value`in r&&(t.value=r.value),n.push(t)}return e.keys=E(i.concat(e.keys)),n.push(e),n}let d=await c();return u(d,await l(d))}function I(e){return e.sourceDB.get(`_local/purges`).then(function(t){let n=t.purgeSeq;return e.db.get(`_local/purgeSeq`).then(function(e){return e._rev}).catch(P(void 0)).then(function(t){return e.db.put({_id:`_local/purgeSeq`,_rev:t,purgeSeq:n})})}).catch(function(e){if(e.status!==404)throw e})}function L(e,t,n){var r=`_local/lastSeq`;return e.db.get(r).catch(P({_id:r,seq:0})).then(function(r){var i=D(t);return Promise.all(i.map(function(n){return F(n,e,t)})).then(function(t){var i=t.flat();return r.seq=n,i.push(r),e.db.bulkDocs({docs:i})}).then(()=>I(e))})}function R(e){let t=typeof e==`string`?e:e.name,n=ae[t];return n||=ae[t]=new O,n}async function z(e,t){return T(R(e),function(){return B(e,t)})()}async function B(e,t){let r,i,a;function o(e,t){let n={id:i._id,key:d(e)};t!=null&&(n.value=d(t)),r.push(n)}let c=n(e.mapFun,o),l=e.seq||0;function f(){return e.sourceDB.info().then(function(t){a=e.sourceDB.activeTasks.add({name:`view_indexing`,total_items:t.update_seq-l})})}function p(t,n){return function(){return L(e,t,n)}}let m=0,h={view:e.name,indexed_docs:m};e.sourceDB.emit(`indexing`,h);let g=new O;async function _(){return b(await e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:`all_docs`,since:l,limit:t.changes_batch_size}),await y())}function y(){return e.db.get(`_local/purgeSeq`).then(function(e){return e.purgeSeq}).catch(P(-1)).then(function(t){return e.sourceDB.get(`_local/purges`).then(function(n){let r=n.purges.filter(function(e,n){return n>t}).map(e=>e.docId),i=r.filter(function(e,t){return r.indexOf(e)===t});return Promise.all(i.map(function(t){return e.sourceDB.get(t).then(function(e){return{docId:t,doc:e}}).catch(P({docId:t}))}))}).catch(P([]))})}function b(n,r){let i=n.results;if(!i.length&&!r.length)return;for(let e of r)if(i.findIndex(function(t){return t.id===e.docId})<0){let t={_id:e.docId,doc:{_id:e.docId,_deleted:1},changes:[]};e.doc&&(t.doc=e.doc,t.changes.push({rev:e.doc._rev})),i.push(t)}let o=x(i);g.add(p(o,l)),m+=i.length;let s={view:e.name,last_seq:n.last_seq,results_count:i.length,indexed_docs:m};if(e.sourceDB.emit(`indexing`,s),e.sourceDB.activeTasks.update(a,{completed_items:m}),!(i.length<t.changes_batch_size))return _()}function x(t){let n=new Map;for(let a of t){if(a.doc._id[0]!==`_`){r=[],i=a.doc,i._deleted||s(e.sourceDB,c,i),r.sort(u);let t=C(r);n.set(a.doc._id,[t,a.changes])}l=a.seq}return n}function C(e){let t=new Map,n;for(let r=0,i=e.length;r<i;r++){let i=e[r],a=[i.key,i.id];r>0&&S(i.key,n)===0&&a.push(r),t.set(v(a),i),n=i.key}return t}try{await f(),await _(),await g.finish(),e.seq=l,e.sourceDB.activeTasks.remove(a)}catch(t){e.sourceDB.activeTasks.remove(a,t)}}function V(e,t,n){n.group_level===0&&delete n.group_level;let r=n.group||n.group_level,a=i(e.reduceFun),o=[],s=isNaN(n.group_level)?1/0:n.group_level;for(let e of t){let t=o[o.length-1],n=r?e.key:null;if(r&&Array.isArray(n)&&(n=n.slice(0,s)),t&&S(t.groupKey,n)===0){t.keys.push([e.key,e.id]),t.values.push(e.value);continue}o.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})}t=[];for(let n of o){let r=l(e.sourceDB,a,n.keys,n.values,!1);if(r.error&&r.error instanceof te)throw r.error;t.push({value:r.error?null:r.output,key:n.groupKey})}return{rows:m(t,n.limit,n.skip)}}function H(e,t){return T(R(e),function(){return U(e,t)})()}async function U(e,t){let n,r=e.reduceFun&&t.reduce!==!1,i=t.skip||0;t.keys!==void 0&&!t.keys.length&&(t.limit=0,delete t.keys);async function a(t){t.include_docs=!0;let r=await e.db.allDocs(t);return n=r.total_rows,r.rows.map(function(e){if(`value`in e.doc&&typeof e.doc.value==`object`&&e.doc.value!==null){let t=Object.keys(e.doc.value).sort(),n=[`id`,`key`,`value`];if(!(t<n||t>n))return e.doc.value}let t=f(e.doc._id);return{key:t[0],id:t[1],value:`value`in e.doc?e.doc.value:null}})}async function o(a){let o;if(o=r?V(e,a,t):t.keys===void 0?{total_rows:n,offset:i,rows:a}:{total_rows:n,offset:i,rows:m(a,t.limit,t.skip)},t.update_seq&&(o.update_seq=e.seq),t.include_docs){let n=E(a.map(h)),r=await e.sourceDB.allDocs({keys:n,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}),i=new Map;for(let e of r.rows)i.set(e.id,e.doc);for(let e of a){let t=h(e),n=i.get(t);n&&(e.doc=n)}}return o}if(t.keys!==void 0){let e=t.keys.map(function(e){let n={startkey:v([e]),endkey:v([e,{}])};return t.update_seq&&(n.update_seq=!0),a(n)});return o((await Promise.all(e)).flat())}else{let e={descending:t.descending};t.update_seq&&(e.update_seq=!0);let n,s;if(`start_key`in t&&(n=t.start_key),`startkey`in t&&(n=t.startkey),`end_key`in t&&(s=t.end_key),`endkey`in t&&(s=t.endkey),n!==void 0&&(e.startkey=t.descending?v([n,{}]):v([n])),s!==void 0){let n=t.inclusive_end!==!1;t.descending&&(n=!n),e.endkey=v(n?[s,{}]:[s])}if(t.key!==void 0){let n=v([t.key]),r=v([t.key,{}]);e.descending?(e.endkey=n,e.startkey=r):(e.startkey=n,e.endkey=r)}return r||(typeof t.limit==`number`&&(e.limit=t.limit),e.skip=i),o(await a(e))}}async function W(e){return(await e.fetch(`_view_cleanup`,{headers:new p({"Content-Type":`application/json`}),method:`POST`})).json()}async function G(e){try{let n=await e.get(`_local/`+t),r=new Map;for(let e of Object.keys(n.views)){let t=j(e),n=`_design/`+t[0],i=t[1],a=r.get(n);a||(a=new Set,r.set(n,a)),a.add(i)}let i={keys:D(r),include_docs:!0},a=await e.allDocs(i),o={};for(let e of a.rows){let t=e.key.substring(8);for(let i of r.get(e.key)){let r=t+`/`+i;n.views[r]||(r=i);let a=Object.keys(n.views[r]),s=e.doc&&e.doc.views&&e.doc.views[i];for(let e of a)o[e]=o[e]||s}}let s=Object.keys(o).filter(function(e){return!o[e]}).map(function(t){return T(R(t),function(){return new e.constructor(t,e.__opts).destroy()})()});return Promise.all(s).then(function(){return{ok:!0}})}catch(e){if(e.status===404)return{ok:!0};throw e}}async function K(e,n,i){if(typeof e._query==`function`)return M(e,n,i);if(a(e))return ue(e,n,i);let s={changes_batch_size:e.__opts.view_update_changes_batch_size||se};if(typeof n!=`string`)return A(i,n),oe.add(async function(){let r=await ie(e,`temp_view/temp_view`,n.map,n.reduce,!0,t);return re(z(r,s).then(function(){return H(r,i)}),function(){return r.db.destroy()})}),oe.finish();{let a=n,c=j(a),l=c[0],u=c[1],d=await e.get(`_design/`+l);if(n=d.views&&d.views[u],!n)throw new ee(`ddoc ${d._id} has no view named ${u}`);o(d,u),A(i,n);let f=await ie(e,a,n.map,n.reduce,!1,t);return i.stale===`ok`||i.stale===`update_after`?(i.stale===`update_after`&&r(function(){z(f,s)}),H(f,i)):(await z(f,s),H(f,i))}}function de(e,t,n){let r=this;typeof t==`function`&&(n=t,t={}),t=t?x(t):{},typeof e==`function`&&(e={map:e});let i=Promise.resolve().then(function(){return K(r,e,t)});return w(i,n),i}return{query:de,viewCleanup:ne(function(){let e=this;return typeof e._viewCleanup==`function`?N(e):a(e)?W(e):G(e)})}}var M=(...e)=>e.flat(1/0),N=(...e)=>{let t=[];for(let n of e)Array.isArray(n)?t=t.concat(N(...n)):t.push(n);return t},P=typeof Array.prototype.flat==`function`?M:N;function F(e){let t={};for(let n of e)Object.assign(t,n);return t}function I(e,t){let n={};for(let r of t){let t=u(r),i=y(e,t);i!==void 0&&h(n,t,i)}return n}function L(e,t){for(let n=0,r=Math.min(e.length,t.length);n<r;n++)if(e[n]!==t[n])return!1;return!0}function R(e,t){return e.length>t.length?!1:L(e,t)}function z(e,t){e=e.slice();for(let n of t){if(!e.length)break;let t=e.indexOf(n);if(t===-1)return!1;e.splice(t,1)}return!0}function B(e){let t={};for(let n of e)t[n]=!0;return t}function V(e,t){let n=null,r=-1;for(let i of e){let e=t(i);e>r&&(r=e,n=i)}return n}function H(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function U(e){return Array.from(new Set(e))}function W(e){return function(...t){let n=t[t.length-1];if(typeof n==`function`){let r=n.bind(null,null),i=n.bind(null);e.apply(this,t.slice(0,-1)).then(r,i)}else return e.apply(this,t)}}function G(e){e=i(e),e.index||={};for(let t of[`type`,`name`,`ddoc`])e.index[t]&&(e[t]=e.index[t],delete e.index[t]);return e.fields&&(e.index.fields=e.fields,delete e.fields),e.type||=`json`,e}function K(e){return typeof e==`object`&&!!e}function de(e,t,n){let r=``,i=t,a=!0;if([`$in`,`$nin`,`$or`,`$and`,`$mod`,`$nor`,`$all`].indexOf(e)!==-1&&(Array.isArray(t)||(r=`Query operator `+e+` must be an array.`)),[`$not`,`$elemMatch`,`$allMatch`].indexOf(e)!==-1&&(!Array.isArray(t)&&K(t)||(r=`Query operator `+e+` must be an object.`)),e===`$mod`&&Array.isArray(t))if(t.length!==2)r=`Query operator $mod must be in the format [divisor, remainder], where divisor and remainder are both integers.`;else{let e=t[0],n=t[1];e===0&&(r=`Query operator $mod's divisor cannot be 0, cannot divide by zero.`,a=!1),(typeof e!=`number`||parseInt(e,10)!==e)&&(r=`Query operator $mod's divisor is not an integer.`,i=e),parseInt(n,10)!==n&&(r=`Query operator $mod's remainder is not an integer.`,i=n)}if(e===`$exists`&&typeof t!=`boolean`&&(r=`Query operator $exists must be a boolean.`),e===`$type`){let e=[`null`,`boolean`,`number`,`string`,`array`,`object`],n=`"`+e.slice(0,e.length-1).join(`", "`)+`", or "`+e[e.length-1]+`"`;typeof t==`string`?e.indexOf(t)==-1&&(r=`Query operator $type must be a string. Supported values: `+n+`.`):r=`Query operator $type must be a string. Supported values: `+n+`.`}if(e===`$size`&&parseInt(t,10)!==t&&(r=`Query operator $size must be a integer.`),e===`$regex`&&typeof t!=`string`&&(n?r=`Query operator $regex must be a string.`:t instanceof RegExp||(r=`Query operator $regex must be a string or an instance of a javascript regular expression.`)),r){if(a){let e=i===null?` `:Array.isArray(i)?` array`:` `+typeof i,t=K(i)?JSON.stringify(i,null,` `):i;r+=` Received`+e+`: `+t}throw Error(r)}}var fe=[`$all`,`$allMatch`,`$and`,`$elemMatch`,`$exists`,`$in`,`$mod`,`$nin`,`$nor`,`$not`,`$or`,`$regex`,`$size`,`$type`],pe=[`$in`,`$nin`,`$mod`,`$all`],me=[`$eq`,`$gt`,`$gte`,`$lt`,`$lte`];function q(e,t){if(Array.isArray(e))for(let n of e)K(n)&&q(n,t);else for(let[n,r]of Object.entries(e))fe.indexOf(n)!==-1&&de(n,r,t),me.indexOf(n)===-1&&pe.indexOf(n)===-1&&K(r)&&q(r,t)}async function J(e,n,r){r.body&&(r.body=JSON.stringify(r.body),r.headers=new p({"Content-type":`application/json`}));let i=await e.fetch(n,r),a=await i.json();if(!i.ok)throw a.status=i.status,c(t(a));return a}async function he(e,t){return await J(e,`_index`,{method:`POST`,body:G(t)})}async function ge(e,t){return q(t.selector,!0),await J(e,`_find`,{method:`POST`,body:t})}async function _e(e,t){return await J(e,`_explain`,{method:`POST`,body:t})}async function ve(e){return await J(e,`_index`,{method:`GET`})}async function ye(e,t){let n=t.ddoc,r=t.type||`json`,i=t.name;if(!n)throw Error(`you must provide an index's ddoc`);if(!i)throw Error(`you must provide an index's name`);return await J(e,`_index/`+[n,r,i].map(encodeURIComponent).join(`/`),{method:`DELETE`})}function be(e,t){for(let n of t)if(e=e[n],e===void 0)return;return e}function xe(e,t,n){return function(r){if(n&&!b(r,n))return;let i=[];for(let t of e){let e=be(r,u(t));if(e===void 0)return;i.push(e)}t(i)}}function Se(e,t,n){let r=u(e);return function(e){if(n&&!b(e,n))return;let i=be(e,r);i!==void 0&&t(i)}}function Ce(e,t,n){return function(r){n&&!b(r,n)||t(r[e])}}function we(e,t,n){return function(r){n&&!b(r,n)||t(e.map(e=>r[e]))}}function Te(e){return e.every(e=>e.indexOf(`.`)===-1)}function Ee(e,t,n){let r=Te(e),i=e.length===1;return r?i?Ce(e[0],t,n):we(e,t,n):i?Se(e[0],t,n):xe(e,t,n)}function De(e,t){let n=Object.keys(e.fields),r=e.partial_filter_selector;return Ee(n,t,r)}function Oe(){throw Error(`reduce not supported`)}function ke(e,t){let n=e.views[t];if(!n.map||!n.map.fields)throw Error(`ddoc `+e._id+` with view `+t+` doesn't have map.fields defined. maybe it wasn't created by this plugin?`)}var Y=ue(`indexes`,De,Oe,ke);function X(e){return e._customFindAbstractMapper?{query:function(t,n){let r=Y.query.bind(this);return e._customFindAbstractMapper.query.call(this,t,n,r)},viewCleanup:function(){let t=Y.viewCleanup.bind(this);return e._customFindAbstractMapper.viewCleanup.call(this,t)}}:Y}function Ae(e){if(!Array.isArray(e))throw Error(`invalid sort json - should be an array`);return e.map(function(e){if(typeof e==`string`){let t={};return t[e]=`asc`,t}else return e})}var je=/^_design\//;function Me(e){let t=[];return typeof e==`string`?t.push(e):t=e,t.map(function(e){return e.replace(je,``)})}function Ne(e){return e.fields=e.fields.map(function(e){if(typeof e==`string`){let t={};return t[e]=`asc`,t}return e}),e.partial_filter_selector&&=_(e.partial_filter_selector),e}function Pe(e,t){return t.def.fields.map(t=>y(e,u(m(t))))}function Fe(e,t,n){let r=n.def.fields,i=0;for(let a of e){let e=Pe(a.doc,n);if(r.length===1)e=e[0];else for(;e.length>t.length;)e.pop();if(Math.abs(S(e,t))>0)break;++i}return i>0?e.slice(i):e}function Ie(e){let t=i(e);return delete t.startkey,delete t.endkey,delete t.inclusive_start,delete t.inclusive_end,`endkey`in e&&(t.startkey=e.endkey),`startkey`in e&&(t.endkey=e.startkey),`inclusive_start`in e&&(t.inclusive_end=e.inclusive_start),`inclusive_end`in e&&(t.inclusive_start=e.inclusive_end),t}function Le(e){let t=e.fields.filter(function(e){return l(e)===`asc`});if(t.length!==0&&t.length!==e.fields.length)throw Error(`unsupported mixed sorting`)}function Re(e,t){if(t.defaultUsed&&e.sort){let t=e.sort.filter(function(e){return Object.keys(e)[0]!==`_id`}).map(function(e){return Object.keys(e)[0]});if(t.length>0)throw Error(`Cannot sort on field(s) "`+t.join(`,`)+`" when using the default index`)}t.defaultUsed}function ze(e){if(typeof e.selector!=`object`)throw Error(`you must provide a selector when you find()`)}function Be(e,t){let n=Object.keys(e),r=t?t.map(m):[],i;return i=n.length>=r.length?n:r,r.length===0?{fields:i}:(i=i.sort(function(e,t){let n=r.indexOf(e);n===-1&&(n=Number.MAX_VALUE);let i=r.indexOf(t);return i===-1&&(i=Number.MAX_VALUE),n<i?-1:n>i?1:0}),{fields:i,sortOrder:t.map(m)})}async function Ve(e,t){t=G(t);let r=i(t.index);t.index=Ne(t.index),Le(t.index);let a;function o(){return a||=n(JSON.stringify(t))}let c=t.name||`idx-`+o(),l=t.ddoc||`idx-`+o(),u=`_design/`+l,d=!1,f=!1;function p(e){return e._rev&&e.language!==`query`&&(d=!0),e.language=`query`,e.views=e.views||{},f=!!e.views[c],f?!1:(e.views[c]={map:{fields:F(t.index.fields),partial_filter_selector:t.index.partial_filter_selector},reduce:`_count`,options:{def:r}},e)}if(e.constructor.emit(`debug`,[`find`,`creating index`,u]),await s(e,u,p),d)throw Error(`invalid language for ddoc with id "`+u+`" (should be "query")`);let m=l+`/`+c;return await X(e).query.call(e,m,{limit:0,reduce:!1}),{id:u,name:c,result:f?`exists`:`created`}}async function He(e){let t=await e.allDocs({startkey:`_design/`,endkey:`_design/`,include_docs:!0}),n={indexes:[{ddoc:null,name:`_all_docs`,type:`special`,def:{fields:[{_id:`asc`}]}}]};return n.indexes=P(n.indexes,t.rows.filter(function(e){return e.doc.language===`query`}).map(function(e){return(e.doc.views===void 0?[]:Object.keys(e.doc.views)).map(function(t){let n=e.doc.views[t];return{ddoc:e.id,name:t,type:`json`,def:Ne(n.options.def)}})})),n.indexes.sort(function(e,t){return x(e.name,t.name)}),n.total_rows=n.indexes.length,n}var Z=null,Q={"":{}},Ue={queryOpts:{limit:0,startkey:Q,endkey:Z},inMemoryFields:[]};function We(e,t){return e.def.fields.some(e=>m(e)===t)}function Ge(e,t){let n=e[t];return m(n)!==`$eq`}function Ke(e,t){let n=t.def.fields.map(m);return e.slice().sort(function(e,t){let r=n.indexOf(e),i=n.indexOf(t);return r===-1&&(r=Number.MAX_VALUE),i===-1&&(i=Number.MAX_VALUE),x(r,i)})}function qe(e,t,n){n=Ke(n,e);let r=!1;for(let i=0,a=n.length;i<a;i++){let o=n[i];if(r||!We(e,o))return n.slice(i);i<a-1&&Ge(t,o)&&(r=!0)}return[]}function Je(e){let t=[];for(let[n,r]of Object.entries(e))for(let e of Object.keys(r))e===`$ne`&&t.push(n);return t}function Ye(e,t,n,r){return Ke(U(P(e,qe(t,n,r),Je(n))),t)}function Xe(e,t,n){if(t){let r=R(t,e),i=L(n,e);return r&&i}return z(n,e)}var Ze=[`$eq`,`$gt`,`$gte`,`$lt`,`$lte`];function Qe(e){return Ze.indexOf(e)===-1}function $e(e,t){let n=t[e[0]];return n===void 0?!0:!(Object.keys(n).length===1&&m(n)===`$ne`)}function et(e,t,n,r){let i=e.def.fields.map(m);return Xe(i,t,n)?$e(i,r):!1}function tt(e,t,n,r){return r.filter(function(r){return et(r,n,t,e)})}function nt(e,t,n,r,i){let a=tt(e,t,n,r);if(a.length===0){if(i)throw{error:`no_usable_index`,message:`There is no index available for this selector.`};let e=r[0];return e.defaultUsed=!0,e}if(a.length===1&&!i)return a[0];let o=B(t);function s(e){let t=e.def.fields.map(m),n=0;for(let e of t)o[e]&&n++;return n}if(i){let e=`_design/`+i[0],t=i.length===2?i[1]:!1,n=a.find(function(n){return!!(t&&n.ddoc===e&&t===n.name||n.ddoc===e)});if(!n)throw{error:`unknown_error`,message:`Could not find that index or could not use that index for the query`};return n}return V(a,s)}function rt(e,t){switch(e){case`$eq`:return{key:t};case`$lte`:return{endkey:t};case`$gte`:return{startkey:t};case`$lt`:return{endkey:t,inclusive_end:!1};case`$gt`:return{startkey:t,inclusive_start:!1}}return{startkey:Z}}function it(e,t){let n=m(t.def.fields[0]),r=e[n]||{},i=[],a=Object.keys(r),o;for(let e of a){Qe(e)&&i.push(n);let t=r[e],a=rt(e,t);o=o?F([o,a]):a}return{queryOpts:o,inMemoryFields:i}}function at(e,t){switch(e){case`$eq`:return{startkey:t,endkey:t};case`$lte`:return{endkey:t};case`$gte`:return{startkey:t};case`$lt`:return{endkey:t,inclusive_end:!1};case`$gt`:return{startkey:t,inclusive_start:!1}}}function ot(e,t){let n=t.def.fields.map(m),r=[],i=[],a=[],o,s;function c(e){o!==!1&&i.push(Z),s!==!1&&a.push(Q),r=n.slice(e)}for(let t=0,r=n.length;t<r;t++){let r=e[n[t]];if(!r||!Object.keys(r).length){c(t);break}else if(Object.keys(r).some(Qe)){c(t);break}else if(t>0){let i=`$gt`in r||`$gte`in r||`$lt`in r||`$lte`in r,a=Object.keys(e[n[t-1]]),o=H(a,[`$eq`]),s=H(a,Object.keys(r));if(i&&!o&&!s){c(t);break}}let l=Object.keys(r),u=null;for(let e of l){let t=r[e],n=at(e,t);u=u?F([u,n]):n}i.push(`startkey`in u?u.startkey:Z),a.push(`endkey`in u?u.endkey:Q),`inclusive_start`in u&&(o=u.inclusive_start),`inclusive_end`in u&&(s=u.inclusive_end)}let l={startkey:i,endkey:a};return o!==void 0&&(l.inclusive_start=o),s!==void 0&&(l.inclusive_end=s),{queryOpts:l,inMemoryFields:r}}function st(e){return Object.keys(e).map(function(t){return e[t]}).some(function(e){return typeof e==`object`&&Object.keys(e).length===0})}function ct(e){return{queryOpts:{startkey:null},inMemoryFields:[Object.keys(e)]}}function lt(e,t){return t.defaultUsed?ct(e,t):t.def.fields.length===1?it(e,t):ot(e,t)}function ut(e,t){let n=e.selector,r=e.sort;if(st(n))return Object.assign({},Ue,{index:t[0]});let i=Be(n,r),a=i.fields,o=i.sortOrder,s=nt(n,a,o,t,e.use_index),c=lt(n,s),l=c.queryOpts,u=c.inMemoryFields;return{queryOpts:l,index:s,inMemoryFields:Ye(u,s,n,a)}}function dt(e){return e.ddoc.substring(8)+`/`+e.name}async function ft(e,t){let n=i(t);n.descending?(`endkey`in n&&typeof n.endkey!=`string`&&(n.endkey=``),`startkey`in n&&typeof n.startkey!=`string`&&(n.limit=0)):(`startkey`in n&&typeof n.startkey!=`string`&&(n.startkey=``),`endkey`in n&&typeof n.endkey!=`string`&&(n.limit=0)),`key`in n&&typeof n.key!=`string`&&(n.limit=0),n.limit>0&&n.indexes_count&&(n.original_limit=n.limit,n.limit+=n.indexes_count);let r=await e.allDocs(n);return r.rows=r.rows.filter(function(e){return!/^_design\//.test(e.id)}),n.original_limit&&(n.limit=n.original_limit),r.rows=r.rows.slice(0,n.limit),r}async function pt(e,t,n){return n.name===`_all_docs`?ft(e,t):X(e).query.call(e,dt(n),t)}async function mt(e,t,n){t.selector&&=(q(t.selector,!1),_(t.selector)),t.sort&&=Ae(t.sort),t.use_index&&=Me(t.use_index),`limit`in t||(t.limit=25),ze(t);let r=await He(e);e.constructor.emit(`debug`,[`find`,`planning query`,t]);let i=ut(t,r.indexes);e.constructor.emit(`debug`,[`find`,`query plan`,i]);let a=i.index;Re(t,a);let o=Object.assign({include_docs:!0,reduce:!1,indexes_count:r.total_rows},i.queryOpts);if(`startkey`in o&&`endkey`in o&&S(o.startkey,o.endkey)>0)return{docs:[]};if(t.sort&&typeof t.sort[0]!=`string`&&l(t.sort[0])===`desc`&&(o.descending=!0,o=Ie(o)),i.inMemoryFields.length||(o.limit=t.limit,`skip`in t&&(o.skip=t.skip)),n)return Promise.resolve(i,o);let s=await pt(e,o,a);o.inclusive_start===!1&&(s.rows=Fe(s.rows,o.startkey,a)),i.inMemoryFields.length&&(s.rows=g(s.rows,t,i.inMemoryFields));let c={docs:s.rows.map(function(e){let n=e.doc;return t.fields?I(n,t.fields):n})};return a.defaultUsed&&(c.warning=`No matching index found, create an index to optimize query time.`),c}async function ht(e,t){let n=await mt(e,t,!0);return{dbname:e.name,index:n.index,selector:t.selector,range:{start_key:n.queryOpts.startkey,end_key:n.queryOpts.endkey},opts:{use_index:t.use_index||[],bookmark:`nil`,limit:t.limit,skip:t.skip,sort:t.sort||{},fields:t.fields,conflicts:!1,r:[49]},limit:t.limit,skip:t.skip||0,fields:t.fields}}async function gt(e,t){if(!t.ddoc)throw Error(`you must supply an index.ddoc when deleting`);if(!t.name)throw Error(`you must supply an index.name when deleting`);let n=t.ddoc,r=t.name;function i(e){return Object.keys(e.views).length===1&&e.views[r]?{_id:n,_deleted:!0}:(delete e.views[r],e)}return await s(e,n,i),await X(e).viewCleanup.apply(e),{ok:!0}}var $={};$.createIndex=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide an index to create`);return(a(this)?he:Ve)(this,e)}),$.find=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide search parameters to find()`);return(a(this)?ge:mt)(this,e)}),$.explain=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide search parameters to explain()`);return(a(this)?_e:ht)(this,e)}),$.getIndexes=W(async function(){return(a(this)?ve:He)(this)}),$.deleteIndex=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide an index to delete`);return(a(this)?ye:gt)(this,e)});export{$ as default};
|
|
4
|
+
Please double-check your map/reduce function.`),o(`error`,t,n)}}function ue(t,n,i,o){function s(e,t,n){try{t(n)}catch(r){le(e,r,{fun:t,doc:n})}}function l(e,t,n,r,i){try{return{output:t(n,r,i)}}catch(a){return le(e,a,{fun:t,keys:n,values:r,rereduce:i}),{error:a}}}function u(e,t){let n=S(e.key,t.key);return n===0?S(e.value,t.value):n}function m(e,t,n){return n||=0,typeof t==`number`?e.slice(n,t+n):n>0?e.slice(n):e}function h(e){let t=e.value;return t&&typeof t==`object`&&t._id||e.id}function g(t){for(let n of t.rows){let t=n.doc&&n.doc._attachments;if(t)for(let n of Object.keys(t)){let r=t[n];t[n].data=e(r.data,r.content_type)}}}function _(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&g(t),t}}function y(e,t,n,r){let i=t[e];i!==void 0&&(r&&(i=encodeURIComponent(JSON.stringify(i))),n.push(e+`=`+i))}function b(e){if(e!==void 0){let t=Number(e);return!isNaN(t)&&t===parseInt(e,10)?t:e}}function x(e){return e.group_level=b(e.group_level),e.limit=b(e.limit),e.skip=b(e.skip),e}function k(e){if(e){if(typeof e!=`number`)return new C(`Invalid value for integer: "${e}"`);if(e<0)return new C(`Invalid value for positive integer: "${e}"`)}}function A(e,t){let n=e.descending?`endkey`:`startkey`,r=e.descending?`startkey`:`endkey`;if(e[n]!==void 0&&e[r]!==void 0&&S(e[n],e[r])>0)throw new C(`No rows can match your key range, reverse your start_key and end_key or set {descending : true}`);if(t.reduce&&e.reduce!==!1){if(e.include_docs)throw new C(`{include_docs:true} is invalid for reduce`);if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new C(`Multi-key fetches for reduce views must use {group: true}`)}for(let t of[`group_level`,`limit`,`skip`]){let n=k(e[t]);if(n)throw n}}async function ue(e,t,n){let r=[],i,a=`GET`,o;if(y(`reduce`,n,r),y(`include_docs`,n,r),y(`attachments`,n,r),y(`limit`,n,r),y(`descending`,n,r),y(`group`,n,r),y(`group_level`,n,r),y(`skip`,n,r),y(`stale`,n,r),y(`conflicts`,n,r),y(`startkey`,n,r,!0),y(`start_key`,n,r,!0),y(`endkey`,n,r,!0),y(`end_key`,n,r,!0),y(`inclusive_end`,n,r),y(`key`,n,r,!0),y(`update_seq`,n,r),r=r.join(`&`),r=r===``?``:`?`+r,n.keys!==void 0){let e=`keys=${encodeURIComponent(JSON.stringify(n.keys))}`;e.length+r.length+1<=2e3?r+=(r[0]===`?`?`&`:`?`)+e:(a=`POST`,typeof t==`string`?i={keys:n.keys}:t.keys=n.keys)}if(typeof t==`string`){let s=j(t),l=await e.fetch(`_design/`+s[0]+`/_view/`+s[1]+r,{headers:new p({"Content-Type":`application/json`}),method:a,body:JSON.stringify(i)});o=l.ok;let u=await l.json();if(!o)throw u.status=l.status,c(u);for(let e of u.rows)if(e.value&&e.value.error&&e.value.error===`builtin_reduce_error`)throw Error(e.reason);return new Promise(function(e){e(u)}).then(_(n))}i||={};for(let e of Object.keys(t))Array.isArray(t[e])?i[e]=t[e]:i[e]=t[e].toString();let s=await e.fetch(`_temp_view`+r,{headers:new p({"Content-Type":`application/json`}),method:`POST`,body:JSON.stringify(i)});o=s.ok;let l=await s.json();if(!o)throw l.status=s.status,c(l);return new Promise(function(e){e(l)}).then(_(n))}function M(e,t,n){return new Promise(function(r,i){e._query(t,n,function(e,t){if(e)return i(e);r(t)})})}function N(e){return new Promise(function(t,n){e._viewCleanup(function(e,r){if(e)return n(e);t(r)})})}function P(e){return function(t){if(t.status===404)return e;throw t}}async function F(e,t,n){let r=`_local/doc_`+e,i={_id:r,keys:[]},a=n.get(e),o=a[0],s=a[1];function c(){return ce(s)?Promise.resolve(i):t.db.get(r).catch(P(i))}function l(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Promise.resolve({rows:[]})}function u(e,t){let n=[],r=new Set;for(let e of t.rows){let t=e.doc;if(t&&(n.push(t),r.add(t._id),t._deleted=!o.has(t._id),!t._deleted)){let e=o.get(t._id);`value`in e&&(t.value=e.value)}}let i=D(o);for(let e of i)if(!r.has(e)){let t={_id:e},r=o.get(e);`value`in r&&(t.value=r.value),n.push(t)}return e.keys=E(i.concat(e.keys)),n.push(e),n}let d=await c();return u(d,await l(d))}function I(e){return e.sourceDB.get(`_local/purges`).then(function(t){let n=t.purgeSeq;return e.db.get(`_local/purgeSeq`).then(function(e){return e._rev}).catch(P(void 0)).then(function(t){return e.db.put({_id:`_local/purgeSeq`,_rev:t,purgeSeq:n})})}).catch(function(e){if(e.status!==404)throw e})}function L(e,t,n){var r=`_local/lastSeq`;return e.db.get(r).catch(P({_id:r,seq:0})).then(function(r){var i=D(t);return Promise.all(i.map(function(n){return F(n,e,t)})).then(function(t){var i=t.flat();return r.seq=n,i.push(r),e.db.bulkDocs({docs:i})}).then(()=>I(e))})}function R(e){let t=typeof e==`string`?e:e.name,n=ae[t];return n||=ae[t]=new O,n}async function z(e,t){return T(R(e),function(){return B(e,t)})()}async function B(e,t){let r,i,a;function o(e,t){let n={id:i._id,key:d(e)};t!=null&&(n.value=d(t)),r.push(n)}let c=n(e.mapFun,o),l=e.seq||0;function f(){return e.sourceDB.info().then(function(t){a=e.sourceDB.activeTasks.add({name:`view_indexing`,total_items:t.update_seq-l})})}function p(t,n){return function(){return L(e,t,n)}}let m=0,h={view:e.name,indexed_docs:m};e.sourceDB.emit(`indexing`,h);let g=new O;async function _(){return b(await e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:`all_docs`,since:l,limit:t.changes_batch_size}),await y())}function y(){return e.db.get(`_local/purgeSeq`).then(function(e){return e.purgeSeq}).catch(P(-1)).then(function(t){return e.sourceDB.get(`_local/purges`).then(function(n){let r=n.purges.filter(function(e,n){return n>t}).map(e=>e.docId),i=r.filter(function(e,t){return r.indexOf(e)===t});return Promise.all(i.map(function(t){return e.sourceDB.get(t).then(function(e){return{docId:t,doc:e}}).catch(P({docId:t}))}))}).catch(P([]))})}function b(n,r){let i=n.results;if(!i.length&&!r.length)return;for(let e of r)if(i.findIndex(function(t){return t.id===e.docId})<0){let t={_id:e.docId,doc:{_id:e.docId,_deleted:1},changes:[]};e.doc&&(t.doc=e.doc,t.changes.push({rev:e.doc._rev})),i.push(t)}let o=x(i);g.add(p(o,l)),m+=i.length;let s={view:e.name,last_seq:n.last_seq,results_count:i.length,indexed_docs:m};if(e.sourceDB.emit(`indexing`,s),e.sourceDB.activeTasks.update(a,{completed_items:m}),!(i.length<t.changes_batch_size))return _()}function x(t){let n=new Map;for(let a of t){if(a.doc._id[0]!==`_`){r=[],i=a.doc,i._deleted||s(e.sourceDB,c,i),r.sort(u);let t=C(r);n.set(a.doc._id,[t,a.changes])}l=a.seq}return n}function C(e){let t=new Map,n;for(let r=0,i=e.length;r<i;r++){let i=e[r],a=[i.key,i.id];r>0&&S(i.key,n)===0&&a.push(r),t.set(v(a),i),n=i.key}return t}try{await f(),await _(),await g.finish(),e.seq=l,e.sourceDB.activeTasks.remove(a)}catch(t){e.sourceDB.activeTasks.remove(a,t)}}function V(e,t,n){n.group_level===0&&delete n.group_level;let r=n.group||n.group_level,a=i(e.reduceFun),o=[],s=isNaN(n.group_level)?1/0:n.group_level;for(let e of t){let t=o[o.length-1],n=r?e.key:null;if(r&&Array.isArray(n)&&(n=n.slice(0,s)),t&&S(t.groupKey,n)===0){t.keys.push([e.key,e.id]),t.values.push(e.value);continue}o.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})}t=[];for(let n of o){let r=l(e.sourceDB,a,n.keys,n.values,!1);if(r.error&&r.error instanceof te)throw r.error;t.push({value:r.error?null:r.output,key:n.groupKey})}return{rows:m(t,n.limit,n.skip)}}function H(e,t){return T(R(e),function(){return U(e,t)})()}async function U(e,t){let n,r=e.reduceFun&&t.reduce!==!1,i=t.skip||0;t.keys!==void 0&&!t.keys.length&&(t.limit=0,delete t.keys);async function a(t){t.include_docs=!0;let r=await e.db.allDocs(t);return n=r.total_rows,r.rows.map(function(e){if(`value`in e.doc&&typeof e.doc.value==`object`&&e.doc.value!==null){let t=Object.keys(e.doc.value).sort(),n=[`id`,`key`,`value`];if(!(t<n||t>n))return e.doc.value}let t=f(e.doc._id);return{key:t[0],id:t[1],value:`value`in e.doc?e.doc.value:null}})}async function o(a){let o;if(o=r?V(e,a,t):t.keys===void 0?{total_rows:n,offset:i,rows:a}:{total_rows:n,offset:i,rows:m(a,t.limit,t.skip)},t.update_seq&&(o.update_seq=e.seq),t.include_docs){let n=E(a.map(h)),r=await e.sourceDB.allDocs({keys:n,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}),i=new Map;for(let e of r.rows)i.set(e.id,e.doc);for(let e of a){let t=h(e),n=i.get(t);n&&(e.doc=n)}}return o}if(t.keys!==void 0){let e=t.keys.map(function(e){let n={startkey:v([e]),endkey:v([e,{}])};return t.update_seq&&(n.update_seq=!0),a(n)});return o((await Promise.all(e)).flat())}else{let e={descending:t.descending};t.update_seq&&(e.update_seq=!0);let n,s;if(`start_key`in t&&(n=t.start_key),`startkey`in t&&(n=t.startkey),`end_key`in t&&(s=t.end_key),`endkey`in t&&(s=t.endkey),n!==void 0&&(e.startkey=t.descending?v([n,{}]):v([n])),s!==void 0){let n=t.inclusive_end!==!1;t.descending&&(n=!n),e.endkey=v(n?[s,{}]:[s])}if(t.key!==void 0){let n=v([t.key]),r=v([t.key,{}]);e.descending?(e.endkey=n,e.startkey=r):(e.startkey=n,e.endkey=r)}return r||(typeof t.limit==`number`&&(e.limit=t.limit),e.skip=i),o(await a(e))}}async function W(e){return(await e.fetch(`_view_cleanup`,{headers:new p({"Content-Type":`application/json`}),method:`POST`})).json()}async function G(e){try{let n=await e.get(`_local/`+t),r=new Map;for(let e of Object.keys(n.views)){let t=j(e),n=`_design/`+t[0],i=t[1],a=r.get(n);a||(a=new Set,r.set(n,a)),a.add(i)}let i={keys:D(r),include_docs:!0},a=await e.allDocs(i),o={};for(let e of a.rows){let t=e.key.substring(8);for(let i of r.get(e.key)){let r=t+`/`+i;n.views[r]||(r=i);let a=Object.keys(n.views[r]),s=e.doc&&e.doc.views&&e.doc.views[i];for(let e of a)o[e]=o[e]||s}}let s=Object.keys(o).filter(function(e){return!o[e]}).map(function(t){return T(R(t),function(){return new e.constructor(t,e.__opts).destroy()})()});return Promise.all(s).then(function(){return{ok:!0}})}catch(e){if(e.status===404)return{ok:!0};throw e}}async function K(e,n,i){if(typeof e._query==`function`)return M(e,n,i);if(a(e))return ue(e,n,i);let s={changes_batch_size:e.__opts.view_update_changes_batch_size||se};if(typeof n!=`string`)return A(i,n),oe.add(async function(){let r=await ie(e,`temp_view/temp_view`,n.map,n.reduce,!0,t);return re(z(r,s).then(function(){return H(r,i)}),function(){return r.db.destroy()})}),oe.finish();{let a=n,c=j(a),l=c[0],u=c[1],d=await e.get(`_design/`+l);if(n=d.views&&d.views[u],!n)throw new ee(`ddoc ${d._id} has no view named ${u}`);o(d,u),A(i,n);let f=await ie(e,a,n.map,n.reduce,!1,t);return i.stale===`ok`||i.stale===`update_after`?(i.stale===`update_after`&&r(function(){z(f,s)}),H(f,i)):(await z(f,s),H(f,i))}}function de(e,t,n){let r=this;typeof t==`function`&&(n=t,t={}),t=t?x(t):{},typeof e==`function`&&(e={map:e});let i=Promise.resolve().then(function(){return K(r,e,t)});return w(i,n),i}return{query:de,viewCleanup:ne(function(){let e=this;return typeof e._viewCleanup==`function`?N(e):a(e)?W(e):G(e)})}}var M=(...e)=>e.flat(1/0),N=(...e)=>{let t=[];for(let n of e)Array.isArray(n)?t=t.concat(N(...n)):t.push(n);return t},P=typeof Array.prototype.flat==`function`?M:N;function F(e){let t={};for(let n of e)Object.assign(t,n);return t}function I(e,t){let n={};for(let r of t){let t=u(r),i=y(e,t);i!==void 0&&h(n,t,i)}return n}function L(e,t){for(let n=0,r=Math.min(e.length,t.length);n<r;n++)if(e[n]!==t[n])return!1;return!0}function R(e,t){return e.length>t.length?!1:L(e,t)}function z(e,t){e=e.slice();for(let n of t){if(!e.length)break;let t=e.indexOf(n);if(t===-1)return!1;e.splice(t,1)}return!0}function B(e){let t={};for(let n of e)t[n]=!0;return t}function V(e,t){let n=null,r=-1;for(let i of e){let e=t(i);e>r&&(r=e,n=i)}return n}function H(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function U(e){return Array.from(new Set(e))}function W(e){return function(...t){let n=t[t.length-1];if(typeof n==`function`){let r=n.bind(null,null),i=n.bind(null);e.apply(this,t.slice(0,-1)).then(r,i)}else return e.apply(this,t)}}function G(e){e=i(e),e.index||={};for(let t of[`type`,`name`,`ddoc`])e.index[t]&&(e[t]=e.index[t],delete e.index[t]);return e.fields&&(e.index.fields=e.fields,delete e.fields),e.type||=`json`,e}function K(e){return typeof e==`object`&&!!e}function de(e,t,n){let r=``,i=t,a=!0;if([`$in`,`$nin`,`$or`,`$and`,`$mod`,`$nor`,`$all`].indexOf(e)!==-1&&(Array.isArray(t)||(r=`Query operator `+e+` must be an array.`)),[`$not`,`$elemMatch`,`$allMatch`].indexOf(e)!==-1&&(!Array.isArray(t)&&K(t)||(r=`Query operator `+e+` must be an object.`)),e===`$mod`&&Array.isArray(t))if(t.length!==2)r=`Query operator $mod must be in the format [divisor, remainder], where divisor and remainder are both integers.`;else{let e=t[0],n=t[1];e===0&&(r=`Query operator $mod's divisor cannot be 0, cannot divide by zero.`,a=!1),(typeof e!=`number`||parseInt(e,10)!==e)&&(r=`Query operator $mod's divisor is not an integer.`,i=e),parseInt(n,10)!==n&&(r=`Query operator $mod's remainder is not an integer.`,i=n)}if(e===`$exists`&&typeof t!=`boolean`&&(r=`Query operator $exists must be a boolean.`),e===`$type`){let e=[`null`,`boolean`,`number`,`string`,`array`,`object`],n=`"`+e.slice(0,e.length-1).join(`", "`)+`", or "`+e[e.length-1]+`"`;typeof t==`string`?e.indexOf(t)==-1&&(r=`Query operator $type must be a string. Supported values: `+n+`.`):r=`Query operator $type must be a string. Supported values: `+n+`.`}if(e===`$size`&&parseInt(t,10)!==t&&(r=`Query operator $size must be a integer.`),e===`$regex`&&typeof t!=`string`&&(n?r=`Query operator $regex must be a string.`:t instanceof RegExp||(r=`Query operator $regex must be a string or an instance of a javascript regular expression.`)),r){if(a){let e=i===null?` `:Array.isArray(i)?` array`:` `+typeof i,t=K(i)?JSON.stringify(i,null,` `):i;r+=` Received`+e+`: `+t}throw Error(r)}}var fe=[`$all`,`$allMatch`,`$and`,`$elemMatch`,`$exists`,`$in`,`$mod`,`$nin`,`$nor`,`$not`,`$or`,`$regex`,`$size`,`$type`],pe=[`$in`,`$nin`,`$mod`,`$all`],me=[`$eq`,`$gt`,`$gte`,`$lt`,`$lte`];function q(e,t){if(Array.isArray(e))for(let n of e)K(n)&&q(n,t);else for(let[n,r]of Object.entries(e))fe.indexOf(n)!==-1&&de(n,r,t),me.indexOf(n)===-1&&pe.indexOf(n)===-1&&K(r)&&q(r,t)}async function J(e,n,r){r.body&&(r.body=JSON.stringify(r.body),r.headers=new p({"Content-type":`application/json`}));let i=await e.fetch(n,r),a=await i.json();if(!i.ok)throw a.status=i.status,c(t(a));return a}async function he(e,t){return await J(e,`_index`,{method:`POST`,body:G(t)})}async function ge(e,t){return q(t.selector,!0),await J(e,`_find`,{method:`POST`,body:t})}async function _e(e,t){return await J(e,`_explain`,{method:`POST`,body:t})}async function ve(e){return await J(e,`_index`,{method:`GET`})}async function ye(e,t){let n=t.ddoc,r=t.type||`json`,i=t.name;if(!n)throw Error(`you must provide an index's ddoc`);if(!i)throw Error(`you must provide an index's name`);return await J(e,`_index/`+[n,r,i].map(encodeURIComponent).join(`/`),{method:`DELETE`})}function be(e,t){for(let n of t)if(e=e[n],e===void 0)return;return e}function xe(e,t,n){return function(r){if(n&&!b(r,n))return;let i=[];for(let t of e){let e=be(r,u(t));if(e===void 0)return;i.push(e)}t(i)}}function Se(e,t,n){let r=u(e);return function(e){if(n&&!b(e,n))return;let i=be(e,r);i!==void 0&&t(i)}}function Ce(e,t,n){return function(r){n&&!b(r,n)||t(r[e])}}function we(e,t,n){return function(r){n&&!b(r,n)||t(e.map(e=>r[e]))}}function Te(e){return e.every(e=>e.indexOf(`.`)===-1)}function Ee(e,t,n){let r=Te(e),i=e.length===1;return r?i?Ce(e[0],t,n):we(e,t,n):i?Se(e[0],t,n):xe(e,t,n)}function De(e,t){let n=Object.keys(e.fields),r=e.partial_filter_selector;return Ee(n,t,r)}function Oe(){throw Error(`reduce not supported`)}function ke(e,t){let n=e.views[t];if(!n.map||!n.map.fields)throw Error(`ddoc `+e._id+` with view `+t+` doesn't have map.fields defined. maybe it wasn't created by this plugin?`)}var Y=ue(`indexes`,De,Oe,ke);function X(e){return e._customFindAbstractMapper?{query:function(t,n){let r=Y.query.bind(this);return e._customFindAbstractMapper.query.call(this,t,n,r)},viewCleanup:function(){let t=Y.viewCleanup.bind(this);return e._customFindAbstractMapper.viewCleanup.call(this,t)}}:Y}function Ae(e){if(!Array.isArray(e))throw Error(`invalid sort json - should be an array`);return e.map(function(e){if(typeof e==`string`){let t={};return t[e]=`asc`,t}else return e})}var je=/^_design\//;function Me(e){let t=[];return typeof e==`string`?t.push(e):t=e,t.map(function(e){return e.replace(je,``)})}function Ne(e){return e.fields=e.fields.map(function(e){if(typeof e==`string`){let t={};return t[e]=`asc`,t}return e}),e.partial_filter_selector&&=_(e.partial_filter_selector),e}function Pe(e,t){return t.def.fields.map(t=>y(e,u(m(t))))}function Fe(e,t,n){let r=n.def.fields,i=0;for(let a of e){let e=Pe(a.doc,n);if(r.length===1)e=e[0];else for(;e.length>t.length;)e.pop();if(Math.abs(S(e,t))>0)break;++i}return i>0?e.slice(i):e}function Ie(e){let t=i(e);return delete t.startkey,delete t.endkey,delete t.inclusive_start,delete t.inclusive_end,`endkey`in e&&(t.startkey=e.endkey),`startkey`in e&&(t.endkey=e.startkey),`inclusive_start`in e&&(t.inclusive_end=e.inclusive_start),`inclusive_end`in e&&(t.inclusive_start=e.inclusive_end),t}function Le(e){let t=e.fields.filter(function(e){return l(e)===`asc`});if(t.length!==0&&t.length!==e.fields.length)throw Error(`unsupported mixed sorting`)}function Re(e,t){if(t.defaultUsed&&e.sort){let t=e.sort.filter(function(e){return Object.keys(e)[0]!==`_id`}).map(function(e){return Object.keys(e)[0]});if(t.length>0)throw Error(`Cannot sort on field(s) "`+t.join(`,`)+`" when using the default index`)}t.defaultUsed}function ze(e){if(typeof e.selector!=`object`)throw Error(`you must provide a selector when you find()`)}function Be(e,t){let n=Object.keys(e),r=t?t.map(m):[],i;return i=n.length>=r.length?n:r,r.length===0?{fields:i}:(i=i.sort(function(e,t){let n=r.indexOf(e);n===-1&&(n=Number.MAX_VALUE);let i=r.indexOf(t);return i===-1&&(i=Number.MAX_VALUE),n<i?-1:+(n>i)}),{fields:i,sortOrder:t.map(m)})}async function Ve(e,t){t=G(t);let r=i(t.index);t.index=Ne(t.index),Le(t.index);let a;function o(){return a||=n(JSON.stringify(t))}let c=t.name||`idx-`+o(),l=t.ddoc||`idx-`+o(),u=`_design/`+l,d=!1,f=!1;function p(e){return e._rev&&e.language!==`query`&&(d=!0),e.language=`query`,e.views=e.views||{},f=!!e.views[c],f?!1:(e.views[c]={map:{fields:F(t.index.fields),partial_filter_selector:t.index.partial_filter_selector},reduce:`_count`,options:{def:r}},e)}if(e.constructor.emit(`debug`,[`find`,`creating index`,u]),await s(e,u,p),d)throw Error(`invalid language for ddoc with id "`+u+`" (should be "query")`);let m=l+`/`+c;return await X(e).query.call(e,m,{limit:0,reduce:!1}),{id:u,name:c,result:f?`exists`:`created`}}async function He(e){let t=await e.allDocs({startkey:`_design/`,endkey:`_design/`,include_docs:!0}),n={indexes:[{ddoc:null,name:`_all_docs`,type:`special`,def:{fields:[{_id:`asc`}]}}]};return n.indexes=P(n.indexes,t.rows.filter(function(e){return e.doc.language===`query`}).map(function(e){return(e.doc.views===void 0?[]:Object.keys(e.doc.views)).map(function(t){let n=e.doc.views[t];return{ddoc:e.id,name:t,type:`json`,def:Ne(n.options.def)}})})),n.indexes.sort(function(e,t){return x(e.name,t.name)}),n.total_rows=n.indexes.length,n}var Z=null,Q={"":{}},Ue={queryOpts:{limit:0,startkey:Q,endkey:Z},inMemoryFields:[]};function We(e,t){return e.def.fields.some(e=>m(e)===t)}function Ge(e,t){let n=e[t];return m(n)!==`$eq`}function Ke(e,t){let n=t.def.fields.map(m);return e.slice().sort(function(e,t){let r=n.indexOf(e),i=n.indexOf(t);return r===-1&&(r=Number.MAX_VALUE),i===-1&&(i=Number.MAX_VALUE),x(r,i)})}function qe(e,t,n){n=Ke(n,e);let r=!1;for(let i=0,a=n.length;i<a;i++){let o=n[i];if(r||!We(e,o))return n.slice(i);i<a-1&&Ge(t,o)&&(r=!0)}return[]}function Je(e){let t=[];for(let[n,r]of Object.entries(e))for(let e of Object.keys(r))e===`$ne`&&t.push(n);return t}function Ye(e,t,n,r){return Ke(U(P(e,qe(t,n,r),Je(n))),t)}function Xe(e,t,n){if(t){let r=R(t,e),i=L(n,e);return r&&i}return z(n,e)}var Ze=[`$eq`,`$gt`,`$gte`,`$lt`,`$lte`];function Qe(e){return Ze.indexOf(e)===-1}function $e(e,t){let n=t[e[0]];return n===void 0?!0:!(Object.keys(n).length===1&&m(n)===`$ne`)}function et(e,t,n,r){let i=e.def.fields.map(m);return Xe(i,t,n)?$e(i,r):!1}function tt(e,t,n,r){return r.filter(function(r){return et(r,n,t,e)})}function nt(e,t,n,r,i){let a=tt(e,t,n,r);if(a.length===0){if(i)throw{error:`no_usable_index`,message:`There is no index available for this selector.`};let e=r[0];return e.defaultUsed=!0,e}if(a.length===1&&!i)return a[0];let o=B(t);function s(e){let t=e.def.fields.map(m),n=0;for(let e of t)o[e]&&n++;return n}if(i){let e=`_design/`+i[0],t=i.length===2?i[1]:!1,n=a.find(function(n){return!!(t&&n.ddoc===e&&t===n.name||n.ddoc===e)});if(!n)throw{error:`unknown_error`,message:`Could not find that index or could not use that index for the query`};return n}return V(a,s)}function rt(e,t){switch(e){case`$eq`:return{key:t};case`$lte`:return{endkey:t};case`$gte`:return{startkey:t};case`$lt`:return{endkey:t,inclusive_end:!1};case`$gt`:return{startkey:t,inclusive_start:!1}}return{startkey:Z}}function it(e,t){let n=m(t.def.fields[0]),r=e[n]||{},i=[],a=Object.keys(r),o;for(let e of a){Qe(e)&&i.push(n);let t=r[e],a=rt(e,t);o=o?F([o,a]):a}return{queryOpts:o,inMemoryFields:i}}function at(e,t){switch(e){case`$eq`:return{startkey:t,endkey:t};case`$lte`:return{endkey:t};case`$gte`:return{startkey:t};case`$lt`:return{endkey:t,inclusive_end:!1};case`$gt`:return{startkey:t,inclusive_start:!1}}}function ot(e,t){let n=t.def.fields.map(m),r=[],i=[],a=[],o,s;function c(e){o!==!1&&i.push(Z),s!==!1&&a.push(Q),r=n.slice(e)}for(let t=0,r=n.length;t<r;t++){let r=e[n[t]];if(!r||!Object.keys(r).length){c(t);break}else if(Object.keys(r).some(Qe)){c(t);break}else if(t>0){let i=`$gt`in r||`$gte`in r||`$lt`in r||`$lte`in r,a=Object.keys(e[n[t-1]]),o=H(a,[`$eq`]),s=H(a,Object.keys(r));if(i&&!o&&!s){c(t);break}}let l=Object.keys(r),u=null;for(let e of l){let t=r[e],n=at(e,t);u=u?F([u,n]):n}i.push(`startkey`in u?u.startkey:Z),a.push(`endkey`in u?u.endkey:Q),`inclusive_start`in u&&(o=u.inclusive_start),`inclusive_end`in u&&(s=u.inclusive_end)}let l={startkey:i,endkey:a};return o!==void 0&&(l.inclusive_start=o),s!==void 0&&(l.inclusive_end=s),{queryOpts:l,inMemoryFields:r}}function st(e){return Object.keys(e).map(function(t){return e[t]}).some(function(e){return typeof e==`object`&&Object.keys(e).length===0})}function ct(e){return{queryOpts:{startkey:null},inMemoryFields:[Object.keys(e)]}}function lt(e,t){return t.defaultUsed?ct(e,t):t.def.fields.length===1?it(e,t):ot(e,t)}function ut(e,t){let n=e.selector,r=e.sort;if(st(n))return Object.assign({},Ue,{index:t[0]});let i=Be(n,r),a=i.fields,o=i.sortOrder,s=nt(n,a,o,t,e.use_index),c=lt(n,s),l=c.queryOpts,u=c.inMemoryFields;return{queryOpts:l,index:s,inMemoryFields:Ye(u,s,n,a)}}function dt(e){return e.ddoc.substring(8)+`/`+e.name}async function ft(e,t){let n=i(t);n.descending?(`endkey`in n&&typeof n.endkey!=`string`&&(n.endkey=``),`startkey`in n&&typeof n.startkey!=`string`&&(n.limit=0)):(`startkey`in n&&typeof n.startkey!=`string`&&(n.startkey=``),`endkey`in n&&typeof n.endkey!=`string`&&(n.limit=0)),`key`in n&&typeof n.key!=`string`&&(n.limit=0),n.limit>0&&n.indexes_count&&(n.original_limit=n.limit,n.limit+=n.indexes_count);let r=await e.allDocs(n);return r.rows=r.rows.filter(function(e){return!/^_design\//.test(e.id)}),n.original_limit&&(n.limit=n.original_limit),r.rows=r.rows.slice(0,n.limit),r}async function pt(e,t,n){return n.name===`_all_docs`?ft(e,t):X(e).query.call(e,dt(n),t)}async function mt(e,t,n){t.selector&&=(q(t.selector,!1),_(t.selector)),t.sort&&=Ae(t.sort),t.use_index&&=Me(t.use_index),`limit`in t||(t.limit=25),ze(t);let r=await He(e);e.constructor.emit(`debug`,[`find`,`planning query`,t]);let i=ut(t,r.indexes);e.constructor.emit(`debug`,[`find`,`query plan`,i]);let a=i.index;Re(t,a);let o=Object.assign({include_docs:!0,reduce:!1,indexes_count:r.total_rows},i.queryOpts);if(`startkey`in o&&`endkey`in o&&S(o.startkey,o.endkey)>0)return{docs:[]};if(t.sort&&typeof t.sort[0]!=`string`&&l(t.sort[0])===`desc`&&(o.descending=!0,o=Ie(o)),i.inMemoryFields.length||(o.limit=t.limit,`skip`in t&&(o.skip=t.skip)),n)return Promise.resolve(i,o);let s=await pt(e,o,a);o.inclusive_start===!1&&(s.rows=Fe(s.rows,o.startkey,a)),i.inMemoryFields.length&&(s.rows=g(s.rows,t,i.inMemoryFields));let c={docs:s.rows.map(function(e){let n=e.doc;return t.fields?I(n,t.fields):n})};return a.defaultUsed&&(c.warning=`No matching index found, create an index to optimize query time.`),c}async function ht(e,t){let n=await mt(e,t,!0);return{dbname:e.name,index:n.index,selector:t.selector,range:{start_key:n.queryOpts.startkey,end_key:n.queryOpts.endkey},opts:{use_index:t.use_index||[],bookmark:`nil`,limit:t.limit,skip:t.skip,sort:t.sort||{},fields:t.fields,conflicts:!1,r:[49]},limit:t.limit,skip:t.skip||0,fields:t.fields}}async function gt(e,t){if(!t.ddoc)throw Error(`you must supply an index.ddoc when deleting`);if(!t.name)throw Error(`you must supply an index.name when deleting`);let n=t.ddoc,r=t.name;function i(e){return Object.keys(e.views).length===1&&e.views[r]?{_id:n,_deleted:!0}:(delete e.views[r],e)}return await s(e,n,i),await X(e).viewCleanup.apply(e),{ok:!0}}var $={};$.createIndex=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide an index to create`);return(a(this)?he:Ve)(this,e)}),$.find=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide search parameters to find()`);return(a(this)?ge:mt)(this,e)}),$.explain=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide search parameters to explain()`);return(a(this)?_e:ht)(this,e)}),$.getIndexes=W(async function(){return(a(this)?ve:He)(this)}),$.deleteIndex=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide an index to delete`);return(a(this)?ye:gt)(this,e)});export{$ as default};
|