|
|
@@ -13,7 +13,7 @@ var Expression = module.exports = (function(){
|
|
|
* @module munge
|
|
|
* @constructor
|
|
|
**/
|
|
|
- var klass = module.exports = Expression = function Expression(opts){
|
|
|
+ var klass = module.exports = Expression = function Expression(){
|
|
|
if(arguments.length !== 0) throw new Error("zero args expected");
|
|
|
}, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
@@ -22,16 +22,26 @@ var Expression = module.exports = (function(){
|
|
|
|
|
|
// NESTED CLASSES
|
|
|
/**
|
|
|
- * Utility class for parseObject() below. isDocumentOk indicates that it is OK to use a Document in the current context.
|
|
|
- *
|
|
|
- * NOTE: deviation from Mongo code: accepts an object of settings rather than a bitmask to help cleanup the interface a little bit
|
|
|
- *
|
|
|
- * @class ObjectCtx
|
|
|
- * @namespace munge.pipeline.expressions.Expression
|
|
|
- * @module munge
|
|
|
+ * Reference to the `munge.pipeline.expressions.Expression.ObjectCtx` class
|
|
|
+ * @static
|
|
|
+ * @property ObjectCtx
|
|
|
**/
|
|
|
var ObjectCtx = Expression.ObjectCtx = (function(){
|
|
|
// CONSTRUCTOR
|
|
|
+ /**
|
|
|
+ * Utility class for parseObject() below. isDocumentOk indicates that it is OK to use a Document in the current context.
|
|
|
+ *
|
|
|
+ * NOTE: deviation from Mongo code: accepts an `Object` of settings rather than a bitmask to help simplify the interface a little bit
|
|
|
+ *
|
|
|
+ * @class ObjectCtx
|
|
|
+ * @namespace munge.pipeline.expressions.Expression
|
|
|
+ * @module munge
|
|
|
+ * @constructor
|
|
|
+ * @param opts
|
|
|
+ * @param [opts.isDocumentOk] {Boolean}
|
|
|
+ * @param [opts.isTopLevel] {Boolean}
|
|
|
+ * @param [opts.isInclusionOk] {Boolean}
|
|
|
+ **/
|
|
|
var klass = function ObjectCtx(opts /*= {isDocumentOk:..., isTopLevel:..., isInclusionOk:...}*/){
|
|
|
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) { // assign all given opts to self so long as they were part of klass.prototype as undefined properties
|
|
|
@@ -39,24 +49,37 @@ var Expression = module.exports = (function(){
|
|
|
}
|
|
|
}, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
+ // PROTOTYPE MEMBERS
|
|
|
proto.isDocumentOk =
|
|
|
proto.isTopLevel =
|
|
|
proto.isInclusionOk = undefined;
|
|
|
+
|
|
|
return klass;
|
|
|
})();
|
|
|
|
|
|
/**
|
|
|
- * Decribes how and when to create an Op instance
|
|
|
- *
|
|
|
- * @class OpDesc
|
|
|
- * @namespace munge.pipeline.expressions.Expression
|
|
|
- * @module munge
|
|
|
+ * Reference to the `munge.pipeline.expressions.Expression.OpDesc` class
|
|
|
+ * @static
|
|
|
+ * @property OpDesc
|
|
|
**/
|
|
|
var OpDesc = Expression.OpDesc = (function(){
|
|
|
// CONSTRUCTOR
|
|
|
+ /**
|
|
|
+ * Decribes how and when to create an Op instance
|
|
|
+ *
|
|
|
+ * @class OpDesc
|
|
|
+ * @namespace munge.pipeline.expressions.Expression
|
|
|
+ * @module munge
|
|
|
+ * @constructor
|
|
|
+ * @param name
|
|
|
+ * @param factory
|
|
|
+ * @param flags
|
|
|
+ * @param argCount
|
|
|
+ **/
|
|
|
var klass = function OpDesc(name, factory, flags, argCount){
|
|
|
- if (arguments[0] instanceof Object && arguments[0].constructor == Object) { //TODO: using this?
|
|
|
- var opts = arguments[0];
|
|
|
+ var firstArg = arguments[0];
|
|
|
+ if (firstArg instanceof Object && firstArg.constructor == Object) { //TODO: using this?
|
|
|
+ var opts = firstArg;
|
|
|
for (var k in opts) { // assign all given opts to self so long as they were part of klass.prototype as undefined properties
|
|
|
if (opts.hasOwnProperty(k) && proto.hasOwnProperty(k) && proto[k] === undefined) this[k] = opts[k];
|
|
|
}
|
|
|
@@ -73,12 +96,16 @@ var Expression = module.exports = (function(){
|
|
|
klass.OBJECT_ARG = 2;
|
|
|
|
|
|
// PROTOTYPE MEMBERS
|
|
|
-
|
|
|
proto.name =
|
|
|
proto.factory =
|
|
|
proto.flags =
|
|
|
proto.argCount = undefined;
|
|
|
|
|
|
+ /**
|
|
|
+ * internal `OpDesc#name` comparer
|
|
|
+ * @method cmp
|
|
|
+ * @param that the other `OpDesc` instance
|
|
|
+ **/
|
|
|
proto.cmp = function cmp(that) {
|
|
|
return this.name < that.name ? -1 : this.name > that.name ? 1 : 0;
|
|
|
};
|
|
|
@@ -247,6 +274,8 @@ var Expression = module.exports = (function(){
|
|
|
/**
|
|
|
* Parse a BSONElement Object which has already been determined to be functional expression.
|
|
|
*
|
|
|
+ * @static
|
|
|
+ * @method parseExpression
|
|
|
* @param opName the name of the (prefix) operator
|
|
|
* @param obj the BSONElement to parse
|
|
|
* @returns the parsed Expression
|
|
|
@@ -280,12 +309,13 @@ var Expression = module.exports = (function(){
|
|
|
expr.addOperand(operand);
|
|
|
}
|
|
|
|
|
|
- return expr;
|
|
|
+ return expr;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* Parse a BSONElement which is an operand in an Expression.
|
|
|
*
|
|
|
+ * @static
|
|
|
* @param pBsonElement the expected operand's BSONElement
|
|
|
* @returns the parsed operand, as an Expression
|
|
|
**/
|
|
|
@@ -303,6 +333,7 @@ var Expression = module.exports = (function(){
|
|
|
* Produce a field path string with the field prefix removed.
|
|
|
* Throws an error if the field prefix is not present.
|
|
|
*
|
|
|
+ * @static
|
|
|
* @param prefixedField the prefixed field
|
|
|
* @returns the field path with the prefix removed
|
|
|
**/
|
|
|
@@ -312,7 +343,13 @@ var Expression = module.exports = (function(){
|
|
|
return prefixedField.substr(1);
|
|
|
};
|
|
|
|
|
|
- /** @returns the sign of a number; -1, 1, or 0 **/
|
|
|
+ /**
|
|
|
+ * returns the signe of a number
|
|
|
+ *
|
|
|
+ * @static
|
|
|
+ * @method signum
|
|
|
+ * @returns the sign of a number; -1, 1, or 0
|
|
|
+ **/
|
|
|
klass.signum = function signum(i) {
|
|
|
if (i < 0) return -1;
|
|
|
if (i > 0) return 1;
|
|
|
@@ -321,11 +358,12 @@ var Expression = module.exports = (function(){
|
|
|
|
|
|
|
|
|
// PROTOTYPE MEMBERS
|
|
|
- /***
|
|
|
+ /**
|
|
|
* Evaluate the Expression using the given document as input.
|
|
|
*
|
|
|
+ * @method evaluate
|
|
|
* @returns the computed value
|
|
|
- ***/
|
|
|
+ **/
|
|
|
proto.evaluate = function evaluate(obj) {
|
|
|
throw new Error("WAS NOT IMPLEMENTED BY INHERITOR!");
|
|
|
};
|
|
|
@@ -340,6 +378,7 @@ var Expression = module.exports = (function(){
|
|
|
* not be the same object. In the case of constant folding, a computed
|
|
|
* expression may be replaced by a constant.
|
|
|
*
|
|
|
+ * @method optimize
|
|
|
* @returns the optimized Expression
|
|
|
**/
|
|
|
proto.optimize = function optimize() {
|
|
|
@@ -352,6 +391,7 @@ var Expression = module.exports = (function(){
|
|
|
* Top-level ExpressionObject gets pointer to empty vector.
|
|
|
* If any other Expression is an ancestor, or in other cases where {a:1} inclusion objects aren't allowed, they get NULL.
|
|
|
*
|
|
|
+ * @method addDependencies
|
|
|
* @param deps output parameter
|
|
|
* @param path path to self if all ancestors are ExpressionObjects.
|
|
|
**/
|
|
|
@@ -359,7 +399,10 @@ var Expression = module.exports = (function(){
|
|
|
throw new Error("WAS NOT IMPLEMENTED BY INHERITOR!");
|
|
|
};
|
|
|
|
|
|
- /** simple expressions are just inclusion exclusion as supported by ExpressionObject **/
|
|
|
+ /**
|
|
|
+ * simple expressions are just inclusion exclusion as supported by ExpressionObject
|
|
|
+ * @method getIsSimple
|
|
|
+ **/
|
|
|
proto.getIsSimple = function getIsSimple() {
|
|
|
return false;
|
|
|
};
|