@ucast/mongo
Advanced tools
Comparing version 2.3.3 to 2.4.0
@@ -5,2 +5,14 @@ # Change Log | ||
# [2.4.0](https://github.com/stalniy/ucast/compare/@ucast/mongo@2.3.3...@ucast/mongo@2.4.0) (2020-11-02) | ||
### Bug Fixes | ||
* **parser:** prevents mangling of `parseField` and `parseFieldOperators` methods of `ObjectQueryParser` ([3b4734b](https://github.com/stalniy/ucast/commit/3b4734b8ac46514aa46855f169e48708d5a9a4b3)) | ||
### Features | ||
* **parser:** extracts `ObjectQueryParser` out of `MongoQueryParser` into reusable piece ([38941dd](https://github.com/stalniy/ucast/commit/38941dd003dfb0ac9d9f7c867d49b0bbd0b5e716)) | ||
## [2.3.3](https://github.com/stalniy/ucast/compare/@ucast/mongo@2.3.2...@ucast/mongo@2.3.3) (2020-10-17) | ||
@@ -7,0 +19,0 @@ |
@@ -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({name:"$"===t[0]?t.slice(1):t},e[t]),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}; | ||
import{optimizedCompoundCondition as e,FieldCondition as t,CompoundCondition as r,ITSELF as n,NULL_CONDITION as o,buildAnd as a,ObjectQueryParser as i}from"@ucast/core";export{defaultInstructionParsers as defaultParsers}from"@ucast/core";function f(e,t){if(!Array.isArray(t))throw new Error('"'+e.name+'" expects value to be an array')}function u(e,t){if(f(e,t),!t.length)throw new Error('"'+e.name+'" expects to have at least one element in array')}var c=function(e){return function(t,r){if(typeof r!==e)throw new Error('"'+t.name+'" expects value to be a "'+e+'"')}},p={type:"compound",validate:u,parse:function(t,r,n){var o=n.parse,a=r.map((function(e){return o(e)}));return e(t.name,a)}},s=p,l={type:"compound",validate:u},d={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,n,o){var a=n instanceof RegExp?new t("regex",o.field,n):o.parse(n,o);return new r(e.name,[a])}},v={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,r,o){var a=o.parse,i=o.field,f=(0,o.hasOperators)(r)?a(r,{field:n}):a(r);return new t(e.name,i,f)}},w={type:"field",validate:c("number")},y={type:"field",validate:f},$=y,x=y,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')}},m={type:"field",validate:c("boolean")},g={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)')}},b=g,E=b,j=b,O={type:"field"},R=O,_={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(e.name,n.field,o)}},q={type:"field",parse:function(){return o}},A={type:"document",validate:c("function")},N=Object.freeze({__proto__:null,$and:p,$or:s,$nor:l,$not:d,$elemMatch:v,$size:w,$in:y,$nin:$,$all:x,$mod:h,$exists:m,$gte:g,$gt:b,$lt:E,$lte:j,$eq:O,$ne:R,$regex:_,$options:q,$where:A});var P=function(e){var t,r;function n(t){return e.call(this,t,{defaultOperatorName:"$eq",operatorToConditionName:function(e){return e.slice(1)}})||this}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n.prototype.parse=function(t,r){return r&&r.field?a(this.parseFieldOperators(r.field,t)):e.prototype.parse.call(this,t)},n}(i),z=N;export{x as $all,p as $and,v as $elemMatch,O as $eq,m as $exists,b as $gt,g as $gte,y as $in,E as $lt,j as $lte,h as $mod,R as $ne,$ as $nin,l as $nor,d as $not,q as $options,s as $or,_ as $regex,w as $size,A as $where,P as MongoQueryParser,z as allParsingInstructions}; | ||
//# 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`)}},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({name:"$"===r[0]?r.slice(1):r},e[r]),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=_; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@ucast/core");function t(e,t){if(!Array.isArray(t))throw new Error(`"${e.name}" expects value to be an array`)}function r(e,r){if(t(e,r),!r.length)throw new Error(`"${e.name}" expects to have at least one element in array`)}const o=e=>(t,r)=>{if(typeof r!==e)throw new Error(`"${t.name}" expects value to be a "${e}"`)},s={type:"compound",validate:r,parse(t,r,{parse:o}){const s=r.map(e=>o(e));return e.optimizedCompoundCondition(t.name,s)}},a=s,n={type:"compound",validate:r},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 s=r instanceof RegExp?new e.FieldCondition("regex",o.field,r):o.parse(r,o);return new e.CompoundCondition(t.name,[s])}},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(t,r,{parse:o,field:s,hasOperators:a}){const n=a(r)?o(r,{field:e.ITSELF}):o(r);return new e.FieldCondition(t.name,s,n)}},l={type:"field",validate:o("number")},c={type:"field",validate:t},x=c,f=c,u={type:"field",validate(e,t){if(!Array.isArray(t)||2!==t.length)throw new Error(`"${e.name}" expects an array with 2 numeric elements`)}},d={type:"field",validate:o("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"},g=b,h={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 s="string"==typeof r?new RegExp(r,o.query.$options||""):r;return new e.FieldCondition(t.name,o.field,s)}},m={type:"field",parse:()=>e.NULL_CONDITION},E={type:"document",validate:o("function")};var j=Object.freeze({__proto__:null,$and:s,$or:a,$nor:n,$not:p,$elemMatch:i,$size:l,$in:c,$nin:x,$all:f,$mod:u,$exists:d,$gte:$,$gt:w,$lt:y,$lte:v,$eq:b,$ne:g,$regex:h,$options:m,$where:E});class O extends e.ObjectQueryParser{constructor(e){super(e,{defaultOperatorName:"$eq",operatorToConditionName:e=>e.slice(1)})}parse(t,r){return r&&r.field?e.buildAnd(this.parseFieldOperators(r.field,t)):super.parse(t)}}const _=j;Object.defineProperty(exports,"defaultParsers",{enumerable:!0,get:function(){return e.defaultInstructionParsers}}),exports.$all=f,exports.$and=s,exports.$elemMatch=i,exports.$eq=b,exports.$exists=d,exports.$gt=w,exports.$gte=$,exports.$in=c,exports.$lt=y,exports.$lte=v,exports.$mod=u,exports.$ne=g,exports.$nin=x,exports.$nor=n,exports.$not=p,exports.$options=m,exports.$or=a,exports.$regex=h,exports.$size=l,exports.$where=E,exports.MongoQueryParser=O,exports.allParsingInstructions=_; | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,2 @@ import * as instructions from './instructions'; | ||
export * from './types'; | ||
export { defaultParsers } from './defaultParsers'; | ||
export { defaultInstructionParsers as defaultParsers } from '@ucast/core'; |
@@ -1,2 +0,2 @@ | ||
import { CompoundInstruction, FieldInstruction, DocumentInstruction, Comparable, FieldParsingContext } from '@ucast/core'; | ||
import { CompoundInstruction, FieldInstruction, DocumentInstruction, Comparable, FieldParsingContext, ObjectQueryFieldParsingContext } from '@ucast/core'; | ||
import { MongoQuery } from './types'; | ||
@@ -9,3 +9,3 @@ export declare const $and: CompoundInstruction<MongoQuery<any>[]>; | ||
export declare const $not: FieldInstruction<MongoQuery<any> | RegExp>; | ||
export declare const $elemMatch: FieldInstruction<MongoQuery<any>>; | ||
export declare const $elemMatch: FieldInstruction<MongoQuery<any>, ObjectQueryFieldParsingContext>; | ||
export declare const $size: FieldInstruction<number>; | ||
@@ -12,0 +12,0 @@ export declare const $in: FieldInstruction<unknown[]>; |
@@ -1,2 +0,2 @@ | ||
import { Condition, ParsingInstruction } from '@ucast/core'; | ||
import { Condition, ParsingInstruction, ObjectQueryParser, FieldQueryOperators } from '@ucast/core'; | ||
import { MongoQuery } from './types'; | ||
@@ -6,10 +6,5 @@ export interface ParseOptions { | ||
} | ||
export declare class MongoQueryParser { | ||
private readonly _instructions; | ||
private _fieldInstructionContext; | ||
export declare class MongoQueryParser extends ObjectQueryParser<MongoQuery<any>> { | ||
constructor(instructions: Record<string, ParsingInstruction>); | ||
setParse(parse: this['parse']): void; | ||
private _parseField; | ||
private _parseFieldOperators; | ||
parse<T extends MongoQuery<any>>(rawQuery: T, options?: ParseOptions): Condition; | ||
parse<Q extends MongoQuery<any>, FQ extends FieldQueryOperators<Q> = FieldQueryOperators<Q>>(query: Q | FQ, options?: ParseOptions): Condition; | ||
} |
@@ -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]=_({name:"$"===r[0]?r.slice(1):r},e[r]),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})})); | ||
!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,t){if(!Array.isArray(t))throw new Error('"'+e.name+'" expects value to be an array')}function n(e,t){if(r(e,t),!t.length)throw new Error('"'+e.name+'" expects to have at least one element in array')}var o=function(e){return function(t,r){if(typeof r!==e)throw new Error('"'+t.name+'" expects value to be a "'+e+'"')}},i={type:"compound",validate:n,parse:function(e,r,n){var o=n.parse,i=r.map((function(e){return o(e)}));return t.optimizedCompoundCondition(e.name,i)}},a=i,f={type:"compound",validate:n},u={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])}},c={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,r,n){var o=n.parse,i=n.field,a=(0,n.hasOperators)(r)?o(r,{field:t.ITSELF}):o(r);return new t.FieldCondition(e.name,i,a)}},s={type:"field",validate:o("number")},p={type:"field",validate:r},l=p,d=p,v={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')}},y={type:"field",validate:o("boolean")},w={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)')}},x=w,$=x,h=x,b={type:"field"},g=b,m={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)}},E={type:"field",parse:function(){return t.NULL_CONDITION}},j={type:"document",validate:o("function")},O=Object.freeze({__proto__:null,$and:i,$or:a,$nor:f,$not:u,$elemMatch:c,$size:s,$in:p,$nin:l,$all:d,$mod:v,$exists:y,$gte:w,$gt:x,$lt:$,$lte:h,$eq:b,$ne:g,$regex:m,$options:E,$where:j});var _=function(e){var r,n;function o(t){return e.call(this,t,{defaultOperatorName:"$eq",operatorToConditionName:function(e){return e.slice(1)}})||this}return n=e,(r=o).prototype=Object.create(n.prototype),r.prototype.constructor=r,r.__proto__=n,o.prototype.parse=function(r,n){return n&&n.field?t.buildAnd(this.parseFieldOperators(n.field,r)):e.prototype.parse.call(this,r)},o}(t.ObjectQueryParser),q=O;Object.defineProperty(e,"defaultParsers",{enumerable:!0,get:function(){return t.defaultInstructionParsers}}),e.$all=d,e.$and=i,e.$elemMatch=c,e.$eq=b,e.$exists=y,e.$gt=x,e.$gte=w,e.$in=p,e.$lt=$,e.$lte=h,e.$mod=v,e.$ne=g,e.$nin=l,e.$nor=f,e.$not=u,e.$options=E,e.$or=a,e.$regex=m,e.$size=s,e.$where=j,e.MongoQueryParser=_,e.allParsingInstructions=q,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@ucast/mongo", | ||
"version": "2.3.3", | ||
"version": "2.4.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
Sorry, the diff of this file is not supported yet
76965
18
141