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

kitsu-core

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kitsu-core - npm Package Compare versions

Comparing version 7.3.1-beta.0 to 7.3.1-beta.1

2

lib/index.js

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

"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;
"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;
{
"version": "7.3.1-beta.0",
"version": "7.3.1-beta.1",
"name": "kitsu-core",

@@ -4,0 +4,0 @@ "description": "Core serialisation and deserialsation functions for the kitsu JSON:API client",

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