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

contentful-resolve-response

Package Overview
Dependencies
Maintainers
6
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-resolve-response - npm Package Compare versions

Comparing version 1.1.4 to 1.2.2

LICENSE

51

CHANGELOG.md

@@ -0,1 +1,52 @@

## [1.2.2](https://github.com/contentful/contentful-resolve-response/compare/v1.2.1...v1.2.2) (2020-07-03)
### Bug Fixes
* bump to 1.2.2 for semantic-release ([b835e90](https://github.com/contentful/contentful-resolve-response/commit/b835e90b9a800712f43576e141500508cefdfffd))
## [1.2.1](https://github.com/contentful/contentful-resolve-response/compare/v1.2.0...v1.2.1) (2020-07-03)
### Bug Fixes
* bump to 1.2.1 for semantic-release ([0cf7de5](https://github.com/contentful/contentful-resolve-response/commit/0cf7de51032933f734dd72011f5b518f5583b6da))
# [1.2.0](https://github.com/contentful/contentful-resolve-response/compare/v1.1.2...v1.2.0) (2020-07-03)
### Bug Fixes
* **get-link:** better performance on large input ([9b1bab0](https://github.com/contentful/contentful-resolve-response/commit/9b1bab06b2ff8d5037e66d7bdd131a51e4d82062))
* Update deps ([587f04c](https://github.com/contentful/contentful-resolve-response/commit/587f04ccd36d62d0241721ee7bbcd00c4f0cfcdc))
* Update Nodejs version ([d4550e0](https://github.com/contentful/contentful-resolve-response/commit/d4550e0b2941a3080b06954ac0d7eb9da4f8a6cd))
* **array-fields:** proper unresolved removal while iterating array ([#19](https://github.com/contentful/contentful-resolve-response/issues/19)) ([39bf40d](https://github.com/contentful/contentful-resolve-response/commit/39bf40d7e38f5e3a0bce96491448c333d128b850))
* **compatibility:** indexOf instead of includes([#18](https://github.com/contentful/contentful-resolve-response/issues/18)) ([1c3b277](https://github.com/contentful/contentful-resolve-response/commit/1c3b277c2189b966841a86da276de018618aa1ce))
### Features
* bump to 1.2.0 for semantic-release ([08a5c8a](https://github.com/contentful/contentful-resolve-response/commit/08a5c8aca742e545a65f27ca32b14d17b618a76b))
## [1.1.3](https://github.com/contentful/contentful-resolve-response/compare/v1.1.2...v1.1.3) (2020-07-03)
### Bug Fixes
* **get-link:** better performance on large input ([9b1bab0](https://github.com/contentful/contentful-resolve-response/commit/9b1bab06b2ff8d5037e66d7bdd131a51e4d82062))
* Update deps ([587f04c](https://github.com/contentful/contentful-resolve-response/commit/587f04ccd36d62d0241721ee7bbcd00c4f0cfcdc))
* Update Nodejs version ([d4550e0](https://github.com/contentful/contentful-resolve-response/commit/d4550e0b2941a3080b06954ac0d7eb9da4f8a6cd))
* **array-fields:** proper unresolved removal while iterating array ([#19](https://github.com/contentful/contentful-resolve-response/issues/19)) ([39bf40d](https://github.com/contentful/contentful-resolve-response/commit/39bf40d7e38f5e3a0bce96491448c333d128b850))
* **compatibility:** indexOf instead of includes([#18](https://github.com/contentful/contentful-resolve-response/issues/18)) ([1c3b277](https://github.com/contentful/contentful-resolve-response/commit/1c3b277c2189b966841a86da276de018618aa1ce))
## [1.1.3](https://github.com/contentful/contentful-resolve-response/compare/v1.1.2...v1.1.3) (2020-07-03)
### Bug Fixes
* Update deps ([587f04c](https://github.com/contentful/contentful-resolve-response/commit/587f04ccd36d62d0241721ee7bbcd00c4f0cfcdc))
* Update Nodejs version ([d4550e0](https://github.com/contentful/contentful-resolve-response/commit/d4550e0b2941a3080b06954ac0d7eb9da4f8a6cd))
* **array-fields:** proper unresolved removal while iterating array ([#19](https://github.com/contentful/contentful-resolve-response/issues/19)) ([39bf40d](https://github.com/contentful/contentful-resolve-response/commit/39bf40d7e38f5e3a0bce96491448c333d128b850))
* **compatibility:** indexOf instead of includes([#18](https://github.com/contentful/contentful-resolve-response/issues/18)) ([1c3b277](https://github.com/contentful/contentful-resolve-response/commit/1c3b277c2189b966841a86da276de018618aa1ce))
# Change Log

@@ -2,0 +53,0 @@ All notable changes to this project will be documented in this file.

40

dist/cjs/index.js

@@ -27,15 +27,11 @@ 'use strict';

/**
* findNormalizableLinkInArray
* Creates a string key for lookup in entityMap
*
* @param array
* @param predicate
* @return {*}
* @param {*} sys
* @param {String} sys.type
* @param {String} sys.id
* @return {String}
*/
var findNormalizableLinkInArray = function findNormalizableLinkInArray(array, predicate) {
for (var i = 0, len = array.length; i < len; i++) {
if (predicate(array[i])) {
return array[i];
}
}
return UNRESOLVED_LINK;
var makeLookupKey = function makeLookupKey(sys) {
return `${sys.type}!${sys.id}`;
};

@@ -50,3 +46,3 @@

*/
var getLink = function getLink(allEntries, link) {
var getLink = function getLink(entityMap, link) {
var _link$sys = link.sys,

@@ -56,9 +52,5 @@ type = _link$sys.linkType,

var lookupKey = makeLookupKey({ type, id });
var predicate = function predicate(_ref) {
var sys = _ref.sys;
return sys.type === type && sys.id === id;
};
return findNormalizableLinkInArray(allEntries, predicate);
return entityMap.get(lookupKey) || UNRESOLVED_LINK;
};

@@ -111,4 +103,4 @@

var normalizeLink = function normalizeLink(allEntries, link, removeUnresolved) {
var resolvedLink = getLink(allEntries, link);
var normalizeLink = function normalizeLink(entityMap, link, removeUnresolved) {
var resolvedLink = getLink(entityMap, link);
if (resolvedLink === UNRESOLVED_LINK) {

@@ -156,2 +148,6 @@ return removeUnresolved ? resolvedLink : link;

var entityMap = new Map(allEntries.map(function (entity) {
return [makeLookupKey(entity.sys), entity];
}));
allEntries.forEach(function (item) {

@@ -161,3 +157,3 @@ var entryObject = makeEntryObject(item, options.itemEntryPoints);

Object.assign(item, walkMutate(entryObject, isLink, function (link) {
return normalizeLink(allEntries, link, options.removeUnresolved);
return normalizeLink(entityMap, link, options.removeUnresolved);
}, options.removeUnresolved));

@@ -170,2 +166,2 @@ });

exports.default = resolveResponse;
module.exports = exports['default'];
module.exports = exports.default;

@@ -19,15 +19,11 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

/**
* findNormalizableLinkInArray
* Creates a string key for lookup in entityMap
*
* @param array
* @param predicate
* @return {*}
* @param {*} sys
* @param {String} sys.type
* @param {String} sys.id
* @return {String}
*/
var findNormalizableLinkInArray = function findNormalizableLinkInArray(array, predicate) {
for (var i = 0, len = array.length; i < len; i++) {
if (predicate(array[i])) {
return array[i];
}
}
return UNRESOLVED_LINK;
var makeLookupKey = function makeLookupKey(sys) {
return sys.type + '!' + sys.id;
};

@@ -42,3 +38,3 @@

*/
var getLink = function getLink(allEntries, link) {
var getLink = function getLink(entityMap, link) {
var _link$sys = link.sys,

@@ -48,9 +44,5 @@ type = _link$sys.linkType,

var lookupKey = makeLookupKey({ type: type, id: id });
var predicate = function predicate(_ref) {
var sys = _ref.sys;
return sys.type === type && sys.id === id;
};
return findNormalizableLinkInArray(allEntries, predicate);
return entityMap.get(lookupKey) || UNRESOLVED_LINK;
};

@@ -103,4 +95,4 @@

var normalizeLink = function normalizeLink(allEntries, link, removeUnresolved) {
var resolvedLink = getLink(allEntries, link);
var normalizeLink = function normalizeLink(entityMap, link, removeUnresolved) {
var resolvedLink = getLink(entityMap, link);
if (resolvedLink === UNRESOLVED_LINK) {

@@ -148,2 +140,6 @@ return removeUnresolved ? resolvedLink : link;

var entityMap = new Map(allEntries.map(function (entity) {
return [makeLookupKey(entity.sys), entity];
}));
allEntries.forEach(function (item) {

@@ -153,3 +149,3 @@ var entryObject = makeEntryObject(item, options.itemEntryPoints);

Object.assign(item, walkMutate(entryObject, isLink, function (link) {
return normalizeLink(allEntries, link, options.removeUnresolved);
return normalizeLink(entityMap, link, options.removeUnresolved);
}, options.removeUnresolved));

@@ -156,0 +152,0 @@ });

{
"name": "contentful-resolve-response",
"version": "1.1.4",
"version": "1.2.2",
"description": "",

@@ -11,9 +11,10 @@ "main": "./dist/cjs/index.js",

"lint": "eslint index.js test",
"test": "npm run lint && npm run test-unit",
"test-unit": "BABEL_ENV=cjs nyc mocha --require babel-register 'test/**/*-test.js'",
"test-watch": "npm run test-unit -- --watch",
"test-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"test": "BABEL_ENV=cjs mocha --require babel-register 'test/**/*-test.js'",
"test-watch": "npm run test -- --watch",
"precommit": "npm run lint",
"prepush": "npm run test",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"format": "prettier --config ./.prettierrc --write \"{*.js,**/*.js,*.ts,**/*.ts,*.json,**/*.json}\"",
"commitlint-circle": "commitlint-circle",
"semantic-release": "semantic-release"
},

@@ -28,22 +29,29 @@ "repository": {

"dependencies": {
"lodash": "^4.17.4"
"lodash": "^4.17.15"
},
"devDependencies": {
"@contentful/eslint-config-backend": "^6.0.0",
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"@contentful/eslint-config-backend": "^7.0.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@timbeyer/commitlint-circle": "^3.0.0",
"babel-cli": "^6.26.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-env": "^1.6.1",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"chai": "^4.1.1",
"codecov": "^3.0.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"eslint": "^4.4.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-mocha": "^4.11.0",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"husky": "^0.14.3",
"mocha": "^4.1.0",
"nyc": "^11.4.1"
"eslint": "^6.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-mocha": "^6.1.1",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"husky": "^3.0.5",
"mocha": "^6.2.0",
"prettier": "^2.0.5",
"semantic-release": "^17.1.1"
},

@@ -58,3 +66,29 @@ "files": [

},
"homepage": "https://github.com/contentful/contentful-resolve-response"
"homepage": "https://github.com/contentful/contentful-resolve-response",
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"release": {
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "build",
"scope": "deps",
"release": "patch"
}
]
}
],
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/git",
"@semantic-release/npm",
"@semantic-release/github"
]
}
}
# contentful-resolve-response
[![npm](https://img.shields.io/npm/v/contentful-resolve-response.svg)](https://www.npmjs.com/package/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)

@@ -7,0 +5,0 @@ Suppose you have a Contentful query's response JSON. The links are

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