Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-shaper

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-shaper - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

13

lib/resolve-fragment.js

@@ -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) {

2

package.json
{
"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();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc