Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mingo

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mingo - npm Package Compare versions

Comparing version 0.2.5 to 0.3.0

2

mingo-min.js

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

(function(){"use strict";function r(r){for(var t=0;t<s.length;t++)if(s[t](r))return e.isRegExp(r)?{$regex:r}:{$eq:r};if(e.isObject(r)){var n=e.keys(r),i=0===e.intersection($.queryOperators,n).length;if(i)return{$eq:r};if(e.contains(n,"$regex")){var o=r.$regex,u=r.$options||"",a="";e.isString(o)&&(a+=o.ignoreCase||u.indexOf("i")>=0?"i":"",a+=o.multiline||u.indexOf("m")>=0?"m":"",a+=o.global||u.indexOf("g")>=0?"g":"",o=new RegExp(o,a)),r.$regex=o,delete r.$options}}return r}var t,e,n=this,i={};null!=n&&(t=n.Mingo),i.noConflict=function(){return n.Mingo=t,i};var o="undefined"!=typeof exports&&"undefined"!=typeof module&&"undefined"!=typeof require&&"undefined"!=typeof process;"undefined"!=typeof exports?(exports="undefined"!=typeof module&&module.exports?module.exports=i:i,e=require("underscore")):(n.Mingo=i,e=n._);var s=[e.isString,e.isBoolean,e.isNumber,e.isDate,e.isNull,e.isRegExp],u={key:"_id"};if(i.setup=function(r){e.extend(u,r||{})},i.Query=function(r,t){return this instanceof i.Query?(this._criteria=r,this._projection=t,this._compiled=[],this._compile(),void 0):new i.Query(r,t)},i.Query.prototype={_compile:function(){if(!e.isEmpty(this._criteria)){if(e.isArray(this._criteria)||e.isFunction(this._criteria)||!e.isObject(this._criteria))throw new Error("Invalid type for criteria");for(var t in this._criteria)if(this._criteria.hasOwnProperty(t)){var n=this._criteria[t];if(e.contains($.compoundOperators,t)){if(e.contains(["$not"],t))throw new Error("Invalid operator");this._processOperator(t,t,n)}else{n=r(n);for(var i in n)n.hasOwnProperty(i)&&this._processOperator(t,i,n[i])}}}},_processOperator:function(r,t,n){var o;if(e.contains($.simpleOperators,t))o={test:function(e){var o=i._resolve(e,r);return l[t](o,n)}};else{if(!e.contains($.compoundOperators,t))throw new Error("Invalid query operator '"+t+"' detected");o=h[t](r,n)}this._compiled.push(o)},test:function(r){for(var t=0;t<this._compiled.length;t++)if(!this._compiled[t].test(r))return!1;return!0},find:function(r,t){return new i.Cursor(r,this,t)},remove:function(r){for(var t=[],e=0;e<r.length;e++)this.test(r[e])||t.push(r[e]);return t}},o){var a=require("stream").Transform,c=require("util");i.Query.prototype.stream=function(r){return new i.Stream(this,r)},i.Stream=function(r,t){return this instanceof i.Stream?(t=t||{},e.extend(t,{objectMode:!0}),a.call(this,t),this._query=r,void 0):new i.Stream(r,t)},c.inherits(i.Stream,a),i.Stream.prototype._transform=function(r,t,n){if(e.isObject(r)&&this._query.test(r))if(e.isEmpty(this._query._projection))this.push(r);else{var o=new i.Cursor([r],this._query);o.hasNext()&&this.push(o.next())}n()}}i.Cursor=function(r,t,e){return this instanceof i.Cursor?(this._query=t,this._collection=r,this._projection=e||t._projection,this._operators={},this._result=!1,this._position=0,void 0):new i.Cursor(r,t,e)},i.Cursor.prototype={_fetch:function(){var r=this;if(this._result!==!1)return this._result;if(e.isObject(this._projection)&&e.extend(this._operators,{$project:this._projection}),!e.isArray(this._collection))throw new Error("Input collection is not of a valid type.");this._result=e.filter(this._collection,this._query.test,this._query);var t=[];if(e.each(["$sort","$skip","$limit","$project"],function(n){e.has(r._operators,n)&&t.push(e.pick(r._operators,n))}),t.length>0){var n=new i.Aggregator(t);this._result=n.run(this._result,this._query)}return this._result},all:function(){return this._fetch()},first:function(){return this.count()>0?this._fetch()[0]:null},last:function(){return this.count()>0?this._fetch()[this.count()-1]:null},count:function(){return this._fetch().length},skip:function(r){return e.extend(this._operators,{$skip:r}),this},limit:function(r){return e.extend(this._operators,{$limit:r}),this},sort:function(r){return e.extend(this._operators,{$sort:r}),this},next:function(){return this.hasNext()?this._fetch()[this._position++]:null},hasNext:function(){return this.count()>this._position},max:function(r){return v.$max(this._fetch(),r)},min:function(r){return v.$min(this._fetch(),r)},map:function(r){return e.map(this._fetch(),r)},forEach:function(r){e.each(this._fetch(),r)}},i.Aggregator=function(r){return this instanceof i.Aggregator?(this._operators=r,void 0):new i.Aggregator(r)},i.Aggregator.prototype={run:function(r,t){if(!e.isEmpty(this._operators))for(var n=0;n<this._operators.length;n++){var i=this._operators[n];for(var o in i)i.hasOwnProperty(o)&&(r=t?f[o].call(t,r,i[o]):f[o](r,i[o]))}return r}},i._get=function(r,t){return e.result(r,t)},i._resolve=function(r,t){if(!t)return void 0;for(var n,o=t.split("."),s=r,u=0;u<o.length;u++){if(n=null===o[u].match(/^\d+$/),n&&e.isArray(s)){var a=[];e.each(s,function(r){e.isObject(r)&&a.push(i._resolve(r,o[u]))}),s=a}else s=i._get(s,o[u]);if(void 0===s)break}return s},i.compile=function(r,t){return new i.Query(r,t)},i.find=function(r,t,e){return new i.Query(t).find(r,e)},i.remove=function(r,t){return new i.Query(t).remove(r)},i.aggregate=function(r,t){if(!e.isArray(t))throw new Error("Aggregation pipeline must be an array");return new i.Aggregator(t).run(r)},i.CollectionMixin={query:function(r,t){return i.find(this.toJSON(),r,t)},aggregate:function(r){var t=[this.toJSON(),r];return i.aggregate.apply(null,t)}};var f={$group:function(r,t){var n=t[u.key],i=[],o=e.groupBy(r,function(r){var t=_(r,n,n);return i.push(t),t});i=e.uniq(i),t=e.omit(t,u.key);var s=[];return e.each(i,function(r){var e={};e[u.key]=r;for(var n in t)t.hasOwnProperty(n)&&(e[n]=m(o[r],n,t[n]));s.push(e)}),s},$match:function(r,t){var e=new i.Query(t);return e.find(r).all()},$project:function(r,t){if(e.isEmpty(t))return r;var n=[],i=e.keys(t);if(e.contains(i,u.key)){var o=t[u.key];(0===o||o===!1)&&(i=e.without(i,u.key))}else i.push(u.key);for(var s=0;s<r.length;s++){var a=r[s],c={};e.each(i,function(r){var n,i=t[r];if(r===u.key&&e.isEmpty(i))n=a[r];else if(e.isString(i))n=_(a,i,r);else if(1===i||i===!0)n=e.result(a,r);else if(e.isObject(i)){var o=e.keys(i);if(o=o.length>1?!1:o[0],o!==!1&&e.contains($.projectionOperators,o)){var s=p[o](a,i[o],r);e.isUndefined(s)||(n=s)}else n=_(a,i,r)}void 0!==n&&(c[r]=e.isObject(n)?e.clone(n):n)}),n.push(c)}return n},$limit:function(r,t){return e.first(r,t)},$skip:function(r,t){return e.rest(r,t)},$unwind:function(r,t){for(var n=[],o=t.substr(1),s=0;s<r.length;s++){var u=r[s],a=i._get(u,o);if(!e.isArray(a))throw new Error("Target field '"+o+"' is not of type Array.");e.each(a,function(r){var t=e.clone(u);t[o]=r,n.push(t)})}return n},$sort:function(r,t){if(!e.isEmpty(t)&&e.isObject(t)){var n=e.keys(t);n.reverse().forEach(function(n){var o=[],s=e.groupBy(r,function(r){var t=i._resolve(r,n);return o.push(t),t});o=e.sortBy(e.uniq(o),function(r){return r}),-1===t[n]&&o.reverse(),r=[],e.each(o,function(t){Array.prototype.push.apply(r,s[t])})})}return r}},h={$and:function(r,t){if(!e.isArray(t))throw new Error("Invalid expression for $and criteria");var n=[];return e.each(t,function(r){n.push(new i.Query(r))}),{test:function(r){for(var t=0;t<n.length;t++)if(!n[t].test(r))return!1;return!0}}},$or:function(r,t){if(!e.isArray(t))throw new Error("Invalid expression for $or criteria");var n=[];return e.each(t,function(r){n.push(new i.Query(r))}),{test:function(r){for(var t=0;t<n.length;t++)if(n[t].test(r))return!0;return!1}}},$nor:function(r,t){if(!e.isArray(t))throw new Error("Invalid expression for $nor criteria");var n=this.$or("$or",t);return{test:function(r){return!n.test(r)}}},$not:function(t,e){var n={};n[t]=r(e);var o=new i.Query(n);return{test:function(r){return!o.test(r)}}},$where:function(r,t){return e.isFunction(t)||(t=new Function("return "+t+";")),{test:function(r){return t.call(r)===!0}}}},l={$eq:function(r,t){return r=e.isArray(r)?r:[r],r=e.find(r,function(r){return e.isEqual(r,t)}),void 0!==r},$ne:function(r,t){return!this.$eq(r,t)},$in:function(r,t){return r=e.isArray(r)?r:[r],e.intersection(r,t).length>0},$nin:function(r,t){return e.isUndefined(r)||!this.$in(r,t)},$lt:function(r,t){return r=e.isArray(r)?r:[r],r=e.find(r,function(r){return t>r}),void 0!==r},$lte:function(r,t){return r=e.isArray(r)?r:[r],r=e.find(r,function(r){return t>=r}),void 0!==r},$gt:function(r,t){return r=e.isArray(r)?r:[r],r=e.find(r,function(r){return r>t}),void 0!==r},$gte:function(r,t){return r=e.isArray(r)?r:[r],r=e.find(r,function(r){return r>=t}),void 0!==r},$mod:function(r,t){return r=e.isArray(r)?r:[r],r=e.find(r,function(r){return e.isNumber(r)&&e.isArray(t)&&2===t.length&&r%t[0]===t[1]}),void 0!==r},$regex:function(r,t){return r=e.isArray(r)?r:[r],r=e.find(r,function(r){return e.isString(r)&&e.isRegExp(t)&&!!r.match(t)}),void 0!==r},$exists:function(r,t){return t===!1&&e.isUndefined(r)||t===!0&&!e.isUndefined(r)},$all:function(r,t){var n=this,i=!1;if(e.isArray(r)&&e.isArray(t))for(var o=0;o<t.length;o++){if(!e.isObject(t[o])||!e.contains(e.keys(t[o]),"$elemMatch"))return e.intersection(t,r).length===t.length;i=i||n.$elemMatch(r,t[o].$elemMatch)}return i},$size:function(r,t){return e.isArray(r)&&e.isNumber(t)&&r.length===t},$elemMatch:function(r,t){if(e.isArray(r)&&!e.isEmpty(r))for(var n=new i.Query(t),o=0;o<r.length;o++)if(n.test(r[o]))return!0;return!1},$type:function(r,t){switch(t){case 1:return e.isNumeric(r)&&-1!==(r+"").indexOf(".");case 2:case 5:return e.isString(r);case 3:return e.isObject(r);case 4:return e.isArray(r);case 8:return e.isBoolean(r);case 9:return e.isDate(r);case 10:return e.isNull(r);case 11:return e.isRegExp(r);case 16:return e.isNumeric(r)&&2147483647>=r&&-1===(r+"").indexOf(".");case 18:return e.isNumeric(r)&&r>2147483647&&0x8000000000000000>=r&&-1===(r+"").indexOf(".");default:return!1}}},p={$:function(){throw new Error("$ not implemented")},$elemMatch:function(r,t,n){var o=i._resolve(r,n),s=new i.Query(t);if(e.isUndefined(o)||!e.isArray(o))return void 0;for(var u=0;u<o.length;u++)if(s.test(o[u]))return o[u];return void 0},$slice:function(r,t,n){var o=i._resolve(r,n);return e.isUndefined(o)?void 0:(e.isArray(t)||(t=[t]),Array.prototype.slice.apply(o,t))}},v={$addToSet:function(r,t){var n=e.map(r,function(r){return _(r,t)});return e.uniq(n)},$sum:function(r,t){return e.isNumber(t)?r.length*t:e.reduce(r,function(r,e){return r+_(e,t)},0)},$max:function(r,t){var n=e.max(r,function(r){return _(r,t)});return _(n,t)},$min:function(r,t){var n=e.min(r,function(r){return _(r,t)});return _(n,t)},$avg:function(r,t){return this.$sum(r,t)/r.length},$push:function(r,t){return e.map(r,function(r){return _(r,t)})},$first:function(r,t){return r.length>0?_(r[0],t):void 0},$last:function(r,t){return r.length>0?_(r[r.length-1],t):void 0}},g={$add:function(r,t){var n=_(r,t);return e.reduce(n,function(r,t){return r+t},0)},$subtract:function(r,t){var e=_(r,t);return e[0]-e[1]},$divide:function(r,t){var e=_(r,t);return e[0]/e[1]},$multiply:function(r,t){var n=_(r,t);return e.reduce(n,function(r,t){return r*t},1)},$mod:function(r,t){var e=_(r,t);return e[0]%e[1]},$cmp:function(r,t){var e=_(r,t);return e[0]>e[1]?1:e[0]<e[1]?-1:0},$concat:function(r,t){var n=_(r,t);return e.contains(n,null)||e.contains(n,void 0)?null:n.join("")},$strcasecmp:function(r,t){var n=_(r,t);return n[0]=e.isEmpty(n[0])?"":n[0].toUpperCase(),n[1]=e.isEmpty(n[1])?"":n[1].toUpperCase(),n[0]>n[1]?1:n[0]<n[1]?-1:0},$substr:function(r,t){var n=_(r,t);return e.isString(n[0])?n[1]<0?"":n[2]<0?n[0].substr(n[1]):n[0].substr(n[1],n[2]):""},$toLower:function(r,t){var n=_(r,t);return e.isEmpty(n)?"":n.toLowerCase()},$toUpper:function(r,t){var n=_(r,t);return e.isEmpty(n)?"":n.toUpperCase()}},y={$setEquals:function(r,t){var n=_(r,t),i=e.uniq(n[0]),o=e.uniq(n[1]);return i.length!==o.length?!1:0==e.difference(i,o).length},$setIntersection:function(r,t){var n=_(r,t);return e.intersection(n[0],n[1])},$setDifference:function(r,t){var n=_(r,t);return e.difference(n[0],n[1])},$setUnion:function(r,t){var n=_(r,t);return e.union(n[0],n[1])},$setIsSubset:function(r,t){var n=_(r,t);return e.intersection(n[0],n[1]).length===n[0].length},$anyElementTrue:function(r,t){for(var e=_(r,t)[0],n=0;n<e.length;n++)if(e[n])return!0;return!1},$allElementsTrue:function(r,t){for(var e=_(r,t)[0],n=0;n<e.length;n++)if(!e[n])return!1;return!0}},d={$cond:function(r,t){var n,i,o;if(e.isArray(t)){if(3!=t.length)throw new Error("Invalid arguments for $cond operator");n=t[0],i=t[1],o=t[2]}else e.isObject(t)&&(n=t["if"],i=t.then,o=t["else"]);var s=_(r,n);return s?_(r,i):_(r,o)},$ifNull:function(r,t){if(!e.isArray(t)||2!=t.length)throw new Error("Invalid arguments for $ifNull operator");var n=_(r,t);return null===n[0]||void 0===n[0]?n[1]:n[0]}};e.each(["$eq","$ne","$gt","$gte","$lt","$lte"],function(r){g[r]=function(t,e){var n=_(t,e);return l[r](n[0],n[1])}}),e.extend(g,y,d);var $={simpleOperators:e.keys(l),compoundOperators:e.keys(h),setOperators:e.keys(y),aggregateOperators:e.keys(g),groupOperators:e.keys(v),pipelineOperators:e.keys(f),projectionOperators:e.keys(p)};$.queryOperators=e.union($.simpleOperators,$.compoundOperators);var m=function(r,t,n){if(e.contains($.groupOperators,t))return v[t](r,n);if(e.isObject(n)){var i={};for(var o in n)if(n.hasOwnProperty(o)&&(i[o]=m(r,o,n[o]),e.contains($.groupOperators,o))){if(i=i[o],e.keys(n).length>1)throw new Error("Invalid $group expression '"+JSON.stringify(n)+"'");break}return i}return void 0},_=function(r,t,n){if(e.contains($.aggregateOperators,n))return g[n](r,t);if(e.isString(t)&&t.length>0&&"$"===t[0])return i._resolve(r,t.slice(1));var o;if(e.isArray(t)){o=[];for(var u=0;u<t.length;u++)o.push(_(r,t[u],null))}else if(e.isObject(t)){o={};for(var a in t)if(t.hasOwnProperty(a)&&(o[a]=_(r,t[a],a),e.contains($.aggregateOperators,a))){if(o=o[a],e.keys(t).length>1)throw new Error("Invalid aggregation expression '"+JSON.stringify(t)+"'");break}}else for(var u=0;u<s.length;u++)if(s[u](t))return t;return o}}).call(this);
!function(r,t){"use strict";function e(r){for(var t=0;t<u.length;t++)if(u[t](r))return i.isRegExp(r)?{$regex:r}:{$eq:r};if(i.isObject(r)){var e=i.keys(r),n=0===i.intersection(m.queryOperators,e).length;if(n)return{$eq:r};if(i.contains(e,"$regex")){var o=r.$regex,s=r.$options||"",a="";i.isString(o)&&(a+=o.ignoreCase||s.indexOf("i")>=0?"i":"",a+=o.multiline||s.indexOf("m")>=0?"m":"",a+=o.global||s.indexOf("g")>=0?"g":"",o=new RegExp(o,a)),r.$regex=o,delete r.$options}}return r}var n,i,o={};null!=r&&(n=r.Mingo),o.noConflict=function(){return r.Mingo=n,o};var s="undefined"!=typeof exports&&"undefined"!=typeof require;s?(exports="undefined"!=typeof module&&module.exports?module.exports=o:o,i=require("underscore")):(r.Mingo=o,i=r._);var u=[i.isString,i.isBoolean,i.isNumber,i.isDate,i.isNull,i.isRegExp],a={key:"_id"};if(o.setup=function(r){i.extend(a,r||{})},o.Query=function(r,t){return this instanceof o.Query?(this._criteria=r,this._projection=t,this._compiled=[],void this._compile()):new o.Query(r,t)},o.Query.prototype={_compile:function(){if(!i.isEmpty(this._criteria)){if(i.isArray(this._criteria)||i.isFunction(this._criteria)||!i.isObject(this._criteria))throw new Error("Invalid type for criteria");for(var r in this._criteria)if(this._criteria.hasOwnProperty(r)){var t=this._criteria[r];if(i.contains(m.compoundOperators,r)){if(i.contains(["$not"],r))throw new Error("Invalid operator");this._processOperator(r,r,t)}else{t=e(t);for(var n in t)t.hasOwnProperty(n)&&this._processOperator(r,n,t[n])}}}},_processOperator:function(r,t,e){var n;if(i.contains(m.simpleOperators,t))n={test:function(n){var i=o._resolve(n,r);return p[t](i,e)}};else{if(!i.contains(m.compoundOperators,t))throw new Error("Invalid query operator '"+t+"' detected");n=l[t](r,e)}this._compiled.push(n)},test:function(r){for(var t=0;t<this._compiled.length;t++)if(!this._compiled[t].test(r))return!1;return!0},find:function(r,t){return new o.Cursor(r,this,t)},remove:function(r){for(var t=[],e=0;e<r.length;e++)this.test(r[e])||t.push(r[e]);return t}},s){var c=require("stream").Transform,f=require("util");o.Query.prototype.stream=function(r){return new o.Stream(this,r)},o.Stream=function(r,t){return this instanceof o.Stream?(t=t||{},i.extend(t,{objectMode:!0}),c.call(this,t),void(this._query=r)):new o.Stream(r,t)},f.inherits(o.Stream,c),o.Stream.prototype._transform=function(r,t,e){if(i.isObject(r)&&this._query.test(r))if(i.isEmpty(this._query._projection))this.push(r);else{var n=new o.Cursor([r],this._query);n.hasNext()&&this.push(n.next())}e()}}o.Cursor=function(r,t,e){return this instanceof o.Cursor?(this._query=t,this._collection=r,this._projection=e||t._projection,this._operators={},this._result=!1,void(this._position=0)):new o.Cursor(r,t,e)},o.Cursor.prototype={_fetch:function(){var r=this;if(this._result!==!1)return this._result;if(i.isObject(this._projection)&&i.extend(this._operators,{$project:this._projection}),!i.isArray(this._collection))throw new Error("Input collection is not of a valid type.");this._result=i.filter(this._collection,this._query.test,this._query);var t=[];if(i.each(["$sort","$skip","$limit","$project"],function(e){i.has(r._operators,e)&&t.push(i.pick(r._operators,e))}),t.length>0){var e=new o.Aggregator(t);this._result=e.run(this._result,this._query)}return this._result},all:function(){return this._fetch()},first:function(){return this.count()>0?this._fetch()[0]:null},last:function(){return this.count()>0?this._fetch()[this.count()-1]:null},count:function(){return this._fetch().length},skip:function(r){return i.extend(this._operators,{$skip:r}),this},limit:function(r){return i.extend(this._operators,{$limit:r}),this},sort:function(r){return i.extend(this._operators,{$sort:r}),this},next:function(){return this.hasNext()?this._fetch()[this._position++]:null},hasNext:function(){return this.count()>this._position},max:function(r){return y.$max(this._fetch(),r)},min:function(r){return y.$min(this._fetch(),r)},map:function(r){return i.map(this._fetch(),r)},forEach:function(r){i.each(this._fetch(),r)}},o.Aggregator=function(r){return this instanceof o.Aggregator?void(this._operators=r):new o.Aggregator(r)},o.Aggregator.prototype={run:function(r,t){if(!i.isEmpty(this._operators))for(var e=0;e<this._operators.length;e++){var n=this._operators[e];for(var o in n)n.hasOwnProperty(o)&&(r=t?h[o].call(t,r,n[o]):h[o](r,n[o]))}return r}},o._get=function(r,t){return i.result(r,t)},o._resolve=function(r,e){if(!e)return t;for(var n,s=e.split("."),u=r,a=0;a<s.length;a++){if(n=null===s[a].match(/^\d+$/),n&&i.isArray(u)){var c=[];i.each(u,function(r){i.isObject(r)&&c.push(o._resolve(r,s[a]))}),u=c}else u=o._get(u,s[a]);if(u===t)break}return u},o.compile=function(r,t){return new o.Query(r,t)},o.find=function(r,t,e){return new o.Query(t).find(r,e)},o.remove=function(r,t){return new o.Query(t).remove(r)},o.aggregate=function(r,t){if(!i.isArray(t))throw new Error("Aggregation pipeline must be an array");return new o.Aggregator(t).run(r)},o.CollectionMixin={query:function(r,t){return o.find(this.toJSON(),r,t)},aggregate:function(r){var t=[this.toJSON(),r];return o.aggregate.apply(null,t)}};var h={$group:function(r,t){var e=t[a.key],n=[],o=i.groupBy(r,function(r){var t=w(r,e,e);return n.push(t),t});n=i.uniq(n),t=i.omit(t,a.key);var s=[];return i.each(n,function(r){var e={};e[a.key]=r;for(var n in t)t.hasOwnProperty(n)&&(e[n]=_(o[r],n,t[n]));s.push(e)}),s},$match:function(r,t){var e=new o.Query(t);return e.find(r).all()},$project:function(r,e){if(i.isEmpty(e))return r;var n=[],o=i.keys(e);if(i.contains(o,a.key)){var s=e[a.key];(0===s||s===!1)&&(o=i.without(o,a.key))}else o.push(a.key);for(var u=0;u<r.length;u++){var c=r[u],f={};i.each(o,function(r){var n,o=e[r];if(r===a.key&&i.isEmpty(o))n=c[r];else if(i.isString(o))n=w(c,o,r);else if(1===o||o===!0)n=i.result(c,r);else if(i.isObject(o)){var s=i.keys(o);if(s=s.length>1?!1:s[0],s!==!1&&i.contains(m.projectionOperators,s)){var u=g[s](c,o[s],r);i.isUndefined(u)||(n=u)}else n=w(c,o,r)}n!==t&&(f[r]=i.isObject(n)?i.clone(n):n)}),n.push(f)}return n},$limit:function(r,t){return i.first(r,t)},$skip:function(r,t){return i.rest(r,t)},$unwind:function(r,t){for(var e=[],n=t.substr(1),s=0;s<r.length;s++){var u=r[s],a=o._get(u,n);if(!i.isArray(a))throw new Error("Target field '"+n+"' is not of type Array.");i.each(a,function(r){var t=i.clone(u);t[n]=r,e.push(t)})}return e},$sort:function(r,t){if(!i.isEmpty(t)&&i.isObject(t)){var e=i.keys(t);e.reverse().forEach(function(e){var n=[],s=i.groupBy(r,function(r){var t=o._resolve(r,e);return n.push(t),t});n=i.sortBy(i.uniq(n),function(r){return r}),-1===t[e]&&n.reverse(),r=[],i.each(n,function(t){Array.prototype.push.apply(r,s[t])})})}return r}},l={$and:function(r,t){if(!i.isArray(t))throw new Error("Invalid expression for $and criteria");var e=[];return i.each(t,function(r){e.push(new o.Query(r))}),{test:function(r){for(var t=0;t<e.length;t++)if(!e[t].test(r))return!1;return!0}}},$or:function(r,t){if(!i.isArray(t))throw new Error("Invalid expression for $or criteria");var e=[];return i.each(t,function(r){e.push(new o.Query(r))}),{test:function(r){for(var t=0;t<e.length;t++)if(e[t].test(r))return!0;return!1}}},$nor:function(r,t){if(!i.isArray(t))throw new Error("Invalid expression for $nor criteria");var e=this.$or("$or",t);return{test:function(r){return!e.test(r)}}},$not:function(r,t){var n={};n[r]=e(t);var i=new o.Query(n);return{test:function(r){return!i.test(r)}}},$where:function(r,t){return i.isFunction(t)||(t=new Function("return "+t+";")),{test:function(r){return t.call(r)===!0}}}},p={$eq:function(r,e){return r=i.isArray(r)?r:[r],r=i.find(r,function(r){return i.isEqual(r,e)}),r!==t},$ne:function(r,t){return!this.$eq(r,t)},$in:function(r,t){return r=i.isArray(r)?r:[r],i.intersection(r,t).length>0},$nin:function(r,t){return i.isUndefined(r)||!this.$in(r,t)},$lt:function(r,e){return r=i.isArray(r)?r:[r],r=i.find(r,function(r){return e>r}),r!==t},$lte:function(r,e){return r=i.isArray(r)?r:[r],r=i.find(r,function(r){return e>=r}),r!==t},$gt:function(r,e){return r=i.isArray(r)?r:[r],r=i.find(r,function(r){return r>e}),r!==t},$gte:function(r,e){return r=i.isArray(r)?r:[r],r=i.find(r,function(r){return r>=e}),r!==t},$mod:function(r,e){return r=i.isArray(r)?r:[r],r=i.find(r,function(r){return i.isNumber(r)&&i.isArray(e)&&2===e.length&&r%e[0]===e[1]}),r!==t},$regex:function(r,e){return r=i.isArray(r)?r:[r],r=i.find(r,function(r){return i.isString(r)&&i.isRegExp(e)&&!!r.match(e)}),r!==t},$exists:function(r,t){return t===!1&&i.isUndefined(r)||t===!0&&!i.isUndefined(r)},$all:function(r,t){var e=this,n=!1;if(i.isArray(r)&&i.isArray(t))for(var o=0;o<t.length;o++){if(!i.isObject(t[o])||!i.contains(i.keys(t[o]),"$elemMatch"))return i.intersection(t,r).length===t.length;n=n||e.$elemMatch(r,t[o].$elemMatch)}return n},$size:function(r,t){return i.isArray(r)&&i.isNumber(t)&&r.length===t},$elemMatch:function(r,t){if(i.isArray(r)&&!i.isEmpty(r))for(var e=new o.Query(t),n=0;n<r.length;n++)if(e.test(r[n]))return!0;return!1},$type:function(r,t){switch(t){case 1:return i.isNumeric(r)&&-1!==(r+"").indexOf(".");case 2:case 5:return i.isString(r);case 3:return i.isObject(r);case 4:return i.isArray(r);case 8:return i.isBoolean(r);case 9:return i.isDate(r);case 10:return i.isNull(r);case 11:return i.isRegExp(r);case 16:return i.isNumeric(r)&&2147483647>=r&&-1===(r+"").indexOf(".");case 18:return i.isNumeric(r)&&r>2147483647&&0x8000000000000000>=r&&-1===(r+"").indexOf(".");default:return!1}}},g={$:function(){throw new Error("$ not implemented")},$elemMatch:function(r,e,n){var s=o._resolve(r,n),u=new o.Query(e);if(i.isUndefined(s)||!i.isArray(s))return t;for(var a=0;a<s.length;a++)if(u.test(s[a]))return s[a];return t},$slice:function(r,e,n){var s=o._resolve(r,n);return i.isUndefined(s)?t:(i.isArray(e)||(e=[e]),Array.prototype.slice.apply(s,e))}},y={$addToSet:function(r,t){var e=i.map(r,function(r){return w(r,t)});return i.uniq(e)},$sum:function(r,t){return i.isNumber(t)?r.length*t:i.reduce(r,function(r,e){return r+w(e,t)},0)},$max:function(r,t){var e=i.max(r,function(r){return w(r,t)});return w(e,t)},$min:function(r,t){var e=i.min(r,function(r){return w(r,t)});return w(e,t)},$avg:function(r,t){return this.$sum(r,t)/r.length},$push:function(r,t){return i.map(r,function(r){return w(r,t)})},$first:function(r,e){return r.length>0?w(r[0],e):t},$last:function(r,e){return r.length>0?w(r[r.length-1],e):t}},v={$add:function(r,t){var e=w(r,t);return i.reduce(e,function(r,t){return r+t},0)},$subtract:function(r,t){var e=w(r,t);return e[0]-e[1]},$divide:function(r,t){var e=w(r,t);return e[0]/e[1]},$multiply:function(r,t){var e=w(r,t);return i.reduce(e,function(r,t){return r*t},1)},$mod:function(r,t){var e=w(r,t);return e[0]%e[1]},$cmp:function(r,t){var e=w(r,t);return e[0]>e[1]?1:e[0]<e[1]?-1:0},$concat:function(r,e){var n=w(r,e);return i.contains(n,null)||i.contains(n,t)?null:n.join("")},$strcasecmp:function(r,t){var e=w(r,t);return e[0]=i.isEmpty(e[0])?"":e[0].toUpperCase(),e[1]=i.isEmpty(e[1])?"":e[1].toUpperCase(),e[0]>e[1]?1:e[0]<e[1]?-1:0},$substr:function(r,t){var e=w(r,t);return i.isString(e[0])?e[1]<0?"":e[2]<0?e[0].substr(e[1]):e[0].substr(e[1],e[2]):""},$toLower:function(r,t){var e=w(r,t);return i.isEmpty(e)?"":e.toLowerCase()},$toUpper:function(r,t){var e=w(r,t);return i.isEmpty(e)?"":e.toUpperCase()}},$={$setEquals:function(r,t){var e=w(r,t),n=i.uniq(e[0]),o=i.uniq(e[1]);return n.length!==o.length?!1:0==i.difference(n,o).length},$setIntersection:function(r,t){var e=w(r,t);return i.intersection(e[0],e[1])},$setDifference:function(r,t){var e=w(r,t);return i.difference(e[0],e[1])},$setUnion:function(r,t){var e=w(r,t);return i.union(e[0],e[1])},$setIsSubset:function(r,t){var e=w(r,t);return i.intersection(e[0],e[1]).length===e[0].length},$anyElementTrue:function(r,t){for(var e=w(r,t)[0],n=0;n<e.length;n++)if(e[n])return!0;return!1},$allElementsTrue:function(r,t){for(var e=w(r,t)[0],n=0;n<e.length;n++)if(!e[n])return!1;return!0}},d={$cond:function(r,t){var e,n,o;if(i.isArray(t)){if(3!=t.length)throw new Error("Invalid arguments for $cond operator");e=t[0],n=t[1],o=t[2]}else i.isObject(t)&&(e=t["if"],n=t.then,o=t["else"]);var s=w(r,e);return s?w(r,n):w(r,o)},$ifNull:function(r,e){if(!i.isArray(e)||2!=e.length)throw new Error("Invalid arguments for $ifNull operator");var n=w(r,e);return null===n[0]||n[0]===t?n[1]:n[0]}};i.each(["$eq","$ne","$gt","$gte","$lt","$lte"],function(r){v[r]=function(t,e){var n=w(t,e);return p[r](n[0],n[1])}}),i.extend(v,$,d);var m={simpleOperators:i.keys(p),compoundOperators:i.keys(l),setOperators:i.keys($),aggregateOperators:i.keys(v),groupOperators:i.keys(y),pipelineOperators:i.keys(h),projectionOperators:i.keys(g)};m.queryOperators=i.union(m.simpleOperators,m.compoundOperators);var _=function(r,e,n){if(i.contains(m.groupOperators,e))return y[e](r,n);if(i.isObject(n)){var o={};for(var s in n)if(n.hasOwnProperty(s)&&(o[s]=_(r,s,n[s]),i.contains(m.groupOperators,s))){if(o=o[s],i.keys(n).length>1)throw new Error("Invalid $group expression '"+JSON.stringify(n)+"'");break}return o}return t},w=function(r,t,e){if(i.contains(m.aggregateOperators,e))return v[e](r,t);if(i.isString(t)&&t.length>0&&"$"===t[0])return o._resolve(r,t.slice(1));var n;if(i.isArray(t)){n=[];for(var s=0;s<t.length;s++)n.push(w(r,t[s],null))}else if(i.isObject(t)){n={};for(var a in t)if(t.hasOwnProperty(a)&&(n[a]=w(r,t[a],a),i.contains(m.aggregateOperators,a))){if(n=n[a],i.keys(t).length>1)throw new Error("Invalid aggregation expression '"+JSON.stringify(t)+"'");break}}else for(var s=0;s<u.length;s++)if(u[s](t))return t;return n}}(this);

@@ -1,7 +0,10 @@

(function () {
// Mingo.js 0.3.0
// Copyright (c) 2015 Francis Asante <kofrasa@gmail.com>
// MIT
(function (root, undefined) {
"use strict";
// global on the server, window in the browser
var root = this;
var Mingo = {}, previousMingo;

@@ -20,9 +23,6 @@ var _;

var nodeEnabled = 'undefined' !== typeof exports &&
'undefined' !== typeof module &&
'undefined' !== typeof require &&
'undefined' !== typeof process;
var nodeEnabled = ('undefined' !== typeof exports && 'undefined' !== typeof require);
// Export the Mingo object for **Node.js**
if (typeof exports !== 'undefined') {
// Export the Mingo object for Node.js
if (nodeEnabled) {
if (typeof module !== 'undefined' && module.exports) {

@@ -1718,2 +1718,2 @@ exports = module.exports = Mingo;

}).call(this);
}(this));
{
"name": "mingo",
"version": "0.2.5",
"version": "0.3.0",
"description": "JavaScript implementation of MongoDB query language",

@@ -24,4 +24,5 @@ "main": "mingo.js",

"backbone": ">=1.1.2",
"tape": "~2.14.0",
"JSON": "~1.0.0"
"tape": ">=2.14.0",
"JSON": ">=1.0.0",
"uglify-js": "2.4.x"
},

@@ -28,0 +29,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc