getta 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/browser/index.js +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/production.analysis.txt +8 -8
- package/lib/main/index.js +8 -11
- package/lib/main/main.js +5 -4
- package/lib/module/index.js +1 -1
- package/lib/module/main.js +2 -2
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/main.d.ts +1 -1
- package/lib/types/main.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/main.test.ts +1 -1
- package/src/main.ts +2 -2
package/CHANGELOG.md
CHANGED
package/lib/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/defineProperty";import t from"lodash/merge";import r from"lodash/castArray";import"core-js/modules/es.promise.js";import a from"md5";import s from"query-string";const i="arrayBuffer",h="blob",o="formData",c="json",n="text",u={ARRAY_BUFFER_FORMAT:"arrayBuffer",BLOB_FORMAT:"blob",FORM_DATA_FORMAT:"formData",JSON_FORMAT:c,TEXT_FORMAT:"text"},d=e=>e,l=5e3,m={"content-type":"application/json"},_=5,p=3,T=/({type})|({id})|({id,\+})|({brief\|standard})/g,R=/({[a-zA-Z0-9_]+\?})/g,f=50,g=100,y="Getta expected to receive 'basePath' in the constructor options,\n but recevied undefined.",v="The request exceeded the maximum number of redirects, which is",q="The request exceeded the maximum number of retries, which is",E="Getta expected to receive 'get', 'post', 'put' or 'delete', but received",b="The requested resource could not been found.",P="The request timed out. Getta did not get a response within",x="get",w="post",C="put",L="delete",k=["get","post","put","delete"],D="information",$="successful",A="redirection",O="clientError",j="serverError",S=304,H=404,M="Cookie",Q="ETag",F="Location",G="If-None-Match",W="Cache-Control",B="request_sent",N="response_received";function I(e,t,r){const a=Object.keys(t);return e.replace(r,e=>a.reduce((r,a)=>e.includes(a)?t[a]:r,""))}function U(e,t,{optionalPathTemplateRegExp:r,pathTemplateCallback:a,pathTemplateData:i,pathTemplateRegExp:h,queryParams:o}){const c=e.endsWith("/")||t.startsWith("/")?"":"/";let n=`${e}${c}${t}`;if(i&&(n=a(n,i,h)),n=n.replace(r,""),n.endsWith("/")&&(n=n.substring(0,n.length-1)),o&&Object.keys(o).length){n=`${n}${s.extract(n)?"&":"?"}${s.stringify(o)}`}return n}class z{constructor(t){e(this,"_basePath",void 0),e(this,"_bodyParser",void 0),e(this,"_cache",void 0),e(this,"_conditionalRequestsEnabled",void 0),e(this,"_fetchTimeout",void 0),e(this,"_headers",void 0),e(this,"_log",void 0),e(this,"_maxRedirects",void 0),e(this,"_maxRetries",void 0),e(this,"_optionalPathTemplateRegExp",void 0),e(this,"_pathTemplateCallback",void 0),e(this,"_pathTemplateRegExp",void 0),e(this,"_performance",void 0),e(this,"_queryParams",void 0),e(this,"_rateLimitCount",0),e(this,"_rateLimitedRequestQueue",[]),e(this,"_rateLimitPerSecond",void 0),e(this,"_rateLimitTimer",null),e(this,"_requestRetryWait",void 0),e(this,"_requestTracker",{active:[],pending:new Map}),e(this,"_streamReader",void 0);const{basePath:r,bodyParser:a=d,cache:s,enableConditionalRequests:i=!0,fetchTimeout:h=l,headers:o,log:n,maxRedirects:u=_,maxRetries:v=p,optionalPathTemplateRegExp:q=R,pathTemplateCallback:E=I,pathTemplateRegExp:b=T,performance:P,queryParams:x={},rateLimitPerSecond:w=f,requestRetryWait:C=g,streamReader:L=c}=t;if(!r)throw new Error(y);this._basePath=r,this._bodyParser=a,this._cache=s,this._conditionalRequestsEnabled=i,this._fetchTimeout=h,this._headers={...m,...o||{}},this._log=n,this._maxRedirects=u,this._maxRetries=v,this._optionalPathTemplateRegExp=q,this._pathTemplateCallback=E,this._pathTemplateRegExp=b,this._performance=P,this._queryParams=x,this._rateLimitPerSecond=w,this._requestRetryWait=C,this._streamReader=L}get cache(){return this._cache}createShortcut(e,r,{method:a,...s}){if(!k.includes(a))throw new Error("Getta expected to receive 'get', 'post', 'put' or 'delete', but received "+a);this[e]=async({method:e,...i}={},h)=>this[null!=e?e:a](r,t({},s,i),h)}async delete(e,t={},r){return this._delete(e,t,r)}async get(e,t={},r){return this._get(e,t,r)}async post(e,t,r){return this._request(e,{...t,method:"post"},r)}async put(e,t,r){return this._request(e,{...t,method:"put"},r)}_addRequestToRateLimitedQueue(e,t,r){return new Promise(a=>{this._rateLimitedRequestQueue.push([a,e,t,r])})}async _cacheEntryDelete(e){if(!this._cache)return!1;try{return await this._cache.delete(e)}catch(e){return Promise.reject(e)}}async _cacheEntryGet(e){if(this._cache)try{return await this._cache.get(e)}catch(e){return Promise.reject(e)}}async _cacheEntryHas(e){if(!this._cache)return!1;try{return await this._cache.has(e)}catch(e){return!1}}async _cacheEntrySet(e,t,r){if(this._cache)try{return await this._cache.set(e,t,{cacheHeaders:r})}catch(e){return Promise.reject(e)}}async _delete(e,{headers:t={},pathTemplateData:r,queryParams:s={},...i},h){const o=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:r,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...s}}),c=a(o);return await this._cacheEntryHas(c)&&this._cacheEntryDelete(c),this._fetch(o,{headers:{...this._headers,...t},method:"delete",...i},h)}async _fetch(e,t,a={}){a.startTime=this._performance.now();try{const{redirects:r,retries:s,...i}=t;return await new Promise(async(h,o)=>{const c=setTimeout(()=>{o(new Error(`${P} ${this._fetchTimeout}ms.`))},this._fetchTimeout);if(this._rateLimit(),!(this._rateLimitCount<this._rateLimitPerSecond))return clearTimeout(c),void h(await this._addRequestToRateLimitedQueue(e,t,a));var n;r||s||(null===(n=this._log)||void 0===n||n.call(this,"request_sent",{context:{redirects:r,retries:s,url:e,...i,...a},stats:{startTime:a.startTime}}));const u=await fetch(e,i);clearTimeout(c);const{headers:d,status:l}=u,m=function(e){switch(!0){case e<200:return"information";case e<300:return"successful";case e<400:return"redirection";case e<500:return"clientError";default:return"serverError"}}(l);if("redirection"===m&&d.get("Location"))return void h(await this._fetchRedirectHandler(u,d.get("Location"),{redirects:r,status:l,...i},a));if("serverError"===m)return void h(await this._fetchRetryHandler(u,e,{retries:s,...i},a));const _=u;try{_.data=u.body?this._bodyParser(await u[this._streamReader]()):void 0,this._logResponse(_,e,t,a),h(_)}catch(t){o([t,new Error(`Unable to ${i.method} ${e} due to previous error`)])}})}catch(s){const i={errors:r(s)};return this._logResponse(i,e,t,a),i}}async _fetchRedirectHandler(e,t,r,a){const{method:s,redirects:i=1,status:h,...o}=r;if(i===this._maxRedirects){const s=e;return s.errors=[new Error(`The request exceeded the maximum number of redirects, which is ${this._maxRedirects}.`)],this._logResponse(s,t,r,a),s}const c=303===h?"get":s;return this._fetch(t,{method:c,redirects:i+1,...o})}async _fetchRetryHandler(e,t,r,a){const{retries:s=1,...i}=r;if(s===this._maxRetries){const s=e;return s.errors=[new Error(`The request exceeded the maximum number of retries, which is ${this._maxRetries}.`)],this._logResponse(s,t,r,a),s}var h;return await(h=this._requestRetryWait,new Promise(e=>setTimeout(e,h))),this._fetch(t,{retries:s+1,...i})}async _get(e,{headers:t={},pathTemplateData:r,queryParams:s={}},i){const h=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:r,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...s}}),o=a(h),c=await this._cacheEntryHas(o);if(c){if(function(e){var t,r,a;return!(null!==(t=null==e||null===(r=e.metadata)||void 0===r||null===(a=r.cacheControl)||void 0===a?void 0:a.noCache)&&void 0!==t&&t)&&e.checkTTL()}(c))return{data:await this._cacheEntryGet(o),headers:new Headers({"cache-control":c.printCacheControl()})};if(this._conditionalRequestsEnabled){var n,u;const e=null!==(n=null==c||null===(u=c.metadata)||void 0===u?void 0:u.etag)&&void 0!==n?n:null;e&&(t["If-None-Match"]=e)}}const d=this._trackRequest(o);return d||this._getResolve(o,await this._fetch(h,{headers:{...this._headers,...t},method:"get"},i))}async _getResolve(e,t){const{data:r,headers:a,status:s}=t;if(404===s)this._cacheEntryDelete(e),t.errors||(t.errors=[]),t.errors.push(new Error("The requested resource could not been found."));else if(304===s&&a){const r=await this._cacheEntryGet(e);r&&(this._cacheEntrySet(e,r,{cacheControl:a.get("Cache-Control")||void 0,etag:a.get("ETag")||void 0}),t.data=r)}else r&&a&&this._cacheEntrySet(e,r,{cacheControl:a.get("Cache-Control")||void 0,etag:a.get("ETag")||void 0});return this._resolvePendingRequests(e,t),this._requestTracker.active=this._requestTracker.active.filter(t=>t!==e),t}_logResponse(e,t,r,a){var s;const{data:i,errors:h,headers:o,status:c}=e,{redirects:n,retries:u}=r,{startTime:d,...l}=a,m=this._performance.now(),_=m-d;null===(s=this._log)||void 0===s||s.call(this,"response_received",{context:{body:i?{data:i}:{errors:null!=h?h:[]},headers:o,method:r.method,redirects:n,retries:u,status:c,url:t,...l},stats:{duration:_,endTime:m,startTime:d}})}_rateLimit(){this._rateLimitTimer||(this._rateLimitTimer=setTimeout(()=>{this._rateLimitTimer=null,this._rateLimitCount=0,this._rateLimitedRequestQueue.length&&this._releaseRateLimitedRequestQueue()},1e3)),this._rateLimitCount+=1}_releaseRateLimitedRequestQueue(){this._rateLimitedRequestQueue.forEach(async([e,t,r,a])=>{e(await this._fetch(t,r,a))}),this._rateLimitedRequestQueue=[]}async _request(e,{body:t,headers:r,method:a,pathTemplateData:s,queryParams:i,...h},o){const c=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:s,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...i}});return this._fetch(c,{body:t,headers:{...this._headers,...r},method:a,...h},o)}_resolvePendingRequests(e,t){const r=this._requestTracker.pending.get(e);r&&(r.forEach(({resolve:e})=>{e(t)}),this._requestTracker.pending.delete(e))}_setPendingRequest(e,t){let r=this._requestTracker.pending.get(e);r||(r=[]),r.push(t),this._requestTracker.pending.set(e,r)}_trackRequest(e){if(this._requestTracker.active.includes(e))return new Promise(t=>{this._setPendingRequest(e,{resolve:t})});this._requestTracker.active.push(e)}}export default function(e,t){const r=new z(e);return t?(Object.keys(t).forEach(e=>{r.createShortcut(e,...t[e])}),r):r}export{i as ARRAY_BUFFER_FORMAT,h as BLOB_FORMAT,W as CACHE_CONTROL_HEADER,O as CLIENT_ERROR_REPSONSE,M as COOKIE_HEADER,d as DEFAULT_BODY_PARSER,l as DEFAULT_FETCH_TIMEOUT,m as DEFAULT_HEADERS,_ as DEFAULT_MAX_REDIRECTS,p as DEFAULT_MAX_RETRIES,T as DEFAULT_PATH_TEMPLATE_REGEX,f as DEFAULT_RATE_LIMIT,g as DEFAULT_REQUEST_RETRY_WAIT,L as DELETE_METHOD,Q as ETAG_HEADER,k as FETCH_METHODS,P as FETCH_TIMEOUT_ERROR,o as FORM_DATA_FORMAT,x as GET_METHOD,z as Getta,G as IF_NONE_MATCH_HEADER,D as INFORMATION_REPSONSE,E as INVALID_FETCH_METHOD_ERROR,c as JSON_FORMAT,F as LOCATION_HEADER,v as MAX_REDIRECTS_EXCEEDED_ERROR,q as MAX_RETRIES_EXCEEDED_ERROR,y as MISSING_BASE_PATH_ERROR,H as NOT_FOUND_STATUS_CODE,S as NOT_MODIFIED_STATUS_CODE,R as OPTIONAL_PATH_TEMPLATE_REGEX,w as POST_METHOD,C as PUT_METHOD,A as REDIRECTION_REPSONSE,B as REQUEST_SENT,b as RESOURCE_NOT_FOUND_ERROR,N as RESPONSE_RECEIVED,j as SERVER_ERROR_REPSONSE,u as STREAM_READERS,$ as SUCCESSFUL_REPSONSE,n as TEXT_FORMAT,I as defaultPathTemplateCallback};
|
|
1
|
+
import e from"@babel/runtime/helpers/defineProperty";import t from"lodash/merge";import r from"lodash/castArray";import"core-js/modules/es.promise.js";import a from"md5";import s from"query-string";const i="arrayBuffer",h="blob",o="formData",c="json",n="text",u={ARRAY_BUFFER_FORMAT:"arrayBuffer",BLOB_FORMAT:"blob",FORM_DATA_FORMAT:"formData",JSON_FORMAT:c,TEXT_FORMAT:"text"},d=e=>e,l=5e3,m={"content-type":"application/json"},_=5,p=3,T=/({type})|({id})|({id,\+})|({brief\|standard})/g,R=/({[a-zA-Z0-9_]+\?})/g,f=50,g=100,y="Getta expected to receive 'basePath' in the constructor options,\n but recevied undefined.",v="The request exceeded the maximum number of redirects, which is",q="The request exceeded the maximum number of retries, which is",E="Getta expected to receive 'get', 'post', 'put' or 'delete', but received",b="The requested resource could not been found.",P="The request timed out. Getta did not get a response within",x="get",w="post",C="put",L="delete",k=["get","post","put","delete"],D="information",$="successful",A="redirection",O="clientError",j="serverError",S=304,H=404,M="Cookie",Q="ETag",F="Location",G="If-None-Match",W="Cache-Control",B="request_sent",N="response_received";function I(e,t,r){const a=Object.keys(t);return e.replace(r,e=>a.reduce((r,a)=>e.includes(a)?t[a]:r,""))}function U(e,t,{optionalPathTemplateRegExp:r,pathTemplateCallback:a,pathTemplateData:i,pathTemplateRegExp:h,queryParams:o}){const c=e.endsWith("/")||t.startsWith("/")?"":"/";let n=`${e}${c}${t}`;if(i&&(n=a(n,i,h)),n=n.replace(r,""),n.endsWith("/")&&(n=n.substring(0,n.length-1)),o&&Object.keys(o).length){n=`${n}${s.extract(n)?"&":"?"}${s.stringify(o)}`}return n}class z{constructor(t){e(this,"_basePath",void 0),e(this,"_bodyParser",void 0),e(this,"_cache",void 0),e(this,"_conditionalRequestsEnabled",void 0),e(this,"_fetchTimeout",void 0),e(this,"_headers",void 0),e(this,"_log",void 0),e(this,"_maxRedirects",void 0),e(this,"_maxRetries",void 0),e(this,"_optionalPathTemplateRegExp",void 0),e(this,"_pathTemplateCallback",void 0),e(this,"_pathTemplateRegExp",void 0),e(this,"_performance",void 0),e(this,"_queryParams",void 0),e(this,"_rateLimitCount",0),e(this,"_rateLimitedRequestQueue",[]),e(this,"_rateLimitPerSecond",void 0),e(this,"_rateLimitTimer",null),e(this,"_requestRetryWait",void 0),e(this,"_requestTracker",{active:[],pending:new Map}),e(this,"_streamReader",void 0);const{basePath:r,bodyParser:a=d,cache:s,enableConditionalRequests:i=!0,fetchTimeout:h=l,headers:o,log:n,maxRedirects:u=_,maxRetries:v=p,optionalPathTemplateRegExp:q=R,pathTemplateCallback:E=I,pathTemplateRegExp:b=T,performance:P,queryParams:x={},rateLimitPerSecond:w=f,requestRetryWait:C=g,streamReader:L=c}=t;if(!r)throw new Error(y);this._basePath=r,this._bodyParser=a,this._cache=s,this._conditionalRequestsEnabled=i,this._fetchTimeout=h,this._headers={...m,...o||{}},this._log=n,this._maxRedirects=u,this._maxRetries=v,this._optionalPathTemplateRegExp=q,this._pathTemplateCallback=E,this._pathTemplateRegExp=b,this._performance=P,this._queryParams=x,this._rateLimitPerSecond=w,this._requestRetryWait=C,this._streamReader=L}get cache(){return this._cache}createShortcut(e,r,{method:a,...s}){if(!k.includes(a))throw new Error("Getta expected to receive 'get', 'post', 'put' or 'delete', but received "+a);this[e]=async({method:e,...i}={},h)=>this[null!=e?e:a](r,t({},s,i),h)}async delete(e,t={},r){return this._delete(e,t,r)}async get(e,t={},r){return this._get(e,t,r)}async post(e,t,r){return this._request(e,{...t,method:"post"},r)}async put(e,t,r){return this._request(e,{...t,method:"put"},r)}_addRequestToRateLimitedQueue(e,t,r){return new Promise(a=>{this._rateLimitedRequestQueue.push([a,e,t,r])})}async _cacheEntryDelete(e){if(!this._cache)return!1;try{return await this._cache.delete(e)}catch(e){return Promise.reject(e)}}async _cacheEntryGet(e){if(this._cache)try{return await this._cache.get(e)}catch(e){return Promise.reject(e)}}async _cacheEntryHas(e){if(!this._cache)return!1;try{return await this._cache.has(e)}catch(e){return!1}}async _cacheEntrySet(e,t,r){if(this._cache)try{return await this._cache.set(e,t,{cacheHeaders:r})}catch(e){return Promise.reject(e)}}async _delete(e,{headers:t={},pathTemplateData:r,queryParams:s={},...i},h){const o=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:r,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...s}}),c=a(o);return await this._cacheEntryHas(c)&&this._cacheEntryDelete(c),this._fetch(o,{headers:{...this._headers,...t},method:"delete",...i},h)}async _fetch(e,t,a={}){a.startTime=this._performance.now();try{const{redirects:r,retries:s,...i}=t;return await new Promise(async(h,o)=>{const c=setTimeout(()=>{o(new Error(`${P} ${this._fetchTimeout}ms.`))},this._fetchTimeout);if(this._rateLimit(),!(this._rateLimitCount<this._rateLimitPerSecond))return clearTimeout(c),void h(await this._addRequestToRateLimitedQueue(e,t,a));var n;r||s||(null===(n=this._log)||void 0===n||n.call(this,"request_sent",{context:{redirects:r,retries:s,url:e,...i,...a},stats:{startTime:a.startTime}}));const u=await fetch(e,i);clearTimeout(c);const{headers:d,status:l}=u,m=function(e){switch(!0){case e<200:return"information";case e<300:return"successful";case e<400:return"redirection";case e<500:return"clientError";default:return"serverError"}}(l);if("redirection"===m&&d.get("Location"))return void h(await this._fetchRedirectHandler(u,d.get("Location"),{redirects:r,status:l,...i},a));if("serverError"===m)return void h(await this._fetchRetryHandler(u,e,{retries:s,...i},a));const _=u;try{_.data=u.body?this._bodyParser(await u[this._streamReader]()):void 0,this._logResponse(_,e,t,a),h(_)}catch(t){o([t,new Error(`Unable to ${i.method} ${e} due to previous error`)])}})}catch(s){const i={errors:r(s)};return this._logResponse(i,e,t,a),i}}async _fetchRedirectHandler(e,t,r,a){const{method:s,redirects:i=1,status:h,...o}=r;if(i===this._maxRedirects){const s=e;return s.errors=[new Error(`The request exceeded the maximum number of redirects, which is ${this._maxRedirects}.`)],this._logResponse(s,t,r,a),s}const c=303===h?"get":s;return this._fetch(t,{method:c,redirects:i+1,...o})}async _fetchRetryHandler(e,t,r,a){const{retries:s=1,...i}=r;if(s===this._maxRetries){const s=e;return s.errors=[new Error(`The request exceeded the maximum number of retries, which is ${this._maxRetries}.`)],this._logResponse(s,t,r,a),s}var h;return await(h=this._requestRetryWait,new Promise(e=>setTimeout(e,h))),this._fetch(t,{retries:s+1,...i})}async _get(e,{headers:t={},pathTemplateData:r,queryParams:s={}},i){const h=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:r,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...s}}),o=a(h),c=await this._cacheEntryHas(o);if(c){if(function(e){var t,r,a;return!(null!==(t=null==e||null===(r=e.metadata)||void 0===r||null===(a=r.cacheControl)||void 0===a?void 0:a.noCache)&&void 0!==t&&t)&&e.checkTTL()}(c))return{data:await this._cacheEntryGet(o),headers:new Headers({"cache-control":c.printCacheControl()})};if(this._conditionalRequestsEnabled){var n,u;const e=null!==(n=null==c||null===(u=c.metadata)||void 0===u?void 0:u.etag)&&void 0!==n?n:null;e&&(t["If-None-Match"]=e)}}const d=this._trackRequest(o);return d||this._getResolve(o,await this._fetch(h,{headers:{...this._headers,...t},method:"get"},i))}async _getResolve(e,t){const{data:r,headers:a,status:s}=t;if(404===s)this._cacheEntryDelete(e),t.errors||(t.errors=[]),t.errors.push(new Error("The requested resource could not been found."));else if(304===s&&a){const r=await this._cacheEntryGet(e);r&&(this._cacheEntrySet(e,r,{cacheControl:a.get("Cache-Control")||void 0,etag:a.get("ETag")||void 0}),t.data=r)}else r&&a&&this._cacheEntrySet(e,r,{cacheControl:a.get("Cache-Control")||void 0,etag:a.get("ETag")||void 0});return this._resolvePendingRequests(e,t),this._requestTracker.active=this._requestTracker.active.filter(t=>t!==e),t}_logResponse(e,t,r,a){var s;const{data:i,errors:h,headers:o,status:c}=e,{redirects:n,retries:u}=r,{startTime:d,...l}=a,m=this._performance.now(),_=m-d;null===(s=this._log)||void 0===s||s.call(this,"response_received",{context:{body:i?{data:i}:{errors:null!=h?h:[]},headers:o,method:r.method,redirects:n,retries:u,status:c,url:t,...l},stats:{duration:_,endTime:m,startTime:d}})}_rateLimit(){this._rateLimitTimer||(this._rateLimitTimer=setTimeout(()=>{this._rateLimitTimer=null,this._rateLimitCount=0,this._rateLimitedRequestQueue.length&&this._releaseRateLimitedRequestQueue()},1e3)),this._rateLimitCount+=1}_releaseRateLimitedRequestQueue(){this._rateLimitedRequestQueue.forEach(async([e,t,r,a])=>{e(await this._fetch(t,r,a))}),this._rateLimitedRequestQueue=[]}async _request(e,{body:t,headers:r,method:a,pathTemplateData:s,queryParams:i,...h},o){const c=U(this._basePath,e,{optionalPathTemplateRegExp:this._optionalPathTemplateRegExp,pathTemplateCallback:this._pathTemplateCallback,pathTemplateData:s,pathTemplateRegExp:this._pathTemplateRegExp,queryParams:{...this._queryParams,...i}});return this._fetch(c,{body:t,headers:{...this._headers,...r},method:a,...h},o)}_resolvePendingRequests(e,t){const r=this._requestTracker.pending.get(e);r&&(r.forEach(({resolve:e})=>{e(t)}),this._requestTracker.pending.delete(e))}_setPendingRequest(e,t){let r=this._requestTracker.pending.get(e);r||(r=[]),r.push(t),this._requestTracker.pending.set(e,r)}_trackRequest(e){if(this._requestTracker.active.includes(e))return new Promise(t=>{this._setPendingRequest(e,{resolve:t})});this._requestTracker.active.push(e)}}const J=(e,t)=>{const r=new z(e);return t?(Object.keys(t).forEach(e=>{r.createShortcut(e,...t[e])}),r):r};export{i as ARRAY_BUFFER_FORMAT,h as BLOB_FORMAT,W as CACHE_CONTROL_HEADER,O as CLIENT_ERROR_REPSONSE,M as COOKIE_HEADER,d as DEFAULT_BODY_PARSER,l as DEFAULT_FETCH_TIMEOUT,m as DEFAULT_HEADERS,_ as DEFAULT_MAX_REDIRECTS,p as DEFAULT_MAX_RETRIES,T as DEFAULT_PATH_TEMPLATE_REGEX,f as DEFAULT_RATE_LIMIT,g as DEFAULT_REQUEST_RETRY_WAIT,L as DELETE_METHOD,Q as ETAG_HEADER,k as FETCH_METHODS,P as FETCH_TIMEOUT_ERROR,o as FORM_DATA_FORMAT,x as GET_METHOD,z as Getta,G as IF_NONE_MATCH_HEADER,D as INFORMATION_REPSONSE,E as INVALID_FETCH_METHOD_ERROR,c as JSON_FORMAT,F as LOCATION_HEADER,v as MAX_REDIRECTS_EXCEEDED_ERROR,q as MAX_RETRIES_EXCEEDED_ERROR,y as MISSING_BASE_PATH_ERROR,H as NOT_FOUND_STATUS_CODE,S as NOT_MODIFIED_STATUS_CODE,R as OPTIONAL_PATH_TEMPLATE_REGEX,w as POST_METHOD,C as PUT_METHOD,A as REDIRECTION_REPSONSE,B as REQUEST_SENT,b as RESOURCE_NOT_FOUND_ERROR,N as RESPONSE_RECEIVED,j as SERVER_ERROR_REPSONSE,u as STREAM_READERS,$ as SUCCESSFUL_REPSONSE,n as TEXT_FORMAT,J as createRestClient,I as defaultPathTemplateCallback};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/browser/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../getta/src/constants.ts","../getta/src/helpers/default-path-template-callback/index.ts","../getta/src/helpers/build-endpoint/index.ts","../getta/src/main.ts","../getta/src/helpers/get-response-group/index.ts","../getta/src/helpers/delay/index.ts","../getta/src/helpers/is-cacheability-valid/index.ts"],"sourcesContent":["import { PlainObject } from \"@repodog/types\";\n\nexport const ARRAY_BUFFER_FORMAT = \"arrayBuffer\" as const;\nexport const BLOB_FORMAT = \"blob\" as const;\nexport const FORM_DATA_FORMAT = \"formData\" as const;\nexport const JSON_FORMAT = \"json\" as const;\nexport const TEXT_FORMAT = \"text\" as const;\n\nexport const STREAM_READERS = {\n ARRAY_BUFFER_FORMAT,\n BLOB_FORMAT,\n FORM_DATA_FORMAT,\n JSON_FORMAT,\n TEXT_FORMAT,\n};\n\nexport const DEFAULT_BODY_PARSER = (body: PlainObject) => body;\nexport const DEFAULT_FETCH_TIMEOUT = 5000 as const;\nexport const DEFAULT_HEADERS = { \"content-type\": \"application/json\" };\nexport const DEFAULT_MAX_REDIRECTS = 5 as const;\nexport const DEFAULT_MAX_RETRIES = 3 as const;\nexport const DEFAULT_PATH_TEMPLATE_REGEX = /({type})|({id})|({id,\\+})|({brief\\|standard})/g;\nexport const OPTIONAL_PATH_TEMPLATE_REGEX = /({[a-zA-Z0-9_]+\\?})/g;\nexport const DEFAULT_RATE_LIMIT = 50;\nexport const DEFAULT_REQUEST_RETRY_WAIT = 100;\n\nexport const MISSING_BASE_PATH_ERROR = `Getta expected to receive 'basePath' in the constructor options,\n but recevied undefined.`;\n\nexport const MAX_REDIRECTS_EXCEEDED_ERROR = \"The request exceeded the maximum number of redirects, which is\";\n\nexport const MAX_RETRIES_EXCEEDED_ERROR = \"The request exceeded the maximum number of retries, which is\";\n\nexport const INVALID_FETCH_METHOD_ERROR = \"Getta expected to receive 'get', 'post', 'put' or 'delete', but received\";\n\nexport const RESOURCE_NOT_FOUND_ERROR = \"The requested resource could not been found.\";\n\nexport const FETCH_TIMEOUT_ERROR = \"The request timed out. Getta did not get a response within\";\n\nexport const GET_METHOD = \"get\" as const;\nexport const POST_METHOD = \"post\" as const;\nexport const PUT_METHOD = \"put\" as const;\nexport const DELETE_METHOD = \"delete\" as const;\n\nexport const FETCH_METHODS = [GET_METHOD, POST_METHOD, PUT_METHOD, DELETE_METHOD];\n\nexport const INFORMATION_REPSONSE = \"information\" as const;\nexport const SUCCESSFUL_REPSONSE = \"successful\" as const;\nexport const REDIRECTION_REPSONSE = \"redirection\" as const;\nexport const CLIENT_ERROR_REPSONSE = \"clientError\" as const;\nexport const SERVER_ERROR_REPSONSE = \"serverError\" as const;\n\nexport const NOT_MODIFIED_STATUS_CODE = 304 as const;\nexport const NOT_FOUND_STATUS_CODE = 404 as const;\n\nexport const COOKIE_HEADER = \"Cookie\" as const;\nexport const ETAG_HEADER = \"ETag\" as const;\nexport const LOCATION_HEADER = \"Location\" as const;\nexport const IF_NONE_MATCH_HEADER = \"If-None-Match\" as const;\nexport const CACHE_CONTROL_HEADER = \"Cache-Control\" as const;\n\nexport const REQUEST_SENT = \"request_sent\" as const;\nexport const RESPONSE_RECEIVED = \"response_received\" as const;\n","import { StringObject } from \"@repodog/types\";\n\nexport default function defaultPathTemplateCallback(\n pathTemplate: string,\n data: StringObject,\n pathTemplateRegExp: RegExp,\n) {\n const dataKeys = Object.keys(data);\n\n return pathTemplate.replace(pathTemplateRegExp, match => {\n return dataKeys.reduce((value, key) => {\n if (match.includes(key)) return data[key];\n return value;\n }, \"\");\n });\n}\n","import queryString from \"query-string\";\nimport { BuildEndpointOptions } from \"./types\";\n\nexport default function buildEndpoint(\n basePath: string,\n path: string,\n {\n optionalPathTemplateRegExp,\n pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp,\n queryParams,\n }: BuildEndpointOptions,\n) {\n const pathJoiner = basePath.endsWith(\"/\") || path.startsWith(\"/\") ? \"\" : \"/\";\n let endpoint = `${basePath}${pathJoiner}${path}`;\n\n if (pathTemplateData) {\n endpoint = pathTemplateCallback(endpoint, pathTemplateData, pathTemplateRegExp);\n }\n\n endpoint = endpoint.replace(optionalPathTemplateRegExp, \"\");\n\n if (endpoint.endsWith(\"/\")) {\n endpoint = endpoint.substring(0, endpoint.length - 1);\n }\n\n if (queryParams && Object.keys(queryParams).length) {\n const queryJoin = queryString.extract(endpoint) ? \"&\" : \"?\";\n endpoint = `${endpoint}${queryJoin}${queryString.stringify(queryParams)}`;\n }\n\n return endpoint;\n}\n","import Cachemap, { CacheHeaders } from \"@cachemap/core\";\nimport { Func, PlainObject, StringObject } from \"@repodog/types\";\nimport Cacheability from \"cacheability\";\nimport { castArray, merge } from \"lodash\";\nimport md5 from \"md5\";\nimport { Required } from \"utility-types\";\nimport {\n CACHE_CONTROL_HEADER,\n DEFAULT_BODY_PARSER,\n DEFAULT_FETCH_TIMEOUT,\n DEFAULT_HEADERS,\n DEFAULT_MAX_REDIRECTS,\n DEFAULT_MAX_RETRIES,\n DEFAULT_PATH_TEMPLATE_REGEX,\n DEFAULT_RATE_LIMIT,\n DEFAULT_REQUEST_RETRY_WAIT,\n DELETE_METHOD,\n ETAG_HEADER,\n FETCH_METHODS,\n FETCH_TIMEOUT_ERROR,\n GET_METHOD,\n IF_NONE_MATCH_HEADER,\n INVALID_FETCH_METHOD_ERROR,\n JSON_FORMAT,\n LOCATION_HEADER,\n MAX_REDIRECTS_EXCEEDED_ERROR,\n MAX_RETRIES_EXCEEDED_ERROR,\n MISSING_BASE_PATH_ERROR,\n NOT_FOUND_STATUS_CODE,\n NOT_MODIFIED_STATUS_CODE,\n OPTIONAL_PATH_TEMPLATE_REGEX,\n POST_METHOD,\n PUT_METHOD,\n REDIRECTION_REPSONSE,\n REQUEST_SENT,\n RESOURCE_NOT_FOUND_ERROR,\n RESPONSE_RECEIVED,\n SERVER_ERROR_REPSONSE,\n} from \"./constants\";\nimport buildEndpoint from \"./helpers/build-endpoint\";\nimport defaultPathTemplateCallback from \"./helpers/default-path-template-callback\";\nimport delay from \"./helpers/delay\";\nimport getResponseGroup from \"./helpers/get-response-group\";\nimport isCacheabilityValid from \"./helpers/is-cacheability-valid\";\nimport {\n ConstructorOptions,\n FetchOptions,\n FetchRedirectHandlerOptions,\n FetchResponse,\n Log,\n PathTemplateCallback,\n PendingRequestResolver,\n PendingRequestResolvers,\n Performance,\n RequestOptions,\n RequestQueue,\n RequestTracker,\n ShortcutProperties,\n Shortcuts,\n StreamReader,\n} from \"./types\";\n\nexport class Getta {\n private _basePath: string;\n private _bodyParser: Func;\n private _cache?: Cachemap;\n private _conditionalRequestsEnabled: boolean;\n private _fetchTimeout: number;\n private _headers: StringObject;\n private _log: Log | undefined;\n private _maxRedirects: number;\n private _maxRetries: number;\n private _optionalPathTemplateRegExp: RegExp;\n private _pathTemplateCallback: PathTemplateCallback;\n private _pathTemplateRegExp: RegExp;\n private _performance: Performance;\n private _queryParams: PlainObject;\n private _rateLimitCount: number = 0;\n private _rateLimitedRequestQueue: RequestQueue = [];\n private _rateLimitPerSecond: number;\n private _rateLimitTimer: NodeJS.Timer | null = null;\n private _requestRetryWait: number;\n private _requestTracker: RequestTracker = { active: [], pending: new Map() };\n private _streamReader: StreamReader;\n\n constructor(options: ConstructorOptions) {\n const {\n basePath,\n bodyParser = DEFAULT_BODY_PARSER,\n cache,\n enableConditionalRequests = true,\n fetchTimeout = DEFAULT_FETCH_TIMEOUT,\n headers,\n log,\n maxRedirects = DEFAULT_MAX_REDIRECTS,\n maxRetries = DEFAULT_MAX_RETRIES,\n optionalPathTemplateRegExp = OPTIONAL_PATH_TEMPLATE_REGEX,\n pathTemplateCallback = defaultPathTemplateCallback,\n pathTemplateRegExp = DEFAULT_PATH_TEMPLATE_REGEX,\n performance,\n queryParams = {},\n rateLimitPerSecond = DEFAULT_RATE_LIMIT,\n requestRetryWait = DEFAULT_REQUEST_RETRY_WAIT,\n streamReader = JSON_FORMAT,\n } = options;\n\n if (!basePath) {\n throw new Error(MISSING_BASE_PATH_ERROR);\n }\n\n this._basePath = basePath;\n this._bodyParser = bodyParser;\n this._cache = cache;\n this._conditionalRequestsEnabled = enableConditionalRequests;\n this._fetchTimeout = fetchTimeout;\n this._headers = { ...DEFAULT_HEADERS, ...(headers || {}) };\n this._log = log;\n this._maxRedirects = maxRedirects;\n this._maxRetries = maxRetries;\n this._optionalPathTemplateRegExp = optionalPathTemplateRegExp;\n this._pathTemplateCallback = pathTemplateCallback;\n this._pathTemplateRegExp = pathTemplateRegExp;\n this._performance = performance;\n this._queryParams = queryParams;\n this._rateLimitPerSecond = rateLimitPerSecond;\n this._requestRetryWait = requestRetryWait;\n this._streamReader = streamReader;\n }\n\n get cache(): Cachemap | undefined {\n return this._cache;\n }\n\n public createShortcut(name: string, path: string, { method, ...otherOptions }: Required<RequestOptions, \"method\">) {\n if (!FETCH_METHODS.includes(method)) {\n throw new Error(`${INVALID_FETCH_METHOD_ERROR} ${method}`);\n }\n\n // @ts-ignore\n this[name] = async <Resource extends PlainObject>(\n { method: requestMethod, ...otherOptionOverrides }: RequestOptions = {},\n context?: PlainObject,\n ) =>\n // @ts-ignore\n this[requestMethod ?? method](path, merge({}, otherOptions, otherOptionOverrides), context) as Promise<\n FetchResponse<Resource>\n >;\n }\n\n public async delete(path: string, options: Omit<RequestOptions, \"method\"> = {}, context?: PlainObject) {\n return this._delete(path, options, context);\n }\n\n public async get(path: string, options: Omit<RequestOptions, \"method\"> = {}, context?: PlainObject) {\n return this._get(path, options, context);\n }\n\n public async post(path: string, options: Omit<Required<RequestOptions, \"body\">, \"method\">, context?: PlainObject) {\n return this._request(path, { ...options, method: POST_METHOD }, context);\n }\n\n public async put(path: string, options: Omit<Required<RequestOptions, \"body\">, \"methood\">, context?: PlainObject) {\n return this._request(path, { ...options, method: PUT_METHOD }, context);\n }\n\n private _addRequestToRateLimitedQueue(endpoint: string, options: FetchOptions, context: PlainObject) {\n return new Promise((resolve: (value: FetchResponse) => void) => {\n this._rateLimitedRequestQueue.push([resolve, endpoint, options, context]);\n });\n }\n\n private async _cacheEntryDelete(requestHash: string): Promise<boolean> {\n if (!this._cache) return false;\n\n try {\n return await this._cache.delete(requestHash);\n } catch (errors) {\n return Promise.reject(errors);\n }\n }\n\n private async _cacheEntryGet(requestHash: string): Promise<PlainObject | undefined> {\n if (!this._cache) return undefined;\n\n try {\n return await this._cache.get(requestHash);\n } catch (errors) {\n return Promise.reject(errors);\n }\n }\n\n private async _cacheEntryHas(requestHash: string): Promise<Cacheability | false> {\n if (!this._cache) return false;\n\n try {\n return await this._cache.has(requestHash);\n } catch (error) {\n return false;\n }\n }\n\n private async _cacheEntrySet(requestHash: string, data: PlainObject, cacheHeaders: CacheHeaders): Promise<void> {\n if (!this._cache) return undefined;\n\n try {\n return await this._cache.set(requestHash, data, { cacheHeaders });\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n private async _delete(\n path: string,\n { headers = {}, pathTemplateData, queryParams = {}, ...rest }: Omit<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n const requestHash = md5(endpoint);\n const cacheability = await this._cacheEntryHas(requestHash);\n\n if (cacheability) {\n this._cacheEntryDelete(requestHash);\n }\n\n return this._fetch(\n endpoint,\n {\n headers: { ...this._headers, ...headers },\n method: DELETE_METHOD,\n ...rest,\n },\n context,\n );\n }\n\n private async _fetch(endpoint: string, options: FetchOptions, context: PlainObject = {}): Promise<FetchResponse> {\n context.startTime = this._performance.now();\n\n try {\n const { redirects, retries, ...rest } = options;\n return await new Promise(async (resolve: (value: FetchResponse) => void, reject) => {\n const fetchTimer = setTimeout(() => {\n reject(new Error(`${FETCH_TIMEOUT_ERROR} ${this._fetchTimeout}ms.`));\n }, this._fetchTimeout);\n\n this._rateLimit();\n\n if (!(this._rateLimitCount < this._rateLimitPerSecond)) {\n clearTimeout(fetchTimer);\n resolve(await this._addRequestToRateLimitedQueue(endpoint, options, context));\n return;\n }\n\n if (!redirects && !retries) {\n this._log?.(REQUEST_SENT, {\n context: { redirects, retries, url: endpoint, ...rest, ...context },\n stats: { startTime: context.startTime },\n });\n }\n\n const res = await fetch(endpoint, rest);\n\n clearTimeout(fetchTimer);\n\n const { headers, status } = res;\n const responseGroup = getResponseGroup(status);\n\n if (responseGroup === REDIRECTION_REPSONSE && headers.get(LOCATION_HEADER)) {\n resolve(\n await this._fetchRedirectHandler(\n res,\n headers.get(LOCATION_HEADER) as string,\n {\n redirects,\n status,\n ...rest,\n },\n context,\n ),\n );\n\n return;\n }\n\n if (responseGroup === SERVER_ERROR_REPSONSE) {\n resolve(\n (await this._fetchRetryHandler(\n res,\n endpoint,\n {\n retries,\n ...rest,\n },\n context,\n )) as FetchResponse,\n );\n\n return;\n }\n\n const fetchRes = res as FetchResponse;\n\n try {\n fetchRes.data = res.body ? this._bodyParser(await res[this._streamReader]()) : undefined;\n this._logResponse(fetchRes, endpoint, options, context);\n resolve(fetchRes);\n } catch (e) {\n reject([e, new Error(`Unable to ${rest.method} ${endpoint} due to previous error`)]);\n }\n });\n } catch (error) {\n const fetchRes = { errors: castArray(error) };\n this._logResponse(fetchRes as FetchResponse, endpoint, options, context);\n return fetchRes as FetchResponse;\n }\n }\n\n private async _fetchRedirectHandler(\n res: Response,\n endpoint: string,\n options: FetchRedirectHandlerOptions,\n context: PlainObject,\n ): Promise<FetchResponse> {\n const { method, redirects = 1, status, ...rest } = options;\n\n if (redirects === this._maxRedirects) {\n const fetchRes = res as FetchResponse;\n fetchRes.errors = [new Error(`${MAX_REDIRECTS_EXCEEDED_ERROR} ${this._maxRedirects}.`)];\n this._logResponse(fetchRes, endpoint, options, context);\n return fetchRes;\n }\n\n const redirectMethod = status === 303 ? GET_METHOD : method;\n return this._fetch(endpoint, { method: redirectMethod, redirects: redirects + 1, ...rest });\n }\n\n private async _fetchRetryHandler(res: Response, endpoint: string, options: FetchOptions, context: PlainObject) {\n const { retries = 1, ...rest } = options;\n\n if (retries === this._maxRetries) {\n const fetchRes = res as FetchResponse;\n fetchRes.errors = [new Error(`${MAX_RETRIES_EXCEEDED_ERROR} ${this._maxRetries}.`)];\n this._logResponse(fetchRes, endpoint, options, context);\n return fetchRes;\n }\n\n await delay(this._requestRetryWait);\n return this._fetch(endpoint, { retries: retries + 1, ...rest });\n }\n\n private async _get(\n path: string,\n { headers = {}, pathTemplateData, queryParams = {} }: Omit<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n const requestHash = md5(endpoint);\n const cacheability = await this._cacheEntryHas(requestHash);\n\n if (cacheability) {\n if (isCacheabilityValid(cacheability)) {\n return {\n data: await this._cacheEntryGet(requestHash),\n headers: new Headers({ \"cache-control\": cacheability.printCacheControl() }),\n };\n }\n\n if (this._conditionalRequestsEnabled) {\n const etag = cacheability?.metadata?.etag ?? null;\n if (etag) headers[IF_NONE_MATCH_HEADER] = etag;\n }\n }\n\n const pendingRequest = this._trackRequest(requestHash);\n if (pendingRequest) return pendingRequest;\n\n return this._getResolve(\n requestHash,\n await this._fetch(endpoint, { headers: { ...this._headers, ...headers }, method: GET_METHOD }, context),\n );\n }\n\n private async _getResolve(requestHash: string, res: FetchResponse) {\n const { data, headers, status } = res;\n\n if (status === NOT_FOUND_STATUS_CODE) {\n this._cacheEntryDelete(requestHash);\n\n if (!res.errors) {\n res.errors = [];\n }\n\n res.errors.push(new Error(RESOURCE_NOT_FOUND_ERROR));\n } else if (status === NOT_MODIFIED_STATUS_CODE && headers) {\n const cachedData = await this._cacheEntryGet(requestHash);\n\n if (cachedData) {\n this._cacheEntrySet(requestHash, cachedData, {\n cacheControl: headers.get(CACHE_CONTROL_HEADER) || undefined,\n etag: headers.get(ETAG_HEADER) || undefined,\n });\n\n res.data = cachedData;\n }\n } else if (data && headers) {\n this._cacheEntrySet(requestHash, data, {\n cacheControl: headers.get(CACHE_CONTROL_HEADER) || undefined,\n etag: headers.get(ETAG_HEADER) || undefined,\n });\n }\n\n this._resolvePendingRequests(requestHash, res);\n this._requestTracker.active = this._requestTracker.active.filter(value => value !== requestHash);\n return res;\n }\n\n private _logResponse(res: FetchResponse, endpoint: string, options: FetchOptions, context: PlainObject) {\n const { data, errors, headers, status } = res;\n const { redirects, retries } = options;\n const { startTime, ...otherContext } = context;\n\n const endTime = this._performance.now();\n const duration = endTime - startTime;\n\n this._log?.(RESPONSE_RECEIVED, {\n context: {\n body: data ? { data } : { errors: errors ?? [] },\n headers,\n method: options.method,\n redirects,\n retries,\n status,\n url: endpoint,\n ...otherContext,\n },\n stats: { duration, endTime, startTime },\n });\n }\n\n private _rateLimit() {\n if (!this._rateLimitTimer) {\n this._rateLimitTimer = setTimeout(() => {\n this._rateLimitTimer = null;\n this._rateLimitCount = 0;\n\n if (this._rateLimitedRequestQueue.length) {\n this._releaseRateLimitedRequestQueue();\n }\n }, 1000);\n }\n\n this._rateLimitCount += 1;\n }\n\n private _releaseRateLimitedRequestQueue() {\n this._rateLimitedRequestQueue.forEach(async ([resolve, endpoint, options, context]) => {\n // @ts-ignore\n resolve(await this._fetch(endpoint, options, context));\n });\n\n this._rateLimitedRequestQueue = [];\n }\n\n private async _request(\n path: string,\n { body, headers, method, pathTemplateData, queryParams, ...rest }: Required<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n return this._fetch(\n endpoint,\n {\n body,\n headers: { ...this._headers, ...headers },\n method,\n ...rest,\n },\n context,\n );\n }\n\n private _resolvePendingRequests(requestHash: string, responseData: FetchResponse) {\n const pendingRequests = this._requestTracker.pending.get(requestHash);\n if (!pendingRequests) return;\n\n pendingRequests.forEach(({ resolve }) => {\n resolve(responseData);\n });\n\n this._requestTracker.pending.delete(requestHash);\n }\n\n private _setPendingRequest(requestHash: string, resolver: PendingRequestResolvers) {\n let pending = this._requestTracker.pending.get(requestHash);\n if (!pending) pending = [];\n pending.push(resolver);\n this._requestTracker.pending.set(requestHash, pending);\n }\n\n private _trackRequest(requestHash: string): Promise<FetchResponse> | void {\n if (this._requestTracker.active.includes(requestHash)) {\n return new Promise((resolve: PendingRequestResolver) => {\n this._setPendingRequest(requestHash, { resolve });\n });\n }\n\n this._requestTracker.active.push(requestHash);\n }\n}\n\nexport default function createRestClient<N extends string>(options: ConstructorOptions, shortcuts?: Shortcuts) {\n const getta = new Getta(options) as Getta & ShortcutProperties<N>;\n if (!shortcuts) return getta;\n\n Object.keys(shortcuts).forEach(key => {\n getta.createShortcut(key, ...shortcuts[key]);\n });\n\n return getta;\n}\n","import {\n CLIENT_ERROR_REPSONSE,\n INFORMATION_REPSONSE,\n REDIRECTION_REPSONSE,\n SERVER_ERROR_REPSONSE,\n SUCCESSFUL_REPSONSE,\n} from \"../../constants\";\n\nexport default function getResponseGroup(status: number) {\n switch (true) {\n case status < 200:\n return INFORMATION_REPSONSE;\n case status < 300:\n return SUCCESSFUL_REPSONSE;\n case status < 400:\n return REDIRECTION_REPSONSE;\n case status < 500:\n return CLIENT_ERROR_REPSONSE;\n default:\n return SERVER_ERROR_REPSONSE;\n }\n}\n","export default function delay(ms: number) {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n","import Cacheability from \"cacheability\";\n\nexport default function isCacheabilityValid(cacheability: Cacheability) {\n const noCache = cacheability?.metadata?.cacheControl?.noCache ?? false;\n return !noCache && cacheability.checkTTL();\n}\n"],"names":["ARRAY_BUFFER_FORMAT","BLOB_FORMAT","FORM_DATA_FORMAT","JSON_FORMAT","TEXT_FORMAT","STREAM_READERS","DEFAULT_BODY_PARSER","body","DEFAULT_FETCH_TIMEOUT","DEFAULT_HEADERS","DEFAULT_MAX_REDIRECTS","DEFAULT_MAX_RETRIES","DEFAULT_PATH_TEMPLATE_REGEX","OPTIONAL_PATH_TEMPLATE_REGEX","DEFAULT_RATE_LIMIT","DEFAULT_REQUEST_RETRY_WAIT","MISSING_BASE_PATH_ERROR","MAX_REDIRECTS_EXCEEDED_ERROR","MAX_RETRIES_EXCEEDED_ERROR","INVALID_FETCH_METHOD_ERROR","RESOURCE_NOT_FOUND_ERROR","FETCH_TIMEOUT_ERROR","GET_METHOD","POST_METHOD","PUT_METHOD","DELETE_METHOD","FETCH_METHODS","INFORMATION_REPSONSE","SUCCESSFUL_REPSONSE","REDIRECTION_REPSONSE","CLIENT_ERROR_REPSONSE","SERVER_ERROR_REPSONSE","NOT_MODIFIED_STATUS_CODE","NOT_FOUND_STATUS_CODE","COOKIE_HEADER","ETAG_HEADER","LOCATION_HEADER","IF_NONE_MATCH_HEADER","CACHE_CONTROL_HEADER","REQUEST_SENT","RESPONSE_RECEIVED","defaultPathTemplateCallback","pathTemplate","data","pathTemplateRegExp","dataKeys","Object","keys","replace","match","reduce","value","key","includes","buildEndpoint","basePath","path","optionalPathTemplateRegExp","pathTemplateCallback","pathTemplateData","queryParams","pathJoiner","endsWith","startsWith","endpoint","substring","length","queryString","extract","stringify","Getta","constructor","options","active","pending","Map","bodyParser","cache","enableConditionalRequests","fetchTimeout","headers","log","maxRedirects","maxRetries","performance","rateLimitPerSecond","requestRetryWait","streamReader","Error","_basePath","_bodyParser","_cache","_conditionalRequestsEnabled","_fetchTimeout","_headers","_log","_maxRedirects","_maxRetries","_optionalPathTemplateRegExp","_pathTemplateCallback","_pathTemplateRegExp","_performance","_queryParams","_rateLimitPerSecond","_requestRetryWait","_streamReader","this","createShortcut","name","method","otherOptions","async","requestMethod","otherOptionOverrides","context","_merge","_delete","_get","_request","_addRequestToRateLimitedQueue","Promise","resolve","_rateLimitedRequestQueue","push","requestHash","delete","errors","reject","get","has","error","cacheHeaders","set","rest","md5","_cacheEntryHas","_cacheEntryDelete","_fetch","startTime","now","redirects","retries","fetchTimer","setTimeout","_rateLimit","_rateLimitCount","clearTimeout","url","stats","res","fetch","status","responseGroup","getResponseGroup","_fetchRedirectHandler","_fetchRetryHandler","fetchRes","undefined","_logResponse","e","_castArray","redirectMethod","ms","cacheability","metadata","_cacheability$metadat2","cacheControl","_cacheability$metadat3","noCache","checkTTL","isCacheabilityValid","_cacheEntryGet","Headers","printCacheControl","etag","pendingRequest","_trackRequest","_getResolve","cachedData","_cacheEntrySet","_resolvePendingRequests","_requestTracker","filter","otherContext","endTime","duration","_rateLimitTimer","_releaseRateLimitedRequestQueue","forEach","responseData","pendingRequests","_setPendingRequest","resolver","shortcuts","getta"],"mappings":"4MAEaA,EAAsB,cACtBC,EAAc,OACdC,EAAmB,WACnBC,EAAc,OACdC,EAAc,OAEdC,EAAi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,EAAqBoE,OAC1CtH,EAAUgC,KAAK2E,gBAAgB3G,QAAQsD,IAAIJ,GAC1ClD,IAASA,EAAU,IACxBA,EAAQiD,KAAKqE,QACRX,gBAAgB3G,QAAQ0D,IAAIR,EAAalD,GAGxCsG,cAAcpD,MAChBlB,KAAK2E,gBAAgB5G,OAAOpB,SAASuE,UAChC,IAAIJ,QAASC,SACbsE,mBAAmBnE,EAAa,CAAEH,QAAAA,WAItC4D,gBAAgB5G,OAAOkD,KAAKC,mBAItB,SAA4CpD,EAA6ByH,SAChFC,EAAQ,IAAI5H,EAAME,UACnByH,GAELnJ,OAAOC,KAAKkJ,GAAWL,QAAQxI,IAC7B8I,EAAMvF,eAAevD,KAAQ6I,EAAU7I,MAGlC8I,GANgBA"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../getta/src/constants.ts","../getta/src/helpers/default-path-template-callback/index.ts","../getta/src/helpers/build-endpoint/index.ts","../getta/src/main.ts","../getta/src/helpers/get-response-group/index.ts","../getta/src/helpers/delay/index.ts","../getta/src/helpers/is-cacheability-valid/index.ts"],"sourcesContent":["import { PlainObject } from \"@repodog/types\";\n\nexport const ARRAY_BUFFER_FORMAT = \"arrayBuffer\" as const;\nexport const BLOB_FORMAT = \"blob\" as const;\nexport const FORM_DATA_FORMAT = \"formData\" as const;\nexport const JSON_FORMAT = \"json\" as const;\nexport const TEXT_FORMAT = \"text\" as const;\n\nexport const STREAM_READERS = {\n ARRAY_BUFFER_FORMAT,\n BLOB_FORMAT,\n FORM_DATA_FORMAT,\n JSON_FORMAT,\n TEXT_FORMAT,\n};\n\nexport const DEFAULT_BODY_PARSER = (body: PlainObject) => body;\nexport const DEFAULT_FETCH_TIMEOUT = 5000 as const;\nexport const DEFAULT_HEADERS = { \"content-type\": \"application/json\" };\nexport const DEFAULT_MAX_REDIRECTS = 5 as const;\nexport const DEFAULT_MAX_RETRIES = 3 as const;\nexport const DEFAULT_PATH_TEMPLATE_REGEX = /({type})|({id})|({id,\\+})|({brief\\|standard})/g;\nexport const OPTIONAL_PATH_TEMPLATE_REGEX = /({[a-zA-Z0-9_]+\\?})/g;\nexport const DEFAULT_RATE_LIMIT = 50;\nexport const DEFAULT_REQUEST_RETRY_WAIT = 100;\n\nexport const MISSING_BASE_PATH_ERROR = `Getta expected to receive 'basePath' in the constructor options,\n but recevied undefined.`;\n\nexport const MAX_REDIRECTS_EXCEEDED_ERROR = \"The request exceeded the maximum number of redirects, which is\";\n\nexport const MAX_RETRIES_EXCEEDED_ERROR = \"The request exceeded the maximum number of retries, which is\";\n\nexport const INVALID_FETCH_METHOD_ERROR = \"Getta expected to receive 'get', 'post', 'put' or 'delete', but received\";\n\nexport const RESOURCE_NOT_FOUND_ERROR = \"The requested resource could not been found.\";\n\nexport const FETCH_TIMEOUT_ERROR = \"The request timed out. Getta did not get a response within\";\n\nexport const GET_METHOD = \"get\" as const;\nexport const POST_METHOD = \"post\" as const;\nexport const PUT_METHOD = \"put\" as const;\nexport const DELETE_METHOD = \"delete\" as const;\n\nexport const FETCH_METHODS = [GET_METHOD, POST_METHOD, PUT_METHOD, DELETE_METHOD];\n\nexport const INFORMATION_REPSONSE = \"information\" as const;\nexport const SUCCESSFUL_REPSONSE = \"successful\" as const;\nexport const REDIRECTION_REPSONSE = \"redirection\" as const;\nexport const CLIENT_ERROR_REPSONSE = \"clientError\" as const;\nexport const SERVER_ERROR_REPSONSE = \"serverError\" as const;\n\nexport const NOT_MODIFIED_STATUS_CODE = 304 as const;\nexport const NOT_FOUND_STATUS_CODE = 404 as const;\n\nexport const COOKIE_HEADER = \"Cookie\" as const;\nexport const ETAG_HEADER = \"ETag\" as const;\nexport const LOCATION_HEADER = \"Location\" as const;\nexport const IF_NONE_MATCH_HEADER = \"If-None-Match\" as const;\nexport const CACHE_CONTROL_HEADER = \"Cache-Control\" as const;\n\nexport const REQUEST_SENT = \"request_sent\" as const;\nexport const RESPONSE_RECEIVED = \"response_received\" as const;\n","import { StringObject } from \"@repodog/types\";\n\nexport default function defaultPathTemplateCallback(\n pathTemplate: string,\n data: StringObject,\n pathTemplateRegExp: RegExp,\n) {\n const dataKeys = Object.keys(data);\n\n return pathTemplate.replace(pathTemplateRegExp, match => {\n return dataKeys.reduce((value, key) => {\n if (match.includes(key)) return data[key];\n return value;\n }, \"\");\n });\n}\n","import queryString from \"query-string\";\nimport { BuildEndpointOptions } from \"./types\";\n\nexport default function buildEndpoint(\n basePath: string,\n path: string,\n {\n optionalPathTemplateRegExp,\n pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp,\n queryParams,\n }: BuildEndpointOptions,\n) {\n const pathJoiner = basePath.endsWith(\"/\") || path.startsWith(\"/\") ? \"\" : \"/\";\n let endpoint = `${basePath}${pathJoiner}${path}`;\n\n if (pathTemplateData) {\n endpoint = pathTemplateCallback(endpoint, pathTemplateData, pathTemplateRegExp);\n }\n\n endpoint = endpoint.replace(optionalPathTemplateRegExp, \"\");\n\n if (endpoint.endsWith(\"/\")) {\n endpoint = endpoint.substring(0, endpoint.length - 1);\n }\n\n if (queryParams && Object.keys(queryParams).length) {\n const queryJoin = queryString.extract(endpoint) ? \"&\" : \"?\";\n endpoint = `${endpoint}${queryJoin}${queryString.stringify(queryParams)}`;\n }\n\n return endpoint;\n}\n","import Cachemap, { CacheHeaders } from \"@cachemap/core\";\nimport { Func, PlainObject, StringObject } from \"@repodog/types\";\nimport Cacheability from \"cacheability\";\nimport { castArray, merge } from \"lodash\";\nimport md5 from \"md5\";\nimport { Required } from \"utility-types\";\nimport {\n CACHE_CONTROL_HEADER,\n DEFAULT_BODY_PARSER,\n DEFAULT_FETCH_TIMEOUT,\n DEFAULT_HEADERS,\n DEFAULT_MAX_REDIRECTS,\n DEFAULT_MAX_RETRIES,\n DEFAULT_PATH_TEMPLATE_REGEX,\n DEFAULT_RATE_LIMIT,\n DEFAULT_REQUEST_RETRY_WAIT,\n DELETE_METHOD,\n ETAG_HEADER,\n FETCH_METHODS,\n FETCH_TIMEOUT_ERROR,\n GET_METHOD,\n IF_NONE_MATCH_HEADER,\n INVALID_FETCH_METHOD_ERROR,\n JSON_FORMAT,\n LOCATION_HEADER,\n MAX_REDIRECTS_EXCEEDED_ERROR,\n MAX_RETRIES_EXCEEDED_ERROR,\n MISSING_BASE_PATH_ERROR,\n NOT_FOUND_STATUS_CODE,\n NOT_MODIFIED_STATUS_CODE,\n OPTIONAL_PATH_TEMPLATE_REGEX,\n POST_METHOD,\n PUT_METHOD,\n REDIRECTION_REPSONSE,\n REQUEST_SENT,\n RESOURCE_NOT_FOUND_ERROR,\n RESPONSE_RECEIVED,\n SERVER_ERROR_REPSONSE,\n} from \"./constants\";\nimport buildEndpoint from \"./helpers/build-endpoint\";\nimport defaultPathTemplateCallback from \"./helpers/default-path-template-callback\";\nimport delay from \"./helpers/delay\";\nimport getResponseGroup from \"./helpers/get-response-group\";\nimport isCacheabilityValid from \"./helpers/is-cacheability-valid\";\nimport {\n ConstructorOptions,\n FetchOptions,\n FetchRedirectHandlerOptions,\n FetchResponse,\n Log,\n PathTemplateCallback,\n PendingRequestResolver,\n PendingRequestResolvers,\n Performance,\n RequestOptions,\n RequestQueue,\n RequestTracker,\n ShortcutProperties,\n Shortcuts,\n StreamReader,\n} from \"./types\";\n\nexport class Getta {\n private _basePath: string;\n private _bodyParser: Func;\n private _cache?: Cachemap;\n private _conditionalRequestsEnabled: boolean;\n private _fetchTimeout: number;\n private _headers: StringObject;\n private _log: Log | undefined;\n private _maxRedirects: number;\n private _maxRetries: number;\n private _optionalPathTemplateRegExp: RegExp;\n private _pathTemplateCallback: PathTemplateCallback;\n private _pathTemplateRegExp: RegExp;\n private _performance: Performance;\n private _queryParams: PlainObject;\n private _rateLimitCount: number = 0;\n private _rateLimitedRequestQueue: RequestQueue = [];\n private _rateLimitPerSecond: number;\n private _rateLimitTimer: NodeJS.Timer | null = null;\n private _requestRetryWait: number;\n private _requestTracker: RequestTracker = { active: [], pending: new Map() };\n private _streamReader: StreamReader;\n\n constructor(options: ConstructorOptions) {\n const {\n basePath,\n bodyParser = DEFAULT_BODY_PARSER,\n cache,\n enableConditionalRequests = true,\n fetchTimeout = DEFAULT_FETCH_TIMEOUT,\n headers,\n log,\n maxRedirects = DEFAULT_MAX_REDIRECTS,\n maxRetries = DEFAULT_MAX_RETRIES,\n optionalPathTemplateRegExp = OPTIONAL_PATH_TEMPLATE_REGEX,\n pathTemplateCallback = defaultPathTemplateCallback,\n pathTemplateRegExp = DEFAULT_PATH_TEMPLATE_REGEX,\n performance,\n queryParams = {},\n rateLimitPerSecond = DEFAULT_RATE_LIMIT,\n requestRetryWait = DEFAULT_REQUEST_RETRY_WAIT,\n streamReader = JSON_FORMAT,\n } = options;\n\n if (!basePath) {\n throw new Error(MISSING_BASE_PATH_ERROR);\n }\n\n this._basePath = basePath;\n this._bodyParser = bodyParser;\n this._cache = cache;\n this._conditionalRequestsEnabled = enableConditionalRequests;\n this._fetchTimeout = fetchTimeout;\n this._headers = { ...DEFAULT_HEADERS, ...(headers || {}) };\n this._log = log;\n this._maxRedirects = maxRedirects;\n this._maxRetries = maxRetries;\n this._optionalPathTemplateRegExp = optionalPathTemplateRegExp;\n this._pathTemplateCallback = pathTemplateCallback;\n this._pathTemplateRegExp = pathTemplateRegExp;\n this._performance = performance;\n this._queryParams = queryParams;\n this._rateLimitPerSecond = rateLimitPerSecond;\n this._requestRetryWait = requestRetryWait;\n this._streamReader = streamReader;\n }\n\n get cache(): Cachemap | undefined {\n return this._cache;\n }\n\n public createShortcut(name: string, path: string, { method, ...otherOptions }: Required<RequestOptions, \"method\">) {\n if (!FETCH_METHODS.includes(method)) {\n throw new Error(`${INVALID_FETCH_METHOD_ERROR} ${method}`);\n }\n\n // @ts-ignore\n this[name] = async <Resource extends PlainObject>(\n { method: requestMethod, ...otherOptionOverrides }: RequestOptions = {},\n context?: PlainObject,\n ) =>\n // @ts-ignore\n this[requestMethod ?? method](path, merge({}, otherOptions, otherOptionOverrides), context) as Promise<\n FetchResponse<Resource>\n >;\n }\n\n public async delete(path: string, options: Omit<RequestOptions, \"method\"> = {}, context?: PlainObject) {\n return this._delete(path, options, context);\n }\n\n public async get(path: string, options: Omit<RequestOptions, \"method\"> = {}, context?: PlainObject) {\n return this._get(path, options, context);\n }\n\n public async post(path: string, options: Omit<Required<RequestOptions, \"body\">, \"method\">, context?: PlainObject) {\n return this._request(path, { ...options, method: POST_METHOD }, context);\n }\n\n public async put(path: string, options: Omit<Required<RequestOptions, \"body\">, \"methood\">, context?: PlainObject) {\n return this._request(path, { ...options, method: PUT_METHOD }, context);\n }\n\n private _addRequestToRateLimitedQueue(endpoint: string, options: FetchOptions, context: PlainObject) {\n return new Promise((resolve: (value: FetchResponse) => void) => {\n this._rateLimitedRequestQueue.push([resolve, endpoint, options, context]);\n });\n }\n\n private async _cacheEntryDelete(requestHash: string): Promise<boolean> {\n if (!this._cache) return false;\n\n try {\n return await this._cache.delete(requestHash);\n } catch (errors) {\n return Promise.reject(errors);\n }\n }\n\n private async _cacheEntryGet(requestHash: string): Promise<PlainObject | undefined> {\n if (!this._cache) return undefined;\n\n try {\n return await this._cache.get(requestHash);\n } catch (errors) {\n return Promise.reject(errors);\n }\n }\n\n private async _cacheEntryHas(requestHash: string): Promise<Cacheability | false> {\n if (!this._cache) return false;\n\n try {\n return await this._cache.has(requestHash);\n } catch (error) {\n return false;\n }\n }\n\n private async _cacheEntrySet(requestHash: string, data: PlainObject, cacheHeaders: CacheHeaders): Promise<void> {\n if (!this._cache) return undefined;\n\n try {\n return await this._cache.set(requestHash, data, { cacheHeaders });\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n private async _delete(\n path: string,\n { headers = {}, pathTemplateData, queryParams = {}, ...rest }: Omit<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n const requestHash = md5(endpoint);\n const cacheability = await this._cacheEntryHas(requestHash);\n\n if (cacheability) {\n this._cacheEntryDelete(requestHash);\n }\n\n return this._fetch(\n endpoint,\n {\n headers: { ...this._headers, ...headers },\n method: DELETE_METHOD,\n ...rest,\n },\n context,\n );\n }\n\n private async _fetch(endpoint: string, options: FetchOptions, context: PlainObject = {}): Promise<FetchResponse> {\n context.startTime = this._performance.now();\n\n try {\n const { redirects, retries, ...rest } = options;\n return await new Promise(async (resolve: (value: FetchResponse) => void, reject) => {\n const fetchTimer = setTimeout(() => {\n reject(new Error(`${FETCH_TIMEOUT_ERROR} ${this._fetchTimeout}ms.`));\n }, this._fetchTimeout);\n\n this._rateLimit();\n\n if (!(this._rateLimitCount < this._rateLimitPerSecond)) {\n clearTimeout(fetchTimer);\n resolve(await this._addRequestToRateLimitedQueue(endpoint, options, context));\n return;\n }\n\n if (!redirects && !retries) {\n this._log?.(REQUEST_SENT, {\n context: { redirects, retries, url: endpoint, ...rest, ...context },\n stats: { startTime: context.startTime },\n });\n }\n\n const res = await fetch(endpoint, rest);\n\n clearTimeout(fetchTimer);\n\n const { headers, status } = res;\n const responseGroup = getResponseGroup(status);\n\n if (responseGroup === REDIRECTION_REPSONSE && headers.get(LOCATION_HEADER)) {\n resolve(\n await this._fetchRedirectHandler(\n res,\n headers.get(LOCATION_HEADER) as string,\n {\n redirects,\n status,\n ...rest,\n },\n context,\n ),\n );\n\n return;\n }\n\n if (responseGroup === SERVER_ERROR_REPSONSE) {\n resolve(\n (await this._fetchRetryHandler(\n res,\n endpoint,\n {\n retries,\n ...rest,\n },\n context,\n )) as FetchResponse,\n );\n\n return;\n }\n\n const fetchRes = res as FetchResponse;\n\n try {\n fetchRes.data = res.body ? this._bodyParser(await res[this._streamReader]()) : undefined;\n this._logResponse(fetchRes, endpoint, options, context);\n resolve(fetchRes);\n } catch (e) {\n reject([e, new Error(`Unable to ${rest.method} ${endpoint} due to previous error`)]);\n }\n });\n } catch (error) {\n const fetchRes = { errors: castArray(error) };\n this._logResponse(fetchRes as FetchResponse, endpoint, options, context);\n return fetchRes as FetchResponse;\n }\n }\n\n private async _fetchRedirectHandler(\n res: Response,\n endpoint: string,\n options: FetchRedirectHandlerOptions,\n context: PlainObject,\n ): Promise<FetchResponse> {\n const { method, redirects = 1, status, ...rest } = options;\n\n if (redirects === this._maxRedirects) {\n const fetchRes = res as FetchResponse;\n fetchRes.errors = [new Error(`${MAX_REDIRECTS_EXCEEDED_ERROR} ${this._maxRedirects}.`)];\n this._logResponse(fetchRes, endpoint, options, context);\n return fetchRes;\n }\n\n const redirectMethod = status === 303 ? GET_METHOD : method;\n return this._fetch(endpoint, { method: redirectMethod, redirects: redirects + 1, ...rest });\n }\n\n private async _fetchRetryHandler(res: Response, endpoint: string, options: FetchOptions, context: PlainObject) {\n const { retries = 1, ...rest } = options;\n\n if (retries === this._maxRetries) {\n const fetchRes = res as FetchResponse;\n fetchRes.errors = [new Error(`${MAX_RETRIES_EXCEEDED_ERROR} ${this._maxRetries}.`)];\n this._logResponse(fetchRes, endpoint, options, context);\n return fetchRes;\n }\n\n await delay(this._requestRetryWait);\n return this._fetch(endpoint, { retries: retries + 1, ...rest });\n }\n\n private async _get(\n path: string,\n { headers = {}, pathTemplateData, queryParams = {} }: Omit<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n const requestHash = md5(endpoint);\n const cacheability = await this._cacheEntryHas(requestHash);\n\n if (cacheability) {\n if (isCacheabilityValid(cacheability)) {\n return {\n data: await this._cacheEntryGet(requestHash),\n headers: new Headers({ \"cache-control\": cacheability.printCacheControl() }),\n };\n }\n\n if (this._conditionalRequestsEnabled) {\n const etag = cacheability?.metadata?.etag ?? null;\n if (etag) headers[IF_NONE_MATCH_HEADER] = etag;\n }\n }\n\n const pendingRequest = this._trackRequest(requestHash);\n if (pendingRequest) return pendingRequest;\n\n return this._getResolve(\n requestHash,\n await this._fetch(endpoint, { headers: { ...this._headers, ...headers }, method: GET_METHOD }, context),\n );\n }\n\n private async _getResolve(requestHash: string, res: FetchResponse) {\n const { data, headers, status } = res;\n\n if (status === NOT_FOUND_STATUS_CODE) {\n this._cacheEntryDelete(requestHash);\n\n if (!res.errors) {\n res.errors = [];\n }\n\n res.errors.push(new Error(RESOURCE_NOT_FOUND_ERROR));\n } else if (status === NOT_MODIFIED_STATUS_CODE && headers) {\n const cachedData = await this._cacheEntryGet(requestHash);\n\n if (cachedData) {\n this._cacheEntrySet(requestHash, cachedData, {\n cacheControl: headers.get(CACHE_CONTROL_HEADER) || undefined,\n etag: headers.get(ETAG_HEADER) || undefined,\n });\n\n res.data = cachedData;\n }\n } else if (data && headers) {\n this._cacheEntrySet(requestHash, data, {\n cacheControl: headers.get(CACHE_CONTROL_HEADER) || undefined,\n etag: headers.get(ETAG_HEADER) || undefined,\n });\n }\n\n this._resolvePendingRequests(requestHash, res);\n this._requestTracker.active = this._requestTracker.active.filter(value => value !== requestHash);\n return res;\n }\n\n private _logResponse(res: FetchResponse, endpoint: string, options: FetchOptions, context: PlainObject) {\n const { data, errors, headers, status } = res;\n const { redirects, retries } = options;\n const { startTime, ...otherContext } = context;\n\n const endTime = this._performance.now();\n const duration = endTime - startTime;\n\n this._log?.(RESPONSE_RECEIVED, {\n context: {\n body: data ? { data } : { errors: errors ?? [] },\n headers,\n method: options.method,\n redirects,\n retries,\n status,\n url: endpoint,\n ...otherContext,\n },\n stats: { duration, endTime, startTime },\n });\n }\n\n private _rateLimit() {\n if (!this._rateLimitTimer) {\n this._rateLimitTimer = setTimeout(() => {\n this._rateLimitTimer = null;\n this._rateLimitCount = 0;\n\n if (this._rateLimitedRequestQueue.length) {\n this._releaseRateLimitedRequestQueue();\n }\n }, 1000);\n }\n\n this._rateLimitCount += 1;\n }\n\n private _releaseRateLimitedRequestQueue() {\n this._rateLimitedRequestQueue.forEach(async ([resolve, endpoint, options, context]) => {\n // @ts-ignore\n resolve(await this._fetch(endpoint, options, context));\n });\n\n this._rateLimitedRequestQueue = [];\n }\n\n private async _request(\n path: string,\n { body, headers, method, pathTemplateData, queryParams, ...rest }: Required<RequestOptions, \"method\">,\n context?: PlainObject,\n ) {\n const endpoint = buildEndpoint(this._basePath, path, {\n optionalPathTemplateRegExp: this._optionalPathTemplateRegExp,\n pathTemplateCallback: this._pathTemplateCallback,\n pathTemplateData,\n pathTemplateRegExp: this._pathTemplateRegExp,\n queryParams: { ...this._queryParams, ...queryParams },\n });\n\n return this._fetch(\n endpoint,\n {\n body,\n headers: { ...this._headers, ...headers },\n method,\n ...rest,\n },\n context,\n );\n }\n\n private _resolvePendingRequests(requestHash: string, responseData: FetchResponse) {\n const pendingRequests = this._requestTracker.pending.get(requestHash);\n if (!pendingRequests) return;\n\n pendingRequests.forEach(({ resolve }) => {\n resolve(responseData);\n });\n\n this._requestTracker.pending.delete(requestHash);\n }\n\n private _setPendingRequest(requestHash: string, resolver: PendingRequestResolvers) {\n let pending = this._requestTracker.pending.get(requestHash);\n if (!pending) pending = [];\n pending.push(resolver);\n this._requestTracker.pending.set(requestHash, pending);\n }\n\n private _trackRequest(requestHash: string): Promise<FetchResponse> | void {\n if (this._requestTracker.active.includes(requestHash)) {\n return new Promise((resolve: PendingRequestResolver) => {\n this._setPendingRequest(requestHash, { resolve });\n });\n }\n\n this._requestTracker.active.push(requestHash);\n }\n}\n\nexport const createRestClient = <N extends string>(options: ConstructorOptions, shortcuts?: Shortcuts) => {\n const getta = new Getta(options) as Getta & ShortcutProperties<N>;\n if (!shortcuts) return getta;\n\n Object.keys(shortcuts).forEach(key => {\n getta.createShortcut(key, ...shortcuts[key]);\n });\n\n return getta;\n};\n","import {\n CLIENT_ERROR_REPSONSE,\n INFORMATION_REPSONSE,\n REDIRECTION_REPSONSE,\n SERVER_ERROR_REPSONSE,\n SUCCESSFUL_REPSONSE,\n} from \"../../constants\";\n\nexport default function getResponseGroup(status: number) {\n switch (true) {\n case status < 200:\n return INFORMATION_REPSONSE;\n case status < 300:\n return SUCCESSFUL_REPSONSE;\n case status < 400:\n return REDIRECTION_REPSONSE;\n case status < 500:\n return CLIENT_ERROR_REPSONSE;\n default:\n return SERVER_ERROR_REPSONSE;\n }\n}\n","export default function delay(ms: number) {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n","import Cacheability from \"cacheability\";\n\nexport default function isCacheabilityValid(cacheability: Cacheability) {\n const noCache = cacheability?.metadata?.cacheControl?.noCache ?? false;\n return !noCache && cacheability.checkTTL();\n}\n"],"names":["ARRAY_BUFFER_FORMAT","BLOB_FORMAT","FORM_DATA_FORMAT","JSON_FORMAT","TEXT_FORMAT","STREAM_READERS","DEFAULT_BODY_PARSER","body","DEFAULT_FETCH_TIMEOUT","DEFAULT_HEADERS","DEFAULT_MAX_REDIRECTS","DEFAULT_MAX_RETRIES","DEFAULT_PATH_TEMPLATE_REGEX","OPTIONAL_PATH_TEMPLATE_REGEX","DEFAULT_RATE_LIMIT","DEFAULT_REQUEST_RETRY_WAIT","MISSING_BASE_PATH_ERROR","MAX_REDIRECTS_EXCEEDED_ERROR","MAX_RETRIES_EXCEEDED_ERROR","INVALID_FETCH_METHOD_ERROR","RESOURCE_NOT_FOUND_ERROR","FETCH_TIMEOUT_ERROR","GET_METHOD","POST_METHOD","PUT_METHOD","DELETE_METHOD","FETCH_METHODS","INFORMATION_REPSONSE","SUCCESSFUL_REPSONSE","REDIRECTION_REPSONSE","CLIENT_ERROR_REPSONSE","SERVER_ERROR_REPSONSE","NOT_MODIFIED_STATUS_CODE","NOT_FOUND_STATUS_CODE","COOKIE_HEADER","ETAG_HEADER","LOCATION_HEADER","IF_NONE_MATCH_HEADER","CACHE_CONTROL_HEADER","REQUEST_SENT","RESPONSE_RECEIVED","defaultPathTemplateCallback","pathTemplate","data","pathTemplateRegExp","dataKeys","Object","keys","replace","match","reduce","value","key","includes","buildEndpoint","basePath","path","optionalPathTemplateRegExp","pathTemplateCallback","pathTemplateData","queryParams","pathJoiner","endsWith","startsWith","endpoint","substring","length","queryString","extract","stringify","Getta","constructor","options","active","pending","Map","bodyParser","cache","enableConditionalRequests","fetchTimeout","headers","log","maxRedirects","maxRetries","performance","rateLimitPerSecond","requestRetryWait","streamReader","Error","_basePath","_bodyParser","_cache","_conditionalRequestsEnabled","_fetchTimeout","_headers","_log","_maxRedirects","_maxRetries","_optionalPathTemplateRegExp","_pathTemplateCallback","_pathTemplateRegExp","_performance","_queryParams","_rateLimitPerSecond","_requestRetryWait","_streamReader","this","createShortcut","name","method","otherOptions","async","requestMethod","otherOptionOverrides","context","_merge","_delete","_get","_request","_addRequestToRateLimitedQueue","Promise","resolve","_rateLimitedRequestQueue","push","requestHash","delete","errors","reject","get","has","error","cacheHeaders","set","rest","md5","_cacheEntryHas","_cacheEntryDelete","_fetch","startTime","now","redirects","retries","fetchTimer","setTimeout","_rateLimit","_rateLimitCount","clearTimeout","url","stats","res","fetch","status","responseGroup","getResponseGroup","_fetchRedirectHandler","_fetchRetryHandler","fetchRes","undefined","_logResponse","e","_castArray","redirectMethod","ms","cacheability","metadata","_cacheability$metadat2","cacheControl","_cacheability$metadat3","noCache","checkTTL","isCacheabilityValid","_cacheEntryGet","Headers","printCacheControl","etag","pendingRequest","_trackRequest","_getResolve","cachedData","_cacheEntrySet","_resolvePendingRequests","_requestTracker","filter","otherContext","endTime","duration","_rateLimitTimer","_releaseRateLimitedRequestQueue","forEach","responseData","pendingRequests","_setPendingRequest","resolver","createRestClient","shortcuts","getta"],"mappings":"4MAEaA,EAAsB,cACtBC,EAAc,OACdC,EAAmB,WACnBC,EAAc,OACdC,EAAc,OAEdC,EAAiB,CAC5BL,oBAPiC,cAQjCC,YAPyB,OAQzBC,iBAP8B,WAQ9BC,YAAAA,EACAC,YAPyB,QAUdE,EAAuBC,GAAsBA,EA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E,QACRX,gBAAgB3G,QAAQ0D,IAAIR,EAAalD,GAGxCsG,cAAcpD,MAChBlB,KAAK2E,gBAAgB5G,OAAOpB,SAASuE,UAChC,IAAIJ,QAASC,SACbsE,mBAAmBnE,EAAa,CAAEH,QAAAA,WAItC4D,gBAAgB5G,OAAOkD,KAAKC,UAIxBqE,EAAmB,CAAmBzH,EAA6B0H,WACxEC,EAAQ,IAAI7H,EAAME,UACnB0H,GAELpJ,OAAOC,KAAKmJ,GAAWN,QAAQxI,IAC7B+I,EAAMxF,eAAevD,KAAQ8I,EAAU9I,MAGlC+I,GANgBA"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
-----------------------------
|
|
2
2
|
Rollup File Analysis
|
|
3
3
|
-----------------------------
|
|
4
|
-
bundle size: 19.
|
|
5
|
-
original size: 24.
|
|
4
|
+
bundle size: 19.094 KB
|
|
5
|
+
original size: 24.507 KB
|
|
6
6
|
code reduction: 22.09 %
|
|
7
7
|
module count: 9
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
███████████████████████████████████████░░░░░░░░░░░
|
|
10
10
|
file: /src/main.ts
|
|
11
|
-
bundle space:
|
|
12
|
-
rendered size: 14.
|
|
13
|
-
original size: 17.
|
|
14
|
-
code reduction: 12.
|
|
11
|
+
bundle space: 78 %
|
|
12
|
+
rendered size: 14.893 KB
|
|
13
|
+
original size: 17.022 KB
|
|
14
|
+
code reduction: 12.51 %
|
|
15
15
|
dependents: 1
|
|
16
16
|
- /src/index.ts
|
|
17
17
|
|
|
@@ -85,7 +85,7 @@ dependents: 1
|
|
|
85
85
|
file: /src/index.ts
|
|
86
86
|
bundle space: 0 %
|
|
87
87
|
rendered size: 0 Byte
|
|
88
|
-
original size:
|
|
88
|
+
original size: 203 Bytes
|
|
89
89
|
code reduction: 100 %
|
|
90
90
|
dependents: 0
|
|
91
91
|
|
package/lib/main/index.js
CHANGED
|
@@ -7,7 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
var _exportNames = {
|
|
9
9
|
defaultPathTemplateCallback: true,
|
|
10
|
-
Getta: true
|
|
10
|
+
Getta: true,
|
|
11
|
+
createRestClient: true
|
|
11
12
|
};
|
|
12
13
|
Object.defineProperty(exports, "defaultPathTemplateCallback", {
|
|
13
14
|
enumerable: true,
|
|
@@ -15,16 +16,16 @@ Object.defineProperty(exports, "defaultPathTemplateCallback", {
|
|
|
15
16
|
return _defaultPathTemplateCallback.default;
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
19
|
+
Object.defineProperty(exports, "Getta", {
|
|
19
20
|
enumerable: true,
|
|
20
21
|
get: function () {
|
|
21
|
-
return _main.
|
|
22
|
+
return _main.Getta;
|
|
22
23
|
}
|
|
23
24
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
25
|
+
Object.defineProperty(exports, "createRestClient", {
|
|
25
26
|
enumerable: true,
|
|
26
27
|
get: function () {
|
|
27
|
-
return _main.
|
|
28
|
+
return _main.createRestClient;
|
|
28
29
|
}
|
|
29
30
|
});
|
|
30
31
|
|
|
@@ -44,7 +45,7 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
44
45
|
|
|
45
46
|
var _defaultPathTemplateCallback = _interopRequireDefault(require("./helpers/default-path-template-callback"));
|
|
46
47
|
|
|
47
|
-
var _main =
|
|
48
|
+
var _main = require("./main");
|
|
48
49
|
|
|
49
50
|
var _types = require("./types");
|
|
50
51
|
|
|
@@ -58,8 +59,4 @@ Object.keys(_types).forEach(function (key) {
|
|
|
58
59
|
return _types[key];
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
64
|
-
|
|
65
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
62
|
+
});
|
package/lib/main/main.js
CHANGED
|
@@ -5,8 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
9
|
-
exports.Getta = void 0;
|
|
8
|
+
exports.createRestClient = exports.Getta = void 0;
|
|
10
9
|
|
|
11
10
|
require("core-js/modules/es.promise.js");
|
|
12
11
|
|
|
@@ -569,11 +568,13 @@ class Getta {
|
|
|
569
568
|
|
|
570
569
|
exports.Getta = Getta;
|
|
571
570
|
|
|
572
|
-
|
|
571
|
+
const createRestClient = (options, shortcuts) => {
|
|
573
572
|
const getta = new Getta(options);
|
|
574
573
|
if (!shortcuts) return getta;
|
|
575
574
|
Object.keys(shortcuts).forEach(key => {
|
|
576
575
|
getta.createShortcut(key, ...shortcuts[key]);
|
|
577
576
|
});
|
|
578
577
|
return getta;
|
|
579
|
-
}
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
exports.createRestClient = createRestClient;
|
package/lib/module/index.js
CHANGED
package/lib/module/main.js
CHANGED
|
@@ -566,11 +566,11 @@ export class Getta {
|
|
|
566
566
|
}
|
|
567
567
|
|
|
568
568
|
}
|
|
569
|
-
export
|
|
569
|
+
export const createRestClient = (options, shortcuts) => {
|
|
570
570
|
const getta = new Getta(options);
|
|
571
571
|
if (!shortcuts) return getta;
|
|
572
572
|
Object.keys(shortcuts).forEach(key => {
|
|
573
573
|
getta.createShortcut(key, ...shortcuts[key]);
|
|
574
574
|
});
|
|
575
575
|
return getta;
|
|
576
|
-
}
|
|
576
|
+
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./constants";
|
|
2
2
|
export { default as defaultPathTemplateCallback } from "./helpers/default-path-template-callback";
|
|
3
|
-
export {
|
|
3
|
+
export { Getta, createRestClient } from "./main";
|
|
4
4
|
export * from "./types";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AACjD,cAAc,SAAS,CAAC"}
|
package/lib/types/main.d.ts
CHANGED
|
@@ -53,5 +53,5 @@ export declare class Getta {
|
|
|
53
53
|
private _setPendingRequest;
|
|
54
54
|
private _trackRequest;
|
|
55
55
|
}
|
|
56
|
-
export
|
|
56
|
+
export declare const createRestClient: <N extends string>(options: ConstructorOptions, shortcuts?: Shortcuts | undefined) => Getta & ShortcutProperties<N>;
|
|
57
57
|
//# sourceMappingURL=main.d.ts.map
|
package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IrF,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW;IAInG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW;IAIhH,OAAO,CAAC,6BAA6B;YAMvB,iBAAiB;YAUjB,cAAc;YAUd,cAAc;YAUd,cAAc;YAUd,OAAO;YA+BP,MAAM;YAkFN,qBAAqB;YAmBrB,kBAAkB;YAclB,IAAI;YAuCJ,WAAW;IAkCzB,OAAO,CAAC,YAAY;IAuBpB,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,+BAA+B;YASzB,QAAQ;IAyBtB,OAAO,CAAC,uBAAuB;IAW/B,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,aAAa;CAStB;AAED,eAAO,MAAM,gBAAgB,8BAA+B,kBAAkB,qEAS7E,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/main.test.ts
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
RESOURCE_NOT_FOUND_ERROR,
|
|
29
29
|
} from "./constants";
|
|
30
30
|
import delay from "./helpers/delay";
|
|
31
|
-
import
|
|
31
|
+
import { Getta, createRestClient } from "./main";
|
|
32
32
|
import { ResponseDataWithErrors, ShortcutProperties } from "./types";
|
|
33
33
|
|
|
34
34
|
describe("Getta", () => {
|
package/src/main.ts
CHANGED
|
@@ -529,7 +529,7 @@ export class Getta {
|
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
-
export
|
|
532
|
+
export const createRestClient = <N extends string>(options: ConstructorOptions, shortcuts?: Shortcuts) => {
|
|
533
533
|
const getta = new Getta(options) as Getta & ShortcutProperties<N>;
|
|
534
534
|
if (!shortcuts) return getta;
|
|
535
535
|
|
|
@@ -538,4 +538,4 @@ export default function createRestClient<N extends string>(options: ConstructorO
|
|
|
538
538
|
});
|
|
539
539
|
|
|
540
540
|
return getta;
|
|
541
|
-
}
|
|
541
|
+
};
|