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 6.2.1 to 6.2.2

CHANGELOG.md

204

lib/index.js

@@ -433,20 +433,13 @@ 'use strict';

function serialise() {
return _serialise.apply(this, arguments);
function isValid() {
return _isValid.apply(this, arguments);
}
function _serialise() {
return _serialise = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(model) {
var obj,
method,
type,
data,
key,
keytype,
_args = arguments;
function _isValid() {
return _isValid = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(obj, method, type) {
return _regeneratorRuntime.wrap(function (_context) {
for (;;) switch (_context.prev = _context.next) {
case 0:
if (obj = 1 < _args.length && void 0 !== _args[1] ? _args[1] : {}, method = 2 < _args.length && void 0 !== _args[2] ? _args[2] : 'POST', _context.prev = 1, obj.constructor === Object && 0 !== Object.keys(obj).length) {
_context.next = 4;
if (obj.constructor === Object && 0 !== Object.keys(obj).length) {
_context.next = 2;
break;

@@ -457,7 +450,5 @@ }

case 4:
if (type = this.plural(this.camel(model)), data = {
type
}, 'POST' === method || obj.id) {
_context.next = 7;
case 2:
if ('POST' === method || obj.id) {
_context.next = 4;
break;

@@ -468,61 +459,168 @@ }

case 7:
_context.t0 = _regeneratorRuntime.keys(('POST' !== method && (data.id = obj.id.toString()), obj));
case 4:
case "end":
return _context.stop();
}
}, _callee, this);
})), _isValid.apply(this, arguments);
}
case 8:
if ((_context.t1 = _context.t0()).done) {
_context.next = 21;
function serialiseObject() {
return _serialiseObject.apply(this, arguments);
}
function _serialiseObject() {
return _serialiseObject = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(node, nodeType, key, data, method) {
return _regeneratorRuntime.wrap(function (_context2) {
for (;;) switch (_context2.prev = _context2.next) {
case 0:
if ('string' === typeof node.id) {
_context2.next = 2;
break;
}
if (key = _context.t1.value, null === obj[key] || obj[key].constructor !== Object) {
_context.next = 18;
throw new Error(requiresID(method, key));
case 2:
return _context2.abrupt("return", (data.relationships || (data.relationships = {}), node.type || (node.type = nodeType), data.relationships[key] = {
data: Object.assign(node)
}, data));
case 3:
case "end":
return _context2.stop();
}
}, _callee2, this);
})), _serialiseObject.apply(this, arguments);
}
function serialiseArray() {
return _serialiseArray.apply(this, arguments);
}
function _serialiseArray() {
return _serialiseArray = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(node, nodeType, key, data, method) {
return _regeneratorRuntime.wrap(function (_context3) {
for (;;) switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt("return", (data.relationships || (data.relationships = {}), data.relationships[key] = {
data: node.map((_ref) => {
let id = _ref.id,
type = _ref.type;
if (!id) throw new Error(requiresID(method, key));
return {
id,
type: type || nodeType
};
})
}, data));
case 1:
case "end":
return _context3.stop();
}
}, _callee3, this);
})), _serialiseArray.apply(this, arguments);
}
function serialiseAttr() {
return _serialiseAttr.apply(this, arguments);
}
function _serialiseAttr() {
return _serialiseAttr = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(node, key, data) {
return _regeneratorRuntime.wrap(function (_context4) {
for (;;) switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt("return", (data.attributes || (data.attributes = {}), data.attributes[key] = node, data));
case 1:
case "end":
return _context4.stop();
}
}, _callee4, this);
})), _serialiseAttr.apply(this, arguments);
}
function serialise() {
return _serialise.apply(this, arguments);
}
function _serialise() {
return _serialise = _asyncToGenerator(_regeneratorRuntime.mark(function _callee5(model) {
var obj,
method,
type,
data,
key,
node,
nodeType,
_args5 = arguments;
return _regeneratorRuntime.wrap(function (_context5) {
for (;;) switch (_context5.prev = _context5.next) {
case 0:
return obj = 1 < _args5.length && void 0 !== _args5[1] ? _args5[1] : {}, method = 2 < _args5.length && void 0 !== _args5[2] ? _args5[2] : 'POST', _context5.prev = 1, type = this.plural(this.camel(model)), data = {
type
}, _context5.next = 6, isValid(obj, method, type);
case 6:
'POST' !== method && (data.id = obj.id + ""), _context5.t0 = _regeneratorRuntime.keys(obj);
case 8:
if ((_context5.t1 = _context5.t0()).done) {
_context5.next = 30;
break;
}
if ('string' !== typeof obj[key].id) {
_context.next = 15;
if (key = _context5.t1.value, node = obj[key], nodeType = this.plural(this.camel(key)), !(null !== node & node.constructor === Object)) {
_context5.next = 17;
break;
}
data.relationships || (data.relationships = {}), obj[key].type || (obj[key].type = this.plural(this.camel(key))), data.relationships[key] = {
data: Object.assign(obj[key])
}, _context.next = 16;
return _context5.next = 14, serialiseObject(node, nodeType, key, data, method);
case 14:
data = _context5.sent, _context5.next = 28;
break;
case 15:
throw new Error(requiresID(method, key));
case 17:
if (!(null !== node && Array.isArray(node))) {
_context5.next = 23;
break;
}
case 16:
_context.next = 19;
return _context5.next = 20, serialiseArray(node, nodeType, key, data, method);
case 20:
data = _context5.sent, _context5.next = 28;
break;
case 18:
null !== obj[key] && Array.isArray(obj[key]) ? (keytype = this.plural(this.camel(key)), data.relationships || (data.relationships = {}), data.relationships[key] = {
data: obj[key].map(elem => {
if (!elem.id) throw new Error(requiresID(method, key));
return {
id: elem.id,
type: elem.type || keytype
};
})
}) : 'id' !== key && 'type' !== key && (data.attributes || (data.attributes = {}), data.attributes[key] = obj[key]);
case 23:
if (_context5.t2 = 'id' !== key && 'type' !== key, !_context5.t2) {
_context5.next = 28;
break;
}
case 19:
_context.next = 8;
return _context5.next = 27, serialiseAttr(node, key, data);
case 27:
data = _context5.sent;
case 28:
_context5.next = 8;
break;
case 21:
return _context.abrupt("return", {
case 30:
return _context5.abrupt("return", {
data
});
case 24:
throw _context.prev = 24, _context.t2 = _context["catch"](1), error(_context.t2);
case 33:
throw _context5.prev = 33, _context5.t3 = _context5["catch"](1), error(_context5.t3);
case 27:
case 36:
case "end":
return _context.stop();
return _context5.stop();
}
}, _callee, this, [[1, 24]]);
}, _callee5, this, [[1, 33]]);
})), _serialise.apply(this, arguments);

@@ -529,0 +627,0 @@ }

@@ -184,2 +184,57 @@ 'use strict';

function isValid() {
return _isValid.apply(this, arguments);
}
function _isValid() {
return _isValid = _asyncToGenerator(function* (obj, method, type) {
if (obj.constructor !== Object || 0 === Object.keys(obj).length) throw new Error(`${method} requires a JSON object body`);
if ('POST' !== method && !obj.id) throw new Error(`${method} requires an ID for the ${type} type`);
}), _isValid.apply(this, arguments);
}
function serialiseObject() {
return _serialiseObject.apply(this, arguments);
}
function _serialiseObject() {
return _serialiseObject = _asyncToGenerator(function* (node, nodeType, key, data, method) {
if ('string' !== typeof node.id) throw new Error(requiresID(method, key));
return data.relationships || (data.relationships = {}), node.type || (node.type = nodeType), data.relationships[key] = {
data: Object.assign(node)
}, data;
}), _serialiseObject.apply(this, arguments);
}
function serialiseArray() {
return _serialiseArray.apply(this, arguments);
}
function _serialiseArray() {
return _serialiseArray = _asyncToGenerator(function* (node, nodeType, key, data, method) {
return data.relationships || (data.relationships = {}), data.relationships[key] = {
data: node.map(({
id,
type
}) => {
if (!id) throw new Error(requiresID(method, key));
return {
id,
type: type || nodeType
};
})
}, data;
}), _serialiseArray.apply(this, arguments);
}
function serialiseAttr() {
return _serialiseAttr.apply(this, arguments);
}
function _serialiseAttr() {
return _serialiseAttr = _asyncToGenerator(function* (node, key, data) {
return data.attributes || (data.attributes = {}), data.attributes[key] = node, data;
}), _serialiseAttr.apply(this, arguments);
}
function serialise() {

@@ -192,25 +247,12 @@ return _serialise.apply(this, arguments);

try {
if (obj.constructor !== Object || 0 === Object.keys(obj).length) throw new Error(`${method} requires a JSON object body`);
const type = this.plural(this.camel(model)),
data = {
const type = this.plural(this.camel(model));
let data = {
type
};
if ('POST' !== method && !obj.id) throw new Error(`${method} requires an ID for the ${type} type`);
for (let key in 'POST' !== method && (data.id = obj.id.toString()), obj) if (null !== obj[key] && obj[key].constructor === Object) {
if ('string' === typeof obj[key].id) data.relationships || (data.relationships = {}), obj[key].type || (obj[key].type = this.plural(this.camel(key))), data.relationships[key] = {
data: Object.assign(obj[key])
};else throw new Error(requiresID(method, key));
} else if (null !== obj[key] && Array.isArray(obj[key])) {
const keytype = this.plural(this.camel(key));
data.relationships || (data.relationships = {}), data.relationships[key] = {
data: obj[key].map(elem => {
if (!elem.id) throw new Error(requiresID(method, key));
return {
id: elem.id,
type: elem.type || keytype
};
})
};
} else 'id' !== key && 'type' !== key && (data.attributes || (data.attributes = {}), data.attributes[key] = obj[key]);
for (let key in yield isValid(obj, method, type), 'POST' !== method && (data.id = obj.id + ""), obj) {
const node = obj[key],
nodeType = this.plural(this.camel(key));
null !== node & node.constructor === Object ? data = yield serialiseObject(node, nodeType, key, data, method) : null !== node && Array.isArray(node) ? data = yield serialiseArray(node, nodeType, key, data, method) : 'id' !== key && 'type' !== key && (data = yield serialiseAttr(node, key, data));
}

@@ -217,0 +259,0 @@ return {

{
"version": "6.2.1",
"version": "6.2.2",
"name": "kitsu-core",

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

],
"gitHead": "c284051ebccbf2e26423505ff6011d2cf0249422"
"gitHead": "245d1b8d3183bbee1eb8457307ccd84d71584027"
}

@@ -99,13 +99,15 @@ <h1 align=center>Kitsu Core</h1>

- [Parameters](#parameters-6)
- [isValid](#isvalid)
- [Parameters](#parameters-7)
- [serialise](#serialise)
- [Parameters](#parameters-7)
- [Parameters](#parameters-8)
- [Examples](#examples-2)
- [camel](#camel)
- [Parameters](#parameters-8)
- [Parameters](#parameters-9)
- [Examples](#examples-3)
- [kebab](#kebab)
- [Parameters](#parameters-9)
- [Parameters](#parameters-10)
- [Examples](#examples-4)
- [snake](#snake)
- [Parameters](#parameters-10)
- [Parameters](#parameters-11)
- [Examples](#examples-5)

@@ -115,3 +117,3 @@

[packages/kitsu-core/src/deattribute/index.js:29-38](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/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/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/deattribute/index.js#L29-L38 "Source code on GitHub")

@@ -158,3 +160,3 @@ Hoists attributes to be top-level

[packages/kitsu-core/src/deserialise/index.js:56-70](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/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/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/deserialise/index.js#L56-L70 "Source code on GitHub")

@@ -209,3 +211,3 @@ Deserialises a JSON-API response

[packages/kitsu-core/src/error/index.js:7-13](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/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/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/error/index.js#L7-L13 "Source code on GitHub")

@@ -223,3 +225,3 @@ Mutates an error and rethrows it

[packages/kitsu-core/src/filterIncludes/index.js:12-21](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/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/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/filterIncludes/index.js#L12-L21 "Source code on GitHub")

@@ -239,3 +241,3 @@ Filters includes for the specific relationship

[packages/kitsu-core/src/linkRelationships/index.js:55-74](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/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/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/linkRelationships/index.js#L55-L74 "Source code on GitHub")

@@ -251,3 +253,3 @@ Links relationships to included data

[packages/kitsu-core/src/query/index.js:8-11](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/packages/kitsu-core/src/query/index.js#L8-L11 "Source code on GitHub")
[packages/kitsu-core/src/query/index.js:8-11](https://github.com/wopian/kitsu/blob/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/query/index.js#L8-L11 "Source code on GitHub")

@@ -265,3 +267,3 @@ Formats a single URL query

[packages/kitsu-core/src/query/index.js:20-31](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/packages/kitsu-core/src/query/index.js#L20-L31 "Source code on GitHub")
[packages/kitsu-core/src/query/index.js:20-31](https://github.com/wopian/kitsu/blob/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/query/index.js#L20-L31 "Source code on GitHub")

@@ -277,5 +279,17 @@ Constructs a URL query string for JSON:API parameters

### isValid
[packages/kitsu-core/src/serialise/index.js:11-20](https://github.com/wopian/kitsu/blob/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/serialise/index.js#L11-L20 "Source code on GitHub")
Checks if data is valid for serialisation
#### Parameters
- `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The data
- `method` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Request type
- `type`
### serialise
[packages/kitsu-core/src/serialise/index.js:19-69](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/packages/kitsu-core/src/serialise/index.js#L19-L69 "Source code on GitHub")
[packages/kitsu-core/src/serialise/index.js:67-92](https://github.com/wopian/kitsu/blob/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/serialise/index.js#L67-L92 "Source code on GitHub")

@@ -292,3 +306,3 @@ Serialises an object into a JSON-API structure

_Due to its usage in kitsu, it **MUST** be called with **this** set in 5.0.x_
_Due to its usage in kitsu, it **MUST** be called with **this** set in 6.0.x_

@@ -306,3 +320,3 @@ ```javascript

[packages/kitsu-core/src/camel/index.js:14-14](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/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/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/camel/index.js#L14-L14 "Source code on GitHub")

@@ -333,3 +347,3 @@ Converts kebab-case and snake_case into camelCase

[packages/kitsu-core/src/kebab/index.js:11-11](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/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/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/kebab/index.js#L11-L11 "Source code on GitHub")

@@ -352,3 +366,3 @@ Converts camelCase into kebab-case

[packages/kitsu-core/src/snake/index.js:11-11](https://github.com/wopian/kitsu/blob/867d16095d854d692bb7b126dba177eedba3b1f9/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/593b2aff50a25b6e9a5909a0badec4c8f5cf3078/packages/kitsu-core/src/snake/index.js#L11-L11 "Source code on GitHub")

@@ -355,0 +369,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

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