UNPKG

@ucast/mongo

Version:

git@github.com:stalniy/ucast.git

2 lines 3.24 kB
import{CompoundCondition as e,FieldCondition as t,ITSELF as n,NULL_CONDITION as r,ObjectQueryParser as i,buildAnd as a,defaultInstructionParsers as o,optimizedCompoundCondition as s}from"@ucast/core";var c=Object.defineProperty,l=((e,t)=>{let n={};for(var r in e)c(n,r,{get:e[r],enumerable:!0});return t||c(n,Symbol.toStringTag,{value:`Module`}),n})({$all:()=>y,$and:()=>u,$elemMatch:()=>h,$eq:()=>E,$exists:()=>x,$gt:()=>C,$gte:()=>S,$in:()=>_,$lt:()=>w,$lte:()=>T,$mod:()=>b,$ne:()=>D,$nin:()=>v,$nor:()=>f,$not:()=>m,$options:()=>k,$or:()=>d,$regex:()=>O,$size:()=>g,$where:()=>A});const u={type:`compound`,validate:M,parse(e,t,n){let r=p(e,t,n);return s(e.name,r)}},d=u,f={type:`compound`,validate:M,parse(t,n,r){let i=p(t,n,r);return new e(t.name,i)}};function p(e,t,n){let r=Array(t.length);for(let i=0;i<t.length;i++){let a=t[i];F(e,a,i),r[i]=n.parse(a)}return r}const m={type:`field`,validate(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw Error(`"${e.name}" expects to receive either regular expression or object of field operators`)},parse(n,r,i){let a=r instanceof RegExp?new t(`regex`,i.field,r):i.parse(r,i);return new e(n.name,[a])}},h={type:`field`,validate(e,t){if(!t||t.constructor!==Object)throw Error(`"${e.name}" expects to receive an object with nested query or field level operators`)},parse(e,r,{parse:i,field:a,hasOperators:o}){let s=o(r)?i(r,{field:n}):i(r);return new t(e.name,a,s)}},g={type:`field`,validate:P(`number`)},_={type:`field`,validate:j},v=_,y=_,b={type:`field`,validate(e,t){if(!Array.isArray(t)||t.length!==2)throw Error(`"${e.name}" expects an array with 2 numeric elements`)}},x={type:`field`,validate:P(`boolean`)},S={type:`field`,validate:N},C=S,w=C,T=C,E={type:`field`},D=E,O={type:`field`,validate(e,t){if(!(t instanceof RegExp)&&typeof t!=`string`)throw Error(`"${e.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(e,n,r){let i=typeof n==`string`?new RegExp(n,r.query.$options||``):n;return new t(e.name,r.field,i)}},k={type:`field`,parse:()=>r},A={type:`document`,validate:P(`function`)};function j(e,t){if(!Array.isArray(t))throw Error(`"${e.name}" expects value to be an array`)}function M(e,t){if(j(e,t),!t.length)throw Error(`"${e.name}" expects to have at least one element in array`)}function N(e,t){if(!(typeof t==`string`||typeof t==`number`||t instanceof Date))throw Error(`"${e.name}" expects value to be comparable (i.e., string, number or date)`)}function P(e){return(t,n)=>{if(typeof n!==e)throw Error(`"${t.name}" expects value to be a "${e}"`)}}function F(e,t,n){let r=t;if(!r||r.constructor!==Object)throw Error(`"${e.name}" expects item at index ${n} to be an object`)}var I=class extends i{constructor(e){super(e,{defaultOperatorName:`$eq`,operatorToConditionName:e=>e.slice(1)})}parse(e,t){return t&&t.field?a(this.parseFieldOperators(t.field,e)):super.parse(e)}};const L=l;export{y as $all,u as $and,h as $elemMatch,E as $eq,x as $exists,C as $gt,S as $gte,_ as $in,w as $lt,T as $lte,b as $mod,D as $ne,v as $nin,f as $nor,m as $not,k as $options,d as $or,O as $regex,g as $size,A as $where,I as MongoQueryParser,L as allParsingInstructions,o as defaultParsers}; //# sourceMappingURL=index.mjs.map