Comparing version 10.0.0-alpha.16 to 10.0.0-alpha.17
@@ -6,2 +6,13 @@ # Change Log | ||
# [10.0.0-alpha.17](https://github.com/wopian/kitsu/compare/v10.0.0-alpha.16...v10.0.0-alpha.17) (2021-10-19) | ||
### Bug Fixes | ||
* **kitsu-core:** Deserialize and link nested relations ([#601](https://github.com/wopian/kitsu/issues/601)) ([5bb705a](https://github.com/wopian/kitsu/commit/5bb705af57d2b0dc59c53550d1c220aa2cfed0c4)) | ||
# [10.0.0-alpha.16](https://github.com/wopian/kitsu/compare/v10.0.0-alpha.15...v10.0.0-alpha.16) (2021-10-18) | ||
@@ -8,0 +19,0 @@ |
@@ -1,1 +0,257 @@ | ||
"use strict";var e=require("kitsu-core"),a=require("axios"),s=require("merge-options"),r=require("pluralize");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=t(a),l=t(s),d=t(r);module.exports=class{constructor(a={}){!1===a.camelCaseTypes?this.camel=e=>e:this.camel=e.camel,"none"===a.resourceCase?this.resCase=e=>e:"snake"===a.resourceCase?this.resCase=e.snake:this.resCase=e.kebab,!1===a.pluralize?this.plural=e=>e:this.plural=d.default,this.headers=l.default({Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json"},a.headers),this.axios=i.default.create(l.default({baseURL:a.baseURL||"https://kitsu.io/api/edge",timeout:a.timeout||3e4},a.axiosOptions)),this.fetch=this.get,this.update=this.patch,this.create=this.post,this.remove=this.delete,this.interceptors=this.axios.interceptors}async get(a,s={}){try{const r=l.default(this.headers,s.headers),t=l.default({},s.params),[i,d,h,u]=a.split("/");let p=this.plural(this.resCase(i));d&&(p+=`/${this.resCase(d)}`),h&&(p+=`/${this.resCase(h)}`),u&&(p+=`/${this.resCase(u)}`);const{data:o,headers:c}=await this.axios.get(p,{headers:r,params:t,paramsSerializer:a=>e.query(a)});return c?l.default(e.deserialise(o),{headers:c}):e.deserialise(o)}catch(a){throw e.error(a)}}async patch(a,s,r={}){try{const t=l.default(this.headers,r.headers),i=l.default({},r.params),[d,h]=e.splitModel(a,{resourceCase:this.resCase,pluralModel:this.plural}),u=e.serialise(d,s,"PATCH",{camelCaseTypes:this.camel,pluralTypes:this.plural}),p=null!=s&&s.id?`${h}/${s.id}`:h,{data:o,headers:c}=await this.axios.patch(p,u,{headers:t,params:i,paramsSerializer:a=>e.query(a)});return c?l.default(e.deserialise(o),{headers:c}):e.deserialise(o)}catch(a){throw e.error(a)}}async post(a,s,r={}){try{const t=l.default(this.headers,r.headers),i=l.default({},r.params),[d,h]=e.splitModel(a,{resourceCase:this.resCase,pluralModel:this.plural}),{data:u,headers:p}=await this.axios.post(h,e.serialise(d,s,"POST",{camelCaseTypes:this.camel,pluralTypes:this.plural}),{headers:t,params:i,paramsSerializer:a=>e.query(a)});return p?l.default(e.deserialise(u),{headers:p}):e.deserialise(u)}catch(a){throw e.error(a)}}async delete(a,s,r={}){try{const t=l.default(this.headers,r.headers),i=l.default({},r.params),[d,h]=e.splitModel(a,{resourceCase:this.resCase,pluralModel:this.plural});let u,p;Array.isArray(s)?(u=h,p=s.map((e=>({id:e})))):(u=`${h}/${s}`,p={id:s});const{data:o,headers:c}=await this.axios.delete(u,{data:e.serialise(d,p,"DELETE",{camelCaseTypes:this.camel,pluralTypes:this.plural}),headers:t,params:i,paramsSerializer:a=>e.query(a)});return c?l.default(e.deserialise(o),{headers:c}):e.deserialise(o)}catch(a){throw e.error(a)}}async self(a={}){try{const e=l.default(this.headers,a.headers),s=l.default(a.params,{filter:{self:!0}}),r=await this.get("users",l.default({headers:e},{params:s}));return r.headers?l.default({data:r.data[0]},{headers:r.headers}):{data:r.data[0]}}catch(a){throw e.error(a)}}async request({body:a,method:s,params:r,type:t,url:i,headers:d}){try{var h;s=(null===(h=s)||void 0===h?void 0:h.toUpperCase())||"GET";const{data:u,headers:p}=await this.axios.request({method:s,url:i,data:["GET","DELETE"].includes(s)?void 0:e.serialise(t,a,s,{camelCaseTypes:this.camel,pluralTypes:this.plural}),headers:l.default(this.headers,d),params:r,paramsSerializer:a=>e.query(a)});return p?l.default(e.deserialise(u),{headers:p}):e.deserialise(u)}catch(a){throw e.error(a)}}}; | ||
'use strict'; | ||
var kitsuCore = require('kitsu-core'); | ||
var axios = require('axios'); | ||
var pluralise = require('pluralize'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios); | ||
var pluralise__default = /*#__PURE__*/_interopDefaultLegacy(pluralise); | ||
class Kitsu { | ||
constructor(options = {}) { | ||
if (options.camelCaseTypes === false) this.camel = s => s;else this.camel = kitsuCore.camel; | ||
if (options.resourceCase === 'none') this.resCase = s => s;else if (options.resourceCase === 'snake') this.resCase = kitsuCore.snake;else this.resCase = kitsuCore.kebab; | ||
if (options.pluralize === false) this.plural = s => s;else this.plural = pluralise__default["default"]; | ||
this.headers = { ...{ | ||
Accept: 'application/vnd.api+json', | ||
'Content-Type': 'application/vnd.api+json' | ||
}, | ||
...options.headers | ||
}; | ||
this.axios = axios__default["default"].create({ ...{ | ||
baseURL: options.baseURL || 'https://kitsu.io/api/edge', | ||
timeout: options.timeout || 30000 | ||
}, | ||
...options.axiosOptions | ||
}); | ||
this.fetch = this.get; | ||
this.update = this.patch; | ||
this.create = this.post; | ||
this.remove = this.delete; | ||
this.interceptors = this.axios.interceptors; | ||
} | ||
async get(model, config = {}) { | ||
try { | ||
const headers = { ...this.headers, | ||
...config.headers | ||
}; | ||
const params = { ...{}, | ||
...config.params | ||
}; | ||
const [res, id, relationship, subRelationship] = model.split('/'); | ||
let url = this.plural(this.resCase(res)); | ||
if (id) url += `/${this.resCase(id)}`; | ||
if (relationship) url += `/${this.resCase(relationship)}`; | ||
if (subRelationship) url += `/${this.resCase(subRelationship)}`; | ||
const { | ||
data, | ||
headers: responseHeaders | ||
} = await this.axios.get(url, { | ||
headers, | ||
params, | ||
paramsSerializer: p => kitsuCore.query(p) | ||
}); | ||
return responseHeaders ? { ...kitsuCore.deserialise(data), | ||
...{ | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} catch (E) { | ||
throw kitsuCore.error(E); | ||
} | ||
} | ||
async patch(model, body, config = {}) { | ||
try { | ||
const headers = { ...this.headers, | ||
...config.headers | ||
}; | ||
const params = { ...{}, | ||
...config.params | ||
}; | ||
const [resourceModel, url] = kitsuCore.splitModel(model, { | ||
resourceCase: this.resCase, | ||
pluralModel: this.plural | ||
}); | ||
const serialData = kitsuCore.serialise(resourceModel, body, 'PATCH', { | ||
camelCaseTypes: this.camel, | ||
pluralTypes: this.plural | ||
}); | ||
const fullURL = body !== null && body !== void 0 && body.id ? `${url}/${body.id}` : url; | ||
const { | ||
data, | ||
headers: responseHeaders | ||
} = await this.axios.patch(fullURL, serialData, { | ||
headers, | ||
params, | ||
paramsSerializer: p => kitsuCore.query(p) | ||
}); | ||
return responseHeaders ? { ...kitsuCore.deserialise(data), | ||
...{ | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} catch (E) { | ||
throw kitsuCore.error(E); | ||
} | ||
} | ||
async post(model, body, config = {}) { | ||
try { | ||
const headers = { ...this.headers, | ||
...config.headers | ||
}; | ||
const params = { ...{}, | ||
...config.params | ||
}; | ||
const [resourceModel, url] = kitsuCore.splitModel(model, { | ||
resourceCase: this.resCase, | ||
pluralModel: this.plural | ||
}); | ||
const { | ||
data, | ||
headers: responseHeaders | ||
} = await this.axios.post(url, kitsuCore.serialise(resourceModel, body, 'POST', { | ||
camelCaseTypes: this.camel, | ||
pluralTypes: this.plural | ||
}), { | ||
headers, | ||
params, | ||
paramsSerializer: p => kitsuCore.query(p) | ||
}); | ||
return responseHeaders ? { ...kitsuCore.deserialise(data), | ||
...{ | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} catch (E) { | ||
throw kitsuCore.error(E); | ||
} | ||
} | ||
async delete(model, id, config = {}) { | ||
try { | ||
const headers = { ...this.headers, | ||
...config.headers | ||
}; | ||
const params = { ...{}, | ||
...config.params | ||
}; | ||
const [resourceModel, url] = kitsuCore.splitModel(model, { | ||
resourceCase: this.resCase, | ||
pluralModel: this.plural | ||
}); | ||
const isBulk = Array.isArray(id); | ||
let path, payload; | ||
if (isBulk) { | ||
path = url; | ||
payload = id.map(id => ({ | ||
id | ||
})); | ||
} else { | ||
path = `${url}/${id}`; | ||
payload = { | ||
id | ||
}; | ||
} | ||
const { | ||
data, | ||
headers: responseHeaders | ||
} = await this.axios.delete(path, { | ||
data: kitsuCore.serialise(resourceModel, payload, 'DELETE', { | ||
camelCaseTypes: this.camel, | ||
pluralTypes: this.plural | ||
}), | ||
headers, | ||
params, | ||
paramsSerializer: p => kitsuCore.query(p) | ||
}); | ||
return responseHeaders ? { ...kitsuCore.deserialise(data), | ||
...{ | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} catch (E) { | ||
throw kitsuCore.error(E); | ||
} | ||
} | ||
async self(config = {}) { | ||
try { | ||
const headers = { ...this.headers, | ||
...config.headers | ||
}; | ||
const params = { ...config.params, | ||
...{ | ||
filter: { | ||
self: true | ||
} | ||
} | ||
}; | ||
const res = await this.get('users', { ...{ | ||
headers | ||
}, | ||
...{ | ||
params | ||
} | ||
}); | ||
return res.headers ? { ...{ | ||
data: res.data[0] | ||
}, | ||
...{ | ||
headers: res.headers | ||
} | ||
} : { | ||
data: res.data[0] | ||
}; | ||
} catch (E) { | ||
throw kitsuCore.error(E); | ||
} | ||
} | ||
async request({ | ||
body, | ||
method, | ||
params, | ||
type, | ||
url, | ||
headers | ||
}) { | ||
try { | ||
var _method; | ||
method = ((_method = method) === null || _method === void 0 ? void 0 : _method.toUpperCase()) || 'GET'; | ||
const { | ||
data, | ||
headers: responseHeaders | ||
} = await this.axios.request({ | ||
method, | ||
url, | ||
data: ['GET', 'DELETE'].includes(method) ? undefined : kitsuCore.serialise(type, body, method, { | ||
camelCaseTypes: this.camel, | ||
pluralTypes: this.plural | ||
}), | ||
headers: { ...this.headers, | ||
...headers | ||
}, | ||
params, | ||
paramsSerializer: p => kitsuCore.query(p) | ||
}); | ||
return responseHeaders ? { ...kitsuCore.deserialise(data), | ||
...{ | ||
headers: responseHeaders | ||
} | ||
} : kitsuCore.deserialise(data); | ||
} catch (E) { | ||
throw kitsuCore.error(E); | ||
} | ||
} | ||
} | ||
module.exports = Kitsu; |
{ | ||
"version": "10.0.0-alpha.16", | ||
"version": "10.0.0-alpha.17", | ||
"name": "kitsu", | ||
@@ -53,4 +53,3 @@ "description": "A simple, lightweight & framework agnostic JSON:API client using Axios", | ||
"axios": "^0.23.0", | ||
"kitsu-core": "^10.0.0-alpha.16", | ||
"merge-options": "^3.0.0", | ||
"kitsu-core": "^10.0.0-alpha.17", | ||
"pluralize": "^8.0.0" | ||
@@ -61,3 +60,3 @@ }, | ||
"path": "./dist/index.js", | ||
"limit": "10 kb", | ||
"limit": "11 kb", | ||
"brotli": true | ||
@@ -64,0 +63,0 @@ }, |
@@ -245,3 +245,3 @@ <h1 align=center>Kitsu</h1> | ||
[packages/kitsu/src/index.js:31-513](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L31-L513 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:30-513](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L30-L513 "Source code on GitHub") | ||
@@ -291,3 +291,3 @@ Creates a new `kitsu` instance | ||
[packages/kitsu/src/index.js:53-54](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L53-L54 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:52-53](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L52-L53 "Source code on GitHub") | ||
@@ -311,3 +311,3 @@ * **See**: <https://www.npmjs.com/package/pluralize> for documentation | ||
[packages/kitsu/src/index.js:68-68](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L68-L68 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:67-67](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L67-L67 "Source code on GitHub") | ||
@@ -340,3 +340,3 @@ Get the current headers or add additional headers | ||
[packages/kitsu/src/index.js:113-113](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L113-L113 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:113-113](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L113-L113 "Source code on GitHub") | ||
@@ -388,3 +388,3 @@ * **See**: <https://github.com/axios/axios#interceptors> for documentation | ||
[packages/kitsu/src/index.js:210-238](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L210-L238 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:210-238](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L210-L238 "Source code on GitHub") | ||
@@ -525,3 +525,3 @@ Fetch resources (alias `fetch`) | ||
[packages/kitsu/src/index.js:273-300](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L273-L300 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:273-300](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L273-L300 "Source code on GitHub") | ||
@@ -587,3 +587,3 @@ Update a resource (alias `update`) | ||
[packages/kitsu/src/index.js:330-355](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L330-L355 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:330-355](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L330-L355 "Source code on GitHub") | ||
@@ -632,3 +632,3 @@ Create a new resource (alias `create`) | ||
[packages/kitsu/src/index.js:372-405](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L372-L405 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:372-405](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L372-L405 "Source code on GitHub") | ||
@@ -664,3 +664,3 @@ Remove a resource (alias `remove`) | ||
[packages/kitsu/src/index.js:428-437](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L428-L437 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:428-437](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L428-L437 "Source code on GitHub") | ||
@@ -702,3 +702,3 @@ Get the authenticated user's data | ||
[packages/kitsu/src/index.js:491-512](https://github.com/wopian/kitsu/blob/9ddfe3734041213b8fa1e70a7722aa0db072efdf/packages/kitsu/src/index.js#L491-L512 "Source code on GitHub") | ||
[packages/kitsu/src/index.js:491-512](https://github.com/wopian/kitsu/blob/fd4f1cb072492c552cb97f45f581b51d204e3f7b/packages/kitsu/src/index.js#L491-L512 "Source code on GitHub") | ||
@@ -705,0 +705,0 @@ Send arbitrary requests |
Sorry, the diff of this file is not supported yet
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 1 instance in 1 package
79253
3
877
1
- Removedmerge-options@^3.0.0
- Removedis-plain-obj@2.1.0(transitive)
- Removedmerge-options@3.0.4(transitive)
Updatedkitsu-core@^10.0.0-alpha.17