Skip to content

Commit

Permalink
refactor: Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCCC committed Jul 2, 2023
1 parent 33b9ad6 commit da8a0b1
Show file tree
Hide file tree
Showing 21 changed files with 1,016 additions and 10,732 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
module.exports = {
extends: [
'react-app',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
settings: {
react: {
version: '999.999.999',
},
},
rules: {
'prettier/prettier': 0,
},
Expand Down
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"trailingComma": "all",
"arrowParens": "always",
"tabWidth": 4
"arrowParens": "always"
}
38 changes: 22 additions & 16 deletions dist/browser/index.global.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/index.global.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/index.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var R=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var h=(u,e,t,r)=>{for(var n=r>1?void 0:r?b(e,t):e,s=u.length-1,o;s>=0;s--)(o=u[s])&&(n=(r?o(e,t,n):o(n))||n);return r&&n&&R(e,t,n),n};import{applyMagic as q}from"js-magic";import f from"axios";import{applyMagic as m}from"js-magic";var g=class{constructor(e,t){this.logger=e,this.httpRequestErrorService=t}process(e){this.logger&&this.logger.warn&&this.logger.warn("API ERROR",e);let t=e;typeof e=="string"&&(t=new Error(e)),this.httpRequestErrorService&&(typeof this.httpRequestErrorService.process<"u"?this.httpRequestErrorService.process(t):typeof this.httpRequestErrorService=="function"&&this.httpRequestErrorService(t))}};var c=class{constructor({baseURL:e="",timeout:t=null,cancellable:r=!1,strategy:n=null,flattenResponse:s=null,defaultResponse:o={},logger:i=null,onError:l=null,...a}){this.timeout=3e4;this.cancellable=!1;this.strategy="reject";this.flattenResponse=!0;this.defaultResponse=null;this.timeout=t!==null?t:this.timeout,this.strategy=n!==null?n:this.strategy,this.cancellable=r||this.cancellable,this.flattenResponse=s!==null?s:this.flattenResponse,this.defaultResponse=o,this.logger=i||global.console||window.console||null,this.httpRequestErrorService=l,this.requestsQueue=new Map,this.requestInstance=f.create({...a,baseURL:e,timeout:this.timeout})}getInstance(){return this.requestInstance}interceptRequest(e){this.getInstance().interceptors.request.use(e)}__get(e){return e in this?this[e]:this.prepareRequest.bind(this,e)}prepareRequest(e,t,r=null,n=null){return this.handleRequest({type:e,url:t,data:r,config:n})}buildRequestConfig(e,t,r,n){let s=e.toLowerCase();return{...n,url:t,method:s,[s==="get"||s==="head"?"params":"data"]:r||{}}}processRequestError(e,t){if(this.isRequestCancelled(e,t))return;t.onError&&typeof t.onError=="function"&&t.onError(e),new g(this.logger,this.httpRequestErrorService).process(e)}async outputErrorResponse(e,t){let r=this.isRequestCancelled(e,t),n=t.strategy||this.strategy;return r&&!t.rejectCancelled?this.defaultResponse:n==="silent"?(await new Promise(()=>null),this.defaultResponse):n==="reject"||n==="throwError"?Promise.reject(e):this.defaultResponse}isRequestCancelled(e,t){return f.isCancel(e)}addCancellationToken(e){if(!this.cancellable&&!e.cancellable)return{};if(typeof e.cancellable<"u"&&!e.cancellable)return{};if(typeof AbortController>"u")return console.error("AbortController is unavailable in your ENV."),{};let{method:t,baseURL:r,url:n,params:s,data:o}=e,i=JSON.stringify([t,r,n,s,o]).substring(0,55**5),l=this.requestsQueue.get(i);l&&l.abort();let a=new AbortController;return this.requestsQueue.set(i,a),{signal:a.signal}}async handleRequest({type:e,url:t,data:r=null,config:n=null}){let s=null,o=n||{},i=this.buildRequestConfig(e,t,r,o);i={...this.addCancellationToken(i),...i};try{s=await this.requestInstance.request(i)}catch(l){return this.processRequestError(l,i),this.outputErrorResponse(l,i)}return this.processResponseData(s)}processResponseData(e){return e.data?this.flattenResponse?typeof e.data=="object"&&typeof e.data.data<"u"&&Object.keys(e.data).length===1?e.data.data:e.data:e:this.defaultResponse}};c=h([m],c);var d=class{constructor({apiUrl:e,endpoints:t,timeout:r=null,cancellable:n=!1,strategy:s=null,flattenResponse:o=null,defaultResponse:i={},logger:l=null,onError:a=null,...p}){this.apiUrl="";this.apiUrl=e,this.endpoints=t,this.logger=l,this.httpRequestHandler=new c({...p,baseURL:this.apiUrl,timeout:r,cancellable:n,strategy:s,flattenResponse:o,defaultResponse:i,logger:l,onError:a})}getInstance(){return this.httpRequestHandler.getInstance()}__get(e){return e in this?this[e]:this.endpoints[e]?this.handleRequest.bind(this,e):this.handleNonImplemented.bind(this,e)}async handleRequest(...e){let t=e[0],r=this.endpoints[t],n=e[1]||{},s=e[2]||{},o=e[3]||{},i=r.url.replace(/:[a-z]+/gi,p=>s[p.substring(1)]?s[p.substring(1)]:p),l=null,a={...r};return delete a.url,delete a.method,l=await this.httpRequestHandler[(r.method||"get").toLowerCase()](i,n,{...o,...a}),l}handleNonImplemented(e){return this.logger&&this.logger.log&&this.logger.log(`${e} endpoint not implemented.`),Promise.resolve(null)}};d=h([q],d);var k=u=>new d(u);export{d as ApiHandler,g as HttpRequestErrorHandler,c as HttpRequestHandler,k as createApiFetcher};
var R=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var h=(u,e,t,r)=>{for(var n=r>1?void 0:r?b(e,t):e,s=u.length-1,o;s>=0;s--)(o=u[s])&&(n=(r?o(e,t,n):o(n))||n);return r&&n&&R(e,t,n),n};import{applyMagic as q}from"js-magic";import f from"axios";import{applyMagic as m}from"js-magic";var g=class{logger;httpRequestErrorService;constructor(e,t){this.logger=e,this.httpRequestErrorService=t}process(e){this.logger&&this.logger.warn&&this.logger.warn("API ERROR",e);let t=e;typeof e=="string"&&(t=new Error(e)),this.httpRequestErrorService&&(typeof this.httpRequestErrorService.process<"u"?this.httpRequestErrorService.process(t):typeof this.httpRequestErrorService=="function"&&this.httpRequestErrorService(t))}};var c=class{requestInstance;timeout=3e4;cancellable=!1;strategy="reject";flattenResponse=!0;defaultResponse=null;logger;httpRequestErrorService;requestsQueue;constructor({baseURL:e="",timeout:t=null,cancellable:r=!1,strategy:n=null,flattenResponse:s=null,defaultResponse:o={},logger:i=null,onError:l=null,...a}){this.timeout=t!==null?t:this.timeout,this.strategy=n!==null?n:this.strategy,this.cancellable=r||this.cancellable,this.flattenResponse=s!==null?s:this.flattenResponse,this.defaultResponse=o,this.logger=i||global.console||window.console||null,this.httpRequestErrorService=l,this.requestsQueue=new Map,this.requestInstance=f.create({...a,baseURL:e,timeout:this.timeout})}getInstance(){return this.requestInstance}interceptRequest(e){this.getInstance().interceptors.request.use(e)}__get(e){return e in this?this[e]:this.prepareRequest.bind(this,e)}prepareRequest(e,t,r=null,n=null){return this.handleRequest({type:e,url:t,data:r,config:n})}buildRequestConfig(e,t,r,n){let s=e.toLowerCase();return{...n,url:t,method:s,[s==="get"||s==="head"?"params":"data"]:r||{}}}processRequestError(e,t){if(this.isRequestCancelled(e,t))return;t.onError&&typeof t.onError=="function"&&t.onError(e),new g(this.logger,this.httpRequestErrorService).process(e)}async outputErrorResponse(e,t){let r=this.isRequestCancelled(e,t),n=t.strategy||this.strategy;return r&&!t.rejectCancelled?this.defaultResponse:n==="silent"?(await new Promise(()=>null),this.defaultResponse):n==="reject"||n==="throwError"?Promise.reject(e):this.defaultResponse}isRequestCancelled(e,t){return f.isCancel(e)}addCancellationToken(e){if(!this.cancellable&&!e.cancellable)return{};if(typeof e.cancellable<"u"&&!e.cancellable)return{};if(typeof AbortController>"u")return console.error("AbortController is unavailable in your ENV."),{};let{method:t,baseURL:r,url:n,params:s,data:o}=e,i=JSON.stringify([t,r,n,s,o]).substring(0,55**5),l=this.requestsQueue.get(i);l&&l.abort();let a=new AbortController;return this.requestsQueue.set(i,a),{signal:a.signal}}async handleRequest({type:e,url:t,data:r=null,config:n=null}){let s=null,o=n||{},i=this.buildRequestConfig(e,t,r,o);i={...this.addCancellationToken(i),...i};try{s=await this.requestInstance.request(i)}catch(l){return this.processRequestError(l,i),this.outputErrorResponse(l,i)}return this.processResponseData(s)}processResponseData(e){return e.data?this.flattenResponse?typeof e.data=="object"&&typeof e.data.data<"u"&&Object.keys(e.data).length===1?e.data.data:e.data:e:this.defaultResponse}};c=h([m],c);var d=class{apiUrl="";httpRequestHandler;endpoints;logger;constructor({apiUrl:e,endpoints:t,timeout:r=null,cancellable:n=!1,strategy:s=null,flattenResponse:o=null,defaultResponse:i={},logger:l=null,onError:a=null,...p}){this.apiUrl=e,this.endpoints=t,this.logger=l,this.httpRequestHandler=new c({...p,baseURL:this.apiUrl,timeout:r,cancellable:n,strategy:s,flattenResponse:o,defaultResponse:i,logger:l,onError:a})}getInstance(){return this.httpRequestHandler.getInstance()}__get(e){return e in this?this[e]:this.endpoints[e]?this.handleRequest.bind(this,e):this.handleNonImplemented.bind(this,e)}async handleRequest(...e){let t=e[0],r=this.endpoints[t],n=e[1]||{},s=e[2]||{},o=e[3]||{},i=r.url.replace(/:[a-z]+/gi,p=>s[p.substring(1)]?s[p.substring(1)]:p),l=null,a={...r};return delete a.url,delete a.method,l=await this.httpRequestHandler[(r.method||"get").toLowerCase()](i,n,{...o,...a}),l}handleNonImplemented(e){return this.logger&&this.logger.log&&this.logger.log(`${e} endpoint not implemented.`),Promise.resolve(null)}};d=h([q],d);var j=u=>new d(u);export{d as ApiHandler,g as HttpRequestErrorHandler,c as HttpRequestHandler,j as createApiFetcher};
//# sourceMappingURL=index.mjs.map
2 changes: 1 addition & 1 deletion dist/browser/index.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/node/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit da8a0b1

Please sign in to comment.