"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("@ucast/core");function t(r,t,e){for(let n=0,o=r.length;n<o;n++)if(0===e(r[n],t))return!0;return!1}function e(r,t){return Array.isArray(r)&&Number.isNaN(Number(t))}function n(r,t,n){if(!e(r,t))return n(r,t);let o=[];for(let e=0;e<r.length;e++){const s=n(r[e],t);void 0!==s&&(o=o.concat(s))}return o}function o(r){return(t,e,n)=>{const o=n.get(e,t.field);return Array.isArray(o)?o.some(e=>r(t,e,n)):r(t,o,n)}}const s=(r,t)=>r[t];function u(r,t,e){const n=t.lastIndexOf(".");return-1===n?[r,t]:[e(r,t.slice(0,n)),t.slice(n+1)]}function p(t,e,o=s){if(e===r.ITSELF)return t;if(!t)throw new Error(`Unable to get field "${e}" out of ${String(t)}.`);return function(r,t,e){if(-1===t.indexOf("."))return n(r,t,e);const o=t.split(".");let s=r;for(let r=0,t=o.length;r<t;r++)if(s=n(s,o[r],e),!s||"object"!=typeof s)return s;return s}(t,e,o)}function c(r,t){return r===t?0:r>t?1:-1}function i(t,e={}){return r.createInterpreter(t,Object.assign({get:p,compare:c},e))}const x=(r,t,{interpret:e})=>r.value.some(r=>e(r,t)),f=(r,t,e)=>!x(r,t,e),a=(r,t,{interpret:e})=>r.value.every(r=>e(r,t)),l=(r,t,{interpret:e})=>!e(r.value[0],t),g=(r,e,{compare:n,get:o})=>{const s=o(e,r.field);return Array.isArray(s)&&!Array.isArray(r.value)?t(s,r.value,n):0===n(s,r.value)},y=(r,t,e)=>!g(r,t,e),b=o((r,t,e)=>{const n=e.compare(t,r.value);return 0===n||-1===n}),m=o((r,t,e)=>-1===e.compare(t,r.value)),A=o((r,t,e)=>1===e.compare(t,r.value)),d=o((r,t,e)=>{const n=e.compare(t,r.value);return 0===n||1===n}),_=(t,n,{get:o})=>{if(t.field===r.ITSELF)return void 0!==n;const[s,p]=u(n,t.field,o),c=r=>null==r?Boolean(r)===t.value:r.hasOwnProperty(p)===t.value;return e(s,p)?s.some(c):c(s)},j=o((r,t)=>"number"==typeof t&&t%r.value[0]===r.value[1]),v=(t,n,{get:o})=>{const[s,p]=u(n,t.field,o),c=r=>{const e=o(r,p);return Array.isArray(e)&&e.length===t.value};return t.field!==r.ITSELF&&e(s,p)?s.some(c):c(s)},h=o((r,t)=>"string"==typeof t&&r.value.test(t)),w=o((r,e,{compare:n})=>t(r.value,e,n)),O=(r,t,e)=>!w(r,t,e),q=(r,e,{compare:n,get:o})=>{const s=o(e,r.field);return Array.isArray(s)&&r.value.every(r=>t(s,r,n))},M=(r,t,{interpret:e,get:n})=>{const o=n(t,r.field);return Array.isArray(o)&&o.some(t=>e(r.value,t))},N=(r,t)=>r.value.call(t);var $=Object.freeze({__proto__:null,or:x,nor:f,and:a,not:l,eq:g,ne:y,lte:b,lt:m,gt:A,gte:d,exists:_,mod:j,size:v,regex:h,within:w,nin:O,all:q,elemMatch:M,where:N});const z=Object.assign({},$,{in:w}),B=i(z);exports.all=q,exports.allInterpreters=z,exports.and=a,exports.compare=c,exports.createGetter=function(r){return(t,e)=>p(t,e,r)},exports.createJsInterpreter=i,exports.elemMatch=M,exports.eq=g,exports.exists=_,exports.getObjectField=p,exports.getObjectFieldCursor=u,exports.gt=A,exports.gte=d,exports.interpret=B,exports.lt=m,exports.lte=b,exports.mod=j,exports.ne=y,exports.nin=O,exports.nor=f,exports.not=l,exports.or=x,exports.regex=h,exports.size=v,exports.where=N,exports.within=w;
//# sourceMappingURL=index.js.map
