@seald-io/nedb
Version:
File-based embedded data store for node.js
2 lines • 106 kB
JavaScript
/*! For license information please see nedb.min.js.LICENSE.txt */
(()=>{var e={100:e=>{e.exports={}},159:e=>{e.exports.uid=e=>(e=>{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=e.length%3;let n,o="";for(let a=0,s=e.length-r;a<s;a+=3)n=(e[a]<<16)+(e[a+1]<<8)+e[a+2],o+=t[(i=n)>>18&63]+t[i>>12&63]+t[i>>6&63]+t[63&i];var i;return 1===r?(n=e[e.length-1],o+=t[n>>2],o+=t[n<<4&63],o+="=="):2===r&&(n=(e[e.length-2]<<8)+e[e.length-1],o+=t[n>>10],o+=t[n>>4&63],o+=t[n<<2&63],o+="="),o})((e=>{const t=new Array(e);for(let r,n=0;n<e;n++)0==(3&n)&&(r=4294967296*Math.random()),t[n]=r>>>((3&n)<<3)&255;return t})(Math.ceil(Math.max(8,2*e)))).replace(/[+/]/g,"").slice(0,e)},909:(e,t,r)=>{const n=r(483).createInstance({name:"NeDB",storeName:"nedbdata"}),o=async(e,t,r)=>{try{await n.setItem(e,t)}catch(e){console.warn("An error happened while writing, skip")}};e.exports.existsAsync=async e=>{try{return null!==await n.getItem(e)}catch(e){return!1}},e.exports.renameAsync=async(e,t)=>{try{const r=await n.getItem(e);null===r?await n.removeItem(t):(await n.setItem(t,r),await n.removeItem(e))}catch(e){console.warn("An error happened while renaming, skip")}},e.exports.writeFileAsync=o,e.exports.crashSafeWriteFileLinesAsync=async(e,t)=>{t.push(""),await o(e,t.join("\n"))},e.exports.appendFileAsync=async(e,t,r)=>{try{const r=await n.getItem(e)||"";await n.setItem(e,r+t)}catch(e){console.warn("An error happened appending to file writing, skip")}},e.exports.readFileAsync=async(e,t)=>{try{return await n.getItem(e)||""}catch(e){return console.warn("An error happened while reading, skip"),""}},e.exports.unlinkAsync=async e=>{try{await n.removeItem(e)}catch(e){console.warn("An error happened while unlinking, skip")}},e.exports.mkdirAsync=(e,t)=>Promise.resolve(),e.exports.ensureDatafileIntegrityAsync=e=>Promise.resolve(),e.exports.ensureParentDirectoryExistsAsync=async(e,t)=>Promise.resolve()},578:(e,t,r)=>{const n=r(118),{callbackify:o}=r(539);e.exports=class{constructor(e,t,r){this.db=e,this.query=t||{},r&&(this.mapFn=r),this._limit=void 0,this._skip=void 0,this._sort=void 0,this._projection=void 0}limit(e){return this._limit=e,this}skip(e){return this._skip=e,this}sort(e){return this._sort=e,this}projection(e){return this._projection=e,this}_project(e){const t=[];let r;if(void 0===this._projection||0===Object.keys(this._projection).length)return e;const o=0!==this._projection._id,{_id:i,...a}=this._projection;this._projection=a;const s=Object.keys(this._projection);return s.forEach((e=>{if(void 0!==r&&this._projection[e]!==r)throw new Error("Can't both keep and omit fields except for _id");r=this._projection[e]})),e.forEach((e=>{let i;1===r?(i={$set:{}},s.forEach((t=>{i.$set[t]=n.getDotValue(e,t),void 0===i.$set[t]&&delete i.$set[t]})),i=n.modify({},i)):(i={$unset:{}},s.forEach((e=>{i.$unset[e]=!0})),i=n.modify(e,i)),o?i._id=e._id:delete i._id,t.push(i)})),t}async _execAsync(){let e=[],t=0,r=0;const o=await this.db._getCandidatesAsync(this.query);for(const i of o)if(n.match(i,this.query))if(this._sort)e.push(i);else if(this._skip&&this._skip>r)r+=1;else if(e.push(i),t+=1,this._limit&&this._limit<=t)break;if(this._sort){const t=Object.entries(this._sort).map((([e,t])=>({key:e,direction:t})));e.sort(((e,r)=>{for(const o of t){const t=o.direction*n.compareThings(n.getDotValue(e,o.key),n.getDotValue(r,o.key),this.db.compareStrings);if(0!==t)return t}return 0}));const r=this._limit||e.length,o=this._skip||0;e=e.slice(o,o+r)}return e=this._project(e),this.mapFn?this.mapFn(e):e}exec(e){o((()=>this.execAsync()))(e)}execAsync(){return this.db.executor.pushAsync((()=>this._execAsync()))}then(e,t){return this.execAsync().then(e,t)}catch(e){return this.execAsync().catch(e)}finally(e){return this.execAsync().finally(e)}}},797:(e,t,r)=>{const{EventEmitter:n}=r(187),{callbackify:o,deprecate:i}=r(539),a=r(578),s=r(159),c=r(196),u=r(98),f=r(118),l=r(328),{isDate:h,pick:p,filterIndexNames:y}=r(988);e.exports=class extends n{constructor(e){let t;super(),"string"==typeof e?i((()=>{t=e,this.inMemoryOnly=!1}),"@seald-io/nedb: Giving a string to the Datastore constructor is deprecated and will be removed in the next major version. Please use an options object with an argument 'filename'.")():(t=(e=e||{}).filename,this.inMemoryOnly=e.inMemoryOnly||!1,this.autoload=e.autoload||!1,this.timestampData=e.timestampData||!1),t&&"string"==typeof t&&0!==t.length?this.filename=t:(this.filename=null,this.inMemoryOnly=!0),this.compareStrings=e.compareStrings,this.persistence=new l({db:this,afterSerialization:e.afterSerialization,beforeDeserialization:e.beforeDeserialization,corruptAlertThreshold:e.corruptAlertThreshold,modes:e.modes,testSerializationHooks:e.testSerializationHooks}),this.executor=new c,this.inMemoryOnly&&(this.executor.ready=!0),this.indexes={},this.indexes._id=new u({fieldName:"_id",unique:!0}),this.ttlIndexes={},this.autoload?(this.autoloadPromise=this.loadDatabaseAsync(),this.autoloadPromise.then((()=>{e.onload&&e.onload()}),(t=>{if(!e.onload)throw t;e.onload(t)}))):this.autoloadPromise=null,this._autocompactionIntervalId=null}compactDatafileAsync(){return this.executor.pushAsync((()=>this.persistence.persistCachedDatabaseAsync()))}compactDatafile(e){const t=this.compactDatafileAsync();"function"==typeof e&&o((()=>t))(e)}setAutocompactionInterval(e){if(Number.isNaN(Number(e)))throw new Error("Interval must be a non-NaN number");const t=Math.max(Number(e),5e3);this.stopAutocompaction(),this._autocompactionIntervalId=setInterval((()=>{this.compactDatafile()}),t)}stopAutocompaction(){this._autocompactionIntervalId&&(clearInterval(this._autocompactionIntervalId),this._autocompactionIntervalId=null)}loadDatabase(e){const t=this.loadDatabaseAsync();"function"==typeof e&&o((()=>t))(e)}dropDatabaseAsync(){return this.persistence.dropDatabaseAsync()}dropDatabase(e){const t=this.dropDatabaseAsync();"function"==typeof e&&o((()=>t))(e)}loadDatabaseAsync(){return this.executor.pushAsync((()=>this.persistence.loadDatabaseAsync()),!0)}getAllData(){return this.indexes._id.getAll()}_resetIndexes(e){for(const t of Object.values(this.indexes))t.reset(e)}ensureIndex(e={},t){const r=this.ensureIndexAsync(e);"function"==typeof t&&o((()=>r))(t)}async ensureIndexAsync(e={}){if(!e.fieldName){const e=new Error("Cannot create an index without a fieldName");throw e.missingFieldName=!0,e}const t=[].concat(e.fieldName).sort();if(t.some((e=>e.includes(","))))throw new Error("Cannot use comma in index fieldName");const r={...e,fieldName:t.join(",")};if(!this.indexes[r.fieldName]){this.indexes[r.fieldName]=new u(r),void 0!==e.expireAfterSeconds&&(this.ttlIndexes[r.fieldName]=r.expireAfterSeconds);try{this.indexes[r.fieldName].insert(this.getAllData())}catch(e){throw delete this.indexes[r.fieldName],e}await this.executor.pushAsync((()=>this.persistence.persistNewStateAsync([{$$indexCreated:r}])),!0)}}removeIndex(e,t=(()=>{})){const r=this.removeIndexAsync(e);o((()=>r))(t)}async removeIndexAsync(e){delete this.indexes[e],await this.executor.pushAsync((()=>this.persistence.persistNewStateAsync([{$$indexRemoved:e}])),!0)}_addToIndexes(e){let t,r;const n=Object.keys(this.indexes);for(let o=0;o<n.length;o+=1)try{this.indexes[n[o]].insert(e)}catch(e){t=o,r=e;break}if(r){for(let r=0;r<t;r+=1)this.indexes[n[r]].remove(e);throw r}}_removeFromIndexes(e){for(const t of Object.values(this.indexes))t.remove(e)}_updateIndexes(e,t){let r,n;const o=Object.keys(this.indexes);for(let i=0;i<o.length;i+=1)try{this.indexes[o[i]].update(e,t)}catch(e){r=i,n=e;break}if(n){for(let n=0;n<r;n+=1)this.indexes[o[n]].revertUpdate(e,t);throw n}}_getRawCandidates(e){const t=Object.keys(this.indexes);let r;if(r=Object.entries(e).filter(y(t)).pop(),r)return this.indexes[r[0]].getMatching(r[1]);const n=t.filter((e=>-1!==e.indexOf(","))).map((e=>e.split(","))).filter((t=>Object.entries(e).filter(y(t)).length===t.length));return n.length>0?this.indexes[n[0]].getMatching(p(e,n[0])):(r=Object.entries(e).filter((([r,n])=>!(!e[r]||!Object.prototype.hasOwnProperty.call(e[r],"$in"))&&t.includes(r))).pop(),r?this.indexes[r[0]].getMatching(r[1].$in):(r=Object.entries(e).filter((([r,n])=>!(!e[r]||!(Object.prototype.hasOwnProperty.call(e[r],"$lt")||Object.prototype.hasOwnProperty.call(e[r],"$lte")||Object.prototype.hasOwnProperty.call(e[r],"$gt")||Object.prototype.hasOwnProperty.call(e[r],"$gte")))&&t.includes(r))).pop(),r?this.indexes[r[0]].getBetweenBounds(r[1]):this.getAllData()))}async _getCandidatesAsync(e,t=!1){const r=[],n=this._getRawCandidates(e);if(t)r.push(...n);else{const e=[],t=Object.keys(this.ttlIndexes);n.forEach((n=>{t.every((e=>!(void 0!==n[e]&&h(n[e])&&Date.now()>n[e].getTime()+1e3*this.ttlIndexes[e])))?r.push(n):e.push(n._id)}));for(const t of e)await this._removeAsync({_id:t},{})}return r}async _insertAsync(e){const t=this._prepareDocumentForInsertion(e);return this._insertInCache(t),await this.persistence.persistNewStateAsync(Array.isArray(t)?t:[t]),f.deepCopy(t)}_createNewId(){let e=s.uid(16);return this.indexes._id.getMatching(e).length>0&&(e=this._createNewId()),e}_prepareDocumentForInsertion(e){let t;if(Array.isArray(e))t=[],e.forEach((e=>{t.push(this._prepareDocumentForInsertion(e))}));else{t=f.deepCopy(e),void 0===t._id&&(t._id=this._createNewId());const r=new Date;this.timestampData&&void 0===t.createdAt&&(t.createdAt=r),this.timestampData&&void 0===t.updatedAt&&(t.updatedAt=r),f.checkObject(t)}return t}_insertInCache(e){Array.isArray(e)?this._insertMultipleDocsInCache(e):this._addToIndexes(e)}_insertMultipleDocsInCache(e){let t,r;for(let n=0;n<e.length;n+=1)try{this._addToIndexes(e[n])}catch(e){r=e,t=n;break}if(r){for(let r=0;r<t;r+=1)this._removeFromIndexes(e[r]);throw r}}insert(e,t){const r=this.insertAsync(e);"function"==typeof t&&o((()=>r))(t)}insertAsync(e){return this.executor.pushAsync((()=>this._insertAsync(e)))}count(e,t){const r=this.countAsync(e);if("function"!=typeof t)return r;o(r.execAsync.bind(r))(t)}countAsync(e){return new a(this,e,(e=>e.length))}find(e,t,r){1===arguments.length?t={}:2===arguments.length&&"function"==typeof t&&(r=t,t={});const n=this.findAsync(e,t);if("function"!=typeof r)return n;o(n.execAsync.bind(n))(r)}findAsync(e,t={}){const r=new a(this,e,(e=>e.map((e=>f.deepCopy(e)))));return r.projection(t),r}findOne(e,t,r){1===arguments.length?t={}:2===arguments.length&&"function"==typeof t&&(r=t,t={});const n=this.findOneAsync(e,t);if("function"!=typeof r)return n;o(n.execAsync.bind(n))(r)}findOneAsync(e,t={}){const r=new a(this,e,(e=>1===e.length?f.deepCopy(e[0]):null));return r.projection(t).limit(1),r}async _updateAsync(e,t,r){const n=void 0!==r.multi&&r.multi;if(void 0!==r.upsert&&r.upsert){const r=new a(this,e);if(1!==(await r.limit(1)._execAsync()).length){let r;try{f.checkObject(t),r=t}catch(n){r=f.modify(f.deepCopy(e,!0),t)}return{numAffected:1,affectedDocuments:await this._insertAsync(r),upsert:!0}}}let o,i=0;const s=[];let c;const u=await this._getCandidatesAsync(e);for(const r of u)f.match(r,e)&&(n||0===i)&&(i+=1,this.timestampData&&(c=r.createdAt),o=f.modify(r,t),this.timestampData&&(o.createdAt=c,o.updatedAt=new Date),s.push({oldDoc:r,newDoc:o}));this._updateIndexes(s);const l=s.map((e=>e.newDoc));if(await this.persistence.persistNewStateAsync(l),r.returnUpdatedDocs){let e=[];return l.forEach((t=>{e.push(f.deepCopy(t))})),n||(e=e[0]),{numAffected:i,affectedDocuments:e,upsert:!1}}return{numAffected:i,upsert:!1,affectedDocuments:null}}update(e,t,r,n){"function"==typeof r&&(n=r,r={}),o(((e,t,r)=>this.updateAsync(e,t,r)))(e,t,r,((e,t={})=>{n&&n(e,t.numAffected,t.affectedDocuments,t.upsert)}))}updateAsync(e,t,r={}){return this.executor.pushAsync((()=>this._updateAsync(e,t,r)))}async _removeAsync(e,t={}){const r=void 0!==t.multi&&t.multi,n=await this._getCandidatesAsync(e,!0),o=[];let i=0;return n.forEach((t=>{f.match(t,e)&&(r||0===i)&&(i+=1,o.push({$$deleted:!0,_id:t._id}),this._removeFromIndexes(t))})),await this.persistence.persistNewStateAsync(o),i}remove(e,t,r){"function"==typeof t&&(r=t,t={});const n=r||(()=>{});o(((e,t)=>this.removeAsync(e,t)))(e,t,n)}removeAsync(e,t={}){return this.executor.pushAsync((()=>this._removeAsync(e,t)))}}},196:(e,t,r)=>{const n=r(496);e.exports=class{constructor(){this.ready=!1,this.queue=new n,this.buffer=null,this._triggerBuffer=null,this.resetBuffer()}pushAsync(e,t=!1){return this.ready||t?this.queue.waterfall(e)():this.buffer.waterfall(e)()}processBuffer(){this.ready=!0,this._triggerBuffer(),this.queue.waterfall((()=>this.buffer.guardian))}resetBuffer(){this.buffer=new n,this.buffer.chain(new Promise((e=>{this._triggerBuffer=e}))),this.ready&&this._triggerBuffer()}}},98:(e,t,r)=>{const n=r(908).AVLTree,o=r(118),{uniq:i,isDate:a}=r(988),s=(e,t)=>e===t,c=e=>null===e?"$null":"string"==typeof e?"$string"+e:"boolean"==typeof e?"$boolean"+e:"number"==typeof e?"$number"+e:a(e)?"$date"+e.getTime():e;e.exports=class{constructor(e){if(this.fieldName=e.fieldName,"string"!=typeof this.fieldName)throw new Error("fieldName must be a string");this._fields=this.fieldName.split(","),this.unique=e.unique||!1,this.sparse=e.sparse||!1,this.treeOptions={unique:this.unique,compareKeys:o.compareThings,checkValueEquality:s},this.tree=new n(this.treeOptions)}reset(e){this.tree=new n(this.treeOptions),e&&this.insert(e)}insert(e){let t,r,n;if(Array.isArray(e))return void this.insertMultipleDocs(e);const a=o.getDotValues(e,this._fields);if(!(void 0===a||"object"==typeof a&&null!==a&&Object.values(a).every((e=>void 0===e)))||!this.sparse)if(Array.isArray(a)){t=i(a,c);for(let o=0;o<t.length;o+=1)try{this.tree.insert(t[o],e)}catch(e){n=e,r=o;break}if(n){for(let n=0;n<r;n+=1)this.tree.delete(t[n],e);throw n}}else this.tree.insert(a,e)}insertMultipleDocs(e){let t,r;for(let n=0;n<e.length;n+=1)try{this.insert(e[n])}catch(e){t=e,r=n;break}if(t){for(let t=0;t<r;t+=1)this.remove(e[t]);throw t}}remove(e){if(Array.isArray(e))return void e.forEach((e=>{this.remove(e)}));const t=o.getDotValues(e,this._fields);void 0===t&&this.sparse||(Array.isArray(t)?i(t,c).forEach((t=>{this.tree.delete(t,e)})):this.tree.delete(t,e))}update(e,t){if(Array.isArray(e))this.updateMultipleDocs(e);else{this.remove(e);try{this.insert(t)}catch(t){throw this.insert(e),t}}}updateMultipleDocs(e){let t,r;for(let t=0;t<e.length;t+=1)this.remove(e[t].oldDoc);for(let n=0;n<e.length;n+=1)try{this.insert(e[n].newDoc)}catch(e){r=e,t=n;break}if(r){for(let r=0;r<t;r+=1)this.remove(e[r].newDoc);for(let t=0;t<e.length;t+=1)this.insert(e[t].oldDoc);throw r}}revertUpdate(e,t){const r=[];Array.isArray(e)?(e.forEach((e=>{r.push({oldDoc:e.newDoc,newDoc:e.oldDoc})})),this.update(r)):this.update(t,e)}getMatching(e){if(Array.isArray(e)){const t={},r=[];return e.forEach((e=>{this.getMatching(e).forEach((e=>{t[e._id]=e}))})),Object.keys(t).forEach((e=>{r.push(t[e])})),r}return this.tree.search(e)}getBetweenBounds(e){return this.tree.betweenBounds(e)}getAll(){const e=[];return this.tree.executeOnEveryNode((t=>{e.push(...t.data)})),e}}},118:(e,t,r)=>{const{uniq:n,isDate:o,isRegExp:i}=r(988),a=(e,t)=>{if("number"==typeof e&&(e=e.toString()),!("$"!==e[0]||"$$date"===e&&"number"==typeof t||"$$deleted"===e&&!0===t||"$$indexCreated"===e||"$$indexRemoved"===e))throw new Error("Field names cannot begin with the $ character");if(-1!==e.indexOf("."))throw new Error("Field names cannot contain a .")},s=e=>{if(Array.isArray(e)&&e.forEach((e=>{s(e)})),"object"==typeof e&&null!==e)for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&(a(t,e[t]),s(e[t]))};function c(e,t){if("boolean"==typeof e||"number"==typeof e||"string"==typeof e||null===e||o(e))return e;if(Array.isArray(e))return e.map((e=>c(e,t)));if("object"==typeof e){const r={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(!t||"$"!==n[0]&&-1===n.indexOf("."))&&(r[n]=c(e[n],t));return r}}const u=e=>"boolean"==typeof e||"number"==typeof e||"string"==typeof e||null===e||o(e)||Array.isArray(e),f=(e,t)=>e<t?-1:e>t?1:0,l=(e,t)=>{const r=Math.min(e.length,t.length);for(let n=0;n<r;n+=1){const r=h(e[n],t[n]);if(0!==r)return r}return f(e.length,t.length)},h=(e,t,r)=>{const n=r||f;if(void 0===e)return void 0===t?0:-1;if(void 0===t)return 1;if(null===e)return null===t?0:-1;if(null===t)return 1;if("number"==typeof e)return"number"==typeof t?f(e,t):-1;if("number"==typeof t)return"number"==typeof e?f(e,t):1;if("string"==typeof e)return"string"==typeof t?n(e,t):-1;if("string"==typeof t)return"string"==typeof e?n(e,t):1;if("boolean"==typeof e)return"boolean"==typeof t?f(e,t):-1;if("boolean"==typeof t)return"boolean"==typeof e?f(e,t):1;if(o(e))return o(t)?f(e.getTime(),t.getTime()):-1;if(o(t))return o(e)?f(e.getTime(),t.getTime()):1;if(Array.isArray(e))return Array.isArray(t)?l(e,t):-1;if(Array.isArray(t))return Array.isArray(e)?l(e,t):1;const i=Object.keys(e).sort(),a=Object.keys(t).sort();for(let r=0;r<Math.min(i.length,a.length);r+=1){const n=h(e[i[r]],t[a[r]]);if(0!==n)return n}return f(i.length,a.length)},p=(e,t=!1)=>(r,n,o)=>{const i=(r,n,o)=>{const a="string"==typeof n?n.split("."):n;if(1===a.length)e(r,n,o);else{if(void 0===r[a[0]]){if(t)return;r[a[0]]={}}i(r[a[0]],a.slice(1),o)}};return i(r,n,o)},y=(e,t,r)=>{if(Object.prototype.hasOwnProperty.call(e,t)||(e[t]=[]),!Array.isArray(e[t]))throw new Error("Can't $addToSet an element on non-array values");if(null!==r&&"object"==typeof r&&r.$each){if(Object.keys(r).length>1)throw new Error("Can't use another field in conjunction with $each");if(!Array.isArray(r.$each))throw new Error("$each requires an array value");r.$each.forEach((r=>{y(e,t,r)}))}else{let n=!0;e[t].forEach((e=>{0===h(e,r)&&(n=!1)})),n&&e[t].push(r)}},d={$set:p(((e,t,r)=>{e[t]=r})),$unset:p(((e,t,r)=>{delete e[t]}),!0),$min:p(((e,t,r)=>{(void 0===e[t]||r<e[t])&&(e[t]=r)})),$max:p(((e,t,r)=>{(void 0===e[t]||r>e[t])&&(e[t]=r)})),$inc:p(((e,t,r)=>{if("number"!=typeof r)throw new Error(`${r} must be a number`);if("number"!=typeof e[t]){if(Object.prototype.hasOwnProperty.call(e,t))throw new Error("Don't use the $inc modifier on non-number fields");e[t]=r}else e[t]+=r})),$pull:p(((e,t,r)=>{if(!Array.isArray(e[t]))throw new Error("Can't $pull an element from non-array values");const n=e[t];for(let e=n.length-1;e>=0;e-=1)O(n[e],r)&&n.splice(e,1)})),$pop:p(((e,t,r)=>{if(!Array.isArray(e[t]))throw new Error("Can't $pop an element from non-array values");if("number"!=typeof r)throw new Error(`${r} isn't an integer, can't use it with $pop`);0!==r&&(e[t]=r>0?e[t].slice(0,e[t].length-1):e[t].slice(1))})),$addToSet:p(y),$push:p(((e,t,r)=>{if(Object.prototype.hasOwnProperty.call(e,t)||(e[t]=[]),!Array.isArray(e[t]))throw new Error("Can't $push an element on non-array values");if(null!==r&&"object"==typeof r&&r.$slice&&void 0===r.$each&&(r.$each=[]),null!==r&&"object"==typeof r&&r.$each){if(Object.keys(r).length>=3||2===Object.keys(r).length&&void 0===r.$slice)throw new Error("Can only use $slice in cunjunction with $each when $push to array");if(!Array.isArray(r.$each))throw new Error("$each requires an array value");if(r.$each.forEach((r=>{e[t].push(r)})),void 0===r.$slice||"number"!=typeof r.$slice)return;if(0===r.$slice)e[t]=[];else{let n,o;const i=e[t].length;r.$slice<0?(n=Math.max(0,i+r.$slice),o=i):r.$slice>0&&(n=0,o=Math.min(i,r.$slice)),e[t]=e[t].slice(n,o)}}else e[t].push(r)}))},g=(e,t)=>{const r="string"==typeof t?t.split("."):t;if(e){if(0===r.length)return e;if(1===r.length)return e[r[0]];if(Array.isArray(e[r[0]])){const t=parseInt(r[1],10);return"number"!=typeof t||isNaN(t)?e[r[0]].map((e=>g(e,r.slice(1)))):g(e[r[0]][t],r.slice(2))}return g(e[r[0]],r.slice(1))}},m=(e,t)=>{if(null===e||"string"==typeof e||"boolean"==typeof e||"number"==typeof e||null===t||"string"==typeof t||"boolean"==typeof t||"number"==typeof t)return e===t;if(o(e)||o(t))return o(e)&&o(t)&&e.getTime()===t.getTime();if((!Array.isArray(e)||!Array.isArray(t))&&(Array.isArray(e)||Array.isArray(t))||void 0===e||void 0===t)return!1;let r,n;try{r=Object.keys(e),n=Object.keys(t)}catch(e){return!1}if(r.length!==n.length)return!1;for(const o of r){if(-1===n.indexOf(o))return!1;if(!m(e[o],t[o]))return!1}return!0},v=(e,t)=>!("string"!=typeof e&&"number"!=typeof e&&!o(e)&&"string"!=typeof t&&"number"!=typeof t&&!o(t))&&typeof e==typeof t,b={$lt:(e,t)=>v(e,t)&&e<t,$lte:(e,t)=>v(e,t)&&e<=t,$gt:(e,t)=>v(e,t)&&e>t,$gte:(e,t)=>v(e,t)&&e>=t,$ne:(e,t)=>void 0===e||!m(e,t),$in:(e,t)=>{if(!Array.isArray(t))throw new Error("$in operator called with a non-array");for(const r of t)if(m(e,r))return!0;return!1},$nin:(e,t)=>{if(!Array.isArray(t))throw new Error("$nin operator called with a non-array");return!b.$in(e,t)},$regex:(e,t)=>{if(!i(t))throw new Error("$regex operator called with non regular expression");return"string"==typeof e&&t.test(e)},$exists:(e,t)=>(t=!(!t&&""!==t),void 0===e?!t:t),$size:(e,t)=>{if(!Array.isArray(e))return!1;if(t%1!=0)throw new Error("$size operator called without an integer");return e.length===t},$elemMatch:(e,t)=>!!Array.isArray(e)&&e.some((e=>O(e,t)))},w={$size:!0,$elemMatch:!0},A={$or:(e,t)=>{if(!Array.isArray(t))throw new Error("$or operator used without an array");for(let r=0;r<t.length;r+=1)if(O(e,t[r]))return!0;return!1},$and:(e,t)=>{if(!Array.isArray(t))throw new Error("$and operator used without an array");for(let r=0;r<t.length;r+=1)if(!O(e,t[r]))return!1;return!0},$not:(e,t)=>!O(e,t),$where:(e,t)=>{if("function"!=typeof t)throw new Error("$where operator used without a function");const r=t.call(e);if("boolean"!=typeof r)throw new Error("$where function must return boolean");return r}},O=(e,t)=>{if(u(e)||u(t))return x({needAKey:e},"needAKey",t);for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const n=t[r];if("$"===r[0]){if(!A[r])throw new Error(`Unknown logical operator ${r}`);if(!A[r](e,n))return!1}else if(!x(e,r,n))return!1}return!0};function x(e,t,r,n){const o=g(e,t);if(Array.isArray(o)&&!n){if(Array.isArray(r))return x(e,t,r,!0);if(null!==r&&"object"==typeof r&&!i(r))for(const n in r)if(Object.prototype.hasOwnProperty.call(r,n)&&w[n])return x(e,t,r,!0);for(const e of o)if(x({k:e},"k",r))return!0;return!1}if(null!==r&&"object"==typeof r&&!i(r)&&!Array.isArray(r)){const e=Object.keys(r),t=e.map((e=>e[0])),n=t.filter((e=>"$"===e));if(0!==n.length&&n.length!==t.length)throw new Error("You cannot mix operators and normal fields");if(n.length>0){for(const t of e){if(!b[t])throw new Error(`Unknown comparison function ${t}`);if(!b[t](o,r[t]))return!1}return!0}}return i(r)?b.$regex(o,r):m(o,r)}e.exports.serialize=e=>JSON.stringify(e,(function(e,t){if(a(e,t),void 0!==t)return null===t?null:"function"==typeof this[e].getTime?{$$date:this[e].getTime()}:t})),e.exports.deserialize=e=>JSON.parse(e,(function(e,t){return"$$date"===e?new Date(t):"string"==typeof t||"number"==typeof t||"boolean"==typeof t||null===t?t:t&&t.$$date?t.$$date:t})),e.exports.deepCopy=c,e.exports.checkObject=s,e.exports.isPrimitiveType=u,e.exports.modify=(e,t)=>{const r=Object.keys(t),o=r.map((e=>e[0])),i=o.filter((e=>"$"===e));let a,u;if(-1!==r.indexOf("_id")&&t._id!==e._id)throw new Error("You cannot change a document's _id");if(0!==i.length&&i.length!==o.length)throw new Error("You cannot mix modifiers and normal fields");if(0===i.length?(a=c(t),a._id=e._id):(u=n(r),a=c(e),u.forEach((e=>{if(!d[e])throw new Error(`Unknown modifier ${e}`);if("object"!=typeof t[e])throw new Error(`Modifier ${e}'s argument must be an object`);Object.keys(t[e]).forEach((r=>{d[e](a,r,t[e][r])}))}))),s(a),e._id!==a._id)throw new Error("You can't change a document's _id");return a},e.exports.getDotValue=g,e.exports.getDotValues=(e,t)=>{if(!Array.isArray(t))throw new Error("fields must be an Array");if(t.length>1){const r={};for(const n of t)r[n]=g(e,n);return r}return g(e,t[0])},e.exports.match=O,e.exports.areThingsEqual=m,e.exports.compareThings=h},328:(e,t,r)=>{const{deprecate:n}=r(539),o=r(100),i=r(98),a=r(118),s=r(909),c=r(496);class u{constructor(e){if(this.db=e.db,this.inMemoryOnly=this.db.inMemoryOnly,this.filename=this.db.filename,this.corruptAlertThreshold=void 0!==e.corruptAlertThreshold?e.corruptAlertThreshold:.1,this.modes=void 0!==e.modes?e.modes:{fileMode:420,dirMode:493},void 0===this.modes.fileMode&&(this.modes.fileMode=420),void 0===this.modes.dirMode&&(this.modes.dirMode=493),!this.inMemoryOnly&&this.filename&&"~"===this.filename.charAt(this.filename.length-1))throw new Error("The datafile name can't end with a ~, which is reserved for crash safe backup files");if(e.afterSerialization&&!e.beforeDeserialization)throw new Error("Serialization hook defined but deserialization hook undefined, cautiously refusing to start NeDB to prevent dataloss");if(!e.afterSerialization&&e.beforeDeserialization)throw new Error("Serialization hook undefined but deserialization hook defined, cautiously refusing to start NeDB to prevent dataloss");this.afterSerialization=async t=>(e.afterSerialization||(e=>e))(t),this.beforeDeserialization=async t=>(e.beforeDeserialization||(e=>e))(t)}async persistCachedDatabaseAsync(){const e=[];if(!this.inMemoryOnly){for(const t of this.db.getAllData())e.push(await this.afterSerialization(a.serialize(t)));for(const t of Object.keys(this.db.indexes))"_id"!==t&&e.push(await this.afterSerialization(a.serialize({$$indexCreated:{fieldName:this.db.indexes[t].fieldName,unique:this.db.indexes[t].unique,sparse:this.db.indexes[t].sparse}})));await s.crashSafeWriteFileLinesAsync(this.filename,e,this.modes),this.db.emit("compaction.done")}}compactDatafile(e){n((e=>this.db.compactDatafile(e)),"@seald-io/nedb: calling Datastore#persistence#compactDatafile is deprecated, please use Datastore#compactDatafile, it will be removed in the next major version.")(e)}setAutocompactionInterval(e){n((e=>this.db.setAutocompactionInterval(e)),"@seald-io/nedb: calling Datastore#persistence#setAutocompactionInterval is deprecated, please use Datastore#setAutocompactionInterval, it will be removed in the next major version.")(e)}stopAutocompaction(){n((()=>this.db.stopAutocompaction()),"@seald-io/nedb: calling Datastore#persistence#stopAutocompaction is deprecated, please use Datastore#stopAutocompaction, it will be removed in the next major version.")()}async persistNewStateAsync(e){let t="";if(!this.inMemoryOnly){for(const r of e)t+=await this.afterSerialization(a.serialize(r))+"\n";0!==t.length&&await s.appendFileAsync(this.filename,t,{encoding:"utf8",mode:this.modes.fileMode})}}async treatRawData(e){const t=e.split("\n").filter((e=>""!==e)).map((async e=>a.deserialize(await this.beforeDeserialization(e)))),r={},n={},o=t.length;let i=0;for(const e of t)try{const t=await e;t._id?!0===t.$$deleted?delete r[t._id]:r[t._id]=t:t.$$indexCreated&&null!=t.$$indexCreated.fieldName?n[t.$$indexCreated.fieldName]=t.$$indexCreated:"string"==typeof t.$$indexRemoved&&delete n[t.$$indexRemoved]}catch(e){i+=1}if(o>0){const e=i/o;if(e>this.corruptAlertThreshold){const t=new Error(`${Math.floor(100*e)}% of the data file is corrupt, more than given corruptAlertThreshold (${Math.floor(100*this.corruptAlertThreshold)}%). Cautiously refusing to start NeDB to prevent dataloss.`);throw t.corruptionRate=e,t.corruptItems=i,t.dataLength=o,t}}return{data:Object.values(r),indexes:n}}treatRawStreamAsync(e){return new Promise(((t,r)=>{const n={},i={};let s=0;const u=o(e);let f=0;const l=new c;u.on("data",(e=>{const t=this.beforeDeserialization(e);return l.waterfall((async()=>{if(""!==e){try{const e=a.deserialize(await t);e._id?!0===e.$$deleted?delete n[e._id]:n[e._id]=e:e.$$indexCreated&&null!=e.$$indexCreated.fieldName?i[e.$$indexCreated.fieldName]=e.$$indexCreated:"string"==typeof e.$$indexRemoved&&delete i[e.$$indexRemoved]}catch(e){s+=1}f++}}))()})),u.on("end",(async()=>{if(await l.guardian,f>0){const e=s/f;if(e>this.corruptAlertThreshold){const t=new Error(`${Math.floor(100*e)}% of the data file is corrupt, more than given corruptAlertThreshold (${Math.floor(100*this.corruptAlertThreshold)}%). Cautiously refusing to start NeDB to prevent dataloss.`);return t.corruptionRate=e,t.corruptItems=s,t.dataLength=f,void r(t,null)}}const e=Object.values(n);t({data:e,indexes:i})})),u.on("error",(function(e){r(e,null)}))}))}async loadDatabaseAsync(){if(this.db._resetIndexes(),this.inMemoryOnly)return;let e;if(await u.ensureParentDirectoryExistsAsync(this.filename,this.modes.dirMode),await s.ensureDatafileIntegrityAsync(this.filename,this.modes.fileMode),s.readFileStream){const t=s.readFileStream(this.filename,{encoding:"utf8",mode:this.modes.fileMode});e=await this.treatRawStreamAsync(t)}else{const t=await s.readFileAsync(this.filename,{encoding:"utf8",mode:this.modes.fileMode});e=await this.treatRawData(t)}Object.keys(e.indexes).forEach((t=>{this.db.indexes[t]=new i(e.indexes[t])}));try{this.db._resetIndexes(e.data)}catch(e){throw this.db._resetIndexes(),e}await this.db.persistence.persistCachedDatabaseAsync(),this.db.executor.processBuffer()}async dropDatabaseAsync(){this.db.stopAutocompaction(),this.db.executor.ready=!1,this.db.executor.resetBuffer(),await this.db.executor.queue.guardian,this.db.indexes={},this.db.indexes._id=new i({fieldName:"_id",unique:!0}),this.db.ttlIndexes={},this.db.inMemoryOnly||await this.db.executor.pushAsync((async()=>{await s.existsAsync(this.filename)&&await s.unlinkAsync(this.filename)}),!0)}static async ensureParentDirectoryExistsAsync(e,t=493){return s.ensureParentDirectoryExistsAsync(e,t)}}e.exports=u},988:e=>{const t=e=>"object"==typeof e&&null!==e,r=e=>t(e)&&"[object Date]"===Object.prototype.toString.call(e);e.exports.uniq=(e,t)=>t?[...new Map(e.map((e=>[t(e),e]))).values()]:[...new Set(e)],e.exports.isDate=r,e.exports.isRegExp=e=>t(e)&&"[object RegExp]"===Object.prototype.toString.call(e),e.exports.pick=(e,t)=>t.reduce(((t,r)=>(e&&Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]),t)),{}),e.exports.filterIndexNames=e=>([t,n])=>!("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n&&!r(n)&&null!==n)&&e.includes(t)},496:e=>{e.exports=class{constructor(){this.guardian=Promise.resolve()}waterfall(e){return(...t)=>(this.guardian=this.guardian.then((()=>e(...t).then((e=>({error:!1,result:e})),(e=>({error:!0,result:e}))))),this.guardian.then((({error:e,result:t})=>e?Promise.reject(t):Promise.resolve(t))))}chain(e){return this.waterfall((()=>e))()}}},908:(e,t,r)=>{r(902),e.exports.AVLTree=r(522)},522:(e,t,r)=>{const n=r(902),o=r(639);class i{constructor(e){this.tree=new a(e)}checkIsAVLT(){this.tree.checkIsAVLT()}insert(e,t){const r=this.tree.insert(e,t);r&&(this.tree=r)}delete(e,t){const r=this.tree.delete(e,t);r&&(this.tree=r)}}class a extends n{constructor(e){super(),e=e||{},this.left=null,this.right=null,this.parent=void 0!==e.parent?e.parent:null,Object.prototype.hasOwnProperty.call(e,"key")&&(this.key=e.key),this.data=Object.prototype.hasOwnProperty.call(e,"value")?[e.value]:[],this.unique=e.unique||!1,this.compareKeys=e.compareKeys||o.defaultCompareKeysFunction,this.checkValueEquality=e.checkValueEquality||o.defaultCheckValueEquality}checkHeightCorrect(){if(!Object.prototype.hasOwnProperty.call(this,"key"))return;if(this.left&&void 0===this.left.height)throw new Error("Undefined height for node "+this.left.key);if(this.right&&void 0===this.right.height)throw new Error("Undefined height for node "+this.right.key);if(void 0===this.height)throw new Error("Undefined height for node "+this.key);const e=this.left?this.left.height:0,t=this.right?this.right.height:0;if(this.height!==1+Math.max(e,t))throw new Error("Height constraint failed for node "+this.key);this.left&&this.left.checkHeightCorrect(),this.right&&this.right.checkHeightCorrect()}balanceFactor(){return(this.left?this.left.height:0)-(this.right?this.right.height:0)}checkBalanceFactors(){if(Math.abs(this.balanceFactor())>1)throw new Error("Tree is unbalanced at node "+this.key);this.left&&this.left.checkBalanceFactors(),this.right&&this.right.checkBalanceFactors()}checkIsAVLT(){super.checkIsBST(),this.checkHeightCorrect(),this.checkBalanceFactors()}rightRotation(){const e=this,t=this.left;if(!t)return e;const r=t.right;e.parent?(t.parent=e.parent,e.parent.left===e?e.parent.left=t:e.parent.right=t):t.parent=null,t.right=e,e.parent=t,e.left=r,r&&(r.parent=e);const n=t.left?t.left.height:0,o=r?r.height:0,i=e.right?e.right.height:0;return e.height=Math.max(o,i)+1,t.height=Math.max(n,e.height)+1,t}leftRotation(){const e=this,t=this.right;if(!t)return this;const r=t.left;e.parent?(t.parent=e.parent,e.parent.left===e?e.parent.left=t:e.parent.right=t):t.parent=null,t.left=e,e.parent=t,e.right=r,r&&(r.parent=e);const n=e.left?e.left.height:0,o=r?r.height:0,i=t.right?t.right.height:0;return e.height=Math.max(n,o)+1,t.height=Math.max(i,e.height)+1,t}rightTooSmall(){return this.balanceFactor()<=1?this:(this.left.balanceFactor()<0&&this.left.leftRotation(),this.rightRotation())}leftTooSmall(){return this.balanceFactor()>=-1?this:(this.right.balanceFactor()>0&&this.right.rightRotation(),this.leftRotation())}rebalanceAlongPath(e){let t,r,n=this;if(!Object.prototype.hasOwnProperty.call(this,"key"))return delete this.height,this;for(r=e.length-1;r>=0;r-=1)e[r].height=1+Math.max(e[r].left?e[r].left.height:0,e[r].right?e[r].right.height:0),e[r].balanceFactor()>1&&(t=e[r].rightTooSmall(),0===r&&(n=t)),e[r].balanceFactor()<-1&&(t=e[r].leftTooSmall(),0===r&&(n=t));return n}insert(e,t){const r=[];let n=this;if(!Object.prototype.hasOwnProperty.call(this,"key"))return this.key=e,this.data.push(t),this.height=1,this;for(;;){if(0===n.compareKeys(n.key,e)){if(n.unique){const t=new Error(`Can't insert key ${JSON.stringify(e)}, it violates the unique constraint`);throw t.key=e,t.errorType="uniqueViolated",t}return n.data.push(t),this}if(r.push(n),n.compareKeys(e,n.key)<0){if(!n.left){r.push(n.createLeftChild({key:e,value:t}));break}n=n.left}else{if(!n.right){r.push(n.createRightChild({key:e,value:t}));break}n=n.right}}return this.rebalanceAlongPath(r)}delete(e,t){const r=[];let n,o=this;const i=[];if(!Object.prototype.hasOwnProperty.call(this,"key"))return this;for(;0!==o.compareKeys(e,o.key);)if(i.push(o),o.compareKeys(e,o.key)<0){if(!o.left)return this;o=o.left}else{if(!o.right)return this;o=o.right}if(o.data.length>1&&void 0!==t)return o.data.forEach((function(e){o.checkValueEquality(e,t)||r.push(e)})),o.data=r,this;if(!o.left&&!o.right)return o===this?(delete o.key,o.data=[],delete o.height,this):(o.parent.left===o?o.parent.left=null:o.parent.right=null,this.rebalanceAlongPath(i));if(!o.left||!o.right)return n=o.left?o.left:o.right,o===this?(n.parent=null,n):(o.parent.left===o?(o.parent.left=n,n.parent=o.parent):(o.parent.right=n,n.parent=o.parent),this.rebalanceAlongPath(i));if(i.push(o),n=o.left,!n.right)return o.key=n.key,o.data=n.data,o.left=n.left,n.left&&(n.left.parent=o),this.rebalanceAlongPath(i);for(;n.right;)i.push(n),n=n.right;return o.key=n.key,o.data=n.data,n.parent.right=n.left,n.left&&(n.left.parent=n.parent),this.rebalanceAlongPath(i)}}i._AVLTree=a,["getNumberOfKeys","search","betweenBounds","prettyPrint","executeOnEveryNode"].forEach((function(e){i.prototype[e]=function(){return this.tree[e].apply(this.tree,arguments)}})),e.exports=i},902:(e,t,r)=>{const n=r(639);function o(e,t){for(let r=0;r<t.length;r+=1)e.push(t[r])}e.exports=class{constructor(e){e=e||{},this.left=null,this.right=null,this.parent=void 0!==e.parent?e.parent:null,Object.prototype.hasOwnProperty.call(e,"key")&&(this.key=e.key),this.data=Object.prototype.hasOwnProperty.call(e,"value")?[e.value]:[],this.unique=e.unique||!1,this.compareKeys=e.compareKeys||n.defaultCompareKeysFunction,this.checkValueEquality=e.checkValueEquality||n.defaultCheckValueEquality}getMaxKeyDescendant(){return this.right?this.right.getMaxKeyDescendant():this}getMaxKey(){return this.getMaxKeyDescendant().key}getMinKeyDescendant(){return this.left?this.left.getMinKeyDescendant():this}getMinKey(){return this.getMinKeyDescendant().key}checkAllNodesFullfillCondition(e){Object.prototype.hasOwnProperty.call(this,"key")&&(e(this.key,this.data),this.left&&this.left.checkAllNodesFullfillCondition(e),this.right&&this.right.checkAllNodesFullfillCondition(e))}checkNodeOrdering(){Object.prototype.hasOwnProperty.call(this,"key")&&(this.left&&(this.left.checkAllNodesFullfillCondition((e=>{if(this.compareKeys(e,this.key)>=0)throw new Error(`Tree with root ${this.key} is not a binary search tree`)})),this.left.checkNodeOrdering()),this.right&&(this.right.checkAllNodesFullfillCondition((e=>{if(this.compareKeys(e,this.key)<=0)throw new Error(`Tree with root ${this.key} is not a binary search tree`)})),this.right.checkNodeOrdering()))}checkInternalPointers(){if(this.left){if(this.left.parent!==this)throw new Error(`Parent pointer broken for key ${this.key}`);this.left.checkInternalPointers()}if(this.right){if(this.right.parent!==this)throw new Error(`Parent pointer broken for key ${this.key}`);this.right.checkInternalPointers()}}checkIsBST(){if(this.checkNodeOrdering(),this.checkInternalPointers(),this.parent)throw new Error("The root shouldn't have a parent")}getNumberOfKeys(){let e;return Object.prototype.hasOwnProperty.call(this,"key")?(e=1,this.left&&(e+=this.left.getNumberOfKeys()),this.right&&(e+=this.right.getNumberOfKeys()),e):0}createSimilar(e){return(e=e||{}).unique=this.unique,e.compareKeys=this.compareKeys,e.checkValueEquality=this.checkValueEquality,new this.constructor(e)}createLeftChild(e){const t=this.createSimilar(e);return t.parent=this,this.left=t,t}createRightChild(e){const t=this.createSimilar(e);return t.parent=this,this.right=t,t}insert(e,t){if(!Object.prototype.hasOwnProperty.call(this,"key"))return this.key=e,void this.data.push(t);if(0!==this.compareKeys(this.key,e))this.compareKeys(e,this.key)<0?this.left?this.left.insert(e,t):this.createLeftChild({key:e,value:t}):this.right?this.right.insert(e,t):this.createRightChild({key:e,value:t});else{if(this.unique){const t=new Error(`Can't insert key ${JSON.stringify(e)}, it violates the unique constraint`);throw t.key=e,t.errorType="uniqueViolated",t}this.data.push(t)}}search(e){return Object.prototype.hasOwnProperty.call(this,"key")?0===this.compareKeys(this.key,e)?this.data:this.compareKeys(e,this.key)<0?this.left?this.left.search(e):[]:this.right?this.right.search(e):[]:[]}getLowerBoundMatcher(e){return Object.prototype.hasOwnProperty.call(e,"$gt")||Object.prototype.hasOwnProperty.call(e,"$gte")?Object.prototype.hasOwnProperty.call(e,"$gt")&&Object.prototype.hasOwnProperty.call(e,"$gte")?0===this.compareKeys(e.$gte,e.$gt)?t=>this.compareKeys(t,e.$gt)>0:this.compareKeys(e.$gte,e.$gt)>0?t=>this.compareKeys(t,e.$gte)>=0:t=>this.compareKeys(t,e.$gt)>0:Object.prototype.hasOwnProperty.call(e,"$gt")?t=>this.compareKeys(t,e.$gt)>0:t=>this.compareKeys(t,e.$gte)>=0:()=>!0}getUpperBoundMatcher(e){return Object.prototype.hasOwnProperty.call(e,"$lt")||Object.prototype.hasOwnProperty.call(e,"$lte")?Object.prototype.hasOwnProperty.call(e,"$lt")&&Object.prototype.hasOwnProperty.call(e,"$lte")?0===this.compareKeys(e.$lte,e.$lt)?t=>this.compareKeys(t,e.$lt)<0:this.compareKeys(e.$lte,e.$lt)<0?t=>this.compareKeys(t,e.$lte)<=0:t=>this.compareKeys(t,e.$lt)<0:Object.prototype.hasOwnProperty.call(e,"$lt")?t=>this.compareKeys(t,e.$lt)<0:t=>this.compareKeys(t,e.$lte)<=0:()=>!0}betweenBounds(e,t,r){const n=[];return Object.prototype.hasOwnProperty.call(this,"key")?(t=t||this.getLowerBoundMatcher(e),r=r||this.getUpperBoundMatcher(e),t(this.key)&&this.left&&o(n,this.left.betweenBounds(e,t,r)),t(this.key)&&r(this.key)&&o(n,this.data),r(this.key)&&this.right&&o(n,this.right.betweenBounds(e,t,r)),n):[]}deleteIfLeaf(){return!(this.left||this.right||(this.parent?(this.parent.left===this?this.parent.left=null:this.parent.right=null,0):(delete this.key,this.data=[],0)))}deleteIfOnlyOneChild(){let e;return this.left&&!this.right&&(e=this.left),!this.left&&this.right&&(e=this.right),!!e&&(this.parent?(this.parent.left===this?(this.parent.left=e,e.parent=this.parent):(this.parent.right=e,e.parent=this.parent),!0):(this.key=e.key,this.data=e.data,this.left=null,e.left&&(this.left=e.left,e.left.parent=this),this.right=null,e.right&&(this.right=e.right,e.right.parent=this),!0))}delete(e,t){const r=[];let n;if(Object.prototype.hasOwnProperty.call(this,"key"))if(this.compareKeys(e,this.key)<0)this.left&&this.left.delete(e,t);else if(this.compareKeys(e,this.key)>0)this.right&&this.right.delete(e,t);else if(0!==!this.compareKeys(e,this.key))return this.data.length>1&&void 0!==t?(this.data.forEach((e=>{this.checkValueEquality(e,t)||r.push(e)})),void(this.data=r)):void(this.deleteIfLeaf()||this.deleteIfOnlyOneChild()||(Math.random()>=.5?(n=this.left.getMaxKeyDescendant(),this.key=n.key,this.data=n.data,this===n.parent?(this.left=n.left,n.left&&(n.left.parent=n.parent)):(n.parent.right=n.left,n.left&&(n.left.parent=n.parent))):(n=this.right.getMinKeyDescendant(),this.key=n.key,this.data=n.data,this===n.parent?(this.right=n.right,n.right&&(n.right.parent=n.parent)):(n.parent.left=n.right,n.right&&(n.right.parent=n.parent)))))}executeOnEveryNode(e){this.left&&this.left.executeOnEveryNode(e),e(this),this.right&&this.right.executeOnEveryNode(e)}prettyPrint(e,t){t=t||"",console.log(`${t}* ${this.key}`),e&&console.log(`${t}* ${this.data}`),(this.left||this.right)&&(this.left?this.left.prettyPrint(e,`${t} `):console.log(`${t} *`),this.right?this.right.prettyPrint(e,`${t} `):console.log(`${t} *`))}}},639:e=>{const t=e=>{if(0===e)return[];if(1===e)return[0];const r=t(e-1),n=Math.floor(Math.random()*e);return r.splice(n,0,e-1),r};e.exports.getRandomArray=t,e.exports.defaultCompareKeysFunction=(e,t)=>{if(e<t)return-1;if(e>t)return 1;if(e===t)return 0;const r=new Error("Couldn't compare elements");throw r.a=e,r.b=t,r},e.exports.defaultCheckValueEquality=(e,t)=>e===t},924:(e,t,r)=>{"use strict";var n=r(210),o=r(559),i=o(n("String.prototype.indexOf"));e.exports=function(e,t){var r=n(e,!!t);return"function"==typeof r&&i(e,".prototype.")>-1?o(r):r}},559:(e,t,r)=>{"use strict";var n=r(612),o=r(210),i=o("%Function.prototype.apply%"),a=o("%Function.prototype.call%"),s=o("%Reflect.apply%",!0)||n.call(a,i),c=o("%Object.getOwnPropertyDescriptor%",!0),u=o("%Object.defineProperty%",!0),f=o("%Math.max%");if(u)try{u({},"a",{value:1})}catch(e){u=null}e.exports=function(e){var t=s(n,a,arguments);return c&&u&&c(t,"length").configurable&&u(t,"length",{value:1+f(0,e.length-(arguments.length-1))}),t};var l=function(){return s(n,i,arguments)};u?u(e.exports,"apply",{value:l}):e.exports.apply=l},187:e=>{"use strict";var t,r="object"==typeof Reflect?Reflect:null,n=r&&"function"==typeof r.apply?r.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};t=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise((function(r,n){function o(r){e.removeListener(t,i),n(r)}function i(){"function"==typeof e.removeListener&&e.removeListener("error",o),r([].slice.call(arguments))}d(e,t,i,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&d(e,"error",t,{once:!0})}(e,o)}))},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var a=10;function s(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function u(e,t,r,n){var o,i,a,u;if(s(r),void 0===(i=e._events)?(i=e._events=Object.create(null),e._eventsCount=0):(void 0!==i.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),i=e._events),a=i[t]),void 0===a)a=i[t]=r,++e._eventsCount;else if("function"==typeof a?a=i[t]=n?[r,a]:[a,r]:n?a.unshift(r):a.push(r),(o=c(e))>0&&a.length>o&&!a.warned){a.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=e,f.type=t,f.count=a.length,u=f,console&&console.warn&&console.warn(u)}return e}function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function l(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=f.bind(n);return o.listener=r,n.wrapFn=o,o}function h(e,t,r){var n=e._events;if(void 0===n)return[];var o=n[t];return void 0===o?[]:"function"==typeof o?r?[o.listener||o]:[o]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(o):y(o,o.length)}function p(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function y(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function d(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function o(i){n.once&&e.removeEventListener(t,o),r(i)}))}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||o(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return c(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var o="error"===e,i=this._events;if(void 0!==i)o=o&&void 0===i.error;else if(!o)return!1;if(o){var a;if(t.length>0&&(a=t[0]),a instanceof Error)throw a;var s=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw s.context=a,s}var c=i[e];if(void 0===c)return!1;if("function"==typeof c)n(c,this,t);else{var u=c.length,f=y(c,u);for(r=0;r<u;++r)n(f[r],this,t)}return!0},i.prototype.addListener=function(e,t){return u(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return u(this,e,t,!0)},i.prototype.once=function(e,t){return s(t),this.on(e,l(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return s(t),this.prependListener(e,l(this,e,t)),this},i.prototype.removeListener=function(e,t){var r,n,o,i,a;if(s(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,i=r.length-1;i>=0;i--)if(r[i]===t||r[i].listener===t){a=r[i].listener,o=i;break}if(o<0)return this;0===o?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,o),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,a||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var o,i=Object.keys(r);for(n=0;n<i.length;++n)"removeListener"!==(o=i[n])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},i.prototype.listeners=function(e){return h(this,e,!0)},i.prototype.rawListeners=function(e){return h(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},i.prototype.listenerCount=p,i.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},29:(e,t,r)=>{"use strict";var n=r(320),o=Object.prototype.toString,i=Object.prototype.hasOwnProperty,a=function(e,t,r){for(var n=0,o=e.length;n<o;n++)i.call(e,n)&&(null==r?t(e[n],n,e):t.call(r,e[n],n,e))},s=function(e,t,r){for(var n=0,o=e.length;n<o;n++)null==r?t(e.charAt(n),n,e):t.call(r,e.charAt(n),n,e)},c=function(e,t,r){for(var n in e)i.call(e,n)&&(null==r?t(e[n],n,e):t.call(r,e[n],n,e))};e.exports=function(e,t,r){if(!n(t))throw new TypeError("iterator must be a function");var i;arguments.length>=3&&(i=r),"[object Array]"===o.call(e)?a(e,t,i):"string"==typeof e?s(e,t,i):c(e,t,i)}},648:e=>{"use strict";var t="Function.prototype.bind called on incompatible ",r=Array.prototype.slice,n=Object.prototype.toString,o="[object Function]";e.exports=function(e){var i=this;if("function"!=typeof i||n.call(i)!==o)throw new TypeError(t+i);for(var a,s=r.call(arguments,1),c=Math.max(0,i.length-s.length),u=[],f=0;f<c;f++)u.push("$"+f);if(a=Function("binder","return function ("+u.join(",")+"){ return binder.apply(this,arguments); }")((function(){if(this instanceof a){var t=i.apply(this,s.concat(r.call(arguments)));return Object(t)===t?t:this}return i.apply(e,s.concat(r.call(arguments)))})),i.prototype){var l=function(){};l.prototype=i.prototype,a.prototype=new l,l.prototype=null}return a}},612:(e,t,r)=>{"use strict";var n=r(648);e.exports=Function.prototype.bind||n},210:(e,t,r)=>{"use strict";var n,o=SyntaxError,i=Function,a=TypeError,s=function(e){try{return i('"use strict"; return ('+e+").constructor;")()}catch(e){}},c=Object.getOwnPropertyDescriptor;if(c)try{c({},"")}catch(e){c=null}var u=function(){throw new a},f=c?function(){try{return u}catch(e){try{return c(ar