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

jsonapi-renderer

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonapi-renderer - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

package.json
{
"name": "jsonapi-renderer",
"version": "1.0.1",
"version": "1.0.2",
"description": "Helper for generating jsonapi compliant output from models",

@@ -5,0 +5,0 @@ "repository": {

@@ -12,3 +12,7 @@ 'use strict';

Render.prototype.shouldRenderField = function(model, name, descriptor, fieldsRequested) {
Render.prototype.shouldRenderField = function(model, name, descriptor, fieldsRequested, fieldsAllowed) {
if (!_.isUndefined(fieldsAllowed) && !_.includes(fieldsAllowed, name)) {
return false;
}
if (descriptor.valid && !descriptor.valid.call(model)) {

@@ -33,7 +37,6 @@ return false;

Render.prototype.extractRenderedFields = function(model, fields, fieldsRequested) {
var filtered = _.pick(fields, function(fieldDescriptor, name) {
return this.shouldRenderField(model, name, fieldDescriptor, fieldsRequested);
Render.prototype.extractRenderedFields = function(model, fields, fieldsRequested, fieldsAllowed) {
return _.pick(fields, function(fieldDescriptor, name) {
return this.shouldRenderField(model, name, fieldDescriptor, fieldsRequested, fieldsAllowed);
}, this);
return filtered;
};

@@ -180,2 +183,3 @@

var fieldsRequested = options.fields[definition.type];
var fieldsAllowed = options.fieldsAllowed && options.fieldsAllowed[definition.type];

@@ -185,3 +189,3 @@ var promises = [];

promises.push(this.getAllAttributes(model, definition).then(function(allAttributes) {
var attributesToRender = this.extractRenderedFields(model, allAttributes, fieldsRequested);
var attributesToRender = this.extractRenderedFields(model, allAttributes, fieldsRequested, fieldsAllowed);
if (_.keys(attributesToRender).length > 0) {

@@ -199,3 +203,3 @@ data.attributes = {};

promises.push(this.getAllRelationships(model, definition).then(function(allRelationships) {
var relationshipsToRender = this.extractRenderedFields(model, allRelationships, fieldsRequested);
var relationshipsToRender = this.extractRenderedFields(model, allRelationships, fieldsRequested, fieldsAllowed);
if (_.keys(relationshipsToRender).length > 0) {

@@ -202,0 +206,0 @@ data.relationships = {};

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