aggregate.web.min.js 117 KB

1234
  1. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.aggregate=e()}}(function(){var define;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module){"use strict";var klass=module.exports=function(items){if(!(items instanceof Array))throw new Error("arg `items` must be an Array");this.cachedData=items.slice(0),this.length=items.length,this.offset=0},base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.ok=function(){return this.offset<this.length||this.hasOwnProperty("curr")},proto.advance=function(){return this.offset>=this.length?(delete this.curr,!1):(this.curr=this.cachedData[this.offset++],this.curr)},proto.current=function(){return this.hasOwnProperty("curr")||this.advance(),this.curr}},{}],2:[function(require,module,exports){"use strict";exports=module.exports=function(pipeline,ctx,inputs,callback){var DocumentSource=exports.pipeline.documentSources.DocumentSource;(ctx instanceof Array||ctx instanceof DocumentSource)&&(callback=inputs,inputs=ctx,ctx={});var pipelineInst=exports.pipeline.Pipeline.parseCommand({pipeline:pipeline},ctx),aggregator=function(ctx,inputs,callback){if((ctx instanceof Array||ctx instanceof DocumentSource)&&(callback=inputs,inputs=ctx,ctx={}),callback||(callback=exports.SYNC_CALLBACK),!inputs)return callback("arg `inputs` is required");pipelineInst||(pipelineInst=exports.pipeline.Pipeline.parseCommand({pipeline:pipeline},ctx));var src;if(inputs instanceof DocumentSource)src=inputs;else try{pipelineInst.collectionName=inputs,src=exports.pipeline.PipelineD.prepareCursorSource(pipelineInst,pipelineInst.ctx)}catch(err){return callback(err)}var results=pipelineInst.run(src,callback===exports.SYNC_CALLBACK?void 0:function(err,results){return err?callback(err):callback(null,results.result)});return pipelineInst=null,results};return inputs?aggregator(ctx,inputs,callback):aggregator},exports.SYNC_CALLBACK=function(err,docs){if(err)throw err;return docs},exports.aggregate=exports,exports.Cursor=require("./Cursor"),exports.pipeline=require("./pipeline/"),exports.version="r2.4.0-rc0",exports.gitVersion="cb8efcd6a2f05d35655ed9f9b947cc4a99ade8db"},{"./Cursor":1,"./pipeline/":62}],3:[function(require,module){"use strict";var Document=module.exports=function Document(){if(this.constructor==Document)throw new Error("Never create instances! Use static helpers only.")},klass=Document,base=Object,Value=(klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),require("./Value"));klass.ID_PROPERTY_NAME="_id",klass.compare=function(l,r){for(var lPropNames=Object.getOwnPropertyNames(l),lPropNamesLength=lPropNames.length,rPropNames=Object.getOwnPropertyNames(r),rPropNamesLength=rPropNames.length,i=0;!0;++i){if(i>=lPropNamesLength)return i>=rPropNamesLength?0:-1;if(i>=rPropNamesLength)return 1;var nameCmp=Value.compare(lPropNames[i],rPropNames[i]);if(0!==nameCmp)return nameCmp;var valueCmp=Value.compare(l[lPropNames[i]],r[rPropNames[i]]);if(valueCmp)return valueCmp}throw new Error("This should never happen")},klass.clone=function(document){var obj={};for(var key in document)if(document.hasOwnProperty(key)){var withObjVal=document[key];obj[key]=null===withObjVal?withObjVal:withObjVal.constructor===Object?Document.clone(withObjVal):withObjVal}return obj}},{"./Value":7}],4:[function(require,module){"use strict";var FieldPath=module.exports=function(path){var fields="object"==typeof path&&"number"==typeof path.length?path:path.split(".");if(0===fields.length)throw new Error("FieldPath cannot be constructed from an empty vector (String or Array).; code 16409");for(var i=0,n=fields.length;n>i;++i){var field=fields[i];if(0===field.length)throw new Error("FieldPath field names may not be empty strings; code 15998");if("$"==field[0])throw new Error("FieldPath field names may not start with '$'; code 16410");if(-1!=field.indexOf("\x00"))throw new Error("FieldPath field names may not contain '\\0'; code 16411");if(-1!=field.indexOf("."))throw new Error("FieldPath field names may not contain '.'; code 16412")}this.path=path,this.fields=fields},klass=FieldPath,base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});klass.PREFIX="$",proto.getPath=function(withPrefix){return(withPrefix?FieldPath.PREFIX:"")+this.fields.join(".")},proto.tail=function(){return new FieldPath(this.fields.slice(1))},proto.getFieldName=function(i){return this.fields[i]},proto.getPathLength=function(){return this.fields.length}},{}],5:[function(require,module){"use strict";function ifError(err){if(err)throw err}var async=require("async"),Pipeline=module.exports=function(theCtx){this.collectionName=null,this.sourceVector=null,this.explain=!1,this.splitMongodPipeline=!1,this.ctx=theCtx},klass=Pipeline,base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),DocumentSource=require("./documentSources/DocumentSource"),LimitDocumentSource=require("./documentSources/LimitDocumentSource"),MatchDocumentSource=require("./documentSources/MatchDocumentSource"),ProjectDocumentSource=require("./documentSources/ProjectDocumentSource"),SkipDocumentSource=require("./documentSources/SkipDocumentSource"),UnwindDocumentSource=require("./documentSources/UnwindDocumentSource"),GroupDocumentSource=require("./documentSources/GroupDocumentSource"),SortDocumentSource=require("./documentSources/SortDocumentSource");klass.COMMAND_NAME="aggregate",klass.PIPELINE_NAME="pipeline",klass.EXPLAIN_NAME="explain",klass.FROM_ROUTER_NAME="fromRouter",klass.SPLIT_MONGOD_PIPELINE_NAME="splitMongodPipeline",klass.SERVER_PIPELINE_NAME="serverPipeline",klass.MONGOS_PIPELINE_NAME="mongosPipeline",klass.stageDesc={},klass.stageDesc[LimitDocumentSource.limitName]=LimitDocumentSource.createFromJson,klass.stageDesc[MatchDocumentSource.matchName]=MatchDocumentSource.createFromJson,klass.stageDesc[ProjectDocumentSource.projectName]=ProjectDocumentSource.createFromJson,klass.stageDesc[SkipDocumentSource.skipName]=SkipDocumentSource.createFromJson,klass.stageDesc[UnwindDocumentSource.unwindName]=UnwindDocumentSource.createFromJson,klass.stageDesc[GroupDocumentSource.groupName]=GroupDocumentSource.createFromJson,klass.stageDesc[SortDocumentSource.sortName]=SortDocumentSource.createFromJson,klass.parseDocumentSources=function(pipeline,ctx){for(var sourceVector=[],nSteps=pipeline.length,iStep=0;nSteps>iStep;++iStep){var pipeElement=pipeline[iStep];if(!(pipeElement instanceof Object))throw new Error("pipeline element "+iStep+" is not an object; code 15942");var obj=pipeElement;if(1!==Object.keys(obj).length)throw new Error("A pipeline stage specification object must contain exactly one field; code 16435");var stageName=Object.keys(obj)[0],stageSpec=obj[stageName],desc=klass.stageDesc[stageName];if(!desc)throw new Error("Unrecognized pipeline stage name: '"+stageName+"'; code 16435");var stage=desc(stageSpec,ctx);if(!stage)throw new Error("Stage must not be undefined!");stage.setPipelineStep(iStep),sourceVector.push(stage)}return sourceVector},klass.parseCommand=function(cmdObj,ctx){var pipeline,pipelineNamespace=require("./"),Pipeline=pipelineNamespace.Pipeline,pipelineInst=new Pipeline(ctx);for(var fieldName in cmdObj){var cmdElement=cmdObj[fieldName];if(fieldName==klass.COMMAND_NAME)pipelineInst.collectionName=cmdElement;else if(fieldName==klass.PIPELINE_NAME)pipeline=cmdElement;else if(fieldName==klass.EXPLAIN_NAME)pipelineInst.explain=cmdElement;else if(fieldName==klass.FROM_ROUTER_NAME)pipelineInst.fromRouter=cmdElement;else{if(fieldName!=klass.SPLIT_MONGOD_PIPELINE_NAME)throw new Error("unrecognized field "+JSON.stringify(fieldName));pipelineInst.splitMongodPipeline=cmdElement}}var sourceVector=pipelineInst.sourceVector=Pipeline.parseDocumentSources(pipeline,ctx);if(!sourceVector.length)return pipelineInst;for(var srcn=sourceVector.length,srci=1;srcn>srci;++srci){var source=sourceVector[srci];if(source instanceof MatchDocumentSource){var previous=sourceVector[srci-1];previous instanceof SortDocumentSource&&(sourceVector[srci-1]=source,sourceVector[srci]=previous)}}var tempVector=sourceVector.slice(0);sourceVector.length=0,sourceVector.push(tempVector[0]);for(var tempn=tempVector.length,tempi=1;tempn>tempi;++tempi){var lastSource=sourceVector[sourceVector.length-1],temp=tempVector[tempi];if(!temp||!lastSource)throw new Error("null document sources found");lastSource.coalesce(temp)||sourceVector.push(temp)}for(var i=0,l=sourceVector.length;l>i;i++){var iter=sourceVector[i];if(!iter)throw new Error("Pipeline received empty document as argument");iter.optimize()}return pipelineInst},klass.SYNC_CALLBACK=function(err,results){if(err)throw err;return results.result},proto.run=function(inputSource,callback){if(inputSource&&!(inputSource instanceof DocumentSource))throw new Error("arg `inputSource` must be an instance of DocumentSource");callback||(callback=klass.SYNC_CALLBACK);var self=this;if(callback===klass.SYNC_CALLBACK){inputSource.setSource(void 0,ifError);for(var source=inputSource,i=0,l=self.sourceVector.length;l>i;i++){var temp=self.sourceVector[i];temp.setSource(source,ifError),source=temp}var resultArray=[];try{for(var hasDoc=!source.eof();hasDoc;hasDoc=source.advance()){var document=source.getCurrent();resultArray.push(document)}}catch(err){return callback(err)}var result={result:resultArray};return callback(null,result)}return inputSource.setSource(void 0,function(err){if(err)return callback(err);var source=inputSource;async.eachSeries(self.sourceVector,function(temp,next){temp.setSource(source,function(err){return err?next(err):(source=temp,next())})},function(err){if(err)return callback(err);var resultArray=[];try{for(var hasDoc=!source.eof();hasDoc;hasDoc=source.advance()){var document=source.getCurrent();resultArray.push(document)}}catch(err){return callback(err)}var result={result:resultArray};return callback(null,result)})})}},{"./":62,"./documentSources/DocumentSource":19,"./documentSources/GroupDocumentSource":21,"./documentSources/LimitDocumentSource":22,"./documentSources/MatchDocumentSource":23,"./documentSources/ProjectDocumentSource":24,"./documentSources/SkipDocumentSource":25,"./documentSources/SortDocumentSource":26,"./documentSources/UnwindDocumentSource":27,async:63}],6:[function(require,module){"use strict";var PipelineD=module.exports=function PipelineD(){if(this.constructor==PipelineD)throw new Error("Never create instances of this! Use the static helpers only.")},klass=PipelineD,base=Object,DocumentSource=(klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),require("./documentSources/DocumentSource")),CursorDocumentSource=require("./documentSources/CursorDocumentSource"),Cursor=require("../Cursor");klass.prepareCursorSource=function(pipeline,expCtx){for(var sources=pipeline.sourceVector,projection={},deps=[],status=DocumentSource.GetDepsReturn.SEE_NEXT,i=0;i<sources.length&&status!=DocumentSource.GetDepsReturn.EXHAUSTIVE;i++)status=sources[i].getDependencies(deps);status==DocumentSource.GetDepsReturn.EXHAUSTIVE&&(projection=DocumentSource.depsToProjection(deps));var cursorWithContext=new CursorDocumentSource.CursorWithContext;cursorWithContext._cursor=new Cursor(pipeline.collectionName);var source=new CursorDocumentSource(cursorWithContext,expCtx);return Object.keys(projection).length&&source.setProjection(projection),source}},{"../Cursor":1,"./documentSources/CursorDocumentSource":18,"./documentSources/DocumentSource":19}],7:[function(require,module){"use strict";function getTypeVerifier(type,IClass,isStrict){return function(value){if(typeof value!=type)throw new Error("typeof value is not: "+type+"; actual: "+typeof value);if("function"==typeof IClass&&!(isStrict?value.constructor==IClass:value instanceof IClass))throw new Error("instanceof value is not: "+IClass.name+"; actual: "+value.constructor.name);return value}}{var Value=module.exports=function Value(){if(this.constructor==Value)throw new Error("Never create instances of this! Use the static helpers only.")},klass=Value,base=Object;klass.prototype=Object.create(base.prototype,{constructor:{value:klass}})}klass.verifyNumber=getTypeVerifier("number",Number),klass.verifyString=getTypeVerifier("string",String),klass.verifyDocument=getTypeVerifier("object",Object,!0),klass.verifyArray=getTypeVerifier("object",Array,!0),klass.verifyDate=getTypeVerifier("object",Date,!0),klass.verifyRegExp=getTypeVerifier("object",RegExp,!0),klass.verifyBool=getTypeVerifier("boolean",Boolean,!0),klass.coerceToBool=function(value){return"string"==typeof value?!0:!!value},klass.coerceToInt=klass.coerceToLong=klass.coerceToDouble=klass._coerceToNumber=function(value){if(null===value)return 0;switch(typeof value){case"undefined":return 0;case"number":return value;case"object":switch(value.constructor.name){case"Long":return parseInt(value.toString(),10);case"Double":return parseFloat(value.value,10);default:throw new Error("can't convert from BSON type "+value.constructor.name+" to int; codes 16003, 16004, 16005")}return value;default:throw new Error("can't convert from BSON type "+typeof value+" to int; codes 16003, 16004, 16005")}},klass.coerceToDate=function(value){if(value instanceof Date)return value;throw new Error("can't convert from BSON type "+typeof value+" to Date; uassert code 16006")},klass.coerceToString=function(value){if(null===value)return"";switch(typeof value){case"undefined":return"";case"number":return value.toString();case"string":return value;default:throw new Error("can't convert from BSON type "+typeof value+" to String; uassert code 16007")}},klass.canonicalize=function(x){var xType=typeof x;switch("object"==xType&&(xType=null===x?"null":x.constructor.name),xType){case"MinKey":return-1;case"MaxKey":return 127;case"EOO":case"undefined":case void 0:return 0;case"jstNULL":case"null":case"Null":return 5;case"NumberDouble":case"NumberInt":case"NumberLong":case"number":return 10;case"Symbol":case"string":return 15;case"Object":return 20;case"Array":return 25;case"Binary":return 30;case"ObjectId":return 35;case"ObjectID":return 35;case"boolean":case"Boolean":return 40;case"Date":case"Timestamp":return 45;case"RegEx":case"RegExp":return 50;case"DBRef":return 55;case"Code":return 60;case"CodeWScope":return 65;default:return 20}},klass.cmp=function(l,r){return r>l?-1:l>r?1:0};var Document;klass.compare=function(l,r){var ret,lt=null===l?"null":typeof l,rt=null===r?"null":typeof r;if(ret=klass.cmp(klass.canonicalize(l),klass.canonicalize(r)),0!==ret)return ret;if("number"===lt&&"number"===rt)return isNaN(l)?isNaN(r)?0:-1:isNaN(r)?1:klass.cmp(l,r);if(lt!==rt)throw new Error("can't compare values of BSON types ["+lt+" "+l.constructor.name+"] and ["+rt+":"+r.constructor.name+"]; code 16016");switch(lt){case"number":throw new Error("number types should have been handled earlier!");case"string":return klass.cmp(l,r);case"boolean":return l==r?0:l?1:-1;case"undefined":case"null":return 0;case"object":if(l instanceof Array){for(var i=0,ll=l.length,rl=r.length;!0;++i){if(i>ll)return i>rl?0:-1;if(i>rl)return 1;var cmp=Value.compare(l[i],r[i]);if(0!==cmp)return cmp}throw new Error("logic error in Value.compare for Array types!")}return l instanceof Date?klass.cmp(l,r):l instanceof RegExp?klass.cmp(l,r):(void 0===Document&&(Document=require("./Document")),Document.compare(l,r));default:throw new Error("unhandled left hand type:"+lt)}}},{"./Document":3}],8:[function(require,module){"use strict";var Accumulator=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=Accumulator,base=require("../expressions/NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getFactory=function(){return klass},proto.addOperand=function(expr){if(this.operands.length>=1)throw new Error("code 15943; group accumulator "+this.getOpName()+" only accepts one operand");base.prototype.addOperand.call(this,expr)},proto.toJSON=function(isExpressionRequired){var rep={};return rep[this.getOpName()]=this.operands[0].toJSON(isExpressionRequired),rep},proto.addToBsonArray=function(){},proto.getValue=function(){throw new Error("You need to define this function on your accumulator")}},{"../expressions/NaryExpression":49}],9:[function(require,module){"use strict";var AddToSetAccumulator=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");this.set={},base.call(this)},klass=AddToSetAccumulator,Accumulator=require("./Accumulator"),base=Accumulator,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$addToSet"},proto.getFactory=function(){return klass},proto.evaluate=function(doc){if(1!==arguments.length)throw new Error("One and only one arg expected");var rhs=this.operands[0].evaluate(doc);void 0!==rhs&&(this.set[JSON.stringify(rhs)]=rhs)},proto.getValue=function(){var setValues=[];for(var setKey in this.set)setValues.push(this.set[setKey]);return setValues}},{"./Accumulator":8}],10:[function(require,module){"use strict";var AvgAccumulator=module.exports=function(){this.subTotalName="subTotal",this.countName="count",this.totalIsANumber=!0,base.call(this)},klass=AvgAccumulator,SumAccumulator=require("./SumAccumulator"),base=SumAccumulator,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getFactory=function(){return klass},proto.getValue=function(){if(this.totalIsANumber&&this.count>0)return this.total/this.count;if(0===this.count)return 0;throw new Error("$sum resulted in a non-numeric type")},proto.getOpName=function(){return"$avg"}},{"./SumAccumulator":16}],11:[function(require,module){"use strict";var FirstAccumulator=module.exports=function(){base.call(this),this.started=0},klass=FirstAccumulator,base=require("./SingleValueAccumulator"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$first"},proto.getFactory=function(){return klass},proto.evaluate=function(doc){if(1!=this.operands.length)throw new Error("this should never happen");return base.prototype.getValue.call(this)||0!==this.started||(this.value=this.operands[0].evaluate(doc),this.started=1),this.value}},{"./SingleValueAccumulator":15}],12:[function(require,module){"use strict";var LastAccumulator=module.exports=function(){base.call(this)},klass=LastAccumulator,SingleValueAccumulator=require("./SingleValueAccumulator"),base=SingleValueAccumulator,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.evaluate=function(doc){if(1!=this.operands.length)throw new Error("this should never happen");this.value=this.operands[0].evaluate(doc)},proto.getOpName=function(){return"$last"}},{"./SingleValueAccumulator":15}],13:[function(require,module){"use strict";var MinMaxAccumulator=module.exports=function(sense){if(arguments.length>1)throw new Error("expects a single value");if(base.call(this),this.sense=sense,1!==this.sense&&-1!==this.sense)throw new Error("this should never happen")},klass=MinMaxAccumulator,base=require("./SingleValueAccumulator"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return 1==this.sense?"$min":"$max"},klass.createMin=function(){return new MinMaxAccumulator(1)},klass.createMax=function(){return new MinMaxAccumulator(-1)},proto.evaluate=function(doc){if(1!=this.operands.length)throw new Error("this should never happen");var prhs=this.operands[0].evaluate(doc);if(this.hasOwnProperty("value")){var cmp=Value.compare(this.value,prhs)*this.sense;cmp>0&&(this.value=prhs)}else this.value=prhs;return this.value}},{"../Value":7,"./SingleValueAccumulator":15}],14:[function(require,module){"use strict";var PushAccumulator=module.exports=function(){this.values=[],base.call(this)},klass=PushAccumulator,Accumulator=require("./Accumulator"),base=Accumulator,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.evaluate=function(doc){if(1!=this.operands.length)throw new Error("this should never happen");var v=this.operands[0].evaluate(doc);return void 0!==v&&this.values.push(v),null},proto.getValue=function(){return this.values},proto.getOpName=function(){return"$push"}},{"./Accumulator":8}],15:[function(require,module){"use strict";{var SingleValueAccumulator=module.exports=function(){if(arguments.length>1)throw new Error("expects a single value");base.call(this)},klass=SingleValueAccumulator,Accumulator=require("./Accumulator"),base=Accumulator,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});require("../Value")}proto.getValue=function(){return this.value}},{"../Value":7,"./Accumulator":8}],16:[function(require,module){"use strict";var SumAccumulator=module.exports=function(){this.total=0,this.count=0,this.totalIsANumber=!0,base.call(this)},klass=SumAccumulator,Accumulator=require("./Accumulator"),base=Accumulator,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.evaluate=function(doc){if(1!=this.operands.length)throw new Error("this should never happen");var v=this.operands[0].evaluate(doc);return"number"!=typeof v?0:(this.totalIsANumber=!0,this.total+=v,this.count++,0)},proto.getValue=function(){if(this.totalIsANumber)return this.total;throw new Error("$sum resulted in a non-numeric type")},proto.getOpName=function(){return"$sum"}},{"./Accumulator":8}],17:[function(require,module){"use strict";module.exports={Accumulator:require("./Accumulator"),AddToSet:require("./AddToSetAccumulator"),Avg:require("./AvgAccumulator"),First:require("./FirstAccumulator"),Last:require("./LastAccumulator"),MinMax:require("./MinMaxAccumulator"),Push:require("./PushAccumulator"),Sum:require("./SumAccumulator")}},{"./Accumulator":8,"./AddToSetAccumulator":9,"./AvgAccumulator":10,"./FirstAccumulator":11,"./LastAccumulator":12,"./MinMaxAccumulator":13,"./PushAccumulator":14,"./SumAccumulator":16}],18:[function(require,module){(function(process){"use strict";var CursorDocumentSource=module.exports=CursorDocumentSource=function(cursorWithContext,expCtx){if(base.call(this,expCtx),this.current=null,this._projection=null,this._cursorWithContext=cursorWithContext,!this._cursorWithContext||!this._cursorWithContext._cursor)throw new Error("CursorDocumentSource requires a valid cursorWithContext")},klass=CursorDocumentSource,base=require("./DocumentSource"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});klass.CursorWithContext=function(){var klass=function(){this._cursor=null};return klass}(),proto.dispose=function(){this._cursorWithContext=null},proto.setProjection=function(projection){if(this._projection)throw new Error("projection is already set");this._projection=projection},proto.eof=function(){return this.current||this.findNext(),null===this.current},proto.advance=function(){return base.prototype.advance.call(this),this.current||this.findNext(),this.findNext(),null!==this.current},proto.getCurrent=function(){return this.current||this.findNext(),this.current},proto.setSource=function(theSource,callback){if(theSource)throw new Error("CursorDocumentSource doesn't take a source");return callback?process.nextTick(callback):void 0},proto.sourceToJson=function(){},proto.findNext=function(){if(!this._cursorWithContext)return void(this.current=null);for(;this.cursor().ok();this.cursor().advance()){var documentObj;return documentObj=this.cursor().current(),this.current=documentObj,void this.cursor().advance()}this.dispose(),this.current=null},proto.cursor=function(){if(this._cursorWithContext&&this._cursorWithContext._cursor)return this._cursorWithContext._cursor;throw new Error("cursor not defined")}}).call(this,require("_process"))},{"./DocumentSource":19,_process:65}],19:[function(require,module){"use strict";var DocumentSource=module.exports=function(expCtx){if(1!==arguments.length)throw new Error("one arg expected");this.source=null,this.step=-1,this.expCtx=expCtx||{},this.nRowsOut=0},klass=DocumentSource,base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.setPipelineStep=function(step){this.step=step},proto.getPipelineStep=function(){return this.step},proto.eof=function(){throw new Error("not implemented")},proto.advance=function(){return!1},proto.getCurrent=function(){throw new Error("not implemented")},proto.dispose=function(){this.source&&this.source.dispose()},proto.getSourceName=function(){return"[UNKNOWN]"},proto.setSource=function(theSource,callback){if(this.source)throw new Error("It is an error to set the source more than once");return this.source=theSource,callback?setTimeout(callback,0):void 0},proto.coalesce=function(){return!1},proto.optimize=function(){},klass.GetDepsReturn={NOT_SUPPORTED:"NOT_SUPPORTED",EXHAUSTIVE:"EXHAUSTIVE",SEE_NEXT:"SEE_NEXT"},proto.getDependencies=function(){return klass.GetDepsReturn.NOT_SUPPORTED},klass.depsToProjection=function(deps){var bb={};void 0===deps._id&&(bb._id=0);var last="";return Object.keys(deps).sort().forEach(function(it){(""===last||it.slice(0,last.length)!==last)&&(last=it+".",bb[it]=1)}),bb},proto.addToJsonArray=function(pBuilder,explain){pBuilder.push(this.sourceToJson({},explain))},proto.sourceToJson=function(){throw new Error("not implemented")},proto.toJSON=function(){var obj={};return this.sourceToJson(obj),obj}},{}],20:[function(require,module){"use strict";var FilterBaseDocumentSource=module.exports=function(ctx){if(arguments.length>1)throw new Error("up to one arg expected");base.call(this,ctx),this.unstarted=!0,this.hasNext=!1,this.current=null},klass=FilterBaseDocumentSource,base=require("./DocumentSource"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.findNext=function(){for(this.unstarted&&(this.hasNext=!this.source.eof(),this.unstarted=!1);this.hasNext;){var document=this.source.getCurrent();if(this.hasNext=this.source.advance(),this.accept(document))return void(this.current=document)}this.current=null},proto.eof=function(){return this.unstarted&&this.findNext(),null===this.current},proto.advance=function(){return base.prototype.advance.call(this),this.unstarted&&this.findNext(),this.findNext(),null!==this.current},proto.getCurrent=function(){if(this.unstarted&&this.findNext(),null===this.current)throw new Error("This should never happen");return this.current},proto.accept=function(){throw new Error("not implemented")},proto.toMatcherJson=function(){throw new Error("not implemented")}},{"./DocumentSource":19}],21:[function(require,module){"use strict";var DocumentSource=require("./DocumentSource"),Accumulators=require("../accumulators/"),Document=require("../Document"),Expression=require("../expressions/Expression"),ConstantExpression=require("../expressions/ConstantExpression"),FieldPathExpression=require("../expressions/FieldPathExpression"),GroupDocumentSource=module.exports=function(expCtx){if(arguments.length>1)throw new Error("up to one arg expected");base.call(this,expCtx),this.populated=!1,this.idExpression=null,this.groups={},this.groupsKeys=[],this.originalGroupsKeys=[],this.fieldNames=[],this.accumulatorFactories=[],this.expressions=[],this.currentDocument=null,this.currentGroupsKeysIndex=0},klass=GroupDocumentSource,base=DocumentSource,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});klass.groupOps={$addToSet:Accumulators.AddToSet,$avg:Accumulators.Avg,$first:Accumulators.First,$last:Accumulators.Last,$max:Accumulators.MinMax.createMax,$min:Accumulators.MinMax.createMin,$push:Accumulators.Push,$sum:Accumulators.Sum},klass.groupName="$group",proto.getSourceName=function(){return klass.groupName},proto.sourceToJson=function(builder){for(var idExp=this.idExpression,insides={_id:idExp?idExp.toJSON():{}},aFac=this.accumulatorFactories,aFacLen=aFac.length,i=0;aFacLen>i;++i){var acc=new aFac[i];acc.addOperand(this.expressions[i]),insides[this.fieldNames[i]]=acc.toJSON(!0)}builder[this.getSourceName()]=insides},klass.createFromJson=function(groupObj,ctx){if(!(groupObj instanceof Object&&groupObj.constructor===Object))throw new Error("a group's fields must be specified in an object");var idSet=!1,group=new GroupDocumentSource(ctx);for(var groupFieldName in groupObj)if(groupObj.hasOwnProperty(groupFieldName)){var groupField=groupObj[groupFieldName];if("_id"===groupFieldName){if(idSet)throw new Error("15948 a group's _id may only be specified once");if(groupField instanceof Object&&groupField.constructor===Object){var objCtx=new Expression.ObjectCtx({isDocumentOk:!0});group.idExpression=Expression.parseObject(groupField,objCtx),idSet=!0}else if("string"==typeof groupField){if("$"!==groupField[0])group.idExpression=new ConstantExpression(groupField);else{var pathString=Expression.removeFieldPrefix(groupField);group.idExpression=new FieldPathExpression(pathString)}idSet=!0}else{var typeStr=group._getTypeStr(groupField);switch(typeStr){case"number":case"string":case"boolean":case"Object":case"object":case"Array":group.idExpression=new ConstantExpression(groupField),idSet=!0;break;default:throw new Error("a group's _id may not include fields of type "+typeStr)}}}else{if(-1!==groupFieldName.indexOf("."))throw new Error("16414 the group aggregate field name '"+groupFieldName+"' cannot contain '.'");if("$"===groupFieldName[0])throw new Error("15950 the group aggregate field name '"+groupFieldName+"' cannot be an operator name");if("Object"===group._getTypeStr(groupFieldName))throw new Error("15951 the group aggregate field '"+groupFieldName+"' must be defined as an expression inside an object");var subFieldCount=0;for(var subFieldName in groupField)if(groupField.hasOwnProperty(subFieldName)){var subField=groupField[subFieldName],op=klass.groupOps[subFieldName];if(!op)throw new Error("15952 unknown group operator '"+subFieldName+"'");var groupExpression,subFieldTypeStr=group._getTypeStr(subField);if("Object"===subFieldTypeStr){var subFieldObjCtx=new Expression.ObjectCtx({isDocumentOk:!0});groupExpression=Expression.parseObject(subField,subFieldObjCtx)}else{if("Array"===subFieldTypeStr)throw new Error("15953 aggregating group operators are unary ("+subFieldName+")");groupExpression=Expression.parseOperand(subField)}group.addAccumulator(groupFieldName,op,groupExpression),++subFieldCount}if(1!=subFieldCount)throw new Error("15954 the computed aggregate '"+groupFieldName+"' must specify exactly one operator")}}if(!idSet)throw new Error("15955 a group specification must include an _id");return group},proto._getTypeStr=function(obj){var typeofStr=typeof obj,typeStr="object"==typeofStr&&null!==obj?obj.constructor.name:typeofStr;return typeStr},proto.advance=function(){return base.prototype.advance.call(this),this.populated||this.populate(),++this.currentGroupsKeysIndex,this.currentGroupsKeysIndex>=this.groupsKeys.length?(this.currentDocument=null,!1):(this.currentDocument=this.makeDocument(this.currentGroupsKeysIndex),!0)},proto.eof=function(){return this.populated||this.populate(),this.currentGroupsKeysIndex===this.groupsKeys.length},proto.getCurrent=function(){return this.populated||this.populate(),this.currentDocument},proto.getDependencies=function(deps){var self=this;return this.idExpression.addDependencies(deps),this.fieldNames.forEach(function(field,i){self.expressions[i].addDependencies(deps)}),DocumentSource.GetDepsReturn.EXHAUSTIVE
  2. },proto.addAccumulator=function(fieldName,accumulatorFactory,expression){this.fieldNames.push(fieldName),this.accumulatorFactories.push(accumulatorFactory),this.expressions.push(expression)},proto.populate=function(){for(var hasNext=!this.source.eof();hasNext;hasNext=this.source.advance()){var group,currentDocument=this.source.getCurrent(),_id=this.idExpression.evaluate(currentDocument);void 0===_id&&(_id=null);var idHash=JSON.stringify(_id);if(idHash in this.groups)group=this.groups[idHash];else{this.groups[idHash]=group=[],this.groupsKeys[this.currentGroupsKeysIndex]=idHash,this.originalGroupsKeys[this.currentGroupsKeysIndex]=_id&&"object"==typeof _id?Document.clone(_id):_id,++this.currentGroupsKeysIndex;for(var ai=0;ai<this.accumulatorFactories.length;++ai){var accumulator=new this.accumulatorFactories[ai];accumulator.addOperand(this.expressions[ai]),group.push(accumulator)}}for(var gi=0;gi<group.length;++gi)group[gi].evaluate(currentDocument)}this.currentGroupsKeysIndex=0,this.groupsKeys.length>0&&(this.currentDocument=this.makeDocument(this.currentGroupsKeysIndex)),this.populated=!0},proto.makeDocument=function(groupKeyIndex){var groupKey=this.groupsKeys[groupKeyIndex],originalGroupKey=this.originalGroupsKeys[groupKeyIndex],group=this.groups[groupKey],doc={};doc[Document.ID_PROPERTY_NAME]=originalGroupKey;for(var i=0;i<this.fieldNames.length;++i){var fieldName=this.fieldNames[i],item=group[i];"null"!==item&&void 0!==item&&(doc[fieldName]=item.getValue())}return doc}},{"../Document":3,"../accumulators/":17,"../expressions/ConstantExpression":35,"../expressions/Expression":40,"../expressions/FieldPathExpression":41,"./DocumentSource":19}],22:[function(require,module){"use strict";var LimitDocumentSource=module.exports=function(ctx){if(arguments.length>1)throw new Error("up to one arg expected");base.call(this,ctx),this.limit=0,this.count=0},klass=LimitDocumentSource,base=require("./DocumentSource"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});klass.limitName="$limit",proto.getSourceName=function(){return klass.limitName},proto.getFactory=function(){return klass},proto.coalesce=function(nextSource){var nextLimit=nextSource.constructor===LimitDocumentSource?nextSource:null;return nextLimit?(nextLimit.limit<this.limit&&(this.limit=nextLimit.limit),!0):!1},proto.eof=function(){return this.source.eof()||this.count>=this.limit},proto.getCurrent=function(){return this.source.getCurrent()},proto.advance=function(){return base.prototype.advance.call(this),++this.count,this.count>=this.limit?!1:(this.current=this.source.getCurrent(),this.source.advance())},proto.sourceToJson=function(builder){builder.$limit=this.limit},klass.createFromJson=function(jsonElement,ctx){if("number"!=typeof jsonElement)throw new Error("code 15957; the limit must be specified as a number");var Limit=proto.getFactory(),nextLimit=new Limit(ctx);if(nextLimit.limit=jsonElement,nextLimit.limit<=0||isNaN(nextLimit.limit))throw new Error("code 15958; the limit must be positive");return nextLimit}},{"./DocumentSource":19}],23:[function(require,module){"use strict";var sift=require("sift"),MatchDocumentSource=module.exports=function(query,ctx){if(arguments.length>2)throw new Error("up to two args expected");if(!query)throw new Error("arg `query` is required");base.call(this,ctx),this.query=query,this.matcher=sift(query)},klass=MatchDocumentSource,base=require("./FilterBaseDocumentSource"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});klass.matchName="$match",proto.getSourceName=function(){return klass.matchName},proto.sourceToJson=function(builder){builder[this.getSourceName()]=this.matcher.query},proto.accept=function(document){return this.matcher.test(document)},proto.toMatcherJson=function(builder){var q=this.matcher.query;for(var k in q)builder[k]=q[k]},klass.uassertNoDisallowedClauses=function(query){for(var key in query)if(query.hasOwnProperty(key)){if("$where"==query[key])throw new Error("code 16395; $where is not allowed inside of a $match aggregation expression");if("$near"==query[key])throw new Error("code 16424; $near is not allowed inside of a $match aggregation expression");if("$within"==query[key])throw new Error("code 16425; $within is not allowed inside of a $match aggregation expression");if("$nearSphere"==query[key])throw new Error("code 16426; $nearSphere is not allowed inside of a $match aggregation expression");query[key]instanceof Object&&query[key].constructor===Object&&this.uassertNoDisallowedClauses(query[key])}},klass.createFromJson=function(jsonElement,ctx){if(!(jsonElement instanceof Object)||jsonElement.constructor!==Object)throw new Error("code 15959 ; the match filter must be an expression in an object");klass.uassertNoDisallowedClauses(jsonElement);var matcher=new MatchDocumentSource(jsonElement,ctx);return matcher}},{"./FilterBaseDocumentSource":20,sift:64}],24:[function(require,module){"use strict";{var ProjectDocumentSource=module.exports=function(ctx){if(arguments.length>1)throw new Error("up to one arg expected");base.call(this,ctx),this.OE=new ObjectExpression,this._raw=void 0},klass=ProjectDocumentSource,base=require("./DocumentSource"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Expression=require("../expressions/Expression"),ObjectExpression=require("../expressions/ObjectExpression");require("../Value")}klass.projectName="$project",proto.getSourceName=function(){return klass.projectName},proto.getRaw=function(){return this._raw},proto.eof=function(){return this.source.eof()},proto.advance=function(){return this.source.advance()},proto.getCurrent=function(){var inDocument=this.source.getCurrent();if(!inDocument)throw new Error("inDocument must be an object");var resultDocument={};return this.OE.addToDocument(resultDocument,inDocument,inDocument),resultDocument},proto.optimize=function(){this.OE.optimize()},proto.toJSON=function(){var obj={};return this.sourceToJson(obj),obj},proto.sourceToJson=function(builder){var insides=this.OE.toJSON(!0);builder[this.getSourceName()]=insides},klass.createFromJson=function(jsonElement,expCtx){if(!(jsonElement instanceof Object)||jsonElement.constructor!==Object)throw new Error("Error 15969. Specification must be an object but was "+typeof jsonElement);var objectContext=new Expression.ObjectCtx({isDocumentOk:!0,isTopLevel:!0,isInclusionOk:!0}),project=new ProjectDocumentSource(expCtx);project._raw=jsonElement;var parsed=Expression.parseObject(jsonElement,objectContext),exprObj=parsed;if(!exprObj instanceof ObjectExpression)throw new Error("16402, parseObject() returned wrong type of Expression");if(!exprObj.getFieldCount())throw new Error("16403, $projection requires at least one output field");return project.OE=exprObj,project},proto.getDependencies=function(deps){var path=[];return this.OE.addDependencies(deps,path),base.GetDepsReturn.EXHAUSTIVE}},{"../Value":7,"../expressions/Expression":40,"../expressions/ObjectExpression":51,"./DocumentSource":19}],25:[function(require,module){"use strict";var SkipDocumentSource=module.exports=function(ctx){if(arguments.length>1)throw new Error("up to one arg expected");base.call(this,ctx),this.skip=0,this.count=0},klass=SkipDocumentSource,base=require("./DocumentSource"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});klass.skipName="$skip",proto.getSourceName=function(){return klass.skipName},proto.coalesce=function(nextSource){var nextSkip=nextSource.constructor===SkipDocumentSource?nextSource:null;return nextSkip?(this.skip+=nextSkip.skip,!0):!1},proto.skipper=function(){if(0===this.count)for(;!this.source.eof()&&this.count++<this.skip;)this.source.advance();return this.source.eof()?void(this.current=null):void(this.current=this.source.getCurrent())},proto.eof=function(){return this.skipper(),this.source.eof()},proto.getCurrent=function(){return this.skipper(),this.source.getCurrent()},proto.advance=function(){return base.prototype.advance.call(this),this.eof()?(this.current=null,!1):(this.current=this.source.getCurrent(),this.source.advance())},proto.sourceToJson=function(builder){builder.$skip=this.skip},klass.createFromJson=function(jsonElement,ctx){if("number"!=typeof jsonElement)throw new Error("code 15972; the value to skip must be a number");var nextSkip=new SkipDocumentSource(ctx);if(nextSkip.skip=jsonElement,nextSkip.skip<0||isNaN(nextSkip.skip))throw new Error("code 15956; the number to skip cannot be negative");return nextSkip}},{"./DocumentSource":19}],26:[function(require,module){"use strict";var SortDocumentSource=module.exports=function(ctx){if(arguments.length>1)throw new Error("up to one arg expected");base.call(this,ctx),this.populated=!1,this.current=null,this.docIterator=null,this.documents=[],this.vSortKey=[],this.vAscending=[]},klass=SortDocumentSource,base=require("./DocumentSource"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),FieldPathExpression=require("../expressions/FieldPathExpression"),Value=require("../Value");klass.sortName="$sort",proto.getSourceName=function(){return klass.sortName},proto.getFactory=function(){return klass},klass.GetDepsReturn={SEE_NEXT:"SEE_NEXT"},proto.getDependencies=function(deps){for(var i=0;i<this.vSortKey.length;++i)this.vSortKey[i].addDependencies(deps);return klass.GetDepsReturn.SEE_NEXT},proto.eof=function(){return this.populated||this.populate(),this.docIterator==this.documents.length},proto.getCurrent=function(){return this.populated||this.populate(),this.current},proto.advance=function(){if(base.prototype.advance.call(this),this.populated||this.populate(),this.docIterator==this.documents.length)throw new Error("This should never happen");return++this.docIterator,this.docIterator==this.documents.length?(this.current=null,!1):(this.current=this.documents[this.docIterator],!0)},proto.sourceToJson=function(builder){var insides={};this.sortKeyToJson(insides,!1),builder[this.getSourceName()]=insides},proto.addKey=function(fieldPath,ascending){var pathExpr=new FieldPathExpression(fieldPath);if(this.vSortKey.push(pathExpr),ascending!==!0&&ascending!==!1)throw new Error("ascending must be true or false");this.vAscending.push(ascending)},proto.populate=function(){if(null===this.vSortKey.length)throw new Error("This should never happen");for(var hasNext=!this.source.eof();hasNext;hasNext=this.source.advance()){var doc=this.source.getCurrent();this.documents.push(doc)}this.vSortKeyFPEs=this.vSortKey.map(function(aSortKey){return new FieldPathExpression(aSortKey.getFieldPath(!1))}),this.documents.sort(SortDocumentSource.prototype.compare.bind(this)),this.docIterator=0,this.docIterator<this.documents.length&&(this.current=this.documents[this.docIterator]),this.populated=!0},proto.compare=function(pL,pR){for(var n=this.vSortKey.length,i=0;n>i;++i){var pathExpr=this.vSortKeyFPEs[i],left=pathExpr.evaluate(pL),right=pathExpr.evaluate(pR),cmp=Value.compare(left,right);if(cmp)return this.vAscending[i]||(cmp=-cmp),cmp}return 0},proto.sortKeyToJson=function(builder,usePrefix){for(var n=this.vSortKey.length,i=0;n>i;++i){var ss=this.vSortKey[i].getFieldPath(usePrefix);builder[ss]=this.vAscending[i]>0?1:-1}},klass.createFromJson=function(jsonElement,ctx){if("object"!=typeof jsonElement)throw new Error("code 15973; the "+klass.sortName+" key specification must be an object");var Sort=proto.getFactory(),nextSort=new Sort(ctx),sortKeys=0;for(var key in jsonElement){var sortOrder=0;if("number"!=typeof jsonElement[key])throw new Error("code 15974; "+klass.sortName+" key ordering must be specified using a number");if(sortOrder=jsonElement[key],1!=sortOrder&&-1!==sortOrder)throw new Error("code 15975; "+klass.sortName+" key ordering must be 1 (for ascending) or 0 (for descending)");nextSort.addKey(key,sortOrder>0),++sortKeys}if(0>=sortKeys)throw new Error("code 15976; "+klass.sortName+" must have at least one sort key");return nextSort}},{"../Value":7,"../expressions/FieldPathExpression":41,"./DocumentSource":19}],27:[function(require,module){"use strict";var UnwindDocumentSource=module.exports=function(ctx){if(arguments.length>1)throw new Error("up to one arg expected");base.call(this,ctx),this._unwindPath=null,this._unwinder=null},klass=UnwindDocumentSource,base=require("./DocumentSource"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),DocumentSource=base,FieldPath=require("../FieldPath"),Document=require("../Document"),Expression=require("../expressions/Expression");klass.Unwinder=function(){var klass=function(unwindPath){this._unwindPath=unwindPath,this._document=null,this._unwindPathFieldIndexes=[],this._unwindArrayIterator=null},base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});return proto.resetDocument=function(document){if(!document)throw new Error("document is required!");this._document=document,this._unwindPathFieldIndexes.length=0,this._unwindArrayIterator=null,delete this._unwindArrayIteratorCurrent;var pathValue=this.extractUnwindValue();if(pathValue&&0!==pathValue.length){if(!(pathValue instanceof Array))throw new Error(UnwindDocumentSource.unwindName+": value at end of field path must be an array; code 15978");this._unwindArrayIterator=pathValue.slice(0),this._unwindArrayIteratorCurrent=this._unwindArrayIterator.splice(0,1)[0]}},proto.eof=function(){return!this.hasOwnProperty("_unwindArrayIteratorCurrent")},proto.advance=function(){this._unwindArrayIterator&&this._unwindArrayIterator.length?this._unwindArrayIteratorCurrent=this._unwindArrayIterator.splice(0,1)[0]:delete this._unwindArrayIteratorCurrent},proto.getCurrent=function(){if(!this.hasOwnProperty("_unwindArrayIteratorCurrent"))return null;var clone=Document.clone(this._document),current=clone,n=this._unwindPathFieldIndexes.length;if(!n)throw new Error("unwindFieldPathIndexes are empty");for(var i=0;n>i;++i){var fi=this._unwindPathFieldIndexes[i],fp=current[fi];if(n>i+1){var next=Document.clone(fp);current[fi]=next,current=next}else current[fi]=this._unwindArrayIteratorCurrent}return clone},proto.extractUnwindValue=function(){for(var pathValue,current=this._document,pathLength=this._unwindPath.getPathLength(),i=0;pathLength>i;++i){var idx=this._unwindPath.getFieldName(i);if(!current.hasOwnProperty(idx))return null;if(this._unwindPathFieldIndexes.push(idx),pathValue=current[idx],pathLength-1>i){if("object"!=typeof pathValue)return null;current=pathValue}}return pathValue},klass}(),proto.lazyInit=function(){if(!this._unwinder){if(!this._unwindPath)throw new Error("unwind path does not exist!");this._unwinder=new klass.Unwinder(this._unwindPath),this.source.eof()||this._unwinder.resetDocument(this.source.getCurrent()),this.mayAdvanceSource()}},proto.mayAdvanceSource=function(){for(;this._unwinder.eof();){if(this.source.eof())return;if(!this.source.advance())return;this._unwinder.resetDocument(this.source.getCurrent())}},proto.unwindPath=function(fieldPath){if(this._unwindPath)throw new Error(this.getSourceName()+" can't unwind more than one path; code 15979");this._unwindPath=new FieldPath(fieldPath)},klass.unwindName="$unwind",proto.getSourceName=function(){return klass.unwindName},proto.getDependencies=function(deps){if(!this._unwindPath)throw new Error("unwind path does not exist!");return deps[this._unwindPath.getPath(!1)]=1,DocumentSource.GetDepsReturn.SEE_NEXT},proto.eof=function(){return this.lazyInit(),this._unwinder.eof()},proto.getCurrent=function(){return this.lazyInit(),this._unwinder.getCurrent()},proto.advance=function(){return base.prototype.advance.call(this),this.lazyInit(),this._unwinder.advance(),this.mayAdvanceSource(),!this._unwinder.eof()},proto.sourceToJson=function(builder){if(!this._unwindPath)throw new Error("unwind path does not exist!");builder[this.getSourceName()]=this._unwindPath.getPath(!0)},klass.createFromJson=function(jsonElement,ctx){if(jsonElement.constructor!==String)throw new Error("the "+klass.unwindName+" field path must be specified as a string; code 15981");var pathString=Expression.removeFieldPrefix(jsonElement),unwind=new UnwindDocumentSource(ctx);return unwind.unwindPath(pathString),unwind}},{"../Document":3,"../FieldPath":4,"../expressions/Expression":40,"./DocumentSource":19}],28:[function(require,module){"use strict";module.exports={CursorDocumentSource:require("./CursorDocumentSource.js"),DocumentSource:require("./DocumentSource.js"),FilterBaseDocumentSource:require("./FilterBaseDocumentSource.js"),GroupDocumentSource:require("./GroupDocumentSource.js"),LimitDocumentSource:require("./LimitDocumentSource.js"),MatchDocumentSource:require("./MatchDocumentSource.js"),ProjectDocumentSource:require("./ProjectDocumentSource.js"),SkipDocumentSource:require("./SkipDocumentSource.js"),SortDocumentSource:require("./SortDocumentSource.js"),UnwindDocumentSource:require("./UnwindDocumentSource.js")}},{"./CursorDocumentSource.js":18,"./DocumentSource.js":19,"./FilterBaseDocumentSource.js":20,"./GroupDocumentSource.js":21,"./LimitDocumentSource.js":22,"./MatchDocumentSource.js":23,"./ProjectDocumentSource.js":24,"./SkipDocumentSource.js":25,"./SortDocumentSource.js":26,"./UnwindDocumentSource.js":27}],29:[function(require,module){"use strict";var AddExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=AddExpression,NaryExpression=require("./NaryExpression"),base=NaryExpression,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$add"},proto.getFactory=function(){return klass},proto.evaluate=function(doc){for(var total=0,i=0,n=this.operands.length;n>i;++i){var value=this.operands[i].evaluate(doc);if(value instanceof Date)throw new Error("$add does not support dates; code 16415");if("string"==typeof value)throw new Error("$add does not support strings; code 16416");total+=Value.coerceToDouble(value)}if("number"!=typeof total)throw new Error("$add resulted in a non-numeric type; code 16417");return total}},{"../Value":7,"./NaryExpression":49}],30:[function(require,module){"use strict";var AndExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=AndExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value"),ConstantExpression=require("./ConstantExpression"),CoerceToBoolExpression=require("./CoerceToBoolExpression");proto.getOpName=function(){return"$and"},proto.getFactory=function(){return klass},proto.evaluate=function(doc){for(var i=0,n=this.operands.length;n>i;++i){var value=this.operands[i].evaluate(doc);if(!Value.coerceToBool(value))return!1}return!0},proto.optimize=function(){var expr=base.prototype.optimize.call(this);if(!(expr instanceof AndExpression))return expr;var andExpr=expr,n=andExpr.operands.length;if(!n)throw new Error("requires operands!");var lastExpr=andExpr.operands[n-1];if(!(lastExpr instanceof ConstantExpression))return expr;var last=Value.coerceToBool(lastExpr.evaluate());return last?2==n?new CoerceToBoolExpression(andExpr.operands[0]):(andExpr.operands.length=n-1,expr):new ConstantExpression(!1)}},{"../Value":7,"./CoerceToBoolExpression":31,"./ConstantExpression":35,"./NaryExpression":49}],31:[function(require,module){"use strict";var CoerceToBoolExpression=module.exports=function(expression){if(1!==arguments.length)throw new Error("args expected: expression");this.expression=expression,base.call(this)},klass=CoerceToBoolExpression,base=require("./Expression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value"),AndExpression=require("./AndExpression"),OrExpression=require("./OrExpression"),NotExpression=require("./NotExpression");proto.evaluate=function(doc){var result=this.expression.evaluate(doc);return Value.coerceToBool(result)},proto.optimize=function(){this.expression=this.expression.optimize();var expr=this.expression;return expr instanceof AndExpression||expr instanceof OrExpression||expr instanceof NotExpression||expr instanceof CoerceToBoolExpression?expr:this},proto.addDependencies=function(deps){return this.expression.addDependencies(deps)},proto.toJSON=function(){return{$and:[this.expression.toJSON()]}}},{"../Value":7,"./AndExpression":30,"./Expression":40,"./NotExpression":50,"./OrExpression":52}],32:[function(require,module){"use strict";var CompareExpression=module.exports=function(cmpOp){if(1!==arguments.length)throw new Error("args expected: cmpOp");this.cmpOp=cmpOp,base.call(this)},klass=CompareExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value"),Expression=require("./Expression"),ConstantExpression=require("./ConstantExpression"),FieldPathExpression=require("./FieldPathExpression"),FieldRangeExpression=require("./FieldRangeExpression"),CmpLookup=function(){{var klass=function(truthValues,reverse,name){if(3!==arguments.length)throw new Error("args expected: truthValues, reverse, name");this.truthValues=truthValues,this.reverse=reverse,this.name=name},base=Object;klass.prototype=Object.create(base.prototype,{constructor:{value:klass}})}return klass}(),cmpLookupMap=[new CmpLookup([!1,!0,!1],Expression.CmpOp.EQ,Expression.CmpOp.EQ),new CmpLookup([!0,!1,!0],Expression.CmpOp.NE,Expression.CmpOp.NE),new CmpLookup([!1,!1,!0],Expression.CmpOp.LT,Expression.CmpOp.GT),new CmpLookup([!1,!0,!0],Expression.CmpOp.LTE,Expression.CmpOp.GTE),new CmpLookup([!0,!1,!1],Expression.CmpOp.GT,Expression.CmpOp.LT),new CmpLookup([!0,!0,!1],Expression.CmpOp.GTE,Expression.CmpOp.LTE),new CmpLookup([!1,!1,!1],Expression.CmpOp.CMP,Expression.CmpOp.CMP)].reduce(function(r,o){return r[o.name]=o,r},{});proto.addOperand=function(expr){this.checkArgLimit(2),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(2);var left=this.operands[0].evaluate(doc),right=this.operands[1].evaluate(doc),cmp=Expression.signum(Value.compare(left,right));return this.cmpOp==Expression.CmpOp.CMP?cmp:cmpLookupMap[this.cmpOp].truthValues[cmp+1]||!1},proto.optimize=function(){var expr=base.prototype.optimize.call(this);if(!(expr instanceof CompareExpression))return expr;var newOp=this.cmpOp;if(newOp==Expression.CmpOp.CMP||newOp==Expression.CmpOp.NE)return expr;var fieldPathExpr,constantExpr,leftExpr=this.operands[0],rightExpr=this.operands[1];if(leftExpr instanceof FieldPathExpression){if(fieldPathExpr=leftExpr,!(rightExpr instanceof ConstantExpression))return expr;constantExpr=rightExpr}else{if(!(leftExpr instanceof ConstantExpression))return expr;if(constantExpr=leftExpr,!(rightExpr instanceof FieldPathExpression))return expr;fieldPathExpr=rightExpr,newOp=cmpLookupMap[newOp].reverse}return new FieldRangeExpression(fieldPathExpr,newOp,constantExpr.getValue())},proto.getOpName=function(){return this.cmpOp}},{"../Value":7,"./ConstantExpression":35,"./Expression":40,"./FieldPathExpression":41,"./FieldRangeExpression":42,"./NaryExpression":49}],33:[function(require,module){"use strict";var ConcatExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=ConcatExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$concat"},proto.getFactory=function(){return klass},proto.evaluate=function(doc){for(var result="",i=0,n=this.operands.length;n>i;++i){var val=this.operands[i].evaluate(doc);if(null===val)return null;if("string"!=typeof val)throw new Error("$concat only supports strings, not "+typeof val+"; code 16702");result+=Value.coerceToString(val)}return result}},{"../Value":7,"./NaryExpression":49}],34:[function(require,module){"use strict";var CondExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=CondExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$cond"},proto.addOperand=function(expr){this.checkArgLimit(3),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(3);var pCond=this.operands[0].evaluate(doc),idx=Value.coerceToBool(pCond)?1:2;return this.operands[idx].evaluate(doc)}},{"../Value":7,"./NaryExpression":49}],35:[function(require,module){"use strict";var ConstantExpression=module.exports=function(value){if(1!==arguments.length)throw new Error("args expected: value");this.value=value,base.call(this)},klass=ConstantExpression,base=require("./Expression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$const"},proto.getValue=function(){return this.value},proto.addDependencies=function(){},proto.evaluate=function(){return this.value},proto.optimize=function(){return this},proto.toJSON=function(isExpressionRequired){return isExpressionRequired?{$const:this.value}:this.value}},{"./Expression":40}],36:[function(require,module){"use strict";var DayOfMonthExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=DayOfMonthExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$dayOfMonth"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc);return date.getUTCDate()}},{"./NaryExpression":49}],37:[function(require,module){"use strict";var DayOfWeekExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=DayOfWeekExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$dayOfWeek"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc);return date.getUTCDay()+1}},{"./NaryExpression":49}],38:[function(require,module){"use strict";var DayOfYearExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=DayOfYearExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$dayOfYear"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc);return klass.getDateDayOfYear(date)},klass.getDateDayOfYear=function(d){var y11=new Date(d.getUTCFullYear(),0,1),ymd=new Date(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate()+1);return Math.ceil((ymd-y11)/864e5)}},{"./NaryExpression":49}],39:[function(require,module){"use strict";var DivideExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=DivideExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$divide"},proto.addOperand=function(expr){this.checkArgLimit(2),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(2);var left=this.operands[0].evaluate(doc),right=this.operands[1].evaluate(doc);if(!(left instanceof Date)&&!right instanceof Date)throw new Error("$divide does not support dates; code 16373");return right=Value.coerceToDouble(right),0===right?void 0:(left=Value.coerceToDouble(left),left/right)}},{"../Value":7,"./NaryExpression":49}],40:[function(require,module){"use strict";var Expression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected")},klass=Expression,base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Document=require("../Document"),ObjectCtx=Expression.ObjectCtx=function(){var klass=function(opts){if(!(opts instanceof Object&&opts.constructor==Object))throw new Error("opts is required and must be an Object containing named args");for(var k in opts)opts.hasOwnProperty(k)&&proto.hasOwnProperty(k)&&void 0===proto[k]&&(this[k]=opts[k])},base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});return proto.isDocumentOk=proto.isTopLevel=proto.isInclusionOk=void 0,klass}(),OpDesc=Expression.OpDesc=function(){var klass=function(name,factory,flags,argCount){var firstArg=arguments[0];if(firstArg instanceof Object&&firstArg.constructor==Object){var opts=firstArg;for(var k in opts)opts.hasOwnProperty(k)&&proto.hasOwnProperty(k)&&void 0===proto[k]&&(this[k]=opts[k])}else this.name=name,this.factory=factory,this.flags=flags||0,this.argCount=argCount||0},base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});return klass.FIXED_COUNT=1,klass.OBJECT_ARG=2,proto.name=proto.factory=proto.flags=proto.argCount=void 0,proto.cmp=function(that){return this.name<that.name?-1:this.name>that.name?1:0},klass}(),kinds={UNKNOWN:"UNKNOWN",OPERATOR:"OPERATOR",NOT_OPERATOR:"NOT_OPERATOR"};klass.CmpOp={EQ:"$eq",NE:"$ne",GT:"$gt",GTE:"$gte",LT:"$lt",LTE:"$lte",CMP:"$cmp"};var FieldPathExpression=require("./FieldPathExpression"),ObjectExpression=require("./ObjectExpression"),ConstantExpression=require("./ConstantExpression"),CompareExpression=require("./CompareExpression");setTimeout(function(){Object.defineProperty(klass,"opMap",{value:klass.opMap})},0),Object.defineProperty(klass,"opMap",{configurable:!0,get:function(){return Object.defineProperty(klass,"opMap",{value:[new OpDesc("$add",require("./AddExpression"),0),new OpDesc("$and",require("./AndExpression"),0),new OpDesc("$cmp",CompareExpression.bind(null,Expression.CmpOp.CMP),OpDesc.FIXED_COUNT,2),new OpDesc("$concat",require("./ConcatExpression"),0),new OpDesc("$cond",require("./CondExpression"),OpDesc.FIXED_COUNT,3),new OpDesc("$dayOfMonth",require("./DayOfMonthExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$dayOfWeek",require("./DayOfWeekExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$dayOfYear",require("./DayOfYearExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$divide",require("./DivideExpression"),OpDesc.FIXED_COUNT,2),new OpDesc("$eq",CompareExpression.bind(null,Expression.CmpOp.EQ),OpDesc.FIXED_COUNT,2),new OpDesc("$gt",CompareExpression.bind(null,Expression.CmpOp.GT),OpDesc.FIXED_COUNT,2),new OpDesc("$gte",CompareExpression.bind(null,Expression.CmpOp.GTE),OpDesc.FIXED_COUNT,2),new OpDesc("$hour",require("./HourExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$ifNull",require("./IfNullExpression"),OpDesc.FIXED_COUNT,2),new OpDesc("$lt",CompareExpression.bind(null,Expression.CmpOp.LT),OpDesc.FIXED_COUNT,2),new OpDesc("$lte",CompareExpression.bind(null,Expression.CmpOp.LTE),OpDesc.FIXED_COUNT,2),new OpDesc("$minute",require("./MinuteExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$mod",require("./ModExpression"),OpDesc.FIXED_COUNT,2),new OpDesc("$month",require("./MonthExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$multiply",require("./MultiplyExpression"),0),new OpDesc("$ne",CompareExpression.bind(null,Expression.CmpOp.NE),OpDesc.FIXED_COUNT,2),new OpDesc("$not",require("./NotExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$or",require("./OrExpression"),0),new OpDesc("$second",require("./SecondExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$strcasecmp",require("./StrcasecmpExpression"),OpDesc.FIXED_COUNT,2),new OpDesc("$substr",require("./SubstrExpression"),OpDesc.FIXED_COUNT,3),new OpDesc("$subtract",require("./SubtractExpression"),OpDesc.FIXED_COUNT,2),new OpDesc("$toLower",require("./ToLowerExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$toUpper",require("./ToUpperExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$week",require("./WeekExpression"),OpDesc.FIXED_COUNT,1),new OpDesc("$year",require("./YearExpression"),OpDesc.FIXED_COUNT,1)].reduce(function(r,o){return r[o.name]=o,r
  3. },{})}).opMap}}),klass.parseObject=function(obj,ctx){if(!(ctx instanceof ObjectCtx))throw new Error("ctx must be ObjectCtx");var expr,exprObj,kind=kinds.UNKNOWN;if(void 0===obj)return new ObjectExpression;for(var fieldNames=Object.keys(obj),fc=0,n=fieldNames.length;n>fc;++fc){var fn=fieldNames[fc];if("$"===fn[0]){if(0!==fc)throw new Error("the operator must be the only field in a pipeline object (at '"+fn+"'.; code 16410");if(ctx.isTopLevel)throw new Error("$expressions are not allowed at the top-level of $project; code 16404");kind=kinds.OPERATOR,expr=Expression.parseExpression(fn,obj[fn])}else{if(kind===kinds.OPERATOR)throw new Error("this object is already an operator expression, and can't be used as a document expression (at '"+fn+"'.; code 15990");if(!ctx.isTopLevel&&-1!=fn.indexOf("."))throw new Error("dotted field names are only allowed at the top level; code 16405");if(void 0===expr){if(!ctx.isDocumentOk)throw new Error("document not allowed in this context");expr=exprObj=new ObjectExpression,kind=kinds.NOT_OPERATOR}var fv=obj[fn];switch(typeof fv){case"object":var subCtx=new ObjectCtx({isDocumentOk:ctx.isDocumentOk,isInclusionOk:ctx.isInclusionOk});exprObj.addField(fn,Expression.parseObject(fv,subCtx));break;case"string":var pathExpr=new FieldPathExpression(Expression.removeFieldPrefix(fv));exprObj.addField(fn,pathExpr);break;case"boolean":case"number":if(fv){if(!ctx.isInclusionOk)throw new Error("field inclusion is not allowed inside of $expressions; code 16420");exprObj.includePath(fn)}else{if(!ctx.isTopLevel||fn!=Document.ID_PROPERTY_NAME)throw new Error("The top-level "+Document.ID_PROPERTY_NAME+" field is the only field currently supported for exclusion; code 16406");exprObj.excludeId=!0}break;default:throw new Error("disallowed field type "+(fv?fv.constructor.name+":":"")+typeof fv+" in object expression (at '"+fn+"')")}}}return expr},klass.parseExpression=function(opName,obj){if("$const"===opName)return new ConstantExpression(obj);var op=klass.opMap[opName];if(!(op instanceof OpDesc))throw new Error("invalid operator "+opName+"; code 15999");var IExpression=op.factory,expr=new IExpression;if(op.flags&OpDesc.FIXED_COUNT&&op.argCount>1&&!(obj instanceof Array))throw new Error("the "+op.name+" operator requires an array of "+op.argCount+" operands; code 16019");var operand;if(obj.constructor===Object){if(!(op.flags&OpDesc.OBJECT_ARG))throw new Error("the "+op.name+" operator does not accept an object as an operand");operand=Expression.parseObject(obj,new ObjectCtx({isDocumentOk:1})),expr.addOperand(operand)}else if(obj instanceof Array){if(op.flags&OpDesc.FIXED_COUNT&&op.argCount!==obj.length)throw new Error("the "+op.name+" operator requires "+op.argCount+" operand(s); code 16020");for(var i=0,n=obj.length;n>i;++i)operand=Expression.parseOperand(obj[i]),expr.addOperand(operand)}else{if(op.flags&OpDesc.FIXED_COUNT&&1!=op.argCount)throw new Error("the "+op.name+" operator requires an array of "+op.argCount+" operands; code 16022");operand=Expression.parseOperand(obj),expr.addOperand(operand)}return expr},klass.parseOperand=function(obj){var t=typeof obj;if("string"===t&&"$"==obj[0]){var path=Expression.removeFieldPrefix(obj);return new FieldPathExpression(path)}return"object"===t&&obj&&obj.constructor===Object?Expression.parseObject(obj,new ObjectCtx({isDocumentOk:!0})):new ConstantExpression(obj)},klass.removeFieldPrefix=function(prefixedField){if(-1!=prefixedField.indexOf("\x00"))throw new Error("field path must not contain embedded null characters; code 16419");if("$"!==prefixedField[0])throw new Error("field path references must be prefixed with a '$' ('"+prefixedField+"'); code 15982");return prefixedField.substr(1)},klass.signum=function(i){return 0>i?-1:i>0?1:0},proto.evaluate=function(){throw new Error("WAS NOT IMPLEMENTED BY INHERITOR!")},proto.optimize=function(){throw new Error("WAS NOT IMPLEMENTED BY INHERITOR!")},proto.addDependencies=function(){throw new Error("WAS NOT IMPLEMENTED BY INHERITOR!")},proto.getIsSimple=function(){return!1},proto.toMatcherBson=function(){throw new Error("WAS NOT IMPLEMENTED BY INHERITOR!")}},{"../Document":3,"./AddExpression":29,"./AndExpression":30,"./CompareExpression":32,"./ConcatExpression":33,"./CondExpression":34,"./ConstantExpression":35,"./DayOfMonthExpression":36,"./DayOfWeekExpression":37,"./DayOfYearExpression":38,"./DivideExpression":39,"./FieldPathExpression":41,"./HourExpression":43,"./IfNullExpression":44,"./MinuteExpression":45,"./ModExpression":46,"./MonthExpression":47,"./MultiplyExpression":48,"./NotExpression":50,"./ObjectExpression":51,"./OrExpression":52,"./SecondExpression":53,"./StrcasecmpExpression":54,"./SubstrExpression":55,"./SubtractExpression":56,"./ToLowerExpression":57,"./ToUpperExpression":58,"./WeekExpression":59,"./YearExpression":60}],41:[function(require,module){"use strict";var FieldPathExpression=module.exports=function(path){if(1!==arguments.length)throw new Error("args expected: path");this.path=new FieldPath(path)},klass=FieldPathExpression,base=require("./Expression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),FieldPath=require("../FieldPath");proto.evaluate=function(obj){return this._evaluatePath(obj,0,this.path.fields.length)},proto._evaluatePath=function(obj,i,len){var fieldName=this.path.fields[i],field=obj[fieldName];if(void 0===field)return void 0;if(++i>=len)return field;if(null===field)return void 0;if(field.constructor===Object)return this._evaluatePath(field,i,len);if(Array.isArray(field)){for(var results=[],i2=0,l2=field.length;l2>i2;i2++){var subObj=field[i2],subObjType=typeof subObj;if("undefined"===subObjType||null===subObj)results.push(subObj);else{if(subObj.constructor!==Object)throw new Error("the element '"+fieldName+"' along the dotted path '"+this.path.getPath()+"' is not an object, and cannot be navigated.; code 16014");results.push(this._evaluatePath(subObj,i,len))}}return results}return void 0},proto.optimize=function(){return this},proto.addDependencies=function(deps){return deps[this.path.getPath()]=1,deps},proto.getFieldPath=function(usePrefix){return this.path.getPath(usePrefix)},proto.toJSON=function(){return this.path.getPath(!0)}},{"../FieldPath":4,"./Expression":40}],42:[function(require,module){"use strict";var FieldRangeExpression=module.exports=function(pathExpr,cmpOp,value){if(3!==arguments.length)throw new Error("args expected: pathExpr, cmpOp, and value");this.pathExpr=pathExpr,this.range=new Range({cmpOp:cmpOp,value:value})},klass=FieldRangeExpression,Expression=require("./Expression"),base=Expression,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value"),ConstantExpression=require("./ConstantExpression"),Range=function(){var klass=function(opts){if(this.isBottomOpen=this.isTopOpen=!1,this.bottom=this.top=void 0,opts.hasOwnProperty("cmpOp")&&opts.hasOwnProperty("value"))switch(opts.cmpOp){case Expression.CmpOp.EQ:this.bottom=this.top=opts.value;break;case Expression.CmpOp.GT:this.isBottomOpen=!0;case Expression.CmpOp.GTE:this.isTopOpen=!0,this.bottom=opts.value;break;case Expression.CmpOp.LT:this.isTopOpen=!0;case Expression.CmpOp.LTE:this.isBottomOpen=!0,this.top=opts.value;break;case Expression.CmpOp.NE:case Expression.CmpOp.CMP:throw new Error("CmpOp not allowed: "+opts.cmpOp);default:throw new Error("Unexpected CmpOp: "+opts.cmpOp)}else this.bottom=opts.bottom,this.isBottomOpen=opts.isBottomOpen,this.top=opts.top,this.isTopOpen=opts.isTopOpen},base=Object,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});return proto.intersect=function(range){var maxBottom=range.bottom,maxBottomOpen=range.isBottomOpen;void 0!==this.bottom&&(void 0===range.bottom?(maxBottom=this.bottom,maxBottomOpen=this.isBottomOpen):0===Value.compare(this.bottom,range.bottom)?maxBottomOpen=this.isBottomOpen||range.isBottomOpen:(maxBottom=this.bottom,maxBottomOpen=this.isBottomOpen));var minTop=range.top,minTopOpen=range.isTopOpen;return void 0!==this.top&&(void 0===range.top?(minTop=this.top,minTopOpen=this.isTopOpen):0===Value.compare(this.top,range.top)?minTopOpen=this.isTopOpen||range.isTopOpen:(minTop=this.top,minTopOpen=this.isTopOpen)),Value.compare(maxBottom,minTop)<=0?new Range({bottom:maxBottom,isBottomOpen:maxBottomOpen,top:minTop,isTopOpen:minTopOpen}):null},proto.contains=function(value){var cmp;if(void 0!==this.bottom){if(cmp=Value.compare(value,this.bottom),0>cmp)return!1;if(this.isBottomOpen&&0===cmp)return!1}if(void 0!==this.top){if(cmp=Value.compare(value,this.top),cmp>0)return!1;if(this.isTopOpen&&0===cmp)return!1}return!0},klass}();proto.evaluate=function(obj){if(void 0===this.range)return!1;var value=this.pathExpr.evaluate(obj);return this.range.contains(value)},proto.optimize=function(){return void 0===this.range?new ConstantExpression(!1):void 0===this.range.bottom&&void 0===this.range.top?new ConstantExpression(!0):this},proto.addDependencies=function(deps){return this.pathExpr.addDependencies(deps)},proto.intersect=function(cmpOp,value){this.range=this.range.intersect(new Range({cmpOp:cmpOp,value:value}))},proto.toJSON=function(){if(void 0===this.range)return!1;if(void 0===this.range.top&&void 0===this.range.bottom)return!0;var json={};if(this.range.top===this.range.bottom)json[Expression.CmpOp.EQ]=[this.pathExpr.toJSON(),this.range.top];else{var leftOp={};if(void 0!==this.range.bottom&&(leftOp[this.range.isBottomOpen?Expression.CmpOp.GT:Expression.CmpOp.GTE]=[this.pathExpr.toJSON(),this.range.bottom],void 0===this.range.top))return leftOp;var rightOp={};if(void 0!==this.range.top&&(rightOp[this.range.isTopOpen?Expression.CmpOp.LT:Expression.CmpOp.LTE]=[this.pathExpr.toJSON(),this.range.top],void 0===this.range.bottom))return rightOp;json.$and=[leftOp,rightOp]}return json}},{"../Value":7,"./ConstantExpression":35,"./Expression":40}],43:[function(require,module){"use strict";var HourExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=HourExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$hour"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc);return date.getUTCHours()}},{"./NaryExpression":49}],44:[function(require,module){"use strict";var IfNullExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=IfNullExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$ifNull"},proto.addOperand=function(expr){this.checkArgLimit(2),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(2);var left=this.operands[0].evaluate(doc);if(void 0!==left&&null!==left)return left;var right=this.operands[1].evaluate(doc);return right}},{"./NaryExpression":49}],45:[function(require,module){"use strict";var MinuteExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=MinuteExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$minute"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc);return date.getUTCMinutes()}},{"./NaryExpression":49}],46:[function(require,module){"use strict";var ModExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=ModExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$mod"},proto.addOperand=function(expr){this.checkArgLimit(2),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(2);var left=this.operands[0].evaluate(doc),right=this.operands[1].evaluate(doc);if(left instanceof Date||right instanceof Date)throw new Error("$mod does not support dates; code 16374");return void 0===left||null===left?left:void 0===right||null===right?right:(right=Value.coerceToDouble(right),0===right?void 0:(left=Value.coerceToDouble(left),left%right))}},{"../Value":7,"./NaryExpression":49}],47:[function(require,module){"use strict";var MonthExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=MonthExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$month"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc);return date.getUTCMonth()+1}},{"./NaryExpression":49}],48:[function(require,module){"use strict";var MultiplyExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=MultiplyExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$multiply"},proto.evaluate=function(doc){for(var product=1,i=0,n=this.operands.length;n>i;++i){var value=this.operands[i].evaluate(doc);if(value instanceof Date)throw new Error("$multiply does not support dates; code 16375");product*=Value.coerceToDouble(value)}if("number"!=typeof product)throw new Error("$multiply resulted in a non-numeric type; code 16418");return product},proto.getFactory=function(){return klass}},{"../Value":7,"./NaryExpression":49}],49:[function(require,module){"use strict";var NaryExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");this.operands=[],base.call(this)},klass=NaryExpression,base=require("./Expression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),ConstantExpression=require("./ConstantExpression");proto.evaluate=void 0,proto.getOpName=function(){throw new Error("NOT IMPLEMENTED BY INHERITOR")},proto.optimize=function(){for(var constsFound=0,stringsFound=0,i=0,l=this.operands.length;l>i;i++){var optimizedExpr=this.operands[i].optimize();optimizedExpr instanceof ConstantExpression&&(constsFound++,"string"==typeof optimizedExpr.value&&stringsFound++),this.operands[i]=optimizedExpr}if(constsFound===l)return new ConstantExpression(this.evaluate());if(stringsFound)return this;if(1>=constsFound)return this;var IExpression=this.getFactory();if(!(IExpression instanceof Function))return this;var expr=new IExpression,constExpr=new IExpression;for(i=0;l>i;++i){var operandExpr=this.operands[i];if(operandExpr instanceof ConstantExpression)constExpr.addOperand(operandExpr);else if(operandExpr instanceof NaryExpression)if(operandExpr.getFactory()!==IExpression)expr.addOperand(operandExpr);else for(var i2=0,n2=operandExpr.operands.length;n2>i2;++i2){var childOperandExpr=operandExpr.operands[i2];childOperandExpr instanceof ConstantExpression?constExpr.addOperand(childOperandExpr):expr.addOperand(childOperandExpr)}else expr.addOperand(operandExpr)}if(1===constExpr.operands.length)expr.addOperand(constExpr.operands[0]);else if(constExpr.operands.length>1){var pResult=constExpr.evaluate();expr.addOperand(new ConstantExpression(pResult))}return expr},proto.addDependencies=function(deps){for(var i=0,l=this.operands.length;l>i;++i)this.operands[i].addDependencies(deps);return deps},proto.addOperand=function(expr){this.operands.push(expr)},proto.getFactory=function(){return void 0},proto.toJSON=function(){var o={};return o[this.getOpName()]=this.operands.map(function(operand){return operand.toJSON()}),o},proto.checkArgLimit=function(maxArgs){if(this.operands.length>=maxArgs)throw new Error(this.getOpName()+" only takes "+maxArgs+" operand"+(1==maxArgs?"":"s")+"; code 15993")},proto.checkArgCount=function(reqArgs){if(this.operands.length!==reqArgs)throw new Error(this.getOpName()+": insufficient operands; "+reqArgs+" required, only got "+this.operands.length+"; code 15997")}},{"./ConstantExpression":35,"./Expression":40}],50:[function(require,module){"use strict";var NotExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=NotExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$not"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var op=this.operands[0].evaluate(doc);return!Value.coerceToBool(op)}},{"../Value":7,"./NaryExpression":49}],51:[function(require,module){"use strict";var ObjectExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");this.excludeId=!1,this._expressions={},this._order=[]},klass=ObjectExpression,Expression=require("./Expression"),base=Expression,proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Document=require("../Document"),FieldPath=require("../FieldPath");proto.excludeId=void 0,proto._expressions=void 0,proto._order=[],proto.evaluateDocument=function(doc){var pResult={};return this.addToDocument(pResult,pResult,doc),pResult},proto.evaluate=function(doc){return this.evaluateDocument(doc)},proto.optimize=function(){for(var key in this._expressions){var expr=this._expressions[key];void 0!==expr&&null!==expr&&(this._expressions[key]=expr.optimize())}return this},proto.getIsSimple=function(){for(var key in this._expressions){var expr=this._expressions[key];if(void 0!==expr&&null!==expr&&!expr.getIsSimple())return!1}return!0},proto.addDependencies=function(deps,path){var depsSet={},pathStr="";if(path instanceof Array)0===path.length?this.excludeId||(depsSet[Document.ID_PROPERTY_NAME]=1):pathStr=new FieldPath(path).getPath()+".";else if(this.excludeId)throw new Error("excludeId is true!");for(var key in this._expressions){var expr=this._expressions[key];if(void 0!==expr&&null!==expr)path instanceof Array&&path.push(key),expr.addDependencies(deps,path),path instanceof Array&&path.pop();else{if(void 0===path||null===path)throw new Error("inclusion not supported in objects nested in $expressions; uassert code 16407");depsSet[pathStr+key]=1}}for(key in depsSet)deps[key]=1;return deps},proto.addToDocument=function(pResult,pDocument,rootDoc){var atRoot=pDocument===rootDoc,doneFields={};for(var fieldName in pDocument)if(pDocument.hasOwnProperty(fieldName)){var fieldValue=pDocument[fieldName];if(this._expressions.hasOwnProperty(fieldName)){doneFields[fieldName]=!0;var expr=this._expressions[fieldName];if(expr instanceof Expression)if(fieldValue instanceof Object&&(fieldValue.constructor===Object||fieldValue.constructor===Array)&&expr instanceof ObjectExpression)if(fieldValue instanceof Object&&fieldValue.constructor===Object)pResult[fieldName]=expr.addToDocument({},fieldValue,rootDoc);else{if(!(fieldValue instanceof Object&&fieldValue.constructor===Array))throw new Error("should never happen");for(var result=[],fvi=0,fvl=fieldValue.length;fvl>fvi;fvi++){var subValue=fieldValue[fvi];subValue.constructor===Object&&result.push(expr.addToDocument({},subValue,rootDoc))}pResult[fieldName]=result}else{var pValue=expr.evaluate(rootDoc);if(expr instanceof ObjectExpression&&pValue instanceof Object&&0===Object.getOwnPropertyNames(pValue).length)continue;void 0!==pValue&&(pResult[fieldName]=pValue)}else pResult[fieldName]=fieldValue}else!this.excludeId&&atRoot&&fieldName==Document.ID_PROPERTY_NAME&&(pResult[fieldName]=fieldValue)}if(Object.getOwnPropertyNames(doneFields).length==Object.getOwnPropertyNames(this._expressions).length)return pResult;for(var i=0,l=this._order.length;l>i;i++){var fieldName2=this._order[i],expr2=this._expressions[fieldName2];if(!doneFields.hasOwnProperty(fieldName2)&&expr2){var value=expr2.evaluate(rootDoc);void 0!==value&&(expr2 instanceof ObjectExpression&&value&&value instanceof Object&&0===Object.getOwnPropertyNames(value).length||(pResult[fieldName2]=value))}}return pResult},proto.getSizeHint=function(){return Object.getOwnPropertyNames(this._expressions).length+(this.excludeId?0:1)},proto.addField=function(fieldPath,pExpression){fieldPath instanceof FieldPath||(fieldPath=new FieldPath(fieldPath));var fieldPart=fieldPath.fields[0],haveExpr=this._expressions.hasOwnProperty(fieldPart),subObj=this._expressions[fieldPart];if(haveExpr){if(1==fieldPath.getPathLength()){if(!(subObj instanceof ObjectExpression&&"object"==typeof pExpression&&pExpression instanceof ObjectExpression))throw new Error("can't add an expression for field `"+fieldPart+"` because there is already an expression for that field or one of its sub-fields; uassert code 16400");for(var key in pExpression._expressions)pExpression._expressions.hasOwnProperty(key)&&subObj.addField(key,pExpression._expressions[key]);return}if(!subObj)throw new Error("can't add an expression for a subfield of `"+fieldPart+"` because there is already an expression that applies to the whole field; uassert code 16401")}else this._order.push(fieldPart);if(1==fieldPath.getPathLength()){if(haveExpr)throw new Error("Internal error.");return void(this._expressions[fieldPart]=pExpression)}haveExpr||(subObj=this._expressions[fieldPart]=new ObjectExpression),subObj.addField(fieldPath.tail(),pExpression)},proto.includePath=function(path){this.addField(path,void 0)},proto.getFieldCount=function(){return Object.getOwnPropertyNames(this._expressions).length},proto.toJSON=function(requireExpression){var o={};this.excludeId&&(o[Document.ID_PROPERTY_NAME]=!1);for(var i=0,l=this._order.length;l>i;i++){var fieldName=this._order[i];if(!this._expressions.hasOwnProperty(fieldName))throw new Error("internal error: fieldName from _ordered list not found in _expressions");var fieldValue=this._expressions[fieldName];o[fieldName]=void 0===fieldValue?!0:fieldValue.toJSON(requireExpression)}return o}},{"../Document":3,"../FieldPath":4,"./Expression":40}],52:[function(require,module){"use strict";var OrExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=OrExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value"),ConstantExpression=require("./ConstantExpression"),CoerceToBoolExpression=require("./CoerceToBoolExpression");proto.getOpName=function(){return"$or"},proto.evaluate=function(doc){for(var i=0,n=this.operands.length;n>i;++i){var value=this.operands[i].evaluate(doc);if(Value.coerceToBool(value))return!0}return!1},proto.optimize=function(){var pE=base.prototype.optimize.call(this);if(!(pE instanceof OrExpression))return pE;var pOr=pE,n=pOr.operands.length;if(!n)throw new Error("OrExpression must have operands!");var pLast=pOr.operands[n-1];if(!(pLast instanceof ConstantExpression))return pE;var last=Value.coerceToBool(pLast.evaluate());return last?new ConstantExpression(!0):2==n?new CoerceToBoolExpression(pOr.operands[0]):(pOr.operands.length=n-1,pE)},proto.getFactory=function(){return klass}},{"../Value":7,"./CoerceToBoolExpression":31,"./ConstantExpression":35,"./NaryExpression":49}],53:[function(require,module){"use strict";var SecondExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=SecondExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});proto.getOpName=function(){return"$second"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc);return date.getUTCSeconds()}},{"./NaryExpression":49}],54:[function(require,module){"use strict";{var StrcasecmpExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=StrcasecmpExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");require("./NaryExpression")}proto.getOpName=function(){return"$strcasecmp"},proto.addOperand=function(expr){this.checkArgLimit(2),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(2);var val1=this.operands[0].evaluate(doc),val2=this.operands[1].evaluate(doc),str1=Value.coerceToString(val1).toUpperCase(),str2=Value.coerceToString(val2).toUpperCase(),cmp=Value.compare(str1,str2);return cmp}},{"../Value":7,"./NaryExpression":49}],55:[function(require,module){"use strict";var SubstrExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=SubstrExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$substr"},proto.addOperand=function(expr){this.checkArgLimit(3),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(3);var val=this.operands[0].evaluate(doc),idx=this.operands[1].evaluate(doc),len=this.operands[2].evaluate(doc),str=Value.coerceToString(val);if("number"!=typeof idx)throw new Error(this.getOpName()+": starting index must be a numeric type; code 16034");if("number"!=typeof len)throw new Error(this.getOpName()+": length must be a numeric type; code 16035");return idx>=str.length?"":(len=-1===len?void 0:len,str.substr(idx,len))}},{"../Value":7,"./NaryExpression":49}],56:[function(require,module){"use strict";{var SubtractExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=SubtractExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});require("../Value")}proto.getOpName=function(){return"$subtract"},proto.addOperand=function(expr){this.checkArgLimit(2),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(2);var left=this.operands[0].evaluate(doc),right=this.operands[1].evaluate(doc);return left-right}},{"../Value":7,"./NaryExpression":49}],57:[function(require,module){"use strict";var ToLowerExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=ToLowerExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$toLower"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var val=this.operands[0].evaluate(doc),str=Value.coerceToString(val);return str.toLowerCase()}},{"../Value":7,"./NaryExpression":49}],58:[function(require,module){"use strict";var ToUpperExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=ToUpperExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),Value=require("../Value");proto.getOpName=function(){return"$toUpper"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var val=this.operands[0].evaluate(doc),str=Value.coerceToString(val);return str.toUpperCase()}},{"../Value":7,"./NaryExpression":49}],59:[function(require,module){"use strict";var WeekExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=WeekExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}}),DayOfYearExpression=(require("../Value"),require("./DayOfYearExpression"));proto.getOpName=function(){return"$week"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc),dayOfWeek=date.getUTCDay(),dayOfYear=DayOfYearExpression.getDateDayOfYear(date),prevSundayDayOfYear=dayOfYear-dayOfWeek,nextSundayDayOfYear=prevSundayDayOfYear+7;return nextSundayDayOfYear/7|0}},{"../Value":7,"./DayOfYearExpression":38,"./NaryExpression":49}],60:[function(require,module){"use strict";{var YearExpression=module.exports=function(){if(0!==arguments.length)throw new Error("zero args expected");base.call(this)},klass=YearExpression,base=require("./NaryExpression"),proto=klass.prototype=Object.create(base.prototype,{constructor:{value:klass}});require("../Value"),require("./DayOfYearExpression")}proto.getOpName=function(){return"$year"},proto.addOperand=function(expr){this.checkArgLimit(1),base.prototype.addOperand.call(this,expr)},proto.evaluate=function(doc){this.checkArgCount(1);var date=this.operands[0].evaluate(doc);return date.getUTCFullYear()}},{"../Value":7,"./DayOfYearExpression":38,"./NaryExpression":49}],61:[function(require,module){"use strict";module.exports={AddExpression:require("./AddExpression.js"),AndExpression:require("./AndExpression.js"),CoerceToBoolExpression:require("./CoerceToBoolExpression.js"),CompareExpression:require("./CompareExpression.js"),CondExpression:require("./CondExpression.js"),ConstantExpression:require("./ConstantExpression.js"),DayOfMonthExpression:require("./DayOfMonthExpression.js"),DayOfWeekExpression:require("./DayOfWeekExpression.js"),DayOfYearExpression:require("./DayOfYearExpression.js"),DivideExpression:require("./DivideExpression.js"),Expression:require("./Expression.js"),FieldPathExpression:require("./FieldPathExpression.js"),FieldRangeExpression:require("./FieldRangeExpression.js"),HourExpression:require("./HourExpression.js"),IfNullExpression:require("./IfNullExpression.js"),MinuteExpression:require("./MinuteExpression.js"),ModExpression:require("./ModExpression.js"),MonthExpression:require("./MonthExpression.js"),MultiplyExpression:require("./MultiplyExpression.js"),NaryExpression:require("./NaryExpression.js"),NotExpression:require("./NotExpression.js"),ObjectExpression:require("./ObjectExpression.js"),OrExpression:require("./OrExpression.js"),SecondExpression:require("./SecondExpression.js"),StrcasecmpExpression:require("./StrcasecmpExpression.js"),SubstrExpression:require("./SubstrExpression.js"),SubtractExpression:require("./SubtractExpression.js"),ToLowerExpression:require("./ToLowerExpression.js"),ToUpperExpression:require("./ToUpperExpression.js"),WeekExpression:require("./WeekExpression.js"),YearExpression:require("./YearExpression.js")}},{"./AddExpression.js":29,"./AndExpression.js":30,"./CoerceToBoolExpression.js":31,"./CompareExpression.js":32,"./CondExpression.js":34,"./ConstantExpression.js":35,"./DayOfMonthExpression.js":36,"./DayOfWeekExpression.js":37,"./DayOfYearExpression.js":38,"./DivideExpression.js":39,"./Expression.js":40,"./FieldPathExpression.js":41,"./FieldRangeExpression.js":42,"./HourExpression.js":43,"./IfNullExpression.js":44,"./MinuteExpression.js":45,"./ModExpression.js":46,"./MonthExpression.js":47,"./MultiplyExpression.js":48,"./NaryExpression.js":49,"./NotExpression.js":50,"./ObjectExpression.js":51,"./OrExpression.js":52,"./SecondExpression.js":53,"./StrcasecmpExpression.js":54,"./SubstrExpression.js":55,"./SubtractExpression.js":56,"./ToLowerExpression.js":57,"./ToUpperExpression.js":58,"./WeekExpression.js":59,"./YearExpression.js":60}],62:[function(require,module){"use strict";
  4. module.exports={Pipeline:require("./Pipeline"),PipelineD:require("./PipelineD"),FieldPath:require("./FieldPath"),Document:require("./Document"),Value:require("./Value"),accumulators:require("./accumulators/"),documentSources:require("./documentSources/"),expressions:require("./expressions/")}},{"./Document":3,"./FieldPath":4,"./Pipeline":5,"./PipelineD":6,"./Value":7,"./accumulators/":17,"./documentSources/":28,"./expressions/":61}],63:[function(require,module){(function(process){!function(){function only_once(fn){var called=!1;return function(){if(called)throw new Error("Callback was already called.");called=!0,fn.apply(root,arguments)}}var root,previous_async,async={};root=this,null!=root&&(previous_async=root.async),async.noConflict=function(){return root.async=previous_async,async};var _toString=Object.prototype.toString,_isArray=Array.isArray||function(obj){return"[object Array]"===_toString.call(obj)},_each=function(arr,iterator){if(arr.forEach)return arr.forEach(iterator);for(var i=0;i<arr.length;i+=1)iterator(arr[i],i,arr)},_map=function(arr,iterator){if(arr.map)return arr.map(iterator);var results=[];return _each(arr,function(x,i,a){results.push(iterator(x,i,a))}),results},_reduce=function(arr,iterator,memo){return arr.reduce?arr.reduce(iterator,memo):(_each(arr,function(x,i,a){memo=iterator(memo,x,i,a)}),memo)},_keys=function(obj){if(Object.keys)return Object.keys(obj);var keys=[];for(var k in obj)obj.hasOwnProperty(k)&&keys.push(k);return keys};"undefined"!=typeof process&&process.nextTick?(async.nextTick=process.nextTick,async.setImmediate="undefined"!=typeof setImmediate?function(fn){setImmediate(fn)}:async.nextTick):"function"==typeof setImmediate?(async.nextTick=function(fn){setImmediate(fn)},async.setImmediate=async.nextTick):(async.nextTick=function(fn){setTimeout(fn,0)},async.setImmediate=async.nextTick),async.each=function(arr,iterator,callback){function done(err){err?(callback(err),callback=function(){}):(completed+=1,completed>=arr.length&&callback())}if(callback=callback||function(){},!arr.length)return callback();var completed=0;_each(arr,function(x){iterator(x,only_once(done))})},async.forEach=async.each,async.eachSeries=function(arr,iterator,callback){if(callback=callback||function(){},!arr.length)return callback();var completed=0,iterate=function(){iterator(arr[completed],function(err){err?(callback(err),callback=function(){}):(completed+=1,completed>=arr.length?callback():iterate())})};iterate()},async.forEachSeries=async.eachSeries,async.eachLimit=function(arr,limit,iterator,callback){var fn=_eachLimit(limit);fn.apply(null,[arr,iterator,callback])},async.forEachLimit=async.eachLimit;var _eachLimit=function(limit){return function(arr,iterator,callback){if(callback=callback||function(){},!arr.length||0>=limit)return callback();var completed=0,started=0,running=0;!function replenish(){if(completed>=arr.length)return callback();for(;limit>running&&started<arr.length;)started+=1,running+=1,iterator(arr[started-1],function(err){err?(callback(err),callback=function(){}):(completed+=1,running-=1,completed>=arr.length?callback():replenish())})}()}},doParallel=function(fn){return function(){var args=Array.prototype.slice.call(arguments);return fn.apply(null,[async.each].concat(args))}},doParallelLimit=function(limit,fn){return function(){var args=Array.prototype.slice.call(arguments);return fn.apply(null,[_eachLimit(limit)].concat(args))}},doSeries=function(fn){return function(){var args=Array.prototype.slice.call(arguments);return fn.apply(null,[async.eachSeries].concat(args))}},_asyncMap=function(eachfn,arr,iterator,callback){if(arr=_map(arr,function(x,i){return{index:i,value:x}}),callback){var results=[];eachfn(arr,function(x,callback){iterator(x.value,function(err,v){results[x.index]=v,callback(err)})},function(err){callback(err,results)})}else eachfn(arr,function(x,callback){iterator(x.value,function(err){callback(err)})})};async.map=doParallel(_asyncMap),async.mapSeries=doSeries(_asyncMap),async.mapLimit=function(arr,limit,iterator,callback){return _mapLimit(limit)(arr,iterator,callback)};var _mapLimit=function(limit){return doParallelLimit(limit,_asyncMap)};async.reduce=function(arr,memo,iterator,callback){async.eachSeries(arr,function(x,callback){iterator(memo,x,function(err,v){memo=v,callback(err)})},function(err){callback(err,memo)})},async.inject=async.reduce,async.foldl=async.reduce,async.reduceRight=function(arr,memo,iterator,callback){var reversed=_map(arr,function(x){return x}).reverse();async.reduce(reversed,memo,iterator,callback)},async.foldr=async.reduceRight;var _filter=function(eachfn,arr,iterator,callback){var results=[];arr=_map(arr,function(x,i){return{index:i,value:x}}),eachfn(arr,function(x,callback){iterator(x.value,function(v){v&&results.push(x),callback()})},function(){callback(_map(results.sort(function(a,b){return a.index-b.index}),function(x){return x.value}))})};async.filter=doParallel(_filter),async.filterSeries=doSeries(_filter),async.select=async.filter,async.selectSeries=async.filterSeries;var _reject=function(eachfn,arr,iterator,callback){var results=[];arr=_map(arr,function(x,i){return{index:i,value:x}}),eachfn(arr,function(x,callback){iterator(x.value,function(v){v||results.push(x),callback()})},function(){callback(_map(results.sort(function(a,b){return a.index-b.index}),function(x){return x.value}))})};async.reject=doParallel(_reject),async.rejectSeries=doSeries(_reject);var _detect=function(eachfn,arr,iterator,main_callback){eachfn(arr,function(x,callback){iterator(x,function(result){result?(main_callback(x),main_callback=function(){}):callback()})},function(){main_callback()})};async.detect=doParallel(_detect),async.detectSeries=doSeries(_detect),async.some=function(arr,iterator,main_callback){async.each(arr,function(x,callback){iterator(x,function(v){v&&(main_callback(!0),main_callback=function(){}),callback()})},function(){main_callback(!1)})},async.any=async.some,async.every=function(arr,iterator,main_callback){async.each(arr,function(x,callback){iterator(x,function(v){v||(main_callback(!1),main_callback=function(){}),callback()})},function(){main_callback(!0)})},async.all=async.every,async.sortBy=function(arr,iterator,callback){async.map(arr,function(x,callback){iterator(x,function(err,criteria){err?callback(err):callback(null,{value:x,criteria:criteria})})},function(err,results){if(err)return callback(err);var fn=function(left,right){var a=left.criteria,b=right.criteria;return b>a?-1:a>b?1:0};callback(null,_map(results.sort(fn),function(x){return x.value}))})},async.auto=function(tasks,callback){callback=callback||function(){};var keys=_keys(tasks),remainingTasks=keys.length;if(!remainingTasks)return callback();var results={},listeners=[],addListener=function(fn){listeners.unshift(fn)},removeListener=function(fn){for(var i=0;i<listeners.length;i+=1)if(listeners[i]===fn)return void listeners.splice(i,1)},taskComplete=function(){remainingTasks--,_each(listeners.slice(0),function(fn){fn()})};addListener(function(){if(!remainingTasks){var theCallback=callback;callback=function(){},theCallback(null,results)}}),_each(keys,function(k){var task=_isArray(tasks[k])?tasks[k]:[tasks[k]],taskCallback=function(err){var args=Array.prototype.slice.call(arguments,1);if(args.length<=1&&(args=args[0]),err){var safeResults={};_each(_keys(results),function(rkey){safeResults[rkey]=results[rkey]}),safeResults[k]=args,callback(err,safeResults),callback=function(){}}else results[k]=args,async.setImmediate(taskComplete)},requires=task.slice(0,Math.abs(task.length-1))||[],ready=function(){return _reduce(requires,function(a,x){return a&&results.hasOwnProperty(x)},!0)&&!results.hasOwnProperty(k)};if(ready())task[task.length-1](taskCallback,results);else{var listener=function(){ready()&&(removeListener(listener),task[task.length-1](taskCallback,results))};addListener(listener)}})},async.retry=function(times,task,callback){var DEFAULT_TIMES=5,attempts=[];"function"==typeof times&&(callback=task,task=times,times=DEFAULT_TIMES),times=parseInt(times,10)||DEFAULT_TIMES;var wrappedTask=function(wrappedCallback,wrappedResults){for(var retryAttempt=function(task,finalAttempt){return function(seriesCallback){task(function(err,result){seriesCallback(!err||finalAttempt,{err:err,result:result})},wrappedResults)}};times;)attempts.push(retryAttempt(task,!(times-=1)));async.series(attempts,function(done,data){data=data[data.length-1],(wrappedCallback||callback)(data.err,data.result)})};return callback?wrappedTask():wrappedTask},async.waterfall=function(tasks,callback){if(callback=callback||function(){},!_isArray(tasks)){var err=new Error("First argument to waterfall must be an array of functions");return callback(err)}if(!tasks.length)return callback();var wrapIterator=function(iterator){return function(err){if(err)callback.apply(null,arguments),callback=function(){};else{var args=Array.prototype.slice.call(arguments,1),next=iterator.next();args.push(next?wrapIterator(next):callback),async.setImmediate(function(){iterator.apply(null,args)})}}};wrapIterator(async.iterator(tasks))()};var _parallel=function(eachfn,tasks,callback){if(callback=callback||function(){},_isArray(tasks))eachfn.map(tasks,function(fn,callback){fn&&fn(function(err){var args=Array.prototype.slice.call(arguments,1);args.length<=1&&(args=args[0]),callback.call(null,err,args)})},callback);else{var results={};eachfn.each(_keys(tasks),function(k,callback){tasks[k](function(err){var args=Array.prototype.slice.call(arguments,1);args.length<=1&&(args=args[0]),results[k]=args,callback(err)})},function(err){callback(err,results)})}};async.parallel=function(tasks,callback){_parallel({map:async.map,each:async.each},tasks,callback)},async.parallelLimit=function(tasks,limit,callback){_parallel({map:_mapLimit(limit),each:_eachLimit(limit)},tasks,callback)},async.series=function(tasks,callback){if(callback=callback||function(){},_isArray(tasks))async.mapSeries(tasks,function(fn,callback){fn&&fn(function(err){var args=Array.prototype.slice.call(arguments,1);args.length<=1&&(args=args[0]),callback.call(null,err,args)})},callback);else{var results={};async.eachSeries(_keys(tasks),function(k,callback){tasks[k](function(err){var args=Array.prototype.slice.call(arguments,1);args.length<=1&&(args=args[0]),results[k]=args,callback(err)})},function(err){callback(err,results)})}},async.iterator=function(tasks){var makeCallback=function(index){var fn=function(){return tasks.length&&tasks[index].apply(null,arguments),fn.next()};return fn.next=function(){return index<tasks.length-1?makeCallback(index+1):null},fn};return makeCallback(0)},async.apply=function(fn){var args=Array.prototype.slice.call(arguments,1);return function(){return fn.apply(null,args.concat(Array.prototype.slice.call(arguments)))}};var _concat=function(eachfn,arr,fn,callback){var r=[];eachfn(arr,function(x,cb){fn(x,function(err,y){r=r.concat(y||[]),cb(err)})},function(err){callback(err,r)})};async.concat=doParallel(_concat),async.concatSeries=doSeries(_concat),async.whilst=function(test,iterator,callback){test()?iterator(function(err){return err?callback(err):void async.whilst(test,iterator,callback)}):callback()},async.doWhilst=function(iterator,test,callback){iterator(function(err){if(err)return callback(err);var args=Array.prototype.slice.call(arguments,1);test.apply(null,args)?async.doWhilst(iterator,test,callback):callback()})},async.until=function(test,iterator,callback){test()?callback():iterator(function(err){return err?callback(err):void async.until(test,iterator,callback)})},async.doUntil=function(iterator,test,callback){iterator(function(err){if(err)return callback(err);var args=Array.prototype.slice.call(arguments,1);test.apply(null,args)?callback():async.doUntil(iterator,test,callback)})},async.queue=function(worker,concurrency){function _insert(q,data,pos,callback){return q.started||(q.started=!0),_isArray(data)||(data=[data]),0==data.length?async.setImmediate(function(){q.drain&&q.drain()}):void _each(data,function(task){var item={data:task,callback:"function"==typeof callback?callback:null};pos?q.tasks.unshift(item):q.tasks.push(item),q.saturated&&q.tasks.length===q.concurrency&&q.saturated(),async.setImmediate(q.process)})}void 0===concurrency&&(concurrency=1);var workers=0,q={tasks:[],concurrency:concurrency,saturated:null,empty:null,drain:null,started:!1,paused:!1,push:function(data,callback){_insert(q,data,!1,callback)},kill:function(){q.drain=null,q.tasks=[]},unshift:function(data,callback){_insert(q,data,!0,callback)},process:function(){if(!q.paused&&workers<q.concurrency&&q.tasks.length){var task=q.tasks.shift();q.empty&&0===q.tasks.length&&q.empty(),workers+=1;var next=function(){workers-=1,task.callback&&task.callback.apply(task,arguments),q.drain&&q.tasks.length+workers===0&&q.drain(),q.process()},cb=only_once(next);worker(task.data,cb)}},length:function(){return q.tasks.length},running:function(){return workers},idle:function(){return q.tasks.length+workers===0},pause:function(){q.paused!==!0&&(q.paused=!0,q.process())},resume:function(){q.paused!==!1&&(q.paused=!1,q.process())}};return q},async.priorityQueue=function(worker,concurrency){function _compareTasks(a,b){return a.priority-b.priority}function _binarySearch(sequence,item,compare){for(var beg=-1,end=sequence.length-1;end>beg;){var mid=beg+(end-beg+1>>>1);compare(item,sequence[mid])>=0?beg=mid:end=mid-1}return beg}function _insert(q,data,priority,callback){return q.started||(q.started=!0),_isArray(data)||(data=[data]),0==data.length?async.setImmediate(function(){q.drain&&q.drain()}):void _each(data,function(task){var item={data:task,priority:priority,callback:"function"==typeof callback?callback:null};q.tasks.splice(_binarySearch(q.tasks,item,_compareTasks)+1,0,item),q.saturated&&q.tasks.length===q.concurrency&&q.saturated(),async.setImmediate(q.process)})}var q=async.queue(worker,concurrency);return q.push=function(data,priority,callback){_insert(q,data,priority,callback)},delete q.unshift,q},async.cargo=function(worker,payload){var working=!1,tasks=[],cargo={tasks:tasks,payload:payload,saturated:null,empty:null,drain:null,drained:!0,push:function(data,callback){_isArray(data)||(data=[data]),_each(data,function(task){tasks.push({data:task,callback:"function"==typeof callback?callback:null}),cargo.drained=!1,cargo.saturated&&tasks.length===payload&&cargo.saturated()}),async.setImmediate(cargo.process)},process:function process(){if(!working){if(0===tasks.length)return cargo.drain&&!cargo.drained&&cargo.drain(),void(cargo.drained=!0);var ts="number"==typeof payload?tasks.splice(0,payload):tasks.splice(0,tasks.length),ds=_map(ts,function(task){return task.data});cargo.empty&&cargo.empty(),working=!0,worker(ds,function(){working=!1;var args=arguments;_each(ts,function(data){data.callback&&data.callback.apply(null,args)}),process()})}},length:function(){return tasks.length},running:function(){return working}};return cargo};var _console_fn=function(name){return function(fn){var args=Array.prototype.slice.call(arguments,1);fn.apply(null,args.concat([function(err){var args=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(err?console.error&&console.error(err):console[name]&&_each(args,function(x){console[name](x)}))}]))}};async.log=_console_fn("log"),async.dir=_console_fn("dir"),async.memoize=function(fn,hasher){var memo={},queues={};hasher=hasher||function(x){return x};var memoized=function(){var args=Array.prototype.slice.call(arguments),callback=args.pop(),key=hasher.apply(null,args);key in memo?async.nextTick(function(){callback.apply(null,memo[key])}):key in queues?queues[key].push(callback):(queues[key]=[callback],fn.apply(null,args.concat([function(){memo[key]=arguments;var q=queues[key];delete queues[key];for(var i=0,l=q.length;l>i;i++)q[i].apply(null,arguments)}])))};return memoized.memo=memo,memoized.unmemoized=fn,memoized},async.unmemoize=function(fn){return function(){return(fn.unmemoized||fn).apply(null,arguments)}},async.times=function(count,iterator,callback){for(var counter=[],i=0;count>i;i++)counter.push(i);return async.map(counter,iterator,callback)},async.timesSeries=function(count,iterator,callback){for(var counter=[],i=0;count>i;i++)counter.push(i);return async.mapSeries(counter,iterator,callback)},async.seq=function(){var fns=arguments;return function(){var that=this,args=Array.prototype.slice.call(arguments),callback=args.pop();async.reduce(fns,args,function(newargs,fn,cb){fn.apply(that,newargs.concat([function(){var err=arguments[0],nextargs=Array.prototype.slice.call(arguments,1);cb(err,nextargs)}]))},function(err,results){callback.apply(that,[err].concat(results))})}},async.compose=function(){return async.seq.apply(null,Array.prototype.reverse.call(arguments))};var _applyEach=function(eachfn,fns){var go=function(){var that=this,args=Array.prototype.slice.call(arguments),callback=args.pop();return eachfn(fns,function(fn,cb){fn.apply(that,args.concat([cb]))},callback)};if(arguments.length>2){var args=Array.prototype.slice.call(arguments,2);return go.apply(this,args)}return go};async.applyEach=doParallel(_applyEach),async.applyEachSeries=doSeries(_applyEach),async.forever=function(fn,callback){function next(err){if(err){if(callback)return callback(err);throw err}fn(next)}next()},"undefined"!=typeof module&&module.exports?module.exports=async:"undefined"!=typeof define&&define.amd?define([],function(){return async}):root.async=async}()}).call(this,require("_process"))},{_process:65}],64:[function(require,module){!function(){var _convertDotToSubObject=function(keyParts,value){for(var subObject={},currentValue=subObject,i=0,n=keyParts.length-1;n>i;i++)currentValue=currentValue[keyParts[i]]={};return currentValue[keyParts[i]]=value,subObject},_queryParser=new function(){function _comparable(value){return value instanceof Date?value.getTime():value}function btop(value){return value?0:-1}var priority=this.priority=function(statement,data){for(var exprs=statement.exprs,priority=0,i=0,n=exprs.length;n>i;i++){var p,expr=exprs[i];if(!~(p=expr.e(expr.v,_comparable(data),data)))return-1;priority+=p}return priority},parse=this.parse=function(statement,key){statement||(statement={$eq:statement});var testers=[];if("[object Object]"===Object.prototype.toString.call(statement))for(var k in statement){var operator;if(_testers[k])operator=k;else{if("$"===k.substr(0,1))throw new Error("Unknown operator.");operator="$trav"}var value=statement[k],exprValue=value;if(TRAV_OP[operator]){if(~k.indexOf(".")){var keyParts=k.split(".");k=keyParts.shift(),exprValue=value=_convertDotToSubObject(keyParts,value)}if(value instanceof Array){exprValue=[];for(var i=value.length;i--;)exprValue.push(parse(value[i]))}else exprValue=parse(value,k)}testers.push(_getExpr(operator,k,exprValue))}else testers.push(_getExpr("$eq",k,statement));var stmt={exprs:testers,k:key,test:function(value){return!!~stmt.priority(value)},priority:function(value){return priority(stmt,value)}};return stmt},TRAV_OP=this.traversable={$and:!0,$or:!0,$nor:!0,$trav:!0,$not:!0},_testers=this.testers={$eq:function(a,b){return btop(a.test(b))},$ne:function(a,b){return btop(!a.test(b))},$lt:function(a,b){return btop(a>b)},$gt:function(a,b){return btop(b>a)},$lte:function(a,b){return btop(a>=b)},$gte:function(a,b){return btop(b>=a)},$exists:function(a,b){return btop(a===(null!=b))},$in:function(a,b){if(!(b instanceof Array))return btop(~a.indexOf(b));for(var i=b.length;i--;)if(~a.indexOf(b[i]))return i;return-1},$not:function(a,b){if(!a.test)throw new Error("$not test should include an expression, not a value. Use $ne instead.");return btop(!a.test(b))},$type:function(a,b,org){return org?btop(org instanceof a||org.constructor==a):-1},$nin:function(a,b){return~_testers.$in(a,b)?-1:0},$mod:function(a,b){return b%a[0]==a[1]?0:-1},$all:function(a,b){b||(b=[]);for(var i=a.length;i--;){var a1=a[i],indexInB=~b.indexOf(a1);if(!indexInB)return-1}return 0},$size:function(a,b){return b?btop(a==b.length):-1},$or:function(a,b){for(var i=a.length,n=i;i--;)if(~priority(a[i],b))return i;return btop(0==n)},$nor:function(a,b){for(var i=a.length;i--;)if(~priority(a[i],b))return-1;return 0},$and:function(a,b){for(var i=a.length;i--;)if(!~priority(a[i],b))return-1;return 0},$trav:function(a,b){if(b instanceof Array){for(var i=b.length;i--;){var subb=b[i];if(subb[a.k]&&~priority(a,subb[a.k]))return i}return-1}return priority(a,b?b[a.k]:void 0)},$regex:function(a,b){var aRE=new RegExp(a);return aRE.test(b)?0:-1}},_prepare={$eq:function(a){var fn;return a instanceof RegExp?a:(fn=a instanceof Function?a:function(b){return b instanceof Array?~b.indexOf(a):a==b},{test:fn})},$ne:function(a){return _prepare.$eq(a)}},_getExpr=function(type,key,value){var v=_comparable(value);return{k:key,v:_prepare[type]?_prepare[type](v):v,e:_testers[type]}}},getSelector=function(selector){if(!selector)return function(value){return value};if("function"==typeof selector)return selector;throw new Error("Unknown sift selector "+selector)},sifter=function(query,selector){var filter=_queryParser.parse(query),self=function(target){for(var testValue,value,priority,sifted=[],i=0,n=target.length;n>i;i++)value=target[i],testValue=selector(value),~(priority=filter.priority(testValue))&&sifted.push(value);return sifted};return self.test=filter.test,self.score=filter.priority,self.query=query,self},sift=function(query,target,rawSelector){"object"!=typeof target&&(rawSelector=target,target=void 0);var sft=sifter(query,getSelector(rawSelector));return target?sft(target):sft};sift.use=function(options){options.operators&&sift.useOperators(options.operators),"function"==typeof options&&options(sift)},sift.useOperators=function(operators){for(var key in operators)sift.useOperator(key,operators[key])},sift.useOperator=function(operator,optionsOrFn){var options={};options="object"==typeof optionsOrFn?optionsOrFn:{test:optionsOrFn};var key="$"+operator;_queryParser.testers[key]=options.test,(options.traversable||options.traverse)&&(_queryParser.traversable[key]=!0)},"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=sift:"undefined"!=typeof window&&(window.sift=sift)}()},{}],65:[function(require,module){function noop(){}var process=module.exports={};process.nextTick=function(){var canSetImmediate="undefined"!=typeof window&&window.setImmediate,canMutationObserver="undefined"!=typeof window&&window.MutationObserver,canPost="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(canSetImmediate)return function(f){return window.setImmediate(f)};var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div"),observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0,queueList.forEach(function(fn){fn()})});return observer.observe(hiddenDiv,{attributes:!0}),function(fn){queue.length||hiddenDiv.setAttribute("yes","no"),queue.push(fn)}}return canPost?(window.addEventListener("message",function(ev){var source=ev.source;if((source===window||null===source)&&"process-tick"===ev.data&&(ev.stopPropagation(),queue.length>0)){var fn=queue.shift();fn()}},!0),function(fn){queue.push(fn),window.postMessage("process-tick","*")}):function(fn){setTimeout(fn,0)}}(),process.title="browser",process.browser=!0,process.env={},process.argv=[],process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.binding=function(){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[2])(2)});