123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- "use strict";
- var ConstantExpression = module.exports = (function(){
- // CONSTRUCTOR
- /**
- * Internal expression for constant values
- *
- * @class ConstantExpression
- * @namespace mungedb.aggregate.pipeline.expressions
- * @module mungedb-aggregate
- * @constructor
- **/
- var klass = function ConstantExpression(value){
- if(arguments.length !== 1) throw new Error("args expected: value");
- this.value = value; //TODO: actually make read-only in terms of JS?
- base.call(this);
- }, base = require("./Expression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
- // PROTOTYPE MEMBERS
- proto.getOpName = function getOpName(){
- return "$const";
- };
- /**
- * Get the constant value represented by this Expression.
- *
- * @method getValue
- * @returns the value
- **/
- proto.getValue = function getValue(){ //TODO: convert this to an instance field rather than a property
- return this.value;
- };
- proto.addDependencies = function addDependencies(deps, path) {
- // nothing to do
- };
- /**
- * Get the constant value represented by this Expression.
- * @method evaluate
- **/
- proto.evaluate = function evaluate(doc){
- return this.value;
- };
- proto.optimize = function optimize() {
- return this; // nothing to do
- };
- proto.toJson = function(isExpressionRequired){
- return isExpressionRequired ? {$const: this.value} : this.value;
- };
- //TODO: proto.addToBsonObj --- may be required for $project to work -- my hope is that we can implement toJson methods all around and use that instead
- //TODO: proto.addToBsonArray
- return klass;
- })();
|