kitsu-core
Advanced tools
Comparing version 6.4.0 to 7.0.0
@@ -6,2 +6,50 @@ # Change Log | ||
# [7.0.0](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/compare/v6.2.3...v7.0.0) (2019-03-02) | ||
### Bug Fixes | ||
* **ci:** remove node-only packages ([467e501](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/467e501)) | ||
* **kitsu-core:** change & to && ([#268](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/issues/268)) ([7195a39](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/7195a39)) | ||
### Build System / Dependencies | ||
* update dependency babel to ^7.0.0 ([81f6be2](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/81f6be2)) | ||
### Chores | ||
* **release:** update documentation ([4421b82](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/4421b82)) | ||
* drop support for node 6 ([7e48c42](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/7e48c42)) | ||
* **release:** publish packages ([4ef5cd2](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/4ef5cd2)) | ||
* **release:** publish packages ([52c4b5d](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/52c4b5d)) | ||
* **release:** publish packages ([3c84631](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/3c84631)) | ||
* **release:** update documentation ([12d3b6e](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/12d3b6e)) | ||
* **release:** update documentation ([4fd20c5](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/4fd20c5)) | ||
* **release:** update documentation ([c59db70](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/c59db70)) | ||
### Documentation Changes | ||
* update package sizes ([07d2aca](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/07d2aca)) | ||
* **kitsu-core:** mark internal functions as private ([7d8cff1](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/7d8cff1)) | ||
* switch david-dm badges to badgen ([8172616](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/8172616)) | ||
### New Features | ||
* add generated typescript declarations ([0cac34d](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/0cac34d)) | ||
* split kitsu-core/node into kitsu-core ([ccaee90](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/commit/ccaee90)) | ||
### BREAKING CHANGES | ||
* Brings native async/await for kitsu/node and kitsu-core/node | ||
# [6.4.0](https://github.com/wopian/kitsu/tree/master/packages/kitsu-core/compare/kitsu-core@6.3.1...kitsu-core@6.4.0) (2018-09-08) | ||
@@ -8,0 +56,0 @@ |
851
lib/index.js
@@ -8,60 +8,45 @@ 'use strict'; | ||
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator')); | ||
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator')); | ||
function deattribute() { | ||
return _deattribute.apply(this, arguments); | ||
} | ||
function deattribute(data) { | ||
return _regeneratorRuntime.async(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (_context2.t0 = 'object' === typeof data && null !== data, !_context2.t0) { | ||
_context2.next = 8; | ||
break; | ||
} | ||
function _deattribute() { | ||
return _deattribute = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data) { | ||
return _regeneratorRuntime.wrap(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (_context2.t0 = 'object' === typeof data && null !== data, !_context2.t0) { | ||
_context2.next = 8; | ||
break; | ||
} | ||
if (!Array.isArray(data)) { | ||
_context2.next = 7; | ||
break; | ||
} | ||
if (!Array.isArray(data)) { | ||
_context2.next = 7; | ||
break; | ||
return _context2.next = 5, _regeneratorRuntime.awrap(data.map(el => _regeneratorRuntime.async(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", deattribute(el)); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, null, this))); | ||
return _context2.next = 5, data.map(function () { | ||
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(el) { | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", deattribute(el)); | ||
case 5: | ||
_context2.next = 8; | ||
break; | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
})); | ||
case 7: | ||
data.attributes && data.attributes.constructor === Object && (Object.keys(data.attributes).forEach(key => { | ||
data[key] = data.attributes[key]; | ||
}), delete data.attributes); | ||
return function () { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
case 8: | ||
return _context2.abrupt("return", data); | ||
case 5: | ||
_context2.next = 8; | ||
break; | ||
case 7: | ||
data.attributes && data.attributes.constructor === Object && (Object.keys(data.attributes).forEach(key => { | ||
data[key] = data.attributes[key]; | ||
}), delete data.attributes); | ||
case 8: | ||
return _context2.abrupt("return", data); | ||
case 9: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this); | ||
})), _deattribute.apply(this, arguments); | ||
case 9: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, null, this); | ||
} | ||
@@ -78,341 +63,299 @@ | ||
function filterIncludes() { | ||
return _filterIncludes.apply(this, arguments); | ||
} | ||
function filterIncludes(included, _ref) { | ||
var id, type, filtered; | ||
return _regeneratorRuntime.async(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return id = _ref.id, type = _ref.type, _context.prev = 1, filtered = included.filter(el => el.id === id && el.type === type)[0] || { | ||
id, | ||
type | ||
}, _context.abrupt("return", Object.assign({}, filtered)); | ||
function _filterIncludes() { | ||
return _filterIncludes = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(included, _ref) { | ||
var id, type, filtered; | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return id = _ref.id, type = _ref.type, _context.prev = 1, filtered = included.filter(el => el.id === id && el.type === type)[0] || { | ||
id, | ||
type | ||
}, _context.abrupt("return", Object.assign({}, filtered)); | ||
case 6: | ||
_context.prev = 6, _context.t0 = _context["catch"](1), error(_context.t0); | ||
case 6: | ||
_context.prev = 6, _context.t0 = _context["catch"](1), error(_context.t0); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this, [[1, 6]]); | ||
})), _filterIncludes.apply(this, arguments); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, null, this, [[1, 6]]); | ||
} | ||
function link() { | ||
return _link.apply(this, arguments); | ||
} | ||
function link(_ref, included) { | ||
var id, type, meta, filtered; | ||
return _regeneratorRuntime.async(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return id = _ref.id, type = _ref.type, meta = _ref.meta, _context.next = 3, _regeneratorRuntime.awrap(filterIncludes(included, { | ||
id, | ||
type | ||
})); | ||
function _link() { | ||
return _link = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_ref, included) { | ||
var id, type, meta, filtered; | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return id = _ref.id, type = _ref.type, meta = _ref.meta, _context.next = 3, filterIncludes(included, { | ||
id, | ||
type | ||
}); | ||
case 3: | ||
if (filtered = _context.sent, _context.t0 = filtered.relationships, !_context.t0) { | ||
_context.next = 8; | ||
break; | ||
} | ||
case 3: | ||
if (filtered = _context.sent, _context.t0 = filtered.relationships, !_context.t0) { | ||
_context.next = 8; | ||
break; | ||
} | ||
return _context.next = 8, _regeneratorRuntime.awrap(linkRelationships(filtered, included)); | ||
return _context.next = 8, linkRelationships(filtered, included); | ||
case 8: | ||
return meta && (filtered.meta = meta), _context.abrupt("return", deattribute(filtered)); | ||
case 8: | ||
return meta && (filtered.meta = meta), _context.abrupt("return", deattribute(filtered)); | ||
case 10: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
})), _link.apply(this, arguments); | ||
case 10: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, null, this); | ||
} | ||
function linkArray() { | ||
return _linkArray.apply(this, arguments); | ||
} | ||
function linkArray(data, included, key) { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _step, _iterator, resource; | ||
function _linkArray() { | ||
return _linkArray = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data, included, key) { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _step, _iterator, resource; | ||
return _regeneratorRuntime.async(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
return data[key] = [], _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0, _context2.prev = 2, _context2.next = 5, _regeneratorRuntime.awrap(data.relationships[key].data); | ||
return _regeneratorRuntime.wrap(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
return data[key] = [], _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0, _context2.prev = 2, _context2.next = 5, data.relationships[key].data; | ||
case 5: | ||
_context2.t0 = Symbol.iterator, _iterator = _context2.sent[_context2.t0](); | ||
case 5: | ||
_context2.t0 = Symbol.iterator, _iterator = _context2.sent[_context2.t0](); | ||
case 7: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context2.next = 17; | ||
break; | ||
} | ||
case 7: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context2.next = 17; | ||
break; | ||
} | ||
return resource = _step.value, _context2.t1 = data[key], _context2.next = 12, _regeneratorRuntime.awrap(link(resource, included)); | ||
return resource = _step.value, _context2.t1 = data[key], _context2.next = 12, link(resource, included); | ||
case 12: | ||
_context2.t2 = _context2.sent, _context2.t1.push.call(_context2.t1, _context2.t2); | ||
case 12: | ||
_context2.t2 = _context2.sent, _context2.t1.push.call(_context2.t1, _context2.t2); | ||
case 14: | ||
_iteratorNormalCompletion = !0, _context2.next = 7; | ||
break; | ||
case 14: | ||
_iteratorNormalCompletion = !0, _context2.next = 7; | ||
break; | ||
case 17: | ||
_context2.next = 22; | ||
break; | ||
case 17: | ||
_context2.next = 22; | ||
break; | ||
case 19: | ||
_context2.prev = 19, _context2.t3 = _context2["catch"](2), _didIteratorError = !0, _iteratorError = _context2.t3; | ||
case 19: | ||
_context2.prev = 19, _context2.t3 = _context2["catch"](2), _didIteratorError = !0, _iteratorError = _context2.t3; | ||
case 22: | ||
_context2.prev = 22, _context2.prev = 23, _iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
case 22: | ||
_context2.prev = 22, _context2.prev = 23, _iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
case 25: | ||
if (_context2.prev = 25, !_didIteratorError) { | ||
_context2.next = 28; | ||
break; | ||
} | ||
case 25: | ||
if (_context2.prev = 25, !_didIteratorError) { | ||
_context2.next = 28; | ||
break; | ||
} | ||
throw _iteratorError; | ||
throw _iteratorError; | ||
case 28: | ||
return _context2.finish(25); | ||
case 28: | ||
return _context2.finish(25); | ||
case 29: | ||
return _context2.finish(22); | ||
case 29: | ||
return _context2.finish(22); | ||
case 30: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this, [[2, 19, 22, 30], [23,, 25, 29]]); | ||
})), _linkArray.apply(this, arguments); | ||
case 30: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, null, this, [[2, 19, 22, 30], [23,, 25, 29]]); | ||
} | ||
function linkObject() { | ||
return _linkObject.apply(this, arguments); | ||
} | ||
function linkObject(data, included, key) { | ||
return _regeneratorRuntime.async(function (_context3) { | ||
for (;;) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context3.next = 2, _regeneratorRuntime.awrap(link(data.relationships[key].data, included)); | ||
function _linkObject() { | ||
return _linkObject = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(data, included, key) { | ||
return _regeneratorRuntime.wrap(function (_context3) { | ||
for (;;) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context3.next = 2, link(data.relationships[key].data, included); | ||
case 2: | ||
data[key] = _context3.sent, delete data[key].relationships; | ||
case 2: | ||
data[key] = _context3.sent, delete data[key].relationships; | ||
case 4: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3, this); | ||
})), _linkObject.apply(this, arguments); | ||
case 4: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, null, this); | ||
} | ||
function linkRelationships() { | ||
return _linkRelationships.apply(this, arguments); | ||
} | ||
function linkRelationships(data, included) { | ||
var relationships, removeRelationships, key; | ||
return _regeneratorRuntime.async(function (_context4) { | ||
for (;;) switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return relationships = data.relationships, removeRelationships = !1, _context4.next = 4, _regeneratorRuntime.awrap(relationships); | ||
function _linkRelationships() { | ||
return _linkRelationships = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(data, included) { | ||
var relationships, removeRelationships, key; | ||
return _regeneratorRuntime.wrap(function (_context4) { | ||
for (;;) switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return relationships = data.relationships, removeRelationships = !1, _context4.next = 4, relationships; | ||
case 4: | ||
_context4.t0 = _regeneratorRuntime.keys(_context4.sent); | ||
case 4: | ||
_context4.t0 = _regeneratorRuntime.keys(_context4.sent); | ||
case 5: | ||
if ((_context4.t1 = _context4.t0()).done) { | ||
_context4.next = 20; | ||
break; | ||
} | ||
case 5: | ||
if ((_context4.t1 = _context4.t0()).done) { | ||
_context4.next = 20; | ||
break; | ||
} | ||
if (key = _context4.t1.value, !(relationships[key].data && Array.isArray(relationships[key].data))) { | ||
_context4.next = 13; | ||
break; | ||
} | ||
if (key = _context4.t1.value, !(relationships[key].data && Array.isArray(relationships[key].data))) { | ||
_context4.next = 13; | ||
break; | ||
} | ||
return _context4.next = 10, _regeneratorRuntime.awrap(linkArray(data, included, key)); | ||
return _context4.next = 10, linkArray(data, included, key); | ||
case 10: | ||
removeRelationships = !0, _context4.next = 18; | ||
break; | ||
case 10: | ||
removeRelationships = !0, _context4.next = 18; | ||
case 13: | ||
if (_context4.t2 = relationships[key].data, !_context4.t2) { | ||
_context4.next = 18; | ||
break; | ||
} | ||
case 13: | ||
if (_context4.t2 = relationships[key].data, !_context4.t2) { | ||
_context4.next = 18; | ||
break; | ||
} | ||
return _context4.next = 17, _regeneratorRuntime.awrap(linkObject(data, included, key)); | ||
return _context4.next = 17, linkObject(data, included, key); | ||
case 17: | ||
removeRelationships = !0; | ||
case 17: | ||
removeRelationships = !0; | ||
case 18: | ||
_context4.next = 5; | ||
break; | ||
case 18: | ||
_context4.next = 5; | ||
break; | ||
case 20: | ||
return _context4.abrupt("return", (removeRelationships && delete data.relationships, data)); | ||
case 20: | ||
return _context4.abrupt("return", (removeRelationships && delete data.relationships, data)); | ||
case 21: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, _callee4, this); | ||
})), _linkRelationships.apply(this, arguments); | ||
case 21: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, null, this); | ||
} | ||
function deserialiseArray() { | ||
return _deserialiseArray.apply(this, arguments); | ||
} | ||
function deserialiseArray(obj) { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _step, _iterator, value; | ||
function _deserialiseArray() { | ||
return _deserialiseArray = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(obj) { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _step, _iterator, value; | ||
return _regeneratorRuntime.async(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0, _context.prev = 1, _context.next = 4, _regeneratorRuntime.awrap(obj.data); | ||
return _regeneratorRuntime.wrap(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0, _context.prev = 1, _context.next = 4, obj.data; | ||
case 4: | ||
_context.t0 = Symbol.iterator, _iterator = _context.sent[_context.t0](); | ||
case 4: | ||
_context.t0 = Symbol.iterator, _iterator = _context.sent[_context.t0](); | ||
case 6: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context.next = 22; | ||
break; | ||
} | ||
case 6: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context.next = 22; | ||
break; | ||
} | ||
if (value = _step.value, _context.t1 = obj.included, !_context.t1) { | ||
_context.next = 13; | ||
break; | ||
} | ||
if (value = _step.value, _context.t1 = obj.included, !_context.t1) { | ||
_context.next = 13; | ||
break; | ||
} | ||
return _context.next = 12, _regeneratorRuntime.awrap(linkRelationships(value, obj.included)); | ||
return _context.next = 12, linkRelationships(value, obj.included); | ||
case 12: | ||
value = _context.sent; | ||
case 12: | ||
value = _context.sent; | ||
case 13: | ||
if (_context.t2 = value.attributes, !_context.t2) { | ||
_context.next = 18; | ||
break; | ||
} | ||
case 13: | ||
if (_context.t2 = value.attributes, !_context.t2) { | ||
_context.next = 18; | ||
break; | ||
} | ||
return _context.next = 17, _regeneratorRuntime.awrap(deattribute(value)); | ||
return _context.next = 17, deattribute(value); | ||
case 17: | ||
value = _context.sent; | ||
case 17: | ||
value = _context.sent; | ||
case 18: | ||
obj.data[obj.data.indexOf(value)] = value; | ||
case 18: | ||
obj.data[obj.data.indexOf(value)] = value; | ||
case 19: | ||
_iteratorNormalCompletion = !0, _context.next = 6; | ||
break; | ||
case 19: | ||
_iteratorNormalCompletion = !0, _context.next = 6; | ||
break; | ||
case 22: | ||
_context.next = 27; | ||
break; | ||
case 22: | ||
_context.next = 27; | ||
break; | ||
case 24: | ||
_context.prev = 24, _context.t3 = _context["catch"](1), _didIteratorError = !0, _iteratorError = _context.t3; | ||
case 24: | ||
_context.prev = 24, _context.t3 = _context["catch"](1), _didIteratorError = !0, _iteratorError = _context.t3; | ||
case 27: | ||
_context.prev = 27, _context.prev = 28, _iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
case 27: | ||
_context.prev = 27, _context.prev = 28, _iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
case 30: | ||
if (_context.prev = 30, !_didIteratorError) { | ||
_context.next = 33; | ||
break; | ||
} | ||
case 30: | ||
if (_context.prev = 30, !_didIteratorError) { | ||
_context.next = 33; | ||
break; | ||
} | ||
throw _iteratorError; | ||
throw _iteratorError; | ||
case 33: | ||
return _context.finish(30); | ||
case 33: | ||
return _context.finish(30); | ||
case 34: | ||
return _context.finish(27); | ||
case 34: | ||
return _context.finish(27); | ||
case 35: | ||
return _context.abrupt("return", obj); | ||
case 35: | ||
return _context.abrupt("return", obj); | ||
case 36: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this, [[1, 24, 27, 35], [28,, 30, 34]]); | ||
})), _deserialiseArray.apply(this, arguments); | ||
case 36: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, null, this, [[1, 24, 27, 35], [28,, 30, 34]]); | ||
} | ||
function deserialise() { | ||
return _deserialise.apply(this, arguments); | ||
} | ||
function deserialise(obj) { | ||
return _regeneratorRuntime.async(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (!(obj.data && obj.data.constructor === Array)) { | ||
_context2.next = 6; | ||
break; | ||
} | ||
function _deserialise() { | ||
return _deserialise = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(obj) { | ||
return _regeneratorRuntime.wrap(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (!(obj.data && obj.data.constructor === Array)) { | ||
_context2.next = 6; | ||
break; | ||
} | ||
return _context2.next = 3, _regeneratorRuntime.awrap(deserialiseArray(obj)); | ||
return _context2.next = 3, deserialiseArray(obj); | ||
case 3: | ||
obj = _context2.sent, _context2.next = 11; | ||
break; | ||
case 3: | ||
obj = _context2.sent, _context2.next = 11; | ||
case 6: | ||
if (_context2.t0 = obj.included, !_context2.t0) { | ||
_context2.next = 11; | ||
break; | ||
} | ||
case 6: | ||
if (_context2.t0 = obj.included, !_context2.t0) { | ||
_context2.next = 11; | ||
break; | ||
} | ||
return _context2.next = 10, _regeneratorRuntime.awrap(linkRelationships(obj.data, obj.included)); | ||
return _context2.next = 10, linkRelationships(obj.data, obj.included); | ||
case 10: | ||
obj.data = _context2.sent; | ||
case 10: | ||
obj.data = _context2.sent; | ||
case 11: | ||
if (delete obj.included, _context2.t1 = obj.data && obj.data.attributes, !_context2.t1) { | ||
_context2.next = 17; | ||
break; | ||
} | ||
case 11: | ||
if (delete obj.included, _context2.t1 = obj.data && obj.data.attributes, !_context2.t1) { | ||
_context2.next = 17; | ||
break; | ||
} | ||
return _context2.next = 16, _regeneratorRuntime.awrap(deattribute(obj.data)); | ||
return _context2.next = 16, deattribute(obj.data); | ||
case 16: | ||
obj.data = _context2.sent; | ||
case 16: | ||
obj.data = _context2.sent; | ||
case 17: | ||
return _context2.abrupt("return", obj); | ||
case 17: | ||
return _context2.abrupt("return", obj); | ||
case 18: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this); | ||
})), _deserialise.apply(this, arguments); | ||
case 18: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, null, this); | ||
} | ||
@@ -435,193 +378,163 @@ | ||
function isValid() { | ||
return _isValid.apply(this, arguments); | ||
} | ||
function isValid(obj, method, type) { | ||
return _regeneratorRuntime.async(function (_context) { | ||
for (;;) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (obj.constructor === Object && 0 !== Object.keys(obj).length) { | ||
_context.next = 2; | ||
break; | ||
} | ||
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.constructor === Object && 0 !== Object.keys(obj).length) { | ||
_context.next = 2; | ||
break; | ||
} | ||
throw new Error(`${method} requires a JSON object body`); | ||
throw new Error(`${method} requires a JSON object body`); | ||
case 2: | ||
if ('POST' === method || obj.id) { | ||
_context.next = 4; | ||
break; | ||
} | ||
case 2: | ||
if ('POST' === method || obj.id) { | ||
_context.next = 4; | ||
break; | ||
} | ||
throw new Error(`${method} requires an ID for the ${type} type`); | ||
throw new Error(`${method} requires an ID for the ${type} type`); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
})), _isValid.apply(this, arguments); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, null, this); | ||
} | ||
function serialiseObject() { | ||
return _serialiseObject.apply(this, arguments); | ||
} | ||
function serialiseObject(node, nodeType, key, data, method) { | ||
return _regeneratorRuntime.async(function (_context2) { | ||
for (;;) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if ('string' === typeof node.id) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
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; | ||
} | ||
throw new Error(requiresID(method, key)); | ||
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 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); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, null, this); | ||
} | ||
function serialiseArray() { | ||
return _serialiseArray.apply(this, arguments); | ||
} | ||
function serialiseArray(node, nodeType, key, data, method) { | ||
return _regeneratorRuntime.async(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)); | ||
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); | ||
case 1: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, null, this); | ||
} | ||
function serialiseAttr() { | ||
return _serialiseAttr.apply(this, arguments); | ||
} | ||
function serialiseAttr(node, key, data) { | ||
return _regeneratorRuntime.async(function (_context4) { | ||
for (;;) switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return _context4.abrupt("return", (data.attributes || (data.attributes = {}), data.attributes[key] = node, data)); | ||
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); | ||
case 1: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, null, this); | ||
} | ||
function serialise() { | ||
return _serialise.apply(this, arguments); | ||
} | ||
function serialise(model) { | ||
var obj, | ||
method, | ||
type, | ||
data, | ||
key, | ||
node, | ||
nodeType, | ||
_args5 = arguments; | ||
return _regeneratorRuntime.async(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, _regeneratorRuntime.awrap(isValid(obj, method, type)); | ||
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 6: | ||
'POST' !== method && (data.id = obj.id + ""), _context5.t0 = _regeneratorRuntime.keys(obj); | ||
case 8: | ||
if ((_context5.t1 = _context5.t0()).done) { | ||
_context5.next = 30; | ||
break; | ||
} | ||
case 8: | ||
if ((_context5.t1 = _context5.t0()).done) { | ||
_context5.next = 30; | ||
break; | ||
} | ||
if (key = _context5.t1.value, node = obj[key], nodeType = this.plural(this.camel(key)), null === node || node.constructor !== Object) { | ||
_context5.next = 17; | ||
break; | ||
} | ||
if (key = _context5.t1.value, node = obj[key], nodeType = this.plural(this.camel(key)), !(null !== node & node.constructor === Object)) { | ||
_context5.next = 17; | ||
break; | ||
} | ||
return _context5.next = 14, _regeneratorRuntime.awrap(serialiseObject(node, nodeType, key, data, method)); | ||
return _context5.next = 14, serialiseObject(node, nodeType, key, data, method); | ||
case 14: | ||
data = _context5.sent, _context5.next = 28; | ||
break; | ||
case 14: | ||
data = _context5.sent, _context5.next = 28; | ||
case 17: | ||
if (!(null !== node && Array.isArray(node))) { | ||
_context5.next = 23; | ||
break; | ||
} | ||
case 17: | ||
if (!(null !== node && Array.isArray(node))) { | ||
_context5.next = 23; | ||
break; | ||
} | ||
return _context5.next = 20, _regeneratorRuntime.awrap(serialiseArray(node, nodeType, key, data, method)); | ||
return _context5.next = 20, serialiseArray(node, nodeType, key, data, method); | ||
case 20: | ||
data = _context5.sent, _context5.next = 28; | ||
break; | ||
case 20: | ||
data = _context5.sent, _context5.next = 28; | ||
case 23: | ||
if (_context5.t2 = 'id' !== key && 'type' !== key, !_context5.t2) { | ||
_context5.next = 28; | ||
break; | ||
} | ||
case 23: | ||
if (_context5.t2 = 'id' !== key && 'type' !== key, !_context5.t2) { | ||
_context5.next = 28; | ||
break; | ||
} | ||
return _context5.next = 27, _regeneratorRuntime.awrap(serialiseAttr(node, key, data)); | ||
return _context5.next = 27, serialiseAttr(node, key, data); | ||
case 27: | ||
data = _context5.sent; | ||
case 27: | ||
data = _context5.sent; | ||
case 28: | ||
_context5.next = 8; | ||
break; | ||
case 28: | ||
_context5.next = 8; | ||
break; | ||
case 30: | ||
return _context5.abrupt("return", { | ||
data | ||
}); | ||
case 30: | ||
return _context5.abrupt("return", { | ||
data | ||
}); | ||
case 33: | ||
throw _context5.prev = 33, _context5.t3 = _context5["catch"](1), error(_context5.t3); | ||
case 33: | ||
throw _context5.prev = 33, _context5.t3 = _context5["catch"](1), error(_context5.t3); | ||
case 36: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
}, _callee5, this, [[1, 33]]); | ||
})), _serialise.apply(this, arguments); | ||
case 36: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
}, null, this, [[1, 33]]); | ||
} | ||
@@ -628,0 +541,0 @@ |
@@ -5,26 +5,8 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator')); | ||
function deattribute() { | ||
return _deattribute.apply(this, arguments); | ||
async function deattribute(data) { | ||
return 'object' === typeof data && null !== data && (Array.isArray(data) ? await data.map(async el => deattribute(el)) : data.attributes && data.attributes.constructor === Object && (Object.keys(data.attributes).forEach(key => { | ||
data[key] = data.attributes[key]; | ||
}), delete data.attributes)), data; | ||
} | ||
function _deattribute() { | ||
return _deattribute = _asyncToGenerator(function* (data) { | ||
return 'object' === typeof data && null !== data && (Array.isArray(data) ? yield data.map(function () { | ||
var _ref = _asyncToGenerator(function* (el) { | ||
return deattribute(el); | ||
}); | ||
return function () { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()) : data.attributes && data.attributes.constructor === Object && (Object.keys(data.attributes).forEach(key => { | ||
data[key] = data.attributes[key]; | ||
}), delete data.attributes)), data; | ||
}), _deattribute.apply(this, arguments); | ||
} | ||
function error(E) { | ||
@@ -39,134 +21,60 @@ if (E.response) { | ||
function filterIncludes() { | ||
return _filterIncludes.apply(this, arguments); | ||
async function filterIncludes(included, { | ||
id, | ||
type | ||
}) { | ||
try { | ||
const filtered = included.filter(el => el.id === id && el.type === type)[0] || { | ||
id, | ||
type | ||
}; | ||
return Object.assign({}, filtered); | ||
} catch (E) { | ||
error(E); | ||
} | ||
} | ||
function _filterIncludes() { | ||
return _filterIncludes = _asyncToGenerator(function* (included, { | ||
async function link({ | ||
id, | ||
type, | ||
meta | ||
}, included) { | ||
const filtered = await filterIncludes(included, { | ||
id, | ||
type | ||
}) { | ||
try { | ||
const filtered = included.filter(el => el.id === id && el.type === type)[0] || { | ||
id, | ||
type | ||
}; | ||
return Object.assign({}, filtered); | ||
} catch (E) { | ||
error(E); | ||
} | ||
}), _filterIncludes.apply(this, arguments); | ||
}); | ||
return filtered.relationships && (await linkRelationships(filtered, included)), meta && (filtered.meta = meta), deattribute(filtered); | ||
} | ||
function link() { | ||
return _link.apply(this, arguments); | ||
} | ||
async function linkArray(data, included, key) { | ||
data[key] = []; | ||
function _link() { | ||
return _link = _asyncToGenerator(function* ({ | ||
id, | ||
type, | ||
meta | ||
}, included) { | ||
const filtered = yield filterIncludes(included, { | ||
id, | ||
type | ||
}); | ||
return filtered.relationships && (yield linkRelationships(filtered, included)), meta && (filtered.meta = meta), deattribute(filtered); | ||
}), _link.apply(this, arguments); | ||
for (let resource of await data.relationships[key].data) data[key].push((await link(resource, included))); | ||
} | ||
function linkArray() { | ||
return _linkArray.apply(this, arguments); | ||
async function linkObject(data, included, key) { | ||
data[key] = await link(data.relationships[key].data, included), delete data[key].relationships; | ||
} | ||
function _linkArray() { | ||
return _linkArray = _asyncToGenerator(function* (data, included, key) { | ||
data[key] = []; | ||
async function linkRelationships(data, included) { | ||
const { | ||
relationships | ||
} = data; | ||
let removeRelationships = !1; | ||
var _iteratorNormalCompletion = !0, | ||
_didIteratorError = !1, | ||
_iteratorError = void 0; | ||
for (let key in await relationships) relationships[key].data && Array.isArray(relationships[key].data) ? (await linkArray(data, included, key), removeRelationships = !0) : relationships[key].data && (await linkObject(data, included, key), removeRelationships = !0); | ||
try { | ||
for (var _step, _iterator = (yield data.relationships[key].data)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) { | ||
let resource = _step.value; | ||
data[key].push((yield link(resource, included))); | ||
} | ||
} catch (err) { | ||
_didIteratorError = !0, _iteratorError = err; | ||
} finally { | ||
try { | ||
_iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
} finally { | ||
if (_didIteratorError) throw _iteratorError; | ||
} | ||
} | ||
}), _linkArray.apply(this, arguments); | ||
return removeRelationships && delete data.relationships, data; | ||
} | ||
function linkObject() { | ||
return _linkObject.apply(this, arguments); | ||
} | ||
async function deserialiseArray(obj) { | ||
for (let value of await obj.data) obj.included && (value = await linkRelationships(value, obj.included)), value.attributes && (value = await deattribute(value)), obj.data[obj.data.indexOf(value)] = value; | ||
function _linkObject() { | ||
return _linkObject = _asyncToGenerator(function* (data, included, key) { | ||
data[key] = yield link(data.relationships[key].data, included), delete data[key].relationships; | ||
}), _linkObject.apply(this, arguments); | ||
return obj; | ||
} | ||
function linkRelationships() { | ||
return _linkRelationships.apply(this, arguments); | ||
async function deserialise(obj) { | ||
return obj.data && obj.data.constructor === Array ? obj = await deserialiseArray(obj) : obj.included && (obj.data = await linkRelationships(obj.data, obj.included)), delete obj.included, obj.data && obj.data.attributes && (obj.data = await deattribute(obj.data)), obj; | ||
} | ||
function _linkRelationships() { | ||
return _linkRelationships = _asyncToGenerator(function* (data, included) { | ||
const relationships = data.relationships; | ||
let removeRelationships = !1; | ||
for (let key in yield relationships) relationships[key].data && Array.isArray(relationships[key].data) ? (yield linkArray(data, included, key), removeRelationships = !0) : relationships[key].data && (yield linkObject(data, included, key), removeRelationships = !0); | ||
return removeRelationships && delete data.relationships, data; | ||
}), _linkRelationships.apply(this, arguments); | ||
} | ||
function deserialiseArray() { | ||
return _deserialiseArray.apply(this, arguments); | ||
} | ||
function _deserialiseArray() { | ||
return _deserialiseArray = _asyncToGenerator(function* (obj) { | ||
var _iteratorNormalCompletion = !0, | ||
_didIteratorError = !1, | ||
_iteratorError = void 0; | ||
try { | ||
for (var _step, _iterator = (yield obj.data)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) { | ||
let value = _step.value; | ||
obj.included && (value = yield linkRelationships(value, obj.included)), value.attributes && (value = yield deattribute(value)), obj.data[obj.data.indexOf(value)] = value; | ||
} | ||
} catch (err) { | ||
_didIteratorError = !0, _iteratorError = err; | ||
} finally { | ||
try { | ||
_iteratorNormalCompletion || null == _iterator.return || _iterator.return(); | ||
} finally { | ||
if (_didIteratorError) throw _iteratorError; | ||
} | ||
} | ||
return obj; | ||
}), _deserialiseArray.apply(this, arguments); | ||
} | ||
function deserialise() { | ||
return _deserialise.apply(this, arguments); | ||
} | ||
function _deserialise() { | ||
return _deserialise = _asyncToGenerator(function* (obj) { | ||
return obj.data && obj.data.constructor === Array ? obj = yield deserialiseArray(obj) : obj.included && (obj.data = yield linkRelationships(obj.data, obj.included)), delete obj.included, obj.data && obj.data.attributes && (obj.data = yield deattribute(obj.data)), obj; | ||
}), _deserialise.apply(this, arguments); | ||
} | ||
function queryFormat(value, key) { | ||
@@ -186,82 +94,52 @@ return null !== value && 'object' === typeof value ? query(value, key) : encodeURIComponent(key) + '=' + encodeURIComponent(value); | ||
function isValid() { | ||
return _isValid.apply(this, arguments); | ||
async function isValid(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`); | ||
} | ||
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); | ||
async function serialiseObject(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; | ||
} | ||
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(({ | ||
async function serialiseArray(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 | ||
}) => { | ||
if (!id) throw new Error(requiresID(method, key)); | ||
return { | ||
id, | ||
type: type || nodeType | ||
}; | ||
}) | ||
}, data; | ||
}), _serialiseArray.apply(this, arguments); | ||
type: type || nodeType | ||
}; | ||
}) | ||
}, data; | ||
} | ||
function serialiseAttr() { | ||
return _serialiseAttr.apply(this, arguments); | ||
async function serialiseAttr(node, key, data) { | ||
return data.attributes || (data.attributes = {}), data.attributes[key] = node, data; | ||
} | ||
function _serialiseAttr() { | ||
return _serialiseAttr = _asyncToGenerator(function* (node, key, data) { | ||
return data.attributes || (data.attributes = {}), data.attributes[key] = node, data; | ||
}), _serialiseAttr.apply(this, arguments); | ||
} | ||
async function serialise(model, obj = {}, method = 'POST') { | ||
try { | ||
const type = this.plural(this.camel(model)); | ||
let data = { | ||
type | ||
}; | ||
function serialise() { | ||
return _serialise.apply(this, arguments); | ||
} | ||
for (let key in await 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 = await serialiseObject(node, nodeType, key, data, method) : null !== node && Array.isArray(node) ? data = await serialiseArray(node, nodeType, key, data, method) : 'id' !== key && 'type' !== key && (data = await serialiseAttr(node, key, data)); | ||
} | ||
function _serialise() { | ||
return _serialise = _asyncToGenerator(function* (model, obj = {}, method = 'POST') { | ||
try { | ||
const type = this.plural(this.camel(model)); | ||
let data = { | ||
type | ||
}; | ||
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)); | ||
} | ||
return { | ||
data | ||
}; | ||
} catch (E) { | ||
throw error(E); | ||
} | ||
}), _serialise.apply(this, arguments); | ||
return { | ||
data | ||
}; | ||
} catch (E) { | ||
throw error(E); | ||
} | ||
} | ||
@@ -268,0 +146,0 @@ |
{ | ||
"version": "6.4.0", | ||
"version": "7.0.0", | ||
"name": "kitsu-core", | ||
@@ -23,3 +23,3 @@ "description": "Core serialisation and deserialsation functions for the kitsu JSON:API client", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">= 8" | ||
}, | ||
@@ -60,4 +60,3 @@ "keywords": [ | ||
} | ||
], | ||
"gitHead": "4ef5cd27361674a240a7a1042db722690bd914aa" | ||
] | ||
} |
@@ -45,4 +45,4 @@ <h1 align=center>Kitsu Core</h1> | ||
| ----------------: | :----------------: | :--: | :----: | :-----: | :----: | :--: | :-: | | ||
| `kitsu-core` | ≤ 4.3 kb | 6+ | 54+ | 51+ | 10+ | 15+ | | | ||
| `kitsu-core/node` | ≤ 1.5 kb | 6+ | | | | | | | ||
| `kitsu-core` | ≤ 4.3 kb | 8+ | 57+ | 52+ | 10.1+ | 16+ | | | ||
| `kitsu-core/node` | ≤ 1.1 kb | 8+ | | | | | | | ||
@@ -113,3 +113,3 @@ \* Including all dependencies, minified & gzipped<br> | ||
[packages/kitsu-core/src/deattribute/index.js:29-38](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/deattribute/index.js#L29-L38 "Source code on GitHub") | ||
@@ -124,4 +124,5 @@ Hoists attributes to be top-level | ||
_Deattribute an array of resources_ | ||
Deattribute an array of resources | ||
```javascript | ||
@@ -140,4 +141,5 @@ // JSON:API 'data' field | ||
_Deattribute a resource_ | ||
Deattribute a resource | ||
```javascript | ||
@@ -158,3 +160,3 @@ // JSON:API 'data' field | ||
[packages/kitsu-core/src/deserialise/index.js:56-70](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/deserialise/index.js#L56-L70 "Source code on GitHub") | ||
@@ -169,4 +171,5 @@ Deserialises a JSON-API response | ||
_Deserialise with a basic data object_ | ||
Deserialise with a basic data object | ||
```javascript | ||
@@ -182,4 +185,5 @@ await deserialise({ | ||
_Deserialise with relationships_ | ||
Deserialise with relationships | ||
```javascript | ||
@@ -211,3 +215,3 @@ await deserialise({ | ||
[packages/kitsu-core/src/error/index.js:7-13](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/error/index.js#L7-L13 "Source code on GitHub") | ||
@@ -225,3 +229,3 @@ Mutates an error and rethrows it | ||
[packages/kitsu-core/src/filterIncludes/index.js:12-21](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/filterIncludes/index.js#L12-L21 "Source code on GitHub") | ||
@@ -241,3 +245,3 @@ Filters includes for the specific relationship | ||
[packages/kitsu-core/src/linkRelationships/index.js:55-74](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/linkRelationships/index.js#L55-L74 "Source code on GitHub") | ||
@@ -253,3 +257,3 @@ Links relationships to included data | ||
[packages/kitsu-core/src/query/index.js:21-32](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/query/index.js#L21-L32 "Source code on GitHub") | ||
@@ -267,3 +271,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/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/serialise/index.js#L96-L121 "Source code on GitHub") | ||
@@ -280,4 +284,5 @@ Serialises an object into a JSON-API structure | ||
_Due to its usage in kitsu, it **MUST** be called with **this** set in 6.0.x_ | ||
Due to its usage in kitsu, it **MUST** be called with **this** set in 6.0.x | ||
```javascript | ||
@@ -294,3 +299,3 @@ import { serialise, camel, kebab } from 'kitsu-core' | ||
[packages/kitsu-core/src/camel/index.js:14-14](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/camel/index.js#L14-L14 "Source code on GitHub") | ||
@@ -305,4 +310,5 @@ Converts kebab-case and snake_case into camelCase | ||
_Convert kebab-case_ | ||
Convert kebab-case | ||
```javascript | ||
@@ -312,4 +318,5 @@ camel('hello-world') // 'helloWorld' | ||
_Convert snake_case_ | ||
Convert snake_case | ||
```javascript | ||
@@ -323,3 +330,3 @@ camel('hello_world') // 'helloWorld' | ||
[packages/kitsu-core/src/kebab/index.js:11-11](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/kebab/index.js#L11-L11 "Source code on GitHub") | ||
@@ -342,3 +349,3 @@ Converts camelCase into kebab-case | ||
[packages/kitsu-core/src/snake/index.js:11-11](https://github.com/wopian/kitsu/blob/0cac34dd976c3f875666adcd7d88800d5ef6b4ad/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/07d2acab9cf767063713d2d30061a96e2c16db55/packages/kitsu-core/src/snake/index.js#L11-L11 "Source code on GitHub") | ||
@@ -345,0 +352,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
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
369
81795
8
1138
1