@hyper-fetch/core 4.0.2 → 5.0.1
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/README.md +0 -9
- package/dist/browser/index.cjs.js +2375 -1
- package/dist/browser/index.cjs.js.map +3 -3
- package/dist/browser/index.esm.js +2350 -1
- package/dist/browser/index.esm.js.map +3 -3
- package/dist/index.cjs.js +2534 -1
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.d.ts +67 -43
- package/dist/index.esm.js +2429 -1
- package/dist/index.esm.js.map +4 -4
- package/package.json +1 -1
- package/src/adapter/adapter.browser.ts +8 -2
- package/src/adapter/adapter.constants.ts +5 -0
- package/src/adapter/adapter.server.ts +13 -27
- package/src/adapter/adapter.types.ts +21 -3
- package/src/adapter/adapter.utils.ts +0 -10
- package/src/cache/cache.events.ts +7 -7
- package/src/cache/cache.ts +51 -14
- package/src/cache/cache.types.ts +2 -0
- package/src/cache/cache.utils.ts +2 -2
- package/src/client/client.constants.ts +0 -6
- package/src/client/client.ts +95 -36
- package/src/client/client.types.ts +4 -0
- package/src/dispatcher/dispatcher.ts +1 -1
- package/src/dispatcher/dispatcher.types.ts +1 -0
- package/src/mocker/mocker.ts +22 -31
- package/src/mocker/mocker.types.ts +8 -5
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2430 @@
|
|
|
1
|
-
var Dt=Object.defineProperty,Qt=Object.defineProperties;var Lt=Object.getOwnPropertyDescriptors;var ge=Object.getOwnPropertySymbols;var Je=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable;var Ne=(s,e,t)=>e in s?Dt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,F=(s,e)=>{for(var t in e||(e={}))Je.call(e,t)&&Ne(s,t,e[t]);if(ge)for(var t of ge(e))et.call(e,t)&&Ne(s,t,e[t]);return s},W=(s,e)=>Qt(s,Lt(e));var tt=(s,e)=>{var t={};for(var r in s)Je.call(s,r)&&e.indexOf(r)<0&&(t[r]=s[r]);if(s!=null&&ge)for(var r of ge(s))e.indexOf(r)<0&&et.call(s,r)&&(t[r]=s[r]);return t};var l=(s,e,t)=>new Promise((r,n)=>{var o=i=>{try{d(t.next(i))}catch(u){n(u)}},a=i=>{try{d(t.throw(i))}catch(u){n(u)}},d=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,a);d((t=t.apply(s,e)).next())});var rt=class{constructor(e){this.config=e;this.getEffectKey=()=>this.config.effectKey;this.onTrigger=e=>{var t,r;(r=(t=this.config).onTrigger)==null||r.call(t,e)};this.onStart=e=>{var t,r;(r=(t=this.config).onStart)==null||r.call(t,e)};this.onSuccess=(e,t)=>{var r,n;(n=(r=this.config).onSuccess)==null||n.call(r,e,t)};this.onError=(e,t)=>{var r,n;(n=(r=this.config).onError)==null||n.call(r,e,t)};this.onFinished=(e,t)=>{var r,n;(n=(r=this.config).onFinished)==null||n.call(r,e,t)}}};var je=(u=>(u[u.second=1e3]="second",u[u.minute=6e4]="minute",u[u.hour=36e5]="hour",u[u.day=864e5]="day",u[u.week=6048e5]="week",u[u.month30=2592e6]="month30",u[u.month31=26784e5]="month31",u[u.year=31536e6]="year",u[u.yearLeap=316224e5]="yearLeap",u))(je||{});var ye=1e3*5;var st=(s,e)=>l(void 0,null,function*(){let{makeRequest:t,fullUrl:r,config:n,payload:o,headers:a,onError:d,onResponseEnd:i,onTimeoutError:u,onRequestEnd:E,createAbortListener:h,onResponseProgress:v,onRequestProgress:c,onResponseStart:x,onBeforeRequest:g,onRequestStart:f,onSuccess:D}=yield he(s,e,0,{headers:{}}),{method:b="GET"}=s;return t(w=>{let T=new XMLHttpRequest;T.timeout=ye;let L=()=>T.abort();Object.entries(n).forEach(([A,R])=>{T[A]=R}),T.open(b,r,!0),Object.entries(a).forEach(([A,R])=>T.setRequestHeader(A,R));let y=h(0,U,L,w);T.upload.onprogress=c,T.onloadstart=()=>{E(),x()},T.onprogress=v,T.onloadend=()=>{i(),y()},T.ontimeout=()=>u(0,U,w),T.onreadystatechange=A=>{let R=A,K=4;if(R.target&&R.target.readyState===K){let{status:q}=R.target,k=String(q).startsWith("2")||String(q).startsWith("3"),P=nt(T.getAllResponseHeaders());if(k){let Q=ie(R.target.response);D(Q,q,{headers:P},w)}else{let Q=fe(R.target.response);d(Q,q,{headers:P},w)}}},g(),f(),T.send(o)})});import St from"http";import Gt from"stream";import Vt from"https";var me=s=>`${s}_${Date.now().toString(36)}_${Math.random().toString(36).substring(2)}`;var J=class{constructor(e,t,r){this.client=e;this.requestOptions=t;this.requestJSON=r;this.setHeaders=e=>this.clone({headers:e});this.setAuth=e=>this.clone({auth:e});this.setParams=e=>this.clone({params:e});this.setData=e=>this.clone({data:e});this.setQueryParams=e=>this.clone({queryParams:e});this.setOptions=e=>this.clone({options:e});this.setCancelable=e=>this.clone({cancelable:e});this.setRetry=e=>this.clone({retry:e});this.setRetryTime=e=>this.clone({retryTime:e});this.setGarbageCollection=e=>this.clone({garbageCollection:e});this.setCache=e=>this.clone({cache:e});this.setCacheTime=e=>this.clone({cacheTime:e});this.setQueued=e=>this.clone({queued:e});this.setAbortKey=e=>(this.updatedAbortKey=!0,this.clone({abortKey:e}));this.setCacheKey=e=>(this.updatedCacheKey=!0,this.clone({cacheKey:e}));this.setQueueKey=e=>(this.updatedQueueKey=!0,this.clone({queueKey:e}));this.setEffectKey=e=>(this.updatedEffectKey=!0,this.clone({effectKey:e}));this.setDeduplicate=e=>this.clone({deduplicate:e});this.setDeduplicateTime=e=>this.clone({deduplicateTime:e});this.setUsed=e=>this.clone({used:e});this.setOffline=e=>this.clone({offline:e});this.setMock=e=>{let t=function*(n){if(Array.isArray(e)){let o=0;for(;;)yield n[o],o=e.length===o+1?0:o+1}else for(;;)yield e};return this.mockData=e,this.mock=t(e),this};this.removeMock=()=>(this.mockData=null,this.mock=null,this);this.setDataMapper=e=>{let t=this.clone(void 0);return t.dataMapper=e,t};this.setRequestMapper=e=>{let t=this.clone(void 0);return t.requestMapper=e,t};this.setResponseMapper=e=>{let t=this.clone();return t.responseMapper=e,t};this.paramsMapper=(e,t)=>{let r=this.requestOptions.endpoint;return e&&Object.entries(e).forEach(([n,o])=>{r=r.replace(new RegExp(`:${n}`,"g"),String(o))}),t&&(r+=this.client.stringifyQueryParams(t)),r};this.abort=()=>{let{requestManager:e}=this.client;return e.abortByKey(this.abortKey),this.clone()};this.exec=e=>l(this,null,function*(){let{adapter:t,requestManager:r}=this.client,n=this.clone(e),o=me(this.queueKey);r.addAbortController(this.abortKey,o);let a=yield t(n,o);return r.removeAbortController(this.abortKey,o),n.responseMapper?n.responseMapper(a):a});this.send=e=>l(this,null,function*(){let o=e||{},{dispatcherType:t}=o,r=tt(o,["dispatcherType"]),n=this.clone(r);return ot(n,e)});var A,R,K,q,k,P,Q,G,S,$,B,V,X,Y,Z,j,te,re,z,se,ne,le,oe,ae,Oe,p,m,C,I;let{endpoint:n,headers:o,auth:a=!0,method:d=e.defaultMethod,options:i,cancelable:u=!1,retry:E=0,retryTime:h=500,garbageCollection:v=6e4*5,cache:c=!0,cacheTime:x=6e4*5,queued:g=!1,offline:f=!0,abortKey:D,cacheKey:b,queueKey:w,effectKey:T,deduplicate:L=!1,deduplicateTime:y=10}=F(F({},(R=(A=this.client).requestDefaultOptions)==null?void 0:R.call(A,t)),t);this.endpoint=(K=r==null?void 0:r.endpoint)!=null?K:n,this.headers=(q=r==null?void 0:r.headers)!=null?q:o,this.auth=(k=r==null?void 0:r.auth)!=null?k:a,this.method=d,this.params=r==null?void 0:r.params,this.data=r==null?void 0:r.data,this.queryParams=r==null?void 0:r.queryParams,this.options=(P=r==null?void 0:r.options)!=null?P:i,this.cancelable=(Q=r==null?void 0:r.cancelable)!=null?Q:u,this.retry=(G=r==null?void 0:r.retry)!=null?G:E,this.retryTime=(S=r==null?void 0:r.retryTime)!=null?S:h,this.garbageCollection=($=r==null?void 0:r.garbageCollection)!=null?$:v,this.cache=(B=r==null?void 0:r.cache)!=null?B:c,this.cacheTime=(V=r==null?void 0:r.cacheTime)!=null?V:x,this.queued=(X=r==null?void 0:r.queued)!=null?X:g,this.offline=(Y=r==null?void 0:r.offline)!=null?Y:f,this.abortKey=(j=(Z=r==null?void 0:r.abortKey)!=null?Z:D)!=null?j:this.client.abortKeyMapper(this),this.cacheKey=(re=(te=r==null?void 0:r.cacheKey)!=null?te:b)!=null?re:this.client.cacheKeyMapper(this),this.queueKey=(se=(z=r==null?void 0:r.queueKey)!=null?z:w)!=null?se:this.client.queueKeyMapper(this),this.effectKey=(le=(ne=r==null?void 0:r.effectKey)!=null?ne:T)!=null?le:this.client.effectKeyMapper(this),this.used=(oe=r==null?void 0:r.used)!=null?oe:!1,this.deduplicate=(ae=r==null?void 0:r.deduplicate)!=null?ae:L,this.deduplicateTime=(Oe=r==null?void 0:r.deduplicateTime)!=null?Oe:y,this.updatedAbortKey=(p=r==null?void 0:r.updatedAbortKey)!=null?p:!1,this.updatedCacheKey=(m=r==null?void 0:r.updatedCacheKey)!=null?m:!1,this.updatedQueueKey=(C=r==null?void 0:r.updatedQueueKey)!=null?C:!1,this.updatedEffectKey=(I=r==null?void 0:r.updatedEffectKey)!=null?I:!1}toJSON(){return{requestOptions:this.requestOptions,endpoint:this.endpoint,headers:this.headers,auth:this.auth,method:this.method,params:this.params,data:this.data,queryParams:this.queryParams,options:this.options,cancelable:this.cancelable,retry:this.retry,retryTime:this.retryTime,garbageCollection:this.garbageCollection,cache:this.cache,cacheTime:this.cacheTime,queued:this.queued,offline:this.offline,abortKey:this.abortKey,cacheKey:this.cacheKey,queueKey:this.queueKey,effectKey:this.effectKey,used:this.used,disableResponseInterceptors:this.requestOptions.disableResponseInterceptors,disableRequestInterceptors:this.requestOptions.disableRequestInterceptors,updatedAbortKey:this.updatedAbortKey,updatedCacheKey:this.updatedCacheKey,updatedQueueKey:this.updatedQueueKey,updatedEffectKey:this.updatedEffectKey,deduplicate:this.deduplicate,deduplicateTime:this.deduplicateTime}}clone(e){let t=this.toJSON(),r=W(F(F({},t),e),{abortKey:this.updatedAbortKey?(e==null?void 0:e.abortKey)||this.abortKey:void 0,cacheKey:this.updatedCacheKey?(e==null?void 0:e.cacheKey)||this.cacheKey:void 0,queueKey:this.updatedQueueKey?(e==null?void 0:e.queueKey)||this.queueKey:void 0,endpoint:this.paramsMapper((e==null?void 0:e.params)||this.params,(e==null?void 0:e.queryParams)||this.queryParams),queryParams:(e==null?void 0:e.queryParams)||this.queryParams,data:(e==null?void 0:e.data)||this.data}),n=new J(this.client,this.requestOptions,r);return n.dataMapper=this.dataMapper,n.responseMapper=this.responseMapper,n.requestMapper=this.requestMapper,n.mockData=this.mockData,n.mock=this.mock,n}};var Re=(o=>(o.get="GET",o.post="POST",o.put="PUT",o.patch="PATCH",o.delete="DELETE",o))(Re||{});var We=(n=>(n.oneByOne="one-by-one",n.allAtOnce="all-at-once",n.previousCanceled="previous-canceled",n.deduplicated="deduplicated",n))(We||{});var at=s=>({setDrained:(e,t)=>{s.emit(Te(e),t)},setQueueStatus:(e,t)=>{s.emit(Ee(e),t)},setQueueChanged:(e,t)=>{s.emit(xe(e),t)},onDrained:(e,t)=>(s.on(Te(e),t),()=>s.removeListener(Te(e),t)),onQueueStatus:(e,t)=>(s.on(Ee(e),t),()=>s.removeListener(Ee(e),t)),onQueueChange:(e,t)=>(s.on(xe(e),t),()=>s.removeListener(xe(e),t))});import kt from"events";var N=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new kt;this.events=at(this.emitter);this.storage=new Map;this.requestCount=new Map;this.runningRequests=new Map;this.start=e=>{let t=this.getQueue(e);t.stopped=!1,this.setQueue(e,t),this.flushQueue(e),this.events.setQueueStatus(e,t)};this.pause=e=>{let t=this.getQueue(e);t.stopped=!0,this.setQueue(e,t),this.events.setQueueStatus(e,t)};this.stop=e=>{let t=this.getQueue(e);t.stopped=!0,this.setQueue(e,t),this.cancelRunningRequests(e),this.events.setQueueStatus(e,t)};this.getQueuesKeys=()=>Array.from(this.storage.keys());this.getQueue=e=>{let t={requests:[],stopped:!1};return this.storage.get(e)||t};this.getRequest=(e,t)=>{let r={requests:[],stopped:!1};return(this.storage.get(e)||r).requests.find(o=>o.requestId===t)};this.getIsActiveQueue=e=>{let t=this.getQueue(e),r=t.requests.some(o=>!o.stopped),n=!t.stopped;return r&&n};this.addQueueElement=(e,t)=>{let r=this.getQueue(e);r.requests.push(t),this.setQueue(e,r)};this.setQueue=(e,t)=>{var r,n;return this.storage.set(e,t),(n=(r=this.options)==null?void 0:r.onUpdateStorage)==null||n.call(r,e,t),this.events.setQueueChanged(e,t),t};this.clearQueue=e=>{var n,o;let t=this.getQueue(e),r={requests:[],stopped:t.stopped};return this.storage.set(e,r),(o=(n=this.options)==null?void 0:n.onDeleteFromStorage)==null||o.call(n,e,r),this.events.setQueueChanged(e,r),r};this.flushQueue=e=>l(this,null,function*(){let t=this.getQueue(e),r=this.getRunningRequests(e),n=t.requests.find(E=>!E.stopped),o=t&&t.stopped,a=!this.client.appManager.isOnline,d=!(n!=null&&n.request.queued),i=!r.length,u=!n;o||a||u?this.logger.debug("Skipping queue trigger",{isStopped:o,isOffline:a,isEmpty:u}):d?t.requests.forEach(E=>{this.hasRunningRequest(e,E.requestId)||this.performRequest(E)}):i&&(yield this.performRequest(n),this.flushQueue(e))});this.flush=()=>l(this,null,function*(){let e=this.getQueuesKeys();for(let t of e)this.getQueue(t)&&this.flushQueue(t)});this.clear=()=>{var t,r;this.getQueuesKeys().forEach(n=>this.cancelRunningRequests(n)),this.runningRequests.clear(),this.storage.clear(),(r=(t=this.options)==null?void 0:t.onClearStorage)==null||r.call(t,this)};this.startRequest=(e,t)=>{let r=this.getQueue(e),n=r.requests.find(o=>o.requestId===t);n&&(n.stopped=!1,this.setQueue(e,r),this.flushQueue(e),this.events.setQueueStatus(e,r))};this.stopRequest=(e,t)=>{let r=this.getQueue(e),n=r.requests.find(o=>o.requestId===t);n&&(n.stopped=!0,this.setQueue(e,r),this.cancelRunningRequest(e,t),this.events.setQueueStatus(e,r))};this.getAllRunningRequest=()=>Array.from(this.runningRequests.values()).flat();this.getRunningRequests=e=>this.runningRequests.get(e)||[];this.getRunningRequest=(e,t)=>this.getRunningRequests(e).find(n=>n.requestId===t);this.addRunningRequest=(e,t,r)=>{let n=this.getRunningRequests(e);n.push({requestId:t,request:r}),this.runningRequests.set(e,n)};this.hasRunningRequests=e=>!!this.getRunningRequests(e).length;this.hasRunningRequest=(e,t)=>!!this.getRunningRequests(e).find(n=>n.requestId===t);this.cancelRunningRequests=e=>{var t;(t=this.runningRequests.get(e))==null||t.forEach(r=>{this.client.requestManager.abortByRequestId(r.request.abortKey,r.requestId)}),this.deleteRunningRequests(e)};this.cancelRunningRequest=(e,t)=>{let r=this.getRunningRequests(e).filter(n=>n.requestId===t?(this.client.requestManager.abortByRequestId(n.request.abortKey,n.requestId),!1):!0);this.runningRequests.set(e,r)};this.deleteRunningRequests=e=>{this.runningRequests.set(e,[])};this.deleteRunningRequest=(e,t)=>{let r=this.getRunningRequests(e);this.runningRequests.set(e,r.filter(n=>n.requestId!==t))};this.getQueueRequestCount=e=>this.requestCount.get(e)||0;this.incrementQueueRequestCount=e=>{let t=this.requestCount.get(e)||0;this.requestCount.set(e,t+1)};this.createStorageElement=e=>({requestId:me(e.queueKey),timestamp:+new Date,request:e,retries:0,stopped:!1});this.add=e=>{let{queueKey:t}=e,r=this.createStorageElement(e),{requestId:n}=r,o=this.getQueue(t),[a]=o.requests.slice(-1),d=it(e,a);switch(this.logger.debug("Adding request to queue",{requestType:d,request:e,requestId:n}),d){case"one-by-one":return this.addQueueElement(t,r),this.flushQueue(t),n;case"previous-canceled":return this.cancelRunningRequests(t),this.clearQueue(t),this.addQueueElement(t,r),this.flushQueue(t),n;case"deduplicated":return o.requests[0].requestId;default:return this.addQueueElement(t,r),this.flushQueue(t),n}};this.delete=(e,t,r)=>{var a,d;this.logger.debug("Deleting request",{queueKey:e,requestId:t,abortKey:r});let n=this.getQueue(e),o=n.requests.find(i=>i.requestId===t);if(!!o)return n.requests=n.requests.filter(i=>i.requestId!==t),this.storage.set(e,n),this.hasRunningRequest(e,t)&&(this.deleteRunningRequest(e,t),this.client.requestManager.abortByRequestId(r,t)),(d=(a=this.options)==null?void 0:a.onDeleteFromStorage)==null||d.call(a,e,n),this.events.setQueueChanged(e,n),this.client.requestManager.events.emitRemove(e,t,{requestId:t,request:o.request}),n.requests.length||this.events.setDrained(e,n),n};this.performRequest=e=>l(this,null,function*(){var A;let{request:t,requestId:r}=e;this.logger.info("Performing request",{request:t,requestId:r});let{retry:n,retryTime:o,queueKey:a,cacheKey:d,abortKey:i,offline:u}=t,{adapter:E,requestManager:h,cache:v,appManager:c}=this.client,x=be(e.retries,n),g=!c.isOnline&&u,f=this.hasRunningRequest(a,r),D=e.stopped;if(g||f||D)return this.logger.warning("Unable to perform request",{isOffline:g,isAlreadyRunning:f,isStopped:D});this.addRunningRequest(a,r,t),h.events.emitLoading(a,r,{queueKey:a,requestId:r,loading:!0,isRetry:!!e.retries,isOffline:g}),this.incrementQueueRequestCount(a),h.addAbortController(i,r);let b=yield E(t,r);h.removeAbortController(i,r);let w=!c.isOnline,T=O("abort").message===((A=b.error)==null?void 0:A.message),L=!this.hasRunningRequest(a,r)||T;this.deleteRunningRequest(a,r);let y={isCanceled:L,isOffline:w,retries:e.retries,timestamp:+new Date};if(h.events.emitLoading(a,r,{queueKey:a,requestId:r,loading:!1,isRetry:!!e.retries,isOffline:g}),h.events.emitResponse(d,r,b,y),v.set(t,F(F({},b),y)),this.logger.info("Request finished",{requestId:r,request:t,response:b,requestDetails:y}),L){let R=this.getQueue(a),K=R.requests.find(q=>q.requestId===r);return!R.stopped&&!(K!=null&&K.stopped)?(this.logger.debug("Request paused",{response:b,requestDetails:y,request:t}),this.delete(a,r,i)):this.logger.debug("Request canceled",{response:b,requestDetails:y,request:t})}if(!b.success&&w)return u?this.logger.debug("Awaiting for network restoration",{response:b,requestDetails:y,request:t}):(this.logger.warning("Removing non-offline request",{response:b,requestDetails:y,request:t}),this.delete(a,r,i));if(b.success)return this.delete(a,r,i),this.logger.debug("Successful response, removing request from queue.",{response:b,requestDetails:y,request:t});!b.success&&x?(this.logger.debug("Waiting for retry",{response:b,requestDetails:y,request:t}),setTimeout(()=>{this.logger.warning("Error response, performing retry"),this.performRequest(W(F({},e),{retries:e.retries+1}))},o||0)):(this.logger.error("All retries have been used. Removing request from queue."),this.delete(a,r,i))});var r,n,o;this.logger=e.loggerManager.init("Dispatcher"),(r=this.options)!=null&&r.storage&&(this.storage=this.options.storage),this.client.appManager.events.onOnline(()=>{this.flush()}),(o=(n=this.options)==null?void 0:n.onInitialization)==null||o.call(n,this)}};var Te=s=>`${s}-drained-event`,Ee=s=>`${s}-status-event`,xe=s=>`${s}-change-event`,Wr=(s,e,t)=>t?t-s<=e:!1,be=(s,e)=>!!(e&&s<e),it=(s,e)=>{let{queued:t,cancelable:r,deduplicate:n}=s,o=e?+new Date-e.timestamp<=s.deduplicateTime:!1;return t?"one-by-one":r?"previous-canceled":o&&n?"deduplicated":"all-at-once"};var pt=s=>{try{if(typeof s=="string")return s;if(s==null)return"";let e=JSON.stringify(s);if(typeof e!="string")throw new Error;return e}catch(e){return""}},$t=({loaded:s,total:e})=>!s||!e?0:Number((s*100/e).toFixed(0)),Ft=(s,e,{total:t,loaded:r})=>{let n=+e-+s||1,o=r/n,a=Math.max(t,r),d=a-r,i=o?d/o:null;return{timeLeft:a===r?0:i,sizeLeft:d}},Xe=(s,e,t)=>{let{total:r,loaded:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return{progress:0,timeLeft:0,sizeLeft:0,total:0,loaded:0,startTimestamp:+s};let{timeLeft:o,sizeLeft:a}=Ft(s,e,t);return{progress:$t(t),timeLeft:o,sizeLeft:a,total:r,loaded:n,startTimestamp:+s}},Ae=s=>`${s.method}_${s.requestOptions.endpoint}_${s.cancelable}`,ut=(s,e)=>{let t=pt(s.method),r=e?s.requestOptions.endpoint:pt(s.endpoint);return`${t}_${r}`},_t=(s,e="auto")=>{let{fetchDispatcher:t,submitDispatcher:r}=s.client,n=s.method==="GET",o=e==="auto"&&n||e==="fetch";return[o?t:r,o]},ot=(s,e)=>{let{requestManager:t}=s.client,[r]=_t(s,e==null?void 0:e.dispatcherType);return new Promise(n=>{var x;let o=!1,a=r.add(s);(x=e==null?void 0:e.onSettle)==null||x.call(e,a,s);let d=t.events.onRequestStartById(a,(...g)=>{var f;return(f=e==null?void 0:e.onRequestStart)==null?void 0:f.call(e,...g)}),i=t.events.onResponseStartById(a,(...g)=>{var f;return(f=e==null?void 0:e.onResponseStart)==null?void 0:f.call(e,...g)}),u=t.events.onUploadProgressById(a,(...g)=>{var f;return(f=e==null?void 0:e.onUploadProgress)==null?void 0:f.call(e,...g)}),E=t.events.onDownloadProgressById(a,(...g)=>{var f;return(f=e==null?void 0:e.onDownloadProgress)==null?void 0:f.call(e,...g)}),h=t.events.onResponseById(a,(g,f)=>{var L;o=!0;let D=(L=s.responseMapper)==null?void 0:L.call(s,g),b=s.offline&&f.isOffline,w=be(f.retries,s.retry),T=(y,A)=>{var R;!y&&b||!y&&w||((R=e==null?void 0:e.onResponse)==null||R.call(e,A,f),n(A),c())};if(D instanceof Promise)l(void 0,null,function*(){let y=yield D,{success:A}=y;T(A,y)});else{let y=D||g,{success:A}=y;T(A,y)}}),v=t.events.onRemoveById(a,(...g)=>{var f;o||((f=e==null?void 0:e.onRemove)==null||f.call(e,...g),n({data:null,status:null,success:null,error:O("deleted"),extra:s.client.defaultExtra}),c())});function c(){d(),i(),u(),E(),h(),v()}})};var ct=(v,c)=>l(void 0,[v,c],function*(s,{onError:e,onResponseEnd:t,onTimeoutError:r,onRequestEnd:n,createAbortListener:o,onResponseProgress:a,onRequestProgress:d,onResponseStart:i,onBeforeRequest:u,onRequestStart:E,onSuccess:h}){var D,b;let x=((D=s.requestOptions.options)==null?void 0:D.timeout)||((b=s.options)==null?void 0:b.timeout),g=s.mock.next(),f=g.value instanceof Function?yield g.value(s):g.value;return new Promise(w=>{let{data:T,config:L={},extra:y}=f,{status:A=200,success:R=!0,responseDelay:K=5,requestSentDuration:q=0,responseReceivedDuration:k=0}=L,P=()=>x&&q+k>x?[Math.floor(x/2)-1,Math.floor(x/2)-1]:[q,k],[Q,G]=P();o(0,{},()=>{},w),u(),E();let S=(B,V)=>new Promise(X=>{let Y=+new Date;setInterval(()=>{let Z=+new Date,j=Math.min(B,Z-Y);j>=B&&X(!0),V({total:B,loaded:j})},20)}),$=()=>l(void 0,null,function*(){yield S(Q,d),n(),i(),yield S(G,a),R?h(T,A,y||{},w):e(T,A,y||{},w)});x&&K>x?setTimeout(()=>r(0,y||{},w),x+1):setTimeout($,K),t()})});var he=(s,e,t,r)=>l(void 0,null,function*(){let{url:n,requestManager:o,loggerManager:a,headerMapper:d,payloadMapper:i}=s.client,u=a.init("Adapter"),E=null,h=null,v=null,c=s,x=1,g=1,f=0,D=0;u.debug("Starting request middleware callbacks");try{c=yield c.client.__modifyRequest(s),c.auth&&(c=yield c.client.__modifyAuth(s)),c.requestMapper&&(c=yield c.requestMapper(c,e))}catch(p){E=p}let{client:b,abortKey:w,queueKey:T,endpoint:L,data:y}=c,A=n+L,R=b.effects.filter(p=>c.effectKey===p.getEffectKey()),K=d(c),q=y;try{q=i(y),c.dataMapper&&(q=yield c.dataMapper(y))}catch(p){E=p}let k=F({},c.options),P=()=>h,Q=()=>v,G=(p,m)=>{if(!m)return p;let C=Number(m.total||0),I=Number(m.loaded||0);return Math.max(C,I,p)},S=(p,m,C)=>{let I=Xe(new Date(p),new Date(m),C);f!==100&&(f=I.total,o.events.emitUploadProgress(T,e,I,{requestId:e,request:c}))},$=(p,m,C)=>{let I=Xe(new Date(p),new Date(m),C);D!==100&&(D=I.total,o.events.emitDownloadProgress(T,e,I,{requestId:e,request:c}))},B=()=>{R.forEach(p=>p.onTrigger(c))},V=p=>{R.forEach(C=>C.onStart(c)),p!=null&&p.total&&(x=G(x,p));let m={total:x,loaded:(p==null?void 0:p.loaded)||0};return h=+new Date,S(h,h,m),o.events.emitRequestStart(T,e,{requestId:e,request:c}),h},X=p=>{h||(h=+new Date),x=G(x,p);let m=+new Date;return S(h,m,{total:x,loaded:p.loaded||0}),m},Y=()=>{h||(h=+new Date);let p=+new Date;return S(h,p,{total:x,loaded:x}),p},Z=p=>{v=+new Date,g=G(g,p);let m={total:g,loaded:(p==null?void 0:p.loaded)||0};return $(v,v,m),o.events.emitResponseStart(T,e,{requestId:e,request:c}),v},j=p=>{v||(v=+new Date);let m=+new Date;return g=G(g,p),$(v,m,{total:p.total||g,loaded:p.loaded||0}),m},te=()=>{v||(v=+new Date);let p=+new Date;return $(v,p,{total:g,loaded:g}),p},re=(p,m,C,I)=>l(void 0,null,function*(){let M={data:p,error:null,success:!0,status:m,extra:C};return M=yield c.client.__modifyResponse(M,c),M=yield c.client.__modifySuccessResponse(M,c),R.forEach(H=>H.onSuccess(M,c)),R.forEach(H=>H.onFinished(M,c)),I(M),M}),z=(p,m,C,I)=>l(void 0,null,function*(){let M={data:null,status:m,error:p,success:!1,extra:C};return M=yield c.client.__modifyResponse(M,c),M=yield c.client.__modifyErrorResponse(M,c),R.forEach(H=>H.onError(M,c)),R.forEach(H=>H.onFinished(M,c)),I(M),M}),se=(p,m,C)=>{let I=O("abort");return z(I,p,m,C)},ne=(p,m,C)=>{let I=O("timeout");return z(I,p,m,C)},le=(p,m,C)=>{let I=O();return z(I,p,m,C)},oe=()=>o.getAbortController(w,e),ae=(p,m,C,I)=>{let M=oe();if(!M)throw new Error("Controller is not found");let H=()=>{se(p,m,I),C(),o.events.emitAbort(w,e,c)};return M.signal.aborted&&H(),M.signal.addEventListener("abort",H),()=>M.signal.removeEventListener("abort",H)};return{fullUrl:A,data:y,headers:K,payload:q,config:k,getAbortController:oe,getRequestStartTimestamp:P,getResponseStartTimestamp:Q,createAbortListener:ae,onBeforeRequest:B,onRequestStart:V,onRequestProgress:X,onRequestEnd:Y,onResponseStart:Z,onResponseProgress:j,onResponseEnd:te,onSuccess:re,onAbortError:se,onTimeoutError:ne,onUnexpectedError:le,onError:z,makeRequest:p=>E?z(E,t,r,()=>null):s.mock?ct(c,{onError:z,onResponseEnd:te,onTimeoutError:ne,onRequestEnd:Y,createAbortListener:ae,onResponseProgress:j,onRequestProgress:X,onResponseStart:Z,onBeforeRequest:B,onRequestStart:V,onSuccess:re}):new Promise(p)}});var O=s=>s==="timeout"?new Error("Request timeout"):s==="abort"?new Error("Request cancelled"):new Error("Unexpected error"),nt=s=>{let e=s.trim().split(/[\r\n]+/),t={};return e.forEach(r=>{let n=r.split(": "),o=n.shift(),a=n.join(": ");t[o]=a}),t},ie=s=>{try{return JSON.parse(s)}catch(e){return s}},fe=s=>s?ie(s):O(),dt=s=>s.length,lt=s=>s;var gt=(s,e)=>l(void 0,null,function*(){let{makeRequest:t,fullUrl:r,config:n,headers:o,payload:a,onError:d,onResponseEnd:i,onTimeoutError:u,onRequestEnd:E,createAbortListener:h,onResponseProgress:v,onRequestProgress:c,onResponseStart:x,onBeforeRequest:g,onRequestStart:f,onSuccess:D}=yield he(s,e,0,U),{method:b="GET",client:w}=s,T=w.url.includes("https://")?Vt:St,L={path:r,method:b,headers:o,timeout:ye};Object.entries(n).forEach(([q,k])=>{L[q]=k});let y=()=>null;g();let A=a?Number(dt(a)):0,R=0,K=yield lt(a);return t(q=>{let k=T.request(L,P=>{P.setEncoding("utf8"),y=h(0,U,P.destroy,q);let Q="",G=Number(P.headers["content-length"]),S=0;P.on("data",$=>{Q||x(),S+=$.length,Q+=$,v({total:G,loaded:S})}),P.on("end",()=>{let{statusCode:$}=P;if(String($).startsWith("2")||String($).startsWith("3")){let V=ie(Q);D(V,$,{headers:P.headers},q)}else{let V=fe(Q);d(V,$,{headers:P.headers},q)}y(),i()})});k.on("timeout",()=>u(0,U,q)),k.on("error",P=>d(P,0,U,q)),K?Gt.Readable.from(K,{objectMode:!1}).on("data",Q=>{R||f(),R+=Q.length,c({total:A,loaded:R})}).on("end",()=>{E()}).pipe(k):k.end()})});var yt=(s,e)=>l(void 0,null,function*(){return typeof XMLHttpRequest!="undefined"?st(s,e):gt(s,e)});import Bt from"events";var pe=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new Bt;this.garbageCollectors=new Map;this.set=(e,t)=>{var E,h,v;this.logger.debug("Processing cache response",{request:e,response:t});let{cacheKey:r,cache:n,cacheTime:o,garbageCollection:a}=e,d=this.storage.get(r),i=ht(d,t),u=W(F({},i),{cacheTime:o,clearKey:this.clearKey,garbageCollection:a});if(this.events.emitCacheData(r,u),this.logger.debug("Emitting cache response",{request:e,data:i}),!n)return this.logger.debug("Prevented saving response to cache",{request:e,data:i});t.success&&(this.logger.debug("Saving response to cache storage",{request:e,data:i}),this.storage.set(r,u),(E=this.lazyStorage)==null||E.set(r,u),(v=(h=this.options)==null?void 0:h.onChange)==null||v.call(h,r,u),this.scheduleGarbageCollector(r))};this.get=e=>(this.getLazyResource(e),this.storage.get(e));this.keys=()=>{let e=this.storage.keys();return Array.from(e)};this.delete=e=>{var t,r,n;this.logger.debug("Deleting cache element",{cacheKey:e}),this.storage.delete(e),(r=(t=this.options)==null?void 0:t.onDelete)==null||r.call(t,e),(n=this.lazyStorage)==null||n.delete(e)};this.revalidate=e=>l(this,null,function*(){this.logger.debug("Revalidating cache element",{cacheKey:e});let t=yield this.getLazyKeys();if(typeof e=="string")this.events.emitRevalidation(e),this.delete(e);else for(let r of t)e.test(r)&&(this.events.emitRevalidation(r),this.delete(r))});this.getLazyResource=e=>l(this,null,function*(){var a;let t=yield(a=this.lazyStorage)==null?void 0:a.get(e),r=this.storage.get(e);if(this.lazyStorage&&t){let d=+new Date,i=r?r.timestamp<t.timestamp:!0,u=t.cacheTime<=d-t.timestamp,E=t.clearKey===this.clearKey;if(E||this.lazyStorage.delete(e),i&&!u&&E)return this.storage.set(e,t),this.events.emitCacheData(e,t),t}let o=(r==null?void 0:r.clearKey)===this.clearKey;return r&&!o&&this.delete(e),r});this.getLazyKeys=()=>l(this,null,function*(){var n;let e=yield(n=this.lazyStorage)==null?void 0:n.keys(),t=Array.from(e||[]),r=Array.from(this.storage.keys());return[...new Set([...t,...r])]});this.scheduleGarbageCollector=e=>l(this,null,function*(){let t=yield this.getLazyResource(e);if(clearTimeout(this.garbageCollectors.get(e)),t){let r=t.garbageCollection+t.timestamp-+new Date;t.garbageCollection!==null&&JSON.stringify(t.garbageCollection)==="null"?this.logger.info("Cache value is Infinite",{cacheKey:e}):r>=0?this.garbageCollectors.set(e,setTimeout(()=>{this.client.appManager.isOnline&&(this.logger.info("Garbage collecting cache element",{cacheKey:e}),this.delete(e))},r)):this.client.appManager.isOnline&&(this.logger.info("Garbage collecting cache element",{cacheKey:e}),this.delete(e))}});this.clear=()=>l(this,null,function*(){this.storage.clear()});var r,n,o,a,d;this.storage=((r=this.options)==null?void 0:r.storage)||new Map,this.events=ft(this.emitter),(o=(n=this.options)==null?void 0:n.onInitialization)==null||o.call(n,this),this.clearKey=((a=this.options)==null?void 0:a.clearKey)||"",this.lazyStorage=(d=this.options)==null?void 0:d.lazyStorage,this.logger=this.client.loggerManager.init("Cache"),this.getLazyKeys().then(i=>{i.forEach(this.scheduleGarbageCollector)}),this.client.appManager.events.onOnline(()=>{this.getLazyKeys().then(i=>{i.forEach(this.scheduleGarbageCollector)})})}};var ht=(s,e)=>{let{data:t,success:r}=e,n=!r&&s?s.data:null,o=t||n;return W(F({},e),{data:o})},ve=s=>`${s}_revalidate`,qe=s=>`${s}_cache`,un=s=>`${s}_cache_by_id`;var ft=s=>({emitCacheData:(e,t)=>{s.emit(qe(e),t)},emitRevalidation:e=>{s.emit(ve(e))},onData:(e,t)=>(s.on(qe(e),t),()=>s.removeListener(qe(e),t)),onRevalidate:(e,t)=>(s.on(ve(e),t),()=>s.removeListener(ve(e),t))});import Ut from"events";var ue=class{constructor(e){this.options=e;this.emitter=new Ut;this.events=mt(this.emitter);this.setInitialFocus=e=>l(this,null,function*(){typeof e=="function"?(this.isFocused=!1,this.isFocused=yield e()):this.isFocused=e});this.setInitialOnline=e=>l(this,null,function*(){typeof e=="function"?(this.isOnline=!1,this.isOnline=yield e()):this.isOnline=e});this.setFocused=e=>{this.isFocused=e,e?this.events.emitFocus():this.events.emitBlur()};this.setOnline=e=>{this.isOnline=e,e?this.events.emitOnline():this.events.emitOffline()};let{focusEvent:t=ee.focusEvent,onlineEvent:r=ee.onlineEvent,initiallyFocused:n=ee.initiallyFocused,initiallyOnline:o=ee.initiallyOnline}=this.options||ee;this.setInitialFocus(n),this.setInitialOnline(o),t(this.setFocused),r(this.setOnline),this.isBrowser=Ye()}};var ce=()=>{try{return Boolean(window&&window.addEventListener)}catch(s){return!1}},Ye=()=>{try{return Boolean(ce()&&window.document&&window.document.addEventListener)}catch(s){return!1}},de=(s,e,t)=>{ce()&&window.addEventListener(s,e,t)},Rt=(s,e,t)=>{Ye()&&window.document.addEventListener(s,e,t)};var mt=s=>({emitFocus:()=>{s.emit("focus")},emitBlur:()=>{s.emit("blur")},emitOnline:()=>{s.emit("online")},emitOffline:()=>{s.emit("offline")},onFocus:e=>(s.on("focus",e),()=>s.removeListener("focus",e)),onBlur:e=>(s.on("blur",e),()=>s.removeListener("blur",e)),onOnline:e=>(s.on("online",e),()=>s.removeListener("online",e)),onOffline:e=>(s.on("offline",e),()=>s.removeListener("offline",e))});var Tt=(n=>(n.focus="focus",n.blur="blur",n.online="online",n.offline="offline",n))(Tt||{}),ee={initiallyFocused:!0,initiallyOnline:!0,focusEvent:s=>{Rt("visibilitychange",()=>s(!0)),de("focus",()=>s(!0)),de("blur",()=>s(!1))},onlineEvent:s=>{de("online",()=>s(!0)),de("offline",()=>s(!1))}};import zt from"events";var Ce=class{constructor(){this.emitter=new zt;this.events=Et(this.emitter);this.abortControllers=new Map;this.addAbortController=(e,t)=>{let r=this.abortControllers.get(e);if(!r){let o=new Map;r=o,this.abortControllers.set(e,o)}let n=r.get(t);(!n||n.signal.aborted)&&r.set(t,new AbortController)};this.getAbortController=(e,t)=>{var r;return(r=this.abortControllers.get(e))==null?void 0:r.get(t)};this.removeAbortController=(e,t)=>{var r;(r=this.abortControllers.get(e))==null||r.delete(t)};this.useAbortController=(e,t)=>{var n;let r=(n=this.abortControllers.get(e))==null?void 0:n.get(t);r==null||r.abort()};this.abortByKey=e=>{let t=this.abortControllers.get(e);t&&Array.from(t.entries()).forEach(([n])=>{this.useAbortController(e,n)})};this.abortByRequestId=(e,t)=>{this.useAbortController(e,t)};this.abortAll=()=>{Array.from(this.abortControllers.entries()).forEach(([t,r])=>{Array.from(r.entries()).forEach(([o])=>{this.useAbortController(t,o)})})}}};var Ie=s=>`${s}-loading-event`,Me=s=>`${s}-loading-event-by-id`,we=s=>`${s}-remove-event`,Pe=s=>`${s}-remove-event-by-id`,De=s=>`${s}-request-abort`,Qe=s=>`${s}-request-abort-by-id`,Le=s=>`${s}-response`,Ke=s=>`${s}-response-by-id`,ke=s=>`${s}-request-start`,$e=s=>`${s}-request-start-by-id`,Fe=s=>`${s}-response-start`,_e=s=>`${s}-response-start-by-id`,Se=s=>`${s}-request-progress`,Ge=s=>`${s}-request-progress-by-id`,Ve=s=>`${s}-response-progress`,He=s=>`${s}-response-progress-by-id`;var Et=s=>({emitLoading:(e,t,r)=>{s.emit(Me(t),r),s.emit(Ie(e),r)},emitRequestStart:(e,t,r)=>{s.emit($e(t),r),s.emit(ke(e),r)},emitResponseStart:(e,t,r)=>{s.emit(_e(t),r),s.emit(Fe(e),r)},emitUploadProgress:(e,t,r,n)=>{s.emit(Ge(t),r,n),s.emit(Se(e),r,n)},emitDownloadProgress:(e,t,r,n)=>{s.emit(He(t),r,n),s.emit(Ve(e),r,n)},emitResponse:(e,t,r,n)=>{s.emit(Ke(t),r,n),s.emit(Le(e),r,n)},emitAbort:(e,t,r)=>{s.emit(Qe(t),r),s.emit(De(e),r)},emitRemove:(e,t,r)=>{s.emit(we(e),r),s.emit(Pe(t),r)},onLoading:(e,t)=>(s.on(Ie(e),t),()=>s.removeListener(Ie(e),t)),onLoadingById:(e,t)=>(s.on(Me(e),t),()=>s.removeListener(Me(e),t)),onRequestStart:(e,t)=>(s.on(ke(e),t),()=>s.removeListener(ke(e),t)),onRequestStartById:(e,t)=>(s.on($e(e),t),()=>s.removeListener($e(e),t)),onResponseStart:(e,t)=>(s.on(Fe(e),t),()=>s.removeListener(Fe(e),t)),onResponseStartById:(e,t)=>(s.on(_e(e),t),()=>s.removeListener(_e(e),t)),onUploadProgress:(e,t)=>(s.on(Se(e),t),()=>s.removeListener(Se(e),t)),onUploadProgressById:(e,t)=>(s.on(Ge(e),t),()=>s.removeListener(Ge(e),t)),onDownloadProgress:(e,t)=>(s.on(Ve(e),t),()=>s.removeListener(Ve(e),t)),onDownloadProgressById:(e,t)=>(s.on(He(e),t),()=>s.removeListener(He(e),t)),onResponse:(e,t)=>(s.on(Le(e),t),()=>s.removeListener(Le(e),t)),onResponseById:(e,t)=>(s.on(Ke(e),t),()=>s.removeListener(Ke(e),t)),onAbort:(e,t)=>(s.on(De(e),t),()=>s.removeListener(De(e),t)),onAbortById:(e,t)=>(s.on(Qe(e),t),()=>s.removeListener(Qe(e),t)),onRemove:(e,t)=>(s.on(we(e),t),()=>s.removeListener(we(e),t)),onRemoveById:(e,t)=>(s.on(Pe(e),t),()=>s.removeListener(Pe(e),t))});import Ot from"events";var Be=class{constructor(e,t){this.client=e;this.options=t;this.emitter=new Ot;this.setSeverity=e=>{this.severity=e};this.init=e=>({error:(t,...r)=>{this.logger({level:"error",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},warning:(t,...r)=>{this.logger({level:"warning",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},info:(t,...r)=>{this.logger({level:"info",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})},debug:(t,...r)=>{this.logger({level:"debug",module:e,message:t,extra:r,severity:this.severity,enabled:this.client.debug})}});var r,n;this.logger=((r=this.options)==null?void 0:r.logger)||xt,this.severity=((n=this.options)==null?void 0:n.severity)||2}};var jt=()=>{let s=new Date;return`${s.toLocaleTimeString()}(:${s.getMilliseconds()})`},xt=s=>{var e;if(s.enabled&&s.severity>=vt[s.level]){let t=bt[s.level],r=At[s.level],n=`%c[${s.module}]:[${jt()}]:`,o=`${r}${n} ${s.message}`;(e=s.extra)!=null&&e.length?(console.groupCollapsed(o,t),s.extra.forEach(a=>{console.log(a)}),console.groupEnd()):console.log(o,t)}};var Ue="background:rgba(0,0,0,0.2);padding:2px 5px;border-radius:5px;font-weight:bold;",bt={error:`${Ue}color:#db2525`,warning:`${Ue}color:#e1941e`,info:`${Ue}color:#1e74e1`,debug:`${Ue}color:#adadad`},At={error:"\u{1F6A8}",warning:"\u{1F6A7}",info:"\u2139\uFE0F",debug:"\u{1F6E9}\uFE0F"},vt={error:0,warning:1,info:2,debug:3};var Wt=s=>{try{return JSON.stringify(s)}catch(e){return""}},Ze=(s,e)=>l(void 0,null,function*(){let t=e;if(!e.requestOptions.disableRequestInterceptors){for(let r of s)if(t=yield r(e),!t)throw new Error("Request modifier must return request")}return t}),ze=(s,e,t)=>l(void 0,null,function*(){let r=e;if(!t.requestOptions.disableResponseInterceptors){for(let n of s)if(r=yield n(e,t),!r)throw new Error("Response modifier must return data")}return r}),qt=s=>{let e=ce()&&s.data instanceof FormData,t={};return e||(t["Content-Type"]="application/json"),Object.assign(t,s.headers),t},Ct=s=>ce()&&s instanceof FormData?s:Wt(s),It=s=>e=>{let{skipNull:t,skipEmptyString:r}=s;return!(r&&e===void 0||r&&e===""||t&&e===null)},_=(s,{encode:e,strict:t})=>e&&t?encodeURIComponent(s).replace(/[!'()*]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase()}`):e?encodeURIComponent(s):s,Xt=(s,e,t)=>{let r=!It(t)(e);if(!s||r)return"";let n=()=>{var o,a;return e instanceof Date?((o=t.dateParser)==null?void 0:o.call(t,e))||e.toISOString():typeof e=="object"&&!Array.isArray(e)?((a=t.objectParser)==null?void 0:a.call(t,e))||JSON.stringify(e):String(e)};return`${_(s,t)}=${_(n(),t)}`},Yt=(s,e,t)=>{let{arrayFormat:r,arraySeparator:n}=t;return e.filter(It(t)).reduce((o,a,d)=>{switch(r){case"index":{let i=`${_(s,t)}[${_(String(d),t)}]=`;o.push(`${i}${_(String(a),t)}`);break}case"bracket":{let i=`${_(s,t)}[]=`;o.push(`${i}${_(String(a),t)}`);break}case"comma":{let i=!o.length&&`${_(s,t)}=`||"";return[[...o,`${i}${_(String(a),t)}`].join(",")]}case"separator":{let i=!o.length&&`${_(s,t)}=`||"";return[[...o,`${i}${_(String(a),t)}`].join(n||"|")]}case"bracket-separator":{let i=!o.length&&`${_(s,t)}[]=`||"";return[[...o,`${i}${_(String(a),t)}`].join(n||"|")]}default:{let i=`${_(s,t)}=`;o.push(`${i}${_(String(a),t)}`)}}return o},[]).join("&")},Mt=(s,e=wt)=>{if(!s||!Object.keys(s).length)return"";if(typeof s=="string")return s[0]==="?"?s:`?${s}`;let t=Object.entries(s).map(([r,n])=>Array.isArray(n)?Yt(r,n,e):Xt(r,n,e)).filter(Boolean).join("&");return t?`?${t}`:""};var Pt=class{constructor(e){this.options=e;this.__onErrorCallbacks=[];this.__onSuccessCallbacks=[];this.__onResponseCallbacks=[];this.__onAuthCallbacks=[];this.__onRequestCallbacks=[];this.requestManager=new Ce;this.loggerManager=new Be(this);this.defaultMethod="GET";this.defaultExtra=U;this.effects=[];this.abortKeyMapper=Ae;this.cacheKeyMapper=ut;this.queueKeyMapper=Ae;this.effectKeyMapper=Ae;this.stringifyQueryParams=e=>Mt(e,this.queryParamsConfig);this.headerMapper=qt;this.payloadMapper=Ct;this.logger=this.loggerManager.init("Client");this.setRequestDefaultOptions=e=>(this.requestDefaultOptions=e,this);this.setAdapterDefaultOptions=e=>(this.adapterDefaultOptions=e,this);this.setDebug=e=>(this.debug=e,this);this.setLoggerSeverity=e=>(this.loggerManager.setSeverity(e),this);this.setLogger=e=>(this.loggerManager=e(this),this);this.setQueryParamsConfig=e=>(this.queryParamsConfig=e,this);this.setStringifyQueryParams=e=>(this.stringifyQueryParams=e,this);this.setHeaderMapper=e=>(this.headerMapper=e,this);this.setPayloadMapper=e=>(this.payloadMapper=e,this);this.setAdapter=e=>(this.adapter=e(this),this);this.setDefaultMethod=e=>(this.defaultMethod=e,this);this.setDefaultExtra=e=>(this.defaultExtra=e,this);this.onAuth=e=>(this.__onAuthCallbacks.push(e),this);this.onError=e=>(this.__onErrorCallbacks.push(e),this);this.onSuccess=e=>(this.__onSuccessCallbacks.push(e),this);this.onRequest=e=>(this.__onRequestCallbacks.push(e),this);this.onResponse=e=>(this.__onResponseCallbacks.push(e),this);this.addEffect=e=>(this.effects=this.effects.concat(e),this);this.removeEffect=e=>{let t=typeof e=="string"?e:e.getEffectKey();return this.effects=this.effects.filter(r=>r.getEffectKey()!==t),this};this.setAbortKeyMapper=e=>{this.abortKeyMapper=e};this.setCacheKeyMapper=e=>{this.cacheKeyMapper=e};this.setQueueKeyMapper=e=>{this.queueKeyMapper=e};this.setEffectKeyMapper=e=>{this.effectKeyMapper=e};this.__modifyAuth=e=>l(this,null,function*(){return Ze(this.__onAuthCallbacks,e)});this.__modifyRequest=e=>l(this,null,function*(){return Ze(this.__onRequestCallbacks,e)});this.__modifyErrorResponse=(e,t)=>l(this,null,function*(){return ze(this.__onErrorCallbacks,e,t)});this.__modifySuccessResponse=(e,t)=>l(this,null,function*(){return ze(this.__onSuccessCallbacks,e,t)});this.__modifyResponse=(e,t)=>l(this,null,function*(){return ze(this.__onResponseCallbacks,e,t)});this.clear=()=>{let{appManager:e,cache:t,fetchDispatcher:r,submitDispatcher:n}=this.options;this.requestManager.abortControllers.clear(),this.fetchDispatcher.clear(),this.submitDispatcher.clear(),this.cache.clear(),this.requestManager.emitter.removeAllListeners(),this.fetchDispatcher.emitter.removeAllListeners(),this.submitDispatcher.emitter.removeAllListeners(),this.cache.emitter.removeAllListeners(),this.appManager=(e==null?void 0:e(this))||new ue,this.cache=(t==null?void 0:t(this))||new pe(this),this.fetchDispatcher=(r==null?void 0:r(this))||new N(this),this.submitDispatcher=(n==null?void 0:n(this))||new N(this)};this.createRequest=()=>e=>new J(this,e);let{url:t,adapter:r,appManager:n,cache:o,fetchDispatcher:a,submitDispatcher:d}=this.options;this.url=t,this.adapter=r||yt,this.appManager=(n==null?void 0:n(this))||new ue,this.cache=(o==null?void 0:o(this))||new pe(this),this.fetchDispatcher=(a==null?void 0:a(this))||new N(this),this.submitDispatcher=(d==null?void 0:d(this))||new N(this)}};var wt={strict:!0,encode:!0,arrayFormat:"bracket",arraySeparator:"",sort:!1,skipNull:!0,skipEmptyString:!0},U={headers:{}};export{Tt as AppEvents,ue as AppManager,pe as Cache,Pt as Client,je as DateInterval,N as Dispatcher,We as DispatcherRequestType,Re as HttpMethodsEnum,Be as LoggerManager,J as Request,rt as RequestEffect,Ce as RequestManager,yt as adapter,ee as appManagerInitialOptions,be as canRetryRequest,ye as defaultTimeout,Qe as getAbortByIdEventKey,De as getAbortEventKey,he as getAdapterBindings,qt as getAdapterHeaders,Ct as getAdapterPayload,mt as getAppManagerEvents,ht as getCacheData,ft as getCacheEvents,un as getCacheIdKey,qe as getCacheKey,xe as getDispatcherChangeEventKey,Te as getDispatcherDrainedEventKey,at as getDispatcherEvents,Ee as getDispatcherStatusEventKey,Ve as getDownloadProgressEventKey,He as getDownloadProgressIdEventKey,O as getErrorMessage,Wr as getIsEqualTimestamp,Ie as getLoadingEventKey,Me as getLoadingIdEventKey,Xe as getProgressData,$t as getProgressValue,we as getRemoveEventKey,Pe as getRemoveIdEventKey,_t as getRequestDispatcher,Ft as getRequestEta,ut as getRequestKey,Et as getRequestManagerEvents,ke as getRequestStartEventKey,$e as getRequestStartIdEventKey,it as getRequestType,Le as getResponseEventKey,nt as getResponseHeaders,Ke as getResponseIdEventKey,Fe as getResponseStartEventKey,_e as getResponseStartIdEventKey,ve as getRevalidateEventKey,Ae as getSimpleKey,lt as getStreamPayload,jt as getTime,me as getUniqueRequestId,Se as getUploadProgressEventKey,Ge as getUploadProgressIdEventKey,dt as getUploadSize,Ye as hasDocument,ce as hasWindow,Ze as interceptRequest,ze as interceptResponse,xt as logger,At as loggerIconLevels,bt as loggerStyles,ct as mocker,Rt as onDocumentEvent,de as onWindowEvent,fe as parseErrorResponse,ie as parseResponse,ot as sendRequest,vt as severity,wt as stringifyDefaultOptions,pt as stringifyKey,Mt as stringifyQueryParams,Wt as stringifyValue,U as xhrExtra};
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/effect/request.effect.ts
|
|
54
|
+
var RequestEffect = class {
|
|
55
|
+
constructor(config) {
|
|
56
|
+
this.config = config;
|
|
57
|
+
this.getEffectKey = () => {
|
|
58
|
+
return this.config.effectKey;
|
|
59
|
+
};
|
|
60
|
+
this.onTrigger = (request) => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
(_b = (_a = this.config).onTrigger) == null ? void 0 : _b.call(_a, request);
|
|
63
|
+
};
|
|
64
|
+
this.onStart = (request) => {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
(_b = (_a = this.config).onStart) == null ? void 0 : _b.call(_a, request);
|
|
67
|
+
};
|
|
68
|
+
this.onSuccess = (response, request) => {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
(_b = (_a = this.config).onSuccess) == null ? void 0 : _b.call(_a, response, request);
|
|
71
|
+
};
|
|
72
|
+
this.onError = (response, request) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
(_b = (_a = this.config).onError) == null ? void 0 : _b.call(_a, response, request);
|
|
75
|
+
};
|
|
76
|
+
this.onFinished = (response, request) => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
(_b = (_a = this.config).onFinished) == null ? void 0 : _b.call(_a, response, request);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/constants/time.constants.ts
|
|
84
|
+
var DateInterval = /* @__PURE__ */ ((DateInterval2) => {
|
|
85
|
+
DateInterval2[DateInterval2["second"] = 1e3] = "second";
|
|
86
|
+
DateInterval2[DateInterval2["minute"] = 6e4] = "minute";
|
|
87
|
+
DateInterval2[DateInterval2["hour"] = 36e5] = "hour";
|
|
88
|
+
DateInterval2[DateInterval2["day"] = 864e5] = "day";
|
|
89
|
+
DateInterval2[DateInterval2["week"] = 6048e5] = "week";
|
|
90
|
+
DateInterval2[DateInterval2["month30"] = 2592e6] = "month30";
|
|
91
|
+
DateInterval2[DateInterval2["month31"] = 26784e5] = "month31";
|
|
92
|
+
DateInterval2[DateInterval2["year"] = 31536e6] = "year";
|
|
93
|
+
DateInterval2[DateInterval2["yearLeap"] = 316224e5] = "yearLeap";
|
|
94
|
+
return DateInterval2;
|
|
95
|
+
})(DateInterval || {});
|
|
96
|
+
|
|
97
|
+
// src/adapter/adapter.constants.ts
|
|
98
|
+
var defaultTimeout = 1e3 /* second */ * 5;
|
|
99
|
+
var xhrExtra = {
|
|
100
|
+
headers: {}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/adapter/adapter.browser.ts
|
|
104
|
+
var adapter = (request, requestId) => __async(void 0, null, function* () {
|
|
105
|
+
const {
|
|
106
|
+
makeRequest,
|
|
107
|
+
fullUrl,
|
|
108
|
+
config,
|
|
109
|
+
payload,
|
|
110
|
+
headers,
|
|
111
|
+
onError,
|
|
112
|
+
onResponseEnd,
|
|
113
|
+
onTimeoutError,
|
|
114
|
+
onRequestEnd,
|
|
115
|
+
createAbortListener,
|
|
116
|
+
onResponseProgress,
|
|
117
|
+
onRequestProgress,
|
|
118
|
+
onResponseStart,
|
|
119
|
+
onBeforeRequest,
|
|
120
|
+
onRequestStart,
|
|
121
|
+
onSuccess
|
|
122
|
+
} = yield getAdapterBindings(request, requestId, 0, {
|
|
123
|
+
headers: {}
|
|
124
|
+
});
|
|
125
|
+
const { method = "GET" } = request;
|
|
126
|
+
return makeRequest((resolve) => {
|
|
127
|
+
const xhr = new XMLHttpRequest();
|
|
128
|
+
xhr.timeout = defaultTimeout;
|
|
129
|
+
const abort = () => xhr.abort();
|
|
130
|
+
Object.entries(config).forEach(([name, value]) => {
|
|
131
|
+
xhr[name] = value;
|
|
132
|
+
});
|
|
133
|
+
xhr.open(method, fullUrl, true);
|
|
134
|
+
Object.entries(headers).forEach(([name, value]) => xhr.setRequestHeader(name, value));
|
|
135
|
+
const unmountListener = createAbortListener(0, xhrExtra, abort, resolve);
|
|
136
|
+
xhr.upload.onprogress = onRequestProgress;
|
|
137
|
+
xhr.onloadstart = () => {
|
|
138
|
+
onRequestEnd();
|
|
139
|
+
onResponseStart();
|
|
140
|
+
};
|
|
141
|
+
xhr.onprogress = onResponseProgress;
|
|
142
|
+
xhr.onloadend = () => {
|
|
143
|
+
onResponseEnd();
|
|
144
|
+
unmountListener();
|
|
145
|
+
};
|
|
146
|
+
xhr.ontimeout = () => onTimeoutError(0, xhrExtra, resolve);
|
|
147
|
+
xhr.onreadystatechange = (e) => {
|
|
148
|
+
const event = e;
|
|
149
|
+
const finishedState = 4;
|
|
150
|
+
if (event.target && event.target.readyState === finishedState) {
|
|
151
|
+
const { status } = event.target;
|
|
152
|
+
const success = String(status).startsWith("2") || String(status).startsWith("3");
|
|
153
|
+
const responseHeaders = getResponseHeaders(xhr.getAllResponseHeaders());
|
|
154
|
+
if (success) {
|
|
155
|
+
const data = parseResponse(event.target.response);
|
|
156
|
+
onSuccess(data, status, { headers: responseHeaders }, resolve);
|
|
157
|
+
} else {
|
|
158
|
+
const data = parseErrorResponse(event.target.response);
|
|
159
|
+
onError(data, status, { headers: responseHeaders }, resolve);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
onBeforeRequest();
|
|
164
|
+
onRequestStart();
|
|
165
|
+
xhr.send(payload);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// src/adapter/adapter.server.ts
|
|
170
|
+
import http from "http";
|
|
171
|
+
import https from "https";
|
|
172
|
+
|
|
173
|
+
// src/constants/http.constants.ts
|
|
174
|
+
var HttpMethodsEnum = /* @__PURE__ */ ((HttpMethodsEnum2) => {
|
|
175
|
+
HttpMethodsEnum2["get"] = "GET";
|
|
176
|
+
HttpMethodsEnum2["post"] = "POST";
|
|
177
|
+
HttpMethodsEnum2["put"] = "PUT";
|
|
178
|
+
HttpMethodsEnum2["patch"] = "PATCH";
|
|
179
|
+
HttpMethodsEnum2["delete"] = "DELETE";
|
|
180
|
+
return HttpMethodsEnum2;
|
|
181
|
+
})(HttpMethodsEnum || {});
|
|
182
|
+
|
|
183
|
+
// src/adapter/adapter.server.ts
|
|
184
|
+
var adapter2 = (request, requestId) => __async(void 0, null, function* () {
|
|
185
|
+
const {
|
|
186
|
+
makeRequest,
|
|
187
|
+
fullUrl,
|
|
188
|
+
config,
|
|
189
|
+
headers,
|
|
190
|
+
payload,
|
|
191
|
+
onError,
|
|
192
|
+
onResponseEnd,
|
|
193
|
+
onTimeoutError,
|
|
194
|
+
onRequestEnd,
|
|
195
|
+
createAbortListener,
|
|
196
|
+
onResponseProgress,
|
|
197
|
+
onResponseStart,
|
|
198
|
+
onBeforeRequest,
|
|
199
|
+
onRequestStart,
|
|
200
|
+
onSuccess
|
|
201
|
+
} = yield getAdapterBindings(request, requestId, 0, xhrExtra);
|
|
202
|
+
const { method = "GET" /* get */, client } = request;
|
|
203
|
+
const httpClient = client.url.includes("https://") ? https : http;
|
|
204
|
+
const options = {
|
|
205
|
+
path: fullUrl,
|
|
206
|
+
method,
|
|
207
|
+
headers,
|
|
208
|
+
timeout: defaultTimeout
|
|
209
|
+
};
|
|
210
|
+
Object.entries(config).forEach(([name, value]) => {
|
|
211
|
+
options[name] = value;
|
|
212
|
+
});
|
|
213
|
+
let unmountListener = () => null;
|
|
214
|
+
onBeforeRequest();
|
|
215
|
+
if (payload) {
|
|
216
|
+
options.headers["Content-Length"] = Buffer.byteLength(JSON.stringify(payload));
|
|
217
|
+
}
|
|
218
|
+
return makeRequest((resolve) => {
|
|
219
|
+
const httpRequest = httpClient.request(options, (response) => {
|
|
220
|
+
response.setEncoding("utf8");
|
|
221
|
+
unmountListener = createAbortListener(0, xhrExtra, response.destroy, resolve);
|
|
222
|
+
let chunks = "";
|
|
223
|
+
const totalDownloadBytes = Number(response.headers["content-length"]);
|
|
224
|
+
let downloadedBytes = 0;
|
|
225
|
+
onRequestStart();
|
|
226
|
+
response.on("data", (chunk) => {
|
|
227
|
+
if (!chunks) {
|
|
228
|
+
onRequestEnd();
|
|
229
|
+
onResponseStart();
|
|
230
|
+
}
|
|
231
|
+
downloadedBytes += chunk.length;
|
|
232
|
+
chunks += chunk;
|
|
233
|
+
onResponseProgress({ total: totalDownloadBytes, loaded: downloadedBytes });
|
|
234
|
+
});
|
|
235
|
+
response.on("end", () => {
|
|
236
|
+
const { statusCode } = response;
|
|
237
|
+
const success = String(statusCode).startsWith("2") || String(statusCode).startsWith("3");
|
|
238
|
+
if (success) {
|
|
239
|
+
const data = parseResponse(chunks);
|
|
240
|
+
onSuccess(data, statusCode, { headers: response.headers }, resolve);
|
|
241
|
+
} else {
|
|
242
|
+
const data = parseErrorResponse(chunks);
|
|
243
|
+
onError(data, statusCode, { headers: response.headers }, resolve);
|
|
244
|
+
}
|
|
245
|
+
unmountListener();
|
|
246
|
+
onResponseEnd();
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
httpRequest.on("timeout", () => onTimeoutError(0, xhrExtra, resolve));
|
|
250
|
+
httpRequest.on("error", (error) => onError(error, 0, xhrExtra, resolve));
|
|
251
|
+
if (payload) {
|
|
252
|
+
httpRequest.write(payload);
|
|
253
|
+
}
|
|
254
|
+
httpRequest.end();
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// src/adapter/adapter.ts
|
|
259
|
+
var adapter3 = (request, requestId) => __async(void 0, null, function* () {
|
|
260
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
261
|
+
return adapter(request, requestId);
|
|
262
|
+
}
|
|
263
|
+
return adapter2(request, requestId);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// src/adapter/adapter.utils.ts
|
|
267
|
+
var getErrorMessage = (errorCase) => {
|
|
268
|
+
if (errorCase === "timeout") {
|
|
269
|
+
return new Error("Request timeout");
|
|
270
|
+
}
|
|
271
|
+
if (errorCase === "abort") {
|
|
272
|
+
return new Error("Request cancelled");
|
|
273
|
+
}
|
|
274
|
+
return new Error("Unexpected error");
|
|
275
|
+
};
|
|
276
|
+
var getResponseHeaders = (headersString) => {
|
|
277
|
+
const arr = headersString.trim().split(/[\r\n]+/);
|
|
278
|
+
const headers = {};
|
|
279
|
+
arr.forEach((line) => {
|
|
280
|
+
const parts = line.split(": ");
|
|
281
|
+
const header = parts.shift();
|
|
282
|
+
const value = parts.join(": ");
|
|
283
|
+
headers[header] = value;
|
|
284
|
+
});
|
|
285
|
+
return headers;
|
|
286
|
+
};
|
|
287
|
+
var parseResponse = (response) => {
|
|
288
|
+
try {
|
|
289
|
+
return JSON.parse(response);
|
|
290
|
+
} catch (err) {
|
|
291
|
+
return response;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var parseErrorResponse = (response) => {
|
|
295
|
+
return response ? parseResponse(response) : getErrorMessage();
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
// src/utils/uuid.utils.ts
|
|
299
|
+
var getUniqueRequestId = (key) => {
|
|
300
|
+
return `${key}_${Date.now().toString(36)}_${Math.random().toString(36).substring(2)}`;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// src/request/request.ts
|
|
304
|
+
var Request = class {
|
|
305
|
+
constructor(client, requestOptions, requestJSON) {
|
|
306
|
+
this.client = client;
|
|
307
|
+
this.requestOptions = requestOptions;
|
|
308
|
+
this.requestJSON = requestJSON;
|
|
309
|
+
this.setHeaders = (headers) => {
|
|
310
|
+
return this.clone({ headers });
|
|
311
|
+
};
|
|
312
|
+
this.setAuth = (auth) => {
|
|
313
|
+
return this.clone({ auth });
|
|
314
|
+
};
|
|
315
|
+
this.setParams = (params) => {
|
|
316
|
+
return this.clone({ params });
|
|
317
|
+
};
|
|
318
|
+
this.setData = (data) => {
|
|
319
|
+
return this.clone({
|
|
320
|
+
data
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
this.setQueryParams = (queryParams) => {
|
|
324
|
+
return this.clone({ queryParams });
|
|
325
|
+
};
|
|
326
|
+
this.setOptions = (options) => {
|
|
327
|
+
return this.clone({ options });
|
|
328
|
+
};
|
|
329
|
+
this.setCancelable = (cancelable) => {
|
|
330
|
+
return this.clone({ cancelable });
|
|
331
|
+
};
|
|
332
|
+
this.setRetry = (retry) => {
|
|
333
|
+
return this.clone({ retry });
|
|
334
|
+
};
|
|
335
|
+
this.setRetryTime = (retryTime) => {
|
|
336
|
+
return this.clone({ retryTime });
|
|
337
|
+
};
|
|
338
|
+
this.setGarbageCollection = (garbageCollection) => {
|
|
339
|
+
return this.clone({ garbageCollection });
|
|
340
|
+
};
|
|
341
|
+
this.setCache = (cache) => {
|
|
342
|
+
return this.clone({ cache });
|
|
343
|
+
};
|
|
344
|
+
this.setCacheTime = (cacheTime) => {
|
|
345
|
+
return this.clone({ cacheTime });
|
|
346
|
+
};
|
|
347
|
+
this.setQueued = (queued) => {
|
|
348
|
+
return this.clone({ queued });
|
|
349
|
+
};
|
|
350
|
+
this.setAbortKey = (abortKey) => {
|
|
351
|
+
this.updatedAbortKey = true;
|
|
352
|
+
return this.clone({ abortKey });
|
|
353
|
+
};
|
|
354
|
+
this.setCacheKey = (cacheKey) => {
|
|
355
|
+
this.updatedCacheKey = true;
|
|
356
|
+
return this.clone({ cacheKey });
|
|
357
|
+
};
|
|
358
|
+
this.setQueueKey = (queueKey) => {
|
|
359
|
+
this.updatedQueueKey = true;
|
|
360
|
+
return this.clone({ queueKey });
|
|
361
|
+
};
|
|
362
|
+
this.setEffectKey = (effectKey) => {
|
|
363
|
+
this.updatedEffectKey = true;
|
|
364
|
+
return this.clone({ effectKey });
|
|
365
|
+
};
|
|
366
|
+
this.setDeduplicate = (deduplicate) => {
|
|
367
|
+
return this.clone({ deduplicate });
|
|
368
|
+
};
|
|
369
|
+
this.setDeduplicateTime = (deduplicateTime) => {
|
|
370
|
+
return this.clone({ deduplicateTime });
|
|
371
|
+
};
|
|
372
|
+
this.setUsed = (used) => {
|
|
373
|
+
return this.clone({ used });
|
|
374
|
+
};
|
|
375
|
+
this.setOffline = (offline) => {
|
|
376
|
+
return this.clone({ offline });
|
|
377
|
+
};
|
|
378
|
+
this.setMock = (mockData) => {
|
|
379
|
+
const mockGenerator = function* mocked(mockedValues) {
|
|
380
|
+
if (Array.isArray(mockData)) {
|
|
381
|
+
let iteration = 0;
|
|
382
|
+
while (true) {
|
|
383
|
+
yield mockedValues[iteration];
|
|
384
|
+
iteration = mockData.length === iteration + 1 ? 0 : iteration + 1;
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
while (true) {
|
|
388
|
+
yield mockData;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
this.mockData = mockData;
|
|
393
|
+
this.mock = mockGenerator(mockData);
|
|
394
|
+
return this;
|
|
395
|
+
};
|
|
396
|
+
this.removeMock = () => {
|
|
397
|
+
this.mockData = null;
|
|
398
|
+
this.mock = null;
|
|
399
|
+
return this;
|
|
400
|
+
};
|
|
401
|
+
this.setDataMapper = (dataMapper) => {
|
|
402
|
+
const cloned = this.clone(void 0);
|
|
403
|
+
cloned.dataMapper = dataMapper;
|
|
404
|
+
return cloned;
|
|
405
|
+
};
|
|
406
|
+
this.setRequestMapper = (requestMapper) => {
|
|
407
|
+
const cloned = this.clone(void 0);
|
|
408
|
+
cloned.requestMapper = requestMapper;
|
|
409
|
+
return cloned;
|
|
410
|
+
};
|
|
411
|
+
this.setResponseMapper = (responseMapper) => {
|
|
412
|
+
const cloned = this.clone();
|
|
413
|
+
cloned.responseMapper = responseMapper;
|
|
414
|
+
return cloned;
|
|
415
|
+
};
|
|
416
|
+
this.paramsMapper = (params, queryParams) => {
|
|
417
|
+
let endpoint = this.requestOptions.endpoint;
|
|
418
|
+
if (params) {
|
|
419
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
420
|
+
endpoint = endpoint.replace(new RegExp(`:${key}`, "g"), String(value));
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
if (queryParams) {
|
|
424
|
+
endpoint += this.client.stringifyQueryParams(queryParams);
|
|
425
|
+
}
|
|
426
|
+
return endpoint;
|
|
427
|
+
};
|
|
428
|
+
this.abort = () => {
|
|
429
|
+
const { requestManager } = this.client;
|
|
430
|
+
requestManager.abortByKey(this.abortKey);
|
|
431
|
+
return this.clone();
|
|
432
|
+
};
|
|
433
|
+
this.exec = (options) => __async(this, null, function* () {
|
|
434
|
+
const { adapter: adapter4, requestManager } = this.client;
|
|
435
|
+
const request = this.clone(options);
|
|
436
|
+
const requestId = getUniqueRequestId(this.queueKey);
|
|
437
|
+
requestManager.addAbortController(this.abortKey, requestId);
|
|
438
|
+
const response = yield adapter4(request, requestId);
|
|
439
|
+
requestManager.removeAbortController(this.abortKey, requestId);
|
|
440
|
+
if (request.responseMapper) {
|
|
441
|
+
return request.responseMapper(response);
|
|
442
|
+
}
|
|
443
|
+
return response;
|
|
444
|
+
});
|
|
445
|
+
this.send = (options) => __async(this, null, function* () {
|
|
446
|
+
const _a = options || {}, { dispatcherType } = _a, rest = __objRest(_a, ["dispatcherType"]);
|
|
447
|
+
const request = this.clone(rest);
|
|
448
|
+
return sendRequest(request, options);
|
|
449
|
+
});
|
|
450
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
|
|
451
|
+
const {
|
|
452
|
+
endpoint,
|
|
453
|
+
headers,
|
|
454
|
+
auth = true,
|
|
455
|
+
method = client.defaultMethod,
|
|
456
|
+
options,
|
|
457
|
+
cancelable = false,
|
|
458
|
+
retry = 0,
|
|
459
|
+
retryTime = 500,
|
|
460
|
+
garbageCollection = 6e4 /* minute */ * 5,
|
|
461
|
+
cache = true,
|
|
462
|
+
cacheTime = 6e4 /* minute */ * 5,
|
|
463
|
+
queued = false,
|
|
464
|
+
offline = true,
|
|
465
|
+
abortKey,
|
|
466
|
+
cacheKey,
|
|
467
|
+
queueKey,
|
|
468
|
+
effectKey,
|
|
469
|
+
deduplicate = false,
|
|
470
|
+
deduplicateTime = 10
|
|
471
|
+
} = __spreadValues(__spreadValues({}, (_b = (_a = this.client).requestDefaultOptions) == null ? void 0 : _b.call(_a, requestOptions)), requestOptions);
|
|
472
|
+
this.endpoint = (_c = requestJSON == null ? void 0 : requestJSON.endpoint) != null ? _c : endpoint;
|
|
473
|
+
this.headers = (_d = requestJSON == null ? void 0 : requestJSON.headers) != null ? _d : headers;
|
|
474
|
+
this.auth = (_e = requestJSON == null ? void 0 : requestJSON.auth) != null ? _e : auth;
|
|
475
|
+
this.method = method;
|
|
476
|
+
this.params = requestJSON == null ? void 0 : requestJSON.params;
|
|
477
|
+
this.data = requestJSON == null ? void 0 : requestJSON.data;
|
|
478
|
+
this.queryParams = requestJSON == null ? void 0 : requestJSON.queryParams;
|
|
479
|
+
this.options = (_f = requestJSON == null ? void 0 : requestJSON.options) != null ? _f : options;
|
|
480
|
+
this.cancelable = (_g = requestJSON == null ? void 0 : requestJSON.cancelable) != null ? _g : cancelable;
|
|
481
|
+
this.retry = (_h = requestJSON == null ? void 0 : requestJSON.retry) != null ? _h : retry;
|
|
482
|
+
this.retryTime = (_i = requestJSON == null ? void 0 : requestJSON.retryTime) != null ? _i : retryTime;
|
|
483
|
+
this.garbageCollection = (_j = requestJSON == null ? void 0 : requestJSON.garbageCollection) != null ? _j : garbageCollection;
|
|
484
|
+
this.cache = (_k = requestJSON == null ? void 0 : requestJSON.cache) != null ? _k : cache;
|
|
485
|
+
this.cacheTime = (_l = requestJSON == null ? void 0 : requestJSON.cacheTime) != null ? _l : cacheTime;
|
|
486
|
+
this.queued = (_m = requestJSON == null ? void 0 : requestJSON.queued) != null ? _m : queued;
|
|
487
|
+
this.offline = (_n = requestJSON == null ? void 0 : requestJSON.offline) != null ? _n : offline;
|
|
488
|
+
this.abortKey = (_p = (_o = requestJSON == null ? void 0 : requestJSON.abortKey) != null ? _o : abortKey) != null ? _p : this.client.abortKeyMapper(this);
|
|
489
|
+
this.cacheKey = (_r = (_q = requestJSON == null ? void 0 : requestJSON.cacheKey) != null ? _q : cacheKey) != null ? _r : this.client.cacheKeyMapper(this);
|
|
490
|
+
this.queueKey = (_t = (_s = requestJSON == null ? void 0 : requestJSON.queueKey) != null ? _s : queueKey) != null ? _t : this.client.queueKeyMapper(this);
|
|
491
|
+
this.effectKey = (_v = (_u = requestJSON == null ? void 0 : requestJSON.effectKey) != null ? _u : effectKey) != null ? _v : this.client.effectKeyMapper(this);
|
|
492
|
+
this.used = (_w = requestJSON == null ? void 0 : requestJSON.used) != null ? _w : false;
|
|
493
|
+
this.deduplicate = (_x = requestJSON == null ? void 0 : requestJSON.deduplicate) != null ? _x : deduplicate;
|
|
494
|
+
this.deduplicateTime = (_y = requestJSON == null ? void 0 : requestJSON.deduplicateTime) != null ? _y : deduplicateTime;
|
|
495
|
+
this.updatedAbortKey = (_z = requestJSON == null ? void 0 : requestJSON.updatedAbortKey) != null ? _z : false;
|
|
496
|
+
this.updatedCacheKey = (_A = requestJSON == null ? void 0 : requestJSON.updatedCacheKey) != null ? _A : false;
|
|
497
|
+
this.updatedQueueKey = (_B = requestJSON == null ? void 0 : requestJSON.updatedQueueKey) != null ? _B : false;
|
|
498
|
+
this.updatedEffectKey = (_C = requestJSON == null ? void 0 : requestJSON.updatedEffectKey) != null ? _C : false;
|
|
499
|
+
}
|
|
500
|
+
toJSON() {
|
|
501
|
+
return {
|
|
502
|
+
requestOptions: this.requestOptions,
|
|
503
|
+
endpoint: this.endpoint,
|
|
504
|
+
headers: this.headers,
|
|
505
|
+
auth: this.auth,
|
|
506
|
+
method: this.method,
|
|
507
|
+
params: this.params,
|
|
508
|
+
data: this.data,
|
|
509
|
+
queryParams: this.queryParams,
|
|
510
|
+
options: this.options,
|
|
511
|
+
cancelable: this.cancelable,
|
|
512
|
+
retry: this.retry,
|
|
513
|
+
retryTime: this.retryTime,
|
|
514
|
+
garbageCollection: this.garbageCollection,
|
|
515
|
+
cache: this.cache,
|
|
516
|
+
cacheTime: this.cacheTime,
|
|
517
|
+
queued: this.queued,
|
|
518
|
+
offline: this.offline,
|
|
519
|
+
abortKey: this.abortKey,
|
|
520
|
+
cacheKey: this.cacheKey,
|
|
521
|
+
queueKey: this.queueKey,
|
|
522
|
+
effectKey: this.effectKey,
|
|
523
|
+
used: this.used,
|
|
524
|
+
disableResponseInterceptors: this.requestOptions.disableResponseInterceptors,
|
|
525
|
+
disableRequestInterceptors: this.requestOptions.disableRequestInterceptors,
|
|
526
|
+
updatedAbortKey: this.updatedAbortKey,
|
|
527
|
+
updatedCacheKey: this.updatedCacheKey,
|
|
528
|
+
updatedQueueKey: this.updatedQueueKey,
|
|
529
|
+
updatedEffectKey: this.updatedEffectKey,
|
|
530
|
+
deduplicate: this.deduplicate,
|
|
531
|
+
deduplicateTime: this.deduplicateTime
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
clone(options) {
|
|
535
|
+
const json = this.toJSON();
|
|
536
|
+
const requestJSON = __spreadProps(__spreadValues(__spreadValues({}, json), options), {
|
|
537
|
+
abortKey: this.updatedAbortKey ? (options == null ? void 0 : options.abortKey) || this.abortKey : void 0,
|
|
538
|
+
cacheKey: this.updatedCacheKey ? (options == null ? void 0 : options.cacheKey) || this.cacheKey : void 0,
|
|
539
|
+
queueKey: this.updatedQueueKey ? (options == null ? void 0 : options.queueKey) || this.queueKey : void 0,
|
|
540
|
+
endpoint: this.paramsMapper((options == null ? void 0 : options.params) || this.params, (options == null ? void 0 : options.queryParams) || this.queryParams),
|
|
541
|
+
queryParams: (options == null ? void 0 : options.queryParams) || this.queryParams,
|
|
542
|
+
data: (options == null ? void 0 : options.data) || this.data
|
|
543
|
+
});
|
|
544
|
+
const cloned = new Request(
|
|
545
|
+
this.client,
|
|
546
|
+
this.requestOptions,
|
|
547
|
+
requestJSON
|
|
548
|
+
);
|
|
549
|
+
cloned.dataMapper = this.dataMapper;
|
|
550
|
+
cloned.responseMapper = this.responseMapper;
|
|
551
|
+
cloned.requestMapper = this.requestMapper;
|
|
552
|
+
cloned.mockData = this.mockData;
|
|
553
|
+
cloned.mock = this.mock;
|
|
554
|
+
return cloned;
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/dispatcher/dispatcher.constants.ts
|
|
559
|
+
var DispatcherRequestType = /* @__PURE__ */ ((DispatcherRequestType2) => {
|
|
560
|
+
DispatcherRequestType2["oneByOne"] = "one-by-one";
|
|
561
|
+
DispatcherRequestType2["allAtOnce"] = "all-at-once";
|
|
562
|
+
DispatcherRequestType2["previousCanceled"] = "previous-canceled";
|
|
563
|
+
DispatcherRequestType2["deduplicated"] = "deduplicated";
|
|
564
|
+
return DispatcherRequestType2;
|
|
565
|
+
})(DispatcherRequestType || {});
|
|
566
|
+
|
|
567
|
+
// src/dispatcher/dispatcher.events.ts
|
|
568
|
+
var getDispatcherEvents = (emitter) => ({
|
|
569
|
+
setDrained: (queueKey, values) => {
|
|
570
|
+
emitter.emit(getDispatcherDrainedEventKey(queueKey), values);
|
|
571
|
+
},
|
|
572
|
+
setQueueStatus: (queueKey, values) => {
|
|
573
|
+
emitter.emit(getDispatcherStatusEventKey(queueKey), values);
|
|
574
|
+
},
|
|
575
|
+
setQueueChanged: (queueKey, values) => {
|
|
576
|
+
emitter.emit(getDispatcherChangeEventKey(queueKey), values);
|
|
577
|
+
},
|
|
578
|
+
onDrained: (queueKey, callback) => {
|
|
579
|
+
emitter.on(getDispatcherDrainedEventKey(queueKey), callback);
|
|
580
|
+
return () => emitter.removeListener(getDispatcherDrainedEventKey(queueKey), callback);
|
|
581
|
+
},
|
|
582
|
+
onQueueStatus: (queueKey, callback) => {
|
|
583
|
+
emitter.on(getDispatcherStatusEventKey(queueKey), callback);
|
|
584
|
+
return () => emitter.removeListener(getDispatcherStatusEventKey(queueKey), callback);
|
|
585
|
+
},
|
|
586
|
+
onQueueChange: (queueKey, callback) => {
|
|
587
|
+
emitter.on(getDispatcherChangeEventKey(queueKey), callback);
|
|
588
|
+
return () => emitter.removeListener(getDispatcherChangeEventKey(queueKey), callback);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
// src/dispatcher/dispatcher.ts
|
|
593
|
+
import EventEmitter from "events";
|
|
594
|
+
var Dispatcher = class {
|
|
595
|
+
constructor(client, options) {
|
|
596
|
+
this.client = client;
|
|
597
|
+
this.options = options;
|
|
598
|
+
this.emitter = new EventEmitter();
|
|
599
|
+
this.events = getDispatcherEvents(this.emitter);
|
|
600
|
+
this.storage = /* @__PURE__ */ new Map();
|
|
601
|
+
this.requestCount = /* @__PURE__ */ new Map();
|
|
602
|
+
this.runningRequests = /* @__PURE__ */ new Map();
|
|
603
|
+
this.start = (queueKey) => {
|
|
604
|
+
const queue = this.getQueue(queueKey);
|
|
605
|
+
queue.stopped = false;
|
|
606
|
+
this.setQueue(queueKey, queue);
|
|
607
|
+
this.flushQueue(queueKey);
|
|
608
|
+
this.events.setQueueStatus(queueKey, queue);
|
|
609
|
+
};
|
|
610
|
+
this.pause = (queueKey) => {
|
|
611
|
+
const queue = this.getQueue(queueKey);
|
|
612
|
+
queue.stopped = true;
|
|
613
|
+
this.setQueue(queueKey, queue);
|
|
614
|
+
this.events.setQueueStatus(queueKey, queue);
|
|
615
|
+
};
|
|
616
|
+
this.stop = (queueKey) => {
|
|
617
|
+
const queue = this.getQueue(queueKey);
|
|
618
|
+
queue.stopped = true;
|
|
619
|
+
this.setQueue(queueKey, queue);
|
|
620
|
+
this.cancelRunningRequests(queueKey);
|
|
621
|
+
this.events.setQueueStatus(queueKey, queue);
|
|
622
|
+
};
|
|
623
|
+
this.getQueuesKeys = () => {
|
|
624
|
+
return Array.from(this.storage.keys());
|
|
625
|
+
};
|
|
626
|
+
this.getQueue = (queueKey) => {
|
|
627
|
+
const initialQueueState = { requests: [], stopped: false };
|
|
628
|
+
const storedEntity = this.storage.get(queueKey);
|
|
629
|
+
return storedEntity || initialQueueState;
|
|
630
|
+
};
|
|
631
|
+
this.getRequest = (queueKey, requestId) => {
|
|
632
|
+
const initialQueueState = { requests: [], stopped: false };
|
|
633
|
+
const storedEntity = this.storage.get(queueKey) || initialQueueState;
|
|
634
|
+
return storedEntity.requests.find((req) => req.requestId === requestId);
|
|
635
|
+
};
|
|
636
|
+
this.getIsActiveQueue = (queueKey) => {
|
|
637
|
+
const queue = this.getQueue(queueKey);
|
|
638
|
+
const hasAvailableRequests = queue.requests.some((req) => !req.stopped);
|
|
639
|
+
const isRunningQueue = !queue.stopped;
|
|
640
|
+
return hasAvailableRequests && isRunningQueue;
|
|
641
|
+
};
|
|
642
|
+
this.addQueueElement = (queueKey, dispatcherDump) => {
|
|
643
|
+
const queue = this.getQueue(queueKey);
|
|
644
|
+
queue.requests.push(dispatcherDump);
|
|
645
|
+
this.setQueue(queueKey, queue);
|
|
646
|
+
};
|
|
647
|
+
this.setQueue = (queueKey, queue) => {
|
|
648
|
+
var _a, _b;
|
|
649
|
+
this.storage.set(queueKey, queue);
|
|
650
|
+
(_b = (_a = this.options) == null ? void 0 : _a.onUpdateStorage) == null ? void 0 : _b.call(_a, queueKey, queue);
|
|
651
|
+
this.events.setQueueChanged(queueKey, queue);
|
|
652
|
+
return queue;
|
|
653
|
+
};
|
|
654
|
+
this.clearQueue = (queueKey) => {
|
|
655
|
+
var _a, _b;
|
|
656
|
+
const queue = this.getQueue(queueKey);
|
|
657
|
+
const newQueue = { requests: [], stopped: queue.stopped };
|
|
658
|
+
this.storage.set(queueKey, newQueue);
|
|
659
|
+
(_b = (_a = this.options) == null ? void 0 : _a.onDeleteFromStorage) == null ? void 0 : _b.call(_a, queueKey, newQueue);
|
|
660
|
+
this.events.setQueueChanged(queueKey, newQueue);
|
|
661
|
+
return newQueue;
|
|
662
|
+
};
|
|
663
|
+
this.flushQueue = (queueKey) => __async(this, null, function* () {
|
|
664
|
+
const queue = this.getQueue(queueKey);
|
|
665
|
+
const runningRequests = this.getRunningRequests(queueKey);
|
|
666
|
+
const queueElement = queue.requests.find((request) => !request.stopped);
|
|
667
|
+
const isStopped = queue && queue.stopped;
|
|
668
|
+
const isOffline = !this.client.appManager.isOnline;
|
|
669
|
+
const isConcurrent = !(queueElement == null ? void 0 : queueElement.request.queued);
|
|
670
|
+
const isInactive = !runningRequests.length;
|
|
671
|
+
const isEmpty = !queueElement;
|
|
672
|
+
if (isStopped || isOffline || isEmpty) {
|
|
673
|
+
this.logger.debug("Skipping queue trigger", { isStopped, isOffline, isEmpty });
|
|
674
|
+
} else if (isConcurrent) {
|
|
675
|
+
queue.requests.forEach((element) => {
|
|
676
|
+
if (!this.hasRunningRequest(queueKey, element.requestId)) {
|
|
677
|
+
this.performRequest(element);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
} else if (isInactive) {
|
|
681
|
+
yield this.performRequest(queueElement);
|
|
682
|
+
this.flushQueue(queueKey);
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
this.flush = () => __async(this, null, function* () {
|
|
686
|
+
const keys = this.getQueuesKeys();
|
|
687
|
+
for (const key of keys) {
|
|
688
|
+
const storageElement = this.getQueue(key);
|
|
689
|
+
if (storageElement) {
|
|
690
|
+
this.flushQueue(key);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
this.clear = () => {
|
|
695
|
+
var _a, _b;
|
|
696
|
+
const keys = this.getQueuesKeys();
|
|
697
|
+
keys.forEach((queueKey) => this.cancelRunningRequests(queueKey));
|
|
698
|
+
this.runningRequests.clear();
|
|
699
|
+
this.storage.clear();
|
|
700
|
+
(_b = (_a = this.options) == null ? void 0 : _a.onClearStorage) == null ? void 0 : _b.call(_a, this);
|
|
701
|
+
};
|
|
702
|
+
this.startRequest = (queueKey, requestId) => {
|
|
703
|
+
const queue = this.getQueue(queueKey);
|
|
704
|
+
const request = queue.requests.find((element) => element.requestId === requestId);
|
|
705
|
+
if (request) {
|
|
706
|
+
request.stopped = false;
|
|
707
|
+
this.setQueue(queueKey, queue);
|
|
708
|
+
this.flushQueue(queueKey);
|
|
709
|
+
this.events.setQueueStatus(queueKey, queue);
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
this.stopRequest = (queueKey, requestId) => {
|
|
713
|
+
const queue = this.getQueue(queueKey);
|
|
714
|
+
const request = queue.requests.find((element) => element.requestId === requestId);
|
|
715
|
+
if (request) {
|
|
716
|
+
request.stopped = true;
|
|
717
|
+
this.setQueue(queueKey, queue);
|
|
718
|
+
this.cancelRunningRequest(queueKey, requestId);
|
|
719
|
+
this.events.setQueueStatus(queueKey, queue);
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
this.getAllRunningRequest = () => {
|
|
723
|
+
return Array.from(this.runningRequests.values()).flat();
|
|
724
|
+
};
|
|
725
|
+
this.getRunningRequests = (queueKey) => {
|
|
726
|
+
return this.runningRequests.get(queueKey) || [];
|
|
727
|
+
};
|
|
728
|
+
this.getRunningRequest = (queueKey, requestId) => {
|
|
729
|
+
const runningRequests = this.getRunningRequests(queueKey);
|
|
730
|
+
return runningRequests.find((req) => req.requestId === requestId);
|
|
731
|
+
};
|
|
732
|
+
this.addRunningRequest = (queueKey, requestId, request) => {
|
|
733
|
+
const runningRequests = this.getRunningRequests(queueKey);
|
|
734
|
+
runningRequests.push({ requestId, request, timestamp: Date.now() });
|
|
735
|
+
this.runningRequests.set(queueKey, runningRequests);
|
|
736
|
+
};
|
|
737
|
+
this.hasRunningRequests = (queueKey) => {
|
|
738
|
+
return !!this.getRunningRequests(queueKey).length;
|
|
739
|
+
};
|
|
740
|
+
this.hasRunningRequest = (queueKey, requestId) => {
|
|
741
|
+
const runningRequests = this.getRunningRequests(queueKey);
|
|
742
|
+
return !!runningRequests.find((req) => req.requestId === requestId);
|
|
743
|
+
};
|
|
744
|
+
this.cancelRunningRequests = (queueKey) => {
|
|
745
|
+
var _a;
|
|
746
|
+
(_a = this.runningRequests.get(queueKey)) == null ? void 0 : _a.forEach((request) => {
|
|
747
|
+
this.client.requestManager.abortByRequestId(request.request.abortKey, request.requestId);
|
|
748
|
+
});
|
|
749
|
+
this.deleteRunningRequests(queueKey);
|
|
750
|
+
};
|
|
751
|
+
this.cancelRunningRequest = (queueKey, requestId) => {
|
|
752
|
+
const requests = this.getRunningRequests(queueKey).filter((request) => {
|
|
753
|
+
if (request.requestId === requestId) {
|
|
754
|
+
this.client.requestManager.abortByRequestId(request.request.abortKey, request.requestId);
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
return true;
|
|
758
|
+
});
|
|
759
|
+
this.runningRequests.set(queueKey, requests);
|
|
760
|
+
};
|
|
761
|
+
this.deleteRunningRequests = (queueKey) => {
|
|
762
|
+
this.runningRequests.set(queueKey, []);
|
|
763
|
+
};
|
|
764
|
+
this.deleteRunningRequest = (queueKey, requestId) => {
|
|
765
|
+
const runningRequests = this.getRunningRequests(queueKey);
|
|
766
|
+
this.runningRequests.set(
|
|
767
|
+
queueKey,
|
|
768
|
+
runningRequests.filter((req) => req.requestId !== requestId)
|
|
769
|
+
);
|
|
770
|
+
};
|
|
771
|
+
this.getQueueRequestCount = (queueKey) => {
|
|
772
|
+
return this.requestCount.get(queueKey) || 0;
|
|
773
|
+
};
|
|
774
|
+
this.incrementQueueRequestCount = (queueKey) => {
|
|
775
|
+
const count = this.requestCount.get(queueKey) || 0;
|
|
776
|
+
this.requestCount.set(queueKey, count + 1);
|
|
777
|
+
};
|
|
778
|
+
this.createStorageElement = (request) => {
|
|
779
|
+
const requestId = getUniqueRequestId(request.queueKey);
|
|
780
|
+
const storageElement = {
|
|
781
|
+
requestId,
|
|
782
|
+
timestamp: +new Date(),
|
|
783
|
+
request,
|
|
784
|
+
retries: 0,
|
|
785
|
+
stopped: false
|
|
786
|
+
};
|
|
787
|
+
return storageElement;
|
|
788
|
+
};
|
|
789
|
+
this.add = (request) => {
|
|
790
|
+
const { queueKey } = request;
|
|
791
|
+
const storageElement = this.createStorageElement(request);
|
|
792
|
+
const { requestId } = storageElement;
|
|
793
|
+
const queue = this.getQueue(queueKey);
|
|
794
|
+
const [latestRequest] = queue.requests.slice(-1);
|
|
795
|
+
const requestType = getRequestType(request, latestRequest);
|
|
796
|
+
this.logger.debug("Adding request to queue", { requestType, request, requestId });
|
|
797
|
+
switch (requestType) {
|
|
798
|
+
case "one-by-one" /* oneByOne */: {
|
|
799
|
+
this.addQueueElement(queueKey, storageElement);
|
|
800
|
+
this.flushQueue(queueKey);
|
|
801
|
+
return requestId;
|
|
802
|
+
}
|
|
803
|
+
case "previous-canceled" /* previousCanceled */: {
|
|
804
|
+
this.cancelRunningRequests(queueKey);
|
|
805
|
+
this.clearQueue(queueKey);
|
|
806
|
+
this.addQueueElement(queueKey, storageElement);
|
|
807
|
+
this.flushQueue(queueKey);
|
|
808
|
+
return requestId;
|
|
809
|
+
}
|
|
810
|
+
case "deduplicated" /* deduplicated */: {
|
|
811
|
+
return queue.requests[0].requestId;
|
|
812
|
+
}
|
|
813
|
+
default: {
|
|
814
|
+
this.addQueueElement(queueKey, storageElement);
|
|
815
|
+
this.flushQueue(queueKey);
|
|
816
|
+
return requestId;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
this.delete = (queueKey, requestId, abortKey) => {
|
|
821
|
+
var _a, _b;
|
|
822
|
+
this.logger.debug("Deleting request", { queueKey, requestId, abortKey });
|
|
823
|
+
const queue = this.getQueue(queueKey);
|
|
824
|
+
const queueElement = queue.requests.find((req) => req.requestId === requestId);
|
|
825
|
+
if (!queueElement)
|
|
826
|
+
return;
|
|
827
|
+
queue.requests = queue.requests.filter((req) => req.requestId !== requestId);
|
|
828
|
+
this.storage.set(queueKey, queue);
|
|
829
|
+
if (this.hasRunningRequest(queueKey, requestId)) {
|
|
830
|
+
this.deleteRunningRequest(queueKey, requestId);
|
|
831
|
+
this.client.requestManager.abortByRequestId(abortKey, requestId);
|
|
832
|
+
}
|
|
833
|
+
(_b = (_a = this.options) == null ? void 0 : _a.onDeleteFromStorage) == null ? void 0 : _b.call(_a, queueKey, queue);
|
|
834
|
+
this.events.setQueueChanged(queueKey, queue);
|
|
835
|
+
this.client.requestManager.events.emitRemove(queueKey, requestId, { requestId, request: queueElement.request });
|
|
836
|
+
if (!queue.requests.length) {
|
|
837
|
+
this.events.setDrained(queueKey, queue);
|
|
838
|
+
}
|
|
839
|
+
return queue;
|
|
840
|
+
};
|
|
841
|
+
this.performRequest = (storageElement) => __async(this, null, function* () {
|
|
842
|
+
var _a;
|
|
843
|
+
const { request, requestId } = storageElement;
|
|
844
|
+
this.logger.info("Performing request", { request, requestId });
|
|
845
|
+
const { retry, retryTime, queueKey, cacheKey, abortKey, offline } = request;
|
|
846
|
+
const { adapter: adapter4, requestManager, cache, appManager } = this.client;
|
|
847
|
+
const canRetry = canRetryRequest(storageElement.retries, retry);
|
|
848
|
+
const isOffline = !appManager.isOnline && offline;
|
|
849
|
+
const isAlreadyRunning = this.hasRunningRequest(queueKey, requestId);
|
|
850
|
+
const isStopped = storageElement.stopped;
|
|
851
|
+
if (isOffline || isAlreadyRunning || isStopped) {
|
|
852
|
+
return this.logger.warning("Unable to perform request", { isOffline, isAlreadyRunning, isStopped });
|
|
853
|
+
}
|
|
854
|
+
this.addRunningRequest(queueKey, requestId, request);
|
|
855
|
+
requestManager.events.emitLoading(queueKey, requestId, {
|
|
856
|
+
queueKey,
|
|
857
|
+
requestId,
|
|
858
|
+
loading: true,
|
|
859
|
+
isRetry: !!storageElement.retries,
|
|
860
|
+
isOffline
|
|
861
|
+
});
|
|
862
|
+
this.incrementQueueRequestCount(queueKey);
|
|
863
|
+
requestManager.addAbortController(abortKey, requestId);
|
|
864
|
+
const response = yield adapter4(request, requestId);
|
|
865
|
+
requestManager.removeAbortController(abortKey, requestId);
|
|
866
|
+
const isOfflineResponseStatus = !appManager.isOnline;
|
|
867
|
+
const isCancelMessage = getErrorMessage("abort").message === ((_a = response.error) == null ? void 0 : _a.message);
|
|
868
|
+
const isCanceled = !this.hasRunningRequest(queueKey, requestId) || isCancelMessage;
|
|
869
|
+
this.deleteRunningRequest(queueKey, requestId);
|
|
870
|
+
const requestDetails = {
|
|
871
|
+
isCanceled,
|
|
872
|
+
isOffline: isOfflineResponseStatus,
|
|
873
|
+
retries: storageElement.retries,
|
|
874
|
+
timestamp: +new Date()
|
|
875
|
+
};
|
|
876
|
+
requestManager.events.emitLoading(queueKey, requestId, {
|
|
877
|
+
queueKey,
|
|
878
|
+
requestId,
|
|
879
|
+
loading: false,
|
|
880
|
+
isRetry: !!storageElement.retries,
|
|
881
|
+
isOffline
|
|
882
|
+
});
|
|
883
|
+
requestManager.events.emitResponse(cacheKey, requestId, response, requestDetails);
|
|
884
|
+
cache.set(request, __spreadValues(__spreadValues({}, response), requestDetails));
|
|
885
|
+
this.logger.info("Request finished", { requestId, request, response, requestDetails });
|
|
886
|
+
if (isCanceled) {
|
|
887
|
+
const queue = this.getQueue(queueKey);
|
|
888
|
+
const queueElement = queue.requests.find((req) => req.requestId === requestId);
|
|
889
|
+
if (!queue.stopped && !(queueElement == null ? void 0 : queueElement.stopped)) {
|
|
890
|
+
this.logger.debug("Request paused", { response, requestDetails, request });
|
|
891
|
+
return this.delete(queueKey, requestId, abortKey);
|
|
892
|
+
}
|
|
893
|
+
return this.logger.debug("Request canceled", { response, requestDetails, request });
|
|
894
|
+
}
|
|
895
|
+
if (!response.success && isOfflineResponseStatus) {
|
|
896
|
+
if (!offline) {
|
|
897
|
+
this.logger.warning("Removing non-offline request", { response, requestDetails, request });
|
|
898
|
+
return this.delete(queueKey, requestId, abortKey);
|
|
899
|
+
}
|
|
900
|
+
return this.logger.debug("Awaiting for network restoration", { response, requestDetails, request });
|
|
901
|
+
}
|
|
902
|
+
if (response.success) {
|
|
903
|
+
this.delete(queueKey, requestId, abortKey);
|
|
904
|
+
return this.logger.debug("Successful response, removing request from queue.", {
|
|
905
|
+
response,
|
|
906
|
+
requestDetails,
|
|
907
|
+
request
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
if (!response.success && canRetry) {
|
|
911
|
+
this.logger.debug("Waiting for retry", { response, requestDetails, request });
|
|
912
|
+
setTimeout(() => {
|
|
913
|
+
this.logger.warning("Error response, performing retry");
|
|
914
|
+
this.performRequest(__spreadProps(__spreadValues({}, storageElement), {
|
|
915
|
+
retries: storageElement.retries + 1
|
|
916
|
+
}));
|
|
917
|
+
}, retryTime || 0);
|
|
918
|
+
} else {
|
|
919
|
+
this.logger.error("All retries have been used. Removing request from queue.");
|
|
920
|
+
this.delete(queueKey, requestId, abortKey);
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
var _a, _b, _c;
|
|
924
|
+
this.logger = client.loggerManager.init("Dispatcher");
|
|
925
|
+
if ((_a = this.options) == null ? void 0 : _a.storage) {
|
|
926
|
+
this.storage = this.options.storage;
|
|
927
|
+
}
|
|
928
|
+
this.client.appManager.events.onOnline(() => {
|
|
929
|
+
this.flush();
|
|
930
|
+
});
|
|
931
|
+
(_c = (_b = this.options) == null ? void 0 : _b.onInitialization) == null ? void 0 : _c.call(_b, this);
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
// src/dispatcher/dispatcher.utils.ts
|
|
936
|
+
var getDispatcherDrainedEventKey = (key) => {
|
|
937
|
+
return `${key}-drained-event`;
|
|
938
|
+
};
|
|
939
|
+
var getDispatcherStatusEventKey = (key) => {
|
|
940
|
+
return `${key}-status-event`;
|
|
941
|
+
};
|
|
942
|
+
var getDispatcherChangeEventKey = (key) => {
|
|
943
|
+
return `${key}-change-event`;
|
|
944
|
+
};
|
|
945
|
+
var getIsEqualTimestamp = (currentTimestamp, threshold, queueTimestamp) => {
|
|
946
|
+
if (!queueTimestamp) {
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
return queueTimestamp - currentTimestamp <= threshold;
|
|
950
|
+
};
|
|
951
|
+
var canRetryRequest = (currentRetries, retry) => {
|
|
952
|
+
if (retry && currentRetries < retry) {
|
|
953
|
+
return true;
|
|
954
|
+
}
|
|
955
|
+
return false;
|
|
956
|
+
};
|
|
957
|
+
var getRequestType = (request, latestRequest) => {
|
|
958
|
+
const { queued, cancelable, deduplicate } = request;
|
|
959
|
+
const canDeduplicate = latestRequest ? +new Date() - latestRequest.timestamp <= request.deduplicateTime : false;
|
|
960
|
+
if (queued) {
|
|
961
|
+
return "one-by-one" /* oneByOne */;
|
|
962
|
+
}
|
|
963
|
+
if (cancelable) {
|
|
964
|
+
return "previous-canceled" /* previousCanceled */;
|
|
965
|
+
}
|
|
966
|
+
if (canDeduplicate && deduplicate) {
|
|
967
|
+
return "deduplicated" /* deduplicated */;
|
|
968
|
+
}
|
|
969
|
+
return "all-at-once" /* allAtOnce */;
|
|
970
|
+
};
|
|
971
|
+
|
|
972
|
+
// src/request/request.utils.ts
|
|
973
|
+
var stringifyKey = (value) => {
|
|
974
|
+
try {
|
|
975
|
+
if (typeof value === "string")
|
|
976
|
+
return value;
|
|
977
|
+
if (value === void 0 || value === null)
|
|
978
|
+
return "";
|
|
979
|
+
const data = JSON.stringify(value);
|
|
980
|
+
if (typeof data !== "string")
|
|
981
|
+
throw new Error();
|
|
982
|
+
return data;
|
|
983
|
+
} catch (_) {
|
|
984
|
+
return "";
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
var getProgressValue = ({ loaded, total }) => {
|
|
988
|
+
if (!loaded || !total)
|
|
989
|
+
return 0;
|
|
990
|
+
return Number((loaded * 100 / total).toFixed(0));
|
|
991
|
+
};
|
|
992
|
+
var getRequestEta = (startDate, progressDate, { total, loaded }) => {
|
|
993
|
+
const timeElapsed = +progressDate - +startDate || 1;
|
|
994
|
+
const uploadSpeed = loaded / timeElapsed;
|
|
995
|
+
const totalValue = Math.max(total, loaded);
|
|
996
|
+
const sizeLeft = totalValue - loaded;
|
|
997
|
+
const estimatedTimeValue = uploadSpeed ? sizeLeft / uploadSpeed : null;
|
|
998
|
+
const timeLeft = totalValue === loaded ? 0 : estimatedTimeValue;
|
|
999
|
+
return { timeLeft, sizeLeft };
|
|
1000
|
+
};
|
|
1001
|
+
var getProgressData = (requestStartTime, progressDate, progressEvent) => {
|
|
1002
|
+
const { total, loaded } = progressEvent;
|
|
1003
|
+
if (Number.isNaN(total) || Number.isNaN(loaded)) {
|
|
1004
|
+
return {
|
|
1005
|
+
progress: 0,
|
|
1006
|
+
timeLeft: 0,
|
|
1007
|
+
sizeLeft: 0,
|
|
1008
|
+
total: 0,
|
|
1009
|
+
loaded: 0,
|
|
1010
|
+
startTimestamp: +requestStartTime
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
const { timeLeft, sizeLeft } = getRequestEta(requestStartTime, progressDate, progressEvent);
|
|
1014
|
+
return {
|
|
1015
|
+
progress: getProgressValue(progressEvent),
|
|
1016
|
+
timeLeft,
|
|
1017
|
+
sizeLeft,
|
|
1018
|
+
total,
|
|
1019
|
+
loaded,
|
|
1020
|
+
startTimestamp: +requestStartTime
|
|
1021
|
+
};
|
|
1022
|
+
};
|
|
1023
|
+
var getSimpleKey = (request) => {
|
|
1024
|
+
return `${request.method}_${request.requestOptions.endpoint}_${request.cancelable}`;
|
|
1025
|
+
};
|
|
1026
|
+
var getRequestKey = (request, useInitialValues) => {
|
|
1027
|
+
const methodKey = stringifyKey(request.method);
|
|
1028
|
+
const endpointKey = useInitialValues ? request.requestOptions.endpoint : stringifyKey(request.endpoint);
|
|
1029
|
+
return `${methodKey}_${endpointKey}`;
|
|
1030
|
+
};
|
|
1031
|
+
var getRequestDispatcher = (request, dispatcherType = "auto") => {
|
|
1032
|
+
const { fetchDispatcher, submitDispatcher } = request.client;
|
|
1033
|
+
const isGet = request.method === "GET" /* get */;
|
|
1034
|
+
const isFetchDispatcher = dispatcherType === "auto" && isGet || dispatcherType === "fetch";
|
|
1035
|
+
const dispatcher = isFetchDispatcher ? fetchDispatcher : submitDispatcher;
|
|
1036
|
+
return [dispatcher, isFetchDispatcher];
|
|
1037
|
+
};
|
|
1038
|
+
var sendRequest = (request, options) => {
|
|
1039
|
+
const { requestManager } = request.client;
|
|
1040
|
+
const [dispatcher] = getRequestDispatcher(request, options == null ? void 0 : options.dispatcherType);
|
|
1041
|
+
return new Promise((resolve) => {
|
|
1042
|
+
var _a;
|
|
1043
|
+
let isResolved = false;
|
|
1044
|
+
const requestId = dispatcher.add(request);
|
|
1045
|
+
(_a = options == null ? void 0 : options.onSettle) == null ? void 0 : _a.call(options, requestId, request);
|
|
1046
|
+
const unmountRequestStart = requestManager.events.onRequestStartById(
|
|
1047
|
+
requestId,
|
|
1048
|
+
(...props) => {
|
|
1049
|
+
var _a2;
|
|
1050
|
+
return (_a2 = options == null ? void 0 : options.onRequestStart) == null ? void 0 : _a2.call(options, ...props);
|
|
1051
|
+
}
|
|
1052
|
+
);
|
|
1053
|
+
const unmountResponseStart = requestManager.events.onResponseStartById(
|
|
1054
|
+
requestId,
|
|
1055
|
+
(...props) => {
|
|
1056
|
+
var _a2;
|
|
1057
|
+
return (_a2 = options == null ? void 0 : options.onResponseStart) == null ? void 0 : _a2.call(options, ...props);
|
|
1058
|
+
}
|
|
1059
|
+
);
|
|
1060
|
+
const unmountUpload = requestManager.events.onUploadProgressById(
|
|
1061
|
+
requestId,
|
|
1062
|
+
(...props) => {
|
|
1063
|
+
var _a2;
|
|
1064
|
+
return (_a2 = options == null ? void 0 : options.onUploadProgress) == null ? void 0 : _a2.call(options, ...props);
|
|
1065
|
+
}
|
|
1066
|
+
);
|
|
1067
|
+
const unmountDownload = requestManager.events.onDownloadProgressById(
|
|
1068
|
+
requestId,
|
|
1069
|
+
(...props) => {
|
|
1070
|
+
var _a2;
|
|
1071
|
+
return (_a2 = options == null ? void 0 : options.onDownloadProgress) == null ? void 0 : _a2.call(options, ...props);
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
1074
|
+
const unmountResponse = requestManager.events.onResponseById(requestId, (response, details) => {
|
|
1075
|
+
var _a2;
|
|
1076
|
+
isResolved = true;
|
|
1077
|
+
const mapping = (_a2 = request.responseMapper) == null ? void 0 : _a2.call(request, response);
|
|
1078
|
+
const isOfflineStatus = request.offline && details.isOffline;
|
|
1079
|
+
const willRetry = canRetryRequest(details.retries, request.retry);
|
|
1080
|
+
const handleResponse = (success, data) => {
|
|
1081
|
+
var _a3;
|
|
1082
|
+
if (!success && isOfflineStatus)
|
|
1083
|
+
return;
|
|
1084
|
+
if (!success && willRetry)
|
|
1085
|
+
return;
|
|
1086
|
+
(_a3 = options == null ? void 0 : options.onResponse) == null ? void 0 : _a3.call(options, data, details);
|
|
1087
|
+
resolve(data);
|
|
1088
|
+
umountAll();
|
|
1089
|
+
};
|
|
1090
|
+
if (mapping instanceof Promise) {
|
|
1091
|
+
(() => __async(void 0, null, function* () {
|
|
1092
|
+
const responseData = yield mapping;
|
|
1093
|
+
const { success } = responseData;
|
|
1094
|
+
handleResponse(success, responseData);
|
|
1095
|
+
}))();
|
|
1096
|
+
} else {
|
|
1097
|
+
const data = mapping || response;
|
|
1098
|
+
const { success } = data;
|
|
1099
|
+
handleResponse(success, data);
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
const unmountRemoveQueueElement = requestManager.events.onRemoveById(requestId, (...props) => {
|
|
1103
|
+
var _a2;
|
|
1104
|
+
if (!isResolved) {
|
|
1105
|
+
(_a2 = options == null ? void 0 : options.onRemove) == null ? void 0 : _a2.call(options, ...props);
|
|
1106
|
+
resolve({
|
|
1107
|
+
data: null,
|
|
1108
|
+
status: null,
|
|
1109
|
+
success: null,
|
|
1110
|
+
error: getErrorMessage("deleted"),
|
|
1111
|
+
extra: request.client.defaultExtra
|
|
1112
|
+
});
|
|
1113
|
+
umountAll();
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
function umountAll() {
|
|
1117
|
+
unmountRequestStart();
|
|
1118
|
+
unmountResponseStart();
|
|
1119
|
+
unmountUpload();
|
|
1120
|
+
unmountDownload();
|
|
1121
|
+
unmountResponse();
|
|
1122
|
+
unmountRemoveQueueElement();
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
// src/mocker/mocker.ts
|
|
1128
|
+
var mocker = (_0, _1) => __async(void 0, [_0, _1], function* (request, {
|
|
1129
|
+
onError,
|
|
1130
|
+
onResponseEnd,
|
|
1131
|
+
onTimeoutError,
|
|
1132
|
+
onRequestEnd,
|
|
1133
|
+
createAbortListener,
|
|
1134
|
+
onResponseProgress,
|
|
1135
|
+
onRequestProgress,
|
|
1136
|
+
onResponseStart,
|
|
1137
|
+
onBeforeRequest,
|
|
1138
|
+
onRequestStart,
|
|
1139
|
+
onSuccess
|
|
1140
|
+
}) {
|
|
1141
|
+
var _a, _b;
|
|
1142
|
+
const timeout = ((_a = request.requestOptions.options) == null ? void 0 : _a.timeout) || ((_b = request.options) == null ? void 0 : _b.timeout);
|
|
1143
|
+
const mock = request.mock.next();
|
|
1144
|
+
const result = mock.value instanceof Function ? yield mock.value(request) : mock.value;
|
|
1145
|
+
return new Promise((resolve) => {
|
|
1146
|
+
const { data, status = 200, success = true, extra, config } = result;
|
|
1147
|
+
const { requestTime = 20, responseTime = 20, totalUploaded = 1, totalDownloaded = 1 } = config || {};
|
|
1148
|
+
createAbortListener(0, {}, () => {
|
|
1149
|
+
}, resolve);
|
|
1150
|
+
onBeforeRequest();
|
|
1151
|
+
onRequestStart();
|
|
1152
|
+
const progress = (totalTime, totalSize, progressFunction) => new Promise((resolveProgress) => {
|
|
1153
|
+
const interval = 20;
|
|
1154
|
+
const dataStart = +new Date();
|
|
1155
|
+
const chunkSize = Math.floor(totalSize / Math.floor(totalTime / Math.min(totalTime, interval)));
|
|
1156
|
+
let currentlyLoaded = 0;
|
|
1157
|
+
const timer = setInterval(function handleProgressInterval() {
|
|
1158
|
+
const currentTime = Math.min(totalTime, +new Date() - dataStart);
|
|
1159
|
+
currentlyLoaded += currentlyLoaded + chunkSize >= totalSize ? totalSize - currentlyLoaded : chunkSize;
|
|
1160
|
+
if (currentTime >= totalTime) {
|
|
1161
|
+
resolveProgress(true);
|
|
1162
|
+
clearInterval(timer);
|
|
1163
|
+
} else {
|
|
1164
|
+
progressFunction({
|
|
1165
|
+
total: totalSize,
|
|
1166
|
+
loaded: currentlyLoaded
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
}, interval);
|
|
1170
|
+
});
|
|
1171
|
+
const getResponse = () => __async(void 0, null, function* () {
|
|
1172
|
+
yield progress(requestTime, totalUploaded, onRequestProgress);
|
|
1173
|
+
onRequestEnd();
|
|
1174
|
+
onResponseStart();
|
|
1175
|
+
yield progress(responseTime, totalDownloaded, onResponseProgress);
|
|
1176
|
+
if (success) {
|
|
1177
|
+
onSuccess(data, status, extra || {}, resolve);
|
|
1178
|
+
} else {
|
|
1179
|
+
onError(data, status, extra || {}, resolve);
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1182
|
+
if (timeout) {
|
|
1183
|
+
setTimeout(() => onTimeoutError(0, extra || {}, resolve), 1);
|
|
1184
|
+
} else {
|
|
1185
|
+
setTimeout(getResponse, requestTime + responseTime + 1);
|
|
1186
|
+
}
|
|
1187
|
+
onResponseEnd();
|
|
1188
|
+
});
|
|
1189
|
+
});
|
|
1190
|
+
|
|
1191
|
+
// src/adapter/adapter.bindings.ts
|
|
1192
|
+
var getAdapterBindings = (req, requestId, systemErrorStatus, systemErrorExtra) => __async(void 0, null, function* () {
|
|
1193
|
+
const { url, requestManager, loggerManager, headerMapper, payloadMapper } = req.client;
|
|
1194
|
+
const logger2 = loggerManager.init("Adapter");
|
|
1195
|
+
let processingError = null;
|
|
1196
|
+
let requestStartTimestamp = null;
|
|
1197
|
+
let responseStartTimestamp = null;
|
|
1198
|
+
let request = req;
|
|
1199
|
+
let requestTotal = 1;
|
|
1200
|
+
let responseTotal = 1;
|
|
1201
|
+
let previousRequestTotal = 0;
|
|
1202
|
+
let previousResponseTotal = 0;
|
|
1203
|
+
logger2.debug(`Starting request middleware callbacks`);
|
|
1204
|
+
try {
|
|
1205
|
+
request = yield request.client.__modifyRequest(req);
|
|
1206
|
+
if (request.auth) {
|
|
1207
|
+
request = yield request.client.__modifyAuth(req);
|
|
1208
|
+
}
|
|
1209
|
+
if (request.requestMapper) {
|
|
1210
|
+
request = yield request.requestMapper(request, requestId);
|
|
1211
|
+
}
|
|
1212
|
+
} catch (err) {
|
|
1213
|
+
processingError = err;
|
|
1214
|
+
}
|
|
1215
|
+
const { client, abortKey, queueKey, endpoint, data } = request;
|
|
1216
|
+
const fullUrl = url + endpoint;
|
|
1217
|
+
const effects = client.effects.filter((effect) => request.effectKey === effect.getEffectKey());
|
|
1218
|
+
const headers = headerMapper(request);
|
|
1219
|
+
let payload = data;
|
|
1220
|
+
try {
|
|
1221
|
+
payload = payloadMapper(data);
|
|
1222
|
+
if (request.dataMapper) {
|
|
1223
|
+
payload = yield request.dataMapper(data);
|
|
1224
|
+
}
|
|
1225
|
+
} catch (err) {
|
|
1226
|
+
processingError = err;
|
|
1227
|
+
}
|
|
1228
|
+
const config = __spreadValues({}, request.options);
|
|
1229
|
+
const getRequestStartTimestamp = () => {
|
|
1230
|
+
return requestStartTimestamp;
|
|
1231
|
+
};
|
|
1232
|
+
const getResponseStartTimestamp = () => {
|
|
1233
|
+
return responseStartTimestamp;
|
|
1234
|
+
};
|
|
1235
|
+
const getTotal = (previousTotal, progress) => {
|
|
1236
|
+
if (!progress)
|
|
1237
|
+
return previousTotal;
|
|
1238
|
+
const total = Number(progress.total || 0);
|
|
1239
|
+
const loaded = Number(progress.loaded || 0);
|
|
1240
|
+
return Math.max(total, loaded, previousTotal);
|
|
1241
|
+
};
|
|
1242
|
+
const handleRequestProgress = (startTimestamp, progressTimestamp, progressEvent) => {
|
|
1243
|
+
const progress = getProgressData(new Date(startTimestamp), new Date(progressTimestamp), progressEvent);
|
|
1244
|
+
if (previousRequestTotal !== 100) {
|
|
1245
|
+
previousRequestTotal = progress.total;
|
|
1246
|
+
requestManager.events.emitUploadProgress(queueKey, requestId, progress, { requestId, request });
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
const handleResponseProgress = (startTimestamp, progressTimestamp, progressEvent) => {
|
|
1250
|
+
const progress = getProgressData(new Date(startTimestamp), new Date(progressTimestamp), progressEvent);
|
|
1251
|
+
if (previousResponseTotal !== 100) {
|
|
1252
|
+
previousResponseTotal = progress.total;
|
|
1253
|
+
requestManager.events.emitDownloadProgress(queueKey, requestId, progress, { requestId, request });
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1256
|
+
const onBeforeRequest = () => {
|
|
1257
|
+
effects.forEach((effect) => effect.onTrigger(request));
|
|
1258
|
+
};
|
|
1259
|
+
const onRequestStart = (progress) => {
|
|
1260
|
+
effects.forEach((action) => action.onStart(request));
|
|
1261
|
+
if (progress == null ? void 0 : progress.total) {
|
|
1262
|
+
requestTotal = getTotal(requestTotal, progress);
|
|
1263
|
+
}
|
|
1264
|
+
const initialPayload = {
|
|
1265
|
+
total: requestTotal,
|
|
1266
|
+
loaded: (progress == null ? void 0 : progress.loaded) || 0
|
|
1267
|
+
};
|
|
1268
|
+
requestStartTimestamp = +new Date();
|
|
1269
|
+
handleRequestProgress(requestStartTimestamp, requestStartTimestamp, initialPayload);
|
|
1270
|
+
requestManager.events.emitRequestStart(queueKey, requestId, { requestId, request });
|
|
1271
|
+
return requestStartTimestamp;
|
|
1272
|
+
};
|
|
1273
|
+
const onRequestProgress = (progress) => {
|
|
1274
|
+
if (!requestStartTimestamp) {
|
|
1275
|
+
requestStartTimestamp = +new Date();
|
|
1276
|
+
}
|
|
1277
|
+
requestTotal = getTotal(requestTotal, progress);
|
|
1278
|
+
const progressTimestamp = +new Date();
|
|
1279
|
+
handleRequestProgress(requestStartTimestamp, progressTimestamp, {
|
|
1280
|
+
total: requestTotal,
|
|
1281
|
+
loaded: progress.loaded || 0
|
|
1282
|
+
});
|
|
1283
|
+
return progressTimestamp;
|
|
1284
|
+
};
|
|
1285
|
+
const onRequestEnd = () => {
|
|
1286
|
+
if (!requestStartTimestamp) {
|
|
1287
|
+
requestStartTimestamp = +new Date();
|
|
1288
|
+
}
|
|
1289
|
+
const progressTimestamp = +new Date();
|
|
1290
|
+
handleRequestProgress(requestStartTimestamp, progressTimestamp, {
|
|
1291
|
+
total: requestTotal,
|
|
1292
|
+
loaded: requestTotal
|
|
1293
|
+
});
|
|
1294
|
+
return progressTimestamp;
|
|
1295
|
+
};
|
|
1296
|
+
const onResponseStart = (progress) => {
|
|
1297
|
+
responseStartTimestamp = +new Date();
|
|
1298
|
+
responseTotal = getTotal(responseTotal, progress);
|
|
1299
|
+
const initialPayload = {
|
|
1300
|
+
total: responseTotal,
|
|
1301
|
+
loaded: (progress == null ? void 0 : progress.loaded) || 0
|
|
1302
|
+
};
|
|
1303
|
+
handleResponseProgress(responseStartTimestamp, responseStartTimestamp, initialPayload);
|
|
1304
|
+
requestManager.events.emitResponseStart(queueKey, requestId, { requestId, request });
|
|
1305
|
+
return responseStartTimestamp;
|
|
1306
|
+
};
|
|
1307
|
+
const onResponseProgress = (progress) => {
|
|
1308
|
+
if (!responseStartTimestamp) {
|
|
1309
|
+
responseStartTimestamp = +new Date();
|
|
1310
|
+
}
|
|
1311
|
+
const progressTimestamp = +new Date();
|
|
1312
|
+
responseTotal = getTotal(responseTotal, progress);
|
|
1313
|
+
handleResponseProgress(responseStartTimestamp, progressTimestamp, {
|
|
1314
|
+
total: progress.total || responseTotal,
|
|
1315
|
+
loaded: progress.loaded || 0
|
|
1316
|
+
});
|
|
1317
|
+
return progressTimestamp;
|
|
1318
|
+
};
|
|
1319
|
+
const onResponseEnd = () => {
|
|
1320
|
+
if (!responseStartTimestamp) {
|
|
1321
|
+
responseStartTimestamp = +new Date();
|
|
1322
|
+
}
|
|
1323
|
+
const progressTimestamp = +new Date();
|
|
1324
|
+
handleResponseProgress(responseStartTimestamp, progressTimestamp, {
|
|
1325
|
+
total: responseTotal,
|
|
1326
|
+
loaded: responseTotal
|
|
1327
|
+
});
|
|
1328
|
+
return progressTimestamp;
|
|
1329
|
+
};
|
|
1330
|
+
const onSuccess = (responseData, status, extra, resolve) => __async(void 0, null, function* () {
|
|
1331
|
+
let response = {
|
|
1332
|
+
data: responseData,
|
|
1333
|
+
error: null,
|
|
1334
|
+
success: true,
|
|
1335
|
+
status,
|
|
1336
|
+
extra
|
|
1337
|
+
};
|
|
1338
|
+
response = yield request.client.__modifyResponse(response, request);
|
|
1339
|
+
response = yield request.client.__modifySuccessResponse(response, request);
|
|
1340
|
+
effects.forEach((effect) => effect.onSuccess(response, request));
|
|
1341
|
+
effects.forEach((effect) => effect.onFinished(response, request));
|
|
1342
|
+
resolve(response);
|
|
1343
|
+
return response;
|
|
1344
|
+
});
|
|
1345
|
+
const onError = (error, status, extra, resolve) => __async(void 0, null, function* () {
|
|
1346
|
+
let responseData = {
|
|
1347
|
+
data: null,
|
|
1348
|
+
status,
|
|
1349
|
+
error,
|
|
1350
|
+
success: false,
|
|
1351
|
+
extra
|
|
1352
|
+
};
|
|
1353
|
+
responseData = yield request.client.__modifyResponse(responseData, request);
|
|
1354
|
+
responseData = yield request.client.__modifyErrorResponse(responseData, request);
|
|
1355
|
+
effects.forEach((effect) => effect.onError(responseData, request));
|
|
1356
|
+
effects.forEach((effect) => effect.onFinished(responseData, request));
|
|
1357
|
+
resolve(responseData);
|
|
1358
|
+
return responseData;
|
|
1359
|
+
});
|
|
1360
|
+
const onAbortError = (status, extra, resolve) => {
|
|
1361
|
+
const error = getErrorMessage("abort");
|
|
1362
|
+
return onError(error, status, extra, resolve);
|
|
1363
|
+
};
|
|
1364
|
+
const onTimeoutError = (status, extra, resolve) => {
|
|
1365
|
+
const error = getErrorMessage("timeout");
|
|
1366
|
+
return onError(error, status, extra, resolve);
|
|
1367
|
+
};
|
|
1368
|
+
const onUnexpectedError = (status, extra, resolve) => {
|
|
1369
|
+
const error = getErrorMessage();
|
|
1370
|
+
return onError(error, status, extra, resolve);
|
|
1371
|
+
};
|
|
1372
|
+
const getAbortController = () => {
|
|
1373
|
+
return requestManager.getAbortController(abortKey, requestId);
|
|
1374
|
+
};
|
|
1375
|
+
const createAbortListener = (status, abortExtra, callback, resolve) => {
|
|
1376
|
+
const controller = getAbortController();
|
|
1377
|
+
if (!controller) {
|
|
1378
|
+
throw new Error("Controller is not found");
|
|
1379
|
+
}
|
|
1380
|
+
const fn = () => {
|
|
1381
|
+
onAbortError(status, abortExtra, resolve);
|
|
1382
|
+
callback();
|
|
1383
|
+
requestManager.events.emitAbort(abortKey, requestId, request);
|
|
1384
|
+
};
|
|
1385
|
+
if (controller.signal.aborted) {
|
|
1386
|
+
fn();
|
|
1387
|
+
}
|
|
1388
|
+
controller.signal.addEventListener("abort", fn);
|
|
1389
|
+
return () => controller.signal.removeEventListener("abort", fn);
|
|
1390
|
+
};
|
|
1391
|
+
const makeRequest = (apiCall) => {
|
|
1392
|
+
if (processingError) {
|
|
1393
|
+
return onError(processingError, systemErrorStatus, systemErrorExtra, () => null);
|
|
1394
|
+
}
|
|
1395
|
+
if (req.mock) {
|
|
1396
|
+
return mocker(request, {
|
|
1397
|
+
onError,
|
|
1398
|
+
onResponseEnd,
|
|
1399
|
+
onTimeoutError,
|
|
1400
|
+
onRequestEnd,
|
|
1401
|
+
createAbortListener,
|
|
1402
|
+
onResponseProgress,
|
|
1403
|
+
onRequestProgress,
|
|
1404
|
+
onResponseStart,
|
|
1405
|
+
onBeforeRequest,
|
|
1406
|
+
onRequestStart,
|
|
1407
|
+
onSuccess
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
return new Promise(apiCall);
|
|
1411
|
+
};
|
|
1412
|
+
return {
|
|
1413
|
+
fullUrl,
|
|
1414
|
+
data,
|
|
1415
|
+
headers,
|
|
1416
|
+
payload,
|
|
1417
|
+
config,
|
|
1418
|
+
getAbortController,
|
|
1419
|
+
getRequestStartTimestamp,
|
|
1420
|
+
getResponseStartTimestamp,
|
|
1421
|
+
createAbortListener,
|
|
1422
|
+
onBeforeRequest,
|
|
1423
|
+
onRequestStart,
|
|
1424
|
+
onRequestProgress,
|
|
1425
|
+
onRequestEnd,
|
|
1426
|
+
onResponseStart,
|
|
1427
|
+
onResponseProgress,
|
|
1428
|
+
onResponseEnd,
|
|
1429
|
+
onSuccess,
|
|
1430
|
+
onAbortError,
|
|
1431
|
+
onTimeoutError,
|
|
1432
|
+
onUnexpectedError,
|
|
1433
|
+
onError,
|
|
1434
|
+
makeRequest
|
|
1435
|
+
};
|
|
1436
|
+
});
|
|
1437
|
+
|
|
1438
|
+
// src/cache/cache.ts
|
|
1439
|
+
import EventEmitter2 from "events";
|
|
1440
|
+
var Cache = class {
|
|
1441
|
+
constructor(client, options) {
|
|
1442
|
+
this.client = client;
|
|
1443
|
+
this.options = options;
|
|
1444
|
+
this.emitter = new EventEmitter2();
|
|
1445
|
+
this.garbageCollectors = /* @__PURE__ */ new Map();
|
|
1446
|
+
this.set = (request, response) => {
|
|
1447
|
+
var _a, _b, _c;
|
|
1448
|
+
this.logger.debug("Processing cache response", { request, response });
|
|
1449
|
+
const { cacheKey, cache, cacheTime, garbageCollection } = request;
|
|
1450
|
+
const cachedData = this.storage.get(cacheKey);
|
|
1451
|
+
const processedResponse = typeof response === "function" ? response(cachedData) : response;
|
|
1452
|
+
const data = getCacheData(cachedData, processedResponse);
|
|
1453
|
+
const newCacheData = __spreadProps(__spreadValues({}, data), { cacheTime, clearKey: this.clearKey, garbageCollection });
|
|
1454
|
+
this.events.emitCacheData(
|
|
1455
|
+
cacheKey,
|
|
1456
|
+
newCacheData
|
|
1457
|
+
);
|
|
1458
|
+
this.logger.debug("Emitting cache response", { request, data });
|
|
1459
|
+
if (!cache) {
|
|
1460
|
+
return this.logger.debug("Prevented saving response to cache", { request, data });
|
|
1461
|
+
}
|
|
1462
|
+
if (processedResponse.success) {
|
|
1463
|
+
this.logger.debug("Saving response to cache storage", { request, data });
|
|
1464
|
+
this.storage.set(cacheKey, newCacheData);
|
|
1465
|
+
(_a = this.lazyStorage) == null ? void 0 : _a.set(cacheKey, newCacheData);
|
|
1466
|
+
(_c = (_b = this.options) == null ? void 0 : _b.onChange) == null ? void 0 : _c.call(_b, cacheKey, newCacheData);
|
|
1467
|
+
this.scheduleGarbageCollector(cacheKey);
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
this.update = (request, partialResponse) => {
|
|
1471
|
+
this.logger.debug("Processing cache update", { request, partialResponse });
|
|
1472
|
+
const { cacheKey } = request;
|
|
1473
|
+
const cachedData = this.storage.get(cacheKey);
|
|
1474
|
+
const processedResponse = typeof partialResponse === "function" ? partialResponse(cachedData) : partialResponse;
|
|
1475
|
+
if (cachedData) {
|
|
1476
|
+
this.set(request, __spreadValues(__spreadValues({}, cachedData), processedResponse));
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
this.get = (cacheKey) => {
|
|
1480
|
+
this.getLazyResource(cacheKey);
|
|
1481
|
+
const cachedData = this.storage.get(cacheKey);
|
|
1482
|
+
return cachedData;
|
|
1483
|
+
};
|
|
1484
|
+
this.keys = () => {
|
|
1485
|
+
const values = this.storage.keys();
|
|
1486
|
+
return Array.from(values);
|
|
1487
|
+
};
|
|
1488
|
+
this.delete = (cacheKey) => {
|
|
1489
|
+
var _a, _b, _c;
|
|
1490
|
+
this.logger.debug("Deleting cache element", { cacheKey });
|
|
1491
|
+
this.storage.delete(cacheKey);
|
|
1492
|
+
(_b = (_a = this.options) == null ? void 0 : _a.onDelete) == null ? void 0 : _b.call(_a, cacheKey);
|
|
1493
|
+
(_c = this.lazyStorage) == null ? void 0 : _c.delete(cacheKey);
|
|
1494
|
+
};
|
|
1495
|
+
this.invalidate = (cacheKey) => __async(this, null, function* () {
|
|
1496
|
+
this.logger.debug("Revalidating cache element", { cacheKey });
|
|
1497
|
+
const keys = yield this.getLazyKeys();
|
|
1498
|
+
if (typeof cacheKey === "string") {
|
|
1499
|
+
this.events.emitInvalidation(cacheKey);
|
|
1500
|
+
this.delete(cacheKey);
|
|
1501
|
+
} else {
|
|
1502
|
+
for (const entityKey of keys) {
|
|
1503
|
+
if (cacheKey.test(entityKey)) {
|
|
1504
|
+
this.events.emitInvalidation(entityKey);
|
|
1505
|
+
this.delete(entityKey);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1510
|
+
this.getLazyResource = (cacheKey) => __async(this, null, function* () {
|
|
1511
|
+
var _a;
|
|
1512
|
+
const data = yield (_a = this.lazyStorage) == null ? void 0 : _a.get(cacheKey);
|
|
1513
|
+
const syncData = this.storage.get(cacheKey);
|
|
1514
|
+
const hasLazyData = this.lazyStorage && data;
|
|
1515
|
+
if (hasLazyData) {
|
|
1516
|
+
const now = +new Date();
|
|
1517
|
+
const isNewestData = syncData ? syncData.timestamp < data.timestamp : true;
|
|
1518
|
+
const isStaleData = data.cacheTime <= now - data.timestamp;
|
|
1519
|
+
const isValidLazyData = data.clearKey === this.clearKey;
|
|
1520
|
+
if (!isValidLazyData) {
|
|
1521
|
+
this.lazyStorage.delete(cacheKey);
|
|
1522
|
+
}
|
|
1523
|
+
if (isNewestData && !isStaleData && isValidLazyData) {
|
|
1524
|
+
this.storage.set(cacheKey, data);
|
|
1525
|
+
this.events.emitCacheData(cacheKey, data);
|
|
1526
|
+
return data;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
const isValidData = (syncData == null ? void 0 : syncData.clearKey) === this.clearKey;
|
|
1530
|
+
if (syncData && !isValidData) {
|
|
1531
|
+
this.delete(cacheKey);
|
|
1532
|
+
}
|
|
1533
|
+
return syncData;
|
|
1534
|
+
});
|
|
1535
|
+
this.getLazyKeys = () => __async(this, null, function* () {
|
|
1536
|
+
var _a;
|
|
1537
|
+
const keys = yield (_a = this.lazyStorage) == null ? void 0 : _a.keys();
|
|
1538
|
+
const asyncKeys = Array.from(keys || []);
|
|
1539
|
+
const syncKeys = Array.from(this.storage.keys());
|
|
1540
|
+
return [.../* @__PURE__ */ new Set([...asyncKeys, ...syncKeys])];
|
|
1541
|
+
});
|
|
1542
|
+
this.scheduleGarbageCollector = (cacheKey) => __async(this, null, function* () {
|
|
1543
|
+
const cacheData = yield this.getLazyResource(cacheKey);
|
|
1544
|
+
clearTimeout(this.garbageCollectors.get(cacheKey));
|
|
1545
|
+
if (cacheData) {
|
|
1546
|
+
const timeLeft = cacheData.garbageCollection + cacheData.timestamp - +new Date();
|
|
1547
|
+
if (cacheData.garbageCollection !== null && JSON.stringify(cacheData.garbageCollection) === "null") {
|
|
1548
|
+
this.logger.info("Cache value is Infinite", { cacheKey });
|
|
1549
|
+
} else if (timeLeft >= 0) {
|
|
1550
|
+
this.garbageCollectors.set(
|
|
1551
|
+
cacheKey,
|
|
1552
|
+
setTimeout(() => {
|
|
1553
|
+
if (this.client.appManager.isOnline) {
|
|
1554
|
+
this.logger.info("Garbage collecting cache element", { cacheKey });
|
|
1555
|
+
this.delete(cacheKey);
|
|
1556
|
+
}
|
|
1557
|
+
}, timeLeft)
|
|
1558
|
+
);
|
|
1559
|
+
} else if (this.client.appManager.isOnline) {
|
|
1560
|
+
this.logger.info("Garbage collecting cache element", { cacheKey });
|
|
1561
|
+
this.delete(cacheKey);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
});
|
|
1565
|
+
this.clear = () => __async(this, null, function* () {
|
|
1566
|
+
this.storage.clear();
|
|
1567
|
+
});
|
|
1568
|
+
var _a, _b, _c, _d, _e;
|
|
1569
|
+
this.storage = ((_a = this.options) == null ? void 0 : _a.storage) || /* @__PURE__ */ new Map();
|
|
1570
|
+
this.events = getCacheEvents(this.emitter);
|
|
1571
|
+
(_c = (_b = this.options) == null ? void 0 : _b.onInitialization) == null ? void 0 : _c.call(_b, this);
|
|
1572
|
+
this.clearKey = ((_d = this.options) == null ? void 0 : _d.clearKey) || "";
|
|
1573
|
+
this.lazyStorage = (_e = this.options) == null ? void 0 : _e.lazyStorage;
|
|
1574
|
+
this.logger = this.client.loggerManager.init("Cache");
|
|
1575
|
+
this.getLazyKeys().then((keys) => {
|
|
1576
|
+
keys.forEach(this.scheduleGarbageCollector);
|
|
1577
|
+
});
|
|
1578
|
+
this.client.appManager.events.onOnline(() => {
|
|
1579
|
+
this.getLazyKeys().then((keys) => {
|
|
1580
|
+
keys.forEach(this.scheduleGarbageCollector);
|
|
1581
|
+
});
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
|
|
1586
|
+
// src/cache/cache.utils.ts
|
|
1587
|
+
var getCacheData = (previousResponse, response) => {
|
|
1588
|
+
const { data, success } = response;
|
|
1589
|
+
const previousData = !success && previousResponse ? previousResponse.data : null;
|
|
1590
|
+
const computedData = data || previousData;
|
|
1591
|
+
return __spreadProps(__spreadValues({}, response), { data: computedData });
|
|
1592
|
+
};
|
|
1593
|
+
var getInvalidateEventKey = (key) => {
|
|
1594
|
+
return `${key}_invalidate`;
|
|
1595
|
+
};
|
|
1596
|
+
var getCacheKey = (key) => {
|
|
1597
|
+
return `${key}_cache`;
|
|
1598
|
+
};
|
|
1599
|
+
var getCacheIdKey = (key) => {
|
|
1600
|
+
return `${key}_cache_by_id`;
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
// src/cache/cache.events.ts
|
|
1604
|
+
var getCacheEvents = (emitter) => ({
|
|
1605
|
+
emitCacheData: (cacheKey, data) => {
|
|
1606
|
+
emitter.emit(getCacheKey(cacheKey), data);
|
|
1607
|
+
},
|
|
1608
|
+
emitInvalidation: (cacheKey) => {
|
|
1609
|
+
emitter.emit(getInvalidateEventKey(cacheKey));
|
|
1610
|
+
},
|
|
1611
|
+
onData: (cacheKey, callback) => {
|
|
1612
|
+
emitter.on(getCacheKey(cacheKey), callback);
|
|
1613
|
+
return () => emitter.removeListener(getCacheKey(cacheKey), callback);
|
|
1614
|
+
},
|
|
1615
|
+
onInvalidate: (cacheKey, callback) => {
|
|
1616
|
+
emitter.on(getInvalidateEventKey(cacheKey), callback);
|
|
1617
|
+
return () => emitter.removeListener(getInvalidateEventKey(cacheKey), callback);
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
|
|
1621
|
+
// src/managers/app/app.manager.ts
|
|
1622
|
+
import EventEmitter3 from "events";
|
|
1623
|
+
var AppManager = class {
|
|
1624
|
+
constructor(options) {
|
|
1625
|
+
this.options = options;
|
|
1626
|
+
this.emitter = new EventEmitter3();
|
|
1627
|
+
this.events = getAppManagerEvents(this.emitter);
|
|
1628
|
+
this.setInitialFocus = (initValue) => __async(this, null, function* () {
|
|
1629
|
+
if (typeof initValue === "function") {
|
|
1630
|
+
this.isFocused = false;
|
|
1631
|
+
this.isFocused = yield initValue();
|
|
1632
|
+
} else {
|
|
1633
|
+
this.isFocused = initValue;
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
this.setInitialOnline = (initValue) => __async(this, null, function* () {
|
|
1637
|
+
if (typeof initValue === "function") {
|
|
1638
|
+
this.isOnline = false;
|
|
1639
|
+
this.isOnline = yield initValue();
|
|
1640
|
+
} else {
|
|
1641
|
+
this.isOnline = initValue;
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
this.setFocused = (isFocused) => {
|
|
1645
|
+
this.isFocused = isFocused;
|
|
1646
|
+
if (isFocused) {
|
|
1647
|
+
this.events.emitFocus();
|
|
1648
|
+
} else {
|
|
1649
|
+
this.events.emitBlur();
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
this.setOnline = (isOnline) => {
|
|
1653
|
+
this.isOnline = isOnline;
|
|
1654
|
+
if (isOnline) {
|
|
1655
|
+
this.events.emitOnline();
|
|
1656
|
+
} else {
|
|
1657
|
+
this.events.emitOffline();
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
const {
|
|
1661
|
+
focusEvent = appManagerInitialOptions.focusEvent,
|
|
1662
|
+
onlineEvent = appManagerInitialOptions.onlineEvent,
|
|
1663
|
+
initiallyFocused = appManagerInitialOptions.initiallyFocused,
|
|
1664
|
+
initiallyOnline = appManagerInitialOptions.initiallyOnline
|
|
1665
|
+
} = this.options || appManagerInitialOptions;
|
|
1666
|
+
this.setInitialFocus(initiallyFocused);
|
|
1667
|
+
this.setInitialOnline(initiallyOnline);
|
|
1668
|
+
focusEvent(this.setFocused);
|
|
1669
|
+
onlineEvent(this.setOnline);
|
|
1670
|
+
this.isBrowser = hasDocument();
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
|
|
1674
|
+
// src/managers/app/app.manager.utils.ts
|
|
1675
|
+
var hasWindow = () => {
|
|
1676
|
+
try {
|
|
1677
|
+
return Boolean(window && window.addEventListener);
|
|
1678
|
+
} catch (err) {
|
|
1679
|
+
return false;
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1682
|
+
var hasDocument = () => {
|
|
1683
|
+
try {
|
|
1684
|
+
return Boolean(hasWindow() && window.document && window.document.addEventListener);
|
|
1685
|
+
} catch (err) {
|
|
1686
|
+
return false;
|
|
1687
|
+
}
|
|
1688
|
+
};
|
|
1689
|
+
var onWindowEvent = (key, listener, options) => {
|
|
1690
|
+
if (hasWindow()) {
|
|
1691
|
+
window.addEventListener(key, listener, options);
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1694
|
+
var onDocumentEvent = (key, listener, options) => {
|
|
1695
|
+
if (hasDocument()) {
|
|
1696
|
+
window.document.addEventListener(key, listener, options);
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
|
|
1700
|
+
// src/managers/app/app.manager.events.ts
|
|
1701
|
+
var getAppManagerEvents = (emitter) => ({
|
|
1702
|
+
emitFocus: () => {
|
|
1703
|
+
emitter.emit("focus" /* focus */);
|
|
1704
|
+
},
|
|
1705
|
+
emitBlur: () => {
|
|
1706
|
+
emitter.emit("blur" /* blur */);
|
|
1707
|
+
},
|
|
1708
|
+
emitOnline: () => {
|
|
1709
|
+
emitter.emit("online" /* online */);
|
|
1710
|
+
},
|
|
1711
|
+
emitOffline: () => {
|
|
1712
|
+
emitter.emit("offline" /* offline */);
|
|
1713
|
+
},
|
|
1714
|
+
onFocus: (callback) => {
|
|
1715
|
+
emitter.on("focus" /* focus */, callback);
|
|
1716
|
+
return () => emitter.removeListener("focus" /* focus */, callback);
|
|
1717
|
+
},
|
|
1718
|
+
onBlur: (callback) => {
|
|
1719
|
+
emitter.on("blur" /* blur */, callback);
|
|
1720
|
+
return () => emitter.removeListener("blur" /* blur */, callback);
|
|
1721
|
+
},
|
|
1722
|
+
onOnline: (callback) => {
|
|
1723
|
+
emitter.on("online" /* online */, callback);
|
|
1724
|
+
return () => emitter.removeListener("online" /* online */, callback);
|
|
1725
|
+
},
|
|
1726
|
+
onOffline: (callback) => {
|
|
1727
|
+
emitter.on("offline" /* offline */, callback);
|
|
1728
|
+
return () => emitter.removeListener("offline" /* offline */, callback);
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1731
|
+
|
|
1732
|
+
// src/managers/app/app.manager.constants.ts
|
|
1733
|
+
var AppEvents = /* @__PURE__ */ ((AppEvents2) => {
|
|
1734
|
+
AppEvents2["focus"] = "focus";
|
|
1735
|
+
AppEvents2["blur"] = "blur";
|
|
1736
|
+
AppEvents2["online"] = "online";
|
|
1737
|
+
AppEvents2["offline"] = "offline";
|
|
1738
|
+
return AppEvents2;
|
|
1739
|
+
})(AppEvents || {});
|
|
1740
|
+
var appManagerInitialOptions = {
|
|
1741
|
+
initiallyFocused: true,
|
|
1742
|
+
initiallyOnline: true,
|
|
1743
|
+
focusEvent: (setFocused) => {
|
|
1744
|
+
onDocumentEvent("visibilitychange", () => setFocused(true));
|
|
1745
|
+
onWindowEvent("focus", () => setFocused(true));
|
|
1746
|
+
onWindowEvent("blur", () => setFocused(false));
|
|
1747
|
+
},
|
|
1748
|
+
onlineEvent: (setOnline) => {
|
|
1749
|
+
onWindowEvent("online", () => setOnline(true));
|
|
1750
|
+
onWindowEvent("offline", () => setOnline(false));
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
|
|
1754
|
+
// src/managers/request/request.manager.ts
|
|
1755
|
+
import EventEmitter4 from "events";
|
|
1756
|
+
var RequestManager = class {
|
|
1757
|
+
constructor() {
|
|
1758
|
+
this.emitter = new EventEmitter4();
|
|
1759
|
+
this.events = getRequestManagerEvents(this.emitter);
|
|
1760
|
+
this.abortControllers = /* @__PURE__ */ new Map();
|
|
1761
|
+
this.addAbortController = (abortKey, requestId) => {
|
|
1762
|
+
let abortGroup = this.abortControllers.get(abortKey);
|
|
1763
|
+
if (!abortGroup) {
|
|
1764
|
+
const newAbortGroup = /* @__PURE__ */ new Map();
|
|
1765
|
+
abortGroup = newAbortGroup;
|
|
1766
|
+
this.abortControllers.set(abortKey, newAbortGroup);
|
|
1767
|
+
}
|
|
1768
|
+
const abortController = abortGroup.get(requestId);
|
|
1769
|
+
if (!abortController || abortController.signal.aborted) {
|
|
1770
|
+
abortGroup.set(requestId, new AbortController());
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
this.getAbortController = (abortKey, requestId) => {
|
|
1774
|
+
var _a;
|
|
1775
|
+
return (_a = this.abortControllers.get(abortKey)) == null ? void 0 : _a.get(requestId);
|
|
1776
|
+
};
|
|
1777
|
+
this.removeAbortController = (abortKey, requestId) => {
|
|
1778
|
+
var _a;
|
|
1779
|
+
(_a = this.abortControllers.get(abortKey)) == null ? void 0 : _a.delete(requestId);
|
|
1780
|
+
};
|
|
1781
|
+
this.useAbortController = (abortKey, requestId) => {
|
|
1782
|
+
var _a;
|
|
1783
|
+
const controller = (_a = this.abortControllers.get(abortKey)) == null ? void 0 : _a.get(requestId);
|
|
1784
|
+
controller == null ? void 0 : controller.abort();
|
|
1785
|
+
};
|
|
1786
|
+
this.abortByKey = (abortKey) => {
|
|
1787
|
+
const controllers = this.abortControllers.get(abortKey);
|
|
1788
|
+
if (controllers) {
|
|
1789
|
+
const entries = Array.from(controllers.entries());
|
|
1790
|
+
entries.forEach(([key]) => {
|
|
1791
|
+
this.useAbortController(abortKey, key);
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
this.abortByRequestId = (abortKey, requestId) => {
|
|
1796
|
+
this.useAbortController(abortKey, requestId);
|
|
1797
|
+
};
|
|
1798
|
+
this.abortAll = () => {
|
|
1799
|
+
const entries = Array.from(this.abortControllers.entries());
|
|
1800
|
+
entries.forEach(([abortKey, value]) => {
|
|
1801
|
+
const controllers = Array.from(value.entries());
|
|
1802
|
+
controllers.forEach(([requestId]) => {
|
|
1803
|
+
this.useAbortController(abortKey, requestId);
|
|
1804
|
+
});
|
|
1805
|
+
});
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
|
|
1810
|
+
// src/managers/request/request.manager.utils.ts
|
|
1811
|
+
var getLoadingEventKey = (key) => `${key}-loading-event`;
|
|
1812
|
+
var getLoadingIdEventKey = (key) => `${key}-loading-event-by-id`;
|
|
1813
|
+
var getRemoveEventKey = (key) => `${key}-remove-event`;
|
|
1814
|
+
var getRemoveIdEventKey = (key) => `${key}-remove-event-by-id`;
|
|
1815
|
+
var getAbortEventKey = (key) => `${key}-request-abort`;
|
|
1816
|
+
var getAbortByIdEventKey = (key) => `${key}-request-abort-by-id`;
|
|
1817
|
+
var getResponseEventKey = (key) => `${key}-response`;
|
|
1818
|
+
var getResponseIdEventKey = (key) => `${key}-response-by-id`;
|
|
1819
|
+
var getRequestStartEventKey = (key) => `${key}-request-start`;
|
|
1820
|
+
var getRequestStartIdEventKey = (key) => `${key}-request-start-by-id`;
|
|
1821
|
+
var getResponseStartEventKey = (key) => `${key}-response-start`;
|
|
1822
|
+
var getResponseStartIdEventKey = (key) => `${key}-response-start-by-id`;
|
|
1823
|
+
var getUploadProgressEventKey = (key) => `${key}-request-progress`;
|
|
1824
|
+
var getUploadProgressIdEventKey = (key) => `${key}-request-progress-by-id`;
|
|
1825
|
+
var getDownloadProgressEventKey = (key) => `${key}-response-progress`;
|
|
1826
|
+
var getDownloadProgressIdEventKey = (key) => `${key}-response-progress-by-id`;
|
|
1827
|
+
|
|
1828
|
+
// src/managers/request/request.manager.events.ts
|
|
1829
|
+
var getRequestManagerEvents = (emitter) => ({
|
|
1830
|
+
emitLoading: (queueKey, requestId, values) => {
|
|
1831
|
+
emitter.emit(getLoadingIdEventKey(requestId), values);
|
|
1832
|
+
emitter.emit(getLoadingEventKey(queueKey), values);
|
|
1833
|
+
},
|
|
1834
|
+
emitRequestStart: (queueKey, requestId, details) => {
|
|
1835
|
+
emitter.emit(getRequestStartIdEventKey(requestId), details);
|
|
1836
|
+
emitter.emit(getRequestStartEventKey(queueKey), details);
|
|
1837
|
+
},
|
|
1838
|
+
emitResponseStart: (queueKey, requestId, details) => {
|
|
1839
|
+
emitter.emit(getResponseStartIdEventKey(requestId), details);
|
|
1840
|
+
emitter.emit(getResponseStartEventKey(queueKey), details);
|
|
1841
|
+
},
|
|
1842
|
+
emitUploadProgress: (queueKey, requestId, values, details) => {
|
|
1843
|
+
emitter.emit(getUploadProgressIdEventKey(requestId), values, details);
|
|
1844
|
+
emitter.emit(getUploadProgressEventKey(queueKey), values, details);
|
|
1845
|
+
},
|
|
1846
|
+
emitDownloadProgress: (queueKey, requestId, values, details) => {
|
|
1847
|
+
emitter.emit(getDownloadProgressIdEventKey(requestId), values, details);
|
|
1848
|
+
emitter.emit(getDownloadProgressEventKey(queueKey), values, details);
|
|
1849
|
+
},
|
|
1850
|
+
emitResponse: (cacheKey, requestId, response, details) => {
|
|
1851
|
+
emitter.emit(getResponseIdEventKey(requestId), response, details);
|
|
1852
|
+
emitter.emit(getResponseEventKey(cacheKey), response, details);
|
|
1853
|
+
},
|
|
1854
|
+
emitAbort: (abortKey, requestId, request) => {
|
|
1855
|
+
emitter.emit(getAbortByIdEventKey(requestId), request);
|
|
1856
|
+
emitter.emit(getAbortEventKey(abortKey), request);
|
|
1857
|
+
},
|
|
1858
|
+
emitRemove: (queueKey, requestId, details) => {
|
|
1859
|
+
emitter.emit(getRemoveEventKey(queueKey), details);
|
|
1860
|
+
emitter.emit(getRemoveIdEventKey(requestId), details);
|
|
1861
|
+
},
|
|
1862
|
+
onLoading: (queueKey, callback) => {
|
|
1863
|
+
emitter.on(getLoadingEventKey(queueKey), callback);
|
|
1864
|
+
return () => emitter.removeListener(getLoadingEventKey(queueKey), callback);
|
|
1865
|
+
},
|
|
1866
|
+
onLoadingById: (requestId, callback) => {
|
|
1867
|
+
emitter.on(getLoadingIdEventKey(requestId), callback);
|
|
1868
|
+
return () => emitter.removeListener(getLoadingIdEventKey(requestId), callback);
|
|
1869
|
+
},
|
|
1870
|
+
onRequestStart: (queueKey, callback) => {
|
|
1871
|
+
emitter.on(getRequestStartEventKey(queueKey), callback);
|
|
1872
|
+
return () => emitter.removeListener(getRequestStartEventKey(queueKey), callback);
|
|
1873
|
+
},
|
|
1874
|
+
onRequestStartById: (requestId, callback) => {
|
|
1875
|
+
emitter.on(getRequestStartIdEventKey(requestId), callback);
|
|
1876
|
+
return () => emitter.removeListener(getRequestStartIdEventKey(requestId), callback);
|
|
1877
|
+
},
|
|
1878
|
+
onResponseStart: (queueKey, callback) => {
|
|
1879
|
+
emitter.on(getResponseStartEventKey(queueKey), callback);
|
|
1880
|
+
return () => emitter.removeListener(getResponseStartEventKey(queueKey), callback);
|
|
1881
|
+
},
|
|
1882
|
+
onResponseStartById: (requestId, callback) => {
|
|
1883
|
+
emitter.on(getResponseStartIdEventKey(requestId), callback);
|
|
1884
|
+
return () => emitter.removeListener(getResponseStartIdEventKey(requestId), callback);
|
|
1885
|
+
},
|
|
1886
|
+
onUploadProgress: (queueKey, callback) => {
|
|
1887
|
+
emitter.on(getUploadProgressEventKey(queueKey), callback);
|
|
1888
|
+
return () => emitter.removeListener(getUploadProgressEventKey(queueKey), callback);
|
|
1889
|
+
},
|
|
1890
|
+
onUploadProgressById: (requestId, callback) => {
|
|
1891
|
+
emitter.on(getUploadProgressIdEventKey(requestId), callback);
|
|
1892
|
+
return () => emitter.removeListener(getUploadProgressIdEventKey(requestId), callback);
|
|
1893
|
+
},
|
|
1894
|
+
onDownloadProgress: (queueKey, callback) => {
|
|
1895
|
+
emitter.on(getDownloadProgressEventKey(queueKey), callback);
|
|
1896
|
+
return () => emitter.removeListener(getDownloadProgressEventKey(queueKey), callback);
|
|
1897
|
+
},
|
|
1898
|
+
onDownloadProgressById: (requestId, callback) => {
|
|
1899
|
+
emitter.on(getDownloadProgressIdEventKey(requestId), callback);
|
|
1900
|
+
return () => emitter.removeListener(getDownloadProgressIdEventKey(requestId), callback);
|
|
1901
|
+
},
|
|
1902
|
+
onResponse: (cacheKey, callback) => {
|
|
1903
|
+
emitter.on(getResponseEventKey(cacheKey), callback);
|
|
1904
|
+
return () => emitter.removeListener(getResponseEventKey(cacheKey), callback);
|
|
1905
|
+
},
|
|
1906
|
+
onResponseById: (requestId, callback) => {
|
|
1907
|
+
emitter.on(getResponseIdEventKey(requestId), callback);
|
|
1908
|
+
return () => emitter.removeListener(getResponseIdEventKey(requestId), callback);
|
|
1909
|
+
},
|
|
1910
|
+
onAbort: (abortKey, callback) => {
|
|
1911
|
+
emitter.on(getAbortEventKey(abortKey), callback);
|
|
1912
|
+
return () => emitter.removeListener(getAbortEventKey(abortKey), callback);
|
|
1913
|
+
},
|
|
1914
|
+
onAbortById: (requestId, callback) => {
|
|
1915
|
+
emitter.on(getAbortByIdEventKey(requestId), callback);
|
|
1916
|
+
return () => emitter.removeListener(getAbortByIdEventKey(requestId), callback);
|
|
1917
|
+
},
|
|
1918
|
+
onRemove: (queueKey, callback) => {
|
|
1919
|
+
emitter.on(getRemoveEventKey(queueKey), callback);
|
|
1920
|
+
return () => emitter.removeListener(getRemoveEventKey(queueKey), callback);
|
|
1921
|
+
},
|
|
1922
|
+
onRemoveById: (requestId, callback) => {
|
|
1923
|
+
emitter.on(getRemoveIdEventKey(requestId), callback);
|
|
1924
|
+
return () => emitter.removeListener(getRemoveIdEventKey(requestId), callback);
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
|
|
1928
|
+
// src/managers/logger/logger.manager.ts
|
|
1929
|
+
import EventEmitter5 from "events";
|
|
1930
|
+
var LoggerManager = class {
|
|
1931
|
+
constructor(client, options) {
|
|
1932
|
+
this.client = client;
|
|
1933
|
+
this.options = options;
|
|
1934
|
+
this.emitter = new EventEmitter5();
|
|
1935
|
+
this.setSeverity = (severity2) => {
|
|
1936
|
+
this.severity = severity2;
|
|
1937
|
+
};
|
|
1938
|
+
this.init = (module) => {
|
|
1939
|
+
return {
|
|
1940
|
+
error: (message, ...extra) => {
|
|
1941
|
+
this.logger({
|
|
1942
|
+
level: "error",
|
|
1943
|
+
module,
|
|
1944
|
+
message,
|
|
1945
|
+
extra,
|
|
1946
|
+
severity: this.severity,
|
|
1947
|
+
enabled: this.client.debug
|
|
1948
|
+
});
|
|
1949
|
+
},
|
|
1950
|
+
warning: (message, ...extra) => {
|
|
1951
|
+
this.logger({
|
|
1952
|
+
level: "warning",
|
|
1953
|
+
module,
|
|
1954
|
+
message,
|
|
1955
|
+
extra,
|
|
1956
|
+
severity: this.severity,
|
|
1957
|
+
enabled: this.client.debug
|
|
1958
|
+
});
|
|
1959
|
+
},
|
|
1960
|
+
info: (message, ...extra) => {
|
|
1961
|
+
this.logger({
|
|
1962
|
+
level: "info",
|
|
1963
|
+
module,
|
|
1964
|
+
message,
|
|
1965
|
+
extra,
|
|
1966
|
+
severity: this.severity,
|
|
1967
|
+
enabled: this.client.debug
|
|
1968
|
+
});
|
|
1969
|
+
},
|
|
1970
|
+
debug: (message, ...extra) => {
|
|
1971
|
+
this.logger({
|
|
1972
|
+
level: "debug",
|
|
1973
|
+
module,
|
|
1974
|
+
message,
|
|
1975
|
+
extra,
|
|
1976
|
+
severity: this.severity,
|
|
1977
|
+
enabled: this.client.debug
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
};
|
|
1981
|
+
};
|
|
1982
|
+
var _a, _b;
|
|
1983
|
+
this.logger = ((_a = this.options) == null ? void 0 : _a.logger) || logger;
|
|
1984
|
+
this.severity = ((_b = this.options) == null ? void 0 : _b.severity) || 2;
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
|
|
1988
|
+
// src/managers/logger/logger.manager.utils.ts
|
|
1989
|
+
var getTime = () => {
|
|
1990
|
+
const d = new Date();
|
|
1991
|
+
return `${d.toLocaleTimeString()}(:${d.getMilliseconds()})`;
|
|
1992
|
+
};
|
|
1993
|
+
var logger = (log) => {
|
|
1994
|
+
var _a;
|
|
1995
|
+
if (log.enabled && log.severity >= severity[log.level]) {
|
|
1996
|
+
const styles = loggerStyles[log.level];
|
|
1997
|
+
const emoji = loggerIconLevels[log.level];
|
|
1998
|
+
const module = `%c[${log.module}]:[${getTime()}]:`;
|
|
1999
|
+
const message = `${emoji}${module} ${log.message}`;
|
|
2000
|
+
if ((_a = log.extra) == null ? void 0 : _a.length) {
|
|
2001
|
+
console.groupCollapsed(message, styles);
|
|
2002
|
+
log.extra.forEach((data) => {
|
|
2003
|
+
console.log(data);
|
|
2004
|
+
});
|
|
2005
|
+
console.groupEnd();
|
|
2006
|
+
} else {
|
|
2007
|
+
console.log(message, styles);
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
};
|
|
2011
|
+
|
|
2012
|
+
// src/managers/logger/logger.manager.constants.ts
|
|
2013
|
+
var defaultStyles = "background:rgba(0,0,0,0.2);padding:2px 5px;border-radius:5px;font-weight:bold;";
|
|
2014
|
+
var loggerStyles = {
|
|
2015
|
+
error: `${defaultStyles}color:#db2525`,
|
|
2016
|
+
warning: `${defaultStyles}color:#e1941e`,
|
|
2017
|
+
info: `${defaultStyles}color:#1e74e1`,
|
|
2018
|
+
debug: `${defaultStyles}color:#adadad`
|
|
2019
|
+
};
|
|
2020
|
+
var loggerIconLevels = {
|
|
2021
|
+
error: `\u{1F6A8}`,
|
|
2022
|
+
warning: `\u{1F6A7}`,
|
|
2023
|
+
info: `\u2139\uFE0F`,
|
|
2024
|
+
debug: `\u{1F6E9}\uFE0F`
|
|
2025
|
+
};
|
|
2026
|
+
var severity = {
|
|
2027
|
+
error: 0,
|
|
2028
|
+
warning: 1,
|
|
2029
|
+
info: 2,
|
|
2030
|
+
debug: 3
|
|
2031
|
+
};
|
|
2032
|
+
|
|
2033
|
+
// src/client/client.utils.ts
|
|
2034
|
+
var stringifyValue = (response) => {
|
|
2035
|
+
try {
|
|
2036
|
+
return JSON.stringify(response);
|
|
2037
|
+
} catch (err) {
|
|
2038
|
+
return "";
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
var interceptRequest = (interceptors, request) => __async(void 0, null, function* () {
|
|
2042
|
+
let newRequest = request;
|
|
2043
|
+
if (!request.requestOptions.disableRequestInterceptors) {
|
|
2044
|
+
for (const interceptor of interceptors) {
|
|
2045
|
+
newRequest = yield interceptor(request);
|
|
2046
|
+
if (!newRequest)
|
|
2047
|
+
throw new Error("Request modifier must return request");
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
return newRequest;
|
|
2051
|
+
});
|
|
2052
|
+
var interceptResponse = (interceptors, response, request) => __async(void 0, null, function* () {
|
|
2053
|
+
let newResponse = response;
|
|
2054
|
+
if (!request.requestOptions.disableResponseInterceptors) {
|
|
2055
|
+
for (const interceptor of interceptors) {
|
|
2056
|
+
newResponse = yield interceptor(response, request);
|
|
2057
|
+
if (!newResponse)
|
|
2058
|
+
throw new Error("Response modifier must return data");
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
return newResponse;
|
|
2062
|
+
});
|
|
2063
|
+
var getAdapterHeaders = (request) => {
|
|
2064
|
+
const isFormData = hasWindow() && request.data instanceof FormData;
|
|
2065
|
+
const headers = {};
|
|
2066
|
+
if (!isFormData)
|
|
2067
|
+
headers["Content-Type"] = "application/json";
|
|
2068
|
+
Object.assign(headers, request.headers);
|
|
2069
|
+
return headers;
|
|
2070
|
+
};
|
|
2071
|
+
var getAdapterPayload = (data) => {
|
|
2072
|
+
const isFormData = hasWindow() && data instanceof FormData;
|
|
2073
|
+
if (isFormData)
|
|
2074
|
+
return data;
|
|
2075
|
+
return stringifyValue(data);
|
|
2076
|
+
};
|
|
2077
|
+
var isValidValue = (options) => {
|
|
2078
|
+
return (value) => {
|
|
2079
|
+
const { skipNull, skipEmptyString } = options;
|
|
2080
|
+
if (skipEmptyString && value === void 0) {
|
|
2081
|
+
return false;
|
|
2082
|
+
}
|
|
2083
|
+
if (skipEmptyString && value === "") {
|
|
2084
|
+
return false;
|
|
2085
|
+
}
|
|
2086
|
+
if (skipNull && value === null) {
|
|
2087
|
+
return false;
|
|
2088
|
+
}
|
|
2089
|
+
return true;
|
|
2090
|
+
};
|
|
2091
|
+
};
|
|
2092
|
+
var encodeValue = (value, { encode, strict }) => {
|
|
2093
|
+
if (encode && strict) {
|
|
2094
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (s) => `%${s.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
2095
|
+
}
|
|
2096
|
+
if (encode) {
|
|
2097
|
+
return encodeURIComponent(value);
|
|
2098
|
+
}
|
|
2099
|
+
return value;
|
|
2100
|
+
};
|
|
2101
|
+
var encodeParams = (key, value, options) => {
|
|
2102
|
+
const shouldSkip = !isValidValue(options)(value);
|
|
2103
|
+
if (!key || shouldSkip) {
|
|
2104
|
+
return "";
|
|
2105
|
+
}
|
|
2106
|
+
const parsedValue = () => {
|
|
2107
|
+
var _a, _b;
|
|
2108
|
+
if (value instanceof Date) {
|
|
2109
|
+
return ((_a = options.dateParser) == null ? void 0 : _a.call(options, value)) || value.toISOString();
|
|
2110
|
+
}
|
|
2111
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
2112
|
+
return ((_b = options.objectParser) == null ? void 0 : _b.call(options, value)) || JSON.stringify(value);
|
|
2113
|
+
}
|
|
2114
|
+
return String(value);
|
|
2115
|
+
};
|
|
2116
|
+
return `${encodeValue(key, options)}=${encodeValue(parsedValue(), options)}`;
|
|
2117
|
+
};
|
|
2118
|
+
var encodeArray = (key, array, options) => {
|
|
2119
|
+
const { arrayFormat, arraySeparator } = options;
|
|
2120
|
+
return array.filter(isValidValue(options)).reduce((acc, value, index) => {
|
|
2121
|
+
switch (arrayFormat) {
|
|
2122
|
+
case "index": {
|
|
2123
|
+
const keyValue = `${encodeValue(key, options)}[${encodeValue(String(index), options)}]=`;
|
|
2124
|
+
acc.push(`${keyValue}${encodeValue(String(value), options)}`);
|
|
2125
|
+
break;
|
|
2126
|
+
}
|
|
2127
|
+
case "bracket": {
|
|
2128
|
+
const keyValue = `${encodeValue(key, options)}[]=`;
|
|
2129
|
+
acc.push(`${keyValue}${encodeValue(String(value), options)}`);
|
|
2130
|
+
break;
|
|
2131
|
+
}
|
|
2132
|
+
case "comma": {
|
|
2133
|
+
const keyValue = !acc.length && `${encodeValue(key, options)}=` || "";
|
|
2134
|
+
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(",")];
|
|
2135
|
+
}
|
|
2136
|
+
case "separator": {
|
|
2137
|
+
const keyValue = !acc.length && `${encodeValue(key, options)}=` || "";
|
|
2138
|
+
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(arraySeparator || "|")];
|
|
2139
|
+
}
|
|
2140
|
+
case "bracket-separator": {
|
|
2141
|
+
const keyValue = !acc.length && `${encodeValue(key, options)}[]=` || "";
|
|
2142
|
+
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(arraySeparator || "|")];
|
|
2143
|
+
}
|
|
2144
|
+
default: {
|
|
2145
|
+
const keyValue = `${encodeValue(key, options)}=`;
|
|
2146
|
+
acc.push(`${keyValue}${encodeValue(String(value), options)}`);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
return acc;
|
|
2150
|
+
}, []).join("&");
|
|
2151
|
+
};
|
|
2152
|
+
var stringifyQueryParams = (queryParams, options = stringifyDefaultOptions) => {
|
|
2153
|
+
if (!queryParams || !Object.keys(queryParams).length) {
|
|
2154
|
+
return "";
|
|
2155
|
+
}
|
|
2156
|
+
if (typeof queryParams === "string") {
|
|
2157
|
+
const hasQuestionMark = queryParams[0] === "?";
|
|
2158
|
+
return hasQuestionMark ? queryParams : `?${queryParams}`;
|
|
2159
|
+
}
|
|
2160
|
+
const stringified = Object.entries(queryParams).map(([key, value]) => {
|
|
2161
|
+
if (Array.isArray(value)) {
|
|
2162
|
+
return encodeArray(key, value, options);
|
|
2163
|
+
}
|
|
2164
|
+
return encodeParams(key, value, options);
|
|
2165
|
+
}).filter(Boolean).join("&");
|
|
2166
|
+
if (stringified) {
|
|
2167
|
+
return `?${stringified}`;
|
|
2168
|
+
}
|
|
2169
|
+
return "";
|
|
2170
|
+
};
|
|
2171
|
+
|
|
2172
|
+
// src/client/client.ts
|
|
2173
|
+
var Client = class {
|
|
2174
|
+
constructor(options) {
|
|
2175
|
+
this.options = options;
|
|
2176
|
+
this.__onErrorCallbacks = [];
|
|
2177
|
+
this.__onSuccessCallbacks = [];
|
|
2178
|
+
this.__onResponseCallbacks = [];
|
|
2179
|
+
this.__onAuthCallbacks = [];
|
|
2180
|
+
this.__onRequestCallbacks = [];
|
|
2181
|
+
this.requestManager = new RequestManager();
|
|
2182
|
+
this.loggerManager = new LoggerManager(this);
|
|
2183
|
+
this.defaultMethod = "GET" /* get */;
|
|
2184
|
+
this.defaultExtra = xhrExtra;
|
|
2185
|
+
this.effects = [];
|
|
2186
|
+
this.abortKeyMapper = getSimpleKey;
|
|
2187
|
+
this.cacheKeyMapper = getRequestKey;
|
|
2188
|
+
this.queueKeyMapper = getSimpleKey;
|
|
2189
|
+
this.effectKeyMapper = getSimpleKey;
|
|
2190
|
+
this.stringifyQueryParams = (queryParams) => stringifyQueryParams(queryParams, this.queryParamsConfig);
|
|
2191
|
+
this.headerMapper = getAdapterHeaders;
|
|
2192
|
+
this.payloadMapper = getAdapterPayload;
|
|
2193
|
+
this.endpointMapper = (endpoint) => endpoint;
|
|
2194
|
+
this.logger = this.loggerManager.init("Client");
|
|
2195
|
+
this.setRequestDefaultOptions = (callback) => {
|
|
2196
|
+
this.requestDefaultOptions = callback;
|
|
2197
|
+
return this;
|
|
2198
|
+
};
|
|
2199
|
+
this.setAdapterDefaultOptions = (callback) => {
|
|
2200
|
+
this.adapterDefaultOptions = callback;
|
|
2201
|
+
return this;
|
|
2202
|
+
};
|
|
2203
|
+
this.setDebug = (debug) => {
|
|
2204
|
+
this.debug = debug;
|
|
2205
|
+
return this;
|
|
2206
|
+
};
|
|
2207
|
+
this.setLoggerSeverity = (severity2) => {
|
|
2208
|
+
this.loggerManager.setSeverity(severity2);
|
|
2209
|
+
return this;
|
|
2210
|
+
};
|
|
2211
|
+
this.setLogger = (callback) => {
|
|
2212
|
+
this.loggerManager = callback(this);
|
|
2213
|
+
return this;
|
|
2214
|
+
};
|
|
2215
|
+
this.setQueryParamsConfig = (queryParamsConfig) => {
|
|
2216
|
+
this.queryParamsConfig = queryParamsConfig;
|
|
2217
|
+
return this;
|
|
2218
|
+
};
|
|
2219
|
+
this.setStringifyQueryParams = (stringifyFn) => {
|
|
2220
|
+
this.stringifyQueryParams = stringifyFn;
|
|
2221
|
+
return this;
|
|
2222
|
+
};
|
|
2223
|
+
this.setHeaderMapper = (headerMapper) => {
|
|
2224
|
+
this.headerMapper = headerMapper;
|
|
2225
|
+
return this;
|
|
2226
|
+
};
|
|
2227
|
+
this.setPayloadMapper = (payloadMapper) => {
|
|
2228
|
+
this.payloadMapper = payloadMapper;
|
|
2229
|
+
return this;
|
|
2230
|
+
};
|
|
2231
|
+
this.setEndpointMapper = (endpointMapper) => {
|
|
2232
|
+
this.endpointMapper = endpointMapper;
|
|
2233
|
+
return this;
|
|
2234
|
+
};
|
|
2235
|
+
this.setAdapter = (callback) => {
|
|
2236
|
+
const value = callback(this);
|
|
2237
|
+
if (value instanceof Client) {
|
|
2238
|
+
return value;
|
|
2239
|
+
}
|
|
2240
|
+
this.adapter = value;
|
|
2241
|
+
return this;
|
|
2242
|
+
};
|
|
2243
|
+
this.setDefaultMethod = (defaultMethod) => {
|
|
2244
|
+
this.defaultMethod = defaultMethod;
|
|
2245
|
+
return this;
|
|
2246
|
+
};
|
|
2247
|
+
this.setDefaultExtra = (defaultExtra) => {
|
|
2248
|
+
this.defaultExtra = defaultExtra;
|
|
2249
|
+
return this;
|
|
2250
|
+
};
|
|
2251
|
+
this.onAuth = (callback) => {
|
|
2252
|
+
this.__onAuthCallbacks.push(callback);
|
|
2253
|
+
return this;
|
|
2254
|
+
};
|
|
2255
|
+
this.onError = (callback) => {
|
|
2256
|
+
this.__onErrorCallbacks.push(callback);
|
|
2257
|
+
return this;
|
|
2258
|
+
};
|
|
2259
|
+
this.onSuccess = (callback) => {
|
|
2260
|
+
this.__onSuccessCallbacks.push(callback);
|
|
2261
|
+
return this;
|
|
2262
|
+
};
|
|
2263
|
+
this.onRequest = (callback) => {
|
|
2264
|
+
this.__onRequestCallbacks.push(callback);
|
|
2265
|
+
return this;
|
|
2266
|
+
};
|
|
2267
|
+
this.onResponse = (callback) => {
|
|
2268
|
+
this.__onResponseCallbacks.push(callback);
|
|
2269
|
+
return this;
|
|
2270
|
+
};
|
|
2271
|
+
this.addEffect = (effect) => {
|
|
2272
|
+
this.effects = this.effects.concat(effect);
|
|
2273
|
+
return this;
|
|
2274
|
+
};
|
|
2275
|
+
this.removeEffect = (effect) => {
|
|
2276
|
+
const name = typeof effect === "string" ? effect : effect.getEffectKey();
|
|
2277
|
+
this.effects = this.effects.filter((currentEffect) => currentEffect.getEffectKey() !== name);
|
|
2278
|
+
return this;
|
|
2279
|
+
};
|
|
2280
|
+
this.setAbortKeyMapper = (callback) => {
|
|
2281
|
+
this.abortKeyMapper = callback;
|
|
2282
|
+
};
|
|
2283
|
+
this.setCacheKeyMapper = (callback) => {
|
|
2284
|
+
this.cacheKeyMapper = callback;
|
|
2285
|
+
};
|
|
2286
|
+
this.setQueueKeyMapper = (callback) => {
|
|
2287
|
+
this.queueKeyMapper = callback;
|
|
2288
|
+
};
|
|
2289
|
+
this.setEffectKeyMapper = (callback) => {
|
|
2290
|
+
this.effectKeyMapper = callback;
|
|
2291
|
+
};
|
|
2292
|
+
this.__modifyAuth = (request) => __async(this, null, function* () {
|
|
2293
|
+
return interceptRequest(this.__onAuthCallbacks, request);
|
|
2294
|
+
});
|
|
2295
|
+
this.__modifyRequest = (request) => __async(this, null, function* () {
|
|
2296
|
+
return interceptRequest(this.__onRequestCallbacks, request);
|
|
2297
|
+
});
|
|
2298
|
+
this.__modifyErrorResponse = (response, request) => __async(this, null, function* () {
|
|
2299
|
+
return interceptResponse(this.__onErrorCallbacks, response, request);
|
|
2300
|
+
});
|
|
2301
|
+
this.__modifySuccessResponse = (response, request) => __async(this, null, function* () {
|
|
2302
|
+
return interceptResponse(this.__onSuccessCallbacks, response, request);
|
|
2303
|
+
});
|
|
2304
|
+
this.__modifyResponse = (response, request) => __async(this, null, function* () {
|
|
2305
|
+
return interceptResponse(this.__onResponseCallbacks, response, request);
|
|
2306
|
+
});
|
|
2307
|
+
this.clear = () => {
|
|
2308
|
+
const { appManager, cache, fetchDispatcher, submitDispatcher } = this.options;
|
|
2309
|
+
this.requestManager.abortControllers.clear();
|
|
2310
|
+
this.fetchDispatcher.clear();
|
|
2311
|
+
this.submitDispatcher.clear();
|
|
2312
|
+
this.cache.clear();
|
|
2313
|
+
this.requestManager.emitter.removeAllListeners();
|
|
2314
|
+
this.fetchDispatcher.emitter.removeAllListeners();
|
|
2315
|
+
this.submitDispatcher.emitter.removeAllListeners();
|
|
2316
|
+
this.cache.emitter.removeAllListeners();
|
|
2317
|
+
this.appManager = (appManager == null ? void 0 : appManager(this)) || new AppManager();
|
|
2318
|
+
this.cache = (cache == null ? void 0 : cache(this)) || new Cache(this);
|
|
2319
|
+
this.fetchDispatcher = (fetchDispatcher == null ? void 0 : fetchDispatcher(this)) || new Dispatcher(this);
|
|
2320
|
+
this.submitDispatcher = (submitDispatcher == null ? void 0 : submitDispatcher(this)) || new Dispatcher(this);
|
|
2321
|
+
};
|
|
2322
|
+
this.createRequest = () => {
|
|
2323
|
+
return (params) => {
|
|
2324
|
+
const endpoint = this.endpointMapper(params.endpoint);
|
|
2325
|
+
const mappedParams = __spreadProps(__spreadValues({}, params), {
|
|
2326
|
+
endpoint
|
|
2327
|
+
});
|
|
2328
|
+
return new Request(this, mappedParams);
|
|
2329
|
+
};
|
|
2330
|
+
};
|
|
2331
|
+
const { url, adapter: adapter4, appManager, cache, fetchDispatcher, submitDispatcher } = this.options;
|
|
2332
|
+
this.url = url;
|
|
2333
|
+
this.adapter = adapter4 || adapter3;
|
|
2334
|
+
this.appManager = (appManager == null ? void 0 : appManager(this)) || new AppManager();
|
|
2335
|
+
this.cache = (cache == null ? void 0 : cache(this)) || new Cache(this);
|
|
2336
|
+
this.fetchDispatcher = (fetchDispatcher == null ? void 0 : fetchDispatcher(this)) || new Dispatcher(this);
|
|
2337
|
+
this.submitDispatcher = (submitDispatcher == null ? void 0 : submitDispatcher(this)) || new Dispatcher(this);
|
|
2338
|
+
}
|
|
2339
|
+
};
|
|
2340
|
+
|
|
2341
|
+
// src/client/client.constants.ts
|
|
2342
|
+
var stringifyDefaultOptions = {
|
|
2343
|
+
strict: true,
|
|
2344
|
+
encode: true,
|
|
2345
|
+
arrayFormat: "bracket",
|
|
2346
|
+
arraySeparator: "",
|
|
2347
|
+
sort: false,
|
|
2348
|
+
skipNull: true,
|
|
2349
|
+
skipEmptyString: true
|
|
2350
|
+
};
|
|
2351
|
+
export {
|
|
2352
|
+
AppEvents,
|
|
2353
|
+
AppManager,
|
|
2354
|
+
Cache,
|
|
2355
|
+
Client,
|
|
2356
|
+
DateInterval,
|
|
2357
|
+
Dispatcher,
|
|
2358
|
+
DispatcherRequestType,
|
|
2359
|
+
HttpMethodsEnum,
|
|
2360
|
+
LoggerManager,
|
|
2361
|
+
Request,
|
|
2362
|
+
RequestEffect,
|
|
2363
|
+
RequestManager,
|
|
2364
|
+
adapter3 as adapter,
|
|
2365
|
+
appManagerInitialOptions,
|
|
2366
|
+
canRetryRequest,
|
|
2367
|
+
defaultTimeout,
|
|
2368
|
+
getAbortByIdEventKey,
|
|
2369
|
+
getAbortEventKey,
|
|
2370
|
+
getAdapterBindings,
|
|
2371
|
+
getAdapterHeaders,
|
|
2372
|
+
getAdapterPayload,
|
|
2373
|
+
getAppManagerEvents,
|
|
2374
|
+
getCacheData,
|
|
2375
|
+
getCacheEvents,
|
|
2376
|
+
getCacheIdKey,
|
|
2377
|
+
getCacheKey,
|
|
2378
|
+
getDispatcherChangeEventKey,
|
|
2379
|
+
getDispatcherDrainedEventKey,
|
|
2380
|
+
getDispatcherEvents,
|
|
2381
|
+
getDispatcherStatusEventKey,
|
|
2382
|
+
getDownloadProgressEventKey,
|
|
2383
|
+
getDownloadProgressIdEventKey,
|
|
2384
|
+
getErrorMessage,
|
|
2385
|
+
getInvalidateEventKey,
|
|
2386
|
+
getIsEqualTimestamp,
|
|
2387
|
+
getLoadingEventKey,
|
|
2388
|
+
getLoadingIdEventKey,
|
|
2389
|
+
getProgressData,
|
|
2390
|
+
getProgressValue,
|
|
2391
|
+
getRemoveEventKey,
|
|
2392
|
+
getRemoveIdEventKey,
|
|
2393
|
+
getRequestDispatcher,
|
|
2394
|
+
getRequestEta,
|
|
2395
|
+
getRequestKey,
|
|
2396
|
+
getRequestManagerEvents,
|
|
2397
|
+
getRequestStartEventKey,
|
|
2398
|
+
getRequestStartIdEventKey,
|
|
2399
|
+
getRequestType,
|
|
2400
|
+
getResponseEventKey,
|
|
2401
|
+
getResponseHeaders,
|
|
2402
|
+
getResponseIdEventKey,
|
|
2403
|
+
getResponseStartEventKey,
|
|
2404
|
+
getResponseStartIdEventKey,
|
|
2405
|
+
getSimpleKey,
|
|
2406
|
+
getTime,
|
|
2407
|
+
getUniqueRequestId,
|
|
2408
|
+
getUploadProgressEventKey,
|
|
2409
|
+
getUploadProgressIdEventKey,
|
|
2410
|
+
hasDocument,
|
|
2411
|
+
hasWindow,
|
|
2412
|
+
interceptRequest,
|
|
2413
|
+
interceptResponse,
|
|
2414
|
+
logger,
|
|
2415
|
+
loggerIconLevels,
|
|
2416
|
+
loggerStyles,
|
|
2417
|
+
mocker,
|
|
2418
|
+
onDocumentEvent,
|
|
2419
|
+
onWindowEvent,
|
|
2420
|
+
parseErrorResponse,
|
|
2421
|
+
parseResponse,
|
|
2422
|
+
sendRequest,
|
|
2423
|
+
severity,
|
|
2424
|
+
stringifyDefaultOptions,
|
|
2425
|
+
stringifyKey,
|
|
2426
|
+
stringifyQueryParams,
|
|
2427
|
+
stringifyValue,
|
|
2428
|
+
xhrExtra
|
|
2429
|
+
};
|
|
2
2430
|
//# sourceMappingURL=index.esm.js.map
|