UNPKG

@dakingindanorf/hive

Version:

A template for creating a nuxt generated static site using Netlify CMS to power the backend. Individual site components can be managed through Bit

1 lines 102 kB
(window.webpackJsonp=window.webpackJsonp||[]).push([[31],{537:function(e,t,n){var r=n(538),o=n(203),l=n(539),h=n(540),c=n(541);function d(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,h=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){h=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(h)throw o}}}}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}n(40),n(18),n(19),n(50),n(73),n(48),n(204),n(542),n(543),n(42),n(12),n(31),n(41),n(23),n(11),n(43),n(44),n(28);var _=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return Object.keys(e).filter((function(e){return t.includes(e)})).reduce((function(t,n){return Object.assign(t,c({},n,e[n]))}),{})},w=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return Object.keys(e).filter((function(e){return!t.includes(e)})).reduce((function(t,n){return Object.assign(t,c({},n,e[n]))}),{})},m=function(){"use strict";function e(t,n){var r=t.query,path=t.path,o=t.init,text=t.text,h=t.postprocess,c=void 0===h?[]:h;l(this,e),this.query=r,this.path=path,this.init=o,this.postprocess=c,this.options=n||{},this.onlyKeys=null,this.withoutKeys=null,this.sortKeys=[],this.limitN=null,this.skipN=null,text||this.postprocess.unshift((function(data){return data.map((function(e){return w(e,["text"])}))}))}var t;return h(e,[{key:"only",value:function(e){return this.onlyKeys=Array.isArray(e)?e:[e],this}},{key:"without",value:function(e){return this.withoutKeys=Array.isArray(e)?e:[e],this}},{key:"sortBy",value:function(e,t){return this.sortKeys.push([e,"desc"===t]),this}},{key:"where",value:function(e){return this.query=this.query.find(e),this}},{key:"search",value:function(e,t){var n;return n="object"===o(e)?e:t?{query:{type:"match",field:e,value:t,prefix_length:1,fuzziness:1,extended:!0,minimum_should_match:1}}:{query:{type:"bool",should:this.options.fullTextSearchFields.map((function(t){return{type:"match",field:t,value:e,prefix_length:1,operator:"and",minimum_should_match:1,fuzziness:1,extended:!0}}))}},this.query=this.query.find({$fts:n}),this}},{key:"surround",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.before,r=void 0===n?1:n,o=t.after,l=void 0===o?1:o;this.onlyKeys&&this.onlyKeys.push("slug"),this.withoutKeys&&(this.withoutKeys=this.withoutKeys.filter((function(e){return"slug"!==e})));var h=function(data){var t=data.findIndex((function(t){return t.slug===e})),n=new Array(r+l).fill(null,0);if(-1===t)return n;for(var o=data.slice(t-r,t),h=data.slice(t+1,t+1+l),c=0,i=r-1;i>=0;i--)n[i]=o[c]||null,c++;for(var d=0,f=r;f<=l;f++)n[f]=h[d]||null,d++;return n};return this.postprocess.push(h),this}},{key:"limit",value:function(e){return"string"==typeof e&&(e=parseInt(e)),this.limitN=e,this}},{key:"skip",value:function(e){return"string"==typeof e&&(e=parseInt(e)),this.skipN=e,this}},{key:"fetch",value:(t=r(regeneratorRuntime.mark((function e(){var data,t,n,r,o,l,h=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.sortKeys&&this.sortKeys.length&&(this.query=this.query.compoundsort(this.sortKeys)),this.skipN&&(this.query=this.query.offset(this.skipN)),this.limitN&&(this.query=this.query.limit(this.limitN)),data=this.query.data({removeMeta:!0}),this.onlyKeys&&(this.options.watch&&this.onlyKeys.push("path","extension"),t=function(data){return data.map((function(e){return _(e,h.onlyKeys)}))},this.postprocess.unshift(t)),this.withoutKeys&&(this.options.watch&&(this.withoutKeys=this.withoutKeys.filter((function(e){return!["path","extension"].includes(e)}))),n=function(data){return data.map((function(e){return w(e,h.withoutKeys)}))},this.postprocess.unshift(n)),r=d(this.postprocess);try{for(r.s();!(o=r.n()).done;)l=o.value,data=l(data)}catch(e){r.e(e)}finally{r.f()}if(data){e.next=10;break}throw new Error("".concat(this.path," not found"));case 10:return e.abrupt("return",JSON.parse(JSON.stringify(data)));case 11:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();e.exports=m},538:function(e,t){function n(e,t,n,r,o,l,h){try{var c=e[l](h),d=c.value}catch(e){return void n(e)}c.done?t(d):Promise.resolve(d).then(r,o)}e.exports=function(e){return function(){var t=this,r=arguments;return new Promise((function(o,l){var h=e.apply(t,r);function c(e){n(h,o,l,c,d,"next",e)}function d(e){n(h,o,l,c,d,"throw",e)}c(void 0)}))}},e.exports.default=e.exports,e.exports.__esModule=!0},539:function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.default=e.exports,e.exports.__esModule=!0},540:function(e,t){function n(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e},e.exports.default=e.exports,e.exports.__esModule=!0},541:function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},e.exports.default=e.exports,e.exports.__esModule=!0},542:function(e,t,n){"use strict";var r=n(3),o=n(62).findIndex,l=n(97),h="findIndex",c=!0;h in[]&&Array(1).findIndex((function(){c=!1})),r({target:"Array",proto:!0,forced:c},{findIndex:function(e){return o(this,e,arguments.length>1?arguments[1]:void 0)}}),l(h)},543:function(e,t,n){var r=n(3),o=n(544),l=n(97);r({target:"Array",proto:!0},{fill:o}),l("fill")},544:function(e,t,n){"use strict";var r=n(32),o=n(98),l=n(24);e.exports=function(e){for(var t=r(this),n=l(t.length),h=arguments.length,c=o(h>1?arguments[1]:void 0,n),d=h>2?arguments[2]:void 0,f=void 0===d?n:o(d,n);f>c;)t[c++]=e;return t}},545:function(e,t,n){var r;"undefined"!=typeof self&&self,r=function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(object,e){return Object.prototype.hasOwnProperty.call(object,e)},n.p="",n(n.s=8)}([function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var r=n(2);let o={js:(e,t)=>e===t?0:e<t?-1:1,"abstract-js":(e,t)=>e==t?0:e<t?-1:1,"abstract-date":(e,t)=>{let n=new Date(e).toISOString(),r=new Date(t).toISOString();return n==r?0:n<r?-1:1},loki:(e,t)=>Object(r.b)(e,t)?0:Object(r.c)(e,t,!1)?-1:1}},function(e,t,n){"use strict";(function(e){function r(){let t;return function(e){t=e}(void 0!==e&&e||this),t}n.d(t,"a",(function(){return o}));const o=function(){const e=r(),t=Symbol.for("LOKI");return void 0===e[t]&&(e[t]={}),e[t]}()}).call(this,n(7))},function(e,t,n){"use strict";function r(e,t){if(e===t)return!0;if(!e||!t||!0===e||!0===t||e!=e||t!=t){let n,r;switch(e){case void 0:case null:n=1;break;case!1:n=3;break;case!0:n=4;break;case"":n=5;break;default:n=e==e?9:0}switch(t){case void 0:case null:r=1;break;case!1:r=3;break;case!0:r=4;break;case"":r=5;break;default:r=t==t?9:0}if(9!==n||9!==r)return n===r}let n=Number(e),r=Number(t);return n==n||r==r?n===r:(n=e.toString(),r=t.toString(),n==r)}function o(e,t,n){if(!e||!t||!0===e||!0===t||e!=e||t!=t){let r,o;switch(e){case void 0:case null:r=1;break;case!1:r=3;break;case!0:r=4;break;case"":r=5;break;default:r=e==e?9:0}switch(t){case void 0:case null:o=1;break;case!1:o=3;break;case!0:o=4;break;case"":o=5;break;default:o=t==t?9:0}if(9!==r||9!==o)return r===o?n:r<o}let r=Number(e),o=Number(t);return r==r&&o==o?r<o||!(r>o)&&n:r==r&&o!=o||(o!=o||r==r)&&(e<t||!(e>t)&&(e==t?n:(r=e.toString(),o=t.toString(),r<o||r==o&&n)))}function l(e,t,n){if(!e||!t||!0===e||!0===t||e!=e||t!=t){let r,o;switch(e){case void 0:case null:r=1;break;case!1:r=3;break;case!0:r=4;break;case"":r=5;break;default:r=e==e?9:0}switch(t){case void 0:case null:o=1;break;case!1:o=3;break;case!0:o=4;break;case"":o=5;break;default:o=t==t?9:0}if(9!==r||9!==o)return r===o?n:r>o}let r=Number(e),o=Number(t);return r==r&&o==o?r>o||!(r<o)&&n:(r!=r||o==o)&&(o==o&&r!=r||e>t||!(e<t)&&(e==t?n:(r=e.toString(),o=t.toString(),r>o||r==o&&n)))}function h(e,t,n){return r(e,t)?0:o(e,t,!1)?n?1:-1:l(e,t,!1)?n?-1:1:0}n.d(t,"b",(function(){return r})),n.d(t,"c",(function(){return o})),n.d(t,"d",(function(){return h})),n.d(t,"a",(function(){return d}));class c{$eq(a,b){return a===b}$ne(a,b){return a!==b}$gt(a,b){return a>b}$gte(a,b){return a>=b}$lt(a,b){return a<b}$lte(a,b){return a<=b}$between(a,e){return null!=a&&a>=e[0]&&a<=e[1]}$in(a,b){return-1!==b.indexOf(a)}$nin(a,b){return-1===b.indexOf(a)}$keyin(a,b){return a in b}$nkeyin(a,b){return!(a in b)}$definedin(a,b){return void 0!==b[a]}$undefinedin(a,b){return void 0===b[a]}$regex(a,b){return b.test(a)}$containsNone(a,b){return!this.$containsAny(a,b)}$containsAny(a,b){const e=this.containsCheckFn(a);return null!==e&&(Array.isArray(b)?b.some(e):e(b))}$contains(a,b){const e=this.containsCheckFn(a);return null!==e&&(Array.isArray(b)?b.every(e):e(b))}$type(a,b){let e=typeof a;return"object"===e&&(Array.isArray(a)?e="array":a instanceof Date&&(e="date")),"object"!=typeof b?e===b:this.doQueryOp(e,b)}$finite(a,b){return b===isFinite(a)}$size(a,b){return!!Array.isArray(a)&&("object"!=typeof b?a.length===b:this.doQueryOp(a.length,b))}$len(a,b){return"string"==typeof a&&("object"!=typeof b?a.length===b:this.doQueryOp(a.length,b))}$where(a,b){return!0===b(a)}$not(a,b){return!this.doQueryOp(a,b)}$and(a,b){for(let e=0,t=b.length;e<t;e++)if(!this.doQueryOp(a,b[e]))return!1;return!0}$or(a,b){for(let e=0,t=b.length;e<t;e++)if(this.doQueryOp(a,b[e]))return!0;return!1}doQueryOp(e,t){for(let p in t)if(Object.hasOwnProperty.call(t,p))return this[p](e,t[p]);return!1}containsCheckFn(a){return"string"==typeof a||Array.isArray(a)?b=>-1!==a.indexOf(b):"object"==typeof a&&null!==a?b=>Object.hasOwnProperty.call(a,b):null}}let d={js:new c,loki:new class extends c{constructor(){super()}$eq(a,b){return r(a,b)}$ne(a,b){return!r(a,b)}$gt(a,b){return l(a,b,!1)}$gte(a,b){return l(a,b,!0)}$lt(a,b){return o(a,b,!1)}$lte(a,b){return o(a,b,!0)}$between(a,e){return null!=a&&l(a,e[0],!0)&&o(a,e[1],!0)}}}},function(e,t,n){"use strict";var r=n(5);class o{constructor(e){this._field=e,this._lokiMap={},this._valMap={}}set(e,t){if(null!=t){if(t in this._lokiMap)throw new Error("Duplicate key for property "+this._field+": "+t);if(e in this._valMap)throw new Error("Duplicate key for property $loki : "+e);this._lokiMap[t]=e,this._valMap[e]=t}}get(e){return this._lokiMap[e]}update(e,t){if(t!==this._valMap[e]){if(t in this._lokiMap)throw new Error("Duplicate key for property "+this._field+": "+t);this.remove(e),this.set(e,t)}}remove(e){if(!(e in this._valMap))throw new Error("Key is not in unique index: "+this._field);let t=this._valMap[e];delete this._lokiMap[t],delete this._valMap[e]}clear(){this._lokiMap={},this._valMap={}}}function l(e,t,n){return e instanceof Array?(e.push(n),e[e.length-1]):e instanceof Object?(e[t]=n,e[t]):void 0}function h(e,t){for(let n in e){let r=e[n];r instanceof Date?l(t,n,new Date(r.getTime())):r instanceof Function?l(t,n,r):r instanceof Array?h(r,l(t,n,[])):r instanceof Object?h(r,l(t,n,{})):l(t,n,r)}}function c(e){if(/number|string|boolean/.test(typeof e))return e;if(e instanceof Date)return new Date(e.getTime());const t=e instanceof Array?[]:{};return h(e,t),t}function d(data,e="parse-stringify"){if(null==data)return null;let t;switch(e){case"parse-stringify":t=JSON.parse(JSON.stringify(data));break;case"deep":t=c(data);break;case"shallow":t=Object.create(data.constructor.prototype),Object.assign(t,data);break;case"shallow-recurse":t=d(data,"shallow");const e=Object.keys(data);for(let i=0;i<e.length;i++){const n=e[i];"object"==typeof data[n]&&"Object"===data[n].constructor.name&&(t[n]=d(data[n],"shallow-recurse"))}}return t}var f=n(2),_=n(0);function w(e,t,n=0){if(++n>=10)return e;for(const r in e)if("string"==typeof e[r]&&0===e[r].indexOf("[%lktxp]")){const n=e[r].substring(8);void 0!==t[n]&&(e[r]=t[n])}else"object"==typeof e[r]&&(e[r]=w(e[r],t,n));return e}const m={$eq:!0,$dteq:!0,$gt:!0,$gte:!0,$lt:!0,$lte:!0,$in:!0,$between:!0};class v{constructor(e){this._filteredRows=[],this._filterInitialized=!1,this._scoring=null,this._collection=e}reset(){return this._filteredRows.length>0&&(this._filteredRows=[]),this._filterInitialized=!1,this}toJSON(){const e=this.copy();return e._collection=null,e}limit(e){return this._filterInitialized||0!==this._filteredRows.length||(this._filteredRows=this._collection._prepareFullDocIndex()),this._filteredRows=this._filteredRows.slice(0,e),this._filterInitialized=!0,this}offset(e){return this._filterInitialized||0!==this._filteredRows.length||(this._filteredRows=this._collection._prepareFullDocIndex()),this._filteredRows=this._filteredRows.slice(e),this._filterInitialized=!0,this}copy(){const e=new v(this._collection);return e._filteredRows=this._filteredRows.slice(),e._filterInitialized=this._filterInitialized,e}transform(e,t){"string"==typeof e&&(e=this._collection._transforms[e]),void 0!==t&&(e=function(e,t){if(void 0===t)return e;const n=[];for(let r=0;r<e.length;r++){const o=d(e[r],"shallow-recurse");n.push(w(o,t))}return n}(e,t));let n=this;for(let t=0;t<e.length;t++){const r=e[t];switch(r.type){case"find":n.find(r.value);break;case"where":n.where(r.value);break;case"simplesort":n.simplesort(r.property,r.options);break;case"compoundsort":n.compoundsort(r.value);break;case"sort":n.sort(r.value);break;case"sortByScoring":n.sortByScoring(r.desc);break;case"limit":n=n.limit(r.value);break;case"offset":n=n.offset(r.value);break;case"map":n=n.map(r.value,r.dataOptions);break;case"eqJoin":n=n.eqJoin(r.joinData,r.leftJoinKey,r.rightJoinKey,r.mapFun,r.dataOptions);break;case"mapReduce":n=n.mapReduce(r.mapFunction,r.reduceFunction);break;case"update":n.update(r.value);break;case"remove":n.remove()}}return n}sort(e){this._filterInitialized||0!==this._filteredRows.length||(this._filteredRows=this._collection._prepareFullDocIndex());const data=this._collection._data;return this._filteredRows.sort(((a,b)=>e(data[a],data[b]))),this}simplesort(e,t={desc:!1}){if("boolean"==typeof t&&(t={desc:t}),!this._filterInitialized&&this._collection._rangedIndexes.hasOwnProperty(e)){let n=this._collection._rangedIndexes[e].index.rangeRequest(),r=[];for(let e of n)r.push(this._collection.get(e,!0)[1]);return this._filteredRows=t.desc?r.reverse():r,this._filterInitialized=!0,this}this._filterInitialized||0!==this._filteredRows.length||(this._filteredRows=this._collection._prepareFullDocIndex());const data=this._collection._data;let n=t.sortComparator?_.a[t.sortComparator]:_.a[this._collection._unindexedSortComparator];return this._filteredRows.sort(((a,b)=>n(data[a][e],data[b][e]))),t.desc&&this._filteredRows.reverse(),this}compoundsort(e){if(0===e.length)throw new Error("Invalid call to compoundsort, need at least one property");if(1===e.length){const t=e[0];return"string"==typeof t?this.simplesort(t,!1):this.simplesort(t[0],t[1])}for(let i=0,t=e.length;i<t;i++){const t=e[i];"string"==typeof t&&(e[i]=[t,!1])}this._filterInitialized||0!==this._filteredRows.length||(this._filteredRows=this._collection._prepareFullDocIndex());const data=this._collection._data;return this._filteredRows.sort(((a,b)=>this._compoundeval(e,data[a],data[b]))),this}_compoundeval(e,t,n){for(let i=0,r=e.length;i<r;i++){const r=e[i],o=r[0],l=Object(f.d)(t[o],n[o],r[1]);if(0!==l)return l}return 0}sortByScoring(e=!1){if(null===this._scoring)throw new Error("No scoring available");return e?this._filteredRows.sort(((a,b)=>this._scoring[a].score-this._scoring[b].score)):this._filteredRows.sort(((a,b)=>this._scoring[b].score-this._scoring[a].score)),this}getScoring(){if(null===this._scoring)throw new Error("No scoring available");const e=[];for(let i=0;i<this._filteredRows.length;i++)e.push(this._scoring[this._filteredRows[i]]);return e}findOr(e){const t=[],n=[],r=this.count();for(let o=0,l=e.length;o<l;o++){const l=this.copy().find(e[o])._filteredRows,h=l.length;if(h===r)return this;for(let e=0;e<h;e++){const r=l[e];void 0===n[r]&&(n[r]=!0,t.push(r))}}return this._filteredRows=t,this._filterInitialized=!0,this}$or(e){return this.findOr(e)}findAnd(e){for(let i=0,t=e.length;i<t;i++){if(0===this.count())return this;this.find(e[i])}return this}$and(e){return this.findAnd(e)}find(e,t=!1){if(0===this._collection._data.length)return this._filteredRows=[],this._filterInitialized=!0,this;const n=e||"getAll";let r,o,l;if("object"==typeof n){let e=[];for(let p in n){let t={};t[p]=n[p],e.push(t),void 0!==n[p]&&(r=p,o=n[p])}if(e.length>1)return this.find({$and:e},t)}if(!r||"getAll"===n)return t&&(this._filteredRows=this._collection._data.length>0?[0]:[],this._filterInitialized=!0),this;if("$and"===r||"$or"===r)return this[r](o),t&&this._filteredRows.length>1&&(this._filteredRows=this._filteredRows.slice(0,1)),this;let h="";if(null===o||"object"!=typeof o||o instanceof Date)h="$eq",l=o;else{if("object"!=typeof o)throw new Error("Do not know what you want to do.");for(let e in o)if(void 0!==o[e]){h=e,l=o[e];break}}"$regex"===h&&(Array.isArray(l)?l=new RegExp(l[0],l[1]):l instanceof RegExp||(l=new RegExp(l)));let c=!1;!this._filterInitialized&&this._collection._rangedIndexes[r]&&m[h]&&(c=!0);const d=f.a[this._collection._defaultLokiOperatorPackage],data=this._collection._data;let _=[];if(this._filterInitialized){let filter=this._filteredRows;if("$fts"===r){this._scoring=this._collection._fullTextSearch.search(n.$fts);let e=Object.keys(this._scoring);for(let i=0;i<e.length;i++)-1!==filter.indexOf(+e[i])&&_.push(+e[i])}else if(void 0!==this._collection._constraints.unique[r]&&"$eq"===h){const e=this._collection._constraints.unique[r].get(l);if(void 0!==e){const t=this._collection.get(e,!0)[1];-1!==filter.indexOf(t)&&_.push(t)}}else for(let i=0;i<filter.length;i++){let e=filter[i];d[h](data[e][r],l)&&_.push(e)}return this._filteredRows=_,this._filterInitialized=!0,this}if(this._filteredRows=_,this._filterInitialized=!0,"$fts"===r){this._scoring=this._collection._fullTextSearch.search(n.$fts);let e=Object.keys(this._scoring);for(let i=0;i<e.length;i++)_.push(+e[i]);return this}if(void 0!==this._collection._constraints.unique[r]&&"$eq"===h){const e=this._collection._constraints.unique[r].get(l);return void 0!==e&&_.push(this._collection.get(e,!0)[1]),this}if(!c){for(let i=0;i<data.length;i++)if(d[h](data[i][r],l)&&(_.push(i),t))return this;return this}if(this._collection._rangedIndexes[r]){if("$in"===h){let e=this._collection._rangedIndexes[r];for(let t of l){let n=e.index.rangeRequest({op:"$eq",val:t});for(let e of n)_.push(this._collection.get(e,!0)[1])}return this}if("$between"===h){let e=this._collection._rangedIndexes[r].index.rangeRequest({op:h,val:l[0],high:l[1]});for(let t of e)_.push(this._collection.get(t,!0)[1]);return this}let e=this._collection._rangedIndexes[r].index.rangeRequest({op:h,val:l});if(!0!==m[h])for(let t of e){let e=this._collection.get(t,!0)[1];m[h](data[e][r],l)&&_.push(e)}else for(let t of e)_.push(this._collection.get(t,!0)[1])}return this}where(e){let t,n=[];if("function"!=typeof e)throw new TypeError("Argument is not a stored view or a function");if(t=e,this._filterInitialized){let e=this._filteredRows.length;for(;e--;)!0===t(this._collection._data[this._filteredRows[e]])&&n.push(this._filteredRows[e]);return this._filteredRows=n,this}{let e=this._collection._data.length;for(;e--;)!0===t(this._collection._data[e])&&n.push(e);return this._filteredRows=n,this._filterInitialized=!0,this}}count(){return this._filterInitialized?this._filteredRows.length:this._collection.count()}data(e={}){let t,n,r;({forceClones:t=!1,forceCloneMethod:n=this._collection._cloneMethod,removeMeta:r=!1}=e);let o,l,h=[],data=this._collection._data;if(r&&!t&&(t=!0,n="shallow"),this._collection._disableDeltaChangesApi||(t=!0,n="deep"),!this._filterInitialized){if(0===this._filteredRows.length){if(this._collection._cloneObjects||t){l=n;for(let i=0;i<data.length;i++)o=this._collection._defineNestedProperties(d(data[i],l)),r&&(delete o.$loki,delete o.meta),h.push(o);return h}return data.slice()}this._filterInitialized=!0}const c=this._filteredRows;if(this._collection._cloneObjects||t){l=n;for(let i=0;i<c.length;i++)o=this._collection._defineNestedProperties(d(data[c[i]],l)),r&&(delete o.$loki,delete o.meta),h.push(o)}else for(let i=0;i<c.length;i++)h.push(data[c[i]]);return h}update(e){this._filterInitialized||0!==this._filteredRows.length||(this._filteredRows=this._collection._prepareFullDocIndex());const t=this._filteredRows.length,n=this._collection._data;for(let r=0;r<t;r++)if(this._collection._cloneObjects||!this._collection._disableDeltaChangesApi){const t=d(n[this._filteredRows[r]],this._collection._cloneMethod);e(t),this._collection.update(t)}else e(n[this._filteredRows[r]]),this._collection.update(n[this._filteredRows[r]]);return this}remove(){return this._filterInitialized||0!==this._filteredRows.length||(this._filteredRows=this._collection._prepareFullDocIndex()),this._collection.remove(this.data()),this._filteredRows=[],this}mapReduce(e,t){try{return t(this.data().map(e))}catch(e){throw e}}eqJoin(e,t,n,r,o){let l,h,c=[],d=[],f="function"==typeof t,_="function"==typeof n,w={},m=this.data(o),y=m.length;if(e instanceof C)c=e.chain().data(o);else if(e instanceof v)c=e.data(o);else{if(!Array.isArray(e))throw new TypeError("joinData needs to be an array or result set");c=e}l=c.length;for(let i=0;i<l;i++)h=_?n(c[i]):c[i][n],w[h]=c[i];r||(r=(e,t)=>({left:e,right:t}));for(let e=0;e<y;e++)h=f?t(m[e]):m[e][t],d.push(r(m[e],w[h]||{}));return this._collection=new C("joinData"),this._collection.insert(d),this._filteredRows=[],this._filterInitialized=!1,this}map(e,t){const data=this.data(t).map(e);return this._collection=new C("mappedData"),this._collection.insert(data),this._filteredRows=[],this._filterInitialized=!1,this}}class y extends r.a{constructor(e,t,n={}){super(),this._rebuildPending=!1,this._resultData=[],this._resultDirty=!1,this._cachedResultSet=null,this._filterPipeline=[],this._sortFunction=null,this._sortCriteria=null,this._sortCriteriaSimple=null,this._sortByScoring=null,this._sortDirty=!1,({persistent:this._persistent=!1,sortPriority:this._sortPriority="passive",minRebuildInterval:this._minRebuildInterval=1}=n),this._collection=e,this.name=t,this._resultSet=new v(e),this._events={rebuild:[]}}_rematerialize({removeWhereFilters:e=!1}){if(this._resultData=[],this._resultDirty=!0,this._resultSet=new v(this._collection),(this._sortFunction||this._sortCriteria||this._sortCriteriaSimple||null!==this._sortByScoring)&&(this._sortDirty=!0),e){let e=this._filterPipeline.length;for(;e--;)"where"===this._filterPipeline[e].type&&(e!==this._filterPipeline.length-1&&(this._filterPipeline[e]=this._filterPipeline[this._filterPipeline.length-1]),this._filterPipeline.length--)}const t=this._filterPipeline;this._filterPipeline=[];for(let e=0;e<t.length;e++)this.applyFind(t[e].val);return this.data(),this.emit("rebuild",this),this}branchResultSet(e,t){const n=this._resultSet.copy();return void 0===e?n:n.transform(e,t)}toJSON(){return{name:this.name,_persistent:this._persistent,_sortPriority:this._sortPriority,_minRebuildInterval:this._minRebuildInterval,_resultSet:this._resultSet,_filterPipeline:this._filterPipeline,_sortCriteria:this._sortCriteria,_sortCriteriaSimple:this._sortCriteriaSimple,_sortByScoring:this._sortByScoring,_sortDirty:this._sortDirty}}static fromJSONObject(e,t){let n=new y(e,t.name);return n._resultDirty=!0,n._filterPipeline=t._filterPipeline,n._resultData=[],n._sortCriteria=t._sortCriteria,n._sortCriteriaSimple=t._sortCriteriaSimple,n._sortByScoring=t._sortByScoring,n._sortDirty=t._sortDirty,n._resultSet._filteredRows=t._resultSet._filteredRows,n._resultSet._filterInitialized=t._resultSet._filterInitialized,n._rematerialize({removeWhereFilters:!0}),n}removeFilters({queueSortPhase:e=!1}={}){this._rebuildPending=!1,this._resultSet.reset(),this._resultData=[],this._resultDirty=!0,this._cachedResultSet=null,this._filterPipeline=[],this._sortFunction=null,this._sortCriteria=null,this._sortCriteriaSimple=null,this._sortByScoring=null,this._sortDirty=!1,!0===e&&this._queueSortPhase()}applySort(e){return this._sortFunction=e,this._sortCriteria=null,this._sortCriteriaSimple=null,this._sortByScoring=null,this._queueSortPhase(),this}applySimpleSort(e,t=!1){return this._sortCriteriaSimple={field:e,options:t},this._sortFunction=null,this._sortCriteria=null,this._sortByScoring=null,this._queueSortPhase(),this}applySortCriteria(e){return this._sortCriteria=e,this._sortCriteriaSimple=null,this._sortFunction=null,this._sortByScoring=null,this._queueSortPhase(),this}applySortByScoring(e=!1){return this._sortFunction=null,this._sortCriteria=null,this._sortCriteriaSimple=null,this._sortByScoring=e,this._queueSortPhase(),this}getScoring(){return this._resultSet.getScoring()}startTransaction(){return this._cachedResultSet=this._resultSet.copy(),this}commit(){return this._cachedResultSet=null,this}rollback(){return this._resultSet=this._cachedResultSet,this._persistent&&(this._resultData=this._resultSet.data(),this.emit("rebuild",this)),this}_indexOfFilterWithId(e){if("string"==typeof e||"number"==typeof e)for(let t=0,n=this._filterPipeline.length;t<n;t++)if(e===this._filterPipeline[t].uid)return t;return-1}_addFilter(filter){this._filterPipeline.push(filter),this._resultSet[filter.type](filter.val)}reapplyFilters(){this._resultSet.reset(),this._cachedResultSet=null,this._persistent&&(this._resultData=[],this._resultDirty=!0);const e=this._filterPipeline;this._filterPipeline=[];for(let t=0,n=e.length;t<n;t++)this._addFilter(e[t]);return this._sortFunction||this._sortCriteria||this._sortCriteriaSimple||null!==this._sortByScoring?this._queueSortPhase():this._queueRebuildEvent(),this}applyFilter(filter){const e=this._indexOfFilterWithId(filter.uid);return e>=0?(this._filterPipeline[e]=filter,this.reapplyFilters()):(this._cachedResultSet=null,this._persistent&&(this._resultData=[],this._resultDirty=!0),this._addFilter(filter),this._sortFunction||this._sortCriteria||this._sortCriteriaSimple||null!==this._sortByScoring?this._queueSortPhase():this._queueRebuildEvent(),this)}applyFind(e,t=""){return this.applyFilter({type:"find",val:e,uid:t}),this}applyWhere(e,t){return this.applyFilter({type:"where",val:e,uid:t}),this}removeFilter(e){const t=this._indexOfFilterWithId(e);if(t<0)throw new Error("Dynamic view does not contain a filter with ID: "+e);return this._filterPipeline.splice(t,1),this.reapplyFilters(),this}count(){return this._resultDirty&&(this._resultData=this._resultSet.data()),this._resultSet.count()}data(e={}){return(this._sortDirty||this._resultDirty)&&this._performSortPhase({suppressRebuildEvent:!0}),this._persistent?this._resultData:this._resultSet.data(e)}_queueRebuildEvent(){this._rebuildPending||(this._rebuildPending=!0,setTimeout((()=>{this._rebuildPending&&(this._rebuildPending=!1,this.emit("rebuild",this))}),this._minRebuildInterval))}_queueSortPhase(){this._sortDirty||(this._sortDirty=!0,"active"===this._sortPriority?setTimeout((()=>{this._performSortPhase()}),this._minRebuildInterval):this._queueRebuildEvent())}_performSortPhase(e={}){(this._sortDirty||this._resultDirty)&&(this._sortDirty&&(this._sortFunction?this._resultSet.sort(this._sortFunction):this._sortCriteria?this._resultSet.compoundsort(this._sortCriteria):this._sortCriteriaSimple?this._resultSet.simplesort(this._sortCriteriaSimple.field,this._sortCriteriaSimple.options):null!==this._sortByScoring&&this._resultSet.sortByScoring(this._sortByScoring),this._sortDirty=!1),this._persistent&&(this._resultData=this._resultSet.data(),this._resultDirty=!1),e.suppressRebuildEvent||this.emit("rebuild",this))}_evaluateDocument(e,t){if(!this._resultSet._filterInitialized)return this._persistent&&(this._resultData=this._resultSet.data()),void(this._sortFunction||this._sortCriteria||this._sortCriteriaSimple?this._queueSortPhase():this._queueRebuildEvent());const n=this._resultSet._filteredRows,r=t?-1:n.indexOf(+e),o=n.length,l=new v(this._collection);let filter;l._filteredRows=[e],l._filterInitialized=!0;for(let e=0,t=this._filterPipeline.length;e<t;e++)filter=this._filterPipeline[e],l[filter.type](filter.val);const h=0===l._filteredRows.length?-1:0;return-1!==r||-1!==h?-1===r&&-1!==h?(n.push(e),this._persistent&&this._resultData.push(this._collection._data[e]),void(this._sortFunction||this._sortCriteria||this._sortCriteriaSimple?this._queueSortPhase():this._queueRebuildEvent())):-1!==r&&-1===h?(r<o-1?(n.splice(r,1),this._persistent&&this._resultData.splice(r,1)):(n.length=o-1,this._persistent&&(this._resultData.length=o-1)),void(this._sortFunction||this._sortCriteria||this._sortCriteriaSimple?this._queueSortPhase():this._queueRebuildEvent())):void(-1!==r&&-1!==h&&(this._persistent&&(this._resultData[r]=this._collection._data[e]),this._sortFunction||this._sortCriteria||this._sortCriteriaSimple?this._queueSortPhase():this._queueRebuildEvent())):void 0}_removeDocument(e){if(!this._resultSet._filterInitialized)return this._persistent&&(this._resultData=this._resultSet.data()),void(this._sortFunction||this._sortCriteria||this._sortCriteriaSimple?this._queueSortPhase():this._queueRebuildEvent());const t=this._resultSet._filteredRows,n=t.indexOf(+e);let r=t.length;-1!==n&&(n<r-1?(t[n]=t[r-1],t.length=r-1,this._persistent&&(this._resultData[n]=this._resultData[r-1],this._resultData.length=r-1)):(t.length=r-1,this._persistent&&(this._resultData.length=r-1)),this._sortFunction||this._sortCriteria||this._sortCriteriaSimple?this._queueSortPhase():this._queueRebuildEvent()),r=t.length;for(let n=0;n<r;n++)t[n]>e&&t[n]--}mapReduce(e,t){try{return t(this.data().map(e))}catch(e){throw e}}}var x=n(4),S=n(1);function k(e){return e.reduce(((a,b)=>a+b),0)/e.length}function I(e,path,t,n=0){if(void 0===e)return!1;if(n+1===path.length)return t.push(e[path[n]]),!1;const r=e[path[n]];if(Array.isArray(r)){for(let i=0;i<r.length;i++)I(r[i],path,t,n+1);return!0}return I(r,path,t,n+1)}n.d(t,"a",(function(){return C}));class C extends r.a{constructor(e,t={}){if(super(),this._data=[],this._idIndex=[],this._rangedIndexes={},this._lokimap={},this._unindexedSortComparator="js",this._defaultLokiOperatorPackage="js",this._constraints={unique:{}},this._transforms={},this._dirty=!0,this._cached=null,this._nestedProperties=[],this._ttl={age:null,ttlInterval:null,daemon:null},this._maxId=0,this._dynamicViews=[],this._changes=[],this._stages={},this._commitLog=[],t&&!0===t.disableMeta){if(!1===t.disableChangesApi)throw new Error("disableMeta option cannot be passed as true when disableChangesApi is passed as false");if(!1===t.disableDeltaChangesApi)throw new Error("disableMeta option cannot be passed as true when disableDeltaChangesApi is passed as false");if("number"==typeof t.ttl&&t.ttl>0)throw new Error("disableMeta option cannot be passed as true when ttl is enabled")}if(this.name=e,this._unindexedSortComparator=t.unindexedSortComparator||"js",this._defaultLokiOperatorPackage=t.defaultLokiOperatorPackage||"js",void 0!==t.unique&&(Array.isArray(t.unique)||(t.unique=[t.unique]),t.unique.forEach((e=>{this._constraints.unique[e]=new o(e)}))),void 0!==S.a.FullTextSearch?this._fullTextSearch=void 0!==t.fullTextSearch?new S.a.FullTextSearch(t.fullTextSearch):null:this._fullTextSearch=null,this._transactional=void 0!==t.transactional&&t.transactional,this._cloneObjects=void 0!==t.clone&&t.clone,this._asyncListeners=void 0!==t.asyncListeners&&t.asyncListeners,this._disableMeta=void 0!==t.disableMeta&&t.disableMeta,this._disableChangesApi=void 0===t.disableChangesApi||t.disableChangesApi,this._disableDeltaChangesApi=void 0===t.disableDeltaChangesApi||t.disableDeltaChangesApi,this._cloneMethod=void 0!==t.cloneMethod?t.cloneMethod:"deep",this._disableChangesApi&&(this._disableDeltaChangesApi=!0),this._serializableIndexes=void 0===t.serializableIndexes||t.serializableIndexes,null!=t.nestedProperties)for(let i=0;i<t.nestedProperties.length;i++){const e=t.nestedProperties[i];"string"==typeof e?this._nestedProperties.push({name:e,path:e.split(".")}):this._nestedProperties.push(e)}this.setTTL(t.ttl||-1,t.ttlInterval),this._events={insert:[],update:[],"pre-insert":[],"pre-update":[],close:[],flushbuffer:[],error:[],delete:[],warning:[]},this._ensureId();let n=t.rangedIndexes||{};for(let e in n)this.ensureRangedIndex(e,n[e].indexTypeName,n[e].comparatorName);this.setChangesApi(this._disableChangesApi,this._disableDeltaChangesApi),this.flushChanges()}toJSON(){return{name:this.name,unindexedSortComparator:this._unindexedSortComparator,defaultLokiOperatorPackage:this._defaultLokiOperatorPackage,_dynamicViews:this._dynamicViews,uniqueNames:Object.keys(this._constraints.unique),transforms:this._transforms,rangedIndexes:this._rangedIndexes,_data:this._data,idIndex:this._idIndex,maxId:this._maxId,_dirty:this._dirty,_nestedProperties:this._nestedProperties,transactional:this._transactional,asyncListeners:this._asyncListeners,disableMeta:this._disableMeta,disableChangesApi:this._disableChangesApi,disableDeltaChangesApi:this._disableDeltaChangesApi,cloneObjects:this._cloneObjects,cloneMethod:this._cloneMethod,changes:this._changes,_fullTextSearch:this._fullTextSearch}}static fromJSONObject(e,t){let n=new C(e.name,{disableChangesApi:e.disableChangesApi,disableDeltaChangesApi:e.disableDeltaChangesApi,unindexedSortComparator:e.unindexedSortComparator,defaultLokiOperatorPackage:e.defaultLokiOperatorPackage});if(n._transactional=e.transactional,n._asyncListeners=e.asyncListeners,n._disableMeta=e.disableMeta,n._disableChangesApi=e.disableChangesApi,n._cloneObjects=e.cloneObjects,n._cloneMethod=e.cloneMethod||"deep",n._changes=e.changes,n._nestedProperties=e._nestedProperties,n._rangedIndexes=e.rangedIndexes||{},n._dirty=!(!t||!0!==t.retainDirtyFlags)&&e._dirty,t&&void 0!==t[e.name]){let r=function(e){const n=t[e.name];if(n.proto){const e=n.inflate||((e,t)=>{for(let n in e)t[n]=e[n]});return data=>{const t=new n.proto;return e(data,t),t}}return n.inflate}(e);for(let t=0;t<e._data.length;t++)n._data[t]=n._defineNestedProperties(r(e._data[t])),n._lokimap[n._data[t].$loki]=n._data[t]}else for(let t=0;t<e._data.length;t++)n._data[t]=n._defineNestedProperties(e._data[t]),n._lokimap[n._data[t].$loki]=n._data[t];n._maxId=void 0===e.maxId?0:e.maxId,n._idIndex=e.idIndex,void 0!==e.transforms&&(n._transforms=e.transforms);for(let t in e.rangedIndexes){let r=e.rangedIndexes[t],o=(0,x.a[r.indexTypeName])(t,_.a[r.comparatorName]);o.restore(r.index),n._rangedIndexes[t].index=o}if(n._ensureId(),void 0!==e.uniqueNames)for(let t=0;t<e.uniqueNames.length;t++)n.ensureUniqueIndex(e.uniqueNames[t]);if(void 0!==e._dynamicViews)for(let t=0;t<e._dynamicViews.length;t++)n._dynamicViews.push(y.fromJSONObject(n,e._dynamicViews[t]));return e._fullTextSearch&&(n._fullTextSearch=S.a.FullTextSearch.fromJSONObject(e._fullTextSearch,t.fullTextSearch)),n}addTransform(e,t){if(void 0!==this._transforms[e])throw new Error("a transform by that name already exists");this._transforms[e]=t}getTransform(e){return this._transforms[e]}setTransform(e,t){this._transforms[e]=t}removeTransform(e){delete this._transforms[e]}setTTL(e,t){e<0?clearInterval(this._ttl.daemon):(this._ttl.age=e,this._ttl.ttlInterval=t,this._ttl.daemon=setInterval((()=>{const e=Date.now();this.chain().where((t=>{const n=t.meta.updated||t.meta.created,r=e-n;return this._ttl.age<r})).remove()}),t))}_prepareFullDocIndex(){const e=new Array(this._data.length);for(let i=0;i<e.length;i++)e[i]=i;return e}ensureIndex(e,t,n){this.ensureRangedIndex(e,t,n)}ensureRangedIndex(e,t,n){if(t=t||"avl",n=n||"loki",!x.a[t])throw new Error("ensureRangedIndex: Unknown range index type");if(!_.a[n])throw new Error("ensureRangedIndex: Unknown comparator");let r=x.a[t],o=_.a[n];this._rangedIndexes[e]={index:r(e,o),indexTypeName:t,comparatorName:n};let l=this._rangedIndexes[e].index;for(let i=0;i<this._data.length;i++)l.insert(this._data[i].$loki,this._data[i][e])}ensureUniqueIndex(e){let t=new o(e);this._constraints.unique[e]=t;for(let i=0;i<this._data.length;i++)t.set(this._data[i].$loki,this._data[i][e]);return t}count(e){return e?this.chain().find(e)._filteredRows.length:this._data.length}_ensureId(){this._idIndex=[];for(let i=0;i<this._data.length;i++)this._idIndex.push(this._data[i].$loki)}addDynamicView(e,t){const n=new y(this,e,t);return this._dynamicViews.push(n),n}removeDynamicView(e){for(let t=0;t<this._dynamicViews.length;t++)this._dynamicViews[t].name===e&&this._dynamicViews.splice(t,1)}getDynamicView(e){for(let t=0;t<this._dynamicViews.length;t++)if(this._dynamicViews[t].name===e)return this._dynamicViews[t];return null}findAndUpdate(e,t){this.chain().find(e).update(t)}findAndRemove(e){this.chain().find(e).remove()}insert(e){if(!Array.isArray(e))return this.insertOne(e);let t,n=[];this.emit("pre-insert",e);for(let i=0;i<e.length;i++){if(t=this.insertOne(e[i],!0),!t)return;n.push(t)}return this.emit("insert",n),n=this._cloneObjects?d(n,this._cloneMethod):n,1===n.length?n[0]:n}insertOne(e,t=!1){let n,r=null;if("object"!=typeof e?r=new TypeError("Document needs to be an object"):null===e&&(r=new TypeError("Object cannot be null")),null!==r)throw this.emit("error",r),r;const o=this._defineNestedProperties(this._cloneObjects?d(e,this._cloneMethod):e);if(this._disableMeta||void 0!==o.meta||(o.meta={version:0,revision:0,created:0}),t||this.emit("pre-insert",o),this._add(o))return this._disableChangesApi?this._insertMeta(o):this._insertMetaWithChange(o),n=this._cloneObjects?d(o,this._cloneMethod):o,t||this.emit("insert",n),n}_defineNestedProperties(data){for(let i=0;i<this._nestedProperties.length;i++){const e=this._nestedProperties[i].name,path=this._nestedProperties[i].path;Object.defineProperty(data,e,{get(){const e=[];return I(this,path,e)?e:e[0]},set(e){path.slice(0,path.length-1).reduce(((e,t)=>e&&e[t]?e[t]:null),this)[path[path.length-1]]=e},enumerable:!1,configurable:!0})}return data}clear({removeIndices:e=!1}={}){if(this._data=[],this._idIndex=[],this._cached=null,this._maxId=0,this._dynamicViews=[],this._dirty=!0,!0===e)this._rangedIndexes={},this._constraints={unique:{}};else{for(let e in this._rangedIndexes)this.ensureRangedIndex(e,this._rangedIndexes[e].indexTypeName,this._rangedIndexes[e].comparatorName);const e=Object.keys(this._constraints.unique);for(let i=0;i<e.length;i++)this._constraints.unique[e[i]].clear()}null!==this._fullTextSearch&&this._fullTextSearch.clear()}update(e){if(Array.isArray(e))for(let i=0;i<e.length;i++)this.update(e[i]);else{if(void 0===e.$loki)throw new Error("Trying to update unsynced document. Please save the document first by using insert() or addMany()");try{this.startTransaction();const t=this.get(e.$loki,!0);if(!t)throw new Error("Trying to update a document not in collection.");let n=t[0],r=t[1],o=this._defineNestedProperties(this._cloneObjects||!this._disableDeltaChangesApi?d(e,this._cloneMethod):e);this.emit("pre-update",e),Object.keys(this._constraints.unique).forEach((e=>{this._constraints.unique[e].update(o.$loki,o[e])})),this._data[r]=o,this._lokimap[e.$loki]=o;for(let e=0;e<this._dynamicViews.length;e++)this._dynamicViews[e]._evaluateDocument(r,!1);for(let t in this._rangedIndexes)this._rangedIndexes[t].index.update(e.$loki,e[t]);this._idIndex[r]=o.$loki,null!==this._fullTextSearch&&this._fullTextSearch.updateDocument(e,r),this.commit(),this._dirty=!0,this._disableChangesApi?this._updateMeta(o):this._updateMetaWithChange(o,n);let l=o;this._cloneObjects&&(l=d(o,this._cloneMethod)),this.emit("update",l,n)}catch(e){throw this.rollback(),this.emit("error",e),e}}}_add(e){if("object"!=typeof e)throw new TypeError("Object being added needs to be an object");if(void 0!==e.$loki)throw new Error("Document is already in collection, please use update()");try{this.startTransaction(),this._maxId++,isNaN(this._maxId)&&(this._maxId=this._data[this._data.length-1].$loki+1);const t=e;t.$loki=this._maxId,this._disableMeta||(t.meta.version=0);const n=this._constraints.unique;for(const e in n)void 0!==n[e]&&n[e].set(t.$loki,t[e]);this._idIndex.push(t.$loki),this._lokimap[t.$loki]=t,this._data.push(t);const r=this._data.length-1,o=this._dynamicViews.length;for(let i=0;i<o;i++)this._dynamicViews[i]._evaluateDocument(r,!0);for(let n in this._rangedIndexes)this._serializableIndexes&&t[n]instanceof Date&&(t[n]=t[n].getTime()),this._rangedIndexes[n].index.insert(e.$loki,e[n]);return null!==this._fullTextSearch&&this._fullTextSearch.addDocument(t,r),this.commit(),this._dirty=!0,this._cloneObjects?d(t,this._cloneMethod):t}catch(e){throw this.rollback(),this.emit("error",e),e}}updateWhere(e,t){const n=this.where(e);try{for(let i=0;i<n.length;i++)this.update(t(n[i]))}catch(e){throw this.rollback(),e}}removeWhere(e){this.remove(this._data.filter(e))}removeDataOnly(){this.remove(this._data.slice())}remove(e){if("number"==typeof e&&(e=this.get(e)),Array.isArray(e)){let t=0;const n=e.length;for(;t<n;t++)this.remove(e[t])}else{if(void 0===e.$loki)throw new Error("Object is not a document stored in the collection");try{this.startTransaction();const t=this.get(e.$loki,!0),n=t[1];let r="number"==typeof e?this.get(e):e;Object.keys(this._constraints.unique).forEach((e=>{e in r&&this._constraints.unique[e].remove(r.$loki)}));for(let e=0;e<this._dynamicViews.length;e++)this._dynamicViews[e]._removeDocument(n);this._data.splice(n,1),this._idIndex.splice(n,1),delete this._lokimap[e.$loki];for(let t in this._rangedIndexes)this._rangedIndexes[t].index.remove(e.$loki);null!==this._fullTextSearch&&this._fullTextSearch.removeDocument(e,n),this.commit(),this._dirty=!0,this._disableChangesApi||this._createChange(this.name,"R",t[0]),this.emit("delete",t[0]),delete e.$loki,delete e.meta}catch(e){throw this.rollback(),this.emit("error",e),e}}}getChanges(){return this._changes}setChangesApi(e,t=!0){this._disableChangesApi=e,this._disableDeltaChangesApi=!!e||t}flushChanges(){this._changes=[]}_getObjectDelta(e,t){const n=null!==t&&"object"==typeof t?Object.keys(t):null;if(n&&n.length&&["string","boolean","number"].indexOf(typeof t)<0){const r={};for(let i=0;i<n.length;i++){const o=n[i];if(t.hasOwnProperty(o))if(e.hasOwnProperty(o)&&void 0===this._constraints.unique[o]&&"$loki"!==o&&"meta"!==o){const n=this._getObjectDelta(e[o],t[o]);void 0!==n&&n!=={}&&(r[o]=n)}else r[o]=t[o]}return 0===Object.keys(r).length?void 0:r}return e===t?void 0:t}_getChangeDelta(e,t){return t?this._getObjectDelta(t,e):JSON.parse(JSON.stringify(e))}_createChange(e,t,n,r){this._changes.push({name:e,operation:t,obj:"U"!==t||this._disableDeltaChangesApi?JSON.parse(JSON.stringify(n)):this._getChangeDelta(n,r)})}_createInsertChange(e){this._createChange(this.name,"I",e)}_createUpdateChange(e,t){this._createChange(this.name,"U",e,t)}_insertMetaWithChange(e){this._insertMeta(e),this._createInsertChange(e)}_updateMetaWithChange(e,t){this._updateMeta(e),this._createUpdateChange(e,t)}_insertMeta(e){this._disableMeta||(e.meta||(e.meta={version:0,revision:0,created:0}),e.meta.created=(new Date).getTime(),e.meta.revision=0)}_updateMeta(e){this._disableMeta||(e.meta.updated=(new Date).getTime(),e.meta.revision+=1)}get(e,t=!1){if(!t){let t=this._lokimap[e];return void 0===t?null:t}const data=this._idIndex;let n=data.length-1,r=0,o=r+n>>1;if(e="number"==typeof e?e:parseInt(e,10),isNaN(e))throw new TypeError("Passed id is not an integer");for(;data[r]<data[n];)o=r+n>>1,data[o]<e?r=o+1:n=o;return n===r&&data[r]===e?t?[this._data[r],r]:this._data[r]:null}by(e,t){let n=this._constraints.unique[e].get(t);return this._cloneObjects?d(this._lokimap[n],this._cloneMethod):this._lokimap[n]}findOne(e){e=e||{};const t=this.chain().find(e,!0).data();return Array.isArray(t)&&0===t.length?null:this._cloneObjects?d(t[0],this._cloneMethod):t[0]}chain(e,t){const n=new v(this);return void 0===e?n:n.transform(e,t)}find(e){return this.chain().find(e).data()}findOneUnindexed(e,t){let n,i=this._data.length;for(;i--;)if(this._data[i][e]===t)return n=this._data[i],n;return null}startTransaction(){if(this._transactional){let e={};for(let t in this._rangedIndexes)e[t].indexTypeName=this._rangedIndexes[t].indexTypeName,e[t].comparatorName=this._rangedIndexes[t].comparatorName,e[t].index=this._rangedIndexes[t].index.backup();this._cached={index:this._idIndex,data:d(this._data,this._cloneMethod),rangedIndexes:e};for(let e=0;e<this._dynamicViews.length;e++)this._dynamicViews[e].startTransaction()}}commit(){if(this._transactional){this._cached=null;for(let e=0;e<this._dynamicViews.length;e++)this._dynamicViews[e].commit()}}rollback(){if(this._transactional&&null!==this._cached){this._idIndex=this._cached.index,this._data=this._cached.data;for(let i=0;i<this._data.length;i++)this._data[i]=this._defineNestedProperties(this._data[i]);for(let e in this._cached.rangedIndexes){let t=this._cached.rangedIndexes[e],n=(0,x.a[t.indexTypeName])(e,_.a[t.comparatorName]);n.restore(t.index),this._rangedIndexes[e].index=n}for(let e=0;e<this._dynamicViews.length;e++)this._dynamicViews[e].rollback()}}where(e){return this.chain().where(e).data()}mapReduce(e,t){return t(this._data.map(e))}eqJoin(e,t,n,r,o){return new v(this).eqJoin(e,t,n,r,o)}getStage(e){return this._stages[e]||(this._stages[e]={}),this._stages[e]}stage(e,t){const n=JSON.parse(JSON.stringify(t));return this.getStage(e)[t.$loki]=n,n}commitStage(e,t){const n=this.getStage(e),r=(new Date).getTime();for(const e in n)this.update(n[e]),this._commitLog.push({timestamp:r,message:t,data:JSON.parse(JSON.stringify(n[e]))});this._stages[e]={}}extract(e){const t=[];for(let i=0;i<this._data.length;i++)t.push(this._data[i][e]);return t}min(e){return Math.min.apply(null,this.extractNumerical(e))}max(e){return Math.max.apply(null,this.extractNumerical(e))}minRecord(e){const t={index:0,value:0};if(0===this._data.length)return t.index=null,t.value=null,t;t.index=this._data[0].$loki,t.value=parseFloat(this._data[0][e]);for(let i=1;i<this._data.length;i++){const n=parseFloat(this._data[i][e]);t.value>n&&(t.value=n,t.index=this._data[i].$loki)}return t}maxRecord(e){const t={index:0,value:0};if(0===this._data.length)return t.index=null,t.value=null,t;t.index=this._data[0].$loki,t.value=parseFloat(this._data[0][e]);for(let i=1;i<this._data.length;i++){const n=parseFloat(this._data[i][e]);t.value<n&&(t.value=n,t.index=this._data[i].$loki)}return t}extractNumerical(e){return this.extract(e).map(parseFloat).filter(Number).filter((e=>!isNaN(e)))}avg(e){return k(this.extractNumerical(e))}stdDev(e){return function(e){const t=k(e),n=k(e.map((e=>{const n=e-t;return n*n})));return Math.sqrt(n)}(this.extractNumerical(e))}mode(e){const t={},data=this.extractNumerical(e);let n=data[0],r=-1/0;for(let i=0;i<data.length;i++){const e=data[i];t[e]?t[e]++:t[e]=1,t[e]>r&&(n=e,r=t[e])}return n}median(e){const t=this.extractNumerical(e);t.sort(((a,b)=>a-b));const n=Math.floor(t.length/2);return t.length%2?t[n]:(t[n-1]+t[n])/2}}},function(e,t,n){"use strict";class r{constructor(e,t){this.nodes={},this.apex=null,this.name=e,this.comparator=t}backup(){let e=new r(this.name,this.comparator);return e.nodes=JSON.parse(JSON.stringify(this.nodes)),e.apex=this.apex,e}restore(e){this.name=e.name,this.comparator=e.comparator,this.nodes=JSON.parse(JSON.stringify(e.nodes)),this.apex=e.apex}insert(e,t){if(e<=0)throw new Error("avl index ids are required to be numbers greater than zero");let n=this.nodes[e]={id:e,value:t,parent:null,balance:0,height:0,left:null,right:null,siblings:[]};this.apex?this.insertNode(this.nodes[this.apex],n):this.apex=e}insertNode(e,t){switch(this.comparator(t.value,e.value)){case 0:e.siblings.push(t.id),t.parent=e.id;break;case 1:e.right?(this.insertNode(this.nodes[e.right],t),this.updateBalance(e)):(e.right=t.id,t.parent=e.id,this.updateBalance(e));break;case-1:e.left?(this.insertNode(this.nodes[e.left],t),this.updateBalance(e)):(e.left=t.id,t.parent=e.id,this.updateBalance(e));break;default:throw new Error("Invalid comparator result")}if(e.balance<-1){if(null===e.left)throw new Error("insertNode.balance() : left child should not be null");this.nodes[e.left].balance<=0?this.leftLeftCase(e):this.leftRightCase(e)}if(e.balance>1){if(null===e.right)throw new Error("insertNode.balance() : right child should not be null");this.nodes[e.right].balance>=0?this.rightRightCase(e):this.rightLeftCase(e)}return e.height}updateBalance(e){let t=e.left?this.nodes[e.left].height:-1,hr=e.right?this.nodes[e.right].height:-1;e.height=t>hr?1+t:1+hr,e.balance=hr-t}leftLeftCase(e){return this.rotateRight(e)}leftRightCase(e){if(!e.left)throw new Error("leftRightCase: left child not set");return e.left=this.rotateLeft(this.nodes[e.left]).id,this.rotateRight(e)}rightRightCase(e)