contentful-resolve-response
Advanced tools
Comparing version 1.0.2 to 1.1.0
23
index.js
@@ -71,2 +71,15 @@ const cloneDeep = require('lodash/cloneDeep'); | ||
const makeEntryObject = (item, itemEntryPoints) => { | ||
if (!Array.isArray(itemEntryPoints)) { | ||
return item; | ||
} | ||
const entryPoints = Object.keys(item).filter((ownKey) => itemEntryPoints.includes(ownKey)); | ||
return entryPoints.reduce((entryObj, entryPoint) => { | ||
entryObj[entryPoint] = item[entryPoint]; | ||
return entryObj; | ||
}, {}); | ||
}; | ||
/** | ||
@@ -78,2 +91,3 @@ * resolveResponse Function | ||
* @param {Boolean} options.removeUnresolved - Remove unresolved links default:false | ||
* @param {Array<String>} options.itemEntryPoints - Resolve links only in those item properties | ||
* @return {Object} | ||
@@ -94,5 +108,8 @@ */ | ||
.forEach((item) => { | ||
Object.assign(item, { | ||
fields: walkMutate(item.fields, isLink, (link) => normalizeLink(allEntries, link, options.removeUnresolved)) | ||
}); | ||
const entryObject = makeEntryObject(item, options.itemEntryPoints); | ||
Object.assign( | ||
item, | ||
walkMutate(entryObject, isLink, (link) => normalizeLink(allEntries, link, options.removeUnresolved)) | ||
); | ||
}); | ||
@@ -99,0 +116,0 @@ |
{ | ||
"name": "contentful-resolve-response", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -9,4 +9,7 @@ "main": "index.js", | ||
"test": "npm run lint && npm run test-unit", | ||
"test-unit": "mocha 'test/**/*-test.js'", | ||
"test-watch": "npm run test-unit -- --watch" | ||
"test-unit": "nyc mocha 'test/**/*-test.js'", | ||
"test-watch": "npm run test-unit -- --watch", | ||
"test-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", | ||
"precommit": "npm run lint", | ||
"prepush": "npm run test" | ||
}, | ||
@@ -20,2 +23,3 @@ "repository": { | ||
"chai": "^4.1.1", | ||
"codecov": "^3.0.0", | ||
"dirty-chai": "^2.0.1", | ||
@@ -28,3 +32,5 @@ "eslint": "^4.4.1", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"mocha": "^4.1.0" | ||
"husky": "^0.14.3", | ||
"mocha": "^4.1.0", | ||
"nyc": "^11.4.1" | ||
}, | ||
@@ -31,0 +37,0 @@ "author": "Contentful GmbH", |
# contentful-resolve-response | ||
[![Build Status](https://travis-ci.org/contentful/contentful-resolve-response.svg?branch=master)](https://travis-ci.org/contentful/contentful-resolve-response) | ||
[![codecov](https://codecov.io/gh/contentful/contentful-resolve-response/branch/master/graph/badge.svg)](https://codecov.io/gh/contentful/contentful-resolve-response) | ||
Suppose you have a Contentful query's response JSON. The links are | ||
@@ -37,3 +40,3 @@ nice, but what we really usually need is the response with a resolved | ||
someValue: 'wow', | ||
// Link gets replaced by the actual object from `includes.Entry` | ||
@@ -40,0 +43,0 @@ someLink: {sys: {type: 'Entry', id: 'suchId'}, very: 'doge'} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
6052
100
51
13
1