kitsu-core
Advanced tools
Comparing version 10.0.0-alpha.25 to 10.0.0-alpha.26
@@ -6,2 +6,14 @@ # Change Log | ||
# [10.0.0-alpha.26](https://github.com/wopian/kitsu/compare/v10.0.0-alpha.25...v10.0.0-alpha.26) (2022-08-11) | ||
### Bug Fixes | ||
* **kitsu-core:** fix inability to link relationship links on circular resources ([#699](https://github.com/wopian/kitsu/issues/699)) ([95d3453](https://github.com/wopian/kitsu/commit/95d3453e61ac9883c6dcb30b15402ddae3587019)) | ||
# [10.0.0-alpha.25](https://github.com/wopian/kitsu/compare/v10.0.0-alpha.24...v10.0.0-alpha.25) (2022-07-13) | ||
@@ -8,0 +20,0 @@ |
@@ -12,5 +12,6 @@ 'use strict'; | ||
const previouslyLinked = {}; | ||
const relationshipCache = {}; | ||
for (let value of array.data) { | ||
value = linkRelationships.linkRelationships(value, [...array.data, ...(array.included || [])], previouslyLinked); | ||
value = linkRelationships.linkRelationships(value, [...array.data, ...(array.included || [])], previouslyLinked, relationshipCache); | ||
if (value.attributes) value = deattribute.deattribute(value); | ||
@@ -17,0 +18,0 @@ array.data[array.data.indexOf(value)] = value; |
@@ -61,3 +61,3 @@ (function (global, factory) { | ||
function link(_ref, included, previouslyLinked) { | ||
function link(_ref, included, previouslyLinked, relationshipCache) { | ||
let { | ||
@@ -75,3 +75,3 @@ id, | ||
if (filtered.relationships) { | ||
linkRelationships(filtered, included, previouslyLinked); | ||
linkRelationships(filtered, included, previouslyLinked, relationshipCache); | ||
} | ||
@@ -83,5 +83,6 @@ | ||
function linkArray(data, included, key, previouslyLinked) { | ||
function linkArray(data, included, key, previouslyLinked, relationshipCache) { | ||
data[key] = {}; | ||
if (data.relationships[key].links) data[key].links = data.relationships[key].links; | ||
if (data.relationships[key].meta) data[key].meta = data.relationships[key].meta; | ||
data[key].data = []; | ||
@@ -91,3 +92,3 @@ | ||
const cache = previouslyLinked[`${resource.type}#${resource.id}`]; | ||
let relationship = cache || link(resource, included, previouslyLinked); | ||
let relationship = cache || link(resource, included, previouslyLinked, relationshipCache); | ||
if (resource.meta !== relationship.meta) relationship = { ...relationship, | ||
@@ -102,8 +103,12 @@ meta: resource.meta | ||
function linkObject(data, included, key, previouslyLinked) { | ||
function linkObject(data, included, key, previouslyLinked, relationshipCache) { | ||
data[key] = {}; | ||
const resource = data.relationships[key].data; | ||
const cache = previouslyLinked[`${resource.type}#${resource.id}`]; | ||
data[key].data = cache || link(resource, included, previouslyLinked); | ||
if (data.relationships[key].links) data[key].links = data.relationships[key].links; | ||
data[key].data = cache || link(resource, included, previouslyLinked, relationshipCache); | ||
const cacheKey = `${data.type}#${data.id}#${key}`; | ||
const relationships = relationshipCache[cacheKey] || data.relationships[key]; | ||
if (!relationshipCache[cacheKey]) relationshipCache[cacheKey] = relationships; | ||
if (relationships !== null && relationships !== void 0 && relationships.links) data[key].links = relationships.links; | ||
if (relationships !== null && relationships !== void 0 && relationships.meta) data[key].meta = relationships.meta; | ||
delete data.relationships[key]; | ||
@@ -121,2 +126,3 @@ } | ||
let previouslyLinked = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
let relationshipCache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
const { | ||
@@ -130,5 +136,5 @@ relationships | ||
if (Array.isArray((_relationships$key = relationships[key]) === null || _relationships$key === void 0 ? void 0 : _relationships$key.data)) { | ||
linkArray(data, included, key, previouslyLinked); | ||
linkArray(data, included, key, previouslyLinked, relationshipCache); | ||
} else if (relationships[key].data) { | ||
linkObject(data, included, key, previouslyLinked); | ||
linkObject(data, included, key, previouslyLinked, relationshipCache); | ||
} else { | ||
@@ -148,5 +154,6 @@ linkAttr(data, key); | ||
const previouslyLinked = {}; | ||
const relationshipCache = {}; | ||
for (let value of array.data) { | ||
value = linkRelationships(value, [...array.data, ...(array.included || [])], previouslyLinked); | ||
value = linkRelationships(value, [...array.data, ...(array.included || [])], previouslyLinked, relationshipCache); | ||
if (value.attributes) value = deattribute(value); | ||
@@ -153,0 +160,0 @@ array.data[array.data.indexOf(value)] = value; |
@@ -9,3 +9,3 @@ 'use strict'; | ||
function link(_ref, included, previouslyLinked) { | ||
function link(_ref, included, previouslyLinked, relationshipCache) { | ||
let { | ||
@@ -23,3 +23,3 @@ id, | ||
if (filtered.relationships) { | ||
linkRelationships(filtered, included, previouslyLinked); | ||
linkRelationships(filtered, included, previouslyLinked, relationshipCache); | ||
} | ||
@@ -31,5 +31,6 @@ | ||
function linkArray(data, included, key, previouslyLinked) { | ||
function linkArray(data, included, key, previouslyLinked, relationshipCache) { | ||
data[key] = {}; | ||
if (data.relationships[key].links) data[key].links = data.relationships[key].links; | ||
if (data.relationships[key].meta) data[key].meta = data.relationships[key].meta; | ||
data[key].data = []; | ||
@@ -39,3 +40,3 @@ | ||
const cache = previouslyLinked[`${resource.type}#${resource.id}`]; | ||
let relationship = cache || link(resource, included, previouslyLinked); | ||
let relationship = cache || link(resource, included, previouslyLinked, relationshipCache); | ||
if (resource.meta !== relationship.meta) relationship = { ...relationship, | ||
@@ -50,8 +51,12 @@ meta: resource.meta | ||
function linkObject(data, included, key, previouslyLinked) { | ||
function linkObject(data, included, key, previouslyLinked, relationshipCache) { | ||
data[key] = {}; | ||
const resource = data.relationships[key].data; | ||
const cache = previouslyLinked[`${resource.type}#${resource.id}`]; | ||
data[key].data = cache || link(resource, included, previouslyLinked); | ||
if (data.relationships[key].links) data[key].links = data.relationships[key].links; | ||
data[key].data = cache || link(resource, included, previouslyLinked, relationshipCache); | ||
const cacheKey = `${data.type}#${data.id}#${key}`; | ||
const relationships = relationshipCache[cacheKey] || data.relationships[key]; | ||
if (!relationshipCache[cacheKey]) relationshipCache[cacheKey] = relationships; | ||
if (relationships !== null && relationships !== void 0 && relationships.links) data[key].links = relationships.links; | ||
if (relationships !== null && relationships !== void 0 && relationships.meta) data[key].meta = relationships.meta; | ||
delete data.relationships[key]; | ||
@@ -69,2 +74,3 @@ } | ||
let previouslyLinked = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
let relationshipCache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
const { | ||
@@ -78,5 +84,5 @@ relationships | ||
if (Array.isArray((_relationships$key = relationships[key]) === null || _relationships$key === void 0 ? void 0 : _relationships$key.data)) { | ||
linkArray(data, included, key, previouslyLinked); | ||
linkArray(data, included, key, previouslyLinked, relationshipCache); | ||
} else if (relationships[key].data) { | ||
linkObject(data, included, key, previouslyLinked); | ||
linkObject(data, included, key, previouslyLinked, relationshipCache); | ||
} else { | ||
@@ -83,0 +89,0 @@ linkAttr(data, key); |
{ | ||
"version": "10.0.0-alpha.25", | ||
"version": "10.0.0-alpha.26", | ||
"name": "kitsu-core", | ||
@@ -61,3 +61,3 @@ "description": "Simple, lightweight & framework agnostic JSON:API (de)serialsation components", | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "~7.0.0" | ||
"@size-limit/preset-small-lib": "~8.0.0" | ||
}, | ||
@@ -64,0 +64,0 @@ "exports": { |
@@ -138,3 +138,3 @@ <h1 align=center>Kitsu Core</h1> | ||
[packages/kitsu-core/src/camel/index.js:14-14](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/camel/index.js#L14-L14 "Source code on GitHub") | ||
[packages/kitsu-core/src/camel/index.js:14-14](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/camel/index.js#L14-L14 "Source code on GitHub") | ||
@@ -165,3 +165,3 @@ Converts kebab-case and snake_case into camelCase | ||
[packages/kitsu-core/src/deattribute/index.js:29-51](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/deattribute/index.js#L29-L51 "Source code on GitHub") | ||
[packages/kitsu-core/src/deattribute/index.js:29-51](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/deattribute/index.js#L29-L51 "Source code on GitHub") | ||
@@ -208,3 +208,3 @@ Hoists attributes to be top-level | ||
[packages/kitsu-core/src/deserialise/index.js:57-72](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/deserialise/index.js#L57-L72 "Source code on GitHub") | ||
[packages/kitsu-core/src/deserialise/index.js:58-73](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/deserialise/index.js#L58-L73 "Source code on GitHub") | ||
@@ -252,3 +252,3 @@ Deserialises a JSON-API response | ||
] | ||
}) // { data: { id: '1', user: { type: 'users', id: '2', slug: 'wopian' } } } | ||
}) // { data: { id: '1', user: { data: { type: 'users', id: '2', slug: 'wopian' } } } } | ||
``` | ||
@@ -260,3 +260,3 @@ | ||
[packages/kitsu-core/src/error/index.js:27-33](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/error/index.js#L27-L33 "Source code on GitHub") | ||
[packages/kitsu-core/src/error/index.js:27-33](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/error/index.js#L27-L33 "Source code on GitHub") | ||
@@ -298,3 +298,3 @@ Uniform error handling for Axios, JSON:API and internal package errors. Mutated Error object is rethrown to the caller. | ||
[packages/kitsu-core/src/filterIncludes/index.js:33-46](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/filterIncludes/index.js#L33-L46 "Source code on GitHub") | ||
[packages/kitsu-core/src/filterIncludes/index.js:33-46](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/filterIncludes/index.js#L33-L46 "Source code on GitHub") | ||
@@ -339,3 +339,3 @@ Filters includes for the specific relationship requested | ||
[packages/kitsu-core/src/kebab/index.js:11-11](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/kebab/index.js#L11-L11 "Source code on GitHub") | ||
[packages/kitsu-core/src/kebab/index.js:11-11](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/kebab/index.js#L11-L11 "Source code on GitHub") | ||
@@ -358,3 +358,3 @@ Converts camelCase into kebab-case | ||
[packages/kitsu-core/src/linkRelationships/index.js:114-134](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/linkRelationships/index.js#L114-L134 "Source code on GitHub") | ||
[packages/kitsu-core/src/linkRelationships/index.js:126-146](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/linkRelationships/index.js#L126-L146 "Source code on GitHub") | ||
@@ -368,2 +368,3 @@ Links relationships to included data | ||
* `previouslyLinked` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** A mapping of already visited resources (internal use only) (optional, default `{}`) | ||
* `relationshipCache` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** A cache object for relationship meta and links (optional, default `{}`) | ||
@@ -399,3 +400,3 @@ #### Examples | ||
[packages/kitsu-core/src/query/index.js:33-42](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/query/index.js#L33-L42 "Source code on GitHub") | ||
[packages/kitsu-core/src/query/index.js:33-42](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/query/index.js#L33-L42 "Source code on GitHub") | ||
@@ -428,3 +429,3 @@ Constructs a URL query string for JSON:API parameters | ||
[packages/kitsu-core/src/serialise/index.js:213-224](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/serialise/index.js#L213-L224 "Source code on GitHub") | ||
[packages/kitsu-core/src/serialise/index.js:213-224](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/serialise/index.js#L213-L224 "Source code on GitHub") | ||
@@ -474,3 +475,3 @@ Serialises an object into a JSON-API structure | ||
[packages/kitsu-core/src/snake/index.js:11-11](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/snake/index.js#L11-L11 "Source code on GitHub") | ||
[packages/kitsu-core/src/snake/index.js:11-11](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/snake/index.js#L11-L11 "Source code on GitHub") | ||
@@ -493,3 +494,3 @@ Converts camelCase into snake_case | ||
[packages/kitsu-core/src/splitModel/index.js:29-39](https://github.com/wopian/kitsu/blob/b47ec069143eb03bb03c3e704cbbb4430421d371/packages/kitsu-core/src/splitModel/index.js#L29-L39 "Source code on GitHub") | ||
[packages/kitsu-core/src/splitModel/index.js:29-39](https://github.com/wopian/kitsu/blob/999bf6ecc235965e794591c29cec62d30cb6e352/packages/kitsu-core/src/splitModel/index.js#L29-L39 "Source code on GitHub") | ||
@@ -496,0 +497,0 @@ Split model name from the model's resource URL |
@@ -35,4 +35,4 @@ /** | ||
* ] | ||
* }) // { data: { id: '1', user: { type: 'users', id: '2', slug: 'wopian' } } } | ||
* }) // { data: { id: '1', user: { data: { type: 'users', id: '2', slug: 'wopian' } } } } | ||
*/ | ||
export function deserialise(response: any): any; |
@@ -7,2 +7,3 @@ /** | ||
* @param {Object} [previouslyLinked] A mapping of already visited resources (internal use only) | ||
* @param {Object} [relationshipCache] A cache object for relationship meta and links | ||
* @returns Parsed data | ||
@@ -32,2 +33,2 @@ * | ||
*/ | ||
export function linkRelationships(data: any, included?: any[], previouslyLinked?: any): any; | ||
export function linkRelationships(data: any, included?: any[], previouslyLinked?: any, relationshipCache?: any): any; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
96317
1165
521