Socket
Socket
Sign inDemoInstall

@ucast/mongo

Package Overview
Dependencies
1
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.2 to 2.2.0

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Change Log

# [2.2.0](https://github.com/stalniy/ucast/compare/@ucast/mongo@2.1.2...@ucast/mongo@2.2.0) (2020-08-18)
### Features
* **parser:** adds possibility to set `parse` function ([8a1e388](https://github.com/stalniy/ucast/commit/8a1e388fe1c5722ae322b783101f066d763dfde5)), closes [#9](https://github.com/stalniy/ucast/issues/9)
## [2.1.2](https://github.com/stalniy/ucast/compare/@ucast/mongo@2.1.1...@ucast/mongo@2.1.2) (2020-08-13)

@@ -7,0 +14,0 @@

2

dist/es5m/index.js

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

import{optimizedCompoundCondition as e,FieldCondition as r,CompoundCondition as t,ITSELF as n,NULL_CONDITION as o,DocumentCondition as i,buildAnd as a}from"@ucast/core";function f(e){if(!e||e&&e.constructor!==Object)return!1;for(var r in e)if(e.hasOwnProperty(r)&&"$"===r[0])return!0;return!1}function u(e,r){if(!Array.isArray(r))throw new Error('"'+e.name+'" expects value to be an array')}function c(e,r){if(u(e,r),!r.length)throw new Error('"'+e.name+'" expects to have at least one element in array')}var s=function(e){return function(r,t){if(typeof t!==e)throw new Error('"'+r.name+'" expects value to be a "'+e+'"')}},p={type:"compound",validate:c,parse:function(r,t,n){var o=n.parse,i=t.map((function(e){return o(e)}));return e(r.name,i)}},l=p,d={type:"compound",validate:c},v={type:"field",validate:function(e,r){if(!(r&&(r instanceof RegExp||r.constructor===Object)))throw new Error('"'+e.name+'" expects to receive either regular expression or object of field operators')},parse:function(e,n,o){var i=n instanceof RegExp?new r("regex",o.field,n):o.parse(n,o);return new t(e.name,[i])}},h={type:"field",validate:function(e,r){if(!r||r.constructor!==Object)throw new Error('"'+e.name+'" expects to receive an object with nested query or field level operators')},parse:function(e,t,o){var i=o.parse,a=o.field,u=f(t)?i(t,{field:n}):i(t);return new r(e.name,a,u)}},w={type:"field",validate:s("number")},y={type:"field",validate:u},$=y,b=y,m={type:"field",validate:function(e,r){if(!Array.isArray(r)||2!==r.length)throw new Error('"'+e.name+'" expects an array with 2 numeric elements')}},x={type:"field",validate:s("boolean")},E={type:"field",validate:function(e,r){if(!("string"==typeof r||"number"==typeof r||r instanceof Date))throw new Error('"'+e.name+'" expects value to be comparable (i.e., string, number or date)')}},g=E,j=g,O=g,q={type:"field"},R=q,U={type:"field",validate:function(e,r){if(!(r instanceof RegExp)&&"string"!=typeof r)throw new Error('"'+e.name+'" expects value to be a regular expression or a string that represents regular expression')},parse:function(e,t,n){var o="string"==typeof t?new RegExp(t,n.query.$options||""):t;return new r(e.name,n.field,o)}},_={type:"field",parse:function(){return o}},A={type:"document",validate:s("function")},k=Object.freeze({__proto__:null,$and:p,$or:l,$nor:d,$not:v,$elemMatch:h,$size:w,$in:y,$nin:$,$all:b,$mod:m,$exists:x,$gte:E,$gt:g,$lt:j,$lte:O,$eq:q,$ne:R,$regex:U,$options:_,$where:A});function z(){return(z=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var D={compound:function(e,r,n){var o=(Array.isArray(r)?r:[r]).map((function(e){return n.parse(e)}));return new t(e.name,o)},field:function(e,t,n){return new r(e.name,n.field,t)},document:function(e,r){return new i(e.name,r)}};function F(e,r,t){return"function"==typeof e.validate&&e.validate(e,r),(e.parse||D[e.type])(e,r,t)}var M=function(){function e(e){this.t=void 0,this.o=void 0,this.t=Object.keys(e).reduce((function(r,t){return r[t]=z({},e[t],{name:t.slice(1)}),r}),{}),this.parse=this.parse.bind(this),this.o={field:"",query:{},parse:this.parse}}var r=e.prototype;return r.i=function(e,r,t,n){var o=this.t[r];if(!o)throw new Error('Unsupported operator "'+r+'"');if("field"!==o.type)throw new Error("Unexpected "+o.type+' operator "'+r+'" at field level');return this.o.field=e,this.o.query=n,F(o,t,this.o)},r.u=function(e,r){for(var t=[],n=Object.keys(r),i=0,a=n.length;i<a;i++){var f=n[i];if("$"!==f[0])throw new Error('Field query for "'+e+'" may contain only operators or a plain object as a value');var u=this.i(e,f,r[f],r);u!==o&&t.push(u)}return t},r.parse=function(e,r){if(r&&r.field)return a(this.u(r.field,e));for(var t=e,n={query:t,parse:this.parse},o=[],i=Object.keys(t),u=0,c=i.length;u<c;u++){var s=i[u],p=t[s],l="$"===s[0],d=this.t[s];if(l){if(!d)throw new Error('Unsupported operator "'+s+'"');if("document"!==d.type&&"compound"!==d.type)throw new Error('Unknown top level operator "'+s+'"');o.push(F(d,p,n))}else f(p)?o.push.apply(o,this.u(s,p)):o.push(this.i(s,"$eq",p,t))}return a(o)},e}(),B=k;export{b as $all,p as $and,h as $elemMatch,q as $eq,x as $exists,g as $gt,E as $gte,y as $in,j as $lt,O as $lte,m as $mod,R as $ne,$ as $nin,d as $nor,v as $not,_ as $options,l as $or,U as $regex,w as $size,A as $where,M as MongoQueryParser,B as allParsingInstructions,D as defaultParsers};
import{optimizedCompoundCondition as e,FieldCondition as r,CompoundCondition as t,ITSELF as n,NULL_CONDITION as o,DocumentCondition as i,buildAnd as a}from"@ucast/core";function f(e){if(!e||e&&e.constructor!==Object)return!1;for(var r in e)if(e.hasOwnProperty(r)&&"$"===r[0])return!0;return!1}function u(e,r){if(!Array.isArray(r))throw new Error('"'+e.name+'" expects value to be an array')}function c(e,r){if(u(e,r),!r.length)throw new Error('"'+e.name+'" expects to have at least one element in array')}var s=function(e){return function(r,t){if(typeof t!==e)throw new Error('"'+r.name+'" expects value to be a "'+e+'"')}},p={type:"compound",validate:c,parse:function(r,t,n){var o=n.parse,i=t.map((function(e){return o(e)}));return e(r.name,i)}},l=p,d={type:"compound",validate:c},v={type:"field",validate:function(e,r){if(!(r&&(r instanceof RegExp||r.constructor===Object)))throw new Error('"'+e.name+'" expects to receive either regular expression or object of field operators')},parse:function(e,n,o){var i=n instanceof RegExp?new r("regex",o.field,n):o.parse(n,o);return new t(e.name,[i])}},h={type:"field",validate:function(e,r){if(!r||r.constructor!==Object)throw new Error('"'+e.name+'" expects to receive an object with nested query or field level operators')},parse:function(e,t,o){var i=o.parse,a=o.field,u=f(t)?i(t,{field:n}):i(t);return new r(e.name,a,u)}},w={type:"field",validate:s("number")},y={type:"field",validate:u},$=y,b=y,m={type:"field",validate:function(e,r){if(!Array.isArray(r)||2!==r.length)throw new Error('"'+e.name+'" expects an array with 2 numeric elements')}},x={type:"field",validate:s("boolean")},E={type:"field",validate:function(e,r){if(!("string"==typeof r||"number"==typeof r||r instanceof Date))throw new Error('"'+e.name+'" expects value to be comparable (i.e., string, number or date)')}},g=E,j=g,O=g,q={type:"field"},R=q,U={type:"field",validate:function(e,r){if(!(r instanceof RegExp)&&"string"!=typeof r)throw new Error('"'+e.name+'" expects value to be a regular expression or a string that represents regular expression')},parse:function(e,t,n){var o="string"==typeof t?new RegExp(t,n.query.$options||""):t;return new r(e.name,n.field,o)}},_={type:"field",parse:function(){return o}},A={type:"document",validate:s("function")},k=Object.freeze({__proto__:null,$and:p,$or:l,$nor:d,$not:v,$elemMatch:h,$size:w,$in:y,$nin:$,$all:b,$mod:m,$exists:x,$gte:E,$gt:g,$lt:j,$lte:O,$eq:q,$ne:R,$regex:U,$options:_,$where:A});function z(){return(z=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var D={compound:function(e,r,n){var o=(Array.isArray(r)?r:[r]).map((function(e){return n.parse(e)}));return new t(e.name,o)},field:function(e,t,n){return new r(e.name,n.field,t)},document:function(e,r){return new i(e.name,r)}};function F(e,r,t){return"function"==typeof e.validate&&e.validate(e,r),(e.parse||D[e.type])(e,r,t)}var M=function(){function e(e){this.t=void 0,this.o=void 0,this.t=Object.keys(e).reduce((function(r,t){return r[t]=z({},e[t],{name:t.slice(1)}),r}),{}),this.parse=this.parse.bind(this),this.o={field:"",query:{},parse:this.parse}}var r=e.prototype;return r.setParse=function(e){this.parse=e,this.o.parse=e},r.i=function(e,r,t,n){var o=this.t[r];if(!o)throw new Error('Unsupported operator "'+r+'"');if("field"!==o.type)throw new Error("Unexpected "+o.type+' operator "'+r+'" at field level');return this.o.field=e,this.o.query=n,F(o,t,this.o)},r.u=function(e,r){for(var t=[],n=Object.keys(r),i=0,a=n.length;i<a;i++){var f=n[i];if("$"!==f[0])throw new Error('Field query for "'+e+'" may contain only operators or a plain object as a value');var u=this.i(e,f,r[f],r);u!==o&&t.push(u)}return t},r.parse=function(e,r){if(r&&r.field)return a(this.u(r.field,e));for(var t=e,n={query:t,parse:this.parse},o=[],i=Object.keys(t),u=0,c=i.length;u<c;u++){var s=i[u],p=t[s],l="$"===s[0],d=this.t[s];if(l){if(!d)throw new Error('Unsupported operator "'+s+'"');if("document"!==d.type&&"compound"!==d.type)throw new Error('Unknown top level operator "'+s+'"');o.push(F(d,p,n))}else f(p)?o.push.apply(o,this.u(s,p)):o.push(this.i(s,"$eq",p,t))}return a(o)},e}(),B=k;export{b as $all,p as $and,h as $elemMatch,q as $eq,x as $exists,g as $gt,E as $gte,y as $in,j as $lt,O as $lte,m as $mod,R as $ne,$ as $nin,d as $nor,v as $not,_ as $options,l as $or,U as $regex,w as $size,A as $where,M as MongoQueryParser,B as allParsingInstructions,D as defaultParsers};
//# sourceMappingURL=index.js.map

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@ucast/core");function t(e){if(!e||e&&e.constructor!==Object)return!1;for(const t in e)if(e.hasOwnProperty(t)&&"$"===t[0])return!0;return!1}function r(e,t){if(!Array.isArray(t))throw new Error(`"${e.name}" expects value to be an array`)}function o(e,t){if(r(e,t),!t.length)throw new Error(`"${e.name}" expects to have at least one element in array`)}const n=e=>(t,r)=>{if(typeof r!==e)throw new Error(`"${t.name}" expects value to be a "${e}"`)},s={type:"compound",validate:o,parse(t,r,{parse:o}){const n=r.map(e=>o(e));return e.optimizedCompoundCondition(t.name,n)}},i=s,a={type:"compound",validate:o},p={type:"field",validate(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error(`"${e.name}" expects to receive either regular expression or object of field operators`)},parse(t,r,o){const n=r instanceof RegExp?new e.FieldCondition("regex",o.field,r):o.parse(r,o);return new e.CompoundCondition(t.name,[n])}},c={type:"field",validate(e,t){if(!t||t.constructor!==Object)throw new Error(`"${e.name}" expects to receive an object with nested query or field level operators`)},parse(r,o,{parse:n,field:s}){const i=t(o)?n(o,{field:e.ITSELF}):n(o);return new e.FieldCondition(r.name,s,i)}},l={type:"field",validate:n("number")},f={type:"field",validate:r},u=f,d=f,x={type:"field",validate(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error(`"${e.name}" expects an array with 2 numeric elements`)}},$={type:"field",validate:n("boolean")},h={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error(`"${e.name}" expects value to be comparable (i.e., string, number or date)`)}},w=h,y=w,v=w,b={type:"field"},m=b,E={type:"field",validate(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error(`"${e.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(t,r,o){const n="string"==typeof r?new RegExp(r,o.query.$options||""):r;return new e.FieldCondition(t.name,o.field,n)}},g={type:"field",parse:()=>e.NULL_CONDITION},j={type:"document",validate:n("function")};var O=Object.freeze({__proto__:null,$and:s,$or:i,$nor:a,$not:p,$elemMatch:c,$size:l,$in:f,$nin:u,$all:d,$mod:x,$exists:$,$gte:h,$gt:w,$lt:y,$lte:v,$eq:b,$ne:m,$regex:E,$options:g,$where:j});const _={compound(t,r,o){const n=(Array.isArray(r)?r:[r]).map(e=>o.parse(e));return new e.CompoundCondition(t.name,n)},field:(t,r,o)=>new e.FieldCondition(t.name,o.field,r),document:(t,r)=>new e.DocumentCondition(t.name,r)};function q(e,t,r){"function"==typeof e.validate&&e.validate(e,t);return(e.parse||_[e.type])(e,t,r)}const R=O;exports.$all=d,exports.$and=s,exports.$elemMatch=c,exports.$eq=b,exports.$exists=$,exports.$gt=w,exports.$gte=h,exports.$in=f,exports.$lt=y,exports.$lte=v,exports.$mod=x,exports.$ne=m,exports.$nin=u,exports.$nor=a,exports.$not=p,exports.$options=g,exports.$or=i,exports.$regex=E,exports.$size=l,exports.$where=j,exports.MongoQueryParser=class{constructor(e){this.t=void 0,this.o=void 0,this.t=Object.keys(e).reduce((t,r)=>(t[r]=Object.assign({},e[r],{name:r.slice(1)}),t),{}),this.parse=this.parse.bind(this),this.o={field:"",query:{},parse:this.parse}}s(e,t,r,o){const n=this.t[t];if(!n)throw new Error(`Unsupported operator "${t}"`);if("field"!==n.type)throw new Error(`Unexpected ${n.type} operator "${t}" at field level`);return this.o.field=e,this.o.query=o,q(n,r,this.o)}i(t,r){const o=[],n=Object.keys(r);for(let s=0,i=n.length;s<i;s++){const i=n[s];if("$"!==i[0])throw new Error(`Field query for "${t}" may contain only operators or a plain object as a value`);const a=this.s(t,i,r[i],r);a!==e.NULL_CONDITION&&o.push(a)}return o}parse(r,o){if(o&&o.field)return e.buildAnd(this.i(o.field,r));const n=r,s={query:n,parse:this.parse},i=[],a=Object.keys(n);for(let e=0,r=a.length;e<r;e++){const r=a[e],o=n[r],p="$"===r[0],c=this.t[r];if(p){if(!c)throw new Error(`Unsupported operator "${r}"`);if("document"!==c.type&&"compound"!==c.type)throw new Error(`Unknown top level operator "${r}"`);i.push(q(c,o,s))}else t(o)?i.push(...this.i(r,o)):i.push(this.s(r,"$eq",o,n))}return e.buildAnd(i)}},exports.allParsingInstructions=R,exports.defaultParsers=_;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@ucast/core");function t(e){if(!e||e&&e.constructor!==Object)return!1;for(const t in e)if(e.hasOwnProperty(t)&&"$"===t[0])return!0;return!1}function r(e,t){if(!Array.isArray(t))throw new Error(`"${e.name}" expects value to be an array`)}function o(e,t){if(r(e,t),!t.length)throw new Error(`"${e.name}" expects to have at least one element in array`)}const n=e=>(t,r)=>{if(typeof r!==e)throw new Error(`"${t.name}" expects value to be a "${e}"`)},s={type:"compound",validate:o,parse(t,r,{parse:o}){const n=r.map(e=>o(e));return e.optimizedCompoundCondition(t.name,n)}},i=s,a={type:"compound",validate:o},p={type:"field",validate(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error(`"${e.name}" expects to receive either regular expression or object of field operators`)},parse(t,r,o){const n=r instanceof RegExp?new e.FieldCondition("regex",o.field,r):o.parse(r,o);return new e.CompoundCondition(t.name,[n])}},c={type:"field",validate(e,t){if(!t||t.constructor!==Object)throw new Error(`"${e.name}" expects to receive an object with nested query or field level operators`)},parse(r,o,{parse:n,field:s}){const i=t(o)?n(o,{field:e.ITSELF}):n(o);return new e.FieldCondition(r.name,s,i)}},l={type:"field",validate:n("number")},f={type:"field",validate:r},u=f,d=f,x={type:"field",validate(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error(`"${e.name}" expects an array with 2 numeric elements`)}},h={type:"field",validate:n("boolean")},$={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error(`"${e.name}" expects value to be comparable (i.e., string, number or date)`)}},w=$,y=w,v=w,b={type:"field"},m=b,E={type:"field",validate(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error(`"${e.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(t,r,o){const n="string"==typeof r?new RegExp(r,o.query.$options||""):r;return new e.FieldCondition(t.name,o.field,n)}},g={type:"field",parse:()=>e.NULL_CONDITION},j={type:"document",validate:n("function")};var O=Object.freeze({__proto__:null,$and:s,$or:i,$nor:a,$not:p,$elemMatch:c,$size:l,$in:f,$nin:u,$all:d,$mod:x,$exists:h,$gte:$,$gt:w,$lt:y,$lte:v,$eq:b,$ne:m,$regex:E,$options:g,$where:j});const _={compound(t,r,o){const n=(Array.isArray(r)?r:[r]).map(e=>o.parse(e));return new e.CompoundCondition(t.name,n)},field:(t,r,o)=>new e.FieldCondition(t.name,o.field,r),document:(t,r)=>new e.DocumentCondition(t.name,r)};function q(e,t,r){"function"==typeof e.validate&&e.validate(e,t);return(e.parse||_[e.type])(e,t,r)}const R=O;exports.$all=d,exports.$and=s,exports.$elemMatch=c,exports.$eq=b,exports.$exists=h,exports.$gt=w,exports.$gte=$,exports.$in=f,exports.$lt=y,exports.$lte=v,exports.$mod=x,exports.$ne=m,exports.$nin=u,exports.$nor=a,exports.$not=p,exports.$options=g,exports.$or=i,exports.$regex=E,exports.$size=l,exports.$where=j,exports.MongoQueryParser=class{constructor(e){this.t=void 0,this.o=void 0,this.t=Object.keys(e).reduce((t,r)=>(t[r]=Object.assign({},e[r],{name:r.slice(1)}),t),{}),this.parse=this.parse.bind(this),this.o={field:"",query:{},parse:this.parse}}setParse(e){this.parse=e,this.o.parse=e}s(e,t,r,o){const n=this.t[t];if(!n)throw new Error(`Unsupported operator "${t}"`);if("field"!==n.type)throw new Error(`Unexpected ${n.type} operator "${t}" at field level`);return this.o.field=e,this.o.query=o,q(n,r,this.o)}i(t,r){const o=[],n=Object.keys(r);for(let s=0,i=n.length;s<i;s++){const i=n[s];if("$"!==i[0])throw new Error(`Field query for "${t}" may contain only operators or a plain object as a value`);const a=this.s(t,i,r[i],r);a!==e.NULL_CONDITION&&o.push(a)}return o}parse(r,o){if(o&&o.field)return e.buildAnd(this.i(o.field,r));const n=r,s={query:n,parse:this.parse},i=[],a=Object.keys(n);for(let e=0,r=a.length;e<r;e++){const r=a[e],o=n[r],p="$"===r[0],c=this.t[r];if(p){if(!c)throw new Error(`Unsupported operator "${r}"`);if("document"!==c.type&&"compound"!==c.type)throw new Error(`Unknown top level operator "${r}"`);i.push(q(c,o,s))}else t(o)?i.push(...this.i(r,o)):i.push(this.s(r,"$eq",o,n))}return e.buildAnd(i)}},exports.allParsingInstructions=R,exports.defaultParsers=_;
//# sourceMappingURL=index.js.map

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

import{optimizedCompoundCondition as e,FieldCondition as t,CompoundCondition as r,ITSELF as o,NULL_CONDITION as n,DocumentCondition as i,buildAnd as a}from"@ucast/core";function s(e){if(!e||e&&e.constructor!==Object)return!1;for(const t in e)if(e.hasOwnProperty(t)&&"$"===t[0])return!0;return!1}function p(e,t){if(!Array.isArray(t))throw new Error(`"${e.name}" expects value to be an array`)}function c(e,t){if(p(e,t),!t.length)throw new Error(`"${e.name}" expects to have at least one element in array`)}const l=e=>(t,r)=>{if(typeof r!==e)throw new Error(`"${t.name}" expects value to be a "${e}"`)},f={type:"compound",validate:c,parse(t,r,{parse:o}){const n=r.map(e=>o(e));return e(t.name,n)}},d=f,u={type:"compound",validate:c},$={type:"field",validate(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error(`"${e.name}" expects to receive either regular expression or object of field operators`)},parse(e,o,n){const i=o instanceof RegExp?new t("regex",n.field,o):n.parse(o,n);return new r(e.name,[i])}},h={type:"field",validate(e,t){if(!t||t.constructor!==Object)throw new Error(`"${e.name}" expects to receive an object with nested query or field level operators`)},parse(e,r,{parse:n,field:i}){const a=s(r)?n(r,{field:o}):n(r);return new t(e.name,i,a)}},w={type:"field",validate:l("number")},y={type:"field",validate:p},v=y,b=y,m={type:"field",validate(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error(`"${e.name}" expects an array with 2 numeric elements`)}},x={type:"field",validate:l("boolean")},E={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error(`"${e.name}" expects value to be comparable (i.e., string, number or date)`)}},g=E,j=g,O=g,q={type:"field"},_=q,R={type:"field",validate(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error(`"${e.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(e,r,o){const n="string"==typeof r?new RegExp(r,o.query.$options||""):r;return new t(e.name,o.field,n)}},U={type:"field",parse:()=>n},A={type:"document",validate:l("function")};var F=Object.freeze({__proto__:null,$and:f,$or:d,$nor:u,$not:$,$elemMatch:h,$size:w,$in:y,$nin:v,$all:b,$mod:m,$exists:x,$gte:E,$gt:g,$lt:j,$lte:O,$eq:q,$ne:_,$regex:R,$options:U,$where:A});const k={compound(e,t,o){const n=(Array.isArray(t)?t:[t]).map(e=>o.parse(e));return new r(e.name,n)},field:(e,r,o)=>new t(e.name,o.field,r),document:(e,t)=>new i(e.name,t)};function z(e,t,r){"function"==typeof e.validate&&e.validate(e,t);return(e.parse||k[e.type])(e,t,r)}class D{constructor(e){this.t=void 0,this.o=void 0,this.t=Object.keys(e).reduce((t,r)=>(t[r]=Object.assign({},e[r],{name:r.slice(1)}),t),{}),this.parse=this.parse.bind(this),this.o={field:"",query:{},parse:this.parse}}i(e,t,r,o){const n=this.t[t];if(!n)throw new Error(`Unsupported operator "${t}"`);if("field"!==n.type)throw new Error(`Unexpected ${n.type} operator "${t}" at field level`);return this.o.field=e,this.o.query=o,z(n,r,this.o)}s(e,t){const r=[],o=Object.keys(t);for(let i=0,a=o.length;i<a;i++){const a=o[i];if("$"!==a[0])throw new Error(`Field query for "${e}" may contain only operators or a plain object as a value`);const s=this.i(e,a,t[a],t);s!==n&&r.push(s)}return r}parse(e,t){if(t&&t.field)return a(this.s(t.field,e));const r=e,o={query:r,parse:this.parse},n=[],i=Object.keys(r);for(let e=0,t=i.length;e<t;e++){const t=i[e],a=r[t],p="$"===t[0],c=this.t[t];if(p){if(!c)throw new Error(`Unsupported operator "${t}"`);if("document"!==c.type&&"compound"!==c.type)throw new Error(`Unknown top level operator "${t}"`);n.push(z(c,a,o))}else s(a)?n.push(...this.s(t,a)):n.push(this.i(t,"$eq",a,r))}return a(n)}}const M=F;export{b as $all,f as $and,h as $elemMatch,q as $eq,x as $exists,g as $gt,E as $gte,y as $in,j as $lt,O as $lte,m as $mod,_ as $ne,v as $nin,u as $nor,$ as $not,U as $options,d as $or,R as $regex,w as $size,A as $where,D as MongoQueryParser,M as allParsingInstructions,k as defaultParsers};
import{optimizedCompoundCondition as e,FieldCondition as t,CompoundCondition as r,ITSELF as o,NULL_CONDITION as n,DocumentCondition as i,buildAnd as a}from"@ucast/core";function s(e){if(!e||e&&e.constructor!==Object)return!1;for(const t in e)if(e.hasOwnProperty(t)&&"$"===t[0])return!0;return!1}function p(e,t){if(!Array.isArray(t))throw new Error(`"${e.name}" expects value to be an array`)}function c(e,t){if(p(e,t),!t.length)throw new Error(`"${e.name}" expects to have at least one element in array`)}const l=e=>(t,r)=>{if(typeof r!==e)throw new Error(`"${t.name}" expects value to be a "${e}"`)},f={type:"compound",validate:c,parse(t,r,{parse:o}){const n=r.map(e=>o(e));return e(t.name,n)}},d=f,u={type:"compound",validate:c},h={type:"field",validate(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error(`"${e.name}" expects to receive either regular expression or object of field operators`)},parse(e,o,n){const i=o instanceof RegExp?new t("regex",n.field,o):n.parse(o,n);return new r(e.name,[i])}},$={type:"field",validate(e,t){if(!t||t.constructor!==Object)throw new Error(`"${e.name}" expects to receive an object with nested query or field level operators`)},parse(e,r,{parse:n,field:i}){const a=s(r)?n(r,{field:o}):n(r);return new t(e.name,i,a)}},w={type:"field",validate:l("number")},y={type:"field",validate:p},v=y,b=y,m={type:"field",validate(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error(`"${e.name}" expects an array with 2 numeric elements`)}},x={type:"field",validate:l("boolean")},E={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error(`"${e.name}" expects value to be comparable (i.e., string, number or date)`)}},g=E,j=g,O=g,q={type:"field"},_=q,R={type:"field",validate(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error(`"${e.name}" expects value to be a regular expression or a string that represents regular expression`)},parse(e,r,o){const n="string"==typeof r?new RegExp(r,o.query.$options||""):r;return new t(e.name,o.field,n)}},U={type:"field",parse:()=>n},A={type:"document",validate:l("function")};var F=Object.freeze({__proto__:null,$and:f,$or:d,$nor:u,$not:h,$elemMatch:$,$size:w,$in:y,$nin:v,$all:b,$mod:m,$exists:x,$gte:E,$gt:g,$lt:j,$lte:O,$eq:q,$ne:_,$regex:R,$options:U,$where:A});const k={compound(e,t,o){const n=(Array.isArray(t)?t:[t]).map(e=>o.parse(e));return new r(e.name,n)},field:(e,r,o)=>new t(e.name,o.field,r),document:(e,t)=>new i(e.name,t)};function z(e,t,r){"function"==typeof e.validate&&e.validate(e,t);return(e.parse||k[e.type])(e,t,r)}class D{constructor(e){this.t=void 0,this.o=void 0,this.t=Object.keys(e).reduce((t,r)=>(t[r]=Object.assign({},e[r],{name:r.slice(1)}),t),{}),this.parse=this.parse.bind(this),this.o={field:"",query:{},parse:this.parse}}setParse(e){this.parse=e,this.o.parse=e}i(e,t,r,o){const n=this.t[t];if(!n)throw new Error(`Unsupported operator "${t}"`);if("field"!==n.type)throw new Error(`Unexpected ${n.type} operator "${t}" at field level`);return this.o.field=e,this.o.query=o,z(n,r,this.o)}s(e,t){const r=[],o=Object.keys(t);for(let i=0,a=o.length;i<a;i++){const a=o[i];if("$"!==a[0])throw new Error(`Field query for "${e}" may contain only operators or a plain object as a value`);const s=this.i(e,a,t[a],t);s!==n&&r.push(s)}return r}parse(e,t){if(t&&t.field)return a(this.s(t.field,e));const r=e,o={query:r,parse:this.parse},n=[],i=Object.keys(r);for(let e=0,t=i.length;e<t;e++){const t=i[e],a=r[t],p="$"===t[0],c=this.t[t];if(p){if(!c)throw new Error(`Unsupported operator "${t}"`);if("document"!==c.type&&"compound"!==c.type)throw new Error(`Unknown top level operator "${t}"`);n.push(z(c,a,o))}else s(a)?n.push(...this.s(t,a)):n.push(this.i(t,"$eq",a,r))}return a(n)}}const M=F;export{b as $all,f as $and,$ as $elemMatch,q as $eq,x as $exists,g as $gt,E as $gte,y as $in,j as $lt,O as $lte,m as $mod,_ as $ne,v as $nin,u as $nor,h as $not,U as $options,d as $or,R as $regex,w as $size,A as $where,D as MongoQueryParser,M as allParsingInstructions,k as defaultParsers};
//# sourceMappingURL=index.js.map

@@ -10,2 +10,3 @@ import { Condition, ParsingInstruction } from '@ucast/core';

constructor(instructions: Record<string, ParsingInstruction>);
setParse(parse: this['parse']): void;
private _parseField;

@@ -12,0 +13,0 @@ private _parseFieldOperators;

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ucast/core")):"function"==typeof define&&define.amd?define(["exports","@ucast/core"],t):t(((e=e||self).ucast=e.ucast||{},e.ucast.mongo={}),e.ucast.core)}(this,(function(e,t){"use strict";function r(e){if(!e||e&&e.constructor!==Object)return!1;for(var t in e)if(e.hasOwnProperty(t)&&"$"===t[0])return!0;return!1}function n(e,t){if(!Array.isArray(t))throw new Error('"'+e.name+'" expects value to be an array')}function o(e,t){if(n(e,t),!t.length)throw new Error('"'+e.name+'" expects to have at least one element in array')}var i=function(e){return function(t,r){if(typeof r!==e)throw new Error('"'+t.name+'" expects value to be a "'+e+'"')}},a={type:"compound",validate:o,parse:function(e,r,n){var o=n.parse,i=r.map((function(e){return o(e)}));return t.optimizedCompoundCondition(e.name,i)}},f=a,u={type:"compound",validate:o},c={type:"field",validate:function(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error('"'+e.name+'" expects to receive either regular expression or object of field operators')},parse:function(e,r,n){var o=r instanceof RegExp?new t.FieldCondition("regex",n.field,r):n.parse(r,n);return new t.CompoundCondition(e.name,[o])}},s={type:"field",validate:function(e,t){if(!t||t.constructor!==Object)throw new Error('"'+e.name+'" expects to receive an object with nested query or field level operators')},parse:function(e,n,o){var i=o.parse,a=o.field,f=r(n)?i(n,{field:t.ITSELF}):i(n);return new t.FieldCondition(e.name,a,f)}},p={type:"field",validate:i("number")},l={type:"field",validate:n},d=l,v=l,h={type:"field",validate:function(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error('"'+e.name+'" expects an array with 2 numeric elements')}},w={type:"field",validate:i("boolean")},y={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error('"'+e.name+'" expects value to be comparable (i.e., string, number or date)')}},$=y,b=$,x=$,m={type:"field"},E=m,g={type:"field",validate:function(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error('"'+e.name+'" expects value to be a regular expression or a string that represents regular expression')},parse:function(e,r,n){var o="string"==typeof r?new RegExp(r,n.query.$options||""):r;return new t.FieldCondition(e.name,n.field,o)}},j={type:"field",parse:function(){return t.NULL_CONDITION}},O={type:"document",validate:i("function")},q=Object.freeze({__proto__:null,$and:a,$or:f,$nor:u,$not:c,$elemMatch:s,$size:p,$in:l,$nin:d,$all:v,$mod:h,$exists:w,$gte:y,$gt:$,$lt:b,$lte:x,$eq:m,$ne:E,$regex:g,$options:j,$where:O});function _(){return(_=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var R={compound:function(e,r,n){var o=(Array.isArray(r)?r:[r]).map((function(e){return n.parse(e)}));return new t.CompoundCondition(e.name,o)},field:function(e,r,n){return new t.FieldCondition(e.name,n.field,r)},document:function(e,r){return new t.DocumentCondition(e.name,r)}};function U(e,t,r){return"function"==typeof e.validate&&e.validate(e,t),(e.parse||R[e.type])(e,t,r)}var A=function(){function e(e){this.t=void 0,this.o=void 0,this.t=Object.keys(e).reduce((function(t,r){return t[r]=_({},e[r],{name:r.slice(1)}),t}),{}),this.parse=this.parse.bind(this),this.o={field:"",query:{},parse:this.parse}}var n=e.prototype;return n.i=function(e,t,r,n){var o=this.t[t];if(!o)throw new Error('Unsupported operator "'+t+'"');if("field"!==o.type)throw new Error("Unexpected "+o.type+' operator "'+t+'" at field level');return this.o.field=e,this.o.query=n,U(o,r,this.o)},n.u=function(e,r){for(var n=[],o=Object.keys(r),i=0,a=o.length;i<a;i++){var f=o[i];if("$"!==f[0])throw new Error('Field query for "'+e+'" may contain only operators or a plain object as a value');var u=this.i(e,f,r[f],r);u!==t.NULL_CONDITION&&n.push(u)}return n},n.parse=function(e,n){if(n&&n.field)return t.buildAnd(this.u(n.field,e));for(var o=e,i={query:o,parse:this.parse},a=[],f=Object.keys(o),u=0,c=f.length;u<c;u++){var s=f[u],p=o[s],l="$"===s[0],d=this.t[s];if(l){if(!d)throw new Error('Unsupported operator "'+s+'"');if("document"!==d.type&&"compound"!==d.type)throw new Error('Unknown top level operator "'+s+'"');a.push(U(d,p,i))}else r(p)?a.push.apply(a,this.u(s,p)):a.push(this.i(s,"$eq",p,o))}return t.buildAnd(a)},e}(),M=q;e.$all=v,e.$and=a,e.$elemMatch=s,e.$eq=m,e.$exists=w,e.$gt=$,e.$gte=y,e.$in=l,e.$lt=b,e.$lte=x,e.$mod=h,e.$ne=E,e.$nin=d,e.$nor=u,e.$not=c,e.$options=j,e.$or=f,e.$regex=g,e.$size=p,e.$where=O,e.MongoQueryParser=A,e.allParsingInstructions=M,e.defaultParsers=R,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ucast/core")):"function"==typeof define&&define.amd?define(["exports","@ucast/core"],t):t(((e=e||self).ucast=e.ucast||{},e.ucast.mongo={}),e.ucast.core)}(this,(function(e,t){"use strict";function r(e){if(!e||e&&e.constructor!==Object)return!1;for(var t in e)if(e.hasOwnProperty(t)&&"$"===t[0])return!0;return!1}function n(e,t){if(!Array.isArray(t))throw new Error('"'+e.name+'" expects value to be an array')}function o(e,t){if(n(e,t),!t.length)throw new Error('"'+e.name+'" expects to have at least one element in array')}var i=function(e){return function(t,r){if(typeof r!==e)throw new Error('"'+t.name+'" expects value to be a "'+e+'"')}},a={type:"compound",validate:o,parse:function(e,r,n){var o=n.parse,i=r.map((function(e){return o(e)}));return t.optimizedCompoundCondition(e.name,i)}},f=a,u={type:"compound",validate:o},c={type:"field",validate:function(e,t){if(!(t&&(t instanceof RegExp||t.constructor===Object)))throw new Error('"'+e.name+'" expects to receive either regular expression or object of field operators')},parse:function(e,r,n){var o=r instanceof RegExp?new t.FieldCondition("regex",n.field,r):n.parse(r,n);return new t.CompoundCondition(e.name,[o])}},s={type:"field",validate:function(e,t){if(!t||t.constructor!==Object)throw new Error('"'+e.name+'" expects to receive an object with nested query or field level operators')},parse:function(e,n,o){var i=o.parse,a=o.field,f=r(n)?i(n,{field:t.ITSELF}):i(n);return new t.FieldCondition(e.name,a,f)}},p={type:"field",validate:i("number")},l={type:"field",validate:n},d=l,v=l,h={type:"field",validate:function(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error('"'+e.name+'" expects an array with 2 numeric elements')}},w={type:"field",validate:i("boolean")},y={type:"field",validate:function(e,t){if(!("string"==typeof t||"number"==typeof t||t instanceof Date))throw new Error('"'+e.name+'" expects value to be comparable (i.e., string, number or date)')}},$=y,b=$,x=$,m={type:"field"},E=m,g={type:"field",validate:function(e,t){if(!(t instanceof RegExp)&&"string"!=typeof t)throw new Error('"'+e.name+'" expects value to be a regular expression or a string that represents regular expression')},parse:function(e,r,n){var o="string"==typeof r?new RegExp(r,n.query.$options||""):r;return new t.FieldCondition(e.name,n.field,o)}},j={type:"field",parse:function(){return t.NULL_CONDITION}},O={type:"document",validate:i("function")},q=Object.freeze({__proto__:null,$and:a,$or:f,$nor:u,$not:c,$elemMatch:s,$size:p,$in:l,$nin:d,$all:v,$mod:h,$exists:w,$gte:y,$gt:$,$lt:b,$lte:x,$eq:m,$ne:E,$regex:g,$options:j,$where:O});function _(){return(_=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var R={compound:function(e,r,n){var o=(Array.isArray(r)?r:[r]).map((function(e){return n.parse(e)}));return new t.CompoundCondition(e.name,o)},field:function(e,r,n){return new t.FieldCondition(e.name,n.field,r)},document:function(e,r){return new t.DocumentCondition(e.name,r)}};function U(e,t,r){return"function"==typeof e.validate&&e.validate(e,t),(e.parse||R[e.type])(e,t,r)}var A=function(){function e(e){this.t=void 0,this.o=void 0,this.t=Object.keys(e).reduce((function(t,r){return t[r]=_({},e[r],{name:r.slice(1)}),t}),{}),this.parse=this.parse.bind(this),this.o={field:"",query:{},parse:this.parse}}var n=e.prototype;return n.setParse=function(e){this.parse=e,this.o.parse=e},n.i=function(e,t,r,n){var o=this.t[t];if(!o)throw new Error('Unsupported operator "'+t+'"');if("field"!==o.type)throw new Error("Unexpected "+o.type+' operator "'+t+'" at field level');return this.o.field=e,this.o.query=n,U(o,r,this.o)},n.u=function(e,r){for(var n=[],o=Object.keys(r),i=0,a=o.length;i<a;i++){var f=o[i];if("$"!==f[0])throw new Error('Field query for "'+e+'" may contain only operators or a plain object as a value');var u=this.i(e,f,r[f],r);u!==t.NULL_CONDITION&&n.push(u)}return n},n.parse=function(e,n){if(n&&n.field)return t.buildAnd(this.u(n.field,e));for(var o=e,i={query:o,parse:this.parse},a=[],f=Object.keys(o),u=0,c=f.length;u<c;u++){var s=f[u],p=o[s],l="$"===s[0],d=this.t[s];if(l){if(!d)throw new Error('Unsupported operator "'+s+'"');if("document"!==d.type&&"compound"!==d.type)throw new Error('Unknown top level operator "'+s+'"');a.push(U(d,p,i))}else r(p)?a.push.apply(a,this.u(s,p)):a.push(this.i(s,"$eq",p,o))}return t.buildAnd(a)},e}(),M=q;e.$all=v,e.$and=a,e.$elemMatch=s,e.$eq=m,e.$exists=w,e.$gt=$,e.$gte=y,e.$in=l,e.$lt=b,e.$lte=x,e.$mod=h,e.$ne=E,e.$nin=d,e.$nor=u,e.$not=c,e.$options=j,e.$or=f,e.$regex=g,e.$size=p,e.$where=O,e.MongoQueryParser=A,e.allParsingInstructions=M,e.defaultParsers=R,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map
{
"name": "@ucast/mongo",
"version": "2.1.2",
"version": "2.2.0",
"description": "git@github.com:stalniy/ucast.git",

@@ -5,0 +5,0 @@ "main": "dist/es6c/index.js",

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

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