|
|
@@ -14,6 +14,8 @@ var ParsedDeps = module.exports = function ParsedDeps(fields) {
|
|
|
this._fields = fields;
|
|
|
}, klass = ParsedDeps, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
+var Value = require("./Value");
|
|
|
+
|
|
|
/**
|
|
|
* Extracts fields from the input into a new Document, based on the caller.
|
|
|
*
|
|
|
@@ -36,12 +38,12 @@ proto.extractFields = function extractFields(input) {
|
|
|
proto._arrayHelper = function _arrayHelper(array, neededFields) {
|
|
|
var values = [];
|
|
|
|
|
|
- array.sort().forEach(function (it) {
|
|
|
+ for (var it in array) {
|
|
|
if (it instanceof Array)
|
|
|
values.push(_arrayHelper(it, neededFields));
|
|
|
else if (it instanceof Object)
|
|
|
values.push(proto._documentHelper(it, neededFields));
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
return values;
|
|
|
};
|
|
|
@@ -57,25 +59,27 @@ proto._arrayHelper = function _arrayHelper(array, neededFields) {
|
|
|
proto._documentHelper = function _documentHelper(json, neededFields) {
|
|
|
var doc = {};
|
|
|
|
|
|
- Object.keys(json).sort().forEach(function (it) {
|
|
|
- var jsonElement = json[it],
|
|
|
- isNeeded = neededFields[it];
|
|
|
+ for (var fieldName in json) {
|
|
|
+ var jsonElement = json[fieldName],
|
|
|
+ isNeeded = neededFields[fieldName];
|
|
|
|
|
|
- if (!isNeeded)
|
|
|
- return;
|
|
|
+ if (isNeeded === undefined)
|
|
|
+ continue;
|
|
|
|
|
|
- if (typeof(isNeeded) === 'boolean') {
|
|
|
- doc[it] = jsonElement;
|
|
|
- return;
|
|
|
+ if (Value.getType(isNeeded) === 'boolean') {
|
|
|
+ doc[fieldName] = jsonElement;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- if (typeof(isNeeded) === 'object') {
|
|
|
+ if (!isNeeded instanceof Object) throw new Error("dassert failure");
|
|
|
+
|
|
|
+ if (Value.getType(isNeeded) === 'object') {
|
|
|
if (jsonElement instanceof Array)
|
|
|
- doc[it] = proto._arrayHelper(jsonElement, isNeeded);
|
|
|
+ doc[fieldName] = proto._arrayHelper(jsonElement, isNeeded);
|
|
|
if (jsonElement instanceof Object)
|
|
|
- doc[it] = proto._documentHelper(jsonElement, isNeeded);
|
|
|
+ doc[fieldName] = proto._documentHelper(jsonElement, isNeeded);
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
return doc;
|
|
|
};
|