From 561cf10f1312c6951c577048394f6f198652652b Mon Sep 17 00:00:00 2001 From: Paul Kilmurray Date: Wed, 12 Jun 2024 20:31:13 +0100 Subject: [PATCH] make sure idb worker is included --- .gitignore | 1 + assets/js/indexeddb.worker.js | 1 + 2 files changed, 2 insertions(+) create mode 100644 assets/js/indexeddb.worker.js diff --git a/.gitignore b/.gitignore index e2a0d9ad..34134a85 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ composer.lock .wp-env.override.json assets/js/* !assets/js/README.md +!assets/js/indexeddb.worker.js assets/css/* !assets/css/README.md assets/asset-manifest.json diff --git a/assets/js/indexeddb.worker.js b/assets/js/indexeddb.worker.js new file mode 100644 index 00000000..66d81893 --- /dev/null +++ b/assets/js/indexeddb.worker.js @@ -0,0 +1 @@ +(()=>{function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(t){var n=function(t,n){if("object"!=e(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,n||"default");if("object"!=e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==e(n)?n:n+""}function n(e,n){for(var r=0;r!1,deepFreezeWhenDevMode:e=>e,tunnelErrorMessage:e=>"RxDB Error-Code "+e+".\n Error messages are not included in RxDB core to reduce build size.\n "};function c(e,t,n){return"RxError ("+t+"):\n"+e+"\n"+function(e){var t="";return 0===Object.keys(e).length?t:(t+="Given parameters: {\n",t+=Object.keys(e).map((t=>{var n="[object Object]";try{n="errors"===t?e[t].map((e=>JSON.stringify(e,Object.getOwnPropertyNames(e)))):JSON.stringify(e[t],(function(e,t){return void 0===t?null:t}),2)}catch(e){}return t+":"+n})).join("\n"),t+="}")}(n)}var u=function(e){function t(t,n,r={}){var o,i=c(n,t,r);return(o=e.call(this,i)||this).code=t,o.message=i,o.url=l(t),o.parameters=r,o.rxdb=!0,o}var o,i,s,a,u;return i=e,(o=t).prototype=Object.create(i.prototype),o.prototype.constructor=o,r(o,i),t.prototype.toString=function(){return this.message},s=t,(a=[{key:"name",get:function(){return"RxError ("+this.code+")"}},{key:"typeError",get:function(){return!1}}])&&n(s.prototype,a),u&&n(s,u),Object.defineProperty(s,"prototype",{writable:!1}),s}(s(Error));function l(e){return"https://rxdb.info/errors.html?code="+e+"&console=errors"}function f(e){return"\n You can find out more about this error here: "+l(e)+" "}function d(e,t){return new u(e,a.tunnelErrorMessage(e)+f(e),t)}var h=/\./g,p="abcdefghijklmnopqrstuvwxyz",m=e=>{var t=typeof e;return null!==e&&("object"===t||"function"===t)},v=new Set(["__proto__","prototype","constructor"]),y=new Set("0123456789");function b(e){var t=[],n="",r="start",o=!1;for(var i of e)switch(i){case"\\":if("index"===r)throw new Error("Invalid character in an index");if("indexEnd"===r)throw new Error("Invalid character after an index");o&&(n+=i),r="property",o=!o;break;case".":if("index"===r)throw new Error("Invalid character in an index");if("indexEnd"===r){r="property";break}if(o){o=!1,n+=i;break}if(v.has(n))return[];t.push(n),n="",r="property";break;case"[":if("index"===r)throw new Error("Invalid character in an index");if("indexEnd"===r){r="index";break}if(o){o=!1,n+=i;break}if("property"===r){if(v.has(n))return[];t.push(n),n=""}r="index";break;case"]":if("index"===r){t.push(Number.parseInt(n,10)),n="",r="indexEnd";break}if("indexEnd"===r)throw new Error("Invalid character after an index");default:if("index"===r&&!y.has(i))throw new Error("Invalid character in an index");if("indexEnd"===r)throw new Error("Invalid character after an index");"start"===r&&(r="property"),o&&(o=!1,n+="\\"),n+=i}switch(o&&(n+="\\"),r){case"property":if(v.has(n))return[];t.push(n);break;case"index":throw new Error("Index was not closed");case"start":t.push("")}return t}function g(e,t){if("number"!=typeof t&&Array.isArray(e)){var n=Number.parseInt(t,10);return Number.isInteger(n)&&e[n]===e[t]}return!1}var w=1;function O(e,t){var n=function(e,t,n){if(Array.isArray(t)&&(t=t.join(".")),!t.includes(".")&&!t.includes("["))return e[t];if(!m(e)||"string"!=typeof t)return void 0===n?e:n;var r=b(t);if(0===r.length)return n;for(var o=0;ot[e]:e=>{for(var r=e,o=0;o"desc"===Object.values(e)[0])),i=new Set;Object.keys(n).forEach((t=>{var r=O(e,t);r&&"boolean"===r.type&&Object.prototype.hasOwnProperty.call(n[t],"$eq")&&i.add(t)}));var s,a=t.sort.map((e=>Object.keys(e)[0])).filter((e=>!i.has(e))).join(","),c=-1;if(r.forEach((e=>{var r=!0,u=!0,l=e.map((e=>{var t=n[e],o=t?Object.keys(t):[],i={};return t&&o.length?o.forEach((e=>{if(T.has(e)){var n=function(e,t){switch(e){case"$eq":return{startKey:t,endKey:t,inclusiveEnd:!0,inclusiveStart:!0};case"$lte":return{endKey:t,inclusiveEnd:!0};case"$gte":return{startKey:t,inclusiveStart:!0};case"$lt":return{endKey:t,inclusiveEnd:!1};case"$gt":return{startKey:t,inclusiveStart:!1};default:throw new Error("SNH")}}(e,t[e]);i=Object.assign(i,n)}})):i={startKey:u?$:A,endKey:r?A:$,inclusiveStart:!0,inclusiveEnd:!0},void 0===i.startKey&&(i.startKey=$),void 0===i.endKey&&(i.endKey=A),void 0===i.inclusiveStart&&(i.inclusiveStart=!0),void 0===i.inclusiveEnd&&(i.inclusiveEnd=!0),u&&!i.inclusiveStart&&(u=!1),r&&!i.inclusiveEnd&&(r=!1),i})),f=l.map((e=>e.startKey)),d=l.map((e=>e.endKey)),h={index:e,startKeys:f,endKeys:d,inclusiveEnd:r,inclusiveStart:u,sortSatisfiedByIndex:!o&&a===e.filter((e=>!i.has(e))).join(","),selectorSatisfiedByIndex:C(e,t.selector,f,d)},p=function(e,t,n){var r=0,o=e=>{e>0&&(r+=e)},i=10,s=N(n.startKeys,(e=>e!==$&&e!==A));o(s*i);var a=N(n.startKeys,(e=>e!==A&&e!==$));o(a*i);var c=N(n.startKeys,((e,t)=>e===n.endKeys[t]));return o(c*i*1.5),o(n.sortSatisfiedByIndex?5:0),r}(0,0,h);(p>=c||t.index)&&(c=p,s=h)})),!s)throw d("SNH",{query:t});return s}var T=new Set(["$eq","$gt","$gte","$lt","$lte"]),R=new Set(["$eq","$gt","$gte"]),M=new Set(["$eq","$lt","$lte"]);function C(e,t,n,r){var o=Object.entries(t).find((([t,n])=>!e.includes(t)||Object.entries(n).find((([e,t])=>!T.has(e)))));if(o)return!1;if(t.$and||t.$or)return!1;var i=[],s=new Set;for(var[a,c]of Object.entries(t)){if(!e.includes(a))return!1;var u=Object.keys(c).filter((e=>R.has(e)));if(u.length>1)return!1;var l=u[0];if(l&&s.add(a),"$eq"!==l){if(i.length>0)return!1;i.push(l)}}var f=[],d=new Set;for(var[h,p]of Object.entries(t)){if(!e.includes(h))return!1;var m=Object.keys(p).filter((e=>M.has(e)));if(m.length>1)return!1;var v=m[0];if(v&&d.add(h),"$eq"!==v){if(f.length>0)return!1;f.push(v)}}var y=0;for(var b of e){for(var g of[s,d]){if(!g.has(b)&&g.size>0)return!1;g.delete(b)}if(n[y]!==r[y]&&s.size>0&&d.size>0)return!1;y++}return!0}function B(e,t){if(!t.sort)throw d("SNH",{query:t});return{query:t,queryPlan:D(e,t)}}class L extends Error{}const K=Number.MAX_SAFE_INTEGER,U=Number.MIN_SAFE_INTEGER,F=Symbol("missing"),q=Object.freeze(new Error("mingo: cycle detected while processing object/array")),z=Object.getPrototypeOf([]),W=Object.getPrototypeOf({}),J=/^\[object ([a-zA-Z0-9]+)\]$/;class V{}class H{}const G=e=>null===e?V:void 0===e?H:e.constructor,Y=e=>{const t=function(e){const t=new Set,n=e=>{const r=G(e);if(te.has(r))return te.get(r)(e);const o=r===Object?"":r.name;if(me(e.toJSON))return`${o}(${JSON.stringify(e)})`;if(t.has(e))throw q;t.add(e);try{if(r===Array)return"["+e.map(n).join(",")+"]";if(r!==Object){const[t,r]=je(e);if(le(e))return`${o}${n([...e,t])}`;e=t}const t=Object.keys(e);return t.sort(),`${o}{`+t.map((t=>`${t}:${n(e[t])}`)).join(",")+"}"}finally{t.delete(e)}};return n(e)}(e);let n=0,r=t.length;for(;r;)n=(n<<5)-n^t.charCodeAt(--r);return n>>>0},Q=new Set(["null","undefined","boolean","number","string","date","regexp"]),X=new Set([H,V,Boolean,String,Number]),Z=e=>e.toString(),ee=e=>`${G(e).name}[${e.toString()}]`,te=new Map([[Number,Z],[Boolean,Z],[RegExp,Z],[Function,Z],[Symbol,Z],[Date,e=>e.toISOString()],[String,JSON.stringify],[V,e=>"null"],[H,e=>"undefined"],[Int8Array,ee],[Uint8Array,ee],[Uint8ClampedArray,ee],[Int16Array,ee],[Uint16Array,ee],[Int32Array,ee],[Uint32Array,ee],[Float32Array,ee],[Float64Array,ee]]);"undefined"!=typeof BigInt&&te.set(BigInt,(e=>"0x"+e.toString(16))),"undefined"!=typeof BigInt64Array&&te.set(BigInt64Array,ee),"undefined"!=typeof BigUint64Array&&te.set(BigUint64Array,ee);const ne={null:0,undefined:0,number:1,string:2,object:3,array:4,boolean:5,date:6,regexp:7,function:8},re=(e,t)=>{e===F&&(e=void 0),t===F&&(t=void 0);const[n,r]=[e,t].map((e=>ne[se(e).toLowerCase()]));return n!==r?n-r:1===n||2===n||6===n?et?1:0:ke(e,t)?0:et?1:0};function oe(e,t){if(!e)throw new L(t)}const ie=e=>{if(X.has(G(e)))return e;const t=new Set,n=e=>{if(t.has(e))throw q;const r=G(e);if(X.has(r))return e;try{if(le(e))return t.add(e),e.map(n);if(fe(e)){t.add(e);const r={};for(const t in e)r[t]=n(e[t]);return r}}finally{t.delete(e)}return r===Date||r===RegExp||(e=>{const t=Object.getPrototypeOf(G(e));return t&&"TypedArray"===t.name})(e)?new r(e):e};return n(e)},se=e=>J.exec(Object.prototype.toString.call(e))[1],ae=e=>"boolean"==typeof e,ce=e=>"string"==typeof e,ue=e=>!isNaN(e)&&"number"==typeof e,le=Array.isArray,fe=e=>{if(!e)return!1;const t=Object.getPrototypeOf(e);return(t===W||null===t)&&"[object Object]"===Object.prototype.toString.call(e)},de=e=>e===Object(e),he=e=>e instanceof Date,pe=e=>e instanceof RegExp,me=e=>"function"==typeof e,ve=e=>null==e,ye=(e,t)=>e.includes(t),be=(e,t)=>!ye(e,t),ge=e=>ve(e)||ce(e)&&!e||e instanceof Array&&0===e.length||fe(e)&&0===Object.keys(e).length,we=e=>e===F,Oe=e=>e instanceof Array?e:[e],Se=(e,t)=>!!e&&Object.prototype.hasOwnProperty.call(e,t),xe=(e,t)=>fe(e)&&fe(t)||le(e)&&le(t);function Ie(e,t,n){if(n=n||{flatten:!1},we(e)||ve(e))return t;if(we(t)||ve(t))return e;if(!xe(e,t)){if(n.skipValidation)return t||e;throw Error("mismatched types. must both be array or object")}if(n.skipValidation=!0,le(e)){const r=e,o=t;if(n.flatten){let e=0,i=0;for(;e{const i=Ne(r,t);n.has(i)?n.get(i).some((t=>ke(e[t],r)))||n.get(i).push(o):n.set(i,[o])})),n}function Pe(e,t=Y){if(e.some((e=>0==e.length)))return[];if(1===e.length)return Array.from(e);const n=function(e,t,n=re){if(ge(e))return e;const r=new Array,o=new Array;for(let n=0;nn(e[0],t[0]))),De(o,r.map((e=>e[1])))}(e.map(((e,t)=>[t,e.length])),(e=>e[1])),r=e[n[0][0]],o=Ee(r,t),i=new Map,s=new Array;return o.forEach(((t,o)=>{const a=t.map((e=>r[e])),c=a.map((e=>0)),u=a.map((e=>[n[0][0],0]));let l=!1;for(let t=1;tf[e]));l=a.map(((n,s)=>e.some(((e,a)=>{const l=c[s];return ke(n,e)&&(c[s]++,rt===e.length-1?[a[n],u[n]]:F)).filter((e=>e!==F)))})),s.sort(((e,t)=>{const[n,[r,o]]=e,[i,[s,a]]=t,c=re(r,s);return 0!==c?c:re(o,a)})).map((e=>e[0]))}function _e(e,t=0){const n=new Array;return function e(t,r){for(let o=0,i=t.length;o0||r<0)?e(t[o],Math.max(-1,r-1)):n.push(t[o])}(e,t),n}const je=e=>{let[t,n]=[Object.getPrototypeOf(e),Object.getOwnPropertyNames(e)],r=t;for(;!n.length&&t!==W&&t!==z;)r=t,n=Object.getOwnPropertyNames(t),t=Object.getPrototypeOf(t);const o={};return n.forEach((t=>o[t]=e[t])),[o,r]};function ke(e,t){const n=[[e,t]];for(;n.length>0;){if([e,t]=n.pop(),e===t)continue;const r=G(e);if(r!==G(t)||me(e))return!1;if(te.has(r)){const n=te.get(r);if(n(e)!==n(t))return!1}else{if(r!==Array&&r!==Object)return!1;{const r=Object.keys(e),o=Object.keys(t);if(r.length!==o.length)return!1;if(new Set(r.concat(o)).size!=r.length)return!1;for(const o of r)n.push([e[o],t[o]])}}}return!n.length}function Ne(e,t){return t=t||Y,ve(e)?null:t(e).toString()}function Ae(e,t,n=Y){if(e.length<1)return new Map;const r=new Map,o=new Map;for(let i=0;ike(e,a))):null;ve(e)?(o.set(a,[s]),r.has(c)?r.get(c).push(a):r.set(c,[a])):o.get(e).push(s)}}return o}const $e=5e4;function De(e,...t){return e instanceof Array?t.reduce(((e,t)=>{let n=Math.ceil(t.length/$e),r=0;for(;n-- >0;)Array.prototype.push.apply(e,t.slice(r,r+$e)),r+=$e;return e}),e):t.filter(de).reduce(((e,t)=>(Object.assign(e,t),e)),e)}function Te(e,t){return de(e)?e[t]:void 0}function Re(e,t,n){let r=0;const o=Q.has(se(e).toLowerCase())?e:function e(t,n){let o=t;for(let t=0;t0)break;r+=1;const i=n.slice(t);o=o.reduce(((t,n)=>{const r=e(n,i);return void 0!==r&&t.push(r),t}),[]);break}if(o=Te(o,i),void 0===o)break}return o}(e,t.split("."));return o instanceof Array&&(null==n?void 0:n.unwrapArray)?function(e,t){if(t<1)return e;for(;t--&&1===e.length;)e=e[0];return e}(o,r):o}function Me(e,t,n){const r=t.split("."),o=r[0],i=r.slice(1).join("."),s=null!==/^\d+$/.exec(o),a=r.length>1;let c,u;if(e instanceof Array)if(s)c=Te(e,Number(o)),a&&(c=Me(c,i,n)),c=[c];else{c=[];for(const r of e)u=Me(r,t,n),(null==n?void 0:n.preserveMissing)?(void 0===u&&(u=F),c.push(u)):void 0!==u&&c.push(u)}else{if(u=Te(e,o),a&&(u=Me(u,i,n)),void 0===u)return;c=(null==n?void 0:n.preserveKeys)?Object.assign({},e):{},c[o]=u}return c}function Ce(e){if(e instanceof Array)for(let t=e.length-1;t>=0;t--)e[t]===F?e.splice(t,1):Ce(e[t]);else if(fe(e))for(const t in e)Se(e,t)&&Ce(e[t])}const Be=/^\d+$/;function Le(e,t,n,r){const o=t.split("."),i=o[0],s=o.slice(1).join(".");if(1===o.length)(fe(e)||le(e)&&Be.test(i))&&n(e,i);else{(null==r?void 0:r.buildGraph)&&ve(e[i])&&(e[i]={});const t=e[i];if(!t)return;const a=!!(o.length>1&&Be.test(o[1]));t instanceof Array&&(null==r?void 0:r.descendArray)&&!a?t.forEach((e=>Le(e,s,n,r))):Le(t,s,n,r)}}function Ke(e,t,n){Le(e,t,((e,t)=>{e[t]=me(n)?n(e[t]):n}),{buildGraph:!0})}function Ue(e,t,n){Le(e,t,((e,t)=>{if(e instanceof Array){if(/^\d+$/.test(t))e.splice(parseInt(t),1);else if(n&&n.descendArray)for(const n of e)fe(n)&&delete n[t]}else fe(e)&&delete e[t]}),n)}const Fe=/^\$[a-zA-Z0-9_]+$/;function qe(e){return Fe.test(e)}function ze(e){if(Q.has(se(e).toLowerCase()))return pe(e)?{$regex:e}:{$eq:e};if(de(e)){const t=e;if(!Object.keys(t).some(qe))return{$eq:e};if(Se(e,"$regex")){const t=Object.assign({},e);return t.$regex=new RegExp(e.$regex,e.$options),delete t.$options,t}}return e}var We,Je;!function(e){e.CLONE_ALL="CLONE_ALL",e.CLONE_INPUT="CLONE_INPUT",e.CLONE_OUTPUT="CLONE_OUTPUT",e.CLONE_OFF="CLONE_OFF"}(We||(We={}));class Ve{constructor(e,t,n,r=Date.now()){this._opts=e,this._root=t,this._local=n,this.timestamp=r,this.update(t,n)}static init(e,t,n){return e instanceof Ve?new Ve(e._opts,ve(e.root)?t:e.root,Object.assign({},e.local,n)):new Ve(e,t,n)}update(e,t){var n;return this._root=e,this._local=t?Object.assign({},t,{variables:Object.assign({},null===(n=this._local)||void 0===n?void 0:n.variables,null==t?void 0:t.variables)}):t,this}getOptions(){return Object.freeze(Object.assign(Object.assign({},this._opts),{context:Ge.from(this._opts.context)}))}get root(){return this._root}get local(){return this._local}get idKey(){return this._opts.idKey}get collation(){var e;return null===(e=this._opts)||void 0===e?void 0:e.collation}get processingMode(){var e;return(null===(e=this._opts)||void 0===e?void 0:e.processingMode)||We.CLONE_OFF}get useStrictMode(){var e;return null===(e=this._opts)||void 0===e?void 0:e.useStrictMode}get scriptEnabled(){var e;return null===(e=this._opts)||void 0===e?void 0:e.scriptEnabled}get useGlobalContext(){var e;return null===(e=this._opts)||void 0===e?void 0:e.useGlobalContext}get hashFunction(){var e;return null===(e=this._opts)||void 0===e?void 0:e.hashFunction}get collectionResolver(){var e;return null===(e=this._opts)||void 0===e?void 0:e.collectionResolver}get jsonSchemaValidator(){var e;return null===(e=this._opts)||void 0===e?void 0:e.jsonSchemaValidator}get variables(){var e;return null===(e=this._opts)||void 0===e?void 0:e.variables}get context(){var e;return null===(e=this._opts)||void 0===e?void 0:e.context}}function He(e){return e instanceof Ve?e.getOptions():Object.freeze(Object.assign(Object.assign({idKey:"_id",scriptEnabled:!0,useStrictMode:!0,useGlobalContext:!0,processingMode:We.CLONE_OFF},e),{context:(null==e?void 0:e.context)?Ge.from(null==e?void 0:e.context):Ge.init({})}))}!function(e){e.ACCUMULATOR="accumulator",e.EXPRESSION="expression",e.PIPELINE="pipeline",e.PROJECTION="projection",e.QUERY="query",e.WINDOW="window"}(Je||(Je={}));class Ge{constructor(e){this.operators={[Je.ACCUMULATOR]:{},[Je.EXPRESSION]:{},[Je.PIPELINE]:{},[Je.PROJECTION]:{},[Je.QUERY]:{},[Je.WINDOW]:{}};for(const[t,n]of Object.entries(e))this.addOperators(t,n)}static init(e={}){return new Ge(e)}static from(e){return new Ge(e.operators)}addOperators(e,t){for(const[n,r]of Object.entries(t))this.getOperator(e,n)||(this.operators[e][n]=r);return this}addAccumulatorOps(e){return this.addOperators(Je.ACCUMULATOR,e)}addExpressionOps(e){return this.addOperators(Je.EXPRESSION,e)}addQueryOps(e){return this.addOperators(Je.QUERY,e)}addPipelineOps(e){return this.addOperators(Je.PIPELINE,e)}addProjectionOps(e){return this.addOperators(Je.PROJECTION,e)}addWindowOps(e){return this.addOperators(Je.WINDOW,e)}getOperator(e,t){return e in this.operators&&this.operators[e][t]||null}}const Ye=Ge.init();function Qe(e,t){for(const[n,r]of Object.entries(t)){oe(me(r)&&qe(n),`'${n}' is not a valid operator`);const t=Xe(e,n,null);oe(!t||r===t,`${n} already exists for '${e}' operators. Cannot change operator function once registered.`)}switch(e){case Je.ACCUMULATOR:Ye.addAccumulatorOps(t);break;case Je.EXPRESSION:Ye.addExpressionOps(t);break;case Je.PIPELINE:Ye.addPipelineOps(t);break;case Je.PROJECTION:Ye.addProjectionOps(t);break;case Je.QUERY:Ye.addQueryOps(t);break;case Je.WINDOW:Ye.addWindowOps(t)}}function Xe(e,t,n){const{context:r,useGlobalContext:o}=n||{},i=r?r.getOperator(e,t):null;return!i&&o?Ye.getOperator(e,t):i}const Ze={$$ROOT:(e,t,n)=>n.root,$$CURRENT:(e,t,n)=>e,$$REMOVE(e,t,n){},$$NOW:(e,t,n)=>new Date(n.timestamp)},et={$$KEEP:(e,t,n)=>e,$$PRUNE(e,t,n){},$$DESCEND(e,t,n){if(!Se(t,"$cond"))return e;let r;for(const[o,i]of Object.entries(e))if(de(i)){if(i instanceof Array){const e=[];for(let r of i)fe(r)&&(r=nt(r,t,n.update(r))),ve(r)||e.push(r);r=e}else r=nt(i,t,n.update(i));ve(r)?delete e[o]:e[o]=r}return e}};function tt(e,t,n,r){var o;const i=Ve.init(r,e);if(qe(n=n||"")){const o=Xe(Je.EXPRESSION,n,r);if(o)return o(e,t,i);const s=Xe(Je.ACCUMULATOR,n,r);if(s)return e instanceof Array||(e=tt(e,t,null,i),t=null),oe(e instanceof Array,`'${n}' target must be an array.`),s(e,t,i.update(null,i.local));throw new L(`operator '${n}' is not registered`)}if(ce(t)&&t.length>0&&"$"===t[0]){if(Se(et,t))return t;let n=i.root;const r=t.split(".");if(Se(Ze,r[0]))n=Ze[r[0]](e,null,i),t=t.slice(r[0].length+1);else if("$$"===r[0].slice(0,2)){n=Object.assign({},i.variables,{this:e},null===(o=i.local)||void 0===o?void 0:o.variables);const s=r[0].slice(2);oe(Se(n,s),`Use of undefined variable: ${s}`),t=t.slice(2)}else t=t.slice(1);return""===t?n:Re(n,t)}if(le(t))return t.map((t=>tt(e,t,null,i)));if(fe(t)){const n={};for(const[o,s]of Object.entries(t))if(n[o]=tt(e,s,o,i),[Je.EXPRESSION,Je.ACCUMULATOR].some((e=>!!Xe(e,o,r))))return oe(1===Object.keys(t).length,"Invalid aggregation expression '"+JSON.stringify(t)+"'"),n[o];return n}return t}function nt(e,t,n){const r=tt(e,t,null,n);return Se(et,r)?et[r](e,t,n):r}function rt(e){return e instanceof at?e:new at(e)}function ot(e,t){const n=e.slice(t+1);e.splice(t),Array.prototype.push.apply(e,n)}const it=new Error;var st;!function(e){e[e.MAP=0]="MAP",e[e.FILTER=1]="FILTER",e[e.TAKE=2]="TAKE",e[e.DROP=3]="DROP"}(st||(st={}));class at{constructor(e){let t;if(this.iteratees=[],this.yieldedValues=[],this.isDone=!1,e instanceof Function&&(e={next:e}),(n=e)&&"object"==typeof n&&(null==n?void 0:n.next)instanceof Function){const n=e;t=()=>{const e=n.next();if(e.done)throw it;return e.value}}else if(e instanceof Array){const n=e,r=n.length;let o=0;t=()=>{if(o0?this.push(st.TAKE,e):this}drop(e){return e>0?this.push(st.DROP,e):this}transform(e){const t=this;let n;return rt((()=>(n||(n=rt(e(t.value()))),n.next())))}value(){return this.isDone||(this.isDone=this.getNext(!0).done),this.yieldedValues}each(e){for(;;){const t=this.next();if(t.done)break;if(!1===e(t.value))return!1}return!0}reduce(e,t){let n=this.next();for(void 0!==t||n.done||(t=n.value,n=this.next());!n.done;)t=e(t,n.value),n=this.next();return t}size(){return this.reduce(((e,t)=>++e),0)}[Symbol.iterator](){return this}}class ct{constructor(e,t){this.pipeline=e,this.options=He(t)}stream(e){let t=rt(e);const n=this.options.processingMode;n!=We.CLONE_ALL&&n!=We.CLONE_INPUT||t.map(ie);const r=new Array;if(!ge(this.pipeline))for(const e of this.pipeline){const n=Object.keys(e),o=n[0],i=Xe(Je.PIPELINE,o,this.options);oe(1===n.length&&!!i,`invalid pipeline operator ${o}`),r.push(o),t=i(t,e[o],this.options)}return(n==We.CLONE_OUTPUT||n==We.CLONE_ALL&&Pe([["$group","$unwind"],r]).length)&&t.map(ie),t}run(e){return this.stream(e).value()}}class ut{constructor(e,t,n,r){this.source=e,this.predicate=t,this.projection=n,this.options=r,this.operators=[],this.result=null,this.buffer=[]}fetch(){return this.result||(fe(this.projection)&&this.operators.push({$project:this.projection}),this.result=rt(this.source).filter(this.predicate),this.operators.length>0&&(this.result=new ct(this.operators,this.options).stream(this.result))),this.result}fetchAll(){const e=rt([...this.buffer]);return this.buffer=[],function(...e){let t=0;return rt((()=>{for(;t0)return this.buffer.pop();const e=this.fetch().next();return e.done?void 0:e.value}hasNext(){if(this.buffer.length>0)return!0;const e=this.fetch().next();return!e.done&&(this.buffer.push(e.value),!0)}map(e){return this.all().map(e)}forEach(e){this.all().forEach(e)}[Symbol.iterator](){return this.fetchAll()}}class lt{constructor(e,t){this.condition=e,this.options=He(t),this.compiled=[],this.compile()}compile(){oe(fe(this.condition),`query criteria must be an object: ${JSON.stringify(this.condition)}`);const e={};for(const[t,n]of Object.entries(this.condition)){if("$where"===t)Object.assign(e,{field:t,expr:n});else if(ye(["$and","$or","$nor","$expr","$jsonSchema"],t))this.processOperator(t,t,n);else{oe(!qe(t),`unknown top level operator: ${t}`);for(const[e,r]of Object.entries(ze(n)))this.processOperator(t,e,r)}e.field&&this.processOperator(e.field,e.field,e.expr)}}processOperator(e,t,n){const r=Xe(Je.QUERY,t,this.options);if(!r)throw new L(`unknown query operator ${t}`);const o=r(e,n,this.options);this.compiled.push(o)}test(e){for(let t=0,n=this.compiled.length;tthis.test(e)),t||{},this.options)}remove(e){return e.reduce(((e,t)=>(this.test(t)||e.push(t),e)),[])}}new WeakMap;const ft=(e,t,n)=>{if(ge(t)||!fe(t))return e;let r=re;const o=n.collation;return fe(o)&&ce(o.locale)&&(r=function(e){const t={sensitivity:dt[e.strength||3],caseFirst:"off"===e.caseFirst?"false":e.caseFirst||"false",numeric:e.numericOrdering||!1,ignorePunctuation:"shifted"===e.alternate};!0===(e.caseLevel||!1)&&("base"===t.sensitivity&&(t.sensitivity="case"),"accent"===t.sensitivity&&(t.sensitivity="variant"));const n=new Intl.Collator(e.locale,t);return(e,t)=>{if(!ce(e)||!ce(t))return re(e,t);const r=n.compare(e,t);return r<0?-1:r>0?1:0}}(o)),e.transform((e=>{const o=Object.keys(t);for(const i of o.reverse()){const o=Ae(e,(e=>Re(e,i)),n.hashFunction),s=Array.from(o.keys()).sort(r);-1===t[i]&&s.reverse(),e=[],s.reduce(((e,t)=>De(e,o.get(t))),e)}return e}))},dt={1:"base",2:"accent",3:"variant"};function ht(e){const t=(t,n,r)=>{const o={unwrapArray:!0},i=Math.max(1,t.split(".").length-1);return s=>{const a=Re(s,t,o);return e(a,n,Object.assign(Object.assign({},r),{depth:i}))}};return t.op="query",t}function pt(e){return(t,n,r)=>{const o=tt(t,n,null,r);return e(...o)}}function mt(e,t,n){if(ke(e,t))return!0;if(ve(e)&&ve(t))return!0;if(e instanceof Array){const r=ke.bind(null,t);return e.some(r)||_e(e,null==n?void 0:n.depth).some(r)}return!1}function vt(e,t,n){return!mt(e,t,n)}function yt(e,t,n){return ve(e)?t.some((e=>null===e)):Pe([Oe(e),t],null==n?void 0:n.hashFunction).length>0}function bt(e,t,n){return!yt(e,t,n)}function gt(e,t,n){return Nt(e,t,((e,t)=>re(e,t)<0))}function wt(e,t,n){return Nt(e,t,((e,t)=>re(e,t)<=0))}function Ot(e,t,n){return Nt(e,t,((e,t)=>re(e,t)>0))}function St(e,t,n){return Nt(e,t,((e,t)=>re(e,t)>=0))}function xt(e){return qe(e)&&-1===["$and","$or","$nor"].indexOf(e)}function It(e,t,n){if(le(e)&&!ge(e)){let r=e=>e,o=t;Object.keys(t).every(xt)&&(o={temp:t},r=e=>({temp:e}));const i=new lt(o,n);for(let t=0,n=e.length;tnull===e,Pt=e=>ue(e)&&e>=-2147483648&&e<=2147483647&&-1===e.toString().indexOf("."),_t=e=>ue(e)&&e>=U&&e<=K&&-1===e.toString().indexOf("."),jt={array:le,bool:ae,boolean:ae,date:he,decimal:ue,double:ue,int:Pt,long:_t,number:ue,null:Et,object:fe,regex:pe,regexp:pe,string:ce,undefined:ve,function:e=>{throw new L("unsupported type key `function`.")},1:ue,2:ce,3:fe,4:le,6:ve,8:ae,9:he,10:Et,11:pe,16:Pt,18:_t,19:ue};function kt(e,t,n){const r=jt[t];return!!r&&r(e)}function Nt(e,t,n){return Oe(e).some((e=>se(e)===se(t)&&n(e,t)))}pt(bt);const At=(e,t)=>(n,r,o)=>{oe(le(r),`${e}: expression must be an array.`);const i=tt(n,r,null,o);return i.some(ve)?null:(oe(i.every(ue),`${e}: expression must evalue to array of numbers.`),t(i))};At("$bitAnd",(e=>e.reduce(((e,t)=>e&t),-1))),At("$bitOr",(e=>e.reduce(((e,t)=>e|t),0))),At("$bitXor",(e=>e.reduce(((e,t)=>e^t),0))),pt(mt),pt(Ot),pt(St),pt(gt),pt(wt),pt(vt);const $t=(e,t)=>{const n={};return e.split("").forEach(((e,r)=>n[e]=t*(r+1))),n};Object.assign(Object.assign(Object.assign({},$t("ABCDEFGHIKLM",1)),$t("NOPQRSTUVWXY",-1)),{Z:0});const Dt={undefined:null,null:null,NaN:NaN,Infinity:new Error,"-Infinity":new Error};function Tt(e,t=Dt){const n=Object.assign({},Dt,t),r=new Set(Object.keys(n));return(t,o,i)=>{const s=tt(t,o,null,i);if(r.has(`${s}`)){const t=n[`${s}`];if(t instanceof Error)throw new L(`cannot apply $${e.name} to -inf, value must in (-inf,inf)`);return t}return e(s)}}Tt(Math.acos,{Infinity:1/0,0:new Error}),Tt(Math.acosh,{Infinity:1/0,0:new Error}),Tt(Math.asin),Tt(Math.asinh,{Infinity:1/0,"-Infinity":-1/0}),Tt(Math.atan),Tt(Math.atanh,{1:1/0,"-1":-1/0}),Tt(Math.cos),Tt(Math.cosh,{"-Infinity":1/0,Infinity:1/0});const Rt=Math.PI/180,Mt=(Tt((e=>e*Rt),{Infinity:1/0,"-Infinity":1/0}),180/Math.PI);Tt((e=>e*Mt),{Infinity:1/0,"-Infinity":-1/0}),Tt(Math.sin),Tt(Math.sinh,{"-Infinity":-1/0,Infinity:1/0}),Tt(Math.tan);const Ct=(e,t,n)=>{if(ge(t))return e;let r=Object.keys(t),o=!1;Lt(t,n);const i=n.idKey;if(ye(r,i)){const e=t[i];0!==e&&!1!==e||(r=r.filter(be.bind(null,[i])),o=0==r.length)}else r.push(i);const s=Ve.init(n);return e.map((e=>Bt(e,t,s.update(e),r,o)))};function Bt(e,t,n,r,o){let i={},s=!1,a=!1;const c=[];o&&c.push(n.idKey);for(const o of r){let r;const u=t[o];if(o!==n.idKey&&ye([0,!1],u)&&(a=!0),o===n.idKey&&ge(u))r=e[o];else if(ce(u))r=tt(e,u,o,n);else if(ye([1,!0],u));else if(u instanceof Array)r=u.map((t=>{const r=tt(e,t,null,n);return ve(r)?null:r}));else{if(!fe(u)){c.push(o);continue}{const t=u,i=Object.keys(u),a=1==i.length?i[0]:"",c=Xe(Je.PROJECTION,a,n);if(c)"$slice"===a?Oe(t[a]).every(ue)?(r=c(e,t[a],o,n),s=!0):r=tt(e,t,o,n):r=c(e,t[a],o,n);else if(qe(a))r=tt(e,t[a],a,n);else if(Se(e,o)){Lt(t,n);let s=e[o];s instanceof Array?r=s.map((e=>Bt(e,t,n,i,!1))):(s=fe(s)?s:e,r=Bt(s,t,n,i,!1))}else r=tt(e,u,null,n)}}const l=Me(e,o,{preserveMissing:!0});void 0!==l&&Ie(i,l,{flatten:!0}),be([0,1,!1,!0],u)&&(void 0===r?Ue(i,o,{descendArray:!0}):Ke(i,o,r))}if(Ce(i),(s||a||o)&&(i=De({},e,i),c.length>0))for(const e of c)Ue(i,e,{descendArray:!0});return i}function Lt(e,t){const n=[!1,!1];for(const[r,o]of Object.entries(e)){if(r===(null==t?void 0:t.idKey))return;0===o||!1===o?n[0]=!0:1!==o&&!0!==o||(n[1]=!0),oe(!(n[0]&&n[1]),"Projection cannot have a mix of inclusion and exclusion.")}}const Kt=(e,t,n)=>{oe(le(t),"Invalid expression: $and expects value to be an Array.");const r=t.map((e=>new lt(e,n)));return e=>r.every((t=>t.test(e)))},Ut=(e,t,n)=>{oe(le(t),"Invalid expression. $or expects value to be an Array");const r=t.map((e=>new lt(e,n)));return e=>r.some((t=>t.test(e)))},Ft=(e,t,n)=>{oe(le(t),"Invalid expression. $nor expects value to be an array.");const r=Ut("$or",t,n);return e=>!r(e)},qt=(e,t,n)=>{const r={};r[e]=ze(t);const o=new lt(r,n);return e=>!o.test(e)},zt=ht(mt),Wt=ht(Ot),Jt=ht(St),Vt=ht(yt),Ht=ht(gt),Gt=ht(wt),Yt=ht(vt),Qt=ht(bt),Xt=ht((function(e,t,n){return Oe(e).some((e=>2===t.length&&e%t[0]===t[1]))})),Zt=ht((function(e,t,n){const r=Oe(e),o=e=>ce(e)&&((e,t=!0)=>!!e||t&&""===e)(t.exec(e),null==n?void 0:n.useStrictMode);return r.some(o)||_e(r,1).some(o)}));ht((function(e,t,n){if(!(le(e)&&le(t)&&e.length&&t.length))return!1;let r=!0;for(const o of t){if(!r)break;r=fe(o)&&ye(Object.keys(o),"$elemMatch")?It(e,o.$elemMatch,n):o instanceof RegExp?e.some((e=>"string"==typeof e&&o.test(e))):e.some((e=>ke(o,e)))}return r}));const en=ht(It),tn=ht((function(e,t,n){return Array.isArray(e)&&e.length===t})),nn=ht((function(e,t,n){return(!1===t||0===t)&&void 0===e||(!0===t||1===t)&&void 0!==e})),rn=ht((function(e,t,n){return Array.isArray(t)?t.findIndex((t=>kt(e,t)))>=0:kt(e,t)}));var on=!1;function sn(e,t){var n=S(e.primaryKey);t=_(t);var r,o=j(t);if("number"!=typeof o.skip&&(o.skip=0),o.selector?(o.selector=o.selector,Object.entries(o.selector).forEach((([e,t])=>{"object"==typeof t&&null!==t||(o.selector[e]={$eq:t})}))):o.selector={},o.index){var i=(r=o.index,Array.isArray(r)?r.slice(0):[r]);i.includes(n)||i.push(n),o.index=i}if(o.sort){var s=o.sort.find((e=>{return t=e,Object.keys(t)[0]===n;var t}));s||(o.sort=o.sort.slice(0),o.sort.push({[n]:"asc"}))}else if(o.index)o.sort=o.index.map((e=>({[e]:"asc"})));else{if(e.indexes){var a=new Set;Object.entries(o.selector).forEach((([e,t])=>{("object"!=typeof t||null===t||Object.keys(t).find((e=>T.has(e))))&&a.add(e)}));var c,u=-1;e.indexes.forEach((e=>{var t,n=(t=e,Array.isArray(t)?e:[e]),r=n.findIndex((e=>!a.has(e)));r>0&&r>u&&(u=r,c=n)})),c&&(o.sort=c.map((e=>({[e]:"asc"}))))}o.sort||(o.sort=[{[n]:"asc"}])}return o}function an(e,t){if(!t.sort)throw d("SNH",{query:t});var n,r=(n=t.selector,on||(Qe(Je.PIPELINE,{$sort:ft,$project:Ct}),Qe(Je.QUERY,{$and:Kt,$eq:zt,$elemMatch:en,$exists:nn,$gt:Wt,$gte:Jt,$in:Vt,$lt:Ht,$lte:Gt,$ne:Yt,$nin:Qt,$mod:Xt,$nor:Ft,$not:qt,$or:Ut,$regex:Zt,$size:tn,$type:rn}),on=!0),new lt(n));return e=>r.test(e)}function cn(e,t,n,r,o,i,s){for(var a,c=!!e.schema.attachments,u=[],l=[],f=[],h={id:function(e=10){for(var t="",n=0;n0,w=r.length,O=function(){var e,o=r[S],h=o.document,p=o.previous,w=h[t],O=h._deleted,x=p&&p._deleted,I=void 0;if(g&&(I=n.get(w)),I){var P=I._rev;if(!p||p&&P!==p._rev){var _={isError:!0,status:409,documentId:w,writeRow:o,documentInDb:I};return f.push(_),1}var j=c?un(o):o;c&&(O?p&&Object.keys(p._attachments).forEach((e=>{y.push({documentId:w,attachmentId:e,digest:E(p)._attachments[e].digest})})):(Object.entries(h._attachments).find((([t,n])=>((p?p._attachments[t]:void 0)||n.data||(e={documentId:w,documentInDb:I,isError:!0,status:510,writeRow:o,attachmentId:t}),!0))),e||Object.entries(h._attachments).forEach((([e,t])=>{var n=p?p._attachments[e]:void 0;if(n){var r=j.document._attachments[e].digest;t.data&&n.digest!==r&&b.push({documentId:w,attachmentId:e,attachmentData:t,digest:t.digest})}else v.push({documentId:w,attachmentId:e,attachmentData:t,digest:t.digest})})))),e?f.push(e):(c?(l.push(un(j)),s&&s(h)):(l.push(j),s&&s(h)),a=j);var k=null,N=null,A=null;if(x&&!O)A="INSERT",k=c?ln(h):h;else if(!p||x||O){if(!O)throw d("SNH",{args:{writeRow:o}});A="DELETE",k=E(h),N=p}else A="UPDATE",k=c?ln(h):h,N=p;var $={documentId:w,documentData:k,previousDocumentData:N,operation:A};m.push($)}else{var D=!!O;if(c&&Object.entries(h._attachments).forEach((([t,n])=>{n.data?v.push({documentId:w,attachmentId:t,attachmentData:n,digest:n.digest}):(e={documentId:w,isError:!0,status:510,writeRow:o,attachmentId:t},f.push(e))})),e||(c?(u.push(un(o)),i&&i(h)):(u.push(o),i&&i(h)),a=o),!D){var T={documentId:w,operation:"INSERT",documentData:c?ln(h):h,previousDocumentData:c&&p?ln(p):p};m.push(T)}}},S=0;S{var r,o,i;t._attachments[e]=(i=(r=n).data)?{length:(o=i,atob(o).length),digest:r.digest,type:r.type}:r})),t}async function fn(e,t,n){if(e.getChangedDocumentsSince)return e.getChangedDocumentsSince(t,n);var r=S(e.schema.primaryKey),o=B(e.schema,function(e,t,n){var r=S(e.schema.primaryKey),o=n?n.lwt:w,i=n?n.id:"";return sn(e.schema,{selector:{$or:[{"_meta.lwt":{$gt:o}},{"_meta.lwt":{$eq:o},[r]:{$gt:n?i:""}}],"_meta.lwt":{$gte:o}},sort:[{"_meta.lwt":"asc"},{[r]:"asc"}],skip:0,limit:t})}(e,t,n)),i=(await e.query(o)).documents,s=k(i);return{documents:i,checkpoint:s?{id:s[r],lwt:s._meta.lwt}:n||{id:"",lwt:0}}}var dn="15.22.0";function hn(e=0){return new Promise((t=>setTimeout(t,e)))}Promise.resolve(!0);var pn=Promise.resolve(!1),mn=(Promise.resolve(null),Promise.resolve());function vn(e=1e4){return"function"==typeof requestIdleCallback?new Promise((t=>{requestIdleCallback((()=>t()),{timeout:e})})):hn(0)}function yn(e,t){var n=e.get(t);if(void 0===n)throw new Error("missing value from map "+t);return n}function bn(e,t){var n=t.map((t=>{var n=O(e,t);if(!n)throw new Error("not in schema: "+t);var r,o=n.type;"number"!==o&&"integer"!==o||(r=gn(n));var i,s=P(t),a=n.maxLength?n.maxLength:0;return i="string"===o?e=>{var t=s(e);return t||(t=""),t.padEnd(a," ")}:"boolean"===o?e=>s(e)?"1":"0":e=>{var t=s(e);return wn(r,t)},{fieldName:t,schemaPart:n,parsedLengths:r,getValue:s,getIndexStringPart:i}}));return n}function gn(e){var t=Math.floor(e.minimum),n=Math.ceil(e.maximum),r=e.multipleOf,o=(n-t).toString().length,i=r.toString().split("."),s=0;return i.length>1&&(s=i[1].length),{minimum:t,maximum:n,nonDecimals:o,decimals:s,roundedMinimum:t}}function wn(e,t){void 0===t&&(t=0),te.maximum&&(t=e.maximum);var n=(Math.floor(t)-e.roundedMinimum).toString().padStart(e.nonDecimals,"0");if(e.decimals>0){var r=t.toString().split(".");n+=(r.length>1?r[1]:"0").padEnd(e.decimals,"0")}return n}function On(e,t,n){var r="";return t.forEach(((t,o)=>{var i=O(e,t),s=n[o],a=i.type;switch(a){case"string":var c=E(i.maxLength,"maxLength not set");r+="string"==typeof s?s.padEnd(c," "):"".padEnd(c," ");break;case"boolean":r+=null===s||s===$?"0":s===A||s?"1":"0";break;case"number":case"integer":var u=gn(i);if(null===s||s===$)r+="0".repeat(u.nonDecimals+u.decimals);else if(s===A)r+=wn(u,u.maximum);else{var l=wn(u,s);r+=l}break;default:throw new Error("unknown index type "+a)}})),r}function Sn(e,t,n){var r="";return t.forEach(((t,o)=>{var i=O(e,t),s=n[o],a=i.type;switch(a){case"string":var c=E(i.maxLength,"maxLength not set");r+="string"==typeof s&&s!==A?s.padEnd(c," "):"".padEnd(c,s===$?" ":A);break;case"boolean":r+=null===s||s?"1":"0";break;case"number":case"integer":var u=gn(i);r+=null===s||s===A?"9".repeat(u.nonDecimals+u.decimals):s===$?"0".repeat(u.nonDecimals+u.decimals):wn(u,s);break;default:throw new Error("unknown index type "+a)}})),r}function xn(e){return e.join("||")}function In(e,t){var n=xn(t);return yn(e.indexIdByName,n)}var En={locale:null,unique:!1};function Pn(e,t,n,r){for(var o={i:n,d:r,i0:void 0,i1:void 0,i2:void 0,i3:void 0,i4:void 0,i5:void 0,i6:void 0,i7:void 0},i=0;iArray.isArray(e)?e.slice(0):[e])):[];n.push(_n);var r=new Map;return n.forEach(((n,o)=>{var i="i"+o,s=xn(n);if(r.has(s))throw new Error("duplicate index "+s);r.set(s,i),t[i]=function(e,t){var n=bn(e,t),r=n.length,o=n.map((e=>e.getIndexStringPart));return function(e){for(var t="",n=0;nt())),Mn.set(e,n),n}function Bn(e,t){t.onversionchange=n=>{e.closed||(t.close(),e.creationPromise=e.refreshIDBDatabase())}}function Ln(e,t,n,r){var o=e.indexedDBStates.get(n);return o||(o=function(e,t,n){var r=Tn++,o=n.indexedDB,i=async()=>(await hn(0),Cn(e,(()=>new Promise(((t,n)=>{var i=o.open(e);i.onerror=function(t){console.error(r+": OPEN IDB DATABASE "+e+" ERROR"),n(t)},i.onsuccess=function(e){var n=i.result;t(n),Bn(s,n)},Un(s,i)}))))),s={debugId:r,closed:!1,storage:t,settings:n,refreshIDBDatabase:i,creationPromise:i(),name:e,refCount:0,storesToOpen:[]};return s}(n,e,t),e.indexedDBStates.set(n,o)),o.storesToOpen=o.storesToOpen.concat(r),o.refCount=o.refCount+1,o.creationPromise.then((()=>async function(e){var t=e.settings.indexedDB;if(0!==e.storesToOpen.length)return e.creationPromise=e.creationPromise.then((async n=>{var r=new Set(Array.from(n.objectStoreNames));if(0===e.storesToOpen.filter((e=>!r.has(Kn(e.collectionName,e.schema).documentStore))).length)return n;var o=n.version+1;return n.close(),Cn(e.name,(()=>new Promise((async(n,r)=>{var i=t.open(e.name,o);i.onerror=function(t){console.error(e.debugId+": ERROR openStoresOnExistingDatabase() openRequest: error "),r(t)},i.onsuccess=function(t){var r=i.result;Bn(e,r),n(r)},i.onblocked=e=>{},Un(e,i)}))))})),e.creationPromise}(E(o)))).then((()=>E(o)))}function Kn(e,t){var n=t.version;return{documentStore:e+"-"+n+"-"+kn,writeAheadStore:e+"-"+n+"-"+Nn,attachmentsStore:e+"-"+n+"-"+An}}function Un(e,t){t.onupgradeneeded=function(n){var r=t.result;e.storesToOpen.forEach((e=>{var t=r.objectStoreNames,n=Kn(e.collectionName,e.schema);if(!t.contains(n.documentStore)){var o=r.createObjectStore(n.documentStore,{keyPath:"i",autoIncrement:!1});r.createObjectStore(n.writeAheadStore,{keyPath:"i",autoIncrement:!1}),function(e,t){t.indexIds.forEach((t=>{e.createIndex(t,t,En)}))}(o,e),e.schema.attachments&&r.createObjectStore(n.attachmentsStore,{keyPath:"docIdWithAttachmentId",autoIncrement:!1})}})),e.storesToOpen=[]}}function Fn(e){if(e.closed)throw new Error("RxStorageInstanceIndexedDB is closed "+e.databaseName+"-"+e.collectionName)}async function qn(e,t){var n=e.primaryPath,r=e.internals.indexIds.length,o=e.internals.getIndexableStringByIndexNumber,i=t.objectStore(e.internals.storeNames.writeAheadStore),s=await new Promise(((e,t)=>{var n=i.get("documents");n.onerror=t,n.onsuccess=t=>{var r=n.result;e(r?JSON.parse(r.docsData):void 0)}}));if(s&&s.length>0){for(var a,c=t.objectStore(e.internals.storeNames.documentStore),u=0;u{a.onerror=t,a.onsuccess=()=>e(!0)})),i.delete("documents")}return t}async function zn(e){var t,n=[e.internals.storeNames.documentStore,e.internals.storeNames.writeAheadStore];e.schema.attachments&&n.push(e.internals.storeNames.attachmentsStore);for(var r=3;r>0;){var o=await e.internals.state.creationPromise;r-=1;try{t=o.transaction(n,"readwrite",$n)}catch(t){if(!("InvalidStateError"===t.name&&r>0))throw t;e.internals.state.creationPromise=e.internals.state.refreshIDBDatabase()}}return await qn(e,E(t)),E(t)}var Wn=function(){function e(e){this.allTasksRuns=[],this.instance=e,this.txPromise=zn(this.instance).then((t=>qn(e,t)))}return e.prototype.addTask=function(e){var t=this.txPromise.then((t=>e(t))),n=t.catch((()=>null));this.allTasksRuns.push(n);var r=this.allTasksRuns.length;return n.then((()=>Promise.all(this.allTasksRuns))).then((()=>{this.allTasksRuns.length===r&&(this.instance.openReadonlyTransaction=void 0)})),t.catch((t=>{if("TransactionInactiveError"===t.name)return this.instance.openReadonlyTransaction=void 0,Jn(this.instance,e);throw t}))},e}();function Jn(e,t){return e.openReadonlyTransaction||(e.openReadonlyTransaction=new Wn(e)),e.openReadonlyTransaction.addTask(t)}var Vn=function(e,t){return Vn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},Vn(e,t)};function Hn(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}Vn(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function Gn(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function Yn(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Xn(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function Zn(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o1||a(e,t)}))})}function a(e,t){try{(n=o[e](t)).value instanceof er?Promise.resolve(n.value.v).then(c,u):l(i[0][2],n)}catch(e){l(i[0][3],e)}var n}function c(e){a("next",e)}function u(e){a("throw",e)}function l(e,t){e(t),i.shift(),i.length&&a(i[0][0],i[0][1])}}function nr(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e=Qn(e),t={},r("next"),r("throw"),r("return"),t[Symbol.asyncIterator]=function(){return this},t);function r(n){t[n]=e[n]&&function(t){return new Promise((function(r,o){!function(e,t,n,r){Promise.resolve(r).then((function(t){e({value:t,done:n})}),t)}(r,o,(t=e[n](t)).done,t.value)}))}}}function rr(e){return"function"==typeof e}function or(e){var t=e((function(e){Error.call(e),e.stack=(new Error).stack}));return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var ir=or((function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map((function(e,t){return t+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}}));function sr(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var ar=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,n,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=Qn(i),a=s.next();!a.done;a=s.next())a.value.remove(this)}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else i.remove(this);var c=this.initialTeardown;if(rr(c))try{c()}catch(e){o=e instanceof ir?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var l=Qn(u),f=l.next();!f.done;f=l.next()){var d=f.value;try{lr(d)}catch(e){o=null!=o?o:[],e instanceof ir?o=Zn(Zn([],Xn(o)),Xn(e.errors)):o.push(e)}}}catch(e){n={error:e}}finally{try{f&&!f.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}}if(o)throw new ir(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)lr(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(n=this._finalizers)&&void 0!==n?n:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&sr(t,e)},e.prototype.remove=function(t){var n=this._finalizers;n&&sr(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}(),cr=ar.EMPTY;function ur(e){return e instanceof ar||e&&"closed"in e&&rr(e.remove)&&rr(e.add)&&rr(e.unsubscribe)}function lr(e){rr(e)?e():e.unsubscribe()}var fr={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},dr={setTimeout:function(e,t){for(var n=[],r=2;r0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var t=this,n=this,r=n.hasError,o=n.isStopped,i=n.observers;return r||o?cr:(this.currentObservers=null,i.push(e),new ar((function(){t.currentObservers=null,sr(i,e)})))},t.prototype._checkFinalizedStatuses=function(e){var t=this,n=t.hasError,r=t.thrownError,o=t.isStopped;n?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new Nr;return e.source=this,e},t.create=function(e,t){return new Tr(e,t)},t}(Nr),Tr=function(e){function t(t,n){var r=e.call(this)||this;return r.destination=t,r.source=n,r}return Hn(t,e),t.prototype.next=function(e){var t,n;null===(n=null===(t=this.destination)||void 0===t?void 0:t.next)||void 0===n||n.call(t,e)},t.prototype.error=function(e){var t,n;null===(n=null===(t=this.destination)||void 0===t?void 0:t.error)||void 0===n||n.call(t,e)},t.prototype.complete=function(){var e,t;null===(t=null===(e=this.destination)||void 0===e?void 0:e.complete)||void 0===t||t.call(e)},t.prototype._subscribe=function(e){var t,n;return null!==(n=null===(t=this.source)||void 0===t?void 0:t.subscribe(e))&&void 0!==n?n:cr},t}(Dr);function Rr(e){return function(t){if(function(e){return rr(null==e?void 0:e.lift)}(t))return t.lift((function(t){try{return e(t,this)}catch(e){this.error(e)}}));throw new TypeError("Unable to lift unknown Observable type")}}var Mr=Array.isArray;function Cr(e,t,n,r,o){return new Br(e,t,n,r,o)}var Br=function(e){function t(t,n,r,o,i,s){var a=e.call(this,t)||this;return a.onFinalize=i,a.shouldUnsubscribe=s,a._next=n?function(e){try{n(e)}catch(e){t.error(e)}}:e.prototype._next,a._error=o?function(e){try{o(e)}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._error,a._complete=r?function(){try{r()}catch(e){t.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,a}return Hn(t,e),t.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;e.prototype.unsubscribe.call(this),!n&&(null===(t=this.onFinalize)||void 0===t||t.call(this))}},t}(gr),Lr=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function Kr(e){return rr(null==e?void 0:e.then)}function Ur(e){return rr(e[_r])}function Fr(e){return Symbol.asyncIterator&&rr(null==e?void 0:e[Symbol.asyncIterator])}function qr(e){return new TypeError("You provided "+(null!==e&&"object"==typeof e?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var zr="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function Wr(e){return rr(null==e?void 0:e[zr])}function Jr(e){return tr(this,arguments,(function(){var t,n,r;return Yn(this,(function(o){switch(o.label){case 0:t=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,er(t.read())];case 3:return n=o.sent(),r=n.value,n.done?[4,er(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,er(r)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return t.releaseLock(),[7];case 10:return[2]}}))}))}function Vr(e){return rr(null==e?void 0:e.getReader)}function Hr(e){if(e instanceof Nr)return e;if(null!=e){if(Ur(e))return o=e,new Nr((function(e){var t=o[_r]();if(rr(t.subscribe))return t.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(Lr(e))return r=e,new Nr((function(e){for(var t=0;t{this._to=!1,function(e){const t=ho()-e.ttl,n=e.map[Symbol.iterator]();for(;;){const r=n.next().value;if(!r)return;const o=r[0];if(!(r[1]0&&void 0!==arguments[0]?arguments[0]:{},t=JSON.parse(JSON.stringify(e));return void 0===t.webWorkerSupport&&(t.webWorkerSupport=!0),t.idb||(t.idb={}),t.idb.ttl||(t.idb.ttl=45e3),t.idb.fallbackInterval||(t.idb.fallbackInterval=150),e.idb&&"function"==typeof e.idb.onclose&&(t.idb.onclose=e.idb.onclose),t.localstorage||(t.localstorage={}),t.localstorage.removeTimeout||(t.localstorage.removeTimeout=6e4),e.methods&&(t.methods=e.methods),t.node||(t.node={}),t.node.ttl||(t.node.ttl=12e4),t.node.maxParallelWrites||(t.node.maxParallelWrites=2048),void 0===t.node.useFastPath&&(t.node.useFastPath=!0),t}var mo="pubkey.broadcast-channel-0-",vo="messages",yo={durability:"relaxed"};function bo(){if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof window){if(void 0!==window.mozIndexedDB)return window.mozIndexedDB;if(void 0!==window.webkitIndexedDB)return window.webkitIndexedDB;if(void 0!==window.msIndexedDB)return window.msIndexedDB}return!1}function go(e){e.commit&&e.commit()}function wo(e,t){var n=e.transaction(vo,"readonly",yo),r=n.objectStore(vo),o=[],i=IDBKeyRange.bound(t+1,1/0);if(r.getAll){var s=r.getAll(i);return new Promise((function(e,t){s.onerror=function(e){return t(e)},s.onsuccess=function(t){e(t.target.result)}}))}return new Promise((function(e,s){var a=function(){try{return i=IDBKeyRange.bound(t+1,1/0),r.openCursor(i)}catch(e){return r.openCursor()}}();a.onerror=function(e){return s(e)},a.onsuccess=function(r){var i=r.target.result;i?i.value.ide.lastCursorId&&(e.lastCursorId=t.id),t})).filter((function(t){return function(e,t){return!(e.uuid===t.uuid||t.eMIs.has(e.id)||e.data.time0||e._addEL.internal.length>0}function Ko(e,t,n){e._addEL[t].push(n),function(e){if(!e._iL&&Lo(e)){var t=function(t){e._addEL[t.type].forEach((function(e){t.time>=e.time&&e.fn(t.data)}))},n=e.method.microSeconds();e._prepP?e._prepP.then((function(){e._iL=!0,e.method.onMessage(e._state,t,n)})):(e._iL=!0,e.method.onMessage(e._state,t,n))}}(e)}function Uo(e,t,n){e._addEL[t]=e._addEL[t].filter((function(e){return e!==n})),function(e){if(e._iL&&!Lo(e)){e._iL=!1;var t=e.method.microSeconds();e.method.onMessage(e._state,null,t)}}(e)}Co._pubkey=!0,Co.prototype={postMessage:function(e){if(this.closed)throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed "+JSON.stringify(e));return Bo(this,"message",e)},postInternal:function(e){return Bo(this,"internal",e)},set onmessage(e){var t={time:this.method.microSeconds(),fn:e};Uo(this,"message",this._onML),e&&"function"==typeof e?(this._onML=t,Ko(this,"message",t)):this._onML=null},addEventListener:function(e,t){Ko(this,e,{time:this.method.microSeconds(),fn:t})},removeEventListener:function(e,t){Uo(this,e,this._addEL[e].find((function(e){return e.fn===t})))},close:function(){var e=this;if(!this.closed){Ro.delete(this),this.closed=!0;var t=this._prepP?this._prepP:io;return this._onML=null,this._addEL.message=[],t.then((function(){return Promise.all(Array.from(e._uMP))})).then((function(){return Promise.all(e._befC.map((function(e){return e()})))})).then((function(){return e.method.close(e._state)}))}},get type(){return this.method.type},get isClosed(){return this.closed}};var Fo=new Map;function qo(e,t){var n=Fo.get(e);if(n)return n.refs.delete(t),0===n.refs.size?(Fo.delete(e),n.bc.close()):void 0}function zo(e,t,n,r){if(t.multiInstance){var o=r||function(e,t,n,r){var o=Fo.get(t);return o||(o={bc:new Co(["RxDB:",e,n].join("|")),refs:new Set},Fo.set(t,o)),o.refs.add(r),o.bc}(e,t.databaseInstanceToken,n.databaseName,n),i=new Dr,s=n=>{n.storageName===e&&n.databaseName===t.databaseName&&n.collectionName===t.collectionName&&n.version===t.schema.version&&i.next(n.eventBulk)};o.addEventListener("message",s);var a=n.changeStream(),c=!1,u=a.subscribe((n=>{c||o.postMessage({storageName:e,databaseName:t.databaseName,collectionName:t.collectionName,version:t.schema.version,eventBulk:n})}));n.changeStream=function(){return i.asObservable().pipe(function(){for(var e=[],t=0;t{var r=t.queryPlan,o=t.query,i=o.skip?o.skip:0,s=i+(o.limit?o.limit:1/0),a=e.internals.storeNames.documentStore,c=e.settings.batchSize?e.settings.batchSize:50,u=!1;r.selectorSatisfiedByIndex||(u=an(e.schema,o));var l,f=r.index,h=!r.sortSatisfiedByIndex,p=f,m=r.startKeys,v=On(e.schema,p,m),y=r.endKeys,b=Sn(e.schema,p,y),g=[],w=n.objectStore(a),O=In(e.internals,p);l=w.index(O),u||t.query.limit||(c=1e5);var S=!1;if(await async function(e,t,n,r,o,i,s,a){var c=e.settings.IDBKeyRange?e.settings.IDBKeyRange:IDBKeyRange,u=e.internals.getIndexableStringByIndexId[s];if("function"==typeof n.getAll&&1!==r)for(var l,f=!0,d=!1,h=async function(){l&&(o=u(l.d));var e=c.bound(o,i,!f||!t.inclusiveStart,!t.inclusiveEnd);f=!1;var s=n.getAll(e,r);await new Promise(((e,t)=>{s.onerror=t,s.onsuccess=t=>{var n=t.target.result;l=k(n),0!==n.length&&!1===a(n)&&(d=!0),n.length{m.onsuccess=function(t){var n=t.target.result;if(n){var r=n.value;a([r])?n.continue():e()}else e()}}))}}(e,r,l,c,v,b,O,(e=>{for(var t=0;t{var t=Object.keys(e)[0],r=Object.values(e)[0];n.push({key:t,direction:r,getValueFn:P(t)})})),(e,t)=>{for(var r=0;r30&&!await function(e,t){var n=(e.settings.IDBKeyRange?e.settings.IDBKeyRange:IDBKeyRange).lowerBound($,!0),r=t.getKey(n);return new Promise((e=>{r.onsuccess=()=>{e(!!r.result)}}))}(e,l)?new Map:await function(e,t,n){var r=n.length,o=new Map;if(0===r)return Promise.resolve(o);for(var i=new Array(r),s=0;s{u.onerror=n,u.onsuccess=()=>{for(var n=0;n0){var g=u.objectStore(o.storeNames.writeAheadStore).put({i:"documents",docsData:JSON.stringify(s)});await new Promise(((e,t)=>{g.onerror=t,g.onsuccess=e})),e.handleWalIdlePromise||hn(100).then((()=>vn())).then((async()=>{e.handleWalIdlePromise=void 0,e.closed||await Jn(e,(()=>pn))}))}var w=void 0;if(e.schema.attachments){var O=u.objectStore(e.internals.storeNames.attachmentsStore);f.attachmentsAdd.forEach((e=>{w=O.put({docIdWithAttachmentId:Rn(e.documentId,e.attachmentId),length:e.attachmentData.length,type:e.attachmentData.type,data:e.attachmentData.data})})),f.attachmentsUpdate.forEach((e=>{w=O.put({docIdWithAttachmentId:Rn(e.documentId,e.attachmentId),length:e.attachmentData.length,type:e.attachmentData.type,data:e.attachmentData.data})})),f.attachmentsRemove.forEach((e=>{w=O.delete(Rn(e.documentId,e.attachmentId))}))}if(w&&await new Promise(((e,t)=>{E(w).onerror=t,E(w).onsuccess=e})),u.commit&&u.commit(),f.eventBulk.events.length>0){var S=E(f.newestRow).document;f.eventBulk.checkpoint={id:S[r],lwt:S._meta.lwt},f.eventBulk.endTime=I(),e.changes$.next(f.eventBulk)}return{success:s,error:d}}var Vo=I(),Ho=function(){function e(e,t,n,r,o,i,s){this.changes$=new Dr,this.instanceId=Vo++,this.storage=e,this.databaseName=t,this.collectionName=n,this.schema=r,this.internals=o,this.options=i,this.settings=s,this.primaryPath=S(this.schema.primaryKey)}var t=e.prototype;return t.updateMinKnownDocs=function(e){this.internals.minKnownDocsAmountfunction(e,t,n){var r=t.length;if(0===r)return Promise.resolve([]);for(var o=new Array,i=0;i{c.onerror=t,c.onsuccess=()=>{for(var t=0;t{var r,o,i=t.queryPlan,s=e.internals.storeNames.documentStore,a=i.index,c=a,u=i.startKeys,l=On(e.schema,c,u),f=i.endKeys,d=Sn(e.schema,c,f),h=n.objectStore(s);o=1===a.length&&a[0]===e.primaryPath?In(e.internals,["_deleted",e.primaryPath]):In(e.internals,c),r=h.index(o);var p=(e.settings.IDBKeyRange?e.settings.IDBKeyRange:IDBKeyRange).bound(l,d,!i.inclusiveStart,!i.inclusiveEnd),m=r.count(p);return{count:await new Promise(((e,t)=>{m.onsuccess=function(){e(m.result)},m.onerror=t})),mode:"fast"}}))}(this,e);return this.updateMinKnownDocs(t.count),t}var n=await Wo(this,e);return this.updateMinKnownDocs(n.documents.length),{count:n.documents.length,mode:"slow"}},t.changeStream=function(){return this.changes$.asObservable()},t.cleanup=async function(e){var t=this.internals.state;await t.creationPromise;var n=this.settings.IDBKeyRange;return Fn(this),Jn(this,(async t=>{var r=t.objectStore(this.internals.storeNames.documentStore),o=this.settings.batchSize,i=I()-e,s=In(this.internals,_n),a=r.index(s),c=On(this.schema,_n,[!0,1]),u=Sn(this.schema,_n,[!0,i]),l=n.bound(c,u,!0,!0),f=await new Promise(((e,t)=>{var n=a.getAll(l,o);n.onerror=t,n.onsuccess=function(t){e(t.target.result)}}));return await Promise.all(f.map((e=>new Promise(((t,n)=>{var o=e.i,i=r.delete(o);i.onerror=n,i.onsuccess=()=>t()}))))),f.length{var t=[e.objectStore(this.internals.storeNames.documentStore),e.objectStore(this.internals.storeNames.writeAheadStore)];return this.schema.attachments&&t.push(e.objectStore(this.internals.storeNames.attachmentsStore)),await Promise.all(t.map((e=>new Promise(((t,n)=>{var r=e.clear();r.onerror=n,r.onsuccess=t}))))),this.close()}))},t.getAttachmentData=async function(e,t){var n=this.internals.state;return await n.creationPromise,Fn(this),Jn(this,(n=>{var r=n.objectStore(this.internals.storeNames.attachmentsStore),o=Rn(e,t);return new Promise(((n,i)=>{var s=r.get(o);s.onsuccess=()=>{var r=s.result;r?n(r.data):i("attachment missing documentId: "+e+" attachmentId: "+t)}}))}))},t.close=async function(){return this.closed||(this.closed=(async()=>(await this.internals.state.creationPromise,await Jn(this,(async e=>{})),this.changes$.complete(),async function(e){if(!e.closed&&(e.refCount=e.refCount-1,0===e.refCount))return e.closed=!0,e.storage.indexedDBStates.delete(e.name),e.creationPromise.then((e=>e.close()))}(this.internals.state)))()),this.closed},t.conflictResultionTasks=function(){return(new Dr).asObservable()},t.resolveConflictResultionTask=function(e){return mn},e}(),Go=function(){function e(e){this.name=Dn,this.rxdbVersion=dn,this.indexedDBStates=new Map,this.settings=e}return e.prototype.createStorageInstance=function(e){return function(e){if(e.schema.keyCompression)throw d("UT5",{args:{params:e}});if((t=e.schema).encrypted&&t.encrypted.length>0||t.attachments&&t.attachments.encrypted)throw d("UT6",{args:{params:e}});var t;if(e.schema.attachments&&e.schema.attachments.compression)throw d("UT7",{args:{params:e}})}(e),async function(e,t,n){var r=jn(t.schema),o=Array.from(r.indexIdByName.values()),i=await Ln(e,n,t.databaseName,[{collectionName:t.collectionName,schema:t.schema,indexIds:o}]);await i.creationPromise;var s={state:i,storeNames:Kn(t.collectionName,t.schema),getIndexableStringByIndexId:r.monadByIndexId,getIndexableStringByIndexNumber:Object.values(r.monadByIndexId),indexIdByName:r.indexIdByName,indexNames:Object.keys(r),indexIds:o,minKnownDocsAmount:0},a=new Ho(e,t.databaseName,t.collectionName,t.schema,s,t.options,n);return await zo(Dn,t,a),a}(this,e,Object.assign({},this.settings,e.options))},e}();function Yo(e,t){return Rr((function(n,r){var o=0;n.subscribe(Cr(r,(function(n){return e.call(t,n,o++)&&r.next(n)})))}))}function Qo(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(e.constructor!==t.constructor)return!1;var n,r;if(Array.isArray(e)){if((n=e.length)!==t.length)return!1;for(r=n;0!=r--;)if(!Qo(e[r],t[r]))return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();var o=Object.keys(e);if((n=o.length)!==Object.keys(t).length)return!1;for(r=n;0!=r--;)if(!Object.prototype.hasOwnProperty.call(t,o[r]))return!1;for(r=n;0!=r--;){var i=o[r];if(!Qo(e[i],t[i]))return!1}return!0}return e!=e&&t!=t}function Xo(e,t){return{connectionId:e.connectionId,answerTo:e.requestId,method:e.method,error:(n=t,{name:n.name,message:n.message,rxdb:n.rxdb,parameters:n.parameters,extensions:n.extensions,code:n.code,url:n.url,stack:n.stack?n.stack.replace(/\n/g," \n "):void 0})};var n}function Zo(e,t){return{connectionId:e.connectionId,answerTo:e.requestId,method:e.method,return:t}}!function(e){var t;console.log("exposeWorkerRxStorage()");var n=new Dr;if("undefined"!=typeof self&&"object"==typeof self.onconnect){var r=new Map;self.onconnect=e=>{var t=e.ports[0];t.onmessage=e=>{var o=e.data;r.set(o.connectionId,t),n.next(o)}},t={storage:e.storage,messages$:n,send(e){yn(r,e.connectionId).postMessage(e)}}}else addEventListener("message",(e=>{var t=e.data;n.next(t)})),t={storage:e.storage,messages$:n,send(e){self.postMessage(e)}};!function(e){var t=new Map;function n(t){if(e.storage)return e.storage.createStorageInstance(t);if(e.database){var n=Array.from(e.database.storageInstances),r=t.collectionName,o=n.find((e=>e.collectionName===r));if(!o)throw console.dir(n),new Error("storageInstance does not exist "+JSON.stringify({collectionName:r}));var i=t.schema;if(!Qo(i,o.schema))throw new Error("Wrong schema "+JSON.stringify({schema:i,existingSchema:o.schema}));return Promise.resolve(o)}throw new Error("no base given")}e.messages$.pipe(Yo((e=>"custom"===e.method))).subscribe((async t=>{if(e.customRequestHandler)try{var n=await e.customRequestHandler(t.params);e.send(Zo(t,n))}catch(n){e.send(Xo(t,n))}else e.send(Xo(t,new Error("Remote storage: cannot resolve custom request because settings.customRequestHandler is not set")))})),e.messages$.pipe(Yo((e=>"create"===e.method))).subscribe((async r=>{var o=r.connectionId;if(!Array.isArray(r.params)){var i=r.params,s=i.collectionName,a=[i.databaseName,i.collectionName,i.schema.version].join("|"),c=t.get(a);if(c){if(!Qo(i.schema,c.params.schema))return void e.send(Xo(r,new Error("Remote storage: schema not equal to existing storage")))}else try{c={storageInstancePromise:n(i),connectionIds:new Set,params:i},t.set(a,c),await c.storageInstancePromise}catch(t){return void e.send(Xo(r,t))}c.connectionIds.add(r.connectionId);var u=[],l=await c.storageInstancePromise;u.push(l.changeStream().subscribe((t=>{var n={connectionId:o,answerTo:"changestream",method:"changeStream",return:t};e.send(n)}))),u.push(l.conflictResultionTasks().subscribe((t=>{var n={connectionId:o,answerTo:"conflictResultionTasks",method:"conflictResultionTasks",return:t};e.send(n)})));var f=!1;if(e.database){var d=e.database,h=d.collections[s];h?h.onDestroy.push((()=>p())):d.onDestroy.push((()=>p()))}u.push(e.messages$.pipe(Yo((e=>e.connectionId===o))).subscribe((async t=>{var n,r=t;if("create"!==r.method&&"custom"!==r.method&&Array.isArray(r.params))try{if("close"===r.method&&e.database)return void e.send(Zo(r,null));if("close"===r.method&&E(c).connectionIds.size>1)return e.send(Zo(r,null)),E(c).connectionIds.delete(o),void u.forEach((e=>e.unsubscribe()));n="getChangedDocumentsSince"!==r.method||l.getChangedDocumentsSince?await l[r.method](r.params[0],r.params[1],r.params[2],r.params[3]):await fn(l,r.params[0],r.params[1]),"close"!==r.method&&"remove"!==r.method||p(),e.send(Zo(r,n))}catch(t){e.send(Xo(r,t))}}))),e.send(Zo(r,"ok"))}function p(){f||(f=!0,u.forEach((e=>e.unsubscribe())),E(c).connectionIds.delete(o),t.delete(a))}}))}(t)}({storage:function(e={}){var t=e.IDBKeyRange?e.IDBKeyRange:IDBKeyRange,n=e.indexedDB?e.indexedDB:indexedDB,r=Object.assign({batchSize:300,transactionDurability:"relaxed"},e,{IDBKeyRange:t,indexedDB:n});return new Go(r)}({})})})(); \ No newline at end of file