Socket
Socket
Sign inDemoInstall

signaldb

Package Overview
Dependencies
2
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.8.7 to 0.8.8

1

dist/.vite/manifest.json
{
"src/index.ts": {
"file": "index.umd.js",
"name": "index",
"src": "src/index.ts",

@@ -5,0 +6,0 @@ "isEntry": true

2

dist/index.umd.js

@@ -1,2 +0,2 @@

(function(w,K){typeof exports=="object"&&typeof module<"u"?K(exports):typeof define=="function"&&define.amd?define(["exports"],K):(w=typeof globalThis<"u"?globalThis:w||self,K(w.SignalDB={}))})(this,function(w){"use strict";var K={exports:{}},Z=typeof Reflect=="object"?Reflect:null,We=Z&&typeof Z.apply=="function"?Z.apply:function(e,n,r){return Function.prototype.apply.call(e,n,r)},he;Z&&typeof Z.ownKeys=="function"?he=Z.ownKeys:Object.getOwnPropertySymbols?he=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:he=function(e){return Object.getOwnPropertyNames(e)};function rn(t){console&&console.warn&&console.warn(t)}var Ye=Number.isNaN||function(e){return e!==e};function g(){g.init.call(this)}K.exports=g,K.exports.once=un,g.EventEmitter=g,g.prototype._events=void 0,g.prototype._eventsCount=0,g.prototype._maxListeners=void 0;var Qe=10;function pe(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return Qe},set:function(t){if(typeof t!="number"||t<0||Ye(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Qe=t}}),g.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},g.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Ye(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};function Xe(t){return t._maxListeners===void 0?g.defaultMaxListeners:t._maxListeners}g.prototype.getMaxListeners=function(){return Xe(this)},g.prototype.emit=function(e){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);var i=e==="error",s=this._events;if(s!==void 0)i=i&&s.error===void 0;else if(!i)return!1;if(i){var o;if(n.length>0&&(o=n[0]),o instanceof Error)throw o;var c=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw c.context=o,c}var u=s[e];if(u===void 0)return!1;if(typeof u=="function")We(u,this,n);else for(var a=u.length,f=tt(u,a),r=0;r<a;++r)We(f[r],this,n);return!0};function Be(t,e,n,r){var i,s,o;if(pe(n),s=t._events,s===void 0?(s=t._events=Object.create(null),t._eventsCount=0):(s.newListener!==void 0&&(t.emit("newListener",e,n.listener?n.listener:n),s=t._events),o=s[e]),o===void 0)o=s[e]=n,++t._eventsCount;else if(typeof o=="function"?o=s[e]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),i=Xe(t),i>0&&o.length>i&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=o.length,rn(c)}return t}g.prototype.addListener=function(e,n){return Be(this,e,n,!1)},g.prototype.on=g.prototype.addListener,g.prototype.prependListener=function(e,n){return Be(this,e,n,!0)};function sn(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function He(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=sn.bind(r);return i.listener=n,r.wrapFn=i,i}g.prototype.once=function(e,n){return pe(n),this.on(e,He(this,e,n)),this},g.prototype.prependOnceListener=function(e,n){return pe(n),this.prependListener(e,He(this,e,n)),this},g.prototype.removeListener=function(e,n){var r,i,s,o,c;if(pe(n),i=this._events,i===void 0)return this;if(r=i[e],r===void 0)return this;if(r===n||r.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||n));else if(typeof r!="function"){for(s=-1,o=r.length-1;o>=0;o--)if(r[o]===n||r[o].listener===n){c=r[o].listener,s=o;break}if(s<0)return this;s===0?r.shift():on(r,s),r.length===1&&(i[e]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",e,c||n)}return this},g.prototype.off=g.prototype.removeListener,g.prototype.removeAllListeners=function(e){var n,r,i;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[e]),this;if(arguments.length===0){var s=Object.keys(r),o;for(i=0;i<s.length;++i)o=s[i],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=r[e],typeof n=="function")this.removeListener(e,n);else if(n!==void 0)for(i=n.length-1;i>=0;i--)this.removeListener(e,n[i]);return this};function Ze(t,e,n){var r=t._events;if(r===void 0)return[];var i=r[e];return i===void 0?[]:typeof i=="function"?n?[i.listener||i]:[i]:n?cn(i):tt(i,i.length)}g.prototype.listeners=function(e){return Ze(this,e,!0)},g.prototype.rawListeners=function(e){return Ze(this,e,!1)},g.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):et.call(t,e)},g.prototype.listenerCount=et;function et(t){var e=this._events;if(e!==void 0){var n=e[t];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}g.prototype.eventNames=function(){return this._eventsCount>0?he(this._events):[]};function tt(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function on(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function cn(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}function un(t,e){return new Promise(function(n,r){function i(o){t.removeListener(e,s),r(o)}function s(){typeof t.removeListener=="function"&&t.removeListener("error",i),n([].slice.call(arguments))}nt(t,e,s,{once:!0}),e!=="error"&&an(t,i,{once:!0})})}function an(t,e,n){typeof t.on=="function"&&nt(t,"error",e,n)}function nt(t,e,n,r){if(typeof t.on=="function")r.once?t.once(e,n):t.on(e,n);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(s){r.once&&t.removeEventListener(e,i),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}var fn=K.exports;class ln extends fn.EventEmitter{}class G extends Error{}const dn=2147483647,hn=-2147483648,pn=Number.MAX_SAFE_INTEGER,mn=Number.MIN_SAFE_INTEGER,R=Symbol("missing"),rt=Object.freeze(new Error("mingo: cycle detected while processing object/array")),gn=Object.getPrototypeOf([]),it=Object.getPrototypeOf({}),yn="[object Object]",On=/^\[object ([a-zA-Z0-9]+)\]$/;class we{}class _e{}const V=t=>t===null?we:t===void 0?_e:t.constructor,oe=t=>{const e=wn(t);let n=0,r=e.length;for(;r;)n=(n<<5)-n^e.charCodeAt(--r);return n>>>0},st=new Set(["null","undefined","boolean","number","string","date","regexp"]),ot=new Set([_e,we,Boolean,String,Number]),ce=t=>t.toString(),P=t=>`${V(t).name}[${t.toString()}]`,J=new Map([[Number,ce],[Boolean,ce],[RegExp,ce],[Function,ce],[Symbol,ce],[Date,t=>t.toISOString()],[String,JSON.stringify],[we,t=>"null"],[_e,t=>"undefined"],[Int8Array,P],[Uint8Array,P],[Uint8ClampedArray,P],[Int16Array,P],[Uint16Array,P],[Int32Array,P],[Uint32Array,P],[Float32Array,P],[Float64Array,P]]);typeof BigInt<"u"&&J.set(BigInt,t=>"0x"+t.toString(16)),typeof BigInt64Array<"u"&&J.set(BigInt64Array,P),typeof BigUint64Array<"u"&&J.set(BigUint64Array,P);const vn={null:0,undefined:0,number:1,string:2,object:3,array:4,boolean:5,date:6,regexp:7,function:8},L=(t,e)=>{t===R&&(t=void 0),e===R&&(e=void 0);const[n,r]=[t,e].map(i=>vn[ue(i).toLowerCase()]);return n!==r?n-r:n===1||n===2||n===6?t<e?-1:t>e?1:0:k(t,e)?0:t<e?-1:t>e?1:0};function v(t,e){if(!t)throw new G(e)}const bn=t=>{const e=Object.getPrototypeOf(V(t));return e&&e.name==="TypedArray"},Ae=t=>{if(ot.has(V(t)))return t;const e=new Set,n=r=>{if(e.has(r))throw rt;const i=V(r);if(ot.has(i))return r;try{if(b(r))return e.add(r),r.map(n);if(O(r)){e.add(r);const s={};for(const o in r)s[o]=n(r[o]);return s}}finally{e.delete(r)}return i===Date||i===RegExp||bn(r)?new i(r):r};return n(t)},ue=t=>On.exec(Object.prototype.toString.call(t))[1],xe=t=>typeof t=="boolean",T=t=>typeof t=="string",x=t=>!isNaN(t)&&typeof t=="number",b=Array.isArray,O=t=>{if(!t)return!1;const e=Object.getPrototypeOf(t);return(e===it||e===null)&&yn===Object.prototype.toString.call(t)},me=t=>t===Object(t),Se=t=>t instanceof Date,ge=t=>t instanceof RegExp,ae=t=>typeof t=="function",$=t=>t==null,ee=(t,e)=>t.includes(e),ct=(t,e)=>!ee(t,e),te=(t,e=!0)=>!!t||e&&t==="",ne=t=>$(t)||T(t)&&!t||t instanceof Array&&t.length===0||O(t)&&Object.keys(t).length===0,ut=t=>t===R,re=t=>t instanceof Array?t:[t],S=(t,e)=>!!t&&Object.prototype.hasOwnProperty.call(t,e),$n=(t,e)=>O(t)&&O(e)||b(t)&&b(e);function je(t,e,n){if(n=n||{flatten:!1},ut(t)||$(t))return e;if(ut(e)||$(e))return t;if(!$n(t,e)){if(n.skipValidation)return e||t;throw Error("mismatched types. must both be array or object")}if(n.skipValidation=!0,b(t)){const r=t,i=e;if(n.flatten){let s=0,o=0;for(;s<r.length&&o<i.length;)r[s]=je(r[s++],i[o++],n);for(;o<i.length;)r.push(e[o++])}else fe(r,i)}else for(const r in e)t[r]=je(t[r],e[r],n);return t}function Me(t,e=oe){const n=new Map;return t.forEach((r,i)=>{const s=ft(r,e);n.has(s)?n.get(s).some(o=>k(t[o],r))||n.get(s).push(i):n.set(s,[i])}),n}function Le(t,e=oe){if(t.some(c=>c.length==0))return[];if(t.length===1)return Array.from(t);const n=_n(t.map((c,u)=>[u,c.length]),c=>c[1]),r=t[n[0][0]],i=Me(r,e),s=new Map,o=new Array;return i.forEach((c,u)=>{const a=c.map(d=>r[d]),f=a.map(d=>0),l=a.map(d=>[n[0][0],0]);let h=!1;for(let d=1;d<t.length;d++){const[p,y]=n[d],N=t[p];if(s.has(d)||s.set(d,Me(N)),s.get(d).has(u)){const A=s.get(d).get(u).map(H=>N[H]);h=a.map((H,de)=>A.some((oi,ci)=>{const ui=f[de];return k(H,oi)&&(f[de]++,p<l[de][0]&&(l[de]=[p,s.get(d).get(u)[ci]])),ui<f[de]})).some(Boolean)}if(!h)return}h&&fe(o,f.map((d,p)=>d===t.length-1?[a[p],l[p]]:R).filter(d=>d!==R))}),o.sort((c,u)=>{const[a,[f,l]]=c,[h,[d,p]]=u,y=L(f,d);return y!==0?y:L(l,p)}).map(c=>c[0])}function at(t,e=0){const n=new Array;function r(i,s){for(let o=0,c=i.length;o<c;o++)b(i[o])&&(s>0||s<0)?r(i[o],Math.max(-1,s-1)):n.push(i[o])}return r(t,e),n}const En=t=>{let[e,n]=[Object.getPrototypeOf(t),Object.getOwnPropertyNames(t)],r=e;for(;!n.length&&e!==it&&e!==gn;)r=e,n=Object.getOwnPropertyNames(e),e=Object.getPrototypeOf(e);const i={};return n.forEach(s=>i[s]=t[s]),[i,r]};function k(t,e){const n=[[t,e]];for(;n.length>0;){if([t,e]=n.pop(),t===e)continue;const r=V(t);if(r!==V(e)||ae(t))return!1;if(J.has(r)){const i=J.get(r);if(i(t)!==i(e))return!1;continue}if(r===Array||r===Object){const i=Object.keys(t),s=Object.keys(e);if(i.length!==s.length||new Set(i.concat(s)).size!=i.length)return!1;for(const o of i)n.push([t[o],e[o]]);continue}return!1}return!n.length}function In(t,e=oe){const n=t.map(r=>R);return Me(t,e).forEach((r,i)=>{r.forEach(s=>n[s]=t[s])}),n.filter(r=>r!==R)}function wn(t){const e=new Set,n=r=>{const i=V(r);if(J.has(i))return J.get(i)(r);const s=i===Object?"":i.name;if(ae(r.toJSON))return`${s}(${JSON.stringify(r)})`;if(e.has(r))throw rt;e.add(r);try{if(i===Array)return"["+r.map(n).join(",")+"]";if(i!==Object){const[c,u]=En(r);if(b(r))return`${s}${n([...r,c])}`;r=c}const o=Object.keys(r);return o.sort(),`${s}{`+o.map(c=>`${c}:${n(r[c])}`).join(",")+"}"}finally{e.delete(r)}};return n(t)}function ft(t,e){return e=e||oe,$(t)?null:e(t).toString()}function _n(t,e,n=L){if(ne(t))return t;const r=new Array,i=new Array;for(let s=0;s<t.length;s++){const o=t[s],c=e(o,s);$(c)?i.push(o):r.push([c,o])}return r.sort((s,o)=>n(s[0],o[0])),fe(i,r.map(s=>s[1]))}function An(t,e,n=oe){if(t.length<1)return new Map;const r=new Map,i=new Map;for(let s=0;s<t.length;s++){const o=t[s],c=e(o,s),u=ft(c,n);if(u===null)i.has(null)?i.get(null).push(o):i.set(null,[o]);else{const a=r.has(u)?r.get(u).find(f=>k(f,c)):null;$(a)?(i.set(c,[o]),r.has(u)?r.get(u).push(c):r.set(u,[c])):i.get(a).push(o)}}return i}const Ne=5e4;function fe(t,...e){return t instanceof Array?e.reduce((n,r)=>{let i=Math.ceil(r.length/Ne),s=0;for(;i-- >0;)Array.prototype.push.apply(n,r.slice(s,s+Ne)),s+=Ne;return n},t):e.filter(me).reduce((n,r)=>(Object.assign(n,r),n),t)}function Pe(t,e){return me(t)?t[e]:void 0}function xn(t,e){if(e<1)return t;for(;e--&&t.length===1;)t=t[0];return t}function U(t,e,n){let r=0;function i(o,c){let u=o;for(let a=0;a<c.length;a++){const f=c[a];if(/^\d+$/.exec(f)===null&&u instanceof Array){if(a===0&&r>0)break;r+=1;const h=c.slice(a);u=u.reduce((d,p)=>{const y=i(p,h);return y!==void 0&&d.push(y),d},[]);break}else u=Pe(u,f);if(u===void 0)break}return u}const s=st.has(ue(t).toLowerCase())?t:i(t,e.split("."));return s instanceof Array&&(n!=null&&n.unwrapArray)?xn(s,r):s}function ye(t,e,n){const r=e.split("."),i=r[0],s=r.slice(1).join("."),o=/^\d+$/.exec(i)!==null,c=r.length>1;let u,a;if(t instanceof Array)if(o)u=Pe(t,Number(i)),c&&(u=ye(u,s,n)),u=[u];else{u=[];for(const f of t)a=ye(f,e,n),n!=null&&n.preserveMissing?(a===void 0&&(a=R),u.push(a)):a!==void 0&&u.push(a)}else{if(a=Pe(t,i),c&&(a=ye(a,s,n)),a===void 0)return;u=n!=null&&n.preserveKeys?Object.assign({},t):{},u[i]=a}return u}function Ce(t){if(t instanceof Array)for(let e=t.length-1;e>=0;e--)t[e]===R?t.splice(e,1):Ce(t[e]);else if(O(t))for(const e in t)S(t,e)&&Ce(t[e])}const lt=/^\d+$/;function le(t,e,n,r){const i=e.split("."),s=i[0],o=i.slice(1).join(".");if(i.length===1)(O(t)||b(t)&&lt.test(s))&&n(t,s);else{r!=null&&r.buildGraph&&$(t[s])&&(t[s]={});const c=t[s];if(!c)return;const u=!!(i.length>1&&lt.test(i[1]));c instanceof Array&&(r!=null&&r.descendArray)&&!u?c.forEach(a=>le(a,o,n,r)):le(c,o,n,r)}}function Sn(t,e,n){le(t,e,(r,i)=>{r[i]=ae(n)?n(r[i]):n},{buildGraph:!0})}function dt(t,e,n){le(t,e,(r,i)=>{if(r instanceof Array){if(/^\d+$/.test(i))r.splice(parseInt(i),1);else if(n&&n.descendArray)for(const s of r)O(s)&&delete s[i]}else O(r)&&delete r[i]},n)}const jn=/^\$[a-zA-Z0-9_]+$/;function W(t){return jn.test(t)}function ht(t){if(st.has(ue(t).toLowerCase()))return ge(t)?{$regex:t}:{$eq:t};if(me(t)){if(!Object.keys(t).some(W))return{$eq:t};if(S(t,"$regex")){const n=Object.assign({},t);return n.$regex=new RegExp(t.$regex,t.$options),delete n.$options,n}}return t}var z;(function(t){t.CLONE_ALL="CLONE_ALL",t.CLONE_INPUT="CLONE_INPUT",t.CLONE_OUTPUT="CLONE_OUTPUT",t.CLONE_OFF="CLONE_OFF"})(z||(z={}));class Y{constructor(e,n,r,i=Date.now()){this._opts=e,this._root=n,this._local=r,this.timestamp=i,this.update(n,r)}static init(e,n,r){return e instanceof Y?new Y(e._opts,$(e.root)?n:e.root,Object.assign({},e.local,r)):new Y(e,n,r)}update(e,n){var r;return this._root=e,this._local=n&&Object.assign({},n,{variables:Object.assign({},(r=this._local)===null||r===void 0?void 0:r.variables,n==null?void 0:n.variables)}),this}getOptions(){return Object.freeze(Object.assign(Object.assign({},this._opts),{context:q.from(this._opts.context)}))}get root(){return this._root}get local(){return this._local}get idKey(){return this._opts.idKey}get collation(){var e;return(e=this._opts)===null||e===void 0?void 0:e.collation}get processingMode(){var e;return((e=this._opts)===null||e===void 0?void 0:e.processingMode)||z.CLONE_OFF}get useStrictMode(){var e;return(e=this._opts)===null||e===void 0?void 0:e.useStrictMode}get scriptEnabled(){var e;return(e=this._opts)===null||e===void 0?void 0:e.scriptEnabled}get useGlobalContext(){var e;return(e=this._opts)===null||e===void 0?void 0:e.useGlobalContext}get hashFunction(){var e;return(e=this._opts)===null||e===void 0?void 0:e.hashFunction}get collectionResolver(){var e;return(e=this._opts)===null||e===void 0?void 0:e.collectionResolver}get jsonSchemaValidator(){var e;return(e=this._opts)===null||e===void 0?void 0:e.jsonSchemaValidator}get variables(){var e;return(e=this._opts)===null||e===void 0?void 0:e.variables}get context(){var e;return(e=this._opts)===null||e===void 0?void 0:e.context}}function Oe(t){return t instanceof Y?t.getOptions():Object.freeze(Object.assign(Object.assign({idKey:"_id",scriptEnabled:!0,useStrictMode:!0,useGlobalContext:!0,processingMode:z.CLONE_OFF},t),{context:t!=null&&t.context?q.from(t==null?void 0:t.context):q.init({})}))}var m;(function(t){t.ACCUMULATOR="accumulator",t.EXPRESSION="expression",t.PIPELINE="pipeline",t.PROJECTION="projection",t.QUERY="query",t.WINDOW="window"})(m||(m={}));class q{constructor(e){this.operators={[m.ACCUMULATOR]:{},[m.EXPRESSION]:{},[m.PIPELINE]:{},[m.PROJECTION]:{},[m.QUERY]:{},[m.WINDOW]:{}};for(const[n,r]of Object.entries(e))this.addOperators(n,r)}static init(e={}){return new q(e)}static from(e){return new q(e.operators)}addOperators(e,n){for(const[r,i]of Object.entries(n))this.getOperator(e,r)||(this.operators[e][r]=i);return this}addAccumulatorOps(e){return this.addOperators(m.ACCUMULATOR,e)}addExpressionOps(e){return this.addOperators(m.EXPRESSION,e)}addQueryOps(e){return this.addOperators(m.QUERY,e)}addPipelineOps(e){return this.addOperators(m.PIPELINE,e)}addProjectionOps(e){return this.addOperators(m.PROJECTION,e)}addWindowOps(e){return this.addOperators(m.WINDOW,e)}getOperator(e,n){return e in this.operators&&this.operators[e][n]||null}}const Q=q.init();function ve(t,e){for(const[n,r]of Object.entries(e)){v(ae(r)&&W(n),`'${n}' is not a valid operator`);const i=X(t,n,null);v(!i||r===i,`${n} already exists for '${t}' operators. Cannot change operator function once registered.`)}switch(t){case m.ACCUMULATOR:Q.addAccumulatorOps(e);break;case m.EXPRESSION:Q.addExpressionOps(e);break;case m.PIPELINE:Q.addPipelineOps(e);break;case m.PROJECTION:Q.addProjectionOps(e);break;case m.QUERY:Q.addQueryOps(e);break;case m.WINDOW:Q.addWindowOps(e);break}}function X(t,e,n){const{context:r,useGlobalContext:i}=n||{},s=r?r.getOperator(t,e):null;return!s&&i?Q.getOperator(t,e):s}const pt={$$ROOT(t,e,n){return n.root},$$CURRENT(t,e,n){return t},$$REMOVE(t,e,n){},$$NOW(t,e,n){return new Date(n.timestamp)}},Re={$$KEEP(t,e,n){return t},$$PRUNE(t,e,n){},$$DESCEND(t,e,n){if(!S(e,"$cond"))return t;let r;for(const[i,s]of Object.entries(t))if(me(s)){if(s instanceof Array){const o=[];for(let c of s)O(c)&&(c=mt(c,e,n.update(c))),$(c)||o.push(c);r=o}else r=mt(s,e,n.update(s));$(r)?delete t[i]:t[i]=r}return t}};function E(t,e,n,r){var i;const s=Y.init(r,t);if(n=n||"",W(n)){const o=X(m.EXPRESSION,n,r);if(o)return o(t,e,s);const c=X(m.ACCUMULATOR,n,r);if(c)return t instanceof Array||(t=E(t,e,null,s),e=null),v(t instanceof Array,`'${n}' target must be an array.`),c(t,e,s.update(null,s.local));throw new G(`operator '${n}' is not registered`)}if(T(e)&&e.length>0&&e[0]==="$"){if(S(Re,e))return e;let o=s.root;const c=e.split(".");if(S(pt,c[0]))o=pt[c[0]](t,null,s),e=e.slice(c[0].length+1);else if(c[0].slice(0,2)==="$$"){o=Object.assign({},s.variables,{this:t},(i=s.local)===null||i===void 0?void 0:i.variables);const u=c[0].slice(2);v(S(o,u),`Use of undefined variable: ${u}`),e=e.slice(2)}else e=e.slice(1);return e===""?o:U(o,e)}if(b(e))return e.map(o=>E(t,o,null,s));if(O(e)){const o={};for(const[c,u]of Object.entries(e))if(o[c]=E(t,u,c,s),[m.EXPRESSION,m.ACCUMULATOR].some(a=>!!X(a,c,r)))return v(Object.keys(e).length===1,"Invalid aggregation expression '"+JSON.stringify(e)+"'"),o[c];return o}return e}function mt(t,e,n){const r=E(t,e,null,n);return S(Re,r)?Re[r](t,e,n):r}const Te=Object.freeze(Object.defineProperty({__proto__:null,$and:(t,e,n)=>{const r=E(t,e,null,n);return te(r,n.useStrictMode)&&r.every(i=>te(i,n.useStrictMode))},$not:(t,e,n)=>{const r=re(e);if(r.length==0)return!1;if(r.length==1)return!E(t,r[0],null,n);throw"Expression $not takes exactly 1 argument"},$or:(t,e,n)=>{const r=E(t,e,null,n),i=n.useStrictMode;return te(r,i)&&r.some(s=>te(s,i))}},Symbol.toStringTag,{value:"Module"})),Mn=(t,e,n)=>{const r=E(t,e,null,n);return r[0]>r[1]?1:r[0]<r[1]?-1:0};function ie(t){return t instanceof gt?t:new gt(t)}function Ln(...t){let e=0;return ie(()=>{for(;e<t.length;){const n=t[e].next();if(!n.done)return n;e++}return{done:!0}})}function Nn(t){return!!t&&typeof t=="object"&&(t==null?void 0:t.next)instanceof Function}function Pn(t,e){const n=t.slice(e+1);t.splice(e),Array.prototype.push.apply(t,n)}const ke=new Error;var C;(function(t){t[t.MAP=0]="MAP",t[t.FILTER=1]="FILTER",t[t.TAKE=2]="TAKE",t[t.DROP=3]="DROP"})(C||(C={}));function Cn(t,e,n){let r=!1,i=-1,s=0;return function(o){try{e:for(;!r;){let c=t();i++;let u=-1;const a=e.length;let f=!1;for(;++u<a;){const l=e[u];switch(l.action){case C.MAP:c=l.func(c,i);break;case C.FILTER:if(!l.func(c,i))continue e;break;case C.TAKE:--l.count,l.count||(f=!0);break;case C.DROP:--l.count,l.count||Pn(e,u);continue e;default:break e}}if(r=f,o)n[s++]=c;else return{value:c,done:!1}}}catch(c){if(c!==ke)throw c}return r=!0,{done:r}}}class gt{constructor(e){this.iteratees=[],this.yieldedValues=[],this.isDone=!1;let n;if(e instanceof Function&&(e={next:e}),Nn(e)){const r=e;n=()=>{const i=r.next();if(i.done)throw ke;return i.value}}else if(e instanceof Array){const r=e,i=r.length;let s=0;n=()=>{if(s<i)return r[s++];throw ke}}else if(!(e instanceof Function))throw new G("Lazy must be initialized with an array, generator, or function.");this.getNext=Cn(n,this.iteratees,this.yieldedValues)}push(e,n){return typeof n=="function"?this.iteratees.push({action:e,func:n}):typeof n=="number"&&this.iteratees.push({action:e,count:n}),this}next(){return this.getNext()}map(e){return this.push(C.MAP,e)}filter(e){return this.push(C.FILTER,e)}take(e){return e>0?this.push(C.TAKE,e):this}drop(e){return e>0?this.push(C.DROP,e):this}transform(e){const n=this;let r;return ie(()=>(r||(r=ie(e(n.value()))),r.next()))}value(){return this.isDone||(this.isDone=this.getNext(!0).done),this.yieldedValues}each(e){for(;;){const n=this.next();if(n.done)break;if(e(n.value)===!1)return!1}return!0}reduce(e,n){let r=this.next();for(n===void 0&&!r.done&&(n=r.value,r=this.next());!r.done;)n=e(n,r.value),r=this.next();return n}size(){return this.reduce((e,n)=>++e,0)}[Symbol.iterator](){return this}}class Rn{constructor(e,n){this.pipeline=e,this.options=Oe(n)}stream(e){let n=ie(e);const r=this.options.processingMode;(r==z.CLONE_ALL||r==z.CLONE_INPUT)&&n.map(Ae);const i=new Array;if(!ne(this.pipeline))for(const s of this.pipeline){const o=Object.keys(s),c=o[0],u=X(m.PIPELINE,c,this.options);v(o.length===1&&!!u,`invalid pipeline operator ${c}`),i.push(c),n=u(n,s[c],this.options)}return(r==z.CLONE_OUTPUT||r==z.CLONE_ALL&&Le([["$group","$unwind"],i]).length)&&n.map(Ae),n}run(e){return this.stream(e).value()}}let Tn=class{constructor(e,n,r,i){this.source=e,this.predicate=n,this.projection=r,this.options=i,this.operators=[],this.result=null,this.buffer=[]}fetch(){return this.result?this.result:(O(this.projection)&&this.operators.push({$project:this.projection}),this.result=ie(this.source).filter(this.predicate),this.operators.length>0&&(this.result=new Rn(this.operators,this.options).stream(this.result)),this.result)}fetchAll(){const e=ie([...this.buffer]);return this.buffer=[],Ln(e,this.fetch())}all(){return this.fetchAll().value()}count(){return this.all().length}skip(e){return this.operators.push({$skip:e}),this}limit(e){return this.operators.push({$limit:e}),this}sort(e){return this.operators.push({$sort:e}),this}collation(e){return this.options=Object.assign(Object.assign({},this.options),{collation:e}),this}next(){if(this.buffer.length>0)return this.buffer.pop();const e=this.fetch().next();if(!e.done)return e.value}hasNext(){if(this.buffer.length>0)return!0;const e=this.fetch().next();return e.done?!1:(this.buffer.push(e.value),!0)}map(e){return this.all().map(e)}forEach(e){this.all().forEach(e)}[Symbol.iterator](){return this.fetchAll()}};class D{constructor(e,n){this.condition=e,this.options=Oe(n),this.compiled=[],this.compile()}compile(){v(O(this.condition),`query criteria must be an object: ${JSON.stringify(this.condition)}`);const e={};for(const[n,r]of Object.entries(this.condition)){if(n==="$where")Object.assign(e,{field:n,expr:r});else if(ee(["$and","$or","$nor","$expr","$jsonSchema"],n))this.processOperator(n,n,r);else{v(!W(n),`unknown top level operator: ${n}`);for(const[i,s]of Object.entries(ht(r)))this.processOperator(n,i,s)}e.field&&this.processOperator(e.field,e.field,e.expr)}}processOperator(e,n,r){const i=X(m.QUERY,n,this.options);if(!i)throw new G(`unknown query operator ${n}`);const s=i(e,r,this.options);this.compiled.push(s)}test(e){for(let n=0,r=this.compiled.length;n<r;n++)if(!this.compiled[n](e))return!1;return!0}find(e,n){return new Tn(e,r=>this.test(r),n||{},this.options)}remove(e){return e.reduce((n,r)=>(this.test(r)||n.push(r),n),[])}}function I(t){const e=(n,r,i)=>{const s={unwrapArray:!0},o=Math.max(1,n.split(".").length-1);return c=>{const u=U(c,n,s);return t(u,r,Object.assign(Object.assign({},i),{depth:o}))}};return e.op="query",e}function se(t){return(e,n,r)=>{const i=E(e,n,null,r);return t(...i)}}function De(t,e,n){if(k(t,e)||$(t)&&$(e))return!0;if(t instanceof Array){const r=k.bind(null,e);return t.some(r)||at(t,n==null?void 0:n.depth).some(r)}return!1}function yt(t,e,n){return!De(t,e,n)}function Ot(t,e,n){return $(t)?e.some(r=>r===null):Le([re(t),e],n==null?void 0:n.hashFunction).length>0}function kn(t,e,n){return!Ot(t,e,n)}function vt(t,e,n){return be(t,e,(r,i)=>L(r,i)<0)}function bt(t,e,n){return be(t,e,(r,i)=>L(r,i)<=0)}function $t(t,e,n){return be(t,e,(r,i)=>L(r,i)>0)}function Et(t,e,n){return be(t,e,(r,i)=>L(r,i)>=0)}function Dn(t,e,n){return re(t).some(r=>e.length===2&&r%e[0]===e[1])}function Fn(t,e,n){const r=re(t),i=s=>T(s)&&te(e.exec(s),n==null?void 0:n.useStrictMode);return r.some(i)||at(r,1).some(i)}function Un(t,e,n){return(e===!1||e===0)&&t===void 0||(e===!0||e===1)&&t!==void 0}function zn(t,e,n){if(!b(t)||!b(e)||!t.length||!e.length)return!1;let r=!0;for(const i of e){if(!r)break;O(i)&&ee(Object.keys(i),"$elemMatch")?r=It(t,i.$elemMatch,n):i instanceof RegExp?r=t.some(s=>typeof s=="string"&&i.test(s)):r=t.some(s=>k(i,s))}return r}function qn(t,e,n){return Array.isArray(t)&&t.length===e}function Kn(t){return W(t)&&["$and","$or","$nor"].indexOf(t)===-1}function It(t,e,n){if(b(t)&&!ne(t)){let r=o=>o,i=e;Object.keys(e).every(Kn)&&(i={temp:e},r=o=>({temp:o}));const s=new D(i,n);for(let o=0,c=t.length;o<c;o++)if(s.test(r(t[o])))return!0}return!1}const wt=t=>t===null,_t=t=>x(t)&&t>=hn&&t<=dn&&t.toString().indexOf(".")===-1,At=t=>x(t)&&t>=mn&&t<=pn&&t.toString().indexOf(".")===-1,Gn={array:b,bool:xe,boolean:xe,date:Se,decimal:x,double:x,int:_t,long:At,number:x,null:wt,object:O,regex:ge,regexp:ge,string:T,undefined:$,function:t=>{throw new G("unsupported type key `function`.")},1:x,2:T,3:O,4:b,6:$,8:xe,9:Se,10:wt,11:ge,16:_t,18:At,19:x};function xt(t,e,n){const r=Gn[e];return r?r(t):!1}function Vn(t,e,n){return Array.isArray(e)?e.findIndex(r=>xt(t,r))>=0:xt(t,e)}function be(t,e,n){return re(t).some(r=>ue(r)===ue(e)&&n(r,e))}const Jn=se(De),Wn=se($t),Yn=se(Et),Qn=se(vt),Xn=se(bt),Bn=se(yt),Fe=Object.freeze(Object.defineProperty({__proto__:null,$cmp:Mn,$eq:Jn,$gt:Wn,$gte:Yn,$lt:Qn,$lte:Xn,$ne:Bn},Symbol.toStringTag,{value:"Module"})),St=(t,e,n)=>{if(ne(e)||!O(e))return t;let r=L;const i=n.collation;return O(i)&&T(i.locale)&&(r=Zn(i)),t.transform(s=>{const o=Object.keys(e);for(const c of o.reverse()){const u=An(s,f=>U(f,c),n.hashFunction),a=Array.from(u.keys()).sort(r);e[c]===-1&&a.reverse(),s=[],a.reduce((f,l)=>fe(f,u.get(l)),s)}return s})},Hn={1:"base",2:"accent",3:"variant"};function Zn(t){const e={sensitivity:Hn[t.strength||3],caseFirst:t.caseFirst==="off"?"false":t.caseFirst||"false",numeric:t.numericOrdering||!1,ignorePunctuation:t.alternate==="shifted"};(t.caseLevel||!1)===!0&&(e.sensitivity==="base"&&(e.sensitivity="case"),e.sensitivity==="accent"&&(e.sensitivity="variant"));const n=new Intl.Collator(t.locale,e);return(r,i)=>{if(!T(r)||!T(i))return L(r,i);const s=n.compare(r,i);return s<0?-1:s>0?1:0}}const jt=(t,e,n)=>t.take(e),er=(t,e,n)=>{const r=E(t,e,null,n),i=r[0];let s=r[1],o=r[2];return $(o)?s<0?(s=Math.max(0,i.length+s),o=i.length-s+1):(o=s,s=0):(s<0&&(s=Math.max(0,i.length+s)),v(o>0,"Invalid argument for $slice operator. Limit must be a positive number"),o+=s),i.slice(s,o)},Mt=(t,e)=>{const n={};return t.split("").forEach((r,i)=>n[r]=e*(i+1)),n};Object.assign(Object.assign(Object.assign({},Mt("ABCDEFGHIKLM",1)),Mt("NOPQRSTUVWXY",-1)),{Z:0});const Lt={undefined:null,null:null,NaN:NaN,Infinity:new Error,"-Infinity":new Error};function j(t,e=Lt){const n=Object.assign({},Lt,e),r=new Set(Object.keys(n));return(i,s,o)=>{const c=E(i,s,null,o);if(r.has(`${c}`)){const u=n[`${c}`];if(u instanceof Error)throw new G(`cannot apply $${t.name} to -inf, value must in (-inf,inf)`);return u}return t(c)}}j(Math.acos,{Infinity:1/0,0:new Error}),j(Math.acosh,{Infinity:1/0,0:new Error}),j(Math.asin),j(Math.asinh,{Infinity:1/0,"-Infinity":-1/0}),j(Math.atan),j(Math.atanh,{1:1/0,"-1":-1/0}),j(Math.cos),j(Math.cosh,{"-Infinity":1/0,Infinity:1/0});const tr=Math.PI/180;j(t=>t*tr,{Infinity:1/0,"-Infinity":1/0});const nr=180/Math.PI;j(t=>t*nr,{Infinity:1/0,"-Infinity":-1/0}),j(Math.sin),j(Math.sinh,{"-Infinity":-1/0,Infinity:1/0}),j(Math.tan);const Nt=(t,e,n)=>{if(ne(e))return t;let r=Object.keys(e),i=!1;Pt(e,n);const s=n.idKey;if(ee(r,s)){const c=e[s];(c===0||c===!1)&&(r=r.filter(ct.bind(null,[s])),i=r.length==0)}else r.push(s);const o=Y.init(n);return t.map(c=>Ue(c,e,o.update(c),r,i))};function Ue(t,e,n,r,i){let s={},o=!1,c=!1;const u=[];i&&u.push(n.idKey);for(const a of r){let f;const l=e[a];if(a!==n.idKey&&ee([0,!1],l)&&(c=!0),a===n.idKey&&ne(l))f=t[a];else if(T(l))f=E(t,l,a,n);else if(!ee([1,!0],l))if(l instanceof Array)f=l.map(d=>{const p=E(t,d,null,n);return $(p)?null:p});else if(O(l)){const d=l,p=Object.keys(l),y=p.length==1?p[0]:"",N=X(m.PROJECTION,y,n);if(N)y==="$slice"?re(d[y]).every(x)?(f=N(t,d[y],a,n),o=!0):f=E(t,d,a,n):f=N(t,d[y],a,n);else if(W(y))f=E(t,d[y],y,n);else if(S(t,a)){Pt(d,n);let A=t[a];A instanceof Array?f=A.map(H=>Ue(H,d,n,p,!1)):(A=O(A)?A:t,f=Ue(A,d,n,p,!1))}else f=E(t,l,null,n)}else{u.push(a);continue}const h=ye(t,a,{preserveMissing:!0});h!==void 0&&je(s,h,{flatten:!0}),ct([0,1,!1,!0],l)&&(f===void 0?dt(s,a,{descendArray:!0}):Sn(s,a,f))}if(Ce(s),(o||c||i)&&(s=fe({},t,s),u.length>0))for(const a of u)dt(s,a,{descendArray:!0});return s}function Pt(t,e){const n=[!1,!1];for(const[r,i]of Object.entries(t)){if(r===(e==null?void 0:e.idKey))return;i===0||i===!1?n[0]=!0:(i===1||i===!0)&&(n[1]=!0),v(!(n[0]&&n[1]),"Projection cannot have a mix of inclusion and exclusion.")}}const Ct=(t,e,n)=>t.drop(e),Rt=Object.freeze(Object.defineProperty({__proto__:null,$elemMatch:(t,e,n,r)=>{const i=U(t,n),s=new D(e,r);v(i instanceof Array,"$elemMatch: argument must resolve to array");const o=[];for(let c=0;c<i.length;c++)if(s.test(i[c])){if(r.useStrictMode)return[i[c]];o.push(i[c])}return o.length>0?o:void 0},$slice:(t,e,n,r)=>{const i=U(t,n),s=e;return b(i)?er(t,e instanceof Array?[i,...s]:[i,e],r):i}},Symbol.toStringTag,{value:"Module"})),rr=I(zn),ir=I(It),sr=I(qn),$e=t=>I((e,n,r)=>{let i=0;if(n instanceof Array)for(const s of n)i=i|1<<s;else i=n;return t(e&i,i)}),or=$e((t,e)=>t==0),cr=$e((t,e)=>t==e),ur=$e((t,e)=>t<e),ar=$e((t,e)=>t>0),fr=I(De),lr=I($t),dr=I(Et),hr=I(Ot),pr=I(vt),mr=I(bt),gr=I(yt),yr=I(kn),Or=I(Un),vr=I(Vn);function br(t,e,n){return r=>E(r,e,null,n)}function $r(t,e,n){if(!(n!=null&&n.jsonSchemaValidator))throw new G("Missing option 'jsonSchemaValidator'. Configure to use '$jsonSchema' operator.");const r=n==null?void 0:n.jsonSchemaValidator(e);return i=>r(i)}const Er=I(Dn),Ir=I(Fn);function wr(t,e,n){v(n.scriptEnabled,"$where operator requires 'scriptEnabled' option to be true");const r=e;return v(ae(r),"$where only accepts a Function object"),i=>te(r.call(i),n==null?void 0:n.useStrictMode)}const _r=(t,e,n)=>{v(b(e),"Invalid expression: $and expects value to be an Array.");const r=e.map(i=>new D(i,n));return i=>r.every(s=>s.test(i))},Tt=(t,e,n)=>{v(b(e),"Invalid expression. $or expects value to be an Array");const r=e.map(i=>new D(i,n));return i=>r.some(s=>s.test(i))},ze=Object.freeze(Object.defineProperty({__proto__:null,$all:rr,$and:_r,$bitsAllClear:or,$bitsAllSet:cr,$bitsAnyClear:ur,$bitsAnySet:ar,$elemMatch:ir,$eq:fr,$exists:Or,$expr:br,$gt:lr,$gte:dr,$in:hr,$jsonSchema:$r,$lt:pr,$lte:mr,$mod:Er,$ne:gr,$nin:yr,$nor:(t,e,n)=>{v(b(e),"Invalid expression. $nor expects value to be an array.");const r=Tt("$or",e,n);return i=>!r(i)},$not:(t,e,n)=>{const r={};r[t]=ht(e);const i=new D(r,n);return s=>!i.test(s)},$or:Tt,$regex:Ir,$size:sr,$type:vr,$where:wr},Symbol.toStringTag,{value:"Module"}));ve(m.EXPRESSION,Object.assign(Object.assign({},Te),Fe)),ve(m.PIPELINE,{$project:Nt,$skip:Ct,$limit:jt,$sort:St}),ve(m.PROJECTION,Rt),ve(m.QUERY,ze),q.init().addExpressionOps(Object.assign(Object.assign({},Te),Fe)).addPipelineOps({$project:Nt,$skip:Ct,$limit:jt,$sort:St}).addProjectionOps(Rt).addQueryOps(ze);function kt(t,e){return new D(e).test(t)}const qe=(t,e)=>{switch(t){case"deep":return Ae(e);case"copy":return Se(e)?new Date(e):b(e)?[...e]:O(e)?Object.assign({},e):e;default:return e}},Ar=/^[a-z]+[a-zA-Z0-9]*$/;function Dt(t){if(!t.includes(".$"))return[{parent:t,selector:t},[]];const e=t.indexOf(".$"),n=t.indexOf("]"),r=t.substring(0,e),i=t.substring(e+3,n);v(i===""||Ar.test(i),"The filter <identifier> must begin with a lowercase letter and contain only alphanumeric characters.");const s=t.substring(n+2),[o,c]=s?Dt(s):[];return[{selector:t,parent:r,child:i||"$",next:o},[i,...c||[]].filter(Boolean)]}const _=(t,e,n,r,i)=>{const{parent:s,child:o,next:c}=e;if(!o){let a=!1;return le(t,s,(l,h)=>a=!!r(l,h)||a,i),a}const u=U(t,s);return b(u)?u.map((a,f)=>n[o]&&!n[o].test({[o]:a})?!1:c?_(a,c,n,r,i):r(u,f)).some(Boolean):!1};function M(t,e,n,r){const i=[];for(const[s,o]of Object.entries(t)){const[c,u]=Dt(s);if(!u.length)r(o,c,{})&&i.push(c.parent);else{const a={};e.forEach(l=>{Object.keys(l).forEach(h=>{u.forEach(d=>{(h===d||h.startsWith(d+"."))&&(a[d]=a[d]||{},Object.assign(a[d],{[h]:l[h]}))})})});const f={};for(const[l,h]of Object.entries(a))f[l]=new D(h,n.queryOptions);r(o,c,f)&&i.push(c.parent)}}return i}const xr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{const c={$each:[i]};return O(i)&&S(i,"$each")&&Object.assign(c,i),_(t,s,o,(u,a)=>{const f=u[a]||(u[a]=[]);return Le([f,c.$each]).length===c.$each.length?!1:(u[a]=qe(r.cloneMode,In(f.concat(c.$each))),!0)},{buildGraph:!0})}),Sr=new Set(["and","or","xor"]),jr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{const c=Object.keys(i);return v(c.length===1&&Sr.has(c[0]),`Invalid bit operator '${c[0]}'. Must be one of 'and', 'or', or 'xor'.`),_(t,s,o,(u,a)=>{let f=u[a];const l=i[c[0]];if(f!==void 0&&!(x(f)&&x(l)))return!1;switch(f=f||0,c[0]){case"and":u[a]=f&l;break;case"or":u[a]=f|l;break;case"xor":u[a]=f^l;break}return u[a]!==f},{buildGraph:!0})}),Mr=(t,e,n=[],r={})=>{const i=Date.now();return M(e,n,r,(s,o,c)=>_(t,o,c,(u,a)=>(u[a]=i,!0),{buildGraph:!0}))},Lr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{if(!s.child){const c=U(t,s.parent);v(c===void 0||x(c),"cannot apply $inc to a value of non-numeric type")}return _(t,s,o,(c,u)=>(c[u]=(c[u]||(c[u]=0))+i,!0),{buildGraph:!0})}),Nr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>c[u]!==void 0&&L(c[u],i)>-1?!1:(c[u]=i,!0),{buildGraph:!0})),Pr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>c[u]!==void 0&&L(c[u],i)<1?!1:(c[u]=i,!0),{buildGraph:!0})),Cr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>{const a=c[u];return c[u]=c[u]===void 0?0:c[u]*i,c[u]!==a},{buildGraph:!0})),Rr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>{const a=c[u];return v(b(a),`path '${s.selector}' contains an element of non-array type.`),a.length?(i===-1?a.splice(0,1):a.pop(),!0):!1})),Ft=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{const c=!O(i)||Object.keys(i).some(W),u=new D(c?{k:i}:i,r.queryOptions),a=c?f=>u.test({k:f}):f=>u.test(f);return _(t,s,o,(f,l)=>{const h=f[l],d=new Array;return h.map(y=>{const N=a(y);return N||d.push(y),N}).some(Boolean)?(f[l]=d,!0):!1})}),Tr=(t,e,n=[],r={})=>{const i={};return Object.entries(e).forEach(([s,o])=>{i[s]={$in:o}}),Ft(t,i,n,r)},kr=Object.freeze(["$each","$slice","$sort","$position"]),Dr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{const c={$each:[i]};return O(i)&&kr.some(u=>S(i,u))&&Object.assign(c,i),_(t,s,o,(u,a)=>{const f=u[a]||(u[a]=[]),l=f.slice(0,c.$slice||f.length),h=f.length,d=x(c.$position)?c.$position:f.length;if(f.splice(d,0,...qe(r.cloneMode,c.$each)),c.$sort){const p=O(c.$sort)?Object.keys(c.$sort||{}).pop():"",y=p?c.$sort[p]:c.$sort,N=p?A=>U(A,p):A=>A;f.sort((A,H)=>y*L(N(A),N(H)))}return x(c.$slice)&&(c.$slice<0?f.splice(0,f.length+c.$slice):f.splice(c.$slice)),h!=f.length||!k(l,f)},{descendArray:!0,buildGraph:!0})}),Ut=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>k(c[u],i)?!1:(c[u]=qe(r.cloneMode,i),!0),{buildGraph:!0})),zt=Object.freeze(Object.defineProperty({__proto__:null,$addToSet:xr,$bit:jr,$currentDate:Mr,$inc:Lr,$max:Nr,$min:Pr,$mul:Cr,$pop:Rr,$pull:Ft,$pullAll:Tr,$push:Dr,$rename:(t,e,n=[],r={})=>{const i=[],s=M(e,n,r,(o,c,u)=>_(t,c,u,(a,f)=>S(a,f)?(i.push(...Ut(t,{[o]:a[f]},n,r)),delete a[f],!0):!1));return Array.from(new Set(s.concat(i)))},$set:Ut,$unset:(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>S(c,u)?(b(c)?c[u]=null:delete c[u],!0):!1))},Symbol.toStringTag,{value:"Module"}));function Fr(t){return t=Object.assign(Object.assign({},t),{queryOptions:Oe(t.queryOptions)}),t.queryOptions.context.addQueryOps(ze).addExpressionOps(Te).addExpressionOps(Fe),(e,n,r=[],i={},s={})=>{const o=Object.assign({cloneMode:"copy"},t,s);Object.assign(o,{queryOptions:Oe(Object.assign({useStrictMode:!1},o==null?void 0:o.queryOptions))}),r=r||[],i=i||{};const c=Object.entries(n);v(c.length===1,"Update expression must contain only one operator.");const[u,a]=c[0];v(S(zt,u),`Update operator '${u}' is not supported.`);const f=zt[u];return Object.keys(i).length&&!new D(i,o.queryOptions).test(e)?[]:f(e,a,r,o)}}const Ur=Fr({});function qt(t,e){const n=Object.assign({},t);return Ur(n,e),n}function Ke(t,e){if(Object.is(t,e))return!0;if(t instanceof RegExp&&e instanceof RegExp)return t.toString()===e.toString();if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(typeof t!="object"||typeof e!="object"||t===null||e===null)return!1;const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(let i=0;i<n.length;i+=1){const s=n[i];if(!r.includes(s)||!Ke(t[s],e[s]))return!1}return!0}function zr(){return Math.floor(Math.random()*1e17).toString(16)}function Kt(t,e=!1){let n=e,r=!1,i=null;return()=>{if((!n||!r)&&i&&clearTimeout(i),n){if(r)return;setTimeout(()=>{t(),r=!1,e&&(n=!0)},0),r=!0;return}n=!0,t(),i=setTimeout(()=>{n=!1},0)}}function B(t){return typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?t.toString():t instanceof Date?t.toISOString():JSON.stringify(t)}var Gt=function(t){return function(e,n,r){return t(e,n,r)*r}},Ge=function(t,e){if(t)throw Error("Invalid sort config: "+e)},Vt=function(t){var e=t||{},n=e.asc,r=e.desc,i=n?1:-1,s=n||r;Ge(!s,"Expected `asc` or `desc` property"),Ge(n&&r,"Ambiguous object with `asc` and `desc` config properties");var o=t.comparer&&Gt(t.comparer);return{order:i,sortBy:s,comparer:o}},qr=function(t){return function e(n,r,i,s,o,c,u){var a,f;if(typeof n=="string")a=c[n],f=u[n];else if(typeof n=="function")a=n(c),f=n(u);else{var l=Vt(n);return e(l.sortBy,r,i,l.order,l.comparer||t,c,u)}var h=o(a,f,s);return(h===0||a==null&&f==null)&&r.length>i?e(r[i],r,i+1,s,o,c,u):h}};function Jt(t,e,n){if(t===void 0||t===!0)return function(s,o){return e(s,o,n)};if(typeof t=="string")return Ge(t.includes("."),"String syntax not allowed for nested properties."),function(s,o){return e(s[t],o[t],n)};if(typeof t=="function")return function(s,o){return e(t(s),t(o),n)};if(Array.isArray(t)){var r=qr(e);return function(s,o){return r(t[0],t,1,n,e,s,o)}}var i=Vt(t);return Jt(i.sortBy,i.comparer||e,i.order)}var Ve=function(t,e,n,r){var i;return Array.isArray(e)?(Array.isArray(n)&&n.length<2&&(i=n,n=i[0]),e.sort(Jt(n,r,t))):e};function Wt(t){var e=Gt(t.comparer);return function(n){var r=Array.isArray(n)&&!t.inPlaceSorting?n.slice():n;return{asc:function(i){return Ve(1,r,i,e)},desc:function(i){return Ve(-1,r,i,e)},by:function(i){return Ve(1,r,i,e)}}}}var Yt=function(t,e,n){return t==null?n:e==null?-n:typeof t!=typeof e?typeof t<typeof e?-1:1:t<e?-1:t>e?1:0},Kr=Wt({comparer:Yt});Wt({comparer:Yt,inPlaceSorting:!0});function Ee(t,e){const n=e.split(/[.[\]]/g);n[0]===""&&n.shift(),n[n.length-1]===""&&n.pop();let r=t;for(let i=0;i<n.length;i+=1){const s=n[i];if(r==null||s.trim()==="")return;r=r[s]}if(r!==void 0)return r}function Gr(t,e){return Kr(t).by(Object.entries(e).map(([n,r])=>({[r===1?"asc":"desc"]:s=>Ee(s,n)})))}function Qt(t,e,n,r=!1){if(t==null)return t;const i=e.split(/[.[\]]/g);i[0]===""&&i.shift(),i[i.length-1]===""&&i.pop();const s=o=>{if(i.length>1){const c=i.shift(),u=!Number.isNaN(parseInt(i[0],10));o[c]===void 0&&(o[c]=u?[]:{}),s(o[c])}else{if(r&&n===void 0){delete o[i[0]];return}o[i[0]]=n}};return s(t),t}function Vr(t,e){if(Object.values(e).every(i=>i===0)){const i=Object.assign({},t);return Object.keys(e).forEach(s=>{Ee(t,s)!==void 0&&Qt(i,s,void 0,!0)}),i}const r={};return Object.entries(e).forEach(([i,s])=>{const o=Ee(t,i);o!==void 0&&(o==null&&s!==1||Qt(r,i,s===1?o:void 0))}),r}class Jr{constructor(e,n,r){this.previousItems=[],this.skipInitial=!1,this.isIinitial=!0,this.callbacks=e,this.skipInitial=r,this.unbindEvents=n()}call(e,...n){const r=this.callbacks[e];r&&(this.skipInitial&&this.isIinitial||r(...n))}hasCallbacks(e){return e.some(n=>!!this.callbacks[n])}check(e){const n=new Map(this.previousItems.map((i,s)=>[i.id,{item:i,index:s,beforeItem:this.previousItems[s+1]||null}])),r=new Map(e.map((i,s)=>[i.id,{item:i,index:s,beforeItem:e[s+1]||null}]));this.hasCallbacks(["changed","movedBefore","removed"])&&n.forEach(({item:i,index:s,beforeItem:o})=>{var c;const u=r.get(i.id);u?(Ke(u.item,i)||this.call("changed",u.item),u.index!==s&&((c=u.beforeItem)===null||c===void 0?void 0:c.id)!==(o==null?void 0:o.id)&&this.call("movedBefore",u.item,u.beforeItem)):this.call("removed",i)}),this.hasCallbacks(["added","addedBefore"])&&e.forEach((i,s)=>{n.get(i.id)||(this.call("added",i),this.call("addedBefore",i,e[s+1]||null))}),this.previousItems=e,this.isIinitial=!1}stop(){this.unbindEvents()}}function Wr(t){return t?t.isInScope?t.isInScope():!0:!1}class Yr{constructor(e,n){this.observers=[],this.onCleanupCallbacks=[],this.getFilteredItems=e,this.options=n||{}}transform(e){return this.options.transform?this.options.transform(e):e}getItems(){const e=this.getFilteredItems(),{sort:n,skip:r,limit:i}=this.options,s=n?Gr(e,n):e,o=r?s.slice(r):s,c=i?o.slice(0,i):o,u=this.options.fields&&this.options.fields.id===0;return c.map(a=>this.options.fields?Object.assign(Object.assign({},u?{}:{id:a.id}),Vr(a,this.options.fields)):a)}depend(e,n){if(!this.options.reactive||!Wr(this.options.reactive))return;const r=this.options.reactive.create();r.depend();const i=()=>r.notify(),s=Object.entries(e).filter(([,c])=>c).map(([c])=>c).reduce((c,u)=>Object.assign(Object.assign({},c),{[u]:i}),{}),o=this.observeChanges(s,!0,n);this.options.reactive.onDispose&&this.options.reactive.onDispose(()=>o(),r),this.onCleanup(o)}cleanup(){this.onCleanupCallbacks.forEach(e=>{e()}),this.onCleanupCallbacks=[]}onCleanup(e){this.onCleanupCallbacks.push(e)}forEach(e){const n=this.getItems();this.depend({addedBefore:!0,removed:!0,changed:!0,movedBefore:!0},n),n.forEach(r=>{e(this.transform(r))})}map(e){const n=[];return this.forEach(r=>{n.push(e(r))}),n}fetch(){return this.map(e=>e)}count(){const e=this.getItems();return this.depend({added:!0,removed:!0}),e.length}observeChanges(e,n=!1,r){const i=Object.entries(e).reduce((o,[c,u])=>u?Object.assign(Object.assign({},o),{[c]:(a,f)=>{const l=this.transform(a),h=f!==void 0,d=h&&f?this.transform(f):null;return u(l,...h?[d]:[])}}):o,{}),s=new Jr(i,()=>{const o=()=>{s.check(this.getItems())},c=this.options.bindEvents&&this.options.bindEvents(o);return()=>{c&&c()}},n);return this.observers.push(s),s.check(r||this.getItems()),this.onCleanup(()=>s.stop()),()=>{s.stop(),this.observers=this.observers.filter(o=>o!==s)}}requery(){const e=this.getItems();this.observers.forEach(n=>n.check(e))}}function Qr(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n}typeof SuppressedError=="function"&&SuppressedError;function Je(...t){return t.length===0?[]:[...new Set(t.reduce((e,n)=>e.filter(r=>n.includes(r))))]}function Xr(t,e){return t.reduce((n,r)=>{/* istanbul ignore if -- @preserve */if(r.getItemPositions){const o=r.getItemPositions(e);return o==null?n:{matched:!0,positions:n.matched?Je(n.positions,o):o,optimizedSelector:n.optimizedSelector}}const i=r.query(e);if(!i.matched)return n;const s=Object.fromEntries(Object.entries(n.optimizedSelector).filter(([o])=>!i.fields.includes(o)));return{matched:!0,positions:[...new Set(n.matched?Je(n.positions,i.positions):i.positions)],optimizedSelector:s}},{matched:!1,positions:[],optimizedSelector:Object.assign({},e)})}function Ie(t,e){if(e==null||Object.keys(e).length<=0)return{matched:!1,positions:[],optimizedSelector:e};const{$and:n,$or:r}=e,i=Qr(e,["$and","$or"]),s=Xr(t,i);let{matched:o,positions:c}=s;const u=s.optimizedSelector;if(Array.isArray(n)){const a=[];for(const f of n){const{matched:l,positions:h,optimizedSelector:d}=Ie(t,f);l?(c=o?Je(c,h):h,o=!0,Object.keys(d).length>0&&a.push(d)):a.push(f)}a.length>0&&(u.$and=a)}if(Array.isArray(r)){const a=[];for(const f of r){const{matched:l,positions:h,optimizedSelector:d}=Ie(t,f);l?(c=[...new Set([...c,...h])],o=!0,Object.keys(d).length>0&&a.push(d)):a.push(f)}a.length>0&&(u.$or=a)}return{matched:o,positions:c||[],optimizedSelector:u}}function Br(t){return t}const Xt=["$eq","$gt","$gte","$lt","$lte","$in","$nin","$ne","$exists","$not","$expr","$jsonSchema","$mod","$regex","$options","$text","$where","$all","$elemMatch","$size","$bitsAllClear","$bitsAllSet","$bitsAnyClear","$bitsAnySet"];function Bt(t){if(typeof t!="object"||t==null)return!1;const e=Object.keys(t);return e.length===0||e.some(i=>!Xt.includes(i))?!1:e.every(i=>Xt.includes(i))}function Hr(t,e){if(e[t]instanceof RegExp)return null;if(e[t]!=null){if(Bt(e[t])){if(Bt(e[t])&&Array.isArray(e[t].$in)&&e[t].$in.length){const r=Object.assign(Object.assign({},e),{[t]:Object.assign({},e[t])});return delete r[t].$in,Object.keys(r[t]).length===0&&delete r[t],e[t].$in.map(B)}return null}return[B(e[t])]}return null}function Ht(t,e){return{query(n){const r=Hr(t,n);return r==null?{matched:!1}:{matched:!0,positions:r.reduce((s,o)=>[...s,...e.get(o)||[]],[]),fields:[t]}},rebuild(){}}}function Zr(t){const e=new Map;return Object.assign(Object.assign({},Ht(t,e)),{rebuild(n){e.clear(),n.forEach((r,i)=>{const s=B(Ee(r,t)),o=e.get(s)||new Set;o.add(i),e.set(s,o)})}})}function Zt(t){return t.added.length>0||t.modified.length>0||t.removed.length>0}function ei(t,{added:e,modified:n,removed:r}){const i=t.slice();return e.forEach(s=>{i.push(s)}),n.forEach(s=>{const o=i.findIndex(({id:c})=>c===s.id);o!==-1&&(i[o]=s)}),r.forEach(s=>{const o=i.findIndex(({id:c})=>c===s.id);o!==-1&&i.splice(o,1)}),i}class F extends ln{constructor(e){var n;if(super(),this.persistenceAdapter=null,this.indexProviders=[],this.indicesOutdated=!1,this.idIndex=new Map,this.rebuildIndicesOncePerTick=Kt(this.rebuildAllIndices.bind(this)),F.collections.push(this),this.options=Object.assign({memory:[]},e),this.debugMode=(n=this.options.enableDebugMode)!==null&&n!==void 0?n:F.debugMode,this.indexProviders=[Ht("id",this.idIndex),...this.options.indices||[]],this.options.persistence){const r=this.options.persistence;this.persistenceAdapter=r;let i=0,s=!1;const o={added:[],modified:[],removed:[]},c=async()=>{const{items:l,changes:h}=await r.load();if(l){if(i>0)return;this.memory().splice(0,this.memoryArray().length,...l),this.idIndex.clear(),this.memory().map((d,p)=>{this.idIndex.set(B(d.id),new Set([p]))})}else h&&(h.added.forEach(d=>{this.memory().push(d);const p=this.memory().findIndex(y=>y===d);this.idIndex.set(B(d.id),new Set([p]))}),h.modified.forEach(d=>{const p=this.memory().findIndex(y=>y.id===d.id);if(p===-1)throw new Error("Cannot resolve index for item");this.memory().splice(p,1,d)}),h.removed.forEach(d=>{const p=this.memory().findIndex(y=>y.id===d.id);if(p===-1)throw new Error("Cannot resolve index for item");this.memory().splice(p,1)}));this.rebuildIndices(),this.emit("persistence.received")},u={added:[],modified:[],removed:[]};let a=!1;const f=()=>{if(a||!Zt(u))return;a=!0,i+=1;const l=this.memoryArray(),h=Object.assign({},u);u.added=[],u.modified=[],u.removed=[],r.save(l,h).then(()=>{this.emit("persistence.transmitted")}).catch(d=>{this.emit("persistence.error",d instanceof Error?d:new Error(d))}).finally(()=>{i-=1,a=!1,f()})};this.on("added",l=>{if(!s){o.added.push(l);return}u.added.push(l),f()}),this.on("changed",l=>{if(!s){o.modified.push(l);return}u.modified.push(l),f()}),this.on("removed",l=>{if(!s){o.removed.push(l);return}u.removed.push(l),f()}),r.register(()=>c()).then(async()=>{let l=this.memoryArray();for(await c();Zt(o);){const h=o.added.splice(0),d=o.modified.splice(0),p=o.removed.splice(0);l=ei(l,{added:h,modified:d,removed:p}),await r.save(l,{added:h,modified:d,removed:p}).then(()=>{this.emit("persistence.transmitted")})}await c(),s=!0,this.emit("persistence.init")}).catch(l=>{this.emit("persistence.error",l instanceof Error?l:new Error(l))})}}getDebugMode(){return this.debugMode}setDebugMode(e){this.debugMode=e}profile(e,n){if(!this.debugMode)return e();const r=performance.now(),i=e(),s=performance.now();return n(s-r),i}executeInDebugMode(e){if(!this.debugMode)return;const n=new Error().stack||"";e(n)}rebuildIndices(){this.indicesOutdated=!0,this.rebuildIndicesOncePerTick()}rebuildAllIndices(){this.indexProviders.forEach(e=>e.rebuild(this.memoryArray())),this.indicesOutdated=!1}getItemAndIndex(e){const n=this.indicesOutdated?{matched:!1,positions:[],optimizedSelector:e}:Ie(this.indexProviders,e),i=(n.matched?n.positions.map(o=>this.memoryArray()[o]):this.memory()).find(o=>kt(o,e)),s=n.matched&&n.positions.find(o=>this.memoryArray()[o]===i)||this.memory().findIndex(o=>o===i);if(i==null)return{item:null,index:-1};if(s===-1)throw new Error("Cannot resolve index for item");return{item:i,index:s}}memory(){return this.options.memory}memoryArray(){return this.memory().map(e=>e)}transform(e){return this.options.transform?this.options.transform(e):e}getItems(e){return this.profile(()=>{const n=e&&!this.indicesOutdated?Ie(this.indexProviders,e):{matched:!1,positions:[],optimizedSelector:e},r=o=>n.optimizedSelector==null||Object.keys(n.optimizedSelector).length<=0?!0:kt(o,n.optimizedSelector);if(!n.matched)return this.memory().filter(r);const i=this.memoryArray();return n.positions.map(o=>i[o]).filter(r)},n=>this.executeInDebugMode(r=>this.emit("_debug.getItems",r,e,n)))}find(e,n){if(e!==void 0&&(!e||typeof e!="object"))throw new Error("Invalid selector");const r=new Yr(()=>this.getItems(e),Object.assign(Object.assign({reactive:this.options.reactivity},n),{transform:this.transform.bind(this),bindEvents:i=>{const s=Kt(i,!0);return this.addListener("persistence.received",s),this.addListener("added",s),this.addListener("changed",s),this.addListener("removed",s),()=>{this.removeListener("persistence.received",s),this.removeListener("added",s),this.removeListener("changed",s),this.removeListener("removed",s)}}}));return this.executeInDebugMode(i=>this.emit("_debug.find",i,e,n,r)),r}findOne(e,n){const i=this.find(e,Object.assign({limit:1},n)).fetch()[0]||void 0;return this.executeInDebugMode(s=>this.emit("_debug.findOne",s,e,n,i)),i}insert(e){if(!e)throw new Error("Invalid item");const n=Object.assign({id:zr()},e);if(this.idIndex.has(B(n.id)))throw new Error("Item with same id already exists");this.memory().push(n);const r=this.memory().findIndex(i=>i===n);return this.idIndex.set(B(n.id),new Set([r])),this.rebuildIndices(),this.emit("added",n),this.executeInDebugMode(i=>this.emit("_debug.insert",i,n)),n.id}updateOne(e,n){if(!e)throw new Error("Invalid selector");if(!n)throw new Error("Invalid modifier");const{item:r,index:i}=this.getItemAndIndex(e);if(r==null)return 0;const s=qt(Object.assign({},r),n),o=this.findOne({id:s.id},{reactive:!1});if(!Ke(o,Object.assign(Object.assign({},o),{id:s.id})))throw new Error("Item with same id already exists");return this.memory().splice(i,1,s),this.rebuildIndices(),this.emit("changed",s),this.executeInDebugMode(c=>this.emit("_debug.updateOne",c,e,n)),1}updateMany(e,n){if(!e)throw new Error("Invalid selector");if(!n)throw new Error("Invalid modifier");const r=this.getItems(e),i=[];return r.forEach(s=>{const{index:o}=this.getItemAndIndex({id:s.id});if(o===-1)throw new Error("Cannot resolve index for item");const c=qt(s,n);this.memory().splice(o,1,c),i.push(c)}),this.rebuildIndices(),i.forEach(s=>{this.emit("changed",s)}),this.executeInDebugMode(s=>this.emit("_debug.updateMany",s,e,n)),i.length}removeOne(e){if(!e)throw new Error("Invalid selector");const{item:n,index:r}=this.getItemAndIndex(e);return this.executeInDebugMode(i=>this.emit("_debug.removeOne",i,e)),n==null?0:(this.memory().splice(r,1),this.rebuildIndices(),this.emit("removed",n),1)}removeMany(e){if(!e)throw new Error("Invalid selector");const n=this.getItems(e);return n.forEach(r=>{const i=this.memory().findIndex(s=>s===r);if(i===-1)throw new Error("Cannot resolve index for item");this.memory().splice(i,1),this.rebuildIndices()}),n.forEach(r=>{this.emit("removed",r)}),this.executeInDebugMode(r=>this.emit("_debug.removeMany",r,e)),n.length}}F.collections=[],F.debugMode=!1,F.enableDebugMode=()=>{F.debugMode=!0,F.collections.forEach(t=>{t.setDebugMode(!0)})};const en=F;function ti(t){return t}function tn(t){const e=`signaldb-collection-${t}`;function n(){return JSON.parse(localStorage.getItem(e)||"[]")}return{async load(){const r=n();return Promise.resolve({items:r})},async save(r,{added:i,modified:s,removed:o}){const c=n();return i.forEach(u=>{c.push(u)}),s.forEach(u=>{const a=c.findIndex(({id:f})=>f===u.id);/* istanbul ignore if -- @preserve */if(a===-1)throw new Error(`Item with ID ${u.id} not found`);c[a]=u}),o.forEach(u=>{const a=c.findIndex(({id:f})=>f===u.id);/* istanbul ignore if -- @preserve */if(a===-1)throw new Error(`Item with ID ${u.id} not found`);c.splice(a,1)}),localStorage.setItem(e,JSON.stringify(c)),Promise.resolve()},async register(){return Promise.resolve()}}}function nn(t){let e=null;async function n(){const r=await import("fs");if(!await r.promises.access(t).then(()=>!0).catch(()=>!1))return[];const s=await r.promises.readFile(t,"utf8").catch(o=>{/* istanbul ignore next -- @preserve */if(o.code==="ENOENT")return"[]";/* istanbul ignore next -- @preserve */throw o});return JSON.parse(s)}return{async register(r){if(typeof window<"u")throw new Error("Filesystem adapter is not supported in the browser");const i=await import("fs");await i.promises.access(t).then(()=>!0).catch(()=>!1)||await i.promises.writeFile(t,"[]"),i.watch(t,{encoding:"utf8"},()=>{r()})},async load(){if(typeof window<"u")throw new Error("Filesystem adapter is not supported in the browser");return e&&await e,{items:await n()}},async save(r,{added:i,modified:s,removed:o}){if(typeof window<"u")throw new Error("Filesystem adapter is not supported in the browser");e&&await e,e=n().then(c=>{const u=c.slice();return i.forEach(a=>{u.push(a)}),s.forEach(a=>{const f=u.findIndex(({id:l})=>l===a.id);/* istanbul ignore if -- @preserve */if(f===-1)throw new Error(`Item with ID ${a.id} not found`);u[f]=a}),o.forEach(a=>{const f=u.findIndex(({id:l})=>l===a.id);/* istanbul ignore if -- @preserve */if(f===-1)throw new Error(`Item with ID ${a.id} not found`);u.splice(f,1)}),u}).then(async c=>{await(await import("fs")).promises.writeFile(t,JSON.stringify(c))}).then(()=>{e=null}),await e}}}function ni(t){return typeof window>"u"?nn(`persistent-collection-${t}.json`):tn(t)}class ri extends en{constructor(e,n){super(Object.assign({persistence:ni(e)},n))}}function ii(t){return t}function si(t){return t}w.Collection=en,w.PersistentCollection=ri,w.createFilesystemAdapter=nn,w.createIndex=Zr,w.createIndexProvider=Br,w.createLocalStorageAdapter=tn,w.createMemoryAdapter=ii,w.createPersistenceAdapter=ti,w.createReactivityAdapter=si,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
(function(w,G){typeof exports=="object"&&typeof module<"u"?G(exports):typeof define=="function"&&define.amd?define(["exports"],G):(w=typeof globalThis<"u"?globalThis:w||self,G(w.SignalDB={}))})(this,function(w){"use strict";var G={exports:{}},Z=typeof Reflect=="object"?Reflect:null,We=Z&&typeof Z.apply=="function"?Z.apply:function(e,n,r){return Function.prototype.apply.call(e,n,r)},he;Z&&typeof Z.ownKeys=="function"?he=Z.ownKeys:Object.getOwnPropertySymbols?he=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:he=function(e){return Object.getOwnPropertyNames(e)};function rn(t){console&&console.warn&&console.warn(t)}var Ye=Number.isNaN||function(e){return e!==e};function g(){g.init.call(this)}G.exports=g,G.exports.once=un,g.EventEmitter=g,g.prototype._events=void 0,g.prototype._eventsCount=0,g.prototype._maxListeners=void 0;var Qe=10;function pe(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return Qe},set:function(t){if(typeof t!="number"||t<0||Ye(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Qe=t}}),g.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},g.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Ye(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};function Xe(t){return t._maxListeners===void 0?g.defaultMaxListeners:t._maxListeners}g.prototype.getMaxListeners=function(){return Xe(this)},g.prototype.emit=function(e){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);var i=e==="error",s=this._events;if(s!==void 0)i=i&&s.error===void 0;else if(!i)return!1;if(i){var o;if(n.length>0&&(o=n[0]),o instanceof Error)throw o;var c=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw c.context=o,c}var u=s[e];if(u===void 0)return!1;if(typeof u=="function")We(u,this,n);else for(var a=u.length,f=tt(u,a),r=0;r<a;++r)We(f[r],this,n);return!0};function Be(t,e,n,r){var i,s,o;if(pe(n),s=t._events,s===void 0?(s=t._events=Object.create(null),t._eventsCount=0):(s.newListener!==void 0&&(t.emit("newListener",e,n.listener?n.listener:n),s=t._events),o=s[e]),o===void 0)o=s[e]=n,++t._eventsCount;else if(typeof o=="function"?o=s[e]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),i=Xe(t),i>0&&o.length>i&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=o.length,rn(c)}return t}g.prototype.addListener=function(e,n){return Be(this,e,n,!1)},g.prototype.on=g.prototype.addListener,g.prototype.prependListener=function(e,n){return Be(this,e,n,!0)};function sn(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function He(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=sn.bind(r);return i.listener=n,r.wrapFn=i,i}g.prototype.once=function(e,n){return pe(n),this.on(e,He(this,e,n)),this},g.prototype.prependOnceListener=function(e,n){return pe(n),this.prependListener(e,He(this,e,n)),this},g.prototype.removeListener=function(e,n){var r,i,s,o,c;if(pe(n),i=this._events,i===void 0)return this;if(r=i[e],r===void 0)return this;if(r===n||r.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||n));else if(typeof r!="function"){for(s=-1,o=r.length-1;o>=0;o--)if(r[o]===n||r[o].listener===n){c=r[o].listener,s=o;break}if(s<0)return this;s===0?r.shift():on(r,s),r.length===1&&(i[e]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",e,c||n)}return this},g.prototype.off=g.prototype.removeListener,g.prototype.removeAllListeners=function(e){var n,r,i;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[e]),this;if(arguments.length===0){var s=Object.keys(r),o;for(i=0;i<s.length;++i)o=s[i],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=r[e],typeof n=="function")this.removeListener(e,n);else if(n!==void 0)for(i=n.length-1;i>=0;i--)this.removeListener(e,n[i]);return this};function Ze(t,e,n){var r=t._events;if(r===void 0)return[];var i=r[e];return i===void 0?[]:typeof i=="function"?n?[i.listener||i]:[i]:n?cn(i):tt(i,i.length)}g.prototype.listeners=function(e){return Ze(this,e,!0)},g.prototype.rawListeners=function(e){return Ze(this,e,!1)},g.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):et.call(t,e)},g.prototype.listenerCount=et;function et(t){var e=this._events;if(e!==void 0){var n=e[t];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}g.prototype.eventNames=function(){return this._eventsCount>0?he(this._events):[]};function tt(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function on(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function cn(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}function un(t,e){return new Promise(function(n,r){function i(o){t.removeListener(e,s),r(o)}function s(){typeof t.removeListener=="function"&&t.removeListener("error",i),n([].slice.call(arguments))}nt(t,e,s,{once:!0}),e!=="error"&&an(t,i,{once:!0})})}function an(t,e,n){typeof t.on=="function"&&nt(t,"error",e,n)}function nt(t,e,n,r){if(typeof t.on=="function")r.once?t.once(e,n):t.on(e,n);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(s){r.once&&t.removeEventListener(e,i),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}var fn=G.exports;class ln extends fn.EventEmitter{}class V extends Error{}const dn=2147483647,hn=-2147483648,pn=Number.MAX_SAFE_INTEGER,mn=Number.MIN_SAFE_INTEGER,T=Symbol("missing"),rt=Object.freeze(new Error("mingo: cycle detected while processing object/array")),gn=Object.getPrototypeOf([]),it=Object.getPrototypeOf({}),yn="[object Object]",On=/^\[object ([a-zA-Z0-9]+)\]$/;class we{}class _e{}const J=t=>t===null?we:t===void 0?_e:t.constructor,oe=t=>{const e=wn(t);let n=0,r=e.length;for(;r;)n=(n<<5)-n^e.charCodeAt(--r);return n>>>0},st=new Set(["null","undefined","boolean","number","string","date","regexp"]),ot=new Set([_e,we,Boolean,String,Number]),ce=t=>t.toString(),P=t=>`${J(t).name}[${t.toString()}]`,W=new Map([[Number,ce],[Boolean,ce],[RegExp,ce],[Function,ce],[Symbol,ce],[Date,t=>t.toISOString()],[String,JSON.stringify],[we,t=>"null"],[_e,t=>"undefined"],[Int8Array,P],[Uint8Array,P],[Uint8ClampedArray,P],[Int16Array,P],[Uint16Array,P],[Int32Array,P],[Uint32Array,P],[Float32Array,P],[Float64Array,P]]);typeof BigInt<"u"&&W.set(BigInt,t=>"0x"+t.toString(16)),typeof BigInt64Array<"u"&&W.set(BigInt64Array,P),typeof BigUint64Array<"u"&&W.set(BigUint64Array,P);const vn={null:0,undefined:0,number:1,string:2,object:3,array:4,boolean:5,date:6,regexp:7,function:8},L=(t,e)=>{t===T&&(t=void 0),e===T&&(e=void 0);const[n,r]=[t,e].map(i=>vn[ue(i).toLowerCase()]);return n!==r?n-r:n===1||n===2||n===6?t<e?-1:t>e?1:0:D(t,e)?0:t<e?-1:t>e?1:0};function v(t,e){if(!t)throw new V(e)}const bn=t=>{const e=Object.getPrototypeOf(J(t));return e&&e.name==="TypedArray"},xe=t=>{if(ot.has(J(t)))return t;const e=new Set,n=r=>{if(e.has(r))throw rt;const i=J(r);if(ot.has(i))return r;try{if(b(r))return e.add(r),r.map(n);if(O(r)){e.add(r);const s={};for(const o in r)s[o]=n(r[o]);return s}}finally{e.delete(r)}return i===Date||i===RegExp||bn(r)?new i(r):r};return n(t)},ue=t=>On.exec(Object.prototype.toString.call(t))[1],Ae=t=>typeof t=="boolean",k=t=>typeof t=="string",A=t=>!isNaN(t)&&typeof t=="number",b=Array.isArray,O=t=>{if(!t)return!1;const e=Object.getPrototypeOf(t);return(e===it||e===null)&&yn===Object.prototype.toString.call(t)},me=t=>t===Object(t),Se=t=>t instanceof Date,ge=t=>t instanceof RegExp,ae=t=>typeof t=="function",$=t=>t==null,ee=(t,e)=>t.includes(e),ct=(t,e)=>!ee(t,e),te=(t,e=!0)=>!!t||e&&t==="",ne=t=>$(t)||k(t)&&!t||t instanceof Array&&t.length===0||O(t)&&Object.keys(t).length===0,ut=t=>t===T,re=t=>t instanceof Array?t:[t],S=(t,e)=>!!t&&Object.prototype.hasOwnProperty.call(t,e),$n=(t,e)=>O(t)&&O(e)||b(t)&&b(e);function je(t,e,n){if(n=n||{flatten:!1},ut(t)||$(t))return e;if(ut(e)||$(e))return t;if(!$n(t,e)){if(n.skipValidation)return e||t;throw Error("mismatched types. must both be array or object")}if(n.skipValidation=!0,b(t)){const r=t,i=e;if(n.flatten){let s=0,o=0;for(;s<r.length&&o<i.length;)r[s]=je(r[s++],i[o++],n);for(;o<i.length;)r.push(e[o++])}else fe(r,i)}else for(const r in e)t[r]=je(t[r],e[r],n);return t}function Me(t,e=oe){const n=new Map;return t.forEach((r,i)=>{const s=ft(r,e);n.has(s)?n.get(s).some(o=>D(t[o],r))||n.get(s).push(i):n.set(s,[i])}),n}function Le(t,e=oe){if(t.some(c=>c.length==0))return[];if(t.length===1)return Array.from(t);const n=_n(t.map((c,u)=>[u,c.length]),c=>c[1]),r=t[n[0][0]],i=Me(r,e),s=new Map,o=new Array;return i.forEach((c,u)=>{const a=c.map(d=>r[d]),f=a.map(d=>0),l=a.map(d=>[n[0][0],0]);let h=!1;for(let d=1;d<t.length;d++){const[p,y]=n[d],N=t[p];if(s.has(d)||s.set(d,Me(N)),s.get(d).has(u)){const x=s.get(d).get(u).map(H=>N[H]);h=a.map((H,de)=>x.some((oi,ci)=>{const ui=f[de];return D(H,oi)&&(f[de]++,p<l[de][0]&&(l[de]=[p,s.get(d).get(u)[ci]])),ui<f[de]})).some(Boolean)}if(!h)return}h&&fe(o,f.map((d,p)=>d===t.length-1?[a[p],l[p]]:T).filter(d=>d!==T))}),o.sort((c,u)=>{const[a,[f,l]]=c,[h,[d,p]]=u,y=L(f,d);return y!==0?y:L(l,p)}).map(c=>c[0])}function at(t,e=0){const n=new Array;function r(i,s){for(let o=0,c=i.length;o<c;o++)b(i[o])&&(s>0||s<0)?r(i[o],Math.max(-1,s-1)):n.push(i[o])}return r(t,e),n}const En=t=>{let[e,n]=[Object.getPrototypeOf(t),Object.getOwnPropertyNames(t)],r=e;for(;!n.length&&e!==it&&e!==gn;)r=e,n=Object.getOwnPropertyNames(e),e=Object.getPrototypeOf(e);const i={};return n.forEach(s=>i[s]=t[s]),[i,r]};function D(t,e){const n=[[t,e]];for(;n.length>0;){if([t,e]=n.pop(),t===e)continue;const r=J(t);if(r!==J(e)||ae(t))return!1;if(W.has(r)){const i=W.get(r);if(i(t)!==i(e))return!1;continue}if(r===Array||r===Object){const i=Object.keys(t),s=Object.keys(e);if(i.length!==s.length||new Set(i.concat(s)).size!=i.length)return!1;for(const o of i)n.push([t[o],e[o]]);continue}return!1}return!n.length}function In(t,e=oe){const n=t.map(r=>T);return Me(t,e).forEach((r,i)=>{r.forEach(s=>n[s]=t[s])}),n.filter(r=>r!==T)}function wn(t){const e=new Set,n=r=>{const i=J(r);if(W.has(i))return W.get(i)(r);const s=i===Object?"":i.name;if(ae(r.toJSON))return`${s}(${JSON.stringify(r)})`;if(e.has(r))throw rt;e.add(r);try{if(i===Array)return"["+r.map(n).join(",")+"]";if(i!==Object){const[c,u]=En(r);if(b(r))return`${s}${n([...r,c])}`;r=c}const o=Object.keys(r);return o.sort(),`${s}{`+o.map(c=>`${c}:${n(r[c])}`).join(",")+"}"}finally{e.delete(r)}};return n(t)}function ft(t,e){return e=e||oe,$(t)?null:e(t).toString()}function _n(t,e,n=L){if(ne(t))return t;const r=new Array,i=new Array;for(let s=0;s<t.length;s++){const o=t[s],c=e(o,s);$(c)?i.push(o):r.push([c,o])}return r.sort((s,o)=>n(s[0],o[0])),fe(i,r.map(s=>s[1]))}function xn(t,e,n=oe){if(t.length<1)return new Map;const r=new Map,i=new Map;for(let s=0;s<t.length;s++){const o=t[s],c=e(o,s),u=ft(c,n);if(u===null)i.has(null)?i.get(null).push(o):i.set(null,[o]);else{const a=r.has(u)?r.get(u).find(f=>D(f,c)):null;$(a)?(i.set(c,[o]),r.has(u)?r.get(u).push(c):r.set(u,[c])):i.get(a).push(o)}}return i}const Ne=5e4;function fe(t,...e){return t instanceof Array?e.reduce((n,r)=>{let i=Math.ceil(r.length/Ne),s=0;for(;i-- >0;)Array.prototype.push.apply(n,r.slice(s,s+Ne)),s+=Ne;return n},t):e.filter(me).reduce((n,r)=>(Object.assign(n,r),n),t)}function Pe(t,e){return me(t)?t[e]:void 0}function An(t,e){if(e<1)return t;for(;e--&&t.length===1;)t=t[0];return t}function z(t,e,n){let r=0;function i(o,c){let u=o;for(let a=0;a<c.length;a++){const f=c[a];if(/^\d+$/.exec(f)===null&&u instanceof Array){if(a===0&&r>0)break;r+=1;const h=c.slice(a);u=u.reduce((d,p)=>{const y=i(p,h);return y!==void 0&&d.push(y),d},[]);break}else u=Pe(u,f);if(u===void 0)break}return u}const s=st.has(ue(t).toLowerCase())?t:i(t,e.split("."));return s instanceof Array&&(n!=null&&n.unwrapArray)?An(s,r):s}function ye(t,e,n){const r=e.split("."),i=r[0],s=r.slice(1).join("."),o=/^\d+$/.exec(i)!==null,c=r.length>1;let u,a;if(t instanceof Array)if(o)u=Pe(t,Number(i)),c&&(u=ye(u,s,n)),u=[u];else{u=[];for(const f of t)a=ye(f,e,n),n!=null&&n.preserveMissing?(a===void 0&&(a=T),u.push(a)):a!==void 0&&u.push(a)}else{if(a=Pe(t,i),c&&(a=ye(a,s,n)),a===void 0)return;u=n!=null&&n.preserveKeys?Object.assign({},t):{},u[i]=a}return u}function Ce(t){if(t instanceof Array)for(let e=t.length-1;e>=0;e--)t[e]===T?t.splice(e,1):Ce(t[e]);else if(O(t))for(const e in t)S(t,e)&&Ce(t[e])}const lt=/^\d+$/;function le(t,e,n,r){const i=e.split("."),s=i[0],o=i.slice(1).join(".");if(i.length===1)(O(t)||b(t)&&lt.test(s))&&n(t,s);else{r!=null&&r.buildGraph&&$(t[s])&&(t[s]={});const c=t[s];if(!c)return;const u=!!(i.length>1&&lt.test(i[1]));c instanceof Array&&(r!=null&&r.descendArray)&&!u?c.forEach(a=>le(a,o,n,r)):le(c,o,n,r)}}function Sn(t,e,n){le(t,e,(r,i)=>{r[i]=ae(n)?n(r[i]):n},{buildGraph:!0})}function dt(t,e,n){le(t,e,(r,i)=>{if(r instanceof Array){if(/^\d+$/.test(i))r.splice(parseInt(i),1);else if(n&&n.descendArray)for(const s of r)O(s)&&delete s[i]}else O(r)&&delete r[i]},n)}const jn=/^\$[a-zA-Z0-9_]+$/;function Y(t){return jn.test(t)}function ht(t){if(st.has(ue(t).toLowerCase()))return ge(t)?{$regex:t}:{$eq:t};if(me(t)){if(!Object.keys(t).some(Y))return{$eq:t};if(S(t,"$regex")){const n=Object.assign({},t);return n.$regex=new RegExp(t.$regex,t.$options),delete n.$options,n}}return t}var q;(function(t){t.CLONE_ALL="CLONE_ALL",t.CLONE_INPUT="CLONE_INPUT",t.CLONE_OUTPUT="CLONE_OUTPUT",t.CLONE_OFF="CLONE_OFF"})(q||(q={}));class Q{constructor(e,n,r,i=Date.now()){this._opts=e,this._root=n,this._local=r,this.timestamp=i,this.update(n,r)}static init(e,n,r){return e instanceof Q?new Q(e._opts,$(e.root)?n:e.root,Object.assign({},e.local,r)):new Q(e,n,r)}update(e,n){var r;return this._root=e,this._local=n&&Object.assign({},n,{variables:Object.assign({},(r=this._local)===null||r===void 0?void 0:r.variables,n==null?void 0:n.variables)}),this}getOptions(){return Object.freeze(Object.assign(Object.assign({},this._opts),{context:K.from(this._opts.context)}))}get root(){return this._root}get local(){return this._local}get idKey(){return this._opts.idKey}get collation(){var e;return(e=this._opts)===null||e===void 0?void 0:e.collation}get processingMode(){var e;return((e=this._opts)===null||e===void 0?void 0:e.processingMode)||q.CLONE_OFF}get useStrictMode(){var e;return(e=this._opts)===null||e===void 0?void 0:e.useStrictMode}get scriptEnabled(){var e;return(e=this._opts)===null||e===void 0?void 0:e.scriptEnabled}get useGlobalContext(){var e;return(e=this._opts)===null||e===void 0?void 0:e.useGlobalContext}get hashFunction(){var e;return(e=this._opts)===null||e===void 0?void 0:e.hashFunction}get collectionResolver(){var e;return(e=this._opts)===null||e===void 0?void 0:e.collectionResolver}get jsonSchemaValidator(){var e;return(e=this._opts)===null||e===void 0?void 0:e.jsonSchemaValidator}get variables(){var e;return(e=this._opts)===null||e===void 0?void 0:e.variables}get context(){var e;return(e=this._opts)===null||e===void 0?void 0:e.context}}function Oe(t){return t instanceof Q?t.getOptions():Object.freeze(Object.assign(Object.assign({idKey:"_id",scriptEnabled:!0,useStrictMode:!0,useGlobalContext:!0,processingMode:q.CLONE_OFF},t),{context:t!=null&&t.context?K.from(t==null?void 0:t.context):K.init({})}))}var m;(function(t){t.ACCUMULATOR="accumulator",t.EXPRESSION="expression",t.PIPELINE="pipeline",t.PROJECTION="projection",t.QUERY="query",t.WINDOW="window"})(m||(m={}));class K{constructor(e){this.operators={[m.ACCUMULATOR]:{},[m.EXPRESSION]:{},[m.PIPELINE]:{},[m.PROJECTION]:{},[m.QUERY]:{},[m.WINDOW]:{}};for(const[n,r]of Object.entries(e))this.addOperators(n,r)}static init(e={}){return new K(e)}static from(e){return new K(e.operators)}addOperators(e,n){for(const[r,i]of Object.entries(n))this.getOperator(e,r)||(this.operators[e][r]=i);return this}addAccumulatorOps(e){return this.addOperators(m.ACCUMULATOR,e)}addExpressionOps(e){return this.addOperators(m.EXPRESSION,e)}addQueryOps(e){return this.addOperators(m.QUERY,e)}addPipelineOps(e){return this.addOperators(m.PIPELINE,e)}addProjectionOps(e){return this.addOperators(m.PROJECTION,e)}addWindowOps(e){return this.addOperators(m.WINDOW,e)}getOperator(e,n){return e in this.operators&&this.operators[e][n]||null}}const X=K.init();function ve(t,e){for(const[n,r]of Object.entries(e)){v(ae(r)&&Y(n),`'${n}' is not a valid operator`);const i=B(t,n,null);v(!i||r===i,`${n} already exists for '${t}' operators. Cannot change operator function once registered.`)}switch(t){case m.ACCUMULATOR:X.addAccumulatorOps(e);break;case m.EXPRESSION:X.addExpressionOps(e);break;case m.PIPELINE:X.addPipelineOps(e);break;case m.PROJECTION:X.addProjectionOps(e);break;case m.QUERY:X.addQueryOps(e);break;case m.WINDOW:X.addWindowOps(e);break}}function B(t,e,n){const{context:r,useGlobalContext:i}=n||{},s=r?r.getOperator(t,e):null;return!s&&i?X.getOperator(t,e):s}const pt={$$ROOT(t,e,n){return n.root},$$CURRENT(t,e,n){return t},$$REMOVE(t,e,n){},$$NOW(t,e,n){return new Date(n.timestamp)}},Re={$$KEEP(t,e,n){return t},$$PRUNE(t,e,n){},$$DESCEND(t,e,n){if(!S(e,"$cond"))return t;let r;for(const[i,s]of Object.entries(t))if(me(s)){if(s instanceof Array){const o=[];for(let c of s)O(c)&&(c=mt(c,e,n.update(c))),$(c)||o.push(c);r=o}else r=mt(s,e,n.update(s));$(r)?delete t[i]:t[i]=r}return t}};function E(t,e,n,r){var i;const s=Q.init(r,t);if(n=n||"",Y(n)){const o=B(m.EXPRESSION,n,r);if(o)return o(t,e,s);const c=B(m.ACCUMULATOR,n,r);if(c)return t instanceof Array||(t=E(t,e,null,s),e=null),v(t instanceof Array,`'${n}' target must be an array.`),c(t,e,s.update(null,s.local));throw new V(`operator '${n}' is not registered`)}if(k(e)&&e.length>0&&e[0]==="$"){if(S(Re,e))return e;let o=s.root;const c=e.split(".");if(S(pt,c[0]))o=pt[c[0]](t,null,s),e=e.slice(c[0].length+1);else if(c[0].slice(0,2)==="$$"){o=Object.assign({},s.variables,{this:t},(i=s.local)===null||i===void 0?void 0:i.variables);const u=c[0].slice(2);v(S(o,u),`Use of undefined variable: ${u}`),e=e.slice(2)}else e=e.slice(1);return e===""?o:z(o,e)}if(b(e))return e.map(o=>E(t,o,null,s));if(O(e)){const o={};for(const[c,u]of Object.entries(e))if(o[c]=E(t,u,c,s),[m.EXPRESSION,m.ACCUMULATOR].some(a=>!!B(a,c,r)))return v(Object.keys(e).length===1,"Invalid aggregation expression '"+JSON.stringify(e)+"'"),o[c];return o}return e}function mt(t,e,n){const r=E(t,e,null,n);return S(Re,r)?Re[r](t,e,n):r}const Te=Object.freeze(Object.defineProperty({__proto__:null,$and:(t,e,n)=>{const r=E(t,e,null,n);return te(r,n.useStrictMode)&&r.every(i=>te(i,n.useStrictMode))},$not:(t,e,n)=>{const r=re(e);if(r.length==0)return!1;if(r.length==1)return!E(t,r[0],null,n);throw"Expression $not takes exactly 1 argument"},$or:(t,e,n)=>{const r=E(t,e,null,n),i=n.useStrictMode;return te(r,i)&&r.some(s=>te(s,i))}},Symbol.toStringTag,{value:"Module"})),Mn=(t,e,n)=>{const r=E(t,e,null,n);return r[0]>r[1]?1:r[0]<r[1]?-1:0};function ie(t){return t instanceof gt?t:new gt(t)}function Ln(...t){let e=0;return ie(()=>{for(;e<t.length;){const n=t[e].next();if(!n.done)return n;e++}return{done:!0}})}function Nn(t){return!!t&&typeof t=="object"&&(t==null?void 0:t.next)instanceof Function}function Pn(t,e){const n=t.slice(e+1);t.splice(e),Array.prototype.push.apply(t,n)}const ke=new Error;var C;(function(t){t[t.MAP=0]="MAP",t[t.FILTER=1]="FILTER",t[t.TAKE=2]="TAKE",t[t.DROP=3]="DROP"})(C||(C={}));function Cn(t,e,n){let r=!1,i=-1,s=0;return function(o){try{e:for(;!r;){let c=t();i++;let u=-1;const a=e.length;let f=!1;for(;++u<a;){const l=e[u];switch(l.action){case C.MAP:c=l.func(c,i);break;case C.FILTER:if(!l.func(c,i))continue e;break;case C.TAKE:--l.count,l.count||(f=!0);break;case C.DROP:--l.count,l.count||Pn(e,u);continue e;default:break e}}if(r=f,o)n[s++]=c;else return{value:c,done:!1}}}catch(c){if(c!==ke)throw c}return r=!0,{done:r}}}class gt{constructor(e){this.iteratees=[],this.yieldedValues=[],this.isDone=!1;let n;if(e instanceof Function&&(e={next:e}),Nn(e)){const r=e;n=()=>{const i=r.next();if(i.done)throw ke;return i.value}}else if(e instanceof Array){const r=e,i=r.length;let s=0;n=()=>{if(s<i)return r[s++];throw ke}}else if(!(e instanceof Function))throw new V("Lazy must be initialized with an array, generator, or function.");this.getNext=Cn(n,this.iteratees,this.yieldedValues)}push(e,n){return typeof n=="function"?this.iteratees.push({action:e,func:n}):typeof n=="number"&&this.iteratees.push({action:e,count:n}),this}next(){return this.getNext()}map(e){return this.push(C.MAP,e)}filter(e){return this.push(C.FILTER,e)}take(e){return e>0?this.push(C.TAKE,e):this}drop(e){return e>0?this.push(C.DROP,e):this}transform(e){const n=this;let r;return ie(()=>(r||(r=ie(e(n.value()))),r.next()))}value(){return this.isDone||(this.isDone=this.getNext(!0).done),this.yieldedValues}each(e){for(;;){const n=this.next();if(n.done)break;if(e(n.value)===!1)return!1}return!0}reduce(e,n){let r=this.next();for(n===void 0&&!r.done&&(n=r.value,r=this.next());!r.done;)n=e(n,r.value),r=this.next();return n}size(){return this.reduce((e,n)=>++e,0)}[Symbol.iterator](){return this}}class Rn{constructor(e,n){this.pipeline=e,this.options=Oe(n)}stream(e){let n=ie(e);const r=this.options.processingMode;(r==q.CLONE_ALL||r==q.CLONE_INPUT)&&n.map(xe);const i=new Array;if(!ne(this.pipeline))for(const s of this.pipeline){const o=Object.keys(s),c=o[0],u=B(m.PIPELINE,c,this.options);v(o.length===1&&!!u,`invalid pipeline operator ${c}`),i.push(c),n=u(n,s[c],this.options)}return(r==q.CLONE_OUTPUT||r==q.CLONE_ALL&&Le([["$group","$unwind"],i]).length)&&n.map(xe),n}run(e){return this.stream(e).value()}}let Tn=class{constructor(e,n,r,i){this.source=e,this.predicate=n,this.projection=r,this.options=i,this.operators=[],this.result=null,this.buffer=[]}fetch(){return this.result?this.result:(O(this.projection)&&this.operators.push({$project:this.projection}),this.result=ie(this.source).filter(this.predicate),this.operators.length>0&&(this.result=new Rn(this.operators,this.options).stream(this.result)),this.result)}fetchAll(){const e=ie([...this.buffer]);return this.buffer=[],Ln(e,this.fetch())}all(){return this.fetchAll().value()}count(){return this.all().length}skip(e){return this.operators.push({$skip:e}),this}limit(e){return this.operators.push({$limit:e}),this}sort(e){return this.operators.push({$sort:e}),this}collation(e){return this.options=Object.assign(Object.assign({},this.options),{collation:e}),this}next(){if(this.buffer.length>0)return this.buffer.pop();const e=this.fetch().next();if(!e.done)return e.value}hasNext(){if(this.buffer.length>0)return!0;const e=this.fetch().next();return e.done?!1:(this.buffer.push(e.value),!0)}map(e){return this.all().map(e)}forEach(e){this.all().forEach(e)}[Symbol.iterator](){return this.fetchAll()}};class R{constructor(e,n){this.condition=e,this.options=Oe(n),this.compiled=[],this.compile()}compile(){v(O(this.condition),`query criteria must be an object: ${JSON.stringify(this.condition)}`);const e={};for(const[n,r]of Object.entries(this.condition)){if(n==="$where")Object.assign(e,{field:n,expr:r});else if(ee(["$and","$or","$nor","$expr","$jsonSchema"],n))this.processOperator(n,n,r);else{v(!Y(n),`unknown top level operator: ${n}`);for(const[i,s]of Object.entries(ht(r)))this.processOperator(n,i,s)}e.field&&this.processOperator(e.field,e.field,e.expr)}}processOperator(e,n,r){const i=B(m.QUERY,n,this.options);if(!i)throw new V(`unknown query operator ${n}`);const s=i(e,r,this.options);this.compiled.push(s)}test(e){for(let n=0,r=this.compiled.length;n<r;n++)if(!this.compiled[n](e))return!1;return!0}find(e,n){return new Tn(e,r=>this.test(r),n||{},this.options)}remove(e){return e.reduce((n,r)=>(this.test(r)||n.push(r),n),[])}}function I(t){const e=(n,r,i)=>{const s={unwrapArray:!0},o=Math.max(1,n.split(".").length-1);return c=>{const u=z(c,n,s);return t(u,r,Object.assign(Object.assign({},i),{depth:o}))}};return e.op="query",e}function se(t){return(e,n,r)=>{const i=E(e,n,null,r);return t(...i)}}function De(t,e,n){if(D(t,e)||$(t)&&$(e))return!0;if(t instanceof Array){const r=D.bind(null,e);return t.some(r)||at(t,n==null?void 0:n.depth).some(r)}return!1}function yt(t,e,n){return!De(t,e,n)}function Ot(t,e,n){return $(t)?e.some(r=>r===null):Le([re(t),e],n==null?void 0:n.hashFunction).length>0}function kn(t,e,n){return!Ot(t,e,n)}function vt(t,e,n){return be(t,e,(r,i)=>L(r,i)<0)}function bt(t,e,n){return be(t,e,(r,i)=>L(r,i)<=0)}function $t(t,e,n){return be(t,e,(r,i)=>L(r,i)>0)}function Et(t,e,n){return be(t,e,(r,i)=>L(r,i)>=0)}function Dn(t,e,n){return re(t).some(r=>e.length===2&&r%e[0]===e[1])}function Fn(t,e,n){const r=re(t),i=s=>k(s)&&te(e.exec(s),n==null?void 0:n.useStrictMode);return r.some(i)||at(r,1).some(i)}function Un(t,e,n){return(e===!1||e===0)&&t===void 0||(e===!0||e===1)&&t!==void 0}function zn(t,e,n){if(!b(t)||!b(e)||!t.length||!e.length)return!1;let r=!0;for(const i of e){if(!r)break;O(i)&&ee(Object.keys(i),"$elemMatch")?r=It(t,i.$elemMatch,n):i instanceof RegExp?r=t.some(s=>typeof s=="string"&&i.test(s)):r=t.some(s=>D(i,s))}return r}function qn(t,e,n){return Array.isArray(t)&&t.length===e}function Kn(t){return Y(t)&&["$and","$or","$nor"].indexOf(t)===-1}function It(t,e,n){if(b(t)&&!ne(t)){let r=o=>o,i=e;Object.keys(e).every(Kn)&&(i={temp:e},r=o=>({temp:o}));const s=new R(i,n);for(let o=0,c=t.length;o<c;o++)if(s.test(r(t[o])))return!0}return!1}const wt=t=>t===null,_t=t=>A(t)&&t>=hn&&t<=dn&&t.toString().indexOf(".")===-1,xt=t=>A(t)&&t>=mn&&t<=pn&&t.toString().indexOf(".")===-1,Gn={array:b,bool:Ae,boolean:Ae,date:Se,decimal:A,double:A,int:_t,long:xt,number:A,null:wt,object:O,regex:ge,regexp:ge,string:k,undefined:$,function:t=>{throw new V("unsupported type key `function`.")},1:A,2:k,3:O,4:b,6:$,8:Ae,9:Se,10:wt,11:ge,16:_t,18:xt,19:A};function At(t,e,n){const r=Gn[e];return r?r(t):!1}function Vn(t,e,n){return Array.isArray(e)?e.findIndex(r=>At(t,r))>=0:At(t,e)}function be(t,e,n){return re(t).some(r=>ue(r)===ue(e)&&n(r,e))}const Jn=se(De),Wn=se($t),Yn=se(Et),Qn=se(vt),Xn=se(bt),Bn=se(yt),Fe=Object.freeze(Object.defineProperty({__proto__:null,$cmp:Mn,$eq:Jn,$gt:Wn,$gte:Yn,$lt:Qn,$lte:Xn,$ne:Bn},Symbol.toStringTag,{value:"Module"})),St=(t,e,n)=>{if(ne(e)||!O(e))return t;let r=L;const i=n.collation;return O(i)&&k(i.locale)&&(r=Zn(i)),t.transform(s=>{const o=Object.keys(e);for(const c of o.reverse()){const u=xn(s,f=>z(f,c),n.hashFunction),a=Array.from(u.keys()).sort(r);e[c]===-1&&a.reverse(),s=[],a.reduce((f,l)=>fe(f,u.get(l)),s)}return s})},Hn={1:"base",2:"accent",3:"variant"};function Zn(t){const e={sensitivity:Hn[t.strength||3],caseFirst:t.caseFirst==="off"?"false":t.caseFirst||"false",numeric:t.numericOrdering||!1,ignorePunctuation:t.alternate==="shifted"};(t.caseLevel||!1)===!0&&(e.sensitivity==="base"&&(e.sensitivity="case"),e.sensitivity==="accent"&&(e.sensitivity="variant"));const n=new Intl.Collator(t.locale,e);return(r,i)=>{if(!k(r)||!k(i))return L(r,i);const s=n.compare(r,i);return s<0?-1:s>0?1:0}}const jt=(t,e,n)=>t.take(e),er=(t,e,n)=>{const r=E(t,e,null,n),i=r[0];let s=r[1],o=r[2];return $(o)?s<0?(s=Math.max(0,i.length+s),o=i.length-s+1):(o=s,s=0):(s<0&&(s=Math.max(0,i.length+s)),v(o>0,"Invalid argument for $slice operator. Limit must be a positive number"),o+=s),i.slice(s,o)},Mt=(t,e)=>{const n={};return t.split("").forEach((r,i)=>n[r]=e*(i+1)),n};Object.assign(Object.assign(Object.assign({},Mt("ABCDEFGHIKLM",1)),Mt("NOPQRSTUVWXY",-1)),{Z:0});const Lt={undefined:null,null:null,NaN:NaN,Infinity:new Error,"-Infinity":new Error};function j(t,e=Lt){const n=Object.assign({},Lt,e),r=new Set(Object.keys(n));return(i,s,o)=>{const c=E(i,s,null,o);if(r.has(`${c}`)){const u=n[`${c}`];if(u instanceof Error)throw new V(`cannot apply $${t.name} to -inf, value must in (-inf,inf)`);return u}return t(c)}}j(Math.acos,{Infinity:1/0,0:new Error}),j(Math.acosh,{Infinity:1/0,0:new Error}),j(Math.asin),j(Math.asinh,{Infinity:1/0,"-Infinity":-1/0}),j(Math.atan),j(Math.atanh,{1:1/0,"-1":-1/0}),j(Math.cos),j(Math.cosh,{"-Infinity":1/0,Infinity:1/0});const tr=Math.PI/180;j(t=>t*tr,{Infinity:1/0,"-Infinity":1/0});const nr=180/Math.PI;j(t=>t*nr,{Infinity:1/0,"-Infinity":-1/0}),j(Math.sin),j(Math.sinh,{"-Infinity":-1/0,Infinity:1/0}),j(Math.tan);const Nt=(t,e,n)=>{if(ne(e))return t;let r=Object.keys(e),i=!1;Pt(e,n);const s=n.idKey;if(ee(r,s)){const c=e[s];(c===0||c===!1)&&(r=r.filter(ct.bind(null,[s])),i=r.length==0)}else r.push(s);const o=Q.init(n);return t.map(c=>Ue(c,e,o.update(c),r,i))};function Ue(t,e,n,r,i){let s={},o=!1,c=!1;const u=[];i&&u.push(n.idKey);for(const a of r){let f;const l=e[a];if(a!==n.idKey&&ee([0,!1],l)&&(c=!0),a===n.idKey&&ne(l))f=t[a];else if(k(l))f=E(t,l,a,n);else if(!ee([1,!0],l))if(l instanceof Array)f=l.map(d=>{const p=E(t,d,null,n);return $(p)?null:p});else if(O(l)){const d=l,p=Object.keys(l),y=p.length==1?p[0]:"",N=B(m.PROJECTION,y,n);if(N)y==="$slice"?re(d[y]).every(A)?(f=N(t,d[y],a,n),o=!0):f=E(t,d,a,n):f=N(t,d[y],a,n);else if(Y(y))f=E(t,d[y],y,n);else if(S(t,a)){Pt(d,n);let x=t[a];x instanceof Array?f=x.map(H=>Ue(H,d,n,p,!1)):(x=O(x)?x:t,f=Ue(x,d,n,p,!1))}else f=E(t,l,null,n)}else{u.push(a);continue}const h=ye(t,a,{preserveMissing:!0});h!==void 0&&je(s,h,{flatten:!0}),ct([0,1,!1,!0],l)&&(f===void 0?dt(s,a,{descendArray:!0}):Sn(s,a,f))}if(Ce(s),(o||c||i)&&(s=fe({},t,s),u.length>0))for(const a of u)dt(s,a,{descendArray:!0});return s}function Pt(t,e){const n=[!1,!1];for(const[r,i]of Object.entries(t)){if(r===(e==null?void 0:e.idKey))return;i===0||i===!1?n[0]=!0:(i===1||i===!0)&&(n[1]=!0),v(!(n[0]&&n[1]),"Projection cannot have a mix of inclusion and exclusion.")}}const Ct=(t,e,n)=>t.drop(e),Rt=Object.freeze(Object.defineProperty({__proto__:null,$elemMatch:(t,e,n,r)=>{const i=z(t,n),s=new R(e,r);v(i instanceof Array,"$elemMatch: argument must resolve to array");const o=[];for(let c=0;c<i.length;c++)if(s.test(i[c])){if(r.useStrictMode)return[i[c]];o.push(i[c])}return o.length>0?o:void 0},$slice:(t,e,n,r)=>{const i=z(t,n),s=e;return b(i)?er(t,e instanceof Array?[i,...s]:[i,e],r):i}},Symbol.toStringTag,{value:"Module"})),rr=I(zn),ir=I(It),sr=I(qn),$e=t=>I((e,n,r)=>{let i=0;if(n instanceof Array)for(const s of n)i=i|1<<s;else i=n;return t(e&i,i)}),or=$e((t,e)=>t==0),cr=$e((t,e)=>t==e),ur=$e((t,e)=>t<e),ar=$e((t,e)=>t>0),fr=I(De),lr=I($t),dr=I(Et),hr=I(Ot),pr=I(vt),mr=I(bt),gr=I(yt),yr=I(kn),Or=I(Un),vr=I(Vn);function br(t,e,n){return r=>E(r,e,null,n)}function $r(t,e,n){if(!(n!=null&&n.jsonSchemaValidator))throw new V("Missing option 'jsonSchemaValidator'. Configure to use '$jsonSchema' operator.");const r=n==null?void 0:n.jsonSchemaValidator(e);return i=>r(i)}const Er=I(Dn),Ir=I(Fn);function wr(t,e,n){v(n.scriptEnabled,"$where operator requires 'scriptEnabled' option to be true");const r=e;return v(ae(r),"$where only accepts a Function object"),i=>te(r.call(i),n==null?void 0:n.useStrictMode)}const _r=(t,e,n)=>{v(b(e),"Invalid expression: $and expects value to be an Array.");const r=e.map(i=>new R(i,n));return i=>r.every(s=>s.test(i))},Tt=(t,e,n)=>{v(b(e),"Invalid expression. $or expects value to be an Array");const r=e.map(i=>new R(i,n));return i=>r.some(s=>s.test(i))},ze=Object.freeze(Object.defineProperty({__proto__:null,$all:rr,$and:_r,$bitsAllClear:or,$bitsAllSet:cr,$bitsAnyClear:ur,$bitsAnySet:ar,$elemMatch:ir,$eq:fr,$exists:Or,$expr:br,$gt:lr,$gte:dr,$in:hr,$jsonSchema:$r,$lt:pr,$lte:mr,$mod:Er,$ne:gr,$nin:yr,$nor:(t,e,n)=>{v(b(e),"Invalid expression. $nor expects value to be an array.");const r=Tt("$or",e,n);return i=>!r(i)},$not:(t,e,n)=>{const r={};r[t]=ht(e);const i=new R(r,n);return s=>!i.test(s)},$or:Tt,$regex:Ir,$size:sr,$type:vr,$where:wr},Symbol.toStringTag,{value:"Module"}));ve(m.EXPRESSION,Object.assign(Object.assign({},Te),Fe)),ve(m.PIPELINE,{$project:Nt,$skip:Ct,$limit:jt,$sort:St}),ve(m.PROJECTION,Rt),ve(m.QUERY,ze),K.init().addExpressionOps(Object.assign(Object.assign({},Te),Fe)).addPipelineOps({$project:Nt,$skip:Ct,$limit:jt,$sort:St}).addProjectionOps(Rt).addQueryOps(ze);function kt(t,e){return new R(e).test(t)}const qe=(t,e)=>{switch(t){case"deep":return xe(e);case"copy":return Se(e)?new Date(e):b(e)?[...e]:O(e)?Object.assign({},e):e;default:return e}},xr=/^[a-z]+[a-zA-Z0-9]*$/;function Dt(t){if(!t.includes(".$"))return[{parent:t,selector:t},[]];const e=t.indexOf(".$"),n=t.indexOf("]"),r=t.substring(0,e),i=t.substring(e+3,n);v(i===""||xr.test(i),"The filter <identifier> must begin with a lowercase letter and contain only alphanumeric characters.");const s=t.substring(n+2),[o,c]=s?Dt(s):[];return[{selector:t,parent:r,child:i||"$",next:o},[i,...c||[]].filter(Boolean)]}const _=(t,e,n,r,i)=>{const{parent:s,child:o,next:c}=e;if(!o){let a=!1;return le(t,s,(l,h)=>a=!!r(l,h)||a,i),a}const u=z(t,s);return b(u)?u.map((a,f)=>n[o]&&!n[o].test({[o]:a})?!1:c?_(a,c,n,r,i):r(u,f)).some(Boolean):!1};function M(t,e,n,r){const i=[];for(const[s,o]of Object.entries(t)){const[c,u]=Dt(s);if(!u.length)r(o,c,{})&&i.push(c.parent);else{const a={};e.forEach(l=>{Object.keys(l).forEach(h=>{u.forEach(d=>{(h===d||h.startsWith(d+"."))&&(a[d]=a[d]||{},Object.assign(a[d],{[h]:l[h]}))})})});const f={};for(const[l,h]of Object.entries(a))f[l]=new R(h,n.queryOptions);r(o,c,f)&&i.push(c.parent)}}return i}const Ar=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{const c={$each:[i]};return O(i)&&S(i,"$each")&&Object.assign(c,i),_(t,s,o,(u,a)=>{const f=u[a]||(u[a]=[]);return Le([f,c.$each]).length===c.$each.length?!1:(u[a]=qe(r.cloneMode,In(f.concat(c.$each))),!0)},{buildGraph:!0})}),Sr=new Set(["and","or","xor"]),jr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{const c=Object.keys(i);return v(c.length===1&&Sr.has(c[0]),`Invalid bit operator '${c[0]}'. Must be one of 'and', 'or', or 'xor'.`),_(t,s,o,(u,a)=>{let f=u[a];const l=i[c[0]];if(f!==void 0&&!(A(f)&&A(l)))return!1;switch(f=f||0,c[0]){case"and":u[a]=f&l;break;case"or":u[a]=f|l;break;case"xor":u[a]=f^l;break}return u[a]!==f},{buildGraph:!0})}),Mr=(t,e,n=[],r={})=>{const i=Date.now();return M(e,n,r,(s,o,c)=>_(t,o,c,(u,a)=>(u[a]=i,!0),{buildGraph:!0}))},Lr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{if(!s.child){const c=z(t,s.parent);v(c===void 0||A(c),"cannot apply $inc to a value of non-numeric type")}return _(t,s,o,(c,u)=>(c[u]=(c[u]||(c[u]=0))+i,!0),{buildGraph:!0})}),Nr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>c[u]!==void 0&&L(c[u],i)>-1?!1:(c[u]=i,!0),{buildGraph:!0})),Pr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>c[u]!==void 0&&L(c[u],i)<1?!1:(c[u]=i,!0),{buildGraph:!0})),Cr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>{const a=c[u];return c[u]=c[u]===void 0?0:c[u]*i,c[u]!==a},{buildGraph:!0})),Rr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>{const a=c[u];return v(b(a),`path '${s.selector}' contains an element of non-array type.`),a.length?(i===-1?a.splice(0,1):a.pop(),!0):!1})),Ft=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{const c=!O(i)||Object.keys(i).some(Y),u=new R(c?{k:i}:i,r.queryOptions),a=c?f=>u.test({k:f}):f=>u.test(f);return _(t,s,o,(f,l)=>{const h=f[l],d=new Array;return h.map(y=>{const N=a(y);return N||d.push(y),N}).some(Boolean)?(f[l]=d,!0):!1})}),Tr=(t,e,n=[],r={})=>{const i={};return Object.entries(e).forEach(([s,o])=>{i[s]={$in:o}}),Ft(t,i,n,r)},kr=Object.freeze(["$each","$slice","$sort","$position"]),Dr=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>{const c={$each:[i]};return O(i)&&kr.some(u=>S(i,u))&&Object.assign(c,i),_(t,s,o,(u,a)=>{const f=u[a]||(u[a]=[]),l=f.slice(0,c.$slice||f.length),h=f.length,d=A(c.$position)?c.$position:f.length;if(f.splice(d,0,...qe(r.cloneMode,c.$each)),c.$sort){const p=O(c.$sort)?Object.keys(c.$sort||{}).pop():"",y=p?c.$sort[p]:c.$sort,N=p?x=>z(x,p):x=>x;f.sort((x,H)=>y*L(N(x),N(H)))}return A(c.$slice)&&(c.$slice<0?f.splice(0,f.length+c.$slice):f.splice(c.$slice)),h!=f.length||!D(l,f)},{descendArray:!0,buildGraph:!0})}),Ut=(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>D(c[u],i)?!1:(c[u]=qe(r.cloneMode,i),!0),{buildGraph:!0})),zt=Object.freeze(Object.defineProperty({__proto__:null,$addToSet:Ar,$bit:jr,$currentDate:Mr,$inc:Lr,$max:Nr,$min:Pr,$mul:Cr,$pop:Rr,$pull:Ft,$pullAll:Tr,$push:Dr,$rename:(t,e,n=[],r={})=>{const i=[],s=M(e,n,r,(o,c,u)=>_(t,c,u,(a,f)=>S(a,f)?(i.push(...Ut(t,{[o]:a[f]},n,r)),delete a[f],!0):!1));return Array.from(new Set(s.concat(i)))},$set:Ut,$unset:(t,e,n=[],r={})=>M(e,n,r,(i,s,o)=>_(t,s,o,(c,u)=>S(c,u)?(b(c)?c[u]=null:delete c[u],!0):!1))},Symbol.toStringTag,{value:"Module"}));function Fr(t){return t=Object.assign(Object.assign({},t),{queryOptions:Oe(t.queryOptions)}),t.queryOptions.context.addQueryOps(ze).addExpressionOps(Te).addExpressionOps(Fe),(e,n,r=[],i={},s={})=>{const o=Object.assign({cloneMode:"copy"},t,s);Object.assign(o,{queryOptions:Oe(Object.assign({useStrictMode:!1},o==null?void 0:o.queryOptions))}),r=r||[],i=i||{};const c=Object.entries(n);v(c.length===1,"Update expression must contain only one operator.");const[u,a]=c[0];v(S(zt,u),`Update operator '${u}' is not supported.`);const f=zt[u];return Object.keys(i).length&&!(i instanceof R?i:new R(i,o.queryOptions)).test(e)?[]:f(e,a,r,o)}}const Ur=Fr({});function qt(t,e){const n=Object.assign({},t);return Ur(n,e),n}function Ke(t,e){if(Object.is(t,e))return!0;if(t instanceof RegExp&&e instanceof RegExp)return t.toString()===e.toString();if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(typeof t!="object"||typeof e!="object"||t===null||e===null)return!1;const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(let i=0;i<n.length;i+=1){const s=n[i];if(!r.includes(s)||!Ke(t[s],e[s]))return!1}return!0}function zr(){return Math.floor(Math.random()*1e17).toString(16)}function Kt(t,e=!1){let n=e,r=!1,i=null;return()=>{if((!n||!r)&&i&&clearTimeout(i),n){if(r)return;setTimeout(()=>{t(),r=!1,e&&(n=!0)},0),r=!0;return}n=!0,t(),i=setTimeout(()=>{n=!1},0)}}function F(t){return typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?t.toString():t instanceof Date?t.toISOString():JSON.stringify(t)}var Gt=function(t){return function(e,n,r){return t(e,n,r)*r}},Ge=function(t,e){if(t)throw Error("Invalid sort config: "+e)},Vt=function(t){var e=t||{},n=e.asc,r=e.desc,i=n?1:-1,s=n||r;Ge(!s,"Expected `asc` or `desc` property"),Ge(n&&r,"Ambiguous object with `asc` and `desc` config properties");var o=t.comparer&&Gt(t.comparer);return{order:i,sortBy:s,comparer:o}},qr=function(t){return function e(n,r,i,s,o,c,u){var a,f;if(typeof n=="string")a=c[n],f=u[n];else if(typeof n=="function")a=n(c),f=n(u);else{var l=Vt(n);return e(l.sortBy,r,i,l.order,l.comparer||t,c,u)}var h=o(a,f,s);return(h===0||a==null&&f==null)&&r.length>i?e(r[i],r,i+1,s,o,c,u):h}};function Jt(t,e,n){if(t===void 0||t===!0)return function(s,o){return e(s,o,n)};if(typeof t=="string")return Ge(t.includes("."),"String syntax not allowed for nested properties."),function(s,o){return e(s[t],o[t],n)};if(typeof t=="function")return function(s,o){return e(t(s),t(o),n)};if(Array.isArray(t)){var r=qr(e);return function(s,o){return r(t[0],t,1,n,e,s,o)}}var i=Vt(t);return Jt(i.sortBy,i.comparer||e,i.order)}var Ve=function(t,e,n,r){var i;return Array.isArray(e)?(Array.isArray(n)&&n.length<2&&(i=n,n=i[0]),e.sort(Jt(n,r,t))):e};function Wt(t){var e=Gt(t.comparer);return function(n){var r=Array.isArray(n)&&!t.inPlaceSorting?n.slice():n;return{asc:function(i){return Ve(1,r,i,e)},desc:function(i){return Ve(-1,r,i,e)},by:function(i){return Ve(1,r,i,e)}}}}var Yt=function(t,e,n){return t==null?n:e==null?-n:typeof t!=typeof e?typeof t<typeof e?-1:1:t<e?-1:t>e?1:0},Kr=Wt({comparer:Yt});Wt({comparer:Yt,inPlaceSorting:!0});function Ee(t,e){const n=e.split(/[.[\]]/g);n[0]===""&&n.shift(),n[n.length-1]===""&&n.pop();let r=t;for(let i=0;i<n.length;i+=1){const s=n[i];if(r==null||s.trim()==="")return;r=r[s]}if(r!==void 0)return r}function Gr(t,e){return Kr(t).by(Object.entries(e).map(([n,r])=>({[r===1?"asc":"desc"]:s=>Ee(s,n)})))}function Qt(t,e,n,r=!1){if(t==null)return t;const i=e.split(/[.[\]]/g);i[0]===""&&i.shift(),i[i.length-1]===""&&i.pop();const s=o=>{if(i.length>1){const c=i.shift(),u=!Number.isNaN(parseInt(i[0],10));o[c]===void 0&&(o[c]=u?[]:{}),s(o[c])}else{if(r&&n===void 0){delete o[i[0]];return}o[i[0]]=n}};return s(t),t}function Vr(t,e){if(Object.values(e).every(i=>i===0)){const i=Object.assign({},t);return Object.keys(e).forEach(s=>{Ee(t,s)!==void 0&&Qt(i,s,void 0,!0)}),i}const r={};return Object.entries(e).forEach(([i,s])=>{const o=Ee(t,i);o!==void 0&&(o==null&&s!==1||Qt(r,i,s===1?o:void 0))}),r}class Jr{constructor(e,n,r){this.previousItems=[],this.skipInitial=!1,this.isIinitial=!0,this.callbacks=e,this.skipInitial=r,this.unbindEvents=n()}call(e,...n){const r=this.callbacks[e];r&&(this.skipInitial&&this.isIinitial||r(...n))}hasCallbacks(e){return e.some(n=>!!this.callbacks[n])}check(e){const n=new Map(this.previousItems.map((i,s)=>[i.id,{item:i,index:s,beforeItem:this.previousItems[s+1]||null}])),r=new Map(e.map((i,s)=>[i.id,{item:i,index:s,beforeItem:e[s+1]||null}]));this.hasCallbacks(["changed","movedBefore","removed"])&&n.forEach(({item:i,index:s,beforeItem:o})=>{var c;const u=r.get(i.id);u?(Ke(u.item,i)||this.call("changed",u.item),u.index!==s&&((c=u.beforeItem)===null||c===void 0?void 0:c.id)!==(o==null?void 0:o.id)&&this.call("movedBefore",u.item,u.beforeItem)):this.call("removed",i)}),this.hasCallbacks(["added","addedBefore"])&&e.forEach((i,s)=>{n.get(i.id)||(this.call("added",i),this.call("addedBefore",i,e[s+1]||null))}),this.previousItems=e,this.isIinitial=!1}stop(){this.unbindEvents()}}function Wr(t){return t?t.isInScope?t.isInScope():!0:!1}class Yr{constructor(e,n){this.observers=[],this.onCleanupCallbacks=[],this.getFilteredItems=e,this.options=n||{}}transform(e){return this.options.transform?this.options.transform(e):e}getItems(){const e=this.getFilteredItems(),{sort:n,skip:r,limit:i}=this.options,s=n?Gr(e,n):e,o=r?s.slice(r):s,c=i?o.slice(0,i):o,u=this.options.fields&&this.options.fields.id===0;return c.map(a=>this.options.fields?Object.assign(Object.assign({},u?{}:{id:a.id}),Vr(a,this.options.fields)):a)}depend(e,n){if(!this.options.reactive||!Wr(this.options.reactive))return;const r=this.options.reactive.create();r.depend();const i=()=>r.notify(),s=Object.entries(e).filter(([,c])=>c).map(([c])=>c).reduce((c,u)=>Object.assign(Object.assign({},c),{[u]:i}),{}),o=this.observeChanges(s,!0,n);this.options.reactive.onDispose&&this.options.reactive.onDispose(()=>o(),r),this.onCleanup(o)}cleanup(){this.onCleanupCallbacks.forEach(e=>{e()}),this.onCleanupCallbacks=[]}onCleanup(e){this.onCleanupCallbacks.push(e)}forEach(e){const n=this.getItems();this.depend({addedBefore:!0,removed:!0,changed:!0,movedBefore:!0},n),n.forEach(r=>{e(this.transform(r))})}map(e){const n=[];return this.forEach(r=>{n.push(e(r))}),n}fetch(){return this.map(e=>e)}count(){const e=this.getItems();return this.depend({added:!0,removed:!0}),e.length}observeChanges(e,n=!1,r){const i=Object.entries(e).reduce((o,[c,u])=>u?Object.assign(Object.assign({},o),{[c]:(a,f)=>{const l=this.transform(a),h=f!==void 0,d=h&&f?this.transform(f):null;return u(l,...h?[d]:[])}}):o,{}),s=new Jr(i,()=>{const o=()=>{s.check(this.getItems())},c=this.options.bindEvents&&this.options.bindEvents(o);return()=>{c&&c()}},n);return this.observers.push(s),s.check(r||this.getItems()),this.onCleanup(()=>s.stop()),()=>{s.stop(),this.observers=this.observers.filter(o=>o!==s)}}requery(){const e=this.getItems();this.observers.forEach(n=>n.check(e))}}function Qr(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n}typeof SuppressedError=="function"&&SuppressedError;function Je(...t){return t.length===0?[]:[...new Set(t.reduce((e,n)=>e.filter(r=>n.includes(r))))]}function Xr(t,e){return t.reduce((n,r)=>{/* istanbul ignore if -- @preserve */if(r.getItemPositions){const o=r.getItemPositions(e);return o==null?n:{matched:!0,positions:n.matched?Je(n.positions,o):o,optimizedSelector:n.optimizedSelector}}const i=r.query(e);if(!i.matched)return n;const s=Object.fromEntries(Object.entries(n.optimizedSelector).filter(([o])=>!i.fields.includes(o)));return{matched:!0,positions:[...new Set(n.matched?Je(n.positions,i.positions):i.positions)],optimizedSelector:s}},{matched:!1,positions:[],optimizedSelector:Object.assign({},e)})}function Ie(t,e){if(e==null||Object.keys(e).length<=0)return{matched:!1,positions:[],optimizedSelector:e};const{$and:n,$or:r}=e,i=Qr(e,["$and","$or"]),s=Xr(t,i);let{matched:o,positions:c}=s;const u=s.optimizedSelector;if(Array.isArray(n)){const a=[];for(const f of n){const{matched:l,positions:h,optimizedSelector:d}=Ie(t,f);l?(c=o?Je(c,h):h,o=!0,Object.keys(d).length>0&&a.push(d)):a.push(f)}a.length>0&&(u.$and=a)}if(Array.isArray(r)){const a=[];for(const f of r){const{matched:l,positions:h,optimizedSelector:d}=Ie(t,f);l?(c=[...new Set([...c,...h])],o=!0,Object.keys(d).length>0&&a.push(d)):a.push(f)}a.length>0&&(u.$or=a)}return{matched:o,positions:c||[],optimizedSelector:u}}function Br(t){return t}const Xt=["$eq","$gt","$gte","$lt","$lte","$in","$nin","$ne","$exists","$not","$expr","$jsonSchema","$mod","$regex","$options","$text","$where","$all","$elemMatch","$size","$bitsAllClear","$bitsAllSet","$bitsAnyClear","$bitsAnySet"];function Bt(t){if(typeof t!="object"||t==null)return!1;const e=Object.keys(t);return e.length===0||e.some(i=>!Xt.includes(i))?!1:e.every(i=>Xt.includes(i))}function Hr(t,e){if(e[t]instanceof RegExp)return null;if(e[t]!=null){if(Bt(e[t])){if(Bt(e[t])&&Array.isArray(e[t].$in)&&e[t].$in.length){const r=Object.assign(Object.assign({},e),{[t]:Object.assign({},e[t])});return delete r[t].$in,Object.keys(r[t]).length===0&&delete r[t],e[t].$in.map(F)}return null}return[F(e[t])]}return null}function Ht(t,e){return{query(n){const r=Hr(t,n);return r==null?{matched:!1}:{matched:!0,positions:r.reduce((s,o)=>[...s,...e.get(o)||[]],[]),fields:[t]}},rebuild(){}}}function Zr(t){const e=new Map;return Object.assign(Object.assign({},Ht(t,e)),{rebuild(n){e.clear(),n.forEach((r,i)=>{const s=F(Ee(r,t)),o=e.get(s)||new Set;o.add(i),e.set(s,o)})}})}function Zt(t){return t.added.length>0||t.modified.length>0||t.removed.length>0}function ei(t,{added:e,modified:n,removed:r}){const i=t.slice();return e.forEach(s=>{i.push(s)}),n.forEach(s=>{const o=i.findIndex(({id:c})=>c===s.id);o!==-1&&(i[o]=s)}),r.forEach(s=>{const o=i.findIndex(({id:c})=>c===s.id);o!==-1&&i.splice(o,1)}),i}class U extends ln{constructor(e){var n;if(super(),this.persistenceAdapter=null,this.indexProviders=[],this.indicesOutdated=!1,this.idIndex=new Map,this.rebuildIndicesOncePerTick=Kt(this.rebuildAllIndices.bind(this)),U.collections.push(this),this.options=Object.assign({memory:[]},e),this.debugMode=(n=this.options.enableDebugMode)!==null&&n!==void 0?n:U.debugMode,this.indexProviders=[Ht("id",this.idIndex),...this.options.indices||[]],this.options.persistence){const r=this.options.persistence;this.persistenceAdapter=r;let i=0,s=!1;const o={added:[],modified:[],removed:[]},c=async()=>{const{items:l,changes:h}=await r.load();if(l){if(i>0)return;this.memory().splice(0,this.memoryArray().length,...l),this.idIndex.clear(),this.memory().map((d,p)=>{this.idIndex.set(F(d.id),new Set([p]))})}else h&&(h.added.forEach(d=>{this.memory().push(d);const p=this.memory().findIndex(y=>y===d);this.idIndex.set(F(d.id),new Set([p]))}),h.modified.forEach(d=>{const p=this.memory().findIndex(y=>y.id===d.id);if(p===-1)throw new Error("Cannot resolve index for item");this.memory().splice(p,1,d)}),h.removed.forEach(d=>{const p=this.memory().findIndex(y=>y.id===d.id);if(p===-1)throw new Error("Cannot resolve index for item");this.memory().splice(p,1)}));this.rebuildIndices(),this.emit("persistence.received")},u={added:[],modified:[],removed:[]};let a=!1;const f=()=>{if(a||!Zt(u))return;a=!0,i+=1;const l=this.memoryArray(),h=Object.assign({},u);u.added=[],u.modified=[],u.removed=[],r.save(l,h).then(()=>{this.emit("persistence.transmitted")}).catch(d=>{this.emit("persistence.error",d instanceof Error?d:new Error(d))}).finally(()=>{i-=1,a=!1,f()})};this.on("added",l=>{if(!s){o.added.push(l);return}u.added.push(l),f()}),this.on("changed",l=>{if(!s){o.modified.push(l);return}u.modified.push(l),f()}),this.on("removed",l=>{if(!s){o.removed.push(l);return}u.removed.push(l),f()}),r.register(()=>c()).then(async()=>{let l=this.memoryArray();for(await c();Zt(o);){const h=o.added.splice(0),d=o.modified.splice(0),p=o.removed.splice(0);l=ei(l,{added:h,modified:d,removed:p}),await r.save(l,{added:h,modified:d,removed:p}).then(()=>{this.emit("persistence.transmitted")})}await c(),s=!0,this.emit("persistence.init")}).catch(l=>{this.emit("persistence.error",l instanceof Error?l:new Error(l))})}}getDebugMode(){return this.debugMode}setDebugMode(e){this.debugMode=e}profile(e,n){if(!this.debugMode)return e();const r=performance.now(),i=e(),s=performance.now();return n(s-r),i}executeInDebugMode(e){if(!this.debugMode)return;const n=new Error().stack||"";e(n)}rebuildIndices(){this.indicesOutdated=!0,this.rebuildIndicesOncePerTick()}rebuildAllIndices(){this.indexProviders.forEach(e=>e.rebuild(this.memoryArray())),this.indicesOutdated=!1}getItemAndIndex(e){const n=this.indicesOutdated?{matched:!1,positions:[],optimizedSelector:e}:Ie(this.indexProviders,e),i=(n.matched?n.positions.map(o=>this.memoryArray()[o]):this.memory()).find(o=>kt(o,e)),s=n.matched&&n.positions.find(o=>this.memoryArray()[o]===i)||this.memory().findIndex(o=>o===i);if(i==null)return{item:null,index:-1};if(s===-1)throw new Error("Cannot resolve index for item");return{item:i,index:s}}memory(){return this.options.memory}memoryArray(){return this.memory().map(e=>e)}transform(e){return this.options.transform?this.options.transform(e):e}getItems(e){return this.profile(()=>{const n=e&&!this.indicesOutdated?Ie(this.indexProviders,e):{matched:!1,positions:[],optimizedSelector:e},r=o=>n.optimizedSelector==null||Object.keys(n.optimizedSelector).length<=0?!0:kt(o,n.optimizedSelector);if(!n.matched)return this.memory().filter(r);const i=this.memoryArray();return n.positions.map(o=>i[o]).filter(r)},n=>this.executeInDebugMode(r=>this.emit("_debug.getItems",r,e,n)))}find(e,n){if(e!==void 0&&(!e||typeof e!="object"))throw new Error("Invalid selector");const r=new Yr(()=>this.getItems(e),Object.assign(Object.assign({reactive:this.options.reactivity},n),{transform:this.transform.bind(this),bindEvents:i=>{const s=Kt(i,!0);return this.addListener("persistence.received",s),this.addListener("added",s),this.addListener("changed",s),this.addListener("removed",s),()=>{this.removeListener("persistence.received",s),this.removeListener("added",s),this.removeListener("changed",s),this.removeListener("removed",s)}}}));return this.executeInDebugMode(i=>this.emit("_debug.find",i,e,n,r)),r}findOne(e,n){const i=this.find(e,Object.assign({limit:1},n)).fetch()[0]||void 0;return this.executeInDebugMode(s=>this.emit("_debug.findOne",s,e,n,i)),i}insert(e){if(!e)throw new Error("Invalid item");const n=Object.assign({id:zr()},e);if(this.idIndex.has(F(n.id)))throw new Error("Item with same id already exists");this.memory().push(n);const r=this.memory().findIndex(i=>i===n);return this.idIndex.set(F(n.id),new Set([r])),this.rebuildIndices(),this.emit("added",n),this.executeInDebugMode(i=>this.emit("_debug.insert",i,n)),n.id}updateOne(e,n){if(!e)throw new Error("Invalid selector");if(!n)throw new Error("Invalid modifier");const{item:r,index:i}=this.getItemAndIndex(e);if(r==null)return 0;const s=qt(Object.assign({},r),n),o=this.findOne({id:s.id},{reactive:!1});if(!Ke(o,Object.assign(Object.assign({},o),{id:s.id})))throw new Error("Item with same id already exists");return this.memory().splice(i,1,s),this.rebuildIndices(),this.emit("changed",s),this.executeInDebugMode(c=>this.emit("_debug.updateOne",c,e,n)),1}updateMany(e,n){if(!e)throw new Error("Invalid selector");if(!n)throw new Error("Invalid modifier");const r=this.getItems(e),i=[];return r.forEach(s=>{const{index:o}=this.getItemAndIndex({id:s.id});if(o===-1)throw new Error("Cannot resolve index for item");const c=qt(s,n);this.memory().splice(o,1,c),i.push(c)}),this.rebuildIndices(),i.forEach(s=>{this.emit("changed",s)}),this.executeInDebugMode(s=>this.emit("_debug.updateMany",s,e,n)),i.length}removeOne(e){if(!e)throw new Error("Invalid selector");const{item:n,index:r}=this.getItemAndIndex(e);return this.executeInDebugMode(i=>this.emit("_debug.removeOne",i,e)),n==null?0:(this.memory().splice(r,1),this.idIndex.delete(F(n.id)),this.rebuildIndices(),this.emit("removed",n),1)}removeMany(e){if(!e)throw new Error("Invalid selector");const n=this.getItems(e);return n.forEach(r=>{const i=this.memory().findIndex(s=>s===r);if(i===-1)throw new Error("Cannot resolve index for item");this.memory().splice(i,1),this.idIndex.delete(F(r.id)),this.rebuildIndices()}),n.forEach(r=>{this.emit("removed",r)}),this.executeInDebugMode(r=>this.emit("_debug.removeMany",r,e)),n.length}}U.collections=[],U.debugMode=!1,U.enableDebugMode=()=>{U.debugMode=!0,U.collections.forEach(t=>{t.setDebugMode(!0)})};const en=U;function ti(t){return t}function tn(t){const e=`signaldb-collection-${t}`;function n(){return JSON.parse(localStorage.getItem(e)||"[]")}return{async load(){const r=n();return Promise.resolve({items:r})},async save(r,{added:i,modified:s,removed:o}){const c=n();return i.forEach(u=>{c.push(u)}),s.forEach(u=>{const a=c.findIndex(({id:f})=>f===u.id);/* istanbul ignore if -- @preserve */if(a===-1)throw new Error(`Item with ID ${u.id} not found`);c[a]=u}),o.forEach(u=>{const a=c.findIndex(({id:f})=>f===u.id);/* istanbul ignore if -- @preserve */if(a===-1)throw new Error(`Item with ID ${u.id} not found`);c.splice(a,1)}),localStorage.setItem(e,JSON.stringify(c)),Promise.resolve()},async register(){return Promise.resolve()}}}function nn(t){let e=null;async function n(){const r=await import("fs");if(!await r.promises.access(t).then(()=>!0).catch(()=>!1))return[];const s=await r.promises.readFile(t,"utf8").catch(o=>{/* istanbul ignore next -- @preserve */if(o.code==="ENOENT")return"[]";/* istanbul ignore next -- @preserve */throw o});return JSON.parse(s)}return{async register(r){if(typeof window<"u")throw new Error("Filesystem adapter is not supported in the browser");const i=await import("fs");await i.promises.access(t).then(()=>!0).catch(()=>!1)||await i.promises.writeFile(t,"[]"),i.watch(t,{encoding:"utf8"},()=>{r()})},async load(){if(typeof window<"u")throw new Error("Filesystem adapter is not supported in the browser");return e&&await e,{items:await n()}},async save(r,{added:i,modified:s,removed:o}){if(typeof window<"u")throw new Error("Filesystem adapter is not supported in the browser");e&&await e,e=n().then(c=>{const u=c.slice();return i.forEach(a=>{u.push(a)}),s.forEach(a=>{const f=u.findIndex(({id:l})=>l===a.id);/* istanbul ignore if -- @preserve */if(f===-1)throw new Error(`Item with ID ${a.id} not found`);u[f]=a}),o.forEach(a=>{const f=u.findIndex(({id:l})=>l===a.id);/* istanbul ignore if -- @preserve */if(f===-1)throw new Error(`Item with ID ${a.id} not found`);u.splice(f,1)}),u}).then(async c=>{await(await import("fs")).promises.writeFile(t,JSON.stringify(c))}).then(()=>{e=null}),await e}}}function ni(t){return typeof window>"u"?nn(`persistent-collection-${t}.json`):tn(t)}class ri extends en{constructor(e,n){super(Object.assign({persistence:ni(e)},n))}}function ii(t){return t}function si(t){return t}w.Collection=en,w.PersistentCollection=ri,w.createFilesystemAdapter=nn,w.createIndex=Zr,w.createIndexProvider=Br,w.createLocalStorageAdapter=tn,w.createMemoryAdapter=ii,w.createPersistenceAdapter=ti,w.createReactivityAdapter=si,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=index.umd.js.map
{
"name": "signaldb",
"version": "0.8.7",
"version": "0.8.8",
"description": "SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON interface to places such as localStorage.",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc