mongodb-pipelinejs
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -846,2 +846,16 @@ type CollectionNamespace = { | ||
redact: (ifExpr: Expression, thenExpr?: Expression | undefined, elseExpr?: Expression | undefined) => Redaction; | ||
$reduce: (input: ObjectExpression, initialValue: Expression, inExpr: Expression) => { | ||
$reduce: { | ||
input: ObjectExpression; | ||
initialValue: Expression; | ||
in: Expression; | ||
}; | ||
}; | ||
reduce: (input: ObjectExpression, initialValue: Expression, inExpr: Expression) => { | ||
$reduce: { | ||
input: ObjectExpression; | ||
initialValue: Expression; | ||
in: Expression; | ||
}; | ||
}; | ||
$replaceRoot: (newRoot: ObjectExpression) => { | ||
@@ -895,3 +909,3 @@ $replaceRoot: { | ||
}; | ||
$setField: (field: string, value: Expression, input: ObjectExpression) => { | ||
$setField: (input: ObjectExpression, field: string, value: Expression) => { | ||
$setField: { | ||
@@ -903,3 +917,3 @@ field: string; | ||
}; | ||
setField: (field: string, value: Expression, input: ObjectExpression) => { | ||
setField: (input: ObjectExpression, field: string, value: Expression) => { | ||
$setField: { | ||
@@ -906,0 +920,0 @@ field: string; |
@@ -756,2 +756,5 @@ "use strict"; | ||
const $rank = ne('$rank'); | ||
const $reduce = (input, initialValue, inExpr) => ({ | ||
$reduce: { input, initialValue, in: inExpr }, | ||
}); | ||
const $round = (value, places = 0) => ({ $round: [value, places] }); | ||
@@ -773,3 +776,3 @@ const $roundStandard = (value, places = 0) => { | ||
const $setEquals = pta('$setEquals'); | ||
const $setField = (field, value, input) => ({ | ||
const $setField = (input, field, value) => ({ | ||
$setField: { field, input, value }, | ||
@@ -1080,2 +1083,4 @@ }); | ||
redact: $redact, | ||
$reduce, | ||
reduce: $reduce, | ||
$replaceRoot, | ||
@@ -1082,0 +1087,0 @@ replaceRoot: $replaceRoot, |
@@ -1,1 +0,1 @@ | ||
"use strict";var __decorate=this&&this.__decorate||function(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)if(d=decorators[i])r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r;return c>3&&r&&Object.defineProperty(target,key,r),r};const nonenumerable_1=require("nonenumerable");const at=ns=>(...args)=>{if(args.length!==2){throw new TypeError(`${ns} expects two arguments. Received ${args.length} arguments.`)}const[a1,a2]=args;return{[ns]:[a1,a2]}};const pta=ns=>(...args)=>({[ns]:args});const ptafaa=ns=>(...args)=>({[ns]:args.length===1&&Array.isArray(args)?args[0]:args});const ne=ns=>()=>({[ns]:{}});const se=(ns,validate)=>expr=>{if(validate)validate(ns,expr);return{[ns]:expr}};const taf=ns=>(...args)=>{if(args.length>1){return{[ns]:args}}return{[ns]:args[0]}};const onlyOnce=(subject,methodName)=>{const subjectText=subject.constructor.name;if(subject[methodName]===undefined){throw new Error(`Method name "${methodName}" does not exist on ${subjectText}`)}if(typeof subject[methodName]!=="function"){throw new Error(`The ${methodName} method is not a function on ${subjectText}`)}Object.defineProperty(subject,methodName,{value:function(){throw new Error(`Redundant call to ${methodName}() on ${subjectText} not allowed.`)}})};const validateFieldExpression=(ns,v)=>{const type=typeof v;if(type==="object"){if(Object.getPrototypeOf(v)!==Object.getPrototypeOf({})){const name=v.constructor.name||"unknown";throw new Error(`Expression for ${ns} expected to be a plain object. Received ${name}`)}if(Object.keys(v).length<=0){throw new Error(`Expression for ${ns} cannot be an empty object`)}}else{throw new TypeError(`Expression for ${ns} expected to be an object. Received: ${type}`)}};const getCollectionName=v=>{if(typeof v==="string"){return v}if(v.s&&v.s.namespace&&typeof v.s.namespace.collection==="string"){return v.s.namespace.collection}throw new TypeError(`Invalid $lookup from parameter: ${v}`)};const safeNumberArgs=fn=>(...args)=>{const nums=args.length===1&&Array.isArray(args[0])?args[0]:args;return fn(...nums.map((arg=>{switch(typeof arg){case"boolean":return arg?1:0;case"number":return arg;case"string":if(arg.match(/^[^$]/))return 0;break;case"object":if(arg===null)return 0;break;case"undefined":return 0;default:}return $ifNull(arg,0)})))};const pipeline=(...args)=>args.filter((v=>v)).map((v=>typeof v==="function"?v(v):v));const $addFields=se("$addFields",validateFieldExpression);class Bucket{constructor(groupBy,boundaries,defaultId,output){this.$bucket={};this.groupBy(groupBy);if(boundaries){this.boundaries(...boundaries)}if(defaultId){this.default(defaultId)}if(output){this.output(output)}}groupBy(value){this.$bucket.groupBy=value;onlyOnce(this,"groupBy");return this}output(document){this.$bucket.output=document;onlyOnce(this,"output");return this}default(value){this.$bucket.default=value;onlyOnce(this,"default");return this}boundaries(...args){this.$bucket.boundaries=args;onlyOnce(this,"boundaries");return this}}const $bucket=(groupBy,boundaries,defaultId,output)=>new Bucket(groupBy,boundaries,defaultId,output);class BucketAuto{constructor(groupBy,buckets,granularity,output){this.$bucketAuto={};this.groupBy(groupBy);if(buckets){this.buckets(buckets)}if(granularity){this.granularity(granularity)}if(output){this.output(output)}}groupBy(value){this.$bucketAuto.groupBy=value;onlyOnce(this,"groupBy");return this}output(document){this.$bucketAuto.output=document;onlyOnce(this,"output");return this}buckets(value){this.$bucketAuto.buckets=value;onlyOnce(this,"buckets");return this}granularity(value){this.$bucketAuto.granularity=value;onlyOnce(this,"granularity");return this}}const $bucketAuto=(groupBy,buckets,granularity,output)=>new BucketAuto(groupBy,buckets,granularity,output);var ChangeStreamFullDocument;(function(ChangeStreamFullDocument){ChangeStreamFullDocument[ChangeStreamFullDocument["default"]=0]="default";ChangeStreamFullDocument[ChangeStreamFullDocument["required"]=1]="required";ChangeStreamFullDocument[ChangeStreamFullDocument["updateLookup"]=2]="updateLookup";ChangeStreamFullDocument[ChangeStreamFullDocument["whenAvailable"]=3]="whenAvailable"})(ChangeStreamFullDocument||(ChangeStreamFullDocument={}));var ChangeStreamFullDocumentBeforeChange;(function(ChangeStreamFullDocumentBeforeChange){ChangeStreamFullDocumentBeforeChange[ChangeStreamFullDocumentBeforeChange["off"]=0]="off";ChangeStreamFullDocumentBeforeChange[ChangeStreamFullDocumentBeforeChange["whenAvailable"]=1]="whenAvailable";ChangeStreamFullDocumentBeforeChange[ChangeStreamFullDocumentBeforeChange["required"]=2]="required"})(ChangeStreamFullDocumentBeforeChange||(ChangeStreamFullDocumentBeforeChange={}));class ChangeStream{constructor(opts={}){this.$changeStream={};if(opts.allChangesForCluster)this.allChangesForCluster(opts.allChangesForCluster);if(opts.fullDocument)this.fullDocument(opts.fullDocument);if(opts.fullDocumentBeforeChange)this.fullDocumentBeforeChange(opts.fullDocumentBeforeChange);if(opts.resumeAfter)this.resumeAfter(opts.resumeAfter);if(opts.showExpandedEvents)this.showExpandedEvents(opts.showExpandedEvents);if(opts.startAfter)this.startAfter(opts.startAfter);if(opts.startAtOperationTime)this.startAtOperationTime(opts.startAtOperationTime)}allChangesForCluster(value){this.$changeStream.allChangesForCluster=value;onlyOnce(this,"allChangesForCluster");return this}fullDocument(value){this.$changeStream.fullDocument=value;onlyOnce(this,"fullDocument");return this}fullDocumentBeforeChange(value){this.$changeStream.fullDocumentBeforeChange=value;onlyOnce(this,"fullDocument");return this}resumeAfter(value){this.$changeStream.resumeAfter=value;onlyOnce(this,"resumeAfter");return this}showExpandedEvents(value){this.$changeStream.showExpandedEvents=value;onlyOnce(this,"showExpandedEvents");return this}startAfter(value){this.$changeStream.startAfter=value;onlyOnce(this,"startAfter");return this}startAtOperationTime(value){this.$changeStream.startAtOperationTime=value;onlyOnce(this,"startAtOperationTime");return this}}const $changeStream=opts=>new ChangeStream(opts);const $count=(name="count")=>({$count:name});const $documents=(mixed,...args)=>{let documents;if(Array.isArray(mixed)){documents=mixed}else{documents=args.length?[mixed,...args]:[mixed]}return{$documents:documents}};const $facet=se("$facet");const $group=se("$group");const $limit=se("$limit");class Lookup{constructor(from,as,localField,foreignField){this.$lookup={};if(Array.isArray(from)){this.$lookup.pipeline=[$documents(...from)]}else{this.from(from)}this.as(as);if(localField)this.localField(localField);if(foreignField)this.foreignField(foreignField)}from(v){this.$lookup.from=getCollectionName(v);onlyOnce(this,"from");return this}as(v){this.$lookup.as=v;onlyOnce(this,"as");return this}localField(v){this.$lookup.localField=v;onlyOnce(this,"localField");return this}foreignField(v){this.$lookup.foreignField=v;onlyOnce(this,"foreignField");return this}let(v){this.$lookup.let=v;onlyOnce(this,"let");return this}pipeline(...args){let stages;if(args.length===1&&Array.isArray(args[0])){[stages]=args}else{stages=args}if(this.$lookup.pipeline===undefined){this.$lookup.pipeline=stages}else{this.$lookup.pipeline.push(...stages)}onlyOnce(this,"pipeline");return this}}const $lookup=(from,asName,localField,foreignField)=>new Lookup(from,asName,localField,foreignField);const $match=se("$match");var MergeActionWhenMatched;(function(MergeActionWhenMatched){MergeActionWhenMatched["Replace"]="replace";MergeActionWhenMatched["KeepExisting"]="keepExisting";MergeActionWhenMatched["Merge"]="merge";MergeActionWhenMatched["Fail"]="fail";MergeActionWhenMatched["Pipeline"]="pipeline"})(MergeActionWhenMatched||(MergeActionWhenMatched={}));var MergeActionWhenNotMatched;(function(MergeActionWhenNotMatched){MergeActionWhenNotMatched["Insert"]="insert";MergeActionWhenNotMatched["Discard"]="discard";MergeActionWhenNotMatched["Fail"]="fail"})(MergeActionWhenNotMatched||(MergeActionWhenNotMatched={}));class Merge{constructor(into,onExpr){this.$merge={into:getCollectionName(into)};if(onExpr)this.on(onExpr)}on(onExpression){this.$merge.on=onExpression;onlyOnce(this,"on");return this}let(varsExpression){this.$merge.let=varsExpression;onlyOnce(this,"let");return this}whenMatched(action){this.$merge.whenMatched=action;onlyOnce(this,"whenMatched");return this}whenNotMatched(action){this.$merge.whenNotMatched=action;onlyOnce(this,"whenNotMatched");return this}}const $merge=(into,onExpr)=>new Merge(into,onExpr);const $out=(collection,db)=>{if(db)return{$out:{db:db,coll:getCollectionName(collection)}};return{$out:collection}};const $project=se("$project");class Redaction{constructor(ifExpr,thenExpr,elseExpr){this.$redact=new Condition(ifExpr,thenExpr,elseExpr)}then(thenExpr){this.$redact.then(thenExpr);return this}else(elseExpr){this.$redact.else(elseExpr);return this}}const $redact=(ifExpr,thenExpr,elseExpr)=>new Redaction(ifExpr,thenExpr,elseExpr);const $replaceRoot=newRoot=>({$replaceRoot:{newRoot:newRoot}});const $replaceWith=replacementDocument=>({$replaceWith:replacementDocument});const $set=se("$set",validateFieldExpression);const $skip=se("$skip");const $sort=se("$sort");const $sortByCount=se("$sortByCount");class Unwind{get path(){return this.params.path}constructor(path,arg2){this.params={path:path};if(arg2!==undefined){this.preserveNullAndEmptyArrays(arg2)}Object.defineProperty(this,"$unwind",{get:()=>{if(this.params.preserveNullAndEmptyArrays!==undefined||this.params.includeArrayIndex!==undefined){return this.params}return this.path},enumerable:true})}preserveNullAndEmptyArrays(value){this.params.preserveNullAndEmptyArrays=value;onlyOnce(this,"preserveNullAndEmptyArrays");return this}includeArrayIndex(value){this.params.includeArrayIndex=value;onlyOnce(this,"includeArrayIndex");return this}}__decorate([nonenumerable_1.nonenumerable],Unwind.prototype,"params",void 0);const $unwind=(path,preserveNullAndEmptyArrays=undefined)=>new Unwind(path,preserveNullAndEmptyArrays);const $abs=se("$abs");const $acos=se("$acos");const $acosh=se("$acosh");const $add=ptafaa("$add");const $addSafe=safeNumberArgs($add);const $addToSet=se("$addToSet");const $all=(...expressions)=>({$all:[...expressions]});const $allElementsTrue=pta("$allElementsTrue");const $and=ptafaa("$and");const $anyElementTrue=pta("$anyElementTrue");const $arrayElemAt=at("$arrayElemAt");const $arrayElemFirst=inputArray=>$arrayElemAt(inputArray,0);const $arrayElemLast=inputArray=>$let({inputArray:inputArray}).in($let({length:$size("$$inputArray")}).in($arrayElemAt("$$inputArray",$cond("$$length",$decrement("$$length"),0))));const $arrayToObject=se("$arrayToObject");const $asin=se("$asin");const $asinh=se("$asinh");const $atan=se("$atan");const $atanh=se("$atanh");const $avg=se("$avg");const $binarySize=se("$binarySize");const $bitAnd=ptafaa("$bitAnd");const $bitNot=se("$bitNot");const $bitOr=ptafaa("$bitOr");const $bitXor=ptafaa("$bitXor");const $bsonSize=se("$bsonSize");const $ceil=se("$ceil");const $comment=se("$comment");const $cmp=at("$cmp");const $concat=ptafaa("$concat");const $concatSafe=(...args)=>{let parts=args;if(args.length&&Array.isArray(args[0]))parts=args[0];return{$concat:parts.map((expr=>$ensureString(expr)))}};const $concatArrays=pta("$concatArrays");const $concatArraysSafe=(...args)=>({$concatArrays:args.map((v=>$ensureArray(v)))});class Condition{constructor(ifExpr,thenExpr,elseExpr){this.$cond={if:ifExpr};if(thenExpr!==undefined)this.then(thenExpr);if(elseExpr!==undefined)this.else(elseExpr)}then(thenExpr){this.$cond.then=thenExpr;onlyOnce(this,"then");return this}else(elseExpr){this.$cond.else=elseExpr;onlyOnce(this,"else");return this}}const $cond=(ifExpr,thenExpr,elseExpr)=>new Condition(ifExpr,thenExpr,elseExpr);var ConversionType;(function(ConversionType){ConversionType[ConversionType["double"]=1]="double";ConversionType[ConversionType["string"]=2]="string";ConversionType[ConversionType["objectId"]=7]="objectId";ConversionType[ConversionType["bool"]=8]="bool";ConversionType[ConversionType["date"]=9]="date";ConversionType[ConversionType["int"]=16]="int";ConversionType[ConversionType["long"]=18]="long";ConversionType[ConversionType["decimal"]=19]="decimal"})(ConversionType||(ConversionType={}));class ConvertOperator{constructor(input,to,onErrorOrNull){this.$convert={};this.input(input);if(to)this.to(to);if(onErrorOrNull!==undefined)this.default(onErrorOrNull)}input(input){this.$convert.input=input;return this}to(type){this.$convert.to=type;return this}onError(expression){this.$convert.onError=expression;return this}onNull(expression){this.$convert.onNull=expression;return this}default(onErrorAndNull){this.onError(onErrorAndNull);this.onNull(onErrorAndNull);return this}}const $convert=(value,toType,defaultValue)=>new ConvertOperator(value,toType,defaultValue);const $cos=se("$cos");const $cosh=se("$cosh");const $covariancePop=at("$covariancePop");const $covarianceSamp=at("$covarianceSamp");const $decrement=value=>$subtract(value,1);const $degreesToRadians=se("$degreesToRadians");const $denseRank=ne("$denseRank");const $divide=at("$divide");const $divideSafe=(dividend,divisor,defaultValue="$$REMOVE")=>{switch(typeof divisor){case"number":if(typeof dividend==="number")return $divide(dividend,divisor);break;case"string":if(divisor.match(/^[^$]/))return 0;break;case"boolean":case"undefined":return 0;case"object":if(divisor===null)return 0;break;default:}switch(typeof dividend){case"undefined":case"boolean":return 0;case"string":if(dividend.match(/^[^$]/))return 0;break;case"object":if(dividend===null)return 0;break;default:}return $let({dividend:typeof dividend==="number"?dividend:$ifNull(dividend,0),divisor:typeof divisor==="number"?divisor:$ifNull(divisor,0)}).in($cond($eq("$$divisor",0),defaultValue,$divide("$$dividend","$$divisor")))};const $documentNumber=ne("$documentNumber");const $each=expression=>({$each:expression});const $elemMatch=query=>({$elemMatch:query});const $ensureArray=value=>{if(Array.isArray(value))return value;switch(typeof value){case"string":if(value.match(/^[^$]/))return[];break;case"object":if(value===null)return[];break;case"number":case"undefined":case"boolean":return[];default:}return $let({input:value}).in($if($isArray("$$input")).then("$$input").else([]))};const $ensureNumber=(value,defaultValue=0)=>{switch(typeof value){case"number":return value;case"boolean":return value?1:0;case"string":if(value.match(/^[^$]/))return $toDouble(value);break;case"object":if(value===null)return defaultValue;break;case"undefined":return defaultValue;default:}return $let({input:value}).in($if($isNumber("$$input")).then("$$input").else($convert("$$input",1,defaultValue)))};const $ensureString=(value,defaultValue="")=>{switch(typeof value){case"string":if(value[0]!=="$")return value;break;case"number":return`${value}`;case"boolean":return value?"true":"false";case"object":if(value===null)return defaultValue;break;case"undefined":return defaultValue;default:}return $convert(value,ConversionType.string,defaultValue)};const $eq=at("$eq");const $exists=se("$exists");const $exp=se("$exp");const $expr=expression=>({$expr:expression});class FilterOperator{constructor(inputExpr,asExpr,cond,limit){this.$filter={};this.input(inputExpr);if(asExpr)this.as(asExpr);if(cond)this.cond(cond);if(limit!==undefined)this.limit(limit)}input(value){this.$filter.input=value;return this}as(name){this.$filter.as=name;return this}cond(expression){this.$filter.cond=expression;return this}limit(value){this.$filter.limit=value;return this}}const $filter=(inputExpr,asName,condExpr,limit)=>new FilterOperator(inputExpr,asName,condExpr,limit);const $find=(...args)=>$arrayElemAt($filter(...args),0);const $first=se("$first");const $floor=se("$floor");const $getField=(field,input=undefined)=>({$getField:input?{field:field,input:input}:{field:field}});const $gt=taf("$gt");const $gte=taf("$gte");const $if=ifExpr=>new Condition(ifExpr);const $ifNull=at("$ifNull");const $increment=value=>$add(value,1);const $in=taf("$in");const $inSafe=(...args)=>{if(args.length===2){const[val,arr]=args;return $in(val,$ifNull(arr,[]))}return $in(...args)};const $isArray=se("$isArray");const $isNumber=se("$isNumber");const $last=se("$last");class LetVarsIn{constructor(varsExpr,inExpr){this.$let={};if(varsExpr)this.vars(varsExpr);if(inExpr)this.in(inExpr)}vars(varsExpr){this.$let.vars=varsExpr;onlyOnce(this,"vars");return this}in(inExpr){this.$let.in=inExpr;onlyOnce(this,"in");return this}}const $let=(varsExpr,inExpr)=>new LetVarsIn(varsExpr,inExpr);const $linearFill=se("$linearFill");const $literal=se("$literal");const $locf=se("$locf");const $log=at("$log");const $log10=se("$log10");const $lt=taf("$lt");const $lte=taf("$lte");class MapOperator{constructor(inputExpr,asName,inExpr){this.$map={};this.input(inputExpr);if(asName)this.as(asName);if(inExpr)this.in(inExpr)}input(inputExpr){this.$map.input=inputExpr;onlyOnce(this,"input");return this}as(name){this.$map.as=name;onlyOnce(this,"as");return this}in(expression){this.$map.in=expression;onlyOnce(this,"in");return this}}const $map=(inputExpr,asName,inExpr)=>new MapOperator(inputExpr,asName,inExpr);const $max=taf("$max");const $mergeObjects=ptafaa("$mergeObjects");var MetaDataKeyword;(function(MetaDataKeyword){MetaDataKeyword[MetaDataKeyword["textScore"]=0]="textScore";MetaDataKeyword[MetaDataKeyword["indexKey"]=1]="indexKey"})(MetaDataKeyword||(MetaDataKeyword={}));const $meta=se("$meta");const $min=taf("$min");const $mod=at("$mod");const $multiply=ptafaa("$multiply");const $multiplySafe=safeNumberArgs($multiply);const $ne=at("$ne");const $nin=taf("$nin");const $ninSafe=(...args)=>{if(args.length===2){const[val,arr]=args;return $in(val,$ifNull(arr,[]))}return $in(...args)};const $nor=se("$nor");const $not=se("$not");const $objectToArray=se("$objectToArray");const $or=ptafaa("$or");const $pow=at("$pow");const $push=se("$push");const $radiansToDegrees=se("$radiansToDegrees");const $rand=ne("$rand");const $rank=ne("$rank");const $round=(value,places=0)=>({$round:[value,places]});const $roundStandard=(value,places=0)=>{const expr=$let({input:value});if(places){const multiplier=Math.pow(10,places||0);return expr.in($let({val:$add($multiply("$$input",multiplier),$if($gte("$$input",0)).then(.5).else(-.5))}).in($divide($subtract("$$val",$mod("$$val",1)),multiplier)))}return expr.in($let({val:$add("$$input",$if($gte("$$input",0)).then(.5).else(-.5))}).in($subtract("$$val",$mod("$$val",1))))};const $sampleRate=se("$sampleRate");const $setDifference=at("$setDifference");const $setEquals=pta("$setEquals");const $setField=(field,value,input)=>({$setField:{field:field,input:input,value:value}});const $setIntersection=pta("$setIntersection");const $setIsSubset=at("$setIsSubset");const $setUnion=pta("$setUnion");const $sin=se("$sin");const $sinh=se("$sinh");const $size=se("$size");const $slice=pta("$slice");const $split=at("$split");const $sqrt=se("$sqrt");const $strcasecmp=at("$strcasecmp");const $strLenBytes=se("$strLenBytes");const $strLenCP=se("$strLenCP");const $subtract=at("$subtract");const $subtractSafe=safeNumberArgs($subtract);const $substr=pta("$substr");const $substrBytes=pta("$substrBytes");const $substrCP=pta("$substrCP");const $sum=se("$sum");const branch=(caseExpr,thenExpr)=>({case:caseExpr,then:thenExpr});class Switch{constructor(arg1,arg2){this.$switch={};const args=[arg1,arg2].filter((v=>v!==undefined));if(args.length>=2){if(args.filter((v=>Array.isArray(v))).length>1){throw new TypeError(`Multiple switch branches input. Only one is supported.`)}if(args.filter((v=>!Array.isArray(v))).length>1){throw new TypeError(`Multiple switch defaults input. Only one is supported.`)}}while(args.length){const arg=args.shift();if(Array.isArray(arg)){this.branches(...arg)}else{this.default(arg)}}}branches(...args){this.$switch.branches=args;return this}branch(caseExpr,thenExpr){if(this.$switch.branches===undefined){this.$switch.branches=[]}this.$switch.branches.push({case:caseExpr,then:thenExpr});return this}default(defaultReturn){this.$switch.default=defaultReturn;onlyOnce(this,"default");return this}}const $switch=(arg1,arg2)=>new Switch(arg1,arg2);const $tan=se("$tan");const $tanh=se("$tanh");const $toBool=se("$toBool");const $toDate=se("$toDate");const $toDecimal=se("$toDecimal");const $toDouble=se("$toDouble");const $toInt=se("$toInt");const $toLong=se("$toLong");const $toObjectId=se("$toObjectId");const $toString=se("$toString");const $toUpper=se("$toUpper");const $toLower=se("$toLower");const $trunc=at("$trunc");const $tsIncrement=se("$tsIncrement");const $tsSecond=se("$tsSecond");const $type=se("$type");const $unsetField=(field,input)=>({$unsetField:{field:field,input:input}});const $year=se("$year");module.exports={$abs:$abs,abs:$abs,$acos:$acos,acos:$acos,$acosh:$acosh,acosh:$acosh,$add:$add,add:$add,$addSafe:$addSafe,addSafe:$addSafe,$addFields:$addFields,addFields:$addFields,$addToSet:$addToSet,addToSet:$addToSet,$all:$all,all:$all,$allElementsTrue:$allElementsTrue,allElementsTrue:$allElementsTrue,$and:$and,and:$and,$anyElementTrue:$anyElementTrue,anyElementTrue:$anyElementTrue,$arrayElemAt:$arrayElemAt,arrayElemAt:$arrayElemAt,$arrayElemFirst:$arrayElemFirst,arrayElemFirst:$arrayElemFirst,$arrayElemLast:$arrayElemLast,arrayElemLast:$arrayElemLast,$arrayToObject:$arrayToObject,arrayToObject:$arrayToObject,$asin:$asin,asin:$asin,$asinh:$asinh,asinh:$asinh,$atan:$atan,atan:$atan,$atanh:$atanh,atanh:$atanh,$avg:$avg,avg:$avg,$bucket:$bucket,bucket:$bucket,$bucketAuto:$bucketAuto,bucketAuto:$bucketAuto,$binarySize:$binarySize,binarySize:$binarySize,branch:branch,$bitAnd:$bitAnd,bitAnd:$bitAnd,$bitNot:$bitNot,bitNot:$bitNot,$bitOr:$bitOr,bitOr:$bitOr,$bitXor:$bitXor,bitXor:$bitXor,$bsonSize:$bsonSize,bsonSize:$bsonSize,case:branch,$ceil:$ceil,ceil:$ceil,$changeStream:$changeStream,changeStream:$changeStream,$cmp:$cmp,cmp:$cmp,$comment:$comment,comment:$comment,$concat:$concat,concat:$concat,$concatSafe:$concatSafe,concatSafe:$concatSafe,$concatArrays:$concatArrays,concatArrays:$concatArrays,$concatArraysSafe:$concatArraysSafe,concatArraysSafe:$concatArraysSafe,$cond:$cond,cond:$cond,$convert:$convert,convert:$convert,$cos:$cos,cos:$cos,$cosh:$cosh,cosh:$cosh,$count:$count,count:$count,$covariancePop:$covariancePop,covariancePop:$covariancePop,$covarianceSamp:$covarianceSamp,covarianceSamp:$covarianceSamp,$decrement:$decrement,decrement:$decrement,$degreesToRadians:$degreesToRadians,degreesToRadians:$degreesToRadians,$denseRank:$denseRank,denseRank:$denseRank,$divide:$divide,divide:$divide,$divideSafe:$divideSafe,divideSafe:$divideSafe,$documentNumber:$documentNumber,documentNumber:$documentNumber,$documents:$documents,documents:$documents,$ensureArray:$ensureArray,$each:$each,each:$each,$elemMatch:$elemMatch,elemMatch:$elemMatch,ensureArray:$ensureArray,$ensureNumber:$ensureNumber,ensureNumber:$ensureNumber,$ensureString:$ensureString,ensureString:$ensureString,$eq:$eq,eq:$eq,$exists:$exists,exists:$exists,$exp:$exp,exp:$exp,$expr:$expr,expr:$expr,$facet:$facet,facet:$facet,$filter:$filter,filter:$filter,$find:$find,find:$find,$first:$first,first:$first,$floor:$floor,floor:$floor,$group:$group,group:$group,$getField:$getField,getField:$getField,$gt:$gt,gt:$gt,$gte:$gte,gte:$gte,$if:$if,if:$if,$ifNull:$ifNull,ifNull:$ifNull,$in:$in,in:$in,$increment:$increment,increment:$increment,$inSafe:$inSafe,inSafe:$inSafe,$isArray:$isArray,isArray:$isArray,$isNumber:$isNumber,isNumber:$isNumber,$last:$last,last:$last,$let:$let,let:$let,$limit:$limit,limit:$limit,$linearFill:$linearFill,linearFill:$linearFill,$literal:$literal,literal:$literal,$locf:$locf,locf:$locf,$log:$log,log:$log,$log10:$log10,log10:$log10,$lookup:$lookup,lookup:$lookup,$lt:$lt,lt:$lt,$lte:$lte,lte:$lte,$map:$map,map:$map,$match:$match,match:$match,$max:$max,max:$max,$meta:$meta,meta:$meta,$min:$min,min:$min,$merge:$merge,merge:$merge,$mergeObjects:$mergeObjects,mergeObjects:$mergeObjects,$mod:$mod,mod:$mod,$multiply:$multiply,multiply:$multiply,$multiplySafe:$multiplySafe,multiplySafe:$multiplySafe,$ne:$ne,ne:$ne,$nin:$nin,nin:$nin,$nor:$nor,nor:$nor,$not:$not,not:$not,$or:$or,or:$or,$out:$out,out:$out,pipeline:pipeline,$pow:$pow,pow:$pow,$objectToArray:$objectToArray,objectToArray:$objectToArray,$radiansToDegrees:$radiansToDegrees,radiansToDegrees:$radiansToDegrees,$project:$project,project:$project,$push:$push,push:$push,$rand:$rand,rand:$rand,$rank:$rank,rank:$rank,$redact:$redact,redact:$redact,$replaceRoot:$replaceRoot,replaceRoot:$replaceRoot,$replaceWith:$replaceWith,replaceWith:$replaceWith,$round:$round,round:$round,$roundStandard:$roundStandard,roundStandard:$roundStandard,$sampleRate:$sampleRate,sampleRate:$sampleRate,$set:$set,set:$set,$setDifference:$setDifference,setDifference:$setDifference,$setEquals:$setEquals,setEquals:$setEquals,$setField:$setField,setField:$setField,$setIntersection:$setIntersection,setIntersection:$setIntersection,$setIsSubset:$setIsSubset,setIsSubset:$setIsSubset,$setUnion:$setUnion,setUnion:$setUnion,$sort:$sort,sort:$sort,$sortByCount:$sortByCount,sortByCount:$sortByCount,$split:$split,split:$split,$strcasecmp:$strcasecmp,strcasecmp:$strcasecmp,$substr:$substr,substr:$substr,$substrBytes:$substrBytes,substrBytes:$substrBytes,$substrCP:$substrCP,substrCP:$substrCP,$subtract:$subtract,subtract:$subtract,$subtractSafe:$subtractSafe,subtractSafe:$subtractSafe,$size:$size,size:$size,$slice:$slice,slice:$slice,$sin:$sin,sin:$sin,$sinh:$sinh,sinh:$sinh,$skip:$skip,skip:$skip,$sqrt:$sqrt,sqrt:$sqrt,$strLenBytes:$strLenBytes,strLenBytes:$strLenBytes,$strLenCP:$strLenCP,strLenCP:$strLenCP,$sum:$sum,sum:$sum,$switch:$switch,switch:$switch,$tan:$tan,tan:$tan,$tanh:$tanh,tanh:$tanh,$toBool:$toBool,toBool:$toBool,$toDate:$toDate,toDate:$toDate,$toDecimal:$toDecimal,toDecimal:$toDecimal,$toDouble:$toDouble,toDouble:$toDouble,$toInt:$toInt,toInt:$toInt,$toLong:$toLong,toLong:$toLong,$toObjectId:$toObjectId,toObjectId:$toObjectId,$toString:$toString,toString:$toString,$toUpper:$toUpper,toUpper:$toUpper,$toLower:$toLower,toLower:$toLower,$tsIncrement:$tsIncrement,tsIncrement:$tsIncrement,$tsSecond:$tsSecond,tsSecond:$tsSecond,$trunc:$trunc,trunc:$trunc,$type:$type,type:$type,$unsetField:$unsetField,unsetField:$unsetField,$unwind:$unwind,unwind:$unwind,$year:$year,year:$year,ChangeStreamFullDocument:ChangeStreamFullDocument,MergeActionWhenMatched:MergeActionWhenMatched,MergeActionWhenNotMatched:MergeActionWhenNotMatched}; | ||
"use strict";var __decorate=this&&this.__decorate||function(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)if(d=decorators[i])r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r;return c>3&&r&&Object.defineProperty(target,key,r),r};const nonenumerable_1=require("nonenumerable");const at=ns=>(...args)=>{if(args.length!==2){throw new TypeError(`${ns} expects two arguments. Received ${args.length} arguments.`)}const[a1,a2]=args;return{[ns]:[a1,a2]}};const pta=ns=>(...args)=>({[ns]:args});const ptafaa=ns=>(...args)=>({[ns]:args.length===1&&Array.isArray(args)?args[0]:args});const ne=ns=>()=>({[ns]:{}});const se=(ns,validate)=>expr=>{if(validate)validate(ns,expr);return{[ns]:expr}};const taf=ns=>(...args)=>{if(args.length>1){return{[ns]:args}}return{[ns]:args[0]}};const onlyOnce=(subject,methodName)=>{const subjectText=subject.constructor.name;if(subject[methodName]===undefined){throw new Error(`Method name "${methodName}" does not exist on ${subjectText}`)}if(typeof subject[methodName]!=="function"){throw new Error(`The ${methodName} method is not a function on ${subjectText}`)}Object.defineProperty(subject,methodName,{value:function(){throw new Error(`Redundant call to ${methodName}() on ${subjectText} not allowed.`)}})};const validateFieldExpression=(ns,v)=>{const type=typeof v;if(type==="object"){if(Object.getPrototypeOf(v)!==Object.getPrototypeOf({})){const name=v.constructor.name||"unknown";throw new Error(`Expression for ${ns} expected to be a plain object. Received ${name}`)}if(Object.keys(v).length<=0){throw new Error(`Expression for ${ns} cannot be an empty object`)}}else{throw new TypeError(`Expression for ${ns} expected to be an object. Received: ${type}`)}};const getCollectionName=v=>{if(typeof v==="string"){return v}if(v.s&&v.s.namespace&&typeof v.s.namespace.collection==="string"){return v.s.namespace.collection}throw new TypeError(`Invalid $lookup from parameter: ${v}`)};const safeNumberArgs=fn=>(...args)=>{const nums=args.length===1&&Array.isArray(args[0])?args[0]:args;return fn(...nums.map((arg=>{switch(typeof arg){case"boolean":return arg?1:0;case"number":return arg;case"string":if(arg.match(/^[^$]/))return 0;break;case"object":if(arg===null)return 0;break;case"undefined":return 0;default:}return $ifNull(arg,0)})))};const pipeline=(...args)=>args.filter((v=>v)).map((v=>typeof v==="function"?v(v):v));const $addFields=se("$addFields",validateFieldExpression);class Bucket{constructor(groupBy,boundaries,defaultId,output){this.$bucket={};this.groupBy(groupBy);if(boundaries){this.boundaries(...boundaries)}if(defaultId){this.default(defaultId)}if(output){this.output(output)}}groupBy(value){this.$bucket.groupBy=value;onlyOnce(this,"groupBy");return this}output(document){this.$bucket.output=document;onlyOnce(this,"output");return this}default(value){this.$bucket.default=value;onlyOnce(this,"default");return this}boundaries(...args){this.$bucket.boundaries=args;onlyOnce(this,"boundaries");return this}}const $bucket=(groupBy,boundaries,defaultId,output)=>new Bucket(groupBy,boundaries,defaultId,output);class BucketAuto{constructor(groupBy,buckets,granularity,output){this.$bucketAuto={};this.groupBy(groupBy);if(buckets){this.buckets(buckets)}if(granularity){this.granularity(granularity)}if(output){this.output(output)}}groupBy(value){this.$bucketAuto.groupBy=value;onlyOnce(this,"groupBy");return this}output(document){this.$bucketAuto.output=document;onlyOnce(this,"output");return this}buckets(value){this.$bucketAuto.buckets=value;onlyOnce(this,"buckets");return this}granularity(value){this.$bucketAuto.granularity=value;onlyOnce(this,"granularity");return this}}const $bucketAuto=(groupBy,buckets,granularity,output)=>new BucketAuto(groupBy,buckets,granularity,output);var ChangeStreamFullDocument;(function(ChangeStreamFullDocument){ChangeStreamFullDocument[ChangeStreamFullDocument["default"]=0]="default";ChangeStreamFullDocument[ChangeStreamFullDocument["required"]=1]="required";ChangeStreamFullDocument[ChangeStreamFullDocument["updateLookup"]=2]="updateLookup";ChangeStreamFullDocument[ChangeStreamFullDocument["whenAvailable"]=3]="whenAvailable"})(ChangeStreamFullDocument||(ChangeStreamFullDocument={}));var ChangeStreamFullDocumentBeforeChange;(function(ChangeStreamFullDocumentBeforeChange){ChangeStreamFullDocumentBeforeChange[ChangeStreamFullDocumentBeforeChange["off"]=0]="off";ChangeStreamFullDocumentBeforeChange[ChangeStreamFullDocumentBeforeChange["whenAvailable"]=1]="whenAvailable";ChangeStreamFullDocumentBeforeChange[ChangeStreamFullDocumentBeforeChange["required"]=2]="required"})(ChangeStreamFullDocumentBeforeChange||(ChangeStreamFullDocumentBeforeChange={}));class ChangeStream{constructor(opts={}){this.$changeStream={};if(opts.allChangesForCluster)this.allChangesForCluster(opts.allChangesForCluster);if(opts.fullDocument)this.fullDocument(opts.fullDocument);if(opts.fullDocumentBeforeChange)this.fullDocumentBeforeChange(opts.fullDocumentBeforeChange);if(opts.resumeAfter)this.resumeAfter(opts.resumeAfter);if(opts.showExpandedEvents)this.showExpandedEvents(opts.showExpandedEvents);if(opts.startAfter)this.startAfter(opts.startAfter);if(opts.startAtOperationTime)this.startAtOperationTime(opts.startAtOperationTime)}allChangesForCluster(value){this.$changeStream.allChangesForCluster=value;onlyOnce(this,"allChangesForCluster");return this}fullDocument(value){this.$changeStream.fullDocument=value;onlyOnce(this,"fullDocument");return this}fullDocumentBeforeChange(value){this.$changeStream.fullDocumentBeforeChange=value;onlyOnce(this,"fullDocument");return this}resumeAfter(value){this.$changeStream.resumeAfter=value;onlyOnce(this,"resumeAfter");return this}showExpandedEvents(value){this.$changeStream.showExpandedEvents=value;onlyOnce(this,"showExpandedEvents");return this}startAfter(value){this.$changeStream.startAfter=value;onlyOnce(this,"startAfter");return this}startAtOperationTime(value){this.$changeStream.startAtOperationTime=value;onlyOnce(this,"startAtOperationTime");return this}}const $changeStream=opts=>new ChangeStream(opts);const $count=(name="count")=>({$count:name});const $documents=(mixed,...args)=>{let documents;if(Array.isArray(mixed)){documents=mixed}else{documents=args.length?[mixed,...args]:[mixed]}return{$documents:documents}};const $facet=se("$facet");const $group=se("$group");const $limit=se("$limit");class Lookup{constructor(from,as,localField,foreignField){this.$lookup={};if(Array.isArray(from)){this.$lookup.pipeline=[$documents(...from)]}else{this.from(from)}this.as(as);if(localField)this.localField(localField);if(foreignField)this.foreignField(foreignField)}from(v){this.$lookup.from=getCollectionName(v);onlyOnce(this,"from");return this}as(v){this.$lookup.as=v;onlyOnce(this,"as");return this}localField(v){this.$lookup.localField=v;onlyOnce(this,"localField");return this}foreignField(v){this.$lookup.foreignField=v;onlyOnce(this,"foreignField");return this}let(v){this.$lookup.let=v;onlyOnce(this,"let");return this}pipeline(...args){let stages;if(args.length===1&&Array.isArray(args[0])){[stages]=args}else{stages=args}if(this.$lookup.pipeline===undefined){this.$lookup.pipeline=stages}else{this.$lookup.pipeline.push(...stages)}onlyOnce(this,"pipeline");return this}}const $lookup=(from,asName,localField,foreignField)=>new Lookup(from,asName,localField,foreignField);const $match=se("$match");var MergeActionWhenMatched;(function(MergeActionWhenMatched){MergeActionWhenMatched["Replace"]="replace";MergeActionWhenMatched["KeepExisting"]="keepExisting";MergeActionWhenMatched["Merge"]="merge";MergeActionWhenMatched["Fail"]="fail";MergeActionWhenMatched["Pipeline"]="pipeline"})(MergeActionWhenMatched||(MergeActionWhenMatched={}));var MergeActionWhenNotMatched;(function(MergeActionWhenNotMatched){MergeActionWhenNotMatched["Insert"]="insert";MergeActionWhenNotMatched["Discard"]="discard";MergeActionWhenNotMatched["Fail"]="fail"})(MergeActionWhenNotMatched||(MergeActionWhenNotMatched={}));class Merge{constructor(into,onExpr){this.$merge={into:getCollectionName(into)};if(onExpr)this.on(onExpr)}on(onExpression){this.$merge.on=onExpression;onlyOnce(this,"on");return this}let(varsExpression){this.$merge.let=varsExpression;onlyOnce(this,"let");return this}whenMatched(action){this.$merge.whenMatched=action;onlyOnce(this,"whenMatched");return this}whenNotMatched(action){this.$merge.whenNotMatched=action;onlyOnce(this,"whenNotMatched");return this}}const $merge=(into,onExpr)=>new Merge(into,onExpr);const $out=(collection,db)=>{if(db)return{$out:{db:db,coll:getCollectionName(collection)}};return{$out:collection}};const $project=se("$project");class Redaction{constructor(ifExpr,thenExpr,elseExpr){this.$redact=new Condition(ifExpr,thenExpr,elseExpr)}then(thenExpr){this.$redact.then(thenExpr);return this}else(elseExpr){this.$redact.else(elseExpr);return this}}const $redact=(ifExpr,thenExpr,elseExpr)=>new Redaction(ifExpr,thenExpr,elseExpr);const $replaceRoot=newRoot=>({$replaceRoot:{newRoot:newRoot}});const $replaceWith=replacementDocument=>({$replaceWith:replacementDocument});const $set=se("$set",validateFieldExpression);const $skip=se("$skip");const $sort=se("$sort");const $sortByCount=se("$sortByCount");class Unwind{get path(){return this.params.path}constructor(path,arg2){this.params={path:path};if(arg2!==undefined){this.preserveNullAndEmptyArrays(arg2)}Object.defineProperty(this,"$unwind",{get:()=>{if(this.params.preserveNullAndEmptyArrays!==undefined||this.params.includeArrayIndex!==undefined){return this.params}return this.path},enumerable:true})}preserveNullAndEmptyArrays(value){this.params.preserveNullAndEmptyArrays=value;onlyOnce(this,"preserveNullAndEmptyArrays");return this}includeArrayIndex(value){this.params.includeArrayIndex=value;onlyOnce(this,"includeArrayIndex");return this}}__decorate([nonenumerable_1.nonenumerable],Unwind.prototype,"params",void 0);const $unwind=(path,preserveNullAndEmptyArrays=undefined)=>new Unwind(path,preserveNullAndEmptyArrays);const $abs=se("$abs");const $acos=se("$acos");const $acosh=se("$acosh");const $add=ptafaa("$add");const $addSafe=safeNumberArgs($add);const $addToSet=se("$addToSet");const $all=(...expressions)=>({$all:[...expressions]});const $allElementsTrue=pta("$allElementsTrue");const $and=ptafaa("$and");const $anyElementTrue=pta("$anyElementTrue");const $arrayElemAt=at("$arrayElemAt");const $arrayElemFirst=inputArray=>$arrayElemAt(inputArray,0);const $arrayElemLast=inputArray=>$let({inputArray:inputArray}).in($let({length:$size("$$inputArray")}).in($arrayElemAt("$$inputArray",$cond("$$length",$decrement("$$length"),0))));const $arrayToObject=se("$arrayToObject");const $asin=se("$asin");const $asinh=se("$asinh");const $atan=se("$atan");const $atanh=se("$atanh");const $avg=se("$avg");const $binarySize=se("$binarySize");const $bitAnd=ptafaa("$bitAnd");const $bitNot=se("$bitNot");const $bitOr=ptafaa("$bitOr");const $bitXor=ptafaa("$bitXor");const $bsonSize=se("$bsonSize");const $ceil=se("$ceil");const $comment=se("$comment");const $cmp=at("$cmp");const $concat=ptafaa("$concat");const $concatSafe=(...args)=>{let parts=args;if(args.length&&Array.isArray(args[0]))parts=args[0];return{$concat:parts.map((expr=>$ensureString(expr)))}};const $concatArrays=pta("$concatArrays");const $concatArraysSafe=(...args)=>({$concatArrays:args.map((v=>$ensureArray(v)))});class Condition{constructor(ifExpr,thenExpr,elseExpr){this.$cond={if:ifExpr};if(thenExpr!==undefined)this.then(thenExpr);if(elseExpr!==undefined)this.else(elseExpr)}then(thenExpr){this.$cond.then=thenExpr;onlyOnce(this,"then");return this}else(elseExpr){this.$cond.else=elseExpr;onlyOnce(this,"else");return this}}const $cond=(ifExpr,thenExpr,elseExpr)=>new Condition(ifExpr,thenExpr,elseExpr);var ConversionType;(function(ConversionType){ConversionType[ConversionType["double"]=1]="double";ConversionType[ConversionType["string"]=2]="string";ConversionType[ConversionType["objectId"]=7]="objectId";ConversionType[ConversionType["bool"]=8]="bool";ConversionType[ConversionType["date"]=9]="date";ConversionType[ConversionType["int"]=16]="int";ConversionType[ConversionType["long"]=18]="long";ConversionType[ConversionType["decimal"]=19]="decimal"})(ConversionType||(ConversionType={}));class ConvertOperator{constructor(input,to,onErrorOrNull){this.$convert={};this.input(input);if(to)this.to(to);if(onErrorOrNull!==undefined)this.default(onErrorOrNull)}input(input){this.$convert.input=input;return this}to(type){this.$convert.to=type;return this}onError(expression){this.$convert.onError=expression;return this}onNull(expression){this.$convert.onNull=expression;return this}default(onErrorAndNull){this.onError(onErrorAndNull);this.onNull(onErrorAndNull);return this}}const $convert=(value,toType,defaultValue)=>new ConvertOperator(value,toType,defaultValue);const $cos=se("$cos");const $cosh=se("$cosh");const $covariancePop=at("$covariancePop");const $covarianceSamp=at("$covarianceSamp");const $decrement=value=>$subtract(value,1);const $degreesToRadians=se("$degreesToRadians");const $denseRank=ne("$denseRank");const $divide=at("$divide");const $divideSafe=(dividend,divisor,defaultValue="$$REMOVE")=>{switch(typeof divisor){case"number":if(typeof dividend==="number")return $divide(dividend,divisor);break;case"string":if(divisor.match(/^[^$]/))return 0;break;case"boolean":case"undefined":return 0;case"object":if(divisor===null)return 0;break;default:}switch(typeof dividend){case"undefined":case"boolean":return 0;case"string":if(dividend.match(/^[^$]/))return 0;break;case"object":if(dividend===null)return 0;break;default:}return $let({dividend:typeof dividend==="number"?dividend:$ifNull(dividend,0),divisor:typeof divisor==="number"?divisor:$ifNull(divisor,0)}).in($cond($eq("$$divisor",0),defaultValue,$divide("$$dividend","$$divisor")))};const $documentNumber=ne("$documentNumber");const $each=expression=>({$each:expression});const $elemMatch=query=>({$elemMatch:query});const $ensureArray=value=>{if(Array.isArray(value))return value;switch(typeof value){case"string":if(value.match(/^[^$]/))return[];break;case"object":if(value===null)return[];break;case"number":case"undefined":case"boolean":return[];default:}return $let({input:value}).in($if($isArray("$$input")).then("$$input").else([]))};const $ensureNumber=(value,defaultValue=0)=>{switch(typeof value){case"number":return value;case"boolean":return value?1:0;case"string":if(value.match(/^[^$]/))return $toDouble(value);break;case"object":if(value===null)return defaultValue;break;case"undefined":return defaultValue;default:}return $let({input:value}).in($if($isNumber("$$input")).then("$$input").else($convert("$$input",1,defaultValue)))};const $ensureString=(value,defaultValue="")=>{switch(typeof value){case"string":if(value[0]!=="$")return value;break;case"number":return`${value}`;case"boolean":return value?"true":"false";case"object":if(value===null)return defaultValue;break;case"undefined":return defaultValue;default:}return $convert(value,ConversionType.string,defaultValue)};const $eq=at("$eq");const $exists=se("$exists");const $exp=se("$exp");const $expr=expression=>({$expr:expression});class FilterOperator{constructor(inputExpr,asExpr,cond,limit){this.$filter={};this.input(inputExpr);if(asExpr)this.as(asExpr);if(cond)this.cond(cond);if(limit!==undefined)this.limit(limit)}input(value){this.$filter.input=value;return this}as(name){this.$filter.as=name;return this}cond(expression){this.$filter.cond=expression;return this}limit(value){this.$filter.limit=value;return this}}const $filter=(inputExpr,asName,condExpr,limit)=>new FilterOperator(inputExpr,asName,condExpr,limit);const $find=(...args)=>$arrayElemAt($filter(...args),0);const $first=se("$first");const $floor=se("$floor");const $getField=(field,input=undefined)=>({$getField:input?{field:field,input:input}:{field:field}});const $gt=taf("$gt");const $gte=taf("$gte");const $if=ifExpr=>new Condition(ifExpr);const $ifNull=at("$ifNull");const $increment=value=>$add(value,1);const $in=taf("$in");const $inSafe=(...args)=>{if(args.length===2){const[val,arr]=args;return $in(val,$ifNull(arr,[]))}return $in(...args)};const $isArray=se("$isArray");const $isNumber=se("$isNumber");const $last=se("$last");class LetVarsIn{constructor(varsExpr,inExpr){this.$let={};if(varsExpr)this.vars(varsExpr);if(inExpr)this.in(inExpr)}vars(varsExpr){this.$let.vars=varsExpr;onlyOnce(this,"vars");return this}in(inExpr){this.$let.in=inExpr;onlyOnce(this,"in");return this}}const $let=(varsExpr,inExpr)=>new LetVarsIn(varsExpr,inExpr);const $linearFill=se("$linearFill");const $literal=se("$literal");const $locf=se("$locf");const $log=at("$log");const $log10=se("$log10");const $lt=taf("$lt");const $lte=taf("$lte");class MapOperator{constructor(inputExpr,asName,inExpr){this.$map={};this.input(inputExpr);if(asName)this.as(asName);if(inExpr)this.in(inExpr)}input(inputExpr){this.$map.input=inputExpr;onlyOnce(this,"input");return this}as(name){this.$map.as=name;onlyOnce(this,"as");return this}in(expression){this.$map.in=expression;onlyOnce(this,"in");return this}}const $map=(inputExpr,asName,inExpr)=>new MapOperator(inputExpr,asName,inExpr);const $max=taf("$max");const $mergeObjects=ptafaa("$mergeObjects");var MetaDataKeyword;(function(MetaDataKeyword){MetaDataKeyword[MetaDataKeyword["textScore"]=0]="textScore";MetaDataKeyword[MetaDataKeyword["indexKey"]=1]="indexKey"})(MetaDataKeyword||(MetaDataKeyword={}));const $meta=se("$meta");const $min=taf("$min");const $mod=at("$mod");const $multiply=ptafaa("$multiply");const $multiplySafe=safeNumberArgs($multiply);const $ne=at("$ne");const $nin=taf("$nin");const $ninSafe=(...args)=>{if(args.length===2){const[val,arr]=args;return $in(val,$ifNull(arr,[]))}return $in(...args)};const $nor=se("$nor");const $not=se("$not");const $objectToArray=se("$objectToArray");const $or=ptafaa("$or");const $pow=at("$pow");const $push=se("$push");const $radiansToDegrees=se("$radiansToDegrees");const $rand=ne("$rand");const $rank=ne("$rank");const $reduce=(input,initialValue,inExpr)=>({$reduce:{input:input,initialValue:initialValue,in:inExpr}});const $round=(value,places=0)=>({$round:[value,places]});const $roundStandard=(value,places=0)=>{const expr=$let({input:value});if(places){const multiplier=Math.pow(10,places||0);return expr.in($let({val:$add($multiply("$$input",multiplier),$if($gte("$$input",0)).then(.5).else(-.5))}).in($divide($subtract("$$val",$mod("$$val",1)),multiplier)))}return expr.in($let({val:$add("$$input",$if($gte("$$input",0)).then(.5).else(-.5))}).in($subtract("$$val",$mod("$$val",1))))};const $sampleRate=se("$sampleRate");const $setDifference=at("$setDifference");const $setEquals=pta("$setEquals");const $setField=(input,field,value)=>({$setField:{field:field,input:input,value:value}});const $setIntersection=pta("$setIntersection");const $setIsSubset=at("$setIsSubset");const $setUnion=pta("$setUnion");const $sin=se("$sin");const $sinh=se("$sinh");const $size=se("$size");const $slice=pta("$slice");const $split=at("$split");const $sqrt=se("$sqrt");const $strcasecmp=at("$strcasecmp");const $strLenBytes=se("$strLenBytes");const $strLenCP=se("$strLenCP");const $subtract=at("$subtract");const $subtractSafe=safeNumberArgs($subtract);const $substr=pta("$substr");const $substrBytes=pta("$substrBytes");const $substrCP=pta("$substrCP");const $sum=se("$sum");const branch=(caseExpr,thenExpr)=>({case:caseExpr,then:thenExpr});class Switch{constructor(arg1,arg2){this.$switch={};const args=[arg1,arg2].filter((v=>v!==undefined));if(args.length>=2){if(args.filter((v=>Array.isArray(v))).length>1){throw new TypeError(`Multiple switch branches input. Only one is supported.`)}if(args.filter((v=>!Array.isArray(v))).length>1){throw new TypeError(`Multiple switch defaults input. Only one is supported.`)}}while(args.length){const arg=args.shift();if(Array.isArray(arg)){this.branches(...arg)}else{this.default(arg)}}}branches(...args){this.$switch.branches=args;return this}branch(caseExpr,thenExpr){if(this.$switch.branches===undefined){this.$switch.branches=[]}this.$switch.branches.push({case:caseExpr,then:thenExpr});return this}default(defaultReturn){this.$switch.default=defaultReturn;onlyOnce(this,"default");return this}}const $switch=(arg1,arg2)=>new Switch(arg1,arg2);const $tan=se("$tan");const $tanh=se("$tanh");const $toBool=se("$toBool");const $toDate=se("$toDate");const $toDecimal=se("$toDecimal");const $toDouble=se("$toDouble");const $toInt=se("$toInt");const $toLong=se("$toLong");const $toObjectId=se("$toObjectId");const $toString=se("$toString");const $toUpper=se("$toUpper");const $toLower=se("$toLower");const $trunc=at("$trunc");const $tsIncrement=se("$tsIncrement");const $tsSecond=se("$tsSecond");const $type=se("$type");const $unsetField=(field,input)=>({$unsetField:{field:field,input:input}});const $year=se("$year");module.exports={$abs:$abs,abs:$abs,$acos:$acos,acos:$acos,$acosh:$acosh,acosh:$acosh,$add:$add,add:$add,$addSafe:$addSafe,addSafe:$addSafe,$addFields:$addFields,addFields:$addFields,$addToSet:$addToSet,addToSet:$addToSet,$all:$all,all:$all,$allElementsTrue:$allElementsTrue,allElementsTrue:$allElementsTrue,$and:$and,and:$and,$anyElementTrue:$anyElementTrue,anyElementTrue:$anyElementTrue,$arrayElemAt:$arrayElemAt,arrayElemAt:$arrayElemAt,$arrayElemFirst:$arrayElemFirst,arrayElemFirst:$arrayElemFirst,$arrayElemLast:$arrayElemLast,arrayElemLast:$arrayElemLast,$arrayToObject:$arrayToObject,arrayToObject:$arrayToObject,$asin:$asin,asin:$asin,$asinh:$asinh,asinh:$asinh,$atan:$atan,atan:$atan,$atanh:$atanh,atanh:$atanh,$avg:$avg,avg:$avg,$bucket:$bucket,bucket:$bucket,$bucketAuto:$bucketAuto,bucketAuto:$bucketAuto,$binarySize:$binarySize,binarySize:$binarySize,branch:branch,$bitAnd:$bitAnd,bitAnd:$bitAnd,$bitNot:$bitNot,bitNot:$bitNot,$bitOr:$bitOr,bitOr:$bitOr,$bitXor:$bitXor,bitXor:$bitXor,$bsonSize:$bsonSize,bsonSize:$bsonSize,case:branch,$ceil:$ceil,ceil:$ceil,$changeStream:$changeStream,changeStream:$changeStream,$cmp:$cmp,cmp:$cmp,$comment:$comment,comment:$comment,$concat:$concat,concat:$concat,$concatSafe:$concatSafe,concatSafe:$concatSafe,$concatArrays:$concatArrays,concatArrays:$concatArrays,$concatArraysSafe:$concatArraysSafe,concatArraysSafe:$concatArraysSafe,$cond:$cond,cond:$cond,$convert:$convert,convert:$convert,$cos:$cos,cos:$cos,$cosh:$cosh,cosh:$cosh,$count:$count,count:$count,$covariancePop:$covariancePop,covariancePop:$covariancePop,$covarianceSamp:$covarianceSamp,covarianceSamp:$covarianceSamp,$decrement:$decrement,decrement:$decrement,$degreesToRadians:$degreesToRadians,degreesToRadians:$degreesToRadians,$denseRank:$denseRank,denseRank:$denseRank,$divide:$divide,divide:$divide,$divideSafe:$divideSafe,divideSafe:$divideSafe,$documentNumber:$documentNumber,documentNumber:$documentNumber,$documents:$documents,documents:$documents,$ensureArray:$ensureArray,$each:$each,each:$each,$elemMatch:$elemMatch,elemMatch:$elemMatch,ensureArray:$ensureArray,$ensureNumber:$ensureNumber,ensureNumber:$ensureNumber,$ensureString:$ensureString,ensureString:$ensureString,$eq:$eq,eq:$eq,$exists:$exists,exists:$exists,$exp:$exp,exp:$exp,$expr:$expr,expr:$expr,$facet:$facet,facet:$facet,$filter:$filter,filter:$filter,$find:$find,find:$find,$first:$first,first:$first,$floor:$floor,floor:$floor,$group:$group,group:$group,$getField:$getField,getField:$getField,$gt:$gt,gt:$gt,$gte:$gte,gte:$gte,$if:$if,if:$if,$ifNull:$ifNull,ifNull:$ifNull,$in:$in,in:$in,$increment:$increment,increment:$increment,$inSafe:$inSafe,inSafe:$inSafe,$isArray:$isArray,isArray:$isArray,$isNumber:$isNumber,isNumber:$isNumber,$last:$last,last:$last,$let:$let,let:$let,$limit:$limit,limit:$limit,$linearFill:$linearFill,linearFill:$linearFill,$literal:$literal,literal:$literal,$locf:$locf,locf:$locf,$log:$log,log:$log,$log10:$log10,log10:$log10,$lookup:$lookup,lookup:$lookup,$lt:$lt,lt:$lt,$lte:$lte,lte:$lte,$map:$map,map:$map,$match:$match,match:$match,$max:$max,max:$max,$meta:$meta,meta:$meta,$min:$min,min:$min,$merge:$merge,merge:$merge,$mergeObjects:$mergeObjects,mergeObjects:$mergeObjects,$mod:$mod,mod:$mod,$multiply:$multiply,multiply:$multiply,$multiplySafe:$multiplySafe,multiplySafe:$multiplySafe,$ne:$ne,ne:$ne,$nin:$nin,nin:$nin,$nor:$nor,nor:$nor,$not:$not,not:$not,$or:$or,or:$or,$out:$out,out:$out,pipeline:pipeline,$pow:$pow,pow:$pow,$objectToArray:$objectToArray,objectToArray:$objectToArray,$radiansToDegrees:$radiansToDegrees,radiansToDegrees:$radiansToDegrees,$project:$project,project:$project,$push:$push,push:$push,$rand:$rand,rand:$rand,$rank:$rank,rank:$rank,$redact:$redact,redact:$redact,$reduce:$reduce,reduce:$reduce,$replaceRoot:$replaceRoot,replaceRoot:$replaceRoot,$replaceWith:$replaceWith,replaceWith:$replaceWith,$round:$round,round:$round,$roundStandard:$roundStandard,roundStandard:$roundStandard,$sampleRate:$sampleRate,sampleRate:$sampleRate,$set:$set,set:$set,$setDifference:$setDifference,setDifference:$setDifference,$setEquals:$setEquals,setEquals:$setEquals,$setField:$setField,setField:$setField,$setIntersection:$setIntersection,setIntersection:$setIntersection,$setIsSubset:$setIsSubset,setIsSubset:$setIsSubset,$setUnion:$setUnion,setUnion:$setUnion,$sort:$sort,sort:$sort,$sortByCount:$sortByCount,sortByCount:$sortByCount,$split:$split,split:$split,$strcasecmp:$strcasecmp,strcasecmp:$strcasecmp,$substr:$substr,substr:$substr,$substrBytes:$substrBytes,substrBytes:$substrBytes,$substrCP:$substrCP,substrCP:$substrCP,$subtract:$subtract,subtract:$subtract,$subtractSafe:$subtractSafe,subtractSafe:$subtractSafe,$size:$size,size:$size,$slice:$slice,slice:$slice,$sin:$sin,sin:$sin,$sinh:$sinh,sinh:$sinh,$skip:$skip,skip:$skip,$sqrt:$sqrt,sqrt:$sqrt,$strLenBytes:$strLenBytes,strLenBytes:$strLenBytes,$strLenCP:$strLenCP,strLenCP:$strLenCP,$sum:$sum,sum:$sum,$switch:$switch,switch:$switch,$tan:$tan,tan:$tan,$tanh:$tanh,tanh:$tanh,$toBool:$toBool,toBool:$toBool,$toDate:$toDate,toDate:$toDate,$toDecimal:$toDecimal,toDecimal:$toDecimal,$toDouble:$toDouble,toDouble:$toDouble,$toInt:$toInt,toInt:$toInt,$toLong:$toLong,toLong:$toLong,$toObjectId:$toObjectId,toObjectId:$toObjectId,$toString:$toString,toString:$toString,$toUpper:$toUpper,toUpper:$toUpper,$toLower:$toLower,toLower:$toLower,$tsIncrement:$tsIncrement,tsIncrement:$tsIncrement,$tsSecond:$tsSecond,tsSecond:$tsSecond,$trunc:$trunc,trunc:$trunc,$type:$type,type:$type,$unsetField:$unsetField,unsetField:$unsetField,$unwind:$unwind,unwind:$unwind,$year:$year,year:$year,ChangeStreamFullDocument:ChangeStreamFullDocument,MergeActionWhenMatched:MergeActionWhenMatched,MergeActionWhenNotMatched:MergeActionWhenNotMatched}; |
{ | ||
"name": "mongodb-pipelinejs", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Use short and sweet JS syntax to compose and cleanly format MongoDB aggregations.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118031
2352