data-shaper
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -41,2 +41,15 @@ 'use strict'; | ||
// We got null back from fetchData. Create data for fragment | ||
// with null value and pass it to the callback | ||
if (fragmentData === null) { | ||
var nullFragmentData = {}; | ||
nullFragmentData[shape.collectionName + '::' + id] = null; | ||
return callback(null, { | ||
data: nullFragmentData, | ||
shape: shape, | ||
id: id | ||
}); | ||
} | ||
// Shape the data for the fragment | ||
@@ -43,0 +56,0 @@ shapeData(fragmentData, shape, options, function(err, shapedFragmentData) { |
@@ -28,2 +28,10 @@ 'use strict'; | ||
// We got null as data, not possible to continue resolving | ||
if (sourceData === null) { | ||
process.nextTick(function() { | ||
callback(null, null); | ||
}); | ||
return; | ||
} | ||
// We're looking for a value we have in the sourceData object | ||
@@ -30,0 +38,0 @@ if (dotPosition < 0) { |
{ | ||
"name": "data-shaper", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Utility for building meaningful data shapes from normalized, related data", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -8,3 +8,3 @@ # Data shaper | ||
### Why? | ||
While normalized datastructures usually is a good idea it does not always translate so good to what you want to present to a client side app or a 3rd party consumer. The problem is in many cases solved creating lots of custom, which is not trivial to maintain. | ||
While normalized datastructures usually is a good idea it does not always translate so good to what you want to present to a client side app or a 3rd party consumer. The problem is in many cases solved creating lots of custom endpoints, which is not trivial to maintain. | ||
@@ -11,0 +11,0 @@ ### How? |
'use strict'; | ||
module.exports = function(data) { | ||
data = (typeof data === 'undefined') ? {} : data; | ||
return function fetchData(id, reference, callback) { | ||
process.nextTick(function() { | ||
callback(null, data || {}); | ||
callback(null, data); | ||
}); | ||
}; | ||
}; |
@@ -78,2 +78,24 @@ 'use strict'; | ||
}); | ||
it('returns null if null is passed as data', function(done) { | ||
resolveFragment( | ||
{ id: 1, participantId: 2 }, | ||
{ | ||
reference: 'participantId', | ||
shape: { | ||
collectionName: 'foobar', | ||
shape: { | ||
id: 'id', | ||
name: 'name' | ||
} | ||
} | ||
}, | ||
merge({}, defaultOptions, { fetchData: mockFetchData(null) }), | ||
function(err, res) { | ||
assert(!err); | ||
assert.equal(res.data['foobar::2'], null); | ||
done(); | ||
} | ||
); | ||
}); | ||
}); |
@@ -47,2 +47,10 @@ 'use strict'; | ||
}); | ||
it('returns null if null is passed as data', function(done) { | ||
resolveValue(null, 'foobar', {}, function(err, res) { | ||
assert(!err); | ||
assert.equal(res, null); | ||
done(); | ||
}); | ||
}); | ||
}); |
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
31455
721