data-shaper
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -74,3 +74,22 @@ 'use strict'; | ||
if (typeof value === 'object') { | ||
async.map(Object.keys(value), function(id, cb) { | ||
var keys = Object.keys(value); | ||
// Got a single object back | ||
if (typeof value[keys[0]] !== 'object') { | ||
options.shapeData(value, shape, options, function(err, shapedFragmentData) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
callback(err, { | ||
data: shapedFragmentData, | ||
shape: shape, | ||
id: value.id | ||
}); | ||
}); | ||
return; | ||
} | ||
// Got multiple objects | ||
async.map(keys, function(id, cb) { | ||
createFragmentHandler(options, shape, id, cb)(null, value[id]); | ||
@@ -77,0 +96,0 @@ }, function(err, res) { |
{ | ||
"name": "data-shaper", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Utility for building meaningful data shapes from normalized, related data", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -108,2 +108,46 @@ 'use strict'; | ||
it('can shape object with one-to-one reverse reference fragment', function(done) { | ||
var shape = { | ||
collectionName: 'persons', | ||
shape: { | ||
id: 'id', | ||
name: 'firstName', | ||
address: { | ||
reference: 'addresses(personId==id)', | ||
shape: { | ||
collectionName: 'addresses', | ||
shape: { | ||
id: 'id' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
dataShaper( | ||
data.persons['1'], | ||
shape, | ||
defaultOptions, | ||
function(err, res) { | ||
assert(!err); | ||
assert.deepEqual(res, { | ||
addresses: { | ||
'1': { | ||
id: 1 | ||
} | ||
}, | ||
persons: { | ||
'1': { | ||
id: 1, | ||
name: 'Fred', | ||
address: { addresses: 1 } | ||
} | ||
} | ||
}); | ||
done(); | ||
} | ||
); | ||
}); | ||
it('can shape object with reverse reference and filter', function(done) { | ||
@@ -110,0 +154,0 @@ var shape = { |
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
55085
1286