Browse Source

EAGLESIX-3083: Adding extra classes

David Aebersold 11 years ago
parent
commit
2c62ac76fa

+ 34 - 4
lib/pipeline/documentSources/SortDocumentSource.js

@@ -56,6 +56,7 @@ klass.GetDepsReturn = {
 proto.dispose = function dispose() {
 	this.docIterator = 0;
 	this.documents = [];
+	this._output.reset();
 	this.source.dispose();
 };
 
@@ -229,6 +230,7 @@ proto.populate = function populate(callback) {
 				self.docIterator = 0;
 
 				self.populated = true;
+				self._output.reset(this.sorter.done());
 				return callback();
 		}
 		);
@@ -239,6 +241,34 @@ proto.populate = function populate(callback) {
 };
 
 
+klass.IteratorFromBsonArray = (function(){
+	/**
+	 * Helper class to unwind arrays within a series of documents.
+	 * @param	{String}	unwindPath is the field path to the array to unwind.
+	 **/
+	var klass = function IteratorFromBsonArray(array){
+		this._sorter = new SortDocumentSource();
+		//this._iterator = new 
+		
+	}, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+
+	proto.next = function next() {
+		if (this.eof())
+			return DocumentSource.EOF;
+
+		var output = this.getCurrent();
+		this.advance();
+		return output;
+	};
+
+	proto.more = function more() { 
+		return this._cursor.more(); 
+	};
+
+	return klass;
+})();
+
+
 proto.populateFromCursors = function populateFromCursors(cursors){
 	for (var i = 0; i < cursors.lenth; i++) {
 		// TODO Create class
@@ -326,7 +356,7 @@ proto.compare = function compare(pL,pR) {
  * Write out an object whose contents are the sort key.
  *
  * @param {bool} explain
- * @return {object} key
+ * @return {Object} key
 **/
 proto.serializeSortKey = function serializeSortKey(explain) {
 	var keyObj = {};
@@ -350,7 +380,7 @@ proto.serializeSortKey = function serializeSortKey(explain) {
  * Creates a new SortDocumentSource
  *
  * @param {Object} jsonElement
- * @ctx {object} context
+ * @ctx {Object} context
  *
 **/
 klass.createFromJson = function createFromJson(jsonElement, ctx) {
@@ -369,7 +399,7 @@ klass.createFromJson = function createFromJson(jsonElement, ctx) {
 			continue;
 		}
 
-		if ( keyField instanceof object) {
+		if ( keyField instanceof Object) {
 			// this restriction is due to needing to figure out sort direction
 			throw new Error("code 17312; " + klass.sortName + "the only expression supported by $sort right now is {$meta: 'textScore'}");
 
@@ -382,7 +412,7 @@ klass.createFromJson = function createFromJson(jsonElement, ctx) {
 
 		var sortOrder = 0;
 		sortOrder = jsonElement[keyField];
-		if ((sortOrder != 1) && (sortOrder !== -1)) throw new Error("code 15975; " + klass.sortName + "$sort key ordering must be 1 (for ascending) or -1 (for descending)");
+		if ((sortOrder != 1) && (sortOrder !== -1)) throw new Error("code 15975; " + klass.sortName + " $sort key ordering must be 1 (for ascending) or -1 (for descending)");
 
 		nextSort.addKey(keyField, (sortOrder > 0));
 		++sortKeys;

+ 2 - 17
test/lib/pipeline/documentSources/SortDocumentSource.js

@@ -44,29 +44,14 @@ module.exports = {
 			/** Assert that iterator state accessors consistently report the source is exhausted. */
 			"should return EOF if there are no more sources": function noSources(next){
 				var cwc = new CursorDocumentSource.CursorWithContext();
-				cwc._cursor = new Cursor( [{a: 1}] );
+				cwc._cursor = new Cursor( [{"a": 1}] );
 				var cds = new CursorDocumentSource(cwc);
-				var sds = SortDocumentSource.createFromJson({a:1});
+				var sds = SortDocumentSource.createFromJson({"a": 1});
 				sds.setSource(cds);
 				sds.getNext(function(err, val) {
 					assert.deepEqual(val, {a:1});
 					sds.getNext(function(err, val) {
 						assert.equal(val, DocumentSource.EOF);
-						next();
-					});
-				});
-				sds.getNext(function(err, val) {
-					assert.deepEqual(val, {a:1});
-					sds.getNext(function(err, val) {
-						assert.equal(val, DocumentSource.EOF);
-						next();
-					});
-				});
-				sds.getNext(function(err, val) {
-					assert.deepEqual(val, {a:1});
-					sds.getNext(function(err, val) {
-						assert.equal(val, DocumentSource.EOF);
-						next();
 					});
 				});
 			},