kitsu-core
Advanced tools
Comparing version 7.2.2 to 7.3.1-beta.0
@@ -1,1 +0,1 @@ | ||
"use strict";async function deattribute(t){return"object"==typeof t&&null!==t&&(Array.isArray(t)?await t.map(async t=>deattribute(t)):t.attributes&&t.attributes.constructor===Object&&(Object.keys(t.attributes).forEach(e=>{t[e]=t.attributes[e]}),delete t.attributes)),t}function error(t){if(t.response){const e=t.response.data;e&&e.errors&&(t.errors=e.errors)}throw t}async function filterIncludes(t,e){let{id:r,type:a}=e;try{const e=t.filter(t=>t.id===r&&t.type===a)[0]||{id:r,type:a};return Object.assign({},e)}catch(t){error(t)}}async function link(t,e){let{id:r,type:a,meta:i}=t;const s=await filterIncludes(e,{id:r,type:a});return s.relationships&&await linkRelationships(s,e),i&&(s.meta=i),deattribute(s)}async function linkArray(t,e,r){t[r]=[];for(let a of await t.relationships[r].data)t[r].push(await link(a,e))}async function linkObject(t,e,r){t[r]=await link(t.relationships[r].data,e),delete t[r].relationships}async function linkRelationships(t,e){const{relationships:r}=t;let a=!1;for(let i in await r)r[i].data&&Array.isArray(r[i].data)?(await linkArray(t,e,i),a=!0):r[i].data&&(await linkObject(t,e,i),a=!0);return a&&delete t.relationships,t}async function deserialiseArray(t){for(let e of await t.data)t.included&&(e=await linkRelationships(e,t.included)),e.attributes&&(e=await deattribute(e)),t.data[t.data.indexOf(e)]=e;return t}async function deserialise(t){return t.data&&t.data.constructor===Array?t=await deserialiseArray(t):t.included&&(t.data=await linkRelationships(t.data,t.included)),delete t.included,t.data&&t.data.attributes&&(t.data=await deattribute(t.data)),t}function queryFormat(t,e){return null!==t&&"object"==typeof t?query(t,e):encodeURIComponent(e)+"="+encodeURIComponent(t)}function query(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const r=[];for(const a in t)t.hasOwnProperty(a)&&r.push(queryFormat(t[a],e?"".concat(e,"[").concat(a,"]"):a));return r.join("&")}Object.defineProperty(exports,"__esModule",{value:!0});const requiresID=(t,e)=>"".concat(t," requires an ID for the ").concat(e," relationships");async function isValid(t,e,r){if(t.constructor!==Object||0===Object.keys(t).length)throw new Error("".concat(e," requires a JSON object body"));if("POST"!==e&&!t.id)throw new Error("".concat(e," requires an ID for the ").concat(r," type"))}async function serialiseObject(t,e,r,a,i){if("string"!=typeof t.id)throw new Error(requiresID(i,r));return a.relationships||(a.relationships={}),t.type||(t.type=e),a.relationships[r]={data:Object.assign(t)},a}async function serialiseArray(t,e,r,a,i){return a.relationships||(a.relationships={}),a.relationships[r]={data:t.map(t=>{let{id:a,type:s}=t;if(!a)throw new Error(requiresID(i,r));return{id:a,type:s||e}})},a}async function serialiseAttr(t,e,r){return r.attributes||(r.attributes={}),r.attributes[e]=t,r}async function serialise(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"POST";try{const a=this.plural(this.camel(t));let i={type:a};await isValid(e,r,a),"POST"!==r&&(i.id=String(e.id));for(let t in e){const a=e[t],s=this.plural(this.camel(t));null!==a&&a.constructor===Object?i=await serialiseObject(a,s,t,i,r):null!==a&&Array.isArray(a)?i=await serialiseArray(a,s,t,i,r):"id"!==t&&"type"!==t&&(i=await serialiseAttr(a,t,i))}return{data:i}}catch(t){throw error(t)}}var index=t=>t.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,t=>t.slice(1).toUpperCase()),index$1=t=>t.charAt(0).toLowerCase()+t.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,t=>"-"+t.toLowerCase()),index$2=t=>t.charAt(0).toLowerCase()+t.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,t=>"_"+t.toLowerCase());exports.camel=index,exports.deattribute=deattribute,exports.deserialise=deserialise,exports.error=error,exports.filterIncludes=filterIncludes,exports.kebab=index$1,exports.linkRelationships=linkRelationships,exports.query=query,exports.serialise=serialise,exports.snake=index$2; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var deattribute=require("./deattribute.js"),error=require("./error.js"),filterIncludes=require("./filterIncludes.js"),linkRelationships=require("./linkRelationships.js"),deserialise=require("./deserialise.js"),query=require("./query.js"),serialise=require("./serialise.js"),camel=require("./camel.js"),kebab=require("./kebab.js"),snake=require("./snake.js");exports.deattribute=deattribute.deattribute,exports.error=error.error,exports.filterIncludes=filterIncludes.filterIncludes,exports.linkRelationships=linkRelationships.linkRelationships,exports.deserialise=deserialise.deserialise,exports.query=query.query,exports.serialise=serialise.serialise,exports.camel=camel,exports.kebab=kebab,exports.snake=snake; |
@@ -1,1 +0,1 @@ | ||
"use strict";async function deattribute(t){return"object"==typeof t&&null!==t&&(Array.isArray(t)?await t.map(async t=>deattribute(t)):t.attributes&&t.attributes.constructor===Object&&(Object.keys(t.attributes).forEach(e=>{t[e]=t.attributes[e]}),delete t.attributes)),t}function error(t){if(t.response){const e=t.response.data;e&&e.errors&&(t.errors=e.errors)}throw t}async function filterIncludes(t,{id:e,type:r}){try{const i=t.filter(t=>t.id===e&&t.type===r)[0]||{id:e,type:r};return Object.assign({},i)}catch(t){error(t)}}async function link({id:t,type:e,meta:r},i){const a=await filterIncludes(i,{id:t,type:e});return a.relationships&&await linkRelationships(a,i),r&&(a.meta=r),deattribute(a)}async function linkArray(t,e,r){t[r]=[];for(let i of await t.relationships[r].data)t[r].push(await link(i,e))}async function linkObject(t,e,r){t[r]=await link(t.relationships[r].data,e),delete t[r].relationships}async function linkRelationships(t,e){const{relationships:r}=t;let i=!1;for(let a in await r)r[a].data&&Array.isArray(r[a].data)?(await linkArray(t,e,a),i=!0):r[a].data&&(await linkObject(t,e,a),i=!0);return i&&delete t.relationships,t}async function deserialiseArray(t){for(let e of await t.data)t.included&&(e=await linkRelationships(e,t.included)),e.attributes&&(e=await deattribute(e)),t.data[t.data.indexOf(e)]=e;return t}async function deserialise(t){return t.data&&t.data.constructor===Array?t=await deserialiseArray(t):t.included&&(t.data=await linkRelationships(t.data,t.included)),delete t.included,t.data&&t.data.attributes&&(t.data=await deattribute(t.data)),t}function queryFormat(t,e){return null!==t&&"object"==typeof t?query(t,e):encodeURIComponent(e)+"="+encodeURIComponent(t)}function query(t,e=null){const r=[];for(const i in t)t.hasOwnProperty(i)&&r.push(queryFormat(t[i],e?`${e}[${i}]`:i));return r.join("&")}Object.defineProperty(exports,"__esModule",{value:!0});const requiresID=(t,e)=>`${t} requires an ID for the ${e} relationships`;async function isValid(t,e,r){if(t.constructor!==Object||0===Object.keys(t).length)throw new Error(`${e} requires a JSON object body`);if("POST"!==e&&!t.id)throw new Error(`${e} requires an ID for the ${r} type`)}async function serialiseObject(t,e,r,i,a){if("string"!=typeof t.id)throw new Error(requiresID(a,r));return i.relationships||(i.relationships={}),t.type||(t.type=e),i.relationships[r]={data:Object.assign(t)},i}async function serialiseArray(t,e,r,i,a){return i.relationships||(i.relationships={}),i.relationships[r]={data:t.map(({id:t,type:i})=>{if(!t)throw new Error(requiresID(a,r));return{id:t,type:i||e}})},i}async function serialiseAttr(t,e,r){return r.attributes||(r.attributes={}),r.attributes[e]=t,r}async function serialise(t,e={},r="POST"){try{const i=this.plural(this.camel(t));let a={type:i};await isValid(e,r,i),"POST"!==r&&(a.id=String(e.id));for(let t in e){const i=e[t],s=this.plural(this.camel(t));null!==i&&i.constructor===Object?a=await serialiseObject(i,s,t,a,r):null!==i&&Array.isArray(i)?a=await serialiseArray(i,s,t,a,r):"id"!==t&&"type"!==t&&(a=await serialiseAttr(i,t,a))}return{data:a}}catch(t){throw error(t)}}var index=t=>t.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,t=>t.slice(1).toUpperCase()),index$1=t=>t.charAt(0).toLowerCase()+t.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,t=>"-"+t.toLowerCase()),index$2=t=>t.charAt(0).toLowerCase()+t.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,t=>"_"+t.toLowerCase());exports.camel=index,exports.deattribute=deattribute,exports.deserialise=deserialise,exports.error=error,exports.filterIncludes=filterIncludes,exports.kebab=index$1,exports.linkRelationships=linkRelationships,exports.query=query,exports.serialise=serialise,exports.snake=index$2; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var deattribute=require("./deattribute.js"),error=require("./error.js"),filterIncludes=require("./filterIncludes.js"),linkRelationships=require("./linkRelationships.js"),deserialise=require("./deserialise.js"),query=require("./query.js"),serialise=require("./serialise.js"),camel=require("./camel.js"),kebab=require("./kebab.js"),snake=require("./snake.js");exports.deattribute=deattribute.deattribute,exports.error=error.error,exports.filterIncludes=filterIncludes.filterIncludes,exports.linkRelationships=linkRelationships.linkRelationships,exports.deserialise=deserialise.deserialise,exports.query=query.query,exports.serialise=serialise.serialise,exports.camel=camel,exports.kebab=kebab,exports.snake=snake; |
{ | ||
"version": "7.2.2", | ||
"version": "7.3.1-beta.0", | ||
"name": "kitsu-core", | ||
@@ -57,3 +57,3 @@ "description": "Core serialisation and deserialsation functions for the kitsu JSON:API client", | ||
], | ||
"gitHead": "c3a4b3f3bb6bd678917092263b9b0e07b0f280a9", | ||
"gitHead": "5c9778d191d17d7c9790cfc6d0f4e983b4742a53", | ||
"devDependencies": { | ||
@@ -60,0 +60,0 @@ "@size-limit/preset-small-lib": "~2.2.1" |
@@ -112,3 +112,3 @@ <h1 align=center>Kitsu Core</h1> | ||
[packages/kitsu-core/src/deattribute/index.js:29-38](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/packages/kitsu-core/src/deattribute/index.js#L29-L38 "Source code on GitHub") | ||
[packages/kitsu-core/src/deattribute/index.js:29-38](https://github.com/wopian/kitsu/blob/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/deattribute/index.js#L29-L38 "Source code on GitHub") | ||
@@ -157,3 +157,3 @@ Hoists attributes to be top-level | ||
[packages/kitsu-core/src/deserialise/index.js:56-70](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/packages/kitsu-core/src/deserialise/index.js#L56-L70 "Source code on GitHub") | ||
[packages/kitsu-core/src/deserialise/index.js:56-70](https://github.com/wopian/kitsu/blob/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/deserialise/index.js#L56-L70 "Source code on GitHub") | ||
@@ -210,3 +210,3 @@ Deserialises a JSON-API response | ||
[packages/kitsu-core/src/error/index.js:7-13](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/packages/kitsu-core/src/error/index.js#L7-L13 "Source code on GitHub") | ||
[packages/kitsu-core/src/error/index.js:7-13](https://github.com/wopian/kitsu/blob/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/error/index.js#L7-L13 "Source code on GitHub") | ||
@@ -224,3 +224,3 @@ Mutates an error and rethrows it | ||
[packages/kitsu-core/src/filterIncludes/index.js:12-21](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/packages/kitsu-core/src/filterIncludes/index.js#L12-L21 "Source code on GitHub") | ||
[packages/kitsu-core/src/filterIncludes/index.js:12-21](https://github.com/wopian/kitsu/blob/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/filterIncludes/index.js#L12-L21 "Source code on GitHub") | ||
@@ -240,3 +240,3 @@ Filters includes for the specific relationship | ||
[packages/kitsu-core/src/linkRelationships/index.js:55-74](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/packages/kitsu-core/src/linkRelationships/index.js#L55-L74 "Source code on GitHub") | ||
[packages/kitsu-core/src/linkRelationships/index.js:55-74](https://github.com/wopian/kitsu/blob/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/linkRelationships/index.js#L55-L74 "Source code on GitHub") | ||
@@ -252,3 +252,3 @@ Links relationships to included data | ||
[packages/kitsu-core/src/query/index.js:21-32](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/packages/kitsu-core/src/query/index.js#L21-L32 "Source code on GitHub") | ||
[packages/kitsu-core/src/query/index.js:21-32](https://github.com/wopian/kitsu/blob/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/query/index.js#L21-L32 "Source code on GitHub") | ||
@@ -266,3 +266,3 @@ Constructs a URL query string for JSON:API parameters | ||
[packages/kitsu-core/src/serialise/index.js:96-121](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/packages/kitsu-core/src/serialise/index.js#L96-L121 "Source code on GitHub") | ||
[packages/kitsu-core/src/serialise/index.js:96-121](https://github.com/wopian/kitsu/blob/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/serialise/index.js#L96-L121 "Source code on GitHub") | ||
@@ -293,3 +293,3 @@ Serialises an object into a JSON-API structure | ||
[packages/kitsu-core/src/camel/index.js:14-14](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/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/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/camel/index.js#L14-L14 "Source code on GitHub") | ||
@@ -322,3 +322,3 @@ Converts kebab-case and snake_case into camelCase | ||
[packages/kitsu-core/src/kebab/index.js:11-11](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/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/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/kebab/index.js#L11-L11 "Source code on GitHub") | ||
@@ -341,3 +341,3 @@ Converts camelCase into kebab-case | ||
[packages/kitsu-core/src/snake/index.js:11-11](https://github.com/wopian/kitsu/blob/56b9e016424a5335acdd3f4844dd8ed1fb446c99/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/8219f20333af2ff4cbc24ac8a0a9805eac18c5f5/packages/kitsu-core/src/snake/index.js#L11-L11 "Source code on GitHub") | ||
@@ -344,0 +344,0 @@ Converts camelCase into snake_case |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
48
132
0
61734
1
9